您的位置:首页 > 其它

JVM第四天之加载,链接,初始化

2015-01-12 15:46 267 查看
Loading is the process of finding the binary representation of a class or interface type with a particular
name and creating a class or interface from that
binary representation.

Linking is the process of taking a class or interface and combining it into the runtime state of the Java virtual machine so that it can be executed. Initialization of a class or interface
consists of executing the class or interface initialization method <clinit>


1. Runtime constant pool

The Java virtual machine maintains a per-type constant pool (§2.5.5), a runtime data structure that serves many of the purposes of the symbol table of a conventional programming language
implementation.

The constant_pooltable (§4.4) in the binary representation of a class or interface is used to construct the runtime constant pool upon class or interface creation (§5.3).

All references in the runtime constant pool are initially symbolic. The symbolic references in the runtime constant pool are derived from structures in the binary representation of the class or interface

JVM instructions refer to symbolic information in the constant_pooltable. JVM常量表用来构建常量池


2. Virtual Machine Start-up


3. Creating and loading

There are two kinds of class loaders: the bootstrap class loader supplied by the Java virtual machine, and user-defined class loaders. Every user-defined class loader is an instance of a subclass of the abstract class ClassLoader. Applications employ user-defined
class loaders in order to extend the manner in which the Java virtual machine dynamically loads and thereby creates classes. User-defined class loaders can be used to create classes that originate from user-defined sources. For example, a class could be downloaded
across a network, generated on the fly, or extracted from an encrypted file.

类加载器默认为classloader,用户也可以自己定义类加载器,继承 abstract class ClassLoader,以便实现从网络读取,从加密文件抽取等功能。

At runtime, a class or interface is determined not by its name alone, but by a pair: its binary name (§4.2.1) and its defining class loader. Each such class or interface belongs to a single runtime package. The runtime package of a class or interface is determined
by the package name and defining class loader of the class or interface。

在运行时,类或者接口由二进制名字和定义其的classloader决定。每个类有一个runtime package,包括包名和定义的classloader。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: