harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gshiman...@apache.org
Subject svn commit: r502290 - in /harmony/enhanced/drlvm/trunk: build/make/targets/ src/test/regression/H2926/ vm/interpreter/src/
Date Thu, 01 Feb 2007 17:23:36 GMT
Author: gshimansky
Date: Thu Feb  1 09:23:35 2007
New Revision: 502290

URL: http://svn.apache.org/viewvc?view=rev&rev=502290
Log:
Applied patch with regression test for HARMONY-2926 [drlvm][jvmti] JVMTI Exception Callbacks
reported at incorrect byte code offset

The regression test when running on interpreter has shown another bug in
interpreter JVMTI support in handling exceptions when JVMTI disables Exception
event inside of event callback. Patch is applied to interpreter code.


Added:
    harmony/enhanced/drlvm/trunk/src/test/regression/H2926/
    harmony/enhanced/drlvm/trunk/src/test/regression/H2926/MyException.java   (with props)
    harmony/enhanced/drlvm/trunk/src/test/regression/H2926/Test.java   (with props)
    harmony/enhanced/drlvm/trunk/src/test/regression/H2926/TestClass.j   (with props)
    harmony/enhanced/drlvm/trunk/src/test/regression/H2926/run.test.xml   (with props)
    harmony/enhanced/drlvm/trunk/src/test/regression/H2926/test.cpp   (with props)
Modified:
    harmony/enhanced/drlvm/trunk/build/make/targets/reg.test.run.xml
    harmony/enhanced/drlvm/trunk/vm/interpreter/src/interpreter.cpp
    harmony/enhanced/drlvm/trunk/vm/interpreter/src/interpreter_ti.cpp

Modified: harmony/enhanced/drlvm/trunk/build/make/targets/reg.test.run.xml
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/build/make/targets/reg.test.run.xml?view=diff&rev=502290&r1=502289&r2=502290
==============================================================================
--- harmony/enhanced/drlvm/trunk/build/make/targets/reg.test.run.xml (original)
+++ harmony/enhanced/drlvm/trunk/build/make/targets/reg.test.run.xml Thu Feb  1 09:23:35 2007
@@ -168,11 +168,13 @@
         <attribute name="test"/>
         <attribute name="vmarg" default=""/>
         <attribute name="agent"/>
+        <element name="jvmti-junit-element" optional="true"/>
         <sequential>
             <run-junit-test test="@{test}" vmarg="@{vmarg}">
                 <junit-element>
+                    <jvmti-junit-element/>
                     <jvmarg value="-Dvm.assert_dialog=0" />
-                        <jvmarg
+                    <jvmarg
                         value="-agentpath:${reg.test.2launch.native.path}/${lib.prefix}@{agent}${lib.suffix}"
                         />
                 </junit-element>

Added: harmony/enhanced/drlvm/trunk/src/test/regression/H2926/MyException.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/src/test/regression/H2926/MyException.java?view=auto&rev=502290
==============================================================================
--- harmony/enhanced/drlvm/trunk/src/test/regression/H2926/MyException.java (added)
+++ harmony/enhanced/drlvm/trunk/src/test/regression/H2926/MyException.java Thu Feb  1 09:23:35
2007
@@ -0,0 +1,11 @@
+package org.apache.harmony.drlvm.tests.regression.h2926;
+
+public class MyException extends Exception {
+    public MyException() {
+        super();
+    }
+
+    public MyException(String msg) {
+        super(msg);
+    }
+}
\ No newline at end of file

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

Added: harmony/enhanced/drlvm/trunk/src/test/regression/H2926/Test.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/src/test/regression/H2926/Test.java?view=auto&rev=502290
==============================================================================
--- harmony/enhanced/drlvm/trunk/src/test/regression/H2926/Test.java (added)
+++ harmony/enhanced/drlvm/trunk/src/test/regression/H2926/Test.java Thu Feb  1 09:23:35 2007
@@ -0,0 +1,23 @@
+package org.apache.harmony.drlvm.tests.regression.h2926;
+
+import junit.framework.TestCase;
+
+/**
+ * Test correct locations of catch and throw in JVMTI Exception event
+ */
+public class Test extends TestCase {
+    public void test() {
+        TestClass tc = new TestClass();
+        tc.f1();
+        tc.f2();
+        tc.f3();
+        tc.f4();
+        System.out.println("test done");
+        assertTrue(Status.status);
+    }
+}
+
+class Status {
+    public static boolean status = false;
+}
+

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

Added: harmony/enhanced/drlvm/trunk/src/test/regression/H2926/TestClass.j
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/src/test/regression/H2926/TestClass.j?view=auto&rev=502290
==============================================================================
--- harmony/enhanced/drlvm/trunk/src/test/regression/H2926/TestClass.j (added)
+++ harmony/enhanced/drlvm/trunk/src/test/regression/H2926/TestClass.j Thu Feb  1 09:23:35
2007
@@ -0,0 +1,97 @@
+.class public org/apache/harmony/drlvm/tests/regression/h2926/TestClass
+.super java/lang/Object
+
+.method public <init>()V
+   .limit stack 1
+   .limit locals 1
+   aload_0
+   invokenonvirtual java/lang/Object/<init>()V
+   return
+.end method
+
+.method public f1()V
+   .limit stack 2
+   .limit locals 2
+   .catch org/apache/harmony/drlvm/tests/regression/h2926/MyException from L1 to L2 using
L2
+L1:
+   new org/apache/harmony/drlvm/tests/regression/h2926/MyException
+   dup
+   invokespecial org/apache/harmony/drlvm/tests/regression/h2926/MyException/<init>()V
+   astore_1
+   aload_1
+   athrow
+L2:
+   astore_1
+   return
+.end method
+
+.method public f2()V
+   .limit stack 1
+   .limit locals 2
+   .catch java/lang/NullPointerException from L1 to L2 using L3
+L1:
+   aconst_null
+   astore_1
+   aload_1
+   invokevirtual java/lang/String/toString()Ljava/lang/String;
+   astore_1
+L2:
+   goto exit
+L3:
+   astore_1
+exit:
+   return
+.end method
+
+.method public f3()V
+   .limit stack 1
+   .limit locals 2
+   .catch org/apache/harmony/drlvm/tests/regression/h2926/MyException from L1 to L2 using
L3
+L1:
+   aload_0
+   invokespecial org/apache/harmony/drlvm/tests/regression/h2926/TestClass/f5()V
+L2:
+   goto exit
+L3:
+   astore_1
+exit:
+   return
+.end method
+
+.method public f4()V
+   .limit stack 1
+   .limit locals 2
+   .catch java/lang/NullPointerException from L1 to L2 using L3
+L1:
+   aload_0
+   invokespecial org/apache/harmony/drlvm/tests/regression/h2926/TestClass/f6()V
+L2:
+   goto exit
+L3:
+   astore_1
+exit:
+   return
+.end method
+
+.method public f5()V
+   .limit stack 2
+   .limit locals 2
+   .throws org/apache/harmony/drlvm/tests/regression/h2926/MyException
+   new org/apache/harmony/drlvm/tests/regression/h2926/MyException
+   dup
+   invokespecial org/apache/harmony/drlvm/tests/regression/h2926/MyException/<init>()V
+   astore_1
+   aload_1
+   athrow
+.end method
+
+.method public f6()V
+   .limit stack 1
+   .limit locals 2
+   aconst_null
+   astore_1
+   aload_1
+   invokevirtual java/lang/String/toString()Ljava.lang.String;
+   astore_1
+   return
+.end method

Propchange: harmony/enhanced/drlvm/trunk/src/test/regression/H2926/TestClass.j
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/drlvm/trunk/src/test/regression/H2926/run.test.xml
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/src/test/regression/H2926/run.test.xml?view=auto&rev=502290
==============================================================================
--- harmony/enhanced/drlvm/trunk/src/test/regression/H2926/run.test.xml (added)
+++ harmony/enhanced/drlvm/trunk/src/test/regression/H2926/run.test.xml Thu Feb  1 09:23:35
2007
@@ -0,0 +1,18 @@
+<project name="RUN HARMONY-2926 Regression Test">
+    <target name="run-test">
+        <!-- use special launcher for JVMTI tests -->
+        <echo message="Running on JIT"/>
+        <run-jvmti-test
+            test="org.apache.harmony.drlvm.tests.regression.h2926.Test"
+            agent="test"/>
+        <echo message="Running on interpreter"/>
+        <run-jvmti-test
+            test="org.apache.harmony.drlvm.tests.regression.h2926.Test"
+            agent="test">
+            <jvmti-junit-element>
+                <jvmarg value="-Xint"/>
+            </jvmti-junit-element>
+        </run-jvmti-test>
+    </target>
+</project>
+

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

Added: harmony/enhanced/drlvm/trunk/src/test/regression/H2926/test.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/src/test/regression/H2926/test.cpp?view=auto&rev=502290
==============================================================================
--- harmony/enhanced/drlvm/trunk/src/test/regression/H2926/test.cpp (added)
+++ harmony/enhanced/drlvm/trunk/src/test/regression/H2926/test.cpp Thu Feb  1 09:23:35 2007
@@ -0,0 +1,145 @@
+#include <jvmti.h>
+#include <string.h>
+
+static const struct ExceptionEvents
+{
+    const char *throw_method_name;
+    const char *catch_method_name;
+    const char *exception_class_name;
+    const jlocation throw_location;
+    const jlocation catch_location;
+} exception_locations[] =
+{
+    {"f1", "f1", "Lorg/apache/harmony/drlvm/tests/regression/h2926/MyException;", 9, 10},
+    {"f2", "f2", "Ljava/lang/NullPointerException;", 3, 10},
+    {"f5", "f3", "Lorg/apache/harmony/drlvm/tests/regression/h2926/MyException;", 9, 7},
+    {"f6", "f4", "Ljava/lang/NullPointerException;", 3, 7}
+};
+
+static void JNICALL exception_callback(jvmtiEnv *jvmti_env,
+    JNIEnv* jni_env,
+    jthread thread,
+    jmethodID throw_method,
+    jlocation throw_location,
+    jobject exception,
+    jmethodID catch_method,
+    jlocation catch_location)
+{
+    static bool testing_started = false;
+    static int count = 0;
+    jvmtiError status;
+
+    char *throw_method_name;
+    char *catch_method_name;
+    char *exception_class_name;
+
+    status = jvmti_env->GetMethodName(throw_method, &throw_method_name, NULL, NULL);
+    if (JVMTI_ERROR_NONE != status)
+        return;
+
+    status = jvmti_env->GetMethodName(catch_method, &catch_method_name, NULL, NULL);
+    if (JVMTI_ERROR_NONE != status)
+        return;
+
+    jclass exception_class = jni_env->GetObjectClass(exception);
+    status = jvmti_env->GetClassSignature(exception_class,
+        &exception_class_name, NULL);
+    if (JVMTI_ERROR_NONE != status)
+        return;
+
+    if ((count < sizeof(exception_locations) / sizeof(ExceptionEvents)) &&
+        (0 ==
+            strcmp(throw_method_name, exception_locations[count].throw_method_name)) &&
+        (0 ==
+            strcmp(catch_method_name, exception_locations[count].catch_method_name)) &&
+        (0 ==
+            strcmp(exception_class_name, exception_locations[count].exception_class_name))
&&
+        (throw_location == exception_locations[count].throw_location) &&
+        (catch_location == exception_locations[count].catch_location)
+)
+    {
+        printf("Exception event received: %s(%d)->%s->%s(%d)\n",
+            throw_method_name,
+            (int)throw_location,
+            exception_class_name,
+            catch_method_name,
+            (int)catch_location);
+
+        testing_started = true;
+
+        if (count < sizeof(exception_locations) / sizeof(ExceptionEvents))
+            count++;
+
+        if (count == sizeof(exception_locations) / sizeof(ExceptionEvents))
+        {
+            printf("Success\n");
+            testing_started = false;
+            jclass cl = jni_env->FindClass("org/apache/harmony/drlvm/tests/regression/h2926/Status");
+            if (NULL == cl)
+                return;
+
+            jfieldID fid = jni_env->GetStaticFieldID(cl, "status", "Z");
+            if (NULL == fid)
+                return;
+
+            jni_env->SetStaticBooleanField(cl, fid, JNI_TRUE);
+
+            jvmti_env->SetEventNotificationMode(JVMTI_DISABLE,
+                JVMTI_EVENT_EXCEPTION, NULL);
+        }
+    }
+    else if (testing_started)
+    {
+        printf("Exception event number %d failed test\n", count);
+        printf("Exception event received: %s(%d)->%s->%s(%d)\n",
+            throw_method_name,
+            (int)throw_location,
+            exception_class_name,
+            catch_method_name,
+            (int)catch_location);
+        printf("Should be: %s(%d)->%s->%s(%d)\n",
+            exception_locations[count].throw_method_name,
+            (int)exception_locations[count].throw_location,
+            exception_locations[count].exception_class_name,
+            exception_locations[count].catch_method_name,
+            (int)exception_locations[count].catch_location);
+        jvmti_env->SetEventNotificationMode(JVMTI_DISABLE,
+            JVMTI_EVENT_EXCEPTION, NULL);
+    }
+
+    jvmti_env->Deallocate((unsigned char *)throw_method_name);
+    jvmti_env->Deallocate((unsigned char *)catch_method_name);
+    jvmti_env->Deallocate((unsigned char *)exception_class_name);
+}
+
+JNIEXPORT jint JNICALL Agent_OnLoad(JavaVM *vm, char *options, void *reserved)
+{
+    jvmtiEnv *jvmti_env;
+    if(vm->GetEnv((void**)&jvmti_env, JVMTI_VERSION_1_0) != JNI_OK)
+        return JNI_ERR;
+
+    // Set exception event capability
+    jvmtiCapabilities capabilities;
+    memset(&capabilities, 0, sizeof(jvmtiCapabilities));
+    capabilities.can_generate_exception_events = 1;
+
+    jvmtiError result = jvmti_env->AddCapabilities(&capabilities);
+    if (JVMTI_ERROR_NONE != result)
+        return JNI_ERR;
+
+    jvmtiEventCallbacks callbacks;
+    memset(&callbacks, 0, sizeof(jvmtiEventCallbacks));
+    callbacks.Exception = exception_callback;
+
+    result = jvmti_env->SetEventCallbacks(&callbacks, (jint)sizeof(callbacks));
+    if (JVMTI_ERROR_NONE != result)
+        return JNI_ERR;
+
+    // Set event mode to true
+    result = jvmti_env->SetEventNotificationMode(JVMTI_ENABLE,
+        JVMTI_EVENT_EXCEPTION, NULL);
+    if (JVMTI_ERROR_NONE != result)
+        return JNI_ERR;
+
+    return JNI_OK;
+}

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

Modified: harmony/enhanced/drlvm/trunk/vm/interpreter/src/interpreter.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/interpreter/src/interpreter.cpp?view=diff&rev=502290&r1=502289&r2=502290
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/interpreter/src/interpreter.cpp (original)
+++ harmony/enhanced/drlvm/trunk/vm/interpreter/src/interpreter.cpp Thu Feb  1 09:23:35 2007
@@ -2620,6 +2620,10 @@
             }
             breakpoint_processed = false;
 
+            if (get_thread_ptr()->p_exception_object_ti || exn_raised()) {
+                frame.exc = get_current_thread_exception();
+                goto got_exception;
+            }
         }
 
 #ifdef INTERPRETER_DEEP_DEBUG
@@ -2629,11 +2633,6 @@
         assert(!hythread_is_suspend_enabled());
         assert(&frame == getLastStackFrame());
         
-        if (get_thread_ptr()->p_exception_object_ti || exn_raised()) {
-             frame.exc = get_current_thread_exception();
-             goto got_exception;
-        }
-
         switch(ip0) {
             case OPCODE_NOP:
                 Opcode_NOP(frame); break;
@@ -3035,7 +3034,8 @@
                 jvmti_interpreter_exception_event_callback_call(frame.exc, method, loc, catch_method,
catch_location);
                 M2N_FREE_MACRO;
                 assert(!exn_raised());
-                p_TLS_vmthread->p_exception_object_ti = (volatile ManagedObject*) frame.exc;
+                if (interpreter_ti_notification_mode)
+                    p_TLS_vmthread->p_exception_object_ti = (volatile ManagedObject*)
frame.exc;
             }
         }
 

Modified: harmony/enhanced/drlvm/trunk/vm/interpreter/src/interpreter_ti.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/interpreter/src/interpreter_ti.cpp?view=diff&rev=502290&r1=502289&r2=502290
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/interpreter/src/interpreter_ti.cpp (original)
+++ harmony/enhanced/drlvm/trunk/vm/interpreter/src/interpreter_ti.cpp Thu Feb  1 09:23:35
2007
@@ -392,6 +392,9 @@
 
     if (enable) interpreter_ti_notification_mode |= new_mask;
     else interpreter_ti_notification_mode &= ~new_mask;
+
+    if (!interpreter_ti_notification_mode)
+        get_thread_ptr()->p_exception_object_ti = NULL;
 }
 
 void method_entry_callback(Method *method) {



Mime
View raw message