1 /*
2  * Copyright (C) 2018 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 {
$noinline$hotnessCount()18   public static void $noinline$hotnessCount() {
19   }
20 
$noinline$hotnessCountWithLoop(int count)21   public static void $noinline$hotnessCountWithLoop(int count) {
22     for (int i = 0; i < count; i++) {
23       $noinline$hotnessCount();
24     }
25   }
26 
main(String[] args)27   public static void main(String[] args) {
28     System.loadLibrary(args[0]);
29     if (!isAotCompiled(Main.class, "main")) {
30       return;
31     }
32     $noinline$hotnessCount();
33     int counter = getHotnessCounter(Main.class, "$noinline$hotnessCount");
34     if (counter == 0) {
35       throw new Error("Expected hotness counter to be updated");
36     }
37 
38     $noinline$hotnessCountWithLoop(1000);
39     int newCounter = getHotnessCounter(Main.class, "$noinline$hotnessCountWithLoop");
40     if (newCounter <= counter) {
41       throw new Error("Expected counter " + newCounter + " to be larger than " + counter);
42     }
43     counter = newCounter;
44 
45     $noinline$hotnessCountWithLoop(65500);
46     newCounter = getHotnessCounter(Main.class, "$noinline$hotnessCountWithLoop");
47     if (newCounter <= counter) {
48       throw new Error("Expected counter " + newCounter + " to be larger than " + counter);
49     }
50   }
51 
getHotnessCounter(Class<?> cls, String methodName)52   public static native int getHotnessCounter(Class<?> cls, String methodName);
isAotCompiled(Class<?> cls, String methodName)53   public static native boolean isAotCompiled(Class<?> cls, String methodName);
54 }
55