src/cpu/ppc/vm/nativeInst_ppc.hpp

Wed, 15 Apr 2020 11:49:55 +0800

author
aoqi
date
Wed, 15 Apr 2020 11:49:55 +0800
changeset 9852
70aa912cebe5
parent 6876
710a3c8b516e
permissions
-rw-r--r--

Merge

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 2002, 2013, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * Copyright 2012, 2013 SAP AG. All rights reserved.
aoqi@0 4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 5 *
aoqi@0 6 * This code is free software; you can redistribute it and/or modify it
aoqi@0 7 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 8 * published by the Free Software Foundation.
aoqi@0 9 *
aoqi@0 10 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 13 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 14 * accompanied this code).
aoqi@0 15 *
aoqi@0 16 * You should have received a copy of the GNU General Public License version
aoqi@0 17 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 19 *
aoqi@0 20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 21 * or visit www.oracle.com if you need additional information or have any
aoqi@0 22 * questions.
aoqi@0 23 *
aoqi@0 24 */
aoqi@0 25
aoqi@0 26 #ifndef CPU_PPC_VM_NATIVEINST_PPC_HPP
aoqi@0 27 #define CPU_PPC_VM_NATIVEINST_PPC_HPP
aoqi@0 28
aoqi@0 29 #include "asm/assembler.hpp"
aoqi@0 30 #include "asm/macroAssembler.hpp"
aoqi@0 31 #include "memory/allocation.hpp"
aoqi@0 32 #include "runtime/icache.hpp"
aoqi@0 33 #include "runtime/os.hpp"
aoqi@0 34 #include "utilities/top.hpp"
aoqi@0 35
aoqi@0 36 // We have interfaces for the following instructions:
aoqi@0 37 //
aoqi@0 38 // - NativeInstruction
aoqi@0 39 // - NativeCall
aoqi@0 40 // - NativeFarCall
aoqi@0 41 // - NativeMovConstReg
aoqi@0 42 // - NativeJump
aoqi@0 43 // - NativeIllegalInstruction
aoqi@0 44 // - NativeConditionalFarBranch
aoqi@0 45 // - NativeCallTrampolineStub
aoqi@0 46
aoqi@0 47 // The base class for different kinds of native instruction abstractions.
aoqi@0 48 // It provides the primitive operations to manipulate code relative to this.
aoqi@0 49 class NativeInstruction VALUE_OBJ_CLASS_SPEC {
aoqi@0 50 friend class Relocation;
aoqi@0 51
aoqi@0 52 public:
aoqi@0 53 bool is_sigtrap_ic_miss_check() {
aoqi@0 54 assert(UseSIGTRAP, "precondition");
aoqi@0 55 return MacroAssembler::is_trap_ic_miss_check(long_at(0));
aoqi@0 56 }
aoqi@0 57
aoqi@0 58 bool is_sigtrap_null_check() {
aoqi@0 59 assert(UseSIGTRAP && TrapBasedNullChecks, "precondition");
aoqi@0 60 return MacroAssembler::is_trap_null_check(long_at(0));
aoqi@0 61 }
aoqi@0 62
aoqi@0 63 // We use a special trap for marking a method as not_entrant or zombie
aoqi@0 64 // iff UseSIGTRAP.
aoqi@0 65 bool is_sigtrap_zombie_not_entrant() {
aoqi@0 66 assert(UseSIGTRAP, "precondition");
aoqi@0 67 return MacroAssembler::is_trap_zombie_not_entrant(long_at(0));
aoqi@0 68 }
aoqi@0 69
aoqi@0 70 // We use an illtrap for marking a method as not_entrant or zombie
aoqi@0 71 // iff !UseSIGTRAP.
aoqi@0 72 bool is_sigill_zombie_not_entrant() {
aoqi@0 73 assert(!UseSIGTRAP, "precondition");
aoqi@0 74 // Work around a C++ compiler bug which changes 'this'.
aoqi@0 75 return NativeInstruction::is_sigill_zombie_not_entrant_at(addr_at(0));
aoqi@0 76 }
aoqi@0 77 static bool is_sigill_zombie_not_entrant_at(address addr);
aoqi@0 78
aoqi@0 79 #ifdef COMPILER2
aoqi@0 80 // SIGTRAP-based implicit range checks
aoqi@0 81 bool is_sigtrap_range_check() {
aoqi@0 82 assert(UseSIGTRAP && TrapBasedRangeChecks, "precondition");
aoqi@0 83 return MacroAssembler::is_trap_range_check(long_at(0));
aoqi@0 84 }
aoqi@0 85 #endif
aoqi@0 86
aoqi@0 87 // 'should not reach here'.
aoqi@0 88 bool is_sigtrap_should_not_reach_here() {
aoqi@0 89 return MacroAssembler::is_trap_should_not_reach_here(long_at(0));
aoqi@0 90 }
aoqi@0 91
aoqi@0 92 bool is_safepoint_poll() {
aoqi@0 93 // Is the current instruction a POTENTIAL read access to the polling page?
aoqi@0 94 // The current arguments of the instruction are not checked!
aoqi@0 95 return MacroAssembler::is_load_from_polling_page(long_at(0), NULL);
aoqi@0 96 }
aoqi@0 97
aoqi@0 98 bool is_memory_serialization(JavaThread *thread, void *ucontext) {
aoqi@0 99 // Is the current instruction a write access of thread to the
aoqi@0 100 // memory serialization page?
aoqi@0 101 return MacroAssembler::is_memory_serialization(long_at(0), thread, ucontext);
aoqi@0 102 }
aoqi@0 103
aoqi@0 104 address get_stack_bang_address(void *ucontext) {
aoqi@0 105 // If long_at(0) is not a stack bang, return 0. Otherwise, return
aoqi@0 106 // banged address.
aoqi@0 107 return MacroAssembler::get_stack_bang_address(long_at(0), ucontext);
aoqi@0 108 }
aoqi@0 109
aoqi@0 110 protected:
aoqi@0 111 address addr_at(int offset) const { return address(this) + offset; }
aoqi@0 112 int long_at(int offset) const { return *(int*)addr_at(offset); }
aoqi@0 113
aoqi@0 114 public:
aoqi@0 115 void verify() NOT_DEBUG_RETURN;
aoqi@0 116 };
aoqi@0 117
aoqi@0 118 inline NativeInstruction* nativeInstruction_at(address address) {
aoqi@0 119 NativeInstruction* inst = (NativeInstruction*)address;
aoqi@0 120 inst->verify();
aoqi@0 121 return inst;
aoqi@0 122 }
aoqi@0 123
aoqi@0 124 // The NativeCall is an abstraction for accessing/manipulating call
aoqi@0 125 // instructions. It is used to manipulate inline caches, primitive &
aoqi@0 126 // dll calls, etc.
aoqi@0 127 //
aoqi@0 128 // Sparc distinguishes `NativeCall' and `NativeFarCall'. On PPC64,
aoqi@0 129 // at present, we provide a single class `NativeCall' representing the
aoqi@0 130 // sequence `load_const, mtctr, bctrl' or the sequence 'ld_from_toc,
aoqi@0 131 // mtctr, bctrl'.
aoqi@0 132 class NativeCall: public NativeInstruction {
aoqi@0 133 public:
aoqi@0 134
aoqi@0 135 enum ppc_specific_constants {
aoqi@0 136 load_const_instruction_size = 28,
aoqi@0 137 load_const_from_method_toc_instruction_size = 16,
aoqi@0 138 instruction_size = 16 // Used in shared code for calls with reloc_info.
aoqi@0 139 };
aoqi@0 140
aoqi@0 141 static bool is_call_at(address a) {
aoqi@0 142 return Assembler::is_bl(*(int*)(a));
aoqi@0 143 }
aoqi@0 144
aoqi@0 145 static bool is_call_before(address return_address) {
aoqi@0 146 return NativeCall::is_call_at(return_address - 4);
aoqi@0 147 }
aoqi@0 148
aoqi@0 149 address instruction_address() const {
aoqi@0 150 return addr_at(0);
aoqi@0 151 }
aoqi@0 152
aoqi@0 153 address next_instruction_address() const {
aoqi@0 154 // We have only bl.
aoqi@0 155 assert(MacroAssembler::is_bl(*(int*)instruction_address()), "Should be bl instruction!");
aoqi@0 156 return addr_at(4);
aoqi@0 157 }
aoqi@0 158
aoqi@0 159 address return_address() const {
aoqi@0 160 return next_instruction_address();
aoqi@0 161 }
aoqi@0 162
aoqi@0 163 address destination() const;
aoqi@0 164
aoqi@0 165 // The parameter assert_lock disables the assertion during code generation.
aoqi@0 166 void set_destination_mt_safe(address dest, bool assert_lock = true);
aoqi@0 167
aoqi@0 168 address get_trampoline();
aoqi@0 169
aoqi@0 170 void verify_alignment() {} // do nothing on ppc
aoqi@0 171 void verify() NOT_DEBUG_RETURN;
aoqi@0 172 };
aoqi@0 173
aoqi@0 174 inline NativeCall* nativeCall_at(address instr) {
aoqi@0 175 NativeCall* call = (NativeCall*)instr;
aoqi@0 176 call->verify();
aoqi@0 177 return call;
aoqi@0 178 }
aoqi@0 179
aoqi@0 180 inline NativeCall* nativeCall_before(address return_address) {
aoqi@0 181 NativeCall* call = NULL;
aoqi@0 182 if (MacroAssembler::is_bl(*(int*)(return_address - 4)))
aoqi@0 183 call = (NativeCall*)(return_address - 4);
aoqi@0 184 call->verify();
aoqi@0 185 return call;
aoqi@0 186 }
aoqi@0 187
aoqi@0 188 // The NativeFarCall is an abstraction for accessing/manipulating native
aoqi@0 189 // call-anywhere instructions.
aoqi@0 190 // Used to call native methods which may be loaded anywhere in the address
aoqi@0 191 // space, possibly out of reach of a call instruction.
aoqi@0 192 class NativeFarCall: public NativeInstruction {
aoqi@0 193 public:
aoqi@0 194 // We use MacroAssembler::bl64_patchable() for implementing a
aoqi@0 195 // call-anywhere instruction.
aoqi@0 196
aoqi@0 197 // Checks whether instr points at a NativeFarCall instruction.
aoqi@0 198 static bool is_far_call_at(address instr) {
aoqi@0 199 return MacroAssembler::is_bl64_patchable_at(instr);
aoqi@0 200 }
aoqi@0 201
aoqi@0 202 // Does the NativeFarCall implementation use a pc-relative encoding
aoqi@0 203 // of the call destination?
aoqi@0 204 // Used when relocating code.
aoqi@0 205 bool is_pcrelative() {
aoqi@0 206 assert(MacroAssembler::is_bl64_patchable_at((address)this),
aoqi@0 207 "unexpected call type");
aoqi@0 208 return MacroAssembler::is_bl64_patchable_pcrelative_at((address)this);
aoqi@0 209 }
aoqi@0 210
aoqi@0 211 // Returns the NativeFarCall's destination.
aoqi@0 212 address destination() const {
aoqi@0 213 assert(MacroAssembler::is_bl64_patchable_at((address)this),
aoqi@0 214 "unexpected call type");
aoqi@0 215 return MacroAssembler::get_dest_of_bl64_patchable_at((address)this);
aoqi@0 216 }
aoqi@0 217
aoqi@0 218 // Sets the NativeCall's destination, not necessarily mt-safe.
aoqi@0 219 // Used when relocating code.
aoqi@0 220 void set_destination(address dest) {
aoqi@0 221 // Set new destination (implementation of call may change here).
aoqi@0 222 assert(MacroAssembler::is_bl64_patchable_at((address)this),
aoqi@0 223 "unexpected call type");
aoqi@0 224 MacroAssembler::set_dest_of_bl64_patchable_at((address)this, dest);
aoqi@0 225 }
aoqi@0 226
aoqi@0 227 void verify() NOT_DEBUG_RETURN;
aoqi@0 228 };
aoqi@0 229
aoqi@0 230 // Instantiates a NativeFarCall object starting at the given instruction
aoqi@0 231 // address and returns the NativeFarCall object.
aoqi@0 232 inline NativeFarCall* nativeFarCall_at(address instr) {
aoqi@0 233 NativeFarCall* call = (NativeFarCall*)instr;
aoqi@0 234 call->verify();
aoqi@0 235 return call;
aoqi@0 236 }
aoqi@0 237
aoqi@0 238 // An interface for accessing/manipulating native set_oop imm, reg instructions.
aoqi@0 239 // (used to manipulate inlined data references, etc.)
aoqi@0 240 class NativeMovConstReg: public NativeInstruction {
aoqi@0 241 public:
aoqi@0 242
aoqi@0 243 enum ppc_specific_constants {
aoqi@0 244 load_const_instruction_size = 20,
aoqi@0 245 load_const_from_method_toc_instruction_size = 8,
aoqi@0 246 instruction_size = 8 // Used in shared code for calls with reloc_info.
aoqi@0 247 };
aoqi@0 248
aoqi@0 249 address instruction_address() const {
aoqi@0 250 return addr_at(0);
aoqi@0 251 }
aoqi@0 252
aoqi@0 253 address next_instruction_address() const;
aoqi@0 254
aoqi@0 255 // (The [set_]data accessor respects oop_type relocs also.)
aoqi@0 256 intptr_t data() const;
aoqi@0 257
aoqi@0 258 // Patch the code stream.
aoqi@0 259 address set_data_plain(intptr_t x, CodeBlob *code);
aoqi@0 260 // Patch the code stream and oop pool.
aoqi@0 261 void set_data(intptr_t x);
aoqi@0 262
aoqi@0 263 // Patch narrow oop constants. Use this also for narrow klass.
aoqi@0 264 void set_narrow_oop(narrowOop data, CodeBlob *code = NULL);
aoqi@0 265
aoqi@0 266 void verify() NOT_DEBUG_RETURN;
aoqi@0 267 };
aoqi@0 268
aoqi@0 269 inline NativeMovConstReg* nativeMovConstReg_at(address address) {
aoqi@0 270 NativeMovConstReg* test = (NativeMovConstReg*)address;
aoqi@0 271 test->verify();
aoqi@0 272 return test;
aoqi@0 273 }
aoqi@0 274
aoqi@0 275 // The NativeJump is an abstraction for accessing/manipulating native
aoqi@0 276 // jump-anywhere instructions.
aoqi@0 277 class NativeJump: public NativeInstruction {
aoqi@0 278 public:
aoqi@0 279 // We use MacroAssembler::b64_patchable() for implementing a
aoqi@0 280 // jump-anywhere instruction.
aoqi@0 281
aoqi@0 282 enum ppc_specific_constants {
aoqi@0 283 instruction_size = MacroAssembler::b64_patchable_size
aoqi@0 284 };
aoqi@0 285
aoqi@0 286 // Checks whether instr points at a NativeJump instruction.
aoqi@0 287 static bool is_jump_at(address instr) {
aoqi@0 288 return MacroAssembler::is_b64_patchable_at(instr)
aoqi@0 289 || ( MacroAssembler::is_load_const_from_method_toc_at(instr)
aoqi@0 290 && Assembler::is_mtctr(*(int*)(instr + 2 * 4))
aoqi@0 291 && Assembler::is_bctr(*(int*)(instr + 3 * 4)));
aoqi@0 292 }
aoqi@0 293
aoqi@0 294 // Does the NativeJump implementation use a pc-relative encoding
aoqi@0 295 // of the call destination?
aoqi@0 296 // Used when relocating code or patching jumps.
aoqi@0 297 bool is_pcrelative() {
aoqi@0 298 return MacroAssembler::is_b64_patchable_pcrelative_at((address)this);
aoqi@0 299 }
aoqi@0 300
aoqi@0 301 // Returns the NativeJump's destination.
aoqi@0 302 address jump_destination() const {
aoqi@0 303 if (MacroAssembler::is_b64_patchable_at((address)this)) {
aoqi@0 304 return MacroAssembler::get_dest_of_b64_patchable_at((address)this);
aoqi@0 305 } else if (MacroAssembler::is_load_const_from_method_toc_at((address)this)
aoqi@0 306 && Assembler::is_mtctr(*(int*)((address)this + 2 * 4))
aoqi@0 307 && Assembler::is_bctr(*(int*)((address)this + 3 * 4))) {
aoqi@0 308 return (address)((NativeMovConstReg *)this)->data();
aoqi@0 309 } else {
aoqi@0 310 ShouldNotReachHere();
aoqi@0 311 return NULL;
aoqi@0 312 }
aoqi@0 313 }
aoqi@0 314
aoqi@0 315 // Sets the NativeJump's destination, not necessarily mt-safe.
aoqi@0 316 // Used when relocating code or patching jumps.
aoqi@0 317 void set_jump_destination(address dest) {
aoqi@0 318 // Set new destination (implementation of call may change here).
aoqi@0 319 if (MacroAssembler::is_b64_patchable_at((address)this)) {
aoqi@0 320 MacroAssembler::set_dest_of_b64_patchable_at((address)this, dest);
aoqi@0 321 } else if (MacroAssembler::is_load_const_from_method_toc_at((address)this)
aoqi@0 322 && Assembler::is_mtctr(*(int*)((address)this + 2 * 4))
aoqi@0 323 && Assembler::is_bctr(*(int*)((address)this + 3 * 4))) {
aoqi@0 324 ((NativeMovConstReg *)this)->set_data((intptr_t)dest);
aoqi@0 325 } else {
aoqi@0 326 ShouldNotReachHere();
aoqi@0 327 }
aoqi@0 328 }
aoqi@0 329
aoqi@0 330 // MT-safe insertion of native jump at verified method entry
aoqi@0 331 static void patch_verified_entry(address entry, address verified_entry, address dest);
aoqi@0 332
aoqi@0 333 void verify() NOT_DEBUG_RETURN;
aoqi@0 334
aoqi@0 335 static void check_verified_entry_alignment(address entry, address verified_entry) {
aoqi@0 336 // We just patch one instruction on ppc64, so the jump doesn't have to
aoqi@0 337 // be aligned. Nothing to do here.
aoqi@0 338 }
aoqi@0 339 };
aoqi@0 340
aoqi@0 341 // Instantiates a NativeJump object starting at the given instruction
aoqi@0 342 // address and returns the NativeJump object.
aoqi@0 343 inline NativeJump* nativeJump_at(address instr) {
aoqi@0 344 NativeJump* call = (NativeJump*)instr;
aoqi@0 345 call->verify();
aoqi@0 346 return call;
aoqi@0 347 }
aoqi@0 348
aoqi@0 349 // NativeConditionalFarBranch is abstraction for accessing/manipulating
aoqi@0 350 // conditional far branches.
aoqi@0 351 class NativeConditionalFarBranch : public NativeInstruction {
aoqi@0 352 public:
aoqi@0 353
aoqi@0 354 static bool is_conditional_far_branch_at(address instr) {
aoqi@0 355 return MacroAssembler::is_bc_far_at(instr);
aoqi@0 356 }
aoqi@0 357
aoqi@0 358 address branch_destination() const {
aoqi@0 359 return MacroAssembler::get_dest_of_bc_far_at((address)this);
aoqi@0 360 }
aoqi@0 361
aoqi@0 362 void set_branch_destination(address dest) {
aoqi@0 363 MacroAssembler::set_dest_of_bc_far_at((address)this, dest);
aoqi@0 364 }
aoqi@0 365 };
aoqi@0 366
aoqi@0 367 inline NativeConditionalFarBranch* NativeConditionalFarBranch_at(address address) {
aoqi@0 368 assert(NativeConditionalFarBranch::is_conditional_far_branch_at(address),
aoqi@0 369 "must be a conditional far branch");
aoqi@0 370 return (NativeConditionalFarBranch*)address;
aoqi@0 371 }
aoqi@0 372
aoqi@0 373 // Call trampoline stubs.
aoqi@0 374 class NativeCallTrampolineStub : public NativeInstruction {
aoqi@0 375 private:
aoqi@0 376
aoqi@0 377 address encoded_destination_addr() const;
aoqi@0 378
aoqi@0 379 public:
aoqi@0 380
aoqi@0 381 address destination(nmethod *nm = NULL) const;
aoqi@0 382 int destination_toc_offset() const;
aoqi@0 383
aoqi@0 384 void set_destination(address new_destination);
aoqi@0 385 };
aoqi@0 386
aoqi@0 387 inline bool is_NativeCallTrampolineStub_at(address address) {
aoqi@0 388 int first_instr = *(int*)address;
aoqi@0 389 return Assembler::is_addis(first_instr) &&
aoqi@0 390 (Register)(intptr_t)Assembler::inv_rt_field(first_instr) == R12_scratch2;
aoqi@0 391 }
aoqi@0 392
aoqi@0 393 inline NativeCallTrampolineStub* NativeCallTrampolineStub_at(address address) {
aoqi@0 394 assert(is_NativeCallTrampolineStub_at(address), "no call trampoline found");
aoqi@0 395 return (NativeCallTrampolineStub*)address;
aoqi@0 396 }
aoqi@0 397
aoqi@0 398 #endif // CPU_PPC_VM_NATIVEINST_PPC_HPP

mercurial