harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gshiman...@apache.org
Subject svn commit: r522599 - in /harmony/enhanced/drlvm/trunk: src/test/regression/H3317/ vm/vmcore/src/jvmti/
Date Mon, 26 Mar 2007 19:14:17 GMT
Author: gshimansky
Date: Mon Mar 26 12:14:16 2007
New Revision: 522599

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


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

Added: harmony/enhanced/drlvm/trunk/src/test/regression/H3317/GetFieldDeclaringClassTest.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/src/test/regression/H3317/GetFieldDeclaringClassTest.cpp?view=auto&rev=522599
==============================================================================
--- harmony/enhanced/drlvm/trunk/src/test/regression/H3317/GetFieldDeclaringClassTest.cpp
(added)
+++ harmony/enhanced/drlvm/trunk/src/test/regression/H3317/GetFieldDeclaringClassTest.cpp
Mon Mar 26 12:14:16 2007
@@ -0,0 +1,101 @@
+/**
+ * This test checks that jvmti function GetFieldDeclaringClass() works for
+ * inherited fields.
+ */
+#include <iostream>
+#include <jvmti.h>
+
+using namespace std;
+
+#define PACKAGE "org/apache/harmony/drlvm/tests/regression/h3317/"
+
+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 parent class
+    jclass parent = jni->FindClass(PACKAGE "Parent");
+    if (NULL == parent) {
+        cerr << "unable to find 'Parent' 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 declaring class
+    jclass declaring = NULL;
+
+    err = jvmti->GetFieldDeclaringClass(child, fid, &declaring);
+    if (JVMTI_ERROR_NONE != err) {
+        cerr << "unable to get declaring class; ERROR: " << err << endl;
+        return;
+    }
+
+    if (jni->IsSameObject(declaring, parent))
+        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/H3317/GetFieldDeclaringClassTest.cpp
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/drlvm/trunk/src/test/regression/H3317/GetFieldDeclaringClassTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/src/test/regression/H3317/GetFieldDeclaringClassTest.java?view=auto&rev=522599
==============================================================================
--- harmony/enhanced/drlvm/trunk/src/test/regression/H3317/GetFieldDeclaringClassTest.java
(added)
+++ harmony/enhanced/drlvm/trunk/src/test/regression/H3317/GetFieldDeclaringClassTest.java
Mon Mar 26 12:14:16 2007
@@ -0,0 +1,30 @@
+package org.apache.harmony.drlvm.tests.regression.h3317;
+
+import junit.framework.TestCase;
+
+/**
+ * Test case for GetFieldDeclaringClass() jvmti function.
+ */
+public class GetFieldDeclaringClassTest extends TestCase {
+    public static void main(String args[]) {
+        (new GetFieldDeclaringClassTest()).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/H3317/GetFieldDeclaringClassTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: harmony/enhanced/drlvm/trunk/src/test/regression/H3317/run.test.xml
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/src/test/regression/H3317/run.test.xml?view=auto&rev=522599
==============================================================================
--- harmony/enhanced/drlvm/trunk/src/test/regression/H3317/run.test.xml (added)
+++ harmony/enhanced/drlvm/trunk/src/test/regression/H3317/run.test.xml Mon Mar 26 12:14:16
2007
@@ -0,0 +1,9 @@
+<project name="RUN HARMONY-3317 Regression Test">
+    <target name="run-test">
+        <!-- use special launcher for JVMTI tests -->
+        <run-jvmti-test
+            test="org.apache.harmony.drlvm.tests.regression.h3317.GetFieldDeclaringClassTest"
+            agent="GetFieldDeclaringClassTest"/>
+    </target>
+</project>
+

Propchange: harmony/enhanced/drlvm/trunk/src/test/regression/H3317/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=522599&r1=522598&r2=522599
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti_field.cpp (original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti_field.cpp Mon Mar 26 12:14:16 2007
@@ -140,21 +140,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( !declaring_class_ptr ) return JVMTI_ERROR_NULL_POINTER;
 

Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti_internal.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti_internal.cpp?view=diff&rev=522599&r1=522598&r2=522599
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti_internal.cpp (original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/jvmti/jvmti_internal.cpp Mon Mar 26 12:14:16
2007
@@ -45,7 +45,7 @@
         return false;
     }
 
-    // Check that object is an instance of java.lang.Thread or extends it
+    // Check that object is an instance of clss or subclasss
     if (mo->vt() == NULL)
     {
         tmn_suspend_enable();



Mime
View raw message