Mercurial > hg > truffle
annotate src/share/vm/utilities/ostream.hpp @ 3187:6ff76a1b8339
The benchmark tool should now print zero values to the csv file, if a benchmark fails
author | Josef Haider <josef.haider@khg.jku.at> |
---|---|
date | Thu, 07 Jul 2011 19:43:17 +0200 |
parents | 1d1603768966 |
children | 2a241e764894 |
rev | line source |
---|---|
0 | 1 /* |
2426
1d1603768966
7010070: Update all 2010 Oracle-changed OpenJDK files to have the proper copyright dates - second pass
trims
parents:
2263
diff
changeset
|
2 * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. |
0 | 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * | |
5 * This code is free software; you can redistribute it and/or modify it | |
6 * under the terms of the GNU General Public License version 2 only, as | |
7 * published by the Free Software Foundation. | |
8 * | |
9 * This code is distributed in the hope that it will be useful, but WITHOUT | |
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
12 * version 2 for more details (a copy is included in the LICENSE file that | |
13 * accompanied this code). | |
14 * | |
15 * You should have received a copy of the GNU General Public License version | |
16 * 2 along with this work; if not, write to the Free Software Foundation, | |
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
18 * | |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
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 | 22 * |
23 */ | |
24 | |
1972 | 25 #ifndef SHARE_VM_UTILITIES_OSTREAM_HPP |
26 #define SHARE_VM_UTILITIES_OSTREAM_HPP | |
27 | |
28 #include "memory/allocation.hpp" | |
29 #include "runtime/timer.hpp" | |
30 | |
0 | 31 // Output streams for printing |
32 // | |
33 // Printing guidelines: | |
34 // Where possible, please use tty->print() and tty->print_cr(). | |
35 // For product mode VM warnings use warning() which internally uses tty. | |
36 // In places where tty is not initialized yet or too much overhead, | |
37 // we may use jio_printf: | |
38 // jio_fprintf(defaultStream::output_stream(), "Message"); | |
39 // This allows for redirection via -XX:+DisplayVMOutputToStdout and | |
40 // -XX:+DisplayVMOutputToStderr | |
41 class outputStream : public ResourceObj { | |
42 protected: | |
43 int _indentation; // current indentation | |
44 int _width; // width of the page | |
45 int _position; // position on the current line | |
46 int _newlines; // number of '\n' output so far | |
47 julong _precount; // number of chars output, less _position | |
48 TimeStamp _stamp; // for time stamps | |
49 | |
50 void update_position(const char* s, size_t len); | |
51 static const char* do_vsnprintf(char* buffer, size_t buflen, | |
52 const char* format, va_list ap, | |
53 bool add_cr, | |
54 size_t& result_len); | |
55 | |
56 public: | |
57 // creation | |
58 outputStream(int width = 80); | |
59 outputStream(int width, bool has_time_stamps); | |
60 | |
61 // indentation | |
62 void indent(); | |
63 void inc() { _indentation++; }; | |
64 void dec() { _indentation--; }; | |
65 int indentation() const { return _indentation; } | |
66 void set_indentation(int i) { _indentation = i; } | |
67 void fill_to(int col); | |
100
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
0
diff
changeset
|
68 void move_to(int col, int slop = 6, int min_space = 2); |
0 | 69 |
70 // sizing | |
71 int width() const { return _width; } | |
72 int position() const { return _position; } | |
73 int newlines() const { return _newlines; } | |
74 julong count() const { return _precount + _position; } | |
75 void set_count(julong count) { _precount = count - _position; } | |
76 void set_position(int pos) { _position = pos; } | |
77 | |
78 // printing | |
79 void print(const char* format, ...); | |
80 void print_cr(const char* format, ...); | |
81 void vprint(const char *format, va_list argptr); | |
82 void vprint_cr(const char* format, va_list argptr); | |
83 void print_raw(const char* str) { write(str, strlen(str)); } | |
84 void print_raw(const char* str, int len) { write(str, len); } | |
85 void print_raw_cr(const char* str) { write(str, strlen(str)); cr(); } | |
86 void print_raw_cr(const char* str, int len){ write(str, len); cr(); } | |
87 void put(char ch); | |
100
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
0
diff
changeset
|
88 void sp(int count = 1); |
0 | 89 void cr(); |
90 void bol() { if (_position > 0) cr(); } | |
91 | |
92 // Time stamp | |
93 TimeStamp& time_stamp() { return _stamp; } | |
94 void stamp(); | |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
100
diff
changeset
|
95 void stamp(bool guard, const char* prefix, const char* suffix); |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
100
diff
changeset
|
96 void stamp(bool guard) { |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
100
diff
changeset
|
97 stamp(guard, "", ": "); |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
100
diff
changeset
|
98 } |
0 | 99 // Date stamp |
100 void date_stamp(bool guard, const char* prefix, const char* suffix); | |
101 // A simplified call that includes a suffix of ": " | |
102 void date_stamp(bool guard) { | |
103 date_stamp(guard, "", ": "); | |
104 } | |
105 | |
106 // portable printing of 64 bit integers | |
107 void print_jlong(jlong value); | |
108 void print_julong(julong value); | |
109 | |
110 // flushing | |
111 virtual void flush() {} | |
112 virtual void write(const char* str, size_t len) = 0; | |
113 virtual ~outputStream() {} // close properly on deletion | |
114 | |
115 void dec_cr() { dec(); cr(); } | |
116 void inc_cr() { inc(); cr(); } | |
117 }; | |
118 | |
119 // standard output | |
120 // ANSI C++ name collision | |
121 extern outputStream* tty; // tty output | |
122 extern outputStream* gclog_or_tty; // stream for gc log if -Xloggc:<f>, or tty | |
123 | |
124 // advisory locking for the shared tty stream: | |
125 class ttyLocker: StackObj { | |
2263
5841dc1964f0
7021531: lock ordering problems after fix for 6354181
never
parents:
2199
diff
changeset
|
126 friend class ttyUnlocker; |
0 | 127 private: |
128 intx _holder; | |
129 | |
130 public: | |
131 static intx hold_tty(); // returns a "holder" token | |
132 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
|
133 static bool release_tty_if_locked(); // returns true if lock was released |
0 | 134 static void break_tty_lock_for_safepoint(intx holder); |
135 | |
136 ttyLocker() { _holder = hold_tty(); } | |
137 ~ttyLocker() { release_tty(_holder); } | |
138 }; | |
139 | |
2263
5841dc1964f0
7021531: lock ordering problems after fix for 6354181
never
parents:
2199
diff
changeset
|
140 // 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
|
141 // locked. Used to avoid lock ordering problems. |
5841dc1964f0
7021531: lock ordering problems after fix for 6354181
never
parents:
2199
diff
changeset
|
142 class ttyUnlocker: StackObj { |
5841dc1964f0
7021531: lock ordering problems after fix for 6354181
never
parents:
2199
diff
changeset
|
143 private: |
5841dc1964f0
7021531: lock ordering problems after fix for 6354181
never
parents:
2199
diff
changeset
|
144 bool _was_locked; |
5841dc1964f0
7021531: lock ordering problems after fix for 6354181
never
parents:
2199
diff
changeset
|
145 public: |
5841dc1964f0
7021531: lock ordering problems after fix for 6354181
never
parents:
2199
diff
changeset
|
146 ttyUnlocker() { |
5841dc1964f0
7021531: lock ordering problems after fix for 6354181
never
parents:
2199
diff
changeset
|
147 _was_locked = ttyLocker::release_tty_if_locked(); |
5841dc1964f0
7021531: lock ordering problems after fix for 6354181
never
parents:
2199
diff
changeset
|
148 } |
5841dc1964f0
7021531: lock ordering problems after fix for 6354181
never
parents:
2199
diff
changeset
|
149 ~ttyUnlocker() { |
5841dc1964f0
7021531: lock ordering problems after fix for 6354181
never
parents:
2199
diff
changeset
|
150 if (_was_locked) { |
5841dc1964f0
7021531: lock ordering problems after fix for 6354181
never
parents:
2199
diff
changeset
|
151 ttyLocker::hold_tty(); |
5841dc1964f0
7021531: lock ordering problems after fix for 6354181
never
parents:
2199
diff
changeset
|
152 } |
5841dc1964f0
7021531: lock ordering problems after fix for 6354181
never
parents:
2199
diff
changeset
|
153 } |
5841dc1964f0
7021531: lock ordering problems after fix for 6354181
never
parents:
2199
diff
changeset
|
154 }; |
5841dc1964f0
7021531: lock ordering problems after fix for 6354181
never
parents:
2199
diff
changeset
|
155 |
0 | 156 // for writing to strings; buffer will expand automatically |
157 class stringStream : public outputStream { | |
158 protected: | |
159 char* buffer; | |
160 size_t buffer_pos; | |
161 size_t buffer_length; | |
162 bool buffer_fixed; | |
163 public: | |
164 stringStream(size_t initial_bufsize = 256); | |
165 stringStream(char* fixed_buffer, size_t fixed_buffer_size); | |
166 ~stringStream(); | |
167 virtual void write(const char* c, size_t len); | |
168 size_t size() { return buffer_pos; } | |
169 const char* base() { return buffer; } | |
170 void reset() { buffer_pos = 0; _precount = 0; _position = 0; } | |
171 char* as_string(); | |
172 }; | |
173 | |
174 class fileStream : public outputStream { | |
175 protected: | |
176 FILE* _file; | |
177 bool _need_close; | |
178 public: | |
179 fileStream(const char* file_name); | |
2199
d8a72fbc4be7
7003401: Implement VM error-reporting functionality on erroneous termination
kamg
parents:
1972
diff
changeset
|
180 fileStream(const char* file_name, const char* opentype); |
0 | 181 fileStream(FILE* file) { _file = file; _need_close = false; } |
182 ~fileStream(); | |
183 bool is_open() const { return _file != NULL; } | |
2199
d8a72fbc4be7
7003401: Implement VM error-reporting functionality on erroneous termination
kamg
parents:
1972
diff
changeset
|
184 void set_need_close(bool b) { _need_close = b;} |
0 | 185 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
|
186 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
|
187 char* readln(char *data, int count); |
d8a72fbc4be7
7003401: Implement VM error-reporting functionality on erroneous termination
kamg
parents:
1972
diff
changeset
|
188 int eof() { return feof(_file); } |
d8a72fbc4be7
7003401: Implement VM error-reporting functionality on erroneous termination
kamg
parents:
1972
diff
changeset
|
189 long fileSize(); |
d8a72fbc4be7
7003401: Implement VM error-reporting functionality on erroneous termination
kamg
parents:
1972
diff
changeset
|
190 void rewind() { ::rewind(_file); } |
0 | 191 void flush(); |
192 }; | |
193 | |
194 // unlike fileStream, fdStream does unbuffered I/O by calling | |
195 // open() and write() directly. It is async-safe, but output | |
196 // from multiple thread may be mixed together. Used by fatal | |
197 // error handler. | |
198 class fdStream : public outputStream { | |
199 protected: | |
200 int _fd; | |
201 bool _need_close; | |
202 public: | |
203 fdStream(const char* file_name); | |
204 fdStream(int fd = -1) { _fd = fd; _need_close = false; } | |
205 ~fdStream(); | |
206 bool is_open() const { return _fd != -1; } | |
207 void set_fd(int fd) { _fd = fd; _need_close = false; } | |
208 int fd() const { return _fd; } | |
209 virtual void write(const char* c, size_t len); | |
210 void flush() {}; | |
211 }; | |
212 | |
213 void ostream_init(); | |
214 void ostream_init_log(); | |
215 void ostream_exit(); | |
216 void ostream_abort(); | |
217 | |
218 // staticBufferStream uses a user-supplied buffer for all formatting. | |
219 // Used for safe formatting during fatal error handling. Not MT safe. | |
220 // Do not share the stream between multiple threads. | |
221 class staticBufferStream : public outputStream { | |
222 private: | |
223 char* _buffer; | |
224 size_t _buflen; | |
225 outputStream* _outer_stream; | |
226 public: | |
227 staticBufferStream(char* buffer, size_t buflen, | |
228 outputStream *outer_stream); | |
229 ~staticBufferStream() {}; | |
230 virtual void write(const char* c, size_t len); | |
231 void flush(); | |
232 void print(const char* format, ...); | |
233 void print_cr(const char* format, ...); | |
234 void vprint(const char *format, va_list argptr); | |
235 void vprint_cr(const char* format, va_list argptr); | |
236 }; | |
237 | |
238 // In the non-fixed buffer case an underlying buffer will be created and | |
239 // managed in C heap. Not MT-safe. | |
240 class bufferedStream : public outputStream { | |
241 protected: | |
242 char* buffer; | |
243 size_t buffer_pos; | |
222 | 244 size_t buffer_max; |
0 | 245 size_t buffer_length; |
246 bool buffer_fixed; | |
247 public: | |
222 | 248 bufferedStream(size_t initial_bufsize = 256, size_t bufmax = 1024*1024*10); |
249 bufferedStream(char* fixed_buffer, size_t fixed_buffer_size, size_t bufmax = 1024*1024*10); | |
0 | 250 ~bufferedStream(); |
251 virtual void write(const char* c, size_t len); | |
252 size_t size() { return buffer_pos; } | |
253 const char* base() { return buffer; } | |
254 void reset() { buffer_pos = 0; _precount = 0; _position = 0; } | |
255 char* as_string(); | |
256 }; | |
257 | |
258 #define O_BUFLEN 2000 // max size of output of individual print() methods | |
259 | |
260 #ifndef PRODUCT | |
261 | |
262 class networkStream : public bufferedStream { | |
263 | |
264 private: | |
265 int _socket; | |
266 | |
267 public: | |
268 networkStream(); | |
269 ~networkStream(); | |
270 | |
271 bool connect(const char *host, short port); | |
272 bool is_open() const { return _socket != -1; } | |
273 int read(char *buf, size_t len); | |
274 void close(); | |
275 virtual void flush(); | |
276 }; | |
277 | |
278 #endif | |
1972 | 279 |
280 #endif // SHARE_VM_UTILITIES_OSTREAM_HPP |