harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gshiman...@apache.org
Subject svn commit: r505334 - in /harmony/enhanced/drlvm/trunk: src/test/regression/H3074/ vm/vmcore/include/ vm/vmcore/src/class_support/ vm/vmcore/src/jni/
Date Fri, 09 Feb 2007 15:53:45 GMT
Author: gshimansky
Date: Fri Feb  9 07:53:45 2007
New Revision: 505334

URL: http://svn.apache.org/viewvc?view=rev&rev=505334
Log:
Applied HARMONY-3074 [drlvm][classloader][jni] When FindClass is called from JNI_OnLoad function
it cannot load user application classes

Also added regression test for this bug.

Tests passed on Ubuntu6 x86, Windows 2003 server x86 and SuSE9 x86_64


Added:
    harmony/enhanced/drlvm/trunk/src/test/regression/H3074/
    harmony/enhanced/drlvm/trunk/src/test/regression/H3074/AnotherClass.java   (with props)
    harmony/enhanced/drlvm/trunk/src/test/regression/H3074/Test.java   (with props)
    harmony/enhanced/drlvm/trunk/src/test/regression/H3074/natives.cpp   (with props)
    harmony/enhanced/drlvm/trunk/src/test/regression/H3074/run.test.xml   (with props)
Modified:
    harmony/enhanced/drlvm/trunk/vm/vmcore/include/vm_threads.h
    harmony/enhanced/drlvm/trunk/vm/vmcore/src/class_support/classloader.cpp
    harmony/enhanced/drlvm/trunk/vm/vmcore/src/jni/jni_utils.cpp

Added: harmony/enhanced/drlvm/trunk/src/test/regression/H3074/AnotherClass.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/src/test/regression/H3074/AnotherClass.java?view=auto&rev=505334
==============================================================================
--- harmony/enhanced/drlvm/trunk/src/test/regression/H3074/AnotherClass.java (added)
+++ harmony/enhanced/drlvm/trunk/src/test/regression/H3074/AnotherClass.java Fri Feb  9 07:53:45
2007
@@ -0,0 +1,11 @@
+package org.apache.harmony.drlvm.tests.regression.h3074;
+
+public class AnotherClass {
+    public static boolean status = false;
+
+    public static void method() {
+        System.out.println("Class was loaded with " +
+            AnotherClass.class.getClassLoader());
+        status = true;
+    }
+}

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

Added: harmony/enhanced/drlvm/trunk/src/test/regression/H3074/Test.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/src/test/regression/H3074/Test.java?view=auto&rev=505334
==============================================================================
--- harmony/enhanced/drlvm/trunk/src/test/regression/H3074/Test.java (added)
+++ harmony/enhanced/drlvm/trunk/src/test/regression/H3074/Test.java Fri Feb  9 07:53:45 2007
@@ -0,0 +1,16 @@
+package org.apache.harmony.drlvm.tests.regression.h3074;
+
+import junit.framework.TestCase;
+
+public class Test extends TestCase {
+    public void test() {
+        System.out.println("Test is loaded with " + Test.class.getClassLoader());
+        try {
+            System.loadLibrary("natives");
+        } catch (Throwable e) {
+            System.out.println("Test failed on exception:");
+            e.printStackTrace();
+        }
+        assertTrue(AnotherClass.status);
+    }
+}

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

Added: harmony/enhanced/drlvm/trunk/src/test/regression/H3074/natives.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/src/test/regression/H3074/natives.cpp?view=auto&rev=505334
==============================================================================
--- harmony/enhanced/drlvm/trunk/src/test/regression/H3074/natives.cpp (added)
+++ harmony/enhanced/drlvm/trunk/src/test/regression/H3074/natives.cpp Fri Feb  9 07:53:45
2007
@@ -0,0 +1,35 @@
+#include <jni.h>
+
+#ifdef __cplusplus
+extern "C" jint JNIEXPORT JNICALL JNI_OnLoad(JavaVM *vm, void *reserved);
+#endif
+
+jint JNIEXPORT JNICALL JNI_OnLoad(JavaVM *vm, void *reserved)
+{
+    JNIEnv *env;
+    jint status = vm->GetEnv((void **)&env, JNI_VERSION_1_4);
+    if (status != JNI_OK)
+    {
+        printf("Could not get JNIenv\n");
+        return 0;
+    }
+
+    jclass cl = env->FindClass("org/apache/harmony/drlvm/tests/regression/h3074/AnotherClass");
+    if (NULL == cl)
+    {
+        printf("Failed to load class:\n");
+        env->ExceptionDescribe();
+        return 0;
+    }
+
+    jmethodID mid = env->GetStaticMethodID(cl, "method", "()V");
+    if (NULL == mid)
+    {
+        printf("Failed to get method ID:\n");
+        env->ExceptionDescribe();
+        return 0;
+    }
+
+    env->CallStaticVoidMethod(cl, mid);
+    return JNI_VERSION_1_4;
+}

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

Added: harmony/enhanced/drlvm/trunk/src/test/regression/H3074/run.test.xml
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/src/test/regression/H3074/run.test.xml?view=auto&rev=505334
==============================================================================
--- harmony/enhanced/drlvm/trunk/src/test/regression/H3074/run.test.xml (added)
+++ harmony/enhanced/drlvm/trunk/src/test/regression/H3074/run.test.xml Fri Feb  9 07:53:45
2007
@@ -0,0 +1,11 @@
+<project name="RUN HARMONY-3074 Regression Test">
+    <target name="run-test">
+        <run-junit-test 
+            test="org.apache.harmony.drlvm.tests.regression.h3074.Test">
+            <junit-element>
+              <sysproperty key="java.library.path" value="${reg.test.native.path}/H3074"/>
+            </junit-element>
+        </run-junit-test>
+    </target>
+</project>
+

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

Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/include/vm_threads.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/include/vm_threads.h?view=diff&rev=505334&r1=505333&r2=505334
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/include/vm_threads.h (original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/include/vm_threads.h Fri Feb  9 07:53:45 2007
@@ -81,6 +81,11 @@
      */
     JNIEnv_Internal * jni_env;
 
+    /**
+     * Class loader which loads native library and calls to its JNI_OnLoad
+     */
+    ClassLoader* onload_caller;
+
     // In case exception is thrown, Exception object is put here
     // TODO: Needs to be replaced with jobject!
     //volatile ManagedObject*           p_exception_object;
@@ -133,8 +138,7 @@
     //gc_enable_disable_state           gc_enabled_status;
     bool                              gc_wait_for_enumeration;
     bool                              restore_context_after_gc_and_resume;
-    
-    
+
 #if defined(PLATFORM_POSIX) && defined(_IPF_)
     // Linux/IPF
     sem_t                             suspend_sem;     // To suspend thread in signal handler

Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/src/class_support/classloader.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/class_support/classloader.cpp?view=diff&rev=505334&r1=505333&r2=505334
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/src/class_support/classloader.cpp (original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/class_support/classloader.cpp Fri Feb  9 07:53:45
2007
@@ -968,15 +968,14 @@
     apr_pool_t* tmp_pool;
     apr_status_t stat = apr_pool_create(&tmp_pool, this->pool);
     // FIXME: process failure properly
-    
-   //
-   // $$$ GMJ - we don't want it to be where we're running from, but
-   //    where everything else came from.  For now, let it be
-   //    so that apr_dso_load() will do the right thing.  This is
-   //    going to be weird, because we have native code in both
-   //    / as well as /default...  FIXME
-   //
-   // const char* canoname = port_filepath_canonical(name, tmp_pool); 
+
+    // $$$ GMJ - we don't want it to be where we're running from, but
+    //    where everything else came from.  For now, let it be
+    //    so that apr_dso_load() will do the right thing.  This is
+    //    going to be weird, because we have native code in both
+    //    / as well as /default...  FIXME
+    //
+    // const char* canoname = port_filepath_canonical(name, tmp_pool); 
 
     const char *canoname = name;
     
@@ -1006,7 +1005,10 @@
     // load native library
     bool just_loaded;
     NativeLoadStatus status;
+    // FIXME: add storing class loader here
+    p_TLS_vmthread->onload_caller = this;
     NativeLibraryHandle handle = natives_load_library(lib_name->bytes, &just_loaded,
&status);
+    p_TLS_vmthread->onload_caller = NULL;
     if( !handle || !just_loaded ) {
         // create error message
         char apr_error_message[1024];

Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/src/jni/jni_utils.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/jni/jni_utils.cpp?view=diff&rev=505334&r1=505333&r2=505334
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/src/jni/jni_utils.cpp (original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/jni/jni_utils.cpp Fri Feb  9 07:53:45 2007
@@ -676,12 +676,14 @@
     assert(hythread_is_suspend_enabled());
     // Determine loader
     StackTraceFrame stf;
-    bool res = st_get_frame(0, &stf);
-    ClassLoader* loader;
-    if (res)
-        loader = (ClassLoader*)class_get_class_loader(method_get_class(stf.method));
-    else
-        loader = env->vm->vm_env->system_class_loader;
+    ClassLoader* loader = p_TLS_vmthread->onload_caller;
+    if(loader == NULL) {
+        bool res = st_get_frame(0, &stf);
+        if (res)
+            loader = (ClassLoader*)class_get_class_loader(method_get_class(stf.method));
+        else
+            loader = env->vm->vm_env->system_class_loader;
+    }
     String *s = name;
     Class* clss =
         class_load_verify_prepare_by_loader_jni(VM_Global_State::loader_env, s, loader);



Mime
View raw message