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"
50 //#include "native/include/sun_reflect_ConstantPool.h"
52 #include "native/vm/reflection.hpp"
54 #include "toolbox/logging.h"
57 #include "vm/exceptions.hpp"
58 #include "vm/resolve.h"
59 #include "vm/string.hpp"
61 #include "vmcore/class.h"
62 #include "vmcore/javaobjects.hpp"
63 #include "vmcore/utf8.h"
69 * Class: sun/reflect/ConstantPool
71 * Signature: (Ljava/lang/Object;)I
73 JNIEXPORT jint JNICALL Java_sun_reflect_ConstantPool_getSize0(JNIEnv *env, jobject _this, jobject jcpool)
75 classinfo *cls = LLNI_classinfo_unwrap(jcpool);
81 * Class: sun/reflect/ConstantPool
83 * Signature: (Ljava/lang/Object;I)Ljava/lang/Class;
85 JNIEXPORT jclass JNICALL Java_sun_reflect_ConstantPool_getClassAt0(JNIEnv *env, jobject _this, jobject jcpool, jint index)
87 constant_classref *ref;
88 classinfo *cls = LLNI_classinfo_unwrap(jcpool);
90 ref = (constant_classref*)class_getconstant(
91 cls, index, CONSTANT_Class);
94 exceptions_throw_illegalargumentexception();
98 return (jclass) LLNI_classinfo_wrap(resolve_classref_eager(ref));
103 * Class: sun/reflect/ConstantPool
104 * Method: getClassAtIfLoaded0
105 * Signature: (Ljava/lang/Object;I)Ljava/lang/Class;
107 JNIEXPORT jclass JNICALL Java_sun_reflect_ConstantPool_getClassAtIfLoaded0(JNIEnv *env, jobject _this, jobject jcpool, jint index)
109 constant_classref *ref;
111 classinfo *cls = LLNI_classinfo_unwrap(jcpool);
113 ref = (constant_classref*)class_getconstant(
114 cls, index, CONSTANT_Class);
117 exceptions_throw_illegalargumentexception();
121 if (!resolve_classref(NULL,ref,resolveLazy,true,true,&c)) {
125 if (c == NULL || !(c->state & CLASS_LOADED)) {
129 return (jclass) LLNI_classinfo_wrap(c);
134 * Class: sun/reflect/ConstantPool
135 * Method: getMethodAt0
136 * Signature: (Ljava/lang/Object;I)Ljava/lang/reflect/Member;
138 JNIEXPORT jobject JNICALL Java_sun_reflect_ConstantPool_getMethodAt0(JNIEnv *env, jobject _this, jobject jcpool, jint index)
140 constant_FMIref *ref;
141 classinfo *cls = LLNI_classinfo_unwrap(jcpool);
143 ref = (constant_FMIref*)class_getconstant(
144 cls, index, CONSTANT_Methodref);
147 exceptions_throw_illegalargumentexception();
151 /* XXX: is that right? or do I have to use resolve_method_*? */
152 return (jobject) java_lang_reflect_Method::create(ref->p.method);
157 * Class: sun/reflect/ConstantPool
158 * Method: getMethodAtIfLoaded0
159 * Signature: (Ljava/lang/Object;I)Ljava/lang/reflect/Member;
161 JNIEXPORT jobject JNICALL Java_sun_reflect_ConstantPool_getMethodAtIfLoaded0(JNIEnv *env, jobject _this, jobject jcpool, jint index)
163 constant_FMIref *ref;
165 classinfo *cls = LLNI_classinfo_unwrap(jcpool);
167 ref = (constant_FMIref*)class_getconstant(
168 cls, index, CONSTANT_Methodref);
171 exceptions_throw_illegalargumentexception();
175 if (!resolve_classref(NULL,ref->p.classref,resolveLazy,true,true,&c)) {
179 if (c == NULL || !(c->state & CLASS_LOADED)) {
183 return (jobject) java_lang_reflect_Method::create(ref->p.method);
188 * Class: sun/reflect/ConstantPool
189 * Method: getFieldAt0
190 * Signature: (Ljava/lang/Object;I)Ljava/lang/reflect/Field;
192 JNIEXPORT jobject JNICALL Java_sun_reflect_ConstantPool_getFieldAt0(JNIEnv *env, jobject _this, jobject jcpool, jint index)
194 constant_FMIref *ref;
195 classinfo *cls = LLNI_classinfo_unwrap(jcpool);
197 ref = (constant_FMIref*)class_getconstant(
198 cls, index, CONSTANT_Fieldref);
201 exceptions_throw_illegalargumentexception();
205 return (jobject) java_lang_reflect_Field::create(ref->p.field);
210 * Class: sun/reflect/ConstantPool
211 * Method: getFieldAtIfLoaded0
212 * Signature: (Ljava/lang/Object;I)Ljava/lang/reflect/Field;
214 JNIEXPORT jobject JNICALL Java_sun_reflect_ConstantPool_getFieldAtIfLoaded0(JNIEnv *env, jobject _this, jobject jcpool, jint index)
216 constant_FMIref *ref;
218 classinfo *cls = LLNI_classinfo_unwrap(jcpool);
220 ref = (constant_FMIref*)class_getconstant(
221 cls, index, CONSTANT_Fieldref);
224 exceptions_throw_illegalargumentexception();
228 if (!resolve_classref(NULL,ref->p.classref,resolveLazy,true,true,&c)) {
232 if (c == NULL || !(c->state & CLASS_LOADED)) {
236 return (jobject) java_lang_reflect_Field::create(ref->p.field);
241 * Class: sun/reflect/ConstantPool
242 * Method: getMemberRefInfoAt0
243 * Signature: (Ljava/lang/Object;I)[Ljava/lang/String;
245 JNIEXPORT jobjectArray JNICALL Java_sun_reflect_ConstantPool_getMemberRefInfoAt0(JNIEnv *env, jobject _this, jobject jcpool, jint index)
247 log_println("Java_sun_reflect_ConstantPool_getMemberRefInfoAt0(env=%p, jcpool=%p, index=%d): IMPLEMENT ME!", env, jcpool, index);
253 * Class: sun/reflect/ConstantPool
255 * Signature: (Ljava/lang/Object;I)I
257 JNIEXPORT jint JNICALL Java_sun_reflect_ConstantPool_getIntAt0(JNIEnv *env, jobject _this, jobject jcpool, jint index)
259 constant_integer *ref;
260 classinfo *cls = LLNI_classinfo_unwrap(jcpool);
262 ref = (constant_integer*)class_getconstant(
263 cls, index, CONSTANT_Integer);
266 exceptions_throw_illegalargumentexception();
275 * Class: sun/reflect/ConstantPool
277 * Signature: (Ljava/lang/Object;I)J
279 JNIEXPORT jlong JNICALL Java_sun_reflect_ConstantPool_getLongAt0(JNIEnv *env, jobject _this, jobject jcpool, jint index)
282 classinfo *cls = LLNI_classinfo_unwrap(jcpool);
284 ref = (constant_long*)class_getconstant(
285 cls, index, CONSTANT_Long);
288 exceptions_throw_illegalargumentexception();
297 * Class: sun/reflect/ConstantPool
298 * Method: getFloatAt0
299 * Signature: (Ljava/lang/Object;I)F
301 JNIEXPORT float JNICALL Java_sun_reflect_ConstantPool_getFloatAt0(JNIEnv *env, jobject _this, jobject jcpool, jint index)
304 classinfo *cls = LLNI_classinfo_unwrap(jcpool);
306 ref = (constant_float*)class_getconstant(
307 cls, index, CONSTANT_Float);
310 exceptions_throw_illegalargumentexception();
319 * Class: sun/reflect/ConstantPool
320 * Method: getDoubleAt0
321 * Signature: (Ljava/lang/Object;I)D
323 JNIEXPORT double JNICALL Java_sun_reflect_ConstantPool_getDoubleAt0(JNIEnv *env, jobject _this, jobject jcpool, jint index)
325 constant_double *ref;
326 classinfo *cls = LLNI_classinfo_unwrap(jcpool);
328 ref = (constant_double*)class_getconstant(
329 cls, index, CONSTANT_Double);
332 exceptions_throw_illegalargumentexception();
341 * Class: sun/reflect/ConstantPool
342 * Method: getStringAt0
343 * Signature: (Ljava/lang/Object;I)Ljava/lang/String;
345 JNIEXPORT jstring JNICALL Java_sun_reflect_ConstantPool_getStringAt0(JNIEnv *env, jobject _this, jobject jcpool, jint index)
348 classinfo *cls = LLNI_classinfo_unwrap(jcpool);
350 ref = (utf*)class_getconstant(cls, index, CONSTANT_String);
353 exceptions_throw_illegalargumentexception();
357 /* XXX: I hope literalstring_new is the right Function. */
358 return (jstring) literalstring_new(ref);
363 * Class: sun/reflect/ConstantPool
365 * Signature: (Ljava/lang/Object;I)Ljava/lang/String;
367 JNIEXPORT jstring JNICALL Java_sun_reflect_ConstantPool_getUTF8At0(JNIEnv *env, jobject _this, jobject jcpool, jint index)
370 classinfo *cls = LLNI_classinfo_unwrap(jcpool);
372 ref = (utf*)class_getconstant(cls, index, CONSTANT_Utf8);
375 exceptions_throw_illegalargumentexception();
379 /* XXX: I hope literalstring_new is the right Function. */
380 return (jstring) literalstring_new(ref);
386 /* native methods implemented by this file ************************************/
388 static JNINativeMethod methods[] = {
389 { (char*) "getSize0", (char*) "(Ljava/lang/Object;I)I", (void*) (uintptr_t) &Java_sun_reflect_ConstantPool_getSize0 },
390 { (char*) "getClassAt0", (char*) "(Ljava/lang/Object;I)Ljava/lang/Class;", (void*) (uintptr_t) &Java_sun_reflect_ConstantPool_getClassAt0 },
391 { (char*) "getClassAtIfLoaded0", (char*) "(Ljava/lang/Object;I)Ljava/lang/Class;", (void*) (uintptr_t) &Java_sun_reflect_ConstantPool_getClassAtIfLoaded0 },
392 { (char*) "getMethodAt0", (char*) "(Ljava/lang/Object;I)Ljava/lang/reflect/Member;", (void*) (uintptr_t) &Java_sun_reflect_ConstantPool_getMethodAt0 },
393 { (char*) "getMethodAtIfLoaded0", (char*) "(Ljava/lang/Object;I)Ljava/lang/reflect/Member;", (void*) (uintptr_t) &Java_sun_reflect_ConstantPool_getMethodAtIfLoaded0 },
394 { (char*) "getFieldAt0", (char*) "(Ljava/lang/Object;I)Ljava/lang/reflect/Field;", (void*) (uintptr_t) &Java_sun_reflect_ConstantPool_getFieldAt0 },
395 { (char*) "getFieldAtIfLoaded0", (char*) "(Ljava/lang/Object;I)Ljava/lang/reflect/Field;", (void*) (uintptr_t) &Java_sun_reflect_ConstantPool_getFieldAtIfLoaded0 },
396 { (char*) "getMemberRefInfoAt0", (char*) "(Ljava/lang/Object;I)[Ljava/lang/String;", (void*) (uintptr_t) &Java_sun_reflect_ConstantPool_getMemberRefInfoAt0 },
397 { (char*) "getIntAt0", (char*) "(Ljava/lang/Object;I)I", (void*) (uintptr_t) &Java_sun_reflect_ConstantPool_getIntAt0 },
398 { (char*) "getLongAt0", (char*) "(Ljava/lang/Object;I)J", (void*) (uintptr_t) &Java_sun_reflect_ConstantPool_getLongAt0 },
399 { (char*) "getFloatAt0", (char*) "(Ljava/lang/Object;I)F", (void*) (uintptr_t) &Java_sun_reflect_ConstantPool_getFloatAt0 },
400 { (char*) "getDoubleAt0", (char*) "(Ljava/lang/Object;I)D", (void*) (uintptr_t) &Java_sun_reflect_ConstantPool_getDoubleAt0 },
401 { (char*) "getStringAt0", (char*) "(Ljava/lang/Object;I)Ljava/lang/String;", (void*) (uintptr_t) &Java_sun_reflect_ConstantPool_getStringAt0 },
402 { (char*) "getUTF8At0", (char*) "(Ljava/lang/Object;I)Ljava/lang/String;", (void*) (uintptr_t) &Java_sun_reflect_ConstantPool_getUTF8At0 },
406 /* _Jv_sun_reflect_ConstantPool_init ******************************************
408 Register native functions.
410 *******************************************************************************/
414 void _Jv_sun_reflect_ConstantPool_init(void)
416 native_method_register(utf_new_char("sun/reflect/ConstantPool"), methods, NATIVE_METHODS_COUNT);
422 * These are local overrides for various environment variables in Emacs.
423 * Please do not remove this and leave it at the end of the file, where
424 * Emacs will automagically detect them.
425 * ---------------------------------------------------------------------
428 * indent-tabs-mode: t
432 * vim:noexpandtab:sw=4:ts=4: