--- old/src/share/vm/services/diagnosticCommand.cpp 2016-01-18 23:43:47.166132851 +0900 +++ new/src/share/vm/services/diagnosticCommand.cpp 2016-01-18 23:43:47.009133609 +0900 @@ -71,6 +71,7 @@ #endif // INCLUDE_SERVICES #if INCLUDE_JVMTI DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl(full_export, true, false)); + DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl(full_export, true, false)); #endif // INCLUDE_JVMTI DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl(full_export, true, false)); DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl(full_export, true, false)); @@ -254,6 +255,52 @@ } } +JVMTIAgentLoadDCmd::JVMTIAgentLoadDCmd(outputStream* output, bool heap) : + DCmdWithParser(output, heap), + _libpath("library path", "Absolute path of the JVMTI agent to load.", + "STRING", true), + _option("agent option", "Option string to pass the agent.", "STRING", false) { + _dcmdparser.add_dcmd_argument(&_libpath); + _dcmdparser.add_dcmd_argument(&_option); +} + +void JVMTIAgentLoadDCmd::execute(DCmdSource source, TRAPS) { + + if (_libpath.value() == NULL) { + output()->print_cr("JVMTI.agent_load dcmd needs library path."); + return; + } + + char *suffix = strrchr(_libpath.value(), '.'); + bool is_java_agent = (suffix != NULL) && (strncmp(".jar", suffix, 4) == 0); + + if (is_java_agent) { + if (_option.value() == NULL) { + JvmtiExport::load_agent_library("instrument", "false", + _libpath.value(), output()); + } else { + int opt_len = strlen(_libpath.value()) + strlen(_option.value()) + 2; + char opt[opt_len]; + snprintf(opt, opt_len, "%s=%s", _libpath.value(), _option.value()); + JvmtiExport::load_agent_library("instrument", "false", opt, output()); + } + } else { + JvmtiExport::load_agent_library(_libpath.value(), "true", + _option.value(), output()); + } +} + +int JVMTIAgentLoadDCmd::num_arguments() { + ResourceMark rm; + JVMTIAgentLoadDCmd* dcmd = new JVMTIAgentLoadDCmd(NULL, false); + if (dcmd != NULL) { + DCmdMark mark(dcmd); + return dcmd->_dcmdparser.num_arguments(); + } else { + return 0; + } +} + void PrintSystemPropertiesDCmd::execute(DCmdSource source, TRAPS) { // load sun.misc.VMSupport Symbol* klass = vmSymbols::sun_misc_VMSupport();