Index: vm/vmcore/include/environment.h =================================================================== --- vm/vmcore/include/environment.h (revision 509148) +++ vm/vmcore/include/environment.h (working copy) @@ -20,6 +20,7 @@ #include #include +#include #include "open/hythread.h" #include "open/compmgr.h" @@ -235,6 +236,11 @@ * Offset to the vm_class field in java.lang.Class. */ unsigned vm_class_offset; + + /** + * VM initialization timestamp + */ + apr_time_t start_time; /** * The VM state. See VM_STATE enum above. Index: vm/vmcore/src/jni/jni.cpp =================================================================== --- vm/vmcore/src/jni/jni.cpp (revision 509148) +++ vm/vmcore/src/jni/jni.cpp (working copy) @@ -25,6 +25,7 @@ #include #include #include +#include #include "open/types.h" #include "open/hythread.h" @@ -483,6 +484,8 @@ goto done; } + vm_env->start_time = apr_time_now()/1000; + java_vm->functions = &java_vm_vtable; java_vm->pool = vm_global_pool; java_vm->vm_env = vm_env; @@ -508,7 +511,7 @@ *p_jni_env = jni_env; // Now JVMTIThread keeps global reference. Discared temporary global reference. - jni_env->DeleteGlobalRef(java_thread); + jni_env->DeleteGlobalRef(java_thread); // Send VM start event. JNI services are available now. // JVMTI services permited in the start phase are available as well. Index: vm/vmcore/src/kernel_classes/native/org_apache_harmony_lang_management_RuntimeMXBeanImpl.cpp =================================================================== --- vm/vmcore/src/kernel_classes/native/org_apache_harmony_lang_management_RuntimeMXBeanImpl.cpp (revision 509148) +++ vm/vmcore/src/kernel_classes/native/org_apache_harmony_lang_management_RuntimeMXBeanImpl.cpp (working copy) @@ -28,19 +28,34 @@ */ #include +#include #include -#include "java_lang_System.h" +#include "environment.h" #include "org_apache_harmony_lang_management_RuntimeMXBeanImpl.h" + +/** + * The number of digits in decimal print for max unsigned long + */ +#define MAX_LONG_LENGTH_AS_DECIMAL 20 + /* * Method: org.apache.harmony.lang.management.RuntimeMXBeanImpl.getNameImpl()Ljava/lang/String; */ JNIEXPORT jstring JNICALL Java_org_apache_harmony_lang_management_RuntimeMXBeanImpl_getNameImpl(JNIEnv *env, jobject) { - // TODO implement this method stub correctly - TRACE2("management","RuntimeMXBeanImpl_getNameImpl stub invocation"); - char *buf = "DRLVM"; - return env->NewStringUTF(buf); + TRACE2("management", "RuntimeMXBeanImpl_getNameImpl called"); + JavaVM * vm = NULL; + env->GetJavaVM(&vm); + + char host_name[APRMAXHOSTLEN + 1] = {0}; + apr_pool_t *pool; + apr_pool_create(&pool, 0); + apr_gethostname(host_name, APRMAXHOSTLEN + 1, pool); + char result[MAX_LONG_LENGTH_AS_DECIMAL + 1 + APRMAXHOSTLEN + 1] = {0}; + sprintf(result, "%d@%s", getpid(), host_name); + apr_pool_destroy(pool); + return env->NewStringUTF(result); }; /* @@ -49,20 +64,21 @@ JNIEXPORT jlong JNICALL Java_org_apache_harmony_lang_management_RuntimeMXBeanImpl_getStartTimeImpl(JNIEnv *env, jobject ) { - // TODO implement this method stub correctly - TRACE2("management","RuntimeMXBeanImpl_getStartTimeImpl stub invocation"); - return apr_time_now()/1000; + TRACE2("management","RuntimeMXBeanImpl_getStartTimeImpl called"); + JavaVM * vm = NULL; + env->GetJavaVM(&vm); + return ((JavaVM_Internal*)vm)->vm_env->start_time; }; /* * Method: org.apache.harmony.lang.management.RuntimeMXBeanImpl.getUptimeImpl()J */ JNIEXPORT jlong JNICALL -Java_org_apache_harmony_lang_management_RuntimeMXBeanImpl_getUptimeImpl(JNIEnv *, jobject) +Java_org_apache_harmony_lang_management_RuntimeMXBeanImpl_getUptimeImpl(JNIEnv *env, jobject obj) { - // TODO implement this method stub correctly - TRACE2("management","RuntimeMXBeanImpl_getUptimeImpl stub invocation"); - return 1L<<10; + TRACE2("management","RuntimeMXBeanImpl_getUptimeImpl called"); + return apr_time_now()/1000 - + Java_org_apache_harmony_lang_management_RuntimeMXBeanImpl_getStartTimeImpl(env, obj); }; /* @@ -71,8 +87,7 @@ JNIEXPORT jboolean JNICALL Java_org_apache_harmony_lang_management_RuntimeMXBeanImpl_isBootClassPathSupportedImpl(JNIEnv *, jobject) { - // TODO implement this method stub correctly - TRACE2("management","isBootClassPathSupportedImpl stub invocation"); + TRACE2("management","RuntimeMXBeanImpl_isBootClassPathSupportedImpl called"); return JNI_TRUE; };