Commit ddf0fc6c by Bryce McKinlay Committed by Bryce McKinlay

resolve.cc (_Jv_SearchMethodInClass): New function.

2000-03-07  Bryce McKinlay  <bryce@albatross.co.nz>

        * resolve.cc (_Jv_SearchMethodInClass): New function.
        (_Jv_ResolvePoolEntry): Search superinterfaces for interface
        methods.
        * java/lang/Class.h (_Jv_SearchMethodInClass): New prototype.

2000-03-07  Bryce McKinlay  <bryce@albatross.co.nz>

        * java/lang/Class.h (union _Jv_IDispatchTable): New declaration.
        (struct _Jv_ifaces): New declaration.
        JV_CLASS: New macro definition.
        (getComponentType): Relocate below isArray() for inlining.
        (getModifiers): Declare `inline'.
        (getSuperclass): Ditto.
        (isArray): Ditto.
        (isPrimitive): Ditto.
        (_Jv_IsAssignableFrom): New prototype.
        (_Jv_LookupInterfaceMethodIdx): New prototype. Predeclare with "C"
        linkage.
        (_Jv_InitClass): Move from natClass.cc. Declare `inline'.
        Check for JV_STATE_DONE before invoking initializeClass().
        (_Jv_PrepareConstantTimeTables): New prototype.
        (_Jv_GetInterfaces): Ditto.
        (_Jv_GenerateITable): Ditto.
        (_Jv_GetMethodString): Ditto.
        (_Jv_AppendPartialITable): Ditto.
        (_Jv_FindIIndex): Ditto.
        depth, ancestors, idt: New class fields.

        * java/lang/natClass.cc (isAssignableFrom): Move functionality to
        inline function `_Jv_IsAssignableFrom'. Use that function.
        (isInstance): Declare `inline'.
        (initializeClass): Get lock on class before checking `state'. Unlock
        before calling resolveClass0. Call _Jv_PrepareConstantTimeTables
	with the lock held.
        (_Jv_LookupInterfaceMethod): Use _Jv_GetMessageString.
        (_Jv_IsAssignableFrom): New inline function. Test assignability
	using class->depth and ancestor table.
        (_Jv_IsInstanceOf): Use _Jv_IsAssignableFrom.
        (_Jv_CheckCast): Move from prims.cc. Use JV_CLASS and
        _Jv_IsAssignableFrom.
        (_Jv_CheckArrayStore): Ditto.
        (_Jv_LookupInterfaceMethodIdx): New function.
        INITIAL_IOFFSETS_LEN, INITIAL_IFACES_LEN: New #defines.
        (_Jv_PrepareConstantTimeTables): New function.
        (_Jv_IndexOf): Ditto.
        (_Jv_GetInterfaces): Ditto.
        (_Jv_GenerateITable): Ditto.
        (_Jv_GetMethodString): Ditto.
        (_Jv_AppendPartialITable): Ditto.
        iindex_mutex, iindex_mutex_initialized: New static fields.
        (_Jv_FindIIndex): New function.

        * java/lang/natClassLoader.cc (_Jv_NewClass): Set new jclass fields.

        * prims.cc (_Jv_CheckCast): Moved to natClass.cc.
        (_Jv_CheckArrayStore): Ditto.
        (JvNewCharArray, JvNewBooleanArray, JvNewByteArray, JvNewShortArray,
        JvNewIntArray, JvNewLongArray, JvNewFloatArray, JvNewDoubleArray):
        Moved to gcj/array.h.
        (_Jv_Realloc): New function.

        * gcj/cni.h: Move _Jv_PrimClass definitions to gcj/array.h.

        * gcj/array.h: _Jv_PrimClass definitions moved from gcj/cni.h.
        (JvNewCharArray, JvNewBooleanArray, JvNewByteArray,
        JvNewShortArray, JvNewIntArray, JvNewLongArray, JvNewFloatArray,
        JvNewDoubleArray): Implementations moved from prims.cc and
        declared `inline'.

        * gcj/javaprims.h (_Jv_Realloc): Prototype.

        * include/jvm.h (_Jv_LookupInterfaceMethodIdx): Prototype.

From-SVN: r32382
parent 173f556c
2000-03-07 Bryce McKinlay <bryce@albatross.co.nz>
* resolve.cc (_Jv_SearchMethodInClass): New function.
(_Jv_ResolvePoolEntry): Search superinterfaces for interface methods.
* java/lang/Class.h (_Jv_SearchMethodInClass): New prototype.
2000-03-07 Bryce McKinlay <bryce@albatross.co.nz>
* java/lang/Class.h (union _Jv_IDispatchTable): New declaration.
(struct _Jv_ifaces): New declaration.
JV_CLASS: New macro definition.
(getComponentType): Relocate below isArray() for inlining.
(getModifiers): Declare `inline'.
(getSuperclass): Ditto.
(isArray): Ditto.
(isPrimitive): Ditto.
(_Jv_IsAssignableFrom): New prototype.
(_Jv_LookupInterfaceMethodIdx): New prototype. Predeclare with "C"
linkage.
(_Jv_InitClass): Move from natClass.cc. Declare `inline'.
Check for JV_STATE_DONE before invoking initializeClass().
(_Jv_PrepareConstantTimeTables): New prototype.
(_Jv_GetInterfaces): Ditto.
(_Jv_GenerateITable): Ditto.
(_Jv_GetMethodString): Ditto.
(_Jv_AppendPartialITable): Ditto.
(_Jv_FindIIndex): Ditto.
depth, ancestors, idt: New class fields.
* java/lang/natClass.cc (isAssignableFrom): Move functionality to
inline function `_Jv_IsAssignableFrom'. Use that function.
(isInstance): Declare `inline'.
(initializeClass): Get lock on class before checking `state'. Unlock
before calling resolveClass0. Call _Jv_PrepareConstantTimeTables with
the lock held.
(_Jv_LookupInterfaceMethod): Use _Jv_GetMessageString.
(_Jv_IsAssignableFrom): New inline function. Test assignability using
class->depth and ancestor table.
(_Jv_IsInstanceOf): Use _Jv_IsAssignableFrom.
(_Jv_CheckCast): Move from prims.cc. Use JV_CLASS and
_Jv_IsAssignableFrom.
(_Jv_CheckArrayStore): Ditto.
(_Jv_LookupInterfaceMethodIdx): New function.
INITIAL_IOFFSETS_LEN, INITIAL_IFACES_LEN: New #defines.
(_Jv_PrepareConstantTimeTables): New function.
(_Jv_IndexOf): Ditto.
(_Jv_GetInterfaces): Ditto.
(_Jv_GenerateITable): Ditto.
(_Jv_GetMethodString): Ditto.
(_Jv_AppendPartialITable): Ditto.
iindex_mutex, iindex_mutex_initialized: New static fields.
(_Jv_FindIIndex): New function.
* java/lang/natClassLoader.cc (_Jv_NewClass): Set new jclass fields.
* prims.cc (_Jv_CheckCast): Moved to natClass.cc.
(_Jv_CheckArrayStore): Ditto.
(JvNewCharArray, JvNewBooleanArray, JvNewByteArray, JvNewShortArray,
JvNewIntArray, JvNewLongArray, JvNewFloatArray, JvNewDoubleArray):
Moved to gcj/array.h.
(_Jv_Realloc): New function.
* gcj/cni.h: Move _Jv_PrimClass definitions to gcj/array.h.
* gcj/array.h: _Jv_PrimClass definitions moved from gcj/cni.h.
(JvNewCharArray, JvNewBooleanArray, JvNewByteArray,
JvNewShortArray, JvNewIntArray, JvNewLongArray, JvNewFloatArray,
JvNewDoubleArray): Implementations moved from prims.cc and
declared `inline'.
* gcj/javaprims.h (_Jv_Realloc): Prototype.
* include/jvm.h (_Jv_LookupInterfaceMethodIdx): Prototype.
2000-03-06 Tom Tromey <tromey@cygnus.com>
* jni.cc (MARK_NONE): New define.
......
......@@ -55,18 +55,68 @@ typedef JArray<jfloat> *jfloatArray;
typedef JArray<jdouble> *jdoubleArray;
typedef JArray<jstring> *jstringArray;
extern "C" jbooleanArray JvNewBooleanArray (jint length);
extern "C" jbyteArray JvNewByteArray (jint length);
extern "C" jcharArray JvNewCharArray (jint length);
extern "C" jshortArray JvNewShortArray (jint length);
extern "C" jintArray JvNewIntArray (jint length);
extern "C" jlongArray JvNewLongArray (jint length);
extern "C" jfloatArray JvNewFloatArray (jint length);
extern "C" jdoubleArray JvNewDoubleArray (jint length);
extern class _Jv_PrimClass _Jv_byteClass, _Jv_shortClass, _Jv_intClass,
_Jv_longClass, _Jv_booleanClass, _Jv_charClass, _Jv_floatClass,
_Jv_doubleClass, _Jv_voidClass;
#define JvPrimClass(TYPE) ((jclass) & _Jv_##TYPE##Class)
extern "C" jobjectArray _Jv_NewObjectArray(jsize length, jclass, jobject init);
extern "C" jobject _Jv_NewPrimArray (jclass eltype, jint count);
extern inline jobjectArray
JvNewObjectArray (jsize length, jclass cls, jobject init)
{
return _Jv_NewObjectArray (length, cls, init);
}
extern inline jcharArray
JvNewCharArray (jint length)
{
return (jcharArray) _Jv_NewPrimArray (JvPrimClass (char), length);
}
extern inline jbooleanArray
JvNewBooleanArray (jint length)
{
return (jbooleanArray) _Jv_NewPrimArray (JvPrimClass (boolean), length);
}
extern inline jbyteArray
JvNewByteArray (jint length)
{
return (jbyteArray) _Jv_NewPrimArray (JvPrimClass (byte), length);
}
extern inline jshortArray
JvNewShortArray (jint length)
{
return (jshortArray) _Jv_NewPrimArray (JvPrimClass (short), length);
}
extern inline jintArray
JvNewIntArray (jint length)
{
return (jintArray) _Jv_NewPrimArray (JvPrimClass (int), length);
}
extern inline jlongArray
JvNewLongArray (jint length)
{
return (jlongArray) _Jv_NewPrimArray (JvPrimClass (long), length);
}
extern inline jfloatArray
JvNewFloatArray (jint length)
{
return (jfloatArray) _Jv_NewPrimArray (JvPrimClass (float), length);
}
extern inline jdoubleArray
JvNewDoubleArray (jint length)
{
return (jdoubleArray) _Jv_NewPrimArray (JvPrimClass (double), length);
}
inline jobjectArray JvNewObjectArray (jsize length, jclass cls, jobject init)
{ return _Jv_NewObjectArray (length, cls, init); }
extern "C" jstringArray JvConvertArgv(int argc, const char **argv);
......
......@@ -93,11 +93,6 @@ JvNewStringUTF (const char *bytes)
return _Jv_NewStringUTF (bytes);
}
extern class _Jv_PrimClass _Jv_byteClass, _Jv_shortClass, _Jv_intClass,
_Jv_longClass, _Jv_booleanClass, _Jv_charClass, _Jv_floatClass,
_Jv_doubleClass, _Jv_voidClass;
#define JvPrimClass(TYPE) ((jclass) & _Jv_##TYPE##Class)
class JvSynchronize
{
private:
......
......@@ -272,6 +272,7 @@ extern "C" jsize _Jv_GetStringUTFRegion (jstring, jsize, jsize, char *);
extern "C" void _Jv_Throw (void *) __attribute__ ((__noreturn__));
extern "C" void _Jv_Sjlj_Throw (void *) __attribute__ ((__noreturn__));
extern "C" void* _Jv_Malloc (jsize) __attribute__((__malloc__));
extern "C" void* _Jv_Realloc (void *, jsize);
extern "C" void _Jv_Free (void*);
typedef unsigned short _Jv_ushort __attribute__((__mode__(__HI__)));
......
......@@ -156,7 +156,9 @@ extern "C" jobject _Jv_NewMultiArray (jclass klass, jint dims, ...)
__attribute__((__malloc__));
extern "C" void *_Jv_CheckCast (jclass klass, jobject obj);
extern "C" void *_Jv_LookupInterfaceMethod (jclass klass, Utf8Const *name,
Utf8Const *signature);
Utf8Const *signature);
extern "C" void *_Jv_LookupInterfaceMethodIdx (jclass klass, jclass iface,
int meth_idx);
extern "C" void _Jv_CheckArrayStore (jobject array, jobject obj);
extern "C" void _Jv_RegisterClass (jclass klass);
extern "C" void _Jv_RegisterClasses (jclass *classes);
......
......@@ -22,6 +22,10 @@ details. */
extern "C" void _Jv_InitClass (jclass klass);
extern "C" void _Jv_RegisterClasses (jclass *classes);
// This must be predefined with "C" linkage.
extern "C" void *_Jv_LookupInterfaceMethodIdx (jclass klass, jclass iface,
int meth_idx);
// These are the possible values for the `state' field of the class
// structure. Note that ordering is important here. Whenever the
// state changes, one should notify all waiters of this class.
......@@ -60,13 +64,41 @@ struct _Jv_Method
_Jv_Utf8Const *signature;
_Jv_ushort accflags;
void *ncode;
_Jv_Method *getNextMethod ()
{ return this + 1; }
};
// Interface Dispatch Tables
union _Jv_IDispatchTable
{
struct
{
// Index into interface's ioffsets.
jshort iindex;
jshort itable_length;
// Class Interface dispatch table.
void **itable;
} cls;
struct
{
// Offsets into implementation class itables.
jshort *ioffsets;
} iface;
};
// Used by _Jv_GetInterfaces ()
struct _Jv_ifaces
{
jclass *list;
jshort len;
jshort count;
};
#define JV_PRIMITIVE_VTABLE ((_Jv_VTable *) -1)
#define JV_CLASS(Obj) ((jclass) (*(_Jv_VTable **) Obj)->clas)
class java::lang::Class : public java::lang::Object
{
public:
......@@ -78,11 +110,6 @@ public:
return loader;
}
jclass getComponentType (void)
{
return isArray () ? (* (jclass *) &methods) : 0;
}
java::lang::reflect::Constructor *getConstructor (JArray<jclass> *);
JArray<java::lang::reflect::Constructor *> *getConstructors (void);
java::lang::reflect::Constructor *getDeclaredConstructor (JArray<jclass> *);
......@@ -112,7 +139,7 @@ public:
java::lang::reflect::Method *getMethod (jstring, JArray<jclass> *);
JArray<java::lang::reflect::Method *> *getMethods (void);
jint getModifiers (void)
inline jint getModifiers (void)
{
return accflags;
}
......@@ -123,21 +150,26 @@ public:
java::io::InputStream *getResourceAsStream (jstring resourceName);
JArray<jobject> *getSigners (void);
jclass getSuperclass (void)
inline jclass getSuperclass (void)
{
return superclass;
}
jboolean isArray (void)
inline jboolean isArray (void)
{
return name->data[0] == '[';
}
inline jclass getComponentType (void)
{
return isArray () ? (* (jclass *) &methods) : 0;
}
jboolean isAssignableFrom (jclass cls);
jboolean isInstance (jobject obj);
jboolean isInterface (void);
jboolean isPrimitive (void)
inline jboolean isPrimitive (void)
{
return vtable == JV_PRIMITIVE_VTABLE;
}
......@@ -150,11 +182,12 @@ public:
{
return size_in_bytes;
}
// finalization
void finalize ();
private:
private:
void checkMemberAccess (jint flags);
void initializeClass (void);
......@@ -162,10 +195,19 @@ private:
// Friend functions implemented in natClass.cc.
friend _Jv_Method *_Jv_GetMethodLocal (jclass klass, _Jv_Utf8Const *name,
_Jv_Utf8Const *signature);
friend jboolean _Jv_IsAssignableFrom(jclass, jclass);
friend void *_Jv_LookupInterfaceMethodIdx (jclass klass, jclass iface,
int method_idx);
inline friend void
_Jv_InitClass (jclass klass)
{
if (klass->state != JV_STATE_DONE)
klass->initializeClass ();
}
friend _Jv_Method* _Jv_LookupDeclaredMethod (jclass, _Jv_Utf8Const *,
_Jv_Utf8Const*);
friend void _Jv_InitClass (jclass klass);
friend jfieldID JvGetFirstInstanceField (jclass);
friend jint JvNumInstanceFields (jclass);
friend jfieldID JvGetFirstStaticField (jclass);
......@@ -205,6 +247,12 @@ private:
java::lang::ClassLoader *loader);
friend void _Jv_PrepareCompiledClass (jclass);
friend void _Jv_PrepareConstantTimeTables (jclass);
friend jshort _Jv_GetInterfaces (jclass, _Jv_ifaces *);
friend void _Jv_GenerateITable (jclass, _Jv_ifaces *, jshort *);
friend jstring _Jv_GetMethodString(jclass, _Jv_Utf8Const *);
friend jshort _Jv_AppendPartialITable (jclass, jclass, void **, jshort);
friend jshort _Jv_FindIIndex (jclass *, jshort *, jshort);
#ifdef INTERPRETER
friend jboolean _Jv_IsInterpretedClass (jclass);
......@@ -213,6 +261,10 @@ private:
_Jv_Utf8Const*);
friend void _Jv_InitField (jobject, jclass, int);
friend _Jv_word _Jv_ResolvePoolEntry (jclass, int);
friend _Jv_Method *_Jv_SearchMethodInClass (jclass cls, jclass klass,
_Jv_Utf8Const *method_name,
_Jv_Utf8Const *method_signature);
friend void _Jv_PrepareClass (jclass);
friend class _Jv_ClassReader;
......@@ -265,6 +317,12 @@ private:
// The thread which has locked this class. Used during class
// initialization.
java::lang::Thread *thread;
// How many levels of "extends" this class is removed from Object.
jshort depth;
// Vector of this class's superclasses, ordered by decreasing depth.
jclass *ancestors;
// Interface Dispatch Table.
_Jv_IDispatchTable *idt;
};
#endif /* __JAVA_LANG_CLASS_H__ */
......@@ -503,6 +503,9 @@ _Jv_NewClass (_Jv_Utf8Const *name, jclass superclass,
ret->interface_count = 0;
ret->state = JV_STATE_NOTHING;
ret->thread = NULL;
ret->depth = 0;
ret->ancestors = NULL;
ret->idt = NULL;
_Jv_RegisterClass (ret);
......
......@@ -42,11 +42,9 @@ details. */
#include <java/lang/ArrayIndexOutOfBoundsException.h>
#include <java/lang/ArithmeticException.h>
#include <java/lang/ClassFormatError.h>
#include <java/lang/ClassCastException.h>
#include <java/lang/NegativeArraySizeException.h>
#include <java/lang/NullPointerException.h>
#include <java/lang/OutOfMemoryError.h>
#include <java/lang/ArrayStoreException.h>
#include <java/lang/System.h>
#include <java/lang/reflect/Modifier.h>
#include <java/io/PrintStream.h>
......@@ -286,31 +284,6 @@ _Jv_ThrowBadArrayIndex(jint bad_index)
(java::lang::String::valueOf(bad_index)));
}
void*
_Jv_CheckCast (jclass c, jobject obj)
{
if (obj != NULL && ! c->isAssignableFrom(obj->getClass()))
JvThrow (new java::lang::ClassCastException);
return obj;
}
void
_Jv_CheckArrayStore (jobject arr, jobject obj)
{
if (obj)
{
JvAssert (arr != NULL);
jclass arr_class = arr->getClass();
JvAssert (arr_class->isArray());
jclass elt_class = arr_class->getComponentType();
jclass obj_class = obj->getClass();
if (! elt_class->isAssignableFrom(obj_class))
JvThrow (new java::lang::ArrayStoreException);
}
}
// Allocate some unscanned memory and throw an exception if no memory.
void *
_Jv_AllocBytesChecked (jsize size)
......@@ -421,54 +394,6 @@ _Jv_NewPrimArray (jclass eltype, jint count)
return arr;
}
jcharArray
JvNewCharArray (jint length)
{
return (jcharArray) _Jv_NewPrimArray (JvPrimClass (char), length);
}
jbooleanArray
JvNewBooleanArray (jint length)
{
return (jbooleanArray) _Jv_NewPrimArray (JvPrimClass (boolean), length);
}
jbyteArray
JvNewByteArray (jint length)
{
return (jbyteArray) _Jv_NewPrimArray (JvPrimClass (byte), length);
}
jshortArray
JvNewShortArray (jint length)
{
return (jshortArray) _Jv_NewPrimArray (JvPrimClass (short), length);
}
jintArray
JvNewIntArray (jint length)
{
return (jintArray) _Jv_NewPrimArray (JvPrimClass (int), length);
}
jlongArray
JvNewLongArray (jint length)
{
return (jlongArray) _Jv_NewPrimArray (JvPrimClass (long), length);
}
jfloatArray
JvNewFloatArray (jint length)
{
return (jfloatArray) _Jv_NewPrimArray (JvPrimClass (float), length);
}
jdoubleArray
JvNewDoubleArray (jint length)
{
return (jdoubleArray) _Jv_NewPrimArray (JvPrimClass (double), length);
}
jobject
_Jv_NewArray (jint type, jint size)
{
......@@ -919,24 +844,35 @@ _Jv_SetMaximumHeapSize (const char *arg)
void *
_Jv_MallocUnchecked (jsize size)
_Jv_Malloc (jsize size)
{
if (size == 0)
size = 1;
return malloc ((size_t) size);
void *ptr = malloc ((size_t) size);
if (ptr == NULL)
JvThrow (no_memory);
return ptr;
}
void *
_Jv_Malloc (jsize size)
_Jv_Realloc (void *ptr, jsize size)
{
if (size == 0)
size = 1;
void *ptr = malloc ((size_t) size);
ptr = realloc (ptr, (size_t) size);
if (ptr == NULL)
JvThrow (no_memory);
return ptr;
}
void *
_Jv_MallocUnchecked (jsize size)
{
if (size == 0)
size = 1;
return malloc ((size_t) size);
}
void
_Jv_Free (void* ptr)
{
......
......@@ -24,6 +24,7 @@ details. */
#include <java/lang/InternalError.h>
#include <java/lang/VirtualMachineError.h>
#include <java/lang/NoSuchFieldError.h>
#include <java/lang/NoSuchMethodError.h>
#include <java/lang/ClassFormatError.h>
#include <java/lang/IllegalAccessError.h>
#include <java/lang/AbstractMethodError.h>
......@@ -230,59 +231,78 @@ _Jv_ResolvePoolEntry (jclass klass, int index)
_Jv_Method *the_method = 0;
jclass found_class = 0;
// we make a loop here, because methods are allowed to be moved to
// a super class, and still be visible.. (binary compatibility).
// First search the class itself.
the_method = _Jv_SearchMethodInClass (owner, klass,
method_name, method_signature);
for (jclass cls = owner; cls != 0; cls = cls->getSuperclass ())
{
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;
if (the_method != 0)
{
found_class = owner;
goto end_of_method_search;
}
if (cls == klass
|| ((method->accflags & Modifier::PUBLIC) != 0)
|| (((method->accflags & Modifier::PROTECTED) != 0)
&& cls->isAssignableFrom (klass))
|| (((method->accflags & Modifier::PRIVATE) == 0)
&& _Jv_ClassNameSamePackage (cls->name,
klass->name)))
{
// FIXME: if (cls->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
the_method = method;
// 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 (pool->tags[index] == JV_CONSTANT_InterfaceMethodref)
{
_Jv_ifaces ifaces;
ifaces.count = 0;
ifaces.len = 4;
ifaces.list = (jclass *) _Jv_Malloc (ifaces.len * sizeof (jclass *));
_Jv_GetInterfaces (owner, &ifaces);
for (int i=0; i < ifaces.count; i++)
{
jclass cls = ifaces.list[i];
the_method = _Jv_SearchMethodInClass (cls, klass, method_name,
method_signature);
if (the_method != 0)
{
found_class = cls;
if (pool->tags[index] == JV_CONSTANT_InterfaceMethodref)
vtable_index = -1;
else
vtable_index = _Jv_DetermineVTableIndex
(cls, method_name, method_signature);
if (vtable_index == 0)
throw_incompatible_class_change_error
(JvNewStringLatin1 ("method not found"));
goto end_of_method_search;
}
else
{
JvThrow (new java::lang::IllegalAccessError);
break;
}
}
_Jv_Free (ifaces.list);
if (the_method != 0)
goto end_of_method_search;
}
// Finally, search superclasses.
for (jclass cls = owner->getSuperclass (); cls != 0;
cls = cls->getSuperclass ())
{
the_method = _Jv_SearchMethodInClass (cls, klass,
method_name, method_signature);
if (the_method != 0)
{
found_class = cls;
break;
}
}
end_of_method_search:
// FIXME: if (cls->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 (pool->tags[index] == JV_CONSTANT_InterfaceMethodref)
vtable_index = -1;
else
vtable_index = _Jv_DetermineVTableIndex
(found_class, method_name, method_signature);
if (vtable_index == 0)
throw_incompatible_class_change_error
(JvNewStringLatin1 ("method not found"));
if (the_method == 0)
{
jstring msg = JvNewStringLatin1 ("method ");
......@@ -290,7 +310,7 @@ _Jv_ResolvePoolEntry (jclass klass, int index)
msg = msg->concat (JvNewStringLatin1("."));
msg = msg->concat (_Jv_NewStringUTF (method_name->data));
msg = msg->concat (JvNewStringLatin1(" was not found."));
JvThrow(new java::lang::NoSuchFieldError (msg));
JvThrow(new java::lang::NoSuchMethodError (msg));
}
pool->data[index].rmethod =
......@@ -307,6 +327,41 @@ _Jv_ResolvePoolEntry (jclass klass, int index)
return pool->data[index];
}
// Find a method declared in the cls that is referenced from klass and
// perform access checks.
_Jv_Method *
_Jv_SearchMethodInClass (jclass cls, jclass klass,
_Jv_Utf8Const *method_name,
_Jv_Utf8Const *method_signature)
{
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;
if (cls == klass
|| ((method->accflags & Modifier::PUBLIC) != 0)
|| (((method->accflags & Modifier::PROTECTED) != 0)
&& cls->isAssignableFrom (klass))
|| (((method->accflags & Modifier::PRIVATE) == 0)
&& _Jv_ClassNameSamePackage (cls->name,
klass->name)))
{
return method;
}
else
{
JvThrow (new java::lang::IllegalAccessError);
}
}
return 0;
}
void
_Jv_ResolveField (_Jv_Field *field, java::lang::ClassLoader *loader)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment