hotspot/test/compiler/arraycopy/TestInstanceCloneAsLoadsStores.java
author thartmann
Thu, 12 May 2016 08:23:25 +0200
changeset 38675 066fcb1eb80a
parent 30629 b6e5ad2f18d5
child 39254 fb4492288b01
permissions -rw-r--r--
8155643: Java crash with assert in Xcomp mode and disabled ReduceInitialCardMarks Summary: We should not emit a subtype check for CloneOop arraycopy. 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
/*
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
     2
 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
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
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    26
 * @bug 6700100
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    27
 * @summary small instance clone as loads/stores
30629
b6e5ad2f18d5 8076188: Optimize arraycopy out for non escaping destination
roland
parents: 28396
diff changeset
    28
 * @compile TestInstanceCloneAsLoadsStores.java TestInstanceCloneUtils.java
28396
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    29
 * @run main/othervm -XX:-BackgroundCompilation -XX:-UseOnStackReplacement -XX:CompileCommand=dontinline,TestInstanceCloneAsLoadsStores::m* TestInstanceCloneAsLoadsStores
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    30
 * @run main/othervm -XX:-BackgroundCompilation -XX:-UseOnStackReplacement -XX:CompileCommand=dontinline,TestInstanceCloneAsLoadsStores::m* -XX:+IgnoreUnrecognizedVMOptions -XX:+StressArrayCopyMacroNode TestInstanceCloneAsLoadsStores
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    31
 *
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    32
 */
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    33
30629
b6e5ad2f18d5 8076188: Optimize arraycopy out for non escaping destination
roland
parents: 28396
diff changeset
    34
public class TestInstanceCloneAsLoadsStores extends TestInstanceCloneUtils {
28396
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    35
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    36
    // Should be compiled as loads/stores
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    37
    static Object m1(D src) throws CloneNotSupportedException {
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    38
        return src.clone();
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    39
    }
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    40
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    41
    // 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
    42
    static int m2(D src) throws CloneNotSupportedException {
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    43
        D dest = (D)src.clone();
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    44
        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
    45
    }
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 arraycopy stub call (object too large)
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    48
    static int m3(E src) throws CloneNotSupportedException {
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    49
        E dest = (E)src.clone();
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    50
        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
    51
            dest.i6 + dest.i7 + dest.i8 + dest.i9;
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    52
    }
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    53
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    54
    // 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
    55
    // 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
    56
    static Object m4(A src) throws CloneNotSupportedException {
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    57
        return src.clone();
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    58
    }
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    59
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    60
    // 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
    61
    static int m5(A src) throws CloneNotSupportedException {
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    62
        A dest = (A)src.clone();
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    63
        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
    64
    }
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    65
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    66
    // 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
    67
    static Object m6(F 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
    // 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
    72
    // 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
    73
    // loads/stores.
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    74
    static G m7(G src) throws CloneNotSupportedException {
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    75
        return (G)src.myclone();
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
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    78
    // 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
    79
    // 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
    80
    // clone with loads/stores.
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    81
    static J m8(J src) throws CloneNotSupportedException {
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    82
        return (J)src.myclone();
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    83
    }
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    84
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    85
    public static void main(String[] args) throws Exception {
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    86
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    87
        TestInstanceCloneAsLoadsStores test = new TestInstanceCloneAsLoadsStores();
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
        test.doTest(d, "m1");
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    90
        test.doTest(d, "m2");
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    91
        test.doTest(e, "m3");
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    92
        test.doTest(a, "m4");
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    93
        test.doTest(a, "m5");
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    94
        test.doTest(f, "m6");
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    95
        test.doTest(g, "m7");
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    96
        test.doTest(k, "m8");
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
        if (!test.success) {
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    99
            throw new RuntimeException("some tests failed");
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
   100
        }
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
   101
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
   102
    }
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
   103
}