Search in sources :

Example 16 with Params

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;
    }
}
Also used : Params(com.oracle.truffle.tools.chromeinspector.commands.Params)

Example 17 with Params

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);
}
Also used : Script(com.oracle.truffle.tools.chromeinspector.types.Script) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) JSONArray(org.json.JSONArray) ArrayList(java.util.ArrayList) TypeObject(com.oracle.truffle.tools.chromeinspector.types.TypeObject) Params(com.oracle.truffle.tools.chromeinspector.commands.Params) Source(com.oracle.truffle.api.source.Source) ScriptTypeProfile(com.oracle.truffle.tools.chromeinspector.types.ScriptTypeProfile) JSONObject(org.json.JSONObject) Collection(java.util.Collection) TypeProfileEntry(com.oracle.truffle.tools.chromeinspector.types.TypeProfileEntry)

Example 18 with Params

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);
}
Also used : CommandProcessException(com.oracle.truffle.tools.chromeinspector.server.CommandProcessException) RemoteObject(com.oracle.truffle.tools.chromeinspector.types.RemoteObject) JSONObject(org.json.JSONObject) DebugValue(com.oracle.truffle.api.debug.DebugValue) Params(com.oracle.truffle.tools.chromeinspector.commands.Params) NoSuspendedThreadException(com.oracle.truffle.tools.chromeinspector.TruffleExecutionContext.NoSuspendedThreadException) GuestLanguageException(com.oracle.truffle.tools.chromeinspector.TruffleExecutionContext.GuestLanguageException)

Example 19 with Params

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);
}
Also used : CommandProcessException(com.oracle.truffle.tools.chromeinspector.server.CommandProcessException) Script(com.oracle.truffle.tools.chromeinspector.types.Script) Breakpoint(com.oracle.truffle.api.debug.Breakpoint) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) Params(com.oracle.truffle.tools.chromeinspector.commands.Params) SourceSection(com.oracle.truffle.api.source.SourceSection) Location(com.oracle.truffle.tools.chromeinspector.types.Location)

Aggregations

Params (com.oracle.truffle.tools.chromeinspector.commands.Params)19 JSONObject (org.json.JSONObject)15 CommandProcessException (com.oracle.truffle.tools.chromeinspector.server.CommandProcessException)9 JSONArray (org.json.JSONArray)7 Breakpoint (com.oracle.truffle.api.debug.Breakpoint)5 GuestLanguageException (com.oracle.truffle.tools.chromeinspector.TruffleExecutionContext.GuestLanguageException)5 NoSuspendedThreadException (com.oracle.truffle.tools.chromeinspector.TruffleExecutionContext.NoSuspendedThreadException)5 Script (com.oracle.truffle.tools.chromeinspector.types.Script)5 DebugValue (com.oracle.truffle.api.debug.DebugValue)4 Source (com.oracle.truffle.api.source.Source)4 SourceSection (com.oracle.truffle.api.source.SourceSection)4 RemoteObject (com.oracle.truffle.tools.chromeinspector.types.RemoteObject)4 Location (com.oracle.truffle.tools.chromeinspector.types.Location)3 ScriptTypeProfile (com.oracle.truffle.tools.chromeinspector.types.ScriptTypeProfile)3 ArrayList (java.util.ArrayList)3 Collection (java.util.Collection)3 HashMap (java.util.HashMap)3 LinkedHashMap (java.util.LinkedHashMap)3 CallFrame (com.oracle.truffle.tools.chromeinspector.types.CallFrame)2 Profile (com.oracle.truffle.tools.chromeinspector.types.Profile)2