hotspot/test/compiler/arraycopy/TestInstanceCloneAsLoadsStores.java
author thartmann
Thu, 04 Aug 2016 10:34:34 +0200
changeset 40365 3791c1b34e36
parent 40059 c2304140ed64
permissions -rw-r--r--
8136818: Test compiler/arraycopy/TestEliminatedArrayCopyDeopt.java fails with "m1 failed" Summary: Added missing Op_StoreB check to ArrayCopyNode::may_modify_helper(). Reviewed-by: kvn
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
28396
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
     1
/*
39254
fb4492288b01 8156760: VM crashes if -XX:-ReduceInitialCardMarks is set
thartmann
parents: 30629
diff changeset
     2
 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
28396
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
     4
 *
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
     7
 * published by the Free Software Foundation.
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
     8
 *
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    13
 * accompanied this code).
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    14
 *
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    18
 *
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    21
 * questions.
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    22
 */
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    23
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    24
/*
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    25
 * @test
39254
fb4492288b01 8156760: VM crashes if -XX:-ReduceInitialCardMarks is set
thartmann
parents: 30629
diff changeset
    26
 * @bug 6700100 8156760
28396
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    27
 * @summary small instance clone as loads/stores
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 39254
diff changeset
    28
 * @library /
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 39254
diff changeset
    29
 *
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 39254
diff changeset
    30
 * @run main/othervm -XX:-BackgroundCompilation -XX:-UseOnStackReplacement
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 39254
diff changeset
    31
 *                   -XX:CompileCommand=dontinline,compiler.arraycopy.TestInstanceCloneAsLoadsStores::m*
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 39254
diff changeset
    32
 *                   compiler.arraycopy.TestInstanceCloneAsLoadsStores
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 39254
diff changeset
    33
 * @run main/othervm -XX:-BackgroundCompilation -XX:-UseOnStackReplacement
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 39254
diff changeset
    34
 *                   -XX:CompileCommand=dontinline,compiler.arraycopy.TestInstanceCloneAsLoadsStores::m*
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 39254
diff changeset
    35
 *                   -XX:+IgnoreUnrecognizedVMOptions -XX:+StressArrayCopyMacroNode
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 39254
diff changeset
    36
 *                   compiler.arraycopy.TestInstanceCloneAsLoadsStores
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 39254
diff changeset
    37
 * @run main/othervm -XX:-BackgroundCompilation -XX:-UseOnStackReplacement
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 39254
diff changeset
    38
 *                   -XX:CompileCommand=dontinline,compiler.arraycopy.TestInstanceCloneAsLoadsStores::m*
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 39254
diff changeset
    39
 *                   -XX:+IgnoreUnrecognizedVMOptions -XX:-ReduceInitialCardMarks
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 39254
diff changeset
    40
 *                   compiler.arraycopy.TestInstanceCloneAsLoadsStores
28396
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    41
 */
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    42
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 39254
diff changeset
    43
package compiler.arraycopy;
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 39254
diff changeset
    44
30629
b6e5ad2f18d5 8076188: Optimize arraycopy out for non escaping destination
roland
parents: 28396
diff changeset
    45
public class TestInstanceCloneAsLoadsStores extends TestInstanceCloneUtils {
28396
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    46
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    47
    // Should be compiled as loads/stores
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    48
    static Object m1(D src) throws CloneNotSupportedException {
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    49
        return src.clone();
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    50
    }
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    51
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    52
    // Should be compiled as adds of src (dest allocation eliminated)
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    53
    static int m2(D src) throws CloneNotSupportedException {
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    54
        D dest = (D)src.clone();
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    55
        return dest.i1 + dest.i2 + ((int)dest.i3) + dest.i4 + dest.i5;
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    56
    }
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    57
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    58
    // Should be compiled as arraycopy stub call (object too large)
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    59
    static int m3(E src) throws CloneNotSupportedException {
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    60
        E dest = (E)src.clone();
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    61
        return dest.i1 + dest.i2 + dest.i3 + dest.i4 + dest.i5 +
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    62
            dest.i6 + dest.i7 + dest.i8 + dest.i9;
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    63
    }
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    64
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    65
    // Need profiling on src's type to be able to know number of
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    66
    // fields. Cannot clone as loads/stores if compile doesn't use it.
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    67
    static Object m4(A src) throws CloneNotSupportedException {
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    68
        return src.clone();
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    69
    }
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    70
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    71
    // Same as above but should optimize out dest allocation
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    72
    static int m5(A src) throws CloneNotSupportedException {
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    73
        A dest = (A)src.clone();
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    74
        return dest.i1 + dest.i2 + dest.i3 + dest.i4 + dest.i5;
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    75
    }
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    76
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    77
    // Check that if we have no fields to clone we do fine
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    78
    static Object m6(F src) throws CloneNotSupportedException {
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    79
        return src.clone();
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    80
    }
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    81
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    82
    // With virtual call to clone: clone inlined from profling which
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    83
    // gives us exact type of src so we can clone it with
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    84
    // loads/stores.
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    85
    static G m7(G src) throws CloneNotSupportedException {
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    86
        return (G)src.myclone();
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    87
    }
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    88
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    89
    // Virtual call to clone but single target: exact type unknown,
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    90
    // clone intrinsic uses profiling to determine exact type and
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    91
    // clone with loads/stores.
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    92
    static J m8(J src) throws CloneNotSupportedException {
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    93
        return (J)src.myclone();
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    94
    }
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    95
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    96
    public static void main(String[] args) throws Exception {
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    97
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    98
        TestInstanceCloneAsLoadsStores test = new TestInstanceCloneAsLoadsStores();
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    99
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
   100
        test.doTest(d, "m1");
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
   101
        test.doTest(d, "m2");
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
   102
        test.doTest(e, "m3");
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
   103
        test.doTest(a, "m4");
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
   104
        test.doTest(a, "m5");
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
   105
        test.doTest(f, "m6");
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
   106
        test.doTest(g, "m7");
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
   107
        test.doTest(k, "m8");
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
   108
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
   109
        if (!test.success) {
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
   110
            throw new RuntimeException("some tests failed");
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
   111
        }
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
   112
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
   113
    }
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
   114
}