duke@435: /* jrose@1934: * Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved. duke@435: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@435: * duke@435: * This code is free software; you can redistribute it and/or modify it duke@435: * under the terms of the GNU General Public License version 2 only, as duke@435: * published by the Free Software Foundation. duke@435: * duke@435: * This code is distributed in the hope that it will be useful, but WITHOUT duke@435: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@435: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@435: * version 2 for more details (a copy is included in the LICENSE file that duke@435: * accompanied this code). duke@435: * duke@435: * You should have received a copy of the GNU General Public License version duke@435: * 2 along with this work; if not, write to the Free Software Foundation, duke@435: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@435: * trims@1907: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA trims@1907: * or visit www.oracle.com if you need additional information or have any trims@1907: * questions. duke@435: * duke@435: */ duke@435: duke@435: #include "incls/_precompiled.incl" duke@435: #include "incls/_runtime_sparc.cpp.incl" duke@435: duke@435: duke@435: #define __ masm-> duke@435: duke@435: ExceptionBlob *OptoRuntime::_exception_blob; duke@435: duke@435: //------------------------------ generate_exception_blob --------------------------- duke@435: // creates exception blob at the end duke@435: // Using exception blob, this code is jumped from a compiled method. duke@435: // (see emit_exception_handler in sparc.ad file) duke@435: // duke@435: // Given an exception pc at a call we call into the runtime for the duke@435: // handler in this method. This handler might merely restore state duke@435: // (i.e. callee save registers) unwind the frame and jump to the duke@435: // exception handler for the nmethod if there is no Java level handler duke@435: // for the nmethod. duke@435: // duke@435: // This code is entered with a jmp. duke@435: // duke@435: // Arguments: duke@435: // O0: exception oop duke@435: // O1: exception pc duke@435: // duke@435: // Results: duke@435: // O0: exception oop duke@435: // O1: exception pc in caller or ??? duke@435: // destination: exception handler of caller duke@435: // duke@435: // Note: the exception pc MUST be at a call (precise debug information) duke@435: // duke@435: void OptoRuntime::generate_exception_blob() { duke@435: // allocate space for code duke@435: ResourceMark rm; duke@435: int pad = VerifyThread ? 256 : 0;// Extra slop space for more verify code duke@435: duke@435: // setup code generation tools duke@435: // Measured 8/7/03 at 256 in 32bit debug build (no VerifyThread) duke@435: // Measured 8/7/03 at 528 in 32bit debug build (VerifyThread) duke@435: CodeBuffer buffer("exception_blob", 600+pad, 512); duke@435: MacroAssembler* masm = new MacroAssembler(&buffer); duke@435: duke@435: int framesize_in_bytes = __ total_frame_size_in_bytes(0); duke@435: int framesize_in_words = framesize_in_bytes / wordSize; duke@435: int framesize_in_slots = framesize_in_bytes / sizeof(jint); duke@435: duke@435: Label L; duke@435: duke@435: int start = __ offset(); duke@435: duke@435: __ verify_thread(); twisti@1162: __ st_ptr(Oexception, G2_thread, JavaThread::exception_oop_offset()); twisti@1162: __ st_ptr(Oissuing_pc, G2_thread, JavaThread::exception_pc_offset()); duke@435: duke@435: // This call does all the hard work. It checks if an exception catch duke@435: // exists in the method. duke@435: // If so, it returns the handler address. duke@435: // If the nmethod has been deoptimized and it had a handler the handler duke@435: // address is the deopt blob unpack_with_exception entry. duke@435: // duke@435: // If no handler exists it prepares for stack-unwinding, restoring the callee-save duke@435: // registers of the frame being removed. duke@435: // duke@435: __ save_frame(0); duke@435: duke@435: __ mov(G2_thread, O0); duke@435: __ set_last_Java_frame(SP, noreg); duke@435: __ save_thread(L7_thread_cache); duke@435: duke@435: // This call can block at exit and nmethod can be deoptimized at that duke@435: // point. If the nmethod had a catch point we would jump to the duke@435: // now deoptimized catch point and fall thru the vanilla deopt duke@435: // path and lose the exception duke@435: // Sure would be simpler if this call didn't block! duke@435: __ call(CAST_FROM_FN_PTR(address, OptoRuntime::handle_exception_C), relocInfo::runtime_call_type); duke@435: __ delayed()->mov(L7_thread_cache, O0); duke@435: duke@435: // Set an oopmap for the call site. This oopmap will only be used if we duke@435: // are unwinding the stack. Hence, all locations will be dead. duke@435: // Callee-saved registers will be the same as the frame above (i.e., duke@435: // handle_exception_stub), since they were restored when we got the duke@435: // exception. duke@435: duke@435: OopMapSet *oop_maps = new OopMapSet(); duke@435: oop_maps->add_gc_map( __ offset()-start, new OopMap(framesize_in_slots, 0)); duke@435: duke@435: __ bind(L); duke@435: __ restore_thread(L7_thread_cache); duke@435: __ reset_last_Java_frame(); duke@435: duke@435: __ mov(O0, G3_scratch); // Move handler address to temp duke@435: __ restore(); duke@435: twisti@1922: // Restore SP from L7 if the exception PC is a MethodHandle call site. twisti@1922: __ lduw(Address(G2_thread, JavaThread::is_method_handle_return_offset()), O7); twisti@1922: __ tst(O7); twisti@1922: __ movcc(Assembler::notZero, false, Assembler::icc, L7_mh_SP_save, SP); twisti@1922: duke@435: // G3_scratch contains handler address duke@435: // Since this may be the deopt blob we must set O7 to look like we returned duke@435: // from the original pc that threw the exception duke@435: twisti@1162: __ ld_ptr(G2_thread, JavaThread::exception_pc_offset(), O7); duke@435: __ sub(O7, frame::pc_return_offset, O7); duke@435: duke@435: duke@435: assert(Assembler::is_simm13(in_bytes(JavaThread::exception_oop_offset())), "exception offset overflows simm13, following ld instruction cannot be in delay slot"); twisti@1162: __ ld_ptr(G2_thread, JavaThread::exception_oop_offset(), Oexception); // O0 duke@435: #ifdef ASSERT twisti@1162: __ st_ptr(G0, G2_thread, JavaThread::exception_handler_pc_offset()); twisti@1162: __ st_ptr(G0, G2_thread, JavaThread::exception_pc_offset()); duke@435: #endif duke@435: __ JMP(G3_scratch, 0); duke@435: // Clear the exception oop so GC no longer processes it as a root. twisti@1162: __ delayed()->st_ptr(G0, G2_thread, JavaThread::exception_oop_offset()); duke@435: duke@435: // ------------- duke@435: // make sure all code is generated duke@435: masm->flush(); duke@435: duke@435: _exception_blob = ExceptionBlob::create(&buffer, oop_maps, framesize_in_words); duke@435: }