src/share/vm/c1/c1_FrameMap.cpp

Tue, 18 Jun 2013 12:31:07 -0700

author
johnc
date
Tue, 18 Jun 2013 12:31:07 -0700
changeset 5277
01522ca68fc7
parent 4668
3c9db54c2660
child 6198
55fb97c4c58d
child 6466
6a936747b569
permissions
-rw-r--r--

8015237: Parallelize string table scanning during strong root processing
Summary: Parallelize the scanning of the intern string table by having each GC worker claim a given number of buckets. Changes were also reviewed by Per Liden <per.liden@oracle.com>.
Reviewed-by: tschatzl, stefank, twisti

duke@435 1 /*
mikael@4153 2 * Copyright (c) 2000, 2012, Oracle and/or its affiliates. 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 *
trims@1907 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1907 20 * or visit www.oracle.com if you need additional information or have any
trims@1907 21 * questions.
duke@435 22 *
duke@435 23 */
duke@435 24
stefank@2314 25 #include "precompiled.hpp"
stefank@2314 26 #include "c1/c1_FrameMap.hpp"
stefank@2314 27 #include "c1/c1_LIR.hpp"
stefank@2314 28 #include "runtime/sharedRuntime.hpp"
stefank@2314 29 #ifdef TARGET_ARCH_x86
stefank@2314 30 # include "vmreg_x86.inline.hpp"
stefank@2314 31 #endif
stefank@2314 32 #ifdef TARGET_ARCH_sparc
stefank@2314 33 # include "vmreg_sparc.inline.hpp"
stefank@2314 34 #endif
stefank@2314 35 #ifdef TARGET_ARCH_zero
stefank@2314 36 # include "vmreg_zero.inline.hpp"
stefank@2314 37 #endif
bobv@2508 38 #ifdef TARGET_ARCH_arm
bobv@2508 39 # include "vmreg_arm.inline.hpp"
bobv@2508 40 #endif
bobv@2508 41 #ifdef TARGET_ARCH_ppc
bobv@2508 42 # include "vmreg_ppc.inline.hpp"
bobv@2508 43 #endif
duke@435 44
duke@435 45
duke@435 46
duke@435 47 //-----------------------------------------------------
duke@435 48
duke@435 49 // Convert method signature into an array of BasicTypes for the arguments
duke@435 50 BasicTypeArray* FrameMap::signature_type_array_for(const ciMethod* method) {
duke@435 51 ciSignature* sig = method->signature();
duke@435 52 BasicTypeList* sta = new BasicTypeList(method->arg_size());
duke@435 53 // add receiver, if any
duke@435 54 if (!method->is_static()) sta->append(T_OBJECT);
duke@435 55 // add remaining arguments
duke@435 56 for (int i = 0; i < sig->count(); i++) {
duke@435 57 ciType* type = sig->type_at(i);
duke@435 58 BasicType t = type->basic_type();
duke@435 59 if (t == T_ARRAY) {
duke@435 60 t = T_OBJECT;
duke@435 61 }
duke@435 62 sta->append(t);
duke@435 63 }
duke@435 64 // done
duke@435 65 return sta;
duke@435 66 }
duke@435 67
duke@435 68
duke@435 69 CallingConvention* FrameMap::java_calling_convention(const BasicTypeArray* signature, bool outgoing) {
duke@435 70 // compute the size of the arguments first. The signature array
duke@435 71 // that java_calling_convention takes includes a T_VOID after double
duke@435 72 // work items but our signatures do not.
duke@435 73 int i;
duke@435 74 int sizeargs = 0;
duke@435 75 for (i = 0; i < signature->length(); i++) {
duke@435 76 sizeargs += type2size[signature->at(i)];
duke@435 77 }
duke@435 78
duke@435 79 BasicType* sig_bt = NEW_RESOURCE_ARRAY(BasicType, sizeargs);
duke@435 80 VMRegPair* regs = NEW_RESOURCE_ARRAY(VMRegPair, sizeargs);
duke@435 81 int sig_index = 0;
duke@435 82 for (i = 0; i < sizeargs; i++, sig_index++) {
duke@435 83 sig_bt[i] = signature->at(sig_index);
duke@435 84 if (sig_bt[i] == T_LONG || sig_bt[i] == T_DOUBLE) {
duke@435 85 sig_bt[i + 1] = T_VOID;
duke@435 86 i++;
duke@435 87 }
duke@435 88 }
duke@435 89
duke@435 90 intptr_t out_preserve = SharedRuntime::java_calling_convention(sig_bt, regs, sizeargs, outgoing);
duke@435 91 LIR_OprList* args = new LIR_OprList(signature->length());
duke@435 92 for (i = 0; i < sizeargs;) {
duke@435 93 BasicType t = sig_bt[i];
duke@435 94 assert(t != T_VOID, "should be skipping these");
duke@435 95 LIR_Opr opr = map_to_opr(t, regs + i, outgoing);
duke@435 96 args->append(opr);
duke@435 97 if (opr->is_address()) {
duke@435 98 LIR_Address* addr = opr->as_address_ptr();
duke@435 99 assert(addr->disp() == (int)addr->disp(), "out of range value");
iveresov@2416 100 out_preserve = MAX2(out_preserve, (intptr_t)(addr->disp() - STACK_BIAS) / 4);
duke@435 101 }
duke@435 102 i += type2size[t];
duke@435 103 }
duke@435 104 assert(args->length() == signature->length(), "size mismatch");
duke@435 105 out_preserve += SharedRuntime::out_preserve_stack_slots();
duke@435 106
duke@435 107 if (outgoing) {
duke@435 108 // update the space reserved for arguments.
bobv@2036 109 update_reserved_argument_area_size(out_preserve * BytesPerWord);
duke@435 110 }
duke@435 111 return new CallingConvention(args, out_preserve);
duke@435 112 }
duke@435 113
duke@435 114
duke@435 115 CallingConvention* FrameMap::c_calling_convention(const BasicTypeArray* signature) {
duke@435 116 // compute the size of the arguments first. The signature array
duke@435 117 // that java_calling_convention takes includes a T_VOID after double
duke@435 118 // work items but our signatures do not.
duke@435 119 int i;
duke@435 120 int sizeargs = 0;
duke@435 121 for (i = 0; i < signature->length(); i++) {
duke@435 122 sizeargs += type2size[signature->at(i)];
duke@435 123 }
duke@435 124
duke@435 125 BasicType* sig_bt = NEW_RESOURCE_ARRAY(BasicType, sizeargs);
duke@435 126 VMRegPair* regs = NEW_RESOURCE_ARRAY(VMRegPair, sizeargs);
duke@435 127 int sig_index = 0;
duke@435 128 for (i = 0; i < sizeargs; i++, sig_index++) {
duke@435 129 sig_bt[i] = signature->at(sig_index);
duke@435 130 if (sig_bt[i] == T_LONG || sig_bt[i] == T_DOUBLE) {
duke@435 131 sig_bt[i + 1] = T_VOID;
duke@435 132 i++;
duke@435 133 }
duke@435 134 }
duke@435 135
duke@435 136 intptr_t out_preserve = SharedRuntime::c_calling_convention(sig_bt, regs, sizeargs);
duke@435 137 LIR_OprList* args = new LIR_OprList(signature->length());
duke@435 138 for (i = 0; i < sizeargs;) {
duke@435 139 BasicType t = sig_bt[i];
duke@435 140 assert(t != T_VOID, "should be skipping these");
duke@435 141
duke@435 142 // C calls are always outgoing
duke@435 143 bool outgoing = true;
duke@435 144 LIR_Opr opr = map_to_opr(t, regs + i, outgoing);
duke@435 145 // they might be of different types if for instance floating point
duke@435 146 // values are passed in cpu registers, but the sizes must match.
duke@435 147 assert(type2size[opr->type()] == type2size[t], "type mismatch");
duke@435 148 args->append(opr);
duke@435 149 if (opr->is_address()) {
duke@435 150 LIR_Address* addr = opr->as_address_ptr();
iveresov@2416 151 out_preserve = MAX2(out_preserve, (intptr_t)(addr->disp() - STACK_BIAS) / 4);
duke@435 152 }
duke@435 153 i += type2size[t];
duke@435 154 }
duke@435 155 assert(args->length() == signature->length(), "size mismatch");
duke@435 156 out_preserve += SharedRuntime::out_preserve_stack_slots();
bobv@2036 157 update_reserved_argument_area_size(out_preserve * BytesPerWord);
duke@435 158 return new CallingConvention(args, out_preserve);
duke@435 159 }
duke@435 160
duke@435 161
duke@435 162 //--------------------------------------------------------
duke@435 163 // FrameMap
duke@435 164 //--------------------------------------------------------
duke@435 165
duke@435 166 bool FrameMap::_init_done = false;
duke@435 167 Register FrameMap::_cpu_rnr2reg [FrameMap::nof_cpu_regs];
duke@435 168 int FrameMap::_cpu_reg2rnr [FrameMap::nof_cpu_regs];
duke@435 169
duke@435 170
duke@435 171 FrameMap::FrameMap(ciMethod* method, int monitors, int reserved_argument_area_size) {
iveresov@1939 172 assert(_init_done, "should already be completed");
duke@435 173
duke@435 174 _framesize = -1;
duke@435 175 _num_spills = -1;
duke@435 176
duke@435 177 assert(monitors >= 0, "not set");
duke@435 178 _num_monitors = monitors;
duke@435 179 assert(reserved_argument_area_size >= 0, "not set");
duke@435 180 _reserved_argument_area_size = MAX2(4, reserved_argument_area_size) * BytesPerWord;
duke@435 181
duke@435 182 _argcount = method->arg_size();
duke@435 183 _argument_locations = new intArray(_argcount, -1);
duke@435 184 _incoming_arguments = java_calling_convention(signature_type_array_for(method), false);
duke@435 185 _oop_map_arg_count = _incoming_arguments->reserved_stack_slots();
duke@435 186
duke@435 187 int java_index = 0;
duke@435 188 for (int i = 0; i < _incoming_arguments->length(); i++) {
duke@435 189 LIR_Opr opr = _incoming_arguments->at(i);
duke@435 190 if (opr->is_address()) {
duke@435 191 LIR_Address* address = opr->as_address_ptr();
duke@435 192 _argument_locations->at_put(java_index, address->disp() - STACK_BIAS);
duke@435 193 _incoming_arguments->args()->at_put(i, LIR_OprFact::stack(java_index, as_BasicType(as_ValueType(address->type()))));
duke@435 194 }
duke@435 195 java_index += type2size[opr->type()];
duke@435 196 }
duke@435 197
duke@435 198 }
duke@435 199
duke@435 200
duke@435 201 bool FrameMap::finalize_frame(int nof_slots) {
duke@435 202 assert(nof_slots >= 0, "must be positive");
duke@435 203 assert(_num_spills == -1, "can only be set once");
duke@435 204 _num_spills = nof_slots;
duke@435 205 assert(_framesize == -1, "should only be calculated once");
duke@435 206 _framesize = round_to(in_bytes(sp_offset_for_monitor_base(0)) +
duke@435 207 _num_monitors * sizeof(BasicObjectLock) +
duke@435 208 sizeof(intptr_t) + // offset of deopt orig pc
duke@435 209 frame_pad_in_bytes,
duke@435 210 StackAlignmentInBytes) / 4;
duke@435 211 int java_index = 0;
duke@435 212 for (int i = 0; i < _incoming_arguments->length(); i++) {
duke@435 213 LIR_Opr opr = _incoming_arguments->at(i);
duke@435 214 if (opr->is_stack()) {
duke@435 215 _argument_locations->at_put(java_index, in_bytes(framesize_in_bytes()) +
duke@435 216 _argument_locations->at(java_index));
duke@435 217 }
duke@435 218 java_index += type2size[opr->type()];
duke@435 219 }
duke@435 220 // make sure it's expressible on the platform
duke@435 221 return validate_frame();
duke@435 222 }
duke@435 223
duke@435 224 VMReg FrameMap::sp_offset2vmreg(ByteSize offset) const {
duke@435 225 int offset_in_bytes = in_bytes(offset);
duke@435 226 assert(offset_in_bytes % 4 == 0, "must be multiple of 4 bytes");
duke@435 227 assert(offset_in_bytes / 4 < framesize() + oop_map_arg_count(), "out of range");
duke@435 228 return VMRegImpl::stack2reg(offset_in_bytes / 4);
duke@435 229 }
duke@435 230
duke@435 231
duke@435 232 bool FrameMap::location_for_sp_offset(ByteSize byte_offset_from_sp,
duke@435 233 Location::Type loc_type,
duke@435 234 Location* loc) const {
duke@435 235 int offset = in_bytes(byte_offset_from_sp);
duke@435 236 assert(offset >= 0, "incorrect offset");
duke@435 237 if (!Location::legal_offset_in_bytes(offset)) {
duke@435 238 return false;
duke@435 239 }
duke@435 240 Location tmp_loc = Location::new_stk_loc(loc_type, offset);
duke@435 241 *loc = tmp_loc;
duke@435 242 return true;
duke@435 243 }
duke@435 244
duke@435 245
duke@435 246 bool FrameMap::locations_for_slot (int index, Location::Type loc_type,
duke@435 247 Location* loc, Location* second) const {
duke@435 248 ByteSize offset_from_sp = sp_offset_for_slot(index);
duke@435 249 if (!location_for_sp_offset(offset_from_sp, loc_type, loc)) {
duke@435 250 return false;
duke@435 251 }
duke@435 252 if (second != NULL) {
duke@435 253 // two word item
duke@435 254 offset_from_sp = offset_from_sp + in_ByteSize(4);
duke@435 255 return location_for_sp_offset(offset_from_sp, loc_type, second);
duke@435 256 }
duke@435 257 return true;
duke@435 258 }
duke@435 259
duke@435 260 //////////////////////
duke@435 261 // Public accessors //
duke@435 262 //////////////////////
duke@435 263
duke@435 264
duke@435 265 ByteSize FrameMap::sp_offset_for_slot(const int index) const {
duke@435 266 if (index < argcount()) {
duke@435 267 int offset = _argument_locations->at(index);
duke@435 268 assert(offset != -1, "not a memory argument");
duke@435 269 assert(offset >= framesize() * 4, "argument inside of frame");
duke@435 270 return in_ByteSize(offset);
duke@435 271 }
duke@435 272 ByteSize offset = sp_offset_for_spill(index - argcount());
duke@435 273 assert(in_bytes(offset) < framesize() * 4, "spill outside of frame");
duke@435 274 return offset;
duke@435 275 }
duke@435 276
duke@435 277
duke@435 278 ByteSize FrameMap::sp_offset_for_double_slot(const int index) const {
duke@435 279 ByteSize offset = sp_offset_for_slot(index);
duke@435 280 if (index >= argcount()) {
duke@435 281 assert(in_bytes(offset) + 4 < framesize() * 4, "spill outside of frame");
duke@435 282 }
duke@435 283 return offset;
duke@435 284 }
duke@435 285
duke@435 286
duke@435 287 ByteSize FrameMap::sp_offset_for_spill(const int index) const {
duke@435 288 assert(index >= 0 && index < _num_spills, "out of range");
duke@435 289 int offset = round_to(first_available_sp_in_frame + _reserved_argument_area_size, sizeof(double)) +
duke@435 290 index * spill_slot_size_in_bytes;
duke@435 291 return in_ByteSize(offset);
duke@435 292 }
duke@435 293
duke@435 294 ByteSize FrameMap::sp_offset_for_monitor_base(const int index) const {
duke@435 295 int end_of_spills = round_to(first_available_sp_in_frame + _reserved_argument_area_size, sizeof(double)) +
duke@435 296 _num_spills * spill_slot_size_in_bytes;
never@739 297 int offset = (int) round_to(end_of_spills, HeapWordSize) + index * sizeof(BasicObjectLock);
duke@435 298 return in_ByteSize(offset);
duke@435 299 }
duke@435 300
duke@435 301 ByteSize FrameMap::sp_offset_for_monitor_lock(int index) const {
duke@435 302 check_monitor_index(index);
duke@435 303 return sp_offset_for_monitor_base(index) + in_ByteSize(BasicObjectLock::lock_offset_in_bytes());;
duke@435 304 }
duke@435 305
duke@435 306 ByteSize FrameMap::sp_offset_for_monitor_object(int index) const {
duke@435 307 check_monitor_index(index);
duke@435 308 return sp_offset_for_monitor_base(index) + in_ByteSize(BasicObjectLock::obj_offset_in_bytes());
duke@435 309 }
duke@435 310
duke@435 311
duke@435 312 // For OopMaps, map a local variable or spill index to an VMReg.
duke@435 313 // This is the offset from sp() in the frame of the slot for the index,
duke@435 314 // skewed by SharedInfo::stack0 to indicate a stack location (vs.a register.)
duke@435 315 //
duke@435 316 // C ABI size +
duke@435 317 // framesize + framesize +
duke@435 318 // stack0 stack0 stack0 0 <- VMReg->value()
duke@435 319 // | | | <registers> |
duke@435 320 // ..........|..............|..............|.............|
duke@435 321 // 0 1 2 3 | <C ABI area> | 4 5 6 ...... | <- local indices
duke@435 322 // ^ ^ sp()
duke@435 323 // | |
duke@435 324 // arguments non-argument locals
duke@435 325
duke@435 326
duke@435 327 VMReg FrameMap::regname(LIR_Opr opr) const {
duke@435 328 if (opr->is_single_cpu()) {
duke@435 329 assert(!opr->is_virtual(), "should not see virtual registers here");
duke@435 330 return opr->as_register()->as_VMReg();
duke@435 331 } else if (opr->is_single_stack()) {
duke@435 332 return sp_offset2vmreg(sp_offset_for_slot(opr->single_stack_ix()));
duke@435 333 } else if (opr->is_address()) {
duke@435 334 LIR_Address* addr = opr->as_address_ptr();
duke@435 335 assert(addr->base() == stack_pointer(), "sp based addressing only");
duke@435 336 return sp_offset2vmreg(in_ByteSize(addr->index()->as_jint()));
duke@435 337 }
duke@435 338 ShouldNotReachHere();
duke@435 339 return VMRegImpl::Bad();
duke@435 340 }
duke@435 341
duke@435 342
duke@435 343
duke@435 344
duke@435 345 // ------------ extra spill slots ---------------

mercurial