/* * Copyright (c) 2000, 2022, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2014, 2020, Red Hat Inc. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. *
*/
#ifndef PRODUCT #define COMMENT(x) do { __ block_comment(x); } while (0) #else #define COMMENT(x) #endif
NEEDS_CLEANUP // remove this definitions ? constRegister IC_Klass = rscratch2; // where the IC klass is cached constRegister SYNC_header = r0; // synchronization header constRegister SHIFT_count = r0; // where count for shift operations must be
Address LIR_Assembler::as_Address_lo(LIR_Address* addr) { return as_Address(addr, rscratch1); // Ouch // FIXME: This needs to be much more clever. See x86.
}
// Ensure a valid Address (base + offset) to a stack-slot. If stack access is // not encodable as a base + (immediate) offset, generate an explicit address // calculation to hold the address in a temporary register.
Address LIR_Assembler::stack_slot_address(int index, uint size, Register tmp, int adjust) {
precond(size == 4 || size == 8);
Address addr = frame_map()->address_for_slot(index, adjust);
precond(addr.getMode() == Address::base_plus_offset);
precond(addr.base() == sp);
precond(addr.offset() > 0);
uint mask = size - 1;
assert((addr.offset() & mask) == 0, "scaled offsets only"); return __ legitimize_address(addr, size, tmp);
}
// we jump here if osr happens with the interpreter // state set up to continue at the beginning of the // loop that triggered osr - in particular, we have // the following registers setup: // // r2: osr buffer //
// build frame
ciMethod* m = compilation()->method();
__ build_frame(initial_frame_size_in_bytes(), bang_size_in_bytes());
// OSR buffer is // // locals[nlocals-1..0] // monitors[0..number_of_locks] // // locals is a direct copy of the interpreter frame so in the osr buffer // so first slot in the local array is the last local from the interpreter // and last slot is local[0] (receiver) from the interpreter // // Similarly with locks. The first lock slot in the osr buffer is the nth lock // from the interpreter frame, the nth lock slot in the osr buffer is 0th lock // in the interpreter frame (the method lock if a sync method)
// Initialize monitors in the compiled activation. // r2: pointer to osr buffer // // All other registers are dead at this point and the locals will be // copied into place by code emitted in the IR.
Register OSR_buf = osrBufferPointer()->as_pointer_register();
{ assert(frame::interpreter_frame_monitor_size() == BasicObjectLock::size(), "adjust code below"); int monitor_offset = BytesPerWord * method()->max_locals() +
(2 * BytesPerWord) * (number_of_locks - 1); // SharedRuntime::OSR_migration_begin() packs BasicObjectLocks in // the OSR buffer using 2 word entries: first the lock and then // the oop. for (int i = 0; i < number_of_locks; i++) { int slot_offset = monitor_offset - ((i * 2) * BytesPerWord); #ifdef ASSERT // verify the interpreter's monitor has a non-null object
{
Label L;
__ ldr(rscratch1, Address(OSR_buf, slot_offset + 1*BytesPerWord));
__ cbnz(rscratch1, L);
__ stop("locked object is NULL");
__ bind(L);
} #endif
__ ldp(r19, r20, Address(OSR_buf, slot_offset));
__ str(r19, frame_map()->address_for_monitor_lock(i));
__ str(r20, frame_map()->address_for_monitor_object(i));
}
}
}
// inline cache check; done before the frame is built. int LIR_Assembler::check_icache() { Register receiver = FrameMap::receiver_opr->as_register(); Register ic_klass = IC_Klass; int start_offset = __ offset();
__ inline_cache_check(receiver, ic_klass);
// if icache check fails, then jump to runtime routine // Note: RECEIVER must still contain the receiver!
Label dont;
__ br(Assembler::EQ, dont);
__ far_jump(RuntimeAddress(SharedRuntime::get_ic_miss_stub()));
// We align the verified entry point unless the method body // (including its inline cache check) will fit in a single 64-byte // icache line. if (! method()->is_accessor() || __ offset() - start_offset > 4 * 4) { // force alignment after the cache check.
__ align(CodeEntryAlignment);
}
__ bind(dont); return start_offset;
}
void LIR_Assembler::clinit_barrier(ciMethod* method) {
assert(VM_Version::supports_fast_class_init_checks(), "sanity");
assert(!method->holder()->is_not_initialized(), "initialization should have been started");
// This specifies the rsp decrement needed to build the frame int LIR_Assembler::initial_frame_size_in_bytes() const { // if rounding, must let FrameMap know!
int LIR_Assembler::emit_exception_handler() { // generate code for exception handler
address handler_base = __ start_a_stub(exception_handler_size()); if (handler_base == NULL) { // not enough space left for the handler
bailout("exception handler overflow"); return -1;
}
int offset = code_offset();
// the exception oop and pc are in r0, and r3 // no other registers need to be preserved, so invalidate them
__ invalidate_registers(false, true, true, false, true, true);
// check that there is really an exception
__ verify_not_null_oop(r0);
// Emit the code to remove the frame from the stack in the exception // unwind path. int LIR_Assembler::emit_unwind_handler() { #ifndef PRODUCT if (CommentedAssembly) {
_masm->block_comment("Unwind handler");
} #endif
int offset = code_offset();
// Fetch the exception from TLS and clear out exception related thread state
__ ldr(r0, Address(rthread, JavaThread::exception_oop_offset()));
__ str(zr, Address(rthread, JavaThread::exception_oop_offset()));
__ str(zr, Address(rthread, JavaThread::exception_pc_offset()));
__ bind(_unwind_handler_entry);
__ verify_not_null_oop(r0); if (method()->is_synchronized() || compilation()->env()->dtrace_method_probes()) {
__ mov(r19, r0); // Preserve the exception
}
if (method()->is_synchronized() || compilation()->env()->dtrace_method_probes()) {
__ mov(r0, r19); // Restore the exception
}
// remove the activation and dispatch to the unwind handler
__ block_comment("remove_frame and dispatch to the unwind handler");
__ remove_frame(initial_frame_size_in_bytes());
__ far_jump(RuntimeAddress(Runtime1::entry_for(Runtime1::unwind_exception_id)));
// Emit the slow path assembly if (stub != NULL) {
stub->emit_code(this);
}
return offset;
}
int LIR_Assembler::emit_deopt_handler() { // generate code for exception handler
address handler_base = __ start_a_stub(deopt_handler_size()); if (handler_base == NULL) { // not enough space left for the handler
bailout("deopt handler overflow"); return -1;
}
switch (type) { case T_ADDRESS:
assert(c->as_jint() == 0, "should be");
insn = &Assembler::str; break; case T_LONG:
assert(c->as_jlong() == 0, "should be");
insn = &Assembler::str; break; case T_INT:
assert(c->as_jint() == 0, "should be");
insn = &Assembler::strw; break; case T_OBJECT: case T_ARRAY:
assert(c->as_jobject() == 0, "should be"); if (UseCompressedOops && !wide) {
insn = &Assembler::strw;
} else {
insn = &Assembler::str;
} break; case T_CHAR: case T_SHORT:
assert(c->as_jint() == 0, "should be");
insn = &Assembler::strh; break; case T_BOOLEAN: case T_BYTE:
assert(c->as_jint() == 0, "should be");
insn = &Assembler::strb; break; default:
ShouldNotReachHere();
insn = &Assembler::str; // unreachable
}
if (info) add_debug_info_for_null_check_here(info);
(_masm->*insn)(zr, as_Address(to_addr, rscratch1));
}
void LIR_Assembler::reg2reg(LIR_Opr src, LIR_Opr dest) {
assert(src->is_register(), "should not call otherwise");
assert(dest->is_register(), "should not call otherwise");
// move between cpu-registers if (dest->is_single_cpu()) { if (src->type() == T_LONG) { // Can do LONG -> OBJECT
move_regs(src->as_register_lo(), dest->as_register()); return;
}
assert(src->is_single_cpu(), "must match"); if (src->type() == T_OBJECT) {
__ verify_oop(src->as_register());
}
move_regs(src->as_register(), dest->as_register());
} elseif (dest->is_double_cpu()) { if (is_reference_type(src->type())) { // Surprising to me but we can see move of a long to t_object
__ verify_oop(src->as_register());
move_regs(src->as_register(), dest->as_register_lo()); return;
}
assert(src->is_double_cpu(), "must match"); Register f_lo = src->as_register_lo(); Register f_hi = src->as_register_hi(); Register t_lo = dest->as_register_lo(); Register t_hi = dest->as_register_hi();
assert(f_hi == f_lo, "must be same");
assert(t_hi == t_lo, "must be same");
move_regs(f_lo, t_lo);
int null_check_here = code_offset(); switch (type) { case T_FLOAT: {
__ strs(src->as_float_reg(), as_Address(to_addr)); break;
}
case T_DOUBLE: {
__ strd(src->as_double_reg(), as_Address(to_addr)); break;
}
case T_ARRAY: // fall through case T_OBJECT: // fall through if (UseCompressedOops && !wide) {
__ strw(compressed_src, as_Address(to_addr, rscratch2));
} else {
__ str(compressed_src, as_Address(to_addr));
} break; case T_METADATA: // We get here to store a method pointer to the stack to pass to // a dtrace runtime call. This can't work on 64 bit with // compressed klass ptrs: T_METADATA can be a compressed klass // ptr or a 64 bit method pointer.
ShouldNotReachHere();
__ str(src->as_register(), as_Address(to_addr)); break; case T_ADDRESS:
__ str(src->as_register(), as_Address(to_addr)); break; case T_INT:
__ strw(src->as_register(), as_Address(to_addr)); break;
case T_LONG: {
__ str(src->as_register_lo(), as_Address_lo(to_addr)); break;
}
case T_BYTE: // fall through case T_BOOLEAN: {
__ strb(src->as_register(), as_Address(to_addr)); break;
}
case T_CHAR: // fall through case T_SHORT:
__ strh(src->as_register(), as_Address(to_addr)); break;
if (addr->base()->type() == T_OBJECT) {
__ verify_oop(addr->base()->as_pointer_register());
}
if (patch_code != lir_patch_none) {
deoptimize_trap(info); return;
}
if (info != NULL) {
add_debug_info_for_null_check_here(info);
} int null_check_here = code_offset(); switch (type) { case T_FLOAT: {
__ ldrs(dest->as_float_reg(), as_Address(from_addr)); break;
}
case T_DOUBLE: {
__ ldrd(dest->as_double_reg(), as_Address(from_addr)); break;
}
case T_ARRAY: // fall through case T_OBJECT: // fall through if (UseCompressedOops && !wide) {
__ ldrw(dest->as_register(), as_Address(from_addr));
} else {
__ ldr(dest->as_register(), as_Address(from_addr));
} break; case T_METADATA: // We get here to store a method pointer to the stack to pass to // a dtrace runtime call. This can't work on 64 bit with // compressed klass ptrs: T_METADATA can be a compressed klass // ptr or a 64 bit method pointer.
ShouldNotReachHere();
__ ldr(dest->as_register(), as_Address(from_addr)); break; case T_ADDRESS:
__ ldr(dest->as_register(), as_Address(from_addr)); break; case T_INT:
__ ldrw(dest->as_register(), as_Address(from_addr)); break;
case T_LONG: {
__ ldr(dest->as_register_lo(), as_Address_lo(from_addr)); break;
}
case T_BYTE:
__ ldrsb(dest->as_register(), as_Address(from_addr)); break; case T_BOOLEAN: {
__ ldrb(dest->as_register(), as_Address(from_addr)); break;
}
case T_CHAR:
__ ldrh(dest->as_register(), as_Address(from_addr)); break; case T_SHORT:
__ ldrsh(dest->as_register(), as_Address(from_addr)); break;
default:
ShouldNotReachHere();
}
if (is_reference_type(type)) { if (UseCompressedOops && !wide) {
__ decode_heap_oop(dest->as_register());
}
if (!UseZGC) { // Load barrier has not yet been applied, so ZGC can't verify the oop here
__ verify_oop(dest->as_register());
}
}
}
int LIR_Assembler::array_element_size(BasicType type) const { int elem_size = type2aelembytes(type); return exact_log2(elem_size);
}
void LIR_Assembler::emit_op3(LIR_Op3* op) { switch (op->code()) { case lir_idiv: case lir_irem:
arithmetic_idiv(op->code(),
op->in_opr1(),
op->in_opr2(),
op->in_opr3(),
op->result_opr(),
op->info()); break; case lir_fmad:
__ fmaddd(op->result_opr()->as_double_reg(),
op->in_opr1()->as_double_reg(),
op->in_opr2()->as_double_reg(),
op->in_opr3()->as_double_reg()); break; case lir_fmaf:
__ fmadds(op->result_opr()->as_float_reg(),
op->in_opr1()->as_float_reg(),
op->in_opr2()->as_float_reg(),
op->in_opr3()->as_float_reg()); break; default: ShouldNotReachHere(); break;
}
}
if (op->fast_check()) { // get object class // not a safepoint as obj null check happens earlier
__ load_klass(rscratch1, obj);
__ cmp( rscratch1, k_RInfo);
__ br(Assembler::NE, *failure_target); // successful cast, fall through to profile or jump
} else { // get object class // not a safepoint as obj null check happens earlier
__ load_klass(klass_RInfo, obj); if (k->is_loaded()) { // See if we get an immediate positive hit
__ ldr(rscratch1, Address(klass_RInfo, int64_t(k->super_check_offset())));
__ cmp(k_RInfo, rscratch1); if ((juint)in_bytes(Klass::secondary_super_cache_offset()) != k->super_check_offset()) {
__ br(Assembler::NE, *failure_target); // successful cast, fall through to profile or jump
} else { // See if we get an immediate positive hit
__ br(Assembler::EQ, *success_target); // check for self
__ cmp(klass_RInfo, k_RInfo);
__ br(Assembler::EQ, *success_target);
__ stp(klass_RInfo, k_RInfo, Address(__ pre(sp, -2 * wordSize)));
__ far_call(RuntimeAddress(Runtime1::entry_for(Runtime1::slow_subtype_check_id)));
__ ldr(klass_RInfo, Address(__ post(sp, 2 * wordSize))); // result is a boolean
__ cbzw(klass_RInfo, *failure_target); // successful cast, fall through to profile or jump
}
} else { // perform the fast part of the checking logic
__ check_klass_subtype_fast_path(klass_RInfo, k_RInfo, Rtmp1, success_target, failure_target, NULL); // call out-of-line instance of __ check_klass_subtype_slow_path(...):
__ stp(klass_RInfo, k_RInfo, Address(__ pre(sp, -2 * wordSize)));
__ far_call(RuntimeAddress(Runtime1::entry_for(Runtime1::slow_subtype_check_id)));
__ ldp(k_RInfo, klass_RInfo, Address(__ post(sp, 2 * wordSize))); // result is a boolean
__ cbz(k_RInfo, *failure_target); // successful cast, fall through to profile or jump
}
} if (should_profile) { Register mdo = klass_RInfo, recv = k_RInfo;
__ bind(profile_cast_success);
__ mov_metadata(mdo, md->constant_encoding());
__ load_klass(recv, obj);
Label update_done;
type_profile_helper(mdo, md, data, recv, success);
__ b(*success);
// get instance klass (it's already uncompressed)
__ ldr(k_RInfo, Address(k_RInfo, ObjArrayKlass::element_klass_offset())); // perform the fast part of the checking logic
__ check_klass_subtype_fast_path(klass_RInfo, k_RInfo, Rtmp1, success_target, failure_target, NULL); // call out-of-line instance of __ check_klass_subtype_slow_path(...):
__ stp(klass_RInfo, k_RInfo, Address(__ pre(sp, -2 * wordSize)));
__ far_call(RuntimeAddress(Runtime1::entry_for(Runtime1::slow_subtype_check_id)));
__ ldp(k_RInfo, klass_RInfo, Address(__ post(sp, 2 * wordSize))); // result is a boolean
__ cbzw(k_RInfo, *failure_target); // fall through to the success case
void LIR_Assembler::arith_op(LIR_Code code, LIR_Opr left, LIR_Opr right, LIR_Opr dest, CodeEmitInfo* info, bool pop_fpu_stack) {
assert(info == NULL, "should never be used, idiv/irem and ldiv/lrem not handled by this method");
// FIXME. This is fugly: we really need to factor all this logic. switch(right->type()) { case T_LONG:
c = right->as_constant_ptr()->as_jlong(); break; case T_INT: case T_ADDRESS:
c = right->as_constant_ptr()->as_jint(); break; default:
ShouldNotReachHere();
c = 0; // unreachable break;
}
// opcode check
assert((code == lir_idiv) || (code == lir_irem), "opcode must be idiv or irem"); bool is_irem = (code == lir_irem);
// operand check
assert(left->is_single_cpu(), "left must be register");
assert(right->is_single_cpu() || right->is_constant(), "right must be register or constant");
assert(result->is_single_cpu(), "result must be register"); Register lreg = left->as_register(); Register dreg = result->as_register();
// power-of-2 constant check and codegen if (right->is_constant()) { int c = right->as_constant_ptr()->as_jint();
assert(c > 0 && is_power_of_2(c), "divisor must be power-of-2 constant"); if (is_irem) { if (c == 1) { // move 0 to dreg if divisor is 1
__ movw(dreg, zr);
} else { // use rscratch1 as intermediate result register
__ negsw(rscratch1, lreg);
__ andw(dreg, lreg, c - 1);
__ andw(rscratch1, rscratch1, c - 1);
__ csnegw(dreg, dreg, rscratch1, Assembler::MI);
}
} else { if (c == 1) { // move lreg to dreg if divisor is 1
__ movw(dreg, lreg);
} else { unsignedint shift = exact_log2(c); // use rscratch1 as intermediate result register
__ asrw(rscratch1, lreg, 31);
__ addw(rscratch1, lreg, rscratch1, Assembler::LSR, 32 - shift);
__ asrw(dreg, rscratch1, shift);
}
}
} else { Register rreg = right->as_register();
__ corrected_idivl(dreg, lreg, rreg, is_irem, rscratch1);
}
}
// exception object is not added to oop map by LinearScan // (LinearScan assumes that no oops are in fixed registers)
info->add_register_oop(exceptionOop);
Runtime1::StubID unwind_id;
// get current pc information // pc is only needed if the method has an exception handler, the unwind code does not need it. if (compilation()->debug_info_recorder()->last_pc_offset() == __ offset()) { // As no instructions have been generated yet for this LIR node it's // possible that an oop map already exists for the current offset. // In that case insert an dummy NOP here to ensure all oop map PCs // are unique. See JDK-8237483.
__ nop();
} int pc_for_athrow_offset = __ offset();
InternalAddress pc_for_athrow(__ pc());
__ adr(exceptionPC->as_register(), pc_for_athrow);
add_call_info(pc_for_athrow_offset, info); // for exception handler
void LIR_Assembler::store_parameter(jobject o, int offset_from_rsp_in_words) {
ShouldNotReachHere();
assert(offset_from_rsp_in_words >= 0, "invalid offset from rsp"); int offset_from_rsp_in_bytes = offset_from_rsp_in_words * BytesPerWord;
assert(offset_from_rsp_in_bytes < frame_map()->reserved_argument_area_size(), "invalid offset");
__ lea(rscratch1, __ constant_oop_address(o));
__ str(rscratch1, Address(sp, offset_from_rsp_in_bytes));
}
// This code replaces a call to arraycopy; no exception may // be thrown in this code, they must be thrown in the System.arraycopy // activation frame; we could save some checks if this would not be the case void LIR_Assembler::emit_arraycopy(LIR_OpArrayCopy* op) {
ciArrayKlass* default_type = op->expected_type(); Register src = op->src()->as_register(); Register dst = op->dst()->as_register(); Register src_pos = op->src_pos()->as_register(); Register dst_pos = op->dst_pos()->as_register(); Register length = op->length()->as_register(); Register tmp = op->tmp()->as_register();
// if we don't know anything, just go through the generic arraycopy if (default_type == NULL // || basic_type == T_OBJECT
) {
Label done;
assert(src == r1 && src_pos == r2, "mismatch in calling convention");
// Save the arguments in case the generic arraycopy fails and we // have to fall back to the JNI stub
__ stp(dst, dst_pos, Address(sp, 0*BytesPerWord));
__ stp(length, src_pos, Address(sp, 2*BytesPerWord));
__ str(src, Address(sp, 4*BytesPerWord));
// The arguments are in java calling convention so we shift them // to C convention
assert_different_registers(c_rarg0, j_rarg1, j_rarg2, j_rarg3, j_rarg4);
__ mov(c_rarg0, j_rarg0);
assert_different_registers(c_rarg1, j_rarg2, j_rarg3, j_rarg4);
__ mov(c_rarg1, j_rarg1);
assert_different_registers(c_rarg2, j_rarg3, j_rarg4);
__ mov(c_rarg2, j_rarg2);
assert_different_registers(c_rarg3, j_rarg4);
__ mov(c_rarg3, j_rarg3);
__ mov(c_rarg4, j_rarg4); #ifndef PRODUCT if (PrintC1Statistics) {
__ incrementw(ExternalAddress((address)&Runtime1::_generic_arraycopystub_cnt));
} #endif
__ far_call(RuntimeAddress(copyfunc_addr));
__ cbz(r0, *stub->continuation());
// Reload values from the stack so they are where the stub // expects them.
__ ldp(dst, dst_pos, Address(sp, 0*BytesPerWord));
__ ldp(length, src_pos, Address(sp, 2*BytesPerWord));
__ ldr(src, Address(sp, 4*BytesPerWord));
// r0 is -1^K where K == partial copied count
__ eonw(rscratch1, r0, zr); // adjust length down and src/end pos up by partial copied count
__ subw(length, length, rscratch1);
__ addw(src_pos, src_pos, rscratch1);
__ addw(dst_pos, dst_pos, rscratch1);
__ b(*stub->entry());
__ bind(*stub->continuation()); return;
}
assert(default_type != NULL && default_type->is_array_klass() && default_type->is_loaded(), "must be true at this point");
int elem_size = type2aelembytes(basic_type); int scale = exact_log2(elem_size);
// test for NULL if (flags & LIR_OpArrayCopy::src_null_check) {
__ cbz(src, *stub->entry());
} if (flags & LIR_OpArrayCopy::dst_null_check) {
__ cbz(dst, *stub->entry());
}
// If the compiler was not able to prove that exact type of the source or the destination // of the arraycopy is an array type, check at runtime if the source or the destination is // an instance type. if (flags & LIR_OpArrayCopy::type_check) { if (!(flags & LIR_OpArrayCopy::LIR_OpArrayCopy::dst_objarray)) {
__ load_klass(tmp, dst);
__ ldrw(rscratch1, Address(tmp, in_bytes(Klass::layout_helper_offset())));
__ cmpw(rscratch1, Klass::_lh_neutral_value);
__ br(Assembler::GE, *stub->entry());
}
if (flags & LIR_OpArrayCopy::type_check) { // We don't know the array types are compatible if (basic_type != T_OBJECT) { // Simple test for basic type arrays if (UseCompressedClassPointers) {
__ ldrw(tmp, src_klass_addr);
__ ldrw(rscratch1, dst_klass_addr);
__ cmpw(tmp, rscratch1);
} else {
__ ldr(tmp, src_klass_addr);
__ ldr(rscratch1, dst_klass_addr);
__ cmp(tmp, rscratch1);
}
__ br(Assembler::NE, *stub->entry());
} else { // For object arrays, if src is a sub class of dst then we can // safely do the copy.
Label cont, slow;
address copyfunc_addr = StubRoutines::checkcast_arraycopy(); if (copyfunc_addr != NULL) { // use stub if available // src is not a sub class of dst so we have to do a // per-element check.
int mask = LIR_OpArrayCopy::src_objarray|LIR_OpArrayCopy::dst_objarray; if ((flags & mask) != mask) { // Check that at least both of them object arrays.
assert(flags & mask, "one of the two should be known to be an object array");
// Spill because stubs can use any register they like and it's // easier to restore just those that we care about.
__ stp(dst, dst_pos, Address(sp, 0*BytesPerWord));
__ stp(length, src_pos, Address(sp, 2*BytesPerWord));
__ str(src, Address(sp, 4*BytesPerWord));
// return value is -1^K where K is partial copied count
__ eonw(rscratch1, r0, zr); // adjust length down and src/end pos up by partial copied count
__ subw(length, length, rscratch1);
__ addw(src_pos, src_pos, rscratch1);
__ addw(dst_pos, dst_pos, rscratch1);
}
__ b(*stub->entry());
__ bind(cont);
__ POP(src, dst);
}
}
#ifdef ASSERT if (basic_type != T_OBJECT || !(flags & LIR_OpArrayCopy::type_check)) { // Sanity check the known type with the incoming class. For the // primitive case the types must match exactly with src.klass and // dst.klass each exactly matching the default type. For the // object array case, if no type check is needed then either the // dst type is exactly the expected type and the src type is a // subtype which we can't check or src is the same array as dst // but not necessarily exactly of type default_type.
Label known_ok, halt;
__ mov_metadata(tmp, default_type->constant_encoding()); if (UseCompressedClassPointers) {
__ encode_klass_not_null(tmp);
}
void LIR_Assembler::emit_lock(LIR_OpLock* op) { Register obj = op->obj_opr()->as_register(); // may not be an oop Register hdr = op->hdr_opr()->as_register(); Register lock = op->lock_opr()->as_register(); if (UseHeavyMonitors) { if (op->info() != NULL) {
add_debug_info_for_null_check_here(op->info());
__ null_check(obj, -1);
}
__ b(*op->stub()->entry());
} elseif (op->code() == lir_lock) {
assert(BasicLock::displaced_header_offset_in_bytes() == 0, "lock_reg must point to the displaced header"); // add debug info for NullPointerException only if one is possible int null_check_offset = __ lock_object(hdr, obj, lock, *op->stub()->entry()); if (op->info() != NULL) {
add_debug_info_for_null_check(null_check_offset, op->info());
} // done
} elseif (op->code() == lir_unlock) {
assert(BasicLock::displaced_header_offset_in_bytes() == 0, "lock_reg must point to the displaced header");
__ unlock_object(hdr, obj, lock, *op->stub()->entry());
} else {
Unimplemented();
}
__ bind(*op->stub()->continuation());
}
// Update counter for all call types
ciMethodData* md = method->method_data_or_null();
assert(md != NULL, "Sanity");
ciProfileData* data = md->bci_to_data(bci);
assert(data != NULL && data->is_CounterData(), "need CounterData for calls");
assert(op->mdo()->is_single_cpu(), "mdo must be allocated"); Register mdo = op->mdo()->as_register();
__ mov_metadata(mdo, md->constant_encoding());
Address counter_addr(mdo, md->byte_offset_of_slot(data, CounterData::count_offset())); // Perform additional virtual call profiling for invokevirtual and // invokeinterface bytecodes if (op->should_profile_receiver_type()) {
assert(op->recv()->is_single_cpu(), "recv must be allocated"); Register recv = op->recv()->as_register();
assert_different_registers(mdo, recv);
assert(data->is_VirtualCallData(), "need VirtualCallData for virtual calls");
ciKlass* known_klass = op->known_holder(); if (C1OptimizeVirtualCallProfiling && known_klass != NULL) { // We know the type that will be seen at this call site; we can // statically update the MethodData* rather than needing to do // dynamic tests on the receiver type
// NOTE: we should probably put a lock around this search to // avoid collisions by concurrent compilations
ciVirtualCallData* vc_data = (ciVirtualCallData*) data;
uint i; for (i = 0; i < VirtualCallData::row_limit(); i++) {
ciKlass* receiver = vc_data->receiver(i); if (known_klass->equals(receiver)) {
Address data_addr(mdo, md->byte_offset_of_slot(data, VirtualCallData::receiver_count_offset(i)));
__ addptr(data_addr, DataLayout::counter_increment); return;
}
}
// Receiver type not found in profile data; select an empty slot
// Note that this is less efficient than it should be because it // always does a write to the receiver part of the // VirtualCallData rather than just the first time for (i = 0; i < VirtualCallData::row_limit(); i++) {
ciKlass* receiver = vc_data->receiver(i); if (receiver == NULL) {
Address recv_addr(mdo, md->byte_offset_of_slot(data, VirtualCallData::receiver_offset(i)));
__ mov_metadata(rscratch1, known_klass->constant_encoding());
__ lea(rscratch2, recv_addr);
__ str(rscratch1, Address(rscratch2));
Address data_addr(mdo, md->byte_offset_of_slot(data, VirtualCallData::receiver_count_offset(i)));
__ addptr(data_addr, DataLayout::counter_increment); return;
}
}
} else {
__ load_klass(recv, recv);
Label update_done;
type_profile_helper(mdo, md, data, recv, &update_done); // Receiver did not match any saved receiver and there is no empty row for it. // Increment total counter to indicate polymorphic case.
__ addptr(counter_addr, DataLayout::counter_increment);
void LIR_Assembler::emit_updatecrc32(LIR_OpUpdateCRC32* op) {
assert(op->crc()->is_single_cpu(), "crc must be register");
assert(op->val()->is_single_cpu(), "byte value must be register");
assert(op->result_opr()->is_single_cpu(), "result must be register"); Register crc = op->crc()->as_register(); Register val = op->val()->as_register(); Register res = op->result_opr()->as_register();
assert(do_null || do_update, "why are we here?");
assert(!TypeEntries::was_null_seen(current_klass) || do_update, "why are we here?");
assert(mdo_addr.base() != rscratch1, "wrong register");
if (do_update) { #ifdef ASSERT if (exact_klass != NULL) {
Label ok;
__ load_klass(tmp, tmp);
__ mov_metadata(rscratch1, exact_klass->constant_encoding());
__ eor(rscratch1, tmp, rscratch1);
__ cbz(rscratch1, ok);
__ stop("exact klass and actual klass differ");
__ bind(ok);
} #endif if (!no_conflict) { if (exact_klass == NULL || TypeEntries::is_type_none(current_klass)) { if (exact_klass != NULL) {
__ mov_metadata(tmp, exact_klass->constant_encoding());
} else {
__ load_klass(tmp, tmp);
}
__ ldr(rscratch2, mdo_addr);
__ eor(tmp, tmp, rscratch2);
__ andr(rscratch1, tmp, TypeEntries::type_klass_mask); // klass seen before, nothing to do. The unknown bit may have been // set already but no need to check.
__ cbz(rscratch1, next);
__ tbnz(tmp, exact_log2(TypeEntries::type_unknown), next); // already unknown. Nothing to do anymore.
if (TypeEntries::is_type_none(current_klass)) {
__ cbz(rscratch2, none);
__ cmp(rscratch2, (u1)TypeEntries::null_seen);
__ br(Assembler::EQ, none); // There is a chance that the checks above (re-reading profiling // data from memory) fail if another thread has just set the // profiling to this obj's klass
__ dmb(Assembler::ISHLD);
__ ldr(rscratch2, mdo_addr);
__ eor(tmp, tmp, rscratch2);
__ andr(rscratch1, tmp, TypeEntries::type_klass_mask);
__ cbz(rscratch1, next);
}
} else {
assert(ciTypeEntries::valid_ciklass(current_klass) != NULL &&
ciTypeEntries::valid_ciklass(current_klass) != exact_klass, "conflict only");
__ ldr(tmp, mdo_addr);
__ tbnz(tmp, exact_log2(TypeEntries::type_unknown), next); // already unknown. Nothing to do anymore.
}
// different than before. Cannot keep accurate profile.
__ ldr(rscratch2, mdo_addr);
__ orr(rscratch2, rscratch2, TypeEntries::type_unknown);
__ str(rscratch2, mdo_addr);
if (TypeEntries::is_type_none(current_klass)) {
__ b(next);
__ bind(none); // first time here. Set profile type.
__ str(tmp, mdo_addr);
}
} else { // There's a single possible klass at this profile point
assert(exact_klass != NULL, "should be"); if (TypeEntries::is_type_none(current_klass)) {
__ mov_metadata(tmp, exact_klass->constant_encoding());
__ ldr(rscratch2, mdo_addr);
__ eor(tmp, tmp, rscratch2);
__ andr(rscratch1, tmp, TypeEntries::type_klass_mask);
__ cbz(rscratch1, next); #ifdef ASSERT
{
Label ok;
__ ldr(rscratch1, mdo_addr);
__ cbz(rscratch1, ok);
__ cmp(rscratch1, (u1)TypeEntries::null_seen);
__ br(Assembler::EQ, ok); // may have been set by another thread
__ dmb(Assembler::ISHLD);
__ mov_metadata(rscratch1, exact_klass->constant_encoding());
__ ldr(rscratch2, mdo_addr);
__ eor(rscratch2, rscratch1, rscratch2);
__ andr(rscratch2, rscratch2, TypeEntries::type_mask);
__ cbz(rscratch2, ok);
__ stop("unexpected profiling mismatch");
__ bind(ok);
} #endif // first time here. Set profile type.
__ str(tmp, mdo_addr);
} else {
assert(ciTypeEntries::valid_ciklass(current_klass) != NULL &&
ciTypeEntries::valid_ciklass(current_klass) != exact_klass, "inconsistent");
__ ldr(tmp, mdo_addr);
__ tbnz(tmp, exact_log2(TypeEntries::type_unknown), next); // already unknown. Nothing to do anymore.
void LIR_Assembler::negate(LIR_Opr left, LIR_Opr dest, LIR_Opr tmp) { // tmp must be unused
assert(tmp->is_illegal(), "wasting a register if tmp is allocated");
if (left->is_single_cpu()) {
assert(dest->is_single_cpu(), "expect single result reg");
__ negw(dest->as_register(), left->as_register());
} elseif (left->is_double_cpu()) {
assert(dest->is_double_cpu(), "expect double result reg");
__ neg(dest->as_register_lo(), left->as_register_lo());
} elseif (left->is_single_fpu()) {
assert(dest->is_single_fpu(), "expect single float result reg");
__ fnegs(dest->as_float_reg(), left->as_float_reg());
} else {
assert(left->is_double_fpu(), "expect double float operand reg");
assert(dest->is_double_fpu(), "expect double float result reg");
__ fnegd(dest->as_double_reg(), left->as_double_reg());
}
}
if (op->in_opr1()->is_valid()) {
assert(op->in_opr2()->is_valid(), "both operands must be valid");
comp_op(op->condition(), op->in_opr1(), op->in_opr2(), op);
} else {
assert(op->in_opr2()->is_illegal(), "both operands must be illegal");
assert(op->condition() == lir_cond_always, "no other conditions allowed");
}
Label ok; if (op->condition() != lir_cond_always) {
Assembler::Condition acond = Assembler::AL; switch (op->condition()) { case lir_cond_equal: acond = Assembler::EQ; break; case lir_cond_notEqual: acond = Assembler::NE; break; case lir_cond_less: acond = Assembler::LT; break; case lir_cond_lessEqual: acond = Assembler::LE; break; case lir_cond_greaterEqual: acond = Assembler::GE; break; case lir_cond_greater: acond = Assembler::GT; break; case lir_cond_belowEqual: acond = Assembler::LS; break; case lir_cond_aboveEqual: acond = Assembler::HS; break; default: ShouldNotReachHere();
}
__ br(acond, ok);
} if (op->halt()) { constchar* str = __ code_string(op->msg());
__ stop(str);
} else {
breakpoint();
}
__ bind(ok);
} #endif
#ifndef PRODUCT #define COMMENT(x) do { __ block_comment(x); } while (0) #else #define COMMENT(x) #endif
/* This finite-state automaton recognizes sequences of compare-and- branch instructions. We will turn them into a tableswitch. You could argue that C1 really shouldn't be doing this sort of optimization, but without it the code is really horrible.
*/
enum { start_s, cmp1_s, beq_s, cmp_s } state; int first_key, last_key = -2147483648; int next_key = 0; int start_insn = -1; int last_insn = -1; Register reg = noreg;
LIR_Opr reg_opr;
state = start_s;
LIR_OpList* inst = lir->instructions_list(); for (int i = 0; i < inst->length(); i++) {
LIR_Op* op = inst->at(i); switch (state) { case start_s:
first_key = -1;
start_insn = i; switch (op->code()) { case lir_cmp:
LIR_Opr opr1 = op->as_Op2()->in_opr1();
LIR_Opr opr2 = op->as_Op2()->in_opr2(); if (opr1->is_cpu_register() && opr1->is_single_cpu()
&& opr2->is_constant()
&& opr2->type() == T_INT) {
reg_opr = opr1;
reg = opr1->as_register();
first_key = opr2->as_constant_ptr()->as_jint();
next_key = first_key + 1;
state = cmp_s; goto next_state;
} break;
} break; case cmp_s: switch (op->code()) { case lir_branch: if (op->as_OpBranch()->cond() == lir_cond_equal) {
state = beq_s;
last_insn = i; goto next_state;
}
}
state = start_s; break; case beq_s: switch (op->code()) { case lir_cmp: {
LIR_Opr opr1 = op->as_Op2()->in_opr1();
LIR_Opr opr2 = op->as_Op2()->in_opr2(); if (opr1->is_cpu_register() && opr1->is_single_cpu()
&& opr1->as_register() == reg
&& opr2->is_constant()
&& opr2->type() == T_INT
&& opr2->as_constant_ptr()->as_jint() == next_key) {
last_key = next_key;
next_key++;
state = cmp_s; goto next_state;
}
}
}
last_key = next_key;
state = start_s; break; default:
assert(false, "impossible state");
} if (state == start_s) { if (first_key < last_key - 5L && reg != noreg) {
{ // printf("found run register %d starting at insn %d low value %d high value %d\n", // reg->encoding(), // start_insn, first_key, last_key); // for (int i = 0; i < inst->length(); i++) { // inst->at(i)->print(); // tty->print("\n"); // } // tty->print("\n");
}
struct tableswitch *sw = &switches[tableswitch_count];
sw->_insn_index = start_insn, sw->_first_key = first_key,
sw->_last_key = last_key, sw->_reg = reg;
inst->insert_before(last_insn + 1, new LIR_OpLabel(&sw->_after));
{ // Insert the new table of branches int offset = last_insn; for (int n = first_key; n < last_key; n++) {
inst->insert_before
(last_insn + 1, new LIR_OpBranch(lir_cond_always, T_ILLEGAL,
inst->at(offset)->as_OpBranch()->label()));
offset -= 2, i++;
}
} // Delete all the old compare-and-branch instructions for (int n = first_key; n < last_key; n++) {
inst->remove_at(start_insn);
inst->remove_at(start_insn);
} // Insert the tableswitch instruction
inst->insert_before(start_insn, new LIR_Op2(lir_cmp, lir_cond_always,
LIR_OprFact::intConst(tableswitch_count),
reg_opr));
inst->insert_before(start_insn + 1, new LIR_OpLabel(&sw->_branches));
tableswitch_count++;
}
reg = noreg;
last_key = -2147483648;
}
next_state:
;
} #endif
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.