* src/vm/vm.hpp (VM::start_runtime_agents): Added new helper method.
authorMichael Starzinger <michi@complang.tuwien.ac.at>
Wed, 23 Sep 2009 19:13:15 +0000 (21:13 +0200)
committerMichael Starzinger <michi@complang.tuwien.ac.at>
Wed, 23 Sep 2009 19:13:15 +0000 (21:13 +0200)
* src/vm/vm.hpp (VM::VM): Start runtime agents after the VM is created.
(VM::start_runtime_agents): Implemented for different JRE configurations.

src/vm/vm.cpp
src/vm/vm.hpp

index 7aff240f09e7f86f220e1acd67f94741a119a4f5..fb56384e03ab5daeeeeb9ef912bf7a2aa75a0d7e 100644 (file)
@@ -1449,6 +1449,10 @@ VM::VM(JavaVMInitArgs* vm_args)
        // the VM is initialized.
        if (opt_PrintConfig)
                print_run_time_config();
+
+       // Start runtime agents after the VM is created.
+       if (!start_runtime_agents())
+               os::abort("vm_create: start_runtime_agents failed");
 }
 
 
@@ -1517,6 +1521,60 @@ void VM::print_run_time_config()
 }
 
 
+/**
+ * Start runtime agents which are provided by the JRE but need to be
+ * started explicitly by the VM.
+ */
+bool VM::start_runtime_agents()
+{
+#if defined(WITH_JAVA_RUNTIME_LIBRARY_GNU_CLASSPATH)
+
+       // Nothing to do.
+
+#elif defined(WITH_JAVA_RUNTIME_LIBRARY_OPENJDK)
+
+       // Check whether the management agent should be loaded.
+       if ((_properties.get("com.sun.management.jmxremote") != NULL) ||
+               (_properties.get("com.sun.management.snmp") != NULL))
+       {
+
+               // Load the management agent class.
+               classinfo* class_sun_management_Agent;
+               if (!(class_sun_management_Agent = load_class_from_sysloader(utf_new_char("sun/management/Agent"))))
+                       return false;
+
+               // Link the management agent class.
+               if (!link_class(class_sun_management_Agent))
+                       return false;
+
+               // Actually start the management agent.
+               methodinfo* m = class_resolveclassmethod(class_sun_management_Agent,
+                                                                                                utf_new_char("startAgent"),
+                                                                                                utf_void__void,
+                                                                                                class_java_lang_Object,
+                                                                                                false);
+
+               if (m == NULL)
+                       return false;
+
+               (void) vm_call_method(m, NULL);
+
+               if (exceptions_get_exception() != NULL)
+                       return false;
+       }
+
+#elif defined(WITH_JAVA_RUNTIME_LIBRARY_CLDC1_1)
+
+       // Nothing to do.
+
+#else
+# error unknown classpath configuration
+#endif
+
+       return true;
+}
+
+
 /* vm_run **********************************************************************
 
    Runs the main-method of the passed class.
index e57c1b958054cb535c55b124c168451ddc70f5ef..8ddb1464a0d11b32139de7e3863e8513f1fcc77b 100644 (file)
@@ -111,6 +111,10 @@ public:
        NativeLibraries& get_nativelibraries() { return _nativelibraries; }
        NativeMethods&   get_nativemethods  () { return _nativemethods; }
        SuckClasspath&   get_suckclasspath  () { return _suckclasspath; }
+
+private:
+       // Internal helper methods.
+       bool start_runtime_agents();
 };
 
 #else