harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From var...@apache.org
Subject svn commit: r513313 - in /harmony/enhanced/drlvm/trunk: src/test/regression/H2644/ src/test/regression/H2846/ vm/vmcore/include/ vm/vmcore/src/class_support/ vm/vmcore/src/jni/ vm/vmcore/src/kernel_classes/javasrc/java/lang/ vm/vmcore/src/kernel_classe...
Date Thu, 01 Mar 2007 13:36:45 GMT
Author: varlax
Date: Thu Mar  1 05:36:42 2007
New Revision: 513313

URL: http://svn.apache.org/viewvc?view=rev&rev=513313
Log:
Fixed HARMONY-2644 and HARMONY-2846 + few related clean-ups in api2vm.
Tested on SUSE10@ia32 and WinXP@ia32

Added:
    harmony/enhanced/drlvm/trunk/src/test/regression/H2644/
    harmony/enhanced/drlvm/trunk/src/test/regression/H2644/BootDelegationTest.java
    harmony/enhanced/drlvm/trunk/src/test/regression/H2644/run.test.xml
    harmony/enhanced/drlvm/trunk/src/test/regression/H2846/
    harmony/enhanced/drlvm/trunk/src/test/regression/H2846/NoVerify.j
    harmony/enhanced/drlvm/trunk/src/test/regression/H2846/NoVerifyTest.java
    harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/native/java_lang_ClassLoader.h
  (with props)
Modified:
    harmony/enhanced/drlvm/trunk/vm/vmcore/include/classloader.h
    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.cpp
    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/ClassLoader.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
    harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/native/java_lang_reflect_VMReflection.cpp

Added: harmony/enhanced/drlvm/trunk/src/test/regression/H2644/BootDelegationTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/src/test/regression/H2644/BootDelegationTest.java?view=auto&rev=513313
==============================================================================
--- harmony/enhanced/drlvm/trunk/src/test/regression/H2644/BootDelegationTest.java (added)
+++ harmony/enhanced/drlvm/trunk/src/test/regression/H2644/BootDelegationTest.java Thu Mar
 1 05:36:42 2007
@@ -0,0 +1,29 @@
+package org.apache.harmony.drlvm.tests.regression.h2644;
+
+import junit.framework.TestCase;
+
+public class BootDelegationTest extends TestCase {
+
+    public void test1() throws Exception {
+        try {
+            System.out.println("SubClass=" + Class.forName("org.apache.harmony.drlvm.tests.regression.h2644.SubClass"));
+            fail("Misconfigured!");
+        } catch (ClassNotFoundException e) {
+            fail();
+        } catch (NoClassDefFoundError ok) {}
+    }
+
+    public void test2() throws Exception {
+        try {
+            System.out.println("SubClass=" + Class.forName("org.apache.harmony.drlvm.tests.regression.h2644.SubClass",
true, null));
+            fail("Misconfigured!");
+        } catch (ClassNotFoundException e) {
+            fail();
+        } catch (NoClassDefFoundError ok) {}
+    }
+}
+
+class SuperClass {}
+class SubClass extends SuperClass {}
+
+

Added: harmony/enhanced/drlvm/trunk/src/test/regression/H2644/run.test.xml
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/src/test/regression/H2644/run.test.xml?view=auto&rev=513313
==============================================================================
--- harmony/enhanced/drlvm/trunk/src/test/regression/H2644/run.test.xml (added)
+++ harmony/enhanced/drlvm/trunk/src/test/regression/H2644/run.test.xml Thu Mar  1 05:36:42
2007
@@ -0,0 +1,12 @@
+<project name="RUN HARMONY-2644 Regression Test">
+    <target name="run-test">
+        <delete
+             file="${reg.test.class.path}/org/apache/harmony/drlvm/tests/regression/h2644/SuperClass.class"
+             verbose="true"/>
+        <run-junit-test 
+             test="org.apache.harmony.drlvm.tests.regression.h2644.BootDelegationTest"
+             vmarg="-Xbootclasspath/a:${reg.test.class.path}${path.separator}${junit.jar}">
+        </run-junit-test>
+    </target>
+</project>
+

Added: harmony/enhanced/drlvm/trunk/src/test/regression/H2846/NoVerify.j
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/src/test/regression/H2846/NoVerify.j?view=auto&rev=513313
==============================================================================
--- harmony/enhanced/drlvm/trunk/src/test/regression/H2846/NoVerify.j (added)
+++ harmony/enhanced/drlvm/trunk/src/test/regression/H2846/NoVerify.j Thu Mar  1 05:36:42
2007
@@ -0,0 +1,14 @@
+.class public org/apache/harmony/drlvm/tests/regression/h2846/NoVerify
+.super java/lang/Object
+
+.method public <init>()V
+   aload_0
+   invokenonvirtual java/lang/Object/<init>()V
+   return
+.end method
+
+.method public test()V
+    .limit locals 1
+    iload_3
+    return
+.end method

Added: harmony/enhanced/drlvm/trunk/src/test/regression/H2846/NoVerifyTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/src/test/regression/H2846/NoVerifyTest.java?view=auto&rev=513313
==============================================================================
--- harmony/enhanced/drlvm/trunk/src/test/regression/H2846/NoVerifyTest.java (added)
+++ harmony/enhanced/drlvm/trunk/src/test/regression/H2846/NoVerifyTest.java Thu Mar  1 05:36:42
2007
@@ -0,0 +1,15 @@
+package org.apache.harmony.drlvm.tests.regression.h2846;
+
+import junit.framework.TestCase;
+
+public class NoVerifyTest extends TestCase {
+
+    public void test() throws Exception {
+        for (int i = 0; i < 3; i++) {
+            try {
+                Class cl = Class.forName("org.apache.harmony.drlvm.tests.regression.h2846.NoVerify");
 
+                fail();
+            } catch (VerifyError ok) {}
+        }
+    }
+}

Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/include/classloader.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/include/classloader.h?view=diff&rev=513313&r1=513312&r2=513313
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/include/classloader.h (original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/include/classloader.h Thu Mar  1 05:36:42 2007
@@ -170,6 +170,8 @@
     Class* LookupClass(const String* name) { 
         LMAutoUnlock aulock(&m_lock);
         Class** klass = m_loadedClasses->Lookup(name);
+        if(klass == NULL)
+            klass = m_initiatedClasses->Lookup(name);
         return klass?*klass:NULL;
     }
     void InsertClass(Class* clss) {

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=513313&r1=513312&r2=513313
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/include/vm_threads.h (original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/include/vm_threads.h Thu Mar  1 05:36:42 2007
@@ -86,6 +86,13 @@
      */
     ClassLoader* onload_caller;
 
+    /**
+    * Flag to detect if a class is not found on bootclasspath,
+    * as opposed to linkage errors.
+    * Used for implementing default delegation model.
+    */
+    bool class_not_found;
+
     // In case exception is thrown, Exception object is put here
     // TODO: Needs to be replaced with jobject!
     //volatile ManagedObject*           p_exception_object;

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=513313&r1=513312&r2=513313
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/src/class_support/classloader.cpp (original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/class_support/classloader.cpp Thu Mar  1 05:36:42
2007
@@ -223,7 +223,7 @@
 {
     assert(!exn_raised());
     const String *className;
-
+    
     LOG2("classloader.defineclass", "Defining class " << (NULL != class_name ? class_name
: "NULL") << " with loader " << this);
     if(class_name) {
         className = env->string_pool.lookup(class_name);
@@ -233,9 +233,20 @@
             FailedLoadingClass(className);
             exn_raise_by_name("java/lang/ClassFormatError",
                 "class name could not be extracted from provided class data", NULL);
+            TRACE("No class name, DefineClass failed with CFE");
             return NULL;
         }
     }
+    if (LookupClass(className) != NULL) {
+        static const char* mess_templ = "Illegal attempt to redefine class : %s";
+        unsigned mess_size = strlen(mess_templ) + className->len + 1;
+        char* err_mess = (char*)STD_ALLOCA(mess_size);
+        sprintf(err_mess, mess_templ, className->bytes);
+        exn_raise_by_name("java/lang/LinkageError", err_mess);
+        TRACE(err_mess);
+        return NULL;
+    }
+    
     if(res_name) {
         *res_name = className;
     }
@@ -274,6 +285,7 @@
         if (NULL != redef_buf)
             _deallocate(redef_buf);
         FailedLoadingClass(className);
+        TRACE("Parsing classdata failed: " << className->bytes);
         return NULL;
     }
     if (NULL != redef_buf)
@@ -1684,7 +1696,7 @@
 
     // the symptom of circularity (illegal) is that a null class name is passed,
     // so detect this immediately
-    if( !class_name->bytes || *(class_name->bytes) == 0 ) {
+    if(!class_name->bytes) {
         REPORT_FAILED_CLASS_NAME(this, class_name->bytes,
             "java/lang/ClassCircularityError", class_name->bytes);
         return NULL;
@@ -1736,6 +1748,7 @@
 
         // check if a given class is found
         if(!not_found) {
+            p_TLS_vmthread->class_not_found = false;
             return clss;
         }
         assert(clss == NULL);

Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/src/jni/jni.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/jni/jni.cpp?view=diff&rev=513313&r1=513312&r2=513313
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/src/jni/jni.cpp (original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/jni/jni.cpp Thu Mar  1 05:36:42 2007
@@ -568,54 +568,6 @@
     ClassLoader* cl;
     if (loader != NULL)
     {
-        if(name)
-        {
-            jclass clazz = GetObjectClass(jenv, loader);
-            jmethodID meth_id = GetMethodID(jenv, clazz, "findLoadedClass", "(Ljava/lang/String;)Ljava/lang/Class;");
-            if (NULL == meth_id)
-            {
-                jobject exn = exn_get();
-                tmn_suspend_disable();
-                Class *exn_class = exn->object->vt()->clss;
-                assert(exn_class);
-                bool f = exn_class != env->java_lang_OutOfMemoryError_Class;
-                tmn_suspend_enable();
-                if(f)
-                    LDIE(19, "Fatal: an access to findLoadedClass method of java.lang.Class
is not provided");
-                // OutOfMemoryError should be rethrown after this JNI method exits
-                return 0;
-            }
-            jstring str = NewStringUTF(jenv, name);
-            if (NULL == str)
-            {
-                // the only OutOfMemoryError can be a reason to be here; it will be rethrown
after this JNI method exits
-                return 0;
-            }
-            jobject obj = CallObjectMethod(jenv, loader, meth_id, str);
-            if(obj)
-            {
-                jthrowable exn;
-                if(exn_raised())
-                {
-                    // pending exception will be rethrown after the JNI method exits
-                    return 0;
-                }
-                else
-                {
-                    static const char* mess_templ = "duplicate class definition: ";
-                    static size_t mess_templ_len = strlen(mess_templ);
-                    size_t mess_size = mess_templ_len + strlen(name) + 1; // 1 is for trailing
'\0'
-                    char* err_mess = (char*)STD_ALLOCA(mess_size);
-                    sprintf(err_mess, "%s%s", mess_templ, name);
-                    exn = exn_create("java/lang/LinkageError", err_mess);
-                }
-
-                assert(exn);
-                jint UNUSED ok = Throw(jenv, exn);
-                assert(ok == 0);
-                return 0;
-            }
-        }
         cl = class_loader_lookup(loader);
     }
     else

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=513313&r1=513312&r2=513313
==============================================================================
--- 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
Thu Mar  1 05:36:42 2007
@@ -134,87 +134,27 @@
      */
     public static Class<?> forName(String name, boolean initialize,
             ClassLoader classLoader) throws ClassNotFoundException {
-        if (name == null)
+        if (name == null) {
             throw new NullPointerException();
-            
-        Class clazz = null;
-        int i = 0;
-        try {
-            // First, if the name is array name convert it to simple reference
-            // name. For example, the name "[[Ljava.lang.Object;" will be
-            // converted to "java.lang.Object".
-            while (name.charAt(i) == '[') {
-                i++;
-            }
-            if (i > 0) {
-                switch (name.charAt(i)) {
-                case 'L':
-                    if (!name.endsWith(";")) {
-                        throw new ClassNotFoundException(name);
-                    }
-                    name = name.substring(i + 1, name.length() - 1);
-                    break;
-                case 'Z':
-                    clazz = Boolean.TYPE;
-                    break;
-                case 'B':
-                    clazz = Byte.TYPE;
-                    break;
-                case 'C':
-                    clazz = Character.TYPE;
-                    break;
-                case 'D':
-                    clazz = Double.TYPE;
-                    break;
-                case 'F':
-                    clazz = Float.TYPE;
-                    break;
-                case 'I':
-                    clazz = Integer.TYPE;
-                    break;
-                case 'J':
-                    clazz = Long.TYPE;
-                    break;
-                case 'S':
-                    clazz = Short.TYPE;
-                    break;
-                }
-                if (clazz != null) {
-                    //To reject superfluous symbols
-                    if (name.length() > i + 1) {
-                        throw new ClassNotFoundException(name);
-                    }
-                    clazz = VMClassRegistry.loadArray(clazz, i);
-                    if (initialize) {
-                        VMClassRegistry.initializeClass(clazz);
-                    } else {
-                        VMClassRegistry.linkClass(clazz);
-                    }
-                    return clazz;
-                }
-            }
-        } catch (RuntimeException e) {
+        }
+        if(name.indexOf("/") != -1) {
             throw new ClassNotFoundException(name);
         }
 
+        Class clazz = null;
+
         if (classLoader == null) {
             SecurityManager sc = System.getSecurityManager();
             if (sc != null &&
                 VMClassRegistry.getClassLoader(VMStack.getCallerClass(0)) != null) {
                 sc.checkPermission(RuntimePermissionCollection.GET_CLASS_LOADER_PERMISSION);
             }
-            clazz = VMClassRegistry.findLoadedClass(name, null);
-            if (clazz == null) {
-                throw new ClassNotFoundException(name);
-            }
+                clazz = VMClassRegistry.loadBootstrapClass(name);
         } else {
             clazz = classLoader.loadClass(name);
-            if (clazz == null) {
-                throw new ClassNotFoundException(name);
-            }
         }
-        if (i > 0) {
-            clazz = VMClassRegistry.loadArray(clazz, i);
+        if(clazz == null) {
+            throw new ClassNotFoundException(name);
         }
         if (initialize) {
             VMClassRegistry.initializeClass(clazz);

Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/javasrc/java/lang/ClassLoader.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/javasrc/java/lang/ClassLoader.java?view=diff&rev=513313&r1=513312&r2=513313
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/javasrc/java/lang/ClassLoader.java
(original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/javasrc/java/lang/ClassLoader.java
Thu Mar  1 05:36:42 2007
@@ -404,18 +404,31 @@
                 throw new SecurityException(
                     "It is not allowed to define classes inside the java.* package: " + name);
             }
+            if (name.indexOf('/') != -1) {
+                throw new NoClassDefFoundError(
+                        "The name is expected in binary (canonical) form,"
+                        + " therefore '/' symbols are not allowed: " + name);
+            }
             int lastDot = name.lastIndexOf('.');
             packageName = lastDot == -1 ? "" : name.substring(0, lastDot);
             certs = getCertificates(packageName, domain.getCodeSource());
         }
-        Class<?> clazz = VMClassRegistry
-            .defineClass(name, this, data, offset, len);
+        Class<?> clazz = defineClass0(name, data, offset, len);
         clazz.setProtectionDomain(domain);
         if (certs != null) {
             packageCertificates.put(packageName, certs);
         }
         return clazz;
     }
+    
+    /**
+     * Loads new type into the classloader name space. 
+     * The class loader is marked as defining class loader. 
+     * @api2vm
+     */
+    private native Class<?> defineClass0(String name, byte[] data, int off, int len)

+    throws ClassFormatError;
+
 
     /**
      * @com.intel.drl.spec_ref
@@ -454,9 +467,7 @@
     /**
      * @com.intel.drl.spec_ref
      */
-    protected final Class<?> findLoadedClass(String name) {
-        return VMClassRegistry.findLoadedClass(name, this);
-    }
+    protected final native Class<?> findLoadedClass(String name);
 
     /**
      * @com.intel.drl.spec_ref
@@ -521,10 +532,17 @@
     protected synchronized Class<?> loadClass(String name, boolean resolve)
         throws ClassNotFoundException {
         checkInitialized();
+        if (name == null) {
+            throw new NullPointerException();
+        }
+        if(name.indexOf("/") != -1) {
+            throw new ClassNotFoundException(name);
+        }
+
         Class<?> clazz = findLoadedClass(name);
         if (clazz == null) {
             if (parentClassLoader == null) {
-                clazz = VMClassRegistry.findLoadedClass(name, null);
+                clazz = VMClassRegistry.loadBootstrapClass(name);
             } else {
                 try {
                     clazz = parentClassLoader.loadClass(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=513313&r1=513312&r2=513313
==============================================================================
--- 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
Thu Mar  1 05:36:42 2007
@@ -90,46 +90,13 @@
     private VMClassRegistry() 
     {
     }
-
-    /**
-     * Loads new type into specified class loader name space. The class loader
-     * should be marked as defining class loader. This method is used for the
-     * {@link ClassLoader#defineClass(String, byte[], int, int, java.security.ProtectionDomain)
-     * ClassLoader.defineClass(String name, byte[] b, int off, int len,
-     * ProtectionDomain protectionDomain)} method implementation.
-     * 
-     * @param name the name of class to be defined
-     * @param classLoader defining class loader
-     * @param data bytes pool containing the class data
-     * @param off start position of the class data in the pool
-     * @param len the length of the class data
-     * @return an object representing the defined class
-     * @throws ClassFormatError if the class data is incorrect.
-     * @throws NoClassDefFoundError if the specified name doesn't match class
-     *         name defined in the data array.
-     * @api2vm
-     */
-    static native Class<?> defineClass(String name, ClassLoader classLoader,
-    byte[] data, int off, int len) throws ClassFormatError;
-
+   
     /**
-     * This method satisfies the requirements of the specification for the
-     * {@link ClassLoader#findLoadedClass(String)
-     * ClassLoader.findLoadedClass(String name)} method. But it differs in
-     * several ways.
-     * <p>
-     * First, it takes additional class loader parameter.
-     * <p>
-     * Second, if the specified class loader is equal to null it should make an
-     * attempt to load a class with the specified name. If class can not be
-     * loaded by any reason null should be returned.
-     * 
-     * @param loader the class loader which is used to find loaded classes. if
-     *        the specified class loader is equal to null than the bootstrap
-     *        class loader will be searched.
+     * Loads the specified class with the bootstrap classloader.  
+     * @throws LinkageError (or any subtype) if loading failed
      * @api2vm
      */
-    static native Class<?> findLoadedClass(String name, ClassLoader loader);
+    static native Class<?> loadBootstrapClass(String name);
 
     /**
      * This method satisfies the requirements of the specification for the
@@ -302,24 +269,6 @@
      * @api2vm
      */
     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

Added: harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/native/java_lang_ClassLoader.h
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/native/java_lang_ClassLoader.h?view=auto&rev=513313
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/native/java_lang_ClassLoader.h
(added)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/native/java_lang_ClassLoader.h
Thu Mar  1 05:36:42 2007
@@ -0,0 +1,108 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+#include <jni.h>
+
+
+/* Header for class java.lang.ClassLoader */
+
+#ifndef _JAVA_LANG_CLASSLOADER_H
+#define _JAVA_LANG_CLASSLOADER_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+/* Native methods */
+
+/*
+ * Method: java.lang.ClassLoader.findLoadedClass(Ljava/lang/String;)Ljava/lang/Class;
+ */
+JNIEXPORT jclass JNICALL
+Java_java_lang_ClassLoader_findLoadedClass(JNIEnv *, jobject, 
+    jstring);
+
+/*                                          
+ * Method: java.lang.ClassLoader.defineClass0(Ljava/lang/String;[BII)Ljava/lang/Class;
+ * Throws: java.lang.ClassFormatError
+ */
+JNIEXPORT jclass JNICALL
+Java_java_lang_ClassLoader_defineClass0(JNIEnv *, jobject, 
+    jstring, jbyteArray, jint, jint);
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _JAVA_LANG_CLASSLOADER_H */
+
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+#include <jni.h>
+
+
+/* Header for class java.lang.ClassLoader */
+
+#ifndef _JAVA_LANG_CLASSLOADER_H
+#define _JAVA_LANG_CLASSLOADER_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+/* Native methods */
+
+/*
+ * Method: java.lang.ClassLoader.findLoadedClass(Ljava/lang/String;)Ljava/lang/Class;
+ */
+JNIEXPORT jclass JNICALL
+Java_java_lang_ClassLoader_findLoadedClass(JNIEnv *, jobject, 
+    jstring);
+
+/*
+ * Method: java.lang.ClassLoader.defineClass(Ljava/lang/String;[BII)Ljava/lang/Class;
+ * Throws: java.lang.ClassFormatError
+ */
+JNIEXPORT jclass JNICALL
+Java_java_lang_ClassLoader_defineClass0(JNIEnv *, jobject, 
+    jstring, jbyteArray, jint, jint);
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _JAVA_LANG_CLASSLOADER_H */
+

Propchange: harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/native/java_lang_ClassLoader.h
------------------------------------------------------------------------------
    svn:eol-style = native

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=513313&r1=513312&r2=513313
==============================================================================
--- 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
Thu Mar  1 05:36:42 2007
@@ -38,34 +38,21 @@
 #include "vm_strings.h"
 
 #include "java_lang_VMClassRegistry.h"
+#include "java_lang_ClassLoader.h"
 
 /*
  * Class:     java_lang_VMClassRegistry
  * Method:    defineClass
  * Signature: (Ljava/lang/String;[BII)Ljava/lang/Class;
  */
-JNIEXPORT jclass JNICALL Java_java_lang_VMClassRegistry_defineClass
-  (JNIEnv *jenv, jclass, jstring name, jobject cl, jbyteArray data, jint offset, jint len)
+JNIEXPORT jclass JNICALL Java_java_lang_ClassLoader_defineClass0 
+  (JNIEnv *jenv, jobject cl, jstring name, jbyteArray data, jint offset, jint len)
 {
     const char* clssname = NULL;
 
     // obtain char * for the name if provided
     if(name) {
         clssname = GetStringUTFChars(jenv, name, NULL);
-        if (NULL != strchr(clssname, '/'))
-        {
-            std::stringstream ss;
-            ss << "The name is expected in binary (canonical) form,"
-                " therefore '/' symbols are not allowed: " << clssname;
-
-            ReleaseStringUTFChars(jenv, name, clssname);
-            exn_raise_object(
-                exn_create(
-                    VM_Global_State::loader_env->JavaLangNoClassDefFoundError_String->bytes,
-                    ss.str().c_str()));
-
-            return NULL;
-        }
     }
 
     // obtain raw classfile data data pointer
@@ -85,86 +72,49 @@
     return clss;
 }
 
+JNIEXPORT jclass JNICALL Java_java_lang_VMClassRegistry_loadBootstrapClass
+    (JNIEnv *jenv, jclass, jstring name)
+{
+    // obtain char* for the name
+    const char* buf = GetStringUTFChars(jenv, name, NULL);
+    // set flag to detect if the requested class is not on the bootclasspath
+    p_TLS_vmthread->class_not_found = true;
+    Class_Handle clss = class_find_class_from_loader(NULL, buf, FALSE);
+    ReleaseStringUTFChars(jenv, name, buf);
+    if (clss) {
+        // filter out primitive types for compatibility
+        return clss->is_primitive() ? NULL : jni_class_from_handle(jenv, clss);
+    } else {
+        assert(exn_raised());
+        if(p_TLS_vmthread->class_not_found) 
+        {
+            // the requested class is not on the bootclasspath
+            // delegation model requires letting child loader(s) to continue 
+            // with searching on their paths, so reset the exception
+            exn_clear();
+        }
+        return NULL;
+    }
+}
+
 /*
  * Class:     java_lang_VMClassRegistry
  * Method:    findLoadedClass
  * Signature: (Ljava/lang/String;Ljava/lang/ClassLoader;)Ljava/lang/Class;
  */
-JNIEXPORT jclass JNICALL Java_java_lang_VMClassRegistry_findLoadedClass
-    (JNIEnv *jenv, jclass, jstring name, jobject cl)
+JNIEXPORT jclass JNICALL Java_java_lang_ClassLoader_findLoadedClass
+    (JNIEnv *jenv, jobject cl, jstring name)
 {
-    ASSERT_RAISE_AREA;
-
-    // check the name is provided
-    if (name == NULL) {
-        ThrowNew_Quick(jenv, "java/lang/NullPointerException", "null class name value.");
+    if (NULL == name) {
         return NULL;
-    }
-
-    // obtain char* for the name
-    unsigned length = GetStringUTFLength(jenv, name);
-    char* buf = (char*)STD_MALLOC(length+1);
-    assert(buf);
-    GetStringUTFRegion(jenv, name, 0, GetStringLength(jenv, name), buf);
-
-    // check for wrong symbols
-    if (strcspn(buf, "/[;") < length) {
-        STD_FREE(buf);
-        return NULL;
-    }
-
-    // filter out primitive types
-
-    Global_Env *ge = jni_get_vm_env(jenv);
-    Class* primitives[] = {
-        ge->Boolean_Class,
-        ge->Char_Class,
-        ge->Float_Class,
-        ge->Double_Class,
-        ge->Byte_Class,
-        ge->Short_Class,
-        ge->Int_Class,
-        ge->Long_Class,
-        ge->Void_Class,
-    };
-    int primitives_len = sizeof(primitives) / sizeof(Class*);
-
-    for (int i = 0; i < primitives_len; i++) {
-        if (primitives[i] && primitives[i]->get_name()) {
-            char *pname = (char*)primitives[i]->get_name()->bytes;
-            if (0 == strcmp(buf, pname)) {
-                STD_FREE(buf);
-                return NULL;
-            }
-        }
-    }
-
-    ClassLoaderHandle loader = NULL;
-    Class_Handle clss = NULL;
-    jclass jclss = NULL;
-
-    if(cl) {
-        // if non null class loader is provided, search among loaded classes
-        loader = class_loader_lookup(cl);
-        clss = class_find_loaded(loader, buf);
-    } else {
-        // if null class loader is specified
-        // load class using bootstrap class loader
-        // clss = class_find_class_from_loader(NULL, buf, TRUE);
-        clss = class_find_class_from_loader(NULL, buf, FALSE);
-    }
-
-    STD_FREE(buf);
-
-    if (clss)
-        jclss = jni_class_from_handle(jenv, clss);
-
-    if (ExceptionOccurred(jenv)) {
-        ExceptionClear(jenv);
-        assert(jclss == NULL);
-    }
-
-    return jclss;
+    } 
+    
+    const char* buf = GetStringUTFChars(jenv, name, NULL);
+    ClassLoaderHandle loader = class_loader_lookup(cl);
+    Class_Handle clss = class_find_loaded(loader, buf);
+    ReleaseStringUTFChars(jenv, name, buf);
+    
+    return clss ? jni_class_from_handle(jenv, clss) : NULL; 
 }
 
 /*
@@ -448,6 +398,7 @@
   (JNIEnv *jenv, jclass unused, jclass clazz)
 {
     ASSERT_RAISE_AREA;
+    assert(clazz != NULL);
     Class *clss = jni_get_class_handle(jenv, clazz);
     Java_java_lang_VMClassRegistry_linkClass(jenv, unused, clazz);
     if(jenv->ExceptionCheck())
@@ -535,25 +486,6 @@
     // ppervov: this method intentionally left blank
     //      as in our VM classes will never get to Java
     //      unlinked (except resolution stage)
-}
-
-/*
- * 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);
 }
 
 /*

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=513313&r1=513312&r2=513313
==============================================================================
--- 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
Thu Mar  1 05:36:42 2007
@@ -15,11 +15,6 @@
  *  limitations under the License.
  */
 
-/** 
- * @author Euguene Ostrovsky
- * @version $Revision: 1.1.2.1.4.6 $
- */  
-
 /*
  * THE FILE HAS BEEN AUTOGENERATED BY INTEL IJH TOOL.
  * Please be aware that all changes made to this file manually
@@ -42,19 +37,12 @@
 /* Native methods */
 
 /*
- * Method: java.lang.VMClassRegistry.defineClass(Ljava/lang/String;Ljava/lang/ClassLoader;[BII)Ljava/lang/Class;
- * Throws: java.lang.ClassFormatError
- */
-JNIEXPORT jclass JNICALL
-Java_java_lang_VMClassRegistry_defineClass(JNIEnv *, jclass, 
-    jstring, jobject, jbyteArray, jint, jint);
-
-/*
- * Method: java.lang.VMClassRegistry.findLoadedClass(Ljava/lang/String;Ljava/lang/ClassLoader;)Ljava/lang/Class;
+ * Method: java.lang.VMClassRegistry.loadBootstrapClass(Ljava/lang/String;)Ljava/lang/Class;
+ * Throws: java.lang.NoClassDefFoundError
  */
 JNIEXPORT jclass JNICALL
-Java_java_lang_VMClassRegistry_findLoadedClass(JNIEnv *, jclass, 
-    jstring, jobject);
+Java_java_lang_VMClassRegistry_loadBootstrapClass(JNIEnv *, jclass, 
+    jstring);
 
 /*
  * Method: java.lang.VMClassRegistry.getClass(Ljava/lang/Object;)Ljava/lang/Class;
@@ -188,13 +176,6 @@
 JNIEXPORT void JNICALL
 Java_java_lang_VMClassRegistry_linkClass(JNIEnv *, jclass, 
     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

Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/native/java_lang_reflect_VMReflection.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/native/java_lang_reflect_VMReflection.cpp?view=diff&rev=513313&r1=513312&r2=513313
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/native/java_lang_reflect_VMReflection.cpp
(original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/native/java_lang_reflect_VMReflection.cpp
Thu Mar  1 05:36:42 2007
@@ -239,17 +239,12 @@
 } // Java_java_lang_reflect_VMReflection_invokeMethod
 
 // create multidimensional array with depth dimensions specified by dims
-jobject createArray(JNIEnv *jenv, jclass compType, jint *dims, int depth)
+jobject createArray(JNIEnv *jenv, Class* arrType, jint *dims, int depth)
 {
     jint size = dims[0];
-    jclass clazz;
-    
-    if (depth > 1) 
-        clazz = Java_java_lang_VMClassRegistry_loadArray(jenv, NULL, compType, (jint)(depth
- 1));
-    else
-        clazz = compType;
 
-    jobjectArray jarray = NewObjectArray(jenv, size, clazz, NULL);
+    jobjectArray jarray = NewObjectArray(jenv, size, 
+        struct_Class_to_java_lang_Class_Handle(arrType), NULL);
 
     if (exn_raised()) {
         return NULL;
@@ -257,6 +252,7 @@
 
     if (depth > 1)
     {
+        Class* compType = arrType->get_array_element_class();
         for (int i = 0; i < size; i++)
         {
             jobject elem = createArray(jenv, compType, dims + 1, depth - 1);
@@ -274,7 +270,7 @@
     TRACE("new array: depth=" << depth);
 
     if (depth <= 0 || depth > 255) {
-        const char *message = (depth <= 0) ? "zero-dimensional array specified." : 
+        const char *message = (depth <= 0) ? "negative or zero dimensional array specified."
: 
                 "requested dimensions number exceeds 255 supported limit." ;
         ThrowNew_Quick(jenv, "java/lang/IllegalArgumentException", message);
         return NULL;
@@ -291,7 +287,17 @@
         }
     }
 
-    jobject jarray = createArray(jenv, compType, dims, depth);
+    Class* arrClss = jclass_to_struct_Class(compType);
+    for (int i = depth - 1; i > 0; --i) {
+        arrClss = class_get_array_of_class(arrClss);
+        if (!arrClss) {
+            assert(exn_raised());
+            break;
+        }
+        WARN(arrClss->get_name()->bytes);
+    }
+
+    jobject jarray = arrClss ? createArray(jenv, arrClss, dims, depth) : NULL;
 
     ReleaseIntArrayElements(jenv, jdims, dims, JNI_ABORT);
 



Mime
View raw message