private static String threadLockedSynchronizers(ThreadInfo threadInfo) { final String NO_SYNCH_INFO = "no locked synchronizers information available\n"; if (null == threadInfo) { return NO_SYNCH_INFO; } try { final LockInfo[] lockInfos = threadInfo.getLockedSynchronizers(); if (lockInfos.length > 0) { final StringBuffer lockedSynchBuff = new StringBuffer(); lockedSynchBuff.append("\nLocked Synchronizers: \n"); for (final LockInfo lockInfo : lockInfos) { lockedSynchBuff.append(lockInfo.getClassName()).append(" <").append(lockInfo.getIdentityHashCode()) .append("> \n"); } return lockedSynchBuff.append("\n").toString(); } else { return ""; } } catch (final Exception e) { return NO_SYNCH_INFO; } }
private void initData(Properties props) { this.db = new HashMap<String, Map<String, CRDTData<?>>>(); this.locks = new HashMap<CRDTIdentifier, LockInfo>(); // this.notifications = new LinkedList<NotificationRecord>(); this.modified = new HashSet<CRDTData<?>>(); this.version = ClockFactory.newClock(); this.cltClock = ClockFactory.newClock(); initDB(props); if (dbServer.ramOnly()) { CRDTIdentifier id = new CRDTIdentifier("e", "1"); ManagedCRDT<IntegerCRDT> i = new ManagedCRDT<IntegerCRDT>(id, new IntegerCRDT(id), version.clone(), true); localPutCRDT(i); CRDTIdentifier id2 = new CRDTIdentifier("e", "2"); ManagedCRDT<IntegerCRDT> i2 = new ManagedCRDT<IntegerCRDT>(id2, new IntegerCRDT(id2), version.clone(), true); localPutCRDT(i2); } }
private static void setLockInfo(TThreadDump threadDump, ThreadInfo threadInfo) { threadDump.setLockName(threadInfo.getLockName()); threadDump.setLockOwnerId(threadInfo.getLockOwnerId()); threadDump.setLockOwnerName(threadInfo.getLockOwnerName()); LockInfo[] lockInfos = threadInfo.getLockedSynchronizers(); if (lockInfos != null) { for (LockInfo lockInfo : lockInfos) { if (lockInfo == null) { continue; } threadDump.addToLockedSynchronizers(lockInfo.toString()); } } else { threadDump.setLockedSynchronizers(Collections.<String>emptyList()); } }
private @Nonnull JmxRuntime extractRuntime(@Nonnull MBeanServerConnection connection) { final List<ThreadInfo> threads = getRemoteThreads(connection); HashSet<JmxThread.Builder> builders = new HashSet<JmxThread.Builder>(threads.size()); for (ThreadInfo thread: threads) { JmxThread.Builder builder = new JmxThread.Builder(); final ThreadStatus status = fillThreadInfoData(thread, builder); final LockInfo lockInfo = thread.getLockInfo(); if (lockInfo != null) { builder.setWaitingToLock(getSynchronizer(lockInfo)); } builders.add(builder); } return new JmxRuntime(builders, new Date(), getVmName(connection)); }
@Override void outputWaitingInfo(ThreadInfo info, ExtraLockInfo exLockInfo, StringBuffer buffer) { final LockInfo lock_info = info.getLockInfo(); if (lock_info != null) { formatLock(lock_info, "waiting on", buffer); if (exLockInfo != null) { if (exLockInfo.isWaitingFor(ExtraLockInfo.WaitingFor.WRITE, lock_info)) buffer.append(" for write"); if (exLockInfo.isWaitingFor(ExtraLockInfo.WaitingFor.READ, lock_info)) buffer.append(" for read"); } buffer.append("."); long lock_owner = info.getLockOwnerId(); if (lock_owner!=-1) { buffer.append(" Locked by \""); buffer.append(info.getLockOwnerName()); buffer.append("\" tid="); buffer.append(lock_owner); } buffer.append("\n"); } }
private static void printLockInfo(LockInfo[] locks, StringBuilder sb) { sb.append("\tLocked synchronizers: count = " + locks.length).append("\n"); for (LockInfo li : locks) { sb.append("\t - " + li).append("\n"); } sb.append("\n"); }
private void printLockInfo(LockInfo[] locks, PrintStream out) { out.println(INDENT + "Locked synchronizers: count = " + locks.length); // NOI18N for (LockInfo li : locks) { out.println(INDENT + " - " + li); // NOI18N } out.println(); }
private static void printLockInfo(LockInfo[] locks, PrintWriter out) { out.println(INDENT + "Locked synchronizers: count = " + locks.length); for (LockInfo li : locks) { out.println(INDENT + " - " + li); } out.println(); }
/** * Prints the thread dump information with locks info to System.out. */ private void dumpThreadInfoWithLocks() { System.out.println("Full Java thread dump with locks info"); ThreadInfo[] tinfos = tmbean.dumpAllThreads(true, true); for (ThreadInfo ti : tinfos) { printThreadInfo(ti); LockInfo[] syncs = ti.getLockedSynchronizers(); printLockInfo(syncs); } System.out.println(); }
private void printLockInfo(LockInfo[] locks) { System.out.println(INDENT + "Locked synchronizers: count = " + locks.length); for (LockInfo li : locks) { System.out.println(INDENT + " - " + li); } System.out.println(); }
public static CompositeData toCompositeData(LockInfo li) { if (li == null) { return null; } LockInfoCompositeData licd = new LockInfoCompositeData(li); return licd.getCompositeData(); }
public static LockInfo toLockInfo(CompositeData cd) { if (cd == null) { throw new NullPointerException("Null CompositeData"); } if (!isTypeMatched(lockInfoCompositeType, cd.getCompositeType())) { throw new IllegalArgumentException( "Unexpected composite type for LockInfo"); } String className = getString(cd, CLASS_NAME); int identityHashCode = getInt(cd, IDENTITY_HASH_CODE); return new LockInfo(className, identityHashCode); }
Object toOpenTypeData(Object data) throws OpenDataException { if (data instanceof MemoryUsage) { return MemoryUsageCompositeData.toCompositeData((MemoryUsage) data); } if (data instanceof ThreadInfo) { return ThreadInfoCompositeData.toCompositeData((ThreadInfo) data); } if (data instanceof LockInfo) { if (data instanceof java.lang.management.MonitorInfo) { return MonitorInfoCompositeData.toCompositeData((MonitorInfo) data); } return LockInfoCompositeData.toCompositeData((LockInfo) data); } if (data instanceof MemoryNotificationInfo) { return MemoryNotifInfoCompositeData. toCompositeData((MemoryNotificationInfo) data); } if (data instanceof VMOption) { return VMOptionCompositeData.toCompositeData((VMOption) data); } if (isCompositeData) { // Classes that implement CompositeData // // construct a new CompositeDataSupport object // so that no other classes are sent over the wire CompositeData cd = (CompositeData) data; CompositeType ct = cd.getCompositeType(); String[] itemNames = ct.keySet().toArray(new String[0]); Object[] itemValues = cd.getAll(itemNames); return new CompositeDataSupport(ct, itemNames, itemValues); } throw new OpenDataException(javaClass.getName() + " is not supported for platform MXBeans"); }
public LockInfo[] lockedSynchronizers() { CompositeData[] lockedSyncsData = (CompositeData[]) cdata.get(LOCKED_SYNCS); // The LockedSynchronizers item cannot be null, but if it is we will // get a NullPointerException when we ask for its length. LockInfo[] locks = new LockInfo[lockedSyncsData.length]; for (int i = 0; i < lockedSyncsData.length; i++) { CompositeData cdi = lockedSyncsData[i]; locks[i] = LockInfo.from(cdi); } return locks; }
private String generateThreadStack(ThreadInfo info) { // This is annoying, but the to string method on info sucks. StringBuilder result = new StringBuilder(); result.append(info.getThreadName()).append(" ID=0x") .append(Long.toHexString(info.getThreadId())).append("(").append(info.getThreadId()) .append(") state=").append(info.getThreadState()); if (info.getLockInfo() != null) { result.append("\n\twaiting to lock <" + info.getLockInfo() + ">"); } for (StackTraceElement element : info.getStackTrace()) { result.append("\n\tat " + element); for (MonitorInfo monitor : info.getLockedMonitors()) { if (element.equals(monitor.getLockedStackFrame())) { result.append("\n\tlocked <" + monitor + ">"); } } } if (info.getLockedSynchronizers().length > 0) { result.append("\nLocked synchronizers:"); for (LockInfo sync : info.getLockedSynchronizers()) { result.append( "\n" + sync.getClassName() + "@" + Integer.toHexString(sync.getIdentityHashCode())); } } return result.toString(); }
public LocalLockInfo(Serializable locatility, LockInfo sync) { super(); this.locatility = locatility; // LockInfo and Monitor info aren't serializable, so copy the information from // them. For backwards compatibility, use the LI class which is used // in older versions of gemfire. if (sync instanceof MonitorInfo) { this.info = new LI(sync.getClassName(), sync.getIdentityHashCode(), ((MonitorInfo) sync).getLockedStackFrame()); } else { this.info = new LI(sync.getClassName(), sync.getIdentityHashCode()); } }
private static void checkLockInfo(LockInfo li) throws Exception { if (!li.getClassName().equals(lockInfo.getClassName())) { throw new RuntimeException("Class Name = " + li.getClassName() + " expected = " + lockInfo.getClassName()); } if (li.getIdentityHashCode() != lockInfo.getIdentityHashCode()) { throw new RuntimeException("Class Name = " + li.getIdentityHashCode() + " expected = " + lockInfo.getIdentityHashCode()); } }
/** * Formats the thread dump for one thread. * * @param ti * the ThreadInfo describing the thread * @return the formatted thread dump */ private static String getThreadDump(ThreadInfo ti) { StringBuilder sb = new StringBuilder(getThreadDumpHeader(ti)); for (LockInfo li : ti.getLockedSynchronizers()) { sb.append(INDENT2 + "locks " + li.toString() + CRLF); } boolean start = true; StackTraceElement[] stes = ti.getStackTrace(); Object[] monitorDepths = new Object[stes.length]; MonitorInfo[] mis = ti.getLockedMonitors(); for (int i = 0; i < mis.length; i++) { monitorDepths[mis[i].getLockedStackDepth()] = mis[i]; } for (int i = 0; i < stes.length; i++) { StackTraceElement ste = stes[i]; sb.append(INDENT2 + "at " + ste.toString() + CRLF); if (start) { if (ti.getLockName() != null) { sb.append(INDENT2 + "- waiting on (a " + ti.getLockName() + ")"); if (ti.getLockOwnerName() != null) { sb.append(" owned by " + ti.getLockOwnerName() + " Id=" + ti.getLockOwnerId()); } sb.append(CRLF); } start = false; } if (monitorDepths[i] != null) { MonitorInfo mi = (MonitorInfo) monitorDepths[i]; sb.append(INDENT2 + "- locked (a " + mi.toString() + ")" + " index " + mi.getLockedStackDepth() + " frame " + mi.getLockedStackFrame().toString()); sb.append(CRLF); } } return sb.toString(); }
public static CharSequence getThreadStats(boolean lockedMonitors, boolean lockedSynchronizers, boolean stackTrace) { StringBuilder list = new StringBuilder(); for(ThreadInfo info : threadMXbean.dumpAllThreads(lockedMonitors, lockedSynchronizers)) { list.append("Thread #").append(info.getThreadId()).append(" (").append(info.getThreadName()).append(")").append("\n"); list.append("=================================================\n"); list.append("\tgetThreadState: ...... ").append(info.getThreadState()).append("\n"); for(MonitorInfo monitorInfo : info.getLockedMonitors()) { list.append("\tLocked monitor: ....... ").append(monitorInfo).append("\n"); list.append("\t\t[").append(monitorInfo.getLockedStackDepth()).append(".]: at ").append(monitorInfo.getLockedStackFrame()).append("\n"); } for(LockInfo lockInfo : info.getLockedSynchronizers()) list.append("\tLocked synchronizer: ...").append(lockInfo).append("\n"); if(stackTrace) { list.append("\tgetStackTace: ..........\n"); for(StackTraceElement trace : info.getStackTrace()) list.append("\t\tat ").append(trace).append("\n"); } list.append("=================================================\n"); } return list; }
@Override public LI[] getLockedSynchronizers(ThreadInfo info) { LockInfo[] monitors = info.getLockedSynchronizers(); if(monitors == null) { return null; } LI[] results = new LI[monitors.length]; for(int i = 0; i < monitors.length; i++) { results[i] = new LI(monitors[i].getClassName(), monitors[i].getIdentityHashCode()); } return results; }
@Override public LI getLockInfo(ThreadInfo threadInfo) { LockInfo lockInfo= threadInfo.getLockInfo(); if(lockInfo == null) { return null; } return new LI(lockInfo.getClassName(), lockInfo.getIdentityHashCode()); }