--- /dev/null 2019-05-21 10:49:56.803155115 +0800 +++ new/test/hotspot/jtreg/compiler/profiling/TestProfileCounterOverflow.java 2019-05-22 16:45:49.339150185 +0800 @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2019, Loongson Technology 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. + */ + +/** + * @test + * @bug 8224162 + * @summary Profile counter for a call site may overflow. + * @requires (vm.debug == true) + * @run main/othervm/timeout=600 -XX:-TieredCompilation -XX:-UseOnStackReplacement -XX:MaxTrivialSize=1 compiler.profiling.TestProfileCounterOverflow + */ + +package compiler.profiling; + +public class TestProfileCounterOverflow { + public static void main(String[] args) throws Exception { + int sum = 0; + for (int i = 0; i < 4; i++) { + sum += test(i); + } + System.out.println("sum = " + sum); + } + + public static int test(int i) throws Exception { + int sum = 0; + if (i == 0) { + long iteration = Integer.MAX_VALUE + 10000L; + // Increase the profile counter to make it overflowed + for (long j = 0; j < iteration; j++) { + sum += call(i); + } + } else { + // Sleep to wait for the compilation to be finished + Thread.sleep(2000); + } + return sum; + } + + public static int call(int i) { + return i; + } +}