harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From var...@apache.org
Subject svn commit: r543106 - in /harmony/enhanced/drlvm/trunk/vm/vmcore/src: class_support/ gc/ kernel_classes/javasrc/java/lang/ kernel_classes/javasrc/org/apache/harmony/vm/
Date Thu, 31 May 2007 10:33:23 GMT
Author: varlax
Date: Thu May 31 03:33:19 2007
New Revision: 543106

URL: http://svn.apache.org/viewvc?view=rev&rev=543106
Log:
Postfix to HARMONY-3462, corrected identified issues + optimized Class.getClassLoader()

Modified:
    harmony/enhanced/drlvm/trunk/vm/vmcore/src/class_support/classloader.cpp
    harmony/enhanced/drlvm/trunk/vm/vmcore/src/gc/root_set_enum_common.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/javasrc/org/apache/harmony/vm/VMStack.java

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=543106&r1=543105&r2=543106
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/src/class_support/classloader.cpp (original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/class_support/classloader.cpp Thu May 31 03:33:19
2007
@@ -1595,33 +1595,23 @@
     return clss;
 } // UserDefinedClassLoader::DoLoadClass
 
-bool ClassLoader::InsertClass(Class* clss) {
-    tmn_suspend_disable();
+static jmethodID getClassRegistryMethod() {
+    Global_Env* env = VM_Global_State::loader_env;
+    String* acr_func_name = env->string_pool.lookup("registerLoadedClass");
+    String* acr_func_desc = env->string_pool.lookup("(Ljava/lang/Class;)V");
+    Class* clss = env->LoadCoreClass("java/lang/ClassLoader");
+    Method* m = clss->lookup_method(acr_func_name, acr_func_desc);
+    assert(m);
+    return (jmethodID)m;
+}
+
+bool ClassLoader::InsertClass(Class* clss) 
+{
     if (!IsBootstrap()) // skip BS classes
     {
-        Global_Env* env = VM_Global_State::loader_env;
-        jvalue args[3];
-        ManagedObject* jstr;
-
-        if (env->compress_references) {
-            jstr = uncompress_compressed_reference(clss->get_name()->intern.compressed_ref);
-        } else {
-            jstr = clss->get_name()->intern.raw_ref;
-        }
-        ObjectHandle h = oh_allocate_local_handle();
-        if (jstr != NULL) {
-            h->object = jstr;
-        } else {
-            h->object = vm_instantiate_cp_string_resolved((String*)clss->get_name());
-        }
-        args[1].l = h;
-
-        if (exn_raised()) {
-            TRACE2("classloader", "OutOfMemoryError on class registering " << clss->get_name()->bytes);
-            assert (false);
-            tmn_suspend_enable();
-            return false;
-        }
+        static jmethodID registryMethod = getClassRegistryMethod();
+        tmn_suspend_disable();
+        jvalue args[2], res;
 
         // this parameter
         ObjectHandle hl = oh_allocate_local_handle();
@@ -1631,19 +1621,12 @@
         // jlc parameter
         ObjectHandle chl = oh_allocate_local_handle();
         chl->object = *clss->get_class_handle();
-        args[2].l = chl;
-
-        static String* acr_func_name = env->string_pool.lookup("addToLoadedClasses");
-        static String* acr_func_desc = env->string_pool.lookup("(Ljava/lang/String;Ljava/lang/Class;)V");
-
-        Method* method = class_lookup_method_recursive(m_loader->vt()->clss, acr_func_name,
acr_func_desc);
-        assert(method);
+        args[1].l = chl;
 
-        jvalue res;
-        vm_execute_java_method_array((jmethodID) method, &res, args);
+        vm_execute_java_method_array(registryMethod, &res, args);
+        tmn_suspend_enable();
 
         if(exn_raised()) {
-            tmn_suspend_enable();
             return false;
         }
     }
@@ -1653,7 +1636,7 @@
     if (!IsBootstrap()){
         RemoveFromReported(clss->get_name());
     }
-    tmn_suspend_enable();
+    
     m_initiatedClasses->Insert(clss->get_name(), clss);
     return true;
 }

Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/src/gc/root_set_enum_common.cpp
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/gc/root_set_enum_common.cpp?view=diff&rev=543106&r1=543105&r2=543106
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/src/gc/root_set_enum_common.cpp (original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/gc/root_set_enum_common.cpp Thu May 31 03:33:19
2007
@@ -93,7 +93,7 @@
         for(unsigned i = 0; i < n_fields; i++) {
             Field* f = c->get_field(i);
             if(f->is_static()) {
-		if(field_is_enumerable_reference(f)){
+                if(field_is_enumerable_reference(f)){
                     // The field is static and it is a reference.
                     if (global_env->compress_references) {
                         vm_enumerate_compressed_root_reference((uint32 *)f->get_address(),
FALSE);
@@ -139,10 +139,9 @@
  } //vm_enumerate_static_fields
 
 
-// This is the main function used to enumerate Java references by the VM and the JITs.  
-// It is part of the JIT-VM interface.
 // 20030405 Note: When compressing references, vm_enumerate_root_reference() expects to be
called with slots
 // containing *managed* refs (represented by heap_base if null, not 0/NULL), so those refs
must not be NULL. 
+#ifdef _DEBUG
 static void check_ref(void** ref)
 {
     if (VM_Global_State::loader_env->compress_references) {
@@ -156,6 +155,7 @@
         } 
     }
 }
+#endif // _DEBUG
 
 void 
 vm_enumerate_root_reference(void **ref, Boolean is_pinned)

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=543106&r1=543105&r2=543106
==============================================================================
--- 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 May 31 03:33:19 2007
@@ -195,7 +195,7 @@
             return false;
         }
         
-        ClassLoader loader = VMClassRegistry.getClassLoader(this);
+        ClassLoader loader = getClassLoaderImpl();
         if (loader == null) {
             // system class, status is controlled via cmdline only
             return VMExecutionEngine.getAssertionStatus(this, true, 0) > 0;
@@ -285,7 +285,7 @@
      * @com.intel.drl.spec_ref
      */
     public ClassLoader getClassLoader() {
-        ClassLoader loader = VMClassRegistry.getClassLoader(this);
+        ClassLoader loader = getClassLoaderImpl();
         SecurityManager sc = System.getSecurityManager();
         if (sc != null) {
             ClassLoader callerLoader = VMClassRegistry.getClassLoader(VMStack
@@ -537,7 +537,7 @@
      * @com.intel.drl.spec_ref
      */
     public Package getPackage() {
-        ClassLoader classLoader = VMClassRegistry.getClassLoader(this);
+        ClassLoader classLoader = getClassLoaderImpl();
         return classLoader == null
             ? ClassLoader.BootstrapLoader.getPackage(getPackageName())
             : classLoader.getPackage(getPackageName());
@@ -567,7 +567,7 @@
      */
     public URL getResource(String resource) {
         resource = getAbsoluteResource(resource);
-        ClassLoader classLoader = VMClassRegistry.getClassLoader(this);
+        ClassLoader classLoader = getClassLoaderImpl();
         return classLoader == null
             ? ClassLoader.getSystemResource(resource)
             : classLoader.getResource(resource);
@@ -578,7 +578,7 @@
      */
     public InputStream getResourceAsStream(String resource) {
         resource = getAbsoluteResource(resource);
-        ClassLoader classLoader = VMClassRegistry.getClassLoader(this);
+        ClassLoader classLoader = getClassLoaderImpl();
         return classLoader == null
             ? ClassLoader.getSystemResourceAsStream(resource)
             : classLoader.getResourceAsStream(resource);
@@ -589,7 +589,7 @@
      */
     public Object[] getSigners() {
         try {
-            Object[] signers = (Object[])VMClassRegistry.getClassLoader(this).classSigners.get(getName());
+            Object[] signers = (Object[])getClassLoaderImpl().classSigners.get(getName());
             return (Object[])signers.clone();
        } catch (NullPointerException e) {
         }
@@ -866,7 +866,8 @@
     /* VMI SPECIFIC PART*/
 
     final ClassLoader getClassLoaderImpl() {
-        return VMClassRegistry.getClassLoader(this);
+        assert(VMClassRegistry.getClassLoader0(this) == definingLoader);
+        return definingLoader;
     }
 
     static final Class[] getStackClasses(int maxDepth, 
@@ -1160,7 +1161,12 @@
         return VMClassRegistry.getSimpleName(this);
     }
 
-    protected ClassLoader definingLoader;
+    /**
+     * Provides strong referencing between the classloader 
+     * and it's defined classes. Intended for class unloading implementation.
+     * @see java.lang.ClassLoader#loadedClasses
+     */
+    ClassLoader definingLoader;
 
     private final class ReflectionData {
         

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=543106&r1=543105&r2=543106
==============================================================================
--- 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 May 31 03:33:19 2007
@@ -106,11 +106,13 @@
      */
     private final HashMap<String, Package> definedPackages;
 
-    /*
-    * The following mapping is used <String binaryClassName, Class clazz>, where binaryClassName
- class name,
-    * clazz - corresponding class.
-    */
-    Hashtable<String, Class> loadedClasses = new Hashtable<String, Class>();

+    /**
+     * The class registry, provides strong referencing between the classloader 
+     * and it's defined classes. Intended for class unloading implementation.
+     * @see java.lang.Class#definingLoader
+     * @see #registerLoadedClass()
+     */
+    private ArrayList<Class> loadedClasses = new ArrayList<Class>(); 
 
     /**
      * package private to access from the java.lang.Class class. The following
@@ -377,12 +379,15 @@
     }
 
     /**
-     * @com.intel.drl.spec_ref
+     * Registers the defined class, invoked by VM.
+     * Intended for class unloading implementation.
      */
-    public void addToLoadedClasses(String name, Class clazz) {
+    @SuppressWarnings("unused") 
+    private void registerLoadedClass(Class<?> clazz) {
         synchronized (loadedClasses){
-            loadedClasses.put(name, clazz); 
+            loadedClasses.add(clazz); 
     	}
+        clazz.definingLoader = this;
     }
 
     /**
@@ -430,7 +435,6 @@
             certs = getCertificates(packageName, domain.getCodeSource());
         }
         Class<?> clazz = defineClass0(name, data, offset, len);
-        clazz.definingLoader = this;
         clazz.setProtectionDomain(domain);
         if (certs != null) {
             packageCertificates.put(packageName, certs);
@@ -595,7 +599,7 @@
     protected final void setSigners(Class<?> clazz, Object[] signers) {
         checkInitialized();
         String name = clazz.getName();
-        ClassLoader classLoader = VMClassRegistry.getClassLoader(clazz);
+        ClassLoader classLoader = clazz.getClassLoaderImpl();
         if (classLoader != null) {
             if (classLoader.classSigners == null) {
                 classLoader.classSigners = new Hashtable<String, Object[]>();
@@ -794,7 +798,7 @@
     
     static final ClassLoader getStackClassLoader(int depth) {
         Class<?> clazz = VMStack.getCallerClass(depth);
-        return clazz != null ? VMClassRegistry.getClassLoader(clazz) : null;
+        return clazz != null ? clazz.getClassLoaderImpl() : null;
     }
     
     final boolean  isSystemClassLoader () {

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=543106&r1=543105&r2=543106
==============================================================================
--- 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 May 31 03:33:19 2007
@@ -114,8 +114,11 @@
      * @api2vm
      */
     static ClassLoader getClassLoader(Class<?> clazz) {
-        return clazz != null ? getClassLoader0(clazz)
-            : Thread.currentThread().getContextClassLoader();
+        if (clazz != null) {
+            assert(getClassLoader0(clazz) == clazz.definingLoader);
+            return clazz.definingLoader;
+        }
+        return Thread.currentThread().getContextClassLoader();
     }
 
     /**

Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/javasrc/org/apache/harmony/vm/VMStack.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/javasrc/org/apache/harmony/vm/VMStack.java?view=diff&rev=543106&r1=543105&r2=543106
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/javasrc/org/apache/harmony/vm/VMStack.java
(original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/javasrc/org/apache/harmony/vm/VMStack.java
Thu May 31 03:33:19 2007
@@ -109,30 +109,5 @@
      */
     public static native StackTraceElement[] getStackTrace(Object state);
     
-    /**
-     * This method does exactly the same things as the
-     * {@link VMClassRegistry#getClassLoader(Class)
-     * VMClassRegistry.getClassLoader(Class clazz)} method. It has package
-     * visibility only. So it can be used by other classes in this package to
-     * to get class loader with out security checks.
-     * 
-     * @param clazz class to get class loader for.
-     * @return class loader for the specified class.
-     * @api2vm
-     */
-    static ClassLoader getClassLoader(Class<?> clazz) {
-        return clazz != null ? getClassLoader0(clazz)
-           : Thread.currentThread().getContextClassLoader();
-    }
-
-
-    /**
-     * This method satisfies the requirements of the specification for the
-     * {@link Class#getClassLoader() Class.getClassLoader()} method.
-     * 
-     * @api2vm
-     */
-    static native ClassLoader getClassLoader0(Class<?> clazz);
-
     public static native StackTraceElement[] getThreadStackTrace(Thread t);
 }



Mime
View raw message