src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot.lir.test/src/org/graalvm/compiler/hotspot/lir/test/BenchmarkCounterOverflowTest.java
author chegar
Thu, 17 Oct 2019 20:54:25 +0100
branchdatagramsocketimpl-branch
changeset 58679 9c3209ff7550
parent 58678 9cf78a70fa4f
parent 58299 6df94ce3ab2f
permissions -rw-r--r--
datagramsocketimpl-branch: merge with default
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
52578
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
     1
/*
54084
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
     2
 * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
52578
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
     4
 *
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
     7
 * published by the Free Software Foundation.
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
     8
 *
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    13
 * accompanied this code).
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    14
 *
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    18
 *
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    21
 * questions.
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    22
 */
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    23
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    24
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    25
package org.graalvm.compiler.hotspot.lir.test;
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    26
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    27
import static org.graalvm.compiler.test.SubprocessUtil.getVMCommandLine;
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    28
import static org.graalvm.compiler.test.SubprocessUtil.withoutDebuggerArguments;
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    29
54084
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
    30
import java.io.File;
57537
ecc6e394475f 8226771: Update Graal
dlong
parents: 54084
diff changeset
    31
import java.io.IOException;
52578
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    32
import java.util.ArrayList;
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    33
import java.util.Iterator;
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    34
import java.util.List;
54084
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
    35
import java.util.regex.Matcher;
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
    36
import java.util.regex.Pattern;
52578
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    37
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    38
import org.graalvm.compiler.api.directives.GraalDirectives;
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    39
import org.graalvm.compiler.core.common.LIRKind;
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    40
import org.graalvm.compiler.hotspot.HotSpotBackend;
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    41
import org.graalvm.compiler.hotspot.debug.BenchmarkCounters;
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    42
import org.graalvm.compiler.lir.ConstantValue;
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    43
import org.graalvm.compiler.lir.gen.LIRGeneratorTool;
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    44
import org.graalvm.compiler.lir.jtt.LIRTest;
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    45
import org.graalvm.compiler.lir.jtt.LIRTestSpecification;
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    46
import org.graalvm.compiler.test.SubprocessUtil;
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    47
import org.junit.Assert;
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    48
import org.junit.Assume;
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    49
import org.junit.Before;
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    50
import org.junit.Test;
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    51
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    52
import jdk.vm.ci.amd64.AMD64;
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    53
import jdk.vm.ci.meta.JavaConstant;
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    54
import jdk.vm.ci.meta.JavaKind;
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    55
import jdk.vm.ci.meta.ResolvedJavaMethod;
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    56
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    57
public class BenchmarkCounterOverflowTest extends LIRTest {
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    58
    private static final String SUBPROCESS_PROPERTY = BenchmarkCounterOverflowTest.class.getSimpleName() + ".subprocess.call";
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    59
    private static final boolean VERBOSE = Boolean.getBoolean(BenchmarkCounterOverflowTest.class.getSimpleName() + ".verbose");
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    60
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    61
    private static LIRKind intKind;
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    62
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    63
    @Before
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    64
    public void checkAMD64() {
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    65
        Assume.assumeTrue("skipping AMD64 specific test", getTarget().arch instanceof AMD64);
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    66
        Assume.assumeTrue("skipping HotSpot specific test", getBackend() instanceof HotSpotBackend);
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    67
    }
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    68
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    69
    @Before
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    70
    public void setUp() {
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    71
        intKind = LIRKind.fromJavaKind(getBackend().getTarget().arch, JavaKind.Long);
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    72
    }
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    73
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    74
    private static final LIRTestSpecification constCounterIncrement = new LIRTestSpecification() {
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    75
        @Override
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    76
        public void generate(LIRGeneratorTool gen) {
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    77
            gen.append(gen.createBenchmarkCounter("counter", "test", new ConstantValue(intKind, JavaConstant.forLong(Integer.MAX_VALUE))));
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    78
        }
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    79
    };
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    80
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    81
    @SuppressWarnings("unused")
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    82
    @LIRIntrinsic
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    83
    public static void counterInc(LIRTestSpecification spec) {
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    84
    }
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    85
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    86
    public static void test(long count) {
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    87
        for (long i = 0; i < count; i++) {
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    88
            counterInc(constCounterIncrement);
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    89
            GraalDirectives.blackhole(i);
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    90
        }
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    91
    }
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    92
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    93
    @Test
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    94
    public void incrementCounter() {
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    95
        Assume.assumeTrue("not a subprocess -> skip", Boolean.getBoolean(SUBPROCESS_PROPERTY));
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    96
        BenchmarkCounters.enabled = true;
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    97
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    98
        Object[] args = new Object[]{Integer.MAX_VALUE * 4L};
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    99
        ResolvedJavaMethod method = getResolvedJavaMethod("test");
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
   100
        executeActualCheckDeopt(getInitialOptions(), method, EMPTY, null, args);
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
   101
    }
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
   102
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
   103
    @Test
57537
ecc6e394475f 8226771: Update Graal
dlong
parents: 54084
diff changeset
   104
    public void spawnSubprocess() throws IOException, InterruptedException {
52578
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
   105
        Assume.assumeFalse("subprocess already spawned -> skip", Boolean.getBoolean(SUBPROCESS_PROPERTY));
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
   106
        List<String> vmArgs = withoutDebuggerArguments(getVMCommandLine());
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
   107
        vmArgs.add("-XX:JVMCICounterSize=1");
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
   108
        vmArgs.add("-Dgraal." + BenchmarkCounters.Options.AbortOnBenchmarkCounterOverflow.getName() + "=true");
58299
6df94ce3ab2f 8229201: Update Graal
dlong
parents: 57537
diff changeset
   109
        vmArgs.addAll(SubprocessUtil.getPackageOpeningOptions());
52578
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
   110
        vmArgs.add("-D" + SUBPROCESS_PROPERTY + "=true");
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
   111
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
   112
        // Disable increment range checks (e.g. HotSpotCounterOp.checkIncrements())
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
   113
        vmArgs.add("-dsa");
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
   114
        vmArgs.add("-da");
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
   115
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
   116
        List<String> mainClassAndArgs = new ArrayList<>();
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
   117
        mainClassAndArgs.add("com.oracle.mxtool.junit.MxJUnitWrapper");
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
   118
        mainClassAndArgs.add(BenchmarkCounterOverflowTest.class.getName());
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
   119
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
   120
        SubprocessUtil.Subprocess proc = SubprocessUtil.java(vmArgs, mainClassAndArgs);
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
   121
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
   122
        if (VERBOSE) {
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
   123
            System.out.println(proc);
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
   124
        }
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
   125
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
   126
        Assert.assertNotEquals("Expected non-zero exit status", 0, proc.exitCode);
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
   127
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
   128
        Iterator<String> it = proc.output.iterator();
54084
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   129
        boolean foundProblematicFrame = false;
52578
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
   130
        while (it.hasNext()) {
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
   131
            String line = it.next();
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
   132
            if (line.contains("Problematic frame:")) {
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
   133
                if (!it.hasNext()) {
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
   134
                    // no more line
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
   135
                    break;
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
   136
                }
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
   137
                line = it.next();
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
   138
                if (line.contains(BenchmarkCounterOverflowTest.class.getName() + ".test")) {
54084
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   139
                    foundProblematicFrame = true;
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   140
                    break;
52578
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
   141
                }
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
   142
                Assert.fail("Unexpected stack trace: " + line);
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
   143
            }
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
   144
        }
54084
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   145
        // find and delete hserr file
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   146
        while (it.hasNext()) {
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   147
            String line = it.next();
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   148
            if (line.contains("An error report file with more information is saved as:")) {
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   149
                if (!it.hasNext()) {
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   150
                    // no more line
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   151
                    break;
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   152
                }
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   153
                line = it.next();
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   154
                Pattern pattern = Pattern.compile("^# (.*hs_err_pid.*log)$");
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   155
                Matcher matcher = pattern.matcher(line);
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   156
                if (matcher.matches()) {
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   157
                    File hserrFile = new File(matcher.group(1));
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   158
                    if (hserrFile.exists()) {
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   159
                        if (VERBOSE) {
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   160
                            System.out.println("Deleting error report file:" + hserrFile.getAbsolutePath());
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   161
                        }
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   162
                        hserrFile.delete();
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   163
                    }
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   164
                }
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   165
            }
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   166
        }
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   167
        Assert.assertTrue(String.format("Could not find method in output:%n%s", proc), foundProblematicFrame);
52578
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
   168
    }
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
   169
}