Path: blob/master/test/hotspot/jtreg/compiler/runtime/TestFloatsOnStackDeopt.java
41152 views
/*1* Copyright (c) 2018, 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*/2223package compiler.runtime;2425/*26* @test27* @summary testing deoptimization on safepoint with floating point values on stack28* @bug 820271029* @run main/othervm -XX:+DeoptimizeALot30* -XX:+UnlockDiagnosticVMOptions -XX:+IgnoreUnrecognizedVMOptions31* compiler.runtime.TestFloatsOnStackDeopt32*/3334public class TestFloatsOnStackDeopt {3536private static final int ARRLEN = 97;37private static final int ITERS1 = 100;38private static final int ITERS2 = 40000;39private static final float VALUE = 15.f;40public static String dummyString = "long long string";41static volatile boolean pleaseStop = false;4243static void run_loop_with_safepoint(float[] a0, float b) {44// Non-counted loop with safepoint.45for (long l = 0; l < ITERS2; l++) {46// Counted and vectorized loop.47for (int i = 0; i < a0.length; i += 1) {48a0[i] += b;49}50}51}5253static int test() {54// thread provokes frequent GC - together with +DeoptimizeALot and safepoint it forces executed function deoptimization55Thread th = new Thread() {56public void run() {57while (!pleaseStop) {58synchronized(this) { try { wait(1); } catch (Exception ex) {} }59dummyString = new StringBuilder(dummyString).append(dummyString).toString();60if (dummyString.length() > 1024*1024) { dummyString = "long long string"; }61}62}63};64th.start();6566int errn = 0;67for (int j = 0; j < ITERS1; j++) {68float[] x0 = new float[ARRLEN];69run_loop_with_safepoint(x0, VALUE);70for (int i = 0; i < ARRLEN; i++) {71if (x0[i] != VALUE * ITERS2) {72System.err.println("(" + j + "): " + "x0[" + i + "] = " + x0[i] + " != " + VALUE * ITERS2);73errn++;74}75x0[i] = 0.f; // Reset76}77if (errn > 0) break;78}7980pleaseStop = true;81try {82th.join();83} catch (InterruptedException e) {84throw new Error("InterruptedException in main thread ", e);85}86return errn;87}8889public static void main(String args[]) {90int errn = test();91System.err.println((errn > 0) ? "FAILED" : "PASSED");92}93}94959697