Search in sources :

Example 1 with SourceSectionFilter

use of com.oracle.truffle.api.instrumentation.SourceSectionFilter in project graal by oracle.

the class SuspendableLocationFinder method collectSuspendableLocations.

private static SectionsCollector collectSuspendableLocations(Source source, int startIndex, int endIndex, boolean restrictToSingleFunction, TruffleInstrument.Env env) {
    SourceSectionFilter filter = SourceSectionFilter.newBuilder().sourceIs(source).indexIn(IndexRange.between(startIndex, endIndex)).tagIs(SUSPENDABLE_TAGS).build();
    SectionsCollector sectionsCollector;
    if (restrictToSingleFunction) {
        sectionsCollector = new FunctionSectionsCollector(startIndex, env.getInstrumenter());
    } else {
        sectionsCollector = new SectionsCollector(startIndex);
    }
    EventBinding<SectionsCollector> binding = env.getInstrumenter().attachLoadSourceSectionListener(filter, sectionsCollector, true);
    binding.dispose();
    return sectionsCollector;
}
Also used : SourceSectionFilter(com.oracle.truffle.api.instrumentation.SourceSectionFilter)

Example 2 with SourceSectionFilter

use of com.oracle.truffle.api.instrumentation.SourceSectionFilter in project graal by oracle.

the class SuspendableLocationFinder method findSuspendableLocations.

static Iterable<SourceSection> findSuspendableLocations(SourceSection range, boolean restrictToSingleFunction, TruffleInstrument.Env env) {
    Source source = range.getSource();
    int startIndex = range.getCharIndex();
    int endIndex = range.getCharEndIndex();
    SectionsCollector sectionsCollector = collectSuspendableLocations(source, startIndex, endIndex, restrictToSingleFunction, env);
    List<SourceSection> sections = sectionsCollector.getSections();
    if (sections.isEmpty()) {
        SourceSectionFilter filter = SourceSectionFilter.newBuilder().sourceIs(source).indexIn(IndexRange.between(startIndex, endIndex)).build();
        ContainerNodeCollector nodeCollector = new ContainerNodeCollector(startIndex);
        EventBinding<ContainerNodeCollector> binding = env.getInstrumenter().attachLoadSourceSectionListener(filter, nodeCollector, true);
        binding.dispose();
        if (nodeCollector.getContainerNode() != null) {
            Node suspendableNode = nodeCollector.getContainerNode().findNearestNodeAt(startIndex, SUSPENDABLE_TAGS_SET);
            if (suspendableNode != null) {
                startIndex = Math.min(startIndex, suspendableNode.getSourceSection().getCharIndex());
                endIndex = Math.max(endIndex, suspendableNode.getSourceSection().getCharEndIndex());
                sectionsCollector = collectSuspendableLocations(source, startIndex, endIndex, restrictToSingleFunction, env);
                sections = sectionsCollector.getSections();
            }
        }
    }
    return sections;
}
Also used : Node(com.oracle.truffle.api.nodes.Node) InstrumentableNode(com.oracle.truffle.api.instrumentation.InstrumentableNode) SourceSection(com.oracle.truffle.api.source.SourceSection) SourceSectionFilter(com.oracle.truffle.api.instrumentation.SourceSectionFilter) Source(com.oracle.truffle.api.source.Source)

Example 3 with SourceSectionFilter

use of com.oracle.truffle.api.instrumentation.SourceSectionFilter in project graal by oracle.

the class TypeHandler method start.

public boolean start() {
    if (currentBinding.get() == null) {
        final SourceSectionFilter filter = SourceSectionFilter.newBuilder().tagIs(StandardTags.RootTag.class).includeInternal(false).build();
        final Instrumenter instrumenter = env.getInstrumenter();
        final EventBinding<TypeProfileEventFactory> binding = instrumenter.attachExecutionEventFactory(filter, new TypeProfileEventFactory());
        if (currentBinding.compareAndSet(null, binding)) {
            return true;
        } else {
            binding.dispose();
        }
    }
    return false;
}
Also used : SourceSectionFilter(com.oracle.truffle.api.instrumentation.SourceSectionFilter) Instrumenter(com.oracle.truffle.api.instrumentation.Instrumenter) StandardTags(com.oracle.truffle.api.instrumentation.StandardTags)

Example 4 with SourceSectionFilter

use of com.oracle.truffle.api.instrumentation.SourceSectionFilter in project graal by oracle.

the class CPUSamplerSnippets method resetSampling.

private void resetSampling() {
    assert Thread.holdsLock(this);
    cleanup();
    if (!collecting || closed) {
        return;
    }
    if (samplerThread == null) {
        samplerThread = new Timer("Sampling thread", true);
    }
    SourceSectionFilter f = this.filter;
    if (f == null) {
        f = DEFAULT_FILTER;
    }
    this.stackOverflowed = false;
    this.shadowStack = new ShadowStack(stackLimit);
    this.stacksBinding = this.shadowStack.install(env.getInstrumenter(), combine(f, mode), mode == Mode.EXCLUDE_INLINED_ROOTS);
    this.samplerTask = new SamplingTimerTask();
    this.samplerThread.schedule(samplerTask, 0, period);
}
Also used : Timer(java.util.Timer) SourceSectionFilter(com.oracle.truffle.api.instrumentation.SourceSectionFilter)

Example 5 with SourceSectionFilter

use of com.oracle.truffle.api.instrumentation.SourceSectionFilter in project graal by oracle.

the class MemoryTracerSnippets method resetTracer.

void resetTracer() {
    assert Thread.holdsLock(this);
    if (activeBinding != null) {
        activeBinding.dispose();
        activeBinding = null;
    }
    if (!collecting || closed) {
        return;
    }
    this.shadowStack = new ShadowStack(stackLimit);
    SourceSectionFilter f = this.filter;
    if (f == null) {
        f = DEFAULT_FILTER;
    }
    this.stacksBinding = this.shadowStack.install(env.getInstrumenter(), f, false);
    this.activeBinding = env.getInstrumenter().attachAllocationListener(AllocationEventFilter.ANY, new Listener());
}
Also used : AllocationListener(com.oracle.truffle.api.instrumentation.AllocationListener) SourceSectionFilter(com.oracle.truffle.api.instrumentation.SourceSectionFilter)

Aggregations

SourceSectionFilter (com.oracle.truffle.api.instrumentation.SourceSectionFilter)32 Test (org.junit.Test)21 StandardTags (com.oracle.truffle.api.instrumentation.StandardTags)7 Source (com.oracle.truffle.api.source.Source)7 ExpressionNode (com.oracle.truffle.api.instrumentation.test.InstrumentationTestLanguage.ExpressionNode)5 MaterializeChildExpressionNode (com.oracle.truffle.api.instrumentation.test.InstrumentationTestLanguage.MaterializeChildExpressionNode)5 MaterializedChildExpressionNode (com.oracle.truffle.api.instrumentation.test.InstrumentationTestLanguage.MaterializedChildExpressionNode)5 ExpressionTag (com.oracle.truffle.api.instrumentation.StandardTags.ExpressionTag)4 InstrumentableNode (com.oracle.truffle.api.instrumentation.InstrumentableNode)3 Node (com.oracle.truffle.api.nodes.Node)3 RootNode (com.oracle.truffle.api.nodes.RootNode)3 EventContext (com.oracle.truffle.api.instrumentation.EventContext)2 ExecutionEventNodeFactory (com.oracle.truffle.api.instrumentation.ExecutionEventNodeFactory)2 Instrumenter (com.oracle.truffle.api.instrumentation.Instrumenter)2 ProbeNode (com.oracle.truffle.api.instrumentation.ProbeNode)2 Builder (com.oracle.truffle.api.instrumentation.SourceSectionFilter.Builder)2 SourceSection (com.oracle.truffle.api.source.SourceSection)2 Source (org.graalvm.polyglot.Source)2 FrameDescriptor (com.oracle.truffle.api.frame.FrameDescriptor)1 AllocationListener (com.oracle.truffle.api.instrumentation.AllocationListener)1