Path: blob/master/test/hotspot/jtreg/compiler/jsr292/PollutedTrapCounts.java
41149 views
/*1* Copyright (c) 2015, 2021, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/**24* @test25* @bug 807455126*27* @requires vm.flagless28* @modules java.base/jdk.internal.misc29* @library /test/lib30*31* @run driver compiler.jsr292.PollutedTrapCounts32*/3334package compiler.jsr292;3536import jdk.test.lib.process.OutputAnalyzer;37import jdk.test.lib.process.ProcessTools;3839import java.lang.invoke.MethodHandle;40import java.lang.invoke.MethodHandles;41import java.lang.invoke.MethodType;4243public class PollutedTrapCounts {44public static void main(String[] args) throws Exception {45ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(46"-XX:+IgnoreUnrecognizedVMOptions",47"-XX:-TieredCompilation", "-Xbatch",48"-XX:PerBytecodeRecompilationCutoff=10", "-XX:PerMethodRecompilationCutoff=10",49"-XX:+PrintCompilation", "-XX:+UnlockDiagnosticVMOptions", "-XX:+PrintInlining",50Test.class.getName());5152OutputAnalyzer analyzer = new OutputAnalyzer(pb.start());5354analyzer.shouldHaveExitValue(0);5556analyzer.shouldNotContain("not compilable (disabled)");57}5859static class Test {60public static final MethodHandle test1;61public static final MethodHandle test2;62public static final MethodHandle empty;6364static {65try {66Class<?> THIS_CLASS = Test.class;67MethodHandles.Lookup LOOKUP = MethodHandles.lookup();68test1 = LOOKUP.findStatic(THIS_CLASS, "test1", MethodType.methodType(boolean.class, boolean.class));69test2 = LOOKUP.findStatic(THIS_CLASS, "test2", MethodType.methodType(boolean.class, boolean.class));70empty = LOOKUP.findStatic(THIS_CLASS, "empty", MethodType.methodType(void.class, boolean.class));71} catch(Throwable e) {72throw new Error(e);73}74}7576static boolean test1(boolean b) {77return b;78}79static boolean test2(boolean b) {80return true;81}82static void empty(boolean b) {}8384static void test(boolean freqValue, boolean removeInlineBlocker) throws Throwable {85MethodHandle innerGWT = MethodHandles.guardWithTest(test1, empty, empty);86MethodHandle outerGWT = MethodHandles.guardWithTest(test2, innerGWT, innerGWT);8788// Trigger compilation89for (int i = 0; i < 20_000; i++) {90outerGWT.invokeExact(freqValue);91}9293// Trigger deopt & nmethod invalidation94outerGWT.invokeExact(!freqValue);9596// Force inline blocker removal on rare-taken path97if (removeInlineBlocker) {98for (int i = 0; i < 100; i++) {99outerGWT.invokeExact(!freqValue);100}101}102103// Trigger recompilation104for (int i = 0; i < 20_000; i++) {105outerGWT.invokeExact(freqValue);106}107}108109public static void main(String[] args) throws Throwable {110boolean freqValue = true;111boolean removeInlineBlocker = false;112for (int i = 0; i < 20; i++) {113test(freqValue, removeInlineBlocker);114freqValue = !freqValue;115removeInlineBlocker = !removeInlineBlocker;116}117}118}119}120121122