// resolve.cc - Code for linking and resolving classes and pool entries.
-/* Copyright (C) 1999, 2000 Free Software Foundation
+/* Copyright (C) 1999, 2000, 2001 , 2002 Free Software Foundation
This file is part of libgcj.
#include <java/lang/IncompatibleClassChangeError.h>
#include <java/lang/reflect/Modifier.h>
+using namespace gcj;
+
+void
+_Jv_ResolveField (_Jv_Field *field, java::lang::ClassLoader *loader)
+{
+ if (! field->isResolved ())
+ {
+ _Jv_Utf8Const *sig = (_Jv_Utf8Const*)field->type;
+ field->type = _Jv_FindClassFromSignature (sig->data, loader);
+ field->flags &= ~_Jv_FIELD_UNRESOLVED_FLAG;
+ }
+}
+
#ifdef INTERPRETER
static void throw_internal_error (char *msg)
static void throw_class_format_error (char *msg)
__attribute__ ((__noreturn__));
-#define ClassObject _CL_Q34java4lang6Object
-extern java::lang::Class ClassObject;
-#define ObjectClass _CL_Q34java4lang6Object
-extern java::lang::Class ObjectClass;
-
// Exceptional return values for _Jv_DetermineVTableIndex
#define METHOD_NOT_THERE (-2)
#define METHOD_INACCESSIBLE (-1)
jint);
-// We need to know the name of a constructor.
-static _Jv_Utf8Const *init_name = _Jv_makeUtf8Const ("<init>", 6);
-
static void throw_incompatible_class_change_error (jstring msg)
{
- JvThrow (new java::lang::IncompatibleClassChangeError (msg));
+ throw new java::lang::IncompatibleClassChangeError (msg);
}
_Jv_word
if (! found)
{
jstring str = _Jv_NewStringUTF (name->data);
- JvThrow (new java::lang::ClassNotFoundException (str));
+ throw new java::lang::ClassNotFoundException (str);
}
if ((found->accflags & Modifier::PUBLIC) == Modifier::PUBLIC
}
else
{
- JvThrow (new java::lang::IllegalAccessError (found->getName()));
+ throw new java::lang::IllegalAccessError (found->getName());
}
}
break;
_Jv_ResolveField (field, cls->loader);
if (field_type != 0 && field->type != field_type)
- JvThrow
- (new java::lang::LinkageError
- (JvNewStringLatin1
- ("field type mismatch with different loaders")));
+ throw new java::lang::LinkageError
+ (JvNewStringLatin1
+ ("field type mismatch with different loaders"));
the_field = field;
goto end_of_field_search;
}
else
{
- JvThrow (new java::lang::IllegalAccessError);
+ throw new java::lang::IllegalAccessError;
}
}
}
msg = msg->concat (JvNewStringLatin1("."));
msg = msg->concat (_Jv_NewStringUTF (method_name->data));
msg = msg->concat (JvNewStringLatin1(" was not found."));
- JvThrow(new java::lang::NoSuchMethodError (msg));
+ throw new java::lang::NoSuchMethodError (msg);
}
pool->data[index].rmethod =
}
else
{
- JvThrow (new java::lang::IllegalAccessError);
+ throw new java::lang::IllegalAccessError;
}
}
return 0;
}
-void
-_Jv_ResolveField (_Jv_Field *field, java::lang::ClassLoader *loader)
-{
- if (! field->isResolved ())
- {
- _Jv_Utf8Const *sig = (_Jv_Utf8Const*)field->type;
- field->type = _Jv_FindClassFromSignature (sig->data, loader);
- field->flags &= ~_Jv_FIELD_UNRESOLVED_FLAG;
- }
-}
-
/** FIXME: this is a terribly inefficient algorithm! It would improve
things if compiled classes to know vtable offset, and _Jv_Method had
a field for this.
static void
_Jv_abstractMethodError ()
{
- JvThrow (new java::lang::AbstractMethodError);
+ throw new java::lang::AbstractMethodError;
}
void
// set the instance size for the class
clz->size_in_bytes = instance_size;
-
+
// allocate static memory
if (static_size != 0)
{
- char *static_data = (char*)_Jv_AllocBytesChecked (static_size);
+ char *static_data = (char*)_Jv_AllocBytes (static_size);
memset (static_data, 0, static_size);
else if (imeth != 0) // it could be abstract
{
_Jv_InterpMethod *im = reinterpret_cast<_Jv_InterpMethod *> (imeth);
+ _Jv_VerifyMethod (im);
clz->methods[i].ncode = im->ncode ();
}
}
{
clz->state = JV_STATE_ERROR;
clz->notifyAll ();
- JvThrow (new java::lang::IncompatibleClassChangeError
- (clz->getName ()));
+ throw new java::lang::IncompatibleClassChangeError (clz->getName ());
}
/* FIXME: At this point, if (loader != super_class->loader), we
clz->vtable_method_count = vtable_count;
/* allocate vtable structure */
- _Jv_VTable *vtable = (_Jv_VTable*)
- _Jv_AllocBytesChecked (sizeof (_Jv_VTable)
- + (sizeof (void*) * (vtable_count)));
+ _Jv_VTable *vtable = _Jv_VTable::new_vtable (vtable_count);
vtable->clas = clz;
vtable->gc_descr = _Jv_BuildGCDescr(clz);
/* copy super class' vtable entries. */
if (effective_superclass && effective_superclass->vtable)
- memcpy ((void*)&vtable->method[0],
- (void*)&effective_superclass->vtable->method[0],
- sizeof (void*) * effective_superclass->vtable_method_count);
+ for (int i = 0; i < effective_superclass->vtable_method_count; ++i)
+ vtable->set_method (i, effective_superclass->vtable->get_method (i));
}
/* now, install our own vtable entries, reprise... */
throw_internal_error ("vtable problem...");
if (clz->interpreted_methods[i] == 0)
- vtable->method[index] = (void*)&_Jv_abstractMethodError;
+ vtable->set_method(index, (void*)&_Jv_abstractMethodError);
else
- vtable->method[index] = this_meth->ncode;
+ vtable->set_method(index, this_meth->ncode);
}
}
/* fall through */
case JV_CONSTANT_ResolvedString:
- if (! (field->type == &StringClass || field->type == &ObjectClass))
+ if (! (field->type == &StringClass
+ || field->type == &java::lang::Class::class$))
throw_class_format_error ("string initialiser to non-string field");
*(jstring*)addr = pool->data[init].string;
* function is non-static, then one is added to the number of elements
* found in the signature */
-static int
-count_arguments (_Jv_Utf8Const *signature,
- jboolean staticp)
+int
+_Jv_count_arguments (_Jv_Utf8Const *signature,
+ jboolean staticp)
{
unsigned char *ptr = (unsigned char*) signature->data;
int arg_count = staticp ? 0 : 1;
#endif
/* we put this one here, and not in interpret.cc because it
- * calls the utility routines count_arguments
+ * calls the utility routines _Jv_count_arguments
* which are static to this module. The following struct defines the
* layout we use for the stubs, it's only used in the ncode method. */
return self->ncode;
jboolean staticp = (self->accflags & Modifier::STATIC) != 0;
- int arg_count = count_arguments (self->signature, staticp);
+ int arg_count = _Jv_count_arguments (self->signature, staticp);
ncode_closure *closure =
- (ncode_closure*)_Jv_AllocBytesChecked (sizeof (ncode_closure)
+ (ncode_closure*)_Jv_AllocBytes (sizeof (ncode_closure)
+ arg_count * sizeof (ffi_type*));
init_cif (self->signature,
return self->ncode;
jboolean staticp = (self->accflags & Modifier::STATIC) != 0;
- int arg_count = count_arguments (self->signature, staticp);
+ int arg_count = _Jv_count_arguments (self->signature, staticp);
ncode_closure *closure =
- (ncode_closure*)_Jv_AllocBytesChecked (sizeof (ncode_closure)
- + arg_count * sizeof (ffi_type*));
+ (ncode_closure*)_Jv_AllocBytes (sizeof (ncode_closure)
+ + arg_count * sizeof (ffi_type*));
ffi_type *rtype;
init_cif (self->signature,
jboolean staticp,
jint vtable_index)
{
- int arg_count = count_arguments (method->signature, staticp);
+ int arg_count = _Jv_count_arguments (method->signature, staticp);
_Jv_ResolvedMethod* result = (_Jv_ResolvedMethod*)
- _Jv_AllocBytesChecked (sizeof (_Jv_ResolvedMethod)
- + arg_count*sizeof (ffi_type*));
+ _Jv_AllocBytes (sizeof (_Jv_ResolvedMethod)
+ + arg_count*sizeof (ffi_type*));
result->stack_item_count
= init_cif (method->signature,
static void
throw_class_format_error (jstring msg)
{
- if (msg == 0)
- JvThrow (new java::lang::ClassFormatError);
- else
- JvThrow (new java::lang::ClassFormatError (msg));
+ throw (msg
+ ? new java::lang::ClassFormatError (msg)
+ : new java::lang::ClassFormatError);
}
static void
static void
throw_internal_error (char *msg)
{
- JvThrow
- (new java::lang::InternalError (JvNewStringLatin1 (msg)));
+ throw new java::lang::InternalError (JvNewStringLatin1 (msg));
}