src/cpu/x86/vm/runtime_x86_32.cpp

Tue, 23 Nov 2010 13:22:55 -0800

author
stefank
date
Tue, 23 Nov 2010 13:22:55 -0800
changeset 2314
f95d63e2154a
parent 1934
e9ff18c4ace7
child 2950
cba7b5c2d53f
permissions
-rw-r--r--

6989984: Use standard include model for Hospot
Summary: Replaced MakeDeps and the includeDB files with more standardized solutions.
Reviewed-by: coleenp, kvn, kamg

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
stefank@2314 25 #include "precompiled.hpp"
stefank@2314 26 #ifdef COMPILER2
stefank@2314 27 #include "asm/assembler.hpp"
stefank@2314 28 #include "assembler_x86.inline.hpp"
stefank@2314 29 #include "classfile/systemDictionary.hpp"
stefank@2314 30 #include "code/vmreg.hpp"
stefank@2314 31 #include "interpreter/interpreter.hpp"
stefank@2314 32 #include "nativeInst_x86.hpp"
stefank@2314 33 #include "opto/runtime.hpp"
stefank@2314 34 #include "runtime/interfaceSupport.hpp"
stefank@2314 35 #include "runtime/sharedRuntime.hpp"
stefank@2314 36 #include "runtime/stubRoutines.hpp"
stefank@2314 37 #include "runtime/vframeArray.hpp"
stefank@2314 38 #include "utilities/globalDefinitions.hpp"
stefank@2314 39 #include "vmreg_x86.inline.hpp"
stefank@2314 40 #endif
duke@435 41
duke@435 42
duke@435 43 #define __ masm->
duke@435 44
duke@435 45 ExceptionBlob* OptoRuntime::_exception_blob;
duke@435 46
duke@435 47 //------------------------------generate_exception_blob---------------------------
duke@435 48 // creates exception blob at the end
duke@435 49 // Using exception blob, this code is jumped from a compiled method.
duke@435 50 //
duke@435 51 // Given an exception pc at a call we call into the runtime for the
duke@435 52 // handler in this method. This handler might merely restore state
duke@435 53 // (i.e. callee save registers) unwind the frame and jump to the
duke@435 54 // exception handler for the nmethod if there is no Java level handler
duke@435 55 // for the nmethod.
duke@435 56 //
duke@435 57 // This code is entered with a jmp.
duke@435 58 //
duke@435 59 // Arguments:
twisti@1570 60 // rax: exception oop
duke@435 61 // rdx: exception pc
duke@435 62 //
duke@435 63 // Results:
twisti@1570 64 // rax: exception oop
duke@435 65 // rdx: exception pc in caller or ???
duke@435 66 // destination: exception handler of caller
duke@435 67 //
duke@435 68 // Note: the exception pc MUST be at a call (precise debug information)
duke@435 69 // Only register rax, rdx, rcx are not callee saved.
duke@435 70 //
duke@435 71
duke@435 72 void OptoRuntime::generate_exception_blob() {
duke@435 73
duke@435 74 // Capture info about frame layout
duke@435 75 enum layout {
duke@435 76 thread_off, // last_java_sp
duke@435 77 // The frame sender code expects that rbp will be in the "natural" place and
duke@435 78 // will override any oopMap setting for it. We must therefore force the layout
duke@435 79 // so that it agrees with the frame sender code.
duke@435 80 rbp_off,
duke@435 81 return_off, // slot for return address
duke@435 82 framesize
duke@435 83 };
duke@435 84
duke@435 85 // allocate space for the code
duke@435 86 ResourceMark rm;
duke@435 87 // setup code generation tools
duke@435 88 CodeBuffer buffer("exception_blob", 512, 512);
duke@435 89 MacroAssembler* masm = new MacroAssembler(&buffer);
duke@435 90
duke@435 91 OopMapSet *oop_maps = new OopMapSet();
duke@435 92
duke@435 93 address start = __ pc();
duke@435 94
never@739 95 __ push(rdx);
never@739 96 __ subptr(rsp, return_off * wordSize); // Prolog!
duke@435 97
duke@435 98 // rbp, location is implicitly known
never@739 99 __ movptr(Address(rsp,rbp_off *wordSize), rbp);
duke@435 100
duke@435 101 // Store exception in Thread object. We cannot pass any arguments to the
duke@435 102 // handle_exception call, since we do not want to make any assumption
duke@435 103 // about the size of the frame where the exception happened in.
duke@435 104 __ get_thread(rcx);
never@739 105 __ movptr(Address(rcx, JavaThread::exception_oop_offset()), rax);
never@739 106 __ movptr(Address(rcx, JavaThread::exception_pc_offset()), rdx);
duke@435 107
duke@435 108 // This call does all the hard work. It checks if an exception handler
duke@435 109 // exists in the method.
duke@435 110 // If so, it returns the handler address.
duke@435 111 // If not, it prepares for stack-unwinding, restoring the callee-save
duke@435 112 // registers of the frame being removed.
duke@435 113 //
never@739 114 __ movptr(Address(rsp, thread_off * wordSize), rcx); // Thread is first argument
duke@435 115 __ set_last_Java_frame(rcx, noreg, noreg, NULL);
duke@435 116
duke@435 117 __ call(RuntimeAddress(CAST_FROM_FN_PTR(address, OptoRuntime::handle_exception_C)));
duke@435 118
duke@435 119 // No registers to map, rbp is known implicitly
duke@435 120 oop_maps->add_gc_map( __ pc() - start, new OopMap( framesize, 0 ));
duke@435 121 __ get_thread(rcx);
duke@435 122 __ reset_last_Java_frame(rcx, false, false);
duke@435 123
duke@435 124 // Restore callee-saved registers
never@739 125 __ movptr(rbp, Address(rsp, rbp_off * wordSize));
duke@435 126
never@739 127 __ addptr(rsp, return_off * wordSize); // Epilog!
never@739 128 __ pop(rdx); // Exception pc
duke@435 129
twisti@1570 130 // rax: exception handler for given <exception oop/exception pc>
duke@435 131
twisti@1803 132 // Restore SP from BP if the exception PC is a MethodHandle call site.
twisti@1803 133 __ cmpl(Address(rcx, JavaThread::is_method_handle_return_offset()), 0);
twisti@1922 134 __ cmovptr(Assembler::notEqual, rsp, rbp_mh_SP_save);
duke@435 135
duke@435 136 // We have a handler in rax, (could be deopt blob)
duke@435 137 // rdx - throwing pc, deopt blob will need it.
duke@435 138
never@739 139 __ push(rax);
duke@435 140
duke@435 141 // Get the exception
never@739 142 __ movptr(rax, Address(rcx, JavaThread::exception_oop_offset()));
duke@435 143 // Get the exception pc in case we are deoptimized
never@739 144 __ movptr(rdx, Address(rcx, JavaThread::exception_pc_offset()));
duke@435 145 #ifdef ASSERT
xlu@947 146 __ movptr(Address(rcx, JavaThread::exception_handler_pc_offset()), NULL_WORD);
xlu@947 147 __ movptr(Address(rcx, JavaThread::exception_pc_offset()), NULL_WORD);
duke@435 148 #endif
duke@435 149 // Clear the exception oop so GC no longer processes it as a root.
xlu@947 150 __ movptr(Address(rcx, JavaThread::exception_oop_offset()), NULL_WORD);
duke@435 151
never@739 152 __ pop(rcx);
duke@435 153
twisti@1570 154 // rax: exception oop
duke@435 155 // rcx: exception handler
duke@435 156 // rdx: exception pc
duke@435 157 __ jmp (rcx);
duke@435 158
duke@435 159 // -------------
duke@435 160 // make sure all code is generated
duke@435 161 masm->flush();
duke@435 162
duke@435 163 _exception_blob = ExceptionBlob::create(&buffer, oop_maps, framesize);
duke@435 164 }

mercurial