< prev index next >

src/hotspot/share/services/diagnosticCommand.cpp

Print this page

 121 #ifdef LINUX
 122   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<PerfMapDCmd>(full_export, true, false));
 123   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<TrimCLibcHeapDCmd>(full_export, true, false));
 124 #endif // LINUX
 125   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<TouchedMethodsDCmd>(full_export, true, false));
 126   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<CodeHeapAnalyticsDCmd>(full_export, true, false));
 127 
 128   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<CompilerDirectivesPrintDCmd>(full_export, true, false));
 129   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<CompilerDirectivesAddDCmd>(full_export, true, false));
 130   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<CompilerDirectivesRemoveDCmd>(full_export, true, false));
 131   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<CompilerDirectivesClearDCmd>(full_export, true, false));
 132 
 133   // Enhanced JMX Agent Support
 134   // These commands won't be exported via the DiagnosticCommandMBean until an
 135   // appropriate permission is created for them
 136   uint32_t jmx_agent_export_flags = DCmd_Source_Internal | DCmd_Source_AttachAPI;
 137   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<JMXStartRemoteDCmd>(jmx_agent_export_flags, true,false));
 138   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<JMXStartLocalDCmd>(jmx_agent_export_flags, true,false));
 139   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<JMXStopRemoteDCmd>(jmx_agent_export_flags, true,false));
 140   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<JMXStatusDCmd>(jmx_agent_export_flags, true,false));


 141 
 142   // Debug on cmd (only makes sense with JVMTI since the agentlib needs it).
 143 #if INCLUDE_JVMTI
 144   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<DebugOnCmdStartDCmd>(full_export, true, true));
 145 #endif // INCLUDE_JVMTI
 146 
 147 #if INCLUDE_CDS
 148   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<DumpSharedArchiveDCmd>(full_export, true, false));
 149 #endif // INCLUDE_CDS
 150 }
 151 
 152 #ifndef HAVE_EXTRA_DCMD
 153 void DCmdRegistrant::register_dcmds_ext(){
 154    // Do nothing here
 155 }
 156 #endif
 157 
 158 
 159 HelpDCmd::HelpDCmd(outputStream* output, bool heap) : DCmdWithParser(output, heap),
 160   _all("-all", "Show help for all commands", "BOOLEAN", false, "false"),

 338 
 339 void PrintSystemPropertiesDCmd::execute(DCmdSource source, TRAPS) {
 340   // load VMSupport
 341   Symbol* klass = vmSymbols::jdk_internal_vm_VMSupport();
 342   Klass* k = SystemDictionary::resolve_or_fail(klass, true, CHECK);
 343   InstanceKlass* ik = InstanceKlass::cast(k);
 344   if (ik->should_be_initialized()) {
 345     ik->initialize(THREAD);
 346   }
 347   if (HAS_PENDING_EXCEPTION) {
 348     java_lang_Throwable::print(PENDING_EXCEPTION, output());
 349     output()->cr();
 350     CLEAR_PENDING_EXCEPTION;
 351     return;
 352   }
 353 
 354   // invoke the serializePropertiesToByteArray method
 355   JavaValue result(T_OBJECT);
 356   JavaCallArguments args;
 357 
 358   Symbol* signature = vmSymbols::serializePropertiesToByteArray_signature();
 359   JavaCalls::call_static(&result,
 360                          ik,
 361                          vmSymbols::serializePropertiesToByteArray_name(),
 362                          signature,
 363                          &args,
 364                          THREAD);
 365   if (HAS_PENDING_EXCEPTION) {
 366     java_lang_Throwable::print(PENDING_EXCEPTION, output());
 367     output()->cr();
 368     CLEAR_PENDING_EXCEPTION;
 369     return;
 370   }
 371 
 372   // The result should be a [B
 373   oop res = result.get_oop();
 374   assert(res->is_typeArray(), "just checking");
 375   assert(TypeArrayKlass::cast(res->klass())->element_type() == T_BYTE, "just checking");
 376 
 377   // copy the bytes to the output stream
 378   typeArrayOop ba = typeArrayOop(res);

1025       if ((strcmp("jdwp", agent->name()) == 0) && (dvc_start_ptr == NULL)) {
1026         char const* func = "debugInit_startDebuggingViaCommand";
1027         dvc_start_ptr = (debugInit_startDebuggingViaCommandPtr) os::find_agent_function(agent, false, &func, 1);
1028       }
1029     }
1030   }
1031 
1032   if (dvc_start_ptr) {
1033     error = dvc_start_ptr(thread->jni_environment(), jt, &transport, &addr, &is_first_start);
1034   }
1035 
1036   if (error != NULL) {
1037     output()->print_cr("Debugging has not been started: %s", error);
1038   } else {
1039     output()->print_cr(is_first_start ? "Debugging has been started." : "Debugging is already active.");
1040     output()->print_cr("Transport : %s", transport ? transport : "#unknown");
1041     output()->print_cr("Address : %s", addr ? addr : "#unknown");
1042   }
1043 }
1044 #endif // INCLUDE_JVMTI











































































 121 #ifdef LINUX
 122   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<PerfMapDCmd>(full_export, true, false));
 123   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<TrimCLibcHeapDCmd>(full_export, true, false));
 124 #endif // LINUX
 125   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<TouchedMethodsDCmd>(full_export, true, false));
 126   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<CodeHeapAnalyticsDCmd>(full_export, true, false));
 127 
 128   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<CompilerDirectivesPrintDCmd>(full_export, true, false));
 129   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<CompilerDirectivesAddDCmd>(full_export, true, false));
 130   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<CompilerDirectivesRemoveDCmd>(full_export, true, false));
 131   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<CompilerDirectivesClearDCmd>(full_export, true, false));
 132 
 133   // Enhanced JMX Agent Support
 134   // These commands won't be exported via the DiagnosticCommandMBean until an
 135   // appropriate permission is created for them
 136   uint32_t jmx_agent_export_flags = DCmd_Source_Internal | DCmd_Source_AttachAPI;
 137   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<JMXStartRemoteDCmd>(jmx_agent_export_flags, true,false));
 138   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<JMXStartLocalDCmd>(jmx_agent_export_flags, true,false));
 139   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<JMXStopRemoteDCmd>(jmx_agent_export_flags, true,false));
 140   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<JMXStatusDCmd>(jmx_agent_export_flags, true,false));
 141     
 142   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<JavaThreadDumpDCmd>(full_export, true, false));
 143 
 144   // Debug on cmd (only makes sense with JVMTI since the agentlib needs it).
 145 #if INCLUDE_JVMTI
 146   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<DebugOnCmdStartDCmd>(full_export, true, true));
 147 #endif // INCLUDE_JVMTI
 148 
 149 #if INCLUDE_CDS
 150   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<DumpSharedArchiveDCmd>(full_export, true, false));
 151 #endif // INCLUDE_CDS
 152 }
 153 
 154 #ifndef HAVE_EXTRA_DCMD
 155 void DCmdRegistrant::register_dcmds_ext(){
 156    // Do nothing here
 157 }
 158 #endif
 159 
 160 
 161 HelpDCmd::HelpDCmd(outputStream* output, bool heap) : DCmdWithParser(output, heap),
 162   _all("-all", "Show help for all commands", "BOOLEAN", false, "false"),

 340 
 341 void PrintSystemPropertiesDCmd::execute(DCmdSource source, TRAPS) {
 342   // load VMSupport
 343   Symbol* klass = vmSymbols::jdk_internal_vm_VMSupport();
 344   Klass* k = SystemDictionary::resolve_or_fail(klass, true, CHECK);
 345   InstanceKlass* ik = InstanceKlass::cast(k);
 346   if (ik->should_be_initialized()) {
 347     ik->initialize(THREAD);
 348   }
 349   if (HAS_PENDING_EXCEPTION) {
 350     java_lang_Throwable::print(PENDING_EXCEPTION, output());
 351     output()->cr();
 352     CLEAR_PENDING_EXCEPTION;
 353     return;
 354   }
 355 
 356   // invoke the serializePropertiesToByteArray method
 357   JavaValue result(T_OBJECT);
 358   JavaCallArguments args;
 359 
 360   Symbol* signature = vmSymbols::void_byte_array_signature();
 361   JavaCalls::call_static(&result,
 362                          ik,
 363                          vmSymbols::serializePropertiesToByteArray_name(),
 364                          signature,
 365                          &args,
 366                          THREAD);
 367   if (HAS_PENDING_EXCEPTION) {
 368     java_lang_Throwable::print(PENDING_EXCEPTION, output());
 369     output()->cr();
 370     CLEAR_PENDING_EXCEPTION;
 371     return;
 372   }
 373 
 374   // The result should be a [B
 375   oop res = result.get_oop();
 376   assert(res->is_typeArray(), "just checking");
 377   assert(TypeArrayKlass::cast(res->klass())->element_type() == T_BYTE, "just checking");
 378 
 379   // copy the bytes to the output stream
 380   typeArrayOop ba = typeArrayOop(res);

1027       if ((strcmp("jdwp", agent->name()) == 0) && (dvc_start_ptr == NULL)) {
1028         char const* func = "debugInit_startDebuggingViaCommand";
1029         dvc_start_ptr = (debugInit_startDebuggingViaCommandPtr) os::find_agent_function(agent, false, &func, 1);
1030       }
1031     }
1032   }
1033 
1034   if (dvc_start_ptr) {
1035     error = dvc_start_ptr(thread->jni_environment(), jt, &transport, &addr, &is_first_start);
1036   }
1037 
1038   if (error != NULL) {
1039     output()->print_cr("Debugging has not been started: %s", error);
1040   } else {
1041     output()->print_cr(is_first_start ? "Debugging has been started." : "Debugging is already active.");
1042     output()->print_cr("Transport : %s", transport ? transport : "#unknown");
1043     output()->print_cr("Address : %s", addr ? addr : "#unknown");
1044   }
1045 }
1046 #endif // INCLUDE_JVMTI
1047 
1048 JavaThreadDumpDCmd::JavaThreadDumpDCmd(outputStream* output, bool heap) :
1049                                        DCmdWithParser(output, heap),
1050   _overwrite("-overwrite", "May overwrite existing file", "BOOLEAN", false, "false"),
1051   _format("-format", "Output format (\"plain\" or \"json\")", "STRING", false, "plain"),
1052   _filepath("filepath", "The file path to the output file", "STRING", true) {
1053   _dcmdparser.add_dcmd_option(&_overwrite);
1054   _dcmdparser.add_dcmd_option(&_format);
1055   _dcmdparser.add_dcmd_argument(&_filepath);
1056 }
1057 
1058 int JavaThreadDumpDCmd::num_arguments() {
1059   ResourceMark rm;
1060   JavaThreadDumpDCmd* dcmd = new JavaThreadDumpDCmd(NULL, false);
1061   if (dcmd != NULL) {
1062     DCmdMark mark(dcmd);
1063     return dcmd->_dcmdparser.num_arguments();
1064   } else {
1065     return 0;
1066   }
1067 }
1068 
1069 void JavaThreadDumpDCmd::execute(DCmdSource source, TRAPS) {
1070   bool json = (_format.value() != NULL) && (strcmp(_format.value(), "json") == 0);
1071   char* path = _filepath.value();
1072   bool overwrite = _overwrite.value();
1073   Symbol* name = (json) ? vmSymbols::dumpThreadsToJson_name() : vmSymbols::dumpThreads_name();
1074   dumpToFile(name, vmSymbols::string_bool_byte_array_signature(), path, overwrite, CHECK);
1075 }
1076 
1077 void JavaThreadDumpDCmd::dumpToFile(Symbol* name, Symbol* signature, const char* path, bool overwrite, TRAPS) {
1078   ResourceMark rm(THREAD);
1079   HandleMark hm(THREAD);
1080 
1081   Handle h_path = java_lang_String::create_from_str(path, CHECK);
1082 
1083   Symbol* sym = vmSymbols::jdk_internal_vm_ThreadDumper();
1084   Klass* k = SystemDictionary::resolve_or_fail(sym, true, CHECK);
1085   InstanceKlass* ik = InstanceKlass::cast(k);
1086   if (HAS_PENDING_EXCEPTION) {
1087     java_lang_Throwable::print(PENDING_EXCEPTION, output());
1088     output()->cr();
1089     CLEAR_PENDING_EXCEPTION;
1090     return;
1091   }
1092 
1093   // invoke the ThreadDump method to dump to file
1094   JavaValue result(T_OBJECT);
1095   JavaCallArguments args;
1096   args.push_oop(h_path);
1097   args.push_int(overwrite ? JNI_TRUE : JNI_FALSE);
1098   JavaCalls::call_static(&result,
1099                          k,
1100                          name,
1101                          signature,
1102                          &args,
1103                          THREAD);
1104   if (HAS_PENDING_EXCEPTION) {
1105     java_lang_Throwable::print(PENDING_EXCEPTION, output());
1106     output()->cr();
1107     CLEAR_PENDING_EXCEPTION;
1108     return;
1109   }
1110 
1111   // check that result is byte array
1112   oop res = cast_to_oop(result.get_jobject());
1113   assert(res->is_typeArray(), "just checking");
1114   assert(TypeArrayKlass::cast(res->klass())->element_type() == T_BYTE, "just checking");
1115 
1116   // copy the bytes to the output stream
1117   typeArrayOop ba = typeArrayOop(res);
1118   jbyte* addr = typeArrayOop(res)->byte_at_addr(0);
1119   output()->print_raw((const char*)addr, ba->length());
1120 }
< prev index next >