Wed, 15 Apr 2020 11:49:55 +0800
Merge
aoqi@0 | 1 | /* |
coleenp@7358 | 2 | * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. |
coleenp@7358 | 3 | * Copyright 2012, 2014 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 | #include "precompiled.hpp" |
aoqi@0 | 27 | #include "asm/macroAssembler.inline.hpp" |
aoqi@0 | 28 | #include "memory/resourceArea.hpp" |
aoqi@0 | 29 | #include "nativeInst_ppc.hpp" |
aoqi@0 | 30 | #include "oops/oop.inline.hpp" |
aoqi@0 | 31 | #include "runtime/handles.hpp" |
aoqi@0 | 32 | #include "runtime/sharedRuntime.hpp" |
aoqi@0 | 33 | #include "runtime/stubRoutines.hpp" |
aoqi@0 | 34 | #include "utilities/ostream.hpp" |
aoqi@0 | 35 | #ifdef COMPILER1 |
aoqi@0 | 36 | #include "c1/c1_Runtime1.hpp" |
aoqi@0 | 37 | #endif |
aoqi@0 | 38 | |
aoqi@0 | 39 | // We use an illtrap for marking a method as not_entrant or zombie iff !UseSIGTRAP |
aoqi@0 | 40 | // Work around a C++ compiler bug which changes 'this' |
aoqi@0 | 41 | bool NativeInstruction::is_sigill_zombie_not_entrant_at(address addr) { |
aoqi@0 | 42 | assert(!UseSIGTRAP, "precondition"); |
aoqi@0 | 43 | if (*(int*)addr != 0 /*illtrap*/) return false; |
aoqi@0 | 44 | CodeBlob* cb = CodeCache::find_blob_unsafe(addr); |
aoqi@0 | 45 | if (cb == NULL || !cb->is_nmethod()) return false; |
aoqi@0 | 46 | nmethod *nm = (nmethod *)cb; |
aoqi@0 | 47 | // This method is not_entrant or zombie iff the illtrap instruction is |
aoqi@0 | 48 | // located at the verified entry point. |
aoqi@0 | 49 | return nm->verified_entry_point() == addr; |
aoqi@0 | 50 | } |
aoqi@0 | 51 | |
aoqi@0 | 52 | #ifdef ASSERT |
aoqi@0 | 53 | void NativeInstruction::verify() { |
aoqi@0 | 54 | // Make sure code pattern is actually an instruction address. |
aoqi@0 | 55 | address addr = addr_at(0); |
aoqi@0 | 56 | if (addr == 0 || ((intptr_t)addr & 3) != 0) { |
aoqi@0 | 57 | fatal("not an instruction address"); |
aoqi@0 | 58 | } |
aoqi@0 | 59 | } |
aoqi@0 | 60 | #endif // ASSERT |
aoqi@0 | 61 | |
aoqi@0 | 62 | // Extract call destination from a NativeCall. The call might use a trampoline stub. |
aoqi@0 | 63 | address NativeCall::destination() const { |
aoqi@0 | 64 | address addr = (address)this; |
aoqi@0 | 65 | address destination = Assembler::bxx_destination(addr); |
aoqi@0 | 66 | |
aoqi@0 | 67 | // Do we use a trampoline stub for this call? |
aoqi@0 | 68 | CodeBlob* cb = CodeCache::find_blob_unsafe(addr); // Else we get assertion if nmethod is zombie. |
aoqi@0 | 69 | assert(cb && cb->is_nmethod(), "sanity"); |
aoqi@0 | 70 | nmethod *nm = (nmethod *)cb; |
aoqi@0 | 71 | if (nm->stub_contains(destination) && is_NativeCallTrampolineStub_at(destination)) { |
aoqi@0 | 72 | // Yes we do, so get the destination from the trampoline stub. |
aoqi@0 | 73 | const address trampoline_stub_addr = destination; |
aoqi@0 | 74 | destination = NativeCallTrampolineStub_at(trampoline_stub_addr)->destination(nm); |
aoqi@0 | 75 | } |
aoqi@0 | 76 | |
aoqi@0 | 77 | return destination; |
aoqi@0 | 78 | } |
aoqi@0 | 79 | |
aoqi@0 | 80 | // Similar to replace_mt_safe, but just changes the destination. The |
aoqi@0 | 81 | // important thing is that free-running threads are able to execute this |
aoqi@0 | 82 | // call instruction at all times. Thus, the displacement field must be |
aoqi@0 | 83 | // instruction-word-aligned. |
aoqi@0 | 84 | // |
aoqi@0 | 85 | // Used in the runtime linkage of calls; see class CompiledIC. |
aoqi@0 | 86 | // |
aoqi@0 | 87 | // Add parameter assert_lock to switch off assertion |
aoqi@0 | 88 | // during code generation, where no patching lock is needed. |
aoqi@0 | 89 | void NativeCall::set_destination_mt_safe(address dest, bool assert_lock) { |
aoqi@0 | 90 | assert(!assert_lock || |
aoqi@0 | 91 | (Patching_lock->is_locked() || SafepointSynchronize::is_at_safepoint()), |
aoqi@0 | 92 | "concurrent code patching"); |
aoqi@0 | 93 | |
aoqi@0 | 94 | ResourceMark rm; |
aoqi@0 | 95 | int code_size = 1 * BytesPerInstWord; |
aoqi@0 | 96 | address addr_call = addr_at(0); |
aoqi@0 | 97 | assert(MacroAssembler::is_bl(*(int*)addr_call), "unexpected code at call-site"); |
aoqi@0 | 98 | |
aoqi@0 | 99 | CodeBuffer cb(addr_call, code_size + 1); |
aoqi@0 | 100 | MacroAssembler* a = new MacroAssembler(&cb); |
aoqi@0 | 101 | |
aoqi@0 | 102 | // Patch the call. |
goetz@7424 | 103 | if (!ReoptimizeCallSequences || !a->is_within_range_of_b(dest, addr_call)) { |
aoqi@0 | 104 | address trampoline_stub_addr = get_trampoline(); |
aoqi@0 | 105 | |
aoqi@0 | 106 | // We did not find a trampoline stub because the current codeblob |
aoqi@0 | 107 | // does not provide this information. The branch will be patched |
aoqi@0 | 108 | // later during a final fixup, when all necessary information is |
aoqi@0 | 109 | // available. |
aoqi@0 | 110 | if (trampoline_stub_addr == 0) |
aoqi@0 | 111 | return; |
aoqi@0 | 112 | |
aoqi@0 | 113 | // Patch the constant in the call's trampoline stub. |
aoqi@0 | 114 | NativeCallTrampolineStub_at(trampoline_stub_addr)->set_destination(dest); |
goetz@7424 | 115 | dest = trampoline_stub_addr; |
goetz@7424 | 116 | } |
aoqi@0 | 117 | |
goetz@7424 | 118 | OrderAccess::release(); |
goetz@7424 | 119 | a->bl(dest); |
goetz@7424 | 120 | |
aoqi@0 | 121 | ICache::ppc64_flush_icache_bytes(addr_call, code_size); |
aoqi@0 | 122 | } |
aoqi@0 | 123 | |
aoqi@0 | 124 | address NativeCall::get_trampoline() { |
aoqi@0 | 125 | address call_addr = addr_at(0); |
aoqi@0 | 126 | |
aoqi@0 | 127 | CodeBlob *code = CodeCache::find_blob(call_addr); |
aoqi@0 | 128 | assert(code != NULL, "Could not find the containing code blob"); |
aoqi@0 | 129 | |
aoqi@0 | 130 | // There are no relocations available when the code gets relocated |
aoqi@0 | 131 | // because of CodeBuffer expansion. |
aoqi@0 | 132 | if (code->relocation_size() == 0) |
aoqi@0 | 133 | return NULL; |
aoqi@0 | 134 | |
aoqi@0 | 135 | address bl_destination = Assembler::bxx_destination(call_addr); |
aoqi@0 | 136 | if (code->content_contains(bl_destination) && |
aoqi@0 | 137 | is_NativeCallTrampolineStub_at(bl_destination)) |
aoqi@0 | 138 | return bl_destination; |
aoqi@0 | 139 | |
aoqi@0 | 140 | // If the codeBlob is not a nmethod, this is because we get here from the |
aoqi@0 | 141 | // CodeBlob constructor, which is called within the nmethod constructor. |
aoqi@0 | 142 | return trampoline_stub_Relocation::get_trampoline_for(call_addr, (nmethod*)code); |
aoqi@0 | 143 | } |
aoqi@0 | 144 | |
aoqi@0 | 145 | #ifdef ASSERT |
aoqi@0 | 146 | void NativeCall::verify() { |
aoqi@0 | 147 | address addr = addr_at(0); |
aoqi@0 | 148 | |
aoqi@0 | 149 | if (!NativeCall::is_call_at(addr)) { |
coleenp@7358 | 150 | tty->print_cr("not a NativeCall at " PTR_FORMAT, p2i(addr)); |
aoqi@0 | 151 | // TODO: PPC port: Disassembler::decode(addr - 20, addr + 20, tty); |
coleenp@7358 | 152 | fatal(err_msg("not a NativeCall at " PTR_FORMAT, p2i(addr))); |
aoqi@0 | 153 | } |
aoqi@0 | 154 | } |
aoqi@0 | 155 | #endif // ASSERT |
aoqi@0 | 156 | |
aoqi@0 | 157 | #ifdef ASSERT |
aoqi@0 | 158 | void NativeFarCall::verify() { |
aoqi@0 | 159 | address addr = addr_at(0); |
aoqi@0 | 160 | |
aoqi@0 | 161 | NativeInstruction::verify(); |
aoqi@0 | 162 | if (!NativeFarCall::is_far_call_at(addr)) { |
coleenp@7358 | 163 | tty->print_cr("not a NativeFarCall at " PTR_FORMAT, p2i(addr)); |
aoqi@0 | 164 | // TODO: PPC port: Disassembler::decode(addr, 20, 20, tty); |
coleenp@7358 | 165 | fatal(err_msg("not a NativeFarCall at " PTR_FORMAT, p2i(addr))); |
aoqi@0 | 166 | } |
aoqi@0 | 167 | } |
aoqi@0 | 168 | #endif // ASSERT |
aoqi@0 | 169 | |
aoqi@0 | 170 | address NativeMovConstReg::next_instruction_address() const { |
aoqi@0 | 171 | #ifdef ASSERT |
aoqi@0 | 172 | CodeBlob* nm = CodeCache::find_blob(instruction_address()); |
aoqi@0 | 173 | assert(!MacroAssembler::is_set_narrow_oop(addr_at(0), nm->content_begin()), "Should not patch narrow oop here"); |
aoqi@0 | 174 | #endif |
aoqi@0 | 175 | |
aoqi@0 | 176 | if (MacroAssembler::is_load_const_from_method_toc_at(addr_at(0))) { |
aoqi@0 | 177 | return addr_at(load_const_from_method_toc_instruction_size); |
aoqi@0 | 178 | } else { |
aoqi@0 | 179 | return addr_at(load_const_instruction_size); |
aoqi@0 | 180 | } |
aoqi@0 | 181 | } |
aoqi@0 | 182 | |
aoqi@0 | 183 | intptr_t NativeMovConstReg::data() const { |
aoqi@0 | 184 | address addr = addr_at(0); |
aoqi@0 | 185 | |
aoqi@0 | 186 | if (MacroAssembler::is_load_const_at(addr)) { |
aoqi@0 | 187 | return MacroAssembler::get_const(addr); |
aoqi@0 | 188 | } |
aoqi@0 | 189 | |
aoqi@0 | 190 | CodeBlob* cb = CodeCache::find_blob_unsafe(addr); |
aoqi@0 | 191 | if (MacroAssembler::is_set_narrow_oop(addr, cb->content_begin())) { |
aoqi@0 | 192 | narrowOop no = (narrowOop)MacroAssembler::get_narrow_oop(addr, cb->content_begin()); |
aoqi@0 | 193 | return cast_from_oop<intptr_t>(oopDesc::decode_heap_oop(no)); |
aoqi@0 | 194 | } else { |
aoqi@0 | 195 | assert(MacroAssembler::is_load_const_from_method_toc_at(addr), "must be load_const_from_pool"); |
aoqi@0 | 196 | |
aoqi@0 | 197 | address ctable = cb->content_begin(); |
aoqi@0 | 198 | int offset = MacroAssembler::get_offset_of_load_const_from_method_toc_at(addr); |
aoqi@0 | 199 | return *(intptr_t *)(ctable + offset); |
aoqi@0 | 200 | } |
aoqi@0 | 201 | } |
aoqi@0 | 202 | |
aoqi@0 | 203 | address NativeMovConstReg::set_data_plain(intptr_t data, CodeBlob *cb) { |
aoqi@0 | 204 | address addr = instruction_address(); |
aoqi@0 | 205 | address next_address = NULL; |
aoqi@0 | 206 | if (!cb) cb = CodeCache::find_blob(addr); |
aoqi@0 | 207 | |
aoqi@0 | 208 | if (cb != NULL && MacroAssembler::is_load_const_from_method_toc_at(addr)) { |
aoqi@0 | 209 | // A load from the method's TOC (ctable). |
aoqi@0 | 210 | assert(cb->is_nmethod(), "must be nmethod"); |
aoqi@0 | 211 | const address ctable = cb->content_begin(); |
aoqi@0 | 212 | const int toc_offset = MacroAssembler::get_offset_of_load_const_from_method_toc_at(addr); |
aoqi@0 | 213 | *(intptr_t *)(ctable + toc_offset) = data; |
aoqi@0 | 214 | next_address = addr + BytesPerInstWord; |
aoqi@0 | 215 | } else if (cb != NULL && |
aoqi@0 | 216 | MacroAssembler::is_calculate_address_from_global_toc_at(addr, cb->content_begin())) { |
aoqi@0 | 217 | // A calculation relative to the global TOC. |
aoqi@0 | 218 | if (MacroAssembler::get_address_of_calculate_address_from_global_toc_at(addr, cb->content_begin()) != |
aoqi@0 | 219 | (address)data) { |
aoqi@0 | 220 | const int invalidated_range = |
aoqi@0 | 221 | MacroAssembler::patch_calculate_address_from_global_toc_at(addr, cb->content_begin(), |
aoqi@0 | 222 | (address)data); |
aoqi@0 | 223 | const address start = invalidated_range < 0 ? addr + invalidated_range : addr; |
aoqi@0 | 224 | // FIXME: |
aoqi@0 | 225 | const int range = invalidated_range < 0 ? 4 - invalidated_range : 8; |
aoqi@0 | 226 | ICache::ppc64_flush_icache_bytes(start, range); |
aoqi@0 | 227 | } |
aoqi@0 | 228 | next_address = addr + 1 * BytesPerInstWord; |
aoqi@0 | 229 | } else if (MacroAssembler::is_load_const_at(addr)) { |
aoqi@0 | 230 | // A normal 5 instruction load_const code sequence. |
aoqi@0 | 231 | if (MacroAssembler::get_const(addr) != (long)data) { |
aoqi@0 | 232 | // This is not mt safe, ok in methods like CodeBuffer::copy_code(). |
aoqi@0 | 233 | MacroAssembler::patch_const(addr, (long)data); |
aoqi@0 | 234 | ICache::ppc64_flush_icache_bytes(addr, load_const_instruction_size); |
aoqi@0 | 235 | } |
aoqi@0 | 236 | next_address = addr + 5 * BytesPerInstWord; |
aoqi@0 | 237 | } else if (MacroAssembler::is_bl(* (int*) addr)) { |
aoqi@0 | 238 | // A single branch-and-link instruction. |
aoqi@0 | 239 | ResourceMark rm; |
aoqi@0 | 240 | const int code_size = 1 * BytesPerInstWord; |
aoqi@0 | 241 | CodeBuffer cb(addr, code_size + 1); |
aoqi@0 | 242 | MacroAssembler* a = new MacroAssembler(&cb); |
aoqi@0 | 243 | a->bl((address) data); |
aoqi@0 | 244 | ICache::ppc64_flush_icache_bytes(addr, code_size); |
aoqi@0 | 245 | next_address = addr + code_size; |
aoqi@0 | 246 | } else { |
aoqi@0 | 247 | ShouldNotReachHere(); |
aoqi@0 | 248 | } |
aoqi@0 | 249 | |
aoqi@0 | 250 | return next_address; |
aoqi@0 | 251 | } |
aoqi@0 | 252 | |
aoqi@0 | 253 | void NativeMovConstReg::set_data(intptr_t data) { |
aoqi@0 | 254 | // Store the value into the instruction stream. |
aoqi@0 | 255 | CodeBlob *cb = CodeCache::find_blob(instruction_address()); |
aoqi@0 | 256 | address next_address = set_data_plain(data, cb); |
aoqi@0 | 257 | |
aoqi@0 | 258 | // Also store the value into an oop_Relocation cell, if any. |
aoqi@0 | 259 | if (cb && cb->is_nmethod()) { |
aoqi@0 | 260 | RelocIterator iter((nmethod *) cb, instruction_address(), next_address); |
aoqi@0 | 261 | oop* oop_addr = NULL; |
aoqi@0 | 262 | Metadata** metadata_addr = NULL; |
aoqi@0 | 263 | while (iter.next()) { |
aoqi@0 | 264 | if (iter.type() == relocInfo::oop_type) { |
aoqi@0 | 265 | oop_Relocation *r = iter.oop_reloc(); |
aoqi@0 | 266 | if (oop_addr == NULL) { |
aoqi@0 | 267 | oop_addr = r->oop_addr(); |
aoqi@0 | 268 | *oop_addr = cast_to_oop(data); |
aoqi@0 | 269 | } else { |
aoqi@0 | 270 | assert(oop_addr == r->oop_addr(), "must be only one set-oop here") ; |
aoqi@0 | 271 | } |
aoqi@0 | 272 | } |
aoqi@0 | 273 | if (iter.type() == relocInfo::metadata_type) { |
aoqi@0 | 274 | metadata_Relocation *r = iter.metadata_reloc(); |
aoqi@0 | 275 | if (metadata_addr == NULL) { |
aoqi@0 | 276 | metadata_addr = r->metadata_addr(); |
aoqi@0 | 277 | *metadata_addr = (Metadata*)data; |
aoqi@0 | 278 | } else { |
aoqi@0 | 279 | assert(metadata_addr == r->metadata_addr(), "must be only one set-metadata here"); |
aoqi@0 | 280 | } |
aoqi@0 | 281 | } |
aoqi@0 | 282 | } |
aoqi@0 | 283 | } |
aoqi@0 | 284 | } |
aoqi@0 | 285 | |
aoqi@0 | 286 | void NativeMovConstReg::set_narrow_oop(narrowOop data, CodeBlob *code /* = NULL */) { |
aoqi@0 | 287 | address addr = addr_at(0); |
aoqi@0 | 288 | CodeBlob* cb = (code) ? code : CodeCache::find_blob(instruction_address()); |
aoqi@0 | 289 | if (MacroAssembler::get_narrow_oop(addr, cb->content_begin()) == (long)data) return; |
aoqi@0 | 290 | const int invalidated_range = |
aoqi@0 | 291 | MacroAssembler::patch_set_narrow_oop(addr, cb->content_begin(), (long)data); |
aoqi@0 | 292 | const address start = invalidated_range < 0 ? addr + invalidated_range : addr; |
aoqi@0 | 293 | // FIXME: |
aoqi@0 | 294 | const int range = invalidated_range < 0 ? 4 - invalidated_range : 8; |
aoqi@0 | 295 | ICache::ppc64_flush_icache_bytes(start, range); |
aoqi@0 | 296 | } |
aoqi@0 | 297 | |
aoqi@0 | 298 | // Do not use an assertion here. Let clients decide whether they only |
aoqi@0 | 299 | // want this when assertions are enabled. |
aoqi@0 | 300 | #ifdef ASSERT |
aoqi@0 | 301 | void NativeMovConstReg::verify() { |
aoqi@0 | 302 | address addr = addr_at(0); |
aoqi@0 | 303 | if (! MacroAssembler::is_load_const_at(addr) && |
aoqi@0 | 304 | ! MacroAssembler::is_load_const_from_method_toc_at(addr)) { |
aoqi@0 | 305 | CodeBlob* cb = CodeCache::find_blob_unsafe(addr); // find_nmethod() asserts if nmethod is zombie. |
aoqi@0 | 306 | if (! (cb != NULL && MacroAssembler::is_calculate_address_from_global_toc_at(addr, cb->content_begin())) && |
aoqi@0 | 307 | ! (cb != NULL && MacroAssembler::is_set_narrow_oop(addr, cb->content_begin())) && |
aoqi@0 | 308 | ! MacroAssembler::is_bl(*((int*) addr))) { |
coleenp@7358 | 309 | tty->print_cr("not a NativeMovConstReg at " PTR_FORMAT, p2i(addr)); |
aoqi@0 | 310 | // TODO: PPC port: Disassembler::decode(addr, 20, 20, tty); |
coleenp@7358 | 311 | fatal(err_msg("not a NativeMovConstReg at " PTR_FORMAT, p2i(addr))); |
aoqi@0 | 312 | } |
aoqi@0 | 313 | } |
aoqi@0 | 314 | } |
aoqi@0 | 315 | #endif // ASSERT |
aoqi@0 | 316 | |
aoqi@0 | 317 | void NativeJump::patch_verified_entry(address entry, address verified_entry, address dest) { |
aoqi@0 | 318 | ResourceMark rm; |
aoqi@0 | 319 | int code_size = 1 * BytesPerInstWord; |
aoqi@0 | 320 | CodeBuffer cb(verified_entry, code_size + 1); |
aoqi@0 | 321 | MacroAssembler* a = new MacroAssembler(&cb); |
aoqi@0 | 322 | #ifdef COMPILER2 |
aoqi@0 | 323 | assert(dest == SharedRuntime::get_handle_wrong_method_stub(), "expected fixed destination of patch"); |
aoqi@0 | 324 | #endif |
aoqi@0 | 325 | // Patch this nmethod atomically. Always use illtrap/trap in debug build. |
aoqi@0 | 326 | if (DEBUG_ONLY(false &&) a->is_within_range_of_b(dest, a->pc())) { |
aoqi@0 | 327 | a->b(dest); |
aoqi@0 | 328 | } else { |
aoqi@0 | 329 | // The signal handler will continue at dest=OptoRuntime::handle_wrong_method_stub(). |
aoqi@0 | 330 | if (TrapBasedNotEntrantChecks) { |
aoqi@0 | 331 | // We use a special trap for marking a method as not_entrant or zombie. |
aoqi@0 | 332 | a->trap_zombie_not_entrant(); |
aoqi@0 | 333 | } else { |
aoqi@0 | 334 | // We use an illtrap for marking a method as not_entrant or zombie. |
aoqi@0 | 335 | a->illtrap(); |
aoqi@0 | 336 | } |
aoqi@0 | 337 | } |
aoqi@0 | 338 | ICache::ppc64_flush_icache_bytes(verified_entry, code_size); |
aoqi@0 | 339 | } |
aoqi@0 | 340 | |
aoqi@0 | 341 | #ifdef ASSERT |
aoqi@0 | 342 | void NativeJump::verify() { |
aoqi@0 | 343 | address addr = addr_at(0); |
aoqi@0 | 344 | |
aoqi@0 | 345 | NativeInstruction::verify(); |
aoqi@0 | 346 | if (!NativeJump::is_jump_at(addr)) { |
coleenp@7358 | 347 | tty->print_cr("not a NativeJump at " PTR_FORMAT, p2i(addr)); |
aoqi@0 | 348 | // TODO: PPC port: Disassembler::decode(addr, 20, 20, tty); |
coleenp@7358 | 349 | fatal(err_msg("not a NativeJump at " PTR_FORMAT, p2i(addr))); |
aoqi@0 | 350 | } |
aoqi@0 | 351 | } |
aoqi@0 | 352 | #endif // ASSERT |
aoqi@0 | 353 | |
aoqi@0 | 354 | //------------------------------------------------------------------- |
aoqi@0 | 355 | |
aoqi@0 | 356 | // Call trampoline stubs. |
aoqi@0 | 357 | // |
aoqi@0 | 358 | // Layout and instructions of a call trampoline stub: |
aoqi@0 | 359 | // 0: load the TOC (part 1) |
aoqi@0 | 360 | // 4: load the TOC (part 2) |
aoqi@0 | 361 | // 8: load the call target from the constant pool (part 1) |
aoqi@0 | 362 | // [12: load the call target from the constant pool (part 2, optional)] |
aoqi@0 | 363 | // ..: branch via CTR |
aoqi@0 | 364 | // |
aoqi@0 | 365 | |
aoqi@0 | 366 | address NativeCallTrampolineStub::encoded_destination_addr() const { |
aoqi@0 | 367 | address instruction_addr = addr_at(2 * BytesPerInstWord); |
aoqi@0 | 368 | assert(MacroAssembler::is_ld_largeoffset(instruction_addr), |
aoqi@0 | 369 | "must be a ld with large offset (from the constant pool)"); |
aoqi@0 | 370 | |
aoqi@0 | 371 | return instruction_addr; |
aoqi@0 | 372 | } |
aoqi@0 | 373 | |
aoqi@0 | 374 | address NativeCallTrampolineStub::destination(nmethod *nm) const { |
aoqi@0 | 375 | CodeBlob* cb = nm ? nm : CodeCache::find_blob_unsafe(addr_at(0)); |
aoqi@0 | 376 | address ctable = cb->content_begin(); |
aoqi@0 | 377 | |
aoqi@0 | 378 | return *(address*)(ctable + destination_toc_offset()); |
aoqi@0 | 379 | } |
aoqi@0 | 380 | |
aoqi@0 | 381 | int NativeCallTrampolineStub::destination_toc_offset() const { |
aoqi@0 | 382 | return MacroAssembler::get_ld_largeoffset_offset(encoded_destination_addr()); |
aoqi@0 | 383 | } |
aoqi@0 | 384 | |
aoqi@0 | 385 | void NativeCallTrampolineStub::set_destination(address new_destination) { |
aoqi@0 | 386 | CodeBlob* cb = CodeCache::find_blob(addr_at(0)); |
aoqi@0 | 387 | address ctable = cb->content_begin(); |
aoqi@0 | 388 | |
aoqi@0 | 389 | *(address*)(ctable + destination_toc_offset()) = new_destination; |
aoqi@0 | 390 | } |
aoqi@0 | 391 |