Commit 04a704a4 by Tom Tromey Committed by Tom Tromey

For PR libgcj/7073:

	* resolve.cc (_Jv_PrepareClass): Only resolve superclass if it
	exists.
	* defineclass.cc (handleClassBegin): Superclass for interface is
	`null'.

From-SVN: r54835
parent aa16c0fa
2002-06-20 Tom Tromey <tromey@redhat.com>
For PR libgcj/7073:
* resolve.cc (_Jv_PrepareClass): Only resolve superclass if it
exists.
* defineclass.cc (handleClassBegin): Superclass for interface is
`null'.
2002-06-18 Tom Tromey <tromey@redhat.com> 2002-06-18 Tom Tromey <tromey@redhat.com>
* gcj/javaprims.h: Updated class declaration list. * gcj/javaprims.h: Updated class declaration list.
......
// defineclass.cc - defining a class from .class format. // defineclass.cc - defining a class from .class format.
/* Copyright (C) 1999, 2000, 2001 Free Software Foundation /* Copyright (C) 1999, 2000, 2001, 2002 Free Software Foundation
This file is part of libgcj. This file is part of libgcj.
...@@ -895,20 +895,11 @@ _Jv_ClassReader::handleClassBegin ...@@ -895,20 +895,11 @@ _Jv_ClassReader::handleClassBegin
pool_data[this_class].clazz = def; pool_data[this_class].clazz = def;
pool_tags[this_class] = JV_CONSTANT_ResolvedClass; pool_tags[this_class] = JV_CONSTANT_ResolvedClass;
if (super_class == 0) if (super_class == 0 && ! (access_flags & Modifier::INTERFACE))
{ {
// interfaces have java.lang.Object as super.
if (access_flags & Modifier::INTERFACE)
{
def->superclass = (jclass)&java::lang::Object::class$;
}
// FIXME: Consider this carefully! // FIXME: Consider this carefully!
else if (!_Jv_equalUtf8Consts (def->name, if (! _Jv_equalUtf8Consts (def->name, java::lang::Object::class$.name))
java::lang::Object::class$.name)) throw_no_class_def_found_error ("loading java.lang.Object");
{
throw_no_class_def_found_error ("loading java.lang.Object");
}
} }
// In the pre-loading state, it can be looked up in the // In the pre-loading state, it can be looked up in the
...@@ -924,25 +915,30 @@ _Jv_ClassReader::handleClassBegin ...@@ -924,25 +915,30 @@ _Jv_ClassReader::handleClassBegin
if (super_class != 0) if (super_class != 0)
{ {
// load the super class // Load the superclass.
check_tag (super_class, JV_CONSTANT_Class); check_tag (super_class, JV_CONSTANT_Class);
_Jv_Utf8Const* super_name = pool_data[super_class].utf8; _Jv_Utf8Const* super_name = pool_data[super_class].utf8;
// load the super class using our defining loader // Load the superclass using our defining loader.
jclass the_super = _Jv_FindClass (super_name, jclass the_super = _Jv_FindClass (super_name,
def->loader); def->loader);
// This will establish that we are allowed to be a subclass, // This will establish that we are allowed to be a subclass,
// and check for class circularity error // and check for class circularity error.
checkExtends (def, the_super); checkExtends (def, the_super);
def->superclass = the_super; // Note: for an interface we will find Object as the
// superclass. We still check it above to ensure class file
// validity, but we simply assign `null' to the actual field in
// this case.
def->superclass = (((access_flags & Modifier::INTERFACE))
? NULL : the_super);
pool_data[super_class].clazz = the_super; pool_data[super_class].clazz = the_super;
pool_tags[super_class] = JV_CONSTANT_ResolvedClass; pool_tags[super_class] = JV_CONSTANT_ResolvedClass;
} }
// now we've come past the circularity problem, we can // Now we've come past the circularity problem, we can
// now say that we're loading... // now say that we're loading.
def->state = JV_STATE_LOADING; def->state = JV_STATE_LOADING;
def->notifyAll (); def->notifyAll ();
......
...@@ -516,11 +516,14 @@ _Jv_PrepareClass(jclass klass) ...@@ -516,11 +516,14 @@ _Jv_PrepareClass(jclass klass)
if (klass->state >= JV_STATE_PREPARED) if (klass->state >= JV_STATE_PREPARED)
return; return;
// make sure super-class is linked. This involves taking a lock on // Make sure super-class is linked. This involves taking a lock on
// the super class, so we use the Java method resolveClass, which will // the super class, so we use the Java method resolveClass, which
// unlock it properly, should an exception happen. // will unlock it properly, should an exception happen. If there's
// no superclass, do nothing -- Object will already have been
// resolved.
java::lang::ClassLoader::resolveClass0 (klass->superclass); if (klass->superclass)
java::lang::ClassLoader::resolveClass0 (klass->superclass);
_Jv_InterpClass *clz = (_Jv_InterpClass*)klass; _Jv_InterpClass *clz = (_Jv_InterpClass*)klass;
...@@ -529,8 +532,12 @@ _Jv_PrepareClass(jclass klass) ...@@ -529,8 +532,12 @@ _Jv_PrepareClass(jclass klass)
int instance_size; int instance_size;
int static_size; int static_size;
// java.lang.Object is never interpreted! // Although java.lang.Object is never interpreted, an interface can
instance_size = clz->superclass->size (); // have a null superclass.
if (clz->superclass)
instance_size = clz->superclass->size();
else
instance_size = java::lang::Object::class$.size();
static_size = 0; static_size = 0;
for (int i = 0; i < clz->field_count; i++) for (int i = 0; i < clz->field_count; i++)
...@@ -646,9 +653,6 @@ _Jv_PrepareClass(jclass klass) ...@@ -646,9 +653,6 @@ _Jv_PrepareClass(jclass klass)
jclass super_class = clz->getSuperclass (); jclass super_class = clz->getSuperclass ();
if (super_class == 0)
throw_internal_error ("cannot handle interpreted base classes");
for (int i = 0; i < clz->method_count; i++) for (int i = 0; i < clz->method_count; i++)
{ {
_Jv_Method *this_meth = &clz->methods[i]; _Jv_Method *this_meth = &clz->methods[i];
...@@ -708,6 +712,10 @@ _Jv_PrepareClass(jclass klass) ...@@ -708,6 +712,10 @@ _Jv_PrepareClass(jclass klass)
while (effective_superclass && effective_superclass->vtable == NULL) while (effective_superclass && effective_superclass->vtable == NULL)
effective_superclass = effective_superclass->superclass; effective_superclass = effective_superclass->superclass;
/* If we ended up without a superclass, use Object. */
if (! effective_superclass)
effective_superclass = &java::lang::Object::class$;
/* copy super class' vtable entries. */ /* copy super class' vtable entries. */
if (effective_superclass && effective_superclass->vtable) if (effective_superclass && effective_superclass->vtable)
for (int i = 0; i < effective_superclass->vtable_method_count; ++i) for (int i = 0; i < effective_superclass->vtable_method_count; ++i)
......
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