1 /* src/native/vm/gnu/sun_reflect_ConstantPool.c
3 Copyright (C) 1996-2005, 2006, 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 *******************************************************************************/
40 #include "mm/memory.h"
42 #include "native/jni.h"
43 #include "native/native.h"
44 #include "native/include/java_lang_Object.h"
45 #include "native/include/java_lang_Class.h"
46 #include "native/include/sun_reflect_ConstantPool.h"
47 #include "native/vm/reflect.h"
49 #include "toolbox/logging.h"
52 #include "vm/resolve.h"
53 #include "vm/stringlocal.h"
55 #include "vmcore/class.h"
56 #include "vmcore/utf8.h"
58 /* native methods implemented by this file ************************************/
60 static JNINativeMethod methods[] = {
61 { "getSize0", "(Ljava/lang/Object;I)I", (void *) (intptr_t) &Java_sun_reflect_ConstantPool_getSize0 },
62 { "getClassAt0", "(Ljava/lang/Object;I)Ljava/lang/Class;", (void *) (intptr_t) &Java_sun_reflect_ConstantPool_getClassAt0 },
63 { "getClassAtIfLoaded0", "(Ljava/lang/Object;I)Ljava/lang/Class;", (void *) (intptr_t) &Java_sun_reflect_ConstantPool_getClassAtIfLoaded0 },
64 { "getMethodAt0", "(Ljava/lang/Object;I)Ljava/lang/reflect/Member;", (void *) (intptr_t) &Java_sun_reflect_ConstantPool_getMethodAt0 },
65 { "getMethodAtIfLoaded0", "(Ljava/lang/Object;I)Ljava/lang/reflect/Member;", (void *) (intptr_t) &Java_sun_reflect_ConstantPool_getMethodAtIfLoaded0 },
66 { "getFieldAt0", "(Ljava/lang/Object;I)Ljava/lang/reflect/Field;", (void *) (intptr_t) &Java_sun_reflect_ConstantPool_getFieldAt0 },
67 { "getFieldAtIfLoaded0", "(Ljava/lang/Object;I)Ljava/lang/reflect/Field;", (void *) (intptr_t) &Java_sun_reflect_ConstantPool_getFieldAtIfLoaded0 },
68 { "getMemberRefInfoAt0", "(Ljava/lang/Object;I)[Ljava/lang/String;", (void *) (intptr_t) &Java_sun_reflect_ConstantPool_getMemberRefInfoAt0 },
69 { "getIntAt0", "(Ljava/lang/Object;I)I", (void *) (intptr_t) &Java_sun_reflect_ConstantPool_getIntAt0 },
70 { "getLongAt0", "(Ljava/lang/Object;I)J", (void *) (intptr_t) &Java_sun_reflect_ConstantPool_getLongAt0 },
71 { "getFloatAt0", "(Ljava/lang/Object;I)F", (void *) (intptr_t) &Java_sun_reflect_ConstantPool_getFloatAt0 },
72 { "getDoubleAt0", "(Ljava/lang/Object;I)D", (void *) (intptr_t) &Java_sun_reflect_ConstantPool_getDoubleAt0 },
73 { "getStringAt0", "(Ljava/lang/Object;I)Ljava/lang/String;", (void *) (intptr_t) &Java_sun_reflect_ConstantPool_getStringAt0 },
74 { "getUTF8At0", "(Ljava/lang/Object;I)Ljava/lang/String;", (void *) (intptr_t) &Java_sun_reflect_ConstantPool_getUTF8At0 },
78 /* _Jv_sun_reflect_ConstantPool_init ********************************************
80 Register native functions.
82 *******************************************************************************/
84 void _Jv_sun_reflect_ConstantPool_init(void)
86 native_method_register(utf_sun_reflect_ConstantPool, methods, NATIVE_METHODS_COUNT);
90 * Class: sun/reflect/ConstantPool
92 * Signature: (Ljava/lang/Object;)I
94 JNIEXPORT int32_t JNICALL Java_sun_reflect_ConstantPool_getSize0(JNIEnv *env, struct sun_reflect_ConstantPool* this, struct java_lang_Object* jcpool)
96 classinfo *cls = LLNI_classinfo_unwrap(jcpool);
102 * Class: sun/reflect/ConstantPool
103 * Method: getClassAt0
104 * Signature: (Ljava/lang/Object;I)Ljava/lang/Class;
106 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)
108 constant_classref *ref;
109 classinfo *cls = LLNI_classinfo_unwrap(jcpool);
111 ref = (constant_classref*)class_getconstant(
112 cls, index, CONSTANT_Class);
118 return LLNI_classinfo_wrap(resolve_classref_eager(ref));
123 * Class: sun/reflect/ConstantPool
124 * Method: getClassAtIfLoaded0
125 * Signature: (Ljava/lang/Object;I)Ljava/lang/Class;
127 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)
129 constant_classref *ref;
131 classinfo *cls = LLNI_classinfo_unwrap(jcpool);
133 ref = (constant_classref*)class_getconstant(
134 cls, index, CONSTANT_Class);
140 if (!resolve_classref(NULL,ref,resolveLazy,true,true,&c)) {
144 if (c == NULL || !(c->state & CLASS_LOADED)) {
148 return LLNI_classinfo_wrap(c);
153 * Class: sun/reflect/ConstantPool
154 * Method: getMethodAt0
155 * Signature: (Ljava/lang/Object;I)Ljava/lang/reflect/Member;
157 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)
159 constant_FMIref *ref;
160 classinfo *cls = LLNI_classinfo_unwrap(jcpool);
162 ref = (constant_FMIref*)class_getconstant(
163 cls, index, CONSTANT_Methodref);
169 /* XXX: is that right? or do I have to use resolve_method_*? */
170 return (jobject)reflect_method_new(ref->p.method);
175 * Class: sun/reflect/ConstantPool
176 * Method: getMethodAtIfLoaded0
177 * Signature: (Ljava/lang/Object;I)Ljava/lang/reflect/Member;
179 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)
181 constant_FMIref *ref;
183 classinfo *cls = LLNI_classinfo_unwrap(jcpool);
185 ref = (constant_FMIref*)class_getconstant(
186 cls, index, CONSTANT_Methodref);
192 if (!resolve_classref(NULL,ref->p.classref,resolveLazy,true,true,&c)) {
196 if (c == NULL || !(c->state & CLASS_LOADED)) {
200 return (jobject)reflect_method_new(ref->p.method);
205 * Class: sun/reflect/ConstantPool
206 * Method: getFieldAt0
207 * Signature: (Ljava/lang/Object;I)Ljava/lang/reflect/Field;
209 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)
211 constant_FMIref *ref;
212 classinfo *cls = LLNI_classinfo_unwrap(jcpool);
214 ref = (constant_FMIref*)class_getconstant(
215 cls, index, CONSTANT_Fieldref);
221 return (jobject)reflect_field_new(ref->p.field);
226 * Class: sun/reflect/ConstantPool
227 * Method: getFieldAtIfLoaded0
228 * Signature: (Ljava/lang/Object;I)Ljava/lang/reflect/Field;
230 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)
232 constant_FMIref *ref;
234 classinfo *cls = LLNI_classinfo_unwrap(jcpool);
236 ref = (constant_FMIref*)class_getconstant(
237 cls, index, CONSTANT_Fieldref);
243 if (!resolve_classref(NULL,ref->p.classref,resolveLazy,true,true,&c)) {
247 if (c == NULL || !(c->state & CLASS_LOADED)) {
251 return (jobject)reflect_field_new(ref->p.field);
256 * Class: sun/reflect/ConstantPool
257 * Method: getMemberRefInfoAt0
258 * Signature: (Ljava/lang/Object;I)[Ljava/lang/String;
260 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)
262 log_println("Java_sun_reflect_ConstantPool_getMemberRefInfoAt0: jcpool=%p, index=%d, IMPLEMENT ME!", jcpool, index);
268 * Class: sun/reflect/ConstantPool
270 * Signature: (Ljava/lang/Object;I)I
272 JNIEXPORT int32_t JNICALL Java_sun_reflect_ConstantPool_getIntAt0(JNIEnv *env, struct sun_reflect_ConstantPool* this, struct java_lang_Object* jcpool, int32_t index)
274 constant_integer *ref;
275 classinfo *cls = LLNI_classinfo_unwrap(jcpool);
277 ref = (constant_integer*)class_getconstant(
278 cls, index, CONSTANT_Integer);
289 * Class: sun/reflect/ConstantPool
291 * Signature: (Ljava/lang/Object;I)J
293 JNIEXPORT int64_t JNICALL Java_sun_reflect_ConstantPool_getLongAt0(JNIEnv *env, struct sun_reflect_ConstantPool* this, struct java_lang_Object* jcpool, int32_t index)
296 classinfo *cls = LLNI_classinfo_unwrap(jcpool);
298 ref = (constant_long*)class_getconstant(
299 cls, index, CONSTANT_Long);
310 * Class: sun/reflect/ConstantPool
311 * Method: getFloatAt0
312 * Signature: (Ljava/lang/Object;I)F
314 JNIEXPORT float JNICALL Java_sun_reflect_ConstantPool_getFloatAt0(JNIEnv *env, struct sun_reflect_ConstantPool* this, struct java_lang_Object* jcpool, int32_t index)
317 classinfo *cls = LLNI_classinfo_unwrap(jcpool);
319 ref = (constant_float*)class_getconstant(
320 cls, index, CONSTANT_Float);
331 * Class: sun/reflect/ConstantPool
332 * Method: getDoubleAt0
333 * Signature: (Ljava/lang/Object;I)D
335 JNIEXPORT double JNICALL Java_sun_reflect_ConstantPool_getDoubleAt0(JNIEnv *env, struct sun_reflect_ConstantPool* this, struct java_lang_Object* jcpool, int32_t index)
337 constant_double *ref;
338 classinfo *cls = LLNI_classinfo_unwrap(jcpool);
340 ref = (constant_double*)class_getconstant(
341 cls, index, CONSTANT_Double);
352 * Class: sun/reflect/ConstantPool
353 * Method: getStringAt0
354 * Signature: (Ljava/lang/Object;I)Ljava/lang/String;
356 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)
359 classinfo *cls = LLNI_classinfo_unwrap(jcpool);
361 ref = (utf*)class_getconstant(cls, index, CONSTANT_String);
367 /* XXX: I hope literalstring_new is the right Function. */
368 return (java_lang_String*)literalstring_new(ref);
373 * Class: sun/reflect/ConstantPool
375 * Signature: (Ljava/lang/Object;I)Ljava/lang/String;
377 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)
380 classinfo *cls = LLNI_classinfo_unwrap(jcpool);
382 ref = (utf*)class_getconstant(cls, index, CONSTANT_Utf8);
388 /* XXX: I hope literalstring_new is the right Function. */
389 return (java_lang_String*)literalstring_new(ref);