Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Stack Trace of Object Creation

Reply
Thread Tools

Stack Trace of Object Creation

 
 
moleskyca1@yahoo.com
Guest
Posts: n/a
 
      08-14-2007
Hi can jhat give me stack trace of where object was allocated? I have
many instance of large object and I need to know where they were
allocated.

Thanks

 
Reply With Quote
 
 
 
 
Lew
Guest
Posts: n/a
 
      08-14-2007
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> Hi can jhat give me stack trace of where object was allocated? I have
> many instance of large object and I need to know where they were
> allocated.


What do you mean by "where they were allocated"?

Objects change their offsets into heap quite frequently.

A stack trace won't help because Java objects live in the heap.

Tell us what "where they were allocated" means and how it will help you, and
we will try to help figure out how to achieve the goal.

--
Lew
 
Reply With Quote
 
 
 
 
Thomas Fritsch
Guest
Posts: n/a
 
      08-14-2007
(E-Mail Removed) wrote:

> Hi can jhat give me stack trace of where object was allocated? I have
> many instance of large object and I need to know where they were
> allocated.

I don't know about "jhat".
For what you want, you need a heap profiler. Sun's Java has a simple
heap profiler built-in. Call your application by
(for Java 1.6 or 1.5)
java -agentlib:hprof=heap=sites ....
or (for Java 1.5 or 1.4)
java -Xrunhprof:heap=sites ....
When your applcation ends, Java writes a file "java.hprof.txt". It
contains the stack traces from where the most objects have been
allocated, ordered by heaviness.

For more information call
(for Java 1.6 and 1.5)
java -agentlib:hprof=help
or (for Java 1.5 and 1.4)
java -Xrunhprof:help
Also read the file <yourJDKdirectory>/jre/lib/jvm.hprof.txt

--
Thomas
 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      08-14-2007
On Mon, 13 Aug 2007 21:15:32 -0400, Lew <(E-Mail Removed)> wrote,
quoted or indirectly quoted someone who said :

>
>What do you mean by "where they were allocated"?


What you would have to to is add an extra parameter to the
constructor, a string noting the location. Or if you want to get
fancier have a look at the code at
http://mindprod.com/jgloss/trace.html

Use it to capture the line number and method of the new and squirrel
it away in the object.
--
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
 
Reply With Quote
 
Thomas Hawtin
Guest
Posts: n/a
 
      08-14-2007
Thomas Fritsch wrote:
> (E-Mail Removed) wrote:
>
>> Hi can jhat give me stack trace of where object was allocated? I have
>> many instance of large object and I need to know where they were
>> allocated.

> I don't know about "jhat".
> For what you want, you need a heap profiler. Sun's Java has a simple
> heap profiler built-in. Call your application by
> (for Java 1.6 or 1.5)
> java -agentlib:hprof=heap=sites ....


jhat is the Sun JDK tool that displays the profile dumps through a web
interface. IIRC, you can set the number of stack frames recorded in the
java command line (read the docs).

Tom Hawtin
 
Reply With Quote
 
Ingo R. Homann
Guest
Posts: n/a
 
      08-14-2007
Hi,

(E-Mail Removed) wrote:
> Hi can jhat give me stack trace of where object was allocated? I have
> many instance of large object and I need to know where they were
> allocated.


I am not sure if this is what you want, but the following is of course
possible:

MyClass {

StackTrace[] creatingStackTrace=(new Throwable()).getStackTrace();

}

This can be perfectly used for debugging purposes (I did this
successfully in a productive, real-world application).

However, of course it needs some more memory, so be careful when using
it in small objects that are instantiated very often.

Ciao,
Ingo

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
C/C++ compilers have one stack for local variables and return addresses and then another stack for array allocations on the stack. Casey Hawthorne C Programming 3 11-01-2009 08:23 PM
How to redirect output from Diagnostics.Trace to Page.Trace? Matthias S. ASP .Net 1 11-30-2005 09:01 AM
Object creation - Do we really need to create a parent for a derieved object - can't the base object just point to an already created base object jon wayne C++ 9 09-22-2005 02:06 AM
Trace: Can anyone suggest a good tool to catch trace messages? Rukmal Fernando ASP .Net 4 10-27-2003 09:03 PM



Advertisments