Commit 23bc3a89 by Bryce McKinlay Committed by Bryce McKinlay

link.cc (_Jv_Linker::resolve_pool_entry): Don't pass vtable_index to resolve_method.

2006-04-28  Bryce McKinlay  <mckinlay@redhat.com>

	* link.cc (_Jv_Linker::resolve_pool_entry): Don't pass vtable_index
	to resolve_method.
	* interpret.cc (insn_invokevirtual): Use method->index, not
	vtable_index. Check accflag FINAL to determine finals. Only do
	explicit null check if calling a final method. Use
	throw_null_pointer_exception.
	(invokevirtual_resolved): Likewise.
	(null_pointer_exc): Remove static field.
	(throw_null_pointer_exception): Always define. Throw a new
	NullPointerException every time.
	* include/java-interp.h (_Jv_ResolvedMethod): Remove vtable_index
	field.
	* include/execution.h (resolve_method): Remove vtable_index argument.

From-SVN: r113370
parent f6326de6
2006-04-28 Bryce McKinlay <mckinlay@redhat.com>
* link.cc (_Jv_Linker::resolve_pool_entry): Don't pass vtable_index
to resolve_method.
* interpret.cc (insn_invokevirtual): Use method->index, not
vtable_index. Check accflag FINAL to determine finals. Only do
explicit null check if calling a final method. Use
throw_null_pointer_exception.
(invokevirtual_resolved): Likewise.
(null_pointer_exc): Remove static field.
(throw_null_pointer_exception): Always define. Throw a new
NullPointerException every time.
* include/java-interp.h (_Jv_ResolvedMethod): Remove vtable_index
field.
* include/execution.h (resolve_method): Remove vtable_index argument.
2006-04-28 Andreas Tobler <a.tobler@schweiz.ch> 2006-04-28 Andreas Tobler <a.tobler@schweiz.ch>
* configure.ac: Add an additional checks for dladdr and dlopen on dld. * configure.ac: Add an additional checks for dladdr and dlopen on dld.
......
...@@ -26,7 +26,7 @@ struct _Jv_ExecutionEngine ...@@ -26,7 +26,7 @@ struct _Jv_ExecutionEngine
void (*allocate_static_fields) (jclass, int, int); void (*allocate_static_fields) (jclass, int, int);
void (*create_ncode) (jclass); void (*create_ncode) (jclass);
_Jv_ResolvedMethod *(*resolve_method) (_Jv_Method *, jclass, _Jv_ResolvedMethod *(*resolve_method) (_Jv_Method *, jclass,
jboolean, jint); jboolean);
void (*post_miranda_hook) (jclass); void (*post_miranda_hook) (jclass);
}; };
...@@ -50,7 +50,7 @@ struct _Jv_CompiledEngine : public _Jv_ExecutionEngine ...@@ -50,7 +50,7 @@ struct _Jv_CompiledEngine : public _Jv_ExecutionEngine
} }
static _Jv_ResolvedMethod *do_resolve_method (_Jv_Method *, jclass, static _Jv_ResolvedMethod *do_resolve_method (_Jv_Method *, jclass,
jboolean, jint) jboolean)
{ {
return NULL; return NULL;
} }
...@@ -118,7 +118,7 @@ class _Jv_InterpreterEngine : public _Jv_ExecutionEngine ...@@ -118,7 +118,7 @@ class _Jv_InterpreterEngine : public _Jv_ExecutionEngine
static void do_allocate_static_fields (jclass, int, int); static void do_allocate_static_fields (jclass, int, int);
static void do_create_ncode (jclass); static void do_create_ncode (jclass);
static _Jv_ResolvedMethod *do_resolve_method (_Jv_Method *, jclass, static _Jv_ResolvedMethod *do_resolve_method (_Jv_Method *, jclass,
jboolean, jint); jboolean);
static bool do_need_resolve_string_fields () static bool do_need_resolve_string_fields ()
{ {
......
...@@ -243,7 +243,6 @@ _Jv_GetFirstMethod (_Jv_InterpClass *klass) ...@@ -243,7 +243,6 @@ _Jv_GetFirstMethod (_Jv_InterpClass *klass)
struct _Jv_ResolvedMethod struct _Jv_ResolvedMethod
{ {
jint stack_item_count; jint stack_item_count;
jint vtable_index;
jclass klass; jclass klass;
_Jv_Method* method; _Jv_Method* method;
......
...@@ -51,10 +51,8 @@ static void throw_internal_error (const char *msg) ...@@ -51,10 +51,8 @@ static void throw_internal_error (const char *msg)
__attribute__ ((__noreturn__)); __attribute__ ((__noreturn__));
static void throw_incompatible_class_change_error (jstring msg) static void throw_incompatible_class_change_error (jstring msg)
__attribute__ ((__noreturn__)); __attribute__ ((__noreturn__));
#ifndef HANDLE_SEGV
static void throw_null_pointer_exception () static void throw_null_pointer_exception ()
__attribute__ ((__noreturn__)); __attribute__ ((__noreturn__));
#endif
static void throw_class_format_error (jstring msg) static void throw_class_format_error (jstring msg)
__attribute__ ((__noreturn__)); __attribute__ ((__noreturn__));
...@@ -1142,31 +1140,27 @@ _Jv_InterpMethod::run (void *retp, ffi_raw *args, _Jv_InterpMethod *meth) ...@@ -1142,31 +1140,27 @@ _Jv_InterpMethod::run (void *retp, ffi_raw *args, _Jv_InterpMethod *meth)
* the corresponding bit JV_CONSTANT_ResolvedFlag in the tag * the corresponding bit JV_CONSTANT_ResolvedFlag in the tag
* directly. For now, I don't think it is worth it. */ * directly. For now, I don't think it is worth it. */
SAVE_PC();
rmeth = (_Jv_Linker::resolve_pool_entry (meth->defining_class, rmeth = (_Jv_Linker::resolve_pool_entry (meth->defining_class,
index)).rmethod; index)).rmethod;
sp -= rmeth->stack_item_count; sp -= rmeth->stack_item_count;
// We don't use NULLCHECK here because we can't rely on that
// working if the method is final. So instead we do an
// explicit test.
if (! sp[0].o)
{
//printf("invokevirtual pc = %p/%i\n", pc, meth->get_pc_val(pc));
throw new java::lang::NullPointerException;
}
if (rmeth->vtable_index == -1) if (rmeth->method->accflags & Modifier::FINAL)
{ {
// final methods do not appear in the vtable, // We can't rely on NULLCHECK working if the method is final.
// if it does not appear in the superclass. SAVE_PC();
if (! sp[0].o)
throw_null_pointer_exception ();
// Final methods might not appear in the vtable.
fun = (void (*)()) rmeth->method->ncode; fun = (void (*)()) rmeth->method->ncode;
} }
else else
{ {
NULLCHECK (sp[0].o);
jobject rcv = sp[0].o; jobject rcv = sp[0].o;
_Jv_VTable *table = *(_Jv_VTable**) rcv; _Jv_VTable *table = *(_Jv_VTable**) rcv;
fun = (void (*)()) table->get_method (rmeth->vtable_index); fun = (void (*)()) table->get_method (rmeth->method->index);
} }
#ifdef DIRECT_THREADED #ifdef DIRECT_THREADED
...@@ -1183,26 +1177,22 @@ _Jv_InterpMethod::run (void *retp, ffi_raw *args, _Jv_InterpMethod *meth) ...@@ -1183,26 +1177,22 @@ _Jv_InterpMethod::run (void *retp, ffi_raw *args, _Jv_InterpMethod *meth)
{ {
rmeth = (_Jv_ResolvedMethod *) AVAL (); rmeth = (_Jv_ResolvedMethod *) AVAL ();
sp -= rmeth->stack_item_count; sp -= rmeth->stack_item_count;
// We don't use NULLCHECK here because we can't rely on that
// working if the method is final. So instead we do an if (rmeth->method->accflags & Modifier::FINAL)
// explicit test.
if (! sp[0].o)
{ {
// We can't rely on NULLCHECK working if the method is final.
SAVE_PC(); SAVE_PC();
throw new java::lang::NullPointerException; if (! sp[0].o)
} throw_null_pointer_exception ();
if (rmeth->vtable_index == -1) // Final methods might not appear in the vtable.
{
// final methods do not appear in the vtable,
// if it does not appear in the superclass.
fun = (void (*)()) rmeth->method->ncode; fun = (void (*)()) rmeth->method->ncode;
} }
else else
{ {
jobject rcv = sp[0].o; jobject rcv = sp[0].o;
_Jv_VTable *table = *(_Jv_VTable**) rcv; _Jv_VTable *table = *(_Jv_VTable**) rcv;
fun = (void (*)()) table->get_method (rmeth->vtable_index); fun = (void (*)()) table->get_method (rmeth->method->index);
} }
} }
goto perform_invoke; goto perform_invoke;
...@@ -2882,7 +2872,7 @@ _Jv_InterpMethod::run (void *retp, ffi_raw *args, _Jv_InterpMethod *meth) ...@@ -2882,7 +2872,7 @@ _Jv_InterpMethod::run (void *retp, ffi_raw *args, _Jv_InterpMethod *meth)
if (! sp[0].o) if (! sp[0].o)
{ {
SAVE_PC(); SAVE_PC();
throw new java::lang::NullPointerException; throw_null_pointer_exception ();
} }
fun = (void (*)()) rmeth->method->ncode; fun = (void (*)()) rmeth->method->ncode;
...@@ -2906,7 +2896,7 @@ _Jv_InterpMethod::run (void *retp, ffi_raw *args, _Jv_InterpMethod *meth) ...@@ -2906,7 +2896,7 @@ _Jv_InterpMethod::run (void *retp, ffi_raw *args, _Jv_InterpMethod *meth)
if (! sp[0].o) if (! sp[0].o)
{ {
SAVE_PC(); SAVE_PC();
throw new java::lang::NullPointerException; throw_null_pointer_exception ();
} }
fun = (void (*)()) rmeth->method->ncode; fun = (void (*)()) rmeth->method->ncode;
} }
...@@ -3304,17 +3294,11 @@ throw_incompatible_class_change_error (jstring msg) ...@@ -3304,17 +3294,11 @@ throw_incompatible_class_change_error (jstring msg)
throw new java::lang::IncompatibleClassChangeError (msg); throw new java::lang::IncompatibleClassChangeError (msg);
} }
#ifndef HANDLE_SEGV
static java::lang::NullPointerException *null_pointer_exc;
static void static void
throw_null_pointer_exception () throw_null_pointer_exception ()
{ {
if (null_pointer_exc == NULL) throw new java::lang::NullPointerException;
null_pointer_exc = new java::lang::NullPointerException;
throw null_pointer_exc;
} }
#endif
/* Look up source code line number for given bytecode (or direct threaded /* Look up source code line number for given bytecode (or direct threaded
interpreter) PC. */ interpreter) PC. */
...@@ -3920,7 +3904,7 @@ _Jv_InterpreterEngine::do_allocate_static_fields (jclass klass, ...@@ -3920,7 +3904,7 @@ _Jv_InterpreterEngine::do_allocate_static_fields (jclass klass,
_Jv_ResolvedMethod * _Jv_ResolvedMethod *
_Jv_InterpreterEngine::do_resolve_method (_Jv_Method *method, jclass klass, _Jv_InterpreterEngine::do_resolve_method (_Jv_Method *method, jclass klass,
jboolean staticp, jint vtable_index) jboolean staticp)
{ {
int arg_count = _Jv_count_arguments (method->signature, staticp); int arg_count = _Jv_count_arguments (method->signature, staticp);
...@@ -3936,7 +3920,6 @@ _Jv_InterpreterEngine::do_resolve_method (_Jv_Method *method, jclass klass, ...@@ -3936,7 +3920,6 @@ _Jv_InterpreterEngine::do_resolve_method (_Jv_Method *method, jclass klass,
&result->arg_types[0], &result->arg_types[0],
NULL); NULL);
result->vtable_index = vtable_index;
result->method = method; result->method = method;
result->klass = klass; result->klass = klass;
......
...@@ -496,16 +496,11 @@ _Jv_Linker::resolve_pool_entry (jclass klass, int index, bool lazy) ...@@ -496,16 +496,11 @@ _Jv_Linker::resolve_pool_entry (jclass klass, int index, bool lazy)
throw new java::lang::NoSuchMethodError (sb->toString()); throw new java::lang::NoSuchMethodError (sb->toString());
} }
int vtable_index = -1;
if (pool->tags[index] != JV_CONSTANT_InterfaceMethodref)
vtable_index = (jshort)the_method->index;
pool->data[index].rmethod pool->data[index].rmethod
= klass->engine->resolve_method(the_method, = klass->engine->resolve_method(the_method,
found_class, found_class,
((the_method->accflags ((the_method->accflags
& Modifier::STATIC) != 0), & Modifier::STATIC) != 0));
vtable_index);
pool->tags[index] |= JV_CONSTANT_ResolvedFlag; pool->tags[index] |= JV_CONSTANT_ResolvedFlag;
} }
break; break;
......
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