1 /* 2 * Copyright (C) 2022 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 static class Inner { 19 // Use a <clinit> method to ensure we execute in the 20 // interpreter. 21 static { Main.callMethodThatThrows()22 Main.callMethodThatThrows(); 23 } 24 } 25 main(String[] args)26 public static void main(String[] args) throws Exception { 27 System.loadLibrary(args[0]); 28 // Disables use of nterp. 29 Main.setAsyncExceptionsThrown(); 30 31 Thread.currentThread().setUncaughtExceptionHandler((th, e) -> { 32 System.out.println("Caught exception"); 33 // Exit the test gracefully. 34 System.exit(0); 35 }); 36 // This will throw at `callMethodThatThrows` and trigger deoptimization checks which we used 37 // to crash on. 38 new Inner(); 39 } 40 callMethodThatThrows()41 public static void callMethodThatThrows() { 42 // Ensures we get deoptimization requests. 43 Main.forceInterpreterOnThread(); 44 throw new Error(""); 45 } 46 forceInterpreterOnThread()47 public static native void forceInterpreterOnThread(); setAsyncExceptionsThrown()48 public static native void setAsyncExceptionsThrown(); 49 50 } 51