diff options
-rw-r--r-- | libjava/ChangeLog | 11 | ||||
-rw-r--r-- | libjava/include/jvm.h | 12 | ||||
-rw-r--r-- | libjava/java/lang/Class.h | 3 | ||||
-rw-r--r-- | libjava/java/lang/natClassLoader.cc | 12 | ||||
-rw-r--r-- | libjava/prims.cc | 14 |
5 files changed, 45 insertions, 7 deletions
diff --git a/libjava/ChangeLog b/libjava/ChangeLog index ded5d9b..7ec5cb1 100644 --- a/libjava/ChangeLog +++ b/libjava/ChangeLog @@ -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>. diff --git a/libjava/include/jvm.h b/libjava/include/jvm.h index 57f449b..ad187c0 100644 --- a/libjava/include/jvm.h +++ b/libjava/include/jvm.h @@ -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; diff --git a/libjava/java/lang/Class.h b/libjava/java/lang/Class.h index 31f143a..9ea3759 100644 --- a/libjava/java/lang/Class.h +++ b/libjava/java/lang/Class.h @@ -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); diff --git a/libjava/java/lang/natClassLoader.cc b/libjava/java/lang/natClassLoader.cc index aa8782d..b4a9e49 100644 --- a/libjava/java/lang/natClassLoader.cc +++ b/libjava/java/lang/natClassLoader.cc @@ -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; } - - diff --git a/libjava/prims.cc b/libjava/prims.cc index 4279b09..3a022f0 100644 --- a/libjava/prims.cc +++ b/libjava/prims.cc @@ -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); |