Path: blob/jdk8u272-b10-aarch32-20201026/hotspot/src/share/vm/c1/c1_Runtime1.cpp
83404 views
/*1* Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#include "precompiled.hpp"25#include "asm/codeBuffer.hpp"26#include "c1/c1_CodeStubs.hpp"27#include "c1/c1_Defs.hpp"28#include "c1/c1_FrameMap.hpp"29#include "c1/c1_LIRAssembler.hpp"30#include "c1/c1_MacroAssembler.hpp"31#include "c1/c1_Runtime1.hpp"32#include "classfile/systemDictionary.hpp"33#include "classfile/vmSymbols.hpp"34#include "code/codeBlob.hpp"35#include "code/compiledIC.hpp"36#include "code/pcDesc.hpp"37#include "code/scopeDesc.hpp"38#include "code/vtableStubs.hpp"39#include "compiler/disassembler.hpp"40#include "gc_interface/collectedHeap.hpp"41#include "interpreter/bytecode.hpp"42#include "interpreter/interpreter.hpp"43#include "jfr/support/jfrIntrinsics.hpp"44#include "memory/allocation.inline.hpp"45#include "memory/barrierSet.hpp"46#include "memory/oopFactory.hpp"47#include "memory/resourceArea.hpp"48#include "oops/objArrayKlass.hpp"49#include "oops/oop.inline.hpp"50#include "runtime/biasedLocking.hpp"51#include "runtime/compilationPolicy.hpp"52#include "runtime/interfaceSupport.hpp"53#include "runtime/javaCalls.hpp"54#include "runtime/sharedRuntime.hpp"55#include "runtime/threadCritical.hpp"56#include "runtime/vframe.hpp"57#include "runtime/vframeArray.hpp"58#include "utilities/copy.hpp"59#include "utilities/events.hpp"606162// Implementation of StubAssembler6364StubAssembler::StubAssembler(CodeBuffer* code, const char * name, int stub_id) : C1_MacroAssembler(code) {65_name = name;66_must_gc_arguments = false;67_frame_size = no_frame_size;68_num_rt_args = 0;69_stub_id = stub_id;70}717273void StubAssembler::set_info(const char* name, bool must_gc_arguments) {74_name = name;75_must_gc_arguments = must_gc_arguments;76}777879void StubAssembler::set_frame_size(int size) {80if (_frame_size == no_frame_size) {81_frame_size = size;82}83assert(_frame_size == size, "can't change the frame size");84}858687void StubAssembler::set_num_rt_args(int args) {88if (_num_rt_args == 0) {89_num_rt_args = args;90}91assert(_num_rt_args == args, "can't change the number of args");92}9394// Implementation of Runtime19596CodeBlob* Runtime1::_blobs[Runtime1::number_of_ids];97const char *Runtime1::_blob_names[] = {98RUNTIME1_STUBS(STUB_NAME, LAST_STUB_NAME)99};100101#ifndef PRODUCT102// statistics103int Runtime1::_generic_arraycopy_cnt = 0;104int Runtime1::_primitive_arraycopy_cnt = 0;105int Runtime1::_oop_arraycopy_cnt = 0;106int Runtime1::_generic_arraycopystub_cnt = 0;107int Runtime1::_arraycopy_slowcase_cnt = 0;108int Runtime1::_arraycopy_checkcast_cnt = 0;109int Runtime1::_arraycopy_checkcast_attempt_cnt = 0;110int Runtime1::_new_type_array_slowcase_cnt = 0;111int Runtime1::_new_object_array_slowcase_cnt = 0;112int Runtime1::_new_instance_slowcase_cnt = 0;113int Runtime1::_new_multi_array_slowcase_cnt = 0;114int Runtime1::_monitorenter_slowcase_cnt = 0;115int Runtime1::_monitorexit_slowcase_cnt = 0;116int Runtime1::_patch_code_slowcase_cnt = 0;117int Runtime1::_throw_range_check_exception_count = 0;118int Runtime1::_throw_index_exception_count = 0;119int Runtime1::_throw_div0_exception_count = 0;120int Runtime1::_throw_null_pointer_exception_count = 0;121int Runtime1::_throw_class_cast_exception_count = 0;122int Runtime1::_throw_incompatible_class_change_error_count = 0;123int Runtime1::_throw_array_store_exception_count = 0;124int Runtime1::_throw_count = 0;125126static int _byte_arraycopy_cnt = 0;127static int _short_arraycopy_cnt = 0;128static int _int_arraycopy_cnt = 0;129static int _long_arraycopy_cnt = 0;130static int _oop_arraycopy_cnt = 0;131132address Runtime1::arraycopy_count_address(BasicType type) {133switch (type) {134case T_BOOLEAN:135case T_BYTE: return (address)&_byte_arraycopy_cnt;136case T_CHAR:137case T_SHORT: return (address)&_short_arraycopy_cnt;138case T_FLOAT:139case T_INT: return (address)&_int_arraycopy_cnt;140case T_DOUBLE:141case T_LONG: return (address)&_long_arraycopy_cnt;142case T_ARRAY:143case T_OBJECT: return (address)&_oop_arraycopy_cnt;144default:145ShouldNotReachHere();146return NULL;147}148}149150151#endif152153// Simple helper to see if the caller of a runtime stub which154// entered the VM has been deoptimized155156static bool caller_is_deopted() {157JavaThread* thread = JavaThread::current();158RegisterMap reg_map(thread, false);159frame runtime_frame = thread->last_frame();160frame caller_frame = runtime_frame.sender(®_map);161assert(caller_frame.is_compiled_frame(), "must be compiled");162return caller_frame.is_deoptimized_frame();163}164165// Stress deoptimization166static void deopt_caller() {167if ( !caller_is_deopted()) {168JavaThread* thread = JavaThread::current();169RegisterMap reg_map(thread, false);170frame runtime_frame = thread->last_frame();171frame caller_frame = runtime_frame.sender(®_map);172Deoptimization::deoptimize_frame(thread, caller_frame.id());173assert(caller_is_deopted(), "Must be deoptimized");174}175}176177178void Runtime1::generate_blob_for(BufferBlob* buffer_blob, StubID id) {179assert(0 <= id && id < number_of_ids, "illegal stub id");180ResourceMark rm;181// create code buffer for code storage182CodeBuffer code(buffer_blob);183184Compilation::setup_code_buffer(&code, 0);185186// create assembler for code generation187StubAssembler* sasm = new StubAssembler(&code, name_for(id), id);188// generate code for runtime stub189OopMapSet* oop_maps;190oop_maps = generate_code_for(id, sasm);191assert(oop_maps == NULL || sasm->frame_size() != no_frame_size,192"if stub has an oop map it must have a valid frame size");193194#ifdef ASSERT195// Make sure that stubs that need oopmaps have them196switch (id) {197// These stubs don't need to have an oopmap198case dtrace_object_alloc_id:199case g1_pre_barrier_slow_id:200case g1_post_barrier_slow_id:201case slow_subtype_check_id:202case fpu2long_stub_id:203case unwind_exception_id:204case counter_overflow_id:205#if defined(SPARC) || defined(PPC)206case handle_exception_nofpu_id: // Unused on sparc207#endif208break;209210// All other stubs should have oopmaps211default:212assert(oop_maps != NULL, "must have an oopmap");213}214#endif215216// align so printing shows nop's instead of random code at the end (SimpleStubs are aligned)217sasm->align(BytesPerWord);218// make sure all code is in code buffer219sasm->flush();220// create blob - distinguish a few special cases221CodeBlob* blob = RuntimeStub::new_runtime_stub(name_for(id),222&code,223CodeOffsets::frame_never_safe,224sasm->frame_size(),225oop_maps,226sasm->must_gc_arguments());227// install blob228assert(blob != NULL, "blob must exist");229_blobs[id] = blob;230}231232233void Runtime1::initialize(BufferBlob* blob) {234// platform-dependent initialization235initialize_pd();236// generate stubs237for (int id = 0; id < number_of_ids; id++) generate_blob_for(blob, (StubID)id);238// printing239#ifndef PRODUCT240if (PrintSimpleStubs) {241ResourceMark rm;242for (int id = 0; id < number_of_ids; id++) {243_blobs[id]->print();244if (_blobs[id]->oop_maps() != NULL) {245_blobs[id]->oop_maps()->print();246}247}248}249#endif250}251252253CodeBlob* Runtime1::blob_for(StubID id) {254assert(0 <= id && id < number_of_ids, "illegal stub id");255return _blobs[id];256}257258259const char* Runtime1::name_for(StubID id) {260assert(0 <= id && id < number_of_ids, "illegal stub id");261return _blob_names[id];262}263264const char* Runtime1::name_for_address(address entry) {265for (int id = 0; id < number_of_ids; id++) {266if (entry == entry_for((StubID)id)) return name_for((StubID)id);267}268269#define FUNCTION_CASE(a, f) \270if ((intptr_t)a == CAST_FROM_FN_PTR(intptr_t, f)) return #f271272FUNCTION_CASE(entry, os::javaTimeMillis);273FUNCTION_CASE(entry, os::javaTimeNanos);274FUNCTION_CASE(entry, SharedRuntime::OSR_migration_end);275FUNCTION_CASE(entry, SharedRuntime::d2f);276FUNCTION_CASE(entry, SharedRuntime::d2i);277FUNCTION_CASE(entry, SharedRuntime::d2l);278FUNCTION_CASE(entry, SharedRuntime::dcos);279FUNCTION_CASE(entry, SharedRuntime::dexp);280FUNCTION_CASE(entry, SharedRuntime::dlog);281FUNCTION_CASE(entry, SharedRuntime::dlog10);282FUNCTION_CASE(entry, SharedRuntime::dpow);283FUNCTION_CASE(entry, SharedRuntime::drem);284FUNCTION_CASE(entry, SharedRuntime::dsin);285FUNCTION_CASE(entry, SharedRuntime::dtan);286FUNCTION_CASE(entry, SharedRuntime::f2i);287FUNCTION_CASE(entry, SharedRuntime::f2l);288FUNCTION_CASE(entry, SharedRuntime::frem);289FUNCTION_CASE(entry, SharedRuntime::l2d);290FUNCTION_CASE(entry, SharedRuntime::l2f);291FUNCTION_CASE(entry, SharedRuntime::ldiv);292FUNCTION_CASE(entry, SharedRuntime::lmul);293FUNCTION_CASE(entry, SharedRuntime::lrem);294FUNCTION_CASE(entry, SharedRuntime::lrem);295FUNCTION_CASE(entry, SharedRuntime::dtrace_method_entry);296FUNCTION_CASE(entry, SharedRuntime::dtrace_method_exit);297FUNCTION_CASE(entry, is_instance_of);298FUNCTION_CASE(entry, trace_block_entry);299#ifdef JFR_HAVE_INTRINSICS300FUNCTION_CASE(entry, JFR_TIME_FUNCTION);301#endif302FUNCTION_CASE(entry, StubRoutines::updateBytesCRC32());303304#undef FUNCTION_CASE305306// Soft float adds more runtime names.307return pd_name_for_address(entry);308}309310311JRT_ENTRY(void, Runtime1::new_instance(JavaThread* thread, Klass* klass))312NOT_PRODUCT(_new_instance_slowcase_cnt++;)313314assert(klass->is_klass(), "not a class");315Handle holder(THREAD, klass->klass_holder()); // keep the klass alive316instanceKlassHandle h(thread, klass);317h->check_valid_for_instantiation(true, CHECK);318// make sure klass is initialized319h->initialize(CHECK);320// allocate instance and return via TLS321oop obj = h->allocate_instance(CHECK);322thread->set_vm_result(obj);323JRT_END324325326JRT_ENTRY(void, Runtime1::new_type_array(JavaThread* thread, Klass* klass, jint length))327NOT_PRODUCT(_new_type_array_slowcase_cnt++;)328// Note: no handle for klass needed since they are not used329// anymore after new_typeArray() and no GC can happen before.330// (This may have to change if this code changes!)331assert(klass->is_klass(), "not a class");332BasicType elt_type = TypeArrayKlass::cast(klass)->element_type();333oop obj = oopFactory::new_typeArray(elt_type, length, CHECK);334thread->set_vm_result(obj);335// This is pretty rare but this runtime patch is stressful to deoptimization336// if we deoptimize here so force a deopt to stress the path.337if (DeoptimizeALot) {338deopt_caller();339}340341JRT_END342343344JRT_ENTRY(void, Runtime1::new_object_array(JavaThread* thread, Klass* array_klass, jint length))345NOT_PRODUCT(_new_object_array_slowcase_cnt++;)346347// Note: no handle for klass needed since they are not used348// anymore after new_objArray() and no GC can happen before.349// (This may have to change if this code changes!)350assert(array_klass->is_klass(), "not a class");351Handle holder(THREAD, array_klass->klass_holder()); // keep the klass alive352Klass* elem_klass = ObjArrayKlass::cast(array_klass)->element_klass();353objArrayOop obj = oopFactory::new_objArray(elem_klass, length, CHECK);354thread->set_vm_result(obj);355// This is pretty rare but this runtime patch is stressful to deoptimization356// if we deoptimize here so force a deopt to stress the path.357if (DeoptimizeALot) {358deopt_caller();359}360JRT_END361362363JRT_ENTRY(void, Runtime1::new_multi_array(JavaThread* thread, Klass* klass, int rank, jint* dims))364NOT_PRODUCT(_new_multi_array_slowcase_cnt++;)365366assert(klass->is_klass(), "not a class");367assert(rank >= 1, "rank must be nonzero");368Handle holder(THREAD, klass->klass_holder()); // keep the klass alive369oop obj = ArrayKlass::cast(klass)->multi_allocate(rank, dims, CHECK);370thread->set_vm_result(obj);371JRT_END372373374JRT_ENTRY(void, Runtime1::unimplemented_entry(JavaThread* thread, StubID id))375tty->print_cr("Runtime1::entry_for(%d) returned unimplemented entry point", id);376JRT_END377378379JRT_ENTRY(void, Runtime1::throw_array_store_exception(JavaThread* thread, oopDesc* obj))380ResourceMark rm(thread);381const char* klass_name = obj->klass()->external_name();382SharedRuntime::throw_and_post_jvmti_exception(thread, vmSymbols::java_lang_ArrayStoreException(), klass_name);383JRT_END384385386// counter_overflow() is called from within C1-compiled methods. The enclosing method is the method387// associated with the top activation record. The inlinee (that is possibly included in the enclosing388// method) method oop is passed as an argument. In order to do that it is embedded in the code as389// a constant.390static nmethod* counter_overflow_helper(JavaThread* THREAD, int branch_bci, Method* m) {391nmethod* osr_nm = NULL;392methodHandle method(THREAD, m);393394RegisterMap map(THREAD, false);395frame fr = THREAD->last_frame().sender(&map);396nmethod* nm = (nmethod*) fr.cb();397assert(nm!= NULL && nm->is_nmethod(), "Sanity check");398methodHandle enclosing_method(THREAD, nm->method());399400CompLevel level = (CompLevel)nm->comp_level();401int bci = InvocationEntryBci;402if (branch_bci != InvocationEntryBci) {403// Compute desination bci404address pc = method()->code_base() + branch_bci;405Bytecodes::Code branch = Bytecodes::code_at(method(), pc);406int offset = 0;407switch (branch) {408case Bytecodes::_if_icmplt: case Bytecodes::_iflt:409case Bytecodes::_if_icmpgt: case Bytecodes::_ifgt:410case Bytecodes::_if_icmple: case Bytecodes::_ifle:411case Bytecodes::_if_icmpge: case Bytecodes::_ifge:412case Bytecodes::_if_icmpeq: case Bytecodes::_if_acmpeq: case Bytecodes::_ifeq:413case Bytecodes::_if_icmpne: case Bytecodes::_if_acmpne: case Bytecodes::_ifne:414case Bytecodes::_ifnull: case Bytecodes::_ifnonnull: case Bytecodes::_goto:415offset = (int16_t)Bytes::get_Java_u2(pc + 1);416break;417case Bytecodes::_goto_w:418offset = Bytes::get_Java_u4(pc + 1);419break;420default: ;421}422bci = branch_bci + offset;423}424assert(!HAS_PENDING_EXCEPTION, "Should not have any exceptions pending");425osr_nm = CompilationPolicy::policy()->event(enclosing_method, method, branch_bci, bci, level, nm, THREAD);426assert(!HAS_PENDING_EXCEPTION, "Event handler should not throw any exceptions");427return osr_nm;428}429430JRT_BLOCK_ENTRY(address, Runtime1::counter_overflow(JavaThread* thread, int bci, Method* method))431nmethod* osr_nm;432JRT_BLOCK433osr_nm = counter_overflow_helper(thread, bci, method);434if (osr_nm != NULL) {435RegisterMap map(thread, false);436frame fr = thread->last_frame().sender(&map);437Deoptimization::deoptimize_frame(thread, fr.id());438}439JRT_BLOCK_END440return NULL;441JRT_END442443extern void vm_exit(int code);444445// Enter this method from compiled code handler below. This is where we transition446// to VM mode. This is done as a helper routine so that the method called directly447// from compiled code does not have to transition to VM. This allows the entry448// method to see if the nmethod that we have just looked up a handler for has449// been deoptimized while we were in the vm. This simplifies the assembly code450// cpu directories.451//452// We are entering here from exception stub (via the entry method below)453// If there is a compiled exception handler in this method, we will continue there;454// otherwise we will unwind the stack and continue at the caller of top frame method455// Note: we enter in Java using a special JRT wrapper. This wrapper allows us to456// control the area where we can allow a safepoint. After we exit the safepoint area we can457// check to see if the handler we are going to return is now in a nmethod that has458// been deoptimized. If that is the case we return the deopt blob459// unpack_with_exception entry instead. This makes life for the exception blob easier460// because making that same check and diverting is painful from assembly language.461JRT_ENTRY_NO_ASYNC(static address, exception_handler_for_pc_helper(JavaThread* thread, oopDesc* ex, address pc, nmethod*& nm))462// Reset method handle flag.463thread->set_is_method_handle_return(false);464465Handle exception(thread, ex);466nm = CodeCache::find_nmethod(pc);467assert(nm != NULL, "this is not an nmethod");468// Adjust the pc as needed/469if (nm->is_deopt_pc(pc)) {470RegisterMap map(thread, false);471frame exception_frame = thread->last_frame().sender(&map);472// if the frame isn't deopted then pc must not correspond to the caller of last_frame473assert(exception_frame.is_deoptimized_frame(), "must be deopted");474pc = exception_frame.pc();475}476#ifdef ASSERT477assert(exception.not_null(), "NULL exceptions should be handled by throw_exception");478assert(exception->is_oop(), "just checking");479// Check that exception is a subclass of Throwable, otherwise we have a VerifyError480if (!(exception->is_a(SystemDictionary::Throwable_klass()))) {481if (ExitVMOnVerifyError) vm_exit(-1);482ShouldNotReachHere();483}484#endif485486// Check the stack guard pages and reenable them if necessary and there is487// enough space on the stack to do so. Use fast exceptions only if the guard488// pages are enabled.489bool guard_pages_enabled = thread->stack_yellow_zone_enabled();490if (!guard_pages_enabled) guard_pages_enabled = thread->reguard_stack();491492if (JvmtiExport::can_post_on_exceptions()) {493// To ensure correct notification of exception catches and throws494// we have to deoptimize here. If we attempted to notify the495// catches and throws during this exception lookup it's possible496// we could deoptimize on the way out of the VM and end back in497// the interpreter at the throw site. This would result in double498// notifications since the interpreter would also notify about499// these same catches and throws as it unwound the frame.500501RegisterMap reg_map(thread);502frame stub_frame = thread->last_frame();503frame caller_frame = stub_frame.sender(®_map);504505// We don't really want to deoptimize the nmethod itself since we506// can actually continue in the exception handler ourselves but I507// don't see an easy way to have the desired effect.508Deoptimization::deoptimize_frame(thread, caller_frame.id());509assert(caller_is_deopted(), "Must be deoptimized");510511return SharedRuntime::deopt_blob()->unpack_with_exception_in_tls();512}513514// ExceptionCache is used only for exceptions at call sites and not for implicit exceptions515if (guard_pages_enabled) {516address fast_continuation = nm->handler_for_exception_and_pc(exception, pc);517if (fast_continuation != NULL) {518// Set flag if return address is a method handle call site.519thread->set_is_method_handle_return(nm->is_method_handle_return(pc));520return fast_continuation;521}522}523524// If the stack guard pages are enabled, check whether there is a handler in525// the current method. Otherwise (guard pages disabled), force an unwind and526// skip the exception cache update (i.e., just leave continuation==NULL).527address continuation = NULL;528if (guard_pages_enabled) {529530// New exception handling mechanism can support inlined methods531// with exception handlers since the mappings are from PC to PC532533// debugging support534// tracing535if (TraceExceptions) {536ttyLocker ttyl;537ResourceMark rm;538tty->print_cr("Exception <%s> (" INTPTR_FORMAT ") thrown in compiled method <%s> at PC " INTPTR_FORMAT " for thread " INTPTR_FORMAT "",539exception->print_value_string(), p2i((address)exception()), nm->method()->print_value_string(), p2i(pc), p2i(thread));540}541// for AbortVMOnException flag542NOT_PRODUCT(Exceptions::debug_check_abort(exception));543544// Clear out the exception oop and pc since looking up an545// exception handler can cause class loading, which might throw an546// exception and those fields are expected to be clear during547// normal bytecode execution.548thread->clear_exception_oop_and_pc();549550bool recursive_exception = false;551continuation = SharedRuntime::compute_compiled_exc_handler(nm, pc, exception, false, false, recursive_exception);552// If an exception was thrown during exception dispatch, the exception oop may have changed553thread->set_exception_oop(exception());554thread->set_exception_pc(pc);555556// the exception cache is used only by non-implicit exceptions557// Update the exception cache only when there didn't happen558// another exception during the computation of the compiled559// exception handler. Checking for exception oop equality is not560// sufficient because some exceptions are pre-allocated and reused.561if (continuation != NULL && !recursive_exception) {562nm->add_handler_for_exception_and_pc(exception, pc, continuation);563}564}565566thread->set_vm_result(exception());567// Set flag if return address is a method handle call site.568thread->set_is_method_handle_return(nm->is_method_handle_return(pc));569570if (TraceExceptions) {571ttyLocker ttyl;572ResourceMark rm;573tty->print_cr("Thread " PTR_FORMAT " continuing at PC " PTR_FORMAT " for exception thrown at PC " PTR_FORMAT,574p2i(thread), p2i(continuation), p2i(pc));575}576577return continuation;578JRT_END579580// Enter this method from compiled code only if there is a Java exception handler581// in the method handling the exception.582// We are entering here from exception stub. We don't do a normal VM transition here.583// We do it in a helper. This is so we can check to see if the nmethod we have just584// searched for an exception handler has been deoptimized in the meantime.585address Runtime1::exception_handler_for_pc(JavaThread* thread) {586oop exception = thread->exception_oop();587address pc = thread->exception_pc();588// Still in Java mode589DEBUG_ONLY(ResetNoHandleMark rnhm);590nmethod* nm = NULL;591address continuation = NULL;592{593// Enter VM mode by calling the helper594ResetNoHandleMark rnhm;595continuation = exception_handler_for_pc_helper(thread, exception, pc, nm);596}597// Back in JAVA, use no oops DON'T safepoint598599// Now check to see if the nmethod we were called from is now deoptimized.600// If so we must return to the deopt blob and deoptimize the nmethod601if (nm != NULL && caller_is_deopted()) {602continuation = SharedRuntime::deopt_blob()->unpack_with_exception_in_tls();603}604605assert(continuation != NULL, "no handler found");606return continuation;607}608609610JRT_ENTRY(void, Runtime1::throw_range_check_exception(JavaThread* thread, int index))611NOT_PRODUCT(_throw_range_check_exception_count++;)612char message[jintAsStringSize];613sprintf(message, "%d", index);614SharedRuntime::throw_and_post_jvmti_exception(thread, vmSymbols::java_lang_ArrayIndexOutOfBoundsException(), message);615JRT_END616617618JRT_ENTRY(void, Runtime1::throw_index_exception(JavaThread* thread, int index))619NOT_PRODUCT(_throw_index_exception_count++;)620char message[16];621sprintf(message, "%d", index);622SharedRuntime::throw_and_post_jvmti_exception(thread, vmSymbols::java_lang_IndexOutOfBoundsException(), message);623JRT_END624625626JRT_ENTRY(void, Runtime1::throw_div0_exception(JavaThread* thread))627NOT_PRODUCT(_throw_div0_exception_count++;)628SharedRuntime::throw_and_post_jvmti_exception(thread, vmSymbols::java_lang_ArithmeticException(), "/ by zero");629JRT_END630631632JRT_ENTRY(void, Runtime1::throw_null_pointer_exception(JavaThread* thread))633NOT_PRODUCT(_throw_null_pointer_exception_count++;)634SharedRuntime::throw_and_post_jvmti_exception(thread, vmSymbols::java_lang_NullPointerException());635JRT_END636637638JRT_ENTRY(void, Runtime1::throw_class_cast_exception(JavaThread* thread, oopDesc* object))639NOT_PRODUCT(_throw_class_cast_exception_count++;)640ResourceMark rm(thread);641char* message = SharedRuntime::generate_class_cast_message(642thread, object->klass()->external_name());643SharedRuntime::throw_and_post_jvmti_exception(644thread, vmSymbols::java_lang_ClassCastException(), message);645JRT_END646647648JRT_ENTRY(void, Runtime1::throw_incompatible_class_change_error(JavaThread* thread))649NOT_PRODUCT(_throw_incompatible_class_change_error_count++;)650ResourceMark rm(thread);651SharedRuntime::throw_and_post_jvmti_exception(thread, vmSymbols::java_lang_IncompatibleClassChangeError());652JRT_END653654655JRT_ENTRY_NO_ASYNC(void, Runtime1::monitorenter(JavaThread* thread, oopDesc* obj, BasicObjectLock* lock))656NOT_PRODUCT(_monitorenter_slowcase_cnt++;)657if (PrintBiasedLockingStatistics) {658Atomic::inc(BiasedLocking::slow_path_entry_count_addr());659}660Handle h_obj(thread, obj);661assert(h_obj()->is_oop(), "must be NULL or an object");662if (UseBiasedLocking) {663// Retry fast entry if bias is revoked to avoid unnecessary inflation664ObjectSynchronizer::fast_enter(h_obj, lock->lock(), true, CHECK);665} else {666if (UseFastLocking) {667// When using fast locking, the compiled code has already tried the fast case668assert(obj == lock->obj(), "must match");669ObjectSynchronizer::slow_enter(h_obj, lock->lock(), THREAD);670} else {671lock->set_obj(obj);672ObjectSynchronizer::fast_enter(h_obj, lock->lock(), false, THREAD);673}674}675JRT_END676677678JRT_LEAF(void, Runtime1::monitorexit(JavaThread* thread, BasicObjectLock* lock))679NOT_PRODUCT(_monitorexit_slowcase_cnt++;)680assert(thread == JavaThread::current(), "threads must correspond");681assert(thread->last_Java_sp(), "last_Java_sp must be set");682// monitorexit is non-blocking (leaf routine) => no exceptions can be thrown683EXCEPTION_MARK;684685oop obj = lock->obj();686assert(obj->is_oop(), "must be NULL or an object");687if (UseFastLocking) {688// When using fast locking, the compiled code has already tried the fast case689ObjectSynchronizer::slow_exit(obj, lock->lock(), THREAD);690} else {691ObjectSynchronizer::fast_exit(obj, lock->lock(), THREAD);692}693JRT_END694695// Cf. OptoRuntime::deoptimize_caller_frame696JRT_ENTRY(void, Runtime1::deoptimize(JavaThread* thread))697// Called from within the owner thread, so no need for safepoint698RegisterMap reg_map(thread, false);699frame stub_frame = thread->last_frame();700assert(stub_frame.is_runtime_frame(), "sanity check");701frame caller_frame = stub_frame.sender(®_map);702703// We are coming from a compiled method; check this is true.704assert(CodeCache::find_nmethod(caller_frame.pc()) != NULL, "sanity");705706// Deoptimize the caller frame.707Deoptimization::deoptimize_frame(thread, caller_frame.id());708709// Return to the now deoptimized frame.710JRT_END711712713static Klass* resolve_field_return_klass(methodHandle caller, int bci, TRAPS) {714Bytecode_field field_access(caller, bci);715// This can be static or non-static field access716Bytecodes::Code code = field_access.code();717718// We must load class, initialize class and resolvethe field719fieldDescriptor result; // initialize class if needed720constantPoolHandle constants(THREAD, caller->constants());721LinkResolver::resolve_field_access(result, constants, field_access.index(), Bytecodes::java_code(code), CHECK_NULL);722return result.field_holder();723}724725726//727// This routine patches sites where a class wasn't loaded or728// initialized at the time the code was generated. It handles729// references to classes, fields and forcing of initialization. Most730// of the cases are straightforward and involving simply forcing731// resolution of a class, rewriting the instruction stream with the732// needed constant and replacing the call in this function with the733// patched code. The case for static field is more complicated since734// the thread which is in the process of initializing a class can735// access it's static fields but other threads can't so the code736// either has to deoptimize when this case is detected or execute a737// check that the current thread is the initializing thread. The738// current739//740// Patches basically look like this:741//742//743// patch_site: jmp patch stub ;; will be patched744// continue: ...745// ...746// ...747// ...748//749// They have a stub which looks like this:750//751// ;; patch body752// movl <const>, reg (for class constants)753// <or> movl [reg1 + <const>], reg (for field offsets)754// <or> movl reg, [reg1 + <const>] (for field offsets)755// <being_init offset> <bytes to copy> <bytes to skip>756// patch_stub: call Runtime1::patch_code (through a runtime stub)757// jmp patch_site758//759//760// A normal patch is done by rewriting the patch body, usually a move,761// and then copying it into place over top of the jmp instruction762// being careful to flush caches and doing it in an MP-safe way. The763// constants following the patch body are used to find various pieces764// of the patch relative to the call site for Runtime1::patch_code.765// The case for getstatic and putstatic is more complicated because766// getstatic and putstatic have special semantics when executing while767// the class is being initialized. getstatic/putstatic on a class768// which is being_initialized may be executed by the initializing769// thread but other threads have to block when they execute it. This770// is accomplished in compiled code by executing a test of the current771// thread against the initializing thread of the class. It's emitted772// as boilerplate in their stub which allows the patched code to be773// executed before it's copied back into the main body of the nmethod.774//775// being_init: get_thread(<tmp reg>776// cmpl [reg1 + <init_thread_offset>], <tmp reg>777// jne patch_stub778// movl [reg1 + <const>], reg (for field offsets) <or>779// movl reg, [reg1 + <const>] (for field offsets)780// jmp continue781// <being_init offset> <bytes to copy> <bytes to skip>782// patch_stub: jmp Runtim1::patch_code (through a runtime stub)783// jmp patch_site784//785// If the class is being initialized the patch body is rewritten and786// the patch site is rewritten to jump to being_init, instead of787// patch_stub. Whenever this code is executed it checks the current788// thread against the intializing thread so other threads will enter789// the runtime and end up blocked waiting the class to finish790// initializing inside the calls to resolve_field below. The791// initializing class will continue on it's way. Once the class is792// fully_initialized, the intializing_thread of the class becomes793// NULL, so the next thread to execute this code will fail the test,794// call into patch_code and complete the patching process by copying795// the patch body back into the main part of the nmethod and resume796// executing.797//798//799800JRT_ENTRY(void, Runtime1::patch_code(JavaThread* thread, Runtime1::StubID stub_id ))801NOT_PRODUCT(_patch_code_slowcase_cnt++;)802803#ifdef AARCH64804// AArch64 does not patch C1-generated code.805ShouldNotReachHere();806#endif807808ResourceMark rm(thread);809RegisterMap reg_map(thread, false);810frame runtime_frame = thread->last_frame();811frame caller_frame = runtime_frame.sender(®_map);812813// last java frame on stack814vframeStream vfst(thread, true);815assert(!vfst.at_end(), "Java frame must exist");816817methodHandle caller_method(THREAD, vfst.method());818// Note that caller_method->code() may not be same as caller_code because of OSR's819// Note also that in the presence of inlining it is not guaranteed820// that caller_method() == caller_code->method()821822int bci = vfst.bci();823Bytecodes::Code code = caller_method()->java_code_at(bci);824825#ifndef PRODUCT826// this is used by assertions in the access_field_patching_id827BasicType patch_field_type = T_ILLEGAL;828#endif // PRODUCT829bool deoptimize_for_volatile = false;830int patch_field_offset = -1;831KlassHandle init_klass(THREAD, NULL); // klass needed by load_klass_patching code832KlassHandle load_klass(THREAD, NULL); // klass needed by load_klass_patching code833Handle mirror(THREAD, NULL); // oop needed by load_mirror_patching code834Handle appendix(THREAD, NULL); // oop needed by appendix_patching code835bool load_klass_or_mirror_patch_id =836(stub_id == Runtime1::load_klass_patching_id || stub_id == Runtime1::load_mirror_patching_id);837838if (stub_id == Runtime1::access_field_patching_id) {839840Bytecode_field field_access(caller_method, bci);841fieldDescriptor result; // initialize class if needed842Bytecodes::Code code = field_access.code();843constantPoolHandle constants(THREAD, caller_method->constants());844LinkResolver::resolve_field_access(result, constants, field_access.index(), Bytecodes::java_code(code), CHECK);845patch_field_offset = result.offset();846847// If we're patching a field which is volatile then at compile it848// must not have been know to be volatile, so the generated code849// isn't correct for a volatile reference. The nmethod has to be850// deoptimized so that the code can be regenerated correctly.851// This check is only needed for access_field_patching since this852// is the path for patching field offsets. load_klass is only853// used for patching references to oops which don't need special854// handling in the volatile case.855deoptimize_for_volatile = result.access_flags().is_volatile();856857#ifndef PRODUCT858patch_field_type = result.field_type();859#endif860} else if (load_klass_or_mirror_patch_id) {861Klass* k = NULL;862switch (code) {863case Bytecodes::_putstatic:864case Bytecodes::_getstatic:865{ Klass* klass = resolve_field_return_klass(caller_method, bci, CHECK);866init_klass = KlassHandle(THREAD, klass);867mirror = Handle(THREAD, klass->java_mirror());868}869break;870case Bytecodes::_new:871{ Bytecode_new bnew(caller_method(), caller_method->bcp_from(bci));872k = caller_method->constants()->klass_at(bnew.index(), CHECK);873}874break;875case Bytecodes::_multianewarray:876{ Bytecode_multianewarray mna(caller_method(), caller_method->bcp_from(bci));877k = caller_method->constants()->klass_at(mna.index(), CHECK);878}879break;880case Bytecodes::_instanceof:881{ Bytecode_instanceof io(caller_method(), caller_method->bcp_from(bci));882k = caller_method->constants()->klass_at(io.index(), CHECK);883}884break;885case Bytecodes::_checkcast:886{ Bytecode_checkcast cc(caller_method(), caller_method->bcp_from(bci));887k = caller_method->constants()->klass_at(cc.index(), CHECK);888}889break;890case Bytecodes::_anewarray:891{ Bytecode_anewarray anew(caller_method(), caller_method->bcp_from(bci));892Klass* ek = caller_method->constants()->klass_at(anew.index(), CHECK);893k = ek->array_klass(CHECK);894}895break;896case Bytecodes::_ldc:897case Bytecodes::_ldc_w:898{899Bytecode_loadconstant cc(caller_method, bci);900oop m = cc.resolve_constant(CHECK);901mirror = Handle(THREAD, m);902}903break;904default: fatal("unexpected bytecode for load_klass_or_mirror_patch_id");905}906// convert to handle907load_klass = KlassHandle(THREAD, k);908} else if (stub_id == load_appendix_patching_id) {909Bytecode_invoke bytecode(caller_method, bci);910Bytecodes::Code bc = bytecode.invoke_code();911912CallInfo info;913constantPoolHandle pool(thread, caller_method->constants());914int index = bytecode.index();915LinkResolver::resolve_invoke(info, Handle(), pool, index, bc, CHECK);916appendix = info.resolved_appendix();917switch (bc) {918case Bytecodes::_invokehandle: {919int cache_index = ConstantPool::decode_cpcache_index(index, true);920assert(cache_index >= 0 && cache_index < pool->cache()->length(), "unexpected cache index");921pool->cache()->entry_at(cache_index)->set_method_handle(pool, info);922break;923}924case Bytecodes::_invokedynamic: {925pool->invokedynamic_cp_cache_entry_at(index)->set_dynamic_call(pool, info);926break;927}928default: fatal("unexpected bytecode for load_appendix_patching_id");929}930} else {931ShouldNotReachHere();932}933934if (deoptimize_for_volatile) {935// At compile time we assumed the field wasn't volatile but after936// loading it turns out it was volatile so we have to throw the937// compiled code out and let it be regenerated.938if (TracePatching) {939tty->print_cr("Deoptimizing for patching volatile field reference");940}941// It's possible the nmethod was invalidated in the last942// safepoint, but if it's still alive then make it not_entrant.943nmethod* nm = CodeCache::find_nmethod(caller_frame.pc());944if (nm != NULL) {945nm->make_not_entrant();946}947948Deoptimization::deoptimize_frame(thread, caller_frame.id());949950// Return to the now deoptimized frame.951}952953// Now copy code back954{955MutexLockerEx ml_patch (Patching_lock, Mutex::_no_safepoint_check_flag);956//957// Deoptimization may have happened while we waited for the lock.958// In that case we don't bother to do any patching we just return959// and let the deopt happen960if (!caller_is_deopted()) {961NativeGeneralJump* jump = nativeGeneralJump_at(caller_frame.pc());962address instr_pc = jump->jump_destination();963NativeInstruction* ni = nativeInstruction_at(instr_pc);964if (ni->is_jump()) {965// the jump has not been patched yet966// The jump destination is slow case and therefore not part of the stubs967// (stubs are only for StaticCalls)968969// format of buffer970// ....971// instr byte 0 <-- copy_buff972// instr byte 1973// ..974// instr byte n-1975// n976// .... <-- call destination977978address stub_location = caller_frame.pc() + PatchingStub::patch_info_offset();979unsigned char* byte_count = (unsigned char*) (stub_location - 1);980unsigned char* byte_skip = (unsigned char*) (stub_location - 2);981unsigned char* being_initialized_entry_offset = (unsigned char*) (stub_location - 3);982address copy_buff = stub_location - *byte_skip - *byte_count;983address being_initialized_entry = stub_location - *being_initialized_entry_offset;984if (TracePatching) {985tty->print_cr(" Patching %s at bci %d at address " INTPTR_FORMAT " (%s)", Bytecodes::name(code), bci,986p2i(instr_pc), (stub_id == Runtime1::access_field_patching_id) ? "field" : "klass");987nmethod* caller_code = CodeCache::find_nmethod(caller_frame.pc());988assert(caller_code != NULL, "nmethod not found");989990// NOTE we use pc() not original_pc() because we already know they are991// identical otherwise we'd have never entered this block of code992993OopMap* map = caller_code->oop_map_for_return_address(caller_frame.pc());994assert(map != NULL, "null check");995map->print();996tty->cr();997998Disassembler::decode(copy_buff, copy_buff + *byte_count, tty);999}1000// depending on the code below, do_patch says whether to copy the patch body back into the nmethod1001bool do_patch = true;1002if (stub_id == Runtime1::access_field_patching_id) {1003// The offset may not be correct if the class was not loaded at code generation time.1004// Set it now.1005NativeMovRegMem* n_move = nativeMovRegMem_at(copy_buff);1006assert(n_move->offset() == 0 || (n_move->offset() == 4 && (patch_field_type == T_DOUBLE || patch_field_type == T_LONG)), "illegal offset for type");1007assert(patch_field_offset >= 0, "illegal offset");1008n_move->add_offset_in_bytes(patch_field_offset);1009} else if (load_klass_or_mirror_patch_id) {1010// If a getstatic or putstatic is referencing a klass which1011// isn't fully initialized, the patch body isn't copied into1012// place until initialization is complete. In this case the1013// patch site is setup so that any threads besides the1014// initializing thread are forced to come into the VM and1015// block.1016do_patch = (code != Bytecodes::_getstatic && code != Bytecodes::_putstatic) ||1017InstanceKlass::cast(init_klass())->is_initialized();1018NativeGeneralJump* jump = nativeGeneralJump_at(instr_pc);1019if (jump->jump_destination() == being_initialized_entry) {1020assert(do_patch == true, "initialization must be complete at this point");1021} else {1022// patch the instruction <move reg, klass>1023NativeMovConstReg* n_copy = nativeMovConstReg_at(copy_buff);10241025assert(n_copy->data() == 0 ||1026n_copy->data() == (intptr_t)Universe::non_oop_word(),1027"illegal init value");1028if (stub_id == Runtime1::load_klass_patching_id) {1029assert(load_klass() != NULL, "klass not set");1030n_copy->set_data((intx) (load_klass()));1031} else {1032assert(mirror() != NULL, "klass not set");1033// Don't need a G1 pre-barrier here since we assert above that data isn't an oop.1034n_copy->set_data(cast_from_oop<intx>(mirror()));1035}10361037if (TracePatching) {1038Disassembler::decode(copy_buff, copy_buff + *byte_count, tty);1039}1040}1041} else if (stub_id == Runtime1::load_appendix_patching_id) {1042NativeMovConstReg* n_copy = nativeMovConstReg_at(copy_buff);1043assert(n_copy->data() == 0 ||1044n_copy->data() == (intptr_t)Universe::non_oop_word(),1045"illegal init value");1046n_copy->set_data(cast_from_oop<intx>(appendix()));10471048if (TracePatching) {1049Disassembler::decode(copy_buff, copy_buff + *byte_count, tty);1050}1051} else {1052ShouldNotReachHere();1053}10541055#if defined(SPARC) || defined(PPC)1056if (load_klass_or_mirror_patch_id ||1057stub_id == Runtime1::load_appendix_patching_id) {1058// Update the location in the nmethod with the proper1059// metadata. When the code was generated, a NULL was stuffed1060// in the metadata table and that table needs to be update to1061// have the right value. On intel the value is kept1062// directly in the instruction instead of in the metadata1063// table, so set_data above effectively updated the value.1064nmethod* nm = CodeCache::find_nmethod(instr_pc);1065assert(nm != NULL, "invalid nmethod_pc");1066RelocIterator mds(nm, copy_buff, copy_buff + 1);1067bool found = false;1068while (mds.next() && !found) {1069if (mds.type() == relocInfo::oop_type) {1070assert(stub_id == Runtime1::load_mirror_patching_id ||1071stub_id == Runtime1::load_appendix_patching_id, "wrong stub id");1072oop_Relocation* r = mds.oop_reloc();1073oop* oop_adr = r->oop_addr();1074*oop_adr = stub_id == Runtime1::load_mirror_patching_id ? mirror() : appendix();1075r->fix_oop_relocation();1076found = true;1077} else if (mds.type() == relocInfo::metadata_type) {1078assert(stub_id == Runtime1::load_klass_patching_id, "wrong stub id");1079metadata_Relocation* r = mds.metadata_reloc();1080Metadata** metadata_adr = r->metadata_addr();1081*metadata_adr = load_klass();1082r->fix_metadata_relocation();1083found = true;1084}1085}1086assert(found, "the metadata must exist!");1087}1088#endif1089if (do_patch) {1090// replace instructions1091// first replace the tail, then the call1092#if defined(ARM) && !defined(AARCH32)1093if((load_klass_or_mirror_patch_id ||1094stub_id == Runtime1::load_appendix_patching_id) &&1095nativeMovConstReg_at(copy_buff)->is_pc_relative()) {1096nmethod* nm = CodeCache::find_nmethod(instr_pc);1097address addr = NULL;1098assert(nm != NULL, "invalid nmethod_pc");1099RelocIterator mds(nm, copy_buff, copy_buff + 1);1100while (mds.next()) {1101if (mds.type() == relocInfo::oop_type) {1102assert(stub_id == Runtime1::load_mirror_patching_id ||1103stub_id == Runtime1::load_appendix_patching_id, "wrong stub id");1104oop_Relocation* r = mds.oop_reloc();1105addr = (address)r->oop_addr();1106break;1107} else if (mds.type() == relocInfo::metadata_type) {1108assert(stub_id == Runtime1::load_klass_patching_id, "wrong stub id");1109metadata_Relocation* r = mds.metadata_reloc();1110addr = (address)r->metadata_addr();1111break;1112}1113}1114assert(addr != NULL, "metadata relocation must exist");1115copy_buff -= *byte_count;1116NativeMovConstReg* n_copy2 = nativeMovConstReg_at(copy_buff);1117n_copy2->set_pc_relative_offset(addr, instr_pc);1118}1119#endif11201121for (int i = NativeCall::instruction_size; i < *byte_count; i++) {1122address ptr = copy_buff + i;1123int a_byte = (*ptr) & 0xFF;1124address dst = instr_pc + i;1125*(unsigned char*)dst = (unsigned char) a_byte;1126}1127ICache::invalidate_range(instr_pc, *byte_count);1128NativeGeneralJump::replace_mt_safe(instr_pc, copy_buff);11291130if (load_klass_or_mirror_patch_id ||1131stub_id == Runtime1::load_appendix_patching_id) {1132relocInfo::relocType rtype =1133(stub_id == Runtime1::load_klass_patching_id) ?1134relocInfo::metadata_type :1135relocInfo::oop_type;1136// update relocInfo to metadata1137nmethod* nm = CodeCache::find_nmethod(instr_pc);1138assert(nm != NULL, "invalid nmethod_pc");11391140// The old patch site is now a move instruction so update1141// the reloc info so that it will get updated during1142// future GCs.1143RelocIterator iter(nm, (address)instr_pc, (address)(instr_pc + 1));1144relocInfo::change_reloc_info_for_address(&iter, (address) instr_pc,1145relocInfo::none, rtype);1146#ifdef SPARC1147// Sparc takes two relocations for an metadata so update the second one.1148address instr_pc2 = instr_pc + NativeMovConstReg::add_offset;1149RelocIterator iter2(nm, instr_pc2, instr_pc2 + 1);1150relocInfo::change_reloc_info_for_address(&iter2, (address) instr_pc2,1151relocInfo::none, rtype);1152#endif1153#ifdef PPC1154{ address instr_pc2 = instr_pc + NativeMovConstReg::lo_offset;1155RelocIterator iter2(nm, instr_pc2, instr_pc2 + 1);1156relocInfo::change_reloc_info_for_address(&iter2, (address) instr_pc2,1157relocInfo::none, rtype);1158}1159#endif1160}1161#ifdef AARCH321162// AArch32 have (disabled) relocation for offset, should enable it back1163if (stub_id == Runtime1::access_field_patching_id) {1164nmethod* nm = CodeCache::find_nmethod(instr_pc);1165RelocIterator iter(nm, (address)instr_pc, (address)(instr_pc + 1));1166relocInfo::change_reloc_info_for_address(&iter, (address) instr_pc,1167relocInfo::none, relocInfo::section_word_type);1168}1169#endif11701171} else {1172ICache::invalidate_range(copy_buff, *byte_count);1173NativeGeneralJump::insert_unconditional(instr_pc, being_initialized_entry);1174}1175}1176}1177}11781179// If we are patching in a non-perm oop, make sure the nmethod1180// is on the right list.1181if (ScavengeRootsInCode && ((mirror.not_null() && mirror()->is_scavengable()) ||1182(appendix.not_null() && appendix->is_scavengable()))) {1183MutexLockerEx ml_code (CodeCache_lock, Mutex::_no_safepoint_check_flag);1184nmethod* nm = CodeCache::find_nmethod(caller_frame.pc());1185guarantee(nm != NULL, "only nmethods can contain non-perm oops");1186if (!nm->on_scavenge_root_list()) {1187CodeCache::add_scavenge_root_nmethod(nm);1188}11891190// Since we've patched some oops in the nmethod,1191// (re)register it with the heap.1192Universe::heap()->register_nmethod(nm);1193}1194JRT_END11951196//1197// Entry point for compiled code. We want to patch a nmethod.1198// We don't do a normal VM transition here because we want to1199// know after the patching is complete and any safepoint(s) are taken1200// if the calling nmethod was deoptimized. We do this by calling a1201// helper method which does the normal VM transition and when it1202// completes we can check for deoptimization. This simplifies the1203// assembly code in the cpu directories.1204//1205#ifndef TARGET_ARCH_aarch641206int Runtime1::move_klass_patching(JavaThread* thread) {1207//1208// NOTE: we are still in Java1209//1210Thread* THREAD = thread;1211debug_only(NoHandleMark nhm;)1212{1213// Enter VM mode12141215ResetNoHandleMark rnhm;1216patch_code(thread, load_klass_patching_id);1217}1218// Back in JAVA, use no oops DON'T safepoint12191220// Return true if calling code is deoptimized12211222return caller_is_deopted();1223}12241225int Runtime1::move_mirror_patching(JavaThread* thread) {1226//1227// NOTE: we are still in Java1228//1229Thread* THREAD = thread;1230debug_only(NoHandleMark nhm;)1231{1232// Enter VM mode12331234ResetNoHandleMark rnhm;1235patch_code(thread, load_mirror_patching_id);1236}1237// Back in JAVA, use no oops DON'T safepoint12381239// Return true if calling code is deoptimized12401241return caller_is_deopted();1242}12431244int Runtime1::move_appendix_patching(JavaThread* thread) {1245//1246// NOTE: we are still in Java1247//1248Thread* THREAD = thread;1249debug_only(NoHandleMark nhm;)1250{1251// Enter VM mode12521253ResetNoHandleMark rnhm;1254patch_code(thread, load_appendix_patching_id);1255}1256// Back in JAVA, use no oops DON'T safepoint12571258// Return true if calling code is deoptimized12591260return caller_is_deopted();1261}1262//1263// Entry point for compiled code. We want to patch a nmethod.1264// We don't do a normal VM transition here because we want to1265// know after the patching is complete and any safepoint(s) are taken1266// if the calling nmethod was deoptimized. We do this by calling a1267// helper method which does the normal VM transition and when it1268// completes we can check for deoptimization. This simplifies the1269// assembly code in the cpu directories.1270//12711272int Runtime1::access_field_patching(JavaThread* thread) {1273//1274// NOTE: we are still in Java1275//1276Thread* THREAD = thread;1277debug_only(NoHandleMark nhm;)1278{1279// Enter VM mode12801281ResetNoHandleMark rnhm;1282patch_code(thread, access_field_patching_id);1283}1284// Back in JAVA, use no oops DON'T safepoint12851286// Return true if calling code is deoptimized12871288return caller_is_deopted();1289JRT_END1290#endif12911292JRT_LEAF(void, Runtime1::trace_block_entry(jint block_id))1293// for now we just print out the block id1294tty->print("%d ", block_id);1295JRT_END129612971298// Array copy return codes.1299enum {1300ac_failed = -1, // arraycopy failed1301ac_ok = 0 // arraycopy succeeded1302};130313041305// Below length is the # elements copied.1306template <class T> int obj_arraycopy_work(oopDesc* src, T* src_addr,1307oopDesc* dst, T* dst_addr,1308int length) {13091310// For performance reasons, we assume we are using a card marking write1311// barrier. The assert will fail if this is not the case.1312// Note that we use the non-virtual inlineable variant of write_ref_array.1313BarrierSet* bs = Universe::heap()->barrier_set();1314assert(bs->has_write_ref_array_opt(), "Barrier set must have ref array opt");1315assert(bs->has_write_ref_array_pre_opt(), "For pre-barrier as well.");1316if (src == dst) {1317// same object, no check1318bs->write_ref_array_pre(dst_addr, length);1319Copy::conjoint_oops_atomic(src_addr, dst_addr, length);1320bs->write_ref_array((HeapWord*)dst_addr, length);1321return ac_ok;1322} else {1323Klass* bound = ObjArrayKlass::cast(dst->klass())->element_klass();1324Klass* stype = ObjArrayKlass::cast(src->klass())->element_klass();1325if (stype == bound || stype->is_subtype_of(bound)) {1326// Elements are guaranteed to be subtypes, so no check necessary1327bs->write_ref_array_pre(dst_addr, length);1328Copy::conjoint_oops_atomic(src_addr, dst_addr, length);1329bs->write_ref_array((HeapWord*)dst_addr, length);1330return ac_ok;1331}1332}1333return ac_failed;1334}13351336// fast and direct copy of arrays; returning -1, means that an exception may be thrown1337// and we did not copy anything1338JRT_LEAF(int, Runtime1::arraycopy(oopDesc* src, int src_pos, oopDesc* dst, int dst_pos, int length))1339#ifndef PRODUCT1340_generic_arraycopy_cnt++; // Slow-path oop array copy1341#endif13421343if (src == NULL || dst == NULL || src_pos < 0 || dst_pos < 0 || length < 0) return ac_failed;1344if (!dst->is_array() || !src->is_array()) return ac_failed;1345if ((unsigned int) arrayOop(src)->length() < (unsigned int)src_pos + (unsigned int)length) return ac_failed;1346if ((unsigned int) arrayOop(dst)->length() < (unsigned int)dst_pos + (unsigned int)length) return ac_failed;13471348if (length == 0) return ac_ok;1349if (src->is_typeArray()) {1350Klass* klass_oop = src->klass();1351if (klass_oop != dst->klass()) return ac_failed;1352TypeArrayKlass* klass = TypeArrayKlass::cast(klass_oop);1353const int l2es = klass->log2_element_size();1354const int ihs = klass->array_header_in_bytes() / wordSize;1355char* src_addr = (char*) ((oopDesc**)src + ihs) + (src_pos << l2es);1356char* dst_addr = (char*) ((oopDesc**)dst + ihs) + (dst_pos << l2es);1357// Potential problem: memmove is not guaranteed to be word atomic1358// Revisit in Merlin1359memmove(dst_addr, src_addr, length << l2es);1360return ac_ok;1361} else if (src->is_objArray() && dst->is_objArray()) {1362if (UseCompressedOops) {1363narrowOop *src_addr = objArrayOop(src)->obj_at_addr<narrowOop>(src_pos);1364narrowOop *dst_addr = objArrayOop(dst)->obj_at_addr<narrowOop>(dst_pos);1365return obj_arraycopy_work(src, src_addr, dst, dst_addr, length);1366} else {1367oop *src_addr = objArrayOop(src)->obj_at_addr<oop>(src_pos);1368oop *dst_addr = objArrayOop(dst)->obj_at_addr<oop>(dst_pos);1369return obj_arraycopy_work(src, src_addr, dst, dst_addr, length);1370}1371}1372return ac_failed;1373JRT_END137413751376JRT_LEAF(void, Runtime1::primitive_arraycopy(HeapWord* src, HeapWord* dst, int length))1377#ifndef PRODUCT1378_primitive_arraycopy_cnt++;1379#endif13801381if (length == 0) return;1382// Not guaranteed to be word atomic, but that doesn't matter1383// for anything but an oop array, which is covered by oop_arraycopy.1384Copy::conjoint_jbytes(src, dst, length);1385JRT_END13861387JRT_LEAF(void, Runtime1::oop_arraycopy(HeapWord* src, HeapWord* dst, int num))1388#ifndef PRODUCT1389_oop_arraycopy_cnt++;1390#endif13911392if (num == 0) return;1393BarrierSet* bs = Universe::heap()->barrier_set();1394assert(bs->has_write_ref_array_opt(), "Barrier set must have ref array opt");1395assert(bs->has_write_ref_array_pre_opt(), "For pre-barrier as well.");1396if (UseCompressedOops) {1397bs->write_ref_array_pre((narrowOop*)dst, num);1398Copy::conjoint_oops_atomic((narrowOop*) src, (narrowOop*) dst, num);1399} else {1400bs->write_ref_array_pre((oop*)dst, num);1401Copy::conjoint_oops_atomic((oop*) src, (oop*) dst, num);1402}1403bs->write_ref_array(dst, num);1404JRT_END140514061407JRT_LEAF(int, Runtime1::is_instance_of(oopDesc* mirror, oopDesc* obj))1408// had to return int instead of bool, otherwise there may be a mismatch1409// between the C calling convention and the Java one.1410// e.g., on x86, GCC may clear only %al when returning a bool false, but1411// JVM takes the whole %eax as the return value, which may misinterpret1412// the return value as a boolean true.14131414assert(mirror != NULL, "should null-check on mirror before calling");1415Klass* k = java_lang_Class::as_Klass(mirror);1416return (k != NULL && obj != NULL && obj->is_a(k)) ? 1 : 0;1417JRT_END14181419JRT_ENTRY(void, Runtime1::predicate_failed_trap(JavaThread* thread))1420ResourceMark rm;14211422assert(!TieredCompilation, "incompatible with tiered compilation");14231424RegisterMap reg_map(thread, false);1425frame runtime_frame = thread->last_frame();1426frame caller_frame = runtime_frame.sender(®_map);14271428nmethod* nm = CodeCache::find_nmethod(caller_frame.pc());1429assert (nm != NULL, "no more nmethod?");1430nm->make_not_entrant();14311432methodHandle m(nm->method());1433MethodData* mdo = m->method_data();14341435if (mdo == NULL && !HAS_PENDING_EXCEPTION) {1436// Build an MDO. Ignore errors like OutOfMemory;1437// that simply means we won't have an MDO to update.1438Method::build_interpreter_method_data(m, THREAD);1439if (HAS_PENDING_EXCEPTION) {1440assert((PENDING_EXCEPTION->is_a(SystemDictionary::OutOfMemoryError_klass())), "we expect only an OOM error here");1441CLEAR_PENDING_EXCEPTION;1442}1443mdo = m->method_data();1444}14451446if (mdo != NULL) {1447mdo->inc_trap_count(Deoptimization::Reason_none);1448}14491450if (TracePredicateFailedTraps) {1451stringStream ss1, ss2;1452vframeStream vfst(thread);1453methodHandle inlinee = methodHandle(vfst.method());1454inlinee->print_short_name(&ss1);1455m->print_short_name(&ss2);1456tty->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()));1457}145814591460Deoptimization::deoptimize_frame(thread, caller_frame.id());14611462JRT_END14631464#ifndef PRODUCT1465void Runtime1::print_statistics() {1466tty->print_cr("C1 Runtime statistics:");1467tty->print_cr(" _resolve_invoke_virtual_cnt: %d", SharedRuntime::_resolve_virtual_ctr);1468tty->print_cr(" _resolve_invoke_opt_virtual_cnt: %d", SharedRuntime::_resolve_opt_virtual_ctr);1469tty->print_cr(" _resolve_invoke_static_cnt: %d", SharedRuntime::_resolve_static_ctr);1470tty->print_cr(" _handle_wrong_method_cnt: %d", SharedRuntime::_wrong_method_ctr);1471tty->print_cr(" _ic_miss_cnt: %d", SharedRuntime::_ic_miss_ctr);1472tty->print_cr(" _generic_arraycopy_cnt: %d", _generic_arraycopy_cnt);1473tty->print_cr(" _generic_arraycopystub_cnt: %d", _generic_arraycopystub_cnt);1474tty->print_cr(" _byte_arraycopy_cnt: %d", _byte_arraycopy_cnt);1475tty->print_cr(" _short_arraycopy_cnt: %d", _short_arraycopy_cnt);1476tty->print_cr(" _int_arraycopy_cnt: %d", _int_arraycopy_cnt);1477tty->print_cr(" _long_arraycopy_cnt: %d", _long_arraycopy_cnt);1478tty->print_cr(" _primitive_arraycopy_cnt: %d", _primitive_arraycopy_cnt);1479tty->print_cr(" _oop_arraycopy_cnt (C): %d", Runtime1::_oop_arraycopy_cnt);1480tty->print_cr(" _oop_arraycopy_cnt (stub): %d", _oop_arraycopy_cnt);1481tty->print_cr(" _arraycopy_slowcase_cnt: %d", _arraycopy_slowcase_cnt);1482tty->print_cr(" _arraycopy_checkcast_cnt: %d", _arraycopy_checkcast_cnt);1483tty->print_cr(" _arraycopy_checkcast_attempt_cnt:%d", _arraycopy_checkcast_attempt_cnt);14841485tty->print_cr(" _new_type_array_slowcase_cnt: %d", _new_type_array_slowcase_cnt);1486tty->print_cr(" _new_object_array_slowcase_cnt: %d", _new_object_array_slowcase_cnt);1487tty->print_cr(" _new_instance_slowcase_cnt: %d", _new_instance_slowcase_cnt);1488tty->print_cr(" _new_multi_array_slowcase_cnt: %d", _new_multi_array_slowcase_cnt);1489tty->print_cr(" _monitorenter_slowcase_cnt: %d", _monitorenter_slowcase_cnt);1490tty->print_cr(" _monitorexit_slowcase_cnt: %d", _monitorexit_slowcase_cnt);1491tty->print_cr(" _patch_code_slowcase_cnt: %d", _patch_code_slowcase_cnt);14921493tty->print_cr(" _throw_range_check_exception_count: %d:", _throw_range_check_exception_count);1494tty->print_cr(" _throw_index_exception_count: %d:", _throw_index_exception_count);1495tty->print_cr(" _throw_div0_exception_count: %d:", _throw_div0_exception_count);1496tty->print_cr(" _throw_null_pointer_exception_count: %d:", _throw_null_pointer_exception_count);1497tty->print_cr(" _throw_class_cast_exception_count: %d:", _throw_class_cast_exception_count);1498tty->print_cr(" _throw_incompatible_class_change_error_count: %d:", _throw_incompatible_class_change_error_count);1499tty->print_cr(" _throw_array_store_exception_count: %d:", _throw_array_store_exception_count);1500tty->print_cr(" _throw_count: %d:", _throw_count);15011502SharedRuntime::print_ic_miss_histogram();1503tty->cr();1504}1505#endif // PRODUCT150615071508