src/share/vm/interpreter/abstractInterpreter.hpp

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

author
aoqi
date
Fri, 29 Apr 2016 00:06:10 +0800
changeset 1
2d8a650513c2
parent 0
f90c822e73f8
child 6876
710a3c8b516e
permissions
-rw-r--r--

Added MIPS 64-bit port.

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 1997, 2013, 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"
aoqi@0 39 #ifdef TARGET_ARCH_x86
aoqi@0 40 # include "interp_masm_x86.hpp"
aoqi@0 41 #endif
aoqi@1 42 #ifdef TARGET_ARCH_MODEL_mips_64
aoqi@1 43 # include "interp_masm_mips_64.hpp"
aoqi@1 44 #endif
aoqi@0 45 #ifdef TARGET_ARCH_MODEL_sparc
aoqi@0 46 # include "interp_masm_sparc.hpp"
aoqi@0 47 #endif
aoqi@0 48 #ifdef TARGET_ARCH_MODEL_zero
aoqi@0 49 # include "interp_masm_zero.hpp"
aoqi@0 50 #endif
aoqi@0 51 #ifdef TARGET_ARCH_MODEL_arm
aoqi@0 52 # include "interp_masm_arm.hpp"
aoqi@0 53 #endif
aoqi@0 54 #ifdef TARGET_ARCH_MODEL_ppc_32
aoqi@0 55 # include "interp_masm_ppc_32.hpp"
aoqi@0 56 #endif
aoqi@0 57 #ifdef TARGET_ARCH_MODEL_ppc_64
aoqi@0 58 # include "interp_masm_ppc_64.hpp"
aoqi@0 59 #endif
aoqi@0 60
aoqi@0 61 // This file contains the platform-independent parts
aoqi@0 62 // of the abstract interpreter and the abstract interpreter generator.
aoqi@0 63
aoqi@0 64 // Organization of the interpreter(s). There exists two different interpreters in hotpot
aoqi@0 65 // an assembly language version (aka template interpreter) and a high level language version
aoqi@0 66 // (aka c++ interpreter). Th division of labor is as follows:
aoqi@0 67
aoqi@0 68 // Template Interpreter C++ Interpreter Functionality
aoqi@0 69 //
aoqi@0 70 // templateTable* bytecodeInterpreter* actual interpretation of bytecodes
aoqi@0 71 //
aoqi@0 72 // templateInterpreter* cppInterpreter* generation of assembly code that creates
aoqi@0 73 // and manages interpreter runtime frames.
aoqi@0 74 // Also code for populating interpreter
aoqi@0 75 // frames created during deoptimization.
aoqi@0 76 //
aoqi@0 77 // For both template and c++ interpreter. There are common files for aspects of the interpreter
aoqi@0 78 // that are generic to both interpreters. This is the layout:
aoqi@0 79 //
aoqi@0 80 // abstractInterpreter.hpp: generic description of the interpreter.
aoqi@0 81 // interpreter*: generic frame creation and handling.
aoqi@0 82 //
aoqi@0 83
aoqi@0 84 //------------------------------------------------------------------------------------------------------------------------
aoqi@0 85 // The C++ interface to the bytecode interpreter(s).
aoqi@0 86
aoqi@0 87 class AbstractInterpreter: AllStatic {
aoqi@0 88 friend class VMStructs;
aoqi@0 89 friend class Interpreter;
aoqi@0 90 friend class CppInterpreterGenerator;
aoqi@0 91 public:
aoqi@0 92 enum MethodKind {
aoqi@0 93 zerolocals, // method needs locals initialization
aoqi@0 94 zerolocals_synchronized, // method needs locals initialization & is synchronized
aoqi@0 95 native, // native method
aoqi@0 96 native_synchronized, // native method & is synchronized
aoqi@0 97 empty, // empty method (code: _return)
aoqi@0 98 accessor, // accessor method (code: _aload_0, _getfield, _(a|i)return)
aoqi@0 99 abstract, // abstract method (throws an AbstractMethodException)
aoqi@0 100 method_handle_invoke_FIRST, // java.lang.invoke.MethodHandles::invokeExact, etc.
aoqi@0 101 method_handle_invoke_LAST = (method_handle_invoke_FIRST
aoqi@0 102 + (vmIntrinsics::LAST_MH_SIG_POLY
aoqi@0 103 - vmIntrinsics::FIRST_MH_SIG_POLY)),
aoqi@0 104 java_lang_math_sin, // implementation of java.lang.Math.sin (x)
aoqi@0 105 java_lang_math_cos, // implementation of java.lang.Math.cos (x)
aoqi@0 106 java_lang_math_tan, // implementation of java.lang.Math.tan (x)
aoqi@0 107 java_lang_math_abs, // implementation of java.lang.Math.abs (x)
aoqi@0 108 java_lang_math_sqrt, // implementation of java.lang.Math.sqrt (x)
aoqi@0 109 java_lang_math_log, // implementation of java.lang.Math.log (x)
aoqi@0 110 java_lang_math_log10, // implementation of java.lang.Math.log10 (x)
aoqi@0 111 java_lang_math_pow, // implementation of java.lang.Math.pow (x,y)
aoqi@0 112 java_lang_math_exp, // implementation of java.lang.Math.exp (x)
aoqi@0 113 java_lang_ref_reference_get, // implementation of java.lang.ref.Reference.get()
aoqi@0 114 java_util_zip_CRC32_update, // implementation of java.util.zip.CRC32.update()
aoqi@0 115 java_util_zip_CRC32_updateBytes, // implementation of java.util.zip.CRC32.updateBytes()
aoqi@0 116 java_util_zip_CRC32_updateByteBuffer, // implementation of java.util.zip.CRC32.updateByteBuffer()
aoqi@0 117 number_of_method_entries,
aoqi@0 118 invalid = -1
aoqi@0 119 };
aoqi@0 120
aoqi@0 121 // Conversion from the part of the above enum to vmIntrinsics::_invokeExact, etc.
aoqi@0 122 static vmIntrinsics::ID method_handle_intrinsic(MethodKind kind) {
aoqi@0 123 if (kind >= method_handle_invoke_FIRST && kind <= method_handle_invoke_LAST)
aoqi@0 124 return (vmIntrinsics::ID)( vmIntrinsics::FIRST_MH_SIG_POLY + (kind - method_handle_invoke_FIRST) );
aoqi@0 125 else
aoqi@0 126 return vmIntrinsics::_none;
aoqi@0 127 }
aoqi@0 128
aoqi@0 129 enum SomeConstants {
aoqi@0 130 number_of_result_handlers = 10 // number of result handlers for native calls
aoqi@0 131 };
aoqi@0 132
aoqi@0 133 protected:
aoqi@0 134 static StubQueue* _code; // the interpreter code (codelets)
aoqi@0 135
aoqi@0 136 static bool _notice_safepoints; // true if safepoints are activated
aoqi@0 137
aoqi@0 138 static address _native_entry_begin; // Region for native entry code
aoqi@0 139 static address _native_entry_end;
aoqi@0 140
aoqi@0 141 // method entry points
aoqi@0 142 static address _entry_table[number_of_method_entries]; // entry points for a given method
aoqi@0 143 static address _native_abi_to_tosca[number_of_result_handlers]; // for native method result handlers
aoqi@0 144 static address _slow_signature_handler; // the native method generic (slow) signature handler
aoqi@0 145
aoqi@0 146 static address _rethrow_exception_entry; // rethrows an activation in previous frame
aoqi@0 147
aoqi@0 148 friend class AbstractInterpreterGenerator;
aoqi@0 149 friend class InterpreterGenerator;
aoqi@0 150 friend class InterpreterMacroAssembler;
aoqi@0 151
aoqi@0 152 public:
aoqi@0 153 // Initialization/debugging
aoqi@0 154 static void initialize();
aoqi@0 155 static StubQueue* code() { return _code; }
aoqi@0 156
aoqi@0 157
aoqi@0 158 // Method activation
aoqi@0 159 static MethodKind method_kind(methodHandle m);
aoqi@0 160 static address entry_for_kind(MethodKind k) { assert(0 <= k && k < number_of_method_entries, "illegal kind"); return _entry_table[k]; }
aoqi@0 161 static address entry_for_method(methodHandle m) { return entry_for_kind(method_kind(m)); }
aoqi@0 162
aoqi@0 163 // used for bootstrapping method handles:
aoqi@0 164 static void set_entry_for_kind(MethodKind k, address e);
aoqi@0 165
aoqi@0 166 static void print_method_kind(MethodKind kind) PRODUCT_RETURN;
aoqi@0 167
aoqi@0 168 static bool can_be_compiled(methodHandle m);
aoqi@0 169
aoqi@0 170 // Runtime support
aoqi@0 171
aoqi@0 172 // length = invoke bytecode length (to advance to next bytecode)
aoqi@0 173 static address deopt_entry(TosState state, int length) { ShouldNotReachHere(); return NULL; }
aoqi@0 174 static address return_entry(TosState state, int length, Bytecodes::Code code) { ShouldNotReachHere(); return NULL; }
aoqi@0 175
aoqi@0 176 static address rethrow_exception_entry() { return _rethrow_exception_entry; }
aoqi@0 177
aoqi@0 178 // Activation size in words for a method that is just being called.
aoqi@0 179 // Parameters haven't been pushed so count them too.
aoqi@0 180 static int size_top_interpreter_activation(Method* method);
aoqi@0 181
aoqi@0 182 // Deoptimization support
aoqi@0 183 // Compute the entry address for continuation after
aoqi@0 184 static address deopt_continue_after_entry(Method* method,
aoqi@0 185 address bcp,
aoqi@0 186 int callee_parameters,
aoqi@0 187 bool is_top_frame);
aoqi@0 188 // Compute the entry address for reexecution
aoqi@0 189 static address deopt_reexecute_entry(Method* method, address bcp);
aoqi@0 190 // Deoptimization should reexecute this bytecode
aoqi@0 191 static bool bytecode_should_reexecute(Bytecodes::Code code);
aoqi@0 192
aoqi@0 193 // deoptimization support
aoqi@0 194 static int size_activation(int max_stack,
aoqi@0 195 int temps,
aoqi@0 196 int extra_args,
aoqi@0 197 int monitors,
aoqi@0 198 int callee_params,
aoqi@0 199 int callee_locals,
aoqi@0 200 bool is_top_frame);
aoqi@0 201
aoqi@0 202 static void layout_activation(Method* method,
aoqi@0 203 int temps,
aoqi@0 204 int popframe_args,
aoqi@0 205 int monitors,
aoqi@0 206 int caller_actual_parameters,
aoqi@0 207 int callee_params,
aoqi@0 208 int callee_locals,
aoqi@0 209 frame* caller,
aoqi@0 210 frame* interpreter_frame,
aoqi@0 211 bool is_top_frame,
aoqi@0 212 bool is_bottom_frame);
aoqi@0 213
aoqi@0 214 // Runtime support
aoqi@0 215 static bool is_not_reached( methodHandle method, int bci);
aoqi@0 216 // Safepoint support
aoqi@0 217 static void notice_safepoints() { ShouldNotReachHere(); } // stops the thread when reaching a safepoint
aoqi@0 218 static void ignore_safepoints() { ShouldNotReachHere(); } // ignores safepoints
aoqi@0 219
aoqi@0 220 // Support for native calls
aoqi@0 221 static address slow_signature_handler() { return _slow_signature_handler; }
aoqi@0 222 static address result_handler(BasicType type) { return _native_abi_to_tosca[BasicType_as_index(type)]; }
aoqi@0 223 static int BasicType_as_index(BasicType type); // computes index into result_handler_by_index table
aoqi@0 224 static bool in_native_entry(address pc) { return _native_entry_begin <= pc && pc < _native_entry_end; }
aoqi@0 225 // Debugging/printing
aoqi@0 226 static void print(); // prints the interpreter code
aoqi@0 227
aoqi@0 228 public:
aoqi@0 229 // Interpreter helpers
aoqi@0 230 const static int stackElementWords = 1;
aoqi@0 231 const static int stackElementSize = stackElementWords * wordSize;
aoqi@0 232 const static int logStackElementSize = LogBytesPerWord;
aoqi@0 233
aoqi@0 234 // Local values relative to locals[n]
aoqi@0 235 static int local_offset_in_bytes(int n) {
aoqi@0 236 return ((frame::interpreter_frame_expression_stack_direction() * n) * stackElementSize);
aoqi@0 237 }
aoqi@0 238
aoqi@0 239 // access to stacked values according to type:
aoqi@0 240 static oop* oop_addr_in_slot(intptr_t* slot_addr) {
aoqi@0 241 return (oop*) slot_addr;
aoqi@0 242 }
aoqi@0 243 static jint* int_addr_in_slot(intptr_t* slot_addr) {
aoqi@0 244 if ((int) sizeof(jint) < wordSize && !Bytes::is_Java_byte_ordering_different())
aoqi@0 245 // big-endian LP64
aoqi@0 246 return (jint*)(slot_addr + 1) - 1;
aoqi@0 247 else
aoqi@0 248 return (jint*) slot_addr;
aoqi@0 249 }
aoqi@0 250 static jlong long_in_slot(intptr_t* slot_addr) {
aoqi@0 251 if (sizeof(intptr_t) >= sizeof(jlong)) {
aoqi@0 252 return *(jlong*) slot_addr;
aoqi@0 253 } else {
aoqi@0 254 return Bytes::get_native_u8((address)slot_addr);
aoqi@0 255 }
aoqi@0 256 }
aoqi@0 257 static void set_long_in_slot(intptr_t* slot_addr, jlong value) {
aoqi@0 258 if (sizeof(intptr_t) >= sizeof(jlong)) {
aoqi@0 259 *(jlong*) slot_addr = value;
aoqi@0 260 } else {
aoqi@0 261 Bytes::put_native_u8((address)slot_addr, value);
aoqi@0 262 }
aoqi@0 263 }
aoqi@0 264 static void get_jvalue_in_slot(intptr_t* slot_addr, BasicType type, jvalue* value) {
aoqi@0 265 switch (type) {
aoqi@0 266 case T_BOOLEAN: value->z = *int_addr_in_slot(slot_addr); break;
aoqi@0 267 case T_CHAR: value->c = *int_addr_in_slot(slot_addr); break;
aoqi@0 268 case T_BYTE: value->b = *int_addr_in_slot(slot_addr); break;
aoqi@0 269 case T_SHORT: value->s = *int_addr_in_slot(slot_addr); break;
aoqi@0 270 case T_INT: value->i = *int_addr_in_slot(slot_addr); break;
aoqi@0 271 case T_LONG: value->j = long_in_slot(slot_addr); break;
aoqi@0 272 case T_FLOAT: value->f = *(jfloat*)int_addr_in_slot(slot_addr); break;
aoqi@0 273 case T_DOUBLE: value->d = jdouble_cast(long_in_slot(slot_addr)); break;
aoqi@0 274 case T_OBJECT: value->l = (jobject)*oop_addr_in_slot(slot_addr); break;
aoqi@0 275 default: ShouldNotReachHere();
aoqi@0 276 }
aoqi@0 277 }
aoqi@0 278 static void set_jvalue_in_slot(intptr_t* slot_addr, BasicType type, jvalue* value) {
aoqi@0 279 switch (type) {
aoqi@0 280 case T_BOOLEAN: *int_addr_in_slot(slot_addr) = (value->z != 0); break;
aoqi@0 281 case T_CHAR: *int_addr_in_slot(slot_addr) = value->c; break;
aoqi@0 282 case T_BYTE: *int_addr_in_slot(slot_addr) = value->b; break;
aoqi@0 283 case T_SHORT: *int_addr_in_slot(slot_addr) = value->s; break;
aoqi@0 284 case T_INT: *int_addr_in_slot(slot_addr) = value->i; break;
aoqi@0 285 case T_LONG: set_long_in_slot(slot_addr, value->j); break;
aoqi@0 286 case T_FLOAT: *(jfloat*)int_addr_in_slot(slot_addr) = value->f; break;
aoqi@0 287 case T_DOUBLE: set_long_in_slot(slot_addr, jlong_cast(value->d)); break;
aoqi@0 288 case T_OBJECT: *oop_addr_in_slot(slot_addr) = (oop) value->l; break;
aoqi@0 289 default: ShouldNotReachHere();
aoqi@0 290 }
aoqi@0 291 }
aoqi@0 292 };
aoqi@0 293
aoqi@0 294 //------------------------------------------------------------------------------------------------------------------------
aoqi@0 295 // The interpreter generator.
aoqi@0 296
aoqi@0 297 class Template;
aoqi@0 298 class AbstractInterpreterGenerator: public StackObj {
aoqi@0 299 protected:
aoqi@0 300 InterpreterMacroAssembler* _masm;
aoqi@0 301
aoqi@0 302 // shared code sequences
aoqi@0 303 // Converter for native abi result to tosca result
aoqi@0 304 address generate_result_handler_for(BasicType type);
aoqi@0 305 address generate_slow_signature_handler();
aoqi@0 306
aoqi@0 307 // entry point generator
aoqi@0 308 address generate_method_entry(AbstractInterpreter::MethodKind kind);
aoqi@0 309
aoqi@0 310 void bang_stack_shadow_pages(bool native_call);
aoqi@0 311
aoqi@0 312 void generate_all();
aoqi@0 313 void initialize_method_handle_entries();
aoqi@0 314
aoqi@0 315 public:
aoqi@0 316 AbstractInterpreterGenerator(StubQueue* _code);
aoqi@0 317 };
aoqi@0 318
aoqi@0 319 #endif // SHARE_VM_INTERPRETER_ABSTRACTINTERPRETER_HPP

mercurial