Mercurial > hg > truffle
annotate src/share/vm/code/vtableStubs.cpp @ 21167:ab451b6de9f8
Interop: introduce separate global language scope
author | Matthias Grimmer <grimmer@ssw.jku.at> |
---|---|
date | Thu, 30 Apr 2015 17:27:53 +0200 |
parents | 52b4284cb496 |
children |
rev | line source |
---|---|
0 | 1 /* |
17937
78bbf4d43a14
8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents:
14330
diff
changeset
|
2 * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. |
0 | 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 * | |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1490
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1490
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1490
diff
changeset
|
21 * questions. |
0 | 22 * |
23 */ | |
24 | |
1972 | 25 #include "precompiled.hpp" |
26 #include "code/vtableStubs.hpp" | |
27 #include "compiler/disassembler.hpp" | |
28 #include "memory/allocation.inline.hpp" | |
29 #include "memory/resourceArea.hpp" | |
30 #include "oops/instanceKlass.hpp" | |
31 #include "oops/klassVtable.hpp" | |
32 #include "oops/oop.inline.hpp" | |
33 #include "prims/forte.hpp" | |
34 #include "prims/jvmtiExport.hpp" | |
35 #include "runtime/handles.inline.hpp" | |
36 #include "runtime/mutexLocker.hpp" | |
37 #include "runtime/sharedRuntime.hpp" | |
38 #ifdef COMPILER2 | |
39 #include "opto/matcher.hpp" | |
40 #endif | |
0 | 41 |
17937
78bbf4d43a14
8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents:
14330
diff
changeset
|
42 PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC |
78bbf4d43a14
8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents:
14330
diff
changeset
|
43 |
0 | 44 // ----------------------------------------------------------------------------------------- |
45 // Implementation of VtableStub | |
46 | |
47 address VtableStub::_chunk = NULL; | |
48 address VtableStub::_chunk_end = NULL; | |
49 VMReg VtableStub::_receiver_location = VMRegImpl::Bad(); | |
50 | |
51 | |
12146
9758d9f36299
8021954: VM SIGSEGV during classloading on MacOS; hs_err_pid file produced
coleenp
parents:
10161
diff
changeset
|
52 void* VtableStub::operator new(size_t size, int code_size) throw() { |
0 | 53 assert(size == sizeof(VtableStub), "mismatched size"); |
54 // compute real VtableStub size (rounded to nearest word) | |
55 const int real_size = round_to(code_size + sizeof(VtableStub), wordSize); | |
56 // malloc them in chunks to minimize header overhead | |
57 const int chunk_factor = 32; | |
58 if (_chunk == NULL || _chunk + real_size > _chunk_end) { | |
59 const int bytes = chunk_factor * real_size + pd_code_alignment(); | |
14330
9341a9963d36
8025841: JVMTI: "vtable stub" dynamic code notification is misplaced
sspitsyn
parents:
12294
diff
changeset
|
60 |
9341a9963d36
8025841: JVMTI: "vtable stub" dynamic code notification is misplaced
sspitsyn
parents:
12294
diff
changeset
|
61 // There is a dependency on the name of the blob in src/share/vm/prims/jvmtiCodeBlobEvents.cpp |
9341a9963d36
8025841: JVMTI: "vtable stub" dynamic code notification is misplaced
sspitsyn
parents:
12294
diff
changeset
|
62 // If changing the name, update the other file accordingly. |
0 | 63 BufferBlob* blob = BufferBlob::create("vtable chunks", bytes); |
1490
f03d0a26bf83
6888954: argument formatting for assert() and friends
jcoomes
parents:
844
diff
changeset
|
64 if (blob == NULL) { |
12294 | 65 return NULL; |
1490
f03d0a26bf83
6888954: argument formatting for assert() and friends
jcoomes
parents:
844
diff
changeset
|
66 } |
1748 | 67 _chunk = blob->content_begin(); |
0 | 68 _chunk_end = _chunk + bytes; |
69 Forte::register_stub("vtable stub", _chunk, _chunk_end); | |
70 align_chunk(); | |
71 } | |
72 assert(_chunk + real_size <= _chunk_end, "bad allocation"); | |
73 void* res = _chunk; | |
74 _chunk += real_size; | |
75 align_chunk(); | |
76 return res; | |
77 } | |
78 | |
79 | |
1681
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1644
diff
changeset
|
80 void VtableStub::print_on(outputStream* st) const { |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1644
diff
changeset
|
81 st->print("vtable stub (index = %d, receiver_location = %d, code = [" INTPTR_FORMAT ", " INTPTR_FORMAT "[)", |
0 | 82 index(), receiver_location(), code_begin(), code_end()); |
83 } | |
84 | |
85 | |
86 // ----------------------------------------------------------------------------------------- | |
87 // Implementation of VtableStubs | |
88 // | |
89 // For each hash value there's a linked list of vtable stubs (with that | |
90 // hash value). Each list is anchored in a little hash _table, indexed | |
91 // by that hash value. | |
92 | |
93 VtableStub* VtableStubs::_table[VtableStubs::N]; | |
94 int VtableStubs::_number_of_vtable_stubs = 0; | |
95 | |
96 | |
97 void VtableStubs::initialize() { | |
98 VtableStub::_receiver_location = SharedRuntime::name_for_receiver(); | |
99 { | |
100 MutexLocker ml(VtableStubs_lock); | |
101 assert(_number_of_vtable_stubs == 0, "potential performance bug: VtableStubs initialized more than once"); | |
102 assert(is_power_of_2(N), "N must be a power of 2"); | |
103 for (int i = 0; i < N; i++) { | |
104 _table[i] = NULL; | |
105 } | |
106 } | |
107 } | |
108 | |
109 | |
12264
b2e698d2276c
8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents:
12146
diff
changeset
|
110 address VtableStubs::find_stub(bool is_vtable_stub, int vtable_index) { |
0 | 111 assert(vtable_index >= 0, "must be positive"); |
112 | |
113 VtableStub* s = ShareVtableStubs ? lookup(is_vtable_stub, vtable_index) : NULL; | |
114 if (s == NULL) { | |
115 if (is_vtable_stub) { | |
116 s = create_vtable_stub(vtable_index); | |
117 } else { | |
118 s = create_itable_stub(vtable_index); | |
119 } | |
12294 | 120 |
121 // Creation of vtable or itable can fail if there is not enough free space in the code cache. | |
122 if (s == NULL) { | |
123 return NULL; | |
124 } | |
125 | |
0 | 126 enter(is_vtable_stub, vtable_index, s); |
127 if (PrintAdapterHandlers) { | |
128 tty->print_cr("Decoding VtableStub %s[%d]@%d", | |
129 is_vtable_stub? "vtbl": "itbl", vtable_index, VtableStub::receiver_location()); | |
130 Disassembler::decode(s->code_begin(), s->code_end()); | |
131 } | |
14330
9341a9963d36
8025841: JVMTI: "vtable stub" dynamic code notification is misplaced
sspitsyn
parents:
12294
diff
changeset
|
132 // Notify JVMTI about this stub. The event will be recorded by the enclosing |
9341a9963d36
8025841: JVMTI: "vtable stub" dynamic code notification is misplaced
sspitsyn
parents:
12294
diff
changeset
|
133 // JvmtiDynamicCodeEventCollector and posted when this thread has released |
9341a9963d36
8025841: JVMTI: "vtable stub" dynamic code notification is misplaced
sspitsyn
parents:
12294
diff
changeset
|
134 // all locks. |
9341a9963d36
8025841: JVMTI: "vtable stub" dynamic code notification is misplaced
sspitsyn
parents:
12294
diff
changeset
|
135 if (JvmtiExport::should_post_dynamic_code_generated()) { |
9341a9963d36
8025841: JVMTI: "vtable stub" dynamic code notification is misplaced
sspitsyn
parents:
12294
diff
changeset
|
136 JvmtiExport::post_dynamic_code_generated_while_holding_locks(is_vtable_stub? "vtable stub": "itable stub", |
9341a9963d36
8025841: JVMTI: "vtable stub" dynamic code notification is misplaced
sspitsyn
parents:
12294
diff
changeset
|
137 s->code_begin(), s->code_end()); |
9341a9963d36
8025841: JVMTI: "vtable stub" dynamic code notification is misplaced
sspitsyn
parents:
12294
diff
changeset
|
138 } |
0 | 139 } |
140 return s->entry_point(); | |
141 } | |
142 | |
143 | |
144 inline uint VtableStubs::hash(bool is_vtable_stub, int vtable_index){ | |
145 // Assumption: receiver_location < 4 in most cases. | |
146 int hash = ((vtable_index << 2) ^ VtableStub::receiver_location()->value()) + vtable_index; | |
147 return (is_vtable_stub ? ~hash : hash) & mask; | |
148 } | |
149 | |
150 | |
151 VtableStub* VtableStubs::lookup(bool is_vtable_stub, int vtable_index) { | |
152 MutexLocker ml(VtableStubs_lock); | |
153 unsigned hash = VtableStubs::hash(is_vtable_stub, vtable_index); | |
154 VtableStub* s = _table[hash]; | |
155 while( s && !s->matches(is_vtable_stub, vtable_index)) s = s->next(); | |
156 return s; | |
157 } | |
158 | |
159 | |
160 void VtableStubs::enter(bool is_vtable_stub, int vtable_index, VtableStub* s) { | |
161 MutexLocker ml(VtableStubs_lock); | |
162 assert(s->matches(is_vtable_stub, vtable_index), "bad vtable stub"); | |
163 unsigned int h = VtableStubs::hash(is_vtable_stub, vtable_index); | |
164 // enter s at the beginning of the corresponding list | |
165 s->set_next(_table[h]); | |
166 _table[h] = s; | |
167 _number_of_vtable_stubs++; | |
168 } | |
169 | |
170 | |
171 bool VtableStubs::is_entry_point(address pc) { | |
172 MutexLocker ml(VtableStubs_lock); | |
173 VtableStub* stub = (VtableStub*)(pc - VtableStub::entry_offset()); | |
174 uint hash = VtableStubs::hash(stub->is_vtable_stub(), stub->index()); | |
175 VtableStub* s; | |
176 for (s = _table[hash]; s != NULL && s != stub; s = s->next()) {} | |
177 return s == stub; | |
178 } | |
179 | |
180 | |
181 bool VtableStubs::contains(address pc) { | |
182 // simple solution for now - we may want to use | |
183 // a faster way if this function is called often | |
184 return stub_containing(pc) != NULL; | |
185 } | |
186 | |
187 | |
188 VtableStub* VtableStubs::stub_containing(address pc) { | |
189 // Note: No locking needed since any change to the data structure | |
190 // happens with an atomic store into it (we don't care about | |
191 // consistency with the _number_of_vtable_stubs counter). | |
192 for (int i = 0; i < N; i++) { | |
193 for (VtableStub* s = _table[i]; s != NULL; s = s->next()) { | |
194 if (s->contains(pc)) return s; | |
195 } | |
196 } | |
197 return NULL; | |
198 } | |
199 | |
200 void vtableStubs_init() { | |
201 VtableStubs::initialize(); | |
202 } | |
203 | |
14330
9341a9963d36
8025841: JVMTI: "vtable stub" dynamic code notification is misplaced
sspitsyn
parents:
12294
diff
changeset
|
204 void VtableStubs::vtable_stub_do(void f(VtableStub*)) { |
9341a9963d36
8025841: JVMTI: "vtable stub" dynamic code notification is misplaced
sspitsyn
parents:
12294
diff
changeset
|
205 for (int i = 0; i < N; i++) { |
9341a9963d36
8025841: JVMTI: "vtable stub" dynamic code notification is misplaced
sspitsyn
parents:
12294
diff
changeset
|
206 for (VtableStub* s = _table[i]; s != NULL; s = s->next()) { |
9341a9963d36
8025841: JVMTI: "vtable stub" dynamic code notification is misplaced
sspitsyn
parents:
12294
diff
changeset
|
207 f(s); |
9341a9963d36
8025841: JVMTI: "vtable stub" dynamic code notification is misplaced
sspitsyn
parents:
12294
diff
changeset
|
208 } |
9341a9963d36
8025841: JVMTI: "vtable stub" dynamic code notification is misplaced
sspitsyn
parents:
12294
diff
changeset
|
209 } |
9341a9963d36
8025841: JVMTI: "vtable stub" dynamic code notification is misplaced
sspitsyn
parents:
12294
diff
changeset
|
210 } |
9341a9963d36
8025841: JVMTI: "vtable stub" dynamic code notification is misplaced
sspitsyn
parents:
12294
diff
changeset
|
211 |
0 | 212 |
213 //----------------------------------------------------------------------------------------------------- | |
214 // Non-product code | |
215 #ifndef PRODUCT | |
216 | |
217 extern "C" void bad_compiled_vtable_index(JavaThread* thread, oop receiver, int index) { | |
218 ResourceMark rm; | |
219 HandleMark hm; | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
1972
diff
changeset
|
220 Klass* klass = receiver->klass(); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
1972
diff
changeset
|
221 InstanceKlass* ik = InstanceKlass::cast(klass); |
0 | 222 klassVtable* vt = ik->vtable(); |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
1972
diff
changeset
|
223 ik->print(); |
1490
f03d0a26bf83
6888954: argument formatting for assert() and friends
jcoomes
parents:
844
diff
changeset
|
224 fatal(err_msg("bad compiled vtable dispatch: receiver " INTPTR_FORMAT ", " |
f03d0a26bf83
6888954: argument formatting for assert() and friends
jcoomes
parents:
844
diff
changeset
|
225 "index %d (vtable length %d)", |
f03d0a26bf83
6888954: argument formatting for assert() and friends
jcoomes
parents:
844
diff
changeset
|
226 (address)receiver, index, vt->length())); |
0 | 227 } |
228 | |
229 #endif // Product |