logo资料库

jvm官方文档.pdf

第1页 / 共606页
第2页 / 共606页
第3页 / 共606页
第4页 / 共606页
第5页 / 共606页
第6页 / 共606页
第7页 / 共606页
第8页 / 共606页
资料共606页,剩余部分请下载后查看
The Java® Virtual Machine Specification
Table of Contents
Preface to the Java SE 7 Edition
Preface to the Second Edition
Preface to the First Edition
1. Introduction
1.1. A Bit of History
1.2. The Java Virtual Machine
1.3. Summary of Chapters
1.4. Notation
2. The Structure of the Java Virtual Machine
2.1. The class File Format
2.2. Data Types
2.3. Primitive Types and Values
2.3.1. Integral Types and Values
2.3.2. Floating-Point Types, Value Sets, and Values
2.3.3. The returnAddress Type and Values
2.3.4. The boolean Type
2.4. Reference Types and Values
2.5. Run-Time Data Areas
2.5.1. The pc Register
2.5.2. Java Virtual Machine Stacks
2.5.3. Heap
2.5.4. Method Area
2.5.5. Run-Time Constant Pool
2.5.6. Native Method Stacks
2.6. Frames
2.6.1. Local Variables
2.6.2. Operand Stacks
2.6.3. Dynamic Linking
2.6.4. Normal Method Invocation Completion
2.6.5. Abrupt Method Invocation Completion
2.7. Representation of Objects
2.8. Floating-Point Arithmetic
2.8.1. Java Virtual Machine Floating-Point Arithmetic and IEEE 754
2.8.2. Floating-Point Modes
2.8.3. Value Set Conversion
2.9. Special Methods
2.10. Exceptions
2.11. Instruction Set Summary
2.11.1. Types and the Java Virtual Machine
2.11.2. Load and Store Instructions
2.11.3. Arithmetic Instructions
2.11.4. Type Conversion Instructions
2.11.5. Object Creation and Manipulation
2.11.6. Operand Stack Management Instructions
2.11.7. Control Transfer Instructions
2.11.8. Method Invocation and Return Instructions
2.11.9. Throwing Exceptions
2.11.10. Synchronization
2.12. Class Libraries
2.13. Public Design, Private Implementation
3. Compiling for the Java Virtual Machine
3.1. Format of Examples
3.2. Use of Constants, Local Variables, and Control Constructs
3.3. Arithmetic
3.4. Accessing the Run-Time Constant Pool
3.5. More Control Examples
3.6. Receiving Arguments
3.7. Invoking Methods
3.8. Working with Class Instances
3.9. Arrays
3.10. Compiling Switches
3.11. Operations on the Operand Stack
3.12. Throwing and Handling Exceptions
3.13. Compiling finally
3.14. Synchronization
3.15. Annotations
4. The class File Format
4.1. The ClassFile Structure
4.2. The Internal Form of Names
4.2.1. Binary Class and Interface Names
4.2.2. Unqualified Names
4.3. Descriptors and Signatures
4.3.1. Grammar Notation
4.3.2. Field Descriptors
4.3.3. Method Descriptors
4.3.4. Signatures
4.4. The Constant Pool
4.4.1. The CONSTANT_Class_info Structure
4.4.2. The CONSTANT_Fieldref_info, CONSTANT_Methodref_info, and CONSTANT_InterfaceMethodref_info Structures
4.4.3. The CONSTANT_String_info Structure
4.4.4. The CONSTANT_Integer_info and CONSTANT_Float_info Structures
4.4.5. The CONSTANT_Long_info and CONSTANT_Double_info Structures
4.4.6. The CONSTANT_NameAndType_info Structure
4.4.7. The CONSTANT_Utf8_info Structure
4.4.8. The CONSTANT_MethodHandle_info Structure
4.4.9. The CONSTANT_MethodType_info Structure
4.4.10. The CONSTANT_InvokeDynamic_info Structure
4.5. Fields
4.6. Methods
4.7. Attributes
4.7.1. Defining and Naming New Attributes
4.7.2. The ConstantValue Attribute
4.7.3. The Code Attribute
4.7.4. The StackMapTable Attribute
4.7.5. The Exceptions Attribute
4.7.6. The InnerClasses Attribute
4.7.7. The EnclosingMethod Attribute
4.7.8. The Synthetic Attribute
4.7.9. The Signature Attribute
4.7.10. The SourceFile Attribute
4.7.11. The SourceDebugExtension Attribute
4.7.12. The LineNumberTable Attribute
4.7.13. The LocalVariableTable Attribute
4.7.14. The LocalVariableTypeTable Attribute
4.7.15. The Deprecated Attribute
4.7.16. The RuntimeVisibleAnnotations attribute
4.7.16.1. The element_value structure
4.7.17. The RuntimeInvisibleAnnotations attribute
4.7.18. The RuntimeVisibleParameterAnnotations attribute
4.7.19. The RuntimeInvisibleParameterAnnotations attribute
4.7.20. The AnnotationDefault attribute
4.7.21. The BootstrapMethods attribute
4.8. Format Checking
4.9. Constraints on Java Virtual Machine code
4.9.1. Static Constraints
4.9.2. Structural Constraints
4.10. Verification of class Files
4.10.1. Verification by Type Checking
4.10.1.1. Accessors for Java Virtual Machine Artifacts
4.10.1.2. Verification Type System
4.10.1.3. Instruction Representation
4.10.1.4. Stack Map Frame Representation
4.10.1.5. Type Checking Abstract and Native Methods
4.10.1.6. Type Checking Methods with Code
4.10.1.7. Type Checking Load and Store Instructions
4.10.1.8. Type Checking for protected Members
4.10.1.9. Type Checking Instructions
aaload
aastore
aconst_null
aload
aload_
anewarray
areturn
arraylength
astore
astore_
athrow
baload
bastore
bipush
caload
castore
checkcast
d2f
d2i
d2l
dadd
daload
dastore
dcmp
dconst_
ddiv
dload
dload_
dmul
dneg
drem
dreturn
dstore
dstore_
dsub
dup
dup_x1
dup_x2
dup2
dup2_x1
dup2_x2
f2d
f2i
f2l
fadd
faload
fastore
fcmp
fconst_
fdiv
fload
fload_
fmul
fneg
frem
freturn
fstore
fstore_
fsub
getfield
getstatic
goto
goto_w
i2b
i2c
i2d
i2f
i2l
i2s
iadd
iaload
iand
iastore
if_acmp
if_icmp
if
ifnonnull
ifnull
iinc
iload
iload_
imul
ineg
instanceof
invokedynamic
invokeinterface
invokespecial
invokestatic
invokevirtual
ior
irem
ireturn
ishl
ishr
istore
istore_
isub
iushr
ixor
l2d
l2f
l2i
ladd
laload
land
lastore
lcmp
lconst_
ldc
ldc_w
ldc2_w
ldiv
lload
lload_
lmul
lneg
lookupswitch
lor
lrem
lreturn
lshl
lshr
lstore
lstore_
lsub
lushr
lxor
monitorenter
monitorexit
multianewarray
new
newarray
nop
pop
pop2
putfield
putstatic
return
saload
sastore
sipush
swap
tableswitch
wide
4.10.2. Verification by Type Inference
4.10.2.1. The Process of Verification by Type Inference
4.10.2.2. The Bytecode Verifier
4.10.2.3. Values of Types long and double
4.10.2.4. Instance Initialization Methods and Newly Created Objects
4.10.2.5. Exceptions and finally
4.11. Limitations of the Java Virtual Machine
5. Loading, Linking, and Initializing
5.1. The Run-Time Constant Pool
5.2. Java Virtual Machine Startup
5.3. Creation and Loading
5.3.1. Loading Using the Bootstrap Class Loader
5.3.2. Loading Using a User-defined Class Loader
5.3.3. Creating Array Classes
5.3.4. Loading Constraints
5.3.5. Deriving a Class from a class File Representation
5.4. Linking
5.4.1. Verification
5.4.2. Preparation
5.4.3. Resolution
5.4.3.1. Class and Interface Resolution
5.4.3.2. Field Resolution
5.4.3.3. Method Resolution
5.4.3.4. Interface Method Resolution
5.4.3.5. Method Type and Method Handle Resolution
5.4.3.6. Call Site Specifier Resolution
5.4.4. Access Control
5.4.5. Method overriding
5.5. Initialization
5.6. Binding Native Method Implementations
5.7. Java Virtual Machine Exit
6. The Java Virtual Machine Instruction Set
6.1. Assumptions: The Meaning of "Must"
6.2. Reserved Opcodes
6.3. Virtual Machine Errors
6.4. Format of Instruction Descriptions
mnemonic
6.5. Instructions
aaload
aastore
aconst_null
aload
aload_
anewarray
areturn
arraylength
astore
astore_
athrow
baload
bastore
bipush
caload
castore
checkcast
d2f
d2i
d2l
dadd
daload
dastore
dcmp
dconst_
ddiv
dload
dload_
dmul
dneg
drem
dreturn
dstore
dstore_
dsub
dup
dup_x1
dup_x2
dup2
dup2_x1
dup2_x2
f2d
f2i
f2l
fadd
faload
fastore
fcmp
fconst_
fdiv
fload
fload_
fmul
fneg
frem
freturn
fstore
fstore_
fsub
getfield
getstatic
goto
goto_w
i2b
i2c
i2d
i2f
i2l
i2s
iadd
iaload
iand
iastore
iconst_
idiv
if_acmp
if_icmp
if
ifnonnull
ifnull
iinc
iload
iload_
imul
ineg
instanceof
invokedynamic
invokeinterface
invokespecial
invokestatic
invokevirtual
ior
irem
ireturn
ishl
ishr
istore
istore_
isub
iushr
ixor
jsr
jsr_w
l2d
l2f
l2i
ladd
laload
land
lastore
lcmp
lconst_
ldc
ldc_w
ldc2_w
ldiv
lload
lload_
lmul
lneg
lookupswitch
lor
lrem
lreturn
lshl
lshr
lstore
lstore_
lsub
lushr
lxor
monitorenter
monitorexit
multianewarray
new
newarray
nop
pop
pop2
putfield
putstatic
ret
return
saload
sastore
sipush
swap
tableswitch
wide
7. Opcode Mnemonics by Opcode
Index
A. Limited License Grant
The Java® Virtual Machine Specification Java SE 7 Edition Tim Lindholm Frank Yellin Gilad Bracha Alex Buckley 2013-02-28
Specification: JSR-000924 Java® Virtual Machine Specification ("Specification") Version: 7 Status: Final Release Release: July 2011 Copyright © 1997, 2013, Oracle America, Inc. and/or its affiliates. All rights reserved. 500 Oracle Parkway, Redwood City, California 94065, U.S.A. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners. The Specification provided herein is provided to you only under the Limited License Grant included herein as Appendix A. Please see Appendix A, Limited License Grant.
Table of Contents Preface to the Java SE 7 Edition xi Preface to the Second Edition xiii Preface to the First Edition xv 1 Introduction 1 1.1 1.2 1.3 1.4 A Bit of History 1 The Java Virtual Machine 2 Summary of Chapters 3 Notation 4 2 The Structure of the Java Virtual Machine 5 2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.8 The pc Register 12 Java Virtual Machine Stacks 12 Heap 13 The class File Format 5 Data Types 6 Primitive Types and Values 6 Integral Types and Values 7 2.3.1 Floating-Point Types, Value Sets, and Values 8 2.3.2 The returnAddress Type and Values 10 2.3.3 2.3.4 The boolean Type 10 Reference Types and Values 11 Run-Time Data Areas 11 2.5.1 2.5.2 2.5.3 2.5.4 Method Area 13 2.5.5 2.5.6 Frames 15 2.6.1 2.6.2 2.6.3 2.6.4 2.6.5 Representation of Objects 19 Floating-Point Arithmetic 19 2.8.1 Local Variables 16 Operand Stacks 17 Dynamic Linking 18 Normal Method Invocation Completion 18 Abrupt Method Invocation Completion 18 Run-Time Constant Pool 14 Native Method Stacks 14 Java Virtual Machine Floating-Point Arithmetic and IEEE 754 19 Floating-Point Modes 20 2.8.2 iii
The Java® Virtual Machine Specification 2.9 2.10 2.11 Value Set Conversion 20 2.8.3 Special Methods 21 Exceptions 23 Instruction Set Summary 25 2.11.1 Types and the Java Virtual Machine 26 2.11.2 Load and Store Instructions 29 2.11.3 Arithmetic Instructions 30 2.11.4 Type Conversion Instructions 32 2.11.5 Object Creation and Manipulation 34 2.11.6 Operand Stack Management Instructions 34 2.11.7 Control Transfer Instructions 34 2.11.8 Method Invocation and Return Instructions 35 2.11.9 Throwing Exceptions 36 2.11.10 Synchronization 36 2.12 Class Libraries 37 2.13 Public Design, Private Implementation 37 3 Compiling for the Java Virtual Machine 39 Format of Examples 39 Use of Constants, Local Variables, and Control Constructs 40 Arithmetic 45 Accessing the Run-Time Constant Pool 46 Receiving Arguments 49 Invoking Methods 50 3.1 3.2 3.3 3.4 3.5 More Control Examples 47 3.6 3.7 3.8 Working with Class Instances 53 3.9 3.10 Compiling Switches 57 3.11 Operations on the Operand Stack 58 3.12 3.13 Compiling finally 63 3.14 3.15 Annotations 67 Synchronization 66 Arrays 55 Throwing and Handling Exceptions 59 4 The class File Format 69 Binary Class and Interface Names 75 Unqualified Names 75 The ClassFile Structure 70 The Internal Form of Names 75 4.2.1 4.2.2 Descriptors and Signatures 75 Grammar Notation 76 4.3.1 4.3.2 Field Descriptors 76 4.3.3 Method Descriptors 78 4.3.4 Signatures 79 The Constant Pool 82 4.4.1 The CONSTANT_Class_info Structure 83 4.1 4.2 4.3 4.4 iv
The Java® Virtual Machine Specification 4.4.2 4.4.3 4.4.4 4.4.5 The CONSTANT_Fieldref_info, CONSTANT_Methodref_info, and CONSTANT_InterfaceMethodref_info Structures 84 The CONSTANT_String_info Structure 86 The CONSTANT_Integer_info and CONSTANT_Float_info Structures 86 The CONSTANT_Long_info and CONSTANT_Double_info Structures 88 The CONSTANT_NameAndType_info Structure 89 The CONSTANT_Utf8_info Structure 90 The CONSTANT_MethodHandle_info Structure 92 The CONSTANT_MethodType_info Structure 93 4.4.6 4.4.7 4.4.8 4.4.9 4.4.10 The CONSTANT_InvokeDynamic_info Structure 94 Fields 95 4.5 4.6 Methods 97 4.7 Attributes 100 Defining and Naming New Attributes 102 4.7.1 The ConstantValue Attribute 103 4.7.2 The Code Attribute 104 4.7.3 The StackMapTable Attribute 107 4.7.4 The Exceptions Attribute 115 4.7.5 The InnerClasses Attribute 116 4.7.6 The EnclosingMethod Attribute 119 4.7.7 The Synthetic Attribute 120 4.7.8 4.7.9 The Signature Attribute 120 4.7.10 The SourceFile Attribute 121 4.7.11 The SourceDebugExtension Attribute 122 4.7.12 The LineNumberTable Attribute 123 4.7.13 The LocalVariableTable Attribute 124 4.7.14 The LocalVariableTypeTable Attribute 126 4.7.15 The Deprecated Attribute 128 4.7.16 The RuntimeVisibleAnnotations attribute 128 4.7.16.1 The element_value structure 130 4.7.17 The RuntimeInvisibleAnnotations attribute 133 4.7.18 The RuntimeVisibleParameterAnnotations attribute 134 4.7.19 The RuntimeInvisibleParameterAnnotations attribute 136 4.7.20 The AnnotationDefault attribute 137 4.7.21 The BootstrapMethods attribute 138 Format Checking 140 Constraints on Java Virtual Machine code 140 4.9.1 4.9.2 Static Constraints 141 Structural Constraints 144 4.8 4.9 4.10 Verification of class Files 148 4.10.1 Verification by Type Checking 149 4.10.1.1 Accessors for Java Virtual Machine Artifacts 152 4.10.1.2 Verification Type System 155 Instruction Representation 159 4.10.1.3 4.10.1.4 Stack Map Frame Representation 160 4.10.1.5 Type Checking Abstract and Native Methods 166 v
The Java® Virtual Machine Specification 4.10.1.6 Type Checking Methods with Code 167 4.10.1.7 Type Checking Load and Store Instructions 174 4.10.1.8 Type Checking for protected Members 176 4.10.1.9 Type Checking Instructions 179 4.10.2 Verification by Type Inference 327 4.10.2.1 The Process of Verification by Type Inference 327 4.10.2.2 The Bytecode Verifier 328 4.10.2.3 Values of Types long and double 330 4.10.2.4 Instance Initialization Methods and Newly Created Objects 331 4.11 Limitations of the Java Virtual Machine 334 4.10.2.5 Exceptions and finally 332 5 Loading, Linking, and Initializing 337 5.1 5.2 5.3 5.4 5.5 5.6 5.7 The Run-Time Constant Pool 337 Java Virtual Machine Startup 340 Creation and Loading 340 5.3.1 5.3.2 5.3.3 5.3.4 5.3.5 Linking 347 5.4.1 5.4.2 5.4.3 Loading Using the Bootstrap Class Loader 342 Loading Using a User-defined Class Loader 343 Creating Array Classes 344 Loading Constraints 344 Deriving a Class from a class File Representation 346 Class and Interface Resolution 350 Field Resolution 351 Verification 348 Preparation 348 Resolution 349 5.4.3.1 5.4.3.2 5.4.3.3 Method Resolution 352 5.4.3.4 5.4.3.5 Method Type and Method Handle Resolution 354 5.4.3.6 Access Control 358 Call Site Specifier Resolution 357 Interface Method Resolution 353 5.4.4 5.4.5 Method overriding 359 Initialization 359 Binding Native Method Implementations 362 Java Virtual Machine Exit 362 6 The Java Virtual Machine Instruction Set 363 6.1 6.2 6.3 6.4 6.5 vi Assumptions: The Meaning of "Must" 363 Reserved Opcodes 364 Virtual Machine Errors 364 Format of Instruction Descriptions 365 mnemonic 366 Instructions 368 aaload 369 aastore 370
aconst_null 372 aload 373 aload_ 374 anewarray 375 areturn 376 arraylength 377 astore 378 astore_ 379 athrow 380 baload 382 bastore 383 bipush 384 caload 385 castore 386 checkcast 387 d2f 389 d2i 390 d2l 391 dadd 392 daload 394 dastore 395 dcmp 396 dconst_ 398 ddiv 399 dload 401 dload_ 402 dmul 403 dneg 405 drem 406 dreturn 408 dstore 409 dstore_ 410 dsub 411 dup 412 dup_x1 413 dup_x2 414 dup2 415 dup2_x1 416 dup2_x2 417 f2d 419 f2i 420 f2l 421 fadd 422 faload 424 fastore 425 fcmp 426 fconst_ 428 fdiv 429 The Java® Virtual Machine Specification vii
The Java® Virtual Machine Specification fload 431 fload_ 432 fmul 433 fneg 435 frem 436 freturn 438 fstore 439 fstore_ 440 fsub 441 getfield 442 getstatic 444 goto 446 goto_w 447 i2b 448 i2c 449 i2d 450 i2f 451 i2l 452 i2s 453 iadd 454 iaload 455 iand 456 iastore 457 iconst_ 458 idiv 459 if_acmp 460 if_icmp 461 if 463 ifnonnull 465 ifnull 466 iinc 467 iload 468 iload_ 469 imul 470 ineg 471 instanceof 472 invokedynamic 474 invokeinterface 479 invokespecial 482 invokestatic 486 invokevirtual 489 ior 494 irem 495 ireturn 496 ishl 497 ishr 498 istore 499 istore_ 500 viii
分享到:
收藏