1 /* 2 * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 * 23 */ 24 25 #include "precompiled.hpp" 26 #include "asm/macroAssembler.hpp" 27 #include "interpreter/bytecodeHistogram.hpp" 28 #include "interpreter/interpreter.hpp" 29 #include "interpreter/interpreterGenerator.hpp" 30 #include "interpreter/interpreterRuntime.hpp" 31 #include "interpreter/interp_masm.hpp" 32 #include "interpreter/templateTable.hpp" 33 #include "oops/arrayOop.hpp" 34 #include "oops/methodData.hpp" 35 #include "oops/method.hpp" 36 #include "oops/oop.inline.hpp" 37 #include "prims/jvmtiExport.hpp" 38 #include "prims/jvmtiThreadState.hpp" 39 #include "prims/methodHandles.hpp" 40 #include "runtime/arguments.hpp" 41 #include "runtime/deoptimization.hpp" 42 #include "runtime/frame.inline.hpp" 43 #include "runtime/sharedRuntime.hpp" 44 #include "runtime/stubRoutines.hpp" 45 #include "runtime/synchronizer.hpp" 46 #include "runtime/timer.hpp" 47 #include "runtime/vframeArray.hpp" 48 #include "utilities/debug.hpp" 49 #ifdef COMPILER1 50 #include "c1/c1_Runtime1.hpp" 51 #endif 52 53 #define __ _masm-> 54 55 //------------------------------------------------------------------------------------------------------------------------ 56 57 address AbstractInterpreterGenerator::generate_slow_signature_handler() { 58 address entry = __ pc(); 59 // rbx,: method 60 // rcx: temporary 61 // rdi: pointer to locals 62 // rsp: end of copied parameters area 63 __ mov(rcx, rsp); 64 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::slow_signature_handler), rbx, rdi, rcx); 65 __ ret(0); 66 return entry; 67 } 68 69 70 address InterpreterGenerator::generate_math_entry(AbstractInterpreter::MethodKind kind) { 71 72 // rbx,: Method* 73 // rcx: scratrch 74 // rsi: sender sp 75 76 if (!InlineIntrinsics) return NULL; // Generate a vanilla entry 77 78 address entry_point = __ pc(); 79 80 // These don't need a safepoint check because they aren't virtually 81 // callable. We won't enter these intrinsics from compiled code. 82 // If in the future we added an intrinsic which was virtually callable 83 // we'd have to worry about how to safepoint so that this code is used. 84 85 // mathematical functions inlined by compiler 86 // (interpreter must provide identical implementation 87 // in order to avoid monotonicity bugs when switching 88 // from interpreter to compiler in the middle of some 89 // computation) 90 // 91 // stack: [ ret adr ] <-- rsp 92 // [ lo(arg) ] 93 // [ hi(arg) ] 94 // 95 96 // Note: For JDK 1.2 StrictMath doesn't exist and Math.sin/cos/sqrt are 97 // native methods. Interpreter::method_kind(...) does a check for 98 // native methods first before checking for intrinsic methods and 99 // thus will never select this entry point. Make sure it is not 100 // called accidentally since the SharedRuntime entry points will 101 // not work for JDK 1.2. 102 // 103 // We no longer need to check for JDK 1.2 since it's EOL'ed. 104 // The following check existed in pre 1.6 implementation, 105 // if (Universe::is_jdk12x_version()) { 106 // __ should_not_reach_here(); 107 // } 108 // Universe::is_jdk12x_version() always returns false since 109 // the JDK version is not yet determined when this method is called. 110 // This method is called during interpreter_init() whereas 111 // JDK version is only determined when universe2_init() is called. 112 113 // Note: For JDK 1.3 StrictMath exists and Math.sin/cos/sqrt are 114 // java methods. Interpreter::method_kind(...) will select 115 // this entry point for the corresponding methods in JDK 1.3. 116 // get argument 117 __ fld_d(Address(rsp, 1*wordSize)); 118 switch (kind) { 119 case Interpreter::java_lang_math_sin : 120 __ subptr(rsp, 2 * wordSize); 121 __ fstp_d(Address(rsp, 0)); 122 if (VM_Version::supports_sse2() && StubRoutines::dsin() != NULL) { 123 __ call(RuntimeAddress(CAST_FROM_FN_PTR(address, StubRoutines::dsin()))); 124 } else { 125 __ call(RuntimeAddress(CAST_FROM_FN_PTR(address, SharedRuntime::dsin))); 126 } 127 __ addptr(rsp, 2 * wordSize); 128 break; 129 case Interpreter::java_lang_math_cos : 130 __ subptr(rsp, 2 * wordSize); 131 __ fstp_d(Address(rsp, 0)); 132 if (VM_Version::supports_sse2() && StubRoutines::dcos() != NULL) { 133 __ call(RuntimeAddress(CAST_FROM_FN_PTR(address, StubRoutines::dcos()))); 134 } else { 135 __ call(RuntimeAddress(CAST_FROM_FN_PTR(address, SharedRuntime::dcos))); 136 } 137 __ addptr(rsp, 2 * wordSize); 138 break; 139 case Interpreter::java_lang_math_tan : 140 __ trigfunc('t'); 141 break; 142 case Interpreter::java_lang_math_sqrt: 143 __ fsqrt(); 144 break; 145 case Interpreter::java_lang_math_abs: 146 __ fabs(); 147 break; 148 case Interpreter::java_lang_math_log: 149 __ subptr(rsp, 2 * wordSize); 150 __ fstp_d(Address(rsp, 0)); 151 if (VM_Version::supports_sse2()) { 152 __ call(RuntimeAddress(CAST_FROM_FN_PTR(address, StubRoutines::dlog()))); 153 } else { 154 __ call(RuntimeAddress(CAST_FROM_FN_PTR(address, SharedRuntime::dlog))); 155 } 156 __ addptr(rsp, 2 * wordSize); 157 break; 158 case Interpreter::java_lang_math_log10: 159 __ flog10(); 160 // Store to stack to convert 80bit precision back to 64bits 161 __ push_fTOS(); 162 __ pop_fTOS(); 163 break; 164 case Interpreter::java_lang_math_pow: 165 __ fld_d(Address(rsp, 3*wordSize)); // second argument 166 __ pow_with_fallback(0); 167 // Store to stack to convert 80bit precision back to 64bits 168 __ push_fTOS(); 169 __ pop_fTOS(); 170 break; 171 case Interpreter::java_lang_math_exp: 172 __ subptr(rsp, 2*wordSize); 173 __ fstp_d(Address(rsp, 0)); 174 if (VM_Version::supports_sse2()) { 175 __ call(RuntimeAddress(CAST_FROM_FN_PTR(address, StubRoutines::dexp()))); 176 } else { 177 __ call(RuntimeAddress(CAST_FROM_FN_PTR(address, SharedRuntime::dexp))); 178 } 179 __ addptr(rsp, 2*wordSize); 180 break; 181 default : 182 ShouldNotReachHere(); 183 } 184 185 // return double result in xmm0 for interpreter and compilers. 186 if (UseSSE >= 2) { 187 __ subptr(rsp, 2*wordSize); 188 __ fstp_d(Address(rsp, 0)); 189 __ movdbl(xmm0, Address(rsp, 0)); 190 __ addptr(rsp, 2*wordSize); 191 } 192 193 // done, result in FPU ST(0) or XMM0 194 __ pop(rdi); // get return address 195 __ mov(rsp, rsi); // set sp to sender sp 196 __ jmp(rdi); 197 198 return entry_point; 199 } 200 201 202 void Deoptimization::unwind_callee_save_values(frame* f, vframeArray* vframe_array) { 203 204 // This code is sort of the equivalent of C2IAdapter::setup_stack_frame back in 205 // the days we had adapter frames. When we deoptimize a situation where a 206 // compiled caller calls a compiled caller will have registers it expects 207 // to survive the call to the callee. If we deoptimize the callee the only 208 // way we can restore these registers is to have the oldest interpreter 209 // frame that we create restore these values. That is what this routine 210 // will accomplish. 211 212 // At the moment we have modified c2 to not have any callee save registers 213 // so this problem does not exist and this routine is just a place holder. 214 215 assert(f->is_interpreted_frame(), "must be interpreted"); 216 }