PrintCFGToFile crashes VM
Stuart Monteith
stuart.monteith at linaro.org
Tue Feb 7 14:12:18 UTC 2017
When running with:
-XX:PrintCFGToFile
It is very straightforward for the VM to SIGSEGV. The single
CFGPrinterOutput instance isn't serialized, and so multiple threads
are setting its _do_print_HIR and _do_print_LIR flags. This causes a
crash when one compilation thread is trying to print LIRs, even when
there aren't any.
For example:
#10 0x000003ffa769df14 in LIR_List::length (this=0x0) at
/home/stuart/repos/jdk9dev/hotspot/src/share/vm/c1/c1_LIR.hpp:2009
#11 0x000003ffa769cf10 in CFGPrinterOutput::print_LIR
(this=0x3fdf4031910, block=0x3fdb8004fc0) at
/home/stuart/repos/jdk9dev/hotspot/src/share/vm/c1/c1_CFGPrinter.cpp:267
#12 0x000003ffa769d4a4 in CFGPrinterOutput::print_block
(this=0x3fdf4031910, block=0x3fdb8004fc0)
at /home/stuart/repos/jdk9dev/hotspot/src/share/vm/c1/c1_CFGPrinter.cpp:338
#13 0x000003ffa769ef14 in
CFGPrinterOutput::PrintBlockClosure::block_do (this=0x3fdcfffdcb0,
block=0x3fdb8004fc0)
at /home/stuart/repos/jdk9dev/hotspot/src/share/vm/c1/c1_CFGPrinter.cpp:45
#14 0x000003ffa76f168c in BlockBegin::iterate_preorder
(this=0x3fdb8004fc0, mark=..., closure=0x3fdcfffdcb0)
at /home/stuart/repos/jdk9dev/hotspot/src/share/vm/c1/c1_Instruction.cpp:706
#15 0x000003ffa76f1708 in BlockBegin::iterate_preorder
(this=0x3fdb8006bc0, mark=..., closure=0x3fdcfffdcb0)
at /home/stuart/repos/jdk9dev/hotspot/src/share/vm/c1/c1_Instruction.cpp:709
#16 0x000003ffa76f18dc in BlockBegin::iterate_preorder
(this=0x3fdb8006bc0, closure=0x3fdcfffdcb0)
at /home/stuart/repos/jdk9dev/hotspot/src/share/vm/c1/c1_Instruction.cpp:728
#17 0x000003ffa76e9cec in IR::iterate_preorder (this=0x3fdb8004ac0,
closure=0x3fdcfffdcb0) at
/home/stuart/repos/jdk9dev/hotspot/src/share/vm/c1/c1_IR.cpp:1200
#18 0x000003ffa769d5e0 in CFGPrinterOutput::print_cfg
(this=0x3fdf4031910, blocks=0x3fdb8004ac0, name=0x3ffa83017d8 "After
Generation of HIR")
at /home/stuart/repos/jdk9dev/hotspot/src/share/vm/c1/c1_CFGPrinter.cpp:362
#19 0x000003ffa769c310 in CFGPrinter::print_cfg (blocks=0x3fdb8004ac0,
name=0x3ffa83017d8 "After Generation of HIR", do_print_HIR=true,
do_print_LIR=false)
at /home/stuart/repos/jdk9dev/hotspot/src/share/vm/c1/c1_CFGPrinter.cpp:98
#20 0x000003ffa76b1264 in Compilation::build_hir (this=0x3fdcfffe0d0)
at /home/stuart/repos/jdk9dev/hotspot/src/share/vm/c1/c1_Compilation.cpp:164
I've constructed a straw-man proposal for how this might be handled
(see below), which is to force there to be one compilation thread if
you use this flags (or two if C2 is enabled). Another possibility is
to explicitly serialize access to the CFGPrinterOutput object. In
principle we could have 1 thread for C1 and as many as are normal for
C2, but that may be complicating things unnecessarily. I'm keen to
hear opinions.
This is low priority, as it is only present in debug builds, and
setting the CICompileCount=1 is sufficient to get correct behaviour.
Stuart
# HG changeset patch
# User smonteith
# Date 1486476452 0
# Tue Feb 07 14:07:32 2017 +0000
# Node ID 530f3652e974874118e90f13639c8e528452f334
# Parent 0ae983a3af0759530a6b59fff35f18e8ac88816e
Option PrintCFGToFile forces single threaded compilation
Running with --XX:PrintCFGToFile causes a SIGSEGV as code is not thread-safe.
Overrides CICompilerCount settings to use one cpu.
diff -r 0ae983a3af07 -r 530f3652e974 src/share/vm/runtime/arguments.cpp
--- a/src/share/vm/runtime/arguments.cpp Wed Jan 11 16:32:35 2017 +0000
+++ b/src/share/vm/runtime/arguments.cpp Tue Feb 07 14:07:32 2017 +0000
@@ -2582,6 +2582,23 @@
FLAG_SET_CMDLINE(bool, PostLoopMultiversioning, false);
}
#endif
+
+#ifndef PRODUCT
+ // C1's CFGPrinter must run on a single thread. If PrintCFGToFile
is enabled, this
+ // code forces the compilers to use one or two threads.
+ if (PrintCFGToFile) {
+ // C1 and C2 each require 1 thread.
+ if(TieredCompilation && TieredStopAtLevel ==
CompLevel_full_optimization) {
+ warning("PrintCFGToFile set, CICompilerCount set to 2,
-CICompilerCountPerCPU ");
+ FLAG_SET_CMDLINE(intx, CICompilerCount, 2);
+ FLAG_SET_CMDLINE(bool, CICompilerCountPerCPU, false);
+ } else {
+ warning("PrintCFGToFile set, CICompilerCount set to 1,
-CICompilerCountPerCPU ");
+ FLAG_SET_CMDLINE(intx, CICompilerCount, 1);
+ FLAG_SET_CMDLINE(bool, CICompilerCountPerCPU, false);
+ }
+ }
+#endif
return status;
}
More information about the hotspot-dev
mailing list