duke@435: /* trims@1907: * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved. duke@435: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@435: * duke@435: * This code is free software; you can redistribute it and/or modify it duke@435: * under the terms of the GNU General Public License version 2 only, as duke@435: * published by the Free Software Foundation. duke@435: * duke@435: * This code is distributed in the hope that it will be useful, but WITHOUT duke@435: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@435: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@435: * version 2 for more details (a copy is included in the LICENSE file that duke@435: * accompanied this code). duke@435: * duke@435: * You should have received a copy of the GNU General Public License version duke@435: * 2 along with this work; if not, write to the Free Software Foundation, duke@435: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@435: * trims@1907: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA trims@1907: * or visit www.oracle.com if you need additional information or have any trims@1907: * questions. duke@435: * duke@435: */ duke@435: stefank@2314: #include "precompiled.hpp" stefank@2314: #include "asm/codeBuffer.hpp" stefank@2314: #include "c1/c1_CodeStubs.hpp" stefank@2314: #include "c1/c1_Defs.hpp" stefank@2314: #include "c1/c1_FrameMap.hpp" stefank@2314: #include "c1/c1_LIRAssembler.hpp" stefank@2314: #include "c1/c1_MacroAssembler.hpp" stefank@2314: #include "c1/c1_Runtime1.hpp" stefank@2314: #include "classfile/systemDictionary.hpp" stefank@2314: #include "classfile/vmSymbols.hpp" stefank@2314: #include "code/codeBlob.hpp" stefank@2314: #include "code/compiledIC.hpp" stefank@2314: #include "code/pcDesc.hpp" stefank@2314: #include "code/scopeDesc.hpp" stefank@2314: #include "code/vtableStubs.hpp" stefank@2314: #include "compiler/disassembler.hpp" stefank@2314: #include "gc_interface/collectedHeap.hpp" stefank@2314: #include "interpreter/bytecode.hpp" stefank@2314: #include "interpreter/interpreter.hpp" stefank@2314: #include "memory/allocation.inline.hpp" stefank@2314: #include "memory/barrierSet.hpp" stefank@2314: #include "memory/oopFactory.hpp" stefank@2314: #include "memory/resourceArea.hpp" stefank@2314: #include "oops/objArrayKlass.hpp" stefank@2314: #include "oops/oop.inline.hpp" stefank@2314: #include "runtime/biasedLocking.hpp" stefank@2314: #include "runtime/compilationPolicy.hpp" stefank@2314: #include "runtime/interfaceSupport.hpp" stefank@2314: #include "runtime/javaCalls.hpp" stefank@2314: #include "runtime/sharedRuntime.hpp" stefank@2314: #include "runtime/threadCritical.hpp" stefank@2314: #include "runtime/vframe.hpp" stefank@2314: #include "runtime/vframeArray.hpp" stefank@2314: #include "utilities/copy.hpp" stefank@2314: #include "utilities/events.hpp" duke@435: duke@435: duke@435: // Implementation of StubAssembler duke@435: duke@435: StubAssembler::StubAssembler(CodeBuffer* code, const char * name, int stub_id) : C1_MacroAssembler(code) { duke@435: _name = name; duke@435: _must_gc_arguments = false; duke@435: _frame_size = no_frame_size; duke@435: _num_rt_args = 0; duke@435: _stub_id = stub_id; duke@435: } duke@435: duke@435: duke@435: void StubAssembler::set_info(const char* name, bool must_gc_arguments) { duke@435: _name = name; duke@435: _must_gc_arguments = must_gc_arguments; duke@435: } duke@435: duke@435: duke@435: void StubAssembler::set_frame_size(int size) { duke@435: if (_frame_size == no_frame_size) { duke@435: _frame_size = size; duke@435: } duke@435: assert(_frame_size == size, "can't change the frame size"); duke@435: } duke@435: duke@435: duke@435: void StubAssembler::set_num_rt_args(int args) { duke@435: if (_num_rt_args == 0) { duke@435: _num_rt_args = args; duke@435: } duke@435: assert(_num_rt_args == args, "can't change the number of args"); duke@435: } duke@435: duke@435: // Implementation of Runtime1 duke@435: duke@435: CodeBlob* Runtime1::_blobs[Runtime1::number_of_ids]; duke@435: const char *Runtime1::_blob_names[] = { duke@435: RUNTIME1_STUBS(STUB_NAME, LAST_STUB_NAME) duke@435: }; duke@435: duke@435: #ifndef PRODUCT duke@435: // statistics duke@435: int Runtime1::_generic_arraycopy_cnt = 0; duke@435: int Runtime1::_primitive_arraycopy_cnt = 0; duke@435: int Runtime1::_oop_arraycopy_cnt = 0; duke@435: int Runtime1::_arraycopy_slowcase_cnt = 0; duke@435: int Runtime1::_new_type_array_slowcase_cnt = 0; duke@435: int Runtime1::_new_object_array_slowcase_cnt = 0; duke@435: int Runtime1::_new_instance_slowcase_cnt = 0; duke@435: int Runtime1::_new_multi_array_slowcase_cnt = 0; duke@435: int Runtime1::_monitorenter_slowcase_cnt = 0; duke@435: int Runtime1::_monitorexit_slowcase_cnt = 0; duke@435: int Runtime1::_patch_code_slowcase_cnt = 0; duke@435: int Runtime1::_throw_range_check_exception_count = 0; duke@435: int Runtime1::_throw_index_exception_count = 0; duke@435: int Runtime1::_throw_div0_exception_count = 0; duke@435: int Runtime1::_throw_null_pointer_exception_count = 0; duke@435: int Runtime1::_throw_class_cast_exception_count = 0; duke@435: int Runtime1::_throw_incompatible_class_change_error_count = 0; duke@435: int Runtime1::_throw_array_store_exception_count = 0; duke@435: int Runtime1::_throw_count = 0; duke@435: #endif duke@435: duke@435: // Simple helper to see if the caller of a runtime stub which duke@435: // entered the VM has been deoptimized duke@435: duke@435: static bool caller_is_deopted() { duke@435: JavaThread* thread = JavaThread::current(); duke@435: RegisterMap reg_map(thread, false); duke@435: frame runtime_frame = thread->last_frame(); duke@435: frame caller_frame = runtime_frame.sender(®_map); duke@435: assert(caller_frame.is_compiled_frame(), "must be compiled"); duke@435: return caller_frame.is_deoptimized_frame(); duke@435: } duke@435: duke@435: // Stress deoptimization duke@435: static void deopt_caller() { duke@435: if ( !caller_is_deopted()) { duke@435: JavaThread* thread = JavaThread::current(); duke@435: RegisterMap reg_map(thread, false); duke@435: frame runtime_frame = thread->last_frame(); duke@435: frame caller_frame = runtime_frame.sender(®_map); dcubed@1648: Deoptimization::deoptimize_frame(thread, caller_frame.id()); duke@435: assert(caller_is_deopted(), "Must be deoptimized"); duke@435: } duke@435: } duke@435: duke@435: iveresov@1939: void Runtime1::generate_blob_for(BufferBlob* buffer_blob, StubID id) { duke@435: assert(0 <= id && id < number_of_ids, "illegal stub id"); duke@435: ResourceMark rm; duke@435: // create code buffer for code storage twisti@2103: CodeBuffer code(buffer_blob); duke@435: iveresov@1939: Compilation::setup_code_buffer(&code, 0); duke@435: duke@435: // create assembler for code generation duke@435: StubAssembler* sasm = new StubAssembler(&code, name_for(id), id); duke@435: // generate code for runtime stub duke@435: OopMapSet* oop_maps; duke@435: oop_maps = generate_code_for(id, sasm); duke@435: assert(oop_maps == NULL || sasm->frame_size() != no_frame_size, duke@435: "if stub has an oop map it must have a valid frame size"); duke@435: duke@435: #ifdef ASSERT duke@435: // Make sure that stubs that need oopmaps have them duke@435: switch (id) { duke@435: // These stubs don't need to have an oopmap duke@435: case dtrace_object_alloc_id: ysr@777: case g1_pre_barrier_slow_id: ysr@777: case g1_post_barrier_slow_id: duke@435: case slow_subtype_check_id: duke@435: case fpu2long_stub_id: duke@435: case unwind_exception_id: iveresov@2138: case counter_overflow_id: bobv@2036: #if defined(SPARC) || defined(PPC) duke@435: case handle_exception_nofpu_id: // Unused on sparc duke@435: #endif duke@435: break; duke@435: duke@435: // All other stubs should have oopmaps duke@435: default: duke@435: assert(oop_maps != NULL, "must have an oopmap"); duke@435: } duke@435: #endif duke@435: duke@435: // align so printing shows nop's instead of random code at the end (SimpleStubs are aligned) duke@435: sasm->align(BytesPerWord); duke@435: // make sure all code is in code buffer duke@435: sasm->flush(); duke@435: // create blob - distinguish a few special cases duke@435: CodeBlob* blob = RuntimeStub::new_runtime_stub(name_for(id), duke@435: &code, duke@435: CodeOffsets::frame_never_safe, duke@435: sasm->frame_size(), duke@435: oop_maps, duke@435: sasm->must_gc_arguments()); duke@435: // install blob duke@435: assert(blob != NULL, "blob must exist"); duke@435: _blobs[id] = blob; duke@435: } duke@435: duke@435: iveresov@1939: void Runtime1::initialize(BufferBlob* blob) { iveresov@1939: // platform-dependent initialization iveresov@1939: initialize_pd(); iveresov@1939: // generate stubs iveresov@1939: for (int id = 0; id < number_of_ids; id++) generate_blob_for(blob, (StubID)id); iveresov@1939: // printing duke@435: #ifndef PRODUCT iveresov@1939: if (PrintSimpleStubs) { iveresov@1939: ResourceMark rm; iveresov@1939: for (int id = 0; id < number_of_ids; id++) { iveresov@1939: _blobs[id]->print(); iveresov@1939: if (_blobs[id]->oop_maps() != NULL) { iveresov@1939: _blobs[id]->oop_maps()->print(); duke@435: } duke@435: } iveresov@1939: } duke@435: #endif duke@435: } duke@435: duke@435: duke@435: CodeBlob* Runtime1::blob_for(StubID id) { duke@435: assert(0 <= id && id < number_of_ids, "illegal stub id"); duke@435: return _blobs[id]; duke@435: } duke@435: duke@435: duke@435: const char* Runtime1::name_for(StubID id) { duke@435: assert(0 <= id && id < number_of_ids, "illegal stub id"); duke@435: return _blob_names[id]; duke@435: } duke@435: duke@435: const char* Runtime1::name_for_address(address entry) { duke@435: for (int id = 0; id < number_of_ids; id++) { duke@435: if (entry == entry_for((StubID)id)) return name_for((StubID)id); duke@435: } duke@435: duke@435: #define FUNCTION_CASE(a, f) \ duke@435: if ((intptr_t)a == CAST_FROM_FN_PTR(intptr_t, f)) return #f duke@435: duke@435: FUNCTION_CASE(entry, os::javaTimeMillis); duke@435: FUNCTION_CASE(entry, os::javaTimeNanos); duke@435: FUNCTION_CASE(entry, SharedRuntime::OSR_migration_end); duke@435: FUNCTION_CASE(entry, SharedRuntime::d2f); duke@435: FUNCTION_CASE(entry, SharedRuntime::d2i); duke@435: FUNCTION_CASE(entry, SharedRuntime::d2l); duke@435: FUNCTION_CASE(entry, SharedRuntime::dcos); duke@435: FUNCTION_CASE(entry, SharedRuntime::dexp); duke@435: FUNCTION_CASE(entry, SharedRuntime::dlog); duke@435: FUNCTION_CASE(entry, SharedRuntime::dlog10); duke@435: FUNCTION_CASE(entry, SharedRuntime::dpow); duke@435: FUNCTION_CASE(entry, SharedRuntime::drem); duke@435: FUNCTION_CASE(entry, SharedRuntime::dsin); duke@435: FUNCTION_CASE(entry, SharedRuntime::dtan); duke@435: FUNCTION_CASE(entry, SharedRuntime::f2i); duke@435: FUNCTION_CASE(entry, SharedRuntime::f2l); duke@435: FUNCTION_CASE(entry, SharedRuntime::frem); duke@435: FUNCTION_CASE(entry, SharedRuntime::l2d); duke@435: FUNCTION_CASE(entry, SharedRuntime::l2f); duke@435: FUNCTION_CASE(entry, SharedRuntime::ldiv); duke@435: FUNCTION_CASE(entry, SharedRuntime::lmul); duke@435: FUNCTION_CASE(entry, SharedRuntime::lrem); duke@435: FUNCTION_CASE(entry, SharedRuntime::lrem); duke@435: FUNCTION_CASE(entry, SharedRuntime::dtrace_method_entry); duke@435: FUNCTION_CASE(entry, SharedRuntime::dtrace_method_exit); duke@435: FUNCTION_CASE(entry, trace_block_entry); duke@435: duke@435: #undef FUNCTION_CASE duke@435: bobv@2036: // Soft float adds more runtime names. bobv@2036: return pd_name_for_address(entry); duke@435: } duke@435: duke@435: duke@435: JRT_ENTRY(void, Runtime1::new_instance(JavaThread* thread, klassOopDesc* klass)) duke@435: NOT_PRODUCT(_new_instance_slowcase_cnt++;) duke@435: duke@435: assert(oop(klass)->is_klass(), "not a class"); duke@435: instanceKlassHandle h(thread, klass); duke@435: h->check_valid_for_instantiation(true, CHECK); duke@435: // make sure klass is initialized duke@435: h->initialize(CHECK); duke@435: // allocate instance and return via TLS duke@435: oop obj = h->allocate_instance(CHECK); duke@435: thread->set_vm_result(obj); duke@435: JRT_END duke@435: duke@435: duke@435: JRT_ENTRY(void, Runtime1::new_type_array(JavaThread* thread, klassOopDesc* klass, jint length)) duke@435: NOT_PRODUCT(_new_type_array_slowcase_cnt++;) duke@435: // Note: no handle for klass needed since they are not used duke@435: // anymore after new_typeArray() and no GC can happen before. duke@435: // (This may have to change if this code changes!) duke@435: assert(oop(klass)->is_klass(), "not a class"); duke@435: BasicType elt_type = typeArrayKlass::cast(klass)->element_type(); duke@435: oop obj = oopFactory::new_typeArray(elt_type, length, CHECK); duke@435: thread->set_vm_result(obj); duke@435: // This is pretty rare but this runtime patch is stressful to deoptimization duke@435: // if we deoptimize here so force a deopt to stress the path. duke@435: if (DeoptimizeALot) { duke@435: deopt_caller(); duke@435: } duke@435: duke@435: JRT_END duke@435: duke@435: duke@435: JRT_ENTRY(void, Runtime1::new_object_array(JavaThread* thread, klassOopDesc* array_klass, jint length)) duke@435: NOT_PRODUCT(_new_object_array_slowcase_cnt++;) duke@435: duke@435: // Note: no handle for klass needed since they are not used duke@435: // anymore after new_objArray() and no GC can happen before. duke@435: // (This may have to change if this code changes!) duke@435: assert(oop(array_klass)->is_klass(), "not a class"); duke@435: klassOop elem_klass = objArrayKlass::cast(array_klass)->element_klass(); duke@435: objArrayOop obj = oopFactory::new_objArray(elem_klass, length, CHECK); duke@435: thread->set_vm_result(obj); duke@435: // This is pretty rare but this runtime patch is stressful to deoptimization duke@435: // if we deoptimize here so force a deopt to stress the path. duke@435: if (DeoptimizeALot) { duke@435: deopt_caller(); duke@435: } duke@435: JRT_END duke@435: duke@435: duke@435: JRT_ENTRY(void, Runtime1::new_multi_array(JavaThread* thread, klassOopDesc* klass, int rank, jint* dims)) duke@435: NOT_PRODUCT(_new_multi_array_slowcase_cnt++;) duke@435: duke@435: assert(oop(klass)->is_klass(), "not a class"); duke@435: assert(rank >= 1, "rank must be nonzero"); duke@435: oop obj = arrayKlass::cast(klass)->multi_allocate(rank, dims, CHECK); duke@435: thread->set_vm_result(obj); duke@435: JRT_END duke@435: duke@435: duke@435: JRT_ENTRY(void, Runtime1::unimplemented_entry(JavaThread* thread, StubID id)) duke@435: tty->print_cr("Runtime1::entry_for(%d) returned unimplemented entry point", id); duke@435: JRT_END duke@435: duke@435: duke@435: JRT_ENTRY(void, Runtime1::throw_array_store_exception(JavaThread* thread)) duke@435: THROW(vmSymbolHandles::java_lang_ArrayStoreException()); duke@435: JRT_END duke@435: duke@435: duke@435: JRT_ENTRY(void, Runtime1::post_jvmti_exception_throw(JavaThread* thread)) dcubed@1648: if (JvmtiExport::can_post_on_exceptions()) { duke@435: vframeStream vfst(thread, true); duke@435: address bcp = vfst.method()->bcp_from(vfst.bci()); duke@435: JvmtiExport::post_exception_throw(thread, vfst.method(), bcp, thread->exception_oop()); duke@435: } duke@435: JRT_END duke@435: iveresov@2138: // This is a helper to allow us to safepoint but allow the outer entry iveresov@2138: // to be safepoint free if we need to do an osr iveresov@2138: static nmethod* counter_overflow_helper(JavaThread* THREAD, int branch_bci, methodOopDesc* m) { iveresov@2138: nmethod* osr_nm = NULL; iveresov@2138: methodHandle method(THREAD, m); iveresov@2138: iveresov@2138: RegisterMap map(THREAD, false); iveresov@2138: frame fr = THREAD->last_frame().sender(&map); duke@435: nmethod* nm = (nmethod*) fr.cb(); iveresov@2138: assert(nm!= NULL && nm->is_nmethod(), "Sanity check"); iveresov@2138: methodHandle enclosing_method(THREAD, nm->method()); iveresov@2138: iveresov@2138: CompLevel level = (CompLevel)nm->comp_level(); iveresov@2138: int bci = InvocationEntryBci; iveresov@2138: if (branch_bci != InvocationEntryBci) { iveresov@2138: // Compute desination bci iveresov@2138: address pc = method()->code_base() + branch_bci; iveresov@2138: Bytecodes::Code branch = Bytecodes::code_at(pc, method()); iveresov@2138: int offset = 0; iveresov@2138: switch (branch) { iveresov@2138: case Bytecodes::_if_icmplt: case Bytecodes::_iflt: iveresov@2138: case Bytecodes::_if_icmpgt: case Bytecodes::_ifgt: iveresov@2138: case Bytecodes::_if_icmple: case Bytecodes::_ifle: iveresov@2138: case Bytecodes::_if_icmpge: case Bytecodes::_ifge: iveresov@2138: case Bytecodes::_if_icmpeq: case Bytecodes::_if_acmpeq: case Bytecodes::_ifeq: iveresov@2138: case Bytecodes::_if_icmpne: case Bytecodes::_if_acmpne: case Bytecodes::_ifne: iveresov@2138: case Bytecodes::_ifnull: case Bytecodes::_ifnonnull: case Bytecodes::_goto: iveresov@2138: offset = (int16_t)Bytes::get_Java_u2(pc + 1); iveresov@2138: break; iveresov@2138: case Bytecodes::_goto_w: iveresov@2138: offset = Bytes::get_Java_u4(pc + 1); iveresov@2138: break; iveresov@2138: default: ; duke@435: } iveresov@2138: bci = branch_bci + offset; iveresov@2138: } iveresov@2138: iveresov@2138: osr_nm = CompilationPolicy::policy()->event(enclosing_method, method, branch_bci, bci, level, THREAD); iveresov@2138: return osr_nm; iveresov@2138: } iveresov@2138: iveresov@2138: JRT_BLOCK_ENTRY(address, Runtime1::counter_overflow(JavaThread* thread, int bci, methodOopDesc* method)) iveresov@2138: nmethod* osr_nm; iveresov@2138: JRT_BLOCK iveresov@2138: osr_nm = counter_overflow_helper(thread, bci, method); iveresov@2138: if (osr_nm != NULL) { iveresov@2138: RegisterMap map(thread, false); iveresov@2138: frame fr = thread->last_frame().sender(&map); never@2260: Deoptimization::deoptimize_frame(thread, fr.id()); duke@435: } iveresov@2138: JRT_BLOCK_END iveresov@2138: return NULL; duke@435: JRT_END duke@435: duke@435: extern void vm_exit(int code); duke@435: duke@435: // Enter this method from compiled code handler below. This is where we transition duke@435: // to VM mode. This is done as a helper routine so that the method called directly duke@435: // from compiled code does not have to transition to VM. This allows the entry duke@435: // method to see if the nmethod that we have just looked up a handler for has duke@435: // been deoptimized while we were in the vm. This simplifies the assembly code duke@435: // cpu directories. duke@435: // duke@435: // We are entering here from exception stub (via the entry method below) duke@435: // If there is a compiled exception handler in this method, we will continue there; duke@435: // otherwise we will unwind the stack and continue at the caller of top frame method duke@435: // Note: we enter in Java using a special JRT wrapper. This wrapper allows us to duke@435: // control the area where we can allow a safepoint. After we exit the safepoint area we can duke@435: // check to see if the handler we are going to return is now in a nmethod that has duke@435: // been deoptimized. If that is the case we return the deopt blob duke@435: // unpack_with_exception entry instead. This makes life for the exception blob easier duke@435: // because making that same check and diverting is painful from assembly language. duke@435: // duke@435: duke@435: duke@435: JRT_ENTRY_NO_ASYNC(static address, exception_handler_for_pc_helper(JavaThread* thread, oopDesc* ex, address pc, nmethod*& nm)) duke@435: duke@435: Handle exception(thread, ex); duke@435: nm = CodeCache::find_nmethod(pc); duke@435: assert(nm != NULL, "this is not an nmethod"); duke@435: // Adjust the pc as needed/ duke@435: if (nm->is_deopt_pc(pc)) { duke@435: RegisterMap map(thread, false); duke@435: frame exception_frame = thread->last_frame().sender(&map); duke@435: // if the frame isn't deopted then pc must not correspond to the caller of last_frame duke@435: assert(exception_frame.is_deoptimized_frame(), "must be deopted"); duke@435: pc = exception_frame.pc(); duke@435: } duke@435: #ifdef ASSERT duke@435: assert(exception.not_null(), "NULL exceptions should be handled by throw_exception"); duke@435: assert(exception->is_oop(), "just checking"); duke@435: // Check that exception is a subclass of Throwable, otherwise we have a VerifyError never@1577: if (!(exception->is_a(SystemDictionary::Throwable_klass()))) { duke@435: if (ExitVMOnVerifyError) vm_exit(-1); duke@435: ShouldNotReachHere(); duke@435: } duke@435: #endif duke@435: duke@435: // Check the stack guard pages and reenable them if necessary and there is duke@435: // enough space on the stack to do so. Use fast exceptions only if the guard duke@435: // pages are enabled. duke@435: bool guard_pages_enabled = thread->stack_yellow_zone_enabled(); duke@435: if (!guard_pages_enabled) guard_pages_enabled = thread->reguard_stack(); duke@435: dcubed@1648: if (JvmtiExport::can_post_on_exceptions()) { duke@435: // To ensure correct notification of exception catches and throws duke@435: // we have to deoptimize here. If we attempted to notify the duke@435: // catches and throws during this exception lookup it's possible duke@435: // we could deoptimize on the way out of the VM and end back in duke@435: // the interpreter at the throw site. This would result in double duke@435: // notifications since the interpreter would also notify about duke@435: // these same catches and throws as it unwound the frame. duke@435: duke@435: RegisterMap reg_map(thread); duke@435: frame stub_frame = thread->last_frame(); duke@435: frame caller_frame = stub_frame.sender(®_map); duke@435: duke@435: // We don't really want to deoptimize the nmethod itself since we duke@435: // can actually continue in the exception handler ourselves but I duke@435: // don't see an easy way to have the desired effect. never@2260: Deoptimization::deoptimize_frame(thread, caller_frame.id()); never@2260: assert(caller_is_deopted(), "Must be deoptimized"); duke@435: duke@435: return SharedRuntime::deopt_blob()->unpack_with_exception_in_tls(); duke@435: } duke@435: duke@435: // ExceptionCache is used only for exceptions at call and not for implicit exceptions duke@435: if (guard_pages_enabled) { duke@435: address fast_continuation = nm->handler_for_exception_and_pc(exception, pc); duke@435: if (fast_continuation != NULL) { duke@435: if (fast_continuation == ExceptionCache::unwind_handler()) fast_continuation = NULL; duke@435: return fast_continuation; duke@435: } duke@435: } duke@435: duke@435: // If the stack guard pages are enabled, check whether there is a handler in duke@435: // the current method. Otherwise (guard pages disabled), force an unwind and duke@435: // skip the exception cache update (i.e., just leave continuation==NULL). duke@435: address continuation = NULL; duke@435: if (guard_pages_enabled) { duke@435: duke@435: // New exception handling mechanism can support inlined methods duke@435: // with exception handlers since the mappings are from PC to PC duke@435: duke@435: // debugging support duke@435: // tracing duke@435: if (TraceExceptions) { duke@435: ttyLocker ttyl; duke@435: ResourceMark rm; duke@435: tty->print_cr("Exception <%s> (0x%x) thrown in compiled method <%s> at PC " PTR_FORMAT " for thread 0x%x", duke@435: exception->print_value_string(), (address)exception(), nm->method()->print_value_string(), pc, thread); duke@435: } duke@435: // for AbortVMOnException flag duke@435: NOT_PRODUCT(Exceptions::debug_check_abort(exception)); duke@435: duke@435: // Clear out the exception oop and pc since looking up an duke@435: // exception handler can cause class loading, which might throw an duke@435: // exception and those fields are expected to be clear during duke@435: // normal bytecode execution. duke@435: thread->set_exception_oop(NULL); duke@435: thread->set_exception_pc(NULL); duke@435: duke@435: continuation = SharedRuntime::compute_compiled_exc_handler(nm, pc, exception, false, false); duke@435: // If an exception was thrown during exception dispatch, the exception oop may have changed duke@435: thread->set_exception_oop(exception()); duke@435: thread->set_exception_pc(pc); duke@435: duke@435: // the exception cache is used only by non-implicit exceptions duke@435: if (continuation == NULL) { duke@435: nm->add_handler_for_exception_and_pc(exception, pc, ExceptionCache::unwind_handler()); duke@435: } else { duke@435: nm->add_handler_for_exception_and_pc(exception, pc, continuation); duke@435: } duke@435: } duke@435: duke@435: thread->set_vm_result(exception()); duke@435: duke@435: if (TraceExceptions) { duke@435: ttyLocker ttyl; duke@435: ResourceMark rm; duke@435: tty->print_cr("Thread " PTR_FORMAT " continuing at PC " PTR_FORMAT " for exception thrown at PC " PTR_FORMAT, duke@435: thread, continuation, pc); duke@435: } duke@435: duke@435: return continuation; duke@435: JRT_END duke@435: duke@435: // Enter this method from compiled code only if there is a Java exception handler duke@435: // in the method handling the exception duke@435: // We are entering here from exception stub. We don't do a normal VM transition here. duke@435: // We do it in a helper. This is so we can check to see if the nmethod we have just duke@435: // searched for an exception handler has been deoptimized in the meantime. duke@435: address Runtime1::exception_handler_for_pc(JavaThread* thread) { duke@435: oop exception = thread->exception_oop(); duke@435: address pc = thread->exception_pc(); duke@435: // Still in Java mode duke@435: debug_only(ResetNoHandleMark rnhm); duke@435: nmethod* nm = NULL; duke@435: address continuation = NULL; duke@435: { duke@435: // Enter VM mode by calling the helper duke@435: duke@435: ResetNoHandleMark rnhm; duke@435: continuation = exception_handler_for_pc_helper(thread, exception, pc, nm); duke@435: } duke@435: // Back in JAVA, use no oops DON'T safepoint duke@435: duke@435: // Now check to see if the nmethod we were called from is now deoptimized. duke@435: // If so we must return to the deopt blob and deoptimize the nmethod duke@435: duke@435: if (nm != NULL && caller_is_deopted()) { duke@435: continuation = SharedRuntime::deopt_blob()->unpack_with_exception_in_tls(); duke@435: } duke@435: duke@435: return continuation; duke@435: } duke@435: duke@435: duke@435: JRT_ENTRY(void, Runtime1::throw_range_check_exception(JavaThread* thread, int index)) duke@435: NOT_PRODUCT(_throw_range_check_exception_count++;) duke@435: Events::log("throw_range_check"); duke@435: char message[jintAsStringSize]; duke@435: sprintf(message, "%d", index); duke@435: SharedRuntime::throw_and_post_jvmti_exception(thread, vmSymbols::java_lang_ArrayIndexOutOfBoundsException(), message); duke@435: JRT_END duke@435: duke@435: duke@435: JRT_ENTRY(void, Runtime1::throw_index_exception(JavaThread* thread, int index)) duke@435: NOT_PRODUCT(_throw_index_exception_count++;) duke@435: Events::log("throw_index"); duke@435: char message[16]; duke@435: sprintf(message, "%d", index); duke@435: SharedRuntime::throw_and_post_jvmti_exception(thread, vmSymbols::java_lang_IndexOutOfBoundsException(), message); duke@435: JRT_END duke@435: duke@435: duke@435: JRT_ENTRY(void, Runtime1::throw_div0_exception(JavaThread* thread)) duke@435: NOT_PRODUCT(_throw_div0_exception_count++;) duke@435: SharedRuntime::throw_and_post_jvmti_exception(thread, vmSymbols::java_lang_ArithmeticException(), "/ by zero"); duke@435: JRT_END duke@435: duke@435: duke@435: JRT_ENTRY(void, Runtime1::throw_null_pointer_exception(JavaThread* thread)) duke@435: NOT_PRODUCT(_throw_null_pointer_exception_count++;) duke@435: SharedRuntime::throw_and_post_jvmti_exception(thread, vmSymbols::java_lang_NullPointerException()); duke@435: JRT_END duke@435: duke@435: duke@435: JRT_ENTRY(void, Runtime1::throw_class_cast_exception(JavaThread* thread, oopDesc* object)) duke@435: NOT_PRODUCT(_throw_class_cast_exception_count++;) duke@435: ResourceMark rm(thread); duke@435: char* message = SharedRuntime::generate_class_cast_message( duke@435: thread, Klass::cast(object->klass())->external_name()); duke@435: SharedRuntime::throw_and_post_jvmti_exception( duke@435: thread, vmSymbols::java_lang_ClassCastException(), message); duke@435: JRT_END duke@435: duke@435: duke@435: JRT_ENTRY(void, Runtime1::throw_incompatible_class_change_error(JavaThread* thread)) duke@435: NOT_PRODUCT(_throw_incompatible_class_change_error_count++;) duke@435: ResourceMark rm(thread); duke@435: SharedRuntime::throw_and_post_jvmti_exception(thread, vmSymbols::java_lang_IncompatibleClassChangeError()); duke@435: JRT_END duke@435: duke@435: duke@435: JRT_ENTRY_NO_ASYNC(void, Runtime1::monitorenter(JavaThread* thread, oopDesc* obj, BasicObjectLock* lock)) duke@435: NOT_PRODUCT(_monitorenter_slowcase_cnt++;) duke@435: if (PrintBiasedLockingStatistics) { duke@435: Atomic::inc(BiasedLocking::slow_path_entry_count_addr()); duke@435: } duke@435: Handle h_obj(thread, obj); duke@435: assert(h_obj()->is_oop(), "must be NULL or an object"); duke@435: if (UseBiasedLocking) { duke@435: // Retry fast entry if bias is revoked to avoid unnecessary inflation duke@435: ObjectSynchronizer::fast_enter(h_obj, lock->lock(), true, CHECK); duke@435: } else { duke@435: if (UseFastLocking) { duke@435: // When using fast locking, the compiled code has already tried the fast case duke@435: assert(obj == lock->obj(), "must match"); duke@435: ObjectSynchronizer::slow_enter(h_obj, lock->lock(), THREAD); duke@435: } else { duke@435: lock->set_obj(obj); duke@435: ObjectSynchronizer::fast_enter(h_obj, lock->lock(), false, THREAD); duke@435: } duke@435: } duke@435: JRT_END duke@435: duke@435: duke@435: JRT_LEAF(void, Runtime1::monitorexit(JavaThread* thread, BasicObjectLock* lock)) duke@435: NOT_PRODUCT(_monitorexit_slowcase_cnt++;) duke@435: assert(thread == JavaThread::current(), "threads must correspond"); duke@435: assert(thread->last_Java_sp(), "last_Java_sp must be set"); duke@435: // monitorexit is non-blocking (leaf routine) => no exceptions can be thrown duke@435: EXCEPTION_MARK; duke@435: duke@435: oop obj = lock->obj(); duke@435: assert(obj->is_oop(), "must be NULL or an object"); duke@435: if (UseFastLocking) { duke@435: // When using fast locking, the compiled code has already tried the fast case duke@435: ObjectSynchronizer::slow_exit(obj, lock->lock(), THREAD); duke@435: } else { duke@435: ObjectSynchronizer::fast_exit(obj, lock->lock(), THREAD); duke@435: } duke@435: JRT_END duke@435: duke@435: duke@435: static klassOop resolve_field_return_klass(methodHandle caller, int bci, TRAPS) { jrose@1957: Bytecode_field* field_access = Bytecode_field_at(caller, bci); duke@435: // This can be static or non-static field access duke@435: Bytecodes::Code code = field_access->code(); duke@435: duke@435: // We must load class, initialize class and resolvethe field duke@435: FieldAccessInfo result; // initialize class if needed duke@435: constantPoolHandle constants(THREAD, caller->constants()); duke@435: LinkResolver::resolve_field(result, constants, field_access->index(), Bytecodes::java_code(code), false, CHECK_NULL); duke@435: return result.klass()(); duke@435: } duke@435: duke@435: duke@435: // duke@435: // This routine patches sites where a class wasn't loaded or duke@435: // initialized at the time the code was generated. It handles duke@435: // references to classes, fields and forcing of initialization. Most duke@435: // of the cases are straightforward and involving simply forcing duke@435: // resolution of a class, rewriting the instruction stream with the duke@435: // needed constant and replacing the call in this function with the duke@435: // patched code. The case for static field is more complicated since duke@435: // the thread which is in the process of initializing a class can duke@435: // access it's static fields but other threads can't so the code duke@435: // either has to deoptimize when this case is detected or execute a duke@435: // check that the current thread is the initializing thread. The duke@435: // current duke@435: // duke@435: // Patches basically look like this: duke@435: // duke@435: // duke@435: // patch_site: jmp patch stub ;; will be patched duke@435: // continue: ... duke@435: // ... duke@435: // ... duke@435: // ... duke@435: // duke@435: // They have a stub which looks like this: duke@435: // duke@435: // ;; patch body duke@435: // movl , reg (for class constants) duke@435: // movl [reg1 + ], reg (for field offsets) duke@435: // movl reg, [reg1 + ] (for field offsets) duke@435: // duke@435: // patch_stub: call Runtime1::patch_code (through a runtime stub) duke@435: // jmp patch_site duke@435: // duke@435: // duke@435: // A normal patch is done by rewriting the patch body, usually a move, duke@435: // and then copying it into place over top of the jmp instruction duke@435: // being careful to flush caches and doing it in an MP-safe way. The duke@435: // constants following the patch body are used to find various pieces duke@435: // of the patch relative to the call site for Runtime1::patch_code. duke@435: // The case for getstatic and putstatic is more complicated because duke@435: // getstatic and putstatic have special semantics when executing while duke@435: // the class is being initialized. getstatic/putstatic on a class duke@435: // which is being_initialized may be executed by the initializing duke@435: // thread but other threads have to block when they execute it. This duke@435: // is accomplished in compiled code by executing a test of the current duke@435: // thread against the initializing thread of the class. It's emitted duke@435: // as boilerplate in their stub which allows the patched code to be duke@435: // executed before it's copied back into the main body of the nmethod. duke@435: // duke@435: // being_init: get_thread( duke@435: // cmpl [reg1 + ], duke@435: // jne patch_stub duke@435: // movl [reg1 + ], reg (for field offsets) duke@435: // movl reg, [reg1 + ] (for field offsets) duke@435: // jmp continue duke@435: // duke@435: // patch_stub: jmp Runtim1::patch_code (through a runtime stub) duke@435: // jmp patch_site duke@435: // duke@435: // If the class is being initialized the patch body is rewritten and duke@435: // the patch site is rewritten to jump to being_init, instead of duke@435: // patch_stub. Whenever this code is executed it checks the current duke@435: // thread against the intializing thread so other threads will enter duke@435: // the runtime and end up blocked waiting the class to finish duke@435: // initializing inside the calls to resolve_field below. The duke@435: // initializing class will continue on it's way. Once the class is duke@435: // fully_initialized, the intializing_thread of the class becomes duke@435: // NULL, so the next thread to execute this code will fail the test, duke@435: // call into patch_code and complete the patching process by copying duke@435: // the patch body back into the main part of the nmethod and resume duke@435: // executing. duke@435: // duke@435: // duke@435: duke@435: JRT_ENTRY(void, Runtime1::patch_code(JavaThread* thread, Runtime1::StubID stub_id )) duke@435: NOT_PRODUCT(_patch_code_slowcase_cnt++;) duke@435: duke@435: ResourceMark rm(thread); duke@435: RegisterMap reg_map(thread, false); duke@435: frame runtime_frame = thread->last_frame(); duke@435: frame caller_frame = runtime_frame.sender(®_map); duke@435: duke@435: // last java frame on stack duke@435: vframeStream vfst(thread, true); duke@435: assert(!vfst.at_end(), "Java frame must exist"); duke@435: duke@435: methodHandle caller_method(THREAD, vfst.method()); duke@435: // Note that caller_method->code() may not be same as caller_code because of OSR's duke@435: // Note also that in the presence of inlining it is not guaranteed duke@435: // that caller_method() == caller_code->method() duke@435: duke@435: duke@435: int bci = vfst.bci(); duke@435: duke@435: Events::log("patch_code @ " INTPTR_FORMAT , caller_frame.pc()); duke@435: duke@435: Bytecodes::Code code = Bytecode_at(caller_method->bcp_from(bci))->java_code(); duke@435: duke@435: #ifndef PRODUCT duke@435: // this is used by assertions in the access_field_patching_id duke@435: BasicType patch_field_type = T_ILLEGAL; duke@435: #endif // PRODUCT duke@435: bool deoptimize_for_volatile = false; duke@435: int patch_field_offset = -1; duke@435: KlassHandle init_klass(THREAD, klassOop(NULL)); // klass needed by access_field_patching code duke@435: Handle load_klass(THREAD, NULL); // oop needed by load_klass_patching code duke@435: if (stub_id == Runtime1::access_field_patching_id) { duke@435: jrose@1957: Bytecode_field* field_access = Bytecode_field_at(caller_method, bci); duke@435: FieldAccessInfo result; // initialize class if needed duke@435: Bytecodes::Code code = field_access->code(); duke@435: constantPoolHandle constants(THREAD, caller_method->constants()); duke@435: LinkResolver::resolve_field(result, constants, field_access->index(), Bytecodes::java_code(code), false, CHECK); duke@435: patch_field_offset = result.field_offset(); duke@435: duke@435: // If we're patching a field which is volatile then at compile it duke@435: // must not have been know to be volatile, so the generated code duke@435: // isn't correct for a volatile reference. The nmethod has to be duke@435: // deoptimized so that the code can be regenerated correctly. duke@435: // This check is only needed for access_field_patching since this duke@435: // is the path for patching field offsets. load_klass is only duke@435: // used for patching references to oops which don't need special duke@435: // handling in the volatile case. duke@435: deoptimize_for_volatile = result.access_flags().is_volatile(); duke@435: duke@435: #ifndef PRODUCT duke@435: patch_field_type = result.field_type(); duke@435: #endif duke@435: } else if (stub_id == Runtime1::load_klass_patching_id) { duke@435: oop k; duke@435: switch (code) { duke@435: case Bytecodes::_putstatic: duke@435: case Bytecodes::_getstatic: duke@435: { klassOop klass = resolve_field_return_klass(caller_method, bci, CHECK); duke@435: // Save a reference to the class that has to be checked for initialization duke@435: init_klass = KlassHandle(THREAD, klass); duke@435: k = klass; duke@435: } duke@435: break; duke@435: case Bytecodes::_new: duke@435: { Bytecode_new* bnew = Bytecode_new_at(caller_method->bcp_from(bci)); duke@435: k = caller_method->constants()->klass_at(bnew->index(), CHECK); duke@435: } duke@435: break; duke@435: case Bytecodes::_multianewarray: duke@435: { Bytecode_multianewarray* mna = Bytecode_multianewarray_at(caller_method->bcp_from(bci)); duke@435: k = caller_method->constants()->klass_at(mna->index(), CHECK); duke@435: } duke@435: break; duke@435: case Bytecodes::_instanceof: duke@435: { Bytecode_instanceof* io = Bytecode_instanceof_at(caller_method->bcp_from(bci)); duke@435: k = caller_method->constants()->klass_at(io->index(), CHECK); duke@435: } duke@435: break; duke@435: case Bytecodes::_checkcast: duke@435: { Bytecode_checkcast* cc = Bytecode_checkcast_at(caller_method->bcp_from(bci)); duke@435: k = caller_method->constants()->klass_at(cc->index(), CHECK); duke@435: } duke@435: break; duke@435: case Bytecodes::_anewarray: duke@435: { Bytecode_anewarray* anew = Bytecode_anewarray_at(caller_method->bcp_from(bci)); duke@435: klassOop ek = caller_method->constants()->klass_at(anew->index(), CHECK); duke@435: k = Klass::cast(ek)->array_klass(CHECK); duke@435: } duke@435: break; duke@435: case Bytecodes::_ldc: duke@435: case Bytecodes::_ldc_w: duke@435: { jrose@1957: Bytecode_loadconstant* cc = Bytecode_loadconstant_at(caller_method, bci); jrose@1957: k = cc->resolve_constant(CHECK); jrose@1957: assert(k != NULL && !k->is_klass(), "must be class mirror or other Java constant"); duke@435: } duke@435: break; duke@435: default: Unimplemented(); duke@435: } duke@435: // convert to handle duke@435: load_klass = Handle(THREAD, k); duke@435: } else { duke@435: ShouldNotReachHere(); duke@435: } duke@435: duke@435: if (deoptimize_for_volatile) { duke@435: // At compile time we assumed the field wasn't volatile but after duke@435: // loading it turns out it was volatile so we have to throw the duke@435: // compiled code out and let it be regenerated. duke@435: if (TracePatching) { duke@435: tty->print_cr("Deoptimizing for patching volatile field reference"); duke@435: } never@920: // It's possible the nmethod was invalidated in the last never@920: // safepoint, but if it's still alive then make it not_entrant. never@920: nmethod* nm = CodeCache::find_nmethod(caller_frame.pc()); never@920: if (nm != NULL) { never@920: nm->make_not_entrant(); never@920: } never@920: never@2260: Deoptimization::deoptimize_frame(thread, caller_frame.id()); duke@435: duke@435: // Return to the now deoptimized frame. duke@435: } duke@435: jrose@1957: // If we are patching in a non-perm oop, make sure the nmethod jrose@1957: // is on the right list. jrose@1957: if (ScavengeRootsInCode && load_klass.not_null() && load_klass->is_scavengable()) { jrose@1957: MutexLockerEx ml_code (CodeCache_lock, Mutex::_no_safepoint_check_flag); jrose@1957: nmethod* nm = CodeCache::find_nmethod(caller_frame.pc()); jrose@1957: guarantee(nm != NULL, "only nmethods can contain non-perm oops"); jrose@1957: if (!nm->on_scavenge_root_list()) jrose@1957: CodeCache::add_scavenge_root_nmethod(nm); jrose@1957: } duke@435: duke@435: // Now copy code back duke@435: duke@435: { duke@435: MutexLockerEx ml_patch (Patching_lock, Mutex::_no_safepoint_check_flag); duke@435: // duke@435: // Deoptimization may have happened while we waited for the lock. duke@435: // In that case we don't bother to do any patching we just return duke@435: // and let the deopt happen duke@435: if (!caller_is_deopted()) { duke@435: NativeGeneralJump* jump = nativeGeneralJump_at(caller_frame.pc()); duke@435: address instr_pc = jump->jump_destination(); duke@435: NativeInstruction* ni = nativeInstruction_at(instr_pc); duke@435: if (ni->is_jump() ) { duke@435: // the jump has not been patched yet duke@435: // The jump destination is slow case and therefore not part of the stubs duke@435: // (stubs are only for StaticCalls) duke@435: duke@435: // format of buffer duke@435: // .... duke@435: // instr byte 0 <-- copy_buff duke@435: // instr byte 1 duke@435: // .. duke@435: // instr byte n-1 duke@435: // n duke@435: // .... <-- call destination duke@435: duke@435: address stub_location = caller_frame.pc() + PatchingStub::patch_info_offset(); duke@435: unsigned char* byte_count = (unsigned char*) (stub_location - 1); duke@435: unsigned char* byte_skip = (unsigned char*) (stub_location - 2); duke@435: unsigned char* being_initialized_entry_offset = (unsigned char*) (stub_location - 3); duke@435: address copy_buff = stub_location - *byte_skip - *byte_count; duke@435: address being_initialized_entry = stub_location - *being_initialized_entry_offset; duke@435: if (TracePatching) { duke@435: tty->print_cr(" Patching %s at bci %d at address 0x%x (%s)", Bytecodes::name(code), bci, duke@435: instr_pc, (stub_id == Runtime1::access_field_patching_id) ? "field" : "klass"); duke@435: nmethod* caller_code = CodeCache::find_nmethod(caller_frame.pc()); duke@435: assert(caller_code != NULL, "nmethod not found"); duke@435: duke@435: // NOTE we use pc() not original_pc() because we already know they are duke@435: // identical otherwise we'd have never entered this block of code duke@435: duke@435: OopMap* map = caller_code->oop_map_for_return_address(caller_frame.pc()); duke@435: assert(map != NULL, "null check"); duke@435: map->print(); duke@435: tty->cr(); duke@435: duke@435: Disassembler::decode(copy_buff, copy_buff + *byte_count, tty); duke@435: } duke@435: // depending on the code below, do_patch says whether to copy the patch body back into the nmethod duke@435: bool do_patch = true; duke@435: if (stub_id == Runtime1::access_field_patching_id) { duke@435: // The offset may not be correct if the class was not loaded at code generation time. duke@435: // Set it now. duke@435: NativeMovRegMem* n_move = nativeMovRegMem_at(copy_buff); duke@435: assert(n_move->offset() == 0 || (n_move->offset() == 4 && (patch_field_type == T_DOUBLE || patch_field_type == T_LONG)), "illegal offset for type"); duke@435: assert(patch_field_offset >= 0, "illegal offset"); duke@435: n_move->add_offset_in_bytes(patch_field_offset); duke@435: } else if (stub_id == Runtime1::load_klass_patching_id) { duke@435: // If a getstatic or putstatic is referencing a klass which duke@435: // isn't fully initialized, the patch body isn't copied into duke@435: // place until initialization is complete. In this case the duke@435: // patch site is setup so that any threads besides the duke@435: // initializing thread are forced to come into the VM and duke@435: // block. duke@435: do_patch = (code != Bytecodes::_getstatic && code != Bytecodes::_putstatic) || duke@435: instanceKlass::cast(init_klass())->is_initialized(); duke@435: NativeGeneralJump* jump = nativeGeneralJump_at(instr_pc); duke@435: if (jump->jump_destination() == being_initialized_entry) { duke@435: assert(do_patch == true, "initialization must be complete at this point"); duke@435: } else { duke@435: // patch the instruction duke@435: NativeMovConstReg* n_copy = nativeMovConstReg_at(copy_buff); bobv@2036: bobv@2036: assert(n_copy->data() == 0 || iveresov@2138: n_copy->data() == (intptr_t)Universe::non_oop_word(), bobv@2036: "illegal init value"); duke@435: assert(load_klass() != NULL, "klass not set"); duke@435: n_copy->set_data((intx) (load_klass())); duke@435: duke@435: if (TracePatching) { duke@435: Disassembler::decode(copy_buff, copy_buff + *byte_count, tty); duke@435: } duke@435: bobv@2036: #if defined(SPARC) || defined(PPC) duke@435: // Update the oop location in the nmethod with the proper duke@435: // oop. When the code was generated, a NULL was stuffed duke@435: // in the oop table and that table needs to be update to duke@435: // have the right value. On intel the value is kept duke@435: // directly in the instruction instead of in the oop duke@435: // table, so set_data above effectively updated the value. duke@435: nmethod* nm = CodeCache::find_nmethod(instr_pc); duke@435: assert(nm != NULL, "invalid nmethod_pc"); duke@435: RelocIterator oops(nm, copy_buff, copy_buff + 1); duke@435: bool found = false; duke@435: while (oops.next() && !found) { duke@435: if (oops.type() == relocInfo::oop_type) { duke@435: oop_Relocation* r = oops.oop_reloc(); duke@435: oop* oop_adr = r->oop_addr(); duke@435: *oop_adr = load_klass(); duke@435: r->fix_oop_relocation(); duke@435: found = true; duke@435: } duke@435: } duke@435: assert(found, "the oop must exist!"); duke@435: #endif duke@435: duke@435: } duke@435: } else { duke@435: ShouldNotReachHere(); duke@435: } duke@435: if (do_patch) { duke@435: // replace instructions duke@435: // first replace the tail, then the call bobv@2036: #ifdef ARM bobv@2036: if(stub_id == Runtime1::load_klass_patching_id && !VM_Version::supports_movw()) { bobv@2036: copy_buff -= *byte_count; bobv@2036: NativeMovConstReg* n_copy2 = nativeMovConstReg_at(copy_buff); bobv@2036: n_copy2->set_data((intx) (load_klass()), instr_pc); bobv@2036: } bobv@2036: #endif bobv@2036: duke@435: for (int i = NativeCall::instruction_size; i < *byte_count; i++) { duke@435: address ptr = copy_buff + i; duke@435: int a_byte = (*ptr) & 0xFF; duke@435: address dst = instr_pc + i; duke@435: *(unsigned char*)dst = (unsigned char) a_byte; duke@435: } duke@435: ICache::invalidate_range(instr_pc, *byte_count); duke@435: NativeGeneralJump::replace_mt_safe(instr_pc, copy_buff); duke@435: duke@435: if (stub_id == Runtime1::load_klass_patching_id) { duke@435: // update relocInfo to oop duke@435: nmethod* nm = CodeCache::find_nmethod(instr_pc); duke@435: assert(nm != NULL, "invalid nmethod_pc"); duke@435: duke@435: // The old patch site is now a move instruction so update duke@435: // the reloc info so that it will get updated during duke@435: // future GCs. duke@435: RelocIterator iter(nm, (address)instr_pc, (address)(instr_pc + 1)); duke@435: relocInfo::change_reloc_info_for_address(&iter, (address) instr_pc, duke@435: relocInfo::none, relocInfo::oop_type); duke@435: #ifdef SPARC duke@435: // Sparc takes two relocations for an oop so update the second one. duke@435: address instr_pc2 = instr_pc + NativeMovConstReg::add_offset; duke@435: RelocIterator iter2(nm, instr_pc2, instr_pc2 + 1); duke@435: relocInfo::change_reloc_info_for_address(&iter2, (address) instr_pc2, duke@435: relocInfo::none, relocInfo::oop_type); duke@435: #endif bobv@2036: #ifdef PPC bobv@2036: { address instr_pc2 = instr_pc + NativeMovConstReg::lo_offset; bobv@2036: RelocIterator iter2(nm, instr_pc2, instr_pc2 + 1); bobv@2036: relocInfo::change_reloc_info_for_address(&iter2, (address) instr_pc2, relocInfo::none, relocInfo::oop_type); bobv@2036: } bobv@2036: #endif duke@435: } duke@435: duke@435: } else { duke@435: ICache::invalidate_range(copy_buff, *byte_count); duke@435: NativeGeneralJump::insert_unconditional(instr_pc, being_initialized_entry); duke@435: } duke@435: } duke@435: } duke@435: } duke@435: JRT_END duke@435: duke@435: // duke@435: // Entry point for compiled code. We want to patch a nmethod. duke@435: // We don't do a normal VM transition here because we want to duke@435: // know after the patching is complete and any safepoint(s) are taken duke@435: // if the calling nmethod was deoptimized. We do this by calling a duke@435: // helper method which does the normal VM transition and when it duke@435: // completes we can check for deoptimization. This simplifies the duke@435: // assembly code in the cpu directories. duke@435: // duke@435: int Runtime1::move_klass_patching(JavaThread* thread) { duke@435: // duke@435: // NOTE: we are still in Java duke@435: // duke@435: Thread* THREAD = thread; duke@435: debug_only(NoHandleMark nhm;) duke@435: { duke@435: // Enter VM mode duke@435: duke@435: ResetNoHandleMark rnhm; duke@435: patch_code(thread, load_klass_patching_id); duke@435: } duke@435: // Back in JAVA, use no oops DON'T safepoint duke@435: duke@435: // Return true if calling code is deoptimized duke@435: duke@435: return caller_is_deopted(); duke@435: } duke@435: duke@435: // duke@435: // Entry point for compiled code. We want to patch a nmethod. duke@435: // We don't do a normal VM transition here because we want to duke@435: // know after the patching is complete and any safepoint(s) are taken duke@435: // if the calling nmethod was deoptimized. We do this by calling a duke@435: // helper method which does the normal VM transition and when it duke@435: // completes we can check for deoptimization. This simplifies the duke@435: // assembly code in the cpu directories. duke@435: // duke@435: duke@435: int Runtime1::access_field_patching(JavaThread* thread) { duke@435: // duke@435: // NOTE: we are still in Java duke@435: // duke@435: Thread* THREAD = thread; duke@435: debug_only(NoHandleMark nhm;) duke@435: { duke@435: // Enter VM mode duke@435: duke@435: ResetNoHandleMark rnhm; duke@435: patch_code(thread, access_field_patching_id); duke@435: } duke@435: // Back in JAVA, use no oops DON'T safepoint duke@435: duke@435: // Return true if calling code is deoptimized duke@435: duke@435: return caller_is_deopted(); duke@435: JRT_END duke@435: duke@435: duke@435: JRT_LEAF(void, Runtime1::trace_block_entry(jint block_id)) duke@435: // for now we just print out the block id duke@435: tty->print("%d ", block_id); duke@435: JRT_END duke@435: duke@435: coleenp@548: // Array copy return codes. coleenp@548: enum { coleenp@548: ac_failed = -1, // arraycopy failed coleenp@548: ac_ok = 0 // arraycopy succeeded coleenp@548: }; coleenp@548: coleenp@548: ysr@1680: // Below length is the # elements copied. coleenp@548: template int obj_arraycopy_work(oopDesc* src, T* src_addr, coleenp@548: oopDesc* dst, T* dst_addr, coleenp@548: int length) { coleenp@548: coleenp@548: // For performance reasons, we assume we are using a card marking write coleenp@548: // barrier. The assert will fail if this is not the case. coleenp@548: // Note that we use the non-virtual inlineable variant of write_ref_array. coleenp@548: BarrierSet* bs = Universe::heap()->barrier_set(); ysr@1680: assert(bs->has_write_ref_array_opt(), "Barrier set must have ref array opt"); ysr@1680: assert(bs->has_write_ref_array_pre_opt(), "For pre-barrier as well."); coleenp@548: if (src == dst) { coleenp@548: // same object, no check ysr@1680: bs->write_ref_array_pre(dst_addr, length); coleenp@548: Copy::conjoint_oops_atomic(src_addr, dst_addr, length); ysr@1680: bs->write_ref_array((HeapWord*)dst_addr, length); coleenp@548: return ac_ok; coleenp@548: } else { coleenp@548: klassOop bound = objArrayKlass::cast(dst->klass())->element_klass(); coleenp@548: klassOop stype = objArrayKlass::cast(src->klass())->element_klass(); coleenp@548: if (stype == bound || Klass::cast(stype)->is_subtype_of(bound)) { coleenp@548: // Elements are guaranteed to be subtypes, so no check necessary ysr@1680: bs->write_ref_array_pre(dst_addr, length); coleenp@548: Copy::conjoint_oops_atomic(src_addr, dst_addr, length); ysr@1680: bs->write_ref_array((HeapWord*)dst_addr, length); coleenp@548: return ac_ok; coleenp@548: } coleenp@548: } coleenp@548: return ac_failed; coleenp@548: } coleenp@548: duke@435: // fast and direct copy of arrays; returning -1, means that an exception may be thrown duke@435: // and we did not copy anything duke@435: JRT_LEAF(int, Runtime1::arraycopy(oopDesc* src, int src_pos, oopDesc* dst, int dst_pos, int length)) duke@435: #ifndef PRODUCT duke@435: _generic_arraycopy_cnt++; // Slow-path oop array copy duke@435: #endif duke@435: duke@435: if (src == NULL || dst == NULL || src_pos < 0 || dst_pos < 0 || length < 0) return ac_failed; duke@435: if (!dst->is_array() || !src->is_array()) return ac_failed; duke@435: if ((unsigned int) arrayOop(src)->length() < (unsigned int)src_pos + (unsigned int)length) return ac_failed; duke@435: if ((unsigned int) arrayOop(dst)->length() < (unsigned int)dst_pos + (unsigned int)length) return ac_failed; duke@435: duke@435: if (length == 0) return ac_ok; duke@435: if (src->is_typeArray()) { duke@435: const klassOop klass_oop = src->klass(); duke@435: if (klass_oop != dst->klass()) return ac_failed; duke@435: typeArrayKlass* klass = typeArrayKlass::cast(klass_oop); duke@435: const int l2es = klass->log2_element_size(); duke@435: const int ihs = klass->array_header_in_bytes() / wordSize; duke@435: char* src_addr = (char*) ((oopDesc**)src + ihs) + (src_pos << l2es); duke@435: char* dst_addr = (char*) ((oopDesc**)dst + ihs) + (dst_pos << l2es); duke@435: // Potential problem: memmove is not guaranteed to be word atomic duke@435: // Revisit in Merlin duke@435: memmove(dst_addr, src_addr, length << l2es); duke@435: return ac_ok; duke@435: } else if (src->is_objArray() && dst->is_objArray()) { iveresov@2344: if (UseCompressedOops) { coleenp@548: narrowOop *src_addr = objArrayOop(src)->obj_at_addr(src_pos); coleenp@548: narrowOop *dst_addr = objArrayOop(dst)->obj_at_addr(dst_pos); coleenp@548: return obj_arraycopy_work(src, src_addr, dst, dst_addr, length); duke@435: } else { coleenp@548: oop *src_addr = objArrayOop(src)->obj_at_addr(src_pos); coleenp@548: oop *dst_addr = objArrayOop(dst)->obj_at_addr(dst_pos); coleenp@548: return obj_arraycopy_work(src, src_addr, dst, dst_addr, length); duke@435: } duke@435: } duke@435: return ac_failed; duke@435: JRT_END duke@435: duke@435: duke@435: JRT_LEAF(void, Runtime1::primitive_arraycopy(HeapWord* src, HeapWord* dst, int length)) duke@435: #ifndef PRODUCT duke@435: _primitive_arraycopy_cnt++; duke@435: #endif duke@435: duke@435: if (length == 0) return; duke@435: // Not guaranteed to be word atomic, but that doesn't matter duke@435: // for anything but an oop array, which is covered by oop_arraycopy. kvn@1958: Copy::conjoint_jbytes(src, dst, length); duke@435: JRT_END duke@435: duke@435: JRT_LEAF(void, Runtime1::oop_arraycopy(HeapWord* src, HeapWord* dst, int num)) duke@435: #ifndef PRODUCT duke@435: _oop_arraycopy_cnt++; duke@435: #endif duke@435: duke@435: if (num == 0) return; ysr@1680: BarrierSet* bs = Universe::heap()->barrier_set(); ysr@1680: assert(bs->has_write_ref_array_opt(), "Barrier set must have ref array opt"); ysr@1680: assert(bs->has_write_ref_array_pre_opt(), "For pre-barrier as well."); ysr@1680: if (UseCompressedOops) { ysr@1680: bs->write_ref_array_pre((narrowOop*)dst, num); iveresov@2344: Copy::conjoint_oops_atomic((narrowOop*) src, (narrowOop*) dst, num); ysr@1680: } else { ysr@1680: bs->write_ref_array_pre((oop*)dst, num); iveresov@2344: Copy::conjoint_oops_atomic((oop*) src, (oop*) dst, num); ysr@1680: } ysr@1680: bs->write_ref_array(dst, num); duke@435: JRT_END duke@435: duke@435: duke@435: #ifndef PRODUCT duke@435: void Runtime1::print_statistics() { duke@435: tty->print_cr("C1 Runtime statistics:"); duke@435: tty->print_cr(" _resolve_invoke_virtual_cnt: %d", SharedRuntime::_resolve_virtual_ctr); duke@435: tty->print_cr(" _resolve_invoke_opt_virtual_cnt: %d", SharedRuntime::_resolve_opt_virtual_ctr); duke@435: tty->print_cr(" _resolve_invoke_static_cnt: %d", SharedRuntime::_resolve_static_ctr); duke@435: tty->print_cr(" _handle_wrong_method_cnt: %d", SharedRuntime::_wrong_method_ctr); duke@435: tty->print_cr(" _ic_miss_cnt: %d", SharedRuntime::_ic_miss_ctr); duke@435: tty->print_cr(" _generic_arraycopy_cnt: %d", _generic_arraycopy_cnt); duke@435: tty->print_cr(" _primitive_arraycopy_cnt: %d", _primitive_arraycopy_cnt); duke@435: tty->print_cr(" _oop_arraycopy_cnt: %d", _oop_arraycopy_cnt); duke@435: tty->print_cr(" _arraycopy_slowcase_cnt: %d", _arraycopy_slowcase_cnt); duke@435: duke@435: tty->print_cr(" _new_type_array_slowcase_cnt: %d", _new_type_array_slowcase_cnt); duke@435: tty->print_cr(" _new_object_array_slowcase_cnt: %d", _new_object_array_slowcase_cnt); duke@435: tty->print_cr(" _new_instance_slowcase_cnt: %d", _new_instance_slowcase_cnt); duke@435: tty->print_cr(" _new_multi_array_slowcase_cnt: %d", _new_multi_array_slowcase_cnt); duke@435: tty->print_cr(" _monitorenter_slowcase_cnt: %d", _monitorenter_slowcase_cnt); duke@435: tty->print_cr(" _monitorexit_slowcase_cnt: %d", _monitorexit_slowcase_cnt); duke@435: tty->print_cr(" _patch_code_slowcase_cnt: %d", _patch_code_slowcase_cnt); duke@435: duke@435: tty->print_cr(" _throw_range_check_exception_count: %d:", _throw_range_check_exception_count); duke@435: tty->print_cr(" _throw_index_exception_count: %d:", _throw_index_exception_count); duke@435: tty->print_cr(" _throw_div0_exception_count: %d:", _throw_div0_exception_count); duke@435: tty->print_cr(" _throw_null_pointer_exception_count: %d:", _throw_null_pointer_exception_count); duke@435: tty->print_cr(" _throw_class_cast_exception_count: %d:", _throw_class_cast_exception_count); duke@435: tty->print_cr(" _throw_incompatible_class_change_error_count: %d:", _throw_incompatible_class_change_error_count); duke@435: tty->print_cr(" _throw_array_store_exception_count: %d:", _throw_array_store_exception_count); duke@435: tty->print_cr(" _throw_count: %d:", _throw_count); duke@435: duke@435: SharedRuntime::print_ic_miss_histogram(); duke@435: tty->cr(); duke@435: } duke@435: #endif // PRODUCT