prims.cc (DECLARE_PRIM_TYPE): Define a vtable as well.

* prims.cc (DECLARE_PRIM_TYPE): Define a vtable as well.
	(_Jv_PrimClass): Set `methods' by calling _Jv_FindArrayClass.
	* include/jvm.h (struct _Jv_ArrayVTable): Declare.
	(NUM_OBJECT_METHODS): New define.
	* java/lang/natClassLoader.cc (_Jv_FindArrayClass): Added
	`array_vtable' parameter.  Added assertion.
	* java/lang/Class.h (_Jv_FindArrayClass): Added `array_vtable'
	parameter.

From-SVN: r34312
This commit is contained in:
Tom Tromey 2000-05-31 23:50:37 +00:00 committed by Tom Tromey
parent f1aa7a521a
commit c74e221410
5 changed files with 45 additions and 7 deletions

View File

@ -1,3 +1,14 @@
2000-05-31 Tom Tromey <tromey@cygnus.com>
* prims.cc (DECLARE_PRIM_TYPE): Define a vtable as well.
(_Jv_PrimClass): Set `methods' by calling _Jv_FindArrayClass.
* include/jvm.h (struct _Jv_ArrayVTable): Declare.
(NUM_OBJECT_METHODS): New define.
* java/lang/natClassLoader.cc (_Jv_FindArrayClass): Added
`array_vtable' parameter. Added assertion.
* java/lang/Class.h (_Jv_FindArrayClass): Added `array_vtable'
parameter.
2000-05-31 Bryce McKinlay <bryce@albatross.co.nz>
* gcj/cni.h: Include <string.h>.

View File

@ -34,6 +34,18 @@ struct _Jv_VTable
void *method[1];
};
// Number of virtual methods on object. FIXME: it sucks that we have
// to keep this up to date by hand.
#define NUM_OBJECT_METHODS 5
// This structure is the type of an array's vtable.
struct _Jv_ArrayVTable
{
jclass clas;
// `+1' because there is an extra slot for C++ RTTI compatibility.
void *method[NUM_OBJECT_METHODS + 1];
};
union _Jv_word
{
jobject o;

View File

@ -251,7 +251,8 @@ private:
friend jclass _Jv_FindClassInCache (_Jv_Utf8Const *name,
java::lang::ClassLoader *loader);
friend jclass _Jv_FindArrayClass (jclass element,
java::lang::ClassLoader *loader);
java::lang::ClassLoader *loader,
_Jv_VTable *array_vtable = 0);
friend jclass _Jv_NewClass (_Jv_Utf8Const *name, jclass superclass,
java::lang::ClassLoader *loader);

View File

@ -514,7 +514,8 @@ _Jv_NewClass (_Jv_Utf8Const *name, jclass superclass,
}
jclass
_Jv_FindArrayClass (jclass element, java::lang::ClassLoader *loader)
_Jv_FindArrayClass (jclass element, java::lang::ClassLoader *loader,
_Jv_VTable *array_vtable)
{
_Jv_Utf8Const *array_name;
int len;
@ -561,6 +562,7 @@ _Jv_FindArrayClass (jclass element, java::lang::ClassLoader *loader)
// Note that `vtable_method_count' doesn't include the initial
// NULL slot.
JvAssert (ObjectClass.vtable_method_count == NUM_OBJECT_METHODS);
int dm_count = ObjectClass.vtable_method_count + 1;
// Create a new vtable by copying Object's vtable (except the
@ -569,7 +571,11 @@ _Jv_FindArrayClass (jclass element, java::lang::ClassLoader *loader)
// GC.
int size = (sizeof (_Jv_VTable) +
((dm_count - 1) * sizeof (void *)));
_Jv_VTable *vtable = (_Jv_VTable *) _Jv_AllocBytes (size);
_Jv_VTable *vtable;
if (array_vtable)
vtable = array_vtable;
else
vtable = (_Jv_VTable *) _Jv_AllocBytes (size);
vtable->clas = array_class;
memcpy (vtable->method, ObjectClass.vtable->method,
dm_count * sizeof (void *));
@ -607,5 +613,3 @@ _Jv_FindArrayClass (jclass element, java::lang::ClassLoader *loader)
return array_class;
}

View File

@ -519,7 +519,7 @@ class _Jv_PrimClass : public java::lang::Class
public:
// FIXME: calling convention is weird. If we use the natural types
// then the compiler will complain because they aren't Java types.
_Jv_PrimClass (jobject cname, jbyte sig, jint len)
_Jv_PrimClass (jobject cname, jbyte sig, jint len, jobject array_vtable)
{
using namespace java::lang::reflect;
@ -545,11 +545,21 @@ public:
interface_count = 0;
state = JV_STATE_NOTHING;
thread = NULL;
// Note that we have to set `methods' to NULL.
if (sig != 'V')
_Jv_FindArrayClass (this, NULL, (_Jv_VTable *) array_vtable);
}
};
// We use this to define both primitive classes and the vtables for
// arrays of primitive classes. The latter are given names so that we
// can refer to them from the compiler, allowing us to construct
// arrays of primitives statically.
#define DECLARE_PRIM_TYPE(NAME, SIG, LEN) \
_Jv_PrimClass _Jv_##NAME##Class((jobject) #NAME, (jbyte) SIG, (jint) LEN)
_Jv_ArrayVTable _Jv_##NAME##VTable; \
_Jv_PrimClass _Jv_##NAME##Class((jobject) #NAME, (jbyte) SIG, (jint) LEN, \
(jobject) &_Jv_##NAME##VTable)
DECLARE_PRIM_TYPE(byte, 'B', 1);
DECLARE_PRIM_TYPE(short, 'S', 2);