author | sspitsyn |
Tue, 13 Sep 2016 13:10:42 -0700 | |
changeset 41089 | 20dee76bef80 |
parent 36301 | cb578d8c6cba |
permissions | -rw-r--r-- |
1 | 1 |
/* |
13963
e5b53c306fb5
7197424: update copyright year to match last edit in jdk8 hotspot repository
mikael
parents:
13195
diff
changeset
|
2 |
* Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved. |
1 | 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 |
* |
|
5547
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
4894
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
4894
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
4894
diff
changeset
|
21 |
* questions. |
1 | 22 |
* |
23 |
*/ |
|
24 |
||
7397 | 25 |
#include "precompiled.hpp" |
26 |
#include "code/codeBlob.hpp" |
|
27 |
#include "code/codeCache.hpp" |
|
28 |
#include "code/scopeDesc.hpp" |
|
22747
f467c14746f5
8025841: JVMTI: "vtable stub" dynamic code notification is misplaced
sspitsyn
parents:
13963
diff
changeset
|
29 |
#include "code/vtableStubs.hpp" |
7397 | 30 |
#include "memory/resourceArea.hpp" |
31 |
#include "oops/oop.inline.hpp" |
|
32 |
#include "prims/jvmtiCodeBlobEvents.hpp" |
|
33 |
#include "prims/jvmtiExport.hpp" |
|
34 |
#include "runtime/handles.hpp" |
|
35 |
#include "runtime/handles.inline.hpp" |
|
36 |
#include "runtime/vmThread.hpp" |
|
1 | 37 |
|
38 |
// Support class to collect a list of the non-nmethod CodeBlobs in |
|
39 |
// the CodeCache. |
|
40 |
// |
|
41 |
// This class actually creates a list of JvmtiCodeBlobDesc - each JvmtiCodeBlobDesc |
|
42 |
// describes a single CodeBlob in the CodeCache. Note that collection is |
|
43 |
// done to a static list - this is because CodeCache::blobs_do is defined |
|
44 |
// as void CodeCache::blobs_do(void f(CodeBlob* nm)) and hence requires |
|
45 |
// a C or static method. |
|
46 |
// |
|
47 |
// Usage :- |
|
48 |
// |
|
49 |
// CodeBlobCollector collector; |
|
50 |
// |
|
51 |
// collector.collect(); |
|
52 |
// JvmtiCodeBlobDesc* blob = collector.first(); |
|
53 |
// while (blob != NULL) { |
|
54 |
// : |
|
55 |
// blob = collector.next(); |
|
56 |
// } |
|
57 |
// |
|
58 |
||
59 |
class CodeBlobCollector : StackObj { |
|
60 |
private: |
|
61 |
GrowableArray<JvmtiCodeBlobDesc*>* _code_blobs; // collected blobs |
|
62 |
int _pos; // iterator position |
|
63 |
||
64 |
// used during a collection |
|
65 |
static GrowableArray<JvmtiCodeBlobDesc*>* _global_code_blobs; |
|
66 |
static void do_blob(CodeBlob* cb); |
|
22747
f467c14746f5
8025841: JVMTI: "vtable stub" dynamic code notification is misplaced
sspitsyn
parents:
13963
diff
changeset
|
67 |
static void do_vtable_stub(VtableStub* vs); |
1 | 68 |
public: |
69 |
CodeBlobCollector() { |
|
70 |
_code_blobs = NULL; |
|
71 |
_pos = -1; |
|
72 |
} |
|
73 |
~CodeBlobCollector() { |
|
74 |
if (_code_blobs != NULL) { |
|
75 |
for (int i=0; i<_code_blobs->length(); i++) { |
|
76 |
FreeHeap(_code_blobs->at(i)); |
|
77 |
} |
|
78 |
delete _code_blobs; |
|
79 |
} |
|
80 |
} |
|
81 |
||
82 |
// collect list of code blobs in the cache |
|
83 |
void collect(); |
|
84 |
||
85 |
// iteration support - return first code blob |
|
86 |
JvmtiCodeBlobDesc* first() { |
|
87 |
assert(_code_blobs != NULL, "not collected"); |
|
88 |
if (_code_blobs->length() == 0) { |
|
89 |
return NULL; |
|
90 |
} |
|
91 |
_pos = 0; |
|
92 |
return _code_blobs->at(0); |
|
93 |
} |
|
94 |
||
95 |
// iteration support - return next code blob |
|
96 |
JvmtiCodeBlobDesc* next() { |
|
97 |
assert(_pos >= 0, "iteration not started"); |
|
98 |
if (_pos+1 >= _code_blobs->length()) { |
|
99 |
return NULL; |
|
100 |
} |
|
101 |
return _code_blobs->at(++_pos); |
|
102 |
} |
|
103 |
||
104 |
}; |
|
105 |
||
106 |
// used during collection |
|
107 |
GrowableArray<JvmtiCodeBlobDesc*>* CodeBlobCollector::_global_code_blobs; |
|
108 |
||
109 |
||
110 |
// called for each CodeBlob in the CodeCache |
|
111 |
// |
|
112 |
// This function filters out nmethods as it is only interested in |
|
113 |
// other CodeBlobs. This function also filters out CodeBlobs that have |
|
114 |
// a duplicate starting address as previous blobs. This is needed to |
|
115 |
// handle the case where multiple stubs are generated into a single |
|
116 |
// BufferBlob. |
|
117 |
||
118 |
void CodeBlobCollector::do_blob(CodeBlob* cb) { |
|
119 |
||
120 |
// ignore nmethods |
|
121 |
if (cb->is_nmethod()) { |
|
122 |
return; |
|
123 |
} |
|
22747
f467c14746f5
8025841: JVMTI: "vtable stub" dynamic code notification is misplaced
sspitsyn
parents:
13963
diff
changeset
|
124 |
// exclude VtableStubs, which are processed separately |
f467c14746f5
8025841: JVMTI: "vtable stub" dynamic code notification is misplaced
sspitsyn
parents:
13963
diff
changeset
|
125 |
if (cb->is_buffer_blob() && strcmp(cb->name(), "vtable chunks") == 0) { |
f467c14746f5
8025841: JVMTI: "vtable stub" dynamic code notification is misplaced
sspitsyn
parents:
13963
diff
changeset
|
126 |
return; |
f467c14746f5
8025841: JVMTI: "vtable stub" dynamic code notification is misplaced
sspitsyn
parents:
13963
diff
changeset
|
127 |
} |
1 | 128 |
|
129 |
// check if this starting address has been seen already - the |
|
130 |
// assumption is that stubs are inserted into the list before the |
|
131 |
// enclosing BufferBlobs. |
|
6418 | 132 |
address addr = cb->code_begin(); |
1 | 133 |
for (int i=0; i<_global_code_blobs->length(); i++) { |
134 |
JvmtiCodeBlobDesc* scb = _global_code_blobs->at(i); |
|
135 |
if (addr == scb->code_begin()) { |
|
136 |
return; |
|
137 |
} |
|
138 |
} |
|
139 |
||
140 |
// record the CodeBlob details as a JvmtiCodeBlobDesc |
|
6418 | 141 |
JvmtiCodeBlobDesc* scb = new JvmtiCodeBlobDesc(cb->name(), cb->code_begin(), cb->code_end()); |
1 | 142 |
_global_code_blobs->append(scb); |
143 |
} |
|
144 |
||
22747
f467c14746f5
8025841: JVMTI: "vtable stub" dynamic code notification is misplaced
sspitsyn
parents:
13963
diff
changeset
|
145 |
// called for each VtableStub in VtableStubs |
f467c14746f5
8025841: JVMTI: "vtable stub" dynamic code notification is misplaced
sspitsyn
parents:
13963
diff
changeset
|
146 |
|
f467c14746f5
8025841: JVMTI: "vtable stub" dynamic code notification is misplaced
sspitsyn
parents:
13963
diff
changeset
|
147 |
void CodeBlobCollector::do_vtable_stub(VtableStub* vs) { |
f467c14746f5
8025841: JVMTI: "vtable stub" dynamic code notification is misplaced
sspitsyn
parents:
13963
diff
changeset
|
148 |
JvmtiCodeBlobDesc* scb = new JvmtiCodeBlobDesc(vs->is_vtable_stub() ? "vtable stub" : "itable stub", |
f467c14746f5
8025841: JVMTI: "vtable stub" dynamic code notification is misplaced
sspitsyn
parents:
13963
diff
changeset
|
149 |
vs->code_begin(), vs->code_end()); |
f467c14746f5
8025841: JVMTI: "vtable stub" dynamic code notification is misplaced
sspitsyn
parents:
13963
diff
changeset
|
150 |
_global_code_blobs->append(scb); |
f467c14746f5
8025841: JVMTI: "vtable stub" dynamic code notification is misplaced
sspitsyn
parents:
13963
diff
changeset
|
151 |
} |
1 | 152 |
|
153 |
// collects a list of CodeBlobs in the CodeCache. |
|
154 |
// |
|
155 |
// The created list is growable array of JvmtiCodeBlobDesc - each one describes |
|
156 |
// a CodeBlob. Note that the list is static - this is because CodeBlob::blobs_do |
|
157 |
// requires a a C or static function so we can't use an instance function. This |
|
158 |
// isn't a problem as the iteration is serial anyway as we need the CodeCache_lock |
|
159 |
// to iterate over the code cache. |
|
160 |
// |
|
161 |
// Note that the CodeBlobs in the CodeCache will include BufferBlobs that may |
|
162 |
// contain multiple stubs. As a profiler is interested in the stubs rather than |
|
163 |
// the enclosing container we first iterate over the stub code descriptors so |
|
164 |
// that the stubs go into the list first. do_blob will then filter out the |
|
165 |
// enclosing blobs if the starting address of the enclosing blobs matches the |
|
166 |
// starting address of first stub generated in the enclosing blob. |
|
167 |
||
168 |
void CodeBlobCollector::collect() { |
|
169 |
assert_locked_or_safepoint(CodeCache_lock); |
|
170 |
assert(_global_code_blobs == NULL, "checking"); |
|
171 |
||
172 |
// create the global list |
|
13195 | 173 |
_global_code_blobs = new (ResourceObj::C_HEAP, mtInternal) GrowableArray<JvmtiCodeBlobDesc*>(50,true); |
1 | 174 |
|
175 |
// iterate over the stub code descriptors and put them in the list first. |
|
36301
cb578d8c6cba
8149741: Don't refer to stub entry points by index in external_word relocations
vlivanov
parents:
33160
diff
changeset
|
176 |
for (StubCodeDesc* desc = StubCodeDesc::first(); desc != NULL; desc = StubCodeDesc::next(desc)) { |
1 | 177 |
_global_code_blobs->append(new JvmtiCodeBlobDesc(desc->name(), desc->begin(), desc->end())); |
178 |
} |
|
179 |
||
22747
f467c14746f5
8025841: JVMTI: "vtable stub" dynamic code notification is misplaced
sspitsyn
parents:
13963
diff
changeset
|
180 |
// Vtable stubs are not described with StubCodeDesc, |
f467c14746f5
8025841: JVMTI: "vtable stub" dynamic code notification is misplaced
sspitsyn
parents:
13963
diff
changeset
|
181 |
// process them separately |
f467c14746f5
8025841: JVMTI: "vtable stub" dynamic code notification is misplaced
sspitsyn
parents:
13963
diff
changeset
|
182 |
VtableStubs::vtable_stub_do(do_vtable_stub); |
f467c14746f5
8025841: JVMTI: "vtable stub" dynamic code notification is misplaced
sspitsyn
parents:
13963
diff
changeset
|
183 |
|
1 | 184 |
// next iterate over all the non-nmethod code blobs and add them to |
185 |
// the list - as noted above this will filter out duplicates and |
|
186 |
// enclosing blobs. |
|
187 |
CodeCache::blobs_do(do_blob); |
|
188 |
||
189 |
// make the global list the instance list so that it can be used |
|
190 |
// for other iterations. |
|
191 |
_code_blobs = _global_code_blobs; |
|
192 |
_global_code_blobs = NULL; |
|
193 |
} |
|
194 |
||
195 |
||
196 |
// Generate a DYNAMIC_CODE_GENERATED event for each non-nmethod code blob. |
|
197 |
||
198 |
jvmtiError JvmtiCodeBlobEvents::generate_dynamic_code_events(JvmtiEnv* env) { |
|
199 |
CodeBlobCollector collector; |
|
200 |
||
5913
9dbc3381245b
6965671: fatal error: acquiring lock JNIGlobalHandle_lock/16 out of order with lock CodeCache_lock/1
never
parents:
5896
diff
changeset
|
201 |
// First collect all the code blobs. This has to be done in a |
9dbc3381245b
6965671: fatal error: acquiring lock JNIGlobalHandle_lock/16 out of order with lock CodeCache_lock/1
never
parents:
5896
diff
changeset
|
202 |
// single pass over the code cache with CodeCache_lock held because |
9dbc3381245b
6965671: fatal error: acquiring lock JNIGlobalHandle_lock/16 out of order with lock CodeCache_lock/1
never
parents:
5896
diff
changeset
|
203 |
// there isn't any safe way to iterate over regular CodeBlobs since |
9dbc3381245b
6965671: fatal error: acquiring lock JNIGlobalHandle_lock/16 out of order with lock CodeCache_lock/1
never
parents:
5896
diff
changeset
|
204 |
// they can be freed at any point. |
1 | 205 |
{ |
206 |
MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag); |
|
207 |
collector.collect(); |
|
208 |
} |
|
209 |
||
210 |
// iterate over the collected list and post an event for each blob |
|
211 |
JvmtiCodeBlobDesc* blob = collector.first(); |
|
212 |
while (blob != NULL) { |
|
213 |
JvmtiExport::post_dynamic_code_generated(env, blob->name(), blob->code_begin(), blob->code_end()); |
|
214 |
blob = collector.next(); |
|
215 |
} |
|
216 |
return JVMTI_ERROR_NONE; |
|
217 |
} |
|
218 |
||
219 |
||
220 |
// Generate a COMPILED_METHOD_LOAD event for each nnmethod |
|
221 |
jvmtiError JvmtiCodeBlobEvents::generate_compiled_method_load_events(JvmtiEnv* env) { |
|
222 |
HandleMark hm; |
|
223 |
||
5913
9dbc3381245b
6965671: fatal error: acquiring lock JNIGlobalHandle_lock/16 out of order with lock CodeCache_lock/1
never
parents:
5896
diff
changeset
|
224 |
// Walk the CodeCache notifying for live nmethods. The code cache |
9dbc3381245b
6965671: fatal error: acquiring lock JNIGlobalHandle_lock/16 out of order with lock CodeCache_lock/1
never
parents:
5896
diff
changeset
|
225 |
// may be changing while this is happening which is ok since newly |
9dbc3381245b
6965671: fatal error: acquiring lock JNIGlobalHandle_lock/16 out of order with lock CodeCache_lock/1
never
parents:
5896
diff
changeset
|
226 |
// created nmethod will notify normally and nmethods which are freed |
9dbc3381245b
6965671: fatal error: acquiring lock JNIGlobalHandle_lock/16 out of order with lock CodeCache_lock/1
never
parents:
5896
diff
changeset
|
227 |
// can be safely skipped. |
9dbc3381245b
6965671: fatal error: acquiring lock JNIGlobalHandle_lock/16 out of order with lock CodeCache_lock/1
never
parents:
5896
diff
changeset
|
228 |
MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag); |
26796 | 229 |
// Iterate over non-profiled and profiled nmethods |
230 |
NMethodIterator iter; |
|
231 |
while(iter.next_alive()) { |
|
232 |
nmethod* current = iter.method(); |
|
233 |
// Lock the nmethod so it can't be freed |
|
234 |
nmethodLocker nml(current); |
|
5929
279fd26a4b68
6968336: VM crash guarantee(!nm->is_zombie()) failed: cannot lock a zombie method
never
parents:
5913
diff
changeset
|
235 |
|
26796 | 236 |
// Don't hold the lock over the notify or jmethodID creation |
237 |
MutexUnlockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag); |
|
238 |
current->get_and_cache_jmethod_id(); |
|
239 |
JvmtiExport::post_compiled_method_load(current); |
|
1 | 240 |
} |
241 |
return JVMTI_ERROR_NONE; |
|
242 |
} |
|
243 |
||
244 |
||
245 |
// create a C-heap allocated address location map for an nmethod |
|
246 |
void JvmtiCodeBlobEvents::build_jvmti_addr_location_map(nmethod *nm, |
|
247 |
jvmtiAddrLocationMap** map_ptr, |
|
248 |
jint *map_length_ptr) |
|
249 |
{ |
|
250 |
ResourceMark rm; |
|
251 |
jvmtiAddrLocationMap* map = NULL; |
|
252 |
jint map_length = 0; |
|
253 |
||
254 |
||
255 |
// Generate line numbers using PcDesc and ScopeDesc info |
|
256 |
methodHandle mh(nm->method()); |
|
257 |
||
258 |
if (!mh->is_native()) { |
|
259 |
PcDesc *pcd; |
|
260 |
int pcds_in_method; |
|
261 |
||
262 |
pcds_in_method = (nm->scopes_pcs_end() - nm->scopes_pcs_begin()); |
|
13195 | 263 |
map = NEW_C_HEAP_ARRAY(jvmtiAddrLocationMap, pcds_in_method, mtInternal); |
1 | 264 |
|
265 |
address scopes_data = nm->scopes_data_begin(); |
|
266 |
for( pcd = nm->scopes_pcs_begin(); pcd < nm->scopes_pcs_end(); ++pcd ) { |
|
33160
c59f1676d27e
8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
26796
diff
changeset
|
267 |
ScopeDesc sc0(nm, pcd->scope_decode_offset(), pcd->should_reexecute(), pcd->rethrow_exception(), pcd->return_oop()); |
1 | 268 |
ScopeDesc *sd = &sc0; |
269 |
while( !sd->is_top() ) { sd = sd->sender(); } |
|
270 |
int bci = sd->bci(); |
|
271 |
if (bci != InvocationEntryBci) { |
|
272 |
assert(map_length < pcds_in_method, "checking"); |
|
273 |
map[map_length].start_address = (const void*)pcd->real_pc(nm); |
|
274 |
map[map_length].location = bci; |
|
275 |
++map_length; |
|
276 |
} |
|
277 |
} |
|
278 |
} |
|
279 |
||
280 |
*map_ptr = map; |
|
281 |
*map_length_ptr = map_length; |
|
282 |
} |