1 /*
2 * Copyright (c) 2025, Institute of Software, Chinese Academy of Sciences.
3 * All rights reserved.
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 *
6 * This code is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 only, as
8 * published by the Free Software Foundation.
9 *
10 * This code is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * version 2 for more details (a copy is included in the LICENSE file that
14 * accompanied this code).
15 *
16 * You should have received a copy of the GNU General Public License version
17 * 2 along with this work; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19 *
20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21 * or visit www.oracle.com if you need additional information or have any
22 * questions.
23 */
24
25 package compiler.c2.irTests.stringopts;
26
27 import compiler.lib.ir_framework.*;
28
29 /**
30 * @test
31 * @bug 8359270
32 * @requires vm.debug == true & vm.compiler2.enabled
33 * @requires os.arch=="amd64" | os.arch=="x86_64" | os.arch=="riscv64" | os.arch=="aarch64"
34 * @summary C2: alignment check should consider base offset when emitting arraycopy runtime call.
35 * @library /test/lib /
36 * @run driver compiler.c2.irTests.stringopts.TestArrayCopySelect
37 */
38
39 public class TestArrayCopySelect {
40
41 public static final String input_strU = "\u0f21\u0f22\u0f23\u0f24\u0f25\u0f26\u0f27\u0f28";
42 public static final char[] input_arrU = new char[] {'\u0f21', '\u0f22', '\u0f23', '\u0f24',
43 '\u0f25', '\u0f26', '\u0f27', '\u0f28'};
44
45 public static String output_strU;
46 public static char[] output_arrU;
47
48 public static void main(String[] args) {
49 TestFramework.runWithFlags("-XX:-UseCompactObjectHeaders",
50 "-XX:-CompactStrings",
51 "-XX:CompileCommand=inline,java.lang.StringBuilder::toString",
52 "-XX:CompileCommand=inline,java.lang.StringUTF16::getChars",
53 "-XX:CompileCommand=inline,java.lang.StringUTF16::toBytes");
54
55 TestFramework.runWithFlags("-XX:+UseCompactObjectHeaders",
56 "-XX:-CompactStrings",
57 "-XX:CompileCommand=inline,java.lang.StringBuilder::toString",
58 "-XX:CompileCommand=inline,java.lang.StringUTF16::getChars",
59 "-XX:CompileCommand=inline,java.lang.StringUTF16::toBytes");
60 }
61
62 @Test
63 @Warmup(10000)
64 @IR(applyIf = {"UseCompactObjectHeaders", "false"},
65 counts = {IRNode.CALL_OF, "arrayof_jshort_disjoint_arraycopy", ">0"})
66 static void testSBToStringAligned() {
67 // Exercise the StringBuilder.toString API
68 StringBuilder sb = new StringBuilder(input_strU);
69 output_strU = sb.append(input_strU).toString();
70 }
71
72 @Test
73 @Warmup(10000)
74 @IR(applyIf = {"UseCompactObjectHeaders", "true"},
75 counts = {IRNode.CALL_OF, "arrayof_jshort_disjoint_arraycopy", "0"})
76 static void testSBToStringUnAligned() {
77 // Exercise the StringBuilder.toString API
78 StringBuilder sb = new StringBuilder(input_strU);
79 output_strU = sb.append(input_strU).toString();
80 }
81
82 @Test
83 @Warmup(10000)
84 @IR(applyIf = {"UseCompactObjectHeaders", "false"},
85 counts = {IRNode.CALL_OF, "arrayof_jshort_disjoint_arraycopy", ">0"})
86 static void testStrUGetCharsAligned() {
87 // Exercise the StringUTF16.getChars API
88 output_arrU = input_strU.toCharArray();
89 }
90
91 @Test
92 @Warmup(10000)
93 @IR(applyIf = {"UseCompactObjectHeaders", "true"},
94 counts = {IRNode.CALL_OF, "arrayof_jshort_disjoint_arraycopy", "0"})
95 static void testStrUGetCharsUnAligned() {
96 // Exercise the StringUTF16.getChars API
97 output_arrU = input_strU.toCharArray();
98 }
99
100 @Test
101 @Warmup(10000)
102 @IR(applyIf = {"UseCompactObjectHeaders", "false"},
103 counts = {IRNode.CALL_OF, "arrayof_jshort_disjoint_arraycopy", ">0"})
104 static void testStrUtoBytesAligned() {
105 // Exercise the StringUTF16.toBytes API
106 output_strU = String.valueOf(input_arrU);
107 }
108
109 @Test
110 @Warmup(10000)
111 @IR(applyIf = {"UseCompactObjectHeaders", "true"},
112 counts = {IRNode.CALL_OF, "arrayof_jshort_disjoint_arraycopy", "0"})
113 static void testStrUtoBytesUnAligned() {
114 // Exercise the StringUTF16.toBytes API
115 output_strU = String.valueOf(input_arrU);
116 }
117
118 }