• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2011 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 package art;
18 
19 public class Test1919 {
20   public static final boolean PRINT_ALL_THREADS = false;
21 
run()22   public static void run() throws Exception {
23     Thread testing_thread = getTestingThread();
24     // TODO(b/124284724): For unknown reasons the testing thread will sometimes SEGV after the test
25     // has otherwise completed successfully. This has only been observed on the release version of
26     // art (libart.so) and I haven't had any luck reproing it. I assume it has something to do with
27     // racing between the DetachCurrentThread and shutdown but I'm not sure. Since the runtime
28     // normally never shuts down anyway for now I'll just ensure everything gets cleaned up early to
29     // prevent the problem from showing up.
30     testing_thread.join();
31     for (Event e : getEvents()) {
32       if (e.thr != null) {
33         if (PRINT_ALL_THREADS ||
34             e.thr.equals(Thread.currentThread()) ||
35             e.thr.equals(testing_thread)) {
36           System.out.println(e.name + ": " + e.thr.getName());
37         }
38       }
39     }
40   }
41 
42   static class Event {
43     public final String name;
44     public final Thread thr;
Event(String name, Thread thr)45     public Event(String name, Thread thr) {
46       this.name = name;
47       this.thr = thr;
48     }
49   }
50 
getEvents()51   public static Event[] getEvents() {
52     String[] ns = getEventNames();
53     Thread[] ts = getEventThreads();
54     Event[] es = new Event[Math.min(ns.length, ts.length)];
55     for (int i = 0; i < es.length; i++) {
56       es[i] = new Event(ns[i], ts[i]);
57     }
58     return es;
59   }
60 
getEventNames()61   public static native String[] getEventNames();
getEventThreads()62   public static native Thread[] getEventThreads();
63 
getTestingThread()64   public static native Thread getTestingThread();
65 }
66