// Unrewrite the bytecodes if an error occurs. void Rewriter::restore_bytecodes() { int len = _methods->length(); for (int i = len-1; i >= 0; i--) { methodOop method = (methodOop)_methods->obj_at(i); scan_method(method, true); } }
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); } }
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 len = _methods->length(); for (int i = len-1; i >= 0; i--) { 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(THREAD); // Restore bytecodes to their unrewritten state if there are exceptions // rewriting bytecodes or allocating the cpCache if (HAS_PENDING_EXCEPTION) { restore_bytecodes(); return; } }