1 #ifdef USE_PRAGMA_IDENT_SRC 2 #pragma ident "@(#)interpreter_x86_32.cpp 1.378 07/09/17 09:26:02 JVM" 3 #endif 4 /* 5 * Copyright 1997-2007 Sun Microsystems, Inc. All Rights Reserved. 6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 7 * 8 * This code is free software; you can redistribute it and/or modify it 9 * under the terms of the GNU General Public License version 2 only, as 10 * published by the Free Software Foundation. 11 * 12 * This code is distributed in the hope that it will be useful, but WITHOUT 13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 15 * version 2 for more details (a copy is included in the LICENSE file that 16 * accompanied this code). 17 * 18 * You should have received a copy of the GNU General Public License version 19 * 2 along with this work; if not, write to the Free Software Foundation, 20 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 21 * 22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 23 * CA 95054 USA or visit www.sun.com if you need additional information or 24 * have any questions. 25 * 26 */ 27 28 #include "incls/_precompiled.incl" 29 #include "incls/_interpreter_x86_32.cpp.incl" 30 31 #define __ _masm-> 32 33 // Initialize the sentinel used to distinguish an interpreter return address. 34 const int Interpreter::return_sentinel = 0xfeedbeed; 35 36 //------------------------------------------------------------------------------------------------------------------------ 37 38 address AbstractInterpreterGenerator::generate_slow_signature_handler() { 39 address entry = __ pc(); 40 // rbx,: method 41 // rcx: temporary 42 // rdi: pointer to locals 43 // rsp: end of copied parameters area 44 __ movl(rcx, rsp); 45 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::slow_signature_handler), rbx, rdi, rcx); 46 __ ret(0); 47 return entry; 48 } 49 50 51 // 52 // Various method entries (that c++ and asm interpreter agree upon) 53 //------------------------------------------------------------------------------------------------------------------------ 54 // 55 // 56 57 // Empty method, generate a very fast return. 58 59 address InterpreterGenerator::generate_empty_entry(void) { 60 61 // rbx,: methodOop 62 // rcx: receiver (unused) 63 // rsi: previous interpreter state (C++ interpreter) must preserve 64 // rsi: sender sp must set sp to this value on return 65 66 if (!UseFastEmptyMethods) return NULL; 67 68 address entry_point = __ pc(); 69 70 // If we need a safepoint check, generate full interpreter entry. 71 Label slow_path; 72 ExternalAddress state(SafepointSynchronize::address_of_state()); 73 __ cmp32(ExternalAddress(SafepointSynchronize::address_of_state()), 74 SafepointSynchronize::_not_synchronized); 75 __ jcc(Assembler::notEqual, slow_path); 76 77 // do nothing for empty methods (do not even increment invocation counter) 78 // Code: _return 79 // _return 80 // return w/o popping parameters 81 __ popl(rax); 82 __ movl(rsp, rsi); 83 __ jmp(rax); 84 85 __ bind(slow_path); 86 (void) generate_normal_entry(false); 87 return entry_point; 88 } 89 90 address InterpreterGenerator::generate_math_entry(AbstractInterpreter::MethodKind kind) { 91 92 // rbx,: methodOop 93 // rcx: scratrch 94 // rsi: sender sp 95 96 if (!InlineIntrinsics) return NULL; // Generate a vanilla entry 97 98 address entry_point = __ pc(); 99 100 // These don't need a safepoint check because they aren't virtually 101 // callable. We won't enter these intrinsics from compiled code. 102 // If in the future we added an intrinsic which was virtually callable 103 // we'd have to worry about how to safepoint so that this code is used. 104 105 // mathematical functions inlined by compiler 106 // (interpreter must provide identical implementation 107 // in order to avoid monotonicity bugs when switching 108 // from interpreter to compiler in the middle of some 109 // computation) 110 // 111 // stack: [ ret adr ] <-- rsp 112 // [ lo(arg) ] 113 // [ hi(arg) ] 114 // 115 116 // Note: For JDK 1.2 StrictMath doesn't exist and Math.sin/cos/sqrt are 117 // native methods. Interpreter::method_kind(...) does a check for 118 // native methods first before checking for intrinsic methods and 119 // thus will never select this entry point. Make sure it is not 120 // called accidentally since the SharedRuntime entry points will 121 // not work for JDK 1.2. 122 // 123 // We no longer need to check for JDK 1.2 since it's EOL'ed. 124 // The following check existed in pre 1.6 implementation, 125 // if (Universe::is_jdk12x_version()) { 126 // __ should_not_reach_here(); 127 // } 128 // Universe::is_jdk12x_version() always returns false since 129 // the JDK version is not yet determined when this method is called. 130 // This method is called during interpreter_init() whereas 131 // JDK version is only determined when universe2_init() is called. 132 133 // Note: For JDK 1.3 StrictMath exists and Math.sin/cos/sqrt are 134 // java methods. Interpreter::method_kind(...) will select 135 // this entry point for the corresponding methods in JDK 1.3. 136 // get argument 137 if (TaggedStackInterpreter) { 138 __ pushl(Address(rsp, 3*wordSize)); // push hi (and note rsp -= wordSize) 139 __ pushl(Address(rsp, 2*wordSize)); // push lo 140 __ fld_d(Address(rsp, 0)); // get double in ST0 141 __ addl(rsp, 2*wordSize); 142 } else { 143 __ fld_d(Address(rsp, 1*wordSize)); 144 } 145 switch (kind) { 146 case Interpreter::java_lang_math_sin : 147 __ trigfunc('s'); 148 break; 149 case Interpreter::java_lang_math_cos : 150 __ trigfunc('c'); 151 break; 152 case Interpreter::java_lang_math_tan : 153 __ trigfunc('t'); 154 break; 155 case Interpreter::java_lang_math_sqrt: 156 __ fsqrt(); 157 break; 158 case Interpreter::java_lang_math_abs: 159 __ fabs(); 160 break; 161 case Interpreter::java_lang_math_log: 162 __ flog(); 163 // Store to stack to convert 80bit precision back to 64bits 164 __ push_fTOS(); 165 __ pop_fTOS(); 166 break; 167 case Interpreter::java_lang_math_log10: 168 __ flog10(); 169 // Store to stack to convert 80bit precision back to 64bits 170 __ push_fTOS(); 171 __ pop_fTOS(); 172 break; 173 default : 174 ShouldNotReachHere(); 175 } 176 177 // return double result in xmm0 for interpreter and compilers. 178 if (UseSSE >= 2) { 179 __ subl(rsp, 2*wordSize); 180 __ fstp_d(Address(rsp, 0)); 181 __ movdbl(xmm0, Address(rsp, 0)); 182 __ addl(rsp, 2*wordSize); 183 } 184 185 // done, result in FPU ST(0) or XMM0 186 __ popl(rdi); // get return address 187 __ movl(rsp, rsi); // set sp to sender sp 188 __ jmp(rdi); 189 190 return entry_point; 191 } 192 193 194 // Abstract method entry 195 // Attempt to execute abstract method. Throw exception 196 address InterpreterGenerator::generate_abstract_entry(void) { 197 198 // rbx,: methodOop 199 // rcx: receiver (unused) 200 // rsi: previous interpreter state (C++ interpreter) must preserve 201 202 // rsi: sender SP 203 204 address entry_point = __ pc(); 205 206 // abstract method entry 207 // remove return address. Not really needed, since exception handling throws away expression stack 208 __ popl(rbx); 209 210 // adjust stack to what a normal return would do 211 __ movl(rsp, rsi); 212 // throw exception 213 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_AbstractMethodError)); 214 // the call_VM checks for exception, so we should never return here. 215 __ should_not_reach_here(); 216 217 return entry_point; 218 } 219 220 // This method tells the deoptimizer how big an interpreted frame must be: 221 int AbstractInterpreter::size_activation(methodOop method, 222 int tempcount, 223 int popframe_extra_args, 224 int moncount, 225 int callee_param_count, 226 int callee_locals, 227 bool is_top_frame) { 228 return layout_activation(method, 229 tempcount, 230 popframe_extra_args, 231 moncount, 232 callee_param_count, 233 callee_locals, 234 (frame*) NULL, 235 (frame*) NULL, 236 is_top_frame); 237 } 238 239 void Deoptimization::unwind_callee_save_values(frame* f, vframeArray* vframe_array) { 240 241 // This code is sort of the equivalent of C2IAdapter::setup_stack_frame back in 242 // the days we had adapter frames. When we deoptimize a situation where a 243 // compiled caller calls a compiled caller will have registers it expects 244 // to survive the call to the callee. If we deoptimize the callee the only 245 // way we can restore these registers is to have the oldest interpreter 246 // frame that we create restore these values. That is what this routine 247 // will accomplish. 248 249 // At the moment we have modified c2 to not have any callee save registers 250 // so this problem does not exist and this routine is just a place holder. 251 252 assert(f->is_interpreted_frame(), "must be interpreted"); 253 } 254 255