/* * Copyright (c) 2016, 2022, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2016, 2020 SAP SE. 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. *
*/
// The assumed minimum size of a BranchTableBlock. // The actual size of each block heavily depends on the CPU capabilities and, // of course, on the logic implemented in each block. #ifdef ASSERT #define BTB_MINSIZE 256 #else #define BTB_MINSIZE 64 #endif
#ifdef ASSERT // Macro to open a BranchTableBlock (a piece of code that is branched to by a calculated branch). #define BTB_BEGIN(lbl, alignment, name) \
__ align_address(alignment); \
__ bind(lbl); \
{ unsignedint b_off = __ offset(); \
uintptr_t b_addr = (uintptr_t)__ pc(); \
__ z_larl(Z_R0, (int64_t)0); /* Check current address alignment. */ \
__ z_slgr(Z_R0, br_tab); /* Current Address must be equal */ \
__ z_slgr(Z_R0, flags); /* to calculated branch target. */ \
__ z_brc(Assembler::bcondLogZero, 3); /* skip trap if ok. */ \
__ z_illtrap(0x55); \
guarantee(b_addr%alignment == 0, "bad alignment at begin of block" name);
// Macro to close a BranchTableBlock (a piece of code that is branched to by a calculated branch). #define BTB_END(lbl, alignment, name) \
uintptr_t e_addr = (uintptr_t)__ pc(); \ unsignedint e_off = __ offset(); \ unsignedint len = e_off-b_off; \ if (len > alignment) { \
tty->print_cr("%4d of %4d @ " INTPTR_FORMAT ": Block len for %s", \
len, alignment, e_addr-len, name); \
guarantee(len <= alignment, "block too large"); \
} \
guarantee(len == e_addr-b_addr, "block len mismatch"); \
} #else // Macro to open a BranchTableBlock (a piece of code that is branched to by a calculated branch). #define BTB_BEGIN(lbl, alignment, name) \
__ align_address(alignment); \
__ bind(lbl); \
{ unsignedint b_off = __ offset(); \
uintptr_t b_addr = (uintptr_t)__ pc(); \
guarantee(b_addr%alignment == 0, "bad alignment at begin of block" name);
// Macro to close a BranchTableBlock (a piece of code that is branched to by a calculated branch). #define BTB_END(lbl, alignment, name) \
uintptr_t e_addr = (uintptr_t)__ pc(); \ unsignedint e_off = __ offset(); \ unsignedint len = e_off-b_off; \ if (len > alignment) { \
tty->print_cr("%4d of %4d @ " INTPTR_FORMAT ": Block len for %s", \
len, alignment, e_addr-len, name); \
guarantee(len <= alignment, "block too large"); \
} \
guarantee(len == e_addr-b_addr, "block len mismatch"); \
} #endif// ASSERT
// At top of Java expression stack which may be different than esp(). It // isn't for category 1 objects. staticinline Address at_tos(int slot = 0) { return Address(Z_esp, Interpreter::expr_offset_in_bytes(slot));
}
// Condition conversion static Assembler::branch_condition j_not(TemplateTable::Condition cc) { switch (cc) { case TemplateTable::equal : return Assembler::bcondNotEqual; case TemplateTable::not_equal : return Assembler::bcondEqual; case TemplateTable::less : return Assembler::bcondNotLow; case TemplateTable::less_equal : return Assembler::bcondHigh; case TemplateTable::greater : return Assembler::bcondNotHigh; case TemplateTable::greater_equal: return Assembler::bcondLow;
}
ShouldNotReachHere(); return Assembler::bcondZero;
}
// Do an oop store like *(base + offset) = val // offset can be a register or a constant. staticvoid do_oop_store(InterpreterMacroAssembler* _masm, const Address& addr, Register val, // Noreg means always null. Register tmp1, Register tmp2, Register tmp3,
DecoratorSet decorators) {
assert_different_registers(tmp1, tmp2, tmp3, val, addr.base());
__ store_heap_oop(val, addr, tmp1, tmp2, tmp3, decorators);
}
switch (bc) { case Bytecodes::_fast_aputfield: case Bytecodes::_fast_bputfield: case Bytecodes::_fast_zputfield: case Bytecodes::_fast_cputfield: case Bytecodes::_fast_dputfield: case Bytecodes::_fast_fputfield: case Bytecodes::_fast_iputfield: case Bytecodes::_fast_lputfield: case Bytecodes::_fast_sputfield:
{ // We skip bytecode quickening for putfield instructions when // the put_code written to the constant pool cache is zero. // This is required so that every execution of this instruction // calls out to InterpreterRuntime::resolve_get_put to do // additional, required work.
assert(byte_no == f1_byte || byte_no == f2_byte, "byte_no out of range");
assert(load_bc_into_bc_reg, "we use bc_reg as temp");
__ get_cache_and_index_and_bytecode_at_bcp(Z_R1_scratch, bc_reg,
temp_reg, byte_no, 1);
__ load_const_optimized(bc_reg, bc);
__ compareU32_and_branch(temp_reg, (intptr_t)0,
Assembler::bcondZero, L_patch_done);
} break; default:
assert(byte_no == -1, "sanity"); // The pair bytecodes have already done the load. if (load_bc_into_bc_reg) {
__ load_const_optimized(bc_reg, bc);
} break;
}
if (JvmtiExport::can_post_breakpoint()) {
Label L_fast_patch;
// If a breakpoint is present we can't rewrite the stream directly.
__ z_cli(at_bcp(0), Bytecodes::_breakpoint);
__ z_brne(L_fast_patch);
__ get_method(temp_reg); // Let breakpoint table handling rewrite to quicker bytecode.
__ call_VM_static(noreg,
CAST_FROM_FN_PTR(address, InterpreterRuntime::set_original_bytecode_at),
temp_reg, Z_R13, bc_reg);
__ z_bru(L_patch_done);
__ bind(L_fast_patch);
}
#ifdef ASSERT
NearLabel L_okay;
// We load into 64 bits, since this works on any CPU.
__ z_llgc(temp_reg, at_bcp(0));
__ compareU32_and_branch(temp_reg, Bytecodes::java_code(bc),
Assembler::bcondEqual, L_okay );
__ compareU32_and_branch(temp_reg, bc_reg, Assembler::bcondEqual, L_okay);
__ stop_static("patching the wrong bytecode");
__ bind(L_okay); #endif
void TemplateTable::iconst(int value) {
transition(vtos, itos); // Zero extension of the iconst makes zero extension at runtime obsolete.
__ load_const_optimized(Z_tos, ((unsignedlong)(unsignedint)value));
}
// Get address of type.
__ add2reg_with_index(Raddr_type, tags_offset, RcpIndex, Rtags);
__ z_cli(0, Raddr_type, JVM_CONSTANT_UnresolvedClass);
__ z_bre(call_ldc); // Unresolved class - get the resolved class.
__ z_cli(0, Raddr_type, JVM_CONSTANT_UnresolvedClassInError);
__ z_bre(call_ldc); // Unresolved class in error state - call into runtime // to throw the error from the first resolution attempt.
__ z_cli(0, Raddr_type, JVM_CONSTANT_Class);
__ z_brne(notClass); // Resolved class - need to call vm to get java // mirror of the class.
// We deal with a class. Call vm to do the appropriate.
__ bind(call_ldc);
__ load_const_optimized(Z_ARG2, is_ldc_wide(type) ? 1 : 0);
call_VM(Z_RET, CAST_FROM_FN_PTR(address, InterpreterRuntime::ldc), Z_ARG2);
__ push_ptr(Z_RET);
__ z_bru(Done);
// Not a class.
__ bind(notClass); Register RcpOffset = RcpIndex;
__ z_sllg(RcpOffset, RcpIndex, LogBytesPerWord); // Convert index to offset.
__ z_cli(0, Raddr_type, JVM_CONSTANT_Float);
__ z_brne(notFloat);
// assume the tag is for condy; if not, the VM runtime will tell us
__ bind(notInt);
condy_helper(Done);
__ bind(Done);
}
// Fast path for caching oop constants. // %%% We should use this to handle Class and String constants also. // %%% It will simplify the ldc/primitive path considerably. void TemplateTable::fast_aldc(LdcType type) {
transition(vtos, atos);
constRegister index = Z_tmp_2; int index_size = is_ldc_wide(type) ? sizeof(u2) : sizeof(u1);
Label L_do_resolve, L_resolved;
// We are resolved if the resolved reference cache entry contains a // non-null object (CallSite, etc.).
__ get_cache_index_at_bcp(index, 1, index_size); // Load index.
__ load_resolved_reference_at_index(Z_tos, index);
__ z_ltgr(Z_tos, Z_tos);
__ z_bre(L_do_resolve);
// VMr = obj = base address to find primitive value to push // VMr2 = flags = (tos, off) using format of CPCE::_flags
assert(ConstantPoolCacheEntry::field_index_mask == 0xffff, "or use other instructions");
__ z_llghr(off, flags); const Address field(obj, off);
// What sort of thing are we loading?
__ z_srl(flags, ConstantPoolCacheEntry::tos_state_shift); // Make sure we don't need to mask flags for tos_state after the above shift.
ConstantPoolCacheEntry::verify_tos_state_shift();
switch (bytecode()) { case Bytecodes::_ldc: case Bytecodes::_ldc_w:
{ // tos in (itos, ftos, stos, btos, ctos, ztos)
Label notInt, notFloat, notShort, notByte, notChar, notBool;
__ z_cghi(flags, itos);
__ z_brne(notInt); // itos
__ z_l(Z_tos, field);
__ push(itos);
__ z_bru(Done);
if (RewriteFrequentPairs && rc == may_rewrite) {
NearLabel rewrite, done; constRegister bc = Z_ARG4;
assert(Z_R1_scratch != bc, "register damaged");
// Get next byte.
__ z_llgc(Z_R1_scratch, at_bcp(Bytecodes::length_for (Bytecodes::_iload)));
// If _iload, wait to rewrite to iload2. We only want to rewrite the // last two iloads in a pair. Comparing against fast_iload means that // the next bytecode is neither an iload or a caload, and therefore // an iload pair.
__ compareU32_and_branch(Z_R1_scratch, Bytecodes::_iload,
Assembler::bcondEqual, done);
__ pop_ptr(Z_tmp_2); // Z_tos : index // Z_tmp_2 : array Register index = Z_tos;
index_check(Z_tmp_2, index, LogBytesPerShort); // Load into 64 bits, works on all CPUs.
__ z_llgh(Z_tos,
Address(Z_tmp_2, index, arrayOopDesc::base_offset_in_bytes(T_CHAR)));
}
// Iload followed by caload frequent pair. void TemplateTable::fast_icaload() {
transition(vtos, itos);
// Load index out of locals.
locals_index(Z_R1_scratch);
__ mem2reg_opt(Z_ARG3, iaddress(_masm, Z_R1_scratch), false); // Z_ARG3 : index // Z_tmp_2 : array
__ pop_ptr(Z_tmp_2);
index_check(Z_tmp_2, Z_ARG3, LogBytesPerShort); // Load into 64 bits, works on all CPUs.
__ z_llgh(Z_tos,
Address(Z_tmp_2, Z_ARG3, arrayOopDesc::base_offset_in_bytes(T_CHAR)));
}
// According to bytecode histograms, the pairs: // // _aload_0, _fast_igetfield // _aload_0, _fast_agetfield // _aload_0, _fast_fgetfield // // occur frequently. If RewriteFrequentPairs is set, the (slow) // _aload_0 bytecode checks if the next bytecode is either // _fast_igetfield, _fast_agetfield or _fast_fgetfield and then // rewrites the current bytecode into a pair bytecode; otherwise it // rewrites the current bytecode into _fast_aload_0 that doesn't do // the pair check anymore. // // Note: If the next bytecode is _getfield, the rewrite must be // delayed, otherwise we may miss an opportunity for a pair. // // Also rewrite frequent pairs // aload_0, aload_1 // aload_0, iload_1 // These bytecodes with a small amount of code are most profitable // to rewrite. if (!(RewriteFrequentPairs && (rc == may_rewrite))) {
aload(0); return;
}
NearLabel rewrite, done; constRegister bc = Z_ARG4;
assert(Z_R1_scratch != bc, "register damaged"); // Get next byte.
__ z_llgc(Z_R1_scratch, at_bcp(Bytecodes::length_for (Bytecodes::_aload_0)));
// Do actual aload_0.
aload(0);
// If _getfield then wait with rewrite.
__ compareU32_and_branch(Z_R1_scratch, Bytecodes::_getfield,
Assembler::bcondEqual, done);
// If _igetfield then rewrite to _fast_iaccess_0.
assert(Bytecodes::java_code(Bytecodes::_fast_iaccess_0)
== Bytecodes::_aload_0, "fix bytecode definition");
// If _agetfield then rewrite to _fast_aaccess_0.
assert(Bytecodes::java_code(Bytecodes::_fast_aaccess_0)
== Bytecodes::_aload_0, "fix bytecode definition");
// If _fgetfield then rewrite to _fast_faccess_0.
assert(Bytecodes::java_code(Bytecodes::_fast_faccess_0)
== Bytecodes::_aload_0, "fix bytecode definition");
patch_bytecode(Bytecodes::_aload_0, bc, Z_R1_scratch, false); // Reload local 0 because of VM call inside patch_bytecode(). // this may trigger GC and thus change the oop.
aload(0);
Register index = Z_ARG3; // Index_check expects index in Z_ARG3. // Value is in Z_tos ...
__ pop_i(index); // index
__ pop_ptr(Z_tmp_1); // array
index_check(Z_tmp_1, index, LogBytesPerInt); // ... and then move the value.
__ reg2mem_opt(Z_tos,
Address(Z_tmp_1, index, arrayOopDesc::base_offset_in_bytes(T_INT)), false);
}
// Generate a fast subtype check. Branch to ok_is_subtype if no failure. // Throw if failure. Register tmp1 = Z_tmp_1; Register tmp2 = Z_tmp_2;
__ gen_subtype_check(Rsub_klass, Rsuper_klass, tmp1, tmp2, ok_is_subtype);
// Fall through on failure. // Object is in Rvalue == Z_tos.
assert(Rvalue == Z_tos, "that's the expected location");
__ load_absolute_address(tmp1, Interpreter::_throw_ArrayStoreException_entry);
__ z_br(tmp1);
Register tmp3 = Rsub_klass;
// Have a NULL in Rvalue.
__ bind(is_null);
__ profile_null_seen(tmp1);
// Store a NULL.
do_oop_store(_masm, Address(Rstore_addr, (intptr_t)0), noreg,
tmp3, tmp2, tmp1, IS_ARRAY);
__ z_bru(done);
// Come here on success.
__ bind(ok_is_subtype);
// Now store using the appropriate barrier.
do_oop_store(_masm, Address(Rstore_addr, (intptr_t)0), Rvalue,
tmp3, tmp2, tmp1, IS_ARRAY | IS_NOT_NULL);
__ pop_i(Z_ARG3);
__ pop_ptr(Z_tmp_2); // Z_tos : value // Z_ARG3 : index // Z_tmp_2 : array
// Need to check whether array is boolean or byte // since both types share the bastore bytecode.
__ load_klass(Z_tmp_1, Z_tmp_2);
__ z_llgf(Z_tmp_1, Address(Z_tmp_1, Klass::layout_helper_offset()));
__ z_tmll(Z_tmp_1, Klass::layout_helper_boolean_diffbit());
Label L_skip;
__ z_bfalse(L_skip); // if it is a T_BOOLEAN array, mask the stored value to 0/1
__ z_nilf(Z_tos, 0x1);
__ bind(L_skip);
// No index shift necessary - pass 0.
index_check(Z_tmp_2, Z_ARG3, 0); // Prefer index in Z_ARG3.
__ z_stc(Z_tos,
Address(Z_tmp_2, Z_ARG3, arrayOopDesc::base_offset_in_bytes(T_BYTE)));
}
// stack: ..., a, b
__ load_ptr(0, Z_tos); // load b
__ load_ptr(1, Z_R0_scratch); // load a
__ store_ptr(1, Z_tos); // store b
__ store_ptr(0, Z_R0_scratch); // store a
__ push_ptr(Z_tos); // push b // stack: ..., b, a, b
}
// stack: ..., a, b, c
__ load_ptr(0, Z_R0_scratch); // load c
__ load_ptr(2, Z_R1_scratch); // load a
__ store_ptr(2, Z_R0_scratch); // store c in a
__ push_ptr(Z_R0_scratch); // push c // stack: ..., c, b, c, c
__ load_ptr(2, Z_R0_scratch); // load b
__ store_ptr(2, Z_R1_scratch); // store a in b // stack: ..., c, a, c, c
__ store_ptr(1, Z_R0_scratch); // store b in c // stack: ..., c, a, b, c
}
// stack: ..., a, b
__ load_ptr(1, Z_R0_scratch); // load a
__ push_ptr(Z_R0_scratch); // push a
__ load_ptr(1, Z_R0_scratch); // load b
__ push_ptr(Z_R0_scratch); // push b // stack: ..., a, b, a, b
}
// stack: ..., a, b, c
__ load_ptr(0, Z_R0_scratch); // load c
__ load_ptr(1, Z_R1_scratch); // load b
__ push_ptr(Z_R1_scratch); // push b
__ push_ptr(Z_R0_scratch); // push c // stack: ..., a, b, c, b, c
__ store_ptr(3, Z_R0_scratch); // store c in b // stack: ..., a, c, c, b, c
__ load_ptr( 4, Z_R0_scratch); // load a
__ store_ptr(2, Z_R0_scratch); // store a in 2nd c // stack: ..., a, c, a, b, c
__ store_ptr(4, Z_R1_scratch); // store b in a // stack: ..., b, c, a, b, c
}
// stack: ..., a, b, c, d
__ load_ptr(0, Z_R0_scratch); // load d
__ load_ptr(1, Z_R1_scratch); // load c
__ push_ptr(Z_R1_scratch); // push c
__ push_ptr(Z_R0_scratch); // push d // stack: ..., a, b, c, d, c, d
__ load_ptr(4, Z_R1_scratch); // load b
__ store_ptr(2, Z_R1_scratch); // store b in d
__ store_ptr(4, Z_R0_scratch); // store d in b // stack: ..., a, d, c, b, c, d
__ load_ptr(5, Z_R0_scratch); // load a
__ load_ptr(3, Z_R1_scratch); // load c
__ store_ptr(3, Z_R0_scratch); // store a in c
__ store_ptr(5, Z_R1_scratch); // store c in a // stack: ..., c, d, a, b, c, d
}
// stack: ..., a, b
__ load_ptr(1, Z_R0_scratch); // load a
__ load_ptr(0, Z_R1_scratch); // load b
__ store_ptr(0, Z_R0_scratch); // store a in b
__ store_ptr(1, Z_R1_scratch); // store b in a // stack: ..., b, a
}
__ bind(not_null); // Special case for dividend == 0x8000 and divisor == -1. if (is_ldiv) { // result := Z_tmp_2 := - dividend
__ z_lcgr(Z_tmp_2, Z_tmp_2);
} else { // result remainder := Z_tmp_1 := 0
__ clear_reg(Z_tmp_1, true, false); // Don't set CC.
}
// if divisor == -1 goto done
__ compare64_and_branch(Z_tos, -1, Assembler::bcondEqual, done); if (is_ldiv) // Restore sign, because divisor != -1.
__ z_lcgr(Z_tmp_2, Z_tmp_2);
__ z_dsgr(Z_tmp_1, Z_tos); // Do it.
__ bind(done);
}
// Z_tmp_1 := increment
__ get_2_byte_integer_at_bcp(Z_tmp_1, 4, InterpreterMacroAssembler::Signed); // Z_R1_scratch := index of local to increment
locals_index_wide(Z_tmp_2); // Load, increment, and store.
__ access_local_int(Z_tmp_2, Z_tos);
__ z_agr(Z_tos, Z_tmp_1); // Shifted index is still in Z_tmp_2.
__ reg2mem_opt(Z_tos, Address(Z_locals, Z_tmp_2), false);
}
switch (bytecode()) { case Bytecodes::_i2l: case Bytecodes::_i2f: case Bytecodes::_i2d: case Bytecodes::_i2b: case Bytecodes::_i2c: case Bytecodes::_i2s:
tos_in = itos; break; case Bytecodes::_l2i: case Bytecodes::_l2f: case Bytecodes::_l2d:
tos_in = ltos; break; case Bytecodes::_f2i: case Bytecodes::_f2l: case Bytecodes::_f2d:
tos_in = ftos; break; case Bytecodes::_d2i: case Bytecodes::_d2l: case Bytecodes::_d2f:
tos_in = dtos; break; default :
ShouldNotReachHere();
} switch (bytecode()) { case Bytecodes::_l2i: case Bytecodes::_f2i: case Bytecodes::_d2i: case Bytecodes::_i2b: case Bytecodes::_i2c: case Bytecodes::_i2s:
tos_out = itos; break; case Bytecodes::_i2l: case Bytecodes::_f2l: case Bytecodes::_d2l:
tos_out = ltos; break; case Bytecodes::_i2f: case Bytecodes::_l2f: case Bytecodes::_d2f:
tos_out = ftos; break; case Bytecodes::_i2d: case Bytecodes::_l2d: case Bytecodes::_f2d:
tos_out = dtos; break; default :
ShouldNotReachHere();
}
transition(tos_in, tos_out); #endif// ASSERT
// Conversion
Label done; switch (bytecode()) { case Bytecodes::_i2l:
__ z_lgfr(Z_tos, Z_tos); return; case Bytecodes::_i2f:
__ z_cefbr(Z_ftos, Z_tos); return; case Bytecodes::_i2d:
__ z_cdfbr(Z_ftos, Z_tos); return; case Bytecodes::_i2b: // Sign extend least significant byte.
__ move_reg_if_needed(Z_tos, T_BYTE, Z_tos, T_INT); return; case Bytecodes::_i2c: // Zero extend 2 least significant bytes.
__ move_reg_if_needed(Z_tos, T_CHAR, Z_tos, T_INT); return; case Bytecodes::_i2s: // Sign extend 2 least significant bytes.
__ move_reg_if_needed(Z_tos, T_SHORT, Z_tos, T_INT); return; case Bytecodes::_l2i: // Sign-extend not needed here, upper 4 bytes of int value in register are ignored. return; case Bytecodes::_l2f:
__ z_cegbr(Z_ftos, Z_tos); return; case Bytecodes::_l2d:
__ z_cdgbr(Z_ftos, Z_tos); return; case Bytecodes::_f2i: case Bytecodes::_f2l:
__ clear_reg(Z_tos, true, false); // Don't set CC.
__ z_cebr(Z_ftos, Z_ftos);
__ z_brno(done); // NaN -> 0 if (bytecode() == Bytecodes::_f2i)
__ z_cfebr(Z_tos, Z_ftos, Assembler::to_zero); else// bytecode() == Bytecodes::_f2l
__ z_cgebr(Z_tos, Z_ftos, Assembler::to_zero); break; case Bytecodes::_f2d:
__ move_freg_if_needed(Z_ftos, T_DOUBLE, Z_ftos, T_FLOAT); return; case Bytecodes::_d2i: case Bytecodes::_d2l:
__ clear_reg(Z_tos, true, false); // Ddon't set CC.
__ z_cdbr(Z_ftos, Z_ftos);
__ z_brno(done); // NaN -> 0 if (bytecode() == Bytecodes::_d2i)
__ z_cfdbr(Z_tos, Z_ftos, Assembler::to_zero); else// Bytecodes::_d2l
__ z_cgdbr(Z_tos, Z_ftos, Assembler::to_zero); break; case Bytecodes::_d2f:
__ move_freg_if_needed(Z_ftos, T_FLOAT, Z_ftos, T_DOUBLE); return; default:
ShouldNotReachHere();
}
__ bind(done);
}
if (VM_Version::has_LoadStoreConditional()) {
__ pop_l(val1); // pop value 1.
__ z_lghi(val2, -1); // lt value
__ z_cgr(val1, Z_tos); // Compare with Z_tos (value 2). Protect CC under all circumstances.
__ z_lghi(val1, 1); // gt value
__ z_lghi(Z_tos, 0); // eq value
__ z_locgr(Z_tos, val1, Assembler::bcondHigh);
__ z_locgr(Z_tos, val2, Assembler::bcondLow);
} else {
__ pop_l(val1); // Pop value 1.
__ z_cgr(val1, Z_tos); // Compare with Z_tos (value 2). Protect CC under all circumstances.
__ z_lghi(Z_tos, 0); // eq value
__ z_bre(done);
__ z_lghi(Z_tos, 1); // gt value
__ z_brh(done);
__ z_lghi(Z_tos, -1); // lt value
}
__ bind(done);
}
void TemplateTable::float_cmp(bool is_float, int unordered_result) {
Label done;
// Get (wide) offset to disp. constRegister disp = Z_ARG5; if (is_wide) {
__ get_4_byte_integer_at_bcp(disp, 1);
} else {
__ get_2_byte_integer_at_bcp(disp, 1, InterpreterMacroAssembler::Signed);
}
// Handle all the JSR stuff here, then exit. // It's much shorter and cleaner than intermingling with the // non-JSR normal-branch stuff occurring below. if (is_jsr) { // Compute return address as bci in Z_tos.
__ z_lgr(Z_R1_scratch, Z_bcp);
__ z_sg(Z_R1_scratch, Address(method, Method::const_offset()));
__ add2reg(Z_tos, (is_wide ? 5 : 3) - in_bytes(ConstMethod::codes_offset()), Z_R1_scratch);
// Bump bcp to target of JSR.
__ z_agr(Z_bcp, disp); // Push return address for "ret" on stack.
__ push_ptr(Z_tos); // And away we go!
__ dispatch_next(vtos, 0 , true); return;
}
// Normal (non-jsr) branch handling.
// Bump bytecode pointer by displacement (take the branch).
__ z_agr(Z_bcp, disp);
// Z_RET: osr nmethod (osr ok) or NULL (osr not possible).
__ compare64_and_branch(Z_RET, (intptr_t) 0, Assembler::bcondEqual, dispatch);
// Nmethod may have been invalidated (VM may block upon call_VM return).
__ z_cliy(nmethod::state_offset(), Z_RET, nmethod::in_use);
__ z_brne(dispatch);
// Migrate the interpreter frame off of the stack.
// Assume branch is more often taken than not (loops use backward branches).
NearLabel not_taken;
__ compare32_and_branch(Z_tos, (intptr_t) 0, j_not(cc), not_taken);
branch(false, false);
__ bind(not_taken);
__ profile_not_taken_branch(Z_tos);
}
// Assume branch is more often taken than not (loops use backward branches).
NearLabel not_taken;
__ pop_i(Z_R0_scratch);
__ compare32_and_branch(Z_R0_scratch, Z_tos, j_not(cc), not_taken);
branch(false, false);
__ bind(not_taken);
__ profile_not_taken_branch(Z_tos);
}
// Assume branch is more often taken than not (loops use backward branches) .
NearLabel not_taken;
__ compare64_and_branch(Z_tos, (intptr_t) 0, j_not(cc), not_taken);
branch(false, false);
__ bind(not_taken);
__ profile_not_taken_branch(Z_tos);
}
void TemplateTable::if_acmp(Condition cc) {
transition(atos, vtos); // Assume branch is more often taken than not (loops use backward branches).
NearLabel not_taken;
__ pop_ptr(Z_ARG2);
__ verify_oop(Z_ARG2);
__ verify_oop(Z_tos);
__ compareU64_and_branch(Z_tos, Z_ARG2, j_not(cc), not_taken);
branch(false, false);
__ bind(not_taken);
__ profile_not_taken_branch(Z_ARG3);
}
// Implementation using the following core algorithm: // // int binary_search(int key, LookupswitchPair* array, int n) { // // Binary search according to "Methodik des Programmierens" by // // Edsger W. Dijkstra and W.H.J. Feijen, Addison Wesley Germany 1985. // int i = 0; // int j = n; // while (i+1 < j) { // // invariant P: 0 <= i < j <= n and (a[i] <= key < a[j] or Q) // // with Q: for all i: 0 <= i < n: key < a[i] // // where a stands for the array and assuming that the (inexisting) // // element a[n] is infinitely big. // int h = (i + j) >> 1; // // i < h < j // if (key < array[h].fast_match()) { // j = h; // } else { // i = h; // } // } // // R: a[i] <= key < a[i+1] or Q // // (i.e., if key is within array, i is the correct index) // return i; // }
// Register allocation // Note: Since we use the indices in address operands, we do all the // computation in 64 bits. constRegister key = Z_tos; // Already set (tosca). constRegister array = Z_tmp_1; constRegister i = Z_tmp_2; constRegister j = Z_ARG5; constRegister h = Z_ARG4; constRegister temp = Z_R1_scratch;
// Initialize i & j.
__ clear_reg(i, true, false); // i = 0; Don't set CC.
__ mem2reg_signed_opt(j, Address(array, -BytesPerInt)); // j = length(array);
// And start.
Label entry;
__ z_bru(entry);
// binary search loop
{
NearLabel loop;
__ bind(loop);
// int h = (i + j) >> 1;
__ add2reg_with_index(h, 0, i, j); // h = i + j;
__ z_srag(h, h, 1); // h = (i + j) >> 1;
// if (key < array[h].fast_match()) { // j = h; // } else { // i = h; // }
// Convert array[h].match to native byte-ordering before compare.
__ z_sllg(temp, h, LogBytesPerWord); // index2bytes
__ mem2reg_opt(temp, Address(array, temp), false);
NearLabel else_;
__ compare32_and_branch(key, temp, Assembler::bcondNotLow, else_); // j = h if (key < array[h].fast_match())
__ z_lgr(j, h);
__ z_bru(entry); // continue
__ bind(else_);
// i = h if (key >= array[h].fast_match())
__ z_lgr(i, h); // and fallthrough
// while (i+1 < j)
__ bind(entry);
// if (i + 1 < j) continue search
__ add2reg(h, 1, i);
__ compare64_and_branch(h, j, Assembler::bcondLow, loop);
}
// End of binary search, result index is i (must check again!).
NearLabel default_case;
// h is no longer needed, so use it to hold the byte offset.
__ z_sllg(h, i, LogBytesPerWord); // index2bytes
__ mem2reg_opt(temp, Address(array, h), false);
__ compare32_and_branch(key, temp, Assembler::bcondNotEqual, default_case);
if (state == itos) { // Narrow result if state is itos but result type is smaller. // Need to narrow in the return bytecode rather than in generate_return_entry // since compiled code callers expect the result to already be narrowed.
__ narrow(Z_tos, Z_tmp_1); /* fall through */
}
// The Rcache and index registers must be set before call. // Index is already a byte offset, don't shift! void TemplateTable::load_field_cp_cache_entry(Register obj, Register cache, Register index, Register off, Register flags, bool is_static = false) {
assert_different_registers(cache, index, flags, off);
ByteSize cp_base_offset = ConstantPoolCache::base_offset();
// Only load the lower 4 bytes and fill high bytes of flags with zeros. // Callers depend on this zero-extension!!! // Attention: overwrites cpe_offset == flags
__ z_llgf(flags, Address(cache, cpe_offset, flags_offset + (BytesPerLong-BytesPerInt)));
BLOCK_COMMENT("} load_invoke_cp_cache_entry");
}
// The registers cache and index expected to be set before call. // Correct values of the cache and index registers are preserved. void TemplateTable::jvmti_post_field_access(Register cache, Register index, bool is_static, bool has_tos) {
// Do the JVMTI work here to avoid disturbing the register state below. // We use c_rarg registers here because we want to use the register used in // the call to the VM if (!JvmtiExport::can_post_field_access()) { return;
}
// Check to see if a field access watch has been set before we // take the time to call into the VM.
Label exit;
assert_different_registers(cache, index, Z_tos);
__ load_absolute_address(Z_tos, (address)JvmtiExport::get_field_access_count_addr());
__ load_and_test_int(Z_R0, Address(Z_tos));
__ z_brz(exit);
// Index is returned as byte offset, do not shift!
__ get_cache_and_index_at_bcp(Z_ARG3, Z_R1_scratch, 1);
// btos
BTB_BEGIN(is_Byte, bsize, "getfield_or_static:is_Byte");
__ z_lb(Z_tos, field);
__ push(btos); // Rewrite bytecode to be faster. if (do_rewrite) {
patch_bytecode(Bytecodes::_fast_bgetfield, bc, Z_ARG5);
}
__ z_bru(Done);
BTB_END(is_Byte, bsize, "getfield_or_static:is_Byte");
// ztos
BTB_BEGIN(is_Bool, bsize, "getfield_or_static:is_Bool");
__ z_lb(Z_tos, field);
__ push(ztos); // Rewrite bytecode to be faster. if (do_rewrite) { // Use btos rewriting, no truncating to t/f bit is needed for getfield.
patch_bytecode(Bytecodes::_fast_bgetfield, bc, Z_ARG5);
}
__ z_bru(Done);
BTB_END(is_Bool, bsize, "getfield_or_static:is_Bool");
// ctos
BTB_BEGIN(is_Char, bsize, "getfield_or_static:is_Char"); // Load into 64 bits, works on all CPUs.
__ z_llgh(Z_tos, field);
__ push(ctos); // Rewrite bytecode to be faster. if (do_rewrite) {
patch_bytecode(Bytecodes::_fast_cgetfield, bc, Z_ARG5);
}
__ z_bru(Done);
BTB_END(is_Char, bsize, "getfield_or_static:is_Char");
// stos
BTB_BEGIN(is_Short, bsize, "getfield_or_static:is_Short");
__ z_lh(Z_tos, field);
__ push(stos); // Rewrite bytecode to be faster. if (do_rewrite) {
patch_bytecode(Bytecodes::_fast_sgetfield, bc, Z_ARG5);
}
__ z_bru(Done);
BTB_END(is_Short, bsize, "getfield_or_static:is_Short");
// itos
BTB_BEGIN(is_Int, bsize, "getfield_or_static:is_Int");
__ mem2reg_opt(Z_tos, field, false);
__ push(itos); // Rewrite bytecode to be faster. if (do_rewrite) {
patch_bytecode(Bytecodes::_fast_igetfield, bc, Z_ARG5);
}
__ z_bru(Done);
BTB_END(is_Int, bsize, "getfield_or_static:is_Int");
// ltos
BTB_BEGIN(is_Long, bsize, "getfield_or_static:is_Long");
__ mem2reg_opt(Z_tos, field);
__ push(ltos); // Rewrite bytecode to be faster. if (do_rewrite) {
patch_bytecode(Bytecodes::_fast_lgetfield, bc, Z_ARG5);
}
__ z_bru(Done);
BTB_END(is_Long, bsize, "getfield_or_static:is_Long");
// ftos
BTB_BEGIN(is_Float, bsize, "getfield_or_static:is_Float");
__ mem2freg_opt(Z_ftos, field, false);
__ push(ftos); // Rewrite bytecode to be faster. if (do_rewrite) {
patch_bytecode(Bytecodes::_fast_fgetfield, bc, Z_ARG5);
}
__ z_bru(Done);
BTB_END(is_Float, bsize, "getfield_or_static:is_Float");
// dtos
BTB_BEGIN(is_Double, bsize, "getfield_or_static:is_Double");
__ mem2freg_opt(Z_ftos, field);
__ push(dtos); // Rewrite bytecode to be faster. if (do_rewrite) {
patch_bytecode(Bytecodes::_fast_dgetfield, bc, Z_ARG5);
}
__ z_bru(Done);
BTB_END(is_Double, bsize, "getfield_or_static:is_Double");
__ align_address(64);
BIND(is_badState); // Do this outside branch table. Needs a lot of space.
{ unsignedint b_off = __ offset(); if (is_static) {
__ stop_static("Bad state in getstatic");
} else {
__ stop_static("Bad state in getfield");
} unsignedint e_off = __ offset();
}
__ align_address(64);
BIND(atosHandler); // Oops are really complicated to handle. // There is a lot of code generated. // Therefore: generate the handler outside of branch table. // There is no performance penalty. The additional branch // to here is compensated for by the fallthru to "Done".
{ unsignedint b_off = __ offset();
do_oop_load(_masm, field, Z_tos, Z_tmp_2, Z_tmp_3, IN_HEAP);
__ verify_oop(Z_tos);
__ push(atos); if (do_rewrite) {
patch_bytecode(Bytecodes::_fast_agetfield, bc, Z_ARG5);
} unsignedint e_off = __ offset();
}
// The registers cache and index expected to be set before call. The // function may destroy various registers, just not the cache and // index registers. void TemplateTable::jvmti_post_field_mod(Register cache, Register index, bool is_static) {
transition(vtos, vtos);
if (!JvmtiExport::can_post_field_modification()) { return;
}
BLOCK_COMMENT("jvmti_post_field_mod {");
// Check to see if a field modification watch has been set before // we take the time to call into the VM.
Label L1;
ByteSize cp_base_offset = ConstantPoolCache::base_offset();
assert_different_registers(cache, index, Z_tos);
// Index is returned as byte offset, do not shift!
__ get_cache_and_index_at_bcp(Z_ARG3, Z_R1_scratch, 1);
if (is_static) { // Life is simple. Null out the object pointer.
__ clear_reg(Z_ARG2, true, false); // Don't set CC.
} else { // Life is harder. The stack holds the value on top, followed by // the object. We don't know the size of the value, though. It // could be one or two words depending on its type. As a result, // we must find the type to determine where the object is.
__ mem2reg_opt(Z_ARG4,
Address(Z_ARG3, Z_R1_scratch,
in_bytes(cp_base_offset + ConstantPoolCacheEntry::flags_offset()) +
(BytesPerLong - BytesPerInt)), false);
__ z_srl(Z_ARG4, ConstantPoolCacheEntry::tos_state_shift); // Make sure we don't need to mask Z_ARG4 for tos_state after the above shift.
ConstantPoolCacheEntry::verify_tos_state_shift();
__ mem2reg_opt(Z_ARG2, at_tos(1)); // Initially assume a one word jvalue.
resolve_cache_and_index(byte_no, cache, index, sizeof(u2));
jvmti_post_field_mod(cache, index, is_static);
load_field_cp_cache_entry(obj, cache, index, off, flags, is_static); // begin of life for: // obj, off long life range // flags short life range, up to branch into branch table // end of life for: // cache, index
__ align_address(64);
BIND(is_badState); // Do this outside branch table. Needs a lot of space.
{ unsignedint b_off = __ offset(); if (is_static) __ stop_static("Bad state in putstatic"); else __ stop_static("Bad state in putfield"); unsignedint e_off = __ offset();
}
__ align_address(64);
BIND(atosHandler); // Oops are really complicated to handle. // There is a lot of code generated. // Therefore: generate the handler outside of branch table. // There is no performance penalty. The additional branch // to here is compensated for by the fallthru to "Done".
{ unsignedint b_off = __ offset();
__ pop(atos); if (!is_static) {
pop_and_check_object(obj);
} // Store into the field
do_oop_store(_masm, Address(obj, off), Z_tos,
oopStore_tmp1, oopStore_tmp2, oopStore_tmp3, IN_HEAP); if (do_rewrite) {
patch_bytecode(Bytecodes::_fast_aputfield, bc, Z_ARG5, true, byte_no);
} // __ z_bru(Done); // fallthru unsignedint e_off = __ offset();
}
__ pop_ptr(obj); // Copy the object pointer from tos.
__ verify_oop(obj);
__ push_ptr(obj); // Put the object pointer back on tos.
// Save tos values before call_VM() clobbers them. Since we have // to do it for every data type, we use the saved values as the // jvalue object. switch (bytecode()) { // Load values into the jvalue object. case Bytecodes::_fast_aputfield:
__ push_ptr(Z_tos); break; case Bytecodes::_fast_bputfield: case Bytecodes::_fast_zputfield: case Bytecodes::_fast_sputfield: case Bytecodes::_fast_cputfield: case Bytecodes::_fast_iputfield:
__ push_i(Z_tos); break; case Bytecodes::_fast_dputfield:
__ push_d(); break; case Bytecodes::_fast_fputfield:
__ push_f(); break; case Bytecodes::_fast_lputfield:
__ push_l(Z_tos); break;
default:
ShouldNotReachHere();
}
// jvalue on the stack
__ load_address(Z_ARG4, Address(Z_esp, Interpreter::stackElementSize)); // Access constant pool cache entry.
__ get_cache_entry_pointer_at_bcp(Z_ARG3, Z_tos, 1);
__ verify_oop(obj);
switch (bytecode()) { // Restore tos values. case Bytecodes::_fast_aputfield:
__ pop_ptr(Z_tos); break; case Bytecodes::_fast_bputfield: case Bytecodes::_fast_zputfield: case Bytecodes::_fast_sputfield: case Bytecodes::_fast_cputfield: case Bytecodes::_fast_iputfield:
__ pop_i(Z_tos); break; case Bytecodes::_fast_dputfield:
__ pop_d(Z_ftos); break; case Bytecodes::_fast_fputfield:
__ pop_f(Z_ftos); break; case Bytecodes::_fast_lputfield:
__ pop_l(Z_tos); break; default: break;
}
ByteSize base = ConstantPoolCache::base_offset();
jvmti_post_fast_field_mod();
// Access constant pool cache. Register cache = Z_tmp_1; Register index = Z_tmp_2; Register flags = Z_ARG5;
// Index comes in bytes, don't shift afterwards!
__ get_cache_and_index_at_bcp(cache, index, 1);
// Test for volatile.
assert(!flags->is_volatile(), "do_oop_store could perform leaf RT call");
__ z_lg(flags, Address(cache, index, base + ConstantPoolCacheEntry::flags_offset()));
// Replace index with field offset from cache entry. Register field_offset = index;
__ z_lg(field_offset, Address(cache, index, base + ConstantPoolCacheEntry::f2_offset()));
// Get object from stack. Register obj = cache;
pop_and_check_object(obj);
// field address const Address field(obj, field_offset);
// access field switch (bytecode()) { case Bytecodes::_fast_aputfield:
do_oop_store(_masm, Address(obj, field_offset), Z_tos,
Z_ARG2, Z_ARG3, Z_ARG4, IN_HEAP); break; case Bytecodes::_fast_lputfield:
__ reg2mem_opt(Z_tos, field); break; case Bytecodes::_fast_iputfield:
__ reg2mem_opt(Z_tos, field, false); break; case Bytecodes::_fast_zputfield:
__ z_nilf(Z_tos, 0x1); // fall through to bputfield case Bytecodes::_fast_bputfield:
__ z_stc(Z_tos, field); break; case Bytecodes::_fast_sputfield: // fall through case Bytecodes::_fast_cputfield:
__ z_sth(Z_tos, field); break; case Bytecodes::_fast_fputfield:
__ freg2mem_opt(Z_ftos, field, false); break; case Bytecodes::_fast_dputfield:
__ freg2mem_opt(Z_ftos, field); break; default:
ShouldNotReachHere();
}
// Do the JVMTI work here to avoid disturbing the register state below if (JvmtiExport::can_post_field_access()) { // Check to see if a field access watch has been set before we // take the time to call into the VM.
Label cont;
// Access constant pool cache. Register cache = Z_tmp_1; Register index = Z_tmp_2;
// Index comes in bytes, don't shift afterwards!
__ get_cache_and_index_at_bcp(cache, index, 1); // Replace index with field offset from cache entry.
__ mem2reg_opt(index,
Address(cache, index,
ConstantPoolCache::base_offset() + ConstantPoolCacheEntry::f2_offset()));
__ verify_oop(obj);
__ null_check(obj);
Address field(obj, index);
// access field switch (bytecode()) { case Bytecodes::_fast_agetfield:
do_oop_load(_masm, field, Z_tos, Z_tmp_1, Z_tmp_2, IN_HEAP);
__ verify_oop(Z_tos); return; case Bytecodes::_fast_lgetfield:
__ mem2reg_opt(Z_tos, field); return; case Bytecodes::_fast_igetfield:
__ mem2reg_opt(Z_tos, field, false); return; case Bytecodes::_fast_bgetfield:
__ z_lb(Z_tos, field); return; case Bytecodes::_fast_sgetfield:
__ z_lh(Z_tos, field); return; case Bytecodes::_fast_cgetfield:
__ z_llgh(Z_tos, field); // Load into 64 bits, works on all CPUs. return; case Bytecodes::_fast_fgetfield:
__ mem2freg_opt(Z_ftos, field, false); return; case Bytecodes::_fast_dgetfield:
__ mem2freg_opt(Z_ftos, field); return; default:
ShouldNotReachHere();
}
}
Register receiver = Z_tos; // Get receiver.
__ mem2reg_opt(Z_tos, aaddress(0));
// Access constant pool cache. Register cache = Z_tmp_1; Register index = Z_tmp_2;
// Index comes in bytes, don't shift afterwards!
__ get_cache_and_index_at_bcp(cache, index, 2); // Replace index with field offset from cache entry.
__ mem2reg_opt(index,
Address(cache, index,
ConstantPoolCache::base_offset() + ConstantPoolCacheEntry::f2_offset()));
// Make sure exception is reported in correct bcp range (getfield is // next instruction).
__ add2reg(Z_bcp, 1);
__ null_check(receiver); switch (state) { case itos:
__ mem2reg_opt(Z_tos, Address(receiver, index), false); break; case atos:
do_oop_load(_masm, Address(receiver, index), Z_tos, Z_tmp_1, Z_tmp_2, IN_HEAP);
__ verify_oop(Z_tos); break; case ftos:
__ mem2freg_opt(Z_ftos, Address(receiver, index)); break; default:
ShouldNotReachHere();
}
// Reset bcp to original position.
__ add2reg(Z_bcp, -1);
}
// Maybe push appendix to arguments. if (is_invokedynamic || is_invokehandle) {
Label L_no_push; Register resolved_reference = Z_R1_scratch;
__ testbit(flags, ConstantPoolCacheEntry::has_appendix_shift);
__ z_bfalse(L_no_push); // Push the appendix as a trailing parameter. // This must be done before we get the receiver, // since the parameter_size includes it.
__ load_resolved_reference_at_index(resolved_reference, index);
__ verify_oop(resolved_reference);
__ push_ptr(resolved_reference); // Push appendix (MethodType, CallSite, etc.).
__ bind(L_no_push);
}
// Load receiver if needed (after appendix is pushed so parameter size is correct). if (load_receiver) {
assert(!is_invokedynamic, ""); // recv := int2long(flags & ConstantPoolCacheEntry::parameter_size_mask) << 3 // Flags is zero-extended int2long when loaded during load_invoke_cp_cache_entry(). // Only the least significant byte (psize) of flags is used.
{ constunsignedint logSES = Interpreter::logStackElementSize; constint bit_shift = logSES; constint r_bitpos = 63 - bit_shift; constint l_bitpos = r_bitpos - ConstantPoolCacheEntry::parameter_size_bits + 1; constint n_rotate = bit_shift;
assert(ConstantPoolCacheEntry::parameter_size_mask == 255, "adapt bitpositions");
__ rotate_then_insert(recv, flags, l_bitpos, r_bitpos, n_rotate, true);
} // Recv now contains #arguments * StackElementSize.
// Compute return type. // ret_type is used by callers (invokespecial, invokestatic) at least. Register ret_type = Z_R1_scratch;
assert_different_registers(ret_type, method);
assert(byte_no == f1_byte, "use this argument"); Register Rmethod = Z_tmp_2;
prepare_invoke(byte_no, Rmethod); // Get f1 method. // Do the call.
__ profile_call(Z_ARG2);
__ profile_arguments_type(Z_ARG2, Rmethod, Z_ARG5, false);
__ jump_from_interpreted(Rmethod, Z_R1_scratch);
}
// Outdated feature, and we don't support it. void TemplateTable::fast_invokevfinal(int byte_no) {
transition(vtos, vtos);
assert(byte_no == f2_byte, "use this argument");
__ stop("fast_invokevfinal not used on linuxs390x");
}
prepare_invoke(byte_no, interface, method, // Get f1 klassOop, f2 Method*.
receiver, flags);
// Z_R14 (== Z_bytecode) : return entry
// First check for Object case, then private interface method, // then regular interface method.
// Special case of invokeinterface called for virtual method of // java.lang.Object. See cpCache.cpp for details.
NearLabel notObjectMethod, no_such_method;
__ testbit(flags, ConstantPoolCacheEntry::is_forced_virtual_shift);
__ z_brz(notObjectMethod);
invokevirtual_helper(method, receiver, flags);
__ bind(notObjectMethod);
// Check for private method invocation - indicated by vfinal
NearLabel notVFinal;
__ testbit(flags, ConstantPoolCacheEntry::is_vfinal_shift);
__ z_brz(notVFinal);
// Get receiver klass into klass - also a null check.
__ load_klass(klass, receiver);
NearLabel subtype, no_such_interface;
__ check_klass_subtype(klass, interface, Z_tmp_2, flags/*scratch*/, subtype); // If we get here the typecheck failed
__ z_bru(no_such_interface);
__ bind(subtype);
// do the call
__ profile_final_call(Z_tmp_2);
__ profile_arguments_type(Z_tmp_2, method, Z_ARG5, true);
__ jump_from_interpreted(method, Z_tmp_2);
__ bind(notVFinal);
// Get receiver klass into klass - also a null check.
__ load_klass(klass, receiver);
// Check for abstract method error. // Note: This should be done more efficiently via a throw_abstract_method_error // interpreter entry point and a conditional jump to it in case of a null // method.
__ compareU64_and_branch(method2, (intptr_t) 0,
Assembler::bcondZero, no_such_method);
// Do the call.
__ jump_from_interpreted(method2, Z_tmp_2);
__ should_not_reach_here();
// exception handling code follows... // Note: Must restore interpreter registers to canonical // state for exception handling to work correctly!
__ bind(no_such_method);
// Throw exception. // Pass arguments for generating a verbose error message.
__ z_lgr(Z_tmp_1, method); // Prevent register clash.
__ call_VM(noreg,
CAST_FROM_FN_PTR(address,
InterpreterRuntime::throw_AbstractMethodErrorVerbose),
klass, Z_tmp_1); // The call_VM checks for exception, so we should never return here.
__ should_not_reach_here();
__ bind(no_such_interface);
// Throw exception. // Pass arguments for generating a verbose error message.
__ call_VM(noreg,
CAST_FROM_FN_PTR(address,
InterpreterRuntime::throw_IncompatibleClassChangeErrorVerbose),
klass, interface); // The call_VM checks for exception, so we should never return here.
__ should_not_reach_here();
// Note: Callsite is already pushed by prepare_invoke.
// TODO: should make a type profile for any invokedynamic that takes a ref argument. // Profile this call.
__ profile_call(Z_ARG2);
__ profile_arguments_type(Z_ARG2, Rmethod, Z_ARG5, false);
__ jump_from_interpreted(Rmethod, Z_ARG2);
}
// Original comment on "allow_shared_alloc": // Always go the slow path. // + Eliminated optimization within the template-based interpreter: // If an allocation is done within the interpreter without using // tlabs, the interpreter tries to do the allocation directly // on the heap. // + That means the profiling hooks are not considered and allocations // get lost for the profiling framework. // + However, we do not think that this optimization is really needed, // so we always go now the slow path through the VM in this case -- // spec jbb2005 shows no measurable performance degradation. void TemplateTable::_new() {
transition(vtos, atos);
address prev_instr_address = NULL; Register tags = Z_tmp_1; Register RallocatedObject = Z_tos; Register cpool = Z_ARG2; Register tmp = Z_ARG3; // RobjectFields==tmp and Rsize==offset must be a register pair. Register offset = Z_ARG4;
Label slow_case;
Label done;
Label initialize_header;
BLOCK_COMMENT("TemplateTable::_new {");
__ get_2_byte_integer_at_bcp(offset/*dest*/, 1, InterpreterMacroAssembler::Unsigned);
__ get_cpool_and_tags(cpool, tags); // Make sure the class we're about to instantiate has been resolved. // This is done before loading InstanceKlass to be consistent with the order // how Constant Pool is updated (see ConstantPool::klass_at_put). constint tags_offset = Array<u1>::base_offset_in_bytes();
__ load_address(tmp, Address(tags, offset, tags_offset));
__ z_cli(0, tmp, JVM_CONSTANT_Class);
__ z_brne(slow_case);
__ z_sllg(offset, offset, LogBytesPerWord); // Convert to to offset. // Get InstanceKlass. Register iklass = cpool;
__ load_resolved_klass_at_offset(cpool, offset, iklass);
// Make sure klass is initialized & doesn't have finalizer. // Make sure klass is fully initialized. constint state_offset = in_bytes(InstanceKlass::init_state_offset()); if (Immediate::is_uimm12(state_offset)) {
__ z_cli(state_offset, iklass, InstanceKlass::fully_initialized);
} else {
__ z_cliy(state_offset, iklass, InstanceKlass::fully_initialized);
}
__ z_brne(slow_case);
// Get instance_size in InstanceKlass (scaled to a count of bytes). Register Rsize = offset;
__ z_llgf(Rsize, Address(iklass, Klass::layout_helper_offset()));
__ z_tmll(Rsize, Klass::_lh_instance_slow_path_bit);
__ z_btrue(slow_case);
// Allocate the instance // 1) Try to allocate in the TLAB. // 2) If the above fails (or is not applicable), go to a slow case // (creates a new TLAB, etc.). // Note: compared to other architectures, s390's implementation always goes // to the slow path if TLAB is used and fails. if (UseTLAB) { Register RoldTopValue = RallocatedObject; Register RnewTopValue = tmp;
__ z_lg(RoldTopValue, Address(Z_thread, JavaThread::tlab_top_offset()));
__ load_address(RnewTopValue, Address(RoldTopValue, Rsize));
__ z_cg(RnewTopValue, Address(Z_thread, JavaThread::tlab_end_offset()));
__ z_brh(slow_case);
__ z_stg(RnewTopValue, Address(Z_thread, JavaThread::tlab_top_offset()));
Register RobjectFields = tmp; Register Rzero = Z_R1_scratch;
__ clear_reg(Rzero, true/*whole reg*/, false); // Load 0L into Rzero. Don't set CC.
if (!ZeroTLAB) { // The object is initialized before the header. If the object size is // zero, go directly to the header initialization.
__ z_aghi(Rsize, (int)-sizeof(oopDesc)); // Subtract header size, set CC.
__ z_bre(initialize_header); // Jump if size of fields is zero.
// Initialize object fields. // See documentation for MVCLE instruction!!!
assert(RobjectFields->encoding() % 2 == 0, "RobjectFields must be an even register");
assert(Rsize->encoding() == (RobjectFields->encoding()+1), "RobjectFields and Rsize must be a register pair");
assert(Rzero->encoding() % 2 == 1, "Rzero must be an odd register");
// Set Rzero to 0 and use it as src length, then mvcle will copy nothing // and fill the object with the padding value 0.
__ add2reg(RobjectFields, sizeof(oopDesc), RallocatedObject);
__ move_long_ext(RobjectFields, as_Register(Rzero->encoding() - 1), 0);
}
BLOCK_COMMENT("checkcast {"); // If object is NULL, we are almost done.
__ compareU64_and_branch(Z_tos, (intptr_t) 0, Assembler::bcondZero, is_null);
// Get cpool & tags index. Register cpool = Z_tmp_1; Register tags = Z_tmp_2; Register index = Z_ARG5;
__ get_cpool_and_tags(cpool, tags);
__ get_2_byte_integer_at_bcp(index, 1, InterpreterMacroAssembler::Unsigned); // See if bytecode has already been quicked. // Note: For CLI, we would have to add the index to the tags pointer first, // thus load and compare in a "classic" manner.
__ z_llgc(Z_R0_scratch,
Address(tags, index, Array<u1>::base_offset_in_bytes()));
__ compareU64_and_branch(Z_R0_scratch, JVM_CONSTANT_Class,
Assembler::bcondEqual, quicked);
__ push(atos); // Save receiver for result, and for GC.
call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::quicken_io_cc));
__ get_vm_result_2(Z_tos);
// Get superklass in klass and subklass in subklass.
__ bind(quicked);
__ z_lgr(Z_ARG4, Z_tos); // Save receiver.
__ z_sllg(index, index, LogBytesPerWord); // index2bytes for addressing
__ load_resolved_klass_at_offset(cpool, index, klass);
__ bind(resolved);
__ load_klass(subklass, receiver);
// Generate subtype check. Object in receiver. // Superklass in klass. Subklass in subklass.
__ gen_subtype_check(subklass, klass, Z_ARG3, Z_tmp_1, ok_is_subtype);
// Come here on failure.
__ push_ptr(receiver); // Object is at TOS, target klass oop expected in rax by convention.
__ z_brul((address) Interpreter::_throw_ClassCastException_entry);
// Come here on success.
__ bind(ok_is_subtype);
__ z_lgr(Z_tos, receiver); // Restore object.
// Collect counts on whether this test sees NULLs a lot or not. if (ProfileInterpreter) {
__ z_bru(done);
__ bind(is_null);
__ profile_null_seen(Z_tmp_1);
} else {
__ bind(is_null); // Same as 'done'.
}
BLOCK_COMMENT("instanceof {"); // If object is NULL, we are almost done.
__ compareU64_and_branch(Z_tos, (intptr_t) 0, Assembler::bcondZero, is_null);
// Get cpool & tags index. Register cpool = Z_tmp_1; Register tags = Z_tmp_2; Register index = Z_ARG5;
__ get_cpool_and_tags(cpool, tags);
__ get_2_byte_integer_at_bcp(index, 1, InterpreterMacroAssembler::Unsigned); // See if bytecode has already been quicked. // Note: For CLI, we would have to add the index to the tags pointer first, // thus load and compare in a "classic" manner.
__ z_llgc(Z_R0_scratch,
Address(tags, index, Array<u1>::base_offset_in_bytes()));
__ compareU64_and_branch(Z_R0_scratch, JVM_CONSTANT_Class, Assembler::bcondEqual, quicked);
__ push(atos); // Save receiver for result, and for GC.
call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::quicken_io_cc));
__ get_vm_result_2(Z_tos);
// Generate subtype check. // Superklass in klass. Subklass in subklass.
__ gen_subtype_check(subklass, klass, Z_ARG4, Z_ARG5, ok_is_subtype);
// Come here on failure.
__ clear_reg(Z_tos, true, false);
__ z_bru(done);
// Come here on success.
__ bind(ok_is_subtype);
__ load_const_optimized(Z_tos, 1);
// Collect counts on whether this test sees NULLs a lot or not. if (ProfileInterpreter) {
__ z_bru(done);
__ bind(is_null);
__ profile_null_seen(Z_tmp_1);
} else {
__ bind(is_null); // same as 'done'
}
__ bind(done); // tos = 0: obj == NULL or obj is not an instanceof the specified klass // tos = 1: obj != NULL and obj is an instanceof the specified klass
BLOCK_COMMENT("} instanceof");
}
// Note: We get here even if we are single stepping. // Jbug insists on setting breakpoints at every bytecode // even if we are in single step mode.
transition(vtos, vtos);
// Get the unpatched byte code.
__ get_method(Z_ARG2);
__ call_VM(noreg,
CAST_FROM_FN_PTR(address, InterpreterRuntime::get_original_bytecode_at),
Z_ARG2, Z_bcp); // Save the result to a register that is preserved over C-function calls.
__ z_lgr(Z_tmp_1, Z_RET);
// Post the breakpoint event.
__ get_method(Z_ARG2);
__ call_VM(noreg,
CAST_FROM_FN_PTR(address, InterpreterRuntime::_breakpoint),
Z_ARG2, Z_bcp);
// Must restore the bytecode, because call_VM destroys Z_bytecode.
__ z_lgr(Z_bytecode, Z_tmp_1);
// Complete the execution of original bytecode.
__ dispatch_only_normal(vtos);
}
// Synchronization // // Note: monitorenter & exit are symmetric routines; which is reflected // in the assembly code structure as well // // Stack layout: // // callers_sp <- Z_SP (callers_sp == Z_fp (own fp)) // return_pc // [rest of ABI_160] // /slot o: free // / ... free // oper. | slot n+1: free <- Z_esp points to first free slot // stack | slot n: val caches IJAVA_STATE.esp // | ... // \slot 0: val // /slot m <- IJAVA_STATE.monitors = monitor block top // | ... // monitors| slot 2 // | slot 1 // \slot 0 // /slot l <- monitor block bot // ijava_state | ... // | slot 2 // \slot 0 // <- Z_fp void TemplateTable::monitorenter() {
transition(atos, vtos);
BLOCK_COMMENT("monitorenter {");
// Check for NULL object.
__ null_check(Z_tos); constint entry_size = frame::interpreter_frame_monitor_size() * wordSize;
NearLabel allocated; // Initialize entry pointer. constRegister Rfree_slot = Z_tmp_1;
__ clear_reg(Rfree_slot, true, false); // Points to free slot or NULL. Don't set CC.
// Find a free slot in the monitor block from top to bot (result in Rfree_slot).
{ constRegister Rcurr_monitor = Z_ARG2; constRegister Rbot = Z_ARG3; // Points to word under bottom of monitor block. constRegister Rlocked_obj = Z_ARG4;
NearLabel loop, exit, not_free; // Starting with top-most entry.
__ get_monitors(Rcurr_monitor); // Rcur_monitor = IJAVA_STATE.monitors
__ add2reg(Rbot, -frame::z_ijava_state_size, Z_fp);
// Check if bottom reached, i.e. if there is at least one monitor.
__ compareU64_and_branch(Rcurr_monitor, Rbot, Assembler::bcondEqual, exit);
__ bind(loop); // Check if current entry is used.
__ load_and_test_long(Rlocked_obj, Address(Rcurr_monitor, BasicObjectLock::obj_offset_in_bytes()));
__ z_brne(not_free); // If not used then remember entry in Rfree_slot.
__ z_lgr(Rfree_slot, Rcurr_monitor);
__ bind(not_free); // Exit if current entry is for same object; this guarantees, that new monitor // used for recursive lock is above the older one.
__ compareU64_and_branch(Rlocked_obj, Z_tos, Assembler::bcondEqual, exit); // otherwise advance to next entry
__ add2reg(Rcurr_monitor, entry_size); // Check if bottom reached, if not at bottom then check this entry.
__ compareU64_and_branch(Rcurr_monitor, Rbot, Assembler::bcondNotEqual, loop);
__ bind(exit);
}
// Rfree_slot != NULL -> found one
__ compareU64_and_branch(Rfree_slot, (intptr_t)0L, Assembler::bcondNotEqual, allocated);
// Allocate one if there's no free slot.
__ add_monitor_to_stack(false, Z_ARG3, Z_ARG4, Z_ARG5);
__ get_monitors(Rfree_slot);
// Rfree_slot: points to monitor entry.
__ bind(allocated);
// Increment bcp to point to the next bytecode, so exception // handling for async. exceptions work correctly. // The object has already been popped from the stack, so the // expression stack looks correct.
__ add2reg(Z_bcp, 1, Z_bcp);
// Store object.
__ z_stg(Z_tos, BasicObjectLock::obj_offset_in_bytes(), Rfree_slot);
__ lock_object(Rfree_slot, Z_tos);
// Check to make sure this monitor doesn't cause stack overflow after locking.
__ save_bcp(); // in case of exception
__ generate_stack_overflow_check(0);
// The bcp has already been incremented. Just need to dispatch to // next instruction.
__ dispatch_next(vtos);
// Check if bottom reached, i.e. if there is at least one monitor.
__ compareU64_and_branch(Rcurr_monitor, Rbot, Assembler::bcondEqual, not_found);
__ bind(loop); // Check if current entry is for same object.
__ z_lg(Rlocked_obj, Address(Rcurr_monitor, BasicObjectLock::obj_offset_in_bytes())); // If same object then stop searching.
__ compareU64_and_branch(Rlocked_obj, Z_tos, Assembler::bcondEqual, found); // Otherwise advance to next entry.
__ add2reg(Rcurr_monitor, entry_size); // Check if bottom reached, if not at bottom then check this entry.
__ compareU64_and_branch(Rcurr_monitor, Rbot, Assembler::bcondNotEqual, loop);
}
__ bind(not_found); // Error handling. Unlocking was not block-structured.
__ call_VM(noreg, CAST_FROM_FN_PTR(address,
InterpreterRuntime::throw_illegal_monitor_state_exception));
__ should_not_reach_here();
__ bind(found);
__ push_ptr(Z_tos); // Make sure object is on stack (contract with oopMaps).
__ unlock_object(Rcurr_monitor, Z_tos);
__ pop_ptr(Z_tos); // Discard object.
BLOCK_COMMENT("} monitorexit");
}
__ z_llgc(Z_R1_scratch, at_bcp(1));
__ z_sllg(Z_R1_scratch, Z_R1_scratch, LogBytesPerWord);
__ load_absolute_address(Z_tmp_1, (address) Interpreter::_wentry_point);
__ mem2reg_opt(Z_tmp_1, Address(Z_tmp_1, Z_R1_scratch));
__ z_br(Z_tmp_1); // Note: the bcp increment step is part of the individual wide // bytecode implementations.
}
// Multi arrays void TemplateTable::multianewarray() {
transition(vtos, atos);
__ z_llgc(Z_tmp_1, at_bcp(3)); // Get number of dimensions. // Slot count to byte offset.
__ z_sllg(Z_tmp_1, Z_tmp_1, Interpreter::logStackElementSize); // Z_esp points past last_dim, so set to Z_ARG2 to first_dim address.
__ load_address(Z_ARG2, Address(Z_esp, Z_tmp_1));
call_VM(Z_RET,
CAST_FROM_FN_PTR(address, InterpreterRuntime::multianewarray),
Z_ARG2); // Pop dimensions from expression stack.
__ z_agr(Z_esp, Z_tmp_1);
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.61 Sekunden
(vorverarbeitet am 2026-04-27)
¤
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.