annotate src/share/vm/prims/jvmtiCodeBlobEvents.cpp @ 14330:9341a9963d36

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