* src/vm/jit/oprofile-agent.cpp: Set source formatting to c++.
[cacao.git] / src / vmcore / field.c
index 98e29f2a6a6ebaee94f69dfc26c0fe30ca05759d..4adcc03bbb5cdbe8416866c10d3156c9b29c9927 100644 (file)
@@ -1,9 +1,7 @@
 /* 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.
 
@@ -22,8 +20,6 @@
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301, USA.
 
-   $Id: field.c 8288 2007-08-10 15:12:00Z twisti $
-
 */
 
 
 
 #include "mm/memory.h"
 
-#include "vm/types.h"
+#include "native/llni.h"
 
-#include "mm/memory.h"
+#include "vm/types.h"
 
-#include "vm/exceptions.h"
+#include "vm/array.h"
+#include "vm/builtin.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"
@@ -74,9 +72,9 @@ bool field_load(classbuffer *cb, fieldinfo *f, descriptor_pool *descpool)
 
        /* Get class. */
 
-       c = cb->class;
+       c = cb->clazz;
 
-       f->class = c;
+       f->clazz = c;
 
        /* Get access flags. */
 
@@ -163,7 +161,7 @@ bool field_load(classbuffer *cb, fieldinfo *f, descriptor_pool *descpool)
                        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);
@@ -363,10 +361,10 @@ classinfo *field_get_type(fieldinfo *f)
                /* 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;
@@ -381,30 +379,57 @@ classinfo *field_get_type(fieldinfo *f)
 
 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).
 
 *******************************************************************************/
 
-annotation_bytearray_t *field_get_annotations(fieldinfo *f)
+java_handle_bytearray_t *field_get_annotations(fieldinfo *f)
 {
-       classinfo *c = f->class;
-       int slot = f - c->fields;
-
-       if (c->field_annotations != NULL &&
-           c->field_annotations->size > slot) {
-               return c->field_annotations->data[slot];
+#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 ************************************************************
@@ -450,13 +475,17 @@ void field_print(fieldinfo *f)
                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
 
@@ -529,4 +558,5 @@ void field_fieldref_println(constant_FMIref *fr)
  * c-basic-offset: 4
  * tab-width: 4
  * End:
+ * vim:noexpandtab:sw=4:ts=4:
  */