Wed, 03 Jul 2019 20:42:37 +0800
Merge
aoqi@0 | 1 | /* |
dlong@7598 | 2 | * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved. |
aoqi@0 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
aoqi@0 | 4 | * |
aoqi@0 | 5 | * This code is free software; you can redistribute it and/or modify it |
aoqi@0 | 6 | * under the terms of the GNU General Public License version 2 only, as |
aoqi@0 | 7 | * published by the Free Software Foundation. |
aoqi@0 | 8 | * |
aoqi@0 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
aoqi@0 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
aoqi@0 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
aoqi@0 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
aoqi@0 | 13 | * accompanied this code). |
aoqi@0 | 14 | * |
aoqi@0 | 15 | * You should have received a copy of the GNU General Public License version |
aoqi@0 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
aoqi@0 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
aoqi@0 | 18 | * |
aoqi@0 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
aoqi@0 | 20 | * or visit www.oracle.com if you need additional information or have any |
aoqi@0 | 21 | * questions. |
aoqi@0 | 22 | * |
aoqi@0 | 23 | */ |
aoqi@0 | 24 | |
aoqi@1 | 25 | /* |
aoqi@1 | 26 | * This file has been modified by Loongson Technology in 2015. These |
aoqi@1 | 27 | * modifications are Copyright (c) 2015 Loongson Technology, and are made |
aoqi@1 | 28 | * available on the same license terms set forth above. |
aoqi@1 | 29 | */ |
aoqi@1 | 30 | |
aoqi@0 | 31 | #ifndef SHARE_VM_INTERPRETER_ABSTRACTINTERPRETER_HPP |
aoqi@0 | 32 | #define SHARE_VM_INTERPRETER_ABSTRACTINTERPRETER_HPP |
aoqi@0 | 33 | |
aoqi@0 | 34 | #include "code/stubs.hpp" |
aoqi@0 | 35 | #include "interpreter/bytecodes.hpp" |
aoqi@0 | 36 | #include "runtime/thread.inline.hpp" |
aoqi@0 | 37 | #include "runtime/vmThread.hpp" |
aoqi@0 | 38 | #include "utilities/top.hpp" |
dlong@7598 | 39 | #if defined INTERP_MASM_MD_HPP |
dlong@7598 | 40 | # include INTERP_MASM_MD_HPP |
dlong@7598 | 41 | #elif defined TARGET_ARCH_x86 |
aoqi@0 | 42 | # include "interp_masm_x86.hpp" |
dlong@7598 | 43 | #elif defined TARGET_ARCH_MODEL_sparc |
roland@6723 | 44 | # include "interp_masm_sparc.hpp" |
dlong@7598 | 45 | #elif defined TARGET_ARCH_MODEL_zero |
roland@6723 | 46 | # include "interp_masm_zero.hpp" |
dlong@7598 | 47 | #elif defined TARGET_ARCH_MODEL_ppc_64 |
roland@6723 | 48 | # include "interp_masm_ppc_64.hpp" |
aoqi@7994 | 49 | #elif defined TARGET_ARCH_MODEL_mips_64 |
aoqi@1 | 50 | # include "interp_masm_mips_64.hpp" |
aoqi@1 | 51 | #endif |
aoqi@0 | 52 | |
aoqi@0 | 53 | // This file contains the platform-independent parts |
aoqi@0 | 54 | // of the abstract interpreter and the abstract interpreter generator. |
aoqi@0 | 55 | |
aoqi@0 | 56 | // Organization of the interpreter(s). There exists two different interpreters in hotpot |
aoqi@0 | 57 | // an assembly language version (aka template interpreter) and a high level language version |
aoqi@0 | 58 | // (aka c++ interpreter). Th division of labor is as follows: |
aoqi@0 | 59 | |
aoqi@0 | 60 | // Template Interpreter C++ Interpreter Functionality |
aoqi@0 | 61 | // |
aoqi@0 | 62 | // templateTable* bytecodeInterpreter* actual interpretation of bytecodes |
aoqi@0 | 63 | // |
aoqi@0 | 64 | // templateInterpreter* cppInterpreter* generation of assembly code that creates |
aoqi@0 | 65 | // and manages interpreter runtime frames. |
aoqi@0 | 66 | // Also code for populating interpreter |
aoqi@0 | 67 | // frames created during deoptimization. |
aoqi@0 | 68 | // |
aoqi@0 | 69 | // For both template and c++ interpreter. There are common files for aspects of the interpreter |
aoqi@0 | 70 | // that are generic to both interpreters. This is the layout: |
aoqi@0 | 71 | // |
aoqi@0 | 72 | // abstractInterpreter.hpp: generic description of the interpreter. |
aoqi@0 | 73 | // interpreter*: generic frame creation and handling. |
aoqi@0 | 74 | // |
aoqi@0 | 75 | |
aoqi@0 | 76 | //------------------------------------------------------------------------------------------------------------------------ |
aoqi@0 | 77 | // The C++ interface to the bytecode interpreter(s). |
aoqi@0 | 78 | |
aoqi@0 | 79 | class AbstractInterpreter: AllStatic { |
aoqi@0 | 80 | friend class VMStructs; |
aoqi@0 | 81 | friend class Interpreter; |
aoqi@0 | 82 | friend class CppInterpreterGenerator; |
aoqi@0 | 83 | public: |
aoqi@0 | 84 | enum MethodKind { |
aoqi@0 | 85 | zerolocals, // method needs locals initialization |
aoqi@0 | 86 | zerolocals_synchronized, // method needs locals initialization & is synchronized |
aoqi@0 | 87 | native, // native method |
aoqi@0 | 88 | native_synchronized, // native method & is synchronized |
aoqi@0 | 89 | empty, // empty method (code: _return) |
aoqi@0 | 90 | accessor, // accessor method (code: _aload_0, _getfield, _(a|i)return) |
aoqi@0 | 91 | abstract, // abstract method (throws an AbstractMethodException) |
aoqi@0 | 92 | method_handle_invoke_FIRST, // java.lang.invoke.MethodHandles::invokeExact, etc. |
aoqi@0 | 93 | method_handle_invoke_LAST = (method_handle_invoke_FIRST |
aoqi@0 | 94 | + (vmIntrinsics::LAST_MH_SIG_POLY |
aoqi@0 | 95 | - vmIntrinsics::FIRST_MH_SIG_POLY)), |
aoqi@0 | 96 | java_lang_math_sin, // implementation of java.lang.Math.sin (x) |
aoqi@0 | 97 | java_lang_math_cos, // implementation of java.lang.Math.cos (x) |
aoqi@0 | 98 | java_lang_math_tan, // implementation of java.lang.Math.tan (x) |
aoqi@0 | 99 | java_lang_math_abs, // implementation of java.lang.Math.abs (x) |
aoqi@0 | 100 | java_lang_math_sqrt, // implementation of java.lang.Math.sqrt (x) |
aoqi@0 | 101 | java_lang_math_log, // implementation of java.lang.Math.log (x) |
aoqi@0 | 102 | java_lang_math_log10, // implementation of java.lang.Math.log10 (x) |
aoqi@0 | 103 | java_lang_math_pow, // implementation of java.lang.Math.pow (x,y) |
aoqi@0 | 104 | java_lang_math_exp, // implementation of java.lang.Math.exp (x) |
aoqi@0 | 105 | java_lang_ref_reference_get, // implementation of java.lang.ref.Reference.get() |
aoqi@0 | 106 | java_util_zip_CRC32_update, // implementation of java.util.zip.CRC32.update() |
aoqi@0 | 107 | java_util_zip_CRC32_updateBytes, // implementation of java.util.zip.CRC32.updateBytes() |
aoqi@0 | 108 | java_util_zip_CRC32_updateByteBuffer, // implementation of java.util.zip.CRC32.updateByteBuffer() |
aoqi@0 | 109 | number_of_method_entries, |
aoqi@0 | 110 | invalid = -1 |
aoqi@0 | 111 | }; |
aoqi@0 | 112 | |
aoqi@0 | 113 | // Conversion from the part of the above enum to vmIntrinsics::_invokeExact, etc. |
aoqi@0 | 114 | static vmIntrinsics::ID method_handle_intrinsic(MethodKind kind) { |
aoqi@0 | 115 | if (kind >= method_handle_invoke_FIRST && kind <= method_handle_invoke_LAST) |
aoqi@0 | 116 | return (vmIntrinsics::ID)( vmIntrinsics::FIRST_MH_SIG_POLY + (kind - method_handle_invoke_FIRST) ); |
aoqi@0 | 117 | else |
aoqi@0 | 118 | return vmIntrinsics::_none; |
aoqi@0 | 119 | } |
aoqi@0 | 120 | |
aoqi@0 | 121 | enum SomeConstants { |
aoqi@0 | 122 | number_of_result_handlers = 10 // number of result handlers for native calls |
aoqi@0 | 123 | }; |
aoqi@0 | 124 | |
aoqi@0 | 125 | protected: |
aoqi@0 | 126 | static StubQueue* _code; // the interpreter code (codelets) |
aoqi@0 | 127 | |
aoqi@0 | 128 | static bool _notice_safepoints; // true if safepoints are activated |
aoqi@0 | 129 | |
aoqi@0 | 130 | static address _native_entry_begin; // Region for native entry code |
aoqi@0 | 131 | static address _native_entry_end; |
aoqi@0 | 132 | |
aoqi@0 | 133 | // method entry points |
aoqi@0 | 134 | static address _entry_table[number_of_method_entries]; // entry points for a given method |
aoqi@0 | 135 | static address _native_abi_to_tosca[number_of_result_handlers]; // for native method result handlers |
aoqi@0 | 136 | static address _slow_signature_handler; // the native method generic (slow) signature handler |
aoqi@0 | 137 | |
aoqi@0 | 138 | static address _rethrow_exception_entry; // rethrows an activation in previous frame |
aoqi@0 | 139 | |
aoqi@0 | 140 | friend class AbstractInterpreterGenerator; |
aoqi@0 | 141 | friend class InterpreterGenerator; |
aoqi@0 | 142 | friend class InterpreterMacroAssembler; |
aoqi@0 | 143 | |
aoqi@0 | 144 | public: |
aoqi@0 | 145 | // Initialization/debugging |
aoqi@0 | 146 | static void initialize(); |
aoqi@0 | 147 | static StubQueue* code() { return _code; } |
aoqi@0 | 148 | |
aoqi@0 | 149 | |
aoqi@0 | 150 | // Method activation |
aoqi@0 | 151 | static MethodKind method_kind(methodHandle m); |
aoqi@0 | 152 | static address entry_for_kind(MethodKind k) { assert(0 <= k && k < number_of_method_entries, "illegal kind"); return _entry_table[k]; } |
aoqi@0 | 153 | static address entry_for_method(methodHandle m) { return entry_for_kind(method_kind(m)); } |
aoqi@0 | 154 | |
aoqi@0 | 155 | // used for bootstrapping method handles: |
aoqi@0 | 156 | static void set_entry_for_kind(MethodKind k, address e); |
aoqi@0 | 157 | |
aoqi@0 | 158 | static void print_method_kind(MethodKind kind) PRODUCT_RETURN; |
aoqi@0 | 159 | |
aoqi@0 | 160 | static bool can_be_compiled(methodHandle m); |
aoqi@0 | 161 | |
aoqi@0 | 162 | // Runtime support |
aoqi@0 | 163 | |
aoqi@0 | 164 | // length = invoke bytecode length (to advance to next bytecode) |
aoqi@0 | 165 | static address deopt_entry(TosState state, int length) { ShouldNotReachHere(); return NULL; } |
aoqi@0 | 166 | static address return_entry(TosState state, int length, Bytecodes::Code code) { ShouldNotReachHere(); return NULL; } |
aoqi@0 | 167 | |
aoqi@0 | 168 | static address rethrow_exception_entry() { return _rethrow_exception_entry; } |
aoqi@0 | 169 | |
aoqi@0 | 170 | // Activation size in words for a method that is just being called. |
aoqi@0 | 171 | // Parameters haven't been pushed so count them too. |
aoqi@0 | 172 | static int size_top_interpreter_activation(Method* method); |
aoqi@0 | 173 | |
aoqi@0 | 174 | // Deoptimization support |
aoqi@0 | 175 | // Compute the entry address for continuation after |
aoqi@0 | 176 | static address deopt_continue_after_entry(Method* method, |
aoqi@0 | 177 | address bcp, |
aoqi@0 | 178 | int callee_parameters, |
aoqi@0 | 179 | bool is_top_frame); |
aoqi@0 | 180 | // Compute the entry address for reexecution |
aoqi@0 | 181 | static address deopt_reexecute_entry(Method* method, address bcp); |
aoqi@0 | 182 | // Deoptimization should reexecute this bytecode |
aoqi@0 | 183 | static bool bytecode_should_reexecute(Bytecodes::Code code); |
aoqi@0 | 184 | |
aoqi@0 | 185 | // deoptimization support |
aoqi@0 | 186 | static int size_activation(int max_stack, |
aoqi@0 | 187 | int temps, |
aoqi@0 | 188 | int extra_args, |
aoqi@0 | 189 | int monitors, |
aoqi@0 | 190 | int callee_params, |
aoqi@0 | 191 | int callee_locals, |
aoqi@0 | 192 | bool is_top_frame); |
aoqi@0 | 193 | |
aoqi@0 | 194 | static void layout_activation(Method* method, |
aoqi@0 | 195 | int temps, |
aoqi@0 | 196 | int popframe_args, |
aoqi@0 | 197 | int monitors, |
aoqi@0 | 198 | int caller_actual_parameters, |
aoqi@0 | 199 | int callee_params, |
aoqi@0 | 200 | int callee_locals, |
aoqi@0 | 201 | frame* caller, |
aoqi@0 | 202 | frame* interpreter_frame, |
aoqi@0 | 203 | bool is_top_frame, |
aoqi@0 | 204 | bool is_bottom_frame); |
aoqi@0 | 205 | |
aoqi@0 | 206 | // Runtime support |
aoqi@0 | 207 | static bool is_not_reached( methodHandle method, int bci); |
aoqi@0 | 208 | // Safepoint support |
aoqi@0 | 209 | static void notice_safepoints() { ShouldNotReachHere(); } // stops the thread when reaching a safepoint |
aoqi@0 | 210 | static void ignore_safepoints() { ShouldNotReachHere(); } // ignores safepoints |
aoqi@0 | 211 | |
aoqi@0 | 212 | // Support for native calls |
aoqi@0 | 213 | static address slow_signature_handler() { return _slow_signature_handler; } |
aoqi@0 | 214 | static address result_handler(BasicType type) { return _native_abi_to_tosca[BasicType_as_index(type)]; } |
aoqi@0 | 215 | static int BasicType_as_index(BasicType type); // computes index into result_handler_by_index table |
aoqi@0 | 216 | static bool in_native_entry(address pc) { return _native_entry_begin <= pc && pc < _native_entry_end; } |
aoqi@0 | 217 | // Debugging/printing |
aoqi@0 | 218 | static void print(); // prints the interpreter code |
aoqi@0 | 219 | |
aoqi@0 | 220 | public: |
aoqi@0 | 221 | // Interpreter helpers |
aoqi@0 | 222 | const static int stackElementWords = 1; |
aoqi@0 | 223 | const static int stackElementSize = stackElementWords * wordSize; |
aoqi@0 | 224 | const static int logStackElementSize = LogBytesPerWord; |
aoqi@0 | 225 | |
aoqi@0 | 226 | // Local values relative to locals[n] |
aoqi@0 | 227 | static int local_offset_in_bytes(int n) { |
aoqi@0 | 228 | return ((frame::interpreter_frame_expression_stack_direction() * n) * stackElementSize); |
aoqi@0 | 229 | } |
aoqi@0 | 230 | |
aoqi@0 | 231 | // access to stacked values according to type: |
aoqi@0 | 232 | static oop* oop_addr_in_slot(intptr_t* slot_addr) { |
aoqi@0 | 233 | return (oop*) slot_addr; |
aoqi@0 | 234 | } |
aoqi@0 | 235 | static jint* int_addr_in_slot(intptr_t* slot_addr) { |
aoqi@0 | 236 | if ((int) sizeof(jint) < wordSize && !Bytes::is_Java_byte_ordering_different()) |
aoqi@0 | 237 | // big-endian LP64 |
aoqi@0 | 238 | return (jint*)(slot_addr + 1) - 1; |
aoqi@0 | 239 | else |
aoqi@0 | 240 | return (jint*) slot_addr; |
aoqi@0 | 241 | } |
aoqi@0 | 242 | static jlong long_in_slot(intptr_t* slot_addr) { |
aoqi@0 | 243 | if (sizeof(intptr_t) >= sizeof(jlong)) { |
aoqi@0 | 244 | return *(jlong*) slot_addr; |
aoqi@0 | 245 | } else { |
aoqi@0 | 246 | return Bytes::get_native_u8((address)slot_addr); |
aoqi@0 | 247 | } |
aoqi@0 | 248 | } |
aoqi@0 | 249 | static void set_long_in_slot(intptr_t* slot_addr, jlong value) { |
aoqi@0 | 250 | if (sizeof(intptr_t) >= sizeof(jlong)) { |
aoqi@0 | 251 | *(jlong*) slot_addr = value; |
aoqi@0 | 252 | } else { |
aoqi@0 | 253 | Bytes::put_native_u8((address)slot_addr, value); |
aoqi@0 | 254 | } |
aoqi@0 | 255 | } |
aoqi@0 | 256 | static void get_jvalue_in_slot(intptr_t* slot_addr, BasicType type, jvalue* value) { |
aoqi@0 | 257 | switch (type) { |
aoqi@0 | 258 | case T_BOOLEAN: value->z = *int_addr_in_slot(slot_addr); break; |
aoqi@0 | 259 | case T_CHAR: value->c = *int_addr_in_slot(slot_addr); break; |
aoqi@0 | 260 | case T_BYTE: value->b = *int_addr_in_slot(slot_addr); break; |
aoqi@0 | 261 | case T_SHORT: value->s = *int_addr_in_slot(slot_addr); break; |
aoqi@0 | 262 | case T_INT: value->i = *int_addr_in_slot(slot_addr); break; |
aoqi@0 | 263 | case T_LONG: value->j = long_in_slot(slot_addr); break; |
aoqi@0 | 264 | case T_FLOAT: value->f = *(jfloat*)int_addr_in_slot(slot_addr); break; |
aoqi@0 | 265 | case T_DOUBLE: value->d = jdouble_cast(long_in_slot(slot_addr)); break; |
aoqi@0 | 266 | case T_OBJECT: value->l = (jobject)*oop_addr_in_slot(slot_addr); break; |
aoqi@0 | 267 | default: ShouldNotReachHere(); |
aoqi@0 | 268 | } |
aoqi@0 | 269 | } |
aoqi@0 | 270 | static void set_jvalue_in_slot(intptr_t* slot_addr, BasicType type, jvalue* value) { |
aoqi@0 | 271 | switch (type) { |
aoqi@0 | 272 | case T_BOOLEAN: *int_addr_in_slot(slot_addr) = (value->z != 0); break; |
aoqi@0 | 273 | case T_CHAR: *int_addr_in_slot(slot_addr) = value->c; break; |
aoqi@0 | 274 | case T_BYTE: *int_addr_in_slot(slot_addr) = value->b; break; |
aoqi@0 | 275 | case T_SHORT: *int_addr_in_slot(slot_addr) = value->s; break; |
aoqi@0 | 276 | case T_INT: *int_addr_in_slot(slot_addr) = value->i; break; |
aoqi@0 | 277 | case T_LONG: set_long_in_slot(slot_addr, value->j); break; |
aoqi@0 | 278 | case T_FLOAT: *(jfloat*)int_addr_in_slot(slot_addr) = value->f; break; |
aoqi@0 | 279 | case T_DOUBLE: set_long_in_slot(slot_addr, jlong_cast(value->d)); break; |
aoqi@0 | 280 | case T_OBJECT: *oop_addr_in_slot(slot_addr) = (oop) value->l; break; |
aoqi@0 | 281 | default: ShouldNotReachHere(); |
aoqi@0 | 282 | } |
aoqi@0 | 283 | } |
aoqi@0 | 284 | }; |
aoqi@0 | 285 | |
aoqi@0 | 286 | //------------------------------------------------------------------------------------------------------------------------ |
aoqi@0 | 287 | // The interpreter generator. |
aoqi@0 | 288 | |
aoqi@0 | 289 | class Template; |
aoqi@0 | 290 | class AbstractInterpreterGenerator: public StackObj { |
aoqi@0 | 291 | protected: |
aoqi@0 | 292 | InterpreterMacroAssembler* _masm; |
aoqi@0 | 293 | |
aoqi@0 | 294 | // shared code sequences |
aoqi@0 | 295 | // Converter for native abi result to tosca result |
aoqi@0 | 296 | address generate_result_handler_for(BasicType type); |
aoqi@0 | 297 | address generate_slow_signature_handler(); |
aoqi@0 | 298 | |
aoqi@0 | 299 | // entry point generator |
aoqi@0 | 300 | address generate_method_entry(AbstractInterpreter::MethodKind kind); |
aoqi@0 | 301 | |
aoqi@0 | 302 | void bang_stack_shadow_pages(bool native_call); |
aoqi@0 | 303 | |
aoqi@0 | 304 | void generate_all(); |
aoqi@0 | 305 | void initialize_method_handle_entries(); |
aoqi@0 | 306 | |
aoqi@0 | 307 | public: |
aoqi@0 | 308 | AbstractInterpreterGenerator(StubQueue* _code); |
aoqi@0 | 309 | }; |
aoqi@0 | 310 | |
aoqi@0 | 311 | #endif // SHARE_VM_INTERPRETER_ABSTRACTINTERPRETER_HPP |