DOC PREVIEW
UA CSC 453 - Study Notes

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

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 11 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 11 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 11 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 11 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 11 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

CSc 453 Compilers and Systems Software 17 The Java VM Christian Collberg Department of Computer Science University of Arizona collberg gmail com c 2009 Christian Collberg Copyright October 25 2009 1 The Java Virtual Machine The Java VM has gone the many complex instructions large VM engine way Each Java source file may contain several Java classes The Java compiler compiles each of these classes to a single Java class file The Java class file stores all necessary data regarding the class There is a symbol table called the Constant Pool which stores strings large literal integers and floats names and of all fields and methods Each method is compiled to Java bytecode a stack VM format The class file is almost isomorphic to the source 2 File java class C1 method M1 int F1 Read lex parse VM Code C2 class C1 class semantics C3 class class C2 Class File Format Magic Number class C3 Constant Pool Transfer class files over the net Read Read VM VM Access Flags Compile This Class read eval print Super Class Interfaces Native Code Interpret Fields Methods Execute Attributes 1 3 Constant Pool Magic Number String HELLO Method C M int Field int F Constant Pool Access Flags This Class Super Class Interfaces Fields Fields Name x priv y Flags pub Methods Attributes Type int C Attributes Methods Flags pub Name Sig q int Code Exceptions Attributes Code MaxStack 5 MaxLocals 8 Code push add store ExceptionTable Attributes 4 Java Byte Codes The 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 formal parameters The bytecode reference these by number Actually we can have up to 65536 local vars There is a special wide instruction that modifies load and store instructions to reference the high numbered locals Hack 5 Java Byte Codes The Java stack is 32 bits wide Longs and doubles hence take two stack entries The bytecodes reference data from the class constant pool These references are 8 or 16 bits long To push a reference to a literal string with constant pool 4567 use ldc2 4567 If the is 123 use ldc2 123 6 Java Byte Codes int8 int16 int32 CP8 CP16 FIdx FIdx16 CP i Var i An 8 bit integer value A 16 bit integer value A 32 bit integer value An 8 bit constant pool index A 16 bit constant pool index An 8 bit local variable index A 16 bit local variable index The i th constant pool entry The i th variable formal parameter in the current method 2 7 Opcode 0 1 2 3 8 Mnemonic nop aconst null iconst m1 iconst n Args Stack null 1 n 9 10 lconst n n 11 13 fconst n n 14 15 dconst n n Opcode 16 Mnemonic bipush Args n int8 Stack n 17 sipush n int16 n 18 ldc1 n CP8 CP n 19 ldc2 n CP16 CP n 20 ldc2w n CP16 CP n Description Push null object Push 1 Push integer constant n 0 n 5 Push long constant n 0 n 1 Push float constant n 0 n 2 Push double constant n 0 n 1 8 Description Push 1 byte signed integer Push 2 byte signed integer Push item from constant pool Push item from constant pool Push long double from constant pool 9 Opcode 21 25 26 29 30 33 34 37 38 41 Mnemonic Args Stack Xload n FIdx Var n X i l f d a Load int long float double object from local var iload n Var n Load local integer var n 0 n 3 lload n Var n Load local long var n 0 n 4 fload n Var n Load local float var n 0 n 4 dload n Var n Load local double var n 0 n 4 3 10 Opcode 42 45 46 53 54 58 59 62 63 66 Mnemonic Args Stack aload n Var n Load local object var n 0 n 4 Xload 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 Xstore n FIdx Var n X i l f d a Store int long float double object to local var istore n Var n Store to local integer var n 0 n 3 lstore n Var n Store to local long var n 0 n 4 11 Opcode 67 70 71 74 75 78 79 86 87 Mnemonic Args Stack fstore n Var n Store to local float var n 0 n 4 dstore n Var n Store to local double var n 0 n 4 astore n Var n Store to local object var n 0 n 4 Xstore 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 pop A Pop top of stack 12 Opcode 88 Mnemonic pop2 89 dup V V V Duplicate top of stack dup x1 B V V B V dup x2 B C V V B C V dup2 V W V W V W dup2 x1 A V W V W A V W dup2 x2 A B V W V W A B V W swap A B B A Swap top stack elements 90 91 92 93 94 95 Stack A B Description Pop 2 elements 4 Duplicate Duplicate Duplicate Duplicate Duplicate 13 Opcode 96 99 100 103 104 107 108 111 112 115 116 119 120 121 122 123 124 125 126 127 128 129 130 131 Mnemonic Xadd Xsub Xmul Xdiv Xmod Xneg Xshl Xshl Xushr Xand Xor Xxor Stack A B R A B R A B R A B R A B R A R A B R A B R A B R A B R A B R A B R Description X i l d f R A B X i l d f R A B X i l d f R A B X i l d f R A B X i l d f R A B X i l d f R A X i l R A B X i l R A B X i l R A B X i l R A B X i l R A B X i l R AxorB Opcode 133 144 Mnemonic Args Stack X2Y cnv F T Convert F from type X to T of type Y X i l f d Y i l f d i2X F T X b c s Convert integer F to byte char or short Xcmp A B V X l f d A B V 1 A B V 1 A B V 0 A NaN B NaN V 1 Xcmp A B V X f d A B V 1 A B V 1 A B V 0 …


View Full Document

UA CSC 453 - Study Notes

Download Study Notes
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 Study Notes 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 Study Notes 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?