java runtime data area

Run-Time Data Areas

The Java virtual machine defines different runtime data areas for program execution. Some of these extents are created when the virtual machine starts and destroyed when the virtual machine exits. Other data areas are private to each thread. The data area of ​​each thread is created when the thread is created and destroyed when the thread exits.

 

The pc Register

The Java virtual machine can support the simultaneous execution of multiple threads. Each Java virtual machine thread has its own pc (program counter) register. At any time, what each Java virtual machine thread is executing is the code for a single method, the current method for that thread. If the method is not native, the pc register contains the address of the currently executing Java virtual machine instruction. If the method the thread is currently executing is native, the value of the pc register of the Java virtual machine is undefined. The Java virtual machine's pc register is wide enough to hold a return address or, on a particular platform, a native pointer.

 

Java Virtual Machine Stacks

Each Java virtual machine thread has a private Java virtual machine stack that is created at the same time as the thread. The Java virtual machine stack stores stack frames. The Java virtual machine stack is similar to the stack in the C language. It contains local variables and partial results, and functions in method calls and returns. The memory space of the Java virtual machine stack does not need to be contiguous.

If thecomputation in a thread requires a larger Java Virtual Machine stack than ispermitted, the Java Virtual Machine throws a StackOverflowError.

If Java VirtualMachine stacks can be dynamically expanded, and expansion is attempted butinsufficient memory can be made available to effect the expansion, or ifinsufficient memory can be made available to create the initial Java VirtualMachine stack for a new thread, the Java Virtual Machine throws an OutOfMemoryError.

 

 

Heap

The Java Virtual Machine has a heap shared by all Java Virtual Machine threads . All class instance and array memory is allocated from the heap .

The heap is created when the virtual machine starts. Heap space is managed through an automatic storage management system ( garbage Collector, GC ) and objects are never explicitly freed. Heap memory does not need to be contiguous.

       If a computation requires more heap thancan be made available by the automatic storage management system, the JavaVirtual Machine throws an OutOfMemoryError.

Method Area

The Java Virtual Machine has a method area that is shared among all Java Virtual Machine threads . It stores the structure of each class, such as the runtime constant pool, field and method data, and code for methods and constructors, including special methods used in class, instance initialization, and interface initialization.

The method area is created when the virtual machine starts. Although the method area is logically part of the heap, it is not garbage collected.

If memory in themethod area cannot be made available to satisfy an allocation request, the JavaVirtual Machine throws an OutOfMemoryError.

 

Run-Time Constant Pool

The runtime constant pool is the runtime representation of the constant_pool table in the class file of each class or each interface. It contains several kinds of constants, ranging from numeric literals known at compile time to method and field references that must be determined at runtime.

Each runtime constant pool is allocated from the method area of ​​the Java virtual machine. When the Java virtual machine creates a class or interface, the runtime constant pool of the class or interface is constructed.

When creating aclass or interface, if the construction of the run-time constant pool requiresmore memory than can be made available in the method area of the Java VirtualMachine, the Java Virtual Machine throws an OutOfMemoryError。

 

Native Method Stacks

Each frame hasits own array of local variables, its own operand stack , and a reference tothe runtime constant pool of the class of the current method.

 


 

Local Variables

A singlelocal variable can hold a value of type boolean,byte, char, short, int, float, reference, or returnAddress. A pair of localvariables can hold a value of type long or double.


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325836485&siteId=291194637