Path: blob/master/test/hotspot/jtreg/compiler/arraycopy/TestInstanceCloneAsLoadsStores.java
64474 views
/*1* Copyright (c) 2016, 2022, 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 6700100 8156760 8248226 828530126* @summary small instance clone as loads/stores27* @library /28*29* @run main/othervm -XX:-BackgroundCompilation -XX:-UseOnStackReplacement30* -XX:CompileCommand=dontinline,compiler.arraycopy.TestInstanceCloneAsLoadsStores::m*31* compiler.arraycopy.TestInstanceCloneAsLoadsStores32* @run main/othervm -XX:-BackgroundCompilation -XX:-UseOnStackReplacement33* -XX:CompileCommand=dontinline,compiler.arraycopy.TestInstanceCloneAsLoadsStores::m*34* -XX:+IgnoreUnrecognizedVMOptions -XX:+StressArrayCopyMacroNode35* compiler.arraycopy.TestInstanceCloneAsLoadsStores36* @run main/othervm -XX:-BackgroundCompilation -XX:-UseOnStackReplacement37* -XX:CompileCommand=dontinline,compiler.arraycopy.TestInstanceCloneAsLoadsStores::m*38* -XX:+IgnoreUnrecognizedVMOptions -XX:-ReduceInitialCardMarks39* compiler.arraycopy.TestInstanceCloneAsLoadsStores40* @run main/othervm -XX:-BackgroundCompilation -XX:-UseOnStackReplacement41* -XX:CompileCommand=dontinline,compiler.arraycopy.TestInstanceCloneAsLoadsStores::m*42* -XX:+IgnoreUnrecognizedVMOptions -XX:-ReduceInitialCardMarks -XX:-ReduceBulkZeroing43* compiler.arraycopy.TestInstanceCloneAsLoadsStores44* @run main/othervm -XX:-BackgroundCompilation -XX:-UseOnStackReplacement45* -XX:CompileCommand=dontinline,compiler.arraycopy.TestInstanceCloneAsLoadsStores::m*46* -XX:+UnlockExperimentalVMOptions -XX:+AlwaysAtomicAccesses47* compiler.arraycopy.TestInstanceCloneAsLoadsStores48*/4950package compiler.arraycopy;5152public class TestInstanceCloneAsLoadsStores extends TestInstanceCloneUtils {5354// Should be compiled as loads/stores55static Object m1(D src) throws CloneNotSupportedException {56return src.clone();57}5859// Should be compiled as adds of src (dest allocation eliminated)60static int m2(D src) throws CloneNotSupportedException {61D dest = (D)src.clone();62return dest.i1 + dest.i2 + ((int)dest.i3) + dest.i4 + dest.i5;63}6465// Should be compiled as arraycopy stub call (object too large)66static int m3(E src) throws CloneNotSupportedException {67E dest = (E)src.clone();68return dest.i1 + dest.i2 + dest.i3 + dest.i4 + dest.i5 +69dest.i6 + dest.i7 + dest.i8 + dest.i9;70}7172// Need profiling on src's type to be able to know number of73// fields. Cannot clone as loads/stores if compile doesn't use it.74static Object m4(A src) throws CloneNotSupportedException {75return src.clone();76}7778// Same as above but should optimize out dest allocation79static int m5(A src) throws CloneNotSupportedException {80A dest = (A)src.clone();81return dest.i1 + dest.i2 + dest.i3 + dest.i4 + dest.i5;82}8384// Check that if we have no fields to clone we do fine85static Object m6(F src) throws CloneNotSupportedException {86return src.clone();87}8889// With virtual call to clone: clone inlined from profling which90// gives us exact type of src so we can clone it with91// loads/stores.92static G m7(G src) throws CloneNotSupportedException {93return (G)src.myclone();94}9596// Virtual call to clone but single target: exact type unknown,97// clone intrinsic uses profiling to determine exact type and98// clone with loads/stores.99static J m8(J src) throws CloneNotSupportedException {100return (J)src.myclone();101}102103public static void main(String[] args) throws Exception {104105TestInstanceCloneAsLoadsStores test = new TestInstanceCloneAsLoadsStores();106107test.doTest(d, "m1");108test.doTest(d, "m2");109test.doTest(e, "m3");110test.doTest(a, "m4");111test.doTest(a, "m5");112test.doTest(f, "m6");113test.doTest(g, "m7");114test.doTest(k, "m8");115116if (!test.success) {117throw new RuntimeException("some tests failed");118}119120}121}122123124