Path: blob/master/src/hotspot/cpu/ppc/interp_masm_ppc_64.cpp
40930 views
/*1* Copyright (c) 2003, 2021, Oracle and/or its affiliates. All rights reserved.2* Copyright (c) 2012, 2021 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*/242526#include "precompiled.hpp"27#include "asm/macroAssembler.inline.hpp"28#include "gc/shared/barrierSet.hpp"29#include "gc/shared/barrierSetAssembler.hpp"30#include "interp_masm_ppc.hpp"31#include "interpreter/interpreterRuntime.hpp"32#include "oops/methodData.hpp"33#include "prims/jvmtiExport.hpp"34#include "prims/jvmtiThreadState.hpp"35#include "runtime/frame.inline.hpp"36#include "runtime/safepointMechanism.hpp"37#include "runtime/sharedRuntime.hpp"38#include "runtime/vm_version.hpp"39#include "utilities/powerOfTwo.hpp"4041// Implementation of InterpreterMacroAssembler.4243// This file specializes the assembler with interpreter-specific macros.4445#ifdef PRODUCT46#define BLOCK_COMMENT(str) // nothing47#else48#define BLOCK_COMMENT(str) block_comment(str)49#endif5051void InterpreterMacroAssembler::null_check_throw(Register a, int offset, Register temp_reg) {52address exception_entry = Interpreter::throw_NullPointerException_entry();53MacroAssembler::null_check_throw(a, offset, temp_reg, exception_entry);54}5556void InterpreterMacroAssembler::jump_to_entry(address entry, Register Rscratch) {57assert(entry, "Entry must have been generated by now");58if (is_within_range_of_b(entry, pc())) {59b(entry);60} else {61load_const_optimized(Rscratch, entry, R0);62mtctr(Rscratch);63bctr();64}65}6667void InterpreterMacroAssembler::dispatch_next(TosState state, int bcp_incr, bool generate_poll) {68Register bytecode = R12_scratch2;69if (bcp_incr != 0) {70lbzu(bytecode, bcp_incr, R14_bcp);71} else {72lbz(bytecode, 0, R14_bcp);73}7475dispatch_Lbyte_code(state, bytecode, Interpreter::dispatch_table(state), generate_poll);76}7778void InterpreterMacroAssembler::dispatch_via(TosState state, address* table) {79// Load current bytecode.80Register bytecode = R12_scratch2;81lbz(bytecode, 0, R14_bcp);82dispatch_Lbyte_code(state, bytecode, table);83}8485// Dispatch code executed in the prolog of a bytecode which does not do it's86// own dispatch. The dispatch address is computed and placed in R24_dispatch_addr.87void InterpreterMacroAssembler::dispatch_prolog(TosState state, int bcp_incr) {88Register bytecode = R12_scratch2;89lbz(bytecode, bcp_incr, R14_bcp);9091load_dispatch_table(R24_dispatch_addr, Interpreter::dispatch_table(state));9293sldi(bytecode, bytecode, LogBytesPerWord);94ldx(R24_dispatch_addr, R24_dispatch_addr, bytecode);95}9697// Dispatch code executed in the epilog of a bytecode which does not do it's98// own dispatch. The dispatch address in R24_dispatch_addr is used for the99// dispatch.100void InterpreterMacroAssembler::dispatch_epilog(TosState state, int bcp_incr) {101if (bcp_incr) { addi(R14_bcp, R14_bcp, bcp_incr); }102mtctr(R24_dispatch_addr);103bcctr(bcondAlways, 0, bhintbhBCCTRisNotPredictable);104}105106void InterpreterMacroAssembler::check_and_handle_popframe(Register scratch_reg) {107assert(scratch_reg != R0, "can't use R0 as scratch_reg here");108if (JvmtiExport::can_pop_frame()) {109Label L;110111// Check the "pending popframe condition" flag in the current thread.112lwz(scratch_reg, in_bytes(JavaThread::popframe_condition_offset()), R16_thread);113114// Initiate popframe handling only if it is not already being115// processed. If the flag has the popframe_processing bit set, it116// means that this code is called *during* popframe handling - we117// don't want to reenter.118andi_(R0, scratch_reg, JavaThread::popframe_pending_bit);119beq(CCR0, L);120121andi_(R0, scratch_reg, JavaThread::popframe_processing_bit);122bne(CCR0, L);123124// Call the Interpreter::remove_activation_preserving_args_entry()125// func to get the address of the same-named entrypoint in the126// generated interpreter code.127#if defined(ABI_ELFv2)128call_c(CAST_FROM_FN_PTR(address,129Interpreter::remove_activation_preserving_args_entry),130relocInfo::none);131#else132call_c(CAST_FROM_FN_PTR(FunctionDescriptor*,133Interpreter::remove_activation_preserving_args_entry),134relocInfo::none);135#endif136137// Jump to Interpreter::_remove_activation_preserving_args_entry.138mtctr(R3_RET);139bctr();140141align(32, 12);142bind(L);143}144}145146void InterpreterMacroAssembler::check_and_handle_earlyret(Register scratch_reg) {147const Register Rthr_state_addr = scratch_reg;148if (JvmtiExport::can_force_early_return()) {149Label Lno_early_ret;150ld(Rthr_state_addr, in_bytes(JavaThread::jvmti_thread_state_offset()), R16_thread);151cmpdi(CCR0, Rthr_state_addr, 0);152beq(CCR0, Lno_early_ret);153154lwz(R0, in_bytes(JvmtiThreadState::earlyret_state_offset()), Rthr_state_addr);155cmpwi(CCR0, R0, JvmtiThreadState::earlyret_pending);156bne(CCR0, Lno_early_ret);157158// Jump to Interpreter::_earlyret_entry.159lwz(R3_ARG1, in_bytes(JvmtiThreadState::earlyret_tos_offset()), Rthr_state_addr);160call_VM_leaf(CAST_FROM_FN_PTR(address, Interpreter::remove_activation_early_entry));161mtlr(R3_RET);162blr();163164align(32, 12);165bind(Lno_early_ret);166}167}168169void InterpreterMacroAssembler::load_earlyret_value(TosState state, Register Rscratch1) {170const Register RjvmtiState = Rscratch1;171const Register Rscratch2 = R0;172173ld(RjvmtiState, in_bytes(JavaThread::jvmti_thread_state_offset()), R16_thread);174li(Rscratch2, 0);175176switch (state) {177case atos: ld(R17_tos, in_bytes(JvmtiThreadState::earlyret_oop_offset()), RjvmtiState);178std(Rscratch2, in_bytes(JvmtiThreadState::earlyret_oop_offset()), RjvmtiState);179break;180case ltos: ld(R17_tos, in_bytes(JvmtiThreadState::earlyret_value_offset()), RjvmtiState);181break;182case btos: // fall through183case ztos: // fall through184case ctos: // fall through185case stos: // fall through186case itos: lwz(R17_tos, in_bytes(JvmtiThreadState::earlyret_value_offset()), RjvmtiState);187break;188case ftos: lfs(F15_ftos, in_bytes(JvmtiThreadState::earlyret_value_offset()), RjvmtiState);189break;190case dtos: lfd(F15_ftos, in_bytes(JvmtiThreadState::earlyret_value_offset()), RjvmtiState);191break;192case vtos: break;193default : ShouldNotReachHere();194}195196// Clean up tos value in the jvmti thread state.197std(Rscratch2, in_bytes(JvmtiThreadState::earlyret_value_offset()), RjvmtiState);198// Set tos state field to illegal value.199li(Rscratch2, ilgl);200stw(Rscratch2, in_bytes(JvmtiThreadState::earlyret_tos_offset()), RjvmtiState);201}202203// Common code to dispatch and dispatch_only.204// Dispatch value in Lbyte_code and increment Lbcp.205206void InterpreterMacroAssembler::load_dispatch_table(Register dst, address* table) {207address table_base = (address)Interpreter::dispatch_table((TosState)0);208intptr_t table_offs = (intptr_t)table - (intptr_t)table_base;209if (is_simm16(table_offs)) {210addi(dst, R25_templateTableBase, (int)table_offs);211} else {212load_const_optimized(dst, table, R0);213}214}215216void InterpreterMacroAssembler::dispatch_Lbyte_code(TosState state, Register bytecode,217address* table, bool generate_poll) {218assert_different_registers(bytecode, R11_scratch1);219220// Calc dispatch table address.221load_dispatch_table(R11_scratch1, table);222223if (generate_poll) {224address *sfpt_tbl = Interpreter::safept_table(state);225if (table != sfpt_tbl) {226Label dispatch;227ld(R0, in_bytes(JavaThread::polling_word_offset()), R16_thread);228// Armed page has poll_bit set, if poll bit is cleared just continue.229andi_(R0, R0, SafepointMechanism::poll_bit());230beq(CCR0, dispatch);231load_dispatch_table(R11_scratch1, sfpt_tbl);232align(32, 16);233bind(dispatch);234}235}236237sldi(R12_scratch2, bytecode, LogBytesPerWord);238ldx(R11_scratch1, R11_scratch1, R12_scratch2);239240// Jump off!241mtctr(R11_scratch1);242bcctr(bcondAlways, 0, bhintbhBCCTRisNotPredictable);243}244245void InterpreterMacroAssembler::load_receiver(Register Rparam_count, Register Rrecv_dst) {246sldi(Rrecv_dst, Rparam_count, Interpreter::logStackElementSize);247ldx(Rrecv_dst, Rrecv_dst, R15_esp);248}249250// helpers for expression stack251252void InterpreterMacroAssembler::pop_i(Register r) {253lwzu(r, Interpreter::stackElementSize, R15_esp);254}255256void InterpreterMacroAssembler::pop_ptr(Register r) {257ldu(r, Interpreter::stackElementSize, R15_esp);258}259260void InterpreterMacroAssembler::pop_l(Register r) {261ld(r, Interpreter::stackElementSize, R15_esp);262addi(R15_esp, R15_esp, 2 * Interpreter::stackElementSize);263}264265void InterpreterMacroAssembler::pop_f(FloatRegister f) {266lfsu(f, Interpreter::stackElementSize, R15_esp);267}268269void InterpreterMacroAssembler::pop_d(FloatRegister f) {270lfd(f, Interpreter::stackElementSize, R15_esp);271addi(R15_esp, R15_esp, 2 * Interpreter::stackElementSize);272}273274void InterpreterMacroAssembler::push_i(Register r) {275stw(r, 0, R15_esp);276addi(R15_esp, R15_esp, - Interpreter::stackElementSize );277}278279void InterpreterMacroAssembler::push_ptr(Register r) {280std(r, 0, R15_esp);281addi(R15_esp, R15_esp, - Interpreter::stackElementSize );282}283284void InterpreterMacroAssembler::push_l(Register r) {285// Clear unused slot.286load_const_optimized(R0, 0L);287std(R0, 0, R15_esp);288std(r, - Interpreter::stackElementSize, R15_esp);289addi(R15_esp, R15_esp, - 2 * Interpreter::stackElementSize );290}291292void InterpreterMacroAssembler::push_f(FloatRegister f) {293stfs(f, 0, R15_esp);294addi(R15_esp, R15_esp, - Interpreter::stackElementSize );295}296297void InterpreterMacroAssembler::push_d(FloatRegister f) {298stfd(f, - Interpreter::stackElementSize, R15_esp);299addi(R15_esp, R15_esp, - 2 * Interpreter::stackElementSize );300}301302void InterpreterMacroAssembler::push_2ptrs(Register first, Register second) {303std(first, 0, R15_esp);304std(second, -Interpreter::stackElementSize, R15_esp);305addi(R15_esp, R15_esp, - 2 * Interpreter::stackElementSize );306}307308void InterpreterMacroAssembler::move_l_to_d(Register l, FloatRegister d) {309if (VM_Version::has_mtfprd()) {310mtfprd(d, l);311} else {312std(l, 0, R15_esp);313lfd(d, 0, R15_esp);314}315}316317void InterpreterMacroAssembler::move_d_to_l(FloatRegister d, Register l) {318if (VM_Version::has_mtfprd()) {319mffprd(l, d);320} else {321stfd(d, 0, R15_esp);322ld(l, 0, R15_esp);323}324}325326void InterpreterMacroAssembler::push(TosState state) {327switch (state) {328case atos: push_ptr(); break;329case btos:330case ztos:331case ctos:332case stos:333case itos: push_i(); break;334case ltos: push_l(); break;335case ftos: push_f(); break;336case dtos: push_d(); break;337case vtos: /* nothing to do */ break;338default : ShouldNotReachHere();339}340}341342void InterpreterMacroAssembler::pop(TosState state) {343switch (state) {344case atos: pop_ptr(); break;345case btos:346case ztos:347case ctos:348case stos:349case itos: pop_i(); break;350case ltos: pop_l(); break;351case ftos: pop_f(); break;352case dtos: pop_d(); break;353case vtos: /* nothing to do */ break;354default : ShouldNotReachHere();355}356verify_oop(R17_tos, state);357}358359void InterpreterMacroAssembler::empty_expression_stack() {360addi(R15_esp, R26_monitor, - Interpreter::stackElementSize);361}362363void InterpreterMacroAssembler::get_2_byte_integer_at_bcp(int bcp_offset,364Register Rdst,365signedOrNot is_signed) {366#if defined(VM_LITTLE_ENDIAN)367if (bcp_offset) {368load_const_optimized(Rdst, bcp_offset);369lhbrx(Rdst, R14_bcp, Rdst);370} else {371lhbrx(Rdst, R14_bcp);372}373if (is_signed == Signed) {374extsh(Rdst, Rdst);375}376#else377// Read Java big endian format.378if (is_signed == Signed) {379lha(Rdst, bcp_offset, R14_bcp);380} else {381lhz(Rdst, bcp_offset, R14_bcp);382}383#endif384}385386void InterpreterMacroAssembler::get_4_byte_integer_at_bcp(int bcp_offset,387Register Rdst,388signedOrNot is_signed) {389#if defined(VM_LITTLE_ENDIAN)390if (bcp_offset) {391load_const_optimized(Rdst, bcp_offset);392lwbrx(Rdst, R14_bcp, Rdst);393} else {394lwbrx(Rdst, R14_bcp);395}396if (is_signed == Signed) {397extsw(Rdst, Rdst);398}399#else400// Read Java big endian format.401if (bcp_offset & 3) { // Offset unaligned?402load_const_optimized(Rdst, bcp_offset);403if (is_signed == Signed) {404lwax(Rdst, R14_bcp, Rdst);405} else {406lwzx(Rdst, R14_bcp, Rdst);407}408} else {409if (is_signed == Signed) {410lwa(Rdst, bcp_offset, R14_bcp);411} else {412lwz(Rdst, bcp_offset, R14_bcp);413}414}415#endif416}417418419// Load the constant pool cache index from the bytecode stream.420//421// Kills / writes:422// - Rdst, Rscratch423void InterpreterMacroAssembler::get_cache_index_at_bcp(Register Rdst, int bcp_offset,424size_t index_size) {425assert(bcp_offset > 0, "bcp is still pointing to start of bytecode");426// Cache index is always in the native format, courtesy of Rewriter.427if (index_size == sizeof(u2)) {428lhz(Rdst, bcp_offset, R14_bcp);429} else if (index_size == sizeof(u4)) {430if (bcp_offset & 3) {431load_const_optimized(Rdst, bcp_offset);432lwax(Rdst, R14_bcp, Rdst);433} else {434lwa(Rdst, bcp_offset, R14_bcp);435}436assert(ConstantPool::decode_invokedynamic_index(~123) == 123, "else change next line");437nand(Rdst, Rdst, Rdst); // convert to plain index438} else if (index_size == sizeof(u1)) {439lbz(Rdst, bcp_offset, R14_bcp);440} else {441ShouldNotReachHere();442}443// Rdst now contains cp cache index.444}445446void InterpreterMacroAssembler::get_cache_and_index_at_bcp(Register cache, int bcp_offset,447size_t index_size) {448get_cache_index_at_bcp(cache, bcp_offset, index_size);449sldi(cache, cache, exact_log2(in_words(ConstantPoolCacheEntry::size()) * BytesPerWord));450add(cache, R27_constPoolCache, cache);451}452453// Load 4-byte signed or unsigned integer in Java format (that is, big-endian format)454// from (Rsrc)+offset.455void InterpreterMacroAssembler::get_u4(Register Rdst, Register Rsrc, int offset,456signedOrNot is_signed) {457#if defined(VM_LITTLE_ENDIAN)458if (offset) {459load_const_optimized(Rdst, offset);460lwbrx(Rdst, Rdst, Rsrc);461} else {462lwbrx(Rdst, Rsrc);463}464if (is_signed == Signed) {465extsw(Rdst, Rdst);466}467#else468if (is_signed == Signed) {469lwa(Rdst, offset, Rsrc);470} else {471lwz(Rdst, offset, Rsrc);472}473#endif474}475476// Load object from cpool->resolved_references(index).477// Kills:478// - index479void InterpreterMacroAssembler::load_resolved_reference_at_index(Register result, Register index,480Register tmp1, Register tmp2,481Label *L_handle_null) {482assert_different_registers(result, index, tmp1, tmp2);483assert(index->is_nonvolatile(), "needs to survive C-call in resolve_oop_handle");484get_constant_pool(result);485486// Convert from field index to resolved_references() index and from487// word index to byte offset. Since this is a java object, it can be compressed.488sldi(index, index, LogBytesPerHeapOop);489// Load pointer for resolved_references[] objArray.490ld(result, ConstantPool::cache_offset_in_bytes(), result);491ld(result, ConstantPoolCache::resolved_references_offset_in_bytes(), result);492resolve_oop_handle(result, tmp1, tmp2, MacroAssembler::PRESERVATION_NONE);493#ifdef ASSERT494Label index_ok;495lwa(R0, arrayOopDesc::length_offset_in_bytes(), result);496sldi(R0, R0, LogBytesPerHeapOop);497cmpd(CCR0, index, R0);498blt(CCR0, index_ok);499stop("resolved reference index out of bounds");500bind(index_ok);501#endif502// Add in the index.503add(result, index, result);504load_heap_oop(result, arrayOopDesc::base_offset_in_bytes(T_OBJECT), result,505tmp1, tmp2,506MacroAssembler::PRESERVATION_NONE,5070, L_handle_null);508}509510// load cpool->resolved_klass_at(index)511void InterpreterMacroAssembler::load_resolved_klass_at_offset(Register Rcpool, Register Roffset, Register Rklass) {512// int value = *(Rcpool->int_at_addr(which));513// int resolved_klass_index = extract_low_short_from_int(value);514add(Roffset, Rcpool, Roffset);515#if defined(VM_LITTLE_ENDIAN)516lhz(Roffset, sizeof(ConstantPool), Roffset); // Roffset = resolved_klass_index517#else518lhz(Roffset, sizeof(ConstantPool) + 2, Roffset); // Roffset = resolved_klass_index519#endif520521ld(Rklass, ConstantPool::resolved_klasses_offset_in_bytes(), Rcpool); // Rklass = Rcpool->_resolved_klasses522523sldi(Roffset, Roffset, LogBytesPerWord);524addi(Roffset, Roffset, Array<Klass*>::base_offset_in_bytes());525isync(); // Order load of instance Klass wrt. tags.526ldx(Rklass, Rklass, Roffset);527}528529void InterpreterMacroAssembler::load_resolved_method_at_index(int byte_no,530Register cache,531Register method) {532const int method_offset = in_bytes(533ConstantPoolCache::base_offset() +534((byte_no == TemplateTable::f2_byte)535? ConstantPoolCacheEntry::f2_offset()536: ConstantPoolCacheEntry::f1_offset()));537538ld(method, method_offset, cache); // get f1 Method*539}540541// Generate a subtype check: branch to ok_is_subtype if sub_klass is542// a subtype of super_klass. Blows registers Rsub_klass, tmp1, tmp2.543void InterpreterMacroAssembler::gen_subtype_check(Register Rsub_klass, Register Rsuper_klass, Register Rtmp1,544Register Rtmp2, Register Rtmp3, Label &ok_is_subtype) {545// Profile the not-null value's klass.546profile_typecheck(Rsub_klass, Rtmp1, Rtmp2);547check_klass_subtype(Rsub_klass, Rsuper_klass, Rtmp1, Rtmp2, ok_is_subtype);548profile_typecheck_failed(Rtmp1, Rtmp2);549}550551// Separate these two to allow for delay slot in middle.552// These are used to do a test and full jump to exception-throwing code.553554// Check that index is in range for array, then shift index by index_shift,555// and put arrayOop + shifted_index into res.556// Note: res is still shy of address by array offset into object.557558void InterpreterMacroAssembler::index_check_without_pop(Register Rarray, Register Rindex,559int index_shift, Register Rtmp, Register Rres) {560// Check that index is in range for array, then shift index by index_shift,561// and put arrayOop + shifted_index into res.562// Note: res is still shy of address by array offset into object.563// Kills:564// - Rindex565// Writes:566// - Rres: Address that corresponds to the array index if check was successful.567verify_oop(Rarray);568const Register Rlength = R0;569const Register RsxtIndex = Rtmp;570Label LisNull, LnotOOR;571572// Array nullcheck573if (!ImplicitNullChecks) {574cmpdi(CCR0, Rarray, 0);575beq(CCR0, LisNull);576} else {577null_check_throw(Rarray, arrayOopDesc::length_offset_in_bytes(), /*temp*/RsxtIndex);578}579580// Rindex might contain garbage in upper bits (remember that we don't sign extend581// during integer arithmetic operations). So kill them and put value into same register582// where ArrayIndexOutOfBounds would expect the index in.583rldicl(RsxtIndex, Rindex, 0, 32); // zero extend 32 bit -> 64 bit584585// Index check586lwz(Rlength, arrayOopDesc::length_offset_in_bytes(), Rarray);587cmplw(CCR0, Rindex, Rlength);588sldi(RsxtIndex, RsxtIndex, index_shift);589blt(CCR0, LnotOOR);590// Index should be in R17_tos, array should be in R4_ARG2.591mr_if_needed(R17_tos, Rindex);592mr_if_needed(R4_ARG2, Rarray);593load_dispatch_table(Rtmp, (address*)Interpreter::_throw_ArrayIndexOutOfBoundsException_entry);594mtctr(Rtmp);595bctr();596597if (!ImplicitNullChecks) {598bind(LisNull);599load_dispatch_table(Rtmp, (address*)Interpreter::_throw_NullPointerException_entry);600mtctr(Rtmp);601bctr();602}603604align(32, 16);605bind(LnotOOR);606607// Calc address608add(Rres, RsxtIndex, Rarray);609}610611void InterpreterMacroAssembler::index_check(Register array, Register index,612int index_shift, Register tmp, Register res) {613// pop array614pop_ptr(array);615616// check array617index_check_without_pop(array, index, index_shift, tmp, res);618}619620void InterpreterMacroAssembler::get_const(Register Rdst) {621ld(Rdst, in_bytes(Method::const_offset()), R19_method);622}623624void InterpreterMacroAssembler::get_constant_pool(Register Rdst) {625get_const(Rdst);626ld(Rdst, in_bytes(ConstMethod::constants_offset()), Rdst);627}628629void InterpreterMacroAssembler::get_constant_pool_cache(Register Rdst) {630get_constant_pool(Rdst);631ld(Rdst, ConstantPool::cache_offset_in_bytes(), Rdst);632}633634void InterpreterMacroAssembler::get_cpool_and_tags(Register Rcpool, Register Rtags) {635get_constant_pool(Rcpool);636ld(Rtags, ConstantPool::tags_offset_in_bytes(), Rcpool);637}638639// Unlock if synchronized method.640//641// Unlock the receiver if this is a synchronized method.642// Unlock any Java monitors from synchronized blocks.643//644// If there are locked Java monitors645// If throw_monitor_exception646// throws IllegalMonitorStateException647// Else if install_monitor_exception648// installs IllegalMonitorStateException649// Else650// no error processing651void InterpreterMacroAssembler::unlock_if_synchronized_method(TosState state,652bool throw_monitor_exception,653bool install_monitor_exception) {654Label Lunlocked, Lno_unlock;655{656Register Rdo_not_unlock_flag = R11_scratch1;657Register Raccess_flags = R12_scratch2;658659// Check if synchronized method or unlocking prevented by660// JavaThread::do_not_unlock_if_synchronized flag.661lbz(Rdo_not_unlock_flag, in_bytes(JavaThread::do_not_unlock_if_synchronized_offset()), R16_thread);662lwz(Raccess_flags, in_bytes(Method::access_flags_offset()), R19_method);663li(R0, 0);664stb(R0, in_bytes(JavaThread::do_not_unlock_if_synchronized_offset()), R16_thread); // reset flag665666push(state);667668// Skip if we don't have to unlock.669rldicl_(R0, Raccess_flags, 64-JVM_ACC_SYNCHRONIZED_BIT, 63); // Extract bit and compare to 0.670beq(CCR0, Lunlocked);671672cmpwi(CCR0, Rdo_not_unlock_flag, 0);673bne(CCR0, Lno_unlock);674}675676// Unlock677{678Register Rmonitor_base = R11_scratch1;679680Label Lunlock;681// If it's still locked, everything is ok, unlock it.682ld(Rmonitor_base, 0, R1_SP);683addi(Rmonitor_base, Rmonitor_base,684-(frame::ijava_state_size + frame::interpreter_frame_monitor_size_in_bytes())); // Monitor base685686ld(R0, BasicObjectLock::obj_offset_in_bytes(), Rmonitor_base);687cmpdi(CCR0, R0, 0);688bne(CCR0, Lunlock);689690// If it's already unlocked, throw exception.691if (throw_monitor_exception) {692call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_illegal_monitor_state_exception));693should_not_reach_here();694} else {695if (install_monitor_exception) {696call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::new_illegal_monitor_state_exception));697b(Lunlocked);698}699}700701bind(Lunlock);702unlock_object(Rmonitor_base);703}704705// Check that all other monitors are unlocked. Throw IllegelMonitorState exception if not.706bind(Lunlocked);707{708Label Lexception, Lrestart;709Register Rcurrent_obj_addr = R11_scratch1;710const int delta = frame::interpreter_frame_monitor_size_in_bytes();711assert((delta & LongAlignmentMask) == 0, "sizeof BasicObjectLock must be even number of doublewords");712713bind(Lrestart);714// Set up search loop: Calc num of iterations.715{716Register Riterations = R12_scratch2;717Register Rmonitor_base = Rcurrent_obj_addr;718ld(Rmonitor_base, 0, R1_SP);719addi(Rmonitor_base, Rmonitor_base, - frame::ijava_state_size); // Monitor base720721subf_(Riterations, R26_monitor, Rmonitor_base);722ble(CCR0, Lno_unlock);723724addi(Rcurrent_obj_addr, Rmonitor_base,725BasicObjectLock::obj_offset_in_bytes() - frame::interpreter_frame_monitor_size_in_bytes());726// Check if any monitor is on stack, bail out if not727srdi(Riterations, Riterations, exact_log2(delta));728mtctr(Riterations);729}730731// The search loop: Look for locked monitors.732{733const Register Rcurrent_obj = R0;734Label Lloop;735736ld(Rcurrent_obj, 0, Rcurrent_obj_addr);737addi(Rcurrent_obj_addr, Rcurrent_obj_addr, -delta);738bind(Lloop);739740// Check if current entry is used.741cmpdi(CCR0, Rcurrent_obj, 0);742bne(CCR0, Lexception);743// Preload next iteration's compare value.744ld(Rcurrent_obj, 0, Rcurrent_obj_addr);745addi(Rcurrent_obj_addr, Rcurrent_obj_addr, -delta);746bdnz(Lloop);747}748// Fell through: Everything's unlocked => finish.749b(Lno_unlock);750751// An object is still locked => need to throw exception.752bind(Lexception);753if (throw_monitor_exception) {754call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_illegal_monitor_state_exception));755should_not_reach_here();756} else {757// Stack unrolling. Unlock object and if requested, install illegal_monitor_exception.758// Unlock does not block, so don't have to worry about the frame.759Register Rmonitor_addr = R11_scratch1;760addi(Rmonitor_addr, Rcurrent_obj_addr, -BasicObjectLock::obj_offset_in_bytes() + delta);761unlock_object(Rmonitor_addr);762if (install_monitor_exception) {763call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::new_illegal_monitor_state_exception));764}765b(Lrestart);766}767}768769align(32, 12);770bind(Lno_unlock);771pop(state);772}773774// Support function for remove_activation & Co.775void InterpreterMacroAssembler::merge_frames(Register Rsender_sp, Register return_pc,776Register Rscratch1, Register Rscratch2) {777// Pop interpreter frame.778ld(Rscratch1, 0, R1_SP); // *SP779ld(Rsender_sp, _ijava_state_neg(sender_sp), Rscratch1); // top_frame_sp780ld(Rscratch2, 0, Rscratch1); // **SP781if (return_pc!=noreg) {782ld(return_pc, _abi0(lr), Rscratch1); // LR783}784785// Merge top frames.786subf(Rscratch1, R1_SP, Rsender_sp); // top_frame_sp - SP787stdux(Rscratch2, R1_SP, Rscratch1); // atomically set *(SP = top_frame_sp) = **SP788}789790void InterpreterMacroAssembler::narrow(Register result) {791Register ret_type = R11_scratch1;792ld(R11_scratch1, in_bytes(Method::const_offset()), R19_method);793lbz(ret_type, in_bytes(ConstMethod::result_type_offset()), R11_scratch1);794795Label notBool, notByte, notChar, done;796797// common case first798cmpwi(CCR0, ret_type, T_INT);799beq(CCR0, done);800801cmpwi(CCR0, ret_type, T_BOOLEAN);802bne(CCR0, notBool);803andi(result, result, 0x1);804b(done);805806bind(notBool);807cmpwi(CCR0, ret_type, T_BYTE);808bne(CCR0, notByte);809extsb(result, result);810b(done);811812bind(notByte);813cmpwi(CCR0, ret_type, T_CHAR);814bne(CCR0, notChar);815andi(result, result, 0xffff);816b(done);817818bind(notChar);819// cmpwi(CCR0, ret_type, T_SHORT); // all that's left820// bne(CCR0, done);821extsh(result, result);822823// Nothing to do for T_INT824bind(done);825}826827// Remove activation.828//829// Apply stack watermark barrier.830// Unlock the receiver if this is a synchronized method.831// Unlock any Java monitors from synchronized blocks.832// Remove the activation from the stack.833//834// If there are locked Java monitors835// If throw_monitor_exception836// throws IllegalMonitorStateException837// Else if install_monitor_exception838// installs IllegalMonitorStateException839// Else840// no error processing841void InterpreterMacroAssembler::remove_activation(TosState state,842bool throw_monitor_exception,843bool install_monitor_exception) {844BLOCK_COMMENT("remove_activation {");845846// The below poll is for the stack watermark barrier. It allows fixing up frames lazily,847// that would normally not be safe to use. Such bad returns into unsafe territory of848// the stack, will call InterpreterRuntime::at_unwind.849Label slow_path;850Label fast_path;851safepoint_poll(slow_path, R11_scratch1, true /* at_return */, false /* in_nmethod */);852b(fast_path);853bind(slow_path);854push(state);855set_last_Java_frame(R1_SP, noreg);856call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::at_unwind), R16_thread);857reset_last_Java_frame();858pop(state);859align(32);860bind(fast_path);861862unlock_if_synchronized_method(state, throw_monitor_exception, install_monitor_exception);863864// Save result (push state before jvmti call and pop it afterwards) and notify jvmti.865notify_method_exit(false, state, NotifyJVMTI, true);866867BLOCK_COMMENT("reserved_stack_check:");868if (StackReservedPages > 0) {869// Test if reserved zone needs to be enabled.870Label no_reserved_zone_enabling;871872// Compare frame pointers. There is no good stack pointer, as with stack873// frame compression we can get different SPs when we do calls. A subsequent874// call could have a smaller SP, so that this compare succeeds for an875// inner call of the method annotated with ReservedStack.876ld_ptr(R0, JavaThread::reserved_stack_activation_offset(), R16_thread);877ld_ptr(R11_scratch1, _abi0(callers_sp), R1_SP); // Load frame pointer.878cmpld(CCR0, R11_scratch1, R0);879blt_predict_taken(CCR0, no_reserved_zone_enabling);880881// Enable reserved zone again, throw stack overflow exception.882call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::enable_stack_reserved_zone), R16_thread);883call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_delayed_StackOverflowError));884885should_not_reach_here();886887bind(no_reserved_zone_enabling);888}889890verify_oop(R17_tos, state);891verify_thread();892893merge_frames(/*top_frame_sp*/ R21_sender_SP, /*return_pc*/ R0, R11_scratch1, R12_scratch2);894mtlr(R0);895BLOCK_COMMENT("} remove_activation");896}897898// Lock object899//900// Registers alive901// monitor - Address of the BasicObjectLock to be used for locking,902// which must be initialized with the object to lock.903// object - Address of the object to be locked.904//905void InterpreterMacroAssembler::lock_object(Register monitor, Register object) {906if (UseHeavyMonitors) {907call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorenter), monitor);908} else {909// template code:910//911// markWord displaced_header = obj->mark().set_unlocked();912// monitor->lock()->set_displaced_header(displaced_header);913// if (Atomic::cmpxchg(/*addr*/obj->mark_addr(), /*cmp*/displaced_header, /*ex=*/monitor) == displaced_header) {914// // We stored the monitor address into the object's mark word.915// } else if (THREAD->is_lock_owned((address)displaced_header))916// // Simple recursive case.917// monitor->lock()->set_displaced_header(NULL);918// } else {919// // Slow path.920// InterpreterRuntime::monitorenter(THREAD, monitor);921// }922923const Register displaced_header = R7_ARG5;924const Register object_mark_addr = R8_ARG6;925const Register current_header = R9_ARG7;926const Register tmp = R10_ARG8;927928Label done;929Label cas_failed, slow_case;930931assert_different_registers(displaced_header, object_mark_addr, current_header, tmp);932933// markWord displaced_header = obj->mark().set_unlocked();934935// Load markWord from object into displaced_header.936ld(displaced_header, oopDesc::mark_offset_in_bytes(), object);937938if (DiagnoseSyncOnValueBasedClasses != 0) {939load_klass(tmp, object);940lwz(tmp, in_bytes(Klass::access_flags_offset()), tmp);941testbitdi(CCR0, R0, tmp, exact_log2(JVM_ACC_IS_VALUE_BASED_CLASS));942bne(CCR0, slow_case);943}944945if (UseBiasedLocking) {946biased_locking_enter(CCR0, object, displaced_header, tmp, current_header, done, &slow_case);947}948949// Set displaced_header to be (markWord of object | UNLOCK_VALUE).950ori(displaced_header, displaced_header, markWord::unlocked_value);951952// monitor->lock()->set_displaced_header(displaced_header);953954// Initialize the box (Must happen before we update the object mark!).955std(displaced_header, BasicObjectLock::lock_offset_in_bytes() +956BasicLock::displaced_header_offset_in_bytes(), monitor);957958// if (Atomic::cmpxchg(/*addr*/obj->mark_addr(), /*cmp*/displaced_header, /*ex=*/monitor) == displaced_header) {959960// Store stack address of the BasicObjectLock (this is monitor) into object.961addi(object_mark_addr, object, oopDesc::mark_offset_in_bytes());962963// Must fence, otherwise, preceding store(s) may float below cmpxchg.964// CmpxchgX sets CCR0 to cmpX(current, displaced).965cmpxchgd(/*flag=*/CCR0,966/*current_value=*/current_header,967/*compare_value=*/displaced_header, /*exchange_value=*/monitor,968/*where=*/object_mark_addr,969MacroAssembler::MemBarRel | MacroAssembler::MemBarAcq,970MacroAssembler::cmpxchgx_hint_acquire_lock(),971noreg,972&cas_failed,973/*check without membar and ldarx first*/true);974975// If the compare-and-exchange succeeded, then we found an unlocked976// object and we have now locked it.977b(done);978bind(cas_failed);979980// } else if (THREAD->is_lock_owned((address)displaced_header))981// // Simple recursive case.982// monitor->lock()->set_displaced_header(NULL);983984// We did not see an unlocked object so try the fast recursive case.985986// Check if owner is self by comparing the value in the markWord of object987// (current_header) with the stack pointer.988sub(current_header, current_header, R1_SP);989990assert(os::vm_page_size() > 0xfff, "page size too small - change the constant");991load_const_optimized(tmp, ~(os::vm_page_size()-1) | markWord::lock_mask_in_place);992993and_(R0/*==0?*/, current_header, tmp);994// If condition is true we are done and hence we can store 0 in the displaced995// header indicating it is a recursive lock.996bne(CCR0, slow_case);997std(R0/*==0!*/, BasicObjectLock::lock_offset_in_bytes() +998BasicLock::displaced_header_offset_in_bytes(), monitor);999b(done);10001001// } else {1002// // Slow path.1003// InterpreterRuntime::monitorenter(THREAD, monitor);10041005// None of the above fast optimizations worked so we have to get into the1006// slow case of monitor enter.1007bind(slow_case);1008call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorenter), monitor);1009// }1010align(32, 12);1011bind(done);1012}1013}10141015// Unlocks an object. Used in monitorexit bytecode and remove_activation.1016//1017// Registers alive1018// monitor - Address of the BasicObjectLock to be used for locking,1019// which must be initialized with the object to lock.1020//1021// Throw IllegalMonitorException if object is not locked by current thread.1022void InterpreterMacroAssembler::unlock_object(Register monitor) {1023if (UseHeavyMonitors) {1024call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorexit), monitor);1025} else {10261027// template code:1028//1029// if ((displaced_header = monitor->displaced_header()) == NULL) {1030// // Recursive unlock. Mark the monitor unlocked by setting the object field to NULL.1031// monitor->set_obj(NULL);1032// } else if (Atomic::cmpxchg(obj->mark_addr(), monitor, displaced_header) == monitor) {1033// // We swapped the unlocked mark in displaced_header into the object's mark word.1034// monitor->set_obj(NULL);1035// } else {1036// // Slow path.1037// InterpreterRuntime::monitorexit(monitor);1038// }10391040const Register object = R7_ARG5;1041const Register displaced_header = R8_ARG6;1042const Register object_mark_addr = R9_ARG7;1043const Register current_header = R10_ARG8;10441045Label free_slot;1046Label slow_case;10471048assert_different_registers(object, displaced_header, object_mark_addr, current_header);10491050if (UseBiasedLocking) {1051// The object address from the monitor is in object.1052ld(object, BasicObjectLock::obj_offset_in_bytes(), monitor);1053assert(oopDesc::mark_offset_in_bytes() == 0, "offset of _mark is not 0");1054biased_locking_exit(CCR0, object, displaced_header, free_slot);1055}10561057// Test first if we are in the fast recursive case.1058ld(displaced_header, BasicObjectLock::lock_offset_in_bytes() +1059BasicLock::displaced_header_offset_in_bytes(), monitor);10601061// If the displaced header is zero, we have a recursive unlock.1062cmpdi(CCR0, displaced_header, 0);1063beq(CCR0, free_slot); // recursive unlock10641065// } else if (Atomic::cmpxchg(obj->mark_addr(), monitor, displaced_header) == monitor) {1066// // We swapped the unlocked mark in displaced_header into the object's mark word.1067// monitor->set_obj(NULL);10681069// If we still have a lightweight lock, unlock the object and be done.10701071// The object address from the monitor is in object.1072if (!UseBiasedLocking) { ld(object, BasicObjectLock::obj_offset_in_bytes(), monitor); }1073addi(object_mark_addr, object, oopDesc::mark_offset_in_bytes());10741075// We have the displaced header in displaced_header. If the lock is still1076// lightweight, it will contain the monitor address and we'll store the1077// displaced header back into the object's mark word.1078// CmpxchgX sets CCR0 to cmpX(current, monitor).1079cmpxchgd(/*flag=*/CCR0,1080/*current_value=*/current_header,1081/*compare_value=*/monitor, /*exchange_value=*/displaced_header,1082/*where=*/object_mark_addr,1083MacroAssembler::MemBarRel,1084MacroAssembler::cmpxchgx_hint_release_lock(),1085noreg,1086&slow_case);1087b(free_slot);10881089// } else {1090// // Slow path.1091// InterpreterRuntime::monitorexit(monitor);10921093// The lock has been converted into a heavy lock and hence1094// we need to get into the slow case.1095bind(slow_case);1096call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorexit), monitor);1097// }10981099Label done;1100b(done); // Monitor register may be overwritten! Runtime has already freed the slot.11011102// Exchange worked, do monitor->set_obj(NULL);1103align(32, 12);1104bind(free_slot);1105li(R0, 0);1106std(R0, BasicObjectLock::obj_offset_in_bytes(), monitor);1107bind(done);1108}1109}11101111// Load compiled (i2c) or interpreter entry when calling from interpreted and1112// do the call. Centralized so that all interpreter calls will do the same actions.1113// If jvmti single stepping is on for a thread we must not call compiled code.1114//1115// Input:1116// - Rtarget_method: method to call1117// - Rret_addr: return address1118// - 2 scratch regs1119//1120void InterpreterMacroAssembler::call_from_interpreter(Register Rtarget_method, Register Rret_addr,1121Register Rscratch1, Register Rscratch2) {1122assert_different_registers(Rscratch1, Rscratch2, Rtarget_method, Rret_addr);1123// Assume we want to go compiled if available.1124const Register Rtarget_addr = Rscratch1;1125const Register Rinterp_only = Rscratch2;11261127ld(Rtarget_addr, in_bytes(Method::from_interpreted_offset()), Rtarget_method);11281129if (JvmtiExport::can_post_interpreter_events()) {1130lwz(Rinterp_only, in_bytes(JavaThread::interp_only_mode_offset()), R16_thread);11311132// JVMTI events, such as single-stepping, are implemented partly by avoiding running1133// compiled code in threads for which the event is enabled. Check here for1134// interp_only_mode if these events CAN be enabled.1135Label done;1136verify_thread();1137cmpwi(CCR0, Rinterp_only, 0);1138beq(CCR0, done);1139ld(Rtarget_addr, in_bytes(Method::interpreter_entry_offset()), Rtarget_method);1140align(32, 12);1141bind(done);1142}11431144#ifdef ASSERT1145{1146Label Lok;1147cmpdi(CCR0, Rtarget_addr, 0);1148bne(CCR0, Lok);1149stop("null entry point");1150bind(Lok);1151}1152#endif // ASSERT11531154mr(R21_sender_SP, R1_SP);11551156// Calc a precise SP for the call. The SP value we calculated in1157// generate_fixed_frame() is based on the max_stack() value, so we would waste stack space1158// if esp is not max. Also, the i2c adapter extends the stack space without restoring1159// our pre-calced value, so repeating calls via i2c would result in stack overflow.1160// Since esp already points to an empty slot, we just have to sub 1 additional slot1161// to meet the abi scratch requirements.1162// The max_stack pointer will get restored by means of the GR_Lmax_stack local in1163// the return entry of the interpreter.1164addi(Rscratch2, R15_esp, Interpreter::stackElementSize - frame::abi_reg_args_size);1165clrrdi(Rscratch2, Rscratch2, exact_log2(frame::alignment_in_bytes)); // round towards smaller address1166resize_frame_absolute(Rscratch2, Rscratch2, R0);11671168mr_if_needed(R19_method, Rtarget_method);1169mtctr(Rtarget_addr);1170mtlr(Rret_addr);11711172save_interpreter_state(Rscratch2);1173#ifdef ASSERT1174ld(Rscratch1, _ijava_state_neg(top_frame_sp), Rscratch2); // Rscratch2 contains fp1175cmpd(CCR0, R21_sender_SP, Rscratch1);1176asm_assert_eq("top_frame_sp incorrect");1177#endif11781179bctr();1180}11811182// Set the method data pointer for the current bcp.1183void InterpreterMacroAssembler::set_method_data_pointer_for_bcp() {1184assert(ProfileInterpreter, "must be profiling interpreter");1185Label get_continue;1186ld(R28_mdx, in_bytes(Method::method_data_offset()), R19_method);1187test_method_data_pointer(get_continue);1188call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::bcp_to_di), R19_method, R14_bcp);11891190addi(R28_mdx, R28_mdx, in_bytes(MethodData::data_offset()));1191add(R28_mdx, R28_mdx, R3_RET);1192bind(get_continue);1193}11941195// Test ImethodDataPtr. If it is null, continue at the specified label.1196void InterpreterMacroAssembler::test_method_data_pointer(Label& zero_continue) {1197assert(ProfileInterpreter, "must be profiling interpreter");1198cmpdi(CCR0, R28_mdx, 0);1199beq(CCR0, zero_continue);1200}12011202void InterpreterMacroAssembler::verify_method_data_pointer() {1203assert(ProfileInterpreter, "must be profiling interpreter");1204#ifdef ASSERT1205Label verify_continue;1206test_method_data_pointer(verify_continue);12071208// If the mdp is valid, it will point to a DataLayout header which is1209// consistent with the bcp. The converse is highly probable also.1210lhz(R11_scratch1, in_bytes(DataLayout::bci_offset()), R28_mdx);1211ld(R12_scratch2, in_bytes(Method::const_offset()), R19_method);1212addi(R11_scratch1, R11_scratch1, in_bytes(ConstMethod::codes_offset()));1213add(R11_scratch1, R12_scratch2, R12_scratch2);1214cmpd(CCR0, R11_scratch1, R14_bcp);1215beq(CCR0, verify_continue);12161217call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::verify_mdp ), R19_method, R14_bcp, R28_mdx);12181219bind(verify_continue);1220#endif1221}12221223// Store a value at some constant offset from the method data pointer.1224void InterpreterMacroAssembler::set_mdp_data_at(int constant, Register value) {1225assert(ProfileInterpreter, "must be profiling interpreter");12261227std(value, constant, R28_mdx);1228}12291230// Increment the value at some constant offset from the method data pointer.1231void InterpreterMacroAssembler::increment_mdp_data_at(int constant,1232Register counter_addr,1233Register Rbumped_count,1234bool decrement) {1235// Locate the counter at a fixed offset from the mdp:1236addi(counter_addr, R28_mdx, constant);1237increment_mdp_data_at(counter_addr, Rbumped_count, decrement);1238}12391240// Increment the value at some non-fixed (reg + constant) offset from1241// the method data pointer.1242void InterpreterMacroAssembler::increment_mdp_data_at(Register reg,1243int constant,1244Register scratch,1245Register Rbumped_count,1246bool decrement) {1247// Add the constant to reg to get the offset.1248add(scratch, R28_mdx, reg);1249// Then calculate the counter address.1250addi(scratch, scratch, constant);1251increment_mdp_data_at(scratch, Rbumped_count, decrement);1252}12531254void InterpreterMacroAssembler::increment_mdp_data_at(Register counter_addr,1255Register Rbumped_count,1256bool decrement) {1257assert(ProfileInterpreter, "must be profiling interpreter");12581259// Load the counter.1260ld(Rbumped_count, 0, counter_addr);12611262if (decrement) {1263// Decrement the register. Set condition codes.1264addi(Rbumped_count, Rbumped_count, - DataLayout::counter_increment);1265// Store the decremented counter, if it is still negative.1266std(Rbumped_count, 0, counter_addr);1267// Note: add/sub overflow check are not ported, since 64 bit1268// calculation should never overflow.1269} else {1270// Increment the register. Set carry flag.1271addi(Rbumped_count, Rbumped_count, DataLayout::counter_increment);1272// Store the incremented counter.1273std(Rbumped_count, 0, counter_addr);1274}1275}12761277// Set a flag value at the current method data pointer position.1278void InterpreterMacroAssembler::set_mdp_flag_at(int flag_constant,1279Register scratch) {1280assert(ProfileInterpreter, "must be profiling interpreter");1281// Load the data header.1282lbz(scratch, in_bytes(DataLayout::flags_offset()), R28_mdx);1283// Set the flag.1284ori(scratch, scratch, flag_constant);1285// Store the modified header.1286stb(scratch, in_bytes(DataLayout::flags_offset()), R28_mdx);1287}12881289// Test the location at some offset from the method data pointer.1290// If it is not equal to value, branch to the not_equal_continue Label.1291void InterpreterMacroAssembler::test_mdp_data_at(int offset,1292Register value,1293Label& not_equal_continue,1294Register test_out) {1295assert(ProfileInterpreter, "must be profiling interpreter");12961297ld(test_out, offset, R28_mdx);1298cmpd(CCR0, value, test_out);1299bne(CCR0, not_equal_continue);1300}13011302// Update the method data pointer by the displacement located at some fixed1303// offset from the method data pointer.1304void InterpreterMacroAssembler::update_mdp_by_offset(int offset_of_disp,1305Register scratch) {1306assert(ProfileInterpreter, "must be profiling interpreter");13071308ld(scratch, offset_of_disp, R28_mdx);1309add(R28_mdx, scratch, R28_mdx);1310}13111312// Update the method data pointer by the displacement located at the1313// offset (reg + offset_of_disp).1314void InterpreterMacroAssembler::update_mdp_by_offset(Register reg,1315int offset_of_disp,1316Register scratch) {1317assert(ProfileInterpreter, "must be profiling interpreter");13181319add(scratch, reg, R28_mdx);1320ld(scratch, offset_of_disp, scratch);1321add(R28_mdx, scratch, R28_mdx);1322}13231324// Update the method data pointer by a simple constant displacement.1325void InterpreterMacroAssembler::update_mdp_by_constant(int constant) {1326assert(ProfileInterpreter, "must be profiling interpreter");1327addi(R28_mdx, R28_mdx, constant);1328}13291330// Update the method data pointer for a _ret bytecode whose target1331// was not among our cached targets.1332void InterpreterMacroAssembler::update_mdp_for_ret(TosState state,1333Register return_bci) {1334assert(ProfileInterpreter, "must be profiling interpreter");13351336push(state);1337assert(return_bci->is_nonvolatile(), "need to protect return_bci");1338call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::update_mdp_for_ret), return_bci);1339pop(state);1340}13411342// Increments the backedge counter.1343// Returns backedge counter + invocation counter in Rdst.1344void InterpreterMacroAssembler::increment_backedge_counter(const Register Rcounters, const Register Rdst,1345const Register Rtmp1, Register Rscratch) {1346assert(UseCompiler, "incrementing must be useful");1347assert_different_registers(Rdst, Rtmp1);1348const Register invocation_counter = Rtmp1;1349const Register counter = Rdst;1350// TODO: PPC port: assert(4 == InvocationCounter::sz_counter(), "unexpected field size.");13511352// Load backedge counter.1353lwz(counter, in_bytes(MethodCounters::backedge_counter_offset()) +1354in_bytes(InvocationCounter::counter_offset()), Rcounters);1355// Load invocation counter.1356lwz(invocation_counter, in_bytes(MethodCounters::invocation_counter_offset()) +1357in_bytes(InvocationCounter::counter_offset()), Rcounters);13581359// Add the delta to the backedge counter.1360addi(counter, counter, InvocationCounter::count_increment);13611362// Mask the invocation counter.1363andi(invocation_counter, invocation_counter, InvocationCounter::count_mask_value);13641365// Store new counter value.1366stw(counter, in_bytes(MethodCounters::backedge_counter_offset()) +1367in_bytes(InvocationCounter::counter_offset()), Rcounters);1368// Return invocation counter + backedge counter.1369add(counter, counter, invocation_counter);1370}13711372// Count a taken branch in the bytecodes.1373void InterpreterMacroAssembler::profile_taken_branch(Register scratch, Register bumped_count) {1374if (ProfileInterpreter) {1375Label profile_continue;13761377// If no method data exists, go to profile_continue.1378test_method_data_pointer(profile_continue);13791380// We are taking a branch. Increment the taken count.1381increment_mdp_data_at(in_bytes(JumpData::taken_offset()), scratch, bumped_count);13821383// The method data pointer needs to be updated to reflect the new target.1384update_mdp_by_offset(in_bytes(JumpData::displacement_offset()), scratch);1385bind (profile_continue);1386}1387}13881389// Count a not-taken branch in the bytecodes.1390void InterpreterMacroAssembler::profile_not_taken_branch(Register scratch1, Register scratch2) {1391if (ProfileInterpreter) {1392Label profile_continue;13931394// If no method data exists, go to profile_continue.1395test_method_data_pointer(profile_continue);13961397// We are taking a branch. Increment the not taken count.1398increment_mdp_data_at(in_bytes(BranchData::not_taken_offset()), scratch1, scratch2);13991400// The method data pointer needs to be updated to correspond to the1401// next bytecode.1402update_mdp_by_constant(in_bytes(BranchData::branch_data_size()));1403bind (profile_continue);1404}1405}14061407// Count a non-virtual call in the bytecodes.1408void InterpreterMacroAssembler::profile_call(Register scratch1, Register scratch2) {1409if (ProfileInterpreter) {1410Label profile_continue;14111412// If no method data exists, go to profile_continue.1413test_method_data_pointer(profile_continue);14141415// We are making a call. Increment the count.1416increment_mdp_data_at(in_bytes(CounterData::count_offset()), scratch1, scratch2);14171418// The method data pointer needs to be updated to reflect the new target.1419update_mdp_by_constant(in_bytes(CounterData::counter_data_size()));1420bind (profile_continue);1421}1422}14231424// Count a final call in the bytecodes.1425void InterpreterMacroAssembler::profile_final_call(Register scratch1, Register scratch2) {1426if (ProfileInterpreter) {1427Label profile_continue;14281429// If no method data exists, go to profile_continue.1430test_method_data_pointer(profile_continue);14311432// We are making a call. Increment the count.1433increment_mdp_data_at(in_bytes(CounterData::count_offset()), scratch1, scratch2);14341435// The method data pointer needs to be updated to reflect the new target.1436update_mdp_by_constant(in_bytes(VirtualCallData::virtual_call_data_size()));1437bind (profile_continue);1438}1439}14401441// Count a virtual call in the bytecodes.1442void InterpreterMacroAssembler::profile_virtual_call(Register Rreceiver,1443Register Rscratch1,1444Register Rscratch2,1445bool receiver_can_be_null) {1446if (!ProfileInterpreter) { return; }1447Label profile_continue;14481449// If no method data exists, go to profile_continue.1450test_method_data_pointer(profile_continue);14511452Label skip_receiver_profile;1453if (receiver_can_be_null) {1454Label not_null;1455cmpdi(CCR0, Rreceiver, 0);1456bne(CCR0, not_null);1457// We are making a call. Increment the count for null receiver.1458increment_mdp_data_at(in_bytes(CounterData::count_offset()), Rscratch1, Rscratch2);1459b(skip_receiver_profile);1460bind(not_null);1461}14621463// Record the receiver type.1464record_klass_in_profile(Rreceiver, Rscratch1, Rscratch2, true);1465bind(skip_receiver_profile);14661467// The method data pointer needs to be updated to reflect the new target.1468update_mdp_by_constant(in_bytes(VirtualCallData::virtual_call_data_size()));1469bind (profile_continue);1470}14711472void InterpreterMacroAssembler::profile_typecheck(Register Rklass, Register Rscratch1, Register Rscratch2) {1473if (ProfileInterpreter) {1474Label profile_continue;14751476// If no method data exists, go to profile_continue.1477test_method_data_pointer(profile_continue);14781479int mdp_delta = in_bytes(BitData::bit_data_size());1480if (TypeProfileCasts) {1481mdp_delta = in_bytes(VirtualCallData::virtual_call_data_size());14821483// Record the object type.1484record_klass_in_profile(Rklass, Rscratch1, Rscratch2, false);1485}14861487// The method data pointer needs to be updated.1488update_mdp_by_constant(mdp_delta);14891490bind (profile_continue);1491}1492}14931494void InterpreterMacroAssembler::profile_typecheck_failed(Register Rscratch1, Register Rscratch2) {1495if (ProfileInterpreter && TypeProfileCasts) {1496Label profile_continue;14971498// If no method data exists, go to profile_continue.1499test_method_data_pointer(profile_continue);15001501int count_offset = in_bytes(CounterData::count_offset());1502// Back up the address, since we have already bumped the mdp.1503count_offset -= in_bytes(VirtualCallData::virtual_call_data_size());15041505// *Decrement* the counter. We expect to see zero or small negatives.1506increment_mdp_data_at(count_offset, Rscratch1, Rscratch2, true);15071508bind (profile_continue);1509}1510}15111512// Count a ret in the bytecodes.1513void InterpreterMacroAssembler::profile_ret(TosState state, Register return_bci,1514Register scratch1, Register scratch2) {1515if (ProfileInterpreter) {1516Label profile_continue;1517uint row;15181519// If no method data exists, go to profile_continue.1520test_method_data_pointer(profile_continue);15211522// Update the total ret count.1523increment_mdp_data_at(in_bytes(CounterData::count_offset()), scratch1, scratch2 );15241525for (row = 0; row < RetData::row_limit(); row++) {1526Label next_test;15271528// See if return_bci is equal to bci[n]:1529test_mdp_data_at(in_bytes(RetData::bci_offset(row)), return_bci, next_test, scratch1);15301531// return_bci is equal to bci[n]. Increment the count.1532increment_mdp_data_at(in_bytes(RetData::bci_count_offset(row)), scratch1, scratch2);15331534// The method data pointer needs to be updated to reflect the new target.1535update_mdp_by_offset(in_bytes(RetData::bci_displacement_offset(row)), scratch1);1536b(profile_continue);1537bind(next_test);1538}15391540update_mdp_for_ret(state, return_bci);15411542bind (profile_continue);1543}1544}15451546// Count the default case of a switch construct.1547void InterpreterMacroAssembler::profile_switch_default(Register scratch1, Register scratch2) {1548if (ProfileInterpreter) {1549Label profile_continue;15501551// If no method data exists, go to profile_continue.1552test_method_data_pointer(profile_continue);15531554// Update the default case count1555increment_mdp_data_at(in_bytes(MultiBranchData::default_count_offset()),1556scratch1, scratch2);15571558// The method data pointer needs to be updated.1559update_mdp_by_offset(in_bytes(MultiBranchData::default_displacement_offset()),1560scratch1);15611562bind (profile_continue);1563}1564}15651566// Count the index'th case of a switch construct.1567void InterpreterMacroAssembler::profile_switch_case(Register index,1568Register scratch1,1569Register scratch2,1570Register scratch3) {1571if (ProfileInterpreter) {1572assert_different_registers(index, scratch1, scratch2, scratch3);1573Label profile_continue;15741575// If no method data exists, go to profile_continue.1576test_method_data_pointer(profile_continue);15771578// Build the base (index * per_case_size_in_bytes()) + case_array_offset_in_bytes().1579li(scratch3, in_bytes(MultiBranchData::case_array_offset()));15801581assert (in_bytes(MultiBranchData::per_case_size()) == 16, "so that shladd works");1582sldi(scratch1, index, exact_log2(in_bytes(MultiBranchData::per_case_size())));1583add(scratch1, scratch1, scratch3);15841585// Update the case count.1586increment_mdp_data_at(scratch1, in_bytes(MultiBranchData::relative_count_offset()), scratch2, scratch3);15871588// The method data pointer needs to be updated.1589update_mdp_by_offset(scratch1, in_bytes(MultiBranchData::relative_displacement_offset()), scratch2);15901591bind (profile_continue);1592}1593}15941595void InterpreterMacroAssembler::profile_null_seen(Register Rscratch1, Register Rscratch2) {1596if (ProfileInterpreter) {1597assert_different_registers(Rscratch1, Rscratch2);1598Label profile_continue;15991600// If no method data exists, go to profile_continue.1601test_method_data_pointer(profile_continue);16021603set_mdp_flag_at(BitData::null_seen_byte_constant(), Rscratch1);16041605// The method data pointer needs to be updated.1606int mdp_delta = in_bytes(BitData::bit_data_size());1607if (TypeProfileCasts) {1608mdp_delta = in_bytes(VirtualCallData::virtual_call_data_size());1609}1610update_mdp_by_constant(mdp_delta);16111612bind (profile_continue);1613}1614}16151616void InterpreterMacroAssembler::record_klass_in_profile(Register Rreceiver,1617Register Rscratch1, Register Rscratch2,1618bool is_virtual_call) {1619assert(ProfileInterpreter, "must be profiling");1620assert_different_registers(Rreceiver, Rscratch1, Rscratch2);16211622Label done;1623record_klass_in_profile_helper(Rreceiver, Rscratch1, Rscratch2, 0, done, is_virtual_call);1624bind (done);1625}16261627void InterpreterMacroAssembler::record_klass_in_profile_helper(1628Register receiver, Register scratch1, Register scratch2,1629int start_row, Label& done, bool is_virtual_call) {1630if (TypeProfileWidth == 0) {1631if (is_virtual_call) {1632increment_mdp_data_at(in_bytes(CounterData::count_offset()), scratch1, scratch2);1633}1634return;1635}16361637int last_row = VirtualCallData::row_limit() - 1;1638assert(start_row <= last_row, "must be work left to do");1639// Test this row for both the receiver and for null.1640// Take any of three different outcomes:1641// 1. found receiver => increment count and goto done1642// 2. found null => keep looking for case 1, maybe allocate this cell1643// 3. found something else => keep looking for cases 1 and 21644// Case 3 is handled by a recursive call.1645for (int row = start_row; row <= last_row; row++) {1646Label next_test;1647bool test_for_null_also = (row == start_row);16481649// See if the receiver is receiver[n].1650int recvr_offset = in_bytes(VirtualCallData::receiver_offset(row));1651test_mdp_data_at(recvr_offset, receiver, next_test, scratch1);1652// delayed()->tst(scratch);16531654// The receiver is receiver[n]. Increment count[n].1655int count_offset = in_bytes(VirtualCallData::receiver_count_offset(row));1656increment_mdp_data_at(count_offset, scratch1, scratch2);1657b(done);1658bind(next_test);16591660if (test_for_null_also) {1661Label found_null;1662// Failed the equality check on receiver[n]... Test for null.1663if (start_row == last_row) {1664// The only thing left to do is handle the null case.1665if (is_virtual_call) {1666// Scratch1 contains test_out from test_mdp_data_at.1667cmpdi(CCR0, scratch1, 0);1668beq(CCR0, found_null);1669// Receiver did not match any saved receiver and there is no empty row for it.1670// Increment total counter to indicate polymorphic case.1671increment_mdp_data_at(in_bytes(CounterData::count_offset()), scratch1, scratch2);1672b(done);1673bind(found_null);1674} else {1675cmpdi(CCR0, scratch1, 0);1676bne(CCR0, done);1677}1678break;1679}1680// Since null is rare, make it be the branch-taken case.1681cmpdi(CCR0, scratch1, 0);1682beq(CCR0, found_null);16831684// Put all the "Case 3" tests here.1685record_klass_in_profile_helper(receiver, scratch1, scratch2, start_row + 1, done, is_virtual_call);16861687// Found a null. Keep searching for a matching receiver,1688// but remember that this is an empty (unused) slot.1689bind(found_null);1690}1691}16921693// In the fall-through case, we found no matching receiver, but we1694// observed the receiver[start_row] is NULL.16951696// Fill in the receiver field and increment the count.1697int recvr_offset = in_bytes(VirtualCallData::receiver_offset(start_row));1698set_mdp_data_at(recvr_offset, receiver);1699int count_offset = in_bytes(VirtualCallData::receiver_count_offset(start_row));1700li(scratch1, DataLayout::counter_increment);1701set_mdp_data_at(count_offset, scratch1);1702if (start_row > 0) {1703b(done);1704}1705}17061707// Argument and return type profilig.1708// kills: tmp, tmp2, R0, CR0, CR11709void InterpreterMacroAssembler::profile_obj_type(Register obj, Register mdo_addr_base,1710RegisterOrConstant mdo_addr_offs,1711Register tmp, Register tmp2) {1712Label do_nothing, do_update;17131714// tmp2 = obj is allowed1715assert_different_registers(obj, mdo_addr_base, tmp, R0);1716assert_different_registers(tmp2, mdo_addr_base, tmp, R0);1717const Register klass = tmp2;17181719verify_oop(obj);17201721ld(tmp, mdo_addr_offs, mdo_addr_base);17221723// Set null_seen if obj is 0.1724cmpdi(CCR0, obj, 0);1725ori(R0, tmp, TypeEntries::null_seen);1726beq(CCR0, do_update);17271728load_klass(klass, obj);17291730clrrdi(R0, tmp, exact_log2(-TypeEntries::type_klass_mask));1731// Basically same as andi(R0, tmp, TypeEntries::type_klass_mask);1732cmpd(CCR1, R0, klass);1733// Klass seen before, nothing to do (regardless of unknown bit).1734//beq(CCR1, do_nothing);17351736andi_(R0, klass, TypeEntries::type_unknown);1737// Already unknown. Nothing to do anymore.1738//bne(CCR0, do_nothing);1739crorc(CCR0, Assembler::equal, CCR1, Assembler::equal); // cr0 eq = cr1 eq or cr0 ne1740beq(CCR0, do_nothing);17411742clrrdi_(R0, tmp, exact_log2(-TypeEntries::type_mask));1743orr(R0, klass, tmp); // Combine klass and null_seen bit (only used if (tmp & type_mask)==0).1744beq(CCR0, do_update); // First time here. Set profile type.17451746// Different than before. Cannot keep accurate profile.1747ori(R0, tmp, TypeEntries::type_unknown);17481749bind(do_update);1750// update profile1751std(R0, mdo_addr_offs, mdo_addr_base);17521753align(32, 12);1754bind(do_nothing);1755}17561757void InterpreterMacroAssembler::profile_arguments_type(Register callee,1758Register tmp1, Register tmp2,1759bool is_virtual) {1760if (!ProfileInterpreter) {1761return;1762}17631764assert_different_registers(callee, tmp1, tmp2, R28_mdx);17651766if (MethodData::profile_arguments() || MethodData::profile_return()) {1767Label profile_continue;17681769test_method_data_pointer(profile_continue);17701771int off_to_start = is_virtual ?1772in_bytes(VirtualCallData::virtual_call_data_size()) : in_bytes(CounterData::counter_data_size());17731774lbz(tmp1, in_bytes(DataLayout::tag_offset()) - off_to_start, R28_mdx);1775cmpwi(CCR0, tmp1, is_virtual ? DataLayout::virtual_call_type_data_tag : DataLayout::call_type_data_tag);1776bne(CCR0, profile_continue);17771778if (MethodData::profile_arguments()) {1779Label done;1780int off_to_args = in_bytes(TypeEntriesAtCall::args_data_offset());1781add(R28_mdx, off_to_args, R28_mdx);17821783for (int i = 0; i < TypeProfileArgsLimit; i++) {1784if (i > 0 || MethodData::profile_return()) {1785// If return value type is profiled we may have no argument to profile.1786ld(tmp1, in_bytes(TypeEntriesAtCall::cell_count_offset())-off_to_args, R28_mdx);1787cmpdi(CCR0, tmp1, (i+1)*TypeStackSlotEntries::per_arg_count());1788addi(tmp1, tmp1, -i*TypeStackSlotEntries::per_arg_count());1789blt(CCR0, done);1790}1791ld(tmp1, in_bytes(Method::const_offset()), callee);1792lhz(tmp1, in_bytes(ConstMethod::size_of_parameters_offset()), tmp1);1793// Stack offset o (zero based) from the start of the argument1794// list, for n arguments translates into offset n - o - 1 from1795// the end of the argument list. But there's an extra slot at1796// the top of the stack. So the offset is n - o from Lesp.1797ld(tmp2, in_bytes(TypeEntriesAtCall::stack_slot_offset(i))-off_to_args, R28_mdx);1798subf(tmp1, tmp2, tmp1);17991800sldi(tmp1, tmp1, Interpreter::logStackElementSize);1801ldx(tmp1, tmp1, R15_esp);18021803profile_obj_type(tmp1, R28_mdx, in_bytes(TypeEntriesAtCall::argument_type_offset(i))-off_to_args, tmp2, tmp1);18041805int to_add = in_bytes(TypeStackSlotEntries::per_arg_size());1806addi(R28_mdx, R28_mdx, to_add);1807off_to_args += to_add;1808}18091810if (MethodData::profile_return()) {1811ld(tmp1, in_bytes(TypeEntriesAtCall::cell_count_offset())-off_to_args, R28_mdx);1812addi(tmp1, tmp1, -TypeProfileArgsLimit*TypeStackSlotEntries::per_arg_count());1813}18141815bind(done);18161817if (MethodData::profile_return()) {1818// We're right after the type profile for the last1819// argument. tmp1 is the number of cells left in the1820// CallTypeData/VirtualCallTypeData to reach its end. Non null1821// if there's a return to profile.1822assert(ReturnTypeEntry::static_cell_count() < TypeStackSlotEntries::per_arg_count(),1823"can't move past ret type");1824sldi(tmp1, tmp1, exact_log2(DataLayout::cell_size));1825add(R28_mdx, tmp1, R28_mdx);1826}1827} else {1828assert(MethodData::profile_return(), "either profile call args or call ret");1829update_mdp_by_constant(in_bytes(TypeEntriesAtCall::return_only_size()));1830}18311832// Mdp points right after the end of the1833// CallTypeData/VirtualCallTypeData, right after the cells for the1834// return value type if there's one.1835align(32, 12);1836bind(profile_continue);1837}1838}18391840void InterpreterMacroAssembler::profile_return_type(Register ret, Register tmp1, Register tmp2) {1841assert_different_registers(ret, tmp1, tmp2);1842if (ProfileInterpreter && MethodData::profile_return()) {1843Label profile_continue;18441845test_method_data_pointer(profile_continue);18461847if (MethodData::profile_return_jsr292_only()) {1848// If we don't profile all invoke bytecodes we must make sure1849// it's a bytecode we indeed profile. We can't go back to the1850// begining of the ProfileData we intend to update to check its1851// type because we're right after it and we don't known its1852// length.1853lbz(tmp1, 0, R14_bcp);1854lbz(tmp2, Method::intrinsic_id_offset_in_bytes(), R19_method);1855cmpwi(CCR0, tmp1, Bytecodes::_invokedynamic);1856cmpwi(CCR1, tmp1, Bytecodes::_invokehandle);1857cror(CCR0, Assembler::equal, CCR1, Assembler::equal);1858cmpwi(CCR1, tmp2, static_cast<int>(vmIntrinsics::_compiledLambdaForm));1859cror(CCR0, Assembler::equal, CCR1, Assembler::equal);1860bne(CCR0, profile_continue);1861}18621863profile_obj_type(ret, R28_mdx, -in_bytes(ReturnTypeEntry::size()), tmp1, tmp2);18641865align(32, 12);1866bind(profile_continue);1867}1868}18691870void InterpreterMacroAssembler::profile_parameters_type(Register tmp1, Register tmp2,1871Register tmp3, Register tmp4) {1872if (ProfileInterpreter && MethodData::profile_parameters()) {1873Label profile_continue, done;18741875test_method_data_pointer(profile_continue);18761877// Load the offset of the area within the MDO used for1878// parameters. If it's negative we're not profiling any parameters.1879lwz(tmp1, in_bytes(MethodData::parameters_type_data_di_offset()) - in_bytes(MethodData::data_offset()), R28_mdx);1880cmpwi(CCR0, tmp1, 0);1881blt(CCR0, profile_continue);18821883// Compute a pointer to the area for parameters from the offset1884// and move the pointer to the slot for the last1885// parameters. Collect profiling from last parameter down.1886// mdo start + parameters offset + array length - 118871888// Pointer to the parameter area in the MDO.1889const Register mdp = tmp1;1890add(mdp, tmp1, R28_mdx);18911892// Offset of the current profile entry to update.1893const Register entry_offset = tmp2;1894// entry_offset = array len in number of cells1895ld(entry_offset, in_bytes(ArrayData::array_len_offset()), mdp);18961897int off_base = in_bytes(ParametersTypeData::stack_slot_offset(0));1898assert(off_base % DataLayout::cell_size == 0, "should be a number of cells");18991900// entry_offset (number of cells) = array len - size of 1 entry + offset of the stack slot field1901addi(entry_offset, entry_offset, -TypeStackSlotEntries::per_arg_count() + (off_base / DataLayout::cell_size));1902// entry_offset in bytes1903sldi(entry_offset, entry_offset, exact_log2(DataLayout::cell_size));19041905Label loop;1906align(32, 12);1907bind(loop);19081909// Load offset on the stack from the slot for this parameter.1910ld(tmp3, entry_offset, mdp);1911sldi(tmp3, tmp3, Interpreter::logStackElementSize);1912neg(tmp3, tmp3);1913// Read the parameter from the local area.1914ldx(tmp3, tmp3, R18_locals);19151916// Make entry_offset now point to the type field for this parameter.1917int type_base = in_bytes(ParametersTypeData::type_offset(0));1918assert(type_base > off_base, "unexpected");1919addi(entry_offset, entry_offset, type_base - off_base);19201921// Profile the parameter.1922profile_obj_type(tmp3, mdp, entry_offset, tmp4, tmp3);19231924// Go to next parameter.1925int delta = TypeStackSlotEntries::per_arg_count() * DataLayout::cell_size + (type_base - off_base);1926cmpdi(CCR0, entry_offset, off_base + delta);1927addi(entry_offset, entry_offset, -delta);1928bge(CCR0, loop);19291930align(32, 12);1931bind(profile_continue);1932}1933}19341935// Add a InterpMonitorElem to stack (see frame_sparc.hpp).1936void InterpreterMacroAssembler::add_monitor_to_stack(bool stack_is_empty, Register Rtemp1, Register Rtemp2) {19371938// Very-local scratch registers.1939const Register esp = Rtemp1;1940const Register slot = Rtemp2;19411942// Extracted monitor_size.1943int monitor_size = frame::interpreter_frame_monitor_size_in_bytes();1944assert(Assembler::is_aligned((unsigned int)monitor_size,1945(unsigned int)frame::alignment_in_bytes),1946"size of a monitor must respect alignment of SP");19471948resize_frame(-monitor_size, /*temp*/esp); // Allocate space for new monitor1949std(R1_SP, _ijava_state_neg(top_frame_sp), esp); // esp contains fp19501951// Shuffle expression stack down. Recall that stack_base points1952// just above the new expression stack bottom. Old_tos and new_tos1953// are used to scan thru the old and new expression stacks.1954if (!stack_is_empty) {1955Label copy_slot, copy_slot_finished;1956const Register n_slots = slot;19571958addi(esp, R15_esp, Interpreter::stackElementSize); // Point to first element (pre-pushed stack).1959subf(n_slots, esp, R26_monitor);1960srdi_(n_slots, n_slots, LogBytesPerWord); // Compute number of slots to copy.1961assert(LogBytesPerWord == 3, "conflicts assembler instructions");1962beq(CCR0, copy_slot_finished); // Nothing to copy.19631964mtctr(n_slots);19651966// loop1967bind(copy_slot);1968ld(slot, 0, esp); // Move expression stack down.1969std(slot, -monitor_size, esp); // distance = monitor_size1970addi(esp, esp, BytesPerWord);1971bdnz(copy_slot);19721973bind(copy_slot_finished);1974}19751976addi(R15_esp, R15_esp, -monitor_size);1977addi(R26_monitor, R26_monitor, -monitor_size);19781979// Restart interpreter1980}19811982// ============================================================================1983// Java locals access19841985// Load a local variable at index in Rindex into register Rdst_value.1986// Also puts address of local into Rdst_address as a service.1987// Kills:1988// - Rdst_value1989// - Rdst_address1990void InterpreterMacroAssembler::load_local_int(Register Rdst_value, Register Rdst_address, Register Rindex) {1991sldi(Rdst_address, Rindex, Interpreter::logStackElementSize);1992subf(Rdst_address, Rdst_address, R18_locals);1993lwz(Rdst_value, 0, Rdst_address);1994}19951996// Load a local variable at index in Rindex into register Rdst_value.1997// Also puts address of local into Rdst_address as a service.1998// Kills:1999// - Rdst_value2000// - Rdst_address2001void InterpreterMacroAssembler::load_local_long(Register Rdst_value, Register Rdst_address, Register Rindex) {2002sldi(Rdst_address, Rindex, Interpreter::logStackElementSize);2003subf(Rdst_address, Rdst_address, R18_locals);2004ld(Rdst_value, -8, Rdst_address);2005}20062007// Load a local variable at index in Rindex into register Rdst_value.2008// Also puts address of local into Rdst_address as a service.2009// Input:2010// - Rindex: slot nr of local variable2011// Kills:2012// - Rdst_value2013// - Rdst_address2014void InterpreterMacroAssembler::load_local_ptr(Register Rdst_value,2015Register Rdst_address,2016Register Rindex) {2017sldi(Rdst_address, Rindex, Interpreter::logStackElementSize);2018subf(Rdst_address, Rdst_address, R18_locals);2019ld(Rdst_value, 0, Rdst_address);2020}20212022// Load a local variable at index in Rindex into register Rdst_value.2023// Also puts address of local into Rdst_address as a service.2024// Kills:2025// - Rdst_value2026// - Rdst_address2027void InterpreterMacroAssembler::load_local_float(FloatRegister Rdst_value,2028Register Rdst_address,2029Register Rindex) {2030sldi(Rdst_address, Rindex, Interpreter::logStackElementSize);2031subf(Rdst_address, Rdst_address, R18_locals);2032lfs(Rdst_value, 0, Rdst_address);2033}20342035// Load a local variable at index in Rindex into register Rdst_value.2036// Also puts address of local into Rdst_address as a service.2037// Kills:2038// - Rdst_value2039// - Rdst_address2040void InterpreterMacroAssembler::load_local_double(FloatRegister Rdst_value,2041Register Rdst_address,2042Register Rindex) {2043sldi(Rdst_address, Rindex, Interpreter::logStackElementSize);2044subf(Rdst_address, Rdst_address, R18_locals);2045lfd(Rdst_value, -8, Rdst_address);2046}20472048// Store an int value at local variable slot Rindex.2049// Kills:2050// - Rindex2051void InterpreterMacroAssembler::store_local_int(Register Rvalue, Register Rindex) {2052sldi(Rindex, Rindex, Interpreter::logStackElementSize);2053subf(Rindex, Rindex, R18_locals);2054stw(Rvalue, 0, Rindex);2055}20562057// Store a long value at local variable slot Rindex.2058// Kills:2059// - Rindex2060void InterpreterMacroAssembler::store_local_long(Register Rvalue, Register Rindex) {2061sldi(Rindex, Rindex, Interpreter::logStackElementSize);2062subf(Rindex, Rindex, R18_locals);2063std(Rvalue, -8, Rindex);2064}20652066// Store an oop value at local variable slot Rindex.2067// Kills:2068// - Rindex2069void InterpreterMacroAssembler::store_local_ptr(Register Rvalue, Register Rindex) {2070sldi(Rindex, Rindex, Interpreter::logStackElementSize);2071subf(Rindex, Rindex, R18_locals);2072std(Rvalue, 0, Rindex);2073}20742075// Store an int value at local variable slot Rindex.2076// Kills:2077// - Rindex2078void InterpreterMacroAssembler::store_local_float(FloatRegister Rvalue, Register Rindex) {2079sldi(Rindex, Rindex, Interpreter::logStackElementSize);2080subf(Rindex, Rindex, R18_locals);2081stfs(Rvalue, 0, Rindex);2082}20832084// Store an int value at local variable slot Rindex.2085// Kills:2086// - Rindex2087void InterpreterMacroAssembler::store_local_double(FloatRegister Rvalue, Register Rindex) {2088sldi(Rindex, Rindex, Interpreter::logStackElementSize);2089subf(Rindex, Rindex, R18_locals);2090stfd(Rvalue, -8, Rindex);2091}20922093// Read pending exception from thread and jump to interpreter.2094// Throw exception entry if one if pending. Fall through otherwise.2095void InterpreterMacroAssembler::check_and_forward_exception(Register Rscratch1, Register Rscratch2) {2096assert_different_registers(Rscratch1, Rscratch2, R3);2097Register Rexception = Rscratch1;2098Register Rtmp = Rscratch2;2099Label Ldone;2100// Get pending exception oop.2101ld(Rexception, thread_(pending_exception));2102cmpdi(CCR0, Rexception, 0);2103beq(CCR0, Ldone);2104li(Rtmp, 0);2105mr_if_needed(R3, Rexception);2106std(Rtmp, thread_(pending_exception)); // Clear exception in thread2107if (Interpreter::rethrow_exception_entry() != NULL) {2108// Already got entry address.2109load_dispatch_table(Rtmp, (address*)Interpreter::rethrow_exception_entry());2110} else {2111// Dynamically load entry address.2112int simm16_rest = load_const_optimized(Rtmp, &Interpreter::_rethrow_exception_entry, R0, true);2113ld(Rtmp, simm16_rest, Rtmp);2114}2115mtctr(Rtmp);2116save_interpreter_state(Rtmp);2117bctr();21182119align(32, 12);2120bind(Ldone);2121}21222123void InterpreterMacroAssembler::call_VM(Register oop_result, address entry_point, bool check_exceptions) {2124save_interpreter_state(R11_scratch1);21252126MacroAssembler::call_VM(oop_result, entry_point, false);21272128restore_interpreter_state(R11_scratch1, /*bcp_and_mdx_only*/ true);21292130check_and_handle_popframe(R11_scratch1);2131check_and_handle_earlyret(R11_scratch1);2132// Now check exceptions manually.2133if (check_exceptions) {2134check_and_forward_exception(R11_scratch1, R12_scratch2);2135}2136}21372138void InterpreterMacroAssembler::call_VM(Register oop_result, address entry_point,2139Register arg_1, bool check_exceptions) {2140// ARG1 is reserved for the thread.2141mr_if_needed(R4_ARG2, arg_1);2142call_VM(oop_result, entry_point, check_exceptions);2143}21442145void InterpreterMacroAssembler::call_VM(Register oop_result, address entry_point,2146Register arg_1, Register arg_2,2147bool check_exceptions) {2148// ARG1 is reserved for the thread.2149mr_if_needed(R4_ARG2, arg_1);2150assert(arg_2 != R4_ARG2, "smashed argument");2151mr_if_needed(R5_ARG3, arg_2);2152call_VM(oop_result, entry_point, check_exceptions);2153}21542155void InterpreterMacroAssembler::call_VM(Register oop_result, address entry_point,2156Register arg_1, Register arg_2, Register arg_3,2157bool check_exceptions) {2158// ARG1 is reserved for the thread.2159mr_if_needed(R4_ARG2, arg_1);2160assert(arg_2 != R4_ARG2, "smashed argument");2161mr_if_needed(R5_ARG3, arg_2);2162assert(arg_3 != R4_ARG2 && arg_3 != R5_ARG3, "smashed argument");2163mr_if_needed(R6_ARG4, arg_3);2164call_VM(oop_result, entry_point, check_exceptions);2165}21662167void InterpreterMacroAssembler::save_interpreter_state(Register scratch) {2168ld(scratch, 0, R1_SP);2169std(R15_esp, _ijava_state_neg(esp), scratch);2170std(R14_bcp, _ijava_state_neg(bcp), scratch);2171std(R26_monitor, _ijava_state_neg(monitors), scratch);2172if (ProfileInterpreter) { std(R28_mdx, _ijava_state_neg(mdx), scratch); }2173// Other entries should be unchanged.2174}21752176void InterpreterMacroAssembler::restore_interpreter_state(Register scratch, bool bcp_and_mdx_only) {2177ld(scratch, 0, R1_SP);2178ld(R14_bcp, _ijava_state_neg(bcp), scratch); // Changed by VM code (exception).2179if (ProfileInterpreter) { ld(R28_mdx, _ijava_state_neg(mdx), scratch); } // Changed by VM code.2180if (!bcp_and_mdx_only) {2181// Following ones are Metadata.2182ld(R19_method, _ijava_state_neg(method), scratch);2183ld(R27_constPoolCache, _ijava_state_neg(cpoolCache), scratch);2184// Following ones are stack addresses and don't require reload.2185ld(R15_esp, _ijava_state_neg(esp), scratch);2186ld(R18_locals, _ijava_state_neg(locals), scratch);2187ld(R26_monitor, _ijava_state_neg(monitors), scratch);2188}2189#ifdef ASSERT2190{2191Label Lok;2192subf(R0, R1_SP, scratch);2193cmpdi(CCR0, R0, frame::abi_reg_args_size + frame::ijava_state_size);2194bge(CCR0, Lok);2195stop("frame too small (restore istate)");2196bind(Lok);2197}2198#endif2199}22002201void InterpreterMacroAssembler::get_method_counters(Register method,2202Register Rcounters,2203Label& skip) {2204BLOCK_COMMENT("Load and ev. allocate counter object {");2205Label has_counters;2206ld(Rcounters, in_bytes(Method::method_counters_offset()), method);2207cmpdi(CCR0, Rcounters, 0);2208bne(CCR0, has_counters);2209call_VM(noreg, CAST_FROM_FN_PTR(address,2210InterpreterRuntime::build_method_counters), method);2211ld(Rcounters, in_bytes(Method::method_counters_offset()), method);2212cmpdi(CCR0, Rcounters, 0);2213beq(CCR0, skip); // No MethodCounters, OutOfMemory.2214BLOCK_COMMENT("} Load and ev. allocate counter object");22152216bind(has_counters);2217}22182219void InterpreterMacroAssembler::increment_invocation_counter(Register Rcounters,2220Register iv_be_count,2221Register Rtmp_r0) {2222assert(UseCompiler || LogTouchedMethods, "incrementing must be useful");2223Register invocation_count = iv_be_count;2224Register backedge_count = Rtmp_r0;2225int delta = InvocationCounter::count_increment;22262227// Load each counter in a register.2228// ld(inv_counter, Rtmp);2229// ld(be_counter, Rtmp2);2230int inv_counter_offset = in_bytes(MethodCounters::invocation_counter_offset() +2231InvocationCounter::counter_offset());2232int be_counter_offset = in_bytes(MethodCounters::backedge_counter_offset() +2233InvocationCounter::counter_offset());22342235BLOCK_COMMENT("Increment profiling counters {");22362237// Load the backedge counter.2238lwz(backedge_count, be_counter_offset, Rcounters); // is unsigned int2239// Mask the backedge counter.2240andi(backedge_count, backedge_count, InvocationCounter::count_mask_value);22412242// Load the invocation counter.2243lwz(invocation_count, inv_counter_offset, Rcounters); // is unsigned int2244// Add the delta to the invocation counter and store the result.2245addi(invocation_count, invocation_count, delta);2246// Store value.2247stw(invocation_count, inv_counter_offset, Rcounters);22482249// Add invocation counter + backedge counter.2250add(iv_be_count, backedge_count, invocation_count);22512252// Note that this macro must leave the backedge_count + invocation_count in2253// register iv_be_count!2254BLOCK_COMMENT("} Increment profiling counters");2255}22562257void InterpreterMacroAssembler::verify_oop(Register reg, TosState state) {2258if (state == atos) { MacroAssembler::verify_oop(reg, FILE_AND_LINE); }2259}22602261// Local helper function for the verify_oop_or_return_address macro.2262static bool verify_return_address(Method* m, int bci) {2263#ifndef PRODUCT2264address pc = (address)(m->constMethod()) + in_bytes(ConstMethod::codes_offset()) + bci;2265// Assume it is a valid return address if it is inside m and is preceded by a jsr.2266if (!m->contains(pc)) return false;2267address jsr_pc;2268jsr_pc = pc - Bytecodes::length_for(Bytecodes::_jsr);2269if (*jsr_pc == Bytecodes::_jsr && jsr_pc >= m->code_base()) return true;2270jsr_pc = pc - Bytecodes::length_for(Bytecodes::_jsr_w);2271if (*jsr_pc == Bytecodes::_jsr_w && jsr_pc >= m->code_base()) return true;2272#endif // PRODUCT2273return false;2274}22752276void InterpreterMacroAssembler::verify_FPU(int stack_depth, TosState state) {2277if (VerifyFPU) {2278unimplemented("verfiyFPU");2279}2280}22812282void InterpreterMacroAssembler::verify_oop_or_return_address(Register reg, Register Rtmp) {2283if (!VerifyOops) return;22842285// The VM documentation for the astore[_wide] bytecode allows2286// the TOS to be not only an oop but also a return address.2287Label test;2288Label skip;2289// See if it is an address (in the current method):22902291const int log2_bytecode_size_limit = 16;2292srdi_(Rtmp, reg, log2_bytecode_size_limit);2293bne(CCR0, test);22942295address fd = CAST_FROM_FN_PTR(address, verify_return_address);2296const int nbytes_save = MacroAssembler::num_volatile_regs * 8;2297save_volatile_gprs(R1_SP, -nbytes_save); // except R02298save_LR_CR(Rtmp); // Save in old frame.2299push_frame_reg_args(nbytes_save, Rtmp);23002301load_const_optimized(Rtmp, fd, R0);2302mr_if_needed(R4_ARG2, reg);2303mr(R3_ARG1, R19_method);2304call_c(Rtmp); // call C23052306pop_frame();2307restore_LR_CR(Rtmp);2308restore_volatile_gprs(R1_SP, -nbytes_save); // except R02309b(skip);23102311// Perform a more elaborate out-of-line call.2312// Not an address; verify it:2313bind(test);2314verify_oop(reg);2315bind(skip);2316}23172318// Inline assembly for:2319//2320// if (thread is in interp_only_mode) {2321// InterpreterRuntime::post_method_entry();2322// }2323// if (*jvmpi::event_flags_array_at_addr(JVMPI_EVENT_METHOD_ENTRY ) ||2324// *jvmpi::event_flags_array_at_addr(JVMPI_EVENT_METHOD_ENTRY2) ) {2325// SharedRuntime::jvmpi_method_entry(method, receiver);2326// }2327void InterpreterMacroAssembler::notify_method_entry() {2328// JVMTI2329// Whenever JVMTI puts a thread in interp_only_mode, method2330// entry/exit events are sent for that thread to track stack2331// depth. If it is possible to enter interp_only_mode we add2332// the code to check if the event should be sent.2333if (JvmtiExport::can_post_interpreter_events()) {2334Label jvmti_post_done;23352336lwz(R0, in_bytes(JavaThread::interp_only_mode_offset()), R16_thread);2337cmpwi(CCR0, R0, 0);2338beq(CCR0, jvmti_post_done);2339call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::post_method_entry));23402341bind(jvmti_post_done);2342}2343}23442345// Inline assembly for:2346//2347// if (thread is in interp_only_mode) {2348// // save result2349// InterpreterRuntime::post_method_exit();2350// // restore result2351// }2352// if (*jvmpi::event_flags_array_at_addr(JVMPI_EVENT_METHOD_EXIT)) {2353// // save result2354// SharedRuntime::jvmpi_method_exit();2355// // restore result2356// }2357//2358// Native methods have their result stored in d_tmp and l_tmp.2359// Java methods have their result stored in the expression stack.2360void InterpreterMacroAssembler::notify_method_exit(bool is_native_method, TosState state,2361NotifyMethodExitMode mode, bool check_exceptions) {2362// JVMTI2363// Whenever JVMTI puts a thread in interp_only_mode, method2364// entry/exit events are sent for that thread to track stack2365// depth. If it is possible to enter interp_only_mode we add2366// the code to check if the event should be sent.2367if (mode == NotifyJVMTI && JvmtiExport::can_post_interpreter_events()) {2368Label jvmti_post_done;23692370lwz(R0, in_bytes(JavaThread::interp_only_mode_offset()), R16_thread);2371cmpwi(CCR0, R0, 0);2372beq(CCR0, jvmti_post_done);2373if (!is_native_method) { push(state); } // Expose tos to GC.2374call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::post_method_exit), check_exceptions);2375if (!is_native_method) { pop(state); }23762377align(32, 12);2378bind(jvmti_post_done);2379}23802381// Dtrace support not implemented.2382}238323842385