Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8263006: Add optimization for Max(*)Node and Min(*)Node #3513

Closed
wants to merge 4 commits into from

Conversation

@Wanghuang-Huawei
Copy link

@Wanghuang-Huawei Wanghuang-Huawei commented Apr 15, 2021

  • I optimize max and min by using these identities

    • op (max(a,b) , min(a,b))=== op(a,b)
    • if op is commutable
    • example :
      • max(a,b) + min(a,b))=== a + b // op = add
      • max(a,b) * min(a,b))=== a * b // op = mul
      • max( max(a,b) , min(a,b)))=== max(a,b) // op = max()
      • min( max(a,b) , min(a,b)))=== max(a,b) // op = min()
  • Test case

    /*
     * Copyright (c) 2021, Huawei Technologies Co. Ltd. All rights reserved.
     * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     *
     * This code is free software; you can redistribute it and/or modify it
     * under the terms of the GNU General Public License version 2 only, as
     * published by the Free Software Foundation.
     *
     * This code is distributed in the hope that it will be useful, but WITHOUT
     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
     * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
     * version 2 for more details (a copy is included in the LICENSE file that
     * accompanied this code).
     *
     * You should have received a copy of the GNU General Public License version
     * 2 along with this work; if not, write to the Free Software Foundation,
     * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
     *
     * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
     * or visit www.oracle.com if you need additional information or have any
     * questions.
     */
    package org.sample;
    
    import org.openjdk.jmh.annotations.Benchmark;
    import org.openjdk.jmh.annotations.*;
    
    import java.util.Random;
    import java.util.concurrent.TimeUnit;
    import org.openjdk.jmh.infra.Blackhole;
    
    @BenchmarkMode({Mode.AverageTime})
    @OutputTimeUnit(TimeUnit.MICROSECONDS)
    public class MyBenchmark {
    
        static int length = 100000;
        static double[] data1 = new double[length];
        static double[] data2 = new double[length];
        static Random random = new Random();
    
        static {
            for(int i = 0; i < length; ++i) {
              data1[i] = random.nextDouble();
              data2[i] = random.nextDouble();
            }
        }
    
        @Benchmark
        public void testAdd(Blackhole bh) {
          double sum = 0;
          for (int i = 0; i < length; i++) {
              sum += Math.max(data1[i], data2[i]) + Math.min(data1[i], data2[i]);
          }
          bh.consume(sum);
        }
    
        @Benchmark
        public void testMax(Blackhole bh) {
            double sum = 0;
            for (int i = 0; i < length; i++) {
                sum += Math.max(Math.max(data1[i], data2[i]), Math.min(data1[i], data2[i]));
            }
            bh.consume(sum);
        }
    
        @Benchmark
        public void testMin(Blackhole bh) {
            double sum = 0;
            for (int i = 0; i < length; i++) {
                sum += Math.min(Math.max(data1[i], data2[i]), Math.min(data1[i], data2[i]));
            }
            bh.consume(sum);
        }
    
        @Benchmark
        public void testMul(Blackhole bh) {
            double sum = 0;
            for (int i = 0; i < length; i++) {
                sum += (Math.max(data1[i], data2[i]) * Math.min(data1[i], data2[i]));
            }
            bh.consume(sum);
        }
    }
  • The result is listed here (aarch64):

before:

Benchmark Mode Samples Score Score error Units
o.s.MyBenchmark.testAdd avgt 10 556.048 32.368 us/op
o.s.MyBenchmark.testMax avgt 10 543.065 54.221 us/op
o.s.MyBenchmark.testMin avgt 10 570.731 37.630 us/op
o.s.MyBenchmark.testMul avgt 10 531.906 20.518 us/op

after:

Benchmark Mode Samples Score Score error Units
o.s.MyBenchmark.testAdd avgt 10 319.350 9.248 us/op
o.s.MyBenchmark.testMax avgt 10 356.138 10.736 us/op
o.s.MyBenchmark.testMin avgt 10 323.731 16.621 us/op
o.s.MyBenchmark.testMul avgt 10 338.458 23.755 us/op
  • I have tested NaN INFINITY and -INFINITY and got same result (before/after)

Progress

  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue
  • Change must be properly reviewed

Issue

  • JDK-8263006: Add optimization for Max()Node and Min()Node

Reviewers

Contributors

  • Wang Huang <whuang@openjdk.org>
  • Wu Yan <wuyan34@huawei.com>

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.java.net/jdk pull/3513/head:pull/3513
$ git checkout pull/3513

Update a local copy of the PR:
$ git checkout pull/3513
$ git pull https://git.openjdk.java.net/jdk pull/3513/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 3513

View PR using the GUI difftool:
$ git pr show -t 3513

Using diff file

Download this PR as a diff file:
https://git.openjdk.java.net/jdk/pull/3513.diff

@bridgekeeper
Copy link

@bridgekeeper bridgekeeper bot commented Apr 15, 2021

👋 Welcome back whuang! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

Loading

@openjdk openjdk bot added the rfr label Apr 15, 2021
@Wanghuang-Huawei
Copy link
Author

@Wanghuang-Huawei Wanghuang-Huawei commented Apr 15, 2021

/contributor add Wang Huang whuang@openjdk.org
/contributor add Wu Yan wuyan34@huawei.com

Loading

@openjdk
Copy link

@openjdk openjdk bot commented Apr 15, 2021

@Wanghuang-Huawei The following label will be automatically applied to this pull request:

  • hotspot-compiler

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.

Loading

@openjdk
Copy link

@openjdk openjdk bot commented Apr 15, 2021

@Wanghuang-Huawei
Contributor Wang Huang <whuang@openjdk.org> successfully added.

Loading

@openjdk
Copy link

@openjdk openjdk bot commented Apr 15, 2021

@Wanghuang-Huawei
Contributor Wu Yan <wuyan34@huawei.com> successfully added.

Loading

@mlbridge
Copy link

@mlbridge mlbridge bot commented Apr 15, 2021

Loading

@Wanghuang-Huawei
Copy link
Author

@Wanghuang-Huawei Wanghuang-Huawei commented Apr 17, 2021

@vnkozlov Can you do me a favor to review this optimization? Thank you very much.

Loading

@vnkozlov
Copy link
Contributor

@vnkozlov vnkozlov commented Apr 17, 2021

Do you have a real example in Java applications which benefit from this optimization?
We should not add and support code which would never be used in real world.

Optimization will not work for Integer because of _min and _max intrinsic which generates cmove:
https://github.com/openjdk/jdk/blob/master/src/hotspot/share/opto/library_call.cpp#L1806

I am not sure if this optimization will always work for float/double because of NaN values.

You need to verify results for all edge cases.

Loading

@Wanghuang-Huawei
Copy link
Author

@Wanghuang-Huawei Wanghuang-Huawei commented Apr 17, 2021

Thank you for your review.

Do you have a real example in Java applications which benefit from this optimization?
We should not add and support code which would never be used in real world.

Yes. We refined this optimization from our internal software experience. For instance, the model min( max(a,b) , min(a,b))) exists in many source codes in some AI projects.

Optimization will not work for Integer because of _min and _max intrinsic which generates cmove:
https://github.com/openjdk/jdk/blob/master/src/hotspot/share/opto/library_call.cpp#L1806

Yes. Adding MaxINode's max_opcode is just for max_opcode method is abstract. Our test cases is for float types only.

I am not sure if this optimization will always work for float/double because of NaN values.

You need to verify results for all edge cases.

I have tested that and showed in my comments. The test cases for NaN values and other special values are listed here

import java.lang.Math;

public class Test {

    public static void main(String[] args) throws Exception {
      Test m = new Test();
      m.test();
    }

    public void test() throws Exception {
      double[] num = new double[9];
      num[0] = 1; num[1] = 0; num[2] = -0;
      num[3] = Double.POSITIVE_INFINITY; 
      num[4] = Double.NEGATIVE_INFINITY;
      num[5] = Double.NaN;
      num[6] = Double.MAX_VALUE;
      num[7] = Double.MIN_VALUE;
      num[8] = Double.MIN_NORMAL;

      for(int i = 0; i < 9; i++) {
        for(int j = 0; j < 9; j++) {
          check(add_opt(num[i], num[j]), (num[i] + num[j]));
          check(mul_opt(num[i], num[j]), (num[i] * num[j]));
          check(max_opt(num[i], num[j]), Math.max(num[i], num[j]));
          check(min_opt(num[i], num[j]), Math.min(num[i], num[j]));
        } 
      }
    }

    public void check(double a, double b) {
      if (a != b) {
        System.out.println("false");
        System.out.println(a);
        System.out.println(b);
        System.out.println();
      }
    }

    public double add_opt(double a, double b) throws Exception {
      return Math.max(a, b) + Math.min(a, b);
    }

    public double mul_opt(double a, double b) throws Exception {
      return Math.max(a, b) * Math.min(a, b);
    }

    public double max_opt(double a, double b) throws Exception {
      return Math.max(Math.max(a, b), Math.min(a, b));
    }

    public double min_opt(double a, double b) throws Exception {
      return Math.min(Math.max(a, b), Math.min(a, b));
    }
}

The NaN is a special case. Because NaN == NaN is false in Java, so I run the case and check the result.

Should I add the other test cases for NaN ?

Loading

@vnkozlov
Copy link
Contributor

@vnkozlov vnkozlov commented Apr 19, 2021

Thank you for answers.
The test should be part of changes.

Loading

Copy link
Contributor

@mgkwill mgkwill left a comment

Running MyBenchmark test listed in the summary on x86_64 Haswell XEON with this patch results in:

# Benchmark: org.sample.MyBenchmark.testMax

# Run progress: 25.00% complete, ETA 00:03:57
# Fork: 1 of 1                                                                                                                                                              # Warmup Iteration   1: 112.714 us/op
# Warmup Iteration   2: # To suppress the following error report, specify this argument
# after -XX: or in .hotspotrc:  SuppressErrorAt=/register.hpp:152                                                                                                           #
# A fatal error has been detected by the Java Runtime Environment:
#
#  Internal Error (/home/mgkwill/src/git/jdk/src/hotspot/share/asm/register.hpp:152), pid=3450238, tid=3450253
#  assert(a != b && a != c && a != d && a != e && b != c && b != d && b != e && c != d && c != e && d != e) failed: registers must be different: a=0x0000000000000001, b=0x0000000000000001, c=0x0000000000000003, d=0x0000000000000004, e=0x0000000000000005
#
# JRE version: OpenJDK Runtime Environment (17.0) (slowdebug build 17-internal+0-adhoc.mgkwill.jdk) 

AND

# Benchmark: org.sample.MyBenchmark.testMin

# Run progress: 25.00% complete, ETA 00:03:57
# Fork: 1 of 1
# Warmup Iteration   1: 112.445 us/op
# Warmup Iteration   2: # To suppress the following error report, specify this argument
# after -XX: or in .hotspotrc:  SuppressErrorAt=/register.hpp:152
#
# A fatal error has been detected by the Java Runtime Environment:
#
#  Internal Error (/home/mgkwill/src/git/jdk/src/hotspot/share/asm/register.hpp:152), pid=3450444, tid=3450481
#  assert(a != b && a != c && a != d && a != e && b != c && b != d && b != e && c != d && c != e && d != e) failed: registers must be different: a=0x0000000000000001, b=0x0000000000000001, c=0x0000000000000003, d=0x0000000000000004, e=0x0000000000000005
#
# JRE version: OpenJDK Runtime Environment (17.0) (slowdebug build 17-internal+0-adhoc.mgkwill.jdk)

Otherwise the results are below.

Baseline
Benchmark            Mode  Cnt    Score     Error  Units
MyBenchmark.testAdd  avgt    5  149.581 ?  13.626  us/op
MyBenchmark.testMax  avgt    5  223.362 ? 195.007  us/op
MyBenchmark.testMin  avgt    5  206.096 ?  16.840  us/op
MyBenchmark.testMul  avgt    5  149.366 ?   9.558  us/op
Finished running test 'micro:MyBenchmark'
Benchmark            Mode  Cnt    Score   Error  Units
MyBenchmark.testAdd  avgt    5  107.874 ? 0.148  us/op
MyBenchmark.testMul  avgt    5  107.881 ? 0.015  us/op
Finished running test 'micro:MyBenchmark'

Loading

@Wanghuang-Huawei
Copy link
Author

@Wanghuang-Huawei Wanghuang-Huawei commented Apr 22, 2021

Running MyBenchmark test listed in the summary on x86_64 Haswell XEON with this patch results in:

# Benchmark: org.sample.MyBenchmark.testMax

# Run progress: 25.00% complete, ETA 00:03:57
# Fork: 1 of 1                                                                                                                                                              # Warmup Iteration   1: 112.714 us/op
# Warmup Iteration   2: # To suppress the following error report, specify this argument
# after -XX: or in .hotspotrc:  SuppressErrorAt=/register.hpp:152                                                                                                           #
# A fatal error has been detected by the Java Runtime Environment:
#
#  Internal Error (/home/mgkwill/src/git/jdk/src/hotspot/share/asm/register.hpp:152), pid=3450238, tid=3450253
#  assert(a != b && a != c && a != d && a != e && b != c && b != d && b != e && c != d && c != e && d != e) failed: registers must be different: a=0x0000000000000001, b=0x0000000000000001, c=0x0000000000000003, d=0x0000000000000004, e=0x0000000000000005
#
# JRE version: OpenJDK Runtime Environment (17.0) (slowdebug build 17-internal+0-adhoc.mgkwill.jdk) 

AND

# Benchmark: org.sample.MyBenchmark.testMin

# Run progress: 25.00% complete, ETA 00:03:57
# Fork: 1 of 1
# Warmup Iteration   1: 112.445 us/op
# Warmup Iteration   2: # To suppress the following error report, specify this argument
# after -XX: or in .hotspotrc:  SuppressErrorAt=/register.hpp:152
#
# A fatal error has been detected by the Java Runtime Environment:
#
#  Internal Error (/home/mgkwill/src/git/jdk/src/hotspot/share/asm/register.hpp:152), pid=3450444, tid=3450481
#  assert(a != b && a != c && a != d && a != e && b != c && b != d && b != e && c != d && c != e && d != e) failed: registers must be different: a=0x0000000000000001, b=0x0000000000000001, c=0x0000000000000003, d=0x0000000000000004, e=0x0000000000000005
#
# JRE version: OpenJDK Runtime Environment (17.0) (slowdebug build 17-internal+0-adhoc.mgkwill.jdk)

Otherwise the results are below.

Baseline
Benchmark            Mode  Cnt    Score     Error  Units
MyBenchmark.testAdd  avgt    5  149.581 ?  13.626  us/op
MyBenchmark.testMax  avgt    5  223.362 ? 195.007  us/op
MyBenchmark.testMin  avgt    5  206.096 ?  16.840  us/op
MyBenchmark.testMul  avgt    5  149.366 ?   9.558  us/op
Finished running test 'micro:MyBenchmark'
Benchmark            Mode  Cnt    Score   Error  Units
MyBenchmark.testAdd  avgt    5  107.874 ? 0.148  us/op
MyBenchmark.testMul  avgt    5  107.881 ? 0.015  us/op
Finished running test 'micro:MyBenchmark'

MyBenchmark.testAdd avgt 5 149.581 ? 13.626 us/op
MyBenchmark.testMax avgt 5 223.362 ? 195.007 us/op
MyBenchmark.testMin avgt 5 206.096 ? 16.840 us/op
MyBenchmark.testMul avgt 5 149.366 ? 9.558 us/op

I run this test case by java -jar target/benchmarks.jar -i 10 -wi 10 -f 1 on Intel(R) Xeon(R) CPU E7-8890 v4 @ 2.20GHz without crash. Can you give me your jvm options and this crash log? Thank you very much.

Loading

@mgkwill
Copy link
Contributor

@mgkwill mgkwill commented Apr 22, 2021

Running MyBenchmark test listed in the summary on x86_64 Haswell XEON with this patch results in:

# Benchmark: org.sample.MyBenchmark.testMax

# Run progress: 25.00% complete, ETA 00:03:57
# Fork: 1 of 1                                                                                                                                                              # Warmup Iteration   1: 112.714 us/op
# Warmup Iteration   2: # To suppress the following error report, specify this argument
# after -XX: or in .hotspotrc:  SuppressErrorAt=/register.hpp:152                                                                                                           #
# A fatal error has been detected by the Java Runtime Environment:
#
#  Internal Error (/home/mgkwill/src/git/jdk/src/hotspot/share/asm/register.hpp:152), pid=3450238, tid=3450253
#  assert(a != b && a != c && a != d && a != e && b != c && b != d && b != e && c != d && c != e && d != e) failed: registers must be different: a=0x0000000000000001, b=0x0000000000000001, c=0x0000000000000003, d=0x0000000000000004, e=0x0000000000000005
#
# JRE version: OpenJDK Runtime Environment (17.0) (slowdebug build 17-internal+0-adhoc.mgkwill.jdk) 

AND

# Benchmark: org.sample.MyBenchmark.testMin

# Run progress: 25.00% complete, ETA 00:03:57
# Fork: 1 of 1
# Warmup Iteration   1: 112.445 us/op
# Warmup Iteration   2: # To suppress the following error report, specify this argument
# after -XX: or in .hotspotrc:  SuppressErrorAt=/register.hpp:152
#
# A fatal error has been detected by the Java Runtime Environment:
#
#  Internal Error (/home/mgkwill/src/git/jdk/src/hotspot/share/asm/register.hpp:152), pid=3450444, tid=3450481
#  assert(a != b && a != c && a != d && a != e && b != c && b != d && b != e && c != d && c != e && d != e) failed: registers must be different: a=0x0000000000000001, b=0x0000000000000001, c=0x0000000000000003, d=0x0000000000000004, e=0x0000000000000005
#
# JRE version: OpenJDK Runtime Environment (17.0) (slowdebug build 17-internal+0-adhoc.mgkwill.jdk)

Otherwise the results are below.

Baseline
Benchmark            Mode  Cnt    Score     Error  Units
MyBenchmark.testAdd  avgt    5  149.581 ?  13.626  us/op
MyBenchmark.testMax  avgt    5  223.362 ? 195.007  us/op
MyBenchmark.testMin  avgt    5  206.096 ?  16.840  us/op
MyBenchmark.testMul  avgt    5  149.366 ?   9.558  us/op
Finished running test 'micro:MyBenchmark'
Benchmark            Mode  Cnt    Score   Error  Units
MyBenchmark.testAdd  avgt    5  107.874 ? 0.148  us/op
MyBenchmark.testMul  avgt    5  107.881 ? 0.015  us/op
Finished running test 'micro:MyBenchmark'

MyBenchmark.testAdd avgt 5 149.581 ? 13.626 us/op
MyBenchmark.testMax avgt 5 223.362 ? 195.007 us/op
MyBenchmark.testMin avgt 5 206.096 ? 16.840 us/op
MyBenchmark.testMul avgt 5 149.366 ? 9.558 us/op

I run this test case by java -jar target/benchmarks.jar -i 10 -wi 10 -f 1 on Intel(R) Xeon(R) CPU E7-8890 v4 @ 2.20GHz without crash. Can you give me your jvm options and this crash log? Thank you very much.

Certainly. Tomorrow morning (my time) I will re-run with your command and test on a few other Xeons. I need to re-run to get crash logs (I'm jumping around between patches and cleaned already) but I will post those when I can recreate.

To run I copied MyBenchmark.java from summary to test/micro/org/openjdk/bench/vm/compiler/MyBenchmark.java
Command on running was:
make test TEST="micro:MyBenchmark" MICRO="FORK=1;WARMUP_ITER=2;" CONF=linux-x86_64-server-slowdebug

This worked on master, but on checkout of pr/3513 caused the errors above.

Loading

@Wanghuang-Huawei
Copy link
Author

@Wanghuang-Huawei Wanghuang-Huawei commented Apr 22, 2021

Running MyBenchmark test listed in the summary on x86_64 Haswell XEON with this patch results in:

# Benchmark: org.sample.MyBenchmark.testMax

# Run progress: 25.00% complete, ETA 00:03:57
# Fork: 1 of 1                                                                                                                                                              # Warmup Iteration   1: 112.714 us/op
# Warmup Iteration   2: # To suppress the following error report, specify this argument
# after -XX: or in .hotspotrc:  SuppressErrorAt=/register.hpp:152                                                                                                           #
# A fatal error has been detected by the Java Runtime Environment:
#
#  Internal Error (/home/mgkwill/src/git/jdk/src/hotspot/share/asm/register.hpp:152), pid=3450238, tid=3450253
#  assert(a != b && a != c && a != d && a != e && b != c && b != d && b != e && c != d && c != e && d != e) failed: registers must be different: a=0x0000000000000001, b=0x0000000000000001, c=0x0000000000000003, d=0x0000000000000004, e=0x0000000000000005
#
# JRE version: OpenJDK Runtime Environment (17.0) (slowdebug build 17-internal+0-adhoc.mgkwill.jdk) 

AND

# Benchmark: org.sample.MyBenchmark.testMin

# Run progress: 25.00% complete, ETA 00:03:57
# Fork: 1 of 1
# Warmup Iteration   1: 112.445 us/op
# Warmup Iteration   2: # To suppress the following error report, specify this argument
# after -XX: or in .hotspotrc:  SuppressErrorAt=/register.hpp:152
#
# A fatal error has been detected by the Java Runtime Environment:
#
#  Internal Error (/home/mgkwill/src/git/jdk/src/hotspot/share/asm/register.hpp:152), pid=3450444, tid=3450481
#  assert(a != b && a != c && a != d && a != e && b != c && b != d && b != e && c != d && c != e && d != e) failed: registers must be different: a=0x0000000000000001, b=0x0000000000000001, c=0x0000000000000003, d=0x0000000000000004, e=0x0000000000000005
#
# JRE version: OpenJDK Runtime Environment (17.0) (slowdebug build 17-internal+0-adhoc.mgkwill.jdk)

Otherwise the results are below.

Baseline
Benchmark            Mode  Cnt    Score     Error  Units
MyBenchmark.testAdd  avgt    5  149.581 ?  13.626  us/op
MyBenchmark.testMax  avgt    5  223.362 ? 195.007  us/op
MyBenchmark.testMin  avgt    5  206.096 ?  16.840  us/op
MyBenchmark.testMul  avgt    5  149.366 ?   9.558  us/op
Finished running test 'micro:MyBenchmark'
Benchmark            Mode  Cnt    Score   Error  Units
MyBenchmark.testAdd  avgt    5  107.874 ? 0.148  us/op
MyBenchmark.testMul  avgt    5  107.881 ? 0.015  us/op
Finished running test 'micro:MyBenchmark'

MyBenchmark.testAdd avgt 5 149.581 ? 13.626 us/op
MyBenchmark.testMax avgt 5 223.362 ? 195.007 us/op
MyBenchmark.testMin avgt 5 206.096 ? 16.840 us/op
MyBenchmark.testMul avgt 5 149.366 ? 9.558 us/op

I run this test case by java -jar target/benchmarks.jar -i 10 -wi 10 -f 1 on Intel(R) Xeon(R) CPU E7-8890 v4 @ 2.20GHz without crash. Can you give me your jvm options and this crash log? Thank you very much.

Certainly. Tomorrow morning (my time) I will re-run with your command and test on a few other Xeons. I need to re-run to get crash logs (I'm jumping around between patches and cleaned already) but I will post those when I can recreate.

To run I copied MyBenchmark.java from summary to test/micro/org/openjdk/bench/vm/compiler/MyBenchmark.java
Command on running was:
make test TEST="micro:MyBenchmark" MICRO="FORK=1;WARMUP_ITER=2;" CONF=linux-x86_64-server-slowdebug

This worked on master, but on checkout of pr/3513 caused the errors above.

Thank you very much. I will check this issue.

Loading

@Wanghuang-Huawei
Copy link
Author

@Wanghuang-Huawei Wanghuang-Huawei commented Apr 23, 2021

Running MyBenchmark test listed in the summary on x86_64 Haswell XEON with this patch results in:

# Benchmark: org.sample.MyBenchmark.testMax

# Run progress: 25.00% complete, ETA 00:03:57
# Fork: 1 of 1                                                                                                                                                              # Warmup Iteration   1: 112.714 us/op
# Warmup Iteration   2: # To suppress the following error report, specify this argument
# after -XX: or in .hotspotrc:  SuppressErrorAt=/register.hpp:152                                                                                                           #
# A fatal error has been detected by the Java Runtime Environment:
#
#  Internal Error (/home/mgkwill/src/git/jdk/src/hotspot/share/asm/register.hpp:152), pid=3450238, tid=3450253
#  assert(a != b && a != c && a != d && a != e && b != c && b != d && b != e && c != d && c != e && d != e) failed: registers must be different: a=0x0000000000000001, b=0x0000000000000001, c=0x0000000000000003, d=0x0000000000000004, e=0x0000000000000005
#
# JRE version: OpenJDK Runtime Environment (17.0) (slowdebug build 17-internal+0-adhoc.mgkwill.jdk) 

AND

# Benchmark: org.sample.MyBenchmark.testMin

# Run progress: 25.00% complete, ETA 00:03:57
# Fork: 1 of 1
# Warmup Iteration   1: 112.445 us/op
# Warmup Iteration   2: # To suppress the following error report, specify this argument
# after -XX: or in .hotspotrc:  SuppressErrorAt=/register.hpp:152
#
# A fatal error has been detected by the Java Runtime Environment:
#
#  Internal Error (/home/mgkwill/src/git/jdk/src/hotspot/share/asm/register.hpp:152), pid=3450444, tid=3450481
#  assert(a != b && a != c && a != d && a != e && b != c && b != d && b != e && c != d && c != e && d != e) failed: registers must be different: a=0x0000000000000001, b=0x0000000000000001, c=0x0000000000000003, d=0x0000000000000004, e=0x0000000000000005
#
# JRE version: OpenJDK Runtime Environment (17.0) (slowdebug build 17-internal+0-adhoc.mgkwill.jdk)

Otherwise the results are below.

Baseline
Benchmark            Mode  Cnt    Score     Error  Units
MyBenchmark.testAdd  avgt    5  149.581 ?  13.626  us/op
MyBenchmark.testMax  avgt    5  223.362 ? 195.007  us/op
MyBenchmark.testMin  avgt    5  206.096 ?  16.840  us/op
MyBenchmark.testMul  avgt    5  149.366 ?   9.558  us/op
Finished running test 'micro:MyBenchmark'
Benchmark            Mode  Cnt    Score   Error  Units
MyBenchmark.testAdd  avgt    5  107.874 ? 0.148  us/op
MyBenchmark.testMul  avgt    5  107.881 ? 0.015  us/op
Finished running test 'micro:MyBenchmark'

MyBenchmark.testAdd avgt 5 149.581 ? 13.626 us/op
MyBenchmark.testMax avgt 5 223.362 ? 195.007 us/op
MyBenchmark.testMin avgt 5 206.096 ? 16.840 us/op
MyBenchmark.testMul avgt 5 149.366 ? 9.558 us/op

I run this test case by java -jar target/benchmarks.jar -i 10 -wi 10 -f 1 on Intel(R) Xeon(R) CPU E7-8890 v4 @ 2.20GHz without crash. Can you give me your jvm options and this crash log? Thank you very much.

Certainly. Tomorrow morning (my time) I will re-run with your command and test on a few other Xeons. I need to re-run to get crash logs (I'm jumping around between patches and cleaned already) but I will post those when I can recreate.

To run I copied MyBenchmark.java from summary to test/micro/org/openjdk/bench/vm/compiler/MyBenchmark.java
Command on running was:
make test TEST="micro:MyBenchmark" MICRO="FORK=1;WARMUP_ITER=2;" CONF=linux-x86_64-server-slowdebug

This worked on master, but on checkout of pr/3513 caused the errors above.

I have tested on my Intel(R) Xeon(R) CPU E7-8890 v4 @ 2.20GHz on make test TEST="micro:MyBenchmark" MICRO="FORK=1;WARMUP_ITER=2;" CONF=linux-x86_64-server-slowdebug. It seems that all things are right?

Loading

@Wanghuang-Huawei
Copy link
Author

@Wanghuang-Huawei Wanghuang-Huawei commented Apr 23, 2021

Running MyBenchmark test listed in the summary on x86_64 Haswell XEON with this patch results in:

# Benchmark: org.sample.MyBenchmark.testMax

# Run progress: 25.00% complete, ETA 00:03:57
# Fork: 1 of 1                                                                                                                                                              # Warmup Iteration   1: 112.714 us/op
# Warmup Iteration   2: # To suppress the following error report, specify this argument
# after -XX: or in .hotspotrc:  SuppressErrorAt=/register.hpp:152                                                                                                           #
# A fatal error has been detected by the Java Runtime Environment:
#
#  Internal Error (/home/mgkwill/src/git/jdk/src/hotspot/share/asm/register.hpp:152), pid=3450238, tid=3450253
#  assert(a != b && a != c && a != d && a != e && b != c && b != d && b != e && c != d && c != e && d != e) failed: registers must be different: a=0x0000000000000001, b=0x0000000000000001, c=0x0000000000000003, d=0x0000000000000004, e=0x0000000000000005
#
# JRE version: OpenJDK Runtime Environment (17.0) (slowdebug build 17-internal+0-adhoc.mgkwill.jdk) 

AND

# Benchmark: org.sample.MyBenchmark.testMin

# Run progress: 25.00% complete, ETA 00:03:57
# Fork: 1 of 1
# Warmup Iteration   1: 112.445 us/op
# Warmup Iteration   2: # To suppress the following error report, specify this argument
# after -XX: or in .hotspotrc:  SuppressErrorAt=/register.hpp:152
#
# A fatal error has been detected by the Java Runtime Environment:
#
#  Internal Error (/home/mgkwill/src/git/jdk/src/hotspot/share/asm/register.hpp:152), pid=3450444, tid=3450481
#  assert(a != b && a != c && a != d && a != e && b != c && b != d && b != e && c != d && c != e && d != e) failed: registers must be different: a=0x0000000000000001, b=0x0000000000000001, c=0x0000000000000003, d=0x0000000000000004, e=0x0000000000000005
#
# JRE version: OpenJDK Runtime Environment (17.0) (slowdebug build 17-internal+0-adhoc.mgkwill.jdk)

Otherwise the results are below.

Baseline
Benchmark            Mode  Cnt    Score     Error  Units
MyBenchmark.testAdd  avgt    5  149.581 ?  13.626  us/op
MyBenchmark.testMax  avgt    5  223.362 ? 195.007  us/op
MyBenchmark.testMin  avgt    5  206.096 ?  16.840  us/op
MyBenchmark.testMul  avgt    5  149.366 ?   9.558  us/op
Finished running test 'micro:MyBenchmark'
Benchmark            Mode  Cnt    Score   Error  Units
MyBenchmark.testAdd  avgt    5  107.874 ? 0.148  us/op
MyBenchmark.testMul  avgt    5  107.881 ? 0.015  us/op
Finished running test 'micro:MyBenchmark'

I fix a bug in my code. I am not sure if it is the reason of your crash. However, you can pull the latest code and test again. Thank you.

Loading

@mgkwill
Copy link
Contributor

@mgkwill mgkwill commented Apr 23, 2021

I fix a bug in my code. I am not sure if it is the reason of your crash. However, you can pull the latest code and test again. Thank you.

Your update fixed the error I was seeing. My apologies for not getting back to you yesterday, it turned out to be busier than I projected.

Perf numbers on Haswell Intel Xeon CPU E5-1603 v3 @ 2.80GHz:

Baseline
Benchmark            Mode  Cnt    Score     Error  Units
MyBenchmark.testAdd  avgt    5  149.581 ?  13.626  us/op
MyBenchmark.testMax  avgt    5  223.362 ? 195.007  us/op
MyBenchmark.testMin  avgt    5  206.096 ?  16.840  us/op
MyBenchmark.testMul  avgt    5  149.366 ?   9.558  us/op
Finished running test 'micro:MyBenchmark'
Patch
Benchmark            Mode  Cnt    Score   Error  Units
MyBenchmark.testAdd  avgt    5  109.432 ? 0.010  us/op
MyBenchmark.testMax  avgt    5  109.893 ? 0.072  us/op
MyBenchmark.testMin  avgt    5  109.500 ? 0.024  us/op
MyBenchmark.testMul  avgt    5  111.225 ? 0.013  us/op

Loading

Copy link
Contributor

@mgkwill mgkwill left a comment

Thank you for answers.
The test should be part of changes.

I agree with @vnkozlov the jmh benchmark should be included in the changes and should be renamed to express what the benchmark is for.

Loading

@Wanghuang-Huawei
Copy link
Author

@Wanghuang-Huawei Wanghuang-Huawei commented Apr 26, 2021

Thank you for answers.
The test should be part of changes.

I agree with @vnkozlov the jmh benchmark should be included in the changes and should be renamed to express what the benchmark is for.

Thank you for your review. I have added the benchmark. @vnkozlov @mgkwill

Loading

@Wanghuang-Huawei
Copy link
Author

@Wanghuang-Huawei Wanghuang-Huawei commented May 11, 2021

Could you do me a favor to review the patch? @vnkozlov @mgkwill Thank you.

Loading

Copy link
Contributor

@vnkozlov vnkozlov left a comment

Looks good. Thank you for adding tests.
I will run some testing before approval.

Loading

Copy link
Contributor

@vnkozlov vnkozlov left a comment

t1-4 testing passed.

Loading

@openjdk
Copy link

@openjdk openjdk bot commented May 12, 2021

@Wanghuang-Huawei This change now passes all automated pre-integration checks.

ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details.

After integration, the commit message for the final commit will be:

8263006: Add optimization for Max(*)Node and Min(*)Node

Co-authored-by: Wang Huang <whuang@openjdk.org>
Co-authored-by: Wu Yan <wuyan34@huawei.com>
Reviewed-by: kvn

You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed.

At the time when this comment was updated there had been 475 new commits pushed to the master branch:

  • d215743: 8231031: runtime/ReservedStack/ReservedStackTest.java fails after jsr166 refresh
  • ab17be2: 8252530: Fix inconsistencies in hotspot whitebox
  • 2568d18: 8267047: Put serviceability/sa/TestJmapCoreMetaspace.java back on ZGC problem list due to JDK-8267045
  • accbfea: 8226216: parameter modifiers are not visible to javac plugins across compilation boundaries
  • 69daedf: 8266845: Shenandoah: Simplify SBS::load_reference_barrier implementation
  • 7433821: 8250658: Performance of ClipFlatOval Renderperf test is very low
  • 4727187: 8266567: Fix javadoc tag references in sun.management.jmxremote.ConnectorBootstrap
  • 11759bf: 8266798: C1: More types of instruction can also apply LoopInvariantCodeMotion
  • dcf250d: 8233378: CHT: Fast reset
  • f3b510b: 8266923: [JVMCI] expose StackOverflow::_stack_overflow_limit to JVMCI
  • ... and 465 more: https://git.openjdk.java.net/jdk/compare/b72d99e77b71e495fe66026f692f28d5407235ce...master

As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details.

As you do not have Committer status in this project an existing Committer must agree to sponsor your change. Possible candidates are the reviewers of this PR (@vnkozlov) but any other Committer may sponsor as well.

➡️ To flag this PR as ready for integration with the above commit message, type /integrate in a new comment. (Afterwards, your sponsor types /sponsor in a new comment to perform the integration).

Loading

@openjdk openjdk bot added the ready label May 12, 2021
@Wanghuang-Huawei
Copy link
Author

@Wanghuang-Huawei Wanghuang-Huawei commented May 13, 2021

/integrate

Loading

@openjdk openjdk bot added the sponsor label May 13, 2021
@openjdk
Copy link

@openjdk openjdk bot commented May 13, 2021

@Wanghuang-Huawei
Your change (at version cd51304) is now ready to be sponsored by a Committer.

Loading

@Wanghuang-Huawei
Copy link
Author

@Wanghuang-Huawei Wanghuang-Huawei commented May 13, 2021

t1-4 testing passed.

Thank you for your review and approval!

Loading

@vnkozlov
Copy link
Contributor

@vnkozlov vnkozlov commented May 14, 2021

/sponsor

Loading

@openjdk
Copy link

@openjdk openjdk bot commented May 14, 2021

@vnkozlov @Wanghuang-Huawei Since your change was applied there have been 498 commits pushed to the master branch:

  • 16ca370: 8265694: Investigate test StressHiddenClasses.java
  • af4cd04: 8266291: (jrtfs) Calling Files.exists may break the JRT filesystem
  • ebcf399: 8266622: Optimize Class.descriptorString() and Class.getCanonicalName0()
  • 644f28c: 8266810: Move trivial Matcher code to cpu-specific header files
  • 88907bb: 8266904: Use function pointer typedefs in OopOopIterateDispatch
  • 301095c: 8266795: Remove dead code LowMemoryDetectorDisabler
  • 1e0ecd6: 8265605: Cannot call BootLoader::loadClassOrNull before initPhase2
  • 4086081: 8264846: Regression ~5% in J2dBench.bimg_misc on Linux after JDK-8263142
  • 2a2f105: 8267117: sun/hotspot/whitebox/CPUInfoTest.java fails on Ice Lake
  • 2667024: 8266881: Enable debug log for SSLEngineExplorerMatchedSNI.java
  • ... and 488 more: https://git.openjdk.java.net/jdk/compare/b72d99e77b71e495fe66026f692f28d5407235ce...master

Your commit was automatically rebased without conflicts.

Pushed as commit 599d07c.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

Loading

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
3 participants