harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gshiman...@apache.org
Subject svn commit: r576467 - in /harmony/enhanced/buildtest/branches/2.0/tests/vts/vm: config/ src/test/vm/jvmti/funcs/GetOwnedMonitorInfo/GetOwnedMonitorInfo0101/
Date Mon, 17 Sep 2007 15:01:11 GMT
Author: gshimansky
Date: Mon Sep 17 08:01:10 2007
New Revision: 576467

URL: http://svn.apache.org/viewvc?rev=576467&view=rev
Log:
Applied patch from HARMONY-4351
[buildtest][vts] Test vm/jvmti/funcs/GetOwnedMonitorInfo/GetOwnedMonitorInfo0101/GetOwnedMonitorInfo0101.xml
is incorrect


Modified:
    harmony/enhanced/buildtest/branches/2.0/tests/vts/vm/config/exclude.file
    harmony/enhanced/buildtest/branches/2.0/tests/vts/vm/src/test/vm/jvmti/funcs/GetOwnedMonitorInfo/GetOwnedMonitorInfo0101/GetOwnedMonitorInfo0101.cpp
    harmony/enhanced/buildtest/branches/2.0/tests/vts/vm/src/test/vm/jvmti/funcs/GetOwnedMonitorInfo/GetOwnedMonitorInfo0101/GetOwnedMonitorInfo0101.java

Modified: harmony/enhanced/buildtest/branches/2.0/tests/vts/vm/config/exclude.file
URL: http://svn.apache.org/viewvc/harmony/enhanced/buildtest/branches/2.0/tests/vts/vm/config/exclude.file?rev=576467&r1=576466&r2=576467&view=diff
==============================================================================
--- harmony/enhanced/buildtest/branches/2.0/tests/vts/vm/config/exclude.file (original)
+++ harmony/enhanced/buildtest/branches/2.0/tests/vts/vm/config/exclude.file Mon Sep 17 08:01:10
2007
@@ -66,8 +66,6 @@
 vm/jvms/threads/threads189/threads18901/threads18901.xml       # test issue 9914 intermittent
failure
 vm/jvms/classFile/finally/finally09/finally0901/finally0901.xml  (former # H-3755)				
 vm/jvms/classFile/constraints/structural/constraint23/subroutine01/subroutine01.xml (former
# H-3755)
-# test issue, see comments H-3866
-vm/jvmti/funcs/GetOwnedMonitorInfo/GetOwnedMonitorInfo0101/GetOwnedMonitorInfo0101.xml	
 
 Harmony bugs:
 # H-2081

Modified: harmony/enhanced/buildtest/branches/2.0/tests/vts/vm/src/test/vm/jvmti/funcs/GetOwnedMonitorInfo/GetOwnedMonitorInfo0101/GetOwnedMonitorInfo0101.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/buildtest/branches/2.0/tests/vts/vm/src/test/vm/jvmti/funcs/GetOwnedMonitorInfo/GetOwnedMonitorInfo0101/GetOwnedMonitorInfo0101.cpp?rev=576467&r1=576466&r2=576467&view=diff
==============================================================================
--- harmony/enhanced/buildtest/branches/2.0/tests/vts/vm/src/test/vm/jvmti/funcs/GetOwnedMonitorInfo/GetOwnedMonitorInfo0101/GetOwnedMonitorInfo0101.cpp
(original)
+++ harmony/enhanced/buildtest/branches/2.0/tests/vts/vm/src/test/vm/jvmti/funcs/GetOwnedMonitorInfo/GetOwnedMonitorInfo0101/GetOwnedMonitorInfo0101.cpp
Mon Sep 17 08:01:10 2007
@@ -14,21 +14,6 @@
     See the License for the specific language governing permissions and
     limitations under the License.
 */
-/**
- * @author Valentin Al. Sitnick
- * @version $Revision: 1.1 $
- *
- */
-
-/* *********************************************************************** */
-
-#include "events.h"
-#include "utils.h"
-#include "fake.h"
-
-static bool test = false;
-static bool util = false;
-static bool flag = false;
 
 /* *********************************************************************** */
 
@@ -42,103 +27,204 @@
 
 /* *********************************************************************** */
 
-JNIEXPORT jint JNICALL Agent_OnLoad(prms_AGENT_ONLOAD)
-{
-    check_AGENT_ONLOAD;
+#include <iostream>
+#include <jvmti.h>
 
-    Callbacks CB;
+using namespace std;
 
-    cb_tstart;
-    cb_death;
+static const char* EXCEPTION_CLASS = "InvokeAgentException;";
 
-    AGENT_FOR_EVENTS_TESTS_PART_I; /* events.h */
+bool is_passed = false;
 
-    jvmtiEvent events[] = { JVMTI_EVENT_THREAD_START, JVMTI_EVENT_VM_DEATH };
+#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; \
+    }
 
-    AGENT_FOR_EVENTS_TESTS_PART_II;
+#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; \
+    } \
+}
 
-    fprintf(stderr, "\n-------------------------------------------------\n");
-    fprintf(stderr, "\ntest GetOwnedMonitorInfo0101 is started\n{\n");
-    fflush(stderr);
+#define CHECK_JNI(result, func) CHECK_JNI3(result, func, )
 
-    return JNI_OK;
+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 << "[JvmtiAgent] ==> VM Init callback" << endl;
 
-void JNICALL callbackThreadStart(prms_THRD_START)
+    TURN_EVENT(JVMTI_EVENT_EXCEPTION, true);
+    TURN_EVENT(JVMTI_EVENT_VM_DEATH, true);
+}
+
+static void JNICALL VMDeath(jvmtiEnv* jvmti, JNIEnv* jni)
 {
-    check_THRD_START;
+    cerr << endl << "[JvmtiAgent] ==> VM Death callback" << endl;
 
-    if (flag) return;
+    cerr << endl << "\tTest of function GetOwnedMonitorInfo0101         :  "
+            << (is_passed ? "passed" : "failed") << " " << endl;
+}
+
+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 (NULL == strstr(class_name, EXCEPTION_CLASS))
+        return;
+
+    cerr << "[JvmtiAgent] ==> Exception callback" << endl;
+    cerr << "[JvmtiAgent]     for class: " << class_name << endl;
+
+    jfieldID field;
+
+    field = jni->GetFieldID(exn_class, "ownerThread", "Ljava/lang/Thread;");
+    CHECK_JNI(field, GetFieldID);
+
+    jthread owner_thread = jni->GetObjectField(exception, field);
+    CHECK_JNI(owner_thread, GetObjectField);
+
+    field = jni->GetFieldID(exn_class, "monitors", "[Ljava/lang/Object;");
+    CHECK_JNI(field, GetFieldID);
+
+    jobjectArray monitors = (jobjectArray) jni->GetObjectField(exception,
+            field);
+    CHECK_JNI(monitors, GetObjectField);
+
+    jint expected_monitor_count = (jint) jni->GetArrayLength(monitors);
+    CHECK_JNI(expected_monitor_count, GetArrayLength);
 
-    jvmtiPhase phase;
-    jvmtiThreadInfo tinfo;
-    jvmtiError result;
-    jint tcount = 0;
-    jthread* threads;
-    jthread my_thread = NULL;
     jint owned_monitor_count;
     jobject* owned_monitors;
 
-    result = jvmti_env->GetPhase(&phase);
-    fprintf(stderr, "\tnative: GetPhase result = %d (must be zero) \n", result);
-    fprintf(stderr, "\tnative: current phase is %d (must be 4 (LIVE-phase)) \n", phase);
-    if ((result != JVMTI_ERROR_NONE) || (phase != JVMTI_PHASE_LIVE)) return;
-    result = jvmti_env->GetThreadInfo(thread, &tinfo);
-    fprintf(stderr, "\tnative: GetThreadInfo result = %d (must be zero) \n", result);
-    fprintf(stderr, "\tnative: current thread name is %s (must be zero) \n", tinfo.name);
-    if (result != JVMTI_ERROR_NONE) return;
-    if (strcmp(tinfo.name, "agent")) return;
-    fprintf(stderr, "\tnative: test started\n");
-
-    flag = true;
-    util = true;
-
-    result = jvmti_env->GetAllThreads(&tcount, &threads);
-    fprintf(stderr, "\tnative: GetAllThreads result = %d (must be zero) \n", result);
-    if (result != JVMTI_ERROR_NONE) return;
-
-    for ( int i = 0; i < tcount; i++ )
-    {
-        result = jvmti_env->GetThreadInfo(threads[i], &tinfo);
-        fprintf(stderr, "\tnative: GetThreadInfo result = %d (must be zero) \n", result);
-        fprintf(stderr, "\tnative: current thread name is %s (must be zero) \n", tinfo.name);
-        if (result != JVMTI_ERROR_NONE) continue;
-        if (strcmp(tinfo.name, "Owner")) continue;
-        my_thread = threads[i];
-        fprintf(stderr, "\tnative: tested thread was found = %p\n", my_thread);
-
-        break;
-    }
-
-    util = true;
-    result = jvmti_env->GetOwnedMonitorInfo(my_thread,
-                &owned_monitor_count, &owned_monitors);
-    fprintf(stderr, "\tnative: GetOwnedMonitorInfo result = %d (must be zero) \n", result);
-    flag = true;
-    fprintf(stderr, "\n\tnative: number of waited threads is %d (must be 7)\n",
-         owned_monitor_count );
-    if ((result == JVMTI_ERROR_NONE) && (owned_monitor_count == 7)) {
-        test = true;
+    cerr << "[JvmtiAgent]     Getting monitor info..." << endl;
+    err = jvmti->GetOwnedMonitorInfo(owner_thread, &owned_monitor_count,
+            &owned_monitors);
+    CHECK_RESULT(GetOwnedMonitorInfo);
+
+    cerr << "[JvmtiAgent]     Owned monitor count    "
+            << owned_monitor_count << endl;
+    cerr << "[JvmtiAgent]     Expected monitor count "
+            << expected_monitor_count << endl;
+
+    if (owned_monitor_count != expected_monitor_count) {
+        cerr << "[JvmtiAgent]     ERROR: Wrong monitor count." << endl;
+
+        err = jvmti->Deallocate((unsigned char*) owned_monitors);
+        CHECK_RESULT(Deallocate);
         return;
     }
+
+    for (jint i = 0; i < owned_monitor_count; i++) {
+        cerr << "[JvmtiAgent]     Check monitor number " << i << endl;
+
+        jobject expected_monitor = jni->GetObjectArrayElement(monitors,
+                owned_monitor_count - 1 - i);
+        CHECK_JNI(expected_monitor, GetObjectArrayElement);
+
+        if (! jni->IsSameObject(expected_monitor, owned_monitors[i])) {
+            cerr << "[JvmtiAgent]     ERROR: Owned monitor number " << i
+                     << " doesn't match the expected one." << endl;
+
+            err = jvmti->Deallocate((unsigned char*) owned_monitors);
+            CHECK_RESULT(Deallocate);
+            return;
+        }
+    }
+
+    err = jvmti->Deallocate((unsigned char*) owned_monitors);
+    CHECK_RESULT(Deallocate);
+
+    is_passed = true;
 }
 
-void JNICALL callbackVMDeath(prms_VMDEATH)
+JNIEXPORT jint JNICALL Agent_OnLoad(JavaVM *vm, char *options, void *reserved)
 {
-    check_VMDEATH;
+    jvmtiEnv *jvmti = NULL;
+    jvmtiError err;
 
-    fprintf(stderr, "\n\tTest of function GetOwnedMonitorInfo0101         : ");
+    // 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;
+    }
 
-    if (test && util)
-        fprintf(stderr, " passed \n");
-    else
-        fprintf(stderr, " failed \n");
+    // Set events callbacks
+    jvmtiEventCallbacks callbacks;
+    memset(&callbacks, 0, sizeof(jvmtiEventCallbacks));
+
+    callbacks.VMInit = VMInit;
+    callbacks.VMDeath = VMDeath;
+    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;
+    }
 
-    fprintf(stderr, "\n} /* test GetOwnedMonitorInfo0101 is finished */ \n");
-    fflush(stderr);
-}
+    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_owned_monitor_info = 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;
+}

Modified: harmony/enhanced/buildtest/branches/2.0/tests/vts/vm/src/test/vm/jvmti/funcs/GetOwnedMonitorInfo/GetOwnedMonitorInfo0101/GetOwnedMonitorInfo0101.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/buildtest/branches/2.0/tests/vts/vm/src/test/vm/jvmti/funcs/GetOwnedMonitorInfo/GetOwnedMonitorInfo0101/GetOwnedMonitorInfo0101.java?rev=576467&r1=576466&r2=576467&view=diff
==============================================================================
--- harmony/enhanced/buildtest/branches/2.0/tests/vts/vm/src/test/vm/jvmti/funcs/GetOwnedMonitorInfo/GetOwnedMonitorInfo0101/GetOwnedMonitorInfo0101.java
(original)
+++ harmony/enhanced/buildtest/branches/2.0/tests/vts/vm/src/test/vm/jvmti/funcs/GetOwnedMonitorInfo/GetOwnedMonitorInfo0101/GetOwnedMonitorInfo0101.java
Mon Sep 17 08:01:10 2007
@@ -16,139 +16,109 @@
 */
 package org.apache.harmony.vts.test.vm.jvmti;
 
-/** 
- * @author Valentin Al. Sitnick
- * @version $Revision: 1.1 $
- *
- */ 
+/**
+ * Test for GetOwnedMonitorInfo JVMTI function.
+ * <p> Test scenario: </p>
+ * <ol>
+ *   <li> Main thread starts "Owner" thread and waits for notification. </li>
+ *   <li> Owner thread occupies 10 monitors, notifies main thread and waits.
+ *     </li>
+ *   <li> Main thread invokes agent's exception callback which checks owned
+ *     monitors for Owner thread. </li>
+ *   <li> Main thread notifies Owner thread. </li>
+ * </ol>
+ */
 public class GetOwnedMonitorInfo0101 {
-    public static boolean all_threads_can_start = false;
-    public final static Object sync0 = new Object();
-    public final static Object sync1 = new Object();
-    public final static Object sync2 = new Object();
-    public final static Object sync3 = new Object();
-    public final static Object sync4 = new Object();
-    public final static Object sync5 = new Object();
-    public final static Object sync6 = new Object();
 
-    public static void main(String[] args) {
+    static final int MONITORS_NUMBER = 10;
+    static Object[] monitors = new Object[MONITORS_NUMBER];
+    static Object lock = new Object();
 
-	TestThread_T_10 tr = new TestThread_T_10("Owner");
-        tr.start();        
-        
-        while (!all_threads_can_start) {
-	    try {
-	        Thread.sleep(500);
-            } catch (Throwable te) {
-                te.printStackTrace();
-            }
+    public static void main(String[] args) {
+        for (int i = 0; i < monitors.length; i++) {
+            monitors[i] = new Object();
         }
 
-        new Thread() { // 0
-            public void run() {
-                synchronized (sync0) {
-                    return;
-                }
-            }
-        }.start();
+        System.err.println("[JAVA] " + monitors.length +
+                " monitor objects created");
 
-        new Thread() { // 1
+        Thread ownerThread = new Thread("Owner") {
             public void run() {
-                synchronized (sync1) {
-                    return;
-                }
+                occupyAllMonitors();
             }
-        }.start();
+        };
 
-        new Thread() { // 2
-            public void run() {
-                synchronized (sync2) {
-                    return;
-                }
-            }
-        }.start();
+        synchronized (lock) {
+            System.err.println("[JAVA] Starting owner thread...");
+            ownerThread.start();
 
-        new Thread() { // 3
-            public void run() {
-                synchronized (sync3) {
-                    return;
-                }
-            }
-        }.start();
+            try {
+                System.err.println("[JAVA] Waiting for owner thread to " +
+                        "occupy monitors...");
+                lock.wait();
 
-        new Thread() { // 4
-            public void run() {
-                synchronized (sync4) {
-                    return;
+                try {
+                    System.err.println("[JAVA] Invoking agent...");
+                    throw new InvokeAgentException(monitors, ownerThread);
+                } catch (InvokeAgentException exc) {
+                    System.err.println("[JAVA] Returned from agent callback.");
                 }
-            }
-        }.start();
 
-        new Thread() { // 5
-            public void run() {
-                synchronized (sync5) {
-                    return;
-                }
-            }
-        }.start();
+                System.err.println("[JAVA] Notifying owner thread...");
+                lock.notify();
 
-        new Thread() { // 6
-            public void run() {
-                synchronized (sync6) {
-                    return;
-                }
+            } catch (InterruptedException exc) {
+                exc.printStackTrace();
             }
-        }.start();
+        }
     }
-}
 
-class TestThread_T_10 extends Thread {
+    static void occupyAllMonitors() {
+        System.err.println("[JAVA] Owner: Occupying monitors...");
 
-    TestThread_T_10(String name) {
-        super(name);
+        occupyMonitor(0);
+
+        System.err.println("[JAVA] Owner: All monitors released.");
     }
 
-    public void special_method() {
-        new Thread("agent") {
-            public void run() {
-                return;
+    static void occupyMonitor(int monitorNumber) {
+        if (monitorNumber < monitors.length) {
+            synchronized (monitors[monitorNumber]) {
+                occupyMonitor(monitorNumber + 1);
             }
-        }.start();
+        } else {
+            top();
+        }
     }
 
-    public void run() {
-        synchronized (GetOwnedMonitorInfo0101.sync0) {
-            synchronized (GetOwnedMonitorInfo0101.sync1) {
-                synchronized (GetOwnedMonitorInfo0101.sync2) {
-                    synchronized (GetOwnedMonitorInfo0101.sync3) {
-                        synchronized (GetOwnedMonitorInfo0101.sync4) {
-                            synchronized (GetOwnedMonitorInfo0101.sync5) {
-                                synchronized (GetOwnedMonitorInfo0101.sync6) {
-
-                                    GetOwnedMonitorInfo0101.all_threads_can_start = true;
-
-                                    try {
-                                        Thread.sleep(5000);
-                                    } catch (Throwable te) {
-                                        te.printStackTrace();
-                                    }
-
-                                    special_method();
-
-                                    try {
-                                        Thread.sleep(1000);
-                                    } catch (Throwable te) {
-                                        te.printStackTrace();
-                                    }
-                                    
-                                    return;
-                                }
-                            }
-                        }
-                    }
-		}
-	    }
+    static void top() {
+        System.err.println("[JAVA] Owner: " + monitors.length +
+                " monitors occupied.");
+
+        synchronized (lock) {
+            System.err.println("[JAVA] Owner: Notifying main thread...");
+            lock.notify();
+
+            System.err.println("[JAVA] Owner: Waiting for main thread to " +
+                    "check owned monitors...");
+            try {
+                lock.wait();
+            } catch (InterruptedException exc) {
+                exc.printStackTrace();
+            }
         }
+
+        System.err.println("[JAVA] Owner: Releasing monitors...");
     }
 }
 
+class InvokeAgentException extends Exception {
+
+    Object[] monitors;
+    Thread ownerThread;
+
+    InvokeAgentException(Object[] monitors, Thread thread) {
+        this.monitors = monitors;
+        this.ownerThread = thread;
+    }
+}



Mime
View raw message