1 /* 2 * Copyright 2020 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 import java.util.concurrent.*; 18 19 public class Main { Main()20 public Main() { 21 } 22 $noinline$f(Runnable r)23 void $noinline$f(Runnable r) throws Exception { 24 $noinline$g(r); 25 } 26 $noinline$g(Runnable r)27 void $noinline$g(Runnable r) { 28 $noinline$h(r); 29 } 30 $noinline$h(Runnable r)31 void $noinline$h(Runnable r) { 32 r.run(); 33 } 34 resetTest()35 public native void resetTest(); waitAndDeopt(Thread t)36 public native void waitAndDeopt(Thread t); doSelfStackWalk()37 public native void doSelfStackWalk(); 38 testConcurrent()39 void testConcurrent() throws Exception { 40 resetTest(); 41 final Thread current = Thread.currentThread(); 42 Thread t = new Thread(() -> { 43 try { 44 this.waitAndDeopt(current); 45 } catch (Exception e) { 46 throw new Error("Fail!", e); 47 } 48 }); 49 t.start(); 50 $noinline$f(() -> { 51 try { 52 this.doSelfStackWalk(); 53 } catch (Exception e) { 54 throw new Error("Fail!", e); 55 } 56 }); 57 t.join(); 58 } 59 main(String[] args)60 public static void main(String[] args) throws Exception { 61 System.loadLibrary(args[0]); 62 Main st = new Main(); 63 st.testConcurrent(); 64 System.out.println("Done"); 65 } 66 } 67