Solved

heap dump profile

Posted on 2003-10-27
9
645 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
 

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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…

760 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now