--- old/src/share/vm/services/diagnosticCommand.cpp 2016-01-14 22:56:20.888996737 +0900 +++ new/src/share/vm/services/diagnosticCommand.cpp 2016-01-14 22:56:20.723997281 +0900 @@ -71,6 +71,8 @@ #endif // INCLUDE_SERVICES #if INCLUDE_JVMTI DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl(full_export, true, false)); + 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 +256,69 @@ } } +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) { + 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; + } +} + +JVMTIJavaAgentLoadDCmd::JVMTIJavaAgentLoadDCmd( + 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 JVMTIJavaAgentLoadDCmd::execute(DCmdSource source, TRAPS) { + size_t option_len = strlen(_libpath.value()); + char *options; + + if (_option.value() == NULL) { + options = os::strdup(_libpath.value()); + } else { + option_len += strlen(_option.value()) + 1; + options = (char *)os::malloc(option_len + 1, mtInternal); + sprintf(options, "%s=%s", _libpath.value(), _option.value()); + } + + JvmtiExport::load_agent_library("instrument", "false", options, output()); + + os::free(options); +} + +int JVMTIJavaAgentLoadDCmd::num_arguments() { + ResourceMark rm; + JVMTIJavaAgentLoadDCmd* dcmd = new JVMTIJavaAgentLoadDCmd(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();