8170548: VM may crash at startup because StdoutLog/StderrLog logging stream can be badly aligned
authorsimonis
Thu, 01 Dec 2016 11:30:22 +0100
changeset 42886 9d8028808e78
parent 42885 d85e387adbb6
child 42888 bf1ddfe56bad
child 42890 6eeb895b1a6f
child 42893 16dd6b309a48
8170548: VM may crash at startup because StdoutLog/StderrLog logging stream can be badly aligned Reviewed-by: stuefe, mlarsson, clanger, dholmes
hotspot/src/share/vm/logging/logFileStreamOutput.cpp
--- a/hotspot/src/share/vm/logging/logFileStreamOutput.cpp	Mon Dec 19 16:26:22 2016 +0100
+++ b/hotspot/src/share/vm/logging/logFileStreamOutput.cpp	Thu Dec 01 11:30:22 2016 +0100
@@ -29,11 +29,17 @@
 #include "memory/allocation.inline.hpp"
 
 static bool initialized;
-static char stdoutmem[sizeof(LogStdoutOutput)];
-static char stderrmem[sizeof(LogStderrOutput)];
+static union {
+  char stdoutmem[sizeof(LogStdoutOutput)];
+  jlong dummy;
+} aligned_stdoutmem;
+static union {
+  char stderrmem[sizeof(LogStderrOutput)];
+  jlong dummy;
+} aligned_stderrmem;
 
-LogStdoutOutput &StdoutLog = reinterpret_cast<LogStdoutOutput&>(stdoutmem);
-LogStderrOutput &StderrLog = reinterpret_cast<LogStderrOutput&>(stderrmem);
+LogStdoutOutput &StdoutLog = reinterpret_cast<LogStdoutOutput&>(aligned_stdoutmem.stdoutmem);
+LogStderrOutput &StderrLog = reinterpret_cast<LogStderrOutput&>(aligned_stderrmem.stderrmem);
 
 LogFileStreamInitializer::LogFileStreamInitializer() {
   if (!initialized) {