annotate src/cpu/sparc/vm/nativeInst_sparc.cpp @ 18408:2c3666f44855

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