use of com.oracle.truffle.tools.chromeinspector.commands.Params in project graal by oracle.
the class TruffleProfiler method takeTypeProfile.
@Override
public Params takeTypeProfile() {
synchronized (typeHandler) {
Params typeProfile = getTypeProfile(typeHandler.getSectionTypeProfiles());
typeHandler.clearData();
return typeProfile;
}
}
use of com.oracle.truffle.tools.chromeinspector.commands.Params in project graal by oracle.
the class TruffleProfiler method getTypeProfile.
private Params getTypeProfile(Collection<TypeHandler.SectionTypeProfile> profiles) {
JSONObject json = new JSONObject();
Map<Source, Collection<TypeHandler.SectionTypeProfile>> sourceToProfiles = new HashMap<>();
profiles.forEach(profile -> {
Collection<TypeHandler.SectionTypeProfile> pfs = sourceToProfiles.computeIfAbsent(profile.getSourceSection().getSource(), t -> new LinkedList<>());
pfs.add(profile);
});
JSONArray result = new JSONArray();
sourceToProfiles.entrySet().forEach(entry -> {
List<TypeProfileEntry> entries = new ArrayList<>();
entry.getValue().forEach(sectionProfile -> {
List<TypeObject> types = new ArrayList<>();
sectionProfile.getTypes().forEach(type -> {
types.add(new TypeObject(type));
});
if (!types.isEmpty()) {
entries.add(new TypeProfileEntry(sectionProfile.getSourceSection().getCharEndIndex(), types.toArray(new TypeObject[types.size()])));
}
});
int scriptId = slh.getScriptId(entry.getKey());
Script script = scriptId < 0 ? null : slh.getScript(scriptId);
result.put(new ScriptTypeProfile(script != null ? script.getId() : 0, script != null ? script.getUrl() : "", entries.toArray(new TypeProfileEntry[entries.size()])).toJSON());
});
json.put("result", result);
return new Params(json);
}
use of com.oracle.truffle.tools.chromeinspector.commands.Params in project graal by oracle.
the class TruffleRuntime method callFunctionOn.
@Override
public Params callFunctionOn(String objectId, String functionDeclaration, JSONArray arguments, boolean silent, boolean returnByValue, boolean awaitPromise) throws CommandProcessException {
if (objectId == null) {
throw new CommandProcessException("An objectId required.");
}
RemoteObject object = context.getRemoteObjectsHandler().getRemote(objectId);
JSONObject json = new JSONObject();
if (object != null) {
DebugValue value = object.getDebugValue();
DebuggerSuspendedInfo suspendedInfo = context.getSuspendedInfo();
if (suspendedInfo != null) {
try {
context.executeInSuspendThread(new SuspendThreadExecutable<Void>() {
@Override
public Void executeCommand() throws CommandProcessException {
JSONObject result;
if (functionDeclaration.startsWith("function getCompletions(")) {
result = createCodecompletion(value);
} else {
String code = "(" + functionDeclaration + ")(" + value.getName() + ")";
DebugValue eval = suspendedInfo.getSuspendedEvent().getTopStackFrame().eval(code);
if (!returnByValue) {
RemoteObject ro = new RemoteObject(eval, context.getErr());
context.getRemoteObjectsHandler().register(ro);
result = ro.toJSON();
} else {
result = RemoteObject.createJSONResultValue(eval, context.getErr());
}
}
json.put("result", result);
return null;
}
});
} catch (NoSuspendedThreadException ex) {
json.put("result", new JSONObject());
} catch (GuestLanguageException ex) {
fillExceptionDetails(json, ex);
}
}
}
return new Params(json);
}
use of com.oracle.truffle.tools.chromeinspector.commands.Params in project graal by oracle.
the class BreakpointsHandler method createBreakpoint.
Params createBreakpoint(Location location, String condition) throws CommandProcessException {
Script script = slh.getScript(location.getScriptId());
if (script == null) {
throw new CommandProcessException("No script with id '" + location.getScriptId() + "'");
}
Breakpoint bp = createBuilder(script.getSource(), location.getLine(), location.getColumn()).resolveListener(resolvedHandler).build();
if (condition != null && !condition.isEmpty()) {
bp.setCondition(condition);
}
bp = ds.install(bp);
JSONArray locations = new JSONArray();
long id;
synchronized (bpIDs) {
id = ++lastID;
bpIDs.put(bp, id);
SourceSection section = resolvedBreakpoints.remove(bp);
if (section != null) {
Location resolvedLocation = new Location(location.getScriptId(), section.getStartLine(), section.getStartColumn());
locations.put(resolvedLocation.toJSON());
}
}
JSONObject json = new JSONObject();
json.put("breakpointId", Long.toString(id));
locations.put(location.toJSON());
json.put("locations", locations);
return new Params(json);
}
Aggregations