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