changeset 53150:3bc6659f2888 lworld

8214426: [lworld][C1] aaload doesn't work with constant index Reviewed-by: thartmann
author iklam
date Fri, 30 Nov 2018 16:51:17 -0800
parents 1e0eba514454
children f19715f86b32
files src/hotspot/share/c1/c1_LIRGenerator.cpp
diffstat 1 files changed, 19 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/hotspot/share/c1/c1_LIRGenerator.cpp	Thu Nov 29 11:30:24 2018 -0800
+++ b/src/hotspot/share/c1/c1_LIRGenerator.cpp	Fri Nov 30 16:51:17 2018 -0800
@@ -1567,15 +1567,30 @@
   ciValueArrayKlass* value_array_klass = array_type->as_value_array_klass();
   ciValueKlass* elem_klass = value_array_klass->element_klass()->as_value_klass();
   int array_header_size = value_array_klass->array_header_in_bytes();
+  int shift = value_array_klass->log2_element_size();
 
 #ifndef _LP64
-  LIR_Opr index_op = index.result();
+  LIR_Opr index_op = new_register(T_INT);
+  // FIXME -- on 32-bit, the shift below can overflow, so we need to check that
+  // the top (shift+1) bits of index_op must be zero, or
+  // else throw ArrayIndexOutOfBoundsException
+  if (index.result()->is_constant()) {
+    jint const_index = index.result()->as_jint();
+    __ move(LIR_OprFact::intConst(const_index << shift), index_op);
+  } else {
+    __ shift_left(index_op, shift, index.result());
+  }
 #else
   LIR_Opr index_op = new_register(T_LONG);
-  __ convert(Bytecodes::_i2l, index.result(), index_op);
+  if (index.result()->is_constant()) {
+    jint const_index = index.result()->as_jint();
+    __ move(LIR_OprFact::longConst(const_index << shift), index_op);
+  } else {
+    __ convert(Bytecodes::_i2l, index.result(), index_op);
+    // Need to shift manually, as LIR_Address can scale only up to 3.
+    __ shift_left(index_op, shift, index_op);
+  }
 #endif
-  // Need to shift manually, as LIR_Address can scale only up to 3.
-  __ shift_left(index_op, value_array_klass->log2_element_size(), index_op);
 
   LIR_Opr elm_op = new_pointer_register();
   LIR_Address* elm_address = new LIR_Address(array.result(), index_op, array_header_size, T_ADDRESS);