|
| 1 | +/* |
| 2 | + * Copyright (c) 2020, 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 | + * @test |
| 26 | + * @bug 8235332 |
| 27 | + * @summary Test cloning with more than 8 (=ArrayCopyLoadStoreMaxElem) fields with StressGCM |
| 28 | + * @library / |
| 29 | + * |
| 30 | + * @run main/othervm -Xbatch |
| 31 | + * -XX:CompileCommand=dontinline,compiler.arraycopy.TestCloneAccessStressGCM::test |
| 32 | + * -XX:+UnlockDiagnosticVMOptions -XX:+StressGCM -XX:-ReduceInitialCardMarks |
| 33 | + * compiler.arraycopy.TestCloneAccessStressGCM |
| 34 | + */ |
| 35 | + |
| 36 | +package compiler.arraycopy; |
| 37 | + |
| 38 | +public class TestCloneAccessStressGCM { |
| 39 | + |
| 40 | + static int test(E src) throws CloneNotSupportedException { |
| 41 | + // ArrayCopyNode for this clone is not inlined since there are more than 8 (=ArrayCopyLoadStoreMaxElem) fields |
| 42 | + E dest = (E)src.clone(); |
| 43 | + |
| 44 | + // The ArrayCopyNode initialization for the clone is executed after the LoadI nodes for 'dest' due to a |
| 45 | + // memory input from the uninitialized new object instead of the ArrayCopyNode. As a result, uninitialized |
| 46 | + // memory is read for each field and added together. |
| 47 | + return dest.i1 + dest.i2 + dest.i3 + dest.i4 + dest.i5 + |
| 48 | + dest.i6 + dest.i7 + dest.i8 + dest.i9; |
| 49 | + } |
| 50 | + |
| 51 | + public static void main(String[] args) throws Exception { |
| 52 | + TestCloneAccessStressGCM test = new TestCloneAccessStressGCM(); |
| 53 | + int result = 0; |
| 54 | + E e = new E(); |
| 55 | + for (int i = 0; i < 20000; i++) { |
| 56 | + result = test(e); |
| 57 | + if (result != 36) { |
| 58 | + throw new RuntimeException("Return value not 36. Got: " + result + "; additional check: " + e.sum()); |
| 59 | + } |
| 60 | + } |
| 61 | + |
| 62 | + if (result != 36) { |
| 63 | + throw new RuntimeException("Return value not 36. Got: " + result + "; additional check: " + e.sum()); |
| 64 | + } |
| 65 | + } |
| 66 | +} |
| 67 | + |
| 68 | +class E implements Cloneable { |
| 69 | + /* |
| 70 | + * Need more than 8 (=ArrayCopyLoadStoreMaxElem) fields |
| 71 | + */ |
| 72 | + int i1; |
| 73 | + int i2; |
| 74 | + int i3; |
| 75 | + int i4; |
| 76 | + int i5; |
| 77 | + int i6; |
| 78 | + int i7; |
| 79 | + int i8; |
| 80 | + int i9; |
| 81 | + |
| 82 | + E() { |
| 83 | + i1 = 0; |
| 84 | + i2 = 1; |
| 85 | + i3 = 2; |
| 86 | + i4 = 3; |
| 87 | + i5 = 4; |
| 88 | + i6 = 5; |
| 89 | + i7 = 6; |
| 90 | + i8 = 7; |
| 91 | + i9 = 8; |
| 92 | + } |
| 93 | + |
| 94 | + public Object clone() throws CloneNotSupportedException { |
| 95 | + return super.clone(); |
| 96 | + } |
| 97 | + |
| 98 | + public int sum() { |
| 99 | + return i1 + i2 + i3 + i4 + i5 + i6 + i7 + i8 + i9; |
| 100 | + } |
| 101 | +} |
| 102 | + |
0 commit comments