2004-11-25 04:47:08 +01:00
|
|
|
// link.cc - Code for linking and resolving classes and pool entries.
|
|
|
|
|
2007-01-10 23:56:20 +01:00
|
|
|
/* Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007 Free Software Foundation
|
2004-11-25 04:47:08 +01:00
|
|
|
|
|
|
|
This file is part of libgcj.
|
|
|
|
|
|
|
|
This software is copyrighted work licensed under the terms of the
|
|
|
|
Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
|
|
|
|
details. */
|
|
|
|
|
|
|
|
/* Author: Kresten Krab Thorup <krab@gnu.org> */
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
#include <platform.h>
|
|
|
|
|
2005-02-02 23:29:31 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
|
2006-03-07 19:04:04 +01:00
|
|
|
#ifdef USE_LIBFFI
|
|
|
|
#include <ffi.h>
|
|
|
|
#endif
|
|
|
|
|
2004-11-25 04:47:08 +01:00
|
|
|
#include <java-interp.h>
|
|
|
|
|
2006-04-24 17:33:16 +02:00
|
|
|
// Set GC_DEBUG before including gc.h!
|
|
|
|
#ifdef LIBGCJ_GC_DEBUG
|
|
|
|
# define GC_DEBUG
|
|
|
|
#endif
|
|
|
|
#include <gc.h>
|
|
|
|
|
2004-11-25 04:47:08 +01:00
|
|
|
#include <jvm.h>
|
|
|
|
#include <gcj/cni.h>
|
|
|
|
#include <string.h>
|
2004-12-01 22:44:09 +01:00
|
|
|
#include <limits.h>
|
2004-11-25 04:47:08 +01:00
|
|
|
#include <java-cpool.h>
|
|
|
|
#include <execution.h>
|
2007-01-25 02:21:27 +01:00
|
|
|
#include <jvmti.h>
|
|
|
|
#include "jvmti-int.h"
|
2004-11-25 04:47:08 +01:00
|
|
|
#include <java/lang/Class.h>
|
|
|
|
#include <java/lang/String.h>
|
|
|
|
#include <java/lang/StringBuffer.h>
|
|
|
|
#include <java/lang/Thread.h>
|
|
|
|
#include <java/lang/InternalError.h>
|
|
|
|
#include <java/lang/VirtualMachineError.h>
|
|
|
|
#include <java/lang/VerifyError.h>
|
|
|
|
#include <java/lang/NoSuchFieldError.h>
|
|
|
|
#include <java/lang/NoSuchMethodError.h>
|
|
|
|
#include <java/lang/ClassFormatError.h>
|
|
|
|
#include <java/lang/IllegalAccessError.h>
|
2006-02-01 14:40:05 +01:00
|
|
|
#include <java/lang/InternalError.h>
|
2004-11-25 04:47:08 +01:00
|
|
|
#include <java/lang/AbstractMethodError.h>
|
|
|
|
#include <java/lang/NoClassDefFoundError.h>
|
|
|
|
#include <java/lang/IncompatibleClassChangeError.h>
|
|
|
|
#include <java/lang/VerifyError.h>
|
|
|
|
#include <java/lang/VMClassLoader.h>
|
|
|
|
#include <java/lang/reflect/Modifier.h>
|
|
|
|
#include <java/security/CodeSource.h>
|
|
|
|
|
|
|
|
using namespace gcj;
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
struct aligner
|
|
|
|
{
|
|
|
|
char c;
|
|
|
|
T field;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define ALIGNOF(TYPE) (offsetof (aligner<TYPE>, field))
|
|
|
|
|
|
|
|
// This returns the alignment of a type as it would appear in a
|
|
|
|
// structure. This can be different from the alignment of the type
|
|
|
|
// itself. For instance on x86 double is 8-aligned but struct{double}
|
|
|
|
// is 4-aligned.
|
|
|
|
int
|
|
|
|
_Jv_Linker::get_alignment_from_class (jclass klass)
|
|
|
|
{
|
|
|
|
if (klass == JvPrimClass (byte))
|
|
|
|
return ALIGNOF (jbyte);
|
|
|
|
else if (klass == JvPrimClass (short))
|
|
|
|
return ALIGNOF (jshort);
|
|
|
|
else if (klass == JvPrimClass (int))
|
|
|
|
return ALIGNOF (jint);
|
|
|
|
else if (klass == JvPrimClass (long))
|
|
|
|
return ALIGNOF (jlong);
|
|
|
|
else if (klass == JvPrimClass (boolean))
|
|
|
|
return ALIGNOF (jboolean);
|
|
|
|
else if (klass == JvPrimClass (char))
|
|
|
|
return ALIGNOF (jchar);
|
|
|
|
else if (klass == JvPrimClass (float))
|
|
|
|
return ALIGNOF (jfloat);
|
|
|
|
else if (klass == JvPrimClass (double))
|
|
|
|
return ALIGNOF (jdouble);
|
|
|
|
else
|
|
|
|
return ALIGNOF (jobject);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_Jv_Linker::resolve_field (_Jv_Field *field, java::lang::ClassLoader *loader)
|
|
|
|
{
|
|
|
|
if (! field->isResolved ())
|
|
|
|
{
|
2005-04-06 00:26:26 +02:00
|
|
|
_Jv_Utf8Const *sig = (_Jv_Utf8Const *) field->type;
|
|
|
|
jclass type = _Jv_FindClassFromSignature (sig->chars(), loader);
|
|
|
|
if (type == NULL)
|
|
|
|
throw new java::lang::NoClassDefFoundError(field->name->toString());
|
|
|
|
field->type = type;
|
2004-11-25 04:47:08 +01:00
|
|
|
field->flags &= ~_Jv_FIELD_UNRESOLVED_FLAG;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-01-10 20:21:46 +01:00
|
|
|
// A helper for find_field that knows how to recursively search
|
|
|
|
// superclasses and interfaces.
|
|
|
|
_Jv_Field *
|
|
|
|
_Jv_Linker::find_field_helper (jclass search, _Jv_Utf8Const *name,
|
2006-02-01 14:40:05 +01:00
|
|
|
_Jv_Utf8Const *type_name, jclass type,
|
2005-01-10 20:21:46 +01:00
|
|
|
jclass *declarer)
|
|
|
|
{
|
|
|
|
while (search)
|
|
|
|
{
|
|
|
|
// From 5.4.3.2. First search class itself.
|
|
|
|
for (int i = 0; i < search->field_count; ++i)
|
|
|
|
{
|
|
|
|
_Jv_Field *field = &search->fields[i];
|
2005-03-07 18:18:33 +01:00
|
|
|
if (! _Jv_equalUtf8Consts (field->name, name))
|
|
|
|
continue;
|
|
|
|
|
2006-02-01 14:40:05 +01:00
|
|
|
// Checks for the odd situation where we were able to retrieve the
|
|
|
|
// field's class from signature but the resolution of the field itself
|
|
|
|
// failed which means a different class was resolved.
|
|
|
|
if (type != NULL)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
resolve_field (field, search->loader);
|
|
|
|
}
|
|
|
|
catch (java::lang::Throwable *exc)
|
|
|
|
{
|
|
|
|
java::lang::LinkageError *le = new java::lang::LinkageError
|
|
|
|
(JvNewStringLatin1
|
|
|
|
("field type mismatch with different loaders"));
|
|
|
|
|
|
|
|
le->initCause(exc);
|
|
|
|
|
|
|
|
throw le;
|
|
|
|
}
|
|
|
|
}
|
2005-03-07 18:18:33 +01:00
|
|
|
|
|
|
|
// Note that we compare type names and not types. This is
|
|
|
|
// bizarre, but we do it because we want to find a field
|
|
|
|
// (and terminate the search) if it has the correct
|
|
|
|
// descriptor -- but then later reject it if the class
|
|
|
|
// loader check results in different classes. We can't just
|
|
|
|
// pass in the descriptor and check that way, because when
|
|
|
|
// the field is already resolved there is no easy way to
|
|
|
|
// find its descriptor again.
|
2006-02-21 11:32:31 +01:00
|
|
|
if ((field->isResolved ()
|
|
|
|
? _Jv_equalUtf8Classnames (type_name, field->type->name)
|
|
|
|
: _Jv_equalUtf8Classnames (type_name,
|
|
|
|
(_Jv_Utf8Const *) field->type)))
|
2005-01-10 20:21:46 +01:00
|
|
|
{
|
|
|
|
*declarer = search;
|
|
|
|
return field;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Next search direct interfaces.
|
|
|
|
for (int i = 0; i < search->interface_count; ++i)
|
|
|
|
{
|
|
|
|
_Jv_Field *result = find_field_helper (search->interfaces[i], name,
|
2006-02-01 14:40:05 +01:00
|
|
|
type_name, type, declarer);
|
2005-01-10 20:21:46 +01:00
|
|
|
if (result)
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now search superclass.
|
|
|
|
search = search->superclass;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2005-02-19 02:16:30 +01:00
|
|
|
bool
|
|
|
|
_Jv_Linker::has_field_p (jclass search, _Jv_Utf8Const *field_name)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < search->field_count; ++i)
|
|
|
|
{
|
|
|
|
_Jv_Field *field = &search->fields[i];
|
|
|
|
if (_Jv_equalUtf8Consts (field->name, field_name))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2005-01-10 20:21:46 +01:00
|
|
|
// Find a field.
|
|
|
|
// KLASS is the class that is requesting the field.
|
|
|
|
// OWNER is the class in which the field should be found.
|
|
|
|
// FIELD_TYPE_NAME is the type descriptor for the field.
|
2005-04-29 20:35:36 +02:00
|
|
|
// Fill FOUND_CLASS with the address of the class in which the field
|
|
|
|
// is actually declared.
|
2005-01-10 20:21:46 +01:00
|
|
|
// This function does the class loader type checks, and
|
|
|
|
// also access checks. Returns the field, or throws an
|
|
|
|
// exception on error.
|
|
|
|
_Jv_Field *
|
|
|
|
_Jv_Linker::find_field (jclass klass, jclass owner,
|
2005-04-29 20:35:36 +02:00
|
|
|
jclass *found_class,
|
2005-01-10 20:21:46 +01:00
|
|
|
_Jv_Utf8Const *field_name,
|
|
|
|
_Jv_Utf8Const *field_type_name)
|
|
|
|
{
|
2005-03-07 18:18:33 +01:00
|
|
|
// FIXME: this allocates a _Jv_Utf8Const each time. We should make
|
|
|
|
// it cheaper.
|
2006-02-01 14:40:05 +01:00
|
|
|
// Note: This call will resolve the primitive type names ("Z", "B", ...) to
|
|
|
|
// their Java counterparts ("boolean", "byte", ...) if accessed via
|
|
|
|
// field_type->name later. Using these variants of the type name is in turn
|
|
|
|
// important for the find_field_helper function. However if the class
|
|
|
|
// resolution failed then we can only use the already given type name.
|
|
|
|
jclass field_type
|
|
|
|
= _Jv_FindClassFromSignatureNoException (field_type_name->chars(),
|
|
|
|
klass->loader);
|
|
|
|
|
|
|
|
_Jv_Field *the_field
|
|
|
|
= find_field_helper (owner, field_name,
|
|
|
|
(field_type
|
|
|
|
? field_type->name :
|
|
|
|
field_type_name ),
|
|
|
|
field_type, found_class);
|
2005-01-10 20:21:46 +01:00
|
|
|
|
|
|
|
if (the_field == 0)
|
|
|
|
{
|
|
|
|
java::lang::StringBuffer *sb = new java::lang::StringBuffer();
|
|
|
|
sb->append(JvNewStringLatin1("field "));
|
|
|
|
sb->append(owner->getName());
|
|
|
|
sb->append(JvNewStringLatin1("."));
|
|
|
|
sb->append(_Jv_NewStringUTF(field_name->chars()));
|
|
|
|
sb->append(JvNewStringLatin1(" was not found."));
|
|
|
|
throw new java::lang::NoSuchFieldError (sb->toString());
|
|
|
|
}
|
|
|
|
|
2006-02-01 14:40:05 +01:00
|
|
|
// Accept it when the field's class could not be resolved.
|
|
|
|
if (field_type == NULL)
|
|
|
|
// Silently ignore that we were not able to retrieve the type to make it
|
|
|
|
// possible to run code which does not access this field.
|
|
|
|
return the_field;
|
|
|
|
|
2005-04-29 20:35:36 +02:00
|
|
|
if (_Jv_CheckAccess (klass, *found_class, the_field->flags))
|
2005-01-10 20:21:46 +01:00
|
|
|
{
|
2005-03-07 18:18:33 +01:00
|
|
|
// Note that the field returned by find_field_helper is always
|
|
|
|
// resolved. There's no point checking class loaders here,
|
|
|
|
// since we already did the work to look up all the types.
|
|
|
|
// FIXME: being lazy here would be nice.
|
|
|
|
if (the_field->type != field_type)
|
2005-01-10 20:21:46 +01:00
|
|
|
throw new java::lang::LinkageError
|
|
|
|
(JvNewStringLatin1
|
|
|
|
("field type mismatch with different loaders"));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
java::lang::StringBuffer *sb
|
|
|
|
= new java::lang::StringBuffer ();
|
|
|
|
sb->append(klass->getName());
|
|
|
|
sb->append(JvNewStringLatin1(": "));
|
2005-04-29 20:35:36 +02:00
|
|
|
sb->append((*found_class)->getName());
|
2005-01-10 20:21:46 +01:00
|
|
|
sb->append(JvNewStringLatin1("."));
|
|
|
|
sb->append(_Jv_NewStringUtf8Const (field_name));
|
|
|
|
throw new java::lang::IllegalAccessError(sb->toString());
|
|
|
|
}
|
|
|
|
|
|
|
|
return the_field;
|
|
|
|
}
|
|
|
|
|
2007-01-09 20:58:05 +01:00
|
|
|
_Jv_Method *
|
|
|
|
_Jv_Linker::resolve_method_entry (jclass klass, jclass &found_class,
|
|
|
|
int class_index, int name_and_type_index,
|
|
|
|
bool init, bool is_iface)
|
|
|
|
{
|
|
|
|
_Jv_Constants *pool = &klass->constants;
|
|
|
|
jclass owner = resolve_pool_entry (klass, class_index).clazz;
|
|
|
|
|
|
|
|
if (init && owner != klass)
|
|
|
|
_Jv_InitClass (owner);
|
|
|
|
|
|
|
|
_Jv_ushort name_index, type_index;
|
|
|
|
_Jv_loadIndexes (&pool->data[name_and_type_index],
|
|
|
|
name_index,
|
|
|
|
type_index);
|
|
|
|
|
|
|
|
_Jv_Utf8Const *method_name = pool->data[name_index].utf8;
|
|
|
|
_Jv_Utf8Const *method_signature = pool->data[type_index].utf8;
|
|
|
|
|
|
|
|
_Jv_Method *the_method = 0;
|
|
|
|
found_class = 0;
|
|
|
|
|
|
|
|
// We're going to cache a pointer to the _Jv_Method object
|
|
|
|
// when we find it. So, to ensure this doesn't get moved from
|
|
|
|
// beneath us, we first put all the needed Miranda methods
|
|
|
|
// into the target class.
|
|
|
|
wait_for_state (klass, JV_STATE_LOADED);
|
|
|
|
|
|
|
|
// First search the class itself.
|
|
|
|
the_method = search_method_in_class (owner, klass,
|
|
|
|
method_name, method_signature);
|
|
|
|
|
|
|
|
if (the_method != 0)
|
|
|
|
{
|
|
|
|
found_class = owner;
|
|
|
|
goto end_of_method_search;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we are resolving an interface method, search the
|
|
|
|
// interface's superinterfaces (A superinterface is not an
|
|
|
|
// interface's superclass - a superinterface is implemented by
|
|
|
|
// the interface).
|
|
|
|
if (is_iface)
|
|
|
|
{
|
|
|
|
_Jv_ifaces ifaces;
|
|
|
|
ifaces.count = 0;
|
|
|
|
ifaces.len = 4;
|
|
|
|
ifaces.list = (jclass *) _Jv_Malloc (ifaces.len
|
|
|
|
* sizeof (jclass *));
|
|
|
|
|
|
|
|
get_interfaces (owner, &ifaces);
|
|
|
|
|
|
|
|
for (int i = 0; i < ifaces.count; i++)
|
|
|
|
{
|
|
|
|
jclass cls = ifaces.list[i];
|
|
|
|
the_method = search_method_in_class (cls, klass, method_name,
|
|
|
|
method_signature);
|
|
|
|
if (the_method != 0)
|
|
|
|
{
|
|
|
|
found_class = cls;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_Jv_Free (ifaces.list);
|
|
|
|
|
|
|
|
if (the_method != 0)
|
|
|
|
goto end_of_method_search;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Finally, search superclasses.
|
|
|
|
the_method = (search_method_in_superclasses
|
|
|
|
(owner->getSuperclass (), klass, method_name,
|
|
|
|
method_signature, &found_class));
|
|
|
|
|
|
|
|
|
|
|
|
end_of_method_search:
|
|
|
|
if (the_method == 0)
|
|
|
|
{
|
|
|
|
java::lang::StringBuffer *sb = new java::lang::StringBuffer();
|
|
|
|
sb->append(JvNewStringLatin1("method "));
|
|
|
|
sb->append(owner->getName());
|
|
|
|
sb->append(JvNewStringLatin1("."));
|
|
|
|
sb->append(_Jv_NewStringUTF(method_name->chars()));
|
|
|
|
sb->append(JvNewStringLatin1(" with signature "));
|
|
|
|
sb->append(_Jv_NewStringUTF(method_signature->chars()));
|
|
|
|
sb->append(JvNewStringLatin1(" was not found."));
|
|
|
|
throw new java::lang::NoSuchMethodError (sb->toString());
|
|
|
|
}
|
|
|
|
|
2007-03-23 12:25:46 +01:00
|
|
|
// if (found_class->loader != klass->loader), then we
|
|
|
|
// must actually check that the types of arguments
|
|
|
|
// correspond. That is, for each argument type, and
|
|
|
|
// the return type, doing _Jv_FindClassFromSignature
|
|
|
|
// with either loader should produce the same result,
|
|
|
|
// i.e., exactly the same jclass object. JVMS 5.4.3.3
|
|
|
|
if (found_class->loader != klass->loader)
|
|
|
|
{
|
|
|
|
JArray<jclass> *found_args, *klass_args;
|
|
|
|
jclass found_return, klass_return;
|
|
|
|
|
|
|
|
_Jv_GetTypesFromSignature (the_method,
|
|
|
|
found_class,
|
|
|
|
&found_args,
|
|
|
|
&found_return);
|
|
|
|
_Jv_GetTypesFromSignature (the_method,
|
|
|
|
klass,
|
|
|
|
&klass_args,
|
|
|
|
&klass_return);
|
|
|
|
|
|
|
|
jclass *found_arg = elements (found_args);
|
|
|
|
jclass *klass_arg = elements (klass_args);
|
|
|
|
|
|
|
|
for (int i = 0; i < found_args->length; i++)
|
|
|
|
{
|
|
|
|
if (*(found_arg++) != *(klass_arg++))
|
|
|
|
throw new java::lang::LinkageError (JvNewStringLatin1
|
|
|
|
("argument type mismatch with different loaders"));
|
|
|
|
}
|
|
|
|
if (found_return != klass_return)
|
|
|
|
throw new java::lang::LinkageError (JvNewStringLatin1
|
|
|
|
("return type mismatch with different loaders"));
|
|
|
|
}
|
|
|
|
|
2007-01-09 20:58:05 +01:00
|
|
|
return the_method;
|
|
|
|
}
|
|
|
|
|
2004-11-25 04:47:08 +01:00
|
|
|
_Jv_word
|
2006-02-01 14:40:05 +01:00
|
|
|
_Jv_Linker::resolve_pool_entry (jclass klass, int index, bool lazy)
|
2004-11-25 04:47:08 +01:00
|
|
|
{
|
|
|
|
using namespace java::lang::reflect;
|
|
|
|
|
2006-04-24 17:33:16 +02:00
|
|
|
if (GC_base (klass) && klass->constants.data
|
|
|
|
&& ! GC_base (klass->constants.data))
|
|
|
|
{
|
|
|
|
jsize count = klass->constants.size;
|
|
|
|
if (count)
|
|
|
|
{
|
|
|
|
_Jv_word* constants
|
|
|
|
= (_Jv_word*) _Jv_AllocRawObj (count * sizeof (_Jv_word));
|
|
|
|
memcpy ((void*)constants,
|
|
|
|
(void*)klass->constants.data,
|
|
|
|
count * sizeof (_Jv_word));
|
|
|
|
klass->constants.data = constants;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-11-25 04:47:08 +01:00
|
|
|
_Jv_Constants *pool = &klass->constants;
|
|
|
|
|
|
|
|
if ((pool->tags[index] & JV_CONSTANT_ResolvedFlag) != 0)
|
|
|
|
return pool->data[index];
|
|
|
|
|
2007-01-09 20:58:05 +01:00
|
|
|
switch (pool->tags[index] & ~JV_CONSTANT_LazyFlag)
|
2004-11-25 04:47:08 +01:00
|
|
|
{
|
|
|
|
case JV_CONSTANT_Class:
|
|
|
|
{
|
|
|
|
_Jv_Utf8Const *name = pool->data[index].utf8;
|
|
|
|
|
|
|
|
jclass found;
|
|
|
|
if (name->first() == '[')
|
2006-02-01 14:40:05 +01:00
|
|
|
found = _Jv_FindClassFromSignatureNoException (name->chars(),
|
|
|
|
klass->loader);
|
|
|
|
else
|
|
|
|
found = _Jv_FindClassNoException (name, klass->loader);
|
|
|
|
|
|
|
|
// If the class could not be loaded a phantom class is created. Any
|
|
|
|
// function that deals with such a class but cannot do something useful
|
|
|
|
// with it should just throw a NoClassDefFoundError with the class'
|
|
|
|
// name.
|
2004-11-25 04:47:08 +01:00
|
|
|
if (! found)
|
2007-01-10 23:56:20 +01:00
|
|
|
{
|
|
|
|
if (lazy)
|
|
|
|
{
|
|
|
|
found = _Jv_NewClass(name, NULL, NULL);
|
|
|
|
found->state = JV_STATE_PHANTOM;
|
|
|
|
pool->tags[index] |= JV_CONSTANT_ResolvedFlag;
|
|
|
|
pool->data[index].clazz = found;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
throw new java::lang::NoClassDefFoundError (name->toString());
|
|
|
|
}
|
2004-11-25 04:47:08 +01:00
|
|
|
|
|
|
|
// Check accessibility, but first strip array types as
|
|
|
|
// _Jv_ClassNameSamePackage can't handle arrays.
|
|
|
|
jclass check;
|
|
|
|
for (check = found;
|
|
|
|
check && check->isArray();
|
|
|
|
check = check->getComponentType())
|
|
|
|
;
|
|
|
|
if ((found->accflags & Modifier::PUBLIC) == Modifier::PUBLIC
|
|
|
|
|| (_Jv_ClassNameSamePackage (check->name,
|
|
|
|
klass->name)))
|
|
|
|
{
|
|
|
|
pool->data[index].clazz = found;
|
|
|
|
pool->tags[index] |= JV_CONSTANT_ResolvedFlag;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
java::lang::StringBuffer *sb = new java::lang::StringBuffer ();
|
|
|
|
sb->append(klass->getName());
|
|
|
|
sb->append(JvNewStringLatin1(" can't access class "));
|
|
|
|
sb->append(found->getName());
|
|
|
|
throw new java::lang::IllegalAccessError(sb->toString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case JV_CONSTANT_String:
|
|
|
|
{
|
|
|
|
jstring str;
|
|
|
|
str = _Jv_NewStringUtf8Const (pool->data[index].utf8);
|
|
|
|
pool->data[index].o = str;
|
|
|
|
pool->tags[index] |= JV_CONSTANT_ResolvedFlag;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case JV_CONSTANT_Fieldref:
|
|
|
|
{
|
|
|
|
_Jv_ushort class_index, name_and_type_index;
|
|
|
|
_Jv_loadIndexes (&pool->data[index],
|
|
|
|
class_index,
|
|
|
|
name_and_type_index);
|
2006-02-01 14:40:05 +01:00
|
|
|
jclass owner = (resolve_pool_entry (klass, class_index, true)).clazz;
|
|
|
|
|
|
|
|
// If a phantom class was resolved our field reference is
|
|
|
|
// unusable because of the missing class.
|
|
|
|
if (owner->state == JV_STATE_PHANTOM)
|
|
|
|
throw new java::lang::NoClassDefFoundError(owner->getName());
|
2004-11-25 04:47:08 +01:00
|
|
|
|
2007-01-09 20:58:05 +01:00
|
|
|
// We don't initialize 'owner', but we do make sure that its
|
|
|
|
// fields exist.
|
|
|
|
wait_for_state (owner, JV_STATE_PREPARED);
|
2004-11-25 04:47:08 +01:00
|
|
|
|
|
|
|
_Jv_ushort name_index, type_index;
|
|
|
|
_Jv_loadIndexes (&pool->data[name_and_type_index],
|
|
|
|
name_index,
|
|
|
|
type_index);
|
|
|
|
|
|
|
|
_Jv_Utf8Const *field_name = pool->data[name_index].utf8;
|
|
|
|
_Jv_Utf8Const *field_type_name = pool->data[type_index].utf8;
|
|
|
|
|
2005-04-29 20:35:36 +02:00
|
|
|
jclass found_class = 0;
|
|
|
|
_Jv_Field *the_field = find_field (klass, owner,
|
|
|
|
&found_class,
|
|
|
|
field_name,
|
2005-01-10 20:21:46 +01:00
|
|
|
field_type_name);
|
2007-01-09 20:58:05 +01:00
|
|
|
// Initialize the field's declaring class, not its qualifying
|
|
|
|
// class.
|
|
|
|
_Jv_InitClass (found_class);
|
2004-11-25 04:47:08 +01:00
|
|
|
pool->data[index].field = the_field;
|
|
|
|
pool->tags[index] |= JV_CONSTANT_ResolvedFlag;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case JV_CONSTANT_Methodref:
|
|
|
|
case JV_CONSTANT_InterfaceMethodref:
|
|
|
|
{
|
|
|
|
_Jv_ushort class_index, name_and_type_index;
|
|
|
|
_Jv_loadIndexes (&pool->data[index],
|
|
|
|
class_index,
|
|
|
|
name_and_type_index);
|
|
|
|
|
2007-01-09 20:58:05 +01:00
|
|
|
_Jv_Method *the_method;
|
|
|
|
jclass found_class;
|
|
|
|
the_method = resolve_method_entry (klass, found_class,
|
|
|
|
class_index, name_and_type_index,
|
|
|
|
true,
|
|
|
|
pool->tags[index] == JV_CONSTANT_InterfaceMethodref);
|
2004-11-25 04:47:08 +01:00
|
|
|
|
|
|
|
pool->data[index].rmethod
|
|
|
|
= klass->engine->resolve_method(the_method,
|
|
|
|
found_class,
|
|
|
|
((the_method->accflags
|
2006-04-29 03:35:50 +02:00
|
|
|
& Modifier::STATIC) != 0));
|
2004-11-25 04:47:08 +01:00
|
|
|
pool->tags[index] |= JV_CONSTANT_ResolvedFlag;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return pool->data[index];
|
|
|
|
}
|
|
|
|
|
|
|
|
// This function is used to lazily locate superclasses and
|
|
|
|
// superinterfaces. This must be called with the class lock held.
|
|
|
|
void
|
|
|
|
_Jv_Linker::resolve_class_ref (jclass klass, jclass *classref)
|
|
|
|
{
|
|
|
|
jclass ret = *classref;
|
|
|
|
|
|
|
|
// If superclass looks like a constant pool entry, resolve it now.
|
|
|
|
if (ret && (uaddr) ret < (uaddr) klass->constants.size)
|
|
|
|
{
|
|
|
|
if (klass->state < JV_STATE_LINKED)
|
|
|
|
{
|
|
|
|
_Jv_Utf8Const *name = klass->constants.data[(uaddr) *classref].utf8;
|
|
|
|
ret = _Jv_FindClass (name, klass->loader);
|
|
|
|
if (! ret)
|
|
|
|
{
|
|
|
|
throw new java::lang::NoClassDefFoundError (name->toString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ret = klass->constants.data[(uaddr) classref].clazz;
|
|
|
|
*classref = ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Find a method declared in the cls that is referenced from klass and
|
2006-06-08 16:00:43 +02:00
|
|
|
// perform access checks if CHECK_PERMS is true.
|
2004-11-25 04:47:08 +01:00
|
|
|
_Jv_Method *
|
|
|
|
_Jv_Linker::search_method_in_class (jclass cls, jclass klass,
|
|
|
|
_Jv_Utf8Const *method_name,
|
2006-06-08 16:00:43 +02:00
|
|
|
_Jv_Utf8Const *method_signature,
|
|
|
|
bool check_perms)
|
2004-11-25 04:47:08 +01:00
|
|
|
{
|
|
|
|
using namespace java::lang::reflect;
|
|
|
|
|
|
|
|
for (int i = 0; i < cls->method_count; i++)
|
|
|
|
{
|
|
|
|
_Jv_Method *method = &cls->methods[i];
|
|
|
|
if ( (!_Jv_equalUtf8Consts (method->name,
|
|
|
|
method_name))
|
|
|
|
|| (!_Jv_equalUtf8Consts (method->signature,
|
|
|
|
method_signature)))
|
|
|
|
continue;
|
|
|
|
|
2006-06-08 16:00:43 +02:00
|
|
|
if (!check_perms || _Jv_CheckAccess (klass, cls, method->accflags))
|
2004-11-25 04:47:08 +01:00
|
|
|
return method;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
java::lang::StringBuffer *sb = new java::lang::StringBuffer();
|
|
|
|
sb->append(klass->getName());
|
|
|
|
sb->append(JvNewStringLatin1(": "));
|
|
|
|
sb->append(cls->getName());
|
|
|
|
sb->append(JvNewStringLatin1("."));
|
|
|
|
sb->append(_Jv_NewStringUTF(method_name->chars()));
|
|
|
|
sb->append(_Jv_NewStringUTF(method_signature->chars()));
|
|
|
|
throw new java::lang::IllegalAccessError (sb->toString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-06-08 16:00:43 +02:00
|
|
|
// Like search_method_in_class, but work our way up the superclass
|
|
|
|
// chain.
|
|
|
|
_Jv_Method *
|
|
|
|
_Jv_Linker::search_method_in_superclasses (jclass cls, jclass klass,
|
|
|
|
_Jv_Utf8Const *method_name,
|
|
|
|
_Jv_Utf8Const *method_signature,
|
|
|
|
jclass *found_class, bool check_perms)
|
|
|
|
{
|
|
|
|
_Jv_Method *the_method = NULL;
|
|
|
|
|
|
|
|
for ( ; cls != 0; cls = cls->getSuperclass ())
|
|
|
|
{
|
|
|
|
the_method = search_method_in_class (cls, klass, method_name,
|
|
|
|
method_signature, check_perms);
|
|
|
|
if (the_method != 0)
|
|
|
|
{
|
|
|
|
if (found_class)
|
|
|
|
*found_class = cls;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return the_method;
|
|
|
|
}
|
2004-11-25 04:47:08 +01:00
|
|
|
|
|
|
|
#define INITIAL_IOFFSETS_LEN 4
|
|
|
|
#define INITIAL_IFACES_LEN 4
|
|
|
|
|
2006-02-10 00:59:30 +01:00
|
|
|
static _Jv_IDispatchTable null_idt = {SHRT_MAX, 0, {}};
|
2004-11-25 04:47:08 +01:00
|
|
|
|
|
|
|
// Generate tables for constant-time assignment testing and interface
|
|
|
|
// method lookup. This implements the technique described by Per Bothner
|
|
|
|
// <per@bothner.com> on the java-discuss mailing list on 1999-09-02:
|
|
|
|
// http://gcc.gnu.org/ml/java/1999-q3/msg00377.html
|
|
|
|
void
|
|
|
|
_Jv_Linker::prepare_constant_time_tables (jclass klass)
|
|
|
|
{
|
|
|
|
if (klass->isPrimitive () || klass->isInterface ())
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Short-circuit in case we've been called already.
|
|
|
|
if ((klass->idt != NULL) || klass->depth != 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Calculate the class depth and ancestor table. The depth of a class
|
|
|
|
// is how many "extends" it is removed from Object. Thus the depth of
|
|
|
|
// java.lang.Object is 0, but the depth of java.io.FilterOutputStream
|
|
|
|
// is 2. Depth is defined for all regular and array classes, but not
|
|
|
|
// interfaces or primitive types.
|
|
|
|
|
|
|
|
jclass klass0 = klass;
|
|
|
|
jboolean has_interfaces = 0;
|
|
|
|
while (klass0 != &java::lang::Object::class$)
|
|
|
|
{
|
|
|
|
has_interfaces += klass0->interface_count;
|
|
|
|
klass0 = klass0->superclass;
|
|
|
|
klass->depth++;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We do class member testing in constant time by using a small table
|
|
|
|
// of all the ancestor classes within each class. The first element is
|
|
|
|
// a pointer to the current class, and the rest are pointers to the
|
|
|
|
// classes ancestors, ordered from the current class down by decreasing
|
|
|
|
// depth. We do not include java.lang.Object in the table of ancestors,
|
2006-02-08 21:07:29 +01:00
|
|
|
// since it is redundant. Note that the classes pointed to by
|
|
|
|
// 'ancestors' will always be reachable by other paths.
|
2004-11-25 04:47:08 +01:00
|
|
|
|
2006-02-08 21:07:29 +01:00
|
|
|
klass->ancestors = (jclass *) _Jv_AllocBytes (klass->depth
|
2004-11-25 04:47:08 +01:00
|
|
|
* sizeof (jclass));
|
|
|
|
klass0 = klass;
|
|
|
|
for (int index = 0; index < klass->depth; index++)
|
|
|
|
{
|
|
|
|
klass->ancestors[index] = klass0;
|
|
|
|
klass0 = klass0->superclass;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((klass->accflags & java::lang::reflect::Modifier::ABSTRACT) != 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Optimization: If class implements no interfaces, use a common
|
|
|
|
// predefined interface table.
|
|
|
|
if (!has_interfaces)
|
|
|
|
{
|
|
|
|
klass->idt = &null_idt;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
_Jv_ifaces ifaces;
|
|
|
|
ifaces.count = 0;
|
|
|
|
ifaces.len = INITIAL_IFACES_LEN;
|
|
|
|
ifaces.list = (jclass *) _Jv_Malloc (ifaces.len * sizeof (jclass *));
|
|
|
|
|
|
|
|
int itable_size = get_interfaces (klass, &ifaces);
|
|
|
|
|
|
|
|
if (ifaces.count > 0)
|
|
|
|
{
|
2006-02-08 21:07:29 +01:00
|
|
|
// The classes pointed to by the itable will always be reachable
|
|
|
|
// via other paths.
|
2006-02-10 00:59:30 +01:00
|
|
|
int idt_bytes = sizeof (_Jv_IDispatchTable) + (itable_size
|
|
|
|
* sizeof (void *));
|
|
|
|
klass->idt = (_Jv_IDispatchTable *) _Jv_AllocBytes (idt_bytes);
|
|
|
|
klass->idt->itable_length = itable_size;
|
2004-11-25 04:47:08 +01:00
|
|
|
|
|
|
|
jshort *itable_offsets =
|
|
|
|
(jshort *) _Jv_Malloc (ifaces.count * sizeof (jshort));
|
|
|
|
|
|
|
|
generate_itable (klass, &ifaces, itable_offsets);
|
|
|
|
|
|
|
|
jshort cls_iindex = find_iindex (ifaces.list, itable_offsets,
|
|
|
|
ifaces.count);
|
|
|
|
|
|
|
|
for (int i = 0; i < ifaces.count; i++)
|
|
|
|
{
|
2006-02-10 00:59:30 +01:00
|
|
|
ifaces.list[i]->ioffsets[cls_iindex] = itable_offsets[i];
|
2004-11-25 04:47:08 +01:00
|
|
|
}
|
|
|
|
|
2006-02-10 00:59:30 +01:00
|
|
|
klass->idt->iindex = cls_iindex;
|
2004-11-25 04:47:08 +01:00
|
|
|
|
|
|
|
_Jv_Free (ifaces.list);
|
|
|
|
_Jv_Free (itable_offsets);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-02-10 00:59:30 +01:00
|
|
|
klass->idt->iindex = SHRT_MAX;
|
2004-11-25 04:47:08 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return index of item in list, or -1 if item is not present.
|
|
|
|
inline jshort
|
|
|
|
_Jv_Linker::indexof (void *item, void **list, jshort list_len)
|
|
|
|
{
|
|
|
|
for (int i=0; i < list_len; i++)
|
|
|
|
{
|
|
|
|
if (list[i] == item)
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Find all unique interfaces directly or indirectly implemented by klass.
|
|
|
|
// Returns the size of the interface dispatch table (itable) for klass, which
|
|
|
|
// is the number of unique interfaces plus the total number of methods that
|
|
|
|
// those interfaces declare. May extend ifaces if required.
|
|
|
|
jshort
|
|
|
|
_Jv_Linker::get_interfaces (jclass klass, _Jv_ifaces *ifaces)
|
|
|
|
{
|
|
|
|
jshort result = 0;
|
|
|
|
|
|
|
|
for (int i = 0; i < klass->interface_count; i++)
|
|
|
|
{
|
|
|
|
jclass iface = klass->interfaces[i];
|
|
|
|
|
|
|
|
/* Make sure interface is linked. */
|
|
|
|
wait_for_state(iface, JV_STATE_LINKED);
|
|
|
|
|
|
|
|
if (indexof (iface, (void **) ifaces->list, ifaces->count) == -1)
|
|
|
|
{
|
|
|
|
if (ifaces->count + 1 >= ifaces->len)
|
|
|
|
{
|
|
|
|
/* Resize ifaces list */
|
|
|
|
ifaces->len = ifaces->len * 2;
|
|
|
|
ifaces->list
|
|
|
|
= (jclass *) _Jv_Realloc (ifaces->list,
|
|
|
|
ifaces->len * sizeof(jclass));
|
|
|
|
}
|
|
|
|
ifaces->list[ifaces->count] = iface;
|
|
|
|
ifaces->count++;
|
|
|
|
|
|
|
|
result += get_interfaces (klass->interfaces[i], ifaces);
|
|
|
|
}
|
|
|
|
}
|
2006-03-15 19:29:44 +01:00
|
|
|
|
2004-11-25 04:47:08 +01:00
|
|
|
if (klass->isInterface())
|
2006-03-15 19:29:44 +01:00
|
|
|
{
|
|
|
|
// We want to add 1 plus the number of interface methods here.
|
|
|
|
// But, we take special care to skip <clinit>.
|
|
|
|
++result;
|
|
|
|
for (int i = 0; i < klass->method_count; ++i)
|
|
|
|
{
|
|
|
|
if (klass->methods[i].name->first() != '<')
|
|
|
|
++result;
|
|
|
|
}
|
|
|
|
}
|
2004-11-25 04:47:08 +01:00
|
|
|
else if (klass->superclass)
|
|
|
|
result += get_interfaces (klass->superclass, ifaces);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Fill out itable in klass, resolving method declarations in each ifaces.
|
|
|
|
// itable_offsets is filled out with the position of each iface in itable,
|
|
|
|
// such that itable[itable_offsets[n]] == ifaces.list[n].
|
|
|
|
void
|
|
|
|
_Jv_Linker::generate_itable (jclass klass, _Jv_ifaces *ifaces,
|
|
|
|
jshort *itable_offsets)
|
|
|
|
{
|
2006-02-10 00:59:30 +01:00
|
|
|
void **itable = klass->idt->itable;
|
2004-11-25 04:47:08 +01:00
|
|
|
jshort itable_pos = 0;
|
|
|
|
|
|
|
|
for (int i = 0; i < ifaces->count; i++)
|
|
|
|
{
|
|
|
|
jclass iface = ifaces->list[i];
|
|
|
|
itable_offsets[i] = itable_pos;
|
|
|
|
itable_pos = append_partial_itable (klass, iface, itable, itable_pos);
|
|
|
|
|
2006-02-10 00:59:30 +01:00
|
|
|
/* Create ioffsets table for iface */
|
|
|
|
if (iface->ioffsets == NULL)
|
2004-11-25 04:47:08 +01:00
|
|
|
{
|
|
|
|
// The first element of ioffsets is its length (itself included).
|
2006-02-08 21:07:29 +01:00
|
|
|
jshort *ioffsets = (jshort *) _Jv_AllocBytes (INITIAL_IOFFSETS_LEN
|
|
|
|
* sizeof (jshort));
|
2004-11-25 04:47:08 +01:00
|
|
|
ioffsets[0] = INITIAL_IOFFSETS_LEN;
|
|
|
|
for (int i = 1; i < INITIAL_IOFFSETS_LEN; i++)
|
|
|
|
ioffsets[i] = -1;
|
|
|
|
|
2006-02-10 00:59:30 +01:00
|
|
|
iface->ioffsets = ioffsets;
|
2004-11-25 04:47:08 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Format method name for use in error messages.
|
|
|
|
jstring
|
2005-02-17 20:17:08 +01:00
|
|
|
_Jv_GetMethodString (jclass klass, _Jv_Method *meth,
|
|
|
|
jclass derived)
|
2004-11-25 04:47:08 +01:00
|
|
|
{
|
2005-02-17 20:17:08 +01:00
|
|
|
using namespace java::lang;
|
|
|
|
StringBuffer *buf = new StringBuffer (klass->name->toString());
|
|
|
|
buf->append (jchar ('.'));
|
|
|
|
buf->append (meth->name->toString());
|
|
|
|
buf->append ((jchar) ' ');
|
|
|
|
buf->append (meth->signature->toString());
|
|
|
|
if (derived)
|
|
|
|
{
|
|
|
|
buf->append(JvNewStringLatin1(" in "));
|
|
|
|
buf->append(derived->name->toString());
|
|
|
|
}
|
|
|
|
return buf->toString();
|
2004-11-25 04:47:08 +01:00
|
|
|
}
|
|
|
|
|
2006-02-01 14:40:05 +01:00
|
|
|
void
|
2004-11-25 04:47:08 +01:00
|
|
|
_Jv_ThrowNoSuchMethodError ()
|
|
|
|
{
|
|
|
|
throw new java::lang::NoSuchMethodError;
|
|
|
|
}
|
|
|
|
|
2006-06-05 23:21:05 +02:00
|
|
|
#if defined USE_LIBFFI && FFI_CLOSURES
|
2006-02-01 14:40:05 +01:00
|
|
|
// A function whose invocation is prepared using libffi. It gets called
|
|
|
|
// whenever a static method of a missing class is invoked. The data argument
|
|
|
|
// holds a reference to a String denoting the missing class.
|
|
|
|
// The prepared function call is stored in a class' atable.
|
|
|
|
void
|
|
|
|
_Jv_ThrowNoClassDefFoundErrorTrampoline(ffi_cif *,
|
|
|
|
void *,
|
|
|
|
void **,
|
|
|
|
void *data)
|
|
|
|
{
|
2006-02-03 14:47:51 +01:00
|
|
|
throw new java::lang::NoClassDefFoundError(
|
2006-02-21 11:32:31 +01:00
|
|
|
_Jv_NewStringUtf8Const((_Jv_Utf8Const *) data));
|
2006-02-01 14:40:05 +01:00
|
|
|
}
|
2006-02-03 14:47:51 +01:00
|
|
|
#else
|
|
|
|
// A variant of the NoClassDefFoundError throwing method that can
|
|
|
|
// be used without libffi.
|
2006-02-01 14:40:05 +01:00
|
|
|
void
|
|
|
|
_Jv_ThrowNoClassDefFoundError()
|
|
|
|
{
|
|
|
|
throw new java::lang::NoClassDefFoundError();
|
|
|
|
}
|
2006-02-03 14:47:51 +01:00
|
|
|
#endif
|
2006-02-01 14:40:05 +01:00
|
|
|
|
2005-12-08 15:19:13 +01:00
|
|
|
// Throw a NoSuchFieldError. Called by compiler-generated code when
|
|
|
|
// an otable entry is zero. OTABLE_INDEX is the index in the caller's
|
|
|
|
// otable that refers to the missing field. This index may be used to
|
|
|
|
// print diagnostic information about the field.
|
|
|
|
void
|
|
|
|
_Jv_ThrowNoSuchFieldError (int /* otable_index */)
|
|
|
|
{
|
|
|
|
throw new java::lang::NoSuchFieldError;
|
|
|
|
}
|
|
|
|
|
2005-02-19 06:17:14 +01:00
|
|
|
// This is put in empty vtable slots.
|
2005-06-15 21:11:43 +02:00
|
|
|
void
|
|
|
|
_Jv_ThrowAbstractMethodError ()
|
2005-02-19 06:17:14 +01:00
|
|
|
{
|
|
|
|
throw new java::lang::AbstractMethodError();
|
|
|
|
}
|
|
|
|
|
2004-11-25 04:47:08 +01:00
|
|
|
// Each superinterface of a class (i.e. each interface that the class
|
|
|
|
// directly or indirectly implements) has a corresponding "Partial
|
|
|
|
// Interface Dispatch Table" whose size is (number of methods + 1) words.
|
|
|
|
// The first word is a pointer to the interface (i.e. the java.lang.Class
|
|
|
|
// instance for that interface). The remaining words are pointers to the
|
|
|
|
// actual methods that implement the methods declared in the interface,
|
|
|
|
// in order of declaration.
|
|
|
|
//
|
|
|
|
// Append partial interface dispatch table for "iface" to "itable", at
|
|
|
|
// position itable_pos.
|
|
|
|
// Returns the offset at which the next partial ITable should be appended.
|
|
|
|
jshort
|
|
|
|
_Jv_Linker::append_partial_itable (jclass klass, jclass iface,
|
2006-03-15 19:29:44 +01:00
|
|
|
void **itable, jshort pos)
|
2004-11-25 04:47:08 +01:00
|
|
|
{
|
|
|
|
using namespace java::lang::reflect;
|
|
|
|
|
|
|
|
itable[pos++] = (void *) iface;
|
|
|
|
_Jv_Method *meth;
|
|
|
|
|
|
|
|
for (int j=0; j < iface->method_count; j++)
|
|
|
|
{
|
2006-03-15 19:29:44 +01:00
|
|
|
// Skip '<clinit>' here.
|
|
|
|
if (iface->methods[j].name->first() == '<')
|
|
|
|
continue;
|
|
|
|
|
2004-11-25 04:47:08 +01:00
|
|
|
meth = NULL;
|
|
|
|
for (jclass cl = klass; cl; cl = cl->getSuperclass())
|
|
|
|
{
|
|
|
|
meth = _Jv_GetMethodLocal (cl, iface->methods[j].name,
|
|
|
|
iface->methods[j].signature);
|
|
|
|
|
|
|
|
if (meth)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2006-03-15 19:29:44 +01:00
|
|
|
if (meth)
|
2004-11-25 04:47:08 +01:00
|
|
|
{
|
|
|
|
if ((meth->accflags & Modifier::STATIC) != 0)
|
|
|
|
throw new java::lang::IncompatibleClassChangeError
|
2005-02-17 20:17:08 +01:00
|
|
|
(_Jv_GetMethodString (klass, meth));
|
2004-11-25 04:47:08 +01:00
|
|
|
if ((meth->accflags & Modifier::PUBLIC) == 0)
|
|
|
|
throw new java::lang::IllegalAccessError
|
2005-02-17 20:17:08 +01:00
|
|
|
(_Jv_GetMethodString (klass, meth));
|
2004-11-25 04:47:08 +01:00
|
|
|
|
2005-02-19 06:17:14 +01:00
|
|
|
if ((meth->accflags & Modifier::ABSTRACT) != 0)
|
2005-06-15 21:11:43 +02:00
|
|
|
itable[pos] = (void *) &_Jv_ThrowAbstractMethodError;
|
2005-02-19 06:17:14 +01:00
|
|
|
else
|
|
|
|
itable[pos] = meth->ncode;
|
2004-11-25 04:47:08 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// The method doesn't exist in klass. Binary compatibility rules
|
|
|
|
// permit this, so we delay the error until runtime using a pointer
|
|
|
|
// to a method which throws an exception.
|
|
|
|
itable[pos] = (void *) _Jv_ThrowNoSuchMethodError;
|
|
|
|
}
|
|
|
|
pos++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return pos;
|
|
|
|
}
|
|
|
|
|
|
|
|
static _Jv_Mutex_t iindex_mutex;
|
|
|
|
static bool iindex_mutex_initialized = false;
|
|
|
|
|
|
|
|
// We need to find the correct offset in the Class Interface Dispatch
|
|
|
|
// Table for a given interface. Once we have that, invoking an interface
|
|
|
|
// method just requires combining the Method's index in the interface
|
|
|
|
// (known at compile time) to get the correct method. Doing a type test
|
|
|
|
// (cast or instanceof) is the same problem: Once we have a possible Partial
|
|
|
|
// Interface Dispatch Table, we just compare the first element to see if it
|
|
|
|
// matches the desired interface. So how can we find the correct offset?
|
|
|
|
// Our solution is to keep a vector of candiate offsets in each interface
|
2006-02-10 00:59:30 +01:00
|
|
|
// (ioffsets), and in each class we have an index (idt->iindex) used to
|
|
|
|
// select the correct offset from ioffsets.
|
2004-11-25 04:47:08 +01:00
|
|
|
//
|
|
|
|
// Calculate and return iindex for a new class.
|
|
|
|
// ifaces is a vector of num interfaces that the class implements.
|
|
|
|
// offsets[j] is the offset in the interface dispatch table for the
|
|
|
|
// interface corresponding to ifaces[j].
|
|
|
|
// May extend the interface ioffsets if required.
|
|
|
|
jshort
|
|
|
|
_Jv_Linker::find_iindex (jclass *ifaces, jshort *offsets, jshort num)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int j;
|
|
|
|
|
|
|
|
// Acquire a global lock to prevent itable corruption in case of multiple
|
|
|
|
// classes that implement an intersecting set of interfaces being linked
|
|
|
|
// simultaneously. We can assume that the mutex will be initialized
|
|
|
|
// single-threaded.
|
|
|
|
if (! iindex_mutex_initialized)
|
|
|
|
{
|
|
|
|
_Jv_MutexInit (&iindex_mutex);
|
|
|
|
iindex_mutex_initialized = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
_Jv_MutexLock (&iindex_mutex);
|
|
|
|
|
|
|
|
for (i=1;; i++) /* each potential position in ioffsets */
|
|
|
|
{
|
|
|
|
for (j=0;; j++) /* each iface */
|
|
|
|
{
|
|
|
|
if (j >= num)
|
|
|
|
goto found;
|
2006-02-10 00:59:30 +01:00
|
|
|
if (i >= ifaces[j]->ioffsets[0])
|
2004-11-25 04:47:08 +01:00
|
|
|
continue;
|
2006-02-10 00:59:30 +01:00
|
|
|
int ioffset = ifaces[j]->ioffsets[i];
|
2004-11-25 04:47:08 +01:00
|
|
|
/* We can potentially share this position with another class. */
|
|
|
|
if (ioffset >= 0 && ioffset != offsets[j])
|
|
|
|
break; /* Nope. Try next i. */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
found:
|
|
|
|
for (j = 0; j < num; j++)
|
|
|
|
{
|
2006-02-10 00:59:30 +01:00
|
|
|
int len = ifaces[j]->ioffsets[0];
|
2004-11-25 04:47:08 +01:00
|
|
|
if (i >= len)
|
|
|
|
{
|
|
|
|
// Resize ioffsets.
|
|
|
|
int newlen = 2 * len;
|
|
|
|
if (i >= newlen)
|
|
|
|
newlen = i + 3;
|
2006-02-10 00:59:30 +01:00
|
|
|
|
|
|
|
jshort *old_ioffsets = ifaces[j]->ioffsets;
|
2006-02-08 21:07:29 +01:00
|
|
|
jshort *new_ioffsets = (jshort *) _Jv_AllocBytes (newlen
|
|
|
|
* sizeof(jshort));
|
2004-11-25 04:47:08 +01:00
|
|
|
memcpy (&new_ioffsets[1], &old_ioffsets[1],
|
|
|
|
(len - 1) * sizeof (jshort));
|
|
|
|
new_ioffsets[0] = newlen;
|
|
|
|
|
|
|
|
while (len < newlen)
|
|
|
|
new_ioffsets[len++] = -1;
|
|
|
|
|
2006-02-10 00:59:30 +01:00
|
|
|
ifaces[j]->ioffsets = new_ioffsets;
|
2004-11-25 04:47:08 +01:00
|
|
|
}
|
2006-02-10 00:59:30 +01:00
|
|
|
ifaces[j]->ioffsets[i] = offsets[j];
|
2004-11-25 04:47:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
_Jv_MutexUnlock (&iindex_mutex);
|
|
|
|
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
2006-06-05 23:21:05 +02:00
|
|
|
#if defined USE_LIBFFI && FFI_CLOSURES
|
2006-02-08 21:07:29 +01:00
|
|
|
// We use a structure of this type to store the closure that
|
|
|
|
// represents a missing method.
|
|
|
|
struct method_closure
|
|
|
|
{
|
|
|
|
// This field must come first, since the address of this field will
|
|
|
|
// be the same as the address of the overall structure. This is due
|
|
|
|
// to disabling interior pointers in the GC.
|
|
|
|
ffi_closure closure;
|
ffi.h.in (ffi_closure_alloc, [...]): New.
libffi/ChangeLog:
* include/ffi.h.in (ffi_closure_alloc, ffi_closure_free): New.
(ffi_prep_closure_loc): New.
(ffi_prep_raw_closure_loc): New.
(ffi_prep_java_raw_closure_loc): New.
* src/closures.c: New file.
* src/dlmalloc.c [FFI_MMAP_EXEC_WRIT] (struct malloc_segment):
Replace sflags with exec_offset.
[FFI_MMAP_EXEC_WRIT] (mmap_exec_offset, add_segment_exec_offset,
sub_segment_exec_offset): New macros.
(get_segment_flags, set_segment_flags, check_segment_merge): New
macros.
(is_mmapped_segment, is_extern_segment): Use get_segment_flags.
(add_segment, sys_alloc, create_mspace, create_mspace_with_base,
destroy_mspace): Use new macros.
(sys_alloc): Silence warning.
* Makefile.am (libffi_la_SOURCES): Add src/closures.c.
* Makefile.in: Rebuilt.
* src/prep_cif [FFI_CLOSURES] (ffi_prep_closure): Implement in
terms of ffi_prep_closure_loc.
* src/raw_api.c (ffi_prep_raw_closure_loc): Renamed and adjusted
from...
(ffi_prep_raw_closure): ... this. Re-implement in terms of the
renamed version.
* src/java_raw_api (ffi_prep_java_raw_closure_loc): Renamed and
adjusted from...
(ffi_prep_java_raw_closure): ... this. Re-implement in terms of
the renamed version.
* src/alpha/ffi.c (ffi_prep_closure_loc): Renamed from
(ffi_prep_closure): ... this.
* src/pa/ffi.c: Likewise.
* src/cris/ffi.c: Likewise. Adjust.
* src/frv/ffi.c: Likewise.
* src/ia64/ffi.c: Likewise.
* src/mips/ffi.c: Likewise.
* src/powerpc/ffi_darwin.c: Likewise.
* src/s390/ffi.c: Likewise.
* src/sh/ffi.c: Likewise.
* src/sh64/ffi.c: Likewise.
* src/sparc/ffi.c: Likewise.
* src/x86/ffi64.c: Likewise.
* src/x86/ffi.c: Likewise.
(FFI_INIT_TRAMPOLINE): Adjust.
(ffi_prep_raw_closure_loc): Renamed and adjusted from...
(ffi_prep_raw_closure): ... this.
* src/powerpc/ffi.c (ffi_prep_closure_loc): Renamed from
(ffi_prep_closure): ... this.
(flush_icache): Adjust.
boehm-gc/ChangeLog:
* include/gc.h (GC_REGISTER_FINALIZER_UNREACHABLE): New.
(GC_register_finalizer_unreachable): Declare.
(GC_debug_register_finalizer_unreachable): Declare.
* finalize.c (GC_unreachable_finalize_mark_proc): New.
(GC_register_finalizer_unreachable): New.
(GC_finalize): Handle it.
* dbg_mlc.c (GC_debug_register_finalizer_unreachable): New.
(GC_debug_register_finalizer_no_order): Fix whitespace.
libjava/ChangeLog:
* include/jvm.h (_Jv_ClosureListFinalizer): New.
(_Jv_Linker::create_error_method): Adjust.
* boehm.cc (_Jv_ClosureListFinalizer): New.
* nogc.cc (_Jv_ClosureListFinalizer): New.
* java/lang/Class.h (class _Jv_ClosureList): New.
(class java::lang::Class): Declare it as friend.
* java/lang/natClass.cc (_Jv_ClosureList::releaseClosures): New.
(_Jv_ClosureList::registerClousure): New.
* include/execution.h (_Jv_ExecutionEngine): Add get_closure_list.
(_Jv_CompiledEngine::do_get_closure_list): New.
(_Jv_CompiledEngine::_Jv_CompiledEngine): Use it.
(_Jv_IndirectCompiledClass): Add closures.
(_Jv_IndirectCompiledEngine::get_aux_info): New.
(_Jv_IndirectCompiledEngine::do_allocate_field_initializers): Use
it.
(_Jv_IndirectCompiledEngine::do_get_closure_list): New.
(_Jv_IndirectCompiledEngine::_Jv_IndirectCompiledEngine): Use it.
(_Jv_InterpreterEngine::do_get_closure_list): Declare.
(_Jv_InterpreterEngine::_Jv_InterpreterEngine): Use it.
* interpret.cc (FFI_PREP_RAW_CLOSURE): Use _loc variants.
(node_closure): Add closure list.
(_Jv_InterpMethod::ncode): Add jclass argument. Use
ffi_closure_alloc and the separate code pointer. Register the
closure for finalization.
(_Jv_JNIMethod::ncode): Likewise.
(_Jv_InterpreterEngine::do_create_ncode): Pass klass to ncode.
(_Jv_InterpreterEngine::do_get_closure_list): New.
* include/java-interp.h (_Jv_InterpMethod::ncode): Adjust.
(_Jv_InterpClass): Add closures field.
(_Jv_JNIMethod::ncode): Adjust.
* defineclass.cc (_Jv_ClassReader::handleCodeAttribute): Adjust.
(_Jv_ClassReader::handleMethodsEnd): Likewise.
* link.cc (struct method_closure): Add closure list.
(_Jv_Linker::create_error_method): Add jclass argument. Use
ffi_closure_alloc and the separate code pointer. Register the
closure for finalization.
(_Jv_Linker::link_symbol_table): Remove outdated comment about
sharing of otable and atable. Adjust.
* java/lang/reflect/natVMProxy.cc (ncode_closure): Add closure
list.
(ncode): Add jclass argument. Use ffi_closure_alloc and the
separate code pointer. Register the closure for finalization.
(java::lang::reflect::VMProxy::generateProxyClass): Adjust.
* testsuite/libjava.jar/TestClosureGC.java: New.
* testsuite/libjava.jar/TestClosureGC.out: New.
* testsuite/libjava.jar/TestClosureGC.xfail: New.
* testsuite/libjava.jar/TestClosureGC.jar: New.
From-SVN: r122652
2007-03-07 08:27:25 +01:00
|
|
|
_Jv_ClosureList list;
|
2006-02-08 21:07:29 +01:00
|
|
|
ffi_cif cif;
|
|
|
|
ffi_type *arg_types[1];
|
|
|
|
};
|
|
|
|
|
2006-02-03 14:47:51 +01:00
|
|
|
void *
|
ffi.h.in (ffi_closure_alloc, [...]): New.
libffi/ChangeLog:
* include/ffi.h.in (ffi_closure_alloc, ffi_closure_free): New.
(ffi_prep_closure_loc): New.
(ffi_prep_raw_closure_loc): New.
(ffi_prep_java_raw_closure_loc): New.
* src/closures.c: New file.
* src/dlmalloc.c [FFI_MMAP_EXEC_WRIT] (struct malloc_segment):
Replace sflags with exec_offset.
[FFI_MMAP_EXEC_WRIT] (mmap_exec_offset, add_segment_exec_offset,
sub_segment_exec_offset): New macros.
(get_segment_flags, set_segment_flags, check_segment_merge): New
macros.
(is_mmapped_segment, is_extern_segment): Use get_segment_flags.
(add_segment, sys_alloc, create_mspace, create_mspace_with_base,
destroy_mspace): Use new macros.
(sys_alloc): Silence warning.
* Makefile.am (libffi_la_SOURCES): Add src/closures.c.
* Makefile.in: Rebuilt.
* src/prep_cif [FFI_CLOSURES] (ffi_prep_closure): Implement in
terms of ffi_prep_closure_loc.
* src/raw_api.c (ffi_prep_raw_closure_loc): Renamed and adjusted
from...
(ffi_prep_raw_closure): ... this. Re-implement in terms of the
renamed version.
* src/java_raw_api (ffi_prep_java_raw_closure_loc): Renamed and
adjusted from...
(ffi_prep_java_raw_closure): ... this. Re-implement in terms of
the renamed version.
* src/alpha/ffi.c (ffi_prep_closure_loc): Renamed from
(ffi_prep_closure): ... this.
* src/pa/ffi.c: Likewise.
* src/cris/ffi.c: Likewise. Adjust.
* src/frv/ffi.c: Likewise.
* src/ia64/ffi.c: Likewise.
* src/mips/ffi.c: Likewise.
* src/powerpc/ffi_darwin.c: Likewise.
* src/s390/ffi.c: Likewise.
* src/sh/ffi.c: Likewise.
* src/sh64/ffi.c: Likewise.
* src/sparc/ffi.c: Likewise.
* src/x86/ffi64.c: Likewise.
* src/x86/ffi.c: Likewise.
(FFI_INIT_TRAMPOLINE): Adjust.
(ffi_prep_raw_closure_loc): Renamed and adjusted from...
(ffi_prep_raw_closure): ... this.
* src/powerpc/ffi.c (ffi_prep_closure_loc): Renamed from
(ffi_prep_closure): ... this.
(flush_icache): Adjust.
boehm-gc/ChangeLog:
* include/gc.h (GC_REGISTER_FINALIZER_UNREACHABLE): New.
(GC_register_finalizer_unreachable): Declare.
(GC_debug_register_finalizer_unreachable): Declare.
* finalize.c (GC_unreachable_finalize_mark_proc): New.
(GC_register_finalizer_unreachable): New.
(GC_finalize): Handle it.
* dbg_mlc.c (GC_debug_register_finalizer_unreachable): New.
(GC_debug_register_finalizer_no_order): Fix whitespace.
libjava/ChangeLog:
* include/jvm.h (_Jv_ClosureListFinalizer): New.
(_Jv_Linker::create_error_method): Adjust.
* boehm.cc (_Jv_ClosureListFinalizer): New.
* nogc.cc (_Jv_ClosureListFinalizer): New.
* java/lang/Class.h (class _Jv_ClosureList): New.
(class java::lang::Class): Declare it as friend.
* java/lang/natClass.cc (_Jv_ClosureList::releaseClosures): New.
(_Jv_ClosureList::registerClousure): New.
* include/execution.h (_Jv_ExecutionEngine): Add get_closure_list.
(_Jv_CompiledEngine::do_get_closure_list): New.
(_Jv_CompiledEngine::_Jv_CompiledEngine): Use it.
(_Jv_IndirectCompiledClass): Add closures.
(_Jv_IndirectCompiledEngine::get_aux_info): New.
(_Jv_IndirectCompiledEngine::do_allocate_field_initializers): Use
it.
(_Jv_IndirectCompiledEngine::do_get_closure_list): New.
(_Jv_IndirectCompiledEngine::_Jv_IndirectCompiledEngine): Use it.
(_Jv_InterpreterEngine::do_get_closure_list): Declare.
(_Jv_InterpreterEngine::_Jv_InterpreterEngine): Use it.
* interpret.cc (FFI_PREP_RAW_CLOSURE): Use _loc variants.
(node_closure): Add closure list.
(_Jv_InterpMethod::ncode): Add jclass argument. Use
ffi_closure_alloc and the separate code pointer. Register the
closure for finalization.
(_Jv_JNIMethod::ncode): Likewise.
(_Jv_InterpreterEngine::do_create_ncode): Pass klass to ncode.
(_Jv_InterpreterEngine::do_get_closure_list): New.
* include/java-interp.h (_Jv_InterpMethod::ncode): Adjust.
(_Jv_InterpClass): Add closures field.
(_Jv_JNIMethod::ncode): Adjust.
* defineclass.cc (_Jv_ClassReader::handleCodeAttribute): Adjust.
(_Jv_ClassReader::handleMethodsEnd): Likewise.
* link.cc (struct method_closure): Add closure list.
(_Jv_Linker::create_error_method): Add jclass argument. Use
ffi_closure_alloc and the separate code pointer. Register the
closure for finalization.
(_Jv_Linker::link_symbol_table): Remove outdated comment about
sharing of otable and atable. Adjust.
* java/lang/reflect/natVMProxy.cc (ncode_closure): Add closure
list.
(ncode): Add jclass argument. Use ffi_closure_alloc and the
separate code pointer. Register the closure for finalization.
(java::lang::reflect::VMProxy::generateProxyClass): Adjust.
* testsuite/libjava.jar/TestClosureGC.java: New.
* testsuite/libjava.jar/TestClosureGC.out: New.
* testsuite/libjava.jar/TestClosureGC.xfail: New.
* testsuite/libjava.jar/TestClosureGC.jar: New.
From-SVN: r122652
2007-03-07 08:27:25 +01:00
|
|
|
_Jv_Linker::create_error_method (_Jv_Utf8Const *class_name, jclass klass)
|
2006-02-03 14:47:51 +01:00
|
|
|
{
|
ffi.h.in (ffi_closure_alloc, [...]): New.
libffi/ChangeLog:
* include/ffi.h.in (ffi_closure_alloc, ffi_closure_free): New.
(ffi_prep_closure_loc): New.
(ffi_prep_raw_closure_loc): New.
(ffi_prep_java_raw_closure_loc): New.
* src/closures.c: New file.
* src/dlmalloc.c [FFI_MMAP_EXEC_WRIT] (struct malloc_segment):
Replace sflags with exec_offset.
[FFI_MMAP_EXEC_WRIT] (mmap_exec_offset, add_segment_exec_offset,
sub_segment_exec_offset): New macros.
(get_segment_flags, set_segment_flags, check_segment_merge): New
macros.
(is_mmapped_segment, is_extern_segment): Use get_segment_flags.
(add_segment, sys_alloc, create_mspace, create_mspace_with_base,
destroy_mspace): Use new macros.
(sys_alloc): Silence warning.
* Makefile.am (libffi_la_SOURCES): Add src/closures.c.
* Makefile.in: Rebuilt.
* src/prep_cif [FFI_CLOSURES] (ffi_prep_closure): Implement in
terms of ffi_prep_closure_loc.
* src/raw_api.c (ffi_prep_raw_closure_loc): Renamed and adjusted
from...
(ffi_prep_raw_closure): ... this. Re-implement in terms of the
renamed version.
* src/java_raw_api (ffi_prep_java_raw_closure_loc): Renamed and
adjusted from...
(ffi_prep_java_raw_closure): ... this. Re-implement in terms of
the renamed version.
* src/alpha/ffi.c (ffi_prep_closure_loc): Renamed from
(ffi_prep_closure): ... this.
* src/pa/ffi.c: Likewise.
* src/cris/ffi.c: Likewise. Adjust.
* src/frv/ffi.c: Likewise.
* src/ia64/ffi.c: Likewise.
* src/mips/ffi.c: Likewise.
* src/powerpc/ffi_darwin.c: Likewise.
* src/s390/ffi.c: Likewise.
* src/sh/ffi.c: Likewise.
* src/sh64/ffi.c: Likewise.
* src/sparc/ffi.c: Likewise.
* src/x86/ffi64.c: Likewise.
* src/x86/ffi.c: Likewise.
(FFI_INIT_TRAMPOLINE): Adjust.
(ffi_prep_raw_closure_loc): Renamed and adjusted from...
(ffi_prep_raw_closure): ... this.
* src/powerpc/ffi.c (ffi_prep_closure_loc): Renamed from
(ffi_prep_closure): ... this.
(flush_icache): Adjust.
boehm-gc/ChangeLog:
* include/gc.h (GC_REGISTER_FINALIZER_UNREACHABLE): New.
(GC_register_finalizer_unreachable): Declare.
(GC_debug_register_finalizer_unreachable): Declare.
* finalize.c (GC_unreachable_finalize_mark_proc): New.
(GC_register_finalizer_unreachable): New.
(GC_finalize): Handle it.
* dbg_mlc.c (GC_debug_register_finalizer_unreachable): New.
(GC_debug_register_finalizer_no_order): Fix whitespace.
libjava/ChangeLog:
* include/jvm.h (_Jv_ClosureListFinalizer): New.
(_Jv_Linker::create_error_method): Adjust.
* boehm.cc (_Jv_ClosureListFinalizer): New.
* nogc.cc (_Jv_ClosureListFinalizer): New.
* java/lang/Class.h (class _Jv_ClosureList): New.
(class java::lang::Class): Declare it as friend.
* java/lang/natClass.cc (_Jv_ClosureList::releaseClosures): New.
(_Jv_ClosureList::registerClousure): New.
* include/execution.h (_Jv_ExecutionEngine): Add get_closure_list.
(_Jv_CompiledEngine::do_get_closure_list): New.
(_Jv_CompiledEngine::_Jv_CompiledEngine): Use it.
(_Jv_IndirectCompiledClass): Add closures.
(_Jv_IndirectCompiledEngine::get_aux_info): New.
(_Jv_IndirectCompiledEngine::do_allocate_field_initializers): Use
it.
(_Jv_IndirectCompiledEngine::do_get_closure_list): New.
(_Jv_IndirectCompiledEngine::_Jv_IndirectCompiledEngine): Use it.
(_Jv_InterpreterEngine::do_get_closure_list): Declare.
(_Jv_InterpreterEngine::_Jv_InterpreterEngine): Use it.
* interpret.cc (FFI_PREP_RAW_CLOSURE): Use _loc variants.
(node_closure): Add closure list.
(_Jv_InterpMethod::ncode): Add jclass argument. Use
ffi_closure_alloc and the separate code pointer. Register the
closure for finalization.
(_Jv_JNIMethod::ncode): Likewise.
(_Jv_InterpreterEngine::do_create_ncode): Pass klass to ncode.
(_Jv_InterpreterEngine::do_get_closure_list): New.
* include/java-interp.h (_Jv_InterpMethod::ncode): Adjust.
(_Jv_InterpClass): Add closures field.
(_Jv_JNIMethod::ncode): Adjust.
* defineclass.cc (_Jv_ClassReader::handleCodeAttribute): Adjust.
(_Jv_ClassReader::handleMethodsEnd): Likewise.
* link.cc (struct method_closure): Add closure list.
(_Jv_Linker::create_error_method): Add jclass argument. Use
ffi_closure_alloc and the separate code pointer. Register the
closure for finalization.
(_Jv_Linker::link_symbol_table): Remove outdated comment about
sharing of otable and atable. Adjust.
* java/lang/reflect/natVMProxy.cc (ncode_closure): Add closure
list.
(ncode): Add jclass argument. Use ffi_closure_alloc and the
separate code pointer. Register the closure for finalization.
(java::lang::reflect::VMProxy::generateProxyClass): Adjust.
* testsuite/libjava.jar/TestClosureGC.java: New.
* testsuite/libjava.jar/TestClosureGC.out: New.
* testsuite/libjava.jar/TestClosureGC.xfail: New.
* testsuite/libjava.jar/TestClosureGC.jar: New.
From-SVN: r122652
2007-03-07 08:27:25 +01:00
|
|
|
void *code;
|
2006-02-08 21:07:29 +01:00
|
|
|
method_closure *closure
|
ffi.h.in (ffi_closure_alloc, [...]): New.
libffi/ChangeLog:
* include/ffi.h.in (ffi_closure_alloc, ffi_closure_free): New.
(ffi_prep_closure_loc): New.
(ffi_prep_raw_closure_loc): New.
(ffi_prep_java_raw_closure_loc): New.
* src/closures.c: New file.
* src/dlmalloc.c [FFI_MMAP_EXEC_WRIT] (struct malloc_segment):
Replace sflags with exec_offset.
[FFI_MMAP_EXEC_WRIT] (mmap_exec_offset, add_segment_exec_offset,
sub_segment_exec_offset): New macros.
(get_segment_flags, set_segment_flags, check_segment_merge): New
macros.
(is_mmapped_segment, is_extern_segment): Use get_segment_flags.
(add_segment, sys_alloc, create_mspace, create_mspace_with_base,
destroy_mspace): Use new macros.
(sys_alloc): Silence warning.
* Makefile.am (libffi_la_SOURCES): Add src/closures.c.
* Makefile.in: Rebuilt.
* src/prep_cif [FFI_CLOSURES] (ffi_prep_closure): Implement in
terms of ffi_prep_closure_loc.
* src/raw_api.c (ffi_prep_raw_closure_loc): Renamed and adjusted
from...
(ffi_prep_raw_closure): ... this. Re-implement in terms of the
renamed version.
* src/java_raw_api (ffi_prep_java_raw_closure_loc): Renamed and
adjusted from...
(ffi_prep_java_raw_closure): ... this. Re-implement in terms of
the renamed version.
* src/alpha/ffi.c (ffi_prep_closure_loc): Renamed from
(ffi_prep_closure): ... this.
* src/pa/ffi.c: Likewise.
* src/cris/ffi.c: Likewise. Adjust.
* src/frv/ffi.c: Likewise.
* src/ia64/ffi.c: Likewise.
* src/mips/ffi.c: Likewise.
* src/powerpc/ffi_darwin.c: Likewise.
* src/s390/ffi.c: Likewise.
* src/sh/ffi.c: Likewise.
* src/sh64/ffi.c: Likewise.
* src/sparc/ffi.c: Likewise.
* src/x86/ffi64.c: Likewise.
* src/x86/ffi.c: Likewise.
(FFI_INIT_TRAMPOLINE): Adjust.
(ffi_prep_raw_closure_loc): Renamed and adjusted from...
(ffi_prep_raw_closure): ... this.
* src/powerpc/ffi.c (ffi_prep_closure_loc): Renamed from
(ffi_prep_closure): ... this.
(flush_icache): Adjust.
boehm-gc/ChangeLog:
* include/gc.h (GC_REGISTER_FINALIZER_UNREACHABLE): New.
(GC_register_finalizer_unreachable): Declare.
(GC_debug_register_finalizer_unreachable): Declare.
* finalize.c (GC_unreachable_finalize_mark_proc): New.
(GC_register_finalizer_unreachable): New.
(GC_finalize): Handle it.
* dbg_mlc.c (GC_debug_register_finalizer_unreachable): New.
(GC_debug_register_finalizer_no_order): Fix whitespace.
libjava/ChangeLog:
* include/jvm.h (_Jv_ClosureListFinalizer): New.
(_Jv_Linker::create_error_method): Adjust.
* boehm.cc (_Jv_ClosureListFinalizer): New.
* nogc.cc (_Jv_ClosureListFinalizer): New.
* java/lang/Class.h (class _Jv_ClosureList): New.
(class java::lang::Class): Declare it as friend.
* java/lang/natClass.cc (_Jv_ClosureList::releaseClosures): New.
(_Jv_ClosureList::registerClousure): New.
* include/execution.h (_Jv_ExecutionEngine): Add get_closure_list.
(_Jv_CompiledEngine::do_get_closure_list): New.
(_Jv_CompiledEngine::_Jv_CompiledEngine): Use it.
(_Jv_IndirectCompiledClass): Add closures.
(_Jv_IndirectCompiledEngine::get_aux_info): New.
(_Jv_IndirectCompiledEngine::do_allocate_field_initializers): Use
it.
(_Jv_IndirectCompiledEngine::do_get_closure_list): New.
(_Jv_IndirectCompiledEngine::_Jv_IndirectCompiledEngine): Use it.
(_Jv_InterpreterEngine::do_get_closure_list): Declare.
(_Jv_InterpreterEngine::_Jv_InterpreterEngine): Use it.
* interpret.cc (FFI_PREP_RAW_CLOSURE): Use _loc variants.
(node_closure): Add closure list.
(_Jv_InterpMethod::ncode): Add jclass argument. Use
ffi_closure_alloc and the separate code pointer. Register the
closure for finalization.
(_Jv_JNIMethod::ncode): Likewise.
(_Jv_InterpreterEngine::do_create_ncode): Pass klass to ncode.
(_Jv_InterpreterEngine::do_get_closure_list): New.
* include/java-interp.h (_Jv_InterpMethod::ncode): Adjust.
(_Jv_InterpClass): Add closures field.
(_Jv_JNIMethod::ncode): Adjust.
* defineclass.cc (_Jv_ClassReader::handleCodeAttribute): Adjust.
(_Jv_ClassReader::handleMethodsEnd): Likewise.
* link.cc (struct method_closure): Add closure list.
(_Jv_Linker::create_error_method): Add jclass argument. Use
ffi_closure_alloc and the separate code pointer. Register the
closure for finalization.
(_Jv_Linker::link_symbol_table): Remove outdated comment about
sharing of otable and atable. Adjust.
* java/lang/reflect/natVMProxy.cc (ncode_closure): Add closure
list.
(ncode): Add jclass argument. Use ffi_closure_alloc and the
separate code pointer. Register the closure for finalization.
(java::lang::reflect::VMProxy::generateProxyClass): Adjust.
* testsuite/libjava.jar/TestClosureGC.java: New.
* testsuite/libjava.jar/TestClosureGC.out: New.
* testsuite/libjava.jar/TestClosureGC.xfail: New.
* testsuite/libjava.jar/TestClosureGC.jar: New.
From-SVN: r122652
2007-03-07 08:27:25 +01:00
|
|
|
= (method_closure *)ffi_closure_alloc (sizeof (method_closure), &code);
|
2006-02-08 21:07:29 +01:00
|
|
|
|
|
|
|
closure->arg_types[0] = &ffi_type_void;
|
|
|
|
|
|
|
|
// Initializes the cif and the closure. If that worked the closure
|
|
|
|
// is returned and can be used as a function pointer in a class'
|
|
|
|
// atable.
|
2006-02-21 11:32:31 +01:00
|
|
|
if ( ffi_prep_cif (&closure->cif,
|
|
|
|
FFI_DEFAULT_ABI,
|
|
|
|
1,
|
|
|
|
&ffi_type_void,
|
|
|
|
closure->arg_types) == FFI_OK
|
ffi.h.in (ffi_closure_alloc, [...]): New.
libffi/ChangeLog:
* include/ffi.h.in (ffi_closure_alloc, ffi_closure_free): New.
(ffi_prep_closure_loc): New.
(ffi_prep_raw_closure_loc): New.
(ffi_prep_java_raw_closure_loc): New.
* src/closures.c: New file.
* src/dlmalloc.c [FFI_MMAP_EXEC_WRIT] (struct malloc_segment):
Replace sflags with exec_offset.
[FFI_MMAP_EXEC_WRIT] (mmap_exec_offset, add_segment_exec_offset,
sub_segment_exec_offset): New macros.
(get_segment_flags, set_segment_flags, check_segment_merge): New
macros.
(is_mmapped_segment, is_extern_segment): Use get_segment_flags.
(add_segment, sys_alloc, create_mspace, create_mspace_with_base,
destroy_mspace): Use new macros.
(sys_alloc): Silence warning.
* Makefile.am (libffi_la_SOURCES): Add src/closures.c.
* Makefile.in: Rebuilt.
* src/prep_cif [FFI_CLOSURES] (ffi_prep_closure): Implement in
terms of ffi_prep_closure_loc.
* src/raw_api.c (ffi_prep_raw_closure_loc): Renamed and adjusted
from...
(ffi_prep_raw_closure): ... this. Re-implement in terms of the
renamed version.
* src/java_raw_api (ffi_prep_java_raw_closure_loc): Renamed and
adjusted from...
(ffi_prep_java_raw_closure): ... this. Re-implement in terms of
the renamed version.
* src/alpha/ffi.c (ffi_prep_closure_loc): Renamed from
(ffi_prep_closure): ... this.
* src/pa/ffi.c: Likewise.
* src/cris/ffi.c: Likewise. Adjust.
* src/frv/ffi.c: Likewise.
* src/ia64/ffi.c: Likewise.
* src/mips/ffi.c: Likewise.
* src/powerpc/ffi_darwin.c: Likewise.
* src/s390/ffi.c: Likewise.
* src/sh/ffi.c: Likewise.
* src/sh64/ffi.c: Likewise.
* src/sparc/ffi.c: Likewise.
* src/x86/ffi64.c: Likewise.
* src/x86/ffi.c: Likewise.
(FFI_INIT_TRAMPOLINE): Adjust.
(ffi_prep_raw_closure_loc): Renamed and adjusted from...
(ffi_prep_raw_closure): ... this.
* src/powerpc/ffi.c (ffi_prep_closure_loc): Renamed from
(ffi_prep_closure): ... this.
(flush_icache): Adjust.
boehm-gc/ChangeLog:
* include/gc.h (GC_REGISTER_FINALIZER_UNREACHABLE): New.
(GC_register_finalizer_unreachable): Declare.
(GC_debug_register_finalizer_unreachable): Declare.
* finalize.c (GC_unreachable_finalize_mark_proc): New.
(GC_register_finalizer_unreachable): New.
(GC_finalize): Handle it.
* dbg_mlc.c (GC_debug_register_finalizer_unreachable): New.
(GC_debug_register_finalizer_no_order): Fix whitespace.
libjava/ChangeLog:
* include/jvm.h (_Jv_ClosureListFinalizer): New.
(_Jv_Linker::create_error_method): Adjust.
* boehm.cc (_Jv_ClosureListFinalizer): New.
* nogc.cc (_Jv_ClosureListFinalizer): New.
* java/lang/Class.h (class _Jv_ClosureList): New.
(class java::lang::Class): Declare it as friend.
* java/lang/natClass.cc (_Jv_ClosureList::releaseClosures): New.
(_Jv_ClosureList::registerClousure): New.
* include/execution.h (_Jv_ExecutionEngine): Add get_closure_list.
(_Jv_CompiledEngine::do_get_closure_list): New.
(_Jv_CompiledEngine::_Jv_CompiledEngine): Use it.
(_Jv_IndirectCompiledClass): Add closures.
(_Jv_IndirectCompiledEngine::get_aux_info): New.
(_Jv_IndirectCompiledEngine::do_allocate_field_initializers): Use
it.
(_Jv_IndirectCompiledEngine::do_get_closure_list): New.
(_Jv_IndirectCompiledEngine::_Jv_IndirectCompiledEngine): Use it.
(_Jv_InterpreterEngine::do_get_closure_list): Declare.
(_Jv_InterpreterEngine::_Jv_InterpreterEngine): Use it.
* interpret.cc (FFI_PREP_RAW_CLOSURE): Use _loc variants.
(node_closure): Add closure list.
(_Jv_InterpMethod::ncode): Add jclass argument. Use
ffi_closure_alloc and the separate code pointer. Register the
closure for finalization.
(_Jv_JNIMethod::ncode): Likewise.
(_Jv_InterpreterEngine::do_create_ncode): Pass klass to ncode.
(_Jv_InterpreterEngine::do_get_closure_list): New.
* include/java-interp.h (_Jv_InterpMethod::ncode): Adjust.
(_Jv_InterpClass): Add closures field.
(_Jv_JNIMethod::ncode): Adjust.
* defineclass.cc (_Jv_ClassReader::handleCodeAttribute): Adjust.
(_Jv_ClassReader::handleMethodsEnd): Likewise.
* link.cc (struct method_closure): Add closure list.
(_Jv_Linker::create_error_method): Add jclass argument. Use
ffi_closure_alloc and the separate code pointer. Register the
closure for finalization.
(_Jv_Linker::link_symbol_table): Remove outdated comment about
sharing of otable and atable. Adjust.
* java/lang/reflect/natVMProxy.cc (ncode_closure): Add closure
list.
(ncode): Add jclass argument. Use ffi_closure_alloc and the
separate code pointer. Register the closure for finalization.
(java::lang::reflect::VMProxy::generateProxyClass): Adjust.
* testsuite/libjava.jar/TestClosureGC.java: New.
* testsuite/libjava.jar/TestClosureGC.out: New.
* testsuite/libjava.jar/TestClosureGC.xfail: New.
* testsuite/libjava.jar/TestClosureGC.jar: New.
From-SVN: r122652
2007-03-07 08:27:25 +01:00
|
|
|
&& ffi_prep_closure_loc (&closure->closure,
|
|
|
|
&closure->cif,
|
|
|
|
_Jv_ThrowNoClassDefFoundErrorTrampoline,
|
|
|
|
class_name,
|
|
|
|
code) == FFI_OK)
|
|
|
|
{
|
|
|
|
closure->list.registerClosure (klass, closure);
|
|
|
|
return code;
|
|
|
|
}
|
2006-02-08 21:07:29 +01:00
|
|
|
else
|
2006-02-03 14:47:51 +01:00
|
|
|
{
|
ffi.h.in (ffi_closure_alloc, [...]): New.
libffi/ChangeLog:
* include/ffi.h.in (ffi_closure_alloc, ffi_closure_free): New.
(ffi_prep_closure_loc): New.
(ffi_prep_raw_closure_loc): New.
(ffi_prep_java_raw_closure_loc): New.
* src/closures.c: New file.
* src/dlmalloc.c [FFI_MMAP_EXEC_WRIT] (struct malloc_segment):
Replace sflags with exec_offset.
[FFI_MMAP_EXEC_WRIT] (mmap_exec_offset, add_segment_exec_offset,
sub_segment_exec_offset): New macros.
(get_segment_flags, set_segment_flags, check_segment_merge): New
macros.
(is_mmapped_segment, is_extern_segment): Use get_segment_flags.
(add_segment, sys_alloc, create_mspace, create_mspace_with_base,
destroy_mspace): Use new macros.
(sys_alloc): Silence warning.
* Makefile.am (libffi_la_SOURCES): Add src/closures.c.
* Makefile.in: Rebuilt.
* src/prep_cif [FFI_CLOSURES] (ffi_prep_closure): Implement in
terms of ffi_prep_closure_loc.
* src/raw_api.c (ffi_prep_raw_closure_loc): Renamed and adjusted
from...
(ffi_prep_raw_closure): ... this. Re-implement in terms of the
renamed version.
* src/java_raw_api (ffi_prep_java_raw_closure_loc): Renamed and
adjusted from...
(ffi_prep_java_raw_closure): ... this. Re-implement in terms of
the renamed version.
* src/alpha/ffi.c (ffi_prep_closure_loc): Renamed from
(ffi_prep_closure): ... this.
* src/pa/ffi.c: Likewise.
* src/cris/ffi.c: Likewise. Adjust.
* src/frv/ffi.c: Likewise.
* src/ia64/ffi.c: Likewise.
* src/mips/ffi.c: Likewise.
* src/powerpc/ffi_darwin.c: Likewise.
* src/s390/ffi.c: Likewise.
* src/sh/ffi.c: Likewise.
* src/sh64/ffi.c: Likewise.
* src/sparc/ffi.c: Likewise.
* src/x86/ffi64.c: Likewise.
* src/x86/ffi.c: Likewise.
(FFI_INIT_TRAMPOLINE): Adjust.
(ffi_prep_raw_closure_loc): Renamed and adjusted from...
(ffi_prep_raw_closure): ... this.
* src/powerpc/ffi.c (ffi_prep_closure_loc): Renamed from
(ffi_prep_closure): ... this.
(flush_icache): Adjust.
boehm-gc/ChangeLog:
* include/gc.h (GC_REGISTER_FINALIZER_UNREACHABLE): New.
(GC_register_finalizer_unreachable): Declare.
(GC_debug_register_finalizer_unreachable): Declare.
* finalize.c (GC_unreachable_finalize_mark_proc): New.
(GC_register_finalizer_unreachable): New.
(GC_finalize): Handle it.
* dbg_mlc.c (GC_debug_register_finalizer_unreachable): New.
(GC_debug_register_finalizer_no_order): Fix whitespace.
libjava/ChangeLog:
* include/jvm.h (_Jv_ClosureListFinalizer): New.
(_Jv_Linker::create_error_method): Adjust.
* boehm.cc (_Jv_ClosureListFinalizer): New.
* nogc.cc (_Jv_ClosureListFinalizer): New.
* java/lang/Class.h (class _Jv_ClosureList): New.
(class java::lang::Class): Declare it as friend.
* java/lang/natClass.cc (_Jv_ClosureList::releaseClosures): New.
(_Jv_ClosureList::registerClousure): New.
* include/execution.h (_Jv_ExecutionEngine): Add get_closure_list.
(_Jv_CompiledEngine::do_get_closure_list): New.
(_Jv_CompiledEngine::_Jv_CompiledEngine): Use it.
(_Jv_IndirectCompiledClass): Add closures.
(_Jv_IndirectCompiledEngine::get_aux_info): New.
(_Jv_IndirectCompiledEngine::do_allocate_field_initializers): Use
it.
(_Jv_IndirectCompiledEngine::do_get_closure_list): New.
(_Jv_IndirectCompiledEngine::_Jv_IndirectCompiledEngine): Use it.
(_Jv_InterpreterEngine::do_get_closure_list): Declare.
(_Jv_InterpreterEngine::_Jv_InterpreterEngine): Use it.
* interpret.cc (FFI_PREP_RAW_CLOSURE): Use _loc variants.
(node_closure): Add closure list.
(_Jv_InterpMethod::ncode): Add jclass argument. Use
ffi_closure_alloc and the separate code pointer. Register the
closure for finalization.
(_Jv_JNIMethod::ncode): Likewise.
(_Jv_InterpreterEngine::do_create_ncode): Pass klass to ncode.
(_Jv_InterpreterEngine::do_get_closure_list): New.
* include/java-interp.h (_Jv_InterpMethod::ncode): Adjust.
(_Jv_InterpClass): Add closures field.
(_Jv_JNIMethod::ncode): Adjust.
* defineclass.cc (_Jv_ClassReader::handleCodeAttribute): Adjust.
(_Jv_ClassReader::handleMethodsEnd): Likewise.
* link.cc (struct method_closure): Add closure list.
(_Jv_Linker::create_error_method): Add jclass argument. Use
ffi_closure_alloc and the separate code pointer. Register the
closure for finalization.
(_Jv_Linker::link_symbol_table): Remove outdated comment about
sharing of otable and atable. Adjust.
* java/lang/reflect/natVMProxy.cc (ncode_closure): Add closure
list.
(ncode): Add jclass argument. Use ffi_closure_alloc and the
separate code pointer. Register the closure for finalization.
(java::lang::reflect::VMProxy::generateProxyClass): Adjust.
* testsuite/libjava.jar/TestClosureGC.java: New.
* testsuite/libjava.jar/TestClosureGC.out: New.
* testsuite/libjava.jar/TestClosureGC.xfail: New.
* testsuite/libjava.jar/TestClosureGC.jar: New.
From-SVN: r122652
2007-03-07 08:27:25 +01:00
|
|
|
ffi_closure_free (closure);
|
2006-02-03 14:47:51 +01:00
|
|
|
java::lang::StringBuffer *buffer = new java::lang::StringBuffer();
|
2006-02-08 21:07:29 +01:00
|
|
|
buffer->append(JvNewStringLatin1("Error setting up FFI closure"
|
|
|
|
" for static method of"
|
|
|
|
" missing class: "));
|
2006-02-03 14:47:51 +01:00
|
|
|
buffer->append (_Jv_NewStringUtf8Const(class_name));
|
|
|
|
throw new java::lang::InternalError(buffer->toString());
|
|
|
|
}
|
2006-02-21 11:32:31 +01:00
|
|
|
}
|
2006-02-03 14:47:51 +01:00
|
|
|
#else
|
2006-02-21 11:32:31 +01:00
|
|
|
void *
|
ffi.h.in (ffi_closure_alloc, [...]): New.
libffi/ChangeLog:
* include/ffi.h.in (ffi_closure_alloc, ffi_closure_free): New.
(ffi_prep_closure_loc): New.
(ffi_prep_raw_closure_loc): New.
(ffi_prep_java_raw_closure_loc): New.
* src/closures.c: New file.
* src/dlmalloc.c [FFI_MMAP_EXEC_WRIT] (struct malloc_segment):
Replace sflags with exec_offset.
[FFI_MMAP_EXEC_WRIT] (mmap_exec_offset, add_segment_exec_offset,
sub_segment_exec_offset): New macros.
(get_segment_flags, set_segment_flags, check_segment_merge): New
macros.
(is_mmapped_segment, is_extern_segment): Use get_segment_flags.
(add_segment, sys_alloc, create_mspace, create_mspace_with_base,
destroy_mspace): Use new macros.
(sys_alloc): Silence warning.
* Makefile.am (libffi_la_SOURCES): Add src/closures.c.
* Makefile.in: Rebuilt.
* src/prep_cif [FFI_CLOSURES] (ffi_prep_closure): Implement in
terms of ffi_prep_closure_loc.
* src/raw_api.c (ffi_prep_raw_closure_loc): Renamed and adjusted
from...
(ffi_prep_raw_closure): ... this. Re-implement in terms of the
renamed version.
* src/java_raw_api (ffi_prep_java_raw_closure_loc): Renamed and
adjusted from...
(ffi_prep_java_raw_closure): ... this. Re-implement in terms of
the renamed version.
* src/alpha/ffi.c (ffi_prep_closure_loc): Renamed from
(ffi_prep_closure): ... this.
* src/pa/ffi.c: Likewise.
* src/cris/ffi.c: Likewise. Adjust.
* src/frv/ffi.c: Likewise.
* src/ia64/ffi.c: Likewise.
* src/mips/ffi.c: Likewise.
* src/powerpc/ffi_darwin.c: Likewise.
* src/s390/ffi.c: Likewise.
* src/sh/ffi.c: Likewise.
* src/sh64/ffi.c: Likewise.
* src/sparc/ffi.c: Likewise.
* src/x86/ffi64.c: Likewise.
* src/x86/ffi.c: Likewise.
(FFI_INIT_TRAMPOLINE): Adjust.
(ffi_prep_raw_closure_loc): Renamed and adjusted from...
(ffi_prep_raw_closure): ... this.
* src/powerpc/ffi.c (ffi_prep_closure_loc): Renamed from
(ffi_prep_closure): ... this.
(flush_icache): Adjust.
boehm-gc/ChangeLog:
* include/gc.h (GC_REGISTER_FINALIZER_UNREACHABLE): New.
(GC_register_finalizer_unreachable): Declare.
(GC_debug_register_finalizer_unreachable): Declare.
* finalize.c (GC_unreachable_finalize_mark_proc): New.
(GC_register_finalizer_unreachable): New.
(GC_finalize): Handle it.
* dbg_mlc.c (GC_debug_register_finalizer_unreachable): New.
(GC_debug_register_finalizer_no_order): Fix whitespace.
libjava/ChangeLog:
* include/jvm.h (_Jv_ClosureListFinalizer): New.
(_Jv_Linker::create_error_method): Adjust.
* boehm.cc (_Jv_ClosureListFinalizer): New.
* nogc.cc (_Jv_ClosureListFinalizer): New.
* java/lang/Class.h (class _Jv_ClosureList): New.
(class java::lang::Class): Declare it as friend.
* java/lang/natClass.cc (_Jv_ClosureList::releaseClosures): New.
(_Jv_ClosureList::registerClousure): New.
* include/execution.h (_Jv_ExecutionEngine): Add get_closure_list.
(_Jv_CompiledEngine::do_get_closure_list): New.
(_Jv_CompiledEngine::_Jv_CompiledEngine): Use it.
(_Jv_IndirectCompiledClass): Add closures.
(_Jv_IndirectCompiledEngine::get_aux_info): New.
(_Jv_IndirectCompiledEngine::do_allocate_field_initializers): Use
it.
(_Jv_IndirectCompiledEngine::do_get_closure_list): New.
(_Jv_IndirectCompiledEngine::_Jv_IndirectCompiledEngine): Use it.
(_Jv_InterpreterEngine::do_get_closure_list): Declare.
(_Jv_InterpreterEngine::_Jv_InterpreterEngine): Use it.
* interpret.cc (FFI_PREP_RAW_CLOSURE): Use _loc variants.
(node_closure): Add closure list.
(_Jv_InterpMethod::ncode): Add jclass argument. Use
ffi_closure_alloc and the separate code pointer. Register the
closure for finalization.
(_Jv_JNIMethod::ncode): Likewise.
(_Jv_InterpreterEngine::do_create_ncode): Pass klass to ncode.
(_Jv_InterpreterEngine::do_get_closure_list): New.
* include/java-interp.h (_Jv_InterpMethod::ncode): Adjust.
(_Jv_InterpClass): Add closures field.
(_Jv_JNIMethod::ncode): Adjust.
* defineclass.cc (_Jv_ClassReader::handleCodeAttribute): Adjust.
(_Jv_ClassReader::handleMethodsEnd): Likewise.
* link.cc (struct method_closure): Add closure list.
(_Jv_Linker::create_error_method): Add jclass argument. Use
ffi_closure_alloc and the separate code pointer. Register the
closure for finalization.
(_Jv_Linker::link_symbol_table): Remove outdated comment about
sharing of otable and atable. Adjust.
* java/lang/reflect/natVMProxy.cc (ncode_closure): Add closure
list.
(ncode): Add jclass argument. Use ffi_closure_alloc and the
separate code pointer. Register the closure for finalization.
(java::lang::reflect::VMProxy::generateProxyClass): Adjust.
* testsuite/libjava.jar/TestClosureGC.java: New.
* testsuite/libjava.jar/TestClosureGC.out: New.
* testsuite/libjava.jar/TestClosureGC.xfail: New.
* testsuite/libjava.jar/TestClosureGC.jar: New.
From-SVN: r122652
2007-03-07 08:27:25 +01:00
|
|
|
_Jv_Linker::create_error_method (_Jv_Utf8Const *, jclass)
|
2006-02-21 11:32:31 +01:00
|
|
|
{
|
2006-02-03 14:47:51 +01:00
|
|
|
// Codepath for platforms which do not support (or want) libffi.
|
|
|
|
// You have to accept that it is impossible to provide the name
|
|
|
|
// of the missing class then.
|
2006-02-03 14:54:19 +01:00
|
|
|
return (void *) _Jv_ThrowNoClassDefFoundError;
|
2006-02-03 14:47:51 +01:00
|
|
|
}
|
2006-06-05 23:21:05 +02:00
|
|
|
#endif // USE_LIBFFI && FFI_CLOSURES
|
2006-02-03 14:47:51 +01:00
|
|
|
|
2004-11-25 04:47:08 +01:00
|
|
|
// Functions for indirect dispatch (symbolic virtual binding) support.
|
|
|
|
|
|
|
|
// There are three tables, atable otable and itable. atable is an
|
|
|
|
// array of addresses, and otable is an array of offsets, and these
|
|
|
|
// are used for static and virtual members respectively. itable is an
|
|
|
|
// array of pairs {address, index} where each address is a pointer to
|
|
|
|
// an interface.
|
|
|
|
|
|
|
|
// {a,o,i}table_syms is an array of _Jv_MethodSymbols. Each such
|
|
|
|
// symbol is a tuple of {classname, member name, signature}.
|
|
|
|
|
|
|
|
// Set this to true to enable debugging of indirect dispatch tables/linking.
|
|
|
|
static bool debug_link = false;
|
|
|
|
|
|
|
|
// link_symbol_table() scans these two arrays and fills in the
|
|
|
|
// corresponding atable and otable with the addresses of static
|
|
|
|
// members and the offsets of virtual members.
|
|
|
|
|
|
|
|
// The offset (in bytes) for each resolved method or field is placed
|
|
|
|
// at the corresponding position in the virtual method offset table
|
|
|
|
// (klass->otable).
|
|
|
|
|
|
|
|
// This must be called while holding the class lock.
|
|
|
|
|
|
|
|
void
|
|
|
|
_Jv_Linker::link_symbol_table (jclass klass)
|
|
|
|
{
|
|
|
|
int index = 0;
|
|
|
|
_Jv_MethodSymbol sym;
|
|
|
|
if (klass->otable == NULL
|
|
|
|
|| klass->otable->state != 0)
|
|
|
|
goto atable;
|
|
|
|
|
|
|
|
klass->otable->state = 1;
|
|
|
|
|
|
|
|
if (debug_link)
|
|
|
|
fprintf (stderr, "Fixing up otable in %s:\n", klass->name->chars());
|
|
|
|
for (index = 0;
|
|
|
|
(sym = klass->otable_syms[index]).class_name != NULL;
|
|
|
|
++index)
|
|
|
|
{
|
|
|
|
jclass target_class = _Jv_FindClass (sym.class_name, klass->loader);
|
|
|
|
_Jv_Method *meth = NULL;
|
|
|
|
|
|
|
|
_Jv_Utf8Const *signature = sym.signature;
|
2006-06-08 16:00:43 +02:00
|
|
|
uaddr special;
|
|
|
|
maybe_adjust_signature (signature, special);
|
2004-11-25 04:47:08 +01:00
|
|
|
|
|
|
|
if (target_class == NULL)
|
|
|
|
throw new java::lang::NoClassDefFoundError
|
|
|
|
(_Jv_NewStringUTF (sym.class_name->chars()));
|
|
|
|
|
|
|
|
// We're looking for a field or a method, and we can tell
|
|
|
|
// which is needed by looking at the signature.
|
|
|
|
if (signature->first() == '(' && signature->len() >= 2)
|
|
|
|
{
|
|
|
|
// Looks like someone is trying to invoke an interface method
|
|
|
|
if (target_class->isInterface())
|
|
|
|
{
|
|
|
|
using namespace java::lang;
|
|
|
|
StringBuffer *sb = new StringBuffer();
|
|
|
|
sb->append(JvNewStringLatin1("found interface "));
|
|
|
|
sb->append(target_class->getName());
|
|
|
|
sb->append(JvNewStringLatin1(" when searching for a class"));
|
|
|
|
throw new VerifyError(sb->toString());
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the target class does not have a vtable_method_count yet,
|
|
|
|
// then we can't tell the offsets for its methods, so we must lay
|
|
|
|
// it out now.
|
|
|
|
wait_for_state(target_class, JV_STATE_PREPARED);
|
|
|
|
|
2006-06-08 16:00:43 +02:00
|
|
|
try
|
|
|
|
{
|
|
|
|
meth = (search_method_in_superclasses
|
|
|
|
(target_class, klass, sym.name, signature,
|
|
|
|
NULL, special == 0));
|
|
|
|
}
|
|
|
|
catch (::java::lang::IllegalAccessError *e)
|
|
|
|
{
|
|
|
|
}
|
2004-11-25 04:47:08 +01:00
|
|
|
|
2005-12-08 15:19:13 +01:00
|
|
|
// Every class has a throwNoSuchMethodErrorIndex method that
|
|
|
|
// it inherits from java.lang.Object. Find its vtable
|
|
|
|
// offset.
|
|
|
|
static int throwNoSuchMethodErrorIndex;
|
|
|
|
if (throwNoSuchMethodErrorIndex == 0)
|
2004-11-25 04:47:08 +01:00
|
|
|
{
|
2005-12-08 15:19:13 +01:00
|
|
|
Utf8Const* name
|
|
|
|
= _Jv_makeUtf8Const ("throwNoSuchMethodError",
|
|
|
|
strlen ("throwNoSuchMethodError"));
|
|
|
|
_Jv_Method* meth
|
|
|
|
= _Jv_LookupDeclaredMethod (&java::lang::Object::class$,
|
|
|
|
name, gcj::void_signature);
|
|
|
|
throwNoSuchMethodErrorIndex
|
|
|
|
= _Jv_VTable::idx_to_offset (meth->index);
|
2004-11-25 04:47:08 +01:00
|
|
|
}
|
2005-12-08 15:19:13 +01:00
|
|
|
|
|
|
|
// If we don't find a nonstatic method, insert the
|
|
|
|
// vtable index of Object.throwNoSuchMethodError().
|
|
|
|
// This defers the missing method error until an attempt
|
|
|
|
// is made to execute it.
|
|
|
|
{
|
|
|
|
int offset;
|
|
|
|
|
|
|
|
if (meth != NULL)
|
|
|
|
offset = _Jv_VTable::idx_to_offset (meth->index);
|
|
|
|
else
|
|
|
|
offset = throwNoSuchMethodErrorIndex;
|
|
|
|
|
|
|
|
if (offset == -1)
|
|
|
|
JvFail ("Bad method index");
|
|
|
|
JvAssert (meth->index < target_class->vtable_method_count);
|
|
|
|
|
|
|
|
klass->otable->offsets[index] = offset;
|
|
|
|
}
|
|
|
|
|
2004-11-25 04:47:08 +01:00
|
|
|
if (debug_link)
|
|
|
|
fprintf (stderr, " offsets[%d] = %d (class %s@%p : %s(%s))\n",
|
|
|
|
(int)index,
|
|
|
|
(int)klass->otable->offsets[index],
|
|
|
|
(const char*)target_class->name->chars(),
|
|
|
|
target_class,
|
|
|
|
(const char*)sym.name->chars(),
|
|
|
|
(const char*)signature->chars());
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2005-01-10 20:21:46 +01:00
|
|
|
// Try fields.
|
2004-11-25 04:47:08 +01:00
|
|
|
{
|
|
|
|
wait_for_state(target_class, JV_STATE_PREPARED);
|
2005-04-29 20:35:36 +02:00
|
|
|
jclass found_class;
|
2005-12-08 15:19:13 +01:00
|
|
|
_Jv_Field *the_field = NULL;
|
|
|
|
try
|
|
|
|
{
|
|
|
|
the_field = find_field (klass, target_class, &found_class,
|
2006-06-08 16:00:43 +02:00
|
|
|
sym.name, signature);
|
2005-12-08 15:19:13 +01:00
|
|
|
if ((the_field->flags & java::lang::reflect::Modifier::STATIC))
|
|
|
|
throw new java::lang::IncompatibleClassChangeError;
|
|
|
|
else
|
|
|
|
klass->otable->offsets[index] = the_field->u.boffset;
|
|
|
|
}
|
|
|
|
catch (java::lang::NoSuchFieldError *err)
|
|
|
|
{
|
|
|
|
klass->otable->offsets[index] = 0;
|
|
|
|
}
|
2004-11-25 04:47:08 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
atable:
|
|
|
|
if (klass->atable == NULL || klass->atable->state != 0)
|
|
|
|
goto itable;
|
|
|
|
|
|
|
|
klass->atable->state = 1;
|
|
|
|
|
|
|
|
for (index = 0;
|
|
|
|
(sym = klass->atable_syms[index]).class_name != NULL;
|
|
|
|
++index)
|
|
|
|
{
|
2006-02-01 14:40:05 +01:00
|
|
|
jclass target_class =
|
|
|
|
_Jv_FindClassNoException (sym.class_name, klass->loader);
|
|
|
|
|
2004-11-25 04:47:08 +01:00
|
|
|
_Jv_Method *meth = NULL;
|
2006-06-08 16:00:43 +02:00
|
|
|
|
2004-11-25 04:47:08 +01:00
|
|
|
_Jv_Utf8Const *signature = sym.signature;
|
2006-06-08 16:00:43 +02:00
|
|
|
uaddr special;
|
|
|
|
maybe_adjust_signature (signature, special);
|
2004-11-25 04:47:08 +01:00
|
|
|
|
|
|
|
// ??? Setting this pointer to null will at least get us a
|
|
|
|
// NullPointerException
|
|
|
|
klass->atable->addresses[index] = NULL;
|
2006-02-01 14:40:05 +01:00
|
|
|
|
ffi.h.in (ffi_closure_alloc, [...]): New.
libffi/ChangeLog:
* include/ffi.h.in (ffi_closure_alloc, ffi_closure_free): New.
(ffi_prep_closure_loc): New.
(ffi_prep_raw_closure_loc): New.
(ffi_prep_java_raw_closure_loc): New.
* src/closures.c: New file.
* src/dlmalloc.c [FFI_MMAP_EXEC_WRIT] (struct malloc_segment):
Replace sflags with exec_offset.
[FFI_MMAP_EXEC_WRIT] (mmap_exec_offset, add_segment_exec_offset,
sub_segment_exec_offset): New macros.
(get_segment_flags, set_segment_flags, check_segment_merge): New
macros.
(is_mmapped_segment, is_extern_segment): Use get_segment_flags.
(add_segment, sys_alloc, create_mspace, create_mspace_with_base,
destroy_mspace): Use new macros.
(sys_alloc): Silence warning.
* Makefile.am (libffi_la_SOURCES): Add src/closures.c.
* Makefile.in: Rebuilt.
* src/prep_cif [FFI_CLOSURES] (ffi_prep_closure): Implement in
terms of ffi_prep_closure_loc.
* src/raw_api.c (ffi_prep_raw_closure_loc): Renamed and adjusted
from...
(ffi_prep_raw_closure): ... this. Re-implement in terms of the
renamed version.
* src/java_raw_api (ffi_prep_java_raw_closure_loc): Renamed and
adjusted from...
(ffi_prep_java_raw_closure): ... this. Re-implement in terms of
the renamed version.
* src/alpha/ffi.c (ffi_prep_closure_loc): Renamed from
(ffi_prep_closure): ... this.
* src/pa/ffi.c: Likewise.
* src/cris/ffi.c: Likewise. Adjust.
* src/frv/ffi.c: Likewise.
* src/ia64/ffi.c: Likewise.
* src/mips/ffi.c: Likewise.
* src/powerpc/ffi_darwin.c: Likewise.
* src/s390/ffi.c: Likewise.
* src/sh/ffi.c: Likewise.
* src/sh64/ffi.c: Likewise.
* src/sparc/ffi.c: Likewise.
* src/x86/ffi64.c: Likewise.
* src/x86/ffi.c: Likewise.
(FFI_INIT_TRAMPOLINE): Adjust.
(ffi_prep_raw_closure_loc): Renamed and adjusted from...
(ffi_prep_raw_closure): ... this.
* src/powerpc/ffi.c (ffi_prep_closure_loc): Renamed from
(ffi_prep_closure): ... this.
(flush_icache): Adjust.
boehm-gc/ChangeLog:
* include/gc.h (GC_REGISTER_FINALIZER_UNREACHABLE): New.
(GC_register_finalizer_unreachable): Declare.
(GC_debug_register_finalizer_unreachable): Declare.
* finalize.c (GC_unreachable_finalize_mark_proc): New.
(GC_register_finalizer_unreachable): New.
(GC_finalize): Handle it.
* dbg_mlc.c (GC_debug_register_finalizer_unreachable): New.
(GC_debug_register_finalizer_no_order): Fix whitespace.
libjava/ChangeLog:
* include/jvm.h (_Jv_ClosureListFinalizer): New.
(_Jv_Linker::create_error_method): Adjust.
* boehm.cc (_Jv_ClosureListFinalizer): New.
* nogc.cc (_Jv_ClosureListFinalizer): New.
* java/lang/Class.h (class _Jv_ClosureList): New.
(class java::lang::Class): Declare it as friend.
* java/lang/natClass.cc (_Jv_ClosureList::releaseClosures): New.
(_Jv_ClosureList::registerClousure): New.
* include/execution.h (_Jv_ExecutionEngine): Add get_closure_list.
(_Jv_CompiledEngine::do_get_closure_list): New.
(_Jv_CompiledEngine::_Jv_CompiledEngine): Use it.
(_Jv_IndirectCompiledClass): Add closures.
(_Jv_IndirectCompiledEngine::get_aux_info): New.
(_Jv_IndirectCompiledEngine::do_allocate_field_initializers): Use
it.
(_Jv_IndirectCompiledEngine::do_get_closure_list): New.
(_Jv_IndirectCompiledEngine::_Jv_IndirectCompiledEngine): Use it.
(_Jv_InterpreterEngine::do_get_closure_list): Declare.
(_Jv_InterpreterEngine::_Jv_InterpreterEngine): Use it.
* interpret.cc (FFI_PREP_RAW_CLOSURE): Use _loc variants.
(node_closure): Add closure list.
(_Jv_InterpMethod::ncode): Add jclass argument. Use
ffi_closure_alloc and the separate code pointer. Register the
closure for finalization.
(_Jv_JNIMethod::ncode): Likewise.
(_Jv_InterpreterEngine::do_create_ncode): Pass klass to ncode.
(_Jv_InterpreterEngine::do_get_closure_list): New.
* include/java-interp.h (_Jv_InterpMethod::ncode): Adjust.
(_Jv_InterpClass): Add closures field.
(_Jv_JNIMethod::ncode): Adjust.
* defineclass.cc (_Jv_ClassReader::handleCodeAttribute): Adjust.
(_Jv_ClassReader::handleMethodsEnd): Likewise.
* link.cc (struct method_closure): Add closure list.
(_Jv_Linker::create_error_method): Add jclass argument. Use
ffi_closure_alloc and the separate code pointer. Register the
closure for finalization.
(_Jv_Linker::link_symbol_table): Remove outdated comment about
sharing of otable and atable. Adjust.
* java/lang/reflect/natVMProxy.cc (ncode_closure): Add closure
list.
(ncode): Add jclass argument. Use ffi_closure_alloc and the
separate code pointer. Register the closure for finalization.
(java::lang::reflect::VMProxy::generateProxyClass): Adjust.
* testsuite/libjava.jar/TestClosureGC.java: New.
* testsuite/libjava.jar/TestClosureGC.out: New.
* testsuite/libjava.jar/TestClosureGC.xfail: New.
* testsuite/libjava.jar/TestClosureGC.jar: New.
From-SVN: r122652
2007-03-07 08:27:25 +01:00
|
|
|
bool use_error_method = false;
|
|
|
|
|
2006-02-01 14:40:05 +01:00
|
|
|
// If the target class is missing we prepare a function call
|
|
|
|
// that throws a NoClassDefFoundError and store the address of
|
2006-06-08 16:00:43 +02:00
|
|
|
// that newly prepared method in the atable. The user can run
|
2006-02-01 14:40:05 +01:00
|
|
|
// code in classes where the missing class is part of the
|
|
|
|
// execution environment as long as it is never referenced.
|
2004-11-25 04:47:08 +01:00
|
|
|
if (target_class == NULL)
|
ffi.h.in (ffi_closure_alloc, [...]): New.
libffi/ChangeLog:
* include/ffi.h.in (ffi_closure_alloc, ffi_closure_free): New.
(ffi_prep_closure_loc): New.
(ffi_prep_raw_closure_loc): New.
(ffi_prep_java_raw_closure_loc): New.
* src/closures.c: New file.
* src/dlmalloc.c [FFI_MMAP_EXEC_WRIT] (struct malloc_segment):
Replace sflags with exec_offset.
[FFI_MMAP_EXEC_WRIT] (mmap_exec_offset, add_segment_exec_offset,
sub_segment_exec_offset): New macros.
(get_segment_flags, set_segment_flags, check_segment_merge): New
macros.
(is_mmapped_segment, is_extern_segment): Use get_segment_flags.
(add_segment, sys_alloc, create_mspace, create_mspace_with_base,
destroy_mspace): Use new macros.
(sys_alloc): Silence warning.
* Makefile.am (libffi_la_SOURCES): Add src/closures.c.
* Makefile.in: Rebuilt.
* src/prep_cif [FFI_CLOSURES] (ffi_prep_closure): Implement in
terms of ffi_prep_closure_loc.
* src/raw_api.c (ffi_prep_raw_closure_loc): Renamed and adjusted
from...
(ffi_prep_raw_closure): ... this. Re-implement in terms of the
renamed version.
* src/java_raw_api (ffi_prep_java_raw_closure_loc): Renamed and
adjusted from...
(ffi_prep_java_raw_closure): ... this. Re-implement in terms of
the renamed version.
* src/alpha/ffi.c (ffi_prep_closure_loc): Renamed from
(ffi_prep_closure): ... this.
* src/pa/ffi.c: Likewise.
* src/cris/ffi.c: Likewise. Adjust.
* src/frv/ffi.c: Likewise.
* src/ia64/ffi.c: Likewise.
* src/mips/ffi.c: Likewise.
* src/powerpc/ffi_darwin.c: Likewise.
* src/s390/ffi.c: Likewise.
* src/sh/ffi.c: Likewise.
* src/sh64/ffi.c: Likewise.
* src/sparc/ffi.c: Likewise.
* src/x86/ffi64.c: Likewise.
* src/x86/ffi.c: Likewise.
(FFI_INIT_TRAMPOLINE): Adjust.
(ffi_prep_raw_closure_loc): Renamed and adjusted from...
(ffi_prep_raw_closure): ... this.
* src/powerpc/ffi.c (ffi_prep_closure_loc): Renamed from
(ffi_prep_closure): ... this.
(flush_icache): Adjust.
boehm-gc/ChangeLog:
* include/gc.h (GC_REGISTER_FINALIZER_UNREACHABLE): New.
(GC_register_finalizer_unreachable): Declare.
(GC_debug_register_finalizer_unreachable): Declare.
* finalize.c (GC_unreachable_finalize_mark_proc): New.
(GC_register_finalizer_unreachable): New.
(GC_finalize): Handle it.
* dbg_mlc.c (GC_debug_register_finalizer_unreachable): New.
(GC_debug_register_finalizer_no_order): Fix whitespace.
libjava/ChangeLog:
* include/jvm.h (_Jv_ClosureListFinalizer): New.
(_Jv_Linker::create_error_method): Adjust.
* boehm.cc (_Jv_ClosureListFinalizer): New.
* nogc.cc (_Jv_ClosureListFinalizer): New.
* java/lang/Class.h (class _Jv_ClosureList): New.
(class java::lang::Class): Declare it as friend.
* java/lang/natClass.cc (_Jv_ClosureList::releaseClosures): New.
(_Jv_ClosureList::registerClousure): New.
* include/execution.h (_Jv_ExecutionEngine): Add get_closure_list.
(_Jv_CompiledEngine::do_get_closure_list): New.
(_Jv_CompiledEngine::_Jv_CompiledEngine): Use it.
(_Jv_IndirectCompiledClass): Add closures.
(_Jv_IndirectCompiledEngine::get_aux_info): New.
(_Jv_IndirectCompiledEngine::do_allocate_field_initializers): Use
it.
(_Jv_IndirectCompiledEngine::do_get_closure_list): New.
(_Jv_IndirectCompiledEngine::_Jv_IndirectCompiledEngine): Use it.
(_Jv_InterpreterEngine::do_get_closure_list): Declare.
(_Jv_InterpreterEngine::_Jv_InterpreterEngine): Use it.
* interpret.cc (FFI_PREP_RAW_CLOSURE): Use _loc variants.
(node_closure): Add closure list.
(_Jv_InterpMethod::ncode): Add jclass argument. Use
ffi_closure_alloc and the separate code pointer. Register the
closure for finalization.
(_Jv_JNIMethod::ncode): Likewise.
(_Jv_InterpreterEngine::do_create_ncode): Pass klass to ncode.
(_Jv_InterpreterEngine::do_get_closure_list): New.
* include/java-interp.h (_Jv_InterpMethod::ncode): Adjust.
(_Jv_InterpClass): Add closures field.
(_Jv_JNIMethod::ncode): Adjust.
* defineclass.cc (_Jv_ClassReader::handleCodeAttribute): Adjust.
(_Jv_ClassReader::handleMethodsEnd): Likewise.
* link.cc (struct method_closure): Add closure list.
(_Jv_Linker::create_error_method): Add jclass argument. Use
ffi_closure_alloc and the separate code pointer. Register the
closure for finalization.
(_Jv_Linker::link_symbol_table): Remove outdated comment about
sharing of otable and atable. Adjust.
* java/lang/reflect/natVMProxy.cc (ncode_closure): Add closure
list.
(ncode): Add jclass argument. Use ffi_closure_alloc and the
separate code pointer. Register the closure for finalization.
(java::lang::reflect::VMProxy::generateProxyClass): Adjust.
* testsuite/libjava.jar/TestClosureGC.java: New.
* testsuite/libjava.jar/TestClosureGC.out: New.
* testsuite/libjava.jar/TestClosureGC.xfail: New.
* testsuite/libjava.jar/TestClosureGC.jar: New.
From-SVN: r122652
2007-03-07 08:27:25 +01:00
|
|
|
use_error_method = true;
|
2004-11-25 04:47:08 +01:00
|
|
|
// We're looking for a static field or a static method, and we
|
|
|
|
// can tell which is needed by looking at the signature.
|
2006-02-01 14:40:05 +01:00
|
|
|
else if (signature->first() == '(' && signature->len() >= 2)
|
2004-11-25 04:47:08 +01:00
|
|
|
{
|
|
|
|
// If the target class does not have a vtable_method_count yet,
|
|
|
|
// then we can't tell the offsets for its methods, so we must lay
|
|
|
|
// it out now.
|
|
|
|
wait_for_state (target_class, JV_STATE_PREPARED);
|
|
|
|
|
|
|
|
// Interface methods cannot have bodies.
|
|
|
|
if (target_class->isInterface())
|
|
|
|
{
|
|
|
|
using namespace java::lang;
|
|
|
|
StringBuffer *sb = new StringBuffer();
|
|
|
|
sb->append(JvNewStringLatin1("class "));
|
|
|
|
sb->append(target_class->getName());
|
|
|
|
sb->append(JvNewStringLatin1(" is an interface: "
|
|
|
|
"class expected"));
|
|
|
|
throw new VerifyError(sb->toString());
|
|
|
|
}
|
|
|
|
|
2006-06-08 16:00:43 +02:00
|
|
|
try
|
|
|
|
{
|
|
|
|
meth = (search_method_in_superclasses
|
|
|
|
(target_class, klass, sym.name, signature,
|
|
|
|
NULL, special == 0));
|
|
|
|
}
|
|
|
|
catch (::java::lang::IllegalAccessError *e)
|
|
|
|
{
|
|
|
|
}
|
2004-11-25 04:47:08 +01:00
|
|
|
|
|
|
|
if (meth != NULL)
|
|
|
|
{
|
|
|
|
if (meth->ncode) // Maybe abstract?
|
|
|
|
{
|
|
|
|
klass->atable->addresses[index] = meth->ncode;
|
|
|
|
if (debug_link)
|
|
|
|
fprintf (stderr, " addresses[%d] = %p (class %s@%p : %s(%s))\n",
|
|
|
|
index,
|
|
|
|
&klass->atable->addresses[index],
|
|
|
|
(const char*)target_class->name->chars(),
|
|
|
|
klass,
|
|
|
|
(const char*)sym.name->chars(),
|
|
|
|
(const char*)signature->chars());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
ffi.h.in (ffi_closure_alloc, [...]): New.
libffi/ChangeLog:
* include/ffi.h.in (ffi_closure_alloc, ffi_closure_free): New.
(ffi_prep_closure_loc): New.
(ffi_prep_raw_closure_loc): New.
(ffi_prep_java_raw_closure_loc): New.
* src/closures.c: New file.
* src/dlmalloc.c [FFI_MMAP_EXEC_WRIT] (struct malloc_segment):
Replace sflags with exec_offset.
[FFI_MMAP_EXEC_WRIT] (mmap_exec_offset, add_segment_exec_offset,
sub_segment_exec_offset): New macros.
(get_segment_flags, set_segment_flags, check_segment_merge): New
macros.
(is_mmapped_segment, is_extern_segment): Use get_segment_flags.
(add_segment, sys_alloc, create_mspace, create_mspace_with_base,
destroy_mspace): Use new macros.
(sys_alloc): Silence warning.
* Makefile.am (libffi_la_SOURCES): Add src/closures.c.
* Makefile.in: Rebuilt.
* src/prep_cif [FFI_CLOSURES] (ffi_prep_closure): Implement in
terms of ffi_prep_closure_loc.
* src/raw_api.c (ffi_prep_raw_closure_loc): Renamed and adjusted
from...
(ffi_prep_raw_closure): ... this. Re-implement in terms of the
renamed version.
* src/java_raw_api (ffi_prep_java_raw_closure_loc): Renamed and
adjusted from...
(ffi_prep_java_raw_closure): ... this. Re-implement in terms of
the renamed version.
* src/alpha/ffi.c (ffi_prep_closure_loc): Renamed from
(ffi_prep_closure): ... this.
* src/pa/ffi.c: Likewise.
* src/cris/ffi.c: Likewise. Adjust.
* src/frv/ffi.c: Likewise.
* src/ia64/ffi.c: Likewise.
* src/mips/ffi.c: Likewise.
* src/powerpc/ffi_darwin.c: Likewise.
* src/s390/ffi.c: Likewise.
* src/sh/ffi.c: Likewise.
* src/sh64/ffi.c: Likewise.
* src/sparc/ffi.c: Likewise.
* src/x86/ffi64.c: Likewise.
* src/x86/ffi.c: Likewise.
(FFI_INIT_TRAMPOLINE): Adjust.
(ffi_prep_raw_closure_loc): Renamed and adjusted from...
(ffi_prep_raw_closure): ... this.
* src/powerpc/ffi.c (ffi_prep_closure_loc): Renamed from
(ffi_prep_closure): ... this.
(flush_icache): Adjust.
boehm-gc/ChangeLog:
* include/gc.h (GC_REGISTER_FINALIZER_UNREACHABLE): New.
(GC_register_finalizer_unreachable): Declare.
(GC_debug_register_finalizer_unreachable): Declare.
* finalize.c (GC_unreachable_finalize_mark_proc): New.
(GC_register_finalizer_unreachable): New.
(GC_finalize): Handle it.
* dbg_mlc.c (GC_debug_register_finalizer_unreachable): New.
(GC_debug_register_finalizer_no_order): Fix whitespace.
libjava/ChangeLog:
* include/jvm.h (_Jv_ClosureListFinalizer): New.
(_Jv_Linker::create_error_method): Adjust.
* boehm.cc (_Jv_ClosureListFinalizer): New.
* nogc.cc (_Jv_ClosureListFinalizer): New.
* java/lang/Class.h (class _Jv_ClosureList): New.
(class java::lang::Class): Declare it as friend.
* java/lang/natClass.cc (_Jv_ClosureList::releaseClosures): New.
(_Jv_ClosureList::registerClousure): New.
* include/execution.h (_Jv_ExecutionEngine): Add get_closure_list.
(_Jv_CompiledEngine::do_get_closure_list): New.
(_Jv_CompiledEngine::_Jv_CompiledEngine): Use it.
(_Jv_IndirectCompiledClass): Add closures.
(_Jv_IndirectCompiledEngine::get_aux_info): New.
(_Jv_IndirectCompiledEngine::do_allocate_field_initializers): Use
it.
(_Jv_IndirectCompiledEngine::do_get_closure_list): New.
(_Jv_IndirectCompiledEngine::_Jv_IndirectCompiledEngine): Use it.
(_Jv_InterpreterEngine::do_get_closure_list): Declare.
(_Jv_InterpreterEngine::_Jv_InterpreterEngine): Use it.
* interpret.cc (FFI_PREP_RAW_CLOSURE): Use _loc variants.
(node_closure): Add closure list.
(_Jv_InterpMethod::ncode): Add jclass argument. Use
ffi_closure_alloc and the separate code pointer. Register the
closure for finalization.
(_Jv_JNIMethod::ncode): Likewise.
(_Jv_InterpreterEngine::do_create_ncode): Pass klass to ncode.
(_Jv_InterpreterEngine::do_get_closure_list): New.
* include/java-interp.h (_Jv_InterpMethod::ncode): Adjust.
(_Jv_InterpClass): Add closures field.
(_Jv_JNIMethod::ncode): Adjust.
* defineclass.cc (_Jv_ClassReader::handleCodeAttribute): Adjust.
(_Jv_ClassReader::handleMethodsEnd): Likewise.
* link.cc (struct method_closure): Add closure list.
(_Jv_Linker::create_error_method): Add jclass argument. Use
ffi_closure_alloc and the separate code pointer. Register the
closure for finalization.
(_Jv_Linker::link_symbol_table): Remove outdated comment about
sharing of otable and atable. Adjust.
* java/lang/reflect/natVMProxy.cc (ncode_closure): Add closure
list.
(ncode): Add jclass argument. Use ffi_closure_alloc and the
separate code pointer. Register the closure for finalization.
(java::lang::reflect::VMProxy::generateProxyClass): Adjust.
* testsuite/libjava.jar/TestClosureGC.java: New.
* testsuite/libjava.jar/TestClosureGC.out: New.
* testsuite/libjava.jar/TestClosureGC.xfail: New.
* testsuite/libjava.jar/TestClosureGC.jar: New.
From-SVN: r122652
2007-03-07 08:27:25 +01:00
|
|
|
use_error_method = true;
|
|
|
|
|
|
|
|
if (use_error_method)
|
2004-11-25 04:47:08 +01:00
|
|
|
klass->atable->addresses[index]
|
ffi.h.in (ffi_closure_alloc, [...]): New.
libffi/ChangeLog:
* include/ffi.h.in (ffi_closure_alloc, ffi_closure_free): New.
(ffi_prep_closure_loc): New.
(ffi_prep_raw_closure_loc): New.
(ffi_prep_java_raw_closure_loc): New.
* src/closures.c: New file.
* src/dlmalloc.c [FFI_MMAP_EXEC_WRIT] (struct malloc_segment):
Replace sflags with exec_offset.
[FFI_MMAP_EXEC_WRIT] (mmap_exec_offset, add_segment_exec_offset,
sub_segment_exec_offset): New macros.
(get_segment_flags, set_segment_flags, check_segment_merge): New
macros.
(is_mmapped_segment, is_extern_segment): Use get_segment_flags.
(add_segment, sys_alloc, create_mspace, create_mspace_with_base,
destroy_mspace): Use new macros.
(sys_alloc): Silence warning.
* Makefile.am (libffi_la_SOURCES): Add src/closures.c.
* Makefile.in: Rebuilt.
* src/prep_cif [FFI_CLOSURES] (ffi_prep_closure): Implement in
terms of ffi_prep_closure_loc.
* src/raw_api.c (ffi_prep_raw_closure_loc): Renamed and adjusted
from...
(ffi_prep_raw_closure): ... this. Re-implement in terms of the
renamed version.
* src/java_raw_api (ffi_prep_java_raw_closure_loc): Renamed and
adjusted from...
(ffi_prep_java_raw_closure): ... this. Re-implement in terms of
the renamed version.
* src/alpha/ffi.c (ffi_prep_closure_loc): Renamed from
(ffi_prep_closure): ... this.
* src/pa/ffi.c: Likewise.
* src/cris/ffi.c: Likewise. Adjust.
* src/frv/ffi.c: Likewise.
* src/ia64/ffi.c: Likewise.
* src/mips/ffi.c: Likewise.
* src/powerpc/ffi_darwin.c: Likewise.
* src/s390/ffi.c: Likewise.
* src/sh/ffi.c: Likewise.
* src/sh64/ffi.c: Likewise.
* src/sparc/ffi.c: Likewise.
* src/x86/ffi64.c: Likewise.
* src/x86/ffi.c: Likewise.
(FFI_INIT_TRAMPOLINE): Adjust.
(ffi_prep_raw_closure_loc): Renamed and adjusted from...
(ffi_prep_raw_closure): ... this.
* src/powerpc/ffi.c (ffi_prep_closure_loc): Renamed from
(ffi_prep_closure): ... this.
(flush_icache): Adjust.
boehm-gc/ChangeLog:
* include/gc.h (GC_REGISTER_FINALIZER_UNREACHABLE): New.
(GC_register_finalizer_unreachable): Declare.
(GC_debug_register_finalizer_unreachable): Declare.
* finalize.c (GC_unreachable_finalize_mark_proc): New.
(GC_register_finalizer_unreachable): New.
(GC_finalize): Handle it.
* dbg_mlc.c (GC_debug_register_finalizer_unreachable): New.
(GC_debug_register_finalizer_no_order): Fix whitespace.
libjava/ChangeLog:
* include/jvm.h (_Jv_ClosureListFinalizer): New.
(_Jv_Linker::create_error_method): Adjust.
* boehm.cc (_Jv_ClosureListFinalizer): New.
* nogc.cc (_Jv_ClosureListFinalizer): New.
* java/lang/Class.h (class _Jv_ClosureList): New.
(class java::lang::Class): Declare it as friend.
* java/lang/natClass.cc (_Jv_ClosureList::releaseClosures): New.
(_Jv_ClosureList::registerClousure): New.
* include/execution.h (_Jv_ExecutionEngine): Add get_closure_list.
(_Jv_CompiledEngine::do_get_closure_list): New.
(_Jv_CompiledEngine::_Jv_CompiledEngine): Use it.
(_Jv_IndirectCompiledClass): Add closures.
(_Jv_IndirectCompiledEngine::get_aux_info): New.
(_Jv_IndirectCompiledEngine::do_allocate_field_initializers): Use
it.
(_Jv_IndirectCompiledEngine::do_get_closure_list): New.
(_Jv_IndirectCompiledEngine::_Jv_IndirectCompiledEngine): Use it.
(_Jv_InterpreterEngine::do_get_closure_list): Declare.
(_Jv_InterpreterEngine::_Jv_InterpreterEngine): Use it.
* interpret.cc (FFI_PREP_RAW_CLOSURE): Use _loc variants.
(node_closure): Add closure list.
(_Jv_InterpMethod::ncode): Add jclass argument. Use
ffi_closure_alloc and the separate code pointer. Register the
closure for finalization.
(_Jv_JNIMethod::ncode): Likewise.
(_Jv_InterpreterEngine::do_create_ncode): Pass klass to ncode.
(_Jv_InterpreterEngine::do_get_closure_list): New.
* include/java-interp.h (_Jv_InterpMethod::ncode): Adjust.
(_Jv_InterpClass): Add closures field.
(_Jv_JNIMethod::ncode): Adjust.
* defineclass.cc (_Jv_ClassReader::handleCodeAttribute): Adjust.
(_Jv_ClassReader::handleMethodsEnd): Likewise.
* link.cc (struct method_closure): Add closure list.
(_Jv_Linker::create_error_method): Add jclass argument. Use
ffi_closure_alloc and the separate code pointer. Register the
closure for finalization.
(_Jv_Linker::link_symbol_table): Remove outdated comment about
sharing of otable and atable. Adjust.
* java/lang/reflect/natVMProxy.cc (ncode_closure): Add closure
list.
(ncode): Add jclass argument. Use ffi_closure_alloc and the
separate code pointer. Register the closure for finalization.
(java::lang::reflect::VMProxy::generateProxyClass): Adjust.
* testsuite/libjava.jar/TestClosureGC.java: New.
* testsuite/libjava.jar/TestClosureGC.out: New.
* testsuite/libjava.jar/TestClosureGC.xfail: New.
* testsuite/libjava.jar/TestClosureGC.jar: New.
From-SVN: r122652
2007-03-07 08:27:25 +01:00
|
|
|
= create_error_method(sym.class_name, klass);
|
2004-11-25 04:47:08 +01:00
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
ffi.h.in (ffi_closure_alloc, [...]): New.
libffi/ChangeLog:
* include/ffi.h.in (ffi_closure_alloc, ffi_closure_free): New.
(ffi_prep_closure_loc): New.
(ffi_prep_raw_closure_loc): New.
(ffi_prep_java_raw_closure_loc): New.
* src/closures.c: New file.
* src/dlmalloc.c [FFI_MMAP_EXEC_WRIT] (struct malloc_segment):
Replace sflags with exec_offset.
[FFI_MMAP_EXEC_WRIT] (mmap_exec_offset, add_segment_exec_offset,
sub_segment_exec_offset): New macros.
(get_segment_flags, set_segment_flags, check_segment_merge): New
macros.
(is_mmapped_segment, is_extern_segment): Use get_segment_flags.
(add_segment, sys_alloc, create_mspace, create_mspace_with_base,
destroy_mspace): Use new macros.
(sys_alloc): Silence warning.
* Makefile.am (libffi_la_SOURCES): Add src/closures.c.
* Makefile.in: Rebuilt.
* src/prep_cif [FFI_CLOSURES] (ffi_prep_closure): Implement in
terms of ffi_prep_closure_loc.
* src/raw_api.c (ffi_prep_raw_closure_loc): Renamed and adjusted
from...
(ffi_prep_raw_closure): ... this. Re-implement in terms of the
renamed version.
* src/java_raw_api (ffi_prep_java_raw_closure_loc): Renamed and
adjusted from...
(ffi_prep_java_raw_closure): ... this. Re-implement in terms of
the renamed version.
* src/alpha/ffi.c (ffi_prep_closure_loc): Renamed from
(ffi_prep_closure): ... this.
* src/pa/ffi.c: Likewise.
* src/cris/ffi.c: Likewise. Adjust.
* src/frv/ffi.c: Likewise.
* src/ia64/ffi.c: Likewise.
* src/mips/ffi.c: Likewise.
* src/powerpc/ffi_darwin.c: Likewise.
* src/s390/ffi.c: Likewise.
* src/sh/ffi.c: Likewise.
* src/sh64/ffi.c: Likewise.
* src/sparc/ffi.c: Likewise.
* src/x86/ffi64.c: Likewise.
* src/x86/ffi.c: Likewise.
(FFI_INIT_TRAMPOLINE): Adjust.
(ffi_prep_raw_closure_loc): Renamed and adjusted from...
(ffi_prep_raw_closure): ... this.
* src/powerpc/ffi.c (ffi_prep_closure_loc): Renamed from
(ffi_prep_closure): ... this.
(flush_icache): Adjust.
boehm-gc/ChangeLog:
* include/gc.h (GC_REGISTER_FINALIZER_UNREACHABLE): New.
(GC_register_finalizer_unreachable): Declare.
(GC_debug_register_finalizer_unreachable): Declare.
* finalize.c (GC_unreachable_finalize_mark_proc): New.
(GC_register_finalizer_unreachable): New.
(GC_finalize): Handle it.
* dbg_mlc.c (GC_debug_register_finalizer_unreachable): New.
(GC_debug_register_finalizer_no_order): Fix whitespace.
libjava/ChangeLog:
* include/jvm.h (_Jv_ClosureListFinalizer): New.
(_Jv_Linker::create_error_method): Adjust.
* boehm.cc (_Jv_ClosureListFinalizer): New.
* nogc.cc (_Jv_ClosureListFinalizer): New.
* java/lang/Class.h (class _Jv_ClosureList): New.
(class java::lang::Class): Declare it as friend.
* java/lang/natClass.cc (_Jv_ClosureList::releaseClosures): New.
(_Jv_ClosureList::registerClousure): New.
* include/execution.h (_Jv_ExecutionEngine): Add get_closure_list.
(_Jv_CompiledEngine::do_get_closure_list): New.
(_Jv_CompiledEngine::_Jv_CompiledEngine): Use it.
(_Jv_IndirectCompiledClass): Add closures.
(_Jv_IndirectCompiledEngine::get_aux_info): New.
(_Jv_IndirectCompiledEngine::do_allocate_field_initializers): Use
it.
(_Jv_IndirectCompiledEngine::do_get_closure_list): New.
(_Jv_IndirectCompiledEngine::_Jv_IndirectCompiledEngine): Use it.
(_Jv_InterpreterEngine::do_get_closure_list): Declare.
(_Jv_InterpreterEngine::_Jv_InterpreterEngine): Use it.
* interpret.cc (FFI_PREP_RAW_CLOSURE): Use _loc variants.
(node_closure): Add closure list.
(_Jv_InterpMethod::ncode): Add jclass argument. Use
ffi_closure_alloc and the separate code pointer. Register the
closure for finalization.
(_Jv_JNIMethod::ncode): Likewise.
(_Jv_InterpreterEngine::do_create_ncode): Pass klass to ncode.
(_Jv_InterpreterEngine::do_get_closure_list): New.
* include/java-interp.h (_Jv_InterpMethod::ncode): Adjust.
(_Jv_InterpClass): Add closures field.
(_Jv_JNIMethod::ncode): Adjust.
* defineclass.cc (_Jv_ClassReader::handleCodeAttribute): Adjust.
(_Jv_ClassReader::handleMethodsEnd): Likewise.
* link.cc (struct method_closure): Add closure list.
(_Jv_Linker::create_error_method): Add jclass argument. Use
ffi_closure_alloc and the separate code pointer. Register the
closure for finalization.
(_Jv_Linker::link_symbol_table): Remove outdated comment about
sharing of otable and atable. Adjust.
* java/lang/reflect/natVMProxy.cc (ncode_closure): Add closure
list.
(ncode): Add jclass argument. Use ffi_closure_alloc and the
separate code pointer. Register the closure for finalization.
(java::lang::reflect::VMProxy::generateProxyClass): Adjust.
* testsuite/libjava.jar/TestClosureGC.java: New.
* testsuite/libjava.jar/TestClosureGC.out: New.
* testsuite/libjava.jar/TestClosureGC.xfail: New.
* testsuite/libjava.jar/TestClosureGC.jar: New.
From-SVN: r122652
2007-03-07 08:27:25 +01:00
|
|
|
|
2006-02-01 14:40:05 +01:00
|
|
|
// Try fields only if the target class exists.
|
2006-02-21 11:32:31 +01:00
|
|
|
if (target_class != NULL)
|
2004-11-25 04:47:08 +01:00
|
|
|
{
|
|
|
|
wait_for_state(target_class, JV_STATE_PREPARED);
|
2005-04-29 20:35:36 +02:00
|
|
|
jclass found_class;
|
|
|
|
_Jv_Field *the_field = find_field (klass, target_class, &found_class,
|
2006-06-08 16:00:43 +02:00
|
|
|
sym.name, signature);
|
2005-01-10 20:21:46 +01:00
|
|
|
if ((the_field->flags & java::lang::reflect::Modifier::STATIC))
|
|
|
|
klass->atable->addresses[index] = the_field->u.addr;
|
2004-11-25 04:47:08 +01:00
|
|
|
else
|
2005-01-10 20:21:46 +01:00
|
|
|
throw new java::lang::IncompatibleClassChangeError;
|
2004-11-25 04:47:08 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
itable:
|
|
|
|
if (klass->itable == NULL
|
|
|
|
|| klass->itable->state != 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
klass->itable->state = 1;
|
|
|
|
|
|
|
|
for (index = 0;
|
|
|
|
(sym = klass->itable_syms[index]).class_name != NULL;
|
|
|
|
++index)
|
|
|
|
{
|
|
|
|
jclass target_class = _Jv_FindClass (sym.class_name, klass->loader);
|
2006-06-08 16:00:43 +02:00
|
|
|
|
2004-11-25 04:47:08 +01:00
|
|
|
_Jv_Utf8Const *signature = sym.signature;
|
2006-06-08 16:00:43 +02:00
|
|
|
uaddr special;
|
|
|
|
maybe_adjust_signature (signature, special);
|
2004-11-25 04:47:08 +01:00
|
|
|
|
|
|
|
jclass cls;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
wait_for_state(target_class, JV_STATE_LOADED);
|
|
|
|
bool found = _Jv_getInterfaceMethod (target_class, cls, i,
|
2006-06-08 16:00:43 +02:00
|
|
|
sym.name, signature);
|
2004-11-25 04:47:08 +01:00
|
|
|
|
|
|
|
if (found)
|
|
|
|
{
|
|
|
|
klass->itable->addresses[index * 2] = cls;
|
2004-11-29 18:06:57 +01:00
|
|
|
klass->itable->addresses[index * 2 + 1] = (void *)(unsigned long) i;
|
2004-11-25 04:47:08 +01:00
|
|
|
if (debug_link)
|
|
|
|
{
|
|
|
|
fprintf (stderr, " interfaces[%d] = %p (interface %s@%p : %s(%s))\n",
|
|
|
|
index,
|
|
|
|
klass->itable->addresses[index * 2],
|
|
|
|
(const char*)cls->name->chars(),
|
|
|
|
cls,
|
|
|
|
(const char*)sym.name->chars(),
|
|
|
|
(const char*)signature->chars());
|
|
|
|
fprintf (stderr, " [%d] = offset %d\n",
|
|
|
|
index + 1,
|
2004-11-29 18:06:57 +01:00
|
|
|
(int)(unsigned long)klass->itable->addresses[index * 2 + 1]);
|
2004-11-25 04:47:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
else
|
|
|
|
throw new java::lang::IncompatibleClassChangeError;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// For each catch_record in the list of caught classes, fill in the
|
|
|
|
// address field.
|
|
|
|
void
|
|
|
|
_Jv_Linker::link_exception_table (jclass self)
|
|
|
|
{
|
|
|
|
struct _Jv_CatchClass *catch_record = self->catch_classes;
|
|
|
|
if (!catch_record || catch_record->classname)
|
|
|
|
return;
|
|
|
|
catch_record++;
|
|
|
|
while (catch_record->classname)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
jclass target_class
|
|
|
|
= _Jv_FindClass (catch_record->classname,
|
|
|
|
self->getClassLoaderInternal ());
|
|
|
|
*catch_record->address = target_class;
|
|
|
|
}
|
|
|
|
catch (::java::lang::Throwable *t)
|
|
|
|
{
|
|
|
|
// FIXME: We need to do something better here.
|
|
|
|
*catch_record->address = 0;
|
|
|
|
}
|
|
|
|
catch_record++;
|
|
|
|
}
|
|
|
|
self->catch_classes->classname = (_Jv_Utf8Const *)-1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set itable method indexes for members of interface IFACE.
|
|
|
|
void
|
|
|
|
_Jv_Linker::layout_interface_methods (jclass iface)
|
|
|
|
{
|
|
|
|
if (! iface->isInterface())
|
|
|
|
return;
|
|
|
|
|
|
|
|
// itable indexes start at 1.
|
|
|
|
// FIXME: Static initalizers currently get a NULL placeholder entry in the
|
|
|
|
// itable so they are also assigned an index here.
|
|
|
|
for (int i = 0; i < iface->method_count; i++)
|
|
|
|
iface->methods[i].index = i + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Prepare virtual method declarations in KLASS, and any superclasses
|
|
|
|
// as required, by determining their vtable index, setting
|
|
|
|
// method->index, and finally setting the class's vtable_method_count.
|
|
|
|
// Must be called with the lock for KLASS held.
|
|
|
|
void
|
|
|
|
_Jv_Linker::layout_vtable_methods (jclass klass)
|
|
|
|
{
|
|
|
|
if (klass->vtable != NULL || klass->isInterface()
|
|
|
|
|| klass->vtable_method_count != -1)
|
|
|
|
return;
|
|
|
|
|
|
|
|
jclass superclass = klass->getSuperclass();
|
|
|
|
|
|
|
|
if (superclass != NULL && superclass->vtable_method_count == -1)
|
|
|
|
{
|
|
|
|
JvSynchronize sync (superclass);
|
|
|
|
layout_vtable_methods (superclass);
|
|
|
|
}
|
|
|
|
|
|
|
|
int index = (superclass == NULL ? 0 : superclass->vtable_method_count);
|
|
|
|
|
|
|
|
for (int i = 0; i < klass->method_count; ++i)
|
|
|
|
{
|
|
|
|
_Jv_Method *meth = &klass->methods[i];
|
|
|
|
_Jv_Method *super_meth = NULL;
|
|
|
|
|
|
|
|
if (! _Jv_isVirtualMethod (meth))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (superclass != NULL)
|
|
|
|
{
|
|
|
|
jclass declarer;
|
|
|
|
super_meth = _Jv_LookupDeclaredMethod (superclass, meth->name,
|
|
|
|
meth->signature, &declarer);
|
|
|
|
// See if this method actually overrides the other method
|
|
|
|
// we've found.
|
|
|
|
if (super_meth)
|
|
|
|
{
|
|
|
|
if (! _Jv_isVirtualMethod (super_meth)
|
|
|
|
|| ! _Jv_CheckAccess (klass, declarer,
|
|
|
|
super_meth->accflags))
|
|
|
|
super_meth = NULL;
|
|
|
|
else if ((super_meth->accflags
|
|
|
|
& java::lang::reflect::Modifier::FINAL) != 0)
|
|
|
|
{
|
|
|
|
using namespace java::lang;
|
|
|
|
StringBuffer *sb = new StringBuffer();
|
|
|
|
sb->append(JvNewStringLatin1("method "));
|
2005-02-17 20:17:08 +01:00
|
|
|
sb->append(_Jv_GetMethodString(klass, meth));
|
2004-11-25 04:47:08 +01:00
|
|
|
sb->append(JvNewStringLatin1(" overrides final method "));
|
2005-02-17 20:17:08 +01:00
|
|
|
sb->append(_Jv_GetMethodString(declarer, super_meth));
|
2004-11-25 04:47:08 +01:00
|
|
|
throw new VerifyError(sb->toString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (super_meth)
|
|
|
|
meth->index = super_meth->index;
|
|
|
|
else
|
|
|
|
meth->index = index++;
|
|
|
|
}
|
|
|
|
|
|
|
|
klass->vtable_method_count = index;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set entries in VTABLE for virtual methods declared in KLASS.
|
|
|
|
void
|
|
|
|
_Jv_Linker::set_vtable_entries (jclass klass, _Jv_VTable *vtable)
|
|
|
|
{
|
|
|
|
for (int i = klass->method_count - 1; i >= 0; i--)
|
|
|
|
{
|
|
|
|
using namespace java::lang::reflect;
|
|
|
|
|
|
|
|
_Jv_Method *meth = &klass->methods[i];
|
|
|
|
if (meth->index == (_Jv_ushort) -1)
|
|
|
|
continue;
|
|
|
|
if ((meth->accflags & Modifier::ABSTRACT))
|
2005-02-19 06:17:14 +01:00
|
|
|
// FIXME: it might be nice to have a libffi trampoline here,
|
|
|
|
// so we could pass in the method name and other information.
|
2005-06-15 21:11:43 +02:00
|
|
|
vtable->set_method(meth->index,
|
|
|
|
(void *) &_Jv_ThrowAbstractMethodError);
|
2004-11-25 04:47:08 +01:00
|
|
|
else
|
|
|
|
vtable->set_method(meth->index, meth->ncode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Allocate and lay out the virtual method table for KLASS. This will
|
|
|
|
// also cause vtables to be generated for any non-abstract
|
|
|
|
// superclasses, and virtual method layout to occur for any abstract
|
|
|
|
// superclasses. Must be called with monitor lock for KLASS held.
|
|
|
|
void
|
|
|
|
_Jv_Linker::make_vtable (jclass klass)
|
|
|
|
{
|
|
|
|
using namespace java::lang::reflect;
|
|
|
|
|
|
|
|
// If the vtable exists, or for interface classes, do nothing. All
|
|
|
|
// other classes, including abstract classes, need a vtable.
|
|
|
|
if (klass->vtable != NULL || klass->isInterface())
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Ensure all the `ncode' entries are set.
|
|
|
|
klass->engine->create_ncode(klass);
|
|
|
|
|
|
|
|
// Class must be laid out before we can create a vtable.
|
|
|
|
if (klass->vtable_method_count == -1)
|
|
|
|
layout_vtable_methods (klass);
|
|
|
|
|
|
|
|
// Allocate the new vtable.
|
|
|
|
_Jv_VTable *vtable = _Jv_VTable::new_vtable (klass->vtable_method_count);
|
|
|
|
klass->vtable = vtable;
|
|
|
|
|
|
|
|
// Copy the vtable of the closest superclass.
|
|
|
|
jclass superclass = klass->superclass;
|
|
|
|
{
|
|
|
|
JvSynchronize sync (superclass);
|
|
|
|
make_vtable (superclass);
|
|
|
|
}
|
|
|
|
for (int i = 0; i < superclass->vtable_method_count; ++i)
|
|
|
|
vtable->set_method (i, superclass->vtable->get_method (i));
|
|
|
|
|
|
|
|
// Set the class pointer and GC descriptor.
|
|
|
|
vtable->clas = klass;
|
|
|
|
vtable->gc_descr = _Jv_BuildGCDescr (klass);
|
|
|
|
|
|
|
|
// For each virtual declared in klass, set new vtable entry or
|
|
|
|
// override an old one.
|
|
|
|
set_vtable_entries (klass, vtable);
|
|
|
|
|
2005-02-19 06:17:14 +01:00
|
|
|
// Note that we don't check for abstract methods here. We used to,
|
|
|
|
// but there is a JVMS clarification that indicates that a check
|
|
|
|
// here would be too eager. And, a simple test case confirms this.
|
2004-11-25 04:47:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Lay out the class, allocating space for static fields and computing
|
|
|
|
// offsets of instance fields. The class lock must be held by the
|
|
|
|
// caller.
|
|
|
|
void
|
|
|
|
_Jv_Linker::ensure_fields_laid_out (jclass klass)
|
|
|
|
{
|
|
|
|
if (klass->size_in_bytes != -1)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Compute the alignment for this type by searching through the
|
|
|
|
// superclasses and finding the maximum required alignment. We
|
|
|
|
// could consider caching this in the Class.
|
|
|
|
int max_align = __alignof__ (java::lang::Object);
|
|
|
|
jclass super = klass->getSuperclass();
|
|
|
|
while (super != NULL)
|
|
|
|
{
|
|
|
|
// Ensure that our super has its super installed before
|
|
|
|
// recursing.
|
|
|
|
wait_for_state(super, JV_STATE_LOADING);
|
|
|
|
ensure_fields_laid_out(super);
|
|
|
|
int num = JvNumInstanceFields (super);
|
|
|
|
_Jv_Field *field = JvGetFirstInstanceField (super);
|
|
|
|
while (num > 0)
|
|
|
|
{
|
|
|
|
int field_align = get_alignment_from_class (field->type);
|
|
|
|
if (field_align > max_align)
|
|
|
|
max_align = field_align;
|
|
|
|
++field;
|
|
|
|
--num;
|
|
|
|
}
|
|
|
|
super = super->getSuperclass();
|
|
|
|
}
|
|
|
|
|
|
|
|
int instance_size;
|
2006-02-08 21:07:29 +01:00
|
|
|
// This is the size of the 'static' non-reference fields.
|
|
|
|
int non_reference_size = 0;
|
|
|
|
// This is the size of the 'static' reference fields. We count
|
|
|
|
// these separately to make it simpler for the GC to scan them.
|
|
|
|
int reference_size = 0;
|
2004-11-25 04:47:08 +01:00
|
|
|
|
|
|
|
// Although java.lang.Object is never interpreted, an interface can
|
|
|
|
// have a null superclass. Note that we have to lay out an
|
|
|
|
// interface because it might have static fields.
|
|
|
|
if (klass->superclass)
|
|
|
|
instance_size = klass->superclass->size();
|
|
|
|
else
|
|
|
|
instance_size = java::lang::Object::class$.size();
|
|
|
|
|
2006-05-10 19:17:20 +02:00
|
|
|
klass->engine->allocate_field_initializers (klass);
|
|
|
|
|
2004-11-25 04:47:08 +01:00
|
|
|
for (int i = 0; i < klass->field_count; i++)
|
|
|
|
{
|
|
|
|
int field_size;
|
|
|
|
int field_align;
|
|
|
|
|
|
|
|
_Jv_Field *field = &klass->fields[i];
|
|
|
|
|
|
|
|
if (! field->isRef ())
|
|
|
|
{
|
|
|
|
// It is safe to resolve the field here, since it's a
|
|
|
|
// primitive class, which does not cause loading to happen.
|
|
|
|
resolve_field (field, klass->loader);
|
|
|
|
field_size = field->type->size ();
|
|
|
|
field_align = get_alignment_from_class (field->type);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
field_size = sizeof (jobject);
|
|
|
|
field_align = __alignof__ (jobject);
|
|
|
|
}
|
|
|
|
|
|
|
|
field->bsize = field_size;
|
|
|
|
|
|
|
|
if ((field->flags & java::lang::reflect::Modifier::STATIC))
|
|
|
|
{
|
|
|
|
if (field->u.addr == NULL)
|
|
|
|
{
|
|
|
|
// This computes an offset into a region we'll allocate
|
2006-02-08 21:07:29 +01:00
|
|
|
// shortly, and then adds this offset to the start
|
2004-11-25 04:47:08 +01:00
|
|
|
// address.
|
2006-02-08 21:07:29 +01:00
|
|
|
if (field->isRef())
|
|
|
|
{
|
|
|
|
reference_size = ROUND (reference_size, field_align);
|
|
|
|
field->u.boffset = reference_size;
|
|
|
|
reference_size += field_size;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
non_reference_size = ROUND (non_reference_size, field_align);
|
|
|
|
field->u.boffset = non_reference_size;
|
|
|
|
non_reference_size += field_size;
|
|
|
|
}
|
2004-11-25 04:47:08 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
instance_size = ROUND (instance_size, field_align);
|
|
|
|
field->u.boffset = instance_size;
|
|
|
|
instance_size += field_size;
|
|
|
|
if (field_align > max_align)
|
|
|
|
max_align = field_align;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-02-08 21:07:29 +01:00
|
|
|
if (reference_size != 0 || non_reference_size != 0)
|
|
|
|
klass->engine->allocate_static_fields (klass, reference_size,
|
|
|
|
non_reference_size);
|
2004-11-25 04:47:08 +01:00
|
|
|
|
|
|
|
// Set the instance size for the class. Note that first we round it
|
|
|
|
// to the alignment required for this object; this keeps us in sync
|
|
|
|
// with our current ABI.
|
|
|
|
instance_size = ROUND (instance_size, max_align);
|
|
|
|
klass->size_in_bytes = instance_size;
|
|
|
|
}
|
|
|
|
|
|
|
|
// This takes the class to state JV_STATE_LINKED. The class lock must
|
|
|
|
// be held when calling this.
|
|
|
|
void
|
|
|
|
_Jv_Linker::ensure_class_linked (jclass klass)
|
|
|
|
{
|
|
|
|
if (klass->state >= JV_STATE_LINKED)
|
|
|
|
return;
|
|
|
|
|
|
|
|
int state = klass->state;
|
|
|
|
try
|
|
|
|
{
|
|
|
|
// Short-circuit, so that mutually dependent classes are ok.
|
|
|
|
klass->state = JV_STATE_LINKED;
|
|
|
|
|
|
|
|
_Jv_Constants *pool = &klass->constants;
|
|
|
|
|
|
|
|
// Compiled classes require that their class constants be
|
|
|
|
// resolved here. However, interpreted classes need their
|
|
|
|
// constants to be resolved lazily. If we resolve an
|
|
|
|
// interpreted class' constants eagerly, we can end up with
|
|
|
|
// spurious IllegalAccessErrors when the constant pool contains
|
|
|
|
// a reference to a class we can't access. This can validly
|
|
|
|
// occur in an obscure case involving the InnerClasses
|
|
|
|
// attribute.
|
|
|
|
if (! _Jv_IsInterpretedClass (klass))
|
|
|
|
{
|
|
|
|
// Resolve class constants first, since other constant pool
|
|
|
|
// entries may rely on these.
|
|
|
|
for (int index = 1; index < pool->size; ++index)
|
|
|
|
{
|
|
|
|
if (pool->tags[index] == JV_CONSTANT_Class)
|
2006-02-01 14:40:05 +01:00
|
|
|
// Lazily resolve the entries.
|
|
|
|
resolve_pool_entry (klass, index, true);
|
2004-11-25 04:47:08 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Resolve the remaining constant pool entries.
|
|
|
|
for (int index = 1; index < pool->size; ++index)
|
|
|
|
{
|
|
|
|
if (pool->tags[index] == JV_CONSTANT_String)
|
|
|
|
{
|
|
|
|
jstring str;
|
|
|
|
|
|
|
|
str = _Jv_NewStringUtf8Const (pool->data[index].utf8);
|
|
|
|
pool->data[index].o = str;
|
|
|
|
pool->tags[index] |= JV_CONSTANT_ResolvedFlag;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (klass->engine->need_resolve_string_fields())
|
|
|
|
{
|
|
|
|
jfieldID f = JvGetFirstStaticField (klass);
|
|
|
|
for (int n = JvNumStaticFields (klass); n > 0; --n)
|
|
|
|
{
|
|
|
|
int mod = f->getModifiers ();
|
|
|
|
// If we have a static String field with a non-null initial
|
|
|
|
// value, we know it points to a Utf8Const.
|
2006-02-01 14:40:05 +01:00
|
|
|
|
|
|
|
// Finds out whether we have to initialize a String without the
|
|
|
|
// need to resolve the field.
|
|
|
|
if ((f->isResolved()
|
|
|
|
? (f->type == &java::lang::String::class$)
|
|
|
|
: _Jv_equalUtf8Classnames((_Jv_Utf8Const *) f->type,
|
|
|
|
java::lang::String::class$.name))
|
2004-11-25 04:47:08 +01:00
|
|
|
&& (mod & java::lang::reflect::Modifier::STATIC) != 0)
|
|
|
|
{
|
|
|
|
jstring *strp = (jstring *) f->u.addr;
|
|
|
|
if (*strp)
|
|
|
|
*strp = _Jv_NewStringUtf8Const ((_Jv_Utf8Const *) *strp);
|
|
|
|
}
|
|
|
|
f = f->getNextField ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
klass->notifyAll ();
|
|
|
|
|
|
|
|
_Jv_PushClass (klass);
|
|
|
|
}
|
|
|
|
catch (java::lang::Throwable *t)
|
|
|
|
{
|
|
|
|
klass->state = state;
|
|
|
|
throw t;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// This ensures that symbolic superclass and superinterface references
|
|
|
|
// are resolved for the indicated class. This must be called with the
|
|
|
|
// class lock held.
|
|
|
|
void
|
|
|
|
_Jv_Linker::ensure_supers_installed (jclass klass)
|
|
|
|
{
|
|
|
|
resolve_class_ref (klass, &klass->superclass);
|
|
|
|
// An interface won't have a superclass.
|
|
|
|
if (klass->superclass)
|
|
|
|
wait_for_state (klass->superclass, JV_STATE_LOADING);
|
|
|
|
|
|
|
|
for (int i = 0; i < klass->interface_count; ++i)
|
|
|
|
{
|
|
|
|
resolve_class_ref (klass, &klass->interfaces[i]);
|
|
|
|
wait_for_state (klass->interfaces[i], JV_STATE_LOADING);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// This adds missing `Miranda methods' to a class.
|
|
|
|
void
|
|
|
|
_Jv_Linker::add_miranda_methods (jclass base, jclass iface_class)
|
|
|
|
{
|
|
|
|
// Note that at this point, all our supers, and the supers of all
|
|
|
|
// our superclasses and superinterfaces, will have been installed.
|
|
|
|
|
|
|
|
for (int i = 0; i < iface_class->interface_count; ++i)
|
|
|
|
{
|
|
|
|
jclass interface = iface_class->interfaces[i];
|
|
|
|
|
|
|
|
for (int j = 0; j < interface->method_count; ++j)
|
|
|
|
{
|
|
|
|
_Jv_Method *meth = &interface->methods[j];
|
|
|
|
// Don't bother with <clinit>.
|
|
|
|
if (meth->name->first() == '<')
|
|
|
|
continue;
|
|
|
|
_Jv_Method *new_meth = _Jv_LookupDeclaredMethod (base, meth->name,
|
|
|
|
meth->signature);
|
|
|
|
if (! new_meth)
|
|
|
|
{
|
|
|
|
// We assume that such methods are very unlikely, so we
|
|
|
|
// just reallocate the method array each time one is
|
|
|
|
// found. This greatly simplifies the searching --
|
|
|
|
// otherwise we have to make sure that each such method
|
|
|
|
// found is really unique among all superinterfaces.
|
|
|
|
int new_count = base->method_count + 1;
|
|
|
|
_Jv_Method *new_m
|
2006-02-08 21:07:29 +01:00
|
|
|
= (_Jv_Method *) _Jv_AllocRawObj (sizeof (_Jv_Method)
|
|
|
|
* new_count);
|
2004-11-25 04:47:08 +01:00
|
|
|
memcpy (new_m, base->methods,
|
|
|
|
sizeof (_Jv_Method) * base->method_count);
|
|
|
|
|
|
|
|
// Add new method.
|
|
|
|
new_m[base->method_count] = *meth;
|
|
|
|
new_m[base->method_count].index = (_Jv_ushort) -1;
|
|
|
|
new_m[base->method_count].accflags
|
|
|
|
|= java::lang::reflect::Modifier::INVISIBLE;
|
|
|
|
|
|
|
|
base->methods = new_m;
|
|
|
|
base->method_count = new_count;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
wait_for_state (interface, JV_STATE_LOADED);
|
|
|
|
add_miranda_methods (base, interface);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// This ensures that the class' method table is "complete". This must
|
|
|
|
// be called with the class lock held.
|
|
|
|
void
|
|
|
|
_Jv_Linker::ensure_method_table_complete (jclass klass)
|
|
|
|
{
|
2005-10-13 19:36:07 +02:00
|
|
|
if (klass->vtable != NULL)
|
2004-11-25 04:47:08 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
// We need our superclass to have its own Miranda methods installed.
|
2005-10-13 19:36:07 +02:00
|
|
|
if (! klass->isInterface())
|
|
|
|
wait_for_state (klass->getSuperclass (), JV_STATE_LOADED);
|
2004-11-25 04:47:08 +01:00
|
|
|
|
|
|
|
// A class might have so-called "Miranda methods". This is a method
|
|
|
|
// that is declared in an interface and not re-declared in an
|
|
|
|
// abstract class. Some compilers don't emit declarations for such
|
|
|
|
// methods in the class; this will give us problems since we expect
|
|
|
|
// a declaration for any method requiring a vtable entry. We handle
|
|
|
|
// this here by searching for such methods and constructing new
|
|
|
|
// internal declarations for them. Note that we do this
|
|
|
|
// unconditionally, and not just for abstract classes, to correctly
|
|
|
|
// account for cases where a class is modified to be concrete and
|
|
|
|
// still incorrectly inherits an abstract method.
|
|
|
|
int pre_count = klass->method_count;
|
|
|
|
add_miranda_methods (klass, klass);
|
|
|
|
|
|
|
|
// Let the execution engine know that we've added methods.
|
|
|
|
if (klass->method_count != pre_count)
|
|
|
|
klass->engine->post_miranda_hook(klass);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Verify a class. Must be called with class lock held.
|
|
|
|
void
|
|
|
|
_Jv_Linker::verify_class (jclass klass)
|
|
|
|
{
|
|
|
|
klass->engine->verify(klass);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check the assertions contained in the type assertion table for KLASS.
|
|
|
|
// This is the equivilent of bytecode verification for native, BC-ABI code.
|
|
|
|
void
|
|
|
|
_Jv_Linker::verify_type_assertions (jclass klass)
|
|
|
|
{
|
|
|
|
if (debug_link)
|
|
|
|
fprintf (stderr, "Evaluating type assertions for %s:\n",
|
|
|
|
klass->name->chars());
|
|
|
|
|
|
|
|
if (klass->assertion_table == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (int i = 0;; i++)
|
|
|
|
{
|
|
|
|
int assertion_code = klass->assertion_table[i].assertion_code;
|
|
|
|
_Jv_Utf8Const *op1 = klass->assertion_table[i].op1;
|
|
|
|
_Jv_Utf8Const *op2 = klass->assertion_table[i].op2;
|
|
|
|
|
|
|
|
if (assertion_code == JV_ASSERT_END_OF_TABLE)
|
|
|
|
return;
|
|
|
|
else if (assertion_code == JV_ASSERT_TYPES_COMPATIBLE)
|
|
|
|
{
|
|
|
|
if (debug_link)
|
|
|
|
{
|
|
|
|
fprintf (stderr, " code=%i, operand A=%s B=%s\n",
|
|
|
|
assertion_code, op1->chars(), op2->chars());
|
|
|
|
}
|
|
|
|
|
|
|
|
// The operands are class signatures. op1 is the source,
|
|
|
|
// op2 is the target.
|
|
|
|
jclass cl1 = _Jv_FindClassFromSignature (op1->chars(),
|
|
|
|
klass->getClassLoaderInternal());
|
|
|
|
jclass cl2 = _Jv_FindClassFromSignature (op2->chars(),
|
|
|
|
klass->getClassLoaderInternal());
|
|
|
|
|
|
|
|
// If the class doesn't exist, ignore the assertion. An exception
|
|
|
|
// will be thrown later if an attempt is made to actually
|
|
|
|
// instantiate the class.
|
|
|
|
if (cl1 == NULL || cl2 == NULL)
|
|
|
|
continue;
|
|
|
|
|
2005-09-06 18:01:31 +02:00
|
|
|
if (! _Jv_IsAssignableFromSlow (cl1, cl2))
|
2004-11-25 04:47:08 +01:00
|
|
|
{
|
|
|
|
jstring s = JvNewStringUTF ("Incompatible types: In class ");
|
|
|
|
s = s->concat (klass->getName());
|
|
|
|
s = s->concat (JvNewStringUTF (": "));
|
|
|
|
s = s->concat (cl1->getName());
|
|
|
|
s = s->concat (JvNewStringUTF (" is not assignable to "));
|
|
|
|
s = s->concat (cl2->getName());
|
|
|
|
throw new java::lang::VerifyError (s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (assertion_code == JV_ASSERT_IS_INSTANTIABLE)
|
|
|
|
{
|
|
|
|
// TODO: Implement this.
|
|
|
|
}
|
|
|
|
// Unknown assertion codes are ignored, for forwards-compatibility.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_Jv_Linker::print_class_loaded (jclass klass)
|
|
|
|
{
|
|
|
|
char *codesource = NULL;
|
|
|
|
if (klass->protectionDomain != NULL)
|
|
|
|
{
|
|
|
|
java::security::CodeSource *cs
|
|
|
|
= klass->protectionDomain->getCodeSource();
|
|
|
|
if (cs != NULL)
|
|
|
|
{
|
|
|
|
jstring css = cs->toString();
|
|
|
|
int len = JvGetStringUTFLength(css);
|
|
|
|
codesource = (char *) _Jv_AllocBytes(len + 1);
|
|
|
|
JvGetStringUTFRegion(css, 0, css->length(), codesource);
|
|
|
|
codesource[len] = '\0';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (codesource == NULL)
|
link.cc (_Jv_Linker::print_class_loaded): Declare string constants as "const char *".
2006-02-08 Bryce McKinlay <mckinlay@redhat.com>
* link.cc (_Jv_Linker::print_class_loaded): Declare string constants
as "const char *".
* verify.cc (verify_fail): Likewise.
* gnu/classpath/natSystemProperties.cc (file_encoding): Likewise.
* interpret.cc (throw_internal_error, throw_class_format_error):
Likewise.
* gcj/javaprims.h (_Jv_hashUtf8String, _Jv_Utf8Const::space_needed,
_Jv_Utf8Const::init, _Jv_makeUtf8Const): Likewise.
* java/lang/Class.h (_Jv_InitPrimClass): Likewise.
* include/jvm.h (_Jv_strLengthUtf8, _Jv_makeUtf8Const): Likewise.
* defineclass.cc (throw_internal_error, throw_no_class_def_found_error,
is_attribute_name): Likewise.
* prims.cc (_Jv_strLengthUtf8, _Jv_hashUtf8String, _Jv_Utf8Const::init,
_Jv_makeUtf8Const, _Jv_InitPrimClass): Likewise.
From-SVN: r110767
2006-02-08 21:38:13 +01:00
|
|
|
codesource = (char *) "<no code source>";
|
2004-11-25 04:47:08 +01:00
|
|
|
|
link.cc (_Jv_Linker::print_class_loaded): Declare string constants as "const char *".
2006-02-08 Bryce McKinlay <mckinlay@redhat.com>
* link.cc (_Jv_Linker::print_class_loaded): Declare string constants
as "const char *".
* verify.cc (verify_fail): Likewise.
* gnu/classpath/natSystemProperties.cc (file_encoding): Likewise.
* interpret.cc (throw_internal_error, throw_class_format_error):
Likewise.
* gcj/javaprims.h (_Jv_hashUtf8String, _Jv_Utf8Const::space_needed,
_Jv_Utf8Const::init, _Jv_makeUtf8Const): Likewise.
* java/lang/Class.h (_Jv_InitPrimClass): Likewise.
* include/jvm.h (_Jv_strLengthUtf8, _Jv_makeUtf8Const): Likewise.
* defineclass.cc (throw_internal_error, throw_no_class_def_found_error,
is_attribute_name): Likewise.
* prims.cc (_Jv_strLengthUtf8, _Jv_hashUtf8String, _Jv_Utf8Const::init,
_Jv_makeUtf8Const, _Jv_InitPrimClass): Likewise.
From-SVN: r110767
2006-02-08 21:38:13 +01:00
|
|
|
const char *abi;
|
2004-11-25 04:47:08 +01:00
|
|
|
if (_Jv_IsInterpretedClass (klass))
|
|
|
|
abi = "bytecode";
|
2005-08-17 22:44:10 +02:00
|
|
|
else if (_Jv_IsBinaryCompatibilityABI (klass))
|
2004-11-25 04:47:08 +01:00
|
|
|
abi = "BC-compiled";
|
|
|
|
else
|
|
|
|
abi = "pre-compiled";
|
|
|
|
|
|
|
|
fprintf (stderr, "[Loaded (%s) %s from %s]\n", abi, klass->name->chars(),
|
|
|
|
codesource);
|
|
|
|
}
|
|
|
|
|
|
|
|
// FIXME: mention invariants and stuff.
|
|
|
|
void
|
|
|
|
_Jv_Linker::wait_for_state (jclass klass, int state)
|
|
|
|
{
|
|
|
|
if (klass->state >= state)
|
|
|
|
return;
|
|
|
|
|
|
|
|
java::lang::Thread *self = java::lang::Thread::currentThread();
|
|
|
|
|
2007-01-25 02:21:27 +01:00
|
|
|
{
|
|
|
|
JvSynchronize sync (klass);
|
2004-11-25 04:47:08 +01:00
|
|
|
|
2007-01-25 02:21:27 +01:00
|
|
|
// This is similar to the strategy for class initialization. If we
|
|
|
|
// already hold the lock, just leave.
|
|
|
|
while (klass->state <= state
|
|
|
|
&& klass->thread
|
|
|
|
&& klass->thread != self)
|
|
|
|
klass->wait ();
|
|
|
|
|
|
|
|
java::lang::Thread *save = klass->thread;
|
|
|
|
klass->thread = self;
|
|
|
|
|
|
|
|
// Allocate memory for static fields and constants.
|
|
|
|
if (GC_base (klass) && klass->fields && ! GC_base (klass->fields))
|
|
|
|
{
|
|
|
|
jsize count = klass->field_count;
|
|
|
|
if (count)
|
|
|
|
{
|
|
|
|
_Jv_Field* fields
|
|
|
|
= (_Jv_Field*) _Jv_AllocRawObj (count * sizeof (_Jv_Field));
|
|
|
|
memcpy ((void*)fields,
|
|
|
|
(void*)klass->fields,
|
|
|
|
count * sizeof (_Jv_Field));
|
|
|
|
klass->fields = fields;
|
|
|
|
}
|
|
|
|
}
|
2006-04-24 17:33:16 +02:00
|
|
|
|
2004-11-25 04:47:08 +01:00
|
|
|
// Print some debugging info if requested. Interpreted classes are
|
|
|
|
// handled in defineclass, so we only need to handle the two
|
|
|
|
// pre-compiled cases here.
|
2007-01-09 20:58:05 +01:00
|
|
|
if ((klass->state == JV_STATE_COMPILED
|
2004-11-25 04:47:08 +01:00
|
|
|
|| klass->state == JV_STATE_PRELOADING)
|
2005-03-17 01:18:50 +01:00
|
|
|
&& ! _Jv_IsInterpretedClass (klass))
|
2007-01-09 20:58:05 +01:00
|
|
|
{
|
|
|
|
if (gcj::verbose_class_flag)
|
|
|
|
print_class_loaded (klass);
|
|
|
|
++gcj::loadedClasses;
|
|
|
|
}
|
2004-11-25 04:47:08 +01:00
|
|
|
|
2007-01-25 02:21:27 +01:00
|
|
|
try
|
|
|
|
{
|
|
|
|
if (state >= JV_STATE_LOADING && klass->state < JV_STATE_LOADING)
|
|
|
|
{
|
|
|
|
ensure_supers_installed (klass);
|
|
|
|
klass->set_state(JV_STATE_LOADING);
|
|
|
|
}
|
2004-11-25 04:47:08 +01:00
|
|
|
|
2007-01-25 02:21:27 +01:00
|
|
|
if (state >= JV_STATE_LOADED && klass->state < JV_STATE_LOADED)
|
|
|
|
{
|
|
|
|
ensure_method_table_complete (klass);
|
|
|
|
klass->set_state(JV_STATE_LOADED);
|
|
|
|
}
|
2004-11-25 04:47:08 +01:00
|
|
|
|
2007-01-25 02:21:27 +01:00
|
|
|
if (state >= JV_STATE_PREPARED && klass->state < JV_STATE_PREPARED)
|
|
|
|
{
|
|
|
|
ensure_fields_laid_out (klass);
|
|
|
|
make_vtable (klass);
|
|
|
|
layout_interface_methods (klass);
|
|
|
|
prepare_constant_time_tables (klass);
|
|
|
|
klass->set_state(JV_STATE_PREPARED);
|
|
|
|
}
|
2004-11-25 04:47:08 +01:00
|
|
|
|
2007-01-25 02:21:27 +01:00
|
|
|
if (state >= JV_STATE_LINKED && klass->state < JV_STATE_LINKED)
|
|
|
|
{
|
|
|
|
if (gcj::verifyClasses)
|
|
|
|
verify_class (klass);
|
2004-11-25 04:47:08 +01:00
|
|
|
|
2007-01-25 02:21:27 +01:00
|
|
|
ensure_class_linked (klass);
|
|
|
|
link_exception_table (klass);
|
|
|
|
link_symbol_table (klass);
|
|
|
|
klass->set_state(JV_STATE_LINKED);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (java::lang::Throwable *exc)
|
|
|
|
{
|
|
|
|
klass->thread = save;
|
|
|
|
klass->set_state(JV_STATE_ERROR);
|
|
|
|
throw exc;
|
|
|
|
}
|
|
|
|
|
|
|
|
klass->thread = save;
|
2004-11-25 04:47:08 +01:00
|
|
|
|
2007-01-25 02:21:27 +01:00
|
|
|
if (klass->state == JV_STATE_ERROR)
|
|
|
|
throw new java::lang::LinkageError;
|
|
|
|
}
|
2004-11-25 04:47:08 +01:00
|
|
|
|
2007-01-25 02:21:27 +01:00
|
|
|
if (__builtin_expect (klass->state == JV_STATE_LINKED, false)
|
|
|
|
&& state >= JV_STATE_LINKED
|
|
|
|
&& JVMTI_REQUESTED_EVENT (ClassPrepare))
|
|
|
|
{
|
|
|
|
JNIEnv *jni_env = _Jv_GetCurrentJNIEnv ();
|
|
|
|
_Jv_JVMTI_PostEvent (JVMTI_EVENT_CLASS_PREPARE, self, jni_env,
|
|
|
|
klass);
|
|
|
|
}
|
2004-11-25 04:47:08 +01:00
|
|
|
}
|