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