Search in sources :

Example 26 with Source

use of com.oracle.truffle.api.source.Source in project graal by oracle.

the class TruffleProfiler method getCoverage.

private Params getCoverage(Collection<CPUTracer.Payload> payloads) {
    JSONObject json = new JSONObject();
    Map<Source, Map<String, Collection<CPUTracer.Payload>>> sourceToRoots = new HashMap<>();
    payloads.forEach(payload -> {
        Map<String, Collection<CPUTracer.Payload>> rootsToPayloads = sourceToRoots.computeIfAbsent(payload.getSourceSection().getSource(), s -> new LinkedHashMap<>());
        Collection<CPUTracer.Payload> pls = rootsToPayloads.computeIfAbsent(payload.getRootName(), t -> new LinkedList<>());
        pls.add(payload);
    });
    JSONArray result = new JSONArray();
    sourceToRoots.entrySet().stream().map(sourceEntry -> {
        List<FunctionCoverage> functions = new ArrayList<>();
        sourceEntry.getValue().entrySet().forEach(rootEntry -> {
            boolean isBlockCoverage = false;
            List<CoverageRange> ranges = new ArrayList<>();
            for (CPUTracer.Payload payload : rootEntry.getValue()) {
                isBlockCoverage |= payload.getTags().contains(StandardTags.StatementTag.class);
                ranges.add(new CoverageRange(payload.getSourceSection().getCharIndex(), payload.getSourceSection().getCharEndIndex(), payload.getCount()));
            }
            functions.add(new FunctionCoverage(rootEntry.getKey(), isBlockCoverage, ranges.toArray(new CoverageRange[ranges.size()])));
        });
        int scriptId = slh.getScriptId(sourceEntry.getKey());
        Script script = scriptId < 0 ? null : slh.getScript(scriptId);
        return new ScriptCoverage(script != null ? script.getId() : 0, script != null ? script.getUrl() : "", functions.toArray(new FunctionCoverage[functions.size()]));
    }).forEachOrdered(scriptCoverage -> {
        result.put(scriptCoverage.toJSON());
    });
    json.put("result", result);
    return new Params(json);
}
Also used : ProfileNode(com.oracle.truffle.tools.chromeinspector.types.ProfileNode) StandardTags(com.oracle.truffle.api.instrumentation.StandardTags) TypeProfileInstrument(com.oracle.truffle.tools.chromeinspector.instrument.TypeProfileInstrument) CoverageRange(com.oracle.truffle.tools.chromeinspector.types.CoverageRange) Script(com.oracle.truffle.tools.chromeinspector.types.Script) HashMap(java.util.HashMap) SourceSectionFilter(com.oracle.truffle.api.instrumentation.SourceSectionFilter) Params(com.oracle.truffle.tools.chromeinspector.commands.Params) Enabler(com.oracle.truffle.tools.chromeinspector.instrument.Enabler) TypeProfileEntry(com.oracle.truffle.tools.chromeinspector.types.TypeProfileEntry) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) JSONObject(org.json.JSONObject) FunctionCoverage(com.oracle.truffle.tools.chromeinspector.types.FunctionCoverage) Map(java.util.Map) ScriptTypeProfile(com.oracle.truffle.tools.chromeinspector.types.ScriptTypeProfile) CPUTracer(com.oracle.truffle.tools.profiler.CPUTracer) SourceSection(com.oracle.truffle.api.source.SourceSection) LinkedList(java.util.LinkedList) ProfilerDomain(com.oracle.truffle.tools.chromeinspector.domains.ProfilerDomain) RuntimeCallFrame(com.oracle.truffle.tools.chromeinspector.types.RuntimeCallFrame) Profile(com.oracle.truffle.tools.chromeinspector.types.Profile) Collection(java.util.Collection) ProfilerNode(com.oracle.truffle.tools.profiler.ProfilerNode) InstrumentInfo(com.oracle.truffle.api.InstrumentInfo) ScriptCoverage(com.oracle.truffle.tools.chromeinspector.types.ScriptCoverage) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) Source(com.oracle.truffle.api.source.Source) CPUSamplerInstrument(com.oracle.truffle.tools.profiler.impl.CPUSamplerInstrument) CPUSampler(com.oracle.truffle.tools.profiler.CPUSampler) Collections(java.util.Collections) JSONArray(org.json.JSONArray) TypeObject(com.oracle.truffle.tools.chromeinspector.types.TypeObject) CPUTracerInstrument(com.oracle.truffle.tools.profiler.impl.CPUTracerInstrument) Script(com.oracle.truffle.tools.chromeinspector.types.Script) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) JSONArray(org.json.JSONArray) Params(com.oracle.truffle.tools.chromeinspector.commands.Params) Source(com.oracle.truffle.api.source.Source) StandardTags(com.oracle.truffle.api.instrumentation.StandardTags) ScriptCoverage(com.oracle.truffle.tools.chromeinspector.types.ScriptCoverage) FunctionCoverage(com.oracle.truffle.tools.chromeinspector.types.FunctionCoverage) JSONObject(org.json.JSONObject) CPUTracer(com.oracle.truffle.tools.profiler.CPUTracer) CoverageRange(com.oracle.truffle.tools.chromeinspector.types.CoverageRange) Collection(java.util.Collection) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 27 with Source

use of com.oracle.truffle.api.source.Source in project graal by oracle.

the class TruffleRuntime method compileScript.

@Override
public Params compileScript(String expression, String sourceURL, boolean persistScript, long executionContextId) throws CommandProcessException {
    if (expression == null) {
        throw new CommandProcessException("An expression required.");
    }
    JSONObject ret = new JSONObject();
    ScriptsHandler sh = context.getScriptsHandler();
    try {
        if (sh != null) {
            Source source = createSource(expression, sourceURL);
            boolean parsed = false;
            String[] exceptionText = new String[1];
            if (context.getSuspendedInfo() != null) {
                try {
                    parsed = context.executeInSuspendThread(new SuspendThreadExecutable<Boolean>() {

                        @Override
                        public Boolean executeCommand() throws CommandProcessException {
                            try {
                                context.getEnv().parse(source);
                                return true;
                            } catch (Exception ex) {
                                // Didn't manage to parse this
                                exceptionText[0] = ex.getLocalizedMessage();
                                return false;
                            }
                        }
                    });
                } catch (GuestLanguageException ex) {
                    fillExceptionDetails(ret, ex);
                } catch (NoSuspendedThreadException ex) {
                    exceptionText[0] = ex.getLocalizedMessage();
                }
            } else {
                // Parse on the current thread will fail most likely due to a lack of context
                parsed = false;
                exceptionText[0] = "<Not suspended>";
            }
            if (parsed && persistScript) {
                int id = sh.assureLoaded(source);
                ret.put("scriptId", Integer.toString(id));
            }
            if (exceptionText[0] != null) {
                JSONObject exceptionDetails = new JSONObject();
                exceptionDetails.put("text", exceptionText[0]);
                ret.put("exceptionDetails", exceptionDetails);
            }
        }
    } finally {
        context.releaseScriptsHandler();
    }
    return new Params(ret);
}
Also used : CommandProcessException(com.oracle.truffle.tools.chromeinspector.server.CommandProcessException) Params(com.oracle.truffle.tools.chromeinspector.commands.Params) NoSuspendedThreadException(com.oracle.truffle.tools.chromeinspector.TruffleExecutionContext.NoSuspendedThreadException) Source(com.oracle.truffle.api.source.Source) NoSuspendedThreadException(com.oracle.truffle.tools.chromeinspector.TruffleExecutionContext.NoSuspendedThreadException) URISyntaxException(java.net.URISyntaxException) CommandProcessException(com.oracle.truffle.tools.chromeinspector.server.CommandProcessException) GuestLanguageException(com.oracle.truffle.tools.chromeinspector.TruffleExecutionContext.GuestLanguageException) JSONObject(org.json.JSONObject) GuestLanguageException(com.oracle.truffle.tools.chromeinspector.TruffleExecutionContext.GuestLanguageException)

Example 28 with Source

use of com.oracle.truffle.api.source.Source in project graal by oracle.

the class LoadNFILibraryTest method eval.

private static TruffleObject eval(String format, Object... args) {
    Source source = Source.newBuilder(String.format(format, args)).name("LoadLibraryTest").mimeType("application/x-native").build();
    CallTarget target = runWithPolyglot.getTruffleTestEnv().parse(source);
    return (TruffleObject) target.call();
}
Also used : CallTarget(com.oracle.truffle.api.CallTarget) Source(com.oracle.truffle.api.source.Source) TruffleObject(com.oracle.truffle.api.interop.TruffleObject)

Example 29 with Source

use of com.oracle.truffle.api.source.Source in project graal by oracle.

the class Context method initializeContext.

@Override
protected void initializeContext(Context context) throws Exception {
    super.initializeContext(context);
    Source code = context.initSource;
    if (code != null) {
        SourceSection outer = code.createSection(0, code.getLength());
        BaseNode node = parse(code);
        RootCallTarget rct = Truffle.getRuntime().createCallTarget(new InstrumentationTestRootNode(this, "", outer, node));
        rct.call();
        if (context.runInitAfterExec) {
            context.afterTarget = rct;
        }
    }
}
Also used : SourceSection(com.oracle.truffle.api.source.SourceSection) RootCallTarget(com.oracle.truffle.api.RootCallTarget) Source(com.oracle.truffle.api.source.Source)

Example 30 with Source

use of com.oracle.truffle.api.source.Source in project graal by oracle.

the class Context method parse.

@Override
protected ExecutableNode parse(InlineParsingRequest request) throws Exception {
    Source code = request.getSource();
    Node location = request.getLocation();
    if (location == null) {
        throw new IllegalArgumentException("Location must not be null.");
    }
    BaseNode node;
    try {
        node = parse(code);
    } catch (LanguageError e) {
        throw new IOException(e);
    }
    return new InlineExecutableNode(this, node);
}
Also used : RootNode(com.oracle.truffle.api.nodes.RootNode) DirectCallNode(com.oracle.truffle.api.nodes.DirectCallNode) ExecutableNode(com.oracle.truffle.api.nodes.ExecutableNode) ProbeNode(com.oracle.truffle.api.instrumentation.ProbeNode) Node(com.oracle.truffle.api.nodes.Node) InstrumentableNode(com.oracle.truffle.api.instrumentation.InstrumentableNode) IOException(java.io.IOException) Source(com.oracle.truffle.api.source.Source)

Aggregations

Source (com.oracle.truffle.api.source.Source)113 Test (org.junit.Test)65 RootNode (com.oracle.truffle.api.nodes.RootNode)23 File (java.io.File)20 InstrumentableNode (com.oracle.truffle.api.instrumentation.InstrumentableNode)16 Node (com.oracle.truffle.api.nodes.Node)16 SourceSection (com.oracle.truffle.api.source.SourceSection)16 ProbeNode (com.oracle.truffle.api.instrumentation.ProbeNode)15 TruffleObject (com.oracle.truffle.api.interop.TruffleObject)11 SourceSectionFilter (com.oracle.truffle.api.instrumentation.SourceSectionFilter)8 IOException (java.io.IOException)8 ArrayList (java.util.ArrayList)7 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 CallTarget (com.oracle.truffle.api.CallTarget)5 FileWriter (java.io.FileWriter)5 RootCallTarget (com.oracle.truffle.api.RootCallTarget)4 TruffleContext (com.oracle.truffle.api.TruffleContext)3 Params (com.oracle.truffle.tools.chromeinspector.commands.Params)3 CommandProcessException (com.oracle.truffle.tools.chromeinspector.server.CommandProcessException)3 Script (com.oracle.truffle.tools.chromeinspector.types.Script)3