Path: blob/master/test/hotspot/jtreg/compiler/gcbarriers/PreserveFPRegistersTest.java
64474 views
/*1* Copyright (c) 2016, 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 814817526* @requires vm.gc=="G1" | vm.gc=="null"27* @library /test/lib28* @run main/bootclasspath/othervm -Xbatch -XX:+UnlockDiagnosticVMOptions29* -XX:+WhiteBoxAPI -Xmx300m -XX:+UseG1GC30* compiler.gcbarriers.PreserveFPRegistersTest31*/3233package compiler.gcbarriers;3435import sun.hotspot.WhiteBox;3637public class PreserveFPRegistersTest {3839public static void main(String... args) throws InterruptedException {40new PreserveFPRegistersTest().go();41}4243private static WhiteBox wb = WhiteBox.getWhiteBox();4445public final Object[][] storage;4647/**48* Number of objects per region.49*/50public final int K = 10;5152/**53* Length of object array: sizeOf(Object[N]) ~= regionSize / K .54*/55public final int N;5657/**58* How many regions involved into testing.59*/60public final int regionCount;6162PreserveFPRegistersTest() {63long regionSize = wb.g1RegionSize();64Runtime rt = Runtime.getRuntime();65long used = rt.totalMemory() - rt.freeMemory();66long totalFree = rt.maxMemory() - used;67regionCount = (int) ( (totalFree / regionSize) * 0.9);68int refSize = wb.getHeapOopSize();69N = (int) ((regionSize / K ) / refSize) - 5;7071System.out.println("%% Memory");72System.out.println("%% used : " + used / 1024 + "M");73System.out.println("%% available : " + totalFree / 1024 + "M");74System.out.println("%% G1 Region Size: " + regionSize / 1024 + "M");75System.out.println("%% region count : " + regionCount);7677System.out.println("%% Objects storage");78System.out.println("%% N (array length) : " + N);79System.out.println("%% K (objects in regions): " + K);80System.out.println("%% Reference size : " + refSize);8182try {83storage = new Object[regionCount * K][];84for (int i = 0; i < storage.length; i++) {85storage[i] = new Object[N];86}87} catch(OutOfMemoryError e) {88throw new AssertionError("Test Failed with unexpected OutOfMemoryError exception");89}90}9192public void go() throws InterruptedException {93final float FINAL = getValue();9495for (int to = 0; to < regionCount; to++) {96Object celebrity = storage[to * K];97for (int from = 0; from < regionCount; from++) {98for (int rn = 0; rn != 100; rn++) {99storage[getY(to, from, rn)][getX(to, from, rn)] = celebrity;100}101if (FINAL != getValue()) {102throw new AssertionError("Final value has changed: " + FINAL + " != " + getValue());103}104}105}106107System.out.println("TEST PASSED");108}109110public float getValue() {111return 6;112}113114private int getX(int to, int from, int rn) {115return (rn*regionCount + to) % N;116}117118private int getY(int to, int from, int rn) {119return ((rn*regionCount + to) / N + from * K) % (regionCount*K) ;120}121}122123124