; Formal Model of the JVM - Spring 2007 ; J Strother Moore ; Practice Final Exam ; There are five problems. Each is worth 20 points. Be sure to ; put your name on your paper! You have 3 hours to do the five ; problems. You may use your notes and books. Laptops are not ; permitted. ; Partial credit will be given. ; During the actual final you will not be allowed to use ACL2. ; But to play with this practice final, you might: (include-book "m5") (in-package "M5") ; ----------------------------------------------------------------- ; Problem 1. On the actual JVM, each class description has a ; ``constant pool'' component, which associates 16-bit indices to ; various data structures. Programs are coded as a strings of ; bytes. Consider the M5's GETFIELD instruction, which we write ; as (GETFIELD (class field)). On the JVM, this is coded in three ; successive 8-bit bytes, the first of which is the hex byte B4 ; (180, decimal), which stands for GETFIELD. The next two bytes, ; say x and then y, are combined to form a 16-bit index (with x ; being the high order part and y the low order part) into the ; constant pool. The data structure at that index contains the ; class and field (strings) we write in the M5 instruction. ; Why does the JVM use the constant pool concept? Why not put ; the data in the program, as we do in M1? ; ----------------------------------------------------------------- ; Problem 2. An M5 ``method description'' is a keytuple with the ; components :name, :formals, :sync, :code, and :xtbl. Thus, ; given a method description m, (get :code m) is the list of ; bytecode instructions and (get :xtbl m) is the exception table. ; The exception table is expected to satisfy the specification: ; An exception table is a list of 4-tuples, each of the form ; (pc1 pc2 pc3 class), where the pci are legal pcs in the method, ; pc1 <= pc2, and class is the name of some class in the class ; table. ; Write an ACL2 function, chk-xt (``check exception table''), ; that takes a method description, m, and a class-table, ct, and ; returns t or nil to indicate whether the method-exception-table ; of m satisfies the above specification. ; ----------------------------------------------------------------- ; Problem 3. Extend M5 to include the new instruction described ; below. It is sufficient to define execute-XRETURNN. ; Format: (XRETURNN n) ; Operand Stack: ... val => ..., val ; Description: Return val from the nth frame from the current ; one. If n is 0, this instruction is the same as XRETURN. If n ; is 1, we return val from the frame that called the current ; frame, etc. If the call-stack is insufficiently deep, halt the ; machine. ; Note: To play with M5, you might execute (redef) so that you ; can redefine do-inst, but that is not necessary in answering ; this problem. ; ----------------------------------------------------------------- ; Problem 4. Extend M5 to include the new instruction described ; below. It is sufficient to define execute-INC. ; Format: (INC n) ; Operand Stack: ... => ... ; Description: Increment the value of local variable n by 1. ; ----------------------------------------------------------------- ; Problem 5. Extend M5 to include the new instruction described ; below. It is sufficient to define execute-STORENEW. ; Format: (STORENEW n class) ; Operand Stack: ... => ... ; Description: Create a new object of class class and store the ; reference to it into local n. ; -----------------------------------------------------------------