Mercurial > hg > truffle
annotate src/share/vm/code/vtableStubs.cpp @ 1490:f03d0a26bf83
6888954: argument formatting for assert() and friends
Reviewed-by: kvn, twisti, apetrusenko, never, dcubed
author | jcoomes |
---|---|
date | Thu, 22 Apr 2010 13:23:15 -0700 |
parents | bd02caa94611 |
children | c18cbe5936b8 |
rev | line source |
---|---|
0 | 1 /* |
844 | 2 * Copyright 1997-2009 Sun Microsystems, Inc. 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 * | |
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, | |
20 * CA 95054 USA or visit www.sun.com if you need additional information or | |
21 * have any questions. | |
22 * | |
23 */ | |
24 | |
25 #include "incls/_precompiled.incl" | |
26 #include "incls/_vtableStubs.cpp.incl" | |
27 | |
28 // ----------------------------------------------------------------------------------------- | |
29 // Implementation of VtableStub | |
30 | |
31 address VtableStub::_chunk = NULL; | |
32 address VtableStub::_chunk_end = NULL; | |
33 VMReg VtableStub::_receiver_location = VMRegImpl::Bad(); | |
34 | |
35 static int num_vtable_chunks = 0; | |
36 | |
37 | |
38 void* VtableStub::operator new(size_t size, int code_size) { | |
39 assert(size == sizeof(VtableStub), "mismatched size"); | |
40 num_vtable_chunks++; | |
41 // compute real VtableStub size (rounded to nearest word) | |
42 const int real_size = round_to(code_size + sizeof(VtableStub), wordSize); | |
43 // malloc them in chunks to minimize header overhead | |
44 const int chunk_factor = 32; | |
45 if (_chunk == NULL || _chunk + real_size > _chunk_end) { | |
46 const int bytes = chunk_factor * real_size + pd_code_alignment(); | |
47 BufferBlob* blob = BufferBlob::create("vtable chunks", bytes); | |
1490
f03d0a26bf83
6888954: argument formatting for assert() and friends
jcoomes
parents:
844
diff
changeset
|
48 if (blob == NULL) { |
f03d0a26bf83
6888954: argument formatting for assert() and friends
jcoomes
parents:
844
diff
changeset
|
49 vm_exit_out_of_memory(bytes, "CodeCache: no room for vtable chunks"); |
f03d0a26bf83
6888954: argument formatting for assert() and friends
jcoomes
parents:
844
diff
changeset
|
50 } |
0 | 51 _chunk = blob->instructions_begin(); |
52 _chunk_end = _chunk + bytes; | |
53 VTune::register_stub("vtable stub", _chunk, _chunk_end); | |
54 Forte::register_stub("vtable stub", _chunk, _chunk_end); | |
55 // Notify JVMTI about this stub. The event will be recorded by the enclosing | |
56 // JvmtiDynamicCodeEventCollector and posted when this thread has released | |
57 // all locks. | |
58 if (JvmtiExport::should_post_dynamic_code_generated()) { | |
59 JvmtiExport::post_dynamic_code_generated_while_holding_locks("vtable stub", _chunk, _chunk_end); | |
60 } | |
61 align_chunk(); | |
62 } | |
63 assert(_chunk + real_size <= _chunk_end, "bad allocation"); | |
64 void* res = _chunk; | |
65 _chunk += real_size; | |
66 align_chunk(); | |
67 return res; | |
68 } | |
69 | |
70 | |
71 void VtableStub::print() { | |
72 tty->print("vtable stub (index = %d, receiver_location = %d, code = [" INTPTR_FORMAT ", " INTPTR_FORMAT "[)", | |
73 index(), receiver_location(), code_begin(), code_end()); | |
74 } | |
75 | |
76 | |
77 // ----------------------------------------------------------------------------------------- | |
78 // Implementation of VtableStubs | |
79 // | |
80 // For each hash value there's a linked list of vtable stubs (with that | |
81 // hash value). Each list is anchored in a little hash _table, indexed | |
82 // by that hash value. | |
83 | |
84 VtableStub* VtableStubs::_table[VtableStubs::N]; | |
85 int VtableStubs::_number_of_vtable_stubs = 0; | |
86 | |
87 | |
88 void VtableStubs::initialize() { | |
89 VtableStub::_receiver_location = SharedRuntime::name_for_receiver(); | |
90 { | |
91 MutexLocker ml(VtableStubs_lock); | |
92 assert(_number_of_vtable_stubs == 0, "potential performance bug: VtableStubs initialized more than once"); | |
93 assert(is_power_of_2(N), "N must be a power of 2"); | |
94 for (int i = 0; i < N; i++) { | |
95 _table[i] = NULL; | |
96 } | |
97 } | |
98 } | |
99 | |
100 | |
101 address VtableStubs::create_stub(bool is_vtable_stub, int vtable_index, methodOop method) { | |
102 assert(vtable_index >= 0, "must be positive"); | |
103 | |
104 VtableStub* s = ShareVtableStubs ? lookup(is_vtable_stub, vtable_index) : NULL; | |
105 if (s == NULL) { | |
106 if (is_vtable_stub) { | |
107 s = create_vtable_stub(vtable_index); | |
108 } else { | |
109 s = create_itable_stub(vtable_index); | |
110 } | |
111 enter(is_vtable_stub, vtable_index, s); | |
112 if (PrintAdapterHandlers) { | |
113 tty->print_cr("Decoding VtableStub %s[%d]@%d", | |
114 is_vtable_stub? "vtbl": "itbl", vtable_index, VtableStub::receiver_location()); | |
115 Disassembler::decode(s->code_begin(), s->code_end()); | |
116 } | |
117 } | |
118 return s->entry_point(); | |
119 } | |
120 | |
121 | |
122 inline uint VtableStubs::hash(bool is_vtable_stub, int vtable_index){ | |
123 // Assumption: receiver_location < 4 in most cases. | |
124 int hash = ((vtable_index << 2) ^ VtableStub::receiver_location()->value()) + vtable_index; | |
125 return (is_vtable_stub ? ~hash : hash) & mask; | |
126 } | |
127 | |
128 | |
129 VtableStub* VtableStubs::lookup(bool is_vtable_stub, int vtable_index) { | |
130 MutexLocker ml(VtableStubs_lock); | |
131 unsigned hash = VtableStubs::hash(is_vtable_stub, vtable_index); | |
132 VtableStub* s = _table[hash]; | |
133 while( s && !s->matches(is_vtable_stub, vtable_index)) s = s->next(); | |
134 return s; | |
135 } | |
136 | |
137 | |
138 void VtableStubs::enter(bool is_vtable_stub, int vtable_index, VtableStub* s) { | |
139 MutexLocker ml(VtableStubs_lock); | |
140 assert(s->matches(is_vtable_stub, vtable_index), "bad vtable stub"); | |
141 unsigned int h = VtableStubs::hash(is_vtable_stub, vtable_index); | |
142 // enter s at the beginning of the corresponding list | |
143 s->set_next(_table[h]); | |
144 _table[h] = s; | |
145 _number_of_vtable_stubs++; | |
146 } | |
147 | |
148 | |
149 bool VtableStubs::is_entry_point(address pc) { | |
150 MutexLocker ml(VtableStubs_lock); | |
151 VtableStub* stub = (VtableStub*)(pc - VtableStub::entry_offset()); | |
152 uint hash = VtableStubs::hash(stub->is_vtable_stub(), stub->index()); | |
153 VtableStub* s; | |
154 for (s = _table[hash]; s != NULL && s != stub; s = s->next()) {} | |
155 return s == stub; | |
156 } | |
157 | |
158 | |
159 bool VtableStubs::contains(address pc) { | |
160 // simple solution for now - we may want to use | |
161 // a faster way if this function is called often | |
162 return stub_containing(pc) != NULL; | |
163 } | |
164 | |
165 | |
166 VtableStub* VtableStubs::stub_containing(address pc) { | |
167 // Note: No locking needed since any change to the data structure | |
168 // happens with an atomic store into it (we don't care about | |
169 // consistency with the _number_of_vtable_stubs counter). | |
170 for (int i = 0; i < N; i++) { | |
171 for (VtableStub* s = _table[i]; s != NULL; s = s->next()) { | |
172 if (s->contains(pc)) return s; | |
173 } | |
174 } | |
175 return NULL; | |
176 } | |
177 | |
178 void vtableStubs_init() { | |
179 VtableStubs::initialize(); | |
180 } | |
181 | |
182 | |
183 //----------------------------------------------------------------------------------------------------- | |
184 // Non-product code | |
185 #ifndef PRODUCT | |
186 | |
187 extern "C" void bad_compiled_vtable_index(JavaThread* thread, oop receiver, int index) { | |
188 ResourceMark rm; | |
189 HandleMark hm; | |
190 klassOop klass = receiver->klass(); | |
191 instanceKlass* ik = instanceKlass::cast(klass); | |
192 klassVtable* vt = ik->vtable(); | |
193 klass->print(); | |
1490
f03d0a26bf83
6888954: argument formatting for assert() and friends
jcoomes
parents:
844
diff
changeset
|
194 fatal(err_msg("bad compiled vtable dispatch: receiver " INTPTR_FORMAT ", " |
f03d0a26bf83
6888954: argument formatting for assert() and friends
jcoomes
parents:
844
diff
changeset
|
195 "index %d (vtable length %d)", |
f03d0a26bf83
6888954: argument formatting for assert() and friends
jcoomes
parents:
844
diff
changeset
|
196 (address)receiver, index, vt->length())); |
0 | 197 } |
198 | |
199 #endif // Product |