< prev index next >

src/hotspot/share/logging/logDecorations.cpp

Print this page




  27 #include "logging/logDecorations.hpp"
  28 #include "runtime/atomic.hpp"
  29 #include "runtime/orderAccess.hpp"
  30 #include "runtime/os.inline.hpp"
  31 #include "runtime/thread.inline.hpp"
  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 = OrderAccess::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; \




  27 #include "logging/logDecorations.hpp"
  28 #include "runtime/atomic.hpp"
  29 #include "runtime/orderAccess.hpp"
  30 #include "runtime/os.inline.hpp"
  31 #include "runtime/thread.inline.hpp"
  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; \


< prev index next >