* src/vm/annotation.c: Moved to C++.
[cacao.git] / src / vm / loader.cpp
index b2dcab6f97e48eee7f481d2b44041c471663aab6..7bc8ff4a177568738f2648857c824ef74c470099 100644 (file)
 
 #include "vm/types.h"
 
-#include "mm/memory.h"
+#include "mm/dumpmemory.hpp"
+#include "mm/memory.hpp"
 
 #include "native/llni.h"
 
-#include "threads/lock-common.h"
 #include "threads/mutex.hpp"
 
 #include "toolbox/hashtable.h"
-#include "toolbox/logging.h"
+#include "toolbox/logging.hpp"
 
 #include "vm/jit/builtin.hpp"
-#include "vm/classcache.h"
+#include "vm/classcache.hpp"
 #include "vm/exceptions.hpp"
-#include "vm/field.h"
+#include "vm/field.hpp"
 #include "vm/global.h"
 #include "vm/globals.hpp"
-#include "vm/linker.h"
+#include "vm/linker.hpp"
 #include "vm/loader.hpp"
-#include "vm/method.h"
+#include "vm/method.hpp"
 #include "vm/options.h"
 #include "vm/package.hpp"
 #include "vm/primitive.hpp"
-#include "vm/resolve.h"
+#include "vm/resolve.hpp"
 #include "vm/rt-timing.h"
 #include "vm/string.hpp"
-#include "vm/suck.h"
+#include "vm/suck.hpp"
 #include "vm/vm.hpp"
 
 
 #if defined(ENABLE_JAVASE)
-# include "vm/annotation.h"
+# include "vm/annotation.hpp"
 # include "vm/stackmap.h"
 #endif
 
@@ -70,7 +70,7 @@
 #endif
 
 #if defined(ENABLE_ZLIB)
-# include "vm/zip.h"
+# include "vm/zip.hpp"
 #endif
 
 #include "vm/jit/stubs.hpp"
@@ -97,19 +97,16 @@ static hashtable *hashtable_classloader;
  
 void loader_preinit(void)
 {
-#if defined(ENABLE_THREADS)
-       list_classpath_entry *lce;
-#endif
-
        TRACESUBSYSTEMINITIALIZATION("loader_preinit");
 
 #if defined(ENABLE_THREADS)
        /* Initialize the monitor pointer for zip/jar file locking. */
 
-       for (lce = (list_classpath_entry*) list_first(list_classpath_entries); lce != NULL;
-                lce = (list_classpath_entry*) list_next(list_classpath_entries, lce)) {
+       for (List<list_classpath_entry*>::iterator it = list_classpath_entries->begin(); it != list_classpath_entries->end(); it++) {
+               list_classpath_entry* lce = *it;
+
                if (lce->type == CLASSPATH_ARCHIVE)
-                       LOCK_INIT_OBJECT_LOCK(lce);
+                       lce->mutex = new Mutex();
        }
 #endif
 
@@ -395,15 +392,15 @@ classloader_t *loader_hashtable_classloader_find(java_handle_t *cl)
 
 void loader_load_all_classes(void)
 {
-       list_classpath_entry    *lce;
 #if defined(ENABLE_ZLIB)
        hashtable               *ht;
        hashtable_zipfile_entry *htzfe;
        utf                     *u;
 #endif
 
-       for (lce = (list_classpath_entry*) list_first(list_classpath_entries); lce != NULL;
-                lce = (list_classpath_entry*) list_next(list_classpath_entries, lce)) {
+       for (List<list_classpath_entry*>::iterator it = list_classpath_entries->begin(); it != list_classpath_entries->end(); it++) {
+               list_classpath_entry* lce = *it;
+
 #if defined(ENABLE_ZLIB)
                if (lce->type == CLASSPATH_ARCHIVE) {
                        /* get the classes hashtable */
@@ -589,7 +586,8 @@ static bool load_constantpool(classbuffer *cb, descriptor_pool *descpool)
 
                switch (t) {
                case CONSTANT_Class:
-                       nfc = DNEW(forward_class);
+#warning Use list.
+                       nfc = (forward_class*) DumpMemory::allocate(sizeof(forward_class));
 
                        nfc->next = forward_classes;
                        forward_classes = nfc;
@@ -605,7 +603,8 @@ static bool load_constantpool(classbuffer *cb, descriptor_pool *descpool)
                        break;
                        
                case CONSTANT_String:
-                       nfs = DNEW(forward_string);
+#warning Use list.
+                       nfs = (forward_string*) DumpMemory::allocate(sizeof(forward_string));
                                
                        nfs->next = forward_strings;
                        forward_strings = nfs;
@@ -622,7 +621,8 @@ static bool load_constantpool(classbuffer *cb, descriptor_pool *descpool)
                        break;
 
                case CONSTANT_NameAndType:
-                       nfn = DNEW(forward_nameandtype);
+#warning Use list.
+                       nfn = (forward_nameandtype*) DumpMemory::allocate(sizeof(forward_nameandtype));
                                
                        nfn->next = forward_nameandtypes;
                        forward_nameandtypes = nfn;
@@ -645,7 +645,8 @@ static bool load_constantpool(classbuffer *cb, descriptor_pool *descpool)
                case CONSTANT_Fieldref:
                case CONSTANT_Methodref:
                case CONSTANT_InterfaceMethodref:
-                       nff = DNEW(forward_fieldmethint);
+#warning Use list.
+                       nff = (forward_fieldmethint*) DumpMemory::allocate(sizeof(forward_fieldmethint));
                        
                        nff->next = forward_fieldmethints;
                        forward_fieldmethints = nff;
@@ -1397,6 +1398,9 @@ static bool load_class_from_classbuffer_intern(classbuffer *cb)
                                        time_parsecpool, time_verify, time_attrs;
 #endif
 
+       // Create new dump memory area.
+       DumpMemoryArea dma;
+
        RT_TIMING_GET_TIME(time_start);
 
        /* Get the classbuffer's class. */
@@ -1557,7 +1561,7 @@ static bool load_class_from_classbuffer_intern(classbuffer *cb)
 
        /* Get the names of the super interfaces. */
 
-       interfacesnames = DMNEW(utf*, c->interfacescount);
+       interfacesnames = (utf**) DumpMemory::allocate(sizeof(utf*) * c->interfacescount);
 
        for (int32_t i = 0; i < c->interfacescount; i++) {
                index = suck_u2(cb);
@@ -1946,7 +1950,6 @@ classinfo *load_class_from_classbuffer(classbuffer *cb)
 {
        classinfo *c;
        bool       result;
-       int32_t    dumpmarker;
 
        /* Get the classbuffer's class. */
 
@@ -1967,10 +1970,6 @@ classinfo *load_class_from_classbuffer(classbuffer *cb)
                log_message_class("Loading class: ", c);
 #endif
 
-       /* Mark start of dump memory area. */
-
-       DMARKER;
-
        /* Class is currently loading. */
 
        c->state |= CLASS_LOADING;
@@ -1979,10 +1978,6 @@ classinfo *load_class_from_classbuffer(classbuffer *cb)
 
        result = load_class_from_classbuffer_intern(cb);
 
-       /* Release dump area. */
-
-       DRELEASE;
-
        /* An error occurred. */
 
        if (result == false) {