annotate src/cpu/sparc/vm/c1_MacroAssembler_sparc.cpp @ 2451:d86923d96dca

7034967: C1: assert(false) failed: error (assembler_sparc.cpp:2043) Summary: Fix -XX:+VerifyOops Reviewed-by: kvn, never
author iveresov
date Fri, 08 Apr 2011 17:03:31 -0700
parents 5577848f5923
children 6c97c830fb6f
rev   line source
duke@0 1 /*
iveresov@2451 2 * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
duke@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@0 4 *
duke@0 5 * This code is free software; you can redistribute it and/or modify it
duke@0 6 * under the terms of the GNU General Public License version 2 only, as
duke@0 7 * published by the Free Software Foundation.
duke@0 8 *
duke@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@0 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@0 13 * accompanied this code).
duke@0 14 *
duke@0 15 * You should have received a copy of the GNU General Public License version
duke@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@0 18 *
trims@1563 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1563 20 * or visit www.oracle.com if you need additional information or have any
trims@1563 21 * questions.
duke@0 22 *
duke@0 23 */
duke@0 24
stefank@1992 25 #include "precompiled.hpp"
stefank@1992 26 #include "c1/c1_MacroAssembler.hpp"
stefank@1992 27 #include "c1/c1_Runtime1.hpp"
stefank@1992 28 #include "classfile/systemDictionary.hpp"
stefank@1992 29 #include "gc_interface/collectedHeap.hpp"
stefank@1992 30 #include "interpreter/interpreter.hpp"
stefank@1992 31 #include "oops/arrayOop.hpp"
stefank@1992 32 #include "oops/markOop.hpp"
stefank@1992 33 #include "runtime/basicLock.hpp"
stefank@1992 34 #include "runtime/biasedLocking.hpp"
stefank@1992 35 #include "runtime/os.hpp"
stefank@1992 36 #include "runtime/stubRoutines.hpp"
duke@0 37
duke@0 38 void C1_MacroAssembler::inline_cache_check(Register receiver, Register iCache) {
duke@0 39 Label L;
duke@0 40 const Register temp_reg = G3_scratch;
duke@0 41 // Note: needs more testing of out-of-line vs. inline slow case
duke@0 42 verify_oop(receiver);
iveresov@2022 43 load_klass(receiver, temp_reg);
duke@0 44 cmp(temp_reg, iCache);
duke@0 45 brx(Assembler::equal, true, Assembler::pt, L);
duke@0 46 delayed()->nop();
twisti@765 47 AddressLiteral ic_miss(SharedRuntime::get_ic_miss_stub());
twisti@765 48 jump_to(ic_miss, temp_reg);
duke@0 49 delayed()->nop();
duke@0 50 align(CodeEntryAlignment);
duke@0 51 bind(L);
duke@0 52 }
duke@0 53
duke@0 54
duke@0 55 void C1_MacroAssembler::explicit_null_check(Register base) {
duke@0 56 Unimplemented();
duke@0 57 }
duke@0 58
duke@0 59
duke@0 60 void C1_MacroAssembler::build_frame(int frame_size_in_bytes) {
duke@0 61
duke@0 62 generate_stack_overflow_check(frame_size_in_bytes);
duke@0 63 // Create the frame.
duke@0 64 save_frame_c1(frame_size_in_bytes);
duke@0 65 }
duke@0 66
duke@0 67
duke@0 68 void C1_MacroAssembler::unverified_entry(Register receiver, Register ic_klass) {
duke@0 69 if (C1Breakpoint) breakpoint_trap();
duke@0 70 inline_cache_check(receiver, ic_klass);
duke@0 71 }
duke@0 72
duke@0 73
duke@0 74 void C1_MacroAssembler::verified_entry() {
duke@0 75 if (C1Breakpoint) breakpoint_trap();
duke@0 76 // build frame
duke@0 77 verify_FPU(0, "method_entry");
duke@0 78 }
duke@0 79
duke@0 80
duke@0 81 void C1_MacroAssembler::lock_object(Register Rmark, Register Roop, Register Rbox, Register Rscratch, Label& slow_case) {
duke@0 82 assert_different_registers(Rmark, Roop, Rbox, Rscratch);
duke@0 83
duke@0 84 Label done;
duke@0 85
twisti@765 86 Address mark_addr(Roop, oopDesc::mark_offset_in_bytes());
duke@0 87
duke@0 88 // The following move must be the first instruction of emitted since debug
duke@0 89 // information may be generated for it.
duke@0 90 // Load object header
duke@0 91 ld_ptr(mark_addr, Rmark);
duke@0 92
duke@0 93 verify_oop(Roop);
duke@0 94
duke@0 95 // save object being locked into the BasicObjectLock
duke@0 96 st_ptr(Roop, Rbox, BasicObjectLock::obj_offset_in_bytes());
duke@0 97
duke@0 98 if (UseBiasedLocking) {
duke@0 99 biased_locking_enter(Roop, Rmark, Rscratch, done, &slow_case);
duke@0 100 }
duke@0 101
duke@0 102 // Save Rbox in Rscratch to be used for the cas operation
duke@0 103 mov(Rbox, Rscratch);
duke@0 104
duke@0 105 // and mark it unlocked
duke@0 106 or3(Rmark, markOopDesc::unlocked_value, Rmark);
duke@0 107
duke@0 108 // save unlocked object header into the displaced header location on the stack
duke@0 109 st_ptr(Rmark, Rbox, BasicLock::displaced_header_offset_in_bytes());
duke@0 110
duke@0 111 // compare object markOop with Rmark and if equal exchange Rscratch with object markOop
duke@0 112 assert(mark_addr.disp() == 0, "cas must take a zero displacement");
duke@0 113 casx_under_lock(mark_addr.base(), Rmark, Rscratch, (address)StubRoutines::Sparc::atomic_memory_operation_lock_addr());
duke@0 114 // if compare/exchange succeeded we found an unlocked object and we now have locked it
duke@0 115 // hence we are done
duke@0 116 cmp(Rmark, Rscratch);
duke@0 117 brx(Assembler::equal, false, Assembler::pt, done);
duke@0 118 delayed()->sub(Rscratch, SP, Rscratch); //pull next instruction into delay slot
duke@0 119 // we did not find an unlocked object so see if this is a recursive case
duke@0 120 // sub(Rscratch, SP, Rscratch);
duke@0 121 assert(os::vm_page_size() > 0xfff, "page size too small - change the constant");
duke@0 122 andcc(Rscratch, 0xfffff003, Rscratch);
duke@0 123 brx(Assembler::notZero, false, Assembler::pn, slow_case);
duke@0 124 delayed()->st_ptr(Rscratch, Rbox, BasicLock::displaced_header_offset_in_bytes());
duke@0 125 bind(done);
duke@0 126 }
duke@0 127
duke@0 128
duke@0 129 void C1_MacroAssembler::unlock_object(Register Rmark, Register Roop, Register Rbox, Label& slow_case) {
duke@0 130 assert_different_registers(Rmark, Roop, Rbox);
duke@0 131
duke@0 132 Label done;
duke@0 133
twisti@765 134 Address mark_addr(Roop, oopDesc::mark_offset_in_bytes());
duke@0 135 assert(mark_addr.disp() == 0, "cas must take a zero displacement");
duke@0 136
duke@0 137 if (UseBiasedLocking) {
duke@0 138 // load the object out of the BasicObjectLock
duke@0 139 ld_ptr(Rbox, BasicObjectLock::obj_offset_in_bytes(), Roop);
duke@0 140 verify_oop(Roop);
duke@0 141 biased_locking_exit(mark_addr, Rmark, done);
duke@0 142 }
duke@0 143 // Test first it it is a fast recursive unlock
duke@0 144 ld_ptr(Rbox, BasicLock::displaced_header_offset_in_bytes(), Rmark);
duke@0 145 br_null(Rmark, false, Assembler::pt, done);
duke@0 146 delayed()->nop();
duke@0 147 if (!UseBiasedLocking) {
duke@0 148 // load object
duke@0 149 ld_ptr(Rbox, BasicObjectLock::obj_offset_in_bytes(), Roop);
duke@0 150 verify_oop(Roop);
duke@0 151 }
duke@0 152
duke@0 153 // Check if it is still a light weight lock, this is is true if we see
duke@0 154 // the stack address of the basicLock in the markOop of the object
duke@0 155 casx_under_lock(mark_addr.base(), Rbox, Rmark, (address)StubRoutines::Sparc::atomic_memory_operation_lock_addr());
duke@0 156 cmp(Rbox, Rmark);
duke@0 157
duke@0 158 brx(Assembler::notEqual, false, Assembler::pn, slow_case);
duke@0 159 delayed()->nop();
duke@0 160 // Done
duke@0 161 bind(done);
duke@0 162 }
duke@0 163
duke@0 164
duke@0 165 void C1_MacroAssembler::try_allocate(
duke@0 166 Register obj, // result: pointer to object after successful allocation
duke@0 167 Register var_size_in_bytes, // object size in bytes if unknown at compile time; invalid otherwise
duke@0 168 int con_size_in_bytes, // object size in bytes if known at compile time
phh@2101 169 Register t1, // temp register, must be global register for incr_allocated_bytes
duke@0 170 Register t2, // temp register
duke@0 171 Label& slow_case // continuation point if fast allocation fails
duke@0 172 ) {
phh@2140 173 RegisterOrConstant size_in_bytes = var_size_in_bytes->is_valid()
phh@2140 174 ? RegisterOrConstant(var_size_in_bytes) : RegisterOrConstant(con_size_in_bytes);
duke@0 175 if (UseTLAB) {
duke@0 176 tlab_allocate(obj, var_size_in_bytes, con_size_in_bytes, t1, slow_case);
duke@0 177 } else {
duke@0 178 eden_allocate(obj, var_size_in_bytes, con_size_in_bytes, t1, t2, slow_case);
phh@2140 179 incr_allocated_bytes(size_in_bytes, t1, t2);
duke@0 180 }
duke@0 181 }
duke@0 182
duke@0 183
duke@0 184 void C1_MacroAssembler::initialize_header(Register obj, Register klass, Register len, Register t1, Register t2) {
duke@0 185 assert_different_registers(obj, klass, len, t1, t2);
duke@0 186 if (UseBiasedLocking && !len->is_valid()) {
duke@0 187 ld_ptr(klass, Klass::prototype_header_offset_in_bytes() + klassOopDesc::klass_part_offset_in_bytes(), t1);
duke@0 188 } else {
duke@0 189 set((intx)markOopDesc::prototype(), t1);
duke@0 190 }
iveresov@2022 191 st_ptr(t1, obj, oopDesc::mark_offset_in_bytes());
iveresov@2022 192 if (UseCompressedOops) {
iveresov@2022 193 // Save klass
iveresov@2022 194 mov(klass, t1);
iveresov@2022 195 encode_heap_oop_not_null(t1);
iveresov@2022 196 stw(t1, obj, oopDesc::klass_offset_in_bytes());
iveresov@2022 197 } else {
iveresov@2022 198 st_ptr(klass, obj, oopDesc::klass_offset_in_bytes());
iveresov@2022 199 }
iveresov@2022 200 if (len->is_valid()) st(len, obj, arrayOopDesc::length_offset_in_bytes());
iveresov@2022 201 else if (UseCompressedOops) {
iveresov@2022 202 store_klass_gap(G0, obj);
iveresov@2022 203 }
duke@0 204 }
duke@0 205
duke@0 206
duke@0 207 void C1_MacroAssembler::initialize_body(Register base, Register index) {
duke@0 208 assert_different_registers(base, index);
duke@0 209 Label loop;
duke@0 210 bind(loop);
duke@0 211 subcc(index, HeapWordSize, index);
duke@0 212 brx(Assembler::greaterEqual, true, Assembler::pt, loop);
duke@0 213 delayed()->st_ptr(G0, base, index);
duke@0 214 }
duke@0 215
duke@0 216
duke@0 217 void C1_MacroAssembler::allocate_object(
duke@0 218 Register obj, // result: pointer to object after successful allocation
duke@0 219 Register t1, // temp register
phh@2101 220 Register t2, // temp register, must be a global register for try_allocate
duke@0 221 Register t3, // temp register
duke@0 222 int hdr_size, // object header size in words
duke@0 223 int obj_size, // object size in words
duke@0 224 Register klass, // object klass
duke@0 225 Label& slow_case // continuation point if fast allocation fails
duke@0 226 ) {
duke@0 227 assert_different_registers(obj, t1, t2, t3, klass);
duke@0 228 assert(klass == G5, "must be G5");
duke@0 229
duke@0 230 // allocate space & initialize header
duke@0 231 if (!is_simm13(obj_size * wordSize)) {
duke@0 232 // would need to use extra register to load
duke@0 233 // object size => go the slow case for now
duke@0 234 br(Assembler::always, false, Assembler::pt, slow_case);
duke@0 235 delayed()->nop();
duke@0 236 return;
duke@0 237 }
duke@0 238 try_allocate(obj, noreg, obj_size * wordSize, t2, t3, slow_case);
duke@0 239
duke@0 240 initialize_object(obj, klass, noreg, obj_size * HeapWordSize, t1, t2);
duke@0 241 }
duke@0 242
duke@0 243 void C1_MacroAssembler::initialize_object(
duke@0 244 Register obj, // result: pointer to object after successful allocation
duke@0 245 Register klass, // object klass
duke@0 246 Register var_size_in_bytes, // object size in bytes if unknown at compile time; invalid otherwise
duke@0 247 int con_size_in_bytes, // object size in bytes if known at compile time
duke@0 248 Register t1, // temp register
duke@0 249 Register t2 // temp register
duke@0 250 ) {
iveresov@2022 251 const int hdr_size_in_bytes = instanceOopDesc::header_size() * HeapWordSize;
duke@0 252
duke@0 253 initialize_header(obj, klass, noreg, t1, t2);
duke@0 254
duke@0 255 #ifdef ASSERT
duke@0 256 {
duke@0 257 Label ok;
duke@0 258 ld(klass, klassOopDesc::header_size() * HeapWordSize + Klass::layout_helper_offset_in_bytes(), t1);
duke@0 259 if (var_size_in_bytes != noreg) {
duke@0 260 cmp(t1, var_size_in_bytes);
duke@0 261 } else {
duke@0 262 cmp(t1, con_size_in_bytes);
duke@0 263 }
duke@0 264 brx(Assembler::equal, false, Assembler::pt, ok);
duke@0 265 delayed()->nop();
duke@0 266 stop("bad size in initialize_object");
duke@0 267 should_not_reach_here();
duke@0 268
duke@0 269 bind(ok);
duke@0 270 }
duke@0 271
duke@0 272 #endif
duke@0 273
duke@0 274 // initialize body
duke@0 275 const int threshold = 5 * HeapWordSize; // approximate break even point for code size
duke@0 276 if (var_size_in_bytes != noreg) {
duke@0 277 // use a loop
duke@0 278 add(obj, hdr_size_in_bytes, t1); // compute address of first element
duke@0 279 sub(var_size_in_bytes, hdr_size_in_bytes, t2); // compute size of body
duke@0 280 initialize_body(t1, t2);
duke@0 281 #ifndef _LP64
duke@0 282 } else if (VM_Version::v9_instructions_work() && con_size_in_bytes < threshold * 2) {
duke@0 283 // on v9 we can do double word stores to fill twice as much space.
duke@0 284 assert(hdr_size_in_bytes % 8 == 0, "double word aligned");
duke@0 285 assert(con_size_in_bytes % 8 == 0, "double word aligned");
duke@0 286 for (int i = hdr_size_in_bytes; i < con_size_in_bytes; i += 2 * HeapWordSize) stx(G0, obj, i);
duke@0 287 #endif
duke@0 288 } else if (con_size_in_bytes <= threshold) {
duke@0 289 // use explicit NULL stores
duke@0 290 for (int i = hdr_size_in_bytes; i < con_size_in_bytes; i += HeapWordSize) st_ptr(G0, obj, i);
duke@0 291 } else if (con_size_in_bytes > hdr_size_in_bytes) {
duke@0 292 // use a loop
duke@0 293 const Register base = t1;
duke@0 294 const Register index = t2;
duke@0 295 add(obj, hdr_size_in_bytes, base); // compute address of first element
duke@0 296 // compute index = number of words to clear
duke@0 297 set(con_size_in_bytes - hdr_size_in_bytes, index);
duke@0 298 initialize_body(base, index);
duke@0 299 }
duke@0 300
kvn@828 301 if (CURRENT_ENV->dtrace_alloc_probes()) {
duke@0 302 assert(obj == O0, "must be");
duke@0 303 call(CAST_FROM_FN_PTR(address, Runtime1::entry_for(Runtime1::dtrace_object_alloc_id)),
duke@0 304 relocInfo::runtime_call_type);
duke@0 305 delayed()->nop();
duke@0 306 }
duke@0 307
duke@0 308 verify_oop(obj);
duke@0 309 }
duke@0 310
duke@0 311
duke@0 312 void C1_MacroAssembler::allocate_array(
duke@0 313 Register obj, // result: pointer to array after successful allocation
duke@0 314 Register len, // array length
duke@0 315 Register t1, // temp register
duke@0 316 Register t2, // temp register
duke@0 317 Register t3, // temp register
duke@0 318 int hdr_size, // object header size in words
duke@0 319 int elt_size, // element size in bytes
duke@0 320 Register klass, // object klass
duke@0 321 Label& slow_case // continuation point if fast allocation fails
duke@0 322 ) {
duke@0 323 assert_different_registers(obj, len, t1, t2, t3, klass);
duke@0 324 assert(klass == G5, "must be G5");
duke@0 325 assert(t1 == G1, "must be G1");
duke@0 326
duke@0 327 // determine alignment mask
duke@0 328 assert(!(BytesPerWord & 1), "must be a multiple of 2 for masking code to work");
duke@0 329
duke@0 330 // check for negative or excessive length
duke@0 331 // note: the maximum length allowed is chosen so that arrays of any
duke@0 332 // element size with this length are always smaller or equal
duke@0 333 // to the largest integer (i.e., array size computation will
duke@0 334 // not overflow)
duke@0 335 set(max_array_allocation_length, t1);
duke@0 336 cmp(len, t1);
duke@0 337 br(Assembler::greaterUnsigned, false, Assembler::pn, slow_case);
duke@0 338
duke@0 339 // compute array size
duke@0 340 // note: if 0 <= len <= max_length, len*elt_size + header + alignment is
duke@0 341 // smaller or equal to the largest integer; also, since top is always
duke@0 342 // aligned, we can do the alignment here instead of at the end address
duke@0 343 // computation
duke@0 344 const Register arr_size = t1;
duke@0 345 switch (elt_size) {
duke@0 346 case 1: delayed()->mov(len, arr_size); break;
duke@0 347 case 2: delayed()->sll(len, 1, arr_size); break;
duke@0 348 case 4: delayed()->sll(len, 2, arr_size); break;
duke@0 349 case 8: delayed()->sll(len, 3, arr_size); break;
duke@0 350 default: ShouldNotReachHere();
duke@0 351 }
duke@0 352 add(arr_size, hdr_size * wordSize + MinObjAlignmentInBytesMask, arr_size); // add space for header & alignment
duke@0 353 and3(arr_size, ~MinObjAlignmentInBytesMask, arr_size); // align array size
duke@0 354
duke@0 355 // allocate space & initialize header
duke@0 356 if (UseTLAB) {
duke@0 357 tlab_allocate(obj, arr_size, 0, t2, slow_case);
duke@0 358 } else {
duke@0 359 eden_allocate(obj, arr_size, 0, t2, t3, slow_case);
duke@0 360 }
duke@0 361 initialize_header(obj, klass, len, t2, t3);
duke@0 362
duke@0 363 // initialize body
duke@0 364 const Register base = t2;
duke@0 365 const Register index = t3;
duke@0 366 add(obj, hdr_size * wordSize, base); // compute address of first element
duke@0 367 sub(arr_size, hdr_size * wordSize, index); // compute index = number of words to clear
duke@0 368 initialize_body(base, index);
duke@0 369
kvn@828 370 if (CURRENT_ENV->dtrace_alloc_probes()) {
duke@0 371 assert(obj == O0, "must be");
duke@0 372 call(CAST_FROM_FN_PTR(address, Runtime1::entry_for(Runtime1::dtrace_object_alloc_id)),
duke@0 373 relocInfo::runtime_call_type);
duke@0 374 delayed()->nop();
duke@0 375 }
duke@0 376
duke@0 377 verify_oop(obj);
duke@0 378 }
duke@0 379
duke@0 380
duke@0 381 #ifndef PRODUCT
duke@0 382
duke@0 383 void C1_MacroAssembler::verify_stack_oop(int stack_offset) {
duke@0 384 if (!VerifyOops) return;
twisti@765 385 verify_oop_addr(Address(SP, stack_offset + STACK_BIAS));
duke@0 386 }
duke@0 387
duke@0 388 void C1_MacroAssembler::verify_not_null_oop(Register r) {
duke@0 389 Label not_null;
iveresov@2451 390 br_notnull(r, false, Assembler::pt, not_null);
duke@0 391 delayed()->nop();
duke@0 392 stop("non-null oop required");
duke@0 393 bind(not_null);
duke@0 394 if (!VerifyOops) return;
duke@0 395 verify_oop(r);
duke@0 396 }
duke@0 397
duke@0 398 void C1_MacroAssembler::invalidate_registers(bool iregisters, bool lregisters, bool oregisters,
duke@0 399 Register preserve1, Register preserve2) {
duke@0 400 if (iregisters) {
duke@0 401 for (int i = 0; i < 6; i++) {
duke@0 402 Register r = as_iRegister(i);
duke@0 403 if (r != preserve1 && r != preserve2) set(0xdead, r);
duke@0 404 }
duke@0 405 }
duke@0 406 if (oregisters) {
duke@0 407 for (int i = 0; i < 6; i++) {
duke@0 408 Register r = as_oRegister(i);
duke@0 409 if (r != preserve1 && r != preserve2) set(0xdead, r);
duke@0 410 }
duke@0 411 }
duke@0 412 if (lregisters) {
duke@0 413 for (int i = 0; i < 8; i++) {
duke@0 414 Register r = as_lRegister(i);
duke@0 415 if (r != preserve1 && r != preserve2) set(0xdead, r);
duke@0 416 }
duke@0 417 }
duke@0 418 }
duke@0 419
duke@0 420
duke@0 421 #endif