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     int counter = getHotnessCounter(Main.class, "$noinline$hotnessCount");
33     $noinline$hotnessCount();
34     int newCounter = getHotnessCounter(Main.class, "$noinline$hotnessCount");
35     if (counter == newCounter) {
36       throw new Error("Expected hotness counter to be updated");
37     }
38 
39     counter = getHotnessCounter(Main.class, "$noinline$hotnessCountWithLoop");
40     $noinline$hotnessCountWithLoop(1000);
41     newCounter = getHotnessCounter(Main.class, "$noinline$hotnessCountWithLoop");
42     if (newCounter == counter) {
43       throw new Error("Expected counter " + newCounter + " to be different than " + counter);
44     }
45     counter = newCounter;
46 
47     $noinline$hotnessCountWithLoop(65500);
48     newCounter = getHotnessCounter(Main.class, "$noinline$hotnessCountWithLoop");
49     if (newCounter == counter) {
50       throw new Error("Expected counter " + newCounter + " to be different than " + counter);
51     }
52   }
53 
getHotnessCounter(Class<?> cls, String methodName)54   public static native int getHotnessCounter(Class<?> cls, String methodName);
isAotCompiled(Class<?> cls, String methodName)55   public static native boolean isAotCompiled(Class<?> cls, String methodName);
56 }
57