annotate src/share/vm/utilities/ostream.hpp @ 14649:f6301b007a16

6498581: ThreadInterruptTest3 produces wrong output on Windows Summary: There is race condition between os::interrupt and os::is_interrupted on Windows. In JVM_Sleep(Thread.sleep), check if thread gets interrupted, it may see interrupted but not really interrupted so cause spurious waking up (early return from sleep). Fix by checking if interrupt event really gets set thus prevent false return. For intrinsic of _isInterrupted, on Windows, go fastpath only on bit not set. Reviewed-by: acorn, kvn Contributed-by: david.holmes@oracle.com, yumin.qi@oracle.com
author minqi
date Wed, 26 Feb 2014 15:20:41 -0800
parents de6a9e811145
children 4ca6dc0799b6 f42c10a3d4b1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
14223
de6a9e811145 8029233: Update copyright year to match last edit in jdk8 hotspot repository for 2013
mikael
parents: 12215
diff changeset
2 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
18 *
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 356
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 356
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: 356
diff changeset
21 * questions.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
25 #ifndef SHARE_VM_UTILITIES_OSTREAM_HPP
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
26 #define SHARE_VM_UTILITIES_OSTREAM_HPP
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
27
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
28 #include "memory/allocation.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
29 #include "runtime/timer.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
30
11136
dbc0b5dc08f5 7143807: ResourceMark nesting problem in stringStream
fparain
parents: 10195
diff changeset
31 DEBUG_ONLY(class ResourceMark;)
dbc0b5dc08f5 7143807: ResourceMark nesting problem in stringStream
fparain
parents: 10195
diff changeset
32
0
a61af66fc99e Initial load
duke
parents:
diff changeset
33 // Output streams for printing
a61af66fc99e Initial load
duke
parents:
diff changeset
34 //
a61af66fc99e Initial load
duke
parents:
diff changeset
35 // Printing guidelines:
a61af66fc99e Initial load
duke
parents:
diff changeset
36 // Where possible, please use tty->print() and tty->print_cr().
a61af66fc99e Initial load
duke
parents:
diff changeset
37 // For product mode VM warnings use warning() which internally uses tty.
a61af66fc99e Initial load
duke
parents:
diff changeset
38 // In places where tty is not initialized yet or too much overhead,
a61af66fc99e Initial load
duke
parents:
diff changeset
39 // we may use jio_printf:
a61af66fc99e Initial load
duke
parents:
diff changeset
40 // jio_fprintf(defaultStream::output_stream(), "Message");
a61af66fc99e Initial load
duke
parents:
diff changeset
41 // This allows for redirection via -XX:+DisplayVMOutputToStdout and
a61af66fc99e Initial load
duke
parents:
diff changeset
42 // -XX:+DisplayVMOutputToStderr
a61af66fc99e Initial load
duke
parents:
diff changeset
43 class outputStream : public ResourceObj {
a61af66fc99e Initial load
duke
parents:
diff changeset
44 protected:
a61af66fc99e Initial load
duke
parents:
diff changeset
45 int _indentation; // current indentation
a61af66fc99e Initial load
duke
parents:
diff changeset
46 int _width; // width of the page
a61af66fc99e Initial load
duke
parents:
diff changeset
47 int _position; // position on the current line
a61af66fc99e Initial load
duke
parents:
diff changeset
48 int _newlines; // number of '\n' output so far
a61af66fc99e Initial load
duke
parents:
diff changeset
49 julong _precount; // number of chars output, less _position
a61af66fc99e Initial load
duke
parents:
diff changeset
50 TimeStamp _stamp; // for time stamps
a61af66fc99e Initial load
duke
parents:
diff changeset
51
a61af66fc99e Initial load
duke
parents:
diff changeset
52 void update_position(const char* s, size_t len);
a61af66fc99e Initial load
duke
parents:
diff changeset
53 static const char* do_vsnprintf(char* buffer, size_t buflen,
a61af66fc99e Initial load
duke
parents:
diff changeset
54 const char* format, va_list ap,
a61af66fc99e Initial load
duke
parents:
diff changeset
55 bool add_cr,
a61af66fc99e Initial load
duke
parents:
diff changeset
56 size_t& result_len);
a61af66fc99e Initial load
duke
parents:
diff changeset
57
a61af66fc99e Initial load
duke
parents:
diff changeset
58 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
59 // creation
a61af66fc99e Initial load
duke
parents:
diff changeset
60 outputStream(int width = 80);
a61af66fc99e Initial load
duke
parents:
diff changeset
61 outputStream(int width, bool has_time_stamps);
a61af66fc99e Initial load
duke
parents:
diff changeset
62
a61af66fc99e Initial load
duke
parents:
diff changeset
63 // indentation
6605
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 3767
diff changeset
64 outputStream& indent();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
65 void inc() { _indentation++; };
a61af66fc99e Initial load
duke
parents:
diff changeset
66 void dec() { _indentation--; };
6605
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 3767
diff changeset
67 void inc(int n) { _indentation += n; };
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 3767
diff changeset
68 void dec(int n) { _indentation -= n; };
0
a61af66fc99e Initial load
duke
parents:
diff changeset
69 int indentation() const { return _indentation; }
a61af66fc99e Initial load
duke
parents:
diff changeset
70 void set_indentation(int i) { _indentation = i; }
a61af66fc99e Initial load
duke
parents:
diff changeset
71 void fill_to(int col);
100
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents: 0
diff changeset
72 void move_to(int col, int slop = 6, int min_space = 2);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
73
a61af66fc99e Initial load
duke
parents:
diff changeset
74 // sizing
a61af66fc99e Initial load
duke
parents:
diff changeset
75 int width() const { return _width; }
a61af66fc99e Initial load
duke
parents:
diff changeset
76 int position() const { return _position; }
a61af66fc99e Initial load
duke
parents:
diff changeset
77 int newlines() const { return _newlines; }
a61af66fc99e Initial load
duke
parents:
diff changeset
78 julong count() const { return _precount + _position; }
a61af66fc99e Initial load
duke
parents:
diff changeset
79 void set_count(julong count) { _precount = count - _position; }
a61af66fc99e Initial load
duke
parents:
diff changeset
80 void set_position(int pos) { _position = pos; }
a61af66fc99e Initial load
duke
parents:
diff changeset
81
a61af66fc99e Initial load
duke
parents:
diff changeset
82 // printing
a61af66fc99e Initial load
duke
parents:
diff changeset
83 void print(const char* format, ...);
a61af66fc99e Initial load
duke
parents:
diff changeset
84 void print_cr(const char* format, ...);
a61af66fc99e Initial load
duke
parents:
diff changeset
85 void vprint(const char *format, va_list argptr);
a61af66fc99e Initial load
duke
parents:
diff changeset
86 void vprint_cr(const char* format, va_list argptr);
a61af66fc99e Initial load
duke
parents:
diff changeset
87 void print_raw(const char* str) { write(str, strlen(str)); }
a61af66fc99e Initial load
duke
parents:
diff changeset
88 void print_raw(const char* str, int len) { write(str, len); }
a61af66fc99e Initial load
duke
parents:
diff changeset
89 void print_raw_cr(const char* str) { write(str, strlen(str)); cr(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
90 void print_raw_cr(const char* str, int len){ write(str, len); cr(); }
6605
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 3767
diff changeset
91 void print_data(void* data, size_t len, bool with_ascii);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
92 void put(char ch);
100
c7c777385a15 6667042: PrintAssembly option does not work without special plugin
jrose
parents: 0
diff changeset
93 void sp(int count = 1);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
94 void cr();
a61af66fc99e Initial load
duke
parents:
diff changeset
95 void bol() { if (_position > 0) cr(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
96
a61af66fc99e Initial load
duke
parents:
diff changeset
97 // Time stamp
a61af66fc99e Initial load
duke
parents:
diff changeset
98 TimeStamp& time_stamp() { return _stamp; }
a61af66fc99e Initial load
duke
parents:
diff changeset
99 void stamp();
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 100
diff changeset
100 void stamp(bool guard, const char* prefix, const char* suffix);
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 100
diff changeset
101 void stamp(bool guard) {
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 100
diff changeset
102 stamp(guard, "", ": ");
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents: 100
diff changeset
103 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
104 // Date stamp
a61af66fc99e Initial load
duke
parents:
diff changeset
105 void date_stamp(bool guard, const char* prefix, const char* suffix);
a61af66fc99e Initial load
duke
parents:
diff changeset
106 // A simplified call that includes a suffix of ": "
a61af66fc99e Initial load
duke
parents:
diff changeset
107 void date_stamp(bool guard) {
a61af66fc99e Initial load
duke
parents:
diff changeset
108 date_stamp(guard, "", ": ");
a61af66fc99e Initial load
duke
parents:
diff changeset
109 }
a61af66fc99e Initial load
duke
parents:
diff changeset
110
a61af66fc99e Initial load
duke
parents:
diff changeset
111 // portable printing of 64 bit integers
a61af66fc99e Initial load
duke
parents:
diff changeset
112 void print_jlong(jlong value);
a61af66fc99e Initial load
duke
parents:
diff changeset
113 void print_julong(julong value);
a61af66fc99e Initial load
duke
parents:
diff changeset
114
a61af66fc99e Initial load
duke
parents:
diff changeset
115 // flushing
a61af66fc99e Initial load
duke
parents:
diff changeset
116 virtual void flush() {}
a61af66fc99e Initial load
duke
parents:
diff changeset
117 virtual void write(const char* str, size_t len) = 0;
3767
2a241e764894 6941923: RFE: Handling large log files produced by long running Java Applications
minqi
parents: 2426
diff changeset
118 virtual void rotate_log() {} // GC log rotation
2a241e764894 6941923: RFE: Handling large log files produced by long running Java Applications
minqi
parents: 2426
diff changeset
119 virtual ~outputStream() {} // close properly on deletion
0
a61af66fc99e Initial load
duke
parents:
diff changeset
120
a61af66fc99e Initial load
duke
parents:
diff changeset
121 void dec_cr() { dec(); cr(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
122 void inc_cr() { inc(); cr(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
123 };
a61af66fc99e Initial load
duke
parents:
diff changeset
124
a61af66fc99e Initial load
duke
parents:
diff changeset
125 // standard output
3767
2a241e764894 6941923: RFE: Handling large log files produced by long running Java Applications
minqi
parents: 2426
diff changeset
126 // ANSI C++ name collision
0
a61af66fc99e Initial load
duke
parents:
diff changeset
127 extern outputStream* tty; // tty output
a61af66fc99e Initial load
duke
parents:
diff changeset
128 extern outputStream* gclog_or_tty; // stream for gc log if -Xloggc:<f>, or tty
a61af66fc99e Initial load
duke
parents:
diff changeset
129
6605
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 3767
diff changeset
130 class streamIndentor : public StackObj {
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 3767
diff changeset
131 private:
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 3767
diff changeset
132 outputStream* _str;
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 3767
diff changeset
133 int _amount;
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 3767
diff changeset
134
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 3767
diff changeset
135 public:
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 3767
diff changeset
136 streamIndentor(outputStream* str, int amt = 2) : _str(str), _amount(amt) {
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 3767
diff changeset
137 _str->inc(_amount);
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 3767
diff changeset
138 }
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 3767
diff changeset
139 ~streamIndentor() { _str->dec(_amount); }
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 3767
diff changeset
140 };
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 3767
diff changeset
141
4ee06e614636 7116786: RFE: Detailed information on VerifyErrors
kamg
parents: 3767
diff changeset
142
0
a61af66fc99e Initial load
duke
parents:
diff changeset
143 // advisory locking for the shared tty stream:
a61af66fc99e Initial load
duke
parents:
diff changeset
144 class ttyLocker: StackObj {
2263
5841dc1964f0 7021531: lock ordering problems after fix for 6354181
never
parents: 2199
diff changeset
145 friend class ttyUnlocker;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
146 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
147 intx _holder;
a61af66fc99e Initial load
duke
parents:
diff changeset
148
a61af66fc99e Initial load
duke
parents:
diff changeset
149 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
150 static intx hold_tty(); // returns a "holder" token
a61af66fc99e Initial load
duke
parents:
diff changeset
151 static void release_tty(intx holder); // must witness same token
2263
5841dc1964f0 7021531: lock ordering problems after fix for 6354181
never
parents: 2199
diff changeset
152 static bool release_tty_if_locked(); // returns true if lock was released
0
a61af66fc99e Initial load
duke
parents:
diff changeset
153 static void break_tty_lock_for_safepoint(intx holder);
a61af66fc99e Initial load
duke
parents:
diff changeset
154
a61af66fc99e Initial load
duke
parents:
diff changeset
155 ttyLocker() { _holder = hold_tty(); }
a61af66fc99e Initial load
duke
parents:
diff changeset
156 ~ttyLocker() { release_tty(_holder); }
a61af66fc99e Initial load
duke
parents:
diff changeset
157 };
a61af66fc99e Initial load
duke
parents:
diff changeset
158
2263
5841dc1964f0 7021531: lock ordering problems after fix for 6354181
never
parents: 2199
diff changeset
159 // Release the tty lock if it's held and reacquire it if it was
5841dc1964f0 7021531: lock ordering problems after fix for 6354181
never
parents: 2199
diff changeset
160 // locked. Used to avoid lock ordering problems.
5841dc1964f0 7021531: lock ordering problems after fix for 6354181
never
parents: 2199
diff changeset
161 class ttyUnlocker: StackObj {
5841dc1964f0 7021531: lock ordering problems after fix for 6354181
never
parents: 2199
diff changeset
162 private:
5841dc1964f0 7021531: lock ordering problems after fix for 6354181
never
parents: 2199
diff changeset
163 bool _was_locked;
5841dc1964f0 7021531: lock ordering problems after fix for 6354181
never
parents: 2199
diff changeset
164 public:
5841dc1964f0 7021531: lock ordering problems after fix for 6354181
never
parents: 2199
diff changeset
165 ttyUnlocker() {
5841dc1964f0 7021531: lock ordering problems after fix for 6354181
never
parents: 2199
diff changeset
166 _was_locked = ttyLocker::release_tty_if_locked();
5841dc1964f0 7021531: lock ordering problems after fix for 6354181
never
parents: 2199
diff changeset
167 }
5841dc1964f0 7021531: lock ordering problems after fix for 6354181
never
parents: 2199
diff changeset
168 ~ttyUnlocker() {
5841dc1964f0 7021531: lock ordering problems after fix for 6354181
never
parents: 2199
diff changeset
169 if (_was_locked) {
5841dc1964f0 7021531: lock ordering problems after fix for 6354181
never
parents: 2199
diff changeset
170 ttyLocker::hold_tty();
5841dc1964f0 7021531: lock ordering problems after fix for 6354181
never
parents: 2199
diff changeset
171 }
5841dc1964f0 7021531: lock ordering problems after fix for 6354181
never
parents: 2199
diff changeset
172 }
5841dc1964f0 7021531: lock ordering problems after fix for 6354181
never
parents: 2199
diff changeset
173 };
5841dc1964f0 7021531: lock ordering problems after fix for 6354181
never
parents: 2199
diff changeset
174
0
a61af66fc99e Initial load
duke
parents:
diff changeset
175 // for writing to strings; buffer will expand automatically
a61af66fc99e Initial load
duke
parents:
diff changeset
176 class stringStream : public outputStream {
a61af66fc99e Initial load
duke
parents:
diff changeset
177 protected:
a61af66fc99e Initial load
duke
parents:
diff changeset
178 char* buffer;
a61af66fc99e Initial load
duke
parents:
diff changeset
179 size_t buffer_pos;
a61af66fc99e Initial load
duke
parents:
diff changeset
180 size_t buffer_length;
a61af66fc99e Initial load
duke
parents:
diff changeset
181 bool buffer_fixed;
11136
dbc0b5dc08f5 7143807: ResourceMark nesting problem in stringStream
fparain
parents: 10195
diff changeset
182 DEBUG_ONLY(ResourceMark* rm;)
0
a61af66fc99e Initial load
duke
parents:
diff changeset
183 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
184 stringStream(size_t initial_bufsize = 256);
a61af66fc99e Initial load
duke
parents:
diff changeset
185 stringStream(char* fixed_buffer, size_t fixed_buffer_size);
a61af66fc99e Initial load
duke
parents:
diff changeset
186 ~stringStream();
a61af66fc99e Initial load
duke
parents:
diff changeset
187 virtual void write(const char* c, size_t len);
a61af66fc99e Initial load
duke
parents:
diff changeset
188 size_t size() { return buffer_pos; }
a61af66fc99e Initial load
duke
parents:
diff changeset
189 const char* base() { return buffer; }
a61af66fc99e Initial load
duke
parents:
diff changeset
190 void reset() { buffer_pos = 0; _precount = 0; _position = 0; }
a61af66fc99e Initial load
duke
parents:
diff changeset
191 char* as_string();
a61af66fc99e Initial load
duke
parents:
diff changeset
192 };
a61af66fc99e Initial load
duke
parents:
diff changeset
193
a61af66fc99e Initial load
duke
parents:
diff changeset
194 class fileStream : public outputStream {
a61af66fc99e Initial load
duke
parents:
diff changeset
195 protected:
a61af66fc99e Initial load
duke
parents:
diff changeset
196 FILE* _file;
a61af66fc99e Initial load
duke
parents:
diff changeset
197 bool _need_close;
a61af66fc99e Initial load
duke
parents:
diff changeset
198 public:
3767
2a241e764894 6941923: RFE: Handling large log files produced by long running Java Applications
minqi
parents: 2426
diff changeset
199 fileStream() { _file = NULL; _need_close = false; }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
200 fileStream(const char* file_name);
2199
d8a72fbc4be7 7003401: Implement VM error-reporting functionality on erroneous termination
kamg
parents: 1972
diff changeset
201 fileStream(const char* file_name, const char* opentype);
10195
e12c9b3740db 8012260: ciReplay: Include PID into the name of replay data file
vlivanov
parents: 8108
diff changeset
202 fileStream(FILE* file, bool need_close = false) { _file = file; _need_close = need_close; }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
203 ~fileStream();
a61af66fc99e Initial load
duke
parents:
diff changeset
204 bool is_open() const { return _file != NULL; }
2199
d8a72fbc4be7 7003401: Implement VM error-reporting functionality on erroneous termination
kamg
parents: 1972
diff changeset
205 void set_need_close(bool b) { _need_close = b;}
0
a61af66fc99e Initial load
duke
parents:
diff changeset
206 virtual void write(const char* c, size_t len);
2199
d8a72fbc4be7 7003401: Implement VM error-reporting functionality on erroneous termination
kamg
parents: 1972
diff changeset
207 size_t read(void *data, size_t size, size_t count) { return ::fread(data, size, count, _file); }
d8a72fbc4be7 7003401: Implement VM error-reporting functionality on erroneous termination
kamg
parents: 1972
diff changeset
208 char* readln(char *data, int count);
d8a72fbc4be7 7003401: Implement VM error-reporting functionality on erroneous termination
kamg
parents: 1972
diff changeset
209 int eof() { return feof(_file); }
d8a72fbc4be7 7003401: Implement VM error-reporting functionality on erroneous termination
kamg
parents: 1972
diff changeset
210 long fileSize();
d8a72fbc4be7 7003401: Implement VM error-reporting functionality on erroneous termination
kamg
parents: 1972
diff changeset
211 void rewind() { ::rewind(_file); }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
212 void flush();
a61af66fc99e Initial load
duke
parents:
diff changeset
213 };
a61af66fc99e Initial load
duke
parents:
diff changeset
214
a61af66fc99e Initial load
duke
parents:
diff changeset
215 // unlike fileStream, fdStream does unbuffered I/O by calling
a61af66fc99e Initial load
duke
parents:
diff changeset
216 // open() and write() directly. It is async-safe, but output
a61af66fc99e Initial load
duke
parents:
diff changeset
217 // from multiple thread may be mixed together. Used by fatal
a61af66fc99e Initial load
duke
parents:
diff changeset
218 // error handler.
a61af66fc99e Initial load
duke
parents:
diff changeset
219 class fdStream : public outputStream {
a61af66fc99e Initial load
duke
parents:
diff changeset
220 protected:
a61af66fc99e Initial load
duke
parents:
diff changeset
221 int _fd;
a61af66fc99e Initial load
duke
parents:
diff changeset
222 bool _need_close;
a61af66fc99e Initial load
duke
parents:
diff changeset
223 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
224 fdStream(const char* file_name);
a61af66fc99e Initial load
duke
parents:
diff changeset
225 fdStream(int fd = -1) { _fd = fd; _need_close = false; }
a61af66fc99e Initial load
duke
parents:
diff changeset
226 ~fdStream();
a61af66fc99e Initial load
duke
parents:
diff changeset
227 bool is_open() const { return _fd != -1; }
a61af66fc99e Initial load
duke
parents:
diff changeset
228 void set_fd(int fd) { _fd = fd; _need_close = false; }
a61af66fc99e Initial load
duke
parents:
diff changeset
229 int fd() const { return _fd; }
a61af66fc99e Initial load
duke
parents:
diff changeset
230 virtual void write(const char* c, size_t len);
a61af66fc99e Initial load
duke
parents:
diff changeset
231 void flush() {};
a61af66fc99e Initial load
duke
parents:
diff changeset
232 };
a61af66fc99e Initial load
duke
parents:
diff changeset
233
12215
621eda7235d2 7164841: Improvements to the GC log file rotation
minqi
parents: 11136
diff changeset
234 class gcLogFileStream : public fileStream {
3767
2a241e764894 6941923: RFE: Handling large log files produced by long running Java Applications
minqi
parents: 2426
diff changeset
235 protected:
12215
621eda7235d2 7164841: Improvements to the GC log file rotation
minqi
parents: 11136
diff changeset
236 const char* _file_name;
8108
0598674c0056 8008314: Unimplemented() Atomic::load breaks the applications
jwilhelm
parents: 6605
diff changeset
237 jlong _bytes_written;
12215
621eda7235d2 7164841: Improvements to the GC log file rotation
minqi
parents: 11136
diff changeset
238 uintx _cur_file_num; // current logfile rotation number, from 0 to NumberOfGCLogFiles-1
3767
2a241e764894 6941923: RFE: Handling large log files produced by long running Java Applications
minqi
parents: 2426
diff changeset
239 public:
12215
621eda7235d2 7164841: Improvements to the GC log file rotation
minqi
parents: 11136
diff changeset
240 gcLogFileStream(const char* file_name);
621eda7235d2 7164841: Improvements to the GC log file rotation
minqi
parents: 11136
diff changeset
241 ~gcLogFileStream();
3767
2a241e764894 6941923: RFE: Handling large log files produced by long running Java Applications
minqi
parents: 2426
diff changeset
242 virtual void write(const char* c, size_t len);
2a241e764894 6941923: RFE: Handling large log files produced by long running Java Applications
minqi
parents: 2426
diff changeset
243 virtual void rotate_log();
12215
621eda7235d2 7164841: Improvements to the GC log file rotation
minqi
parents: 11136
diff changeset
244 void dump_loggc_header();
3767
2a241e764894 6941923: RFE: Handling large log files produced by long running Java Applications
minqi
parents: 2426
diff changeset
245 };
2a241e764894 6941923: RFE: Handling large log files produced by long running Java Applications
minqi
parents: 2426
diff changeset
246
12215
621eda7235d2 7164841: Improvements to the GC log file rotation
minqi
parents: 11136
diff changeset
247 #ifndef PRODUCT
621eda7235d2 7164841: Improvements to the GC log file rotation
minqi
parents: 11136
diff changeset
248 // unit test for checking -Xloggc:<filename> parsing result
621eda7235d2 7164841: Improvements to the GC log file rotation
minqi
parents: 11136
diff changeset
249 void test_loggc_filename();
621eda7235d2 7164841: Improvements to the GC log file rotation
minqi
parents: 11136
diff changeset
250 #endif
621eda7235d2 7164841: Improvements to the GC log file rotation
minqi
parents: 11136
diff changeset
251
0
a61af66fc99e Initial load
duke
parents:
diff changeset
252 void ostream_init();
a61af66fc99e Initial load
duke
parents:
diff changeset
253 void ostream_init_log();
a61af66fc99e Initial load
duke
parents:
diff changeset
254 void ostream_exit();
a61af66fc99e Initial load
duke
parents:
diff changeset
255 void ostream_abort();
a61af66fc99e Initial load
duke
parents:
diff changeset
256
a61af66fc99e Initial load
duke
parents:
diff changeset
257 // staticBufferStream uses a user-supplied buffer for all formatting.
a61af66fc99e Initial load
duke
parents:
diff changeset
258 // Used for safe formatting during fatal error handling. Not MT safe.
a61af66fc99e Initial load
duke
parents:
diff changeset
259 // Do not share the stream between multiple threads.
a61af66fc99e Initial load
duke
parents:
diff changeset
260 class staticBufferStream : public outputStream {
a61af66fc99e Initial load
duke
parents:
diff changeset
261 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
262 char* _buffer;
a61af66fc99e Initial load
duke
parents:
diff changeset
263 size_t _buflen;
a61af66fc99e Initial load
duke
parents:
diff changeset
264 outputStream* _outer_stream;
a61af66fc99e Initial load
duke
parents:
diff changeset
265 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
266 staticBufferStream(char* buffer, size_t buflen,
a61af66fc99e Initial load
duke
parents:
diff changeset
267 outputStream *outer_stream);
a61af66fc99e Initial load
duke
parents:
diff changeset
268 ~staticBufferStream() {};
a61af66fc99e Initial load
duke
parents:
diff changeset
269 virtual void write(const char* c, size_t len);
a61af66fc99e Initial load
duke
parents:
diff changeset
270 void flush();
a61af66fc99e Initial load
duke
parents:
diff changeset
271 void print(const char* format, ...);
a61af66fc99e Initial load
duke
parents:
diff changeset
272 void print_cr(const char* format, ...);
a61af66fc99e Initial load
duke
parents:
diff changeset
273 void vprint(const char *format, va_list argptr);
a61af66fc99e Initial load
duke
parents:
diff changeset
274 void vprint_cr(const char* format, va_list argptr);
a61af66fc99e Initial load
duke
parents:
diff changeset
275 };
a61af66fc99e Initial load
duke
parents:
diff changeset
276
a61af66fc99e Initial load
duke
parents:
diff changeset
277 // In the non-fixed buffer case an underlying buffer will be created and
a61af66fc99e Initial load
duke
parents:
diff changeset
278 // managed in C heap. Not MT-safe.
a61af66fc99e Initial load
duke
parents:
diff changeset
279 class bufferedStream : public outputStream {
a61af66fc99e Initial load
duke
parents:
diff changeset
280 protected:
a61af66fc99e Initial load
duke
parents:
diff changeset
281 char* buffer;
a61af66fc99e Initial load
duke
parents:
diff changeset
282 size_t buffer_pos;
222
2a1a77d3458f 6718676: putback for 6604014 is incomplete
never
parents: 100
diff changeset
283 size_t buffer_max;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
284 size_t buffer_length;
a61af66fc99e Initial load
duke
parents:
diff changeset
285 bool buffer_fixed;
a61af66fc99e Initial load
duke
parents:
diff changeset
286 public:
222
2a1a77d3458f 6718676: putback for 6604014 is incomplete
never
parents: 100
diff changeset
287 bufferedStream(size_t initial_bufsize = 256, size_t bufmax = 1024*1024*10);
2a1a77d3458f 6718676: putback for 6604014 is incomplete
never
parents: 100
diff changeset
288 bufferedStream(char* fixed_buffer, size_t fixed_buffer_size, size_t bufmax = 1024*1024*10);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
289 ~bufferedStream();
a61af66fc99e Initial load
duke
parents:
diff changeset
290 virtual void write(const char* c, size_t len);
a61af66fc99e Initial load
duke
parents:
diff changeset
291 size_t size() { return buffer_pos; }
a61af66fc99e Initial load
duke
parents:
diff changeset
292 const char* base() { return buffer; }
a61af66fc99e Initial load
duke
parents:
diff changeset
293 void reset() { buffer_pos = 0; _precount = 0; _position = 0; }
a61af66fc99e Initial load
duke
parents:
diff changeset
294 char* as_string();
a61af66fc99e Initial load
duke
parents:
diff changeset
295 };
a61af66fc99e Initial load
duke
parents:
diff changeset
296
a61af66fc99e Initial load
duke
parents:
diff changeset
297 #define O_BUFLEN 2000 // max size of output of individual print() methods
a61af66fc99e Initial load
duke
parents:
diff changeset
298
a61af66fc99e Initial load
duke
parents:
diff changeset
299 #ifndef PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
300
a61af66fc99e Initial load
duke
parents:
diff changeset
301 class networkStream : public bufferedStream {
a61af66fc99e Initial load
duke
parents:
diff changeset
302
a61af66fc99e Initial load
duke
parents:
diff changeset
303 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
304 int _socket;
a61af66fc99e Initial load
duke
parents:
diff changeset
305
a61af66fc99e Initial load
duke
parents:
diff changeset
306 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
307 networkStream();
a61af66fc99e Initial load
duke
parents:
diff changeset
308 ~networkStream();
a61af66fc99e Initial load
duke
parents:
diff changeset
309
a61af66fc99e Initial load
duke
parents:
diff changeset
310 bool connect(const char *host, short port);
a61af66fc99e Initial load
duke
parents:
diff changeset
311 bool is_open() const { return _socket != -1; }
a61af66fc99e Initial load
duke
parents:
diff changeset
312 int read(char *buf, size_t len);
a61af66fc99e Initial load
duke
parents:
diff changeset
313 void close();
a61af66fc99e Initial load
duke
parents:
diff changeset
314 virtual void flush();
a61af66fc99e Initial load
duke
parents:
diff changeset
315 };
a61af66fc99e Initial load
duke
parents:
diff changeset
316
a61af66fc99e Initial load
duke
parents:
diff changeset
317 #endif
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
318
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
319 #endif // SHARE_VM_UTILITIES_OSTREAM_HPP