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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
844
bd02caa94611 6862919: Update copyright year
xdono
parents: 709
diff changeset
2 * Copyright 1997-2009 Sun Microsystems, Inc. All Rights Reserved.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
18 *
a61af66fc99e Initial load
duke
parents:
diff changeset
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
a61af66fc99e Initial load
duke
parents:
diff changeset
20 * CA 95054 USA or visit www.sun.com if you need additional information or
a61af66fc99e Initial load
duke
parents:
diff changeset
21 * have any questions.
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
a61af66fc99e Initial load
duke
parents:
diff changeset
25 #include "incls/_precompiled.incl"
a61af66fc99e Initial load
duke
parents:
diff changeset
26 #include "incls/_vtableStubs.cpp.incl"
a61af66fc99e Initial load
duke
parents:
diff changeset
27
a61af66fc99e Initial load
duke
parents:
diff changeset
28 // -----------------------------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
29 // Implementation of VtableStub
a61af66fc99e Initial load
duke
parents:
diff changeset
30
a61af66fc99e Initial load
duke
parents:
diff changeset
31 address VtableStub::_chunk = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
32 address VtableStub::_chunk_end = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
33 VMReg VtableStub::_receiver_location = VMRegImpl::Bad();
a61af66fc99e Initial load
duke
parents:
diff changeset
34
a61af66fc99e Initial load
duke
parents:
diff changeset
35 static int num_vtable_chunks = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
36
a61af66fc99e Initial load
duke
parents:
diff changeset
37
a61af66fc99e Initial load
duke
parents:
diff changeset
38 void* VtableStub::operator new(size_t size, int code_size) {
a61af66fc99e Initial load
duke
parents:
diff changeset
39 assert(size == sizeof(VtableStub), "mismatched size");
a61af66fc99e Initial load
duke
parents:
diff changeset
40 num_vtable_chunks++;
a61af66fc99e Initial load
duke
parents:
diff changeset
41 // compute real VtableStub size (rounded to nearest word)
a61af66fc99e Initial load
duke
parents:
diff changeset
42 const int real_size = round_to(code_size + sizeof(VtableStub), wordSize);
a61af66fc99e Initial load
duke
parents:
diff changeset
43 // malloc them in chunks to minimize header overhead
a61af66fc99e Initial load
duke
parents:
diff changeset
44 const int chunk_factor = 32;
a61af66fc99e Initial load
duke
parents:
diff changeset
45 if (_chunk == NULL || _chunk + real_size > _chunk_end) {
a61af66fc99e Initial load
duke
parents:
diff changeset
46 const int bytes = chunk_factor * real_size + pd_code_alignment();
a61af66fc99e Initial load
duke
parents:
diff changeset
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
a61af66fc99e Initial load
duke
parents:
diff changeset
51 _chunk = blob->instructions_begin();
a61af66fc99e Initial load
duke
parents:
diff changeset
52 _chunk_end = _chunk + bytes;
a61af66fc99e Initial load
duke
parents:
diff changeset
53 VTune::register_stub("vtable stub", _chunk, _chunk_end);
a61af66fc99e Initial load
duke
parents:
diff changeset
54 Forte::register_stub("vtable stub", _chunk, _chunk_end);
a61af66fc99e Initial load
duke
parents:
diff changeset
55 // Notify JVMTI about this stub. The event will be recorded by the enclosing
a61af66fc99e Initial load
duke
parents:
diff changeset
56 // JvmtiDynamicCodeEventCollector and posted when this thread has released
a61af66fc99e Initial load
duke
parents:
diff changeset
57 // all locks.
a61af66fc99e Initial load
duke
parents:
diff changeset
58 if (JvmtiExport::should_post_dynamic_code_generated()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
59 JvmtiExport::post_dynamic_code_generated_while_holding_locks("vtable stub", _chunk, _chunk_end);
a61af66fc99e Initial load
duke
parents:
diff changeset
60 }
a61af66fc99e Initial load
duke
parents:
diff changeset
61 align_chunk();
a61af66fc99e Initial load
duke
parents:
diff changeset
62 }
a61af66fc99e Initial load
duke
parents:
diff changeset
63 assert(_chunk + real_size <= _chunk_end, "bad allocation");
a61af66fc99e Initial load
duke
parents:
diff changeset
64 void* res = _chunk;
a61af66fc99e Initial load
duke
parents:
diff changeset
65 _chunk += real_size;
a61af66fc99e Initial load
duke
parents:
diff changeset
66 align_chunk();
a61af66fc99e Initial load
duke
parents:
diff changeset
67 return res;
a61af66fc99e Initial load
duke
parents:
diff changeset
68 }
a61af66fc99e Initial load
duke
parents:
diff changeset
69
a61af66fc99e Initial load
duke
parents:
diff changeset
70
a61af66fc99e Initial load
duke
parents:
diff changeset
71 void VtableStub::print() {
a61af66fc99e Initial load
duke
parents:
diff changeset
72 tty->print("vtable stub (index = %d, receiver_location = %d, code = [" INTPTR_FORMAT ", " INTPTR_FORMAT "[)",
a61af66fc99e Initial load
duke
parents:
diff changeset
73 index(), receiver_location(), code_begin(), code_end());
a61af66fc99e Initial load
duke
parents:
diff changeset
74 }
a61af66fc99e Initial load
duke
parents:
diff changeset
75
a61af66fc99e Initial load
duke
parents:
diff changeset
76
a61af66fc99e Initial load
duke
parents:
diff changeset
77 // -----------------------------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
78 // Implementation of VtableStubs
a61af66fc99e Initial load
duke
parents:
diff changeset
79 //
a61af66fc99e Initial load
duke
parents:
diff changeset
80 // For each hash value there's a linked list of vtable stubs (with that
a61af66fc99e Initial load
duke
parents:
diff changeset
81 // hash value). Each list is anchored in a little hash _table, indexed
a61af66fc99e Initial load
duke
parents:
diff changeset
82 // by that hash value.
a61af66fc99e Initial load
duke
parents:
diff changeset
83
a61af66fc99e Initial load
duke
parents:
diff changeset
84 VtableStub* VtableStubs::_table[VtableStubs::N];
a61af66fc99e Initial load
duke
parents:
diff changeset
85 int VtableStubs::_number_of_vtable_stubs = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
86
a61af66fc99e Initial load
duke
parents:
diff changeset
87
a61af66fc99e Initial load
duke
parents:
diff changeset
88 void VtableStubs::initialize() {
a61af66fc99e Initial load
duke
parents:
diff changeset
89 VtableStub::_receiver_location = SharedRuntime::name_for_receiver();
a61af66fc99e Initial load
duke
parents:
diff changeset
90 {
a61af66fc99e Initial load
duke
parents:
diff changeset
91 MutexLocker ml(VtableStubs_lock);
a61af66fc99e Initial load
duke
parents:
diff changeset
92 assert(_number_of_vtable_stubs == 0, "potential performance bug: VtableStubs initialized more than once");
a61af66fc99e Initial load
duke
parents:
diff changeset
93 assert(is_power_of_2(N), "N must be a power of 2");
a61af66fc99e Initial load
duke
parents:
diff changeset
94 for (int i = 0; i < N; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
95 _table[i] = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
96 }
a61af66fc99e Initial load
duke
parents:
diff changeset
97 }
a61af66fc99e Initial load
duke
parents:
diff changeset
98 }
a61af66fc99e Initial load
duke
parents:
diff changeset
99
a61af66fc99e Initial load
duke
parents:
diff changeset
100
a61af66fc99e Initial load
duke
parents:
diff changeset
101 address VtableStubs::create_stub(bool is_vtable_stub, int vtable_index, methodOop method) {
a61af66fc99e Initial load
duke
parents:
diff changeset
102 assert(vtable_index >= 0, "must be positive");
a61af66fc99e Initial load
duke
parents:
diff changeset
103
a61af66fc99e Initial load
duke
parents:
diff changeset
104 VtableStub* s = ShareVtableStubs ? lookup(is_vtable_stub, vtable_index) : NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
105 if (s == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
106 if (is_vtable_stub) {
a61af66fc99e Initial load
duke
parents:
diff changeset
107 s = create_vtable_stub(vtable_index);
a61af66fc99e Initial load
duke
parents:
diff changeset
108 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
109 s = create_itable_stub(vtable_index);
a61af66fc99e Initial load
duke
parents:
diff changeset
110 }
a61af66fc99e Initial load
duke
parents:
diff changeset
111 enter(is_vtable_stub, vtable_index, s);
a61af66fc99e Initial load
duke
parents:
diff changeset
112 if (PrintAdapterHandlers) {
a61af66fc99e Initial load
duke
parents:
diff changeset
113 tty->print_cr("Decoding VtableStub %s[%d]@%d",
a61af66fc99e Initial load
duke
parents:
diff changeset
114 is_vtable_stub? "vtbl": "itbl", vtable_index, VtableStub::receiver_location());
a61af66fc99e Initial load
duke
parents:
diff changeset
115 Disassembler::decode(s->code_begin(), s->code_end());
a61af66fc99e Initial load
duke
parents:
diff changeset
116 }
a61af66fc99e Initial load
duke
parents:
diff changeset
117 }
a61af66fc99e Initial load
duke
parents:
diff changeset
118 return s->entry_point();
a61af66fc99e Initial load
duke
parents:
diff changeset
119 }
a61af66fc99e Initial load
duke
parents:
diff changeset
120
a61af66fc99e Initial load
duke
parents:
diff changeset
121
a61af66fc99e Initial load
duke
parents:
diff changeset
122 inline uint VtableStubs::hash(bool is_vtable_stub, int vtable_index){
a61af66fc99e Initial load
duke
parents:
diff changeset
123 // Assumption: receiver_location < 4 in most cases.
a61af66fc99e Initial load
duke
parents:
diff changeset
124 int hash = ((vtable_index << 2) ^ VtableStub::receiver_location()->value()) + vtable_index;
a61af66fc99e Initial load
duke
parents:
diff changeset
125 return (is_vtable_stub ? ~hash : hash) & mask;
a61af66fc99e Initial load
duke
parents:
diff changeset
126 }
a61af66fc99e Initial load
duke
parents:
diff changeset
127
a61af66fc99e Initial load
duke
parents:
diff changeset
128
a61af66fc99e Initial load
duke
parents:
diff changeset
129 VtableStub* VtableStubs::lookup(bool is_vtable_stub, int vtable_index) {
a61af66fc99e Initial load
duke
parents:
diff changeset
130 MutexLocker ml(VtableStubs_lock);
a61af66fc99e Initial load
duke
parents:
diff changeset
131 unsigned hash = VtableStubs::hash(is_vtable_stub, vtable_index);
a61af66fc99e Initial load
duke
parents:
diff changeset
132 VtableStub* s = _table[hash];
a61af66fc99e Initial load
duke
parents:
diff changeset
133 while( s && !s->matches(is_vtable_stub, vtable_index)) s = s->next();
a61af66fc99e Initial load
duke
parents:
diff changeset
134 return s;
a61af66fc99e Initial load
duke
parents:
diff changeset
135 }
a61af66fc99e Initial load
duke
parents:
diff changeset
136
a61af66fc99e Initial load
duke
parents:
diff changeset
137
a61af66fc99e Initial load
duke
parents:
diff changeset
138 void VtableStubs::enter(bool is_vtable_stub, int vtable_index, VtableStub* s) {
a61af66fc99e Initial load
duke
parents:
diff changeset
139 MutexLocker ml(VtableStubs_lock);
a61af66fc99e Initial load
duke
parents:
diff changeset
140 assert(s->matches(is_vtable_stub, vtable_index), "bad vtable stub");
a61af66fc99e Initial load
duke
parents:
diff changeset
141 unsigned int h = VtableStubs::hash(is_vtable_stub, vtable_index);
a61af66fc99e Initial load
duke
parents:
diff changeset
142 // enter s at the beginning of the corresponding list
a61af66fc99e Initial load
duke
parents:
diff changeset
143 s->set_next(_table[h]);
a61af66fc99e Initial load
duke
parents:
diff changeset
144 _table[h] = s;
a61af66fc99e Initial load
duke
parents:
diff changeset
145 _number_of_vtable_stubs++;
a61af66fc99e Initial load
duke
parents:
diff changeset
146 }
a61af66fc99e Initial load
duke
parents:
diff changeset
147
a61af66fc99e Initial load
duke
parents:
diff changeset
148
a61af66fc99e Initial load
duke
parents:
diff changeset
149 bool VtableStubs::is_entry_point(address pc) {
a61af66fc99e Initial load
duke
parents:
diff changeset
150 MutexLocker ml(VtableStubs_lock);
a61af66fc99e Initial load
duke
parents:
diff changeset
151 VtableStub* stub = (VtableStub*)(pc - VtableStub::entry_offset());
a61af66fc99e Initial load
duke
parents:
diff changeset
152 uint hash = VtableStubs::hash(stub->is_vtable_stub(), stub->index());
a61af66fc99e Initial load
duke
parents:
diff changeset
153 VtableStub* s;
a61af66fc99e Initial load
duke
parents:
diff changeset
154 for (s = _table[hash]; s != NULL && s != stub; s = s->next()) {}
a61af66fc99e Initial load
duke
parents:
diff changeset
155 return s == stub;
a61af66fc99e Initial load
duke
parents:
diff changeset
156 }
a61af66fc99e Initial load
duke
parents:
diff changeset
157
a61af66fc99e Initial load
duke
parents:
diff changeset
158
a61af66fc99e Initial load
duke
parents:
diff changeset
159 bool VtableStubs::contains(address pc) {
a61af66fc99e Initial load
duke
parents:
diff changeset
160 // simple solution for now - we may want to use
a61af66fc99e Initial load
duke
parents:
diff changeset
161 // a faster way if this function is called often
a61af66fc99e Initial load
duke
parents:
diff changeset
162 return stub_containing(pc) != NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
163 }
a61af66fc99e Initial load
duke
parents:
diff changeset
164
a61af66fc99e Initial load
duke
parents:
diff changeset
165
a61af66fc99e Initial load
duke
parents:
diff changeset
166 VtableStub* VtableStubs::stub_containing(address pc) {
a61af66fc99e Initial load
duke
parents:
diff changeset
167 // Note: No locking needed since any change to the data structure
a61af66fc99e Initial load
duke
parents:
diff changeset
168 // happens with an atomic store into it (we don't care about
a61af66fc99e Initial load
duke
parents:
diff changeset
169 // consistency with the _number_of_vtable_stubs counter).
a61af66fc99e Initial load
duke
parents:
diff changeset
170 for (int i = 0; i < N; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
171 for (VtableStub* s = _table[i]; s != NULL; s = s->next()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
172 if (s->contains(pc)) return s;
a61af66fc99e Initial load
duke
parents:
diff changeset
173 }
a61af66fc99e Initial load
duke
parents:
diff changeset
174 }
a61af66fc99e Initial load
duke
parents:
diff changeset
175 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
176 }
a61af66fc99e Initial load
duke
parents:
diff changeset
177
a61af66fc99e Initial load
duke
parents:
diff changeset
178 void vtableStubs_init() {
a61af66fc99e Initial load
duke
parents:
diff changeset
179 VtableStubs::initialize();
a61af66fc99e Initial load
duke
parents:
diff changeset
180 }
a61af66fc99e Initial load
duke
parents:
diff changeset
181
a61af66fc99e Initial load
duke
parents:
diff changeset
182
a61af66fc99e Initial load
duke
parents:
diff changeset
183 //-----------------------------------------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
184 // Non-product code
a61af66fc99e Initial load
duke
parents:
diff changeset
185 #ifndef PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
186
a61af66fc99e Initial load
duke
parents:
diff changeset
187 extern "C" void bad_compiled_vtable_index(JavaThread* thread, oop receiver, int index) {
a61af66fc99e Initial load
duke
parents:
diff changeset
188 ResourceMark rm;
a61af66fc99e Initial load
duke
parents:
diff changeset
189 HandleMark hm;
a61af66fc99e Initial load
duke
parents:
diff changeset
190 klassOop klass = receiver->klass();
a61af66fc99e Initial load
duke
parents:
diff changeset
191 instanceKlass* ik = instanceKlass::cast(klass);
a61af66fc99e Initial load
duke
parents:
diff changeset
192 klassVtable* vt = ik->vtable();
a61af66fc99e Initial load
duke
parents:
diff changeset
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
a61af66fc99e Initial load
duke
parents:
diff changeset
197 }
a61af66fc99e Initial load
duke
parents:
diff changeset
198
a61af66fc99e Initial load
duke
parents:
diff changeset
199 #endif // Product