void
_Jv_ClassReader::handleMethodsBegin (int count)
{
- def->methods = (_Jv_Method*)
- _Jv_AllocBytes (sizeof (_Jv_Method)*count);
+ def->methods = (_Jv_Method *) _Jv_AllocBytes (sizeof (_Jv_Method) * count);
def->interpreted_methods
= (_Jv_MethodBase **) _Jv_AllocBytes (sizeof (_Jv_MethodBase *)
* count);
for (int i = 0; i < count; i++)
- def->interpreted_methods[i] = 0;
+ {
+ def->interpreted_methods[i] = 0;
+ def->methods[i].index = (_Jv_ushort) -1;
+ }
def->method_count = count;
}
throw new java::lang::InternalError (JvNewStringLatin1 (msg));
}
-static void throw_incompatible_class_change_error (jstring msg)
+static void
+throw_incompatible_class_change_error (jstring msg)
{
throw new java::lang::IncompatibleClassChangeError (msg);
}
-static void throw_class_circularity_error (jstring msg)
+static void
+throw_class_circularity_error (jstring msg)
{
throw new java::lang::ClassCircularityError (msg);
}
java::lang::Class *klass = NULL;
try
{
- for (int i=1; !klass; i++)
+ for (int i = 1; !klass; i++)
{
klass = t->classAt (i);
}
}
// Returns true if METH should get an entry in a VTable.
-static bool
+static jboolean
isVirtualMethod (_Jv_Method *meth)
{
using namespace java::lang::reflect;
if (klass->vtable != NULL || klass->isInterface()
|| klass->vtable_method_count != -1)
return;
-
+
jclass superclass = klass->superclass;
if (superclass != NULL && superclass->vtable_method_count == -1)
JvSynchronize sync (superclass);
_Jv_LayoutVTableMethods (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 (!isVirtualMethod(meth))
- continue;
-
+
+ if (! isVirtualMethod (meth))
+ continue;
+
if (superclass != NULL)
super_meth = _Jv_LookupDeclaredMethod (superclass, meth->name,
meth->signature);
-
+
if (super_meth)
meth->index = super_meth->index;
- else
+ else if (! (meth->accflags & java::lang::reflect::Modifier::FINAL))
meth->index = index++;
}
-
+
klass->vtable_method_count = index;
}
-// Set entries in VTABLE for virtual methods declared in KLASS. If KLASS has
-// an immediate abstract parent, recursivly do its methods first.
+// Set entries in VTABLE for virtual methods declared in KLASS. If
+// KLASS has an immediate abstract parent, recursively do its methods
+// first. FLAGS is used to determine which slots we've actually set.
void
-_Jv_SetVTableEntries (jclass klass, _Jv_VTable *vtable)
+_Jv_SetVTableEntries (jclass klass, _Jv_VTable *vtable, jboolean *flags)
{
using namespace java::lang::reflect;
jclass superclass = klass->getSuperclass();
if (superclass != NULL && (superclass->getModifiers() & Modifier::ABSTRACT))
- _Jv_SetVTableEntries (superclass, vtable);
-
+ _Jv_SetVTableEntries (superclass, vtable, flags);
+
for (int i = klass->method_count - 1; i >= 0; i--)
{
_Jv_Method *meth = &klass->methods[i];
- if (!isVirtualMethod(meth))
+ if (meth->index == (_Jv_ushort) -1)
continue;
- vtable->set_method(meth->index, meth->ncode);
+ if ((meth->accflags & Modifier::ABSTRACT))
+ {
+ // FIXME: we should set abstract slots to a function that
+ // throws AbstractMethodError. How can we do that on IA-64?
+ flags[meth->index] = false;
+ }
+ else
+ {
+ vtable->set_method(meth->index, meth->ncode);
+ flags[meth->index] = true;
+ }
}
}
if (klass->vtable != NULL || klass->isInterface()
|| (klass->accflags & Modifier::ABSTRACT))
return;
-
+
// out before we can create a vtable.
if (klass->vtable_method_count == -1)
_Jv_LayoutVTableMethods (klass);
// Allocate the new vtable.
_Jv_VTable *vtable = _Jv_VTable::new_vtable (klass->vtable_method_count);
klass->vtable = vtable;
-
+
+ jboolean flags[klass->vtable_method_count];
+ for (int i = 0; i < klass->vtable_method_count; ++i)
+ flags[i] = false;
+
// Copy the vtable of the closest non-abstract superclass.
jclass superclass = klass->superclass;
if (superclass != NULL)
}
for (int i = 0; i < superclass->vtable_method_count; ++i)
- vtable->set_method (i, superclass->vtable->get_method (i));
+ {
+ vtable->set_method (i, superclass->vtable->get_method (i));
+ flags[i] = true;
+ }
}
// Set the class pointer and GC descriptor.
// For each virtual declared in klass and any immediate abstract
// superclasses, set new vtable entry or override an old one.
- _Jv_SetVTableEntries (klass, vtable);
+ _Jv_SetVTableEntries (klass, vtable, flags);
+
+ // It is an error to have an abstract method in a concrete class.
+ if (! (klass->accflags & Modifier::ABSTRACT))
+ {
+ for (int i = 0; i < klass->vtable_method_count; ++i)
+ if (! flags[i])
+ // FIXME: messsage.
+ throw new java::lang::AbstractMethodError ();
+ }
}