From b72eda7859994dbf86a6a5bbab64d9a048fb7ab5 Mon Sep 17 00:00:00 2001 From: Michael Starzinger Date: Wed, 23 Sep 2009 21:13:15 +0200 Subject: [PATCH] * src/vm/vm.hpp (VM::start_runtime_agents): Added new helper method. * 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 | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++ src/vm/vm.hpp | 4 ++++ 2 files changed, 62 insertions(+) diff --git a/src/vm/vm.cpp b/src/vm/vm.cpp index 7aff240f0..fb56384e0 100644 --- a/src/vm/vm.cpp +++ b/src/vm/vm.cpp @@ -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. diff --git a/src/vm/vm.hpp b/src/vm/vm.hpp index e57c1b958..8ddb1464a 100644 --- a/src/vm/vm.hpp +++ b/src/vm/vm.hpp @@ -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 -- 2.25.1