duke@435: /* stefank@2314: * Copyright (c) 1997, 2010, Oracle and/or its affiliates. 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: * trims@1907: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA trims@1907: * or visit www.oracle.com if you need additional information or have any trims@1907: * questions. duke@435: * duke@435: */ duke@435: stefank@2314: #ifndef SHARE_VM_CODE_VTABLESTUBS_HPP stefank@2314: #define SHARE_VM_CODE_VTABLESTUBS_HPP stefank@2314: stefank@2325: #include "code/vmreg.hpp" stefank@2314: #include "memory/allocation.hpp" stefank@2314: duke@435: // A VtableStub holds an individual code stub for a pair (vtable index, #args) for either itables or vtables duke@435: // There's a one-to-one relationship between a VtableStub and such a pair. duke@435: duke@435: class VtableStub { duke@435: private: duke@435: friend class VtableStubs; duke@435: duke@435: static address _chunk; // For allocation duke@435: static address _chunk_end; // For allocation duke@435: static VMReg _receiver_location; // Where to find receiver duke@435: duke@435: VtableStub* _next; // Pointer to next entry in hash table duke@435: const short _index; // vtable index duke@435: short _ame_offset; // Where an AbstractMethodError might occur duke@435: short _npe_offset; // Where a NullPointerException might occur duke@435: bool _is_vtable_stub; // True if vtable stub, false, is itable stub duke@435: /* code follows here */ // The vtableStub code duke@435: duke@435: void* operator new(size_t size, int code_size); duke@435: duke@435: VtableStub(bool is_vtable_stub, int index) duke@435: : _next(NULL), _is_vtable_stub(is_vtable_stub), duke@435: _index(index), _ame_offset(-1), _npe_offset(-1) {} duke@435: VtableStub* next() const { return _next; } duke@435: int index() const { return _index; } duke@435: static VMReg receiver_location() { return _receiver_location; } duke@435: void set_next(VtableStub* n) { _next = n; } duke@435: address code_begin() const { return (address)(this + 1); } duke@435: address code_end() const { return code_begin() + pd_code_size_limit(_is_vtable_stub); } duke@435: address entry_point() const { return code_begin(); } duke@435: static int entry_offset() { return sizeof(class VtableStub); } duke@435: duke@435: bool matches(bool is_vtable_stub, int index) const { duke@435: return _index == index && _is_vtable_stub == is_vtable_stub; duke@435: } duke@435: bool contains(address pc) const { return code_begin() <= pc && pc < code_end(); } duke@435: duke@435: void set_exception_points(address npe_addr, address ame_addr) { duke@435: _npe_offset = npe_addr - code_begin(); duke@435: _ame_offset = ame_addr - code_begin(); duke@435: assert(is_abstract_method_error(ame_addr), "offset must be correct"); duke@435: assert(is_null_pointer_exception(npe_addr), "offset must be correct"); duke@435: assert(!is_abstract_method_error(npe_addr), "offset must be correct"); duke@435: assert(!is_null_pointer_exception(ame_addr), "offset must be correct"); duke@435: } duke@435: duke@435: // platform-dependent routines duke@435: static int pd_code_size_limit(bool is_vtable_stub); duke@435: static int pd_code_alignment(); duke@435: // CNC: Removed because vtable stubs are now made with an ideal graph duke@435: // static bool pd_disregard_arg_size(); duke@435: duke@435: static void align_chunk() { duke@435: uintptr_t off = (uintptr_t)( _chunk + sizeof(VtableStub) ) % pd_code_alignment(); duke@435: if (off != 0) _chunk += pd_code_alignment() - off; duke@435: } duke@435: duke@435: public: duke@435: // Query duke@435: bool is_itable_stub() { return !_is_vtable_stub; } duke@435: bool is_vtable_stub() { return _is_vtable_stub; } duke@435: bool is_abstract_method_error(address epc) { return epc == code_begin()+_ame_offset; } duke@435: bool is_null_pointer_exception(address epc) { return epc == code_begin()+_npe_offset; } duke@435: bobv@2036: void print_on(outputStream* st) const; bobv@2036: void print() const { print_on(tty); } bobv@2036: duke@435: }; duke@435: duke@435: duke@435: // VtableStubs creates the code stubs for compiled calls through vtables. duke@435: // There is one stub per (vtable index, args_size) pair, and the stubs are duke@435: // never deallocated. They don't need to be GCed because they contain no oops. duke@435: duke@435: class VtableStubs : AllStatic { duke@435: public: // N must be public (some compilers need this for _table) duke@435: enum { duke@435: N = 256, // size of stub table; must be power of two duke@435: mask = N - 1 duke@435: }; duke@435: duke@435: private: duke@435: static VtableStub* _table[N]; // table of existing stubs duke@435: static int _number_of_vtable_stubs; // number of stubs created so far (for statistics) duke@435: duke@435: static VtableStub* create_vtable_stub(int vtable_index); duke@435: static VtableStub* create_itable_stub(int vtable_index); duke@435: static VtableStub* lookup (bool is_vtable_stub, int vtable_index); duke@435: static void enter (bool is_vtable_stub, int vtable_index, VtableStub* s); duke@435: static inline uint hash (bool is_vtable_stub, int vtable_index); duke@435: duke@435: public: duke@435: static address create_stub(bool is_vtable_stub, int vtable_index, methodOop method); // return the entry point of a stub for this call duke@435: static bool is_entry_point(address pc); // is pc a vtable stub entry point? duke@435: static bool contains(address pc); // is pc within any stub? duke@435: static VtableStub* stub_containing(address pc); // stub containing pc or NULL duke@435: static int number_of_vtable_stubs() { return _number_of_vtable_stubs; } duke@435: static void initialize(); duke@435: }; stefank@2314: stefank@2314: #endif // SHARE_VM_CODE_VTABLESTUBS_HPP