Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion com.microsoft.java.debug.core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.microsoft.java</groupId>
<artifactId>java-debug-parent</artifactId>
<version>0.4.0</version>
<version>0.5.0</version>
</parent>
<artifactId>com.microsoft.java.debug.core</artifactId>
<packaging>jar</packaging>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,6 @@ public interface IStackFrameManager {
*/
StackFrame getStackFrame(StackFrameReference ref);

/**
* Acquire a lock on the specified thread, this method will block if there is already a lock on the thread util
* the lock is released.
*
* @param thread the jdi thread
* @return the lock on the thread
*/
DisposableLock acquireThreadLock(ThreadReference thread);

/**
* Refresh all stackframes from jdi thread.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,6 @@ protected void dispatchRequest(Messages.Request request) {
ex.getMessage() != null ? ex.getMessage() : ex.toString()));
}
return null;
});
}).join();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.locks.ReentrantLock;

import com.microsoft.java.debug.core.adapter.variables.StackFrameReference;
import com.sun.jdi.IncompatibleThreadStateException;
Expand All @@ -23,7 +22,6 @@

public class StackFrameManager implements IStackFrameManager {
private Map<Long, StackFrame[]> threadStackFrameMap = Collections.synchronizedMap(new HashMap<>());
private Map<Long, ReentrantLock> locks = Collections.synchronizedMap(new HashMap<>());

@Override
public StackFrame getStackFrame(StackFrameReference ref) {
Expand All @@ -33,13 +31,6 @@ public StackFrame getStackFrame(StackFrameReference ref) {
return frames == null || frames.length < depth ? null : frames[depth];
}

@Override
public DisposableLock acquireThreadLock(ThreadReference thread) {
ReentrantLock lock = locks.computeIfAbsent(thread.uniqueID(), t -> new ReentrantLock());
lock.lock();
return new DisposableLock(lock);
}

@Override
public StackFrame[] reloadStackFrames(ThreadReference thread) {
return threadStackFrameMap.compute(thread.uniqueID(), (key, old) -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import com.microsoft.java.debug.core.Configuration;
import com.microsoft.java.debug.core.DebugSettings;
import com.microsoft.java.debug.core.adapter.AdapterUtils;
import com.microsoft.java.debug.core.adapter.DisposableLock;
import com.microsoft.java.debug.core.adapter.ErrorCode;
import com.microsoft.java.debug.core.adapter.IDebugAdapterContext;
import com.microsoft.java.debug.core.adapter.IDebugRequestHandler;
Expand Down Expand Up @@ -72,7 +71,7 @@ public CompletableFuture<Response> handle(Command command, Arguments arguments,
}

CompletableFuture<Response> completableFuture = CompletableFuture.supplyAsync(() -> {
try (DisposableLock lock = context.getStackFrameManager().acquireThreadLock(stackFrameReference.getThread())) {
try {
IEvaluationProvider engine = context.getProvider(IEvaluationProvider.class);
Value value = engine.evaluate(expression, stackFrameReference.getThread(), stackFrameReference.getDepth()).get();
IVariableFormatter variableFormatter = context.getVariableFormatter();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import java.util.List;
import java.util.concurrent.CompletableFuture;

import com.microsoft.java.debug.core.adapter.DisposableLock;
import com.microsoft.java.debug.core.adapter.IDebugAdapterContext;
import com.microsoft.java.debug.core.adapter.IDebugRequestHandler;
import com.microsoft.java.debug.core.adapter.variables.StackFrameReference;
Expand Down Expand Up @@ -45,14 +44,12 @@ public CompletableFuture<Response> handle(Command command, Arguments arguments,
response.body = new Responses.ScopesResponseBody(scopes);
return CompletableFuture.completedFuture(response);
}
try (DisposableLock lock = context.getStackFrameManager().acquireThreadLock(stackFrameReference.getThread())) {
ThreadReference thread = stackFrameReference.getThread();
VariableProxy localScope = new VariableProxy(thread, "Local", stackFrameReference);
int localScopeId = context.getRecyclableIdPool().addObject(thread.uniqueID(), localScope);
scopes.add(new Types.Scope(localScope.getScope(), localScopeId, false));
ThreadReference thread = stackFrameReference.getThread();
VariableProxy localScope = new VariableProxy(thread, "Local", stackFrameReference);
int localScopeId = context.getRecyclableIdPool().addObject(thread.uniqueID(), localScope);
scopes.add(new Types.Scope(localScope.getScope(), localScopeId, false));

response.body = new Responses.ScopesResponseBody(scopes);
return CompletableFuture.completedFuture(response);
}
response.body = new Responses.ScopesResponseBody(scopes);
return CompletableFuture.completedFuture(response);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

import com.microsoft.java.debug.core.DebugSettings;
import com.microsoft.java.debug.core.adapter.AdapterUtils;
import com.microsoft.java.debug.core.adapter.DisposableLock;
import com.microsoft.java.debug.core.adapter.ErrorCode;
import com.microsoft.java.debug.core.adapter.IDebugAdapterContext;
import com.microsoft.java.debug.core.adapter.IDebugRequestHandler;
Expand Down Expand Up @@ -85,52 +84,50 @@ public CompletableFuture<Response> handle(Command command, Arguments arguments,
"Failed to set variable. Reason: Cannot set value because the thread is resumed.");
}

try (DisposableLock lock = context.getStackFrameManager().acquireThreadLock(((VariableProxy) container).getThread())) {
String name = setVarArguments.name;
Value newValue = null;
String belongToClass = null;
String name = setVarArguments.name;
Value newValue = null;
String belongToClass = null;

if (setVarArguments.name.contains("(")) {
name = setVarArguments.name.replaceFirst(PATTERN, "$1");
belongToClass = setVarArguments.name.replaceFirst(PATTERN, "$2");
}
if (setVarArguments.name.contains("(")) {
name = setVarArguments.name.replaceFirst(PATTERN, "$1");
belongToClass = setVarArguments.name.replaceFirst(PATTERN, "$2");
}

try {
Object containerObj = ((VariableProxy) container).getProxiedVariable();
if (containerObj instanceof StackFrameReference) {
StackFrameReference stackFrameReference = (StackFrameReference) containerObj;
StackFrame sf = context.getStackFrameManager().getStackFrame(stackFrameReference);
newValue = handleSetValueForStackFrame(name, belongToClass, setVarArguments.value,
showStaticVariables, sf, options);
} else if (containerObj instanceof ObjectReference) {
newValue = handleSetValueForObject(name, belongToClass, setVarArguments.value, (ObjectReference) containerObj, options);
} else {
return AdapterUtils.createAsyncErrorResponse(response, ErrorCode.SET_VARIABLE_FAILURE,
String.format("SetVariableRequest: Variable %s cannot be found.", setVarArguments.variablesReference));
}
} catch (IllegalArgumentException | AbsentInformationException | InvalidTypeException
| UnsupportedOperationException | ClassNotLoadedException e) {
try {
Object containerObj = ((VariableProxy) container).getProxiedVariable();
if (containerObj instanceof StackFrameReference) {
StackFrameReference stackFrameReference = (StackFrameReference) containerObj;
StackFrame sf = context.getStackFrameManager().getStackFrame(stackFrameReference);
newValue = handleSetValueForStackFrame(name, belongToClass, setVarArguments.value,
showStaticVariables, sf, options);
} else if (containerObj instanceof ObjectReference) {
newValue = handleSetValueForObject(name, belongToClass, setVarArguments.value, (ObjectReference) containerObj, options);
} else {
return AdapterUtils.createAsyncErrorResponse(response, ErrorCode.SET_VARIABLE_FAILURE,
String.format("Failed to set variable. Reason: %s", e.toString()));
}
int referenceId = 0;
if (newValue instanceof ObjectReference && VariableUtils.hasChildren(newValue, showStaticVariables)) {
long threadId = ((VariableProxy) container).getThreadId();
String scopeName = ((VariableProxy) container).getScope();
VariableProxy varProxy = new VariableProxy(((VariableProxy) container).getThread(), scopeName, newValue);
referenceId = context.getRecyclableIdPool().addObject(threadId, varProxy);
String.format("SetVariableRequest: Variable %s cannot be found.", setVarArguments.variablesReference));
}
} catch (IllegalArgumentException | AbsentInformationException | InvalidTypeException
| UnsupportedOperationException | ClassNotLoadedException e) {
return AdapterUtils.createAsyncErrorResponse(response, ErrorCode.SET_VARIABLE_FAILURE,
String.format("Failed to set variable. Reason: %s", e.toString()));
}
int referenceId = 0;
if (newValue instanceof ObjectReference && VariableUtils.hasChildren(newValue, showStaticVariables)) {
long threadId = ((VariableProxy) container).getThreadId();
String scopeName = ((VariableProxy) container).getScope();
VariableProxy varProxy = new VariableProxy(((VariableProxy) container).getThread(), scopeName, newValue);
referenceId = context.getRecyclableIdPool().addObject(threadId, varProxy);
}

int indexedVariables = 0;
if (newValue instanceof ArrayReference) {
indexedVariables = ((ArrayReference) newValue).length();
}
response.body = new Responses.SetVariablesResponseBody(
context.getVariableFormatter().typeToString(newValue == null ? null : newValue.type(), options), // type
context.getVariableFormatter().valueToString(newValue, options), // value,
referenceId, indexedVariables);
return CompletableFuture.completedFuture(response);
int indexedVariables = 0;
if (newValue instanceof ArrayReference) {
indexedVariables = ((ArrayReference) newValue).length();
}
response.body = new Responses.SetVariablesResponseBody(
context.getVariableFormatter().typeToString(newValue == null ? null : newValue.type(), options), // type
context.getVariableFormatter().valueToString(newValue, options), // value,
referenceId, indexedVariables);
return CompletableFuture.completedFuture(response);
}

private Value handleSetValueForObject(String name, String belongToClass, String valueString,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

import com.microsoft.java.debug.core.DebugUtility;
import com.microsoft.java.debug.core.adapter.AdapterUtils;
import com.microsoft.java.debug.core.adapter.DisposableLock;
import com.microsoft.java.debug.core.adapter.IDebugAdapterContext;
import com.microsoft.java.debug.core.adapter.IDebugRequestHandler;
import com.microsoft.java.debug.core.adapter.ISourceLookUpProvider;
Expand Down Expand Up @@ -61,7 +60,7 @@ public CompletableFuture<Response> handle(Command command, Arguments arguments,
ThreadReference thread = DebugUtility.getThread(context.getDebugSession(), stacktraceArgs.threadId);
int totalFrames = 0;
if (thread != null) {
try (DisposableLock lock = context.getStackFrameManager().acquireThreadLock(thread)) {
try {
totalFrames = thread.frameCount();
if (totalFrames <= stacktraceArgs.startFrame) {
response.body = new Responses.StackTraceResponseBody(result, totalFrames);
Expand Down
Loading