* src/vm/array.hpp: Implemented array access classes in C++.
[cacao.git] / src / native / vm / gnuclasspath / java_lang_VMClassLoader.cpp
index 6acc53b5f3641dfff76cbc6f2043de54688d54cd..b67c8bc9ef48de663bc5034d189a81006380e26e 100644 (file)
 #include <stdint.h>
 #include <sys/stat.h>
 
-#include "mm/memory.h"
+#include "mm/memory.hpp"
 
-#include "native/jni.h"
+#include "native/jni.hpp"
 #include "native/llni.h"
-#include "native/native.h"
+#include "native/native.hpp"
 
 #if defined(ENABLE_JNI_HEADERS)
 # include "native/vm/include/java_lang_VMClassLoader.h"
 #endif
 
-#include "toolbox/logging.h"
-#include "toolbox/list.h"
+#include "toolbox/logging.hpp"
+#include "toolbox/list.hpp"
 
 #if defined(ENABLE_ASSERTION)
-#include "vm/assertion.h"
+#include "vm/assertion.hpp"
 #endif
 
-#include "vm/builtin.h"
-#include "vm/class.h"
-#include "vm/classcache.h"
+#include "vm/array.hpp"
+#include "vm/jit/builtin.hpp"
+#include "vm/class.hpp"
+#include "vm/classcache.hpp"
 #include "vm/exceptions.hpp"
 #include "vm/globals.hpp"
-#include "vm/initialize.h"
+#include "vm/initialize.hpp"
 #include "vm/javaobjects.hpp"
-#include "vm/linker.h"
-#include "vm/loader.h"
+#include "vm/linker.hpp"
+#include "vm/loader.hpp"
 #include "vm/options.h"
 #include "vm/primitive.hpp"
 #include "vm/statistics.h"
 #include "vm/string.hpp"
-#include "vm/suck.h"
 #include "vm/vm.hpp"
-#include "vm/zip.h"
+#include "vm/zip.hpp"
 
 #include "vm/jit/asmpart.h"
 
@@ -80,11 +80,10 @@ extern "C" {
  */
 JNIEXPORT jclass JNICALL Java_java_lang_VMClassLoader_defineClass(JNIEnv *env, jclass clazz, jobject cl, jstring name, jbyteArray data, jint offset, jint len, jobject pd)
 {
-       utf             *utfname;
-       classinfo       *c;
-       classloader_t   *loader;
-       java_handle_bytearray_t* ba;
-       uint8_t*                 stream;
+       utf*           utfname;
+       classinfo*     c;
+       classloader_t* loader;
+       uint8_t*       stream;
 
 #if defined(ENABLE_JVMTI)
        jint new_class_data_len = 0;
@@ -100,7 +99,9 @@ JNIEXPORT jclass JNICALL Java_java_lang_VMClassLoader_defineClass(JNIEnv *env, j
 
        /* check the indexes passed */
 
-       if ((offset < 0) || (len < 0) || ((offset + len) > LLNI_array_size(data))) {
+       ByteArray ba(data);
+
+       if ((offset < 0) || (len < 0) || ((offset + len) > ba.get_length())) {
                exceptions_throw_arrayindexoutofboundsexception();
                return NULL;
        }
@@ -139,8 +140,7 @@ JNIEXPORT jclass JNICALL Java_java_lang_VMClassLoader_defineClass(JNIEnv *env, j
        else
 #endif
        {
-               ba = (java_handle_bytearray_t*) data;
-               stream = (uint8_t *) &LLNI_array_direct(ba, offset);
+               stream = ((uint8_t *) ba.get_raw_data_ptr()) + offset;
                c = class_define(utfname, loader, len, stream, (java_handle_t *) pd);
        }
 
@@ -249,7 +249,6 @@ JNIEXPORT jobject JNICALL Java_java_lang_VMClassLoader_nativeGetResources(JNIEnv
        java_handle_t        *o;         /* vector being created     */
        methodinfo           *m;         /* "add" method of vector   */
        java_handle_t        *path;      /* path to be added         */
-       list_classpath_entry *lce;       /* classpath entry          */
        utf                  *utfname;   /* utf to look for          */
        char                 *buffer;    /* char buffer              */
        char                 *namestart; /* start of name to use     */
@@ -320,8 +319,9 @@ JNIEXPORT jobject JNICALL Java_java_lang_VMClassLoader_nativeGetResources(JNIEnv
 
        /* iterate over all classpath entries */
 
-       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;
+
                /* clear path pointer */
                path = NULL;
 
@@ -422,7 +422,6 @@ JNIEXPORT jobject JNICALL Java_java_lang_VMClassLoader_packageAssertionStatus0(J
 #if defined(ENABLE_ASSERTION)
        java_handle_t     *js;
        methodinfo        *m;
-       assertion_name_t  *item;
 #endif
 
        /* new HashMap() */
@@ -451,13 +450,11 @@ JNIEXPORT jobject JNICALL Java_java_lang_VMClassLoader_packageAssertionStatus0(J
                return NULL;
        }
 
-       item = (assertion_name_t *)list_first(list_assertion_names);
+       for (List<assertion_name_t*>::iterator it = list_assertion_names->begin(); it != list_assertion_names->end(); it++) {
+               assertion_name_t* item = *it;
 
-       while (item != NULL) {
-               if (item->package == false) {
-                       item = (assertion_name_t *)list_next(list_assertion_names, item);
+               if (item->package == false)
                        continue;
-               }
                
                if (strcmp(item->name, "") == 0) {
                        /* unnamed package wanted */
@@ -476,8 +473,6 @@ JNIEXPORT jobject JNICALL Java_java_lang_VMClassLoader_packageAssertionStatus0(J
                else {
                        vm_call_method(m, hm, js, jfalse);
                }
-
-               item = (assertion_name_t *)list_next(list_assertion_names, item);
        }
 #endif
 
@@ -495,7 +490,6 @@ JNIEXPORT jobject JNICALL Java_java_lang_VMClassLoader_classAssertionStatus0(JNI
 #if defined(ENABLE_ASSERTION)
        java_handle_t     *js;
        methodinfo        *m;
-       assertion_name_t  *item;
 #endif
 
        /* new HashMap() */
@@ -524,13 +518,11 @@ JNIEXPORT jobject JNICALL Java_java_lang_VMClassLoader_classAssertionStatus0(JNI
                return NULL;
        }
 
-       item = (assertion_name_t *)list_first(list_assertion_names);
+       for (List<assertion_name_t*>::iterator it = list_assertion_names->begin(); it != list_assertion_names->end(); it++) {
+               assertion_name_t* item = *it;
 
-       while (item != NULL) {
-               if (item->package == true) {
-                       item = (assertion_name_t *)list_next(list_assertion_names, item);
+               if (item->package == true)
                        continue;
-               }
 
                js = javastring_new_from_ascii(item->name);
                if (js == NULL) {
@@ -543,8 +535,6 @@ JNIEXPORT jobject JNICALL Java_java_lang_VMClassLoader_classAssertionStatus0(JNI
                else {
                        vm_call_method(m, hm, js, jfalse);
                }
-
-               item = (assertion_name_t *)list_next(list_assertion_names, item);
        }
 #endif
 
@@ -608,16 +598,12 @@ static JNINativeMethod methods[] = {
 
 *******************************************************************************/
 
-// FIXME
-extern "C" {
 void _Jv_java_lang_VMClassLoader_init(void)
 {
-       utf *u;
+       utf* u = utf_new_char("java/lang/VMClassLoader");
 
-       u = utf_new_char("java/lang/VMClassLoader");
-
-       native_method_register(u, methods, NATIVE_METHODS_COUNT);
-}
+       NativeMethods& nm = VM::get_current()->get_nativemethods();
+       nm.register_methods(u, methods, NATIVE_METHODS_COUNT);
 }