31 #include "utilities/ostream.hpp"
32
33
34 class LogStream : public outputStream {
35 friend class LogStreamTest_TestLineBufferAllocation_test_vm_Test; // see test/native/logging/test_logStream.cpp
36 friend class LogStreamTest_TestLineBufferAllocationCap_test_vm_Test; // see test/native/logging/test_logStream.cpp
37
38 // Helper class, maintains the line buffer. For small line lengths,
39 // we avoid malloc and use a fixed sized member char array. If LogStream
40 // is allocated on the stack, this means small lines are assembled
41 // directly on the stack.
42 class LineBuffer {
43 char _smallbuf[64];
44 char* _buf;
45 size_t _cap;
46 size_t _pos;
47 void try_ensure_cap(size_t cap);
48 public:
49 LineBuffer();
50 ~LineBuffer();
51 const char* ptr() const { return _buf; }
52 void append(const char* s, size_t len);
53 void reset();
54 };
55 LineBuffer _current_line;
56 LogTargetHandle _log_handle;
57
58 // Prevent operator new for LogStream.
59 static void* operator new (size_t);
60 static void* operator new[] (size_t);
61
62 public:
63 // Constructor to support creation from a LogTarget instance.
64 //
65 // LogTarget(Debug, gc) log;
66 // LogStreamBase(log) stream;
67 template <LogLevelType level, LogTagType T0, LogTagType T1, LogTagType T2, LogTagType T3, LogTagType T4, LogTagType GuardTag>
68 LogStream(const LogTargetImpl<level, T0, T1, T2, T3, T4, GuardTag>& type_carrier) :
69 _log_handle(level, &LogTagSetMapping<T0, T1, T2, T3, T4>::tagset()) {}
70
71 // Constructor to support creation from typed (likely NULL) pointer. Mostly used by the logging framework.
|
31 #include "utilities/ostream.hpp"
32
33
34 class LogStream : public outputStream {
35 friend class LogStreamTest_TestLineBufferAllocation_test_vm_Test; // see test/native/logging/test_logStream.cpp
36 friend class LogStreamTest_TestLineBufferAllocationCap_test_vm_Test; // see test/native/logging/test_logStream.cpp
37
38 // Helper class, maintains the line buffer. For small line lengths,
39 // we avoid malloc and use a fixed sized member char array. If LogStream
40 // is allocated on the stack, this means small lines are assembled
41 // directly on the stack.
42 class LineBuffer {
43 char _smallbuf[64];
44 char* _buf;
45 size_t _cap;
46 size_t _pos;
47 void try_ensure_cap(size_t cap);
48 public:
49 LineBuffer();
50 ~LineBuffer();
51 const char* buffer() const { return _buf; }
52 void append(const char* s, size_t len);
53 void reset();
54 };
55 LineBuffer _current_line;
56 LogTargetHandle _log_handle;
57
58 // Prevent operator new for LogStream.
59 static void* operator new (size_t);
60 static void* operator new[] (size_t);
61
62 public:
63 // Constructor to support creation from a LogTarget instance.
64 //
65 // LogTarget(Debug, gc) log;
66 // LogStreamBase(log) stream;
67 template <LogLevelType level, LogTagType T0, LogTagType T1, LogTagType T2, LogTagType T3, LogTagType T4, LogTagType GuardTag>
68 LogStream(const LogTargetImpl<level, T0, T1, T2, T3, T4, GuardTag>& type_carrier) :
69 _log_handle(level, &LogTagSetMapping<T0, T1, T2, T3, T4>::tagset()) {}
70
71 // Constructor to support creation from typed (likely NULL) pointer. Mostly used by the logging framework.
|