• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017 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: char Main.$noinline$inlineMonomorphic(java.lang.CharSequence) inliner (before)
20   /// CHECK:       InvokeInterface method_name:java.lang.CharSequence.charAt
21 
22   /// CHECK-START: char Main.$noinline$inlineMonomorphic(java.lang.CharSequence) inliner (after)
23   /// CHECK:       Deoptimize
24   /// CHECK:       InvokeVirtual method_name:java.lang.String.charAt intrinsic:StringCharAt
25 
26   /// CHECK-START: char Main.$noinline$inlineMonomorphic(java.lang.CharSequence) instruction_simplifier$after_inlining (after)
27   /// CHECK:       Deoptimize
28   /// CHECK-NOT:   InvokeInterface
29   /// CHECK-NOT:   InvokeVirtual
30 
$noinline$inlineMonomorphic(CharSequence cs)31   public static char $noinline$inlineMonomorphic(CharSequence cs) {
32     return cs.charAt(0);
33   }
34 
35   /// CHECK-START: char Main.$noinline$knownReceiverType() inliner (before)
36   /// CHECK:       InvokeInterface method_name:java.lang.CharSequence.charAt
37 
38   /// CHECK-START: char Main.$noinline$knownReceiverType() inliner (after)
39   /// CHECK:       InvokeVirtual method_name:java.lang.String.charAt intrinsic:StringCharAt
40 
41   /// CHECK-START: char Main.$noinline$knownReceiverType() instruction_simplifier$after_inlining (after)
42   /// CHECK-NOT:   InvokeInterface
43   /// CHECK-NOT:   InvokeVirtual
44 
$noinline$knownReceiverType()45   public static char $noinline$knownReceiverType() {
46     CharSequence cs = "abc";
47     return cs.charAt(1);
48   }
49 
50   /// CHECK-START: boolean Main.$noinline$stringEquals(java.lang.Object) inliner (before)
51   /// CHECK:       InvokeVirtual method_name:java.lang.Object.equals intrinsic:None
52 
53   /// CHECK-START: boolean Main.$noinline$stringEquals(java.lang.Object) inliner (after)
54   /// CHECK:       Deoptimize
55   /// CHECK:       InvokeVirtual method_name:java.lang.String.equals intrinsic:StringEquals
56 
57   /// CHECK-START: boolean Main.$noinline$stringEquals(java.lang.Object) instruction_simplifier$after_inlining (after)
58   /// CHECK:       Deoptimize
59   /// CHECK:       InvokeVirtual method_name:java.lang.String.equals intrinsic:StringEquals
60 
$noinline$stringEquals(Object obj)61   public static boolean $noinline$stringEquals(Object obj) {
62     return obj.equals("def");
63   }
64 
test()65   public static void test() {
66     // Warm up inline cache.
67     for (int i = 0; i < 45; i++) {
68       $noinline$inlineMonomorphic(str);
69     }
70     for (int i = 0; i < 60; i++) {
71       $noinline$stringEquals(str);
72     }
73     ensureJitCompiled(Main.class, "$noinline$stringEquals");
74     ensureJitCompiled(Main.class, "$noinline$inlineMonomorphic");
75     ensureJitCompiled(Main.class, "$noinline$knownReceiverType");
76     if ($noinline$inlineMonomorphic(str) != 'x') {
77       throw new Error("Expected x");
78     }
79     if ($noinline$knownReceiverType() != 'b') {
80       throw new Error("Expected b");
81     }
82     if ($noinline$stringEquals("abc")) {
83       throw new Error("Expected false");
84     }
85   }
86 
main(String[] args)87   public static void main(String[] args) {
88     System.loadLibrary(args[0]);
89     test();
90   }
91 
92   static String str = "xyz";
93 
ensureJitCompiled(Class<?> itf, String method_name)94   private static native void ensureJitCompiled(Class<?> itf, String method_name);
95 }
96