Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
- $Id: linker.c 8277 2007-08-08 16:42:11Z michi $
-
*/
#include "toolbox/logging.h"
#include "vm/access.h"
+#include "vm/array.h"
#include "vm/exceptions.h"
+#include "vm/primitive.h"
#include "vm/stringlocal.h"
#include "vm/vm.h"
#include "vmcore/classcache.h"
#include "vmcore/loader.h"
#include "vmcore/options.h"
-#include "vmcore/primitive.h"
#include "vmcore/rt-timing.h"
/* #include "vm/resolve.h" */
static s4 interfaceindex; /* sequential numbering of interfaces */
static s4 classvalue;
-java_objectheader *linker_classrenumber_lock;
+java_object_t *linker_classrenumber_lock;
/* private functions **********************************************************/
/* Check for if alignment for long and double matches what we
assume for the current architecture. */
-#if defined(__I386__) || (defined(__ARM__) && !defined(__ARM_EABI__))
+#if defined(__I386__) || (defined(__ARM__) && !defined(__ARM_EABI__)) || (defined(__POWERPC__) && defined(__DARWIN__))
if (OFFSET(dummy_alignment_long_t, l) != 4)
vm_abort("linker_init: long alignment is different from what assumed: %d != %d",
OFFSET(dummy_alignment_long_t, l), 4);
#if defined(ENABLE_THREADS)
/* create the global lock object */
- linker_classrenumber_lock = NEW(java_objectheader);
+ linker_classrenumber_lock = NEW(java_object_t);
LOCK_INIT_OBJECT_LOCK(linker_classrenumber_lock);
#endif
LOCK_MONITOR_ENTER(c);
- /* maybe the class is already linked */
+ /* Maybe the class is currently linking or is already linked.*/
- if (c->state & CLASS_LINKED) {
+ if ((c->state & CLASS_LINKING) || (c->state & CLASS_LINKED)) {
LOCK_MONITOR_EXIT(c);
return c;
r = link_class_intern(c);
- /* if return value is NULL, we had a problem and the class is not linked */
+ /* If return value is NULL, we had a problem and the class is not
+ linked. */
- if (!r)
+ if (r == NULL)
c->state &= ~CLASS_LINKING;
#if defined(ENABLE_STATISTICS)
RT_TIMING_GET_TIME(time_start);
- /* the class is already linked */
-
- if (c->state & CLASS_LINKED)
- return c;
-
#if !defined(NDEBUG)
if (linkverbose)
log_message_class("Linking class: ", c);
/* XXX should this be a specific exception? */
assert(c->state & CLASS_LOADED);
+ /* This is check in link_class. */
+
+ assert(!(c->state & CLASS_LINKED));
+
/* cache the self-reference of this class */
/* we do this for cases where the defining loader of the class */
/* has not yet been recorded as an initiating loader for the class */
if (c->super.any == NULL) { /* class java.lang.Object */
c->index = 0;
- c->instancesize = sizeof(java_objectheader);
+ c->instancesize = sizeof(java_object_t);
vftbllength = supervftbllength = 0;
c->finalizer = NULL;
- } else {
- /* resolve super class */
+ }
+ else {
+ /* Resolve super class. */
- if ((super = resolve_classref_or_classinfo_eager(c->super, true)) == NULL)
+ super = resolve_classref_or_classinfo_eager(c->super, true);
+
+ if (super == NULL)
return NULL;
c->super.cls = super;
- /* detect circularity */
+ /* Detect circularity. */
if (super == c) {
exceptions_throw_classcircularityerror(c);
if (!(f->flags & ACC_STATIC)) {
dsize = descriptor_typesize(f->parseddesc);
-#if defined(__I386__) || (defined(__ARM__) && !defined(__ARM_EABI__))
+#if defined(__I386__) || (defined(__ARM__) && !defined(__ARM_EABI__)) || (defined(__POWERPC__) && defined(__DARWIN__))
/* On i386 and ARM we align double and s8 fields to
4-bytes. This matches what GCC does for struct
members. We must do the same as gcc here because the
/* c is an array of references */
desc->arraytype = ARRAYTYPE_OBJECT;
desc->componentsize = sizeof(void*);
- desc->dataoffset = OFFSET(java_objectarray, data);
+ desc->dataoffset = OFFSET(java_objectarray_t, data);
compvftbl = comp->vftbl;
switch (c->name->text[1]) {
case 'Z':
desc->arraytype = ARRAYTYPE_BOOLEAN;
- desc->dataoffset = OFFSET(java_booleanarray,data);
+ desc->dataoffset = OFFSET(java_booleanarray_t,data);
desc->componentsize = sizeof(u1);
break;
case 'B':
desc->arraytype = ARRAYTYPE_BYTE;
- desc->dataoffset = OFFSET(java_bytearray,data);
+ desc->dataoffset = OFFSET(java_bytearray_t,data);
desc->componentsize = sizeof(u1);
break;
case 'C':
desc->arraytype = ARRAYTYPE_CHAR;
- desc->dataoffset = OFFSET(java_chararray,data);
+ desc->dataoffset = OFFSET(java_chararray_t,data);
desc->componentsize = sizeof(u2);
break;
case 'D':
desc->arraytype = ARRAYTYPE_DOUBLE;
- desc->dataoffset = OFFSET(java_doublearray,data);
+ desc->dataoffset = OFFSET(java_doublearray_t,data);
desc->componentsize = sizeof(double);
break;
case 'F':
desc->arraytype = ARRAYTYPE_FLOAT;
- desc->dataoffset = OFFSET(java_floatarray,data);
+ desc->dataoffset = OFFSET(java_floatarray_t,data);
desc->componentsize = sizeof(float);
break;
case 'I':
desc->arraytype = ARRAYTYPE_INT;
- desc->dataoffset = OFFSET(java_intarray,data);
+ desc->dataoffset = OFFSET(java_intarray_t,data);
desc->componentsize = sizeof(s4);
break;
case 'J':
desc->arraytype = ARRAYTYPE_LONG;
- desc->dataoffset = OFFSET(java_longarray,data);
+ desc->dataoffset = OFFSET(java_longarray_t,data);
desc->componentsize = sizeof(s8);
break;
case 'S':
desc->arraytype = ARRAYTYPE_SHORT;
- desc->dataoffset = OFFSET(java_shortarray,data);
+ desc->dataoffset = OFFSET(java_shortarray_t,data);
desc->componentsize = sizeof(s2);
break;