-
Notifications
You must be signed in to change notification settings - Fork 518
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
183 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
hprof-heap/src/test/java/org/netbeans/lib/profiler/heap/LayoutPrinter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package org.netbeans.lib.profiler.heap; | ||
|
||
import java.io.File; | ||
import java.io.FileNotFoundException; | ||
import java.io.IOException; | ||
|
||
import org.junit.Test; | ||
|
||
/** | ||
* Resolves offset by instance ID. | ||
* | ||
* @author Alexey Ragozin (alexey.ragozin@gmail.com) | ||
*/ | ||
public class LayoutPrinter { | ||
|
||
HprofHeap heap; | ||
HprofByteBuffer dumpBuffer; | ||
long[] pointer = new long[1]; | ||
|
||
public void scan(String path) throws FileNotFoundException, IOException { | ||
FastHprofHeap heap = new FastHprofHeap(new File(path), 0); | ||
this.heap = heap; | ||
this.dumpBuffer = heap.dumpBuffer; | ||
|
||
TagBounds bounds = heap.getAllInstanceDumpBounds(); | ||
pointer[0] = bounds.startOffset; | ||
long offs = pointer[0]; | ||
long lastPtr = readID() >>> 3; | ||
System.out.println("" + offs + " -> " + lastPtr); | ||
while(true) { | ||
offs = pointer[0]; | ||
long ref = readID(); | ||
if (ref == -1) { | ||
break; | ||
} | ||
long ptr = ref >>> 3; | ||
if (ptr <= lastPtr) { | ||
System.out.println("" + offs + " -> " + lastPtr); | ||
} | ||
lastPtr = ptr; | ||
} | ||
} | ||
|
||
@Test | ||
public void test() throws FileNotFoundException, IOException { | ||
scan("file path"); | ||
} | ||
|
||
private long readID() { | ||
TagBounds bounds = heap.getAllInstanceDumpBounds(); | ||
|
||
while(pointer[0] < bounds.endOffset) { | ||
long ptr = pointer[0]; | ||
int tag = heap.readDumpTag(pointer); | ||
|
||
if ( tag == HprofHeap.INSTANCE_DUMP | ||
|| tag == HprofHeap.OBJECT_ARRAY_DUMP | ||
|| tag == HprofHeap.PRIMITIVE_ARRAY_DUMP) { | ||
return dumpBuffer.getID(ptr + 1); | ||
} | ||
} | ||
return -1; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.