/* src/vmcore/field.c - field functions
- Copyright (C) 1996-2005, 2006, 2007 R. Grafl, A. Krall, C. Kruegel,
- C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
- E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
- J. Wenninger, Institut f. Computersprachen - TU Wien
+ Copyright (C) 1996-2005, 2006, 2007, 2008
+ CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
This file is part of CACAO.
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
- $Id: field.c 8315 2007-08-15 22:49:20Z panzi $
-
*/
#include "mm/memory.h"
-#include "vm/types.h"
+#include "native/llni.h"
-#include "mm/memory.h"
+#include "vm/types.h"
+#include "vm/array.h"
#include "vm/builtin.h"
-#include "vm/exceptions.h"
+#include "vm/exceptions.hpp"
#include "vm/global.h"
-#include "vm/primitive.h"
-#include "vm/stringlocal.h"
-#include "vm/vm.h"
+#include "vm/primitive.hpp"
+#include "vm/string.hpp"
+#include "vm/vm.hpp"
#include "vmcore/annotation.h"
#include "vmcore/class.h"
/* Get class. */
- c = cb->class;
+ c = cb->clazz;
- f->class = c;
+ f->clazz = c;
/* Get access flags. */
break;
case TYPE_ADR:
-#if defined(ENABLE_GC_CACAO)
+#if !defined(ENABLE_GC_BOEHM)
f->value = NEW(imm_union);
#else
f->value = GCNEW_UNCOLLECTABLE(imm_union, 1);
/* load the class of the field-type with the field's
classloader */
- c = load_class_from_classloader(u, f->class->classloader);
+ c = load_class_from_classloader(u, f->clazz->classloader);
}
else {
- c = primitive_class_get_by_type(td->decltype);
+ c = Primitive_get_class_by_type(td->primitivetype);
}
return c;
void field_free(fieldinfo *f)
{
- /* empty */
+ /* free memory for fields which have a value */
+
+ if (f->value)
+#if defined(ENABLE_GC_BOEHM)
+ if (f->type != TYPE_ADR)
+#endif
+ FREE(f->value, imm_union);
}
-#if defined(ENABLE_ANNOTATIONS)
/* field_get_annotations ******************************************************
- Gets a fields' annotations (or NULL if none).
+ Get a fields' unparsed annotations in a byte array.
+
+ IN:
+ f........the field of which the annotations should be returned
+
+ RETURN VALUE:
+ The unparsed annotations in a byte array (or NULL if there aren't any).
*******************************************************************************/
-java_bytearray *field_get_annotations(fieldinfo *f)
+java_handle_bytearray_t *field_get_annotations(fieldinfo *f)
{
- classinfo *c = f->class;
- int slot = f - c->fields;
- annotation_bytearray_t *ba = NULL;
- java_bytearray *annotations = NULL;
-
- if (c->field_annotations != NULL && c->field_annotations->size > slot) {
- ba = c->field_annotations->data[slot];
-
- if (ba != NULL) {
- annotations = builtin_newarray_byte(ba->size);
-
- if (annotations != NULL) {
- MCOPY(annotations->data, ba->data, uint8_t, ba->size);
- }
- }
+#if defined(ENABLE_ANNOTATIONS)
+ classinfo *c; /* declaring class */
+ int slot; /* slot of this field */
+ java_handle_bytearray_t *annotations; /* unparsed annotations */
+ java_handle_t *field_annotations; /* array of unparsed */
+ /* annotations of all fields of the declaring class */
+
+ c = f->clazz;
+ slot = f - c->fields;
+ annotations = NULL;
+
+ LLNI_classinfo_field_get(c, field_annotations, field_annotations);
+
+ /* the field_annotations array might be shorter then the field
+ * count if the fields above a certain index have no annotations.
+ */
+ if (field_annotations != NULL &&
+ array_length_get(field_annotations) > slot) {
+ annotations = (java_handle_bytearray_t*)array_objectarray_element_get(
+ (java_handle_objectarray_t*)field_annotations, slot);
}
return annotations;
-}
+#else
+ return NULL;
#endif
+}
/* field_printflags ************************************************************
return;
}
- utf_display_printable_ascii_classname(f->class->name);
+ utf_display_printable_ascii_classname(f->clazz->name);
printf(".");
utf_display_printable_ascii(f->name);
printf(" ");
utf_display_printable_ascii(f->descriptor);
field_printflags(f);
+
+ if (!(f->flags & ACC_STATIC)) {
+ printf(", offset: %d", f->offset);
+ }
}
#endif
* c-basic-offset: 4
* tab-width: 4
* End:
+ * vim:noexpandtab:sw=4:ts=4:
*/