blob: 53a7eea0131f1e9fcdc689d475c7b2c76f406986 [file] [log] [blame]
Nicolas Geoffraye91e7952020-01-23 10:15:56 +00001/*
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
17import java.util.concurrent.*;
18
19public 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 Alle2d4feeb2021-10-13 15:39:37 +000036 public native void waitAndInstrumentStack(Thread t);
Nicolas Geoffraye91e7952020-01-23 10:15:56 +000037 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 Alle2d4feeb2021-10-13 15:39:37 +000044 this.waitAndInstrumentStack(current);
Nicolas Geoffraye91e7952020-01-23 10:15:56 +000045 } 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}