This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[libjava] ia64 c++ abi vtable changes
- To: gcc-patches at gcc dot gnu dot org, java-patches at gcc dot gnu dot org
- Subject: [libjava] ia64 c++ abi vtable changes
- From: Richard Henderson <rth at redhat dot com>
- Date: Thu, 20 Sep 2001 15:38:09 -0700
Fairly straightforward once we abstract a bit back into
the vtable class.
r~
* include/jvm.h (_Jv_VTable): Handle function descriptors for ia64;
add get_method, set_method, vtable_elt_size, new_vtable.
(_Jv_ArrayVTable): Derive from _Jv_VTable.
* resolve.cc (_Jv_PrepareClass): Use new _Jv_VTable methods.
* interpret.cc (_Jv_InterpMethod::continue1): Likewise.
* java/lang/natClassLoader.cc (_Jv_NewArrayClass): Likewise.
Index: libjava/interpret.cc
===================================================================
RCS file: /cvs/gcc/gcc/libjava/interpret.cc,v
retrieving revision 1.25
diff -c -p -d -r1.25 interpret.cc
*** libjava/interpret.cc 2001/03/26 07:05:31 1.25
--- libjava/interpret.cc 2001/09/20 22:19:17
*************** void _Jv_InterpMethod::continue1 (_Jv_In
*** 691,697 ****
{
jobject rcv = sp[0].o;
_Jv_VTable *table = *(_Jv_VTable**)rcv;
! fun = (void (*)()) table->method[rmeth->vtable_index];
}
}
goto perform_invoke;
--- 691,697 ----
{
jobject rcv = sp[0].o;
_Jv_VTable *table = *(_Jv_VTable**)rcv;
! fun = (void (*)()) table->get_method(rmeth->vtable_index);
}
}
goto perform_invoke;
Index: libjava/resolve.cc
===================================================================
RCS file: /cvs/gcc/gcc/libjava/resolve.cc,v
retrieving revision 1.22
diff -c -p -d -r1.22 resolve.cc
*** libjava/resolve.cc 2001/05/24 05:40:36 1.22
--- libjava/resolve.cc 2001/09/20 22:19:17
*************** _Jv_PrepareClass(jclass klass)
*** 696,704 ****
clz->vtable_method_count = vtable_count;
/* allocate vtable structure */
! _Jv_VTable *vtable = (_Jv_VTable*)
! _Jv_AllocBytes (sizeof (_Jv_VTable)
! + (sizeof (void*) * (vtable_count)));
vtable->clas = clz;
vtable->gc_descr = _Jv_BuildGCDescr(clz);
--- 696,702 ----
clz->vtable_method_count = vtable_count;
/* allocate vtable structure */
! _Jv_VTable *vtable = _Jv_VTable::new_vtable (vtable_count);
vtable->clas = clz;
vtable->gc_descr = _Jv_BuildGCDescr(clz);
*************** _Jv_PrepareClass(jclass klass)
*** 712,720 ****
/* copy super class' vtable entries. */
if (effective_superclass && effective_superclass->vtable)
! memcpy ((void*)&vtable->method[0],
! (void*)&effective_superclass->vtable->method[0],
! sizeof (void*) * effective_superclass->vtable_method_count);
}
/* now, install our own vtable entries, reprise... */
--- 710,717 ----
/* copy super class' vtable entries. */
if (effective_superclass && effective_superclass->vtable)
! for (int i = 0; i < effective_superclass->vtable_method_count; ++i)
! vtable->set_method (i, effective_superclass->vtable->get_method (i));
}
/* now, install our own vtable entries, reprise... */
*************** _Jv_PrepareClass(jclass klass)
*** 735,743 ****
throw_internal_error ("vtable problem...");
if (clz->interpreted_methods[i] == 0)
! vtable->method[index] = (void*)&_Jv_abstractMethodError;
else
! vtable->method[index] = this_meth->ncode;
}
}
--- 732,740 ----
throw_internal_error ("vtable problem...");
if (clz->interpreted_methods[i] == 0)
! vtable->set_method(i, (void*)&_Jv_abstractMethodError);
else
! vtable->set_method(i, this_meth->ncode);
}
}
Index: libjava/include/jvm.h
===================================================================
RCS file: /cvs/gcc/gcc/libjava/include/jvm.h,v
retrieving revision 1.39
diff -c -p -d -r1.39 jvm.h
*** libjava/include/jvm.h 2001/09/10 01:21:08 1.39
--- libjava/include/jvm.h 2001/09/20 22:19:17
*************** details. */
*** 27,36 ****
/* Structure of the virtual table. */
struct _Jv_VTable
{
jclass clas;
void *gc_descr;
! void *method[1];
! void *get_finalizer() { return method[0]; }
};
// Number of virtual methods on object. FIXME: it sucks that we have
--- 27,61 ----
/* Structure of the virtual table. */
struct _Jv_VTable
{
+ #ifdef __ia64__
jclass clas;
+ unsigned long : 64;
void *gc_descr;
! unsigned long : 64;
!
! typedef struct { void *pc, *gp; } vtable_elt;
! #else
! jclass clas;
! void *gc_descr;
!
! typedef void *vtable_elt;
! #endif
!
! // This must be last, as derived classes "extend" this by
! // adding new data members.
! vtable_elt method[1];
!
! #ifdef __ia64__
! void *get_method(int i) { return &method[i]; }
! void set_method(int i, void *fptr) { method[i] = *(vtable_elt *)fptr; }
! #else
! void *get_method(int i) { return method[i]; }
! void set_method(int i, void *fptr) { method[i] = fptr; }
! #endif
!
! void *get_finalizer() { return get_method(0); }
! static size_t vtable_elt_size() { return sizeof(vtable_elt); }
! static _Jv_VTable *new_vtable (int count);
};
// Number of virtual methods on object. FIXME: it sucks that we have
*************** struct _Jv_VTable
*** 38,49 ****
#define NUM_OBJECT_METHODS 5
// This structure is the type of an array's vtable.
! struct _Jv_ArrayVTable
{
! jclass clas;
! void *gc_descr;
! void *method[NUM_OBJECT_METHODS];
! void *get_finalizer() { return method[0]; }
};
union _Jv_word
--- 63,71 ----
#define NUM_OBJECT_METHODS 5
// This structure is the type of an array's vtable.
! struct _Jv_ArrayVTable : public _Jv_VTable
{
! vtable_elt extra_method[NUM_OBJECT_METHODS - 1];
};
union _Jv_word
*************** void _Jv_SetMaximumHeapSize (const char
*** 171,176 ****
--- 193,210 ----
extern "C" void JvRunMain (jclass klass, int argc, const char **argv);
void _Jv_RunMain (jclass klass, const char *name, int argc, const char **argv,
bool is_jar);
+
+ // Delayed until after _Jv_AllocBytes is declared.
+ //
+ // Note that we allocate this as unscanned memory -- the vtables
+ // are handled specially by the GC.
+
+ inline _Jv_VTable *
+ _Jv_VTable::new_vtable (int count)
+ {
+ size_t size = sizeof(_Jv_VTable) + (count - 1) * vtable_elt_size ();
+ return (_Jv_VTable *) _Jv_AllocBytes (size);
+ }
// This function is used to determine the hash code of an object.
inline jint
Index: libjava/java/lang/natClassLoader.cc
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/lang/natClassLoader.cc,v
retrieving revision 1.36
diff -c -p -d -r1.36 natClassLoader.cc
*** libjava/java/lang/natClassLoader.cc 2001/09/05 17:48:18 1.36
--- libjava/java/lang/natClassLoader.cc 2001/09/20 22:19:17
*************** _Jv_NewArrayClass (jclass element, java:
*** 626,645 ****
JvAssert (ObjectClass.vtable_method_count == NUM_OBJECT_METHODS);
int dm_count = ObjectClass.vtable_method_count;
! // Create a new vtable by copying Object's vtable (except the
! // class pointer, of course). Note that we allocate this as
! // unscanned memory -- the vtables are handled specially by the
! // GC.
! int size = (sizeof (_Jv_VTable) + ((dm_count - 1) * sizeof (void *)));
_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 *));
vtable->gc_descr = ObjectClass.vtable->gc_descr;
array_class->vtable = vtable;
array_class->vtable_method_count = ObjectClass.vtable_method_count;
--- 626,642 ----
JvAssert (ObjectClass.vtable_method_count == NUM_OBJECT_METHODS);
int dm_count = ObjectClass.vtable_method_count;
! // Create a new vtable by copying Object's vtable.
_Jv_VTable *vtable;
if (array_vtable)
vtable = array_vtable;
else
! vtable = _Jv_VTable::new_vtable (dm_count);
vtable->clas = array_class;
vtable->gc_descr = ObjectClass.vtable->gc_descr;
+ for (int i = 0; i < dm_count; ++i)
+ vtable->set_method (i, ObjectClass.vtable->get_method (i));
+
array_class->vtable = vtable;
array_class->vtable_method_count = ObjectClass.vtable_method_count;