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()21   public static void $noinline$hotnessCountWithLoop() {
22     for (int i = 0; i < 100; 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();
39     if (getHotnessCounter(Main.class, "$noinline$hotnessCountWithLoop") <= counter) {
40       throw new Error("Expected hotness counter of a loop to be greater than without loop");
41     }
42   }
43 
getHotnessCounter(Class<?> cls, String methodName)44   public static native int getHotnessCounter(Class<?> cls, String methodName);
isAotCompiled(Class<?> cls, String methodName)45   public static native boolean isAotCompiled(Class<?> cls, String methodName);
46 }
47