Home | History | Annotate | Download | only in src
      1 /*
      2  * Copyright (C) 2015 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   public static void run() {
     20     // Loop enough to get JIT compilation.
     21     for (int i = 0; i < 10000; ++i) {
     22       doCall(new int[0]);
     23     }
     24   }
     25 
     26   public static void main(String[] args) throws Exception {
     27     run();
     28   }
     29 
     30   public static void doCall(int[] array) {
     31     try {
     32       deopt(array);
     33     } catch (IndexOutOfBoundsException ioobe) {
     34       // Expected
     35     }
     36   }
     37 
     38   public static void deopt(int[] array) {
     39     // Invoke `deopt` much more than `$inline$deopt` so that only `deopt` gets
     40     // initially JITted.
     41     if (call == 100) {
     42       call = 0;
     43       $inline$deopt(array);
     44     } else {
     45       call++;
     46     }
     47   }
     48 
     49   public static void $inline$deopt(int[] array) {
     50     array[0] = 1;
     51     array[1] = 1;
     52   }
     53 
     54   static int call = 0;
     55 }
     56