runtime_sparc.cpp revision 10762:ea81fe138932
1248557Sray/* 2248557Sray * Copyright (c) 1998, 2016, Oracle and/or its affiliates. All rights reserved. 3250357Sray * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4289091Sian * 5248557Sray * This code is free software; you can redistribute it and/or modify it 6248557Sray * under the terms of the GNU General Public License version 2 only, as 7248557Sray * published by the Free Software Foundation. 8248557Sray * 9248557Sray * This code is distributed in the hope that it will be useful, but WITHOUT 10248557Sray * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11248557Sray * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12248557Sray * version 2 for more details (a copy is included in the LICENSE file that 13248557Sray * accompanied this code). 14248557Sray * 15248557Sray * You should have received a copy of the GNU General Public License version 16248557Sray * 2 along with this work; if not, write to the Free Software Foundation, 17248557Sray * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18248557Sray * 19248557Sray * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20248557Sray * or visit www.oracle.com if you need additional information or have any 21248557Sray * questions. 22248557Sray * 23248557Sray */ 24248557Sray 25248557Sray#include "precompiled.hpp" 26248557Sray#ifdef COMPILER2 27248557Sray#include "asm/macroAssembler.inline.hpp" 28248557Sray#include "classfile/systemDictionary.hpp" 29248557Sray#include "code/vmreg.hpp" 30248557Sray#include "interpreter/interpreter.hpp" 31248557Sray#include "memory/resourceArea.hpp" 32289091Sian#include "nativeInst_sparc.hpp" 33289091Sian#include "opto/runtime.hpp" 34289091Sian#include "runtime/interfaceSupport.hpp" 35289091Sian#include "runtime/sharedRuntime.hpp" 36289091Sian#include "runtime/stubRoutines.hpp" 37289091Sian#include "runtime/vframeArray.hpp" 38289091Sian#include "utilities/globalDefinitions.hpp" 39289091Sian#include "vmreg_sparc.inline.hpp" 40289091Sian#endif 41289091Sian 42289091Sian 43289091Sian#define __ masm-> 44289091Sian 45248557Sray//------------------------------ generate_exception_blob --------------------------- 46248557Sray// creates exception blob at the end 47248557Sray// Using exception blob, this code is jumped from a compiled method. 48248557Sray// (see emit_exception_handler in sparc.ad file) 49248557Sray// 50248557Sray// Given an exception pc at a call we call into the runtime for the 51248557Sray// handler in this method. This handler might merely restore state 52274641Sian// (i.e. callee save registers) unwind the frame and jump to the 53248557Sray// exception handler for the nmethod if there is no Java level handler 54248557Sray// for the nmethod. 55248557Sray// 56248557Sray// This code is entered with a jmp. 57248557Sray// 58248557Sray// Arguments: 59248557Sray// O0: exception oop 60274641Sian// O1: exception pc 61274641Sian// 62248557Sray// Results: 63248557Sray// O0: exception oop 64248557Sray// O1: exception pc in caller or ??? 65248557Sray// destination: exception handler of caller 66248557Sray// 67248557Sray// Note: the exception pc MUST be at a call (precise debug information) 68248557Sray// 69248557Srayvoid OptoRuntime::generate_exception_blob() { 70248557Sray // allocate space for code 71248557Sray ResourceMark rm; 72248557Sray int pad = VerifyThread ? 256 : 0;// Extra slop space for more verify code 73248557Sray 74248557Sray // setup code generation tools 75248557Sray // Measured 8/7/03 at 256 in 32bit debug build (no VerifyThread) 76248557Sray // Measured 8/7/03 at 528 in 32bit debug build (VerifyThread) 77248557Sray CodeBuffer buffer("exception_blob", 600+pad, 512); 78248557Sray MacroAssembler* masm = new MacroAssembler(&buffer); 79248557Sray 80248557Sray int framesize_in_bytes = __ total_frame_size_in_bytes(0); 81248557Sray int framesize_in_words = framesize_in_bytes / wordSize; 82248557Sray int framesize_in_slots = framesize_in_bytes / sizeof(jint); 83248557Sray 84248557Sray Label L; 85248557Sray 86248557Sray int start = __ offset(); 87248557Sray 88248557Sray __ verify_thread(); 89248557Sray __ st_ptr(Oexception, G2_thread, JavaThread::exception_oop_offset()); 90248557Sray __ st_ptr(Oissuing_pc, G2_thread, JavaThread::exception_pc_offset()); 91248557Sray 92248557Sray // This call does all the hard work. It checks if an exception catch 93248557Sray // exists in the method. 94248557Sray // If so, it returns the handler address. 95248557Sray // If the nmethod has been deoptimized and it had a handler the handler 96274641Sian // address is the deopt blob unpack_with_exception entry. 97274641Sian // 98274641Sian // If no handler exists it prepares for stack-unwinding, restoring the callee-save 99274641Sian // registers of the frame being removed. 100274641Sian // 101274641Sian __ save_frame(0); 102274641Sian 103274641Sian __ mov(G2_thread, O0); 104274641Sian __ set_last_Java_frame(SP, noreg); 105274641Sian __ save_thread(L7_thread_cache); 106274641Sian 107274641Sian // This call can block at exit and nmethod can be deoptimized at that 108274641Sian // point. If the nmethod had a catch point we would jump to the 109274641Sian // now deoptimized catch point and fall thru the vanilla deopt 110274641Sian // path and lose the exception 111274641Sian // Sure would be simpler if this call didn't block! 112274641Sian __ call(CAST_FROM_FN_PTR(address, OptoRuntime::handle_exception_C), relocInfo::runtime_call_type); 113274641Sian __ delayed()->mov(L7_thread_cache, O0); 114274641Sian 115274641Sian // Set an oopmap for the call site. This oopmap will only be used if we 116274641Sian // are unwinding the stack. Hence, all locations will be dead. 117274641Sian // Callee-saved registers will be the same as the frame above (i.e., 118274641Sian // handle_exception_stub), since they were restored when we got the 119274641Sian // exception. 120274641Sian 121274641Sian OopMapSet *oop_maps = new OopMapSet(); 122268977Sbr oop_maps->add_gc_map( __ offset()-start, new OopMap(framesize_in_slots, 0)); 123268977Sbr 124268977Sbr __ bind(L); 125268977Sbr __ restore_thread(L7_thread_cache); 126268977Sbr __ reset_last_Java_frame(); 127268977Sbr 128248557Sray __ mov(O0, G3_scratch); // Move handler address to temp 129248557Sray __ restore(); 130248557Sray 131248557Sray // Restore SP from L7 if the exception PC is a MethodHandle call site. 132248557Sray __ lduw(Address(G2_thread, JavaThread::is_method_handle_return_offset()), O7); 133289091Sian __ tst(O7); 134248557Sray __ movcc(Assembler::notZero, false, Assembler::icc, L7_mh_SP_save, SP); 135248557Sray 136248557Sray // G3_scratch contains handler address 137248557Sray // Since this may be the deopt blob we must set O7 to look like we returned 138248557Sray // from the original pc that threw the exception 139248557Sray 140248557Sray __ ld_ptr(G2_thread, JavaThread::exception_pc_offset(), O7); 141248557Sray __ sub(O7, frame::pc_return_offset, O7); 142248557Sray 143248557Sray 144248557Sray assert(Assembler::is_simm13(in_bytes(JavaThread::exception_oop_offset())), "exception offset overflows simm13, following ld instruction cannot be in delay slot"); 145248557Sray __ ld_ptr(G2_thread, JavaThread::exception_oop_offset(), Oexception); // O0 146248557Sray#ifdef ASSERT 147248557Sray __ st_ptr(G0, G2_thread, JavaThread::exception_handler_pc_offset()); 148248557Sray __ st_ptr(G0, G2_thread, JavaThread::exception_pc_offset()); 149248557Sray#endif 150248557Sray __ JMP(G3_scratch, 0); 151248557Sray // Clear the exception oop so GC no longer processes it as a root. 152248557Sray __ delayed()->st_ptr(G0, G2_thread, JavaThread::exception_oop_offset()); 153248557Sray 154248557Sray // ------------- 155248557Sray // make sure all code is generated 156248557Sray masm->flush(); 157248557Sray 158248557Sray _exception_blob = ExceptionBlob::create(&buffer, oop_maps, framesize_in_words); 159248557Sray} 160248557Sray