test/compiler/6823354/Test6823354.java

Mon, 28 Jul 2014 15:06:38 -0700

author
fzhinkin
date
Mon, 28 Jul 2014 15:06:38 -0700
changeset 6997
dbb05f6d93c4
parent 1907
c18cbe5936b8
child 6876
710a3c8b516e
permissions
-rw-r--r--

8051344: JVM crashed in Compile::start() during method parsing w/ UseRTMDeopt turned on
Summary: call rtm_deopt() only if there were no compilation bailouts before.
Reviewed-by: kvn

     1 /*
     2  * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     8  *
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    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  */
    24 /**
    25  * @test
    26  * @bug 6823354
    27  * @summary These methods can be instrinsified by using bit scan, bit test, and population count instructions.
    28  *
    29  * @run main/othervm -Xcomp -XX:CompileOnly=Test6823354.lzcomp,Test6823354.tzcomp,.dolzcomp,.dotzcomp Test6823354
    30  */
    32 import java.net.URLClassLoader;
    34 public class Test6823354 {
    35     // Arrays of corner case values.
    36     static final int[]  ia = new int[]  { 0,  1,  -1,  Integer.MIN_VALUE, Integer.MAX_VALUE };
    37     static final long[] la = new long[] { 0L, 1L, -1L, Long.MIN_VALUE,    Long.MAX_VALUE    };
    39     public static void main(String[] args) throws Exception {
    40         // Load the classes and the methods.
    41         Integer.numberOfLeadingZeros(0);
    42         Integer.numberOfTrailingZeros(0);
    43         Long.numberOfLeadingZeros(0);
    44         Long.numberOfTrailingZeros(0);
    46         lz();
    47         tz();
    48     }
    50     static void lz() throws Exception {
    51         // int
    53         // Test corner cases.
    54         for (int i = 0; i < ia.length; i++) {
    55             int x = ia[i];
    56             check(x, lzcomp(x), lzint(x));
    57         }
    59         // Test all possible return values.
    60         for (int i = 0; i < Integer.SIZE; i++) {
    61             int x = 1 << i;
    62             check(x, lzcomp(x), lzint(x));
    63         }
    65         String classname = "Test6823354$lzconI";
    67         // Test Ideal optimizations (constant values).
    68         for (int i = 0; i < ia.length; i++) {
    69             testclass(classname, ia[i]);
    70         }
    72         // Test Ideal optimizations (constant values).
    73         for (int i = 0; i < Integer.SIZE; i++) {
    74             int x = 1 << i;
    75             testclass(classname, x);
    76         }
    79         // long
    81         // Test corner cases.
    82         for (int i = 0; i < ia.length; i++) {
    83             long x = la[i];
    84             check(x, lzcomp(x), lzint(x));
    85         }
    87         // Test all possible return values.
    88         for (int i = 0; i < Long.SIZE; i++) {
    89             long x = 1L << i;
    90             check(x, lzcomp(x), lzint(x));
    91         }
    93         classname = "Test6823354$lzconL";
    95         // Test Ideal optimizations (constant values).
    96         for (int i = 0; i < la.length; i++) {
    97             testclass(classname, la[i]);
    98         }
   100         // Test Ideal optimizations (constant values).
   101         for (int i = 0; i < Long.SIZE; i++) {
   102             long x = 1L << i;
   103             testclass(classname, x);
   104         }
   105     }
   107     static void tz() throws Exception {
   108         // int
   110         // Test corner cases.
   111         for (int i = 0; i < ia.length; i++) {
   112             int x = ia[i];
   113             check(x, tzcomp(x), tzint(x));
   114         }
   116         // Test all possible return values.
   117         for (int i = 0; i < Integer.SIZE; i++) {
   118             int x = 1 << i;
   119             check(x, tzcomp(x), tzint(x));
   120         }
   122         String classname = "Test6823354$tzconI";
   124         // Test Ideal optimizations (constant values).
   125         for (int i = 0; i < ia.length; i++) {
   126             testclass(classname, ia[i]);
   127         }
   129         // Test Ideal optimizations (constant values).
   130         for (int i = 0; i < Integer.SIZE; i++) {
   131             int x = 1 << i;
   132             testclass(classname, x);
   133         }
   136         // long
   138         // Test corner cases.
   139         for (int i = 0; i < la.length; i++) {
   140             long x = la[i];
   141             check(x, tzcomp(x), tzint(x));
   142         }
   144         // Test all possible return values.
   145         for (int i = 0; i < Long.SIZE; i++) {
   146             long x = 1L << i;
   147             check(x, tzcomp(x), tzint(x));
   148         }
   150         classname = "Test6823354$tzconL";
   152         // Test Ideal optimizations (constant values).
   153         for (int i = 0; i < la.length; i++) {
   154             testclass(classname, la[i]);
   155         }
   157         // Test Ideal optimizations (constant values).
   158         for (int i = 0; i < Long.SIZE; i++) {
   159             long x = 1L << i;
   160             testclass(classname, x);
   161         }
   162     }
   164     static void check(int value, int result, int expected) {
   165         //System.out.println(value + ": " + result + ", " + expected);
   166         if (result != expected)
   167             throw new InternalError(value + " failed: " + result + " != " + expected);
   168     }
   170     static void check(long value, long result, long expected) {
   171         //System.out.println(value + ": " + result + ", " + expected);
   172         if (result != expected)
   173             throw new InternalError(value + " failed: " + result + " != " + expected);
   174     }
   176     static int lzint( int i)  { return Integer.numberOfLeadingZeros(i); }
   177     static int lzcomp(int i)  { return Integer.numberOfLeadingZeros(i); }
   179     static int lzint( long l) { return Long.numberOfLeadingZeros(l); }
   180     static int lzcomp(long l) { return Long.numberOfLeadingZeros(l); }
   182     static int tzint( int i)  { return Integer.numberOfTrailingZeros(i); }
   183     static int tzcomp(int i)  { return Integer.numberOfTrailingZeros(i); }
   185     static int tzint( long l) { return Long.numberOfTrailingZeros(l); }
   186     static int tzcomp(long l) { return Long.numberOfTrailingZeros(l); }
   188     static void testclass(String classname, int x) throws Exception {
   189         System.setProperty("value", "" + x);
   190         loadandrunclass(classname);
   191     }
   193     static void testclass(String classname, long x) throws Exception {
   194         System.setProperty("value", "" + x);
   195         loadandrunclass(classname);
   196     }
   198     static void loadandrunclass(String classname) throws Exception {
   199         Class cl = Class.forName(classname);
   200         URLClassLoader apploader = (URLClassLoader) cl.getClassLoader();
   201         ClassLoader loader = new URLClassLoader(apploader.getURLs(), apploader.getParent());
   202         Class c = loader.loadClass(classname);
   203         Runnable r = (Runnable) c.newInstance();
   204         r.run();
   205     }
   207     public static class lzconI implements Runnable {
   208         static final int VALUE;
   210         static {
   211             int value = 0;
   212             try {
   213                 value = Integer.decode(System.getProperty("value"));
   214             } catch (Throwable e) {}
   215             VALUE = value;
   216         }
   218         public void run() { check(VALUE, lzint(VALUE), dolzcomp()); }
   219         static int dolzcomp() { return lzcomp(VALUE); }
   220     }
   222     public static class lzconL implements Runnable {
   223         static final long VALUE;
   225         static {
   226             long value = 0;
   227             try {
   228                 value = Long.decode(System.getProperty("value"));
   229             } catch (Throwable e) {}
   230             VALUE = value;
   231         }
   233         public void run() { check(VALUE, lzint(VALUE), dolzcomp()); }
   234         static int dolzcomp() { return lzcomp(VALUE); }
   235     }
   237     public static class tzconI implements Runnable {
   238         static final int VALUE;
   240         static {
   241             int value = 0;
   242             try {
   243                 value = Integer.decode(System.getProperty("value"));
   244             } catch (Throwable e) {}
   245             VALUE = value;
   246         }
   248         public void run() { check(VALUE, tzint(VALUE), dotzcomp()); }
   249         static int dotzcomp() { return tzcomp(VALUE); }
   250     }
   252     public static class tzconL implements Runnable {
   253         static final long VALUE;
   255         static {
   256             long value = 0;
   257             try {
   258                 value = Long.decode(System.getProperty("value"));
   259             } catch (Throwable e) {}
   260             VALUE = value;
   261         }
   263         public void run() { check(VALUE, tzint(VALUE), dotzcomp()); }
   264         static int dotzcomp() { return tzcomp(VALUE); }
   265     }
   266 }

mercurial