author | phh |
Sat, 30 Nov 2019 14:33:05 -0800 | |
changeset 59330 | 5b96c12f909d |
parent 54807 | 33fe50b6d707 |
permissions | -rw-r--r-- |
1 | 1 |
/* |
53244
9807daeb47c4
8216167: Update include guards to reflect correct directories
coleenp
parents:
51618
diff
changeset
|
2 |
* Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved. |
1 | 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 |
* |
|
5547
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1
diff
changeset
|
21 |
* questions. |
1 | 22 |
* |
23 |
*/ |
|
24 |
||
53244
9807daeb47c4
8216167: Update include guards to reflect correct directories
coleenp
parents:
51618
diff
changeset
|
25 |
#ifndef SHARE_CODE_VTABLESTUBS_HPP |
9807daeb47c4
8216167: Update include guards to reflect correct directories
coleenp
parents:
51618
diff
changeset
|
26 |
#define SHARE_CODE_VTABLESTUBS_HPP |
7397 | 27 |
|
51618
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
51333
diff
changeset
|
28 |
#include "asm/macroAssembler.hpp" |
7408
c04a5c989f26
7003125: precompiled.hpp is included when precompiled headers are not used
stefank
parents:
7397
diff
changeset
|
29 |
#include "code/vmreg.hpp" |
7397 | 30 |
#include "memory/allocation.hpp" |
31 |
||
1 | 32 |
// A VtableStub holds an individual code stub for a pair (vtable index, #args) for either itables or vtables |
33 |
// There's a one-to-one relationship between a VtableStub and such a pair. |
|
34 |
||
51618
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
51333
diff
changeset
|
35 |
// A word on VtableStub sizing: |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
51333
diff
changeset
|
36 |
// Such a vtable/itable stub consists of the instance data |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
51333
diff
changeset
|
37 |
// and an immediately following CodeBuffer. |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
51333
diff
changeset
|
38 |
// Unfortunately, the required space for the code buffer varies, depending on |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
51333
diff
changeset
|
39 |
// the setting of compile time macros (PRODUCT, ASSERT, ...) and of command line |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
51333
diff
changeset
|
40 |
// parameters. Actual data may have an influence on the size as well. |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
51333
diff
changeset
|
41 |
// |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
51333
diff
changeset
|
42 |
// A simple approximation for the VtableStub size would be to just take a value |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
51333
diff
changeset
|
43 |
// "large enough" for all circumstances - a worst case estimate. |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
51333
diff
changeset
|
44 |
// As there can exist many stubs - and they never go away - we certainly don't |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
51333
diff
changeset
|
45 |
// want to waste more code cache space than absolutely necessary. |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
51333
diff
changeset
|
46 |
// |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
51333
diff
changeset
|
47 |
// We need a different approach which, as far as possible, should be independent |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
51333
diff
changeset
|
48 |
// from or adaptive to code size variations. These variations may be caused by |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
51333
diff
changeset
|
49 |
// changed compile time or run time switches as well as by changed emitter code. |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
51333
diff
changeset
|
50 |
// |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
51333
diff
changeset
|
51 |
// Here is the idea: |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
51333
diff
changeset
|
52 |
// For the first stub we generate, we allocate a "large enough" code buffer. |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
51333
diff
changeset
|
53 |
// Once all instructions are emitted, we know the actual size of the stub. |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
51333
diff
changeset
|
54 |
// Remembering that size allows us to allocate a tightly matching code buffer |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
51333
diff
changeset
|
55 |
// for all subsequent stubs. That covers all "static variance", i.e. all variance |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
51333
diff
changeset
|
56 |
// that is due to compile time macros, command line parameters, machine capabilities, |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
51333
diff
changeset
|
57 |
// and other influences which are immutable for the life span of the vm. |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
51333
diff
changeset
|
58 |
// |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
51333
diff
changeset
|
59 |
// Life isn't always that easy. Code size may depend on actual data, "load constant" |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
51333
diff
changeset
|
60 |
// being an example for that. All code segments with such "dynamic variance" require |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
51333
diff
changeset
|
61 |
// additional care. We need to know or estimate the worst case code size for each |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
51333
diff
changeset
|
62 |
// such segment. With that knowledge, we can maintain a "slop counter" in the |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
51333
diff
changeset
|
63 |
// platform-specific stub emitters. It accumulates the difference between worst-case |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
51333
diff
changeset
|
64 |
// and actual code size. When the stub is fully generated, the actual stub size is |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
51333
diff
changeset
|
65 |
// adjusted (increased) by the slop counter value. |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
51333
diff
changeset
|
66 |
// |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
51333
diff
changeset
|
67 |
// As a result, we allocate all but the first code buffers with the same, tightly matching size. |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
51333
diff
changeset
|
68 |
// |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
51333
diff
changeset
|
69 |
|
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
51333
diff
changeset
|
70 |
// VtableStubs creates the code stubs for compiled calls through vtables. |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
51333
diff
changeset
|
71 |
// There is one stub per (vtable index, args_size) pair, and the stubs are |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
51333
diff
changeset
|
72 |
// never deallocated. They don't need to be GCed because they contain no oops. |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
51333
diff
changeset
|
73 |
class VtableStub; |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
51333
diff
changeset
|
74 |
|
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
51333
diff
changeset
|
75 |
class VtableStubs : AllStatic { |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
51333
diff
changeset
|
76 |
public: // N must be public (some compilers need this for _table) |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
51333
diff
changeset
|
77 |
enum { |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
51333
diff
changeset
|
78 |
N = 256, // size of stub table; must be power of two |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
51333
diff
changeset
|
79 |
mask = N - 1 |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
51333
diff
changeset
|
80 |
}; |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
51333
diff
changeset
|
81 |
|
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
51333
diff
changeset
|
82 |
private: |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
51333
diff
changeset
|
83 |
friend class VtableStub; |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
51333
diff
changeset
|
84 |
static VtableStub* _table[N]; // table of existing stubs |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
51333
diff
changeset
|
85 |
static int _number_of_vtable_stubs; // number of stubs created so far (for statistics) |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
51333
diff
changeset
|
86 |
static int _vtab_stub_size; // current size estimate for vtable stub (quasi-constant) |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
51333
diff
changeset
|
87 |
static int _itab_stub_size; // current size estimate for itable stub (quasi-constant) |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
51333
diff
changeset
|
88 |
|
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
51333
diff
changeset
|
89 |
static VtableStub* create_vtable_stub(int vtable_index); |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
51333
diff
changeset
|
90 |
static VtableStub* create_itable_stub(int vtable_index); |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
51333
diff
changeset
|
91 |
static VtableStub* lookup (bool is_vtable_stub, int vtable_index); |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
51333
diff
changeset
|
92 |
static void enter (bool is_vtable_stub, int vtable_index, VtableStub* s); |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
51333
diff
changeset
|
93 |
static inline uint hash (bool is_vtable_stub, int vtable_index); |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
51333
diff
changeset
|
94 |
static address find_stub (bool is_vtable_stub, int vtable_index); |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
51333
diff
changeset
|
95 |
static void bookkeeping(MacroAssembler* masm, outputStream* out, VtableStub* s, |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
51333
diff
changeset
|
96 |
address npe_addr, address ame_addr, bool is_vtable_stub, |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
51333
diff
changeset
|
97 |
int index, int slop_bytes, int index_dependent_slop); |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
51333
diff
changeset
|
98 |
static int code_size_limit(bool is_vtable_stub); |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
51333
diff
changeset
|
99 |
static void check_and_set_size_limit(bool is_vtable_stub, |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
51333
diff
changeset
|
100 |
int code_size, |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
51333
diff
changeset
|
101 |
int padding); |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
51333
diff
changeset
|
102 |
|
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
51333
diff
changeset
|
103 |
public: |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
51333
diff
changeset
|
104 |
static address find_vtable_stub(int vtable_index) { return find_stub(true, vtable_index); } |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
51333
diff
changeset
|
105 |
static address find_itable_stub(int itable_index) { return find_stub(false, itable_index); } |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
51333
diff
changeset
|
106 |
|
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
51333
diff
changeset
|
107 |
static VtableStub* entry_point(address pc); // vtable stub entry point for a pc |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
51333
diff
changeset
|
108 |
static bool contains(address pc); // is pc within any stub? |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
51333
diff
changeset
|
109 |
static VtableStub* stub_containing(address pc); // stub containing pc or NULL |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
51333
diff
changeset
|
110 |
static int number_of_vtable_stubs() { return _number_of_vtable_stubs; } |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
51333
diff
changeset
|
111 |
static void initialize(); |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
51333
diff
changeset
|
112 |
static void vtable_stub_do(void f(VtableStub*)); // iterates over all vtable stubs |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
51333
diff
changeset
|
113 |
}; |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
51333
diff
changeset
|
114 |
|
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
51333
diff
changeset
|
115 |
|
1 | 116 |
class VtableStub { |
117 |
private: |
|
118 |
friend class VtableStubs; |
|
119 |
||
120 |
static address _chunk; // For allocation |
|
121 |
static address _chunk_end; // For allocation |
|
122 |
static VMReg _receiver_location; // Where to find receiver |
|
123 |
||
124 |
VtableStub* _next; // Pointer to next entry in hash table |
|
125 |
const short _index; // vtable index |
|
126 |
short _ame_offset; // Where an AbstractMethodError might occur |
|
127 |
short _npe_offset; // Where a NullPointerException might occur |
|
128 |
bool _is_vtable_stub; // True if vtable stub, false, is itable stub |
|
129 |
/* code follows here */ // The vtableStub code |
|
130 |
||
19696
bd5a0131bde1
8021954: VM SIGSEGV during classloading on MacOS; hs_err_pid file produced
coleenp
parents:
13728
diff
changeset
|
131 |
void* operator new(size_t size, int code_size) throw(); |
1 | 132 |
|
133 |
VtableStub(bool is_vtable_stub, int index) |
|
51333
f6641fcf7b7e
8208670: Compiler changes to allow enabling -Wreorder
tschatzl
parents:
49655
diff
changeset
|
134 |
: _next(NULL), _index(index), _ame_offset(-1), _npe_offset(-1), |
f6641fcf7b7e
8208670: Compiler changes to allow enabling -Wreorder
tschatzl
parents:
49655
diff
changeset
|
135 |
_is_vtable_stub(is_vtable_stub) {} |
1 | 136 |
VtableStub* next() const { return _next; } |
137 |
int index() const { return _index; } |
|
138 |
static VMReg receiver_location() { return _receiver_location; } |
|
139 |
void set_next(VtableStub* n) { _next = n; } |
|
13391
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
7408
diff
changeset
|
140 |
|
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
7408
diff
changeset
|
141 |
public: |
1 | 142 |
address code_begin() const { return (address)(this + 1); } |
51618
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
51333
diff
changeset
|
143 |
address code_end() const { return code_begin() + VtableStubs::code_size_limit(_is_vtable_stub); } |
1 | 144 |
address entry_point() const { return code_begin(); } |
145 |
static int entry_offset() { return sizeof(class VtableStub); } |
|
146 |
||
147 |
bool matches(bool is_vtable_stub, int index) const { |
|
148 |
return _index == index && _is_vtable_stub == is_vtable_stub; |
|
149 |
} |
|
150 |
bool contains(address pc) const { return code_begin() <= pc && pc < code_end(); } |
|
151 |
||
13391
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
7408
diff
changeset
|
152 |
private: |
1 | 153 |
void set_exception_points(address npe_addr, address ame_addr) { |
154 |
_npe_offset = npe_addr - code_begin(); |
|
155 |
_ame_offset = ame_addr - code_begin(); |
|
156 |
assert(is_abstract_method_error(ame_addr), "offset must be correct"); |
|
157 |
assert(is_null_pointer_exception(npe_addr), "offset must be correct"); |
|
158 |
assert(!is_abstract_method_error(npe_addr), "offset must be correct"); |
|
159 |
assert(!is_null_pointer_exception(ame_addr), "offset must be correct"); |
|
160 |
} |
|
161 |
||
162 |
// platform-dependent routines |
|
163 |
static int pd_code_alignment(); |
|
164 |
// CNC: Removed because vtable stubs are now made with an ideal graph |
|
165 |
// static bool pd_disregard_arg_size(); |
|
166 |
||
167 |
static void align_chunk() { |
|
168 |
uintptr_t off = (uintptr_t)( _chunk + sizeof(VtableStub) ) % pd_code_alignment(); |
|
169 |
if (off != 0) _chunk += pd_code_alignment() - off; |
|
170 |
} |
|
171 |
||
172 |
public: |
|
173 |
// Query |
|
174 |
bool is_itable_stub() { return !_is_vtable_stub; } |
|
175 |
bool is_vtable_stub() { return _is_vtable_stub; } |
|
176 |
bool is_abstract_method_error(address epc) { return epc == code_begin()+_ame_offset; } |
|
177 |
bool is_null_pointer_exception(address epc) { return epc == code_begin()+_npe_offset; } |
|
178 |
||
6176
4d9030fe341f
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
5547
diff
changeset
|
179 |
void print_on(outputStream* st) const; |
54807 | 180 |
void print() const; |
6176
4d9030fe341f
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
5547
diff
changeset
|
181 |
|
1 | 182 |
}; |
183 |
||
53244
9807daeb47c4
8216167: Update include guards to reflect correct directories
coleenp
parents:
51618
diff
changeset
|
184 |
#endif // SHARE_CODE_VTABLESTUBS_HPP |