public void notifySuspendAllNoFire(Set<ThreadReference> ignoredThreads, ThreadReference eventThread) { Collection threads = threadsTranslation.getTranslated(); for (Iterator it = threads.iterator(); it.hasNext(); ) { Object threadOrGroup = it.next(); if (threadOrGroup instanceof JPDAThreadImpl) { JPDAThreadImpl thread = (JPDAThreadImpl) threadOrGroup; ThreadReference tr = thread.getThreadReference(); if (ignoredThreads == null || !ignoredThreads.contains(tr)) { int status = thread.getState(); boolean invalid = (status == JPDAThread.STATE_NOT_STARTED || status == JPDAThread.STATE_UNKNOWN || status == JPDAThread.STATE_ZOMBIE); if (!invalid) { try { thread.notifySuspendedNoFire(tr == eventThread, false); } catch (ObjectCollectedException ocex) { invalid = true; } } else if (status == JPDAThread.STATE_UNKNOWN || status == JPDAThread.STATE_ZOMBIE) { threadsTranslation.remove(tr); } } } } }
private void initGroups(ThreadGroupReference group) { try { List<ThreadGroupReference> groups = new ArrayList(ThreadGroupReferenceWrapper.threadGroups0(group)); List<ThreadReference> threads = new ArrayList(ThreadGroupReferenceWrapper.threads0(group)); filterThreads(threads); groupMap.put(group, groups); threadMap.put(group, threads); for (ThreadGroupReference g : groups) { initGroups(g); } } catch (ObjectCollectedException e) { } }
private static StringReference createStringMirrorWithDisabledCollection(String s, VirtualMachine vm, EvaluationContext evaluationContext) { StringReference sr; do { try { sr = vm.mirrorOf(s); } catch (UnsupportedOperationException e) { Assert.error(null, "unsupportedStringCreation"); return null; } try { evaluationContext.disableCollectionOf(sr); } catch (ObjectCollectedException oce) { sr = null; // Already collected! Create a new value and try again... } } while (sr == null); return sr; }
/** * Recycle the related ids owned by the specified thread. */ public static void checkThreadRunningAndRecycleIds(ThreadReference thread, IDebugAdapterContext context) { try { IEvaluationProvider engine = context.getProvider(IEvaluationProvider.class); engine.clearState(thread); boolean allThreadsRunning = !DebugUtility.getAllThreadsSafely(context.getDebugSession()).stream() .anyMatch(ThreadReference::isSuspended); if (allThreadsRunning) { context.getRecyclableIdPool().removeAllObjects(); } else { context.getRecyclableIdPool().removeObjectsByOwner(thread.uniqueID()); } } catch (VMDisconnectedException ex) { // isSuspended may throw VMDisconnectedException when the VM terminates context.getRecyclableIdPool().removeAllObjects(); } catch (ObjectCollectedException collectedEx) { // isSuspended may throw ObjectCollectedException when the thread terminates context.getRecyclableIdPool().removeObjectsByOwner(thread.uniqueID()); } }
/** * Resume the thread the times as it has been suspended. * * @param thread * the thread reference */ public static void resumeThread(ThreadReference thread) { // if thread is not found or is garbage collected, do nothing if (thread == null || thread.isCollected()) { return; } try { int suspends = thread.suspendCount(); for (int i = 0; i < suspends; i++) { /** * Invoking this method will decrement the count of pending suspends on this thread. * If it is decremented to 0, the thread will continue to execute. */ thread.resume(); } } catch (ObjectCollectedException ex) { // ObjectCollectionException can be thrown if the thread has already completed (exited) in the VM when calling suspendCount, // the resume operation to this thread is meanness. } }
@Override public boolean isSuspended(ThreadReferenceProxyImpl thread) throws ObjectCollectedException{ DebuggerManagerThreadImpl.assertIsManagerThread(); boolean suspended = false; if (isFrozen(thread)) { suspended = true; } else { for (SuspendContextImpl suspendContext : myEventContexts) { if (suspendContext.suspends(thread)) { suspended = true; break; } } } //bug in JDI : newly created thread may be resumed even when suspendPolicy == SUSPEND_ALL //if(LOG.isDebugEnabled() && suspended) { // LOG.assertTrue(thread.suspends(), thread.name()); //} return suspended && (thread == null || thread.isSuspended()); }
private void updateRequestState(final boolean enabled, @Nullable final ThreadReference thread) { try { final MethodExitRequest request = myRequest; if (request != null) { myRequest = null; myRequestManager.deleteEventRequest(request); } if (enabled) { myLastExecutedMethod = null; myLastMethodReturnValue = null; myRequest = createRequest(thread); myRequest.enable(); } } catch (ObjectCollectedException ignored) { } }
protected String calcRepresentation(EvaluationContextImpl context, DescriptorLabelListener labelListener) throws EvaluateException { DebuggerManagerThreadImpl.assertIsManagerThread(); ThreadReferenceProxyImpl thread = getThreadReference(); try { myName = thread.name(); ThreadGroupReferenceProxyImpl gr = getThreadReference().threadGroupProxy(); final String grname = (gr != null)? gr.name() : null; final String threadStatusText = DebuggerUtilsEx.getThreadStatusText(getThreadReference().status()); //noinspection HardCodedStringLiteral if (grname != null && !"SYSTEM".equalsIgnoreCase(grname)) { return DebuggerBundle.message("label.thread.node.in.group", myName, thread.uniqueID(), threadStatusText, grname); } return DebuggerBundle.message("label.thread.node", myName, thread.uniqueID(), threadStatusText); } catch (ObjectCollectedException e) { return myName != null ? DebuggerBundle.message("label.thread.node.thread.collected", myName) : ""; } }
public void setContext(EvaluationContextImpl context) { final ThreadReferenceProxyImpl thread = getThreadReference(); final SuspendManager suspendManager = context != null? context.getDebugProcess().getSuspendManager() : null; final SuspendContextImpl suspendContext = context != null? context.getSuspendContext() : null; try { myIsSuspended = suspendManager != null? suspendManager.isSuspended(thread) : thread.isSuspended(); } catch (ObjectCollectedException e) { myIsSuspended = false; } myIsExpandable = calcExpandable(myIsSuspended); mySuspendContext = SuspendManagerUtil.getSuspendContextForThread(suspendContext, thread); myIsAtBreakpoint = suspendManager != null? SuspendManagerUtil.findContextByThread(suspendManager, thread) != null : thread.isAtBreakpoint(); myIsCurrent = suspendContext != null? suspendContext.getThread() == thread : false; myIsFrozen = suspendManager != null? suspendManager.isFrozen(thread) : myIsSuspended; }
public boolean isSuspended(ThreadReferenceProxyImpl thread) throws ObjectCollectedException{ DebuggerManagerThreadImpl.assertIsManagerThread(); boolean suspended = false; if (isFrozen(thread)) { suspended = true; } else { for (SuspendContextImpl suspendContext : myEventContexts) { if (suspendContext.suspends(thread)) { suspended = true; break; } } } //bug in JDI : newly created thread may be resumed even when suspendPolicy == SUSPEND_ALL //if(LOG.isDebugEnabled() && suspended) { // LOG.assertTrue(thread.suspends(), thread.name()); //} return suspended && (thread == null || thread.isSuspended()); }
public void setContext(EvaluationContextImpl context) { final ThreadReferenceProxyImpl thread = getThreadReference(); final SuspendManager suspendManager = context != null? context.getDebugProcess().getSuspendManager() : null; final SuspendContextImpl suspendContext = context != null? context.getSuspendContext() : null; try { myIsSuspended = suspendManager != null? suspendManager.isSuspended(thread) : thread.isSuspended(); } catch (ObjectCollectedException e) { myIsSuspended = false; } myIsExpandable = calcExpandable(myIsSuspended); mySuspendContext = SuspendManagerUtil.getSuspendContextForThread(suspendContext, thread); myIsAtBreakpoint = suspendManager != null? SuspendManagerUtil.findContextByThread(suspendManager, thread) != null : thread.getThreadReference().isAtBreakpoint(); myIsCurrent = suspendContext != null? suspendContext.getThread() == thread : false; myIsFrozen = suspendManager != null? suspendManager.isFrozen(thread) : myIsSuspended; }
@Override protected JDIThread newThread(final ThreadReference reference) { try { // no need to track system threads if (!jdiManager().modelFilter().acceptsThread(reference)) { return new JDIThread(this, reference); } return new JiveThread(this, reference); } catch (final ObjectCollectedException exception) { // ObjectCollectionException can be thrown if the thread has already // completed (exited) in the VM. } return null; }
public List<PropertyChangeEvent> notifySuspendAll(boolean doFire, boolean explicitelyPaused, Set<ThreadReference> ignoredThreads) { Collection threads = threadsTranslation.getTranslated(); List<PropertyChangeEvent> events = new ArrayList<PropertyChangeEvent>(threads.size()); for (Iterator it = threads.iterator(); it.hasNext(); ) { Object threadOrGroup = it.next(); if (threadOrGroup instanceof JPDAThreadImpl && (ignoredThreads == null || !ignoredThreads.contains(((JPDAThreadImpl) threadOrGroup).getThreadReference()))) { int status = ((JPDAThreadImpl) threadOrGroup).getState(); boolean invalid = (status == JPDAThread.STATE_NOT_STARTED || status == JPDAThread.STATE_UNKNOWN || status == JPDAThread.STATE_ZOMBIE); if (!invalid) { try { PropertyChangeEvent event = ((JPDAThreadImpl) threadOrGroup).notifySuspended(doFire, explicitelyPaused); if (event != null) { events.add(event); } } catch (ObjectCollectedException ocex) { invalid = true; } } else if (status == JPDAThread.STATE_UNKNOWN || status == JPDAThread.STATE_ZOMBIE) { threadsTranslation.remove(((JPDAThreadImpl) threadOrGroup).getThreadReference()); } } } return events; }
private static ArrayReference createArrayMirrorWithDisabledCollection(ArrayType arrayType, int dimension, EvaluationContext evaluationContext) { ArrayReference array; do { array = arrayType.newInstance(dimension); try { evaluationContext.disableCollectionOf(array); } catch (ObjectCollectedException oce) { array = null; // Already collected! Create a new value and try again... } } while (array == null); return array; }
RuntimeException toJDIException() { switch (errorCode) { case JDWP.Error.INVALID_OBJECT: return new ObjectCollectedException(); case JDWP.Error.INVALID_MODULE: return new InvalidModuleException(); case JDWP.Error.VM_DEAD: return new VMDisconnectedException(); case JDWP.Error.OUT_OF_MEMORY: return new VMOutOfMemoryException(); case JDWP.Error.CLASS_NOT_PREPARED: return new ClassNotPreparedException(); case JDWP.Error.INVALID_FRAMEID: case JDWP.Error.NOT_CURRENT_FRAME: return new InvalidStackFrameException(); case JDWP.Error.NOT_IMPLEMENTED: return new UnsupportedOperationException(); case JDWP.Error.INVALID_INDEX: case JDWP.Error.INVALID_LENGTH: return new IndexOutOfBoundsException(); case JDWP.Error.TYPE_MISMATCH: return new InconsistentDebugInfoException(); case JDWP.Error.INVALID_THREAD: return new IllegalThreadStateException(); default: return new InternalException("Unexpected JDWP Error: " + errorCode, errorCode); } }
@Override public CompletableFuture<Response> handle(Command command, Arguments arguments, Response response, IDebugAdapterContext context) { StackTraceArguments stacktraceArgs = (StackTraceArguments) arguments; List<Types.StackFrame> result = new ArrayList<>(); if (stacktraceArgs.startFrame < 0 || stacktraceArgs.levels < 0) { response.body = new Responses.StackTraceResponseBody(result, 0); return CompletableFuture.completedFuture(response); } ThreadReference thread = DebugUtility.getThread(context.getDebugSession(), stacktraceArgs.threadId); int totalFrames = 0; if (thread != null) { try { totalFrames = thread.frameCount(); if (totalFrames <= stacktraceArgs.startFrame) { response.body = new Responses.StackTraceResponseBody(result, totalFrames); return CompletableFuture.completedFuture(response); } StackFrame[] frames = context.getStackFrameManager().reloadStackFrames(thread); int count = stacktraceArgs.levels == 0 ? totalFrames - stacktraceArgs.startFrame : Math.min(totalFrames - stacktraceArgs.startFrame, stacktraceArgs.levels); for (int i = stacktraceArgs.startFrame; i < frames.length && count-- > 0; i++) { StackFrameReference stackframe = new StackFrameReference(thread, i); int frameId = context.getRecyclableIdPool().addObject(thread.uniqueID(), stackframe); result.add(convertDebuggerStackFrameToClient(frames[i], frameId, context)); } } catch (IncompatibleThreadStateException | IndexOutOfBoundsException | URISyntaxException | AbsentInformationException | ObjectCollectedException e) { // when error happens, the possible reason is: // 1. the vscode has wrong parameter/wrong uri // 2. the thread actually terminates // TODO: should record a error log here. } } response.body = new Responses.StackTraceResponseBody(result, totalFrames); return CompletableFuture.completedFuture(response); }
private static Pair<String, Map<String, ObjectReference>> createMarkupVariablesText(Map<?, ValueMarkup> markupMap) { final Map<String, ObjectReference> reverseMap = new HashMap<String, ObjectReference>(); final StringBuilder buffer = StringBuilderSpinAllocator.alloc(); try { for (Map.Entry<?, ValueMarkup> entry : markupMap.entrySet()) { ObjectReference objectRef = (ObjectReference)entry.getKey(); final ValueMarkup markup = entry.getValue(); String labelName = markup.getText(); if (!StringUtil.isJavaIdentifier(labelName)) { continue; } try { final String typeName = objectRef.type().name(); labelName += DEBUG_LABEL_SUFFIX; if (buffer.length() > 0) { buffer.append("\n"); } buffer.append(typeName).append(" ").append(labelName).append(";"); reverseMap.put(labelName, objectRef); } catch (ObjectCollectedException e) { //it.remove(); } } buffer.append(" "); return Pair.create(buffer.toString(), reverseMap); } finally { StringBuilderSpinAllocator.dispose(buffer); } }
@Override public final void contextAction() throws Exception { // with custom thread we have the right context already if (myCustomThread != null) { threadAction(); return; } SuspendManager suspendManager = myDebuggerContext.getDebugProcess().getSuspendManager(); boolean isSuspendedByContext; try { isSuspendedByContext = suspendManager.isSuspended(getThread()); } catch (ObjectCollectedException ignored) { notifyCancelled(); return; } if (isSuspendedByContext) { if (LOG.isDebugEnabled()) { LOG.debug("Context thread " + getSuspendContext().getThread()); LOG.debug("Debug thread" + getThread()); } threadAction(); } else { // there are no suspend context currently registered SuspendContextImpl suspendContextForThread = SuspendManagerUtil.findContextByThread(suspendManager, getThread()); if (suspendContextForThread != null) { suspendContextForThread.postponeCommand(this); } else { notifyCancelled(); } } }
public static Value getArrayElement(ArrayReference reference, int idx) throws EvaluateException { try { return reference.getValue(idx); } catch (ObjectCollectedException e) { throw EvaluateExceptionUtil.ARRAY_WAS_COLLECTED; } }
protected String calcRepresentation(EvaluationContextImpl context, DescriptorLabelListener labelListener) throws EvaluateException { DebuggerManagerThreadImpl.assertIsManagerThread(); ThreadGroupReferenceProxyImpl group = getThreadGroupReference(); try { myName = group.name(); return DebuggerBundle.message("label.thread.group.node", myName, group.uniqueID()); } catch (ObjectCollectedException e) { return myName != null ? DebuggerBundle.message("label.thread.group.node.group.collected", myName) : ""; } }
@Override public Value calcValue(EvaluationContextImpl evaluationContext) throws EvaluateException { DebuggerManagerThreadImpl.assertIsManagerThread(); try { return (myObject != null) ? myObject.getValue(myField) : myField.declaringType().getValue(myField); } catch (ObjectCollectedException ignored) { throw EvaluateExceptionUtil.OBJECT_WAS_COLLECTED; } }
private static Pair<String, Map<String, ObjectReference>> createMarkupVariablesText(Map<ObjectReference, ValueMarkup> markupMap) { final Map<String, ObjectReference> reverseMap = new HashMap<String, ObjectReference>(); final StringBuilder buffer = StringBuilderSpinAllocator.alloc(); try { for (Iterator<Map.Entry<ObjectReference, ValueMarkup>> it = markupMap.entrySet().iterator(); it.hasNext();) { Map.Entry<ObjectReference, ValueMarkup> entry = it.next(); final ObjectReference objectRef = entry.getKey(); final ValueMarkup markup = entry.getValue(); String labelName = markup.getText(); if (!StringUtil.isJavaIdentifier(labelName)) { continue; } try { final String typeName = objectRef.type().name(); labelName += DEBUG_LABEL_SUFFIX; if (buffer.length() > 0) { buffer.append("\n"); } buffer.append(typeName).append(" ").append(labelName).append(";"); reverseMap.put(labelName, objectRef); } catch (ObjectCollectedException e) { it.remove(); } } buffer.append(" "); return new Pair<String, Map<String, ObjectReference>>(buffer.toString(), reverseMap); } finally { StringBuilderSpinAllocator.dispose(buffer); } }
public final void contextAction() throws Exception { final SuspendManager suspendManager = myDebuggerContext.getDebugProcess().getSuspendManager(); final ThreadReferenceProxyImpl debuggerContextThread = myDebuggerContext.getThreadProxy(); final boolean isSuspendedByContext; try { isSuspendedByContext = suspendManager.isSuspended(debuggerContextThread); } catch (ObjectCollectedException e) { notifyCancelled(); return; } if (isSuspendedByContext) { if (LOG.isDebugEnabled()) { LOG.debug("Context thread " + getSuspendContext().getThread()); LOG.debug("Debug thread" + debuggerContextThread); } threadAction(); } else { // there are no suspend context currently registered SuspendContextImpl suspendContextForThread = SuspendManagerUtil.findContextByThread(suspendManager, debuggerContextThread); if(suspendContextForThread != null) { suspendContextForThread.postponeCommand(this); } else { notifyCancelled(); } } }
private void updateFrameList(ThreadReferenceProxyImpl thread) { try { if(!getSuspendContext().getDebugProcess().getSuspendManager().isSuspended(thread)) { return; } } catch (ObjectCollectedException e) { return; } final EvaluationContextImpl evaluationContext = getDebuggerContext().createEvaluationContext(); final List<StackFrameDescriptorImpl> descriptors = new ArrayList<StackFrameDescriptorImpl>(); synchronized (myFramesList) { final DefaultListModel model = myFramesList.getModel(); final int size = model.getSize(); for (int i = 0; i < size; i++) { final Object elem = model.getElementAt(i); if (elem instanceof StackFrameDescriptorImpl) { descriptors.add((StackFrameDescriptorImpl)elem); } } } for (StackFrameDescriptorImpl descriptor : descriptors) { descriptor.setContext(evaluationContext); descriptor.updateRepresentation(evaluationContext, DescriptorLabelListener.DUMMY_LISTENER); } }
public Value calcValue(EvaluationContextImpl evaluationContext) throws EvaluateException { try { return myArray.getValue(myIndex); } catch (ObjectCollectedException e) { throw EvaluateExceptionUtil.ARRAY_WAS_COLLECTED; } }
public JDIThreadAdapter(final JDIDebugTarget target, final ThreadReference thread) throws ObjectCollectedException { super(target, thread); }
JiveThread(final JDIDebugTarget target, final ThreadReference thread) throws ObjectCollectedException { super(target, thread); }
boolean isSuspended(ThreadReferenceProxyImpl thread) throws ObjectCollectedException;