hotspot/src/share/vm/logging/log.hpp
changeset 33766 3290cae587f9
parent 33097 96e348cb0442
child 34251 0ce22a6d7d8c
--- a/hotspot/src/share/vm/logging/log.hpp	Mon Aug 18 14:37:55 2014 +0200
+++ b/hotspot/src/share/vm/logging/log.hpp	Wed Nov 04 17:18:59 2015 -0500
@@ -29,6 +29,8 @@
 #include "logging/logTagSet.hpp"
 #include "logging/logTag.hpp"
 #include "memory/allocation.hpp"
+#include "memory/allocation.inline.hpp"
+#include "runtime/os.hpp"
 #include "utilities/debug.hpp"
 #include "utilities/ostream.hpp"
 
@@ -104,9 +106,20 @@
   static void vwrite(const char* fmt, va_list args) {
     char buf[LogBufferSize];
     size_t prefix_len = LogPrefix<T0, T1, T2, T3, T4>::prefix(buf, sizeof(buf));
-    int ret = vsnprintf(buf + prefix_len, sizeof(buf) - prefix_len, fmt, args);
-    assert(ret >= 0 && (size_t)ret < sizeof(buf), "Log message too long");
-    puts<Level>(buf);
+    // Check that string fits in buffer; resize buffer if necessary
+    int ret = os::log_vsnprintf(buf + prefix_len, sizeof(buf) - prefix_len, fmt, args);
+    assert(ret >= 0, "Log message buffer issue");
+    if ((size_t)ret > sizeof(buf)) {
+      size_t newbuf_len = prefix_len + ret + 1;
+      char* newbuf = NEW_C_HEAP_ARRAY(char, newbuf_len, mtLogging);
+      prefix_len = LogPrefix<T0, T1, T2, T3, T4>::prefix(newbuf, newbuf_len);
+      ret = os::log_vsnprintf(newbuf + prefix_len, newbuf_len - prefix_len, fmt, args);
+      assert(ret >= 0, "Log message buffer issue");
+      puts<Level>(newbuf);
+      FREE_C_HEAP_ARRAY(char, newbuf);
+    } else {
+      puts<Level>(buf);
+    }
   }
 
   template <LogLevelType Level>