* src/vmcore/class.c (class_define): New function.
authortwisti <none@none>
Thu, 7 Jun 2007 23:30:45 +0000 (23:30 +0000)
committertwisti <none@none>
Thu, 7 Jun 2007 23:30:45 +0000 (23:30 +0000)
* src/vmcore/class.h (class_define): Added.

* src/native/vm/java_lang_ClassLoader.c (defineClass): Use
class_define.

src/native/vm/java_lang_ClassLoader.c
src/vmcore/class.c
src/vmcore/class.h

index 95cda7fae864b001f8340a6c282b549e48074ba1..b3480e1b9c9aafadb3e7003b0b07d3f5b960d80e 100644 (file)
@@ -71,9 +71,7 @@ java_lang_Class *_Jv_java_lang_ClassLoader_defineClass(java_lang_ClassLoader *cl
        java_objectheader *loader;
        utf               *utfname;
        classinfo         *c;
-       classinfo         *r;
-       classbuffer       *cb;
-       java_lang_Class   *co;
+       java_lang_Class   *o;
 #if defined(ENABLE_JVMTI)
        jint new_class_data_len = 0;
        unsigned char* new_class_data = NULL;
@@ -99,15 +97,6 @@ java_lang_Class *_Jv_java_lang_ClassLoader_defineClass(java_lang_ClassLoader *cl
                /* convert '.' to '/' in java string */
 
                utfname = javastring_toutf((java_objectheader *) name, true);
-               
-               /* check if this class has already been defined */
-
-               c = classcache_lookup_defined_or_initiated(loader, utfname);
-
-               if (c != NULL) {
-                       exceptions_throw_linkageerror("duplicate class definition: ", c);
-                       return NULL;
-               }
        } 
        else {
                utfname = NULL;
@@ -122,82 +111,27 @@ java_lang_Class *_Jv_java_lang_ClassLoader_defineClass(java_lang_ClassLoader *cl
                                                                &new_class_data_len, &new_class_data);
 #endif
 
-       /* create a new classinfo struct */
-
-       c = class_create_classinfo(utfname);
-
-#if defined(ENABLE_STATISTICS)
-       /* measure time */
-
-       if (opt_getloadingtime)
-               loadingtime_start();
-#endif
+       /* define the class */
 
-       /* build a classbuffer with the given data */
-
-       cb = NEW(classbuffer);
-       cb->class = c;
 #if defined(ENABLE_JVMTI)
        /* check if the JVMTI wants to modify the class */
-       if (new_class_data == NULL) {
-#endif
-       cb->size  = len;
-       cb->data  = (u1 *) &data->data[offset];
-#if defined(ENABLE_JVMTI)
-       } else {
-               cb->size  = new_class_data_len;
-               cb->data  = (u1 *) new_class_data;
-       }
-#endif
-       cb->pos   = cb->data;
-
-       /* preset the defining classloader */
 
-       c->classloader = loader;
-
-       /* load the class from this buffer */
-
-       r = load_class_from_classbuffer(cb);
-
-       /* free memory */
-
-       FREE(cb, classbuffer);
-
-#if defined(ENABLE_STATISTICS)
-       /* measure time */
-
-       if (opt_getloadingtime)
-               loadingtime_stop();
+       if (new_class_data == NULL)
+               c = class_define(utfname, loader, new_class_data_len, new_class_data); 
+       else
 #endif
+               c = class_define(utfname, loader, len, (u1 *) &data->data[offset]); 
 
-       if (r == NULL) {
-               /* If return value is NULL, we had a problem and the class is
-                  not loaded.  Now free the allocated memory, otherwise we
-                  could run into a DOS. */
-
-               class_free(c);
-
+       if (c == NULL)
                return NULL;
-       }
 
        /* set ProtectionDomain */
 
-       co = (java_lang_Class *) c;
-
-       co->pd = pd;
-
-       /* Store the newly defined class in the class cache. This call also       */
-       /* checks whether a class of the same name has already been defined by    */
-       /* the same defining loader, and if so, replaces the newly created class  */
-       /* by the one defined earlier.                                            */
-       /* Important: The classinfo given to classcache_store must be             */
-       /*            fully prepared because another thread may return this       */
-       /*            pointer after the lookup at to top of this function         */
-       /*            directly after the class cache lock has been released.      */
+       o = (java_lang_Class *) c;
 
-       c = classcache_store(loader, c, true);
+       o->pd = pd;
 
-       return (java_lang_Class *) c;
+       return o;
 }
 
 
index 3d29b5e0427cc98981b40064e7d339b4fe75b4e2..4be4c7438401bfabf0383d4459bfe57ce38d77bc 100644 (file)
@@ -22,7 +22,7 @@
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301, USA.
 
-   $Id: class.c 8042 2007-06-07 17:43:29Z twisti $
+   $Id: class.c 8049 2007-06-07 23:30:45Z twisti $
 
 */
 
@@ -278,6 +278,94 @@ void class_postset_header_vftbl(void)
        }
 }
 
+/* class_define ****************************************************************
+
+   Calls the loader and defines a class in the VM.
+
+*******************************************************************************/
+
+classinfo *class_define(utf *name, java_objectheader *cl, s4 length, u1 *data)
+{
+       classinfo   *c;
+       classinfo   *r;
+       classbuffer *cb;
+
+       if (name != NULL) {
+               /* check if this class has already been defined */
+
+               c = classcache_lookup_defined_or_initiated(cl, name);
+
+               if (c != NULL) {
+                       exceptions_throw_linkageerror("duplicate class definition: ", c);
+                       return NULL;
+               }
+       } 
+
+       /* create a new classinfo struct */
+
+       c = class_create_classinfo(name);
+
+#if defined(ENABLE_STATISTICS)
+       /* measure time */
+
+       if (opt_getloadingtime)
+               loadingtime_start();
+#endif
+
+       /* build a classbuffer with the given data */
+
+       cb = NEW(classbuffer);
+
+       cb->class = c;
+       cb->size  = length;
+       cb->data  = data;
+       cb->pos   = cb->data;
+
+       /* preset the defining classloader */
+
+       c->classloader = cl;
+
+       /* load the class from this buffer */
+
+       r = load_class_from_classbuffer(cb);
+
+       /* free memory */
+
+       FREE(cb, classbuffer);
+
+#if defined(ENABLE_STATISTICS)
+       /* measure time */
+
+       if (opt_getloadingtime)
+               loadingtime_stop();
+#endif
+
+       if (r == NULL) {
+               /* If return value is NULL, we had a problem and the class is
+                  not loaded.  Now free the allocated memory, otherwise we
+                  could run into a DOS. */
+
+               class_free(c);
+
+               return NULL;
+       }
+
+       /* Store the newly defined class in the class cache. This call
+          also checks whether a class of the same name has already been
+          defined by the same defining loader, and if so, replaces the
+          newly created class by the one defined earlier. */
+
+       /* Important: The classinfo given to classcache_store must be
+                     fully prepared because another thread may return
+                     this pointer after the lookup at to top of this
+                     function directly after the class cache lock has
+                     been released. */
+
+       c = classcache_store(cl, c, true);
+
+       return c;
+}
+
 
 /* class_load_attribute_sourcefile *********************************************
 
index 769d63c3f51c178663254e91b68db329fd672324..8f32e13026e493733eabb833751370d882ad943c 100644 (file)
@@ -22,7 +22,7 @@
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301, USA.
 
-   $Id: class.h 8042 2007-06-07 17:43:29Z twisti $
+   $Id: class.h 8049 2007-06-07 23:30:45Z twisti $
 
 */
 
@@ -284,6 +284,8 @@ classinfo *class_create_classinfo(utf *u);
 /* postset's the header.vftbl */
 void class_postset_header_vftbl(void);
 
+classinfo *class_define(utf *name, java_objectheader *cl, s4 length, u1 *data);
+
 /* set the package name after the name has been set */
 void class_set_packagename(classinfo *c);