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

  Discuss factors that affect sorting in sediment

Discuss factors that affect sorting in sediment. How could one tell the latitude at which a sediment was originally deposited? Compare and contrast phosphate and manganese nodules.

  Part-1inheritance write code using eclipse and output

part-1inheritance write code using eclipse and output screenimplement a subclass square that extends the rectangle

  Die class that can hold an integer

Design a die class that can hold an integer from 1 to 6. use the dice class to create a dice game. in this game, the user chooses a number between 2 and 12 inclusive

  A common useful equation

In physics, a common useful equation for finding the position s of a body in linear motion at a given time t, based on its initial position s0, initial velocity v0, and rate of acceleration a, is the following: ??= ??0+??0??+12????2. Write code to de..

  Define private instance variable to hold boolean value

Write a Java Enumeration "LetterGrade" that represents letter grades A through F including plus and minus grades. Define a private instance variable to hold a boolean value.

  Hunt the wumpus game

Reprot on Hunt the Wumpus Game has Source Code listing, screen captures and UML design here and also, may include Javadoc source here.

  Create a class for services offered by a hair-styling salon

Create a class for services offered by a hair-styling salon. Data fields include a String to hold the service description and write an application named Salon Report that contains an array to hold six Service objects and fill it with the data

  Write a class named test scores

Write a class named TestScores.The class constructor should accept an array of test scores as an argument.The class should have a method that returns the average of the test scores.

  Using notepad that implements a basic text analyzer

Write a Java application using Notepad that implements a basic Text Analyzer.

  Minimal spanning tree decreasing edge

minimal spanning tree decreasing edge dismissalreverse-delete algorithm. develop an implementation that computes the

  Prepare worlddataapp project it implements the nameindex

prepare worlddataapp project. it implements the nameindex portion includingbull creating it implemented as a binary

  Design a java program that has two parallel arrays

Design a java program that has two parallel arrays: a string array named people that is initialized with the names of seven of your friends, and a string array named phoneNumbers that is initialized with your friends phone numbers.

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