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
25 $Id: sun_reflect_ConstantPool.c 8393 2007-08-22 01:10:09Z panzi $
29 /*******************************************************************************
31 XXX: The Methods in this file are very redundant to thouse in
32 src/native/vm/sun/jvm.c Unless someone has a good idea how to cover
33 such redundancy I leave it how it is.
35 *******************************************************************************/
42 #include "mm/memory.h"
44 #include "native/jni.h"
45 #include "native/llni.h"
46 #include "native/native.h"
48 #include "native/include/java_lang_Object.h"
49 #include "native/include/java_lang_Class.h"
50 #include "native/include/sun_reflect_ConstantPool.h"
52 #include "native/vm/reflect.h"
54 #include "toolbox/logging.h"
57 #include "vm/resolve.h"
58 #include "vm/stringlocal.h"
60 #include "vmcore/class.h"
61 #include "vmcore/utf8.h"
64 /* native methods implemented by this file ************************************/
66 static JNINativeMethod methods[] = {
67 { "getSize0", "(Ljava/lang/Object;I)I", (void *) (intptr_t) &Java_sun_reflect_ConstantPool_getSize0 },
68 { "getClassAt0", "(Ljava/lang/Object;I)Ljava/lang/Class;", (void *) (intptr_t) &Java_sun_reflect_ConstantPool_getClassAt0 },
69 { "getClassAtIfLoaded0", "(Ljava/lang/Object;I)Ljava/lang/Class;", (void *) (intptr_t) &Java_sun_reflect_ConstantPool_getClassAtIfLoaded0 },
70 { "getMethodAt0", "(Ljava/lang/Object;I)Ljava/lang/reflect/Member;", (void *) (intptr_t) &Java_sun_reflect_ConstantPool_getMethodAt0 },
71 { "getMethodAtIfLoaded0", "(Ljava/lang/Object;I)Ljava/lang/reflect/Member;", (void *) (intptr_t) &Java_sun_reflect_ConstantPool_getMethodAtIfLoaded0 },
72 { "getFieldAt0", "(Ljava/lang/Object;I)Ljava/lang/reflect/Field;", (void *) (intptr_t) &Java_sun_reflect_ConstantPool_getFieldAt0 },
73 { "getFieldAtIfLoaded0", "(Ljava/lang/Object;I)Ljava/lang/reflect/Field;", (void *) (intptr_t) &Java_sun_reflect_ConstantPool_getFieldAtIfLoaded0 },
74 { "getMemberRefInfoAt0", "(Ljava/lang/Object;I)[Ljava/lang/String;", (void *) (intptr_t) &Java_sun_reflect_ConstantPool_getMemberRefInfoAt0 },
75 { "getIntAt0", "(Ljava/lang/Object;I)I", (void *) (intptr_t) &Java_sun_reflect_ConstantPool_getIntAt0 },
76 { "getLongAt0", "(Ljava/lang/Object;I)J", (void *) (intptr_t) &Java_sun_reflect_ConstantPool_getLongAt0 },
77 { "getFloatAt0", "(Ljava/lang/Object;I)F", (void *) (intptr_t) &Java_sun_reflect_ConstantPool_getFloatAt0 },
78 { "getDoubleAt0", "(Ljava/lang/Object;I)D", (void *) (intptr_t) &Java_sun_reflect_ConstantPool_getDoubleAt0 },
79 { "getStringAt0", "(Ljava/lang/Object;I)Ljava/lang/String;", (void *) (intptr_t) &Java_sun_reflect_ConstantPool_getStringAt0 },
80 { "getUTF8At0", "(Ljava/lang/Object;I)Ljava/lang/String;", (void *) (intptr_t) &Java_sun_reflect_ConstantPool_getUTF8At0 },
84 /* _Jv_sun_reflect_ConstantPool_init ********************************************
86 Register native functions.
88 *******************************************************************************/
90 void _Jv_sun_reflect_ConstantPool_init(void)
92 native_method_register(utf_sun_reflect_ConstantPool, methods, NATIVE_METHODS_COUNT);
96 * Class: sun/reflect/ConstantPool
98 * Signature: (Ljava/lang/Object;)I
100 JNIEXPORT int32_t JNICALL Java_sun_reflect_ConstantPool_getSize0(JNIEnv *env, struct sun_reflect_ConstantPool* this, struct java_lang_Object* jcpool)
102 classinfo *cls = LLNI_classinfo_unwrap(jcpool);
108 * Class: sun/reflect/ConstantPool
109 * Method: getClassAt0
110 * Signature: (Ljava/lang/Object;I)Ljava/lang/Class;
112 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)
114 constant_classref *ref;
115 classinfo *cls = LLNI_classinfo_unwrap(jcpool);
117 ref = (constant_classref*)class_getconstant(
118 cls, index, CONSTANT_Class);
124 return LLNI_classinfo_wrap(resolve_classref_eager(ref));
129 * Class: sun/reflect/ConstantPool
130 * Method: getClassAtIfLoaded0
131 * Signature: (Ljava/lang/Object;I)Ljava/lang/Class;
133 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)
135 constant_classref *ref;
137 classinfo *cls = LLNI_classinfo_unwrap(jcpool);
139 ref = (constant_classref*)class_getconstant(
140 cls, index, CONSTANT_Class);
146 if (!resolve_classref(NULL,ref,resolveLazy,true,true,&c)) {
150 if (c == NULL || !(c->state & CLASS_LOADED)) {
154 return LLNI_classinfo_wrap(c);
159 * Class: sun/reflect/ConstantPool
160 * Method: getMethodAt0
161 * Signature: (Ljava/lang/Object;I)Ljava/lang/reflect/Member;
163 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)
165 constant_FMIref *ref;
166 classinfo *cls = LLNI_classinfo_unwrap(jcpool);
168 ref = (constant_FMIref*)class_getconstant(
169 cls, index, CONSTANT_Methodref);
175 /* XXX: is that right? or do I have to use resolve_method_*? */
176 return (jobject)reflect_method_new(ref->p.method);
181 * Class: sun/reflect/ConstantPool
182 * Method: getMethodAtIfLoaded0
183 * Signature: (Ljava/lang/Object;I)Ljava/lang/reflect/Member;
185 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)
187 constant_FMIref *ref;
189 classinfo *cls = LLNI_classinfo_unwrap(jcpool);
191 ref = (constant_FMIref*)class_getconstant(
192 cls, index, CONSTANT_Methodref);
198 if (!resolve_classref(NULL,ref->p.classref,resolveLazy,true,true,&c)) {
202 if (c == NULL || !(c->state & CLASS_LOADED)) {
206 return (jobject)reflect_method_new(ref->p.method);
211 * Class: sun/reflect/ConstantPool
212 * Method: getFieldAt0
213 * Signature: (Ljava/lang/Object;I)Ljava/lang/reflect/Field;
215 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)
217 constant_FMIref *ref;
218 classinfo *cls = LLNI_classinfo_unwrap(jcpool);
220 ref = (constant_FMIref*)class_getconstant(
221 cls, index, CONSTANT_Fieldref);
227 return (jobject)reflect_field_new(ref->p.field);
232 * Class: sun/reflect/ConstantPool
233 * Method: getFieldAtIfLoaded0
234 * Signature: (Ljava/lang/Object;I)Ljava/lang/reflect/Field;
236 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)
238 constant_FMIref *ref;
240 classinfo *cls = LLNI_classinfo_unwrap(jcpool);
242 ref = (constant_FMIref*)class_getconstant(
243 cls, index, CONSTANT_Fieldref);
249 if (!resolve_classref(NULL,ref->p.classref,resolveLazy,true,true,&c)) {
253 if (c == NULL || !(c->state & CLASS_LOADED)) {
257 return (jobject)reflect_field_new(ref->p.field);
262 * Class: sun/reflect/ConstantPool
263 * Method: getMemberRefInfoAt0
264 * Signature: (Ljava/lang/Object;I)[Ljava/lang/String;
266 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)
268 log_println("Java_sun_reflect_ConstantPool_getMemberRefInfoAt0(env=%p, jcpool=%p, index=%d): IMPLEMENT ME!", env, jcpool, index);
274 * Class: sun/reflect/ConstantPool
276 * Signature: (Ljava/lang/Object;I)I
278 JNIEXPORT int32_t JNICALL Java_sun_reflect_ConstantPool_getIntAt0(JNIEnv *env, struct sun_reflect_ConstantPool* this, struct java_lang_Object* jcpool, int32_t index)
280 constant_integer *ref;
281 classinfo *cls = LLNI_classinfo_unwrap(jcpool);
283 ref = (constant_integer*)class_getconstant(
284 cls, index, CONSTANT_Integer);
295 * Class: sun/reflect/ConstantPool
297 * Signature: (Ljava/lang/Object;I)J
299 JNIEXPORT int64_t JNICALL Java_sun_reflect_ConstantPool_getLongAt0(JNIEnv *env, struct sun_reflect_ConstantPool* this, struct java_lang_Object* jcpool, int32_t index)
302 classinfo *cls = LLNI_classinfo_unwrap(jcpool);
304 ref = (constant_long*)class_getconstant(
305 cls, index, CONSTANT_Long);
316 * Class: sun/reflect/ConstantPool
317 * Method: getFloatAt0
318 * Signature: (Ljava/lang/Object;I)F
320 JNIEXPORT float JNICALL Java_sun_reflect_ConstantPool_getFloatAt0(JNIEnv *env, struct sun_reflect_ConstantPool* this, struct java_lang_Object* jcpool, int32_t index)
323 classinfo *cls = LLNI_classinfo_unwrap(jcpool);
325 ref = (constant_float*)class_getconstant(
326 cls, index, CONSTANT_Float);
337 * Class: sun/reflect/ConstantPool
338 * Method: getDoubleAt0
339 * Signature: (Ljava/lang/Object;I)D
341 JNIEXPORT double JNICALL Java_sun_reflect_ConstantPool_getDoubleAt0(JNIEnv *env, struct sun_reflect_ConstantPool* this, struct java_lang_Object* jcpool, int32_t index)
343 constant_double *ref;
344 classinfo *cls = LLNI_classinfo_unwrap(jcpool);
346 ref = (constant_double*)class_getconstant(
347 cls, index, CONSTANT_Double);
358 * Class: sun/reflect/ConstantPool
359 * Method: getStringAt0
360 * Signature: (Ljava/lang/Object;I)Ljava/lang/String;
362 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)
365 classinfo *cls = LLNI_classinfo_unwrap(jcpool);
367 ref = (utf*)class_getconstant(cls, index, CONSTANT_String);
373 /* XXX: I hope literalstring_new is the right Function. */
374 return (java_lang_String*)literalstring_new(ref);
379 * Class: sun/reflect/ConstantPool
381 * Signature: (Ljava/lang/Object;I)Ljava/lang/String;
383 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)
386 classinfo *cls = LLNI_classinfo_unwrap(jcpool);
388 ref = (utf*)class_getconstant(cls, index, CONSTANT_Utf8);
394 /* XXX: I hope literalstring_new is the right Function. */
395 return (java_lang_String*)literalstring_new(ref);
400 * These are local overrides for various environment variables in Emacs.
401 * Please do not remove this and leave it at the end of the file, where
402 * Emacs will automagically detect them.
403 * ---------------------------------------------------------------------
406 * indent-tabs-mode: t
410 * vim:noexpandtab:sw=4:ts=4: