ClassLoader.java (setSigners): Implemented.
[gcc.git] / libjava / java / lang / natClass.cc
index 2eec179fa647c1f3be814a670ad604fe836560b3..4c71ed1cea03fd4272fbe98b84665db6fc705504 100644 (file)
@@ -1,6 +1,6 @@
 // natClass.cc - Implementation of java.lang.Class native methods.
 
-/* Copyright (C) 1998, 1999, 2000  Free Software Foundation
+/* Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003  Free Software Foundation
 
    This file is part of libgcj.
 
@@ -34,7 +34,10 @@ details.  */
 #include <java/lang/ExceptionInInitializerError.h>
 #include <java/lang/IllegalAccessException.h>
 #include <java/lang/IllegalAccessError.h>
+#include <java/lang/IllegalArgumentException.h>
 #include <java/lang/IncompatibleClassChangeError.h>
+#include <java/lang/NoSuchFieldError.h>
+#include <java/lang/ArrayIndexOutOfBoundsException.h>
 #include <java/lang/InstantiationException.h>
 #include <java/lang/NoClassDefFoundError.h>
 #include <java/lang/NoSuchFieldException.h>
@@ -42,58 +45,47 @@ details.  */
 #include <java/lang/NoSuchMethodException.h>
 #include <java/lang/Thread.h>
 #include <java/lang/NullPointerException.h>
+#include <java/lang/RuntimePermission.h>
 #include <java/lang/System.h>
 #include <java/lang/SecurityManager.h>
 #include <java/lang/StringBuffer.h>
+#include <java/lang/VMClassLoader.h>
+#include <gnu/gcj/runtime/StackTrace.h>
 #include <gcj/method.h>
+#include <gnu/gcj/runtime/MethodRef.h>
+#include <gnu/gcj/RawData.h>
 
 #include <java-cpool.h>
 
 \f
 
-// FIXME: remove these.
-#define CloneableClass java::lang::Cloneable::class$
-#define ObjectClass java::lang::Object::class$
-#define ErrorClass java::lang::Error::class$
-#define ClassClass java::lang::Class::class$
-#define MethodClass java::lang::reflect::Method::class$
-#define FieldClass java::lang::reflect::Field::class$
-#define ConstructorClass java::lang::reflect::Constructor::class$
-
-// Some constants we use to look up the class initializer.
-static _Jv_Utf8Const *void_signature = _Jv_makeUtf8Const ("()V", 3);
-static _Jv_Utf8Const *clinit_name = _Jv_makeUtf8Const ("<clinit>", 8);
-static _Jv_Utf8Const *init_name = _Jv_makeUtf8Const ("<init>", 6);
-static _Jv_Utf8Const *finit_name = _Jv_makeUtf8Const ("finit$", 6);
-// The legacy `$finit$' method name, which still needs to be
-// recognized as equivalent to the now prefered `finit$' name.
-static _Jv_Utf8Const *finit_leg_name = _Jv_makeUtf8Const ("$finit$", 7);
-
-\f
+using namespace gcj;
 
 jclass
-java::lang::Class::forName (jstring className, java::lang::ClassLoader *loader)
+java::lang::Class::forName (jstring className, jboolean initialize,
+                            java::lang::ClassLoader *loader)
 {
   if (! className)
-    JvThrow (new java::lang::NullPointerException);
+    throw new java::lang::NullPointerException;
 
   jsize length = _Jv_GetStringUTFLength (className);
   char buffer[length];
   _Jv_GetStringUTFRegion (className, 0, length, buffer);
 
-  // FIXME: should check syntax of CLASSNAME and throw
-  // IllegalArgumentException on failure.
   _Jv_Utf8Const *name = _Jv_makeUtf8Const (buffer, length);
 
-  // FIXME: should use bootstrap class loader if loader is null.
+  if (! _Jv_VerifyClassName (name))
+    throw new java::lang::ClassNotFoundException (className);
+
   jclass klass = (buffer[0] == '[' 
                  ? _Jv_FindClassFromSignature (name->data, loader)
                  : _Jv_FindClass (name, loader));
 
-  if (klass)
+  if (klass == NULL)
+    throw new java::lang::ClassNotFoundException (className);
+
+  if (initialize)
     _Jv_InitClass (klass);
-  else
-    JvThrow (new java::lang::ClassNotFoundException (className));
 
   return klass;
 }
@@ -101,20 +93,77 @@ java::lang::Class::forName (jstring className, java::lang::ClassLoader *loader)
 jclass
 java::lang::Class::forName (jstring className)
 {
-  // FIXME: should use class loader from calling method.
-  return forName (className, NULL);
+  java::lang::ClassLoader *loader = NULL;
+  gnu::gcj::runtime::StackTrace *t 
+    = new gnu::gcj::runtime::StackTrace(4);
+  java::lang::Class *klass = NULL;
+  try
+    {
+      for (int i = 1; !klass; i++)
+       {
+         klass = t->classAt (i);
+       }
+      loader = klass->getClassLoaderInternal();
+    }
+  catch (::java::lang::ArrayIndexOutOfBoundsException *e)
+    {
+    }
+
+  return forName (className, true, loader);
+}
+
+java::lang::ClassLoader *
+java::lang::Class::getClassLoader (void)
+{
+  java::lang::SecurityManager *s = java::lang::System::getSecurityManager();
+  if (s != NULL)
+    {
+      gnu::gcj::runtime::StackTrace *t 
+       = new gnu::gcj::runtime::StackTrace(4);
+      Class *caller = NULL;
+      ClassLoader *caller_loader = NULL;
+      try
+       {
+         for (int i = 1; !caller; i++)
+           {
+             caller = t->classAt (i);
+           }
+         caller_loader = caller->getClassLoaderInternal();
+       }
+      catch (::java::lang::ArrayIndexOutOfBoundsException *e)
+       {
+       }
+
+      // If the caller has a non-null class loader, and that loader
+      // is not this class' loader or an ancestor thereof, then do a
+      // security check.
+      if (caller_loader != NULL && ! caller_loader->isAncestorOf(loader))
+       s->checkPermission (new RuntimePermission (JvNewStringLatin1 ("getClassLoader")));
+    }
+
+  // The spec requires us to return `null' for primitive classes.  In
+  // other cases we have the option of returning `null' for classes
+  // loaded with the bootstrap loader.  All gcj-compiled classes which
+  // are linked into the application used to return `null' here, but
+  // that confuses some poorly-written applications.  It is a useful
+  // and apparently harmless compatibility hack to simply never return
+  // `null' instead.
+  if (isPrimitive ())
+    return NULL;
+  return loader ? loader : ClassLoader::getSystemClassLoader ();
 }
 
 java::lang::reflect::Constructor *
 java::lang::Class::getConstructor (JArray<jclass> *param_types)
 {
+  memberAccessCheck(java::lang::reflect::Member::PUBLIC);
+
   jstring partial_sig = getSignature (param_types, true);
   jint hash = partial_sig->hashCode ();
 
   int i = isPrimitive () ? 0 : method_count;
   while (--i >= 0)
     {
-      // FIXME: access checks.
       if (_Jv_equalUtf8Consts (methods[i].name, init_name)
          && _Jv_equal (methods[i].signature, partial_sig, hash))
        {
@@ -129,13 +178,13 @@ java::lang::Class::getConstructor (JArray<jclass> *param_types)
          return cons;
        }
     }
-  JvThrow (new java::lang::NoSuchMethodException);
+  throw new java::lang::NoSuchMethodException (_Jv_NewStringUtf8Const (init_name));
 }
 
 JArray<java::lang::reflect::Constructor *> *
 java::lang::Class::_getConstructors (jboolean declared)
 {
-  // FIXME: this method needs access checks.
+  memberAccessCheck(java::lang::reflect::Member::PUBLIC);
 
   int numConstructors = 0;
   int max = isPrimitive () ? 0 : method_count;
@@ -153,7 +202,9 @@ java::lang::Class::_getConstructors (jboolean declared)
     }
   JArray<java::lang::reflect::Constructor *> *result
     = (JArray<java::lang::reflect::Constructor *> *)
-    JvNewObjectArray (numConstructors, &ConstructorClass, NULL);
+    JvNewObjectArray (numConstructors,
+                     &java::lang::reflect::Constructor::class$,
+                     NULL);
   java::lang::reflect::Constructor** cptr = elements (result);
   for (i = 0;  i < max;  i++)
     {
@@ -176,13 +227,14 @@ java::lang::Class::_getConstructors (jboolean declared)
 java::lang::reflect::Constructor *
 java::lang::Class::getDeclaredConstructor (JArray<jclass> *param_types)
 {
+  memberAccessCheck(java::lang::reflect::Member::DECLARED);
+
   jstring partial_sig = getSignature (param_types, true);
   jint hash = partial_sig->hashCode ();
 
   int i = isPrimitive () ? 0 : method_count;
   while (--i >= 0)
     {
-      // FIXME: access checks.
       if (_Jv_equalUtf8Consts (methods[i].name, init_name)
          && _Jv_equal (methods[i].signature, partial_sig, hash))
        {
@@ -194,7 +246,7 @@ java::lang::Class::getDeclaredConstructor (JArray<jclass> *param_types)
          return cons;
        }
     }
-  JvThrow (new java::lang::NoSuchMethodException);
+  throw new java::lang::NoSuchMethodException (_Jv_NewStringUtf8Const (init_name));
 }
 
 java::lang::reflect::Field *
@@ -226,9 +278,7 @@ java::lang::Class::getField (jstring name, jint hash)
 java::lang::reflect::Field *
 java::lang::Class::getDeclaredField (jstring name)
 {
-  java::lang::SecurityManager *s = java::lang::System::getSecurityManager();
-  if (s != NULL)
-    s->checkMemberAccess (this, java::lang::reflect::Member::DECLARED);
+  memberAccessCheck(java::lang::reflect::Member::DECLARED);
   int hash = name->hashCode();
   for (int i = 0;  i < field_count;  i++)
     {
@@ -241,18 +291,16 @@ java::lang::Class::getDeclaredField (jstring name)
       rfield->name = name;
       return rfield;
     }
-  JvThrow (new java::lang::NoSuchFieldException (name));
+  throw new java::lang::NoSuchFieldException (name);
 }
 
 JArray<java::lang::reflect::Field *> *
 java::lang::Class::getDeclaredFields (void)
 {
-  java::lang::SecurityManager *s = java::lang::System::getSecurityManager();
-  if (s != NULL)
-    s->checkMemberAccess (this, java::lang::reflect::Member::DECLARED);
+  memberAccessCheck(java::lang::reflect::Member::DECLARED);
   JArray<java::lang::reflect::Field *> *result
     = (JArray<java::lang::reflect::Field *> *)
-    JvNewObjectArray (field_count, &FieldClass, NULL);
+    JvNewObjectArray (field_count, &java::lang::reflect::Field::class$, NULL);
   java::lang::reflect::Field** fptr = elements (result);
   for (int i = 0;  i < field_count;  i++)
     {
@@ -289,9 +337,13 @@ java::lang::Class::getSignature (JArray<jclass> *param_types,
 {
   java::lang::StringBuffer *buf = new java::lang::StringBuffer ();
   buf->append((jchar) '(');
-  jclass *v = elements (param_types);
-  for (int i = 0; i < param_types->length; ++i)
-    v[i]->getSignature(buf);
+  // A NULL param_types means "no parameters".
+  if (param_types != NULL)
+    {
+      jclass *v = elements (param_types);
+      for (int i = 0; i < param_types->length; ++i)
+       v[i]->getSignature(buf);
+    }
   buf->append((jchar) ')');
   if (is_constructor)
     buf->append((jchar) 'V');
@@ -299,8 +351,8 @@ java::lang::Class::getSignature (JArray<jclass> *param_types,
 }
 
 java::lang::reflect::Method *
-java::lang::Class::getDeclaredMethod (jstring name,
-                                     JArray<jclass> *param_types)
+java::lang::Class::_getDeclaredMethod (jstring name,
+                                      JArray<jclass> *param_types)
 {
   jstring partial_sig = getSignature (param_types, false);
   jint p_len = partial_sig->length();
@@ -308,9 +360,10 @@ java::lang::Class::getDeclaredMethod (jstring name,
   int i = isPrimitive () ? 0 : method_count;
   while (--i >= 0)
     {
-      // FIXME: access checks.
       if (_Jv_equalUtf8Consts (methods[i].name, utf_name)
-         && _Jv_equaln (methods[i].signature, partial_sig, p_len))
+         && _Jv_equaln (methods[i].signature, partial_sig, p_len)
+         && (methods[i].accflags
+             & java::lang::reflect::Modifier::INVISIBLE) == 0)
        {
          // Found it.
          using namespace java::lang::reflect;
@@ -320,12 +373,14 @@ java::lang::Class::getDeclaredMethod (jstring name,
          return rmethod;
        }
     }
-  JvThrow (new java::lang::NoSuchMethodException);
+  return NULL;
 }
 
 JArray<java::lang::reflect::Method *> *
 java::lang::Class::getDeclaredMethods (void)
 {
+  memberAccessCheck(java::lang::reflect::Member::DECLARED);
+
   int numMethods = 0;
   int max = isPrimitive () ? 0 : method_count;
   int i;
@@ -336,14 +391,14 @@ java::lang::Class::getDeclaredMethods (void)
          || _Jv_equalUtf8Consts (method->name, clinit_name)
          || _Jv_equalUtf8Consts (method->name, init_name)
          || _Jv_equalUtf8Consts (method->name, finit_name)
-         // Backward compatibility hack: match the legacy `$finit$' name
-         || _Jv_equalUtf8Consts (method->name, finit_leg_name))
+         || (methods[i].accflags
+             & java::lang::reflect::Modifier::INVISIBLE) != 0)
        continue;
       numMethods++;
     }
   JArray<java::lang::reflect::Method *> *result
     = (JArray<java::lang::reflect::Method *> *)
-    JvNewObjectArray (numMethods, &MethodClass, NULL);
+    JvNewObjectArray (numMethods, &java::lang::reflect::Method::class$, NULL);
   java::lang::reflect::Method** mptr = elements (result);
   for (i = 0;  i < max;  i++)
     {
@@ -352,8 +407,8 @@ java::lang::Class::getDeclaredMethods (void)
          || _Jv_equalUtf8Consts (method->name, clinit_name)
          || _Jv_equalUtf8Consts (method->name, init_name)
          || _Jv_equalUtf8Consts (method->name, finit_name)
-         // Backward compatibility hack: match the legacy `$finit$' name
-         || _Jv_equalUtf8Consts (method->name, finit_leg_name))
+         || (methods[i].accflags
+             & java::lang::reflect::Modifier::INVISIBLE) != 0)
        continue;
       java::lang::reflect::Method* rmethod
        = new java::lang::reflect::Method ();
@@ -376,21 +431,25 @@ java::lang::Class::getName (void)
 JArray<jclass> *
 java::lang::Class::getClasses (void)
 {
+  // FIXME: security checking.
+
   // Until we have inner classes, it always makes sense to return an
   // empty array.
   JArray<jclass> *result
-    = (JArray<jclass> *) JvNewObjectArray (0, &ClassClass, NULL);
+    = (JArray<jclass> *) JvNewObjectArray (0, &java::lang::Class::class$,
+                                          NULL);
   return result;
 }
 
 JArray<jclass> *
 java::lang::Class::getDeclaredClasses (void)
 {
-  checkMemberAccess (java::lang::reflect::Member::DECLARED);
+  memberAccessCheck (java::lang::reflect::Member::DECLARED);
   // Until we have inner classes, it always makes sense to return an
   // empty array.
   JArray<jclass> *result
-    = (JArray<jclass> *) JvNewObjectArray (0, &ClassClass, NULL);
+    = (JArray<jclass> *) JvNewObjectArray (0, &java::lang::Class::class$,
+                                          NULL);
   return result;
 }
 
@@ -421,7 +480,7 @@ java::lang::Class::_getFields (JArray<java::lang::reflect::Field *> *result,
          rfield->offset = (char *) field - (char *) fields;
          rfield->declaringClass = this;
          rfield->name = _Jv_NewStringUtf8Const (field->name);
-         (elements (result))[offset + i] = rfield;
+         (elements (result))[offset++] = rfield;
        }
     }
   jclass superclass = getSuperclass();
@@ -443,13 +502,13 @@ java::lang::Class::_getFields (JArray<java::lang::reflect::Field *> *result,
 JArray<java::lang::reflect::Field *> *
 java::lang::Class::getFields (void)
 {
-  using namespace java::lang::reflect;
+  memberAccessCheck(java::lang::reflect::Member::PUBLIC);
 
   int count = _getFields (NULL, 0);
 
   JArray<java::lang::reflect::Field *> *result
     = ((JArray<java::lang::reflect::Field *> *)
-       JvNewObjectArray (count, &FieldClass, NULL));
+       JvNewObjectArray (count, &java::lang::reflect::Field::class$, NULL));
 
   _getFields (result, 0);
 
@@ -467,7 +526,7 @@ java::lang::Class::getInterfaces (void)
 }
 
 java::lang::reflect::Method *
-java::lang::Class::getMethod (jstring name, JArray<jclass> *param_types)
+java::lang::Class::_getMethod (jstring name, JArray<jclass> *param_types)
 {
   jstring partial_sig = getSignature (param_types, false);
   jint p_len = partial_sig->length();
@@ -477,9 +536,10 @@ java::lang::Class::getMethod (jstring name, JArray<jclass> *param_types)
       int i = klass->isPrimitive () ? 0 : klass->method_count;
       while (--i >= 0)
        {
-         // FIXME: access checks.
          if (_Jv_equalUtf8Consts (klass->methods[i].name, utf_name)
-             && _Jv_equaln (klass->methods[i].signature, partial_sig, p_len))
+             && _Jv_equaln (klass->methods[i].signature, partial_sig, p_len)
+             && (klass->methods[i].accflags
+                 & java::lang::reflect::Modifier::INVISIBLE) == 0)
            {
              // Found it.
              using namespace java::lang::reflect;
@@ -496,7 +556,21 @@ java::lang::Class::getMethod (jstring name, JArray<jclass> *param_types)
            }
        }
     }
-  JvThrow (new java::lang::NoSuchMethodException);
+
+  // If we haven't found a match, and this class is an interface, then
+  // check all the superinterfaces.
+  if (isInterface())
+    {
+      for (int i = 0; i < interface_count; ++i)
+       {
+         using namespace java::lang::reflect;
+         Method *rmethod = interfaces[i]->_getMethod (name, param_types);
+         if (rmethod != NULL)
+           return rmethod;
+       }
+    }
+
+  return NULL;
 }
 
 // This is a very slow implementation, since it re-scans all the
@@ -517,8 +591,8 @@ java::lang::Class::_getMethods (JArray<java::lang::reflect::Method *> *result,
          || _Jv_equalUtf8Consts (method->name, clinit_name)
          || _Jv_equalUtf8Consts (method->name, init_name)
          || _Jv_equalUtf8Consts (method->name, finit_name)
-         // Backward compatibility hack: match the legacy `$finit$' name
-         || _Jv_equalUtf8Consts (method->name, finit_leg_name))
+         || (method->accflags
+             & java::lang::reflect::Modifier::INVISIBLE) != 0)
        continue;
       // Only want public methods.
       if (! java::lang::reflect::Modifier::isPublic (method->accflags))
@@ -585,13 +659,15 @@ java::lang::Class::getMethods (void)
 {
   using namespace java::lang::reflect;
 
-  // FIXME: security checks.
+  memberAccessCheck(Member::PUBLIC);
 
   // This will overestimate the size we need.
   jint count = _getMethods (NULL, 0);
 
   JArray<Method *> *result
-    = ((JArray<Method *> *) JvNewObjectArray (count, &MethodClass, NULL));
+    = ((JArray<Method *> *) JvNewObjectArray (count,
+                                             &Method::class$,
+                                             NULL));
 
   // When filling the array for real, we get the actual count.  Then
   // we resize the array.
@@ -600,7 +676,8 @@ java::lang::Class::getMethods (void)
   if (real_count != count)
     {
       JArray<Method *> *r2
-       = ((JArray<Method *> *) JvNewObjectArray (real_count, &MethodClass,
+       = ((JArray<Method *> *) JvNewObjectArray (real_count,
+                                                 &Method::class$,
                                                  NULL));
       
       Method **destp = elements (r2);
@@ -615,7 +692,7 @@ java::lang::Class::getMethods (void)
   return result;
 }
 
-inline jboolean
+jboolean
 java::lang::Class::isAssignableFrom (jclass klass)
 {
   // Arguments may not have been initialized, given ".class" syntax.
@@ -624,42 +701,31 @@ java::lang::Class::isAssignableFrom (jclass klass)
   return _Jv_IsAssignableFrom (this, klass);
 }
 
-inline jboolean
+jboolean
 java::lang::Class::isInstance (jobject obj)
 {
-  if (__builtin_expect (! obj || isPrimitive (), false))
+  if (! obj)
     return false;
   _Jv_InitClass (this);
   return _Jv_IsAssignableFrom (this, JV_CLASS (obj));
 }
 
-inline jboolean
-java::lang::Class::isInterface (void)
-{
-  return (accflags & java::lang::reflect::Modifier::INTERFACE) != 0;
-}
-
 jobject
 java::lang::Class::newInstance (void)
 {
-  // FIXME: do accessibility checks here.  There currently doesn't
-  // seem to be any way to do these.
-  // FIXME: we special-case one check here just to pass a Plum Hall
-  // test.  Once access checking is implemented, remove this.
-  if (this == &ClassClass)
-    JvThrow (new java::lang::IllegalAccessException);
+  memberAccessCheck(java::lang::reflect::Member::PUBLIC);
 
   if (isPrimitive ()
       || isInterface ()
       || isArray ()
       || java::lang::reflect::Modifier::isAbstract(accflags))
-    JvThrow (new java::lang::InstantiationException);
+    throw new java::lang::InstantiationException (getName ());
 
   _Jv_InitClass (this);
 
   _Jv_Method *meth = _Jv_GetMethodLocal (this, init_name, void_signature);
   if (! meth)
-    JvThrow (new java::lang::NoSuchMethodException);
+    throw new java::lang::NoSuchMethodException (_Jv_NewStringUtf8Const (init_name));
 
   jobject r = JvAllocObject (this);
   ((void (*) (jobject)) meth->ncode) (r);
@@ -680,7 +746,7 @@ java::lang::Class::finalize (void)
 void
 java::lang::Class::initializeClass (void)
 {
-  // jshort-circuit to avoid needless locking.
+  // short-circuit to avoid needless locking.
   if (state == JV_STATE_DONE)
     return;
 
@@ -694,7 +760,7 @@ java::lang::Class::initializeClass (void)
        {
          // this can throw exceptions, so exit the monitor as a precaution.
          _Jv_MonitorExit (this);
-         java::lang::ClassLoader::resolveClass0 (this);
+         java::lang::VMClassLoader::resolveClass (this);
          _Jv_MonitorEnter (this);
        }
       else
@@ -703,9 +769,6 @@ java::lang::Class::initializeClass (void)
          _Jv_PrepareCompiledClass (this);
        }
     }
-  
-  if (state <= JV_STATE_LINKED)
-    _Jv_PrepareConstantTimeTables (this);
 
   // Step 2.
   java::lang::Thread *self = java::lang::Thread::currentThread();
@@ -715,17 +778,29 @@ java::lang::Class::initializeClass (void)
     wait ();
 
   // Steps 3 &  4.
-  if (state == JV_STATE_DONE || state == JV_STATE_IN_PROGRESS || thread == self)
+  if (state == JV_STATE_DONE)
     {
       _Jv_MonitorExit (this);
       return;
     }
+  if (state == JV_STATE_IN_PROGRESS)
+    {
+      _Jv_MonitorExit (this);
+
+      /* Initialization in progress.  The class is linked now,
+         so ensure internal tables are built.  */
+      _Jv_PrepareConstantTimeTables (this);
+      _Jv_MakeVTable(this);
+      _Jv_LinkSymbolTable(this);
+
+      return;
+    }
 
   // Step 5.
   if (state == JV_STATE_ERROR)
     {
       _Jv_MonitorExit (this);
-      JvThrow (new java::lang::NoClassDefFoundError);
+      throw new java::lang::NoClassDefFoundError (getName());
     }
 
   // Step 6.
@@ -738,7 +813,7 @@ java::lang::Class::initializeClass (void)
     {
       try
        {
-         superclass->initializeClass ();
+         _Jv_InitClass (superclass);
        }
       catch (java::lang::Throwable *except)
        {
@@ -751,6 +826,14 @@ java::lang::Class::initializeClass (void)
        }
     }
 
+  _Jv_PrepareConstantTimeTables (this);
+
+  if (vtable == NULL)
+    _Jv_MakeVTable(this);
+
+  if (otable || atable)
+    _Jv_LinkSymbolTable(this);
+
   // Steps 8, 9, 10, 11.
   try
     {
@@ -761,7 +844,7 @@ java::lang::Class::initializeClass (void)
     }
   catch (java::lang::Throwable *except)
     {
-      if (! ErrorClass.isInstance(except))
+      if (! java::lang::Error::class$.isInstance(except))
        {
          try
            {
@@ -776,7 +859,7 @@ java::lang::Class::initializeClass (void)
       state = JV_STATE_ERROR;
       notifyAll ();
       _Jv_MonitorExit (this);
-      JvThrow (except);
+      throw except;
     }
 
   _Jv_MonitorEnter (this);
@@ -853,14 +936,14 @@ static void
 _Jv_AddMethodToCache (jclass klass,
                        _Jv_Method *method)
 {
-  _Jv_MonitorEnter (&ClassClass); 
+  _Jv_MonitorEnter (&java::lang::Class::class$); 
 
   int index = method->name->hash & MCACHE_SIZE;
 
   method_cache[index].method = method;
   method_cache[index].klass = klass;
 
-  _Jv_MonitorExit (&ClassClass);
+  _Jv_MonitorExit (&java::lang::Class::class$);
 }
 
 void *
@@ -880,21 +963,20 @@ _Jv_LookupInterfaceMethod (jclass klass, _Jv_Utf8Const *name,
         continue;
 
       if (Modifier::isStatic(meth->accflags))
-       JvThrow (new java::lang::IncompatibleClassChangeError
-                (_Jv_GetMethodString (klass, meth->name)));
+       throw new java::lang::IncompatibleClassChangeError
+         (_Jv_GetMethodString (klass, meth->name));
       if (Modifier::isAbstract(meth->accflags))
-       JvThrow (new java::lang::AbstractMethodError
-                (_Jv_GetMethodString (klass, meth->name)));
+       throw new java::lang::AbstractMethodError
+         (_Jv_GetMethodString (klass, meth->name));
       if (! Modifier::isPublic(meth->accflags))
-       JvThrow (new java::lang::IllegalAccessError
-                (_Jv_GetMethodString (klass, meth->name)));
+       throw new java::lang::IllegalAccessError
+         (_Jv_GetMethodString (klass, meth->name));
 
       _Jv_AddMethodToCache (klass, meth);
 
       return meth->ncode;
     }
-  JvThrow (new java::lang::IncompatibleClassChangeError);
-  return NULL;                 // Placate compiler.
+  throw new java::lang::IncompatibleClassChangeError;
 }
 
 // Fast interface method lookup by index.
@@ -909,19 +991,16 @@ _Jv_LookupInterfaceMethodIdx (jclass klass, jclass iface, int method_idx)
 jboolean
 _Jv_IsAssignableFrom (jclass target, jclass source)
 {
-  if (target == &ObjectClass 
-      || source == target 
-      || (source->ancestors != NULL 
-          && source->ancestors[source->depth - target->depth] == target))
-     return true;
-     
+  if (source == target)
+    return true;
+
   // If target is array, so must source be.  
-  if (target->isArray ())
+  while (target->isArray ())
     {
       if (! source->isArray())
        return false;
-      return _Jv_IsAssignableFrom(target->getComponentType(), 
-                                  source->getComponentType());
+      target = target->getComponentType();
+      source = source->getComponentType();
     }
 
   if (target->isInterface())
@@ -929,25 +1008,49 @@ _Jv_IsAssignableFrom (jclass target, jclass source)
       // Abstract classes have no IDT, and IDTs provide no way to check
       // two interfaces for assignability.
       if (__builtin_expect 
-         (java::lang::reflect::Modifier::isAbstract (source->accflags)
-          || source->isInterface(), false))
+          (source->idt == NULL || source->isInterface(), false))
         return _Jv_InterfaceAssignableFrom (target, source);
-       
+
       _Jv_IDispatchTable *cl_idt = source->idt;
       _Jv_IDispatchTable *if_idt = target->idt;
 
       if (__builtin_expect ((if_idt == NULL), false))
        return false; // No class implementing TARGET has been loaded.    
       jshort cl_iindex = cl_idt->cls.iindex;
-      if (cl_iindex <= if_idt->iface.ioffsets[0])
+      if (cl_iindex < if_idt->iface.ioffsets[0])
         {
          jshort offset = if_idt->iface.ioffsets[cl_iindex];
-         if (offset < cl_idt->cls.itable_length
+         if (offset != -1 && offset < cl_idt->cls.itable_length
              && cl_idt->cls.itable[offset] == target)
            return true;
        }
+      return false;
     }
-    
+
+  // Primitive TYPE classes are only assignable to themselves.
+  if (__builtin_expect (target->isPrimitive() || source->isPrimitive(), false))
+    return false;
+
+  if (target == &java::lang::Object::class$)
+    return true;
+  else if (source->ancestors == NULL || target->ancestors == NULL)
+    {
+      // We need this case when either SOURCE or TARGET has not has
+      // its constant-time tables prepared.
+
+      // At this point we know that TARGET can't be Object, so it is
+      // safe to use that as the termination point.
+      while (source && source != &java::lang::Object::class$)
+       {
+         if (source == target)
+           return true;
+         source = source->getSuperclass();
+       }
+    }
+  else if (source->depth >= target->depth
+          && source->ancestors[source->depth - target->depth] == target)
+    return true;
+
   return false;
 }
 
@@ -986,7 +1089,12 @@ _Jv_CheckCast (jclass c, jobject obj)
 {
   if (__builtin_expect 
        (obj != NULL && ! _Jv_IsAssignableFrom(c, JV_CLASS (obj)), false))
-    JvThrow (new java::lang::ClassCastException);
+    throw new java::lang::ClassCastException
+      ((new java::lang::StringBuffer
+       (obj->getClass()->getName()))->append
+       (JvNewStringUTF(" cannot be cast to "))->append
+       (c->getName())->toString());
+
   return obj;
 }
 
@@ -997,20 +1105,29 @@ _Jv_CheckArrayStore (jobject arr, jobject obj)
     {
       JvAssert (arr != NULL);
       jclass elt_class = (JV_CLASS (arr))->getComponentType();
+      if (elt_class == &java::lang::Object::class$)
+       return;
       jclass obj_class = JV_CLASS (obj);
       if (__builtin_expect 
           (! _Jv_IsAssignableFrom (elt_class, obj_class), false))
-       JvThrow (new java::lang::ArrayStoreException);
+       throw new java::lang::ArrayStoreException
+               ((new java::lang::StringBuffer
+                (JvNewStringUTF("Cannot store ")))->append
+                (obj_class->getName())->append
+                (JvNewStringUTF(" in array of type "))->append
+                (elt_class->getName())->toString());
     }
 }
 
 #define INITIAL_IOFFSETS_LEN 4
 #define INITIAL_IFACES_LEN 4
 
+static _Jv_IDispatchTable null_idt = { {SHRT_MAX, 0, NULL} };
+
 // Generate tables for constant-time assignment testing and interface
 // method lookup. This implements the technique described by Per Bothner
 // <per@bothner.com> on the java-discuss mailing list on 1999-09-02:
-// http://sourceware.cygnus.com/ml/java-discuss/1999-q3/msg00377.html
+// http://gcc.gnu.org/ml/java/1999-q3/msg00377.html
 void 
 _Jv_PrepareConstantTimeTables (jclass klass)
 {  
@@ -1028,8 +1145,10 @@ _Jv_PrepareConstantTimeTables (jclass klass)
   // interfaces or primitive types.
    
   jclass klass0 = klass;
-  while (klass0 != &ObjectClass)
+  jboolean has_interfaces = 0;
+  while (klass0 != &java::lang::Object::class$)
     {
+      has_interfaces += klass0->interface_count;
       klass0 = klass0->superclass;
       klass->depth++;
     }
@@ -1051,6 +1170,14 @@ _Jv_PrepareConstantTimeTables (jclass klass)
     
   if (java::lang::reflect::Modifier::isAbstract (klass->accflags))
     return;
+  
+  // Optimization: If class implements no interfaces, use a common
+  // predefined interface table.
+  if (!has_interfaces)
+    {
+      klass->idt = &null_idt;
+      return;
+    }
 
   klass->idt = 
     (_Jv_IDispatchTable *) _Jv_Malloc (sizeof (_Jv_IDispatchTable));
@@ -1095,7 +1222,7 @@ _Jv_PrepareConstantTimeTables (jclass klass)
 }
 
 // Return index of item in list, or -1 if item is not present.
-jshort
+inline jshort
 _Jv_IndexOf (void *item, void **list, jshort list_len)
 {
   for (int i=0; i < list_len; i++)
@@ -1118,6 +1245,10 @@ _Jv_GetInterfaces (jclass klass, _Jv_ifaces *ifaces)
   for (int i=0; i < klass->interface_count; i++)
     {
       jclass iface = klass->interfaces[i];
+
+      /* Make sure interface is linked.  */
+      _Jv_WaitForState(iface, JV_STATE_LINKED);
+
       if (_Jv_IndexOf (iface, (void **) ifaces->list, ifaces->count) == -1)
         {
          if (ifaces->count + 1 >= ifaces->len)
@@ -1161,8 +1292,7 @@ _Jv_GenerateITable (jclass klass, _Jv_ifaces *ifaces, jshort *itable_offsets)
     { 
       jclass iface = ifaces->list[i];
       itable_offsets[i] = itable_pos;
-      itable_pos = _Jv_AppendPartialITable (klass, iface, itable,
-                   itable_pos);
+      itable_pos = _Jv_AppendPartialITable (klass, iface, itable, itable_pos);
       
       /* Create interface dispatch table for iface */
       if (iface->idt == NULL)
@@ -1195,7 +1325,7 @@ _Jv_GetMethodString (jclass klass, _Jv_Utf8Const *name)
 void 
 _Jv_ThrowNoSuchMethodError ()
 {
-  JvThrow (new java::lang::NoSuchMethodError ());
+  throw new java::lang::NoSuchMethodError;
 }
 
 // Each superinterface of a class (i.e. each interface that the class
@@ -1224,7 +1354,7 @@ _Jv_AppendPartialITable (jclass klass, jclass iface, void **itable,
       for (jclass cl = klass; cl; cl = cl->getSuperclass())
         {
          meth = _Jv_GetMethodLocal (cl, iface->methods[j].name,
-                 iface->methods[j].signature);
+                                    iface->methods[j].signature);
                 
          if (meth)
            break;
@@ -1238,14 +1368,14 @@ _Jv_AppendPartialITable (jclass klass, jclass iface, void **itable,
       else if (meth)
         {
          if (Modifier::isStatic(meth->accflags))
-           JvThrow (new java::lang::IncompatibleClassChangeError
-                    (_Jv_GetMethodString (klass, meth->name)));
+           throw new java::lang::IncompatibleClassChangeError
+             (_Jv_GetMethodString (klass, meth->name));
          if (Modifier::isAbstract(meth->accflags))
-           JvThrow (new java::lang::AbstractMethodError
-                    (_Jv_GetMethodString (klass, meth->name)));
+           throw new java::lang::AbstractMethodError
+             (_Jv_GetMethodString (klass, meth->name));
          if (! Modifier::isPublic(meth->accflags))
-           JvThrow (new java::lang::IllegalAccessError
-                    (_Jv_GetMethodString (klass, meth->name)));
+           throw new java::lang::IllegalAccessError
+             (_Jv_GetMethodString (klass, meth->name));
 
          itable[pos] = meth->ncode;
        }
@@ -1263,7 +1393,7 @@ _Jv_AppendPartialITable (jclass klass, jclass iface, void **itable,
 }
 
 static _Jv_Mutex_t iindex_mutex;
-bool iindex_mutex_initialized = false;
+static bool iindex_mutex_initialized = false;
 
 // We need to find the correct offset in the Class Interface Dispatch 
 // Table for a given interface. Once we have that, invoking an interface 
@@ -1305,7 +1435,7 @@ _Jv_FindIIndex (jclass *ifaces, jshort *offsets, jshort num)
         {
          if (j >= num)
            goto found;
-         if (i > ifaces[j]->idt->iface.ioffsets[0])
+         if (i >= ifaces[j]->idt->iface.ioffsets[0])
            continue;
          int ioffset = ifaces[j]->idt->iface.ioffsets[i];
          /* We can potentially share this position with another class. */
@@ -1380,7 +1510,6 @@ java::lang::Class::getPrivateMethod (jstring name, JArray<jclass> *param_types)
       int i = klass->isPrimitive () ? 0 : klass->method_count;
       while (--i >= 0)
        {
-         // FIXME: access checks.
          if (_Jv_equalUtf8Consts (klass->methods[i].name, utf_name)
              && _Jv_equaln (klass->methods[i].signature, partial_sig, p_len))
            {
@@ -1395,6 +1524,433 @@ java::lang::Class::getPrivateMethod (jstring name, JArray<jclass> *param_types)
            }
        }
     }
-  JvThrow (new java::lang::NoSuchMethodException);
+  throw new java::lang::NoSuchMethodException (name);
+}
+
+// Private accessor method for Java code to retrieve the protection domain.
+java::security::ProtectionDomain *
+java::lang::Class::getProtectionDomain0 ()
+{
+  return protectionDomain;
+}
+
+JArray<jobject> *
+java::lang::Class::getSigners()
+{
+  return signers;
 }
 
+void
+java::lang::Class::setSigners(JArray<jobject> *s)
+{
+  signers = s;
+}
+
+// Functions for indirect dispatch (symbolic virtual binding) support.
+
+// There are two tables, atable and otable.  atable is an array of
+// addresses, and otable is an array of offsets, and these are used
+// for static and virtual members respectively.
+
+// {a,o}table_syms is an array of _Jv_MethodSymbols.  Each such symbol
+// is a tuple of {classname, member name, signature}.
+// _Jv_LinkSymbolTable() scans these two arrays and fills in the
+// corresponding atable and otable with the addresses of static
+// members and the offsets of virtual members.
+
+// The offset (in bytes) for each resolved method or field is placed
+// at the corresponding position in the virtual method offset table
+// (klass->otable). 
+
+// The same otable and atable may be shared by many classes.
+
+void
+_Jv_LinkSymbolTable(jclass klass)
+{
+  //// FIXME: Need to lock the tables ////
+  
+  int index = 0;
+  _Jv_MethodSymbol sym;
+  if (klass->otable == NULL
+      || klass->otable->state != 0)
+    goto atable;
+   
+  klass->otable->state = 1;
+
+  for (index = 0; sym = klass->otable_syms[index], sym.name != NULL; index++)
+    {
+      jclass target_class = _Jv_FindClass (sym.class_name, NULL);
+      _Jv_Method *meth = NULL;            
+
+      const _Jv_Utf8Const *signature = sym.signature;
+
+      // FIXME: This should be special index for ThrowNoSuchMethod().
+      klass->otable->offsets[index] = -1;
+      
+      if (target_class == NULL)
+       continue;
+
+      if (target_class->isInterface())
+       {
+         // FIXME: This does not yet fully conform to binary compatibility
+         // rules. It will break if a declaration is moved into a 
+         // superinterface.
+         for (jclass cls = target_class; cls != 0; cls = cls->getSuperclass ())
+           {
+             for (int i=0; i < cls->method_count; i++)
+               {
+                 meth = &cls->methods[i];
+                 if (_Jv_equalUtf8Consts (sym.name, meth->name)
+                     && _Jv_equalUtf8Consts (signature, meth->signature))
+                   {
+                     klass->otable->offsets[index] = i + 1;
+                     goto found;
+                   }
+               }
+           
+           }
+       found:
+         continue;
+       }
+
+      // We're looking for a field or a method, and we can tell
+      // which is needed by looking at the signature.
+      if (signature->length >= 2
+         && signature->data[0] == '(')
+       {
+         // If the target class does not have a vtable_method_count yet, 
+         // then we can't tell the offsets for its methods, so we must lay 
+         // it out now.
+         if (target_class->vtable_method_count == -1)
+           {
+             JvSynchronize sync (target_class);
+             _Jv_LayoutVTableMethods (target_class);
+           }
+               
+         meth = _Jv_LookupDeclaredMethod(target_class, sym.name, 
+                                         sym.signature);
+               
+         if (meth != NULL)
+           {
+             klass->otable->offsets[index] = 
+               _Jv_VTable::idx_to_offset (meth->index);              
+           }
+
+         continue;
+       }
+
+      // try fields
+      {
+       _Jv_Field *the_field = NULL;
+
+       for (jclass cls = target_class; cls != 0; cls = cls->getSuperclass ())
+         {
+           for (int i = 0; i < cls->field_count; i++)
+             {
+               _Jv_Field *field = &cls->fields[i];
+               if (! _Jv_equalUtf8Consts (field->name, sym.name))
+                 continue;
+
+               // FIXME: What access checks should we perform here?
+//             if (_Jv_CheckAccess (klass, cls, field->flags))
+//               {
+
+               if (!field->isResolved ())
+                 _Jv_ResolveField (field, cls->loader);
+
+//             if (field_type != 0 && field->type != field_type)
+//               throw new java::lang::LinkageError
+//                 (JvNewStringLatin1 
+//                  ("field type mismatch with different loaders"));
+
+               the_field = field;
+               goto end_of_field_search;
+             }
+         }
+      end_of_field_search:
+       if (the_field != NULL)
+         {
+           if (the_field->flags & 0x0008 /* Modifier::STATIC */)
+             {       
+               throw new java::lang::IncompatibleClassChangeError;
+             }
+           else
+             {
+               klass->otable->offsets[index] = the_field->u.boffset;
+             }
+         }
+       else
+         {
+           throw new java::lang::NoSuchFieldError
+             (_Jv_NewStringUtf8Const (sym.name));
+         }
+      }
+    }
+
+ atable:
+  if (klass->atable == NULL
+      || klass->atable->state != 0)
+    return;
+
+  klass->atable->state = 1;
+
+  for (index = 0; sym = klass->atable_syms[index], sym.name != NULL; index++)
+    {
+      jclass target_class = _Jv_FindClass (sym.class_name, NULL);
+      _Jv_Method *meth = NULL;            
+      const _Jv_Utf8Const *signature = sym.signature;
+
+      // ??? Setting this pointer to null will at least get us a
+      // NullPointerException
+      klass->atable->addresses[index] = NULL;
+      
+      if (target_class == NULL)
+       continue;
+      
+      // We're looking for a static field or a static method, and we
+      // can tell which is needed by looking at the signature.
+      if (signature->length >= 2
+         && signature->data[0] == '(')
+       {
+         // If the target class does not have a vtable_method_count yet, 
+         // then we can't tell the offsets for its methods, so we must lay 
+         // it out now.
+         if (target_class->vtable_method_count == -1)
+           {
+             JvSynchronize sync (target_class);
+             _Jv_LayoutVTableMethods (target_class);
+           }
+         
+         meth = _Jv_LookupDeclaredMethod(target_class, sym.name, 
+                                         sym.signature);
+         
+         if (meth != NULL)
+           klass->atable->addresses[index] = meth->ncode;
+         else
+           klass->atable->addresses[index] = (void *)_Jv_ThrowNoSuchMethodError;
+
+         continue;
+       }
+
+      // try fields
+      {
+       _Jv_Field *the_field = NULL;
+
+       for (jclass cls = target_class; cls != 0; cls = cls->getSuperclass ())
+         {
+           for (int i = 0; i < cls->field_count; i++)
+             {
+               _Jv_Field *field = &cls->fields[i];
+               if (! _Jv_equalUtf8Consts (field->name, sym.name))
+                 continue;
+
+               // FIXME: What access checks should we perform here?
+//             if (_Jv_CheckAccess (klass, cls, field->flags))
+//               {
+
+               if (!field->isResolved ())
+                 _Jv_ResolveField (field, cls->loader);
+               
+//             if (field_type != 0 && field->type != field_type)
+//               throw new java::lang::LinkageError
+//                 (JvNewStringLatin1 
+//                  ("field type mismatch with different loaders"));
+
+               the_field = field;
+               goto end_of_static_field_search;
+             }
+         }
+      end_of_static_field_search:
+       if (the_field != NULL)
+         {
+           if (the_field->flags & 0x0008 /* Modifier::STATIC */)
+             {       
+               klass->atable->addresses[index] = the_field->u.addr;
+             }
+           else
+             {
+               throw new java::lang::IncompatibleClassChangeError;
+             }
+         }
+       else
+         {
+           throw new java::lang::NoSuchFieldError
+             (_Jv_NewStringUtf8Const (sym.name));
+         }
+      }
+    }
+}
+
+// Returns true if METH should get an entry in a VTable.
+static jboolean
+isVirtualMethod (_Jv_Method *meth)
+{
+  using namespace java::lang::reflect;
+  return (((meth->accflags & (Modifier::STATIC | Modifier::PRIVATE)) == 0)
+          && meth->name->data[0] != '<');
+}
+
+// This is put in empty vtable slots.
+static void
+_Jv_abstractMethodError (void)
+{
+  throw new java::lang::AbstractMethodError();
+}
+
+// Prepare virtual method declarations in KLASS, and any superclasses as 
+// required, by determining their vtable index, setting method->index, and
+// finally setting the class's vtable_method_count. Must be called with the
+// lock for KLASS held.
+void
+_Jv_LayoutVTableMethods (jclass klass)
+{
+  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 (superclass != NULL)
+       {
+         super_meth = _Jv_LookupDeclaredMethod (superclass, meth->name, 
+                                                meth->signature);
+       }
+
+      if (super_meth)
+        meth->index = super_meth->index;
+      else if (! (meth->accflags & java::lang::reflect::Modifier::FINAL)
+              && ! (klass->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, recursively do its methods
+// first.  FLAGS is used to determine which slots we've actually set.
+void
+_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, flags);
+
+  for (int i = klass->method_count - 1; i >= 0; i--)
+    {
+      _Jv_Method *meth = &klass->methods[i];
+      if (meth->index == (_Jv_ushort) -1)
+       continue;
+      if ((meth->accflags & Modifier::ABSTRACT))
+       {
+         vtable->set_method(meth->index, (void *) &_Jv_abstractMethodError);
+         flags[meth->index] = false;
+       }
+      else
+       {
+         vtable->set_method(meth->index, meth->ncode);
+         flags[meth->index] = true;
+       }
+    }
+}
+
+// Allocate and lay out the virtual method table for KLASS. This will also
+// cause vtables to be generated for any non-abstract superclasses, and
+// virtual method layout to occur for any abstract superclasses. Must be
+// called with monitor lock for KLASS held.
+void
+_Jv_MakeVTable (jclass klass)
+{
+  using namespace java::lang::reflect;  
+
+  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)
+    {
+      while ((superclass->accflags & Modifier::ABSTRACT) != 0)
+       superclass = superclass->superclass;
+
+      if (superclass->vtable == NULL)
+       {
+         JvSynchronize sync (superclass);
+         _Jv_MakeVTable (superclass);
+       }
+
+      for (int i = 0; i < superclass->vtable_method_count; ++i)
+       {
+         vtable->set_method (i, superclass->vtable->get_method (i));
+         flags[i] = true;
+       }
+    }
+
+  // Set the class pointer and GC descriptor.
+  vtable->clas = klass;
+  vtable->gc_descr = _Jv_BuildGCDescr (klass);
+
+  // For each virtual declared in klass and any immediate abstract 
+  // superclasses, set new vtable entry or override an old one.
+  _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])
+         {
+           using namespace java::lang;
+           while (klass != NULL)
+             {
+               for (int j = 0; j < klass->method_count; ++j)
+                 {
+                   if (klass->methods[i].index == i)
+                     {
+                       StringBuffer *buf = new StringBuffer ();
+                       buf->append (_Jv_NewStringUtf8Const (klass->methods[i].name));
+                       buf->append ((jchar) ' ');
+                       buf->append (_Jv_NewStringUtf8Const (klass->methods[i].signature));
+                       throw new AbstractMethodError (buf->toString ());
+                     }
+                 }
+               klass = klass->getSuperclass ();
+             }
+           // Couldn't find the name, which is weird.
+           // But we still must throw the error.
+           throw new AbstractMethodError ();
+         }
+    }
+}