Mercurial > hg > graal-jvmci-8
annotate src/cpu/sparc/vm/macroAssembler_sparc.cpp @ 10997:46c544b8fbfc
8008407: remove SPARC V8 support
Summary: Removed most of the SPARC V8 instructions
Reviewed-by: kvn, twisti
author | morris |
---|---|
date | Fri, 07 Jun 2013 16:46:37 -0700 |
parents | 8d52e305a777 |
children | 7875ea94bea5 |
rev | line source |
---|---|
7204 | 1 /* |
2 * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. | |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
4 * | |
5 * This code is free software; you can redistribute it and/or modify it | |
6 * under the terms of the GNU General Public License version 2 only, as | |
7 * published by the Free Software Foundation. | |
8 * | |
9 * This code is distributed in the hope that it will be useful, but WITHOUT | |
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
12 * version 2 for more details (a copy is included in the LICENSE file that | |
13 * accompanied this code). | |
14 * | |
15 * You should have received a copy of the GNU General Public License version | |
16 * 2 along with this work; if not, write to the Free Software Foundation, | |
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
18 * | |
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | |
20 * or visit www.oracle.com if you need additional information or have any | |
21 * questions. | |
22 * | |
23 */ | |
24 | |
25 #include "precompiled.hpp" | |
26 #include "asm/assembler.inline.hpp" | |
27 #include "compiler/disassembler.hpp" | |
28 #include "gc_interface/collectedHeap.inline.hpp" | |
29 #include "interpreter/interpreter.hpp" | |
30 #include "memory/cardTableModRefBS.hpp" | |
31 #include "memory/resourceArea.hpp" | |
32 #include "prims/methodHandles.hpp" | |
33 #include "runtime/biasedLocking.hpp" | |
34 #include "runtime/interfaceSupport.hpp" | |
35 #include "runtime/objectMonitor.hpp" | |
36 #include "runtime/os.hpp" | |
37 #include "runtime/sharedRuntime.hpp" | |
38 #include "runtime/stubRoutines.hpp" | |
8001
db9981fd3124
8005915: Unify SERIALGC and INCLUDE_ALTERNATE_GCS
jprovino
parents:
7476
diff
changeset
|
39 #include "utilities/macros.hpp" |
db9981fd3124
8005915: Unify SERIALGC and INCLUDE_ALTERNATE_GCS
jprovino
parents:
7476
diff
changeset
|
40 #if INCLUDE_ALL_GCS |
7204 | 41 #include "gc_implementation/g1/g1CollectedHeap.inline.hpp" |
42 #include "gc_implementation/g1/g1SATBCardTableModRefBS.hpp" | |
43 #include "gc_implementation/g1/heapRegion.hpp" | |
8001
db9981fd3124
8005915: Unify SERIALGC and INCLUDE_ALTERNATE_GCS
jprovino
parents:
7476
diff
changeset
|
44 #endif // INCLUDE_ALL_GCS |
7204 | 45 |
46 #ifdef PRODUCT | |
47 #define BLOCK_COMMENT(str) /* nothing */ | |
48 #define STOP(error) stop(error) | |
49 #else | |
50 #define BLOCK_COMMENT(str) block_comment(str) | |
51 #define STOP(error) block_comment(error); stop(error) | |
52 #endif | |
53 | |
54 // Convert the raw encoding form into the form expected by the | |
55 // constructor for Address. | |
56 Address Address::make_raw(int base, int index, int scale, int disp, relocInfo::relocType disp_reloc) { | |
57 assert(scale == 0, "not supported"); | |
58 RelocationHolder rspec; | |
59 if (disp_reloc != relocInfo::none) { | |
60 rspec = Relocation::spec_simple(disp_reloc); | |
61 } | |
62 | |
63 Register rindex = as_Register(index); | |
64 if (rindex != G0) { | |
65 Address madr(as_Register(base), rindex); | |
66 madr._rspec = rspec; | |
67 return madr; | |
68 } else { | |
69 Address madr(as_Register(base), disp); | |
70 madr._rspec = rspec; | |
71 return madr; | |
72 } | |
73 } | |
74 | |
75 Address Argument::address_in_frame() const { | |
76 // Warning: In LP64 mode disp will occupy more than 10 bits, but | |
77 // op codes such as ld or ldx, only access disp() to get | |
78 // their simm13 argument. | |
79 int disp = ((_number - Argument::n_register_parameters + frame::memory_parameter_word_sp_offset) * BytesPerWord) + STACK_BIAS; | |
80 if (is_in()) | |
81 return Address(FP, disp); // In argument. | |
82 else | |
83 return Address(SP, disp); // Out argument. | |
84 } | |
85 | |
86 static const char* argumentNames[][2] = { | |
87 {"A0","P0"}, {"A1","P1"}, {"A2","P2"}, {"A3","P3"}, {"A4","P4"}, | |
88 {"A5","P5"}, {"A6","P6"}, {"A7","P7"}, {"A8","P8"}, {"A9","P9"}, | |
89 {"A(n>9)","P(n>9)"} | |
90 }; | |
91 | |
92 const char* Argument::name() const { | |
93 int nofArgs = sizeof argumentNames / sizeof argumentNames[0]; | |
94 int num = number(); | |
95 if (num >= nofArgs) num = nofArgs - 1; | |
96 return argumentNames[num][is_in() ? 1 : 0]; | |
97 } | |
98 | |
99 #ifdef ASSERT | |
100 // On RISC, there's no benefit to verifying instruction boundaries. | |
101 bool AbstractAssembler::pd_check_instruction_mark() { return false; } | |
102 #endif | |
103 | |
104 // Patch instruction inst at offset inst_pos to refer to dest_pos | |
105 // and return the resulting instruction. | |
106 // We should have pcs, not offsets, but since all is relative, it will work out | |
107 // OK. | |
108 int MacroAssembler::patched_branch(int dest_pos, int inst, int inst_pos) { | |
109 int m; // mask for displacement field | |
110 int v; // new value for displacement field | |
111 const int word_aligned_ones = -4; | |
112 switch (inv_op(inst)) { | |
113 default: ShouldNotReachHere(); | |
114 case call_op: m = wdisp(word_aligned_ones, 0, 30); v = wdisp(dest_pos, inst_pos, 30); break; | |
115 case branch_op: | |
116 switch (inv_op2(inst)) { | |
117 case fbp_op2: m = wdisp( word_aligned_ones, 0, 19); v = wdisp( dest_pos, inst_pos, 19); break; | |
118 case bp_op2: m = wdisp( word_aligned_ones, 0, 19); v = wdisp( dest_pos, inst_pos, 19); break; | |
119 case fb_op2: m = wdisp( word_aligned_ones, 0, 22); v = wdisp( dest_pos, inst_pos, 22); break; | |
120 case br_op2: m = wdisp( word_aligned_ones, 0, 22); v = wdisp( dest_pos, inst_pos, 22); break; | |
121 case bpr_op2: { | |
122 if (is_cbcond(inst)) { | |
123 m = wdisp10(word_aligned_ones, 0); | |
124 v = wdisp10(dest_pos, inst_pos); | |
125 } else { | |
126 m = wdisp16(word_aligned_ones, 0); | |
127 v = wdisp16(dest_pos, inst_pos); | |
128 } | |
129 break; | |
130 } | |
131 default: ShouldNotReachHere(); | |
132 } | |
133 } | |
134 return inst & ~m | v; | |
135 } | |
136 | |
137 // Return the offset of the branch destionation of instruction inst | |
138 // at offset pos. | |
139 // Should have pcs, but since all is relative, it works out. | |
140 int MacroAssembler::branch_destination(int inst, int pos) { | |
141 int r; | |
142 switch (inv_op(inst)) { | |
143 default: ShouldNotReachHere(); | |
144 case call_op: r = inv_wdisp(inst, pos, 30); break; | |
145 case branch_op: | |
146 switch (inv_op2(inst)) { | |
147 case fbp_op2: r = inv_wdisp( inst, pos, 19); break; | |
148 case bp_op2: r = inv_wdisp( inst, pos, 19); break; | |
149 case fb_op2: r = inv_wdisp( inst, pos, 22); break; | |
150 case br_op2: r = inv_wdisp( inst, pos, 22); break; | |
151 case bpr_op2: { | |
152 if (is_cbcond(inst)) { | |
153 r = inv_wdisp10(inst, pos); | |
154 } else { | |
155 r = inv_wdisp16(inst, pos); | |
156 } | |
157 break; | |
158 } | |
159 default: ShouldNotReachHere(); | |
160 } | |
161 } | |
162 return r; | |
163 } | |
164 | |
165 void MacroAssembler::null_check(Register reg, int offset) { | |
166 if (needs_explicit_null_check((intptr_t)offset)) { | |
167 // provoke OS NULL exception if reg = NULL by | |
168 // accessing M[reg] w/o changing any registers | |
169 ld_ptr(reg, 0, G0); | |
170 } | |
171 else { | |
172 // nothing to do, (later) access of M[reg + offset] | |
173 // will provoke OS NULL exception if reg = NULL | |
174 } | |
175 } | |
176 | |
177 // Ring buffer jumps | |
178 | |
179 #ifndef PRODUCT | |
180 void MacroAssembler::ret( bool trace ) { if (trace) { | |
181 mov(I7, O7); // traceable register | |
182 JMP(O7, 2 * BytesPerInstWord); | |
183 } else { | |
184 jmpl( I7, 2 * BytesPerInstWord, G0 ); | |
185 } | |
186 } | |
187 | |
188 void MacroAssembler::retl( bool trace ) { if (trace) JMP(O7, 2 * BytesPerInstWord); | |
189 else jmpl( O7, 2 * BytesPerInstWord, G0 ); } | |
190 #endif /* PRODUCT */ | |
191 | |
192 | |
193 void MacroAssembler::jmp2(Register r1, Register r2, const char* file, int line ) { | |
194 assert_not_delayed(); | |
195 // This can only be traceable if r1 & r2 are visible after a window save | |
196 if (TraceJumps) { | |
197 #ifndef PRODUCT | |
198 save_frame(0); | |
199 verify_thread(); | |
200 ld(G2_thread, in_bytes(JavaThread::jmp_ring_index_offset()), O0); | |
201 add(G2_thread, in_bytes(JavaThread::jmp_ring_offset()), O1); | |
202 sll(O0, exact_log2(4*sizeof(intptr_t)), O2); | |
203 add(O2, O1, O1); | |
204 | |
205 add(r1->after_save(), r2->after_save(), O2); | |
206 set((intptr_t)file, O3); | |
207 set(line, O4); | |
208 Label L; | |
209 // get nearby pc, store jmp target | |
210 call(L, relocInfo::none); // No relocation for call to pc+0x8 | |
211 delayed()->st(O2, O1, 0); | |
212 bind(L); | |
213 | |
214 // store nearby pc | |
215 st(O7, O1, sizeof(intptr_t)); | |
216 // store file | |
217 st(O3, O1, 2*sizeof(intptr_t)); | |
218 // store line | |
219 st(O4, O1, 3*sizeof(intptr_t)); | |
220 add(O0, 1, O0); | |
221 and3(O0, JavaThread::jump_ring_buffer_size - 1, O0); | |
222 st(O0, G2_thread, in_bytes(JavaThread::jmp_ring_index_offset())); | |
223 restore(); | |
224 #endif /* PRODUCT */ | |
225 } | |
226 jmpl(r1, r2, G0); | |
227 } | |
228 void MacroAssembler::jmp(Register r1, int offset, const char* file, int line ) { | |
229 assert_not_delayed(); | |
230 // This can only be traceable if r1 is visible after a window save | |
231 if (TraceJumps) { | |
232 #ifndef PRODUCT | |
233 save_frame(0); | |
234 verify_thread(); | |
235 ld(G2_thread, in_bytes(JavaThread::jmp_ring_index_offset()), O0); | |
236 add(G2_thread, in_bytes(JavaThread::jmp_ring_offset()), O1); | |
237 sll(O0, exact_log2(4*sizeof(intptr_t)), O2); | |
238 add(O2, O1, O1); | |
239 | |
240 add(r1->after_save(), offset, O2); | |
241 set((intptr_t)file, O3); | |
242 set(line, O4); | |
243 Label L; | |
244 // get nearby pc, store jmp target | |
245 call(L, relocInfo::none); // No relocation for call to pc+0x8 | |
246 delayed()->st(O2, O1, 0); | |
247 bind(L); | |
248 | |
249 // store nearby pc | |
250 st(O7, O1, sizeof(intptr_t)); | |
251 // store file | |
252 st(O3, O1, 2*sizeof(intptr_t)); | |
253 // store line | |
254 st(O4, O1, 3*sizeof(intptr_t)); | |
255 add(O0, 1, O0); | |
256 and3(O0, JavaThread::jump_ring_buffer_size - 1, O0); | |
257 st(O0, G2_thread, in_bytes(JavaThread::jmp_ring_index_offset())); | |
258 restore(); | |
259 #endif /* PRODUCT */ | |
260 } | |
261 jmp(r1, offset); | |
262 } | |
263 | |
264 // This code sequence is relocatable to any address, even on LP64. | |
265 void MacroAssembler::jumpl(const AddressLiteral& addrlit, Register temp, Register d, int offset, const char* file, int line) { | |
266 assert_not_delayed(); | |
267 // Force fixed length sethi because NativeJump and NativeFarCall don't handle | |
268 // variable length instruction streams. | |
269 patchable_sethi(addrlit, temp); | |
270 Address a(temp, addrlit.low10() + offset); // Add the offset to the displacement. | |
271 if (TraceJumps) { | |
272 #ifndef PRODUCT | |
273 // Must do the add here so relocation can find the remainder of the | |
274 // value to be relocated. | |
275 add(a.base(), a.disp(), a.base(), addrlit.rspec(offset)); | |
276 save_frame(0); | |
277 verify_thread(); | |
278 ld(G2_thread, in_bytes(JavaThread::jmp_ring_index_offset()), O0); | |
279 add(G2_thread, in_bytes(JavaThread::jmp_ring_offset()), O1); | |
280 sll(O0, exact_log2(4*sizeof(intptr_t)), O2); | |
281 add(O2, O1, O1); | |
282 | |
283 set((intptr_t)file, O3); | |
284 set(line, O4); | |
285 Label L; | |
286 | |
287 // get nearby pc, store jmp target | |
288 call(L, relocInfo::none); // No relocation for call to pc+0x8 | |
289 delayed()->st(a.base()->after_save(), O1, 0); | |
290 bind(L); | |
291 | |
292 // store nearby pc | |
293 st(O7, O1, sizeof(intptr_t)); | |
294 // store file | |
295 st(O3, O1, 2*sizeof(intptr_t)); | |
296 // store line | |
297 st(O4, O1, 3*sizeof(intptr_t)); | |
298 add(O0, 1, O0); | |
299 and3(O0, JavaThread::jump_ring_buffer_size - 1, O0); | |
300 st(O0, G2_thread, in_bytes(JavaThread::jmp_ring_index_offset())); | |
301 restore(); | |
302 jmpl(a.base(), G0, d); | |
303 #else | |
304 jmpl(a.base(), a.disp(), d); | |
305 #endif /* PRODUCT */ | |
306 } else { | |
307 jmpl(a.base(), a.disp(), d); | |
308 } | |
309 } | |
310 | |
311 void MacroAssembler::jump(const AddressLiteral& addrlit, Register temp, int offset, const char* file, int line) { | |
312 jumpl(addrlit, temp, G0, offset, file, line); | |
313 } | |
314 | |
315 | |
316 // Conditional breakpoint (for assertion checks in assembly code) | |
317 void MacroAssembler::breakpoint_trap(Condition c, CC cc) { | |
318 trap(c, cc, G0, ST_RESERVED_FOR_USER_0); | |
319 } | |
320 | |
321 // We want to use ST_BREAKPOINT here, but the debugger is confused by it. | |
322 void MacroAssembler::breakpoint_trap() { | |
323 trap(ST_RESERVED_FOR_USER_0); | |
324 } | |
325 | |
326 // Write serialization page so VM thread can do a pseudo remote membar | |
327 // We use the current thread pointer to calculate a thread specific | |
328 // offset to write to within the page. This minimizes bus traffic | |
329 // due to cache line collision. | |
330 void MacroAssembler::serialize_memory(Register thread, Register tmp1, Register tmp2) { | |
331 srl(thread, os::get_serialize_page_shift_count(), tmp2); | |
332 if (Assembler::is_simm13(os::vm_page_size())) { | |
333 and3(tmp2, (os::vm_page_size() - sizeof(int)), tmp2); | |
334 } | |
335 else { | |
336 set((os::vm_page_size() - sizeof(int)), tmp1); | |
337 and3(tmp2, tmp1, tmp2); | |
338 } | |
339 set(os::get_memory_serialize_page(), tmp1); | |
340 st(G0, tmp1, tmp2); | |
341 } | |
342 | |
343 | |
344 | |
345 void MacroAssembler::enter() { | |
346 Unimplemented(); | |
347 } | |
348 | |
349 void MacroAssembler::leave() { | |
350 Unimplemented(); | |
351 } | |
352 | |
353 // Calls to C land | |
354 | |
355 #ifdef ASSERT | |
356 // a hook for debugging | |
357 static Thread* reinitialize_thread() { | |
358 return ThreadLocalStorage::thread(); | |
359 } | |
360 #else | |
361 #define reinitialize_thread ThreadLocalStorage::thread | |
362 #endif | |
363 | |
364 #ifdef ASSERT | |
365 address last_get_thread = NULL; | |
366 #endif | |
367 | |
368 // call this when G2_thread is not known to be valid | |
369 void MacroAssembler::get_thread() { | |
370 save_frame(0); // to avoid clobbering O0 | |
371 mov(G1, L0); // avoid clobbering G1 | |
372 mov(G5_method, L1); // avoid clobbering G5 | |
373 mov(G3, L2); // avoid clobbering G3 also | |
374 mov(G4, L5); // avoid clobbering G4 | |
375 #ifdef ASSERT | |
376 AddressLiteral last_get_thread_addrlit(&last_get_thread); | |
377 set(last_get_thread_addrlit, L3); | |
10997 | 378 rdpc(L4); |
379 inc(L4, 3 * BytesPerInstWord); // skip rdpc + inc + st_ptr to point L4 at call st_ptr(L4, L3, 0); | |
7204 | 380 #endif |
381 call(CAST_FROM_FN_PTR(address, reinitialize_thread), relocInfo::runtime_call_type); | |
382 delayed()->nop(); | |
383 mov(L0, G1); | |
384 mov(L1, G5_method); | |
385 mov(L2, G3); | |
386 mov(L5, G4); | |
387 restore(O0, 0, G2_thread); | |
388 } | |
389 | |
390 static Thread* verify_thread_subroutine(Thread* gthread_value) { | |
391 Thread* correct_value = ThreadLocalStorage::thread(); | |
392 guarantee(gthread_value == correct_value, "G2_thread value must be the thread"); | |
393 return correct_value; | |
394 } | |
395 | |
396 void MacroAssembler::verify_thread() { | |
397 if (VerifyThread) { | |
398 // NOTE: this chops off the heads of the 64-bit O registers. | |
399 #ifdef CC_INTERP | |
400 save_frame(0); | |
401 #else | |
402 // make sure G2_thread contains the right value | |
403 save_frame_and_mov(0, Lmethod, Lmethod); // to avoid clobbering O0 (and propagate Lmethod for -Xprof) | |
404 mov(G1, L1); // avoid clobbering G1 | |
405 // G2 saved below | |
406 mov(G3, L3); // avoid clobbering G3 | |
407 mov(G4, L4); // avoid clobbering G4 | |
408 mov(G5_method, L5); // avoid clobbering G5_method | |
409 #endif /* CC_INTERP */ | |
410 #if defined(COMPILER2) && !defined(_LP64) | |
411 // Save & restore possible 64-bit Long arguments in G-regs | |
412 srlx(G1,32,L0); | |
413 srlx(G4,32,L6); | |
414 #endif | |
415 call(CAST_FROM_FN_PTR(address,verify_thread_subroutine), relocInfo::runtime_call_type); | |
416 delayed()->mov(G2_thread, O0); | |
417 | |
418 mov(L1, G1); // Restore G1 | |
419 // G2 restored below | |
420 mov(L3, G3); // restore G3 | |
421 mov(L4, G4); // restore G4 | |
422 mov(L5, G5_method); // restore G5_method | |
423 #if defined(COMPILER2) && !defined(_LP64) | |
424 // Save & restore possible 64-bit Long arguments in G-regs | |
425 sllx(L0,32,G2); // Move old high G1 bits high in G2 | |
426 srl(G1, 0,G1); // Clear current high G1 bits | |
427 or3 (G1,G2,G1); // Recover 64-bit G1 | |
428 sllx(L6,32,G2); // Move old high G4 bits high in G2 | |
429 srl(G4, 0,G4); // Clear current high G4 bits | |
430 or3 (G4,G2,G4); // Recover 64-bit G4 | |
431 #endif | |
432 restore(O0, 0, G2_thread); | |
433 } | |
434 } | |
435 | |
436 | |
437 void MacroAssembler::save_thread(const Register thread_cache) { | |
438 verify_thread(); | |
439 if (thread_cache->is_valid()) { | |
440 assert(thread_cache->is_local() || thread_cache->is_in(), "bad volatile"); | |
441 mov(G2_thread, thread_cache); | |
442 } | |
443 if (VerifyThread) { | |
444 // smash G2_thread, as if the VM were about to anyway | |
445 set(0x67676767, G2_thread); | |
446 } | |
447 } | |
448 | |
449 | |
450 void MacroAssembler::restore_thread(const Register thread_cache) { | |
451 if (thread_cache->is_valid()) { | |
452 assert(thread_cache->is_local() || thread_cache->is_in(), "bad volatile"); | |
453 mov(thread_cache, G2_thread); | |
454 verify_thread(); | |
455 } else { | |
456 // do it the slow way | |
457 get_thread(); | |
458 } | |
459 } | |
460 | |
461 | |
462 // %%% maybe get rid of [re]set_last_Java_frame | |
463 void MacroAssembler::set_last_Java_frame(Register last_java_sp, Register last_Java_pc) { | |
464 assert_not_delayed(); | |
465 Address flags(G2_thread, JavaThread::frame_anchor_offset() + | |
466 JavaFrameAnchor::flags_offset()); | |
467 Address pc_addr(G2_thread, JavaThread::last_Java_pc_offset()); | |
468 | |
469 // Always set last_Java_pc and flags first because once last_Java_sp is visible | |
470 // has_last_Java_frame is true and users will look at the rest of the fields. | |
471 // (Note: flags should always be zero before we get here so doesn't need to be set.) | |
472 | |
473 #ifdef ASSERT | |
474 // Verify that flags was zeroed on return to Java | |
475 Label PcOk; | |
476 save_frame(0); // to avoid clobbering O0 | |
477 ld_ptr(pc_addr, L0); | |
478 br_null_short(L0, Assembler::pt, PcOk); | |
479 STOP("last_Java_pc not zeroed before leaving Java"); | |
480 bind(PcOk); | |
481 | |
482 // Verify that flags was zeroed on return to Java | |
483 Label FlagsOk; | |
484 ld(flags, L0); | |
485 tst(L0); | |
486 br(Assembler::zero, false, Assembler::pt, FlagsOk); | |
487 delayed() -> restore(); | |
488 STOP("flags not zeroed before leaving Java"); | |
489 bind(FlagsOk); | |
490 #endif /* ASSERT */ | |
491 // | |
492 // When returning from calling out from Java mode the frame anchor's last_Java_pc | |
493 // will always be set to NULL. It is set here so that if we are doing a call to | |
494 // native (not VM) that we capture the known pc and don't have to rely on the | |
495 // native call having a standard frame linkage where we can find the pc. | |
496 | |
497 if (last_Java_pc->is_valid()) { | |
498 st_ptr(last_Java_pc, pc_addr); | |
499 } | |
500 | |
501 #ifdef _LP64 | |
502 #ifdef ASSERT | |
503 // Make sure that we have an odd stack | |
504 Label StackOk; | |
505 andcc(last_java_sp, 0x01, G0); | |
506 br(Assembler::notZero, false, Assembler::pt, StackOk); | |
507 delayed()->nop(); | |
508 STOP("Stack Not Biased in set_last_Java_frame"); | |
509 bind(StackOk); | |
510 #endif // ASSERT | |
511 assert( last_java_sp != G4_scratch, "bad register usage in set_last_Java_frame"); | |
512 add( last_java_sp, STACK_BIAS, G4_scratch ); | |
513 st_ptr(G4_scratch, G2_thread, JavaThread::last_Java_sp_offset()); | |
514 #else | |
515 st_ptr(last_java_sp, G2_thread, JavaThread::last_Java_sp_offset()); | |
516 #endif // _LP64 | |
517 } | |
518 | |
519 void MacroAssembler::reset_last_Java_frame(void) { | |
520 assert_not_delayed(); | |
521 | |
522 Address sp_addr(G2_thread, JavaThread::last_Java_sp_offset()); | |
523 Address pc_addr(G2_thread, JavaThread::frame_anchor_offset() + JavaFrameAnchor::last_Java_pc_offset()); | |
524 Address flags (G2_thread, JavaThread::frame_anchor_offset() + JavaFrameAnchor::flags_offset()); | |
525 | |
526 #ifdef ASSERT | |
527 // check that it WAS previously set | |
528 #ifdef CC_INTERP | |
529 save_frame(0); | |
530 #else | |
531 save_frame_and_mov(0, Lmethod, Lmethod); // Propagate Lmethod to helper frame for -Xprof | |
532 #endif /* CC_INTERP */ | |
533 ld_ptr(sp_addr, L0); | |
534 tst(L0); | |
535 breakpoint_trap(Assembler::zero, Assembler::ptr_cc); | |
536 restore(); | |
537 #endif // ASSERT | |
538 | |
539 st_ptr(G0, sp_addr); | |
540 // Always return last_Java_pc to zero | |
541 st_ptr(G0, pc_addr); | |
542 // Always null flags after return to Java | |
543 st(G0, flags); | |
544 } | |
545 | |
546 | |
547 void MacroAssembler::call_VM_base( | |
548 Register oop_result, | |
549 Register thread_cache, | |
550 Register last_java_sp, | |
551 address entry_point, | |
552 int number_of_arguments, | |
553 bool check_exceptions) | |
554 { | |
555 assert_not_delayed(); | |
556 | |
557 // determine last_java_sp register | |
558 if (!last_java_sp->is_valid()) { | |
559 last_java_sp = SP; | |
560 } | |
561 // debugging support | |
562 assert(number_of_arguments >= 0 , "cannot have negative number of arguments"); | |
563 | |
564 // 64-bit last_java_sp is biased! | |
565 set_last_Java_frame(last_java_sp, noreg); | |
566 if (VerifyThread) mov(G2_thread, O0); // about to be smashed; pass early | |
567 save_thread(thread_cache); | |
568 // do the call | |
569 call(entry_point, relocInfo::runtime_call_type); | |
570 if (!VerifyThread) | |
571 delayed()->mov(G2_thread, O0); // pass thread as first argument | |
572 else | |
573 delayed()->nop(); // (thread already passed) | |
574 restore_thread(thread_cache); | |
575 reset_last_Java_frame(); | |
576 | |
577 // check for pending exceptions. use Gtemp as scratch register. | |
578 if (check_exceptions) { | |
579 check_and_forward_exception(Gtemp); | |
580 } | |
581 | |
582 #ifdef ASSERT | |
583 set(badHeapWordVal, G3); | |
584 set(badHeapWordVal, G4); | |
585 set(badHeapWordVal, G5); | |
586 #endif | |
587 | |
588 // get oop result if there is one and reset the value in the thread | |
589 if (oop_result->is_valid()) { | |
590 get_vm_result(oop_result); | |
591 } | |
592 } | |
593 | |
594 void MacroAssembler::check_and_forward_exception(Register scratch_reg) | |
595 { | |
596 Label L; | |
597 | |
598 check_and_handle_popframe(scratch_reg); | |
599 check_and_handle_earlyret(scratch_reg); | |
600 | |
601 Address exception_addr(G2_thread, Thread::pending_exception_offset()); | |
602 ld_ptr(exception_addr, scratch_reg); | |
603 br_null_short(scratch_reg, pt, L); | |
604 // we use O7 linkage so that forward_exception_entry has the issuing PC | |
605 call(StubRoutines::forward_exception_entry(), relocInfo::runtime_call_type); | |
606 delayed()->nop(); | |
607 bind(L); | |
608 } | |
609 | |
610 | |
611 void MacroAssembler::check_and_handle_popframe(Register scratch_reg) { | |
612 } | |
613 | |
614 | |
615 void MacroAssembler::check_and_handle_earlyret(Register scratch_reg) { | |
616 } | |
617 | |
618 | |
619 void MacroAssembler::call_VM(Register oop_result, address entry_point, int number_of_arguments, bool check_exceptions) { | |
620 call_VM_base(oop_result, noreg, noreg, entry_point, number_of_arguments, check_exceptions); | |
621 } | |
622 | |
623 | |
624 void MacroAssembler::call_VM(Register oop_result, address entry_point, Register arg_1, bool check_exceptions) { | |
625 // O0 is reserved for the thread | |
626 mov(arg_1, O1); | |
627 call_VM(oop_result, entry_point, 1, check_exceptions); | |
628 } | |
629 | |
630 | |
631 void MacroAssembler::call_VM(Register oop_result, address entry_point, Register arg_1, Register arg_2, bool check_exceptions) { | |
632 // O0 is reserved for the thread | |
633 mov(arg_1, O1); | |
634 mov(arg_2, O2); assert(arg_2 != O1, "smashed argument"); | |
635 call_VM(oop_result, entry_point, 2, check_exceptions); | |
636 } | |
637 | |
638 | |
639 void MacroAssembler::call_VM(Register oop_result, address entry_point, Register arg_1, Register arg_2, Register arg_3, bool check_exceptions) { | |
640 // O0 is reserved for the thread | |
641 mov(arg_1, O1); | |
642 mov(arg_2, O2); assert(arg_2 != O1, "smashed argument"); | |
643 mov(arg_3, O3); assert(arg_3 != O1 && arg_3 != O2, "smashed argument"); | |
644 call_VM(oop_result, entry_point, 3, check_exceptions); | |
645 } | |
646 | |
647 | |
648 | |
649 // Note: The following call_VM overloadings are useful when a "save" | |
650 // has already been performed by a stub, and the last Java frame is | |
651 // the previous one. In that case, last_java_sp must be passed as FP | |
652 // instead of SP. | |
653 | |
654 | |
655 void MacroAssembler::call_VM(Register oop_result, Register last_java_sp, address entry_point, int number_of_arguments, bool check_exceptions) { | |
656 call_VM_base(oop_result, noreg, last_java_sp, entry_point, number_of_arguments, check_exceptions); | |
657 } | |
658 | |
659 | |
660 void MacroAssembler::call_VM(Register oop_result, Register last_java_sp, address entry_point, Register arg_1, bool check_exceptions) { | |
661 // O0 is reserved for the thread | |
662 mov(arg_1, O1); | |
663 call_VM(oop_result, last_java_sp, entry_point, 1, check_exceptions); | |
664 } | |
665 | |
666 | |
667 void MacroAssembler::call_VM(Register oop_result, Register last_java_sp, address entry_point, Register arg_1, Register arg_2, bool check_exceptions) { | |
668 // O0 is reserved for the thread | |
669 mov(arg_1, O1); | |
670 mov(arg_2, O2); assert(arg_2 != O1, "smashed argument"); | |
671 call_VM(oop_result, last_java_sp, entry_point, 2, check_exceptions); | |
672 } | |
673 | |
674 | |
675 void MacroAssembler::call_VM(Register oop_result, Register last_java_sp, address entry_point, Register arg_1, Register arg_2, Register arg_3, bool check_exceptions) { | |
676 // O0 is reserved for the thread | |
677 mov(arg_1, O1); | |
678 mov(arg_2, O2); assert(arg_2 != O1, "smashed argument"); | |
679 mov(arg_3, O3); assert(arg_3 != O1 && arg_3 != O2, "smashed argument"); | |
680 call_VM(oop_result, last_java_sp, entry_point, 3, check_exceptions); | |
681 } | |
682 | |
683 | |
684 | |
685 void MacroAssembler::call_VM_leaf_base(Register thread_cache, address entry_point, int number_of_arguments) { | |
686 assert_not_delayed(); | |
687 save_thread(thread_cache); | |
688 // do the call | |
689 call(entry_point, relocInfo::runtime_call_type); | |
690 delayed()->nop(); | |
691 restore_thread(thread_cache); | |
692 #ifdef ASSERT | |
693 set(badHeapWordVal, G3); | |
694 set(badHeapWordVal, G4); | |
695 set(badHeapWordVal, G5); | |
696 #endif | |
697 } | |
698 | |
699 | |
700 void MacroAssembler::call_VM_leaf(Register thread_cache, address entry_point, int number_of_arguments) { | |
701 call_VM_leaf_base(thread_cache, entry_point, number_of_arguments); | |
702 } | |
703 | |
704 | |
705 void MacroAssembler::call_VM_leaf(Register thread_cache, address entry_point, Register arg_1) { | |
706 mov(arg_1, O0); | |
707 call_VM_leaf(thread_cache, entry_point, 1); | |
708 } | |
709 | |
710 | |
711 void MacroAssembler::call_VM_leaf(Register thread_cache, address entry_point, Register arg_1, Register arg_2) { | |
712 mov(arg_1, O0); | |
713 mov(arg_2, O1); assert(arg_2 != O0, "smashed argument"); | |
714 call_VM_leaf(thread_cache, entry_point, 2); | |
715 } | |
716 | |
717 | |
718 void MacroAssembler::call_VM_leaf(Register thread_cache, address entry_point, Register arg_1, Register arg_2, Register arg_3) { | |
719 mov(arg_1, O0); | |
720 mov(arg_2, O1); assert(arg_2 != O0, "smashed argument"); | |
721 mov(arg_3, O2); assert(arg_3 != O0 && arg_3 != O1, "smashed argument"); | |
722 call_VM_leaf(thread_cache, entry_point, 3); | |
723 } | |
724 | |
725 | |
726 void MacroAssembler::get_vm_result(Register oop_result) { | |
727 verify_thread(); | |
728 Address vm_result_addr(G2_thread, JavaThread::vm_result_offset()); | |
729 ld_ptr( vm_result_addr, oop_result); | |
730 st_ptr(G0, vm_result_addr); | |
731 verify_oop(oop_result); | |
732 } | |
733 | |
734 | |
735 void MacroAssembler::get_vm_result_2(Register metadata_result) { | |
736 verify_thread(); | |
737 Address vm_result_addr_2(G2_thread, JavaThread::vm_result_2_offset()); | |
738 ld_ptr(vm_result_addr_2, metadata_result); | |
739 st_ptr(G0, vm_result_addr_2); | |
740 } | |
741 | |
742 | |
743 // We require that C code which does not return a value in vm_result will | |
744 // leave it undisturbed. | |
745 void MacroAssembler::set_vm_result(Register oop_result) { | |
746 verify_thread(); | |
747 Address vm_result_addr(G2_thread, JavaThread::vm_result_offset()); | |
748 verify_oop(oop_result); | |
749 | |
750 # ifdef ASSERT | |
751 // Check that we are not overwriting any other oop. | |
752 #ifdef CC_INTERP | |
753 save_frame(0); | |
754 #else | |
755 save_frame_and_mov(0, Lmethod, Lmethod); // Propagate Lmethod for -Xprof | |
756 #endif /* CC_INTERP */ | |
757 ld_ptr(vm_result_addr, L0); | |
758 tst(L0); | |
759 restore(); | |
760 breakpoint_trap(notZero, Assembler::ptr_cc); | |
761 // } | |
762 # endif | |
763 | |
764 st_ptr(oop_result, vm_result_addr); | |
765 } | |
766 | |
767 | |
768 void MacroAssembler::ic_call(address entry, bool emit_delay) { | |
769 RelocationHolder rspec = virtual_call_Relocation::spec(pc()); | |
770 patchable_set((intptr_t)Universe::non_oop_word(), G5_inline_cache_reg); | |
771 relocate(rspec); | |
772 call(entry, relocInfo::none); | |
773 if (emit_delay) { | |
774 delayed()->nop(); | |
775 } | |
776 } | |
777 | |
778 | |
779 void MacroAssembler::card_table_write(jbyte* byte_map_base, | |
780 Register tmp, Register obj) { | |
781 #ifdef _LP64 | |
782 srlx(obj, CardTableModRefBS::card_shift, obj); | |
783 #else | |
784 srl(obj, CardTableModRefBS::card_shift, obj); | |
785 #endif | |
786 assert(tmp != obj, "need separate temp reg"); | |
787 set((address) byte_map_base, tmp); | |
788 stb(G0, tmp, obj); | |
789 } | |
790 | |
791 | |
792 void MacroAssembler::internal_sethi(const AddressLiteral& addrlit, Register d, bool ForceRelocatable) { | |
793 address save_pc; | |
794 int shiftcnt; | |
795 #ifdef _LP64 | |
796 # ifdef CHECK_DELAY | |
797 assert_not_delayed((char*) "cannot put two instructions in delay slot"); | |
798 # endif | |
799 v9_dep(); | |
800 save_pc = pc(); | |
801 | |
802 int msb32 = (int) (addrlit.value() >> 32); | |
803 int lsb32 = (int) (addrlit.value()); | |
804 | |
805 if (msb32 == 0 && lsb32 >= 0) { | |
806 Assembler::sethi(lsb32, d, addrlit.rspec()); | |
807 } | |
808 else if (msb32 == -1) { | |
809 Assembler::sethi(~lsb32, d, addrlit.rspec()); | |
810 xor3(d, ~low10(~0), d); | |
811 } | |
812 else { | |
813 Assembler::sethi(msb32, d, addrlit.rspec()); // msb 22-bits | |
814 if (msb32 & 0x3ff) // Any bits? | |
815 or3(d, msb32 & 0x3ff, d); // msb 32-bits are now in lsb 32 | |
816 if (lsb32 & 0xFFFFFC00) { // done? | |
817 if ((lsb32 >> 20) & 0xfff) { // Any bits set? | |
818 sllx(d, 12, d); // Make room for next 12 bits | |
819 or3(d, (lsb32 >> 20) & 0xfff, d); // Or in next 12 | |
820 shiftcnt = 0; // We already shifted | |
821 } | |
822 else | |
823 shiftcnt = 12; | |
824 if ((lsb32 >> 10) & 0x3ff) { | |
825 sllx(d, shiftcnt + 10, d); // Make room for last 10 bits | |
826 or3(d, (lsb32 >> 10) & 0x3ff, d); // Or in next 10 | |
827 shiftcnt = 0; | |
828 } | |
829 else | |
830 shiftcnt = 10; | |
831 sllx(d, shiftcnt + 10, d); // Shift leaving disp field 0'd | |
832 } | |
833 else | |
834 sllx(d, 32, d); | |
835 } | |
836 // Pad out the instruction sequence so it can be patched later. | |
837 if (ForceRelocatable || (addrlit.rtype() != relocInfo::none && | |
838 addrlit.rtype() != relocInfo::runtime_call_type)) { | |
839 while (pc() < (save_pc + (7 * BytesPerInstWord))) | |
840 nop(); | |
841 } | |
842 #else | |
843 Assembler::sethi(addrlit.value(), d, addrlit.rspec()); | |
844 #endif | |
845 } | |
846 | |
847 | |
848 void MacroAssembler::sethi(const AddressLiteral& addrlit, Register d) { | |
849 internal_sethi(addrlit, d, false); | |
850 } | |
851 | |
852 | |
853 void MacroAssembler::patchable_sethi(const AddressLiteral& addrlit, Register d) { | |
854 internal_sethi(addrlit, d, true); | |
855 } | |
856 | |
857 | |
858 int MacroAssembler::insts_for_sethi(address a, bool worst_case) { | |
859 #ifdef _LP64 | |
860 if (worst_case) return 7; | |
861 intptr_t iaddr = (intptr_t) a; | |
862 int msb32 = (int) (iaddr >> 32); | |
863 int lsb32 = (int) (iaddr); | |
864 int count; | |
865 if (msb32 == 0 && lsb32 >= 0) | |
866 count = 1; | |
867 else if (msb32 == -1) | |
868 count = 2; | |
869 else { | |
870 count = 2; | |
871 if (msb32 & 0x3ff) | |
872 count++; | |
873 if (lsb32 & 0xFFFFFC00 ) { | |
874 if ((lsb32 >> 20) & 0xfff) count += 2; | |
875 if ((lsb32 >> 10) & 0x3ff) count += 2; | |
876 } | |
877 } | |
878 return count; | |
879 #else | |
880 return 1; | |
881 #endif | |
882 } | |
883 | |
884 int MacroAssembler::worst_case_insts_for_set() { | |
885 return insts_for_sethi(NULL, true) + 1; | |
886 } | |
887 | |
888 | |
889 // Keep in sync with MacroAssembler::insts_for_internal_set | |
890 void MacroAssembler::internal_set(const AddressLiteral& addrlit, Register d, bool ForceRelocatable) { | |
891 intptr_t value = addrlit.value(); | |
892 | |
893 if (!ForceRelocatable && addrlit.rspec().type() == relocInfo::none) { | |
894 // can optimize | |
895 if (-4096 <= value && value <= 4095) { | |
896 or3(G0, value, d); // setsw (this leaves upper 32 bits sign-extended) | |
897 return; | |
898 } | |
899 if (inv_hi22(hi22(value)) == value) { | |
900 sethi(addrlit, d); | |
901 return; | |
902 } | |
903 } | |
904 assert_not_delayed((char*) "cannot put two instructions in delay slot"); | |
905 internal_sethi(addrlit, d, ForceRelocatable); | |
906 if (ForceRelocatable || addrlit.rspec().type() != relocInfo::none || addrlit.low10() != 0) { | |
907 add(d, addrlit.low10(), d, addrlit.rspec()); | |
908 } | |
909 } | |
910 | |
911 // Keep in sync with MacroAssembler::internal_set | |
912 int MacroAssembler::insts_for_internal_set(intptr_t value) { | |
913 // can optimize | |
914 if (-4096 <= value && value <= 4095) { | |
915 return 1; | |
916 } | |
917 if (inv_hi22(hi22(value)) == value) { | |
918 return insts_for_sethi((address) value); | |
919 } | |
920 int count = insts_for_sethi((address) value); | |
921 AddressLiteral al(value); | |
922 if (al.low10() != 0) { | |
923 count++; | |
924 } | |
925 return count; | |
926 } | |
927 | |
928 void MacroAssembler::set(const AddressLiteral& al, Register d) { | |
929 internal_set(al, d, false); | |
930 } | |
931 | |
932 void MacroAssembler::set(intptr_t value, Register d) { | |
933 AddressLiteral al(value); | |
934 internal_set(al, d, false); | |
935 } | |
936 | |
937 void MacroAssembler::set(address addr, Register d, RelocationHolder const& rspec) { | |
938 AddressLiteral al(addr, rspec); | |
939 internal_set(al, d, false); | |
940 } | |
941 | |
942 void MacroAssembler::patchable_set(const AddressLiteral& al, Register d) { | |
943 internal_set(al, d, true); | |
944 } | |
945 | |
946 void MacroAssembler::patchable_set(intptr_t value, Register d) { | |
947 AddressLiteral al(value); | |
948 internal_set(al, d, true); | |
949 } | |
950 | |
951 | |
952 void MacroAssembler::set64(jlong value, Register d, Register tmp) { | |
953 assert_not_delayed(); | |
954 v9_dep(); | |
955 | |
956 int hi = (int)(value >> 32); | |
957 int lo = (int)(value & ~0); | |
958 // (Matcher::isSimpleConstant64 knows about the following optimizations.) | |
959 if (Assembler::is_simm13(lo) && value == lo) { | |
960 or3(G0, lo, d); | |
961 } else if (hi == 0) { | |
962 Assembler::sethi(lo, d); // hardware version zero-extends to upper 32 | |
963 if (low10(lo) != 0) | |
964 or3(d, low10(lo), d); | |
965 } | |
966 else if (hi == -1) { | |
967 Assembler::sethi(~lo, d); // hardware version zero-extends to upper 32 | |
968 xor3(d, low10(lo) ^ ~low10(~0), d); | |
969 } | |
970 else if (lo == 0) { | |
971 if (Assembler::is_simm13(hi)) { | |
972 or3(G0, hi, d); | |
973 } else { | |
974 Assembler::sethi(hi, d); // hardware version zero-extends to upper 32 | |
975 if (low10(hi) != 0) | |
976 or3(d, low10(hi), d); | |
977 } | |
978 sllx(d, 32, d); | |
979 } | |
980 else { | |
981 Assembler::sethi(hi, tmp); | |
982 Assembler::sethi(lo, d); // macro assembler version sign-extends | |
983 if (low10(hi) != 0) | |
984 or3 (tmp, low10(hi), tmp); | |
985 if (low10(lo) != 0) | |
986 or3 ( d, low10(lo), d); | |
987 sllx(tmp, 32, tmp); | |
988 or3 (d, tmp, d); | |
989 } | |
990 } | |
991 | |
992 int MacroAssembler::insts_for_set64(jlong value) { | |
993 v9_dep(); | |
994 | |
995 int hi = (int) (value >> 32); | |
996 int lo = (int) (value & ~0); | |
997 int count = 0; | |
998 | |
999 // (Matcher::isSimpleConstant64 knows about the following optimizations.) | |
1000 if (Assembler::is_simm13(lo) && value == lo) { | |
1001 count++; | |
1002 } else if (hi == 0) { | |
1003 count++; | |
1004 if (low10(lo) != 0) | |
1005 count++; | |
1006 } | |
1007 else if (hi == -1) { | |
1008 count += 2; | |
1009 } | |
1010 else if (lo == 0) { | |
1011 if (Assembler::is_simm13(hi)) { | |
1012 count++; | |
1013 } else { | |
1014 count++; | |
1015 if (low10(hi) != 0) | |
1016 count++; | |
1017 } | |
1018 count++; | |
1019 } | |
1020 else { | |
1021 count += 2; | |
1022 if (low10(hi) != 0) | |
1023 count++; | |
1024 if (low10(lo) != 0) | |
1025 count++; | |
1026 count += 2; | |
1027 } | |
1028 return count; | |
1029 } | |
1030 | |
1031 // compute size in bytes of sparc frame, given | |
1032 // number of extraWords | |
1033 int MacroAssembler::total_frame_size_in_bytes(int extraWords) { | |
1034 | |
1035 int nWords = frame::memory_parameter_word_sp_offset; | |
1036 | |
1037 nWords += extraWords; | |
1038 | |
1039 if (nWords & 1) ++nWords; // round up to double-word | |
1040 | |
1041 return nWords * BytesPerWord; | |
1042 } | |
1043 | |
1044 | |
1045 // save_frame: given number of "extra" words in frame, | |
1046 // issue approp. save instruction (p 200, v8 manual) | |
1047 | |
1048 void MacroAssembler::save_frame(int extraWords) { | |
1049 int delta = -total_frame_size_in_bytes(extraWords); | |
1050 if (is_simm13(delta)) { | |
1051 save(SP, delta, SP); | |
1052 } else { | |
1053 set(delta, G3_scratch); | |
1054 save(SP, G3_scratch, SP); | |
1055 } | |
1056 } | |
1057 | |
1058 | |
1059 void MacroAssembler::save_frame_c1(int size_in_bytes) { | |
1060 if (is_simm13(-size_in_bytes)) { | |
1061 save(SP, -size_in_bytes, SP); | |
1062 } else { | |
1063 set(-size_in_bytes, G3_scratch); | |
1064 save(SP, G3_scratch, SP); | |
1065 } | |
1066 } | |
1067 | |
1068 | |
1069 void MacroAssembler::save_frame_and_mov(int extraWords, | |
1070 Register s1, Register d1, | |
1071 Register s2, Register d2) { | |
1072 assert_not_delayed(); | |
1073 | |
1074 // The trick here is to use precisely the same memory word | |
1075 // that trap handlers also use to save the register. | |
1076 // This word cannot be used for any other purpose, but | |
1077 // it works fine to save the register's value, whether or not | |
1078 // an interrupt flushes register windows at any given moment! | |
1079 Address s1_addr; | |
1080 if (s1->is_valid() && (s1->is_in() || s1->is_local())) { | |
1081 s1_addr = s1->address_in_saved_window(); | |
1082 st_ptr(s1, s1_addr); | |
1083 } | |
1084 | |
1085 Address s2_addr; | |
1086 if (s2->is_valid() && (s2->is_in() || s2->is_local())) { | |
1087 s2_addr = s2->address_in_saved_window(); | |
1088 st_ptr(s2, s2_addr); | |
1089 } | |
1090 | |
1091 save_frame(extraWords); | |
1092 | |
1093 if (s1_addr.base() == SP) { | |
1094 ld_ptr(s1_addr.after_save(), d1); | |
1095 } else if (s1->is_valid()) { | |
1096 mov(s1->after_save(), d1); | |
1097 } | |
1098 | |
1099 if (s2_addr.base() == SP) { | |
1100 ld_ptr(s2_addr.after_save(), d2); | |
1101 } else if (s2->is_valid()) { | |
1102 mov(s2->after_save(), d2); | |
1103 } | |
1104 } | |
1105 | |
1106 | |
1107 AddressLiteral MacroAssembler::allocate_metadata_address(Metadata* obj) { | |
1108 assert(oop_recorder() != NULL, "this assembler needs a Recorder"); | |
1109 int index = oop_recorder()->allocate_metadata_index(obj); | |
1110 RelocationHolder rspec = metadata_Relocation::spec(index); | |
1111 return AddressLiteral((address)obj, rspec); | |
1112 } | |
1113 | |
1114 AddressLiteral MacroAssembler::constant_metadata_address(Metadata* obj) { | |
1115 assert(oop_recorder() != NULL, "this assembler needs a Recorder"); | |
1116 int index = oop_recorder()->find_index(obj); | |
1117 RelocationHolder rspec = metadata_Relocation::spec(index); | |
1118 return AddressLiteral((address)obj, rspec); | |
1119 } | |
1120 | |
1121 | |
1122 AddressLiteral MacroAssembler::constant_oop_address(jobject obj) { | |
1123 assert(oop_recorder() != NULL, "this assembler needs an OopRecorder"); | |
1124 assert(Universe::heap()->is_in_reserved(JNIHandles::resolve(obj)), "not an oop"); | |
1125 int oop_index = oop_recorder()->find_index(obj); | |
1126 return AddressLiteral(obj, oop_Relocation::spec(oop_index)); | |
1127 } | |
1128 | |
1129 void MacroAssembler::set_narrow_oop(jobject obj, Register d) { | |
1130 assert(oop_recorder() != NULL, "this assembler needs an OopRecorder"); | |
1131 int oop_index = oop_recorder()->find_index(obj); | |
1132 RelocationHolder rspec = oop_Relocation::spec(oop_index); | |
1133 | |
1134 assert_not_delayed(); | |
1135 // Relocation with special format (see relocInfo_sparc.hpp). | |
1136 relocate(rspec, 1); | |
1137 // Assembler::sethi(0x3fffff, d); | |
7476
ffa87474d7a4
8004537: replace AbstractAssembler emit_long with emit_int32
twisti
parents:
7420
diff
changeset
|
1138 emit_int32( op(branch_op) | rd(d) | op2(sethi_op2) | hi22(0x3fffff) ); |
7204 | 1139 // Don't add relocation for 'add'. Do patching during 'sethi' processing. |
1140 add(d, 0x3ff, d); | |
1141 | |
1142 } | |
1143 | |
1144 void MacroAssembler::set_narrow_klass(Klass* k, Register d) { | |
1145 assert(oop_recorder() != NULL, "this assembler needs an OopRecorder"); | |
1146 int klass_index = oop_recorder()->find_index(k); | |
1147 RelocationHolder rspec = metadata_Relocation::spec(klass_index); | |
1148 narrowOop encoded_k = oopDesc::encode_klass(k); | |
1149 | |
1150 assert_not_delayed(); | |
1151 // Relocation with special format (see relocInfo_sparc.hpp). | |
1152 relocate(rspec, 1); | |
1153 // Assembler::sethi(encoded_k, d); | |
7476
ffa87474d7a4
8004537: replace AbstractAssembler emit_long with emit_int32
twisti
parents:
7420
diff
changeset
|
1154 emit_int32( op(branch_op) | rd(d) | op2(sethi_op2) | hi22(encoded_k) ); |
7204 | 1155 // Don't add relocation for 'add'. Do patching during 'sethi' processing. |
1156 add(d, low10(encoded_k), d); | |
1157 | |
1158 } | |
1159 | |
1160 void MacroAssembler::align(int modulus) { | |
1161 while (offset() % modulus != 0) nop(); | |
1162 } | |
1163 | |
1164 | |
1165 void MacroAssembler::safepoint() { | |
1166 relocate(breakpoint_Relocation::spec(breakpoint_Relocation::safepoint)); | |
1167 } | |
1168 | |
1169 | |
1170 void RegistersForDebugging::print(outputStream* s) { | |
1171 FlagSetting fs(Debugging, true); | |
1172 int j; | |
1173 for (j = 0; j < 8; ++j) { | |
1174 if (j != 6) { s->print("i%d = ", j); os::print_location(s, i[j]); } | |
1175 else { s->print( "fp = " ); os::print_location(s, i[j]); } | |
1176 } | |
1177 s->cr(); | |
1178 | |
1179 for (j = 0; j < 8; ++j) { | |
1180 s->print("l%d = ", j); os::print_location(s, l[j]); | |
1181 } | |
1182 s->cr(); | |
1183 | |
1184 for (j = 0; j < 8; ++j) { | |
1185 if (j != 6) { s->print("o%d = ", j); os::print_location(s, o[j]); } | |
1186 else { s->print( "sp = " ); os::print_location(s, o[j]); } | |
1187 } | |
1188 s->cr(); | |
1189 | |
1190 for (j = 0; j < 8; ++j) { | |
1191 s->print("g%d = ", j); os::print_location(s, g[j]); | |
1192 } | |
1193 s->cr(); | |
1194 | |
1195 // print out floats with compression | |
1196 for (j = 0; j < 32; ) { | |
1197 jfloat val = f[j]; | |
1198 int last = j; | |
1199 for ( ; last+1 < 32; ++last ) { | |
1200 char b1[1024], b2[1024]; | |
1201 sprintf(b1, "%f", val); | |
1202 sprintf(b2, "%f", f[last+1]); | |
1203 if (strcmp(b1, b2)) | |
1204 break; | |
1205 } | |
1206 s->print("f%d", j); | |
1207 if ( j != last ) s->print(" - f%d", last); | |
1208 s->print(" = %f", val); | |
1209 s->fill_to(25); | |
1210 s->print_cr(" (0x%x)", val); | |
1211 j = last + 1; | |
1212 } | |
1213 s->cr(); | |
1214 | |
1215 // and doubles (evens only) | |
1216 for (j = 0; j < 32; ) { | |
1217 jdouble val = d[j]; | |
1218 int last = j; | |
1219 for ( ; last+1 < 32; ++last ) { | |
1220 char b1[1024], b2[1024]; | |
1221 sprintf(b1, "%f", val); | |
1222 sprintf(b2, "%f", d[last+1]); | |
1223 if (strcmp(b1, b2)) | |
1224 break; | |
1225 } | |
1226 s->print("d%d", 2 * j); | |
1227 if ( j != last ) s->print(" - d%d", last); | |
1228 s->print(" = %f", val); | |
1229 s->fill_to(30); | |
1230 s->print("(0x%x)", *(int*)&val); | |
1231 s->fill_to(42); | |
1232 s->print_cr("(0x%x)", *(1 + (int*)&val)); | |
1233 j = last + 1; | |
1234 } | |
1235 s->cr(); | |
1236 } | |
1237 | |
1238 void RegistersForDebugging::save_registers(MacroAssembler* a) { | |
1239 a->sub(FP, round_to(sizeof(RegistersForDebugging), sizeof(jdouble)) - STACK_BIAS, O0); | |
10997 | 1240 a->flushw(); |
7204 | 1241 int i; |
1242 for (i = 0; i < 8; ++i) { | |
1243 a->ld_ptr(as_iRegister(i)->address_in_saved_window().after_save(), L1); a->st_ptr( L1, O0, i_offset(i)); | |
1244 a->ld_ptr(as_lRegister(i)->address_in_saved_window().after_save(), L1); a->st_ptr( L1, O0, l_offset(i)); | |
1245 a->st_ptr(as_oRegister(i)->after_save(), O0, o_offset(i)); | |
1246 a->st_ptr(as_gRegister(i)->after_save(), O0, g_offset(i)); | |
1247 } | |
1248 for (i = 0; i < 32; ++i) { | |
1249 a->stf(FloatRegisterImpl::S, as_FloatRegister(i), O0, f_offset(i)); | |
1250 } | |
10997 | 1251 for (i = 0; i < 64; i += 2) { |
7204 | 1252 a->stf(FloatRegisterImpl::D, as_FloatRegister(i), O0, d_offset(i)); |
1253 } | |
1254 } | |
1255 | |
1256 void RegistersForDebugging::restore_registers(MacroAssembler* a, Register r) { | |
1257 for (int i = 1; i < 8; ++i) { | |
1258 a->ld_ptr(r, g_offset(i), as_gRegister(i)); | |
1259 } | |
1260 for (int j = 0; j < 32; ++j) { | |
1261 a->ldf(FloatRegisterImpl::S, O0, f_offset(j), as_FloatRegister(j)); | |
1262 } | |
10997 | 1263 for (int k = 0; k < 64; k += 2) { |
7204 | 1264 a->ldf(FloatRegisterImpl::D, O0, d_offset(k), as_FloatRegister(k)); |
1265 } | |
1266 } | |
1267 | |
1268 | |
1269 // pushes double TOS element of FPU stack on CPU stack; pops from FPU stack | |
1270 void MacroAssembler::push_fTOS() { | |
1271 // %%%%%% need to implement this | |
1272 } | |
1273 | |
1274 // pops double TOS element from CPU stack and pushes on FPU stack | |
1275 void MacroAssembler::pop_fTOS() { | |
1276 // %%%%%% need to implement this | |
1277 } | |
1278 | |
1279 void MacroAssembler::empty_FPU_stack() { | |
1280 // %%%%%% need to implement this | |
1281 } | |
1282 | |
1283 void MacroAssembler::_verify_oop(Register reg, const char* msg, const char * file, int line) { | |
1284 // plausibility check for oops | |
1285 if (!VerifyOops) return; | |
1286 | |
1287 if (reg == G0) return; // always NULL, which is always an oop | |
1288 | |
1289 BLOCK_COMMENT("verify_oop {"); | |
1290 char buffer[64]; | |
1291 #ifdef COMPILER1 | |
1292 if (CommentedAssembly) { | |
1293 snprintf(buffer, sizeof(buffer), "verify_oop at %d", offset()); | |
1294 block_comment(buffer); | |
1295 } | |
1296 #endif | |
1297 | |
8767
a5de0cc2f91c
8008555: Debugging code in compiled method sometimes leaks memory
roland
parents:
8001
diff
changeset
|
1298 const char* real_msg = NULL; |
a5de0cc2f91c
8008555: Debugging code in compiled method sometimes leaks memory
roland
parents:
8001
diff
changeset
|
1299 { |
a5de0cc2f91c
8008555: Debugging code in compiled method sometimes leaks memory
roland
parents:
8001
diff
changeset
|
1300 ResourceMark rm; |
a5de0cc2f91c
8008555: Debugging code in compiled method sometimes leaks memory
roland
parents:
8001
diff
changeset
|
1301 stringStream ss; |
a5de0cc2f91c
8008555: Debugging code in compiled method sometimes leaks memory
roland
parents:
8001
diff
changeset
|
1302 ss.print("%s at offset %d (%s:%d)", msg, offset(), file, line); |
a5de0cc2f91c
8008555: Debugging code in compiled method sometimes leaks memory
roland
parents:
8001
diff
changeset
|
1303 real_msg = code_string(ss.as_string()); |
a5de0cc2f91c
8008555: Debugging code in compiled method sometimes leaks memory
roland
parents:
8001
diff
changeset
|
1304 } |
7204 | 1305 |
1306 // Call indirectly to solve generation ordering problem | |
1307 AddressLiteral a(StubRoutines::verify_oop_subroutine_entry_address()); | |
1308 | |
1309 // Make some space on stack above the current register window. | |
1310 // Enough to hold 8 64-bit registers. | |
1311 add(SP,-8*8,SP); | |
1312 | |
1313 // Save some 64-bit registers; a normal 'save' chops the heads off | |
1314 // of 64-bit longs in the 32-bit build. | |
1315 stx(O0,SP,frame::register_save_words*wordSize+STACK_BIAS+0*8); | |
1316 stx(O1,SP,frame::register_save_words*wordSize+STACK_BIAS+1*8); | |
1317 mov(reg,O0); // Move arg into O0; arg might be in O7 which is about to be crushed | |
1318 stx(O7,SP,frame::register_save_words*wordSize+STACK_BIAS+7*8); | |
1319 | |
1320 // Size of set() should stay the same | |
1321 patchable_set((intptr_t)real_msg, O1); | |
1322 // Load address to call to into O7 | |
1323 load_ptr_contents(a, O7); | |
1324 // Register call to verify_oop_subroutine | |
1325 callr(O7, G0); | |
1326 delayed()->nop(); | |
1327 // recover frame size | |
1328 add(SP, 8*8,SP); | |
1329 BLOCK_COMMENT("} verify_oop"); | |
1330 } | |
1331 | |
1332 void MacroAssembler::_verify_oop_addr(Address addr, const char* msg, const char * file, int line) { | |
1333 // plausibility check for oops | |
1334 if (!VerifyOops) return; | |
1335 | |
8767
a5de0cc2f91c
8008555: Debugging code in compiled method sometimes leaks memory
roland
parents:
8001
diff
changeset
|
1336 const char* real_msg = NULL; |
a5de0cc2f91c
8008555: Debugging code in compiled method sometimes leaks memory
roland
parents:
8001
diff
changeset
|
1337 { |
a5de0cc2f91c
8008555: Debugging code in compiled method sometimes leaks memory
roland
parents:
8001
diff
changeset
|
1338 ResourceMark rm; |
a5de0cc2f91c
8008555: Debugging code in compiled method sometimes leaks memory
roland
parents:
8001
diff
changeset
|
1339 stringStream ss; |
a5de0cc2f91c
8008555: Debugging code in compiled method sometimes leaks memory
roland
parents:
8001
diff
changeset
|
1340 ss.print("%s at SP+%d (%s:%d)", msg, addr.disp(), file, line); |
a5de0cc2f91c
8008555: Debugging code in compiled method sometimes leaks memory
roland
parents:
8001
diff
changeset
|
1341 real_msg = code_string(ss.as_string()); |
a5de0cc2f91c
8008555: Debugging code in compiled method sometimes leaks memory
roland
parents:
8001
diff
changeset
|
1342 } |
7204 | 1343 |
1344 // Call indirectly to solve generation ordering problem | |
1345 AddressLiteral a(StubRoutines::verify_oop_subroutine_entry_address()); | |
1346 | |
1347 // Make some space on stack above the current register window. | |
1348 // Enough to hold 8 64-bit registers. | |
1349 add(SP,-8*8,SP); | |
1350 | |
1351 // Save some 64-bit registers; a normal 'save' chops the heads off | |
1352 // of 64-bit longs in the 32-bit build. | |
1353 stx(O0,SP,frame::register_save_words*wordSize+STACK_BIAS+0*8); | |
1354 stx(O1,SP,frame::register_save_words*wordSize+STACK_BIAS+1*8); | |
1355 ld_ptr(addr.base(), addr.disp() + 8*8, O0); // Load arg into O0; arg might be in O7 which is about to be crushed | |
1356 stx(O7,SP,frame::register_save_words*wordSize+STACK_BIAS+7*8); | |
1357 | |
1358 // Size of set() should stay the same | |
1359 patchable_set((intptr_t)real_msg, O1); | |
1360 // Load address to call to into O7 | |
1361 load_ptr_contents(a, O7); | |
1362 // Register call to verify_oop_subroutine | |
1363 callr(O7, G0); | |
1364 delayed()->nop(); | |
1365 // recover frame size | |
1366 add(SP, 8*8,SP); | |
1367 } | |
1368 | |
1369 // side-door communication with signalHandler in os_solaris.cpp | |
1370 address MacroAssembler::_verify_oop_implicit_branch[3] = { NULL }; | |
1371 | |
1372 // This macro is expanded just once; it creates shared code. Contract: | |
1373 // receives an oop in O0. Must restore O0 & O7 from TLS. Must not smash ANY | |
1374 // registers, including flags. May not use a register 'save', as this blows | |
1375 // the high bits of the O-regs if they contain Long values. Acts as a 'leaf' | |
1376 // call. | |
1377 void MacroAssembler::verify_oop_subroutine() { | |
1378 // Leaf call; no frame. | |
1379 Label succeed, fail, null_or_fail; | |
1380 | |
1381 // O0 and O7 were saved already (O0 in O0's TLS home, O7 in O5's TLS home). | |
1382 // O0 is now the oop to be checked. O7 is the return address. | |
1383 Register O0_obj = O0; | |
1384 | |
1385 // Save some more registers for temps. | |
1386 stx(O2,SP,frame::register_save_words*wordSize+STACK_BIAS+2*8); | |
1387 stx(O3,SP,frame::register_save_words*wordSize+STACK_BIAS+3*8); | |
1388 stx(O4,SP,frame::register_save_words*wordSize+STACK_BIAS+4*8); | |
1389 stx(O5,SP,frame::register_save_words*wordSize+STACK_BIAS+5*8); | |
1390 | |
1391 // Save flags | |
1392 Register O5_save_flags = O5; | |
1393 rdccr( O5_save_flags ); | |
1394 | |
1395 { // count number of verifies | |
1396 Register O2_adr = O2; | |
1397 Register O3_accum = O3; | |
1398 inc_counter(StubRoutines::verify_oop_count_addr(), O2_adr, O3_accum); | |
1399 } | |
1400 | |
1401 Register O2_mask = O2; | |
1402 Register O3_bits = O3; | |
1403 Register O4_temp = O4; | |
1404 | |
1405 // mark lower end of faulting range | |
1406 assert(_verify_oop_implicit_branch[0] == NULL, "set once"); | |
1407 _verify_oop_implicit_branch[0] = pc(); | |
1408 | |
1409 // We can't check the mark oop because it could be in the process of | |
1410 // locking or unlocking while this is running. | |
1411 set(Universe::verify_oop_mask (), O2_mask); | |
1412 set(Universe::verify_oop_bits (), O3_bits); | |
1413 | |
1414 // assert((obj & oop_mask) == oop_bits); | |
1415 and3(O0_obj, O2_mask, O4_temp); | |
1416 cmp_and_brx_short(O4_temp, O3_bits, notEqual, pn, null_or_fail); | |
1417 | |
1418 if ((NULL_WORD & Universe::verify_oop_mask()) == Universe::verify_oop_bits()) { | |
1419 // the null_or_fail case is useless; must test for null separately | |
1420 br_null_short(O0_obj, pn, succeed); | |
1421 } | |
1422 | |
1423 // Check the Klass* of this object for being in the right area of memory. | |
1424 // Cannot do the load in the delay above slot in case O0 is null | |
1425 load_klass(O0_obj, O0_obj); | |
1426 // assert((klass != NULL) | |
1427 br_null_short(O0_obj, pn, fail); | |
1428 // TODO: Future assert that klass is lower 4g memory for UseCompressedKlassPointers | |
1429 | |
1430 wrccr( O5_save_flags ); // Restore CCR's | |
1431 | |
1432 // mark upper end of faulting range | |
1433 _verify_oop_implicit_branch[1] = pc(); | |
1434 | |
1435 //----------------------- | |
1436 // all tests pass | |
1437 bind(succeed); | |
1438 | |
1439 // Restore prior 64-bit registers | |
1440 ldx(SP,frame::register_save_words*wordSize+STACK_BIAS+0*8,O0); | |
1441 ldx(SP,frame::register_save_words*wordSize+STACK_BIAS+1*8,O1); | |
1442 ldx(SP,frame::register_save_words*wordSize+STACK_BIAS+2*8,O2); | |
1443 ldx(SP,frame::register_save_words*wordSize+STACK_BIAS+3*8,O3); | |
1444 ldx(SP,frame::register_save_words*wordSize+STACK_BIAS+4*8,O4); | |
1445 ldx(SP,frame::register_save_words*wordSize+STACK_BIAS+5*8,O5); | |
1446 | |
1447 retl(); // Leaf return; restore prior O7 in delay slot | |
1448 delayed()->ldx(SP,frame::register_save_words*wordSize+STACK_BIAS+7*8,O7); | |
1449 | |
1450 //----------------------- | |
1451 bind(null_or_fail); // nulls are less common but OK | |
1452 br_null(O0_obj, false, pt, succeed); | |
1453 delayed()->wrccr( O5_save_flags ); // Restore CCR's | |
1454 | |
1455 //----------------------- | |
1456 // report failure: | |
1457 bind(fail); | |
1458 _verify_oop_implicit_branch[2] = pc(); | |
1459 | |
1460 wrccr( O5_save_flags ); // Restore CCR's | |
1461 | |
1462 save_frame(::round_to(sizeof(RegistersForDebugging) / BytesPerWord, 2)); | |
1463 | |
1464 // stop_subroutine expects message pointer in I1. | |
1465 mov(I1, O1); | |
1466 | |
1467 // Restore prior 64-bit registers | |
1468 ldx(FP,frame::register_save_words*wordSize+STACK_BIAS+0*8,I0); | |
1469 ldx(FP,frame::register_save_words*wordSize+STACK_BIAS+1*8,I1); | |
1470 ldx(FP,frame::register_save_words*wordSize+STACK_BIAS+2*8,I2); | |
1471 ldx(FP,frame::register_save_words*wordSize+STACK_BIAS+3*8,I3); | |
1472 ldx(FP,frame::register_save_words*wordSize+STACK_BIAS+4*8,I4); | |
1473 ldx(FP,frame::register_save_words*wordSize+STACK_BIAS+5*8,I5); | |
1474 | |
1475 // factor long stop-sequence into subroutine to save space | |
1476 assert(StubRoutines::Sparc::stop_subroutine_entry_address(), "hasn't been generated yet"); | |
1477 | |
1478 // call indirectly to solve generation ordering problem | |
1479 AddressLiteral al(StubRoutines::Sparc::stop_subroutine_entry_address()); | |
1480 load_ptr_contents(al, O5); | |
1481 jmpl(O5, 0, O7); | |
1482 delayed()->nop(); | |
1483 } | |
1484 | |
1485 | |
1486 void MacroAssembler::stop(const char* msg) { | |
1487 // save frame first to get O7 for return address | |
1488 // add one word to size in case struct is odd number of words long | |
1489 // It must be doubleword-aligned for storing doubles into it. | |
1490 | |
1491 save_frame(::round_to(sizeof(RegistersForDebugging) / BytesPerWord, 2)); | |
1492 | |
1493 // stop_subroutine expects message pointer in I1. | |
1494 // Size of set() should stay the same | |
1495 patchable_set((intptr_t)msg, O1); | |
1496 | |
1497 // factor long stop-sequence into subroutine to save space | |
1498 assert(StubRoutines::Sparc::stop_subroutine_entry_address(), "hasn't been generated yet"); | |
1499 | |
1500 // call indirectly to solve generation ordering problem | |
1501 AddressLiteral a(StubRoutines::Sparc::stop_subroutine_entry_address()); | |
1502 load_ptr_contents(a, O5); | |
1503 jmpl(O5, 0, O7); | |
1504 delayed()->nop(); | |
1505 | |
1506 breakpoint_trap(); // make stop actually stop rather than writing | |
1507 // unnoticeable results in the output files. | |
1508 | |
1509 // restore(); done in callee to save space! | |
1510 } | |
1511 | |
1512 | |
1513 void MacroAssembler::warn(const char* msg) { | |
1514 save_frame(::round_to(sizeof(RegistersForDebugging) / BytesPerWord, 2)); | |
1515 RegistersForDebugging::save_registers(this); | |
1516 mov(O0, L0); | |
1517 // Size of set() should stay the same | |
1518 patchable_set((intptr_t)msg, O0); | |
1519 call( CAST_FROM_FN_PTR(address, warning) ); | |
1520 delayed()->nop(); | |
1521 // ret(); | |
1522 // delayed()->restore(); | |
1523 RegistersForDebugging::restore_registers(this, L0); | |
1524 restore(); | |
1525 } | |
1526 | |
1527 | |
1528 void MacroAssembler::untested(const char* what) { | |
1529 // We must be able to turn interactive prompting off | |
1530 // in order to run automated test scripts on the VM | |
1531 // Use the flag ShowMessageBoxOnError | |
1532 | |
8767
a5de0cc2f91c
8008555: Debugging code in compiled method sometimes leaks memory
roland
parents:
8001
diff
changeset
|
1533 const char* b = NULL; |
a5de0cc2f91c
8008555: Debugging code in compiled method sometimes leaks memory
roland
parents:
8001
diff
changeset
|
1534 { |
a5de0cc2f91c
8008555: Debugging code in compiled method sometimes leaks memory
roland
parents:
8001
diff
changeset
|
1535 ResourceMark rm; |
a5de0cc2f91c
8008555: Debugging code in compiled method sometimes leaks memory
roland
parents:
8001
diff
changeset
|
1536 stringStream ss; |
a5de0cc2f91c
8008555: Debugging code in compiled method sometimes leaks memory
roland
parents:
8001
diff
changeset
|
1537 ss.print("untested: %s", what); |
a5de0cc2f91c
8008555: Debugging code in compiled method sometimes leaks memory
roland
parents:
8001
diff
changeset
|
1538 b = code_string(ss.as_string()); |
a5de0cc2f91c
8008555: Debugging code in compiled method sometimes leaks memory
roland
parents:
8001
diff
changeset
|
1539 } |
7204 | 1540 if (ShowMessageBoxOnError) { STOP(b); } |
1541 else { warn(b); } | |
1542 } | |
1543 | |
1544 | |
1545 void MacroAssembler::stop_subroutine() { | |
1546 RegistersForDebugging::save_registers(this); | |
1547 | |
1548 // for the sake of the debugger, stick a PC on the current frame | |
1549 // (this assumes that the caller has performed an extra "save") | |
1550 mov(I7, L7); | |
1551 add(O7, -7 * BytesPerInt, I7); | |
1552 | |
1553 save_frame(); // one more save to free up another O7 register | |
1554 mov(I0, O1); // addr of reg save area | |
1555 | |
1556 // We expect pointer to message in I1. Caller must set it up in O1 | |
1557 mov(I1, O0); // get msg | |
1558 call (CAST_FROM_FN_PTR(address, MacroAssembler::debug), relocInfo::runtime_call_type); | |
1559 delayed()->nop(); | |
1560 | |
1561 restore(); | |
1562 | |
1563 RegistersForDebugging::restore_registers(this, O0); | |
1564 | |
1565 save_frame(0); | |
1566 call(CAST_FROM_FN_PTR(address,breakpoint)); | |
1567 delayed()->nop(); | |
1568 restore(); | |
1569 | |
1570 mov(L7, I7); | |
1571 retl(); | |
1572 delayed()->restore(); // see stop above | |
1573 } | |
1574 | |
1575 | |
1576 void MacroAssembler::debug(char* msg, RegistersForDebugging* regs) { | |
1577 if ( ShowMessageBoxOnError ) { | |
1578 JavaThread* thread = JavaThread::current(); | |
1579 JavaThreadState saved_state = thread->thread_state(); | |
1580 thread->set_thread_state(_thread_in_vm); | |
1581 { | |
1582 // In order to get locks work, we need to fake a in_VM state | |
1583 ttyLocker ttyl; | |
1584 ::tty->print_cr("EXECUTION STOPPED: %s\n", msg); | |
1585 if (CountBytecodes || TraceBytecodes || StopInterpreterAt) { | |
1586 BytecodeCounter::print(); | |
1587 } | |
1588 if (os::message_box(msg, "Execution stopped, print registers?")) | |
1589 regs->print(::tty); | |
1590 } | |
1591 BREAKPOINT; | |
1592 ThreadStateTransition::transition(JavaThread::current(), _thread_in_vm, saved_state); | |
1593 } | |
1594 else { | |
1595 ::tty->print_cr("=============== DEBUG MESSAGE: %s ================\n", msg); | |
1596 } | |
1597 assert(false, err_msg("DEBUG MESSAGE: %s", msg)); | |
1598 } | |
1599 | |
1600 | |
1601 void MacroAssembler::calc_mem_param_words(Register Rparam_words, Register Rresult) { | |
1602 subcc( Rparam_words, Argument::n_register_parameters, Rresult); // how many mem words? | |
1603 Label no_extras; | |
1604 br( negative, true, pt, no_extras ); // if neg, clear reg | |
1605 delayed()->set(0, Rresult); // annuled, so only if taken | |
1606 bind( no_extras ); | |
1607 } | |
1608 | |
1609 | |
1610 void MacroAssembler::calc_frame_size(Register Rextra_words, Register Rresult) { | |
1611 #ifdef _LP64 | |
1612 add(Rextra_words, frame::memory_parameter_word_sp_offset, Rresult); | |
1613 #else | |
1614 add(Rextra_words, frame::memory_parameter_word_sp_offset + 1, Rresult); | |
1615 #endif | |
1616 bclr(1, Rresult); | |
1617 sll(Rresult, LogBytesPerWord, Rresult); // Rresult has total frame bytes | |
1618 } | |
1619 | |
1620 | |
1621 void MacroAssembler::calc_frame_size_and_save(Register Rextra_words, Register Rresult) { | |
1622 calc_frame_size(Rextra_words, Rresult); | |
1623 neg(Rresult); | |
1624 save(SP, Rresult, SP); | |
1625 } | |
1626 | |
1627 | |
1628 // --------------------------------------------------------- | |
1629 Assembler::RCondition cond2rcond(Assembler::Condition c) { | |
1630 switch (c) { | |
1631 /*case zero: */ | |
1632 case Assembler::equal: return Assembler::rc_z; | |
1633 case Assembler::lessEqual: return Assembler::rc_lez; | |
1634 case Assembler::less: return Assembler::rc_lz; | |
1635 /*case notZero:*/ | |
1636 case Assembler::notEqual: return Assembler::rc_nz; | |
1637 case Assembler::greater: return Assembler::rc_gz; | |
1638 case Assembler::greaterEqual: return Assembler::rc_gez; | |
1639 } | |
1640 ShouldNotReachHere(); | |
1641 return Assembler::rc_z; | |
1642 } | |
1643 | |
1644 // compares (32 bit) register with zero and branches. NOT FOR USE WITH 64-bit POINTERS | |
1645 void MacroAssembler::cmp_zero_and_br(Condition c, Register s1, Label& L, bool a, Predict p) { | |
1646 tst(s1); | |
1647 br (c, a, p, L); | |
1648 } | |
1649 | |
1650 // Compares a pointer register with zero and branches on null. | |
1651 // Does a test & branch on 32-bit systems and a register-branch on 64-bit. | |
1652 void MacroAssembler::br_null( Register s1, bool a, Predict p, Label& L ) { | |
1653 assert_not_delayed(); | |
1654 #ifdef _LP64 | |
1655 bpr( rc_z, a, p, s1, L ); | |
1656 #else | |
1657 tst(s1); | |
1658 br ( zero, a, p, L ); | |
1659 #endif | |
1660 } | |
1661 | |
1662 void MacroAssembler::br_notnull( Register s1, bool a, Predict p, Label& L ) { | |
1663 assert_not_delayed(); | |
1664 #ifdef _LP64 | |
1665 bpr( rc_nz, a, p, s1, L ); | |
1666 #else | |
1667 tst(s1); | |
1668 br ( notZero, a, p, L ); | |
1669 #endif | |
1670 } | |
1671 | |
1672 // Compare registers and branch with nop in delay slot or cbcond without delay slot. | |
1673 | |
1674 // Compare integer (32 bit) values (icc only). | |
1675 void MacroAssembler::cmp_and_br_short(Register s1, Register s2, Condition c, | |
1676 Predict p, Label& L) { | |
1677 assert_not_delayed(); | |
1678 if (use_cbcond(L)) { | |
1679 Assembler::cbcond(c, icc, s1, s2, L); | |
1680 } else { | |
1681 cmp(s1, s2); | |
1682 br(c, false, p, L); | |
1683 delayed()->nop(); | |
1684 } | |
1685 } | |
1686 | |
1687 // Compare integer (32 bit) values (icc only). | |
1688 void MacroAssembler::cmp_and_br_short(Register s1, int simm13a, Condition c, | |
1689 Predict p, Label& L) { | |
1690 assert_not_delayed(); | |
1691 if (is_simm(simm13a,5) && use_cbcond(L)) { | |
1692 Assembler::cbcond(c, icc, s1, simm13a, L); | |
1693 } else { | |
1694 cmp(s1, simm13a); | |
1695 br(c, false, p, L); | |
1696 delayed()->nop(); | |
1697 } | |
1698 } | |
1699 | |
1700 // Branch that tests xcc in LP64 and icc in !LP64 | |
1701 void MacroAssembler::cmp_and_brx_short(Register s1, Register s2, Condition c, | |
1702 Predict p, Label& L) { | |
1703 assert_not_delayed(); | |
1704 if (use_cbcond(L)) { | |
1705 Assembler::cbcond(c, ptr_cc, s1, s2, L); | |
1706 } else { | |
1707 cmp(s1, s2); | |
1708 brx(c, false, p, L); | |
1709 delayed()->nop(); | |
1710 } | |
1711 } | |
1712 | |
1713 // Branch that tests xcc in LP64 and icc in !LP64 | |
1714 void MacroAssembler::cmp_and_brx_short(Register s1, int simm13a, Condition c, | |
1715 Predict p, Label& L) { | |
1716 assert_not_delayed(); | |
1717 if (is_simm(simm13a,5) && use_cbcond(L)) { | |
1718 Assembler::cbcond(c, ptr_cc, s1, simm13a, L); | |
1719 } else { | |
1720 cmp(s1, simm13a); | |
1721 brx(c, false, p, L); | |
1722 delayed()->nop(); | |
1723 } | |
1724 } | |
1725 | |
1726 // Short branch version for compares a pointer with zero. | |
1727 | |
1728 void MacroAssembler::br_null_short(Register s1, Predict p, Label& L) { | |
1729 assert_not_delayed(); | |
1730 if (use_cbcond(L)) { | |
1731 Assembler::cbcond(zero, ptr_cc, s1, 0, L); | |
1732 return; | |
1733 } | |
1734 br_null(s1, false, p, L); | |
1735 delayed()->nop(); | |
1736 } | |
1737 | |
1738 void MacroAssembler::br_notnull_short(Register s1, Predict p, Label& L) { | |
1739 assert_not_delayed(); | |
1740 if (use_cbcond(L)) { | |
1741 Assembler::cbcond(notZero, ptr_cc, s1, 0, L); | |
1742 return; | |
1743 } | |
1744 br_notnull(s1, false, p, L); | |
1745 delayed()->nop(); | |
1746 } | |
1747 | |
1748 // Unconditional short branch | |
1749 void MacroAssembler::ba_short(Label& L) { | |
1750 if (use_cbcond(L)) { | |
1751 Assembler::cbcond(equal, icc, G0, G0, L); | |
1752 return; | |
1753 } | |
1754 br(always, false, pt, L); | |
1755 delayed()->nop(); | |
1756 } | |
1757 | |
1758 // instruction sequences factored across compiler & interpreter | |
1759 | |
1760 | |
1761 void MacroAssembler::lcmp( Register Ra_hi, Register Ra_low, | |
1762 Register Rb_hi, Register Rb_low, | |
1763 Register Rresult) { | |
1764 | |
1765 Label check_low_parts, done; | |
1766 | |
1767 cmp(Ra_hi, Rb_hi ); // compare hi parts | |
1768 br(equal, true, pt, check_low_parts); | |
1769 delayed()->cmp(Ra_low, Rb_low); // test low parts | |
1770 | |
1771 // And, with an unsigned comparison, it does not matter if the numbers | |
1772 // are negative or not. | |
1773 // E.g., -2 cmp -1: the low parts are 0xfffffffe and 0xffffffff. | |
1774 // The second one is bigger (unsignedly). | |
1775 | |
1776 // Other notes: The first move in each triplet can be unconditional | |
1777 // (and therefore probably prefetchable). | |
1778 // And the equals case for the high part does not need testing, | |
1779 // since that triplet is reached only after finding the high halves differ. | |
1780 | |
10997 | 1781 mov(-1, Rresult); |
1782 ba(done); | |
1783 delayed()->movcc(greater, false, icc, 1, Rresult); | |
1784 | |
1785 bind(check_low_parts); | |
1786 | |
1787 mov( -1, Rresult); | |
1788 movcc(equal, false, icc, 0, Rresult); | |
1789 movcc(greaterUnsigned, false, icc, 1, Rresult); | |
1790 | |
1791 bind(done); | |
7204 | 1792 } |
1793 | |
1794 void MacroAssembler::lneg( Register Rhi, Register Rlow ) { | |
1795 subcc( G0, Rlow, Rlow ); | |
1796 subc( G0, Rhi, Rhi ); | |
1797 } | |
1798 | |
1799 void MacroAssembler::lshl( Register Rin_high, Register Rin_low, | |
1800 Register Rcount, | |
1801 Register Rout_high, Register Rout_low, | |
1802 Register Rtemp ) { | |
1803 | |
1804 | |
1805 Register Ralt_count = Rtemp; | |
1806 Register Rxfer_bits = Rtemp; | |
1807 | |
1808 assert( Ralt_count != Rin_high | |
1809 && Ralt_count != Rin_low | |
1810 && Ralt_count != Rcount | |
1811 && Rxfer_bits != Rin_low | |
1812 && Rxfer_bits != Rin_high | |
1813 && Rxfer_bits != Rcount | |
1814 && Rxfer_bits != Rout_low | |
1815 && Rout_low != Rin_high, | |
1816 "register alias checks"); | |
1817 | |
1818 Label big_shift, done; | |
1819 | |
1820 // This code can be optimized to use the 64 bit shifts in V9. | |
1821 // Here we use the 32 bit shifts. | |
1822 | |
1823 and3( Rcount, 0x3f, Rcount); // take least significant 6 bits | |
1824 subcc(Rcount, 31, Ralt_count); | |
1825 br(greater, true, pn, big_shift); | |
1826 delayed()->dec(Ralt_count); | |
1827 | |
1828 // shift < 32 bits, Ralt_count = Rcount-31 | |
1829 | |
1830 // We get the transfer bits by shifting right by 32-count the low | |
1831 // register. This is done by shifting right by 31-count and then by one | |
1832 // more to take care of the special (rare) case where count is zero | |
1833 // (shifting by 32 would not work). | |
1834 | |
1835 neg(Ralt_count); | |
1836 | |
1837 // The order of the next two instructions is critical in the case where | |
1838 // Rin and Rout are the same and should not be reversed. | |
1839 | |
1840 srl(Rin_low, Ralt_count, Rxfer_bits); // shift right by 31-count | |
1841 if (Rcount != Rout_low) { | |
1842 sll(Rin_low, Rcount, Rout_low); // low half | |
1843 } | |
1844 sll(Rin_high, Rcount, Rout_high); | |
1845 if (Rcount == Rout_low) { | |
1846 sll(Rin_low, Rcount, Rout_low); // low half | |
1847 } | |
1848 srl(Rxfer_bits, 1, Rxfer_bits ); // shift right by one more | |
1849 ba(done); | |
1850 delayed()->or3(Rout_high, Rxfer_bits, Rout_high); // new hi value: or in shifted old hi part and xfer from low | |
1851 | |
1852 // shift >= 32 bits, Ralt_count = Rcount-32 | |
1853 bind(big_shift); | |
1854 sll(Rin_low, Ralt_count, Rout_high ); | |
1855 clr(Rout_low); | |
1856 | |
1857 bind(done); | |
1858 } | |
1859 | |
1860 | |
1861 void MacroAssembler::lshr( Register Rin_high, Register Rin_low, | |
1862 Register Rcount, | |
1863 Register Rout_high, Register Rout_low, | |
1864 Register Rtemp ) { | |
1865 | |
1866 Register Ralt_count = Rtemp; | |
1867 Register Rxfer_bits = Rtemp; | |
1868 | |
1869 assert( Ralt_count != Rin_high | |
1870 && Ralt_count != Rin_low | |
1871 && Ralt_count != Rcount | |
1872 && Rxfer_bits != Rin_low | |
1873 && Rxfer_bits != Rin_high | |
1874 && Rxfer_bits != Rcount | |
1875 && Rxfer_bits != Rout_high | |
1876 && Rout_high != Rin_low, | |
1877 "register alias checks"); | |
1878 | |
1879 Label big_shift, done; | |
1880 | |
1881 // This code can be optimized to use the 64 bit shifts in V9. | |
1882 // Here we use the 32 bit shifts. | |
1883 | |
1884 and3( Rcount, 0x3f, Rcount); // take least significant 6 bits | |
1885 subcc(Rcount, 31, Ralt_count); | |
1886 br(greater, true, pn, big_shift); | |
1887 delayed()->dec(Ralt_count); | |
1888 | |
1889 // shift < 32 bits, Ralt_count = Rcount-31 | |
1890 | |
1891 // We get the transfer bits by shifting left by 32-count the high | |
1892 // register. This is done by shifting left by 31-count and then by one | |
1893 // more to take care of the special (rare) case where count is zero | |
1894 // (shifting by 32 would not work). | |
1895 | |
1896 neg(Ralt_count); | |
1897 if (Rcount != Rout_low) { | |
1898 srl(Rin_low, Rcount, Rout_low); | |
1899 } | |
1900 | |
1901 // The order of the next two instructions is critical in the case where | |
1902 // Rin and Rout are the same and should not be reversed. | |
1903 | |
1904 sll(Rin_high, Ralt_count, Rxfer_bits); // shift left by 31-count | |
1905 sra(Rin_high, Rcount, Rout_high ); // high half | |
1906 sll(Rxfer_bits, 1, Rxfer_bits); // shift left by one more | |
1907 if (Rcount == Rout_low) { | |
1908 srl(Rin_low, Rcount, Rout_low); | |
1909 } | |
1910 ba(done); | |
1911 delayed()->or3(Rout_low, Rxfer_bits, Rout_low); // new low value: or shifted old low part and xfer from high | |
1912 | |
1913 // shift >= 32 bits, Ralt_count = Rcount-32 | |
1914 bind(big_shift); | |
1915 | |
1916 sra(Rin_high, Ralt_count, Rout_low); | |
1917 sra(Rin_high, 31, Rout_high); // sign into hi | |
1918 | |
1919 bind( done ); | |
1920 } | |
1921 | |
1922 | |
1923 | |
1924 void MacroAssembler::lushr( Register Rin_high, Register Rin_low, | |
1925 Register Rcount, | |
1926 Register Rout_high, Register Rout_low, | |
1927 Register Rtemp ) { | |
1928 | |
1929 Register Ralt_count = Rtemp; | |
1930 Register Rxfer_bits = Rtemp; | |
1931 | |
1932 assert( Ralt_count != Rin_high | |
1933 && Ralt_count != Rin_low | |
1934 && Ralt_count != Rcount | |
1935 && Rxfer_bits != Rin_low | |
1936 && Rxfer_bits != Rin_high | |
1937 && Rxfer_bits != Rcount | |
1938 && Rxfer_bits != Rout_high | |
1939 && Rout_high != Rin_low, | |
1940 "register alias checks"); | |
1941 | |
1942 Label big_shift, done; | |
1943 | |
1944 // This code can be optimized to use the 64 bit shifts in V9. | |
1945 // Here we use the 32 bit shifts. | |
1946 | |
1947 and3( Rcount, 0x3f, Rcount); // take least significant 6 bits | |
1948 subcc(Rcount, 31, Ralt_count); | |
1949 br(greater, true, pn, big_shift); | |
1950 delayed()->dec(Ralt_count); | |
1951 | |
1952 // shift < 32 bits, Ralt_count = Rcount-31 | |
1953 | |
1954 // We get the transfer bits by shifting left by 32-count the high | |
1955 // register. This is done by shifting left by 31-count and then by one | |
1956 // more to take care of the special (rare) case where count is zero | |
1957 // (shifting by 32 would not work). | |
1958 | |
1959 neg(Ralt_count); | |
1960 if (Rcount != Rout_low) { | |
1961 srl(Rin_low, Rcount, Rout_low); | |
1962 } | |
1963 | |
1964 // The order of the next two instructions is critical in the case where | |
1965 // Rin and Rout are the same and should not be reversed. | |
1966 | |
1967 sll(Rin_high, Ralt_count, Rxfer_bits); // shift left by 31-count | |
1968 srl(Rin_high, Rcount, Rout_high ); // high half | |
1969 sll(Rxfer_bits, 1, Rxfer_bits); // shift left by one more | |
1970 if (Rcount == Rout_low) { | |
1971 srl(Rin_low, Rcount, Rout_low); | |
1972 } | |
1973 ba(done); | |
1974 delayed()->or3(Rout_low, Rxfer_bits, Rout_low); // new low value: or shifted old low part and xfer from high | |
1975 | |
1976 // shift >= 32 bits, Ralt_count = Rcount-32 | |
1977 bind(big_shift); | |
1978 | |
1979 srl(Rin_high, Ralt_count, Rout_low); | |
1980 clr(Rout_high); | |
1981 | |
1982 bind( done ); | |
1983 } | |
1984 | |
1985 #ifdef _LP64 | |
1986 void MacroAssembler::lcmp( Register Ra, Register Rb, Register Rresult) { | |
1987 cmp(Ra, Rb); | |
1988 mov(-1, Rresult); | |
1989 movcc(equal, false, xcc, 0, Rresult); | |
1990 movcc(greater, false, xcc, 1, Rresult); | |
1991 } | |
1992 #endif | |
1993 | |
1994 | |
1995 void MacroAssembler::load_sized_value(Address src, Register dst, size_t size_in_bytes, bool is_signed) { | |
1996 switch (size_in_bytes) { | |
1997 case 8: ld_long(src, dst); break; | |
1998 case 4: ld( src, dst); break; | |
1999 case 2: is_signed ? ldsh(src, dst) : lduh(src, dst); break; | |
2000 case 1: is_signed ? ldsb(src, dst) : ldub(src, dst); break; | |
2001 default: ShouldNotReachHere(); | |
2002 } | |
2003 } | |
2004 | |
2005 void MacroAssembler::store_sized_value(Register src, Address dst, size_t size_in_bytes) { | |
2006 switch (size_in_bytes) { | |
2007 case 8: st_long(src, dst); break; | |
2008 case 4: st( src, dst); break; | |
2009 case 2: sth( src, dst); break; | |
2010 case 1: stb( src, dst); break; | |
2011 default: ShouldNotReachHere(); | |
2012 } | |
2013 } | |
2014 | |
2015 | |
2016 void MacroAssembler::float_cmp( bool is_float, int unordered_result, | |
2017 FloatRegister Fa, FloatRegister Fb, | |
2018 Register Rresult) { | |
10997 | 2019 if (is_float) { |
2020 fcmp(FloatRegisterImpl::S, fcc0, Fa, Fb); | |
7204 | 2021 } else { |
10997 | 2022 fcmp(FloatRegisterImpl::D, fcc0, Fa, Fb); |
7204 | 2023 } |
10997 | 2024 |
2025 if (unordered_result == 1) { | |
2026 mov( -1, Rresult); | |
2027 movcc(f_equal, true, fcc0, 0, Rresult); | |
2028 movcc(f_unorderedOrGreater, true, fcc0, 1, Rresult); | |
7204 | 2029 } else { |
10997 | 2030 mov( -1, Rresult); |
2031 movcc(f_equal, true, fcc0, 0, Rresult); | |
2032 movcc(f_greater, true, fcc0, 1, Rresult); | |
7204 | 2033 } |
2034 } | |
2035 | |
2036 | |
2037 void MacroAssembler::save_all_globals_into_locals() { | |
2038 mov(G1,L1); | |
2039 mov(G2,L2); | |
2040 mov(G3,L3); | |
2041 mov(G4,L4); | |
2042 mov(G5,L5); | |
2043 mov(G6,L6); | |
2044 mov(G7,L7); | |
2045 } | |
2046 | |
2047 void MacroAssembler::restore_globals_from_locals() { | |
2048 mov(L1,G1); | |
2049 mov(L2,G2); | |
2050 mov(L3,G3); | |
2051 mov(L4,G4); | |
2052 mov(L5,G5); | |
2053 mov(L6,G6); | |
2054 mov(L7,G7); | |
2055 } | |
2056 | |
2057 RegisterOrConstant MacroAssembler::delayed_value_impl(intptr_t* delayed_value_addr, | |
2058 Register tmp, | |
2059 int offset) { | |
2060 intptr_t value = *delayed_value_addr; | |
2061 if (value != 0) | |
2062 return RegisterOrConstant(value + offset); | |
2063 | |
2064 // load indirectly to solve generation ordering problem | |
2065 AddressLiteral a(delayed_value_addr); | |
2066 load_ptr_contents(a, tmp); | |
2067 | |
2068 #ifdef ASSERT | |
2069 tst(tmp); | |
2070 breakpoint_trap(zero, xcc); | |
2071 #endif | |
2072 | |
2073 if (offset != 0) | |
2074 add(tmp, offset, tmp); | |
2075 | |
2076 return RegisterOrConstant(tmp); | |
2077 } | |
2078 | |
2079 | |
2080 RegisterOrConstant MacroAssembler::regcon_andn_ptr(RegisterOrConstant s1, RegisterOrConstant s2, RegisterOrConstant d, Register temp) { | |
2081 assert(d.register_or_noreg() != G0, "lost side effect"); | |
2082 if ((s2.is_constant() && s2.as_constant() == 0) || | |
2083 (s2.is_register() && s2.as_register() == G0)) { | |
2084 // Do nothing, just move value. | |
2085 if (s1.is_register()) { | |
2086 if (d.is_constant()) d = temp; | |
2087 mov(s1.as_register(), d.as_register()); | |
2088 return d; | |
2089 } else { | |
2090 return s1; | |
2091 } | |
2092 } | |
2093 | |
2094 if (s1.is_register()) { | |
2095 assert_different_registers(s1.as_register(), temp); | |
2096 if (d.is_constant()) d = temp; | |
2097 andn(s1.as_register(), ensure_simm13_or_reg(s2, temp), d.as_register()); | |
2098 return d; | |
2099 } else { | |
2100 if (s2.is_register()) { | |
2101 assert_different_registers(s2.as_register(), temp); | |
2102 if (d.is_constant()) d = temp; | |
2103 set(s1.as_constant(), temp); | |
2104 andn(temp, s2.as_register(), d.as_register()); | |
2105 return d; | |
2106 } else { | |
2107 intptr_t res = s1.as_constant() & ~s2.as_constant(); | |
2108 return res; | |
2109 } | |
2110 } | |
2111 } | |
2112 | |
2113 RegisterOrConstant MacroAssembler::regcon_inc_ptr(RegisterOrConstant s1, RegisterOrConstant s2, RegisterOrConstant d, Register temp) { | |
2114 assert(d.register_or_noreg() != G0, "lost side effect"); | |
2115 if ((s2.is_constant() && s2.as_constant() == 0) || | |
2116 (s2.is_register() && s2.as_register() == G0)) { | |
2117 // Do nothing, just move value. | |
2118 if (s1.is_register()) { | |
2119 if (d.is_constant()) d = temp; | |
2120 mov(s1.as_register(), d.as_register()); | |
2121 return d; | |
2122 } else { | |
2123 return s1; | |
2124 } | |
2125 } | |
2126 | |
2127 if (s1.is_register()) { | |
2128 assert_different_registers(s1.as_register(), temp); | |
2129 if (d.is_constant()) d = temp; | |
2130 add(s1.as_register(), ensure_simm13_or_reg(s2, temp), d.as_register()); | |
2131 return d; | |
2132 } else { | |
2133 if (s2.is_register()) { | |
2134 assert_different_registers(s2.as_register(), temp); | |
2135 if (d.is_constant()) d = temp; | |
2136 add(s2.as_register(), ensure_simm13_or_reg(s1, temp), d.as_register()); | |
2137 return d; | |
2138 } else { | |
2139 intptr_t res = s1.as_constant() + s2.as_constant(); | |
2140 return res; | |
2141 } | |
2142 } | |
2143 } | |
2144 | |
2145 RegisterOrConstant MacroAssembler::regcon_sll_ptr(RegisterOrConstant s1, RegisterOrConstant s2, RegisterOrConstant d, Register temp) { | |
2146 assert(d.register_or_noreg() != G0, "lost side effect"); | |
2147 if (!is_simm13(s2.constant_or_zero())) | |
2148 s2 = (s2.as_constant() & 0xFF); | |
2149 if ((s2.is_constant() && s2.as_constant() == 0) || | |
2150 (s2.is_register() && s2.as_register() == G0)) { | |
2151 // Do nothing, just move value. | |
2152 if (s1.is_register()) { | |
2153 if (d.is_constant()) d = temp; | |
2154 mov(s1.as_register(), d.as_register()); | |
2155 return d; | |
2156 } else { | |
2157 return s1; | |
2158 } | |
2159 } | |
2160 | |
2161 if (s1.is_register()) { | |
2162 assert_different_registers(s1.as_register(), temp); | |
2163 if (d.is_constant()) d = temp; | |
2164 sll_ptr(s1.as_register(), ensure_simm13_or_reg(s2, temp), d.as_register()); | |
2165 return d; | |
2166 } else { | |
2167 if (s2.is_register()) { | |
2168 assert_different_registers(s2.as_register(), temp); | |
2169 if (d.is_constant()) d = temp; | |
2170 set(s1.as_constant(), temp); | |
2171 sll_ptr(temp, s2.as_register(), d.as_register()); | |
2172 return d; | |
2173 } else { | |
2174 intptr_t res = s1.as_constant() << s2.as_constant(); | |
2175 return res; | |
2176 } | |
2177 } | |
2178 } | |
2179 | |
2180 | |
2181 // Look up the method for a megamorphic invokeinterface call. | |
2182 // The target method is determined by <intf_klass, itable_index>. | |
2183 // The receiver klass is in recv_klass. | |
2184 // On success, the result will be in method_result, and execution falls through. | |
2185 // On failure, execution transfers to the given label. | |
2186 void MacroAssembler::lookup_interface_method(Register recv_klass, | |
2187 Register intf_klass, | |
2188 RegisterOrConstant itable_index, | |
2189 Register method_result, | |
2190 Register scan_temp, | |
2191 Register sethi_temp, | |
2192 Label& L_no_such_interface) { | |
2193 assert_different_registers(recv_klass, intf_klass, method_result, scan_temp); | |
2194 assert(itable_index.is_constant() || itable_index.as_register() == method_result, | |
2195 "caller must use same register for non-constant itable index as for method"); | |
2196 | |
2197 Label L_no_such_interface_restore; | |
2198 bool did_save = false; | |
2199 if (scan_temp == noreg || sethi_temp == noreg) { | |
2200 Register recv_2 = recv_klass->is_global() ? recv_klass : L0; | |
2201 Register intf_2 = intf_klass->is_global() ? intf_klass : L1; | |
2202 assert(method_result->is_global(), "must be able to return value"); | |
2203 scan_temp = L2; | |
2204 sethi_temp = L3; | |
2205 save_frame_and_mov(0, recv_klass, recv_2, intf_klass, intf_2); | |
2206 recv_klass = recv_2; | |
2207 intf_klass = intf_2; | |
2208 did_save = true; | |
2209 } | |
2210 | |
2211 // Compute start of first itableOffsetEntry (which is at the end of the vtable) | |
2212 int vtable_base = InstanceKlass::vtable_start_offset() * wordSize; | |
2213 int scan_step = itableOffsetEntry::size() * wordSize; | |
2214 int vte_size = vtableEntry::size() * wordSize; | |
2215 | |
2216 lduw(recv_klass, InstanceKlass::vtable_length_offset() * wordSize, scan_temp); | |
2217 // %%% We should store the aligned, prescaled offset in the klassoop. | |
2218 // Then the next several instructions would fold away. | |
2219 | |
2220 int round_to_unit = ((HeapWordsPerLong > 1) ? BytesPerLong : 0); | |
2221 int itb_offset = vtable_base; | |
2222 if (round_to_unit != 0) { | |
2223 // hoist first instruction of round_to(scan_temp, BytesPerLong): | |
2224 itb_offset += round_to_unit - wordSize; | |
2225 } | |
2226 int itb_scale = exact_log2(vtableEntry::size() * wordSize); | |
2227 sll(scan_temp, itb_scale, scan_temp); | |
2228 add(scan_temp, itb_offset, scan_temp); | |
2229 if (round_to_unit != 0) { | |
2230 // Round up to align_object_offset boundary | |
2231 // see code for InstanceKlass::start_of_itable! | |
2232 // Was: round_to(scan_temp, BytesPerLong); | |
2233 // Hoisted: add(scan_temp, BytesPerLong-1, scan_temp); | |
2234 and3(scan_temp, -round_to_unit, scan_temp); | |
2235 } | |
2236 add(recv_klass, scan_temp, scan_temp); | |
2237 | |
2238 // Adjust recv_klass by scaled itable_index, so we can free itable_index. | |
2239 RegisterOrConstant itable_offset = itable_index; | |
2240 itable_offset = regcon_sll_ptr(itable_index, exact_log2(itableMethodEntry::size() * wordSize), itable_offset); | |
2241 itable_offset = regcon_inc_ptr(itable_offset, itableMethodEntry::method_offset_in_bytes(), itable_offset); | |
2242 add(recv_klass, ensure_simm13_or_reg(itable_offset, sethi_temp), recv_klass); | |
2243 | |
2244 // for (scan = klass->itable(); scan->interface() != NULL; scan += scan_step) { | |
2245 // if (scan->interface() == intf) { | |
2246 // result = (klass + scan->offset() + itable_index); | |
2247 // } | |
2248 // } | |
2249 Label L_search, L_found_method; | |
2250 | |
2251 for (int peel = 1; peel >= 0; peel--) { | |
2252 // %%%% Could load both offset and interface in one ldx, if they were | |
2253 // in the opposite order. This would save a load. | |
2254 ld_ptr(scan_temp, itableOffsetEntry::interface_offset_in_bytes(), method_result); | |
2255 | |
2256 // Check that this entry is non-null. A null entry means that | |
2257 // the receiver class doesn't implement the interface, and wasn't the | |
2258 // same as when the caller was compiled. | |
2259 bpr(Assembler::rc_z, false, Assembler::pn, method_result, did_save ? L_no_such_interface_restore : L_no_such_interface); | |
2260 delayed()->cmp(method_result, intf_klass); | |
2261 | |
2262 if (peel) { | |
2263 brx(Assembler::equal, false, Assembler::pt, L_found_method); | |
2264 } else { | |
2265 brx(Assembler::notEqual, false, Assembler::pn, L_search); | |
2266 // (invert the test to fall through to found_method...) | |
2267 } | |
2268 delayed()->add(scan_temp, scan_step, scan_temp); | |
2269 | |
2270 if (!peel) break; | |
2271 | |
2272 bind(L_search); | |
2273 } | |
2274 | |
2275 bind(L_found_method); | |
2276 | |
2277 // Got a hit. | |
2278 int ito_offset = itableOffsetEntry::offset_offset_in_bytes(); | |
2279 // scan_temp[-scan_step] points to the vtable offset we need | |
2280 ito_offset -= scan_step; | |
2281 lduw(scan_temp, ito_offset, scan_temp); | |
2282 ld_ptr(recv_klass, scan_temp, method_result); | |
2283 | |
2284 if (did_save) { | |
2285 Label L_done; | |
2286 ba(L_done); | |
2287 delayed()->restore(); | |
2288 | |
2289 bind(L_no_such_interface_restore); | |
2290 ba(L_no_such_interface); | |
2291 delayed()->restore(); | |
2292 | |
2293 bind(L_done); | |
2294 } | |
2295 } | |
2296 | |
2297 | |
2298 // virtual method calling | |
2299 void MacroAssembler::lookup_virtual_method(Register recv_klass, | |
2300 RegisterOrConstant vtable_index, | |
2301 Register method_result) { | |
2302 assert_different_registers(recv_klass, method_result, vtable_index.register_or_noreg()); | |
2303 Register sethi_temp = method_result; | |
2304 const int base = (InstanceKlass::vtable_start_offset() * wordSize + | |
2305 // method pointer offset within the vtable entry: | |
2306 vtableEntry::method_offset_in_bytes()); | |
2307 RegisterOrConstant vtable_offset = vtable_index; | |
2308 // Each of the following three lines potentially generates an instruction. | |
2309 // But the total number of address formation instructions will always be | |
2310 // at most two, and will often be zero. In any case, it will be optimal. | |
2311 // If vtable_index is a register, we will have (sll_ptr N,x; inc_ptr B,x; ld_ptr k,x). | |
2312 // If vtable_index is a constant, we will have at most (set B+X<<N,t; ld_ptr k,t). | |
2313 vtable_offset = regcon_sll_ptr(vtable_index, exact_log2(vtableEntry::size() * wordSize), vtable_offset); | |
2314 vtable_offset = regcon_inc_ptr(vtable_offset, base, vtable_offset, sethi_temp); | |
2315 Address vtable_entry_addr(recv_klass, ensure_simm13_or_reg(vtable_offset, sethi_temp)); | |
2316 ld_ptr(vtable_entry_addr, method_result); | |
2317 } | |
2318 | |
2319 | |
2320 void MacroAssembler::check_klass_subtype(Register sub_klass, | |
2321 Register super_klass, | |
2322 Register temp_reg, | |
2323 Register temp2_reg, | |
2324 Label& L_success) { | |
2325 Register sub_2 = sub_klass; | |
2326 Register sup_2 = super_klass; | |
2327 if (!sub_2->is_global()) sub_2 = L0; | |
2328 if (!sup_2->is_global()) sup_2 = L1; | |
2329 bool did_save = false; | |
2330 if (temp_reg == noreg || temp2_reg == noreg) { | |
2331 temp_reg = L2; | |
2332 temp2_reg = L3; | |
2333 save_frame_and_mov(0, sub_klass, sub_2, super_klass, sup_2); | |
2334 sub_klass = sub_2; | |
2335 super_klass = sup_2; | |
2336 did_save = true; | |
2337 } | |
2338 Label L_failure, L_pop_to_failure, L_pop_to_success; | |
2339 check_klass_subtype_fast_path(sub_klass, super_klass, | |
2340 temp_reg, temp2_reg, | |
2341 (did_save ? &L_pop_to_success : &L_success), | |
2342 (did_save ? &L_pop_to_failure : &L_failure), NULL); | |
2343 | |
2344 if (!did_save) | |
2345 save_frame_and_mov(0, sub_klass, sub_2, super_klass, sup_2); | |
2346 check_klass_subtype_slow_path(sub_2, sup_2, | |
2347 L2, L3, L4, L5, | |
2348 NULL, &L_pop_to_failure); | |
2349 | |
2350 // on success: | |
2351 bind(L_pop_to_success); | |
2352 restore(); | |
2353 ba_short(L_success); | |
2354 | |
2355 // on failure: | |
2356 bind(L_pop_to_failure); | |
2357 restore(); | |
2358 bind(L_failure); | |
2359 } | |
2360 | |
2361 | |
2362 void MacroAssembler::check_klass_subtype_fast_path(Register sub_klass, | |
2363 Register super_klass, | |
2364 Register temp_reg, | |
2365 Register temp2_reg, | |
2366 Label* L_success, | |
2367 Label* L_failure, | |
2368 Label* L_slow_path, | |
2369 RegisterOrConstant super_check_offset) { | |
2370 int sc_offset = in_bytes(Klass::secondary_super_cache_offset()); | |
2371 int sco_offset = in_bytes(Klass::super_check_offset_offset()); | |
2372 | |
2373 bool must_load_sco = (super_check_offset.constant_or_zero() == -1); | |
2374 bool need_slow_path = (must_load_sco || | |
2375 super_check_offset.constant_or_zero() == sco_offset); | |
2376 | |
2377 assert_different_registers(sub_klass, super_klass, temp_reg); | |
2378 if (super_check_offset.is_register()) { | |
2379 assert_different_registers(sub_klass, super_klass, temp_reg, | |
2380 super_check_offset.as_register()); | |
2381 } else if (must_load_sco) { | |
2382 assert(temp2_reg != noreg, "supply either a temp or a register offset"); | |
2383 } | |
2384 | |
2385 Label L_fallthrough; | |
2386 int label_nulls = 0; | |
2387 if (L_success == NULL) { L_success = &L_fallthrough; label_nulls++; } | |
2388 if (L_failure == NULL) { L_failure = &L_fallthrough; label_nulls++; } | |
2389 if (L_slow_path == NULL) { L_slow_path = &L_fallthrough; label_nulls++; } | |
2390 assert(label_nulls <= 1 || | |
2391 (L_slow_path == &L_fallthrough && label_nulls <= 2 && !need_slow_path), | |
2392 "at most one NULL in the batch, usually"); | |
2393 | |
2394 // If the pointers are equal, we are done (e.g., String[] elements). | |
2395 // This self-check enables sharing of secondary supertype arrays among | |
2396 // non-primary types such as array-of-interface. Otherwise, each such | |
2397 // type would need its own customized SSA. | |
2398 // We move this check to the front of the fast path because many | |
2399 // type checks are in fact trivially successful in this manner, | |
2400 // so we get a nicely predicted branch right at the start of the check. | |
2401 cmp(super_klass, sub_klass); | |
2402 brx(Assembler::equal, false, Assembler::pn, *L_success); | |
2403 delayed()->nop(); | |
2404 | |
2405 // Check the supertype display: | |
2406 if (must_load_sco) { | |
2407 // The super check offset is always positive... | |
2408 lduw(super_klass, sco_offset, temp2_reg); | |
2409 super_check_offset = RegisterOrConstant(temp2_reg); | |
2410 // super_check_offset is register. | |
2411 assert_different_registers(sub_klass, super_klass, temp_reg, super_check_offset.as_register()); | |
2412 } | |
2413 ld_ptr(sub_klass, super_check_offset, temp_reg); | |
2414 cmp(super_klass, temp_reg); | |
2415 | |
2416 // This check has worked decisively for primary supers. | |
2417 // Secondary supers are sought in the super_cache ('super_cache_addr'). | |
2418 // (Secondary supers are interfaces and very deeply nested subtypes.) | |
2419 // This works in the same check above because of a tricky aliasing | |
2420 // between the super_cache and the primary super display elements. | |
2421 // (The 'super_check_addr' can address either, as the case requires.) | |
2422 // Note that the cache is updated below if it does not help us find | |
2423 // what we need immediately. | |
2424 // So if it was a primary super, we can just fail immediately. | |
2425 // Otherwise, it's the slow path for us (no success at this point). | |
2426 | |
2427 // Hacked ba(), which may only be used just before L_fallthrough. | |
2428 #define FINAL_JUMP(label) \ | |
2429 if (&(label) != &L_fallthrough) { \ | |
2430 ba(label); delayed()->nop(); \ | |
2431 } | |
2432 | |
2433 if (super_check_offset.is_register()) { | |
2434 brx(Assembler::equal, false, Assembler::pn, *L_success); | |
2435 delayed()->cmp(super_check_offset.as_register(), sc_offset); | |
2436 | |
2437 if (L_failure == &L_fallthrough) { | |
2438 brx(Assembler::equal, false, Assembler::pt, *L_slow_path); | |
2439 delayed()->nop(); | |
2440 } else { | |
2441 brx(Assembler::notEqual, false, Assembler::pn, *L_failure); | |
2442 delayed()->nop(); | |
2443 FINAL_JUMP(*L_slow_path); | |
2444 } | |
2445 } else if (super_check_offset.as_constant() == sc_offset) { | |
2446 // Need a slow path; fast failure is impossible. | |
2447 if (L_slow_path == &L_fallthrough) { | |
2448 brx(Assembler::equal, false, Assembler::pt, *L_success); | |
2449 delayed()->nop(); | |
2450 } else { | |
2451 brx(Assembler::notEqual, false, Assembler::pn, *L_slow_path); | |
2452 delayed()->nop(); | |
2453 FINAL_JUMP(*L_success); | |
2454 } | |
2455 } else { | |
2456 // No slow path; it's a fast decision. | |
2457 if (L_failure == &L_fallthrough) { | |
2458 brx(Assembler::equal, false, Assembler::pt, *L_success); | |
2459 delayed()->nop(); | |
2460 } else { | |
2461 brx(Assembler::notEqual, false, Assembler::pn, *L_failure); | |
2462 delayed()->nop(); | |
2463 FINAL_JUMP(*L_success); | |
2464 } | |
2465 } | |
2466 | |
2467 bind(L_fallthrough); | |
2468 | |
2469 #undef FINAL_JUMP | |
2470 } | |
2471 | |
2472 | |
2473 void MacroAssembler::check_klass_subtype_slow_path(Register sub_klass, | |
2474 Register super_klass, | |
2475 Register count_temp, | |
2476 Register scan_temp, | |
2477 Register scratch_reg, | |
2478 Register coop_reg, | |
2479 Label* L_success, | |
2480 Label* L_failure) { | |
2481 assert_different_registers(sub_klass, super_klass, | |
2482 count_temp, scan_temp, scratch_reg, coop_reg); | |
2483 | |
2484 Label L_fallthrough, L_loop; | |
2485 int label_nulls = 0; | |
2486 if (L_success == NULL) { L_success = &L_fallthrough; label_nulls++; } | |
2487 if (L_failure == NULL) { L_failure = &L_fallthrough; label_nulls++; } | |
2488 assert(label_nulls <= 1, "at most one NULL in the batch"); | |
2489 | |
2490 // a couple of useful fields in sub_klass: | |
2491 int ss_offset = in_bytes(Klass::secondary_supers_offset()); | |
2492 int sc_offset = in_bytes(Klass::secondary_super_cache_offset()); | |
2493 | |
2494 // Do a linear scan of the secondary super-klass chain. | |
2495 // This code is rarely used, so simplicity is a virtue here. | |
2496 | |
2497 #ifndef PRODUCT | |
2498 int* pst_counter = &SharedRuntime::_partial_subtype_ctr; | |
2499 inc_counter((address) pst_counter, count_temp, scan_temp); | |
2500 #endif | |
2501 | |
2502 // We will consult the secondary-super array. | |
2503 ld_ptr(sub_klass, ss_offset, scan_temp); | |
2504 | |
2505 Register search_key = super_klass; | |
2506 | |
2507 // Load the array length. (Positive movl does right thing on LP64.) | |
2508 lduw(scan_temp, Array<Klass*>::length_offset_in_bytes(), count_temp); | |
2509 | |
2510 // Check for empty secondary super list | |
2511 tst(count_temp); | |
2512 | |
2513 // In the array of super classes elements are pointer sized. | |
2514 int element_size = wordSize; | |
2515 | |
2516 // Top of search loop | |
2517 bind(L_loop); | |
2518 br(Assembler::equal, false, Assembler::pn, *L_failure); | |
2519 delayed()->add(scan_temp, element_size, scan_temp); | |
2520 | |
2521 // Skip the array header in all array accesses. | |
2522 int elem_offset = Array<Klass*>::base_offset_in_bytes(); | |
2523 elem_offset -= element_size; // the scan pointer was pre-incremented also | |
2524 | |
2525 // Load next super to check | |
2526 ld_ptr( scan_temp, elem_offset, scratch_reg ); | |
2527 | |
2528 // Look for Rsuper_klass on Rsub_klass's secondary super-class-overflow list | |
2529 cmp(scratch_reg, search_key); | |
2530 | |
2531 // A miss means we are NOT a subtype and need to keep looping | |
2532 brx(Assembler::notEqual, false, Assembler::pn, L_loop); | |
2533 delayed()->deccc(count_temp); // decrement trip counter in delay slot | |
2534 | |
2535 // Success. Cache the super we found and proceed in triumph. | |
2536 st_ptr(super_klass, sub_klass, sc_offset); | |
2537 | |
2538 if (L_success != &L_fallthrough) { | |
2539 ba(*L_success); | |
2540 delayed()->nop(); | |
2541 } | |
2542 | |
2543 bind(L_fallthrough); | |
2544 } | |
2545 | |
2546 | |
2547 RegisterOrConstant MacroAssembler::argument_offset(RegisterOrConstant arg_slot, | |
2548 Register temp_reg, | |
2549 int extra_slot_offset) { | |
2550 // cf. TemplateTable::prepare_invoke(), if (load_receiver). | |
2551 int stackElementSize = Interpreter::stackElementSize; | |
2552 int offset = extra_slot_offset * stackElementSize; | |
2553 if (arg_slot.is_constant()) { | |
2554 offset += arg_slot.as_constant() * stackElementSize; | |
2555 return offset; | |
2556 } else { | |
2557 assert(temp_reg != noreg, "must specify"); | |
2558 sll_ptr(arg_slot.as_register(), exact_log2(stackElementSize), temp_reg); | |
2559 if (offset != 0) | |
2560 add(temp_reg, offset, temp_reg); | |
2561 return temp_reg; | |
2562 } | |
2563 } | |
2564 | |
2565 | |
2566 Address MacroAssembler::argument_address(RegisterOrConstant arg_slot, | |
2567 Register temp_reg, | |
2568 int extra_slot_offset) { | |
2569 return Address(Gargs, argument_offset(arg_slot, temp_reg, extra_slot_offset)); | |
2570 } | |
2571 | |
2572 | |
2573 void MacroAssembler::biased_locking_enter(Register obj_reg, Register mark_reg, | |
2574 Register temp_reg, | |
2575 Label& done, Label* slow_case, | |
2576 BiasedLockingCounters* counters) { | |
2577 assert(UseBiasedLocking, "why call this otherwise?"); | |
2578 | |
2579 if (PrintBiasedLockingStatistics) { | |
2580 assert_different_registers(obj_reg, mark_reg, temp_reg, O7); | |
2581 if (counters == NULL) | |
2582 counters = BiasedLocking::counters(); | |
2583 } | |
2584 | |
2585 Label cas_label; | |
2586 | |
2587 // Biased locking | |
2588 // See whether the lock is currently biased toward our thread and | |
2589 // whether the epoch is still valid | |
2590 // Note that the runtime guarantees sufficient alignment of JavaThread | |
2591 // pointers to allow age to be placed into low bits | |
2592 assert(markOopDesc::age_shift == markOopDesc::lock_bits + markOopDesc::biased_lock_bits, "biased locking makes assumptions about bit layout"); | |
2593 and3(mark_reg, markOopDesc::biased_lock_mask_in_place, temp_reg); | |
2594 cmp_and_brx_short(temp_reg, markOopDesc::biased_lock_pattern, Assembler::notEqual, Assembler::pn, cas_label); | |
2595 | |
2596 load_klass(obj_reg, temp_reg); | |
2597 ld_ptr(Address(temp_reg, Klass::prototype_header_offset()), temp_reg); | |
2598 or3(G2_thread, temp_reg, temp_reg); | |
2599 xor3(mark_reg, temp_reg, temp_reg); | |
2600 andcc(temp_reg, ~((int) markOopDesc::age_mask_in_place), temp_reg); | |
2601 if (counters != NULL) { | |
2602 cond_inc(Assembler::equal, (address) counters->biased_lock_entry_count_addr(), mark_reg, temp_reg); | |
2603 // Reload mark_reg as we may need it later | |
2604 ld_ptr(Address(obj_reg, oopDesc::mark_offset_in_bytes()), mark_reg); | |
2605 } | |
2606 brx(Assembler::equal, true, Assembler::pt, done); | |
2607 delayed()->nop(); | |
2608 | |
2609 Label try_revoke_bias; | |
2610 Label try_rebias; | |
2611 Address mark_addr = Address(obj_reg, oopDesc::mark_offset_in_bytes()); | |
2612 assert(mark_addr.disp() == 0, "cas must take a zero displacement"); | |
2613 | |
2614 // At this point we know that the header has the bias pattern and | |
2615 // that we are not the bias owner in the current epoch. We need to | |
2616 // figure out more details about the state of the header in order to | |
2617 // know what operations can be legally performed on the object's | |
2618 // header. | |
2619 | |
2620 // If the low three bits in the xor result aren't clear, that means | |
2621 // the prototype header is no longer biased and we have to revoke | |
2622 // the bias on this object. | |
2623 btst(markOopDesc::biased_lock_mask_in_place, temp_reg); | |
2624 brx(Assembler::notZero, false, Assembler::pn, try_revoke_bias); | |
2625 | |
2626 // Biasing is still enabled for this data type. See whether the | |
2627 // epoch of the current bias is still valid, meaning that the epoch | |
2628 // bits of the mark word are equal to the epoch bits of the | |
2629 // prototype header. (Note that the prototype header's epoch bits | |
2630 // only change at a safepoint.) If not, attempt to rebias the object | |
2631 // toward the current thread. Note that we must be absolutely sure | |
2632 // that the current epoch is invalid in order to do this because | |
2633 // otherwise the manipulations it performs on the mark word are | |
2634 // illegal. | |
2635 delayed()->btst(markOopDesc::epoch_mask_in_place, temp_reg); | |
2636 brx(Assembler::notZero, false, Assembler::pn, try_rebias); | |
2637 | |
2638 // The epoch of the current bias is still valid but we know nothing | |
2639 // about the owner; it might be set or it might be clear. Try to | |
2640 // acquire the bias of the object using an atomic operation. If this | |
2641 // fails we will go in to the runtime to revoke the object's bias. | |
2642 // Note that we first construct the presumed unbiased header so we | |
2643 // don't accidentally blow away another thread's valid bias. | |
2644 delayed()->and3(mark_reg, | |
2645 markOopDesc::biased_lock_mask_in_place | markOopDesc::age_mask_in_place | markOopDesc::epoch_mask_in_place, | |
2646 mark_reg); | |
2647 or3(G2_thread, mark_reg, temp_reg); | |
10997 | 2648 cas_ptr(mark_addr.base(), mark_reg, temp_reg); |
7204 | 2649 // If the biasing toward our thread failed, this means that |
2650 // another thread succeeded in biasing it toward itself and we | |
2651 // need to revoke that bias. The revocation will occur in the | |
2652 // interpreter runtime in the slow case. | |
2653 cmp(mark_reg, temp_reg); | |
2654 if (counters != NULL) { | |
2655 cond_inc(Assembler::zero, (address) counters->anonymously_biased_lock_entry_count_addr(), mark_reg, temp_reg); | |
2656 } | |
2657 if (slow_case != NULL) { | |
2658 brx(Assembler::notEqual, true, Assembler::pn, *slow_case); | |
2659 delayed()->nop(); | |
2660 } | |
2661 ba_short(done); | |
2662 | |
2663 bind(try_rebias); | |
2664 // At this point we know the epoch has expired, meaning that the | |
2665 // current "bias owner", if any, is actually invalid. Under these | |
2666 // circumstances _only_, we are allowed to use the current header's | |
2667 // value as the comparison value when doing the cas to acquire the | |
2668 // bias in the current epoch. In other words, we allow transfer of | |
2669 // the bias from one thread to another directly in this situation. | |
2670 // | |
2671 // FIXME: due to a lack of registers we currently blow away the age | |
2672 // bits in this situation. Should attempt to preserve them. | |
2673 load_klass(obj_reg, temp_reg); | |
2674 ld_ptr(Address(temp_reg, Klass::prototype_header_offset()), temp_reg); | |
2675 or3(G2_thread, temp_reg, temp_reg); | |
10997 | 2676 cas_ptr(mark_addr.base(), mark_reg, temp_reg); |
7204 | 2677 // If the biasing toward our thread failed, this means that |
2678 // another thread succeeded in biasing it toward itself and we | |
2679 // need to revoke that bias. The revocation will occur in the | |
2680 // interpreter runtime in the slow case. | |
2681 cmp(mark_reg, temp_reg); | |
2682 if (counters != NULL) { | |
2683 cond_inc(Assembler::zero, (address) counters->rebiased_lock_entry_count_addr(), mark_reg, temp_reg); | |
2684 } | |
2685 if (slow_case != NULL) { | |
2686 brx(Assembler::notEqual, true, Assembler::pn, *slow_case); | |
2687 delayed()->nop(); | |
2688 } | |
2689 ba_short(done); | |
2690 | |
2691 bind(try_revoke_bias); | |
2692 // The prototype mark in the klass doesn't have the bias bit set any | |
2693 // more, indicating that objects of this data type are not supposed | |
2694 // to be biased any more. We are going to try to reset the mark of | |
2695 // this object to the prototype value and fall through to the | |
2696 // CAS-based locking scheme. Note that if our CAS fails, it means | |
2697 // that another thread raced us for the privilege of revoking the | |
2698 // bias of this particular object, so it's okay to continue in the | |
2699 // normal locking code. | |
2700 // | |
2701 // FIXME: due to a lack of registers we currently blow away the age | |
2702 // bits in this situation. Should attempt to preserve them. | |
2703 load_klass(obj_reg, temp_reg); | |
2704 ld_ptr(Address(temp_reg, Klass::prototype_header_offset()), temp_reg); | |
10997 | 2705 cas_ptr(mark_addr.base(), mark_reg, temp_reg); |
7204 | 2706 // Fall through to the normal CAS-based lock, because no matter what |
2707 // the result of the above CAS, some thread must have succeeded in | |
2708 // removing the bias bit from the object's header. | |
2709 if (counters != NULL) { | |
2710 cmp(mark_reg, temp_reg); | |
2711 cond_inc(Assembler::zero, (address) counters->revoked_lock_entry_count_addr(), mark_reg, temp_reg); | |
2712 } | |
2713 | |
2714 bind(cas_label); | |
2715 } | |
2716 | |
2717 void MacroAssembler::biased_locking_exit (Address mark_addr, Register temp_reg, Label& done, | |
2718 bool allow_delay_slot_filling) { | |
2719 // Check for biased locking unlock case, which is a no-op | |
2720 // Note: we do not have to check the thread ID for two reasons. | |
2721 // First, the interpreter checks for IllegalMonitorStateException at | |
2722 // a higher level. Second, if the bias was revoked while we held the | |
2723 // lock, the object could not be rebiased toward another thread, so | |
2724 // the bias bit would be clear. | |
2725 ld_ptr(mark_addr, temp_reg); | |
2726 and3(temp_reg, markOopDesc::biased_lock_mask_in_place, temp_reg); | |
2727 cmp(temp_reg, markOopDesc::biased_lock_pattern); | |
2728 brx(Assembler::equal, allow_delay_slot_filling, Assembler::pt, done); | |
2729 delayed(); | |
2730 if (!allow_delay_slot_filling) { | |
2731 nop(); | |
2732 } | |
2733 } | |
2734 | |
2735 | |
2736 // compiler_lock_object() and compiler_unlock_object() are direct transliterations | |
2737 // of i486.ad fast_lock() and fast_unlock(). See those methods for detailed comments. | |
2738 // The code could be tightened up considerably. | |
2739 // | |
2740 // box->dhw disposition - post-conditions at DONE_LABEL. | |
2741 // - Successful inflated lock: box->dhw != 0. | |
2742 // Any non-zero value suffices. | |
2743 // Consider G2_thread, rsp, boxReg, or unused_mark() | |
2744 // - Successful Stack-lock: box->dhw == mark. | |
2745 // box->dhw must contain the displaced mark word value | |
2746 // - Failure -- icc.ZFlag == 0 and box->dhw is undefined. | |
2747 // The slow-path fast_enter() and slow_enter() operators | |
2748 // are responsible for setting box->dhw = NonZero (typically ::unused_mark). | |
2749 // - Biased: box->dhw is undefined | |
2750 // | |
2751 // SPARC refworkload performance - specifically jetstream and scimark - are | |
2752 // extremely sensitive to the size of the code emitted by compiler_lock_object | |
2753 // and compiler_unlock_object. Critically, the key factor is code size, not path | |
2754 // length. (Simply experiments to pad CLO with unexecuted NOPs demonstrte the | |
2755 // effect). | |
2756 | |
2757 | |
2758 void MacroAssembler::compiler_lock_object(Register Roop, Register Rmark, | |
2759 Register Rbox, Register Rscratch, | |
2760 BiasedLockingCounters* counters, | |
2761 bool try_bias) { | |
2762 Address mark_addr(Roop, oopDesc::mark_offset_in_bytes()); | |
2763 | |
2764 verify_oop(Roop); | |
2765 Label done ; | |
2766 | |
2767 if (counters != NULL) { | |
2768 inc_counter((address) counters->total_entry_count_addr(), Rmark, Rscratch); | |
2769 } | |
2770 | |
2771 if (EmitSync & 1) { | |
2772 mov(3, Rscratch); | |
2773 st_ptr(Rscratch, Rbox, BasicLock::displaced_header_offset_in_bytes()); | |
2774 cmp(SP, G0); | |
2775 return ; | |
2776 } | |
2777 | |
2778 if (EmitSync & 2) { | |
2779 | |
2780 // Fetch object's markword | |
2781 ld_ptr(mark_addr, Rmark); | |
2782 | |
2783 if (try_bias) { | |
2784 biased_locking_enter(Roop, Rmark, Rscratch, done, NULL, counters); | |
2785 } | |
2786 | |
2787 // Save Rbox in Rscratch to be used for the cas operation | |
2788 mov(Rbox, Rscratch); | |
2789 | |
2790 // set Rmark to markOop | markOopDesc::unlocked_value | |
2791 or3(Rmark, markOopDesc::unlocked_value, Rmark); | |
2792 | |
2793 // Initialize the box. (Must happen before we update the object mark!) | |
2794 st_ptr(Rmark, Rbox, BasicLock::displaced_header_offset_in_bytes()); | |
2795 | |
2796 // compare object markOop with Rmark and if equal exchange Rscratch with object markOop | |
2797 assert(mark_addr.disp() == 0, "cas must take a zero displacement"); | |
10997 | 2798 cas_ptr(mark_addr.base(), Rmark, Rscratch); |
7204 | 2799 |
2800 // if compare/exchange succeeded we found an unlocked object and we now have locked it | |
2801 // hence we are done | |
2802 cmp(Rmark, Rscratch); | |
2803 #ifdef _LP64 | |
2804 sub(Rscratch, STACK_BIAS, Rscratch); | |
2805 #endif | |
2806 brx(Assembler::equal, false, Assembler::pt, done); | |
2807 delayed()->sub(Rscratch, SP, Rscratch); //pull next instruction into delay slot | |
2808 | |
2809 // we did not find an unlocked object so see if this is a recursive case | |
2810 // sub(Rscratch, SP, Rscratch); | |
2811 assert(os::vm_page_size() > 0xfff, "page size too small - change the constant"); | |
2812 andcc(Rscratch, 0xfffff003, Rscratch); | |
2813 st_ptr(Rscratch, Rbox, BasicLock::displaced_header_offset_in_bytes()); | |
2814 bind (done); | |
2815 return ; | |
2816 } | |
2817 | |
2818 Label Egress ; | |
2819 | |
2820 if (EmitSync & 256) { | |
2821 Label IsInflated ; | |
2822 | |
2823 ld_ptr(mark_addr, Rmark); // fetch obj->mark | |
2824 // Triage: biased, stack-locked, neutral, inflated | |
2825 if (try_bias) { | |
2826 biased_locking_enter(Roop, Rmark, Rscratch, done, NULL, counters); | |
2827 // Invariant: if control reaches this point in the emitted stream | |
2828 // then Rmark has not been modified. | |
2829 } | |
2830 | |
2831 // Store mark into displaced mark field in the on-stack basic-lock "box" | |
2832 // Critically, this must happen before the CAS | |
2833 // Maximize the ST-CAS distance to minimize the ST-before-CAS penalty. | |
2834 st_ptr(Rmark, Rbox, BasicLock::displaced_header_offset_in_bytes()); | |
2835 andcc(Rmark, 2, G0); | |
2836 brx(Assembler::notZero, false, Assembler::pn, IsInflated); | |
2837 delayed()-> | |
2838 | |
2839 // Try stack-lock acquisition. | |
2840 // Beware: the 1st instruction is in a delay slot | |
2841 mov(Rbox, Rscratch); | |
2842 or3(Rmark, markOopDesc::unlocked_value, Rmark); | |
2843 assert(mark_addr.disp() == 0, "cas must take a zero displacement"); | |
10997 | 2844 cas_ptr(mark_addr.base(), Rmark, Rscratch); |
7204 | 2845 cmp(Rmark, Rscratch); |
2846 brx(Assembler::equal, false, Assembler::pt, done); | |
2847 delayed()->sub(Rscratch, SP, Rscratch); | |
2848 | |
2849 // Stack-lock attempt failed - check for recursive stack-lock. | |
2850 // See the comments below about how we might remove this case. | |
2851 #ifdef _LP64 | |
2852 sub(Rscratch, STACK_BIAS, Rscratch); | |
2853 #endif | |
2854 assert(os::vm_page_size() > 0xfff, "page size too small - change the constant"); | |
2855 andcc(Rscratch, 0xfffff003, Rscratch); | |
2856 br(Assembler::always, false, Assembler::pt, done); | |
2857 delayed()-> st_ptr(Rscratch, Rbox, BasicLock::displaced_header_offset_in_bytes()); | |
2858 | |
2859 bind(IsInflated); | |
2860 if (EmitSync & 64) { | |
2861 // If m->owner != null goto IsLocked | |
2862 // Pessimistic form: Test-and-CAS vs CAS | |
2863 // The optimistic form avoids RTS->RTO cache line upgrades. | |
2864 ld_ptr(Rmark, ObjectMonitor::owner_offset_in_bytes() - 2, Rscratch); | |
2865 andcc(Rscratch, Rscratch, G0); | |
2866 brx(Assembler::notZero, false, Assembler::pn, done); | |
2867 delayed()->nop(); | |
2868 // m->owner == null : it's unlocked. | |
2869 } | |
2870 | |
2871 // Try to CAS m->owner from null to Self | |
2872 // Invariant: if we acquire the lock then _recursions should be 0. | |
2873 add(Rmark, ObjectMonitor::owner_offset_in_bytes()-2, Rmark); | |
2874 mov(G2_thread, Rscratch); | |
10997 | 2875 cas_ptr(Rmark, G0, Rscratch); |
7204 | 2876 cmp(Rscratch, G0); |
2877 // Intentional fall-through into done | |
2878 } else { | |
2879 // Aggressively avoid the Store-before-CAS penalty | |
2880 // Defer the store into box->dhw until after the CAS | |
2881 Label IsInflated, Recursive ; | |
2882 | |
2883 // Anticipate CAS -- Avoid RTS->RTO upgrade | |
2884 // prefetch (mark_addr, Assembler::severalWritesAndPossiblyReads); | |
2885 | |
2886 ld_ptr(mark_addr, Rmark); // fetch obj->mark | |
2887 // Triage: biased, stack-locked, neutral, inflated | |
2888 | |
2889 if (try_bias) { | |
2890 biased_locking_enter(Roop, Rmark, Rscratch, done, NULL, counters); | |
2891 // Invariant: if control reaches this point in the emitted stream | |
2892 // then Rmark has not been modified. | |
2893 } | |
2894 andcc(Rmark, 2, G0); | |
2895 brx(Assembler::notZero, false, Assembler::pn, IsInflated); | |
2896 delayed()-> // Beware - dangling delay-slot | |
2897 | |
2898 // Try stack-lock acquisition. | |
2899 // Transiently install BUSY (0) encoding in the mark word. | |
2900 // if the CAS of 0 into the mark was successful then we execute: | |
2901 // ST box->dhw = mark -- save fetched mark in on-stack basiclock box | |
2902 // ST obj->mark = box -- overwrite transient 0 value | |
2903 // This presumes TSO, of course. | |
2904 | |
2905 mov(0, Rscratch); | |
2906 or3(Rmark, markOopDesc::unlocked_value, Rmark); | |
2907 assert(mark_addr.disp() == 0, "cas must take a zero displacement"); | |
10997 | 2908 cas_ptr(mark_addr.base(), Rmark, Rscratch); |
7204 | 2909 // prefetch (mark_addr, Assembler::severalWritesAndPossiblyReads); |
2910 cmp(Rscratch, Rmark); | |
2911 brx(Assembler::notZero, false, Assembler::pn, Recursive); | |
2912 delayed()->st_ptr(Rmark, Rbox, BasicLock::displaced_header_offset_in_bytes()); | |
2913 if (counters != NULL) { | |
2914 cond_inc(Assembler::equal, (address) counters->fast_path_entry_count_addr(), Rmark, Rscratch); | |
2915 } | |
2916 ba(done); | |
2917 delayed()->st_ptr(Rbox, mark_addr); | |
2918 | |
2919 bind(Recursive); | |
2920 // Stack-lock attempt failed - check for recursive stack-lock. | |
2921 // Tests show that we can remove the recursive case with no impact | |
2922 // on refworkload 0.83. If we need to reduce the size of the code | |
2923 // emitted by compiler_lock_object() the recursive case is perfect | |
2924 // candidate. | |
2925 // | |
2926 // A more extreme idea is to always inflate on stack-lock recursion. | |
2927 // This lets us eliminate the recursive checks in compiler_lock_object | |
2928 // and compiler_unlock_object and the (box->dhw == 0) encoding. | |
2929 // A brief experiment - requiring changes to synchronizer.cpp, interpreter, | |
2930 // and showed a performance *increase*. In the same experiment I eliminated | |
2931 // the fast-path stack-lock code from the interpreter and always passed | |
2932 // control to the "slow" operators in synchronizer.cpp. | |
2933 | |
10997 | 2934 // RScratch contains the fetched obj->mark value from the failed CAS. |
7204 | 2935 #ifdef _LP64 |
2936 sub(Rscratch, STACK_BIAS, Rscratch); | |
2937 #endif | |
2938 sub(Rscratch, SP, Rscratch); | |
2939 assert(os::vm_page_size() > 0xfff, "page size too small - change the constant"); | |
2940 andcc(Rscratch, 0xfffff003, Rscratch); | |
2941 if (counters != NULL) { | |
2942 // Accounting needs the Rscratch register | |
2943 st_ptr(Rscratch, Rbox, BasicLock::displaced_header_offset_in_bytes()); | |
2944 cond_inc(Assembler::equal, (address) counters->fast_path_entry_count_addr(), Rmark, Rscratch); | |
2945 ba_short(done); | |
2946 } else { | |
2947 ba(done); | |
2948 delayed()->st_ptr(Rscratch, Rbox, BasicLock::displaced_header_offset_in_bytes()); | |
2949 } | |
2950 | |
2951 bind (IsInflated); | |
2952 if (EmitSync & 64) { | |
2953 // If m->owner != null goto IsLocked | |
2954 // Test-and-CAS vs CAS | |
2955 // Pessimistic form avoids futile (doomed) CAS attempts | |
2956 // The optimistic form avoids RTS->RTO cache line upgrades. | |
2957 ld_ptr(Rmark, ObjectMonitor::owner_offset_in_bytes() - 2, Rscratch); | |
2958 andcc(Rscratch, Rscratch, G0); | |
2959 brx(Assembler::notZero, false, Assembler::pn, done); | |
2960 delayed()->nop(); | |
2961 // m->owner == null : it's unlocked. | |
2962 } | |
2963 | |
2964 // Try to CAS m->owner from null to Self | |
2965 // Invariant: if we acquire the lock then _recursions should be 0. | |
2966 add(Rmark, ObjectMonitor::owner_offset_in_bytes()-2, Rmark); | |
2967 mov(G2_thread, Rscratch); | |
10997 | 2968 cas_ptr(Rmark, G0, Rscratch); |
7204 | 2969 cmp(Rscratch, G0); |
2970 // ST box->displaced_header = NonZero. | |
2971 // Any non-zero value suffices: | |
2972 // unused_mark(), G2_thread, RBox, RScratch, rsp, etc. | |
2973 st_ptr(Rbox, Rbox, BasicLock::displaced_header_offset_in_bytes()); | |
2974 // Intentional fall-through into done | |
2975 } | |
2976 | |
2977 bind (done); | |
2978 } | |
2979 | |
2980 void MacroAssembler::compiler_unlock_object(Register Roop, Register Rmark, | |
2981 Register Rbox, Register Rscratch, | |
2982 bool try_bias) { | |
2983 Address mark_addr(Roop, oopDesc::mark_offset_in_bytes()); | |
2984 | |
2985 Label done ; | |
2986 | |
2987 if (EmitSync & 4) { | |
2988 cmp(SP, G0); | |
2989 return ; | |
2990 } | |
2991 | |
2992 if (EmitSync & 8) { | |
2993 if (try_bias) { | |
2994 biased_locking_exit(mark_addr, Rscratch, done); | |
2995 } | |
2996 | |
2997 // Test first if it is a fast recursive unlock | |
2998 ld_ptr(Rbox, BasicLock::displaced_header_offset_in_bytes(), Rmark); | |
2999 br_null_short(Rmark, Assembler::pt, done); | |
3000 | |
3001 // Check if it is still a light weight lock, this is is true if we see | |
3002 // the stack address of the basicLock in the markOop of the object | |
3003 assert(mark_addr.disp() == 0, "cas must take a zero displacement"); | |
10997 | 3004 cas_ptr(mark_addr.base(), Rbox, Rmark); |
7204 | 3005 ba(done); |
3006 delayed()->cmp(Rbox, Rmark); | |
3007 bind(done); | |
3008 return ; | |
3009 } | |
3010 | |
3011 // Beware ... If the aggregate size of the code emitted by CLO and CUO is | |
3012 // is too large performance rolls abruptly off a cliff. | |
3013 // This could be related to inlining policies, code cache management, or | |
3014 // I$ effects. | |
3015 Label LStacked ; | |
3016 | |
3017 if (try_bias) { | |
3018 // TODO: eliminate redundant LDs of obj->mark | |
3019 biased_locking_exit(mark_addr, Rscratch, done); | |
3020 } | |
3021 | |
3022 ld_ptr(Roop, oopDesc::mark_offset_in_bytes(), Rmark); | |
3023 ld_ptr(Rbox, BasicLock::displaced_header_offset_in_bytes(), Rscratch); | |
3024 andcc(Rscratch, Rscratch, G0); | |
3025 brx(Assembler::zero, false, Assembler::pn, done); | |
3026 delayed()->nop(); // consider: relocate fetch of mark, above, into this DS | |
3027 andcc(Rmark, 2, G0); | |
3028 brx(Assembler::zero, false, Assembler::pt, LStacked); | |
3029 delayed()->nop(); | |
3030 | |
3031 // It's inflated | |
3032 // Conceptually we need a #loadstore|#storestore "release" MEMBAR before | |
3033 // the ST of 0 into _owner which releases the lock. This prevents loads | |
3034 // and stores within the critical section from reordering (floating) | |
3035 // past the store that releases the lock. But TSO is a strong memory model | |
3036 // and that particular flavor of barrier is a noop, so we can safely elide it. | |
3037 // Note that we use 1-0 locking by default for the inflated case. We | |
3038 // close the resultant (and rare) race by having contented threads in | |
3039 // monitorenter periodically poll _owner. | |
3040 ld_ptr(Rmark, ObjectMonitor::owner_offset_in_bytes() - 2, Rscratch); | |
3041 ld_ptr(Rmark, ObjectMonitor::recursions_offset_in_bytes() - 2, Rbox); | |
3042 xor3(Rscratch, G2_thread, Rscratch); | |
3043 orcc(Rbox, Rscratch, Rbox); | |
3044 brx(Assembler::notZero, false, Assembler::pn, done); | |
3045 delayed()-> | |
3046 ld_ptr(Rmark, ObjectMonitor::EntryList_offset_in_bytes() - 2, Rscratch); | |
3047 ld_ptr(Rmark, ObjectMonitor::cxq_offset_in_bytes() - 2, Rbox); | |
3048 orcc(Rbox, Rscratch, G0); | |
3049 if (EmitSync & 65536) { | |
3050 Label LSucc ; | |
3051 brx(Assembler::notZero, false, Assembler::pn, LSucc); | |
3052 delayed()->nop(); | |
3053 ba(done); | |
3054 delayed()->st_ptr(G0, Rmark, ObjectMonitor::owner_offset_in_bytes() - 2); | |
3055 | |
3056 bind(LSucc); | |
3057 st_ptr(G0, Rmark, ObjectMonitor::owner_offset_in_bytes() - 2); | |
3058 if (os::is_MP()) { membar (StoreLoad); } | |
3059 ld_ptr(Rmark, ObjectMonitor::succ_offset_in_bytes() - 2, Rscratch); | |
3060 andcc(Rscratch, Rscratch, G0); | |
3061 brx(Assembler::notZero, false, Assembler::pt, done); | |
3062 delayed()->andcc(G0, G0, G0); | |
3063 add(Rmark, ObjectMonitor::owner_offset_in_bytes()-2, Rmark); | |
3064 mov(G2_thread, Rscratch); | |
10997 | 3065 cas_ptr(Rmark, G0, Rscratch); |
7204 | 3066 // invert icc.zf and goto done |
3067 br_notnull(Rscratch, false, Assembler::pt, done); | |
3068 delayed()->cmp(G0, G0); | |
3069 ba(done); | |
3070 delayed()->cmp(G0, 1); | |
3071 } else { | |
3072 brx(Assembler::notZero, false, Assembler::pn, done); | |
3073 delayed()->nop(); | |
3074 ba(done); | |
3075 delayed()->st_ptr(G0, Rmark, ObjectMonitor::owner_offset_in_bytes() - 2); | |
3076 } | |
3077 | |
3078 bind (LStacked); | |
3079 // Consider: we could replace the expensive CAS in the exit | |
3080 // path with a simple ST of the displaced mark value fetched from | |
3081 // the on-stack basiclock box. That admits a race where a thread T2 | |
3082 // in the slow lock path -- inflating with monitor M -- could race a | |
3083 // thread T1 in the fast unlock path, resulting in a missed wakeup for T2. | |
3084 // More precisely T1 in the stack-lock unlock path could "stomp" the | |
3085 // inflated mark value M installed by T2, resulting in an orphan | |
3086 // object monitor M and T2 becoming stranded. We can remedy that situation | |
3087 // by having T2 periodically poll the object's mark word using timed wait | |
3088 // operations. If T2 discovers that a stomp has occurred it vacates | |
3089 // the monitor M and wakes any other threads stranded on the now-orphan M. | |
3090 // In addition the monitor scavenger, which performs deflation, | |
3091 // would also need to check for orpan monitors and stranded threads. | |
3092 // | |
3093 // Finally, inflation is also used when T2 needs to assign a hashCode | |
3094 // to O and O is stack-locked by T1. The "stomp" race could cause | |
3095 // an assigned hashCode value to be lost. We can avoid that condition | |
3096 // and provide the necessary hashCode stability invariants by ensuring | |
3097 // that hashCode generation is idempotent between copying GCs. | |
3098 // For example we could compute the hashCode of an object O as | |
3099 // O's heap address XOR some high quality RNG value that is refreshed | |
3100 // at GC-time. The monitor scavenger would install the hashCode | |
3101 // found in any orphan monitors. Again, the mechanism admits a | |
3102 // lost-update "stomp" WAW race but detects and recovers as needed. | |
3103 // | |
3104 // A prototype implementation showed excellent results, although | |
3105 // the scavenger and timeout code was rather involved. | |
3106 | |
10997 | 3107 cas_ptr(mark_addr.base(), Rbox, Rscratch); |
7204 | 3108 cmp(Rbox, Rscratch); |
3109 // Intentional fall through into done ... | |
3110 | |
3111 bind(done); | |
3112 } | |
3113 | |
3114 | |
3115 | |
3116 void MacroAssembler::print_CPU_state() { | |
3117 // %%%%% need to implement this | |
3118 } | |
3119 | |
3120 void MacroAssembler::verify_FPU(int stack_depth, const char* s) { | |
3121 // %%%%% need to implement this | |
3122 } | |
3123 | |
3124 void MacroAssembler::push_IU_state() { | |
3125 // %%%%% need to implement this | |
3126 } | |
3127 | |
3128 | |
3129 void MacroAssembler::pop_IU_state() { | |
3130 // %%%%% need to implement this | |
3131 } | |
3132 | |
3133 | |
3134 void MacroAssembler::push_FPU_state() { | |
3135 // %%%%% need to implement this | |
3136 } | |
3137 | |
3138 | |
3139 void MacroAssembler::pop_FPU_state() { | |
3140 // %%%%% need to implement this | |
3141 } | |
3142 | |
3143 | |
3144 void MacroAssembler::push_CPU_state() { | |
3145 // %%%%% need to implement this | |
3146 } | |
3147 | |
3148 | |
3149 void MacroAssembler::pop_CPU_state() { | |
3150 // %%%%% need to implement this | |
3151 } | |
3152 | |
3153 | |
3154 | |
3155 void MacroAssembler::verify_tlab() { | |
3156 #ifdef ASSERT | |
3157 if (UseTLAB && VerifyOops) { | |
3158 Label next, next2, ok; | |
3159 Register t1 = L0; | |
3160 Register t2 = L1; | |
3161 Register t3 = L2; | |
3162 | |
3163 save_frame(0); | |
3164 ld_ptr(G2_thread, in_bytes(JavaThread::tlab_top_offset()), t1); | |
3165 ld_ptr(G2_thread, in_bytes(JavaThread::tlab_start_offset()), t2); | |
3166 or3(t1, t2, t3); | |
3167 cmp_and_br_short(t1, t2, Assembler::greaterEqual, Assembler::pn, next); | |
3168 STOP("assert(top >= start)"); | |
3169 should_not_reach_here(); | |
3170 | |
3171 bind(next); | |
3172 ld_ptr(G2_thread, in_bytes(JavaThread::tlab_top_offset()), t1); | |
3173 ld_ptr(G2_thread, in_bytes(JavaThread::tlab_end_offset()), t2); | |
3174 or3(t3, t2, t3); | |
3175 cmp_and_br_short(t1, t2, Assembler::lessEqual, Assembler::pn, next2); | |
3176 STOP("assert(top <= end)"); | |
3177 should_not_reach_here(); | |
3178 | |
3179 bind(next2); | |
3180 and3(t3, MinObjAlignmentInBytesMask, t3); | |
3181 cmp_and_br_short(t3, 0, Assembler::lessEqual, Assembler::pn, ok); | |
3182 STOP("assert(aligned)"); | |
3183 should_not_reach_here(); | |
3184 | |
3185 bind(ok); | |
3186 restore(); | |
3187 } | |
3188 #endif | |
3189 } | |
3190 | |
3191 | |
3192 void MacroAssembler::eden_allocate( | |
3193 Register obj, // result: pointer to object after successful allocation | |
3194 Register var_size_in_bytes, // object size in bytes if unknown at compile time; invalid otherwise | |
3195 int con_size_in_bytes, // object size in bytes if known at compile time | |
3196 Register t1, // temp register | |
3197 Register t2, // temp register | |
3198 Label& slow_case // continuation point if fast allocation fails | |
3199 ){ | |
3200 // make sure arguments make sense | |
3201 assert_different_registers(obj, var_size_in_bytes, t1, t2); | |
3202 assert(0 <= con_size_in_bytes && Assembler::is_simm13(con_size_in_bytes), "illegal object size"); | |
3203 assert((con_size_in_bytes & MinObjAlignmentInBytesMask) == 0, "object size is not multiple of alignment"); | |
3204 | |
3205 if (CMSIncrementalMode || !Universe::heap()->supports_inline_contig_alloc()) { | |
3206 // No allocation in the shared eden. | |
10995
8d52e305a777
8015437: SPARC cbcond branch offset out of 10-bit range
morris
parents:
8767
diff
changeset
|
3207 ba(slow_case); |
8d52e305a777
8015437: SPARC cbcond branch offset out of 10-bit range
morris
parents:
8767
diff
changeset
|
3208 delayed()->nop(); |
7204 | 3209 } else { |
3210 // get eden boundaries | |
3211 // note: we need both top & top_addr! | |
3212 const Register top_addr = t1; | |
3213 const Register end = t2; | |
3214 | |
3215 CollectedHeap* ch = Universe::heap(); | |
3216 set((intx)ch->top_addr(), top_addr); | |
3217 intx delta = (intx)ch->end_addr() - (intx)ch->top_addr(); | |
3218 ld_ptr(top_addr, delta, end); | |
3219 ld_ptr(top_addr, 0, obj); | |
3220 | |
3221 // try to allocate | |
3222 Label retry; | |
3223 bind(retry); | |
3224 #ifdef ASSERT | |
3225 // make sure eden top is properly aligned | |
3226 { | |
3227 Label L; | |
3228 btst(MinObjAlignmentInBytesMask, obj); | |
3229 br(Assembler::zero, false, Assembler::pt, L); | |
3230 delayed()->nop(); | |
3231 STOP("eden top is not properly aligned"); | |
3232 bind(L); | |
3233 } | |
3234 #endif // ASSERT | |
3235 const Register free = end; | |
3236 sub(end, obj, free); // compute amount of free space | |
3237 if (var_size_in_bytes->is_valid()) { | |
3238 // size is unknown at compile time | |
3239 cmp(free, var_size_in_bytes); | |
3240 br(Assembler::lessUnsigned, false, Assembler::pn, slow_case); // if there is not enough space go the slow case | |
3241 delayed()->add(obj, var_size_in_bytes, end); | |
3242 } else { | |
3243 // size is known at compile time | |
3244 cmp(free, con_size_in_bytes); | |
3245 br(Assembler::lessUnsigned, false, Assembler::pn, slow_case); // if there is not enough space go the slow case | |
3246 delayed()->add(obj, con_size_in_bytes, end); | |
3247 } | |
3248 // Compare obj with the value at top_addr; if still equal, swap the value of | |
3249 // end with the value at top_addr. If not equal, read the value at top_addr | |
3250 // into end. | |
10997 | 3251 cas_ptr(top_addr, obj, end); |
7204 | 3252 // if someone beat us on the allocation, try again, otherwise continue |
3253 cmp(obj, end); | |
3254 brx(Assembler::notEqual, false, Assembler::pn, retry); | |
3255 delayed()->mov(end, obj); // nop if successfull since obj == end | |
3256 | |
3257 #ifdef ASSERT | |
3258 // make sure eden top is properly aligned | |
3259 { | |
3260 Label L; | |
3261 const Register top_addr = t1; | |
3262 | |
3263 set((intx)ch->top_addr(), top_addr); | |
3264 ld_ptr(top_addr, 0, top_addr); | |
3265 btst(MinObjAlignmentInBytesMask, top_addr); | |
3266 br(Assembler::zero, false, Assembler::pt, L); | |
3267 delayed()->nop(); | |
3268 STOP("eden top is not properly aligned"); | |
3269 bind(L); | |
3270 } | |
3271 #endif // ASSERT | |
3272 } | |
3273 } | |
3274 | |
3275 | |
3276 void MacroAssembler::tlab_allocate( | |
3277 Register obj, // result: pointer to object after successful allocation | |
3278 Register var_size_in_bytes, // object size in bytes if unknown at compile time; invalid otherwise | |
3279 int con_size_in_bytes, // object size in bytes if known at compile time | |
3280 Register t1, // temp register | |
3281 Label& slow_case // continuation point if fast allocation fails | |
3282 ){ | |
3283 // make sure arguments make sense | |
3284 assert_different_registers(obj, var_size_in_bytes, t1); | |
3285 assert(0 <= con_size_in_bytes && is_simm13(con_size_in_bytes), "illegal object size"); | |
3286 assert((con_size_in_bytes & MinObjAlignmentInBytesMask) == 0, "object size is not multiple of alignment"); | |
3287 | |
3288 const Register free = t1; | |
3289 | |
3290 verify_tlab(); | |
3291 | |
3292 ld_ptr(G2_thread, in_bytes(JavaThread::tlab_top_offset()), obj); | |
3293 | |
3294 // calculate amount of free space | |
3295 ld_ptr(G2_thread, in_bytes(JavaThread::tlab_end_offset()), free); | |
3296 sub(free, obj, free); | |
3297 | |
3298 Label done; | |
3299 if (var_size_in_bytes == noreg) { | |
3300 cmp(free, con_size_in_bytes); | |
3301 } else { | |
3302 cmp(free, var_size_in_bytes); | |
3303 } | |
3304 br(Assembler::less, false, Assembler::pn, slow_case); | |
3305 // calculate the new top pointer | |
3306 if (var_size_in_bytes == noreg) { | |
3307 delayed()->add(obj, con_size_in_bytes, free); | |
3308 } else { | |
3309 delayed()->add(obj, var_size_in_bytes, free); | |
3310 } | |
3311 | |
3312 bind(done); | |
3313 | |
3314 #ifdef ASSERT | |
3315 // make sure new free pointer is properly aligned | |
3316 { | |
3317 Label L; | |
3318 btst(MinObjAlignmentInBytesMask, free); | |
3319 br(Assembler::zero, false, Assembler::pt, L); | |
3320 delayed()->nop(); | |
3321 STOP("updated TLAB free is not properly aligned"); | |
3322 bind(L); | |
3323 } | |
3324 #endif // ASSERT | |
3325 | |
3326 // update the tlab top pointer | |
3327 st_ptr(free, G2_thread, in_bytes(JavaThread::tlab_top_offset())); | |
3328 verify_tlab(); | |
3329 } | |
3330 | |
3331 | |
3332 void MacroAssembler::tlab_refill(Label& retry, Label& try_eden, Label& slow_case) { | |
3333 Register top = O0; | |
3334 Register t1 = G1; | |
3335 Register t2 = G3; | |
3336 Register t3 = O1; | |
3337 assert_different_registers(top, t1, t2, t3, G4, G5 /* preserve G4 and G5 */); | |
3338 Label do_refill, discard_tlab; | |
3339 | |
3340 if (CMSIncrementalMode || !Universe::heap()->supports_inline_contig_alloc()) { | |
3341 // No allocation in the shared eden. | |
3342 ba_short(slow_case); | |
3343 } | |
3344 | |
3345 ld_ptr(G2_thread, in_bytes(JavaThread::tlab_top_offset()), top); | |
3346 ld_ptr(G2_thread, in_bytes(JavaThread::tlab_end_offset()), t1); | |
3347 ld_ptr(G2_thread, in_bytes(JavaThread::tlab_refill_waste_limit_offset()), t2); | |
3348 | |
3349 // calculate amount of free space | |
3350 sub(t1, top, t1); | |
3351 srl_ptr(t1, LogHeapWordSize, t1); | |
3352 | |
3353 // Retain tlab and allocate object in shared space if | |
3354 // the amount free in the tlab is too large to discard. | |
3355 cmp(t1, t2); | |
3356 brx(Assembler::lessEqual, false, Assembler::pt, discard_tlab); | |
3357 | |
3358 // increment waste limit to prevent getting stuck on this slow path | |
3359 delayed()->add(t2, ThreadLocalAllocBuffer::refill_waste_limit_increment(), t2); | |
3360 st_ptr(t2, G2_thread, in_bytes(JavaThread::tlab_refill_waste_limit_offset())); | |
3361 if (TLABStats) { | |
3362 // increment number of slow_allocations | |
3363 ld(G2_thread, in_bytes(JavaThread::tlab_slow_allocations_offset()), t2); | |
3364 add(t2, 1, t2); | |
3365 stw(t2, G2_thread, in_bytes(JavaThread::tlab_slow_allocations_offset())); | |
3366 } | |
3367 ba_short(try_eden); | |
3368 | |
3369 bind(discard_tlab); | |
3370 if (TLABStats) { | |
3371 // increment number of refills | |
3372 ld(G2_thread, in_bytes(JavaThread::tlab_number_of_refills_offset()), t2); | |
3373 add(t2, 1, t2); | |
3374 stw(t2, G2_thread, in_bytes(JavaThread::tlab_number_of_refills_offset())); | |
3375 // accumulate wastage | |
3376 ld(G2_thread, in_bytes(JavaThread::tlab_fast_refill_waste_offset()), t2); | |
3377 add(t2, t1, t2); | |
3378 stw(t2, G2_thread, in_bytes(JavaThread::tlab_fast_refill_waste_offset())); | |
3379 } | |
3380 | |
3381 // if tlab is currently allocated (top or end != null) then | |
3382 // fill [top, end + alignment_reserve) with array object | |
3383 br_null_short(top, Assembler::pn, do_refill); | |
3384 | |
3385 set((intptr_t)markOopDesc::prototype()->copy_set_hash(0x2), t2); | |
3386 st_ptr(t2, top, oopDesc::mark_offset_in_bytes()); // set up the mark word | |
3387 // set klass to intArrayKlass | |
3388 sub(t1, typeArrayOopDesc::header_size(T_INT), t1); | |
3389 add(t1, ThreadLocalAllocBuffer::alignment_reserve(), t1); | |
3390 sll_ptr(t1, log2_intptr(HeapWordSize/sizeof(jint)), t1); | |
3391 st(t1, top, arrayOopDesc::length_offset_in_bytes()); | |
3392 set((intptr_t)Universe::intArrayKlassObj_addr(), t2); | |
3393 ld_ptr(t2, 0, t2); | |
3394 // store klass last. concurrent gcs assumes klass length is valid if | |
3395 // klass field is not null. | |
3396 store_klass(t2, top); | |
3397 verify_oop(top); | |
3398 | |
3399 ld_ptr(G2_thread, in_bytes(JavaThread::tlab_start_offset()), t1); | |
3400 sub(top, t1, t1); // size of tlab's allocated portion | |
3401 incr_allocated_bytes(t1, t2, t3); | |
3402 | |
3403 // refill the tlab with an eden allocation | |
3404 bind(do_refill); | |
3405 ld_ptr(G2_thread, in_bytes(JavaThread::tlab_size_offset()), t1); | |
3406 sll_ptr(t1, LogHeapWordSize, t1); | |
3407 // allocate new tlab, address returned in top | |
3408 eden_allocate(top, t1, 0, t2, t3, slow_case); | |
3409 | |
3410 st_ptr(top, G2_thread, in_bytes(JavaThread::tlab_start_offset())); | |
3411 st_ptr(top, G2_thread, in_bytes(JavaThread::tlab_top_offset())); | |
3412 #ifdef ASSERT | |
3413 // check that tlab_size (t1) is still valid | |
3414 { | |
3415 Label ok; | |
3416 ld_ptr(G2_thread, in_bytes(JavaThread::tlab_size_offset()), t2); | |
3417 sll_ptr(t2, LogHeapWordSize, t2); | |
3418 cmp_and_br_short(t1, t2, Assembler::equal, Assembler::pt, ok); | |
3419 STOP("assert(t1 == tlab_size)"); | |
3420 should_not_reach_here(); | |
3421 | |
3422 bind(ok); | |
3423 } | |
3424 #endif // ASSERT | |
3425 add(top, t1, top); // t1 is tlab_size | |
3426 sub(top, ThreadLocalAllocBuffer::alignment_reserve_in_bytes(), top); | |
3427 st_ptr(top, G2_thread, in_bytes(JavaThread::tlab_end_offset())); | |
3428 verify_tlab(); | |
3429 ba_short(retry); | |
3430 } | |
3431 | |
3432 void MacroAssembler::incr_allocated_bytes(RegisterOrConstant size_in_bytes, | |
3433 Register t1, Register t2) { | |
3434 // Bump total bytes allocated by this thread | |
3435 assert(t1->is_global(), "must be global reg"); // so all 64 bits are saved on a context switch | |
3436 assert_different_registers(size_in_bytes.register_or_noreg(), t1, t2); | |
3437 // v8 support has gone the way of the dodo | |
3438 ldx(G2_thread, in_bytes(JavaThread::allocated_bytes_offset()), t1); | |
3439 add(t1, ensure_simm13_or_reg(size_in_bytes, t2), t1); | |
3440 stx(t1, G2_thread, in_bytes(JavaThread::allocated_bytes_offset())); | |
3441 } | |
3442 | |
3443 Assembler::Condition MacroAssembler::negate_condition(Assembler::Condition cond) { | |
3444 switch (cond) { | |
3445 // Note some conditions are synonyms for others | |
3446 case Assembler::never: return Assembler::always; | |
3447 case Assembler::zero: return Assembler::notZero; | |
3448 case Assembler::lessEqual: return Assembler::greater; | |
3449 case Assembler::less: return Assembler::greaterEqual; | |
3450 case Assembler::lessEqualUnsigned: return Assembler::greaterUnsigned; | |
3451 case Assembler::lessUnsigned: return Assembler::greaterEqualUnsigned; | |
3452 case Assembler::negative: return Assembler::positive; | |
3453 case Assembler::overflowSet: return Assembler::overflowClear; | |
3454 case Assembler::always: return Assembler::never; | |
3455 case Assembler::notZero: return Assembler::zero; | |
3456 case Assembler::greater: return Assembler::lessEqual; | |
3457 case Assembler::greaterEqual: return Assembler::less; | |
3458 case Assembler::greaterUnsigned: return Assembler::lessEqualUnsigned; | |
3459 case Assembler::greaterEqualUnsigned: return Assembler::lessUnsigned; | |
3460 case Assembler::positive: return Assembler::negative; | |
3461 case Assembler::overflowClear: return Assembler::overflowSet; | |
3462 } | |
3463 | |
3464 ShouldNotReachHere(); return Assembler::overflowClear; | |
3465 } | |
3466 | |
3467 void MacroAssembler::cond_inc(Assembler::Condition cond, address counter_ptr, | |
3468 Register Rtmp1, Register Rtmp2 /*, Register Rtmp3, Register Rtmp4 */) { | |
3469 Condition negated_cond = negate_condition(cond); | |
3470 Label L; | |
3471 brx(negated_cond, false, Assembler::pt, L); | |
3472 delayed()->nop(); | |
3473 inc_counter(counter_ptr, Rtmp1, Rtmp2); | |
3474 bind(L); | |
3475 } | |
3476 | |
3477 void MacroAssembler::inc_counter(address counter_addr, Register Rtmp1, Register Rtmp2) { | |
3478 AddressLiteral addrlit(counter_addr); | |
3479 sethi(addrlit, Rtmp1); // Move hi22 bits into temporary register. | |
3480 Address addr(Rtmp1, addrlit.low10()); // Build an address with low10 bits. | |
3481 ld(addr, Rtmp2); | |
3482 inc(Rtmp2); | |
3483 st(Rtmp2, addr); | |
3484 } | |
3485 | |
3486 void MacroAssembler::inc_counter(int* counter_addr, Register Rtmp1, Register Rtmp2) { | |
3487 inc_counter((address) counter_addr, Rtmp1, Rtmp2); | |
3488 } | |
3489 | |
3490 SkipIfEqual::SkipIfEqual( | |
3491 MacroAssembler* masm, Register temp, const bool* flag_addr, | |
3492 Assembler::Condition condition) { | |
3493 _masm = masm; | |
3494 AddressLiteral flag(flag_addr); | |
3495 _masm->sethi(flag, temp); | |
3496 _masm->ldub(temp, flag.low10(), temp); | |
3497 _masm->tst(temp); | |
3498 _masm->br(condition, false, Assembler::pt, _label); | |
3499 _masm->delayed()->nop(); | |
3500 } | |
3501 | |
3502 SkipIfEqual::~SkipIfEqual() { | |
3503 _masm->bind(_label); | |
3504 } | |
3505 | |
3506 | |
3507 // Writes to stack successive pages until offset reached to check for | |
3508 // stack overflow + shadow pages. This clobbers tsp and scratch. | |
3509 void MacroAssembler::bang_stack_size(Register Rsize, Register Rtsp, | |
3510 Register Rscratch) { | |
3511 // Use stack pointer in temp stack pointer | |
3512 mov(SP, Rtsp); | |
3513 | |
3514 // Bang stack for total size given plus stack shadow page size. | |
3515 // Bang one page at a time because a large size can overflow yellow and | |
3516 // red zones (the bang will fail but stack overflow handling can't tell that | |
3517 // it was a stack overflow bang vs a regular segv). | |
3518 int offset = os::vm_page_size(); | |
3519 Register Roffset = Rscratch; | |
3520 | |
3521 Label loop; | |
3522 bind(loop); | |
3523 set((-offset)+STACK_BIAS, Rscratch); | |
3524 st(G0, Rtsp, Rscratch); | |
3525 set(offset, Roffset); | |
3526 sub(Rsize, Roffset, Rsize); | |
3527 cmp(Rsize, G0); | |
3528 br(Assembler::greater, false, Assembler::pn, loop); | |
3529 delayed()->sub(Rtsp, Roffset, Rtsp); | |
3530 | |
3531 // Bang down shadow pages too. | |
3532 // The -1 because we already subtracted 1 page. | |
3533 for (int i = 0; i< StackShadowPages-1; i++) { | |
3534 set((-i*offset)+STACK_BIAS, Rscratch); | |
3535 st(G0, Rtsp, Rscratch); | |
3536 } | |
3537 } | |
3538 | |
3539 /////////////////////////////////////////////////////////////////////////////////// | |
8001
db9981fd3124
8005915: Unify SERIALGC and INCLUDE_ALTERNATE_GCS
jprovino
parents:
7476
diff
changeset
|
3540 #if INCLUDE_ALL_GCS |
7204 | 3541 |
3542 static address satb_log_enqueue_with_frame = NULL; | |
3543 static u_char* satb_log_enqueue_with_frame_end = NULL; | |
3544 | |
3545 static address satb_log_enqueue_frameless = NULL; | |
3546 static u_char* satb_log_enqueue_frameless_end = NULL; | |
3547 | |
3548 static int EnqueueCodeSize = 128 DEBUG_ONLY( + 256); // Instructions? | |
3549 | |
3550 static void generate_satb_log_enqueue(bool with_frame) { | |
3551 BufferBlob* bb = BufferBlob::create("enqueue_with_frame", EnqueueCodeSize); | |
3552 CodeBuffer buf(bb); | |
3553 MacroAssembler masm(&buf); | |
3554 | |
3555 #define __ masm. | |
3556 | |
3557 address start = __ pc(); | |
3558 Register pre_val; | |
3559 | |
3560 Label refill, restart; | |
3561 if (with_frame) { | |
3562 __ save_frame(0); | |
3563 pre_val = I0; // Was O0 before the save. | |
3564 } else { | |
3565 pre_val = O0; | |
3566 } | |
3567 | |
3568 int satb_q_index_byte_offset = | |
3569 in_bytes(JavaThread::satb_mark_queue_offset() + | |
3570 PtrQueue::byte_offset_of_index()); | |
3571 | |
3572 int satb_q_buf_byte_offset = | |
3573 in_bytes(JavaThread::satb_mark_queue_offset() + | |
3574 PtrQueue::byte_offset_of_buf()); | |
3575 | |
3576 assert(in_bytes(PtrQueue::byte_width_of_index()) == sizeof(intptr_t) && | |
3577 in_bytes(PtrQueue::byte_width_of_buf()) == sizeof(intptr_t), | |
3578 "check sizes in assembly below"); | |
3579 | |
3580 __ bind(restart); | |
3581 | |
3582 // Load the index into the SATB buffer. PtrQueue::_index is a size_t | |
3583 // so ld_ptr is appropriate. | |
3584 __ ld_ptr(G2_thread, satb_q_index_byte_offset, L0); | |
3585 | |
3586 // index == 0? | |
3587 __ cmp_and_brx_short(L0, G0, Assembler::equal, Assembler::pn, refill); | |
3588 | |
3589 __ ld_ptr(G2_thread, satb_q_buf_byte_offset, L1); | |
3590 __ sub(L0, oopSize, L0); | |
3591 | |
3592 __ st_ptr(pre_val, L1, L0); // [_buf + index] := I0 | |
3593 if (!with_frame) { | |
3594 // Use return-from-leaf | |
3595 __ retl(); | |
3596 __ delayed()->st_ptr(L0, G2_thread, satb_q_index_byte_offset); | |
3597 } else { | |
3598 // Not delayed. | |
3599 __ st_ptr(L0, G2_thread, satb_q_index_byte_offset); | |
3600 } | |
3601 if (with_frame) { | |
3602 __ ret(); | |
3603 __ delayed()->restore(); | |
3604 } | |
3605 __ bind(refill); | |
3606 | |
3607 address handle_zero = | |
3608 CAST_FROM_FN_PTR(address, | |
3609 &SATBMarkQueueSet::handle_zero_index_for_thread); | |
3610 // This should be rare enough that we can afford to save all the | |
3611 // scratch registers that the calling context might be using. | |
3612 __ mov(G1_scratch, L0); | |
3613 __ mov(G3_scratch, L1); | |
3614 __ mov(G4, L2); | |
3615 // We need the value of O0 above (for the write into the buffer), so we | |
3616 // save and restore it. | |
3617 __ mov(O0, L3); | |
3618 // Since the call will overwrite O7, we save and restore that, as well. | |
3619 __ mov(O7, L4); | |
3620 __ call_VM_leaf(L5, handle_zero, G2_thread); | |
3621 __ mov(L0, G1_scratch); | |
3622 __ mov(L1, G3_scratch); | |
3623 __ mov(L2, G4); | |
3624 __ mov(L3, O0); | |
3625 __ br(Assembler::always, /*annul*/false, Assembler::pt, restart); | |
3626 __ delayed()->mov(L4, O7); | |
3627 | |
3628 if (with_frame) { | |
3629 satb_log_enqueue_with_frame = start; | |
3630 satb_log_enqueue_with_frame_end = __ pc(); | |
3631 } else { | |
3632 satb_log_enqueue_frameless = start; | |
3633 satb_log_enqueue_frameless_end = __ pc(); | |
3634 } | |
3635 | |
3636 #undef __ | |
3637 } | |
3638 | |
3639 static inline void generate_satb_log_enqueue_if_necessary(bool with_frame) { | |
3640 if (with_frame) { | |
3641 if (satb_log_enqueue_with_frame == 0) { | |
3642 generate_satb_log_enqueue(with_frame); | |
3643 assert(satb_log_enqueue_with_frame != 0, "postcondition."); | |
3644 if (G1SATBPrintStubs) { | |
3645 tty->print_cr("Generated with-frame satb enqueue:"); | |
3646 Disassembler::decode((u_char*)satb_log_enqueue_with_frame, | |
3647 satb_log_enqueue_with_frame_end, | |
3648 tty); | |
3649 } | |
3650 } | |
3651 } else { | |
3652 if (satb_log_enqueue_frameless == 0) { | |
3653 generate_satb_log_enqueue(with_frame); | |
3654 assert(satb_log_enqueue_frameless != 0, "postcondition."); | |
3655 if (G1SATBPrintStubs) { | |
3656 tty->print_cr("Generated frameless satb enqueue:"); | |
3657 Disassembler::decode((u_char*)satb_log_enqueue_frameless, | |
3658 satb_log_enqueue_frameless_end, | |
3659 tty); | |
3660 } | |
3661 } | |
3662 } | |
3663 } | |
3664 | |
3665 void MacroAssembler::g1_write_barrier_pre(Register obj, | |
3666 Register index, | |
3667 int offset, | |
3668 Register pre_val, | |
3669 Register tmp, | |
3670 bool preserve_o_regs) { | |
3671 Label filtered; | |
3672 | |
3673 if (obj == noreg) { | |
3674 // We are not loading the previous value so make | |
3675 // sure that we don't trash the value in pre_val | |
3676 // with the code below. | |
3677 assert_different_registers(pre_val, tmp); | |
3678 } else { | |
3679 // We will be loading the previous value | |
3680 // in this code so... | |
3681 assert(offset == 0 || index == noreg, "choose one"); | |
3682 assert(pre_val == noreg, "check this code"); | |
3683 } | |
3684 | |
3685 // Is marking active? | |
3686 if (in_bytes(PtrQueue::byte_width_of_active()) == 4) { | |
3687 ld(G2, | |
3688 in_bytes(JavaThread::satb_mark_queue_offset() + | |
3689 PtrQueue::byte_offset_of_active()), | |
3690 tmp); | |
3691 } else { | |
3692 guarantee(in_bytes(PtrQueue::byte_width_of_active()) == 1, | |
3693 "Assumption"); | |
3694 ldsb(G2, | |
3695 in_bytes(JavaThread::satb_mark_queue_offset() + | |
3696 PtrQueue::byte_offset_of_active()), | |
3697 tmp); | |
3698 } | |
3699 | |
3700 // Is marking active? | |
3701 cmp_and_br_short(tmp, G0, Assembler::equal, Assembler::pt, filtered); | |
3702 | |
3703 // Do we need to load the previous value? | |
3704 if (obj != noreg) { | |
3705 // Load the previous value... | |
3706 if (index == noreg) { | |
3707 if (Assembler::is_simm13(offset)) { | |
3708 load_heap_oop(obj, offset, tmp); | |
3709 } else { | |
3710 set(offset, tmp); | |
3711 load_heap_oop(obj, tmp, tmp); | |
3712 } | |
3713 } else { | |
3714 load_heap_oop(obj, index, tmp); | |
3715 } | |
3716 // Previous value has been loaded into tmp | |
3717 pre_val = tmp; | |
3718 } | |
3719 | |
3720 assert(pre_val != noreg, "must have a real register"); | |
3721 | |
3722 // Is the previous value null? | |
3723 cmp_and_brx_short(pre_val, G0, Assembler::equal, Assembler::pt, filtered); | |
3724 | |
3725 // OK, it's not filtered, so we'll need to call enqueue. In the normal | |
3726 // case, pre_val will be a scratch G-reg, but there are some cases in | |
3727 // which it's an O-reg. In the first case, do a normal call. In the | |
3728 // latter, do a save here and call the frameless version. | |
3729 | |
3730 guarantee(pre_val->is_global() || pre_val->is_out(), | |
3731 "Or we need to think harder."); | |
3732 | |
3733 if (pre_val->is_global() && !preserve_o_regs) { | |
3734 generate_satb_log_enqueue_if_necessary(true); // with frame | |
3735 | |
3736 call(satb_log_enqueue_with_frame); | |
3737 delayed()->mov(pre_val, O0); | |
3738 } else { | |
3739 generate_satb_log_enqueue_if_necessary(false); // frameless | |
3740 | |
3741 save_frame(0); | |
3742 call(satb_log_enqueue_frameless); | |
3743 delayed()->mov(pre_val->after_save(), O0); | |
3744 restore(); | |
3745 } | |
3746 | |
3747 bind(filtered); | |
3748 } | |
3749 | |
3750 static address dirty_card_log_enqueue = 0; | |
3751 static u_char* dirty_card_log_enqueue_end = 0; | |
3752 | |
3753 // This gets to assume that o0 contains the object address. | |
3754 static void generate_dirty_card_log_enqueue(jbyte* byte_map_base) { | |
3755 BufferBlob* bb = BufferBlob::create("dirty_card_enqueue", EnqueueCodeSize*2); | |
3756 CodeBuffer buf(bb); | |
3757 MacroAssembler masm(&buf); | |
3758 #define __ masm. | |
3759 address start = __ pc(); | |
3760 | |
3761 Label not_already_dirty, restart, refill; | |
3762 | |
3763 #ifdef _LP64 | |
3764 __ srlx(O0, CardTableModRefBS::card_shift, O0); | |
3765 #else | |
3766 __ srl(O0, CardTableModRefBS::card_shift, O0); | |
3767 #endif | |
3768 AddressLiteral addrlit(byte_map_base); | |
3769 __ set(addrlit, O1); // O1 := <card table base> | |
3770 __ ldub(O0, O1, O2); // O2 := [O0 + O1] | |
3771 | |
3772 assert(CardTableModRefBS::dirty_card_val() == 0, "otherwise check this code"); | |
3773 __ cmp_and_br_short(O2, G0, Assembler::notEqual, Assembler::pt, not_already_dirty); | |
3774 | |
3775 // We didn't take the branch, so we're already dirty: return. | |
3776 // Use return-from-leaf | |
3777 __ retl(); | |
3778 __ delayed()->nop(); | |
3779 | |
3780 // Not dirty. | |
3781 __ bind(not_already_dirty); | |
3782 | |
3783 // Get O0 + O1 into a reg by itself | |
3784 __ add(O0, O1, O3); | |
3785 | |
3786 // First, dirty it. | |
3787 __ stb(G0, O3, G0); // [cardPtr] := 0 (i.e., dirty). | |
3788 | |
3789 int dirty_card_q_index_byte_offset = | |
3790 in_bytes(JavaThread::dirty_card_queue_offset() + | |
3791 PtrQueue::byte_offset_of_index()); | |
3792 int dirty_card_q_buf_byte_offset = | |
3793 in_bytes(JavaThread::dirty_card_queue_offset() + | |
3794 PtrQueue::byte_offset_of_buf()); | |
3795 __ bind(restart); | |
3796 | |
3797 // Load the index into the update buffer. PtrQueue::_index is | |
3798 // a size_t so ld_ptr is appropriate here. | |
3799 __ ld_ptr(G2_thread, dirty_card_q_index_byte_offset, L0); | |
3800 | |
3801 // index == 0? | |
3802 __ cmp_and_brx_short(L0, G0, Assembler::equal, Assembler::pn, refill); | |
3803 | |
3804 __ ld_ptr(G2_thread, dirty_card_q_buf_byte_offset, L1); | |
3805 __ sub(L0, oopSize, L0); | |
3806 | |
3807 __ st_ptr(O3, L1, L0); // [_buf + index] := I0 | |
3808 // Use return-from-leaf | |
3809 __ retl(); | |
3810 __ delayed()->st_ptr(L0, G2_thread, dirty_card_q_index_byte_offset); | |
3811 | |
3812 __ bind(refill); | |
3813 address handle_zero = | |
3814 CAST_FROM_FN_PTR(address, | |
3815 &DirtyCardQueueSet::handle_zero_index_for_thread); | |
3816 // This should be rare enough that we can afford to save all the | |
3817 // scratch registers that the calling context might be using. | |
3818 __ mov(G1_scratch, L3); | |
3819 __ mov(G3_scratch, L5); | |
3820 // We need the value of O3 above (for the write into the buffer), so we | |
3821 // save and restore it. | |
3822 __ mov(O3, L6); | |
3823 // Since the call will overwrite O7, we save and restore that, as well. | |
3824 __ mov(O7, L4); | |
3825 | |
3826 __ call_VM_leaf(L7_thread_cache, handle_zero, G2_thread); | |
3827 __ mov(L3, G1_scratch); | |
3828 __ mov(L5, G3_scratch); | |
3829 __ mov(L6, O3); | |
3830 __ br(Assembler::always, /*annul*/false, Assembler::pt, restart); | |
3831 __ delayed()->mov(L4, O7); | |
3832 | |
3833 dirty_card_log_enqueue = start; | |
3834 dirty_card_log_enqueue_end = __ pc(); | |
3835 // XXX Should have a guarantee here about not going off the end! | |
3836 // Does it already do so? Do an experiment... | |
3837 | |
3838 #undef __ | |
3839 | |
3840 } | |
3841 | |
3842 static inline void | |
3843 generate_dirty_card_log_enqueue_if_necessary(jbyte* byte_map_base) { | |
3844 if (dirty_card_log_enqueue == 0) { | |
3845 generate_dirty_card_log_enqueue(byte_map_base); | |
3846 assert(dirty_card_log_enqueue != 0, "postcondition."); | |
3847 if (G1SATBPrintStubs) { | |
3848 tty->print_cr("Generated dirty_card enqueue:"); | |
3849 Disassembler::decode((u_char*)dirty_card_log_enqueue, | |
3850 dirty_card_log_enqueue_end, | |
3851 tty); | |
3852 } | |
3853 } | |
3854 } | |
3855 | |
3856 | |
3857 void MacroAssembler::g1_write_barrier_post(Register store_addr, Register new_val, Register tmp) { | |
3858 | |
3859 Label filtered; | |
3860 MacroAssembler* post_filter_masm = this; | |
3861 | |
3862 if (new_val == G0) return; | |
3863 | |
3864 G1SATBCardTableModRefBS* bs = (G1SATBCardTableModRefBS*) Universe::heap()->barrier_set(); | |
3865 assert(bs->kind() == BarrierSet::G1SATBCT || | |
3866 bs->kind() == BarrierSet::G1SATBCTLogging, "wrong barrier"); | |
3867 | |
3868 if (G1RSBarrierRegionFilter) { | |
3869 xor3(store_addr, new_val, tmp); | |
3870 #ifdef _LP64 | |
3871 srlx(tmp, HeapRegion::LogOfHRGrainBytes, tmp); | |
3872 #else | |
3873 srl(tmp, HeapRegion::LogOfHRGrainBytes, tmp); | |
3874 #endif | |
3875 | |
3876 // XXX Should I predict this taken or not? Does it matter? | |
3877 cmp_and_brx_short(tmp, G0, Assembler::equal, Assembler::pt, filtered); | |
3878 } | |
3879 | |
3880 // If the "store_addr" register is an "in" or "local" register, move it to | |
3881 // a scratch reg so we can pass it as an argument. | |
3882 bool use_scr = !(store_addr->is_global() || store_addr->is_out()); | |
3883 // Pick a scratch register different from "tmp". | |
3884 Register scr = (tmp == G1_scratch ? G3_scratch : G1_scratch); | |
3885 // Make sure we use up the delay slot! | |
3886 if (use_scr) { | |
3887 post_filter_masm->mov(store_addr, scr); | |
3888 } else { | |
3889 post_filter_masm->nop(); | |
3890 } | |
3891 generate_dirty_card_log_enqueue_if_necessary(bs->byte_map_base); | |
3892 save_frame(0); | |
3893 call(dirty_card_log_enqueue); | |
3894 if (use_scr) { | |
3895 delayed()->mov(scr, O0); | |
3896 } else { | |
3897 delayed()->mov(store_addr->after_save(), O0); | |
3898 } | |
3899 restore(); | |
3900 | |
3901 bind(filtered); | |
3902 } | |
3903 | |
8001
db9981fd3124
8005915: Unify SERIALGC and INCLUDE_ALTERNATE_GCS
jprovino
parents:
7476
diff
changeset
|
3904 #endif // INCLUDE_ALL_GCS |
7204 | 3905 /////////////////////////////////////////////////////////////////////////////////// |
3906 | |
3907 void MacroAssembler::card_write_barrier_post(Register store_addr, Register new_val, Register tmp) { | |
3908 // If we're writing constant NULL, we can skip the write barrier. | |
3909 if (new_val == G0) return; | |
3910 CardTableModRefBS* bs = (CardTableModRefBS*) Universe::heap()->barrier_set(); | |
3911 assert(bs->kind() == BarrierSet::CardTableModRef || | |
3912 bs->kind() == BarrierSet::CardTableExtension, "wrong barrier"); | |
3913 card_table_write(bs->byte_map_base, tmp, store_addr); | |
3914 } | |
3915 | |
3916 void MacroAssembler::load_klass(Register src_oop, Register klass) { | |
3917 // The number of bytes in this code is used by | |
3918 // MachCallDynamicJavaNode::ret_addr_offset() | |
3919 // if this changes, change that. | |
3920 if (UseCompressedKlassPointers) { | |
3921 lduw(src_oop, oopDesc::klass_offset_in_bytes(), klass); | |
3922 decode_klass_not_null(klass); | |
3923 } else { | |
3924 ld_ptr(src_oop, oopDesc::klass_offset_in_bytes(), klass); | |
3925 } | |
3926 } | |
3927 | |
3928 void MacroAssembler::store_klass(Register klass, Register dst_oop) { | |
3929 if (UseCompressedKlassPointers) { | |
3930 assert(dst_oop != klass, "not enough registers"); | |
3931 encode_klass_not_null(klass); | |
3932 st(klass, dst_oop, oopDesc::klass_offset_in_bytes()); | |
3933 } else { | |
3934 st_ptr(klass, dst_oop, oopDesc::klass_offset_in_bytes()); | |
3935 } | |
3936 } | |
3937 | |
3938 void MacroAssembler::store_klass_gap(Register s, Register d) { | |
3939 if (UseCompressedKlassPointers) { | |
3940 assert(s != d, "not enough registers"); | |
3941 st(s, d, oopDesc::klass_gap_offset_in_bytes()); | |
3942 } | |
3943 } | |
3944 | |
3945 void MacroAssembler::load_heap_oop(const Address& s, Register d) { | |
3946 if (UseCompressedOops) { | |
3947 lduw(s, d); | |
3948 decode_heap_oop(d); | |
3949 } else { | |
3950 ld_ptr(s, d); | |
3951 } | |
3952 } | |
3953 | |
3954 void MacroAssembler::load_heap_oop(Register s1, Register s2, Register d) { | |
3955 if (UseCompressedOops) { | |
3956 lduw(s1, s2, d); | |
3957 decode_heap_oop(d, d); | |
3958 } else { | |
3959 ld_ptr(s1, s2, d); | |
3960 } | |
3961 } | |
3962 | |
3963 void MacroAssembler::load_heap_oop(Register s1, int simm13a, Register d) { | |
3964 if (UseCompressedOops) { | |
3965 lduw(s1, simm13a, d); | |
3966 decode_heap_oop(d, d); | |
3967 } else { | |
3968 ld_ptr(s1, simm13a, d); | |
3969 } | |
3970 } | |
3971 | |
3972 void MacroAssembler::load_heap_oop(Register s1, RegisterOrConstant s2, Register d) { | |
3973 if (s2.is_constant()) load_heap_oop(s1, s2.as_constant(), d); | |
3974 else load_heap_oop(s1, s2.as_register(), d); | |
3975 } | |
3976 | |
3977 void MacroAssembler::store_heap_oop(Register d, Register s1, Register s2) { | |
3978 if (UseCompressedOops) { | |
3979 assert(s1 != d && s2 != d, "not enough registers"); | |
3980 encode_heap_oop(d); | |
3981 st(d, s1, s2); | |
3982 } else { | |
3983 st_ptr(d, s1, s2); | |
3984 } | |
3985 } | |
3986 | |
3987 void MacroAssembler::store_heap_oop(Register d, Register s1, int simm13a) { | |
3988 if (UseCompressedOops) { | |
3989 assert(s1 != d, "not enough registers"); | |
3990 encode_heap_oop(d); | |
3991 st(d, s1, simm13a); | |
3992 } else { | |
3993 st_ptr(d, s1, simm13a); | |
3994 } | |
3995 } | |
3996 | |
3997 void MacroAssembler::store_heap_oop(Register d, const Address& a, int offset) { | |
3998 if (UseCompressedOops) { | |
3999 assert(a.base() != d, "not enough registers"); | |
4000 encode_heap_oop(d); | |
4001 st(d, a, offset); | |
4002 } else { | |
4003 st_ptr(d, a, offset); | |
4004 } | |
4005 } | |
4006 | |
4007 | |
4008 void MacroAssembler::encode_heap_oop(Register src, Register dst) { | |
4009 assert (UseCompressedOops, "must be compressed"); | |
4010 assert (Universe::heap() != NULL, "java heap should be initialized"); | |
4011 assert (LogMinObjAlignmentInBytes == Universe::narrow_oop_shift(), "decode alg wrong"); | |
4012 verify_oop(src); | |
4013 if (Universe::narrow_oop_base() == NULL) { | |
4014 srlx(src, LogMinObjAlignmentInBytes, dst); | |
4015 return; | |
4016 } | |
4017 Label done; | |
4018 if (src == dst) { | |
4019 // optimize for frequent case src == dst | |
4020 bpr(rc_nz, true, Assembler::pt, src, done); | |
4021 delayed() -> sub(src, G6_heapbase, dst); // annuled if not taken | |
4022 bind(done); | |
4023 srlx(src, LogMinObjAlignmentInBytes, dst); | |
4024 } else { | |
4025 bpr(rc_z, false, Assembler::pn, src, done); | |
4026 delayed() -> mov(G0, dst); | |
4027 // could be moved before branch, and annulate delay, | |
4028 // but may add some unneeded work decoding null | |
4029 sub(src, G6_heapbase, dst); | |
4030 srlx(dst, LogMinObjAlignmentInBytes, dst); | |
4031 bind(done); | |
4032 } | |
4033 } | |
4034 | |
4035 | |
4036 void MacroAssembler::encode_heap_oop_not_null(Register r) { | |
4037 assert (UseCompressedOops, "must be compressed"); | |
4038 assert (Universe::heap() != NULL, "java heap should be initialized"); | |
4039 assert (LogMinObjAlignmentInBytes == Universe::narrow_oop_shift(), "decode alg wrong"); | |
4040 verify_oop(r); | |
4041 if (Universe::narrow_oop_base() != NULL) | |
4042 sub(r, G6_heapbase, r); | |
4043 srlx(r, LogMinObjAlignmentInBytes, r); | |
4044 } | |
4045 | |
4046 void MacroAssembler::encode_heap_oop_not_null(Register src, Register dst) { | |
4047 assert (UseCompressedOops, "must be compressed"); | |
4048 assert (Universe::heap() != NULL, "java heap should be initialized"); | |
4049 assert (LogMinObjAlignmentInBytes == Universe::narrow_oop_shift(), "decode alg wrong"); | |
4050 verify_oop(src); | |
4051 if (Universe::narrow_oop_base() == NULL) { | |
4052 srlx(src, LogMinObjAlignmentInBytes, dst); | |
4053 } else { | |
4054 sub(src, G6_heapbase, dst); | |
4055 srlx(dst, LogMinObjAlignmentInBytes, dst); | |
4056 } | |
4057 } | |
4058 | |
4059 // Same algorithm as oops.inline.hpp decode_heap_oop. | |
4060 void MacroAssembler::decode_heap_oop(Register src, Register dst) { | |
4061 assert (UseCompressedOops, "must be compressed"); | |
4062 assert (Universe::heap() != NULL, "java heap should be initialized"); | |
4063 assert (LogMinObjAlignmentInBytes == Universe::narrow_oop_shift(), "decode alg wrong"); | |
4064 sllx(src, LogMinObjAlignmentInBytes, dst); | |
4065 if (Universe::narrow_oop_base() != NULL) { | |
4066 Label done; | |
4067 bpr(rc_nz, true, Assembler::pt, dst, done); | |
4068 delayed() -> add(dst, G6_heapbase, dst); // annuled if not taken | |
4069 bind(done); | |
4070 } | |
4071 verify_oop(dst); | |
4072 } | |
4073 | |
4074 void MacroAssembler::decode_heap_oop_not_null(Register r) { | |
4075 // Do not add assert code to this unless you change vtableStubs_sparc.cpp | |
4076 // pd_code_size_limit. | |
4077 // Also do not verify_oop as this is called by verify_oop. | |
4078 assert (UseCompressedOops, "must be compressed"); | |
4079 assert (Universe::heap() != NULL, "java heap should be initialized"); | |
4080 assert (LogMinObjAlignmentInBytes == Universe::narrow_oop_shift(), "decode alg wrong"); | |
4081 sllx(r, LogMinObjAlignmentInBytes, r); | |
4082 if (Universe::narrow_oop_base() != NULL) | |
4083 add(r, G6_heapbase, r); | |
4084 } | |
4085 | |
4086 void MacroAssembler::decode_heap_oop_not_null(Register src, Register dst) { | |
4087 // Do not add assert code to this unless you change vtableStubs_sparc.cpp | |
4088 // pd_code_size_limit. | |
4089 // Also do not verify_oop as this is called by verify_oop. | |
4090 assert (UseCompressedOops, "must be compressed"); | |
4091 assert (LogMinObjAlignmentInBytes == Universe::narrow_oop_shift(), "decode alg wrong"); | |
4092 sllx(src, LogMinObjAlignmentInBytes, dst); | |
4093 if (Universe::narrow_oop_base() != NULL) | |
4094 add(dst, G6_heapbase, dst); | |
4095 } | |
4096 | |
4097 void MacroAssembler::encode_klass_not_null(Register r) { | |
4098 assert(Metaspace::is_initialized(), "metaspace should be initialized"); | |
4099 assert (UseCompressedKlassPointers, "must be compressed"); | |
4100 assert (LogKlassAlignmentInBytes == Universe::narrow_klass_shift(), "decode alg wrong"); | |
4101 if (Universe::narrow_klass_base() != NULL) | |
4102 sub(r, G6_heapbase, r); | |
4103 srlx(r, LogKlassAlignmentInBytes, r); | |
4104 } | |
4105 | |
4106 void MacroAssembler::encode_klass_not_null(Register src, Register dst) { | |
4107 assert(Metaspace::is_initialized(), "metaspace should be initialized"); | |
4108 assert (UseCompressedKlassPointers, "must be compressed"); | |
4109 assert (LogKlassAlignmentInBytes == Universe::narrow_klass_shift(), "decode alg wrong"); | |
4110 if (Universe::narrow_klass_base() == NULL) { | |
4111 srlx(src, LogKlassAlignmentInBytes, dst); | |
4112 } else { | |
4113 sub(src, G6_heapbase, dst); | |
4114 srlx(dst, LogKlassAlignmentInBytes, dst); | |
4115 } | |
4116 } | |
4117 | |
4118 void MacroAssembler::decode_klass_not_null(Register r) { | |
4119 assert(Metaspace::is_initialized(), "metaspace should be initialized"); | |
4120 // Do not add assert code to this unless you change vtableStubs_sparc.cpp | |
4121 // pd_code_size_limit. | |
4122 assert (UseCompressedKlassPointers, "must be compressed"); | |
4123 assert (LogKlassAlignmentInBytes == Universe::narrow_klass_shift(), "decode alg wrong"); | |
4124 sllx(r, LogKlassAlignmentInBytes, r); | |
4125 if (Universe::narrow_klass_base() != NULL) | |
4126 add(r, G6_heapbase, r); | |
4127 } | |
4128 | |
4129 void MacroAssembler::decode_klass_not_null(Register src, Register dst) { | |
4130 assert(Metaspace::is_initialized(), "metaspace should be initialized"); | |
4131 // Do not add assert code to this unless you change vtableStubs_sparc.cpp | |
4132 // pd_code_size_limit. | |
4133 assert (UseCompressedKlassPointers, "must be compressed"); | |
4134 assert (LogKlassAlignmentInBytes == Universe::narrow_klass_shift(), "decode alg wrong"); | |
4135 sllx(src, LogKlassAlignmentInBytes, dst); | |
4136 if (Universe::narrow_klass_base() != NULL) | |
4137 add(dst, G6_heapbase, dst); | |
4138 } | |
4139 | |
4140 void MacroAssembler::reinit_heapbase() { | |
4141 if (UseCompressedOops || UseCompressedKlassPointers) { | |
4142 AddressLiteral base(Universe::narrow_ptrs_base_addr()); | |
4143 load_ptr_contents(base, G6_heapbase); | |
4144 } | |
4145 } | |
4146 | |
4147 // Compare char[] arrays aligned to 4 bytes. | |
4148 void MacroAssembler::char_arrays_equals(Register ary1, Register ary2, | |
4149 Register limit, Register result, | |
4150 Register chr1, Register chr2, Label& Ldone) { | |
4151 Label Lvector, Lloop; | |
4152 assert(chr1 == result, "should be the same"); | |
4153 | |
4154 // Note: limit contains number of bytes (2*char_elements) != 0. | |
4155 andcc(limit, 0x2, chr1); // trailing character ? | |
4156 br(Assembler::zero, false, Assembler::pt, Lvector); | |
4157 delayed()->nop(); | |
4158 | |
4159 // compare the trailing char | |
4160 sub(limit, sizeof(jchar), limit); | |
4161 lduh(ary1, limit, chr1); | |
4162 lduh(ary2, limit, chr2); | |
4163 cmp(chr1, chr2); | |
4164 br(Assembler::notEqual, true, Assembler::pt, Ldone); | |
4165 delayed()->mov(G0, result); // not equal | |
4166 | |
4167 // only one char ? | |
4168 cmp_zero_and_br(zero, limit, Ldone, true, Assembler::pn); | |
4169 delayed()->add(G0, 1, result); // zero-length arrays are equal | |
4170 | |
4171 // word by word compare, dont't need alignment check | |
4172 bind(Lvector); | |
4173 // Shift ary1 and ary2 to the end of the arrays, negate limit | |
4174 add(ary1, limit, ary1); | |
4175 add(ary2, limit, ary2); | |
4176 neg(limit, limit); | |
4177 | |
4178 lduw(ary1, limit, chr1); | |
4179 bind(Lloop); | |
4180 lduw(ary2, limit, chr2); | |
4181 cmp(chr1, chr2); | |
4182 br(Assembler::notEqual, true, Assembler::pt, Ldone); | |
4183 delayed()->mov(G0, result); // not equal | |
4184 inccc(limit, 2*sizeof(jchar)); | |
4185 // annul LDUW if branch is not taken to prevent access past end of array | |
4186 br(Assembler::notZero, true, Assembler::pt, Lloop); | |
4187 delayed()->lduw(ary1, limit, chr1); // hoisted | |
4188 | |
4189 // Caller should set it: | |
4190 // add(G0, 1, result); // equals | |
4191 } | |
4192 | |
4193 // Use BIS for zeroing (count is in bytes). | |
4194 void MacroAssembler::bis_zeroing(Register to, Register count, Register temp, Label& Ldone) { | |
4195 assert(UseBlockZeroing && VM_Version::has_block_zeroing(), "only works with BIS zeroing"); | |
4196 Register end = count; | |
4197 int cache_line_size = VM_Version::prefetch_data_size(); | |
4198 // Minimum count when BIS zeroing can be used since | |
4199 // it needs membar which is expensive. | |
4200 int block_zero_size = MAX2(cache_line_size*3, (int)BlockZeroingLowLimit); | |
4201 | |
4202 Label small_loop; | |
4203 // Check if count is negative (dead code) or zero. | |
4204 // Note, count uses 64bit in 64 bit VM. | |
4205 cmp_and_brx_short(count, 0, Assembler::lessEqual, Assembler::pn, Ldone); | |
4206 | |
4207 // Use BIS zeroing only for big arrays since it requires membar. | |
4208 if (Assembler::is_simm13(block_zero_size)) { // < 4096 | |
4209 cmp(count, block_zero_size); | |
4210 } else { | |
4211 set(block_zero_size, temp); | |
4212 cmp(count, temp); | |
4213 } | |
4214 br(Assembler::lessUnsigned, false, Assembler::pt, small_loop); | |
4215 delayed()->add(to, count, end); | |
4216 | |
4217 // Note: size is >= three (32 bytes) cache lines. | |
4218 | |
4219 // Clean the beginning of space up to next cache line. | |
4220 for (int offs = 0; offs < cache_line_size; offs += 8) { | |
4221 stx(G0, to, offs); | |
4222 } | |
4223 | |
4224 // align to next cache line | |
4225 add(to, cache_line_size, to); | |
4226 and3(to, -cache_line_size, to); | |
4227 | |
4228 // Note: size left >= two (32 bytes) cache lines. | |
4229 | |
4230 // BIS should not be used to zero tail (64 bytes) | |
4231 // to avoid zeroing a header of the following object. | |
4232 sub(end, (cache_line_size*2)-8, end); | |
4233 | |
4234 Label bis_loop; | |
4235 bind(bis_loop); | |
4236 stxa(G0, to, G0, Assembler::ASI_ST_BLKINIT_PRIMARY); | |
4237 add(to, cache_line_size, to); | |
4238 cmp_and_brx_short(to, end, Assembler::lessUnsigned, Assembler::pt, bis_loop); | |
4239 | |
4240 // BIS needs membar. | |
4241 membar(Assembler::StoreLoad); | |
4242 | |
4243 add(end, (cache_line_size*2)-8, end); // restore end | |
4244 cmp_and_brx_short(to, end, Assembler::greaterEqualUnsigned, Assembler::pn, Ldone); | |
4245 | |
4246 // Clean the tail. | |
4247 bind(small_loop); | |
4248 stx(G0, to, 0); | |
4249 add(to, 8, to); | |
4250 cmp_and_brx_short(to, end, Assembler::lessUnsigned, Assembler::pt, small_loop); | |
4251 nop(); // Separate short branches | |
4252 } |