JVM Memory Overview
METHOD AREA
- Inside a Java virtual machine instance, information about loaded types is stored in a logical area of memory called the method area.
- When the JVM loads a type, it uses a class loader to locate the appropriate class file.
- The class loader reads in the class file in a linear stream of binary data and passes it to the virtual machine.
- The virtual machine extracts information about the type from the binary data and stores the information in the method area.
- Memory for class (static) variables declared in the class is also taken from the method area.
JAVAEDITOR JAVAC CLASSLOADER JVM
Java -> Class File -> Linear Stream of Binary Data -> Type Information Stroed in Method Area
TYPE INFORMATION
For each type it loads, a JVM must store the following kinds of information in the method area:
* The fully qualified name of the type
* The fully qualified name of the type's direct superclass (unless the type is an interface or class java.lang.Object, neither of which have a superclass)
* Whether or not the type is a class or an interface
* The type's modifiers ( some subset of` public, abstract, final)
* An ordered list of the fully qualified names of any direct superinterfaces
In addition to the basic type information listed previously, the virtual machine must also store for each loaded type:
* The constant pool for the type
* Field information
* Method information
* All class (static) variables declared in the type, except constants
* A reference to class ClassLoader
* A reference to class Class
THE HEAP
- Whenever a class instance or array is created in a running Java application, the memory for the new object is allocated from a single heap.
- As there is only one heap inside a Java virtual machine instance, all threads share it.
- Because a Java application runs inside its "own" exclusive Java virtual machine instance, there is a separate heap for every individual running application.
- There is no way two different Java applications could trample on each other's heap data.
- Two different threads of the same application, however, could trample on each other's heap data.
- This is why you must be concerned about proper synchronization of multi-threaded access to objects (heap data) in your Java programs.
GARBAGE COLLECTOR
—————
