Contents | Prev | Next | Index


The JavaTM Virtual Machine Specification

Tim Lindholm
Frank Yellin

(Converted from the printed book, September 1996, first printing)



Preface xv

1 Introduction 1

2 Java Concepts 5
2.1 Unicode 5
2.2 Identifiers 6
2.3 Literals 6
2.4 Types and Values 6
2.4.1 Primitive Types and Values 7
2.4.2 Operators on Integral Values 8
2.4.3 Operators on Floating-Point Values 8
2.4.4 Operators on boolean Values 9
2.4.5 Reference Types, Objects, and Reference Values 9
2.4.6 The Class Object 10
2.4.7 The Class String 10
2.4.8 Operators on Objects 10
2.5 Variables 10
2.5.1 Initial Values of Variables 12
2.5.2 Variables Have Types, Objects Have Classes 13
2.6 Conversions and Promotions 13
2.6.1 Identity Conversions 14
2.6.2 Widening Primitive Conversions 15
2.6.3 Narrowing Primitive Conversions 15
2.6.4 Widening Reference Conversions 16
2.6.5 Narrowing Reference Conversions 16
2.6.6 Assignment Conversion 17
2.6.7 Method Invocation Conversion 18
2.6.8 Casting Conversions 19
2.6.9 Numeric Promotion 19
2.7 Names and Packages 20
2.7.1 Names 20
2.7.2 Packages 20
2.7.3 Members 21
2.7.4 Package Members 21
2.7.5 The Members of a Class Type 21
2.7.6 The Members of an Interface Type 22
2.7.7 The Members of an Array Type 22
2.7.8 Qualified Names and Access Control 22
2.7.9 Fully Qualified Names 23
2.8 Classes 24
2.8.1 Class Names 24
2.8.2 Class Modifiers 24
2.8.3 Superclasses and Subclasses 25
2.8.4 The Class Members 25
2.9 Fields 26
2.9.1 Field Modifiers 26
2.9.2 Initialization of Fields 27
2.10 Methods 27
2.10.1 Formal Parameters 28
2.10.2 Signature 28
2.10.3 Method Modifiers 28
2.11 Static Initializers 29
2.12 Constructors 29
2.13 Interfaces 30
2.13.1 Interface Modifiers 31
2.13.2 Superinterfaces 31
2.13.3 Interface Members 31
2.13.4 Interface (Constant) Fields 31
2.13.5 Interface (Abstract) Methods 32
2.13.6 Overriding, Inheritance, and Overloading in Interfaces 32
2.14 Arrays 32
2.14.1 Array Types 33
2.14.2 Array Variables 33
2.14.3 Array Creation 34
2.14.4 Array Access 34
2.15 Exceptions 34
2.15.1 The Causes of Exceptions 35
2.15.2 Handling an Exception 36
2.15.3 The Exception Hierarchy 38
2.15.4 The Classes Exception and RuntimeException 38
2.16 Execution 40
2.16.1 Virtual Machine Start-up 40
2.16.2 Loading 43
2.16.3 Linking: Verification, Preparation, and Resolution 43
2.16.4 Initialization 46
2.16.5 Detailed Initialization Procedure 47
2.16.6 Creation of New Class Instances 49
2.16.7 Finalization of Class Instances 51
2.16.8 Finalization and Unloading of Classes and Interfaces 52
2.16.9 Virtual Machine Exit 52
2.17 Threads 53

3 Structure of the Java Virtual Machine 57
3.1 Data Types 57
3.2 Primitive Types and Values 58
3.2.1 Integral Types and Values 58
3.2.2 Floating-Point Types and Values 59
3.2.3 The returnAddress Type and Values 60
3.2.4 There Is No boolean Type 60
3.3 Reference Types and Values 61
3.4 Words 61
3.5 Runtime Data Areas 61
3.5.1 The pc Register 61
3.5.2 Java Stack 62
3.5.3 Heap 63
3.5.4 Method Area 63
3.5.5 Constant Pool 64
3.5.6 Native Method Stacks 65
3.6 Frames 66
3.6.1 Local Variables 66
3.6.2 Operand Stacks 67
3.6.3 Dynamic Linking 67
3.6.4 Normal Method Completion 68
3.6.5 Abnormal Method Completion 68
3.6.6 Additional Information 68
3.7 Representation of Objects 69
3.8 Special Initialization Methods 69
3.9 Exceptions 69
3.10 The class File Format 70
3.11 Instruction Set Summary 71
3.11.1 Types and the Java Virtual Machine 72
3.11.2 Load and Store Instructions 74
3.11.3 Arithmetic Instructions 75
3.11.4 Type Conversion Instructions 77
3.11.5 Object Creation and Manipulation 79
3.11.6 Operand Stack Management Instructions 79
3.11.7 Control Transfer Instructions 80
3.11.8 Method Invocation and Return Instructions 80
3.11.9 Throwing and Handling Exceptions 81
3.11.10 Implementing finally 81
3.11.11 Synchronization 81
3.12 Public Design, Private Implementation 81

4 The class File Format 83
4.1 ClassFile 84
4.2 Internal Form of Fully Qualified Class Names 89
4.3 Descriptors 89
4.3.1 Grammar Notation 90
4.3.2 Field Descriptors 90
4.3.3 Method Descriptors 91
4.4 Constant Pool 92
4.4.1 CONSTANT_Class 93
4.4.2 CONSTANT_Fieldref, CONSTANT_Methodref, and CONSTANT_InterfaceMethodref 94
4.4.3 CONSTANT_String 96
4.4.4 CONSTANT_Integer and CONSTANT_Float 96
4.4.5 CONSTANT_Long and CONSTANT_Double 97
4.4.6 CONSTANT_NameAndType 99
4.4.7 CONSTANT_Utf8 100
4.5 Fields 101
4.6 Methods 104
4.7 Attributes 106
4.7.1 Defining and Naming New Attributes 107
4.7.2 SourceFile Attribute 108
4.7.3 ConstantValue Attribute 109
4.7.4 Code Attribute 110
4.7.5 Exceptions Attribute 113
4.7.6 LineNumberTable Attribute 115
4.7.7 LocalVariableTable Attribute 116
4.8 Constraints on Java Virtual Machine Code 118
4.8.1 Static Constraints 118
4.8.2 Structural Constraints 121
4.9 Verification of class Files 124
4.9.1 The Verification Process 125
4.9.2 The Bytecode Verifier 128
4.9.3 Long Integers and Doubles 131
4.9.4 Instance Initialization Methods and Newly Created Objects 131
4.9.5 Exception Handlers 133
4.9.6 Exceptions and finally 133
4.10 Limitations of the Java Virtual Machine and class File Format 136

5 Constant Pool Resolution 139
5.1 Class and Interface Resolution 140
5.1.1 Current Class or Interface Not Loaded by a Class Loader 141
5.1.2 Current Class or Interface Loaded by a Class Loader 144
5.1.3 Array Classes 146
5.2 Field and Method Resolution 147
5.3 Interface Method Resolution 148
5.4 String Resolution 148
5.5 Resolution of Other Constant Pool Items 149

6 Java Virtual Machine Instruction Set 151
6.1 Assumptions: The Meaning of "Must" 151
6.2 Reserved Opcodes 152
6.3 Virtual Machine Errors 152
6.4 The Java Virtual Machine Instruction Set 152

7 Compiling for the Java Virtual Machine 339
7.1 Format of Examples 340
7.2 Use of Constants, Local Variables, and Control Constructs 341
7.3 Arithmetic 345
7.4 Accessing the Constant Pool 346
7.5 More Control Examples 348
7.6 Receiving Arguments 351
7.7 Invoking Methods 352
7.8 Working with Class Instances 354
7.9 Arrays 356
7.10 Compiling Switches 359
7.11 Operations on the Operand Stack 361
7.12 Throwing and Handling Exceptions 362
7.13 Compiling finally 366
7.14 Synchronization 369

8 Threads and Locks 371
8.1 Terminology and Framework 371
8.2 Execution Order and Consistency 373
8.3 Rules About Variables 374
8.4 Nonatomic Treatment of Double and Long Variables 376
8.5 Rules About Locks 376
8.6 Rules About the Interaction of Locks and Variables 377
8.7 Rules for Volatile Variables 378
8.8 Prescient Store Operations 378
8.9 Discussion 379
8.10 Example: Possible Swap 380
8.11 Example: Out-of-Order Writes 384
8.12 Threads 386
8.13 Locks and Synchronization 386
8.14 Wait Sets and Notification 387

9 An Optimization 389
9.1 Dynamic Linking via Rewriting 389
9.2 The _quick Pseudo-instructions 390

10 Opcode Mnemonics by Opcode 429

Contents | Prev | Next | Index

Java Virtual Machine Specification
Copyright © 1996, 1997 Sun Microsystems, Inc. All rights reserved
Please send any comments or corrections to jvm@java.sun.com