| 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 |
|
| 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 |
// After the inliner runs, we can see the inlined call and check |
| 44 |
// that the compiler intrinsifies it. |
| 45 |
|
| 46 |
/// CHECK-START: void Main.testNewStringFromChars() builder (after) |
| 47 |
/// CHECK-DAG: InvokeStaticOrDirect method_name:java.lang.StringFactory.newStringFromChars intrinsic:None |
| 48 |
|
| 49 |
/// CHECK-START: void Main.testNewStringFromChars() inliner (after) |
| 50 |
/// CHECK-DAG: InvokeStaticOrDirect method_name:java.lang.StringFactory.newStringFromChars intrinsic:StringNewStringFromChars |
| 51 |
|
| 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) |
| 59 |
/// 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 |
} |