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/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/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 InterpreterGenerator::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 __ subptr(rsp, 2 * wordSize); 120 __ fstp_d(Address(rsp, 0)); 121 if (VM_Version::supports_sse2() && StubRoutines::dsin() != NULL) { 122 __ call(RuntimeAddress(CAST_FROM_FN_PTR(address, StubRoutines::dsin()))); 123 } else { 124 __ call(RuntimeAddress(CAST_FROM_FN_PTR(address, SharedRuntime::dsin))); 125 } 126 __ addptr(rsp, 2 * wordSize); 127 break; 128 case Interpreter::java_lang_math_cos : 129 __ subptr(rsp, 2 * wordSize); 130 __ fstp_d(Address(rsp, 0)); 131 if (VM_Version::supports_sse2() && StubRoutines::dcos() != NULL) { 132 __ call(RuntimeAddress(CAST_FROM_FN_PTR(address, StubRoutines::dcos()))); 133 } else { 134 __ call(RuntimeAddress(CAST_FROM_FN_PTR(address, SharedRuntime::dcos))); 135 } 136 __ addptr(rsp, 2 * wordSize); 137 break; 138 case Interpreter::java_lang_math_tan : 139 __ trigfunc('t'); 140 break; 141 case Interpreter::java_lang_math_sqrt: 142 __ fsqrt(); 143 break; 144 case Interpreter::java_lang_math_abs: 145 __ fabs(); 146 break; 147 case Interpreter::java_lang_math_log: 148 __ subptr(rsp, 2 * wordSize); 149 __ fstp_d(Address(rsp, 0)); 150 if (VM_Version::supports_sse2()) { 151 __ call(RuntimeAddress(CAST_FROM_FN_PTR(address, StubRoutines::dlog()))); 152 } else { 153 __ call(RuntimeAddress(CAST_FROM_FN_PTR(address, SharedRuntime::dlog))); 154 } 155 __ addptr(rsp, 2 * wordSize); 156 break; 157 case Interpreter::java_lang_math_log10: 158 __ flog10(); 159 // Store to stack to convert 80bit precision back to 64bits 160 __ push_fTOS(); 161 __ pop_fTOS(); 162 break; 163 case Interpreter::java_lang_math_pow: 164 __ fld_d(Address(rsp, 3*wordSize)); // second argument 165 __ subptr(rsp, 4 * wordSize); 166 __ fstp_d(Address(rsp, 0)); 167 __ fstp_d(Address(rsp, 2 * wordSize)); 168 if (VM_Version::supports_sse2()) { 169 __ call(RuntimeAddress(CAST_FROM_FN_PTR(address, StubRoutines::dpow()))); 170 } else { 171 __ call(RuntimeAddress(CAST_FROM_FN_PTR(address, SharedRuntime::dpow))); 172 } 173 __ addptr(rsp, 4 * wordSize); 174 break; 175 case Interpreter::java_lang_math_exp: 176 __ subptr(rsp, 2*wordSize); 177 __ fstp_d(Address(rsp, 0)); 178 if (VM_Version::supports_sse2()) { 179 __ call(RuntimeAddress(CAST_FROM_FN_PTR(address, StubRoutines::dexp()))); 180 } else { 181 __ call(RuntimeAddress(CAST_FROM_FN_PTR(address, SharedRuntime::dexp))); 182 } 183 __ addptr(rsp, 2*wordSize); 184 break; 185 default : 186 ShouldNotReachHere(); 187 } 188 189 // return double result in xmm0 for interpreter and compilers. 190 if (UseSSE >= 2) { 191 __ subptr(rsp, 2*wordSize); 192 __ fstp_d(Address(rsp, 0)); 193 __ movdbl(xmm0, Address(rsp, 0)); 194 __ addptr(rsp, 2*wordSize); 195 } 196 197 // done, result in FPU ST(0) or XMM0 198 __ pop(rdi); // get return address 199 __ mov(rsp, rsi); // set sp to sender sp 200 __ jmp(rdi); 201 202 return entry_point; 203 }