Path: blob/master/src/hotspot/cpu/s390/macroAssembler_s390.hpp
40930 views
/*1* Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved.2* Copyright (c) 2016, 2019 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#ifndef CPU_S390_MACROASSEMBLER_S390_HPP26#define CPU_S390_MACROASSEMBLER_S390_HPP2728#include "asm/assembler.hpp"29#include "oops/accessDecorators.hpp"3031#define MODERN_IFUN(name) ((void (MacroAssembler::*)(Register, int64_t, Register, Register))&MacroAssembler::name)32#define CLASSIC_IFUN(name) ((void (MacroAssembler::*)(Register, int64_t, Register, Register))&MacroAssembler::name)33#define MODERN_FFUN(name) ((void (MacroAssembler::*)(FloatRegister, int64_t, Register, Register))&MacroAssembler::name)34#define CLASSIC_FFUN(name) ((void (MacroAssembler::*)(FloatRegister, int64_t, Register, Register))&MacroAssembler::name)3536class MacroAssembler: public Assembler {37public:38MacroAssembler(CodeBuffer* code) : Assembler(code) {}3940//41// Optimized instruction emitters42//4344// Move register if destination register and target register are different.45void lr_if_needed(Register rd, Register rs);46void lgr_if_needed(Register rd, Register rs);47void llgfr_if_needed(Register rd, Register rs);48void ldr_if_needed(FloatRegister rd, FloatRegister rs);4950void move_reg_if_needed(Register dest, BasicType dest_type, Register src, BasicType src_type);51void move_freg_if_needed(FloatRegister dest, BasicType dest_type, FloatRegister src, BasicType src_type);5253void freg2mem_opt(FloatRegister reg,54int64_t disp,55Register index,56Register base,57void (MacroAssembler::*modern) (FloatRegister, int64_t, Register, Register),58void (MacroAssembler::*classic)(FloatRegister, int64_t, Register, Register),59Register scratch = Z_R0);60void freg2mem_opt(FloatRegister reg,61const Address &a, bool is_double = true);6263void mem2freg_opt(FloatRegister reg,64int64_t disp,65Register index,66Register base,67void (MacroAssembler::*modern) (FloatRegister, int64_t, Register, Register),68void (MacroAssembler::*classic)(FloatRegister, int64_t, Register, Register),69Register scratch = Z_R0);70void mem2freg_opt(FloatRegister reg,71const Address &a, bool is_double = true);7273void reg2mem_opt(Register reg,74int64_t disp,75Register index,76Register base,77void (MacroAssembler::*modern) (Register, int64_t, Register, Register),78void (MacroAssembler::*classic)(Register, int64_t, Register, Register),79Register scratch = Z_R0);80// returns offset of the store instruction81int reg2mem_opt(Register reg, const Address &a, bool is_double = true);8283void mem2reg_opt(Register reg,84int64_t disp,85Register index,86Register base,87void (MacroAssembler::*modern) (Register, int64_t, Register, Register),88void (MacroAssembler::*classic)(Register, int64_t, Register, Register));89void mem2reg_opt(Register reg, const Address &a, bool is_double = true);90void mem2reg_signed_opt(Register reg, const Address &a);9192// AND immediate and set condition code, works for 64 bit immediates/operation as well.93void and_imm(Register r, long mask, Register tmp = Z_R0, bool wide = false);9495// 1's complement, 32bit or 64bit. Optimized to exploit distinct operands facility.96// Note: The condition code is neither preserved nor correctly set by this code!!!97// Note: (wide == false) does not protect the high order half of the target register98// from alternation. It only serves as optimization hint for 32-bit results.99void not_(Register r1, Register r2 = noreg, bool wide = false); // r1 = ~r2100101// Expanded support of all "rotate_then_<logicalOP>" instructions.102//103// Generalize and centralize rotate_then_<logicalOP> emitter.104// Functional description. For details, see Principles of Operation, Chapter 7, "Rotate Then Insert..."105// - Bits in a register are numbered left (most significant) to right (least significant), i.e. [0..63].106// - Bytes in a register are numbered left (most significant) to right (least significant), i.e. [0..7].107// - Register src is rotated to the left by (nRotate&0x3f) positions.108// - Negative values for nRotate result in a rotation to the right by abs(nRotate) positions.109// - The bits in positions [lBitPos..rBitPos] of the _ROTATED_ src operand take part in the110// logical operation performed on the contents (in those positions) of the dst operand.111// - The logical operation that is performed on the dst operand is one of112// o insert the selected bits (replacing the original contents of those bit positions)113// o and the selected bits with the corresponding bits of the dst operand114// o or the selected bits with the corresponding bits of the dst operand115// o xor the selected bits with the corresponding bits of the dst operand116// - For clear_dst == true, the destination register is cleared before the bits are inserted.117// For clear_dst == false, only the bit positions that get data inserted from src118// are changed. All other bit positions remain unchanged.119// - For test_only == true, the result of the logicalOP is only used to set the condition code, dst remains unchanged.120// For test_only == false, the result of the logicalOP replaces the selected bits of dst.121// - src32bit and dst32bit indicate the respective register is used as 32bit value only.122// Knowledge can simplify code generation.123//124// Here is an important performance note, valid for all <logicalOP>s except "insert":125// Due to the too complex nature of the operation, it cannot be done in a single cycle.126// Timing constraints require the instructions to be cracked into two micro-ops, taking127// one or two cycles each to execute. In some cases, an additional pipeline bubble might get added.128// Macroscopically, that makes up for a three- or four-cycle instruction where you would129// expect just a single cycle.130// It is thus not beneficial from a performance point of view to exploit those instructions.131// Other reasons (code compactness, register pressure, ...) might outweigh this penalty.132//133unsigned long create_mask(int lBitPos, int rBitPos);134void rotate_then_mask(Register dst, Register src, int lBitPos, int rBitPos,135int nRotate, bool src32bit, bool dst32bit, bool oneBits);136void rotate_then_insert(Register dst, Register src, int lBitPos, int rBitPos, int nRotate,137bool clear_dst);138void rotate_then_and(Register dst, Register src, int lBitPos, int rBitPos, int nRotate,139bool test_only);140void rotate_then_or(Register dst, Register src, int lBitPos, int rBitPos, int nRotate,141bool test_onlyt);142void rotate_then_xor(Register dst, Register src, int lBitPos, int rBitPos, int nRotate,143bool test_only);144145void add64(Register r1, RegisterOrConstant inc);146147// Helper function to multiply the 64bit contents of a register by a 16bit constant.148// The optimization tries to avoid the mghi instruction, since it uses the FPU for149// calculation and is thus rather slow.150//151// There is no handling for special cases, e.g. cval==0 or cval==1.152//153// Returns len of generated code block.154unsigned int mul_reg64_const16(Register rval, Register work, int cval);155156// Generic operation r1 := r2 + imm.157void add2reg(Register r1, int64_t imm, Register r2 = noreg);158// Generic operation r := b + x + d.159void add2reg_with_index(Register r, int64_t d, Register x, Register b = noreg);160161// Add2mem* methods for direct memory increment.162void add2mem_32(const Address &a, int64_t imm, Register tmp);163void add2mem_64(const Address &a, int64_t imm, Register tmp);164165// *((int8_t*)(dst)) |= imm8166inline void or2mem_8(Address& dst, int64_t imm8);167168// Load values by size and signedness.169void load_sized_value(Register dst, Address src, size_t size_in_bytes, bool is_signed);170void store_sized_value(Register src, Address dst, size_t size_in_bytes);171172// Load values with large offsets to base address.173private:174int split_largeoffset(int64_t si20_offset, Register tmp, bool fixed_codelen, bool accumulate);175public:176void load_long_largeoffset(Register t, int64_t si20, Register a, Register tmp);177void load_float_largeoffset(FloatRegister t, int64_t si20, Register a, Register tmp);178void load_double_largeoffset(FloatRegister t, int64_t si20, Register a, Register tmp);179180private:181long toc_distance();182public:183void load_toc(Register Rtoc);184void load_long_pcrelative(Register Rdst, address dataLocation);185static int load_long_pcrelative_size() { return 6; }186void load_addr_pcrelative(Register Rdst, address dataLocation);187static int load_addr_pcrel_size() { return 6; } // Just a LARL.188189// Load a value from memory and test (set CC).190void load_and_test_byte (Register dst, const Address &a);191void load_and_test_short (Register dst, const Address &a);192void load_and_test_int (Register dst, const Address &a);193void load_and_test_int2long(Register dst, const Address &a);194void load_and_test_long (Register dst, const Address &a);195196// Test a bit in memory. Result is reflected in CC.197void testbit(const Address &a, unsigned int bit);198// Test a bit in a register. Result is reflected in CC.199void testbit(Register r, unsigned int bitPos);200201void prefetch_read(Address a);202void prefetch_update(Address a);203204// Clear a register, i.e. load const zero into reg. Return len (in bytes) of205// generated instruction(s).206// whole_reg: Clear 64 bits if true, 32 bits otherwise.207// set_cc: Use instruction that sets the condition code, if true.208int clear_reg(Register r, bool whole_reg = true, bool set_cc = true);209210#ifdef ASSERT211int preset_reg(Register r, unsigned long pattern, int pattern_len);212#endif213214// Clear (store zeros) a small piece of memory.215// CAUTION: Do not use this for atomic memory clearing. Use store_const() instead.216// addr: Address descriptor of memory to clear.217// Index register will not be used!218// size: Number of bytes to clear.219void clear_mem(const Address& addr, unsigned size);220221// Move immediate values to memory. Currently supports 32 and 64 bit stores,222// but may be extended to 16 bit store operation, if needed.223// For details, see implementation in *.cpp file.224int store_const(const Address &dest, long imm,225unsigned int lm, unsigned int lc,226Register scratch = Z_R0);227inline int store_const(const Address &dest, long imm,228Register scratch = Z_R0, bool is_long = true);229230// Move/initialize arbitrarily large memory area. No check for destructive overlap.231// Being interruptible, these instructions need a retry-loop.232void move_long_ext(Register dst, Register src, unsigned int pad);233234void compare_long_ext(Register left, Register right, unsigned int pad);235void compare_long_uni(Register left, Register right, unsigned int pad);236237void search_string(Register end, Register start);238void search_string_uni(Register end, Register start);239240// Translate instructions241// Being interruptible, these instructions need a retry-loop.242void translate_oo(Register dst, Register src, uint mask);243void translate_ot(Register dst, Register src, uint mask);244void translate_to(Register dst, Register src, uint mask);245void translate_tt(Register dst, Register src, uint mask);246247// Crypto instructions.248// Being interruptible, these instructions need a retry-loop.249void cksm(Register crcBuff, Register srcBuff);250void km( Register dstBuff, Register srcBuff);251void kmc(Register dstBuff, Register srcBuff);252void kimd(Register srcBuff);253void klmd(Register srcBuff);254void kmac(Register srcBuff);255256// nop padding257void align(int modulus);258void align_address(int modulus);259260//261// Constants, loading constants, TOC support262//263264// Load generic address: d <- base(a) + index(a) + disp(a).265inline void load_address(Register d, const Address &a);266// Load absolute address (and try to optimize).267void load_absolute_address(Register d, address addr);268269// Address of Z_ARG1 and argument_offset.270// If temp_reg == arg_slot, arg_slot will be overwritten.271Address argument_address(RegisterOrConstant arg_slot,272Register temp_reg = noreg,273int64_t extra_slot_offset = 0);274275// Load a narrow ptr constant (oop or klass ptr).276void load_narrow_oop( Register t, narrowOop a);277void load_narrow_klass(Register t, Klass* k);278279static bool is_load_const_32to64(address pos);280static bool is_load_narrow_oop(address pos) { return is_load_const_32to64(pos); }281static bool is_load_narrow_klass(address pos) { return is_load_const_32to64(pos); }282283static int load_const_32to64_size() { return 6; }284static bool load_narrow_oop_size() { return load_const_32to64_size(); }285static bool load_narrow_klass_size() { return load_const_32to64_size(); }286287static int patch_load_const_32to64(address pos, int64_t a);288static int patch_load_narrow_oop(address pos, oop o);289static int patch_load_narrow_klass(address pos, Klass* k);290291// cOops. CLFI exploit.292void compare_immediate_narrow_oop(Register oop1, narrowOop oop2);293void compare_immediate_narrow_klass(Register op1, Klass* op2);294static bool is_compare_immediate32(address pos);295static bool is_compare_immediate_narrow_oop(address pos);296static bool is_compare_immediate_narrow_klass(address pos);297static int compare_immediate_narrow_size() { return 6; }298static int compare_immediate_narrow_oop_size() { return compare_immediate_narrow_size(); }299static int compare_immediate_narrow_klass_size() { return compare_immediate_narrow_size(); }300static int patch_compare_immediate_32(address pos, int64_t a);301static int patch_compare_immediate_narrow_oop(address pos, oop o);302static int patch_compare_immediate_narrow_klass(address pos, Klass* k);303304// Load a 32bit constant into a 64bit register.305void load_const_32to64(Register t, int64_t x, bool sign_extend=true);306// Load a 64 bit constant.307void load_const(Register t, long a);308inline void load_const(Register t, void* a);309inline void load_const(Register t, Label& L);310inline void load_const(Register t, const AddressLiteral& a);311// Get the 64 bit constant from a `load_const' sequence.312static long get_const(address load_const);313// Patch the 64 bit constant of a `load_const' sequence. This is a low level314// procedure. It neither flushes the instruction cache nor is it atomic.315static void patch_const(address load_const, long x);316static int load_const_size() { return 12; }317318// Turn a char into boolean. NOTE: destroys r.319void c2bool(Register r, Register t = Z_R0);320321// Optimized version of load_const for constants that do not need to be322// loaded by a sequence of instructions of fixed length and that do not323// need to be patched.324int load_const_optimized_rtn_len(Register t, long x, bool emit);325inline void load_const_optimized(Register t, long x);326inline void load_const_optimized(Register t, void* a);327inline void load_const_optimized(Register t, Label& L);328inline void load_const_optimized(Register t, const AddressLiteral& a);329330public:331332//----------------------------------------------------------333// oops in code -------------334// including compressed oops support -------------335//----------------------------------------------------------336337// Metadata in code that we have to keep track of.338AddressLiteral allocate_metadata_address(Metadata* obj); // allocate_index339AddressLiteral constant_metadata_address(Metadata* obj); // find_index340341// allocate_index342AddressLiteral allocate_oop_address(jobject obj);343// find_index344AddressLiteral constant_oop_address(jobject obj);345// Uses allocate_oop_address.346inline void set_oop (jobject obj, Register d);347// Uses constant_oop_address.348inline void set_oop_constant(jobject obj, Register d);349// Uses constant_metadata_address.350inline bool set_metadata_constant(Metadata* md, Register d);351352//353// branch, jump354//355356// Use one generic function for all branch patches.357static unsigned long patched_branch(address dest_pos, unsigned long inst, address inst_pos);358359void pd_patch_instruction(address branch, address target, const char* file, int line);360361// Extract relative address from "relative" instructions.362static long get_pcrel_offset(unsigned long inst);363static long get_pcrel_offset(address pc);364static address get_target_addr_pcrel(address pc);365366static inline bool is_call_pcrelative_short(unsigned long inst);367static inline bool is_call_pcrelative_long(unsigned long inst);368static inline bool is_branch_pcrelative_short(unsigned long inst);369static inline bool is_branch_pcrelative_long(unsigned long inst);370static inline bool is_compareandbranch_pcrelative_short(unsigned long inst);371static inline bool is_branchoncount_pcrelative_short(unsigned long inst);372static inline bool is_branchonindex32_pcrelative_short(unsigned long inst);373static inline bool is_branchonindex64_pcrelative_short(unsigned long inst);374static inline bool is_branchonindex_pcrelative_short(unsigned long inst);375static inline bool is_branch_pcrelative16(unsigned long inst);376static inline bool is_branch_pcrelative32(unsigned long inst);377static inline bool is_branch_pcrelative(unsigned long inst);378static inline bool is_load_pcrelative_long(unsigned long inst);379static inline bool is_misc_pcrelative_long(unsigned long inst);380static inline bool is_pcrelative_short(unsigned long inst);381static inline bool is_pcrelative_long(unsigned long inst);382// PCrelative TOC access. Variants with address argument.383static inline bool is_load_pcrelative_long(address iLoc);384static inline bool is_pcrelative_short(address iLoc);385static inline bool is_pcrelative_long(address iLoc);386387static inline bool is_pcrelative_instruction(address iloc);388static inline bool is_load_addr_pcrel(address a);389390static void patch_target_addr_pcrel(address pc, address con);391static void patch_addr_pcrel(address pc, address con) {392patch_target_addr_pcrel(pc, con); // Just delegate. This is only for nativeInst_s390.cpp.393}394395//---------------------------------------------------------396// Some macros for more comfortable assembler programming.397//---------------------------------------------------------398399// NOTE: pass NearLabel T to signal that the branch target T will be bound to a near address.400401void compare32_and_branch(Register r1, RegisterOrConstant x2, branch_condition cond, Label& target);402void compareU32_and_branch(Register r1, RegisterOrConstant x2, branch_condition cond, Label& target);403void compare64_and_branch(Register r1, RegisterOrConstant x2, branch_condition cond, Label& target);404void compareU64_and_branch(Register r1, RegisterOrConstant x2, branch_condition cond, Label& target);405406void branch_optimized(Assembler::branch_condition cond, address branch_target);407void branch_optimized(Assembler::branch_condition cond, Label& branch_target);408void compare_and_branch_optimized(Register r1,409Register r2,410Assembler::branch_condition cond,411address branch_addr,412bool len64,413bool has_sign);414void compare_and_branch_optimized(Register r1,415jlong x2,416Assembler::branch_condition cond,417Label& branch_target,418bool len64,419bool has_sign);420void compare_and_branch_optimized(Register r1,421Register r2,422Assembler::branch_condition cond,423Label& branch_target,424bool len64,425bool has_sign);426427//428// Support for frame handling429//430// Specify the register that should be stored as the return pc in the431// current frame (default is R14).432inline void save_return_pc(Register pc = Z_R14);433inline void restore_return_pc();434435// Get current PC.436address get_PC(Register result);437438// Get current PC + offset. Offset given in bytes, must be even!439address get_PC(Register result, int64_t offset);440441// Get size of instruction at pc (which must point to valid code).442void instr_size(Register size, Register pc);443444// Accessing, and in particular modifying, a stack location is only safe if445// the stack pointer (Z_SP) is set such that the accessed stack location is446// in the reserved range.447//448// From a performance point of view, it is desirable not to change the SP449// first and then immediately use it to access the freshly reserved space.450// That opens a small gap, though. If, just after storing some value (the451// frame pointer) into the to-be-reserved space, an interrupt is caught,452// the handler might use the space beyond Z_SP for it's own purpose.453// If that happens, the stored value might get altered.454455// Resize current frame either relatively wrt to current SP or absolute.456void resize_frame_sub(Register offset, Register fp, bool load_fp=true);457void resize_frame_abs_with_offset(Register newSP, Register fp, int offset, bool load_fp);458void resize_frame_absolute(Register addr, Register fp, bool load_fp);459void resize_frame(RegisterOrConstant offset, Register fp, bool load_fp=true);460461// Push a frame of size bytes, if copy_sp is false, old_sp must already462// contain a copy of Z_SP.463void push_frame(Register bytes, Register old_sp, bool copy_sp = true, bool bytes_with_inverted_sign = false);464465// Push a frame of size `bytes'. no abi space provided.466// Don't rely on register locking, instead pass a scratch register467// (Z_R0 by default).468// CAUTION! passing registers >= Z_R2 may produce bad results on469// old CPUs!470unsigned int push_frame(unsigned int bytes, Register scratch = Z_R0);471472// Push a frame of size `bytes' with abi160 on top.473unsigned int push_frame_abi160(unsigned int bytes);474475// Pop current C frame.476void pop_frame();477// Pop current C frame and restore return PC register (Z_R14).478void pop_frame_restore_retPC(int frame_size_in_bytes);479480//481// Calls482//483484private:485address _last_calls_return_pc;486487public:488// Support for VM calls. This is the base routine called by the489// different versions of call_VM_leaf. The interpreter may customize490// this version by overriding it for its purposes (e.g., to491// save/restore additional registers when doing a VM call).492void call_VM_leaf_base(address entry_point);493void call_VM_leaf_base(address entry_point, bool allow_relocation);494495// It is imperative that all calls into the VM are handled via the496// call_VM macros. They make sure that the stack linkage is setup497// correctly. Call_VM's correspond to ENTRY/ENTRY_X entry points498// while call_VM_leaf's correspond to LEAF entry points.499//500// This is the base routine called by the different versions of501// call_VM. The interpreter may customize this version by overriding502// it for its purposes (e.g., to save/restore additional registers503// when doing a VM call).504505// If no last_java_sp is specified (noreg) then SP will be used instead.506507virtual void call_VM_base(508Register oop_result, // Where an oop-result ends up if any; use noreg otherwise.509Register last_java_sp, // To set up last_Java_frame in stubs; use noreg otherwise.510address entry_point, // The entry point.511bool check_exception); // Flag which indicates if exception should be checked.512virtual void call_VM_base(513Register oop_result, // Where an oop-result ends up if any; use noreg otherwise.514Register last_java_sp, // To set up last_Java_frame in stubs; use noreg otherwise.515address entry_point, // The entry point.516bool allow_relocation, // Flag to request generation of relocatable code.517bool check_exception); // Flag which indicates if exception should be checked.518519// Call into the VM.520// Passes the thread pointer (in Z_ARG1) as a prepended argument.521// Makes sure oop return values are visible to the GC.522void call_VM(Register oop_result, address entry_point, bool check_exceptions = true);523void call_VM(Register oop_result, address entry_point, Register arg_1, bool check_exceptions = true);524void call_VM(Register oop_result, address entry_point, Register arg_1, Register arg_2, bool check_exceptions = true);525void call_VM(Register oop_result, address entry_point, Register arg_1, Register arg_2,526Register arg_3, bool check_exceptions = true);527528void call_VM_static(Register oop_result, address entry_point, bool check_exceptions = true);529void call_VM_static(Register oop_result, address entry_point, Register arg_1, Register arg_2,530Register arg_3, bool check_exceptions = true);531532// Overloaded with last_java_sp.533void call_VM(Register oop_result, Register last_java_sp, address entry_point, bool check_exceptions = true);534void call_VM(Register oop_result, Register last_java_sp, address entry_point,535Register arg_1, bool check_exceptions = true);536void call_VM(Register oop_result, Register last_java_sp, address entry_point,537Register arg_1, Register arg_2, bool check_exceptions = true);538void call_VM(Register oop_result, Register last_java_sp, address entry_point,539Register arg_1, Register arg_2, Register arg_3, bool check_exceptions = true);540541void call_VM_leaf(address entry_point);542void call_VM_leaf(address entry_point, Register arg_1);543void call_VM_leaf(address entry_point, Register arg_1, Register arg_2);544void call_VM_leaf(address entry_point, Register arg_1, Register arg_2, Register arg_3);545546// Really static VM leaf call (never patched).547void call_VM_leaf_static(address entry_point);548void call_VM_leaf_static(address entry_point, Register arg_1);549void call_VM_leaf_static(address entry_point, Register arg_1, Register arg_2);550void call_VM_leaf_static(address entry_point, Register arg_1, Register arg_2, Register arg_3);551552// Call a C function via its function entry. Updates and returns _last_calls_return_pc.553inline address call(Register function_entry);554inline address call_c(Register function_entry);555address call_c(address function_entry);556// Variant for really static (non-relocatable) calls which are never patched.557address call_c_static(address function_entry);558// TOC or pc-relative call + emits a runtime_call relocation.559address call_c_opt(address function_entry);560561inline address call_stub(Register function_entry);562inline address call_stub(address function_entry);563564// Get the pc where the last call will return to. Returns _last_calls_return_pc.565inline address last_calls_return_pc();566567private:568static bool is_call_far_patchable_variant0_at(address instruction_addr); // Dynamic TOC: load target addr from CP and call.569static bool is_call_far_patchable_variant2_at(address instruction_addr); // PC-relative call, prefixed with NOPs.570571572public:573bool call_far_patchable(address target, int64_t toc_offset);574static bool is_call_far_patchable_at(address inst_start); // All supported forms of patchable calls.575static bool is_call_far_patchable_pcrelative_at(address inst_start); // Pc-relative call with leading nops.576static bool is_call_far_pcrelative(address instruction_addr); // Pure far pc-relative call, with one leading size adjustment nop.577static void set_dest_of_call_far_patchable_at(address inst_start, address target, int64_t toc_offset);578static address get_dest_of_call_far_patchable_at(address inst_start, address toc_start);579580void align_call_far_patchable(address pc);581582// PCrelative TOC access.583584// This value is independent of code position - constant for the lifetime of the VM.585static int call_far_patchable_size() {586return load_const_from_toc_size() + call_byregister_size();587}588589static int call_far_patchable_ret_addr_offset() { return call_far_patchable_size(); }590591static bool call_far_patchable_requires_alignment_nop(address pc) {592int size = call_far_patchable_size();593return ((intptr_t)(pc + size) & 0x03L) != 0;594}595596// END OF PCrelative TOC access.597598static int jump_byregister_size() { return 2; }599static int jump_pcrelative_size() { return 4; }600static int jump_far_pcrelative_size() { return 6; }601static int call_byregister_size() { return 2; }602static int call_pcrelative_size() { return 4; }603static int call_far_pcrelative_size() { return 2 + 6; } // Prepend each BRASL with a nop.604static int call_far_pcrelative_size_raw() { return 6; } // Prepend each BRASL with a nop.605606//607// Java utilities608//609610// These routines should emit JVMTI PopFrame and ForceEarlyReturn handling code.611// The implementation is only non-empty for the InterpreterMacroAssembler,612// as only the interpreter handles PopFrame and ForceEarlyReturn requests.613virtual void check_and_handle_popframe(Register java_thread);614virtual void check_and_handle_earlyret(Register java_thread);615616// Polling page support.617enum poll_mask {618mask_stackbang = 0xde, // 222 (dec)619mask_safepoint = 0x6f, // 111 (dec)620mask_profiling = 0xba // 186 (dec)621};622623// Read from the polling page.624void load_from_polling_page(Register polling_page_address, int64_t offset = 0);625626// Check if given instruction is a read from the polling page627// as emitted by load_from_polling_page.628static bool is_load_from_polling_page(address instr_loc);629// Extract poll address from instruction and ucontext.630static address get_poll_address(address instr_loc, void* ucontext);631// Extract poll register from instruction.632static uint get_poll_register(address instr_loc);633634// Check if safepoint requested and if so branch635void safepoint_poll(Label& slow_path, Register temp_reg);636637// Stack overflow checking638void bang_stack_with_offset(int offset);639640// Check for reserved stack access in method being exited. If the reserved641// stack area was accessed, protect it again and throw StackOverflowError.642// Uses Z_R1.643void reserved_stack_check(Register return_pc);644645// Atomics646// -- none?647648void tlab_allocate(Register obj, // Result: pointer to object after successful allocation649Register var_size_in_bytes, // Object size in bytes if unknown at compile time; invalid otherwise.650int con_size_in_bytes, // Object size in bytes if known at compile time.651Register t1, // temp register652Label& slow_case); // Continuation point if fast allocation fails.653654// Emitter for interface method lookup.655// input: recv_klass, intf_klass, itable_index656// output: method_result657// kills: itable_index, temp1_reg, Z_R0, Z_R1658void lookup_interface_method(Register recv_klass,659Register intf_klass,660RegisterOrConstant itable_index,661Register method_result,662Register temp1_reg,663Label& no_such_interface,664bool return_method = true);665666// virtual method calling667void lookup_virtual_method(Register recv_klass,668RegisterOrConstant vtable_index,669Register method_result);670671// Factor out code to call ic_miss_handler.672unsigned int call_ic_miss_handler(Label& ICM, int trapMarker, int requiredSize, Register scratch);673void nmethod_UEP(Label& ic_miss);674675// Emitters for "partial subtype" checks.676677// Test sub_klass against super_klass, with fast and slow paths.678679// The fast path produces a tri-state answer: yes / no / maybe-slow.680// One of the three labels can be NULL, meaning take the fall-through.681// If super_check_offset is -1, the value is loaded up from super_klass.682// No registers are killed, except temp_reg and temp2_reg.683// If super_check_offset is not -1, temp1_reg is not used and can be noreg.684void check_klass_subtype_fast_path(Register sub_klass,685Register super_klass,686Register temp1_reg,687Label* L_success,688Label* L_failure,689Label* L_slow_path,690RegisterOrConstant super_check_offset = RegisterOrConstant(-1));691692// The rest of the type check; must be wired to a corresponding fast path.693// It does not repeat the fast path logic, so don't use it standalone.694// The temp_reg can be noreg, if no temps are available.695// It can also be sub_klass or super_klass, meaning it's OK to kill that one.696// Updates the sub's secondary super cache as necessary.697void check_klass_subtype_slow_path(Register Rsubklass,698Register Rsuperklas,699Register Rarray_ptr, // tmp700Register Rlength, // tmp701Label* L_success,702Label* L_failure);703704// Simplified, combined version, good for typical uses.705// Falls through on failure.706void check_klass_subtype(Register sub_klass,707Register super_klass,708Register temp1_reg,709Register temp2_reg,710Label& L_success);711712void clinit_barrier(Register klass,713Register thread,714Label* L_fast_path = NULL,715Label* L_slow_path = NULL);716717// Increment a counter at counter_address when the eq condition code is set.718// Kills registers tmp1_reg and tmp2_reg and preserves the condition code.719void increment_counter_eq(address counter_address, Register tmp1_reg, Register tmp2_reg);720// Biased locking support721// Upon entry,obj_reg must contain the target object, and mark_reg722// must contain the target object's header.723// Destroys mark_reg if an attempt is made to bias an anonymously724// biased lock. In this case a failure will go either to the slow725// case or fall through with the notEqual condition code set with726// the expectation that the slow case in the runtime will be called.727// In the fall-through case where the CAS-based lock is done,728// mark_reg is not destroyed.729void biased_locking_enter(Register obj_reg, Register mark_reg, Register temp_reg,730Register temp2_reg, Label& done, Label* slow_case = NULL);731// Upon entry, the base register of mark_addr must contain the oop.732// Destroys temp_reg.733// If allow_delay_slot_filling is set to true, the next instruction734// emitted after this one will go in an annulled delay slot if the735// biased locking exit case failed.736void biased_locking_exit(Register mark_addr, Register temp_reg, Label& done);737738void compiler_fast_lock_object(Register oop, Register box, Register temp1, Register temp2, bool try_bias = UseBiasedLocking);739void compiler_fast_unlock_object(Register oop, Register box, Register temp1, Register temp2, bool try_bias = UseBiasedLocking);740741void resolve_jobject(Register value, Register tmp1, Register tmp2);742743// Support for last Java frame (but use call_VM instead where possible).744private:745void set_last_Java_frame(Register last_Java_sp, Register last_Java_pc, bool allow_relocation);746void reset_last_Java_frame(bool allow_relocation);747void set_top_ijava_frame_at_SP_as_last_Java_frame(Register sp, Register tmp1, bool allow_relocation);748public:749inline void set_last_Java_frame(Register last_java_sp, Register last_Java_pc);750inline void set_last_Java_frame_static(Register last_java_sp, Register last_Java_pc);751inline void reset_last_Java_frame(void);752inline void reset_last_Java_frame_static(void);753inline void set_top_ijava_frame_at_SP_as_last_Java_frame(Register sp, Register tmp1);754inline void set_top_ijava_frame_at_SP_as_last_Java_frame_static(Register sp, Register tmp1);755756void set_thread_state(JavaThreadState new_state);757758// Read vm result from thread.759void get_vm_result (Register oop_result);760void get_vm_result_2(Register result);761762// Vm result is currently getting hijacked to for oop preservation.763void set_vm_result(Register oop_result);764765// Support for NULL-checks766//767// Generates code that causes a NULL OS exception if the content of reg is NULL.768// If the accessed location is M[reg + offset] and the offset is known, provide the769// offset. No explicit code generation is needed if the offset is within a certain770// range (0 <= offset <= page_size).771//772// %%%%%% Currently not done for z/Architecture773774void null_check(Register reg, Register tmp = Z_R0, int64_t offset = -1);775static bool needs_explicit_null_check(intptr_t offset); // Implemented in shared file ?!776static bool uses_implicit_null_check(void* address);777778// Klass oop manipulations if compressed.779void encode_klass_not_null(Register dst, Register src = noreg);780void decode_klass_not_null(Register dst, Register src);781void decode_klass_not_null(Register dst);782void load_klass(Register klass, Address mem);783void load_klass(Register klass, Register src_oop);784void load_prototype_header(Register Rheader, Register Rsrc_oop);785void store_klass(Register klass, Register dst_oop, Register ck = noreg); // Klass will get compressed if ck not provided.786void store_klass_gap(Register s, Register dst_oop);787788// This function calculates the size of the code generated by789// decode_klass_not_null(register dst)790// when (Universe::heap() != NULL). Hence, if the instructions791// it generates change, then this method needs to be updated.792static int instr_size_for_decode_klass_not_null();793794void encode_heap_oop(Register oop);795void encode_heap_oop_not_null(Register oop);796797static int get_oop_base_pow2_offset(uint64_t oop_base);798int get_oop_base(Register Rbase, uint64_t oop_base);799int get_oop_base_complement(Register Rbase, uint64_t oop_base);800void compare_heap_oop(Register Rop1, Address mem, bool maybeNULL);801void compare_klass_ptr(Register Rop1, int64_t disp, Register Rbase, bool maybeNULL);802803// Access heap oop, handle encoding and GC barriers.804private:805void access_store_at(BasicType type, DecoratorSet decorators,806const Address& addr, Register val,807Register tmp1, Register tmp2, Register tmp3);808void access_load_at(BasicType type, DecoratorSet decorators,809const Address& addr, Register dst,810Register tmp1, Register tmp2, Label *is_null = NULL);811812public:813// tmp1 and tmp2 are used with decorators ON_PHANTOM_OOP_REF or ON_WEAK_OOP_REF.814void load_heap_oop(Register dest, const Address &a,815Register tmp1, Register tmp2,816DecoratorSet decorators = 0, Label *is_null = NULL);817void store_heap_oop(Register Roop, const Address &a,818Register tmp1, Register tmp2, Register tmp3,819DecoratorSet decorators = 0);820821void oop_encoder(Register Rdst, Register Rsrc, bool maybeNULL,822Register Rbase = Z_R1, int pow2_offset = -1, bool only32bitValid = false);823void oop_decoder(Register Rdst, Register Rsrc, bool maybeNULL,824Register Rbase = Z_R1, int pow2_offset = -1);825826void resolve_oop_handle(Register result);827void load_mirror_from_const_method(Register mirror, Register const_method);828void load_method_holder(Register holder, Register method);829830//--------------------------831//--- Operations on arrays.832//--------------------------833unsigned int Clear_Array(Register cnt_arg, Register base_pointer_arg, Register odd_tmp_reg);834unsigned int Clear_Array_Const(long cnt, Register base);835unsigned int Clear_Array_Const_Big(long cnt, Register base_pointer_arg, Register odd_tmp_reg);836unsigned int CopyRawMemory_AlignedDisjoint(Register src_reg, Register dst_reg,837Register cnt_reg,838Register tmp1_reg, Register tmp2_reg);839840841// Emit an oop const to the constant pool and set a relocation info842// with address current_pc. Return the TOC offset of the constant.843int store_const_in_toc(AddressLiteral& val);844int store_oop_in_toc(AddressLiteral& oop);845// Emit an oop const to the constant pool via store_oop_in_toc, or846// emit a scalar const to the constant pool via store_const_in_toc,847// and load the constant into register dst.848bool load_const_from_toc(Register dst, AddressLiteral& a, Register Rtoc = noreg);849// Get CPU version dependent size of load_const sequence.850// The returned value is valid only for code sequences851// generated by load_const, not load_const_optimized.852static int load_const_from_toc_size() {853return load_long_pcrelative_size();854}855bool load_oop_from_toc(Register dst, AddressLiteral& a, Register Rtoc = noreg);856static intptr_t get_const_from_toc(address pc);857static void set_const_in_toc(address pc, unsigned long new_data, CodeBlob *cb);858859// Dynamic TOC.860static bool is_load_const(address a);861static bool is_load_const_from_toc_pcrelative(address a);862static bool is_load_const_from_toc(address a) { return is_load_const_from_toc_pcrelative(a); }863864// PCrelative TOC access.865static bool is_call_byregister(address a) { return is_z_basr(*(short*)a); }866static bool is_load_const_from_toc_call(address a);867static bool is_load_const_call(address a);868static int load_const_call_size() { return load_const_size() + call_byregister_size(); }869static int load_const_from_toc_call_size() { return load_const_from_toc_size() + call_byregister_size(); }870// Offset is +/- 2**32 -> use long.871static long get_load_const_from_toc_offset(address a);872873// Bit operations for single register operands.874inline void lshift(Register r, int places, bool doubl = true); // <<875inline void rshift(Register r, int places, bool doubl = true); // >>876877//878// Debugging879//880881// Assert on CC (condition code in CPU state).882void asm_assert(bool check_equal, const char* msg, int id) PRODUCT_RETURN;883void asm_assert_low(const char *msg, int id) PRODUCT_RETURN;884void asm_assert_high(const char *msg, int id) PRODUCT_RETURN;885void asm_assert_eq(const char* msg, int id) { asm_assert(true, msg, id); }886void asm_assert_ne(const char* msg, int id) { asm_assert(false, msg, id); }887888void asm_assert_static(bool check_equal, const char* msg, int id) PRODUCT_RETURN;889890private:891// Emit assertions.892void asm_assert_mems_zero(bool check_equal, bool allow_relocation, int size, int64_t mem_offset,893Register mem_base, const char* msg, int id) PRODUCT_RETURN;894895public:896inline void asm_assert_mem4_is_zero(int64_t mem_offset, Register mem_base, const char* msg, int id) {897asm_assert_mems_zero(true, true, 4, mem_offset, mem_base, msg, id);898}899inline void asm_assert_mem8_is_zero(int64_t mem_offset, Register mem_base, const char* msg, int id) {900asm_assert_mems_zero(true, true, 8, mem_offset, mem_base, msg, id);901}902inline void asm_assert_mem4_isnot_zero(int64_t mem_offset, Register mem_base, const char* msg, int id) {903asm_assert_mems_zero(false, true, 4, mem_offset, mem_base, msg, id);904}905inline void asm_assert_mem8_isnot_zero(int64_t mem_offset, Register mem_base, const char* msg, int id) {906asm_assert_mems_zero(false, true, 8, mem_offset, mem_base, msg, id);907}908909inline void asm_assert_mem4_is_zero_static(int64_t mem_offset, Register mem_base, const char* msg, int id) {910asm_assert_mems_zero(true, false, 4, mem_offset, mem_base, msg, id);911}912inline void asm_assert_mem8_is_zero_static(int64_t mem_offset, Register mem_base, const char* msg, int id) {913asm_assert_mems_zero(true, false, 8, mem_offset, mem_base, msg, id);914}915inline void asm_assert_mem4_isnot_zero_static(int64_t mem_offset, Register mem_base, const char* msg, int id) {916asm_assert_mems_zero(false, false, 4, mem_offset, mem_base, msg, id);917}918inline void asm_assert_mem8_isnot_zero_static(int64_t mem_offset, Register mem_base, const char* msg, int id) {919asm_assert_mems_zero(false, false, 8, mem_offset, mem_base, msg, id);920}921void asm_assert_frame_size(Register expected_size, Register tmp, const char* msg, int id) PRODUCT_RETURN;922923// Verify Z_thread contents.924void verify_thread();925926// Save and restore functions: Exclude Z_R0.927void save_volatile_regs( Register dst, int offset, bool include_fp, bool include_flags);928void restore_volatile_regs(Register src, int offset, bool include_fp, bool include_flags);929930// Only if +VerifyOops.931// Kills Z_R0.932void verify_oop(Register reg, const char* s = "broken oop");933// Kills Z_R0, condition code.934void verify_oop_addr(Address addr, const char* msg = "contains broken oop");935936// TODO: verify_method and klass metadata (compare against vptr?).937void _verify_method_ptr(Register reg, const char * msg, const char * file, int line) {}938void _verify_klass_ptr(Register reg, const char * msg, const char * file, int line) {}939940#define verify_method_ptr(reg) _verify_method_ptr(reg, "broken method " #reg, __FILE__, __LINE__)941#define verify_klass_ptr(reg) _verify_klass_ptr(reg, "broken klass " #reg, __FILE__, __LINE__)942943private:944// Generate printout in stop().945static const char* stop_types[];946enum {947stop_stop = 0,948stop_untested = 1,949stop_unimplemented = 2,950stop_shouldnotreachhere = 3,951stop_end = 4952};953// Prints msg and stops execution.954void stop(int type, const char* msg, int id = 0);955address stop_chain(address reentry, int type, const char* msg, int id, bool allow_relocation); // Non-relocateable code only!!956void stop_static(int type, const char* msg, int id); // Non-relocateable code only!!957958public:959960// Prints msg and stops.961address stop_chain( address reentry, const char* msg = "", int id = 0) { return stop_chain(reentry, stop_stop, msg, id, true); }962address stop_chain_static(address reentry, const char* msg = "", int id = 0) { return stop_chain(reentry, stop_stop, msg, id, false); }963void stop_static (const char* msg = "", int id = 0) { stop_static(stop_stop, msg, id); }964void stop (const char* msg = "", int id = 0) { stop(stop_stop, msg, id); }965void untested (const char* msg = "", int id = 0) { stop(stop_untested, msg, id); }966void unimplemented(const char* msg = "", int id = 0) { stop(stop_unimplemented, msg, id); }967void should_not_reach_here(const char* msg = "", int id = -1) { stop(stop_shouldnotreachhere, msg, id); }968969// Factor out part of stop into subroutine to save space.970void stop_subroutine();971972// Prints msg, but don't stop.973void warn(const char* msg);974975//-----------------------------976//--- basic block tracing code977//-----------------------------978void trace_basic_block(uint i);979void init_basic_block_trace();980// Number of bytes a basic block gets larger due to the tracing code macro (worst case).981// Currently, worst case is 48 bytes. 64 puts us securely on the safe side.982static int basic_blck_trace_blk_size_incr() { return 64; }983984// Write pattern 0x0101010101010101 in region [low-before, high+after].985// Low and high may be the same registers. Before and after are986// the numbers of 8-byte words.987void zap_from_to(Register low, Register high, Register tmp1 = Z_R0, Register tmp2 = Z_R1,988int before = 0, int after = 0) PRODUCT_RETURN;989990// Emitters for CRC32 calculation.991// A note on invertCRC:992// Unfortunately, internal representation of crc differs between CRC32 and CRC32C.993// CRC32 holds it's current crc value in the externally visible representation.994// CRC32C holds it's current crc value in internal format, ready for updating.995// Thus, the crc value must be bit-flipped before updating it in the CRC32 case.996// In the CRC32C case, it must be bit-flipped when it is given to the outside world (getValue()).997// The bool invertCRC parameter indicates whether bit-flipping is required before updates.998private:999void fold_byte_crc32(Register crc, Register table, Register val, Register tmp);1000void fold_8bit_crc32(Register crc, Register table, Register tmp);1001void update_byte_crc32( Register crc, Register val, Register table);1002void update_byteLoop_crc32(Register crc, Register buf, Register len, Register table,1003Register data);1004void update_1word_crc32(Register crc, Register buf, Register table, int bufDisp, int bufInc,1005Register t0, Register t1, Register t2, Register t3);1006public:1007void kernel_crc32_singleByteReg(Register crc, Register val, Register table,1008bool invertCRC);1009void kernel_crc32_singleByte(Register crc, Register buf, Register len, Register table, Register tmp,1010bool invertCRC);1011void kernel_crc32_1byte(Register crc, Register buf, Register len, Register table,1012Register t0, Register t1, Register t2, Register t3,1013bool invertCRC);1014void kernel_crc32_1word(Register crc, Register buf, Register len, Register table,1015Register t0, Register t1, Register t2, Register t3,1016bool invertCRC);10171018// Emitters for BigInteger.multiplyToLen intrinsic1019// note: length of result array (zlen) is passed on the stack1020private:1021void add2_with_carry(Register dest_hi, Register dest_lo,1022Register src1, Register src2);1023void multiply_64_x_64_loop(Register x, Register xstart,1024Register x_xstart,1025Register y, Register y_idx, Register z,1026Register carry, Register product,1027Register idx, Register kdx);1028void multiply_add_128_x_128(Register x_xstart, Register y, Register z,1029Register yz_idx, Register idx,1030Register carry, Register product, int offset);1031void multiply_128_x_128_loop(Register x_xstart,1032Register y, Register z,1033Register yz_idx, Register idx,1034Register jdx,1035Register carry, Register product,1036Register carry2);1037public:1038void multiply_to_len(Register x, Register xlen,1039Register y, Register ylen,1040Register z,1041Register tmp1, Register tmp2,1042Register tmp3, Register tmp4, Register tmp5);1043};10441045/**1046* class SkipIfEqual:1047*1048* Instantiating this class will result in assembly code being output that will1049* jump around any code emitted between the creation of the instance and it's1050* automatic destruction at the end of a scope block, depending on the value of1051* the flag passed to the constructor, which will be checked at run-time.1052*/1053class SkipIfEqual {1054private:1055MacroAssembler* _masm;1056Label _label;10571058public:1059SkipIfEqual(MacroAssembler*, const bool* flag_addr, bool value, Register _rscratch);1060~SkipIfEqual();1061};10621063#ifdef ASSERT1064// Return false (e.g. important for our impl. of virtual calls).1065inline bool AbstractAssembler::pd_check_instruction_mark() { return false; }1066#endif10671068#endif // CPU_S390_MACROASSEMBLER_S390_HPP106910701071