test/compiler/7177917/Test7177917.java

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

author
fzhinkin
date
Mon, 28 Jul 2014 15:06:38 -0700
changeset 6997
dbb05f6d93c4
parent 0
f90c822e73f8
child 9954
1f0cffcf648a
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) 2012, 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  *
    23  */
    25 /*
    26  * Micro-benchmark for Math.pow() and Math.exp()
    27  */
    29 import java.util.*;
    31 public class Test7177917 {
    33   static double d;
    35   static Random r = new Random(0);
    37   static long  m_pow(double[][] values) {
    38     double res = 0;
    39     long start = System.nanoTime();
    40     for (int i = 0; i < values.length; i++) {
    41       res += Math.pow(values[i][0], values[i][1]);
    42     }
    43     long stop = System.nanoTime();
    44     d = res;
    45     return (stop - start) / 1000;
    46   }
    48   static long  m_exp(double[] values) {
    49     double res = 0;
    50     long start = System.nanoTime();
    51     for (int i = 0; i < values.length; i++) {
    52       res += Math.exp(values[i]);
    53     }
    54     long stop = System.nanoTime();
    55     d = res;
    56     return (stop - start) / 1000;
    57   }
    59   static double[][] pow_values(int nb) {
    60     double[][] res = new double[nb][2];
    61     for (int i = 0; i < nb; i++) {
    62       double ylogx = (1 + (r.nextDouble() * 2045)) - 1023; // 2045 rather than 2046 as a safety margin
    63       double x = Math.abs(Double.longBitsToDouble(r.nextLong()));
    64       while (x != x) {
    65         x = Math.abs(Double.longBitsToDouble(r.nextLong()));
    66       }
    67       double logx = Math.log(x) / Math.log(2);
    68       double y = ylogx / logx;
    70       res[i][0] = x;
    71       res[i][1] = y;
    72     }
    73     return res;
    74   }
    76   static double[] exp_values(int nb) {
    77     double[] res = new double[nb];
    78     for (int i = 0; i < nb; i++) {
    79       double ylogx = (1 + (r.nextDouble() * 2045)) - 1023; // 2045 rather than 2046 as a safety margin
    80       double x = Math.E;
    81       double logx = Math.log(x) / Math.log(2);
    82       double y = ylogx / logx;
    83       res[i] = y;
    84     }
    85     return res;
    86   }
    88   static public void main(String[] args) {
    89     {
    90       // warmup
    91       double[][] warmup_values = pow_values(10);
    92       m_pow(warmup_values);
    94       for (int i = 0; i < 20000; i++) {
    95         m_pow(warmup_values);
    96       }
    97       // test pow perf
    98       double[][] values = pow_values(1000000);
    99       System.out.println("==> POW " + m_pow(values));
   101       // force uncommon trap
   102       double[][] nan_values = new double[1][2];
   103       nan_values[0][0] = Double.NaN;
   104       nan_values[0][1] = Double.NaN;
   105       m_pow(nan_values);
   107       // force recompilation
   108       for (int i = 0; i < 20000; i++) {
   109         m_pow(warmup_values);
   110       }
   112       // test pow perf again
   113       System.out.println("==> POW " + m_pow(values));
   114     }
   115     {
   116       // warmup
   117       double[] warmup_values = exp_values(10);
   118       m_exp(warmup_values);
   120       for (int i = 0; i < 20000; i++) {
   121         m_exp(warmup_values);
   122       }
   124       // test pow perf
   125       double[] values = exp_values(1000000);
   126       System.out.println("==> EXP " + m_exp(values));
   128       // force uncommon trap
   129       double[] nan_values = new double[1];
   130       nan_values[0] = Double.NaN;
   131       m_exp(nan_values);
   133       // force recompilation
   134       for (int i = 0; i < 20000; i++) {
   135         m_exp(warmup_values);
   136       }
   138       // test pow perf again
   139       System.out.println("==> EXP " + m_exp(values));
   140     }
   141   }
   142 }

mercurial