Mercurial > hg > truffle
annotate src/share/vm/code/vtableStubs.cpp @ 13705:ac5b0f31f7a2
Truffle API-change: FrameDescriptors are now stored in the RootNode in a final field instead of the CallTarget.
author | Christian Humer <christian.humer@gmail.com> |
---|---|
date | Fri, 17 Jan 2014 17:06:08 +0100 |
parents | 891687731b59 |
children | 9341a9963d36 |
rev | line source |
---|---|
0 | 1 /* |
12146
9758d9f36299
8021954: VM SIGSEGV during classloading on MacOS; hs_err_pid file produced
coleenp
parents:
10161
diff
changeset
|
2 * Copyright (c) 1997, 2013, 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 |
42 // ----------------------------------------------------------------------------------------- | |
43 // Implementation of VtableStub | |
44 | |
45 address VtableStub::_chunk = NULL; | |
46 address VtableStub::_chunk_end = NULL; | |
47 VMReg VtableStub::_receiver_location = VMRegImpl::Bad(); | |
48 | |
49 | |
12146
9758d9f36299
8021954: VM SIGSEGV during classloading on MacOS; hs_err_pid file produced
coleenp
parents:
10161
diff
changeset
|
50 void* VtableStub::operator new(size_t size, int code_size) throw() { |
0 | 51 assert(size == sizeof(VtableStub), "mismatched size"); |
52 // compute real VtableStub size (rounded to nearest word) | |
53 const int real_size = round_to(code_size + sizeof(VtableStub), wordSize); | |
54 // malloc them in chunks to minimize header overhead | |
55 const int chunk_factor = 32; | |
56 if (_chunk == NULL || _chunk + real_size > _chunk_end) { | |
57 const int bytes = chunk_factor * real_size + pd_code_alignment(); | |
58 BufferBlob* blob = BufferBlob::create("vtable chunks", bytes); | |
1490
f03d0a26bf83
6888954: argument formatting for assert() and friends
jcoomes
parents:
844
diff
changeset
|
59 if (blob == NULL) { |
12294 | 60 return NULL; |
1490
f03d0a26bf83
6888954: argument formatting for assert() and friends
jcoomes
parents:
844
diff
changeset
|
61 } |
1748 | 62 _chunk = blob->content_begin(); |
0 | 63 _chunk_end = _chunk + bytes; |
64 Forte::register_stub("vtable stub", _chunk, _chunk_end); | |
65 // Notify JVMTI about this stub. The event will be recorded by the enclosing | |
66 // JvmtiDynamicCodeEventCollector and posted when this thread has released | |
67 // all locks. | |
68 if (JvmtiExport::should_post_dynamic_code_generated()) { | |
69 JvmtiExport::post_dynamic_code_generated_while_holding_locks("vtable stub", _chunk, _chunk_end); | |
70 } | |
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 | |
1681
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1644
diff
changeset
|
81 void VtableStub::print_on(outputStream* st) const { |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1644
diff
changeset
|
82 st->print("vtable stub (index = %d, receiver_location = %d, code = [" INTPTR_FORMAT ", " INTPTR_FORMAT "[)", |
0 | 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 | |
12264
b2e698d2276c
8014013: CallInfo structure no longer accurately reports the result of a LinkResolver operation
drchase
parents:
12146
diff
changeset
|
111 address VtableStubs::find_stub(bool is_vtable_stub, int vtable_index) { |
0 | 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 } | |
12294 | 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 | |
0 | 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 } | |
133 } | |
134 return s->entry_point(); | |
135 } | |
136 | |
137 | |
138 inline uint VtableStubs::hash(bool is_vtable_stub, int vtable_index){ | |
139 // Assumption: receiver_location < 4 in most cases. | |
140 int hash = ((vtable_index << 2) ^ VtableStub::receiver_location()->value()) + vtable_index; | |
141 return (is_vtable_stub ? ~hash : hash) & mask; | |
142 } | |
143 | |
144 | |
145 VtableStub* VtableStubs::lookup(bool is_vtable_stub, int vtable_index) { | |
146 MutexLocker ml(VtableStubs_lock); | |
147 unsigned hash = VtableStubs::hash(is_vtable_stub, vtable_index); | |
148 VtableStub* s = _table[hash]; | |
149 while( s && !s->matches(is_vtable_stub, vtable_index)) s = s->next(); | |
150 return s; | |
151 } | |
152 | |
153 | |
154 void VtableStubs::enter(bool is_vtable_stub, int vtable_index, VtableStub* s) { | |
155 MutexLocker ml(VtableStubs_lock); | |
156 assert(s->matches(is_vtable_stub, vtable_index), "bad vtable stub"); | |
157 unsigned int h = VtableStubs::hash(is_vtable_stub, vtable_index); | |
158 // enter s at the beginning of the corresponding list | |
159 s->set_next(_table[h]); | |
160 _table[h] = s; | |
161 _number_of_vtable_stubs++; | |
162 } | |
163 | |
164 | |
165 bool VtableStubs::is_entry_point(address pc) { | |
166 MutexLocker ml(VtableStubs_lock); | |
167 VtableStub* stub = (VtableStub*)(pc - VtableStub::entry_offset()); | |
168 uint hash = VtableStubs::hash(stub->is_vtable_stub(), stub->index()); | |
169 VtableStub* s; | |
170 for (s = _table[hash]; s != NULL && s != stub; s = s->next()) {} | |
171 return s == stub; | |
172 } | |
173 | |
174 | |
175 bool VtableStubs::contains(address pc) { | |
176 // simple solution for now - we may want to use | |
177 // a faster way if this function is called often | |
178 return stub_containing(pc) != NULL; | |
179 } | |
180 | |
181 | |
182 VtableStub* VtableStubs::stub_containing(address pc) { | |
183 // Note: No locking needed since any change to the data structure | |
184 // happens with an atomic store into it (we don't care about | |
185 // consistency with the _number_of_vtable_stubs counter). | |
186 for (int i = 0; i < N; i++) { | |
187 for (VtableStub* s = _table[i]; s != NULL; s = s->next()) { | |
188 if (s->contains(pc)) return s; | |
189 } | |
190 } | |
191 return NULL; | |
192 } | |
193 | |
194 void vtableStubs_init() { | |
195 VtableStubs::initialize(); | |
196 } | |
197 | |
198 | |
199 //----------------------------------------------------------------------------------------------------- | |
200 // Non-product code | |
201 #ifndef PRODUCT | |
202 | |
203 extern "C" void bad_compiled_vtable_index(JavaThread* thread, oop receiver, int index) { | |
204 ResourceMark rm; | |
205 HandleMark hm; | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
1972
diff
changeset
|
206 Klass* klass = receiver->klass(); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
1972
diff
changeset
|
207 InstanceKlass* ik = InstanceKlass::cast(klass); |
0 | 208 klassVtable* vt = ik->vtable(); |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
1972
diff
changeset
|
209 ik->print(); |
1490
f03d0a26bf83
6888954: argument formatting for assert() and friends
jcoomes
parents:
844
diff
changeset
|
210 fatal(err_msg("bad compiled vtable dispatch: receiver " INTPTR_FORMAT ", " |
f03d0a26bf83
6888954: argument formatting for assert() and friends
jcoomes
parents:
844
diff
changeset
|
211 "index %d (vtable length %d)", |
f03d0a26bf83
6888954: argument formatting for assert() and friends
jcoomes
parents:
844
diff
changeset
|
212 (address)receiver, index, vt->length())); |
0 | 213 } |
214 | |
215 #endif // Product |