Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/cpu/sparc/vm/c1_CodeStubs_sparc.cpp
32285 views
/*1* Copyright (c) 1999, 2013, 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 "c1/c1_CodeStubs.hpp"26#include "c1/c1_FrameMap.hpp"27#include "c1/c1_LIRAssembler.hpp"28#include "c1/c1_MacroAssembler.hpp"29#include "c1/c1_Runtime1.hpp"30#include "nativeInst_sparc.hpp"31#include "runtime/sharedRuntime.hpp"32#include "utilities/macros.hpp"33#include "vmreg_sparc.inline.hpp"34#if INCLUDE_ALL_GCS35#include "gc_implementation/g1/g1SATBCardTableModRefBS.hpp"36#endif // INCLUDE_ALL_GCS3738#define __ ce->masm()->3940RangeCheckStub::RangeCheckStub(CodeEmitInfo* info, LIR_Opr index,41bool throw_index_out_of_bounds_exception)42: _throw_index_out_of_bounds_exception(throw_index_out_of_bounds_exception)43, _index(index)44{45assert(info != NULL, "must have info");46_info = new CodeEmitInfo(info);47}484950void RangeCheckStub::emit_code(LIR_Assembler* ce) {51__ bind(_entry);5253if (_info->deoptimize_on_exception()) {54address a = Runtime1::entry_for(Runtime1::predicate_failed_trap_id);55__ call(a, relocInfo::runtime_call_type);56__ delayed()->nop();57ce->add_call_info_here(_info);58ce->verify_oop_map(_info);59debug_only(__ should_not_reach_here());60return;61}6263if (_index->is_register()) {64__ mov(_index->as_register(), G4);65} else {66__ set(_index->as_jint(), G4);67}68if (_throw_index_out_of_bounds_exception) {69__ call(Runtime1::entry_for(Runtime1::throw_index_exception_id), relocInfo::runtime_call_type);70} else {71__ call(Runtime1::entry_for(Runtime1::throw_range_check_failed_id), relocInfo::runtime_call_type);72}73__ delayed()->nop();74ce->add_call_info_here(_info);75ce->verify_oop_map(_info);76debug_only(__ should_not_reach_here());77}7879PredicateFailedStub::PredicateFailedStub(CodeEmitInfo* info) {80_info = new CodeEmitInfo(info);81}8283void PredicateFailedStub::emit_code(LIR_Assembler* ce) {84__ bind(_entry);85address a = Runtime1::entry_for(Runtime1::predicate_failed_trap_id);86__ call(a, relocInfo::runtime_call_type);87__ delayed()->nop();88ce->add_call_info_here(_info);89ce->verify_oop_map(_info);90debug_only(__ should_not_reach_here());91}9293void CounterOverflowStub::emit_code(LIR_Assembler* ce) {94__ bind(_entry);95__ set(_bci, G4);96__ call(Runtime1::entry_for(Runtime1::counter_overflow_id), relocInfo::runtime_call_type);97__ delayed()->mov_or_nop(_method->as_register(), G5);98ce->add_call_info_here(_info);99ce->verify_oop_map(_info);100101__ br(Assembler::always, true, Assembler::pt, _continuation);102__ delayed()->nop();103}104105106void DivByZeroStub::emit_code(LIR_Assembler* ce) {107if (_offset != -1) {108ce->compilation()->implicit_exception_table()->append(_offset, __ offset());109}110__ bind(_entry);111__ call(Runtime1::entry_for(Runtime1::throw_div0_exception_id), relocInfo::runtime_call_type);112__ delayed()->nop();113ce->add_call_info_here(_info);114ce->verify_oop_map(_info);115#ifdef ASSERT116__ should_not_reach_here();117#endif118}119120121void ImplicitNullCheckStub::emit_code(LIR_Assembler* ce) {122address a;123if (_info->deoptimize_on_exception()) {124// Deoptimize, do not throw the exception, because it is probably wrong to do it here.125a = Runtime1::entry_for(Runtime1::predicate_failed_trap_id);126} else {127a = Runtime1::entry_for(Runtime1::throw_null_pointer_exception_id);128}129130ce->compilation()->implicit_exception_table()->append(_offset, __ offset());131__ bind(_entry);132__ call(a, relocInfo::runtime_call_type);133__ delayed()->nop();134ce->add_call_info_here(_info);135ce->verify_oop_map(_info);136#ifdef ASSERT137__ should_not_reach_here();138#endif139}140141142// Implementation of SimpleExceptionStub143// Note: %g1 and %g3 are already in use144void SimpleExceptionStub::emit_code(LIR_Assembler* ce) {145__ bind(_entry);146__ call(Runtime1::entry_for(_stub), relocInfo::runtime_call_type);147148if (_obj->is_valid()) {149__ delayed()->mov(_obj->as_register(), G4); // _obj contains the optional argument to the stub150} else {151__ delayed()->mov(G0, G4);152}153ce->add_call_info_here(_info);154#ifdef ASSERT155__ should_not_reach_here();156#endif157}158159160// Implementation of NewInstanceStub161162NewInstanceStub::NewInstanceStub(LIR_Opr klass_reg, LIR_Opr result, ciInstanceKlass* klass, CodeEmitInfo* info, Runtime1::StubID stub_id) {163_result = result;164_klass = klass;165_klass_reg = klass_reg;166_info = new CodeEmitInfo(info);167assert(stub_id == Runtime1::new_instance_id ||168stub_id == Runtime1::fast_new_instance_id ||169stub_id == Runtime1::fast_new_instance_init_check_id,170"need new_instance id");171_stub_id = stub_id;172}173174175void NewInstanceStub::emit_code(LIR_Assembler* ce) {176__ bind(_entry);177__ call(Runtime1::entry_for(_stub_id), relocInfo::runtime_call_type);178__ delayed()->mov_or_nop(_klass_reg->as_register(), G5);179ce->add_call_info_here(_info);180ce->verify_oop_map(_info);181__ br(Assembler::always, false, Assembler::pt, _continuation);182__ delayed()->mov_or_nop(O0, _result->as_register());183}184185186// Implementation of NewTypeArrayStub187NewTypeArrayStub::NewTypeArrayStub(LIR_Opr klass_reg, LIR_Opr length, LIR_Opr result, CodeEmitInfo* info) {188_klass_reg = klass_reg;189_length = length;190_result = result;191_info = new CodeEmitInfo(info);192}193194195void NewTypeArrayStub::emit_code(LIR_Assembler* ce) {196__ bind(_entry);197198__ mov(_length->as_register(), G4);199__ call(Runtime1::entry_for(Runtime1::new_type_array_id), relocInfo::runtime_call_type);200__ delayed()->mov_or_nop(_klass_reg->as_register(), G5);201ce->add_call_info_here(_info);202ce->verify_oop_map(_info);203__ br(Assembler::always, false, Assembler::pt, _continuation);204__ delayed()->mov_or_nop(O0, _result->as_register());205}206207208// Implementation of NewObjectArrayStub209210NewObjectArrayStub::NewObjectArrayStub(LIR_Opr klass_reg, LIR_Opr length, LIR_Opr result, CodeEmitInfo* info) {211_klass_reg = klass_reg;212_length = length;213_result = result;214_info = new CodeEmitInfo(info);215}216217218void NewObjectArrayStub::emit_code(LIR_Assembler* ce) {219__ bind(_entry);220221__ mov(_length->as_register(), G4);222__ call(Runtime1::entry_for(Runtime1::new_object_array_id), relocInfo::runtime_call_type);223__ delayed()->mov_or_nop(_klass_reg->as_register(), G5);224ce->add_call_info_here(_info);225ce->verify_oop_map(_info);226__ br(Assembler::always, false, Assembler::pt, _continuation);227__ delayed()->mov_or_nop(O0, _result->as_register());228}229230231// Implementation of MonitorAccessStubs232MonitorEnterStub::MonitorEnterStub(LIR_Opr obj_reg, LIR_Opr lock_reg, CodeEmitInfo* info)233: MonitorAccessStub(obj_reg, lock_reg) {234_info = new CodeEmitInfo(info);235}236237238void MonitorEnterStub::emit_code(LIR_Assembler* ce) {239__ bind(_entry);240__ mov(_obj_reg->as_register(), G4);241if (ce->compilation()->has_fpu_code()) {242__ call(Runtime1::entry_for(Runtime1::monitorenter_id), relocInfo::runtime_call_type);243} else {244__ call(Runtime1::entry_for(Runtime1::monitorenter_nofpu_id), relocInfo::runtime_call_type);245}246__ delayed()->mov_or_nop(_lock_reg->as_register(), G5);247ce->add_call_info_here(_info);248ce->verify_oop_map(_info);249__ br(Assembler::always, true, Assembler::pt, _continuation);250__ delayed()->nop();251}252253254void MonitorExitStub::emit_code(LIR_Assembler* ce) {255__ bind(_entry);256if (_compute_lock) {257ce->monitor_address(_monitor_ix, _lock_reg);258}259if (ce->compilation()->has_fpu_code()) {260__ call(Runtime1::entry_for(Runtime1::monitorexit_id), relocInfo::runtime_call_type);261} else {262__ call(Runtime1::entry_for(Runtime1::monitorexit_nofpu_id), relocInfo::runtime_call_type);263}264265__ delayed()->mov_or_nop(_lock_reg->as_register(), G4);266__ br(Assembler::always, true, Assembler::pt, _continuation);267__ delayed()->nop();268}269270// Implementation of patching:271// - Copy the code at given offset to an inlined buffer (first the bytes, then the number of bytes)272// - Replace original code with a call to the stub273// At Runtime:274// - call to stub, jump to runtime275// - in runtime: preserve all registers (especially objects, i.e., source and destination object)276// - in runtime: after initializing class, restore original code, reexecute instruction277278int PatchingStub::_patch_info_offset = -NativeGeneralJump::instruction_size;279280void PatchingStub::align_patch_site(MacroAssembler* ) {281// patch sites on sparc are always properly aligned.282}283284void PatchingStub::emit_code(LIR_Assembler* ce) {285// copy original code here286assert(NativeCall::instruction_size <= _bytes_to_copy && _bytes_to_copy <= 0xFF,287"not enough room for call");288assert((_bytes_to_copy & 0x3) == 0, "must copy a multiple of four bytes");289290Label call_patch;291292int being_initialized_entry = __ offset();293294if (_id == load_klass_id) {295// produce a copy of the load klass instruction for use by the being initialized case296#ifdef ASSERT297address start = __ pc();298#endif299AddressLiteral addrlit(NULL, metadata_Relocation::spec(_index));300__ patchable_set(addrlit, _obj);301302#ifdef ASSERT303for (int i = 0; i < _bytes_to_copy; i++) {304address ptr = (address)(_pc_start + i);305int a_byte = (*ptr) & 0xFF;306assert(a_byte == *start++, "should be the same code");307}308#endif309} else if (_id == load_mirror_id || _id == load_appendix_id) {310// produce a copy of the load mirror instruction for use by the being initialized case311#ifdef ASSERT312address start = __ pc();313#endif314AddressLiteral addrlit(NULL, oop_Relocation::spec(_index));315__ patchable_set(addrlit, _obj);316317#ifdef ASSERT318for (int i = 0; i < _bytes_to_copy; i++) {319address ptr = (address)(_pc_start + i);320int a_byte = (*ptr) & 0xFF;321assert(a_byte == *start++, "should be the same code");322}323#endif324} else {325// make a copy the code which is going to be patched.326for (int i = 0; i < _bytes_to_copy; i++) {327address ptr = (address)(_pc_start + i);328int a_byte = (*ptr) & 0xFF;329__ emit_int8 (a_byte);330}331}332333address end_of_patch = __ pc();334int bytes_to_skip = 0;335if (_id == load_mirror_id) {336int offset = __ offset();337if (CommentedAssembly) {338__ block_comment(" being_initialized check");339}340341// static field accesses have special semantics while the class342// initializer is being run so we emit a test which can be used to343// check that this code is being executed by the initializing344// thread.345assert(_obj != noreg, "must be a valid register");346assert(_index >= 0, "must have oop index");347__ ld_ptr(_obj, java_lang_Class::klass_offset_in_bytes(), G3);348__ ld_ptr(G3, in_bytes(InstanceKlass::init_thread_offset()), G3);349__ cmp_and_brx_short(G2_thread, G3, Assembler::notEqual, Assembler::pn, call_patch);350351// load_klass patches may execute the patched code before it's352// copied back into place so we need to jump back into the main353// code of the nmethod to continue execution.354__ br(Assembler::always, false, Assembler::pt, _patch_site_continuation);355__ delayed()->nop();356357// make sure this extra code gets skipped358bytes_to_skip += __ offset() - offset;359}360361// Now emit the patch record telling the runtime how to find the362// pieces of the patch. We only need 3 bytes but it has to be363// aligned as an instruction so emit 4 bytes.364int sizeof_patch_record = 4;365bytes_to_skip += sizeof_patch_record;366367// emit the offsets needed to find the code to patch368int being_initialized_entry_offset = __ offset() - being_initialized_entry + sizeof_patch_record;369370// Emit the patch record. We need to emit a full word, so emit an extra empty byte371__ emit_int8(0);372__ emit_int8(being_initialized_entry_offset);373__ emit_int8(bytes_to_skip);374__ emit_int8(_bytes_to_copy);375address patch_info_pc = __ pc();376assert(patch_info_pc - end_of_patch == bytes_to_skip, "incorrect patch info");377378address entry = __ pc();379NativeGeneralJump::insert_unconditional((address)_pc_start, entry);380address target = NULL;381relocInfo::relocType reloc_type = relocInfo::none;382switch (_id) {383case access_field_id: target = Runtime1::entry_for(Runtime1::access_field_patching_id); break;384case load_klass_id: target = Runtime1::entry_for(Runtime1::load_klass_patching_id); reloc_type = relocInfo::metadata_type; break;385case load_mirror_id: target = Runtime1::entry_for(Runtime1::load_mirror_patching_id); reloc_type = relocInfo::oop_type; break;386case load_appendix_id: target = Runtime1::entry_for(Runtime1::load_appendix_patching_id); reloc_type = relocInfo::oop_type; break;387default: ShouldNotReachHere();388}389__ bind(call_patch);390391if (CommentedAssembly) {392__ block_comment("patch entry point");393}394__ call(target, relocInfo::runtime_call_type);395__ delayed()->nop();396assert(_patch_info_offset == (patch_info_pc - __ pc()), "must not change");397ce->add_call_info_here(_info);398__ br(Assembler::always, false, Assembler::pt, _patch_site_entry);399__ delayed()->nop();400if (_id == load_klass_id || _id == load_mirror_id || _id == load_appendix_id) {401CodeSection* cs = __ code_section();402address pc = (address)_pc_start;403RelocIterator iter(cs, pc, pc + 1);404relocInfo::change_reloc_info_for_address(&iter, (address) pc, reloc_type, relocInfo::none);405406pc = (address)(_pc_start + NativeMovConstReg::add_offset);407RelocIterator iter2(cs, pc, pc+1);408relocInfo::change_reloc_info_for_address(&iter2, (address) pc, reloc_type, relocInfo::none);409}410411}412413414void DeoptimizeStub::emit_code(LIR_Assembler* ce) {415__ bind(_entry);416__ call(Runtime1::entry_for(Runtime1::deoptimize_id), relocInfo::runtime_call_type);417__ delayed()->nop();418ce->add_call_info_here(_info);419DEBUG_ONLY(__ should_not_reach_here());420}421422423void ArrayCopyStub::emit_code(LIR_Assembler* ce) {424//---------------slow case: call to native-----------------425__ bind(_entry);426__ mov(src()->as_register(), O0);427__ mov(src_pos()->as_register(), O1);428__ mov(dst()->as_register(), O2);429__ mov(dst_pos()->as_register(), O3);430__ mov(length()->as_register(), O4);431432ce->emit_static_call_stub();433if (ce->compilation()->bailed_out()) {434return; // CodeCache is full435}436437__ call(SharedRuntime::get_resolve_static_call_stub(), relocInfo::static_call_type);438__ delayed()->nop();439ce->add_call_info_here(info());440ce->verify_oop_map(info());441442#ifndef PRODUCT443__ set((intptr_t)&Runtime1::_arraycopy_slowcase_cnt, O0);444__ ld(O0, 0, O1);445__ inc(O1);446__ st(O1, 0, O0);447#endif448449__ br(Assembler::always, false, Assembler::pt, _continuation);450__ delayed()->nop();451}452453454///////////////////////////////////////////////////////////////////////////////////455#if INCLUDE_ALL_GCS456457void G1PreBarrierStub::emit_code(LIR_Assembler* ce) {458// At this point we know that marking is in progress.459// If do_load() is true then we have to emit the460// load of the previous value; otherwise it has already461// been loaded into _pre_val.462463__ bind(_entry);464465assert(pre_val()->is_register(), "Precondition.");466Register pre_val_reg = pre_val()->as_register();467468if (do_load()) {469ce->mem2reg(addr(), pre_val(), T_OBJECT, patch_code(), info(), false /*wide*/, false /*unaligned*/);470}471472if (__ is_in_wdisp16_range(_continuation)) {473__ br_null(pre_val_reg, /*annul*/false, Assembler::pt, _continuation);474} else {475__ cmp(pre_val_reg, G0);476__ brx(Assembler::equal, false, Assembler::pn, _continuation);477}478__ delayed()->nop();479480__ call(Runtime1::entry_for(Runtime1::Runtime1::g1_pre_barrier_slow_id));481__ delayed()->mov(pre_val_reg, G4);482__ br(Assembler::always, false, Assembler::pt, _continuation);483__ delayed()->nop();484485}486487jbyte* G1PostBarrierStub::_byte_map_base = NULL;488489jbyte* G1PostBarrierStub::byte_map_base_slow() {490BarrierSet* bs = Universe::heap()->barrier_set();491assert(bs->is_a(BarrierSet::G1SATBCTLogging),492"Must be if we're using this.");493return ((G1SATBCardTableModRefBS*)bs)->byte_map_base;494}495496void G1PostBarrierStub::emit_code(LIR_Assembler* ce) {497__ bind(_entry);498499assert(addr()->is_register(), "Precondition.");500assert(new_val()->is_register(), "Precondition.");501Register addr_reg = addr()->as_pointer_register();502Register new_val_reg = new_val()->as_register();503504if (__ is_in_wdisp16_range(_continuation)) {505__ br_null(new_val_reg, /*annul*/false, Assembler::pt, _continuation);506} else {507__ cmp(new_val_reg, G0);508__ brx(Assembler::equal, false, Assembler::pn, _continuation);509}510__ delayed()->nop();511512__ call(Runtime1::entry_for(Runtime1::Runtime1::g1_post_barrier_slow_id));513__ delayed()->mov(addr_reg, G4);514__ br(Assembler::always, false, Assembler::pt, _continuation);515__ delayed()->nop();516}517518#endif // INCLUDE_ALL_GCS519///////////////////////////////////////////////////////////////////////////////////520521#undef __522523524