annotate src/cpu/x86/vm/runtime_x86_32.cpp @ 0:a61af66fc99e

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