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.hpp"
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/javaobjects.hpp"
59 #include "vm/resolve.h"
60 #include "vm/string.hpp"
65 // Native functions are exported as C functions.
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 java_lang_reflect_Method jlrm(ref->p.method);
154 return (jobject) jlrm.get_handle();
159 * Class: sun/reflect/ConstantPool
160 * Method: getMethodAtIfLoaded0
161 * Signature: (Ljava/lang/Object;I)Ljava/lang/reflect/Member;
163 JNIEXPORT jobject JNICALL Java_sun_reflect_ConstantPool_getMethodAtIfLoaded0(JNIEnv *env, jobject _this, jobject jcpool, jint index)
165 constant_FMIref *ref;
167 classinfo *cls = LLNI_classinfo_unwrap(jcpool);
169 ref = (constant_FMIref*)class_getconstant(
170 cls, index, CONSTANT_Methodref);
173 exceptions_throw_illegalargumentexception();
177 if (!resolve_classref(NULL,ref->p.classref,resolveLazy,true,true,&c)) {
181 if (c == NULL || !(c->state & CLASS_LOADED)) {
185 java_lang_reflect_Method jlrm(ref->p.method);
187 return (jobject) jlrm.get_handle();
192 * Class: sun/reflect/ConstantPool
193 * Method: getFieldAt0
194 * Signature: (Ljava/lang/Object;I)Ljava/lang/reflect/Field;
196 JNIEXPORT jobject JNICALL Java_sun_reflect_ConstantPool_getFieldAt0(JNIEnv *env, jobject _this, jobject jcpool, jint index)
198 constant_FMIref *ref;
199 classinfo *cls = LLNI_classinfo_unwrap(jcpool);
201 ref = (constant_FMIref*) class_getconstant(cls, index, CONSTANT_Fieldref);
204 exceptions_throw_illegalargumentexception();
208 // Create a new java.lang.reflect.Field Java object.
209 java_lang_reflect_Field jlrf(ref->p.field);
211 return (jobject) jlrf.get_handle();
216 * Class: sun/reflect/ConstantPool
217 * Method: getFieldAtIfLoaded0
218 * Signature: (Ljava/lang/Object;I)Ljava/lang/reflect/Field;
220 JNIEXPORT jobject JNICALL Java_sun_reflect_ConstantPool_getFieldAtIfLoaded0(JNIEnv *env, jobject _this, jobject jcpool, jint index)
222 constant_FMIref *ref;
224 classinfo *cls = LLNI_classinfo_unwrap(jcpool);
226 ref = (constant_FMIref*) class_getconstant(cls, index, CONSTANT_Fieldref);
229 exceptions_throw_illegalargumentexception();
233 if (!resolve_classref(NULL,ref->p.classref,resolveLazy,true,true,&c)) {
237 if (c == NULL || !(c->state & CLASS_LOADED)) {
241 // Create a new java.lang.reflect.Field Java object.
242 java_lang_reflect_Field jlrf(ref->p.field);
244 return (jobject) jlrf.get_handle();
249 * Class: sun/reflect/ConstantPool
250 * Method: getMemberRefInfoAt0
251 * Signature: (Ljava/lang/Object;I)[Ljava/lang/String;
253 JNIEXPORT jobjectArray JNICALL Java_sun_reflect_ConstantPool_getMemberRefInfoAt0(JNIEnv *env, jobject _this, jobject jcpool, jint index)
255 log_println("Java_sun_reflect_ConstantPool_getMemberRefInfoAt0(env=%p, jcpool=%p, index=%d): IMPLEMENT ME!", env, jcpool, index);
261 * Class: sun/reflect/ConstantPool
263 * Signature: (Ljava/lang/Object;I)I
265 JNIEXPORT jint JNICALL Java_sun_reflect_ConstantPool_getIntAt0(JNIEnv *env, jobject _this, jobject jcpool, jint index)
267 constant_integer *ref;
268 classinfo *cls = LLNI_classinfo_unwrap(jcpool);
270 ref = (constant_integer*) class_getconstant(cls, index, CONSTANT_Integer);
273 exceptions_throw_illegalargumentexception();
282 * Class: sun/reflect/ConstantPool
284 * Signature: (Ljava/lang/Object;I)J
286 JNIEXPORT jlong JNICALL Java_sun_reflect_ConstantPool_getLongAt0(JNIEnv *env, jobject _this, jobject jcpool, jint index)
289 classinfo *cls = LLNI_classinfo_unwrap(jcpool);
291 ref = (constant_long*)class_getconstant(
292 cls, index, CONSTANT_Long);
295 exceptions_throw_illegalargumentexception();
304 * Class: sun/reflect/ConstantPool
305 * Method: getFloatAt0
306 * Signature: (Ljava/lang/Object;I)F
308 JNIEXPORT float JNICALL Java_sun_reflect_ConstantPool_getFloatAt0(JNIEnv *env, jobject _this, jobject jcpool, jint index)
311 classinfo *cls = LLNI_classinfo_unwrap(jcpool);
313 ref = (constant_float*)class_getconstant(
314 cls, index, CONSTANT_Float);
317 exceptions_throw_illegalargumentexception();
326 * Class: sun/reflect/ConstantPool
327 * Method: getDoubleAt0
328 * Signature: (Ljava/lang/Object;I)D
330 JNIEXPORT double JNICALL Java_sun_reflect_ConstantPool_getDoubleAt0(JNIEnv *env, jobject _this, jobject jcpool, jint index)
332 constant_double *ref;
333 classinfo *cls = LLNI_classinfo_unwrap(jcpool);
335 ref = (constant_double*)class_getconstant(
336 cls, index, CONSTANT_Double);
339 exceptions_throw_illegalargumentexception();
348 * Class: sun/reflect/ConstantPool
349 * Method: getStringAt0
350 * Signature: (Ljava/lang/Object;I)Ljava/lang/String;
352 JNIEXPORT jstring JNICALL Java_sun_reflect_ConstantPool_getStringAt0(JNIEnv *env, jobject _this, jobject jcpool, jint index)
355 classinfo *cls = LLNI_classinfo_unwrap(jcpool);
357 ref = (utf*)class_getconstant(cls, index, CONSTANT_String);
360 exceptions_throw_illegalargumentexception();
364 /* XXX: I hope literalstring_new is the right Function. */
365 return (jstring) literalstring_new(ref);
370 * Class: sun/reflect/ConstantPool
372 * Signature: (Ljava/lang/Object;I)Ljava/lang/String;
374 JNIEXPORT jstring JNICALL Java_sun_reflect_ConstantPool_getUTF8At0(JNIEnv *env, jobject _this, jobject jcpool, jint index)
377 classinfo *cls = LLNI_classinfo_unwrap(jcpool);
379 ref = (utf*)class_getconstant(cls, index, CONSTANT_Utf8);
382 exceptions_throw_illegalargumentexception();
386 /* XXX: I hope literalstring_new is the right Function. */
387 return (jstring) literalstring_new(ref);
393 /* native methods implemented by this file ************************************/
395 static JNINativeMethod methods[] = {
396 { (char*) "getSize0", (char*) "(Ljava/lang/Object;I)I", (void*) (uintptr_t) &Java_sun_reflect_ConstantPool_getSize0 },
397 { (char*) "getClassAt0", (char*) "(Ljava/lang/Object;I)Ljava/lang/Class;", (void*) (uintptr_t) &Java_sun_reflect_ConstantPool_getClassAt0 },
398 { (char*) "getClassAtIfLoaded0", (char*) "(Ljava/lang/Object;I)Ljava/lang/Class;", (void*) (uintptr_t) &Java_sun_reflect_ConstantPool_getClassAtIfLoaded0 },
399 { (char*) "getMethodAt0", (char*) "(Ljava/lang/Object;I)Ljava/lang/reflect/Member;", (void*) (uintptr_t) &Java_sun_reflect_ConstantPool_getMethodAt0 },
400 { (char*) "getMethodAtIfLoaded0", (char*) "(Ljava/lang/Object;I)Ljava/lang/reflect/Member;", (void*) (uintptr_t) &Java_sun_reflect_ConstantPool_getMethodAtIfLoaded0 },
401 { (char*) "getFieldAt0", (char*) "(Ljava/lang/Object;I)Ljava/lang/reflect/Field;", (void*) (uintptr_t) &Java_sun_reflect_ConstantPool_getFieldAt0 },
402 { (char*) "getFieldAtIfLoaded0", (char*) "(Ljava/lang/Object;I)Ljava/lang/reflect/Field;", (void*) (uintptr_t) &Java_sun_reflect_ConstantPool_getFieldAtIfLoaded0 },
403 { (char*) "getMemberRefInfoAt0", (char*) "(Ljava/lang/Object;I)[Ljava/lang/String;", (void*) (uintptr_t) &Java_sun_reflect_ConstantPool_getMemberRefInfoAt0 },
404 { (char*) "getIntAt0", (char*) "(Ljava/lang/Object;I)I", (void*) (uintptr_t) &Java_sun_reflect_ConstantPool_getIntAt0 },
405 { (char*) "getLongAt0", (char*) "(Ljava/lang/Object;I)J", (void*) (uintptr_t) &Java_sun_reflect_ConstantPool_getLongAt0 },
406 { (char*) "getFloatAt0", (char*) "(Ljava/lang/Object;I)F", (void*) (uintptr_t) &Java_sun_reflect_ConstantPool_getFloatAt0 },
407 { (char*) "getDoubleAt0", (char*) "(Ljava/lang/Object;I)D", (void*) (uintptr_t) &Java_sun_reflect_ConstantPool_getDoubleAt0 },
408 { (char*) "getStringAt0", (char*) "(Ljava/lang/Object;I)Ljava/lang/String;", (void*) (uintptr_t) &Java_sun_reflect_ConstantPool_getStringAt0 },
409 { (char*) "getUTF8At0", (char*) "(Ljava/lang/Object;I)Ljava/lang/String;", (void*) (uintptr_t) &Java_sun_reflect_ConstantPool_getUTF8At0 },
413 /* _Jv_sun_reflect_ConstantPool_init ******************************************
415 Register native functions.
417 *******************************************************************************/
421 void _Jv_sun_reflect_ConstantPool_init(void)
423 native_method_register(utf_new_char("sun/reflect/ConstantPool"), methods, NATIVE_METHODS_COUNT);
429 * These are local overrides for various environment variables in Emacs.
430 * Please do not remove this and leave it at the end of the file, where
431 * Emacs will automagically detect them.
432 * ---------------------------------------------------------------------
435 * indent-tabs-mode: t
439 * vim:noexpandtab:sw=4:ts=4: