box and val (c2 crash)

Tobias Hartmann tobias.hartmann at oracle.com
Fri Jan 4 14:25:09 UTC 2019


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