• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 {
Main()18   public Main() {
19   }
20 
testLiveArgument(int arg)21   static int testLiveArgument(int arg) {
22     doStaticNativeCallLiveVreg();
23     return arg;
24   }
25 
moveArgToCalleeSave()26   static void moveArgToCalleeSave() {
27     try {
28       Thread.sleep(0);
29     } catch (Exception e) {
30       throw new Error(e);
31     }
32   }
33 
$opt$noinline$testIntervalHole(int arg, boolean test)34   static void $opt$noinline$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     if (staticField1 == 2) {
48       throw new Error("");
49     }
50   }
51 
doStaticNativeCallLiveVreg()52   static native void doStaticNativeCallLiveVreg();
53 
main(String[] args)54   public static void main(String[] args) {
55     System.loadLibrary(args[0]);
56     if (testLiveArgument(staticField3) != staticField3) {
57       throw new Error("Expected " + staticField3);
58     }
59 
60     if (testLiveArgument(staticField3) != staticField3) {
61       throw new Error("Expected " + staticField3);
62     }
63 
64     testWrapperIntervalHole(1, true);
65     testWrapperIntervalHole(1, false);
66   }
67 
68   // Wrapper method to avoid inlining, which affects liveness
69   // of dex registers.
testWrapperIntervalHole(int arg, boolean test)70   static void testWrapperIntervalHole(int arg, boolean test) {
71     try {
72       Thread.sleep(0);
73       $opt$noinline$testIntervalHole(arg, test);
74     } catch (Exception e) {
75       throw new Error(e);
76     }
77   }
78 
79   static int staticField1;
80   static int staticField2;
81   static int staticField3 = 42;
82 }
83