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