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 *******************************************************************************/
40 #include "mm/memory.h"
42 #include "native/jni.h"
43 #include "native/llni.h"
44 #include "native/native.h"
46 #include "native/include/java_lang_Object.h"
47 #include "native/include/java_lang_Class.h"
48 #include "native/include/sun_reflect_ConstantPool.h"
50 #include "native/vm/reflect.h"
52 #include "toolbox/logging.h"
55 #include "vm/resolve.h"
56 #include "vm/stringlocal.h"
58 #include "vmcore/class.h"
59 #include "vmcore/utf8.h"
62 /* native methods implemented by this file ************************************/
64 static JNINativeMethod methods[] = {
65 { "getSize0", "(Ljava/lang/Object;I)I", (void *) (intptr_t) &Java_sun_reflect_ConstantPool_getSize0 },
66 { "getClassAt0", "(Ljava/lang/Object;I)Ljava/lang/Class;", (void *) (intptr_t) &Java_sun_reflect_ConstantPool_getClassAt0 },
67 { "getClassAtIfLoaded0", "(Ljava/lang/Object;I)Ljava/lang/Class;", (void *) (intptr_t) &Java_sun_reflect_ConstantPool_getClassAtIfLoaded0 },
68 { "getMethodAt0", "(Ljava/lang/Object;I)Ljava/lang/reflect/Member;", (void *) (intptr_t) &Java_sun_reflect_ConstantPool_getMethodAt0 },
69 { "getMethodAtIfLoaded0", "(Ljava/lang/Object;I)Ljava/lang/reflect/Member;", (void *) (intptr_t) &Java_sun_reflect_ConstantPool_getMethodAtIfLoaded0 },
70 { "getFieldAt0", "(Ljava/lang/Object;I)Ljava/lang/reflect/Field;", (void *) (intptr_t) &Java_sun_reflect_ConstantPool_getFieldAt0 },
71 { "getFieldAtIfLoaded0", "(Ljava/lang/Object;I)Ljava/lang/reflect/Field;", (void *) (intptr_t) &Java_sun_reflect_ConstantPool_getFieldAtIfLoaded0 },
72 { "getMemberRefInfoAt0", "(Ljava/lang/Object;I)[Ljava/lang/String;", (void *) (intptr_t) &Java_sun_reflect_ConstantPool_getMemberRefInfoAt0 },
73 { "getIntAt0", "(Ljava/lang/Object;I)I", (void *) (intptr_t) &Java_sun_reflect_ConstantPool_getIntAt0 },
74 { "getLongAt0", "(Ljava/lang/Object;I)J", (void *) (intptr_t) &Java_sun_reflect_ConstantPool_getLongAt0 },
75 { "getFloatAt0", "(Ljava/lang/Object;I)F", (void *) (intptr_t) &Java_sun_reflect_ConstantPool_getFloatAt0 },
76 { "getDoubleAt0", "(Ljava/lang/Object;I)D", (void *) (intptr_t) &Java_sun_reflect_ConstantPool_getDoubleAt0 },
77 { "getStringAt0", "(Ljava/lang/Object;I)Ljava/lang/String;", (void *) (intptr_t) &Java_sun_reflect_ConstantPool_getStringAt0 },
78 { "getUTF8At0", "(Ljava/lang/Object;I)Ljava/lang/String;", (void *) (intptr_t) &Java_sun_reflect_ConstantPool_getUTF8At0 },
82 /* _Jv_sun_reflect_ConstantPool_init ********************************************
84 Register native functions.
86 *******************************************************************************/
88 void _Jv_sun_reflect_ConstantPool_init(void)
90 native_method_register(utf_sun_reflect_ConstantPool, methods, NATIVE_METHODS_COUNT);
94 * Class: sun/reflect/ConstantPool
96 * Signature: (Ljava/lang/Object;)I
98 JNIEXPORT int32_t JNICALL Java_sun_reflect_ConstantPool_getSize0(JNIEnv *env, struct sun_reflect_ConstantPool* this, struct java_lang_Object* jcpool)
100 classinfo *cls = LLNI_classinfo_unwrap(jcpool);
106 * Class: sun/reflect/ConstantPool
107 * Method: getClassAt0
108 * Signature: (Ljava/lang/Object;I)Ljava/lang/Class;
110 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)
112 constant_classref *ref;
113 classinfo *cls = LLNI_classinfo_unwrap(jcpool);
115 ref = (constant_classref*)class_getconstant(
116 cls, index, CONSTANT_Class);
122 return LLNI_classinfo_wrap(resolve_classref_eager(ref));
127 * Class: sun/reflect/ConstantPool
128 * Method: getClassAtIfLoaded0
129 * Signature: (Ljava/lang/Object;I)Ljava/lang/Class;
131 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)
133 constant_classref *ref;
135 classinfo *cls = LLNI_classinfo_unwrap(jcpool);
137 ref = (constant_classref*)class_getconstant(
138 cls, index, CONSTANT_Class);
144 if (!resolve_classref(NULL,ref,resolveLazy,true,true,&c)) {
148 if (c == NULL || !(c->state & CLASS_LOADED)) {
152 return LLNI_classinfo_wrap(c);
157 * Class: sun/reflect/ConstantPool
158 * Method: getMethodAt0
159 * Signature: (Ljava/lang/Object;I)Ljava/lang/reflect/Member;
161 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)
163 constant_FMIref *ref;
164 classinfo *cls = LLNI_classinfo_unwrap(jcpool);
166 ref = (constant_FMIref*)class_getconstant(
167 cls, index, CONSTANT_Methodref);
173 /* XXX: is that right? or do I have to use resolve_method_*? */
174 return (jobject)reflect_method_new(ref->p.method);
179 * Class: sun/reflect/ConstantPool
180 * Method: getMethodAtIfLoaded0
181 * Signature: (Ljava/lang/Object;I)Ljava/lang/reflect/Member;
183 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)
185 constant_FMIref *ref;
187 classinfo *cls = LLNI_classinfo_unwrap(jcpool);
189 ref = (constant_FMIref*)class_getconstant(
190 cls, index, CONSTANT_Methodref);
196 if (!resolve_classref(NULL,ref->p.classref,resolveLazy,true,true,&c)) {
200 if (c == NULL || !(c->state & CLASS_LOADED)) {
204 return (jobject)reflect_method_new(ref->p.method);
209 * Class: sun/reflect/ConstantPool
210 * Method: getFieldAt0
211 * Signature: (Ljava/lang/Object;I)Ljava/lang/reflect/Field;
213 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)
215 constant_FMIref *ref;
216 classinfo *cls = LLNI_classinfo_unwrap(jcpool);
218 ref = (constant_FMIref*)class_getconstant(
219 cls, index, CONSTANT_Fieldref);
225 return (jobject)reflect_field_new(ref->p.field);
230 * Class: sun/reflect/ConstantPool
231 * Method: getFieldAtIfLoaded0
232 * Signature: (Ljava/lang/Object;I)Ljava/lang/reflect/Field;
234 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)
236 constant_FMIref *ref;
238 classinfo *cls = LLNI_classinfo_unwrap(jcpool);
240 ref = (constant_FMIref*)class_getconstant(
241 cls, index, CONSTANT_Fieldref);
247 if (!resolve_classref(NULL,ref->p.classref,resolveLazy,true,true,&c)) {
251 if (c == NULL || !(c->state & CLASS_LOADED)) {
255 return (jobject)reflect_field_new(ref->p.field);
260 * Class: sun/reflect/ConstantPool
261 * Method: getMemberRefInfoAt0
262 * Signature: (Ljava/lang/Object;I)[Ljava/lang/String;
264 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)
266 log_println("Java_sun_reflect_ConstantPool_getMemberRefInfoAt0(env=%p, jcpool=%p, index=%d): IMPLEMENT ME!", env, jcpool, index);
272 * Class: sun/reflect/ConstantPool
274 * Signature: (Ljava/lang/Object;I)I
276 JNIEXPORT int32_t JNICALL Java_sun_reflect_ConstantPool_getIntAt0(JNIEnv *env, struct sun_reflect_ConstantPool* this, struct java_lang_Object* jcpool, int32_t index)
278 constant_integer *ref;
279 classinfo *cls = LLNI_classinfo_unwrap(jcpool);
281 ref = (constant_integer*)class_getconstant(
282 cls, index, CONSTANT_Integer);
293 * Class: sun/reflect/ConstantPool
295 * Signature: (Ljava/lang/Object;I)J
297 JNIEXPORT int64_t JNICALL Java_sun_reflect_ConstantPool_getLongAt0(JNIEnv *env, struct sun_reflect_ConstantPool* this, struct java_lang_Object* jcpool, int32_t index)
300 classinfo *cls = LLNI_classinfo_unwrap(jcpool);
302 ref = (constant_long*)class_getconstant(
303 cls, index, CONSTANT_Long);
314 * Class: sun/reflect/ConstantPool
315 * Method: getFloatAt0
316 * Signature: (Ljava/lang/Object;I)F
318 JNIEXPORT float JNICALL Java_sun_reflect_ConstantPool_getFloatAt0(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_float*)class_getconstant(
324 cls, index, CONSTANT_Float);
335 * Class: sun/reflect/ConstantPool
336 * Method: getDoubleAt0
337 * Signature: (Ljava/lang/Object;I)D
339 JNIEXPORT double JNICALL Java_sun_reflect_ConstantPool_getDoubleAt0(JNIEnv *env, struct sun_reflect_ConstantPool* this, struct java_lang_Object* jcpool, int32_t index)
341 constant_double *ref;
342 classinfo *cls = LLNI_classinfo_unwrap(jcpool);
344 ref = (constant_double*)class_getconstant(
345 cls, index, CONSTANT_Double);
356 * Class: sun/reflect/ConstantPool
357 * Method: getStringAt0
358 * Signature: (Ljava/lang/Object;I)Ljava/lang/String;
360 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)
363 classinfo *cls = LLNI_classinfo_unwrap(jcpool);
365 ref = (utf*)class_getconstant(cls, index, CONSTANT_String);
371 /* XXX: I hope literalstring_new is the right Function. */
372 return (java_lang_String*)literalstring_new(ref);
377 * Class: sun/reflect/ConstantPool
379 * Signature: (Ljava/lang/Object;I)Ljava/lang/String;
381 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)
384 classinfo *cls = LLNI_classinfo_unwrap(jcpool);
386 ref = (utf*)class_getconstant(cls, index, CONSTANT_Utf8);
392 /* XXX: I hope literalstring_new is the right Function. */
393 return (java_lang_String*)literalstring_new(ref);
398 * These are local overrides for various environment variables in Emacs.
399 * Please do not remove this and leave it at the end of the file, where
400 * Emacs will automagically detect them.
401 * ---------------------------------------------------------------------
404 * indent-tabs-mode: t
408 * vim:noexpandtab:sw=4:ts=4: