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 
     18 public class Main {
     19   public static int FIBCOUNT = 64;
     20   public static int[] fibs;
     21 
     22   /// CHECK-START-X86_64: int Main.test() disassembly (after)
     23   /// CHECK-DAG:   <<Zero:i\d+>>        IntConstant 0
     24   //
     25   /// CHECK:                            If
     26   /// CHECK-NEXT:                       cmp
     27   /// CHECK-NEXT:                       jle/ng
     28   //
     29   /// CHECK-DAG:   <<Fibs:l\d+>>        StaticFieldGet
     30   /// CHECK-DAG:                        NullCheck [<<Fibs>>]
     31   /// CHECK-NOT:                        jmp
     32   /// CHECK-DAG:   <<FibsAtZero:i\d+>>  ArrayGet [<<Fibs>>,<<Zero>>]
     33   /// CHECK-DAG:                        Return [<<FibsAtZero>>]
     34   //
     35   // Checks that there is no conditional jump over a `jmp`
     36   // instruction. The `ArrayGet` instruction is in the next block.
     37   //
     38   // Note that the `StaticFieldGet` HIR instruction above (captured as
     39   // `Fibs`) can produce a `jmp` x86-64 instruction when read barriers
     40   // are enabled (to jump into the read barrier slow path), which is
     41   // different from the `jmp` in the `CHECK-NOT` assertion.
     42   public static int test() {
     43     for (int i = 1; ; i++) {
     44       if (i >= FIBCOUNT) {
     45         return fibs[0];
     46       }
     47       fibs[i] = (i + fibs[(i - 1)]);
     48     }
     49   }
     50 
     51   public static void main(String[] args) {
     52     fibs = new int[FIBCOUNT];
     53     fibs[0] = 1;
     54     test();
     55   }
     56 }
     57