src/hotspot/share/services/attachListener.cpp
changeset 53858 e7cf035682e3
parent 52876 2d17750d41e7
child 54065 f984aca565c1
equal deleted inserted replaced
53851:cc4f5bf6b26b 53858:e7cf035682e3
     1 /*
     1 /*
     2  * Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2005, 2019, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     7  * published by the Free Software Foundation.
   255 
   255 
   256 // Implementation of "inspectheap" command
   256 // Implementation of "inspectheap" command
   257 // See also: ClassHistogramDCmd class
   257 // See also: ClassHistogramDCmd class
   258 //
   258 //
   259 // Input arguments :-
   259 // Input arguments :-
   260 //   arg0: "-live" or "-all"
   260 //   arg0: Name of the dump file or NULL
       
   261 //   arg1: "-live" or "-all"
   261 static jint heap_inspection(AttachOperation* op, outputStream* out) {
   262 static jint heap_inspection(AttachOperation* op, outputStream* out) {
   262   bool live_objects_only = true;   // default is true to retain the behavior before this change is made
   263   bool live_objects_only = true;   // default is true to retain the behavior before this change is made
   263   const char* arg0 = op->arg(0);
   264   outputStream* os = out;   // if path not specified or path is NULL, use out
   264   if (arg0 != NULL && (strlen(arg0) > 0)) {
   265   fileStream* fs = NULL;
   265     if (strcmp(arg0, "-all") != 0 && strcmp(arg0, "-live") != 0) {
   266   const char* path = op->arg(0);
   266       out->print_cr("Invalid argument to inspectheap operation: %s", arg0);
   267   if (path != NULL) {
       
   268     if (path[0] == '\0') {
       
   269       out->print_cr("No dump file specified");
       
   270     } else {
       
   271       // create file
       
   272       fs = new (ResourceObj::C_HEAP, mtInternal) fileStream(path);
       
   273       if (fs == NULL) {
       
   274         out->print_cr("Failed to allocate space for file: %s", path);
       
   275         return JNI_ERR;
       
   276       }
       
   277       os = fs;
       
   278     }
       
   279   }
       
   280   const char* arg1 = op->arg(1);
       
   281   if (arg1 != NULL && (strlen(arg1) > 0)) {
       
   282     if (strcmp(arg1, "-all") != 0 && strcmp(arg1, "-live") != 0) {
       
   283       out->print_cr("Invalid argument to inspectheap operation: %s", arg1);
   267       return JNI_ERR;
   284       return JNI_ERR;
   268     }
   285     }
   269     live_objects_only = strcmp(arg0, "-live") == 0;
   286     live_objects_only = strcmp(arg1, "-live") == 0;
   270   }
   287   }
   271   VM_GC_HeapInspection heapop(out, live_objects_only /* request full gc */);
   288   VM_GC_HeapInspection heapop(os, live_objects_only /* request full gc */);
   272   VMThread::execute(&heapop);
   289   VMThread::execute(&heapop);
       
   290   if (os != NULL && os != out) {
       
   291     out->print_cr("Heap inspection file created: %s", path);
       
   292     delete fs;
       
   293   }
   273   return JNI_OK;
   294   return JNI_OK;
   274 }
   295 }
   275 
   296 
   276 // Implementation of "setflag" command
   297 // Implementation of "setflag" command
   277 static jint set_flag(AttachOperation* op, outputStream* out) {
   298 static jint set_flag(AttachOperation* op, outputStream* out) {