harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From var...@apache.org
Subject svn commit: r515482 - in /harmony/enhanced: classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ drlvm/trunk/vm/vmcore/src/kernel_classes/javasrc/java/lang/ drlvm/trunk/vm/vmcore/src/kernel_classes/native/
Date Wed, 07 Mar 2007 07:14:35 GMT
Author: varlax
Date: Tue Mar  6 23:14:34 2007
New Revision: 515482

URL: http://svn.apache.org/viewvc?view=rev&rev=515482
Log:
Fixed HARMONY-2644, loading array classes via Class.forName
Tested on SUSE10@ia32 & WinXP

Modified:
    harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ClassTest.java
    harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/javasrc/java/lang/Class.java
    harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/javasrc/java/lang/VMClassRegistry.java
    harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/native/java_lang_VMClassRegistry.cpp
    harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/native/java_lang_VMClassRegistry.h

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ClassTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ClassTest.java?view=diff&rev=515482&r1=515481&r2=515482
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ClassTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ClassTest.java
Tue Mar  6 23:14:34 2007
@@ -731,4 +731,44 @@
 		assertNotNull(in);
 		in.close();		
 	}
+        
+        /*
+         * Regression test for HARMONY-2644:
+         * Load system and non-system array classes via Class.forName()
+         */
+        public void test_forName_arrays() throws Exception {
+            Class c1 = getClass();
+            String s = c1.getName();
+            Class a1 = Class.forName("[L" + s + ";");
+            Class a2 = Class.forName("[[L" + s + ";");
+            assertSame(c1, a1.getComponentType());
+            assertSame(a1, a2.getComponentType());
+            Class l4 = Class.forName("[[[[[J");
+            assertSame(long[][][][][].class, l4);
+            
+            try{
+                System.out.println(Class.forName("[;"));
+                fail("1");
+            } catch (ClassNotFoundException ok) {}
+            try{
+                System.out.println(Class.forName("[["));
+                fail("2");
+            } catch (ClassNotFoundException ok) {}
+            try{
+                System.out.println(Class.forName("[L"));
+                fail("3");
+            } catch (ClassNotFoundException ok) {}
+            try{
+                System.out.println(Class.forName("[L;"));
+                fail("4");
+            } catch (ClassNotFoundException ok) {}
+            try{
+                System.out.println(Class.forName(";"));
+                fail("5");
+            } catch (ClassNotFoundException ok) {}
+            try{
+                System.out.println(Class.forName(""));
+                fail("6");
+            } catch (ClassNotFoundException ok) {}
+        }
 }

Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/javasrc/java/lang/Class.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/javasrc/java/lang/Class.java?view=diff&rev=515482&r1=515481&r2=515482
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/javasrc/java/lang/Class.java
(original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/javasrc/java/lang/Class.java
Tue Mar  6 23:14:34 2007
@@ -149,9 +149,27 @@
                 VMClassRegistry.getClassLoader(VMStack.getCallerClass(0)) != null) {
                 sc.checkPermission(RuntimePermissionCollection.GET_CLASS_LOADER_PERMISSION);
             }
-                clazz = VMClassRegistry.loadBootstrapClass(name);
+            clazz = VMClassRegistry.loadBootstrapClass(name);
         } else {
-            clazz = classLoader.loadClass(name);
+            int dims = 0;
+            int len = name.length();
+            while (dims < len && name.charAt(dims) == '[') dims++;
+            if (dims > 0 && len > dims + 1 
+                    && name.charAt(dims) == 'L' && name.endsWith(";")) {
+                /*
+                 * an array of a reference type is requested.
+                 * do not care of arrays of primitives as 
+                 * they are perfectly loaded by bootstrap classloader. 
+                 */
+                try {
+                    clazz = classLoader.loadClass(name.substring(dims + 1, len - 1));
+                } catch (ClassNotFoundException ignore) {}
+                if (clazz != null ) {
+                    clazz = VMClassRegistry.loadArray(clazz, dims);
+                }
+            } else {
+                clazz = classLoader.loadClass(name);
+            }
         }
         if(clazz == null) {
             throw new ClassNotFoundException(name);

Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/javasrc/java/lang/VMClassRegistry.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/javasrc/java/lang/VMClassRegistry.java?view=diff&rev=515482&r1=515481&r2=515482
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/javasrc/java/lang/VMClassRegistry.java
(original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/javasrc/java/lang/VMClassRegistry.java
Tue Mar  6 23:14:34 2007
@@ -271,6 +271,24 @@
     static native void linkClass(Class<?> clazz);
 
     /**
+     * This method is used for the
+     * {@link Class#forName(java.lang.String, boolean, java.lang.ClassLoader)
+     * Class.forName(String name, boolean initialize, ClassLoader loader)}
+     * method implementation. If the name parameter represents an array then this  
+     * method should be invoked in order to load an array class. For example, an
+     * expression (loadArray(Integer.TYPE, 1) == new int[0].getClass()) must be
+     * true. 
+     * <p>
+     * <b>Note:</b> Under design yet. Subjected to change.
+     * 
+     * @param componentType the type of array components. It must not be null.
+     * @param dimensions array dimension. It must be greater or equal to 0.
+     * @return a class which represents array
+     * @api2vm
+     */
+    static native Class loadArray(Class componentType, int dimensions);
+
+    /**
      * This method is used for implementation of the
      * {@link Runtime#load(java.lang.String) Runtime.load(String filename)}
      * method.

Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/native/java_lang_VMClassRegistry.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/native/java_lang_VMClassRegistry.cpp?view=diff&rev=515482&r1=515481&r2=515482
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/native/java_lang_VMClassRegistry.cpp
(original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/native/java_lang_VMClassRegistry.cpp
Tue Mar  6 23:14:34 2007
@@ -490,6 +490,25 @@
 
 /*
  * Class:     java_lang_VMClassRegistry
+ * Method:    loadArray
+ * Signature: (Ljava/lang/Class;I)Ljava/lang/Class;
+ */
+JNIEXPORT jclass JNICALL Java_java_lang_VMClassRegistry_loadArray
+  (JNIEnv *jenv, jclass, jclass compType, jint dims)
+{
+    Class *clss = jni_get_class_handle(jenv, compType);
+    Class *arr_clss = clss;
+
+    for (int i = 0; i < dims; i++) {
+        arr_clss = (Class *)class_get_array_of_class(arr_clss);
+        if (!arr_clss)   return 0;
+    }
+
+    return jni_class_from_handle(jenv, arr_clss);
+}
+
+/*
+ * Class:     java_lang_VMClassRegistry
  * Method:    loadLibrary
  * Signature: (Ljava/lang/String;Ljava/lang/ClassLoader;)V
  */

Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/native/java_lang_VMClassRegistry.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/native/java_lang_VMClassRegistry.h?view=diff&rev=515482&r1=515481&r2=515482
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/native/java_lang_VMClassRegistry.h
(original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/native/java_lang_VMClassRegistry.h
Tue Mar  6 23:14:34 2007
@@ -178,6 +178,13 @@
     jclass);
 
 /*
+ * Method: java.lang.VMClassRegistry.loadArray(Ljava/lang/Class;I)Ljava/lang/Class;
+ */
+JNIEXPORT jclass JNICALL
+Java_java_lang_VMClassRegistry_loadArray(JNIEnv *, jclass, 
+    jclass, jint);
+
+/*
  * Method: java.lang.VMClassRegistry.loadLibrary(Ljava/lang/String;Ljava/lang/ClassLoader;)V
  */
 JNIEXPORT void JNICALL



Mime
View raw message