java vm specification 1995.pdf

(388 KB) Pobierz
22971473 UNPDF
The Java Virtual Machine Specification
Release 1.0 Beta
DRAFT
August 21, 1995
22971473.002.png
Copyright Information
1993, 1994, 1995 Sun Microsystems, Inc.
2550 Garcia Avenue, Mountain View, California 94043-1100 U.S.A.
All rights reserved. This BETA quality release and related documentation are protected by copyright and distributed under
licenses restricting its use, copying, distribution, and decompilation. No part of this release or related documentation may be
reproduced in any form by any means without prior written authorization of Sun and its licensors, if any.
Portions of this product may be derived from the UNIX ® and Berkeley 4.3 BSD systems, licensed from UNIX System
Laboratories, Inc. and the University of California, respectively. Third-party font software in this release is protected by
copyright and licensed from Sun’s Font Suppliers.
RESTRICTED RIGHTS LEGEND: Use, duplication, or disclosure by the United States Government is subject to the restrictions
set forth in DFARS 252.227-7013 (c)(1)(ii) and FAR 52.227-19.
The release described in this manual may be protected by one or more U.S. patents, foreign patents, or pending applications.
TRADEMARKS
Sun, Sun Microsystems, Sun Microsystems Computer Corporation, the Sun logo, the Sun Microsystems Computer
Corporation logo, WebRunner, Java, FirstPerson and the FirstPerson logo and agent are trademarks or registered trademarks
of Sun Microsystems, Inc. The "Duke" character is a trademark of Sun Microsystems, Inc. and Copyright (c) 1992-1995 Sun
Microsystems, Inc. All Rights Reserved. UNIX ® is a registered trademark in the United States and other countries, exclusively
licensed through X/Open Comapny, Ltd. OPEN LOOK is a registered trademark of Novell, Inc. All other product names
mentioned herein are the trademarks of their respective owners.
All SPARC trademarks, including the SCD Compliant Logo, are trademarks or registered trademarks of SPARC International,
Inc. SPARCstation, SPARCserver, SPARCengine, SPARCworks, and SPARCompiler are licensed exclusively to Sun
Microsystems, Inc. Products bearing SPARC trademarks are based upon an architecture developed by Sun Microsystems, Inc.
The OPEN LOOK ® and Sun™ Graphical User Interfaces were developed by Sun Microsystems, Inc. for its users and licensees.
Sun acknowledges the pioneering efforts of Xerox in researching and developing the concept of visual or graphical user
interfaces for the computer industry. Sun holds a non-exclusive license from Xerox to the Xerox Graphical User Interface,
which license also covers Sun’s licensees who implement OPEN LOOK GUIs and otherwise comply with Sun’s written license
agreements.
X Window System is a trademark and product of the Massachusetts Institute of Technology.
THIS PUBLICATION IS PROVIDED “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
THIS PUBLICATION COULD INCLUDE TECHNICAL INACCURACIES OR TYPOGRAPHICAL ERRORS. CHANGES ARE
PERIODICALLY ADDED TO THE INFORMATION HEREIN; THESE CHANGES WILL BE INCORPORATED IN NEW
EDITIONS OF THE PUBLICATION. SUN MICROSYSTEMS, INC. MAY MAKE IMPROVEMENTS AND/OR CHANGES IN
THE PRODUCT(S) AND/OR THE PROGRAM(S) DESCRIBED IN THIS PUBLICATION AT ANY TIME.
Please
Recycle
Ó
22971473.003.png
Contents
Preface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
Chapter 1: Java Virtual Machine Architecture. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
Chapter 2: Class File Format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
2.1 Format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
2.2 Signatures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
2.3 Constant Pool. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
2.4 Fields . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
2.5 Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
2.6 Attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
Chapter 3: The Virtual Machine Instruction Set . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
3.1 Format for the Instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
3.2 Pushing Constants onto the Stack. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
3.3 Loading Local Variables Onto the Stack . . . . . . . . . . . . . . . . . . . . . . . . . . 30
3.4 Storing Stack Values into Local Variables . . . . . . . . . . . . . . . . . . . . . . . . . 33
3.5 Wider index for Loading, Storing and Incrementing . . . . . . . . . . . . . . . 35
3.6 Managing Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
3.7 Stack Instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
3.8 Arithmetic Instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
3.9 Logical Instructions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
3.10 Conversion Operations. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
3.11 Control Transfer Instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
3.12 Function Return. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
3.13 Table Jumping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
3.14 Manipulating Object Fields . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
3.15 Method Invocation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
3.16 Exception Handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
3.17 Miscellaneous Object Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
3.18 Monitors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
Appendix A: An Optimization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
A.1 Constant Pool Resolution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
A.2 Pushing Constants onto the Stack (_quick variants). . . . . . . . . . . . . . . . 74
A.3 Managing Arrays (_quick variants). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
A.4 Manipulating Object Fields (_quick variants) . . . . . . . . . . . . . . . . . . . . . 76
A.5 Method Invocation (_quick variants) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
A.6 Miscellaneous Object Operations (_quick variants) . . . . . . . . . . . . . . . . 80
Index of Instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
March 4, 1996
Java Virtual Machine Specification
3
22971473.004.png
4
Java Virtual Machine Specification
March 4, 1996
 
Preface
This document describes version 1.0 of the Java Virtual Machine and its instruction set. We have written this
document to act as a specification for both compiler writers, who wish to target the machine, and as a
specification for others who may wish to implement a compliant Java Virtual Machine.
The Java Virtual Machine is an imaginary machine that is implemented by emulating it in software on a real
machine. Code for the Java Virtual Machine is stored in .class files, each of which contains the code for at
most one public class.
Simple and efficient emulations of the Java Virtual Machine are possible because the machine’s format is
compact and efficient bytecodes. Implementations whose native code speed approximates that of compiled C
are also possible, by translating the bytecodes to machine code, although Sun has not released such
implementations at this time.
The rest of this document is structured as follows:
• Chapter 1 describes the architecture of the Java Virtual Machine.
• Chapter 2 describes the .class file format.
• Chapter 3 describes the bytecodes.
• Appendix A contains some instructions generated internally by Sun’s implementation of the Java
Virtual Machine. While not strictly part of the specification we describe these here so that this
specification can serve as a reference for our implementation. As more implementations of the Java
Virtual Machine become available, we may remove Appendix A from future releases.
Sun will license the Java Virtual Machine trademark and logo for use with compliant implementations of this
specification. If you are considering constructing your own implementation of the Java Virtual Machine please
contact us, at the email address below, so that we can work together to insure 100% compatiblity of your
implementation.
Send comments on this specification or questions about implementing the Java Virtual Machine to our
electronic mail address: java@java.sun.com .
August 22, 1995
Java Virtual Machine Specification
5
22971473.001.png
Zgłoś jeśli naruszono regulamin