relocInfo_sparc.cpp revision 1472:c18cbe5936b8
1/*
2 * Copyright (c) 1998, 2009, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25# include "incls/_precompiled.incl"
26# include "incls/_relocInfo_sparc.cpp.incl"
27
28void Relocation::pd_set_data_value(address x, intptr_t o) {
29  NativeInstruction* ip = nativeInstruction_at(addr());
30  jint inst = ip->long_at(0);
31  assert(inst != NativeInstruction::illegal_instruction(), "no breakpoint");
32  switch (Assembler::inv_op(inst)) {
33
34  case Assembler::ldst_op:
35    #ifdef ASSERT
36      switch (Assembler::inv_op3(inst)) {
37        case Assembler::lduw_op3:
38        case Assembler::ldub_op3:
39        case Assembler::lduh_op3:
40        case Assembler::ldd_op3:
41        case Assembler::ldsw_op3:
42        case Assembler::ldsb_op3:
43        case Assembler::ldsh_op3:
44        case Assembler::ldx_op3:
45        case Assembler::ldf_op3:
46        case Assembler::lddf_op3:
47        case Assembler::stw_op3:
48        case Assembler::stb_op3:
49        case Assembler::sth_op3:
50        case Assembler::std_op3:
51        case Assembler::stx_op3:
52        case Assembler::stf_op3:
53        case Assembler::stdf_op3:
54        case Assembler::casa_op3:
55        case Assembler::casxa_op3:
56          break;
57        default:
58          ShouldNotReachHere();
59      }
60      goto do_non_sethi;
61    #endif
62
63  case Assembler::arith_op:
64    #ifdef ASSERT
65      switch (Assembler::inv_op3(inst)) {
66        case Assembler::or_op3:
67        case Assembler::add_op3:
68        case Assembler::jmpl_op3:
69          break;
70        default:
71          ShouldNotReachHere();
72      }
73    do_non_sethi:;
74    #endif
75    {
76    guarantee(Assembler::inv_immed(inst), "must have a simm13 field");
77    int simm13 = Assembler::low10((intptr_t)x) + o;
78    guarantee(Assembler::is_simm13(simm13), "offset can't overflow simm13");
79    inst &= ~Assembler::simm(    -1, 13);
80    inst |=  Assembler::simm(simm13, 13);
81    ip->set_long_at(0, inst);
82    }
83    break;
84
85  case Assembler::branch_op:
86    {
87#ifdef _LP64
88    jint inst2;
89    guarantee(Assembler::inv_op2(inst)==Assembler::sethi_op2, "must be sethi");
90    if (format() != 0) {
91      assert(type() == relocInfo::oop_type, "only narrow oops case");
92      jint np = oopDesc::encode_heap_oop((oop)x);
93      inst &= ~Assembler::hi22(-1);
94      inst |=  Assembler::hi22((intptr_t)np);
95      ip->set_long_at(0, inst);
96      inst2 = ip->long_at( NativeInstruction::nop_instruction_size );
97      guarantee(Assembler::inv_op(inst2)==Assembler::arith_op, "arith op");
98      ip->set_long_at(NativeInstruction::nop_instruction_size, ip->set_data32_simm13( inst2, (intptr_t)np));
99      break;
100    }
101    ip->set_data64_sethi( ip->addr_at(0), (intptr_t)x );
102#else
103    guarantee(Assembler::inv_op2(inst)==Assembler::sethi_op2, "must be sethi");
104    inst &= ~Assembler::hi22(     -1);
105    inst |=  Assembler::hi22((intptr_t)x);
106    // (ignore offset; it doesn't play into the sethi)
107    ip->set_long_at(0, inst);
108#endif
109    }
110    break;
111
112  default:
113    guarantee(false, "instruction must perform arithmetic or memory access");
114  }
115}
116
117
118address Relocation::pd_call_destination(address orig_addr) {
119  intptr_t adj = 0;
120  if (orig_addr != NULL) {
121    // We just moved this call instruction from orig_addr to addr().
122    // This means its target will appear to have grown by addr() - orig_addr.
123    adj = -( addr() - orig_addr );
124  }
125  if (NativeCall::is_call_at(addr())) {
126    NativeCall* call = nativeCall_at(addr());
127    return call->destination() + adj;
128  }
129  if (NativeFarCall::is_call_at(addr())) {
130    NativeFarCall* call = nativeFarCall_at(addr());
131    return call->destination() + adj;
132  }
133  // Special case:  Patchable branch local to the code cache.
134  // This will break badly if the code cache grows larger than a few Mb.
135  NativeGeneralJump* br = nativeGeneralJump_at(addr());
136  return br->jump_destination() + adj;
137}
138
139
140void Relocation::pd_set_call_destination(address x) {
141  if (NativeCall::is_call_at(addr())) {
142    NativeCall* call = nativeCall_at(addr());
143    call->set_destination(x);
144    return;
145  }
146  if (NativeFarCall::is_call_at(addr())) {
147    NativeFarCall* call = nativeFarCall_at(addr());
148    call->set_destination(x);
149    return;
150  }
151  // Special case:  Patchable branch local to the code cache.
152  // This will break badly if the code cache grows larger than a few Mb.
153  NativeGeneralJump* br = nativeGeneralJump_at(addr());
154  br->set_jump_destination(x);
155}
156
157
158address* Relocation::pd_address_in_code() {
159  // SPARC never embeds addresses in code, at present.
160  //assert(type() == relocInfo::oop_type, "only oops are inlined at present");
161  return (address*)addr();
162}
163
164
165address Relocation::pd_get_address_from_code() {
166  // SPARC never embeds addresses in code, at present.
167  //assert(type() == relocInfo::oop_type, "only oops are inlined at present");
168  return *(address*)addr();
169}
170
171
172int Relocation::pd_breakpoint_size() {
173  // minimum breakpoint size, in short words
174  return NativeIllegalInstruction::instruction_size / sizeof(short);
175}
176
177void Relocation::pd_swap_in_breakpoint(address x, short* instrs, int instrlen) {
178  Untested("pd_swap_in_breakpoint");
179  // %%% probably do not need a general instrlen; just use the trap size
180  if (instrs != NULL) {
181    assert(instrlen * sizeof(short) == NativeIllegalInstruction::instruction_size, "enough instrlen in reloc. data");
182    for (int i = 0; i < instrlen; i++) {
183      instrs[i] = ((short*)x)[i];
184    }
185  }
186  NativeIllegalInstruction::insert(x);
187}
188
189
190void Relocation::pd_swap_out_breakpoint(address x, short* instrs, int instrlen) {
191  Untested("pd_swap_out_breakpoint");
192  assert(instrlen * sizeof(short) == sizeof(int), "enough buf");
193  union { int l; short s[1]; } u;
194  for (int i = 0; i < instrlen; i++) {
195    u.s[i] = instrs[i];
196  }
197  NativeInstruction* ni = nativeInstruction_at(x);
198  ni->set_long_at(0, u.l);
199}
200
201void poll_Relocation::fix_relocation_after_move(const CodeBuffer* src, CodeBuffer* dest) {
202}
203
204void poll_return_Relocation::fix_relocation_after_move(const CodeBuffer* src, CodeBuffer* dest) {
205}
206