Path: blob/master/test/hotspot/jtreg/compiler/arraycopy/TestCloneAccessStressGCM.java
64474 views
/*1* Copyright (c) 2020, 2021, 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* @key stress randomness26* @bug 8235332 824822627* @summary Test cloning with more than 8 (=ArrayCopyLoadStoreMaxElem) fields with StressGCM28* @library /29* @requires vm.compiler2.enabled | vm.graal.enabled30*31* @run main/othervm -Xbatch32* -XX:CompileCommand=dontinline,compiler.arraycopy.TestCloneAccessStressGCM::test33* -XX:+UnlockDiagnosticVMOptions -XX:+StressGCM -XX:-ReduceInitialCardMarks34* compiler.arraycopy.TestCloneAccessStressGCM35* @run main/othervm -Xbatch36* -XX:CompileCommand=dontinline,compiler.arraycopy.TestCloneAccessStressGCM::test37* -XX:+UnlockDiagnosticVMOptions -XX:+StressGCM -XX:-ReduceInitialCardMarks38* -XX:-ReduceBulkZeroing39* compiler.arraycopy.TestCloneAccessStressGCM40*/4142package compiler.arraycopy;4344public class TestCloneAccessStressGCM {4546static int test(E src) throws CloneNotSupportedException {47// ArrayCopyNode for this clone is not inlined since there are more than 8 (=ArrayCopyLoadStoreMaxElem) fields48E dest = (E)src.clone();4950// The ArrayCopyNode initialization for the clone is executed after the LoadI nodes for 'dest' due to a51// memory input from the uninitialized new object instead of the ArrayCopyNode. As a result, uninitialized52// memory is read for each field and added together.53return dest.i1 + dest.i2 + dest.i3 + dest.i4 + dest.i5 +54dest.i6 + dest.i7 + dest.i8 + dest.i9;55}5657public static void main(String[] args) throws Exception {58TestCloneAccessStressGCM test = new TestCloneAccessStressGCM();59int result = 0;60E e = new E();61for (int i = 0; i < 20000; i++) {62result = test(e);63if (result != 36) {64throw new RuntimeException("Return value not 36. Got: " + result + "; additional check: " + e.sum());65}66}6768if (result != 36) {69throw new RuntimeException("Return value not 36. Got: " + result + "; additional check: " + e.sum());70}71}72}7374class E implements Cloneable {75/*76* Need more than 8 (=ArrayCopyLoadStoreMaxElem) fields77*/78int i1;79int i2;80int i3;81int i4;82int i5;83int i6;84int i7;85int i8;86int i9;8788E() {89i1 = 0;90i2 = 1;91i3 = 2;92i4 = 3;93i5 = 4;94i6 = 5;95i7 = 6;96i8 = 7;97i9 = 8;98}99100public Object clone() throws CloneNotSupportedException {101return super.clone();102}103104public int sum() {105return i1 + i2 + i3 + i4 + i5 + i6 + i7 + i8 + i9;106}107}108109110111