author | coleenp |
Fri, 10 May 2019 09:05:29 -0400 | |
changeset 54807 | 33fe50b6d707 |
parent 54623 | 1126f0607c70 |
child 54960 | e46fe26d7f77 |
permissions | -rw-r--r-- |
1 | 1 |
/* |
54623
1126f0607c70
8222811: Consolidate MutexLockerEx and MutexLocker
coleenp
parents:
52980
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:
5403
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
5403
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:
5403
diff
changeset
|
21 |
* questions. |
1 | 22 |
* |
23 |
*/ |
|
24 |
||
7397 | 25 |
#include "precompiled.hpp" |
26 |
#include "code/vtableStubs.hpp" |
|
25495
aeb87692dfd0
8022968: Some codecache allocation failures don't result in invoking the sweeper
thartmann
parents:
24424
diff
changeset
|
27 |
#include "compiler/compileBroker.hpp" |
7397 | 28 |
#include "compiler/disassembler.hpp" |
51627
d5ba88422499
8210355: Minimal and Zero non-PCH builds fail after JDK-8207343 (Automate vtable/itable stub size calculation)
shade
parents:
51618
diff
changeset
|
29 |
#include "logging/log.hpp" |
7397 | 30 |
#include "memory/allocation.inline.hpp" |
31 |
#include "memory/resourceArea.hpp" |
|
32 |
#include "oops/instanceKlass.hpp" |
|
33 |
#include "oops/klassVtable.hpp" |
|
34 |
#include "oops/oop.inline.hpp" |
|
35 |
#include "prims/forte.hpp" |
|
36 |
#include "prims/jvmtiExport.hpp" |
|
37 |
#include "runtime/handles.inline.hpp" |
|
38 |
#include "runtime/mutexLocker.hpp" |
|
39 |
#include "runtime/sharedRuntime.hpp" |
|
46625 | 40 |
#include "utilities/align.hpp" |
7397 | 41 |
#ifdef COMPILER2 |
42 |
#include "opto/matcher.hpp" |
|
43 |
#endif |
|
1 | 44 |
|
45 |
// ----------------------------------------------------------------------------------------- |
|
46 |
// Implementation of VtableStub |
|
47 |
||
48 |
address VtableStub::_chunk = NULL; |
|
49 |
address VtableStub::_chunk_end = NULL; |
|
50 |
VMReg VtableStub::_receiver_location = VMRegImpl::Bad(); |
|
51 |
||
52 |
||
19696
bd5a0131bde1
8021954: VM SIGSEGV during classloading on MacOS; hs_err_pid file produced
coleenp
parents:
17087
diff
changeset
|
53 |
void* VtableStub::operator new(size_t size, int code_size) throw() { |
52980
24525070d934
8215206: VtableStubs::find_stub is not appropriately protected by VtableStubs_lock
eosterlund
parents:
52857
diff
changeset
|
54 |
assert_lock_strong(VtableStubs_lock); |
1 | 55 |
assert(size == sizeof(VtableStub), "mismatched size"); |
56 |
// compute real VtableStub size (rounded to nearest word) |
|
46620
750c6edff33b
8178500: Replace usages of round_to and round_down with align_up and align_down
stefank
parents:
46408
diff
changeset
|
57 |
const int real_size = align_up(code_size + (int)sizeof(VtableStub), wordSize); |
1 | 58 |
// malloc them in chunks to minimize header overhead |
59 |
const int chunk_factor = 32; |
|
60 |
if (_chunk == NULL || _chunk + real_size > _chunk_end) { |
|
61 |
const int bytes = chunk_factor * real_size + pd_code_alignment(); |
|
22747
f467c14746f5
8025841: JVMTI: "vtable stub" dynamic code notification is misplaced
sspitsyn
parents:
20072
diff
changeset
|
62 |
|
f467c14746f5
8025841: JVMTI: "vtable stub" dynamic code notification is misplaced
sspitsyn
parents:
20072
diff
changeset
|
63 |
// There is a dependency on the name of the blob in src/share/vm/prims/jvmtiCodeBlobEvents.cpp |
f467c14746f5
8025841: JVMTI: "vtable stub" dynamic code notification is misplaced
sspitsyn
parents:
20072
diff
changeset
|
64 |
// If changing the name, update the other file accordingly. |
49655
d6893a76c554
8199406: Performance drop with Java JDK 1.8.0_162-b32
poonam
parents:
47216
diff
changeset
|
65 |
VtableBlob* blob = VtableBlob::create("vtable chunks", bytes); |
5403
6b0dd9c75dde
6888954: argument formatting for assert() and friends
jcoomes
parents:
3261
diff
changeset
|
66 |
if (blob == NULL) { |
20072 | 67 |
return NULL; |
5403
6b0dd9c75dde
6888954: argument formatting for assert() and friends
jcoomes
parents:
3261
diff
changeset
|
68 |
} |
6418 | 69 |
_chunk = blob->content_begin(); |
1 | 70 |
_chunk_end = _chunk + bytes; |
71 |
Forte::register_stub("vtable stub", _chunk, _chunk_end); |
|
72 |
align_chunk(); |
|
73 |
} |
|
74 |
assert(_chunk + real_size <= _chunk_end, "bad allocation"); |
|
75 |
void* res = _chunk; |
|
76 |
_chunk += real_size; |
|
77 |
align_chunk(); |
|
78 |
return res; |
|
79 |
} |
|
80 |
||
81 |
||
6176
4d9030fe341f
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
5924
diff
changeset
|
82 |
void VtableStub::print_on(outputStream* st) const { |
33148
68fa8b6c4340
8042893: compiler: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents:
33105
diff
changeset
|
83 |
st->print("vtable stub (index = %d, receiver_location = " INTX_FORMAT ", code = [" INTPTR_FORMAT ", " INTPTR_FORMAT "[)", |
68fa8b6c4340
8042893: compiler: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents:
33105
diff
changeset
|
84 |
index(), p2i(receiver_location()), p2i(code_begin()), p2i(code_end())); |
1 | 85 |
} |
86 |
||
54807 | 87 |
void VtableStub::print() const { print_on(tty); } |
1 | 88 |
|
89 |
// ----------------------------------------------------------------------------------------- |
|
90 |
// Implementation of VtableStubs |
|
91 |
// |
|
92 |
// For each hash value there's a linked list of vtable stubs (with that |
|
93 |
// hash value). Each list is anchored in a little hash _table, indexed |
|
94 |
// by that hash value. |
|
95 |
||
96 |
VtableStub* VtableStubs::_table[VtableStubs::N]; |
|
97 |
int VtableStubs::_number_of_vtable_stubs = 0; |
|
51618
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
49655
diff
changeset
|
98 |
int VtableStubs::_vtab_stub_size = 0; |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
49655
diff
changeset
|
99 |
int VtableStubs::_itab_stub_size = 0; |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
49655
diff
changeset
|
100 |
|
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
49655
diff
changeset
|
101 |
#if defined(PRODUCT) |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
49655
diff
changeset
|
102 |
// These values are good for the PRODUCT case (no tracing). |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
49655
diff
changeset
|
103 |
static const int first_vtableStub_size = 64; |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
49655
diff
changeset
|
104 |
static const int first_itableStub_size = 256; |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
49655
diff
changeset
|
105 |
#else |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
49655
diff
changeset
|
106 |
// These values are good for the non-PRODUCT case (when tracing can be switched on). |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
49655
diff
changeset
|
107 |
// To find out, run test workload with |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
49655
diff
changeset
|
108 |
// -Xlog:vtablestubs=Trace -XX:+CountCompiledCalls -XX:+DebugVtables |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
49655
diff
changeset
|
109 |
// and use the reported "estimate" value. |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
49655
diff
changeset
|
110 |
// Here is a list of observed worst-case values: |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
49655
diff
changeset
|
111 |
// vtable itable |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
49655
diff
changeset
|
112 |
// aarch64: 460 324 |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
49655
diff
changeset
|
113 |
// arm: ? ? |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
49655
diff
changeset
|
114 |
// ppc (linux, BE): 404 288 |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
49655
diff
changeset
|
115 |
// ppc (linux, LE): 356 276 |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
49655
diff
changeset
|
116 |
// ppc (AIX): 416 296 |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
49655
diff
changeset
|
117 |
// s390x: 408 256 |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
49655
diff
changeset
|
118 |
// Solaris-sparc: 792 348 |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
49655
diff
changeset
|
119 |
// x86 (Linux): 670 309 |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
49655
diff
changeset
|
120 |
// x86 (MacOS): 682 321 |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
49655
diff
changeset
|
121 |
static const int first_vtableStub_size = 1024; |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
49655
diff
changeset
|
122 |
static const int first_itableStub_size = 512; |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
49655
diff
changeset
|
123 |
#endif |
1 | 124 |
|
125 |
||
126 |
void VtableStubs::initialize() { |
|
127 |
VtableStub::_receiver_location = SharedRuntime::name_for_receiver(); |
|
128 |
{ |
|
54623
1126f0607c70
8222811: Consolidate MutexLockerEx and MutexLocker
coleenp
parents:
52980
diff
changeset
|
129 |
MutexLocker ml(VtableStubs_lock, Mutex::_no_safepoint_check_flag); |
1 | 130 |
assert(_number_of_vtable_stubs == 0, "potential performance bug: VtableStubs initialized more than once"); |
131 |
assert(is_power_of_2(N), "N must be a power of 2"); |
|
132 |
for (int i = 0; i < N; i++) { |
|
133 |
_table[i] = NULL; |
|
134 |
} |
|
135 |
} |
|
136 |
} |
|
137 |
||
138 |
||
51618
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
49655
diff
changeset
|
139 |
int VtableStubs::code_size_limit(bool is_vtable_stub) { |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
49655
diff
changeset
|
140 |
if (is_vtable_stub) { |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
49655
diff
changeset
|
141 |
return _vtab_stub_size > 0 ? _vtab_stub_size : first_vtableStub_size; |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
49655
diff
changeset
|
142 |
} else { // itable stub |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
49655
diff
changeset
|
143 |
return _itab_stub_size > 0 ? _itab_stub_size : first_itableStub_size; |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
49655
diff
changeset
|
144 |
} |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
49655
diff
changeset
|
145 |
} // code_size_limit |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
49655
diff
changeset
|
146 |
|
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
49655
diff
changeset
|
147 |
|
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
49655
diff
changeset
|
148 |
void VtableStubs::check_and_set_size_limit(bool is_vtable_stub, |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
49655
diff
changeset
|
149 |
int code_size, |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
49655
diff
changeset
|
150 |
int padding) { |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
49655
diff
changeset
|
151 |
const char* name = is_vtable_stub ? "vtable" : "itable"; |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
49655
diff
changeset
|
152 |
|
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
49655
diff
changeset
|
153 |
guarantee(code_size <= code_size_limit(is_vtable_stub), |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
49655
diff
changeset
|
154 |
"buffer overflow in %s stub, code_size is %d, limit is %d", name, code_size, code_size_limit(is_vtable_stub)); |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
49655
diff
changeset
|
155 |
|
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
49655
diff
changeset
|
156 |
if (is_vtable_stub) { |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
49655
diff
changeset
|
157 |
if (log_is_enabled(Trace, vtablestubs)) { |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
49655
diff
changeset
|
158 |
if ( (_vtab_stub_size > 0) && ((code_size + padding) > _vtab_stub_size) ) { |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
49655
diff
changeset
|
159 |
log_trace(vtablestubs)("%s size estimate needed adjustment from %d to %d bytes", |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
49655
diff
changeset
|
160 |
name, _vtab_stub_size, code_size + padding); |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
49655
diff
changeset
|
161 |
} |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
49655
diff
changeset
|
162 |
} |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
49655
diff
changeset
|
163 |
if ( (code_size + padding) > _vtab_stub_size ) { |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
49655
diff
changeset
|
164 |
_vtab_stub_size = code_size + padding; |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
49655
diff
changeset
|
165 |
} |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
49655
diff
changeset
|
166 |
} else { // itable stub |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
49655
diff
changeset
|
167 |
if (log_is_enabled(Trace, vtablestubs)) { |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
49655
diff
changeset
|
168 |
if ( (_itab_stub_size > 0) && ((code_size + padding) > _itab_stub_size) ) { |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
49655
diff
changeset
|
169 |
log_trace(vtablestubs)("%s size estimate needed adjustment from %d to %d bytes", |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
49655
diff
changeset
|
170 |
name, _itab_stub_size, code_size + padding); |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
49655
diff
changeset
|
171 |
} |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
49655
diff
changeset
|
172 |
} |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
49655
diff
changeset
|
173 |
if ( (code_size + padding) > _itab_stub_size ) { |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
49655
diff
changeset
|
174 |
_itab_stub_size = code_size + padding; |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
49655
diff
changeset
|
175 |
} |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
49655
diff
changeset
|
176 |
} |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
49655
diff
changeset
|
177 |
return; |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
49655
diff
changeset
|
178 |
} // check_and_set_size_limit |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
49655
diff
changeset
|
179 |
|
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
49655
diff
changeset
|
180 |
|
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
49655
diff
changeset
|
181 |
void VtableStubs::bookkeeping(MacroAssembler* masm, outputStream* out, VtableStub* s, |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
49655
diff
changeset
|
182 |
address npe_addr, address ame_addr, bool is_vtable_stub, |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
49655
diff
changeset
|
183 |
int index, int slop_bytes, int index_dependent_slop) { |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
49655
diff
changeset
|
184 |
const char* name = is_vtable_stub ? "vtable" : "itable"; |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
49655
diff
changeset
|
185 |
const int stub_length = code_size_limit(is_vtable_stub); |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
49655
diff
changeset
|
186 |
|
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
49655
diff
changeset
|
187 |
if (log_is_enabled(Trace, vtablestubs)) { |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
49655
diff
changeset
|
188 |
log_trace(vtablestubs)("%s #%d at " PTR_FORMAT ": size: %d, estimate: %d, slop area: %d", |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
49655
diff
changeset
|
189 |
name, index, p2i(s->code_begin()), |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
49655
diff
changeset
|
190 |
(int)(masm->pc() - s->code_begin()), |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
49655
diff
changeset
|
191 |
stub_length, |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
49655
diff
changeset
|
192 |
(int)(s->code_end() - masm->pc())); |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
49655
diff
changeset
|
193 |
} |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
49655
diff
changeset
|
194 |
guarantee(masm->pc() <= s->code_end(), "%s #%d: overflowed buffer, estimated len: %d, actual len: %d, overrun: %d", |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
49655
diff
changeset
|
195 |
name, index, stub_length, |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
49655
diff
changeset
|
196 |
(int)(masm->pc() - s->code_begin()), |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
49655
diff
changeset
|
197 |
(int)(masm->pc() - s->code_end())); |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
49655
diff
changeset
|
198 |
assert((masm->pc() + index_dependent_slop) <= s->code_end(), "%s #%d: spare space for 32-bit offset: required = %d, available = %d", |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
49655
diff
changeset
|
199 |
name, index, index_dependent_slop, |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
49655
diff
changeset
|
200 |
(int)(s->code_end() - masm->pc())); |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
49655
diff
changeset
|
201 |
|
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
49655
diff
changeset
|
202 |
// After the first vtable/itable stub is generated, we have a much |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
49655
diff
changeset
|
203 |
// better estimate for the stub size. Remember/update this |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
49655
diff
changeset
|
204 |
// estimate after some sanity checks. |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
49655
diff
changeset
|
205 |
check_and_set_size_limit(is_vtable_stub, masm->offset(), slop_bytes); |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
49655
diff
changeset
|
206 |
s->set_exception_points(npe_addr, ame_addr); |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
49655
diff
changeset
|
207 |
} |
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
49655
diff
changeset
|
208 |
|
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
49655
diff
changeset
|
209 |
|
20017
81eba62e9048
8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents:
19696
diff
changeset
|
210 |
address VtableStubs::find_stub(bool is_vtable_stub, int vtable_index) { |
1 | 211 |
assert(vtable_index >= 0, "must be positive"); |
212 |
||
52980
24525070d934
8215206: VtableStubs::find_stub is not appropriately protected by VtableStubs_lock
eosterlund
parents:
52857
diff
changeset
|
213 |
VtableStub* s; |
24525070d934
8215206: VtableStubs::find_stub is not appropriately protected by VtableStubs_lock
eosterlund
parents:
52857
diff
changeset
|
214 |
{ |
54623
1126f0607c70
8222811: Consolidate MutexLockerEx and MutexLocker
coleenp
parents:
52980
diff
changeset
|
215 |
MutexLocker ml(VtableStubs_lock, Mutex::_no_safepoint_check_flag); |
52980
24525070d934
8215206: VtableStubs::find_stub is not appropriately protected by VtableStubs_lock
eosterlund
parents:
52857
diff
changeset
|
216 |
s = ShareVtableStubs ? lookup(is_vtable_stub, vtable_index) : NULL; |
20072 | 217 |
if (s == NULL) { |
52980
24525070d934
8215206: VtableStubs::find_stub is not appropriately protected by VtableStubs_lock
eosterlund
parents:
52857
diff
changeset
|
218 |
if (is_vtable_stub) { |
24525070d934
8215206: VtableStubs::find_stub is not appropriately protected by VtableStubs_lock
eosterlund
parents:
52857
diff
changeset
|
219 |
s = create_vtable_stub(vtable_index); |
24525070d934
8215206: VtableStubs::find_stub is not appropriately protected by VtableStubs_lock
eosterlund
parents:
52857
diff
changeset
|
220 |
} else { |
24525070d934
8215206: VtableStubs::find_stub is not appropriately protected by VtableStubs_lock
eosterlund
parents:
52857
diff
changeset
|
221 |
s = create_itable_stub(vtable_index); |
24525070d934
8215206: VtableStubs::find_stub is not appropriately protected by VtableStubs_lock
eosterlund
parents:
52857
diff
changeset
|
222 |
} |
20072 | 223 |
|
52980
24525070d934
8215206: VtableStubs::find_stub is not appropriately protected by VtableStubs_lock
eosterlund
parents:
52857
diff
changeset
|
224 |
// Creation of vtable or itable can fail if there is not enough free space in the code cache. |
24525070d934
8215206: VtableStubs::find_stub is not appropriately protected by VtableStubs_lock
eosterlund
parents:
52857
diff
changeset
|
225 |
if (s == NULL) { |
24525070d934
8215206: VtableStubs::find_stub is not appropriately protected by VtableStubs_lock
eosterlund
parents:
52857
diff
changeset
|
226 |
return NULL; |
24525070d934
8215206: VtableStubs::find_stub is not appropriately protected by VtableStubs_lock
eosterlund
parents:
52857
diff
changeset
|
227 |
} |
24525070d934
8215206: VtableStubs::find_stub is not appropriately protected by VtableStubs_lock
eosterlund
parents:
52857
diff
changeset
|
228 |
|
24525070d934
8215206: VtableStubs::find_stub is not appropriately protected by VtableStubs_lock
eosterlund
parents:
52857
diff
changeset
|
229 |
enter(is_vtable_stub, vtable_index, s); |
24525070d934
8215206: VtableStubs::find_stub is not appropriately protected by VtableStubs_lock
eosterlund
parents:
52857
diff
changeset
|
230 |
if (PrintAdapterHandlers) { |
24525070d934
8215206: VtableStubs::find_stub is not appropriately protected by VtableStubs_lock
eosterlund
parents:
52857
diff
changeset
|
231 |
tty->print_cr("Decoding VtableStub %s[%d]@" INTX_FORMAT, |
24525070d934
8215206: VtableStubs::find_stub is not appropriately protected by VtableStubs_lock
eosterlund
parents:
52857
diff
changeset
|
232 |
is_vtable_stub? "vtbl": "itbl", vtable_index, p2i(VtableStub::receiver_location())); |
24525070d934
8215206: VtableStubs::find_stub is not appropriately protected by VtableStubs_lock
eosterlund
parents:
52857
diff
changeset
|
233 |
Disassembler::decode(s->code_begin(), s->code_end()); |
24525070d934
8215206: VtableStubs::find_stub is not appropriately protected by VtableStubs_lock
eosterlund
parents:
52857
diff
changeset
|
234 |
} |
24525070d934
8215206: VtableStubs::find_stub is not appropriately protected by VtableStubs_lock
eosterlund
parents:
52857
diff
changeset
|
235 |
// Notify JVMTI about this stub. The event will be recorded by the enclosing |
24525070d934
8215206: VtableStubs::find_stub is not appropriately protected by VtableStubs_lock
eosterlund
parents:
52857
diff
changeset
|
236 |
// JvmtiDynamicCodeEventCollector and posted when this thread has released |
24525070d934
8215206: VtableStubs::find_stub is not appropriately protected by VtableStubs_lock
eosterlund
parents:
52857
diff
changeset
|
237 |
// all locks. |
24525070d934
8215206: VtableStubs::find_stub is not appropriately protected by VtableStubs_lock
eosterlund
parents:
52857
diff
changeset
|
238 |
if (JvmtiExport::should_post_dynamic_code_generated()) { |
24525070d934
8215206: VtableStubs::find_stub is not appropriately protected by VtableStubs_lock
eosterlund
parents:
52857
diff
changeset
|
239 |
JvmtiExport::post_dynamic_code_generated_while_holding_locks(is_vtable_stub? "vtable stub": "itable stub", |
24525070d934
8215206: VtableStubs::find_stub is not appropriately protected by VtableStubs_lock
eosterlund
parents:
52857
diff
changeset
|
240 |
s->code_begin(), s->code_end()); |
24525070d934
8215206: VtableStubs::find_stub is not appropriately protected by VtableStubs_lock
eosterlund
parents:
52857
diff
changeset
|
241 |
} |
22747
f467c14746f5
8025841: JVMTI: "vtable stub" dynamic code notification is misplaced
sspitsyn
parents:
20072
diff
changeset
|
242 |
} |
1 | 243 |
} |
244 |
return s->entry_point(); |
|
245 |
} |
|
246 |
||
247 |
||
248 |
inline uint VtableStubs::hash(bool is_vtable_stub, int vtable_index){ |
|
249 |
// Assumption: receiver_location < 4 in most cases. |
|
250 |
int hash = ((vtable_index << 2) ^ VtableStub::receiver_location()->value()) + vtable_index; |
|
251 |
return (is_vtable_stub ? ~hash : hash) & mask; |
|
252 |
} |
|
253 |
||
254 |
||
255 |
VtableStub* VtableStubs::lookup(bool is_vtable_stub, int vtable_index) { |
|
52980
24525070d934
8215206: VtableStubs::find_stub is not appropriately protected by VtableStubs_lock
eosterlund
parents:
52857
diff
changeset
|
256 |
assert_lock_strong(VtableStubs_lock); |
1 | 257 |
unsigned hash = VtableStubs::hash(is_vtable_stub, vtable_index); |
258 |
VtableStub* s = _table[hash]; |
|
259 |
while( s && !s->matches(is_vtable_stub, vtable_index)) s = s->next(); |
|
260 |
return s; |
|
261 |
} |
|
262 |
||
263 |
||
264 |
void VtableStubs::enter(bool is_vtable_stub, int vtable_index, VtableStub* s) { |
|
52980
24525070d934
8215206: VtableStubs::find_stub is not appropriately protected by VtableStubs_lock
eosterlund
parents:
52857
diff
changeset
|
265 |
assert_lock_strong(VtableStubs_lock); |
1 | 266 |
assert(s->matches(is_vtable_stub, vtable_index), "bad vtable stub"); |
267 |
unsigned int h = VtableStubs::hash(is_vtable_stub, vtable_index); |
|
268 |
// enter s at the beginning of the corresponding list |
|
269 |
s->set_next(_table[h]); |
|
270 |
_table[h] = s; |
|
271 |
_number_of_vtable_stubs++; |
|
272 |
} |
|
273 |
||
49655
d6893a76c554
8199406: Performance drop with Java JDK 1.8.0_162-b32
poonam
parents:
47216
diff
changeset
|
274 |
VtableStub* VtableStubs::entry_point(address pc) { |
54623
1126f0607c70
8222811: Consolidate MutexLockerEx and MutexLocker
coleenp
parents:
52980
diff
changeset
|
275 |
MutexLocker ml(VtableStubs_lock, Mutex::_no_safepoint_check_flag); |
1 | 276 |
VtableStub* stub = (VtableStub*)(pc - VtableStub::entry_offset()); |
277 |
uint hash = VtableStubs::hash(stub->is_vtable_stub(), stub->index()); |
|
278 |
VtableStub* s; |
|
279 |
for (s = _table[hash]; s != NULL && s != stub; s = s->next()) {} |
|
51618
54b344d9dd4e
8207343: Automate vtable/itable stub size calculation
lucy
parents:
49655
diff
changeset
|
280 |
return (s == stub) ? s : NULL; |
1 | 281 |
} |
282 |
||
283 |
bool VtableStubs::contains(address pc) { |
|
284 |
// simple solution for now - we may want to use |
|
285 |
// a faster way if this function is called often |
|
286 |
return stub_containing(pc) != NULL; |
|
287 |
} |
|
288 |
||
289 |
||
290 |
VtableStub* VtableStubs::stub_containing(address pc) { |
|
291 |
// Note: No locking needed since any change to the data structure |
|
292 |
// happens with an atomic store into it (we don't care about |
|
293 |
// consistency with the _number_of_vtable_stubs counter). |
|
294 |
for (int i = 0; i < N; i++) { |
|
295 |
for (VtableStub* s = _table[i]; s != NULL; s = s->next()) { |
|
296 |
if (s->contains(pc)) return s; |
|
297 |
} |
|
298 |
} |
|
299 |
return NULL; |
|
300 |
} |
|
301 |
||
302 |
void vtableStubs_init() { |
|
303 |
VtableStubs::initialize(); |
|
304 |
} |
|
305 |
||
22747
f467c14746f5
8025841: JVMTI: "vtable stub" dynamic code notification is misplaced
sspitsyn
parents:
20072
diff
changeset
|
306 |
void VtableStubs::vtable_stub_do(void f(VtableStub*)) { |
f467c14746f5
8025841: JVMTI: "vtable stub" dynamic code notification is misplaced
sspitsyn
parents:
20072
diff
changeset
|
307 |
for (int i = 0; i < N; i++) { |
f467c14746f5
8025841: JVMTI: "vtable stub" dynamic code notification is misplaced
sspitsyn
parents:
20072
diff
changeset
|
308 |
for (VtableStub* s = _table[i]; s != NULL; s = s->next()) { |
f467c14746f5
8025841: JVMTI: "vtable stub" dynamic code notification is misplaced
sspitsyn
parents:
20072
diff
changeset
|
309 |
f(s); |
f467c14746f5
8025841: JVMTI: "vtable stub" dynamic code notification is misplaced
sspitsyn
parents:
20072
diff
changeset
|
310 |
} |
f467c14746f5
8025841: JVMTI: "vtable stub" dynamic code notification is misplaced
sspitsyn
parents:
20072
diff
changeset
|
311 |
} |
f467c14746f5
8025841: JVMTI: "vtable stub" dynamic code notification is misplaced
sspitsyn
parents:
20072
diff
changeset
|
312 |
} |
f467c14746f5
8025841: JVMTI: "vtable stub" dynamic code notification is misplaced
sspitsyn
parents:
20072
diff
changeset
|
313 |
|
1 | 314 |
|
315 |
//----------------------------------------------------------------------------------------------------- |
|
316 |
// Non-product code |
|
317 |
#ifndef PRODUCT |
|
318 |
||
319 |
extern "C" void bad_compiled_vtable_index(JavaThread* thread, oop receiver, int index) { |
|
320 |
ResourceMark rm; |
|
321 |
HandleMark hm; |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
7397
diff
changeset
|
322 |
Klass* klass = receiver->klass(); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
7397
diff
changeset
|
323 |
InstanceKlass* ik = InstanceKlass::cast(klass); |
46408
70aab0c2ea8b
8178350: klassVtable and klassItable should be ValueObj
iklam
parents:
33148
diff
changeset
|
324 |
klassVtable vt = ik->vtable(); |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
7397
diff
changeset
|
325 |
ik->print(); |
33105
294e48b4f704
8080775: Better argument formatting for assert() and friends
david
parents:
27420
diff
changeset
|
326 |
fatal("bad compiled vtable dispatch: receiver " INTPTR_FORMAT ", " |
294e48b4f704
8080775: Better argument formatting for assert() and friends
david
parents:
27420
diff
changeset
|
327 |
"index %d (vtable length %d)", |
46408
70aab0c2ea8b
8178350: klassVtable and klassItable should be ValueObj
iklam
parents:
33148
diff
changeset
|
328 |
p2i(receiver), index, vt.length()); |
1 | 329 |
} |
330 |
||
33105
294e48b4f704
8080775: Better argument formatting for assert() and friends
david
parents:
27420
diff
changeset
|
331 |
#endif // PRODUCT |