Merged branch subtype-trunk into default.
[cacao.git] / src / native / vm / gnuclasspath / sun_reflect_ConstantPool.cpp
index 8ec93342cd0dbb872d9e3b262df0da3b3de216e3..b811d6068dca24d65060697de33a1f9a57f3d283 100644 (file)
 #include <assert.h>
 #include <stdint.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"
 
 // FIXME
 //#include "native/include/sun_reflect_ConstantPool.h"
 
 #include "native/vm/reflection.hpp"
 
-#include "toolbox/logging.h"
+#include "toolbox/logging.hpp"
 
-#include "vm/vm.hpp"
+#include "vm/class.hpp"
 #include "vm/exceptions.hpp"
-#include "vm/resolve.h"
+#include "vm/javaobjects.hpp"
+#include "vm/resolve.hpp"
 #include "vm/string.hpp"
-
-#include "vmcore/class.h"
-#include "vmcore/javaobjects.hpp"
-#include "vmcore/utf8.h"
+#include "vm/utf8.h"
+#include "vm/vm.hpp"
 
 
+// Native functions are exported as C functions.
 extern "C" {
 
 /*
@@ -149,7 +149,9 @@ JNIEXPORT jobject JNICALL Java_sun_reflect_ConstantPool_getMethodAt0(JNIEnv *env
        }
 
        /* XXX: is that right? or do I have to use resolve_method_*? */
-       return (jobject) java_lang_reflect_Method::create(ref->p.method);
+       java_lang_reflect_Method jlrm(ref->p.method);
+
+       return (jobject) jlrm.get_handle();
 }
 
 
@@ -180,7 +182,9 @@ JNIEXPORT jobject JNICALL Java_sun_reflect_ConstantPool_getMethodAtIfLoaded0(JNI
                return NULL;
        }
 
-       return (jobject) java_lang_reflect_Method::create(ref->p.method);
+       java_lang_reflect_Method jlrm(ref->p.method);
+
+       return (jobject) jlrm.get_handle();
 }
 
 
@@ -194,15 +198,17 @@ JNIEXPORT jobject JNICALL Java_sun_reflect_ConstantPool_getFieldAt0(JNIEnv *env,
        constant_FMIref *ref;
        classinfo *cls = LLNI_classinfo_unwrap(jcpool);
 
-       ref = (constant_FMIref*)class_getconstant(
-               cls, index, CONSTANT_Fieldref);
+       ref = (constant_FMIref*) class_getconstant(cls, index, CONSTANT_Fieldref);
 
        if (ref == NULL) {
                exceptions_throw_illegalargumentexception();
                return NULL;
        }
 
-       return (jobject) java_lang_reflect_Field::create(ref->p.field);
+       // Create a new java.lang.reflect.Field Java object.
+       java_lang_reflect_Field jlrf(ref->p.field);
+
+       return (jobject) jlrf.get_handle();
 }
 
 
@@ -217,8 +223,7 @@ JNIEXPORT jobject JNICALL Java_sun_reflect_ConstantPool_getFieldAtIfLoaded0(JNIE
        classinfo *c;
        classinfo *cls = LLNI_classinfo_unwrap(jcpool);
 
-       ref = (constant_FMIref*)class_getconstant(
-               cls, index, CONSTANT_Fieldref);
+       ref = (constant_FMIref*) class_getconstant(cls, index, CONSTANT_Fieldref);
 
        if (ref == NULL) {
                exceptions_throw_illegalargumentexception();
@@ -233,7 +238,10 @@ JNIEXPORT jobject JNICALL Java_sun_reflect_ConstantPool_getFieldAtIfLoaded0(JNIE
                return NULL;
        }
 
-       return (jobject) java_lang_reflect_Field::create(ref->p.field);
+       // Create a new java.lang.reflect.Field Java object.
+       java_lang_reflect_Field jlrf(ref->p.field);
+
+       return (jobject) jlrf.get_handle();
 }
 
 
@@ -259,8 +267,7 @@ JNIEXPORT jint JNICALL Java_sun_reflect_ConstantPool_getIntAt0(JNIEnv *env, jobj
        constant_integer *ref;
        classinfo *cls = LLNI_classinfo_unwrap(jcpool);
 
-       ref = (constant_integer*)class_getconstant(
-               cls, index, CONSTANT_Integer);
+       ref = (constant_integer*) class_getconstant(cls, index, CONSTANT_Integer);
 
        if (ref == NULL) {
                exceptions_throw_illegalargumentexception();
@@ -409,12 +416,12 @@ static JNINativeMethod methods[] = {
 
 *******************************************************************************/
 
-// FIXME
-extern "C" {
 void _Jv_sun_reflect_ConstantPool_init(void)
 {
-       native_method_register(utf_new_char("sun/reflect/ConstantPool"), methods, NATIVE_METHODS_COUNT);
-}
+       utf* u = utf_new_char("sun/reflect/ConstantPool");
+
+       NativeMethods& nm = VM::get_current()->get_nativemethods();
+       nm.register_methods(u, methods, NATIVE_METHODS_COUNT);
 }