1 /* 2 * Copyright (c) 1997, 2015, 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/interpreterRuntime.hpp" 30 #include "interpreter/interp_masm.hpp" 31 #include "interpreter/templateInterpreterGenerator.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/frame.inline.hpp" 42 #include "runtime/sharedRuntime.hpp" 43 #include "runtime/stubRoutines.hpp" 44 #include "runtime/synchronizer.hpp" 45 #include "runtime/timer.hpp" 46 #include "runtime/vframeArray.hpp" 47 #include "utilities/debug.hpp" 48 #ifdef COMPILER1 49 #include "c1/c1_Runtime1.hpp" 50 #endif 51 52 #define __ _masm-> 53 54 //------------------------------------------------------------------------------------------------------------------------ 55 56 address AbstractInterpreterGenerator::generate_slow_signature_handler() { 57 address entry = __ pc(); 58 // rbx,: method 59 // rcx: temporary 60 // rdi: pointer to locals 61 // rsp: end of copied parameters area 62 __ mov(rcx, rsp); 63 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::slow_signature_handler), rbx, rdi, rcx); 64 __ ret(0); 65 return entry; 66 } 67 68 69 address TemplateInterpreterGenerator::generate_math_entry(AbstractInterpreter::MethodKind kind) { 70 71 // rbx,: Method* 72 // rcx: scratrch 73 // rsi: sender sp 74 75 if (!InlineIntrinsics) return NULL; // Generate a vanilla entry 76 77 address entry_point = __ pc(); 78 79 // These don't need a safepoint check because they aren't virtually 80 // callable. We won't enter these intrinsics from compiled code. 81 // If in the future we added an intrinsic which was virtually callable 82 // we'd have to worry about how to safepoint so that this code is used. 83 84 // mathematical functions inlined by compiler 85 // (interpreter must provide identical implementation 86 // in order to avoid monotonicity bugs when switching 87 // from interpreter to compiler in the middle of some 88 // computation) 89 // 90 // stack: [ ret adr ] <-- rsp 91 // [ lo(arg) ] 92 // [ hi(arg) ] 93 // 94 95 // Note: For JDK 1.2 StrictMath doesn't exist and Math.sin/cos/sqrt are 96 // native methods. Interpreter::method_kind(...) does a check for 97 // native methods first before checking for intrinsic methods and 98 // thus will never select this entry point. Make sure it is not 99 // called accidentally since the SharedRuntime entry points will 100 // not work for JDK 1.2. 101 // 102 // We no longer need to check for JDK 1.2 since it's EOL'ed. 103 // The following check existed in pre 1.6 implementation, 104 // if (Universe::is_jdk12x_version()) { 105 // __ should_not_reach_here(); 106 // } 107 // Universe::is_jdk12x_version() always returns false since 108 // the JDK version is not yet determined when this method is called. 109 // This method is called during interpreter_init() whereas 110 // JDK version is only determined when universe2_init() is called. 111 112 // Note: For JDK 1.3 StrictMath exists and Math.sin/cos/sqrt are 113 // java methods. Interpreter::method_kind(...) will select 114 // this entry point for the corresponding methods in JDK 1.3. 115 // get argument 116 __ fld_d(Address(rsp, 1*wordSize)); 117 switch (kind) { 118 case Interpreter::java_lang_math_sin : 119 __ trigfunc('s'); 120 break; 121 case Interpreter::java_lang_math_cos : 122 __ trigfunc('c'); 123 break; 124 case Interpreter::java_lang_math_tan : 125 __ trigfunc('t'); 126 break; 127 case Interpreter::java_lang_math_sqrt: 128 __ fsqrt(); 129 break; 130 case Interpreter::java_lang_math_abs: 131 __ fabs(); 132 break; 133 case Interpreter::java_lang_math_log: 134 __ subptr(rsp, 2 * wordSize); 135 __ fstp_d(Address(rsp, 0)); 136 if (VM_Version::supports_sse2()) { 137 __ call(RuntimeAddress(CAST_FROM_FN_PTR(address, StubRoutines::dlog()))); 138 } 139 else { 140 __ call(RuntimeAddress(CAST_FROM_FN_PTR(address, SharedRuntime::dlog))); 141 } 142 __ addptr(rsp, 2 * wordSize); 143 break; 144 case Interpreter::java_lang_math_log10: 145 __ flog10(); 146 // Store to stack to convert 80bit precision back to 64bits 147 __ push_fTOS(); 148 __ pop_fTOS(); 149 break; 150 case Interpreter::java_lang_math_pow: 151 __ fld_d(Address(rsp, 3*wordSize)); // second argument 152 __ pow_with_fallback(0); 153 // Store to stack to convert 80bit precision back to 64bits 154 __ push_fTOS(); 155 __ pop_fTOS(); 156 break; 157 case Interpreter::java_lang_math_exp: 158 __ subptr(rsp, 2*wordSize); 159 __ fstp_d(Address(rsp, 0)); 160 if (VM_Version::supports_sse2()) { 161 __ call(RuntimeAddress(CAST_FROM_FN_PTR(address, StubRoutines::dexp()))); 162 } else { 163 __ call(RuntimeAddress(CAST_FROM_FN_PTR(address, SharedRuntime::dexp))); 164 } 165 __ addptr(rsp, 2*wordSize); 166 break; 167 default : 168 ShouldNotReachHere(); 169 } 170 171 // return double result in xmm0 for interpreter and compilers. 172 if (UseSSE >= 2) { 173 __ subptr(rsp, 2*wordSize); 174 __ fstp_d(Address(rsp, 0)); 175 __ movdbl(xmm0, Address(rsp, 0)); 176 __ addptr(rsp, 2*wordSize); 177 } 178 179 // done, result in FPU ST(0) or XMM0 180 __ pop(rdi); // get return address 181 __ mov(rsp, rsi); // set sp to sender sp 182 __ jmp(rdi); 183 184 return entry_point; 185 }