| Nicolas Geoffray | e91e795 | 2020-01-23 10:15:56 +0000 | [diff] [blame] | 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 { |
| 20 | public Main() { |
| 21 | } |
| 22 | |
| 23 | void $noinline$f(Runnable r) throws Exception { |
| 24 | $noinline$g(r); |
| 25 | } |
| 26 | |
| 27 | void $noinline$g(Runnable r) { |
| 28 | $noinline$h(r); |
| 29 | } |
| 30 | |
| 31 | void $noinline$h(Runnable r) { |
| 32 | r.run(); |
| 33 | } |
| 34 | |
| 35 | public native void resetTest(); |
| Mythri Alle | 2d4feeb | 2021-10-13 15:39:37 +0000 | [diff] [blame^] | 36 | public native void waitAndInstrumentStack(Thread t); |
| Nicolas Geoffray | e91e795 | 2020-01-23 10:15:56 +0000 | [diff] [blame] | 37 | public native void doSelfStackWalk(); |
| 38 | |
| 39 | void testConcurrent() throws Exception { |
| 40 | resetTest(); |
| 41 | final Thread current = Thread.currentThread(); |
| 42 | Thread t = new Thread(() -> { |
| 43 | try { |
| Mythri Alle | 2d4feeb | 2021-10-13 15:39:37 +0000 | [diff] [blame^] | 44 | this.waitAndInstrumentStack(current); |
| Nicolas Geoffray | e91e795 | 2020-01-23 10:15:56 +0000 | [diff] [blame] | 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 | |
| 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 | } |