• Home
  • History
  • Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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 
17 public class Main {
18 
19   /// CHECK-START: void Main.testNewStringFromBytes() builder (after)
20   /// CHECK-DAG:     InvokeStaticOrDirect method_name:java.lang.StringFactory.newStringFromBytes intrinsic:None
21 
22   /// CHECK-START: void Main.testNewStringFromBytes() intrinsics_recognition (after)
23   /// CHECK-DAG:     InvokeStaticOrDirect method_name:java.lang.StringFactory.newStringFromBytes intrinsic:StringNewStringFromBytes
24 
testNewStringFromBytes()25   public static void testNewStringFromBytes() {
26     byte[] bytes = { 'f', 'o', 'o' };
27     String s = StringFactory.newStringFromBytes(bytes, 0, 0, 3);
28     System.out.println(s);
29   }
30 
31   // The (native) method
32   //
33   //   java.lang.StringFactory.newStringFromChars(int offset, int charCount, char[] data)
34   //
35   // is recognized as intrinsic StringNewStringFromChars.  However,
36   // because this method is not public, we cannot call it and check
37   // that the compiler actually intrinsifies it (as it does for the
38   // StringNewStringFromBytes and StringNewStringFromString
39   // intrinsics) with Checker.
40   //
41   // We can call a public method such as
42   //
43   //   java.lang.StringFactory.newStringFromChars(char[] data)
44   //
45   // which contains a call to the former (non-public) native method.
46   // However, this call will not be inlined (because it is a method in
47   // another Dex file and which contains a call, which needs an
48   // environment), so we cannot use Checker here to ensure the native
49   // call was intrinsified either.
50 
51   /// CHECK-START: void Main.testNewStringFromChars() builder (after)
52   /// CHECK-DAG:     InvokeStaticOrDirect method_name:java.lang.StringFactory.newStringFromChars intrinsic:None
53 
54   /// CHECK-START: void Main.testNewStringFromChars() intrinsics_recognition (after)
55   /// CHECK-DAG:     InvokeStaticOrDirect method_name:java.lang.StringFactory.newStringFromChars intrinsic:None
56 
57   /// CHECK-START: void Main.testNewStringFromChars() inliner (after)
58   /// CHECK-DAG:     InvokeStaticOrDirect method_name:java.lang.StringFactory.newStringFromChars intrinsic:None
59 
testNewStringFromChars()60   public static void testNewStringFromChars() {
61     char[] chars = { 'b', 'a', 'r' };
62     String s = StringFactory.newStringFromChars(chars);
63     System.out.println(s);
64   }
65 
66   /// CHECK-START: void Main.testNewStringFromString() builder (after)
67   /// CHECK-DAG:     InvokeStaticOrDirect method_name:java.lang.StringFactory.newStringFromString intrinsic:None
68 
69   /// CHECK-START: void Main.testNewStringFromString() intrinsics_recognition (after)
70   /// CHECK-DAG:     InvokeStaticOrDirect method_name:java.lang.StringFactory.newStringFromString intrinsic:StringNewStringFromString
71 
testNewStringFromString()72   public static void testNewStringFromString() {
73     String s1 = "baz";
74     String s2 = StringFactory.newStringFromString(s1);
75     System.out.println(s2);
76   }
77 
main(String[] args)78   public static void main(String[] args) throws Exception {
79     testNewStringFromBytes();
80     testNewStringFromChars();
81     testNewStringFromString();
82   }
83 }
84