Does jmap force garbage collection when the live option is used?

后端 未结 1 958
轮回少年
轮回少年 2020-12-05 00:03

I\'ve been experimenting with jmap -histo and jmap -dump today

When run in this sequence

jmap -dump:format=b,file=heap.1 [p         


        
相关标签:
1条回答
  • 2020-12-05 00:47

    In order to determine liveness, Java has to run full GC, so yes, it does.


    To put the question to sleep... here is the answer, if anyone needs to dig deeper. Feel free.

    part of /hotspot/agent/src/share/vm/services/attachListener.cpp taken from

    openjdk http://download.java.net/openjdk/jdk7/ and you must accept 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;
    }
    

    in vmGCOperations.hpp it's the definition

    `VM_GC_HeapInspection(outputStream* out, bool request_full_gc,
                       bool need_prologue) :`
    
    0 讨论(0)
提交回复
热议问题