--- old/src/share/vm/utilities/ostream.hpp 2020-01-27 23:21:10.000000000 -0800 +++ new/src/share/vm/utilities/ostream.hpp 2020-01-27 23:21:10.000000000 -0800 @@ -27,6 +27,7 @@ #include "memory/allocation.hpp" #include "runtime/timer.hpp" +#include "runtime/task.hpp" class GCId; DEBUG_ONLY(class ResourceMark;) @@ -235,16 +236,28 @@ void flush() {}; }; +class Mutex; +class GCLogEvent; + class gcLogFileStream : public fileStream { protected: const char* _file_name; jlong _bytes_written; uintx _cur_file_num; // current logfile rotation number, from 0 to NumberOfGCLogFiles-1 + private: + GCLogEvent* _reader; + GCLogEvent* _writer; + Mutex* _lock; + public: gcLogFileStream(const char* file_name); ~gcLogFileStream(); + // write asynchronously virtual void write(const char* c, size_t len); + // really write to file system. + void write_blocking(const char* c, size_t len); virtual void rotate_log(bool force, outputStream* out = NULL); + void flush_log(); void dump_loggc_header(); /* If "force" sets true, force log file rotation from outside JVM */ @@ -255,6 +268,22 @@ }; +class GCLogFlusher: public PeriodicTask { + gcLogFileStream * _ostream; + elapsedTimer _accumulatedTime; +public: + GCLogFlusher(int interval, gcLogFileStream* ostream):PeriodicTask(interval), _ostream(ostream) {} + + virtual void task() { + TraceTime t("GCLogFlusher", &_accumulatedTime, true, PrintGCLogFlushTime); + _ostream->flush_log(); + } + + elapsedTimer getAccumulatedTime() { + return _accumulatedTime; + } +}; + #ifndef PRODUCT // unit test for checking -Xloggc: parsing result void test_loggc_filename();