1
|
1 |
/*
|
|
2 |
* Copyright 1997-2006 Sun Microsystems, Inc. All Rights Reserved.
|
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 |
*
|
|
5 |
* This code is free software; you can redistribute it and/or modify it
|
|
6 |
* under the terms of the GNU General Public License version 2 only, as
|
|
7 |
* published by the Free Software Foundation.
|
|
8 |
*
|
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
13 |
* accompanied this code).
|
|
14 |
*
|
|
15 |
* You should have received a copy of the GNU General Public License version
|
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
18 |
*
|
|
19 |
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
|
20 |
* CA 95054 USA or visit www.sun.com if you need additional information or
|
|
21 |
* have any questions.
|
|
22 |
*
|
|
23 |
*/
|
|
24 |
|
|
25 |
// A VtableStub holds an individual code stub for a pair (vtable index, #args) for either itables or vtables
|
|
26 |
// There's a one-to-one relationship between a VtableStub and such a pair.
|
|
27 |
|
|
28 |
class VtableStub {
|
|
29 |
private:
|
|
30 |
friend class VtableStubs;
|
|
31 |
|
|
32 |
static address _chunk; // For allocation
|
|
33 |
static address _chunk_end; // For allocation
|
|
34 |
static VMReg _receiver_location; // Where to find receiver
|
|
35 |
|
|
36 |
VtableStub* _next; // Pointer to next entry in hash table
|
|
37 |
const short _index; // vtable index
|
|
38 |
short _ame_offset; // Where an AbstractMethodError might occur
|
|
39 |
short _npe_offset; // Where a NullPointerException might occur
|
|
40 |
bool _is_vtable_stub; // True if vtable stub, false, is itable stub
|
|
41 |
/* code follows here */ // The vtableStub code
|
|
42 |
|
|
43 |
void* operator new(size_t size, int code_size);
|
|
44 |
|
|
45 |
VtableStub(bool is_vtable_stub, int index)
|
|
46 |
: _next(NULL), _is_vtable_stub(is_vtable_stub),
|
|
47 |
_index(index), _ame_offset(-1), _npe_offset(-1) {}
|
|
48 |
VtableStub* next() const { return _next; }
|
|
49 |
int index() const { return _index; }
|
|
50 |
static VMReg receiver_location() { return _receiver_location; }
|
|
51 |
void set_next(VtableStub* n) { _next = n; }
|
|
52 |
address code_begin() const { return (address)(this + 1); }
|
|
53 |
address code_end() const { return code_begin() + pd_code_size_limit(_is_vtable_stub); }
|
|
54 |
address entry_point() const { return code_begin(); }
|
|
55 |
static int entry_offset() { return sizeof(class VtableStub); }
|
|
56 |
|
|
57 |
bool matches(bool is_vtable_stub, int index) const {
|
|
58 |
return _index == index && _is_vtable_stub == is_vtable_stub;
|
|
59 |
}
|
|
60 |
bool contains(address pc) const { return code_begin() <= pc && pc < code_end(); }
|
|
61 |
|
|
62 |
void set_exception_points(address npe_addr, address ame_addr) {
|
|
63 |
_npe_offset = npe_addr - code_begin();
|
|
64 |
_ame_offset = ame_addr - code_begin();
|
|
65 |
assert(is_abstract_method_error(ame_addr), "offset must be correct");
|
|
66 |
assert(is_null_pointer_exception(npe_addr), "offset must be correct");
|
|
67 |
assert(!is_abstract_method_error(npe_addr), "offset must be correct");
|
|
68 |
assert(!is_null_pointer_exception(ame_addr), "offset must be correct");
|
|
69 |
}
|
|
70 |
|
|
71 |
// platform-dependent routines
|
|
72 |
static int pd_code_size_limit(bool is_vtable_stub);
|
|
73 |
static int pd_code_alignment();
|
|
74 |
// CNC: Removed because vtable stubs are now made with an ideal graph
|
|
75 |
// static bool pd_disregard_arg_size();
|
|
76 |
|
|
77 |
static void align_chunk() {
|
|
78 |
uintptr_t off = (uintptr_t)( _chunk + sizeof(VtableStub) ) % pd_code_alignment();
|
|
79 |
if (off != 0) _chunk += pd_code_alignment() - off;
|
|
80 |
}
|
|
81 |
|
|
82 |
public:
|
|
83 |
// Query
|
|
84 |
bool is_itable_stub() { return !_is_vtable_stub; }
|
|
85 |
bool is_vtable_stub() { return _is_vtable_stub; }
|
|
86 |
bool is_abstract_method_error(address epc) { return epc == code_begin()+_ame_offset; }
|
|
87 |
bool is_null_pointer_exception(address epc) { return epc == code_begin()+_npe_offset; }
|
|
88 |
|
|
89 |
void print();
|
|
90 |
};
|
|
91 |
|
|
92 |
|
|
93 |
// VtableStubs creates the code stubs for compiled calls through vtables.
|
|
94 |
// There is one stub per (vtable index, args_size) pair, and the stubs are
|
|
95 |
// never deallocated. They don't need to be GCed because they contain no oops.
|
|
96 |
|
|
97 |
class VtableStubs : AllStatic {
|
|
98 |
public: // N must be public (some compilers need this for _table)
|
|
99 |
enum {
|
|
100 |
N = 256, // size of stub table; must be power of two
|
|
101 |
mask = N - 1
|
|
102 |
};
|
|
103 |
|
|
104 |
private:
|
|
105 |
static VtableStub* _table[N]; // table of existing stubs
|
|
106 |
static int _number_of_vtable_stubs; // number of stubs created so far (for statistics)
|
|
107 |
|
|
108 |
static VtableStub* create_vtable_stub(int vtable_index);
|
|
109 |
static VtableStub* create_itable_stub(int vtable_index);
|
|
110 |
static VtableStub* lookup (bool is_vtable_stub, int vtable_index);
|
|
111 |
static void enter (bool is_vtable_stub, int vtable_index, VtableStub* s);
|
|
112 |
static inline uint hash (bool is_vtable_stub, int vtable_index);
|
|
113 |
|
|
114 |
public:
|
|
115 |
static address create_stub(bool is_vtable_stub, int vtable_index, methodOop method); // return the entry point of a stub for this call
|
|
116 |
static bool is_entry_point(address pc); // is pc a vtable stub entry point?
|
|
117 |
static bool contains(address pc); // is pc within any stub?
|
|
118 |
static VtableStub* stub_containing(address pc); // stub containing pc or NULL
|
|
119 |
static int number_of_vtable_stubs() { return _number_of_vtable_stubs; }
|
|
120 |
static void initialize();
|
|
121 |
};
|