< prev index next >

src/share/vm/services/diagnosticCommand.cpp

Print this page




 260 
 261 #if INCLUDE_SERVICES
 262 JVMTIAgentLoadDCmd::JVMTIAgentLoadDCmd(outputStream* output, bool heap) :
 263                                        DCmdWithParser(output, heap),
 264   _libpath("library path", "Absolute path of the JVMTI agent to load.",
 265            "STRING", true),
 266   _option("agent option", "Option string to pass the agent.", "STRING", false) {
 267   _dcmdparser.add_dcmd_argument(&_libpath);
 268   _dcmdparser.add_dcmd_argument(&_option);
 269 }
 270 
 271 void JVMTIAgentLoadDCmd::execute(DCmdSource source, TRAPS) {
 272 
 273   if (_libpath.value() == NULL) {
 274     output()->print_cr("JVMTI.agent_load dcmd needs library path.");
 275     return;
 276   }
 277 
 278   char *suffix = strrchr(_libpath.value(), '.');
 279   bool is_java_agent = (suffix != NULL) && (strncmp(".jar", suffix, 4) == 0);

 280 
 281   if (is_java_agent) {
 282     if (_option.value() == NULL) {
 283       JvmtiExport::load_agent_library("instrument", "false",
 284                                       _libpath.value(), output());
 285     } else {
 286       size_t opt_len = strlen(_libpath.value()) + strlen(_option.value()) + 2;
 287       if (opt_len > 4096) {
 288         output()->print_cr("JVMTI agent attach failed: Options is too long.");
 289         return;
 290       }
 291 
 292       char *opt = (char *)os::malloc(opt_len, mtInternal);
 293       if (opt == NULL) {
 294         output()->print_cr("JVMTI agent attach failed: "
 295                            "Could not allocate %zu bytes for argument.",
 296                            opt_len);
 297         return;
 298       }
 299 
 300       jio_snprintf(opt, opt_len, "%s=%s", _libpath.value(), _option.value());
 301       JvmtiExport::load_agent_library("instrument", "false", opt, output());

 302 
 303       os::free(opt);
 304     }
 305   } else {
 306     JvmtiExport::load_agent_library(_libpath.value(), "true",
 307                                     _option.value(), output());
 308   }



 309 }
 310 
 311 int JVMTIAgentLoadDCmd::num_arguments() {
 312   ResourceMark rm;
 313   JVMTIAgentLoadDCmd* dcmd = new JVMTIAgentLoadDCmd(NULL, false);
 314   if (dcmd != NULL) {
 315     DCmdMark mark(dcmd);
 316     return dcmd->_dcmdparser.num_arguments();
 317   } else {
 318     return 0;
 319   }
 320 }
 321 #endif // INCLUDE_SERVICES
 322 
 323 void PrintSystemPropertiesDCmd::execute(DCmdSource source, TRAPS) {
 324   // load VMSupport
 325   Symbol* klass = vmSymbols::jdk_internal_vm_VMSupport();
 326   Klass* k = SystemDictionary::resolve_or_fail(klass, true, CHECK);
 327   instanceKlassHandle ik (THREAD, k);
 328   if (ik->should_be_initialized()) {




 260 
 261 #if INCLUDE_SERVICES
 262 JVMTIAgentLoadDCmd::JVMTIAgentLoadDCmd(outputStream* output, bool heap) :
 263                                        DCmdWithParser(output, heap),
 264   _libpath("library path", "Absolute path of the JVMTI agent to load.",
 265            "STRING", true),
 266   _option("agent option", "Option string to pass the agent.", "STRING", false) {
 267   _dcmdparser.add_dcmd_argument(&_libpath);
 268   _dcmdparser.add_dcmd_argument(&_option);
 269 }
 270 
 271 void JVMTIAgentLoadDCmd::execute(DCmdSource source, TRAPS) {
 272 
 273   if (_libpath.value() == NULL) {
 274     output()->print_cr("JVMTI.agent_load dcmd needs library path.");
 275     return;
 276   }
 277 
 278   char *suffix = strrchr(_libpath.value(), '.');
 279   bool is_java_agent = (suffix != NULL) && (strncmp(".jar", suffix, 4) == 0);
 280   jint result = JNI_ERR;
 281 
 282   if (is_java_agent) {
 283     if (_option.value() == NULL) {
 284       result = JvmtiExport::load_agent_library("instrument", "false",
 285                                                 _libpath.value(), output());
 286     } else {
 287       size_t opt_len = strlen(_libpath.value()) + strlen(_option.value()) + 2;
 288       if (opt_len > 4096) {
 289         output()->print_cr("JVMTI agent attach failed: Options is too long.");
 290         return;
 291       }
 292 
 293       char *opt = (char *)os::malloc(opt_len, mtInternal);
 294       if (opt == NULL) {
 295         output()->print_cr("JVMTI agent attach failed: "
 296                            "Could not allocate %zu bytes for argument.",
 297                            opt_len);
 298         return;
 299       }
 300 
 301       jio_snprintf(opt, opt_len, "%s=%s", _libpath.value(), _option.value());
 302       result = JvmtiExport::load_agent_library("instrument", "false",
 303                                                 opt, output());
 304 
 305       os::free(opt);
 306     }
 307   } else {
 308     result = JvmtiExport::load_agent_library(_libpath.value(), "true",
 309                                              _option.value(), output());
 310   }
 311 
 312   output()->print_cr("JVMTI agent attach %s.",
 313                                   (result == JNI_OK) ? "succeeded" : "failed");
 314 }
 315 
 316 int JVMTIAgentLoadDCmd::num_arguments() {
 317   ResourceMark rm;
 318   JVMTIAgentLoadDCmd* dcmd = new JVMTIAgentLoadDCmd(NULL, false);
 319   if (dcmd != NULL) {
 320     DCmdMark mark(dcmd);
 321     return dcmd->_dcmdparser.num_arguments();
 322   } else {
 323     return 0;
 324   }
 325 }
 326 #endif // INCLUDE_SERVICES
 327 
 328 void PrintSystemPropertiesDCmd::execute(DCmdSource source, TRAPS) {
 329   // load VMSupport
 330   Symbol* klass = vmSymbols::jdk_internal_vm_VMSupport();
 331   Klass* k = SystemDictionary::resolve_or_fail(klass, true, CHECK);
 332   instanceKlassHandle ik (THREAD, k);
 333   if (ik->should_be_initialized()) {


< prev index next >