src/cpu/x86/vm/c1_MacroAssembler_x86.cpp

Sun, 13 Apr 2008 17:43:42 -0400

author
coleenp
date
Sun, 13 Apr 2008 17:43:42 -0400
changeset 548
ba764ed4b6f2
parent 435
a61af66fc99e
child 631
d1605aabd0a1
permissions
-rw-r--r--

6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
Summary: Compressed oops in instances, arrays, and headers. Code contributors are coleenp, phh, never, swamyv
Reviewed-by: jmasa, kamg, acorn, tbell, kvn, rasbold

duke@435 1 /*
duke@435 2 * Copyright 1999-2007 Sun Microsystems, Inc. All Rights Reserved.
duke@435 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@435 4 *
duke@435 5 * This code is free software; you can redistribute it and/or modify it
duke@435 6 * under the terms of the GNU General Public License version 2 only, as
duke@435 7 * published by the Free Software Foundation.
duke@435 8 *
duke@435 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@435 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@435 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@435 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@435 13 * accompanied this code).
duke@435 14 *
duke@435 15 * You should have received a copy of the GNU General Public License version
duke@435 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@435 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@435 18 *
duke@435 19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
duke@435 20 * CA 95054 USA or visit www.sun.com if you need additional information or
duke@435 21 * have any questions.
duke@435 22 *
duke@435 23 */
duke@435 24
duke@435 25 #include "incls/_precompiled.incl"
duke@435 26 #include "incls/_c1_MacroAssembler_x86.cpp.incl"
duke@435 27
duke@435 28 int C1_MacroAssembler::lock_object(Register hdr, Register obj, Register disp_hdr, Register scratch, Label& slow_case) {
duke@435 29 const int aligned_mask = 3;
duke@435 30 const int hdr_offset = oopDesc::mark_offset_in_bytes();
duke@435 31 assert(hdr == rax, "hdr must be rax, for the cmpxchg instruction");
duke@435 32 assert(hdr != obj && hdr != disp_hdr && obj != disp_hdr, "registers must be different");
duke@435 33 assert(BytesPerWord == 4, "adjust aligned_mask and code");
duke@435 34 Label done;
duke@435 35 int null_check_offset = -1;
duke@435 36
duke@435 37 verify_oop(obj);
duke@435 38
duke@435 39 // save object being locked into the BasicObjectLock
duke@435 40 movl(Address(disp_hdr, BasicObjectLock::obj_offset_in_bytes()), obj);
duke@435 41
duke@435 42 if (UseBiasedLocking) {
duke@435 43 assert(scratch != noreg, "should have scratch register at this point");
duke@435 44 null_check_offset = biased_locking_enter(disp_hdr, obj, hdr, scratch, false, done, &slow_case);
duke@435 45 } else {
duke@435 46 null_check_offset = offset();
duke@435 47 }
duke@435 48
duke@435 49 // Load object header
duke@435 50 movl(hdr, Address(obj, hdr_offset));
duke@435 51 // and mark it as unlocked
duke@435 52 orl(hdr, markOopDesc::unlocked_value);
duke@435 53 // save unlocked object header into the displaced header location on the stack
duke@435 54 movl(Address(disp_hdr, 0), hdr);
duke@435 55 // test if object header is still the same (i.e. unlocked), and if so, store the
duke@435 56 // displaced header address in the object header - if it is not the same, get the
duke@435 57 // object header instead
duke@435 58 if (os::is_MP()) MacroAssembler::lock(); // must be immediately before cmpxchg!
duke@435 59 cmpxchg(disp_hdr, Address(obj, hdr_offset));
duke@435 60 // if the object header was the same, we're done
duke@435 61 if (PrintBiasedLockingStatistics) {
duke@435 62 cond_inc32(Assembler::equal,
duke@435 63 ExternalAddress((address)BiasedLocking::fast_path_entry_count_addr()));
duke@435 64 }
duke@435 65 jcc(Assembler::equal, done);
duke@435 66 // if the object header was not the same, it is now in the hdr register
duke@435 67 // => test if it is a stack pointer into the same stack (recursive locking), i.e.:
duke@435 68 //
duke@435 69 // 1) (hdr & aligned_mask) == 0
duke@435 70 // 2) rsp <= hdr
duke@435 71 // 3) hdr <= rsp + page_size
duke@435 72 //
duke@435 73 // these 3 tests can be done by evaluating the following expression:
duke@435 74 //
duke@435 75 // (hdr - rsp) & (aligned_mask - page_size)
duke@435 76 //
duke@435 77 // assuming both the stack pointer and page_size have their least
duke@435 78 // significant 2 bits cleared and page_size is a power of 2
duke@435 79 subl(hdr, rsp);
duke@435 80 andl(hdr, aligned_mask - os::vm_page_size());
duke@435 81 // for recursive locking, the result is zero => save it in the displaced header
duke@435 82 // location (NULL in the displaced hdr location indicates recursive locking)
duke@435 83 movl(Address(disp_hdr, 0), hdr);
duke@435 84 // otherwise we don't care about the result and handle locking via runtime call
duke@435 85 jcc(Assembler::notZero, slow_case);
duke@435 86 // done
duke@435 87 bind(done);
duke@435 88 return null_check_offset;
duke@435 89 }
duke@435 90
duke@435 91
duke@435 92 void C1_MacroAssembler::unlock_object(Register hdr, Register obj, Register disp_hdr, Label& slow_case) {
duke@435 93 const int aligned_mask = 3;
duke@435 94 const int hdr_offset = oopDesc::mark_offset_in_bytes();
duke@435 95 assert(disp_hdr == rax, "disp_hdr must be rax, for the cmpxchg instruction");
duke@435 96 assert(hdr != obj && hdr != disp_hdr && obj != disp_hdr, "registers must be different");
duke@435 97 assert(BytesPerWord == 4, "adjust aligned_mask and code");
duke@435 98 Label done;
duke@435 99
duke@435 100 if (UseBiasedLocking) {
duke@435 101 // load object
duke@435 102 movl(obj, Address(disp_hdr, BasicObjectLock::obj_offset_in_bytes()));
duke@435 103 biased_locking_exit(obj, hdr, done);
duke@435 104 }
duke@435 105
duke@435 106 // load displaced header
duke@435 107 movl(hdr, Address(disp_hdr, 0));
duke@435 108 // if the loaded hdr is NULL we had recursive locking
duke@435 109 testl(hdr, hdr);
duke@435 110 // if we had recursive locking, we are done
duke@435 111 jcc(Assembler::zero, done);
duke@435 112 if (!UseBiasedLocking) {
duke@435 113 // load object
duke@435 114 movl(obj, Address(disp_hdr, BasicObjectLock::obj_offset_in_bytes()));
duke@435 115 }
duke@435 116 verify_oop(obj);
duke@435 117 // test if object header is pointing to the displaced header, and if so, restore
duke@435 118 // the displaced header in the object - if the object header is not pointing to
duke@435 119 // the displaced header, get the object header instead
duke@435 120 if (os::is_MP()) MacroAssembler::lock(); // must be immediately before cmpxchg!
duke@435 121 cmpxchg(hdr, Address(obj, hdr_offset));
duke@435 122 // if the object header was not pointing to the displaced header,
duke@435 123 // we do unlocking via runtime call
duke@435 124 jcc(Assembler::notEqual, slow_case);
duke@435 125 // done
duke@435 126 bind(done);
duke@435 127 }
duke@435 128
duke@435 129
duke@435 130 // Defines obj, preserves var_size_in_bytes
duke@435 131 void C1_MacroAssembler::try_allocate(Register obj, Register var_size_in_bytes, int con_size_in_bytes, Register t1, Register t2, Label& slow_case) {
duke@435 132 if (UseTLAB) {
duke@435 133 tlab_allocate(obj, var_size_in_bytes, con_size_in_bytes, t1, t2, slow_case);
duke@435 134 } else {
duke@435 135 eden_allocate(obj, var_size_in_bytes, con_size_in_bytes, t1, slow_case);
duke@435 136 }
duke@435 137 }
duke@435 138
duke@435 139
duke@435 140 void C1_MacroAssembler::initialize_header(Register obj, Register klass, Register len, Register t1, Register t2) {
duke@435 141 assert_different_registers(obj, klass, len);
duke@435 142 if (UseBiasedLocking && !len->is_valid()) {
duke@435 143 assert_different_registers(obj, klass, len, t1, t2);
duke@435 144 movl(t1, Address(klass, Klass::prototype_header_offset_in_bytes() + klassOopDesc::klass_part_offset_in_bytes()));
duke@435 145 movl(Address(obj, oopDesc::mark_offset_in_bytes()), t1);
duke@435 146 } else {
duke@435 147 movl(Address(obj, oopDesc::mark_offset_in_bytes ()), (int)markOopDesc::prototype());
duke@435 148 }
duke@435 149
duke@435 150 movl(Address(obj, oopDesc::klass_offset_in_bytes()), klass);
duke@435 151 if (len->is_valid()) {
duke@435 152 movl(Address(obj, arrayOopDesc::length_offset_in_bytes()), len);
duke@435 153 }
duke@435 154 }
duke@435 155
duke@435 156
duke@435 157 // preserves obj, destroys len_in_bytes
duke@435 158 void C1_MacroAssembler::initialize_body(Register obj, Register len_in_bytes, int hdr_size_in_bytes, Register t1) {
duke@435 159 Label done;
duke@435 160 assert(obj != len_in_bytes && obj != t1 && t1 != len_in_bytes, "registers must be different");
duke@435 161 assert((hdr_size_in_bytes & (BytesPerWord - 1)) == 0, "header size is not a multiple of BytesPerWord");
duke@435 162 Register index = len_in_bytes;
duke@435 163 subl(index, hdr_size_in_bytes);
duke@435 164 jcc(Assembler::zero, done);
duke@435 165 // initialize topmost word, divide index by 2, check if odd and test if zero
duke@435 166 // note: for the remaining code to work, index must be a multiple of BytesPerWord
duke@435 167 #ifdef ASSERT
duke@435 168 { Label L;
duke@435 169 testl(index, BytesPerWord - 1);
duke@435 170 jcc(Assembler::zero, L);
duke@435 171 stop("index is not a multiple of BytesPerWord");
duke@435 172 bind(L);
duke@435 173 }
duke@435 174 #endif
duke@435 175 xorl(t1, t1); // use _zero reg to clear memory (shorter code)
duke@435 176 if (UseIncDec) {
duke@435 177 shrl(index, 3); // divide by 8 and set carry flag if bit 2 was set
duke@435 178 } else {
duke@435 179 shrl(index, 2); // use 2 instructions to avoid partial flag stall
duke@435 180 shrl(index, 1);
duke@435 181 }
duke@435 182 // index could have been not a multiple of 8 (i.e., bit 2 was set)
duke@435 183 { Label even;
duke@435 184 // note: if index was a multiple of 8, than it cannot
duke@435 185 // be 0 now otherwise it must have been 0 before
duke@435 186 // => if it is even, we don't need to check for 0 again
duke@435 187 jcc(Assembler::carryClear, even);
duke@435 188 // clear topmost word (no jump needed if conditional assignment would work here)
duke@435 189 movl(Address(obj, index, Address::times_8, hdr_size_in_bytes - 0*BytesPerWord), t1);
duke@435 190 // index could be 0 now, need to check again
duke@435 191 jcc(Assembler::zero, done);
duke@435 192 bind(even);
duke@435 193 }
duke@435 194 // initialize remaining object fields: rdx is a multiple of 2 now
duke@435 195 { Label loop;
duke@435 196 bind(loop);
duke@435 197 movl(Address(obj, index, Address::times_8, hdr_size_in_bytes - 1*BytesPerWord), t1);
duke@435 198 movl(Address(obj, index, Address::times_8, hdr_size_in_bytes - 2*BytesPerWord), t1);
duke@435 199 decrement(index);
duke@435 200 jcc(Assembler::notZero, loop);
duke@435 201 }
duke@435 202
duke@435 203 // done
duke@435 204 bind(done);
duke@435 205 }
duke@435 206
duke@435 207
duke@435 208 void C1_MacroAssembler::allocate_object(Register obj, Register t1, Register t2, int header_size, int object_size, Register klass, Label& slow_case) {
duke@435 209 assert(obj == rax, "obj must be in rax, for cmpxchg");
duke@435 210 assert(obj != t1 && obj != t2 && t1 != t2, "registers must be different"); // XXX really?
duke@435 211 assert(header_size >= 0 && object_size >= header_size, "illegal sizes");
duke@435 212
duke@435 213 try_allocate(obj, noreg, object_size * BytesPerWord, t1, t2, slow_case);
duke@435 214
duke@435 215 initialize_object(obj, klass, noreg, object_size * HeapWordSize, t1, t2);
duke@435 216 }
duke@435 217
duke@435 218 void C1_MacroAssembler::initialize_object(Register obj, Register klass, Register var_size_in_bytes, int con_size_in_bytes, Register t1, Register t2) {
duke@435 219 assert((con_size_in_bytes & MinObjAlignmentInBytesMask) == 0,
duke@435 220 "con_size_in_bytes is not multiple of alignment");
coleenp@548 221 const int hdr_size_in_bytes = instanceOopDesc::base_offset_in_bytes();
duke@435 222
duke@435 223 initialize_header(obj, klass, noreg, t1, t2);
duke@435 224
duke@435 225 // clear rest of allocated space
duke@435 226 const Register t1_zero = t1;
duke@435 227 const Register index = t2;
duke@435 228 const int threshold = 6 * BytesPerWord; // approximate break even point for code size (see comments below)
duke@435 229 if (var_size_in_bytes != noreg) {
duke@435 230 movl(index, var_size_in_bytes);
duke@435 231 initialize_body(obj, index, hdr_size_in_bytes, t1_zero);
duke@435 232 } else if (con_size_in_bytes <= threshold) {
duke@435 233 // use explicit null stores
duke@435 234 // code size = 2 + 3*n bytes (n = number of fields to clear)
duke@435 235 xorl(t1_zero, t1_zero); // use t1_zero reg to clear memory (shorter code)
duke@435 236 for (int i = hdr_size_in_bytes; i < con_size_in_bytes; i += BytesPerWord)
duke@435 237 movl(Address(obj, i), t1_zero);
duke@435 238 } else if (con_size_in_bytes > hdr_size_in_bytes) {
duke@435 239 // use loop to null out the fields
duke@435 240 // code size = 16 bytes for even n (n = number of fields to clear)
duke@435 241 // initialize last object field first if odd number of fields
duke@435 242 xorl(t1_zero, t1_zero); // use t1_zero reg to clear memory (shorter code)
duke@435 243 movl(index, (con_size_in_bytes - hdr_size_in_bytes) >> 3);
duke@435 244 // initialize last object field if constant size is odd
duke@435 245 if (((con_size_in_bytes - hdr_size_in_bytes) & 4) != 0)
duke@435 246 movl(Address(obj, con_size_in_bytes - (1*BytesPerWord)), t1_zero);
duke@435 247 // initialize remaining object fields: rdx is a multiple of 2
duke@435 248 { Label loop;
duke@435 249 bind(loop);
duke@435 250 movl(Address(obj, index, Address::times_8,
duke@435 251 hdr_size_in_bytes - (1*BytesPerWord)), t1_zero);
duke@435 252 movl(Address(obj, index, Address::times_8,
duke@435 253 hdr_size_in_bytes - (2*BytesPerWord)), t1_zero);
duke@435 254 decrement(index);
duke@435 255 jcc(Assembler::notZero, loop);
duke@435 256 }
duke@435 257 }
duke@435 258
duke@435 259 if (DTraceAllocProbes) {
duke@435 260 assert(obj == rax, "must be");
duke@435 261 call(RuntimeAddress(Runtime1::entry_for(Runtime1::dtrace_object_alloc_id)));
duke@435 262 }
duke@435 263
duke@435 264 verify_oop(obj);
duke@435 265 }
duke@435 266
duke@435 267 void C1_MacroAssembler::allocate_array(Register obj, Register len, Register t1, Register t2, int header_size, Address::ScaleFactor f, Register klass, Label& slow_case) {
duke@435 268 assert(obj == rax, "obj must be in rax, for cmpxchg");
duke@435 269 assert_different_registers(obj, len, t1, t2, klass);
duke@435 270
duke@435 271 // determine alignment mask
duke@435 272 assert(BytesPerWord == 4, "must be a multiple of 2 for masking code to work");
duke@435 273
duke@435 274 // check for negative or excessive length
duke@435 275 cmpl(len, max_array_allocation_length);
duke@435 276 jcc(Assembler::above, slow_case);
duke@435 277
duke@435 278 const Register arr_size = t2; // okay to be the same
duke@435 279 // align object end
duke@435 280 movl(arr_size, header_size * BytesPerWord + MinObjAlignmentInBytesMask);
duke@435 281 leal(arr_size, Address(arr_size, len, f));
duke@435 282 andl(arr_size, ~MinObjAlignmentInBytesMask);
duke@435 283
duke@435 284 try_allocate(obj, arr_size, 0, t1, t2, slow_case);
duke@435 285
duke@435 286 initialize_header(obj, klass, len, t1, t2);
duke@435 287
duke@435 288 // clear rest of allocated space
duke@435 289 const Register len_zero = len;
duke@435 290 initialize_body(obj, arr_size, header_size * BytesPerWord, len_zero);
duke@435 291
duke@435 292 if (DTraceAllocProbes) {
duke@435 293 assert(obj == rax, "must be");
duke@435 294 call(RuntimeAddress(Runtime1::entry_for(Runtime1::dtrace_object_alloc_id)));
duke@435 295 }
duke@435 296
duke@435 297 verify_oop(obj);
duke@435 298 }
duke@435 299
duke@435 300
duke@435 301
duke@435 302 void C1_MacroAssembler::inline_cache_check(Register receiver, Register iCache) {
duke@435 303 verify_oop(receiver);
duke@435 304 // explicit NULL check not needed since load from [klass_offset] causes a trap
duke@435 305 // check against inline cache
duke@435 306 assert(!MacroAssembler::needs_explicit_null_check(oopDesc::klass_offset_in_bytes()), "must add explicit null check");
duke@435 307 int start_offset = offset();
duke@435 308 cmpl(iCache, Address(receiver, oopDesc::klass_offset_in_bytes()));
duke@435 309 // if icache check fails, then jump to runtime routine
duke@435 310 // Note: RECEIVER must still contain the receiver!
duke@435 311 jump_cc(Assembler::notEqual,
duke@435 312 RuntimeAddress(SharedRuntime::get_ic_miss_stub()));
duke@435 313 assert(offset() - start_offset == 9, "check alignment in emit_method_entry");
duke@435 314 }
duke@435 315
duke@435 316
duke@435 317 void C1_MacroAssembler::method_exit(bool restore_frame) {
duke@435 318 if (restore_frame) {
duke@435 319 leave();
duke@435 320 }
duke@435 321 ret(0);
duke@435 322 }
duke@435 323
duke@435 324
duke@435 325 void C1_MacroAssembler::build_frame(int frame_size_in_bytes) {
duke@435 326 // Make sure there is enough stack space for this method's activation.
duke@435 327 // Note that we do this before doing an enter(). This matches the
duke@435 328 // ordering of C2's stack overflow check / rsp decrement and allows
duke@435 329 // the SharedRuntime stack overflow handling to be consistent
duke@435 330 // between the two compilers.
duke@435 331 generate_stack_overflow_check(frame_size_in_bytes);
duke@435 332
duke@435 333 enter();
duke@435 334 #ifdef TIERED
duke@435 335 // c2 leaves fpu stack dirty. Clean it on entry
duke@435 336 if (UseSSE < 2 ) {
duke@435 337 empty_FPU_stack();
duke@435 338 }
duke@435 339 #endif // TIERED
duke@435 340 decrement(rsp, frame_size_in_bytes); // does not emit code for frame_size == 0
duke@435 341 }
duke@435 342
duke@435 343
duke@435 344 void C1_MacroAssembler::unverified_entry(Register receiver, Register ic_klass) {
duke@435 345 if (C1Breakpoint) int3();
duke@435 346 inline_cache_check(receiver, ic_klass);
duke@435 347 }
duke@435 348
duke@435 349
duke@435 350 void C1_MacroAssembler::verified_entry() {
duke@435 351 if (C1Breakpoint)int3();
duke@435 352 // build frame
duke@435 353 verify_FPU(0, "method_entry");
duke@435 354 }
duke@435 355
duke@435 356
duke@435 357 #ifndef PRODUCT
duke@435 358
duke@435 359 void C1_MacroAssembler::verify_stack_oop(int stack_offset) {
duke@435 360 if (!VerifyOops) return;
duke@435 361 verify_oop_addr(Address(rsp, stack_offset));
duke@435 362 }
duke@435 363
duke@435 364 void C1_MacroAssembler::verify_not_null_oop(Register r) {
duke@435 365 if (!VerifyOops) return;
duke@435 366 Label not_null;
duke@435 367 testl(r, r);
duke@435 368 jcc(Assembler::notZero, not_null);
duke@435 369 stop("non-null oop required");
duke@435 370 bind(not_null);
duke@435 371 verify_oop(r);
duke@435 372 }
duke@435 373
duke@435 374 void C1_MacroAssembler::invalidate_registers(bool inv_rax, bool inv_rbx, bool inv_rcx, bool inv_rdx, bool inv_rsi, bool inv_rdi) {
duke@435 375 #ifdef ASSERT
duke@435 376 if (inv_rax) movl(rax, 0xDEAD);
duke@435 377 if (inv_rbx) movl(rbx, 0xDEAD);
duke@435 378 if (inv_rcx) movl(rcx, 0xDEAD);
duke@435 379 if (inv_rdx) movl(rdx, 0xDEAD);
duke@435 380 if (inv_rsi) movl(rsi, 0xDEAD);
duke@435 381 if (inv_rdi) movl(rdi, 0xDEAD);
duke@435 382 #endif
duke@435 383 }
duke@435 384
duke@435 385 #endif // ifndef PRODUCT

mercurial