1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/vm/code/vtableStubs.hpp Sat Dec 01 00:00:00 2007 +0000 1.3 @@ -0,0 +1,121 @@ 1.4 +/* 1.5 + * Copyright 1997-2006 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 1.23 + * CA 95054 USA or visit www.sun.com if you need additional information or 1.24 + * have any questions. 1.25 + * 1.26 + */ 1.27 + 1.28 +// A VtableStub holds an individual code stub for a pair (vtable index, #args) for either itables or vtables 1.29 +// There's a one-to-one relationship between a VtableStub and such a pair. 1.30 + 1.31 +class VtableStub { 1.32 + private: 1.33 + friend class VtableStubs; 1.34 + 1.35 + static address _chunk; // For allocation 1.36 + static address _chunk_end; // For allocation 1.37 + static VMReg _receiver_location; // Where to find receiver 1.38 + 1.39 + VtableStub* _next; // Pointer to next entry in hash table 1.40 + const short _index; // vtable index 1.41 + short _ame_offset; // Where an AbstractMethodError might occur 1.42 + short _npe_offset; // Where a NullPointerException might occur 1.43 + bool _is_vtable_stub; // True if vtable stub, false, is itable stub 1.44 + /* code follows here */ // The vtableStub code 1.45 + 1.46 + void* operator new(size_t size, int code_size); 1.47 + 1.48 + VtableStub(bool is_vtable_stub, int index) 1.49 + : _next(NULL), _is_vtable_stub(is_vtable_stub), 1.50 + _index(index), _ame_offset(-1), _npe_offset(-1) {} 1.51 + VtableStub* next() const { return _next; } 1.52 + int index() const { return _index; } 1.53 + static VMReg receiver_location() { return _receiver_location; } 1.54 + void set_next(VtableStub* n) { _next = n; } 1.55 + address code_begin() const { return (address)(this + 1); } 1.56 + address code_end() const { return code_begin() + pd_code_size_limit(_is_vtable_stub); } 1.57 + address entry_point() const { return code_begin(); } 1.58 + static int entry_offset() { return sizeof(class VtableStub); } 1.59 + 1.60 + bool matches(bool is_vtable_stub, int index) const { 1.61 + return _index == index && _is_vtable_stub == is_vtable_stub; 1.62 + } 1.63 + bool contains(address pc) const { return code_begin() <= pc && pc < code_end(); } 1.64 + 1.65 + void set_exception_points(address npe_addr, address ame_addr) { 1.66 + _npe_offset = npe_addr - code_begin(); 1.67 + _ame_offset = ame_addr - code_begin(); 1.68 + assert(is_abstract_method_error(ame_addr), "offset must be correct"); 1.69 + assert(is_null_pointer_exception(npe_addr), "offset must be correct"); 1.70 + assert(!is_abstract_method_error(npe_addr), "offset must be correct"); 1.71 + assert(!is_null_pointer_exception(ame_addr), "offset must be correct"); 1.72 + } 1.73 + 1.74 + // platform-dependent routines 1.75 + static int pd_code_size_limit(bool is_vtable_stub); 1.76 + static int pd_code_alignment(); 1.77 + // CNC: Removed because vtable stubs are now made with an ideal graph 1.78 + // static bool pd_disregard_arg_size(); 1.79 + 1.80 + static void align_chunk() { 1.81 + uintptr_t off = (uintptr_t)( _chunk + sizeof(VtableStub) ) % pd_code_alignment(); 1.82 + if (off != 0) _chunk += pd_code_alignment() - off; 1.83 + } 1.84 + 1.85 + public: 1.86 + // Query 1.87 + bool is_itable_stub() { return !_is_vtable_stub; } 1.88 + bool is_vtable_stub() { return _is_vtable_stub; } 1.89 + bool is_abstract_method_error(address epc) { return epc == code_begin()+_ame_offset; } 1.90 + bool is_null_pointer_exception(address epc) { return epc == code_begin()+_npe_offset; } 1.91 + 1.92 + void print(); 1.93 +}; 1.94 + 1.95 + 1.96 +// VtableStubs creates the code stubs for compiled calls through vtables. 1.97 +// There is one stub per (vtable index, args_size) pair, and the stubs are 1.98 +// never deallocated. They don't need to be GCed because they contain no oops. 1.99 + 1.100 +class VtableStubs : AllStatic { 1.101 + public: // N must be public (some compilers need this for _table) 1.102 + enum { 1.103 + N = 256, // size of stub table; must be power of two 1.104 + mask = N - 1 1.105 + }; 1.106 + 1.107 + private: 1.108 + static VtableStub* _table[N]; // table of existing stubs 1.109 + static int _number_of_vtable_stubs; // number of stubs created so far (for statistics) 1.110 + 1.111 + static VtableStub* create_vtable_stub(int vtable_index); 1.112 + static VtableStub* create_itable_stub(int vtable_index); 1.113 + static VtableStub* lookup (bool is_vtable_stub, int vtable_index); 1.114 + static void enter (bool is_vtable_stub, int vtable_index, VtableStub* s); 1.115 + static inline uint hash (bool is_vtable_stub, int vtable_index); 1.116 + 1.117 + public: 1.118 + static address create_stub(bool is_vtable_stub, int vtable_index, methodOop method); // return the entry point of a stub for this call 1.119 + static bool is_entry_point(address pc); // is pc a vtable stub entry point? 1.120 + static bool contains(address pc); // is pc within any stub? 1.121 + static VtableStub* stub_containing(address pc); // stub containing pc or NULL 1.122 + static int number_of_vtable_stubs() { return _number_of_vtable_stubs; } 1.123 + static void initialize(); 1.124 +};