src/share/vm/utilities/ostream.hpp
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File 7164841 Sdiff src/share/vm/utilities

src/share/vm/utilities/ostream.hpp

Print this page
7164841: Improvements to the GC log file rotation


 193 
 194 class fileStream : public outputStream {
 195  protected:
 196   FILE* _file;
 197   bool  _need_close;
 198  public:
 199   fileStream() { _file = NULL; _need_close = false; }
 200   fileStream(const char* file_name);
 201   fileStream(const char* file_name, const char* opentype);
 202   fileStream(FILE* file, bool need_close = false) { _file = file; _need_close = need_close; }
 203   ~fileStream();
 204   bool is_open() const { return _file != NULL; }
 205   void set_need_close(bool b) { _need_close = b;}
 206   virtual void write(const char* c, size_t len);
 207   size_t read(void *data, size_t size, size_t count) { return ::fread(data, size, count, _file); }
 208   char* readln(char *data, int count);
 209   int eof() { return feof(_file); }
 210   long fileSize();
 211   void rewind() { ::rewind(_file); }
 212   void flush();

 213 };
 214 
 215 // unlike fileStream, fdStream does unbuffered I/O by calling
 216 // open() and write() directly. It is async-safe, but output
 217 // from multiple thread may be mixed together. Used by fatal
 218 // error handler.
 219 class fdStream : public outputStream {
 220  protected:
 221   int  _fd;
 222   bool _need_close;
 223  public:
 224   fdStream(const char* file_name);
 225   fdStream(int fd = -1) { _fd = fd; _need_close = false; }
 226   ~fdStream();
 227   bool is_open() const { return _fd != -1; }
 228   void set_fd(int fd) { _fd = fd; _need_close = false; }
 229   int fd() const { return _fd; }
 230   virtual void write(const char* c, size_t len);
 231   void flush() {};
 232 };
 233 
 234 class rotatingFileStream : public fileStream {
 235  protected:
 236   char*  _file_name;
 237   jlong  _bytes_written;
 238   uintx  _cur_file_num;             // current logfile rotation number, from 0 to MaxGCLogFileNumbers-1
 239  public:
 240   rotatingFileStream(const char* file_name);
 241   rotatingFileStream(const char* file_name, const char* opentype);
 242   rotatingFileStream(FILE* file) : fileStream(file) {}
 243   ~rotatingFileStream();
 244   virtual void write(const char* c, size_t len);
 245   virtual void rotate_log();
 246 };
 247 
 248 void ostream_init();
 249 void ostream_init_log();
 250 void ostream_exit();
 251 void ostream_abort();
 252 
 253 // staticBufferStream uses a user-supplied buffer for all formatting.
 254 // Used for safe formatting during fatal error handling.  Not MT safe.
 255 // Do not share the stream between multiple threads.
 256 class staticBufferStream : public outputStream {
 257  private:
 258   char* _buffer;
 259   size_t _buflen;
 260   outputStream* _outer_stream;
 261  public:
 262   staticBufferStream(char* buffer, size_t buflen,




 193 
 194 class fileStream : public outputStream {
 195  protected:
 196   FILE* _file;
 197   bool  _need_close;
 198  public:
 199   fileStream() { _file = NULL; _need_close = false; }
 200   fileStream(const char* file_name);
 201   fileStream(const char* file_name, const char* opentype);
 202   fileStream(FILE* file, bool need_close = false) { _file = file; _need_close = need_close; }
 203   ~fileStream();
 204   bool is_open() const { return _file != NULL; }
 205   void set_need_close(bool b) { _need_close = b;}
 206   virtual void write(const char* c, size_t len);
 207   size_t read(void *data, size_t size, size_t count) { return ::fread(data, size, count, _file); }
 208   char* readln(char *data, int count);
 209   int eof() { return feof(_file); }
 210   long fileSize();
 211   void rewind() { ::rewind(_file); }
 212   void flush();
 213   void dump_loggc_header();
 214 };
 215 
 216 // unlike fileStream, fdStream does unbuffered I/O by calling
 217 // open() and write() directly. It is async-safe, but output
 218 // from multiple thread may be mixed together. Used by fatal
 219 // error handler.
 220 class fdStream : public outputStream {
 221  protected:
 222   int  _fd;
 223   bool _need_close;
 224  public:
 225   fdStream(const char* file_name);
 226   fdStream(int fd = -1) { _fd = fd; _need_close = false; }
 227   ~fdStream();
 228   bool is_open() const { return _fd != -1; }
 229   void set_fd(int fd) { _fd = fd; _need_close = false; }
 230   int fd() const { return _fd; }
 231   virtual void write(const char* c, size_t len);
 232   void flush() {};
 233 };
 234 
 235 class rotatingFileStream : public fileStream {
 236  protected:
 237   char*  _file_name;
 238   jlong  _bytes_written;
 239   uintx  _cur_file_num;             // current logfile rotation number, from 0 to NumberOfGCLogFiles-1
 240  public:
 241   rotatingFileStream(const char* file_name);


 242   ~rotatingFileStream();
 243   virtual void write(const char* c, size_t len);
 244   virtual void rotate_log();
 245 };
 246 
 247 void ostream_init();
 248 void ostream_init_log();
 249 void ostream_exit();
 250 void ostream_abort();
 251 
 252 // staticBufferStream uses a user-supplied buffer for all formatting.
 253 // Used for safe formatting during fatal error handling.  Not MT safe.
 254 // Do not share the stream between multiple threads.
 255 class staticBufferStream : public outputStream {
 256  private:
 257   char* _buffer;
 258   size_t _buflen;
 259   outputStream* _outer_stream;
 260  public:
 261   staticBufferStream(char* buffer, size_t buflen,


src/share/vm/utilities/ostream.hpp
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File