author | bdelsart |
Wed, 01 Jul 2015 10:53:26 +0200 | |
changeset 31620 | 53be635ad49c |
parent 27420 | 04e6f914cce1 |
child 33105 | 294e48b4f704 |
permissions | -rw-r--r-- |
1 | 1 |
/* |
24424
2658d7834c6e
8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents:
22747
diff
changeset
|
2 |
* Copyright (c) 1997, 2014, 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" |
29 |
#include "memory/allocation.inline.hpp" |
|
30 |
#include "memory/resourceArea.hpp" |
|
31 |
#include "oops/instanceKlass.hpp" |
|
32 |
#include "oops/klassVtable.hpp" |
|
33 |
#include "oops/oop.inline.hpp" |
|
34 |
#include "prims/forte.hpp" |
|
35 |
#include "prims/jvmtiExport.hpp" |
|
36 |
#include "runtime/handles.inline.hpp" |
|
37 |
#include "runtime/mutexLocker.hpp" |
|
38 |
#include "runtime/sharedRuntime.hpp" |
|
39 |
#ifdef COMPILER2 |
|
40 |
#include "opto/matcher.hpp" |
|
41 |
#endif |
|
1 | 42 |
|
24424
2658d7834c6e
8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents:
22747
diff
changeset
|
43 |
PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC |
2658d7834c6e
8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents:
22747
diff
changeset
|
44 |
|
1 | 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() { |
1 | 54 |
assert(size == sizeof(VtableStub), "mismatched size"); |
55 |
// compute real VtableStub size (rounded to nearest word) |
|
56 |
const int real_size = round_to(code_size + sizeof(VtableStub), wordSize); |
|
57 |
// malloc them in chunks to minimize header overhead |
|
58 |
const int chunk_factor = 32; |
|
59 |
if (_chunk == NULL || _chunk + real_size > _chunk_end) { |
|
60 |
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
|
61 |
|
f467c14746f5
8025841: JVMTI: "vtable stub" dynamic code notification is misplaced
sspitsyn
parents:
20072
diff
changeset
|
62 |
// 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
|
63 |
// If changing the name, update the other file accordingly. |
1 | 64 |
BufferBlob* blob = BufferBlob::create("vtable chunks", bytes); |
5403
6b0dd9c75dde
6888954: argument formatting for assert() and friends
jcoomes
parents:
3261
diff
changeset
|
65 |
if (blob == NULL) { |
20072 | 66 |
return NULL; |
5403
6b0dd9c75dde
6888954: argument formatting for assert() and friends
jcoomes
parents:
3261
diff
changeset
|
67 |
} |
6418 | 68 |
_chunk = blob->content_begin(); |
1 | 69 |
_chunk_end = _chunk + bytes; |
70 |
Forte::register_stub("vtable stub", _chunk, _chunk_end); |
|
71 |
align_chunk(); |
|
72 |
} |
|
73 |
assert(_chunk + real_size <= _chunk_end, "bad allocation"); |
|
74 |
void* res = _chunk; |
|
75 |
_chunk += real_size; |
|
76 |
align_chunk(); |
|
77 |
return res; |
|
78 |
} |
|
79 |
||
80 |
||
6176
4d9030fe341f
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
5924
diff
changeset
|
81 |
void VtableStub::print_on(outputStream* st) const { |
4d9030fe341f
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
5924
diff
changeset
|
82 |
st->print("vtable stub (index = %d, receiver_location = %d, code = [" INTPTR_FORMAT ", " INTPTR_FORMAT "[)", |
1 | 83 |
index(), receiver_location(), code_begin(), code_end()); |
84 |
} |
|
85 |
||
86 |
||
87 |
// ----------------------------------------------------------------------------------------- |
|
88 |
// Implementation of VtableStubs |
|
89 |
// |
|
90 |
// For each hash value there's a linked list of vtable stubs (with that |
|
91 |
// hash value). Each list is anchored in a little hash _table, indexed |
|
92 |
// by that hash value. |
|
93 |
||
94 |
VtableStub* VtableStubs::_table[VtableStubs::N]; |
|
95 |
int VtableStubs::_number_of_vtable_stubs = 0; |
|
96 |
||
97 |
||
98 |
void VtableStubs::initialize() { |
|
99 |
VtableStub::_receiver_location = SharedRuntime::name_for_receiver(); |
|
100 |
{ |
|
101 |
MutexLocker ml(VtableStubs_lock); |
|
102 |
assert(_number_of_vtable_stubs == 0, "potential performance bug: VtableStubs initialized more than once"); |
|
103 |
assert(is_power_of_2(N), "N must be a power of 2"); |
|
104 |
for (int i = 0; i < N; i++) { |
|
105 |
_table[i] = NULL; |
|
106 |
} |
|
107 |
} |
|
108 |
} |
|
109 |
||
110 |
||
20017
81eba62e9048
8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents:
19696
diff
changeset
|
111 |
address VtableStubs::find_stub(bool is_vtable_stub, int vtable_index) { |
1 | 112 |
assert(vtable_index >= 0, "must be positive"); |
113 |
||
114 |
VtableStub* s = ShareVtableStubs ? lookup(is_vtable_stub, vtable_index) : NULL; |
|
115 |
if (s == NULL) { |
|
116 |
if (is_vtable_stub) { |
|
117 |
s = create_vtable_stub(vtable_index); |
|
118 |
} else { |
|
119 |
s = create_itable_stub(vtable_index); |
|
120 |
} |
|
20072 | 121 |
|
122 |
// Creation of vtable or itable can fail if there is not enough free space in the code cache. |
|
123 |
if (s == NULL) { |
|
124 |
return NULL; |
|
125 |
} |
|
126 |
||
1 | 127 |
enter(is_vtable_stub, vtable_index, s); |
128 |
if (PrintAdapterHandlers) { |
|
129 |
tty->print_cr("Decoding VtableStub %s[%d]@%d", |
|
130 |
is_vtable_stub? "vtbl": "itbl", vtable_index, VtableStub::receiver_location()); |
|
131 |
Disassembler::decode(s->code_begin(), s->code_end()); |
|
132 |
} |
|
22747
f467c14746f5
8025841: JVMTI: "vtable stub" dynamic code notification is misplaced
sspitsyn
parents:
20072
diff
changeset
|
133 |
// Notify JVMTI about this stub. The event will be recorded by the enclosing |
f467c14746f5
8025841: JVMTI: "vtable stub" dynamic code notification is misplaced
sspitsyn
parents:
20072
diff
changeset
|
134 |
// JvmtiDynamicCodeEventCollector and posted when this thread has released |
f467c14746f5
8025841: JVMTI: "vtable stub" dynamic code notification is misplaced
sspitsyn
parents:
20072
diff
changeset
|
135 |
// all locks. |
f467c14746f5
8025841: JVMTI: "vtable stub" dynamic code notification is misplaced
sspitsyn
parents:
20072
diff
changeset
|
136 |
if (JvmtiExport::should_post_dynamic_code_generated()) { |
f467c14746f5
8025841: JVMTI: "vtable stub" dynamic code notification is misplaced
sspitsyn
parents:
20072
diff
changeset
|
137 |
JvmtiExport::post_dynamic_code_generated_while_holding_locks(is_vtable_stub? "vtable stub": "itable stub", |
f467c14746f5
8025841: JVMTI: "vtable stub" dynamic code notification is misplaced
sspitsyn
parents:
20072
diff
changeset
|
138 |
s->code_begin(), s->code_end()); |
f467c14746f5
8025841: JVMTI: "vtable stub" dynamic code notification is misplaced
sspitsyn
parents:
20072
diff
changeset
|
139 |
} |
1 | 140 |
} |
141 |
return s->entry_point(); |
|
142 |
} |
|
143 |
||
144 |
||
145 |
inline uint VtableStubs::hash(bool is_vtable_stub, int vtable_index){ |
|
146 |
// Assumption: receiver_location < 4 in most cases. |
|
147 |
int hash = ((vtable_index << 2) ^ VtableStub::receiver_location()->value()) + vtable_index; |
|
148 |
return (is_vtable_stub ? ~hash : hash) & mask; |
|
149 |
} |
|
150 |
||
151 |
||
152 |
VtableStub* VtableStubs::lookup(bool is_vtable_stub, int vtable_index) { |
|
153 |
MutexLocker ml(VtableStubs_lock); |
|
154 |
unsigned hash = VtableStubs::hash(is_vtable_stub, vtable_index); |
|
155 |
VtableStub* s = _table[hash]; |
|
156 |
while( s && !s->matches(is_vtable_stub, vtable_index)) s = s->next(); |
|
157 |
return s; |
|
158 |
} |
|
159 |
||
160 |
||
161 |
void VtableStubs::enter(bool is_vtable_stub, int vtable_index, VtableStub* s) { |
|
162 |
MutexLocker ml(VtableStubs_lock); |
|
163 |
assert(s->matches(is_vtable_stub, vtable_index), "bad vtable stub"); |
|
164 |
unsigned int h = VtableStubs::hash(is_vtable_stub, vtable_index); |
|
165 |
// enter s at the beginning of the corresponding list |
|
166 |
s->set_next(_table[h]); |
|
167 |
_table[h] = s; |
|
168 |
_number_of_vtable_stubs++; |
|
169 |
} |
|
170 |
||
171 |
||
172 |
bool VtableStubs::is_entry_point(address pc) { |
|
173 |
MutexLocker ml(VtableStubs_lock); |
|
174 |
VtableStub* stub = (VtableStub*)(pc - VtableStub::entry_offset()); |
|
175 |
uint hash = VtableStubs::hash(stub->is_vtable_stub(), stub->index()); |
|
176 |
VtableStub* s; |
|
177 |
for (s = _table[hash]; s != NULL && s != stub; s = s->next()) {} |
|
178 |
return s == stub; |
|
179 |
} |
|
180 |
||
181 |
||
182 |
bool VtableStubs::contains(address pc) { |
|
183 |
// simple solution for now - we may want to use |
|
184 |
// a faster way if this function is called often |
|
185 |
return stub_containing(pc) != NULL; |
|
186 |
} |
|
187 |
||
188 |
||
189 |
VtableStub* VtableStubs::stub_containing(address pc) { |
|
190 |
// Note: No locking needed since any change to the data structure |
|
191 |
// happens with an atomic store into it (we don't care about |
|
192 |
// consistency with the _number_of_vtable_stubs counter). |
|
193 |
for (int i = 0; i < N; i++) { |
|
194 |
for (VtableStub* s = _table[i]; s != NULL; s = s->next()) { |
|
195 |
if (s->contains(pc)) return s; |
|
196 |
} |
|
197 |
} |
|
198 |
return NULL; |
|
199 |
} |
|
200 |
||
201 |
void vtableStubs_init() { |
|
202 |
VtableStubs::initialize(); |
|
203 |
} |
|
204 |
||
22747
f467c14746f5
8025841: JVMTI: "vtable stub" dynamic code notification is misplaced
sspitsyn
parents:
20072
diff
changeset
|
205 |
void VtableStubs::vtable_stub_do(void f(VtableStub*)) { |
f467c14746f5
8025841: JVMTI: "vtable stub" dynamic code notification is misplaced
sspitsyn
parents:
20072
diff
changeset
|
206 |
for (int i = 0; i < N; i++) { |
f467c14746f5
8025841: JVMTI: "vtable stub" dynamic code notification is misplaced
sspitsyn
parents:
20072
diff
changeset
|
207 |
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
|
208 |
f(s); |
f467c14746f5
8025841: JVMTI: "vtable stub" dynamic code notification is misplaced
sspitsyn
parents:
20072
diff
changeset
|
209 |
} |
f467c14746f5
8025841: JVMTI: "vtable stub" dynamic code notification is misplaced
sspitsyn
parents:
20072
diff
changeset
|
210 |
} |
f467c14746f5
8025841: JVMTI: "vtable stub" dynamic code notification is misplaced
sspitsyn
parents:
20072
diff
changeset
|
211 |
} |
f467c14746f5
8025841: JVMTI: "vtable stub" dynamic code notification is misplaced
sspitsyn
parents:
20072
diff
changeset
|
212 |
|
1 | 213 |
|
214 |
//----------------------------------------------------------------------------------------------------- |
|
215 |
// Non-product code |
|
216 |
#ifndef PRODUCT |
|
217 |
||
218 |
extern "C" void bad_compiled_vtable_index(JavaThread* thread, oop receiver, int index) { |
|
219 |
ResourceMark rm; |
|
220 |
HandleMark hm; |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
7397
diff
changeset
|
221 |
Klass* klass = receiver->klass(); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
7397
diff
changeset
|
222 |
InstanceKlass* ik = InstanceKlass::cast(klass); |
1 | 223 |
klassVtable* vt = ik->vtable(); |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
7397
diff
changeset
|
224 |
ik->print(); |
5403
6b0dd9c75dde
6888954: argument formatting for assert() and friends
jcoomes
parents:
3261
diff
changeset
|
225 |
fatal(err_msg("bad compiled vtable dispatch: receiver " INTPTR_FORMAT ", " |
6b0dd9c75dde
6888954: argument formatting for assert() and friends
jcoomes
parents:
3261
diff
changeset
|
226 |
"index %d (vtable length %d)", |
6b0dd9c75dde
6888954: argument formatting for assert() and friends
jcoomes
parents:
3261
diff
changeset
|
227 |
(address)receiver, index, vt->length())); |
1 | 228 |
} |
229 |
||
230 |
#endif // Product |