interpreterRuntime.hpp revision 3864:f34d701e952e
1219820Sjeff/* 2219820Sjeff * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. 3219820Sjeff * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4219820Sjeff * 5219820Sjeff * This code is free software; you can redistribute it and/or modify it 6219820Sjeff * under the terms of the GNU General Public License version 2 only, as 7219820Sjeff * published by the Free Software Foundation. 8219820Sjeff * 9219820Sjeff * This code is distributed in the hope that it will be useful, but WITHOUT 10219820Sjeff * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11219820Sjeff * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12219820Sjeff * version 2 for more details (a copy is included in the LICENSE file that 13219820Sjeff * accompanied this code). 14219820Sjeff * 15219820Sjeff * You should have received a copy of the GNU General Public License version 16219820Sjeff * 2 along with this work; if not, write to the Free Software Foundation, 17219820Sjeff * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18219820Sjeff * 19219820Sjeff * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20219820Sjeff * or visit www.oracle.com if you need additional information or have any 21219820Sjeff * questions. 22219820Sjeff * 23219820Sjeff */ 24219820Sjeff 25219820Sjeff#ifndef SHARE_VM_INTERPRETER_INTERPRETERRUNTIME_HPP 26219820Sjeff#define SHARE_VM_INTERPRETER_INTERPRETERRUNTIME_HPP 27219820Sjeff 28219820Sjeff#include "interpreter/bytecode.hpp" 29219820Sjeff#include "interpreter/linkResolver.hpp" 30219820Sjeff#include "memory/universe.hpp" 31219820Sjeff#include "oops/method.hpp" 32219820Sjeff#include "runtime/frame.inline.hpp" 33219820Sjeff#include "runtime/signature.hpp" 34219820Sjeff#include "runtime/thread.inline.hpp" 35219820Sjeff#include "utilities/top.hpp" 36219820Sjeff 37219820Sjeff// The InterpreterRuntime is called by the interpreter for everything 38219820Sjeff// that cannot/should not be dealt with in assembly and needs C support. 39219820Sjeff 40219820Sjeffclass InterpreterRuntime: AllStatic { 41219820Sjeff friend class BytecodeClosure; // for method and bcp 42219820Sjeff friend class PrintingClosure; // for method and bcp 43219820Sjeff 44219820Sjeff private: 45219820Sjeff // Helper functions to access current interpreter state 46219820Sjeff static frame last_frame(JavaThread *thread) { return thread->last_frame(); } 47219820Sjeff static Method* method(JavaThread *thread) { return last_frame(thread).interpreter_frame_method(); } 48219820Sjeff static address bcp(JavaThread *thread) { return last_frame(thread).interpreter_frame_bcp(); } 49219820Sjeff static int bci(JavaThread *thread) { return last_frame(thread).interpreter_frame_bci(); } 50219820Sjeff static void set_bcp_and_mdp(address bcp, JavaThread*thread); 51219820Sjeff static Bytecodes::Code code(JavaThread *thread) { 52219820Sjeff // pass method to avoid calling unsafe bcp_to_method (partial fix 4926272) 53219820Sjeff return Bytecodes::code_at(method(thread), bcp(thread)); 54219820Sjeff } 55219820Sjeff static bool already_resolved(JavaThread *thread) { return cache_entry(thread)->is_resolved(code(thread)); } 56219820Sjeff static Bytecode bytecode(JavaThread *thread) { return Bytecode(method(thread), bcp(thread)); } 57219820Sjeff static int get_index_u1(JavaThread *thread, Bytecodes::Code bc) 58219820Sjeff { return bytecode(thread).get_index_u1(bc); } 59219820Sjeff static int get_index_u2(JavaThread *thread, Bytecodes::Code bc) 60219820Sjeff { return bytecode(thread).get_index_u2(bc); } 61219820Sjeff static int get_index_u2_cpcache(JavaThread *thread, Bytecodes::Code bc) 62219820Sjeff { return bytecode(thread).get_index_u2_cpcache(bc); } 63219820Sjeff static int get_index_u4(JavaThread *thread, Bytecodes::Code bc) 64219820Sjeff { return bytecode(thread).get_index_u4(bc); } 65219820Sjeff static int number_of_dimensions(JavaThread *thread) { return bcp(thread)[3]; } 66219820Sjeff 67219820Sjeff static ConstantPoolCacheEntry* cache_entry_at(JavaThread *thread, int i) { return method(thread)->constants()->cache()->entry_at(i); } 68219820Sjeff static ConstantPoolCacheEntry* cache_entry(JavaThread *thread) { return cache_entry_at(thread, Bytes::get_native_u2(bcp(thread) + 1)); } 69219820Sjeff static void note_trap(JavaThread *thread, int reason, TRAPS); 70219820Sjeff 71219820Sjeff // Inner work method for Interpreter's frequency counter overflow 72219820Sjeff static nmethod* frequency_counter_overflow_inner(JavaThread* thread, address branch_bcp); 73219820Sjeff 74219820Sjeff public: 75219820Sjeff // Constants 76219820Sjeff static void ldc (JavaThread* thread, bool wide); 77219820Sjeff static void resolve_ldc (JavaThread* thread, Bytecodes::Code bytecode); 78219820Sjeff 79219820Sjeff // Allocation 80219820Sjeff static void _new (JavaThread* thread, ConstantPool* pool, int index); 81219820Sjeff static void newarray (JavaThread* thread, BasicType type, jint size); 82219820Sjeff static void anewarray (JavaThread* thread, ConstantPool* pool, int index, jint size); 83219820Sjeff static void multianewarray(JavaThread* thread, jint* first_size_address); 84219820Sjeff static void register_finalizer(JavaThread* thread, oopDesc* obj); 85219820Sjeff 86219820Sjeff // Quicken instance-of and check-cast bytecodes 87219820Sjeff static void quicken_io_cc(JavaThread* thread); 88219820Sjeff 89219820Sjeff // Exceptions thrown by the interpreter 90219820Sjeff static void throw_AbstractMethodError(JavaThread* thread); 91219820Sjeff static void throw_IncompatibleClassChangeError(JavaThread* thread); 92219820Sjeff static void throw_StackOverflowError(JavaThread* thread); 93219820Sjeff static void throw_ArrayIndexOutOfBoundsException(JavaThread* thread, char* name, jint index); 94219820Sjeff static void throw_ClassCastException(JavaThread* thread, oopDesc* obj); 95219820Sjeff static void create_exception(JavaThread* thread, char* name, char* message); 96219820Sjeff static void create_klass_exception(JavaThread* thread, char* name, oopDesc* obj); 97219820Sjeff static address exception_handler_for_exception(JavaThread* thread, oopDesc* exception); 98219820Sjeff static void throw_pending_exception(JavaThread* thread); 99219820Sjeff 100219820Sjeff // Statics & fields 101219820Sjeff static void resolve_get_put(JavaThread* thread, Bytecodes::Code bytecode); 102219820Sjeff 103219820Sjeff // Synchronization 104219820Sjeff static void monitorenter(JavaThread* thread, BasicObjectLock* elem); 105219820Sjeff static void monitorexit (JavaThread* thread, BasicObjectLock* elem); 106219820Sjeff 107219820Sjeff static void throw_illegal_monitor_state_exception(JavaThread* thread); 108219820Sjeff static void new_illegal_monitor_state_exception(JavaThread* thread); 109219820Sjeff 110219820Sjeff // Calls 111219820Sjeff static void resolve_invoke (JavaThread* thread, Bytecodes::Code bytecode); 112219820Sjeff static void resolve_invokehandle (JavaThread* thread); 113219820Sjeff static void resolve_invokedynamic(JavaThread* thread); 114219820Sjeff 115219820Sjeff // Breakpoints 116219820Sjeff static void _breakpoint(JavaThread* thread, Method* method, address bcp); 117219820Sjeff static Bytecodes::Code get_original_bytecode_at(JavaThread* thread, Method* method, address bcp); 118219820Sjeff static void set_original_bytecode_at(JavaThread* thread, Method* method, address bcp, Bytecodes::Code new_code); 119219820Sjeff static bool is_breakpoint(JavaThread *thread) { return Bytecodes::code_or_bp_at(bcp(thread)) == Bytecodes::_breakpoint; } 120219820Sjeff 121219820Sjeff // Safepoints 122219820Sjeff static void at_safepoint(JavaThread* thread); 123219820Sjeff 124219820Sjeff // Debugger support 125219820Sjeff static void post_field_access(JavaThread *thread, oopDesc* obj, 126219820Sjeff ConstantPoolCacheEntry *cp_entry); 127219820Sjeff static void post_field_modification(JavaThread *thread, oopDesc* obj, 128219820Sjeff ConstantPoolCacheEntry *cp_entry, jvalue *value); 129219820Sjeff static void post_method_entry(JavaThread *thread); 130219820Sjeff static void post_method_exit (JavaThread *thread); 131219820Sjeff static int interpreter_contains(address pc); 132219820Sjeff 133219820Sjeff // Native signature handlers 134219820Sjeff static void prepare_native_call(JavaThread* thread, Method* method); 135219820Sjeff static address slow_signature_handler(JavaThread* thread, 136219820Sjeff Method* method, 137219820Sjeff intptr_t* from, intptr_t* to); 138219820Sjeff 139219820Sjeff#if defined(IA32) || defined(AMD64) || defined(ARM) 140219820Sjeff // Popframe support (only needed on x86, AMD64 and ARM) 141219820Sjeff static void popframe_move_outgoing_args(JavaThread* thread, void* src_address, void* dest_address); 142219820Sjeff#endif 143219820Sjeff 144219820Sjeff // Platform dependent stuff 145219820Sjeff#ifdef TARGET_ARCH_x86 146219820Sjeff# include "interpreterRT_x86.hpp" 147219820Sjeff#endif 148219820Sjeff#ifdef TARGET_ARCH_sparc 149219820Sjeff# include "interpreterRT_sparc.hpp" 150219820Sjeff#endif 151219820Sjeff#ifdef TARGET_ARCH_zero 152219820Sjeff# include "interpreterRT_zero.hpp" 153219820Sjeff#endif 154219820Sjeff#ifdef TARGET_ARCH_arm 155219820Sjeff# include "interpreterRT_arm.hpp" 156219820Sjeff#endif 157219820Sjeff#ifdef TARGET_ARCH_ppc 158219820Sjeff# include "interpreterRT_ppc.hpp" 159219820Sjeff#endif 160219820Sjeff 161219820Sjeff 162219820Sjeff // Interpreter's frequency counter overflow 163219820Sjeff static nmethod* frequency_counter_overflow(JavaThread* thread, address branch_bcp); 164219820Sjeff 165219820Sjeff // Interpreter profiling support 166219820Sjeff static jint bcp_to_di(Method* method, address cur_bcp); 167219820Sjeff static void profile_method(JavaThread* thread); 168219820Sjeff static void update_mdp_for_ret(JavaThread* thread, int bci); 169219820Sjeff#ifdef ASSERT 170219820Sjeff static void verify_mdp(Method* method, address bcp, address mdp); 171219820Sjeff#endif // ASSERT 172219820Sjeff}; 173219820Sjeff 174219820Sjeff 175219820Sjeffclass SignatureHandlerLibrary: public AllStatic { 176219820Sjeff public: 177219820Sjeff enum { buffer_size = 1*K }; // the size of the temporary code buffer 178219820Sjeff enum { blob_size = 32*K }; // the size of a handler code blob. 179219820Sjeff 180219820Sjeff private: 181219820Sjeff static BufferBlob* _handler_blob; // the current buffer blob containing the generated handlers 182219820Sjeff static address _handler; // next available address within _handler_blob; 183219820Sjeff static GrowableArray<uint64_t>* _fingerprints; // the fingerprint collection 184219820Sjeff static GrowableArray<address>* _handlers; // the corresponding handlers 185219820Sjeff static address _buffer; // the temporary code buffer 186219820Sjeff 187219820Sjeff static address set_handler_blob(); 188219820Sjeff static void initialize(); 189219820Sjeff static address set_handler(CodeBuffer* buffer); 190219820Sjeff static void pd_set_handler(address handler); 191219820Sjeff 192219820Sjeff public: 193219820Sjeff static void add(methodHandle method); 194219820Sjeff}; 195219820Sjeff 196219820Sjeff#endif // SHARE_VM_INTERPRETER_INTERPRETERRUNTIME_HPP 197219820Sjeff