hotspot/test/compiler/c2/Test7177917.java
author tpivovarova
Tue, 12 Jul 2016 18:24:48 +0300
changeset 40059 c2304140ed64
parent 30604 hotspot/test/compiler/c2/7177917/Test7177917.java@b8d532cb6420
child 40631 ed82623d7831
permissions -rw-r--r--
8132919: Put compiler tests in packages Reviewed-by: vlivanov, dpochepk Contributed-by: igor.ignatyev@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
13203
d10fd0d3cb27 7177917: Failed test java/lang/Math/PowTests.java
roland
parents:
diff changeset
     1
/*
30604
b8d532cb6420 8067013: Rename the com.oracle.java.testlibary package
ykantser
parents: 27699
diff changeset
     2
 * Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved.
13203
d10fd0d3cb27 7177917: Failed test java/lang/Math/PowTests.java
roland
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
d10fd0d3cb27 7177917: Failed test java/lang/Math/PowTests.java
roland
parents:
diff changeset
     4
 *
d10fd0d3cb27 7177917: Failed test java/lang/Math/PowTests.java
roland
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
d10fd0d3cb27 7177917: Failed test java/lang/Math/PowTests.java
roland
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
d10fd0d3cb27 7177917: Failed test java/lang/Math/PowTests.java
roland
parents:
diff changeset
     7
 * published by the Free Software Foundation.
d10fd0d3cb27 7177917: Failed test java/lang/Math/PowTests.java
roland
parents:
diff changeset
     8
 *
d10fd0d3cb27 7177917: Failed test java/lang/Math/PowTests.java
roland
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
d10fd0d3cb27 7177917: Failed test java/lang/Math/PowTests.java
roland
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
d10fd0d3cb27 7177917: Failed test java/lang/Math/PowTests.java
roland
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
d10fd0d3cb27 7177917: Failed test java/lang/Math/PowTests.java
roland
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
d10fd0d3cb27 7177917: Failed test java/lang/Math/PowTests.java
roland
parents:
diff changeset
    13
 * accompanied this code).
d10fd0d3cb27 7177917: Failed test java/lang/Math/PowTests.java
roland
parents:
diff changeset
    14
 *
d10fd0d3cb27 7177917: Failed test java/lang/Math/PowTests.java
roland
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
d10fd0d3cb27 7177917: Failed test java/lang/Math/PowTests.java
roland
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
d10fd0d3cb27 7177917: Failed test java/lang/Math/PowTests.java
roland
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
d10fd0d3cb27 7177917: Failed test java/lang/Math/PowTests.java
roland
parents:
diff changeset
    18
 *
d10fd0d3cb27 7177917: Failed test java/lang/Math/PowTests.java
roland
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
d10fd0d3cb27 7177917: Failed test java/lang/Math/PowTests.java
roland
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
d10fd0d3cb27 7177917: Failed test java/lang/Math/PowTests.java
roland
parents:
diff changeset
    21
 * questions.
d10fd0d3cb27 7177917: Failed test java/lang/Math/PowTests.java
roland
parents:
diff changeset
    22
 *
d10fd0d3cb27 7177917: Failed test java/lang/Math/PowTests.java
roland
parents:
diff changeset
    23
 */
d10fd0d3cb27 7177917: Failed test java/lang/Math/PowTests.java
roland
parents:
diff changeset
    24
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 30604
diff changeset
    25
/**
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 30604
diff changeset
    26
 * @test
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 30604
diff changeset
    27
 * @bug 7177917
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 30604
diff changeset
    28
 * @summary Micro-benchmark for Math.pow() and Math.exp()
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 30604
diff changeset
    29
 * @modules java.base/jdk.internal.misc
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 30604
diff changeset
    30
 * @library /testlibrary
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 30604
diff changeset
    31
 *
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 30604
diff changeset
    32
 * @run main compiler.c2.Test7177917
13203
d10fd0d3cb27 7177917: Failed test java/lang/Math/PowTests.java
roland
parents:
diff changeset
    33
 */
d10fd0d3cb27 7177917: Failed test java/lang/Math/PowTests.java
roland
parents:
diff changeset
    34
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 30604
diff changeset
    35
package compiler.c2;
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 30604
diff changeset
    36
30604
b8d532cb6420 8067013: Rename the com.oracle.java.testlibary package
ykantser
parents: 27699
diff changeset
    37
import jdk.test.lib.Utils;
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 30604
diff changeset
    38
27453
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents: 13203
diff changeset
    39
import java.util.Random;
13203
d10fd0d3cb27 7177917: Failed test java/lang/Math/PowTests.java
roland
parents:
diff changeset
    40
d10fd0d3cb27 7177917: Failed test java/lang/Math/PowTests.java
roland
parents:
diff changeset
    41
public class Test7177917 {
d10fd0d3cb27 7177917: Failed test java/lang/Math/PowTests.java
roland
parents:
diff changeset
    42
d10fd0d3cb27 7177917: Failed test java/lang/Math/PowTests.java
roland
parents:
diff changeset
    43
  static double d;
d10fd0d3cb27 7177917: Failed test java/lang/Math/PowTests.java
roland
parents:
diff changeset
    44
27453
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents: 13203
diff changeset
    45
  static final Random R = Utils.getRandomInstance();
13203
d10fd0d3cb27 7177917: Failed test java/lang/Math/PowTests.java
roland
parents:
diff changeset
    46
d10fd0d3cb27 7177917: Failed test java/lang/Math/PowTests.java
roland
parents:
diff changeset
    47
  static long  m_pow(double[][] values) {
d10fd0d3cb27 7177917: Failed test java/lang/Math/PowTests.java
roland
parents:
diff changeset
    48
    double res = 0;
d10fd0d3cb27 7177917: Failed test java/lang/Math/PowTests.java
roland
parents:
diff changeset
    49
    long start = System.nanoTime();
d10fd0d3cb27 7177917: Failed test java/lang/Math/PowTests.java
roland
parents:
diff changeset
    50
    for (int i = 0; i < values.length; i++) {
d10fd0d3cb27 7177917: Failed test java/lang/Math/PowTests.java
roland
parents:
diff changeset
    51
      res += Math.pow(values[i][0], values[i][1]);
d10fd0d3cb27 7177917: Failed test java/lang/Math/PowTests.java
roland
parents:
diff changeset
    52
    }
d10fd0d3cb27 7177917: Failed test java/lang/Math/PowTests.java
roland
parents:
diff changeset
    53
    long stop = System.nanoTime();
d10fd0d3cb27 7177917: Failed test java/lang/Math/PowTests.java
roland
parents:
diff changeset
    54
    d = res;
d10fd0d3cb27 7177917: Failed test java/lang/Math/PowTests.java
roland
parents:
diff changeset
    55
    return (stop - start) / 1000;
d10fd0d3cb27 7177917: Failed test java/lang/Math/PowTests.java
roland
parents:
diff changeset
    56
  }
d10fd0d3cb27 7177917: Failed test java/lang/Math/PowTests.java
roland
parents:
diff changeset
    57
d10fd0d3cb27 7177917: Failed test java/lang/Math/PowTests.java
roland
parents:
diff changeset
    58
  static long  m_exp(double[] values) {
d10fd0d3cb27 7177917: Failed test java/lang/Math/PowTests.java
roland
parents:
diff changeset
    59
    double res = 0;
d10fd0d3cb27 7177917: Failed test java/lang/Math/PowTests.java
roland
parents:
diff changeset
    60
    long start = System.nanoTime();
d10fd0d3cb27 7177917: Failed test java/lang/Math/PowTests.java
roland
parents:
diff changeset
    61
    for (int i = 0; i < values.length; i++) {
d10fd0d3cb27 7177917: Failed test java/lang/Math/PowTests.java
roland
parents:
diff changeset
    62
      res += Math.exp(values[i]);
d10fd0d3cb27 7177917: Failed test java/lang/Math/PowTests.java
roland
parents:
diff changeset
    63
    }
d10fd0d3cb27 7177917: Failed test java/lang/Math/PowTests.java
roland
parents:
diff changeset
    64
    long stop = System.nanoTime();
d10fd0d3cb27 7177917: Failed test java/lang/Math/PowTests.java
roland
parents:
diff changeset
    65
    d = res;
d10fd0d3cb27 7177917: Failed test java/lang/Math/PowTests.java
roland
parents:
diff changeset
    66
    return (stop - start) / 1000;
d10fd0d3cb27 7177917: Failed test java/lang/Math/PowTests.java
roland
parents:
diff changeset
    67
  }
d10fd0d3cb27 7177917: Failed test java/lang/Math/PowTests.java
roland
parents:
diff changeset
    68
d10fd0d3cb27 7177917: Failed test java/lang/Math/PowTests.java
roland
parents:
diff changeset
    69
  static double[][] pow_values(int nb) {
d10fd0d3cb27 7177917: Failed test java/lang/Math/PowTests.java
roland
parents:
diff changeset
    70
    double[][] res = new double[nb][2];
d10fd0d3cb27 7177917: Failed test java/lang/Math/PowTests.java
roland
parents:
diff changeset
    71
    for (int i = 0; i < nb; i++) {
27453
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents: 13203
diff changeset
    72
      double ylogx = (1 + (R.nextDouble() * 2045)) - 1023; // 2045 rather than 2046 as a safety margin
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents: 13203
diff changeset
    73
      double x = Math.abs(Double.longBitsToDouble(R.nextLong()));
13203
d10fd0d3cb27 7177917: Failed test java/lang/Math/PowTests.java
roland
parents:
diff changeset
    74
      while (x != x) {
27453
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents: 13203
diff changeset
    75
        x = Math.abs(Double.longBitsToDouble(R.nextLong()));
13203
d10fd0d3cb27 7177917: Failed test java/lang/Math/PowTests.java
roland
parents:
diff changeset
    76
      }
d10fd0d3cb27 7177917: Failed test java/lang/Math/PowTests.java
roland
parents:
diff changeset
    77
      double logx = Math.log(x) / Math.log(2);
d10fd0d3cb27 7177917: Failed test java/lang/Math/PowTests.java
roland
parents:
diff changeset
    78
      double y = ylogx / logx;
d10fd0d3cb27 7177917: Failed test java/lang/Math/PowTests.java
roland
parents:
diff changeset
    79
d10fd0d3cb27 7177917: Failed test java/lang/Math/PowTests.java
roland
parents:
diff changeset
    80
      res[i][0] = x;
d10fd0d3cb27 7177917: Failed test java/lang/Math/PowTests.java
roland
parents:
diff changeset
    81
      res[i][1] = y;
d10fd0d3cb27 7177917: Failed test java/lang/Math/PowTests.java
roland
parents:
diff changeset
    82
    }
d10fd0d3cb27 7177917: Failed test java/lang/Math/PowTests.java
roland
parents:
diff changeset
    83
    return res;
d10fd0d3cb27 7177917: Failed test java/lang/Math/PowTests.java
roland
parents:
diff changeset
    84
  }
d10fd0d3cb27 7177917: Failed test java/lang/Math/PowTests.java
roland
parents:
diff changeset
    85
d10fd0d3cb27 7177917: Failed test java/lang/Math/PowTests.java
roland
parents:
diff changeset
    86
  static double[] exp_values(int nb) {
d10fd0d3cb27 7177917: Failed test java/lang/Math/PowTests.java
roland
parents:
diff changeset
    87
    double[] res = new double[nb];
d10fd0d3cb27 7177917: Failed test java/lang/Math/PowTests.java
roland
parents:
diff changeset
    88
    for (int i = 0; i < nb; i++) {
27453
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents: 13203
diff changeset
    89
      double ylogx = (1 + (R.nextDouble() * 2045)) - 1023; // 2045 rather than 2046 as a safety margin
13203
d10fd0d3cb27 7177917: Failed test java/lang/Math/PowTests.java
roland
parents:
diff changeset
    90
      double x = Math.E;
d10fd0d3cb27 7177917: Failed test java/lang/Math/PowTests.java
roland
parents:
diff changeset
    91
      double logx = Math.log(x) / Math.log(2);
d10fd0d3cb27 7177917: Failed test java/lang/Math/PowTests.java
roland
parents:
diff changeset
    92
      double y = ylogx / logx;
d10fd0d3cb27 7177917: Failed test java/lang/Math/PowTests.java
roland
parents:
diff changeset
    93
      res[i] = y;
d10fd0d3cb27 7177917: Failed test java/lang/Math/PowTests.java
roland
parents:
diff changeset
    94
    }
d10fd0d3cb27 7177917: Failed test java/lang/Math/PowTests.java
roland
parents:
diff changeset
    95
    return res;
d10fd0d3cb27 7177917: Failed test java/lang/Math/PowTests.java
roland
parents:
diff changeset
    96
  }
d10fd0d3cb27 7177917: Failed test java/lang/Math/PowTests.java
roland
parents:
diff changeset
    97
d10fd0d3cb27 7177917: Failed test java/lang/Math/PowTests.java
roland
parents:
diff changeset
    98
  static public void main(String[] args) {
d10fd0d3cb27 7177917: Failed test java/lang/Math/PowTests.java
roland
parents:
diff changeset
    99
    {
d10fd0d3cb27 7177917: Failed test java/lang/Math/PowTests.java
roland
parents:
diff changeset
   100
      // warmup
d10fd0d3cb27 7177917: Failed test java/lang/Math/PowTests.java
roland
parents:
diff changeset
   101
      double[][] warmup_values = pow_values(10);
d10fd0d3cb27 7177917: Failed test java/lang/Math/PowTests.java
roland
parents:
diff changeset
   102
      m_pow(warmup_values);
d10fd0d3cb27 7177917: Failed test java/lang/Math/PowTests.java
roland
parents:
diff changeset
   103
d10fd0d3cb27 7177917: Failed test java/lang/Math/PowTests.java
roland
parents:
diff changeset
   104
      for (int i = 0; i < 20000; i++) {
d10fd0d3cb27 7177917: Failed test java/lang/Math/PowTests.java
roland
parents:
diff changeset
   105
        m_pow(warmup_values);
d10fd0d3cb27 7177917: Failed test java/lang/Math/PowTests.java
roland
parents:
diff changeset
   106
      }
d10fd0d3cb27 7177917: Failed test java/lang/Math/PowTests.java
roland
parents:
diff changeset
   107
      // test pow perf
d10fd0d3cb27 7177917: Failed test java/lang/Math/PowTests.java
roland
parents:
diff changeset
   108
      double[][] values = pow_values(1000000);
d10fd0d3cb27 7177917: Failed test java/lang/Math/PowTests.java
roland
parents:
diff changeset
   109
      System.out.println("==> POW " + m_pow(values));
d10fd0d3cb27 7177917: Failed test java/lang/Math/PowTests.java
roland
parents:
diff changeset
   110
d10fd0d3cb27 7177917: Failed test java/lang/Math/PowTests.java
roland
parents:
diff changeset
   111
      // force uncommon trap
d10fd0d3cb27 7177917: Failed test java/lang/Math/PowTests.java
roland
parents:
diff changeset
   112
      double[][] nan_values = new double[1][2];
d10fd0d3cb27 7177917: Failed test java/lang/Math/PowTests.java
roland
parents:
diff changeset
   113
      nan_values[0][0] = Double.NaN;
d10fd0d3cb27 7177917: Failed test java/lang/Math/PowTests.java
roland
parents:
diff changeset
   114
      nan_values[0][1] = Double.NaN;
d10fd0d3cb27 7177917: Failed test java/lang/Math/PowTests.java
roland
parents:
diff changeset
   115
      m_pow(nan_values);
d10fd0d3cb27 7177917: Failed test java/lang/Math/PowTests.java
roland
parents:
diff changeset
   116
d10fd0d3cb27 7177917: Failed test java/lang/Math/PowTests.java
roland
parents:
diff changeset
   117
      // force recompilation
d10fd0d3cb27 7177917: Failed test java/lang/Math/PowTests.java
roland
parents:
diff changeset
   118
      for (int i = 0; i < 20000; i++) {
d10fd0d3cb27 7177917: Failed test java/lang/Math/PowTests.java
roland
parents:
diff changeset
   119
        m_pow(warmup_values);
d10fd0d3cb27 7177917: Failed test java/lang/Math/PowTests.java
roland
parents:
diff changeset
   120
      }
d10fd0d3cb27 7177917: Failed test java/lang/Math/PowTests.java
roland
parents:
diff changeset
   121
d10fd0d3cb27 7177917: Failed test java/lang/Math/PowTests.java
roland
parents:
diff changeset
   122
      // test pow perf again
d10fd0d3cb27 7177917: Failed test java/lang/Math/PowTests.java
roland
parents:
diff changeset
   123
      System.out.println("==> POW " + m_pow(values));
d10fd0d3cb27 7177917: Failed test java/lang/Math/PowTests.java
roland
parents:
diff changeset
   124
    }
d10fd0d3cb27 7177917: Failed test java/lang/Math/PowTests.java
roland
parents:
diff changeset
   125
    {
d10fd0d3cb27 7177917: Failed test java/lang/Math/PowTests.java
roland
parents:
diff changeset
   126
      // warmup
d10fd0d3cb27 7177917: Failed test java/lang/Math/PowTests.java
roland
parents:
diff changeset
   127
      double[] warmup_values = exp_values(10);
d10fd0d3cb27 7177917: Failed test java/lang/Math/PowTests.java
roland
parents:
diff changeset
   128
      m_exp(warmup_values);
d10fd0d3cb27 7177917: Failed test java/lang/Math/PowTests.java
roland
parents:
diff changeset
   129
d10fd0d3cb27 7177917: Failed test java/lang/Math/PowTests.java
roland
parents:
diff changeset
   130
      for (int i = 0; i < 20000; i++) {
d10fd0d3cb27 7177917: Failed test java/lang/Math/PowTests.java
roland
parents:
diff changeset
   131
        m_exp(warmup_values);
d10fd0d3cb27 7177917: Failed test java/lang/Math/PowTests.java
roland
parents:
diff changeset
   132
      }
d10fd0d3cb27 7177917: Failed test java/lang/Math/PowTests.java
roland
parents:
diff changeset
   133
d10fd0d3cb27 7177917: Failed test java/lang/Math/PowTests.java
roland
parents:
diff changeset
   134
      // test pow perf
d10fd0d3cb27 7177917: Failed test java/lang/Math/PowTests.java
roland
parents:
diff changeset
   135
      double[] values = exp_values(1000000);
d10fd0d3cb27 7177917: Failed test java/lang/Math/PowTests.java
roland
parents:
diff changeset
   136
      System.out.println("==> EXP " + m_exp(values));
d10fd0d3cb27 7177917: Failed test java/lang/Math/PowTests.java
roland
parents:
diff changeset
   137
d10fd0d3cb27 7177917: Failed test java/lang/Math/PowTests.java
roland
parents:
diff changeset
   138
      // force uncommon trap
d10fd0d3cb27 7177917: Failed test java/lang/Math/PowTests.java
roland
parents:
diff changeset
   139
      double[] nan_values = new double[1];
d10fd0d3cb27 7177917: Failed test java/lang/Math/PowTests.java
roland
parents:
diff changeset
   140
      nan_values[0] = Double.NaN;
d10fd0d3cb27 7177917: Failed test java/lang/Math/PowTests.java
roland
parents:
diff changeset
   141
      m_exp(nan_values);
d10fd0d3cb27 7177917: Failed test java/lang/Math/PowTests.java
roland
parents:
diff changeset
   142
d10fd0d3cb27 7177917: Failed test java/lang/Math/PowTests.java
roland
parents:
diff changeset
   143
      // force recompilation
d10fd0d3cb27 7177917: Failed test java/lang/Math/PowTests.java
roland
parents:
diff changeset
   144
      for (int i = 0; i < 20000; i++) {
d10fd0d3cb27 7177917: Failed test java/lang/Math/PowTests.java
roland
parents:
diff changeset
   145
        m_exp(warmup_values);
d10fd0d3cb27 7177917: Failed test java/lang/Math/PowTests.java
roland
parents:
diff changeset
   146
      }
d10fd0d3cb27 7177917: Failed test java/lang/Math/PowTests.java
roland
parents:
diff changeset
   147
d10fd0d3cb27 7177917: Failed test java/lang/Math/PowTests.java
roland
parents:
diff changeset
   148
      // test pow perf again
d10fd0d3cb27 7177917: Failed test java/lang/Math/PowTests.java
roland
parents:
diff changeset
   149
      System.out.println("==> EXP " + m_exp(values));
d10fd0d3cb27 7177917: Failed test java/lang/Math/PowTests.java
roland
parents:
diff changeset
   150
    }
d10fd0d3cb27 7177917: Failed test java/lang/Math/PowTests.java
roland
parents:
diff changeset
   151
  }
d10fd0d3cb27 7177917: Failed test java/lang/Math/PowTests.java
roland
parents:
diff changeset
   152
}