1 /* src/native/vm/gnu/sun_reflect_ConstantPool.c
3 Copyright (C) 2007 R. Grafl, A. Krall, C. Kruegel,
4 C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
5 E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
6 J. Wenninger, M. S. Panzenböck Institut f. Computersprachen - TU Wien
8 This file is part of CACAO.
10 This program is free software; you can redistribute it and/or
11 modify it under the terms of the GNU General Public License as
12 published by the Free Software Foundation; either version 2, or (at
13 your option) any later version.
15 This program is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
27 /*******************************************************************************
29 XXX: The Methods in this file are very redundant to thouse in
30 src/native/vm/sun/jvm.c Unless someone has a good idea how to cover
31 such redundancy I leave it how it is.
33 The ConstantPool class represents an interface to the constant pool of a
34 class and is used by the annotations parser (sun.reflect.annotation.
35 AnnotationParser) to get the values of the constants refered by the
38 *******************************************************************************/
45 #include "mm/memory.h"
47 #include "native/jni.h"
48 #include "native/llni.h"
49 #include "native/native.h"
51 #include "native/include/java_lang_Object.h"
52 #include "native/include/java_lang_Class.h"
53 #include "native/include/sun_reflect_ConstantPool.h"
55 #include "native/vm/reflect.h"
57 #include "toolbox/logging.h"
60 #include "vm/exceptions.h"
61 #include "vm/resolve.h"
62 #include "vm/stringlocal.h"
64 #include "vmcore/class.h"
65 #include "vmcore/utf8.h"
68 /* native methods implemented by this file ************************************/
70 static JNINativeMethod methods[] = {
71 { "getSize0", "(Ljava/lang/Object;I)I", (void *) (intptr_t) &Java_sun_reflect_ConstantPool_getSize0 },
72 { "getClassAt0", "(Ljava/lang/Object;I)Ljava/lang/Class;", (void *) (intptr_t) &Java_sun_reflect_ConstantPool_getClassAt0 },
73 { "getClassAtIfLoaded0", "(Ljava/lang/Object;I)Ljava/lang/Class;", (void *) (intptr_t) &Java_sun_reflect_ConstantPool_getClassAtIfLoaded0 },
74 { "getMethodAt0", "(Ljava/lang/Object;I)Ljava/lang/reflect/Member;", (void *) (intptr_t) &Java_sun_reflect_ConstantPool_getMethodAt0 },
75 { "getMethodAtIfLoaded0", "(Ljava/lang/Object;I)Ljava/lang/reflect/Member;", (void *) (intptr_t) &Java_sun_reflect_ConstantPool_getMethodAtIfLoaded0 },
76 { "getFieldAt0", "(Ljava/lang/Object;I)Ljava/lang/reflect/Field;", (void *) (intptr_t) &Java_sun_reflect_ConstantPool_getFieldAt0 },
77 { "getFieldAtIfLoaded0", "(Ljava/lang/Object;I)Ljava/lang/reflect/Field;", (void *) (intptr_t) &Java_sun_reflect_ConstantPool_getFieldAtIfLoaded0 },
78 { "getMemberRefInfoAt0", "(Ljava/lang/Object;I)[Ljava/lang/String;", (void *) (intptr_t) &Java_sun_reflect_ConstantPool_getMemberRefInfoAt0 },
79 { "getIntAt0", "(Ljava/lang/Object;I)I", (void *) (intptr_t) &Java_sun_reflect_ConstantPool_getIntAt0 },
80 { "getLongAt0", "(Ljava/lang/Object;I)J", (void *) (intptr_t) &Java_sun_reflect_ConstantPool_getLongAt0 },
81 { "getFloatAt0", "(Ljava/lang/Object;I)F", (void *) (intptr_t) &Java_sun_reflect_ConstantPool_getFloatAt0 },
82 { "getDoubleAt0", "(Ljava/lang/Object;I)D", (void *) (intptr_t) &Java_sun_reflect_ConstantPool_getDoubleAt0 },
83 { "getStringAt0", "(Ljava/lang/Object;I)Ljava/lang/String;", (void *) (intptr_t) &Java_sun_reflect_ConstantPool_getStringAt0 },
84 { "getUTF8At0", "(Ljava/lang/Object;I)Ljava/lang/String;", (void *) (intptr_t) &Java_sun_reflect_ConstantPool_getUTF8At0 },
88 /* _Jv_sun_reflect_ConstantPool_init ******************************************
90 Register native functions.
92 *******************************************************************************/
94 void _Jv_sun_reflect_ConstantPool_init(void)
96 native_method_register(utf_new_char("sun/reflect/ConstantPool"), methods, NATIVE_METHODS_COUNT);
100 * Class: sun/reflect/ConstantPool
102 * Signature: (Ljava/lang/Object;)I
104 JNIEXPORT int32_t JNICALL Java_sun_reflect_ConstantPool_getSize0(JNIEnv *env, struct sun_reflect_ConstantPool* this, struct java_lang_Object* jcpool)
106 classinfo *cls = LLNI_classinfo_unwrap(jcpool);
112 * Class: sun/reflect/ConstantPool
113 * Method: getClassAt0
114 * Signature: (Ljava/lang/Object;I)Ljava/lang/Class;
116 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)
118 constant_classref *ref;
119 classinfo *cls = LLNI_classinfo_unwrap(jcpool);
121 ref = (constant_classref*)class_getconstant(
122 cls, index, CONSTANT_Class);
125 exceptions_throw_illegalargumentexception();
129 return LLNI_classinfo_wrap(resolve_classref_eager(ref));
134 * Class: sun/reflect/ConstantPool
135 * Method: getClassAtIfLoaded0
136 * Signature: (Ljava/lang/Object;I)Ljava/lang/Class;
138 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)
140 constant_classref *ref;
142 classinfo *cls = LLNI_classinfo_unwrap(jcpool);
144 ref = (constant_classref*)class_getconstant(
145 cls, index, CONSTANT_Class);
148 exceptions_throw_illegalargumentexception();
152 if (!resolve_classref(NULL,ref,resolveLazy,true,true,&c)) {
156 if (c == NULL || !(c->state & CLASS_LOADED)) {
160 return LLNI_classinfo_wrap(c);
165 * Class: sun/reflect/ConstantPool
166 * Method: getMethodAt0
167 * Signature: (Ljava/lang/Object;I)Ljava/lang/reflect/Member;
169 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)
171 constant_FMIref *ref;
172 classinfo *cls = LLNI_classinfo_unwrap(jcpool);
174 ref = (constant_FMIref*)class_getconstant(
175 cls, index, CONSTANT_Methodref);
178 exceptions_throw_illegalargumentexception();
182 /* XXX: is that right? or do I have to use resolve_method_*? */
183 return (jobject)reflect_method_new(ref->p.method);
188 * Class: sun/reflect/ConstantPool
189 * Method: getMethodAtIfLoaded0
190 * Signature: (Ljava/lang/Object;I)Ljava/lang/reflect/Member;
192 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)
194 constant_FMIref *ref;
196 classinfo *cls = LLNI_classinfo_unwrap(jcpool);
198 ref = (constant_FMIref*)class_getconstant(
199 cls, index, CONSTANT_Methodref);
202 exceptions_throw_illegalargumentexception();
206 if (!resolve_classref(NULL,ref->p.classref,resolveLazy,true,true,&c)) {
210 if (c == NULL || !(c->state & CLASS_LOADED)) {
214 return (jobject)reflect_method_new(ref->p.method);
219 * Class: sun/reflect/ConstantPool
220 * Method: getFieldAt0
221 * Signature: (Ljava/lang/Object;I)Ljava/lang/reflect/Field;
223 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)
225 constant_FMIref *ref;
226 classinfo *cls = LLNI_classinfo_unwrap(jcpool);
228 ref = (constant_FMIref*)class_getconstant(
229 cls, index, CONSTANT_Fieldref);
232 exceptions_throw_illegalargumentexception();
236 return (jobject)reflect_field_new(ref->p.field);
241 * Class: sun/reflect/ConstantPool
242 * Method: getFieldAtIfLoaded0
243 * Signature: (Ljava/lang/Object;I)Ljava/lang/reflect/Field;
245 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)
247 constant_FMIref *ref;
249 classinfo *cls = LLNI_classinfo_unwrap(jcpool);
251 ref = (constant_FMIref*)class_getconstant(
252 cls, index, CONSTANT_Fieldref);
255 exceptions_throw_illegalargumentexception();
259 if (!resolve_classref(NULL,ref->p.classref,resolveLazy,true,true,&c)) {
263 if (c == NULL || !(c->state & CLASS_LOADED)) {
267 return (jobject)reflect_field_new(ref->p.field);
272 * Class: sun/reflect/ConstantPool
273 * Method: getMemberRefInfoAt0
274 * Signature: (Ljava/lang/Object;I)[Ljava/lang/String;
276 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)
278 log_println("Java_sun_reflect_ConstantPool_getMemberRefInfoAt0(env=%p, jcpool=%p, index=%d): IMPLEMENT ME!", env, jcpool, index);
284 * Class: sun/reflect/ConstantPool
286 * Signature: (Ljava/lang/Object;I)I
288 JNIEXPORT int32_t JNICALL Java_sun_reflect_ConstantPool_getIntAt0(JNIEnv *env, struct sun_reflect_ConstantPool* this, struct java_lang_Object* jcpool, int32_t index)
290 constant_integer *ref;
291 classinfo *cls = LLNI_classinfo_unwrap(jcpool);
293 ref = (constant_integer*)class_getconstant(
294 cls, index, CONSTANT_Integer);
297 exceptions_throw_illegalargumentexception();
306 * Class: sun/reflect/ConstantPool
308 * Signature: (Ljava/lang/Object;I)J
310 JNIEXPORT int64_t JNICALL Java_sun_reflect_ConstantPool_getLongAt0(JNIEnv *env, struct sun_reflect_ConstantPool* this, struct java_lang_Object* jcpool, int32_t index)
313 classinfo *cls = LLNI_classinfo_unwrap(jcpool);
315 ref = (constant_long*)class_getconstant(
316 cls, index, CONSTANT_Long);
319 exceptions_throw_illegalargumentexception();
328 * Class: sun/reflect/ConstantPool
329 * Method: getFloatAt0
330 * Signature: (Ljava/lang/Object;I)F
332 JNIEXPORT float JNICALL Java_sun_reflect_ConstantPool_getFloatAt0(JNIEnv *env, struct sun_reflect_ConstantPool* this, struct java_lang_Object* jcpool, int32_t index)
335 classinfo *cls = LLNI_classinfo_unwrap(jcpool);
337 ref = (constant_float*)class_getconstant(
338 cls, index, CONSTANT_Float);
341 exceptions_throw_illegalargumentexception();
350 * Class: sun/reflect/ConstantPool
351 * Method: getDoubleAt0
352 * Signature: (Ljava/lang/Object;I)D
354 JNIEXPORT double JNICALL Java_sun_reflect_ConstantPool_getDoubleAt0(JNIEnv *env, struct sun_reflect_ConstantPool* this, struct java_lang_Object* jcpool, int32_t index)
356 constant_double *ref;
357 classinfo *cls = LLNI_classinfo_unwrap(jcpool);
359 ref = (constant_double*)class_getconstant(
360 cls, index, CONSTANT_Double);
363 exceptions_throw_illegalargumentexception();
372 * Class: sun/reflect/ConstantPool
373 * Method: getStringAt0
374 * Signature: (Ljava/lang/Object;I)Ljava/lang/String;
376 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)
379 classinfo *cls = LLNI_classinfo_unwrap(jcpool);
381 ref = (utf*)class_getconstant(cls, index, CONSTANT_String);
384 exceptions_throw_illegalargumentexception();
388 /* XXX: I hope literalstring_new is the right Function. */
389 return (java_lang_String*)literalstring_new(ref);
394 * Class: sun/reflect/ConstantPool
396 * Signature: (Ljava/lang/Object;I)Ljava/lang/String;
398 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)
401 classinfo *cls = LLNI_classinfo_unwrap(jcpool);
403 ref = (utf*)class_getconstant(cls, index, CONSTANT_Utf8);
406 exceptions_throw_illegalargumentexception();
410 /* XXX: I hope literalstring_new is the right Function. */
411 return (java_lang_String*)literalstring_new(ref);
416 * These are local overrides for various environment variables in Emacs.
417 * Please do not remove this and leave it at the end of the file, where
418 * Emacs will automagically detect them.
419 * ---------------------------------------------------------------------
422 * indent-tabs-mode: t
426 * vim:noexpandtab:sw=4:ts=4: