hotspot/src/share/vm/logging/log.hpp
changeset 33766 3290cae587f9
parent 33097 96e348cb0442
child 34251 0ce22a6d7d8c
equal deleted inserted replaced
33754:49614940dafc 33766:3290cae587f9
    27 #include "logging/logLevel.hpp"
    27 #include "logging/logLevel.hpp"
    28 #include "logging/logPrefix.hpp"
    28 #include "logging/logPrefix.hpp"
    29 #include "logging/logTagSet.hpp"
    29 #include "logging/logTagSet.hpp"
    30 #include "logging/logTag.hpp"
    30 #include "logging/logTag.hpp"
    31 #include "memory/allocation.hpp"
    31 #include "memory/allocation.hpp"
       
    32 #include "memory/allocation.inline.hpp"
       
    33 #include "runtime/os.hpp"
    32 #include "utilities/debug.hpp"
    34 #include "utilities/debug.hpp"
    33 #include "utilities/ostream.hpp"
    35 #include "utilities/ostream.hpp"
    34 
    36 
    35 //
    37 //
    36 // Logging macros
    38 // Logging macros
   102   template <LogLevelType Level>
   104   template <LogLevelType Level>
   103   ATTRIBUTE_PRINTF(1, 0)
   105   ATTRIBUTE_PRINTF(1, 0)
   104   static void vwrite(const char* fmt, va_list args) {
   106   static void vwrite(const char* fmt, va_list args) {
   105     char buf[LogBufferSize];
   107     char buf[LogBufferSize];
   106     size_t prefix_len = LogPrefix<T0, T1, T2, T3, T4>::prefix(buf, sizeof(buf));
   108     size_t prefix_len = LogPrefix<T0, T1, T2, T3, T4>::prefix(buf, sizeof(buf));
   107     int ret = vsnprintf(buf + prefix_len, sizeof(buf) - prefix_len, fmt, args);
   109     // Check that string fits in buffer; resize buffer if necessary
   108     assert(ret >= 0 && (size_t)ret < sizeof(buf), "Log message too long");
   110     int ret = os::log_vsnprintf(buf + prefix_len, sizeof(buf) - prefix_len, fmt, args);
   109     puts<Level>(buf);
   111     assert(ret >= 0, "Log message buffer issue");
       
   112     if ((size_t)ret > sizeof(buf)) {
       
   113       size_t newbuf_len = prefix_len + ret + 1;
       
   114       char* newbuf = NEW_C_HEAP_ARRAY(char, newbuf_len, mtLogging);
       
   115       prefix_len = LogPrefix<T0, T1, T2, T3, T4>::prefix(newbuf, newbuf_len);
       
   116       ret = os::log_vsnprintf(newbuf + prefix_len, newbuf_len - prefix_len, fmt, args);
       
   117       assert(ret >= 0, "Log message buffer issue");
       
   118       puts<Level>(newbuf);
       
   119       FREE_C_HEAP_ARRAY(char, newbuf);
       
   120     } else {
       
   121       puts<Level>(buf);
       
   122     }
   110   }
   123   }
   111 
   124 
   112   template <LogLevelType Level>
   125   template <LogLevelType Level>
   113   static void puts(const char* string) {
   126   static void puts(const char* string) {
   114     LogTagSetMapping<T0, T1, T2, T3, T4>::tagset().log(Level, string);
   127     LogTagSetMapping<T0, T1, T2, T3, T4>::tagset().log(Level, string);