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

C2: ArrayCopy elimination skips required parameter checks

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P2 P2
    • 9
    • 9
    • hotspot
    • None
    • b146
    • Verified

      We noticed that the test program below fails.

      The arraycopy call has to throw an IndexOutOfBoundsException because the length is -1. We can see this happening when we switch off EliminateAllocations (or DoEscapeAnalysis).

      Seems like PhaseMacroExpand::process_users_of_allocation removes the ArrayCopyNode without checking the parameters. After the ArrayCopyNode is removed, the parameters are no longer checked and no exception is thrown.

      TestArrayCopyMinusOne.java
      public class TestArrayCopyMinusOne{

          public boolean do_test() {
              try {
                  System.arraycopy(new Object[1], 1, new Object[1], 1, -1);
                  return false;
              } catch (IndexOutOfBoundsException e) {
                  return true;
              }
          }

       
         static final int loop_cnt=100000;

         public static void main(String args[]){
             TestArrayCopyMinusOne xyz = new TestArrayCopyMinusOne();
             int errors = 0;
             long duration = System.nanoTime();
             for (int x = 0; x < loop_cnt; x++) {
                 if (!xyz.do_test()) errors++;
             }
             duration = System.nanoTime() - duration;
             System.out.println("errors: " + errors + " (duration: " + duration/loop_cnt + ")");
         }

      }

            simonis Volker Simonis
            mdoerr Martin Doerr
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: