1 /* 2 * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved. 3 * Copyright (c) 2014, Red Hat Inc. All rights reserved. 4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 5 * 6 * This code is free software; you can redistribute it and/or modify it 7 * under the terms of the GNU General Public License version 2 only, as 8 * published by the Free Software Foundation. 9 * 10 * This code is distributed in the hope that it will be useful, but WITHOUT 11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13 * version 2 for more details (a copy is included in the LICENSE file that 14 * accompanied this code). 15 * 16 * You should have received a copy of the GNU General Public License version 17 * 2 along with this work; if not, write to the Free Software Foundation, 18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 19 * 20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 21 * or visit www.oracle.com if you need additional information or have any 22 * questions. 23 * 24 */ 25 26 #include "precompiled.hpp" 27 #include "asm/macroAssembler.hpp" 28 #include "interpreter/bytecodeHistogram.hpp" 29 #include "interpreter/interpreter.hpp" 30 #include "interpreter/interpreterGenerator.hpp" 31 #include "interpreter/interpreterRuntime.hpp" 32 #include "interpreter/interp_masm.hpp" 33 #include "interpreter/templateTable.hpp" 34 #include "oops/arrayOop.hpp" 35 #include "oops/methodData.hpp" 36 #include "oops/method.hpp" 37 #include "oops/oop.inline.hpp" 38 #include "prims/jvmtiExport.hpp" 39 #include "prims/jvmtiThreadState.hpp" 40 #include "prims/methodHandles.hpp" 41 #include "runtime/arguments.hpp" 42 #include "runtime/deoptimization.hpp" 43 #include "runtime/frame.inline.hpp" 44 #include "runtime/sharedRuntime.hpp" 45 #include "runtime/stubRoutines.hpp" 46 #include "runtime/synchronizer.hpp" 47 #include "runtime/timer.hpp" 48 #include "runtime/vframeArray.hpp" 49 #include "utilities/debug.hpp" 50 #ifdef COMPILER1 51 #include "c1/c1_Runtime1.hpp" 52 #endif 53 54 #define __ _masm-> 55 56 57 address AbstractInterpreterGenerator::generate_slow_signature_handler() { 58 address entry = __ pc(); 59 60 __ andr(esp, esp, -16); 61 __ mov(c_rarg3, esp); 62 // rmethod 63 // rlocals 64 // c_rarg3: first stack arg - wordSize 65 66 // adjust sp 67 __ sub(sp, c_rarg3, 18 * wordSize); 68 __ str(lr, Address(__ pre(sp, -2 * wordSize))); 69 __ call_VM(noreg, 70 CAST_FROM_FN_PTR(address, 71 InterpreterRuntime::slow_signature_handler), 72 rmethod, rlocals, c_rarg3); 73 74 // r0: result handler 75 76 // Stack layout: 77 // rsp: return address <- sp 78 // 1 garbage 79 // 8 integer args (if static first is unused) 80 // 1 float/double identifiers 81 // 8 double args 82 // stack args <- esp 83 // garbage 84 // expression stack bottom 85 // bcp (NULL) 86 // ... 87 88 // Restore LR 89 __ ldr(lr, Address(__ post(sp, 2 * wordSize))); 90 91 // Do FP first so we can use c_rarg3 as temp 92 __ ldrw(c_rarg3, Address(sp, 9 * wordSize)); // float/double identifiers 93 94 for (int i = 0; i < Argument::n_float_register_parameters_c; i++) { 95 const FloatRegister r = as_FloatRegister(i); 96 97 Label d, done; 98 99 __ tbnz(c_rarg3, i, d); 100 __ ldrs(r, Address(sp, (10 + i) * wordSize)); 101 __ b(done); 102 __ bind(d); 103 __ ldrd(r, Address(sp, (10 + i) * wordSize)); 104 __ bind(done); 105 } 106 107 // c_rarg0 contains the result from the call of 108 // InterpreterRuntime::slow_signature_handler so we don't touch it 109 // here. It will be loaded with the JNIEnv* later. 110 __ ldr(c_rarg1, Address(sp, 1 * wordSize)); 111 for (int i = c_rarg2->encoding(); i <= c_rarg7->encoding(); i += 2) { 112 Register rm = as_Register(i), rn = as_Register(i+1); 113 __ ldp(rm, rn, Address(sp, i * wordSize)); 114 } 115 116 __ add(sp, sp, 18 * wordSize); 117 __ ret(lr); 118 119 return entry; 120 } 121 122 123 // 124 // Various method entries 125 // 126 127 address InterpreterGenerator::generate_math_entry(AbstractInterpreter::MethodKind kind) { 128 // rmethod: Method* 129 // r13: sender sp 130 // esp: args 131 132 if (!InlineIntrinsics) return NULL; // Generate a vanilla entry 133 134 // These don't need a safepoint check because they aren't virtually 135 // callable. We won't enter these intrinsics from compiled code. 136 // If in the future we added an intrinsic which was virtually callable 137 // we'd have to worry about how to safepoint so that this code is used. 138 139 // mathematical functions inlined by compiler 140 // (interpreter must provide identical implementation 141 // in order to avoid monotonicity bugs when switching 142 // from interpreter to compiler in the middle of some 143 // computation) 144 // 145 // stack: 146 // [ arg ] <-- esp 147 // [ arg ] 148 // retaddr in lr 149 150 address entry_point = NULL; 151 Register continuation = lr; 152 switch (kind) { 153 case Interpreter::java_lang_math_abs: 154 entry_point = __ pc(); 155 __ ldrd(v0, Address(esp)); 156 __ fabsd(v0, v0); 157 __ mov(sp, r13); // Restore caller's SP 158 break; 159 case Interpreter::java_lang_math_sqrt: 160 entry_point = __ pc(); 161 __ ldrd(v0, Address(esp)); 162 __ fsqrtd(v0, v0); 163 __ mov(sp, r13); 164 break; 165 case Interpreter::java_lang_math_sin : 166 case Interpreter::java_lang_math_cos : 167 case Interpreter::java_lang_math_tan : 168 case Interpreter::java_lang_math_log : 169 case Interpreter::java_lang_math_log10 : 170 case Interpreter::java_lang_math_exp : 171 entry_point = __ pc(); 172 __ ldrd(v0, Address(esp)); 173 __ mov(sp, r13); 174 __ mov(r19, lr); 175 continuation = r19; // The first callee-saved register 176 generate_transcendental_entry(kind, 1); 177 break; 178 case Interpreter::java_lang_math_pow : 179 entry_point = __ pc(); 180 __ mov(r19, lr); 181 continuation = r19; 182 __ ldrd(v0, Address(esp, 2 * Interpreter::stackElementSize)); 183 __ ldrd(v1, Address(esp)); 184 __ mov(sp, r13); 185 generate_transcendental_entry(kind, 2); 186 break; 187 default: 188 ; 189 } 190 if (entry_point) { 191 __ br(continuation); 192 } 193 194 return entry_point; 195 } 196 197 // double trigonometrics and transcendentals 198 // static jdouble dsin(jdouble x); 199 // static jdouble dcos(jdouble x); 200 // static jdouble dtan(jdouble x); 201 // static jdouble dlog(jdouble x); 202 // static jdouble dlog10(jdouble x); 203 // static jdouble dexp(jdouble x); 204 // static jdouble dpow(jdouble x, jdouble y); 205 206 void InterpreterGenerator::generate_transcendental_entry(AbstractInterpreter::MethodKind kind, int fpargs) { 207 address fn; 208 switch (kind) { 209 case Interpreter::java_lang_math_sin : 210 fn = CAST_FROM_FN_PTR(address, SharedRuntime::dsin); 211 break; 212 case Interpreter::java_lang_math_cos : 213 fn = CAST_FROM_FN_PTR(address, SharedRuntime::dcos); 214 break; 215 case Interpreter::java_lang_math_tan : 216 fn = CAST_FROM_FN_PTR(address, SharedRuntime::dtan); 217 break; 218 case Interpreter::java_lang_math_log : 219 fn = CAST_FROM_FN_PTR(address, SharedRuntime::dlog); 220 break; 221 case Interpreter::java_lang_math_log10 : 222 fn = CAST_FROM_FN_PTR(address, SharedRuntime::dlog10); 223 break; 224 case Interpreter::java_lang_math_exp : 225 fn = CAST_FROM_FN_PTR(address, SharedRuntime::dexp); 226 break; 227 case Interpreter::java_lang_math_pow : 228 fpargs = 2; 229 fn = CAST_FROM_FN_PTR(address, SharedRuntime::dpow); 230 break; 231 default: 232 ShouldNotReachHere(); 233 } 234 const int gpargs = 0, rtype = 3; 235 __ mov(rscratch1, fn); 236 __ blrt(rscratch1, gpargs, fpargs, rtype); 237 } 238 239 // Abstract method entry 240 // Attempt to execute abstract method. Throw exception 241 address InterpreterGenerator::generate_abstract_entry(void) { 242 // rmethod: Method* 243 // r13: sender SP 244 245 address entry_point = __ pc(); 246 247 // abstract method entry 248 249 // pop return address, reset last_sp to NULL 250 __ empty_expression_stack(); 251 __ restore_bcp(); // bcp must be correct for exception handler (was destroyed) 252 __ restore_locals(); // make sure locals pointer is correct as well (was destroyed) 253 254 // throw exception 255 __ call_VM(noreg, CAST_FROM_FN_PTR(address, 256 InterpreterRuntime::throw_AbstractMethodError)); 257 // the call_VM checks for exception, so we should never return here. 258 __ should_not_reach_here(); 259 260 return entry_point; 261 } 262 263 264 void Deoptimization::unwind_callee_save_values(frame* f, vframeArray* vframe_array) { 265 266 // This code is sort of the equivalent of C2IAdapter::setup_stack_frame back in 267 // the days we had adapter frames. When we deoptimize a situation where a 268 // compiled caller calls a compiled caller will have registers it expects 269 // to survive the call to the callee. If we deoptimize the callee the only 270 // way we can restore these registers is to have the oldest interpreter 271 // frame that we create restore these values. That is what this routine 272 // will accomplish. 273 274 // At the moment we have modified c2 to not have any callee save registers 275 // so this problem does not exist and this routine is just a place holder. 276 277 assert(f->is_interpreted_frame(), "must be interpreted"); 278 }