src/cpu/sparc/vm/nativeInst_sparc.cpp

Tue, 11 Jan 2011 17:33:21 -0500

author
phh
date
Tue, 11 Jan 2011 17:33:21 -0500
changeset 2447
5577848f5923
parent 2314
f95d63e2154a
child 2657
d673ef06fe96
permissions
-rw-r--r--

7011463: Sparc MacroAssembler::incr_allocated_bytes() needs a RegisterOrConstant argument
Summary: Replaced incr_allocated_bytes() formals var_size_in_bytes and con_size_in_bytes with a single RegisterOrConstant formal.
Reviewed-by: twisti, jcoomes

duke@435 1 /*
jrose@1934 2 * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
duke@435 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@435 4 *
duke@435 5 * This code is free software; you can redistribute it and/or modify it
duke@435 6 * under the terms of the GNU General Public License version 2 only, as
duke@435 7 * published by the Free Software Foundation.
duke@435 8 *
duke@435 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@435 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@435 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@435 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@435 13 * accompanied this code).
duke@435 14 *
duke@435 15 * You should have received a copy of the GNU General Public License version
duke@435 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@435 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@435 18 *
trims@1907 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1907 20 * or visit www.oracle.com if you need additional information or have any
trims@1907 21 * questions.
duke@435 22 *
duke@435 23 */
duke@435 24
stefank@2314 25 #include "precompiled.hpp"
stefank@2314 26 #include "assembler_sparc.inline.hpp"
stefank@2314 27 #include "memory/resourceArea.hpp"
stefank@2314 28 #include "nativeInst_sparc.hpp"
stefank@2314 29 #include "oops/oop.inline.hpp"
stefank@2314 30 #include "runtime/handles.hpp"
stefank@2314 31 #include "runtime/sharedRuntime.hpp"
stefank@2314 32 #include "runtime/stubRoutines.hpp"
stefank@2314 33 #include "utilities/ostream.hpp"
stefank@2314 34 #ifdef COMPILER1
stefank@2314 35 #include "c1/c1_Runtime1.hpp"
stefank@2314 36 #endif
duke@435 37
duke@435 38
kamg@551 39 bool NativeInstruction::is_dtrace_trap() {
kamg@551 40 return !is_nop();
kamg@551 41 }
kamg@551 42
duke@435 43 void NativeInstruction::set_data64_sethi(address instaddr, intptr_t x) {
duke@435 44 ResourceMark rm;
duke@435 45 CodeBuffer buf(instaddr, 10 * BytesPerInstWord );
duke@435 46 MacroAssembler* _masm = new MacroAssembler(&buf);
duke@435 47 Register destreg;
duke@435 48
duke@435 49 destreg = inv_rd(*(unsigned int *)instaddr);
duke@435 50 // Generate a the new sequence
twisti@1162 51 _masm->patchable_sethi(x, destreg);
duke@435 52 ICache::invalidate_range(instaddr, 7 * BytesPerInstWord);
duke@435 53 }
duke@435 54
duke@435 55 void NativeInstruction::verify() {
duke@435 56 // make sure code pattern is actually an instruction address
duke@435 57 address addr = addr_at(0);
duke@435 58 if (addr == 0 || ((intptr_t)addr & 3) != 0) {
duke@435 59 fatal("not an instruction address");
duke@435 60 }
duke@435 61 }
duke@435 62
duke@435 63 void NativeInstruction::print() {
duke@435 64 tty->print_cr(INTPTR_FORMAT ": 0x%x", addr_at(0), long_at(0));
duke@435 65 }
duke@435 66
duke@435 67 void NativeInstruction::set_long_at(int offset, int i) {
duke@435 68 address addr = addr_at(offset);
duke@435 69 *(int*)addr = i;
duke@435 70 ICache::invalidate_word(addr);
duke@435 71 }
duke@435 72
duke@435 73 void NativeInstruction::set_jlong_at(int offset, jlong i) {
duke@435 74 address addr = addr_at(offset);
duke@435 75 *(jlong*)addr = i;
duke@435 76 // Don't need to invalidate 2 words here, because
duke@435 77 // the flush instruction operates on doublewords.
duke@435 78 ICache::invalidate_word(addr);
duke@435 79 }
duke@435 80
duke@435 81 void NativeInstruction::set_addr_at(int offset, address x) {
duke@435 82 address addr = addr_at(offset);
duke@435 83 assert( ((intptr_t)addr & (wordSize-1)) == 0, "set_addr_at bad address alignment");
duke@435 84 *(uintptr_t*)addr = (uintptr_t)x;
duke@435 85 // Don't need to invalidate 2 words here in the 64-bit case,
duke@435 86 // because the flush instruction operates on doublewords.
duke@435 87 ICache::invalidate_word(addr);
duke@435 88 // The Intel code has this assertion for NativeCall::set_destination,
duke@435 89 // NativeMovConstReg::set_data, NativeMovRegMem::set_offset,
duke@435 90 // NativeJump::set_jump_destination, and NativePushImm32::set_data
duke@435 91 //assert (Patching_lock->owned_by_self(), "must hold lock to patch instruction")
duke@435 92 }
duke@435 93
duke@435 94 bool NativeInstruction::is_zero_test(Register &reg) {
duke@435 95 int x = long_at(0);
duke@435 96 Assembler::op3s temp = (Assembler::op3s) (Assembler::sub_op3 | Assembler::cc_bit_op3);
duke@435 97 if (is_op3(x, temp, Assembler::arith_op) &&
duke@435 98 inv_immed(x) && inv_rd(x) == G0) {
duke@435 99 if (inv_rs1(x) == G0) {
duke@435 100 reg = inv_rs2(x);
duke@435 101 return true;
duke@435 102 } else if (inv_rs2(x) == G0) {
duke@435 103 reg = inv_rs1(x);
duke@435 104 return true;
duke@435 105 }
duke@435 106 }
duke@435 107 return false;
duke@435 108 }
duke@435 109
duke@435 110 bool NativeInstruction::is_load_store_with_small_offset(Register reg) {
duke@435 111 int x = long_at(0);
duke@435 112 if (is_op(x, Assembler::ldst_op) &&
duke@435 113 inv_rs1(x) == reg && inv_immed(x)) {
duke@435 114 return true;
duke@435 115 }
duke@435 116 return false;
duke@435 117 }
duke@435 118
duke@435 119 void NativeCall::verify() {
duke@435 120 NativeInstruction::verify();
duke@435 121 // make sure code pattern is actually a call instruction
duke@435 122 if (!is_op(long_at(0), Assembler::call_op)) {
duke@435 123 fatal("not a call");
duke@435 124 }
duke@435 125 }
duke@435 126
duke@435 127 void NativeCall::print() {
duke@435 128 tty->print_cr(INTPTR_FORMAT ": call " INTPTR_FORMAT, instruction_address(), destination());
duke@435 129 }
duke@435 130
duke@435 131
duke@435 132 // MT-safe patching of a call instruction (and following word).
duke@435 133 // First patches the second word, and then atomicly replaces
duke@435 134 // the first word with the first new instruction word.
duke@435 135 // Other processors might briefly see the old first word
duke@435 136 // followed by the new second word. This is OK if the old
duke@435 137 // second word is harmless, and the new second word may be
duke@435 138 // harmlessly executed in the delay slot of the call.
duke@435 139 void NativeCall::replace_mt_safe(address instr_addr, address code_buffer) {
duke@435 140 assert(Patching_lock->is_locked() ||
duke@435 141 SafepointSynchronize::is_at_safepoint(), "concurrent code patching");
duke@435 142 assert (instr_addr != NULL, "illegal address for code patching");
duke@435 143 NativeCall* n_call = nativeCall_at (instr_addr); // checking that it is a call
duke@435 144 assert(NativeCall::instruction_size == 8, "wrong instruction size; must be 8");
duke@435 145 int i0 = ((int*)code_buffer)[0];
duke@435 146 int i1 = ((int*)code_buffer)[1];
duke@435 147 int* contention_addr = (int*) n_call->addr_at(1*BytesPerInstWord);
duke@435 148 assert(inv_op(*contention_addr) == Assembler::arith_op ||
duke@435 149 *contention_addr == nop_instruction() || !VM_Version::v9_instructions_work(),
duke@435 150 "must not interfere with original call");
duke@435 151 // The set_long_at calls do the ICacheInvalidate so we just need to do them in reverse order
duke@435 152 n_call->set_long_at(1*BytesPerInstWord, i1);
duke@435 153 n_call->set_long_at(0*BytesPerInstWord, i0);
duke@435 154 // NOTE: It is possible that another thread T will execute
duke@435 155 // only the second patched word.
duke@435 156 // In other words, since the original instruction is this
duke@435 157 // call patching_stub; nop (NativeCall)
duke@435 158 // and the new sequence from the buffer is this:
duke@435 159 // sethi %hi(K), %r; add %r, %lo(K), %r (NativeMovConstReg)
duke@435 160 // what T will execute is this:
duke@435 161 // call patching_stub; add %r, %lo(K), %r
duke@435 162 // thereby putting garbage into %r before calling the patching stub.
duke@435 163 // This is OK, because the patching stub ignores the value of %r.
duke@435 164
duke@435 165 // Make sure the first-patched instruction, which may co-exist
duke@435 166 // briefly with the call, will do something harmless.
duke@435 167 assert(inv_op(*contention_addr) == Assembler::arith_op ||
duke@435 168 *contention_addr == nop_instruction() || !VM_Version::v9_instructions_work(),
duke@435 169 "must not interfere with original call");
duke@435 170 }
duke@435 171
duke@435 172 // Similar to replace_mt_safe, but just changes the destination. The
duke@435 173 // important thing is that free-running threads are able to execute this
duke@435 174 // call instruction at all times. Thus, the displacement field must be
duke@435 175 // instruction-word-aligned. This is always true on SPARC.
duke@435 176 //
duke@435 177 // Used in the runtime linkage of calls; see class CompiledIC.
duke@435 178 void NativeCall::set_destination_mt_safe(address dest) {
duke@435 179 assert(Patching_lock->is_locked() ||
duke@435 180 SafepointSynchronize::is_at_safepoint(), "concurrent code patching");
duke@435 181 // set_destination uses set_long_at which does the ICache::invalidate
duke@435 182 set_destination(dest);
duke@435 183 }
duke@435 184
duke@435 185 // Code for unit testing implementation of NativeCall class
duke@435 186 void NativeCall::test() {
duke@435 187 #ifdef ASSERT
duke@435 188 ResourceMark rm;
duke@435 189 CodeBuffer cb("test", 100, 100);
duke@435 190 MacroAssembler* a = new MacroAssembler(&cb);
duke@435 191 NativeCall *nc;
duke@435 192 uint idx;
duke@435 193 int offsets[] = {
duke@435 194 0x0,
duke@435 195 0xfffffff0,
duke@435 196 0x7ffffff0,
duke@435 197 0x80000000,
duke@435 198 0x20,
duke@435 199 0x4000,
duke@435 200 };
duke@435 201
duke@435 202 VM_Version::allow_all();
duke@435 203
duke@435 204 a->call( a->pc(), relocInfo::none );
duke@435 205 a->delayed()->nop();
twisti@2103 206 nc = nativeCall_at( cb.insts_begin() );
duke@435 207 nc->print();
duke@435 208
duke@435 209 nc = nativeCall_overwriting_at( nc->next_instruction_address() );
duke@435 210 for (idx = 0; idx < ARRAY_SIZE(offsets); idx++) {
twisti@2103 211 nc->set_destination( cb.insts_begin() + offsets[idx] );
twisti@2103 212 assert(nc->destination() == (cb.insts_begin() + offsets[idx]), "check unit test");
duke@435 213 nc->print();
duke@435 214 }
duke@435 215
twisti@2103 216 nc = nativeCall_before( cb.insts_begin() + 8 );
duke@435 217 nc->print();
duke@435 218
duke@435 219 VM_Version::revert();
duke@435 220 #endif
duke@435 221 }
duke@435 222 // End code for unit testing implementation of NativeCall class
duke@435 223
duke@435 224 //-------------------------------------------------------------------
duke@435 225
duke@435 226 #ifdef _LP64
duke@435 227
duke@435 228 void NativeFarCall::set_destination(address dest) {
duke@435 229 // Address materialized in the instruction stream, so nothing to do.
duke@435 230 return;
duke@435 231 #if 0 // What we'd do if we really did want to change the destination
duke@435 232 if (destination() == dest) {
duke@435 233 return;
duke@435 234 }
duke@435 235 ResourceMark rm;
duke@435 236 CodeBuffer buf(addr_at(0), instruction_size + 1);
duke@435 237 MacroAssembler* _masm = new MacroAssembler(&buf);
duke@435 238 // Generate the new sequence
twisti@1162 239 AddressLiteral(dest);
twisti@1162 240 _masm->jumpl_to(dest, O7, O7);
duke@435 241 ICache::invalidate_range(addr_at(0), instruction_size );
duke@435 242 #endif
duke@435 243 }
duke@435 244
duke@435 245 void NativeFarCall::verify() {
duke@435 246 // make sure code pattern is actually a jumpl_to instruction
duke@435 247 assert((int)instruction_size == (int)NativeJump::instruction_size, "same as jump_to");
duke@435 248 assert((int)jmpl_offset == (int)NativeMovConstReg::add_offset, "sethi size ok");
duke@435 249 nativeJump_at(addr_at(0))->verify();
duke@435 250 }
duke@435 251
duke@435 252 bool NativeFarCall::is_call_at(address instr) {
duke@435 253 return nativeInstruction_at(instr)->is_sethi();
duke@435 254 }
duke@435 255
duke@435 256 void NativeFarCall::print() {
duke@435 257 tty->print_cr(INTPTR_FORMAT ": call " INTPTR_FORMAT, instruction_address(), destination());
duke@435 258 }
duke@435 259
duke@435 260 bool NativeFarCall::destination_is_compiled_verified_entry_point() {
duke@435 261 nmethod* callee = CodeCache::find_nmethod(destination());
duke@435 262 if (callee == NULL) {
duke@435 263 return false;
duke@435 264 } else {
duke@435 265 return destination() == callee->verified_entry_point();
duke@435 266 }
duke@435 267 }
duke@435 268
duke@435 269 // MT-safe patching of a far call.
duke@435 270 void NativeFarCall::replace_mt_safe(address instr_addr, address code_buffer) {
duke@435 271 Unimplemented();
duke@435 272 }
duke@435 273
duke@435 274 // Code for unit testing implementation of NativeFarCall class
duke@435 275 void NativeFarCall::test() {
duke@435 276 Unimplemented();
duke@435 277 }
duke@435 278 // End code for unit testing implementation of NativeFarCall class
duke@435 279
duke@435 280 #endif // _LP64
duke@435 281
duke@435 282 //-------------------------------------------------------------------
duke@435 283
duke@435 284
duke@435 285 void NativeMovConstReg::verify() {
duke@435 286 NativeInstruction::verify();
duke@435 287 // make sure code pattern is actually a "set_oop" synthetic instruction
duke@435 288 // see MacroAssembler::set_oop()
duke@435 289 int i0 = long_at(sethi_offset);
duke@435 290 int i1 = long_at(add_offset);
duke@435 291
duke@435 292 // verify the pattern "sethi %hi22(imm), reg ; add reg, %lo10(imm), reg"
duke@435 293 Register rd = inv_rd(i0);
duke@435 294 #ifndef _LP64
duke@435 295 if (!(is_op2(i0, Assembler::sethi_op2) && rd != G0 &&
duke@435 296 is_op3(i1, Assembler::add_op3, Assembler::arith_op) &&
duke@435 297 inv_immed(i1) && (unsigned)get_simm13(i1) < (1 << 10) &&
duke@435 298 rd == inv_rs1(i1) && rd == inv_rd(i1))) {
duke@435 299 fatal("not a set_oop");
duke@435 300 }
duke@435 301 #else
duke@435 302 if (!is_op2(i0, Assembler::sethi_op2) && rd != G0 ) {
duke@435 303 fatal("not a set_oop");
duke@435 304 }
duke@435 305 #endif
duke@435 306 }
duke@435 307
duke@435 308
duke@435 309 void NativeMovConstReg::print() {
duke@435 310 tty->print_cr(INTPTR_FORMAT ": mov reg, " INTPTR_FORMAT, instruction_address(), data());
duke@435 311 }
duke@435 312
duke@435 313
duke@435 314 #ifdef _LP64
duke@435 315 intptr_t NativeMovConstReg::data() const {
duke@435 316 return data64(addr_at(sethi_offset), long_at(add_offset));
duke@435 317 }
duke@435 318 #else
duke@435 319 intptr_t NativeMovConstReg::data() const {
duke@435 320 return data32(long_at(sethi_offset), long_at(add_offset));
duke@435 321 }
duke@435 322 #endif
duke@435 323
duke@435 324
duke@435 325 void NativeMovConstReg::set_data(intptr_t x) {
duke@435 326 #ifdef _LP64
duke@435 327 set_data64_sethi(addr_at(sethi_offset), x);
duke@435 328 #else
duke@435 329 set_long_at(sethi_offset, set_data32_sethi( long_at(sethi_offset), x));
duke@435 330 #endif
duke@435 331 set_long_at(add_offset, set_data32_simm13( long_at(add_offset), x));
duke@435 332
duke@435 333 // also store the value into an oop_Relocation cell, if any
twisti@1918 334 CodeBlob* cb = CodeCache::find_blob(instruction_address());
twisti@1918 335 nmethod* nm = cb ? cb->as_nmethod_or_null() : NULL;
duke@435 336 if (nm != NULL) {
duke@435 337 RelocIterator iter(nm, instruction_address(), next_instruction_address());
duke@435 338 oop* oop_addr = NULL;
duke@435 339 while (iter.next()) {
duke@435 340 if (iter.type() == relocInfo::oop_type) {
duke@435 341 oop_Relocation *r = iter.oop_reloc();
duke@435 342 if (oop_addr == NULL) {
duke@435 343 oop_addr = r->oop_addr();
duke@435 344 *oop_addr = (oop)x;
duke@435 345 } else {
duke@435 346 assert(oop_addr == r->oop_addr(), "must be only one set-oop here");
duke@435 347 }
duke@435 348 }
duke@435 349 }
duke@435 350 }
duke@435 351 }
duke@435 352
duke@435 353
duke@435 354 // Code for unit testing implementation of NativeMovConstReg class
duke@435 355 void NativeMovConstReg::test() {
duke@435 356 #ifdef ASSERT
duke@435 357 ResourceMark rm;
duke@435 358 CodeBuffer cb("test", 100, 100);
duke@435 359 MacroAssembler* a = new MacroAssembler(&cb);
duke@435 360 NativeMovConstReg* nm;
duke@435 361 uint idx;
duke@435 362 int offsets[] = {
duke@435 363 0x0,
duke@435 364 0x7fffffff,
duke@435 365 0x80000000,
duke@435 366 0xffffffff,
duke@435 367 0x20,
duke@435 368 4096,
duke@435 369 4097,
duke@435 370 };
duke@435 371
duke@435 372 VM_Version::allow_all();
duke@435 373
twisti@1162 374 AddressLiteral al1(0xaaaabbbb, relocInfo::external_word_type);
twisti@1162 375 a->sethi(al1, I3);
twisti@1162 376 a->add(I3, al1.low10(), I3);
twisti@1162 377 AddressLiteral al2(0xccccdddd, relocInfo::external_word_type);
twisti@1162 378 a->sethi(al2, O2);
twisti@1162 379 a->add(O2, al2.low10(), O2);
duke@435 380
twisti@2103 381 nm = nativeMovConstReg_at( cb.insts_begin() );
duke@435 382 nm->print();
duke@435 383
duke@435 384 nm = nativeMovConstReg_at( nm->next_instruction_address() );
duke@435 385 for (idx = 0; idx < ARRAY_SIZE(offsets); idx++) {
duke@435 386 nm->set_data( offsets[idx] );
duke@435 387 assert(nm->data() == offsets[idx], "check unit test");
duke@435 388 }
duke@435 389 nm->print();
duke@435 390
duke@435 391 VM_Version::revert();
duke@435 392 #endif
duke@435 393 }
duke@435 394 // End code for unit testing implementation of NativeMovConstReg class
duke@435 395
duke@435 396 //-------------------------------------------------------------------
duke@435 397
duke@435 398 void NativeMovConstRegPatching::verify() {
duke@435 399 NativeInstruction::verify();
duke@435 400 // Make sure code pattern is sethi/nop/add.
duke@435 401 int i0 = long_at(sethi_offset);
duke@435 402 int i1 = long_at(nop_offset);
duke@435 403 int i2 = long_at(add_offset);
duke@435 404 assert((int)nop_offset == (int)NativeMovConstReg::add_offset, "sethi size ok");
duke@435 405
duke@435 406 // Verify the pattern "sethi %hi22(imm), reg; nop; add reg, %lo10(imm), reg"
duke@435 407 // The casual reader should note that on Sparc a nop is a special case if sethi
duke@435 408 // in which the destination register is %g0.
duke@435 409 Register rd0 = inv_rd(i0);
duke@435 410 Register rd1 = inv_rd(i1);
duke@435 411 if (!(is_op2(i0, Assembler::sethi_op2) && rd0 != G0 &&
duke@435 412 is_op2(i1, Assembler::sethi_op2) && rd1 == G0 && // nop is a special case of sethi
duke@435 413 is_op3(i2, Assembler::add_op3, Assembler::arith_op) &&
duke@435 414 inv_immed(i2) && (unsigned)get_simm13(i2) < (1 << 10) &&
duke@435 415 rd0 == inv_rs1(i2) && rd0 == inv_rd(i2))) {
duke@435 416 fatal("not a set_oop");
duke@435 417 }
duke@435 418 }
duke@435 419
duke@435 420
duke@435 421 void NativeMovConstRegPatching::print() {
duke@435 422 tty->print_cr(INTPTR_FORMAT ": mov reg, " INTPTR_FORMAT, instruction_address(), data());
duke@435 423 }
duke@435 424
duke@435 425
duke@435 426 int NativeMovConstRegPatching::data() const {
duke@435 427 #ifdef _LP64
duke@435 428 return data64(addr_at(sethi_offset), long_at(add_offset));
duke@435 429 #else
duke@435 430 return data32(long_at(sethi_offset), long_at(add_offset));
duke@435 431 #endif
duke@435 432 }
duke@435 433
duke@435 434
duke@435 435 void NativeMovConstRegPatching::set_data(int x) {
duke@435 436 #ifdef _LP64
duke@435 437 set_data64_sethi(addr_at(sethi_offset), x);
duke@435 438 #else
duke@435 439 set_long_at(sethi_offset, set_data32_sethi(long_at(sethi_offset), x));
duke@435 440 #endif
duke@435 441 set_long_at(add_offset, set_data32_simm13(long_at(add_offset), x));
duke@435 442
duke@435 443 // also store the value into an oop_Relocation cell, if any
twisti@1918 444 CodeBlob* cb = CodeCache::find_blob(instruction_address());
twisti@1918 445 nmethod* nm = cb ? cb->as_nmethod_or_null() : NULL;
duke@435 446 if (nm != NULL) {
duke@435 447 RelocIterator iter(nm, instruction_address(), next_instruction_address());
duke@435 448 oop* oop_addr = NULL;
duke@435 449 while (iter.next()) {
duke@435 450 if (iter.type() == relocInfo::oop_type) {
duke@435 451 oop_Relocation *r = iter.oop_reloc();
duke@435 452 if (oop_addr == NULL) {
duke@435 453 oop_addr = r->oop_addr();
duke@435 454 *oop_addr = (oop)x;
duke@435 455 } else {
duke@435 456 assert(oop_addr == r->oop_addr(), "must be only one set-oop here");
duke@435 457 }
duke@435 458 }
duke@435 459 }
duke@435 460 }
duke@435 461 }
duke@435 462
duke@435 463
duke@435 464 // Code for unit testing implementation of NativeMovConstRegPatching class
duke@435 465 void NativeMovConstRegPatching::test() {
duke@435 466 #ifdef ASSERT
duke@435 467 ResourceMark rm;
duke@435 468 CodeBuffer cb("test", 100, 100);
duke@435 469 MacroAssembler* a = new MacroAssembler(&cb);
duke@435 470 NativeMovConstRegPatching* nm;
duke@435 471 uint idx;
duke@435 472 int offsets[] = {
duke@435 473 0x0,
duke@435 474 0x7fffffff,
duke@435 475 0x80000000,
duke@435 476 0xffffffff,
duke@435 477 0x20,
duke@435 478 4096,
duke@435 479 4097,
duke@435 480 };
duke@435 481
duke@435 482 VM_Version::allow_all();
duke@435 483
twisti@1162 484 AddressLiteral al1(0xaaaabbbb, relocInfo::external_word_type);
twisti@1162 485 a->sethi(al1, I3);
duke@435 486 a->nop();
twisti@1162 487 a->add(I3, al1.low10(), I3);
twisti@1162 488 AddressLiteral al2(0xccccdddd, relocInfo::external_word_type);
twisti@1162 489 a->sethi(al2, O2);
duke@435 490 a->nop();
twisti@1162 491 a->add(O2, al2.low10(), O2);
duke@435 492
twisti@2103 493 nm = nativeMovConstRegPatching_at( cb.insts_begin() );
duke@435 494 nm->print();
duke@435 495
duke@435 496 nm = nativeMovConstRegPatching_at( nm->next_instruction_address() );
duke@435 497 for (idx = 0; idx < ARRAY_SIZE(offsets); idx++) {
duke@435 498 nm->set_data( offsets[idx] );
duke@435 499 assert(nm->data() == offsets[idx], "check unit test");
duke@435 500 }
duke@435 501 nm->print();
duke@435 502
duke@435 503 VM_Version::revert();
duke@435 504 #endif // ASSERT
duke@435 505 }
duke@435 506 // End code for unit testing implementation of NativeMovConstRegPatching class
duke@435 507
duke@435 508
duke@435 509 //-------------------------------------------------------------------
duke@435 510
duke@435 511
duke@435 512 void NativeMovRegMem::copy_instruction_to(address new_instruction_address) {
duke@435 513 Untested("copy_instruction_to");
duke@435 514 int instruction_size = next_instruction_address() - instruction_address();
duke@435 515 for (int i = 0; i < instruction_size; i += BytesPerInstWord) {
duke@435 516 *(int*)(new_instruction_address + i) = *(int*)(address(this) + i);
duke@435 517 }
duke@435 518 }
duke@435 519
duke@435 520
duke@435 521 void NativeMovRegMem::verify() {
duke@435 522 NativeInstruction::verify();
duke@435 523 // make sure code pattern is actually a "ld" or "st" of some sort.
duke@435 524 int i0 = long_at(0);
duke@435 525 int op3 = inv_op3(i0);
duke@435 526
duke@435 527 assert((int)add_offset == NativeMovConstReg::add_offset, "sethi size ok");
duke@435 528
duke@435 529 if (!(is_op(i0, Assembler::ldst_op) &&
duke@435 530 inv_immed(i0) &&
duke@435 531 0 != (op3 < op3_ldst_int_limit
duke@435 532 ? (1 << op3 ) & (op3_mask_ld | op3_mask_st)
duke@435 533 : (1 << (op3 - op3_ldst_int_limit)) & (op3_mask_ldf | op3_mask_stf))))
duke@435 534 {
duke@435 535 int i1 = long_at(ldst_offset);
duke@435 536 Register rd = inv_rd(i0);
duke@435 537
duke@435 538 op3 = inv_op3(i1);
duke@435 539 if (!is_op(i1, Assembler::ldst_op) && rd == inv_rs2(i1) &&
duke@435 540 0 != (op3 < op3_ldst_int_limit
duke@435 541 ? (1 << op3 ) & (op3_mask_ld | op3_mask_st)
duke@435 542 : (1 << (op3 - op3_ldst_int_limit)) & (op3_mask_ldf | op3_mask_stf))) {
duke@435 543 fatal("not a ld* or st* op");
duke@435 544 }
duke@435 545 }
duke@435 546 }
duke@435 547
duke@435 548
duke@435 549 void NativeMovRegMem::print() {
duke@435 550 if (is_immediate()) {
duke@435 551 tty->print_cr(INTPTR_FORMAT ": mov reg, [reg + %x]", instruction_address(), offset());
duke@435 552 } else {
duke@435 553 tty->print_cr(INTPTR_FORMAT ": mov reg, [reg + reg]", instruction_address());
duke@435 554 }
duke@435 555 }
duke@435 556
duke@435 557
duke@435 558 // Code for unit testing implementation of NativeMovRegMem class
duke@435 559 void NativeMovRegMem::test() {
duke@435 560 #ifdef ASSERT
duke@435 561 ResourceMark rm;
duke@435 562 CodeBuffer cb("test", 1000, 1000);
duke@435 563 MacroAssembler* a = new MacroAssembler(&cb);
duke@435 564 NativeMovRegMem* nm;
duke@435 565 uint idx = 0;
duke@435 566 uint idx1;
duke@435 567 int offsets[] = {
duke@435 568 0x0,
duke@435 569 0xffffffff,
duke@435 570 0x7fffffff,
duke@435 571 0x80000000,
duke@435 572 4096,
duke@435 573 4097,
duke@435 574 0x20,
duke@435 575 0x4000,
duke@435 576 };
duke@435 577
duke@435 578 VM_Version::allow_all();
duke@435 579
twisti@1162 580 AddressLiteral al1(0xffffffff, relocInfo::external_word_type);
twisti@1162 581 AddressLiteral al2(0xaaaabbbb, relocInfo::external_word_type);
twisti@1162 582 a->ldsw( G5, al1.low10(), G4 ); idx++;
twisti@1162 583 a->sethi(al2, I3); a->add(I3, al2.low10(), I3);
duke@435 584 a->ldsw( G5, I3, G4 ); idx++;
twisti@1162 585 a->ldsb( G5, al1.low10(), G4 ); idx++;
twisti@1162 586 a->sethi(al2, I3); a->add(I3, al2.low10(), I3);
duke@435 587 a->ldsb( G5, I3, G4 ); idx++;
twisti@1162 588 a->ldsh( G5, al1.low10(), G4 ); idx++;
twisti@1162 589 a->sethi(al2, I3); a->add(I3, al2.low10(), I3);
duke@435 590 a->ldsh( G5, I3, G4 ); idx++;
twisti@1162 591 a->lduw( G5, al1.low10(), G4 ); idx++;
twisti@1162 592 a->sethi(al2, I3); a->add(I3, al2.low10(), I3);
duke@435 593 a->lduw( G5, I3, G4 ); idx++;
twisti@1162 594 a->ldub( G5, al1.low10(), G4 ); idx++;
twisti@1162 595 a->sethi(al2, I3); a->add(I3, al2.low10(), I3);
duke@435 596 a->ldub( G5, I3, G4 ); idx++;
twisti@1162 597 a->lduh( G5, al1.low10(), G4 ); idx++;
twisti@1162 598 a->sethi(al2, I3); a->add(I3, al2.low10(), I3);
duke@435 599 a->lduh( G5, I3, G4 ); idx++;
twisti@1162 600 a->ldx( G5, al1.low10(), G4 ); idx++;
twisti@1162 601 a->sethi(al2, I3); a->add(I3, al2.low10(), I3);
duke@435 602 a->ldx( G5, I3, G4 ); idx++;
twisti@1162 603 a->ldd( G5, al1.low10(), G4 ); idx++;
twisti@1162 604 a->sethi(al2, I3); a->add(I3, al2.low10(), I3);
duke@435 605 a->ldd( G5, I3, G4 ); idx++;
duke@435 606 a->ldf( FloatRegisterImpl::D, O2, -1, F14 ); idx++;
twisti@1162 607 a->sethi(al2, I3); a->add(I3, al2.low10(), I3);
duke@435 608 a->ldf( FloatRegisterImpl::S, O0, I3, F15 ); idx++;
duke@435 609
twisti@1162 610 a->stw( G5, G4, al1.low10() ); idx++;
twisti@1162 611 a->sethi(al2, I3); a->add(I3, al2.low10(), I3);
duke@435 612 a->stw( G5, G4, I3 ); idx++;
twisti@1162 613 a->stb( G5, G4, al1.low10() ); idx++;
twisti@1162 614 a->sethi(al2, I3); a->add(I3, al2.low10(), I3);
duke@435 615 a->stb( G5, G4, I3 ); idx++;
twisti@1162 616 a->sth( G5, G4, al1.low10() ); idx++;
twisti@1162 617 a->sethi(al2, I3); a->add(I3, al2.low10(), I3);
duke@435 618 a->sth( G5, G4, I3 ); idx++;
twisti@1162 619 a->stx( G5, G4, al1.low10() ); idx++;
twisti@1162 620 a->sethi(al2, I3); a->add(I3, al2.low10(), I3);
duke@435 621 a->stx( G5, G4, I3 ); idx++;
twisti@1162 622 a->std( G5, G4, al1.low10() ); idx++;
twisti@1162 623 a->sethi(al2, I3); a->add(I3, al2.low10(), I3);
duke@435 624 a->std( G5, G4, I3 ); idx++;
duke@435 625 a->stf( FloatRegisterImpl::S, F18, O2, -1 ); idx++;
twisti@1162 626 a->sethi(al2, I3); a->add(I3, al2.low10(), I3);
duke@435 627 a->stf( FloatRegisterImpl::S, F15, O0, I3 ); idx++;
duke@435 628
twisti@2103 629 nm = nativeMovRegMem_at( cb.insts_begin() );
duke@435 630 nm->print();
duke@435 631 nm->set_offset( low10(0) );
duke@435 632 nm->print();
duke@435 633 nm->add_offset_in_bytes( low10(0xbb) * wordSize );
duke@435 634 nm->print();
duke@435 635
duke@435 636 while (--idx) {
duke@435 637 nm = nativeMovRegMem_at( nm->next_instruction_address() );
duke@435 638 nm->print();
duke@435 639 for (idx1 = 0; idx1 < ARRAY_SIZE(offsets); idx1++) {
duke@435 640 nm->set_offset( nm->is_immediate() ? low10(offsets[idx1]) : offsets[idx1] );
duke@435 641 assert(nm->offset() == (nm->is_immediate() ? low10(offsets[idx1]) : offsets[idx1]),
duke@435 642 "check unit test");
duke@435 643 nm->print();
duke@435 644 }
duke@435 645 nm->add_offset_in_bytes( low10(0xbb) * wordSize );
duke@435 646 nm->print();
duke@435 647 }
duke@435 648
duke@435 649 VM_Version::revert();
duke@435 650 #endif // ASSERT
duke@435 651 }
duke@435 652
duke@435 653 // End code for unit testing implementation of NativeMovRegMem class
duke@435 654
duke@435 655 //--------------------------------------------------------------------------------
duke@435 656
duke@435 657
duke@435 658 void NativeMovRegMemPatching::copy_instruction_to(address new_instruction_address) {
duke@435 659 Untested("copy_instruction_to");
duke@435 660 int instruction_size = next_instruction_address() - instruction_address();
duke@435 661 for (int i = 0; i < instruction_size; i += wordSize) {
duke@435 662 *(long*)(new_instruction_address + i) = *(long*)(address(this) + i);
duke@435 663 }
duke@435 664 }
duke@435 665
duke@435 666
duke@435 667 void NativeMovRegMemPatching::verify() {
duke@435 668 NativeInstruction::verify();
duke@435 669 // make sure code pattern is actually a "ld" or "st" of some sort.
duke@435 670 int i0 = long_at(0);
duke@435 671 int op3 = inv_op3(i0);
duke@435 672
duke@435 673 assert((int)nop_offset == (int)NativeMovConstReg::add_offset, "sethi size ok");
duke@435 674
duke@435 675 if (!(is_op(i0, Assembler::ldst_op) &&
duke@435 676 inv_immed(i0) &&
duke@435 677 0 != (op3 < op3_ldst_int_limit
duke@435 678 ? (1 << op3 ) & (op3_mask_ld | op3_mask_st)
duke@435 679 : (1 << (op3 - op3_ldst_int_limit)) & (op3_mask_ldf | op3_mask_stf)))) {
duke@435 680 int i1 = long_at(ldst_offset);
duke@435 681 Register rd = inv_rd(i0);
duke@435 682
duke@435 683 op3 = inv_op3(i1);
duke@435 684 if (!is_op(i1, Assembler::ldst_op) && rd == inv_rs2(i1) &&
duke@435 685 0 != (op3 < op3_ldst_int_limit
duke@435 686 ? (1 << op3 ) & (op3_mask_ld | op3_mask_st)
duke@435 687 : (1 << (op3 - op3_ldst_int_limit)) & (op3_mask_ldf | op3_mask_stf))) {
duke@435 688 fatal("not a ld* or st* op");
duke@435 689 }
duke@435 690 }
duke@435 691 }
duke@435 692
duke@435 693
duke@435 694 void NativeMovRegMemPatching::print() {
duke@435 695 if (is_immediate()) {
duke@435 696 tty->print_cr(INTPTR_FORMAT ": mov reg, [reg + %x]", instruction_address(), offset());
duke@435 697 } else {
duke@435 698 tty->print_cr(INTPTR_FORMAT ": mov reg, [reg + reg]", instruction_address());
duke@435 699 }
duke@435 700 }
duke@435 701
duke@435 702
duke@435 703 // Code for unit testing implementation of NativeMovRegMemPatching class
duke@435 704 void NativeMovRegMemPatching::test() {
duke@435 705 #ifdef ASSERT
duke@435 706 ResourceMark rm;
duke@435 707 CodeBuffer cb("test", 1000, 1000);
duke@435 708 MacroAssembler* a = new MacroAssembler(&cb);
duke@435 709 NativeMovRegMemPatching* nm;
duke@435 710 uint idx = 0;
duke@435 711 uint idx1;
duke@435 712 int offsets[] = {
duke@435 713 0x0,
duke@435 714 0xffffffff,
duke@435 715 0x7fffffff,
duke@435 716 0x80000000,
duke@435 717 4096,
duke@435 718 4097,
duke@435 719 0x20,
duke@435 720 0x4000,
duke@435 721 };
duke@435 722
duke@435 723 VM_Version::allow_all();
duke@435 724
twisti@1162 725 AddressLiteral al(0xffffffff, relocInfo::external_word_type);
twisti@1162 726 a->ldsw( G5, al.low10(), G4); idx++;
twisti@1162 727 a->sethi(al, I3); a->nop(); a->add(I3, al.low10(), I3);
duke@435 728 a->ldsw( G5, I3, G4 ); idx++;
twisti@1162 729 a->ldsb( G5, al.low10(), G4); idx++;
twisti@1162 730 a->sethi(al, I3); a->nop(); a->add(I3, al.low10(), I3);
duke@435 731 a->ldsb( G5, I3, G4 ); idx++;
twisti@1162 732 a->ldsh( G5, al.low10(), G4); idx++;
twisti@1162 733 a->sethi(al, I3); a->nop(); a->add(I3, al.low10(), I3);
duke@435 734 a->ldsh( G5, I3, G4 ); idx++;
twisti@1162 735 a->lduw( G5, al.low10(), G4); idx++;
twisti@1162 736 a->sethi(al, I3); a->nop(); a->add(I3, al.low10(), I3);
duke@435 737 a->lduw( G5, I3, G4 ); idx++;
twisti@1162 738 a->ldub( G5, al.low10(), G4); idx++;
twisti@1162 739 a->sethi(al, I3); a->nop(); a->add(I3, al.low10(), I3);
duke@435 740 a->ldub( G5, I3, G4 ); idx++;
twisti@1162 741 a->lduh( G5, al.low10(), G4); idx++;
twisti@1162 742 a->sethi(al, I3); a->nop(); a->add(I3, al.low10(), I3);
duke@435 743 a->lduh( G5, I3, G4 ); idx++;
twisti@1162 744 a->ldx( G5, al.low10(), G4); idx++;
twisti@1162 745 a->sethi(al, I3); a->nop(); a->add(I3, al.low10(), I3);
twisti@1162 746 a->ldx( G5, I3, G4 ); idx++;
twisti@1162 747 a->ldd( G5, al.low10(), G4); idx++;
twisti@1162 748 a->sethi(al, I3); a->nop(); a->add(I3, al.low10(), I3);
twisti@1162 749 a->ldd( G5, I3, G4 ); idx++;
twisti@1162 750 a->ldf( FloatRegisterImpl::D, O2, -1, F14 ); idx++;
twisti@1162 751 a->sethi(al, I3); a->nop(); a->add(I3, al.low10(), I3);
twisti@1162 752 a->ldf( FloatRegisterImpl::S, O0, I3, F15 ); idx++;
duke@435 753
twisti@1162 754 a->stw( G5, G4, al.low10()); idx++;
twisti@1162 755 a->sethi(al, I3); a->nop(); a->add(I3, al.low10(), I3);
duke@435 756 a->stw( G5, G4, I3 ); idx++;
twisti@1162 757 a->stb( G5, G4, al.low10()); idx++;
twisti@1162 758 a->sethi(al, I3); a->nop(); a->add(I3, al.low10(), I3);
duke@435 759 a->stb( G5, G4, I3 ); idx++;
twisti@1162 760 a->sth( G5, G4, al.low10()); idx++;
twisti@1162 761 a->sethi(al, I3); a->nop(); a->add(I3, al.low10(), I3);
duke@435 762 a->sth( G5, G4, I3 ); idx++;
twisti@1162 763 a->stx( G5, G4, al.low10()); idx++;
twisti@1162 764 a->sethi(al, I3); a->nop(); a->add(I3, al.low10(), I3);
duke@435 765 a->stx( G5, G4, I3 ); idx++;
twisti@1162 766 a->std( G5, G4, al.low10()); idx++;
twisti@1162 767 a->sethi(al, I3); a->nop(); a->add(I3, al.low10(), I3);
duke@435 768 a->std( G5, G4, I3 ); idx++;
duke@435 769 a->stf( FloatRegisterImpl::S, F18, O2, -1 ); idx++;
twisti@1162 770 a->sethi(al, I3); a->nop(); a->add(I3, al.low10(), I3);
duke@435 771 a->stf( FloatRegisterImpl::S, F15, O0, I3 ); idx++;
duke@435 772
twisti@2103 773 nm = nativeMovRegMemPatching_at( cb.insts_begin() );
duke@435 774 nm->print();
duke@435 775 nm->set_offset( low10(0) );
duke@435 776 nm->print();
duke@435 777 nm->add_offset_in_bytes( low10(0xbb) * wordSize );
duke@435 778 nm->print();
duke@435 779
duke@435 780 while (--idx) {
duke@435 781 nm = nativeMovRegMemPatching_at( nm->next_instruction_address() );
duke@435 782 nm->print();
duke@435 783 for (idx1 = 0; idx1 < ARRAY_SIZE(offsets); idx1++) {
duke@435 784 nm->set_offset( nm->is_immediate() ? low10(offsets[idx1]) : offsets[idx1] );
duke@435 785 assert(nm->offset() == (nm->is_immediate() ? low10(offsets[idx1]) : offsets[idx1]),
duke@435 786 "check unit test");
duke@435 787 nm->print();
duke@435 788 }
duke@435 789 nm->add_offset_in_bytes( low10(0xbb) * wordSize );
duke@435 790 nm->print();
duke@435 791 }
duke@435 792
duke@435 793 VM_Version::revert();
duke@435 794 #endif // ASSERT
duke@435 795 }
duke@435 796 // End code for unit testing implementation of NativeMovRegMemPatching class
duke@435 797
duke@435 798
duke@435 799 //--------------------------------------------------------------------------------
duke@435 800
duke@435 801
duke@435 802 void NativeJump::verify() {
duke@435 803 NativeInstruction::verify();
duke@435 804 int i0 = long_at(sethi_offset);
duke@435 805 int i1 = long_at(jmpl_offset);
duke@435 806 assert((int)jmpl_offset == (int)NativeMovConstReg::add_offset, "sethi size ok");
duke@435 807 // verify the pattern "sethi %hi22(imm), treg ; jmpl treg, %lo10(imm), lreg"
duke@435 808 Register rd = inv_rd(i0);
duke@435 809 #ifndef _LP64
duke@435 810 if (!(is_op2(i0, Assembler::sethi_op2) && rd != G0 &&
duke@435 811 (is_op3(i1, Assembler::jmpl_op3, Assembler::arith_op) ||
duke@435 812 (TraceJumps && is_op3(i1, Assembler::add_op3, Assembler::arith_op))) &&
duke@435 813 inv_immed(i1) && (unsigned)get_simm13(i1) < (1 << 10) &&
duke@435 814 rd == inv_rs1(i1))) {
duke@435 815 fatal("not a jump_to instruction");
duke@435 816 }
duke@435 817 #else
duke@435 818 // In LP64, the jump instruction location varies for non relocatable
duke@435 819 // jumps, for example is could be sethi, xor, jmp instead of the
duke@435 820 // 7 instructions for sethi. So let's check sethi only.
duke@435 821 if (!is_op2(i0, Assembler::sethi_op2) && rd != G0 ) {
duke@435 822 fatal("not a jump_to instruction");
duke@435 823 }
duke@435 824 #endif
duke@435 825 }
duke@435 826
duke@435 827
duke@435 828 void NativeJump::print() {
duke@435 829 tty->print_cr(INTPTR_FORMAT ": jmpl reg, " INTPTR_FORMAT, instruction_address(), jump_destination());
duke@435 830 }
duke@435 831
duke@435 832
duke@435 833 // Code for unit testing implementation of NativeJump class
duke@435 834 void NativeJump::test() {
duke@435 835 #ifdef ASSERT
duke@435 836 ResourceMark rm;
duke@435 837 CodeBuffer cb("test", 100, 100);
duke@435 838 MacroAssembler* a = new MacroAssembler(&cb);
duke@435 839 NativeJump* nj;
duke@435 840 uint idx;
duke@435 841 int offsets[] = {
duke@435 842 0x0,
duke@435 843 0xffffffff,
duke@435 844 0x7fffffff,
duke@435 845 0x80000000,
duke@435 846 4096,
duke@435 847 4097,
duke@435 848 0x20,
duke@435 849 0x4000,
duke@435 850 };
duke@435 851
duke@435 852 VM_Version::allow_all();
duke@435 853
twisti@1162 854 AddressLiteral al(0x7fffbbbb, relocInfo::external_word_type);
twisti@1162 855 a->sethi(al, I3);
twisti@1162 856 a->jmpl(I3, al.low10(), G0, RelocationHolder::none);
duke@435 857 a->delayed()->nop();
twisti@1162 858 a->sethi(al, I3);
twisti@1162 859 a->jmpl(I3, al.low10(), L3, RelocationHolder::none);
duke@435 860 a->delayed()->nop();
duke@435 861
twisti@2103 862 nj = nativeJump_at( cb.insts_begin() );
duke@435 863 nj->print();
duke@435 864
duke@435 865 nj = nativeJump_at( nj->next_instruction_address() );
duke@435 866 for (idx = 0; idx < ARRAY_SIZE(offsets); idx++) {
duke@435 867 nj->set_jump_destination( nj->instruction_address() + offsets[idx] );
duke@435 868 assert(nj->jump_destination() == (nj->instruction_address() + offsets[idx]), "check unit test");
duke@435 869 nj->print();
duke@435 870 }
duke@435 871
duke@435 872 VM_Version::revert();
duke@435 873 #endif // ASSERT
duke@435 874 }
duke@435 875 // End code for unit testing implementation of NativeJump class
duke@435 876
duke@435 877
duke@435 878 void NativeJump::insert(address code_pos, address entry) {
duke@435 879 Unimplemented();
duke@435 880 }
duke@435 881
duke@435 882 // MT safe inserting of a jump over an unknown instruction sequence (used by nmethod::makeZombie)
duke@435 883 // The problem: jump_to <dest> is a 3-word instruction (including its delay slot).
duke@435 884 // Atomic write can be only with 1 word.
duke@435 885 void NativeJump::patch_verified_entry(address entry, address verified_entry, address dest) {
duke@435 886 // Here's one way to do it: Pre-allocate a three-word jump sequence somewhere
duke@435 887 // in the header of the nmethod, within a short branch's span of the patch point.
duke@435 888 // Set up the jump sequence using NativeJump::insert, and then use an annulled
duke@435 889 // unconditional branch at the target site (an atomic 1-word update).
duke@435 890 // Limitations: You can only patch nmethods, with any given nmethod patched at
duke@435 891 // most once, and the patch must be in the nmethod's header.
duke@435 892 // It's messy, but you can ask the CodeCache for the nmethod containing the
duke@435 893 // target address.
duke@435 894
duke@435 895 // %%%%% For now, do something MT-stupid:
duke@435 896 ResourceMark rm;
duke@435 897 int code_size = 1 * BytesPerInstWord;
duke@435 898 CodeBuffer cb(verified_entry, code_size + 1);
duke@435 899 MacroAssembler* a = new MacroAssembler(&cb);
duke@435 900 if (VM_Version::v9_instructions_work()) {
duke@435 901 a->ldsw(G0, 0, O7); // "ld" must agree with code in the signal handler
duke@435 902 } else {
duke@435 903 a->lduw(G0, 0, O7); // "ld" must agree with code in the signal handler
duke@435 904 }
duke@435 905 ICache::invalidate_range(verified_entry, code_size);
duke@435 906 }
duke@435 907
duke@435 908
duke@435 909 void NativeIllegalInstruction::insert(address code_pos) {
duke@435 910 NativeIllegalInstruction* nii = (NativeIllegalInstruction*) nativeInstruction_at(code_pos);
duke@435 911 nii->set_long_at(0, illegal_instruction());
duke@435 912 }
duke@435 913
duke@435 914 static int illegal_instruction_bits = 0;
duke@435 915
duke@435 916 int NativeInstruction::illegal_instruction() {
duke@435 917 if (illegal_instruction_bits == 0) {
duke@435 918 ResourceMark rm;
duke@435 919 char buf[40];
duke@435 920 CodeBuffer cbuf((address)&buf[0], 20);
duke@435 921 MacroAssembler* a = new MacroAssembler(&cbuf);
duke@435 922 address ia = a->pc();
duke@435 923 a->trap(ST_RESERVED_FOR_USER_0 + 1);
duke@435 924 int bits = *(int*)ia;
duke@435 925 assert(is_op3(bits, Assembler::trap_op3, Assembler::arith_op), "bad instruction");
duke@435 926 illegal_instruction_bits = bits;
duke@435 927 assert(illegal_instruction_bits != 0, "oops");
duke@435 928 }
duke@435 929 return illegal_instruction_bits;
duke@435 930 }
duke@435 931
duke@435 932 static int ic_miss_trap_bits = 0;
duke@435 933
duke@435 934 bool NativeInstruction::is_ic_miss_trap() {
duke@435 935 if (ic_miss_trap_bits == 0) {
duke@435 936 ResourceMark rm;
duke@435 937 char buf[40];
duke@435 938 CodeBuffer cbuf((address)&buf[0], 20);
duke@435 939 MacroAssembler* a = new MacroAssembler(&cbuf);
duke@435 940 address ia = a->pc();
duke@435 941 a->trap(Assembler::notEqual, Assembler::ptr_cc, G0, ST_RESERVED_FOR_USER_0 + 2);
duke@435 942 int bits = *(int*)ia;
duke@435 943 assert(is_op3(bits, Assembler::trap_op3, Assembler::arith_op), "bad instruction");
duke@435 944 ic_miss_trap_bits = bits;
duke@435 945 assert(ic_miss_trap_bits != 0, "oops");
duke@435 946 }
duke@435 947 return long_at(0) == ic_miss_trap_bits;
duke@435 948 }
duke@435 949
duke@435 950
duke@435 951 bool NativeInstruction::is_illegal() {
duke@435 952 if (illegal_instruction_bits == 0) {
duke@435 953 return false;
duke@435 954 }
duke@435 955 return long_at(0) == illegal_instruction_bits;
duke@435 956 }
duke@435 957
duke@435 958
duke@435 959 void NativeGeneralJump::verify() {
duke@435 960 assert(((NativeInstruction *)this)->is_jump() ||
duke@435 961 ((NativeInstruction *)this)->is_cond_jump(), "not a general jump instruction");
duke@435 962 }
duke@435 963
duke@435 964
duke@435 965 void NativeGeneralJump::insert_unconditional(address code_pos, address entry) {
duke@435 966 Assembler::Condition condition = Assembler::always;
duke@435 967 int x = Assembler::op2(Assembler::br_op2) | Assembler::annul(false) |
duke@435 968 Assembler::cond(condition) | Assembler::wdisp((intptr_t)entry, (intptr_t)code_pos, 22);
duke@435 969 NativeGeneralJump* ni = (NativeGeneralJump*) nativeInstruction_at(code_pos);
duke@435 970 ni->set_long_at(0, x);
duke@435 971 }
duke@435 972
duke@435 973
duke@435 974 // MT-safe patching of a jmp instruction (and following word).
duke@435 975 // First patches the second word, and then atomicly replaces
duke@435 976 // the first word with the first new instruction word.
duke@435 977 // Other processors might briefly see the old first word
duke@435 978 // followed by the new second word. This is OK if the old
duke@435 979 // second word is harmless, and the new second word may be
duke@435 980 // harmlessly executed in the delay slot of the call.
duke@435 981 void NativeGeneralJump::replace_mt_safe(address instr_addr, address code_buffer) {
duke@435 982 assert(Patching_lock->is_locked() ||
duke@435 983 SafepointSynchronize::is_at_safepoint(), "concurrent code patching");
duke@435 984 assert (instr_addr != NULL, "illegal address for code patching");
duke@435 985 NativeGeneralJump* h_jump = nativeGeneralJump_at (instr_addr); // checking that it is a call
duke@435 986 assert(NativeGeneralJump::instruction_size == 8, "wrong instruction size; must be 8");
duke@435 987 int i0 = ((int*)code_buffer)[0];
duke@435 988 int i1 = ((int*)code_buffer)[1];
duke@435 989 int* contention_addr = (int*) h_jump->addr_at(1*BytesPerInstWord);
duke@435 990 assert(inv_op(*contention_addr) == Assembler::arith_op ||
duke@435 991 *contention_addr == nop_instruction() || !VM_Version::v9_instructions_work(),
duke@435 992 "must not interfere with original call");
duke@435 993 // The set_long_at calls do the ICacheInvalidate so we just need to do them in reverse order
duke@435 994 h_jump->set_long_at(1*BytesPerInstWord, i1);
duke@435 995 h_jump->set_long_at(0*BytesPerInstWord, i0);
duke@435 996 // NOTE: It is possible that another thread T will execute
duke@435 997 // only the second patched word.
duke@435 998 // In other words, since the original instruction is this
duke@435 999 // jmp patching_stub; nop (NativeGeneralJump)
duke@435 1000 // and the new sequence from the buffer is this:
duke@435 1001 // sethi %hi(K), %r; add %r, %lo(K), %r (NativeMovConstReg)
duke@435 1002 // what T will execute is this:
duke@435 1003 // jmp patching_stub; add %r, %lo(K), %r
duke@435 1004 // thereby putting garbage into %r before calling the patching stub.
duke@435 1005 // This is OK, because the patching stub ignores the value of %r.
duke@435 1006
duke@435 1007 // Make sure the first-patched instruction, which may co-exist
duke@435 1008 // briefly with the call, will do something harmless.
duke@435 1009 assert(inv_op(*contention_addr) == Assembler::arith_op ||
duke@435 1010 *contention_addr == nop_instruction() || !VM_Version::v9_instructions_work(),
duke@435 1011 "must not interfere with original call");
duke@435 1012 }

mercurial