From e69f60a859d3c795af4ab538217340e839f2bd73 Mon Sep 17 00:00:00 2001 From: edwin Date: Wed, 5 Oct 2005 11:53:28 +0000 Subject: [PATCH] cache self-reference of class in link_class_intern verify that the right method is called in methods --- src/vm/classcache.c | 13 +++++++------ src/vm/jit/verify/typecheck.c | 21 ++++++++++++++------- src/vm/linker.c | 9 ++++++++- 3 files changed, 29 insertions(+), 14 deletions(-) diff --git a/src/vm/classcache.c b/src/vm/classcache.c index 783e2cbde..0bcb43f24 100644 --- a/src/vm/classcache.c +++ b/src/vm/classcache.c @@ -28,7 +28,7 @@ Changes: Christian Thalinger - $Id: classcache.c 3263 2005-09-21 20:18:03Z twisti $ + $Id: classcache.c 3351 2005-10-05 11:53:28Z edwin $ */ @@ -619,13 +619,14 @@ classcache_store_defined(/*@shared@*/ classinfo *cls) /* check if this class has been defined by the same classloader */ if (clsen->classobj != NULL && clsen->classobj->classloader == cls->classloader) { /* we found an earlier definition, delete the newer one */ + /* (if it is a different classinfo) */ + if (clsen->classobj != cls) { #ifdef CLASSCACHE_VERBOSE - dolog("replacing %p with earlier defined class %p",cls,clsen->classobj); + dolog("replacing %p with earlier defined class %p",cls,clsen->classobj); #endif - /* we assert that the earlier object is not the same that we were given */ - CLASSCACHE_ASSERT(clsen->classobj != cls); - class_free(cls); - cls = clsen->classobj; + class_free(cls); + cls = clsen->classobj; + } goto return_success; } } diff --git a/src/vm/jit/verify/typecheck.c b/src/vm/jit/verify/typecheck.c index e3d76102e..b7168484c 100644 --- a/src/vm/jit/verify/typecheck.c +++ b/src/vm/jit/verify/typecheck.c @@ -28,7 +28,7 @@ Changes: Christian Thalinger - $Id: typecheck.c 3348 2005-10-05 09:20:30Z edwin $ + $Id: typecheck.c 3351 2005-10-05 11:53:28Z edwin $ */ @@ -1221,20 +1221,27 @@ verify_invocation(verifier_state *state) /* initializing the 'this' reference? */ if (!ins) { + classinfo *cls; TYPECHECK_ASSERT(state->initmethod); - /* must be of current class or direct superclass */ - /* XXX check with classrefs */ -#if 0 - if (mi->class != m->class && mi->class != m->class->super.cls) + /* { we are initializing the 'this' reference } */ + /* must be of current class or direct superclass */ + /* the current class is linked, so must be its superclass. thus we can be */ + /* sure that resolving will be trivial. */ + if (!resolve_classref(state->m,mref->classref,resolveLazy,false,true,&cls)) + return false; /* exception */ + + /* if lazy resolving did not succeed, it's not one of the allowed classes */ + /* otherwise we check it directly */ + if (cls == NULL || (cls != state->m->class && cls != state->m->class->super.cls)) { TYPECHECK_VERIFYERROR_bool(" calling of the wrong class"); -#endif + } /* set our marker variable to type int */ LOG("setting marker"); typevectorset_store(state->localset,state->numlocals-1,TYPE_INT,NULL); } else { - /* initializing an instance created with NEW */ + /* { we are initializing an instance created with NEW } */ /* XXX is this strictness ok? */ /* XXX check with classrefs */ #if 0 diff --git a/src/vm/linker.c b/src/vm/linker.c index b10bfd390..95bab8867 100644 --- a/src/vm/linker.c +++ b/src/vm/linker.c @@ -32,7 +32,7 @@ Edwin Steiner Christian Thalinger - $Id: linker.c 3344 2005-10-04 21:54:28Z twisti $ + $Id: linker.c 3351 2005-10-05 11:53:28Z edwin $ */ @@ -442,6 +442,13 @@ static classinfo *link_class_intern(classinfo *c) throw_cacao_exception_exit(string_java_lang_InternalError, "Trying to link unloaded class"); + /* cache the self-reference of this class */ + /* we do this for cases where the defining loader of the class */ + /* has not yet been recorded as an initiating loader for the class */ + /* this is needed so subsequent code can assume that self-refs */ + /* will always resolve lazily */ + classcache_store(c->classloader,c,false); + /* ok, this class is somewhat linked */ c->linked = true; -- 2.25.1