src/cpu/x86/vm/interpreter_x86_32.cpp

changeset 435
a61af66fc99e
child 739
dc7f315e41f7
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/cpu/x86/vm/interpreter_x86_32.cpp	Sat Dec 01 00:00:00 2007 +0000
     1.3 @@ -0,0 +1,250 @@
     1.4 +/*
     1.5 + * Copyright 1997-2007 Sun Microsystems, Inc.  All Rights Reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.
    1.11 + *
    1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.15 + * version 2 for more details (a copy is included in the LICENSE file that
    1.16 + * accompanied this code).
    1.17 + *
    1.18 + * You should have received a copy of the GNU General Public License version
    1.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.21 + *
    1.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    1.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
    1.24 + * have any questions.
    1.25 + *
    1.26 + */
    1.27 +
    1.28 +#include "incls/_precompiled.incl"
    1.29 +#include "incls/_interpreter_x86_32.cpp.incl"
    1.30 +
    1.31 +#define __ _masm->
    1.32 +
    1.33 +// Initialize the sentinel used to distinguish an interpreter return address.
    1.34 +const int Interpreter::return_sentinel = 0xfeedbeed;
    1.35 +
    1.36 +//------------------------------------------------------------------------------------------------------------------------
    1.37 +
    1.38 +address AbstractInterpreterGenerator::generate_slow_signature_handler() {
    1.39 +  address entry = __ pc();
    1.40 +  // rbx,: method
    1.41 +  // rcx: temporary
    1.42 +  // rdi: pointer to locals
    1.43 +  // rsp: end of copied parameters area
    1.44 +  __ movl(rcx, rsp);
    1.45 +  __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::slow_signature_handler), rbx, rdi, rcx);
    1.46 +  __ ret(0);
    1.47 +  return entry;
    1.48 +}
    1.49 +
    1.50 +
    1.51 +//
    1.52 +// Various method entries (that c++ and asm interpreter agree upon)
    1.53 +//------------------------------------------------------------------------------------------------------------------------
    1.54 +//
    1.55 +//
    1.56 +
    1.57 +// Empty method, generate a very fast return.
    1.58 +
    1.59 +address InterpreterGenerator::generate_empty_entry(void) {
    1.60 +
    1.61 +  // rbx,: methodOop
    1.62 +  // rcx: receiver (unused)
    1.63 +  // rsi: previous interpreter state (C++ interpreter) must preserve
    1.64 +  // rsi: sender sp must set sp to this value on return
    1.65 +
    1.66 +  if (!UseFastEmptyMethods) return NULL;
    1.67 +
    1.68 +  address entry_point = __ pc();
    1.69 +
    1.70 +  // If we need a safepoint check, generate full interpreter entry.
    1.71 +  Label slow_path;
    1.72 +  ExternalAddress state(SafepointSynchronize::address_of_state());
    1.73 +  __ cmp32(ExternalAddress(SafepointSynchronize::address_of_state()),
    1.74 +           SafepointSynchronize::_not_synchronized);
    1.75 +  __ jcc(Assembler::notEqual, slow_path);
    1.76 +
    1.77 +  // do nothing for empty methods (do not even increment invocation counter)
    1.78 +  // Code: _return
    1.79 +  // _return
    1.80 +  // return w/o popping parameters
    1.81 +  __ popl(rax);
    1.82 +  __ movl(rsp, rsi);
    1.83 +  __ jmp(rax);
    1.84 +
    1.85 +  __ bind(slow_path);
    1.86 +  (void) generate_normal_entry(false);
    1.87 +  return entry_point;
    1.88 +}
    1.89 +
    1.90 +address InterpreterGenerator::generate_math_entry(AbstractInterpreter::MethodKind kind) {
    1.91 +
    1.92 +  // rbx,: methodOop
    1.93 +  // rcx: scratrch
    1.94 +  // rsi: sender sp
    1.95 +
    1.96 +  if (!InlineIntrinsics) return NULL; // Generate a vanilla entry
    1.97 +
    1.98 +  address entry_point = __ pc();
    1.99 +
   1.100 +  // These don't need a safepoint check because they aren't virtually
   1.101 +  // callable. We won't enter these intrinsics from compiled code.
   1.102 +  // If in the future we added an intrinsic which was virtually callable
   1.103 +  // we'd have to worry about how to safepoint so that this code is used.
   1.104 +
   1.105 +  // mathematical functions inlined by compiler
   1.106 +  // (interpreter must provide identical implementation
   1.107 +  // in order to avoid monotonicity bugs when switching
   1.108 +  // from interpreter to compiler in the middle of some
   1.109 +  // computation)
   1.110 +  //
   1.111 +  // stack: [ ret adr ] <-- rsp
   1.112 +  //        [ lo(arg) ]
   1.113 +  //        [ hi(arg) ]
   1.114 +  //
   1.115 +
   1.116 +  // Note: For JDK 1.2 StrictMath doesn't exist and Math.sin/cos/sqrt are
   1.117 +  //       native methods. Interpreter::method_kind(...) does a check for
   1.118 +  //       native methods first before checking for intrinsic methods and
   1.119 +  //       thus will never select this entry point. Make sure it is not
   1.120 +  //       called accidentally since the SharedRuntime entry points will
   1.121 +  //       not work for JDK 1.2.
   1.122 +  //
   1.123 +  // We no longer need to check for JDK 1.2 since it's EOL'ed.
   1.124 +  // The following check existed in pre 1.6 implementation,
   1.125 +  //    if (Universe::is_jdk12x_version()) {
   1.126 +  //      __ should_not_reach_here();
   1.127 +  //    }
   1.128 +  // Universe::is_jdk12x_version() always returns false since
   1.129 +  // the JDK version is not yet determined when this method is called.
   1.130 +  // This method is called during interpreter_init() whereas
   1.131 +  // JDK version is only determined when universe2_init() is called.
   1.132 +
   1.133 +  // Note: For JDK 1.3 StrictMath exists and Math.sin/cos/sqrt are
   1.134 +  //       java methods.  Interpreter::method_kind(...) will select
   1.135 +  //       this entry point for the corresponding methods in JDK 1.3.
   1.136 +  // get argument
   1.137 +  if (TaggedStackInterpreter) {
   1.138 +    __ pushl(Address(rsp, 3*wordSize));  // push hi (and note rsp -= wordSize)
   1.139 +    __ pushl(Address(rsp, 2*wordSize));  // push lo
   1.140 +    __ fld_d(Address(rsp, 0));           // get double in ST0
   1.141 +    __ addl(rsp, 2*wordSize);
   1.142 +  } else {
   1.143 +    __ fld_d(Address(rsp, 1*wordSize));
   1.144 +  }
   1.145 +  switch (kind) {
   1.146 +    case Interpreter::java_lang_math_sin :
   1.147 +        __ trigfunc('s');
   1.148 +        break;
   1.149 +    case Interpreter::java_lang_math_cos :
   1.150 +        __ trigfunc('c');
   1.151 +        break;
   1.152 +    case Interpreter::java_lang_math_tan :
   1.153 +        __ trigfunc('t');
   1.154 +        break;
   1.155 +    case Interpreter::java_lang_math_sqrt:
   1.156 +        __ fsqrt();
   1.157 +        break;
   1.158 +    case Interpreter::java_lang_math_abs:
   1.159 +        __ fabs();
   1.160 +        break;
   1.161 +    case Interpreter::java_lang_math_log:
   1.162 +        __ flog();
   1.163 +        // Store to stack to convert 80bit precision back to 64bits
   1.164 +        __ push_fTOS();
   1.165 +        __ pop_fTOS();
   1.166 +        break;
   1.167 +    case Interpreter::java_lang_math_log10:
   1.168 +        __ flog10();
   1.169 +        // Store to stack to convert 80bit precision back to 64bits
   1.170 +        __ push_fTOS();
   1.171 +        __ pop_fTOS();
   1.172 +        break;
   1.173 +    default                              :
   1.174 +        ShouldNotReachHere();
   1.175 +  }
   1.176 +
   1.177 +  // return double result in xmm0 for interpreter and compilers.
   1.178 +  if (UseSSE >= 2) {
   1.179 +    __ subl(rsp, 2*wordSize);
   1.180 +    __ fstp_d(Address(rsp, 0));
   1.181 +    __ movdbl(xmm0, Address(rsp, 0));
   1.182 +    __ addl(rsp, 2*wordSize);
   1.183 +  }
   1.184 +
   1.185 +  // done, result in FPU ST(0) or XMM0
   1.186 +  __ popl(rdi);                              // get return address
   1.187 +  __ movl(rsp, rsi);                         // set sp to sender sp
   1.188 +  __ jmp(rdi);
   1.189 +
   1.190 +  return entry_point;
   1.191 +}
   1.192 +
   1.193 +
   1.194 +// Abstract method entry
   1.195 +// Attempt to execute abstract method. Throw exception
   1.196 +address InterpreterGenerator::generate_abstract_entry(void) {
   1.197 +
   1.198 +  // rbx,: methodOop
   1.199 +  // rcx: receiver (unused)
   1.200 +  // rsi: previous interpreter state (C++ interpreter) must preserve
   1.201 +
   1.202 +  // rsi: sender SP
   1.203 +
   1.204 +  address entry_point = __ pc();
   1.205 +
   1.206 +  // abstract method entry
   1.207 +  // remove return address. Not really needed, since exception handling throws away expression stack
   1.208 +  __ popl(rbx);
   1.209 +
   1.210 +  // adjust stack to what a normal return would do
   1.211 +  __ movl(rsp, rsi);
   1.212 +  // throw exception
   1.213 +  __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_AbstractMethodError));
   1.214 +  // the call_VM checks for exception, so we should never return here.
   1.215 +  __ should_not_reach_here();
   1.216 +
   1.217 +  return entry_point;
   1.218 +}
   1.219 +
   1.220 +// This method tells the deoptimizer how big an interpreted frame must be:
   1.221 +int AbstractInterpreter::size_activation(methodOop method,
   1.222 +                                         int tempcount,
   1.223 +                                         int popframe_extra_args,
   1.224 +                                         int moncount,
   1.225 +                                         int callee_param_count,
   1.226 +                                         int callee_locals,
   1.227 +                                         bool is_top_frame) {
   1.228 +  return layout_activation(method,
   1.229 +                           tempcount,
   1.230 +                           popframe_extra_args,
   1.231 +                           moncount,
   1.232 +                           callee_param_count,
   1.233 +                           callee_locals,
   1.234 +                           (frame*) NULL,
   1.235 +                           (frame*) NULL,
   1.236 +                           is_top_frame);
   1.237 +}
   1.238 +
   1.239 +void Deoptimization::unwind_callee_save_values(frame* f, vframeArray* vframe_array) {
   1.240 +
   1.241 +  // This code is sort of the equivalent of C2IAdapter::setup_stack_frame back in
   1.242 +  // the days we had adapter frames. When we deoptimize a situation where a
   1.243 +  // compiled caller calls a compiled caller will have registers it expects
   1.244 +  // to survive the call to the callee. If we deoptimize the callee the only
   1.245 +  // way we can restore these registers is to have the oldest interpreter
   1.246 +  // frame that we create restore these values. That is what this routine
   1.247 +  // will accomplish.
   1.248 +
   1.249 +  // At the moment we have modified c2 to not have any callee save registers
   1.250 +  // so this problem does not exist and this routine is just a place holder.
   1.251 +
   1.252 +  assert(f->is_interpreted_frame(), "must be interpreted");
   1.253 +}

mercurial