src/cpu/mips/vm/interpreter_mips_64.cpp

Fri, 29 Apr 2016 00:06:10 +0800

author
aoqi
date
Fri, 29 Apr 2016 00:06:10 +0800
changeset 1
2d8a650513c2
child 6880
52ea28d233d2
permissions
-rw-r--r--

Added MIPS 64-bit port.

aoqi@1 1 /*
aoqi@1 2 * Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved.
aoqi@1 3 * Copyright (c) 2015, 2016, Loongson Technology. All rights reserved.
aoqi@1 4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@1 5 *
aoqi@1 6 * This code is free software; you can redistribute it and/or modify it
aoqi@1 7 * under the terms of the GNU General Public License version 2 only, as
aoqi@1 8 * published by the Free Software Foundation.
aoqi@1 9 *
aoqi@1 10 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@1 11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@1 12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@1 13 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@1 14 * accompanied this code).
aoqi@1 15 *
aoqi@1 16 * You should have received a copy of the GNU General Public License version
aoqi@1 17 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@1 18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@1 19 *
aoqi@1 20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@1 21 * or visit www.oracle.com if you need additional information or have any
aoqi@1 22 * questions.
aoqi@1 23 *
aoqi@1 24 */
aoqi@1 25
aoqi@1 26 #include "precompiled.hpp"
aoqi@1 27 #include "asm/macroAssembler.hpp"
aoqi@1 28 #include "interpreter/bytecodeHistogram.hpp"
aoqi@1 29 #include "interpreter/interpreter.hpp"
aoqi@1 30 #include "interpreter/interpreterGenerator.hpp"
aoqi@1 31 #include "interpreter/interpreterRuntime.hpp"
aoqi@1 32 #include "interpreter/templateTable.hpp"
aoqi@1 33 #include "oops/arrayOop.hpp"
aoqi@1 34 #include "oops/methodData.hpp"
aoqi@1 35 #include "oops/method.hpp"
aoqi@1 36 #include "oops/oop.inline.hpp"
aoqi@1 37 #include "prims/jvmtiExport.hpp"
aoqi@1 38 #include "prims/jvmtiThreadState.hpp"
aoqi@1 39 #include "prims/methodHandles.hpp"
aoqi@1 40 #include "runtime/arguments.hpp"
aoqi@1 41 #include "runtime/deoptimization.hpp"
aoqi@1 42 #include "runtime/frame.inline.hpp"
aoqi@1 43 #include "runtime/sharedRuntime.hpp"
aoqi@1 44 #include "runtime/stubRoutines.hpp"
aoqi@1 45 #include "runtime/synchronizer.hpp"
aoqi@1 46 #include "runtime/timer.hpp"
aoqi@1 47 #include "runtime/vframeArray.hpp"
aoqi@1 48 #include "utilities/debug.hpp"
aoqi@1 49 #ifdef COMPILER1
aoqi@1 50 #include "c1/c1_Runtime1.hpp"
aoqi@1 51 #endif
aoqi@1 52
aoqi@1 53 #define __ _masm->
aoqi@1 54
aoqi@1 55
aoqi@1 56 address AbstractInterpreterGenerator::generate_slow_signature_handler() {
aoqi@1 57 address entry = __ pc();
aoqi@1 58
aoqi@1 59 // Rmethod: method
aoqi@1 60 // LVP: pointer to locals
aoqi@1 61 // T3: first stack arg - wordSize
aoqi@1 62 __ move(T3, SP);
aoqi@1 63 __ pushad();
aoqi@1 64 __ call_VM(noreg,
aoqi@1 65 CAST_FROM_FN_PTR(address,
aoqi@1 66 InterpreterRuntime::slow_signature_handler),
aoqi@1 67 Rmethod, LVP, T3);
aoqi@1 68 __ move(S0, V0);
aoqi@1 69 __ popad();
aoqi@1 70 __ move(V0, S0);
aoqi@1 71
aoqi@1 72 // V0: result handler
aoqi@1 73
aoqi@1 74 // Stack layout:
aoqi@1 75 // ...
aoqi@1 76
aoqi@1 77 // Do FP first so we can use c_rarg3 as temp
aoqi@1 78 __ ld(T3, Address(SP, -1 * wordSize)); // float/double identifiers
aoqi@1 79
aoqi@1 80 // A0 is for env.
aoqi@1 81 // If the mothed is not static, A1 will be corrected in generate_native_entry.
aoqi@1 82 for ( int i= 1; i < Argument::n_register_parameters; i++ ) {
aoqi@1 83 Register reg = as_Register(i + A0->encoding());
aoqi@1 84 FloatRegister floatreg = as_FloatRegister(i + F12->encoding());
aoqi@1 85 Label isfloatordouble, isdouble, next;
aoqi@1 86
aoqi@1 87 __ andi(AT, T3, 1 << (i*2)); // Float or Double?
aoqi@1 88 __ bne(AT, R0, isfloatordouble);
aoqi@1 89 __ delayed()->nop();
aoqi@1 90
aoqi@1 91 // Do Int register here
aoqi@1 92 __ ld(reg, Address(SP, -(Argument::n_register_parameters + 1 -i) * wordSize));
aoqi@1 93 __ b (next);
aoqi@1 94 __ delayed()->nop();
aoqi@1 95
aoqi@1 96 __ bind(isfloatordouble);
aoqi@1 97 __ andi(AT,T3, 1 << ((i*2)+1)); // Double?
aoqi@1 98 __ bne(AT, R0, isdouble);
aoqi@1 99 __ delayed()->nop();
aoqi@1 100
aoqi@1 101 // Do Float Here
aoqi@1 102 __ lwc1(floatreg, Address(SP, -(Argument::n_float_register_parameters + 1 -i) * wordSize));
aoqi@1 103 __ b(next);
aoqi@1 104 __ delayed()->nop();
aoqi@1 105
aoqi@1 106 // Do Double here
aoqi@1 107 __ bind(isdouble);
aoqi@1 108 __ ldc1(floatreg, Address(SP, -(Argument::n_float_register_parameters + 1 -i) * wordSize));
aoqi@1 109
aoqi@1 110 __ bind(next);
aoqi@1 111 }
aoqi@1 112
aoqi@1 113 __ jr(RA);
aoqi@1 114 __ delayed()->nop();
aoqi@1 115 return entry;
aoqi@1 116 }
aoqi@1 117
aoqi@1 118
aoqi@1 119 //
aoqi@1 120 // Various method entries
aoqi@1 121 //
aoqi@1 122
aoqi@1 123 address InterpreterGenerator::generate_math_entry(AbstractInterpreter::MethodKind kind) {
aoqi@1 124
aoqi@1 125 // Rmethod: methodOop
aoqi@1 126 // V0: scratrch
aoqi@1 127 // esi: send 's sp, should we use Rsender @jerome
aoqi@1 128 if (!InlineIntrinsics) return NULL; // Generate a vanilla entry
aoqi@1 129 address entry_point = __ pc();
aoqi@1 130
aoqi@1 131 // These don't need a safepoint check because they aren't virtually
aoqi@1 132 // callable. We won't enter these intrinsics from compiled code.
aoqi@1 133 // If in the future we added an intrinsic which was virtually callable
aoqi@1 134 // we'd have to worry about how to safepoint so that this code is used.
aoqi@1 135
aoqi@1 136
aoqi@1 137 // mathematical functions inlined by compiler
aoqi@1 138 // (interpreter must provide identical implementation
aoqi@1 139 // in order to avoid monotonicity bugs when switching
aoqi@1 140 // from interpreter to compiler in the middle of some
aoqi@1 141 // computation)
aoqi@1 142 //
aoqi@1 143 // stack: [ lo(arg) ] <-- sp
aoqi@1 144 // [ hi(arg) ]
aoqi@1 145 /*
aoqi@1 146 if (Universe::is_jdk12x_version()) {
aoqi@1 147 // Note: For JDK 1.2 StrictMath doesn't exist and Math.sin/cos/sqrt are
aoqi@1 148 // native methods. Interpreter::method_kind(...) does a check for
aoqi@1 149 // native methods first before checking for intrinsic methods and
aoqi@1 150 // thus will never select this entry point. Make sure it is not
aoqi@1 151 // called accidentally since the SharedRuntime entry points will
aoqi@1 152 // not work for JDK 1.2.
aoqi@1 153 __ should_not_reach_here();
aoqi@1 154 } else
aoqi@1 155 */
aoqi@1 156 {
aoqi@1 157 // Note: For JDK 1.3 StrictMath exists and Math.sin/cos/sqrt are
aoqi@1 158 // java methods. Interpreter::method_kind(...) will select
aoqi@1 159 // this entry point for the corresponding methods in JDK 1.3.
aoqi@1 160 //FIXME, @jerome
aoqi@1 161 /*if (TaggedStackInterpreter) {
aoqi@1 162 __ lw(AT, SP,3*wordSize);
aoqi@1 163 __ push(AT);//push hi note ,SP -=wordSize
aoqi@1 164 __ lw(AT, SP,2*wordSize);
aoqi@1 165 __ push(AT);//push lo
aoqi@1 166 __ lwc1(F12, SP, 2 * wordSize);
aoqi@1 167 __ lwc1(F13, SP, 3 * wordSize);
aoqi@1 168 __ sw(RA, SP, (1) * wordSize);
aoqi@1 169 __ sw(FP, SP, (0) * wordSize);
aoqi@1 170 __ addi(SP, SP, 2 * wordSize);
aoqi@1 171 __ move(FP, SP);
aoqi@1 172
aoqi@1 173 }else {*/
aoqi@1 174 __ ldc1(F12, SP, 0 * wordSize);
aoqi@1 175 __ ldc1(F13, SP, 1 * wordSize);
aoqi@1 176 __ sd(RA, SP, (-1) * wordSize);
aoqi@1 177 __ sd(FP, SP, (-2) * wordSize);
aoqi@1 178 __ move(FP, SP);
aoqi@1 179 __ daddi(SP, SP, (-2) * wordSize);
aoqi@1 180
aoqi@1 181 // }
aoqi@1 182 // [ fp ] <-- sp
aoqi@1 183 // [ ra ]
aoqi@1 184 // [ lo ] <-- fp
aoqi@1 185 // [ hi ]
aoqi@1 186 /*
aoqi@1 187 switch (kind) {
aoqi@1 188 case Interpreter::java_lang_math_sin :
aoqi@1 189 __ sincos(true, true);
aoqi@1 190 break;
aoqi@1 191 case Interpreter::java_lang_math_cos :
aoqi@1 192 __ sincos(false, true);
aoqi@1 193 break;
aoqi@1 194 case Interpreter::java_lang_math_sqrt:
aoqi@1 195 __ sqrt_d(F0, F12);
aoqi@1 196 break;
aoqi@1 197 default :
aoqi@1 198 ShouldNotReachHere();
aoqi@1 199 }
aoqi@1 200 */
aoqi@1 201 //FIXME, need consider this
aoqi@1 202 switch (kind) {
aoqi@1 203 case Interpreter::java_lang_math_sin :
aoqi@1 204 __ trigfunc('s');
aoqi@1 205 break;
aoqi@1 206 case Interpreter::java_lang_math_cos :
aoqi@1 207 __ trigfunc('c');
aoqi@1 208 break;
aoqi@1 209 case Interpreter::java_lang_math_tan :
aoqi@1 210 __ trigfunc('t');
aoqi@1 211 break;
aoqi@1 212 case Interpreter::java_lang_math_sqrt:
aoqi@1 213 // __ fsqrt();
aoqi@1 214 __ sqrt_d(F0, F12);
aoqi@1 215 break;
aoqi@1 216 case Interpreter::java_lang_math_abs:
aoqi@1 217 // __ fabs();
aoqi@1 218 __ abs_d(F0, F12);
aoqi@1 219 break;
aoqi@1 220 case Interpreter::java_lang_math_log:
aoqi@1 221 // __ flog();
aoqi@1 222 // Store to stack to convert 80bit precision back to 64bits
aoqi@1 223 // __ push_fTOS();
aoqi@1 224 // __ pop_fTOS();
aoqi@1 225 break;
aoqi@1 226 case Interpreter::java_lang_math_log10:
aoqi@1 227 // __ flog10();
aoqi@1 228 // Store to stack to convert 80bit precision back to 64bits
aoqi@1 229 // __ push_fTOS();
aoqi@1 230 // __ pop_fTOS();
aoqi@1 231 break;
aoqi@1 232 case Interpreter::java_lang_math_pow:
aoqi@1 233 //__ fld_d(Address(rsp, 3*wordSize)); // second argument (one
aoqi@1 234 // empty stack slot)
aoqi@1 235 //__ pow_with_fallback(0);
aoqi@1 236 break;
aoqi@1 237 case Interpreter::java_lang_math_exp:
aoqi@1 238 //__ exp_with_fallback(0);
aoqi@1 239 break;
aoqi@1 240
aoqi@1 241 default :
aoqi@1 242 ShouldNotReachHere();
aoqi@1 243 }
aoqi@1 244
aoqi@1 245 // must maintain return value in F0:F1
aoqi@1 246 __ ld(RA, FP, (-1) * wordSize);
aoqi@1 247 //FIXME
aoqi@1 248 __ move(SP, Rsender);
aoqi@1 249 // __ move(SP, T0);
aoqi@1 250 __ ld(FP, FP, (-2) * wordSize);
aoqi@1 251 __ jr(RA);
aoqi@1 252 __ delayed()->nop();
aoqi@1 253 }
aoqi@1 254 return entry_point;
aoqi@1 255 }
aoqi@1 256
aoqi@1 257
aoqi@1 258 // Abstract method entry
aoqi@1 259 // Attempt to execute abstract method. Throw exception
aoqi@1 260 address InterpreterGenerator::generate_abstract_entry(void) {
aoqi@1 261
aoqi@1 262 // Rmethod: methodOop
aoqi@1 263 // V0: receiver (unused)
aoqi@1 264 // esi: previous interpreter state (C++ interpreter) must preserve
aoqi@1 265 // Rsender : sender 's sp
aoqi@1 266 address entry_point = __ pc();
aoqi@1 267
aoqi@1 268 // abstract method entry
aoqi@1 269 // throw exception
aoqi@1 270 // adjust stack to what a normal return would do
aoqi@1 271
aoqi@1 272 //__ movl(esp, esi);
aoqi@1 273 __ move(SP,Rsender); //FIXME, why jvm6 add this @jerome
aoqi@1 274 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_AbstractMethodError));
aoqi@1 275 // the call_VM checks for exception, so we should never return here.
aoqi@1 276 __ should_not_reach_here();
aoqi@1 277
aoqi@1 278 return entry_point;
aoqi@1 279 }
aoqi@1 280
aoqi@1 281
aoqi@1 282 // Empty method, generate a very fast return.
aoqi@1 283
aoqi@1 284 address InterpreterGenerator::generate_empty_entry(void) {
aoqi@1 285
aoqi@1 286 // Rmethod: methodOop
aoqi@1 287 // V0: receiver (unused)
aoqi@1 288 // esi: previous interpreter state (C++ interpreter) must preserve
aoqi@1 289 //Rsender: sender 's sp , must set sp to this value on return , on mips ,now use T0,as it right?
aoqi@1 290 if (!UseFastEmptyMethods) return NULL;
aoqi@1 291
aoqi@1 292 address entry_point = __ pc();
aoqi@1 293
aoqi@1 294 Label slow_path;
aoqi@1 295 __ li(RT0, SafepointSynchronize::address_of_state());
aoqi@1 296 __ lw(AT, RT0, 0);
aoqi@1 297 __ move(RT0, (SafepointSynchronize::_not_synchronized));
aoqi@1 298 __ bne(AT, RT0,slow_path);
aoqi@1 299 __ delayed()->nop();
aoqi@1 300 __ move(SP, Rsender);
aoqi@1 301 __ jr(RA);
aoqi@1 302 __ delayed()->nop();
aoqi@1 303 __ bind(slow_path);
aoqi@1 304 (void) generate_normal_entry(false);
aoqi@1 305
aoqi@1 306 return entry_point;
aoqi@1 307
aoqi@1 308 }
aoqi@1 309
aoqi@1 310 void Deoptimization::unwind_callee_save_values(frame* f, vframeArray* vframe_array) {
aoqi@1 311
aoqi@1 312 // This code is sort of the equivalent of C2IAdapter::setup_stack_frame back in
aoqi@1 313 // the days we had adapter frames. When we deoptimize a situation where a
aoqi@1 314 // compiled caller calls a compiled caller will have registers it expects
aoqi@1 315 // to survive the call to the callee. If we deoptimize the callee the only
aoqi@1 316 // way we can restore these registers is to have the oldest interpreter
aoqi@1 317 // frame that we create restore these values. That is what this routine
aoqi@1 318 // will accomplish.
aoqi@1 319
aoqi@1 320 // At the moment we have modified c2 to not have any callee save registers
aoqi@1 321 // so this problem does not exist and this routine is just a place holder.
aoqi@1 322
aoqi@1 323 assert(f->is_interpreted_frame(), "must be interpreted");
aoqi@1 324 }

mercurial