duke@435: /* duke@435: * Copyright 1999-2007 Sun Microsystems, Inc. All Rights Reserved. duke@435: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@435: * duke@435: * This code is free software; you can redistribute it and/or modify it duke@435: * under the terms of the GNU General Public License version 2 only, as duke@435: * published by the Free Software Foundation. duke@435: * duke@435: * This code is distributed in the hope that it will be useful, but WITHOUT duke@435: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@435: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@435: * version 2 for more details (a copy is included in the LICENSE file that duke@435: * accompanied this code). duke@435: * duke@435: * You should have received a copy of the GNU General Public License version duke@435: * 2 along with this work; if not, write to the Free Software Foundation, duke@435: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@435: * duke@435: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, duke@435: * CA 95054 USA or visit www.sun.com if you need additional information or duke@435: * have any questions. duke@435: * duke@435: */ duke@435: duke@435: class StubAssembler; duke@435: duke@435: // The Runtime1 holds all assembly stubs and VM duke@435: // runtime routines needed by code code generated duke@435: // by the Compiler1. duke@435: duke@435: #define RUNTIME1_STUBS(stub, last_entry) \ duke@435: stub(dtrace_object_alloc) \ duke@435: stub(unwind_exception) \ duke@435: stub(forward_exception) \ duke@435: stub(throw_range_check_failed) /* throws ArrayIndexOutOfBoundsException */ \ duke@435: stub(throw_index_exception) /* throws IndexOutOfBoundsException */ \ duke@435: stub(throw_div0_exception) \ duke@435: stub(throw_null_pointer_exception) \ duke@435: stub(register_finalizer) \ duke@435: stub(new_instance) \ duke@435: stub(fast_new_instance) \ duke@435: stub(fast_new_instance_init_check) \ duke@435: stub(new_type_array) \ duke@435: stub(new_object_array) \ duke@435: stub(new_multi_array) \ duke@435: stub(handle_exception_nofpu) /* optimized version that does not preserve fpu registers */ \ duke@435: stub(handle_exception) \ duke@435: stub(throw_array_store_exception) \ duke@435: stub(throw_class_cast_exception) \ duke@435: stub(throw_incompatible_class_change_error) \ duke@435: stub(slow_subtype_check) \ duke@435: stub(monitorenter) \ duke@435: stub(monitorenter_nofpu) /* optimized version that does not preserve fpu registers */ \ duke@435: stub(monitorexit) \ duke@435: stub(monitorexit_nofpu) /* optimized version that does not preserve fpu registers */ \ duke@435: stub(access_field_patching) \ duke@435: stub(load_klass_patching) \ duke@435: stub(jvmti_exception_throw) \ duke@435: stub(fpu2long_stub) \ duke@435: stub(counter_overflow) \ duke@435: last_entry(number_of_ids) duke@435: duke@435: #define DECLARE_STUB_ID(x) x ## _id , duke@435: #define DECLARE_LAST_STUB_ID(x) x duke@435: #define STUB_NAME(x) #x " Runtime1 stub", duke@435: #define LAST_STUB_NAME(x) #x " Runtime1 stub" duke@435: duke@435: class Runtime1: public AllStatic { duke@435: friend class VMStructs; duke@435: friend class ArrayCopyStub; duke@435: private: duke@435: static int desired_max_code_buffer_size() { duke@435: return (int) NMethodSizeLimit; // default 256K or 512K duke@435: } duke@435: static int desired_max_constant_size() { duke@435: return (int) NMethodSizeLimit / 10; // about 25K duke@435: } duke@435: duke@435: // Note: This buffers is allocated once at startup since allocation duke@435: // for each compilation seems to be too expensive (at least on Intel duke@435: // win32). duke@435: static BufferBlob* _buffer_blob; duke@435: duke@435: public: duke@435: enum StubID { duke@435: RUNTIME1_STUBS(DECLARE_STUB_ID, DECLARE_LAST_STUB_ID) duke@435: }; duke@435: duke@435: // statistics duke@435: #ifndef PRODUCT duke@435: static int _resolve_invoke_cnt; duke@435: static int _handle_wrong_method_cnt; duke@435: static int _ic_miss_cnt; duke@435: static int _generic_arraycopy_cnt; duke@435: static int _primitive_arraycopy_cnt; duke@435: static int _oop_arraycopy_cnt; duke@435: static int _arraycopy_slowcase_cnt; duke@435: static int _new_type_array_slowcase_cnt; duke@435: static int _new_object_array_slowcase_cnt; duke@435: static int _new_instance_slowcase_cnt; duke@435: static int _new_multi_array_slowcase_cnt; duke@435: static int _monitorenter_slowcase_cnt; duke@435: static int _monitorexit_slowcase_cnt; duke@435: static int _patch_code_slowcase_cnt; duke@435: static int _throw_range_check_exception_count; duke@435: static int _throw_index_exception_count; duke@435: static int _throw_div0_exception_count; duke@435: static int _throw_null_pointer_exception_count; duke@435: static int _throw_class_cast_exception_count; duke@435: static int _throw_incompatible_class_change_error_count; duke@435: static int _throw_array_store_exception_count; duke@435: static int _throw_count; duke@435: #endif duke@435: duke@435: private: duke@435: static bool _is_initialized; duke@435: static CodeBlob* _blobs[number_of_ids]; duke@435: static const char* _blob_names[]; duke@435: duke@435: // stub generation duke@435: static void generate_blob_for(StubID id); duke@435: static OopMapSet* generate_code_for(StubID id, StubAssembler* masm); duke@435: static OopMapSet* generate_exception_throw(StubAssembler* sasm, address target, bool has_argument); duke@435: static void generate_handle_exception(StubAssembler *sasm, OopMapSet* oop_maps, OopMap* oop_map, bool ignore_fpu_registers = false); duke@435: static void generate_unwind_exception(StubAssembler *sasm); duke@435: static OopMapSet* generate_patching(StubAssembler* sasm, address target); duke@435: duke@435: static OopMapSet* generate_stub_call(StubAssembler* sasm, Register result, address entry, duke@435: Register arg1 = noreg, Register arg2 = noreg, Register arg3 = noreg); duke@435: duke@435: // runtime entry points duke@435: static void new_instance (JavaThread* thread, klassOopDesc* klass); duke@435: static void new_type_array (JavaThread* thread, klassOopDesc* klass, jint length); duke@435: static void new_object_array(JavaThread* thread, klassOopDesc* klass, jint length); duke@435: static void new_multi_array (JavaThread* thread, klassOopDesc* klass, int rank, jint* dims); duke@435: duke@435: #ifdef TIERED duke@435: static void counter_overflow(JavaThread* thread, int bci); duke@435: #endif // TIERED duke@435: duke@435: static void unimplemented_entry (JavaThread* thread, StubID id); duke@435: duke@435: static address exception_handler_for_pc(JavaThread* thread); duke@435: static void post_jvmti_exception_throw(JavaThread* thread); duke@435: duke@435: static void throw_range_check_exception(JavaThread* thread, int index); duke@435: static void throw_index_exception(JavaThread* thread, int index); duke@435: static void throw_div0_exception(JavaThread* thread); duke@435: static void throw_null_pointer_exception(JavaThread* thread); duke@435: static void throw_class_cast_exception(JavaThread* thread, oopDesc* obect); duke@435: static void throw_incompatible_class_change_error(JavaThread* thread); duke@435: static void throw_array_store_exception(JavaThread* thread); duke@435: duke@435: static void monitorenter(JavaThread* thread, oopDesc* obj, BasicObjectLock* lock); duke@435: static void monitorexit (JavaThread* thread, BasicObjectLock* lock); duke@435: duke@435: static int access_field_patching(JavaThread* thread); duke@435: static int move_klass_patching(JavaThread* thread); duke@435: duke@435: static void patch_code(JavaThread* thread, StubID stub_id); duke@435: duke@435: public: duke@435: static BufferBlob* get_buffer_blob(); duke@435: static void setup_code_buffer(CodeBuffer* cb, int call_stub_estimate); duke@435: duke@435: // initialization duke@435: static bool is_initialized() { return _is_initialized; } duke@435: static void initialize(); duke@435: static void initialize_pd(); duke@435: duke@435: // stubs duke@435: static CodeBlob* blob_for (StubID id); duke@435: static address entry_for(StubID id) { return blob_for(id)->instructions_begin(); } duke@435: static const char* name_for (StubID id); duke@435: static const char* name_for_address(address entry); duke@435: duke@435: // method tracing duke@435: static void trace_block_entry(jint block_id); duke@435: duke@435: #ifndef PRODUCT duke@435: static address throw_count_address() { return (address)&_throw_count; } duke@435: #endif duke@435: duke@435: // directly accessible leaf routine duke@435: static int arraycopy(oopDesc* src, int src_pos, oopDesc* dst, int dst_pos, int length); duke@435: static void primitive_arraycopy(HeapWord* src, HeapWord* dst, int length); duke@435: static void oop_arraycopy(HeapWord* src, HeapWord* dst, int length); duke@435: duke@435: static void print_statistics() PRODUCT_RETURN; duke@435: };