Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
- $Id: java_lang_Class.c 8249 2007-07-31 12:59:03Z panzi $
-
*/
#include "mm/memory.h"
#include "native/jni.h"
+#include "native/llni.h"
#include "native/native.h"
/* keep this order of the native includes */
#endif
#include "native/vm/java_lang_Class.h"
-#include "native/vm/java_lang_String.h"
#if defined(ENABLE_JAVASE)
# include "native/vm/reflect.h"
#include "vm/exceptions.h"
#include "vm/global.h"
#include "vm/initialize.h"
+#include "vm/primitive.h"
#include "vm/resolve.h"
#include "vm/stringlocal.h"
#include "vmcore/class.h"
#include "vmcore/loader.h"
-#include "vmcore/primitive.h"
#if defined(WITH_CLASSPATH_GNU) && defined(ENABLE_ANNOTATIONS)
+#include "vm/vm.h"
#include "vmcore/annotation.h"
#include "native/include/sun_reflect_ConstantPool.h"
#endif
{
classinfo *c;
java_lang_String *s;
+ java_chararray_t *ca;
u4 i;
- c = (classinfo *) klass;
+ c = LLNI_classinfo_unwrap(klass);
/* create a java string */
/* return string where '/' is replaced by '.' */
- for (i = 0; i < s->value->header.size; i++) {
- if (s->value->data[i] == '/')
- s->value->data[i] = '.';
+ LLNI_field_get_ref(s, value, ca);
+
+ for (i = 0; i < LLNI_array_size(ca); i++) {
+ if (LLNI_array_direct(ca, i) == '/')
+ LLNI_array_direct(ca, i) = '.';
}
return s;
#endif
{
#if defined(ENABLE_JAVASE)
- java_objectheader *cl;
+ classloader *cl;
#endif
- utf *ufile;
- utf *uname;
- classinfo *c;
- u2 *pos;
- s4 i;
+ utf *ufile;
+ utf *uname;
+ classinfo *c;
+ u2 *pos;
+ s4 i;
#if defined(ENABLE_JAVASE)
- cl = (java_objectheader *) loader;
+ cl = (classloader *) loader;
#endif
/* illegal argument */
/* create utf string in which '.' is replaced by '/' */
- ufile = javastring_toutf((java_objectheader *) name, true);
- uname = javastring_toutf((java_objectheader *) name, false);
+ ufile = javastring_toutf((java_handle_t *) name, true);
+ uname = javastring_toutf((java_handle_t *) name, false);
/* name must not contain '/' (mauve test) */
- for (i = 0, pos = name->value->data + name->offset; i < name->count; i++, pos++) {
+ for (i = 0, pos = LLNI_field_direct(name, value)->data + LLNI_field_direct(name, offset); i < LLNI_field_direct(name, count); i++, pos++) {
if (*pos == '/') {
exceptions_throw_classnotfoundexception(uname);
return NULL;
if (!initialize_class(c))
return NULL;
- return (java_lang_Class *) c;
+ return LLNI_classinfo_wrap(c);
}
*/
s4 _Jv_java_lang_Class_isInstance(java_lang_Class *klass, java_lang_Object *o)
{
- classinfo *c;
- java_objectheader *ob;
+ classinfo *c;
+ java_handle_t *ob;
- c = (classinfo *) klass;
- ob = (java_objectheader *) o;
+ c = LLNI_classinfo_unwrap(klass);
+ ob = (java_handle_t *) o;
if (!(c->state & CLASS_LINKED))
if (!link_class(c))
classinfo *kc;
classinfo *cc;
- kc = (classinfo *) klass;
- cc = (classinfo *) c;
+ kc = LLNI_classinfo_unwrap(klass);
+ cc = LLNI_classinfo_unwrap(c);
if (cc == NULL) {
exceptions_throw_nullpointerexception();
{
classinfo *c;
- c = (classinfo *) this;
+ c = LLNI_classinfo_unwrap(this);
return class_is_interface(c);
}
{
classinfo *c;
- c = (classinfo *) klass;
+ c = LLNI_classinfo_unwrap(klass);
return class_is_primitive(c);
}
classinfo *c;
classinfo *super;
- c = (classinfo *) klass;
+ c = LLNI_classinfo_unwrap(klass);
super = class_get_superclass(c);
- return super;
+ return LLNI_classinfo_wrap(super);
}
* Method: getInterfaces
* Signature: ()[Ljava/lang/Class;
*/
-java_objectarray *_Jv_java_lang_Class_getInterfaces(java_lang_Class *klass)
+java_handle_objectarray_t *_Jv_java_lang_Class_getInterfaces(java_lang_Class *klass)
{
- classinfo *c;
- classinfo *ic;
- java_objectarray *oa;
- u4 i;
+ classinfo *c;
+ java_handle_objectarray_t *oa;
- c = (classinfo *) klass;
-
- if (!(c->state & CLASS_LINKED))
- if (!link_class(c))
- return NULL;
+ c = LLNI_classinfo_unwrap(klass);
- oa = builtin_anewarray(c->interfacescount, class_java_lang_Class);
-
- if (oa == NULL)
- return NULL;
-
- for (i = 0; i < c->interfacescount; i++) {
- ic = c->interfaces[i].cls;
-
- oa->data[i] = (java_objectheader *) ic;
- }
+ oa = class_get_interfaces(c);
return oa;
}
-/*
- * Class: java/lang/Class
- * Method: getComponentType
- * Signature: ()Ljava/lang/Class;
- */
-java_lang_Class *_Jv_java_lang_Class_getComponentType(java_lang_Class *klass)
-{
- classinfo *c;
- classinfo *comp;
- arraydescriptor *desc;
-
- c = (classinfo *) klass;
-
- /* XXX maybe we could find a way to do this without linking. */
- /* This way should be safe and easy, however. */
-
- if (!(c->state & CLASS_LINKED))
- if (!link_class(c))
- return NULL;
-
- desc = c->vftbl->arraydesc;
-
- if (desc == NULL)
- return NULL;
-
- if (desc->arraytype == ARRAYTYPE_OBJECT)
- comp = desc->componentvftbl->class;
- else
- comp = primitive_class_get_by_type(desc->arraytype);
-
- return (java_lang_Class *) comp;
-}
-
-
/*
* Class: java/lang/Class
* Method: getModifiers
utf *innername;
s4 i;
- c = (classinfo *) klass;
+ c = LLNI_classinfo_unwrap(klass);
if (!ignoreInnerClassesAttrib && (c->innerclasscount != 0)) {
/* search for passed class as inner class */
java_lang_Class *_Jv_java_lang_Class_getDeclaringClass(java_lang_Class *klass)
{
classinfo *c;
+ classinfo *dc;
- c = (classinfo *) klass;
+ c = LLNI_classinfo_unwrap(klass);
- return (java_lang_Class *) class_get_declaringclass(c);
+ dc = class_get_declaringclass(c);
+
+ return LLNI_classinfo_wrap(dc);
}
* Method: getDeclaredClasses
* Signature: (Z)[Ljava/lang/Class;
*/
-java_objectarray *_Jv_java_lang_Class_getDeclaredClasses(java_lang_Class *klass, s4 publicOnly)
+java_handle_objectarray_t *_Jv_java_lang_Class_getDeclaredClasses(java_lang_Class *klass, s4 publicOnly)
{
- classinfo *c;
- classref_or_classinfo outer;
- utf *outername;
- s4 declaredclasscount; /* number of declared classes */
- s4 pos; /* current declared class */
- java_objectarray *oa; /* array of declared classes */
- s4 i;
+ classinfo *c;
+ java_handle_objectarray_t *oa;
- c = (classinfo *) klass;
- declaredclasscount = 0;
+ c = LLNI_classinfo_unwrap(klass);
- if (!class_is_primitive(c) && (c->name->text[0] != '[')) {
- /* determine number of declared classes */
-
- for (i = 0; i < c->innerclasscount; i++) {
- outer = c->innerclass[i].outer_class;
-
- /* check if outer_class is a classref or a real class and
- get the class name from the structure */
-
- outername = IS_CLASSREF(outer) ? outer.ref->name : outer.cls->name;
-
- /* outer class is this class */
-
- if ((outername == c->name) &&
- ((publicOnly == 0) || (c->innerclass[i].flags & ACC_PUBLIC)))
- declaredclasscount++;
- }
- }
-
- /* allocate Class[] and check for OOM */
-
- oa = builtin_anewarray(declaredclasscount, class_java_lang_Class);
-
- if (oa == NULL)
- return NULL;
-
- for (i = 0, pos = 0; i < c->innerclasscount; i++) {
- outer = c->innerclass[i].outer_class;
-
- /* check if outer_class is a classref or a real class and
- get the class name from the structure */
-
- outername = IS_CLASSREF(outer) ? outer.ref->name : outer.cls->name;
-
- /* outer class is this class */
-
- if ((outername == c->name) &&
- ((publicOnly == 0) || (c->innerclass[i].flags & ACC_PUBLIC))) {
- classinfo *inner;
-
- if ((inner = resolve_classref_or_classinfo_eager(
- c->innerclass[i].inner_class,
- false)) == NULL)
- return NULL;
-
- if (!(inner->state & CLASS_LINKED))
- if (!link_class(inner))
- return NULL;
-
- oa->data[pos++] = (java_objectheader *) inner;
- }
- }
+ oa = class_get_declaredclasses(c, publicOnly);
return oa;
}
* Method: getDeclaredFields
* Signature: (Z)[Ljava/lang/reflect/Field;
*/
-java_objectarray *_Jv_java_lang_Class_getDeclaredFields(java_lang_Class *klass, s4 publicOnly)
+java_handle_objectarray_t *_Jv_java_lang_Class_getDeclaredFields(java_lang_Class *klass, s4 publicOnly)
{
- classinfo *c;
- java_objectarray *oa; /* result: array of field-objects */
- fieldinfo *f;
- java_lang_reflect_Field *rf;
+ classinfo *c;
+ java_handle_objectarray_t *oa; /* result: array of field-objects */
+ fieldinfo *f;
+ java_lang_reflect_Field *rf;
s4 public_fields; /* number of elements in field-array */
s4 pos;
s4 i;
- c = (classinfo *) klass;
+ c = LLNI_classinfo_unwrap(klass);
/* determine number of fields */
/* store object into array */
- oa->data[pos++] = (java_objectheader *) rf;
+ LLNI_objectarray_element_set(oa, pos, rf);
+ pos++;
}
}
* Method: getDeclaredMethods
* Signature: (Z)[Ljava/lang/reflect/Method;
*/
-java_objectarray *_Jv_java_lang_Class_getDeclaredMethods(java_lang_Class *klass, s4 publicOnly)
+java_handle_objectarray_t *_Jv_java_lang_Class_getDeclaredMethods(java_lang_Class *klass, s4 publicOnly)
{
- classinfo *c;
- java_lang_reflect_Method *rm;
- java_objectarray *oa; /* result: array of Method-objects */
- methodinfo *m; /* the current method to be represented */
+ classinfo *c;
+ java_lang_reflect_Method *rm;
+ java_handle_objectarray_t *oa; /* result: array of Method-objects */
+ methodinfo *m; /* the current method to be represented */
s4 public_methods; /* number of public methods of the class */
s4 pos;
s4 i;
- c = (classinfo *) klass;
+ c = LLNI_classinfo_unwrap(klass);
public_methods = 0;
/* store object into array */
- oa->data[pos++] = (java_objectheader *) rm;
+ LLNI_objectarray_element_set(oa, pos, rm);
+ pos++;
}
}
* Method: getDeclaredConstructors
* Signature: (Z)[Ljava/lang/reflect/Constructor;
*/
-java_objectarray *_Jv_java_lang_Class_getDeclaredConstructors(java_lang_Class *klass, s4 publicOnly)
+java_handle_objectarray_t *_Jv_java_lang_Class_getDeclaredConstructors(java_lang_Class *klass, s4 publicOnly)
{
classinfo *c;
methodinfo *m; /* the current method to be represented */
- java_objectarray *oa; /* result: array of Method-objects */
+ java_handle_objectarray_t *oa; /* result: array of Method-objects */
java_lang_reflect_Constructor *rc;
s4 public_methods; /* number of public methods of the class */
s4 pos;
s4 i;
- c = (classinfo *) klass;
+ c = LLNI_classinfo_unwrap(klass);
/* determine number of constructors */
/* store object into array */
- oa->data[pos++] = (java_objectheader *) rc;
+ LLNI_objectarray_element_set(oa, pos, rc);
+ pos++;
}
}
{
classinfo *c;
- c = (classinfo *) klass;
+ c = LLNI_classinfo_unwrap(klass);
return (java_lang_ClassLoader *) c->classloader;
}
{
classinfo *c;
- c = (classinfo *) this;
+ c = LLNI_classinfo_unwrap(this);
return class_is_array(c);
}
*/
void _Jv_java_lang_Class_throwException(java_lang_Throwable *t)
{
- java_objectheader *o;
+ java_handle_t *o;
- o = (java_objectheader *) t;
+ o = (java_handle_t *) t;
exceptions_set_exception(o);
}
* Method: getDeclaredAnnotations
* Signature: (Ljava/lang/Class;)[Ljava/lang/annotation/Annotation;
*/
-java_objectarray *_Jv_java_lang_Class_getDeclaredAnnotations(java_lang_Class* klass)
+java_handle_objectarray_t *_Jv_java_lang_Class_getDeclaredAnnotations(java_lang_Class* klass)
{
- classinfo *c = (classinfo*)klass;
- methodinfo *m = NULL;
- utf *utf_parseAnnotationsIntoArray = NULL;
- utf *utf_desc = NULL;
- java_bytearray *annotations = NULL;
- sun_reflect_ConstantPool *constantPool = NULL;
-
- if (c == NULL) {
+ classinfo *c = NULL;
+ static methodinfo *m_parseAnnotationsIntoArray = NULL;
+ utf *utf_parseAnnotationsIntoArray = NULL;
+ utf *utf_desc = NULL;
+ java_handle_bytearray_t *annotations = NULL;
+ sun_reflect_ConstantPool *constantPool = NULL;
+ java_lang_Object *constantPoolOop = (java_lang_Object*)klass;
+
+ if (klass == NULL) {
exceptions_throw_nullpointerexception();
return NULL;
}
- /* Return null for arrays and primitives: */
- if (class_is_primitive(c) || class_is_array(c)) {
- return NULL;
- }
+ c = LLNI_classinfo_unwrap(klass);
- if (c->annotations != NULL) {
- uint32_t size = c->annotations->size;
- annotations = builtin_newarray_byte(size);
+ /* get annotations: */
+ annotations = class_get_annotations(c);
- if(annotations != NULL)
- {
- MCOPY(annotations->data, c->annotations->data, uint8_t, size);
- }
+ if (exceptions_get_exception() != NULL) {
+ /* the only exception possible here should be a out of memory exception
+ * raised by copying the annotations into a java bytearray */
+ return NULL;
}
constantPool =
return NULL;
}
- constantPool->constantPoolOop = (java_lang_Object*)klass;
-
- utf_parseAnnotationsIntoArray = utf_new_char("parseAnnotationsIntoArray");
- utf_desc = utf_new_char(
- "([BLsun/reflect/ConstantPool;Ljava/lang/Class;)[Ljava/lang/annotation/Annotation;");
-
- if (utf_parseAnnotationsIntoArray == NULL || utf_desc == NULL) {
- /* out of memory */
- return NULL;
- }
-
- m = class_resolveclassmethod(
- class_sun_reflect_annotation_AnnotationParser,
- utf_parseAnnotationsIntoArray,
- utf_desc,
- class_java_lang_Class,
- true);
-
- if (m == NULL) {
- /* method not found */
- return NULL;
- }
-
- return vm_call_method(m, NULL, annotations, constantPool, klass);
-}
-#endif
-
-
-/*
- * Class: java/lang/Class
- * Method: getEnclosingClass
- * Signature: (Ljava/lang/Class;)Ljava/lang/Class;
- */
-java_lang_Class *_Jv_java_lang_Class_getEnclosingClass(java_lang_Class *klass)
-{
- classinfo *c;
- classref_or_classinfo cr;
- classinfo *ec;
-
- c = (classinfo *) klass;
-
- /* get enclosing class */
+ LLNI_field_set_ref(constantPool, constantPoolOop, constantPoolOop);
- cr = c->enclosingclass;
+ /* only resolve the method the first time */
+ if (m_parseAnnotationsIntoArray == NULL) {
+ utf_parseAnnotationsIntoArray = utf_new_char("parseAnnotationsIntoArray");
+ utf_desc = utf_new_char(
+ "([BLsun/reflect/ConstantPool;Ljava/lang/Class;)"
+ "[Ljava/lang/annotation/Annotation;");
- if (cr.any == NULL)
- return NULL;
-
- /* resolve the class if necessary */
+ if (utf_parseAnnotationsIntoArray == NULL || utf_desc == NULL) {
+ /* out of memory */
+ return NULL;
+ }
- if (IS_CLASSREF(cr)) {
- ec = resolve_classref_eager(cr.ref);
+ m_parseAnnotationsIntoArray = class_resolveclassmethod(
+ class_sun_reflect_annotation_AnnotationParser,
+ utf_parseAnnotationsIntoArray,
+ utf_desc,
+ class_java_lang_Class,
+ true);
- if (ec == NULL)
+ if (m_parseAnnotationsIntoArray == NULL) {
+ /* method not found */
return NULL;
+ }
}
- else
- ec = cr.cls;
- return (java_lang_Class *) ec;
+ return (java_handle_objectarray_t*)vm_call_method(
+ m_parseAnnotationsIntoArray, NULL,
+ annotations, constantPool, klass);
}
+#endif
/* _Jv_java_lang_Class_getEnclosingMethod_intern *******************************
static methodinfo *_Jv_java_lang_Class_getEnclosingMethod_intern(classinfo *c)
{
- classref_or_classinfo cr;
- constant_nameandtype *cn;
- classinfo *ec;
- methodinfo *m;
+ constant_nameandtype *cn;
+ classinfo *ec;
+ methodinfo *m;
/* get enclosing class and method */
- cr = c->enclosingclass;
+ ec = class_get_enclosingclass(c);
cn = c->enclosingmethod;
/* check for enclosing class and method */
- if (cr.any == NULL)
+ if (ec == NULL)
return NULL;
if (cn == NULL)
return NULL;
- /* resolve the class if necessary */
-
- if (IS_CLASSREF(cr)) {
- ec = resolve_classref_eager(cr.ref);
-
- if (ec == NULL)
- return NULL;
- }
- else
- ec = cr.cls;
-
/* find method in enclosing class */
m = class_findmethod(ec, cn->name, cn->descriptor);
methodinfo *m;
java_lang_reflect_Constructor *rc;
- c = (classinfo *) klass;
+ c = LLNI_classinfo_unwrap(klass);
/* get enclosing method */
methodinfo *m;
java_lang_reflect_Method *rm;
- c = (classinfo *) klass;
+ c = LLNI_classinfo_unwrap(klass);
/* get enclosing method */
*/
java_lang_String *_Jv_java_lang_Class_getClassSignature(java_lang_Class* klass)
{
- classinfo *c;
- java_objectheader *o;
+ classinfo *c;
+ java_handle_t *o;
- c = (classinfo *) klass;
+ c = LLNI_classinfo_unwrap(klass);
if (c->signature == NULL)
return NULL;
return (java_lang_String *) o;
}
-
-#if 0
-/*
- * Class: java/lang/Class
- * Method: isAnonymousClass
- * Signature: (Ljava/lang/Class;)Z
- */
-s4 _Jv_java_lang_Class_isAnonymousClass(JNIEnv *env, jclass clazz, struct java_lang_Class* par1);
-
-
-/*
- * Class: java/lang/VMClass
- * Method: isLocalClass
- * Signature: (Ljava/lang/Class;)Z
- */
-JNIEXPORT s4 JNICALL Java_java_lang_VMClass_isLocalClass(JNIEnv *env, jclass clazz, struct java_lang_Class* par1);
-
-
-/*
- * Class: java/lang/VMClass
- * Method: isMemberClass
- * Signature: (Ljava/lang/Class;)Z
- */
-JNIEXPORT s4 JNICALL Java_java_lang_VMClass_isMemberClass(JNIEnv *env, jclass clazz, struct java_lang_Class* par1);
-#endif
-
#endif /* ENABLE_JAVASE */