1 /* src/native/vm/gnuclasspath/sun_reflect_ConstantPool.cpp
3 Copyright (C) 2007, 2008
4 CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
6 This file is part of CACAO.
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License as
10 published by the Free Software Foundation; either version 2, or (at
11 your option) any later version.
13 This program is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
25 /*******************************************************************************
27 XXX: The Methods in this file are very redundant to thouse in
28 src/native/vm/sun/jvm.c Unless someone has a good idea how to cover
29 such redundancy I leave it how it is.
31 The ConstantPool class represents an interface to the constant pool of a
32 class and is used by the annotations parser (sun.reflect.annotation.
33 AnnotationParser) to get the values of the constants refered by the
36 *******************************************************************************/
43 #include "mm/memory.h"
45 #include "native/jni.h"
46 #include "native/llni.h"
47 #include "native/native.h"
49 #include "native/include/java_lang_Object.h"
50 #include "native/include/java_lang_Class.h"
54 #include "native/include/sun_reflect_ConstantPool.h"
57 #include "native/vm/reflect.h"
59 #include "toolbox/logging.h"
62 #include "vm/exceptions.hpp"
63 #include "vm/resolve.h"
64 #include "vm/string.hpp"
66 #include "vmcore/class.h"
67 #include "vmcore/utf8.h"
70 /* native methods implemented by this file ************************************/
72 static JNINativeMethod methods[] = {
73 { (char*) "getSize0", (char*) "(Ljava/lang/Object;I)I", (void*) (uintptr_t) &Java_sun_reflect_ConstantPool_getSize0 },
74 { (char*) "getClassAt0", (char*) "(Ljava/lang/Object;I)Ljava/lang/Class;", (void*) (uintptr_t) &Java_sun_reflect_ConstantPool_getClassAt0 },
75 { (char*) "getClassAtIfLoaded0", (char*) "(Ljava/lang/Object;I)Ljava/lang/Class;", (void*) (uintptr_t) &Java_sun_reflect_ConstantPool_getClassAtIfLoaded0 },
76 { (char*) "getMethodAt0", (char*) "(Ljava/lang/Object;I)Ljava/lang/reflect/Member;", (void*) (uintptr_t) &Java_sun_reflect_ConstantPool_getMethodAt0 },
77 { (char*) "getMethodAtIfLoaded0", (char*) "(Ljava/lang/Object;I)Ljava/lang/reflect/Member;", (void*) (uintptr_t) &Java_sun_reflect_ConstantPool_getMethodAtIfLoaded0 },
78 { (char*) "getFieldAt0", (char*) "(Ljava/lang/Object;I)Ljava/lang/reflect/Field;", (void*) (uintptr_t) &Java_sun_reflect_ConstantPool_getFieldAt0 },
79 { (char*) "getFieldAtIfLoaded0", (char*) "(Ljava/lang/Object;I)Ljava/lang/reflect/Field;", (void*) (uintptr_t) &Java_sun_reflect_ConstantPool_getFieldAtIfLoaded0 },
80 { (char*) "getMemberRefInfoAt0", (char*) "(Ljava/lang/Object;I)[Ljava/lang/String;", (void*) (uintptr_t) &Java_sun_reflect_ConstantPool_getMemberRefInfoAt0 },
81 { (char*) "getIntAt0", (char*) "(Ljava/lang/Object;I)I", (void*) (uintptr_t) &Java_sun_reflect_ConstantPool_getIntAt0 },
82 { (char*) "getLongAt0", (char*) "(Ljava/lang/Object;I)J", (void*) (uintptr_t) &Java_sun_reflect_ConstantPool_getLongAt0 },
83 { (char*) "getFloatAt0", (char*) "(Ljava/lang/Object;I)F", (void*) (uintptr_t) &Java_sun_reflect_ConstantPool_getFloatAt0 },
84 { (char*) "getDoubleAt0", (char*) "(Ljava/lang/Object;I)D", (void*) (uintptr_t) &Java_sun_reflect_ConstantPool_getDoubleAt0 },
85 { (char*) "getStringAt0", (char*) "(Ljava/lang/Object;I)Ljava/lang/String;", (void*) (uintptr_t) &Java_sun_reflect_ConstantPool_getStringAt0 },
86 { (char*) "getUTF8At0", (char*) "(Ljava/lang/Object;I)Ljava/lang/String;", (void*) (uintptr_t) &Java_sun_reflect_ConstantPool_getUTF8At0 },
90 /* _Jv_sun_reflect_ConstantPool_init ******************************************
92 Register native functions.
94 *******************************************************************************/
98 void _Jv_sun_reflect_ConstantPool_init(void)
100 native_method_register(utf_new_char("sun/reflect/ConstantPool"), methods, NATIVE_METHODS_COUNT);
108 * Class: sun/reflect/ConstantPool
110 * Signature: (Ljava/lang/Object;)I
112 JNIEXPORT int32_t JNICALL Java_sun_reflect_ConstantPool_getSize0(JNIEnv *env, struct sun_reflect_ConstantPool* _this, struct java_lang_Object* jcpool)
114 classinfo *cls = LLNI_classinfo_unwrap(jcpool);
120 * Class: sun/reflect/ConstantPool
121 * Method: getClassAt0
122 * Signature: (Ljava/lang/Object;I)Ljava/lang/Class;
124 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)
126 constant_classref *ref;
127 classinfo *cls = LLNI_classinfo_unwrap(jcpool);
129 ref = (constant_classref*)class_getconstant(
130 cls, index, CONSTANT_Class);
133 exceptions_throw_illegalargumentexception();
137 return LLNI_classinfo_wrap(resolve_classref_eager(ref));
142 * Class: sun/reflect/ConstantPool
143 * Method: getClassAtIfLoaded0
144 * Signature: (Ljava/lang/Object;I)Ljava/lang/Class;
146 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)
148 constant_classref *ref;
150 classinfo *cls = LLNI_classinfo_unwrap(jcpool);
152 ref = (constant_classref*)class_getconstant(
153 cls, index, CONSTANT_Class);
156 exceptions_throw_illegalargumentexception();
160 if (!resolve_classref(NULL,ref,resolveLazy,true,true,&c)) {
164 if (c == NULL || !(c->state & CLASS_LOADED)) {
168 return LLNI_classinfo_wrap(c);
173 * Class: sun/reflect/ConstantPool
174 * Method: getMethodAt0
175 * Signature: (Ljava/lang/Object;I)Ljava/lang/reflect/Member;
177 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)
179 constant_FMIref *ref;
180 classinfo *cls = LLNI_classinfo_unwrap(jcpool);
182 ref = (constant_FMIref*)class_getconstant(
183 cls, index, CONSTANT_Methodref);
186 exceptions_throw_illegalargumentexception();
190 /* XXX: is that right? or do I have to use resolve_method_*? */
191 return (struct java_lang_reflect_Member*) reflect_method_new(ref->p.method);
196 * Class: sun/reflect/ConstantPool
197 * Method: getMethodAtIfLoaded0
198 * Signature: (Ljava/lang/Object;I)Ljava/lang/reflect/Member;
200 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)
202 constant_FMIref *ref;
204 classinfo *cls = LLNI_classinfo_unwrap(jcpool);
206 ref = (constant_FMIref*)class_getconstant(
207 cls, index, CONSTANT_Methodref);
210 exceptions_throw_illegalargumentexception();
214 if (!resolve_classref(NULL,ref->p.classref,resolveLazy,true,true,&c)) {
218 if (c == NULL || !(c->state & CLASS_LOADED)) {
222 return (struct java_lang_reflect_Member*) reflect_method_new(ref->p.method);
227 * Class: sun/reflect/ConstantPool
228 * Method: getFieldAt0
229 * Signature: (Ljava/lang/Object;I)Ljava/lang/reflect/Field;
231 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)
233 constant_FMIref *ref;
234 classinfo *cls = LLNI_classinfo_unwrap(jcpool);
236 ref = (constant_FMIref*)class_getconstant(
237 cls, index, CONSTANT_Fieldref);
240 exceptions_throw_illegalargumentexception();
244 return (struct java_lang_reflect_Field*) reflect_field_new(ref->p.field);
249 * Class: sun/reflect/ConstantPool
250 * Method: getFieldAtIfLoaded0
251 * Signature: (Ljava/lang/Object;I)Ljava/lang/reflect/Field;
253 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)
255 constant_FMIref *ref;
257 classinfo *cls = LLNI_classinfo_unwrap(jcpool);
259 ref = (constant_FMIref*)class_getconstant(
260 cls, index, CONSTANT_Fieldref);
263 exceptions_throw_illegalargumentexception();
267 if (!resolve_classref(NULL,ref->p.classref,resolveLazy,true,true,&c)) {
271 if (c == NULL || !(c->state & CLASS_LOADED)) {
275 return (struct java_lang_reflect_Field*) reflect_field_new(ref->p.field);
280 * Class: sun/reflect/ConstantPool
281 * Method: getMemberRefInfoAt0
282 * Signature: (Ljava/lang/Object;I)[Ljava/lang/String;
284 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)
286 log_println("Java_sun_reflect_ConstantPool_getMemberRefInfoAt0(env=%p, jcpool=%p, index=%d): IMPLEMENT ME!", env, jcpool, index);
292 * Class: sun/reflect/ConstantPool
294 * Signature: (Ljava/lang/Object;I)I
296 JNIEXPORT int32_t JNICALL Java_sun_reflect_ConstantPool_getIntAt0(JNIEnv *env, struct sun_reflect_ConstantPool* _this, struct java_lang_Object* jcpool, int32_t index)
298 constant_integer *ref;
299 classinfo *cls = LLNI_classinfo_unwrap(jcpool);
301 ref = (constant_integer*)class_getconstant(
302 cls, index, CONSTANT_Integer);
305 exceptions_throw_illegalargumentexception();
314 * Class: sun/reflect/ConstantPool
316 * Signature: (Ljava/lang/Object;I)J
318 JNIEXPORT int64_t JNICALL Java_sun_reflect_ConstantPool_getLongAt0(JNIEnv *env, struct sun_reflect_ConstantPool* _this, struct java_lang_Object* jcpool, int32_t index)
321 classinfo *cls = LLNI_classinfo_unwrap(jcpool);
323 ref = (constant_long*)class_getconstant(
324 cls, index, CONSTANT_Long);
327 exceptions_throw_illegalargumentexception();
336 * Class: sun/reflect/ConstantPool
337 * Method: getFloatAt0
338 * Signature: (Ljava/lang/Object;I)F
340 JNIEXPORT float JNICALL Java_sun_reflect_ConstantPool_getFloatAt0(JNIEnv *env, struct sun_reflect_ConstantPool* _this, struct java_lang_Object* jcpool, int32_t index)
343 classinfo *cls = LLNI_classinfo_unwrap(jcpool);
345 ref = (constant_float*)class_getconstant(
346 cls, index, CONSTANT_Float);
349 exceptions_throw_illegalargumentexception();
358 * Class: sun/reflect/ConstantPool
359 * Method: getDoubleAt0
360 * Signature: (Ljava/lang/Object;I)D
362 JNIEXPORT double JNICALL Java_sun_reflect_ConstantPool_getDoubleAt0(JNIEnv *env, struct sun_reflect_ConstantPool* _this, struct java_lang_Object* jcpool, int32_t index)
364 constant_double *ref;
365 classinfo *cls = LLNI_classinfo_unwrap(jcpool);
367 ref = (constant_double*)class_getconstant(
368 cls, index, CONSTANT_Double);
371 exceptions_throw_illegalargumentexception();
380 * Class: sun/reflect/ConstantPool
381 * Method: getStringAt0
382 * Signature: (Ljava/lang/Object;I)Ljava/lang/String;
384 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)
387 classinfo *cls = LLNI_classinfo_unwrap(jcpool);
389 ref = (utf*)class_getconstant(cls, index, CONSTANT_String);
392 exceptions_throw_illegalargumentexception();
396 /* XXX: I hope literalstring_new is the right Function. */
397 return (java_lang_String*)literalstring_new(ref);
402 * Class: sun/reflect/ConstantPool
404 * Signature: (Ljava/lang/Object;I)Ljava/lang/String;
406 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)
409 classinfo *cls = LLNI_classinfo_unwrap(jcpool);
411 ref = (utf*)class_getconstant(cls, index, CONSTANT_Utf8);
414 exceptions_throw_illegalargumentexception();
418 /* XXX: I hope literalstring_new is the right Function. */
419 return (java_lang_String*)literalstring_new(ref);
426 * These are local overrides for various environment variables in Emacs.
427 * Please do not remove this and leave it at the end of the file, where
428 * Emacs will automagically detect them.
429 * ---------------------------------------------------------------------
432 * indent-tabs-mode: t
436 * vim:noexpandtab:sw=4:ts=4: