DOC PREVIEW
UA CSC 453 - The Java VM

This preview shows page 1-2-3 out of 8 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 8 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 8 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 8 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 8 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

CSc 453Compilers and Systems Software17 : The Java VMDepartment of Computer ScienceUniversity of [email protected]° 2009 Christian CollbergThe Java Virtual MachineThe Java VM has gone the “many complex instructions/largeVM engine” way.Each Java source file may contain several Java classes. TheJava compiler compiles each of these classes to a single Javaclass file.The Java class file stores all necessary data regarding theclass. There is a symbol table (called the Constant Pool)which stores strings, large literal integers and floats, namesand of all fields and methods.Each method is compiled to Java bytecode, a stack VMformat.The class file is (almost) isomorphic to the source.Read, lex,parse,semanticsVMCodeclass C1 {}class C2 {}class C3 {}method M1(){}int F1;......File.javaC2.classC1.classC3.classTransferclass filesover the netMagic NumberConstant PoolAccess FlagsThis ClassSuper ClassInterfacesFieldsMethodsAttributesClass File FormatCompileReadVMCodeNativeExecutereadevalprintInterpretReadVMCodeString: "HELLO"Method: "C.M(int)"Field: "int F".....Constant PoolFlagsName TypeAttributes[pub]"x"int[priv]"y"CFieldsExceptionTableCode[]={push,add,store...}[]={...}MaxStack=5, MaxLocals=8AttributesMagic NumberConstant PoolAccess FlagsThis ClassSuper ClassInterfacesFieldsMethodsAttributes[pub]FlagsNameAttributesSig"q" ()intMethodsCodeExceptionsJava Byte CodesThe Java bytecodes can manipulate data in these formats:integers (32-bits), longs (64-bits), floats (32-bits), doubles(64-bits), shorts (16-bits), bytes (8-bits), object references(32/64-bit pointers), and arrays.The bytecodes are 1 byte wide.Each method can have up to 256 local variables and formalparameters. The bytecode reference these by number.Actually, we can have up to 65536 local vars. There is aspecial wide instruction that modifies load and storeinstructions to reference the high-numbered locals. Hack.Java Byte Codes. . .The Java stack is 32-bits wide. Longs and doubles hence taketwo stack entries.The bytecodes reference data from the class’ constant pool.These references are 8 or 16 bits long. To push a reference toa literal string with constant pool # 4567, use ’ldc2 4567’.If the # is 123, use ’ldc2 123’.Java Byte Codes. . .int8An 8-bit integer value.int16A 16-bit integer value.int32A 32-bit integer value.CP8An 8-bit constant pool index.CP16A 16-bit constant pool index.FIdx An 8-bit local variable index.FIdx16A 16-bit local variable index.CP[i ] The i :th constant pool entry.Var[i ] The i:th variable/formal parameter in the current method.Opcode Mnemonic Args Stack Description0 nop [] ⇒ []1 aconst null [] ⇒ [null] Push null object2 iconst m1 [] ⇒ [-1] Push -13 . . . 8 iconst n [] ⇒ [n] Push integer constantn, 0 ≤ n ≤ 59 . . . 10 lconst n [] ⇒ [n] Push long constantn, 0 ≤ n ≤ 111 . . . 13 fconst n [] ⇒ [n] Push float constantn, 0 ≤ n ≤ 214 . . . 15 dconst n [] ⇒ [n] Push double constantn, 0 ≤ n ≤ 1Opcode Mnemonic Args Stack Description16 bipush n:int8[] ⇒ [n] Push 1-byte signed in-teger17 sipush n:int16[] ⇒ [n] Push 2-byte signed in-teger18 ldc1 n:CP8[] ⇒ [CP[n]] Push item from con-stant pool19 ldc2 n:CP16[] ⇒ [CP[n]] Push item from con-stant pool20 ldc2w n:CP16[] ⇒ [CP[n]] Push long/doublefrom constant poolOpcode Mnemonic Args Stack21 . . . 25 X load n:FIdx [] ⇒ [Var[n]]X ∈{i,l,f,d,a}, Load int, long, float, double, object fromlocal var.26 . . . 29 iload n [] ⇒ [Var[n]]Load local integer var n, 0 ≤ n ≤ 330 . . . 33 lload n [] ⇒ [Var[n]]Load local long var n, 0 ≤ n ≤ 434 . . . 37 fload n [] ⇒ [Var[n]]Load local float var n, 0 ≤ n ≤ 438 . . . 41 dload n [] ⇒ [Var[n]]Load local double var n, 0 ≤ n ≤ 4Opcode Mnemonic Args Stack42 . . . 45 aload n [] ⇒ [Var[n]]Load local object var n, 0 ≤ n ≤ 446 . . . 53 X load [A, I ] ⇒ [V ]X ∈{ia,la,fa,da,aa,ba, ca,sa}. Push the value V (an int,long, etc.) stored at index I of array A.54 . . . 58 X store n:FIdx [Var[n]] ⇒ []X ∈{i,l,f,d,a}, Store int, long, float, double, object tolocal var.59 . . . 62 istore n [Var[n]] ⇒ []Store to local integer var n, 0 ≤ n ≤ 363 . . . 66 lstore n [Var[n]] ⇒ []Store to local long var n, 0 ≤ n ≤ 4Opcode Mnemonic Args Stack67 . . . 70 fstore n [Var[n]] ⇒ []Store to local float var n, 0 ≤ n ≤ 471 . . . 74 dstore n [Var[n]] ⇒ []Store to local double var n, 0 ≤ n ≤ 475 . . . 78 astore n [Var[n]] ⇒ []Store to local object var n, 0 ≤ n ≤ 479 . . . 86 X store [A, I , V ] ⇒ []X ∈{ia,la,fa,da,aa,ba,ca,sa}. Store the value V (an int,long, etc.) at index I of array A.87 pop [A] ⇒ []Pop top of stack.Opcode Mnemonic Stack Description88 pop2 [A, B ] ⇒ [] Pop 2 ele-ments.89 dup [V ] ⇒ [V , V ]Duplicate top of stack.90 dup x1 [B, V ] ⇒ [V , B , V ] Duplicate.91 dup x2 [B, C , V ] ⇒ [V , B, C , V ] Duplicate.92 dup2 [V , W ] ⇒ [V , W , V , W ] Duplicate.93 dup2 x1 [A,V , W ] ⇒ [V , W , A, V , W ] Duplicate.94 dup2 x2 [A,B, V , W ] ⇒[V , W , A, B , V , W ] Duplicate.95 swap [A, B ] ⇒ [B, A]Swap top stack elements.Opcode Mnemonic Stack Description96 . . . 99 X add [A, B ] ⇒ [R] X ∈{i,l,d,f}. R = A + B100 . . . 103 X sub [A, B ] ⇒ [R] X ∈{i,l,d,f}. R = A − B104 . . . 107 X mul [A, B ] ⇒ [R] X ∈{i,l,d,f}. R = A ∗ B108 . . . 111 X div [A, B ] ⇒ [R] X ∈{i,l,d,f}. R = A/B112 . . . 115 X mod [A, B ] ⇒ [R] X ∈{i,l,d,f}. R = A%B116 . . . 119 X neg [A] ⇒ [R ] X ∈{i,l,d,f}. R = −A120 . . . 121 X shl [A, B ] ⇒ [R] X ∈{i,l}. R = A << B122 . . . 123 X shl [A, B ] ⇒ [R] X ∈{i,l}. R = A >> B124 . . . 125 X ushr [A, B ] ⇒ [R] X ∈{i,l}. R = A >>> B126 . . . 127 X and [A, B ] ⇒ [R] X ∈{i,l}. R = A&&B128 . . . 129 X or [A, B] ⇒ [R] X ∈{i,l}. R = A||B130 . . . 131 X xor [A, B ] ⇒ [R] X ∈{i,l}. R = AxorBOpcode Mnemonic Args Stack133 . . . 144 X 2Y cnv [F ] ⇒ [T ]Convert F from type X to T of type Y . X ∈{i,l,f,d},Y ∈{i,l,f,d}.145 . . . 147 i2X [F ] ⇒ [T ]X ∈{b,c,s}. Convert integer F to byte, char, or short.148,149,151 X cmp [A, B ] ⇒ [V ]X ∈{l,f,d}. A > B ⇒ V = 1, A < B ⇒ V = −1,A = B ⇒ V = 0. A = NaN ∨ B = NaN ⇒ V = −1150,152 X cmp [A, B ] ⇒ [V ]X ∈{f,d}. A > B ⇒ V = 1, A < B ⇒ V = −1,A = B ⇒ V = 0. A = NaN ∨ B = NaN ⇒ V = 1153 . . . 154 if⋄ L:int16[A] ⇒ []⋄={eq,ne,lt,ge,gt,le}. If A ⋄ 0 goto L + pc.Opcode Mnemonic Args Stack159 . . . 164 if icomp⋄ …


View Full Document

UA CSC 453 - The Java VM

Download The Java VM
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view The Java VM and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view The Java VM 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?