为了确定存活性,Java必须运行完整的GC,所以是的,它会这样做。
为了解决问题...这里是答案,如果有人需要深入了解,请随意。
/hotspot/agent/src/share/vm/services/attachListener.cpp 的一部分 取自
openjdk http://download.java.net/openjdk/jdk7/
并且你必须接受 http://www.gnu.org/licenses/gpl-2.0.html
static jint heap_inspection(AttachOperation* op, outputStream* out) {
bool live_objects_only = true;
const char* arg0 = op->arg(0);
if (arg0 != NULL && (strlen(arg0) > 0)) {
if (strcmp(arg0, "-all") != 0 && strcmp(arg0, "-live") != 0) {
out->print_cr("Invalid argument to inspectheap operation: %s", arg0);
return JNI_ERR;
}
live_objects_only = strcmp(arg0, "-live") == 0;
}
VM_GC_HeapInspection heapop(out, live_objects_only , true );
VMThread::execute(&heapop);
return JNI_OK;
}
在vmGCOperations.hpp中,这是定义。
`VM_GC_HeapInspection(outputStream* out, bool request_full_gc,
bool need_prologue) :`
-histo
选项,live
子选项是可选的,并指定只转储活动对象。同意,这并没有直接告诉我们GC运行的情况,但正如之前提到的那样,这可能是唯一(也是最方便)的方法。 - David Lantos