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