< prev index next >

test/compiler/rangechecks/TestRangeCheckSmearing.java

Print this page




  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /*
  25  * @test
  26  * @bug 8066103
  27  * @summary C2's range check smearing allows out of bound array accesses
  28  * @library /testlibrary /test/lib /
  29  * @modules java.base/jdk.internal.misc
  30  *          java.management
  31  * @ignore 8157984
  32  * @build TestRangeCheckSmearing
  33  * @run driver ClassFileInstaller sun.hotspot.WhiteBox
  34  *                                jdk.test.lib.Platform
  35  * @run main/othervm -ea -Xmixed -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI
  36  *                   -XX:-BackgroundCompilation -XX:-UseOnStackReplacement TestRangeCheckSmearing
  37  *
  38  */
  39 
  40 import java.lang.annotation.*;
  41 import java.lang.reflect.*;
  42 import java.util.*;
  43 import sun.hotspot.WhiteBox;
  44 import sun.hotspot.code.NMethod;
  45 import jdk.test.lib.Platform;
  46 import compiler.whitebox.CompilerWhiteBoxTest;

  47 
  48 public class TestRangeCheckSmearing {
  49     private static final WhiteBox WHITE_BOX = WhiteBox.getWhiteBox();
  50 
  51     @Retention(RetentionPolicy.RUNTIME)
  52     @interface Args { int[] value(); }
  53 
  54     // first range check is i + max of all constants
  55     @Args({0, 8})
  56     static int m1(int[] array, int i, boolean allaccesses) {
  57         int res = 0;
  58         res += array[i+9];
  59         if (allaccesses) {
  60             res += array[i+8];
  61             res += array[i+7];
  62             res += array[i+6];
  63             res += array[i+5];
  64             res += array[i+4];
  65             res += array[i+3];
  66             res += array[i+2];


 379 
 380         // valid access
 381         invokeTest(m, array, index0, true);
 382 
 383         if (!WHITE_BOX.isMethodCompiled(m)) {
 384             throw new RuntimeException(m + " deoptimized on valid array access");
 385         }
 386 
 387         exception = false;
 388         boolean test_success = true;
 389         try {
 390             invokeTest(m, array, index1, false);
 391         } catch(ArrayIndexOutOfBoundsException aioob) {
 392             exception = true;
 393             System.out.println("ArrayIndexOutOfBoundsException thrown in "+name);
 394         }
 395         if (!exception) {
 396             System.out.println("ArrayIndexOutOfBoundsException was not thrown in "+name);
 397         }
 398 
 399         if (Platform.isServer()) {
 400             if (exceptionRequired == WHITE_BOX.isMethodCompiled(m)) {
 401                 System.out.println((exceptionRequired?"Didn't deoptimized":"deoptimized") + " in "+name);
 402                 test_success = false;
 403             }
 404         }
 405 
 406         if (exception != exceptionRequired) {
 407             System.out.println((exceptionRequired?"exception required but not thrown":"not exception required but thrown") + " in "+name);
 408             test_success = false;
 409         }
 410 
 411         if (!test_success) {
 412             success = false;
 413             System.out.println("TEST FAILED: "+name);
 414         }
 415 
 416     }
 417     void doTests() {
 418         doTest("m1");
 419         doTest("m2");




  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /*
  25  * @test
  26  * @bug 8066103
  27  * @summary C2's range check smearing allows out of bound array accesses
  28  * @library /testlibrary /test/lib /
  29  * @modules java.base/jdk.internal.misc
  30  *          java.management

  31  * @build TestRangeCheckSmearing
  32  * @run driver ClassFileInstaller sun.hotspot.WhiteBox
  33  *                                jdk.test.lib.Platform
  34  * @run main/othervm -ea -Xmixed -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI
  35  *                   -XX:-BackgroundCompilation -XX:-UseOnStackReplacement TestRangeCheckSmearing
  36  *
  37  */
  38 
  39 import java.lang.annotation.*;
  40 import java.lang.reflect.*;
  41 import java.util.*;
  42 import sun.hotspot.WhiteBox;
  43 import sun.hotspot.code.NMethod;
  44 import jdk.test.lib.Platform;
  45 import compiler.whitebox.CompilerWhiteBoxTest;
  46 import compiler.testlibrary.CompilerUtils;
  47 
  48 public class TestRangeCheckSmearing {
  49     private static final WhiteBox WHITE_BOX = WhiteBox.getWhiteBox();
  50 
  51     @Retention(RetentionPolicy.RUNTIME)
  52     @interface Args { int[] value(); }
  53 
  54     // first range check is i + max of all constants
  55     @Args({0, 8})
  56     static int m1(int[] array, int i, boolean allaccesses) {
  57         int res = 0;
  58         res += array[i+9];
  59         if (allaccesses) {
  60             res += array[i+8];
  61             res += array[i+7];
  62             res += array[i+6];
  63             res += array[i+5];
  64             res += array[i+4];
  65             res += array[i+3];
  66             res += array[i+2];


 379 
 380         // valid access
 381         invokeTest(m, array, index0, true);
 382 
 383         if (!WHITE_BOX.isMethodCompiled(m)) {
 384             throw new RuntimeException(m + " deoptimized on valid array access");
 385         }
 386 
 387         exception = false;
 388         boolean test_success = true;
 389         try {
 390             invokeTest(m, array, index1, false);
 391         } catch(ArrayIndexOutOfBoundsException aioob) {
 392             exception = true;
 393             System.out.println("ArrayIndexOutOfBoundsException thrown in "+name);
 394         }
 395         if (!exception) {
 396             System.out.println("ArrayIndexOutOfBoundsException was not thrown in "+name);
 397         }
 398 
 399         if (CompilerUtils.getMaxCompilationLevel() == CompilerWhiteBoxTest.COMP_LEVEL_FULL_OPTIMIZATION) {
 400             if (exceptionRequired == WHITE_BOX.isMethodCompiled(m)) {
 401                 System.out.println((exceptionRequired?"Didn't deoptimized":"deoptimized") + " in "+name);
 402                 test_success = false;
 403             }
 404         }
 405 
 406         if (exception != exceptionRequired) {
 407             System.out.println((exceptionRequired?"exception required but not thrown":"not exception required but thrown") + " in "+name);
 408             test_success = false;
 409         }
 410 
 411         if (!test_success) {
 412             success = false;
 413             System.out.println("TEST FAILED: "+name);
 414         }
 415 
 416     }
 417     void doTests() {
 418         doTest("m1");
 419         doTest("m2");


< prev index next >