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:StringNewStringFromBytes 21 testNewStringFromBytes()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. 43 // However, this call will not be inlined (because it is a method in 44 // another Dex file and which contains a call, which needs an 45 // environment), so we cannot use Checker here to ensure the native 46 // call was intrinsified either. 47 48 /// CHECK-START: void Main.testNewStringFromChars() builder (after) 49 /// CHECK-DAG: InvokeStaticOrDirect method_name:java.lang.StringFactory.newStringFromChars intrinsic:None 50 51 /// CHECK-START: void Main.testNewStringFromChars() inliner (after) 52 /// CHECK-DAG: InvokeStaticOrDirect method_name:java.lang.StringFactory.newStringFromChars intrinsic:None 53 testNewStringFromChars()54 public static void testNewStringFromChars() { 55 char[] chars = { 'b', 'a', 'r' }; 56 String s = StringFactory.newStringFromChars(chars); 57 System.out.println(s); 58 } 59 60 /// CHECK-START: void Main.testNewStringFromString() builder (after) 61 /// CHECK-DAG: InvokeStaticOrDirect method_name:java.lang.StringFactory.newStringFromString intrinsic:StringNewStringFromString 62 testNewStringFromString()63 public static void testNewStringFromString() { 64 String s1 = "baz"; 65 String s2 = StringFactory.newStringFromString(s1); 66 System.out.println(s2); 67 } 68 main(String[] args)69 public static void main(String[] args) throws Exception { 70 testNewStringFromBytes(); 71 testNewStringFromChars(); 72 testNewStringFromString(); 73 } 74 } 75