box and val (c2 crash)

forax at univ-mlv.fr forax at univ-mlv.fr
Tue Jan 8 20:46:25 UTC 2019


----- Mail original -----
> De: "Tobias Hartmann" <tobias.hartmann at oracle.com>
> À: "Remi Forax" <forax at univ-mlv.fr>
> Cc: "valhalla-dev" <valhalla-dev at openjdk.java.net>
> Envoyé: Mardi 8 Janvier 2019 17:16:02
> Objet: Re: box and val (c2 crash)

> Hi Remi,
> 
> I've fixed the issue with:
> http://hg.openjdk.java.net/valhalla/valhalla/rev/530ea41023b2
> 
> Please let me know if you still see crashes with your benchmarks.

yes, no crash anymore. perf are as horrible because as you said box are not stack allocated :)
Thank you Tobias.

> 
> Thanks,
> Tobias


Rémi

> 
> 
> On 07.01.19 17:37, Tobias Hartmann wrote:
>> Thanks Remi! I've filed https://bugs.openjdk.java.net/browse/JDK-8216270 and
>> will work on a fix.
>> 
>> Best regards,
>> Tobias
>> 
>> On 07.01.19 14:16, forax at univ-mlv.fr wrote:
>>> Hi Tobias,
>>> it solves the second issue i've reported but not the first one,
>>> (the issue in TypePtr::xmeet_helper(Type const*)),
>>> so it still crashes.
>>>
>>> with 12-valhalla+0-09d9f9085910:
>>>
>>> Current CompileTask:
>>> C2:    325  120             fr.umlv.valuetype.perf.TupleLoopBenchMark::sum (46
>>> bytes)
>>>
>>> Stack: [0x00007f53541cd000,0x00007f53542ce000],  sp=0x00007f53542ca700,  free
>>> space=1013k
>>> Native frames: (J=compiled Java code, A=aot compiled Java code, j=interpreted,
>>> Vv=VM code, C=native code)
>>> V  [libjvm.so+0xe1a0a6]  VMError::report_and_die(int, char const*, char const*,
>>> __va_list_tag*, Thread*, unsigned char*, void*, void*, char const*, int,
>>> unsigned long)+0x186
>>> V  [libjvm.so+0xe1ae57]  VMError::report_and_die(Thread*, void*, char const*,
>>> int, char const*, char const*, __va_list_tag*)+0x47
>>> V  [libjvm.so+0x67a7fe]  report_vm_error(char const*, int, char const*, char
>>> const*, ...) [clone .constprop.51]+0xee
>>> V  [libjvm.so+0xdbc50e]  TypePtr::xmeet_helper(Type const*) const+0x5e
>>> V  [libjvm.so+0xdb8250]  TypePtr::xmeet(Type const*) const+0x10
>>> V  [libjvm.so+0x556611]  PhiNode::Value(PhaseGVN*) const+0x131
>>> V  [libjvm.so+0xc38af6]  PhaseGVN::transform_no_reclaim(Node*)+0x86
>>> V  [libjvm.so+0xc00d9d]  Parse::do_exits()+0x4bd
>>> V  [libjvm.so+0xc05d86]  Parse::Parse(JVMState*, ciMethod*, float)+0xab6
>>> V  [libjvm.so+0x53db98]  ParseGenerator::generate(JVMState*)+0x88
>>> V  [libjvm.so+0x70f9ed]  Parse::do_call()+0x2dd
>>> V  [libjvm.so+0xc15b08]  Parse::do_one_bytecode()+0x32e8
>>> V  [libjvm.so+0xc031e7]  Parse::do_one_block()+0x197
>>> V  [libjvm.so+0xc03652]  Parse::do_all_blocks()+0x102
>>> V  [libjvm.so+0xc05d40]  Parse::Parse(JVMState*, ciMethod*, float)+0xa70
>>> V  [libjvm.so+0x53db98]  ParseGenerator::generate(JVMState*)+0x88
>>> V  [libjvm.so+0x61bc28]  Compile::Compile(ciEnv*, C2Compiler*, ciMethod*, int,
>>> bool, bool, bool, DirectiveSet*)+0xe98
>>> V  [libjvm.so+0x53d096]  C2Compiler::compile_method(ciEnv*, ciMethod*, int,
>>> DirectiveSet*)+0xe6
>>> V  [libjvm.so+0x6242f2]
>>> CompileBroker::invoke_compiler_on_method(CompileTask*)+0x3a2
>>> V  [libjvm.so+0x625738]  CompileBroker::compiler_thread_loop()+0x608
>>> V  [libjvm.so+0xda4468]  JavaThread::thread_main_inner()+0xf8
>>> V  [libjvm.so+0xda1131]  Thread::call_run()+0x171
>>> V  [libjvm.so+0xbd5708]  thread_native_entry(Thread*)+0xf8
>>>
>>> cheers,
>>> Rémi
>>>
>>> ----- Mail original -----
>>>> De: "Tobias Hartmann" <tobias.hartmann at oracle.com>
>>>> À: "Remi Forax" <forax at univ-mlv.fr>, "valhalla-dev"
>>>> <valhalla-dev at openjdk.java.net>
>>>> Envoyé: Lundi 7 Janvier 2019 10:55:51
>>>> Objet: Re: box and val (c2 crash)
>>>
>>>> Hi Remi,
>>>>
>>>> I fixed the issue with JDK-8216260:
>>>> http://hg.openjdk.java.net/valhalla/valhalla/rev/09d9f9085910
>>>>
>>>> The problem was that we tried to scalarize a boxed value type return which
>>>> obviously fails if null
>>>> is returned. Could you please verify that the fix solves the crashes you were
>>>> seeing?
>>>>
>>>> Thanks,
>>>> Tobias
>>>>
>>>> On 04.01.19 15:25, Tobias Hartmann wrote:
>>>>> Hi Remi,
>>>>>
>>>>> thanks a lot for reporting these issues. I'll have a look!
>>>>>
>>>>> Best regards,
>>>>> Tobias
>>>>>
>>>>>
>>>>> On 04.01.19 15:14, Remi Forax wrote:
>>>>>> I believe the crash comes from the method "next()" (or indexedElements() because
>>>>>> it the same kind of code),
>>>>>>
>>>>>>   Cursor.box next() {
>>>>>>     if (index + 1 == array.length) {
>>>>>>       return null;
>>>>>>     }
>>>>>>     return new Cursor(array, index + 1);
>>>>>>   }
>>>>>>
>>>>>> There is a merge of either null or a Cursor (which is a value type) into a
>>>>>> register typed Cursor.box.
>>>>>>
>>>>>> Trying to insert a local variable in between result in a crash in a different
>>>>>> methods
>>>>>>   Cursor.box next() {
>>>>>>     Cursor.box box;
>>>>>>     if (index + 1 == array.length) {
>>>>>>       box = null;
>>>>>>     } else {
>>>>>>       box = new Cursor(array, index + 1);
>>>>>>     }
>>>>>>     return box;
>>>>>>   }
>>>>>>
>>>>>> Current CompileTask:
>>>>>> C2:    308  117
>>>>>> fr.umlv.valuetype.perf.TupleLoopBenchMark$Cursor::next (38 bytes)
>>>>>>
>>>>>> Stack: [0x00007fb3b253c000,0x00007fb3b263d000],  sp=0x00007fb3b2639d00,  free
>>>>>> space=1015k
>>>>>> Native frames: (J=compiled Java code, A=aot compiled Java code, j=interpreted,
>>>>>> Vv=VM code, C=native code)
>>>>>> V  [libjvm.so+0xde246f]  ValueTypeNode::make_from_oop(GraphKit*, Node*,
>>>>>> ciValueKlass*)+0x9f
>>>>>> V  [libjvm.so+0xc06567]  Parse::return_current(Node*)+0x8d7
>>>>>> V  [libjvm.so+0xc14dc4]  Parse::do_one_bytecode()+0x2714
>>>>>> V  [libjvm.so+0xc03077]  Parse::do_one_block()+0x197
>>>>>> V  [libjvm.so+0xc034e2]  Parse::do_all_blocks()+0x102
>>>>>> V  [libjvm.so+0xc05bd0]  Parse::Parse(JVMState*, ciMethod*, float)+0xa70
>>>>>> V  [libjvm.so+0x53da48]  ParseGenerator::generate(JVMState*)+0x88
>>>>>> V  [libjvm.so+0x61bab8]  Compile::Compile(ciEnv*, C2Compiler*, ciMethod*, int,
>>>>>> bool, bool, bool, DirectiveSet*)+0xe98
>>>>>> V  [libjvm.so+0x53cf46]  C2Compiler::compile_method(ciEnv*, ciMethod*, int,
>>>>>> DirectiveSet*)+0xe6
>>>>>> V  [libjvm.so+0x624182]
>>>>>> CompileBroker::invoke_compiler_on_method(CompileTask*)+0x3a2
>>>>>> V  [libjvm.so+0x6255c8]  CompileBroker::compiler_thread_loop()+0x608
>>>>>> V  [libjvm.so+0xda42f8]  JavaThread::thread_main_inner()+0xf8
>>>>>> V  [libjvm.so+0xda0fc1]  Thread::call_run()+0x171
>>>>>> V  [libjvm.so+0xbd5598]  thread_native_entry(Thread*)+0xf8
>>>>>>
>>>>>> Rémi
>>>>>>
>>>>>> ----- Mail original -----
>>>>>>> De: "Remi Forax" <forax at univ-mlv.fr>
>>>>>>> À: "valhalla-dev" <valhalla-dev at openjdk.java.net>
>>>>>>> Envoyé: Jeudi 3 Janvier 2019 16:14:22
>>>>>>> Objet: box and val (c2 crash)
>>>>>>
>>>>>>> Now, i've tried to play with the .box/.val trying to implement the clojure
>>>>>>> Cursor protocol,
>>>>>>> which iterate like it's an abstract linked list, so at each step either you
>>>>>>> return a new Cursor (a value type) or null at the end (which seems to be a good
>>>>>>> test for a nullable value type).
>>>>>>>
>>>>>>> The following code compiles !
>>>>>>> I had to had the fix method because the compier refuse to find any methods on
>>>>>>> Cursor.box and
>>>>>>>  Cursor.box boxed = ...
>>>>>>>  ((Cursor)boxed).next
>>>>>>> doesn't compile too.
>>>>>>>
>>>>>>> If you try to execute the code, it crashes the VM (in the C2 compiler thread it
>>>>>>> seems)
>>>>>>>
>>>>>>> Current CompileTask:
>>>>>>> C2:    338  119             fr.umlv.valuetype.perf.TupleLoopBenchMark::sum (46
>>>>>>> bytes)
>>>>>>>
>>>>>>> Stack: [0x00007ff4c0a37000,0x00007ff4c0b38000],  sp=0x00007ff4c0b34700,  free
>>>>>>> space=1013k
>>>>>>> Native frames: (J=compiled Java code, A=aot compiled Java code, j=interpreted,
>>>>>>> Vv=VM code, C=native code)
>>>>>>> V  [libjvm.so+0xe19ed6]  VMError::report_and_die(int, char const*, char const*,
>>>>>>> __va_list_tag*, Thread*, unsigned char*, void*, void*, char const*, int,
>>>>>>> unsigned long)+0x186
>>>>>>> V  [libjvm.so+0xe1ac87]  VMError::report_and_die(Thread*, void*, char const*,
>>>>>>> int, char const*, char const*, __va_list_tag*)+0x47
>>>>>>> V  [libjvm.so+0x67a68e]  report_vm_error(char const*, int, char const*, char
>>>>>>> const*, ...) [clone .constprop.51]+0xee
>>>>>>> V  [libjvm.so+0xdbc39e]  TypePtr::xmeet_helper(Type const*) const+0x5e
>>>>>>> V  [libjvm.so+0xdb80e0]  TypePtr::xmeet(Type const*) const+0x10
>>>>>>> V  [libjvm.so+0x5564c1]  PhiNode::Value(PhaseGVN*) const+0x131
>>>>>>> V  [libjvm.so+0xc38986]  PhaseGVN::transform_no_reclaim(Node*)+0x86
>>>>>>> V  [libjvm.so+0xc00c2d]  Parse::do_exits()+0x4bd
>>>>>>> V  [libjvm.so+0xc05c16]  Parse::Parse(JVMState*, ciMethod*, float)+0xab6
>>>>>>> V  [libjvm.so+0x53da48]  ParseGenerator::generate(JVMState*)+0x88
>>>>>>> V  [libjvm.so+0x70f87d]  Parse::do_call()+0x2dd
>>>>>>> V  [libjvm.so+0xc15998]  Parse::do_one_bytecode()+0x32e8
>>>>>>> V  [libjvm.so+0xc03077]  Parse::do_one_block()+0x197
>>>>>>> V  [libjvm.so+0xc034e2]  Parse::do_all_blocks()+0x102
>>>>>>> V  [libjvm.so+0xc05bd0]  Parse::Parse(JVMState*, ciMethod*, float)+0xa70
>>>>>>> V  [libjvm.so+0x53da48]  ParseGenerator::generate(JVMState*)+0x88
>>>>>>> V  [libjvm.so+0x61bab8]  Compile::Compile(ciEnv*, C2Compiler*, ciMethod*, int,
>>>>>>> bool, bool, bool, DirectiveSet*)+0xe98
>>>>>>> V  [libjvm.so+0x53cf46]  C2Compiler::compile_method(ciEnv*, ciMethod*, int,
>>>>>>> DirectiveSet*)+0xe6
>>>>>>> V  [libjvm.so+0x624182]
>>>>>>> CompileBroker::invoke_compiler_on_method(CompileTask*)+0x3a2
>>>>>>> V  [libjvm.so+0x6255c8]  CompileBroker::compiler_thread_loop()+0x608
>>>>>>> V  [libjvm.so+0xda42f8]  JavaThread::thread_main_inner()+0xf8
>>>>>>> V  [libjvm.so+0xda0fc1]  Thread::call_run()+0x171
>>>>>>> V  [libjvm.so+0xbd5598]  thread_native_entry(Thread*)+0xf8
>>>>>>>
>>>>>>>
>>>>>>> Rémi
>>>>>>>
>>>>>>> ---
>>>>>>>  static value class Tuple {
>>>>>>>    private final int index;
>>>>>>>    private final int element;
>>>>>>>    
>>>>>>>    
>>>>>>>    private Tuple(int index, int element) {
>>>>>>>      this.index = index;
>>>>>>>      this.element = element;
>>>>>>>    }
>>>>>>>  }
>>>>>>>  
>>>>>>>  static value class Cursor {
>>>>>>>    private final int[] array;
>>>>>>>    private final int index;
>>>>>>>    
>>>>>>>    private Cursor(int[] array, int index) {
>>>>>>>      this.array = array;
>>>>>>>      this.index = index;
>>>>>>>    }
>>>>>>>    
>>>>>>>    Tuple current() {
>>>>>>>      return new Tuple(index, array[index]);
>>>>>>>    }
>>>>>>>    
>>>>>>>    Cursor.box next() {
>>>>>>>      if (index + 1 == array.length) {
>>>>>>>        return null;
>>>>>>>      }
>>>>>>>      return new Cursor(array, index + 1);
>>>>>>>    }
>>>>>>>  }
>>>>>>>  
>>>>>>>  private static Cursor.box indexedElements(int[] array) {
>>>>>>>    if (array.length == 0) {
>>>>>>>      return null;
>>>>>>>    }
>>>>>>>    return new Cursor(array, 0);
>>>>>>>  }
>>>>>>>  
>>>>>>>  private static Cursor fix(Cursor.box cursor) {
>>>>>>>    return cursor;
>>>>>>>  }
>>>>>>>  
>>>>>>>  @Benchmark
>>>>>>>  public int sum() {
>>>>>>>    int sum = 0;
>>>>>>>    for(Cursor.box cursor = indexedElements(ARRAY); cursor != null; cursor =
>>>>>>>    fix(cursor).next()) {
>>>>>>>      Tuple tuple = fix(cursor).current();
>>>>>>>      sum += tuple.index + tuple.element;
>>>>>>>    }
>>>>>>>    return sum;
> >>>>>>   }


More information about the valhalla-dev mailing list