Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 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 | // Note that $opt$ is a marker for the optimizing compiler to ensure |
| 18 | // it does compile the method. |
| 19 | |
| 20 | public class Main { |
| 21 | public static void main(String[] args) { |
| 22 | Error error = null; |
| 23 | try { |
| 24 | $opt$TestInvokeStatic(); |
| 25 | } catch (Error e) { |
| 26 | error = e; |
| 27 | } |
| 28 | System.out.println(error); |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame^] | 29 | |
| 30 | $opt$TestInvokeNew(); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 31 | } |
| 32 | |
| 33 | public static void $opt$TestInvokeStatic() { |
| 34 | printStaticMethod(); |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 35 | printStaticMethodWith2Args(1, 2); |
| 36 | printStaticMethodWith5Args(1, 2, 3, 4, 5); |
| 37 | printStaticMethodWith7Args(1, 2, 3, 4, 5, 6, 7); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 38 | forceGCStaticMethod(); |
| 39 | throwStaticMethod(); |
| 40 | } |
| 41 | |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame^] | 42 | public static void $opt$TestInvokeNew() { |
| 43 | Object o = new Object(); |
| 44 | forceGCStaticMethod(); |
| 45 | printStaticMethodWithObjectArg(o); |
| 46 | forceGCStaticMethod(); |
| 47 | } |
| 48 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 49 | public static void printStaticMethod() { |
| 50 | System.out.println("In static method"); |
| 51 | } |
| 52 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 53 | public static void printStaticMethodWith2Args(int a, int b) { |
| 54 | System.out.println("In static method with 2 args " + a + " " + b); |
| 55 | } |
| 56 | |
| 57 | public static void printStaticMethodWith5Args(int a, int b, int c, int d, int e) { |
| 58 | System.out.println("In static method with 5 args " |
| 59 | + a + " " + b + " " + c + " " + d + " " + e); |
| 60 | } |
| 61 | |
| 62 | public static void printStaticMethodWith7Args(int a, int b, int c, int d, int e, int f, int g) { |
| 63 | System.out.println("In static method with 7 args " |
| 64 | + a + " " + b + " " + c + " " + d + " " + e + " " + f + " " + g); |
| 65 | } |
| 66 | |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame^] | 67 | public static void printStaticMethodWithObjectArg(Object a) { |
| 68 | System.out.println("In static method with object arg " + a.getClass()); |
| 69 | } |
| 70 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 71 | public static void forceGCStaticMethod() { |
| 72 | Runtime.getRuntime().gc(); |
| 73 | Runtime.getRuntime().gc(); |
| 74 | Runtime.getRuntime().gc(); |
| 75 | Runtime.getRuntime().gc(); |
| 76 | Runtime.getRuntime().gc(); |
| 77 | Runtime.getRuntime().gc(); |
| 78 | System.out.println("Forced GC"); |
| 79 | } |
| 80 | |
| 81 | public static void throwStaticMethod() { |
| 82 | throw new Error("Error"); |
| 83 | } |
| 84 | } |