void Rewriter::relocate_and_link(instanceKlassHandle this_oop, objArrayHandle methods, TRAPS) { int len = methods->length(); for (int i = len-1; i >= 0; i--) { methodHandle m(THREAD, (methodOop)methods->obj_at(i)); if (m->has_jsrs()) { m = rewrite_jsrs(m, CHECK); // Method might have gotten rewritten. methods->obj_at_put(i, m()); } // Set up method entry points for compiler and interpreter . m->link_method(m, CHECK); // This is for JVMTI and unrelated to relocator but the last thing we do #ifdef ASSERT if (StressMethodComparator) { static int nmc = 0; for (int j = i; j >= 0 && j >= i-4; j--) { if ((++nmc % 1000) == 0) tty->print_cr("Have run MethodComparator %d times...", nmc); bool z = MethodComparator::methods_EMCP(m(), (methodOop)methods->obj_at(j)); if (j == i && !z) { tty->print("MethodComparator FAIL: "); m->print(); m->print_codes(); assert(z, "method must compare equal to itself"); } } } #endif //ASSERT } }
Rewriter::Rewriter(instanceKlassHandle klass, constantPoolHandle cpool, objArrayHandle methods, TRAPS) : _klass(klass), _pool(cpool), _methods(methods) { assert(_pool->cache() == NULL, "constant pool cache must not be set yet"); // determine index maps for methodOop rewriting compute_index_maps(); if (RegisterFinalizersAtInit && _klass->name() == vmSymbols::java_lang_Object()) { bool did_rewrite = false; int i = _methods->length(); while (i-- > 0) { methodOop method = (methodOop)_methods->obj_at(i); if (method->intrinsic_id() == vmIntrinsics::_Object_init) { // rewrite the return bytecodes of Object.<init> to register the // object for finalization if needed. methodHandle m(THREAD, method); rewrite_Object_init(m, CHECK); did_rewrite = true; break; } } assert(did_rewrite, "must find Object::<init> to rewrite it"); } // rewrite methods, in two passes int i, len = _methods->length(); for (i = len; --i >= 0; ) { methodOop method = (methodOop)_methods->obj_at(i); scan_method(method); } // allocate constant pool cache, now that we've seen all the bytecodes make_constant_pool_cache(CHECK); for (i = len; --i >= 0; ) { methodHandle m(THREAD, (methodOop)_methods->obj_at(i)); if (m->has_jsrs()) { m = rewrite_jsrs(m, CHECK); // Method might have gotten rewritten. _methods->obj_at_put(i, m()); } // Set up method entry points for compiler and interpreter. m->link_method(m, CHECK); } }