Java Virtual Machine 1

The Structure of the Java Virtual Machine

THIS document specifies an abstract machine. 

It does not describe any particular implementation of the Java Virtual Machine.

To implement the Java Virtual Machine correctly, 

you need only be able to read the class 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.

All references to Unicode in this specification are given with respect to The Unicode Standard, Version 6.0.0, available at http://www.unicode.org/.
2.1 The class File Format

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 class file format. 

The class file format precisely defines 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.


Chapter 4, "The 
precisely defines 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.

Chapter 4, "The class File Format", covers the class file format in detail.


2.2 Data Types THE STRUCTURE OF THE JAVA VIRTUAL MACHINE

Like the Java programming language, the Java Virtual Machine operates on two kinds of types: 

primitive types and reference types

There are, correspondingly, two kinds of values that can be stored in variables, passed as arguments, returned by
methods, and operated upon:

kinds of values that can be stored in variables, passed as arguments, returned by methods, and operated upon: primitive values and reference values.

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, iadd, ladd, fadd, and dadd are all Java Virtual Machine instructions that add two numeric values and produce numeric results, but each is specialized for its operand type: int, long, float, and double, respectively. 

For a summary of type support in the Java Virtual Machine instruction set, see §2.11.1.

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 reference

Values of type reference 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 reference.

2.3 Primitive Types and Values
The primitive data types supported by the Java Virtual Machine are the numeric types, the boolean type (§2.3.4), and the returnAddress type (§2.3.3).
The numeric types consist of the
integral types (§2.3.1) and the floating-point types(§2.3.2).
The integral types are:
byte, whose values are 8-bit signed two's-complement integers, and whose default value is zero
short, whose values are 16-bit signed two's-complement integers, and whose default value is zero

THE STRUCTURE OF THE JAVA VIRTUAL MACHINE 

Primitive Types and Values 2.3

int, whose values are 32-bit signed two's-complement integers, and whose default value is zero
long, whose values are 64-bit signed two's-complement integers, and whose default value is zero
char, whose values are 16-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 are elements of the float value set or, 

where supported, the float-extended-exponent value set, and whose default value is positive zero

double, whose values are elements of the double value set or, where supported,
the double-extended-exponent value set, and whose default value is positive zero
The values of the
boolean type encode the truth values true and false, and the default value is false.

The Java Virtual Machine Specification, First Edition did not consider boolean to be a Java Virtual Machine type. However, boolean values do have limited support in the Java Virtual Machine. 

The Java Virtual Machine Specification, Second Edition clarified the issue by treating

by treating boolean as a type.
The values of the returnAddress type are pointers to the opcodes of Java Virtual
Machine instructions. Of the primitive types, only the
returnAddress type is not
directly associated with a Java programming language type.
2.3.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
• For
short, from -32768 to 32767 (-215 to 215 - 1), inclusive
• For
int, from -2147483648 to 2147483647 (-231 to 231 - 1), inclusive
• For
long, from -9223372036854775808 to 9223372036854775807 (-263 to 263
- 1), inclusive
• For
char, from 0 to 65535 inclusive
2.3 Primitive Types and Values THE STRUCTURE OF THE JAVA VIRTUAL MACHINE
2.3.2 Floating-Point Types, Value Sets, and Values
The floating-point types are float and double, which are conceptually associated
with the 32-bit single-precision and 64-bit double-precision format IEEE 754
values and operations as specified in
IEEE Standard for Binary Floating-Point
Arithmetic
(ANSI/IEEE Std. 754-1985, New York).
The IEEE 754 standard includes not only positive and negative sign-magnitude
numbers, but also positive and negative zeros, positive and negative
infinities, and
a special Not-a-Number value (hereafter abbreviated as "NaN"). The NaN value
is used to represent the result of certain invalid operations such as dividing zero
by zero.
Every implementation of the Java Virtual Machine is required to support two
standard sets of floating-point values, called the
float value set and the double value

set

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

support either or both of two extended-exponent floating-point value sets, called
the
float-extended-exponent value set and the double-extended-exponent value set.
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.
The finite nonzero values of any floating-point value set can all be expressed in
the form
s m 2(e - N + 1), where s is +1 or -1, m is a positive integer less than
2
N, and e is an integer between Emin = -(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 be represented in this form in more than one way; 

for example, supposing that a value be represented in this form in more than one way; 

for example, supposing that a value v in a value set might be represented in this form using certain values for

s, m, and e, then if it happened that m were even and e were less than 2K-1

one could halve m and increase e by 1 to produce a second representation for the same value value v

A representation in this form is called normalized if m 2N-1

otherwise the representation is said to be denormalized

If a value in a value set cannot be represented in such a way that m 2N-1

then the value is said to be a denormalized value, because it has no normalized representation.

The constraints on the parameters N and K (and on the derived parameters Emin
and Emax) for the two required and two optional floating-point value sets are
summarized in Table 2.1.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值