Path: blob/master/test/hotspot/jtreg/compiler/arraycopy/TestCloneAccess.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* @bug 824879126* @summary Test cloning with more than 8 (=ArrayCopyLoadStoreMaxElem) where loads are wrongly replaced by zero.27* @run main/othervm -XX:-ReduceBulkZeroing28* -XX:CompileCommand=dontinline,compiler.arraycopy.TestCloneAccess::*29* compiler.arraycopy.TestCloneAccess30* @run main/othervm -XX:-ReduceBulkZeroing -XX:-ReduceInitialCardMarks31* -XX:CompileCommand=dontinline,compiler.arraycopy.TestCloneAccess::*32* compiler.arraycopy.TestCloneAccess33*/34package compiler.arraycopy;3536public class TestCloneAccess {37static int test(E src) throws CloneNotSupportedException {38// ArrayCopyNode for this clone is not inlined since there are more than 8 (=ArrayCopyLoadStoreMaxElem) fields39src.i1 = 3;40E dest = (E)src.clone();41dontInline(dest.i1, dest.i2);4243// Both loads are wrongly optimized and replaced by a constant zero. LoadNode::Value() tries to find out if a load44// is done from a freshly-allocated object. If that is the case, the load can be replaced by the default value zero.45// However, in this case, the Allocation node belongs to an ArrayCopyNode which is responsible for initializing 'dest'.46// If -XX:-ReduceBulkZeroing is set, the InitializationNode of the allocation does not bail out of this optimization47// which results in a replacement of both loads by zero. This is addressed by this fix. If -XX:+ReduceBulkZeroing is48// set, then we already bail out and perform the load correctly.49return dest.i1 + dest.i2;50}5152public static void main(String[] args) throws Exception {53E e = new E();54e.i2 = 4;55int res = 0;56for (int i = 0; i < 20000; i++) {57res = test(e);58if (res != 7 || e.i1 != 3 || e.i2 != 4) {59throw new RuntimeException("Wrong result! Expected: res = 7, e.i1 = 3, e.i2 = 4 "60+ "but got: res = " + res + ", e.i1 = " + e.i1 + ", e.i2 = " + e.i2);61}62}63}6465// Dont inline this method66public static void dontInline(int i1, int i2) {67}68}6970class E implements Cloneable {71/*72* Need more than 8 (=ArrayCopyLoadStoreMaxElem) fields73*/74int i1;75int i2;76int i3;77int i4;78int i5;79int i6;80int i7;81int i8;82int i9;8384E() {85i1 = 0;86i2 = 1;87i3 = 2;88i4 = 3;89i5 = 4;90i6 = 5;91i7 = 6;92i8 = 7;93i9 = 8;94}9596public Object clone() throws CloneNotSupportedException {97return super.clone();98}99}100101102103