harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gshiman...@apache.org
Subject svn commit: r522984 - in /harmony/enhanced/drlvm/trunk: src/test/regression/H3505/ vm/vmcore/src/jvmti/
Date Tue, 27 Mar 2007 16:17:33 GMT
Author: gshimansky
Date: Tue Mar 27 09:17:31 2007
New Revision: 522984

URL: http://svn.apache.org/viewvc?view=rev&rev=522984
Log:
Applied HARMONY-3505 [drlvm][jvmti] GetFieldModifiers() returns error for field declared in
superclass


Added:
    harmony/enhanced/drlvm/trunk/src/test/regression/H3505/
    harmony/enhanced/drlvm/trunk/src/test/regression/H3505/GetFieldModifiersTest.cpp   (with
props)
    harmony/enhanced/drlvm/trunk/src/test/regression/H3505/GetFieldModifiersTest.java   (with
props)
    harmony/enhanced/drlvm/trunk/src/test/regression/H3505/run.test.xml   (with props)
Modified:
    harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti_field.cpp

Added: harmony/enhanced/drlvm/trunk/src/test/regression/H3505/GetFieldModifiersTest.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/src/test/regression/H3505/GetFieldModifiersTest.cpp?view=auto&rev=522984
==============================================================================
--- harmony/enhanced/drlvm/trunk/src/test/regression/H3505/GetFieldModifiersTest.cpp (added)
+++ harmony/enhanced/drlvm/trunk/src/test/regression/H3505/GetFieldModifiersTest.cpp Tue Mar
27 09:17:31 2007
@@ -0,0 +1,100 @@
+/**
+ * This test checks that jvmti function GetFieldModifiers() works for
+ * fields specified by jfieldID and jclass that inherits the field.
+ */
+#include <iostream>
+#include <jvmti.h>
+
+using namespace std;
+
+#define PACKAGE "org/apache/harmony/drlvm/tests/regression/h3505/"
+static const jint EXPECTED_MODIFIERS = 0;
+
+static void set_passed_state(JNIEnv* jni)
+{
+    jclass cl = jni->FindClass(PACKAGE "Status");
+    if (NULL == cl) {
+        cerr << "unable to find 'Status' class" << endl;
+        return;
+    }
+
+    jfieldID fid = jni->GetStaticFieldID(cl, "status", "Z");
+    if (NULL == fid) {
+        cerr << "unable to find 'status' field" << endl;
+        return;
+    }
+
+    jni->SetStaticBooleanField(cl, fid, JNI_TRUE);
+}
+
+static void JNICALL VMInit(jvmtiEnv* jvmti, JNIEnv* jni, jthread thread)
+{
+    jvmtiError err;
+
+    // get child class
+    jclass child = jni->FindClass(PACKAGE "Child");
+    if (NULL == child) {
+        cerr << "unable to find 'Child' class" << endl;
+        return;
+    }
+
+    // get inherited field from child class
+    jfieldID fid = jni->GetFieldID(child, "intField", "I");
+    if (NULL == fid) {
+        cerr << "unable to find the field" << endl;
+        return;
+    }
+
+    // get field modifiers, specifying field by ID and child class
+    jint modifiers = 0;
+
+    err = jvmti->GetFieldModifiers(child, fid, &modifiers);
+    if (JVMTI_ERROR_NONE != err) {
+        cerr << "unable to get field modifiers; ERROR: " << err << endl;
+        return;
+    }
+
+    if (EXPECTED_MODIFIERS != modifiers) {
+        cerr << "wrong field modifiers: " << modifiers
+                << "\texpected: " << EXPECTED_MODIFIERS << endl;
+        return;
+    }
+
+    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;
+
+    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;
+    }
+
+    // Agent initialized successfully
+    return 0;
+}

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

Added: harmony/enhanced/drlvm/trunk/src/test/regression/H3505/GetFieldModifiersTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/src/test/regression/H3505/GetFieldModifiersTest.java?view=auto&rev=522984
==============================================================================
--- harmony/enhanced/drlvm/trunk/src/test/regression/H3505/GetFieldModifiersTest.java (added)
+++ harmony/enhanced/drlvm/trunk/src/test/regression/H3505/GetFieldModifiersTest.java Tue
Mar 27 09:17:31 2007
@@ -0,0 +1,30 @@
+package org.apache.harmony.drlvm.tests.regression.h3505;
+
+import junit.framework.TestCase;
+
+/**
+ * Test case for GetFieldModifiers() jvmti function.
+ */
+public class GetFieldModifiersTest extends TestCase {
+    public static void main(String args[]) {
+        (new GetFieldModifiersTest()).test();
+    }
+
+    public void test() {
+        System.out.println("test done");
+        assertTrue(Status.status);
+    }
+}
+
+class Status {
+    /** the field should be modified by jvmti agent to determine test result. */
+    public static boolean status = false;
+}
+
+/** Base class declaring the field */
+class Parent {
+    int intField;
+}
+
+/** Derived class inherits the field */
+class Child extends Parent { }

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

Added: harmony/enhanced/drlvm/trunk/src/test/regression/H3505/run.test.xml
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/src/test/regression/H3505/run.test.xml?view=auto&rev=522984
==============================================================================
--- harmony/enhanced/drlvm/trunk/src/test/regression/H3505/run.test.xml (added)
+++ harmony/enhanced/drlvm/trunk/src/test/regression/H3505/run.test.xml Tue Mar 27 09:17:31
2007
@@ -0,0 +1,9 @@
+<project name="RUN HARMONY-3505 Regression Test">
+    <target name="run-test">
+        <!-- use special launcher for JVMTI tests -->
+        <run-jvmti-test
+            test="org.apache.harmony.drlvm.tests.regression.h3505.GetFieldModifiersTest"
+            agent="GetFieldModifiersTest"/>
+    </target>
+</project>
+

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

Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti_field.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti_field.cpp?view=diff&rev=522984&r1=522983&r2=522984
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti_field.cpp (original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti_field.cpp Tue Mar 27 09:17:31 2007
@@ -60,22 +60,8 @@
     if (! is_valid_class_object(klass))
         return JVMTI_ERROR_INVALID_CLASS;
 
-    Class *cl = jclass_to_struct_Class(klass);
-    if( cl == NULL ) return JVMTI_ERROR_NULL_POINTER;
-
     if( !field ) return JVMTI_ERROR_INVALID_FIELDID; // (25)
 
-    bool present = false;
-    for( unsigned i = 0; i < cl->get_number_of_fields(); i++ ) {
-        if( (jfieldID)cl->get_field(i) == field ) {
-            present = true;
-            break;
-        }
-    }
-
-    if( !present )
-        return JVMTI_ERROR_INVALID_FIELDID;
-
     char* fld_name;
     char* fld_sig;
     Field* fld = reinterpret_cast<Field*>(field);
@@ -180,21 +166,7 @@
     if (! is_valid_class_object(klass))
         return JVMTI_ERROR_INVALID_CLASS;
     
-    Class *cl = jclass_to_struct_Class(klass);
-    if( cl == NULL ) return JVMTI_ERROR_NULL_POINTER;
-
     if( !field ) return JVMTI_ERROR_INVALID_FIELDID;
-
-    bool present = false;
-    for( unsigned i = 0; i < cl->get_number_of_fields(); i++ ) {
-        if( (jfieldID)cl->get_field(i) == field ) {
-            present = true;
-            break;
-        }
-    }
-
-    if( !present )
-        return JVMTI_ERROR_INVALID_FIELDID;
 
     if( !modifiers_ptr ) return JVMTI_ERROR_NULL_POINTER;
 



Mime
View raw message