src/share/vm/interpreter/abstractInterpreter.hpp

changeset 0
f90c822e73f8
child 1
2d8a650513c2
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/vm/interpreter/abstractInterpreter.hpp	Wed Apr 27 01:25:04 2016 +0800
     1.3 @@ -0,0 +1,310 @@
     1.4 +/*
     1.5 + * Copyright (c) 1997, 2013, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.23 + * or visit www.oracle.com if you need additional information or have any
    1.24 + * questions.
    1.25 + *
    1.26 + */
    1.27 +
    1.28 +#ifndef SHARE_VM_INTERPRETER_ABSTRACTINTERPRETER_HPP
    1.29 +#define SHARE_VM_INTERPRETER_ABSTRACTINTERPRETER_HPP
    1.30 +
    1.31 +#include "code/stubs.hpp"
    1.32 +#include "interpreter/bytecodes.hpp"
    1.33 +#include "runtime/thread.inline.hpp"
    1.34 +#include "runtime/vmThread.hpp"
    1.35 +#include "utilities/top.hpp"
    1.36 +#ifdef TARGET_ARCH_x86
    1.37 +# include "interp_masm_x86.hpp"
    1.38 +#endif
    1.39 +#ifdef TARGET_ARCH_MODEL_sparc
    1.40 +# include "interp_masm_sparc.hpp"
    1.41 +#endif
    1.42 +#ifdef TARGET_ARCH_MODEL_zero
    1.43 +# include "interp_masm_zero.hpp"
    1.44 +#endif
    1.45 +#ifdef TARGET_ARCH_MODEL_arm
    1.46 +# include "interp_masm_arm.hpp"
    1.47 +#endif
    1.48 +#ifdef TARGET_ARCH_MODEL_ppc_32
    1.49 +# include "interp_masm_ppc_32.hpp"
    1.50 +#endif
    1.51 +#ifdef TARGET_ARCH_MODEL_ppc_64
    1.52 +# include "interp_masm_ppc_64.hpp"
    1.53 +#endif
    1.54 +
    1.55 +// This file contains the platform-independent parts
    1.56 +// of the abstract interpreter and the abstract interpreter generator.
    1.57 +
    1.58 +// Organization of the interpreter(s). There exists two different interpreters in hotpot
    1.59 +// an assembly language version (aka template interpreter) and a high level language version
    1.60 +// (aka c++ interpreter). Th division of labor is as follows:
    1.61 +
    1.62 +// Template Interpreter          C++ Interpreter        Functionality
    1.63 +//
    1.64 +// templateTable*                bytecodeInterpreter*   actual interpretation of bytecodes
    1.65 +//
    1.66 +// templateInterpreter*          cppInterpreter*        generation of assembly code that creates
    1.67 +//                                                      and manages interpreter runtime frames.
    1.68 +//                                                      Also code for populating interpreter
    1.69 +//                                                      frames created during deoptimization.
    1.70 +//
    1.71 +// For both template and c++ interpreter. There are common files for aspects of the interpreter
    1.72 +// that are generic to both interpreters. This is the layout:
    1.73 +//
    1.74 +// abstractInterpreter.hpp: generic description of the interpreter.
    1.75 +// interpreter*:            generic frame creation and handling.
    1.76 +//
    1.77 +
    1.78 +//------------------------------------------------------------------------------------------------------------------------
    1.79 +// The C++ interface to the bytecode interpreter(s).
    1.80 +
    1.81 +class AbstractInterpreter: AllStatic {
    1.82 +  friend class VMStructs;
    1.83 +  friend class Interpreter;
    1.84 +  friend class CppInterpreterGenerator;
    1.85 + public:
    1.86 +  enum MethodKind {
    1.87 +    zerolocals,                                                 // method needs locals initialization
    1.88 +    zerolocals_synchronized,                                    // method needs locals initialization & is synchronized
    1.89 +    native,                                                     // native method
    1.90 +    native_synchronized,                                        // native method & is synchronized
    1.91 +    empty,                                                      // empty method (code: _return)
    1.92 +    accessor,                                                   // accessor method (code: _aload_0, _getfield, _(a|i)return)
    1.93 +    abstract,                                                   // abstract method (throws an AbstractMethodException)
    1.94 +    method_handle_invoke_FIRST,                                 // java.lang.invoke.MethodHandles::invokeExact, etc.
    1.95 +    method_handle_invoke_LAST                                   = (method_handle_invoke_FIRST
    1.96 +                                                                   + (vmIntrinsics::LAST_MH_SIG_POLY
    1.97 +                                                                      - vmIntrinsics::FIRST_MH_SIG_POLY)),
    1.98 +    java_lang_math_sin,                                         // implementation of java.lang.Math.sin   (x)
    1.99 +    java_lang_math_cos,                                         // implementation of java.lang.Math.cos   (x)
   1.100 +    java_lang_math_tan,                                         // implementation of java.lang.Math.tan   (x)
   1.101 +    java_lang_math_abs,                                         // implementation of java.lang.Math.abs   (x)
   1.102 +    java_lang_math_sqrt,                                        // implementation of java.lang.Math.sqrt  (x)
   1.103 +    java_lang_math_log,                                         // implementation of java.lang.Math.log   (x)
   1.104 +    java_lang_math_log10,                                       // implementation of java.lang.Math.log10 (x)
   1.105 +    java_lang_math_pow,                                         // implementation of java.lang.Math.pow   (x,y)
   1.106 +    java_lang_math_exp,                                         // implementation of java.lang.Math.exp   (x)
   1.107 +    java_lang_ref_reference_get,                                // implementation of java.lang.ref.Reference.get()
   1.108 +    java_util_zip_CRC32_update,                                 // implementation of java.util.zip.CRC32.update()
   1.109 +    java_util_zip_CRC32_updateBytes,                            // implementation of java.util.zip.CRC32.updateBytes()
   1.110 +    java_util_zip_CRC32_updateByteBuffer,                       // implementation of java.util.zip.CRC32.updateByteBuffer()
   1.111 +    number_of_method_entries,
   1.112 +    invalid = -1
   1.113 +  };
   1.114 +
   1.115 +  // Conversion from the part of the above enum to vmIntrinsics::_invokeExact, etc.
   1.116 +  static vmIntrinsics::ID method_handle_intrinsic(MethodKind kind) {
   1.117 +    if (kind >= method_handle_invoke_FIRST && kind <= method_handle_invoke_LAST)
   1.118 +      return (vmIntrinsics::ID)( vmIntrinsics::FIRST_MH_SIG_POLY + (kind - method_handle_invoke_FIRST) );
   1.119 +    else
   1.120 +      return vmIntrinsics::_none;
   1.121 +  }
   1.122 +
   1.123 +  enum SomeConstants {
   1.124 +    number_of_result_handlers = 10                              // number of result handlers for native calls
   1.125 +  };
   1.126 +
   1.127 + protected:
   1.128 +  static StubQueue* _code;                                      // the interpreter code (codelets)
   1.129 +
   1.130 +  static bool       _notice_safepoints;                         // true if safepoints are activated
   1.131 +
   1.132 +  static address    _native_entry_begin;                        // Region for native entry code
   1.133 +  static address    _native_entry_end;
   1.134 +
   1.135 +  // method entry points
   1.136 +  static address    _entry_table[number_of_method_entries];     // entry points for a given method
   1.137 +  static address    _native_abi_to_tosca[number_of_result_handlers];  // for native method result handlers
   1.138 +  static address    _slow_signature_handler;                              // the native method generic (slow) signature handler
   1.139 +
   1.140 +  static address    _rethrow_exception_entry;                   // rethrows an activation in previous frame
   1.141 +
   1.142 +  friend class      AbstractInterpreterGenerator;
   1.143 +  friend class              InterpreterGenerator;
   1.144 +  friend class      InterpreterMacroAssembler;
   1.145 +
   1.146 + public:
   1.147 +  // Initialization/debugging
   1.148 +  static void       initialize();
   1.149 +  static StubQueue* code()                                      { return _code; }
   1.150 +
   1.151 +
   1.152 +  // Method activation
   1.153 +  static MethodKind method_kind(methodHandle m);
   1.154 +  static address    entry_for_kind(MethodKind k)                { assert(0 <= k && k < number_of_method_entries, "illegal kind"); return _entry_table[k]; }
   1.155 +  static address    entry_for_method(methodHandle m)            { return entry_for_kind(method_kind(m)); }
   1.156 +
   1.157 +  // used for bootstrapping method handles:
   1.158 +  static void       set_entry_for_kind(MethodKind k, address e);
   1.159 +
   1.160 +  static void       print_method_kind(MethodKind kind)          PRODUCT_RETURN;
   1.161 +
   1.162 +  static bool       can_be_compiled(methodHandle m);
   1.163 +
   1.164 +  // Runtime support
   1.165 +
   1.166 +  // length = invoke bytecode length (to advance to next bytecode)
   1.167 +  static address deopt_entry(TosState state, int length) { ShouldNotReachHere(); return NULL; }
   1.168 +  static address return_entry(TosState state, int length, Bytecodes::Code code) { ShouldNotReachHere(); return NULL; }
   1.169 +
   1.170 +  static address    rethrow_exception_entry()                   { return _rethrow_exception_entry; }
   1.171 +
   1.172 +  // Activation size in words for a method that is just being called.
   1.173 +  // Parameters haven't been pushed so count them too.
   1.174 +  static int        size_top_interpreter_activation(Method* method);
   1.175 +
   1.176 +  // Deoptimization support
   1.177 +  // Compute the entry address for continuation after
   1.178 +  static address deopt_continue_after_entry(Method* method,
   1.179 +                                            address bcp,
   1.180 +                                            int callee_parameters,
   1.181 +                                            bool is_top_frame);
   1.182 +  // Compute the entry address for reexecution
   1.183 +  static address deopt_reexecute_entry(Method* method, address bcp);
   1.184 +  // Deoptimization should reexecute this bytecode
   1.185 +  static bool    bytecode_should_reexecute(Bytecodes::Code code);
   1.186 +
   1.187 +  // deoptimization support
   1.188 +  static int        size_activation(int max_stack,
   1.189 +                                    int temps,
   1.190 +                                    int extra_args,
   1.191 +                                    int monitors,
   1.192 +                                    int callee_params,
   1.193 +                                    int callee_locals,
   1.194 +                                    bool is_top_frame);
   1.195 +
   1.196 +  static void      layout_activation(Method* method,
   1.197 +                                     int temps,
   1.198 +                                     int popframe_args,
   1.199 +                                     int monitors,
   1.200 +                                     int caller_actual_parameters,
   1.201 +                                     int callee_params,
   1.202 +                                     int callee_locals,
   1.203 +                                     frame* caller,
   1.204 +                                     frame* interpreter_frame,
   1.205 +                                     bool is_top_frame,
   1.206 +                                     bool is_bottom_frame);
   1.207 +
   1.208 +  // Runtime support
   1.209 +  static bool       is_not_reached(                       methodHandle method, int bci);
   1.210 +  // Safepoint support
   1.211 +  static void       notice_safepoints()                         { ShouldNotReachHere(); } // stops the thread when reaching a safepoint
   1.212 +  static void       ignore_safepoints()                         { ShouldNotReachHere(); } // ignores safepoints
   1.213 +
   1.214 +  // Support for native calls
   1.215 +  static address    slow_signature_handler()                    { return _slow_signature_handler; }
   1.216 +  static address    result_handler(BasicType type)              { return _native_abi_to_tosca[BasicType_as_index(type)]; }
   1.217 +  static int        BasicType_as_index(BasicType type);         // computes index into result_handler_by_index table
   1.218 +  static bool       in_native_entry(address pc)                 { return _native_entry_begin <= pc && pc < _native_entry_end; }
   1.219 +  // Debugging/printing
   1.220 +  static void       print();                                    // prints the interpreter code
   1.221 +
   1.222 + public:
   1.223 +  // Interpreter helpers
   1.224 +  const static int stackElementWords   = 1;
   1.225 +  const static int stackElementSize    = stackElementWords * wordSize;
   1.226 +  const static int logStackElementSize = LogBytesPerWord;
   1.227 +
   1.228 +  // Local values relative to locals[n]
   1.229 +  static int  local_offset_in_bytes(int n) {
   1.230 +    return ((frame::interpreter_frame_expression_stack_direction() * n) * stackElementSize);
   1.231 +  }
   1.232 +
   1.233 +  // access to stacked values according to type:
   1.234 +  static oop* oop_addr_in_slot(intptr_t* slot_addr) {
   1.235 +    return (oop*) slot_addr;
   1.236 +  }
   1.237 +  static jint* int_addr_in_slot(intptr_t* slot_addr) {
   1.238 +    if ((int) sizeof(jint) < wordSize && !Bytes::is_Java_byte_ordering_different())
   1.239 +      // big-endian LP64
   1.240 +      return (jint*)(slot_addr + 1) - 1;
   1.241 +    else
   1.242 +      return (jint*) slot_addr;
   1.243 +  }
   1.244 +  static jlong long_in_slot(intptr_t* slot_addr) {
   1.245 +    if (sizeof(intptr_t) >= sizeof(jlong)) {
   1.246 +      return *(jlong*) slot_addr;
   1.247 +    } else {
   1.248 +      return Bytes::get_native_u8((address)slot_addr);
   1.249 +    }
   1.250 +  }
   1.251 +  static void set_long_in_slot(intptr_t* slot_addr, jlong value) {
   1.252 +    if (sizeof(intptr_t) >= sizeof(jlong)) {
   1.253 +      *(jlong*) slot_addr = value;
   1.254 +    } else {
   1.255 +      Bytes::put_native_u8((address)slot_addr, value);
   1.256 +    }
   1.257 +  }
   1.258 +  static void get_jvalue_in_slot(intptr_t* slot_addr, BasicType type, jvalue* value) {
   1.259 +    switch (type) {
   1.260 +    case T_BOOLEAN: value->z = *int_addr_in_slot(slot_addr);            break;
   1.261 +    case T_CHAR:    value->c = *int_addr_in_slot(slot_addr);            break;
   1.262 +    case T_BYTE:    value->b = *int_addr_in_slot(slot_addr);            break;
   1.263 +    case T_SHORT:   value->s = *int_addr_in_slot(slot_addr);            break;
   1.264 +    case T_INT:     value->i = *int_addr_in_slot(slot_addr);            break;
   1.265 +    case T_LONG:    value->j = long_in_slot(slot_addr);                 break;
   1.266 +    case T_FLOAT:   value->f = *(jfloat*)int_addr_in_slot(slot_addr);   break;
   1.267 +    case T_DOUBLE:  value->d = jdouble_cast(long_in_slot(slot_addr));   break;
   1.268 +    case T_OBJECT:  value->l = (jobject)*oop_addr_in_slot(slot_addr);   break;
   1.269 +    default:        ShouldNotReachHere();
   1.270 +    }
   1.271 +  }
   1.272 +  static void set_jvalue_in_slot(intptr_t* slot_addr, BasicType type, jvalue* value) {
   1.273 +    switch (type) {
   1.274 +    case T_BOOLEAN: *int_addr_in_slot(slot_addr) = (value->z != 0);     break;
   1.275 +    case T_CHAR:    *int_addr_in_slot(slot_addr) = value->c;            break;
   1.276 +    case T_BYTE:    *int_addr_in_slot(slot_addr) = value->b;            break;
   1.277 +    case T_SHORT:   *int_addr_in_slot(slot_addr) = value->s;            break;
   1.278 +    case T_INT:     *int_addr_in_slot(slot_addr) = value->i;            break;
   1.279 +    case T_LONG:    set_long_in_slot(slot_addr, value->j);              break;
   1.280 +    case T_FLOAT:   *(jfloat*)int_addr_in_slot(slot_addr) = value->f;   break;
   1.281 +    case T_DOUBLE:  set_long_in_slot(slot_addr, jlong_cast(value->d));  break;
   1.282 +    case T_OBJECT:  *oop_addr_in_slot(slot_addr) = (oop) value->l;      break;
   1.283 +    default:        ShouldNotReachHere();
   1.284 +    }
   1.285 +  }
   1.286 +};
   1.287 +
   1.288 +//------------------------------------------------------------------------------------------------------------------------
   1.289 +// The interpreter generator.
   1.290 +
   1.291 +class Template;
   1.292 +class AbstractInterpreterGenerator: public StackObj {
   1.293 + protected:
   1.294 +  InterpreterMacroAssembler* _masm;
   1.295 +
   1.296 +  // shared code sequences
   1.297 +  // Converter for native abi result to tosca result
   1.298 +  address generate_result_handler_for(BasicType type);
   1.299 +  address generate_slow_signature_handler();
   1.300 +
   1.301 +  // entry point generator
   1.302 +  address generate_method_entry(AbstractInterpreter::MethodKind kind);
   1.303 +
   1.304 +  void bang_stack_shadow_pages(bool native_call);
   1.305 +
   1.306 +  void generate_all();
   1.307 +  void initialize_method_handle_entries();
   1.308 +
   1.309 + public:
   1.310 +  AbstractInterpreterGenerator(StubQueue* _code);
   1.311 +};
   1.312 +
   1.313 +#endif // SHARE_VM_INTERPRETER_ABSTRACTINTERPRETER_HPP

mercurial