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   public Main() {
     19   }
     20 
     21   static int testLiveArgument(int arg) {
     22     doStaticNativeCallLiveVreg();
     23     return arg;
     24   }
     25 
     26   static void moveArgToCalleeSave() {
     27     try {
     28       Thread.sleep(0);
     29     } catch (Exception e) {
     30       throw new Error(e);
     31     }
     32   }
     33 
     34   static void testIntervalHole(int arg, boolean test) {
     35     // Move the argument to callee save to ensure it is in
     36     // a readable register.
     37     moveArgToCalleeSave();
     38     if (test) {
     39       staticField1 = arg;
     40       // The environment use of `arg` should not make it live.
     41       doStaticNativeCallLiveVreg();
     42     } else {
     43       staticField2 = arg;
     44       // The environment use of `arg` should not make it live.
     45       doStaticNativeCallLiveVreg();
     46     }
     47   }
     48 
     49   static native void doStaticNativeCallLiveVreg();
     50 
     51   static {
     52     System.loadLibrary("arttest");
     53   }
     54 
     55   public static void main(String[] args) {
     56     if (testLiveArgument(42) != 42) {
     57       throw new Error("Expected 42");
     58     }
     59 
     60     if (testLiveArgument(42) != 42) {
     61       throw new Error("Expected 42");
     62     }
     63 
     64     testIntervalHole(1, true);
     65     testIntervalHole(1, false);
     66   }
     67 
     68   static int staticField1;
     69   static int staticField2;
     70 }
     71