#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/include/java_lang_Object.h"
-#include "native/include/java_lang_Class.h"
+#include "native/native.hpp"
// FIXME
-extern "C" {
-#include "native/include/sun_reflect_ConstantPool.h"
-}
-
-#include "native/vm/reflect.h"
-
-#include "toolbox/logging.h"
-
-#include "vm/vm.h"
-#include "vm/exceptions.h"
-#include "vm/resolve.h"
-#include "vm/stringlocal.h"
-
-#include "vmcore/class.h"
-#include "vmcore/utf8.h"
-
-
-/* native methods implemented by this file ************************************/
-
-static JNINativeMethod methods[] = {
- { (char*) "getSize0", (char*) "(Ljava/lang/Object;I)I", (void*) (uintptr_t) &Java_sun_reflect_ConstantPool_getSize0 },
- { (char*) "getClassAt0", (char*) "(Ljava/lang/Object;I)Ljava/lang/Class;", (void*) (uintptr_t) &Java_sun_reflect_ConstantPool_getClassAt0 },
- { (char*) "getClassAtIfLoaded0", (char*) "(Ljava/lang/Object;I)Ljava/lang/Class;", (void*) (uintptr_t) &Java_sun_reflect_ConstantPool_getClassAtIfLoaded0 },
- { (char*) "getMethodAt0", (char*) "(Ljava/lang/Object;I)Ljava/lang/reflect/Member;", (void*) (uintptr_t) &Java_sun_reflect_ConstantPool_getMethodAt0 },
- { (char*) "getMethodAtIfLoaded0", (char*) "(Ljava/lang/Object;I)Ljava/lang/reflect/Member;", (void*) (uintptr_t) &Java_sun_reflect_ConstantPool_getMethodAtIfLoaded0 },
- { (char*) "getFieldAt0", (char*) "(Ljava/lang/Object;I)Ljava/lang/reflect/Field;", (void*) (uintptr_t) &Java_sun_reflect_ConstantPool_getFieldAt0 },
- { (char*) "getFieldAtIfLoaded0", (char*) "(Ljava/lang/Object;I)Ljava/lang/reflect/Field;", (void*) (uintptr_t) &Java_sun_reflect_ConstantPool_getFieldAtIfLoaded0 },
- { (char*) "getMemberRefInfoAt0", (char*) "(Ljava/lang/Object;I)[Ljava/lang/String;", (void*) (uintptr_t) &Java_sun_reflect_ConstantPool_getMemberRefInfoAt0 },
- { (char*) "getIntAt0", (char*) "(Ljava/lang/Object;I)I", (void*) (uintptr_t) &Java_sun_reflect_ConstantPool_getIntAt0 },
- { (char*) "getLongAt0", (char*) "(Ljava/lang/Object;I)J", (void*) (uintptr_t) &Java_sun_reflect_ConstantPool_getLongAt0 },
- { (char*) "getFloatAt0", (char*) "(Ljava/lang/Object;I)F", (void*) (uintptr_t) &Java_sun_reflect_ConstantPool_getFloatAt0 },
- { (char*) "getDoubleAt0", (char*) "(Ljava/lang/Object;I)D", (void*) (uintptr_t) &Java_sun_reflect_ConstantPool_getDoubleAt0 },
- { (char*) "getStringAt0", (char*) "(Ljava/lang/Object;I)Ljava/lang/String;", (void*) (uintptr_t) &Java_sun_reflect_ConstantPool_getStringAt0 },
- { (char*) "getUTF8At0", (char*) "(Ljava/lang/Object;I)Ljava/lang/String;", (void*) (uintptr_t) &Java_sun_reflect_ConstantPool_getUTF8At0 },
-};
+//#include "native/include/sun_reflect_ConstantPool.h"
+#include "native/vm/reflection.hpp"
-/* _Jv_sun_reflect_ConstantPool_init ******************************************
+#include "toolbox/logging.hpp"
- Register native functions.
-
-*******************************************************************************/
-
-// FIXME
-extern "C" {
-void _Jv_sun_reflect_ConstantPool_init(void)
-{
- native_method_register(utf_new_char("sun/reflect/ConstantPool"), methods, NATIVE_METHODS_COUNT);
-}
-}
+#include "vm/class.hpp"
+#include "vm/exceptions.hpp"
+#include "vm/javaobjects.hpp"
+#include "vm/resolve.hpp"
+#include "vm/string.hpp"
+#include "vm/utf8.h"
+#include "vm/vm.hpp"
+// Native functions are exported as C functions.
extern "C" {
/*
* Method: getSize0
* Signature: (Ljava/lang/Object;)I
*/
-JNIEXPORT int32_t JNICALL Java_sun_reflect_ConstantPool_getSize0(JNIEnv *env, struct sun_reflect_ConstantPool* _this, struct java_lang_Object* jcpool)
+JNIEXPORT jint JNICALL Java_sun_reflect_ConstantPool_getSize0(JNIEnv *env, jobject _this, jobject jcpool)
{
classinfo *cls = LLNI_classinfo_unwrap(jcpool);
return cls->cpcount;
* Method: getClassAt0
* Signature: (Ljava/lang/Object;I)Ljava/lang/Class;
*/
-JNIEXPORT struct java_lang_Class* JNICALL Java_sun_reflect_ConstantPool_getClassAt0(JNIEnv *env, struct sun_reflect_ConstantPool* _this, struct java_lang_Object* jcpool, int32_t index)
+JNIEXPORT jclass JNICALL Java_sun_reflect_ConstantPool_getClassAt0(JNIEnv *env, jobject _this, jobject jcpool, jint index)
{
constant_classref *ref;
classinfo *cls = LLNI_classinfo_unwrap(jcpool);
return NULL;
}
- return LLNI_classinfo_wrap(resolve_classref_eager(ref));
+ return (jclass) LLNI_classinfo_wrap(resolve_classref_eager(ref));
}
* Method: getClassAtIfLoaded0
* Signature: (Ljava/lang/Object;I)Ljava/lang/Class;
*/
-JNIEXPORT struct java_lang_Class* JNICALL Java_sun_reflect_ConstantPool_getClassAtIfLoaded0(JNIEnv *env, struct sun_reflect_ConstantPool* _this, struct java_lang_Object* jcpool, int32_t index)
+JNIEXPORT jclass JNICALL Java_sun_reflect_ConstantPool_getClassAtIfLoaded0(JNIEnv *env, jobject _this, jobject jcpool, jint index)
{
constant_classref *ref;
classinfo *c = NULL;
return NULL;
}
- return LLNI_classinfo_wrap(c);
+ return (jclass) LLNI_classinfo_wrap(c);
}
* Method: getMethodAt0
* Signature: (Ljava/lang/Object;I)Ljava/lang/reflect/Member;
*/
-JNIEXPORT struct java_lang_reflect_Member* JNICALL Java_sun_reflect_ConstantPool_getMethodAt0(JNIEnv *env, struct sun_reflect_ConstantPool* _this, struct java_lang_Object* jcpool, int32_t index)
+JNIEXPORT jobject JNICALL Java_sun_reflect_ConstantPool_getMethodAt0(JNIEnv *env, jobject _this, jobject jcpool, jint index)
{
constant_FMIref *ref;
classinfo *cls = LLNI_classinfo_unwrap(jcpool);
}
/* XXX: is that right? or do I have to use resolve_method_*? */
- return (struct java_lang_reflect_Member*) reflect_method_new(ref->p.method);
+ java_lang_reflect_Method jlrm(ref->p.method);
+
+ return (jobject) jlrm.get_handle();
}
* Method: getMethodAtIfLoaded0
* Signature: (Ljava/lang/Object;I)Ljava/lang/reflect/Member;
*/
-JNIEXPORT struct java_lang_reflect_Member* JNICALL Java_sun_reflect_ConstantPool_getMethodAtIfLoaded0(JNIEnv *env, struct sun_reflect_ConstantPool* _this, struct java_lang_Object* jcpool, int32_t index)
+JNIEXPORT jobject JNICALL Java_sun_reflect_ConstantPool_getMethodAtIfLoaded0(JNIEnv *env, jobject _this, jobject jcpool, jint index)
{
constant_FMIref *ref;
classinfo *c = NULL;
return NULL;
}
- return (struct java_lang_reflect_Member*) reflect_method_new(ref->p.method);
+ java_lang_reflect_Method jlrm(ref->p.method);
+
+ return (jobject) jlrm.get_handle();
}
* Method: getFieldAt0
* Signature: (Ljava/lang/Object;I)Ljava/lang/reflect/Field;
*/
-JNIEXPORT struct java_lang_reflect_Field* JNICALL Java_sun_reflect_ConstantPool_getFieldAt0(JNIEnv *env, struct sun_reflect_ConstantPool* _this, struct java_lang_Object* jcpool, int32_t index)
+JNIEXPORT jobject JNICALL Java_sun_reflect_ConstantPool_getFieldAt0(JNIEnv *env, jobject _this, jobject jcpool, jint index)
{
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 (struct java_lang_reflect_Field*) reflect_field_new(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();
}
* Method: getFieldAtIfLoaded0
* Signature: (Ljava/lang/Object;I)Ljava/lang/reflect/Field;
*/
-JNIEXPORT struct java_lang_reflect_Field* JNICALL Java_sun_reflect_ConstantPool_getFieldAtIfLoaded0(JNIEnv *env, struct sun_reflect_ConstantPool* _this, struct java_lang_Object* jcpool, int32_t index)
+JNIEXPORT jobject JNICALL Java_sun_reflect_ConstantPool_getFieldAtIfLoaded0(JNIEnv *env, jobject _this, jobject jcpool, jint index)
{
constant_FMIref *ref;
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();
return NULL;
}
- return (struct java_lang_reflect_Field*) reflect_field_new(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();
}
* Method: getMemberRefInfoAt0
* Signature: (Ljava/lang/Object;I)[Ljava/lang/String;
*/
-JNIEXPORT java_handle_objectarray_t* JNICALL Java_sun_reflect_ConstantPool_getMemberRefInfoAt0(JNIEnv *env, struct sun_reflect_ConstantPool* _this, struct java_lang_Object* jcpool, int32_t index)
+JNIEXPORT jobjectArray JNICALL Java_sun_reflect_ConstantPool_getMemberRefInfoAt0(JNIEnv *env, jobject _this, jobject jcpool, jint index)
{
log_println("Java_sun_reflect_ConstantPool_getMemberRefInfoAt0(env=%p, jcpool=%p, index=%d): IMPLEMENT ME!", env, jcpool, index);
return NULL;
* Method: getIntAt0
* Signature: (Ljava/lang/Object;I)I
*/
-JNIEXPORT int32_t JNICALL Java_sun_reflect_ConstantPool_getIntAt0(JNIEnv *env, struct sun_reflect_ConstantPool* _this, struct java_lang_Object* jcpool, int32_t index)
+JNIEXPORT jint JNICALL Java_sun_reflect_ConstantPool_getIntAt0(JNIEnv *env, jobject _this, jobject jcpool, jint index)
{
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();
* Method: getLongAt0
* Signature: (Ljava/lang/Object;I)J
*/
-JNIEXPORT int64_t JNICALL Java_sun_reflect_ConstantPool_getLongAt0(JNIEnv *env, struct sun_reflect_ConstantPool* _this, struct java_lang_Object* jcpool, int32_t index)
+JNIEXPORT jlong JNICALL Java_sun_reflect_ConstantPool_getLongAt0(JNIEnv *env, jobject _this, jobject jcpool, jint index)
{
constant_long *ref;
classinfo *cls = LLNI_classinfo_unwrap(jcpool);
* Method: getFloatAt0
* Signature: (Ljava/lang/Object;I)F
*/
-JNIEXPORT float JNICALL Java_sun_reflect_ConstantPool_getFloatAt0(JNIEnv *env, struct sun_reflect_ConstantPool* _this, struct java_lang_Object* jcpool, int32_t index)
+JNIEXPORT float JNICALL Java_sun_reflect_ConstantPool_getFloatAt0(JNIEnv *env, jobject _this, jobject jcpool, jint index)
{
constant_float *ref;
classinfo *cls = LLNI_classinfo_unwrap(jcpool);
* Method: getDoubleAt0
* Signature: (Ljava/lang/Object;I)D
*/
-JNIEXPORT double JNICALL Java_sun_reflect_ConstantPool_getDoubleAt0(JNIEnv *env, struct sun_reflect_ConstantPool* _this, struct java_lang_Object* jcpool, int32_t index)
+JNIEXPORT double JNICALL Java_sun_reflect_ConstantPool_getDoubleAt0(JNIEnv *env, jobject _this, jobject jcpool, jint index)
{
constant_double *ref;
classinfo *cls = LLNI_classinfo_unwrap(jcpool);
* Method: getStringAt0
* Signature: (Ljava/lang/Object;I)Ljava/lang/String;
*/
-JNIEXPORT struct java_lang_String* JNICALL Java_sun_reflect_ConstantPool_getStringAt0(JNIEnv *env, struct sun_reflect_ConstantPool* _this, struct java_lang_Object* jcpool, int32_t index)
+JNIEXPORT jstring JNICALL Java_sun_reflect_ConstantPool_getStringAt0(JNIEnv *env, jobject _this, jobject jcpool, jint index)
{
utf *ref;
classinfo *cls = LLNI_classinfo_unwrap(jcpool);
}
/* XXX: I hope literalstring_new is the right Function. */
- return (java_lang_String*)literalstring_new(ref);
+ return (jstring) literalstring_new(ref);
}
* Method: getUTF8At0
* Signature: (Ljava/lang/Object;I)Ljava/lang/String;
*/
-JNIEXPORT struct java_lang_String* JNICALL Java_sun_reflect_ConstantPool_getUTF8At0(JNIEnv *env, struct sun_reflect_ConstantPool* _this, struct java_lang_Object* jcpool, int32_t index)
+JNIEXPORT jstring JNICALL Java_sun_reflect_ConstantPool_getUTF8At0(JNIEnv *env, jobject _this, jobject jcpool, jint index)
{
utf *ref;
classinfo *cls = LLNI_classinfo_unwrap(jcpool);
}
/* XXX: I hope literalstring_new is the right Function. */
- return (java_lang_String*)literalstring_new(ref);
+ return (jstring) literalstring_new(ref);
}
} // extern "C"
+/* native methods implemented by this file ************************************/
+
+static JNINativeMethod methods[] = {
+ { (char*) "getSize0", (char*) "(Ljava/lang/Object;I)I", (void*) (uintptr_t) &Java_sun_reflect_ConstantPool_getSize0 },
+ { (char*) "getClassAt0", (char*) "(Ljava/lang/Object;I)Ljava/lang/Class;", (void*) (uintptr_t) &Java_sun_reflect_ConstantPool_getClassAt0 },
+ { (char*) "getClassAtIfLoaded0", (char*) "(Ljava/lang/Object;I)Ljava/lang/Class;", (void*) (uintptr_t) &Java_sun_reflect_ConstantPool_getClassAtIfLoaded0 },
+ { (char*) "getMethodAt0", (char*) "(Ljava/lang/Object;I)Ljava/lang/reflect/Member;", (void*) (uintptr_t) &Java_sun_reflect_ConstantPool_getMethodAt0 },
+ { (char*) "getMethodAtIfLoaded0", (char*) "(Ljava/lang/Object;I)Ljava/lang/reflect/Member;", (void*) (uintptr_t) &Java_sun_reflect_ConstantPool_getMethodAtIfLoaded0 },
+ { (char*) "getFieldAt0", (char*) "(Ljava/lang/Object;I)Ljava/lang/reflect/Field;", (void*) (uintptr_t) &Java_sun_reflect_ConstantPool_getFieldAt0 },
+ { (char*) "getFieldAtIfLoaded0", (char*) "(Ljava/lang/Object;I)Ljava/lang/reflect/Field;", (void*) (uintptr_t) &Java_sun_reflect_ConstantPool_getFieldAtIfLoaded0 },
+ { (char*) "getMemberRefInfoAt0", (char*) "(Ljava/lang/Object;I)[Ljava/lang/String;", (void*) (uintptr_t) &Java_sun_reflect_ConstantPool_getMemberRefInfoAt0 },
+ { (char*) "getIntAt0", (char*) "(Ljava/lang/Object;I)I", (void*) (uintptr_t) &Java_sun_reflect_ConstantPool_getIntAt0 },
+ { (char*) "getLongAt0", (char*) "(Ljava/lang/Object;I)J", (void*) (uintptr_t) &Java_sun_reflect_ConstantPool_getLongAt0 },
+ { (char*) "getFloatAt0", (char*) "(Ljava/lang/Object;I)F", (void*) (uintptr_t) &Java_sun_reflect_ConstantPool_getFloatAt0 },
+ { (char*) "getDoubleAt0", (char*) "(Ljava/lang/Object;I)D", (void*) (uintptr_t) &Java_sun_reflect_ConstantPool_getDoubleAt0 },
+ { (char*) "getStringAt0", (char*) "(Ljava/lang/Object;I)Ljava/lang/String;", (void*) (uintptr_t) &Java_sun_reflect_ConstantPool_getStringAt0 },
+ { (char*) "getUTF8At0", (char*) "(Ljava/lang/Object;I)Ljava/lang/String;", (void*) (uintptr_t) &Java_sun_reflect_ConstantPool_getUTF8At0 },
+};
+
+
+/* _Jv_sun_reflect_ConstantPool_init ******************************************
+
+ Register native functions.
+
+*******************************************************************************/
+
+void _Jv_sun_reflect_ConstantPool_init(void)
+{
+ utf* u = utf_new_char("sun/reflect/ConstantPool");
+
+ NativeMethods& nm = VM::get_current()->get_nativemethods();
+ nm.register_methods(u, methods, NATIVE_METHODS_COUNT);
+}
+
+
/*
* These are local overrides for various environment variables in Emacs.
* Please do not remove this and leave it at the end of the file, where
* Emacs will automagically detect them.
* ---------------------------------------------------------------------
* Local variables:
- * mode: c
+ * mode: c++
* indent-tabs-mode: t
* c-basic-offset: 4
* tab-width: 4