Question on arithmetic overflow detection support in C2

Vladimir Kozlov vladimir.kozlov at
Wed Jun 20 15:13:07 PDT 2012

Look on output before assert message. It should have problematic ideal subgraph 
dump which it can't match.

I think the problem is that you have Proj node in between If and CheckedAddI 
nodes so that it can't match 'If' node since it looks for inputs which produce 
flags (cr). May be CheckedAddINode::match() is not enough.

Also you can't use EMPTY mask for data result projection. Bind it to an register 
as DivMod node.

And use masm instructions encoding

   ins_encode %{
     __ addl($dst$$Register, $src$$Register);

instead of

    ins_encode(REX_reg_reg(dst, src), OpcP, reg_reg(dst, src));


Krystal Mok wrote:
> Thank you for all your input, John and Vladimir!
> I'm close to getting some prototype that could actually run...but not 
> there just yet.
> I've got Match.addExact(int, int) compiled down to this graph:
> with the CheckedAddI node resembling the way DivModI works.
> But apparently I'm not getting the Matcher part right yet. I'm getting 
> this error message:
> #  Internal Error 
> (/home/sajia/temp/hotspot-comp/src/share/vm/opto/matcher.cpp:1564), 
> pid=16856, tid=1117243712
> #  assert(false) failed: bad AD file
> from this stack trace:
> V  []  VMError::report(outputStream*)+0xfa4
> V  []  VMError::report_and_die()+0x649
> V  []  report_vm_error(char const*, int, char const*, 
> char const*)+0x9c
> V  []  Matcher::Label_Root(Node const*, State*, Node*, 
> Node const*)+0x48c
> V  []  Matcher::match_tree(Node const*)+0x205
> V  []  Matcher::xform(Node*, int)+0x16d
> V  []  Matcher::match()+0xb0e
> V  []  Compile::Code_Gen()+0x91
> V  []  Compile::Compile(ciEnv*, C2Compiler*, 
> ciMethod*, int, bool, bool)+0x101e
> V  []  C2Compiler::compile_method(ciEnv*, ciMethod*, 
> int)+0xea
> V  [] 
>  CompileBroker::invoke_compiler_on_method(CompileTask*)+0x332
> V  []  CompileBroker::compiler_thread_loop()+0x2fa
> V  []  compiler_thread_entry(JavaThread*, Thread*)+0x54
> V  []  JavaThread::thread_main_inner()+0x102
> V  []  JavaThread::run()+0xef
> V  []  java_start(Thread*)+0x16f
> The current status of the patch is avaiable here:
> I haven't done a full-fledged intrinsic for Math.addExact(int, int) yet; 
> just as a prototype, I'm faking the use of CmpAddI node right now. At 
> the end of Optimize(), I pattern match for the overflow checking logic, 
> replace it with a new fake CmpAddI node, then make the actual 
> CheckedAddI node from the CmpAddI, finally replace the old AddI and Bool 
> nodes.
> Most of the changes besides the new nodes are for adding the 
> overflow/no-overflow conditions to BoolTest and cmpOp.
> If there were separate AddI and CmpAddI nodes, they would have had a 
> (Set dst ...) and (Set cr ...) in their match rule. But I can't see how 
> I can express it here.
> Regards,
> Kris

More information about the hotspot-compiler-dev mailing list