Mercurial > hg > truffle
annotate src/share/vm/utilities/ostream.cpp @ 21202:a03e95b6d629
MoveResolver: refactor handling of blocked registers.
author | Josef Eisl <josef.eisl@jku.at> |
---|---|
date | Mon, 27 Apr 2015 16:26:14 +0200 |
parents | 7848fc12602b |
children |
rev | line source |
---|---|
0 | 1 /* |
17937
78bbf4d43a14
8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents:
17827
diff
changeset
|
2 * Copyright (c) 1997, 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:
1353
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1353
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:
1353
diff
changeset
|
21 * questions. |
0 | 22 * |
23 */ | |
24 | |
1972 | 25 #include "precompiled.hpp" |
26 #include "compiler/compileLog.hpp" | |
20190
0982ec23da03
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
17937
diff
changeset
|
27 #include "gc_implementation/shared/gcId.hpp" |
1972 | 28 #include "oops/oop.inline.hpp" |
29 #include "runtime/arguments.hpp" | |
30 #include "utilities/defaultStream.hpp" | |
31 #include "utilities/ostream.hpp" | |
32 #include "utilities/top.hpp" | |
33 #include "utilities/xmlstream.hpp" | |
34 #ifdef TARGET_OS_FAMILY_linux | |
35 # include "os_linux.inline.hpp" | |
36 #endif | |
37 #ifdef TARGET_OS_FAMILY_solaris | |
38 # include "os_solaris.inline.hpp" | |
39 #endif | |
40 #ifdef TARGET_OS_FAMILY_windows | |
41 # include "os_windows.inline.hpp" | |
42 #endif | |
14411 | 43 #ifdef TARGET_OS_FAMILY_aix |
44 # include "os_aix.inline.hpp" | |
45 #endif | |
3960 | 46 #ifdef TARGET_OS_FAMILY_bsd |
47 # include "os_bsd.inline.hpp" | |
48 #endif | |
0 | 49 |
50 extern "C" void jio_print(const char* s); // Declarationtion of jvm method | |
51 | |
52 outputStream::outputStream(int width) { | |
53 _width = width; | |
54 _position = 0; | |
55 _newlines = 0; | |
56 _precount = 0; | |
57 _indentation = 0; | |
58 } | |
59 | |
60 outputStream::outputStream(int width, bool has_time_stamps) { | |
61 _width = width; | |
62 _position = 0; | |
63 _newlines = 0; | |
64 _precount = 0; | |
65 _indentation = 0; | |
66 if (has_time_stamps) _stamp.update(); | |
67 } | |
68 | |
69 void outputStream::update_position(const char* s, size_t len) { | |
70 for (size_t i = 0; i < len; i++) { | |
71 char ch = s[i]; | |
72 if (ch == '\n') { | |
73 _newlines += 1; | |
74 _precount += _position + 1; | |
75 _position = 0; | |
76 } else if (ch == '\t') { | |
100
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
0
diff
changeset
|
77 int tw = 8 - (_position & 7); |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
0
diff
changeset
|
78 _position += tw; |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
0
diff
changeset
|
79 _precount -= tw-1; // invariant: _precount + _position == total count |
0 | 80 } else { |
81 _position += 1; | |
82 } | |
83 } | |
84 } | |
85 | |
86 // Execute a vsprintf, using the given buffer if necessary. | |
87 // Return a pointer to the formatted string. | |
88 const char* outputStream::do_vsnprintf(char* buffer, size_t buflen, | |
89 const char* format, va_list ap, | |
90 bool add_cr, | |
91 size_t& result_len) { | |
92 const char* result; | |
93 if (add_cr) buflen--; | |
94 if (!strchr(format, '%')) { | |
95 // constant format string | |
96 result = format; | |
97 result_len = strlen(result); | |
98 if (add_cr && result_len >= buflen) result_len = buflen-1; // truncate | |
99 } else if (format[0] == '%' && format[1] == 's' && format[2] == '\0') { | |
100 // trivial copy-through format string | |
101 result = va_arg(ap, const char*); | |
102 result_len = strlen(result); | |
103 if (add_cr && result_len >= buflen) result_len = buflen-1; // truncate | |
104 } else if (vsnprintf(buffer, buflen, format, ap) >= 0) { | |
105 result = buffer; | |
106 result_len = strlen(result); | |
107 } else { | |
108 DEBUG_ONLY(warning("increase O_BUFLEN in ostream.hpp -- output truncated");) | |
109 result = buffer; | |
110 result_len = buflen - 1; | |
111 buffer[result_len] = 0; | |
112 } | |
113 if (add_cr) { | |
114 if (result != buffer) { | |
115 strncpy(buffer, result, buflen); | |
116 result = buffer; | |
117 } | |
118 buffer[result_len++] = '\n'; | |
119 buffer[result_len] = 0; | |
120 } | |
121 return result; | |
122 } | |
123 | |
124 void outputStream::print(const char* format, ...) { | |
125 char buffer[O_BUFLEN]; | |
126 va_list ap; | |
127 va_start(ap, format); | |
128 size_t len; | |
129 const char* str = do_vsnprintf(buffer, O_BUFLEN, format, ap, false, len); | |
130 write(str, len); | |
131 va_end(ap); | |
132 } | |
133 | |
134 void outputStream::print_cr(const char* format, ...) { | |
135 char buffer[O_BUFLEN]; | |
136 va_list ap; | |
137 va_start(ap, format); | |
138 size_t len; | |
139 const char* str = do_vsnprintf(buffer, O_BUFLEN, format, ap, true, len); | |
140 write(str, len); | |
141 va_end(ap); | |
142 } | |
143 | |
144 void outputStream::vprint(const char *format, va_list argptr) { | |
145 char buffer[O_BUFLEN]; | |
146 size_t len; | |
147 const char* str = do_vsnprintf(buffer, O_BUFLEN, format, argptr, false, len); | |
148 write(str, len); | |
149 } | |
150 | |
151 void outputStream::vprint_cr(const char* format, va_list argptr) { | |
152 char buffer[O_BUFLEN]; | |
153 size_t len; | |
154 const char* str = do_vsnprintf(buffer, O_BUFLEN, format, argptr, true, len); | |
155 write(str, len); | |
156 } | |
157 | |
158 void outputStream::fill_to(int col) { | |
100
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
0
diff
changeset
|
159 int need_fill = col - position(); |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
0
diff
changeset
|
160 sp(need_fill); |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
0
diff
changeset
|
161 } |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
0
diff
changeset
|
162 |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
0
diff
changeset
|
163 void outputStream::move_to(int col, int slop, int min_space) { |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
0
diff
changeset
|
164 if (position() >= col + slop) |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
0
diff
changeset
|
165 cr(); |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
0
diff
changeset
|
166 int need_fill = col - position(); |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
0
diff
changeset
|
167 if (need_fill < min_space) |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
0
diff
changeset
|
168 need_fill = min_space; |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
0
diff
changeset
|
169 sp(need_fill); |
0 | 170 } |
171 | |
172 void outputStream::put(char ch) { | |
173 assert(ch != 0, "please fix call site"); | |
174 char buf[] = { ch, '\0' }; | |
175 write(buf, 1); | |
176 } | |
177 | |
100
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
0
diff
changeset
|
178 #define SP_USE_TABS false |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
0
diff
changeset
|
179 |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
0
diff
changeset
|
180 void outputStream::sp(int count) { |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
0
diff
changeset
|
181 if (count < 0) return; |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
0
diff
changeset
|
182 if (SP_USE_TABS && count >= 8) { |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
0
diff
changeset
|
183 int target = position() + count; |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
0
diff
changeset
|
184 while (count >= 8) { |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
0
diff
changeset
|
185 this->write("\t", 1); |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
0
diff
changeset
|
186 count -= 8; |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
0
diff
changeset
|
187 } |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
0
diff
changeset
|
188 count = target - position(); |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
0
diff
changeset
|
189 } |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
0
diff
changeset
|
190 while (count > 0) { |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
0
diff
changeset
|
191 int nw = (count > 8) ? 8 : count; |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
0
diff
changeset
|
192 this->write(" ", nw); |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
0
diff
changeset
|
193 count -= nw; |
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
0
diff
changeset
|
194 } |
0 | 195 } |
196 | |
197 void outputStream::cr() { | |
198 this->write("\n", 1); | |
199 } | |
200 | |
201 void outputStream::stamp() { | |
202 if (! _stamp.is_updated()) { | |
203 _stamp.update(); // start at 0 on first call to stamp() | |
204 } | |
205 | |
206 // outputStream::stamp() may get called by ostream_abort(), use snprintf | |
207 // to avoid allocating large stack buffer in print(). | |
208 char buf[40]; | |
209 jio_snprintf(buf, sizeof(buf), "%.3f", _stamp.seconds()); | |
210 print_raw(buf); | |
211 } | |
212 | |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
102
diff
changeset
|
213 void outputStream::stamp(bool guard, |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
102
diff
changeset
|
214 const char* prefix, |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
102
diff
changeset
|
215 const char* suffix) { |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
102
diff
changeset
|
216 if (!guard) { |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
102
diff
changeset
|
217 return; |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
102
diff
changeset
|
218 } |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
102
diff
changeset
|
219 print_raw(prefix); |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
102
diff
changeset
|
220 stamp(); |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
102
diff
changeset
|
221 print_raw(suffix); |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
102
diff
changeset
|
222 } |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
102
diff
changeset
|
223 |
0 | 224 void outputStream::date_stamp(bool guard, |
225 const char* prefix, | |
226 const char* suffix) { | |
227 if (!guard) { | |
228 return; | |
229 } | |
230 print_raw(prefix); | |
231 static const char error_time[] = "yyyy-mm-ddThh:mm:ss.mmm+zzzz"; | |
232 static const int buffer_length = 32; | |
233 char buffer[buffer_length]; | |
234 const char* iso8601_result = os::iso8601_time(buffer, buffer_length); | |
235 if (iso8601_result != NULL) { | |
236 print_raw(buffer); | |
237 } else { | |
238 print_raw(error_time); | |
239 } | |
240 print_raw(suffix); | |
241 return; | |
242 } | |
243 | |
20190
0982ec23da03
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
17937
diff
changeset
|
244 void outputStream::gclog_stamp(const GCId& gc_id) { |
0982ec23da03
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
17937
diff
changeset
|
245 date_stamp(PrintGCDateStamps); |
0982ec23da03
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
17937
diff
changeset
|
246 stamp(PrintGCTimeStamps); |
0982ec23da03
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
17937
diff
changeset
|
247 if (PrintGCID) { |
0982ec23da03
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
17937
diff
changeset
|
248 print("#%u: ", gc_id.id()); |
0982ec23da03
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
17937
diff
changeset
|
249 } |
0982ec23da03
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
17937
diff
changeset
|
250 } |
0982ec23da03
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
17937
diff
changeset
|
251 |
6605 | 252 outputStream& outputStream::indent() { |
0 | 253 while (_position < _indentation) sp(); |
6605 | 254 return *this; |
0 | 255 } |
256 | |
257 void outputStream::print_jlong(jlong value) { | |
7623
203f64878aab
7102489: RFE: cleanup jlong typedef on __APPLE__and _LLP64 systems.
hseigel
parents:
6843
diff
changeset
|
258 print(JLONG_FORMAT, value); |
0 | 259 } |
260 | |
261 void outputStream::print_julong(julong value) { | |
7623
203f64878aab
7102489: RFE: cleanup jlong typedef on __APPLE__and _LLP64 systems.
hseigel
parents:
6843
diff
changeset
|
262 print(JULONG_FORMAT, value); |
0 | 263 } |
264 | |
6605 | 265 /** |
266 * This prints out hex data in a 'windbg' or 'xxd' form, where each line is: | |
267 * <hex-address>: 8 * <hex-halfword> <ascii translation (optional)> | |
268 * example: | |
269 * 0000000: 7f44 4f46 0102 0102 0000 0000 0000 0000 .DOF............ | |
270 * 0000010: 0000 0000 0000 0040 0000 0020 0000 0005 .......@... .... | |
271 * 0000020: 0000 0000 0000 0040 0000 0000 0000 015d .......@.......] | |
272 * ... | |
273 * | |
274 * indent is applied to each line. Ends with a CR. | |
275 */ | |
276 void outputStream::print_data(void* data, size_t len, bool with_ascii) { | |
277 size_t limit = (len + 16) / 16 * 16; | |
278 for (size_t i = 0; i < limit; ++i) { | |
279 if (i % 16 == 0) { | |
17937
78bbf4d43a14
8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents:
17827
diff
changeset
|
280 indent().print(SIZE_FORMAT_HEX_W(07)":", i); |
6605 | 281 } |
282 if (i % 2 == 0) { | |
283 print(" "); | |
284 } | |
285 if (i < len) { | |
286 print("%02x", ((unsigned char*)data)[i]); | |
287 } else { | |
288 print(" "); | |
289 } | |
290 if ((i + 1) % 16 == 0) { | |
291 if (with_ascii) { | |
292 print(" "); | |
293 for (size_t j = 0; j < 16; ++j) { | |
294 size_t idx = i + j - 15; | |
295 if (idx < len) { | |
296 char c = ((char*)data)[idx]; | |
297 print("%c", c >= 32 && c <= 126 ? c : '.'); | |
298 } | |
299 } | |
300 } | |
17937
78bbf4d43a14
8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents:
17827
diff
changeset
|
301 cr(); |
6605 | 302 } |
303 } | |
304 } | |
305 | |
0 | 306 stringStream::stringStream(size_t initial_size) : outputStream() { |
307 buffer_length = initial_size; | |
308 buffer = NEW_RESOURCE_ARRAY(char, buffer_length); | |
309 buffer_pos = 0; | |
310 buffer_fixed = false; | |
11136
dbc0b5dc08f5
7143807: ResourceMark nesting problem in stringStream
fparain
parents:
8108
diff
changeset
|
311 DEBUG_ONLY(rm = Thread::current()->current_resource_mark();) |
0 | 312 } |
313 | |
314 // useful for output to fixed chunks of memory, such as performance counters | |
315 stringStream::stringStream(char* fixed_buffer, size_t fixed_buffer_size) : outputStream() { | |
316 buffer_length = fixed_buffer_size; | |
317 buffer = fixed_buffer; | |
318 buffer_pos = 0; | |
319 buffer_fixed = true; | |
320 } | |
321 | |
322 void stringStream::write(const char* s, size_t len) { | |
323 size_t write_len = len; // number of non-null bytes to write | |
324 size_t end = buffer_pos + len + 1; // position after write and final '\0' | |
325 if (end > buffer_length) { | |
326 if (buffer_fixed) { | |
327 // if buffer cannot resize, silently truncate | |
328 end = buffer_length; | |
329 write_len = end - buffer_pos - 1; // leave room for the final '\0' | |
330 } else { | |
331 // For small overruns, double the buffer. For larger ones, | |
332 // increase to the requested size. | |
333 if (end < buffer_length * 2) { | |
334 end = buffer_length * 2; | |
335 } | |
336 char* oldbuf = buffer; | |
11136
dbc0b5dc08f5
7143807: ResourceMark nesting problem in stringStream
fparain
parents:
8108
diff
changeset
|
337 assert(rm == NULL || Thread::current()->current_resource_mark() == rm, |
dbc0b5dc08f5
7143807: ResourceMark nesting problem in stringStream
fparain
parents:
8108
diff
changeset
|
338 "stringStream is re-allocated with a different ResourceMark"); |
0 | 339 buffer = NEW_RESOURCE_ARRAY(char, end); |
340 strncpy(buffer, oldbuf, buffer_pos); | |
341 buffer_length = end; | |
342 } | |
343 } | |
344 // invariant: buffer is always null-terminated | |
345 guarantee(buffer_pos + write_len + 1 <= buffer_length, "stringStream oob"); | |
346 buffer[buffer_pos + write_len] = 0; | |
347 strncpy(buffer + buffer_pos, s, write_len); | |
348 buffer_pos += write_len; | |
349 | |
350 // Note that the following does not depend on write_len. | |
351 // This means that position and count get updated | |
352 // even when overflow occurs. | |
353 update_position(s, len); | |
354 } | |
355 | |
356 char* stringStream::as_string() { | |
12215 | 357 char* copy = NEW_RESOURCE_ARRAY(char, buffer_pos + 1); |
0 | 358 strncpy(copy, buffer, buffer_pos); |
359 copy[buffer_pos] = 0; // terminating null | |
360 return copy; | |
361 } | |
362 | |
363 stringStream::~stringStream() {} | |
364 | |
365 xmlStream* xtty; | |
366 outputStream* tty; | |
367 outputStream* gclog_or_tty; | |
20375
6e0cb14ce59b
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
20190
diff
changeset
|
368 CDS_ONLY(fileStream* classlist_file;) // Only dump the classes that can be stored into the CDS archive |
0 | 369 extern Mutex* tty_lock; |
370 | |
12215 | 371 #define EXTRACHARLEN 32 |
372 #define CURRENTAPPX ".current" | |
373 // convert YYYY-MM-DD HH:MM:SS to YYYY-MM-DD_HH-MM-SS | |
374 char* get_datetime_string(char *buf, size_t len) { | |
375 os::local_time_string(buf, len); | |
376 int i = (int)strlen(buf); | |
377 while (i-- >= 0) { | |
378 if (buf[i] == ' ') buf[i] = '_'; | |
379 else if (buf[i] == ':') buf[i] = '-'; | |
380 } | |
381 return buf; | |
382 } | |
383 | |
384 static const char* make_log_name_internal(const char* log_name, const char* force_directory, | |
385 int pid, const char* tms) { | |
386 const char* basename = log_name; | |
387 char file_sep = os::file_separator()[0]; | |
388 const char* cp; | |
389 char pid_text[32]; | |
390 | |
391 for (cp = log_name; *cp != '\0'; cp++) { | |
392 if (*cp == '/' || *cp == file_sep) { | |
393 basename = cp + 1; | |
394 } | |
395 } | |
396 const char* nametail = log_name; | |
397 // Compute buffer length | |
398 size_t buffer_length; | |
399 if (force_directory != NULL) { | |
400 buffer_length = strlen(force_directory) + strlen(os::file_separator()) + | |
401 strlen(basename) + 1; | |
402 } else { | |
403 buffer_length = strlen(log_name) + 1; | |
404 } | |
405 | |
406 const char* pts = strstr(basename, "%p"); | |
407 int pid_pos = (pts == NULL) ? -1 : (pts - nametail); | |
408 | |
409 if (pid_pos >= 0) { | |
410 jio_snprintf(pid_text, sizeof(pid_text), "pid%u", pid); | |
411 buffer_length += strlen(pid_text); | |
412 } | |
413 | |
414 pts = strstr(basename, "%t"); | |
415 int tms_pos = (pts == NULL) ? -1 : (pts - nametail); | |
416 if (tms_pos >= 0) { | |
417 buffer_length += strlen(tms); | |
418 } | |
419 | |
20734 | 420 // File name is too long. |
421 if (buffer_length > JVM_MAXPATHLEN) { | |
422 return NULL; | |
423 } | |
424 | |
12215 | 425 // Create big enough buffer. |
426 char *buf = NEW_C_HEAP_ARRAY(char, buffer_length, mtInternal); | |
427 | |
428 strcpy(buf, ""); | |
429 if (force_directory != NULL) { | |
430 strcat(buf, force_directory); | |
431 strcat(buf, os::file_separator()); | |
432 nametail = basename; // completely skip directory prefix | |
433 } | |
434 | |
435 // who is first, %p or %t? | |
436 int first = -1, second = -1; | |
437 const char *p1st = NULL; | |
438 const char *p2nd = NULL; | |
439 | |
440 if (pid_pos >= 0 && tms_pos >= 0) { | |
441 // contains both %p and %t | |
442 if (pid_pos < tms_pos) { | |
443 // case foo%pbar%tmonkey.log | |
444 first = pid_pos; | |
445 p1st = pid_text; | |
446 second = tms_pos; | |
447 p2nd = tms; | |
448 } else { | |
449 // case foo%tbar%pmonkey.log | |
450 first = tms_pos; | |
451 p1st = tms; | |
452 second = pid_pos; | |
453 p2nd = pid_text; | |
454 } | |
455 } else if (pid_pos >= 0) { | |
456 // contains %p only | |
457 first = pid_pos; | |
458 p1st = pid_text; | |
459 } else if (tms_pos >= 0) { | |
460 // contains %t only | |
461 first = tms_pos; | |
462 p1st = tms; | |
463 } | |
464 | |
465 int buf_pos = (int)strlen(buf); | |
466 const char* tail = nametail; | |
467 | |
468 if (first >= 0) { | |
469 tail = nametail + first + 2; | |
470 strncpy(&buf[buf_pos], nametail, first); | |
471 strcpy(&buf[buf_pos + first], p1st); | |
472 buf_pos = (int)strlen(buf); | |
473 if (second >= 0) { | |
474 strncpy(&buf[buf_pos], tail, second - first - 2); | |
475 strcpy(&buf[buf_pos + second - first - 2], p2nd); | |
476 tail = nametail + second + 2; | |
477 } | |
478 } | |
479 strcat(buf, tail); // append rest of name, or all of name | |
480 return buf; | |
481 } | |
482 | |
20375
6e0cb14ce59b
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
20190
diff
changeset
|
483 // log_name comes from -XX:LogFile=log_name, -Xloggc:log_name or |
6e0cb14ce59b
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
20190
diff
changeset
|
484 // -XX:DumpLoadedClassList=<file_name> |
12864
bf8a21c3ab3b
8025849: Redundant "pid" in VM log file name (e.g. hotspot_pidpid12345.log)
vlivanov
parents:
12269
diff
changeset
|
485 // in log_name, %p => pid1234 and |
12215 | 486 // %t => YYYY-MM-DD_HH-MM-SS |
487 static const char* make_log_name(const char* log_name, const char* force_directory) { | |
488 char timestr[32]; | |
489 get_datetime_string(timestr, sizeof(timestr)); | |
490 return make_log_name_internal(log_name, force_directory, os::current_process_id(), | |
491 timestr); | |
492 } | |
493 | |
494 #ifndef PRODUCT | |
495 void test_loggc_filename() { | |
496 int pid; | |
497 char tms[32]; | |
20734 | 498 char i_result[JVM_MAXPATHLEN]; |
12215 | 499 const char* o_result; |
500 get_datetime_string(tms, sizeof(tms)); | |
501 pid = os::current_process_id(); | |
502 | |
503 // test.log | |
20734 | 504 jio_snprintf(i_result, JVM_MAXPATHLEN, "test.log", tms); |
12215 | 505 o_result = make_log_name_internal("test.log", NULL, pid, tms); |
506 assert(strcmp(i_result, o_result) == 0, "failed on testing make_log_name(\"test.log\", NULL)"); | |
507 FREE_C_HEAP_ARRAY(char, o_result, mtInternal); | |
508 | |
509 // test-%t-%p.log | |
20734 | 510 jio_snprintf(i_result, JVM_MAXPATHLEN, "test-%s-pid%u.log", tms, pid); |
12215 | 511 o_result = make_log_name_internal("test-%t-%p.log", NULL, pid, tms); |
512 assert(strcmp(i_result, o_result) == 0, "failed on testing make_log_name(\"test-%%t-%%p.log\", NULL)"); | |
513 FREE_C_HEAP_ARRAY(char, o_result, mtInternal); | |
514 | |
515 // test-%t%p.log | |
20734 | 516 jio_snprintf(i_result, JVM_MAXPATHLEN, "test-%spid%u.log", tms, pid); |
12215 | 517 o_result = make_log_name_internal("test-%t%p.log", NULL, pid, tms); |
518 assert(strcmp(i_result, o_result) == 0, "failed on testing make_log_name(\"test-%%t%%p.log\", NULL)"); | |
519 FREE_C_HEAP_ARRAY(char, o_result, mtInternal); | |
520 | |
521 // %p%t.log | |
20734 | 522 jio_snprintf(i_result, JVM_MAXPATHLEN, "pid%u%s.log", pid, tms); |
12215 | 523 o_result = make_log_name_internal("%p%t.log", NULL, pid, tms); |
524 assert(strcmp(i_result, o_result) == 0, "failed on testing make_log_name(\"%%p%%t.log\", NULL)"); | |
525 FREE_C_HEAP_ARRAY(char, o_result, mtInternal); | |
526 | |
527 // %p-test.log | |
20734 | 528 jio_snprintf(i_result, JVM_MAXPATHLEN, "pid%u-test.log", pid); |
12215 | 529 o_result = make_log_name_internal("%p-test.log", NULL, pid, tms); |
530 assert(strcmp(i_result, o_result) == 0, "failed on testing make_log_name(\"%%p-test.log\", NULL)"); | |
531 FREE_C_HEAP_ARRAY(char, o_result, mtInternal); | |
532 | |
533 // %t.log | |
20734 | 534 jio_snprintf(i_result, JVM_MAXPATHLEN, "%s.log", tms); |
12215 | 535 o_result = make_log_name_internal("%t.log", NULL, pid, tms); |
536 assert(strcmp(i_result, o_result) == 0, "failed on testing make_log_name(\"%%t.log\", NULL)"); | |
537 FREE_C_HEAP_ARRAY(char, o_result, mtInternal); | |
20734 | 538 |
539 { | |
540 // longest filename | |
541 char longest_name[JVM_MAXPATHLEN]; | |
542 memset(longest_name, 'a', sizeof(longest_name)); | |
543 longest_name[JVM_MAXPATHLEN - 1] = '\0'; | |
544 o_result = make_log_name_internal((const char*)&longest_name, NULL, pid, tms); | |
545 assert(strcmp(longest_name, o_result) == 0, err_msg("longest name does not match. expected '%s' but got '%s'", longest_name, o_result)); | |
546 FREE_C_HEAP_ARRAY(char, o_result, mtInternal); | |
547 } | |
548 | |
549 { | |
550 // too long file name | |
551 char too_long_name[JVM_MAXPATHLEN + 100]; | |
552 int too_long_length = sizeof(too_long_name); | |
553 memset(too_long_name, 'a', too_long_length); | |
554 too_long_name[too_long_length - 1] = '\0'; | |
555 o_result = make_log_name_internal((const char*)&too_long_name, NULL, pid, tms); | |
556 assert(o_result == NULL, err_msg("Too long file name should return NULL, but got '%s'", o_result)); | |
557 } | |
558 | |
559 { | |
560 // too long with timestamp | |
561 char longest_name[JVM_MAXPATHLEN]; | |
562 memset(longest_name, 'a', JVM_MAXPATHLEN); | |
563 longest_name[JVM_MAXPATHLEN - 3] = '%'; | |
564 longest_name[JVM_MAXPATHLEN - 2] = 't'; | |
565 longest_name[JVM_MAXPATHLEN - 1] = '\0'; | |
566 o_result = make_log_name_internal((const char*)&longest_name, NULL, pid, tms); | |
567 assert(o_result == NULL, err_msg("Too long file name after timestamp expansion should return NULL, but got '%s'", o_result)); | |
568 } | |
569 | |
570 { | |
571 // too long with pid | |
572 char longest_name[JVM_MAXPATHLEN]; | |
573 memset(longest_name, 'a', JVM_MAXPATHLEN); | |
574 longest_name[JVM_MAXPATHLEN - 3] = '%'; | |
575 longest_name[JVM_MAXPATHLEN - 2] = 'p'; | |
576 longest_name[JVM_MAXPATHLEN - 1] = '\0'; | |
577 o_result = make_log_name_internal((const char*)&longest_name, NULL, pid, tms); | |
578 assert(o_result == NULL, err_msg("Too long file name after pid expansion should return NULL, but got '%s'", o_result)); | |
579 } | |
12215 | 580 } |
581 #endif // PRODUCT | |
582 | |
0 | 583 fileStream::fileStream(const char* file_name) { |
584 _file = fopen(file_name, "w"); | |
12215 | 585 if (_file != NULL) { |
586 _need_close = true; | |
587 } else { | |
588 warning("Cannot open file %s due to %s\n", file_name, strerror(errno)); | |
589 _need_close = false; | |
590 } | |
0 | 591 } |
592 | |
2199
d8a72fbc4be7
7003401: Implement VM error-reporting functionality on erroneous termination
kamg
parents:
1980
diff
changeset
|
593 fileStream::fileStream(const char* file_name, const char* opentype) { |
d8a72fbc4be7
7003401: Implement VM error-reporting functionality on erroneous termination
kamg
parents:
1980
diff
changeset
|
594 _file = fopen(file_name, opentype); |
12215 | 595 if (_file != NULL) { |
596 _need_close = true; | |
597 } else { | |
598 warning("Cannot open file %s due to %s\n", file_name, strerror(errno)); | |
599 _need_close = false; | |
600 } | |
2199
d8a72fbc4be7
7003401: Implement VM error-reporting functionality on erroneous termination
kamg
parents:
1980
diff
changeset
|
601 } |
d8a72fbc4be7
7003401: Implement VM error-reporting functionality on erroneous termination
kamg
parents:
1980
diff
changeset
|
602 |
0 | 603 void fileStream::write(const char* s, size_t len) { |
513
2328d1d3f8cf
6781583: Hotspot build fails on linux 64 bit platform with gcc 4.3.2
xlu
parents:
356
diff
changeset
|
604 if (_file != NULL) { |
2328d1d3f8cf
6781583: Hotspot build fails on linux 64 bit platform with gcc 4.3.2
xlu
parents:
356
diff
changeset
|
605 // Make an unused local variable to avoid warning from gcc 4.x compiler. |
2328d1d3f8cf
6781583: Hotspot build fails on linux 64 bit platform with gcc 4.3.2
xlu
parents:
356
diff
changeset
|
606 size_t count = fwrite(s, 1, len, _file); |
2328d1d3f8cf
6781583: Hotspot build fails on linux 64 bit platform with gcc 4.3.2
xlu
parents:
356
diff
changeset
|
607 } |
0 | 608 update_position(s, len); |
609 } | |
610 | |
2199
d8a72fbc4be7
7003401: Implement VM error-reporting functionality on erroneous termination
kamg
parents:
1980
diff
changeset
|
611 long fileStream::fileSize() { |
d8a72fbc4be7
7003401: Implement VM error-reporting functionality on erroneous termination
kamg
parents:
1980
diff
changeset
|
612 long size = -1; |
d8a72fbc4be7
7003401: Implement VM error-reporting functionality on erroneous termination
kamg
parents:
1980
diff
changeset
|
613 if (_file != NULL) { |
d8a72fbc4be7
7003401: Implement VM error-reporting functionality on erroneous termination
kamg
parents:
1980
diff
changeset
|
614 long pos = ::ftell(_file); |
d8a72fbc4be7
7003401: Implement VM error-reporting functionality on erroneous termination
kamg
parents:
1980
diff
changeset
|
615 if (::fseek(_file, 0, SEEK_END) == 0) { |
d8a72fbc4be7
7003401: Implement VM error-reporting functionality on erroneous termination
kamg
parents:
1980
diff
changeset
|
616 size = ::ftell(_file); |
d8a72fbc4be7
7003401: Implement VM error-reporting functionality on erroneous termination
kamg
parents:
1980
diff
changeset
|
617 } |
d8a72fbc4be7
7003401: Implement VM error-reporting functionality on erroneous termination
kamg
parents:
1980
diff
changeset
|
618 ::fseek(_file, pos, SEEK_SET); |
d8a72fbc4be7
7003401: Implement VM error-reporting functionality on erroneous termination
kamg
parents:
1980
diff
changeset
|
619 } |
d8a72fbc4be7
7003401: Implement VM error-reporting functionality on erroneous termination
kamg
parents:
1980
diff
changeset
|
620 return size; |
d8a72fbc4be7
7003401: Implement VM error-reporting functionality on erroneous termination
kamg
parents:
1980
diff
changeset
|
621 } |
d8a72fbc4be7
7003401: Implement VM error-reporting functionality on erroneous termination
kamg
parents:
1980
diff
changeset
|
622 |
d8a72fbc4be7
7003401: Implement VM error-reporting functionality on erroneous termination
kamg
parents:
1980
diff
changeset
|
623 char* fileStream::readln(char *data, int count ) { |
d8a72fbc4be7
7003401: Implement VM error-reporting functionality on erroneous termination
kamg
parents:
1980
diff
changeset
|
624 char * ret = ::fgets(data, count, _file); |
d8a72fbc4be7
7003401: Implement VM error-reporting functionality on erroneous termination
kamg
parents:
1980
diff
changeset
|
625 //Get rid of annoying \n char |
d8a72fbc4be7
7003401: Implement VM error-reporting functionality on erroneous termination
kamg
parents:
1980
diff
changeset
|
626 data[::strlen(data)-1] = '\0'; |
d8a72fbc4be7
7003401: Implement VM error-reporting functionality on erroneous termination
kamg
parents:
1980
diff
changeset
|
627 return ret; |
d8a72fbc4be7
7003401: Implement VM error-reporting functionality on erroneous termination
kamg
parents:
1980
diff
changeset
|
628 } |
d8a72fbc4be7
7003401: Implement VM error-reporting functionality on erroneous termination
kamg
parents:
1980
diff
changeset
|
629 |
0 | 630 fileStream::~fileStream() { |
631 if (_file != NULL) { | |
632 if (_need_close) fclose(_file); | |
3767
2a241e764894
6941923: RFE: Handling large log files produced by long running Java Applications
minqi
parents:
2420
diff
changeset
|
633 _file = NULL; |
0 | 634 } |
635 } | |
636 | |
637 void fileStream::flush() { | |
638 fflush(_file); | |
639 } | |
640 | |
641 fdStream::fdStream(const char* file_name) { | |
642 _fd = open(file_name, O_WRONLY | O_CREAT | O_TRUNC, 0666); | |
643 _need_close = true; | |
644 } | |
645 | |
646 fdStream::~fdStream() { | |
647 if (_fd != -1) { | |
648 if (_need_close) close(_fd); | |
649 _fd = -1; | |
650 } | |
651 } | |
652 | |
653 void fdStream::write(const char* s, size_t len) { | |
513
2328d1d3f8cf
6781583: Hotspot build fails on linux 64 bit platform with gcc 4.3.2
xlu
parents:
356
diff
changeset
|
654 if (_fd != -1) { |
2328d1d3f8cf
6781583: Hotspot build fails on linux 64 bit platform with gcc 4.3.2
xlu
parents:
356
diff
changeset
|
655 // Make an unused local variable to avoid warning from gcc 4.x compiler. |
2328d1d3f8cf
6781583: Hotspot build fails on linux 64 bit platform with gcc 4.3.2
xlu
parents:
356
diff
changeset
|
656 size_t count = ::write(_fd, s, (int)len); |
2328d1d3f8cf
6781583: Hotspot build fails on linux 64 bit platform with gcc 4.3.2
xlu
parents:
356
diff
changeset
|
657 } |
0 | 658 update_position(s, len); |
659 } | |
660 | |
12215 | 661 // dump vm version, os version, platform info, build id, |
662 // memory usage and command line flags into header | |
663 void gcLogFileStream::dump_loggc_header() { | |
664 if (is_open()) { | |
17937
78bbf4d43a14
8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents:
17827
diff
changeset
|
665 print_cr("%s", Abstract_VM_Version::internal_vm_info_string()); |
12215 | 666 os::print_memory_info(this); |
667 print("CommandLine flags: "); | |
668 CommandLineFlags::printSetFlags(this); | |
669 } | |
670 } | |
671 | |
672 gcLogFileStream::~gcLogFileStream() { | |
3767
2a241e764894
6941923: RFE: Handling large log files produced by long running Java Applications
minqi
parents:
2420
diff
changeset
|
673 if (_file != NULL) { |
2a241e764894
6941923: RFE: Handling large log files produced by long running Java Applications
minqi
parents:
2420
diff
changeset
|
674 if (_need_close) fclose(_file); |
12215 | 675 _file = NULL; |
676 } | |
677 if (_file_name != NULL) { | |
6197 | 678 FREE_C_HEAP_ARRAY(char, _file_name, mtInternal); |
3767
2a241e764894
6941923: RFE: Handling large log files produced by long running Java Applications
minqi
parents:
2420
diff
changeset
|
679 _file_name = NULL; |
2a241e764894
6941923: RFE: Handling large log files produced by long running Java Applications
minqi
parents:
2420
diff
changeset
|
680 } |
2a241e764894
6941923: RFE: Handling large log files produced by long running Java Applications
minqi
parents:
2420
diff
changeset
|
681 } |
2a241e764894
6941923: RFE: Handling large log files produced by long running Java Applications
minqi
parents:
2420
diff
changeset
|
682 |
12215 | 683 gcLogFileStream::gcLogFileStream(const char* file_name) { |
3767
2a241e764894
6941923: RFE: Handling large log files produced by long running Java Applications
minqi
parents:
2420
diff
changeset
|
684 _cur_file_num = 0; |
8108
0598674c0056
8008314: Unimplemented() Atomic::load breaks the applications
jwilhelm
parents:
7623
diff
changeset
|
685 _bytes_written = 0L; |
12215 | 686 _file_name = make_log_name(file_name, NULL); |
687 | |
20734 | 688 if (_file_name == NULL) { |
689 warning("Cannot open file %s: file name is too long.\n", file_name); | |
690 _need_close = false; | |
691 UseGCLogFileRotation = false; | |
692 return; | |
693 } | |
694 | |
12215 | 695 // gc log file rotation |
696 if (UseGCLogFileRotation && NumberOfGCLogFiles > 1) { | |
20734 | 697 char tempbuf[JVM_MAXPATHLEN]; |
12215 | 698 jio_snprintf(tempbuf, sizeof(tempbuf), "%s.%d" CURRENTAPPX, _file_name, _cur_file_num); |
699 _file = fopen(tempbuf, "w"); | |
700 } else { | |
701 _file = fopen(_file_name, "w"); | |
702 } | |
703 if (_file != NULL) { | |
704 _need_close = true; | |
705 dump_loggc_header(); | |
706 } else { | |
707 warning("Cannot open file %s due to %s\n", _file_name, strerror(errno)); | |
708 _need_close = false; | |
709 } | |
3767
2a241e764894
6941923: RFE: Handling large log files produced by long running Java Applications
minqi
parents:
2420
diff
changeset
|
710 } |
2a241e764894
6941923: RFE: Handling large log files produced by long running Java Applications
minqi
parents:
2420
diff
changeset
|
711 |
12215 | 712 void gcLogFileStream::write(const char* s, size_t len) { |
8108
0598674c0056
8008314: Unimplemented() Atomic::load breaks the applications
jwilhelm
parents:
7623
diff
changeset
|
713 if (_file != NULL) { |
3767
2a241e764894
6941923: RFE: Handling large log files produced by long running Java Applications
minqi
parents:
2420
diff
changeset
|
714 size_t count = fwrite(s, 1, len, _file); |
8108
0598674c0056
8008314: Unimplemented() Atomic::load breaks the applications
jwilhelm
parents:
7623
diff
changeset
|
715 _bytes_written += count; |
3767
2a241e764894
6941923: RFE: Handling large log files produced by long running Java Applications
minqi
parents:
2420
diff
changeset
|
716 } |
2a241e764894
6941923: RFE: Handling large log files produced by long running Java Applications
minqi
parents:
2420
diff
changeset
|
717 update_position(s, len); |
2a241e764894
6941923: RFE: Handling large log files produced by long running Java Applications
minqi
parents:
2420
diff
changeset
|
718 } |
2a241e764894
6941923: RFE: Handling large log files produced by long running Java Applications
minqi
parents:
2420
diff
changeset
|
719 |
2a241e764894
6941923: RFE: Handling large log files produced by long running Java Applications
minqi
parents:
2420
diff
changeset
|
720 // rotate_log must be called from VMThread at safepoint. In case need change parameters |
2a241e764894
6941923: RFE: Handling large log files produced by long running Java Applications
minqi
parents:
2420
diff
changeset
|
721 // for gc log rotation from thread other than VMThread, a sub type of VM_Operation |
2a241e764894
6941923: RFE: Handling large log files produced by long running Java Applications
minqi
parents:
2420
diff
changeset
|
722 // should be created and be submitted to VMThread's operation queue. DO NOT call this |
2a241e764894
6941923: RFE: Handling large log files produced by long running Java Applications
minqi
parents:
2420
diff
changeset
|
723 // function directly. Currently, it is safe to rotate log at safepoint through VMThread. |
2a241e764894
6941923: RFE: Handling large log files produced by long running Java Applications
minqi
parents:
2420
diff
changeset
|
724 // That is, no mutator threads and concurrent GC threads run parallel with VMThread to |
2a241e764894
6941923: RFE: Handling large log files produced by long running Java Applications
minqi
parents:
2420
diff
changeset
|
725 // write to gc log file at safepoint. If in future, changes made for mutator threads or |
2a241e764894
6941923: RFE: Handling large log files produced by long running Java Applications
minqi
parents:
2420
diff
changeset
|
726 // concurrent GC threads to run parallel with VMThread at safepoint, write and rotate_log |
2a241e764894
6941923: RFE: Handling large log files produced by long running Java Applications
minqi
parents:
2420
diff
changeset
|
727 // must be synchronized. |
17827 | 728 void gcLogFileStream::rotate_log(bool force, outputStream* out) { |
20734 | 729 char time_msg[O_BUFLEN]; |
12215 | 730 char time_str[EXTRACHARLEN]; |
20734 | 731 char current_file_name[JVM_MAXPATHLEN]; |
732 char renamed_file_name[JVM_MAXPATHLEN]; | |
12215 | 733 |
17827 | 734 if (!should_rotate(force)) { |
8108
0598674c0056
8008314: Unimplemented() Atomic::load breaks the applications
jwilhelm
parents:
7623
diff
changeset
|
735 return; |
0598674c0056
8008314: Unimplemented() Atomic::load breaks the applications
jwilhelm
parents:
7623
diff
changeset
|
736 } |
0598674c0056
8008314: Unimplemented() Atomic::load breaks the applications
jwilhelm
parents:
7623
diff
changeset
|
737 |
3767
2a241e764894
6941923: RFE: Handling large log files produced by long running Java Applications
minqi
parents:
2420
diff
changeset
|
738 #ifdef ASSERT |
2a241e764894
6941923: RFE: Handling large log files produced by long running Java Applications
minqi
parents:
2420
diff
changeset
|
739 Thread *thread = Thread::current(); |
2a241e764894
6941923: RFE: Handling large log files produced by long running Java Applications
minqi
parents:
2420
diff
changeset
|
740 assert(thread == NULL || |
2a241e764894
6941923: RFE: Handling large log files produced by long running Java Applications
minqi
parents:
2420
diff
changeset
|
741 (thread->is_VM_thread() && SafepointSynchronize::is_at_safepoint()), |
2a241e764894
6941923: RFE: Handling large log files produced by long running Java Applications
minqi
parents:
2420
diff
changeset
|
742 "Must be VMThread at safepoint"); |
2a241e764894
6941923: RFE: Handling large log files produced by long running Java Applications
minqi
parents:
2420
diff
changeset
|
743 #endif |
2a241e764894
6941923: RFE: Handling large log files produced by long running Java Applications
minqi
parents:
2420
diff
changeset
|
744 if (NumberOfGCLogFiles == 1) { |
2a241e764894
6941923: RFE: Handling large log files produced by long running Java Applications
minqi
parents:
2420
diff
changeset
|
745 // rotate in same file |
2a241e764894
6941923: RFE: Handling large log files produced by long running Java Applications
minqi
parents:
2420
diff
changeset
|
746 rewind(); |
8108
0598674c0056
8008314: Unimplemented() Atomic::load breaks the applications
jwilhelm
parents:
7623
diff
changeset
|
747 _bytes_written = 0L; |
12215 | 748 jio_snprintf(time_msg, sizeof(time_msg), "File %s rotated at %s\n", |
749 _file_name, os::local_time_string((char *)time_str, sizeof(time_str))); | |
750 write(time_msg, strlen(time_msg)); | |
17827 | 751 |
752 if (out != NULL) { | |
17937
78bbf4d43a14
8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents:
17827
diff
changeset
|
753 out->print("%s", time_msg); |
17827 | 754 } |
755 | |
12215 | 756 dump_loggc_header(); |
3767
2a241e764894
6941923: RFE: Handling large log files produced by long running Java Applications
minqi
parents:
2420
diff
changeset
|
757 return; |
2a241e764894
6941923: RFE: Handling large log files produced by long running Java Applications
minqi
parents:
2420
diff
changeset
|
758 } |
2a241e764894
6941923: RFE: Handling large log files produced by long running Java Applications
minqi
parents:
2420
diff
changeset
|
759 |
12215 | 760 #if defined(_WINDOWS) |
761 #ifndef F_OK | |
762 #define F_OK 0 | |
763 #endif | |
764 #endif // _WINDOWS | |
765 | |
766 // rotate file in names extended_filename.0, extended_filename.1, ..., | |
767 // extended_filename.<NumberOfGCLogFiles - 1>. Current rotation file name will | |
768 // have a form of extended_filename.<i>.current where i is the current rotation | |
769 // file number. After it reaches max file size, the file will be saved and renamed | |
770 // with .current removed from its tail. | |
3767
2a241e764894
6941923: RFE: Handling large log files produced by long running Java Applications
minqi
parents:
2420
diff
changeset
|
771 if (_file != NULL) { |
20734 | 772 jio_snprintf(renamed_file_name, JVM_MAXPATHLEN, "%s.%d", |
12215 | 773 _file_name, _cur_file_num); |
20734 | 774 int result = jio_snprintf(current_file_name, JVM_MAXPATHLEN, |
775 "%s.%d" CURRENTAPPX, _file_name, _cur_file_num); | |
776 if (result >= JVM_MAXPATHLEN) { | |
777 warning("Cannot create new log file name: %s: file name is too long.\n", current_file_name); | |
778 return; | |
779 } | |
17827 | 780 |
781 const char* msg = force ? "GC log rotation request has been received." | |
782 : "GC log file has reached the maximum size."; | |
783 jio_snprintf(time_msg, sizeof(time_msg), "%s %s Saved as %s\n", | |
784 os::local_time_string((char *)time_str, sizeof(time_str)), | |
785 msg, renamed_file_name); | |
12215 | 786 write(time_msg, strlen(time_msg)); |
787 | |
17827 | 788 if (out != NULL) { |
17937
78bbf4d43a14
8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents:
17827
diff
changeset
|
789 out->print("%s", time_msg); |
17827 | 790 } |
791 | |
3767
2a241e764894
6941923: RFE: Handling large log files produced by long running Java Applications
minqi
parents:
2420
diff
changeset
|
792 fclose(_file); |
2a241e764894
6941923: RFE: Handling large log files produced by long running Java Applications
minqi
parents:
2420
diff
changeset
|
793 _file = NULL; |
12215 | 794 |
795 bool can_rename = true; | |
796 if (access(current_file_name, F_OK) != 0) { | |
797 // current file does not exist? | |
798 warning("No source file exists, cannot rename\n"); | |
799 can_rename = false; | |
800 } | |
801 if (can_rename) { | |
802 if (access(renamed_file_name, F_OK) == 0) { | |
803 if (remove(renamed_file_name) != 0) { | |
804 warning("Could not delete existing file %s\n", renamed_file_name); | |
805 can_rename = false; | |
806 } | |
807 } else { | |
808 // file does not exist, ok to rename | |
809 } | |
810 } | |
811 if (can_rename && rename(current_file_name, renamed_file_name) != 0) { | |
812 warning("Could not rename %s to %s\n", _file_name, renamed_file_name); | |
813 } | |
3767
2a241e764894
6941923: RFE: Handling large log files produced by long running Java Applications
minqi
parents:
2420
diff
changeset
|
814 } |
12215 | 815 |
816 _cur_file_num++; | |
817 if (_cur_file_num > NumberOfGCLogFiles - 1) _cur_file_num = 0; | |
20734 | 818 int result = jio_snprintf(current_file_name, JVM_MAXPATHLEN, "%s.%d" CURRENTAPPX, |
12215 | 819 _file_name, _cur_file_num); |
20734 | 820 if (result >= JVM_MAXPATHLEN) { |
821 warning("Cannot create new log file name: %s: file name is too long.\n", current_file_name); | |
822 return; | |
823 } | |
824 | |
12215 | 825 _file = fopen(current_file_name, "w"); |
826 | |
3767
2a241e764894
6941923: RFE: Handling large log files produced by long running Java Applications
minqi
parents:
2420
diff
changeset
|
827 if (_file != NULL) { |
8108
0598674c0056
8008314: Unimplemented() Atomic::load breaks the applications
jwilhelm
parents:
7623
diff
changeset
|
828 _bytes_written = 0L; |
3767
2a241e764894
6941923: RFE: Handling large log files produced by long running Java Applications
minqi
parents:
2420
diff
changeset
|
829 _need_close = true; |
12215 | 830 // reuse current_file_name for time_msg |
20734 | 831 jio_snprintf(current_file_name, JVM_MAXPATHLEN, |
12215 | 832 "%s.%d", _file_name, _cur_file_num); |
833 jio_snprintf(time_msg, sizeof(time_msg), "%s GC log file created %s\n", | |
20734 | 834 os::local_time_string((char *)time_str, sizeof(time_str)), current_file_name); |
12215 | 835 write(time_msg, strlen(time_msg)); |
17827 | 836 |
837 if (out != NULL) { | |
17937
78bbf4d43a14
8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents:
17827
diff
changeset
|
838 out->print("%s", time_msg); |
17827 | 839 } |
840 | |
12215 | 841 dump_loggc_header(); |
842 // remove the existing file | |
843 if (access(current_file_name, F_OK) == 0) { | |
844 if (remove(current_file_name) != 0) { | |
845 warning("Could not delete existing file %s\n", current_file_name); | |
846 } | |
847 } | |
3767
2a241e764894
6941923: RFE: Handling large log files produced by long running Java Applications
minqi
parents:
2420
diff
changeset
|
848 } else { |
12215 | 849 warning("failed to open rotation log file %s due to %s\n" |
850 "Turned off GC log file rotation\n", | |
3767
2a241e764894
6941923: RFE: Handling large log files produced by long running Java Applications
minqi
parents:
2420
diff
changeset
|
851 _file_name, strerror(errno)); |
2a241e764894
6941923: RFE: Handling large log files produced by long running Java Applications
minqi
parents:
2420
diff
changeset
|
852 _need_close = false; |
12215 | 853 FLAG_SET_DEFAULT(UseGCLogFileRotation, false); |
3767
2a241e764894
6941923: RFE: Handling large log files produced by long running Java Applications
minqi
parents:
2420
diff
changeset
|
854 } |
2a241e764894
6941923: RFE: Handling large log files produced by long running Java Applications
minqi
parents:
2420
diff
changeset
|
855 } |
2a241e764894
6941923: RFE: Handling large log files produced by long running Java Applications
minqi
parents:
2420
diff
changeset
|
856 |
0 | 857 defaultStream* defaultStream::instance = NULL; |
858 int defaultStream::_output_fd = 1; | |
859 int defaultStream::_error_fd = 2; | |
860 FILE* defaultStream::_output_stream = stdout; | |
861 FILE* defaultStream::_error_stream = stderr; | |
862 | |
863 #define LOG_MAJOR_VERSION 160 | |
864 #define LOG_MINOR_VERSION 1 | |
865 | |
866 void defaultStream::init() { | |
867 _inited = true; | |
868 if (LogVMOutput || LogCompilation) { | |
869 init_log(); | |
870 } | |
871 } | |
872 | |
873 bool defaultStream::has_log_file() { | |
874 // lazily create log file (at startup, LogVMOutput is false even | |
875 // if +LogVMOutput is used, because the flags haven't been parsed yet) | |
876 // For safer printing during fatal error handling, do not init logfile | |
877 // if a VM error has been reported. | |
878 if (!_inited && !is_error_reported()) init(); | |
879 return _log_file != NULL; | |
880 } | |
881 | |
20734 | 882 fileStream* defaultStream::open_file(const char* log_name) { |
883 const char* try_name = make_log_name(log_name, NULL); | |
884 if (try_name == NULL) { | |
885 warning("Cannot open file %s: file name is too long.\n", log_name); | |
886 return NULL; | |
887 } | |
888 | |
889 fileStream* file = new(ResourceObj::C_HEAP, mtInternal) fileStream(try_name); | |
890 FREE_C_HEAP_ARRAY(char, try_name, mtInternal); | |
891 if (file->is_open()) { | |
892 return file; | |
893 } | |
894 | |
895 // Try again to open the file in the temp directory. | |
896 delete file; | |
897 char warnbuf[O_BUFLEN*2]; | |
898 jio_snprintf(warnbuf, sizeof(warnbuf), "Warning: Cannot open log file: %s\n", log_name); | |
899 // Note: This feature is for maintainer use only. No need for L10N. | |
900 jio_print(warnbuf); | |
901 try_name = make_log_name(log_name, os::get_temp_directory()); | |
902 if (try_name == NULL) { | |
903 warning("Cannot open file %s: file name is too long for directory %s.\n", log_name, os::get_temp_directory()); | |
904 return NULL; | |
905 } | |
906 | |
907 jio_snprintf(warnbuf, sizeof(warnbuf), | |
908 "Warning: Forcing option -XX:LogFile=%s\n", try_name); | |
909 jio_print(warnbuf); | |
910 | |
911 file = new(ResourceObj::C_HEAP, mtInternal) fileStream(try_name); | |
912 FREE_C_HEAP_ARRAY(char, try_name, mtInternal); | |
913 if (file->is_open()) { | |
914 return file; | |
915 } | |
916 | |
917 delete file; | |
918 return NULL; | |
919 } | |
920 | |
0 | 921 void defaultStream::init_log() { |
922 // %%% Need a MutexLocker? | |
12864
bf8a21c3ab3b
8025849: Redundant "pid" in VM log file name (e.g. hotspot_pidpid12345.log)
vlivanov
parents:
12269
diff
changeset
|
923 const char* log_name = LogFile != NULL ? LogFile : "hotspot_%p.log"; |
20734 | 924 fileStream* file = open_file(log_name); |
925 | |
926 if (file != NULL) { | |
927 _log_file = file; | |
928 _outer_xmlStream = new(ResourceObj::C_HEAP, mtInternal) xmlStream(file); | |
929 start_log(); | |
930 } else { | |
931 // and leave xtty as NULL | |
932 LogVMOutput = false; | |
933 DisplayVMOutput = true; | |
934 LogCompilation = false; | |
0 | 935 } |
20734 | 936 } |
12257
01b268b3080a
8023134: Rename VM LogFile to hotspot_pid{pid}.log (was hotspot.log)
vlivanov
parents:
11136
diff
changeset
|
937 |
20734 | 938 void defaultStream::start_log() { |
939 xmlStream*xs = _outer_xmlStream; | |
0 | 940 if (this == tty) xtty = xs; |
941 // Write XML header. | |
942 xs->print_cr("<?xml version='1.0' encoding='UTF-8'?>"); | |
943 // (For now, don't bother to issue a DTD for this private format.) | |
944 jlong time_ms = os::javaTimeMillis() - tty->time_stamp().milliseconds(); | |
945 // %%% Should be: jlong time_ms = os::start_time_milliseconds(), if | |
946 // we ever get round to introduce that method on the os class | |
947 xs->head("hotspot_log version='%d %d'" | |
948 " process='%d' time_ms='"INT64_FORMAT"'", | |
949 LOG_MAJOR_VERSION, LOG_MINOR_VERSION, | |
17937
78bbf4d43a14
8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents:
17827
diff
changeset
|
950 os::current_process_id(), (int64_t)time_ms); |
0 | 951 // Write VM version header immediately. |
952 xs->head("vm_version"); | |
953 xs->head("name"); xs->text("%s", VM_Version::vm_name()); xs->cr(); | |
954 xs->tail("name"); | |
955 xs->head("release"); xs->text("%s", VM_Version::vm_release()); xs->cr(); | |
956 xs->tail("release"); | |
957 xs->head("info"); xs->text("%s", VM_Version::internal_vm_info_string()); xs->cr(); | |
958 xs->tail("info"); | |
959 xs->tail("vm_version"); | |
960 // Record information about the command-line invocation. | |
961 xs->head("vm_arguments"); // Cf. Arguments::print_on() | |
962 if (Arguments::num_jvm_flags() > 0) { | |
963 xs->head("flags"); | |
964 Arguments::print_jvm_flags_on(xs->text()); | |
965 xs->tail("flags"); | |
966 } | |
967 if (Arguments::num_jvm_args() > 0) { | |
968 xs->head("args"); | |
969 Arguments::print_jvm_args_on(xs->text()); | |
970 xs->tail("args"); | |
971 } | |
972 if (Arguments::java_command() != NULL) { | |
973 xs->head("command"); xs->text()->print_cr("%s", Arguments::java_command()); | |
974 xs->tail("command"); | |
975 } | |
976 if (Arguments::sun_java_launcher() != NULL) { | |
977 xs->head("launcher"); xs->text()->print_cr("%s", Arguments::sun_java_launcher()); | |
978 xs->tail("launcher"); | |
979 } | |
980 if (Arguments::system_properties() != NULL) { | |
981 xs->head("properties"); | |
982 // Print it as a java-style property list. | |
983 // System properties don't generally contain newlines, so don't bother with unparsing. | |
984 for (SystemProperty* p = Arguments::system_properties(); p != NULL; p = p->next()) { | |
985 xs->text()->print_cr("%s=%s", p->key(), p->value()); | |
986 } | |
987 xs->tail("properties"); | |
988 } | |
989 xs->tail("vm_arguments"); | |
990 // tty output per se is grouped under the <tty>...</tty> element. | |
991 xs->head("tty"); | |
992 // All further non-markup text gets copied to the tty: | |
993 xs->_text = this; // requires friend declaration! | |
994 } | |
995 | |
996 // finish_log() is called during normal VM shutdown. finish_log_on_error() is | |
997 // called by ostream_abort() after a fatal error. | |
998 // | |
999 void defaultStream::finish_log() { | |
1000 xmlStream* xs = _outer_xmlStream; | |
1001 xs->done("tty"); | |
1002 | |
1003 // Other log forks are appended here, at the End of Time: | |
1004 CompileLog::finish_log(xs->out()); // write compile logging, if any, now | |
1005 | |
1006 xs->done("hotspot_log"); | |
1007 xs->flush(); | |
1008 | |
1009 fileStream* file = _log_file; | |
1010 _log_file = NULL; | |
1011 | |
1012 delete _outer_xmlStream; | |
1013 _outer_xmlStream = NULL; | |
1014 | |
1015 file->flush(); | |
1016 delete file; | |
1017 } | |
1018 | |
1019 void defaultStream::finish_log_on_error(char *buf, int buflen) { | |
1020 xmlStream* xs = _outer_xmlStream; | |
1021 | |
1022 if (xs && xs->out()) { | |
1023 | |
1024 xs->done_raw("tty"); | |
1025 | |
1026 // Other log forks are appended here, at the End of Time: | |
1027 CompileLog::finish_log_on_error(xs->out(), buf, buflen); // write compile logging, if any, now | |
1028 | |
1029 xs->done_raw("hotspot_log"); | |
1030 xs->flush(); | |
1031 | |
1032 fileStream* file = _log_file; | |
1033 _log_file = NULL; | |
1034 _outer_xmlStream = NULL; | |
1035 | |
1036 if (file) { | |
1037 file->flush(); | |
1038 | |
1039 // Can't delete or close the file because delete and fclose aren't | |
1040 // async-safe. We are about to die, so leave it to the kernel. | |
1041 // delete file; | |
1042 } | |
1043 } | |
1044 } | |
1045 | |
1046 intx defaultStream::hold(intx writer_id) { | |
1047 bool has_log = has_log_file(); // check before locking | |
1048 if (// impossible, but who knows? | |
1049 writer_id == NO_WRITER || | |
1050 | |
1051 // bootstrap problem | |
1052 tty_lock == NULL || | |
1053 | |
1054 // can't grab a lock or call Thread::current() if TLS isn't initialized | |
1055 ThreadLocalStorage::thread() == NULL || | |
1056 | |
1057 // developer hook | |
1058 !SerializeVMOutput || | |
1059 | |
1060 // VM already unhealthy | |
1061 is_error_reported() || | |
1062 | |
1063 // safepoint == global lock (for VM only) | |
1064 (SafepointSynchronize::is_synchronizing() && | |
1065 Thread::current()->is_VM_thread()) | |
1066 ) { | |
1067 // do not attempt to lock unless we know the thread and the VM is healthy | |
1068 return NO_WRITER; | |
1069 } | |
1070 if (_writer == writer_id) { | |
1071 // already held, no need to re-grab the lock | |
1072 return NO_WRITER; | |
1073 } | |
1074 tty_lock->lock_without_safepoint_check(); | |
1075 // got the lock | |
1076 if (writer_id != _last_writer) { | |
1077 if (has_log) { | |
1078 _log_file->bol(); | |
1079 // output a hint where this output is coming from: | |
6843 | 1080 _log_file->print_cr("<writer thread='" UINTX_FORMAT "'/>", writer_id); |
0 | 1081 } |
1082 _last_writer = writer_id; | |
1083 } | |
1084 _writer = writer_id; | |
1085 return writer_id; | |
1086 } | |
1087 | |
1088 void defaultStream::release(intx holder) { | |
1089 if (holder == NO_WRITER) { | |
1090 // nothing to release: either a recursive lock, or we scribbled (too bad) | |
1091 return; | |
1092 } | |
1093 if (_writer != holder) { | |
1094 return; // already unlocked, perhaps via break_tty_lock_for_safepoint | |
1095 } | |
1096 _writer = NO_WRITER; | |
1097 tty_lock->unlock(); | |
1098 } | |
1099 | |
1100 | |
1101 // Yuck: jio_print does not accept char*/len. | |
1102 static void call_jio_print(const char* s, size_t len) { | |
1103 char buffer[O_BUFLEN+100]; | |
1104 if (len > sizeof(buffer)-1) { | |
1105 warning("increase O_BUFLEN in ostream.cpp -- output truncated"); | |
1106 len = sizeof(buffer)-1; | |
1107 } | |
1108 strncpy(buffer, s, len); | |
1109 buffer[len] = '\0'; | |
1110 jio_print(buffer); | |
1111 } | |
1112 | |
1113 | |
1114 void defaultStream::write(const char* s, size_t len) { | |
1115 intx thread_id = os::current_thread_id(); | |
1116 intx holder = hold(thread_id); | |
1117 | |
1118 if (DisplayVMOutput && | |
1119 (_outer_xmlStream == NULL || !_outer_xmlStream->inside_attrs())) { | |
1120 // print to output stream. It can be redirected by a vfprintf hook | |
1121 if (s[len] == '\0') { | |
1122 jio_print(s); | |
1123 } else { | |
1124 call_jio_print(s, len); | |
1125 } | |
1126 } | |
1127 | |
1128 // print to log file | |
1129 if (has_log_file()) { | |
1130 int nl0 = _newlines; | |
1131 xmlTextStream::write(s, len); | |
1132 // flush the log file too, if there were any newlines | |
1133 if (nl0 != _newlines){ | |
1134 flush(); | |
1135 } | |
1136 } else { | |
1137 update_position(s, len); | |
1138 } | |
1139 | |
1140 release(holder); | |
1141 } | |
1142 | |
1143 intx ttyLocker::hold_tty() { | |
1144 if (defaultStream::instance == NULL) return defaultStream::NO_WRITER; | |
1145 intx thread_id = os::current_thread_id(); | |
1146 return defaultStream::instance->hold(thread_id); | |
1147 } | |
1148 | |
1149 void ttyLocker::release_tty(intx holder) { | |
1150 if (holder == defaultStream::NO_WRITER) return; | |
1151 defaultStream::instance->release(holder); | |
1152 } | |
1153 | |
2263
5841dc1964f0
7021531: lock ordering problems after fix for 6354181
never
parents:
2199
diff
changeset
|
1154 bool ttyLocker::release_tty_if_locked() { |
5841dc1964f0
7021531: lock ordering problems after fix for 6354181
never
parents:
2199
diff
changeset
|
1155 intx thread_id = os::current_thread_id(); |
5841dc1964f0
7021531: lock ordering problems after fix for 6354181
never
parents:
2199
diff
changeset
|
1156 if (defaultStream::instance->writer() == thread_id) { |
5841dc1964f0
7021531: lock ordering problems after fix for 6354181
never
parents:
2199
diff
changeset
|
1157 // release the lock and return true so callers know if was |
5841dc1964f0
7021531: lock ordering problems after fix for 6354181
never
parents:
2199
diff
changeset
|
1158 // previously held. |
5841dc1964f0
7021531: lock ordering problems after fix for 6354181
never
parents:
2199
diff
changeset
|
1159 release_tty(thread_id); |
5841dc1964f0
7021531: lock ordering problems after fix for 6354181
never
parents:
2199
diff
changeset
|
1160 return true; |
5841dc1964f0
7021531: lock ordering problems after fix for 6354181
never
parents:
2199
diff
changeset
|
1161 } |
5841dc1964f0
7021531: lock ordering problems after fix for 6354181
never
parents:
2199
diff
changeset
|
1162 return false; |
5841dc1964f0
7021531: lock ordering problems after fix for 6354181
never
parents:
2199
diff
changeset
|
1163 } |
5841dc1964f0
7021531: lock ordering problems after fix for 6354181
never
parents:
2199
diff
changeset
|
1164 |
0 | 1165 void ttyLocker::break_tty_lock_for_safepoint(intx holder) { |
1166 if (defaultStream::instance != NULL && | |
1167 defaultStream::instance->writer() == holder) { | |
1168 if (xtty != NULL) { | |
1169 xtty->print_cr("<!-- safepoint while printing -->"); | |
1170 } | |
1171 defaultStream::instance->release(holder); | |
1172 } | |
1173 // (else there was no lock to break) | |
1174 } | |
1175 | |
1176 void ostream_init() { | |
1177 if (defaultStream::instance == NULL) { | |
6197 | 1178 defaultStream::instance = new(ResourceObj::C_HEAP, mtInternal) defaultStream(); |
0 | 1179 tty = defaultStream::instance; |
1180 | |
1181 // We want to ensure that time stamps in GC logs consider time 0 | |
1182 // the time when the JVM is initialized, not the first time we ask | |
1183 // for a time stamp. So, here, we explicitly update the time stamp | |
1184 // of tty. | |
1185 tty->time_stamp().update_to(1); | |
1186 } | |
1187 } | |
1188 | |
1189 void ostream_init_log() { | |
1190 // For -Xloggc:<file> option - called in runtime/thread.cpp | |
1191 // Note : this must be called AFTER ostream_init() | |
1192 | |
1193 gclog_or_tty = tty; // default to tty | |
1194 if (Arguments::gc_log_filename() != NULL) { | |
12215 | 1195 fileStream * gclog = new(ResourceObj::C_HEAP, mtInternal) |
1196 gcLogFileStream(Arguments::gc_log_filename()); | |
0 | 1197 if (gclog->is_open()) { |
1198 // now we update the time stamp of the GC log to be synced up | |
1199 // with tty. | |
1200 gclog->time_stamp().update_to(tty->time_stamp().ticks()); | |
1201 } | |
3767
2a241e764894
6941923: RFE: Handling large log files produced by long running Java Applications
minqi
parents:
2420
diff
changeset
|
1202 gclog_or_tty = gclog; |
0 | 1203 } |
1204 | |
20375
6e0cb14ce59b
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
20190
diff
changeset
|
1205 #if INCLUDE_CDS |
6e0cb14ce59b
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
20190
diff
changeset
|
1206 // For -XX:DumpLoadedClassList=<file> option |
6e0cb14ce59b
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
20190
diff
changeset
|
1207 if (DumpLoadedClassList != NULL) { |
6e0cb14ce59b
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
20190
diff
changeset
|
1208 const char* list_name = make_log_name(DumpLoadedClassList, NULL); |
6e0cb14ce59b
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
20190
diff
changeset
|
1209 classlist_file = new(ResourceObj::C_HEAP, mtInternal) |
6e0cb14ce59b
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
20190
diff
changeset
|
1210 fileStream(list_name); |
6e0cb14ce59b
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
20190
diff
changeset
|
1211 FREE_C_HEAP_ARRAY(char, list_name, mtInternal); |
6e0cb14ce59b
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
20190
diff
changeset
|
1212 } |
6e0cb14ce59b
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
20190
diff
changeset
|
1213 #endif |
6e0cb14ce59b
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
20190
diff
changeset
|
1214 |
0 | 1215 // If we haven't lazily initialized the logfile yet, do it now, |
1216 // to avoid the possibility of lazy initialization during a VM | |
1217 // crash, which can affect the stability of the fatal error handler. | |
1218 defaultStream::instance->has_log_file(); | |
1219 } | |
1220 | |
1221 // ostream_exit() is called during normal VM exit to finish log files, flush | |
1222 // output and free resource. | |
1223 void ostream_exit() { | |
1224 static bool ostream_exit_called = false; | |
1225 if (ostream_exit_called) return; | |
1226 ostream_exit_called = true; | |
20375
6e0cb14ce59b
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
20190
diff
changeset
|
1227 #if INCLUDE_CDS |
6e0cb14ce59b
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
20190
diff
changeset
|
1228 if (classlist_file != NULL) { |
6e0cb14ce59b
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
20190
diff
changeset
|
1229 delete classlist_file; |
6e0cb14ce59b
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
20190
diff
changeset
|
1230 } |
6e0cb14ce59b
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
20190
diff
changeset
|
1231 #endif |
0 | 1232 if (gclog_or_tty != tty) { |
1233 delete gclog_or_tty; | |
1234 } | |
1235 { | |
1236 // we temporaly disable PrintMallocFree here | |
1237 // as otherwise it'll lead to using of almost deleted | |
1238 // tty or defaultStream::instance in logging facility | |
1239 // of HeapFree(), see 6391258 | |
1240 DEBUG_ONLY(FlagSetting fs(PrintMallocFree, false);) | |
1241 if (tty != defaultStream::instance) { | |
1242 delete tty; | |
1243 } | |
1244 if (defaultStream::instance != NULL) { | |
1245 delete defaultStream::instance; | |
1246 } | |
1247 } | |
1248 tty = NULL; | |
1249 xtty = NULL; | |
1250 gclog_or_tty = NULL; | |
1251 defaultStream::instance = NULL; | |
1252 } | |
1253 | |
1254 // ostream_abort() is called by os::abort() when VM is about to die. | |
1255 void ostream_abort() { | |
1256 // Here we can't delete gclog_or_tty and tty, just flush their output | |
1257 if (gclog_or_tty) gclog_or_tty->flush(); | |
1258 if (tty) tty->flush(); | |
1259 | |
1260 if (defaultStream::instance != NULL) { | |
1261 static char buf[4096]; | |
1262 defaultStream::instance->finish_log_on_error(buf, sizeof(buf)); | |
1263 } | |
1264 } | |
1265 | |
1266 staticBufferStream::staticBufferStream(char* buffer, size_t buflen, | |
1267 outputStream *outer_stream) { | |
1268 _buffer = buffer; | |
1269 _buflen = buflen; | |
1270 _outer_stream = outer_stream; | |
2420
8010c8c623ac
7032849: 7022998 changes broke hs_err compile task print
kvn
parents:
2400
diff
changeset
|
1271 // compile task prints time stamp relative to VM start |
8010c8c623ac
7032849: 7022998 changes broke hs_err compile task print
kvn
parents:
2400
diff
changeset
|
1272 _stamp.update_to(1); |
0 | 1273 } |
1274 | |
1275 void staticBufferStream::write(const char* c, size_t len) { | |
1276 _outer_stream->print_raw(c, (int)len); | |
1277 } | |
1278 | |
1279 void staticBufferStream::flush() { | |
1280 _outer_stream->flush(); | |
1281 } | |
1282 | |
1283 void staticBufferStream::print(const char* format, ...) { | |
1284 va_list ap; | |
1285 va_start(ap, format); | |
1286 size_t len; | |
1287 const char* str = do_vsnprintf(_buffer, _buflen, format, ap, false, len); | |
1288 write(str, len); | |
1289 va_end(ap); | |
1290 } | |
1291 | |
1292 void staticBufferStream::print_cr(const char* format, ...) { | |
1293 va_list ap; | |
1294 va_start(ap, format); | |
1295 size_t len; | |
1296 const char* str = do_vsnprintf(_buffer, _buflen, format, ap, true, len); | |
1297 write(str, len); | |
1298 va_end(ap); | |
1299 } | |
1300 | |
1301 void staticBufferStream::vprint(const char *format, va_list argptr) { | |
1302 size_t len; | |
1303 const char* str = do_vsnprintf(_buffer, _buflen, format, argptr, false, len); | |
1304 write(str, len); | |
1305 } | |
1306 | |
1307 void staticBufferStream::vprint_cr(const char* format, va_list argptr) { | |
1308 size_t len; | |
1309 const char* str = do_vsnprintf(_buffer, _buflen, format, argptr, true, len); | |
1310 write(str, len); | |
1311 } | |
1312 | |
222 | 1313 bufferedStream::bufferedStream(size_t initial_size, size_t bufmax) : outputStream() { |
0 | 1314 buffer_length = initial_size; |
6197 | 1315 buffer = NEW_C_HEAP_ARRAY(char, buffer_length, mtInternal); |
0 | 1316 buffer_pos = 0; |
1317 buffer_fixed = false; | |
222 | 1318 buffer_max = bufmax; |
0 | 1319 } |
1320 | |
222 | 1321 bufferedStream::bufferedStream(char* fixed_buffer, size_t fixed_buffer_size, size_t bufmax) : outputStream() { |
0 | 1322 buffer_length = fixed_buffer_size; |
1323 buffer = fixed_buffer; | |
1324 buffer_pos = 0; | |
1325 buffer_fixed = true; | |
222 | 1326 buffer_max = bufmax; |
0 | 1327 } |
1328 | |
1329 void bufferedStream::write(const char* s, size_t len) { | |
222 | 1330 |
1331 if(buffer_pos + len > buffer_max) { | |
1332 flush(); | |
1333 } | |
1334 | |
0 | 1335 size_t end = buffer_pos + len; |
1336 if (end >= buffer_length) { | |
1337 if (buffer_fixed) { | |
1338 // if buffer cannot resize, silently truncate | |
1339 len = buffer_length - buffer_pos - 1; | |
1340 } else { | |
1341 // For small overruns, double the buffer. For larger ones, | |
1342 // increase to the requested size. | |
1343 if (end < buffer_length * 2) { | |
1344 end = buffer_length * 2; | |
1345 } | |
6197 | 1346 buffer = REALLOC_C_HEAP_ARRAY(char, buffer, end, mtInternal); |
0 | 1347 buffer_length = end; |
1348 } | |
1349 } | |
1350 memcpy(buffer + buffer_pos, s, len); | |
1351 buffer_pos += len; | |
1352 update_position(s, len); | |
1353 } | |
1354 | |
1355 char* bufferedStream::as_string() { | |
1356 char* copy = NEW_RESOURCE_ARRAY(char, buffer_pos+1); | |
1357 strncpy(copy, buffer, buffer_pos); | |
1358 copy[buffer_pos] = 0; // terminating null | |
1359 return copy; | |
1360 } | |
1361 | |
1362 bufferedStream::~bufferedStream() { | |
1363 if (!buffer_fixed) { | |
6197 | 1364 FREE_C_HEAP_ARRAY(char, buffer, mtInternal); |
0 | 1365 } |
1366 } | |
1367 | |
1368 #ifndef PRODUCT | |
1369 | |
14411 | 1370 #if defined(SOLARIS) || defined(LINUX) || defined(AIX) || defined(_ALLBSD_SOURCE) |
0 | 1371 #include <sys/types.h> |
1372 #include <sys/socket.h> | |
1373 #include <netinet/in.h> | |
1374 #include <arpa/inet.h> | |
1375 #endif | |
1376 | |
1377 // Network access | |
222 | 1378 networkStream::networkStream() : bufferedStream(1024*10, 1024*10) { |
0 | 1379 |
1380 _socket = -1; | |
1381 | |
1980
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
1382 int result = os::socket(AF_INET, SOCK_STREAM, 0); |
0 | 1383 if (result <= 0) { |
1384 assert(false, "Socket could not be created!"); | |
1385 } else { | |
1386 _socket = result; | |
1387 } | |
1388 } | |
1389 | |
1390 int networkStream::read(char *buf, size_t len) { | |
1980
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
1391 return os::recv(_socket, buf, (int)len, 0); |
0 | 1392 } |
1393 | |
1394 void networkStream::flush() { | |
1395 if (size() != 0) { | |
4717
11c26bfcf8c7
7091417: recvfrom's 6th input should be of type socklen_t
phh
parents:
3960
diff
changeset
|
1396 int result = os::raw_send(_socket, (char *)base(), size(), 0); |
222 | 1397 assert(result != -1, "connection error"); |
1398 assert(result == (int)size(), "didn't send enough data"); | |
0 | 1399 } |
1400 reset(); | |
1401 } | |
1402 | |
1403 networkStream::~networkStream() { | |
1404 close(); | |
1405 } | |
1406 | |
1407 void networkStream::close() { | |
1408 if (_socket != -1) { | |
1409 flush(); | |
1980
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
1410 os::socket_close(_socket); |
0 | 1411 _socket = -1; |
1412 } | |
1413 } | |
1414 | |
1415 bool networkStream::connect(const char *ip, short port) { | |
1416 | |
1417 struct sockaddr_in server; | |
1418 server.sin_family = AF_INET; | |
1419 server.sin_port = htons(port); | |
1420 | |
1421 server.sin_addr.s_addr = inet_addr(ip); | |
80
092ea87cc974
6679422: networkStream::connect() in ostream.cpp is not 64-bit clean
jcoomes
parents:
0
diff
changeset
|
1422 if (server.sin_addr.s_addr == (uint32_t)-1) { |
1980
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
1423 struct hostent* host = os::get_host_by_name((char*)ip); |
0 | 1424 if (host != NULL) { |
1425 memcpy(&server.sin_addr, host->h_addr_list[0], host->h_length); | |
1426 } else { | |
1427 return false; | |
1428 } | |
1429 } | |
1430 | |
1431 | |
1980
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
1432 int result = os::connect(_socket, (struct sockaddr*)&server, sizeof(struct sockaddr_in)); |
0 | 1433 return (result >= 0); |
1434 } | |
1435 | |
1436 #endif |