/** * Constructor, initializes this value with its debug target and root object * * @param target The debug target associated with this value * @param root The root object that the elements in the array refer to. */ public JDIReferenceListValue(IJavaObject root) { super((JDIDebugTarget) root.getDebugTarget(), ((JDIObjectValue) root).getUnderlyingObject()); fRoot = root; try { IJavaType[] javaTypes = ((JDIDebugTarget) root.getDebugTarget()) .getJavaTypes("java.lang.Object[]"); // $NON-NLS-1$ if (javaTypes != null && javaTypes.length > 0) { fType = javaTypes[0]; } } catch (DebugException e) { } }
/** Re-enable garbage collection if interim results. */ private void releaseObjects() { if (fPermStorage != null) { Iterator<IJavaObject> iterator = fPermStorage.iterator(); while (iterator.hasNext()) { IJavaObject object = iterator.next(); try { object.enableCollection(); } catch (CoreException e) { // don't worry about GC if the VM has terminated if ((e.getStatus().getException() instanceof VMDisconnectedException)) { break; } JDIDebugPlugin.log(e); } } fPermStorage = null; } }
/** * Avoid garbage collecting interim results. * * @param value object to disable garbage collection for */ private void disableCollection(IJavaObject value) { if (fPermStorage == null) { fPermStorage = new ArrayList<IJavaObject>(5); } try { value.disableCollection(); fPermStorage.add(value); } catch (CoreException e) { JDIDebugPlugin.log(e); } }
/** @return all references to the root object as an array of IJavaObjects */ protected synchronized IJavaObject[] getReferences() { try { int max = HeapWalkingManager.getDefault().getAllReferencesMaxCount(); IJavaObject[] referringObjects = null; fIsMoreThanPreference = false; if (max == 0) { referringObjects = fRoot.getReferringObjects(max); } else { referringObjects = fRoot.getReferringObjects(max + 1); if (referringObjects.length > max) { fIsMoreThanPreference = true; referringObjects[max] = new JDIPlaceholderValue( (JDIDebugTarget) fRoot.getDebugTarget(), MessageFormat.format( JDIDebugModelMessages.JDIReferenceListValue_9, Integer.toString(max))); } } return referringObjects; } catch (DebugException e) { JDIDebugPlugin.log(e); return new IJavaObject[0]; } }
/** * Update the information for this thread. * * @return <code>true</code> if the contended monitor or the owned monitors changed. */ private boolean update() { boolean changed = false; synchronized (this) { if (!fToUpdate) { return false; } try { // update the contended monitor IJavaObject contendedMonitor = fThread.getContendedMonitor(); if (contendedMonitor == null) { changed = fContendedMonitor != null; fContendedMonitor = null; } else { changed = fContendedMonitor == null || !contendedMonitor.equals(fContendedMonitor.getMonitor()); fContendedMonitor = ThreadMonitorManager.getDefault().getJavaMonitor(contendedMonitor); } // update the owned monitors IJavaObject[] ownedMonitors = fThread.getOwnedMonitors(); if (ownedMonitors == null || ownedMonitors.length == 0) { // no owned monitor, not much to do changed = fOwnedMonitors != null && fOwnedMonitors.length != 0; fOwnedMonitors = new JavaMonitor[0]; } else { JavaMonitor[] tmp = new JavaMonitor[ownedMonitors.length]; ThreadMonitorManager threadMonitorManager = ThreadMonitorManager.getDefault(); if (changed || fOwnedMonitors.length != ownedMonitors.length) { // if we know it changed, we can just create the new list. for (int i = 0; i < ownedMonitors.length; i++) { tmp[i] = threadMonitorManager.getJavaMonitor(ownedMonitors[i]); } changed = true; } else { // we need to check in the new list contains the same monitors as the // previous list int sameMonitor = 0; for (int i = 0; i < ownedMonitors.length; i++) { for (int j = 0; j < fOwnedMonitors.length; j++) { if (ownedMonitors[i].equals(fOwnedMonitors[i].getMonitor())) { sameMonitor++; break; } } tmp[i] = threadMonitorManager.getJavaMonitor(ownedMonitors[i]); } changed = sameMonitor != ownedMonitors.length; } fOwnedMonitors = tmp; } } catch (DebugException e) { Throwable cause = e.getStatus().getException(); if (!(cause instanceof IncompatibleThreadStateException)) { // IncompatibleThreadStateException are expected from Sun VMs // if the thread is not suspended. // For all other exceptions, null the values. fContendedMonitor = null; changed = fOwnedMonitors != null && fOwnedMonitors.length != 0; fOwnedMonitors = new JavaMonitor[0]; } } finally { fToUpdate = false; } } if (changed) { fireChangeEvent(DebugEvent.CONTENT); } return changed; }
/* * (non-Javadoc) * * @see org.eclipse.jdt.internal.debug.core.model.JDIValue#hashCode() */ @Override public int hashCode() { return getClass().hashCode() + fRoot.hashCode(); }
/* * (non-Javadoc) * * @see org.eclipse.jdt.internal.debug.core.model.JDIValue#isAllocated() */ @Override public boolean isAllocated() throws DebugException { return fRoot.isAllocated(); }