Tracer for java

Assignment Help JAVA Programming
Reference no: EM13100013

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: EM13100013

Questions Cloud

Finite population correction factor : Using the finite population correction factor, compute the standard error for each of the three firms given a sample of size 50.
Exponential distribution function-derivation of equation : Show how to generate a random variable from the exponential distribution function shown above. Show derivation of the equation.
Explain clarions current information systems : Recognize the key players in this case. Explain each players role and their relationship to each other. Explain the IS management position(s) which were missing at Clarion and suggest candidate(s) to fill roles.
Identify the gas that was produced : Hypothesize why some substances were not metabolized, while others were. Research the chemical formula of Equal and Splenda and explain how it would affect respiration.
Tracer for java : Implementation of a tracer of Java objects and the tracer can be invoked from any point of a Java program, accepting an object as argument.
Designing and implementing mrp system : Stan Garner resides in illinois and promotes boxing matches for Supersports, INC. an Illinois corporation. Garner created the conect of "ages" promotion- a three fight series of boxing matches pitting an older fighter (george foreman) against a young..
Difference between descriptive and prescriptive models : Explain the difference between descriptive and prescriptive (optimization) models. Describe how to use Excel data tables, scenario manager, and goal seek tools to analyze decision models.
Estimating quality assurance and binomial distribution : John Rengel is the Quality Assurance Supervisor for Vino Supremo Vinyards. He knows that 10 percent of each box of corks is undersized.
Determine the concentration of culture a and b : Assume that you measure the OD of two E.coli cultures: culture A and culture B. The spectrophotometer gives you a reading of 3.2 for culture A and 0.01 for culture B. What would you do to determine the concentration of culture A and B and why? Giv..

Reviews

Write a Review

JAVA Programming Questions & Answers

  Create application uses two-dimensional arrays

Create an application which uses 2-dimensional arrays to keep track of 5 students' grades, with each student having 3 different classes.

  Write program in java-calculate and display mortgage payment

Write the program in Java (with a graphical user interface) and have it calculate and display the mortgage payment amount from user input of the amount of the mortgage.

  Write java program to store values retrieved from user-array

Write a Java program named Arrays6_2GF.java Use an array to store values retrieved from user input. The number of integers to be entered (the length of the array )should also be retrieved through user input.

  Write down the java code for the bank

Write down the java code for the bank of Fraud. User is presented with menu which looks something like this: 1. Deposit 2. Withdrawal 3. Check Balance 4. Exit.

  Evaluate the rtas resource requirements

Design and implement a set of classes and interfaces and use them to evaluate the RTA's resource requirements.

  Program to find maximum-minimum of sequence of values

Common task which should be done in loop is to find maximum and minimum of sequence of values. File Temps.java contains program which reads in sequence of hourly temperature readings over 24- hour period.

  Develop a reliable transfer protocol over udp

Develop a reliable transfer protocol over UDP. Focus on a Stop- and-Wait protocol.

  Dijikstra for undirected graph using simple scheme

Dijikstra for undirected graph using simple scheme with array and fibonacci heap and compare the performance/results, preferably in java.

  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

  Java application which creates bank records

Write down a java application which creates 10000 bank records and the allow user ti enter a balance and customer account info. using a an account number.

  Implement simple java program to input syllabus grades

To implement simple Java program to input (hypothetical) syllabus grades, computing and displaying both normal Mean and Harmonic Mean.

  Write a java program in a netbeans project

Write a Java program in a NetBeans project

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