src/cpu/ppc/vm/runtime_ppc.cpp

Wed, 15 Apr 2020 11:49:55 +0800

author
aoqi
date
Wed, 15 Apr 2020 11:49:55 +0800
changeset 9852
70aa912cebe5
parent 6876
710a3c8b516e
permissions
-rw-r--r--

Merge

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * Copyright 2012, 2013 SAP AG. All rights reserved.
aoqi@0 4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 5 *
aoqi@0 6 * This code is free software; you can redistribute it and/or modify it
aoqi@0 7 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 8 * published by the Free Software Foundation.
aoqi@0 9 *
aoqi@0 10 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 13 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 14 * accompanied this code).
aoqi@0 15 *
aoqi@0 16 * You should have received a copy of the GNU General Public License version
aoqi@0 17 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 19 *
aoqi@0 20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 21 * or visit www.oracle.com if you need additional information or have any
aoqi@0 22 * questions.
aoqi@0 23 *
aoqi@0 24 */
aoqi@0 25
aoqi@0 26 #include "precompiled.hpp"
aoqi@0 27 #ifdef COMPILER2
aoqi@0 28 #include "asm/assembler.inline.hpp"
aoqi@0 29 #include "asm/macroAssembler.inline.hpp"
aoqi@0 30 #include "classfile/systemDictionary.hpp"
aoqi@0 31 #include "code/vmreg.hpp"
aoqi@0 32 #include "interpreter/interpreter.hpp"
aoqi@0 33 #include "nativeInst_ppc.hpp"
aoqi@0 34 #include "opto/runtime.hpp"
aoqi@0 35 #include "runtime/interfaceSupport.hpp"
aoqi@0 36 #include "runtime/sharedRuntime.hpp"
aoqi@0 37 #include "runtime/stubRoutines.hpp"
aoqi@0 38 #include "runtime/vframeArray.hpp"
aoqi@0 39 #include "utilities/globalDefinitions.hpp"
aoqi@0 40 #include "vmreg_ppc.inline.hpp"
aoqi@0 41 #endif
aoqi@0 42
aoqi@0 43 #define __ masm->
aoqi@0 44
aoqi@0 45
aoqi@0 46 #ifdef COMPILER2
aoqi@0 47
aoqi@0 48 // SP adjustment (must use unextended SP) for method handle call sites
aoqi@0 49 // during exception handling.
aoqi@0 50 static intptr_t adjust_SP_for_methodhandle_callsite(JavaThread *thread) {
aoqi@0 51 RegisterMap map(thread, false);
aoqi@0 52 // The frame constructor will do the correction for us (see frame::adjust_unextended_SP).
aoqi@0 53 frame mh_caller_frame = thread->last_frame().sender(&map);
aoqi@0 54 assert(mh_caller_frame.is_compiled_frame(), "Only may reach here for compiled MH call sites");
aoqi@0 55 return (intptr_t) mh_caller_frame.unextended_sp();
aoqi@0 56 }
aoqi@0 57
aoqi@0 58 //------------------------------generate_exception_blob---------------------------
aoqi@0 59 // Creates exception blob at the end.
aoqi@0 60 // Using exception blob, this code is jumped from a compiled method.
aoqi@0 61 //
aoqi@0 62 // Given an exception pc at a call we call into the runtime for the
aoqi@0 63 // handler in this method. This handler might merely restore state
aoqi@0 64 // (i.e. callee save registers) unwind the frame and jump to the
aoqi@0 65 // exception handler for the nmethod if there is no Java level handler
aoqi@0 66 // for the nmethod.
aoqi@0 67 //
aoqi@0 68 // This code is entered with a jmp.
aoqi@0 69 //
aoqi@0 70 // Arguments:
aoqi@0 71 // R3_ARG1: exception oop
aoqi@0 72 // R4_ARG2: exception pc
aoqi@0 73 //
aoqi@0 74 // Results:
aoqi@0 75 // R3_ARG1: exception oop
aoqi@0 76 // R4_ARG2: exception pc in caller
aoqi@0 77 // destination: exception handler of caller
aoqi@0 78 //
aoqi@0 79 // Note: the exception pc MUST be at a call (precise debug information)
aoqi@0 80 //
aoqi@0 81 void OptoRuntime::generate_exception_blob() {
aoqi@0 82 // Allocate space for the code.
aoqi@0 83 ResourceMark rm;
aoqi@0 84 // Setup code generation tools.
aoqi@0 85 CodeBuffer buffer("exception_blob", 2048, 1024);
aoqi@0 86 InterpreterMacroAssembler* masm = new InterpreterMacroAssembler(&buffer);
aoqi@0 87
aoqi@0 88 address start = __ pc();
aoqi@0 89
aoqi@0 90 int frame_size_in_bytes = frame::abi_reg_args_size;
aoqi@0 91 OopMap* map = new OopMap(frame_size_in_bytes / sizeof(jint), 0);
aoqi@0 92
aoqi@0 93 // Exception pc is 'return address' for stack walker.
aoqi@0 94 __ std(R4_ARG2/*exception pc*/, _abi(lr), R1_SP);
aoqi@0 95
aoqi@0 96 // Store the exception in the Thread object.
aoqi@0 97 __ std(R3_ARG1/*exception oop*/, in_bytes(JavaThread::exception_oop_offset()), R16_thread);
aoqi@0 98 __ std(R4_ARG2/*exception pc*/, in_bytes(JavaThread::exception_pc_offset()), R16_thread);
aoqi@0 99
aoqi@0 100 // Save callee-saved registers.
aoqi@0 101 // Push a C frame for the exception blob. It is needed for the C call later on.
aoqi@0 102 __ push_frame_reg_args(0, R11_scratch1);
aoqi@0 103
aoqi@0 104 // This call does all the hard work. It checks if an exception handler
aoqi@0 105 // exists in the method.
aoqi@0 106 // If so, it returns the handler address.
aoqi@0 107 // If not, it prepares for stack-unwinding, restoring the callee-save
aoqi@0 108 // registers of the frame being removed.
aoqi@0 109 __ set_last_Java_frame(/*sp=*/R1_SP, noreg);
aoqi@0 110
aoqi@0 111 __ mr(R3_ARG1, R16_thread);
aoqi@0 112 #if defined(ABI_ELFv2)
aoqi@0 113 __ call_c((address) OptoRuntime::handle_exception_C, relocInfo::none);
aoqi@0 114 #else
aoqi@0 115 __ call_c(CAST_FROM_FN_PTR(FunctionDescriptor*, OptoRuntime::handle_exception_C),
aoqi@0 116 relocInfo::none);
aoqi@0 117 #endif
aoqi@0 118 address calls_return_pc = __ last_calls_return_pc();
aoqi@0 119 # ifdef ASSERT
aoqi@0 120 __ cmpdi(CCR0, R3_RET, 0);
aoqi@0 121 __ asm_assert_ne("handle_exception_C must not return NULL", 0x601);
aoqi@0 122 # endif
aoqi@0 123
aoqi@0 124 // Set an oopmap for the call site. This oopmap will only be used if we
aoqi@0 125 // are unwinding the stack. Hence, all locations will be dead.
aoqi@0 126 // Callee-saved registers will be the same as the frame above (i.e.,
aoqi@0 127 // handle_exception_stub), since they were restored when we got the
aoqi@0 128 // exception.
aoqi@0 129 OopMapSet* oop_maps = new OopMapSet();
aoqi@0 130 oop_maps->add_gc_map(calls_return_pc - start, map);
aoqi@0 131
aoqi@0 132 // Get unextended_sp for method handle call sites.
aoqi@0 133 Label mh_callsite, mh_done; // Use a 2nd c call if it's a method handle call site.
aoqi@0 134 __ lwa(R4_ARG2, in_bytes(JavaThread::is_method_handle_return_offset()), R16_thread);
aoqi@0 135 __ cmpwi(CCR0, R4_ARG2, 0);
aoqi@0 136 __ bne(CCR0, mh_callsite);
aoqi@0 137
aoqi@0 138 __ mtctr(R3_RET); // Move address of exception handler to SR_CTR.
aoqi@0 139 __ reset_last_Java_frame();
aoqi@0 140 __ pop_frame();
aoqi@0 141
aoqi@0 142 __ bind(mh_done);
aoqi@0 143 // We have a handler in register SR_CTR (could be deopt blob).
aoqi@0 144
aoqi@0 145 // Get the exception oop.
aoqi@0 146 __ ld(R3_ARG1, in_bytes(JavaThread::exception_oop_offset()), R16_thread);
aoqi@0 147
aoqi@0 148 // Get the exception pc in case we are deoptimized.
aoqi@0 149 __ ld(R4_ARG2, in_bytes(JavaThread::exception_pc_offset()), R16_thread);
aoqi@0 150
aoqi@0 151 // Reset thread values.
aoqi@0 152 __ li(R0, 0);
aoqi@0 153 #ifdef ASSERT
aoqi@0 154 __ std(R0, in_bytes(JavaThread::exception_handler_pc_offset()), R16_thread);
aoqi@0 155 __ std(R0, in_bytes(JavaThread::exception_pc_offset()), R16_thread);
aoqi@0 156 #endif
aoqi@0 157 // Clear the exception oop so GC no longer processes it as a root.
aoqi@0 158 __ std(R0, in_bytes(JavaThread::exception_oop_offset()), R16_thread);
aoqi@0 159
aoqi@0 160 // Move exception pc into SR_LR.
aoqi@0 161 __ mtlr(R4_ARG2);
aoqi@0 162 __ bctr();
aoqi@0 163
aoqi@0 164
aoqi@0 165 // Same as above, but also set sp to unextended_sp.
aoqi@0 166 __ bind(mh_callsite);
aoqi@0 167 __ mr(R31, R3_RET); // Save branch address.
aoqi@0 168 __ mr(R3_ARG1, R16_thread);
aoqi@0 169 #if defined(ABI_ELFv2)
aoqi@0 170 __ call_c((address) adjust_SP_for_methodhandle_callsite, relocInfo::none);
aoqi@0 171 #else
aoqi@0 172 __ call_c(CAST_FROM_FN_PTR(FunctionDescriptor*, adjust_SP_for_methodhandle_callsite), relocInfo::none);
aoqi@0 173 #endif
aoqi@0 174 // Returns unextended_sp in R3_RET.
aoqi@0 175
aoqi@0 176 __ mtctr(R31); // Move address of exception handler to SR_CTR.
aoqi@0 177 __ reset_last_Java_frame();
aoqi@0 178
aoqi@0 179 __ mr(R1_SP, R3_RET); // Set sp to unextended_sp.
aoqi@0 180 __ b(mh_done);
aoqi@0 181
aoqi@0 182
aoqi@0 183 // Make sure all code is generated.
aoqi@0 184 masm->flush();
aoqi@0 185
aoqi@0 186 // Set exception blob.
aoqi@0 187 _exception_blob = ExceptionBlob::create(&buffer, oop_maps,
aoqi@0 188 frame_size_in_bytes/wordSize);
aoqi@0 189 }
aoqi@0 190
aoqi@0 191 #endif // COMPILER2

mercurial