Java - JVM: 读书笔记 Chapter 05 The Java Virtual Machine ( Part I Basic )

Tutorial Materials: Inside Java Machine

 

Chapter 5 - The Java Virtual Machine 

 

5.1 The Lifetime of a Java Virtual Machine 

A runtime instance of the Java Virtual Machine has a clear mission in life: to run one Java application, When a Java application starts, a runtime instance is born. When the application completes, the instance dies. on the same computer, using the same concrete implementation, you'll get three Java Virtual Machine instances. Each Java application runs inside its own Java Virtual Machine.

 

5.2 The Architecture of the Java Virtual Machine

a. Internal architecture



b. Runtime data area

  Each instance of the Java Virtual Machine has one method area and one heap. These areas are shared by all threads running inside the virtual machine. When the virtual machine loads a class file, it parses information about a type from the binary data contained in the class file. It places this type information into the method area. As the program runs, the virtual machine places all objects the program instantiates onto the heap.

 

c. Runtime data areas exclusive to each Thread

  1) When each thread initialized, it gets its own pc register(program counter) and Java Stack

  2) If the thread is executing a Java method (not a native method), the value of the pc register indicates the next instruction to execute. 
  3) A threadís Java stack stores the state of Java (not native) method invocations for the thread. The state of a Java method invocation includes its local variables, the parameters with which it was invoked, its return value (if any), and intermediate calculations.  The state of native method invocations is stored in an implementation-dependent way in native method stacks, as well as possibly in registers or other implementation-dependent memory areas. 

  4) The Java stack is composed of stack frames (or frames). A stack frame contains the state of one Java method invocation. When a thread invokes a method, the Java Virtual Machine pushes a new frame onto that thread's Java stack. When the method completes, the virtual machine pops and discards the frame for that method.
  5) The Java Virtual Machine is not designed to use the registers to hold the intermediate data values but to use the Java Stack instead. - The goal is to eliminate the few or irregular general purpose registers of different PC Platform.
  6) No thread can access the pc register or Java stack of another thread.

 

5.3 Data Types

  Data Type of the JVM composes by Primitive Type and Reference Types. 

  Reference values refer to objects, but are not objects themselves. ( consider it as the value of the address of the Object instance )

  returnValue type. This primitive type is used to implement finally clauses of Java programs.

5.4 Word Size
  The basic unit of size for data values in the Java Virtual Machine is the word--a fixed size chosen by the designer of each Java Virtual Machine implementation
  1. The word size must be large enough to hold a value of type byte, short, int, char, float, returnValue, or reference. Two words must be large enough to hold a value of type long or double
 
2. An implementation designer must therefore choose a word size that is at least 32 bits, but otherwise can pick whatever word size will yield the most efficient implementation. The word size is often chosen to be the size of a native pointer on the host platform.

 

5.5 The Class Loader Subsystem

 

5.5.1 Loading, Linking and Initialization is the responsiblities of the Class Loader Subsystem
 

  1. Loading: finding and importing the binary data for a type


  2. Linking: performing verification, preparation, and (optionally) resolution

      a. Verification: ensuring the correctness of the imported type
      b. Preparation: allocating memory for class variables and initializing the memory to default values
      c. Resolution: transforming symbolic references from the type into direct references.

 

  3. Initialization: invoking Java code that initializes class variables to their proper starting values.
   

5.5.2 The Primordial Class Loader

 
  Primordial Class Loader -
Java Virtual Machine implementations must be able to recognize and load classes and interfaces stored in binary files that conform to the Java class file format.
  Every Java Virtual Machine implementation has a primordial class loader, which knows how to load trusted classes, including the classes of the Java API. The Java Virtual Machine specification doesnít define how the primordial loader should locate classes. That is another decision the specification leaves to implementation designers.
 

5.5.3 The Class Loader Objects

 

  Class Loader Objects themselves are part of the Java Application, three methods defined in class ClassLoader are getways into Java Virtual Machine.

    

  protected final Class defineClass(byte data[], int offset,  int length);
  
  protected final Class findSystemClass(String name);
 

  protected final void resolveClass(Class c);

 

  defineClass ( ) method accepts byte arrays, class ClassLoader expects binary data conforming to the Java class file format--binary data that represents a new type for the running application.  Every Java Virtual Machine implementation must make sure the defineClass() method of class ClassLoader can cause a new type to be imported into the method area. ( the new Type should be the binary data of the Class data, it stores in the Method area )

 

  findSystemClass ( ) : When a class loader object invokes this method, it is requesting that the virtual machine attempt to load the named type via its primordial class loader. If the primordial class loader has already loaded or successfully loads the type, it returns a reference to the Class object representing the type( The reference to the Class data stores in the Mehtod area). If it can't locate the binary data for the type, it throws ClassNotFoundException. Every Java Virtual Machine implementation must make sure the findSystemClass() method can invoke the primordial class loader in this way. 

 

  resolveClass ( ) method accpets a reference to a Class instance ( The class instance is the class data stored in the Method area ). This method causes the type represented by the Class instance to be linked and initialized (if it hasnít already been linked and initialized).  ( The defineClass() method, described above, only takes care of loading. (See the above section, "Loading, Linking, and Initialization" for definitions of these terms.) When defineClass() returns a Class instance, the binary file for the type has definitely been located and imported into the method area, but not necessarily linked and initialized. ) Java Virtual Machine implementations make sure the resolveClass() method of class ClassLoader can cause the class loader subsystem to perform linking and initialization.

 

5.5.4   Name Spaces

 

  Each class loader maintains its own name space populated by the types it has loaded. see Chapter 3, the "Security" chapter described that there are different unique Name Spaces contained by each different Class Loader.

 

Java - JVM: 读书笔记 Chapter 05 The Java Virtual Machine ( Part II Method Area )

java虚拟机的运行机理的详细介绍 Inside the Java Virtual Machine Bill Venners $39.95 0-07-913248-0 Inside the Java Virtual Machine Acknowledgments Introduction Part One: Java's Architecture 1 Introduction to Java's Architecture Why Java? The Architecture The Java Virtual Machine The Class Loader Architecture The Java Class File The Java API The Java Programming Language Architectural Tradeoffs Future Trends On the CD-ROM The Resources Page 2 Platform independence Why Platform Independence? Java's Architectural Support for Platform Independence Scalability Factors that Influence Platform Independence The Java Platform Native Methods Other Factors Seven Steps to Platform Independence The Politics of Platform Independence The Resources Page 3 Security Why Security? The Sandbox The Class Loader Architecture The Class File Verifier Phase One: Internal Checks Phase Two: Verification of Symbolic References Safety Features Built Into the Java Virtual Machine The Security Manager and the Java API The Security API Security Beyond the Architecture The Resources Page 4 Network-mobility Why Network Mobility? A New Software Paradigm Java's Architectural Support for Network-Mobility The Applet: An Example of Network-Mobile Java The Resources Page Part Two: Java Internals 5 The Java Virtual Machine What is a Java Virtual Machine? The Lifetime of a Java Virtual Machine The Architecture of the Java Virtual Machine Data Types Word Size The Class Loader Subsystem Loading, Linking and Initialization The Primordial Class Loader Class Loader Objects Name Spaces The Method Area Type Information The Constant Pool Field Information Method Information Class Variables A Reference to Class ClassLoader A Reference to Class Class Method Tables An Example of Method Area Use The Heap Garbage Collection Object Representation Array Representation The Program Counter The Java Stack The Stack Frame Local Variables Operand Stack Frame Data Possible Implemen
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值