Chinaunix首页 | 论坛 | 博客
  • 博客访问: 197221
  • 博文数量: 69
  • 博客积分: 1400
  • 博客等级: 上尉
  • 技术积分: 720
  • 用 户 组: 普通用户
  • 注册时间: 2005-08-03 11:35
文章分类

全部博文(69)

文章存档

2011年(13)

2010年(46)

2009年(10)

我的朋友

分类: Java

2010-07-14 20:02:28

JLS100714Note on JLS, Ch12

 

@ http://zcatt.cublog.cn

 

Hist:

1007014, draft

 

 

 

Chapter 12 Execution(执行)

This chapter specifies activities that occur during execution of a program. It is organized around the life cycle of a JVM and of the classes, interfaces, and objects that from a program.

 

Virtual Machine Start-Up

A JVM starts execution by invoking the method main of some specified class. Let’s suppose the class Test

 

Load the Class Test

The initial attempt to execute the method main of class Test discovers that the class Test is not loaded. The VM then uses a class loader to attempt to find such a binary representation.

 

Link Test: Verify, Prepare, (Optionally)Resolve

After loaded and before initialized, Test, like all (class or interface) types, must be linked. Linking involves verification, preparation and (optionally) resolution.

Verification checks that the loaded representation of Test is well-formed with a proper symbol table.

Preparation involves allocation of static storage and any data structures that are used internally by the vm, such as method tables.

Resolution is the process of checking symbolic references from Test to other classes and interfaces.

 

Initialize Test: Execute Initializers

Initialization consists of execution of any class variable initializers and static initializers of the class Test, in textual order.

Initialization may cause loading, linking, and initialization errors, including errors involving other type.

 

Invoke Test.main

 

 

Loading of Classes and Interfaces

Loading refers to the process of finding the binary form of a class or interface type with a particular name, and constructing a Class object to represent the class or interface.

 

The Loading Process

The loading process is implemented by the class ClassLoader and its sublcasses.

 

Linking of Classes and Interfaces

Linking is the process of taking a binary form of a class or interface type and combining it into the runtime state of the JVM, so that it can be executed.

 

Verification of the Binary Representation

Verification ensures that the binary representation of a class or interface is structurally correct.

 

Preparation of a Class or Interface Type

Preparation involves creating the static fields for a class or interface and initializing such fields to the default values.

 

Resolution of Symbolic References

Before a symbolic reference can be used it must undergo resolution, wherein a symbolic reference is checked to be correct and, typically, replaced with a direct reference that can be more efficiently processed if the reference is used repeatedly.

 

Initialization of Classes and Interfaces

Initialization of a class consists of executing its static initializers and the initializers for static fields delcared in the class. Initialization of an interface consists of executing the initializers for fields(constants) declared there.

 

Creation of New Class Instances

A new class instance is explicitly created when evalution of a class instance creation expression causes a class to be instantiated. A new class instance may be implicitly created.

 

Finalization of Class Instance.

The class Object has a protected method called finalize. This method can be overridden by other classes. The particular definition of finalize that can be invoke for an object is called the finalizer of that object. Before the storage for an object is reclaimed by the garbage collector, the JVM will invoke the finalizer of taht object.

Finalizers provide a chance to free up resources that cannot be freed automatically by an automatic storage manager.

 

Unloading of Classes and Interfaces

An implementation of the Java programming language may unload classes. A class or interface may be unloaded if and only if its defining class loader may be reclaimed by the garbage collector. Classes and interfaces loaded by the bootstrap loader may not be unloaded.

 

Program Exit

A program terminates all its activity and exits when one of two things happens:

1)      All the threads that are not daemon threads terminate.

2)      Some thread invokes the exit method of class Runtime or class System and the exit operation is not forbidden by the security manager.

 

 

REF

1.       JLS 3nd

2.       JVM 2nd
Locations of visitors to this page

阅读(1039) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~