Unformatted text preview:

University of Arizona, Department of Computer ScienceCSc 620 — Assignment 1 — Due midnight, Mon Sep 12 — 5%Christian CollbergAugust 29, 20051 IntroductionThe pur pose of this assignment is to learn Java bytecode, the J asmin Java assembler, the BCEL bytecodeediting library, and the JDI Java debugging library.You c an do this assignment in teams of two.2 JasminThe purpose of this task is to gain some experience writing in Java bytecode. Jasmin can be fo und here:http://sourceforge.net/projects/jasmin.1. Translate the following Java program C.java to a Jasmin assembly file C.jasmin:c l a s s C {s t a t i c void P( i n t i ) {System . out . p r i n t l n ( i ) ;}p u b l i c s t a t i c vo id main ( S t r i n g [ ] a r gs ) {f o r ( i n t i =0; i < 10 ; i ++) {P( i ∗ 1 0 0 ) ;}}}2. Assemble C.jasmin using Jasmin into C.class and execute it. Debug until it works. <-;.3. Disassemble C.class using javap.3 BCELThe purpose of this task is to gain some exp e rience manipulating Java class files. You can download andread about BCEL here: http://jakarta.apache.org/bcel.Write a BCEL program Instrument.java that traces method calls, i.e. it should11. Open up a Java classfile C.class given on the command line:> java Ins t r u ment C. c l a s s C1 . c l a s s2. Insert, at the beginning and end of every method, code that prints out the name of the method andthe values of the incomming arguments:c l a s s C {s t a t i c void P( i n t i ) {System . out . p r i n t l n (”ENTERING C. P” ) ;System . out . p r i n t l n ( ” i =”, i ) ;System . out . p r i n t l n ( i ) ;System . out . p r i n t l n (”EXITING P” ) ;}p u b l i c s t a t i c vo id main ( S t r i n g [ ] a r gs ) {System . out . p r i n t l n (”ENTERING C. main ” ) ;f o r ( i n t i =0; i < 10 ; i ++) {P( i ∗ 1 0 0 ) ;}System . out . p r i n t l n (”EXITING C. main ” ) ;}}To simplify things, you only have to print out values of integer arguments.3. Save the mo dified cla ssfile to C1.class, also give on the command line.4. Try it out on C.class from the previous section.> java In s t r u ment C. c l a s s C1 . c l a s s> java C1 . c l a s sDisassemble C.class with javap to see that you generated the expected code.4 JDIThe purpose of this task is to gain some experience executing a Java program under the Java debuggerinterface, JDI.The JDI API can be found here: http://java.sun.com/products/jpda/doc/jdi/index.htmlWrite a JDI program Trace.java that traces method calls, i.e. it should1. Open up a Java classfile C.class given on the command line:> java − c l a s s p a t h . : t o o l s . j a r Trace C. c l a s stools.jar comes with Sun’s Java dis tribution.2. Start running that program under J DI. This is approximately what needs to be done to get started:2p r i v a t e com . sun . j d i . connect . Connector f i ndC o nn e ct o r ( St r i n g name ) {ja va . u t i l . L i s t c o n n ec t or s =com . sun . j d i . B o o ts tr a p . virtualMachineManager ( ) . a l l C o n n e c to r s ( ) ;ja va . u t i l . I t e r a t o r i t e r = co n ne c to r s . i t e r a t o r ( ) ;wh i le ( i t e r . hasNext ( ) ) {com . sun . j d i . c o n n e c t . Connector c on n ec t o r =(com . sun . j d i . connect . Connector ) i t e r . next ( ) ;i f ( co n ne c to r . name ( ) . eq u a l s (name ) ) {r e tur n co nne c to r ;}}r e tur n n u l l ;}com . sun . j d i . Virtua lM a c h ine vm;p u b l i c s t a t i c v o i d main ( St r i n g [ ] a rg s ) {i n t t r a c e F l a g s = com . sun . j d i . Vi r t ua l Ma chine .TRACEALL;S t r i n g c o n n ectSpec = ”com . sun . j d i . CommandLineLaunch” ;com . sun . j d i . co nnect . Connector co n nec t or = f ind C on n ec t o r ( co nnectSp e c ) ;ja va . u t i l .Map connecto rA r g s = c o nn e cto r . defa ultArgument s ( ) ;com . sun . j d i . co nnect . Connector . Argument argument =(com . sun . j d i . c o n nect . Connector . Argument) co nnectorArgs . g e t (” main ” ) ;S t r i n g cmdLine = ” ” ;f o r ( in t i =0; i < argv . le ng th ; i ++)cmdLine += argv [ i ] + ” ” ;argument . s etV a lu e ( cmdLine ) ;com . sun . j d i . co nnect . LaunchingConnector lau n ch e r =(com . sun . j d i . c o n nect . LaunchingConnector ) co n nec t or ;vm = l a un c her . launch ( co nnectorArgs ) ;vm. setDebugTraceMode( t r a c e F l a g s ) ;ja va . lang . P r o c e ss p r o c e s s = vm. p r o c e s s ( ) ;vm. resume ( ) ;}3. For every method entry and exit point, print out what method was entered, and exited. This can eitherbe done by setting breakpoints (probably the wrong thing …


View Full Document

UA CSC 620 - CSc 620 — Assignment 1

Download CSc 620 — Assignment 1
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 CSc 620 — Assignment 1 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 CSc 620 — Assignment 1 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?