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

C2: ArrayCopy elimination skips required parameter checks

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P2
    • Resolution: Fixed
    • Affects Version/s: 9
    • Fix Version/s: 9
    • Component/s: hotspot
    • Labels:
      None
    • Subcomponent:
    • Resolved In Build:
      b146
    • Verification:
      Verified

      Description

      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 + ")");
         }

      }

        Attachments

          Issue Links

            Activity

              People

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

                Dates

                • Created:
                  Updated:
                  Resolved: