< prev index next >

src/hotspot/share/services/diagnosticCommand.cpp

Print this page
*** 136,10 ***
--- 136,12 ---
    uint32_t jmx_agent_export_flags = DCmd_Source_Internal | DCmd_Source_AttachAPI;
    DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<JMXStartRemoteDCmd>(jmx_agent_export_flags, true,false));
    DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<JMXStartLocalDCmd>(jmx_agent_export_flags, true,false));
    DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<JMXStopRemoteDCmd>(jmx_agent_export_flags, true,false));
    DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<JMXStatusDCmd>(jmx_agent_export_flags, true,false));
+     
+   DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<JavaThreadDumpDCmd>(full_export, true, false));
  
    // Debug on cmd (only makes sense with JVMTI since the agentlib needs it).
  #if INCLUDE_JVMTI
    DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl<DebugOnCmdStartDCmd>(full_export, true, true));
  #endif // INCLUDE_JVMTI

*** 353,11 ***
  
    // invoke the serializePropertiesToByteArray method
    JavaValue result(T_OBJECT);
    JavaCallArguments args;
  
!   Symbol* signature = vmSymbols::serializePropertiesToByteArray_signature();
    JavaCalls::call_static(&result,
                           ik,
                           vmSymbols::serializePropertiesToByteArray_name(),
                           signature,
                           &args,
--- 355,11 ---
  
    // invoke the serializePropertiesToByteArray method
    JavaValue result(T_OBJECT);
    JavaCallArguments args;
  
!   Symbol* signature = vmSymbols::void_byte_array_signature();
    JavaCalls::call_static(&result,
                           ik,
                           vmSymbols::serializePropertiesToByteArray_name(),
                           signature,
                           &args,

*** 1040,5 ***
--- 1042,79 ---
      output()->print_cr("Transport : %s", transport ? transport : "#unknown");
      output()->print_cr("Address : %s", addr ? addr : "#unknown");
    }
  }
  #endif // INCLUDE_JVMTI
+ 
+ JavaThreadDumpDCmd::JavaThreadDumpDCmd(outputStream* output, bool heap) :
+                                        DCmdWithParser(output, heap),
+   _overwrite("-overwrite", "May overwrite existing file", "BOOLEAN", false, "false"),
+   _format("-format", "Output format (\"plain\" or \"json\")", "STRING", false, "plain"),
+   _filepath("filepath", "The file path to the output file", "STRING", true) {
+   _dcmdparser.add_dcmd_option(&_overwrite);
+   _dcmdparser.add_dcmd_option(&_format);
+   _dcmdparser.add_dcmd_argument(&_filepath);
+ }
+ 
+ int JavaThreadDumpDCmd::num_arguments() {
+   ResourceMark rm;
+   JavaThreadDumpDCmd* dcmd = new JavaThreadDumpDCmd(NULL, false);
+   if (dcmd != NULL) {
+     DCmdMark mark(dcmd);
+     return dcmd->_dcmdparser.num_arguments();
+   } else {
+     return 0;
+   }
+ }
+ 
+ void JavaThreadDumpDCmd::execute(DCmdSource source, TRAPS) {
+   bool json = (_format.value() != NULL) && (strcmp(_format.value(), "json") == 0);
+   char* path = _filepath.value();
+   bool overwrite = _overwrite.value();
+   Symbol* name = (json) ? vmSymbols::dumpThreadsToJson_name() : vmSymbols::dumpThreads_name();
+   dumpToFile(name, vmSymbols::string_bool_byte_array_signature(), path, overwrite, CHECK);
+ }
+ 
+ void JavaThreadDumpDCmd::dumpToFile(Symbol* name, Symbol* signature, const char* path, bool overwrite, TRAPS) {
+   ResourceMark rm(THREAD);
+   HandleMark hm(THREAD);
+ 
+   Handle h_path = java_lang_String::create_from_str(path, CHECK);
+ 
+   Symbol* sym = vmSymbols::jdk_internal_vm_ThreadDumper();
+   Klass* k = SystemDictionary::resolve_or_fail(sym, true, CHECK);
+   InstanceKlass* ik = InstanceKlass::cast(k);
+   if (HAS_PENDING_EXCEPTION) {
+     java_lang_Throwable::print(PENDING_EXCEPTION, output());
+     output()->cr();
+     CLEAR_PENDING_EXCEPTION;
+     return;
+   }
+ 
+   // invoke the ThreadDump method to dump to file
+   JavaValue result(T_OBJECT);
+   JavaCallArguments args;
+   args.push_oop(h_path);
+   args.push_int(overwrite ? JNI_TRUE : JNI_FALSE);
+   JavaCalls::call_static(&result,
+                          k,
+                          name,
+                          signature,
+                          &args,
+                          THREAD);
+   if (HAS_PENDING_EXCEPTION) {
+     java_lang_Throwable::print(PENDING_EXCEPTION, output());
+     output()->cr();
+     CLEAR_PENDING_EXCEPTION;
+     return;
+   }
+ 
+   // check that result is byte array
+   oop res = cast_to_oop(result.get_jobject());
+   assert(res->is_typeArray(), "just checking");
+   assert(TypeArrayKlass::cast(res->klass())->element_type() == T_BYTE, "just checking");
+ 
+   // copy the bytes to the output stream
+   typeArrayOop ba = typeArrayOop(res);
+   jbyte* addr = typeArrayOop(res)->byte_at_addr(0);
+   output()->print_raw((const char*)addr, ba->length());
+ }
< prev index next >