0N/A/*
2053N/A * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
1472N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1472N/A * or visit www.oracle.com if you need additional information or have any
1472N/A * questions.
0N/A *
0N/A */
0N/A
1879N/A#include "precompiled.hpp"
1879N/A#include "c1/c1_CodeStubs.hpp"
1879N/A#include "c1/c1_FrameMap.hpp"
1879N/A#include "c1/c1_LIRAssembler.hpp"
1879N/A#include "c1/c1_MacroAssembler.hpp"
1879N/A#include "c1/c1_Runtime1.hpp"
1879N/A#include "nativeInst_x86.hpp"
1879N/A#include "runtime/sharedRuntime.hpp"
1879N/A#include "vmreg_x86.inline.hpp"
1879N/A#ifndef SERIALGC
1879N/A#include "gc_implementation/g1/g1SATBCardTableModRefBS.hpp"
1879N/A#endif
0N/A
0N/A
0N/A#define __ ce->masm()->
0N/A
0N/Afloat ConversionStub::float_zero = 0.0;
0N/Adouble ConversionStub::double_zero = 0.0;
0N/A
0N/Avoid ConversionStub::emit_code(LIR_Assembler* ce) {
0N/A __ bind(_entry);
0N/A assert(bytecode() == Bytecodes::_f2i || bytecode() == Bytecodes::_d2i, "other conversions do not require stub");
0N/A
0N/A
0N/A if (input()->is_single_xmm()) {
0N/A __ comiss(input()->as_xmm_float_reg(),
0N/A ExternalAddress((address)&float_zero));
0N/A } else if (input()->is_double_xmm()) {
0N/A __ comisd(input()->as_xmm_double_reg(),
0N/A ExternalAddress((address)&double_zero));
0N/A } else {
304N/A LP64_ONLY(ShouldNotReachHere());
304N/A __ push(rax);
0N/A __ ftst();
0N/A __ fnstsw_ax();
0N/A __ sahf();
304N/A __ pop(rax);
0N/A }
0N/A
0N/A Label NaN, do_return;
0N/A __ jccb(Assembler::parity, NaN);
0N/A __ jccb(Assembler::below, do_return);
0N/A
0N/A // input is > 0 -> return maxInt
0N/A // result register already contains 0x80000000, so subtracting 1 gives 0x7fffffff
0N/A __ decrement(result()->as_register());
0N/A __ jmpb(do_return);
0N/A
0N/A // input is NaN -> return 0
0N/A __ bind(NaN);
304N/A __ xorptr(result()->as_register(), result()->as_register());
0N/A
0N/A __ bind(do_return);
0N/A __ jmp(_continuation);
0N/A}
0N/A
0N/Avoid CounterOverflowStub::emit_code(LIR_Assembler* ce) {
0N/A __ bind(_entry);
1703N/A ce->store_parameter(_method->as_register(), 1);
0N/A ce->store_parameter(_bci, 0);
0N/A __ call(RuntimeAddress(Runtime1::entry_for(Runtime1::counter_overflow_id)));
0N/A ce->add_call_info_here(_info);
0N/A ce->verify_oop_map(_info);
0N/A __ jmp(_continuation);
0N/A}
0N/A
0N/ARangeCheckStub::RangeCheckStub(CodeEmitInfo* info, LIR_Opr index,
0N/A bool throw_index_out_of_bounds_exception)
0N/A : _throw_index_out_of_bounds_exception(throw_index_out_of_bounds_exception)
0N/A , _index(index)
0N/A{
1739N/A assert(info != NULL, "must have info");
1739N/A _info = new CodeEmitInfo(info);
0N/A}
0N/A
0N/A
0N/Avoid RangeCheckStub::emit_code(LIR_Assembler* ce) {
0N/A __ bind(_entry);
0N/A // pass the array index on stack because all registers must be preserved
0N/A if (_index->is_cpu_register()) {
0N/A ce->store_parameter(_index->as_register(), 0);
0N/A } else {
0N/A ce->store_parameter(_index->as_jint(), 0);
0N/A }
0N/A Runtime1::StubID stub_id;
0N/A if (_throw_index_out_of_bounds_exception) {
0N/A stub_id = Runtime1::throw_index_exception_id;
0N/A } else {
0N/A stub_id = Runtime1::throw_range_check_failed_id;
0N/A }
0N/A __ call(RuntimeAddress(Runtime1::entry_for(stub_id)));
0N/A ce->add_call_info_here(_info);
0N/A debug_only(__ should_not_reach_here());
0N/A}
0N/A
0N/A
0N/Avoid DivByZeroStub::emit_code(LIR_Assembler* ce) {
0N/A if (_offset != -1) {
0N/A ce->compilation()->implicit_exception_table()->append(_offset, __ offset());
0N/A }
0N/A __ bind(_entry);
0N/A __ call(RuntimeAddress(Runtime1::entry_for(Runtime1::throw_div0_exception_id)));
0N/A ce->add_call_info_here(_info);
0N/A debug_only(__ should_not_reach_here());
0N/A}
0N/A
0N/A
0N/A// Implementation of NewInstanceStub
0N/A
0N/ANewInstanceStub::NewInstanceStub(LIR_Opr klass_reg, LIR_Opr result, ciInstanceKlass* klass, CodeEmitInfo* info, Runtime1::StubID stub_id) {
0N/A _result = result;
0N/A _klass = klass;
0N/A _klass_reg = klass_reg;
0N/A _info = new CodeEmitInfo(info);
0N/A assert(stub_id == Runtime1::new_instance_id ||
0N/A stub_id == Runtime1::fast_new_instance_id ||
0N/A stub_id == Runtime1::fast_new_instance_init_check_id,
0N/A "need new_instance id");
0N/A _stub_id = stub_id;
0N/A}
0N/A
0N/A
0N/Avoid NewInstanceStub::emit_code(LIR_Assembler* ce) {
0N/A assert(__ rsp_offset() == 0, "frame size should be fixed");
0N/A __ bind(_entry);
304N/A __ movptr(rdx, _klass_reg->as_register());
0N/A __ call(RuntimeAddress(Runtime1::entry_for(_stub_id)));
0N/A ce->add_call_info_here(_info);
0N/A ce->verify_oop_map(_info);
0N/A assert(_result->as_register() == rax, "result must in rax,");
0N/A __ jmp(_continuation);
0N/A}
0N/A
0N/A
0N/A// Implementation of NewTypeArrayStub
0N/A
0N/ANewTypeArrayStub::NewTypeArrayStub(LIR_Opr klass_reg, LIR_Opr length, LIR_Opr result, CodeEmitInfo* info) {
0N/A _klass_reg = klass_reg;
0N/A _length = length;
0N/A _result = result;
0N/A _info = new CodeEmitInfo(info);
0N/A}
0N/A
0N/A
0N/Avoid NewTypeArrayStub::emit_code(LIR_Assembler* ce) {
0N/A assert(__ rsp_offset() == 0, "frame size should be fixed");
0N/A __ bind(_entry);
0N/A assert(_length->as_register() == rbx, "length must in rbx,");
0N/A assert(_klass_reg->as_register() == rdx, "klass_reg must in rdx");
0N/A __ call(RuntimeAddress(Runtime1::entry_for(Runtime1::new_type_array_id)));
0N/A ce->add_call_info_here(_info);
0N/A ce->verify_oop_map(_info);
0N/A assert(_result->as_register() == rax, "result must in rax,");
0N/A __ jmp(_continuation);
0N/A}
0N/A
0N/A
0N/A// Implementation of NewObjectArrayStub
0N/A
0N/ANewObjectArrayStub::NewObjectArrayStub(LIR_Opr klass_reg, LIR_Opr length, LIR_Opr result, CodeEmitInfo* info) {
0N/A _klass_reg = klass_reg;
0N/A _result = result;
0N/A _length = length;
0N/A _info = new CodeEmitInfo(info);
0N/A}
0N/A
0N/A
0N/Avoid NewObjectArrayStub::emit_code(LIR_Assembler* ce) {
0N/A assert(__ rsp_offset() == 0, "frame size should be fixed");
0N/A __ bind(_entry);
0N/A assert(_length->as_register() == rbx, "length must in rbx,");
0N/A assert(_klass_reg->as_register() == rdx, "klass_reg must in rdx");
0N/A __ call(RuntimeAddress(Runtime1::entry_for(Runtime1::new_object_array_id)));
0N/A ce->add_call_info_here(_info);
0N/A ce->verify_oop_map(_info);
0N/A assert(_result->as_register() == rax, "result must in rax,");
0N/A __ jmp(_continuation);
0N/A}
0N/A
0N/A
0N/A// Implementation of MonitorAccessStubs
0N/A
0N/AMonitorEnterStub::MonitorEnterStub(LIR_Opr obj_reg, LIR_Opr lock_reg, CodeEmitInfo* info)
0N/A: MonitorAccessStub(obj_reg, lock_reg)
0N/A{
0N/A _info = new CodeEmitInfo(info);
0N/A}
0N/A
0N/A
0N/Avoid MonitorEnterStub::emit_code(LIR_Assembler* ce) {
0N/A assert(__ rsp_offset() == 0, "frame size should be fixed");
0N/A __ bind(_entry);
0N/A ce->store_parameter(_obj_reg->as_register(), 1);
0N/A ce->store_parameter(_lock_reg->as_register(), 0);
0N/A Runtime1::StubID enter_id;
0N/A if (ce->compilation()->has_fpu_code()) {
0N/A enter_id = Runtime1::monitorenter_id;
0N/A } else {
0N/A enter_id = Runtime1::monitorenter_nofpu_id;
0N/A }
0N/A __ call(RuntimeAddress(Runtime1::entry_for(enter_id)));
0N/A ce->add_call_info_here(_info);
0N/A ce->verify_oop_map(_info);
0N/A __ jmp(_continuation);
0N/A}
0N/A
0N/A
0N/Avoid MonitorExitStub::emit_code(LIR_Assembler* ce) {
0N/A __ bind(_entry);
0N/A if (_compute_lock) {
0N/A // lock_reg was destroyed by fast unlocking attempt => recompute it
0N/A ce->monitor_address(_monitor_ix, _lock_reg);
0N/A }
0N/A ce->store_parameter(_lock_reg->as_register(), 0);
0N/A // note: non-blocking leaf routine => no call info needed
0N/A Runtime1::StubID exit_id;
0N/A if (ce->compilation()->has_fpu_code()) {
0N/A exit_id = Runtime1::monitorexit_id;
0N/A } else {
0N/A exit_id = Runtime1::monitorexit_nofpu_id;
0N/A }
0N/A __ call(RuntimeAddress(Runtime1::entry_for(exit_id)));
0N/A __ jmp(_continuation);
0N/A}
0N/A
0N/A
0N/A// Implementation of patching:
0N/A// - Copy the code at given offset to an inlined buffer (first the bytes, then the number of bytes)
0N/A// - Replace original code with a call to the stub
0N/A// At Runtime:
0N/A// - call to stub, jump to runtime
0N/A// - in runtime: preserve all registers (rspecially objects, i.e., source and destination object)
0N/A// - in runtime: after initializing class, restore original code, reexecute instruction
0N/A
0N/Aint PatchingStub::_patch_info_offset = -NativeGeneralJump::instruction_size;
0N/A
0N/Avoid PatchingStub::align_patch_site(MacroAssembler* masm) {
0N/A // We're patching a 5-7 byte instruction on intel and we need to
0N/A // make sure that we don't see a piece of the instruction. It
0N/A // appears mostly impossible on Intel to simply invalidate other
0N/A // processors caches and since they may do aggressive prefetch it's
0N/A // very hard to make a guess about what code might be in the icache.
0N/A // Force the instruction to be double word aligned so that it
0N/A // doesn't span a cache line.
0N/A masm->align(round_to(NativeGeneralJump::instruction_size, wordSize));
0N/A}
0N/A
0N/Avoid PatchingStub::emit_code(LIR_Assembler* ce) {
0N/A assert(NativeCall::instruction_size <= _bytes_to_copy && _bytes_to_copy <= 0xFF, "not enough room for call");
0N/A
0N/A Label call_patch;
0N/A
0N/A // static field accesses have special semantics while the class
0N/A // initializer is being run so we emit a test which can be used to
0N/A // check that this code is being executed by the initializing
0N/A // thread.
0N/A address being_initialized_entry = __ pc();
0N/A if (CommentedAssembly) {
0N/A __ block_comment(" patch template");
0N/A }
0N/A if (_id == load_klass_id) {
0N/A // produce a copy of the load klass instruction for use by the being initialized case
0N/A address start = __ pc();
0N/A jobject o = NULL;
0N/A __ movoop(_obj, o);
0N/A#ifdef ASSERT
0N/A for (int i = 0; i < _bytes_to_copy; i++) {
0N/A address ptr = (address)(_pc_start + i);
0N/A int a_byte = (*ptr) & 0xFF;
0N/A assert(a_byte == *start++, "should be the same code");
0N/A }
0N/A#endif
0N/A } else {
0N/A // make a copy the code which is going to be patched.
0N/A for ( int i = 0; i < _bytes_to_copy; i++) {
0N/A address ptr = (address)(_pc_start + i);
0N/A int a_byte = (*ptr) & 0xFF;
0N/A __ a_byte (a_byte);
0N/A *ptr = 0x90; // make the site look like a nop
0N/A }
0N/A }
0N/A
0N/A address end_of_patch = __ pc();
0N/A int bytes_to_skip = 0;
0N/A if (_id == load_klass_id) {
0N/A int offset = __ offset();
0N/A if (CommentedAssembly) {
0N/A __ block_comment(" being_initialized check");
0N/A }
0N/A assert(_obj != noreg, "must be a valid register");
0N/A Register tmp = rax;
2223N/A Register tmp2 = rbx;
304N/A __ push(tmp);
2223N/A __ push(tmp2);
2311N/A // Load without verification to keep code size small. We need it because
2311N/A // begin_initialized_entry_offset has to fit in a byte. Also, we know it's not null.
2311N/A __ load_heap_oop_not_null(tmp2, Address(_obj, java_lang_Class::klass_offset_in_bytes()));
0N/A __ get_thread(tmp);
3042N/A __ cmpptr(tmp, Address(tmp2, instanceKlass::init_thread_offset()));
2223N/A __ pop(tmp2);
304N/A __ pop(tmp);
0N/A __ jcc(Assembler::notEqual, call_patch);
0N/A
0N/A // access_field patches may execute the patched code before it's
0N/A // copied back into place so we need to jump back into the main
0N/A // code of the nmethod to continue execution.
0N/A __ jmp(_patch_site_continuation);
0N/A
0N/A // make sure this extra code gets skipped
0N/A bytes_to_skip += __ offset() - offset;
0N/A }
0N/A if (CommentedAssembly) {
0N/A __ block_comment("patch data encoded as movl");
0N/A }
0N/A // Now emit the patch record telling the runtime how to find the
0N/A // pieces of the patch. We only need 3 bytes but for readability of
0N/A // the disassembly we make the data look like a movl reg, imm32,
0N/A // which requires 5 bytes
0N/A int sizeof_patch_record = 5;
0N/A bytes_to_skip += sizeof_patch_record;
0N/A
0N/A // emit the offsets needed to find the code to patch
0N/A int being_initialized_entry_offset = __ pc() - being_initialized_entry + sizeof_patch_record;
0N/A
0N/A __ a_byte(0xB8);
0N/A __ a_byte(0);
0N/A __ a_byte(being_initialized_entry_offset);
0N/A __ a_byte(bytes_to_skip);
0N/A __ a_byte(_bytes_to_copy);
0N/A address patch_info_pc = __ pc();
0N/A assert(patch_info_pc - end_of_patch == bytes_to_skip, "incorrect patch info");
0N/A
0N/A address entry = __ pc();
0N/A NativeGeneralJump::insert_unconditional((address)_pc_start, entry);
0N/A address target = NULL;
0N/A switch (_id) {
0N/A case access_field_id: target = Runtime1::entry_for(Runtime1::access_field_patching_id); break;
0N/A case load_klass_id: target = Runtime1::entry_for(Runtime1::load_klass_patching_id); break;
0N/A default: ShouldNotReachHere();
0N/A }
0N/A __ bind(call_patch);
0N/A
0N/A if (CommentedAssembly) {
0N/A __ block_comment("patch entry point");
0N/A }
0N/A __ call(RuntimeAddress(target));
0N/A assert(_patch_info_offset == (patch_info_pc - __ pc()), "must not change");
0N/A ce->add_call_info_here(_info);
0N/A int jmp_off = __ offset();
0N/A __ jmp(_patch_site_entry);
0N/A // Add enough nops so deoptimization can overwrite the jmp above with a call
0N/A // and not destroy the world.
0N/A for (int j = __ offset() ; j < jmp_off + 5 ; j++ ) {
0N/A __ nop();
0N/A }
0N/A if (_id == load_klass_id) {
0N/A CodeSection* cs = __ code_section();
0N/A RelocIterator iter(cs, (address)_pc_start, (address)(_pc_start + 1));
0N/A relocInfo::change_reloc_info_for_address(&iter, (address) _pc_start, relocInfo::oop_type, relocInfo::none);
0N/A }
0N/A}
0N/A
0N/A
1295N/Avoid DeoptimizeStub::emit_code(LIR_Assembler* ce) {
1295N/A __ bind(_entry);
2886N/A __ call(RuntimeAddress(Runtime1::entry_for(Runtime1::deoptimize_id)));
1295N/A ce->add_call_info_here(_info);
2886N/A DEBUG_ONLY(__ should_not_reach_here());
1295N/A}
1295N/A
1295N/A
0N/Avoid ImplicitNullCheckStub::emit_code(LIR_Assembler* ce) {
0N/A ce->compilation()->implicit_exception_table()->append(_offset, __ offset());
0N/A __ bind(_entry);
0N/A __ call(RuntimeAddress(Runtime1::entry_for(Runtime1::throw_null_pointer_exception_id)));
0N/A ce->add_call_info_here(_info);
0N/A debug_only(__ should_not_reach_here());
0N/A}
0N/A
0N/A
0N/Avoid SimpleExceptionStub::emit_code(LIR_Assembler* ce) {
0N/A assert(__ rsp_offset() == 0, "frame size should be fixed");
0N/A
0N/A __ bind(_entry);
0N/A // pass the object on stack because all registers must be preserved
0N/A if (_obj->is_cpu_register()) {
0N/A ce->store_parameter(_obj->as_register(), 0);
0N/A }
0N/A __ call(RuntimeAddress(Runtime1::entry_for(_stub)));
0N/A ce->add_call_info_here(_info);
0N/A debug_only(__ should_not_reach_here());
0N/A}
0N/A
0N/A
0N/Avoid ArrayCopyStub::emit_code(LIR_Assembler* ce) {
0N/A //---------------slow case: call to native-----------------
0N/A __ bind(_entry);
0N/A // Figure out where the args should go
0N/A // This should really convert the IntrinsicID to the methodOop and signature
0N/A // but I don't know how to do that.
0N/A //
0N/A VMRegPair args[5];
0N/A BasicType signature[5] = { T_OBJECT, T_INT, T_OBJECT, T_INT, T_INT};
0N/A SharedRuntime::java_calling_convention(signature, args, 5, true);
0N/A
0N/A // push parameters
0N/A // (src, src_pos, dest, destPos, length)
0N/A Register r[5];
0N/A r[0] = src()->as_register();
0N/A r[1] = src_pos()->as_register();
0N/A r[2] = dst()->as_register();
0N/A r[3] = dst_pos()->as_register();
0N/A r[4] = length()->as_register();
0N/A
0N/A // next registers will get stored on the stack
0N/A for (int i = 0; i < 5 ; i++ ) {
0N/A VMReg r_1 = args[i].first();
0N/A if (r_1->is_stack()) {
0N/A int st_off = r_1->reg2stack() * wordSize;
304N/A __ movptr (Address(rsp, st_off), r[i]);
0N/A } else {
0N/A assert(r[i] == args[i].first()->as_Register(), "Wrong register for arg ");
0N/A }
0N/A }
0N/A
0N/A ce->align_call(lir_static_call);
0N/A
0N/A ce->emit_static_call_stub();
0N/A AddressLiteral resolve(SharedRuntime::get_resolve_static_call_stub(),
0N/A relocInfo::static_call_type);
0N/A __ call(resolve);
0N/A ce->add_call_info_here(info());
0N/A
0N/A#ifndef PRODUCT
304N/A __ incrementl(ExternalAddress((address)&Runtime1::_arraycopy_slowcase_cnt));
0N/A#endif
0N/A
0N/A __ jmp(_continuation);
0N/A}
0N/A
342N/A/////////////////////////////////////////////////////////////////////////////
342N/A#ifndef SERIALGC
342N/A
342N/Avoid G1PreBarrierStub::emit_code(LIR_Assembler* ce) {
2346N/A // At this point we know that marking is in progress.
2346N/A // If do_load() is true then we have to emit the
2346N/A // load of the previous value; otherwise it has already
2346N/A // been loaded into _pre_val.
342N/A
342N/A __ bind(_entry);
342N/A assert(pre_val()->is_register(), "Precondition.");
342N/A
342N/A Register pre_val_reg = pre_val()->as_register();
342N/A
2346N/A if (do_load()) {
2346N/A ce->mem2reg(addr(), pre_val(), T_OBJECT, patch_code(), info(), false /*wide*/, false /*unaligned*/);
2346N/A }
342N/A
362N/A __ cmpptr(pre_val_reg, (int32_t) NULL_WORD);
342N/A __ jcc(Assembler::equal, _continuation);
342N/A ce->store_parameter(pre_val()->as_register(), 0);
342N/A __ call(RuntimeAddress(Runtime1::entry_for(Runtime1::g1_pre_barrier_slow_id)));
342N/A __ jmp(_continuation);
342N/A
342N/A}
342N/A
342N/Ajbyte* G1PostBarrierStub::_byte_map_base = NULL;
342N/A
342N/Ajbyte* G1PostBarrierStub::byte_map_base_slow() {
342N/A BarrierSet* bs = Universe::heap()->barrier_set();
342N/A assert(bs->is_a(BarrierSet::G1SATBCTLogging),
342N/A "Must be if we're using this.");
342N/A return ((G1SATBCardTableModRefBS*)bs)->byte_map_base;
342N/A}
342N/A
342N/Avoid G1PostBarrierStub::emit_code(LIR_Assembler* ce) {
342N/A __ bind(_entry);
342N/A assert(addr()->is_register(), "Precondition.");
342N/A assert(new_val()->is_register(), "Precondition.");
342N/A Register new_val_reg = new_val()->as_register();
362N/A __ cmpptr(new_val_reg, (int32_t) NULL_WORD);
342N/A __ jcc(Assembler::equal, _continuation);
1793N/A ce->store_parameter(addr()->as_pointer_register(), 0);
342N/A __ call(RuntimeAddress(Runtime1::entry_for(Runtime1::g1_post_barrier_slow_id)));
342N/A __ jmp(_continuation);
342N/A}
342N/A
342N/A#endif // SERIALGC
342N/A/////////////////////////////////////////////////////////////////////////////
0N/A
0N/A#undef __