src/share/vm/interpreter/abstractInterpreter.hpp

Wed, 27 Apr 2016 01:25:04 +0800

author
aoqi
date
Wed, 27 Apr 2016 01:25:04 +0800
changeset 0
f90c822e73f8
child 1
2d8a650513c2
permissions
-rw-r--r--

Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/hotspot/
changeset: 6782:28b50d07f6f8
tag: jdk8u25-b17

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

mercurial