Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
- $Id: java_lang_Class.c 8311 2007-08-15 17:03:40Z panzi $
-
*/
#endif
#include "native/vm/java_lang_Class.h"
-#include "native/vm/java_lang_String.h"
#if defined(ENABLE_JAVASE)
# include "native/vm/reflect.h"
{
classinfo *c;
java_lang_String *s;
- java_chararray *ca;
+ java_chararray_t *ca;
u4 i;
- c = (classinfo *) klass;
+ c = LLNI_classinfo_unwrap(klass);
/* create a java string */
LLNI_field_get_ref(s, value, ca);
- for (i = 0; i < ca->header.size; i++) {
- if (ca->data[i] == '/')
- ca->data[i] = '.';
+ for (i = 0; i < LLNI_array_size(ca); i++) {
+ if (LLNI_array_direct(ca, i) == '/')
+ LLNI_array_direct(ca, i) = '.';
}
return s;
if (!initialize_class(c))
return NULL;
- return (java_lang_Class *) c;
+ return LLNI_classinfo_wrap(c);
}
classinfo *c;
java_handle_t *ob;
- c = (classinfo *) klass;
+ c = LLNI_classinfo_unwrap(klass);
ob = (java_handle_t *) o;
if (!(c->state & CLASS_LINKED))
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 (java_lang_Class *) 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;
- java_objectarray *oa;
+ classinfo *c;
+ java_handle_objectarray_t *oa;
- c = (classinfo *) klass;
+ c = LLNI_classinfo_unwrap(klass);
oa = class_get_interfaces(c);
}
-/*
- * 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 = LLNI_classinfo_unwrap(klass);
- c = (classinfo *) klass;
+ dc = class_get_declaringclass(c);
- return (java_lang_Class *) 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;
- java_objectarray *oa;
+ classinfo *c;
+ java_handle_objectarray_t *oa;
- c = (classinfo *) klass;
+ c = LLNI_classinfo_unwrap(klass);
oa = class_get_declaredclasses(c, publicOnly);
* 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++] = 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++] = 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++] = 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);
}
* 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;
+ classinfo *c = NULL;
static methodinfo *m_parseAnnotationsIntoArray = NULL;
utf *utf_parseAnnotationsIntoArray = NULL;
utf *utf_desc = NULL;
- java_bytearray *annotations = NULL;
+ java_handle_bytearray_t *annotations = NULL;
sun_reflect_ConstantPool *constantPool = NULL;
- uint32_t size = 0;
java_lang_Object *constantPoolOop = (java_lang_Object*)klass;
- if (c == NULL) {
+ 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) {
- 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 (java_objectarray*)vm_call_method(
+ return (java_handle_objectarray_t*)vm_call_method(
m_parseAnnotationsIntoArray, 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 */
-
- cr = c->enclosingclass;
-
- if (cr.any == 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;
-
- return (java_lang_Class *) ec;
-}
-
-
/* _Jv_java_lang_Class_getEnclosingMethod_intern *******************************
Helper function for _Jv_java_lang_Class_getEnclosingConstructor and
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 */
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 */