20030425 - JavaVirtualMachine&ClassFile

Embed Size (px)

Citation preview

  • 8/7/2019 20030425 - JavaVirtualMachine&ClassFile

    1/86

    Java Virtual MachineJava Virtual Machine

  • 8/7/2019 20030425 - JavaVirtualMachine&ClassFile

    2/86

    Java: Not a Traditional Programming LanguageJava: Not a Traditional Programming Language

    Hardware

    Win32/NTLinux Solaris

    Java Platform

    Java

    Source

    (*.java)Java Compiler

    Java

    Bytecode

    (*.class)

    Java bytecode

    (moves locally or via web)

  • 8/7/2019 20030425 - JavaVirtualMachine&ClassFile

    3/86

    Java PlatformJava Platform

  • 8/7/2019 20030425 - JavaVirtualMachine&ClassFile

    4/86

    Java Platform & VM & DevicesJava Platform & VM & Devices

  • 8/7/2019 20030425 - JavaVirtualMachine&ClassFile

    5/86

    Java 2 XXX EditionJava 2 XXX Edition

    Each edition is a developer treasure chest ofEach edition is a developer treasure chest oftools and supplies that can be used with atools and supplies that can be used with aparticular product:particular product: Java virtual machines that fit inside the range ofJava virtual machines that fit inside the range of

    consumer devicesconsumer devices a library of APIs that are specialized for each type ofa library of APIs that are specialized for each type of

    devicedevice tools for deployment and device configurationtools for deployment and device configuration a profile, that is, a specification of the minimum set ofa profile, that is, a specification of the minimum set ofAPIs useful for a particular kind of consumer deviceAPIs useful for a particular kind of consumer device(set(set--top, screenphone, wireless, car, and digitaltop, screenphone, wireless, car, and digitalassistant) and a specification of the Java virtualassistant) and a specification of the Java virtualmachine functions required to support those APIsmachine functions required to support those APIs

  • 8/7/2019 20030425 - JavaVirtualMachine&ClassFile

    6/86

    Java 2 Standard EditionJava 2 Standard Edition

  • 8/7/2019 20030425 - JavaVirtualMachine&ClassFile

    7/86

    Java 2 Enterprise EditionJava 2 Enterprise Edition

  • 8/7/2019 20030425 - JavaVirtualMachine&ClassFile

    8/86

  • 8/7/2019 20030425 - JavaVirtualMachine&ClassFile

    9/86

    Various VMVarious VM

    JVM (J2EE & J2SE)JVM (J2EE & J2SE) WellWell--known Java Virtual Machine.known Java Virtual Machine.

    CVM, KVM (J2ME)CVM, KVM (J2ME)Addresses on vast small devices.Addresses on vast small devices.

    Reduces some VM features to fit resourceReduces some VM features to fit resource--constrained devices.constrained devices.

    JCVM (Java Card)JCVM (Java Card)Addresses on smart cards.Addresses on smart cards.

    It has least VM features.It has least VM features.

  • 8/7/2019 20030425 - JavaVirtualMachine&ClassFile

    10/86

    J2ME : ConfigurationJ2ME : Configuration

    J2ME technology has two design centersJ2ME technology has two design centers----things that you hold in your hand andthings that you hold in your hand and

    things you plug into a wall.things you plug into a wall.

    Configurations are composed of the twoConfigurations are composed of the twolowlow--level APIs and optimized virtuallevel APIs and optimized virtualmachines .machines .

  • 8/7/2019 20030425 - JavaVirtualMachine&ClassFile

    11/86

    J2ME : ProfileJ2ME : Profile

    A profile is a specification that details theA profile is a specification that details theJava technology APIs, built on top of andJava technology APIs, built on top of andutilizing the underlying Configuration.utilizing the underlying Configuration.

    Profiles specify both APIs and theProfiles specify both APIs and theConfiguration.Configuration.

  • 8/7/2019 20030425 - JavaVirtualMachine&ClassFile

    12/86

    Profiles:Foundation & MIDPProfiles:Foundation & MIDP

    MIDP:Mobile Information Device ProfileMIDP:Mobile Information Device Profile

    Foundation is a set of JavaTM APIs which,Foundation is a set of JavaTM APIs which,

    together with the Connected Devicetogether with the Connected DeviceConfiguration (CDC).Configuration (CDC).

    MIDP is a set of Java APIs which, togetherMIDP is a set of Java APIs which, togetherwith the Connected Limited Devicewith the Connected Limited DeviceConfiguration (CLDC).Configuration (CLDC).

  • 8/7/2019 20030425 - JavaVirtualMachine&ClassFile

    13/86

    CVM & CDC (1)CVM & CDC (1)

    CDC : Connected Device ConfigurationCDC : Connected Device Configuration

    CVM is a Java 2 virtual machine designed forCVM is a Java 2 virtual machine designed fordevices needing the functionality of the Java 2devices needing the functionality of the Java 2

    virtual machine feature set, but with a smallervirtual machine feature set, but with a smallerfootprint.footprint.

    The Connected Device Configuration (CDC)The Connected Device Configuration (CDC)

    includes the CVM and basic class libraries toincludes the CVM and basic class libraries tosupport Java language applications on consumersupport Java language applications on consumerelectronic and embedded devices.electronic and embedded devices.

  • 8/7/2019 20030425 - JavaVirtualMachine&ClassFile

    14/86

    CVM & CDC (2)CVM & CDC (2)

    CDC is designed for the devices such asCDC is designed for the devices such assmart communicators, pagers, personalsmart communicators, pagers, personaldigital assistants (PDAs), and interactive,digital assistants (PDAs), and interactive,digital television setdigital television set--top boxes.top boxes.

    Typically, these devices run a 32Typically, these devices run a 32--bitbitmicroprocessor/controller and have moremicroprocessor/controller and have morethan 2.0MB of total memory.than 2.0MB of total memory.

  • 8/7/2019 20030425 - JavaVirtualMachine&ClassFile

    15/86

    KVM & CLDC (1)KVM & CLDC (1)

    CLDC : Connected Limited Device ConfigurationCLDC : Connected Limited Device Configuration

    K virtual machine (KVM) is a new, highlyK virtual machine (KVM) is a new, highlyoptimized Java virtual machine specificallyoptimized Java virtual machine specifically

    designed for resourcedesigned for resource--constrained consumerconstrained consumerdevices.devices.

    CLDC outlines the most basic set of libraries andCLDC outlines the most basic set of libraries andJavaTM virtual machine features that must beJavaTM virtual machine features that must be

    present in each implementation of a Java 2present in each implementation of a Java 2Platform, Micro Edition environment on highlyPlatform, Micro Edition environment on highlyconstrained devices.constrained devices.

  • 8/7/2019 20030425 - JavaVirtualMachine&ClassFile

    16/86

  • 8/7/2019 20030425 - JavaVirtualMachine&ClassFile

    17/86

    JCVM (1)JCVM (1)

  • 8/7/2019 20030425 - JavaVirtualMachine&ClassFile

    18/86

    JCVM (2)JCVM (2)

  • 8/7/2019 20030425 - JavaVirtualMachine&ClassFile

    19/86

    JCVM (3)JCVM (3)

    JCVM has least VM features defined inJCVM has least VM features defined inJVM SPEC.JVM SPEC.

    Unsupported Features:Unsupported Features: Dynamic Class LoadingDynamic Class Loading

    Security ManagerSecurity Manager

    Garbage Collection & FinalizationGarbage Collection & Finalization

    ThreadsThreads

    CloningCloning

  • 8/7/2019 20030425 - JavaVirtualMachine&ClassFile

    20/86

    JCVM (4)JCVM (4)

    Unsupported Keywords:Unsupported Keywords:

    nativenative

    synchronizedsynchronized transienttransient

    volatilevolatile

    Unsupported Types:Unsupported Types:

    char, float, double, longchar, float, double, long

    Arrays that is more than one dimension.Arrays that is more than one dimension.

  • 8/7/2019 20030425 - JavaVirtualMachine&ClassFile

    21/86

    JCVM (5)JCVM (5)

    In general, none of Java core API classesIn general, none of Java core API classesare supported in the Java Card platform.are supported in the Java Card platform.

    Some classes from java.lang package areSome classes from java.lang package aresupported, but none of the rest are.supported, but none of the rest are.

    Class java.lang.System is not supported.Class java.lang.System is not supported.Instead, it supplies a classInstead, it supplies a class

    javacard.framework.JCSystem, whichjavacard.framework.JCSystem, whichprovides an interface to system behavior.provides an interface to system behavior.

  • 8/7/2019 20030425 - JavaVirtualMachine&ClassFile

    22/86

    VM MechanismVM Mechanism

  • 8/7/2019 20030425 - JavaVirtualMachine&ClassFile

    23/86

    Internal Architecture of JVMInternal Architecture of JVMJava Runtime System

    Operating System

    native method

    Java Class

    Library

    Java bytecode

    (*.class)

    execution engine

    Exception,

    Thread,

    Security.

    Heap

    Class Loader& Verifier

    nativemethod linker

    classmethod

    area

    nativemethodarea

    Java Stack,

    Register

  • 8/7/2019 20030425 - JavaVirtualMachine&ClassFile

    24/86

    Method Area & HeapMethod Area & Heap

    Each JVM implementation has a heap andEach JVM implementation has a heap anda method area.a method area.

    Heap is shared among all threads. It is theHeap is shared among all threads. It is theruntime data area from which for all classruntime data area from which for all classinstances and arrays is allocated.instances and arrays is allocated.

    Method area is shared among all threads.Method area is shared among all threads.

    It stores perIt stores per--class structures such as theclass structures such as theruntime constant pool, field and methodruntime constant pool, field and methoddata, the code for methods.data, the code for methods.

  • 8/7/2019 20030425 - JavaVirtualMachine&ClassFile

    25/86

    Class Loader & VerifierClass Loader & Verifier

    Loading: Load binary representation of classLoading: Load binary representation of class(*.class).(*.class).

    Linking:Linking: Verification: Ensure that the binary representation isVerification: Ensure that the binary representation is

    structurally valid.structurally valid. Preparation: Create the static fields for the class orPreparation: Create the static fields for the class or

    interface and initializing those fields to their standardinterface and initializing those fields to their standarddefault values.default values.

    Resolution: Determine concrete values from symbolicResolution: Determine concrete values from symbolic

    references in the runtime constant pool .references in the runtime constant pool . Initializing: Invoke its static initializers and theInitializing: Invoke its static initializers and the

    initializers for static fields declared in class.initializers for static fields declared in class.

  • 8/7/2019 20030425 - JavaVirtualMachine&ClassFile

    26/86

    RegisterRegister

    PC (program counter) register. It containsPC (program counter) register. It containsthe address of the Java virtual machinethe address of the Java virtual machineinstruction currently being executed.instruction currently being executed.

    Each thread has its own PC register.Each thread has its own PC register.

    If the method currently being executed byIf the method currently being executed bythe thread is native, the value of the Javathe thread is native, the value of the Javavirtual machine's pc register is undefined.virtual machine's pc register is undefined.

  • 8/7/2019 20030425 - JavaVirtualMachine&ClassFile

    27/86

    Java StackJava Stack

    Java Stack stores frames.Java Stack stores frames.

    Each thread has a private JVM stack,Each thread has a private JVM stack,

    created at the same time as thread.created at the same time as thread. Java Stack holds local variables and partialJava Stack holds local variables and partial

    results, and plays a part in methodresults, and plays a part in methodinvocation and return.invocation and return.

  • 8/7/2019 20030425 - JavaVirtualMachine&ClassFile

    28/86

    Java Stack : frame (1)Java Stack : frame (1)

    A new frame is created each time aA new frame is created each time amethod is invoked. A frame is destroyedmethod is invoked. A frame is destroyedwhen its method invocation completes.when its method invocation completes.

    A frame is used to store data and partialA frame is used to store data and partialresults, as well as to perform dynamicresults, as well as to perform dynamiclinking, return values for methods, andlinking, return values for methods, and

    dispatch exception.dispatch exception.

  • 8/7/2019 20030425 - JavaVirtualMachine&ClassFile

    29/86

    Java Stack : frame (2)Java Stack : frame (2)

    Each frame has its own array of localEach frame has its own array of localvariables, its own operand stack, and avariables, its own operand stack, and areference to the runtime constant pool ofreference to the runtime constant pool ofthe class of the current method.the class of the current method.

    local variables

    Java Stack

    operand stack

    othersframe

  • 8/7/2019 20030425 - JavaVirtualMachine&ClassFile

    30/86

    Java Stack : frame (3)Java Stack : frame (3)

    class LocalVariableExample {

    public static void runClassMethod(int i, long l, float f) { }

    public void runInstanceMethod(char c, double d, boolean b) { }

    }

    runClassMethod()

    int i

    long l

    float f

    0

    1

    3

    runInstanceMethod()

    double d

    char c

    boolean b

    0

    2

    4

    1

    reference

  • 8/7/2019 20030425 - JavaVirtualMachine&ClassFile

    31/86

    Java Stack : frame (4)Java Stack : frame (4)

    iload_0

    iload_1

    iadd

    istore_2

    98

    0

    21

    100

    98

    0

    21

    100

    100

    98

    0

    2

    1

    100

    98

    100

    980

    21

    100

    198

    980

    21

    100

    198

    local variables

    operand stack

  • 8/7/2019 20030425 - JavaVirtualMachine&ClassFile

    32/86

    Java Stack : frame (5)Java Stack : frame (5)

    class pointerclass pointer

    previous frame pointerprevious frame pointer

    exception tableexception table

  • 8/7/2019 20030425 - JavaVirtualMachine&ClassFile

    33/86

    Execution Engine (1)Execution Engine (1)

    A virtual processorA virtual processor ---- the core of JVM.the core of JVM.

    Programming aspect : interpreter.Programming aspect : interpreter.

    Read bytecode stream then execute theRead bytecode stream then execute theinstructions.instructions.

    The performance can be improved byThe performance can be improved by

    JustJust--InIn--Time(JIT) compiler.Time(JIT) compiler.

  • 8/7/2019 20030425 - JavaVirtualMachine&ClassFile

    34/86

    Execution Engine (2)Execution Engine (2)

    int y=x+5;

    iload 1

    bipush 5

    iadd

    istore 2

    iload 1 bipush 5 iadd istore 2

    21 1 16 5 96 54 2

  • 8/7/2019 20030425 - JavaVirtualMachine&ClassFile

    35/86

    JavaJava

    Assembly LanguageAssembly Language

  • 8/7/2019 20030425 - JavaVirtualMachine&ClassFile

    36/86

    Count.javaCount.javapublic class Count

    {

    public static void main(String[] args)

    {

    int i;

    for(i=0;i

  • 8/7/2019 20030425 - JavaVirtualMachine&ClassFile

    37/86

    Count.j (1)Count.j (1).class public Count.super java/lang/Object

    .method public ()V

    aload_0

    invokespecial java/lang/Object/()Vreturn

    .end method

  • 8/7/2019 20030425 - JavaVirtualMachine&ClassFile

    38/86

    Count.j (2)Count.j (2)

    .method public static main([Ljava/lang/String;)V

    .limit stack 3

    .limit locals 4

    getstatic java/lang/System/out Ljava/io/PrintStream;

    astore_1

    bipush 10

    istore_2

  • 8/7/2019 20030425 - JavaVirtualMachine&ClassFile

    39/86

    Count.j (3)Count.j (3)

    Loop:bipush 10iload_2isubinvokestatic java/lang/String/valueOf(I)Ljava/lang/String;

    astore_3aload_1aload_3invokevirtual java/io/PrintStream/println(Ljava/lang/String;)V

    iinc 2 -1

    iload_2ifne Loop

    return.end method

  • 8/7/2019 20030425 - JavaVirtualMachine&ClassFile

    40/86

    Java AssemblerJava Assembler

    Not an official assembler. There is noNot an official assembler. There is nostandard for java assembly language.standard for java assembly language.

    http://mrl.nyu.edu/~meyer/jasmin/http://mrl.nyu.edu/~meyer/jasmin/

  • 8/7/2019 20030425 - JavaVirtualMachine&ClassFile

    41/86

    Class File StructureClass File Structure

  • 8/7/2019 20030425 - JavaVirtualMachine&ClassFile

    42/86

    Tables of Class FileTables of Class File

    Top Table:Top Table: Basic information of the whole class.Basic information of the whole class.

    Constant Pool Table:Constant Pool Table: Records string, constant, reference, method name, field nameRecords string, constant, reference, method name, field name

    Interface Table:Interface Table: What interface are implemented by this class.What interface are implemented by this class.

    Field Table:Field Table: The fields which class owns.The fields which class owns.

    Method Table:Method Table: The methods which class owns.The methods which class owns.

    Attribute Table:Attribute Table: The extra information of class, field, methodThe extra information of class, field, method and so on.and so on.

  • 8/7/2019 20030425 - JavaVirtualMachine&ClassFile

    43/86

    Magic NumberMagic Number

    0xCA, 0xFE, 0xBA, 0xBE0xCA, 0xFE, 0xBA, 0xBE

    Every class file contains these 4Every class file contains these 4--byte databyte datain the header.in the header.

  • 8/7/2019 20030425 - JavaVirtualMachine&ClassFile

    44/86

    Type Descriptor (1)Type Descriptor (1)

    Primitive Type:Primitive Type: B : byteB : byte

    C : charC : char

    D : doubleD : double F : floatF : float

    I : intI : int

    J : longJ : long S : shortS : short

    Z : booleanZ : boolean

  • 8/7/2019 20030425 - JavaVirtualMachine&ClassFile

    45/86

    Type Descriptor (2)Type Descriptor (2)

    Class Type:Class Type:

    L;L;

    Ex1: Ljava/lang/String;Ex1: Ljava/lang/String;

    Ex2:Ex2: Ljava/io/PrintStream;

  • 8/7/2019 20030425 - JavaVirtualMachine&ClassFile

    46/86

    Type Descriptor (3)Type Descriptor (3)

    Array Type:Array Type:

    [[

    Ex1: [CEx1: [C char[]char[]

    Ex2: [[FEx2: [[F float[][]float[][]

    Ex3: [Ljava/lang/Thread;Ex3: [Ljava/lang/Thread; Thread[]Thread[]

  • 8/7/2019 20030425 - JavaVirtualMachine&ClassFile

    47/86

    Type Descriptor (4)Type Descriptor (4)

    Method:Method: ()()

    VV indicatesindicates voidvoid (used in return type)(used in return type)

    Ex1: ()VEx1: ()V void xyz() {void xyz() {}}

    Ex2: (SF[Ljava/lang/Thread;)IEx2: (SF[Ljava/lang/Thread;)I int xyz(short x, float y, Thread[] z) {int xyz(short x, float y, Thread[] z) {}}

  • 8/7/2019 20030425 - JavaVirtualMachine&ClassFile

    48/86

    Constant PoolConstant Pool

    TagTag ValueValue DescriptionDescription

    CONSTANT_Utf8CONSTANT_Utf8 11 array of bytearray of byte

    CONSTANT_IntegerCONSTANT_Integer 33 integerinteger

    CONSTANT_FloatCONSTANT_Float 44 float float

    CONSTANT_LongCONSTANT_Long 55 longlong

    CONSTANT_DoubleCONSTANT_Double 66 DoubleDouble

    CONSTANT_ClassCONSTANT_Class 77 TagTag--1 index1 index

    CONSTANT_StringCONSTANT_String 88 TagTag--1 index1 index

    CONSTANT_FieldrefCONSTANT_Fieldref 99 TagTag--7 index + Tag7 index + Tag--12 index12 index

    CONSTANT_MethodrefCONSTANT_Methodref 1010 TagTag--7 index + Tag7 index + Tag--12 index12 index

    CONSTANT_InterfaceMethodrefCONSTANT_InterfaceMethodref 1111 TagTag--7 index + Tag7 index + Tag--12 index12 index

    CONSTANT_NameAndTypeCONSTANT_NameAndType 1212 TagTag--1 index(filed,method name)1 index(filed,method name)

    + Tag+ Tag--1 index(type descriptor)1 index(type descriptor)

  • 8/7/2019 20030425 - JavaVirtualMachine&ClassFile

    49/86

    Access FlagAccess Flag

    FlagFlag ValueValue

    ACC_PUBLICACC_PUBLIC 0x00010x0001

    ACC_PRIVATEACC_PRIVATE 0x00020x0002

    ACC_PROTECTEDACC_PROTECTED 0x00040x0004

    ACC_STATICACC_STATIC 0x00080x0008

    ACC_FINALACC_FINAL 0x00100x0010

    ACC_SUPERACC_SUPER 0x00200x0020

    ACC_SYNCHRONIZEDACC_SYNCHRONIZED 0x00200x0020

    ACC_VOLATILEACC_VOLATILE 0x00400x0040ACC_TRANSIENTACC_TRANSIENT 0x00800x0080

    ACC_NATIVEACC_NATIVE 0x01000x0100

    ACC_INTERFACEACC_INTERFACE 0x02000x0200

    ACC_ABSTRACTACC_ABSTRACT 0x04000x0400

  • 8/7/2019 20030425 - JavaVirtualMachine&ClassFile

    50/86

    out.jout.j.class public out

    .super java/lang/Object

    .method public ()V

    aload_0

    invokespecial java/lang/Object/()V

    return

    .end method

    .method public static main([Ljava/lang/String;)V

    .limit stack 2

    getstatic java/lang/System/out Ljava/io/PrintStream;ldc Hello World

    invokevirtual java/io/PrintStream/println(Ljava/lang/String;)V

    return

    .end method

  • 8/7/2019 20030425 - JavaVirtualMachine&ClassFile

    51/86

    out.classout.class[ ][ ] [ ] [ ]

    1

    [

    ]

    2

    []

    3

    []

    4

    [ ]5

    [ ]6

    [ ]7

    []

    8

    [ ]9

    [ ]10

    []

    11

    [ ]12 [

    ]

    13

    [ ]14

    [ ]15 []

    16

    []

    17

    [ ]18

    []

    19

    []

    20

    [ ]21

    [ ]22

    [ ]23

    [ ]24

    [

    ]

    25

    [ ]

    26

  • 8/7/2019 20030425 - JavaVirtualMachine&ClassFile

    52/86

    public + superpublic + super[ ][ ] [ ] [ ]

    1

    [

    ]

    2

    []

    3

    []

    4

    [ ]5

    [ ]6

    [ ]7

    []

    8

    [ ]9

    [ ]10

    []

    11

    [ ]12 [

    ]

    13

    [ ]14

    [ ]15 []

    16

    []

    17

    [ ]18

    []

    19

    []

    20

    [ ]21

    [ ]22

    [ ]23

    [ ]24

    [

    ]

    25

    [ ]

    26

  • 8/7/2019 20030425 - JavaVirtualMachine&ClassFile

    53/86

    self class nameself class name[ ][ ] [ ] [ ]

    1

    [

    ]

    2

    []

    3

    []

    4

    [ ]5

    [ ]6

    [ ]7

    []

    8

    [ ]9

    [ ]10

    []

    11

    [ ]12 [

    ]

    13

    [ ]14

    [ ]15 []

    16

    []

    17

    [ ]18

    []

    19

    []

    20

    [ ]21

    [ ]22

    [ ]23

    [ ]24

    [

    ]

    25

    [ ]

    26

  • 8/7/2019 20030425 - JavaVirtualMachine&ClassFile

    54/86

    super class namesuper class name[ ][ ] [ ] [ ]

    1

    [

    ]

    2

    []

    3

    []

    4

    [ ]5

    [ ]6

    [ ]7

    []

    8

    [ ]9

    [ ]10

    []

    11

    [ ]12 [

    ]

    13

    [ ]14

    [ ]15 []

    16

    []

    17

    [ ]18

    []

    19

    []

    20

    [ ]21

    [ ]22

    [ ]23

    [ ]24

    [

    ]

    25

    [ ]

    26

  • 8/7/2019 20030425 - JavaVirtualMachine&ClassFile

    55/86

    interface numberinterface number[ ][ ] [ ] [ ]

    1

    [

    ]

    2

    []

    3

    []

    4

    [ ]5

    [ ]6

    [ ]7

    []

    8

    [ ]9

    [ ]10

    []

    11

    [ ]12 [

    ]

    13

    [ ]14

    [ ]15 []

    16

    []

    17

    [ ]18

    []

    19

    []

    20

    [ ]21

    [ ]22

    [ ]23

    [ ]24

    [

    ]

    25

    [ ]

    26

  • 8/7/2019 20030425 - JavaVirtualMachine&ClassFile

    56/86

    field numberfield number[ ][ ] [ ] [ ]

    1

    [

    ]

    2

    []

    3

    []

    4

    [ ]5

    [ ]6

    [ ]7

    []

    8

    [ ]9

    [ ]10

    []

    11

    [ ]12 [

    ]

    13

    [ ]14

    [ ]15 []

    16

    []

    17

    [ ]18

    []

    19

    []

    20

    [ ]21

    [ ]22

    [ ]23

    [ ]24

    [

    ]

    25

    [ ]

    26

  • 8/7/2019 20030425 - JavaVirtualMachine&ClassFile

    57/86

    method numbermethod number[ ][ ] [ ] [ ]

    1

    [

    ]

    2

    []

    3

    []

    4

    [ ]5

    [ ]6

    [ ]7

    []

    8

    [ ]9

    [ ]10

    []

    11

    [ ]12 [

    ]

    13

    [ ]14

    [ ]15 []

    16

    []

    17

    [ ]18

    []

    19

    []

    20

    [ ]21

    [ ]22

    [ ]23

    [ ]24

    [

    ]

    25

    [ ]

    26

  • 8/7/2019 20030425 - JavaVirtualMachine&ClassFile

    58/86

    publicpublic[ ][ ] [ ] [ ]

    1

    [

    ]

    2

    []

    3

    []

    4

    [ ]5

    [ ]6

    [ ]7

    []

    8

    [ ]9

    [ ]10

    []

    11

    [ ]12 [

    ]

    13

    [ ]14

    [ ]15 []

    16

    []

    17

    [ ]18

    []

    19

    []

    20

    [ ]21

    [ ]22

    [ ]23

    [ ]24

    [

    ]

    25

    [ ]

    26

  • 8/7/2019 20030425 - JavaVirtualMachine&ClassFile

    59/86

    method namemethod name[ ][ ] [ ] [ ]

    1

    [

    ]

    2

    []

    3

    []

    4

    [ ]5

    [ ]6

    [ ]7

    []

    8

    [ ]9

    [ ]10

    []

    11

    [ ]12 [

    ]

    13

    [ ]14

    [ ]15 []

    16

    []

    17

    [ ]18

    []

    19

    []

    20

    [ ]21

    [ ]22

    [ ]23

    [ ]24

    [

    ]

    25

    [ ]

    26

  • 8/7/2019 20030425 - JavaVirtualMachine&ClassFile

    60/86

    method typemethod type[ ][ ] [ ] [ ]

    1

    [

    ]

    2

    []

    3

    []

    4

    [ ]5

    [ ]6

    [ ]7

    []

    8

    [ ]9

    [ ]10

    []

    11

    [ ]12 [

    ]

    13

    [ ]14

    [ ]15 []

    16

    []

    17

    [ ]18

    []

    19

    []

    20

    [ ]21

    [ ]22

    [ ]23

    [ ]24

    [

    ]

    25

    [ ]

    26

  • 8/7/2019 20030425 - JavaVirtualMachine&ClassFile

    61/86

    attribute numberattribute number[ ][ ] [ ] [ ]

    1

    [

    ]

    2

    []

    3

    []

    4

    [ ]5

    [ ]6

    [ ]7

    []

    8

    [ ]9

    [ ]10

    []

    11

    [ ]12 [

    ]

    13

    [ ]14

    [ ]15 []

    16

    []

    17

    [ ]18

    []

    19

    []

    20

    [ ]21

    [ ]22

    [ ]23

    [ ]24

    [

    ]

    25

    [ ]

    26

  • 8/7/2019 20030425 - JavaVirtualMachine&ClassFile

    62/86

    attribute typeattribute type[ ][ ] [ ] [ ]

    1

    [

    ]

    2

    []

    3

    []

    4

    [ ]5

    [ ]6

    [ ]7

    []

    8

    [ ]9

    [ ]10

    []

    11

    [ ]12 [

    ]

    13

    [ ]14

    [ ]15 []

    16

    []

    17

    [ ]18

    []

    19

    []

    20

    [ ]21

    [ ]22

    [ ]23

    [ ]24

    [

    ]

    25

    [ ]

    26

  • 8/7/2019 20030425 - JavaVirtualMachine&ClassFile

    63/86

  • 8/7/2019 20030425 - JavaVirtualMachine&ClassFile

    64/86

    stack sizestack size

    [ ][ ] [ ] [ ]1

    [

    ]

    2

    []

    3

    []

    4

    [ ]5

    [ ]6

    [ ]7

    []

    8

    [ ]9

    [ ]10

    []

    11

    [ ]12 [

    ]

    13

    [ ]14

    [ ]15 []

    16

    []

    17

    [ ]18

    []

    19

    []

    20

    [ ]21

    [ ]22

    [ ]23

    [ ]24

    [

    ]

    25

    [ ]

    26

    []

  • 8/7/2019 20030425 - JavaVirtualMachine&ClassFile

    65/86

    local variable sizelocal variable size

    [ ][ ] [ ] [ ]1

    [

    ]

    2

    []

    3

    []

    4

    [ ]5

    [ ]6

    [ ]7

    []

    8

    [ ]9

    [ ]10

    []

    11

    [ ]12 [

    ]

    13

    [ ]14

    [ ]15 []

    16

    []

    17

    [ ]18

    []

    19

    []

    20

    [ ]21

    [ ]22

    [ ]23

    [ ]24

    [

    ]

    25

    [ ]

    26

    []

  • 8/7/2019 20030425 - JavaVirtualMachine&ClassFile

    66/86

    bytecode lengthbytecode length

    [ ][ ] [ ] [ ]1

    []

    2

    []

    3

    []

    4

    [ ]5

    [ ]6

    [ ]7

    []

    8

    [ ]9

    [ ]10

    []

    11

    [ ]12 [

    ]

    13

    [ ]14

    [ ]15 []

    16

    []

    17

    [ ]18

    []

    19

    []

    20

    [ ]21

    [ ]22

    [ ]23

    [ ]24

    [

    ]

    25

    [ ]

    26

    []

  • 8/7/2019 20030425 - JavaVirtualMachine&ClassFile

    67/86

    bytecode contentbytecode content

    [ ][ ] [ ] [ ]1

    []

    2

    []

    3

    []

    4

    [ ]5

    [ ]6

    [ ]7

    []

    8

    [ ]9

    [ ]10

    []

    11

    [ ]12 [

    ]

    13

    [ ]14

    [ ]15 []

    16

    []

    17

    [ ]18

    []

    19

    []

    20

    [ ]21

    [ ]22

    [ ]23

    [ ]24

    [

    ]

    25

    [ ]

    26

    []

  • 8/7/2019 20030425 - JavaVirtualMachine&ClassFile

    68/86

    exception sizeexception size

    [ ][ ] [ ] [ ]

    1

    []

    2

    []

    3

    []

    4

    [ ]5

    [ ]6

    [ ]7

    []

    8

    [ ]9

    [ ]10

    []

    11

    [ ]12 [

    ]

    13

    [ ]14

    [ ]15 []

    16

    []

    17

    [ ]18

    []

    19

    []

    20

    [ ]21

    [ ]22

    [ ]23

    [ ]24

    [

    ]

    25

    [ ]

    26

    []

  • 8/7/2019 20030425 - JavaVirtualMachine&ClassFile

    69/86

    extra attribute numberextra attribute number

    [ ][ ] [ ] [ ]

    1

    []

    2

    []

    3

    []

    4

    [ ]5

    [ ]6

    [ ]7

    []

    8

    [ ]9

    [ ]10

    []

    11

    [ ]12 [

    ]

    13

    [ ]14

    [ ]15 []

    16

    []

    17

    [ ]18

    []

    19

    []

    20

    [ ]21

    [ ]22

    [ ]23

    [ ]24

    [

    ]

    25

    [ ]

    26

    []

  • 8/7/2019 20030425 - JavaVirtualMachine&ClassFile

    70/86

    public + staticpublic + static

    [ ][ ] [ ] [ ]

    1

    []

    2

    []

    3

    []

    4

    [ ]5

    [ ]6

    [ ]7

    []

    8

    [ ]9

    [ ]10

    []

    11

    [ ]12 [

    ]

    13

    [ ]14

    [ ]15

    []

    16

    []

    17

    [ ]18

    []

    19

    []

    20

    [ ]21

    [ ]22

    [ ]23

    [ ]24

    [

    ]

    25

    [ ]

    26

  • 8/7/2019 20030425 - JavaVirtualMachine&ClassFile

    71/86

    method namemethod name

    [ ][ ] [ ] [ ]

    1

    []

    2

    []

    3

    []

    4

    [ ]5

    [ ]6

    [ ]7

    []

    8

    [ ]9

    [ ]10

    []

    11

    [ ]12 [

    ]

    13

    [ ]14

    [ ]15

    []

    16

    []

    17

    [ ]18

    []

    19

    []

    20

    [ ]21

    [ ]22

    [ ]23

    [ ]24

    [

    ]

    25

    []

    26

  • 8/7/2019 20030425 - JavaVirtualMachine&ClassFile

    72/86

    method typemethod type

    [ ][ ] [ ] [ ]

    1

    []

    2

    []

    3

    []

    4

    [ ]5

    [ ]6

    [ ]7

    []

    8

    [ ]9

    [ ]10

    []

    11

    [ ]12 [

    ]

    13

    [ ]14

    [ ]15

    []

    16

    []

    17

    [ ]18

    []

    19

    []

    20

    [ ]21

    [ ]22

    [ ]23

    [ ]24

    [

    ]

    25

    []

    26

  • 8/7/2019 20030425 - JavaVirtualMachine&ClassFile

    73/86

    attribute numberattribute number

    [ ][ ] [ ] [ ]

    1

    []

    2

    []

    3

    []

    4

    [ ]5

    [ ]6

    [ ]7

    []

    8

    [ ]9

    [ ]10

    []

    11

    [ ]12 [

    ]

    13

    [ ]14

    [ ]15

    []

    16

    []

    17

    [ ]18

    []

    19

    []

    20

    [ ]21

    [ ]22

    [ ]23

    [ ]24

    [

    ]

    25

    []

    26

  • 8/7/2019 20030425 - JavaVirtualMachine&ClassFile

    74/86

    attribute typeattribute type

    [ ][ ] [ ] [ ]

    1

    []

    2

    []

    3

    []

    4

    [ ]5

    [ ]6

    [ ]7

    []

    8

    [ ]9

    [ ]10

    []

    11

    [ ]12 [

    ]

    13

    [ ]14

    [ ]15

    []

    16

    []

    17

    [ ]18

    []

    19

    []

    20

    [ ]21

    [ ]22

    [ ]23

    [ ]24

    [

    ]

    25

    []

    26

  • 8/7/2019 20030425 - JavaVirtualMachine&ClassFile

    75/86

    method lengthmethod length

    [ ][ ] [ ] [ ]

    1

    []

    2

    []

    3

    []

    4

    [ ]5

    [ ]6

    [ ]7

    []

    8

    [ ]9

    [ ]10

    []

    11

    [ ]12 [

    ]

    13

    [ ]14

    [ ]15

    []

    16

    []

    17

    [ ]18

    []

    19

    []

    20

    [ ]21

    [ ]22

    [ ]23

    [ ]24

    [

    ]

    25

    []

    26

    []

  • 8/7/2019 20030425 - JavaVirtualMachine&ClassFile

    76/86

    stack sizestack size

    [ ][ ] [ ] [ ]

    1

    []

    2

    []

    3

    []

    4

    [ ]5

    [ ]6

    [ ]7

    []

    8

    [ ]9

    [ ]10

    []

    11

    [ ]12 [

    ]

    13

    [ ]14

    [ ]15

    []

    16

    []

    17

    [ ]18

    []

    19

    []

    20

    [ ]21

    [ ]22

    [ ]23

    [ ]24

    [

    ]

    25

    []

    26

    []

  • 8/7/2019 20030425 - JavaVirtualMachine&ClassFile

    77/86

    local variable sizelocal variable size

    [ ][ ] [ ] [ ]

    1

    []

    2

    []

    3

    []

    4

    [ ]5

    [ ]6

    [ ]7

    []

    8

    [ ]9

    [ ]10

    []

    11

    [ ]12 [

    ]

    13

    [ ]14

    [ ]15

    []

    16

    []

    17

    [ ]18

    []

    19

    []

    20

    [ ]21

    [ ]22

    [ ]23

    [ ]24

    [

    ]

    25

    []

    26

    []

  • 8/7/2019 20030425 - JavaVirtualMachine&ClassFile

    78/86

    bytecode lengthbytecode length

    [ ][ ] [ ] [ ]

    1

    []

    2

    []

    3

    []

    4

    [ ]5

    [ ]6

    [ ]7

    []

    8

    [ ]9

    [ ]10

    []

    11

    [ ]12 [

    ]

    13

    [ ]14

    [ ]15

    []

    16

    []

    17

    [ ]18

    []

    19

    []

    20

    [ ]21

    [ ]22

    [ ]23

    [ ]24

    [

    ]

    25

    []

    26

    []

  • 8/7/2019 20030425 - JavaVirtualMachine&ClassFile

    79/86

    bytecode contentbytecode content

    [ ][ ] [ ] [ ]

    1

    []

    2

    []

    3

    []

    4

    [ ]5

    [ ]6

    [ ]7

    []

    8

    [ ]9

    [ ]10

    []

    11

    [ ]12 [

    ]

    13

    [ ]14

    [ ]15

    []

    16

    []

    17

    [ ]18

    []

    19

    []

    20

    [ ]21

    [ ]22

    [ ]23

    [ ]24

    [

    ]

    25

    []

    26

    []

  • 8/7/2019 20030425 - JavaVirtualMachine&ClassFile

    80/86

    exception sizeexception size

    [ ][ ] [ ] [ ]

    1

    []

    2

    []

    3

    []

    4

    [ ]5

    [ ]6

    [ ]7

    []

    8

    [ ]9

    [ ]10

    []

    11

    [ ]12 [

    ]

    13

    [ ]14

    [ ]15

    []

    16

    []

    17

    [ ]18

    []

    19

    []

    20

    [ ]21

    [ ]22

    [ ]23

    [ ]24

    [

    ]

    25

    []

    26

    []

  • 8/7/2019 20030425 - JavaVirtualMachine&ClassFile

    81/86

    extra attribute numberextra attribute number

    [ ][ ] [ ] [ ]

    1

    []

    2

    []

    3

    []

    4

    [ ]5

    [ ]6

    [ ]7

    []

    8

    [ ]9

    [ ]10

    []

    11

    [ ]12 [

    ]

    13

    [ ]14

    [ ]15

    [ ]

    16

    []

    17

    [ ]18

    []

    19

    []

    20

    [ ]21

    [ ]22

    [ ]23

    [ ]24

    [

    ]

    25

    []

    26

    []

  • 8/7/2019 20030425 - JavaVirtualMachine&ClassFile

    82/86

    atttribute numberatttribute number

    [ ][ ] [ ] [ ]

    1

    []

    2

    []

    3

    []

    4

    [ ]5

    [ ]6

    [ ]7

    []

    8

    [ ]9

    [ ]10

    []

    11

    [ ]12 [

    ]

    13

    [ ]14

    [ ]15

    [ ]

    16

    []

    17

    [ ]18

    []

    19

    []

    20

    [ ]21

    [ ]22

    [ ]23

    [ ]24

    [

    ]

    25

    []

    26

  • 8/7/2019 20030425 - JavaVirtualMachine&ClassFile

    83/86

    attribute typeattribute type

    [ ][ ] [ ] [ ]

    1

    []

    2

    []

    3

    []

    4

    [ ]5

    [ ]6

    [ ]7

    []

    8

    [ ]9

    [ ]10

    []

    11

    [ ]12 [

    ]

    13

    [ ]14

    [ ]15

    [ ]

    16

    []

    17

    [ ]18

    []

    19

    []

    20

    [ ]21

    [ ]22

    [ ]23

    [ ]24

    [

    ]

    25

    []

    26

  • 8/7/2019 20030425 - JavaVirtualMachine&ClassFile

    84/86

    attribute lengthattribute length

    [ ][ ] [ ] [ ]

    1

    []

    2

    []

    3

    []

    4

    [ ]5

    [ ]6

    [ ]7

    []

    8

    [ ]9

    [ ]10

    []

    11

    [ ]12 [

    ]

    13

    [ ]14

    [ ]15

    [ ]

    16

    []

    17

    [ ]18

    []

    19

    []

    20

    [ ]21

    [ ]22

    [ ]23

    [ ]24

    [

    ]

    25

    []

    26

  • 8/7/2019 20030425 - JavaVirtualMachine&ClassFile

    85/86

    attribute dataattribute data

    [ ][ ] [ ] [ ]

    1

    []

    2

    []

    3

    []

    4

    [ ]5

    [ ]6

    [ ]7

    []

    8

    [ ]9

    [ ]10

    []

    11

    [ ]12 [

    ]

    13

    [ ]14

    [ ]15

    [ ]

    16

    []

    17

    [ ]18

    []

    19

    []

    20

    [ ]21

    [ ]22

    [ ]23

    [ ]24

    [

    ]

    25

    []

    26

  • 8/7/2019 20030425 - JavaVirtualMachine&ClassFile

    86/86

    The EndThe End