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