Path: blob/master/src/hotspot/cpu/s390/interp_masm_s390.cpp
40930 views
/*1* Copyright (c) 2016, 2021, Oracle and/or its affiliates. All rights reserved.2* Copyright (c) 2016, 2020 SAP SE. All rights reserved.3* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.4*5* This code is free software; you can redistribute it and/or modify it6* under the terms of the GNU General Public License version 2 only, as7* published by the Free Software Foundation.8*9* This code is distributed in the hope that it will be useful, but WITHOUT10* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or11* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License12* version 2 for more details (a copy is included in the LICENSE file that13* accompanied this code).14*15* You should have received a copy of the GNU General Public License version16* 2 along with this work; if not, write to the Free Software Foundation,17* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.18*19* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA20* or visit www.oracle.com if you need additional information or have any21* questions.22*23*/2425// Major contributions by AHa, AS, JL, ML.2627#include "precompiled.hpp"28#include "asm/macroAssembler.inline.hpp"29#include "gc/shared/barrierSet.hpp"30#include "gc/shared/barrierSetAssembler.hpp"31#include "interp_masm_s390.hpp"32#include "interpreter/interpreter.hpp"33#include "interpreter/interpreterRuntime.hpp"34#include "oops/arrayOop.hpp"35#include "oops/markWord.hpp"36#include "oops/methodData.hpp"37#include "prims/jvmtiExport.hpp"38#include "prims/jvmtiThreadState.hpp"39#include "runtime/basicLock.hpp"40#include "runtime/biasedLocking.hpp"41#include "runtime/frame.inline.hpp"42#include "runtime/safepointMechanism.hpp"43#include "runtime/sharedRuntime.hpp"44#include "runtime/thread.inline.hpp"45#include "utilities/powerOfTwo.hpp"4647// Implementation of InterpreterMacroAssembler.48// This file specializes the assembler with interpreter-specific macros.4950#ifdef PRODUCT51#define BLOCK_COMMENT(str)52#define BIND(label) bind(label);53#else54#define BLOCK_COMMENT(str) block_comment(str)55#define BIND(label) bind(label); BLOCK_COMMENT(#label ":")56#endif5758void InterpreterMacroAssembler::jump_to_entry(address entry, Register Rscratch) {59assert(entry != NULL, "Entry must have been generated by now");60assert(Rscratch != Z_R0, "Can't use R0 for addressing");61branch_optimized(Assembler::bcondAlways, entry);62}6364void InterpreterMacroAssembler::empty_expression_stack(void) {65get_monitors(Z_R1_scratch);66add2reg(Z_esp, -Interpreter::stackElementSize, Z_R1_scratch);67}6869// Dispatch code executed in the prolog of a bytecode which does not do it's70// own dispatch.71void InterpreterMacroAssembler::dispatch_prolog(TosState state, int bcp_incr) {72// On z/Architecture we are short on registers, therefore we do not preload the73// dispatch address of the next bytecode.74}7576// Dispatch code executed in the epilog of a bytecode which does not do it's77// own dispatch.78void InterpreterMacroAssembler::dispatch_epilog(TosState state, int step) {79dispatch_next(state, step);80}8182void InterpreterMacroAssembler::dispatch_next(TosState state, int bcp_incr, bool generate_poll) {83z_llgc(Z_bytecode, bcp_incr, Z_R0, Z_bcp); // Load next bytecode.84add2reg(Z_bcp, bcp_incr); // Advance bcp. Add2reg produces optimal code.85dispatch_base(state, Interpreter::dispatch_table(state), generate_poll);86}8788// Common code to dispatch and dispatch_only.89// Dispatch value in Lbyte_code and increment Lbcp.9091void InterpreterMacroAssembler::dispatch_base(TosState state, address* table, bool generate_poll) {92verify_FPU(1, state);9394#ifdef ASSERT95address reentry = NULL;96{ Label OK;97// Check if the frame pointer in Z_fp is correct.98z_cg(Z_fp, 0, Z_SP);99z_bre(OK);100reentry = stop_chain_static(reentry, "invalid frame pointer Z_fp: " FILE_AND_LINE);101bind(OK);102}103{ Label OK;104// check if the locals pointer in Z_locals is correct105z_cg(Z_locals, _z_ijava_state_neg(locals), Z_fp);106z_bre(OK);107reentry = stop_chain_static(reentry, "invalid locals pointer Z_locals: " FILE_AND_LINE);108bind(OK);109}110#endif111112// TODO: Maybe implement +VerifyActivationFrameSize here.113// verify_thread(); // Too slow. We will just verify on method entry & exit.114verify_oop(Z_tos, state);115116// Dispatch table to use.117load_absolute_address(Z_tmp_1, (address)table); // Z_tmp_1 = table;118119if (generate_poll) {120address *sfpt_tbl = Interpreter::safept_table(state);121if (table != sfpt_tbl) {122Label dispatch;123const Address poll_byte_addr(Z_thread, in_bytes(JavaThread::polling_word_offset()) + 7 /* Big Endian */);124// Armed page has poll_bit set, if poll bit is cleared just continue.125z_tm(poll_byte_addr, SafepointMechanism::poll_bit());126z_braz(dispatch);127load_absolute_address(Z_tmp_1, (address)sfpt_tbl); // Z_tmp_1 = table;128bind(dispatch);129}130}131132// 0 <= Z_bytecode < 256 => Use a 32 bit shift, because it is shorter than sllg.133// Z_bytecode must have been loaded zero-extended for this approach to be correct.134z_sll(Z_bytecode, LogBytesPerWord, Z_R0); // Multiply by wordSize.135z_lg(Z_tmp_1, 0, Z_bytecode, Z_tmp_1); // Get entry addr.136137z_br(Z_tmp_1);138}139140void InterpreterMacroAssembler::dispatch_only(TosState state, bool generate_poll) {141dispatch_base(state, Interpreter::dispatch_table(state), generate_poll);142}143144void InterpreterMacroAssembler::dispatch_only_normal(TosState state) {145dispatch_base(state, Interpreter::normal_table(state));146}147148void InterpreterMacroAssembler::dispatch_via(TosState state, address *table) {149// Load current bytecode.150z_llgc(Z_bytecode, Address(Z_bcp, (intptr_t)0));151dispatch_base(state, table);152}153154// The following call_VM*_base() methods overload and mask the respective155// declarations/definitions in class MacroAssembler. They are meant as a "detour"156// to perform additional, template interpreter specific tasks before actually157// calling their MacroAssembler counterparts.158159void InterpreterMacroAssembler::call_VM_leaf_base(address entry_point) {160bool allow_relocation = true; // Fenerally valid variant. Assume code is relocated.161// interpreter specific162// Note: No need to save/restore bcp (Z_R13) pointer since these are callee163// saved registers and no blocking/ GC can happen in leaf calls.164165// super call166MacroAssembler::call_VM_leaf_base(entry_point, allow_relocation);167}168169void InterpreterMacroAssembler::call_VM_leaf_base(address entry_point, bool allow_relocation) {170// interpreter specific171// Note: No need to save/restore bcp (Z_R13) pointer since these are callee172// saved registers and no blocking/ GC can happen in leaf calls.173174// super call175MacroAssembler::call_VM_leaf_base(entry_point, allow_relocation);176}177178void InterpreterMacroAssembler::call_VM_base(Register oop_result, Register last_java_sp,179address entry_point, bool check_exceptions) {180bool allow_relocation = true; // Fenerally valid variant. Assume code is relocated.181// interpreter specific182183save_bcp();184save_esp();185// super call186MacroAssembler::call_VM_base(oop_result, last_java_sp,187entry_point, allow_relocation, check_exceptions);188restore_bcp();189}190191void InterpreterMacroAssembler::call_VM_base(Register oop_result, Register last_java_sp,192address entry_point, bool allow_relocation,193bool check_exceptions) {194// interpreter specific195196save_bcp();197save_esp();198// super call199MacroAssembler::call_VM_base(oop_result, last_java_sp,200entry_point, allow_relocation, check_exceptions);201restore_bcp();202}203204void InterpreterMacroAssembler::check_and_handle_popframe(Register scratch_reg) {205if (JvmtiExport::can_pop_frame()) {206BLOCK_COMMENT("check_and_handle_popframe {");207Label L;208// Initiate popframe handling only if it is not already being209// processed. If the flag has the popframe_processing bit set, it210// means that this code is called *during* popframe handling - we211// don't want to reenter.212// TODO: Check if all four state combinations could be visible.213// If (processing and !pending) is an invisible/impossible state,214// there is optimization potential by testing both bits at once.215// Then, All_Zeroes and All_Ones means skip, Mixed means doit.216testbit(Address(Z_thread, JavaThread::popframe_condition_offset()),217exact_log2(JavaThread::popframe_pending_bit));218z_bfalse(L);219testbit(Address(Z_thread, JavaThread::popframe_condition_offset()),220exact_log2(JavaThread::popframe_processing_bit));221z_btrue(L);222223// Call Interpreter::remove_activation_preserving_args_entry() to get the224// address of the same-named entrypoint in the generated interpreter code.225call_VM_leaf(CAST_FROM_FN_PTR(address, Interpreter::remove_activation_preserving_args_entry));226// The above call should (as its only effect) return the contents of the field227// _remove_activation_preserving_args_entry in Z_RET.228// We just jump there to have the work done.229z_br(Z_RET);230// There is no way for control to fall thru here.231232bind(L);233BLOCK_COMMENT("} check_and_handle_popframe");234}235}236237238void InterpreterMacroAssembler::load_earlyret_value(TosState state) {239Register RjvmtiState = Z_R1_scratch;240int tos_off = in_bytes(JvmtiThreadState::earlyret_tos_offset());241int oop_off = in_bytes(JvmtiThreadState::earlyret_oop_offset());242int val_off = in_bytes(JvmtiThreadState::earlyret_value_offset());243int state_off = in_bytes(JavaThread::jvmti_thread_state_offset());244245z_lg(RjvmtiState, state_off, Z_thread);246247switch (state) {248case atos: z_lg(Z_tos, oop_off, RjvmtiState);249store_const(Address(RjvmtiState, oop_off), 0L, 8, 8, Z_R0_scratch);250break;251case ltos: z_lg(Z_tos, val_off, RjvmtiState); break;252case btos: // fall through253case ztos: // fall through254case ctos: // fall through255case stos: // fall through256case itos: z_llgf(Z_tos, val_off, RjvmtiState); break;257case ftos: z_le(Z_ftos, val_off, RjvmtiState); break;258case dtos: z_ld(Z_ftos, val_off, RjvmtiState); break;259case vtos: /* nothing to do */ break;260default : ShouldNotReachHere();261}262263// Clean up tos value in the jvmti thread state.264store_const(Address(RjvmtiState, val_off), 0L, 8, 8, Z_R0_scratch);265// Set tos state field to illegal value.266store_const(Address(RjvmtiState, tos_off), ilgl, 4, 1, Z_R0_scratch);267}268269void InterpreterMacroAssembler::check_and_handle_earlyret(Register scratch_reg) {270if (JvmtiExport::can_force_early_return()) {271BLOCK_COMMENT("check_and_handle_earlyret {");272Label L;273// arg regs are save, because we are just behind the call in call_VM_base274Register jvmti_thread_state = Z_ARG2;275Register tmp = Z_ARG3;276load_and_test_long(jvmti_thread_state, Address(Z_thread, JavaThread::jvmti_thread_state_offset()));277z_bre(L); // if (thread->jvmti_thread_state() == NULL) exit;278279// Initiate earlyret handling only if it is not already being processed.280// If the flag has the earlyret_processing bit set, it means that this code281// is called *during* earlyret handling - we don't want to reenter.282283assert((JvmtiThreadState::earlyret_pending != 0) && (JvmtiThreadState::earlyret_inactive == 0),284"must fix this check, when changing the values of the earlyret enum");285assert(JvmtiThreadState::earlyret_pending == 1, "must fix this check, when changing the values of the earlyret enum");286287load_and_test_int(tmp, Address(jvmti_thread_state, JvmtiThreadState::earlyret_state_offset()));288z_brz(L); // if (thread->jvmti_thread_state()->_earlyret_state != JvmtiThreadState::earlyret_pending) exit;289290// Call Interpreter::remove_activation_early_entry() to get the address of the291// same-named entrypoint in the generated interpreter code.292assert(sizeof(TosState) == 4, "unexpected size");293z_l(Z_ARG1, Address(jvmti_thread_state, JvmtiThreadState::earlyret_tos_offset()));294call_VM_leaf(CAST_FROM_FN_PTR(address, Interpreter::remove_activation_early_entry), Z_ARG1);295// The above call should (as its only effect) return the contents of the field296// _remove_activation_preserving_args_entry in Z_RET.297// We just jump there to have the work done.298z_br(Z_RET);299// There is no way for control to fall thru here.300301bind(L);302BLOCK_COMMENT("} check_and_handle_earlyret");303}304}305306void InterpreterMacroAssembler::super_call_VM_leaf(address entry_point, Register arg_1, Register arg_2) {307lgr_if_needed(Z_ARG1, arg_1);308assert(arg_2 != Z_ARG1, "smashed argument");309lgr_if_needed(Z_ARG2, arg_2);310MacroAssembler::call_VM_leaf_base(entry_point, true);311}312313void InterpreterMacroAssembler::get_cache_index_at_bcp(Register index, int bcp_offset, size_t index_size) {314Address param(Z_bcp, bcp_offset);315316BLOCK_COMMENT("get_cache_index_at_bcp {");317assert(bcp_offset > 0, "bcp is still pointing to start of bytecode");318if (index_size == sizeof(u2)) {319load_sized_value(index, param, 2, false /*signed*/);320} else if (index_size == sizeof(u4)) {321322load_sized_value(index, param, 4, false);323324// Check if the secondary index definition is still ~x, otherwise325// we have to change the following assembler code to calculate the326// plain index.327assert(ConstantPool::decode_invokedynamic_index(~123) == 123, "else change next line");328not_(index); // Convert to plain index.329} else if (index_size == sizeof(u1)) {330z_llgc(index, param);331} else {332ShouldNotReachHere();333}334BLOCK_COMMENT("}");335}336337338void InterpreterMacroAssembler::get_cache_and_index_at_bcp(Register cache, Register cpe_offset,339int bcp_offset, size_t index_size) {340BLOCK_COMMENT("get_cache_and_index_at_bcp {");341assert_different_registers(cache, cpe_offset);342get_cache_index_at_bcp(cpe_offset, bcp_offset, index_size);343z_lg(cache, Address(Z_fp, _z_ijava_state_neg(cpoolCache)));344// Convert from field index to ConstantPoolCache offset in bytes.345z_sllg(cpe_offset, cpe_offset, exact_log2(in_words(ConstantPoolCacheEntry::size()) * BytesPerWord));346BLOCK_COMMENT("}");347}348349// Kills Z_R0_scratch.350void InterpreterMacroAssembler::get_cache_and_index_and_bytecode_at_bcp(Register cache,351Register cpe_offset,352Register bytecode,353int byte_no,354int bcp_offset,355size_t index_size) {356BLOCK_COMMENT("get_cache_and_index_and_bytecode_at_bcp {");357get_cache_and_index_at_bcp(cache, cpe_offset, bcp_offset, index_size);358359// We want to load (from CP cache) the bytecode that corresponds to the passed-in byte_no.360// It is located at (cache + cpe_offset + base_offset + indices_offset + (8-1) (last byte in DW) - (byte_no+1).361// Instead of loading, shifting and masking a DW, we just load that one byte of interest with z_llgc (unsigned).362const int base_ix_off = in_bytes(ConstantPoolCache::base_offset() + ConstantPoolCacheEntry::indices_offset());363const int off_in_DW = (8-1) - (1+byte_no);364assert(ConstantPoolCacheEntry::bytecode_1_mask == ConstantPoolCacheEntry::bytecode_2_mask, "common mask");365assert(ConstantPoolCacheEntry::bytecode_1_mask == 0xff, "");366load_sized_value(bytecode, Address(cache, cpe_offset, base_ix_off+off_in_DW), 1, false /*signed*/);367368BLOCK_COMMENT("}");369}370371// Load object from cpool->resolved_references(index).372void InterpreterMacroAssembler::load_resolved_reference_at_index(Register result, Register index) {373assert_different_registers(result, index);374get_constant_pool(result);375376// Convert377// - from field index to resolved_references() index and378// - from word index to byte offset.379// Since this is a java object, it is potentially compressed.380Register tmp = index; // reuse381z_sllg(index, index, LogBytesPerHeapOop); // Offset into resolved references array.382// Load pointer for resolved_references[] objArray.383z_lg(result, ConstantPool::cache_offset_in_bytes(), result);384z_lg(result, ConstantPoolCache::resolved_references_offset_in_bytes(), result);385resolve_oop_handle(result); // Load resolved references array itself.386#ifdef ASSERT387NearLabel index_ok;388z_lgf(Z_R0, Address(result, arrayOopDesc::length_offset_in_bytes()));389z_sllg(Z_R0, Z_R0, LogBytesPerHeapOop);390compare64_and_branch(tmp, Z_R0, Assembler::bcondLow, index_ok);391stop("resolved reference index out of bounds", 0x09256);392bind(index_ok);393#endif394z_agr(result, index); // Address of indexed array element.395load_heap_oop(result, Address(result, arrayOopDesc::base_offset_in_bytes(T_OBJECT)), tmp, noreg);396}397398// load cpool->resolved_klass_at(index)399void InterpreterMacroAssembler::load_resolved_klass_at_offset(Register cpool, Register offset, Register iklass) {400// int value = *(Rcpool->int_at_addr(which));401// int resolved_klass_index = extract_low_short_from_int(value);402z_llgh(offset, Address(cpool, offset, sizeof(ConstantPool) + 2)); // offset = resolved_klass_index (s390 is big-endian)403z_sllg(offset, offset, LogBytesPerWord); // Convert 'index' to 'offset'404z_lg(iklass, Address(cpool, ConstantPool::resolved_klasses_offset_in_bytes())); // iklass = cpool->_resolved_klasses405z_lg(iklass, Address(iklass, offset, Array<Klass*>::base_offset_in_bytes()));406}407408void InterpreterMacroAssembler::get_cache_entry_pointer_at_bcp(Register cache,409Register tmp,410int bcp_offset,411size_t index_size) {412BLOCK_COMMENT("get_cache_entry_pointer_at_bcp {");413get_cache_and_index_at_bcp(cache, tmp, bcp_offset, index_size);414add2reg_with_index(cache, in_bytes(ConstantPoolCache::base_offset()), tmp, cache);415BLOCK_COMMENT("}");416}417418void InterpreterMacroAssembler::load_resolved_method_at_index(int byte_no,419Register cache,420Register cpe_offset,421Register method) {422const int method_offset = in_bytes(423ConstantPoolCache::base_offset() +424((byte_no == TemplateTable::f2_byte)425? ConstantPoolCacheEntry::f2_offset()426: ConstantPoolCacheEntry::f1_offset()));427428z_lg(method, Address(cache, cpe_offset, method_offset)); // get f1 Method*429}430431// Generate a subtype check: branch to ok_is_subtype if sub_klass is432// a subtype of super_klass. Blows registers Rsuper_klass, Rsub_klass, tmp1, tmp2.433void InterpreterMacroAssembler::gen_subtype_check(Register Rsub_klass,434Register Rsuper_klass,435Register Rtmp1,436Register Rtmp2,437Label &ok_is_subtype) {438// Profile the not-null value's klass.439profile_typecheck(Rtmp1, Rsub_klass, Rtmp2);440441// Do the check.442check_klass_subtype(Rsub_klass, Rsuper_klass, Rtmp1, Rtmp2, ok_is_subtype);443444// Profile the failure of the check.445profile_typecheck_failed(Rtmp1, Rtmp2);446}447448// Pop topmost element from stack. It just disappears.449// Useful if consumed previously by access via stackTop().450void InterpreterMacroAssembler::popx(int len) {451add2reg(Z_esp, len*Interpreter::stackElementSize);452debug_only(verify_esp(Z_esp, Z_R1_scratch));453}454455// Get Address object of stack top. No checks. No pop.456// Purpose: - Provide address of stack operand to exploit reg-mem operations.457// - Avoid RISC-like mem2reg - reg-reg-op sequence.458Address InterpreterMacroAssembler::stackTop() {459return Address(Z_esp, Interpreter::expr_offset_in_bytes(0));460}461462void InterpreterMacroAssembler::pop_i(Register r) {463z_l(r, Interpreter::expr_offset_in_bytes(0), Z_esp);464add2reg(Z_esp, Interpreter::stackElementSize);465assert_different_registers(r, Z_R1_scratch);466debug_only(verify_esp(Z_esp, Z_R1_scratch));467}468469void InterpreterMacroAssembler::pop_ptr(Register r) {470z_lg(r, Interpreter::expr_offset_in_bytes(0), Z_esp);471add2reg(Z_esp, Interpreter::stackElementSize);472assert_different_registers(r, Z_R1_scratch);473debug_only(verify_esp(Z_esp, Z_R1_scratch));474}475476void InterpreterMacroAssembler::pop_l(Register r) {477z_lg(r, Interpreter::expr_offset_in_bytes(0), Z_esp);478add2reg(Z_esp, 2*Interpreter::stackElementSize);479assert_different_registers(r, Z_R1_scratch);480debug_only(verify_esp(Z_esp, Z_R1_scratch));481}482483void InterpreterMacroAssembler::pop_f(FloatRegister f) {484mem2freg_opt(f, Address(Z_esp, Interpreter::expr_offset_in_bytes(0)), false);485add2reg(Z_esp, Interpreter::stackElementSize);486debug_only(verify_esp(Z_esp, Z_R1_scratch));487}488489void InterpreterMacroAssembler::pop_d(FloatRegister f) {490mem2freg_opt(f, Address(Z_esp, Interpreter::expr_offset_in_bytes(0)), true);491add2reg(Z_esp, 2*Interpreter::stackElementSize);492debug_only(verify_esp(Z_esp, Z_R1_scratch));493}494495void InterpreterMacroAssembler::push_i(Register r) {496assert_different_registers(r, Z_R1_scratch);497debug_only(verify_esp(Z_esp, Z_R1_scratch));498z_st(r, Address(Z_esp));499add2reg(Z_esp, -Interpreter::stackElementSize);500}501502void InterpreterMacroAssembler::push_ptr(Register r) {503z_stg(r, Address(Z_esp));504add2reg(Z_esp, -Interpreter::stackElementSize);505}506507void InterpreterMacroAssembler::push_l(Register r) {508assert_different_registers(r, Z_R1_scratch);509debug_only(verify_esp(Z_esp, Z_R1_scratch));510int offset = -Interpreter::stackElementSize;511z_stg(r, Address(Z_esp, offset));512clear_mem(Address(Z_esp), Interpreter::stackElementSize);513add2reg(Z_esp, 2 * offset);514}515516void InterpreterMacroAssembler::push_f(FloatRegister f) {517debug_only(verify_esp(Z_esp, Z_R1_scratch));518freg2mem_opt(f, Address(Z_esp), false);519add2reg(Z_esp, -Interpreter::stackElementSize);520}521522void InterpreterMacroAssembler::push_d(FloatRegister d) {523debug_only(verify_esp(Z_esp, Z_R1_scratch));524int offset = -Interpreter::stackElementSize;525freg2mem_opt(d, Address(Z_esp, offset));526add2reg(Z_esp, 2 * offset);527}528529void InterpreterMacroAssembler::push(TosState state) {530verify_oop(Z_tos, state);531switch (state) {532case atos: push_ptr(); break;533case btos: push_i(); break;534case ztos:535case ctos:536case stos: push_i(); break;537case itos: push_i(); break;538case ltos: push_l(); break;539case ftos: push_f(); break;540case dtos: push_d(); break;541case vtos: /* nothing to do */ break;542default : ShouldNotReachHere();543}544}545546void InterpreterMacroAssembler::pop(TosState state) {547switch (state) {548case atos: pop_ptr(Z_tos); break;549case btos: pop_i(Z_tos); break;550case ztos:551case ctos:552case stos: pop_i(Z_tos); break;553case itos: pop_i(Z_tos); break;554case ltos: pop_l(Z_tos); break;555case ftos: pop_f(Z_ftos); break;556case dtos: pop_d(Z_ftos); break;557case vtos: /* nothing to do */ break;558default : ShouldNotReachHere();559}560verify_oop(Z_tos, state);561}562563// Helpers for swap and dup.564void InterpreterMacroAssembler::load_ptr(int n, Register val) {565z_lg(val, Address(Z_esp, Interpreter::expr_offset_in_bytes(n)));566}567568void InterpreterMacroAssembler::store_ptr(int n, Register val) {569z_stg(val, Address(Z_esp, Interpreter::expr_offset_in_bytes(n)));570}571572void InterpreterMacroAssembler::prepare_to_jump_from_interpreted(Register method) {573// Satisfy interpreter calling convention (see generate_normal_entry()).574z_lgr(Z_R10, Z_SP); // Set sender sp (aka initial caller sp, aka unextended sp).575// Record top_frame_sp, because the callee might modify it, if it's compiled.576z_stg(Z_SP, _z_ijava_state_neg(top_frame_sp), Z_fp);577save_bcp();578save_esp();579z_lgr(Z_method, method); // Set Z_method (kills Z_fp!).580}581582// Jump to from_interpreted entry of a call unless single stepping is possible583// in this thread in which case we must call the i2i entry.584void InterpreterMacroAssembler::jump_from_interpreted(Register method, Register temp) {585assert_different_registers(method, Z_R10 /*used for initial_caller_sp*/, temp);586prepare_to_jump_from_interpreted(method);587588if (JvmtiExport::can_post_interpreter_events()) {589// JVMTI events, such as single-stepping, are implemented partly by avoiding running590// compiled code in threads for which the event is enabled. Check here for591// interp_only_mode if these events CAN be enabled.592z_lg(Z_R1_scratch, Address(method, Method::from_interpreted_offset()));593MacroAssembler::load_and_test_int(Z_R0_scratch, Address(Z_thread, JavaThread::interp_only_mode_offset()));594z_bcr(bcondEqual, Z_R1_scratch); // Run compiled code if zero.595// Run interpreted.596z_lg(Z_R1_scratch, Address(method, Method::interpreter_entry_offset()));597z_br(Z_R1_scratch);598} else {599// Run compiled code.600z_lg(Z_R1_scratch, Address(method, Method::from_interpreted_offset()));601z_br(Z_R1_scratch);602}603}604605#ifdef ASSERT606void InterpreterMacroAssembler::verify_esp(Register Resp, Register Rtemp) {607// About to read or write Resp[0].608// Make sure it is not in the monitors or the TOP_IJAVA_FRAME_ABI.609address reentry = NULL;610611{612// Check if the frame pointer in Z_fp is correct.613NearLabel OK;614z_cg(Z_fp, 0, Z_SP);615z_bre(OK);616reentry = stop_chain_static(reentry, "invalid frame pointer Z_fp");617bind(OK);618}619{620// Resp must not point into or below the operand stack,621// i.e. IJAVA_STATE.monitors > Resp.622NearLabel OK;623Register Rmonitors = Rtemp;624z_lg(Rmonitors, _z_ijava_state_neg(monitors), Z_fp);625compareU64_and_branch(Rmonitors, Resp, bcondHigh, OK);626reentry = stop_chain_static(reentry, "too many pops: Z_esp points into monitor area");627bind(OK);628}629{630// Resp may point to the last word of TOP_IJAVA_FRAME_ABI, but not below631// i.e. !(Z_SP + frame::z_top_ijava_frame_abi_size - Interpreter::stackElementSize > Resp).632NearLabel OK;633Register Rabi_bottom = Rtemp;634add2reg(Rabi_bottom, frame::z_top_ijava_frame_abi_size - Interpreter::stackElementSize, Z_SP);635compareU64_and_branch(Rabi_bottom, Resp, bcondNotHigh, OK);636reentry = stop_chain_static(reentry, "too many pushes: Z_esp points into TOP_IJAVA_FRAME_ABI");637bind(OK);638}639}640641void InterpreterMacroAssembler::asm_assert_ijava_state_magic(Register tmp) {642Label magic_ok;643load_const_optimized(tmp, frame::z_istate_magic_number);644z_cg(tmp, Address(Z_fp, _z_ijava_state_neg(magic)));645z_bre(magic_ok);646stop_static("error: wrong magic number in ijava_state access");647bind(magic_ok);648}649#endif // ASSERT650651void InterpreterMacroAssembler::save_bcp() {652z_stg(Z_bcp, Address(Z_fp, _z_ijava_state_neg(bcp)));653asm_assert_ijava_state_magic(Z_bcp);654NOT_PRODUCT(z_lg(Z_bcp, Address(Z_fp, _z_ijava_state_neg(bcp))));655}656657void InterpreterMacroAssembler::restore_bcp() {658asm_assert_ijava_state_magic(Z_bcp);659z_lg(Z_bcp, Address(Z_fp, _z_ijava_state_neg(bcp)));660}661662void InterpreterMacroAssembler::save_esp() {663z_stg(Z_esp, Address(Z_fp, _z_ijava_state_neg(esp)));664}665666void InterpreterMacroAssembler::restore_esp() {667asm_assert_ijava_state_magic(Z_esp);668z_lg(Z_esp, Address(Z_fp, _z_ijava_state_neg(esp)));669}670671void InterpreterMacroAssembler::get_monitors(Register reg) {672asm_assert_ijava_state_magic(reg);673mem2reg_opt(reg, Address(Z_fp, _z_ijava_state_neg(monitors)));674}675676void InterpreterMacroAssembler::save_monitors(Register reg) {677reg2mem_opt(reg, Address(Z_fp, _z_ijava_state_neg(monitors)));678}679680void InterpreterMacroAssembler::get_mdp(Register mdp) {681z_lg(mdp, _z_ijava_state_neg(mdx), Z_fp);682}683684void InterpreterMacroAssembler::save_mdp(Register mdp) {685z_stg(mdp, _z_ijava_state_neg(mdx), Z_fp);686}687688// Values that are only read (besides initialization).689void InterpreterMacroAssembler::restore_locals() {690asm_assert_ijava_state_magic(Z_locals);691z_lg(Z_locals, Address(Z_fp, _z_ijava_state_neg(locals)));692}693694void InterpreterMacroAssembler::get_method(Register reg) {695asm_assert_ijava_state_magic(reg);696z_lg(reg, Address(Z_fp, _z_ijava_state_neg(method)));697}698699void InterpreterMacroAssembler::get_2_byte_integer_at_bcp(Register Rdst, int bcp_offset,700signedOrNot is_signed) {701// Rdst is an 8-byte return value!!!702703// Unaligned loads incur only a small penalty on z/Architecture. The penalty704// is a few (2..3) ticks, even when the load crosses a cache line705// boundary. In case of a cache miss, the stall could, of course, be706// much longer.707708switch (is_signed) {709case Signed:710z_lgh(Rdst, bcp_offset, Z_R0, Z_bcp);711break;712case Unsigned:713z_llgh(Rdst, bcp_offset, Z_R0, Z_bcp);714break;715default:716ShouldNotReachHere();717}718}719720721void InterpreterMacroAssembler::get_4_byte_integer_at_bcp(Register Rdst, int bcp_offset,722setCCOrNot set_cc) {723// Rdst is an 8-byte return value!!!724725// Unaligned loads incur only a small penalty on z/Architecture. The penalty726// is a few (2..3) ticks, even when the load crosses a cache line727// boundary. In case of a cache miss, the stall could, of course, be728// much longer.729730// Both variants implement a sign-extending int2long load.731if (set_cc == set_CC) {732load_and_test_int2long(Rdst, Address(Z_bcp, (intptr_t)bcp_offset));733} else {734mem2reg_signed_opt( Rdst, Address(Z_bcp, (intptr_t)bcp_offset));735}736}737738void InterpreterMacroAssembler::get_constant_pool(Register Rdst) {739get_method(Rdst);740mem2reg_opt(Rdst, Address(Rdst, Method::const_offset()));741mem2reg_opt(Rdst, Address(Rdst, ConstMethod::constants_offset()));742}743744void InterpreterMacroAssembler::get_cpool_and_tags(Register Rcpool, Register Rtags) {745get_constant_pool(Rcpool);746mem2reg_opt(Rtags, Address(Rcpool, ConstantPool::tags_offset_in_bytes()));747}748749// Unlock if synchronized method.750//751// Unlock the receiver if this is a synchronized method.752// Unlock any Java monitors from syncronized blocks.753//754// If there are locked Java monitors755// If throw_monitor_exception756// throws IllegalMonitorStateException757// Else if install_monitor_exception758// installs IllegalMonitorStateException759// Else760// no error processing761void InterpreterMacroAssembler::unlock_if_synchronized_method(TosState state,762bool throw_monitor_exception,763bool install_monitor_exception) {764NearLabel unlocked, unlock, no_unlock;765766{767Register R_method = Z_ARG2;768Register R_do_not_unlock_if_synchronized = Z_ARG3;769770// Get the value of _do_not_unlock_if_synchronized into G1_scratch.771const Address do_not_unlock_if_synchronized(Z_thread,772JavaThread::do_not_unlock_if_synchronized_offset());773load_sized_value(R_do_not_unlock_if_synchronized, do_not_unlock_if_synchronized, 1, false /*unsigned*/);774z_mvi(do_not_unlock_if_synchronized, false); // Reset the flag.775776// Check if synchronized method.777get_method(R_method);778verify_oop(Z_tos, state);779push(state); // Save tos/result.780testbit(method2_(R_method, access_flags), JVM_ACC_SYNCHRONIZED_BIT);781z_bfalse(unlocked);782783// Don't unlock anything if the _do_not_unlock_if_synchronized flag784// is set.785compareU64_and_branch(R_do_not_unlock_if_synchronized, (intptr_t)0L, bcondNotEqual, no_unlock);786}787788// unlock monitor789790// BasicObjectLock will be first in list, since this is a791// synchronized method. However, need to check that the object has792// not been unlocked by an explicit monitorexit bytecode.793const Address monitor(Z_fp, -(frame::z_ijava_state_size + (int) sizeof(BasicObjectLock)));794// We use Z_ARG2 so that if we go slow path it will be the correct795// register for unlock_object to pass to VM directly.796load_address(Z_ARG2, monitor); // Address of first monitor.797z_lg(Z_ARG3, Address(Z_ARG2, BasicObjectLock::obj_offset_in_bytes()));798compareU64_and_branch(Z_ARG3, (intptr_t)0L, bcondNotEqual, unlock);799800if (throw_monitor_exception) {801// Entry already unlocked need to throw an exception.802MacroAssembler::call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_illegal_monitor_state_exception));803should_not_reach_here();804} else {805// Monitor already unlocked during a stack unroll.806// If requested, install an illegal_monitor_state_exception.807// Continue with stack unrolling.808if (install_monitor_exception) {809MacroAssembler::call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::new_illegal_monitor_state_exception));810}811z_bru(unlocked);812}813814bind(unlock);815816unlock_object(Z_ARG2);817818bind(unlocked);819820// I0, I1: Might contain return value821822// Check that all monitors are unlocked.823{824NearLabel loop, exception, entry, restart;825const int entry_size = frame::interpreter_frame_monitor_size() * wordSize;826// We use Z_ARG2 so that if we go slow path it will be the correct827// register for unlock_object to pass to VM directly.828Register R_current_monitor = Z_ARG2;829Register R_monitor_block_bot = Z_ARG1;830const Address monitor_block_top(Z_fp, _z_ijava_state_neg(monitors));831const Address monitor_block_bot(Z_fp, -frame::z_ijava_state_size);832833bind(restart);834// Starting with top-most entry.835z_lg(R_current_monitor, monitor_block_top);836// Points to word before bottom of monitor block.837load_address(R_monitor_block_bot, monitor_block_bot);838z_bru(entry);839840// Entry already locked, need to throw exception.841bind(exception);842843if (throw_monitor_exception) {844// Throw exception.845MacroAssembler::call_VM(noreg,846CAST_FROM_FN_PTR(address, InterpreterRuntime::847throw_illegal_monitor_state_exception));848should_not_reach_here();849} else {850// Stack unrolling. Unlock object and install illegal_monitor_exception.851// Unlock does not block, so don't have to worry about the frame.852// We don't have to preserve c_rarg1 since we are going to throw an exception.853unlock_object(R_current_monitor);854if (install_monitor_exception) {855call_VM(noreg, CAST_FROM_FN_PTR(address,856InterpreterRuntime::857new_illegal_monitor_state_exception));858}859z_bru(restart);860}861862bind(loop);863// Check if current entry is used.864load_and_test_long(Z_R0_scratch, Address(R_current_monitor, BasicObjectLock::obj_offset_in_bytes()));865z_brne(exception);866867add2reg(R_current_monitor, entry_size); // Otherwise advance to next entry.868bind(entry);869compareU64_and_branch(R_current_monitor, R_monitor_block_bot, bcondNotEqual, loop);870}871872bind(no_unlock);873pop(state);874verify_oop(Z_tos, state);875}876877void InterpreterMacroAssembler::narrow(Register result, Register ret_type) {878get_method(ret_type);879z_lg(ret_type, Address(ret_type, in_bytes(Method::const_offset())));880z_lb(ret_type, Address(ret_type, in_bytes(ConstMethod::result_type_offset())));881882Label notBool, notByte, notChar, done;883884// common case first885compareU32_and_branch(ret_type, T_INT, bcondEqual, done);886887compareU32_and_branch(ret_type, T_BOOLEAN, bcondNotEqual, notBool);888z_nilf(result, 0x1);889z_bru(done);890891bind(notBool);892compareU32_and_branch(ret_type, T_BYTE, bcondNotEqual, notByte);893z_lbr(result, result);894z_bru(done);895896bind(notByte);897compareU32_and_branch(ret_type, T_CHAR, bcondNotEqual, notChar);898z_nilf(result, 0xffff);899z_bru(done);900901bind(notChar);902// compareU32_and_branch(ret_type, T_SHORT, bcondNotEqual, notShort);903z_lhr(result, result);904905// Nothing to do for T_INT906bind(done);907}908909// remove activation910//911// Unlock the receiver if this is a synchronized method.912// Unlock any Java monitors from syncronized blocks.913// Remove the activation from the stack.914//915// If there are locked Java monitors916// If throw_monitor_exception917// throws IllegalMonitorStateException918// Else if install_monitor_exception919// installs IllegalMonitorStateException920// Else921// no error processing922void InterpreterMacroAssembler::remove_activation(TosState state,923Register return_pc,924bool throw_monitor_exception,925bool install_monitor_exception,926bool notify_jvmti) {927BLOCK_COMMENT("remove_activation {");928unlock_if_synchronized_method(state, throw_monitor_exception, install_monitor_exception);929930// Save result (push state before jvmti call and pop it afterwards) and notify jvmti.931notify_method_exit(false, state, notify_jvmti ? NotifyJVMTI : SkipNotifyJVMTI);932933if (StackReservedPages > 0) {934BLOCK_COMMENT("reserved_stack_check:");935// Test if reserved zone needs to be enabled.936Label no_reserved_zone_enabling;937938// Compare frame pointers. There is no good stack pointer, as with stack939// frame compression we can get different SPs when we do calls. A subsequent940// call could have a smaller SP, so that this compare succeeds for an941// inner call of the method annotated with ReservedStack.942z_lg(Z_R0, Address(Z_SP, (intptr_t)_z_abi(callers_sp)));943z_clg(Z_R0, Address(Z_thread, JavaThread::reserved_stack_activation_offset())); // Compare with frame pointer in memory.944z_brl(no_reserved_zone_enabling);945946// Enable reserved zone again, throw stack overflow exception.947call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::enable_stack_reserved_zone), Z_thread);948call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_delayed_StackOverflowError));949950should_not_reach_here();951952bind(no_reserved_zone_enabling);953}954955verify_oop(Z_tos, state);956verify_thread();957958pop_interpreter_frame(return_pc, Z_ARG2, Z_ARG3);959BLOCK_COMMENT("} remove_activation");960}961962// lock object963//964// Registers alive965// monitor - Address of the BasicObjectLock to be used for locking,966// which must be initialized with the object to lock.967// object - Address of the object to be locked.968void InterpreterMacroAssembler::lock_object(Register monitor, Register object) {969970if (UseHeavyMonitors) {971call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorenter), monitor);972return;973}974975// template code:976//977// markWord displaced_header = obj->mark().set_unlocked();978// monitor->lock()->set_displaced_header(displaced_header);979// if (Atomic::cmpxchg(/*addr*/obj->mark_addr(), /*cmp*/displaced_header, /*ex=*/monitor) == displaced_header) {980// // We stored the monitor address into the object's mark word.981// } else if (THREAD->is_lock_owned((address)displaced_header))982// // Simple recursive case.983// monitor->lock()->set_displaced_header(NULL);984// } else {985// // Slow path.986// InterpreterRuntime::monitorenter(THREAD, monitor);987// }988989const Register displaced_header = Z_ARG5;990const Register object_mark_addr = Z_ARG4;991const Register current_header = Z_ARG5;992993NearLabel done;994NearLabel slow_case;995996// markWord displaced_header = obj->mark().set_unlocked();997998// Load markWord from object into displaced_header.999z_lg(displaced_header, oopDesc::mark_offset_in_bytes(), object);10001001if (DiagnoseSyncOnValueBasedClasses != 0) {1002load_klass(Z_R1_scratch, object);1003testbit(Address(Z_R1_scratch, Klass::access_flags_offset()), exact_log2(JVM_ACC_IS_VALUE_BASED_CLASS));1004z_btrue(slow_case);1005}10061007if (UseBiasedLocking) {1008biased_locking_enter(object, displaced_header, Z_R1, Z_R0, done, &slow_case);1009}10101011// Set displaced_header to be (markWord of object | UNLOCK_VALUE).1012z_oill(displaced_header, markWord::unlocked_value);10131014// monitor->lock()->set_displaced_header(displaced_header);10151016// Initialize the box (Must happen before we update the object mark!).1017z_stg(displaced_header, BasicObjectLock::lock_offset_in_bytes() +1018BasicLock::displaced_header_offset_in_bytes(), monitor);10191020// if (Atomic::cmpxchg(/*addr*/obj->mark_addr(), /*cmp*/displaced_header, /*ex=*/monitor) == displaced_header) {10211022// Store stack address of the BasicObjectLock (this is monitor) into object.1023add2reg(object_mark_addr, oopDesc::mark_offset_in_bytes(), object);10241025z_csg(displaced_header, monitor, 0, object_mark_addr);1026assert(current_header==displaced_header, "must be same register"); // Identified two registers from z/Architecture.10271028z_bre(done);10291030// } else if (THREAD->is_lock_owned((address)displaced_header))1031// // Simple recursive case.1032// monitor->lock()->set_displaced_header(NULL);10331034// We did not see an unlocked object so try the fast recursive case.10351036// Check if owner is self by comparing the value in the markWord of object1037// (current_header) with the stack pointer.1038z_sgr(current_header, Z_SP);10391040assert(os::vm_page_size() > 0xfff, "page size too small - change the constant");10411042// The prior sequence "LGR, NGR, LTGR" can be done better1043// (Z_R1 is temp and not used after here).1044load_const_optimized(Z_R0, (~(os::vm_page_size()-1) | markWord::lock_mask_in_place));1045z_ngr(Z_R0, current_header); // AND sets CC (result eq/ne 0)10461047// If condition is true we are done and hence we can store 0 in the displaced1048// header indicating it is a recursive lock and be done.1049z_brne(slow_case);1050z_release(); // Membar unnecessary on zarch AND because the above csg does a sync before and after.1051z_stg(Z_R0/*==0!*/, BasicObjectLock::lock_offset_in_bytes() +1052BasicLock::displaced_header_offset_in_bytes(), monitor);1053z_bru(done);10541055// } else {1056// // Slow path.1057// InterpreterRuntime::monitorenter(THREAD, monitor);10581059// None of the above fast optimizations worked so we have to get into the1060// slow case of monitor enter.1061bind(slow_case);1062call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorenter), monitor);10631064// }10651066bind(done);1067}10681069// Unlocks an object. Used in monitorexit bytecode and remove_activation.1070//1071// Registers alive1072// monitor - address of the BasicObjectLock to be used for locking,1073// which must be initialized with the object to lock.1074//1075// Throw IllegalMonitorException if object is not locked by current thread.1076void InterpreterMacroAssembler::unlock_object(Register monitor, Register object) {10771078if (UseHeavyMonitors) {1079call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorexit), monitor);1080return;1081}10821083// else {1084// template code:1085//1086// if ((displaced_header = monitor->displaced_header()) == NULL) {1087// // Recursive unlock. Mark the monitor unlocked by setting the object field to NULL.1088// monitor->set_obj(NULL);1089// } else if (Atomic::cmpxchg(obj->mark_addr(), monitor, displaced_header) == monitor) {1090// // We swapped the unlocked mark in displaced_header into the object's mark word.1091// monitor->set_obj(NULL);1092// } else {1093// // Slow path.1094// InterpreterRuntime::monitorexit(monitor);1095// }10961097const Register displaced_header = Z_ARG4;1098const Register current_header = Z_R1;1099Address obj_entry(monitor, BasicObjectLock::obj_offset_in_bytes());1100Label done;11011102if (object == noreg) {1103// In the template interpreter, we must assure that the object1104// entry in the monitor is cleared on all paths. Thus we move1105// loading up to here, and clear the entry afterwards.1106object = Z_ARG3; // Use Z_ARG3 if caller didn't pass object.1107z_lg(object, obj_entry);1108}11091110assert_different_registers(monitor, object, displaced_header, current_header);11111112// if ((displaced_header = monitor->displaced_header()) == NULL) {1113// // Recursive unlock. Mark the monitor unlocked by setting the object field to NULL.1114// monitor->set_obj(NULL);11151116clear_mem(obj_entry, sizeof(oop));11171118if (UseBiasedLocking) {1119// The object address from the monitor is in object.1120assert(oopDesc::mark_offset_in_bytes() == 0, "offset of _mark is not 0");1121biased_locking_exit(object, displaced_header, done);1122}11231124// Test first if we are in the fast recursive case.1125MacroAssembler::load_and_test_long(displaced_header,1126Address(monitor, BasicObjectLock::lock_offset_in_bytes() +1127BasicLock::displaced_header_offset_in_bytes()));1128z_bre(done); // displaced_header == 0 -> goto done11291130// } else if (Atomic::cmpxchg(obj->mark_addr(), monitor, displaced_header) == monitor) {1131// // We swapped the unlocked mark in displaced_header into the object's mark word.1132// monitor->set_obj(NULL);11331134// If we still have a lightweight lock, unlock the object and be done.11351136// The markword is expected to be at offset 0.1137assert(oopDesc::mark_offset_in_bytes() == 0, "unlock_object: review code below");11381139// We have the displaced header in displaced_header. If the lock is still1140// lightweight, it will contain the monitor address and we'll store the1141// displaced header back into the object's mark word.1142z_lgr(current_header, monitor);1143z_csg(current_header, displaced_header, 0, object);1144z_bre(done);11451146// } else {1147// // Slow path.1148// InterpreterRuntime::monitorexit(monitor);11491150// The lock has been converted into a heavy lock and hence1151// we need to get into the slow case.1152z_stg(object, obj_entry); // Restore object entry, has been cleared above.1153call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorexit), monitor);11541155// }11561157bind(done);1158}11591160void InterpreterMacroAssembler::test_method_data_pointer(Register mdp, Label& zero_continue) {1161assert(ProfileInterpreter, "must be profiling interpreter");1162load_and_test_long(mdp, Address(Z_fp, _z_ijava_state_neg(mdx)));1163z_brz(zero_continue);1164}11651166// Set the method data pointer for the current bcp.1167void InterpreterMacroAssembler::set_method_data_pointer_for_bcp() {1168assert(ProfileInterpreter, "must be profiling interpreter");1169Label set_mdp;1170Register mdp = Z_ARG4;1171Register method = Z_ARG5;11721173get_method(method);1174// Test MDO to avoid the call if it is NULL.1175load_and_test_long(mdp, method2_(method, method_data));1176z_brz(set_mdp);11771178call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::bcp_to_di), method, Z_bcp);1179// Z_RET: mdi1180// Mdo is guaranteed to be non-zero here, we checked for it before the call.1181assert(method->is_nonvolatile(), "choose nonvolatile reg or reload from frame");1182z_lg(mdp, method2_(method, method_data)); // Must reload, mdp is volatile reg.1183add2reg_with_index(mdp, in_bytes(MethodData::data_offset()), Z_RET, mdp);11841185bind(set_mdp);1186save_mdp(mdp);1187}11881189void InterpreterMacroAssembler::verify_method_data_pointer() {1190assert(ProfileInterpreter, "must be profiling interpreter");1191#ifdef ASSERT1192NearLabel verify_continue;1193Register bcp_expected = Z_ARG3;1194Register mdp = Z_ARG4;1195Register method = Z_ARG5;11961197test_method_data_pointer(mdp, verify_continue); // If mdp is zero, continue1198get_method(method);11991200// If the mdp is valid, it will point to a DataLayout header which is1201// consistent with the bcp. The converse is highly probable also.1202load_sized_value(bcp_expected, Address(mdp, DataLayout::bci_offset()), 2, false /*signed*/);1203z_ag(bcp_expected, Address(method, Method::const_offset()));1204load_address(bcp_expected, Address(bcp_expected, ConstMethod::codes_offset()));1205compareU64_and_branch(bcp_expected, Z_bcp, bcondEqual, verify_continue);1206call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::verify_mdp), method, Z_bcp, mdp);1207bind(verify_continue);1208#endif // ASSERT1209}12101211void InterpreterMacroAssembler::set_mdp_data_at(Register mdp_in, int constant, Register value) {1212assert(ProfileInterpreter, "must be profiling interpreter");1213z_stg(value, constant, mdp_in);1214}12151216void InterpreterMacroAssembler::increment_mdp_data_at(Register mdp_in,1217int constant,1218Register tmp,1219bool decrement) {1220assert_different_registers(mdp_in, tmp);1221// counter address1222Address data(mdp_in, constant);1223const int delta = decrement ? -DataLayout::counter_increment : DataLayout::counter_increment;1224add2mem_64(Address(mdp_in, constant), delta, tmp);1225}12261227void InterpreterMacroAssembler::set_mdp_flag_at(Register mdp_in,1228int flag_byte_constant) {1229assert(ProfileInterpreter, "must be profiling interpreter");1230// Set the flag.1231z_oi(Address(mdp_in, DataLayout::flags_offset()), flag_byte_constant);1232}12331234void InterpreterMacroAssembler::test_mdp_data_at(Register mdp_in,1235int offset,1236Register value,1237Register test_value_out,1238Label& not_equal_continue) {1239assert(ProfileInterpreter, "must be profiling interpreter");1240if (test_value_out == noreg) {1241z_cg(value, Address(mdp_in, offset));1242z_brne(not_equal_continue);1243} else {1244// Put the test value into a register, so caller can use it:1245z_lg(test_value_out, Address(mdp_in, offset));1246compareU64_and_branch(test_value_out, value, bcondNotEqual, not_equal_continue);1247}1248}12491250void InterpreterMacroAssembler::update_mdp_by_offset(Register mdp_in, int offset_of_disp) {1251update_mdp_by_offset(mdp_in, noreg, offset_of_disp);1252}12531254void InterpreterMacroAssembler::update_mdp_by_offset(Register mdp_in,1255Register dataidx,1256int offset_of_disp) {1257assert(ProfileInterpreter, "must be profiling interpreter");1258Address disp_address(mdp_in, dataidx, offset_of_disp);1259Assembler::z_ag(mdp_in, disp_address);1260save_mdp(mdp_in);1261}12621263void InterpreterMacroAssembler::update_mdp_by_constant(Register mdp_in, int constant) {1264assert(ProfileInterpreter, "must be profiling interpreter");1265add2reg(mdp_in, constant);1266save_mdp(mdp_in);1267}12681269void InterpreterMacroAssembler::update_mdp_for_ret(Register return_bci) {1270assert(ProfileInterpreter, "must be profiling interpreter");1271assert(return_bci->is_nonvolatile(), "choose nonvolatile reg or save/restore");1272call_VM(noreg,1273CAST_FROM_FN_PTR(address, InterpreterRuntime::update_mdp_for_ret),1274return_bci);1275}12761277void InterpreterMacroAssembler::profile_taken_branch(Register mdp, Register bumped_count) {1278if (ProfileInterpreter) {1279Label profile_continue;12801281// If no method data exists, go to profile_continue.1282// Otherwise, assign to mdp.1283test_method_data_pointer(mdp, profile_continue);12841285// We are taking a branch. Increment the taken count.1286// We inline increment_mdp_data_at to return bumped_count in a register1287//increment_mdp_data_at(mdp, in_bytes(JumpData::taken_offset()));1288Address data(mdp, JumpData::taken_offset());1289z_lg(bumped_count, data);1290// 64-bit overflow is very unlikely. Saturation to 32-bit values is1291// performed when reading the counts.1292add2reg(bumped_count, DataLayout::counter_increment);1293z_stg(bumped_count, data); // Store back out12941295// The method data pointer needs to be updated to reflect the new target.1296update_mdp_by_offset(mdp, in_bytes(JumpData::displacement_offset()));1297bind(profile_continue);1298}1299}13001301// Kills Z_R1_scratch.1302void InterpreterMacroAssembler::profile_not_taken_branch(Register mdp) {1303if (ProfileInterpreter) {1304Label profile_continue;13051306// If no method data exists, go to profile_continue.1307test_method_data_pointer(mdp, profile_continue);13081309// We are taking a branch. Increment the not taken count.1310increment_mdp_data_at(mdp, in_bytes(BranchData::not_taken_offset()), Z_R1_scratch);13111312// The method data pointer needs to be updated to correspond to1313// the next bytecode.1314update_mdp_by_constant(mdp, in_bytes(BranchData::branch_data_size()));1315bind(profile_continue);1316}1317}13181319// Kills: Z_R1_scratch.1320void InterpreterMacroAssembler::profile_call(Register mdp) {1321if (ProfileInterpreter) {1322Label profile_continue;13231324// If no method data exists, go to profile_continue.1325test_method_data_pointer(mdp, profile_continue);13261327// We are making a call. Increment the count.1328increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));13291330// The method data pointer needs to be updated to reflect the new target.1331update_mdp_by_constant(mdp, in_bytes(CounterData::counter_data_size()));1332bind(profile_continue);1333}1334}13351336void InterpreterMacroAssembler::profile_final_call(Register mdp) {1337if (ProfileInterpreter) {1338Label profile_continue;13391340// If no method data exists, go to profile_continue.1341test_method_data_pointer(mdp, profile_continue);13421343// We are making a call. Increment the count.1344increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));13451346// The method data pointer needs to be updated to reflect the new target.1347update_mdp_by_constant(mdp, in_bytes(VirtualCallData::virtual_call_data_size()));1348bind(profile_continue);1349}1350}13511352void InterpreterMacroAssembler::profile_virtual_call(Register receiver,1353Register mdp,1354Register reg2,1355bool receiver_can_be_null) {1356if (ProfileInterpreter) {1357NearLabel profile_continue;13581359// If no method data exists, go to profile_continue.1360test_method_data_pointer(mdp, profile_continue);13611362NearLabel skip_receiver_profile;1363if (receiver_can_be_null) {1364NearLabel not_null;1365compareU64_and_branch(receiver, (intptr_t)0L, bcondNotEqual, not_null);1366// We are making a call. Increment the count for null receiver.1367increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));1368z_bru(skip_receiver_profile);1369bind(not_null);1370}13711372// Record the receiver type.1373record_klass_in_profile(receiver, mdp, reg2, true);1374bind(skip_receiver_profile);13751376// The method data pointer needs to be updated to reflect the new target.1377update_mdp_by_constant(mdp, in_bytes(VirtualCallData::virtual_call_data_size()));1378bind(profile_continue);1379}1380}13811382// This routine creates a state machine for updating the multi-row1383// type profile at a virtual call site (or other type-sensitive bytecode).1384// The machine visits each row (of receiver/count) until the receiver type1385// is found, or until it runs out of rows. At the same time, it remembers1386// the location of the first empty row. (An empty row records null for its1387// receiver, and can be allocated for a newly-observed receiver type.)1388// Because there are two degrees of freedom in the state, a simple linear1389// search will not work; it must be a decision tree. Hence this helper1390// function is recursive, to generate the required tree structured code.1391// It's the interpreter, so we are trading off code space for speed.1392// See below for example code.1393void InterpreterMacroAssembler::record_klass_in_profile_helper(1394Register receiver, Register mdp,1395Register reg2, int start_row,1396Label& done, bool is_virtual_call) {1397if (TypeProfileWidth == 0) {1398if (is_virtual_call) {1399increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));1400}1401return;1402}14031404int last_row = VirtualCallData::row_limit() - 1;1405assert(start_row <= last_row, "must be work left to do");1406// Test this row for both the receiver and for null.1407// Take any of three different outcomes:1408// 1. found receiver => increment count and goto done1409// 2. found null => keep looking for case 1, maybe allocate this cell1410// 3. found something else => keep looking for cases 1 and 21411// Case 3 is handled by a recursive call.1412for (int row = start_row; row <= last_row; row++) {1413NearLabel next_test;1414bool test_for_null_also = (row == start_row);14151416// See if the receiver is receiver[n].1417int recvr_offset = in_bytes(VirtualCallData::receiver_offset(row));1418test_mdp_data_at(mdp, recvr_offset, receiver,1419(test_for_null_also ? reg2 : noreg),1420next_test);1421// (Reg2 now contains the receiver from the CallData.)14221423// The receiver is receiver[n]. Increment count[n].1424int count_offset = in_bytes(VirtualCallData::receiver_count_offset(row));1425increment_mdp_data_at(mdp, count_offset);1426z_bru(done);1427bind(next_test);14281429if (test_for_null_also) {1430Label found_null;1431// Failed the equality check on receiver[n]... Test for null.1432z_ltgr(reg2, reg2);1433if (start_row == last_row) {1434// The only thing left to do is handle the null case.1435if (is_virtual_call) {1436z_brz(found_null);1437// Receiver did not match any saved receiver and there is no empty row for it.1438// Increment total counter to indicate polymorphic case.1439increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));1440z_bru(done);1441bind(found_null);1442} else {1443z_brnz(done);1444}1445break;1446}1447// Since null is rare, make it be the branch-taken case.1448z_brz(found_null);14491450// Put all the "Case 3" tests here.1451record_klass_in_profile_helper(receiver, mdp, reg2, start_row + 1, done, is_virtual_call);14521453// Found a null. Keep searching for a matching receiver,1454// but remember that this is an empty (unused) slot.1455bind(found_null);1456}1457}14581459// In the fall-through case, we found no matching receiver, but we1460// observed the receiver[start_row] is NULL.14611462// Fill in the receiver field and increment the count.1463int recvr_offset = in_bytes(VirtualCallData::receiver_offset(start_row));1464set_mdp_data_at(mdp, recvr_offset, receiver);1465int count_offset = in_bytes(VirtualCallData::receiver_count_offset(start_row));1466load_const_optimized(reg2, DataLayout::counter_increment);1467set_mdp_data_at(mdp, count_offset, reg2);1468if (start_row > 0) {1469z_bru(done);1470}1471}14721473// Example state machine code for three profile rows:1474// // main copy of decision tree, rooted at row[1]1475// if (row[0].rec == rec) { row[0].incr(); goto done; }1476// if (row[0].rec != NULL) {1477// // inner copy of decision tree, rooted at row[1]1478// if (row[1].rec == rec) { row[1].incr(); goto done; }1479// if (row[1].rec != NULL) {1480// // degenerate decision tree, rooted at row[2]1481// if (row[2].rec == rec) { row[2].incr(); goto done; }1482// if (row[2].rec != NULL) { count.incr(); goto done; } // overflow1483// row[2].init(rec); goto done;1484// } else {1485// // remember row[1] is empty1486// if (row[2].rec == rec) { row[2].incr(); goto done; }1487// row[1].init(rec); goto done;1488// }1489// } else {1490// // remember row[0] is empty1491// if (row[1].rec == rec) { row[1].incr(); goto done; }1492// if (row[2].rec == rec) { row[2].incr(); goto done; }1493// row[0].init(rec); goto done;1494// }1495// done:14961497void InterpreterMacroAssembler::record_klass_in_profile(Register receiver,1498Register mdp, Register reg2,1499bool is_virtual_call) {1500assert(ProfileInterpreter, "must be profiling");1501Label done;15021503record_klass_in_profile_helper(receiver, mdp, reg2, 0, done, is_virtual_call);15041505bind (done);1506}15071508void InterpreterMacroAssembler::profile_ret(Register return_bci, Register mdp) {1509if (ProfileInterpreter) {1510NearLabel profile_continue;1511uint row;15121513// If no method data exists, go to profile_continue.1514test_method_data_pointer(mdp, profile_continue);15151516// Update the total ret count.1517increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset()));15181519for (row = 0; row < RetData::row_limit(); row++) {1520NearLabel next_test;15211522// See if return_bci is equal to bci[n]:1523test_mdp_data_at(mdp,1524in_bytes(RetData::bci_offset(row)),1525return_bci, noreg,1526next_test);15271528// Return_bci is equal to bci[n]. Increment the count.1529increment_mdp_data_at(mdp, in_bytes(RetData::bci_count_offset(row)));15301531// The method data pointer needs to be updated to reflect the new target.1532update_mdp_by_offset(mdp, in_bytes(RetData::bci_displacement_offset(row)));1533z_bru(profile_continue);1534bind(next_test);1535}15361537update_mdp_for_ret(return_bci);15381539bind(profile_continue);1540}1541}15421543void InterpreterMacroAssembler::profile_null_seen(Register mdp) {1544if (ProfileInterpreter) {1545Label profile_continue;15461547// If no method data exists, go to profile_continue.1548test_method_data_pointer(mdp, profile_continue);15491550set_mdp_flag_at(mdp, BitData::null_seen_byte_constant());15511552// The method data pointer needs to be updated.1553int mdp_delta = in_bytes(BitData::bit_data_size());1554if (TypeProfileCasts) {1555mdp_delta = in_bytes(VirtualCallData::virtual_call_data_size());1556}1557update_mdp_by_constant(mdp, mdp_delta);15581559bind(profile_continue);1560}1561}15621563void InterpreterMacroAssembler::profile_typecheck_failed(Register mdp, Register tmp) {1564if (ProfileInterpreter && TypeProfileCasts) {1565Label profile_continue;15661567// If no method data exists, go to profile_continue.1568test_method_data_pointer(mdp, profile_continue);15691570int count_offset = in_bytes(CounterData::count_offset());1571// Back up the address, since we have already bumped the mdp.1572count_offset -= in_bytes(VirtualCallData::virtual_call_data_size());15731574// *Decrement* the counter. We expect to see zero or small negatives.1575increment_mdp_data_at(mdp, count_offset, tmp, true);15761577bind (profile_continue);1578}1579}15801581void InterpreterMacroAssembler::profile_typecheck(Register mdp, Register klass, Register reg2) {1582if (ProfileInterpreter) {1583Label profile_continue;15841585// If no method data exists, go to profile_continue.1586test_method_data_pointer(mdp, profile_continue);15871588// The method data pointer needs to be updated.1589int mdp_delta = in_bytes(BitData::bit_data_size());1590if (TypeProfileCasts) {1591mdp_delta = in_bytes(VirtualCallData::virtual_call_data_size());15921593// Record the object type.1594record_klass_in_profile(klass, mdp, reg2, false);1595}1596update_mdp_by_constant(mdp, mdp_delta);15971598bind(profile_continue);1599}1600}16011602void InterpreterMacroAssembler::profile_switch_default(Register mdp) {1603if (ProfileInterpreter) {1604Label profile_continue;16051606// If no method data exists, go to profile_continue.1607test_method_data_pointer(mdp, profile_continue);16081609// Update the default case count.1610increment_mdp_data_at(mdp, in_bytes(MultiBranchData::default_count_offset()));16111612// The method data pointer needs to be updated.1613update_mdp_by_offset(mdp, in_bytes(MultiBranchData::default_displacement_offset()));16141615bind(profile_continue);1616}1617}16181619// Kills: index, scratch1, scratch2.1620void InterpreterMacroAssembler::profile_switch_case(Register index,1621Register mdp,1622Register scratch1,1623Register scratch2) {1624if (ProfileInterpreter) {1625Label profile_continue;1626assert_different_registers(index, mdp, scratch1, scratch2);16271628// If no method data exists, go to profile_continue.1629test_method_data_pointer(mdp, profile_continue);16301631// Build the base (index * per_case_size_in_bytes()) +1632// case_array_offset_in_bytes().1633z_sllg(index, index, exact_log2(in_bytes(MultiBranchData::per_case_size())));1634add2reg(index, in_bytes(MultiBranchData::case_array_offset()));16351636// Add the calculated base to the mdp -> address of the case' data.1637Address case_data_addr(mdp, index);1638Register case_data = scratch1;1639load_address(case_data, case_data_addr);16401641// Update the case count.1642increment_mdp_data_at(case_data,1643in_bytes(MultiBranchData::relative_count_offset()),1644scratch2);16451646// The method data pointer needs to be updated.1647update_mdp_by_offset(mdp,1648index,1649in_bytes(MultiBranchData::relative_displacement_offset()));16501651bind(profile_continue);1652}1653}16541655// kills: R0, R1, flags, loads klass from obj (if not null)1656void InterpreterMacroAssembler::profile_obj_type(Register obj, Address mdo_addr, Register klass, bool cmp_done) {1657NearLabel null_seen, init_klass, do_nothing, do_update;16581659// Klass = obj is allowed.1660const Register tmp = Z_R1;1661assert_different_registers(obj, mdo_addr.base(), tmp, Z_R0);1662assert_different_registers(klass, mdo_addr.base(), tmp, Z_R0);16631664z_lg(tmp, mdo_addr);1665if (cmp_done) {1666z_brz(null_seen);1667} else {1668compareU64_and_branch(obj, (intptr_t)0, Assembler::bcondEqual, null_seen);1669}16701671MacroAssembler::verify_oop(obj, FILE_AND_LINE);1672load_klass(klass, obj);16731674// Klass seen before, nothing to do (regardless of unknown bit).1675z_lgr(Z_R0, tmp);1676assert(Immediate::is_uimm(~TypeEntries::type_klass_mask, 16), "or change following instruction");1677z_nill(Z_R0, TypeEntries::type_klass_mask & 0xFFFF);1678compareU64_and_branch(Z_R0, klass, Assembler::bcondEqual, do_nothing);16791680// Already unknown. Nothing to do anymore.1681z_tmll(tmp, TypeEntries::type_unknown);1682z_brc(Assembler::bcondAllOne, do_nothing);16831684z_lgr(Z_R0, tmp);1685assert(Immediate::is_uimm(~TypeEntries::type_mask, 16), "or change following instruction");1686z_nill(Z_R0, TypeEntries::type_mask & 0xFFFF);1687compareU64_and_branch(Z_R0, (intptr_t)0, Assembler::bcondEqual, init_klass);16881689// Different than before. Cannot keep accurate profile.1690z_oill(tmp, TypeEntries::type_unknown);1691z_bru(do_update);16921693bind(init_klass);1694// Combine klass and null_seen bit (only used if (tmp & type_mask)==0).1695z_ogr(tmp, klass);1696z_bru(do_update);16971698bind(null_seen);1699// Set null_seen if obj is 0.1700z_oill(tmp, TypeEntries::null_seen);1701// fallthru: z_bru(do_update);17021703bind(do_update);1704z_stg(tmp, mdo_addr);17051706bind(do_nothing);1707}17081709void InterpreterMacroAssembler::profile_arguments_type(Register mdp, Register callee, Register tmp, bool is_virtual) {1710if (!ProfileInterpreter) {1711return;1712}17131714assert_different_registers(mdp, callee, tmp);17151716if (MethodData::profile_arguments() || MethodData::profile_return()) {1717Label profile_continue;17181719test_method_data_pointer(mdp, profile_continue);17201721int off_to_start = is_virtual ? in_bytes(VirtualCallData::virtual_call_data_size()) : in_bytes(CounterData::counter_data_size());17221723z_cliy(in_bytes(DataLayout::tag_offset()) - off_to_start, mdp,1724is_virtual ? DataLayout::virtual_call_type_data_tag : DataLayout::call_type_data_tag);1725z_brne(profile_continue);17261727if (MethodData::profile_arguments()) {1728NearLabel done;1729int off_to_args = in_bytes(TypeEntriesAtCall::args_data_offset());1730add2reg(mdp, off_to_args);17311732for (int i = 0; i < TypeProfileArgsLimit; i++) {1733if (i > 0 || MethodData::profile_return()) {1734// If return value type is profiled we may have no argument to profile.1735z_lg(tmp, in_bytes(TypeEntriesAtCall::cell_count_offset())-off_to_args, mdp);1736add2reg(tmp, -i*TypeStackSlotEntries::per_arg_count());1737compare64_and_branch(tmp, TypeStackSlotEntries::per_arg_count(), Assembler::bcondLow, done);1738}1739z_lg(tmp, Address(callee, Method::const_offset()));1740z_lgh(tmp, Address(tmp, ConstMethod::size_of_parameters_offset()));1741// Stack offset o (zero based) from the start of the argument1742// list. For n arguments translates into offset n - o - 1 from1743// the end of the argument list. But there is an extra slot at1744// the top of the stack. So the offset is n - o from Lesp.1745z_sg(tmp, Address(mdp, in_bytes(TypeEntriesAtCall::stack_slot_offset(i))-off_to_args));1746z_sllg(tmp, tmp, Interpreter::logStackElementSize);1747Address stack_slot_addr(tmp, Z_esp);1748z_ltg(tmp, stack_slot_addr);17491750Address mdo_arg_addr(mdp, in_bytes(TypeEntriesAtCall::argument_type_offset(i))-off_to_args);1751profile_obj_type(tmp, mdo_arg_addr, tmp, /*ltg did compare to 0*/ true);17521753int to_add = in_bytes(TypeStackSlotEntries::per_arg_size());1754add2reg(mdp, to_add);1755off_to_args += to_add;1756}17571758if (MethodData::profile_return()) {1759z_lg(tmp, in_bytes(TypeEntriesAtCall::cell_count_offset())-off_to_args, mdp);1760add2reg(tmp, -TypeProfileArgsLimit*TypeStackSlotEntries::per_arg_count());1761}17621763bind(done);17641765if (MethodData::profile_return()) {1766// We're right after the type profile for the last1767// argument. Tmp is the number of cells left in the1768// CallTypeData/VirtualCallTypeData to reach its end. Non null1769// if there's a return to profile.1770assert(ReturnTypeEntry::static_cell_count() < TypeStackSlotEntries::per_arg_count(), "can't move past ret type");1771z_sllg(tmp, tmp, exact_log2(DataLayout::cell_size));1772z_agr(mdp, tmp);1773}1774z_stg(mdp, _z_ijava_state_neg(mdx), Z_fp);1775} else {1776assert(MethodData::profile_return(), "either profile call args or call ret");1777update_mdp_by_constant(mdp, in_bytes(TypeEntriesAtCall::return_only_size()));1778}17791780// Mdp points right after the end of the1781// CallTypeData/VirtualCallTypeData, right after the cells for the1782// return value type if there's one.1783bind(profile_continue);1784}1785}17861787void InterpreterMacroAssembler::profile_return_type(Register mdp, Register ret, Register tmp) {1788assert_different_registers(mdp, ret, tmp);1789if (ProfileInterpreter && MethodData::profile_return()) {1790Label profile_continue;17911792test_method_data_pointer(mdp, profile_continue);17931794if (MethodData::profile_return_jsr292_only()) {1795// If we don't profile all invoke bytecodes we must make sure1796// it's a bytecode we indeed profile. We can't go back to the1797// beginning of the ProfileData we intend to update to check its1798// type because we're right after it and we don't known its1799// length.1800NearLabel do_profile;1801Address bc(Z_bcp);1802z_lb(tmp, bc);1803compare32_and_branch(tmp, Bytecodes::_invokedynamic, Assembler::bcondEqual, do_profile);1804compare32_and_branch(tmp, Bytecodes::_invokehandle, Assembler::bcondEqual, do_profile);1805get_method(tmp);1806// Supplement to 8139891: _intrinsic_id exceeded 1-byte size limit.1807if (Method::intrinsic_id_size_in_bytes() == 1) {1808z_cli(Method::intrinsic_id_offset_in_bytes(), tmp, static_cast<int>(vmIntrinsics::_compiledLambdaForm));1809} else {1810assert(Method::intrinsic_id_size_in_bytes() == 2, "size error: check Method::_intrinsic_id");1811z_lh(tmp, Method::intrinsic_id_offset_in_bytes(), Z_R0, tmp);1812z_chi(tmp, static_cast<int>(vmIntrinsics::_compiledLambdaForm));1813}1814z_brne(profile_continue);18151816bind(do_profile);1817}18181819Address mdo_ret_addr(mdp, -in_bytes(ReturnTypeEntry::size()));1820profile_obj_type(ret, mdo_ret_addr, tmp);18211822bind(profile_continue);1823}1824}18251826void InterpreterMacroAssembler::profile_parameters_type(Register mdp, Register tmp1, Register tmp2) {1827if (ProfileInterpreter && MethodData::profile_parameters()) {1828Label profile_continue, done;18291830test_method_data_pointer(mdp, profile_continue);18311832// Load the offset of the area within the MDO used for1833// parameters. If it's negative we're not profiling any parameters.1834Address parm_di_addr(mdp, in_bytes(MethodData::parameters_type_data_di_offset()) - in_bytes(MethodData::data_offset()));1835load_and_test_int2long(tmp1, parm_di_addr);1836z_brl(profile_continue);18371838// Compute a pointer to the area for parameters from the offset1839// and move the pointer to the slot for the last1840// parameters. Collect profiling from last parameter down.1841// mdo start + parameters offset + array length - 118421843// Pointer to the parameter area in the MDO.1844z_agr(mdp, tmp1);18451846// Offset of the current profile entry to update.1847const Register entry_offset = tmp1;1848// entry_offset = array len in number of cells.1849z_lg(entry_offset, Address(mdp, ArrayData::array_len_offset()));1850// entry_offset (number of cells) = array len - size of 1 entry1851add2reg(entry_offset, -TypeStackSlotEntries::per_arg_count());1852// entry_offset in bytes1853z_sllg(entry_offset, entry_offset, exact_log2(DataLayout::cell_size));18541855Label loop;1856bind(loop);18571858Address arg_off(mdp, entry_offset, ParametersTypeData::stack_slot_offset(0));1859Address arg_type(mdp, entry_offset, ParametersTypeData::type_offset(0));18601861// Load offset on the stack from the slot for this parameter.1862z_lg(tmp2, arg_off);1863z_sllg(tmp2, tmp2, Interpreter::logStackElementSize);1864z_lcgr(tmp2); // Negate.18651866// Profile the parameter.1867z_ltg(tmp2, Address(Z_locals, tmp2));1868profile_obj_type(tmp2, arg_type, tmp2, /*ltg did compare to 0*/ true);18691870// Go to next parameter.1871z_aghi(entry_offset, -TypeStackSlotEntries::per_arg_count() * DataLayout::cell_size);1872z_brnl(loop);18731874bind(profile_continue);1875}1876}18771878// Jump if ((*counter_addr += increment) & mask) satisfies the condition.1879void InterpreterMacroAssembler::increment_mask_and_jump(Address counter_addr,1880int increment,1881Address mask,1882Register scratch,1883bool preloaded,1884branch_condition cond,1885Label *where) {1886assert_different_registers(counter_addr.base(), scratch);1887if (preloaded) {1888add2reg(scratch, increment);1889reg2mem_opt(scratch, counter_addr, false);1890} else {1891if (VM_Version::has_MemWithImmALUOps() && Immediate::is_simm8(increment) && counter_addr.is_RSYform()) {1892z_alsi(counter_addr.disp20(), counter_addr.base(), increment);1893mem2reg_signed_opt(scratch, counter_addr);1894} else {1895mem2reg_signed_opt(scratch, counter_addr);1896add2reg(scratch, increment);1897reg2mem_opt(scratch, counter_addr, false);1898}1899}1900z_n(scratch, mask);1901if (where) { z_brc(cond, *where); }1902}19031904// Get MethodCounters object for given method. Lazily allocated if necessary.1905// method - Ptr to Method object.1906// Rcounters - Ptr to MethodCounters object associated with Method object.1907// skip - Exit point if MethodCounters object can't be created (OOM condition).1908void InterpreterMacroAssembler::get_method_counters(Register Rmethod,1909Register Rcounters,1910Label& skip) {1911assert_different_registers(Rmethod, Rcounters);19121913BLOCK_COMMENT("get MethodCounters object {");19141915Label has_counters;1916load_and_test_long(Rcounters, Address(Rmethod, Method::method_counters_offset()));1917z_brnz(has_counters);19181919call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::build_method_counters), Rmethod);1920z_ltgr(Rcounters, Z_RET); // Runtime call returns MethodCounters object.1921z_brz(skip); // No MethodCounters, out of memory.19221923bind(has_counters);19241925BLOCK_COMMENT("} get MethodCounters object");1926}19271928// Increment invocation counter in MethodCounters object.1929// Return (invocation_counter+backedge_counter) as "result" in RctrSum.1930// Counter values are all unsigned.1931void InterpreterMacroAssembler::increment_invocation_counter(Register Rcounters, Register RctrSum) {1932assert(UseCompiler || LogTouchedMethods, "incrementing must be useful");1933assert_different_registers(Rcounters, RctrSum);19341935int increment = InvocationCounter::count_increment;1936int inv_counter_offset = in_bytes(MethodCounters::invocation_counter_offset() + InvocationCounter::counter_offset());1937int be_counter_offset = in_bytes(MethodCounters::backedge_counter_offset() + InvocationCounter::counter_offset());19381939BLOCK_COMMENT("Increment invocation counter {");19401941if (VM_Version::has_MemWithImmALUOps() && Immediate::is_simm8(increment)) {1942// Increment the invocation counter in place,1943// then add the incremented value to the backedge counter.1944z_l(RctrSum, be_counter_offset, Rcounters);1945z_alsi(inv_counter_offset, Rcounters, increment); // Atomic increment @no extra cost!1946z_nilf(RctrSum, InvocationCounter::count_mask_value); // Mask off state bits.1947z_al(RctrSum, inv_counter_offset, Z_R0, Rcounters);1948} else {1949// This path is optimized for low register consumption1950// at the cost of somewhat higher operand delays.1951// It does not need an extra temp register.19521953// Update the invocation counter.1954z_l(RctrSum, inv_counter_offset, Rcounters);1955if (RctrSum == Z_R0) {1956z_ahi(RctrSum, increment);1957} else {1958add2reg(RctrSum, increment);1959}1960z_st(RctrSum, inv_counter_offset, Rcounters);19611962// Mask off the state bits.1963z_nilf(RctrSum, InvocationCounter::count_mask_value);19641965// Add the backedge counter to the updated invocation counter to1966// form the result.1967z_al(RctrSum, be_counter_offset, Z_R0, Rcounters);1968}19691970BLOCK_COMMENT("} Increment invocation counter");19711972// Note that this macro must leave the backedge_count + invocation_count in Rtmp!1973}197419751976// increment backedge counter in MethodCounters object.1977// return (invocation_counter+backedge_counter) as "result" in RctrSum1978// counter values are all unsigned!1979void InterpreterMacroAssembler::increment_backedge_counter(Register Rcounters, Register RctrSum) {1980assert(UseCompiler, "incrementing must be useful");1981assert_different_registers(Rcounters, RctrSum);19821983int increment = InvocationCounter::count_increment;1984int inv_counter_offset = in_bytes(MethodCounters::invocation_counter_offset() + InvocationCounter::counter_offset());1985int be_counter_offset = in_bytes(MethodCounters::backedge_counter_offset() + InvocationCounter::counter_offset());19861987BLOCK_COMMENT("Increment backedge counter {");19881989if (VM_Version::has_MemWithImmALUOps() && Immediate::is_simm8(increment)) {1990// Increment the invocation counter in place,1991// then add the incremented value to the backedge counter.1992z_l(RctrSum, inv_counter_offset, Rcounters);1993z_alsi(be_counter_offset, Rcounters, increment); // Atomic increment @no extra cost!1994z_nilf(RctrSum, InvocationCounter::count_mask_value); // Mask off state bits.1995z_al(RctrSum, be_counter_offset, Z_R0, Rcounters);1996} else {1997// This path is optimized for low register consumption1998// at the cost of somewhat higher operand delays.1999// It does not need an extra temp register.20002001// Update the invocation counter.2002z_l(RctrSum, be_counter_offset, Rcounters);2003if (RctrSum == Z_R0) {2004z_ahi(RctrSum, increment);2005} else {2006add2reg(RctrSum, increment);2007}2008z_st(RctrSum, be_counter_offset, Rcounters);20092010// Mask off the state bits.2011z_nilf(RctrSum, InvocationCounter::count_mask_value);20122013// Add the backedge counter to the updated invocation counter to2014// form the result.2015z_al(RctrSum, inv_counter_offset, Z_R0, Rcounters);2016}20172018BLOCK_COMMENT("} Increment backedge counter");20192020// Note that this macro must leave the backedge_count + invocation_count in Rtmp!2021}20222023// Add an InterpMonitorElem to stack (see frame_s390.hpp).2024void InterpreterMacroAssembler::add_monitor_to_stack(bool stack_is_empty,2025Register Rtemp1,2026Register Rtemp2,2027Register Rtemp3) {20282029const Register Rcurr_slot = Rtemp1;2030const Register Rlimit = Rtemp2;2031const jint delta = -frame::interpreter_frame_monitor_size() * wordSize;20322033assert((delta & LongAlignmentMask) == 0,2034"sizeof BasicObjectLock must be even number of doublewords");2035assert(2 * wordSize == -delta, "this works only as long as delta == -2*wordSize");2036assert(Rcurr_slot != Z_R0, "Register must be usable as base register");2037assert_different_registers(Rlimit, Rcurr_slot, Rtemp3);20382039get_monitors(Rlimit);20402041// Adjust stack pointer for additional monitor entry.2042resize_frame(RegisterOrConstant((intptr_t) delta), Z_fp, false);20432044if (!stack_is_empty) {2045// Must copy stack contents down.2046NearLabel next, done;20472048// Rtemp := addr(Tos), Z_esp is pointing below it!2049add2reg(Rcurr_slot, wordSize, Z_esp);20502051// Nothing to do, if already at monitor area.2052compareU64_and_branch(Rcurr_slot, Rlimit, bcondNotLow, done);20532054bind(next);20552056// Move one stack slot.2057mem2reg_opt(Rtemp3, Address(Rcurr_slot));2058reg2mem_opt(Rtemp3, Address(Rcurr_slot, delta));2059add2reg(Rcurr_slot, wordSize);2060compareU64_and_branch(Rcurr_slot, Rlimit, bcondLow, next); // Are we done?20612062bind(done);2063// Done copying stack.2064}20652066// Adjust expression stack and monitor pointers.2067add2reg(Z_esp, delta);2068add2reg(Rlimit, delta);2069save_monitors(Rlimit);2070}20712072// Note: Index holds the offset in bytes afterwards.2073// You can use this to store a new value (with Llocals as the base).2074void InterpreterMacroAssembler::access_local_int(Register index, Register dst) {2075z_sllg(index, index, LogBytesPerWord);2076mem2reg_opt(dst, Address(Z_locals, index), false);2077}20782079void InterpreterMacroAssembler::verify_oop(Register reg, TosState state) {2080if (state == atos) { MacroAssembler::verify_oop(reg, FILE_AND_LINE); }2081}20822083// Inline assembly for:2084//2085// if (thread is in interp_only_mode) {2086// InterpreterRuntime::post_method_entry();2087// }20882089void InterpreterMacroAssembler::notify_method_entry() {20902091// JVMTI2092// Whenever JVMTI puts a thread in interp_only_mode, method2093// entry/exit events are sent for that thread to track stack2094// depth. If it is possible to enter interp_only_mode we add2095// the code to check if the event should be sent.2096if (JvmtiExport::can_post_interpreter_events()) {2097Label jvmti_post_done;2098MacroAssembler::load_and_test_int(Z_R0, Address(Z_thread, JavaThread::interp_only_mode_offset()));2099z_bre(jvmti_post_done);2100call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::post_method_entry));2101bind(jvmti_post_done);2102}2103}21042105// Inline assembly for:2106//2107// if (thread is in interp_only_mode) {2108// if (!native_method) save result2109// InterpreterRuntime::post_method_exit();2110// if (!native_method) restore result2111// }2112// if (DTraceMethodProbes) {2113// SharedRuntime::dtrace_method_exit(thread, method);2114// }2115//2116// For native methods their result is stored in z_ijava_state.lresult2117// and z_ijava_state.fresult before coming here.2118// Java methods have their result stored in the expression stack.2119//2120// Notice the dependency to frame::interpreter_frame_result().2121void InterpreterMacroAssembler::notify_method_exit(bool native_method,2122TosState state,2123NotifyMethodExitMode mode) {2124// JVMTI2125// Whenever JVMTI puts a thread in interp_only_mode, method2126// entry/exit events are sent for that thread to track stack2127// depth. If it is possible to enter interp_only_mode we add2128// the code to check if the event should be sent.2129if (mode == NotifyJVMTI && JvmtiExport::can_post_interpreter_events()) {2130Label jvmti_post_done;2131MacroAssembler::load_and_test_int(Z_R0, Address(Z_thread, JavaThread::interp_only_mode_offset()));2132z_bre(jvmti_post_done);2133if (!native_method) push(state); // see frame::interpreter_frame_result()2134call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::post_method_exit));2135if (!native_method) pop(state);2136bind(jvmti_post_done);2137}21382139#if 02140// Dtrace currently not supported on z/Architecture.2141{2142SkipIfEqual skip(this, &DTraceMethodProbes, false);2143push(state);2144get_method(c_rarg1);2145call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_method_exit),2146r15_thread, c_rarg1);2147pop(state);2148}2149#endif2150}21512152void InterpreterMacroAssembler::skip_if_jvmti_mode(Label &Lskip, Register Rscratch) {2153if (!JvmtiExport::can_post_interpreter_events()) {2154return;2155}21562157load_and_test_int(Rscratch, Address(Z_thread, JavaThread::interp_only_mode_offset()));2158z_brnz(Lskip);21592160}21612162// Pop the topmost TOP_IJAVA_FRAME and set it's sender_sp as new Z_SP.2163// The return pc is loaded into the register return_pc.2164//2165// Registers updated:2166// return_pc - The return pc of the calling frame.2167// tmp1, tmp2 - scratch2168void InterpreterMacroAssembler::pop_interpreter_frame(Register return_pc, Register tmp1, Register tmp2) {2169// F0 Z_SP -> caller_sp (F1's)2170// ...2171// sender_sp (F1's)2172// ...2173// F1 Z_fp -> caller_sp (F2's)2174// return_pc (Continuation after return from F0.)2175// ...2176// F2 caller_sp21772178// Remove F0's activation. Restoring Z_SP to sender_sp reverts modifications2179// (a) by a c2i adapter and (b) by generate_fixed_frame().2180// In case (a) the new top frame F1 is an unextended compiled frame.2181// In case (b) F1 is converted from PARENT_IJAVA_FRAME to TOP_IJAVA_FRAME.21822183// Case (b) seems to be redundant when returning to a interpreted caller,2184// because then the caller's top_frame_sp is installed as sp (see2185// TemplateInterpreterGenerator::generate_return_entry_for ()). But2186// pop_interpreter_frame() is also used in exception handling and there the2187// frame type of the caller is unknown, therefore top_frame_sp cannot be used,2188// so it is important that sender_sp is the caller's sp as TOP_IJAVA_FRAME.21892190Register R_f1_sender_sp = tmp1;2191Register R_f2_sp = tmp2;21922193// First check for the interpreter frame's magic.2194asm_assert_ijava_state_magic(R_f2_sp/*tmp*/);2195z_lg(R_f2_sp, _z_parent_ijava_frame_abi(callers_sp), Z_fp);2196z_lg(R_f1_sender_sp, _z_ijava_state_neg(sender_sp), Z_fp);2197if (return_pc->is_valid())2198z_lg(return_pc, _z_parent_ijava_frame_abi(return_pc), Z_fp);2199// Pop F0 by resizing to R_f1_sender_sp and using R_f2_sp as fp.2200resize_frame_absolute(R_f1_sender_sp, R_f2_sp, false/*load fp*/);22012202#ifdef ASSERT2203// The return_pc in the new top frame is dead... at least that's my2204// current understanding; to assert this I overwrite it.2205load_const_optimized(Z_ARG3, 0xb00b1);2206z_stg(Z_ARG3, _z_parent_ijava_frame_abi(return_pc), Z_SP);2207#endif2208}22092210void InterpreterMacroAssembler::verify_FPU(int stack_depth, TosState state) {2211if (VerifyFPU) {2212unimplemented("verfiyFPU");2213}2214}221522162217