src/share/vm/services/attachListener.cpp

Print this page
rev 4773 : 8005849: JEP 167: Event-Based JVM Tracing
Reviewed-by: acorn, coleenp, sla
Contributed-by: Karen Kinnear <karen.kinnear@oracle.com>, Bengt Rutisson <bengt.rutisson@oracle.com>, Calvin Cheung <calvin.cheung@oracle.com>, Erik Gahlin <erik.gahlin@oracle.com>, Erik Helin <erik.helin@oracle.com>, Jesper Wilhelmsson <jesper.wilhelmsson@oracle.com>, Keith McGuigan <keith.mcguigan@oracle.com>, Mattias Tobiasson <mattias.tobiasson@oracle.com>, Markus Gronlund <markus.gronlund@oracle.com>, Mikael Auno <mikael.auno@oracle.com>, Nils Eliasson <nils.eliasson@oracle.com>, Nils Loodin <nils.loodin@oracle.com>, Rickard Backman <rickard.backman@oracle.com>, Staffan Larsen <staffan.larsen@oracle.com>, Stefan Karlsson <stefan.karlsson@oracle.com>, Yekaterina Kantserova <yekaterina.kantserova@oracle.com>


 210     }
 211   }
 212   return JNI_OK;
 213 }
 214 
 215 // Implementation of "inspectheap" command
 216 // See also: ClassHistogramDCmd class
 217 //
 218 // Input arguments :-
 219 //   arg0: "-live" or "-all"
 220 static jint heap_inspection(AttachOperation* op, outputStream* out) {
 221   bool live_objects_only = true;   // default is true to retain the behavior before this change is made
 222   const char* arg0 = op->arg(0);
 223   if (arg0 != NULL && (strlen(arg0) > 0)) {
 224     if (strcmp(arg0, "-all") != 0 && strcmp(arg0, "-live") != 0) {
 225       out->print_cr("Invalid argument to inspectheap operation: %s", arg0);
 226       return JNI_ERR;
 227     }
 228     live_objects_only = strcmp(arg0, "-live") == 0;
 229   }
 230   VM_GC_HeapInspection heapop(out, live_objects_only /* request full gc */, true /* need_prologue */);
 231   VMThread::execute(&heapop);
 232   return JNI_OK;
 233 }
 234 
 235 // set a boolean global flag using value from AttachOperation
 236 static jint set_bool_flag(const char* name, AttachOperation* op, outputStream* out) {
 237   bool value = true;
 238   const char* arg1;
 239   if ((arg1 = op->arg(1)) != NULL) {
 240     int tmp;
 241     int n = sscanf(arg1, "%d", &tmp);
 242     if (n != 1) {
 243       out->print_cr("flag value must be a boolean (1 or 0)");
 244       return JNI_ERR;
 245     }
 246     value = (tmp != 0);
 247   }
 248   bool res = CommandLineFlags::boolAtPut((char*)name, &value, ATTACH_ON_DEMAND);
 249   if (! res) {
 250     out->print_cr("setting flag %s failed", name);




 210     }
 211   }
 212   return JNI_OK;
 213 }
 214 
 215 // Implementation of "inspectheap" command
 216 // See also: ClassHistogramDCmd class
 217 //
 218 // Input arguments :-
 219 //   arg0: "-live" or "-all"
 220 static jint heap_inspection(AttachOperation* op, outputStream* out) {
 221   bool live_objects_only = true;   // default is true to retain the behavior before this change is made
 222   const char* arg0 = op->arg(0);
 223   if (arg0 != NULL && (strlen(arg0) > 0)) {
 224     if (strcmp(arg0, "-all") != 0 && strcmp(arg0, "-live") != 0) {
 225       out->print_cr("Invalid argument to inspectheap operation: %s", arg0);
 226       return JNI_ERR;
 227     }
 228     live_objects_only = strcmp(arg0, "-live") == 0;
 229   }
 230   VM_GC_HeapInspection heapop(out, live_objects_only /* request full gc */);
 231   VMThread::execute(&heapop);
 232   return JNI_OK;
 233 }
 234 
 235 // set a boolean global flag using value from AttachOperation
 236 static jint set_bool_flag(const char* name, AttachOperation* op, outputStream* out) {
 237   bool value = true;
 238   const char* arg1;
 239   if ((arg1 = op->arg(1)) != NULL) {
 240     int tmp;
 241     int n = sscanf(arg1, "%d", &tmp);
 242     if (n != 1) {
 243       out->print_cr("flag value must be a boolean (1 or 0)");
 244       return JNI_ERR;
 245     }
 246     value = (tmp != 0);
 247   }
 248   bool res = CommandLineFlags::boolAtPut((char*)name, &value, ATTACH_ON_DEMAND);
 249   if (! res) {
 250     out->print_cr("setting flag %s failed", name);