hotspot/test/compiler/jsr292/PollutedTrapCounts.java
author alanb
Tue, 03 May 2016 09:09:20 +0100
changeset 37773 e5b3e9732c3c
parent 31228 8e427370cdd1
child 38152 80e5da81fb2c
permissions -rw-r--r--
8154956: Module system implementation refresh (4/2016) Reviewed-by: acorn, jiangli, ccheung, hseigel Contributed-by: alan.bateman@oracle.com, lois.foltan@oracle.com, harold.seigel@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
31228
8e427370cdd1 8074551: GWT can be marked non-compilable due to deopt count pollution
vlivanov
parents:
diff changeset
     1
/*
8e427370cdd1 8074551: GWT can be marked non-compilable due to deopt count pollution
vlivanov
parents:
diff changeset
     2
 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
8e427370cdd1 8074551: GWT can be marked non-compilable due to deopt count pollution
vlivanov
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8e427370cdd1 8074551: GWT can be marked non-compilable due to deopt count pollution
vlivanov
parents:
diff changeset
     4
 *
8e427370cdd1 8074551: GWT can be marked non-compilable due to deopt count pollution
vlivanov
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
8e427370cdd1 8074551: GWT can be marked non-compilable due to deopt count pollution
vlivanov
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
8e427370cdd1 8074551: GWT can be marked non-compilable due to deopt count pollution
vlivanov
parents:
diff changeset
     7
 * published by the Free Software Foundation.
8e427370cdd1 8074551: GWT can be marked non-compilable due to deopt count pollution
vlivanov
parents:
diff changeset
     8
 *
8e427370cdd1 8074551: GWT can be marked non-compilable due to deopt count pollution
vlivanov
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
8e427370cdd1 8074551: GWT can be marked non-compilable due to deopt count pollution
vlivanov
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
8e427370cdd1 8074551: GWT can be marked non-compilable due to deopt count pollution
vlivanov
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
8e427370cdd1 8074551: GWT can be marked non-compilable due to deopt count pollution
vlivanov
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
8e427370cdd1 8074551: GWT can be marked non-compilable due to deopt count pollution
vlivanov
parents:
diff changeset
    13
 * accompanied this code).
8e427370cdd1 8074551: GWT can be marked non-compilable due to deopt count pollution
vlivanov
parents:
diff changeset
    14
 *
8e427370cdd1 8074551: GWT can be marked non-compilable due to deopt count pollution
vlivanov
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
8e427370cdd1 8074551: GWT can be marked non-compilable due to deopt count pollution
vlivanov
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
8e427370cdd1 8074551: GWT can be marked non-compilable due to deopt count pollution
vlivanov
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
8e427370cdd1 8074551: GWT can be marked non-compilable due to deopt count pollution
vlivanov
parents:
diff changeset
    18
 *
8e427370cdd1 8074551: GWT can be marked non-compilable due to deopt count pollution
vlivanov
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
8e427370cdd1 8074551: GWT can be marked non-compilable due to deopt count pollution
vlivanov
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
8e427370cdd1 8074551: GWT can be marked non-compilable due to deopt count pollution
vlivanov
parents:
diff changeset
    21
 * questions.
8e427370cdd1 8074551: GWT can be marked non-compilable due to deopt count pollution
vlivanov
parents:
diff changeset
    22
 */
8e427370cdd1 8074551: GWT can be marked non-compilable due to deopt count pollution
vlivanov
parents:
diff changeset
    23
8e427370cdd1 8074551: GWT can be marked non-compilable due to deopt count pollution
vlivanov
parents:
diff changeset
    24
/**
8e427370cdd1 8074551: GWT can be marked non-compilable due to deopt count pollution
vlivanov
parents:
diff changeset
    25
 * @test
8e427370cdd1 8074551: GWT can be marked non-compilable due to deopt count pollution
vlivanov
parents:
diff changeset
    26
 * @bug 8074551
8e427370cdd1 8074551: GWT can be marked non-compilable due to deopt count pollution
vlivanov
parents:
diff changeset
    27
 * @library /testlibrary
8e427370cdd1 8074551: GWT can be marked non-compilable due to deopt count pollution
vlivanov
parents:
diff changeset
    28
 * @run main PollutedTrapCounts
8e427370cdd1 8074551: GWT can be marked non-compilable due to deopt count pollution
vlivanov
parents:
diff changeset
    29
 */
8e427370cdd1 8074551: GWT can be marked non-compilable due to deopt count pollution
vlivanov
parents:
diff changeset
    30
import java.lang.invoke.*;
8e427370cdd1 8074551: GWT can be marked non-compilable due to deopt count pollution
vlivanov
parents:
diff changeset
    31
import jdk.test.lib.*;
8e427370cdd1 8074551: GWT can be marked non-compilable due to deopt count pollution
vlivanov
parents:
diff changeset
    32
8e427370cdd1 8074551: GWT can be marked non-compilable due to deopt count pollution
vlivanov
parents:
diff changeset
    33
public class PollutedTrapCounts {
8e427370cdd1 8074551: GWT can be marked non-compilable due to deopt count pollution
vlivanov
parents:
diff changeset
    34
    public static void main(String[] args) throws Exception {
8e427370cdd1 8074551: GWT can be marked non-compilable due to deopt count pollution
vlivanov
parents:
diff changeset
    35
        ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
8e427370cdd1 8074551: GWT can be marked non-compilable due to deopt count pollution
vlivanov
parents:
diff changeset
    36
                "-XX:+IgnoreUnrecognizedVMOptions",
8e427370cdd1 8074551: GWT can be marked non-compilable due to deopt count pollution
vlivanov
parents:
diff changeset
    37
                "-XX:-TieredCompilation", "-Xbatch",
8e427370cdd1 8074551: GWT can be marked non-compilable due to deopt count pollution
vlivanov
parents:
diff changeset
    38
                "-XX:PerBytecodeRecompilationCutoff=10", "-XX:PerMethodRecompilationCutoff=10",
8e427370cdd1 8074551: GWT can be marked non-compilable due to deopt count pollution
vlivanov
parents:
diff changeset
    39
                "-XX:+PrintCompilation", "-XX:+UnlockDiagnosticVMOptions", "-XX:+PrintInlining",
8e427370cdd1 8074551: GWT can be marked non-compilable due to deopt count pollution
vlivanov
parents:
diff changeset
    40
                    "PollutedTrapCounts$Test");
8e427370cdd1 8074551: GWT can be marked non-compilable due to deopt count pollution
vlivanov
parents:
diff changeset
    41
8e427370cdd1 8074551: GWT can be marked non-compilable due to deopt count pollution
vlivanov
parents:
diff changeset
    42
        OutputAnalyzer analyzer = new OutputAnalyzer(pb.start());
8e427370cdd1 8074551: GWT can be marked non-compilable due to deopt count pollution
vlivanov
parents:
diff changeset
    43
8e427370cdd1 8074551: GWT can be marked non-compilable due to deopt count pollution
vlivanov
parents:
diff changeset
    44
        analyzer.shouldHaveExitValue(0);
8e427370cdd1 8074551: GWT can be marked non-compilable due to deopt count pollution
vlivanov
parents:
diff changeset
    45
8e427370cdd1 8074551: GWT can be marked non-compilable due to deopt count pollution
vlivanov
parents:
diff changeset
    46
        analyzer.shouldNotContain("not compilable (disabled)");
8e427370cdd1 8074551: GWT can be marked non-compilable due to deopt count pollution
vlivanov
parents:
diff changeset
    47
    }
8e427370cdd1 8074551: GWT can be marked non-compilable due to deopt count pollution
vlivanov
parents:
diff changeset
    48
8e427370cdd1 8074551: GWT can be marked non-compilable due to deopt count pollution
vlivanov
parents:
diff changeset
    49
    static class Test {
8e427370cdd1 8074551: GWT can be marked non-compilable due to deopt count pollution
vlivanov
parents:
diff changeset
    50
        public static final MethodHandle test1;
8e427370cdd1 8074551: GWT can be marked non-compilable due to deopt count pollution
vlivanov
parents:
diff changeset
    51
        public static final MethodHandle test2;
8e427370cdd1 8074551: GWT can be marked non-compilable due to deopt count pollution
vlivanov
parents:
diff changeset
    52
        public static final MethodHandle empty;
8e427370cdd1 8074551: GWT can be marked non-compilable due to deopt count pollution
vlivanov
parents:
diff changeset
    53
8e427370cdd1 8074551: GWT can be marked non-compilable due to deopt count pollution
vlivanov
parents:
diff changeset
    54
        static {
8e427370cdd1 8074551: GWT can be marked non-compilable due to deopt count pollution
vlivanov
parents:
diff changeset
    55
            try {
8e427370cdd1 8074551: GWT can be marked non-compilable due to deopt count pollution
vlivanov
parents:
diff changeset
    56
                Class<?> THIS_CLASS = Test.class;
8e427370cdd1 8074551: GWT can be marked non-compilable due to deopt count pollution
vlivanov
parents:
diff changeset
    57
                MethodHandles.Lookup LOOKUP = MethodHandles.lookup();
8e427370cdd1 8074551: GWT can be marked non-compilable due to deopt count pollution
vlivanov
parents:
diff changeset
    58
                test1 = LOOKUP.findStatic(THIS_CLASS, "test1", MethodType.methodType(boolean.class, boolean.class));
8e427370cdd1 8074551: GWT can be marked non-compilable due to deopt count pollution
vlivanov
parents:
diff changeset
    59
                test2 = LOOKUP.findStatic(THIS_CLASS, "test2", MethodType.methodType(boolean.class, boolean.class));
8e427370cdd1 8074551: GWT can be marked non-compilable due to deopt count pollution
vlivanov
parents:
diff changeset
    60
                empty = LOOKUP.findStatic(THIS_CLASS, "empty", MethodType.methodType(void.class, boolean.class));
8e427370cdd1 8074551: GWT can be marked non-compilable due to deopt count pollution
vlivanov
parents:
diff changeset
    61
            } catch(Throwable e) {
8e427370cdd1 8074551: GWT can be marked non-compilable due to deopt count pollution
vlivanov
parents:
diff changeset
    62
                throw new Error(e);
8e427370cdd1 8074551: GWT can be marked non-compilable due to deopt count pollution
vlivanov
parents:
diff changeset
    63
            }
8e427370cdd1 8074551: GWT can be marked non-compilable due to deopt count pollution
vlivanov
parents:
diff changeset
    64
        }
8e427370cdd1 8074551: GWT can be marked non-compilable due to deopt count pollution
vlivanov
parents:
diff changeset
    65
8e427370cdd1 8074551: GWT can be marked non-compilable due to deopt count pollution
vlivanov
parents:
diff changeset
    66
        static boolean test1(boolean b) {
8e427370cdd1 8074551: GWT can be marked non-compilable due to deopt count pollution
vlivanov
parents:
diff changeset
    67
            return b;
8e427370cdd1 8074551: GWT can be marked non-compilable due to deopt count pollution
vlivanov
parents:
diff changeset
    68
        }
8e427370cdd1 8074551: GWT can be marked non-compilable due to deopt count pollution
vlivanov
parents:
diff changeset
    69
        static boolean test2(boolean b) {
8e427370cdd1 8074551: GWT can be marked non-compilable due to deopt count pollution
vlivanov
parents:
diff changeset
    70
            return true;
8e427370cdd1 8074551: GWT can be marked non-compilable due to deopt count pollution
vlivanov
parents:
diff changeset
    71
        }
8e427370cdd1 8074551: GWT can be marked non-compilable due to deopt count pollution
vlivanov
parents:
diff changeset
    72
        static void    empty(boolean b) {}
8e427370cdd1 8074551: GWT can be marked non-compilable due to deopt count pollution
vlivanov
parents:
diff changeset
    73
8e427370cdd1 8074551: GWT can be marked non-compilable due to deopt count pollution
vlivanov
parents:
diff changeset
    74
        static void test(boolean freqValue, boolean removeInlineBlocker) throws Throwable {
8e427370cdd1 8074551: GWT can be marked non-compilable due to deopt count pollution
vlivanov
parents:
diff changeset
    75
            MethodHandle innerGWT = MethodHandles.guardWithTest(test1, empty, empty);
8e427370cdd1 8074551: GWT can be marked non-compilable due to deopt count pollution
vlivanov
parents:
diff changeset
    76
            MethodHandle outerGWT = MethodHandles.guardWithTest(test2, innerGWT, innerGWT);
8e427370cdd1 8074551: GWT can be marked non-compilable due to deopt count pollution
vlivanov
parents:
diff changeset
    77
8e427370cdd1 8074551: GWT can be marked non-compilable due to deopt count pollution
vlivanov
parents:
diff changeset
    78
            // Trigger compilation
8e427370cdd1 8074551: GWT can be marked non-compilable due to deopt count pollution
vlivanov
parents:
diff changeset
    79
            for (int i = 0; i < 20_000; i++) {
8e427370cdd1 8074551: GWT can be marked non-compilable due to deopt count pollution
vlivanov
parents:
diff changeset
    80
                outerGWT.invokeExact(freqValue);
8e427370cdd1 8074551: GWT can be marked non-compilable due to deopt count pollution
vlivanov
parents:
diff changeset
    81
            }
8e427370cdd1 8074551: GWT can be marked non-compilable due to deopt count pollution
vlivanov
parents:
diff changeset
    82
8e427370cdd1 8074551: GWT can be marked non-compilable due to deopt count pollution
vlivanov
parents:
diff changeset
    83
            // Trigger deopt & nmethod invalidation
8e427370cdd1 8074551: GWT can be marked non-compilable due to deopt count pollution
vlivanov
parents:
diff changeset
    84
            outerGWT.invokeExact(!freqValue);
8e427370cdd1 8074551: GWT can be marked non-compilable due to deopt count pollution
vlivanov
parents:
diff changeset
    85
8e427370cdd1 8074551: GWT can be marked non-compilable due to deopt count pollution
vlivanov
parents:
diff changeset
    86
            // Force inline blocker removal on rare-taken path
8e427370cdd1 8074551: GWT can be marked non-compilable due to deopt count pollution
vlivanov
parents:
diff changeset
    87
            if (removeInlineBlocker) {
8e427370cdd1 8074551: GWT can be marked non-compilable due to deopt count pollution
vlivanov
parents:
diff changeset
    88
                for (int i = 0; i < 100; i++) {
8e427370cdd1 8074551: GWT can be marked non-compilable due to deopt count pollution
vlivanov
parents:
diff changeset
    89
                    outerGWT.invokeExact(!freqValue);
8e427370cdd1 8074551: GWT can be marked non-compilable due to deopt count pollution
vlivanov
parents:
diff changeset
    90
                }
8e427370cdd1 8074551: GWT can be marked non-compilable due to deopt count pollution
vlivanov
parents:
diff changeset
    91
            }
8e427370cdd1 8074551: GWT can be marked non-compilable due to deopt count pollution
vlivanov
parents:
diff changeset
    92
8e427370cdd1 8074551: GWT can be marked non-compilable due to deopt count pollution
vlivanov
parents:
diff changeset
    93
            // Trigger recompilation
8e427370cdd1 8074551: GWT can be marked non-compilable due to deopt count pollution
vlivanov
parents:
diff changeset
    94
            for (int i = 0; i < 20_000; i++) {
8e427370cdd1 8074551: GWT can be marked non-compilable due to deopt count pollution
vlivanov
parents:
diff changeset
    95
                outerGWT.invokeExact(freqValue);
8e427370cdd1 8074551: GWT can be marked non-compilable due to deopt count pollution
vlivanov
parents:
diff changeset
    96
            }
8e427370cdd1 8074551: GWT can be marked non-compilable due to deopt count pollution
vlivanov
parents:
diff changeset
    97
        }
8e427370cdd1 8074551: GWT can be marked non-compilable due to deopt count pollution
vlivanov
parents:
diff changeset
    98
8e427370cdd1 8074551: GWT can be marked non-compilable due to deopt count pollution
vlivanov
parents:
diff changeset
    99
        public static void main(String[] args) throws Throwable {
8e427370cdd1 8074551: GWT can be marked non-compilable due to deopt count pollution
vlivanov
parents:
diff changeset
   100
            boolean freqValue = true;
8e427370cdd1 8074551: GWT can be marked non-compilable due to deopt count pollution
vlivanov
parents:
diff changeset
   101
            boolean removeInlineBlocker = false;
8e427370cdd1 8074551: GWT can be marked non-compilable due to deopt count pollution
vlivanov
parents:
diff changeset
   102
            for (int i = 0; i < 20; i++) {
8e427370cdd1 8074551: GWT can be marked non-compilable due to deopt count pollution
vlivanov
parents:
diff changeset
   103
                test(freqValue, removeInlineBlocker);
8e427370cdd1 8074551: GWT can be marked non-compilable due to deopt count pollution
vlivanov
parents:
diff changeset
   104
                freqValue = !freqValue;
8e427370cdd1 8074551: GWT can be marked non-compilable due to deopt count pollution
vlivanov
parents:
diff changeset
   105
                removeInlineBlocker = !removeInlineBlocker;
8e427370cdd1 8074551: GWT can be marked non-compilable due to deopt count pollution
vlivanov
parents:
diff changeset
   106
            }
8e427370cdd1 8074551: GWT can be marked non-compilable due to deopt count pollution
vlivanov
parents:
diff changeset
   107
        }
8e427370cdd1 8074551: GWT can be marked non-compilable due to deopt count pollution
vlivanov
parents:
diff changeset
   108
    }
8e427370cdd1 8074551: GWT can be marked non-compilable due to deopt count pollution
vlivanov
parents:
diff changeset
   109
}