Print this page
rev 1081 : imported patch indy-cleanup-6893081.patch
Split |
Close |
Expand all |
Collapse all |
--- old/src/cpu/x86/vm/sharedRuntime_x86_64.cpp
+++ new/src/cpu/x86/vm/sharedRuntime_x86_64.cpp
1 1 /*
2 2 * Copyright 2003-2009 Sun Microsystems, Inc. All Rights Reserved.
3 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 4 *
5 5 * This code is free software; you can redistribute it and/or modify it
6 6 * under the terms of the GNU General Public License version 2 only, as
7 7 * published by the Free Software Foundation.
8 8 *
9 9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 12 * version 2 for more details (a copy is included in the LICENSE file that
13 13 * accompanied this code).
14 14 *
15 15 * You should have received a copy of the GNU General Public License version
16 16 * 2 along with this work; if not, write to the Free Software Foundation,
17 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 18 *
19 19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
20 20 * CA 95054 USA or visit www.sun.com if you need additional information or
21 21 * have any questions.
22 22 *
23 23 */
24 24
25 25 #include "incls/_precompiled.incl"
26 26 #include "incls/_sharedRuntime_x86_64.cpp.incl"
27 27
28 28 DeoptimizationBlob *SharedRuntime::_deopt_blob;
29 29 #ifdef COMPILER2
30 30 UncommonTrapBlob *SharedRuntime::_uncommon_trap_blob;
31 31 ExceptionBlob *OptoRuntime::_exception_blob;
32 32 #endif // COMPILER2
33 33
34 34 SafepointBlob *SharedRuntime::_polling_page_safepoint_handler_blob;
35 35 SafepointBlob *SharedRuntime::_polling_page_return_handler_blob;
36 36 RuntimeStub* SharedRuntime::_wrong_method_blob;
37 37 RuntimeStub* SharedRuntime::_ic_miss_blob;
38 38 RuntimeStub* SharedRuntime::_resolve_opt_virtual_call_blob;
39 39 RuntimeStub* SharedRuntime::_resolve_virtual_call_blob;
40 40 RuntimeStub* SharedRuntime::_resolve_static_call_blob;
41 41
42 42 const int StackAlignmentInSlots = StackAlignmentInBytes / VMRegImpl::stack_slot_size;
43 43
44 44 #define __ masm->
45 45
46 46 class SimpleRuntimeFrame {
47 47
48 48 public:
49 49
50 50 // Most of the runtime stubs have this simple frame layout.
51 51 // This class exists to make the layout shared in one place.
52 52 // Offsets are for compiler stack slots, which are jints.
53 53 enum layout {
54 54 // The frame sender code expects that rbp will be in the "natural" place and
55 55 // will override any oopMap setting for it. We must therefore force the layout
56 56 // so that it agrees with the frame sender code.
57 57 rbp_off = frame::arg_reg_save_area_bytes/BytesPerInt,
58 58 rbp_off2,
59 59 return_off, return_off2,
60 60 framesize
61 61 };
62 62 };
63 63
64 64 class RegisterSaver {
65 65 // Capture info about frame layout. Layout offsets are in jint
66 66 // units because compiler frame slots are jints.
67 67 #define DEF_XMM_OFFS(regnum) xmm ## regnum ## _off = xmm_off + (regnum)*16/BytesPerInt, xmm ## regnum ## H_off
68 68 enum layout {
69 69 fpu_state_off = frame::arg_reg_save_area_bytes/BytesPerInt, // fxsave save area
70 70 xmm_off = fpu_state_off + 160/BytesPerInt, // offset in fxsave save area
71 71 DEF_XMM_OFFS(0),
72 72 DEF_XMM_OFFS(1),
73 73 DEF_XMM_OFFS(2),
74 74 DEF_XMM_OFFS(3),
75 75 DEF_XMM_OFFS(4),
76 76 DEF_XMM_OFFS(5),
77 77 DEF_XMM_OFFS(6),
78 78 DEF_XMM_OFFS(7),
79 79 DEF_XMM_OFFS(8),
80 80 DEF_XMM_OFFS(9),
81 81 DEF_XMM_OFFS(10),
82 82 DEF_XMM_OFFS(11),
83 83 DEF_XMM_OFFS(12),
84 84 DEF_XMM_OFFS(13),
85 85 DEF_XMM_OFFS(14),
86 86 DEF_XMM_OFFS(15),
87 87 fpu_state_end = fpu_state_off + ((FPUStateSizeInWords-1)*wordSize / BytesPerInt),
88 88 fpu_stateH_end,
89 89 r15_off, r15H_off,
90 90 r14_off, r14H_off,
91 91 r13_off, r13H_off,
92 92 r12_off, r12H_off,
93 93 r11_off, r11H_off,
94 94 r10_off, r10H_off,
95 95 r9_off, r9H_off,
96 96 r8_off, r8H_off,
97 97 rdi_off, rdiH_off,
98 98 rsi_off, rsiH_off,
99 99 ignore_off, ignoreH_off, // extra copy of rbp
100 100 rsp_off, rspH_off,
101 101 rbx_off, rbxH_off,
102 102 rdx_off, rdxH_off,
103 103 rcx_off, rcxH_off,
104 104 rax_off, raxH_off,
105 105 // 16-byte stack alignment fill word: see MacroAssembler::push/pop_IU_state
106 106 align_off, alignH_off,
107 107 flags_off, flagsH_off,
108 108 // The frame sender code expects that rbp will be in the "natural" place and
109 109 // will override any oopMap setting for it. We must therefore force the layout
110 110 // so that it agrees with the frame sender code.
111 111 rbp_off, rbpH_off, // copy of rbp we will restore
112 112 return_off, returnH_off, // slot for return address
113 113 reg_save_size // size in compiler stack slots
114 114 };
115 115
116 116 public:
117 117 static OopMap* save_live_registers(MacroAssembler* masm, int additional_frame_words, int* total_frame_words);
118 118 static void restore_live_registers(MacroAssembler* masm);
119 119
120 120 // Offsets into the register save area
121 121 // Used by deoptimization when it is managing result register
122 122 // values on its own
123 123
124 124 static int rax_offset_in_bytes(void) { return BytesPerInt * rax_off; }
125 125 static int rdx_offset_in_bytes(void) { return BytesPerInt * rdx_off; }
126 126 static int rbx_offset_in_bytes(void) { return BytesPerInt * rbx_off; }
127 127 static int xmm0_offset_in_bytes(void) { return BytesPerInt * xmm0_off; }
128 128 static int return_offset_in_bytes(void) { return BytesPerInt * return_off; }
129 129
130 130 // During deoptimization only the result registers need to be restored,
131 131 // all the other values have already been extracted.
132 132 static void restore_result_registers(MacroAssembler* masm);
133 133 };
134 134
135 135 OopMap* RegisterSaver::save_live_registers(MacroAssembler* masm, int additional_frame_words, int* total_frame_words) {
136 136
137 137 // Always make the frame size 16-byte aligned
138 138 int frame_size_in_bytes = round_to(additional_frame_words*wordSize +
139 139 reg_save_size*BytesPerInt, 16);
140 140 // OopMap frame size is in compiler stack slots (jint's) not bytes or words
141 141 int frame_size_in_slots = frame_size_in_bytes / BytesPerInt;
142 142 // The caller will allocate additional_frame_words
143 143 int additional_frame_slots = additional_frame_words*wordSize / BytesPerInt;
144 144 // CodeBlob frame size is in words.
145 145 int frame_size_in_words = frame_size_in_bytes / wordSize;
146 146 *total_frame_words = frame_size_in_words;
147 147
148 148 // Save registers, fpu state, and flags.
149 149 // We assume caller has already pushed the return address onto the
150 150 // stack, so rsp is 8-byte aligned here.
151 151 // We push rpb twice in this sequence because we want the real rbp
152 152 // to be under the return like a normal enter.
153 153
154 154 __ enter(); // rsp becomes 16-byte aligned here
155 155 __ push_CPU_state(); // Push a multiple of 16 bytes
156 156 if (frame::arg_reg_save_area_bytes != 0) {
157 157 // Allocate argument register save area
158 158 __ subptr(rsp, frame::arg_reg_save_area_bytes);
159 159 }
160 160
161 161 // Set an oopmap for the call site. This oopmap will map all
162 162 // oop-registers and debug-info registers as callee-saved. This
163 163 // will allow deoptimization at this safepoint to find all possible
164 164 // debug-info recordings, as well as let GC find all oops.
165 165
166 166 OopMapSet *oop_maps = new OopMapSet();
167 167 OopMap* map = new OopMap(frame_size_in_slots, 0);
168 168 map->set_callee_saved(VMRegImpl::stack2reg( rax_off + additional_frame_slots), rax->as_VMReg());
169 169 map->set_callee_saved(VMRegImpl::stack2reg( rcx_off + additional_frame_slots), rcx->as_VMReg());
170 170 map->set_callee_saved(VMRegImpl::stack2reg( rdx_off + additional_frame_slots), rdx->as_VMReg());
171 171 map->set_callee_saved(VMRegImpl::stack2reg( rbx_off + additional_frame_slots), rbx->as_VMReg());
172 172 // rbp location is known implicitly by the frame sender code, needs no oopmap
173 173 // and the location where rbp was saved by is ignored
174 174 map->set_callee_saved(VMRegImpl::stack2reg( rsi_off + additional_frame_slots), rsi->as_VMReg());
175 175 map->set_callee_saved(VMRegImpl::stack2reg( rdi_off + additional_frame_slots), rdi->as_VMReg());
176 176 map->set_callee_saved(VMRegImpl::stack2reg( r8_off + additional_frame_slots), r8->as_VMReg());
177 177 map->set_callee_saved(VMRegImpl::stack2reg( r9_off + additional_frame_slots), r9->as_VMReg());
178 178 map->set_callee_saved(VMRegImpl::stack2reg( r10_off + additional_frame_slots), r10->as_VMReg());
179 179 map->set_callee_saved(VMRegImpl::stack2reg( r11_off + additional_frame_slots), r11->as_VMReg());
180 180 map->set_callee_saved(VMRegImpl::stack2reg( r12_off + additional_frame_slots), r12->as_VMReg());
181 181 map->set_callee_saved(VMRegImpl::stack2reg( r13_off + additional_frame_slots), r13->as_VMReg());
182 182 map->set_callee_saved(VMRegImpl::stack2reg( r14_off + additional_frame_slots), r14->as_VMReg());
183 183 map->set_callee_saved(VMRegImpl::stack2reg( r15_off + additional_frame_slots), r15->as_VMReg());
184 184 map->set_callee_saved(VMRegImpl::stack2reg(xmm0_off + additional_frame_slots), xmm0->as_VMReg());
185 185 map->set_callee_saved(VMRegImpl::stack2reg(xmm1_off + additional_frame_slots), xmm1->as_VMReg());
186 186 map->set_callee_saved(VMRegImpl::stack2reg(xmm2_off + additional_frame_slots), xmm2->as_VMReg());
187 187 map->set_callee_saved(VMRegImpl::stack2reg(xmm3_off + additional_frame_slots), xmm3->as_VMReg());
188 188 map->set_callee_saved(VMRegImpl::stack2reg(xmm4_off + additional_frame_slots), xmm4->as_VMReg());
189 189 map->set_callee_saved(VMRegImpl::stack2reg(xmm5_off + additional_frame_slots), xmm5->as_VMReg());
190 190 map->set_callee_saved(VMRegImpl::stack2reg(xmm6_off + additional_frame_slots), xmm6->as_VMReg());
191 191 map->set_callee_saved(VMRegImpl::stack2reg(xmm7_off + additional_frame_slots), xmm7->as_VMReg());
192 192 map->set_callee_saved(VMRegImpl::stack2reg(xmm8_off + additional_frame_slots), xmm8->as_VMReg());
193 193 map->set_callee_saved(VMRegImpl::stack2reg(xmm9_off + additional_frame_slots), xmm9->as_VMReg());
194 194 map->set_callee_saved(VMRegImpl::stack2reg(xmm10_off + additional_frame_slots), xmm10->as_VMReg());
195 195 map->set_callee_saved(VMRegImpl::stack2reg(xmm11_off + additional_frame_slots), xmm11->as_VMReg());
196 196 map->set_callee_saved(VMRegImpl::stack2reg(xmm12_off + additional_frame_slots), xmm12->as_VMReg());
197 197 map->set_callee_saved(VMRegImpl::stack2reg(xmm13_off + additional_frame_slots), xmm13->as_VMReg());
198 198 map->set_callee_saved(VMRegImpl::stack2reg(xmm14_off + additional_frame_slots), xmm14->as_VMReg());
199 199 map->set_callee_saved(VMRegImpl::stack2reg(xmm15_off + additional_frame_slots), xmm15->as_VMReg());
200 200
201 201 // %%% These should all be a waste but we'll keep things as they were for now
202 202 if (true) {
203 203 map->set_callee_saved(VMRegImpl::stack2reg( raxH_off + additional_frame_slots),
204 204 rax->as_VMReg()->next());
205 205 map->set_callee_saved(VMRegImpl::stack2reg( rcxH_off + additional_frame_slots),
206 206 rcx->as_VMReg()->next());
207 207 map->set_callee_saved(VMRegImpl::stack2reg( rdxH_off + additional_frame_slots),
208 208 rdx->as_VMReg()->next());
209 209 map->set_callee_saved(VMRegImpl::stack2reg( rbxH_off + additional_frame_slots),
210 210 rbx->as_VMReg()->next());
211 211 // rbp location is known implicitly by the frame sender code, needs no oopmap
212 212 map->set_callee_saved(VMRegImpl::stack2reg( rsiH_off + additional_frame_slots),
213 213 rsi->as_VMReg()->next());
214 214 map->set_callee_saved(VMRegImpl::stack2reg( rdiH_off + additional_frame_slots),
215 215 rdi->as_VMReg()->next());
216 216 map->set_callee_saved(VMRegImpl::stack2reg( r8H_off + additional_frame_slots),
217 217 r8->as_VMReg()->next());
218 218 map->set_callee_saved(VMRegImpl::stack2reg( r9H_off + additional_frame_slots),
219 219 r9->as_VMReg()->next());
220 220 map->set_callee_saved(VMRegImpl::stack2reg( r10H_off + additional_frame_slots),
221 221 r10->as_VMReg()->next());
222 222 map->set_callee_saved(VMRegImpl::stack2reg( r11H_off + additional_frame_slots),
223 223 r11->as_VMReg()->next());
224 224 map->set_callee_saved(VMRegImpl::stack2reg( r12H_off + additional_frame_slots),
225 225 r12->as_VMReg()->next());
226 226 map->set_callee_saved(VMRegImpl::stack2reg( r13H_off + additional_frame_slots),
227 227 r13->as_VMReg()->next());
228 228 map->set_callee_saved(VMRegImpl::stack2reg( r14H_off + additional_frame_slots),
229 229 r14->as_VMReg()->next());
230 230 map->set_callee_saved(VMRegImpl::stack2reg( r15H_off + additional_frame_slots),
231 231 r15->as_VMReg()->next());
232 232 map->set_callee_saved(VMRegImpl::stack2reg(xmm0H_off + additional_frame_slots),
233 233 xmm0->as_VMReg()->next());
234 234 map->set_callee_saved(VMRegImpl::stack2reg(xmm1H_off + additional_frame_slots),
235 235 xmm1->as_VMReg()->next());
236 236 map->set_callee_saved(VMRegImpl::stack2reg(xmm2H_off + additional_frame_slots),
237 237 xmm2->as_VMReg()->next());
238 238 map->set_callee_saved(VMRegImpl::stack2reg(xmm3H_off + additional_frame_slots),
239 239 xmm3->as_VMReg()->next());
240 240 map->set_callee_saved(VMRegImpl::stack2reg(xmm4H_off + additional_frame_slots),
241 241 xmm4->as_VMReg()->next());
242 242 map->set_callee_saved(VMRegImpl::stack2reg(xmm5H_off + additional_frame_slots),
243 243 xmm5->as_VMReg()->next());
244 244 map->set_callee_saved(VMRegImpl::stack2reg(xmm6H_off + additional_frame_slots),
245 245 xmm6->as_VMReg()->next());
246 246 map->set_callee_saved(VMRegImpl::stack2reg(xmm7H_off + additional_frame_slots),
247 247 xmm7->as_VMReg()->next());
248 248 map->set_callee_saved(VMRegImpl::stack2reg(xmm8H_off + additional_frame_slots),
249 249 xmm8->as_VMReg()->next());
250 250 map->set_callee_saved(VMRegImpl::stack2reg(xmm9H_off + additional_frame_slots),
251 251 xmm9->as_VMReg()->next());
252 252 map->set_callee_saved(VMRegImpl::stack2reg(xmm10H_off + additional_frame_slots),
253 253 xmm10->as_VMReg()->next());
254 254 map->set_callee_saved(VMRegImpl::stack2reg(xmm11H_off + additional_frame_slots),
255 255 xmm11->as_VMReg()->next());
256 256 map->set_callee_saved(VMRegImpl::stack2reg(xmm12H_off + additional_frame_slots),
257 257 xmm12->as_VMReg()->next());
258 258 map->set_callee_saved(VMRegImpl::stack2reg(xmm13H_off + additional_frame_slots),
259 259 xmm13->as_VMReg()->next());
260 260 map->set_callee_saved(VMRegImpl::stack2reg(xmm14H_off + additional_frame_slots),
261 261 xmm14->as_VMReg()->next());
262 262 map->set_callee_saved(VMRegImpl::stack2reg(xmm15H_off + additional_frame_slots),
263 263 xmm15->as_VMReg()->next());
264 264 }
265 265
266 266 return map;
267 267 }
268 268
269 269 void RegisterSaver::restore_live_registers(MacroAssembler* masm) {
270 270 if (frame::arg_reg_save_area_bytes != 0) {
271 271 // Pop arg register save area
272 272 __ addptr(rsp, frame::arg_reg_save_area_bytes);
273 273 }
274 274 // Recover CPU state
275 275 __ pop_CPU_state();
276 276 // Get the rbp described implicitly by the calling convention (no oopMap)
277 277 __ pop(rbp);
278 278 }
279 279
280 280 void RegisterSaver::restore_result_registers(MacroAssembler* masm) {
281 281
282 282 // Just restore result register. Only used by deoptimization. By
283 283 // now any callee save register that needs to be restored to a c2
284 284 // caller of the deoptee has been extracted into the vframeArray
285 285 // and will be stuffed into the c2i adapter we create for later
286 286 // restoration so only result registers need to be restored here.
287 287
288 288 // Restore fp result register
289 289 __ movdbl(xmm0, Address(rsp, xmm0_offset_in_bytes()));
290 290 // Restore integer result register
291 291 __ movptr(rax, Address(rsp, rax_offset_in_bytes()));
292 292 __ movptr(rdx, Address(rsp, rdx_offset_in_bytes()));
293 293
294 294 // Pop all of the register save are off the stack except the return address
295 295 __ addptr(rsp, return_offset_in_bytes());
296 296 }
297 297
298 298 // The java_calling_convention describes stack locations as ideal slots on
299 299 // a frame with no abi restrictions. Since we must observe abi restrictions
300 300 // (like the placement of the register window) the slots must be biased by
301 301 // the following value.
302 302 static int reg2offset_in(VMReg r) {
303 303 // Account for saved rbp and return address
304 304 // This should really be in_preserve_stack_slots
305 305 return (r->reg2stack() + 4) * VMRegImpl::stack_slot_size;
306 306 }
307 307
308 308 static int reg2offset_out(VMReg r) {
309 309 return (r->reg2stack() + SharedRuntime::out_preserve_stack_slots()) * VMRegImpl::stack_slot_size;
310 310 }
311 311
312 312 // ---------------------------------------------------------------------------
313 313 // Read the array of BasicTypes from a signature, and compute where the
314 314 // arguments should go. Values in the VMRegPair regs array refer to 4-byte
315 315 // quantities. Values less than VMRegImpl::stack0 are registers, those above
316 316 // refer to 4-byte stack slots. All stack slots are based off of the stack pointer
317 317 // as framesizes are fixed.
318 318 // VMRegImpl::stack0 refers to the first slot 0(sp).
319 319 // and VMRegImpl::stack0+1 refers to the memory word 4-byes higher. Register
320 320 // up to RegisterImpl::number_of_registers) are the 64-bit
321 321 // integer registers.
322 322
323 323 // Note: the INPUTS in sig_bt are in units of Java argument words, which are
324 324 // either 32-bit or 64-bit depending on the build. The OUTPUTS are in 32-bit
325 325 // units regardless of build. Of course for i486 there is no 64 bit build
326 326
327 327 // The Java calling convention is a "shifted" version of the C ABI.
328 328 // By skipping the first C ABI register we can call non-static jni methods
329 329 // with small numbers of arguments without having to shuffle the arguments
330 330 // at all. Since we control the java ABI we ought to at least get some
331 331 // advantage out of it.
332 332
333 333 int SharedRuntime::java_calling_convention(const BasicType *sig_bt,
334 334 VMRegPair *regs,
335 335 int total_args_passed,
336 336 int is_outgoing) {
337 337
338 338 // Create the mapping between argument positions and
339 339 // registers.
340 340 static const Register INT_ArgReg[Argument::n_int_register_parameters_j] = {
341 341 j_rarg0, j_rarg1, j_rarg2, j_rarg3, j_rarg4, j_rarg5
342 342 };
343 343 static const XMMRegister FP_ArgReg[Argument::n_float_register_parameters_j] = {
344 344 j_farg0, j_farg1, j_farg2, j_farg3,
345 345 j_farg4, j_farg5, j_farg6, j_farg7
346 346 };
347 347
348 348
349 349 uint int_args = 0;
350 350 uint fp_args = 0;
351 351 uint stk_args = 0; // inc by 2 each time
352 352
353 353 for (int i = 0; i < total_args_passed; i++) {
354 354 switch (sig_bt[i]) {
355 355 case T_BOOLEAN:
356 356 case T_CHAR:
357 357 case T_BYTE:
358 358 case T_SHORT:
359 359 case T_INT:
360 360 if (int_args < Argument::n_int_register_parameters_j) {
361 361 regs[i].set1(INT_ArgReg[int_args++]->as_VMReg());
362 362 } else {
363 363 regs[i].set1(VMRegImpl::stack2reg(stk_args));
364 364 stk_args += 2;
365 365 }
366 366 break;
367 367 case T_VOID:
368 368 // halves of T_LONG or T_DOUBLE
369 369 assert(i != 0 && (sig_bt[i - 1] == T_LONG || sig_bt[i - 1] == T_DOUBLE), "expecting half");
370 370 regs[i].set_bad();
371 371 break;
372 372 case T_LONG:
373 373 assert(sig_bt[i + 1] == T_VOID, "expecting half");
374 374 // fall through
375 375 case T_OBJECT:
376 376 case T_ARRAY:
377 377 case T_ADDRESS:
378 378 if (int_args < Argument::n_int_register_parameters_j) {
379 379 regs[i].set2(INT_ArgReg[int_args++]->as_VMReg());
380 380 } else {
381 381 regs[i].set2(VMRegImpl::stack2reg(stk_args));
382 382 stk_args += 2;
383 383 }
384 384 break;
385 385 case T_FLOAT:
386 386 if (fp_args < Argument::n_float_register_parameters_j) {
387 387 regs[i].set1(FP_ArgReg[fp_args++]->as_VMReg());
388 388 } else {
389 389 regs[i].set1(VMRegImpl::stack2reg(stk_args));
390 390 stk_args += 2;
391 391 }
392 392 break;
393 393 case T_DOUBLE:
394 394 assert(sig_bt[i + 1] == T_VOID, "expecting half");
395 395 if (fp_args < Argument::n_float_register_parameters_j) {
396 396 regs[i].set2(FP_ArgReg[fp_args++]->as_VMReg());
397 397 } else {
398 398 regs[i].set2(VMRegImpl::stack2reg(stk_args));
399 399 stk_args += 2;
400 400 }
401 401 break;
402 402 default:
403 403 ShouldNotReachHere();
404 404 break;
405 405 }
406 406 }
407 407
408 408 return round_to(stk_args, 2);
409 409 }
410 410
411 411 // Patch the callers callsite with entry to compiled code if it exists.
412 412 static void patch_callers_callsite(MacroAssembler *masm) {
413 413 Label L;
414 414 __ verify_oop(rbx);
415 415 __ cmpptr(Address(rbx, in_bytes(methodOopDesc::code_offset())), (int32_t)NULL_WORD);
416 416 __ jcc(Assembler::equal, L);
417 417
418 418 // Save the current stack pointer
419 419 __ mov(r13, rsp);
420 420 // Schedule the branch target address early.
421 421 // Call into the VM to patch the caller, then jump to compiled callee
422 422 // rax isn't live so capture return address while we easily can
423 423 __ movptr(rax, Address(rsp, 0));
424 424
425 425 // align stack so push_CPU_state doesn't fault
426 426 __ andptr(rsp, -(StackAlignmentInBytes));
427 427 __ push_CPU_state();
428 428
429 429
430 430 __ verify_oop(rbx);
431 431 // VM needs caller's callsite
432 432 // VM needs target method
433 433 // This needs to be a long call since we will relocate this adapter to
434 434 // the codeBuffer and it may not reach
435 435
436 436 // Allocate argument register save area
437 437 if (frame::arg_reg_save_area_bytes != 0) {
438 438 __ subptr(rsp, frame::arg_reg_save_area_bytes);
439 439 }
440 440 __ mov(c_rarg0, rbx);
441 441 __ mov(c_rarg1, rax);
442 442 __ call(RuntimeAddress(CAST_FROM_FN_PTR(address, SharedRuntime::fixup_callers_callsite)));
443 443
444 444 // De-allocate argument register save area
445 445 if (frame::arg_reg_save_area_bytes != 0) {
446 446 __ addptr(rsp, frame::arg_reg_save_area_bytes);
447 447 }
448 448
449 449 __ pop_CPU_state();
450 450 // restore sp
451 451 __ mov(rsp, r13);
452 452 __ bind(L);
453 453 }
454 454
455 455 // Helper function to put tags in interpreter stack.
456 456 static void tag_stack(MacroAssembler *masm, const BasicType sig, int st_off) {
457 457 if (TaggedStackInterpreter) {
458 458 int tag_offset = st_off + Interpreter::expr_tag_offset_in_bytes(0);
459 459 if (sig == T_OBJECT || sig == T_ARRAY) {
460 460 __ movptr(Address(rsp, tag_offset), (int32_t) frame::TagReference);
461 461 } else if (sig == T_LONG || sig == T_DOUBLE) {
462 462 int next_tag_offset = st_off + Interpreter::expr_tag_offset_in_bytes(1);
463 463 __ movptr(Address(rsp, next_tag_offset), (int32_t) frame::TagValue);
464 464 __ movptr(Address(rsp, tag_offset), (int32_t) frame::TagValue);
465 465 } else {
466 466 __ movptr(Address(rsp, tag_offset), (int32_t) frame::TagValue);
467 467 }
468 468 }
469 469 }
470 470
471 471
472 472 static void gen_c2i_adapter(MacroAssembler *masm,
473 473 int total_args_passed,
474 474 int comp_args_on_stack,
475 475 const BasicType *sig_bt,
476 476 const VMRegPair *regs,
477 477 Label& skip_fixup) {
478 478 // Before we get into the guts of the C2I adapter, see if we should be here
479 479 // at all. We've come from compiled code and are attempting to jump to the
480 480 // interpreter, which means the caller made a static call to get here
481 481 // (vcalls always get a compiled target if there is one). Check for a
482 482 // compiled target. If there is one, we need to patch the caller's call.
483 483 patch_callers_callsite(masm);
484 484
485 485 __ bind(skip_fixup);
486 486
487 487 // Since all args are passed on the stack, total_args_passed *
488 488 // Interpreter::stackElementSize is the space we need. Plus 1 because
489 489 // we also account for the return address location since
490 490 // we store it first rather than hold it in rax across all the shuffling
491 491
492 492 int extraspace = (total_args_passed * Interpreter::stackElementSize()) + wordSize;
493 493
494 494 // stack is aligned, keep it that way
495 495 extraspace = round_to(extraspace, 2*wordSize);
496 496
497 497 // Get return address
498 498 __ pop(rax);
499 499
500 500 // set senderSP value
501 501 __ mov(r13, rsp);
502 502
503 503 __ subptr(rsp, extraspace);
504 504
505 505 // Store the return address in the expected location
506 506 __ movptr(Address(rsp, 0), rax);
507 507
508 508 // Now write the args into the outgoing interpreter space
509 509 for (int i = 0; i < total_args_passed; i++) {
510 510 if (sig_bt[i] == T_VOID) {
511 511 assert(i > 0 && (sig_bt[i-1] == T_LONG || sig_bt[i-1] == T_DOUBLE), "missing half");
512 512 continue;
513 513 }
514 514
515 515 // offset to start parameters
516 516 int st_off = (total_args_passed - i) * Interpreter::stackElementSize() +
517 517 Interpreter::value_offset_in_bytes();
518 518 int next_off = st_off - Interpreter::stackElementSize();
519 519
520 520 // Say 4 args:
521 521 // i st_off
522 522 // 0 32 T_LONG
523 523 // 1 24 T_VOID
524 524 // 2 16 T_OBJECT
525 525 // 3 8 T_BOOL
526 526 // - 0 return address
527 527 //
528 528 // However to make thing extra confusing. Because we can fit a long/double in
529 529 // a single slot on a 64 bt vm and it would be silly to break them up, the interpreter
530 530 // leaves one slot empty and only stores to a single slot. In this case the
531 531 // slot that is occupied is the T_VOID slot. See I said it was confusing.
532 532
533 533 VMReg r_1 = regs[i].first();
534 534 VMReg r_2 = regs[i].second();
535 535 if (!r_1->is_valid()) {
536 536 assert(!r_2->is_valid(), "");
537 537 continue;
538 538 }
539 539 if (r_1->is_stack()) {
540 540 // memory to memory use rax
541 541 int ld_off = r_1->reg2stack() * VMRegImpl::stack_slot_size + extraspace;
542 542 if (!r_2->is_valid()) {
543 543 // sign extend??
544 544 __ movl(rax, Address(rsp, ld_off));
545 545 __ movptr(Address(rsp, st_off), rax);
546 546 tag_stack(masm, sig_bt[i], st_off);
547 547
548 548 } else {
549 549
550 550 __ movq(rax, Address(rsp, ld_off));
551 551
552 552 // Two VMREgs|OptoRegs can be T_OBJECT, T_ADDRESS, T_DOUBLE, T_LONG
553 553 // T_DOUBLE and T_LONG use two slots in the interpreter
554 554 if ( sig_bt[i] == T_LONG || sig_bt[i] == T_DOUBLE) {
555 555 // ld_off == LSW, ld_off+wordSize == MSW
556 556 // st_off == MSW, next_off == LSW
557 557 __ movq(Address(rsp, next_off), rax);
558 558 #ifdef ASSERT
559 559 // Overwrite the unused slot with known junk
560 560 __ mov64(rax, CONST64(0xdeadffffdeadaaaa));
561 561 __ movptr(Address(rsp, st_off), rax);
562 562 #endif /* ASSERT */
563 563 tag_stack(masm, sig_bt[i], next_off);
564 564 } else {
565 565 __ movq(Address(rsp, st_off), rax);
566 566 tag_stack(masm, sig_bt[i], st_off);
567 567 }
568 568 }
569 569 } else if (r_1->is_Register()) {
570 570 Register r = r_1->as_Register();
571 571 if (!r_2->is_valid()) {
572 572 // must be only an int (or less ) so move only 32bits to slot
573 573 // why not sign extend??
574 574 __ movl(Address(rsp, st_off), r);
575 575 tag_stack(masm, sig_bt[i], st_off);
576 576 } else {
577 577 // Two VMREgs|OptoRegs can be T_OBJECT, T_ADDRESS, T_DOUBLE, T_LONG
578 578 // T_DOUBLE and T_LONG use two slots in the interpreter
579 579 if ( sig_bt[i] == T_LONG || sig_bt[i] == T_DOUBLE) {
580 580 // long/double in gpr
581 581 #ifdef ASSERT
582 582 // Overwrite the unused slot with known junk
583 583 __ mov64(rax, CONST64(0xdeadffffdeadaaab));
584 584 __ movptr(Address(rsp, st_off), rax);
585 585 #endif /* ASSERT */
586 586 __ movq(Address(rsp, next_off), r);
587 587 tag_stack(masm, sig_bt[i], next_off);
588 588 } else {
589 589 __ movptr(Address(rsp, st_off), r);
590 590 tag_stack(masm, sig_bt[i], st_off);
591 591 }
592 592 }
593 593 } else {
594 594 assert(r_1->is_XMMRegister(), "");
595 595 if (!r_2->is_valid()) {
596 596 // only a float use just part of the slot
597 597 __ movflt(Address(rsp, st_off), r_1->as_XMMRegister());
598 598 tag_stack(masm, sig_bt[i], st_off);
599 599 } else {
600 600 #ifdef ASSERT
601 601 // Overwrite the unused slot with known junk
602 602 __ mov64(rax, CONST64(0xdeadffffdeadaaac));
603 603 __ movptr(Address(rsp, st_off), rax);
604 604 #endif /* ASSERT */
605 605 __ movdbl(Address(rsp, next_off), r_1->as_XMMRegister());
606 606 tag_stack(masm, sig_bt[i], next_off);
607 607 }
608 608 }
609 609 }
610 610
611 611 // Schedule the branch target address early.
612 612 __ movptr(rcx, Address(rbx, in_bytes(methodOopDesc::interpreter_entry_offset())));
613 613 __ jmp(rcx);
614 614 }
615 615
616 616 static void gen_i2c_adapter(MacroAssembler *masm,
617 617 int total_args_passed,
618 618 int comp_args_on_stack,
619 619 const BasicType *sig_bt,
620 620 const VMRegPair *regs) {
621 621
622 622 //
623 623 // We will only enter here from an interpreted frame and never from after
624 624 // passing thru a c2i. Azul allowed this but we do not. If we lose the
625 625 // race and use a c2i we will remain interpreted for the race loser(s).
626 626 // This removes all sorts of headaches on the x86 side and also eliminates
627 627 // the possibility of having c2i -> i2c -> c2i -> ... endless transitions.
628 628
629 629
630 630 // Note: r13 contains the senderSP on entry. We must preserve it since
↓ open down ↓ |
630 lines elided |
↑ open up ↑ |
631 631 // we may do a i2c -> c2i transition if we lose a race where compiled
632 632 // code goes non-entrant while we get args ready.
633 633 // In addition we use r13 to locate all the interpreter args as
634 634 // we must align the stack to 16 bytes on an i2c entry else we
635 635 // lose alignment we expect in all compiled code and register
636 636 // save code can segv when fxsave instructions find improperly
637 637 // aligned stack pointer.
638 638
639 639 __ movptr(rax, Address(rsp, 0));
640 640
641 + // Must preserve original SP for loading incoming arguments because
642 + // we need to align the outgoing SP for compiled code.
643 + __ movptr(r11, rsp);
644 +
641 645 // Cut-out for having no stack args. Since up to 2 int/oop args are passed
642 646 // in registers, we will occasionally have no stack args.
643 647 int comp_words_on_stack = 0;
644 648 if (comp_args_on_stack) {
645 649 // Sig words on the stack are greater-than VMRegImpl::stack0. Those in
646 650 // registers are below. By subtracting stack0, we either get a negative
647 651 // number (all values in registers) or the maximum stack slot accessed.
648 652
649 653 // Convert 4-byte c2 stack slots to words.
650 654 comp_words_on_stack = round_to(comp_args_on_stack*VMRegImpl::stack_slot_size, wordSize)>>LogBytesPerWord;
651 655 // Round up to miminum stack alignment, in wordSize
652 656 comp_words_on_stack = round_to(comp_words_on_stack, 2);
653 657 __ subptr(rsp, comp_words_on_stack * wordSize);
↓ open down ↓ |
3 lines elided |
↑ open up ↑ |
654 658 }
655 659
656 660
657 661 // Ensure compiled code always sees stack at proper alignment
658 662 __ andptr(rsp, -16);
659 663
660 664 // push the return address and misalign the stack that youngest frame always sees
661 665 // as far as the placement of the call instruction
662 666 __ push(rax);
663 667
668 + // Put saved SP in another register
669 + const Register saved_sp = rax;
670 + __ movptr(saved_sp, r11);
671 +
664 672 // Will jump to the compiled code just as if compiled code was doing it.
665 673 // Pre-load the register-jump target early, to schedule it better.
666 674 __ movptr(r11, Address(rbx, in_bytes(methodOopDesc::from_compiled_offset())));
667 675
668 676 // Now generate the shuffle code. Pick up all register args and move the
669 677 // rest through the floating point stack top.
670 678 for (int i = 0; i < total_args_passed; i++) {
671 679 if (sig_bt[i] == T_VOID) {
672 680 // Longs and doubles are passed in native word order, but misaligned
673 681 // in the 32-bit build.
674 682 assert(i > 0 && (sig_bt[i-1] == T_LONG || sig_bt[i-1] == T_DOUBLE), "missing half");
675 683 continue;
676 684 }
677 685
678 686 // Pick up 0, 1 or 2 words from SP+offset.
679 687
680 688 assert(!regs[i].second()->is_valid() || regs[i].first()->next() == regs[i].second(),
681 689 "scrambled load targets?");
682 690 // Load in argument order going down.
683 - // int ld_off = (total_args_passed + comp_words_on_stack -i)*wordSize;
684 - // base ld_off on r13 (sender_sp) as the stack alignment makes offsets from rsp
685 - // unpredictable
686 - int ld_off = ((total_args_passed - 1) - i)*Interpreter::stackElementSize();
687 -
691 + int ld_off = (total_args_passed - i)*Interpreter::stackElementSize() + Interpreter::value_offset_in_bytes();
688 692 // Point to interpreter value (vs. tag)
689 693 int next_off = ld_off - Interpreter::stackElementSize();
690 694 //
691 695 //
692 696 //
693 697 VMReg r_1 = regs[i].first();
694 698 VMReg r_2 = regs[i].second();
695 699 if (!r_1->is_valid()) {
696 700 assert(!r_2->is_valid(), "");
697 701 continue;
698 702 }
699 703 if (r_1->is_stack()) {
700 704 // Convert stack slot to an SP offset (+ wordSize to account for return address )
701 705 int st_off = regs[i].first()->reg2stack()*VMRegImpl::stack_slot_size + wordSize;
706 +
707 + // We can use r13 as a temp here because compiled code doesn't need r13 as an input
708 + // and if we end up going thru a c2i because of a miss a reasonable value of r13
709 + // will be generated.
702 710 if (!r_2->is_valid()) {
703 711 // sign extend???
704 - __ movl(rax, Address(r13, ld_off));
705 - __ movptr(Address(rsp, st_off), rax);
712 + __ movl(r13, Address(saved_sp, ld_off));
713 + __ movptr(Address(rsp, st_off), r13);
706 714 } else {
707 715 //
708 716 // We are using two optoregs. This can be either T_OBJECT, T_ADDRESS, T_LONG, or T_DOUBLE
709 717 // the interpreter allocates two slots but only uses one for thr T_LONG or T_DOUBLE case
710 718 // So we must adjust where to pick up the data to match the interpreter.
711 719 //
712 720 // Interpreter local[n] == MSW, local[n+1] == LSW however locals
713 721 // are accessed as negative so LSW is at LOW address
714 722
715 723 // ld_off is MSW so get LSW
716 724 const int offset = (sig_bt[i]==T_LONG||sig_bt[i]==T_DOUBLE)?
717 725 next_off : ld_off;
718 - __ movq(rax, Address(r13, offset));
726 + __ movq(r13, Address(saved_sp, offset));
719 727 // st_off is LSW (i.e. reg.first())
720 - __ movq(Address(rsp, st_off), rax);
728 + __ movq(Address(rsp, st_off), r13);
721 729 }
722 730 } else if (r_1->is_Register()) { // Register argument
723 731 Register r = r_1->as_Register();
724 732 assert(r != rax, "must be different");
725 733 if (r_2->is_valid()) {
726 734 //
727 735 // We are using two VMRegs. This can be either T_OBJECT, T_ADDRESS, T_LONG, or T_DOUBLE
728 736 // the interpreter allocates two slots but only uses one for thr T_LONG or T_DOUBLE case
729 737 // So we must adjust where to pick up the data to match the interpreter.
730 738
731 739 const int offset = (sig_bt[i]==T_LONG||sig_bt[i]==T_DOUBLE)?
732 740 next_off : ld_off;
733 741
734 742 // this can be a misaligned move
735 - __ movq(r, Address(r13, offset));
743 + __ movq(r, Address(saved_sp, offset));
736 744 } else {
737 745 // sign extend and use a full word?
738 - __ movl(r, Address(r13, ld_off));
746 + __ movl(r, Address(saved_sp, ld_off));
739 747 }
740 748 } else {
741 749 if (!r_2->is_valid()) {
742 - __ movflt(r_1->as_XMMRegister(), Address(r13, ld_off));
750 + __ movflt(r_1->as_XMMRegister(), Address(saved_sp, ld_off));
743 751 } else {
744 - __ movdbl(r_1->as_XMMRegister(), Address(r13, next_off));
752 + __ movdbl(r_1->as_XMMRegister(), Address(saved_sp, next_off));
745 753 }
746 754 }
747 755 }
748 756
749 757 // 6243940 We might end up in handle_wrong_method if
750 758 // the callee is deoptimized as we race thru here. If that
751 759 // happens we don't want to take a safepoint because the
752 760 // caller frame will look interpreted and arguments are now
753 761 // "compiled" so it is much better to make this transition
754 762 // invisible to the stack walking code. Unfortunately if
755 763 // we try and find the callee by normal means a safepoint
756 764 // is possible. So we stash the desired callee in the thread
757 765 // and the vm will find there should this case occur.
758 766
759 767 __ movptr(Address(r15_thread, JavaThread::callee_target_offset()), rbx);
760 768
761 769 // put methodOop where a c2i would expect should we end up there
762 770 // only needed becaus eof c2 resolve stubs return methodOop as a result in
763 771 // rax
764 772 __ mov(rax, rbx);
765 773 __ jmp(r11);
766 774 }
767 775
768 776 // ---------------------------------------------------------------
769 777 AdapterHandlerEntry* SharedRuntime::generate_i2c2i_adapters(MacroAssembler *masm,
770 778 int total_args_passed,
771 779 int comp_args_on_stack,
772 780 const BasicType *sig_bt,
773 781 const VMRegPair *regs) {
774 782 address i2c_entry = __ pc();
775 783
776 784 gen_i2c_adapter(masm, total_args_passed, comp_args_on_stack, sig_bt, regs);
777 785
778 786 // -------------------------------------------------------------------------
779 787 // Generate a C2I adapter. On entry we know rbx holds the methodOop during calls
780 788 // to the interpreter. The args start out packed in the compiled layout. They
781 789 // need to be unpacked into the interpreter layout. This will almost always
782 790 // require some stack space. We grow the current (compiled) stack, then repack
783 791 // the args. We finally end in a jump to the generic interpreter entry point.
784 792 // On exit from the interpreter, the interpreter will restore our SP (lest the
785 793 // compiled code, which relys solely on SP and not RBP, get sick).
786 794
787 795 address c2i_unverified_entry = __ pc();
788 796 Label skip_fixup;
789 797 Label ok;
790 798
791 799 Register holder = rax;
792 800 Register receiver = j_rarg0;
793 801 Register temp = rbx;
794 802
795 803 {
796 804 __ verify_oop(holder);
797 805 __ load_klass(temp, receiver);
798 806 __ verify_oop(temp);
799 807
800 808 __ cmpptr(temp, Address(holder, compiledICHolderOopDesc::holder_klass_offset()));
801 809 __ movptr(rbx, Address(holder, compiledICHolderOopDesc::holder_method_offset()));
802 810 __ jcc(Assembler::equal, ok);
803 811 __ jump(RuntimeAddress(SharedRuntime::get_ic_miss_stub()));
804 812
805 813 __ bind(ok);
806 814 // Method might have been compiled since the call site was patched to
807 815 // interpreted if that is the case treat it as a miss so we can get
808 816 // the call site corrected.
809 817 __ cmpptr(Address(rbx, in_bytes(methodOopDesc::code_offset())), (int32_t)NULL_WORD);
810 818 __ jcc(Assembler::equal, skip_fixup);
811 819 __ jump(RuntimeAddress(SharedRuntime::get_ic_miss_stub()));
812 820 }
813 821
814 822 address c2i_entry = __ pc();
815 823
816 824 gen_c2i_adapter(masm, total_args_passed, comp_args_on_stack, sig_bt, regs, skip_fixup);
817 825
818 826 __ flush();
819 827 return new AdapterHandlerEntry(i2c_entry, c2i_entry, c2i_unverified_entry);
820 828 }
821 829
822 830 int SharedRuntime::c_calling_convention(const BasicType *sig_bt,
823 831 VMRegPair *regs,
824 832 int total_args_passed) {
825 833 // We return the amount of VMRegImpl stack slots we need to reserve for all
826 834 // the arguments NOT counting out_preserve_stack_slots.
827 835
828 836 // NOTE: These arrays will have to change when c1 is ported
829 837 #ifdef _WIN64
830 838 static const Register INT_ArgReg[Argument::n_int_register_parameters_c] = {
831 839 c_rarg0, c_rarg1, c_rarg2, c_rarg3
832 840 };
833 841 static const XMMRegister FP_ArgReg[Argument::n_float_register_parameters_c] = {
834 842 c_farg0, c_farg1, c_farg2, c_farg3
835 843 };
836 844 #else
837 845 static const Register INT_ArgReg[Argument::n_int_register_parameters_c] = {
838 846 c_rarg0, c_rarg1, c_rarg2, c_rarg3, c_rarg4, c_rarg5
839 847 };
840 848 static const XMMRegister FP_ArgReg[Argument::n_float_register_parameters_c] = {
841 849 c_farg0, c_farg1, c_farg2, c_farg3,
842 850 c_farg4, c_farg5, c_farg6, c_farg7
843 851 };
844 852 #endif // _WIN64
845 853
846 854
847 855 uint int_args = 0;
848 856 uint fp_args = 0;
849 857 uint stk_args = 0; // inc by 2 each time
850 858
851 859 for (int i = 0; i < total_args_passed; i++) {
852 860 switch (sig_bt[i]) {
853 861 case T_BOOLEAN:
854 862 case T_CHAR:
855 863 case T_BYTE:
856 864 case T_SHORT:
857 865 case T_INT:
858 866 if (int_args < Argument::n_int_register_parameters_c) {
859 867 regs[i].set1(INT_ArgReg[int_args++]->as_VMReg());
860 868 #ifdef _WIN64
861 869 fp_args++;
862 870 // Allocate slots for callee to stuff register args the stack.
863 871 stk_args += 2;
864 872 #endif
865 873 } else {
866 874 regs[i].set1(VMRegImpl::stack2reg(stk_args));
867 875 stk_args += 2;
868 876 }
869 877 break;
870 878 case T_LONG:
871 879 assert(sig_bt[i + 1] == T_VOID, "expecting half");
872 880 // fall through
873 881 case T_OBJECT:
874 882 case T_ARRAY:
875 883 case T_ADDRESS:
876 884 if (int_args < Argument::n_int_register_parameters_c) {
877 885 regs[i].set2(INT_ArgReg[int_args++]->as_VMReg());
878 886 #ifdef _WIN64
879 887 fp_args++;
880 888 stk_args += 2;
881 889 #endif
882 890 } else {
883 891 regs[i].set2(VMRegImpl::stack2reg(stk_args));
884 892 stk_args += 2;
885 893 }
886 894 break;
887 895 case T_FLOAT:
888 896 if (fp_args < Argument::n_float_register_parameters_c) {
889 897 regs[i].set1(FP_ArgReg[fp_args++]->as_VMReg());
890 898 #ifdef _WIN64
891 899 int_args++;
892 900 // Allocate slots for callee to stuff register args the stack.
893 901 stk_args += 2;
894 902 #endif
895 903 } else {
896 904 regs[i].set1(VMRegImpl::stack2reg(stk_args));
897 905 stk_args += 2;
898 906 }
899 907 break;
900 908 case T_DOUBLE:
901 909 assert(sig_bt[i + 1] == T_VOID, "expecting half");
902 910 if (fp_args < Argument::n_float_register_parameters_c) {
903 911 regs[i].set2(FP_ArgReg[fp_args++]->as_VMReg());
904 912 #ifdef _WIN64
905 913 int_args++;
906 914 // Allocate slots for callee to stuff register args the stack.
907 915 stk_args += 2;
908 916 #endif
909 917 } else {
910 918 regs[i].set2(VMRegImpl::stack2reg(stk_args));
911 919 stk_args += 2;
912 920 }
913 921 break;
914 922 case T_VOID: // Halves of longs and doubles
915 923 assert(i != 0 && (sig_bt[i - 1] == T_LONG || sig_bt[i - 1] == T_DOUBLE), "expecting half");
916 924 regs[i].set_bad();
917 925 break;
918 926 default:
919 927 ShouldNotReachHere();
920 928 break;
921 929 }
922 930 }
923 931 #ifdef _WIN64
924 932 // windows abi requires that we always allocate enough stack space
925 933 // for 4 64bit registers to be stored down.
926 934 if (stk_args < 8) {
927 935 stk_args = 8;
928 936 }
929 937 #endif // _WIN64
930 938
931 939 return stk_args;
932 940 }
933 941
934 942 // On 64 bit we will store integer like items to the stack as
935 943 // 64 bits items (sparc abi) even though java would only store
936 944 // 32bits for a parameter. On 32bit it will simply be 32 bits
937 945 // So this routine will do 32->32 on 32bit and 32->64 on 64bit
938 946 static void move32_64(MacroAssembler* masm, VMRegPair src, VMRegPair dst) {
939 947 if (src.first()->is_stack()) {
940 948 if (dst.first()->is_stack()) {
941 949 // stack to stack
942 950 __ movslq(rax, Address(rbp, reg2offset_in(src.first())));
943 951 __ movq(Address(rsp, reg2offset_out(dst.first())), rax);
944 952 } else {
945 953 // stack to reg
946 954 __ movslq(dst.first()->as_Register(), Address(rbp, reg2offset_in(src.first())));
947 955 }
948 956 } else if (dst.first()->is_stack()) {
949 957 // reg to stack
950 958 // Do we really have to sign extend???
951 959 // __ movslq(src.first()->as_Register(), src.first()->as_Register());
952 960 __ movq(Address(rsp, reg2offset_out(dst.first())), src.first()->as_Register());
953 961 } else {
954 962 // Do we really have to sign extend???
955 963 // __ movslq(dst.first()->as_Register(), src.first()->as_Register());
956 964 if (dst.first() != src.first()) {
957 965 __ movq(dst.first()->as_Register(), src.first()->as_Register());
958 966 }
959 967 }
960 968 }
961 969
962 970
963 971 // An oop arg. Must pass a handle not the oop itself
964 972 static void object_move(MacroAssembler* masm,
965 973 OopMap* map,
966 974 int oop_handle_offset,
967 975 int framesize_in_slots,
968 976 VMRegPair src,
969 977 VMRegPair dst,
970 978 bool is_receiver,
971 979 int* receiver_offset) {
972 980
973 981 // must pass a handle. First figure out the location we use as a handle
974 982
975 983 Register rHandle = dst.first()->is_stack() ? rax : dst.first()->as_Register();
976 984
977 985 // See if oop is NULL if it is we need no handle
978 986
979 987 if (src.first()->is_stack()) {
980 988
981 989 // Oop is already on the stack as an argument
982 990 int offset_in_older_frame = src.first()->reg2stack() + SharedRuntime::out_preserve_stack_slots();
983 991 map->set_oop(VMRegImpl::stack2reg(offset_in_older_frame + framesize_in_slots));
984 992 if (is_receiver) {
985 993 *receiver_offset = (offset_in_older_frame + framesize_in_slots) * VMRegImpl::stack_slot_size;
986 994 }
987 995
988 996 __ cmpptr(Address(rbp, reg2offset_in(src.first())), (int32_t)NULL_WORD);
989 997 __ lea(rHandle, Address(rbp, reg2offset_in(src.first())));
990 998 // conditionally move a NULL
991 999 __ cmovptr(Assembler::equal, rHandle, Address(rbp, reg2offset_in(src.first())));
992 1000 } else {
993 1001
994 1002 // Oop is in an a register we must store it to the space we reserve
995 1003 // on the stack for oop_handles and pass a handle if oop is non-NULL
996 1004
997 1005 const Register rOop = src.first()->as_Register();
998 1006 int oop_slot;
999 1007 if (rOop == j_rarg0)
1000 1008 oop_slot = 0;
1001 1009 else if (rOop == j_rarg1)
1002 1010 oop_slot = 1;
1003 1011 else if (rOop == j_rarg2)
1004 1012 oop_slot = 2;
1005 1013 else if (rOop == j_rarg3)
1006 1014 oop_slot = 3;
1007 1015 else if (rOop == j_rarg4)
1008 1016 oop_slot = 4;
1009 1017 else {
1010 1018 assert(rOop == j_rarg5, "wrong register");
1011 1019 oop_slot = 5;
1012 1020 }
1013 1021
1014 1022 oop_slot = oop_slot * VMRegImpl::slots_per_word + oop_handle_offset;
1015 1023 int offset = oop_slot*VMRegImpl::stack_slot_size;
1016 1024
1017 1025 map->set_oop(VMRegImpl::stack2reg(oop_slot));
1018 1026 // Store oop in handle area, may be NULL
1019 1027 __ movptr(Address(rsp, offset), rOop);
1020 1028 if (is_receiver) {
1021 1029 *receiver_offset = offset;
1022 1030 }
1023 1031
1024 1032 __ cmpptr(rOop, (int32_t)NULL_WORD);
1025 1033 __ lea(rHandle, Address(rsp, offset));
1026 1034 // conditionally move a NULL from the handle area where it was just stored
1027 1035 __ cmovptr(Assembler::equal, rHandle, Address(rsp, offset));
1028 1036 }
1029 1037
1030 1038 // If arg is on the stack then place it otherwise it is already in correct reg.
1031 1039 if (dst.first()->is_stack()) {
1032 1040 __ movptr(Address(rsp, reg2offset_out(dst.first())), rHandle);
1033 1041 }
1034 1042 }
1035 1043
1036 1044 // A float arg may have to do float reg int reg conversion
1037 1045 static void float_move(MacroAssembler* masm, VMRegPair src, VMRegPair dst) {
1038 1046 assert(!src.second()->is_valid() && !dst.second()->is_valid(), "bad float_move");
1039 1047
1040 1048 // The calling conventions assures us that each VMregpair is either
1041 1049 // all really one physical register or adjacent stack slots.
1042 1050 // This greatly simplifies the cases here compared to sparc.
1043 1051
1044 1052 if (src.first()->is_stack()) {
1045 1053 if (dst.first()->is_stack()) {
1046 1054 __ movl(rax, Address(rbp, reg2offset_in(src.first())));
1047 1055 __ movptr(Address(rsp, reg2offset_out(dst.first())), rax);
1048 1056 } else {
1049 1057 // stack to reg
1050 1058 assert(dst.first()->is_XMMRegister(), "only expect xmm registers as parameters");
1051 1059 __ movflt(dst.first()->as_XMMRegister(), Address(rbp, reg2offset_in(src.first())));
1052 1060 }
1053 1061 } else if (dst.first()->is_stack()) {
1054 1062 // reg to stack
1055 1063 assert(src.first()->is_XMMRegister(), "only expect xmm registers as parameters");
1056 1064 __ movflt(Address(rsp, reg2offset_out(dst.first())), src.first()->as_XMMRegister());
1057 1065 } else {
1058 1066 // reg to reg
1059 1067 // In theory these overlap but the ordering is such that this is likely a nop
1060 1068 if ( src.first() != dst.first()) {
1061 1069 __ movdbl(dst.first()->as_XMMRegister(), src.first()->as_XMMRegister());
1062 1070 }
1063 1071 }
1064 1072 }
1065 1073
1066 1074 // A long move
1067 1075 static void long_move(MacroAssembler* masm, VMRegPair src, VMRegPair dst) {
1068 1076
1069 1077 // The calling conventions assures us that each VMregpair is either
1070 1078 // all really one physical register or adjacent stack slots.
1071 1079 // This greatly simplifies the cases here compared to sparc.
1072 1080
1073 1081 if (src.is_single_phys_reg() ) {
1074 1082 if (dst.is_single_phys_reg()) {
1075 1083 if (dst.first() != src.first()) {
1076 1084 __ mov(dst.first()->as_Register(), src.first()->as_Register());
1077 1085 }
1078 1086 } else {
1079 1087 assert(dst.is_single_reg(), "not a stack pair");
1080 1088 __ movq(Address(rsp, reg2offset_out(dst.first())), src.first()->as_Register());
1081 1089 }
1082 1090 } else if (dst.is_single_phys_reg()) {
1083 1091 assert(src.is_single_reg(), "not a stack pair");
1084 1092 __ movq(dst.first()->as_Register(), Address(rbp, reg2offset_out(src.first())));
1085 1093 } else {
1086 1094 assert(src.is_single_reg() && dst.is_single_reg(), "not stack pairs");
1087 1095 __ movq(rax, Address(rbp, reg2offset_in(src.first())));
1088 1096 __ movq(Address(rsp, reg2offset_out(dst.first())), rax);
1089 1097 }
1090 1098 }
1091 1099
1092 1100 // A double move
1093 1101 static void double_move(MacroAssembler* masm, VMRegPair src, VMRegPair dst) {
1094 1102
1095 1103 // The calling conventions assures us that each VMregpair is either
1096 1104 // all really one physical register or adjacent stack slots.
1097 1105 // This greatly simplifies the cases here compared to sparc.
1098 1106
1099 1107 if (src.is_single_phys_reg() ) {
1100 1108 if (dst.is_single_phys_reg()) {
1101 1109 // In theory these overlap but the ordering is such that this is likely a nop
1102 1110 if ( src.first() != dst.first()) {
1103 1111 __ movdbl(dst.first()->as_XMMRegister(), src.first()->as_XMMRegister());
1104 1112 }
1105 1113 } else {
1106 1114 assert(dst.is_single_reg(), "not a stack pair");
1107 1115 __ movdbl(Address(rsp, reg2offset_out(dst.first())), src.first()->as_XMMRegister());
1108 1116 }
1109 1117 } else if (dst.is_single_phys_reg()) {
1110 1118 assert(src.is_single_reg(), "not a stack pair");
1111 1119 __ movdbl(dst.first()->as_XMMRegister(), Address(rbp, reg2offset_out(src.first())));
1112 1120 } else {
1113 1121 assert(src.is_single_reg() && dst.is_single_reg(), "not stack pairs");
1114 1122 __ movq(rax, Address(rbp, reg2offset_in(src.first())));
1115 1123 __ movq(Address(rsp, reg2offset_out(dst.first())), rax);
1116 1124 }
1117 1125 }
1118 1126
1119 1127
1120 1128 void SharedRuntime::save_native_result(MacroAssembler *masm, BasicType ret_type, int frame_slots) {
1121 1129 // We always ignore the frame_slots arg and just use the space just below frame pointer
1122 1130 // which by this time is free to use
1123 1131 switch (ret_type) {
1124 1132 case T_FLOAT:
1125 1133 __ movflt(Address(rbp, -wordSize), xmm0);
1126 1134 break;
1127 1135 case T_DOUBLE:
1128 1136 __ movdbl(Address(rbp, -wordSize), xmm0);
1129 1137 break;
1130 1138 case T_VOID: break;
1131 1139 default: {
1132 1140 __ movptr(Address(rbp, -wordSize), rax);
1133 1141 }
1134 1142 }
1135 1143 }
1136 1144
1137 1145 void SharedRuntime::restore_native_result(MacroAssembler *masm, BasicType ret_type, int frame_slots) {
1138 1146 // We always ignore the frame_slots arg and just use the space just below frame pointer
1139 1147 // which by this time is free to use
1140 1148 switch (ret_type) {
1141 1149 case T_FLOAT:
1142 1150 __ movflt(xmm0, Address(rbp, -wordSize));
1143 1151 break;
1144 1152 case T_DOUBLE:
1145 1153 __ movdbl(xmm0, Address(rbp, -wordSize));
1146 1154 break;
1147 1155 case T_VOID: break;
1148 1156 default: {
1149 1157 __ movptr(rax, Address(rbp, -wordSize));
1150 1158 }
1151 1159 }
1152 1160 }
1153 1161
1154 1162 static void save_args(MacroAssembler *masm, int arg_count, int first_arg, VMRegPair *args) {
1155 1163 for ( int i = first_arg ; i < arg_count ; i++ ) {
1156 1164 if (args[i].first()->is_Register()) {
1157 1165 __ push(args[i].first()->as_Register());
1158 1166 } else if (args[i].first()->is_XMMRegister()) {
1159 1167 __ subptr(rsp, 2*wordSize);
1160 1168 __ movdbl(Address(rsp, 0), args[i].first()->as_XMMRegister());
1161 1169 }
1162 1170 }
1163 1171 }
1164 1172
1165 1173 static void restore_args(MacroAssembler *masm, int arg_count, int first_arg, VMRegPair *args) {
1166 1174 for ( int i = arg_count - 1 ; i >= first_arg ; i-- ) {
1167 1175 if (args[i].first()->is_Register()) {
1168 1176 __ pop(args[i].first()->as_Register());
1169 1177 } else if (args[i].first()->is_XMMRegister()) {
1170 1178 __ movdbl(args[i].first()->as_XMMRegister(), Address(rsp, 0));
1171 1179 __ addptr(rsp, 2*wordSize);
1172 1180 }
1173 1181 }
1174 1182 }
1175 1183
1176 1184 // ---------------------------------------------------------------------------
1177 1185 // Generate a native wrapper for a given method. The method takes arguments
1178 1186 // in the Java compiled code convention, marshals them to the native
1179 1187 // convention (handlizes oops, etc), transitions to native, makes the call,
1180 1188 // returns to java state (possibly blocking), unhandlizes any result and
1181 1189 // returns.
1182 1190 nmethod *SharedRuntime::generate_native_wrapper(MacroAssembler *masm,
1183 1191 methodHandle method,
1184 1192 int total_in_args,
1185 1193 int comp_args_on_stack,
1186 1194 BasicType *in_sig_bt,
1187 1195 VMRegPair *in_regs,
1188 1196 BasicType ret_type) {
1189 1197 // Native nmethod wrappers never take possesion of the oop arguments.
1190 1198 // So the caller will gc the arguments. The only thing we need an
1191 1199 // oopMap for is if the call is static
1192 1200 //
1193 1201 // An OopMap for lock (and class if static)
1194 1202 OopMapSet *oop_maps = new OopMapSet();
1195 1203 intptr_t start = (intptr_t)__ pc();
1196 1204
1197 1205 // We have received a description of where all the java arg are located
1198 1206 // on entry to the wrapper. We need to convert these args to where
1199 1207 // the jni function will expect them. To figure out where they go
1200 1208 // we convert the java signature to a C signature by inserting
1201 1209 // the hidden arguments as arg[0] and possibly arg[1] (static method)
1202 1210
1203 1211 int total_c_args = total_in_args + 1;
1204 1212 if (method->is_static()) {
1205 1213 total_c_args++;
1206 1214 }
1207 1215
1208 1216 BasicType* out_sig_bt = NEW_RESOURCE_ARRAY(BasicType, total_c_args);
1209 1217 VMRegPair* out_regs = NEW_RESOURCE_ARRAY(VMRegPair, total_c_args);
1210 1218
1211 1219 int argc = 0;
1212 1220 out_sig_bt[argc++] = T_ADDRESS;
1213 1221 if (method->is_static()) {
1214 1222 out_sig_bt[argc++] = T_OBJECT;
1215 1223 }
1216 1224
1217 1225 for (int i = 0; i < total_in_args ; i++ ) {
1218 1226 out_sig_bt[argc++] = in_sig_bt[i];
1219 1227 }
1220 1228
1221 1229 // Now figure out where the args must be stored and how much stack space
1222 1230 // they require.
1223 1231 //
1224 1232 int out_arg_slots;
1225 1233 out_arg_slots = c_calling_convention(out_sig_bt, out_regs, total_c_args);
1226 1234
1227 1235 // Compute framesize for the wrapper. We need to handlize all oops in
1228 1236 // incoming registers
1229 1237
1230 1238 // Calculate the total number of stack slots we will need.
1231 1239
1232 1240 // First count the abi requirement plus all of the outgoing args
1233 1241 int stack_slots = SharedRuntime::out_preserve_stack_slots() + out_arg_slots;
1234 1242
1235 1243 // Now the space for the inbound oop handle area
1236 1244
1237 1245 int oop_handle_offset = stack_slots;
1238 1246 stack_slots += 6*VMRegImpl::slots_per_word;
1239 1247
1240 1248 // Now any space we need for handlizing a klass if static method
1241 1249
1242 1250 int oop_temp_slot_offset = 0;
1243 1251 int klass_slot_offset = 0;
1244 1252 int klass_offset = -1;
1245 1253 int lock_slot_offset = 0;
1246 1254 bool is_static = false;
1247 1255
1248 1256 if (method->is_static()) {
1249 1257 klass_slot_offset = stack_slots;
1250 1258 stack_slots += VMRegImpl::slots_per_word;
1251 1259 klass_offset = klass_slot_offset * VMRegImpl::stack_slot_size;
1252 1260 is_static = true;
1253 1261 }
1254 1262
1255 1263 // Plus a lock if needed
1256 1264
1257 1265 if (method->is_synchronized()) {
1258 1266 lock_slot_offset = stack_slots;
1259 1267 stack_slots += VMRegImpl::slots_per_word;
1260 1268 }
1261 1269
1262 1270 // Now a place (+2) to save return values or temp during shuffling
1263 1271 // + 4 for return address (which we own) and saved rbp
1264 1272 stack_slots += 6;
1265 1273
1266 1274 // Ok The space we have allocated will look like:
1267 1275 //
1268 1276 //
1269 1277 // FP-> | |
1270 1278 // |---------------------|
1271 1279 // | 2 slots for moves |
1272 1280 // |---------------------|
1273 1281 // | lock box (if sync) |
1274 1282 // |---------------------| <- lock_slot_offset
1275 1283 // | klass (if static) |
1276 1284 // |---------------------| <- klass_slot_offset
1277 1285 // | oopHandle area |
1278 1286 // |---------------------| <- oop_handle_offset (6 java arg registers)
1279 1287 // | outbound memory |
1280 1288 // | based arguments |
1281 1289 // | |
1282 1290 // |---------------------|
1283 1291 // | |
1284 1292 // SP-> | out_preserved_slots |
1285 1293 //
1286 1294 //
1287 1295
1288 1296
1289 1297 // Now compute actual number of stack words we need rounding to make
1290 1298 // stack properly aligned.
1291 1299 stack_slots = round_to(stack_slots, StackAlignmentInSlots);
1292 1300
1293 1301 int stack_size = stack_slots * VMRegImpl::stack_slot_size;
1294 1302
1295 1303
1296 1304 // First thing make an ic check to see if we should even be here
1297 1305
1298 1306 // We are free to use all registers as temps without saving them and
1299 1307 // restoring them except rbp. rbp is the only callee save register
1300 1308 // as far as the interpreter and the compiler(s) are concerned.
1301 1309
1302 1310
1303 1311 const Register ic_reg = rax;
1304 1312 const Register receiver = j_rarg0;
1305 1313
1306 1314 Label ok;
1307 1315 Label exception_pending;
1308 1316
1309 1317 assert_different_registers(ic_reg, receiver, rscratch1);
1310 1318 __ verify_oop(receiver);
1311 1319 __ load_klass(rscratch1, receiver);
1312 1320 __ cmpq(ic_reg, rscratch1);
1313 1321 __ jcc(Assembler::equal, ok);
1314 1322
1315 1323 __ jump(RuntimeAddress(SharedRuntime::get_ic_miss_stub()));
1316 1324
1317 1325 __ bind(ok);
1318 1326
1319 1327 // Verified entry point must be aligned
1320 1328 __ align(8);
1321 1329
1322 1330 int vep_offset = ((intptr_t)__ pc()) - start;
1323 1331
1324 1332 // The instruction at the verified entry point must be 5 bytes or longer
1325 1333 // because it can be patched on the fly by make_non_entrant. The stack bang
1326 1334 // instruction fits that requirement.
1327 1335
1328 1336 // Generate stack overflow check
1329 1337
1330 1338 if (UseStackBanging) {
1331 1339 __ bang_stack_with_offset(StackShadowPages*os::vm_page_size());
1332 1340 } else {
1333 1341 // need a 5 byte instruction to allow MT safe patching to non-entrant
1334 1342 __ fat_nop();
1335 1343 }
1336 1344
1337 1345 // Generate a new frame for the wrapper.
1338 1346 __ enter();
1339 1347 // -2 because return address is already present and so is saved rbp
1340 1348 __ subptr(rsp, stack_size - 2*wordSize);
1341 1349
1342 1350 // Frame is now completed as far as size and linkage.
1343 1351
1344 1352 int frame_complete = ((intptr_t)__ pc()) - start;
1345 1353
1346 1354 #ifdef ASSERT
1347 1355 {
1348 1356 Label L;
1349 1357 __ mov(rax, rsp);
1350 1358 __ andptr(rax, -16); // must be 16 byte boundary (see amd64 ABI)
1351 1359 __ cmpptr(rax, rsp);
1352 1360 __ jcc(Assembler::equal, L);
1353 1361 __ stop("improperly aligned stack");
1354 1362 __ bind(L);
1355 1363 }
1356 1364 #endif /* ASSERT */
1357 1365
1358 1366
1359 1367 // We use r14 as the oop handle for the receiver/klass
1360 1368 // It is callee save so it survives the call to native
1361 1369
1362 1370 const Register oop_handle_reg = r14;
1363 1371
1364 1372
1365 1373
1366 1374 //
1367 1375 // We immediately shuffle the arguments so that any vm call we have to
1368 1376 // make from here on out (sync slow path, jvmti, etc.) we will have
1369 1377 // captured the oops from our caller and have a valid oopMap for
1370 1378 // them.
1371 1379
1372 1380 // -----------------
1373 1381 // The Grand Shuffle
1374 1382
1375 1383 // The Java calling convention is either equal (linux) or denser (win64) than the
1376 1384 // c calling convention. However the because of the jni_env argument the c calling
1377 1385 // convention always has at least one more (and two for static) arguments than Java.
1378 1386 // Therefore if we move the args from java -> c backwards then we will never have
1379 1387 // a register->register conflict and we don't have to build a dependency graph
1380 1388 // and figure out how to break any cycles.
1381 1389 //
1382 1390
1383 1391 // Record esp-based slot for receiver on stack for non-static methods
1384 1392 int receiver_offset = -1;
1385 1393
1386 1394 // This is a trick. We double the stack slots so we can claim
1387 1395 // the oops in the caller's frame. Since we are sure to have
1388 1396 // more args than the caller doubling is enough to make
1389 1397 // sure we can capture all the incoming oop args from the
1390 1398 // caller.
1391 1399 //
1392 1400 OopMap* map = new OopMap(stack_slots * 2, 0 /* arg_slots*/);
1393 1401
1394 1402 // Mark location of rbp (someday)
1395 1403 // map->set_callee_saved(VMRegImpl::stack2reg( stack_slots - 2), stack_slots * 2, 0, vmreg(rbp));
1396 1404
1397 1405 // Use eax, ebx as temporaries during any memory-memory moves we have to do
1398 1406 // All inbound args are referenced based on rbp and all outbound args via rsp.
1399 1407
1400 1408
1401 1409 #ifdef ASSERT
1402 1410 bool reg_destroyed[RegisterImpl::number_of_registers];
1403 1411 bool freg_destroyed[XMMRegisterImpl::number_of_registers];
1404 1412 for ( int r = 0 ; r < RegisterImpl::number_of_registers ; r++ ) {
1405 1413 reg_destroyed[r] = false;
1406 1414 }
1407 1415 for ( int f = 0 ; f < XMMRegisterImpl::number_of_registers ; f++ ) {
1408 1416 freg_destroyed[f] = false;
1409 1417 }
1410 1418
1411 1419 #endif /* ASSERT */
1412 1420
1413 1421
1414 1422 int c_arg = total_c_args - 1;
1415 1423 for ( int i = total_in_args - 1; i >= 0 ; i--, c_arg-- ) {
1416 1424 #ifdef ASSERT
1417 1425 if (in_regs[i].first()->is_Register()) {
1418 1426 assert(!reg_destroyed[in_regs[i].first()->as_Register()->encoding()], "destroyed reg!");
1419 1427 } else if (in_regs[i].first()->is_XMMRegister()) {
1420 1428 assert(!freg_destroyed[in_regs[i].first()->as_XMMRegister()->encoding()], "destroyed reg!");
1421 1429 }
1422 1430 if (out_regs[c_arg].first()->is_Register()) {
1423 1431 reg_destroyed[out_regs[c_arg].first()->as_Register()->encoding()] = true;
1424 1432 } else if (out_regs[c_arg].first()->is_XMMRegister()) {
1425 1433 freg_destroyed[out_regs[c_arg].first()->as_XMMRegister()->encoding()] = true;
1426 1434 }
1427 1435 #endif /* ASSERT */
1428 1436 switch (in_sig_bt[i]) {
1429 1437 case T_ARRAY:
1430 1438 case T_OBJECT:
1431 1439 object_move(masm, map, oop_handle_offset, stack_slots, in_regs[i], out_regs[c_arg],
1432 1440 ((i == 0) && (!is_static)),
1433 1441 &receiver_offset);
1434 1442 break;
1435 1443 case T_VOID:
1436 1444 break;
1437 1445
1438 1446 case T_FLOAT:
1439 1447 float_move(masm, in_regs[i], out_regs[c_arg]);
1440 1448 break;
1441 1449
1442 1450 case T_DOUBLE:
1443 1451 assert( i + 1 < total_in_args &&
1444 1452 in_sig_bt[i + 1] == T_VOID &&
1445 1453 out_sig_bt[c_arg+1] == T_VOID, "bad arg list");
1446 1454 double_move(masm, in_regs[i], out_regs[c_arg]);
1447 1455 break;
1448 1456
1449 1457 case T_LONG :
1450 1458 long_move(masm, in_regs[i], out_regs[c_arg]);
1451 1459 break;
1452 1460
1453 1461 case T_ADDRESS: assert(false, "found T_ADDRESS in java args");
1454 1462
1455 1463 default:
1456 1464 move32_64(masm, in_regs[i], out_regs[c_arg]);
1457 1465 }
1458 1466 }
1459 1467
1460 1468 // point c_arg at the first arg that is already loaded in case we
1461 1469 // need to spill before we call out
1462 1470 c_arg++;
1463 1471
1464 1472 // Pre-load a static method's oop into r14. Used both by locking code and
1465 1473 // the normal JNI call code.
1466 1474 if (method->is_static()) {
1467 1475
1468 1476 // load oop into a register
1469 1477 __ movoop(oop_handle_reg, JNIHandles::make_local(Klass::cast(method->method_holder())->java_mirror()));
1470 1478
1471 1479 // Now handlize the static class mirror it's known not-null.
1472 1480 __ movptr(Address(rsp, klass_offset), oop_handle_reg);
1473 1481 map->set_oop(VMRegImpl::stack2reg(klass_slot_offset));
1474 1482
1475 1483 // Now get the handle
1476 1484 __ lea(oop_handle_reg, Address(rsp, klass_offset));
1477 1485 // store the klass handle as second argument
1478 1486 __ movptr(c_rarg1, oop_handle_reg);
1479 1487 // and protect the arg if we must spill
1480 1488 c_arg--;
1481 1489 }
1482 1490
1483 1491 // Change state to native (we save the return address in the thread, since it might not
1484 1492 // be pushed on the stack when we do a a stack traversal). It is enough that the pc()
1485 1493 // points into the right code segment. It does not have to be the correct return pc.
1486 1494 // We use the same pc/oopMap repeatedly when we call out
1487 1495
1488 1496 intptr_t the_pc = (intptr_t) __ pc();
1489 1497 oop_maps->add_gc_map(the_pc - start, map);
1490 1498
1491 1499 __ set_last_Java_frame(rsp, noreg, (address)the_pc);
1492 1500
1493 1501
1494 1502 // We have all of the arguments setup at this point. We must not touch any register
1495 1503 // argument registers at this point (what if we save/restore them there are no oop?
1496 1504
1497 1505 {
1498 1506 SkipIfEqual skip(masm, &DTraceMethodProbes, false);
1499 1507 // protect the args we've loaded
1500 1508 save_args(masm, total_c_args, c_arg, out_regs);
1501 1509 __ movoop(c_rarg1, JNIHandles::make_local(method()));
1502 1510 __ call_VM_leaf(
1503 1511 CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_method_entry),
1504 1512 r15_thread, c_rarg1);
1505 1513 restore_args(masm, total_c_args, c_arg, out_regs);
1506 1514 }
1507 1515
1508 1516 // RedefineClasses() tracing support for obsolete method entry
1509 1517 if (RC_TRACE_IN_RANGE(0x00001000, 0x00002000)) {
1510 1518 // protect the args we've loaded
1511 1519 save_args(masm, total_c_args, c_arg, out_regs);
1512 1520 __ movoop(c_rarg1, JNIHandles::make_local(method()));
1513 1521 __ call_VM_leaf(
1514 1522 CAST_FROM_FN_PTR(address, SharedRuntime::rc_trace_method_entry),
1515 1523 r15_thread, c_rarg1);
1516 1524 restore_args(masm, total_c_args, c_arg, out_regs);
1517 1525 }
1518 1526
1519 1527 // Lock a synchronized method
1520 1528
1521 1529 // Register definitions used by locking and unlocking
1522 1530
1523 1531 const Register swap_reg = rax; // Must use rax for cmpxchg instruction
1524 1532 const Register obj_reg = rbx; // Will contain the oop
1525 1533 const Register lock_reg = r13; // Address of compiler lock object (BasicLock)
1526 1534 const Register old_hdr = r13; // value of old header at unlock time
1527 1535
1528 1536 Label slow_path_lock;
1529 1537 Label lock_done;
1530 1538
1531 1539 if (method->is_synchronized()) {
1532 1540
1533 1541
1534 1542 const int mark_word_offset = BasicLock::displaced_header_offset_in_bytes();
1535 1543
1536 1544 // Get the handle (the 2nd argument)
1537 1545 __ mov(oop_handle_reg, c_rarg1);
1538 1546
1539 1547 // Get address of the box
1540 1548
1541 1549 __ lea(lock_reg, Address(rsp, lock_slot_offset * VMRegImpl::stack_slot_size));
1542 1550
1543 1551 // Load the oop from the handle
1544 1552 __ movptr(obj_reg, Address(oop_handle_reg, 0));
1545 1553
1546 1554 if (UseBiasedLocking) {
1547 1555 __ biased_locking_enter(lock_reg, obj_reg, swap_reg, rscratch1, false, lock_done, &slow_path_lock);
1548 1556 }
1549 1557
1550 1558 // Load immediate 1 into swap_reg %rax
1551 1559 __ movl(swap_reg, 1);
1552 1560
1553 1561 // Load (object->mark() | 1) into swap_reg %rax
1554 1562 __ orptr(swap_reg, Address(obj_reg, 0));
1555 1563
1556 1564 // Save (object->mark() | 1) into BasicLock's displaced header
1557 1565 __ movptr(Address(lock_reg, mark_word_offset), swap_reg);
1558 1566
1559 1567 if (os::is_MP()) {
1560 1568 __ lock();
1561 1569 }
1562 1570
1563 1571 // src -> dest iff dest == rax else rax <- dest
1564 1572 __ cmpxchgptr(lock_reg, Address(obj_reg, 0));
1565 1573 __ jcc(Assembler::equal, lock_done);
1566 1574
1567 1575 // Hmm should this move to the slow path code area???
1568 1576
1569 1577 // Test if the oopMark is an obvious stack pointer, i.e.,
1570 1578 // 1) (mark & 3) == 0, and
1571 1579 // 2) rsp <= mark < mark + os::pagesize()
1572 1580 // These 3 tests can be done by evaluating the following
1573 1581 // expression: ((mark - rsp) & (3 - os::vm_page_size())),
1574 1582 // assuming both stack pointer and pagesize have their
1575 1583 // least significant 2 bits clear.
1576 1584 // NOTE: the oopMark is in swap_reg %rax as the result of cmpxchg
1577 1585
1578 1586 __ subptr(swap_reg, rsp);
1579 1587 __ andptr(swap_reg, 3 - os::vm_page_size());
1580 1588
1581 1589 // Save the test result, for recursive case, the result is zero
1582 1590 __ movptr(Address(lock_reg, mark_word_offset), swap_reg);
1583 1591 __ jcc(Assembler::notEqual, slow_path_lock);
1584 1592
1585 1593 // Slow path will re-enter here
1586 1594
1587 1595 __ bind(lock_done);
1588 1596 }
1589 1597
1590 1598
1591 1599 // Finally just about ready to make the JNI call
1592 1600
1593 1601
1594 1602 // get JNIEnv* which is first argument to native
1595 1603
1596 1604 __ lea(c_rarg0, Address(r15_thread, in_bytes(JavaThread::jni_environment_offset())));
1597 1605
1598 1606 // Now set thread in native
1599 1607 __ movl(Address(r15_thread, JavaThread::thread_state_offset()), _thread_in_native);
1600 1608
1601 1609 __ call(RuntimeAddress(method->native_function()));
1602 1610
1603 1611 // Either restore the MXCSR register after returning from the JNI Call
1604 1612 // or verify that it wasn't changed.
1605 1613 if (RestoreMXCSROnJNICalls) {
1606 1614 __ ldmxcsr(ExternalAddress(StubRoutines::x86::mxcsr_std()));
1607 1615
1608 1616 }
1609 1617 else if (CheckJNICalls ) {
1610 1618 __ call(RuntimeAddress(CAST_FROM_FN_PTR(address, StubRoutines::x86::verify_mxcsr_entry())));
1611 1619 }
1612 1620
1613 1621
1614 1622 // Unpack native results.
1615 1623 switch (ret_type) {
1616 1624 case T_BOOLEAN: __ c2bool(rax); break;
1617 1625 case T_CHAR : __ movzwl(rax, rax); break;
1618 1626 case T_BYTE : __ sign_extend_byte (rax); break;
1619 1627 case T_SHORT : __ sign_extend_short(rax); break;
1620 1628 case T_INT : /* nothing to do */ break;
1621 1629 case T_DOUBLE :
1622 1630 case T_FLOAT :
1623 1631 // Result is in xmm0 we'll save as needed
1624 1632 break;
1625 1633 case T_ARRAY: // Really a handle
1626 1634 case T_OBJECT: // Really a handle
1627 1635 break; // can't de-handlize until after safepoint check
1628 1636 case T_VOID: break;
1629 1637 case T_LONG: break;
1630 1638 default : ShouldNotReachHere();
1631 1639 }
1632 1640
1633 1641 // Switch thread to "native transition" state before reading the synchronization state.
1634 1642 // This additional state is necessary because reading and testing the synchronization
1635 1643 // state is not atomic w.r.t. GC, as this scenario demonstrates:
1636 1644 // Java thread A, in _thread_in_native state, loads _not_synchronized and is preempted.
1637 1645 // VM thread changes sync state to synchronizing and suspends threads for GC.
1638 1646 // Thread A is resumed to finish this native method, but doesn't block here since it
1639 1647 // didn't see any synchronization is progress, and escapes.
1640 1648 __ movl(Address(r15_thread, JavaThread::thread_state_offset()), _thread_in_native_trans);
1641 1649
1642 1650 if(os::is_MP()) {
1643 1651 if (UseMembar) {
1644 1652 // Force this write out before the read below
1645 1653 __ membar(Assembler::Membar_mask_bits(
1646 1654 Assembler::LoadLoad | Assembler::LoadStore |
1647 1655 Assembler::StoreLoad | Assembler::StoreStore));
1648 1656 } else {
1649 1657 // Write serialization page so VM thread can do a pseudo remote membar.
1650 1658 // We use the current thread pointer to calculate a thread specific
1651 1659 // offset to write to within the page. This minimizes bus traffic
1652 1660 // due to cache line collision.
1653 1661 __ serialize_memory(r15_thread, rcx);
1654 1662 }
1655 1663 }
1656 1664
1657 1665
1658 1666 // check for safepoint operation in progress and/or pending suspend requests
1659 1667 {
1660 1668 Label Continue;
1661 1669
1662 1670 __ cmp32(ExternalAddress((address)SafepointSynchronize::address_of_state()),
1663 1671 SafepointSynchronize::_not_synchronized);
1664 1672
1665 1673 Label L;
1666 1674 __ jcc(Assembler::notEqual, L);
1667 1675 __ cmpl(Address(r15_thread, JavaThread::suspend_flags_offset()), 0);
1668 1676 __ jcc(Assembler::equal, Continue);
1669 1677 __ bind(L);
1670 1678
1671 1679 // Don't use call_VM as it will see a possible pending exception and forward it
1672 1680 // and never return here preventing us from clearing _last_native_pc down below.
1673 1681 // Also can't use call_VM_leaf either as it will check to see if rsi & rdi are
1674 1682 // preserved and correspond to the bcp/locals pointers. So we do a runtime call
1675 1683 // by hand.
1676 1684 //
1677 1685 save_native_result(masm, ret_type, stack_slots);
1678 1686 __ mov(c_rarg0, r15_thread);
1679 1687 __ mov(r12, rsp); // remember sp
1680 1688 __ subptr(rsp, frame::arg_reg_save_area_bytes); // windows
1681 1689 __ andptr(rsp, -16); // align stack as required by ABI
1682 1690 __ call(RuntimeAddress(CAST_FROM_FN_PTR(address, JavaThread::check_special_condition_for_native_trans)));
1683 1691 __ mov(rsp, r12); // restore sp
1684 1692 __ reinit_heapbase();
1685 1693 // Restore any method result value
1686 1694 restore_native_result(masm, ret_type, stack_slots);
1687 1695 __ bind(Continue);
1688 1696 }
1689 1697
1690 1698 // change thread state
1691 1699 __ movl(Address(r15_thread, JavaThread::thread_state_offset()), _thread_in_Java);
1692 1700
1693 1701 Label reguard;
1694 1702 Label reguard_done;
1695 1703 __ cmpl(Address(r15_thread, JavaThread::stack_guard_state_offset()), JavaThread::stack_guard_yellow_disabled);
1696 1704 __ jcc(Assembler::equal, reguard);
1697 1705 __ bind(reguard_done);
1698 1706
1699 1707 // native result if any is live
1700 1708
1701 1709 // Unlock
1702 1710 Label unlock_done;
1703 1711 Label slow_path_unlock;
1704 1712 if (method->is_synchronized()) {
1705 1713
1706 1714 // Get locked oop from the handle we passed to jni
1707 1715 __ movptr(obj_reg, Address(oop_handle_reg, 0));
1708 1716
1709 1717 Label done;
1710 1718
1711 1719 if (UseBiasedLocking) {
1712 1720 __ biased_locking_exit(obj_reg, old_hdr, done);
1713 1721 }
1714 1722
1715 1723 // Simple recursive lock?
1716 1724
1717 1725 __ cmpptr(Address(rsp, lock_slot_offset * VMRegImpl::stack_slot_size), (int32_t)NULL_WORD);
1718 1726 __ jcc(Assembler::equal, done);
1719 1727
1720 1728 // Must save rax if if it is live now because cmpxchg must use it
1721 1729 if (ret_type != T_FLOAT && ret_type != T_DOUBLE && ret_type != T_VOID) {
1722 1730 save_native_result(masm, ret_type, stack_slots);
1723 1731 }
1724 1732
1725 1733
1726 1734 // get address of the stack lock
1727 1735 __ lea(rax, Address(rsp, lock_slot_offset * VMRegImpl::stack_slot_size));
1728 1736 // get old displaced header
1729 1737 __ movptr(old_hdr, Address(rax, 0));
1730 1738
1731 1739 // Atomic swap old header if oop still contains the stack lock
1732 1740 if (os::is_MP()) {
1733 1741 __ lock();
1734 1742 }
1735 1743 __ cmpxchgptr(old_hdr, Address(obj_reg, 0));
1736 1744 __ jcc(Assembler::notEqual, slow_path_unlock);
1737 1745
1738 1746 // slow path re-enters here
1739 1747 __ bind(unlock_done);
1740 1748 if (ret_type != T_FLOAT && ret_type != T_DOUBLE && ret_type != T_VOID) {
1741 1749 restore_native_result(masm, ret_type, stack_slots);
1742 1750 }
1743 1751
1744 1752 __ bind(done);
1745 1753
1746 1754 }
1747 1755 {
1748 1756 SkipIfEqual skip(masm, &DTraceMethodProbes, false);
1749 1757 save_native_result(masm, ret_type, stack_slots);
1750 1758 __ movoop(c_rarg1, JNIHandles::make_local(method()));
1751 1759 __ call_VM_leaf(
1752 1760 CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_method_exit),
1753 1761 r15_thread, c_rarg1);
1754 1762 restore_native_result(masm, ret_type, stack_slots);
1755 1763 }
1756 1764
1757 1765 __ reset_last_Java_frame(false, true);
1758 1766
1759 1767 // Unpack oop result
1760 1768 if (ret_type == T_OBJECT || ret_type == T_ARRAY) {
1761 1769 Label L;
1762 1770 __ testptr(rax, rax);
1763 1771 __ jcc(Assembler::zero, L);
1764 1772 __ movptr(rax, Address(rax, 0));
1765 1773 __ bind(L);
1766 1774 __ verify_oop(rax);
1767 1775 }
1768 1776
1769 1777 // reset handle block
1770 1778 __ movptr(rcx, Address(r15_thread, JavaThread::active_handles_offset()));
1771 1779 __ movptr(Address(rcx, JNIHandleBlock::top_offset_in_bytes()), (int32_t)NULL_WORD);
1772 1780
1773 1781 // pop our frame
1774 1782
1775 1783 __ leave();
1776 1784
1777 1785 // Any exception pending?
1778 1786 __ cmpptr(Address(r15_thread, in_bytes(Thread::pending_exception_offset())), (int32_t)NULL_WORD);
1779 1787 __ jcc(Assembler::notEqual, exception_pending);
1780 1788
1781 1789 // Return
1782 1790
1783 1791 __ ret(0);
1784 1792
1785 1793 // Unexpected paths are out of line and go here
1786 1794
1787 1795 // forward the exception
1788 1796 __ bind(exception_pending);
1789 1797
1790 1798 // and forward the exception
1791 1799 __ jump(RuntimeAddress(StubRoutines::forward_exception_entry()));
1792 1800
1793 1801
1794 1802 // Slow path locking & unlocking
1795 1803 if (method->is_synchronized()) {
1796 1804
1797 1805 // BEGIN Slow path lock
1798 1806 __ bind(slow_path_lock);
1799 1807
1800 1808 // has last_Java_frame setup. No exceptions so do vanilla call not call_VM
1801 1809 // args are (oop obj, BasicLock* lock, JavaThread* thread)
1802 1810
1803 1811 // protect the args we've loaded
1804 1812 save_args(masm, total_c_args, c_arg, out_regs);
1805 1813
1806 1814 __ mov(c_rarg0, obj_reg);
1807 1815 __ mov(c_rarg1, lock_reg);
1808 1816 __ mov(c_rarg2, r15_thread);
1809 1817
1810 1818 // Not a leaf but we have last_Java_frame setup as we want
1811 1819 __ call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::complete_monitor_locking_C), 3);
1812 1820 restore_args(masm, total_c_args, c_arg, out_regs);
1813 1821
1814 1822 #ifdef ASSERT
1815 1823 { Label L;
1816 1824 __ cmpptr(Address(r15_thread, in_bytes(Thread::pending_exception_offset())), (int32_t)NULL_WORD);
1817 1825 __ jcc(Assembler::equal, L);
1818 1826 __ stop("no pending exception allowed on exit from monitorenter");
1819 1827 __ bind(L);
1820 1828 }
1821 1829 #endif
1822 1830 __ jmp(lock_done);
1823 1831
1824 1832 // END Slow path lock
1825 1833
1826 1834 // BEGIN Slow path unlock
1827 1835 __ bind(slow_path_unlock);
1828 1836
1829 1837 // If we haven't already saved the native result we must save it now as xmm registers
1830 1838 // are still exposed.
1831 1839
1832 1840 if (ret_type == T_FLOAT || ret_type == T_DOUBLE ) {
1833 1841 save_native_result(masm, ret_type, stack_slots);
1834 1842 }
1835 1843
1836 1844 __ lea(c_rarg1, Address(rsp, lock_slot_offset * VMRegImpl::stack_slot_size));
1837 1845
1838 1846 __ mov(c_rarg0, obj_reg);
1839 1847 __ mov(r12, rsp); // remember sp
1840 1848 __ subptr(rsp, frame::arg_reg_save_area_bytes); // windows
1841 1849 __ andptr(rsp, -16); // align stack as required by ABI
1842 1850
1843 1851 // Save pending exception around call to VM (which contains an EXCEPTION_MARK)
1844 1852 // NOTE that obj_reg == rbx currently
1845 1853 __ movptr(rbx, Address(r15_thread, in_bytes(Thread::pending_exception_offset())));
1846 1854 __ movptr(Address(r15_thread, in_bytes(Thread::pending_exception_offset())), (int32_t)NULL_WORD);
1847 1855
1848 1856 __ call(RuntimeAddress(CAST_FROM_FN_PTR(address, SharedRuntime::complete_monitor_unlocking_C)));
1849 1857 __ mov(rsp, r12); // restore sp
1850 1858 __ reinit_heapbase();
1851 1859 #ifdef ASSERT
1852 1860 {
1853 1861 Label L;
1854 1862 __ cmpptr(Address(r15_thread, in_bytes(Thread::pending_exception_offset())), (int)NULL_WORD);
1855 1863 __ jcc(Assembler::equal, L);
1856 1864 __ stop("no pending exception allowed on exit complete_monitor_unlocking_C");
1857 1865 __ bind(L);
1858 1866 }
1859 1867 #endif /* ASSERT */
1860 1868
1861 1869 __ movptr(Address(r15_thread, in_bytes(Thread::pending_exception_offset())), rbx);
1862 1870
1863 1871 if (ret_type == T_FLOAT || ret_type == T_DOUBLE ) {
1864 1872 restore_native_result(masm, ret_type, stack_slots);
1865 1873 }
1866 1874 __ jmp(unlock_done);
1867 1875
1868 1876 // END Slow path unlock
1869 1877
1870 1878 } // synchronized
1871 1879
1872 1880 // SLOW PATH Reguard the stack if needed
1873 1881
1874 1882 __ bind(reguard);
1875 1883 save_native_result(masm, ret_type, stack_slots);
1876 1884 __ mov(r12, rsp); // remember sp
1877 1885 __ subptr(rsp, frame::arg_reg_save_area_bytes); // windows
1878 1886 __ andptr(rsp, -16); // align stack as required by ABI
1879 1887 __ call(RuntimeAddress(CAST_FROM_FN_PTR(address, SharedRuntime::reguard_yellow_pages)));
1880 1888 __ mov(rsp, r12); // restore sp
1881 1889 __ reinit_heapbase();
1882 1890 restore_native_result(masm, ret_type, stack_slots);
1883 1891 // and continue
1884 1892 __ jmp(reguard_done);
1885 1893
1886 1894
1887 1895
1888 1896 __ flush();
1889 1897
1890 1898 nmethod *nm = nmethod::new_native_nmethod(method,
1891 1899 masm->code(),
1892 1900 vep_offset,
1893 1901 frame_complete,
1894 1902 stack_slots / VMRegImpl::slots_per_word,
1895 1903 (is_static ? in_ByteSize(klass_offset) : in_ByteSize(receiver_offset)),
1896 1904 in_ByteSize(lock_slot_offset*VMRegImpl::stack_slot_size),
1897 1905 oop_maps);
1898 1906 return nm;
1899 1907
1900 1908 }
1901 1909
1902 1910 #ifdef HAVE_DTRACE_H
1903 1911 // ---------------------------------------------------------------------------
1904 1912 // Generate a dtrace nmethod for a given signature. The method takes arguments
1905 1913 // in the Java compiled code convention, marshals them to the native
1906 1914 // abi and then leaves nops at the position you would expect to call a native
1907 1915 // function. When the probe is enabled the nops are replaced with a trap
1908 1916 // instruction that dtrace inserts and the trace will cause a notification
1909 1917 // to dtrace.
1910 1918 //
1911 1919 // The probes are only able to take primitive types and java/lang/String as
1912 1920 // arguments. No other java types are allowed. Strings are converted to utf8
1913 1921 // strings so that from dtrace point of view java strings are converted to C
1914 1922 // strings. There is an arbitrary fixed limit on the total space that a method
1915 1923 // can use for converting the strings. (256 chars per string in the signature).
1916 1924 // So any java string larger then this is truncated.
1917 1925
1918 1926 static int fp_offset[ConcreteRegisterImpl::number_of_registers] = { 0 };
1919 1927 static bool offsets_initialized = false;
1920 1928
1921 1929
1922 1930 nmethod *SharedRuntime::generate_dtrace_nmethod(MacroAssembler *masm,
1923 1931 methodHandle method) {
1924 1932
1925 1933
1926 1934 // generate_dtrace_nmethod is guarded by a mutex so we are sure to
1927 1935 // be single threaded in this method.
1928 1936 assert(AdapterHandlerLibrary_lock->owned_by_self(), "must be");
1929 1937
1930 1938 if (!offsets_initialized) {
1931 1939 fp_offset[c_rarg0->as_VMReg()->value()] = -1 * wordSize;
1932 1940 fp_offset[c_rarg1->as_VMReg()->value()] = -2 * wordSize;
1933 1941 fp_offset[c_rarg2->as_VMReg()->value()] = -3 * wordSize;
1934 1942 fp_offset[c_rarg3->as_VMReg()->value()] = -4 * wordSize;
1935 1943 fp_offset[c_rarg4->as_VMReg()->value()] = -5 * wordSize;
1936 1944 fp_offset[c_rarg5->as_VMReg()->value()] = -6 * wordSize;
1937 1945
1938 1946 fp_offset[c_farg0->as_VMReg()->value()] = -7 * wordSize;
1939 1947 fp_offset[c_farg1->as_VMReg()->value()] = -8 * wordSize;
1940 1948 fp_offset[c_farg2->as_VMReg()->value()] = -9 * wordSize;
1941 1949 fp_offset[c_farg3->as_VMReg()->value()] = -10 * wordSize;
1942 1950 fp_offset[c_farg4->as_VMReg()->value()] = -11 * wordSize;
1943 1951 fp_offset[c_farg5->as_VMReg()->value()] = -12 * wordSize;
1944 1952 fp_offset[c_farg6->as_VMReg()->value()] = -13 * wordSize;
1945 1953 fp_offset[c_farg7->as_VMReg()->value()] = -14 * wordSize;
1946 1954
1947 1955 offsets_initialized = true;
1948 1956 }
1949 1957 // Fill in the signature array, for the calling-convention call.
1950 1958 int total_args_passed = method->size_of_parameters();
1951 1959
1952 1960 BasicType* in_sig_bt = NEW_RESOURCE_ARRAY(BasicType, total_args_passed);
1953 1961 VMRegPair *in_regs = NEW_RESOURCE_ARRAY(VMRegPair, total_args_passed);
1954 1962
1955 1963 // The signature we are going to use for the trap that dtrace will see
1956 1964 // java/lang/String is converted. We drop "this" and any other object
1957 1965 // is converted to NULL. (A one-slot java/lang/Long object reference
1958 1966 // is converted to a two-slot long, which is why we double the allocation).
1959 1967 BasicType* out_sig_bt = NEW_RESOURCE_ARRAY(BasicType, total_args_passed * 2);
1960 1968 VMRegPair* out_regs = NEW_RESOURCE_ARRAY(VMRegPair, total_args_passed * 2);
1961 1969
1962 1970 int i=0;
1963 1971 int total_strings = 0;
1964 1972 int first_arg_to_pass = 0;
1965 1973 int total_c_args = 0;
1966 1974
1967 1975 // Skip the receiver as dtrace doesn't want to see it
1968 1976 if( !method->is_static() ) {
1969 1977 in_sig_bt[i++] = T_OBJECT;
1970 1978 first_arg_to_pass = 1;
1971 1979 }
1972 1980
1973 1981 // We need to convert the java args to where a native (non-jni) function
1974 1982 // would expect them. To figure out where they go we convert the java
1975 1983 // signature to a C signature.
1976 1984
1977 1985 SignatureStream ss(method->signature());
1978 1986 for ( ; !ss.at_return_type(); ss.next()) {
1979 1987 BasicType bt = ss.type();
1980 1988 in_sig_bt[i++] = bt; // Collect remaining bits of signature
1981 1989 out_sig_bt[total_c_args++] = bt;
1982 1990 if( bt == T_OBJECT) {
1983 1991 symbolOop s = ss.as_symbol_or_null();
1984 1992 if (s == vmSymbols::java_lang_String()) {
1985 1993 total_strings++;
1986 1994 out_sig_bt[total_c_args-1] = T_ADDRESS;
1987 1995 } else if (s == vmSymbols::java_lang_Boolean() ||
1988 1996 s == vmSymbols::java_lang_Character() ||
1989 1997 s == vmSymbols::java_lang_Byte() ||
1990 1998 s == vmSymbols::java_lang_Short() ||
1991 1999 s == vmSymbols::java_lang_Integer() ||
1992 2000 s == vmSymbols::java_lang_Float()) {
1993 2001 out_sig_bt[total_c_args-1] = T_INT;
1994 2002 } else if (s == vmSymbols::java_lang_Long() ||
1995 2003 s == vmSymbols::java_lang_Double()) {
1996 2004 out_sig_bt[total_c_args-1] = T_LONG;
1997 2005 out_sig_bt[total_c_args++] = T_VOID;
1998 2006 }
1999 2007 } else if ( bt == T_LONG || bt == T_DOUBLE ) {
2000 2008 in_sig_bt[i++] = T_VOID; // Longs & doubles take 2 Java slots
2001 2009 // We convert double to long
2002 2010 out_sig_bt[total_c_args-1] = T_LONG;
2003 2011 out_sig_bt[total_c_args++] = T_VOID;
2004 2012 } else if ( bt == T_FLOAT) {
2005 2013 // We convert float to int
2006 2014 out_sig_bt[total_c_args-1] = T_INT;
2007 2015 }
2008 2016 }
2009 2017
2010 2018 assert(i==total_args_passed, "validly parsed signature");
2011 2019
2012 2020 // Now get the compiled-Java layout as input arguments
2013 2021 int comp_args_on_stack;
2014 2022 comp_args_on_stack = SharedRuntime::java_calling_convention(
2015 2023 in_sig_bt, in_regs, total_args_passed, false);
2016 2024
2017 2025 // Now figure out where the args must be stored and how much stack space
2018 2026 // they require (neglecting out_preserve_stack_slots but space for storing
2019 2027 // the 1st six register arguments). It's weird see int_stk_helper.
2020 2028
2021 2029 int out_arg_slots;
2022 2030 out_arg_slots = c_calling_convention(out_sig_bt, out_regs, total_c_args);
2023 2031
2024 2032 // Calculate the total number of stack slots we will need.
2025 2033
2026 2034 // First count the abi requirement plus all of the outgoing args
2027 2035 int stack_slots = SharedRuntime::out_preserve_stack_slots() + out_arg_slots;
2028 2036
2029 2037 // Now space for the string(s) we must convert
2030 2038 int* string_locs = NEW_RESOURCE_ARRAY(int, total_strings + 1);
2031 2039 for (i = 0; i < total_strings ; i++) {
2032 2040 string_locs[i] = stack_slots;
2033 2041 stack_slots += max_dtrace_string_size / VMRegImpl::stack_slot_size;
2034 2042 }
2035 2043
2036 2044 // Plus the temps we might need to juggle register args
2037 2045 // regs take two slots each
2038 2046 stack_slots += (Argument::n_int_register_parameters_c +
2039 2047 Argument::n_float_register_parameters_c) * 2;
2040 2048
2041 2049
2042 2050 // + 4 for return address (which we own) and saved rbp,
2043 2051
2044 2052 stack_slots += 4;
2045 2053
2046 2054 // Ok The space we have allocated will look like:
2047 2055 //
2048 2056 //
2049 2057 // FP-> | |
2050 2058 // |---------------------|
2051 2059 // | string[n] |
2052 2060 // |---------------------| <- string_locs[n]
2053 2061 // | string[n-1] |
2054 2062 // |---------------------| <- string_locs[n-1]
2055 2063 // | ... |
2056 2064 // | ... |
2057 2065 // |---------------------| <- string_locs[1]
2058 2066 // | string[0] |
2059 2067 // |---------------------| <- string_locs[0]
2060 2068 // | outbound memory |
2061 2069 // | based arguments |
2062 2070 // | |
2063 2071 // |---------------------|
2064 2072 // | |
2065 2073 // SP-> | out_preserved_slots |
2066 2074 //
2067 2075 //
2068 2076
2069 2077 // Now compute actual number of stack words we need rounding to make
2070 2078 // stack properly aligned.
2071 2079 stack_slots = round_to(stack_slots, 4 * VMRegImpl::slots_per_word);
2072 2080
2073 2081 int stack_size = stack_slots * VMRegImpl::stack_slot_size;
2074 2082
2075 2083 intptr_t start = (intptr_t)__ pc();
2076 2084
2077 2085 // First thing make an ic check to see if we should even be here
2078 2086
2079 2087 // We are free to use all registers as temps without saving them and
2080 2088 // restoring them except rbp. rbp, is the only callee save register
2081 2089 // as far as the interpreter and the compiler(s) are concerned.
2082 2090
2083 2091 const Register ic_reg = rax;
2084 2092 const Register receiver = rcx;
2085 2093 Label hit;
2086 2094 Label exception_pending;
2087 2095
2088 2096
2089 2097 __ verify_oop(receiver);
2090 2098 __ cmpl(ic_reg, Address(receiver, oopDesc::klass_offset_in_bytes()));
2091 2099 __ jcc(Assembler::equal, hit);
2092 2100
2093 2101 __ jump(RuntimeAddress(SharedRuntime::get_ic_miss_stub()));
2094 2102
2095 2103 // verified entry must be aligned for code patching.
2096 2104 // and the first 5 bytes must be in the same cache line
2097 2105 // if we align at 8 then we will be sure 5 bytes are in the same line
2098 2106 __ align(8);
2099 2107
2100 2108 __ bind(hit);
2101 2109
2102 2110 int vep_offset = ((intptr_t)__ pc()) - start;
2103 2111
2104 2112
2105 2113 // The instruction at the verified entry point must be 5 bytes or longer
2106 2114 // because it can be patched on the fly by make_non_entrant. The stack bang
2107 2115 // instruction fits that requirement.
2108 2116
2109 2117 // Generate stack overflow check
2110 2118
2111 2119 if (UseStackBanging) {
2112 2120 if (stack_size <= StackShadowPages*os::vm_page_size()) {
2113 2121 __ bang_stack_with_offset(StackShadowPages*os::vm_page_size());
2114 2122 } else {
2115 2123 __ movl(rax, stack_size);
2116 2124 __ bang_stack_size(rax, rbx);
2117 2125 }
2118 2126 } else {
2119 2127 // need a 5 byte instruction to allow MT safe patching to non-entrant
2120 2128 __ fat_nop();
2121 2129 }
2122 2130
2123 2131 assert(((uintptr_t)__ pc() - start - vep_offset) >= 5,
2124 2132 "valid size for make_non_entrant");
2125 2133
2126 2134 // Generate a new frame for the wrapper.
2127 2135 __ enter();
2128 2136
2129 2137 // -4 because return address is already present and so is saved rbp,
2130 2138 if (stack_size - 2*wordSize != 0) {
2131 2139 __ subq(rsp, stack_size - 2*wordSize);
2132 2140 }
2133 2141
2134 2142 // Frame is now completed as far a size and linkage.
2135 2143
2136 2144 int frame_complete = ((intptr_t)__ pc()) - start;
2137 2145
2138 2146 int c_arg, j_arg;
2139 2147
2140 2148 // State of input register args
2141 2149
2142 2150 bool live[ConcreteRegisterImpl::number_of_registers];
2143 2151
2144 2152 live[j_rarg0->as_VMReg()->value()] = false;
2145 2153 live[j_rarg1->as_VMReg()->value()] = false;
2146 2154 live[j_rarg2->as_VMReg()->value()] = false;
2147 2155 live[j_rarg3->as_VMReg()->value()] = false;
2148 2156 live[j_rarg4->as_VMReg()->value()] = false;
2149 2157 live[j_rarg5->as_VMReg()->value()] = false;
2150 2158
2151 2159 live[j_farg0->as_VMReg()->value()] = false;
2152 2160 live[j_farg1->as_VMReg()->value()] = false;
2153 2161 live[j_farg2->as_VMReg()->value()] = false;
2154 2162 live[j_farg3->as_VMReg()->value()] = false;
2155 2163 live[j_farg4->as_VMReg()->value()] = false;
2156 2164 live[j_farg5->as_VMReg()->value()] = false;
2157 2165 live[j_farg6->as_VMReg()->value()] = false;
2158 2166 live[j_farg7->as_VMReg()->value()] = false;
2159 2167
2160 2168
2161 2169 bool rax_is_zero = false;
2162 2170
2163 2171 // All args (except strings) destined for the stack are moved first
2164 2172 for (j_arg = first_arg_to_pass, c_arg = 0 ;
2165 2173 j_arg < total_args_passed ; j_arg++, c_arg++ ) {
2166 2174 VMRegPair src = in_regs[j_arg];
2167 2175 VMRegPair dst = out_regs[c_arg];
2168 2176
2169 2177 // Get the real reg value or a dummy (rsp)
2170 2178
2171 2179 int src_reg = src.first()->is_reg() ?
2172 2180 src.first()->value() :
2173 2181 rsp->as_VMReg()->value();
2174 2182
2175 2183 bool useless = in_sig_bt[j_arg] == T_ARRAY ||
2176 2184 (in_sig_bt[j_arg] == T_OBJECT &&
2177 2185 out_sig_bt[c_arg] != T_INT &&
2178 2186 out_sig_bt[c_arg] != T_ADDRESS &&
2179 2187 out_sig_bt[c_arg] != T_LONG);
2180 2188
2181 2189 live[src_reg] = !useless;
2182 2190
2183 2191 if (dst.first()->is_stack()) {
2184 2192
2185 2193 // Even though a string arg in a register is still live after this loop
2186 2194 // after the string conversion loop (next) it will be dead so we take
2187 2195 // advantage of that now for simpler code to manage live.
2188 2196
2189 2197 live[src_reg] = false;
2190 2198 switch (in_sig_bt[j_arg]) {
2191 2199
2192 2200 case T_ARRAY:
2193 2201 case T_OBJECT:
2194 2202 {
2195 2203 Address stack_dst(rsp, reg2offset_out(dst.first()));
2196 2204
2197 2205 if (out_sig_bt[c_arg] == T_INT || out_sig_bt[c_arg] == T_LONG) {
2198 2206 // need to unbox a one-word value
2199 2207 Register in_reg = rax;
2200 2208 if ( src.first()->is_reg() ) {
2201 2209 in_reg = src.first()->as_Register();
2202 2210 } else {
2203 2211 __ movq(rax, Address(rbp, reg2offset_in(src.first())));
2204 2212 rax_is_zero = false;
2205 2213 }
2206 2214 Label skipUnbox;
2207 2215 __ movptr(Address(rsp, reg2offset_out(dst.first())),
2208 2216 (int32_t)NULL_WORD);
2209 2217 __ testq(in_reg, in_reg);
2210 2218 __ jcc(Assembler::zero, skipUnbox);
2211 2219
2212 2220 BasicType bt = out_sig_bt[c_arg];
2213 2221 int box_offset = java_lang_boxing_object::value_offset_in_bytes(bt);
2214 2222 Address src1(in_reg, box_offset);
2215 2223 if ( bt == T_LONG ) {
2216 2224 __ movq(in_reg, src1);
2217 2225 __ movq(stack_dst, in_reg);
2218 2226 assert(out_sig_bt[c_arg+1] == T_VOID, "must be");
2219 2227 ++c_arg; // skip over T_VOID to keep the loop indices in sync
2220 2228 } else {
2221 2229 __ movl(in_reg, src1);
2222 2230 __ movl(stack_dst, in_reg);
2223 2231 }
2224 2232
2225 2233 __ bind(skipUnbox);
2226 2234 } else if (out_sig_bt[c_arg] != T_ADDRESS) {
2227 2235 // Convert the arg to NULL
2228 2236 if (!rax_is_zero) {
2229 2237 __ xorq(rax, rax);
2230 2238 rax_is_zero = true;
2231 2239 }
2232 2240 __ movq(stack_dst, rax);
2233 2241 }
2234 2242 }
2235 2243 break;
2236 2244
2237 2245 case T_VOID:
2238 2246 break;
2239 2247
2240 2248 case T_FLOAT:
2241 2249 // This does the right thing since we know it is destined for the
2242 2250 // stack
2243 2251 float_move(masm, src, dst);
2244 2252 break;
2245 2253
2246 2254 case T_DOUBLE:
2247 2255 // This does the right thing since we know it is destined for the
2248 2256 // stack
2249 2257 double_move(masm, src, dst);
2250 2258 break;
2251 2259
2252 2260 case T_LONG :
2253 2261 long_move(masm, src, dst);
2254 2262 break;
2255 2263
2256 2264 case T_ADDRESS: assert(false, "found T_ADDRESS in java args");
2257 2265
2258 2266 default:
2259 2267 move32_64(masm, src, dst);
2260 2268 }
2261 2269 }
2262 2270
2263 2271 }
2264 2272
2265 2273 // If we have any strings we must store any register based arg to the stack
2266 2274 // This includes any still live xmm registers too.
2267 2275
2268 2276 int sid = 0;
2269 2277
2270 2278 if (total_strings > 0 ) {
2271 2279 for (j_arg = first_arg_to_pass, c_arg = 0 ;
2272 2280 j_arg < total_args_passed ; j_arg++, c_arg++ ) {
2273 2281 VMRegPair src = in_regs[j_arg];
2274 2282 VMRegPair dst = out_regs[c_arg];
2275 2283
2276 2284 if (src.first()->is_reg()) {
2277 2285 Address src_tmp(rbp, fp_offset[src.first()->value()]);
2278 2286
2279 2287 // string oops were left untouched by the previous loop even if the
2280 2288 // eventual (converted) arg is destined for the stack so park them
2281 2289 // away now (except for first)
2282 2290
2283 2291 if (out_sig_bt[c_arg] == T_ADDRESS) {
2284 2292 Address utf8_addr = Address(
2285 2293 rsp, string_locs[sid++] * VMRegImpl::stack_slot_size);
2286 2294 if (sid != 1) {
2287 2295 // The first string arg won't be killed until after the utf8
2288 2296 // conversion
2289 2297 __ movq(utf8_addr, src.first()->as_Register());
2290 2298 }
2291 2299 } else if (dst.first()->is_reg()) {
2292 2300 if (in_sig_bt[j_arg] == T_FLOAT || in_sig_bt[j_arg] == T_DOUBLE) {
2293 2301
2294 2302 // Convert the xmm register to an int and store it in the reserved
2295 2303 // location for the eventual c register arg
2296 2304 XMMRegister f = src.first()->as_XMMRegister();
2297 2305 if (in_sig_bt[j_arg] == T_FLOAT) {
2298 2306 __ movflt(src_tmp, f);
2299 2307 } else {
2300 2308 __ movdbl(src_tmp, f);
2301 2309 }
2302 2310 } else {
2303 2311 // If the arg is an oop type we don't support don't bother to store
2304 2312 // it remember string was handled above.
2305 2313 bool useless = in_sig_bt[j_arg] == T_ARRAY ||
2306 2314 (in_sig_bt[j_arg] == T_OBJECT &&
2307 2315 out_sig_bt[c_arg] != T_INT &&
2308 2316 out_sig_bt[c_arg] != T_LONG);
2309 2317
2310 2318 if (!useless) {
2311 2319 __ movq(src_tmp, src.first()->as_Register());
2312 2320 }
2313 2321 }
2314 2322 }
2315 2323 }
2316 2324 if (in_sig_bt[j_arg] == T_OBJECT && out_sig_bt[c_arg] == T_LONG) {
2317 2325 assert(out_sig_bt[c_arg+1] == T_VOID, "must be");
2318 2326 ++c_arg; // skip over T_VOID to keep the loop indices in sync
2319 2327 }
2320 2328 }
2321 2329
2322 2330 // Now that the volatile registers are safe, convert all the strings
2323 2331 sid = 0;
2324 2332
2325 2333 for (j_arg = first_arg_to_pass, c_arg = 0 ;
2326 2334 j_arg < total_args_passed ; j_arg++, c_arg++ ) {
2327 2335 if (out_sig_bt[c_arg] == T_ADDRESS) {
2328 2336 // It's a string
2329 2337 Address utf8_addr = Address(
2330 2338 rsp, string_locs[sid++] * VMRegImpl::stack_slot_size);
2331 2339 // The first string we find might still be in the original java arg
2332 2340 // register
2333 2341
2334 2342 VMReg src = in_regs[j_arg].first();
2335 2343
2336 2344 // We will need to eventually save the final argument to the trap
2337 2345 // in the von-volatile location dedicated to src. This is the offset
2338 2346 // from fp we will use.
2339 2347 int src_off = src->is_reg() ?
2340 2348 fp_offset[src->value()] : reg2offset_in(src);
2341 2349
2342 2350 // This is where the argument will eventually reside
2343 2351 VMRegPair dst = out_regs[c_arg];
2344 2352
2345 2353 if (src->is_reg()) {
2346 2354 if (sid == 1) {
2347 2355 __ movq(c_rarg0, src->as_Register());
2348 2356 } else {
2349 2357 __ movq(c_rarg0, utf8_addr);
2350 2358 }
2351 2359 } else {
2352 2360 // arg is still in the original location
2353 2361 __ movq(c_rarg0, Address(rbp, reg2offset_in(src)));
2354 2362 }
2355 2363 Label done, convert;
2356 2364
2357 2365 // see if the oop is NULL
2358 2366 __ testq(c_rarg0, c_rarg0);
2359 2367 __ jcc(Assembler::notEqual, convert);
2360 2368
2361 2369 if (dst.first()->is_reg()) {
2362 2370 // Save the ptr to utf string in the origina src loc or the tmp
2363 2371 // dedicated to it
2364 2372 __ movq(Address(rbp, src_off), c_rarg0);
2365 2373 } else {
2366 2374 __ movq(Address(rsp, reg2offset_out(dst.first())), c_rarg0);
2367 2375 }
2368 2376 __ jmp(done);
2369 2377
2370 2378 __ bind(convert);
2371 2379
2372 2380 __ lea(c_rarg1, utf8_addr);
2373 2381 if (dst.first()->is_reg()) {
2374 2382 __ movq(Address(rbp, src_off), c_rarg1);
2375 2383 } else {
2376 2384 __ movq(Address(rsp, reg2offset_out(dst.first())), c_rarg1);
2377 2385 }
2378 2386 // And do the conversion
2379 2387 __ call(RuntimeAddress(
2380 2388 CAST_FROM_FN_PTR(address, SharedRuntime::get_utf)));
2381 2389
2382 2390 __ bind(done);
2383 2391 }
2384 2392 if (in_sig_bt[j_arg] == T_OBJECT && out_sig_bt[c_arg] == T_LONG) {
2385 2393 assert(out_sig_bt[c_arg+1] == T_VOID, "must be");
2386 2394 ++c_arg; // skip over T_VOID to keep the loop indices in sync
2387 2395 }
2388 2396 }
2389 2397 // The get_utf call killed all the c_arg registers
2390 2398 live[c_rarg0->as_VMReg()->value()] = false;
2391 2399 live[c_rarg1->as_VMReg()->value()] = false;
2392 2400 live[c_rarg2->as_VMReg()->value()] = false;
2393 2401 live[c_rarg3->as_VMReg()->value()] = false;
2394 2402 live[c_rarg4->as_VMReg()->value()] = false;
2395 2403 live[c_rarg5->as_VMReg()->value()] = false;
2396 2404
2397 2405 live[c_farg0->as_VMReg()->value()] = false;
2398 2406 live[c_farg1->as_VMReg()->value()] = false;
2399 2407 live[c_farg2->as_VMReg()->value()] = false;
2400 2408 live[c_farg3->as_VMReg()->value()] = false;
2401 2409 live[c_farg4->as_VMReg()->value()] = false;
2402 2410 live[c_farg5->as_VMReg()->value()] = false;
2403 2411 live[c_farg6->as_VMReg()->value()] = false;
2404 2412 live[c_farg7->as_VMReg()->value()] = false;
2405 2413 }
2406 2414
2407 2415 // Now we can finally move the register args to their desired locations
2408 2416
2409 2417 rax_is_zero = false;
2410 2418
2411 2419 for (j_arg = first_arg_to_pass, c_arg = 0 ;
2412 2420 j_arg < total_args_passed ; j_arg++, c_arg++ ) {
2413 2421
2414 2422 VMRegPair src = in_regs[j_arg];
2415 2423 VMRegPair dst = out_regs[c_arg];
2416 2424
2417 2425 // Only need to look for args destined for the interger registers (since we
2418 2426 // convert float/double args to look like int/long outbound)
2419 2427 if (dst.first()->is_reg()) {
2420 2428 Register r = dst.first()->as_Register();
2421 2429
2422 2430 // Check if the java arg is unsupported and thereofre useless
2423 2431 bool useless = in_sig_bt[j_arg] == T_ARRAY ||
2424 2432 (in_sig_bt[j_arg] == T_OBJECT &&
2425 2433 out_sig_bt[c_arg] != T_INT &&
2426 2434 out_sig_bt[c_arg] != T_ADDRESS &&
2427 2435 out_sig_bt[c_arg] != T_LONG);
2428 2436
2429 2437
2430 2438 // If we're going to kill an existing arg save it first
2431 2439 if (live[dst.first()->value()]) {
2432 2440 // you can't kill yourself
2433 2441 if (src.first() != dst.first()) {
2434 2442 __ movq(Address(rbp, fp_offset[dst.first()->value()]), r);
2435 2443 }
2436 2444 }
2437 2445 if (src.first()->is_reg()) {
2438 2446 if (live[src.first()->value()] ) {
2439 2447 if (in_sig_bt[j_arg] == T_FLOAT) {
2440 2448 __ movdl(r, src.first()->as_XMMRegister());
2441 2449 } else if (in_sig_bt[j_arg] == T_DOUBLE) {
2442 2450 __ movdq(r, src.first()->as_XMMRegister());
2443 2451 } else if (r != src.first()->as_Register()) {
2444 2452 if (!useless) {
2445 2453 __ movq(r, src.first()->as_Register());
2446 2454 }
2447 2455 }
2448 2456 } else {
2449 2457 // If the arg is an oop type we don't support don't bother to store
2450 2458 // it
2451 2459 if (!useless) {
2452 2460 if (in_sig_bt[j_arg] == T_DOUBLE ||
2453 2461 in_sig_bt[j_arg] == T_LONG ||
2454 2462 in_sig_bt[j_arg] == T_OBJECT ) {
2455 2463 __ movq(r, Address(rbp, fp_offset[src.first()->value()]));
2456 2464 } else {
2457 2465 __ movl(r, Address(rbp, fp_offset[src.first()->value()]));
2458 2466 }
2459 2467 }
2460 2468 }
2461 2469 live[src.first()->value()] = false;
2462 2470 } else if (!useless) {
2463 2471 // full sized move even for int should be ok
2464 2472 __ movq(r, Address(rbp, reg2offset_in(src.first())));
2465 2473 }
2466 2474
2467 2475 // At this point r has the original java arg in the final location
2468 2476 // (assuming it wasn't useless). If the java arg was an oop
2469 2477 // we have a bit more to do
2470 2478
2471 2479 if (in_sig_bt[j_arg] == T_ARRAY || in_sig_bt[j_arg] == T_OBJECT ) {
2472 2480 if (out_sig_bt[c_arg] == T_INT || out_sig_bt[c_arg] == T_LONG) {
2473 2481 // need to unbox a one-word value
2474 2482 Label skip;
2475 2483 __ testq(r, r);
2476 2484 __ jcc(Assembler::equal, skip);
2477 2485 BasicType bt = out_sig_bt[c_arg];
2478 2486 int box_offset = java_lang_boxing_object::value_offset_in_bytes(bt);
2479 2487 Address src1(r, box_offset);
2480 2488 if ( bt == T_LONG ) {
2481 2489 __ movq(r, src1);
2482 2490 } else {
2483 2491 __ movl(r, src1);
2484 2492 }
2485 2493 __ bind(skip);
2486 2494
2487 2495 } else if (out_sig_bt[c_arg] != T_ADDRESS) {
2488 2496 // Convert the arg to NULL
2489 2497 __ xorq(r, r);
2490 2498 }
2491 2499 }
2492 2500
2493 2501 // dst can longer be holding an input value
2494 2502 live[dst.first()->value()] = false;
2495 2503 }
2496 2504 if (in_sig_bt[j_arg] == T_OBJECT && out_sig_bt[c_arg] == T_LONG) {
2497 2505 assert(out_sig_bt[c_arg+1] == T_VOID, "must be");
2498 2506 ++c_arg; // skip over T_VOID to keep the loop indices in sync
2499 2507 }
2500 2508 }
2501 2509
2502 2510
2503 2511 // Ok now we are done. Need to place the nop that dtrace wants in order to
2504 2512 // patch in the trap
2505 2513 int patch_offset = ((intptr_t)__ pc()) - start;
2506 2514
2507 2515 __ nop();
2508 2516
2509 2517
2510 2518 // Return
2511 2519
2512 2520 __ leave();
2513 2521 __ ret(0);
2514 2522
2515 2523 __ flush();
2516 2524
2517 2525 nmethod *nm = nmethod::new_dtrace_nmethod(
2518 2526 method, masm->code(), vep_offset, patch_offset, frame_complete,
2519 2527 stack_slots / VMRegImpl::slots_per_word);
2520 2528 return nm;
2521 2529
2522 2530 }
2523 2531
2524 2532 #endif // HAVE_DTRACE_H
2525 2533
2526 2534 // this function returns the adjust size (in number of words) to a c2i adapter
2527 2535 // activation for use during deoptimization
2528 2536 int Deoptimization::last_frame_adjust(int callee_parameters, int callee_locals ) {
2529 2537 return (callee_locals - callee_parameters) * Interpreter::stackElementWords();
2530 2538 }
2531 2539
2532 2540
2533 2541 uint SharedRuntime::out_preserve_stack_slots() {
2534 2542 return 0;
2535 2543 }
2536 2544
2537 2545
2538 2546 //------------------------------generate_deopt_blob----------------------------
2539 2547 void SharedRuntime::generate_deopt_blob() {
2540 2548 // Allocate space for the code
2541 2549 ResourceMark rm;
2542 2550 // Setup code generation tools
2543 2551 CodeBuffer buffer("deopt_blob", 2048, 1024);
2544 2552 MacroAssembler* masm = new MacroAssembler(&buffer);
2545 2553 int frame_size_in_words;
2546 2554 OopMap* map = NULL;
2547 2555 OopMapSet *oop_maps = new OopMapSet();
2548 2556
2549 2557 // -------------
2550 2558 // This code enters when returning to a de-optimized nmethod. A return
2551 2559 // address has been pushed on the the stack, and return values are in
2552 2560 // registers.
2553 2561 // If we are doing a normal deopt then we were called from the patched
2554 2562 // nmethod from the point we returned to the nmethod. So the return
2555 2563 // address on the stack is wrong by NativeCall::instruction_size
2556 2564 // We will adjust the value so it looks like we have the original return
2557 2565 // address on the stack (like when we eagerly deoptimized).
2558 2566 // In the case of an exception pending when deoptimizing, we enter
2559 2567 // with a return address on the stack that points after the call we patched
2560 2568 // into the exception handler. We have the following register state from,
2561 2569 // e.g., the forward exception stub (see stubGenerator_x86_64.cpp).
2562 2570 // rax: exception oop
2563 2571 // rbx: exception handler
2564 2572 // rdx: throwing pc
2565 2573 // So in this case we simply jam rdx into the useless return address and
2566 2574 // the stack looks just like we want.
2567 2575 //
2568 2576 // At this point we need to de-opt. We save the argument return
2569 2577 // registers. We call the first C routine, fetch_unroll_info(). This
2570 2578 // routine captures the return values and returns a structure which
2571 2579 // describes the current frame size and the sizes of all replacement frames.
2572 2580 // The current frame is compiled code and may contain many inlined
2573 2581 // functions, each with their own JVM state. We pop the current frame, then
2574 2582 // push all the new frames. Then we call the C routine unpack_frames() to
2575 2583 // populate these frames. Finally unpack_frames() returns us the new target
2576 2584 // address. Notice that callee-save registers are BLOWN here; they have
2577 2585 // already been captured in the vframeArray at the time the return PC was
2578 2586 // patched.
2579 2587 address start = __ pc();
2580 2588 Label cont;
2581 2589
2582 2590 // Prolog for non exception case!
2583 2591
2584 2592 // Save everything in sight.
2585 2593 map = RegisterSaver::save_live_registers(masm, 0, &frame_size_in_words);
2586 2594
2587 2595 // Normal deoptimization. Save exec mode for unpack_frames.
2588 2596 __ movl(r14, Deoptimization::Unpack_deopt); // callee-saved
2589 2597 __ jmp(cont);
2590 2598
2591 2599 int reexecute_offset = __ pc() - start;
2592 2600
2593 2601 // Reexecute case
2594 2602 // return address is the pc describes what bci to do re-execute at
2595 2603
2596 2604 // No need to update map as each call to save_live_registers will produce identical oopmap
2597 2605 (void) RegisterSaver::save_live_registers(masm, 0, &frame_size_in_words);
2598 2606
2599 2607 __ movl(r14, Deoptimization::Unpack_reexecute); // callee-saved
2600 2608 __ jmp(cont);
2601 2609
2602 2610 int exception_offset = __ pc() - start;
2603 2611
2604 2612 // Prolog for exception case
2605 2613
2606 2614 // all registers are dead at this entry point, except for rax, and
2607 2615 // rdx which contain the exception oop and exception pc
2608 2616 // respectively. Set them in TLS and fall thru to the
2609 2617 // unpack_with_exception_in_tls entry point.
2610 2618
2611 2619 __ movptr(Address(r15_thread, JavaThread::exception_pc_offset()), rdx);
2612 2620 __ movptr(Address(r15_thread, JavaThread::exception_oop_offset()), rax);
2613 2621
2614 2622 int exception_in_tls_offset = __ pc() - start;
2615 2623
2616 2624 // new implementation because exception oop is now passed in JavaThread
2617 2625
2618 2626 // Prolog for exception case
2619 2627 // All registers must be preserved because they might be used by LinearScan
2620 2628 // Exceptiop oop and throwing PC are passed in JavaThread
2621 2629 // tos: stack at point of call to method that threw the exception (i.e. only
2622 2630 // args are on the stack, no return address)
2623 2631
2624 2632 // make room on stack for the return address
2625 2633 // It will be patched later with the throwing pc. The correct value is not
2626 2634 // available now because loading it from memory would destroy registers.
2627 2635 __ push(0);
2628 2636
2629 2637 // Save everything in sight.
2630 2638 map = RegisterSaver::save_live_registers(masm, 0, &frame_size_in_words);
2631 2639
2632 2640 // Now it is safe to overwrite any register
2633 2641
2634 2642 // Deopt during an exception. Save exec mode for unpack_frames.
2635 2643 __ movl(r14, Deoptimization::Unpack_exception); // callee-saved
2636 2644
2637 2645 // load throwing pc from JavaThread and patch it as the return address
2638 2646 // of the current frame. Then clear the field in JavaThread
2639 2647
2640 2648 __ movptr(rdx, Address(r15_thread, JavaThread::exception_pc_offset()));
2641 2649 __ movptr(Address(rbp, wordSize), rdx);
2642 2650 __ movptr(Address(r15_thread, JavaThread::exception_pc_offset()), (int32_t)NULL_WORD);
2643 2651
2644 2652 #ifdef ASSERT
2645 2653 // verify that there is really an exception oop in JavaThread
2646 2654 __ movptr(rax, Address(r15_thread, JavaThread::exception_oop_offset()));
2647 2655 __ verify_oop(rax);
2648 2656
2649 2657 // verify that there is no pending exception
2650 2658 Label no_pending_exception;
2651 2659 __ movptr(rax, Address(r15_thread, Thread::pending_exception_offset()));
2652 2660 __ testptr(rax, rax);
2653 2661 __ jcc(Assembler::zero, no_pending_exception);
2654 2662 __ stop("must not have pending exception here");
2655 2663 __ bind(no_pending_exception);
2656 2664 #endif
2657 2665
2658 2666 __ bind(cont);
2659 2667
2660 2668 // Call C code. Need thread and this frame, but NOT official VM entry
2661 2669 // crud. We cannot block on this call, no GC can happen.
2662 2670 //
2663 2671 // UnrollBlock* fetch_unroll_info(JavaThread* thread)
2664 2672
2665 2673 // fetch_unroll_info needs to call last_java_frame().
2666 2674
2667 2675 __ set_last_Java_frame(noreg, noreg, NULL);
2668 2676 #ifdef ASSERT
2669 2677 { Label L;
2670 2678 __ cmpptr(Address(r15_thread,
2671 2679 JavaThread::last_Java_fp_offset()),
2672 2680 (int32_t)0);
2673 2681 __ jcc(Assembler::equal, L);
2674 2682 __ stop("SharedRuntime::generate_deopt_blob: last_Java_fp not cleared");
2675 2683 __ bind(L);
2676 2684 }
2677 2685 #endif // ASSERT
2678 2686 __ mov(c_rarg0, r15_thread);
2679 2687 __ call(RuntimeAddress(CAST_FROM_FN_PTR(address, Deoptimization::fetch_unroll_info)));
2680 2688
2681 2689 // Need to have an oopmap that tells fetch_unroll_info where to
2682 2690 // find any register it might need.
2683 2691 oop_maps->add_gc_map(__ pc() - start, map);
2684 2692
2685 2693 __ reset_last_Java_frame(false, false);
2686 2694
2687 2695 // Load UnrollBlock* into rdi
2688 2696 __ mov(rdi, rax);
2689 2697
2690 2698 Label noException;
2691 2699 __ cmpl(r14, Deoptimization::Unpack_exception); // Was exception pending?
2692 2700 __ jcc(Assembler::notEqual, noException);
2693 2701 __ movptr(rax, Address(r15_thread, JavaThread::exception_oop_offset()));
2694 2702 // QQQ this is useless it was NULL above
2695 2703 __ movptr(rdx, Address(r15_thread, JavaThread::exception_pc_offset()));
2696 2704 __ movptr(Address(r15_thread, JavaThread::exception_oop_offset()), (int32_t)NULL_WORD);
2697 2705 __ movptr(Address(r15_thread, JavaThread::exception_pc_offset()), (int32_t)NULL_WORD);
2698 2706
2699 2707 __ verify_oop(rax);
2700 2708
2701 2709 // Overwrite the result registers with the exception results.
2702 2710 __ movptr(Address(rsp, RegisterSaver::rax_offset_in_bytes()), rax);
2703 2711 // I think this is useless
2704 2712 __ movptr(Address(rsp, RegisterSaver::rdx_offset_in_bytes()), rdx);
2705 2713
2706 2714 __ bind(noException);
2707 2715
2708 2716 // Only register save data is on the stack.
2709 2717 // Now restore the result registers. Everything else is either dead
2710 2718 // or captured in the vframeArray.
2711 2719 RegisterSaver::restore_result_registers(masm);
2712 2720
2713 2721 // All of the register save area has been popped of the stack. Only the
2714 2722 // return address remains.
2715 2723
2716 2724 // Pop all the frames we must move/replace.
2717 2725 //
2718 2726 // Frame picture (youngest to oldest)
2719 2727 // 1: self-frame (no frame link)
2720 2728 // 2: deopting frame (no frame link)
2721 2729 // 3: caller of deopting frame (could be compiled/interpreted).
2722 2730 //
2723 2731 // Note: by leaving the return address of self-frame on the stack
2724 2732 // and using the size of frame 2 to adjust the stack
2725 2733 // when we are done the return to frame 3 will still be on the stack.
2726 2734
2727 2735 // Pop deoptimized frame
2728 2736 __ movl(rcx, Address(rdi, Deoptimization::UnrollBlock::size_of_deoptimized_frame_offset_in_bytes()));
2729 2737 __ addptr(rsp, rcx);
2730 2738
2731 2739 // rsp should be pointing at the return address to the caller (3)
2732 2740
2733 2741 // Stack bang to make sure there's enough room for these interpreter frames.
2734 2742 if (UseStackBanging) {
2735 2743 __ movl(rbx, Address(rdi, Deoptimization::UnrollBlock::total_frame_sizes_offset_in_bytes()));
2736 2744 __ bang_stack_size(rbx, rcx);
2737 2745 }
2738 2746
2739 2747 // Load address of array of frame pcs into rcx
2740 2748 __ movptr(rcx, Address(rdi, Deoptimization::UnrollBlock::frame_pcs_offset_in_bytes()));
2741 2749
2742 2750 // Trash the old pc
2743 2751 __ addptr(rsp, wordSize);
2744 2752
2745 2753 // Load address of array of frame sizes into rsi
2746 2754 __ movptr(rsi, Address(rdi, Deoptimization::UnrollBlock::frame_sizes_offset_in_bytes()));
2747 2755
2748 2756 // Load counter into rdx
2749 2757 __ movl(rdx, Address(rdi, Deoptimization::UnrollBlock::number_of_frames_offset_in_bytes()));
2750 2758
2751 2759 // Pick up the initial fp we should save
2752 2760 __ movptr(rbp, Address(rdi, Deoptimization::UnrollBlock::initial_fp_offset_in_bytes()));
2753 2761
2754 2762 // Now adjust the caller's stack to make up for the extra locals
2755 2763 // but record the original sp so that we can save it in the skeletal interpreter
2756 2764 // frame and the stack walking of interpreter_sender will get the unextended sp
2757 2765 // value and not the "real" sp value.
2758 2766
2759 2767 const Register sender_sp = r8;
2760 2768
2761 2769 __ mov(sender_sp, rsp);
2762 2770 __ movl(rbx, Address(rdi,
2763 2771 Deoptimization::UnrollBlock::
2764 2772 caller_adjustment_offset_in_bytes()));
2765 2773 __ subptr(rsp, rbx);
2766 2774
2767 2775 // Push interpreter frames in a loop
2768 2776 Label loop;
2769 2777 __ bind(loop);
2770 2778 __ movptr(rbx, Address(rsi, 0)); // Load frame size
2771 2779 #ifdef CC_INTERP
2772 2780 __ subptr(rbx, 4*wordSize); // we'll push pc and ebp by hand and
2773 2781 #ifdef ASSERT
2774 2782 __ push(0xDEADDEAD); // Make a recognizable pattern
2775 2783 __ push(0xDEADDEAD);
2776 2784 #else /* ASSERT */
2777 2785 __ subptr(rsp, 2*wordSize); // skip the "static long no_param"
2778 2786 #endif /* ASSERT */
2779 2787 #else
2780 2788 __ subptr(rbx, 2*wordSize); // We'll push pc and ebp by hand
2781 2789 #endif // CC_INTERP
2782 2790 __ pushptr(Address(rcx, 0)); // Save return address
2783 2791 __ enter(); // Save old & set new ebp
2784 2792 __ subptr(rsp, rbx); // Prolog
2785 2793 #ifdef CC_INTERP
2786 2794 __ movptr(Address(rbp,
2787 2795 -(sizeof(BytecodeInterpreter)) + in_bytes(byte_offset_of(BytecodeInterpreter, _sender_sp))),
2788 2796 sender_sp); // Make it walkable
2789 2797 #else /* CC_INTERP */
2790 2798 // This value is corrected by layout_activation_impl
2791 2799 __ movptr(Address(rbp, frame::interpreter_frame_last_sp_offset * wordSize), (int32_t)NULL_WORD );
2792 2800 __ movptr(Address(rbp, frame::interpreter_frame_sender_sp_offset * wordSize), sender_sp); // Make it walkable
2793 2801 #endif /* CC_INTERP */
2794 2802 __ mov(sender_sp, rsp); // Pass sender_sp to next frame
2795 2803 __ addptr(rsi, wordSize); // Bump array pointer (sizes)
2796 2804 __ addptr(rcx, wordSize); // Bump array pointer (pcs)
2797 2805 __ decrementl(rdx); // Decrement counter
2798 2806 __ jcc(Assembler::notZero, loop);
2799 2807 __ pushptr(Address(rcx, 0)); // Save final return address
2800 2808
2801 2809 // Re-push self-frame
2802 2810 __ enter(); // Save old & set new ebp
2803 2811
2804 2812 // Allocate a full sized register save area.
2805 2813 // Return address and rbp are in place, so we allocate two less words.
2806 2814 __ subptr(rsp, (frame_size_in_words - 2) * wordSize);
2807 2815
2808 2816 // Restore frame locals after moving the frame
2809 2817 __ movdbl(Address(rsp, RegisterSaver::xmm0_offset_in_bytes()), xmm0);
2810 2818 __ movptr(Address(rsp, RegisterSaver::rax_offset_in_bytes()), rax);
2811 2819
2812 2820 // Call C code. Need thread but NOT official VM entry
2813 2821 // crud. We cannot block on this call, no GC can happen. Call should
2814 2822 // restore return values to their stack-slots with the new SP.
2815 2823 //
2816 2824 // void Deoptimization::unpack_frames(JavaThread* thread, int exec_mode)
2817 2825
2818 2826 // Use rbp because the frames look interpreted now
2819 2827 __ set_last_Java_frame(noreg, rbp, NULL);
2820 2828
2821 2829 __ mov(c_rarg0, r15_thread);
2822 2830 __ movl(c_rarg1, r14); // second arg: exec_mode
2823 2831 __ call(RuntimeAddress(CAST_FROM_FN_PTR(address, Deoptimization::unpack_frames)));
2824 2832
2825 2833 // Set an oopmap for the call site
2826 2834 oop_maps->add_gc_map(__ pc() - start,
2827 2835 new OopMap( frame_size_in_words, 0 ));
2828 2836
2829 2837 __ reset_last_Java_frame(true, false);
2830 2838
2831 2839 // Collect return values
2832 2840 __ movdbl(xmm0, Address(rsp, RegisterSaver::xmm0_offset_in_bytes()));
2833 2841 __ movptr(rax, Address(rsp, RegisterSaver::rax_offset_in_bytes()));
2834 2842 // I think this is useless (throwing pc?)
2835 2843 __ movptr(rdx, Address(rsp, RegisterSaver::rdx_offset_in_bytes()));
2836 2844
2837 2845 // Pop self-frame.
2838 2846 __ leave(); // Epilog
2839 2847
2840 2848 // Jump to interpreter
2841 2849 __ ret(0);
2842 2850
2843 2851 // Make sure all code is generated
2844 2852 masm->flush();
2845 2853
2846 2854 _deopt_blob = DeoptimizationBlob::create(&buffer, oop_maps, 0, exception_offset, reexecute_offset, frame_size_in_words);
2847 2855 _deopt_blob->set_unpack_with_exception_in_tls_offset(exception_in_tls_offset);
2848 2856 }
2849 2857
2850 2858 #ifdef COMPILER2
2851 2859 //------------------------------generate_uncommon_trap_blob--------------------
2852 2860 void SharedRuntime::generate_uncommon_trap_blob() {
2853 2861 // Allocate space for the code
2854 2862 ResourceMark rm;
2855 2863 // Setup code generation tools
2856 2864 CodeBuffer buffer("uncommon_trap_blob", 2048, 1024);
2857 2865 MacroAssembler* masm = new MacroAssembler(&buffer);
2858 2866
2859 2867 assert(SimpleRuntimeFrame::framesize % 4 == 0, "sp not 16-byte aligned");
2860 2868
2861 2869 address start = __ pc();
2862 2870
2863 2871 // Push self-frame. We get here with a return address on the
2864 2872 // stack, so rsp is 8-byte aligned until we allocate our frame.
2865 2873 __ subptr(rsp, SimpleRuntimeFrame::return_off << LogBytesPerInt); // Epilog!
2866 2874
2867 2875 // No callee saved registers. rbp is assumed implicitly saved
2868 2876 __ movptr(Address(rsp, SimpleRuntimeFrame::rbp_off << LogBytesPerInt), rbp);
2869 2877
2870 2878 // compiler left unloaded_class_index in j_rarg0 move to where the
2871 2879 // runtime expects it.
2872 2880 __ movl(c_rarg1, j_rarg0);
2873 2881
2874 2882 __ set_last_Java_frame(noreg, noreg, NULL);
2875 2883
2876 2884 // Call C code. Need thread but NOT official VM entry
2877 2885 // crud. We cannot block on this call, no GC can happen. Call should
2878 2886 // capture callee-saved registers as well as return values.
2879 2887 // Thread is in rdi already.
2880 2888 //
2881 2889 // UnrollBlock* uncommon_trap(JavaThread* thread, jint unloaded_class_index);
2882 2890
2883 2891 __ mov(c_rarg0, r15_thread);
2884 2892 __ call(RuntimeAddress(CAST_FROM_FN_PTR(address, Deoptimization::uncommon_trap)));
2885 2893
2886 2894 // Set an oopmap for the call site
2887 2895 OopMapSet* oop_maps = new OopMapSet();
2888 2896 OopMap* map = new OopMap(SimpleRuntimeFrame::framesize, 0);
2889 2897
2890 2898 // location of rbp is known implicitly by the frame sender code
2891 2899
2892 2900 oop_maps->add_gc_map(__ pc() - start, map);
2893 2901
2894 2902 __ reset_last_Java_frame(false, false);
2895 2903
2896 2904 // Load UnrollBlock* into rdi
2897 2905 __ mov(rdi, rax);
2898 2906
2899 2907 // Pop all the frames we must move/replace.
2900 2908 //
2901 2909 // Frame picture (youngest to oldest)
2902 2910 // 1: self-frame (no frame link)
2903 2911 // 2: deopting frame (no frame link)
2904 2912 // 3: caller of deopting frame (could be compiled/interpreted).
2905 2913
2906 2914 // Pop self-frame. We have no frame, and must rely only on rax and rsp.
2907 2915 __ addptr(rsp, (SimpleRuntimeFrame::framesize - 2) << LogBytesPerInt); // Epilog!
2908 2916
2909 2917 // Pop deoptimized frame (int)
2910 2918 __ movl(rcx, Address(rdi,
2911 2919 Deoptimization::UnrollBlock::
2912 2920 size_of_deoptimized_frame_offset_in_bytes()));
2913 2921 __ addptr(rsp, rcx);
2914 2922
2915 2923 // rsp should be pointing at the return address to the caller (3)
2916 2924
2917 2925 // Stack bang to make sure there's enough room for these interpreter frames.
2918 2926 if (UseStackBanging) {
2919 2927 __ movl(rbx, Address(rdi ,Deoptimization::UnrollBlock::total_frame_sizes_offset_in_bytes()));
2920 2928 __ bang_stack_size(rbx, rcx);
2921 2929 }
2922 2930
2923 2931 // Load address of array of frame pcs into rcx (address*)
2924 2932 __ movptr(rcx,
2925 2933 Address(rdi,
2926 2934 Deoptimization::UnrollBlock::frame_pcs_offset_in_bytes()));
2927 2935
2928 2936 // Trash the return pc
2929 2937 __ addptr(rsp, wordSize);
2930 2938
2931 2939 // Load address of array of frame sizes into rsi (intptr_t*)
2932 2940 __ movptr(rsi, Address(rdi,
2933 2941 Deoptimization::UnrollBlock::
2934 2942 frame_sizes_offset_in_bytes()));
2935 2943
2936 2944 // Counter
2937 2945 __ movl(rdx, Address(rdi,
2938 2946 Deoptimization::UnrollBlock::
2939 2947 number_of_frames_offset_in_bytes())); // (int)
2940 2948
2941 2949 // Pick up the initial fp we should save
2942 2950 __ movptr(rbp,
2943 2951 Address(rdi,
2944 2952 Deoptimization::UnrollBlock::initial_fp_offset_in_bytes()));
2945 2953
2946 2954 // Now adjust the caller's stack to make up for the extra locals but
2947 2955 // record the original sp so that we can save it in the skeletal
2948 2956 // interpreter frame and the stack walking of interpreter_sender
2949 2957 // will get the unextended sp value and not the "real" sp value.
2950 2958
2951 2959 const Register sender_sp = r8;
2952 2960
2953 2961 __ mov(sender_sp, rsp);
2954 2962 __ movl(rbx, Address(rdi,
2955 2963 Deoptimization::UnrollBlock::
2956 2964 caller_adjustment_offset_in_bytes())); // (int)
2957 2965 __ subptr(rsp, rbx);
2958 2966
2959 2967 // Push interpreter frames in a loop
2960 2968 Label loop;
2961 2969 __ bind(loop);
2962 2970 __ movptr(rbx, Address(rsi, 0)); // Load frame size
2963 2971 __ subptr(rbx, 2 * wordSize); // We'll push pc and rbp by hand
2964 2972 __ pushptr(Address(rcx, 0)); // Save return address
2965 2973 __ enter(); // Save old & set new rbp
2966 2974 __ subptr(rsp, rbx); // Prolog
2967 2975 #ifdef CC_INTERP
2968 2976 __ movptr(Address(rbp,
2969 2977 -(sizeof(BytecodeInterpreter)) + in_bytes(byte_offset_of(BytecodeInterpreter, _sender_sp))),
2970 2978 sender_sp); // Make it walkable
2971 2979 #else // CC_INTERP
2972 2980 __ movptr(Address(rbp, frame::interpreter_frame_sender_sp_offset * wordSize),
2973 2981 sender_sp); // Make it walkable
2974 2982 // This value is corrected by layout_activation_impl
2975 2983 __ movptr(Address(rbp, frame::interpreter_frame_last_sp_offset * wordSize), (int32_t)NULL_WORD );
2976 2984 #endif // CC_INTERP
2977 2985 __ mov(sender_sp, rsp); // Pass sender_sp to next frame
2978 2986 __ addptr(rsi, wordSize); // Bump array pointer (sizes)
2979 2987 __ addptr(rcx, wordSize); // Bump array pointer (pcs)
2980 2988 __ decrementl(rdx); // Decrement counter
2981 2989 __ jcc(Assembler::notZero, loop);
2982 2990 __ pushptr(Address(rcx, 0)); // Save final return address
2983 2991
2984 2992 // Re-push self-frame
2985 2993 __ enter(); // Save old & set new rbp
2986 2994 __ subptr(rsp, (SimpleRuntimeFrame::framesize - 4) << LogBytesPerInt);
2987 2995 // Prolog
2988 2996
2989 2997 // Use rbp because the frames look interpreted now
2990 2998 __ set_last_Java_frame(noreg, rbp, NULL);
2991 2999
2992 3000 // Call C code. Need thread but NOT official VM entry
2993 3001 // crud. We cannot block on this call, no GC can happen. Call should
2994 3002 // restore return values to their stack-slots with the new SP.
2995 3003 // Thread is in rdi already.
2996 3004 //
2997 3005 // BasicType unpack_frames(JavaThread* thread, int exec_mode);
2998 3006
2999 3007 __ mov(c_rarg0, r15_thread);
3000 3008 __ movl(c_rarg1, Deoptimization::Unpack_uncommon_trap);
3001 3009 __ call(RuntimeAddress(CAST_FROM_FN_PTR(address, Deoptimization::unpack_frames)));
3002 3010
3003 3011 // Set an oopmap for the call site
3004 3012 oop_maps->add_gc_map(__ pc() - start, new OopMap(SimpleRuntimeFrame::framesize, 0));
3005 3013
3006 3014 __ reset_last_Java_frame(true, false);
3007 3015
3008 3016 // Pop self-frame.
3009 3017 __ leave(); // Epilog
3010 3018
3011 3019 // Jump to interpreter
3012 3020 __ ret(0);
3013 3021
3014 3022 // Make sure all code is generated
3015 3023 masm->flush();
3016 3024
3017 3025 _uncommon_trap_blob = UncommonTrapBlob::create(&buffer, oop_maps,
3018 3026 SimpleRuntimeFrame::framesize >> 1);
3019 3027 }
3020 3028 #endif // COMPILER2
3021 3029
3022 3030
3023 3031 //------------------------------generate_handler_blob------
3024 3032 //
3025 3033 // Generate a special Compile2Runtime blob that saves all registers,
3026 3034 // and setup oopmap.
3027 3035 //
3028 3036 static SafepointBlob* generate_handler_blob(address call_ptr, bool cause_return) {
3029 3037 assert(StubRoutines::forward_exception_entry() != NULL,
3030 3038 "must be generated before");
3031 3039
3032 3040 ResourceMark rm;
3033 3041 OopMapSet *oop_maps = new OopMapSet();
3034 3042 OopMap* map;
3035 3043
3036 3044 // Allocate space for the code. Setup code generation tools.
3037 3045 CodeBuffer buffer("handler_blob", 2048, 1024);
3038 3046 MacroAssembler* masm = new MacroAssembler(&buffer);
3039 3047
3040 3048 address start = __ pc();
3041 3049 address call_pc = NULL;
3042 3050 int frame_size_in_words;
3043 3051
3044 3052 // Make room for return address (or push it again)
3045 3053 if (!cause_return) {
3046 3054 __ push(rbx);
3047 3055 }
3048 3056
3049 3057 // Save registers, fpu state, and flags
3050 3058 map = RegisterSaver::save_live_registers(masm, 0, &frame_size_in_words);
3051 3059
3052 3060 // The following is basically a call_VM. However, we need the precise
3053 3061 // address of the call in order to generate an oopmap. Hence, we do all the
3054 3062 // work outselves.
3055 3063
3056 3064 __ set_last_Java_frame(noreg, noreg, NULL);
3057 3065
3058 3066 // The return address must always be correct so that frame constructor never
3059 3067 // sees an invalid pc.
3060 3068
3061 3069 if (!cause_return) {
3062 3070 // overwrite the dummy value we pushed on entry
3063 3071 __ movptr(c_rarg0, Address(r15_thread, JavaThread::saved_exception_pc_offset()));
3064 3072 __ movptr(Address(rbp, wordSize), c_rarg0);
3065 3073 }
3066 3074
3067 3075 // Do the call
3068 3076 __ mov(c_rarg0, r15_thread);
3069 3077 __ call(RuntimeAddress(call_ptr));
3070 3078
3071 3079 // Set an oopmap for the call site. This oopmap will map all
3072 3080 // oop-registers and debug-info registers as callee-saved. This
3073 3081 // will allow deoptimization at this safepoint to find all possible
3074 3082 // debug-info recordings, as well as let GC find all oops.
3075 3083
3076 3084 oop_maps->add_gc_map( __ pc() - start, map);
3077 3085
3078 3086 Label noException;
3079 3087
3080 3088 __ reset_last_Java_frame(false, false);
3081 3089
3082 3090 __ cmpptr(Address(r15_thread, Thread::pending_exception_offset()), (int32_t)NULL_WORD);
3083 3091 __ jcc(Assembler::equal, noException);
3084 3092
3085 3093 // Exception pending
3086 3094
3087 3095 RegisterSaver::restore_live_registers(masm);
3088 3096
3089 3097 __ jump(RuntimeAddress(StubRoutines::forward_exception_entry()));
3090 3098
3091 3099 // No exception case
3092 3100 __ bind(noException);
3093 3101
3094 3102 // Normal exit, restore registers and exit.
3095 3103 RegisterSaver::restore_live_registers(masm);
3096 3104
3097 3105 __ ret(0);
3098 3106
3099 3107 // Make sure all code is generated
3100 3108 masm->flush();
3101 3109
3102 3110 // Fill-out other meta info
3103 3111 return SafepointBlob::create(&buffer, oop_maps, frame_size_in_words);
3104 3112 }
3105 3113
3106 3114 //
3107 3115 // generate_resolve_blob - call resolution (static/virtual/opt-virtual/ic-miss
3108 3116 //
3109 3117 // Generate a stub that calls into vm to find out the proper destination
3110 3118 // of a java call. All the argument registers are live at this point
3111 3119 // but since this is generic code we don't know what they are and the caller
3112 3120 // must do any gc of the args.
3113 3121 //
3114 3122 static RuntimeStub* generate_resolve_blob(address destination, const char* name) {
3115 3123 assert (StubRoutines::forward_exception_entry() != NULL, "must be generated before");
3116 3124
3117 3125 // allocate space for the code
3118 3126 ResourceMark rm;
3119 3127
3120 3128 CodeBuffer buffer(name, 1000, 512);
3121 3129 MacroAssembler* masm = new MacroAssembler(&buffer);
3122 3130
3123 3131 int frame_size_in_words;
3124 3132
3125 3133 OopMapSet *oop_maps = new OopMapSet();
3126 3134 OopMap* map = NULL;
3127 3135
3128 3136 int start = __ offset();
3129 3137
3130 3138 map = RegisterSaver::save_live_registers(masm, 0, &frame_size_in_words);
3131 3139
3132 3140 int frame_complete = __ offset();
3133 3141
3134 3142 __ set_last_Java_frame(noreg, noreg, NULL);
3135 3143
3136 3144 __ mov(c_rarg0, r15_thread);
3137 3145
3138 3146 __ call(RuntimeAddress(destination));
3139 3147
3140 3148
3141 3149 // Set an oopmap for the call site.
3142 3150 // We need this not only for callee-saved registers, but also for volatile
3143 3151 // registers that the compiler might be keeping live across a safepoint.
3144 3152
3145 3153 oop_maps->add_gc_map( __ offset() - start, map);
3146 3154
3147 3155 // rax contains the address we are going to jump to assuming no exception got installed
3148 3156
3149 3157 // clear last_Java_sp
3150 3158 __ reset_last_Java_frame(false, false);
3151 3159 // check for pending exceptions
3152 3160 Label pending;
3153 3161 __ cmpptr(Address(r15_thread, Thread::pending_exception_offset()), (int32_t)NULL_WORD);
3154 3162 __ jcc(Assembler::notEqual, pending);
3155 3163
3156 3164 // get the returned methodOop
3157 3165 __ movptr(rbx, Address(r15_thread, JavaThread::vm_result_offset()));
3158 3166 __ movptr(Address(rsp, RegisterSaver::rbx_offset_in_bytes()), rbx);
3159 3167
3160 3168 __ movptr(Address(rsp, RegisterSaver::rax_offset_in_bytes()), rax);
3161 3169
3162 3170 RegisterSaver::restore_live_registers(masm);
3163 3171
3164 3172 // We are back the the original state on entry and ready to go.
3165 3173
3166 3174 __ jmp(rax);
3167 3175
3168 3176 // Pending exception after the safepoint
3169 3177
3170 3178 __ bind(pending);
3171 3179
3172 3180 RegisterSaver::restore_live_registers(masm);
3173 3181
3174 3182 // exception pending => remove activation and forward to exception handler
3175 3183
3176 3184 __ movptr(Address(r15_thread, JavaThread::vm_result_offset()), (int)NULL_WORD);
3177 3185
3178 3186 __ movptr(rax, Address(r15_thread, Thread::pending_exception_offset()));
3179 3187 __ jump(RuntimeAddress(StubRoutines::forward_exception_entry()));
3180 3188
3181 3189 // -------------
3182 3190 // make sure all code is generated
3183 3191 masm->flush();
3184 3192
3185 3193 // return the blob
3186 3194 // frame_size_words or bytes??
3187 3195 return RuntimeStub::new_runtime_stub(name, &buffer, frame_complete, frame_size_in_words, oop_maps, true);
3188 3196 }
3189 3197
3190 3198
3191 3199 void SharedRuntime::generate_stubs() {
3192 3200
3193 3201 _wrong_method_blob = generate_resolve_blob(CAST_FROM_FN_PTR(address, SharedRuntime::handle_wrong_method),
3194 3202 "wrong_method_stub");
3195 3203 _ic_miss_blob = generate_resolve_blob(CAST_FROM_FN_PTR(address, SharedRuntime::handle_wrong_method_ic_miss),
3196 3204 "ic_miss_stub");
3197 3205 _resolve_opt_virtual_call_blob = generate_resolve_blob(CAST_FROM_FN_PTR(address, SharedRuntime::resolve_opt_virtual_call_C),
3198 3206 "resolve_opt_virtual_call");
3199 3207
3200 3208 _resolve_virtual_call_blob = generate_resolve_blob(CAST_FROM_FN_PTR(address, SharedRuntime::resolve_virtual_call_C),
3201 3209 "resolve_virtual_call");
3202 3210
3203 3211 _resolve_static_call_blob = generate_resolve_blob(CAST_FROM_FN_PTR(address, SharedRuntime::resolve_static_call_C),
3204 3212 "resolve_static_call");
3205 3213 _polling_page_safepoint_handler_blob =
3206 3214 generate_handler_blob(CAST_FROM_FN_PTR(address,
3207 3215 SafepointSynchronize::handle_polling_page_exception), false);
3208 3216
3209 3217 _polling_page_return_handler_blob =
3210 3218 generate_handler_blob(CAST_FROM_FN_PTR(address,
3211 3219 SafepointSynchronize::handle_polling_page_exception), true);
3212 3220
3213 3221 generate_deopt_blob();
3214 3222
3215 3223 #ifdef COMPILER2
3216 3224 generate_uncommon_trap_blob();
3217 3225 #endif // COMPILER2
3218 3226 }
3219 3227
3220 3228
3221 3229 #ifdef COMPILER2
3222 3230 // This is here instead of runtime_x86_64.cpp because it uses SimpleRuntimeFrame
3223 3231 //
3224 3232 //------------------------------generate_exception_blob---------------------------
3225 3233 // creates exception blob at the end
3226 3234 // Using exception blob, this code is jumped from a compiled method.
3227 3235 // (see emit_exception_handler in x86_64.ad file)
3228 3236 //
3229 3237 // Given an exception pc at a call we call into the runtime for the
3230 3238 // handler in this method. This handler might merely restore state
3231 3239 // (i.e. callee save registers) unwind the frame and jump to the
3232 3240 // exception handler for the nmethod if there is no Java level handler
3233 3241 // for the nmethod.
3234 3242 //
3235 3243 // This code is entered with a jmp.
3236 3244 //
3237 3245 // Arguments:
3238 3246 // rax: exception oop
3239 3247 // rdx: exception pc
3240 3248 //
3241 3249 // Results:
3242 3250 // rax: exception oop
3243 3251 // rdx: exception pc in caller or ???
3244 3252 // destination: exception handler of caller
3245 3253 //
3246 3254 // Note: the exception pc MUST be at a call (precise debug information)
3247 3255 // Registers rax, rdx, rcx, rsi, rdi, r8-r11 are not callee saved.
3248 3256 //
3249 3257
3250 3258 void OptoRuntime::generate_exception_blob() {
3251 3259 assert(!OptoRuntime::is_callee_saved_register(RDX_num), "");
3252 3260 assert(!OptoRuntime::is_callee_saved_register(RAX_num), "");
3253 3261 assert(!OptoRuntime::is_callee_saved_register(RCX_num), "");
3254 3262
3255 3263 assert(SimpleRuntimeFrame::framesize % 4 == 0, "sp not 16-byte aligned");
3256 3264
3257 3265 // Allocate space for the code
3258 3266 ResourceMark rm;
3259 3267 // Setup code generation tools
3260 3268 CodeBuffer buffer("exception_blob", 2048, 1024);
3261 3269 MacroAssembler* masm = new MacroAssembler(&buffer);
3262 3270
3263 3271
3264 3272 address start = __ pc();
3265 3273
3266 3274 // Exception pc is 'return address' for stack walker
3267 3275 __ push(rdx);
3268 3276 __ subptr(rsp, SimpleRuntimeFrame::return_off << LogBytesPerInt); // Prolog
3269 3277
3270 3278 // Save callee-saved registers. See x86_64.ad.
3271 3279
3272 3280 // rbp is an implicitly saved callee saved register (i.e. the calling
3273 3281 // convention will save restore it in prolog/epilog) Other than that
3274 3282 // there are no callee save registers now that adapter frames are gone.
3275 3283
3276 3284 __ movptr(Address(rsp, SimpleRuntimeFrame::rbp_off << LogBytesPerInt), rbp);
3277 3285
3278 3286 // Store exception in Thread object. We cannot pass any arguments to the
3279 3287 // handle_exception call, since we do not want to make any assumption
3280 3288 // about the size of the frame where the exception happened in.
3281 3289 // c_rarg0 is either rdi (Linux) or rcx (Windows).
3282 3290 __ movptr(Address(r15_thread, JavaThread::exception_oop_offset()),rax);
3283 3291 __ movptr(Address(r15_thread, JavaThread::exception_pc_offset()), rdx);
3284 3292
3285 3293 // This call does all the hard work. It checks if an exception handler
3286 3294 // exists in the method.
3287 3295 // If so, it returns the handler address.
3288 3296 // If not, it prepares for stack-unwinding, restoring the callee-save
3289 3297 // registers of the frame being removed.
3290 3298 //
3291 3299 // address OptoRuntime::handle_exception_C(JavaThread* thread)
3292 3300
3293 3301 __ set_last_Java_frame(noreg, noreg, NULL);
3294 3302 __ mov(c_rarg0, r15_thread);
3295 3303 __ call(RuntimeAddress(CAST_FROM_FN_PTR(address, OptoRuntime::handle_exception_C)));
3296 3304
3297 3305 // Set an oopmap for the call site. This oopmap will only be used if we
3298 3306 // are unwinding the stack. Hence, all locations will be dead.
3299 3307 // Callee-saved registers will be the same as the frame above (i.e.,
3300 3308 // handle_exception_stub), since they were restored when we got the
3301 3309 // exception.
3302 3310
3303 3311 OopMapSet* oop_maps = new OopMapSet();
3304 3312
3305 3313 oop_maps->add_gc_map( __ pc()-start, new OopMap(SimpleRuntimeFrame::framesize, 0));
3306 3314
3307 3315 __ reset_last_Java_frame(false, false);
3308 3316
3309 3317 // Restore callee-saved registers
3310 3318
3311 3319 // rbp is an implicitly saved callee saved register (i.e. the calling
↓ open down ↓ |
2557 lines elided |
↑ open up ↑ |
3312 3320 // convention will save restore it in prolog/epilog) Other than that
3313 3321 // there are no callee save registers no that adapter frames are gone.
3314 3322
3315 3323 __ movptr(rbp, Address(rsp, SimpleRuntimeFrame::rbp_off << LogBytesPerInt));
3316 3324
3317 3325 __ addptr(rsp, SimpleRuntimeFrame::return_off << LogBytesPerInt); // Epilog
3318 3326 __ pop(rdx); // No need for exception pc anymore
3319 3327
3320 3328 // rax: exception handler
3321 3329
3330 + // Restore SP from BP if the exception PC is a MethodHandle call.
3331 + __ cmpl(Address(r15_thread, JavaThread::is_method_handle_exception_offset()), 0);
3332 + __ cmovptr(Assembler::notEqual, rsp, rbp);
3333 +
3322 3334 // We have a handler in rax (could be deopt blob).
3323 3335 __ mov(r8, rax);
3324 3336
3325 3337 // Get the exception oop
3326 3338 __ movptr(rax, Address(r15_thread, JavaThread::exception_oop_offset()));
3327 3339 // Get the exception pc in case we are deoptimized
3328 3340 __ movptr(rdx, Address(r15_thread, JavaThread::exception_pc_offset()));
3329 3341 #ifdef ASSERT
3330 3342 __ movptr(Address(r15_thread, JavaThread::exception_handler_pc_offset()), (int)NULL_WORD);
3331 3343 __ movptr(Address(r15_thread, JavaThread::exception_pc_offset()), (int)NULL_WORD);
3332 3344 #endif
3333 3345 // Clear the exception oop so GC no longer processes it as a root.
3334 3346 __ movptr(Address(r15_thread, JavaThread::exception_oop_offset()), (int)NULL_WORD);
3335 3347
3336 3348 // rax: exception oop
3337 3349 // r8: exception handler
3338 3350 // rdx: exception pc
3339 3351 // Jump to handler
3340 3352
3341 3353 __ jmp(r8);
3342 3354
3343 3355 // Make sure all code is generated
3344 3356 masm->flush();
3345 3357
3346 3358 // Set exception blob
3347 3359 _exception_blob = ExceptionBlob::create(&buffer, oop_maps, SimpleRuntimeFrame::framesize >> 1);
3348 3360 }
3349 3361 #endif // COMPILER2
↓ open down ↓ |
18 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX