218
219 // unlike fileStream, fdStream does unbuffered I/O by calling
220 // open() and write() directly. It is async-safe, but output
221 // from multiple thread may be mixed together. Used by fatal
222 // error handler.
223 class fdStream : public outputStream {
224 protected:
225 int _fd;
226 bool _need_close;
227 public:
228 fdStream(const char* file_name);
229 fdStream(int fd = -1) { _fd = fd; _need_close = false; }
230 ~fdStream();
231 bool is_open() const { return _fd != -1; }
232 void set_fd(int fd) { _fd = fd; _need_close = false; }
233 int fd() const { return _fd; }
234 virtual void write(const char* c, size_t len);
235 void flush() {};
236 };
237
238 class gcLogFileStream : public fileStream {
239 protected:
240 const char* _file_name;
241 jlong _bytes_written;
242 uintx _cur_file_num; // current logfile rotation number, from 0 to NumberOfGCLogFiles-1
243 public:
244 gcLogFileStream(const char* file_name);
245 ~gcLogFileStream();
246 virtual void write(const char* c, size_t len);
247 virtual void rotate_log(bool force, outputStream* out = NULL);
248 void dump_loggc_header();
249
250 /* If "force" sets true, force log file rotation from outside JVM */
251 bool should_rotate(bool force) {
252 return force ||
253 ((GCLogFileSize != 0) && (_bytes_written >= (jlong)GCLogFileSize));
254 }
255 };
256
257 #ifndef PRODUCT
|
218
219 // unlike fileStream, fdStream does unbuffered I/O by calling
220 // open() and write() directly. It is async-safe, but output
221 // from multiple thread may be mixed together. Used by fatal
222 // error handler.
223 class fdStream : public outputStream {
224 protected:
225 int _fd;
226 bool _need_close;
227 public:
228 fdStream(const char* file_name);
229 fdStream(int fd = -1) { _fd = fd; _need_close = false; }
230 ~fdStream();
231 bool is_open() const { return _fd != -1; }
232 void set_fd(int fd) { _fd = fd; _need_close = false; }
233 int fd() const { return _fd; }
234 virtual void write(const char* c, size_t len);
235 void flush() {};
236 };
237
238 class logStream : public outputStream {
239 private:
240 stringStream _current_line;
241 void (*_log_func)(const char* fmt, ...);
242 public:
243 void write(const char* s, size_t len);
244 logStream(void (*log_func)(const char* fmt, ...)) : _log_func(log_func) {}
245 ~logStream() {
246 guarantee(_current_line.size() == 0, "Buffer not flushed. Missing call to print_cr()?");
247 }
248 };
249
250 class gcLogFileStream : public fileStream {
251 protected:
252 const char* _file_name;
253 jlong _bytes_written;
254 uintx _cur_file_num; // current logfile rotation number, from 0 to NumberOfGCLogFiles-1
255 public:
256 gcLogFileStream(const char* file_name);
257 ~gcLogFileStream();
258 virtual void write(const char* c, size_t len);
259 virtual void rotate_log(bool force, outputStream* out = NULL);
260 void dump_loggc_header();
261
262 /* If "force" sets true, force log file rotation from outside JVM */
263 bool should_rotate(bool force) {
264 return force ||
265 ((GCLogFileSize != 0) && (_bytes_written >= (jlong)GCLogFileSize));
266 }
267 };
268
269 #ifndef PRODUCT
|