1 /* 2 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 * 23 */ 24 25 /** 26 * @test 27 * @bug 8148175 28 * 29 * @ignore 8153194 30 * @run main/othervm/timeout=300 -Xbatch -Xmx128m 31 * compiler.gcbarriers.PreserveFPRegistersTest 32 */ 33 34 package compiler.gcbarriers; 35 36 public class PreserveFPRegistersTest { 37 38 public static void main(String... args) throws InterruptedException { 39 new PreserveFPRegistersTest().go(); 40 } 41 42 public final Object[][] storage; 43 44 /** 45 * Number of objects per region. 46 */ 47 public final int K = 10; 48 49 /** 50 * Length of object array: sizeOf(Object[N]) ~= regionSize / K . 51 */ 52 public final int N; 53 54 /** 55 * How many regions involved into testing. 56 */ 57 public final int regionCount; 58 59 PreserveFPRegistersTest() { 60 long regionSize = 1_000_000; //WB.g1RegionSize(); 61 62 Runtime rt = Runtime.getRuntime(); 63 long used = rt.totalMemory() - rt.freeMemory(); 64 long totalFree = rt.maxMemory() - used; 65 regionCount = (int) ( (totalFree / regionSize) * 0.9); 66 int refSize = 4; 67 68 N = (int) ((regionSize / K ) / refSize) - 5; 69 storage = new Object[regionCount * K][]; 70 for (int i = 0; i < storage.length; i++) { 71 storage[i] = new Object[N]; 72 } 73 } 74 75 public void go() throws InterruptedException { 76 final float FINAL = getValue(); 77 78 for (int to = 0; to < regionCount; to++) { 79 Object celebrity = storage[to * K]; 80 for (int from = 0; from < regionCount; from++) { 81 for (int rn = 0; rn != 100; rn++) { 82 storage[getY(to, from, rn)][getX(to, from, rn)] = celebrity; 83 } 84 if (FINAL != getValue()) { 85 throw new AssertionError("Final value has changed: " + FINAL + " != " + getValue()); 86 } 87 } 88 } 89 90 System.out.println("TEST PASSED"); 91 } 92 93 public float getValue() { 94 return 6; 95 } 96 97 private int getX(int to, int from, int rn) { 98 return (rn*regionCount + to) % N; 99 } 100 101 private int getY(int to, int from, int rn) { 102 return ((rn*regionCount + to) / N + from * K) % (regionCount*K) ; 103 } 104 }