1/* 2 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23package utils; 24 25import java.util.Iterator; 26import java.util.LinkedList; 27 28/** 29 * 30 * Represents the stack of the thread 31 * 32 */ 33public class ThreadStack { 34 35 private String threadType; // Thread / RealtimeThread / NoHeapRealtimeThread 36 private String threadName; 37 private String type; //daemon or not 38 private String priority; 39 private String tid; 40 private String nid; 41 42 /** 43 * runnable or waiting on condition 44 */ 45 private String status; 46 private String pointerRange; 47 48 /** 49 * i.e. java.lang.Thread.State: WAITING (on object monitor) 50 */ 51 private String extendedStatus; 52 53 private LinkedList<MethodInfo> stack = new LinkedList<MethodInfo>(); 54 55 private LinkedList<LockInfo> lockOSList = new LinkedList<LockInfo>(); 56 57 public String getThreadName() { 58 return threadName; 59 } 60 61 public void setThreadName(String threadName) { 62 this.threadName = threadName; 63 } 64 65 public String getType() { 66 return type; 67 } 68 69 public void setType(String type) { 70 this.type = type; 71 } 72 73 public String getPriority() { 74 return priority; 75 } 76 77 public void setPriority(String priority) { 78 this.priority = priority; 79 } 80 81 public String getTid() { 82 return tid; 83 } 84 85 public void setTid(String tid) { 86 this.tid = tid; 87 } 88 89 public String getNid() { 90 return nid; 91 } 92 93 public void setNid(String nid) { 94 this.nid = nid; 95 } 96 97 public String getStatus() { 98 return status; 99 } 100 101 public void setStatus(String status) { 102 this.status = status; 103 } 104 105 public String getPointerRange() { 106 return pointerRange; 107 } 108 109 public void setPointerRange(String pointerRange) { 110 this.pointerRange = pointerRange; 111 } 112 113 public String getExtendedStatus() { 114 return extendedStatus; 115 } 116 117 public void setExtendedStatus(String extendedStatus) { 118 this.extendedStatus = extendedStatus; 119 } 120 121 public LinkedList<MethodInfo> getStack() { 122 return stack; 123 } 124 125 public LinkedList<LockInfo> getLockOSList() { 126 return lockOSList; 127 } 128 129 public void setLockOSList(LinkedList<LockInfo> lockOSList) { 130 this.lockOSList = lockOSList; 131 } 132 133 public void addMethod(MethodInfo mi) { 134 stack.add(mi); 135 } 136 137 public boolean hasEqualStack(ThreadStack another) { 138 boolean result = true; 139 140 Iterator<MethodInfo> it1 = stack.iterator(); 141 Iterator<MethodInfo> it2 = another.stack.iterator(); 142 143 while (it1.hasNext() && it2.hasNext()) { 144 145 MethodInfo mi1 = it1.next(); 146 MethodInfo mi2 = it2.next(); 147 148 if (mi1 == null && mi2 == null) { 149 break; 150 } 151 152 boolean oneOfMethodInfoIsNull = mi1 == null && mi2 != null || mi1 != null && mi2 == null; 153 154 if (oneOfMethodInfoIsNull || !mi1.equals(mi2)) { 155 result = false; 156 } 157 } 158 159 if (it1.hasNext() || it2.hasNext()) { 160 Utils.log("stack sizes", String.valueOf(stack.size()), String.valueOf(another.stack.size())); 161 result = false; 162 } 163 164 return result; 165 } 166 167 public String getThreadType() { 168 return threadType; 169 } 170 171 public void setThreadType(String threadType) { 172 this.threadType = threadType; 173 } 174 175} 176