1d8126bef62df7f40f2e6abc74004f52e664daf45Nicolas Geoffray/*
2d8126bef62df7f40f2e6abc74004f52e664daf45Nicolas Geoffray * Copyright (C) 2015 The Android Open Source Project
3d8126bef62df7f40f2e6abc74004f52e664daf45Nicolas Geoffray *
4d8126bef62df7f40f2e6abc74004f52e664daf45Nicolas Geoffray * Licensed under the Apache License, Version 2.0 (the "License");
5d8126bef62df7f40f2e6abc74004f52e664daf45Nicolas Geoffray * you may not use this file except in compliance with the License.
6d8126bef62df7f40f2e6abc74004f52e664daf45Nicolas Geoffray * You may obtain a copy of the License at
7d8126bef62df7f40f2e6abc74004f52e664daf45Nicolas Geoffray *
8d8126bef62df7f40f2e6abc74004f52e664daf45Nicolas Geoffray *      http://www.apache.org/licenses/LICENSE-2.0
9d8126bef62df7f40f2e6abc74004f52e664daf45Nicolas Geoffray *
10d8126bef62df7f40f2e6abc74004f52e664daf45Nicolas Geoffray * Unless required by applicable law or agreed to in writing, software
11d8126bef62df7f40f2e6abc74004f52e664daf45Nicolas Geoffray * distributed under the License is distributed on an "AS IS" BASIS,
12d8126bef62df7f40f2e6abc74004f52e664daf45Nicolas Geoffray * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13d8126bef62df7f40f2e6abc74004f52e664daf45Nicolas Geoffray * See the License for the specific language governing permissions and
14d8126bef62df7f40f2e6abc74004f52e664daf45Nicolas Geoffray * limitations under the License.
15d8126bef62df7f40f2e6abc74004f52e664daf45Nicolas Geoffray */
16d8126bef62df7f40f2e6abc74004f52e664daf45Nicolas Geoffray
17d8126bef62df7f40f2e6abc74004f52e664daf45Nicolas Geoffraypublic class Main {
18d8126bef62df7f40f2e6abc74004f52e664daf45Nicolas Geoffray  public Main() {
19d8126bef62df7f40f2e6abc74004f52e664daf45Nicolas Geoffray  }
20d8126bef62df7f40f2e6abc74004f52e664daf45Nicolas Geoffray
21d8126bef62df7f40f2e6abc74004f52e664daf45Nicolas Geoffray  static int testLiveArgument(int arg) {
22d8126bef62df7f40f2e6abc74004f52e664daf45Nicolas Geoffray    doStaticNativeCallLiveVreg();
23d8126bef62df7f40f2e6abc74004f52e664daf45Nicolas Geoffray    return arg;
24d8126bef62df7f40f2e6abc74004f52e664daf45Nicolas Geoffray  }
25d8126bef62df7f40f2e6abc74004f52e664daf45Nicolas Geoffray
26d8126bef62df7f40f2e6abc74004f52e664daf45Nicolas Geoffray  static void moveArgToCalleeSave() {
27d8126bef62df7f40f2e6abc74004f52e664daf45Nicolas Geoffray    try {
28d8126bef62df7f40f2e6abc74004f52e664daf45Nicolas Geoffray      Thread.sleep(0);
29d8126bef62df7f40f2e6abc74004f52e664daf45Nicolas Geoffray    } catch (Exception e) {
30d8126bef62df7f40f2e6abc74004f52e664daf45Nicolas Geoffray      throw new Error(e);
31d8126bef62df7f40f2e6abc74004f52e664daf45Nicolas Geoffray    }
32d8126bef62df7f40f2e6abc74004f52e664daf45Nicolas Geoffray  }
33d8126bef62df7f40f2e6abc74004f52e664daf45Nicolas Geoffray
34d8126bef62df7f40f2e6abc74004f52e664daf45Nicolas Geoffray  static void testIntervalHole(int arg, boolean test) {
35d8126bef62df7f40f2e6abc74004f52e664daf45Nicolas Geoffray    // Move the argument to callee save to ensure it is in
36d8126bef62df7f40f2e6abc74004f52e664daf45Nicolas Geoffray    // a readable register.
37d8126bef62df7f40f2e6abc74004f52e664daf45Nicolas Geoffray    moveArgToCalleeSave();
38d8126bef62df7f40f2e6abc74004f52e664daf45Nicolas Geoffray    if (test) {
39d8126bef62df7f40f2e6abc74004f52e664daf45Nicolas Geoffray      staticField1 = arg;
40d8126bef62df7f40f2e6abc74004f52e664daf45Nicolas Geoffray      // The environment use of `arg` should not make it live.
41d8126bef62df7f40f2e6abc74004f52e664daf45Nicolas Geoffray      doStaticNativeCallLiveVreg();
42d8126bef62df7f40f2e6abc74004f52e664daf45Nicolas Geoffray    } else {
43d8126bef62df7f40f2e6abc74004f52e664daf45Nicolas Geoffray      staticField2 = arg;
44d8126bef62df7f40f2e6abc74004f52e664daf45Nicolas Geoffray      // The environment use of `arg` should not make it live.
45d8126bef62df7f40f2e6abc74004f52e664daf45Nicolas Geoffray      doStaticNativeCallLiveVreg();
46d8126bef62df7f40f2e6abc74004f52e664daf45Nicolas Geoffray    }
47d8126bef62df7f40f2e6abc74004f52e664daf45Nicolas Geoffray  }
48d8126bef62df7f40f2e6abc74004f52e664daf45Nicolas Geoffray
49d8126bef62df7f40f2e6abc74004f52e664daf45Nicolas Geoffray  static native void doStaticNativeCallLiveVreg();
50d8126bef62df7f40f2e6abc74004f52e664daf45Nicolas Geoffray
51d8126bef62df7f40f2e6abc74004f52e664daf45Nicolas Geoffray  static {
52d8126bef62df7f40f2e6abc74004f52e664daf45Nicolas Geoffray    System.loadLibrary("arttest");
53d8126bef62df7f40f2e6abc74004f52e664daf45Nicolas Geoffray  }
54d8126bef62df7f40f2e6abc74004f52e664daf45Nicolas Geoffray
55d8126bef62df7f40f2e6abc74004f52e664daf45Nicolas Geoffray  public static void main(String[] args) {
56d8126bef62df7f40f2e6abc74004f52e664daf45Nicolas Geoffray    if (testLiveArgument(42) != 42) {
57d8126bef62df7f40f2e6abc74004f52e664daf45Nicolas Geoffray      throw new Error("Expected 42");
58d8126bef62df7f40f2e6abc74004f52e664daf45Nicolas Geoffray    }
59d8126bef62df7f40f2e6abc74004f52e664daf45Nicolas Geoffray
60d8126bef62df7f40f2e6abc74004f52e664daf45Nicolas Geoffray    if (testLiveArgument(42) != 42) {
61d8126bef62df7f40f2e6abc74004f52e664daf45Nicolas Geoffray      throw new Error("Expected 42");
62d8126bef62df7f40f2e6abc74004f52e664daf45Nicolas Geoffray    }
63d8126bef62df7f40f2e6abc74004f52e664daf45Nicolas Geoffray
64d8126bef62df7f40f2e6abc74004f52e664daf45Nicolas Geoffray    testIntervalHole(1, true);
65d8126bef62df7f40f2e6abc74004f52e664daf45Nicolas Geoffray    testIntervalHole(1, false);
66d8126bef62df7f40f2e6abc74004f52e664daf45Nicolas Geoffray  }
67d8126bef62df7f40f2e6abc74004f52e664daf45Nicolas Geoffray
68d8126bef62df7f40f2e6abc74004f52e664daf45Nicolas Geoffray  static int staticField1;
69d8126bef62df7f40f2e6abc74004f52e664daf45Nicolas Geoffray  static int staticField2;
70d8126bef62df7f40f2e6abc74004f52e664daf45Nicolas Geoffray}
71