当使用live选项时,jmap是否强制进行垃圾收集?

我今天一直在尝试使用jmap -histojmap -dump

按此顺序运行时

 jmap -dump:format=b,file=heap.1 [pid] jmap -dump:live,format=b,file=heap.2 [pid] jmap -dump:format=b,file=heap.3 [pid] 

heap.3heap.1 。 特别是,我在heap.1中感兴趣的“死”对象在heap.1中不存在。

看到这个,我开始寻找可以告诉我应该期待的文档。 我最接近的是这次讨论 ,来自briand和alanb的评论意味着在实践中我可以预期当我使用live选项时会发生这个GC; 但答案是五年了,论坛上的post对于规范来说似乎有些不正式。

我在哪里可以找到记录的当前行为?

为了确定活跃性,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

 // Implementation of "inspectheap" command // // Input arguments :- // arg0: "-live" or "-all" static jint heap_inspection(AttachOperation* op, outputStream* out) { bool live_objects_only = true; // default is true to retain the behavior before this change is made 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 /* request full gc */, true /* need_prologue */); VMThread::execute(&heapop); return JNI_OK; } 

在vmGCOperations.hpp中,这是定义

 `VM_GC_HeapInspection(outputStream* out, bool request_full_gc, bool need_prologue) :`