Wed, 03 Jul 2019 20:42:37 +0800
Merge
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_INTERPRETERRUNTIME_HPP |
aoqi@0 | 32 | #define SHARE_VM_INTERPRETER_INTERPRETERRUNTIME_HPP |
aoqi@0 | 33 | |
aoqi@0 | 34 | #include "interpreter/bytecode.hpp" |
aoqi@0 | 35 | #include "interpreter/linkResolver.hpp" |
aoqi@0 | 36 | #include "memory/universe.hpp" |
aoqi@0 | 37 | #include "oops/method.hpp" |
aoqi@0 | 38 | #include "runtime/frame.inline.hpp" |
aoqi@0 | 39 | #include "runtime/signature.hpp" |
aoqi@0 | 40 | #include "runtime/thread.inline.hpp" |
aoqi@0 | 41 | #include "utilities/top.hpp" |
aoqi@0 | 42 | |
aoqi@0 | 43 | // The InterpreterRuntime is called by the interpreter for everything |
aoqi@0 | 44 | // that cannot/should not be dealt with in assembly and needs C support. |
aoqi@0 | 45 | |
aoqi@0 | 46 | class InterpreterRuntime: AllStatic { |
aoqi@0 | 47 | friend class BytecodeClosure; // for method and bcp |
aoqi@0 | 48 | friend class PrintingClosure; // for method and bcp |
aoqi@0 | 49 | |
aoqi@0 | 50 | private: |
aoqi@0 | 51 | // Helper functions to access current interpreter state |
aoqi@0 | 52 | static frame last_frame(JavaThread *thread) { return thread->last_frame(); } |
aoqi@0 | 53 | static Method* method(JavaThread *thread) { return last_frame(thread).interpreter_frame_method(); } |
aoqi@0 | 54 | static address bcp(JavaThread *thread) { return last_frame(thread).interpreter_frame_bcp(); } |
aoqi@0 | 55 | static int bci(JavaThread *thread) { return last_frame(thread).interpreter_frame_bci(); } |
aoqi@0 | 56 | static void set_bcp_and_mdp(address bcp, JavaThread*thread); |
aoqi@0 | 57 | static Bytecodes::Code code(JavaThread *thread) { |
aoqi@0 | 58 | // pass method to avoid calling unsafe bcp_to_method (partial fix 4926272) |
aoqi@0 | 59 | return Bytecodes::code_at(method(thread), bcp(thread)); |
aoqi@0 | 60 | } |
aoqi@0 | 61 | static bool already_resolved(JavaThread *thread) { return cache_entry(thread)->is_resolved(code(thread)); } |
aoqi@0 | 62 | static Bytecode bytecode(JavaThread *thread) { return Bytecode(method(thread), bcp(thread)); } |
aoqi@0 | 63 | static int get_index_u1(JavaThread *thread, Bytecodes::Code bc) |
aoqi@0 | 64 | { return bytecode(thread).get_index_u1(bc); } |
aoqi@0 | 65 | static int get_index_u2(JavaThread *thread, Bytecodes::Code bc) |
aoqi@0 | 66 | { return bytecode(thread).get_index_u2(bc); } |
aoqi@0 | 67 | static int get_index_u2_cpcache(JavaThread *thread, Bytecodes::Code bc) |
aoqi@0 | 68 | { return bytecode(thread).get_index_u2_cpcache(bc); } |
aoqi@0 | 69 | static int get_index_u4(JavaThread *thread, Bytecodes::Code bc) |
aoqi@0 | 70 | { return bytecode(thread).get_index_u4(bc); } |
aoqi@0 | 71 | static int number_of_dimensions(JavaThread *thread) { return bcp(thread)[3]; } |
aoqi@0 | 72 | |
aoqi@0 | 73 | static ConstantPoolCacheEntry* cache_entry_at(JavaThread *thread, int i) { return method(thread)->constants()->cache()->entry_at(i); } |
aoqi@0 | 74 | static ConstantPoolCacheEntry* cache_entry(JavaThread *thread) { return cache_entry_at(thread, Bytes::get_native_u2(bcp(thread) + 1)); } |
aoqi@0 | 75 | static void note_trap_inner(JavaThread* thread, int reason, |
aoqi@0 | 76 | methodHandle trap_method, int trap_bci, TRAPS); |
aoqi@0 | 77 | static void note_trap(JavaThread *thread, int reason, TRAPS); |
aoqi@0 | 78 | #ifdef CC_INTERP |
aoqi@0 | 79 | // Profile traps in C++ interpreter. |
aoqi@0 | 80 | static void note_trap(JavaThread* thread, int reason, Method *method, int trap_bci); |
aoqi@0 | 81 | #endif // CC_INTERP |
aoqi@0 | 82 | |
aoqi@0 | 83 | // Inner work method for Interpreter's frequency counter overflow. |
aoqi@0 | 84 | static nmethod* frequency_counter_overflow_inner(JavaThread* thread, address branch_bcp); |
aoqi@0 | 85 | |
aoqi@0 | 86 | public: |
aoqi@0 | 87 | // Constants |
aoqi@0 | 88 | static void ldc (JavaThread* thread, bool wide); |
aoqi@0 | 89 | static void resolve_ldc (JavaThread* thread, Bytecodes::Code bytecode); |
aoqi@0 | 90 | |
aoqi@0 | 91 | // Allocation |
aoqi@0 | 92 | static void _new (JavaThread* thread, ConstantPool* pool, int index); |
aoqi@0 | 93 | static void newarray (JavaThread* thread, BasicType type, jint size); |
aoqi@0 | 94 | static void anewarray (JavaThread* thread, ConstantPool* pool, int index, jint size); |
aoqi@0 | 95 | static void multianewarray(JavaThread* thread, jint* first_size_address); |
aoqi@0 | 96 | static void register_finalizer(JavaThread* thread, oopDesc* obj); |
aoqi@0 | 97 | |
aoqi@0 | 98 | // Quicken instance-of and check-cast bytecodes |
aoqi@0 | 99 | static void quicken_io_cc(JavaThread* thread); |
aoqi@0 | 100 | |
aoqi@0 | 101 | // Exceptions thrown by the interpreter |
aoqi@0 | 102 | static void throw_AbstractMethodError(JavaThread* thread); |
aoqi@0 | 103 | static void throw_IncompatibleClassChangeError(JavaThread* thread); |
aoqi@0 | 104 | static void throw_StackOverflowError(JavaThread* thread); |
aoqi@0 | 105 | static void throw_ArrayIndexOutOfBoundsException(JavaThread* thread, char* name, jint index); |
aoqi@0 | 106 | static void throw_ClassCastException(JavaThread* thread, oopDesc* obj); |
aoqi@0 | 107 | static void create_exception(JavaThread* thread, char* name, char* message); |
aoqi@0 | 108 | static void create_klass_exception(JavaThread* thread, char* name, oopDesc* obj); |
aoqi@0 | 109 | static address exception_handler_for_exception(JavaThread* thread, oopDesc* exception); |
aoqi@0 | 110 | #if INCLUDE_JVMTI |
aoqi@0 | 111 | static void member_name_arg_or_null(JavaThread* thread, address dmh, Method* m, address bcp); |
aoqi@0 | 112 | #endif |
aoqi@0 | 113 | static void throw_pending_exception(JavaThread* thread); |
aoqi@0 | 114 | |
aoqi@0 | 115 | #ifdef CC_INTERP |
aoqi@0 | 116 | // Profile traps in C++ interpreter. |
aoqi@0 | 117 | static void note_nullCheck_trap (JavaThread* thread, Method *method, int trap_bci); |
aoqi@0 | 118 | static void note_div0Check_trap (JavaThread* thread, Method *method, int trap_bci); |
aoqi@0 | 119 | static void note_rangeCheck_trap(JavaThread* thread, Method *method, int trap_bci); |
aoqi@0 | 120 | static void note_classCheck_trap(JavaThread* thread, Method *method, int trap_bci); |
aoqi@0 | 121 | static void note_arrayCheck_trap(JavaThread* thread, Method *method, int trap_bci); |
aoqi@0 | 122 | // A dummy for makros that shall not profile traps. |
aoqi@0 | 123 | static void note_no_trap(JavaThread* thread, Method *method, int trap_bci) {} |
aoqi@0 | 124 | #endif // CC_INTERP |
aoqi@0 | 125 | |
aoqi@0 | 126 | // Statics & fields |
aoqi@0 | 127 | static void resolve_get_put(JavaThread* thread, Bytecodes::Code bytecode); |
aoqi@0 | 128 | |
aoqi@0 | 129 | // Synchronization |
aoqi@0 | 130 | static void monitorenter(JavaThread* thread, BasicObjectLock* elem); |
aoqi@0 | 131 | static void monitorexit (JavaThread* thread, BasicObjectLock* elem); |
aoqi@0 | 132 | |
aoqi@0 | 133 | static void throw_illegal_monitor_state_exception(JavaThread* thread); |
aoqi@0 | 134 | static void new_illegal_monitor_state_exception(JavaThread* thread); |
aoqi@0 | 135 | |
aoqi@0 | 136 | // Calls |
aoqi@0 | 137 | static void resolve_invoke (JavaThread* thread, Bytecodes::Code bytecode); |
aoqi@0 | 138 | static void resolve_invokehandle (JavaThread* thread); |
aoqi@0 | 139 | static void resolve_invokedynamic(JavaThread* thread); |
aoqi@0 | 140 | |
aoqi@0 | 141 | // Breakpoints |
aoqi@0 | 142 | static void _breakpoint(JavaThread* thread, Method* method, address bcp); |
aoqi@0 | 143 | static Bytecodes::Code get_original_bytecode_at(JavaThread* thread, Method* method, address bcp); |
aoqi@0 | 144 | static void set_original_bytecode_at(JavaThread* thread, Method* method, address bcp, Bytecodes::Code new_code); |
aoqi@0 | 145 | static bool is_breakpoint(JavaThread *thread) { return Bytecodes::code_or_bp_at(bcp(thread)) == Bytecodes::_breakpoint; } |
aoqi@0 | 146 | |
aoqi@0 | 147 | // Safepoints |
aoqi@0 | 148 | static void at_safepoint(JavaThread* thread); |
aoqi@0 | 149 | |
aoqi@0 | 150 | // Debugger support |
aoqi@0 | 151 | static void post_field_access(JavaThread *thread, oopDesc* obj, |
aoqi@0 | 152 | ConstantPoolCacheEntry *cp_entry); |
aoqi@0 | 153 | static void post_field_modification(JavaThread *thread, oopDesc* obj, |
aoqi@0 | 154 | ConstantPoolCacheEntry *cp_entry, jvalue *value); |
aoqi@0 | 155 | static void post_method_entry(JavaThread *thread); |
aoqi@0 | 156 | static void post_method_exit (JavaThread *thread); |
aoqi@0 | 157 | static int interpreter_contains(address pc); |
aoqi@0 | 158 | |
aoqi@0 | 159 | // Native signature handlers |
aoqi@0 | 160 | static void prepare_native_call(JavaThread* thread, Method* method); |
aoqi@0 | 161 | static address slow_signature_handler(JavaThread* thread, |
aoqi@0 | 162 | Method* method, |
aoqi@0 | 163 | intptr_t* from, intptr_t* to); |
aoqi@0 | 164 | |
fujie@9138 | 165 | #if defined(IA32) || defined(AMD64) || defined(ARM) || defined(MIPS) |
aoqi@0 | 166 | // Popframe support (only needed on x86, AMD64 and ARM) |
aoqi@0 | 167 | static void popframe_move_outgoing_args(JavaThread* thread, void* src_address, void* dest_address); |
aoqi@0 | 168 | #endif |
aoqi@0 | 169 | |
aoqi@0 | 170 | // Platform dependent stuff |
aoqi@0 | 171 | #ifdef TARGET_ARCH_x86 |
aoqi@0 | 172 | # include "interpreterRT_x86.hpp" |
aoqi@0 | 173 | #endif |
aoqi@1 | 174 | #ifdef TARGET_ARCH_mips |
aoqi@1 | 175 | # include "interpreterRT_mips.hpp" |
aoqi@1 | 176 | #endif |
aoqi@0 | 177 | #ifdef TARGET_ARCH_sparc |
aoqi@0 | 178 | # include "interpreterRT_sparc.hpp" |
aoqi@0 | 179 | #endif |
aoqi@0 | 180 | #ifdef TARGET_ARCH_zero |
aoqi@0 | 181 | # include "interpreterRT_zero.hpp" |
aoqi@0 | 182 | #endif |
aoqi@0 | 183 | #ifdef TARGET_ARCH_arm |
aoqi@0 | 184 | # include "interpreterRT_arm.hpp" |
aoqi@0 | 185 | #endif |
aoqi@0 | 186 | #ifdef TARGET_ARCH_ppc |
aoqi@0 | 187 | # include "interpreterRT_ppc.hpp" |
aoqi@0 | 188 | #endif |
aoqi@0 | 189 | |
aoqi@0 | 190 | |
aoqi@0 | 191 | // Interpreter's frequency counter overflow |
aoqi@0 | 192 | static nmethod* frequency_counter_overflow(JavaThread* thread, address branch_bcp); |
aoqi@0 | 193 | |
aoqi@0 | 194 | // Interpreter profiling support |
aoqi@0 | 195 | static jint bcp_to_di(Method* method, address cur_bcp); |
aoqi@0 | 196 | static void profile_method(JavaThread* thread); |
aoqi@0 | 197 | static void update_mdp_for_ret(JavaThread* thread, int bci); |
aoqi@0 | 198 | #ifdef ASSERT |
aoqi@0 | 199 | static void verify_mdp(Method* method, address bcp, address mdp); |
aoqi@0 | 200 | #endif // ASSERT |
aoqi@0 | 201 | static MethodCounters* build_method_counters(JavaThread* thread, Method* m); |
aoqi@0 | 202 | }; |
aoqi@0 | 203 | |
aoqi@0 | 204 | |
aoqi@0 | 205 | class SignatureHandlerLibrary: public AllStatic { |
aoqi@0 | 206 | public: |
aoqi@0 | 207 | enum { buffer_size = 1*K }; // the size of the temporary code buffer |
aoqi@0 | 208 | enum { blob_size = 32*K }; // the size of a handler code blob. |
aoqi@0 | 209 | |
aoqi@0 | 210 | private: |
aoqi@0 | 211 | static BufferBlob* _handler_blob; // the current buffer blob containing the generated handlers |
aoqi@0 | 212 | static address _handler; // next available address within _handler_blob; |
aoqi@0 | 213 | static GrowableArray<uint64_t>* _fingerprints; // the fingerprint collection |
aoqi@0 | 214 | static GrowableArray<address>* _handlers; // the corresponding handlers |
aoqi@0 | 215 | static address _buffer; // the temporary code buffer |
aoqi@0 | 216 | |
aoqi@0 | 217 | static address set_handler_blob(); |
aoqi@0 | 218 | static void initialize(); |
aoqi@0 | 219 | static address set_handler(CodeBuffer* buffer); |
aoqi@0 | 220 | static void pd_set_handler(address handler); |
aoqi@0 | 221 | |
aoqi@0 | 222 | public: |
aoqi@0 | 223 | static void add(methodHandle method); |
aoqi@0 | 224 | }; |
aoqi@0 | 225 | |
aoqi@0 | 226 | #endif // SHARE_VM_INTERPRETER_INTERPRETERRUNTIME_HPP |