0

I'm trying to analyze Java heap dumps in the case an exception is thrown. So e.g. for a method

void foo(){
   int[] a = new int[100];
   //do stuff

   throw new RunTimeException();
}

I create a heap dump and try to access the values of the array. For this i'm using the provided classes from com.sun.tools.hat.internal.model.

The problem is that when I iterate over all JavaThings given by the Snapshot I can't find the array. Is it possible that the values of the last stack frame aren't saved?

Also: What would be the easiest way to access the array in the example using the given classes?

skappler
  • 722
  • 1
  • 10
  • 26
  • JavaThings..? Snapshot? what do you mean? Your question is very vague. – Mohammad Najar Oct 14 '14 at 18:49
  • Sorry. Those are all classes from the hat.internal.model package. http://www.docjar.com/docs/api/com/sun/tools/hat/internal/model/package-index.html – skappler Oct 14 '14 at 18:52
  • When is the heap dump triggered? When you catch the exception? If so, then it is outside the scope of the method call and the array has become eligible for GC, thus it will probably not be part of the heap dump – Lolo Oct 14 '14 at 18:52
  • I haven written the code for creating the dumps, but in the stack trace synthesized from the dump the topmost method is the method that throws the exception. – skappler Oct 14 '14 at 18:55
  • The compiler might have optimised the array away, as it us never used. – Raedwald Oct 14 '14 at 19:33
  • It is used. Just assume something is written into it in the do stuff part. In my real usecase the arrays are added via bytecode instrumentation anyway, so they can't be optimized by the compiler :) – skappler Oct 14 '14 at 19:35

0 Answers0