hotspot/src/cpu/aarch64/vm/interpreter_aarch64.cpp
changeset 35479 62c12ca7a45e
parent 35474 8333d76c7fee
child 35480 6ed8e1b70803
equal deleted inserted replaced
35474:8333d76c7fee 35479:62c12ca7a45e
     1 /*
       
     2  * Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.
       
     3  * Copyright (c) 2014, Red Hat Inc. All rights reserved.
       
     4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       
     5  *
       
     6  * This code is free software; you can redistribute it and/or modify it
       
     7  * under the terms of the GNU General Public License version 2 only, as
       
     8  * published by the Free Software Foundation.
       
     9  *
       
    10  * This code is distributed in the hope that it will be useful, but WITHOUT
       
    11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    13  * version 2 for more details (a copy is included in the LICENSE file that
       
    14  * accompanied this code).
       
    15  *
       
    16  * You should have received a copy of the GNU General Public License version
       
    17  * 2 along with this work; if not, write to the Free Software Foundation,
       
    18  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    19  *
       
    20  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
       
    21  * or visit www.oracle.com if you need additional information or have any
       
    22  * questions.
       
    23  *
       
    24  */
       
    25 
       
    26 #include "precompiled.hpp"
       
    27 #include "asm/macroAssembler.hpp"
       
    28 #include "interpreter/bytecodeHistogram.hpp"
       
    29 #include "interpreter/interpreter.hpp"
       
    30 #include "interpreter/interpreterRuntime.hpp"
       
    31 #include "interpreter/interp_masm.hpp"
       
    32 #include "interpreter/templateInterpreterGenerator.hpp"
       
    33 #include "interpreter/templateTable.hpp"
       
    34 #include "oops/arrayOop.hpp"
       
    35 #include "oops/methodData.hpp"
       
    36 #include "oops/method.hpp"
       
    37 #include "oops/oop.inline.hpp"
       
    38 #include "prims/jvmtiExport.hpp"
       
    39 #include "prims/jvmtiThreadState.hpp"
       
    40 #include "prims/methodHandles.hpp"
       
    41 #include "runtime/arguments.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 address AbstractInterpreterGenerator::generate_slow_signature_handler() {
       
    57   address entry = __ pc();
       
    58 
       
    59   __ andr(esp, esp, -16);
       
    60   __ mov(c_rarg3, esp);
       
    61   // rmethod
       
    62   // rlocals
       
    63   // c_rarg3: first stack arg - wordSize
       
    64 
       
    65   // adjust sp
       
    66   __ sub(sp, c_rarg3, 18 * wordSize);
       
    67   __ str(lr, Address(__ pre(sp, -2 * wordSize)));
       
    68   __ call_VM(noreg,
       
    69              CAST_FROM_FN_PTR(address,
       
    70                               InterpreterRuntime::slow_signature_handler),
       
    71              rmethod, rlocals, c_rarg3);
       
    72 
       
    73   // r0: result handler
       
    74 
       
    75   // Stack layout:
       
    76   // rsp: return address           <- sp
       
    77   //      1 garbage
       
    78   //      8 integer args (if static first is unused)
       
    79   //      1 float/double identifiers
       
    80   //      8 double args
       
    81   //        stack args              <- esp
       
    82   //        garbage
       
    83   //        expression stack bottom
       
    84   //        bcp (NULL)
       
    85   //        ...
       
    86 
       
    87   // Restore LR
       
    88   __ ldr(lr, Address(__ post(sp, 2 * wordSize)));
       
    89 
       
    90   // Do FP first so we can use c_rarg3 as temp
       
    91   __ ldrw(c_rarg3, Address(sp, 9 * wordSize)); // float/double identifiers
       
    92 
       
    93   for (int i = 0; i < Argument::n_float_register_parameters_c; i++) {
       
    94     const FloatRegister r = as_FloatRegister(i);
       
    95 
       
    96     Label d, done;
       
    97 
       
    98     __ tbnz(c_rarg3, i, d);
       
    99     __ ldrs(r, Address(sp, (10 + i) * wordSize));
       
   100     __ b(done);
       
   101     __ bind(d);
       
   102     __ ldrd(r, Address(sp, (10 + i) * wordSize));
       
   103     __ bind(done);
       
   104   }
       
   105 
       
   106   // c_rarg0 contains the result from the call of
       
   107   // InterpreterRuntime::slow_signature_handler so we don't touch it
       
   108   // here.  It will be loaded with the JNIEnv* later.
       
   109   __ ldr(c_rarg1, Address(sp, 1 * wordSize));
       
   110   for (int i = c_rarg2->encoding(); i <= c_rarg7->encoding(); i += 2) {
       
   111     Register rm = as_Register(i), rn = as_Register(i+1);
       
   112     __ ldp(rm, rn, Address(sp, i * wordSize));
       
   113   }
       
   114 
       
   115   __ add(sp, sp, 18 * wordSize);
       
   116   __ ret(lr);
       
   117 
       
   118   return entry;
       
   119 }
       
   120 
       
   121 
       
   122 //
       
   123 // Various method entries
       
   124 //
       
   125 
       
   126 address TemplateInterpreterGenerator::generate_math_entry(AbstractInterpreter::MethodKind kind) {
       
   127   // rmethod: Method*
       
   128   // r13: sender sp
       
   129   // esp: args
       
   130 
       
   131   if (!InlineIntrinsics) return NULL; // Generate a vanilla entry
       
   132 
       
   133   // These don't need a safepoint check because they aren't virtually
       
   134   // callable. We won't enter these intrinsics from compiled code.
       
   135   // If in the future we added an intrinsic which was virtually callable
       
   136   // we'd have to worry about how to safepoint so that this code is used.
       
   137 
       
   138   // mathematical functions inlined by compiler
       
   139   // (interpreter must provide identical implementation
       
   140   // in order to avoid monotonicity bugs when switching
       
   141   // from interpreter to compiler in the middle of some
       
   142   // computation)
       
   143   //
       
   144   // stack:
       
   145   //        [ arg ] <-- esp
       
   146   //        [ arg ]
       
   147   // retaddr in lr
       
   148 
       
   149   address entry_point = NULL;
       
   150   Register continuation = lr;
       
   151   switch (kind) {
       
   152   case Interpreter::java_lang_math_abs:
       
   153     entry_point = __ pc();
       
   154     __ ldrd(v0, Address(esp));
       
   155     __ fabsd(v0, v0);
       
   156     __ mov(sp, r13); // Restore caller's SP
       
   157     break;
       
   158   case Interpreter::java_lang_math_sqrt:
       
   159     entry_point = __ pc();
       
   160     __ ldrd(v0, Address(esp));
       
   161     __ fsqrtd(v0, v0);
       
   162     __ mov(sp, r13);
       
   163     break;
       
   164   case Interpreter::java_lang_math_sin :
       
   165   case Interpreter::java_lang_math_cos :
       
   166   case Interpreter::java_lang_math_tan :
       
   167   case Interpreter::java_lang_math_log :
       
   168   case Interpreter::java_lang_math_log10 :
       
   169   case Interpreter::java_lang_math_exp :
       
   170     entry_point = __ pc();
       
   171     __ ldrd(v0, Address(esp));
       
   172     __ mov(sp, r13);
       
   173     __ mov(r19, lr);
       
   174     continuation = r19;  // The first callee-saved register
       
   175     generate_transcendental_entry(kind, 1);
       
   176     break;
       
   177   case Interpreter::java_lang_math_pow :
       
   178     entry_point = __ pc();
       
   179     __ mov(r19, lr);
       
   180     continuation = r19;
       
   181     __ ldrd(v0, Address(esp, 2 * Interpreter::stackElementSize));
       
   182     __ ldrd(v1, Address(esp));
       
   183     __ mov(sp, r13);
       
   184     generate_transcendental_entry(kind, 2);
       
   185     break;
       
   186   default:
       
   187     ;
       
   188   }
       
   189   if (entry_point) {
       
   190     __ br(continuation);
       
   191   }
       
   192 
       
   193   return entry_point;
       
   194 }
       
   195 
       
   196   // double trigonometrics and transcendentals
       
   197   // static jdouble dsin(jdouble x);
       
   198   // static jdouble dcos(jdouble x);
       
   199   // static jdouble dtan(jdouble x);
       
   200   // static jdouble dlog(jdouble x);
       
   201   // static jdouble dlog10(jdouble x);
       
   202   // static jdouble dexp(jdouble x);
       
   203   // static jdouble dpow(jdouble x, jdouble y);
       
   204 
       
   205 void TemplateInterpreterGenerator::generate_transcendental_entry(AbstractInterpreter::MethodKind kind, int fpargs) {
       
   206   address fn;
       
   207   switch (kind) {
       
   208   case Interpreter::java_lang_math_sin :
       
   209     fn = CAST_FROM_FN_PTR(address, SharedRuntime::dsin);
       
   210     break;
       
   211   case Interpreter::java_lang_math_cos :
       
   212     fn = CAST_FROM_FN_PTR(address, SharedRuntime::dcos);
       
   213     break;
       
   214   case Interpreter::java_lang_math_tan :
       
   215     fn = CAST_FROM_FN_PTR(address, SharedRuntime::dtan);
       
   216     break;
       
   217   case Interpreter::java_lang_math_log :
       
   218     fn = CAST_FROM_FN_PTR(address, SharedRuntime::dlog);
       
   219     break;
       
   220   case Interpreter::java_lang_math_log10 :
       
   221     fn = CAST_FROM_FN_PTR(address, SharedRuntime::dlog10);
       
   222     break;
       
   223   case Interpreter::java_lang_math_exp :
       
   224     fn = CAST_FROM_FN_PTR(address, SharedRuntime::dexp);
       
   225     break;
       
   226   case Interpreter::java_lang_math_pow :
       
   227     fpargs = 2;
       
   228     fn = CAST_FROM_FN_PTR(address, SharedRuntime::dpow);
       
   229     break;
       
   230   default:
       
   231     ShouldNotReachHere();
       
   232   }
       
   233   const int gpargs = 0, rtype = 3;
       
   234   __ mov(rscratch1, fn);
       
   235   __ blrt(rscratch1, gpargs, fpargs, rtype);
       
   236 }
       
   237 
       
   238 // Abstract method entry
       
   239 // Attempt to execute abstract method. Throw exception
       
   240 address TemplateInterpreterGenerator::generate_abstract_entry(void) {
       
   241   // rmethod: Method*
       
   242   // r13: sender SP
       
   243 
       
   244   address entry_point = __ pc();
       
   245 
       
   246   // abstract method entry
       
   247 
       
   248   //  pop return address, reset last_sp to NULL
       
   249   __ empty_expression_stack();
       
   250   __ restore_bcp();      // bcp must be correct for exception handler   (was destroyed)
       
   251   __ restore_locals();   // make sure locals pointer is correct as well (was destroyed)
       
   252 
       
   253   // throw exception
       
   254   __ call_VM(noreg, CAST_FROM_FN_PTR(address,
       
   255                              InterpreterRuntime::throw_AbstractMethodError));
       
   256   // the call_VM checks for exception, so we should never return here.
       
   257   __ should_not_reach_here();
       
   258 
       
   259   return entry_point;
       
   260 }