32 #include "services/management.hpp"
33
34 jlong LogDecorations::_vm_start_time_millis = 0;
35 const char* volatile LogDecorations::_host_name = NULL;
36
37 LogDecorations::LogDecorations(LogLevelType level, const LogTagSet &tagset, const LogDecorators &decorators)
38 : _level(level), _tagset(tagset), _millis(-1) {
39 create_decorations(decorators);
40 }
41
42 void LogDecorations::initialize(jlong vm_start_time) {
43 _vm_start_time_millis = vm_start_time;
44 }
45
46 const char* LogDecorations::host_name() {
47 const char* host_name = Atomic::load_acquire(&_host_name);
48 if (host_name == NULL) {
49 char buffer[1024];
50 if (os::get_host_name(buffer, sizeof(buffer))) {
51 host_name = os::strdup_check_oom(buffer);
52 const char* old_value = Atomic::cmpxchg(host_name, &_host_name, (const char*)NULL);
53 if (old_value != NULL) {
54 os::free((void *) host_name);
55 host_name = old_value;
56 }
57 }
58 }
59 return host_name;
60 }
61
62 void LogDecorations::create_decorations(const LogDecorators &decorators) {
63 char* position = _decorations_buffer;
64 #define DECORATOR(full_name, abbr) \
65 if (decorators.is_decorator(LogDecorators::full_name##_decorator)) { \
66 _decoration_offset[LogDecorators::full_name##_decorator] = position; \
67 position = create_##full_name##_decoration(position) + 1; \
68 } else { \
69 _decoration_offset[LogDecorators::full_name##_decorator] = NULL; \
70 }
71 DECORATOR_LIST
72 #undef DECORATOR
130 int written = jio_snprintf(pos, DecorationsBufferSize - (pos - _decorations_buffer),
131 INTX_FORMAT, os::current_thread_id());
132 ASSERT_AND_RETURN(written, pos)
133 }
134
135 char* LogDecorations::create_level_decoration(char* pos) {
136 // Avoid generating the level decoration because it may change.
137 // The decoration() method has a special case for level decorations.
138 return pos;
139 }
140
141 char* LogDecorations::create_tags_decoration(char* pos) {
142 int written = _tagset.label(pos, DecorationsBufferSize - (pos - _decorations_buffer));
143 ASSERT_AND_RETURN(written, pos)
144 }
145
146 char* LogDecorations::create_hostname_decoration(char* pos) {
147 int written = jio_snprintf(pos, DecorationsBufferSize - (pos - _decorations_buffer), "%s", host_name());
148 ASSERT_AND_RETURN(written, pos)
149 }
150
|
32 #include "services/management.hpp"
33
34 jlong LogDecorations::_vm_start_time_millis = 0;
35 const char* volatile LogDecorations::_host_name = NULL;
36
37 LogDecorations::LogDecorations(LogLevelType level, const LogTagSet &tagset, const LogDecorators &decorators)
38 : _level(level), _tagset(tagset), _millis(-1) {
39 create_decorations(decorators);
40 }
41
42 void LogDecorations::initialize(jlong vm_start_time) {
43 _vm_start_time_millis = vm_start_time;
44 }
45
46 const char* LogDecorations::host_name() {
47 const char* host_name = Atomic::load_acquire(&_host_name);
48 if (host_name == NULL) {
49 char buffer[1024];
50 if (os::get_host_name(buffer, sizeof(buffer))) {
51 host_name = os::strdup_check_oom(buffer);
52 const char* old_value = Atomic::cmpxchg(&_host_name, (const char*)NULL, host_name);
53 if (old_value != NULL) {
54 os::free((void *) host_name);
55 host_name = old_value;
56 }
57 }
58 }
59 return host_name;
60 }
61
62 void LogDecorations::create_decorations(const LogDecorators &decorators) {
63 char* position = _decorations_buffer;
64 #define DECORATOR(full_name, abbr) \
65 if (decorators.is_decorator(LogDecorators::full_name##_decorator)) { \
66 _decoration_offset[LogDecorators::full_name##_decorator] = position; \
67 position = create_##full_name##_decoration(position) + 1; \
68 } else { \
69 _decoration_offset[LogDecorators::full_name##_decorator] = NULL; \
70 }
71 DECORATOR_LIST
72 #undef DECORATOR
130 int written = jio_snprintf(pos, DecorationsBufferSize - (pos - _decorations_buffer),
131 INTX_FORMAT, os::current_thread_id());
132 ASSERT_AND_RETURN(written, pos)
133 }
134
135 char* LogDecorations::create_level_decoration(char* pos) {
136 // Avoid generating the level decoration because it may change.
137 // The decoration() method has a special case for level decorations.
138 return pos;
139 }
140
141 char* LogDecorations::create_tags_decoration(char* pos) {
142 int written = _tagset.label(pos, DecorationsBufferSize - (pos - _decorations_buffer));
143 ASSERT_AND_RETURN(written, pos)
144 }
145
146 char* LogDecorations::create_hostname_decoration(char* pos) {
147 int written = jio_snprintf(pos, DecorationsBufferSize - (pos - _decorations_buffer), "%s", host_name());
148 ASSERT_AND_RETURN(written, pos)
149 }
|