Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Java Expert


Home >> Java

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.

Java, Programming

  • Category:- Java
  • Reference No.:- M9370253
  • Price:- $50

Priced at Now at $50, Verified Solution

Have any Question?


Related Questions in Java

Operating systems assignment -problem 1 sharing the bridgea

Operating Systems Assignment - Problem 1: Sharing the Bridge A new single lane bridge is constructed to connect the North Island of New Zealand to the South Island of New Zealand. Farmers from each island use the bridge ...

Assignment taskwrite a java console application that allows

Assignment task Write a java console application that allows the user to read, validate, store, display, sort and search data such as flight departure city (String), flight number (integer), flight distance (integer), fl ...

Assignment game prototypeoverviewfor this assessment task

Assignment: Game Prototype Overview For this assessment task you are expected to construct a prototype level/area as a "proof of concept" for the game that you have designed in Assignment 1. The prototype should function ...

Overviewyou are required to use java se 80 and javafx to

Overview You are required to use Java SE 8.0 and JavaFX to develop a Graphical User Interface (GUI) for the FlexiRent rental property management program created in Assignment 1. This assignment is designed to help you: 1 ...

Answer the following question whats the difference public

Answer the following Question : What's the difference public inheritance and private inheritance? What can derived classes inherit from base classes? What cannot be inherited from base classes?

Chatbotscreate a small networked chat application that is

Chatbots Create a small, networked chat application that is populated by bots. Introduction On an old server park, filled with applications from the early days of the internet, a few servers still run one of the earliest ...

Assessment instructionsin this assessment you will complete

Assessment Instructions In this assessment, you will complete the programming of two Java class methods in a console application that registers students for courses in a term of study. The application is written using th ...

Object-oriented software development1 introduction 11

OBJECT-ORIENTED SOFTWARE DEVELOPMENT 1. Introduction 1.1 Assignment Requirement 1.2 Deliverables and Structure (what to submit) 1.3 Software Restrictions 1.4 How to score high... 1.5 Assumptions 2. System Requirements 2. ...

Part a specification - robot simulationpart a

PART A Specification - Robot Simulation PART A Requirements To complete this assignment you will use the supplied eclipse project Robot P1/. It is already set up to execute a simple arm movement loop which you will build ...

Simple order processing systemquestion given the classes

Simple Order Processing System Question: Given the classes Ship (with getter and setter), Speedboat, and SpeedboatTest. Answer the following questions: Refine the whole application (all classes) and create Abstract class ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As