JVMS specification (1)-thestructure of the Java Virtual Matchine__java

Source: Internet
Author: User
Tags arithmetic float double

Subsections

1 Thestructure of the Java Virtual matchine

1.1 Theclass File Format

1.2 DataType

1.3 Primitivetypes and Values

1.3.1 The Numerictypes

1.3.2 the ReturnAddress Type and Values

1.3.3 the Boolean Type

1.4 Reference Types and Values

1.5 Runtime Data Areas

1.5.1 the PC Register

1.5.2 Java Virtual Machine Stacks

1.5.3 Heap

1.5.4 Method Area

1.5.5 Runtime Constant Pool

1.5.6 Native Method Stacks

1.6 Frames

1.6.1 Local Variables

1.6.2 Operand Stacks

1.6.3 Dynamic linking

1.6.4 Normal Method Invocation Completion

1.6.5 Abrupt method Invocation completion

1.7 Representation of Objects

1.8 Floating-point arithmetic

1.8.1 Java Virtual Machine floating-point arithmetic and IEEE 754

1.8.2 floating-point Modes

1.8.3 Value Set Conversion

1.9 Special Methods

1.10 Exceptions

1.11 Instructionset Summary

1.11.1 Types and the Java Virtual Machine

1.11.2 Load and Store instructions

1.11.3 Arithmetic Instructions

1.11.4 Type Conversion Instructions

1.11.5 Object creation and manipulation

1.11.6 Operand Stack Management Instructions

1.11.7 Control Transfer Instructions

1.11.8 method invocation and return instructions

1.11.9 Throwing Exceptions

1.11.1 Synchronization

1.12 classlibraries

1.13 publicdesign, Private implementation 1 The structureof the Java Virtual matchine

Toimplement the Java virtual machine correctly, you are need only is able to read Theclass file format and corrently perform O Perations Specifiedtherein. Implementation details this are not part of the Java Virtualmachine ' specification would unnecessarily the constrain Vity ofimplementors. For example,the memory layout of runtime data areas,thegarbage-collection algorithm Used,and any internal optimization of The javavirtual machine instructions (for example,translating them into machine code) are the left to the discretion of the Impl Ementor.
To implement the correct Java virtual machine, you only need to read the correct class format file and then execute the instructions correctly inside, and the implementation is not included in the Java Virtual Machine specification, which limits the creator's ability to create. For example, the Run-time data area of the memory layout, the use of garbage collector, and the optimization of internal instructions in Java virtual machines (such as converting them to machine code) are left to the implementation to judge for themselves. 1.1 The class File Format

Compiled code to being executed by the Javavirtual machine is represented using a hardware and operationgsystem-independent b Inary format,typically (but not necessarily) stored ina File,known as the class file format. The class file format precisely definesthe representation of a class or interface,including details such as Byteordering t Hat might be taken to granted in Aplatform-specific object FileFormat.

Compiling code that is executed by a Java Virtual machine is a binary format that is used independently by the hardware and the operating system. In general, (but not necessarily) stored as a class file, this class file accurately describes the class or interface, including details, such as byte order may be considered a platform-specific object file format. 1.2 Data Type

Like the Java programminglanguage,the Java Virtual Machine operates on two kind s of types:primitivetypes and reference Ty Pes. There are correspondingly,two kinds of values Thatcan is stored in variables,passed as arguments,returned by Method,and op Eratedupon:primitive values Andpreference valuesthe Java Virtual Machine expects that nearly all type Checkingis done Prio R to Runtime,typically by Compiler,and does is done bythe Java Virtual machine itself. Vales of primitive type Nedd not is tagged orotherwise is inspectable to  determine their in types, or to runtime istinguished fromvalues of reference types. Instead, the instruction set ofthe Java virtual machinedistinguishes its operand types using instructionsintended to Opera Te on values of specific types. For instance,  iadd, ladd,  fadd, and  dadd are all Java virtual machineinstructions that add two Nume Ric values and produce numeric results,but eachis specialized  for its operand type: int,  long,  float,and  double,respectively. For a summary of type support in the Java virtualmachine instruc-tion set. 
The Java virtual machine contains explicitsupport for objects. An object is either a dynamically allocated class Instanceor a array. A reference to the considered to have Java virtualmachine type reference. Values OfType Reference can be thought of as pointersto objects. More than one refer-ence to an object may exist. Objects are alwaysoperated on, passed, and tested via values of type
Like the Java programming language, two types of Java virtual machines work: basic data types and reference data types. The corresponding two values are stored in the variable, and are manipulated by the parameter of the method or by the return value. Java virtual machines want all types to be checked before they run, typically by compilers, and do not need Java virtual machines to do it themselves. Values for basic data types do not need to be marked, their types are checked at run time, and they are distinguished from reference types. Instead, the instruction set of the Java Virtual machine distinguishes the operand type using a directive to manipulate a particular type of value. Like Iadd,ladd,fadd,and Dadd. These are Java Virtual Machine directives that add two numeric values, resulting in a number, but between specific operand types, such as int long float double, are independent of each other.

Java virtual machines explicitly contain support objects, an object is an instance of a class or an array, and a reference to an object is considered to be a Java Virtual machine type reference, the value of a type reference is considered to be the object pointed to by the pointer, there may be multiple references to an object, and the object is always referenced, passed, or tested. 1.3 Primitive Types andvalues

Basic data types and values

The primitive data typessupported by the Java virtual machine are thenumeric

Types, the Boolean type (§2.3.4), 1 and the ReturnAddress type (§2.3.3). The

Numeric types consist ofthe integral types (§2.3.1) and the floating-point types

(§2.3.2). The Integraltypes are:

byte, whose values Are8-bit signed two ' s-complement integers, and whose

Default value is zero

short, whose values Are16-bit signed two ' s-complement integers, and whose

Default value is zero

int, whose values are32-bit signed two ' s-complement integers, and whose

Default value is zero

long, whose values Are64-bit signed two ' s-complement integers, and whose

Default value is zero

Char, whose values are16-bit unsigned integers representing Unicode code

Points in the Basic multilingual Plane, encoded with UTF-16, and whose

Default value is the null code point (' \u0000 ')

The floating-point types are:

float, whose values areelements of the float value set or, where supported,

The Float-extended-exponent value set, and whose default value is Positivezero

double, whose values areelements of the double value set or, where supported,

The Double-extended-exponent value set, and whose default value is Positivezero

The values of the Boolean type encode the truth values true and false, and the DefaultValue is false.

The values of the ReturnAddress type are pointers to the opcodes of Java

Virtual machine instructions. Of the primitive types only the ReturnAddress type isn't directlyassociated with a Java programming language type.

Basic data types supported by Java virtual machines are 1, numeric type, 2, Boolean type and 3, return address type

Numeric types include integers and floating-point types

Seven-integer

BYTE one byte for 8 bit, default is 0

Short one short takes 16 bit, default is 0

int an int takes up 32 bit and defaults to 0

Long a long takes 64 bit, default is 0

Char whose value is a 16-bit unsigned integer that represents the Unicode code. The default is ' \u0000 '. 1.3.1 The Numerictypes 1.3.1.1 Integral Types and Values

The values of the integral types of the Java virtual machine are:

for Byte, from−128 to 127 (−27 to 27−1), inclusive

Value range: [-128,127]

for short, from−32768 to 32767 (−215 to 215−1), inclusive

Value range: [−32768, 32767]

for int, from−2147483648 to 2147483647 (−231 to 231−1), inclusive

Value range: [−2147483648, 2147483647]

for long, from−9223372036854775808 to 9223372036854775807 (−263to 263−1), inclusive

Value range: [−9223372036854775808, 9223372036854775807]

for Char, from 0 to 65535inclusive

Value range: [0, 65535] 1.3.1.2 floating-pointtypes, value Sets, and values

The floating-point types are float and double, which areconceptually associated

With the 32-bit single-precision and 64-bit double-precision format IEEE754 values

and operations as specified in the IEEE Standard for Binaryfloating-point arithmetic,

Ansi/ieee Std. 754-1985 (IEEE, New York).

The IEEE 754 standard includes not only positive and negativesign-magnitude

Numbers, but also positive and negative zeros, positive and negativeinfinities,

and a special Not-a-number value (hereafter abbreviated as "NaN"). The

NaN value is used to represent the result of certain invalid Operationssuch as

Dividing zero by zero.

A floating-point number type includes a float type and a double type. Corresponds to the 32-bit single and 64-bit double-precision IEEE 754 format values. IEEE Standard binary Floating-point arithmetic

The IEEE 754 standard includes not only positive and negative signed data, but also positive, negative 0, positive, negative infinity

and a special Non-numeric number (hereinafter referred to as "non-digit"). The Nan value is used to indicate some invalid operations, such as the result 0 is removed by 0.

Added: The representation of signed numbers requires that negative numbers be encoded in binary form.

Binary signed and unsigned

01111111 127 127

10000000−0 128

10000001−1 129

Every implementation of the Java virtual machine is required to Supporttwo

Standard sets of floating-point values, called Thefloat Valuesetand the Double

Value set. In addition, a implementation of the Java Virtualmachine may

option, support either or both of two extended-exponent Floating-pointvalue sets,

Called the Float-extended-exponent value Setand thedouble-extended-exponent

Value set. These extended-exponent value sets may, under Certaincircumstances,

be used instead of the standard value sets to represent the values of typefloat or

Double.

The implementation of any one JVM must require support for two standard floating-point sets, float and double. In addition, some JVMS include extended single precision and extended double precision sets. These extended sets of precision are only substituted for the standard set in specific cases and do not represent float and double.

The finite nonzero values of any floating-point value set can all beexpressed

In the form s⋅m⋅2 (e−n + 1), where's +1 or−1, M is a positive integer less than

2N, and E is an integer betweenemin=− (2k−1−2) and Emax = 2k−1−1, inclusive,

And where N and K are parameters that depend on the value set. Some values

Can is represented in the more than one way; For example,supposing that

A value V in a value set might is represented in this form usingcertain values Fors,

M, and E, then if it happened thatmwere even and e were less the than 2k−1, one

Could halve M and Increaseeby 1 to produce a second for the representation

Value v. A representation inthis form is callednormalizedif m≥2n−1; otherwise

The representation is said to bedenormalized. If a value in Avalue set cannot is

Represented in such a way this m≥2n−1, then the value issaid to be a denormalized

Value, because it has no normalized representation.

The constraints on the Parametersnand K (and on the derived parameters

Emin and Emax) for the two required and two optional Floating-pointvalue, sets are

Summarized in Table 2.1.

Where one or both extended-exponent value sets are supported by Animplementation,

Then for each supported Extended-exponent value set there is a specific

Implementation-dependent CONSTANTK, whose value is constrained by Table 2.1;

This value K in turn dictates the values Foreminand Emax.

Each of the four value sets includes isn't only the finite nonzero valuesthat

Ascribed to it above, but also the five values positive zero, Negativezero, positive

Infinity, negative infinity, and NaN.

The constraints in Table 2.1 are designed so every elementof the

Float value set is necessarily also an element of thefloat-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 thedouble-

Extended-exponent value set. Each extended-exponent value set has a larger

Range of exponent values than the corresponding standard value set, Butdoes not

have more precision.

The elements of the float value set are exactly the values that can berepresented

Using the floating-point format defined in the IEEE 754 standard,

Except that there are only one Nan value (IEEE 754 specifies 224−2 distinct Nan

Values). The elements of the double value set are exactly the values thatcan be

Represented using the double floating-point format defined in the IEEE 754standard,

Except that there are only one NaN value (IEEE 754 specifies 253−2 distinct

NaN values). Note, however, the elements of Thefloat-extended-exponent and

Double-extended-exponent value sets defined here Donotcorrespond to thevalues

That is represented using IEEE 754 single extended and double Extendedformats,

respectively. This specification does isn't mandate a specificrepresentation for the

Values of the floating-point value sets except where floating-point valuesmust be

Represented in the class file format (§4.4.4,§4.4.5).

The float, float-extended-exponent, double, and double-extended-exponent

Value sets are not types. It is always correct for a implementation ofthe Java virtual

Machine to use an element of the float value set to represent a value oftype

Float However, it may is permissible in certain contexts Foran implementation

To use an element of the Float-extended-exponent value set instead. Similarly, it is

Always correct for a implementation to use an element of the double valueset to

Represent a value of type double; However, it may is permissible in certain con-

Table 2.1 Floating-point value set parameters

Parameter float

Float-extendedexponent

Double

Double-extendedexponent

N 24 24 53 53

K 8≥11 11≥15

Emax +127≥+1023 +1023≥+16383

emin−126≤−1022−1022≤−16382

The STRUCTURE O F the JAVA VIRTUAL MACHINE

Texts for a implementation to use an element of thedouble-extended-exponent

Value set instead.

Except for NaNs, values of the floating-point value sets areordered. When

Arranged from smallest to largest, they are negative, infinity values,

Positive and negative zero, positive finite values, and positive infinity.

Floating-point positive zero and floating-point negative zero compare as

Equal, but there are other operations that can distinguish them; Forexample, dividing

1.0 by 0.0 produces positive infinity, but dividing 1.0 by-0.0, produces

Negative infinity.

NaNs are unordered, so numerical comparisons and tests for numericalequality

Have the value false if either or both of their operands are NaN. Inparticular,

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.