1 /*
2 * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
43
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
52 void* VtableStub::operator new(size_t size, int code_size) throw() {
53 assert(size == sizeof(VtableStub), "mismatched size");
54 // compute real VtableStub size (rounded to nearest word)
55 const int real_size = align_up(code_size + (int)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();
60
61 // There is a dependency on the name of the blob in src/share/vm/prims/jvmtiCodeBlobEvents.cpp
62 // If changing the name, update the other file accordingly.
63 BufferBlob* blob = BufferBlob::create("vtable chunks", bytes);
64 if (blob == NULL) {
65 return NULL;
66 }
67 _chunk = blob->content_begin();
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
80 void VtableStub::print_on(outputStream* st) const {
81 st->print("vtable stub (index = %d, receiver_location = " INTX_FORMAT ", code = [" INTPTR_FORMAT ", " INTPTR_FORMAT "[)",
82 index(), p2i(receiver_location()), p2i(code_begin()), p2i(code_end()));
83 }
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() {
|
1 /*
2 * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
43
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
52 void* VtableStub::operator new(size_t size, int code_size) throw() {
53 assert(size == sizeof(VtableStub), "mismatched size");
54 // compute real VtableStub size (rounded to nearest word)
55 const int real_size = align_up(code_size + (int)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();
60
61 // There is a dependency on the name of the blob in src/share/vm/prims/jvmtiCodeBlobEvents.cpp
62 // If changing the name, update the other file accordingly.
63 VtableBlob* blob = VtableBlob::create("vtable chunks", bytes);
64 if (blob == NULL) {
65 return NULL;
66 }
67 _chunk = blob->content_begin();
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
80 void VtableStub::print_on(outputStream* st) const {
81 st->print("vtable stub (index = %d, receiver_location = " INTX_FORMAT ", code = [" INTPTR_FORMAT ", " INTPTR_FORMAT "[)",
82 index(), p2i(receiver_location()), p2i(code_begin()), p2i(code_end()));
83 }
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 VtableStub* VtableStubs::entry_point(address pc) {
171 MutexLocker ml(VtableStubs_lock);
172 VtableStub* stub = (VtableStub*)(pc - VtableStub::entry_offset());
173 uint hash = VtableStubs::hash(stub->is_vtable_stub(), stub->index());
174 VtableStub* s;
175 for (s = _table[hash]; s != NULL && s != stub; s = s->next()) {}
176 if (s == stub) {
177 return s;
178 }
179 return NULL;
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() {
|