author | alanb |
Thu, 01 Dec 2016 15:54:39 +0000 | |
changeset 42309 | 21f9f3fbc302 |
parent 40059 | c2304140ed64 |
permissions | -rw-r--r-- |
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 |
* |
40059 | 29 |
* @run main/othervm -XX:-BackgroundCompilation -XX:-UseOnStackReplacement |
30 |
* compiler.arraycopy.TestArrayCopyMacro |
|
28396
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 |
|
40059 | 33 |
package compiler.arraycopy; |
34 |
||
28396
7fe4347e6792
6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff
changeset
|
35 |
public class TestArrayCopyMacro { |
7fe4347e6792
6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff
changeset
|
36 |
static class A { |
7fe4347e6792
6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff
changeset
|
37 |
} |
7fe4347e6792
6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff
changeset
|
38 |
|
7fe4347e6792
6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff
changeset
|
39 |
// 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
|
40 |
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
|
41 |
if (i == 4) { |
7fe4347e6792
6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff
changeset
|
42 |
return o1; |
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 |
return o2; |
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 |
static Object m1(A[] src, Object dest) { |
7fe4347e6792
6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff
changeset
|
48 |
int i = 1; |
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 |
// won't be optimized out until after parsing |
7fe4347e6792
6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff
changeset
|
51 |
for (; i < 3; i *= 4) { |
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 |
dest = m2(new A[10], dest, i); |
7fe4347e6792
6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff
changeset
|
54 |
|
7fe4347e6792
6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff
changeset
|
55 |
// 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
|
56 |
// 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
|
57 |
System.arraycopy(src, 0, dest, 0, 10); |
7fe4347e6792
6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff
changeset
|
58 |
return dest; |
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 |
|
7fe4347e6792
6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff
changeset
|
61 |
public static void main(String[] args) { |
7fe4347e6792
6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff
changeset
|
62 |
A[] array_src = new A[10]; |
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 |
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
|
65 |
array_src[i] = new A(); |
7fe4347e6792
6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff
changeset
|
66 |
} |
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 |
for (int i = 0; i < 20000; i++) { |
7fe4347e6792
6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff
changeset
|
69 |
m2(null, null, 0); |
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 |
|
7fe4347e6792
6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff
changeset
|
72 |
for (int i = 0; i < 20000; i++) { |
7fe4347e6792
6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff
changeset
|
73 |
Object[] array_dest = (Object[])m1(array_src, null); |
7fe4347e6792
6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff
changeset
|
74 |
|
7fe4347e6792
6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff
changeset
|
75 |
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
|
76 |
if (array_dest[j] != array_src[j]) { |
7fe4347e6792
6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff
changeset
|
77 |
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
|
78 |
} |
7fe4347e6792
6700100: optimize inline_native_clone() for small objects with exact klass
roland
parents:
diff
changeset
|
79 |
} |
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 |
} |