Solved

heap dump profile

Posted on 2003-10-27
9
655 Views
Last Modified: 2013-11-23
Hi

I have a problem with "OutOfMemoryException".
I have tried to make sure that my program doesn't leak memory using optimizeIt.
Nevertheless in some cases (on the field), the program stops with "OutOfMemException".

I've figured to that with the -Xrunhprof:heap=all flag, I can make the jvm dump its heap.
If I can analyze the heap I can determine if the app needs more memory or if it leaks.
The problem is that I can find no tool to analyze the XX Mb large heap dump.

Any hints? (I'm using java1.4@win2k.)

www.hpjmeter.com doesn't support java1.4.
The experimental "hat"-tool from sun doesn't work in 1.4.
http://prophit.westslopesoftware.com/ is closed?
PerfAnal (http://www.javalinux.net/CDROM/#JavaBinaries) is too old.

0
Comment
Question by:eklas
  • 4
  • 2
  • 2
9 Comments
 
LVL 7

Expert Comment

by:tomboshell
ID: 9626595
Interesting...I've always done manual checking.  Make sure all loops end correctly, no never-ending loops, counters don't reach infinity, recursive calls have ending situations that WILL be reached, close File I/O classes, and such.  That is the advice I could give, so I wait and listen to other expert advice--I might learn something :)
0
 

Author Comment

by:eklas
ID: 9626762
It's a fairly large GUI app (~100Mb ram).
Each dump is ~15mb.
Impossible to get an overview by reading the heap-dump text file.
0
 
LVL 1

Expert Comment

by:amswain
ID: 9627045
Have you tried setting the max heap size of the vm running the swing app.

java -Xmx256m

You could also run a thread inside you app

    /** Thread used to update the status bar with memory use */
    private Thread thread = new Thread( "Memory use thread" ) {
        public void run() {
            while( true ) {
                getStatusBar().setPercentMemoryUsed( MemoryManager.getPercentageUsed() );
                try {
                    Thread.sleep( 1500L );
                } catch ( InterruptedException ex ) {
                }
            }
        }
    };


class MemoryManager {

    /** The runtime environment */
    private static Runtime runtime = Runtime.getRuntime();

    /**
     *  The percentage used.
     */
    public static int getPercentageUsed() {
        long free = runtime.freeMemory();
        long total = runtime.totalMemory();
        double used = (total-free)/(double)total;
        return (int)(100*used);
    }
}

I have something like this running in my swing gui which is also quite memory hungry.
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

Author Comment

by:eklas
ID: 9627124
I need more detailed info than total amount of memory used.
I currently use "-Xmx100m".
I don't just want to increase mem by +30% without knowing why.
It might be a mem leak problem in some rase use case that I havn't covered in my tests.
To be 100% sure that the code doesn't leak mem I need to do a 100% code coverage in the my mem tests. Impossible. Therefore I need a heap dump _when_ the situation occurrs.
Compare to a thead dump (ctrl-beak, kill -QUIT <pid>).
Of course it must be possible to do something simliar on memory problems?!?
0
 
LVL 1

Expert Comment

by:amswain
ID: 9627205
Sure, I understand what you want to do but if there's a specific action in the gui that is causing the memory to go sky high then you should probably investigate that first.  I have found it quite useful to see what the memory is doing (on our status bar).  I used JProbe some time ago but it wasn't with java 1.4.  I can't give you any specific advice for java 1.4 i'm afraid.
0
 

Author Comment

by:eklas
ID: 9627665
Nope, the problem is not reproducible.
Any help for 1.3 or 1.4 will do.
0
 
LVL 7

Accepted Solution

by:
tomboshell earned 500 total points
ID: 9634053
I just ran across this while surfing the net: http://www.alphaworks.ibm.com/tech/heaproots?open&ca=daw-rss-s8
as they state it "HeapRoots is a tool for debugging memory leaks in JavaTM applications through analysis of "heap dumps.""

You might want to give it a whirl.
0
 

Author Comment

by:eklas
ID: 9636389
HeapRoot:s was a very nice tool.
If no-one can come up with with a tool compatible with Sun Jdk (that I can run on solaris),
your answer was the best available.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question