author | naoto |
Tue, 09 Jul 2019 08:05:38 -0700 | |
changeset 55627 | 9c1885fb2a42 |
parent 55236 | c87e52dbdca0 |
child 58195 | a82fe7a88ce4 |
permissions | -rw-r--r-- |
1 | 1 |
/* |
53911
65f2a401e0eb
8218811: replace open by os::open in hotspot coding
mbaesken
parents:
51070
diff
changeset
|
2 |
* Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved. |
1 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
5547
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
5237
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
5237
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
5237
diff
changeset
|
21 |
* questions. |
1 | 22 |
* |
23 |
*/ |
|
24 |
||
7397 | 25 |
#include "precompiled.hpp" |
47765
b7c7428eaab9
8189610: Reconcile jvm.h and all jvm_md.h between java.base and hotspot
coleenp
parents:
47216
diff
changeset
|
26 |
#include "jvm.h" |
7397 | 27 |
#include "compiler/compileLog.hpp" |
49360 | 28 |
#include "memory/allocation.inline.hpp" |
7397 | 29 |
#include "oops/oop.inline.hpp" |
30 |
#include "runtime/arguments.hpp" |
|
49593
4dd58ecc9912
8200105: Remove cyclic dependency between oop.inline.hpp and collectedHeap.inline.hpp
stefank
parents:
49360
diff
changeset
|
31 |
#include "runtime/os.inline.hpp" |
25715
d5a8dbdc5150
8049325: Introduce and clean up umbrella headers for the files in the cpu subdirectories.
goetz
parents:
25468
diff
changeset
|
32 |
#include "runtime/vm_version.hpp" |
7397 | 33 |
#include "utilities/defaultStream.hpp" |
27683
1d5707553fff
8064580: Move INCLUDE_CDS include section to the end of the include list
stefank
parents:
26135
diff
changeset
|
34 |
#include "utilities/macros.hpp" |
7397 | 35 |
#include "utilities/ostream.hpp" |
46589 | 36 |
#include "utilities/vmError.hpp" |
7397 | 37 |
#include "utilities/xmlstream.hpp" |
1 | 38 |
|
49842
8c1a4628b2f0
8201649: Remove dubious call_jio_print in ostream.cpp
clanger
parents:
49726
diff
changeset
|
39 |
// Declarations of jvm methods |
8c1a4628b2f0
8201649: Remove dubious call_jio_print in ostream.cpp
clanger
parents:
49726
diff
changeset
|
40 |
extern "C" void jio_print(const char* s, size_t len); |
8c1a4628b2f0
8201649: Remove dubious call_jio_print in ostream.cpp
clanger
parents:
49726
diff
changeset
|
41 |
extern "C" int jio_printf(const char *fmt, ...); |
1 | 42 |
|
43 |
outputStream::outputStream(int width) { |
|
44 |
_width = width; |
|
45 |
_position = 0; |
|
46 |
_newlines = 0; |
|
47 |
_precount = 0; |
|
48 |
_indentation = 0; |
|
35869 | 49 |
_scratch = NULL; |
50 |
_scratch_len = 0; |
|
1 | 51 |
} |
52 |
||
53 |
outputStream::outputStream(int width, bool has_time_stamps) { |
|
54 |
_width = width; |
|
55 |
_position = 0; |
|
56 |
_newlines = 0; |
|
57 |
_precount = 0; |
|
58 |
_indentation = 0; |
|
35869 | 59 |
_scratch = NULL; |
60 |
_scratch_len = 0; |
|
1 | 61 |
if (has_time_stamps) _stamp.update(); |
62 |
} |
|
63 |
||
64 |
void outputStream::update_position(const char* s, size_t len) { |
|
65 |
for (size_t i = 0; i < len; i++) { |
|
66 |
char ch = s[i]; |
|
67 |
if (ch == '\n') { |
|
68 |
_newlines += 1; |
|
69 |
_precount += _position + 1; |
|
70 |
_position = 0; |
|
71 |
} else if (ch == '\t') { |
|
347
df859fcca515
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
1
diff
changeset
|
72 |
int tw = 8 - (_position & 7); |
df859fcca515
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
1
diff
changeset
|
73 |
_position += tw; |
df859fcca515
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
1
diff
changeset
|
74 |
_precount -= tw-1; // invariant: _precount + _position == total count |
1 | 75 |
} else { |
76 |
_position += 1; |
|
77 |
} |
|
78 |
} |
|
79 |
} |
|
80 |
||
81 |
// Execute a vsprintf, using the given buffer if necessary. |
|
82 |
// Return a pointer to the formatted string. |
|
83 |
const char* outputStream::do_vsnprintf(char* buffer, size_t buflen, |
|
84 |
const char* format, va_list ap, |
|
85 |
bool add_cr, |
|
86 |
size_t& result_len) { |
|
27471 | 87 |
assert(buflen >= 2, "buffer too small"); |
88 |
||
1 | 89 |
const char* result; |
90 |
if (add_cr) buflen--; |
|
91 |
if (!strchr(format, '%')) { |
|
92 |
// constant format string |
|
93 |
result = format; |
|
94 |
result_len = strlen(result); |
|
95 |
if (add_cr && result_len >= buflen) result_len = buflen-1; // truncate |
|
96 |
} else if (format[0] == '%' && format[1] == 's' && format[2] == '\0') { |
|
97 |
// trivial copy-through format string |
|
98 |
result = va_arg(ap, const char*); |
|
99 |
result_len = strlen(result); |
|
100 |
if (add_cr && result_len >= buflen) result_len = buflen-1; // truncate |
|
27471 | 101 |
} else { |
49177
eebf559c9e0d
8196882: VS2017 Hotspot Defined vsnprintf Function Causes C2084 Already Defined Compilation Error
kbarrett
parents:
48859
diff
changeset
|
102 |
int written = os::vsnprintf(buffer, buflen, format, ap); |
eebf559c9e0d
8196882: VS2017 Hotspot Defined vsnprintf Function Causes C2084 Already Defined Compilation Error
kbarrett
parents:
48859
diff
changeset
|
103 |
assert(written >= 0, "vsnprintf encoding error"); |
1 | 104 |
result = buffer; |
49177
eebf559c9e0d
8196882: VS2017 Hotspot Defined vsnprintf Function Causes C2084 Already Defined Compilation Error
kbarrett
parents:
48859
diff
changeset
|
105 |
if ((size_t)written < buflen) { |
27471 | 106 |
result_len = written; |
107 |
} else { |
|
108 |
DEBUG_ONLY(warning("increase O_BUFLEN in ostream.hpp -- output truncated");) |
|
109 |
result_len = buflen - 1; |
|
110 |
} |
|
1 | 111 |
} |
112 |
if (add_cr) { |
|
113 |
if (result != buffer) { |
|
30281 | 114 |
memcpy(buffer, result, result_len); |
1 | 115 |
result = buffer; |
116 |
} |
|
117 |
buffer[result_len++] = '\n'; |
|
118 |
buffer[result_len] = 0; |
|
119 |
} |
|
120 |
return result; |
|
121 |
} |
|
122 |
||
35869 | 123 |
void outputStream::do_vsnprintf_and_write_with_automatic_buffer(const char* format, va_list ap, bool add_cr) { |
124 |
char buffer[O_BUFLEN]; |
|
125 |
size_t len; |
|
126 |
const char* str = do_vsnprintf(buffer, sizeof(buffer), format, ap, add_cr, len); |
|
127 |
write(str, len); |
|
128 |
} |
|
129 |
||
130 |
void outputStream::do_vsnprintf_and_write_with_scratch_buffer(const char* format, va_list ap, bool add_cr) { |
|
131 |
size_t len; |
|
132 |
const char* str = do_vsnprintf(_scratch, _scratch_len, format, ap, add_cr, len); |
|
133 |
write(str, len); |
|
134 |
} |
|
135 |
||
136 |
void outputStream::do_vsnprintf_and_write(const char* format, va_list ap, bool add_cr) { |
|
137 |
if (_scratch) { |
|
138 |
do_vsnprintf_and_write_with_scratch_buffer(format, ap, add_cr); |
|
139 |
} else { |
|
140 |
do_vsnprintf_and_write_with_automatic_buffer(format, ap, add_cr); |
|
141 |
} |
|
142 |
} |
|
143 |
||
1 | 144 |
void outputStream::print(const char* format, ...) { |
145 |
va_list ap; |
|
146 |
va_start(ap, format); |
|
35869 | 147 |
do_vsnprintf_and_write(format, ap, false); |
1 | 148 |
va_end(ap); |
149 |
} |
|
150 |
||
151 |
void outputStream::print_cr(const char* format, ...) { |
|
152 |
va_list ap; |
|
153 |
va_start(ap, format); |
|
35869 | 154 |
do_vsnprintf_and_write(format, ap, true); |
1 | 155 |
va_end(ap); |
156 |
} |
|
157 |
||
158 |
void outputStream::vprint(const char *format, va_list argptr) { |
|
35869 | 159 |
do_vsnprintf_and_write(format, argptr, false); |
1 | 160 |
} |
161 |
||
162 |
void outputStream::vprint_cr(const char* format, va_list argptr) { |
|
35869 | 163 |
do_vsnprintf_and_write(format, argptr, true); |
1 | 164 |
} |
165 |
||
166 |
void outputStream::fill_to(int col) { |
|
347
df859fcca515
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
1
diff
changeset
|
167 |
int need_fill = col - position(); |
df859fcca515
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
1
diff
changeset
|
168 |
sp(need_fill); |
df859fcca515
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
1
diff
changeset
|
169 |
} |
df859fcca515
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
1
diff
changeset
|
170 |
|
df859fcca515
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
1
diff
changeset
|
171 |
void outputStream::move_to(int col, int slop, int min_space) { |
df859fcca515
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
1
diff
changeset
|
172 |
if (position() >= col + slop) |
df859fcca515
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
1
diff
changeset
|
173 |
cr(); |
df859fcca515
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
1
diff
changeset
|
174 |
int need_fill = col - position(); |
df859fcca515
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
1
diff
changeset
|
175 |
if (need_fill < min_space) |
df859fcca515
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
1
diff
changeset
|
176 |
need_fill = min_space; |
df859fcca515
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
1
diff
changeset
|
177 |
sp(need_fill); |
1 | 178 |
} |
179 |
||
180 |
void outputStream::put(char ch) { |
|
181 |
assert(ch != 0, "please fix call site"); |
|
182 |
char buf[] = { ch, '\0' }; |
|
183 |
write(buf, 1); |
|
184 |
} |
|
185 |
||
347
df859fcca515
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
1
diff
changeset
|
186 |
#define SP_USE_TABS false |
df859fcca515
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
1
diff
changeset
|
187 |
|
df859fcca515
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
1
diff
changeset
|
188 |
void outputStream::sp(int count) { |
df859fcca515
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
1
diff
changeset
|
189 |
if (count < 0) return; |
df859fcca515
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
1
diff
changeset
|
190 |
if (SP_USE_TABS && count >= 8) { |
df859fcca515
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
1
diff
changeset
|
191 |
int target = position() + count; |
df859fcca515
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
1
diff
changeset
|
192 |
while (count >= 8) { |
df859fcca515
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
1
diff
changeset
|
193 |
this->write("\t", 1); |
df859fcca515
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
1
diff
changeset
|
194 |
count -= 8; |
df859fcca515
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
1
diff
changeset
|
195 |
} |
df859fcca515
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
1
diff
changeset
|
196 |
count = target - position(); |
df859fcca515
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
1
diff
changeset
|
197 |
} |
df859fcca515
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
1
diff
changeset
|
198 |
while (count > 0) { |
df859fcca515
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
1
diff
changeset
|
199 |
int nw = (count > 8) ? 8 : count; |
df859fcca515
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
1
diff
changeset
|
200 |
this->write(" ", nw); |
df859fcca515
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
1
diff
changeset
|
201 |
count -= nw; |
df859fcca515
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
1
diff
changeset
|
202 |
} |
1 | 203 |
} |
204 |
||
205 |
void outputStream::cr() { |
|
206 |
this->write("\n", 1); |
|
207 |
} |
|
208 |
||
49980 | 209 |
void outputStream::cr_indent() { |
210 |
cr(); indent(); |
|
211 |
} |
|
212 |
||
1 | 213 |
void outputStream::stamp() { |
214 |
if (! _stamp.is_updated()) { |
|
215 |
_stamp.update(); // start at 0 on first call to stamp() |
|
216 |
} |
|
217 |
||
218 |
// outputStream::stamp() may get called by ostream_abort(), use snprintf |
|
219 |
// to avoid allocating large stack buffer in print(). |
|
220 |
char buf[40]; |
|
221 |
jio_snprintf(buf, sizeof(buf), "%.3f", _stamp.seconds()); |
|
222 |
print_raw(buf); |
|
223 |
} |
|
224 |
||
1374
4c24294029a9
6711316: Open source the Garbage-First garbage collector
ysr
parents:
349
diff
changeset
|
225 |
void outputStream::stamp(bool guard, |
4c24294029a9
6711316: Open source the Garbage-First garbage collector
ysr
parents:
349
diff
changeset
|
226 |
const char* prefix, |
4c24294029a9
6711316: Open source the Garbage-First garbage collector
ysr
parents:
349
diff
changeset
|
227 |
const char* suffix) { |
4c24294029a9
6711316: Open source the Garbage-First garbage collector
ysr
parents:
349
diff
changeset
|
228 |
if (!guard) { |
4c24294029a9
6711316: Open source the Garbage-First garbage collector
ysr
parents:
349
diff
changeset
|
229 |
return; |
4c24294029a9
6711316: Open source the Garbage-First garbage collector
ysr
parents:
349
diff
changeset
|
230 |
} |
4c24294029a9
6711316: Open source the Garbage-First garbage collector
ysr
parents:
349
diff
changeset
|
231 |
print_raw(prefix); |
4c24294029a9
6711316: Open source the Garbage-First garbage collector
ysr
parents:
349
diff
changeset
|
232 |
stamp(); |
4c24294029a9
6711316: Open source the Garbage-First garbage collector
ysr
parents:
349
diff
changeset
|
233 |
print_raw(suffix); |
4c24294029a9
6711316: Open source the Garbage-First garbage collector
ysr
parents:
349
diff
changeset
|
234 |
} |
4c24294029a9
6711316: Open source the Garbage-First garbage collector
ysr
parents:
349
diff
changeset
|
235 |
|
1 | 236 |
void outputStream::date_stamp(bool guard, |
237 |
const char* prefix, |
|
238 |
const char* suffix) { |
|
239 |
if (!guard) { |
|
240 |
return; |
|
241 |
} |
|
242 |
print_raw(prefix); |
|
243 |
static const char error_time[] = "yyyy-mm-ddThh:mm:ss.mmm+zzzz"; |
|
244 |
static const int buffer_length = 32; |
|
245 |
char buffer[buffer_length]; |
|
246 |
const char* iso8601_result = os::iso8601_time(buffer, buffer_length); |
|
247 |
if (iso8601_result != NULL) { |
|
248 |
print_raw(buffer); |
|
249 |
} else { |
|
250 |
print_raw(error_time); |
|
251 |
} |
|
252 |
print_raw(suffix); |
|
253 |
return; |
|
254 |
} |
|
255 |
||
13476 | 256 |
outputStream& outputStream::indent() { |
1 | 257 |
while (_position < _indentation) sp(); |
13476 | 258 |
return *this; |
1 | 259 |
} |
260 |
||
261 |
void outputStream::print_jlong(jlong value) { |
|
15228
e92acc84ade3
7102489: RFE: cleanup jlong typedef on __APPLE__and _LLP64 systems.
hseigel
parents:
13964
diff
changeset
|
262 |
print(JLONG_FORMAT, value); |
1 | 263 |
} |
264 |
||
265 |
void outputStream::print_julong(julong value) { |
|
15228
e92acc84ade3
7102489: RFE: cleanup jlong typedef on __APPLE__and _LLP64 systems.
hseigel
parents:
13964
diff
changeset
|
266 |
print(JULONG_FORMAT, value); |
1 | 267 |
} |
268 |
||
13476 | 269 |
/** |
270 |
* This prints out hex data in a 'windbg' or 'xxd' form, where each line is: |
|
271 |
* <hex-address>: 8 * <hex-halfword> <ascii translation (optional)> |
|
272 |
* example: |
|
273 |
* 0000000: 7f44 4f46 0102 0102 0000 0000 0000 0000 .DOF............ |
|
274 |
* 0000010: 0000 0000 0000 0040 0000 0020 0000 0005 .......@... .... |
|
275 |
* 0000020: 0000 0000 0000 0040 0000 0000 0000 015d .......@.......] |
|
276 |
* ... |
|
277 |
* |
|
278 |
* indent is applied to each line. Ends with a CR. |
|
279 |
*/ |
|
280 |
void outputStream::print_data(void* data, size_t len, bool with_ascii) { |
|
281 |
size_t limit = (len + 16) / 16 * 16; |
|
282 |
for (size_t i = 0; i < limit; ++i) { |
|
283 |
if (i % 16 == 0) { |
|
31592
43f48e165466
8081202: Hotspot compile warning: "Invalid suffix on literal; C++11 requires a space between literal and identifier"
bpittore
parents:
30764
diff
changeset
|
284 |
indent().print(INTPTR_FORMAT_W(07) ":", i); |
13476 | 285 |
} |
286 |
if (i % 2 == 0) { |
|
287 |
print(" "); |
|
288 |
} |
|
289 |
if (i < len) { |
|
290 |
print("%02x", ((unsigned char*)data)[i]); |
|
291 |
} else { |
|
292 |
print(" "); |
|
293 |
} |
|
294 |
if ((i + 1) % 16 == 0) { |
|
295 |
if (with_ascii) { |
|
296 |
print(" "); |
|
297 |
for (size_t j = 0; j < 16; ++j) { |
|
298 |
size_t idx = i + j - 15; |
|
299 |
if (idx < len) { |
|
300 |
char c = ((char*)data)[idx]; |
|
301 |
print("%c", c >= 32 && c <= 126 ? c : '.'); |
|
302 |
} |
|
303 |
} |
|
304 |
} |
|
24424
2658d7834c6e
8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents:
23517
diff
changeset
|
305 |
cr(); |
13476 | 306 |
} |
307 |
} |
|
308 |
} |
|
309 |
||
1 | 310 |
stringStream::stringStream(size_t initial_size) : outputStream() { |
311 |
buffer_length = initial_size; |
|
54974 | 312 |
buffer = NEW_C_HEAP_ARRAY(char, buffer_length, mtInternal); |
1 | 313 |
buffer_pos = 0; |
314 |
buffer_fixed = false; |
|
55236
c87e52dbdca0
8225225: stringStream internal buffer should always be zero terminated
stuefe
parents:
55023
diff
changeset
|
315 |
zero_terminate(); |
1 | 316 |
} |
317 |
||
318 |
// useful for output to fixed chunks of memory, such as performance counters |
|
319 |
stringStream::stringStream(char* fixed_buffer, size_t fixed_buffer_size) : outputStream() { |
|
320 |
buffer_length = fixed_buffer_size; |
|
321 |
buffer = fixed_buffer; |
|
322 |
buffer_pos = 0; |
|
323 |
buffer_fixed = true; |
|
55236
c87e52dbdca0
8225225: stringStream internal buffer should always be zero terminated
stuefe
parents:
55023
diff
changeset
|
324 |
zero_terminate(); |
1 | 325 |
} |
326 |
||
327 |
void stringStream::write(const char* s, size_t len) { |
|
328 |
size_t write_len = len; // number of non-null bytes to write |
|
329 |
size_t end = buffer_pos + len + 1; // position after write and final '\0' |
|
330 |
if (end > buffer_length) { |
|
331 |
if (buffer_fixed) { |
|
332 |
// if buffer cannot resize, silently truncate |
|
333 |
end = buffer_length; |
|
334 |
write_len = end - buffer_pos - 1; // leave room for the final '\0' |
|
335 |
} else { |
|
336 |
// For small overruns, double the buffer. For larger ones, |
|
337 |
// increase to the requested size. |
|
338 |
if (end < buffer_length * 2) { |
|
339 |
end = buffer_length * 2; |
|
340 |
} |
|
54974 | 341 |
buffer = REALLOC_C_HEAP_ARRAY(char, buffer, end, mtInternal); |
1 | 342 |
buffer_length = end; |
343 |
} |
|
344 |
} |
|
345 |
// invariant: buffer is always null-terminated |
|
346 |
guarantee(buffer_pos + write_len + 1 <= buffer_length, "stringStream oob"); |
|
30281 | 347 |
if (write_len > 0) { |
348 |
memcpy(buffer + buffer_pos, s, write_len); |
|
349 |
buffer_pos += write_len; |
|
55236
c87e52dbdca0
8225225: stringStream internal buffer should always be zero terminated
stuefe
parents:
55023
diff
changeset
|
350 |
zero_terminate(); |
30281 | 351 |
} |
1 | 352 |
|
353 |
// Note that the following does not depend on write_len. |
|
354 |
// This means that position and count get updated |
|
355 |
// even when overflow occurs. |
|
356 |
update_position(s, len); |
|
357 |
} |
|
358 |
||
55236
c87e52dbdca0
8225225: stringStream internal buffer should always be zero terminated
stuefe
parents:
55023
diff
changeset
|
359 |
void stringStream::zero_terminate() { |
c87e52dbdca0
8225225: stringStream internal buffer should always be zero terminated
stuefe
parents:
55023
diff
changeset
|
360 |
assert(buffer != NULL && |
c87e52dbdca0
8225225: stringStream internal buffer should always be zero terminated
stuefe
parents:
55023
diff
changeset
|
361 |
buffer_pos < buffer_length, "sanity"); |
c87e52dbdca0
8225225: stringStream internal buffer should always be zero terminated
stuefe
parents:
55023
diff
changeset
|
362 |
buffer[buffer_pos] = '\0'; |
c87e52dbdca0
8225225: stringStream internal buffer should always be zero terminated
stuefe
parents:
55023
diff
changeset
|
363 |
} |
c87e52dbdca0
8225225: stringStream internal buffer should always be zero terminated
stuefe
parents:
55023
diff
changeset
|
364 |
|
c87e52dbdca0
8225225: stringStream internal buffer should always be zero terminated
stuefe
parents:
55023
diff
changeset
|
365 |
void stringStream::reset() { |
c87e52dbdca0
8225225: stringStream internal buffer should always be zero terminated
stuefe
parents:
55023
diff
changeset
|
366 |
buffer_pos = 0; _precount = 0; _position = 0; |
c87e52dbdca0
8225225: stringStream internal buffer should always be zero terminated
stuefe
parents:
55023
diff
changeset
|
367 |
zero_terminate(); |
c87e52dbdca0
8225225: stringStream internal buffer should always be zero terminated
stuefe
parents:
55023
diff
changeset
|
368 |
} |
c87e52dbdca0
8225225: stringStream internal buffer should always be zero terminated
stuefe
parents:
55023
diff
changeset
|
369 |
|
c87e52dbdca0
8225225: stringStream internal buffer should always be zero terminated
stuefe
parents:
55023
diff
changeset
|
370 |
char* stringStream::as_string() const { |
19968 | 371 |
char* copy = NEW_RESOURCE_ARRAY(char, buffer_pos + 1); |
1 | 372 |
strncpy(copy, buffer, buffer_pos); |
373 |
copy[buffer_pos] = 0; // terminating null |
|
374 |
return copy; |
|
375 |
} |
|
376 |
||
54974 | 377 |
stringStream::~stringStream() { |
378 |
if (buffer_fixed == false && buffer != NULL) { |
|
379 |
FREE_C_HEAP_ARRAY(char, buffer); |
|
380 |
} |
|
381 |
} |
|
1 | 382 |
|
383 |
xmlStream* xtty; |
|
384 |
outputStream* tty; |
|
26135
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
385 |
CDS_ONLY(fileStream* classlist_file;) // Only dump the classes that can be stored into the CDS archive |
1 | 386 |
extern Mutex* tty_lock; |
387 |
||
19968 | 388 |
#define EXTRACHARLEN 32 |
389 |
#define CURRENTAPPX ".current" |
|
390 |
// convert YYYY-MM-DD HH:MM:SS to YYYY-MM-DD_HH-MM-SS |
|
391 |
char* get_datetime_string(char *buf, size_t len) { |
|
392 |
os::local_time_string(buf, len); |
|
393 |
int i = (int)strlen(buf); |
|
35936
e401b754ae09
8148005: One byte may be corrupted by get_datetime_string()
asmotrak
parents:
35897
diff
changeset
|
394 |
while (--i >= 0) { |
19968 | 395 |
if (buf[i] == ' ') buf[i] = '_'; |
396 |
else if (buf[i] == ':') buf[i] = '-'; |
|
397 |
} |
|
398 |
return buf; |
|
399 |
} |
|
400 |
||
401 |
static const char* make_log_name_internal(const char* log_name, const char* force_directory, |
|
402 |
int pid, const char* tms) { |
|
403 |
const char* basename = log_name; |
|
404 |
char file_sep = os::file_separator()[0]; |
|
405 |
const char* cp; |
|
406 |
char pid_text[32]; |
|
407 |
||
408 |
for (cp = log_name; *cp != '\0'; cp++) { |
|
409 |
if (*cp == '/' || *cp == file_sep) { |
|
410 |
basename = cp + 1; |
|
411 |
} |
|
412 |
} |
|
413 |
const char* nametail = log_name; |
|
414 |
// Compute buffer length |
|
415 |
size_t buffer_length; |
|
416 |
if (force_directory != NULL) { |
|
417 |
buffer_length = strlen(force_directory) + strlen(os::file_separator()) + |
|
418 |
strlen(basename) + 1; |
|
419 |
} else { |
|
420 |
buffer_length = strlen(log_name) + 1; |
|
421 |
} |
|
422 |
||
423 |
const char* pts = strstr(basename, "%p"); |
|
424 |
int pid_pos = (pts == NULL) ? -1 : (pts - nametail); |
|
425 |
||
426 |
if (pid_pos >= 0) { |
|
427 |
jio_snprintf(pid_text, sizeof(pid_text), "pid%u", pid); |
|
428 |
buffer_length += strlen(pid_text); |
|
429 |
} |
|
430 |
||
431 |
pts = strstr(basename, "%t"); |
|
432 |
int tms_pos = (pts == NULL) ? -1 : (pts - nametail); |
|
433 |
if (tms_pos >= 0) { |
|
434 |
buffer_length += strlen(tms); |
|
435 |
} |
|
436 |
||
28509 | 437 |
// File name is too long. |
438 |
if (buffer_length > JVM_MAXPATHLEN) { |
|
439 |
return NULL; |
|
440 |
} |
|
441 |
||
19968 | 442 |
// Create big enough buffer. |
443 |
char *buf = NEW_C_HEAP_ARRAY(char, buffer_length, mtInternal); |
|
444 |
||
445 |
strcpy(buf, ""); |
|
446 |
if (force_directory != NULL) { |
|
447 |
strcat(buf, force_directory); |
|
448 |
strcat(buf, os::file_separator()); |
|
449 |
nametail = basename; // completely skip directory prefix |
|
450 |
} |
|
451 |
||
452 |
// who is first, %p or %t? |
|
453 |
int first = -1, second = -1; |
|
454 |
const char *p1st = NULL; |
|
455 |
const char *p2nd = NULL; |
|
456 |
||
457 |
if (pid_pos >= 0 && tms_pos >= 0) { |
|
458 |
// contains both %p and %t |
|
459 |
if (pid_pos < tms_pos) { |
|
460 |
// case foo%pbar%tmonkey.log |
|
461 |
first = pid_pos; |
|
462 |
p1st = pid_text; |
|
463 |
second = tms_pos; |
|
464 |
p2nd = tms; |
|
465 |
} else { |
|
466 |
// case foo%tbar%pmonkey.log |
|
467 |
first = tms_pos; |
|
468 |
p1st = tms; |
|
469 |
second = pid_pos; |
|
470 |
p2nd = pid_text; |
|
471 |
} |
|
472 |
} else if (pid_pos >= 0) { |
|
473 |
// contains %p only |
|
474 |
first = pid_pos; |
|
475 |
p1st = pid_text; |
|
476 |
} else if (tms_pos >= 0) { |
|
477 |
// contains %t only |
|
478 |
first = tms_pos; |
|
479 |
p1st = tms; |
|
480 |
} |
|
481 |
||
482 |
int buf_pos = (int)strlen(buf); |
|
483 |
const char* tail = nametail; |
|
484 |
||
485 |
if (first >= 0) { |
|
486 |
tail = nametail + first + 2; |
|
487 |
strncpy(&buf[buf_pos], nametail, first); |
|
488 |
strcpy(&buf[buf_pos + first], p1st); |
|
489 |
buf_pos = (int)strlen(buf); |
|
490 |
if (second >= 0) { |
|
491 |
strncpy(&buf[buf_pos], tail, second - first - 2); |
|
492 |
strcpy(&buf[buf_pos + second - first - 2], p2nd); |
|
493 |
tail = nametail + second + 2; |
|
494 |
} |
|
495 |
} |
|
496 |
strcat(buf, tail); // append rest of name, or all of name |
|
497 |
return buf; |
|
498 |
} |
|
499 |
||
35061 | 500 |
// log_name comes from -XX:LogFile=log_name or |
26135
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
501 |
// -XX:DumpLoadedClassList=<file_name> |
20691
63d27d9c8e79
8025849: Redundant "pid" in VM log file name (e.g. hotspot_pidpid12345.log)
vlivanov
parents:
20022
diff
changeset
|
502 |
// in log_name, %p => pid1234 and |
19968 | 503 |
// %t => YYYY-MM-DD_HH-MM-SS |
504 |
static const char* make_log_name(const char* log_name, const char* force_directory) { |
|
505 |
char timestr[32]; |
|
506 |
get_datetime_string(timestr, sizeof(timestr)); |
|
507 |
return make_log_name_internal(log_name, force_directory, os::current_process_id(), |
|
508 |
timestr); |
|
509 |
} |
|
510 |
||
1 | 511 |
fileStream::fileStream(const char* file_name) { |
512 |
_file = fopen(file_name, "w"); |
|
19968 | 513 |
if (_file != NULL) { |
514 |
_need_close = true; |
|
515 |
} else { |
|
37113 | 516 |
warning("Cannot open file %s due to %s\n", file_name, os::strerror(errno)); |
19968 | 517 |
_need_close = false; |
518 |
} |
|
1 | 519 |
} |
520 |
||
8114
340b5b8b544b
7003401: Implement VM error-reporting functionality on erroneous termination
kamg
parents:
7405
diff
changeset
|
521 |
fileStream::fileStream(const char* file_name, const char* opentype) { |
340b5b8b544b
7003401: Implement VM error-reporting functionality on erroneous termination
kamg
parents:
7405
diff
changeset
|
522 |
_file = fopen(file_name, opentype); |
19968 | 523 |
if (_file != NULL) { |
524 |
_need_close = true; |
|
525 |
} else { |
|
37113 | 526 |
warning("Cannot open file %s due to %s\n", file_name, os::strerror(errno)); |
19968 | 527 |
_need_close = false; |
528 |
} |
|
8114
340b5b8b544b
7003401: Implement VM error-reporting functionality on erroneous termination
kamg
parents:
7405
diff
changeset
|
529 |
} |
340b5b8b544b
7003401: Implement VM error-reporting functionality on erroneous termination
kamg
parents:
7405
diff
changeset
|
530 |
|
1 | 531 |
void fileStream::write(const char* s, size_t len) { |
1889
24b003a6fe46
6781583: Hotspot build fails on linux 64 bit platform with gcc 4.3.2
xlu
parents:
1388
diff
changeset
|
532 |
if (_file != NULL) { |
24b003a6fe46
6781583: Hotspot build fails on linux 64 bit platform with gcc 4.3.2
xlu
parents:
1388
diff
changeset
|
533 |
// Make an unused local variable to avoid warning from gcc 4.x compiler. |
24b003a6fe46
6781583: Hotspot build fails on linux 64 bit platform with gcc 4.3.2
xlu
parents:
1388
diff
changeset
|
534 |
size_t count = fwrite(s, 1, len, _file); |
24b003a6fe46
6781583: Hotspot build fails on linux 64 bit platform with gcc 4.3.2
xlu
parents:
1388
diff
changeset
|
535 |
} |
1 | 536 |
update_position(s, len); |
537 |
} |
|
538 |
||
8114
340b5b8b544b
7003401: Implement VM error-reporting functionality on erroneous termination
kamg
parents:
7405
diff
changeset
|
539 |
long fileStream::fileSize() { |
340b5b8b544b
7003401: Implement VM error-reporting functionality on erroneous termination
kamg
parents:
7405
diff
changeset
|
540 |
long size = -1; |
340b5b8b544b
7003401: Implement VM error-reporting functionality on erroneous termination
kamg
parents:
7405
diff
changeset
|
541 |
if (_file != NULL) { |
51070 | 542 |
long pos = ::ftell(_file); |
543 |
if (pos < 0) return pos; |
|
8114
340b5b8b544b
7003401: Implement VM error-reporting functionality on erroneous termination
kamg
parents:
7405
diff
changeset
|
544 |
if (::fseek(_file, 0, SEEK_END) == 0) { |
340b5b8b544b
7003401: Implement VM error-reporting functionality on erroneous termination
kamg
parents:
7405
diff
changeset
|
545 |
size = ::ftell(_file); |
340b5b8b544b
7003401: Implement VM error-reporting functionality on erroneous termination
kamg
parents:
7405
diff
changeset
|
546 |
} |
340b5b8b544b
7003401: Implement VM error-reporting functionality on erroneous termination
kamg
parents:
7405
diff
changeset
|
547 |
::fseek(_file, pos, SEEK_SET); |
340b5b8b544b
7003401: Implement VM error-reporting functionality on erroneous termination
kamg
parents:
7405
diff
changeset
|
548 |
} |
340b5b8b544b
7003401: Implement VM error-reporting functionality on erroneous termination
kamg
parents:
7405
diff
changeset
|
549 |
return size; |
340b5b8b544b
7003401: Implement VM error-reporting functionality on erroneous termination
kamg
parents:
7405
diff
changeset
|
550 |
} |
340b5b8b544b
7003401: Implement VM error-reporting functionality on erroneous termination
kamg
parents:
7405
diff
changeset
|
551 |
|
340b5b8b544b
7003401: Implement VM error-reporting functionality on erroneous termination
kamg
parents:
7405
diff
changeset
|
552 |
char* fileStream::readln(char *data, int count ) { |
340b5b8b544b
7003401: Implement VM error-reporting functionality on erroneous termination
kamg
parents:
7405
diff
changeset
|
553 |
char * ret = ::fgets(data, count, _file); |
340b5b8b544b
7003401: Implement VM error-reporting functionality on erroneous termination
kamg
parents:
7405
diff
changeset
|
554 |
//Get rid of annoying \n char |
340b5b8b544b
7003401: Implement VM error-reporting functionality on erroneous termination
kamg
parents:
7405
diff
changeset
|
555 |
data[::strlen(data)-1] = '\0'; |
340b5b8b544b
7003401: Implement VM error-reporting functionality on erroneous termination
kamg
parents:
7405
diff
changeset
|
556 |
return ret; |
340b5b8b544b
7003401: Implement VM error-reporting functionality on erroneous termination
kamg
parents:
7405
diff
changeset
|
557 |
} |
340b5b8b544b
7003401: Implement VM error-reporting functionality on erroneous termination
kamg
parents:
7405
diff
changeset
|
558 |
|
1 | 559 |
fileStream::~fileStream() { |
560 |
if (_file != NULL) { |
|
561 |
if (_need_close) fclose(_file); |
|
9990
c8683968c01b
6941923: RFE: Handling large log files produced by long running Java Applications
minqi
parents:
8887
diff
changeset
|
562 |
_file = NULL; |
1 | 563 |
} |
564 |
} |
|
565 |
||
566 |
void fileStream::flush() { |
|
567 |
fflush(_file); |
|
568 |
} |
|
569 |
||
570 |
void fdStream::write(const char* s, size_t len) { |
|
1889
24b003a6fe46
6781583: Hotspot build fails on linux 64 bit platform with gcc 4.3.2
xlu
parents:
1388
diff
changeset
|
571 |
if (_fd != -1) { |
24b003a6fe46
6781583: Hotspot build fails on linux 64 bit platform with gcc 4.3.2
xlu
parents:
1388
diff
changeset
|
572 |
// Make an unused local variable to avoid warning from gcc 4.x compiler. |
24b003a6fe46
6781583: Hotspot build fails on linux 64 bit platform with gcc 4.3.2
xlu
parents:
1388
diff
changeset
|
573 |
size_t count = ::write(_fd, s, (int)len); |
24b003a6fe46
6781583: Hotspot build fails on linux 64 bit platform with gcc 4.3.2
xlu
parents:
1388
diff
changeset
|
574 |
} |
1 | 575 |
update_position(s, len); |
576 |
} |
|
577 |
||
578 |
defaultStream* defaultStream::instance = NULL; |
|
579 |
int defaultStream::_output_fd = 1; |
|
580 |
int defaultStream::_error_fd = 2; |
|
581 |
FILE* defaultStream::_output_stream = stdout; |
|
582 |
FILE* defaultStream::_error_stream = stderr; |
|
583 |
||
584 |
#define LOG_MAJOR_VERSION 160 |
|
585 |
#define LOG_MINOR_VERSION 1 |
|
586 |
||
587 |
void defaultStream::init() { |
|
588 |
_inited = true; |
|
589 |
if (LogVMOutput || LogCompilation) { |
|
590 |
init_log(); |
|
591 |
} |
|
592 |
} |
|
593 |
||
594 |
bool defaultStream::has_log_file() { |
|
595 |
// lazily create log file (at startup, LogVMOutput is false even |
|
596 |
// if +LogVMOutput is used, because the flags haven't been parsed yet) |
|
597 |
// For safer printing during fatal error handling, do not init logfile |
|
598 |
// if a VM error has been reported. |
|
46589 | 599 |
if (!_inited && !VMError::is_error_reported()) init(); |
1 | 600 |
return _log_file != NULL; |
601 |
} |
|
602 |
||
28509 | 603 |
fileStream* defaultStream::open_file(const char* log_name) { |
604 |
const char* try_name = make_log_name(log_name, NULL); |
|
605 |
if (try_name == NULL) { |
|
606 |
warning("Cannot open file %s: file name is too long.\n", log_name); |
|
607 |
return NULL; |
|
608 |
} |
|
609 |
||
610 |
fileStream* file = new(ResourceObj::C_HEAP, mtInternal) fileStream(try_name); |
|
611 |
FREE_C_HEAP_ARRAY(char, try_name); |
|
612 |
if (file->is_open()) { |
|
613 |
return file; |
|
614 |
} |
|
615 |
||
616 |
// Try again to open the file in the temp directory. |
|
617 |
delete file; |
|
49842
8c1a4628b2f0
8201649: Remove dubious call_jio_print in ostream.cpp
clanger
parents:
49726
diff
changeset
|
618 |
// Note: This feature is for maintainer use only. No need for L10N. |
8c1a4628b2f0
8201649: Remove dubious call_jio_print in ostream.cpp
clanger
parents:
49726
diff
changeset
|
619 |
jio_printf("Warning: Cannot open log file: %s\n", log_name); |
28509 | 620 |
try_name = make_log_name(log_name, os::get_temp_directory()); |
621 |
if (try_name == NULL) { |
|
622 |
warning("Cannot open file %s: file name is too long for directory %s.\n", log_name, os::get_temp_directory()); |
|
623 |
return NULL; |
|
624 |
} |
|
625 |
||
49842
8c1a4628b2f0
8201649: Remove dubious call_jio_print in ostream.cpp
clanger
parents:
49726
diff
changeset
|
626 |
jio_printf("Warning: Forcing option -XX:LogFile=%s\n", try_name); |
28509 | 627 |
|
628 |
file = new(ResourceObj::C_HEAP, mtInternal) fileStream(try_name); |
|
629 |
FREE_C_HEAP_ARRAY(char, try_name); |
|
630 |
if (file->is_open()) { |
|
631 |
return file; |
|
632 |
} |
|
633 |
||
634 |
delete file; |
|
635 |
return NULL; |
|
636 |
} |
|
637 |
||
1 | 638 |
void defaultStream::init_log() { |
639 |
// %%% Need a MutexLocker? |
|
20691
63d27d9c8e79
8025849: Redundant "pid" in VM log file name (e.g. hotspot_pidpid12345.log)
vlivanov
parents:
20022
diff
changeset
|
640 |
const char* log_name = LogFile != NULL ? LogFile : "hotspot_%p.log"; |
28509 | 641 |
fileStream* file = open_file(log_name); |
642 |
||
643 |
if (file != NULL) { |
|
644 |
_log_file = file; |
|
645 |
_outer_xmlStream = new(ResourceObj::C_HEAP, mtInternal) xmlStream(file); |
|
646 |
start_log(); |
|
647 |
} else { |
|
648 |
// and leave xtty as NULL |
|
649 |
LogVMOutput = false; |
|
650 |
DisplayVMOutput = true; |
|
651 |
LogCompilation = false; |
|
1 | 652 |
} |
28509 | 653 |
} |
20010
c66a7254680c
8023134: Rename VM LogFile to hotspot_pid{pid}.log (was hotspot.log)
vlivanov
parents:
18928
diff
changeset
|
654 |
|
28509 | 655 |
void defaultStream::start_log() { |
656 |
xmlStream*xs = _outer_xmlStream; |
|
1 | 657 |
if (this == tty) xtty = xs; |
658 |
// Write XML header. |
|
659 |
xs->print_cr("<?xml version='1.0' encoding='UTF-8'?>"); |
|
660 |
// (For now, don't bother to issue a DTD for this private format.) |
|
661 |
jlong time_ms = os::javaTimeMillis() - tty->time_stamp().milliseconds(); |
|
662 |
// %%% Should be: jlong time_ms = os::start_time_milliseconds(), if |
|
663 |
// we ever get round to introduce that method on the os class |
|
664 |
xs->head("hotspot_log version='%d %d'" |
|
31592
43f48e165466
8081202: Hotspot compile warning: "Invalid suffix on literal; C++11 requires a space between literal and identifier"
bpittore
parents:
30764
diff
changeset
|
665 |
" process='%d' time_ms='" INT64_FORMAT "'", |
1 | 666 |
LOG_MAJOR_VERSION, LOG_MINOR_VERSION, |
24424
2658d7834c6e
8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents:
23517
diff
changeset
|
667 |
os::current_process_id(), (int64_t)time_ms); |
1 | 668 |
// Write VM version header immediately. |
669 |
xs->head("vm_version"); |
|
670 |
xs->head("name"); xs->text("%s", VM_Version::vm_name()); xs->cr(); |
|
671 |
xs->tail("name"); |
|
672 |
xs->head("release"); xs->text("%s", VM_Version::vm_release()); xs->cr(); |
|
673 |
xs->tail("release"); |
|
674 |
xs->head("info"); xs->text("%s", VM_Version::internal_vm_info_string()); xs->cr(); |
|
675 |
xs->tail("info"); |
|
676 |
xs->tail("vm_version"); |
|
677 |
// Record information about the command-line invocation. |
|
678 |
xs->head("vm_arguments"); // Cf. Arguments::print_on() |
|
679 |
if (Arguments::num_jvm_flags() > 0) { |
|
680 |
xs->head("flags"); |
|
681 |
Arguments::print_jvm_flags_on(xs->text()); |
|
682 |
xs->tail("flags"); |
|
683 |
} |
|
684 |
if (Arguments::num_jvm_args() > 0) { |
|
685 |
xs->head("args"); |
|
686 |
Arguments::print_jvm_args_on(xs->text()); |
|
687 |
xs->tail("args"); |
|
688 |
} |
|
689 |
if (Arguments::java_command() != NULL) { |
|
690 |
xs->head("command"); xs->text()->print_cr("%s", Arguments::java_command()); |
|
691 |
xs->tail("command"); |
|
692 |
} |
|
693 |
if (Arguments::sun_java_launcher() != NULL) { |
|
694 |
xs->head("launcher"); xs->text()->print_cr("%s", Arguments::sun_java_launcher()); |
|
695 |
xs->tail("launcher"); |
|
696 |
} |
|
697 |
if (Arguments::system_properties() != NULL) { |
|
698 |
xs->head("properties"); |
|
699 |
// Print it as a java-style property list. |
|
700 |
// System properties don't generally contain newlines, so don't bother with unparsing. |
|
30251
9b05c9cc4698
8077308: Fix warning: increase O_BUFLEN in ostream.hpp -- output truncated
dholmes
parents:
28509
diff
changeset
|
701 |
outputStream *text = xs->text(); |
1 | 702 |
for (SystemProperty* p = Arguments::system_properties(); p != NULL; p = p->next()) { |
36508 | 703 |
assert(p->key() != NULL, "p->key() is NULL"); |
40244
b3055c216762
8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
37466
diff
changeset
|
704 |
if (p->is_readable()) { |
b3055c216762
8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
37466
diff
changeset
|
705 |
// Print in two stages to avoid problems with long |
b3055c216762
8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
37466
diff
changeset
|
706 |
// keys/values. |
b3055c216762
8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
37466
diff
changeset
|
707 |
text->print_raw(p->key()); |
b3055c216762
8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
37466
diff
changeset
|
708 |
text->put('='); |
b3055c216762
8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
37466
diff
changeset
|
709 |
assert(p->value() != NULL, "p->value() is NULL"); |
b3055c216762
8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
37466
diff
changeset
|
710 |
text->print_raw_cr(p->value()); |
b3055c216762
8136930: Simplify use of module-system options by custom launchers
hseigel
parents:
37466
diff
changeset
|
711 |
} |
1 | 712 |
} |
713 |
xs->tail("properties"); |
|
714 |
} |
|
715 |
xs->tail("vm_arguments"); |
|
716 |
// tty output per se is grouped under the <tty>...</tty> element. |
|
717 |
xs->head("tty"); |
|
718 |
// All further non-markup text gets copied to the tty: |
|
719 |
xs->_text = this; // requires friend declaration! |
|
720 |
} |
|
721 |
||
722 |
// finish_log() is called during normal VM shutdown. finish_log_on_error() is |
|
723 |
// called by ostream_abort() after a fatal error. |
|
724 |
// |
|
725 |
void defaultStream::finish_log() { |
|
726 |
xmlStream* xs = _outer_xmlStream; |
|
727 |
xs->done("tty"); |
|
728 |
||
729 |
// Other log forks are appended here, at the End of Time: |
|
730 |
CompileLog::finish_log(xs->out()); // write compile logging, if any, now |
|
731 |
||
732 |
xs->done("hotspot_log"); |
|
733 |
xs->flush(); |
|
734 |
||
735 |
fileStream* file = _log_file; |
|
736 |
_log_file = NULL; |
|
737 |
||
738 |
delete _outer_xmlStream; |
|
739 |
_outer_xmlStream = NULL; |
|
740 |
||
741 |
file->flush(); |
|
742 |
delete file; |
|
743 |
} |
|
744 |
||
745 |
void defaultStream::finish_log_on_error(char *buf, int buflen) { |
|
746 |
xmlStream* xs = _outer_xmlStream; |
|
747 |
||
748 |
if (xs && xs->out()) { |
|
749 |
||
750 |
xs->done_raw("tty"); |
|
751 |
||
752 |
// Other log forks are appended here, at the End of Time: |
|
753 |
CompileLog::finish_log_on_error(xs->out(), buf, buflen); // write compile logging, if any, now |
|
754 |
||
755 |
xs->done_raw("hotspot_log"); |
|
756 |
xs->flush(); |
|
757 |
||
758 |
fileStream* file = _log_file; |
|
759 |
_log_file = NULL; |
|
760 |
_outer_xmlStream = NULL; |
|
761 |
||
762 |
if (file) { |
|
763 |
file->flush(); |
|
764 |
||
765 |
// Can't delete or close the file because delete and fclose aren't |
|
766 |
// async-safe. We are about to die, so leave it to the kernel. |
|
767 |
// delete file; |
|
768 |
} |
|
769 |
} |
|
770 |
} |
|
771 |
||
772 |
intx defaultStream::hold(intx writer_id) { |
|
773 |
bool has_log = has_log_file(); // check before locking |
|
774 |
if (// impossible, but who knows? |
|
775 |
writer_id == NO_WRITER || |
|
776 |
||
777 |
// bootstrap problem |
|
778 |
tty_lock == NULL || |
|
779 |
||
34633
2a6c7c7b30a7
8132510: Replace ThreadLocalStorage with compiler/language-based thread-local variables
dholmes
parents:
33736
diff
changeset
|
780 |
// can't grab a lock if current Thread isn't set |
2a6c7c7b30a7
8132510: Replace ThreadLocalStorage with compiler/language-based thread-local variables
dholmes
parents:
33736
diff
changeset
|
781 |
Thread::current_or_null() == NULL || |
1 | 782 |
|
783 |
// developer hook |
|
784 |
!SerializeVMOutput || |
|
785 |
||
786 |
// VM already unhealthy |
|
46589 | 787 |
VMError::is_error_reported() || |
1 | 788 |
|
789 |
// safepoint == global lock (for VM only) |
|
790 |
(SafepointSynchronize::is_synchronizing() && |
|
791 |
Thread::current()->is_VM_thread()) |
|
792 |
) { |
|
793 |
// do not attempt to lock unless we know the thread and the VM is healthy |
|
794 |
return NO_WRITER; |
|
795 |
} |
|
796 |
if (_writer == writer_id) { |
|
797 |
// already held, no need to re-grab the lock |
|
798 |
return NO_WRITER; |
|
799 |
} |
|
800 |
tty_lock->lock_without_safepoint_check(); |
|
801 |
// got the lock |
|
802 |
if (writer_id != _last_writer) { |
|
803 |
if (has_log) { |
|
804 |
_log_file->bol(); |
|
805 |
// output a hint where this output is coming from: |
|
13964 | 806 |
_log_file->print_cr("<writer thread='" UINTX_FORMAT "'/>", writer_id); |
1 | 807 |
} |
808 |
_last_writer = writer_id; |
|
809 |
} |
|
810 |
_writer = writer_id; |
|
811 |
return writer_id; |
|
812 |
} |
|
813 |
||
814 |
void defaultStream::release(intx holder) { |
|
815 |
if (holder == NO_WRITER) { |
|
816 |
// nothing to release: either a recursive lock, or we scribbled (too bad) |
|
817 |
return; |
|
818 |
} |
|
819 |
if (_writer != holder) { |
|
820 |
return; // already unlocked, perhaps via break_tty_lock_for_safepoint |
|
821 |
} |
|
822 |
_writer = NO_WRITER; |
|
823 |
tty_lock->unlock(); |
|
824 |
} |
|
825 |
||
826 |
void defaultStream::write(const char* s, size_t len) { |
|
827 |
intx thread_id = os::current_thread_id(); |
|
828 |
intx holder = hold(thread_id); |
|
829 |
||
830 |
if (DisplayVMOutput && |
|
831 |
(_outer_xmlStream == NULL || !_outer_xmlStream->inside_attrs())) { |
|
832 |
// print to output stream. It can be redirected by a vfprintf hook |
|
49842
8c1a4628b2f0
8201649: Remove dubious call_jio_print in ostream.cpp
clanger
parents:
49726
diff
changeset
|
833 |
jio_print(s, len); |
1 | 834 |
} |
835 |
||
836 |
// print to log file |
|
837 |
if (has_log_file()) { |
|
838 |
int nl0 = _newlines; |
|
839 |
xmlTextStream::write(s, len); |
|
840 |
// flush the log file too, if there were any newlines |
|
841 |
if (nl0 != _newlines){ |
|
842 |
flush(); |
|
843 |
} |
|
844 |
} else { |
|
845 |
update_position(s, len); |
|
846 |
} |
|
847 |
||
848 |
release(holder); |
|
849 |
} |
|
850 |
||
851 |
intx ttyLocker::hold_tty() { |
|
852 |
if (defaultStream::instance == NULL) return defaultStream::NO_WRITER; |
|
853 |
intx thread_id = os::current_thread_id(); |
|
854 |
return defaultStream::instance->hold(thread_id); |
|
855 |
} |
|
856 |
||
857 |
void ttyLocker::release_tty(intx holder) { |
|
858 |
if (holder == defaultStream::NO_WRITER) return; |
|
859 |
defaultStream::instance->release(holder); |
|
860 |
} |
|
861 |
||
8333
11a7f6fc6419
7021531: lock ordering problems after fix for 6354181
never
parents:
8114
diff
changeset
|
862 |
bool ttyLocker::release_tty_if_locked() { |
11a7f6fc6419
7021531: lock ordering problems after fix for 6354181
never
parents:
8114
diff
changeset
|
863 |
intx thread_id = os::current_thread_id(); |
11a7f6fc6419
7021531: lock ordering problems after fix for 6354181
never
parents:
8114
diff
changeset
|
864 |
if (defaultStream::instance->writer() == thread_id) { |
11a7f6fc6419
7021531: lock ordering problems after fix for 6354181
never
parents:
8114
diff
changeset
|
865 |
// release the lock and return true so callers know if was |
11a7f6fc6419
7021531: lock ordering problems after fix for 6354181
never
parents:
8114
diff
changeset
|
866 |
// previously held. |
11a7f6fc6419
7021531: lock ordering problems after fix for 6354181
never
parents:
8114
diff
changeset
|
867 |
release_tty(thread_id); |
11a7f6fc6419
7021531: lock ordering problems after fix for 6354181
never
parents:
8114
diff
changeset
|
868 |
return true; |
11a7f6fc6419
7021531: lock ordering problems after fix for 6354181
never
parents:
8114
diff
changeset
|
869 |
} |
11a7f6fc6419
7021531: lock ordering problems after fix for 6354181
never
parents:
8114
diff
changeset
|
870 |
return false; |
11a7f6fc6419
7021531: lock ordering problems after fix for 6354181
never
parents:
8114
diff
changeset
|
871 |
} |
11a7f6fc6419
7021531: lock ordering problems after fix for 6354181
never
parents:
8114
diff
changeset
|
872 |
|
1 | 873 |
void ttyLocker::break_tty_lock_for_safepoint(intx holder) { |
874 |
if (defaultStream::instance != NULL && |
|
875 |
defaultStream::instance->writer() == holder) { |
|
876 |
if (xtty != NULL) { |
|
877 |
xtty->print_cr("<!-- safepoint while printing -->"); |
|
878 |
} |
|
879 |
defaultStream::instance->release(holder); |
|
880 |
} |
|
881 |
// (else there was no lock to break) |
|
882 |
} |
|
883 |
||
884 |
void ostream_init() { |
|
885 |
if (defaultStream::instance == NULL) { |
|
13195 | 886 |
defaultStream::instance = new(ResourceObj::C_HEAP, mtInternal) defaultStream(); |
1 | 887 |
tty = defaultStream::instance; |
888 |
||
889 |
// We want to ensure that time stamps in GC logs consider time 0 |
|
890 |
// the time when the JVM is initialized, not the first time we ask |
|
891 |
// for a time stamp. So, here, we explicitly update the time stamp |
|
892 |
// of tty. |
|
893 |
tty->time_stamp().update_to(1); |
|
894 |
} |
|
895 |
} |
|
896 |
||
897 |
void ostream_init_log() { |
|
898 |
// Note : this must be called AFTER ostream_init() |
|
899 |
||
26135
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
900 |
#if INCLUDE_CDS |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
901 |
// For -XX:DumpLoadedClassList=<file> option |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
902 |
if (DumpLoadedClassList != NULL) { |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
903 |
const char* list_name = make_log_name(DumpLoadedClassList, NULL); |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
904 |
classlist_file = new(ResourceObj::C_HEAP, mtInternal) |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
905 |
fileStream(list_name); |
27880
afb974a04396
8060074: os::free() takes MemoryTrackingLevel but doesn't need it
coleenp
parents:
27471
diff
changeset
|
906 |
FREE_C_HEAP_ARRAY(char, list_name); |
26135
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
907 |
} |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
908 |
#endif |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
909 |
|
1 | 910 |
// If we haven't lazily initialized the logfile yet, do it now, |
911 |
// to avoid the possibility of lazy initialization during a VM |
|
912 |
// crash, which can affect the stability of the fatal error handler. |
|
913 |
defaultStream::instance->has_log_file(); |
|
914 |
} |
|
915 |
||
916 |
// ostream_exit() is called during normal VM exit to finish log files, flush |
|
917 |
// output and free resource. |
|
918 |
void ostream_exit() { |
|
919 |
static bool ostream_exit_called = false; |
|
920 |
if (ostream_exit_called) return; |
|
921 |
ostream_exit_called = true; |
|
26135
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
922 |
#if INCLUDE_CDS |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
923 |
if (classlist_file != NULL) { |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
924 |
delete classlist_file; |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
925 |
} |
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25715
diff
changeset
|
926 |
#endif |
48859
5a4d08efbad9
6909265: assert(_OnDeck != Self->_MutexEvent,"invariant") with -XX:+PrintMallocFree
coleenp
parents:
47765
diff
changeset
|
927 |
if (tty != defaultStream::instance) { |
5a4d08efbad9
6909265: assert(_OnDeck != Self->_MutexEvent,"invariant") with -XX:+PrintMallocFree
coleenp
parents:
47765
diff
changeset
|
928 |
delete tty; |
5a4d08efbad9
6909265: assert(_OnDeck != Self->_MutexEvent,"invariant") with -XX:+PrintMallocFree
coleenp
parents:
47765
diff
changeset
|
929 |
} |
5a4d08efbad9
6909265: assert(_OnDeck != Self->_MutexEvent,"invariant") with -XX:+PrintMallocFree
coleenp
parents:
47765
diff
changeset
|
930 |
if (defaultStream::instance != NULL) { |
5a4d08efbad9
6909265: assert(_OnDeck != Self->_MutexEvent,"invariant") with -XX:+PrintMallocFree
coleenp
parents:
47765
diff
changeset
|
931 |
delete defaultStream::instance; |
1 | 932 |
} |
933 |
tty = NULL; |
|
934 |
xtty = NULL; |
|
935 |
defaultStream::instance = NULL; |
|
936 |
} |
|
937 |
||
938 |
// ostream_abort() is called by os::abort() when VM is about to die. |
|
939 |
void ostream_abort() { |
|
35061 | 940 |
// Here we can't delete tty, just flush its output |
1 | 941 |
if (tty) tty->flush(); |
942 |
||
943 |
if (defaultStream::instance != NULL) { |
|
944 |
static char buf[4096]; |
|
945 |
defaultStream::instance->finish_log_on_error(buf, sizeof(buf)); |
|
946 |
} |
|
947 |
} |
|
948 |
||
768 | 949 |
bufferedStream::bufferedStream(size_t initial_size, size_t bufmax) : outputStream() { |
1 | 950 |
buffer_length = initial_size; |
13195 | 951 |
buffer = NEW_C_HEAP_ARRAY(char, buffer_length, mtInternal); |
1 | 952 |
buffer_pos = 0; |
953 |
buffer_fixed = false; |
|
768 | 954 |
buffer_max = bufmax; |
55023 | 955 |
truncated = false; |
1 | 956 |
} |
957 |
||
768 | 958 |
bufferedStream::bufferedStream(char* fixed_buffer, size_t fixed_buffer_size, size_t bufmax) : outputStream() { |
1 | 959 |
buffer_length = fixed_buffer_size; |
960 |
buffer = fixed_buffer; |
|
961 |
buffer_pos = 0; |
|
962 |
buffer_fixed = true; |
|
768 | 963 |
buffer_max = bufmax; |
55023 | 964 |
truncated = false; |
1 | 965 |
} |
966 |
||
967 |
void bufferedStream::write(const char* s, size_t len) { |
|
768 | 968 |
|
55023 | 969 |
if (truncated) { |
970 |
return; |
|
971 |
} |
|
972 |
||
768 | 973 |
if(buffer_pos + len > buffer_max) { |
55023 | 974 |
flush(); // Note: may be a noop. |
768 | 975 |
} |
976 |
||
1 | 977 |
size_t end = buffer_pos + len; |
978 |
if (end >= buffer_length) { |
|
979 |
if (buffer_fixed) { |
|
980 |
// if buffer cannot resize, silently truncate |
|
981 |
len = buffer_length - buffer_pos - 1; |
|
55023 | 982 |
truncated = true; |
1 | 983 |
} else { |
984 |
// For small overruns, double the buffer. For larger ones, |
|
985 |
// increase to the requested size. |
|
986 |
if (end < buffer_length * 2) { |
|
987 |
end = buffer_length * 2; |
|
988 |
} |
|
55023 | 989 |
// Impose a cap beyond which the buffer cannot grow - a size which |
990 |
// in all probability indicates a real error, e.g. faulty printing |
|
991 |
// code looping, while not affecting cases of just-very-large-but-its-normal |
|
992 |
// output. |
|
993 |
const size_t reasonable_cap = MAX2(100 * M, buffer_max * 2); |
|
994 |
if (end > reasonable_cap) { |
|
995 |
// In debug VM, assert right away. |
|
996 |
assert(false, "Exceeded max buffer size for this string."); |
|
997 |
// Release VM: silently truncate. We do this since these kind of errors |
|
998 |
// are both difficult to predict with testing (depending on logging content) |
|
999 |
// and usually not serious enough to kill a production VM for it. |
|
1000 |
end = reasonable_cap; |
|
1001 |
size_t remaining = end - buffer_pos; |
|
1002 |
if (len >= remaining) { |
|
1003 |
len = remaining - 1; |
|
1004 |
truncated = true; |
|
1005 |
} |
|
1006 |
} |
|
1007 |
if (buffer_length < end) { |
|
1008 |
buffer = REALLOC_C_HEAP_ARRAY(char, buffer, end, mtInternal); |
|
1009 |
buffer_length = end; |
|
1010 |
} |
|
1 | 1011 |
} |
1012 |
} |
|
55023 | 1013 |
if (len > 0) { |
1014 |
memcpy(buffer + buffer_pos, s, len); |
|
1015 |
buffer_pos += len; |
|
1016 |
update_position(s, len); |
|
1017 |
} |
|
1 | 1018 |
} |
1019 |
||
1020 |
char* bufferedStream::as_string() { |
|
1021 |
char* copy = NEW_RESOURCE_ARRAY(char, buffer_pos+1); |
|
1022 |
strncpy(copy, buffer, buffer_pos); |
|
1023 |
copy[buffer_pos] = 0; // terminating null |
|
1024 |
return copy; |
|
1025 |
} |
|
1026 |
||
1027 |
bufferedStream::~bufferedStream() { |
|
1028 |
if (!buffer_fixed) { |
|
27880
afb974a04396
8060074: os::free() takes MemoryTrackingLevel but doesn't need it
coleenp
parents:
27471
diff
changeset
|
1029 |
FREE_C_HEAP_ARRAY(char, buffer); |
1 | 1030 |
} |
1031 |
} |
|
1032 |
||
1033 |
#ifndef PRODUCT |
|
1034 |
||
22827 | 1035 |
#if defined(SOLARIS) || defined(LINUX) || defined(AIX) || defined(_ALLBSD_SOURCE) |
1 | 1036 |
#include <sys/types.h> |
1037 |
#include <sys/socket.h> |
|
1038 |
#include <netinet/in.h> |
|
1039 |
#include <arpa/inet.h> |
|
49726
4ae63fcabe2e
8199736: Define WIN32_LEAN_AND_MEAN before including windows.h
rwestberg
parents:
49593
diff
changeset
|
1040 |
#elif defined(_WINDOWS) |
4ae63fcabe2e
8199736: Define WIN32_LEAN_AND_MEAN before including windows.h
rwestberg
parents:
49593
diff
changeset
|
1041 |
#include <winsock2.h> |
1 | 1042 |
#endif |
1043 |
||
1044 |
// Network access |
|
768 | 1045 |
networkStream::networkStream() : bufferedStream(1024*10, 1024*10) { |
1 | 1046 |
|
1047 |
_socket = -1; |
|
1048 |
||
7405
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
1049 |
int result = os::socket(AF_INET, SOCK_STREAM, 0); |
1 | 1050 |
if (result <= 0) { |
1051 |
assert(false, "Socket could not be created!"); |
|
1052 |
} else { |
|
1053 |
_socket = result; |
|
1054 |
} |
|
1055 |
} |
|
1056 |
||
1057 |
int networkStream::read(char *buf, size_t len) { |
|
7405
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
1058 |
return os::recv(_socket, buf, (int)len, 0); |
1 | 1059 |
} |
1060 |
||
1061 |
void networkStream::flush() { |
|
1062 |
if (size() != 0) { |
|
11256
025cd1741566
7091417: recvfrom's 6th input should be of type socklen_t
phh
parents:
10565
diff
changeset
|
1063 |
int result = os::raw_send(_socket, (char *)base(), size(), 0); |
768 | 1064 |
assert(result != -1, "connection error"); |
1065 |
assert(result == (int)size(), "didn't send enough data"); |
|
1 | 1066 |
} |
1067 |
reset(); |
|
1068 |
} |
|
1069 |
||
1070 |
networkStream::~networkStream() { |
|
1071 |
close(); |
|
1072 |
} |
|
1073 |
||
1074 |
void networkStream::close() { |
|
1075 |
if (_socket != -1) { |
|
1076 |
flush(); |
|
7405
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
1077 |
os::socket_close(_socket); |
1 | 1078 |
_socket = -1; |
1079 |
} |
|
1080 |
} |
|
1081 |
||
1082 |
bool networkStream::connect(const char *ip, short port) { |
|
1083 |
||
1084 |
struct sockaddr_in server; |
|
1085 |
server.sin_family = AF_INET; |
|
1086 |
server.sin_port = htons(port); |
|
1087 |
||
1088 |
server.sin_addr.s_addr = inet_addr(ip); |
|
253
cc8062372007
6679422: networkStream::connect() in ostream.cpp is not 64-bit clean
jcoomes
parents:
1
diff
changeset
|
1089 |
if (server.sin_addr.s_addr == (uint32_t)-1) { |
7405
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
1090 |
struct hostent* host = os::get_host_by_name((char*)ip); |
1 | 1091 |
if (host != NULL) { |
1092 |
memcpy(&server.sin_addr, host->h_addr_list[0], host->h_length); |
|
1093 |
} else { |
|
1094 |
return false; |
|
1095 |
} |
|
1096 |
} |
|
1097 |
||
1098 |
||
7405
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
1099 |
int result = os::connect(_socket, (struct sockaddr*)&server, sizeof(struct sockaddr_in)); |
1 | 1100 |
return (result >= 0); |
1101 |
} |
|
1102 |
||
1103 |
#endif |