< 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


  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  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #ifndef SHARE_VM_LOGGING_LOGSTREAM_HPP
  26 #define SHARE_VM_LOGGING_LOGSTREAM_HPP
  27 
  28 #include "logging/log.hpp"
  29 #include "logging/logHandle.hpp"
  30 #include "memory/resourceArea.hpp"
  31 #include "utilities/ostream.hpp"
  32 
  33 
  34 class LogStream : public outputStream {
  35   bufferedStream  _current_line;


















  36   LogTargetHandle _log_handle;
  37 




  38 public:
  39   // Constructor to support creation from a LogTarget instance.
  40   //
  41   // LogTarget(Debug, gc) log;
  42   // LogStreamBase(log) stream;
  43   template <LogLevelType level, LogTagType T0, LogTagType T1, LogTagType T2, LogTagType T3, LogTagType T4, LogTagType GuardTag>
  44   LogStream(const LogTargetImpl<level, T0, T1, T2, T3, T4, GuardTag>& type_carrier) :
  45       _log_handle(level, &LogTagSetMapping<T0, T1, T2, T3, T4>::tagset()) {}
  46 
  47   // Constructor to support creation from typed (likely NULL) pointer. Mostly used by the logging framework.
  48   //
  49   // LogStreamBase stream(log.debug());
  50   //  or
  51   // LogStreamBase stream((LogTargetImpl<level, T0, T1, T2, T3, T4, GuardTag>*)NULL);
  52   template <LogLevelType level, LogTagType T0, LogTagType T1, LogTagType T2, LogTagType T3, LogTagType T4, LogTagType GuardTag>
  53   LogStream(const LogTargetImpl<level, T0, T1, T2, T3, T4, GuardTag>* type_carrier) :
  54       _log_handle(level, &LogTagSetMapping<T0, T1, T2, T3, T4>::tagset()) {}
  55 
  56   // Constructor to support creation from a LogTargetHandle.
  57   //
  58   // LogTarget(Debug, gc) log;
  59   // LogTargetHandle(log) handle;
  60   // LogStreamBase stream(handle);
  61   LogStream(LogTargetHandle handle) : _log_handle(handle) {}
  62 
  63   // Constructor to support creation from a log level and tagset.
  64   //
  65   // LogStreamBase(level, tageset);
  66   LogStream(LogLevelType level, LogTagSet* tagset) : _log_handle(level, tagset) {}
  67 
  68   ~LogStream() {
  69     guarantee(_current_line.size() == 0, "Buffer not flushed. Missing call to print_cr()?");
  70   }
  71 
  72 public:
  73   void write(const char* s, size_t len);
  74 };
  75 
  76 typedef LogStream LogStreamNoResourceMark;
  77 typedef LogStream LogStreamCHeap;
  78 
  79 // Support creation of a LogStream without having to provide a LogTarget pointer.
  80 #define LogStreamHandle(level, ...) LogStreamTemplate<LogLevel::level, LOG_TAGS(__VA_ARGS__)>
  81 
  82 template <LogLevelType level, LogTagType T0, LogTagType T1, LogTagType T2, LogTagType T3, LogTagType T4, LogTagType GuardTag>
  83 class LogStreamTemplate : public LogStream {
  84 public:
  85   LogStreamTemplate() : LogStream((LogTargetImpl<level, T0, T1, T2, T3, T4, GuardTag>*)NULL) {}
  86 };
  87 
  88 
  89 #endif // SHARE_VM_LOGGING_LOGSTREAM_HPP


  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  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #ifndef SHARE_VM_LOGGING_LOGSTREAM_HPP
  26 #define SHARE_VM_LOGGING_LOGSTREAM_HPP
  27 
  28 #include "logging/log.hpp"
  29 #include "logging/logHandle.hpp"
  30 #include "memory/resourceArea.hpp"
  31 #include "utilities/ostream.hpp"
  32 
  33 
  34 class LogStream : public outputStream {
  35 
  36   // Helper class, maintains the line buffer. For small line lengths,
  37   // we avoid malloc and use a fixed sized member char array. If LogStream
  38   // is allocated on the stack, this means small lines are assembled
  39   // directly on the stack.
  40   class LineBuffer {
  41     char _smallbuf[128];
  42     char* _buf;
  43     size_t _cap;
  44     size_t _pos;
  45     void ensure_cap(size_t cap);
  46   public:
  47     LineBuffer();
  48     ~LineBuffer();
  49     const char* ptr() const { return _buf; }
  50     void append(const char* s, size_t len);
  51     void reset();
  52   }; 
  53   LineBuffer  _current_line;
  54   LogTargetHandle _log_handle;
  55 
  56   // Prevent operator new for LogStream.
  57 //  static void* operator new (size_t);
  58 //   static void* operator new[] (size_t);
  59   
  60 public:
  61   // Constructor to support creation from a LogTarget instance.
  62   //
  63   // LogTarget(Debug, gc) log;
  64   // LogStreamBase(log) stream;
  65   template <LogLevelType level, LogTagType T0, LogTagType T1, LogTagType T2, LogTagType T3, LogTagType T4, LogTagType GuardTag>
  66   LogStream(const LogTargetImpl<level, T0, T1, T2, T3, T4, GuardTag>& type_carrier) :
  67       _log_handle(level, &LogTagSetMapping<T0, T1, T2, T3, T4>::tagset()) {}
  68 
  69   // Constructor to support creation from typed (likely NULL) pointer. Mostly used by the logging framework.
  70   //
  71   // LogStreamBase stream(log.debug());
  72   //  or
  73   // LogStreamBase stream((LogTargetImpl<level, T0, T1, T2, T3, T4, GuardTag>*)NULL);
  74   template <LogLevelType level, LogTagType T0, LogTagType T1, LogTagType T2, LogTagType T3, LogTagType T4, LogTagType GuardTag>
  75   LogStream(const LogTargetImpl<level, T0, T1, T2, T3, T4, GuardTag>* type_carrier) :
  76       _log_handle(level, &LogTagSetMapping<T0, T1, T2, T3, T4>::tagset()) {}
  77 
  78   // Constructor to support creation from a LogTargetHandle.
  79   //
  80   // LogTarget(Debug, gc) log;
  81   // LogTargetHandle(log) handle;
  82   // LogStreamBase stream(handle);
  83   LogStream(LogTargetHandle handle) : _log_handle(handle) {}
  84 
  85   // Constructor to support creation from a log level and tagset.
  86   //
  87   // LogStreamBase(level, tageset);
  88   LogStream(LogLevelType level, LogTagSet* tagset) : _log_handle(level, tagset) {}




  89 
  90 public:
  91   void write(const char* s, size_t len);
  92 };
  93 
  94 typedef LogStream LogStreamNoResourceMark;
  95 typedef LogStream LogStreamCHeap;
  96 
  97 // Support creation of a LogStream without having to provide a LogTarget pointer.
  98 #define LogStreamHandle(level, ...) LogStreamTemplate<LogLevel::level, LOG_TAGS(__VA_ARGS__)>
  99 
 100 template <LogLevelType level, LogTagType T0, LogTagType T1, LogTagType T2, LogTagType T3, LogTagType T4, LogTagType GuardTag>
 101 class LogStreamTemplate : public LogStream {
 102 public:
 103   LogStreamTemplate() : LogStream((LogTargetImpl<level, T0, T1, T2, T3, T4, GuardTag>*)NULL) {}
 104 };
 105 
 106 
 107 #endif // SHARE_VM_LOGGING_LOGSTREAM_HPP
< prev index next >