annotate src/share/vm/compiler/compileLog.cpp @ 6862:8a5ea0a9ccc4

7127708: G1: change task num types from int to uint in concurrent mark Summary: Change the type of various task num fields, parameters etc to unsigned and rename them to be more consistent with the other collectors. Code changes were also reviewed by Vitaly Davidovich. Reviewed-by: johnc Contributed-by: Kaushik Srenevasan <kaushik@twitter.com>
author johnc
date Sat, 06 Oct 2012 01:17:44 -0700
parents 9191895df19d
children c3e799c37717
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
2 * Copyright (c) 2002, 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: 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
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: 1552
diff changeset
25 #include "precompiled.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
26 #include "ci/ciMethod.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
27 #include "compiler/compileLog.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
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
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
30 #include "runtime/mutexLocker.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
31 #include "runtime/os.hpp"
0
a61af66fc99e Initial load
duke
parents:
diff changeset
32
a61af66fc99e Initial load
duke
parents:
diff changeset
33 CompileLog* CompileLog::_first = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
34
a61af66fc99e Initial load
duke
parents:
diff changeset
35 // ------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
36 // CompileLog::CompileLog
a61af66fc99e Initial load
duke
parents:
diff changeset
37 CompileLog::CompileLog(const char* file, FILE* fp, intx thread_id)
a61af66fc99e Initial load
duke
parents:
diff changeset
38 : _context(_context_buffer, sizeof(_context_buffer))
a61af66fc99e Initial load
duke
parents:
diff changeset
39 {
6197
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 1972
diff changeset
40 initialize(new(ResourceObj::C_HEAP, mtCompiler) fileStream(fp));
0
a61af66fc99e Initial load
duke
parents:
diff changeset
41 _file = file;
a61af66fc99e Initial load
duke
parents:
diff changeset
42 _file_end = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
43 _thread_id = thread_id;
a61af66fc99e Initial load
duke
parents:
diff changeset
44
a61af66fc99e Initial load
duke
parents:
diff changeset
45 _identities_limit = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
46 _identities_capacity = 400;
6197
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 1972
diff changeset
47 _identities = NEW_C_HEAP_ARRAY(char, _identities_capacity, mtCompiler);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
48
a61af66fc99e Initial load
duke
parents:
diff changeset
49 // link into the global list
a61af66fc99e Initial load
duke
parents:
diff changeset
50 { MutexLocker locker(CompileTaskAlloc_lock);
a61af66fc99e Initial load
duke
parents:
diff changeset
51 _next = _first;
a61af66fc99e Initial load
duke
parents:
diff changeset
52 _first = this;
a61af66fc99e Initial load
duke
parents:
diff changeset
53 }
a61af66fc99e Initial load
duke
parents:
diff changeset
54 }
a61af66fc99e Initial load
duke
parents:
diff changeset
55
a61af66fc99e Initial load
duke
parents:
diff changeset
56 CompileLog::~CompileLog() {
a61af66fc99e Initial load
duke
parents:
diff changeset
57 delete _out;
a61af66fc99e Initial load
duke
parents:
diff changeset
58 _out = NULL;
6197
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 1972
diff changeset
59 FREE_C_HEAP_ARRAY(char, _identities, mtCompiler);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
60 }
a61af66fc99e Initial load
duke
parents:
diff changeset
61
a61af66fc99e Initial load
duke
parents:
diff changeset
62
a61af66fc99e Initial load
duke
parents:
diff changeset
63 // Advance kind up to a null or space, return this tail.
a61af66fc99e Initial load
duke
parents:
diff changeset
64 // Make sure kind is null-terminated, not space-terminated.
a61af66fc99e Initial load
duke
parents:
diff changeset
65 // Use the buffer if necessary.
a61af66fc99e Initial load
duke
parents:
diff changeset
66 static const char* split_attrs(const char* &kind, char* buffer) {
a61af66fc99e Initial load
duke
parents:
diff changeset
67 const char* attrs = strchr(kind, ' ');
a61af66fc99e Initial load
duke
parents:
diff changeset
68 // Tease apart the first word from the rest:
a61af66fc99e Initial load
duke
parents:
diff changeset
69 if (attrs == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
70 return ""; // no attrs, no split
a61af66fc99e Initial load
duke
parents:
diff changeset
71 } else if (kind == buffer) {
a61af66fc99e Initial load
duke
parents:
diff changeset
72 ((char*) attrs)[-1] = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
73 return attrs;
a61af66fc99e Initial load
duke
parents:
diff changeset
74 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
75 // park it in the buffer, so we can put a null on the end
1489
cff162798819 6888953: some calls to function-like macros are missing semicolons
jcoomes
parents: 0
diff changeset
76 assert(!(kind >= buffer && kind < buffer+100), "not obviously in buffer");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
77 int klen = attrs - kind;
a61af66fc99e Initial load
duke
parents:
diff changeset
78 strncpy(buffer, kind, klen);
a61af66fc99e Initial load
duke
parents:
diff changeset
79 buffer[klen] = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
80 kind = buffer; // return by reference
a61af66fc99e Initial load
duke
parents:
diff changeset
81 return attrs;
a61af66fc99e Initial load
duke
parents:
diff changeset
82 }
a61af66fc99e Initial load
duke
parents:
diff changeset
83 }
a61af66fc99e Initial load
duke
parents:
diff changeset
84
a61af66fc99e Initial load
duke
parents:
diff changeset
85 // see_tag, pop_tag: Override the default do-nothing methods on xmlStream.
a61af66fc99e Initial load
duke
parents:
diff changeset
86 // These methods provide a hook for managing the the extra context markup.
a61af66fc99e Initial load
duke
parents:
diff changeset
87 void CompileLog::see_tag(const char* tag, bool push) {
a61af66fc99e Initial load
duke
parents:
diff changeset
88 if (_context.size() > 0 && _out != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
89 _out->write(_context.base(), _context.size());
a61af66fc99e Initial load
duke
parents:
diff changeset
90 _context.reset();
a61af66fc99e Initial load
duke
parents:
diff changeset
91 }
a61af66fc99e Initial load
duke
parents:
diff changeset
92 xmlStream::see_tag(tag, push);
a61af66fc99e Initial load
duke
parents:
diff changeset
93 }
a61af66fc99e Initial load
duke
parents:
diff changeset
94 void CompileLog::pop_tag(const char* tag) {
a61af66fc99e Initial load
duke
parents:
diff changeset
95 _context.reset(); // toss any context info.
a61af66fc99e Initial load
duke
parents:
diff changeset
96 xmlStream::pop_tag(tag);
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 // CompileLog::identify
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
102 int CompileLog::identify(ciBaseObject* obj) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
103 if (obj == NULL) return 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
104 int id = obj->ident();
a61af66fc99e Initial load
duke
parents:
diff changeset
105 if (id < 0) return id;
a61af66fc99e Initial load
duke
parents:
diff changeset
106 // If it has already been identified, just return the id.
a61af66fc99e Initial load
duke
parents:
diff changeset
107 if (id < _identities_limit && _identities[id] != 0) return id;
a61af66fc99e Initial load
duke
parents:
diff changeset
108 // Lengthen the array, if necessary.
a61af66fc99e Initial load
duke
parents:
diff changeset
109 if (id >= _identities_capacity) {
a61af66fc99e Initial load
duke
parents:
diff changeset
110 int new_cap = _identities_capacity * 2;
a61af66fc99e Initial load
duke
parents:
diff changeset
111 if (new_cap <= id) new_cap = id + 100;
6197
d2a62e0f25eb 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 1972
diff changeset
112 _identities = REALLOC_C_HEAP_ARRAY(char, _identities, new_cap, mtCompiler);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
113 _identities_capacity = new_cap;
a61af66fc99e Initial load
duke
parents:
diff changeset
114 }
a61af66fc99e Initial load
duke
parents:
diff changeset
115 while (id >= _identities_limit) {
a61af66fc99e Initial load
duke
parents:
diff changeset
116 _identities[_identities_limit++] = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
117 }
a61af66fc99e Initial load
duke
parents:
diff changeset
118 assert(id < _identities_limit, "oob");
a61af66fc99e Initial load
duke
parents:
diff changeset
119 // Mark this id as processed.
a61af66fc99e Initial load
duke
parents:
diff changeset
120 // (Be sure to do this before any recursive calls to identify.)
a61af66fc99e Initial load
duke
parents:
diff changeset
121 _identities[id] = 1; // mark
a61af66fc99e Initial load
duke
parents:
diff changeset
122
a61af66fc99e Initial load
duke
parents:
diff changeset
123 // 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
124 if (obj->is_metadata()) {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
125 ciMetadata* mobj = obj->as_metadata();
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
126 if (mobj->is_klass()) {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
127 ciKlass* klass = mobj->as_klass();
6800
9191895df19d 7200001: failed C1 OSR compile doesn't get recompiled with C2
twisti
parents: 6725
diff changeset
128 begin_elem("klass id='%d'", id);
9191895df19d 7200001: failed C1 OSR compile doesn't get recompiled with C2
twisti
parents: 6725
diff changeset
129 name(klass->name());
9191895df19d 7200001: failed C1 OSR compile doesn't get recompiled with C2
twisti
parents: 6725
diff changeset
130 if (!klass->is_loaded()) {
9191895df19d 7200001: failed C1 OSR compile doesn't get recompiled with C2
twisti
parents: 6725
diff changeset
131 print(" unloaded='1'");
9191895df19d 7200001: failed C1 OSR compile doesn't get recompiled with C2
twisti
parents: 6725
diff changeset
132 } else {
9191895df19d 7200001: failed C1 OSR compile doesn't get recompiled with C2
twisti
parents: 6725
diff changeset
133 print(" flags='%d'", klass->modifier_flags());
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 end_elem();
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
136 } else if (mobj->is_method()) {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
137 ciMethod* method = mobj->as_method();
6800
9191895df19d 7200001: failed C1 OSR compile doesn't get recompiled with C2
twisti
parents: 6725
diff changeset
138 ciSignature* sig = method->signature();
9191895df19d 7200001: failed C1 OSR compile doesn't get recompiled with C2
twisti
parents: 6725
diff changeset
139 // Pre-identify items that we will need!
9191895df19d 7200001: failed C1 OSR compile doesn't get recompiled with C2
twisti
parents: 6725
diff changeset
140 identify(sig->return_type());
0
a61af66fc99e Initial load
duke
parents:
diff changeset
141 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
142 identify(sig->type_at(i));
0
a61af66fc99e Initial load
duke
parents:
diff changeset
143 }
6800
9191895df19d 7200001: failed C1 OSR compile doesn't get recompiled with C2
twisti
parents: 6725
diff changeset
144 begin_elem("method id='%d' holder='%d'",
9191895df19d 7200001: failed C1 OSR compile doesn't get recompiled with C2
twisti
parents: 6725
diff changeset
145 id, identify(method->holder()));
9191895df19d 7200001: failed C1 OSR compile doesn't get recompiled with C2
twisti
parents: 6725
diff changeset
146 name(method->name());
9191895df19d 7200001: failed C1 OSR compile doesn't get recompiled with C2
twisti
parents: 6725
diff changeset
147 print(" return='%d'", identify(sig->return_type()));
9191895df19d 7200001: failed C1 OSR compile doesn't get recompiled with C2
twisti
parents: 6725
diff changeset
148 if (sig->count() > 0) {
9191895df19d 7200001: failed C1 OSR compile doesn't get recompiled with C2
twisti
parents: 6725
diff changeset
149 print(" arguments='");
9191895df19d 7200001: failed C1 OSR compile doesn't get recompiled with C2
twisti
parents: 6725
diff changeset
150 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
151 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
152 }
9191895df19d 7200001: failed C1 OSR compile doesn't get recompiled with C2
twisti
parents: 6725
diff changeset
153 print("'");
9191895df19d 7200001: failed C1 OSR compile doesn't get recompiled with C2
twisti
parents: 6725
diff changeset
154 }
9191895df19d 7200001: failed C1 OSR compile doesn't get recompiled with C2
twisti
parents: 6725
diff changeset
155 if (!method->is_loaded()) {
9191895df19d 7200001: failed C1 OSR compile doesn't get recompiled with C2
twisti
parents: 6725
diff changeset
156 print(" unloaded='1'");
9191895df19d 7200001: failed C1 OSR compile doesn't get recompiled with C2
twisti
parents: 6725
diff changeset
157 } else {
9191895df19d 7200001: failed C1 OSR compile doesn't get recompiled with C2
twisti
parents: 6725
diff changeset
158 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
159 // output a few metrics
9191895df19d 7200001: failed C1 OSR compile doesn't get recompiled with C2
twisti
parents: 6725
diff changeset
160 print(" bytes='%d'", method->code_size());
9191895df19d 7200001: failed C1 OSR compile doesn't get recompiled with C2
twisti
parents: 6725
diff changeset
161 method->log_nmethod_identity(this);
9191895df19d 7200001: failed C1 OSR compile doesn't get recompiled with C2
twisti
parents: 6725
diff changeset
162 //print(" count='%d'", method->invocation_count());
9191895df19d 7200001: failed C1 OSR compile doesn't get recompiled with C2
twisti
parents: 6725
diff changeset
163 //int bec = method->backedge_count();
9191895df19d 7200001: failed C1 OSR compile doesn't get recompiled with C2
twisti
parents: 6725
diff changeset
164 //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
165 print(" iicount='%d'", method->interpreter_invocation_count());
9191895df19d 7200001: failed C1 OSR compile doesn't get recompiled with C2
twisti
parents: 6725
diff changeset
166 }
9191895df19d 7200001: failed C1 OSR compile doesn't get recompiled with C2
twisti
parents: 6725
diff changeset
167 end_elem();
6725
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
168 } else if (mobj->is_type()) {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
169 BasicType type = mobj->as_type()->basic_type();
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
170 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
171 } else {
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
172 // Should not happen.
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
173 elem("unknown id='%d'", id);
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
174 ShouldNotReachHere();
da91efe96a93 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 6197
diff changeset
175 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
176 } else if (obj->is_symbol()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
177 begin_elem("symbol id='%d'", id);
a61af66fc99e Initial load
duke
parents:
diff changeset
178 name(obj->as_symbol());
a61af66fc99e Initial load
duke
parents:
diff changeset
179 end_elem();
a61af66fc99e Initial load
duke
parents:
diff changeset
180 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
181 // Should not happen.
a61af66fc99e Initial load
duke
parents:
diff changeset
182 elem("unknown id='%d'", id);
a61af66fc99e Initial load
duke
parents:
diff changeset
183 }
a61af66fc99e Initial load
duke
parents:
diff changeset
184 return id;
a61af66fc99e Initial load
duke
parents:
diff changeset
185 }
a61af66fc99e Initial load
duke
parents:
diff changeset
186
a61af66fc99e Initial load
duke
parents:
diff changeset
187 void CompileLog::name(ciSymbol* name) {
a61af66fc99e Initial load
duke
parents:
diff changeset
188 if (name == NULL) return;
a61af66fc99e Initial load
duke
parents:
diff changeset
189 print(" name='");
a61af66fc99e Initial load
duke
parents:
diff changeset
190 name->print_symbol_on(text()); // handles quoting conventions
a61af66fc99e Initial load
duke
parents:
diff changeset
191 print("'");
a61af66fc99e Initial load
duke
parents:
diff changeset
192 }
a61af66fc99e Initial load
duke
parents:
diff changeset
193
a61af66fc99e Initial load
duke
parents:
diff changeset
194
a61af66fc99e Initial load
duke
parents:
diff changeset
195 // ------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
196 // CompileLog::clear_identities
a61af66fc99e Initial load
duke
parents:
diff changeset
197 // Forget which identities have been printed.
a61af66fc99e Initial load
duke
parents:
diff changeset
198 void CompileLog::clear_identities() {
a61af66fc99e Initial load
duke
parents:
diff changeset
199 _identities_limit = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
200 }
a61af66fc99e Initial load
duke
parents:
diff changeset
201
a61af66fc99e Initial load
duke
parents:
diff changeset
202 // ------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
203 // CompileLog::finish_log_on_error
a61af66fc99e Initial load
duke
parents:
diff changeset
204 //
a61af66fc99e Initial load
duke
parents:
diff changeset
205 // Note: This function is called after fatal error, avoid unnecessary memory
a61af66fc99e Initial load
duke
parents:
diff changeset
206 // or stack allocation, use only async-safe functions. It's possible JVM is
a61af66fc99e Initial load
duke
parents:
diff changeset
207 // only partially initialized.
a61af66fc99e Initial load
duke
parents:
diff changeset
208 void CompileLog::finish_log_on_error(outputStream* file, char* buf, int buflen) {
a61af66fc99e Initial load
duke
parents:
diff changeset
209 static bool called_exit = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
210 if (called_exit) return;
a61af66fc99e Initial load
duke
parents:
diff changeset
211 called_exit = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
212
a61af66fc99e Initial load
duke
parents:
diff changeset
213 for (CompileLog* log = _first; log != NULL; log = log->_next) {
a61af66fc99e Initial load
duke
parents:
diff changeset
214 log->flush();
a61af66fc99e Initial load
duke
parents:
diff changeset
215 const char* partial_file = log->file();
a61af66fc99e Initial load
duke
parents:
diff changeset
216 int partial_fd = open(partial_file, O_RDONLY);
a61af66fc99e Initial load
duke
parents:
diff changeset
217 if (partial_fd != -1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
218 // print/print_cr may need to allocate large stack buffer to format
a61af66fc99e Initial load
duke
parents:
diff changeset
219 // strings, here we use snprintf() and print_raw() instead.
a61af66fc99e Initial load
duke
parents:
diff changeset
220 file->print_raw("<compilation_log thread='");
a61af66fc99e Initial load
duke
parents:
diff changeset
221 jio_snprintf(buf, buflen, UINTX_FORMAT, log->thread_id());
a61af66fc99e Initial load
duke
parents:
diff changeset
222 file->print_raw(buf);
a61af66fc99e Initial load
duke
parents:
diff changeset
223 file->print_raw_cr("'>");
a61af66fc99e Initial load
duke
parents:
diff changeset
224
a61af66fc99e Initial load
duke
parents:
diff changeset
225 size_t nr; // number read into buf from partial log
a61af66fc99e Initial load
duke
parents:
diff changeset
226 // Copy data up to the end of the last <event> element:
a61af66fc99e Initial load
duke
parents:
diff changeset
227 julong to_read = log->_file_end;
a61af66fc99e Initial load
duke
parents:
diff changeset
228 while (to_read > 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
229 if (to_read < (julong)buflen)
a61af66fc99e Initial load
duke
parents:
diff changeset
230 nr = (size_t)to_read;
a61af66fc99e Initial load
duke
parents:
diff changeset
231 else nr = buflen;
a61af66fc99e Initial load
duke
parents:
diff changeset
232 nr = read(partial_fd, buf, (int)nr);
a61af66fc99e Initial load
duke
parents:
diff changeset
233 if (nr <= 0) break;
a61af66fc99e Initial load
duke
parents:
diff changeset
234 to_read -= (julong)nr;
a61af66fc99e Initial load
duke
parents:
diff changeset
235 file->write(buf, nr);
a61af66fc99e Initial load
duke
parents:
diff changeset
236 }
a61af66fc99e Initial load
duke
parents:
diff changeset
237
a61af66fc99e Initial load
duke
parents:
diff changeset
238 // Copy any remaining data inside a quote:
a61af66fc99e Initial load
duke
parents:
diff changeset
239 bool saw_slop = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
240 int end_cdata = 0; // state machine [0..2] watching for too many "]]"
a61af66fc99e Initial load
duke
parents:
diff changeset
241 while ((nr = read(partial_fd, buf, buflen)) > 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
242 if (!saw_slop) {
a61af66fc99e Initial load
duke
parents:
diff changeset
243 file->print_raw_cr("<fragment>");
a61af66fc99e Initial load
duke
parents:
diff changeset
244 file->print_raw_cr("<![CDATA[");
a61af66fc99e Initial load
duke
parents:
diff changeset
245 saw_slop = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
246 }
a61af66fc99e Initial load
duke
parents:
diff changeset
247 // The rest of this loop amounts to a simple copy operation:
a61af66fc99e Initial load
duke
parents:
diff changeset
248 // { file->write(buf, nr); }
a61af66fc99e Initial load
duke
parents:
diff changeset
249 // However, it must sometimes output the buffer in parts,
a61af66fc99e Initial load
duke
parents:
diff changeset
250 // in case there is a CDATA quote embedded in the fragment.
a61af66fc99e Initial load
duke
parents:
diff changeset
251 const char* bufp; // pointer into buf
a61af66fc99e Initial load
duke
parents:
diff changeset
252 size_t nw; // number written in each pass of the following loop:
a61af66fc99e Initial load
duke
parents:
diff changeset
253 for (bufp = buf; nr > 0; nr -= nw, bufp += nw) {
a61af66fc99e Initial load
duke
parents:
diff changeset
254 // Write up to any problematic CDATA delimiter (usually all of nr).
a61af66fc99e Initial load
duke
parents:
diff changeset
255 for (nw = 0; nw < nr; nw++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
256 // First, scan ahead into the buf, checking the state machine.
a61af66fc99e Initial load
duke
parents:
diff changeset
257 switch (bufp[nw]) {
a61af66fc99e Initial load
duke
parents:
diff changeset
258 case ']':
a61af66fc99e Initial load
duke
parents:
diff changeset
259 if (end_cdata < 2) end_cdata += 1; // saturating counter
a61af66fc99e Initial load
duke
parents:
diff changeset
260 continue; // keep scanning
a61af66fc99e Initial load
duke
parents:
diff changeset
261 case '>':
a61af66fc99e Initial load
duke
parents:
diff changeset
262 if (end_cdata == 2) break; // found CDATA delimiter!
a61af66fc99e Initial load
duke
parents:
diff changeset
263 // else fall through:
a61af66fc99e Initial load
duke
parents:
diff changeset
264 default:
a61af66fc99e Initial load
duke
parents:
diff changeset
265 end_cdata = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
266 continue; // keep scanning
a61af66fc99e Initial load
duke
parents:
diff changeset
267 }
a61af66fc99e Initial load
duke
parents:
diff changeset
268 // If we get here, nw is pointing at a bad '>'.
a61af66fc99e Initial load
duke
parents:
diff changeset
269 // It is very rare for this to happen.
a61af66fc99e Initial load
duke
parents:
diff changeset
270 // However, this code has been tested by introducing
a61af66fc99e Initial load
duke
parents:
diff changeset
271 // CDATA sequences into the compilation log.
a61af66fc99e Initial load
duke
parents:
diff changeset
272 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
273 }
a61af66fc99e Initial load
duke
parents:
diff changeset
274 // Now nw is the number of characters to write, usually == nr.
a61af66fc99e Initial load
duke
parents:
diff changeset
275 file->write(bufp, nw);
a61af66fc99e Initial load
duke
parents:
diff changeset
276 if (nw < nr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
277 // We are about to go around the loop again.
a61af66fc99e Initial load
duke
parents:
diff changeset
278 // But first, disrupt the ]]> by closing and reopening the quote.
a61af66fc99e Initial load
duke
parents:
diff changeset
279 file->print_raw("]]><![CDATA[");
a61af66fc99e Initial load
duke
parents:
diff changeset
280 end_cdata = 0; // reset state machine
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 if (saw_slop) {
a61af66fc99e Initial load
duke
parents:
diff changeset
285 file->print_raw_cr("]]>");
a61af66fc99e Initial load
duke
parents:
diff changeset
286 file->print_raw_cr("</fragment>");
a61af66fc99e Initial load
duke
parents:
diff changeset
287 }
a61af66fc99e Initial load
duke
parents:
diff changeset
288 file->print_raw_cr("</compilation_log>");
a61af66fc99e Initial load
duke
parents:
diff changeset
289 close(partial_fd);
a61af66fc99e Initial load
duke
parents:
diff changeset
290 unlink(partial_file);
a61af66fc99e Initial load
duke
parents:
diff changeset
291 }
a61af66fc99e Initial load
duke
parents:
diff changeset
292 }
a61af66fc99e Initial load
duke
parents:
diff changeset
293 }
a61af66fc99e Initial load
duke
parents:
diff changeset
294
a61af66fc99e Initial load
duke
parents:
diff changeset
295 // ------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
296 // CompileLog::finish_log
a61af66fc99e Initial load
duke
parents:
diff changeset
297 //
a61af66fc99e Initial load
duke
parents:
diff changeset
298 // Called during normal shutdown. For now, any clean-up needed in normal
a61af66fc99e Initial load
duke
parents:
diff changeset
299 // shutdown is also needed in VM abort, so is covered by finish_log_on_error().
a61af66fc99e Initial load
duke
parents:
diff changeset
300 // Just allocate a buffer and call finish_log_on_error().
a61af66fc99e Initial load
duke
parents:
diff changeset
301 void CompileLog::finish_log(outputStream* file) {
a61af66fc99e Initial load
duke
parents:
diff changeset
302 char buf[4 * K];
a61af66fc99e Initial load
duke
parents:
diff changeset
303 finish_log_on_error(file, buf, sizeof(buf));
a61af66fc99e Initial load
duke
parents:
diff changeset
304 }