java memory model study notes

A Java program execution flow:

 

 

  • 1. First of all, we want to execute java program, we must first write the java source files, which is the java code, followed by the compiler (java Complier), (javac command to compile) the source code into a class file byte code
  • 2. With bytecode files, in order to execute the bytecode files, you need to call the ClassLoader class loader, the corresponding byte code. File is loaded into memory, which is the (run-time data area Runtime Data Area), java memory model that is this one.
  • 3. After it, handed over Jvm execution engine (ExEcution Engine) will be based on the contents of the runtime data area, to execute our code.

Second java memory model:

The memory specification jvm, jvm memory is divided into:

  VM stack, heap, the method area, the program counter, native method stacks of five parts.

Program Counter:

  • For each thread has a program counter
  • The program counter for each thread is a thread private, independently of each other, are thread-safe
  • The memory address of the program counter records the executing thread to interrupt proceed in accordance with the instruction address again interrupted thread resumes execution

VM stack Java Stack:

  • Each thread will correspond to a java stack
  • Each Java stack consisting of several stack frames
  • Each stack frame corresponds to a method of
  • In the run-time stack frame method, create and stack method executed, the stack frame element stack frame pop up as the method returns a value, the stack frame is cleared
  • Top of the stack stack frame stack called activities, representation of the current execution, execution can be cpu
  • Request thread stack depth is greater than the virtual machine allowable depth, an exception will be thrown stackOverFlowError
  • Unable to apply enough memory when the stack to expand, it will throw an OutOfMemoryError

 

Method area:

  • Java stack area is permanent

  • The method area to store the information to be loaded class (name, modifiers), class static variable, the class is defined as the final type of constant, method Field class information, class information
  • The method area is shared java thread
  • Method zone to use more memory than its allowable size that will throw OutOfMemoryError: Error Message PremGen space of

Constant pool:

  • Method part region
  • Store two types of data: the literal and the reference amount
  • Literal: string, final variables
  • Citations: class / interface, method, and field names and descriptors
  • Constant pool will be determined at compile time, and stored in the compiled .class file

Native method stacks: similar to the role played by java stack, the stack for the JVM java implementation of java-service method, and the local Native method stacks for the JVM execution method service.

 

Guess you like

Origin www.cnblogs.com/padazala/p/12669783.html