hotspot/test/compiler/arraycopy/TestArrayCopyMacro.java
author roland
Tue, 16 Dec 2014 13:49:36 +0100
changeset 28396 7fe4347e6792
child 40059 c2304140ed64
permissions -rw-r--r--
6700100: optimize inline_native_clone() for small objects with exact klass Summary: optimize small instance clones as loads/stores Reviewed-by: kvn, iveresov
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 7173584
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    27
 * @summary arraycopy as macro node
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    28
 * @run main/othervm -XX:-BackgroundCompilation -XX:-UseOnStackReplacement TestArrayCopyMacro
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    29
 *
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    30
 */
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
public class TestArrayCopyMacro {
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    33
    static class A {
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    34
    }
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
    // In its own method so profiling reports both branches taken
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    37
    static Object m2(Object o1, Object o2, int i) {
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    38
        if (i == 4) {
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    39
            return o1;
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
        return o2;
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    42
    }
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    43
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    44
    static Object m1(A[] src, Object dest) {
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    45
        int i = 1;
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
        // won't be optimized out until after parsing
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    48
        for (; i < 3; i *= 4) {
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    49
        }
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    50
        dest = m2(new A[10], dest, i);
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
        // dest is new array here but C2 picks the "disjoint" stub
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    53
        // only if stub to call is decided after parsing
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    54
        System.arraycopy(src, 0, dest, 0, 10);
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    55
        return dest;
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
    public static void main(String[] args) {
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    59
        A[] array_src = new A[10];
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    60
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    61
        for (int i = 0; i < array_src.length; i++) {
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    62
            array_src[i] = new A();
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
        for (int i = 0; i < 20000; i++) {
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    66
            m2(null, null, 0);
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    67
        }
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    68
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    69
        for (int i = 0; i < 20000; i++) {
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    70
            Object[] array_dest = (Object[])m1(array_src, null);
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    71
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    72
            for (int j = 0; j < array_src.length; j++) {
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    73
                if (array_dest[j] != array_src[j]) {
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    74
                    throw new RuntimeException("copy failed at index " + j + " src = " + array_src[j] + " dest = " + array_dest[j]);
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
        }
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    78
    }
7fe4347e6792 6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff changeset
    79
}