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