< prev index next >

src/cpu/x86/vm/c1_MacroAssembler_x86.cpp

Print this page




   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 "c1/c1_MacroAssembler.hpp"
  27 #include "c1/c1_Runtime1.hpp"
  28 #include "classfile/systemDictionary.hpp"
  29 #include "gc/shared/collectedHeap.hpp"
  30 #include "interpreter/interpreter.hpp"
  31 #include "oops/arrayOop.hpp"
  32 #include "oops/markOop.hpp"
  33 #include "runtime/basicLock.hpp"
  34 #include "runtime/biasedLocking.hpp"
  35 #include "runtime/os.hpp"
  36 #include "runtime/sharedRuntime.hpp"
  37 #include "runtime/stubRoutines.hpp"
  38 
  39 int C1_MacroAssembler::lock_object(Register hdr, Register obj, Register disp_hdr, Register scratch, Label& slow_case) {
  40   const int aligned_mask = BytesPerWord -1;
  41   const int hdr_offset = oopDesc::mark_offset_in_bytes();
  42   assert(hdr == rax, "hdr must be rax, for the cmpxchg instruction");
  43   assert(hdr != obj && hdr != disp_hdr && obj != disp_hdr, "registers must be different");
  44   Label done;
  45   int null_check_offset = -1;


 184 void C1_MacroAssembler::initialize_body(Register obj, Register len_in_bytes, int hdr_size_in_bytes, Register t1) {
 185   assert(hdr_size_in_bytes >= 0, "header size must be positive or 0");
 186   Label done;
 187 
 188   // len_in_bytes is positive and ptr sized
 189   subptr(len_in_bytes, hdr_size_in_bytes);
 190   jcc(Assembler::zero, done);
 191   zero_memory(obj, len_in_bytes, hdr_size_in_bytes, t1);
 192   bind(done);
 193 }
 194 
 195 
 196 void C1_MacroAssembler::allocate_object(Register obj, Register t1, Register t2, int header_size, int object_size, Register klass, Label& slow_case) {
 197   assert(obj == rax, "obj must be in rax, for cmpxchg");
 198   assert_different_registers(obj, t1, t2); // XXX really?
 199   assert(header_size >= 0 && object_size >= header_size, "illegal sizes");
 200 
 201   try_allocate(obj, noreg, object_size * BytesPerWord, t1, t2, slow_case);
 202 
 203   initialize_object(obj, klass, noreg, object_size * HeapWordSize, t1, t2, UseTLAB);




 204 }
 205 
 206 void C1_MacroAssembler::initialize_object(Register obj, Register klass, Register var_size_in_bytes, int con_size_in_bytes, Register t1, Register t2, bool is_tlab_allocated) {
 207   assert((con_size_in_bytes & MinObjAlignmentInBytesMask) == 0,
 208          "con_size_in_bytes is not multiple of alignment");
 209   const int hdr_size_in_bytes = instanceOopDesc::header_size() * HeapWordSize;
 210 
 211   initialize_header(obj, klass, noreg, t1, t2);
 212 
 213   if (!(UseTLAB && ZeroTLAB && is_tlab_allocated)) {
 214     // clear rest of allocated space
 215     const Register t1_zero = t1;
 216     const Register index = t2;
 217     const int threshold = 6 * BytesPerWord;   // approximate break even point for code size (see comments below)
 218     if (var_size_in_bytes != noreg) {
 219       mov(index, var_size_in_bytes);
 220       initialize_body(obj, index, hdr_size_in_bytes, t1_zero);
 221     } else if (con_size_in_bytes <= threshold) {
 222       // use explicit null stores
 223       // code size = 2 + 3*n bytes (n = number of fields to clear)


 260 
 261   // determine alignment mask
 262   assert(!(BytesPerWord & 1), "must be a multiple of 2 for masking code to work");
 263 
 264   // check for negative or excessive length
 265   cmpptr(len, (int32_t)max_array_allocation_length);
 266   jcc(Assembler::above, slow_case);
 267 
 268   const Register arr_size = t2; // okay to be the same
 269   // align object end
 270   movptr(arr_size, (int32_t)header_size * BytesPerWord + MinObjAlignmentInBytesMask);
 271   lea(arr_size, Address(arr_size, len, f));
 272   andptr(arr_size, ~MinObjAlignmentInBytesMask);
 273 
 274   try_allocate(obj, arr_size, 0, t1, t2, slow_case);
 275 
 276   initialize_header(obj, klass, len, t1, t2);
 277 
 278   // clear rest of allocated space
 279   const Register len_zero = len;


 280   initialize_body(obj, arr_size, header_size * BytesPerWord, len_zero);

 281 
 282   if (CURRENT_ENV->dtrace_alloc_probes()) {
 283     assert(obj == rax, "must be");
 284     call(RuntimeAddress(Runtime1::entry_for(Runtime1::dtrace_object_alloc_id)));
 285   }
 286 



 287   verify_oop(obj);
 288 }
 289 
 290 
 291 
 292 void C1_MacroAssembler::inline_cache_check(Register receiver, Register iCache) {
 293   verify_oop(receiver);
 294   // explicit NULL check not needed since load from [klass_offset] causes a trap
 295   // check against inline cache
 296   assert(!MacroAssembler::needs_explicit_null_check(oopDesc::klass_offset_in_bytes()), "must add explicit null check");
 297   int start_offset = offset();
 298 
 299   if (UseCompressedClassPointers) {
 300     load_klass(rscratch1, receiver);
 301     cmpptr(rscratch1, iCache);
 302   } else {
 303     cmpptr(iCache, Address(receiver, oopDesc::klass_offset_in_bytes()));
 304   }
 305   // if icache check fails, then jump to runtime routine
 306   // Note: RECEIVER must still contain the receiver!




   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 "assembler_x86.hpp"
  27 #include "c1/c1_MacroAssembler.hpp"
  28 #include "c1/c1_Runtime1.hpp"
  29 #include "classfile/systemDictionary.hpp"
  30 #include "gc/shared/collectedHeap.hpp"
  31 #include "interpreter/interpreter.hpp"
  32 #include "oops/arrayOop.hpp"
  33 #include "oops/markOop.hpp"
  34 #include "runtime/basicLock.hpp"
  35 #include "runtime/biasedLocking.hpp"
  36 #include "runtime/os.hpp"
  37 #include "runtime/sharedRuntime.hpp"
  38 #include "runtime/stubRoutines.hpp"
  39 
  40 int C1_MacroAssembler::lock_object(Register hdr, Register obj, Register disp_hdr, Register scratch, Label& slow_case) {
  41   const int aligned_mask = BytesPerWord -1;
  42   const int hdr_offset = oopDesc::mark_offset_in_bytes();
  43   assert(hdr == rax, "hdr must be rax, for the cmpxchg instruction");
  44   assert(hdr != obj && hdr != disp_hdr && obj != disp_hdr, "registers must be different");
  45   Label done;
  46   int null_check_offset = -1;


 185 void C1_MacroAssembler::initialize_body(Register obj, Register len_in_bytes, int hdr_size_in_bytes, Register t1) {
 186   assert(hdr_size_in_bytes >= 0, "header size must be positive or 0");
 187   Label done;
 188 
 189   // len_in_bytes is positive and ptr sized
 190   subptr(len_in_bytes, hdr_size_in_bytes);
 191   jcc(Assembler::zero, done);
 192   zero_memory(obj, len_in_bytes, hdr_size_in_bytes, t1);
 193   bind(done);
 194 }
 195 
 196 
 197 void C1_MacroAssembler::allocate_object(Register obj, Register t1, Register t2, int header_size, int object_size, Register klass, Label& slow_case) {
 198   assert(obj == rax, "obj must be in rax, for cmpxchg");
 199   assert_different_registers(obj, t1, t2); // XXX really?
 200   assert(header_size >= 0 && object_size >= header_size, "illegal sizes");
 201 
 202   try_allocate(obj, noreg, object_size * BytesPerWord, t1, t2, slow_case);
 203 
 204   initialize_object(obj, klass, noreg, object_size * HeapWordSize, t1, t2, UseTLAB);
 205 
 206   HEAP_MONITORING(this, noreg, noreg, object_size * HeapWordSize, obj,
 207                   t1, t2, call(RuntimeAddress(Runtime1::entry_for(
 208                       Runtime1::heap_object_sample_id))););
 209 }
 210 
 211 void C1_MacroAssembler::initialize_object(Register obj, Register klass, Register var_size_in_bytes, int con_size_in_bytes, Register t1, Register t2, bool is_tlab_allocated) {
 212   assert((con_size_in_bytes & MinObjAlignmentInBytesMask) == 0,
 213          "con_size_in_bytes is not multiple of alignment");
 214   const int hdr_size_in_bytes = instanceOopDesc::header_size() * HeapWordSize;
 215 
 216   initialize_header(obj, klass, noreg, t1, t2);
 217 
 218   if (!(UseTLAB && ZeroTLAB && is_tlab_allocated)) {
 219     // clear rest of allocated space
 220     const Register t1_zero = t1;
 221     const Register index = t2;
 222     const int threshold = 6 * BytesPerWord;   // approximate break even point for code size (see comments below)
 223     if (var_size_in_bytes != noreg) {
 224       mov(index, var_size_in_bytes);
 225       initialize_body(obj, index, hdr_size_in_bytes, t1_zero);
 226     } else if (con_size_in_bytes <= threshold) {
 227       // use explicit null stores
 228       // code size = 2 + 3*n bytes (n = number of fields to clear)


 265 
 266   // determine alignment mask
 267   assert(!(BytesPerWord & 1), "must be a multiple of 2 for masking code to work");
 268 
 269   // check for negative or excessive length
 270   cmpptr(len, (int32_t)max_array_allocation_length);
 271   jcc(Assembler::above, slow_case);
 272 
 273   const Register arr_size = t2; // okay to be the same
 274   // align object end
 275   movptr(arr_size, (int32_t)header_size * BytesPerWord + MinObjAlignmentInBytesMask);
 276   lea(arr_size, Address(arr_size, len, f));
 277   andptr(arr_size, ~MinObjAlignmentInBytesMask);
 278 
 279   try_allocate(obj, arr_size, 0, t1, t2, slow_case);
 280 
 281   initialize_header(obj, klass, len, t1, t2);
 282 
 283   // clear rest of allocated space
 284   const Register len_zero = len;
 285   // Initialize body destroys arr_size so remember it.
 286   push(arr_size);
 287   initialize_body(obj, arr_size, header_size * BytesPerWord, len_zero);
 288   pop(arr_size);
 289 
 290   if (CURRENT_ENV->dtrace_alloc_probes()) {
 291     assert(obj == rax, "must be");
 292     call(RuntimeAddress(Runtime1::entry_for(Runtime1::dtrace_object_alloc_id)));
 293   }
 294 
 295   HEAP_MONITORING(this, noreg, arr_size, 0, obj, t1, noreg,
 296                   call(RuntimeAddress(Runtime1::entry_for(
 297                       Runtime1::heap_object_sample_id))););
 298   verify_oop(obj);
 299 }
 300 
 301 
 302 
 303 void C1_MacroAssembler::inline_cache_check(Register receiver, Register iCache) {
 304   verify_oop(receiver);
 305   // explicit NULL check not needed since load from [klass_offset] causes a trap
 306   // check against inline cache
 307   assert(!MacroAssembler::needs_explicit_null_check(oopDesc::klass_offset_in_bytes()), "must add explicit null check");
 308   int start_offset = offset();
 309 
 310   if (UseCompressedClassPointers) {
 311     load_klass(rscratch1, receiver);
 312     cmpptr(rscratch1, iCache);
 313   } else {
 314     cmpptr(iCache, Address(receiver, oopDesc::klass_offset_in_bytes()));
 315   }
 316   // if icache check fails, then jump to runtime routine
 317   // Note: RECEIVER must still contain the receiver!


< prev index next >