defineclass.cc (handleMethodsBegin): Allocate _Jv_MethodBase pointers.

* defineclass.cc (handleMethodsBegin): Allocate _Jv_MethodBase
	pointers.
	(handleMethodsEnd): Fixed error messages.  Create a _Jv_JNIMethod
	if the method is native.
	* resolve.cc (ncode): Don't handle native methods.
	(_Jv_JNIMethod::ncode): New method.
	(_Jv_PrepareClass): Handle native methods.
	* jni.cc (call): Renamed from _Jv_JNI_conversion_call.
	Include AbstractMethodError.h.
	(add_char): New function.
	(mangled_name): Likewise.
	* include/java-interp.h (class _Jv_JNIMethod): New class.
	(class _Jv_MethodBase): New class.
	(class _Jv_InterpMethod): Derive from _Jv_MethodBase.
	(_Jv_InterpClass): Changed `interpreted_methods' field to type
	`_Jv_MethodBase'.

	* include/jvm.h (_Jv_FindSymbolInExecutable): Declare.
	* java/lang/natRuntime.cc (libraries_size, libraries_count,
	libraries): New globals.
	(add_library): New function.
	(_Jv_FindSymbolInExecutable): New function.

	* java/lang/natClassLoader.cc (initiated_classes, loaded_classes):
	Now static.

From-SVN: r31790
This commit is contained in:
Tom Tromey 2000-02-04 20:49:27 +00:00 committed by Tom Tromey
parent a89608cbeb
commit facc279fc1
8 changed files with 312 additions and 58 deletions

View file

@ -563,21 +563,21 @@ _Jv_PrepareClass(jclass klass)
have code -- for static constructors. */
for (int i = 0; i < clz->method_count; i++)
{
_Jv_InterpMethod *imeth = clz->interpreted_methods[i];
_Jv_MethodBase *imeth = clz->interpreted_methods[i];
if (imeth != 0) // it could be abstract or native
if ((clz->methods[i].accflags & Modifier::NATIVE) != 0)
{
clz->methods[i].ncode = imeth->ncode ();
// You might think we could use a virtual `ncode' method in
// the _Jv_MethodBase and unify the native and non-native
// cases. Well, we can't, because we don't allocate these
// objects using `new', and thus they don't get a vtable.
_Jv_JNIMethod *jnim = reinterpret_cast<_Jv_JNIMethod *> (imeth);
clz->methods[i].ncode = jnim->ncode ();
}
else
else if (imeth != 0) // it could be abstract
{
if ((clz->methods[i].accflags & Modifier::NATIVE) != 0)
{
JvThrow
(new java::lang::VirtualMachineError
(JvNewStringLatin1
("the interpreter does not support native methods")));
}
_Jv_InterpMethod *im = reinterpret_cast<_Jv_InterpMethod *> (im);
clz->methods[i].ncode = im->ncode ();
}
}
@ -588,13 +588,6 @@ _Jv_PrepareClass(jclass klass)
return;
}
/* FIXME: native methods for interpreted classes should be handled, I
* dunno exactly how, but it seems that we should try to find them at
* this point, and if we fail, try again after <clinit>, since it
* could have caused additional code to be loaded. Interfaces cannot
* have native methods (not even for static initialization). */
/* Now onto the actual job: vtable layout. First, count how many new
methods we have */
int new_method_count = 0;
@ -1022,13 +1015,9 @@ _Jv_InterpMethod::ncode ()
args_raw_size = ffi_raw_size (&closure->cif);
if ((self->accflags & Modifier::NATIVE) != 0)
{
// FIXME: for now we assume that all native methods for
// interpreted code use JNI.
fun = (ffi_closure_fun) &_Jv_JNI_conversion_call;
}
else if ((self->accflags & Modifier::SYNCHRONIZED) != 0)
JvAssert ((self->accflags & Modifier::NATIVE) == 0);
if ((self->accflags & Modifier::SYNCHRONIZED) != 0)
{
if (staticp)
fun = (ffi_closure_fun)&_Jv_InterpMethod::run_synch_class;
@ -1041,9 +1030,48 @@ _Jv_InterpMethod::ncode ()
}
ffi_prep_raw_closure (&closure->closure,
&closure->cif,
fun,
(void*)this);
&closure->cif,
fun,
(void*) this);
self->ncode = (void*)closure;
return self->ncode;
}
void *
_Jv_JNIMethod::ncode ()
{
using namespace java::lang::reflect;
if (self->ncode != 0)
return self->ncode;
jboolean staticp = (self->accflags & Modifier::STATIC) != 0;
int arg_count = count_arguments (self->signature, staticp);
ncode_closure *closure =
(ncode_closure*)_Jv_AllocBytesChecked (sizeof (ncode_closure)
+ arg_count * sizeof (ffi_type*));
init_cif (self->signature,
arg_count,
staticp,
&closure->cif,
&closure->arg_types[0]);
ffi_closure_fun fun;
JvAssert ((self->accflags & Modifier::NATIVE) != 0);
// FIXME: for now we assume that all native methods for
// interpreted code use JNI.
fun = (ffi_closure_fun) &_Jv_JNIMethod::call;
ffi_prep_raw_closure (&closure->closure,
&closure->cif,
fun,
(void*) this);
self->ncode = (void*)closure;
return self->ncode;