Commit 68940f3f by Tom Tromey Committed by Tom Tromey

For PR java/5088:

	* java/lang/natClassLoader.cc (_Jv_InitNewClassFields): New
	function.
	(_Jv_NewClass): Use it.
	(defineClass0): Use it.
	* prims.cc (_Jv_InitPrimClass): Adjust vtable here.
	(_Jv_InitPrimClass): Use _Jv_InitNewClassFields.
	(_Jv_NewArray): Don't abort; just throw exception.
	Include InternalError.h.
	* java/lang/Class.h (Class::Class): Declare, don't define.
	(Class): Declare _Jv_InitNewClassFields as a friend.
	(union _Jv_Self): Removed.

From-SVN: r48081
parent 495513ee
2001-12-16 Tom Tromey <tromey@redhat.com> 2001-12-16 Tom Tromey <tromey@redhat.com>
For PR java/5088:
* java/lang/natClassLoader.cc (_Jv_InitNewClassFields): New
function.
(_Jv_NewClass): Use it.
(defineClass0): Use it.
* prims.cc (_Jv_InitPrimClass): Adjust vtable here.
(_Jv_InitPrimClass): Use _Jv_InitNewClassFields.
(_Jv_NewArray): Don't abort; just throw exception.
Include InternalError.h.
* java/lang/Class.h (Class::Class): Declare, don't define.
(Class): Declare _Jv_InitNewClassFields as a friend.
(union _Jv_Self): Removed.
* Makefile.in: Rebuilt. * Makefile.in: Rebuilt.
* Makefile.am (ordinary_java_source_files): Removed old file; * Makefile.am (ordinary_java_source_files): Removed old file;
added new file. added new file.
......
...@@ -109,13 +109,6 @@ struct _Jv_ifaces ...@@ -109,13 +109,6 @@ struct _Jv_ifaces
jshort count; jshort count;
}; };
// Used for vtable pointer manipulation.
union _Jv_Self
{
char *vtable_ptr;
jclass self;
};
struct _Jv_MethodSymbol struct _Jv_MethodSymbol
{ {
_Jv_Utf8Const *class_name; _Jv_Utf8Const *class_name;
...@@ -232,12 +225,7 @@ public: ...@@ -232,12 +225,7 @@ public:
// This constructor is used to create Class object for the primitive // This constructor is used to create Class object for the primitive
// types. See prims.cc. // types. See prims.cc.
Class () Class ();
{
// C++ ctors set the vtbl pointer to point at an offset inside the vtable
// object. That doesn't work for Java, so this hack adjusts it back.
((_Jv_Self *)this)->vtable_ptr -= 2 * sizeof (void *);
}
static java::lang::Class class$; static java::lang::Class class$;
...@@ -307,6 +295,7 @@ private: ...@@ -307,6 +295,7 @@ private:
_Jv_VTable *array_vtable = 0); _Jv_VTable *array_vtable = 0);
friend jclass _Jv_NewClass (_Jv_Utf8Const *name, jclass superclass, friend jclass _Jv_NewClass (_Jv_Utf8Const *name, jclass superclass,
java::lang::ClassLoader *loader); java::lang::ClassLoader *loader);
friend void _Jv_InitNewClassFields (jclass klass);
// in prims.cc // in prims.cc
friend void _Jv_InitPrimClass (jclass, char *, char, int, _Jv_ArrayVTable *); friend void _Jv_InitPrimClass (jclass, char *, char, int, _Jv_ArrayVTable *);
......
...@@ -61,6 +61,7 @@ java::lang::ClassLoader::defineClass0 (jstring name, ...@@ -61,6 +61,7 @@ java::lang::ClassLoader::defineClass0 (jstring name,
#ifdef INTERPRETER #ifdef INTERPRETER
jclass klass; jclass klass;
klass = (jclass) JvAllocObject (&ClassClass, sizeof (_Jv_InterpClass)); klass = (jclass) JvAllocObject (&ClassClass, sizeof (_Jv_InterpClass));
_Jv_InitNewClassFields (klass);
// synchronize on the class, so that it is not // synchronize on the class, so that it is not
// attempted initialized until we're done loading. // attempted initialized until we're done loading.
...@@ -549,16 +550,13 @@ _Jv_FindClass (_Jv_Utf8Const *name, java::lang::ClassLoader *loader) ...@@ -549,16 +550,13 @@ _Jv_FindClass (_Jv_Utf8Const *name, java::lang::ClassLoader *loader)
return klass; return klass;
} }
jclass void
_Jv_NewClass (_Jv_Utf8Const *name, jclass superclass, _Jv_InitNewClassFields (jclass ret)
java::lang::ClassLoader *loader)
{ {
jclass ret = (jclass) JvAllocObject (&ClassClass);
ret->next = NULL; ret->next = NULL;
ret->name = name; ret->name = NULL;
ret->accflags = 0; ret->accflags = 0;
ret->superclass = superclass; ret->superclass = NULL;
ret->constants.size = 0; ret->constants.size = 0;
ret->constants.tags = NULL; ret->constants.tags = NULL;
ret->constants.data = NULL; ret->constants.data = NULL;
...@@ -571,7 +569,7 @@ _Jv_NewClass (_Jv_Utf8Const *name, jclass superclass, ...@@ -571,7 +569,7 @@ _Jv_NewClass (_Jv_Utf8Const *name, jclass superclass,
ret->static_field_count = 0; ret->static_field_count = 0;
ret->vtable = NULL; ret->vtable = NULL;
ret->interfaces = NULL; ret->interfaces = NULL;
ret->loader = loader; ret->loader = NULL;
ret->interface_count = 0; ret->interface_count = 0;
ret->state = JV_STATE_NOTHING; ret->state = JV_STATE_NOTHING;
ret->thread = NULL; ret->thread = NULL;
...@@ -579,6 +577,17 @@ _Jv_NewClass (_Jv_Utf8Const *name, jclass superclass, ...@@ -579,6 +577,17 @@ _Jv_NewClass (_Jv_Utf8Const *name, jclass superclass,
ret->ancestors = NULL; ret->ancestors = NULL;
ret->idt = NULL; ret->idt = NULL;
ret->arrayclass = NULL; ret->arrayclass = NULL;
}
jclass
_Jv_NewClass (_Jv_Utf8Const *name, jclass superclass,
java::lang::ClassLoader *loader)
{
jclass ret = (jclass) JvAllocObject (&ClassClass);
_Jv_InitNewClassFields (ret);
ret->name = name;
ret->superclass = superclass;
ret->loader = loader;
_Jv_RegisterClass (ret); _Jv_RegisterClass (ret);
......
...@@ -56,6 +56,7 @@ details. */ ...@@ -56,6 +56,7 @@ details. */
#include <java/lang/ArrayIndexOutOfBoundsException.h> #include <java/lang/ArrayIndexOutOfBoundsException.h>
#include <java/lang/ArithmeticException.h> #include <java/lang/ArithmeticException.h>
#include <java/lang/ClassFormatError.h> #include <java/lang/ClassFormatError.h>
#include <java/lang/InternalError.h>
#include <java/lang/NegativeArraySizeException.h> #include <java/lang/NegativeArraySizeException.h>
#include <java/lang/NullPointerException.h> #include <java/lang/NullPointerException.h>
#include <java/lang/OutOfMemoryError.h> #include <java/lang/OutOfMemoryError.h>
...@@ -533,8 +534,8 @@ _Jv_NewArray (jint type, jint size) ...@@ -533,8 +534,8 @@ _Jv_NewArray (jint type, jint size)
case 10: return JvNewIntArray (size); case 10: return JvNewIntArray (size);
case 11: return JvNewLongArray (size); case 11: return JvNewLongArray (size);
} }
JvFail ("newarray - bad type code"); throw new java::lang::InternalError
return NULL; // Placate compiler. (JvNewStringLatin1 ("invalid type code in _Jv_NewArray"));
} }
// Allocate a possibly multi-dimensional array but don't check that // Allocate a possibly multi-dimensional array but don't check that
...@@ -613,9 +614,14 @@ _Jv_InitPrimClass (jclass cl, char *cname, char sig, int len, ...@@ -613,9 +614,14 @@ _Jv_InitPrimClass (jclass cl, char *cname, char sig, int len,
{ {
using namespace java::lang::reflect; using namespace java::lang::reflect;
// We must initialize every field of the class. We do this in the _Jv_InitNewClassFields (cl);
// same order they are declared in Class.h, except for fields that
// are initialized to NULL. // We must set the vtable for the class; the Java constructor
// doesn't do this.
(*(_Jv_VTable **) cl) = java::lang::Class::class$.vtable;
// Initialize the fields we care about. We do this in the same
// order they are declared in Class.h.
cl->name = _Jv_makeUtf8Const ((char *) cname, -1); cl->name = _Jv_makeUtf8Const ((char *) cname, -1);
cl->accflags = Modifier::PUBLIC | Modifier::FINAL | Modifier::ABSTRACT; cl->accflags = Modifier::PUBLIC | Modifier::FINAL | Modifier::ABSTRACT;
cl->method_count = sig; cl->method_count = sig;
......
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