Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8231961

[lworld] C1 compiled code returns incorrect value for flattened array access

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P3
    • repo-valhalla
    • repo-valhalla
    • hotspot

    Description

      When run with -Xcomp, the attached sample function test6a() returns null when it should return the field value.

      @SuppressWarnings("unchecked")
      public class BugOpt1 {

          private BNode<Integer,Integer>[] table;

          public static void main(String[] args) {
              BugOpt1 st = new BugOpt1();
              st.table = (BNode<Integer,Integer>[])new BNode[1];
              st.table[0] = new BNode<Integer,Integer>(Integer.valueOf(0), Integer.valueOf(99));
              Object o = st.test6a(Integer.valueOf(0), Integer.valueOf(10));
              if (o == null) {
                  throw new AssertionError("return value should be 99");
              }
          }

          Integer test6a(Integer k, Integer v) {
              int index = k.intValue();
              if (index >= 0 && table[index].value != null) {
      // System.out.println(); // With this change, the correct value is returned.
                  return table[index].value;
              }
              return v;
          }

          /**
           * Basic hash bin node.
           */
          static inline class BNode<K,V> {
              final K key;
              final V value;

              BNode(K key, V value) {
                  this.key = key;
                  this.value = value;
              }
          }
      }


      Attachments

        Activity

          People

            thartmann Tobias Hartmann
            rriggs Roger Riggs
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: