1 /* 2 * Copyright (C) 2017 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 dalvik.system; 18 19 import static android.annotation.SystemApi.Client.MODULE_LIBRARIES; 20 21 import android.annotation.SystemApi; 22 import libcore.util.NonNull; 23 import libcore.util.Nullable; 24 25 /** 26 * A class encapsulating a StackTraceElement and lock state. This adds 27 * critical thread state to the standard stack trace information, which 28 * can be used to detect deadlocks at the Java level. 29 * 30 * @hide 31 */ 32 @SystemApi(client = MODULE_LIBRARIES) 33 public final class AnnotatedStackTraceElement { 34 /** 35 * The traditional StackTraceElement describing the Java stack frame. 36 */ 37 private StackTraceElement stackTraceElement; 38 39 /** 40 * An array containing objects that are locked in this frame. May be null. 41 */ 42 private Object[] heldLocks; 43 44 /** 45 * If this frame denotes the top of stack, {@code blockedOn} will hold 46 * the object this thread is waiting to lock, or waiting on, if any. May be 47 * null. 48 */ 49 private Object blockedOn; 50 51 // Internal allocation, only. AnnotatedStackTraceElement()52 private AnnotatedStackTraceElement() { 53 } 54 55 /** 56 * Returns the {@link StackTraceElement} describing the Java stack frame. 57 * 58 * @return {@link StackTraceElement} describing the Java stack frame. 59 * 60 * @hide 61 */ 62 @SystemApi(client = MODULE_LIBRARIES) getStackTraceElement()63 @NonNull public StackTraceElement getStackTraceElement() { 64 return stackTraceElement; 65 } 66 67 /** 68 * Returns the objects this stack frame is synchronized on. 69 * May be {@code null}. 70 * 71 * @return array of objects current frame is syncronized on. 72 * 73 * @hide 74 */ 75 @SystemApi(client = MODULE_LIBRARIES) getHeldLocks()76 @Nullable public Object[] getHeldLocks() { 77 return heldLocks; 78 } 79 80 /** 81 * Returns the object this stack frame is waiting on for synchronization. 82 * May be {@code null}. 83 * 84 * @return object this thread is waiting to lock, or waiting on, if any, 85 * or {@code null}, if none. 86 * 87 * @hide 88 */ 89 @SystemApi(client = MODULE_LIBRARIES) getBlockedOn()90 @Nullable public Object getBlockedOn() { 91 return blockedOn; 92 } 93 } 94