8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #ifdef COMPILER2
26 #include "asm/macroAssembler.hpp"
27 #include "asm/macroAssembler.inline.hpp"
28 #include "code/vmreg.hpp"
29 #include "interpreter/interpreter.hpp"
30 #include "opto/runtime.hpp"
31 #include "runtime/sharedRuntime.hpp"
32 #include "runtime/stubRoutines.hpp"
33 #include "runtime/vframeArray.hpp"
34 #include "utilities/globalDefinitions.hpp"
35 #include "vmreg_x86.inline.hpp"
36
37 class SimpleRuntimeFrame {
38
39 public:
40
41 // Most of the runtime stubs have this simple frame layout.
42 // This class exists to make the layout shared in one place.
43 // Offsets are for compiler stack slots, which are jints.
44 enum layout {
45 // The frame sender code expects that rbp will be in the "natural" place and
46 // will override any oopMap setting for it. We must therefore force the layout
47 // so that it agrees with the frame sender code.
248 // Results:
249 // rax: exception oop
250 // rdx: exception pc in caller or ???
251 // destination: exception handler of caller
252 //
253 // Note: the exception pc MUST be at a call (precise debug information)
254 // Registers rax, rdx, rcx, rsi, rdi, r8-r11 are not callee saved.
255 //
256
257 void OptoRuntime::generate_exception_blob() {
258 assert(!OptoRuntime::is_callee_saved_register(RDX_num), "");
259 assert(!OptoRuntime::is_callee_saved_register(RAX_num), "");
260 assert(!OptoRuntime::is_callee_saved_register(RCX_num), "");
261
262 assert(SimpleRuntimeFrame::framesize % 4 == 0, "sp not 16-byte aligned");
263
264 // Allocate space for the code
265 ResourceMark rm;
266 // Setup code generation tools
267 CodeBuffer buffer("exception_blob", 2048, 1024);
268 MacroAssembler* masm = new MacroAssembler(&buffer);
269
270
271 address start = __ pc();
272
273 // Exception pc is 'return address' for stack walker
274 __ push(rdx);
275 __ subptr(rsp, SimpleRuntimeFrame::return_off << LogBytesPerInt); // Prolog
276
277 // Save callee-saved registers. See x86_64.ad.
278
279 // rbp is an implicitly saved callee saved register (i.e., the calling
280 // convention will save/restore it in the prolog/epilog). Other than that
281 // there are no callee save registers now that adapter frames are gone.
282
283 __ movptr(Address(rsp, SimpleRuntimeFrame::rbp_off << LogBytesPerInt), rbp);
284
285 // Store exception in Thread object. We cannot pass any arguments to the
286 // handle_exception call, since we do not want to make any assumption
287 // about the size of the frame where the exception happened in.
288 // c_rarg0 is either rdi (Linux) or rcx (Windows).
289 __ movptr(Address(r15_thread, JavaThread::exception_oop_offset()),rax);
290 __ movptr(Address(r15_thread, JavaThread::exception_pc_offset()), rdx);
296 // registers of the frame being removed.
297 //
298 // address OptoRuntime::handle_exception_C(JavaThread* thread)
299
300 // At a method handle call, the stack may not be properly aligned
301 // when returning with an exception.
302 address the_pc = __ pc();
303 __ set_last_Java_frame(noreg, noreg, the_pc, rscratch1);
304 __ mov(c_rarg0, r15_thread);
305 __ andptr(rsp, -(StackAlignmentInBytes)); // Align stack
306 __ call(RuntimeAddress(CAST_FROM_FN_PTR(address, OptoRuntime::handle_exception_C)));
307
308 // Set an oopmap for the call site. This oopmap will only be used if we
309 // are unwinding the stack. Hence, all locations will be dead.
310 // Callee-saved registers will be the same as the frame above (i.e.,
311 // handle_exception_stub), since they were restored when we got the
312 // exception.
313
314 OopMapSet* oop_maps = new OopMapSet();
315
316 oop_maps->add_gc_map(the_pc - start, new OopMap(SimpleRuntimeFrame::framesize, 0));
317
318 __ reset_last_Java_frame(false);
319
320 // Restore callee-saved registers
321
322 // rbp is an implicitly saved callee-saved register (i.e., the calling
323 // convention will save restore it in prolog/epilog) Other than that
324 // there are no callee save registers now that adapter frames are gone.
325
326 __ movptr(rbp, Address(rsp, SimpleRuntimeFrame::rbp_off << LogBytesPerInt));
327
328 __ addptr(rsp, SimpleRuntimeFrame::return_off << LogBytesPerInt); // Epilog
329 __ pop(rdx); // No need for exception pc anymore
330
331 // rax: exception handler
332
333 // We have a handler in rax (could be deopt blob).
334 __ mov(r8, rax);
335
336 // Get the exception oop
337 __ movptr(rax, Address(r15_thread, JavaThread::exception_oop_offset()));
338 // Get the exception pc in case we are deoptimized
339 __ movptr(rdx, Address(r15_thread, JavaThread::exception_pc_offset()));
340 #ifdef ASSERT
341 __ movptr(Address(r15_thread, JavaThread::exception_handler_pc_offset()), NULL_WORD);
342 __ movptr(Address(r15_thread, JavaThread::exception_pc_offset()), NULL_WORD);
343 #endif
344 // Clear the exception oop so GC no longer processes it as a root.
345 __ movptr(Address(r15_thread, JavaThread::exception_oop_offset()), NULL_WORD);
346
347 // rax: exception oop
348 // r8: exception handler
349 // rdx: exception pc
350 // Jump to handler
351
352 __ jmp(r8);
353
354 // Make sure all code is generated
355 masm->flush();
356
357 // Set exception blob
358 _exception_blob = ExceptionBlob::create(&buffer, oop_maps, SimpleRuntimeFrame::framesize >> 1);
359 }
360 #endif // COMPILER2
|
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #ifdef COMPILER2
26 #include "asm/macroAssembler.hpp"
27 #include "asm/macroAssembler.inline.hpp"
28 #include "code/SCCache.hpp"
29 #include "code/vmreg.hpp"
30 #include "interpreter/interpreter.hpp"
31 #include "opto/runtime.hpp"
32 #include "runtime/sharedRuntime.hpp"
33 #include "runtime/stubRoutines.hpp"
34 #include "runtime/vframeArray.hpp"
35 #include "utilities/globalDefinitions.hpp"
36 #include "vmreg_x86.inline.hpp"
37
38 class SimpleRuntimeFrame {
39
40 public:
41
42 // Most of the runtime stubs have this simple frame layout.
43 // This class exists to make the layout shared in one place.
44 // Offsets are for compiler stack slots, which are jints.
45 enum layout {
46 // The frame sender code expects that rbp will be in the "natural" place and
47 // will override any oopMap setting for it. We must therefore force the layout
48 // so that it agrees with the frame sender code.
249 // Results:
250 // rax: exception oop
251 // rdx: exception pc in caller or ???
252 // destination: exception handler of caller
253 //
254 // Note: the exception pc MUST be at a call (precise debug information)
255 // Registers rax, rdx, rcx, rsi, rdi, r8-r11 are not callee saved.
256 //
257
258 void OptoRuntime::generate_exception_blob() {
259 assert(!OptoRuntime::is_callee_saved_register(RDX_num), "");
260 assert(!OptoRuntime::is_callee_saved_register(RAX_num), "");
261 assert(!OptoRuntime::is_callee_saved_register(RCX_num), "");
262
263 assert(SimpleRuntimeFrame::framesize % 4 == 0, "sp not 16-byte aligned");
264
265 // Allocate space for the code
266 ResourceMark rm;
267 // Setup code generation tools
268 CodeBuffer buffer("exception_blob", 2048, 1024);
269 int pc_offset = 0;
270 if (SCCache::load_exception_blob(&buffer, &pc_offset)) {
271 OopMapSet* oop_maps = new OopMapSet();
272 oop_maps->add_gc_map(pc_offset, new OopMap(SimpleRuntimeFrame::framesize, 0));
273
274 // Set exception blob
275 _exception_blob = ExceptionBlob::create(&buffer, oop_maps, SimpleRuntimeFrame::framesize >> 1);
276 return;
277 }
278
279 MacroAssembler* masm = new MacroAssembler(&buffer);
280 address start = __ pc();
281
282 // Exception pc is 'return address' for stack walker
283 __ push(rdx);
284 __ subptr(rsp, SimpleRuntimeFrame::return_off << LogBytesPerInt); // Prolog
285
286 // Save callee-saved registers. See x86_64.ad.
287
288 // rbp is an implicitly saved callee saved register (i.e., the calling
289 // convention will save/restore it in the prolog/epilog). Other than that
290 // there are no callee save registers now that adapter frames are gone.
291
292 __ movptr(Address(rsp, SimpleRuntimeFrame::rbp_off << LogBytesPerInt), rbp);
293
294 // Store exception in Thread object. We cannot pass any arguments to the
295 // handle_exception call, since we do not want to make any assumption
296 // about the size of the frame where the exception happened in.
297 // c_rarg0 is either rdi (Linux) or rcx (Windows).
298 __ movptr(Address(r15_thread, JavaThread::exception_oop_offset()),rax);
299 __ movptr(Address(r15_thread, JavaThread::exception_pc_offset()), rdx);
305 // registers of the frame being removed.
306 //
307 // address OptoRuntime::handle_exception_C(JavaThread* thread)
308
309 // At a method handle call, the stack may not be properly aligned
310 // when returning with an exception.
311 address the_pc = __ pc();
312 __ set_last_Java_frame(noreg, noreg, the_pc, rscratch1);
313 __ mov(c_rarg0, r15_thread);
314 __ andptr(rsp, -(StackAlignmentInBytes)); // Align stack
315 __ call(RuntimeAddress(CAST_FROM_FN_PTR(address, OptoRuntime::handle_exception_C)));
316
317 // Set an oopmap for the call site. This oopmap will only be used if we
318 // are unwinding the stack. Hence, all locations will be dead.
319 // Callee-saved registers will be the same as the frame above (i.e.,
320 // handle_exception_stub), since they were restored when we got the
321 // exception.
322
323 OopMapSet* oop_maps = new OopMapSet();
324
325 pc_offset = the_pc - start;
326 oop_maps->add_gc_map(pc_offset, new OopMap(SimpleRuntimeFrame::framesize, 0));
327
328 __ reset_last_Java_frame(false);
329
330 // Restore callee-saved registers
331
332 // rbp is an implicitly saved callee-saved register (i.e., the calling
333 // convention will save restore it in prolog/epilog) Other than that
334 // there are no callee save registers now that adapter frames are gone.
335
336 __ movptr(rbp, Address(rsp, SimpleRuntimeFrame::rbp_off << LogBytesPerInt));
337
338 __ addptr(rsp, SimpleRuntimeFrame::return_off << LogBytesPerInt); // Epilog
339 __ pop(rdx); // No need for exception pc anymore
340
341 // rax: exception handler
342
343 // We have a handler in rax (could be deopt blob).
344 __ mov(r8, rax);
345
346 // Get the exception oop
347 __ movptr(rax, Address(r15_thread, JavaThread::exception_oop_offset()));
348 // Get the exception pc in case we are deoptimized
349 __ movptr(rdx, Address(r15_thread, JavaThread::exception_pc_offset()));
350 #ifdef ASSERT
351 __ movptr(Address(r15_thread, JavaThread::exception_handler_pc_offset()), NULL_WORD);
352 __ movptr(Address(r15_thread, JavaThread::exception_pc_offset()), NULL_WORD);
353 #endif
354 // Clear the exception oop so GC no longer processes it as a root.
355 __ movptr(Address(r15_thread, JavaThread::exception_oop_offset()), NULL_WORD);
356
357 // rax: exception oop
358 // r8: exception handler
359 // rdx: exception pc
360 // Jump to handler
361
362 __ jmp(r8);
363
364 // Make sure all code is generated
365 masm->flush();
366
367 SCCache::store_exception_blob(&buffer, pc_offset);
368 // Set exception blob
369 _exception_blob = ExceptionBlob::create(&buffer, oop_maps, SimpleRuntimeFrame::framesize >> 1);
370 }
371 #endif // COMPILER2
|