Is there such a thing as a continuous heap dump?
Paulo Levi
i30817 at gmail.com
Tue Sep 8 07:59:26 PDT 2009
Recently like i fool i did a performance OQL query for the netbeans
OQL console, that gives overallocated Buffers, like duplicated
BufferedReaders etc, this works, but only if the dump is at exactly
the right time, which is most useless since these objects are short
lived and the whole point is discovering them. So i'd like to know if
there is a way to generate a continuous heap dump, like a collection
of all the states the application went through until a point, or if
that is not possible at least to trigger a heap dump before the
finalize of certain objects (like in a finalizer, but without the
finalizer obviously). I'd like this to be unobtrusive too. I guess
that there might be other performance analysis that could be done if
only heap dumps gave a more complete overview of the app state.
the query is this:
var duplicated;
function instanceOf(it, other){
c2 = heap.findClass(other);
if(c2 == null)
return false;
c1 = classof(it);
return c1 == c2 || c1.isSubclassOf(c2);
}
function overAllocationFilterInputStream(it) {
while(instanceOf(it, "java.io.FilterInputStream")){
stream = it["in"];
if(instanceOf(stream, "java.io.BufferedInputStream") ||
instanceOf(stream, "java.io.ByteArrayInputStream") ||
instanceOf(stream, "java.io.StringBufferInputStream") ||
instanceOf(stream, "java.io.PipedInputStream")){
duplicated = stream;
return true;
}
it = stream;
}
return false;
}
function overAllocationFilterOutputStream(it) {
while(instanceOf(it, "java.io.FilterOutputStream")){
stream = it["out"];
if(instanceOf(stream, "java.io.BufferedOutputStream") ||
instanceOf(stream, "java.io.ByteArrayOutputStream") ||
instanceOf(stream, "java.io.PipedOutputStream")){
duplicated = stream;
return true;
}
it = stream;
}
return false;
}
function overAllocationReader(it) {
while(instanceOf(it, "java.io.BufferedReader") || instanceOf(it,
"java.io.FilterReader")){
stream = it["in"];
if(instanceOf(stream, "java.io.BufferedReader") ||
instanceOf(stream, "java.io.PipedReader") ||
instanceOf(stream, "java.io.CharArrayReader") ||
instanceOf(stream, "java.io.StringReader")){
duplicated = stream;
return true;
}
it = stream;
}
return false;
}
function overAllocationWriter(it) {
while(instanceOf(it, "java.io.BufferedWriter") || instanceOf(it,
"java.io.FilterWriter")){
stream = it["out"];
if(instanceOf(stream, "java.io.BufferedWriter") ||
instanceOf(stream, "java.io.PipedWriter") ||
instanceOf(stream, "java.io.CharArrayWriter") ||
instanceOf(stream, "java.io.StringWriter")){
duplicated = stream;
return true;
}
it = stream;
}
return false;
}
function showOAinfo(it) {
return toHtml(it) + " buffers data that " + toHtml(duplicated) + "
also does, one of them probably should be eliminated.";
}
map(
concat(
concat(
concat(
concat(
concat(
heap.objects("java.util.zip.InflaterInputStream", false,
'overAllocationFilterInputStream(it)'),
heap.objects("java.io.BufferedInputStream", false,
'overAllocationFilterInputStream(it)')),
heap.objects("java.util.zip.DeflaterOutputStream", false,
'overAllocationFilterOutputStream(it)')),
heap.objects("java.io.BufferedOutputStream", false,
'overAllocationFilterOutputStream(it)')),
heap.objects("java.io.BufferedReader", false, 'overAllocationReader(it)')),
heap.objects("java.io.BufferedWriter", false,
'overAllocationWriter(it)')), showOAinfo);
More information about the serviceability-dev
mailing list