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 * @ignore 8153194 29 * @run main/othervm/timeout=300 -Xbatch -Xmx128m PreserveFPRegistersTest 30 */ 31 public class PreserveFPRegistersTest { 32 33 public static void main(String... args) throws InterruptedException { 34 new PreserveFPRegistersTest().go(); 35 } 36 37 public final Object[][] storage; 38 39 /** 40 * Number of objects per region. 41 */ 42 public final int K = 10; 43 44 /** 45 * Length of object array: sizeOf(Object[N]) ~= regionSize / K . 46 */ 47 public final int N; 48 49 /** 50 * How many regions involved into testing. 51 */ 52 public final int regionCount; 53 54 PreserveFPRegistersTest() { 55 long regionSize = 1_000_000; //WB.g1RegionSize(); 56 57 Runtime rt = Runtime.getRuntime(); 58 long used = rt.totalMemory() - rt.freeMemory(); 59 long totalFree = rt.maxMemory() - used; 60 regionCount = (int) ( (totalFree / regionSize) * 0.9); 61 int refSize = 4; 62 63 N = (int) ((regionSize / K ) / refSize) - 5; 64 storage = new Object[regionCount * K][]; 65 for (int i = 0; i < storage.length; i++) { 66 storage[i] = new Object[N]; 67 } 68 } 69 70 public void go() throws InterruptedException { 71 final float FINAL = getValue(); 72 73 for (int to = 0; to < regionCount; to++) { 74 Object celebrity = storage[to * K]; 75 for (int from = 0; from < regionCount; from++) { 76 for (int rn = 0; rn != 100; rn++) { 77 storage[getY(to, from, rn)][getX(to, from, rn)] = celebrity; 78 } 79 if (FINAL != getValue()) { 80 throw new AssertionError("Final value has changed: " + FINAL + " != " + getValue()); 81 } 82 } 83 } 84 85 System.out.println("TEST PASSED"); 86 } 87 88 public float getValue() { 89 return 6; 90 } 91 92 private int getX(int to, int from, int rn) { 93 return (rn*regionCount + to) % N; 94 } 95 96 private int getY(int to, int from, int rn) { 97 return ((rn*regionCount + to) / N + from * K) % (regionCount*K) ; 98 } 99 }