Mercurial > hg > graal-jvmci-8
annotate src/share/vm/compiler/compileLog.cpp @ 24234:ea6f94ab283b default tip
Added tag jvmci-0.36 for changeset 8128b98d4736
author | Gilles Duboscq <gilles.m.duboscq@oracle.com> |
---|---|
date | Mon, 18 Sep 2017 18:49:45 +0200 |
parents | 7848fc12602b |
children |
rev | line source |
---|---|
0 | 1 /* |
17937
78bbf4d43a14
8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents:
14223
diff
changeset
|
2 * Copyright (c) 2002, 2014, Oracle and/or its affiliates. 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 * | |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1489
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1489
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:
1489
diff
changeset
|
21 * questions. |
0 | 22 * |
23 */ | |
24 | |
1972 | 25 #include "precompiled.hpp" |
26 #include "ci/ciMethod.hpp" | |
27 #include "compiler/compileLog.hpp" | |
28 #include "memory/allocation.inline.hpp" | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
29 #include "oops/method.hpp" |
1972 | 30 #include "runtime/mutexLocker.hpp" |
31 #include "runtime/os.hpp" | |
0 | 32 |
33 CompileLog* CompileLog::_first = NULL; | |
34 | |
35 // ------------------------------------------------------------------ | |
36 // CompileLog::CompileLog | |
10394
813f26e34135
8013329: File leak in hotspot/src/share/vm/compiler/compileBroker.cpp
anoll
parents:
9060
diff
changeset
|
37 CompileLog::CompileLog(const char* file_name, FILE* fp, intx thread_id) |
0 | 38 : _context(_context_buffer, sizeof(_context_buffer)) |
39 { | |
10394
813f26e34135
8013329: File leak in hotspot/src/share/vm/compiler/compileBroker.cpp
anoll
parents:
9060
diff
changeset
|
40 initialize(new(ResourceObj::C_HEAP, mtCompiler) fileStream(fp, true)); |
0 | 41 _file_end = 0; |
42 _thread_id = thread_id; | |
43 | |
44 _identities_limit = 0; | |
45 _identities_capacity = 400; | |
6197 | 46 _identities = NEW_C_HEAP_ARRAY(char, _identities_capacity, mtCompiler); |
10394
813f26e34135
8013329: File leak in hotspot/src/share/vm/compiler/compileBroker.cpp
anoll
parents:
9060
diff
changeset
|
47 _file = NEW_C_HEAP_ARRAY(char, strlen(file_name)+1, mtCompiler); |
813f26e34135
8013329: File leak in hotspot/src/share/vm/compiler/compileBroker.cpp
anoll
parents:
9060
diff
changeset
|
48 strcpy((char*)_file, file_name); |
0 | 49 |
50 // link into the global list | |
51 { MutexLocker locker(CompileTaskAlloc_lock); | |
52 _next = _first; | |
53 _first = this; | |
54 } | |
55 } | |
56 | |
57 CompileLog::~CompileLog() { | |
20679
ecccc23346fe
8007993: hotspot.log w/ enabled LogCompilation can be an invalid XML
thartmann
parents:
17937
diff
changeset
|
58 delete _out; // Close fd in fileStream::~fileStream() |
0 | 59 _out = NULL; |
20679
ecccc23346fe
8007993: hotspot.log w/ enabled LogCompilation can be an invalid XML
thartmann
parents:
17937
diff
changeset
|
60 // Remove partial file after merging in CompileLog::finish_log_on_error |
ecccc23346fe
8007993: hotspot.log w/ enabled LogCompilation can be an invalid XML
thartmann
parents:
17937
diff
changeset
|
61 unlink(_file); |
6197 | 62 FREE_C_HEAP_ARRAY(char, _identities, mtCompiler); |
10394
813f26e34135
8013329: File leak in hotspot/src/share/vm/compiler/compileBroker.cpp
anoll
parents:
9060
diff
changeset
|
63 FREE_C_HEAP_ARRAY(char, _file, mtCompiler); |
0 | 64 } |
65 | |
66 | |
67 // see_tag, pop_tag: Override the default do-nothing methods on xmlStream. | |
68 // These methods provide a hook for managing the the extra context markup. | |
69 void CompileLog::see_tag(const char* tag, bool push) { | |
70 if (_context.size() > 0 && _out != NULL) { | |
71 _out->write(_context.base(), _context.size()); | |
72 _context.reset(); | |
73 } | |
74 xmlStream::see_tag(tag, push); | |
75 } | |
76 void CompileLog::pop_tag(const char* tag) { | |
77 _context.reset(); // toss any context info. | |
78 xmlStream::pop_tag(tag); | |
79 } | |
80 | |
81 | |
82 // ------------------------------------------------------------------ | |
83 // CompileLog::identify | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
84 int CompileLog::identify(ciBaseObject* obj) { |
0 | 85 if (obj == NULL) return 0; |
86 int id = obj->ident(); | |
87 if (id < 0) return id; | |
88 // If it has already been identified, just return the id. | |
89 if (id < _identities_limit && _identities[id] != 0) return id; | |
90 // Lengthen the array, if necessary. | |
91 if (id >= _identities_capacity) { | |
92 int new_cap = _identities_capacity * 2; | |
93 if (new_cap <= id) new_cap = id + 100; | |
6197 | 94 _identities = REALLOC_C_HEAP_ARRAY(char, _identities, new_cap, mtCompiler); |
0 | 95 _identities_capacity = new_cap; |
96 } | |
97 while (id >= _identities_limit) { | |
98 _identities[_identities_limit++] = 0; | |
99 } | |
100 assert(id < _identities_limit, "oob"); | |
101 // Mark this id as processed. | |
102 // (Be sure to do this before any recursive calls to identify.) | |
103 _identities[id] = 1; // mark | |
104 | |
105 // Now, print the object's identity once, in detail. | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
106 if (obj->is_metadata()) { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
107 ciMetadata* mobj = obj->as_metadata(); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
108 if (mobj->is_klass()) { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
109 ciKlass* klass = mobj->as_klass(); |
6800
9191895df19d
7200001: failed C1 OSR compile doesn't get recompiled with C2
twisti
parents:
6725
diff
changeset
|
110 begin_elem("klass id='%d'", id); |
9191895df19d
7200001: failed C1 OSR compile doesn't get recompiled with C2
twisti
parents:
6725
diff
changeset
|
111 name(klass->name()); |
9191895df19d
7200001: failed C1 OSR compile doesn't get recompiled with C2
twisti
parents:
6725
diff
changeset
|
112 if (!klass->is_loaded()) { |
9191895df19d
7200001: failed C1 OSR compile doesn't get recompiled with C2
twisti
parents:
6725
diff
changeset
|
113 print(" unloaded='1'"); |
9191895df19d
7200001: failed C1 OSR compile doesn't get recompiled with C2
twisti
parents:
6725
diff
changeset
|
114 } else { |
9191895df19d
7200001: failed C1 OSR compile doesn't get recompiled with C2
twisti
parents:
6725
diff
changeset
|
115 print(" flags='%d'", klass->modifier_flags()); |
9191895df19d
7200001: failed C1 OSR compile doesn't get recompiled with C2
twisti
parents:
6725
diff
changeset
|
116 } |
9191895df19d
7200001: failed C1 OSR compile doesn't get recompiled with C2
twisti
parents:
6725
diff
changeset
|
117 end_elem(); |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
118 } else if (mobj->is_method()) { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
119 ciMethod* method = mobj->as_method(); |
6800
9191895df19d
7200001: failed C1 OSR compile doesn't get recompiled with C2
twisti
parents:
6725
diff
changeset
|
120 ciSignature* sig = method->signature(); |
9191895df19d
7200001: failed C1 OSR compile doesn't get recompiled with C2
twisti
parents:
6725
diff
changeset
|
121 // Pre-identify items that we will need! |
9191895df19d
7200001: failed C1 OSR compile doesn't get recompiled with C2
twisti
parents:
6725
diff
changeset
|
122 identify(sig->return_type()); |
0 | 123 for (int i = 0; i < sig->count(); i++) { |
6800
9191895df19d
7200001: failed C1 OSR compile doesn't get recompiled with C2
twisti
parents:
6725
diff
changeset
|
124 identify(sig->type_at(i)); |
0 | 125 } |
6800
9191895df19d
7200001: failed C1 OSR compile doesn't get recompiled with C2
twisti
parents:
6725
diff
changeset
|
126 begin_elem("method id='%d' holder='%d'", |
9191895df19d
7200001: failed C1 OSR compile doesn't get recompiled with C2
twisti
parents:
6725
diff
changeset
|
127 id, identify(method->holder())); |
9191895df19d
7200001: failed C1 OSR compile doesn't get recompiled with C2
twisti
parents:
6725
diff
changeset
|
128 name(method->name()); |
9191895df19d
7200001: failed C1 OSR compile doesn't get recompiled with C2
twisti
parents:
6725
diff
changeset
|
129 print(" return='%d'", identify(sig->return_type())); |
9191895df19d
7200001: failed C1 OSR compile doesn't get recompiled with C2
twisti
parents:
6725
diff
changeset
|
130 if (sig->count() > 0) { |
9191895df19d
7200001: failed C1 OSR compile doesn't get recompiled with C2
twisti
parents:
6725
diff
changeset
|
131 print(" arguments='"); |
9191895df19d
7200001: failed C1 OSR compile doesn't get recompiled with C2
twisti
parents:
6725
diff
changeset
|
132 for (int i = 0; i < sig->count(); i++) { |
9191895df19d
7200001: failed C1 OSR compile doesn't get recompiled with C2
twisti
parents:
6725
diff
changeset
|
133 print((i == 0) ? "%d" : " %d", identify(sig->type_at(i))); |
9191895df19d
7200001: failed C1 OSR compile doesn't get recompiled with C2
twisti
parents:
6725
diff
changeset
|
134 } |
9191895df19d
7200001: failed C1 OSR compile doesn't get recompiled with C2
twisti
parents:
6725
diff
changeset
|
135 print("'"); |
9191895df19d
7200001: failed C1 OSR compile doesn't get recompiled with C2
twisti
parents:
6725
diff
changeset
|
136 } |
9191895df19d
7200001: failed C1 OSR compile doesn't get recompiled with C2
twisti
parents:
6725
diff
changeset
|
137 if (!method->is_loaded()) { |
9191895df19d
7200001: failed C1 OSR compile doesn't get recompiled with C2
twisti
parents:
6725
diff
changeset
|
138 print(" unloaded='1'"); |
9191895df19d
7200001: failed C1 OSR compile doesn't get recompiled with C2
twisti
parents:
6725
diff
changeset
|
139 } else { |
9191895df19d
7200001: failed C1 OSR compile doesn't get recompiled with C2
twisti
parents:
6725
diff
changeset
|
140 print(" flags='%d'", (jchar) method->flags().as_int()); |
9191895df19d
7200001: failed C1 OSR compile doesn't get recompiled with C2
twisti
parents:
6725
diff
changeset
|
141 // output a few metrics |
9191895df19d
7200001: failed C1 OSR compile doesn't get recompiled with C2
twisti
parents:
6725
diff
changeset
|
142 print(" bytes='%d'", method->code_size()); |
9191895df19d
7200001: failed C1 OSR compile doesn't get recompiled with C2
twisti
parents:
6725
diff
changeset
|
143 method->log_nmethod_identity(this); |
9191895df19d
7200001: failed C1 OSR compile doesn't get recompiled with C2
twisti
parents:
6725
diff
changeset
|
144 //print(" count='%d'", method->invocation_count()); |
9191895df19d
7200001: failed C1 OSR compile doesn't get recompiled with C2
twisti
parents:
6725
diff
changeset
|
145 //int bec = method->backedge_count(); |
9191895df19d
7200001: failed C1 OSR compile doesn't get recompiled with C2
twisti
parents:
6725
diff
changeset
|
146 //if (bec != 0) print(" backedge_count='%d'", bec); |
9191895df19d
7200001: failed C1 OSR compile doesn't get recompiled with C2
twisti
parents:
6725
diff
changeset
|
147 print(" iicount='%d'", method->interpreter_invocation_count()); |
9191895df19d
7200001: failed C1 OSR compile doesn't get recompiled with C2
twisti
parents:
6725
diff
changeset
|
148 } |
9191895df19d
7200001: failed C1 OSR compile doesn't get recompiled with C2
twisti
parents:
6725
diff
changeset
|
149 end_elem(); |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
150 } else if (mobj->is_type()) { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
151 BasicType type = mobj->as_type()->basic_type(); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
152 elem("type id='%d' name='%s'", id, type2name(type)); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
153 } else { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
154 // Should not happen. |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
155 elem("unknown id='%d'", id); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
156 ShouldNotReachHere(); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6197
diff
changeset
|
157 } |
0 | 158 } else if (obj->is_symbol()) { |
159 begin_elem("symbol id='%d'", id); | |
160 name(obj->as_symbol()); | |
161 end_elem(); | |
162 } else { | |
163 // Should not happen. | |
164 elem("unknown id='%d'", id); | |
165 } | |
166 return id; | |
167 } | |
168 | |
169 void CompileLog::name(ciSymbol* name) { | |
170 if (name == NULL) return; | |
171 print(" name='"); | |
172 name->print_symbol_on(text()); // handles quoting conventions | |
173 print("'"); | |
174 } | |
175 | |
176 | |
177 // ------------------------------------------------------------------ | |
178 // CompileLog::clear_identities | |
179 // Forget which identities have been printed. | |
180 void CompileLog::clear_identities() { | |
181 _identities_limit = 0; | |
182 } | |
183 | |
184 // ------------------------------------------------------------------ | |
185 // CompileLog::finish_log_on_error | |
186 // | |
187 // Note: This function is called after fatal error, avoid unnecessary memory | |
188 // or stack allocation, use only async-safe functions. It's possible JVM is | |
189 // only partially initialized. | |
190 void CompileLog::finish_log_on_error(outputStream* file, char* buf, int buflen) { | |
191 static bool called_exit = false; | |
192 if (called_exit) return; | |
193 called_exit = true; | |
194 | |
10394
813f26e34135
8013329: File leak in hotspot/src/share/vm/compiler/compileBroker.cpp
anoll
parents:
9060
diff
changeset
|
195 CompileLog* log = _first; |
813f26e34135
8013329: File leak in hotspot/src/share/vm/compiler/compileBroker.cpp
anoll
parents:
9060
diff
changeset
|
196 while (log != NULL) { |
0 | 197 log->flush(); |
198 const char* partial_file = log->file(); | |
199 int partial_fd = open(partial_file, O_RDONLY); | |
200 if (partial_fd != -1) { | |
201 // print/print_cr may need to allocate large stack buffer to format | |
202 // strings, here we use snprintf() and print_raw() instead. | |
203 file->print_raw("<compilation_log thread='"); | |
204 jio_snprintf(buf, buflen, UINTX_FORMAT, log->thread_id()); | |
205 file->print_raw(buf); | |
206 file->print_raw_cr("'>"); | |
207 | |
208 size_t nr; // number read into buf from partial log | |
209 // Copy data up to the end of the last <event> element: | |
210 julong to_read = log->_file_end; | |
211 while (to_read > 0) { | |
212 if (to_read < (julong)buflen) | |
213 nr = (size_t)to_read; | |
214 else nr = buflen; | |
215 nr = read(partial_fd, buf, (int)nr); | |
216 if (nr <= 0) break; | |
217 to_read -= (julong)nr; | |
218 file->write(buf, nr); | |
219 } | |
220 | |
221 // Copy any remaining data inside a quote: | |
222 bool saw_slop = false; | |
223 int end_cdata = 0; // state machine [0..2] watching for too many "]]" | |
224 while ((nr = read(partial_fd, buf, buflen)) > 0) { | |
225 if (!saw_slop) { | |
226 file->print_raw_cr("<fragment>"); | |
227 file->print_raw_cr("<![CDATA["); | |
228 saw_slop = true; | |
229 } | |
230 // The rest of this loop amounts to a simple copy operation: | |
231 // { file->write(buf, nr); } | |
232 // However, it must sometimes output the buffer in parts, | |
233 // in case there is a CDATA quote embedded in the fragment. | |
234 const char* bufp; // pointer into buf | |
235 size_t nw; // number written in each pass of the following loop: | |
236 for (bufp = buf; nr > 0; nr -= nw, bufp += nw) { | |
237 // Write up to any problematic CDATA delimiter (usually all of nr). | |
238 for (nw = 0; nw < nr; nw++) { | |
239 // First, scan ahead into the buf, checking the state machine. | |
240 switch (bufp[nw]) { | |
241 case ']': | |
242 if (end_cdata < 2) end_cdata += 1; // saturating counter | |
243 continue; // keep scanning | |
244 case '>': | |
245 if (end_cdata == 2) break; // found CDATA delimiter! | |
246 // else fall through: | |
247 default: | |
248 end_cdata = 0; | |
249 continue; // keep scanning | |
250 } | |
251 // If we get here, nw is pointing at a bad '>'. | |
252 // It is very rare for this to happen. | |
253 // However, this code has been tested by introducing | |
254 // CDATA sequences into the compilation log. | |
255 break; | |
256 } | |
257 // Now nw is the number of characters to write, usually == nr. | |
258 file->write(bufp, nw); | |
259 if (nw < nr) { | |
260 // We are about to go around the loop again. | |
261 // But first, disrupt the ]]> by closing and reopening the quote. | |
262 file->print_raw("]]><![CDATA["); | |
263 end_cdata = 0; // reset state machine | |
264 } | |
265 } | |
266 } | |
267 if (saw_slop) { | |
268 file->print_raw_cr("]]>"); | |
269 file->print_raw_cr("</fragment>"); | |
270 } | |
271 file->print_raw_cr("</compilation_log>"); | |
272 close(partial_fd); | |
273 } | |
10394
813f26e34135
8013329: File leak in hotspot/src/share/vm/compiler/compileBroker.cpp
anoll
parents:
9060
diff
changeset
|
274 CompileLog* next_log = log->_next; |
20679
ecccc23346fe
8007993: hotspot.log w/ enabled LogCompilation can be an invalid XML
thartmann
parents:
17937
diff
changeset
|
275 delete log; // Removes partial file |
10394
813f26e34135
8013329: File leak in hotspot/src/share/vm/compiler/compileBroker.cpp
anoll
parents:
9060
diff
changeset
|
276 log = next_log; |
0 | 277 } |
10394
813f26e34135
8013329: File leak in hotspot/src/share/vm/compiler/compileBroker.cpp
anoll
parents:
9060
diff
changeset
|
278 _first = NULL; |
0 | 279 } |
280 | |
281 // ------------------------------------------------------------------ | |
282 // CompileLog::finish_log | |
283 // | |
284 // Called during normal shutdown. For now, any clean-up needed in normal | |
285 // shutdown is also needed in VM abort, so is covered by finish_log_on_error(). | |
286 // Just allocate a buffer and call finish_log_on_error(). | |
287 void CompileLog::finish_log(outputStream* file) { | |
288 char buf[4 * K]; | |
289 finish_log_on_error(file, buf, sizeof(buf)); | |
290 } | |
6843 | 291 |
292 // ------------------------------------------------------------------ | |
293 // CompileLog::inline_success | |
294 // | |
295 // Print about successful method inlining. | |
296 void CompileLog::inline_success(const char* reason) { | |
297 begin_elem("inline_success reason='"); | |
17937
78bbf4d43a14
8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents:
14223
diff
changeset
|
298 text("%s", reason); |
6843 | 299 end_elem("'"); |
300 } | |
301 | |
302 // ------------------------------------------------------------------ | |
303 // CompileLog::inline_fail | |
304 // | |
305 // Print about failed method inlining. | |
306 void CompileLog::inline_fail(const char* reason) { | |
307 begin_elem("inline_fail reason='"); | |
17937
78bbf4d43a14
8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents:
14223
diff
changeset
|
308 text("%s", reason); |
6843 | 309 end_elem("'"); |
310 } | |
311 | |
312 // ------------------------------------------------------------------ | |
313 // CompileLog::set_context | |
314 // | |
315 // Set XML tag as an optional marker - it is printed only if | |
316 // there are other entries after until it is reset. | |
317 void CompileLog::set_context(const char* format, ...) { | |
318 va_list ap; | |
319 va_start(ap, format); | |
320 clear_context(); | |
321 _context.print("<"); | |
322 _context.vprint(format, ap); | |
323 _context.print_cr("/>"); | |
324 va_end(ap); | |
325 } | |
326 | |
327 // ------------------------------------------------------------------ | |
328 // CompileLog::code_cache_state | |
329 // | |
330 // Print code cache state. | |
331 void CompileLog::code_cache_state() { | |
332 begin_elem("code_cache"); | |
333 CodeCache::log_state(this); | |
17937
78bbf4d43a14
8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents:
14223
diff
changeset
|
334 end_elem("%s", ""); |
6843 | 335 } |