src/cpu/ppc/vm/macroAssembler_ppc.hpp

Wed, 11 Dec 2013 00:06:11 +0100

author
goetz
date
Wed, 11 Dec 2013 00:06:11 +0100
changeset 6495
67fa91961822
parent 6477
eb178e97560c
child 6511
31e80afe3fed
permissions
-rw-r--r--

8029940: PPC64 (part 122): C2 compiler port
Reviewed-by: kvn

goetz@6458 1 /*
goetz@6458 2 * Copyright (c) 2002, 2013, Oracle and/or its affiliates. All rights reserved.
goetz@6458 3 * Copyright 2012, 2013 SAP AG. All rights reserved.
goetz@6458 4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
goetz@6458 5 *
goetz@6458 6 * This code is free software; you can redistribute it and/or modify it
goetz@6458 7 * under the terms of the GNU General Public License version 2 only, as
goetz@6458 8 * published by the Free Software Foundation.
goetz@6458 9 *
goetz@6458 10 * This code is distributed in the hope that it will be useful, but WITHOUT
goetz@6458 11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
goetz@6458 12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
goetz@6458 13 * version 2 for more details (a copy is included in the LICENSE file that
goetz@6458 14 * accompanied this code).
goetz@6458 15 *
goetz@6458 16 * You should have received a copy of the GNU General Public License version
goetz@6458 17 * 2 along with this work; if not, write to the Free Software Foundation,
goetz@6458 18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
goetz@6458 19 *
goetz@6458 20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
goetz@6458 21 * or visit www.oracle.com if you need additional information or have any
goetz@6458 22 * questions.
goetz@6458 23 *
goetz@6458 24 */
goetz@6458 25
goetz@6458 26 #ifndef CPU_PPC_VM_MACROASSEMBLER_PPC_HPP
goetz@6458 27 #define CPU_PPC_VM_MACROASSEMBLER_PPC_HPP
goetz@6458 28
goetz@6458 29 #include "asm/assembler.hpp"
goetz@6458 30
goetz@6458 31 // MacroAssembler extends Assembler by a few frequently used macros.
goetz@6458 32
goetz@6458 33 class ciTypeArray;
goetz@6458 34
goetz@6458 35 class MacroAssembler: public Assembler {
goetz@6458 36 public:
goetz@6458 37 MacroAssembler(CodeBuffer* code) : Assembler(code) {}
goetz@6458 38
goetz@6458 39 //
goetz@6458 40 // Optimized instruction emitters
goetz@6458 41 //
goetz@6458 42
goetz@6458 43 inline static int largeoffset_si16_si16_hi(int si31) { return (si31 + (1<<15)) >> 16; }
goetz@6458 44 inline static int largeoffset_si16_si16_lo(int si31) { return si31 - (((si31 + (1<<15)) >> 16) << 16); }
goetz@6458 45
goetz@6458 46 // load d = *[a+si31]
goetz@6458 47 // Emits several instructions if the offset is not encodable in one instruction.
goetz@6458 48 void ld_largeoffset_unchecked(Register d, int si31, Register a, int emit_filler_nop);
goetz@6458 49 void ld_largeoffset (Register d, int si31, Register a, int emit_filler_nop);
goetz@6458 50 inline static bool is_ld_largeoffset(address a);
goetz@6458 51 inline static int get_ld_largeoffset_offset(address a);
goetz@6458 52
goetz@6458 53 inline void round_to(Register r, int modulus);
goetz@6458 54
goetz@6458 55 // Load/store with type given by parameter.
goetz@6458 56 void load_sized_value( Register dst, RegisterOrConstant offs, Register base, size_t size_in_bytes, bool is_signed);
goetz@6458 57 void store_sized_value(Register dst, RegisterOrConstant offs, Register base, size_t size_in_bytes);
goetz@6458 58
goetz@6458 59 // Move register if destination register and target register are different
goetz@6458 60 inline void mr_if_needed(Register rd, Register rs);
goetz@6495 61 inline void fmr_if_needed(FloatRegister rd, FloatRegister rs);
goetz@6495 62 // This is dedicated for emitting scheduled mach nodes. For better
goetz@6495 63 // readability of the ad file I put it here.
goetz@6495 64 // Endgroups are not needed if
goetz@6495 65 // - the scheduler is off
goetz@6495 66 // - the scheduler found that there is a natural group end, in that
goetz@6495 67 // case it reduced the size of the instruction used in the test
goetz@6495 68 // yielding 'needed'.
goetz@6495 69 inline void endgroup_if_needed(bool needed);
goetz@6495 70
goetz@6495 71 // Memory barriers.
goetz@6495 72 inline void membar(int bits);
goetz@6495 73 inline void release();
goetz@6495 74 inline void acquire();
goetz@6495 75 inline void fence();
goetz@6458 76
goetz@6458 77 // nop padding
goetz@6495 78 void align(int modulus, int max = 252, int rem = 0);
goetz@6458 79
goetz@6458 80 //
goetz@6458 81 // Constants, loading constants, TOC support
goetz@6458 82 //
goetz@6458 83
goetz@6458 84 // Address of the global TOC.
goetz@6458 85 inline static address global_toc();
goetz@6458 86 // Offset of given address to the global TOC.
goetz@6458 87 inline static int offset_to_global_toc(const address addr);
goetz@6458 88
goetz@6458 89 // Address of TOC of the current method.
goetz@6458 90 inline address method_toc();
goetz@6458 91 // Offset of given address to TOC of the current method.
goetz@6458 92 inline int offset_to_method_toc(const address addr);
goetz@6458 93
goetz@6458 94 // Global TOC.
goetz@6458 95 void calculate_address_from_global_toc(Register dst, address addr,
goetz@6458 96 bool hi16 = true, bool lo16 = true,
goetz@6458 97 bool add_relocation = true, bool emit_dummy_addr = false);
goetz@6458 98 inline void calculate_address_from_global_toc_hi16only(Register dst, address addr) {
goetz@6458 99 calculate_address_from_global_toc(dst, addr, true, false);
goetz@6458 100 };
goetz@6458 101 inline void calculate_address_from_global_toc_lo16only(Register dst, address addr) {
goetz@6458 102 calculate_address_from_global_toc(dst, addr, false, true);
goetz@6458 103 };
goetz@6458 104
goetz@6458 105 inline static bool is_calculate_address_from_global_toc_at(address a, address bound);
goetz@6458 106 static int patch_calculate_address_from_global_toc_at(address a, address addr, address bound);
goetz@6458 107 static address get_address_of_calculate_address_from_global_toc_at(address a, address addr);
goetz@6458 108
goetz@6458 109 #ifdef _LP64
goetz@6458 110 // Patch narrow oop constant.
goetz@6458 111 inline static bool is_set_narrow_oop(address a, address bound);
goetz@6458 112 static int patch_set_narrow_oop(address a, address bound, narrowOop data);
goetz@6458 113 static narrowOop get_narrow_oop(address a, address bound);
goetz@6458 114 #endif
goetz@6458 115
goetz@6458 116 inline static bool is_load_const_at(address a);
goetz@6458 117
goetz@6458 118 // Emits an oop const to the constant pool, loads the constant, and
goetz@6458 119 // sets a relocation info with address current_pc.
goetz@6458 120 void load_const_from_method_toc(Register dst, AddressLiteral& a, Register toc);
goetz@6458 121 void load_toc_from_toc(Register dst, AddressLiteral& a, Register toc) {
goetz@6458 122 assert(dst == R2_TOC, "base register must be TOC");
goetz@6458 123 load_const_from_method_toc(dst, a, toc);
goetz@6458 124 }
goetz@6458 125
goetz@6458 126 static bool is_load_const_from_method_toc_at(address a);
goetz@6458 127 static int get_offset_of_load_const_from_method_toc_at(address a);
goetz@6458 128
goetz@6458 129 // Get the 64 bit constant from a `load_const' sequence.
goetz@6458 130 static long get_const(address load_const);
goetz@6458 131
goetz@6458 132 // Patch the 64 bit constant of a `load_const' sequence. This is a
goetz@6458 133 // low level procedure. It neither flushes the instruction cache nor
goetz@6458 134 // is it atomic.
goetz@6458 135 static void patch_const(address load_const, long x);
goetz@6458 136
goetz@6458 137 // Metadata in code that we have to keep track of.
goetz@6458 138 AddressLiteral allocate_metadata_address(Metadata* obj); // allocate_index
goetz@6458 139 AddressLiteral constant_metadata_address(Metadata* obj); // find_index
goetz@6458 140 // Oops used directly in compiled code are stored in the constant pool,
goetz@6458 141 // and loaded from there.
goetz@6458 142 // Allocate new entry for oop in constant pool. Generate relocation.
goetz@6458 143 AddressLiteral allocate_oop_address(jobject obj);
goetz@6458 144 // Find oop obj in constant pool. Return relocation with it's index.
goetz@6458 145 AddressLiteral constant_oop_address(jobject obj);
goetz@6458 146
goetz@6458 147 // Find oop in constant pool and emit instructions to load it.
goetz@6458 148 // Uses constant_oop_address.
goetz@6458 149 inline void set_oop_constant(jobject obj, Register d);
goetz@6458 150 // Same as load_address.
goetz@6458 151 inline void set_oop (AddressLiteral obj_addr, Register d);
goetz@6458 152
goetz@6458 153 // Read runtime constant: Issue load if constant not yet established,
goetz@6458 154 // else use real constant.
goetz@6458 155 virtual RegisterOrConstant delayed_value_impl(intptr_t* delayed_value_addr,
goetz@6458 156 Register tmp,
goetz@6458 157 int offset);
goetz@6458 158
goetz@6458 159 //
goetz@6458 160 // branch, jump
goetz@6458 161 //
goetz@6458 162
goetz@6458 163 inline void pd_patch_instruction(address branch, address target);
goetz@6458 164 NOT_PRODUCT(static void pd_print_patched_instruction(address branch);)
goetz@6458 165
goetz@6458 166 // Conditional far branch for destinations encodable in 24+2 bits.
goetz@6458 167 // Same interface as bc, e.g. no inverse boint-field.
goetz@6458 168 enum {
goetz@6458 169 bc_far_optimize_not = 0,
goetz@6458 170 bc_far_optimize_on_relocate = 1
goetz@6458 171 };
goetz@6458 172 // optimize: flag for telling the conditional far branch to optimize
goetz@6458 173 // itself when relocated.
goetz@6458 174 void bc_far(int boint, int biint, Label& dest, int optimize);
goetz@6458 175 // Relocation of conditional far branches.
goetz@6458 176 static bool is_bc_far_at(address instruction_addr);
goetz@6458 177 static address get_dest_of_bc_far_at(address instruction_addr);
goetz@6458 178 static void set_dest_of_bc_far_at(address instruction_addr, address dest);
goetz@6458 179 private:
goetz@6458 180 static bool inline is_bc_far_variant1_at(address instruction_addr);
goetz@6458 181 static bool inline is_bc_far_variant2_at(address instruction_addr);
goetz@6458 182 static bool inline is_bc_far_variant3_at(address instruction_addr);
goetz@6458 183 public:
goetz@6458 184
goetz@6458 185 // Convenience bc_far versions.
goetz@6458 186 inline void blt_far(ConditionRegister crx, Label& L, int optimize);
goetz@6458 187 inline void bgt_far(ConditionRegister crx, Label& L, int optimize);
goetz@6458 188 inline void beq_far(ConditionRegister crx, Label& L, int optimize);
goetz@6458 189 inline void bso_far(ConditionRegister crx, Label& L, int optimize);
goetz@6458 190 inline void bge_far(ConditionRegister crx, Label& L, int optimize);
goetz@6458 191 inline void ble_far(ConditionRegister crx, Label& L, int optimize);
goetz@6458 192 inline void bne_far(ConditionRegister crx, Label& L, int optimize);
goetz@6458 193 inline void bns_far(ConditionRegister crx, Label& L, int optimize);
goetz@6458 194
goetz@6458 195 // Emit, identify and patch a NOT mt-safe patchable 64 bit absolute call/jump.
goetz@6458 196 private:
goetz@6458 197 enum {
goetz@6458 198 bxx64_patchable_instruction_count = (2/*load_codecache_const*/ + 3/*5load_const*/ + 1/*mtctr*/ + 1/*bctrl*/),
goetz@6458 199 bxx64_patchable_size = bxx64_patchable_instruction_count * BytesPerInstWord,
goetz@6458 200 bxx64_patchable_ret_addr_offset = bxx64_patchable_size
goetz@6458 201 };
goetz@6458 202 void bxx64_patchable(address target, relocInfo::relocType rt, bool link);
goetz@6458 203 static bool is_bxx64_patchable_at( address instruction_addr, bool link);
goetz@6458 204 // Does the instruction use a pc-relative encoding of the destination?
goetz@6458 205 static bool is_bxx64_patchable_pcrelative_at( address instruction_addr, bool link);
goetz@6458 206 static bool is_bxx64_patchable_variant1_at( address instruction_addr, bool link);
goetz@6458 207 // Load destination relative to global toc.
goetz@6458 208 static bool is_bxx64_patchable_variant1b_at( address instruction_addr, bool link);
goetz@6458 209 static bool is_bxx64_patchable_variant2_at( address instruction_addr, bool link);
goetz@6458 210 static void set_dest_of_bxx64_patchable_at( address instruction_addr, address target, bool link);
goetz@6458 211 static address get_dest_of_bxx64_patchable_at(address instruction_addr, bool link);
goetz@6458 212
goetz@6458 213 public:
goetz@6458 214 // call
goetz@6458 215 enum {
goetz@6458 216 bl64_patchable_instruction_count = bxx64_patchable_instruction_count,
goetz@6458 217 bl64_patchable_size = bxx64_patchable_size,
goetz@6458 218 bl64_patchable_ret_addr_offset = bxx64_patchable_ret_addr_offset
goetz@6458 219 };
goetz@6458 220 inline void bl64_patchable(address target, relocInfo::relocType rt) {
goetz@6458 221 bxx64_patchable(target, rt, /*link=*/true);
goetz@6458 222 }
goetz@6458 223 inline static bool is_bl64_patchable_at(address instruction_addr) {
goetz@6458 224 return is_bxx64_patchable_at(instruction_addr, /*link=*/true);
goetz@6458 225 }
goetz@6458 226 inline static bool is_bl64_patchable_pcrelative_at(address instruction_addr) {
goetz@6458 227 return is_bxx64_patchable_pcrelative_at(instruction_addr, /*link=*/true);
goetz@6458 228 }
goetz@6458 229 inline static void set_dest_of_bl64_patchable_at(address instruction_addr, address target) {
goetz@6458 230 set_dest_of_bxx64_patchable_at(instruction_addr, target, /*link=*/true);
goetz@6458 231 }
goetz@6458 232 inline static address get_dest_of_bl64_patchable_at(address instruction_addr) {
goetz@6458 233 return get_dest_of_bxx64_patchable_at(instruction_addr, /*link=*/true);
goetz@6458 234 }
goetz@6458 235 // jump
goetz@6458 236 enum {
goetz@6458 237 b64_patchable_instruction_count = bxx64_patchable_instruction_count,
goetz@6458 238 b64_patchable_size = bxx64_patchable_size,
goetz@6458 239 };
goetz@6458 240 inline void b64_patchable(address target, relocInfo::relocType rt) {
goetz@6458 241 bxx64_patchable(target, rt, /*link=*/false);
goetz@6458 242 }
goetz@6458 243 inline static bool is_b64_patchable_at(address instruction_addr) {
goetz@6458 244 return is_bxx64_patchable_at(instruction_addr, /*link=*/false);
goetz@6458 245 }
goetz@6458 246 inline static bool is_b64_patchable_pcrelative_at(address instruction_addr) {
goetz@6458 247 return is_bxx64_patchable_pcrelative_at(instruction_addr, /*link=*/false);
goetz@6458 248 }
goetz@6458 249 inline static void set_dest_of_b64_patchable_at(address instruction_addr, address target) {
goetz@6458 250 set_dest_of_bxx64_patchable_at(instruction_addr, target, /*link=*/false);
goetz@6458 251 }
goetz@6458 252 inline static address get_dest_of_b64_patchable_at(address instruction_addr) {
goetz@6458 253 return get_dest_of_bxx64_patchable_at(instruction_addr, /*link=*/false);
goetz@6458 254 }
goetz@6458 255
goetz@6458 256 //
goetz@6458 257 // Support for frame handling
goetz@6458 258 //
goetz@6458 259
goetz@6458 260 // some ABI-related functions
goetz@6458 261 void save_nonvolatile_gprs( Register dst_base, int offset);
goetz@6458 262 void restore_nonvolatile_gprs(Register src_base, int offset);
goetz@6458 263 void save_volatile_gprs( Register dst_base, int offset);
goetz@6458 264 void restore_volatile_gprs(Register src_base, int offset);
goetz@6458 265 void save_LR_CR( Register tmp); // tmp contains LR on return.
goetz@6458 266 void restore_LR_CR(Register tmp);
goetz@6458 267
goetz@6458 268 // Get current PC using bl-next-instruction trick.
goetz@6458 269 address get_PC_trash_LR(Register result);
goetz@6458 270
goetz@6458 271 // Resize current frame either relatively wrt to current SP or absolute.
goetz@6458 272 void resize_frame(Register offset, Register tmp);
goetz@6458 273 void resize_frame(int offset, Register tmp);
goetz@6458 274 void resize_frame_absolute(Register addr, Register tmp1, Register tmp2);
goetz@6458 275
goetz@6458 276 // Push a frame of size bytes.
goetz@6458 277 void push_frame(Register bytes, Register tmp);
goetz@6458 278
goetz@6458 279 // Push a frame of size `bytes'. No abi space provided.
goetz@6458 280 void push_frame(unsigned int bytes, Register tmp);
goetz@6458 281
goetz@6458 282 // Push a frame of size `bytes' plus abi112 on top.
goetz@6458 283 void push_frame_abi112(unsigned int bytes, Register tmp);
goetz@6458 284
goetz@6458 285 // Setup up a new C frame with a spill area for non-volatile GPRs and additional
goetz@6458 286 // space for local variables
goetz@6458 287 void push_frame_abi112_nonvolatiles(unsigned int bytes, Register tmp);
goetz@6458 288
goetz@6458 289 // pop current C frame
goetz@6458 290 void pop_frame();
goetz@6458 291
goetz@6458 292 //
goetz@6458 293 // Calls
goetz@6458 294 //
goetz@6458 295
goetz@6458 296 private:
goetz@6458 297 address _last_calls_return_pc;
goetz@6458 298
goetz@6458 299 // Generic version of a call to C function via a function descriptor
goetz@6458 300 // with variable support for C calling conventions (TOC, ENV, etc.).
goetz@6458 301 // updates and returns _last_calls_return_pc.
goetz@6458 302 address branch_to(Register function_descriptor, bool and_link, bool save_toc_before_call,
goetz@6458 303 bool restore_toc_after_call, bool load_toc_of_callee, bool load_env_of_callee);
goetz@6458 304
goetz@6458 305 public:
goetz@6458 306
goetz@6458 307 // Get the pc where the last call will return to. returns _last_calls_return_pc.
goetz@6458 308 inline address last_calls_return_pc();
goetz@6458 309
goetz@6458 310 // Call a C function via a function descriptor and use full C
goetz@6458 311 // calling conventions. Updates and returns _last_calls_return_pc.
goetz@6458 312 address call_c(Register function_descriptor);
goetz@6495 313 // For tail calls: only branch, don't link, so callee returns to caller of this function.
goetz@6495 314 address call_c_and_return_to_caller(Register function_descriptor);
goetz@6458 315 address call_c(const FunctionDescriptor* function_descriptor, relocInfo::relocType rt);
goetz@6458 316 address call_c_using_toc(const FunctionDescriptor* function_descriptor, relocInfo::relocType rt,
goetz@6458 317 Register toc);
goetz@6458 318
goetz@6458 319 protected:
goetz@6458 320
goetz@6458 321 // It is imperative that all calls into the VM are handled via the
goetz@6458 322 // call_VM macros. They make sure that the stack linkage is setup
goetz@6458 323 // correctly. call_VM's correspond to ENTRY/ENTRY_X entry points
goetz@6458 324 // while call_VM_leaf's correspond to LEAF entry points.
goetz@6458 325 //
goetz@6458 326 // This is the base routine called by the different versions of
goetz@6458 327 // call_VM. The interpreter may customize this version by overriding
goetz@6458 328 // it for its purposes (e.g., to save/restore additional registers
goetz@6458 329 // when doing a VM call).
goetz@6458 330 //
goetz@6458 331 // If no last_java_sp is specified (noreg) then SP will be used instead.
goetz@6458 332 virtual void call_VM_base(
goetz@6458 333 // where an oop-result ends up if any; use noreg otherwise
goetz@6458 334 Register oop_result,
goetz@6458 335 // to set up last_Java_frame in stubs; use noreg otherwise
goetz@6458 336 Register last_java_sp,
goetz@6458 337 // the entry point
goetz@6458 338 address entry_point,
goetz@6458 339 // flag which indicates if exception should be checked
goetz@6495 340 bool check_exception = true
goetz@6458 341 );
goetz@6458 342
goetz@6458 343 // Support for VM calls. This is the base routine called by the
goetz@6458 344 // different versions of call_VM_leaf. The interpreter may customize
goetz@6458 345 // this version by overriding it for its purposes (e.g., to
goetz@6458 346 // save/restore additional registers when doing a VM call).
goetz@6458 347 void call_VM_leaf_base(address entry_point);
goetz@6458 348
goetz@6458 349 public:
goetz@6458 350 // Call into the VM.
goetz@6458 351 // Passes the thread pointer (in R3_ARG1) as a prepended argument.
goetz@6458 352 // Makes sure oop return values are visible to the GC.
goetz@6458 353 void call_VM(Register oop_result, address entry_point, bool check_exceptions = true);
goetz@6458 354 void call_VM(Register oop_result, address entry_point, Register arg_1, bool check_exceptions = true);
goetz@6458 355 void call_VM(Register oop_result, address entry_point, Register arg_1, Register arg_2, bool check_exceptions = true);
goetz@6458 356 void call_VM_leaf(address entry_point);
goetz@6458 357 void call_VM_leaf(address entry_point, Register arg_1);
goetz@6458 358 void call_VM_leaf(address entry_point, Register arg_1, Register arg_2);
goetz@6458 359 void call_VM_leaf(address entry_point, Register arg_1, Register arg_2, Register arg_3);
goetz@6458 360
goetz@6458 361 // Call a stub function via a function descriptor, but don't save
goetz@6458 362 // TOC before call, don't setup TOC and ENV for call, and don't
goetz@6458 363 // restore TOC after call. Updates and returns _last_calls_return_pc.
goetz@6458 364 inline address call_stub(Register function_entry);
goetz@6458 365 inline void call_stub_and_return_to(Register function_entry, Register return_pc);
goetz@6458 366
goetz@6458 367 //
goetz@6458 368 // Java utilities
goetz@6458 369 //
goetz@6458 370
goetz@6458 371 // Read from the polling page, its address is already in a register.
goetz@6458 372 inline void load_from_polling_page(Register polling_page_address, int offset = 0);
goetz@6458 373 // Check whether instruction is a read access to the polling page
goetz@6458 374 // which was emitted by load_from_polling_page(..).
goetz@6458 375 static bool is_load_from_polling_page(int instruction, void* ucontext/*may be NULL*/,
goetz@6458 376 address* polling_address_ptr = NULL);
goetz@6458 377
goetz@6458 378 // Check whether instruction is a write access to the memory
goetz@6458 379 // serialization page realized by one of the instructions stw, stwu,
goetz@6458 380 // stwx, or stwux.
goetz@6458 381 static bool is_memory_serialization(int instruction, JavaThread* thread, void* ucontext);
goetz@6458 382
goetz@6458 383 // Support for NULL-checks
goetz@6458 384 //
goetz@6458 385 // Generates code that causes a NULL OS exception if the content of reg is NULL.
goetz@6458 386 // If the accessed location is M[reg + offset] and the offset is known, provide the
goetz@6458 387 // offset. No explicit code generation is needed if the offset is within a certain
goetz@6458 388 // range (0 <= offset <= page_size).
goetz@6458 389
goetz@6458 390 // Stack overflow checking
goetz@6458 391 void bang_stack_with_offset(int offset);
goetz@6458 392
goetz@6458 393 // If instruction is a stack bang of the form ld, stdu, or
goetz@6458 394 // stdux, return the banged address. Otherwise, return 0.
goetz@6458 395 static address get_stack_bang_address(int instruction, void* ucontext);
goetz@6458 396
goetz@6458 397 // Atomics
goetz@6458 398 // CmpxchgX sets condition register to cmpX(current, compare).
goetz@6458 399 // (flag == ne) => (dest_current_value != compare_value), (!swapped)
goetz@6458 400 // (flag == eq) => (dest_current_value == compare_value), ( swapped)
goetz@6458 401 static inline bool cmpxchgx_hint_acquire_lock() { return true; }
goetz@6458 402 // The stxcx will probably not be succeeded by a releasing store.
goetz@6458 403 static inline bool cmpxchgx_hint_release_lock() { return false; }
goetz@6458 404 static inline bool cmpxchgx_hint_atomic_update() { return false; }
goetz@6458 405
goetz@6458 406 // Cmpxchg semantics
goetz@6458 407 enum {
goetz@6458 408 MemBarNone = 0,
goetz@6458 409 MemBarRel = 1,
goetz@6458 410 MemBarAcq = 2,
goetz@6458 411 MemBarFenceAfter = 4 // use powers of 2
goetz@6458 412 };
goetz@6458 413 void cmpxchgw(ConditionRegister flag,
goetz@6458 414 Register dest_current_value, Register compare_value, Register exchange_value, Register addr_base,
goetz@6458 415 int semantics, bool cmpxchgx_hint = false,
goetz@6458 416 Register int_flag_success = noreg, bool contention_hint = false);
goetz@6458 417 void cmpxchgd(ConditionRegister flag,
goetz@6458 418 Register dest_current_value, Register compare_value, Register exchange_value, Register addr_base,
goetz@6458 419 int semantics, bool cmpxchgx_hint = false,
goetz@6458 420 Register int_flag_success = noreg, Label* failed = NULL, bool contention_hint = false);
goetz@6458 421
goetz@6458 422 // interface method calling
goetz@6458 423 void lookup_interface_method(Register recv_klass,
goetz@6458 424 Register intf_klass,
goetz@6458 425 RegisterOrConstant itable_index,
goetz@6458 426 Register method_result,
goetz@6458 427 Register temp_reg, Register temp2_reg,
goetz@6458 428 Label& no_such_interface);
goetz@6458 429
goetz@6458 430 // virtual method calling
goetz@6458 431 void lookup_virtual_method(Register recv_klass,
goetz@6458 432 RegisterOrConstant vtable_index,
goetz@6458 433 Register method_result);
goetz@6458 434
goetz@6458 435 // Test sub_klass against super_klass, with fast and slow paths.
goetz@6458 436
goetz@6458 437 // The fast path produces a tri-state answer: yes / no / maybe-slow.
goetz@6458 438 // One of the three labels can be NULL, meaning take the fall-through.
goetz@6458 439 // If super_check_offset is -1, the value is loaded up from super_klass.
goetz@6458 440 // No registers are killed, except temp_reg and temp2_reg.
goetz@6458 441 // If super_check_offset is not -1, temp2_reg is not used and can be noreg.
goetz@6458 442 void check_klass_subtype_fast_path(Register sub_klass,
goetz@6458 443 Register super_klass,
goetz@6458 444 Register temp1_reg,
goetz@6458 445 Register temp2_reg,
goetz@6458 446 Label& L_success,
goetz@6458 447 Label& L_failure);
goetz@6458 448
goetz@6458 449 // The rest of the type check; must be wired to a corresponding fast path.
goetz@6458 450 // It does not repeat the fast path logic, so don't use it standalone.
goetz@6458 451 // The temp_reg can be noreg, if no temps are available.
goetz@6458 452 // It can also be sub_klass or super_klass, meaning it's OK to kill that one.
goetz@6458 453 // Updates the sub's secondary super cache as necessary.
goetz@6458 454 void check_klass_subtype_slow_path(Register sub_klass,
goetz@6458 455 Register super_klass,
goetz@6458 456 Register temp1_reg,
goetz@6458 457 Register temp2_reg,
goetz@6458 458 Label* L_success = NULL,
goetz@6458 459 Register result_reg = noreg);
goetz@6458 460
goetz@6458 461 // Simplified, combined version, good for typical uses.
goetz@6458 462 // Falls through on failure.
goetz@6458 463 void check_klass_subtype(Register sub_klass,
goetz@6458 464 Register super_klass,
goetz@6458 465 Register temp1_reg,
goetz@6458 466 Register temp2_reg,
goetz@6458 467 Label& L_success);
goetz@6458 468
goetz@6458 469 // Method handle support (JSR 292).
goetz@6458 470 void check_method_handle_type(Register mtype_reg, Register mh_reg, Register temp_reg, Label& wrong_method_type);
goetz@6458 471
goetz@6458 472 RegisterOrConstant argument_offset(RegisterOrConstant arg_slot, Register temp_reg, int extra_slot_offset = 0);
goetz@6458 473
goetz@6458 474 // Biased locking support
goetz@6458 475 // Upon entry,obj_reg must contain the target object, and mark_reg
goetz@6458 476 // must contain the target object's header.
goetz@6458 477 // Destroys mark_reg if an attempt is made to bias an anonymously
goetz@6458 478 // biased lock. In this case a failure will go either to the slow
goetz@6458 479 // case or fall through with the notEqual condition code set with
goetz@6458 480 // the expectation that the slow case in the runtime will be called.
goetz@6458 481 // In the fall-through case where the CAS-based lock is done,
goetz@6458 482 // mark_reg is not destroyed.
goetz@6458 483 void biased_locking_enter(ConditionRegister cr_reg, Register obj_reg, Register mark_reg, Register temp_reg,
goetz@6458 484 Register temp2_reg, Label& done, Label* slow_case = NULL);
goetz@6458 485 // Upon entry, the base register of mark_addr must contain the oop.
goetz@6458 486 // Destroys temp_reg.
goetz@6458 487 // If allow_delay_slot_filling is set to true, the next instruction
goetz@6458 488 // emitted after this one will go in an annulled delay slot if the
goetz@6458 489 // biased locking exit case failed.
goetz@6458 490 void biased_locking_exit(ConditionRegister cr_reg, Register mark_addr, Register temp_reg, Label& done);
goetz@6458 491
goetz@6458 492 void compiler_fast_lock_object( ConditionRegister flag, Register oop, Register box, Register tmp1, Register tmp2, Register tmp3);
goetz@6458 493 void compiler_fast_unlock_object(ConditionRegister flag, Register oop, Register box, Register tmp1, Register tmp2, Register tmp3);
goetz@6458 494
goetz@6458 495 // Support for serializing memory accesses between threads
goetz@6458 496 void serialize_memory(Register thread, Register tmp1, Register tmp2);
goetz@6458 497
goetz@6458 498 // GC barrier support.
goetz@6458 499 void card_write_barrier_post(Register Rstore_addr, Register Rnew_val, Register Rtmp);
goetz@6458 500 void card_table_write(jbyte* byte_map_base, Register Rtmp, Register Robj);
goetz@6458 501
goetz@6458 502 #ifndef SERIALGC
goetz@6458 503 // General G1 pre-barrier generator.
goetz@6458 504 void g1_write_barrier_pre(Register Robj, RegisterOrConstant offset, Register Rpre_val,
goetz@6458 505 Register Rtmp1, Register Rtmp2, bool needs_frame = false);
goetz@6458 506 // General G1 post-barrier generator
goetz@6458 507 void g1_write_barrier_post(Register Rstore_addr, Register Rnew_val, Register Rtmp1,
goetz@6458 508 Register Rtmp2, Register Rtmp3, Label *filtered_ext = NULL);
goetz@6458 509 #endif // SERIALGC
goetz@6458 510
goetz@6458 511 // Support for managing the JavaThread pointer (i.e.; the reference to
goetz@6458 512 // thread-local information).
goetz@6458 513
goetz@6458 514 // Support for last Java frame (but use call_VM instead where possible):
goetz@6458 515 // access R16_thread->last_Java_sp.
goetz@6458 516 void set_last_Java_frame(Register last_java_sp, Register last_Java_pc);
goetz@6458 517 void reset_last_Java_frame(void);
goetz@6458 518 void set_top_ijava_frame_at_SP_as_last_Java_frame(Register sp, Register tmp1);
goetz@6458 519
goetz@6458 520 // Read vm result from thread: oop_result = R16_thread->result;
goetz@6458 521 void get_vm_result (Register oop_result);
goetz@6458 522 void get_vm_result_2(Register metadata_result);
goetz@6458 523
goetz@6458 524 static bool needs_explicit_null_check(intptr_t offset);
goetz@6458 525
goetz@6458 526 // Trap-instruction-based checks.
goetz@6458 527 // Range checks can be distinguished from zero checks as they check 32 bit,
goetz@6458 528 // zero checks all 64 bits (tw, td).
goetz@6458 529 inline void trap_null_check(Register a, trap_to_bits cmp = traptoEqual);
goetz@6458 530 static bool is_trap_null_check(int x) {
goetz@6458 531 return is_tdi(x, traptoEqual, -1/*any reg*/, 0) ||
goetz@6458 532 is_tdi(x, traptoGreaterThanUnsigned, -1/*any reg*/, 0);
goetz@6458 533 }
goetz@6458 534
goetz@6458 535 inline void trap_zombie_not_entrant();
goetz@6458 536 static bool is_trap_zombie_not_entrant(int x) { return is_tdi(x, traptoUnconditional, 0/*reg 0*/, 1); }
goetz@6458 537
goetz@6458 538 inline void trap_should_not_reach_here();
goetz@6458 539 static bool is_trap_should_not_reach_here(int x) { return is_tdi(x, traptoUnconditional, 0/*reg 0*/, 2); }
goetz@6458 540
goetz@6458 541 inline void trap_ic_miss_check(Register a, Register b);
goetz@6458 542 static bool is_trap_ic_miss_check(int x) {
goetz@6458 543 return is_td(x, traptoGreaterThanUnsigned | traptoLessThanUnsigned, -1/*any reg*/, -1/*any reg*/);
goetz@6458 544 }
goetz@6458 545
goetz@6458 546 // Implicit or explicit null check, jumps to static address exception_entry.
goetz@6458 547 inline void null_check_throw(Register a, int offset, Register temp_reg, address exception_entry);
goetz@6458 548
goetz@6458 549 // Check accessed object for null. Use SIGTRAP-based null checks on AIX.
goetz@6495 550 inline void load_with_trap_null_check(Register d, int si16, Register s1);
goetz@6458 551
goetz@6458 552 // Load heap oop and decompress. Loaded oop may not be null.
goetz@6458 553 inline void load_heap_oop_not_null(Register d, RegisterOrConstant offs, Register s1 = noreg);
goetz@6458 554
goetz@6458 555 // Null allowed.
goetz@6458 556 inline void load_heap_oop(Register d, RegisterOrConstant offs, Register s1 = noreg);
goetz@6458 557
goetz@6458 558 // Encode/decode heap oop. Oop may not be null, else en/decoding goes wrong.
goetz@6458 559 inline void encode_heap_oop_not_null(Register d);
goetz@6458 560 inline void decode_heap_oop_not_null(Register d);
goetz@6458 561
goetz@6458 562 // Null allowed.
goetz@6458 563 inline void decode_heap_oop(Register d);
goetz@6458 564
goetz@6458 565 // Load/Store klass oop from klass field. Compress.
goetz@6458 566 void load_klass(Register dst, Register src);
goetz@6458 567 void load_klass_with_trap_null_check(Register dst, Register src);
goetz@6458 568 void store_klass(Register dst_oop, Register klass, Register tmp = R0);
goetz@6477 569 static int instr_size_for_decode_klass_not_null();
goetz@6458 570 void decode_klass_not_null(Register dst, Register src = noreg);
goetz@6458 571 void encode_klass_not_null(Register dst, Register src = noreg);
goetz@6458 572
goetz@6458 573 // Load common heap base into register.
goetz@6458 574 void reinit_heapbase(Register d, Register tmp = noreg);
goetz@6458 575
goetz@6458 576 // SIGTRAP-based range checks for arrays.
goetz@6458 577 inline void trap_range_check_l(Register a, Register b);
goetz@6458 578 inline void trap_range_check_l(Register a, int si16);
goetz@6458 579 static bool is_trap_range_check_l(int x) {
goetz@6458 580 return (is_tw (x, traptoLessThanUnsigned, -1/*any reg*/, -1/*any reg*/) ||
goetz@6458 581 is_twi(x, traptoLessThanUnsigned, -1/*any reg*/) );
goetz@6458 582 }
goetz@6458 583 inline void trap_range_check_le(Register a, int si16);
goetz@6458 584 static bool is_trap_range_check_le(int x) {
goetz@6458 585 return is_twi(x, traptoEqual | traptoLessThanUnsigned, -1/*any reg*/);
goetz@6458 586 }
goetz@6458 587 inline void trap_range_check_g(Register a, int si16);
goetz@6458 588 static bool is_trap_range_check_g(int x) {
goetz@6458 589 return is_twi(x, traptoGreaterThanUnsigned, -1/*any reg*/);
goetz@6458 590 }
goetz@6458 591 inline void trap_range_check_ge(Register a, Register b);
goetz@6458 592 inline void trap_range_check_ge(Register a, int si16);
goetz@6458 593 static bool is_trap_range_check_ge(int x) {
goetz@6458 594 return (is_tw (x, traptoEqual | traptoGreaterThanUnsigned, -1/*any reg*/, -1/*any reg*/) ||
goetz@6458 595 is_twi(x, traptoEqual | traptoGreaterThanUnsigned, -1/*any reg*/) );
goetz@6458 596 }
goetz@6458 597 static bool is_trap_range_check(int x) {
goetz@6458 598 return is_trap_range_check_l(x) || is_trap_range_check_le(x) ||
goetz@6458 599 is_trap_range_check_g(x) || is_trap_range_check_ge(x);
goetz@6458 600 }
goetz@6458 601
goetz@6495 602 void clear_memory_doubleword(Register base_ptr, Register cnt_dwords, Register tmp = R0);
goetz@6495 603
goetz@6458 604 // Needle of length 1.
goetz@6458 605 void string_indexof_1(Register result, Register haystack, Register haycnt,
goetz@6458 606 Register needle, jchar needleChar,
goetz@6458 607 Register tmp1, Register tmp2);
goetz@6458 608 // General indexof, eventually with constant needle length.
goetz@6458 609 void string_indexof(Register result, Register haystack, Register haycnt,
goetz@6458 610 Register needle, ciTypeArray* needle_values, Register needlecnt, int needlecntval,
goetz@6458 611 Register tmp1, Register tmp2, Register tmp3, Register tmp4);
goetz@6458 612 void string_compare(Register str1_reg, Register str2_reg, Register cnt1_reg, Register cnt2_reg,
goetz@6458 613 Register result_reg, Register tmp_reg);
goetz@6458 614 void char_arrays_equals(Register str1_reg, Register str2_reg, Register cnt_reg, Register result_reg,
goetz@6458 615 Register tmp1_reg, Register tmp2_reg, Register tmp3_reg, Register tmp4_reg,
goetz@6458 616 Register tmp5_reg);
goetz@6458 617 void char_arrays_equalsImm(Register str1_reg, Register str2_reg, int cntval, Register result_reg,
goetz@6458 618 Register tmp1_reg, Register tmp2_reg);
goetz@6458 619
goetz@6458 620 //
goetz@6458 621 // Debugging
goetz@6458 622 //
goetz@6458 623
goetz@6458 624 // assert on cr0
goetz@6458 625 void asm_assert(bool check_equal, const char* msg, int id);
goetz@6458 626 void asm_assert_eq(const char* msg, int id) { asm_assert(true, msg, id); }
goetz@6458 627 void asm_assert_ne(const char* msg, int id) { asm_assert(false, msg, id); }
goetz@6458 628
goetz@6458 629 private:
goetz@6458 630 void asm_assert_mems_zero(bool check_equal, int size, int mem_offset, Register mem_base,
goetz@6458 631 const char* msg, int id);
goetz@6458 632
goetz@6458 633 public:
goetz@6458 634
goetz@6458 635 void asm_assert_mem8_is_zero(int mem_offset, Register mem_base, const char* msg, int id) {
goetz@6458 636 asm_assert_mems_zero(true, 8, mem_offset, mem_base, msg, id);
goetz@6458 637 }
goetz@6458 638 void asm_assert_mem8_isnot_zero(int mem_offset, Register mem_base, const char* msg, int id) {
goetz@6458 639 asm_assert_mems_zero(false, 8, mem_offset, mem_base, msg, id);
goetz@6458 640 }
goetz@6458 641
goetz@6458 642 // Verify R16_thread contents.
goetz@6458 643 void verify_thread();
goetz@6458 644
goetz@6458 645 // Emit code to verify that reg contains a valid oop if +VerifyOops is set.
goetz@6458 646 void verify_oop(Register reg, const char* s = "broken oop");
goetz@6458 647
goetz@6458 648 // TODO: verify method and klass metadata (compare against vptr?)
goetz@6458 649 void _verify_method_ptr(Register reg, const char * msg, const char * file, int line) {}
goetz@6495 650 void _verify_klass_ptr(Register reg, const char * msg, const char * file, int line) {}
goetz@6458 651
goetz@6458 652 #define verify_method_ptr(reg) _verify_method_ptr(reg, "broken method " #reg, __FILE__, __LINE__)
goetz@6458 653 #define verify_klass_ptr(reg) _verify_klass_ptr(reg, "broken klass " #reg, __FILE__, __LINE__)
goetz@6458 654
goetz@6458 655 private:
goetz@6458 656
goetz@6458 657 enum {
goetz@6458 658 stop_stop = 0,
goetz@6458 659 stop_untested = 1,
goetz@6458 660 stop_unimplemented = 2,
goetz@6458 661 stop_shouldnotreachhere = 3,
goetz@6458 662 stop_end = 4
goetz@6458 663 };
goetz@6458 664 void stop(int type, const char* msg, int id);
goetz@6458 665
goetz@6458 666 public:
goetz@6458 667 // Prints msg, dumps registers and stops execution.
goetz@6458 668 void stop (const char* msg = "", int id = 0) { stop(stop_stop, msg, id); }
goetz@6458 669 void untested (const char* msg = "", int id = 0) { stop(stop_untested, msg, id); }
goetz@6458 670 void unimplemented(const char* msg = "", int id = 0) { stop(stop_unimplemented, msg, id); }
goetz@6458 671 void should_not_reach_here() { stop(stop_shouldnotreachhere, "", -1); }
goetz@6458 672
goetz@6458 673 void zap_from_to(Register low, int before, Register high, int after, Register val, Register addr) PRODUCT_RETURN;
goetz@6458 674 };
goetz@6458 675
goetz@6458 676 #endif // CPU_PPC_VM_MACROASSEMBLER_PPC_HPP

mercurial