harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gshiman...@apache.org
Subject svn commit: r559582 - in /harmony/enhanced/drlvm/trunk: src/test/regression/H4512/ src/test/regression/excludes/ vm/vmcore/src/thread/
Date Wed, 25 Jul 2007 20:33:26 GMT
Author: gshimansky
Date: Wed Jul 25 13:33:25 2007
New Revision: 559582

URL: http://svn.apache.org/viewvc?view=rev&rev=559582
Log:
Applied patches from HARMONY-4512
[drlvm][jvmti][thread] VM crashes in GetCurrentThreadCpuTime(() Ti function.
Test is excluded for x86_64 architectures because JVMTI is not implemeted
for them in JIT mode yet


Added:
    harmony/enhanced/drlvm/trunk/src/test/regression/H4512/
    harmony/enhanced/drlvm/trunk/src/test/regression/H4512/GetCurrentThreadCpuTime.cpp   (with
props)
    harmony/enhanced/drlvm/trunk/src/test/regression/H4512/GetCurrentThreadCpuTime.java  
(with props)
    harmony/enhanced/drlvm/trunk/src/test/regression/H4512/run.test.xml   (with props)
Modified:
    harmony/enhanced/drlvm/trunk/src/test/regression/excludes/exclude.linux.x86_64
    harmony/enhanced/drlvm/trunk/src/test/regression/excludes/exclude.windows.x86_64
    harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/thread_ti_timing.cpp

Added: harmony/enhanced/drlvm/trunk/src/test/regression/H4512/GetCurrentThreadCpuTime.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/src/test/regression/H4512/GetCurrentThreadCpuTime.cpp?view=auto&rev=559582
==============================================================================
--- harmony/enhanced/drlvm/trunk/src/test/regression/H4512/GetCurrentThreadCpuTime.cpp (added)
+++ harmony/enhanced/drlvm/trunk/src/test/regression/H4512/GetCurrentThreadCpuTime.cpp Wed
Jul 25 13:33:25 2007
@@ -0,0 +1,156 @@
+#include <iostream>
+#include <jvmti.h>
+
+using namespace std;
+
+#define PACKAGE "org/apache/harmony/drlvm/tests/regression/h4512/"
+
+static const char* EXCEPTION_CLASS = "L" PACKAGE "InvokeAgentException;";
+
+#define TURN_EVENT(event, state) { \
+    jvmtiError err = turn_event(jvmti, event, state, #event); \
+    if (JVMTI_ERROR_NONE != err) return; \
+}
+
+#define CHECK_RESULT(func) \
+    if (JVMTI_ERROR_NONE != err) { \
+        cerr << "[JvmtiAgent] ERROR: " << #func << " failed with error:
" << err << endl;  \
+        return; \
+    }
+
+#define CHECK_JNI3(result, func, error_code) { \
+    if (jni->ExceptionCheck()) { \
+        cerr << "[JvmtiAgent] ERROR: unexpected exception in " << #func <<
endl;  \
+        jni->ExceptionDescribe(); \
+        return error_code; \
+    } \
+    if (! (result)) { \
+        cerr << "[JvmtiAgent] ERROR: get NULL in " << #func << endl;  \
+        return error_code; \
+    } \
+}
+
+#define CHECK_JNI(result, func) CHECK_JNI3(result, func, )
+
+static void set_passed_state(JNIEnv* jni)
+{
+    cerr << endl << "TEST PASSED" << endl << endl;
+
+    jclass cl = jni->FindClass(PACKAGE "Status");
+    CHECK_JNI(cl, FindClass);
+
+    jfieldID testGroup_field = jni->GetStaticFieldID(cl, "status", "Z");
+    CHECK_JNI(testGroup_field, GetStaticFieldID);
+
+    jni->SetStaticBooleanField(cl, testGroup_field, JNI_TRUE);
+    CHECK_JNI(true, SetStaticBooleanField);
+}
+
+static jvmtiError turn_event(jvmtiEnv* jvmti, jvmtiEvent event, bool state,
+        const char* event_name)
+{
+    jvmtiError err;
+    err = jvmti->SetEventNotificationMode(state ? JVMTI_ENABLE : JVMTI_DISABLE,
+            event, NULL);
+    if (JVMTI_ERROR_NONE != err) {
+        cerr << "[JvmtiAgent] ERROR: unable to " << (state ? "en" : "dis")
+                << "able " << event_name
+                << endl;
+    }
+
+    return err;
+}
+
+static void JNICALL VMInit(jvmtiEnv* jvmti, JNIEnv* jni, jthread thread)
+{
+    cerr << endl << "==> VM Init callback" << endl;
+
+    TURN_EVENT(JVMTI_EVENT_EXCEPTION, true);
+}
+
+static void JNICALL
+Exception(jvmtiEnv *jvmti,
+            JNIEnv* jni,
+            jthread thread,
+            jmethodID method,
+            jlocation location,
+            jobject exception,
+            jmethodID catch_method,
+            jlocation catch_location)
+{
+    jvmtiError err;
+
+    jclass exn_class = jni->GetObjectClass(exception);
+    CHECK_JNI(exn_class, GetObjectClass);
+
+    char* class_name = NULL;
+    err = jvmti->GetClassSignature(exn_class, &class_name, NULL);
+    CHECK_RESULT(GetClassSignature);
+
+    if (0 != strcmp(EXCEPTION_CLASS, class_name))
+        return;
+
+    cerr << endl << "==> Exception callback" << endl;
+    cerr << "    for class: " << class_name << endl;
+
+    TURN_EVENT(JVMTI_EVENT_EXCEPTION, false);
+
+    jlong nanos = 0;
+    cerr << "    calling GetCurrentThreadCpuTime()..." << endl;
+
+    err = jvmti->GetCurrentThreadCpuTime(&nanos);
+    CHECK_RESULT(GetCurrentThreadCpuTime);
+
+    cerr << "    ok." << endl;
+
+    set_passed_state(jni);
+}
+
+JNIEXPORT jint JNICALL Agent_OnLoad(JavaVM *vm, char *options, void *reserved)
+{
+    jvmtiEnv *jvmti = NULL;
+    jvmtiError err;
+
+    // Get JVMTI interface pointer
+    jint iRes = vm->GetEnv((void**)&jvmti, JVMTI_VERSION);
+    if (JNI_OK != iRes) {
+        cerr << "[JvmtiAgent] ERROR: unable to get JVMTI environment" << endl;
+        return -1;
+    }
+
+    // Set events callbacks
+    jvmtiEventCallbacks callbacks;
+    memset(&callbacks, 0, sizeof(jvmtiEventCallbacks));
+
+    callbacks.VMInit = VMInit;
+    callbacks.Exception = Exception;
+
+    err = jvmti->SetEventCallbacks(&callbacks, sizeof(jvmtiEventCallbacks));
+    if (JVMTI_ERROR_NONE != err) {
+        cerr << "[JvmtiAgent] ERROR: unable to register event callbacks" << endl;
+        return -1;
+    }
+
+    err = jvmti->SetEventNotificationMode(JVMTI_ENABLE,
+            JVMTI_EVENT_VM_INIT, NULL);
+    if (JVMTI_ERROR_NONE != err) {
+        cerr << "[JvmtiAgent] ERROR: unable to enable VMInit event"
+                << endl;
+        return -1;
+    }
+
+    // Set capabilities
+    jvmtiCapabilities capabilities;
+    memset(&capabilities, 0, sizeof(jvmtiCapabilities));
+    capabilities.can_generate_exception_events = 1;
+    capabilities.can_get_current_thread_cpu_time = 1;
+
+    err = jvmti->AddCapabilities(&capabilities);
+    if (JVMTI_ERROR_NONE != err) {
+        cerr << "[JvmtiAgent] ERROR: unable to possess capabilities" << endl;
+        return -1;
+    }
+
+    // Agent initialized successfully
+    return 0;
+}

Propchange: harmony/enhanced/drlvm/trunk/src/test/regression/H4512/GetCurrentThreadCpuTime.cpp
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/drlvm/trunk/src/test/regression/H4512/GetCurrentThreadCpuTime.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/src/test/regression/H4512/GetCurrentThreadCpuTime.java?view=auto&rev=559582
==============================================================================
--- harmony/enhanced/drlvm/trunk/src/test/regression/H4512/GetCurrentThreadCpuTime.java (added)
+++ harmony/enhanced/drlvm/trunk/src/test/regression/H4512/GetCurrentThreadCpuTime.java Wed
Jul 25 13:33:25 2007
@@ -0,0 +1,35 @@
+package org.apache.harmony.drlvm.tests.regression.h4512;
+
+import junit.framework.TestCase;
+
+/**
+ * Test case for GetCurrentThreadCpuTime() TI function.
+ * Tests that vm doesn't crash in that function.
+ */
+public class GetCurrentThreadCpuTime extends TestCase {
+
+    public static void main(String args[]) {
+        (new GetCurrentThreadCpuTime()).test();
+    }
+
+    public void test() {
+
+        try {
+            System.err.println("[Java]: Throwing an exception to invoke agent");
+            // pass execution to the agent
+            throw new InvokeAgentException();
+        } catch (Exception e) {
+            System.err.println("[Java]: Exception caught");
+        }
+
+        System.err.println("[Java]: test done");
+        assertTrue(Status.status);
+    }
+}
+
+class InvokeAgentException extends Exception {}
+
+class Status {
+    /** the field should be modified by jvmti agent to determine test result. */
+    public static boolean status = false;
+}

Propchange: harmony/enhanced/drlvm/trunk/src/test/regression/H4512/GetCurrentThreadCpuTime.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/drlvm/trunk/src/test/regression/H4512/run.test.xml
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/src/test/regression/H4512/run.test.xml?view=auto&rev=559582
==============================================================================
--- harmony/enhanced/drlvm/trunk/src/test/regression/H4512/run.test.xml (added)
+++ harmony/enhanced/drlvm/trunk/src/test/regression/H4512/run.test.xml Wed Jul 25 13:33:25
2007
@@ -0,0 +1,9 @@
+<project name="RUN HARMONY-4512 Regression Test">
+    <target name="run-test">
+        <!-- use special launcher for JVMTI tests -->
+        <run-jvmti-test
+            test="org.apache.harmony.drlvm.tests.regression.h4512.GetCurrentThreadCpuTime"
+            agent="GetCurrentThreadCpuTime"/>
+    </target>
+</project>
+

Propchange: harmony/enhanced/drlvm/trunk/src/test/regression/H4512/run.test.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: harmony/enhanced/drlvm/trunk/src/test/regression/excludes/exclude.linux.x86_64
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/src/test/regression/excludes/exclude.linux.x86_64?view=diff&rev=559582&r1=559581&r2=559582
==============================================================================
--- harmony/enhanced/drlvm/trunk/src/test/regression/excludes/exclude.linux.x86_64 (original)
+++ harmony/enhanced/drlvm/trunk/src/test/regression/excludes/exclude.linux.x86_64 Wed Jul
25 13:33:25 2007
@@ -16,4 +16,6 @@
 H3909
 # Exclude this test because JVMTI is not implemented for x86_64 in JIT mode yet
 H3982
+# Exclude this test because JVMTI is not implemented for x86_64 in JIT mode yet
+H4512
  

Modified: harmony/enhanced/drlvm/trunk/src/test/regression/excludes/exclude.windows.x86_64
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/src/test/regression/excludes/exclude.windows.x86_64?view=diff&rev=559582&r1=559581&r2=559582
==============================================================================
--- harmony/enhanced/drlvm/trunk/src/test/regression/excludes/exclude.windows.x86_64 (original)
+++ harmony/enhanced/drlvm/trunk/src/test/regression/excludes/exclude.windows.x86_64 Wed Jul
25 13:33:25 2007
@@ -15,4 +15,6 @@
 H3909
 # Exclude this test because JVMTI is not implemented for x86_64 in JIT mode yet
 H3982
+# Exclude this test because JVMTI is not implemented for x86_64 in JIT mode yet
+H4512
 

Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/thread_ti_timing.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/thread_ti_timing.cpp?view=diff&rev=559582&r1=559581&r2=559582
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/thread_ti_timing.cpp (original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/thread/thread_ti_timing.cpp Wed Jul 25 13:33:25
2007
@@ -65,7 +65,7 @@
     int64 kernel_time;
 
     assert(nanos_ptr);
-    hythread_t native_thread = java_thread
+    hythread_t native_thread = (NULL == java_thread)
         ? hythread_self() : vm_jthread_get_tm_data(java_thread);
     assert(native_thread);
     return hythread_get_thread_times(native_thread, &kernel_time,



Mime
View raw message