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