Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8151991

jvmti diagnostics commands requires INCLUDE_SERVICES

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 9
    • 9.1
    • hotspot
    • None
    • svc
    • b115

        JDK-8147388 introduced some new diagnostic commands for jvmti that rely on runtime agent loading. In the mobile/dev repos a minimal vm is supported which does include jvmti, but does not support INCLUDE_SERVICES for runtime agent loading.

        The workaround in mobile/dev repos adds INCLUDE_SERVICE conditional compilation checks.


        hotspot/src/share/vm/prims/jvmtiExport.hpp:
        ...

        #if INCLUDE_SERVICES
          // attach support
          static jint load_agent_library(const char *agent, const char *absParam, const char *options, outputStream* out) NOT_JVMTI_RETURN_(JNI_ERR);
          static jint load_agent_library(AttachOperation* op, outputStream* out) NOT_JVMTI_RETURN_(JNI_ERR);
        #endif // INCLUDE_SERVICES


        hotspot/src/share/vm/services/diagnosticCommand.cpp: proposed

        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 INCLUDE_SERVICES
          if (is_java_agent) {
            if (_option.value() == NULL) {
              JvmtiExport::load_agent_library("instrument", "false",
                                              _libpath.value(), output());
            } else {
              size_t opt_len = strlen(_libpath.value()) + strlen(_option.value()) + 2;
              if (opt_len > 4096) {
                output()->print_cr("JVMTI agent attach failed: Options is too long.");
                return;
              }

              char *opt = (char *)os::malloc(opt_len, mtInternal);
              if (opt == NULL) {
                output()->print_cr("JVMTI agent attach failed: "
                                   "Could not allocate %zu bytes for argument.",
                                   opt_len);
                return;
              }

              jio_snprintf(opt, opt_len, "%s=%s", _libpath.value(), _option.value());
              JvmtiExport::load_agent_library("instrument", "false", opt, output());

              os::free(opt);
            }
          } else {
            JvmtiExport::load_agent_library(_libpath.value(), "true",
                                            _option.value(), output());
          }
        #endif
        }

              dsamersoff Dmitriy Samersoff
              gadams Gary Adams (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Created:
                Updated:
                Resolved: