1 introductionin order to debug an application it is

Assignment Help JAVA Programming
Reference no: EM13372102

1 Introduction

In order to debug an application, it is sometimes useful to know where a given object comes from, or where was it sent to. An object tracer describes the origin of an object and also the places where the object was provided as an argument or returned as a result.

2 Goals

Implementation of a tracer of Java objects. The tracer can be invoked from any point of a Java program, accepting an object as argument. The tracer should immediatly log on System.err the history of that object in terms of the place where it was created, and all places where it was provided as an argument or returned as a result.

The tracer is called using the following form:

ist.meic.pa.Trace.print(object)

This means that y o u need to implement the class ist.meic.pa.Trace withastatic method that accepts one object as argument.

As a result of calling the previous method, the tracer must then present the point of instantiation and the points of call/return in the history of the object, namely:

  •  The constructor call used to create the object, including le name and line number.
  •  All method calls where the object was used as an argument, including le name and line number.
  •  All method calls where the object was returned, including le name and line number.

It should be possible to invoke the tracer in several di erent points of the (traced) program, with several di erent objects. The trace information for that object should follow the time sequence of operations on that object, from the oldest one to the most recent one.

3 Interface

The tracer presents the object history based on a textual representation that is printed on the console. As an example, consider the following Java class de ned in le Test0.java:

1 import ist.meic.pa.Trace;
2
3 class Test {
4
5 public Object foo() {
6 return new String("Foo");
7 }
8
9 public Object bar() {
10 return new String("Bar");
11 }
12
13 public Object identity(Object o) {
14 return o;

15 }
16
17 public void test() {
18 Trace.print(foo());
19 Object b = bar();
20 Trace.print(identity(b));
21 }
22 }
23
24 public class Test0 {
25
26 public static void main(String args[]) {
27 (new Test()).test();
28 }
29 }
The execution of this Java class le produces the following output:
$ java Test0
Tracing for Foo is nonexistent!
Tracing for Bar is nonexistent!

However, by using Javassist, it is possible to transform the bytecode of the class le in a way that allows much more information to be printed. The bytecode transformation is done at load time, by the class TraceVM.

Using this class, the example becomes:

$ java ist.meic.pa.TraceVM Test0

Tracing for Foo
<- java.lang.String(java.lang.String) on Test0.java:6
<- Test.foo() on Test0.java:18
-> ist.meic.pa.Trace.print(java.lang.Object) on Test0.java:18

Tracing for Bar
<- java.lang.String(java.lang.String) on Test0.java:10
<- Test.bar() on Test0.java:19
-> Test.identity(java.lang.Object) on Test0.java:20
<- Test.identity(java.lang.Object) on Test0.java:20
-> ist.meic.pa.Trace.print(java.lang.Object) on Test0.java:20

Note, in the previous example, that the arrows show the direction of the control flow. The arrow <- indicates that the object was returned, either from calling a constructor, or from calling a method. The arrow -> indicates that the object was provided as argument to a constructor or to a method call. After printing the arrow, the tracer prints the invoked constructor or method, and the le name and line number where the invocation was done.

Asasecond example, consider the following le Test1.java:

1 import ist.meic.pa.Trace;
2
3 class Test {
4
5 public Object foo() {
6 return new String("Foo");
7 }
8
9 public Object bar() {
10 return foo();
11 }
12
13 public Object baz() {
14 return bar();
15 }
16
17 public void test() {

18 Trace.print(foo());
19 Trace.print(bar());
20 Trace.print(baz());
21 }
22 }
23
24 public class Test1 {
25
26 public static void main(String args[]) {
27 (new Test()).test();
28 }
29 }

Running the previous class le using the bytecode transformation implemented by TraceVM, produces the following output:

$ java ist.meic.pa.TraceVM Test1
Tracing for Foo
<- java.lang.String(java.lang.String) on Test1.java:6
<- Test.foo() on Test1.java:18
-> ist.meic.pa.Trace.print(java.lang.Object) on Test1.java:18
Tracing for Foo
<- java.lang.String(java.lang.String) on Test1.java:6
<- Test.foo() on Test1.java:10
<- Test.bar() on Test1.java:19
-> ist.meic.pa.Trace.print(java.lang.Object) on Test1.java:19
Tracing for Foo
<- java.lang.String(java.lang.String) on Test1.java:6
<- Test.foo() on Test1.java:10
<- Test.bar() on Test1.java:14
<- Test.baz() on Test1.java:20
-> ist.meic.pa.Trace.print(java.lang.Object) on Test1.java:20

Assignment is to implement the classes ist.meic.pa.Trace and ist.meic.pa.TraceVM. The rst one is used to print the history of an object. The second one is used to transform the bytecode of all classes loaded as a result of loading its rst argument.

In order to implement the required output format, y o u should consider the following templates:

 When there is no tracing information:

Tracing for object is nonexistent!
 When there is tracing information:

Tracing for object
followed, in the case of a constructor or method call returning object as result, by

<- behavior on file :line

or, in the case of a constructor or method call using object as argument

-> behavior on file :line

In the previous templates, object is the printed representation of an object, as produced by its toStringmethod, while behavior is the description of a constructor or method, as implemented b y Javassist API method getLongName. Finally, file is the name of the le and line is a number.

4 Code
Your implementation must work in Java 6 and should use the bytecode manipulation tool Javassist, version 3.18.1-GA.

The written code should have the best possible style, should allow easy reading and should not require excessive comments. It is always preferable to have clearer code with few comments than obscure code with lots of comments.

The code should be modular, divided in functionalities with speci c and reduced responsibilities. Each module should haveashort comment describing its purpose.

You must implement a Java class named ist.meic.pa.Trace that must provide, at least, the method with signature:

static public void print(Object object)

The previous method prints on System.err the trace of the object provided as argument, following the format described previously.

You must also implement a Java class named ist.meic.pa.TraceVM, containingastatic method main that accepts, as arguments, the name of another Java program (i.e., a Java class that also containsastatic method main)) and the arguments that should be provided to that program. The class should (1) operate the necessary transformations to the loaded Java classes so that objects are traced during the execution of the program, and (2) should transfer the control to the main method of the program.

Reference no: EM13372102

Questions Cloud

Suppose you present overview of computers and software to : suppose you present overview of computers and software to individuals who have not utilized computers extensively and
Prepare a research paper on great depressionthe encarta : prepare a research paper on great depressionthe encarta website gives a geneal overview of what youll need. you can
Write a persuasive essay using apa format on a given : write a persuasive essay using apa format on a given commodity.how is the production or trade of plastic bags ethical
Piston and flywheelconsider the one-cylinder four-stroke : piston and flywheelconsider the one-cylinder four-stroke engine assembly shown in figure 1. the mass of the piston p is
1 introductionin order to debug an application it is : 1 introductionin order to debug an application it is sometimes useful to know where a given object comes from or where
Huang is the son of successful malaysian business people : huang is the son of successful malaysian business people and works for his parents company. huang owns a home in a
1 ross whites machine shop uses 2500 brackets during the : 1. ross whites machine shop uses 2500 brackets during the course of the year and this usage is relatively constant
Create functions in filehow to code this functiondeclare : create functions in filehow to code this functiondeclare function inputs and outputsdownload-
You have to create a world class that contains a 2d array : you have to create a world class that contains a 2d array then create an abstract class called organism that contains

Reviews

Write a Review

JAVA Programming Questions & Answers

  Your letterinventory class must use an array

Your LetterInventory class must use an array of Counter objects. Note that there is no nextChar method in the Scanner class. You must use the next() method and then use a loop through the characters of the token that is returned. Ignore any character..

  Determine the type of moped

Write a driver class called MopedRental. This class should perform the following: asks the user to enter the size of the moped, the day of the week and the number of hours rented, creates the Moped object, based on the size, and displays the input..

  Write a restful web service demo example using spring mvc

Write a restful web service demo example using spring mvc

  Using an array in java

Using an array in Java - have a list of keywords from a web service and have to print out the list of keywords on the screen with one keyword on each line. This is my code

  Write a java program to register students for a college

Project is for designing and developing a College Registration program. Write a Java program to register students for a college

  What aspects of judaism are rejected or reinterpreted

What theology does Jesus present in the two excerpts from the Gospels that are a part of the readings? What aspects of Judaism are strongly represented? What aspects of Judaism are rejected or reinterpreted?

  Web engineering principles

web application development, Web Engineering methodology, UML-based Web Engineering (UWE), models to the expansion of web applications, Object Oriented Web Solutions (OOWS),Web Modeling Language (WebML) methodology, Object-Oriented Hypermedia Design..

  Write a java program to perform matrix multiplication

Write a java program to perform matrix multiplication - Your code will need to be able to read in these files, place the contents of each file into separate two-dimensional arrays and then perform the needed multiplication and place the output of t..

  How large a value can be stored in an integer variable

Most programming languages have a built-in integer data type. Normally this representation has a fixed size, thus placing a limit on how large a value can be stored in an integer variable

  What was in mind of the coder in each part of the code

Need a video that goes through all this java code - as if it was a tutorial showing it line by line - and explain in detail the structure of it all as if you code it yourself.

  The application with all the specifications should be

the application with all the specifications should be developed based on a graphical user interface.1. implement proper

  Java program which demonstrates cellular automata

Using the internet, locate a Java program (or Java applet) which demonstrates "Cellular Automata", in particular "the Game of Life".

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd