What is JVM
Definition: Java Virtual Machine, the environment in which JAVA programs run (the environment in which JAVA binary byte code runs)
memory structure
The JVM memory layout defines the strategy for memory application, allocation and management during Java operation, which ensures the efficient and stable operation of the JVM. There are some differences in how different JVMs divide memory and how they manage it. This is often referred to asrun-time data area
program counter
define
Thread private, used as a line number indicator for the current thread to record the address of the thread instruction currently being executed by the virtual machine.
corresponds English -ity, -ism, -ization
- The line number indicator of the byte code executed by the current thread, through which the flow control of the code is realized, such as: sequential execution, selection, looping, exception handling.
- In the case of multi-threading, a program counter is used to keep track of where the current thread is executing, so that when the thread is switched back it can know where it last executed.
specificities
-
Thread Private
-
The CPU allocates time slices for each thread.When the time slice of the current thread is used up, the CPU executes the code in another thread.
-
The program counter is private to each thread. When another thread runs out of time and returns to execute the current thread's code, the program counter tells you which instruction to execute.
-
There will be no memory overflow
The program counter is the only area of memory that doesn't have an OutOfMemoryError, and its lifecycle is created as the thread is created and dies as the thread ends
virtual machine stack
summarize
Definition: Each thread creates a virtual machine stack when it is created, which holds one stack frame inside, corresponding to one Java method call, which is thread-private and has the same lifecycle as the thread.
Role: Supervises the operation of a Java program. It holds local variables, partial results of methods, and participates in method calls and returns.
Features:
-
The memory space that each thread needs to run is called the virtual machine stack. It is thread-private, each thread has its own Java virtual machine stack, and is created when the thread is created and dies when the thread dies.
-
The Java virtual machine stack is made up of individual stack frames that correspond to the memory occupied by each method call. A corresponding stack frame is pressed into the VM stack for each function call, and a stack frame is popped at the end of each function call. The two ways to return to a function, whichever way you use, will result in a stack frame being ejected
-
For normal function return, use the return directive
-
throw an exception
-
-
Each thread can only have one active stack frame, with the top of the stack holding the current method currently being executed
internal structure in a stack (computing)
stored in each stack frame:
-
Local Variables table (Local Variables)
-
Operand Stack (or Expression Stack)
-
Dynamic Linking: method references to the pool of runtime constants
-
Method return address (Return Address): method normal exit or abnormal exit address
local variable table (math.)
Stores compile-time-aware basic types (boolean, byte, char, short, int, float, long, double), object references (reference types), and returnAddress types (which point to the address of a bytecode instruction). (Java's basic data types are not necessarily stored on the stack.Local variables are stored on the stack for basic types and on the stack for reference types, but the object pointed to by the variable name (the basic data type) is stored on the heap. Member variables, on the other hand, are stored in the heap with both the variable name and the object, regardless of whether they are of basic type or reference type.。)
Since the local variable table is built on the thread's stack and is private data to the thread, theNo data security issues
operand stack
is a Last-In-First-Out (LIFO) operand stack, which can also be referred to as aexpression stack(Expression Stack)。It is mainly used to save the intermediate results of the calculation process, and also serves as a temporary storage space for variables in the calculation process.
The operand stack, during method execution, writes data to or extracts data from the operand stack based on bytecode instructions, i.e., in (push) and out (pop). Some bytecode instructions press values into the operand stack and the rest of the bytecode instructions take operands out of the stack. The result is then pressed onto the stack after using them. For example, performing operations such as copying, swapping, summing, etc.
dynamic link
Each stack frame contains a symbolic reference to the method to which the stack belongs in the pool of runtime constants, which is dynamically linked during method calls to convert this symbolic reference into a direct reference.
-
Partial symbolic references are converted to direct references during the class loading phase, and this conversion is the static linking
-
Some symbolic references are converted to direct references during runtime; this conversion is dynamic linking
Method return address
Used to hold the value of the PC register from which the method was called.
A method ends in one of two ways
-
Normal execution completed
-
Unprocessed exception, abnormal exit
Regardless of which way you exit, after a method exits it returns to the location where the method was called. When a method exits normally, the value of the caller's PC counter is used as the return address, i.e., the address of the next instruction in the instruction that called the method. Whereas for exiting by exception, the return address is determined by the exception table, and this information is not normally stored in the stack frame.
Essentially.The exit of a method is the current stack frame out of the stack. At this point, it is necessary to restore the upper level method's local variable table, operand stack, press the return value into the operand stack of the caller's stack frame, set the PC register value, and so on, to allow the caller's method to continue to execute.
The difference between a normal completion exit and an abnormal completion exit is:An exit via an exception does not generate any return to the higher-level caller.
Virtual Machine Stack Errors
There are two types of errors that occur with the Java VM stack:*Error and OutOfMemoryError . The size of the VM stack memory for each thread can be specified with the -Xss parameter:
java -Xss2M
Why *Error occurs
-
Too many stack frames in the VM stack (infinite recursion)
-
Too much memory per stack frame
OutOfMemoryError occurs due to the following reasons
-
In a single-threaded program, OOM exceptions cannot occur; however, OOM exceptions can be generated by looping through the creation of a thread (the thread body calling a method). In this case, the cause of the OOM exception is not related to whether the stack space is large enough or not.
-
Threads scale dynamically, OOM occurs when there is not enough memory for the application
problem analysis
-
Does garbage collection involve stack memory?
- Not required. Because the virtual machine stack is made up of individual stack frames, the corresponding stack frame is popped off the stack after the method execution is complete. So there is no need to reclaim memory through the garbage collection mechanism.
-
Is a larger allocation of stack memory better?
- No. Because physical memory is certain, the larger the stack memory, the more recursive calls can be supported, but the smaller the number of threads that can be executed.
-
Are local variables within methods thread-safe?
- Local variables within a method are thread-safe if they don't escape the method's scope; if they need to be considered thread-safe if the local variable references an object and escapes the method's scope
Thread running diagnostics
Excessive CPU usage
-
When running certain programs under Linux environment, it may lead to high CPU usage, and then you need to locate the thread that occupies too much CPU.
-
top command to see which process is hogging too much CPU
-
ps H -eo pid, tid (thread id), %cpu | grep The process number that was just found by top The ps command is used to further check which thread is using too much CPU.
-
jstack process id By looking at the process of the thread nid, just through the ps command to see the tid to compare and locate, note that jstack to find out the thread id is hexadecimal, you need to convert the
local method stack
Also thread-private
The virtual machine stack serves the Java methods executed by the virtual machine, while the native method stack serves the Native methods used by the virtual machine, which are typically written in other languages (C, C++, etc.).
When a local method is executed, a stack frame is also created on the local method stack to hold the local variable table, operand stack, dynamic links, and exit information for that local method.
The reason for using native methods: some methods with native keywords just need JAVA to call C or C++ methods, because theJAVA sometimes can't interact directly with the underlying operating system, so you need to use native methods.
Native Method Stack: This is done by registering native methods in the Native Method Stack and loading the Native Libraies when executed by the Execution Engine.
Native Interface: The role of the native interface is to integrate different programming languages used by Java, its original intention is to integrate the C / C program, Java was born at the time of the C / C rampant, want to get a foothold, there must be a call to C, C + + + program, so in the memory of a special block of area to deal with the code labeled native, it is the specific approach is to register native methods in the Native Method Stack, in ( Execution Engine ) execution engine to load the Native Libraies. Specific approach is to register native methods in the Native Method Stack, in ( Execution Engine ) Execution Engine execution time to load Native Libraies. Currently the method is used less and less, unless it is related to hardware applications, such as through the Java program to drive printers or Java systems to manage the production equipment, it has been relatively rare in enterprise applications. Because now the heterogeneous inter-domain communication is very developed , such as the use of socket communication , you can also use Web Service and so on.
In the Hotspot JVM, it is straightforward to combine the local method stack and the virtual machine stack into one
Local Method Stack Exception Same as VM Stack
heap up
define
Objects created through the new keyword are placed in heap memory
specificities
-
All thread-shared, heap memory objects need to be considered thread-safe
-
There is a garbage collection mechanism
-
Regions in the heap: New Generation (Eden space, From Survivor, To Survivor space) and Old Generation.
The young generation is divided into three parts - the Garden of Eden (Eden Memory) and two survivor memories (Survivor Memory, known as from/to or s0/s1) - with a default ratio of 8:1:1
Set the amount of memory the program takes up at startup with -Xms, and the maximum amount of memory it can take up while the program is running with -Xmx. If the program requires more memory than this setting, an OutOfMemory exception is thrown.
-Xms1M -Xmx2M
The Eden area is the area where objects are created, but theEden zone will call light GC for garbage collection if it's fullIf the object is referenced at this point it survives into the survivor area, at which point the Eden area is cleared of memory and the garbage is collected.If the survivor's section is full, we'll go to the senior's section.。
GC trash pickup is primarily in the Eden and Senior Districts.
Setting Heap Memory Size and OOM
The Java heap is used to store instances of Java objects, so the size of the heap is determined when the JVM starts, and can be set with -Xmx and -Xms.
-
-Xms is used to indicate the starting memory of the heap, equivalent to -XX:InitialHeapSize
-
-Xmx is used to indicate the maximum memory of the heap, equivalent to -XX:MaxHeapSize
If the size of the heap exceeds the maximum memory set by -Xmx, an OutOfMemoryError exception is thrown.
The -Xmx and -Xms parameters are usually configured to the same value to improve performance by eliminating the need to re-separate the heap size after the garbage collection mechanism has cleaned up the heap. If-Xms
cap (a poem)-Xmx
set to different values, the JVM may constantly adjust the heap size at runtime based on memory usage. This dynamic adjustment requires memory allocation and garbage collection, which may increase system overhead and latency. In contrast, by setting both parameters to the same value, the JVM allocates a fixed amount of heap memory at startup, thus avoiding the overhead of memory reallocation.
-
By default, the initial heap memory size is: computer memory size/64
-
By default, the maximum heap memory size is: computer memory size/4
It is possible to get the set value in code and of course simulate an OOM:
OOM is the heap memory overflow error that is reported after even the old age area has overflowed and the entire memory is no longer able to handle it. That is : java heap space. heap memory overflow.
public static void main(String[] args) {
// Return the JVM heap size
long initalMemory = ().totalMemory() / 1024 /1024;
// Returns the maximum memory of the JVM heap.
long maxMemory = ().maxMemory() / 1024 /1024; //return the current JVM heap size.
//freeMemory gets the memory that the current program has that is not yet used, i.e., that can be reclaimed by gc.
("-Xms : "+initalMemory + "M");
("-Xmx : "+maxMemory + "M"); ("-Xmx : "+maxMemory + "M").
("System Memory Size : " + initalMemory * 64 / 1024 + "G");
("System Memory Size: " + maxMemory * 4 / 1024 + "G");
}
Viewing JVM Heap Memory Allocation
-
In the case where the JVM heap memory size is not configured by default, the JVM configures the current memory size based on the default values
-
By default the ratio of new generation to old generation is 1:2, which can be configured with -XX:NewRatio
- in the new generationEdenFrom SurvivorTo SurvivorThe percentage of8:1:1,This can be configured with -XX:SurvivorRatio
-
JDK 8 turns on -XX:+UseAdaptiveSizePolicy by default.Don't just turn it off.-XX:+UseAdaptiveSizePolicy, unless the division of heap memory is explicitly planned for
-
Eden, From Survivor, To Survivor sizes are recalculated after each GC
Calculations are based onGC processin the statisticsGC time、throughput、memory footprint
java -XX:+PrintFlagsFinal -version | grep HeapSize
uintx ErgoHeapSizeLimit = 0 {product}
uintx HeapSizePerGCThread = 87241520 {product}
uintx InitialHeapSize := 134217728 {product}
uintx LargePageHeapSizeThreshold = 134217728 {product}
uintx MaxHeapSize := 2147483648 {product}
java version "1.8.0_211"
Java(TM) SE Runtime Environment (build 1.8.0_211-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.211-b12, mixed mode)
$ jmap -heap process number
methodology area
framework
The method area, like the Java heap, is a memory area shared by all threads, which is used to store data such as class information, constants, static variables, and code compiled by the on-the-fly compiler that has been loaded by the virtual machine.
The main goal of garbage collection for the method area is toRecycling of constant pools and unloading of classes。
The method area is just a concept defined in the JVM specification., which is used to store data such as class information, constant pools, static variables, JIT-compiled code, etc., doesn't specify how to implement it, and different vendors have different implementations. WhilePermGen is a concept unique to the Hotspot virtual machine, and in Java8 it is also known as metaspace.replaced, both the permanent generation and the meta-space can be interpreted as a grounded realization of the method area.
Permanent generations and metric spaces
Permanent Representative
Method zones are the norm for JVMs, and permalinks PermGen is an implementation of method zones, and only HotSpot has permalinks. For other types of VMs, such as JRockit, there is no permalink. Since the method area mainly stores information about the class, it is easier to have a perma-gen memory overflow in scenarios where the class is dynamically generated.
The permanent area is memory-resident and is used to hold Class objects and interface metadata carried by the JDK itself. This way this data does not take up space. It is used to store the java runtime environment.
- Prior to JDK 1.7, strings were stored in the method area.
- After JDK 1.7 strings were placed on the heap
- In Java 8, the method area was eliminated in favor of a metaspace that uses direct memory directly. That is, the metaspace logically belongs to the heap, but in physical memory, the memory in the metaspace is not allocated from the heap memory.
space (math.)
As of JDK 1.8, HotSpot's permanent generation was completely removed and replaced with metaspaces. Metaspaces are similar in nature to persistent generations, in that they are an implementation of the method regions in the JVM specification. The major difference is that metaspaces are not in the virtual machine, but use direct memory.
Why replace permanent generation with meta-space? The permanent generation memory is limited by the JVM's available memory, while the metaspace uses direct memory, which is limited by the locally available memory, and while the metaspace can still overflow, the probability of overflowing the permanent generation memory is less than that of overflowing the permanent generation memory.
internal composition
The method area is used to store data such as class information, constants, static variables, code compiled by the immediate compiler, etc. that has been loaded by the virtual machine.
Type information
For each loaded type (class class, interface interface, enum enum, annotation), the JVM must store the following type information in the method area
-
The full valid name of this type (full name = package name. Class name)
-
the full valid name of the direct parent of the type (for interface or , there is no parent)
-
Modifiers of this type (some subset of public, abstract, final)
-
An ordered list of direct interfaces of this type
Field information
-
The JVM must keep information about all the domains of a type and the order in which they are declared in the method area
-
Information about the domain includes: domain name, domain type, domain modifiers (some subset of public, private, protected, static, final, volatile, transient)
Method information
The JVM must save all methods of the
-
Method name
-
The return type of the method
-
Number and type of method parameters
-
Method modifiers (a subset of public, private, protected, static, final, synchronized, native, abstract)
-
Method bytecodes, operand stacks, local variable tables, and sizes (except for abstract and native methods).
-
Exception table (except abstract and native methods)
- The start position, end position, code handling offset address in the program counter, and constant pool index of the caught exception class for each exception handled
run-time constant pool
Runtime Constant Pool is part of the method area)
constant pool
A valid bytecode file contains, in addition to class version information, descriptions of fields, methods, and interfaces, the Constant Pool Table, which contains various literals and symbolic references to types, fields, and methods.
Why do I need a constant pool?
A Java source file of classes, interfaces, compiled to produce a bytecode file. The bytecode in Java needs to be supported by data, usually this data will be so large that it can not be stored directly into the bytecode, another way, can be stored into the constant pool, the bytecode contains a reference to the constant pool. This bytecode contains a reference to the constant pool. It is the runtime constant pool that is used in dynamic linking.
As follows, we look at a simple class with just the Main method via jclasslib, and #2 in the bytecode points to the Constant Pool
The pool of constants can be thought of as a table, and virtual machine instructions find the types of class names, method names, parameter types, literals, and so on, to be executed based on this table of constants.
run-time constant pool
-
After loading classes and structures into the virtual machine, the corresponding runtime constant pool is created
-
The Constant Pool Table is part of the Class file and is used to store various literal and symbolic references generated during compilation.This part will be stored in the runtime constants pool in the method area after the class is loaded
-
The JVM maintains a pool of constants for each loaded type (class or interface). The data items in the pool are accessed by index like array items
-
The runtime constant pool contains a variety of constants, including numeric literals that are already specified by the compiler, as well as method or field references that are not available until after runtime parsing. This is no longer a symbolic address in the pool, but a real address instead.
- Another important feature of the runtime constant pool, as opposed to the Class file constant pool, is:Dynamics.The Java language does not require constants to be generated only during compilation; new constants can also be put into the pool during runtime, as is the case with the intern() method of the String class
-
When creating a runtime constant pool for a class or interface, the JVM throws an OutOfMemoryError exception if the memory space required to construct the runtime constant pool exceeds the maximum value available in the method area
String Into String Pool Case
String assignment:
public static void main(String[] args) {
String a = "a";
String b = "b";
String ab = "ab";
}
The information in the constant pool is loaded into the runtime constant pool, but at this point a b ab are only symbols in the constant pool and have not yet become java strings
0: ldc #2 // String a
2: astore_1
3: ldc #3 // String b
5: astore_2
6: ldc #4 // String ab
8: astore_3
9: return
When ldc #2 is executed, the symbol a is changed to an "a" string object and placed in the string pool
When ldc #3 is executed, the symbol b is changed to a "b" string object and placed in the string pool
When ldc #4 is reached, the symbol ab is changed to an "ab" string object and placed into the string pool
eventualStringTable [“a”, “b”, “ab”]
Note: String objects are created lazily, and are only created and placed in the string pool when that line of string is run and does not exist in the string pool (e.g. ldc #2).
- The process of creating a string using a spliced string variable object:
public class StringTableStudy {
public static void main(String[] args) {
String a = "a";
String b = "b";
String ab = "ab";
//Splicing string objects to create new strings
String ab2 = a+b; //practiceStringBuilderput together
}
}
The result after decompilation
Code:
stack=2, locals=5, args_size=1
0: ldc #2 // String a
2: astore_1
3: ldc #3 // String b
5: astore_2
6: ldc #4 // String ab
8: astore_3
9: new #5 // class java/lang/StringBuilder
12: dup
13: invokespecial #6 // Method java/lang/StringBuilder."<init>":()V
16: aload_1
17: invokevirtual #7 // Method java/lang/:(Ljava/lang/String;)Ljava/lang/StringBuilder;
20: aload_2
21: invokevirtual #7 // Method java/lang/:(Ljava/lang/String;)Ljava/lang/StringBuilder;
24: invokevirtual #8 // Method java/lang/:()Ljava/lang/String;
27: astore 4
29: return
The process of creating a string by splicing is: StringBuilder().append("a").append("b").toString() The final toString method's return value is a new string, two different strings, although the value of the string is the same as the spliced string.One in the string pool, one in heap memory
String ab = "ab";
String ab2 = a+b;
// The result is false, because ab exists in the string pool, and ab2 is an object returned by StringBuilder's toString method, which exists in heap memory.
(ab == ab2);
- Creating a string using the method of splicing a string constant object
public class StringTableStudy {
public static void main(String[] args) {
String a = "a";
String b = "b";
String ab = "ab";
String ab2 = a+b;
// Create a string using the method of splicing string constants
String ab3 = "a" + "b";//ab3 gets the value directly from the string pool, which is equivalent to ab3="ab".
}
}
The result after decompilation
Code:
stack=2, locals=6, args_size=1
0: ldc #2 // String a
2: astore_1
3: ldc #3 // String b
5: astore_2
6: ldc #4 // String ab
8: astore_3
9: new #5 // class java/lang/StringBuilder
12: dup
13: invokespecial #6 // Method java/lang/StringBuilder."<init>":()V
16: aload_1
17: invokevirtual #7 // Method java/lang/:(Ljava/lang/String;)Ljava/lang/StringBuilder;
20: aload_2
21: invokevirtual #7 // Method java/lang/:(Ljava/lang/String;)Ljava/lang/StringBuilder;
24: invokevirtual #8 // Method java/lang/:()Ljava/lang/String;
27: astore 4
//ab3Initialize by getting the string directly from the string pool
29: ldc #4 // String ab
31: astore 5
33: return
When using the method of splicing string constants to create a new string, because the content is a constant, javac will be optimized in the compilation period, the result has been determined in the compilation period for the ab, and the creation of the ab has been put in the string pool in the "ab", so the ab3 directly from the string pool to get the value, so the operation is carried out and ab = "ab".
When using the method of splicing string variables to create a new string, since the content is a variable whose value can only be determined at runtime, you need to use StringBuilder to create the
- intern method 1.8
Calling the intern method of a string object will try to put that string object into the string pool
-
If the string object is not in the string pool, it is put in successfully
-
Failed to put in the string object if it exists
Regardless of whether the put succeeds or not, the string object in the string pool is returned
Note: At this point, if the call to the intern method succeeds, the heap memory and the string object in the string pool are the same object; if it fails, it is not the same object
Example 1:
public class Main {
public static void main(String[] args) {
//"a" "b" is put into the string pool and str is in heap memory
String str = new String("a") + new String("b"); //call the intern of str.
//call the intern method of str, when there is no "ab" in the pool, the string object will be put into the pool, and the heap memory is the same object as the "ab" in the pool.
String st2 = ();
//Assign value to str3, because at this time there is already "ab" in the string pool, then directly return the contents of the string pool
String str3 = "ab";
//Because the heap memory and the string pool "ab" is the same object, so the following two statements are printed as true
(str == st2);; (str == str3)
(str == str3); //Since the heap memory is the same object as "ab" in the string pool, the following two statements print true
}
}
Example 2:
public class Main {
public static void main(String[] args) {
//Here create the string object "ab", because there is no "ab" in the string pool, so put it into the string pool
String str3 = "ab"; //"a" "b" "ab
//"a" "b" is put into the pool, str is in heap memory.
String str = new String("a") + new String("b"); //This time, because str is being created, it will be put into the string pool.
//This time, since "ab" already existed in the pool when str3 was created, it fails to be put into the pool, but "ab" in the pool is returned.
String str2 = ();
//false, str is in heap memory, str2 is in string pool.
(str == str2);
//false, str in heap memory, str3 in string pool
(str == str3);
//true, str2 and str3 are the same object in the string pool
(str2 == str3);
}
}
Garbage collection in method areas
There are two main types of garbage collection in method areas, the collection of deprecated constants and the collection of useless classes.
-
When a constant object is no longer referenced anywhere, it is marked as a deprecated constant and the constant can be recycled.
-
Useless Classes.
-
All instances of this class have been recycled.
-
The class loader that loaded the class has been recycled. This condition is usually difficult to achieve except in carefully designed scenarios with replaceable class loaders, such as OSGi, JSP reloading, etc.
-
The object corresponding to this class is not referenced anywhere, and the methods of this class cannot be accessed anywhere through reflection.
-
virtual machinecanRecycling is performed on classes that satisfy the above 3 conditions, but themaybewill be recycled. The HotSpot VM provides the -Xnoclassgc parameter to control whether classes are recycled or not, and you can also view class loading and unloading information using -verbose:class, as well as -XX:+TraceClassLoading and -XX:+TraceClassUnLoading.
Scenarios that make heavy use of reflection, dynamic proxies, ByteCode frameworks such as CGLib, dynamically generated JSPs, and frequently customized ClassLoaders such as OSGi require the VM to have class offloading capabilities to ensure that the permanent generation does not overflow.
Example of a memory model
public class PersonDemo
{
public static void main(String[] args)
{ // The local variable p and the formal parameter args are in the stack frame of the main method.
//new Person() object allocates space in the heap
Person p = new Person("zs",18); // The new Person() object allocates space in the stack frame.
= "cn1"; //reassign a in the heap, "cn1" is put into the string pool
//sum in stack, new int[10] allocate space in heap
int[] sum = new int[10];
}
}
class Person //Template in method area
{
// Instance variables are in the heap. The "cn" constant is in the constant pool
private String a = "cn";
// Instance variables name and age are allocated space in the Heap.
private String name; private int age; // Instance variables name and age are allocated space in the Heap.
private String name; private int age; //Instance variables name and age are allocated space in the heap.
// class variable (reference type) name1 in the Method Area and "cn" in the Constant Pool.
private static String name1 = "cn"; // class variable (reference type) name1 in Method Area and "cn" in constant pool.
//class variable (reference type) name2 is in Method Area.
//"cn" already exists, in the constant pool, name2 points to "cn" in the constant pool.
private static String name2 = new String("cn"); //num is in the heap, name2 points to "cn" in the constant pool.
//num is in the heap, new int[10] is also in the heap
private int[] num = new int[10];
Person(String name,int age)
{
//this and the formal parameters name and age will open up space in the stack frame of the constructor method when it is called.
// will open up space in the stack frame of the constructor method.
= name.
= age.
}
// The setName() method is a class template and is loaded in the method area. But the call will be pressed into the stack, and the local variable name into the name, and then name for the value passed into the name address
public void setName(String name)
{
= name; }
}
//speak() method in the method area
public void speak()
{
(+"..." +);
}
// showCountry() method in the method area
public static void showCountry()
{
("country");
}
}
Its memory model is as follows:
The pool of constants described here though is in the method area only as an understanding. It can also be understood as being in the heap, or metaspace
Interview questions column
Java interview questions columnIt's online, so feel free to visit.
- If you don't know how to write a resume, resume projects don't know how to package them;
- If there's something on your resume that you're not sure if you should put on it or not;
- If there are some comprehensive questions you don't know how to answer;
Then feel free to private message me and I will help you in any way I can.