Path: blob/master/test/hotspot/jtreg/compiler/arraycopy/TestCloneAccessStressGCM.java
41149 views
/*1* Copyright (c) 2020, 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*30* @run main/othervm -Xbatch31* -XX:CompileCommand=dontinline,compiler.arraycopy.TestCloneAccessStressGCM::test32* -XX:+UnlockDiagnosticVMOptions -XX:+StressGCM -XX:-ReduceInitialCardMarks33* compiler.arraycopy.TestCloneAccessStressGCM34* @run main/othervm -Xbatch35* -XX:CompileCommand=dontinline,compiler.arraycopy.TestCloneAccessStressGCM::test36* -XX:+UnlockDiagnosticVMOptions -XX:+StressGCM -XX:-ReduceInitialCardMarks37* -XX:-ReduceBulkZeroing38* compiler.arraycopy.TestCloneAccessStressGCM39*/4041package compiler.arraycopy;4243public class TestCloneAccessStressGCM {4445static int test(E src) throws CloneNotSupportedException {46// ArrayCopyNode for this clone is not inlined since there are more than 8 (=ArrayCopyLoadStoreMaxElem) fields47E dest = (E)src.clone();4849// The ArrayCopyNode initialization for the clone is executed after the LoadI nodes for 'dest' due to a50// memory input from the uninitialized new object instead of the ArrayCopyNode. As a result, uninitialized51// memory is read for each field and added together.52return dest.i1 + dest.i2 + dest.i3 + dest.i4 + dest.i5 +53dest.i6 + dest.i7 + dest.i8 + dest.i9;54}5556public static void main(String[] args) throws Exception {57TestCloneAccessStressGCM test = new TestCloneAccessStressGCM();58int result = 0;59E e = new E();60for (int i = 0; i < 20000; i++) {61result = test(e);62if (result != 36) {63throw new RuntimeException("Return value not 36. Got: " + result + "; additional check: " + e.sum());64}65}6667if (result != 36) {68throw new RuntimeException("Return value not 36. Got: " + result + "; additional check: " + e.sum());69}70}71}7273class E implements Cloneable {74/*75* Need more than 8 (=ArrayCopyLoadStoreMaxElem) fields76*/77int i1;78int i2;79int i3;80int i4;81int i5;82int i6;83int i7;84int i8;85int i9;8687E() {88i1 = 0;89i2 = 1;90i3 = 2;91i4 = 3;92i5 = 4;93i6 = 5;94i7 = 6;95i8 = 7;96i9 = 8;97}9899public Object clone() throws CloneNotSupportedException {100return super.clone();101}102103public int sum() {104return i1 + i2 + i3 + i4 + i5 + i6 + i7 + i8 + i9;105}106}107108109110