src/cpu/x86/vm/runtime_x86_32.cpp

Mon, 13 Sep 2010 23:24:30 -0700

author
jrose
date
Mon, 13 Sep 2010 23:24:30 -0700
changeset 2148
d257356e35f0
parent 1934
e9ff18c4ace7
child 2314
f95d63e2154a
permissions
-rw-r--r--

6939224: MethodHandle.invokeGeneric needs to perform the correct set of conversions
Reviewed-by: never

duke@435 1 /*
jrose@1934 2 * Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved.
duke@435 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@435 4 *
duke@435 5 * This code is free software; you can redistribute it and/or modify it
duke@435 6 * under the terms of the GNU General Public License version 2 only, as
duke@435 7 * published by the Free Software Foundation.
duke@435 8 *
duke@435 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@435 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@435 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@435 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@435 13 * accompanied this code).
duke@435 14 *
duke@435 15 * You should have received a copy of the GNU General Public License version
duke@435 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@435 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@435 18 *
trims@1907 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1907 20 * or visit www.oracle.com if you need additional information or have any
trims@1907 21 * questions.
duke@435 22 *
duke@435 23 */
duke@435 24
duke@435 25
duke@435 26 #include "incls/_precompiled.incl"
duke@435 27 #include "incls/_runtime_x86_32.cpp.incl"
duke@435 28
duke@435 29 #define __ masm->
duke@435 30
duke@435 31 ExceptionBlob* OptoRuntime::_exception_blob;
duke@435 32
duke@435 33 //------------------------------generate_exception_blob---------------------------
duke@435 34 // creates exception blob at the end
duke@435 35 // Using exception blob, this code is jumped from a compiled method.
duke@435 36 //
duke@435 37 // Given an exception pc at a call we call into the runtime for the
duke@435 38 // handler in this method. This handler might merely restore state
duke@435 39 // (i.e. callee save registers) unwind the frame and jump to the
duke@435 40 // exception handler for the nmethod if there is no Java level handler
duke@435 41 // for the nmethod.
duke@435 42 //
duke@435 43 // This code is entered with a jmp.
duke@435 44 //
duke@435 45 // Arguments:
twisti@1570 46 // rax: exception oop
duke@435 47 // rdx: exception pc
duke@435 48 //
duke@435 49 // Results:
twisti@1570 50 // rax: exception oop
duke@435 51 // rdx: exception pc in caller or ???
duke@435 52 // destination: exception handler of caller
duke@435 53 //
duke@435 54 // Note: the exception pc MUST be at a call (precise debug information)
duke@435 55 // Only register rax, rdx, rcx are not callee saved.
duke@435 56 //
duke@435 57
duke@435 58 void OptoRuntime::generate_exception_blob() {
duke@435 59
duke@435 60 // Capture info about frame layout
duke@435 61 enum layout {
duke@435 62 thread_off, // last_java_sp
duke@435 63 // The frame sender code expects that rbp will be in the "natural" place and
duke@435 64 // will override any oopMap setting for it. We must therefore force the layout
duke@435 65 // so that it agrees with the frame sender code.
duke@435 66 rbp_off,
duke@435 67 return_off, // slot for return address
duke@435 68 framesize
duke@435 69 };
duke@435 70
duke@435 71 // allocate space for the code
duke@435 72 ResourceMark rm;
duke@435 73 // setup code generation tools
duke@435 74 CodeBuffer buffer("exception_blob", 512, 512);
duke@435 75 MacroAssembler* masm = new MacroAssembler(&buffer);
duke@435 76
duke@435 77 OopMapSet *oop_maps = new OopMapSet();
duke@435 78
duke@435 79 address start = __ pc();
duke@435 80
never@739 81 __ push(rdx);
never@739 82 __ subptr(rsp, return_off * wordSize); // Prolog!
duke@435 83
duke@435 84 // rbp, location is implicitly known
never@739 85 __ movptr(Address(rsp,rbp_off *wordSize), rbp);
duke@435 86
duke@435 87 // Store exception in Thread object. We cannot pass any arguments to the
duke@435 88 // handle_exception call, since we do not want to make any assumption
duke@435 89 // about the size of the frame where the exception happened in.
duke@435 90 __ get_thread(rcx);
never@739 91 __ movptr(Address(rcx, JavaThread::exception_oop_offset()), rax);
never@739 92 __ movptr(Address(rcx, JavaThread::exception_pc_offset()), rdx);
duke@435 93
duke@435 94 // This call does all the hard work. It checks if an exception handler
duke@435 95 // exists in the method.
duke@435 96 // If so, it returns the handler address.
duke@435 97 // If not, it prepares for stack-unwinding, restoring the callee-save
duke@435 98 // registers of the frame being removed.
duke@435 99 //
never@739 100 __ movptr(Address(rsp, thread_off * wordSize), rcx); // Thread is first argument
duke@435 101 __ set_last_Java_frame(rcx, noreg, noreg, NULL);
duke@435 102
duke@435 103 __ call(RuntimeAddress(CAST_FROM_FN_PTR(address, OptoRuntime::handle_exception_C)));
duke@435 104
duke@435 105 // No registers to map, rbp is known implicitly
duke@435 106 oop_maps->add_gc_map( __ pc() - start, new OopMap( framesize, 0 ));
duke@435 107 __ get_thread(rcx);
duke@435 108 __ reset_last_Java_frame(rcx, false, false);
duke@435 109
duke@435 110 // Restore callee-saved registers
never@739 111 __ movptr(rbp, Address(rsp, rbp_off * wordSize));
duke@435 112
never@739 113 __ addptr(rsp, return_off * wordSize); // Epilog!
never@739 114 __ pop(rdx); // Exception pc
duke@435 115
twisti@1570 116 // rax: exception handler for given <exception oop/exception pc>
duke@435 117
twisti@1803 118 // Restore SP from BP if the exception PC is a MethodHandle call site.
twisti@1803 119 __ cmpl(Address(rcx, JavaThread::is_method_handle_return_offset()), 0);
twisti@1922 120 __ cmovptr(Assembler::notEqual, rsp, rbp_mh_SP_save);
duke@435 121
duke@435 122 // We have a handler in rax, (could be deopt blob)
duke@435 123 // rdx - throwing pc, deopt blob will need it.
duke@435 124
never@739 125 __ push(rax);
duke@435 126
duke@435 127 // Get the exception
never@739 128 __ movptr(rax, Address(rcx, JavaThread::exception_oop_offset()));
duke@435 129 // Get the exception pc in case we are deoptimized
never@739 130 __ movptr(rdx, Address(rcx, JavaThread::exception_pc_offset()));
duke@435 131 #ifdef ASSERT
xlu@947 132 __ movptr(Address(rcx, JavaThread::exception_handler_pc_offset()), NULL_WORD);
xlu@947 133 __ movptr(Address(rcx, JavaThread::exception_pc_offset()), NULL_WORD);
duke@435 134 #endif
duke@435 135 // Clear the exception oop so GC no longer processes it as a root.
xlu@947 136 __ movptr(Address(rcx, JavaThread::exception_oop_offset()), NULL_WORD);
duke@435 137
never@739 138 __ pop(rcx);
duke@435 139
twisti@1570 140 // rax: exception oop
duke@435 141 // rcx: exception handler
duke@435 142 // rdx: exception pc
duke@435 143 __ jmp (rcx);
duke@435 144
duke@435 145 // -------------
duke@435 146 // make sure all code is generated
duke@435 147 masm->flush();
duke@435 148
duke@435 149 _exception_blob = ExceptionBlob::create(&buffer, oop_maps, framesize);
duke@435 150 }

mercurial