blob: 34af579a4bea0f94213a183028e45498a8e168a7 [file] [log] [blame]
Roland Levillainf969a202016-03-09 16:14:00 +00001/*
2 * Copyright (C) 2016 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17public class Main {
18
19 /// CHECK-START: void Main.testNewStringFromBytes() builder (after)
Roland Levillainf969a202016-03-09 16:14:00 +000020 /// CHECK-DAG: InvokeStaticOrDirect method_name:java.lang.StringFactory.newStringFromBytes intrinsic:StringNewStringFromBytes
21
22 public static void testNewStringFromBytes() {
23 byte[] bytes = { 'f', 'o', 'o' };
24 String s = StringFactory.newStringFromBytes(bytes, 0, 0, 3);
25 System.out.println(s);
26 }
27
28 // The (native) method
29 //
30 // java.lang.StringFactory.newStringFromChars(int offset, int charCount, char[] data)
31 //
32 // is recognized as intrinsic StringNewStringFromChars. However,
33 // because this method is not public, we cannot call it and check
34 // that the compiler actually intrinsifies it (as it does for the
35 // StringNewStringFromBytes and StringNewStringFromString
36 // intrinsics) with Checker.
37 //
38 // We can call a public method such as
39 //
40 // java.lang.StringFactory.newStringFromChars(char[] data)
41 //
42 // which contains a call to the former (non-public) native method.
Santiago Aboy Solanesc3e004d2021-11-24 10:29:38 +000043 // After the inliner runs, we can see the inlined call and check
44 // that the compiler intrinsifies it.
Roland Levillainf969a202016-03-09 16:14:00 +000045
46 /// CHECK-START: void Main.testNewStringFromChars() builder (after)
47 /// CHECK-DAG: InvokeStaticOrDirect method_name:java.lang.StringFactory.newStringFromChars intrinsic:None
48
Roland Levillainf969a202016-03-09 16:14:00 +000049 /// CHECK-START: void Main.testNewStringFromChars() inliner (after)
Santiago Aboy Solanesc3e004d2021-11-24 10:29:38 +000050 /// CHECK-DAG: InvokeStaticOrDirect method_name:java.lang.StringFactory.newStringFromChars intrinsic:StringNewStringFromChars
Roland Levillainf969a202016-03-09 16:14:00 +000051
52 public static void testNewStringFromChars() {
53 char[] chars = { 'b', 'a', 'r' };
54 String s = StringFactory.newStringFromChars(chars);
55 System.out.println(s);
56 }
57
58 /// CHECK-START: void Main.testNewStringFromString() builder (after)
Roland Levillainf969a202016-03-09 16:14:00 +000059 /// CHECK-DAG: InvokeStaticOrDirect method_name:java.lang.StringFactory.newStringFromString intrinsic:StringNewStringFromString
60
61 public static void testNewStringFromString() {
62 String s1 = "baz";
63 String s2 = StringFactory.newStringFromString(s1);
64 System.out.println(s2);
65 }
66
67 public static void main(String[] args) throws Exception {
68 testNewStringFromBytes();
69 testNewStringFromChars();
70 testNewStringFromString();
71 }
72}