⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 overview.doc.html

📁 A Java virtual machine instruction consists of an opcode specifying the operation to be performed, f
💻 HTML
📖 第 1 页 / 共 5 页
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN"><html><head><title>VM Spec  The Structure of the  Java Virtual Machine</title></head><body BGCOLOR=#eeeeff text=#000000 LINK=#0000ff VLINK=#000077 ALINK=#ff0000><table width=100%><tr><td><a href="VMSpecTOC.doc.html">Contents</a> | <a href="Concepts.doc.html">Prev</a> | <a href="ClassFile.doc.html">Next</a> | <a href="VMSpecIX.fm.html">Index</a></td><td align=right><i><i>The Java<sup><font size=-2>TM</font></sup> Virtual Machine Specification</i></i></td></tr></table><hr><br> <a name="2839"></a><p><strong>CHAPTER 3 </strong></p><a name="25786"></a><h1>The Structure of the  Java Virtual Machine</h1><hr><p><a name="25787"></a>This book specifies an abstract machine. It does not document any particular implementation of the Java virtual machine, including Sun Microsystems'.<p><a name="25427"></a>To implement the Java virtual machine correctly, you need only be able to read the <code>class</code> file format and correctly perform the operations specified therein. Implementation details that are not part of the Java virtual machine's specification would unnecessarily constrain the creativity of implementors. For example, the memory layout of run-time data areas, the garbage-collection algorithm used, and any internal optimization of the Java virtual machine instructions (for example, translating them into machine code) are left to the discretion of the implementor. <p><a name="32310"></a><hr><h2>3.1    The <code><font size=+4>class</font></code> File Format</h2><a name="32311"></a>Compiled code to be executed by the Java virtual machine is represented using a hardware- and operating system-independent binary format, typically (but not necessarily)stored in a file, known as the <code>class</code> file format. The <code>class</code> file format preciselydefines the representation of a class or interface, including details such as byte ordering that might be taken for granted in a platform-specific object file format. <p><a name="32320"></a><a href="ClassFile.doc.html#80959">Chapter 4, "The <code>class</code> File Format"</a>, covers the <code>class</code> file format in detail.<p><a name="12237"></a><hr><h2>3.2    Data Types</h2><a name="15063"></a>Like the Java programming language, the Java virtual machine operates on two kinds of types: <i>primitive types</i> and <i>reference types</i>. There are, correspondingly, two kinds of values that can be stored in variables, passed as arguments, returned by methods, and operated upon: <i>primitive values</i> and <i>reference values</i>.<p><a name="15114"></a>The Java virtual machine expects that nearly all type checking is done prior to run time, typically by a compiler, and does not have to be done by the Java virtual machine itself. Values of primitive types need not be tagged or otherwise be inspectable to determine their types at run time, or to be distinguished from values of reference types. Instead, the instruction set of the Java virtual machine distinguishes its operand types using instructions intended to operate on values of specific types. For instance, <i>iadd</i>, <i>ladd</i>, <i>fadd</i>, and <i>dadd</i> are all Java virtual machine instructions that add two numeric values and produce numeric results, but each is specialized for its operand type: <code>int</code>, <code>long</code>, <code>float</code>, and <code>double</code>, respectively. For a summary of type support in the Java virtual machine instruction set, see <a href="Overview.doc.html#7565">&#167;3.11.1</a>.<p><a name="15118"></a>The Java virtual machine contains explicit support for objects. An object is either a dynamically allocated class instance or an array. A reference to an object is considered to have Java virtual machine type <code>reference</code>. Values of type <code>reference</code> can be thought of as pointers to objects. More than one reference to an object may exist. Objects are always operated on, passed, and tested via values of type <code>reference</code>. <p><a name="22239"></a><hr><h2>3.3    Primitive Types and Values</h2><a name="3560"></a>The primitive data types supported by the Java virtual machine are the <i>numeric types</i>, the <code>boolean</code> type <a href="Overview.doc.html#22909">(&#167;3.3.4)</a>,<a href="#33623"><sup>1</sup></a> and the <code>returnAddress</code> type <a href="Overview.doc.html#34568">(&#167;3.3.3)</a>. The numeric types consist of the <i>integral types</i> <a href="Overview.doc.html#31446">(&#167;3.3.1)</a> and the <i>floating-point types</i> <a href="Overview.doc.html#28147">(&#167;3.3.2)</a>. The integral types are:<p><ul><li><code>byte</code>, whose values are 8-bit signed two's-complement integers<p><li><code>short</code>, whose values are 16-bit signed two's-complement integers<p><li><code>int</code>, whose values are 32-bit signed two's-complement integers<p><li><code>long</code>, whose values are 64-bit signed two's-complement integers<p><li><code>char</code>, whose values are 16-bit unsigned integers representing Unicode characters <a href="Concepts.doc.html#25310">(&#167;2.1)</a></ul><a name="22892"></a>The floating-point types<i></i> are:<p><ul><li><code>float</code>, whose values are elements of the float value set or, where supported, the float-extended-exponent value set <p><li><code>double</code>, whose values are elements of the double value set or, where supported, the double-extended-exponent value set</ul><a name="31730"></a>The values of the <code>boolean</code> type encode the truth values <code>true</code> and <code>false</code>.<p><a name="31712"></a>The values of the <code>returnAddress</code> type are pointers to the opcodes of Java virtual machine instructions. Of the primitive types only the <code>returnAddress</code> type is not directly associated with a Java programming language type.<p><a name="31446"></a><h3>3.3.1    Integral Types and Values</h3><a name="25222"></a>The values of the integral types of the Java virtual machine are the same as those for the integral types of the Java programming language <a href="Concepts.doc.html#19511">(&#167;2.4.1)</a>:<p><ul><li>For <code>byte</code>, from -128 to 127 (-2<sup>7</sup> to 2<sup>7</sup>-1), inclusive<p><li>For <code>short</code>, from -32768 to 32767 (-2<sup>15</sup> to 2<sup>15</sup>-1), inclusive<p><li>For <code>int</code>, from -2147483648 to 2147483647 (-2<sup>31</sup> to 2<sup>31</sup>-1), inclusive<p><li>For <code>long</code>, from -9223372036854775808 to 9223372036854775807 (-2<sup>63</sup>  to 2<sup>63</sup>-1), inclusive<p><li>For <code>char</code>, from 0 to 65535 inclusive</ul><a name="28147"></a><h3>3.3.2    Floating-Point Types, Value Sets, and Values</h3><a name="29104"></a>The floating-point types are <code>float</code> and <code>double</code>, which are conceptually associated with the 32-bit single-precision and 64-bit double-precision format IEEE 754 values and operations as specified in <i>IEEE Standard for Binary Floating-Point Arithmetic</i>, ANSI/IEEE Std. 754-1985 (IEEE, New York).<p><a name="33745"></a>The IEEE 754 standard includes not only positive and negative sign-magnitude numbers, but also positive and negative zeros, positive and negative <i>infinities</i>, and a special <i>Not-a-Number value </i>(hereafter abbreviated as "NaN"). The NaN value is used to represent the result of certain invalid operations such as dividing zero by zero.<p><a name="33963"></a>Every implementation of the Java virtual machine is required to support two standard sets of floating-point values, called the <i>float value set</i> and the <i>double value set</i>. In addition, an implementation of the Java virtual machine may, at its option, support either or both of two extended-exponent floating-point value sets, called the<i> float-extended-exponent value set</i> and the<i> double-extended-exponent value set</i>. These extended-exponent value sets may, under certain circumstances, be used instead of the standard value sets to represent the values of type float or double.<p><a name="33964"></a>The finite nonzero values of any floating-point value set can all be expressed in the form s &#183; <i>m</i>&#183; &#32;2<sup>(e &#32;-N &#32;+ &#32;1)</sup>, where <i>s</i> is +1 or -1, <i>m</i> is a positive integer less than 2<sup>N</sup>, and <i>e</i> is an integer between <i>E</i>min = - (2<sup>K &#32;-1</sup>-2) and <i>E</i>max = 2<sup>K &#32;-1</sup>-1, inclusive, and where <i>N</i> and <i>K</i> are parameters that depend on the value set. Some values can be represented in this form in more than one way; for example, supposing that a value <i>v</i> in a value set might be represented in this form using certain values for <i>s</i>, <i>m</i>, and <i>e</i>, then if it happened that <i>m</i> were even and <i>e</i> were less than 2<sup>K &#32;-1</sup>, one could halve <i>m</i> and increase <i>e</i> by 1 to produce a second representation for the same value <i>v</i>. A representation in this form is called <i>normalized</i> if <i>m</i> <img src="chars/gtequal.gif"> 2<sup>N &#32;-1</sup>; otherwise the representation is said to be <i>denormalized</i>. If a value in a value set cannot be represented in such a way that <i>m</i> <img src="chars/gtequal.gif"> 2<sup>N &#32;-1</sup>, then the value is said to be a <i>denormalized value</i>, because it has no normalized representation.<p><a name="34070"></a>The constraints on the parameters <i>N</i> and <i>K</i> (and on the derived parameters <i>E</i>min and <i>E</i>max) for the two required and two optional floating-point value sets are summarized in <a href="Overview.doc.html#34123">Table 3.1</a>.<a name="34123"></a><p><Table Border="1"><tr><th><b><i></i></b><b><i>Parameter</i></b><th><b><i></i></b><b><i>float</i></b><th><b><i>float-extended-exponent</i></b><th><b><i></i></b><b><i>double</i></b><th><b><i>double-extended- exponent</i></b><tr><td><a name="34083"></a><i>N</i><td><a name="34085"></a>24<td><a name="34087"></a>24<td><a name="34089"></a>53<td><a name="34091"></a>53<tr><td><a name="34093"></a>K<td><a name="34095"></a>8<td><a name="34097"></a><img src="chars/gtequal.gif"> 11<td><a name="34099"></a>11<td><a name="34101"></a><img src="chars/gtequal.gif"> 15<tr><td><a name="34103"></a><i>E</i>max<td><a name="34105"></a>+127<td><a name="34107"></a><img src="chars/gtequal.gif"> +1023<td><a name="34109"></a>+1023<td><a name="34111"></a><img src="chars/gtequal.gif"> +16383<tr><td><a name="34113"></a><i>E</i>min<td><a name="34115"></a>-126<td><a name="34117"></a><img src="chars/lt_equal.gif"> -1022<td><a name="34119"></a>-1022<td><a name="34121"></a><img src="chars/lt_equal.gif"> -16382</Table><br><br><p><a name="36244"></a>Where one or both extended-exponent value sets are supported by an implementation, then for each supported extended-exponent value set there is a specific implementation-dependent constant <i>K</i>, whose value is constrained by <a href="Overview.doc.html#34123">Table 3.1</a>; this value <i>K</i> in turn dictates the values for <i>E</i>min and <i>E</i>max.<p><a name="34020"></a>Each of the four value sets includes not only the finite nonzero values that are ascribed to it above, but also the five values positive zero, negative zero, positive infinity, negative infinity, and NaN.<p><a name="34021"></a>Note that the constraints in <a href="Overview.doc.html#34123">Table 3.1</a> are designed so that every element of the float value set is necessarily also an element of the float-extended-exponent value set, the double value set, and the double-extended-exponent value set. Likewise, each element of the double value set is necessarily also an element of the double-extended-exponent value set. Each extended-exponent value set has a larger range of exponent values than the corresponding standard value set, but does not have more precision.<p><a name="32626"></a>The elements of the float value set are exactly the values that can be represented using the single floating-point format defined in the IEEE 754 standard, except that there is only one NaN value (IEEE 754 specifies 2<sup>24</sup> - 2 distinct NaN values). The elements of the double value set are exactly the values that can be represented using the double floating-point format defined in the IEEE 754 standard, except that there is only one NaN value (IEEE 754 specifies 2<sup>53</sup> - 2 distinct NaN values). Note, however, that the elements of the float-extended-exponent and double-extended-exponent value sets defined here do <i>not</i> correspond to the values that be represented using IEEE 754 single extended and double extended formats, respectively. This specification does not mandate a specific representation for the values of the floating-point value sets except where floating-point values must be represented in the <code>class</code> file format (<a href="ClassFile.doc.html#21942">&#167;4.4.4</a>, <a href="ClassFile.doc.html#1348">&#167;4.4.5)</a>.<p><a name="33767"></a>The float, float-extended-exponent, double, and double-extended-exponent value sets are not types. It is always correct for an implementation of the Java virtual machine to use an element of the float value set to represent a value of type float; however, it may be permissible in certain contexts for an implementation to use an element of the float-extended-exponent value set instead. Similarly, it is always correct for an implementation to use an element of the double value set to represent a value of type double; however, it may be permissible in certain contexts for an implementation to use an element of the double-extended-exponent value set instead.<p><a name="28247"></a>Except for NaNs, values of the floating-point value sets are <i>ordered</i>. When arranged from smallest to largest, they are negative infinity, negative finite values, positive and negative zero, positive finite values, and positive infinity.<p><a name="28249"></a>Floating-point positive zero and floating-point negative zero compare as equal, but there are other operations that can distinguish them; for example, dividing <code>1.0</code> by <code>0.0</code> produces positive infinity, but dividing <code>1.0</code> by <code>-0.0</code> produces negative infinity.<p><a name="34565"></a>NaNs are <i>unordered</i>, so numerical comparisons and tests for numerical equality have the value <code>false</code> if either or both of their operands are NaN. In particular, a test for numerical equality of a value against itself has the value <code>false</code> if and only if the value is NaN. A test for numerical inequality has the value <code>true</code> if either operand is NaN.<p><a name="34568"></a><h3>3.3.3    The <code>returnAddress</code> Type and Values</h3><a name="34571"></a>The <code>returnAddress</code> type is used by the Java virtual machine's <i>jsr</i>, <i>ret</i>, and <i>jsr_w</i> instructions. The values of the <code>returnAddress</code> type are pointers to the opcodes of Java virtual machine instructions. Unlike the numeric primitive types, the <code>returnAddress</code> type does not correspond to any Java programming language type and cannot be modified by the running program.<p><a name="22909"></a><h3>3.3.4    The <code>boolean</code> Type</h3><a name="22914"></a>Although the Java virtual machine defines a <code>boolean</code> type, it only provides very limited support for it. There are no Java virtual machine instructions solely dedicatedto operations on <code>boolean</code> values. Instead, expressions in the Java programminglanguage that operate on <code>boolean</code> values are compiled to use values of the Java virtual machine <code>int</code> data type. <p><a name="22912"></a>The Java virtual machine does directly support <code>boolean</code> arrays. Its <i>newarray</i> instruction enables creation of <code>boolean</code> arrays. Arrays of type <code>boolean</code> are accessed and modified using the <code>byte</code> array instructions <i>baload</i> and <i>bastore</i>.<a href="#24357"><sup>2</sup></a><p><a name="31764"></a>The Java virtual machine encodes <code>boolean</code> array components using <i>1</i> to represent <code>true</code> and <i>0</i> to represent <code>false</code>. Where Java programming language <code>boolean</code> values are mapped by compilers to values of Java virtual machine type <code>int</code>, the compilers must use the same encoding. <p><a name="15079"></a><hr><h2>3.4    Reference Types and Values</h2><a name="15127"></a>There are three kinds of <code>reference</code> types: class types, array types, and interface types. Their values are references to dynamically created class instances, arrays, or class instances or arrays that implement interfaces, respectively. A <code>reference</code> value may also be the special null reference, a reference to no object, which will be denoted here by <code>null</code>. The <code>null</code> reference initially has no runtime type, but may be cast to any type <a href="Concepts.doc.html#22930">(&#167;2.4)</a>. <p><a name="31978"></a>The Java virtual machine specification does not mandate a concrete value encoding <code>null</code>.<p><a name="1732"></a><hr><h2>3.5    Runtime Data Areas</h2><a name="35268"></a>The Java virtual machine defines various runtime data areas that are used during execution of a program. Some of these data areas are created on Java virtual machine start-up and are destroyed only when the Java virtual machine exits. Other data areas are per thread. Per-thread data areas are created when a thread is created and destroyed when the thread exits.<p><a name="6648"></a><h3>3.5.1    The <code>pc</code> Register</h3><a name="25816"></a>The Java virtual machine can support many threads of execution at once <a href="Concepts.doc.html#33308">(&#167;2.19)</a>. Each Java virtual machine thread has its own <code>pc</code> (program counter) register. At any point, each Java virtual machine thread is executing the code of a single method, the 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -