< prev index next >

src/share/vm/logging/logStream.hpp

Print this page
rev 13105 : imported patch 8181917-refactor-ul-logstream-alt1-callsite-changes
rev 13106 : imported patch 8181917-refactor-ul-logstream-alt1-api-changes
rev 13107 : imported patch 8181917-refactor-ul-logstream-alt1-logstream-optimization

@@ -30,13 +30,35 @@
 #include "memory/resourceArea.hpp"
 #include "utilities/ostream.hpp"
 
 
 class LogStream : public outputStream {
-  bufferedStream  _current_line;
+
+  // Helper class, maintains the line buffer. For small line lengths,
+  // we avoid malloc and use a fixed sized member char array. If LogStream
+  // is allocated on the stack, this means small lines are assembled
+  // directly on the stack.
+  class LineBuffer {
+    char _smallbuf[128];
+    char* _buf;
+    size_t _cap;
+    size_t _pos;
+    void ensure_cap(size_t cap);
+  public:
+    LineBuffer();
+    ~LineBuffer();
+    const char* ptr() const { return _buf; }
+    void append(const char* s, size_t len);
+    void reset();
+  }; 
+  LineBuffer  _current_line;
   LogTargetHandle _log_handle;
 
+  // Prevent operator new for LogStream.
+//  static void* operator new (size_t);
+//   static void* operator new[] (size_t);
+  
 public:
   // Constructor to support creation from a LogTarget instance.
   //
   // LogTarget(Debug, gc) log;
   // LogStreamBase(log) stream;

@@ -63,14 +85,10 @@
   // Constructor to support creation from a log level and tagset.
   //
   // LogStreamBase(level, tageset);
   LogStream(LogLevelType level, LogTagSet* tagset) : _log_handle(level, tagset) {}
 
-  ~LogStream() {
-    guarantee(_current_line.size() == 0, "Buffer not flushed. Missing call to print_cr()?");
-  }
-
 public:
   void write(const char* s, size_t len);
 };
 
 typedef LogStream LogStreamNoResourceMark;
< prev index next >