Path: blob/master/test/hotspot/jtreg/compiler/arraycopy/TestInstanceCloneAsLoadsStores.java
41149 views
/*1* Copyright (c) 2016, 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 824822626* @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*/4546package compiler.arraycopy;4748public class TestInstanceCloneAsLoadsStores extends TestInstanceCloneUtils {4950// Should be compiled as loads/stores51static Object m1(D src) throws CloneNotSupportedException {52return src.clone();53}5455// Should be compiled as adds of src (dest allocation eliminated)56static int m2(D src) throws CloneNotSupportedException {57D dest = (D)src.clone();58return dest.i1 + dest.i2 + ((int)dest.i3) + dest.i4 + dest.i5;59}6061// Should be compiled as arraycopy stub call (object too large)62static int m3(E src) throws CloneNotSupportedException {63E dest = (E)src.clone();64return dest.i1 + dest.i2 + dest.i3 + dest.i4 + dest.i5 +65dest.i6 + dest.i7 + dest.i8 + dest.i9;66}6768// Need profiling on src's type to be able to know number of69// fields. Cannot clone as loads/stores if compile doesn't use it.70static Object m4(A src) throws CloneNotSupportedException {71return src.clone();72}7374// Same as above but should optimize out dest allocation75static int m5(A src) throws CloneNotSupportedException {76A dest = (A)src.clone();77return dest.i1 + dest.i2 + dest.i3 + dest.i4 + dest.i5;78}7980// Check that if we have no fields to clone we do fine81static Object m6(F src) throws CloneNotSupportedException {82return src.clone();83}8485// With virtual call to clone: clone inlined from profling which86// gives us exact type of src so we can clone it with87// loads/stores.88static G m7(G src) throws CloneNotSupportedException {89return (G)src.myclone();90}9192// Virtual call to clone but single target: exact type unknown,93// clone intrinsic uses profiling to determine exact type and94// clone with loads/stores.95static J m8(J src) throws CloneNotSupportedException {96return (J)src.myclone();97}9899public static void main(String[] args) throws Exception {100101TestInstanceCloneAsLoadsStores test = new TestInstanceCloneAsLoadsStores();102103test.doTest(d, "m1");104test.doTest(d, "m2");105test.doTest(e, "m3");106test.doTest(a, "m4");107test.doTest(a, "m5");108test.doTest(f, "m6");109test.doTest(g, "m7");110test.doTest(k, "m8");111112if (!test.success) {113throw new RuntimeException("some tests failed");114}115116}117}118119120