1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/vm/interpreter/interpreterRuntime.hpp Wed Apr 27 01:25:04 2016 +0800 1.3 @@ -0,0 +1,217 @@ 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_INTERPRETERRUNTIME_HPP 1.29 +#define SHARE_VM_INTERPRETER_INTERPRETERRUNTIME_HPP 1.30 + 1.31 +#include "interpreter/bytecode.hpp" 1.32 +#include "interpreter/linkResolver.hpp" 1.33 +#include "memory/universe.hpp" 1.34 +#include "oops/method.hpp" 1.35 +#include "runtime/frame.inline.hpp" 1.36 +#include "runtime/signature.hpp" 1.37 +#include "runtime/thread.inline.hpp" 1.38 +#include "utilities/top.hpp" 1.39 + 1.40 +// The InterpreterRuntime is called by the interpreter for everything 1.41 +// that cannot/should not be dealt with in assembly and needs C support. 1.42 + 1.43 +class InterpreterRuntime: AllStatic { 1.44 + friend class BytecodeClosure; // for method and bcp 1.45 + friend class PrintingClosure; // for method and bcp 1.46 + 1.47 + private: 1.48 + // Helper functions to access current interpreter state 1.49 + static frame last_frame(JavaThread *thread) { return thread->last_frame(); } 1.50 + static Method* method(JavaThread *thread) { return last_frame(thread).interpreter_frame_method(); } 1.51 + static address bcp(JavaThread *thread) { return last_frame(thread).interpreter_frame_bcp(); } 1.52 + static int bci(JavaThread *thread) { return last_frame(thread).interpreter_frame_bci(); } 1.53 + static void set_bcp_and_mdp(address bcp, JavaThread*thread); 1.54 + static Bytecodes::Code code(JavaThread *thread) { 1.55 + // pass method to avoid calling unsafe bcp_to_method (partial fix 4926272) 1.56 + return Bytecodes::code_at(method(thread), bcp(thread)); 1.57 + } 1.58 + static bool already_resolved(JavaThread *thread) { return cache_entry(thread)->is_resolved(code(thread)); } 1.59 + static Bytecode bytecode(JavaThread *thread) { return Bytecode(method(thread), bcp(thread)); } 1.60 + static int get_index_u1(JavaThread *thread, Bytecodes::Code bc) 1.61 + { return bytecode(thread).get_index_u1(bc); } 1.62 + static int get_index_u2(JavaThread *thread, Bytecodes::Code bc) 1.63 + { return bytecode(thread).get_index_u2(bc); } 1.64 + static int get_index_u2_cpcache(JavaThread *thread, Bytecodes::Code bc) 1.65 + { return bytecode(thread).get_index_u2_cpcache(bc); } 1.66 + static int get_index_u4(JavaThread *thread, Bytecodes::Code bc) 1.67 + { return bytecode(thread).get_index_u4(bc); } 1.68 + static int number_of_dimensions(JavaThread *thread) { return bcp(thread)[3]; } 1.69 + 1.70 + static ConstantPoolCacheEntry* cache_entry_at(JavaThread *thread, int i) { return method(thread)->constants()->cache()->entry_at(i); } 1.71 + static ConstantPoolCacheEntry* cache_entry(JavaThread *thread) { return cache_entry_at(thread, Bytes::get_native_u2(bcp(thread) + 1)); } 1.72 + static void note_trap_inner(JavaThread* thread, int reason, 1.73 + methodHandle trap_method, int trap_bci, TRAPS); 1.74 + static void note_trap(JavaThread *thread, int reason, TRAPS); 1.75 +#ifdef CC_INTERP 1.76 + // Profile traps in C++ interpreter. 1.77 + static void note_trap(JavaThread* thread, int reason, Method *method, int trap_bci); 1.78 +#endif // CC_INTERP 1.79 + 1.80 + // Inner work method for Interpreter's frequency counter overflow. 1.81 + static nmethod* frequency_counter_overflow_inner(JavaThread* thread, address branch_bcp); 1.82 + 1.83 + public: 1.84 + // Constants 1.85 + static void ldc (JavaThread* thread, bool wide); 1.86 + static void resolve_ldc (JavaThread* thread, Bytecodes::Code bytecode); 1.87 + 1.88 + // Allocation 1.89 + static void _new (JavaThread* thread, ConstantPool* pool, int index); 1.90 + static void newarray (JavaThread* thread, BasicType type, jint size); 1.91 + static void anewarray (JavaThread* thread, ConstantPool* pool, int index, jint size); 1.92 + static void multianewarray(JavaThread* thread, jint* first_size_address); 1.93 + static void register_finalizer(JavaThread* thread, oopDesc* obj); 1.94 + 1.95 + // Quicken instance-of and check-cast bytecodes 1.96 + static void quicken_io_cc(JavaThread* thread); 1.97 + 1.98 + // Exceptions thrown by the interpreter 1.99 + static void throw_AbstractMethodError(JavaThread* thread); 1.100 + static void throw_IncompatibleClassChangeError(JavaThread* thread); 1.101 + static void throw_StackOverflowError(JavaThread* thread); 1.102 + static void throw_ArrayIndexOutOfBoundsException(JavaThread* thread, char* name, jint index); 1.103 + static void throw_ClassCastException(JavaThread* thread, oopDesc* obj); 1.104 + static void create_exception(JavaThread* thread, char* name, char* message); 1.105 + static void create_klass_exception(JavaThread* thread, char* name, oopDesc* obj); 1.106 + static address exception_handler_for_exception(JavaThread* thread, oopDesc* exception); 1.107 +#if INCLUDE_JVMTI 1.108 + static void member_name_arg_or_null(JavaThread* thread, address dmh, Method* m, address bcp); 1.109 +#endif 1.110 + static void throw_pending_exception(JavaThread* thread); 1.111 + 1.112 +#ifdef CC_INTERP 1.113 + // Profile traps in C++ interpreter. 1.114 + static void note_nullCheck_trap (JavaThread* thread, Method *method, int trap_bci); 1.115 + static void note_div0Check_trap (JavaThread* thread, Method *method, int trap_bci); 1.116 + static void note_rangeCheck_trap(JavaThread* thread, Method *method, int trap_bci); 1.117 + static void note_classCheck_trap(JavaThread* thread, Method *method, int trap_bci); 1.118 + static void note_arrayCheck_trap(JavaThread* thread, Method *method, int trap_bci); 1.119 + // A dummy for makros that shall not profile traps. 1.120 + static void note_no_trap(JavaThread* thread, Method *method, int trap_bci) {} 1.121 +#endif // CC_INTERP 1.122 + 1.123 + // Statics & fields 1.124 + static void resolve_get_put(JavaThread* thread, Bytecodes::Code bytecode); 1.125 + 1.126 + // Synchronization 1.127 + static void monitorenter(JavaThread* thread, BasicObjectLock* elem); 1.128 + static void monitorexit (JavaThread* thread, BasicObjectLock* elem); 1.129 + 1.130 + static void throw_illegal_monitor_state_exception(JavaThread* thread); 1.131 + static void new_illegal_monitor_state_exception(JavaThread* thread); 1.132 + 1.133 + // Calls 1.134 + static void resolve_invoke (JavaThread* thread, Bytecodes::Code bytecode); 1.135 + static void resolve_invokehandle (JavaThread* thread); 1.136 + static void resolve_invokedynamic(JavaThread* thread); 1.137 + 1.138 + // Breakpoints 1.139 + static void _breakpoint(JavaThread* thread, Method* method, address bcp); 1.140 + static Bytecodes::Code get_original_bytecode_at(JavaThread* thread, Method* method, address bcp); 1.141 + static void set_original_bytecode_at(JavaThread* thread, Method* method, address bcp, Bytecodes::Code new_code); 1.142 + static bool is_breakpoint(JavaThread *thread) { return Bytecodes::code_or_bp_at(bcp(thread)) == Bytecodes::_breakpoint; } 1.143 + 1.144 + // Safepoints 1.145 + static void at_safepoint(JavaThread* thread); 1.146 + 1.147 + // Debugger support 1.148 + static void post_field_access(JavaThread *thread, oopDesc* obj, 1.149 + ConstantPoolCacheEntry *cp_entry); 1.150 + static void post_field_modification(JavaThread *thread, oopDesc* obj, 1.151 + ConstantPoolCacheEntry *cp_entry, jvalue *value); 1.152 + static void post_method_entry(JavaThread *thread); 1.153 + static void post_method_exit (JavaThread *thread); 1.154 + static int interpreter_contains(address pc); 1.155 + 1.156 + // Native signature handlers 1.157 + static void prepare_native_call(JavaThread* thread, Method* method); 1.158 + static address slow_signature_handler(JavaThread* thread, 1.159 + Method* method, 1.160 + intptr_t* from, intptr_t* to); 1.161 + 1.162 +#if defined(IA32) || defined(AMD64) || defined(ARM) 1.163 + // Popframe support (only needed on x86, AMD64 and ARM) 1.164 + static void popframe_move_outgoing_args(JavaThread* thread, void* src_address, void* dest_address); 1.165 +#endif 1.166 + 1.167 + // Platform dependent stuff 1.168 +#ifdef TARGET_ARCH_x86 1.169 +# include "interpreterRT_x86.hpp" 1.170 +#endif 1.171 +#ifdef TARGET_ARCH_sparc 1.172 +# include "interpreterRT_sparc.hpp" 1.173 +#endif 1.174 +#ifdef TARGET_ARCH_zero 1.175 +# include "interpreterRT_zero.hpp" 1.176 +#endif 1.177 +#ifdef TARGET_ARCH_arm 1.178 +# include "interpreterRT_arm.hpp" 1.179 +#endif 1.180 +#ifdef TARGET_ARCH_ppc 1.181 +# include "interpreterRT_ppc.hpp" 1.182 +#endif 1.183 + 1.184 + 1.185 + // Interpreter's frequency counter overflow 1.186 + static nmethod* frequency_counter_overflow(JavaThread* thread, address branch_bcp); 1.187 + 1.188 + // Interpreter profiling support 1.189 + static jint bcp_to_di(Method* method, address cur_bcp); 1.190 + static void profile_method(JavaThread* thread); 1.191 + static void update_mdp_for_ret(JavaThread* thread, int bci); 1.192 +#ifdef ASSERT 1.193 + static void verify_mdp(Method* method, address bcp, address mdp); 1.194 +#endif // ASSERT 1.195 + static MethodCounters* build_method_counters(JavaThread* thread, Method* m); 1.196 +}; 1.197 + 1.198 + 1.199 +class SignatureHandlerLibrary: public AllStatic { 1.200 + public: 1.201 + enum { buffer_size = 1*K }; // the size of the temporary code buffer 1.202 + enum { blob_size = 32*K }; // the size of a handler code blob. 1.203 + 1.204 + private: 1.205 + static BufferBlob* _handler_blob; // the current buffer blob containing the generated handlers 1.206 + static address _handler; // next available address within _handler_blob; 1.207 + static GrowableArray<uint64_t>* _fingerprints; // the fingerprint collection 1.208 + static GrowableArray<address>* _handlers; // the corresponding handlers 1.209 + static address _buffer; // the temporary code buffer 1.210 + 1.211 + static address set_handler_blob(); 1.212 + static void initialize(); 1.213 + static address set_handler(CodeBuffer* buffer); 1.214 + static void pd_set_handler(address handler); 1.215 + 1.216 + public: 1.217 + static void add(methodHandle method); 1.218 +}; 1.219 + 1.220 +#endif // SHARE_VM_INTERPRETER_INTERPRETERRUNTIME_HPP