Skip to content

Commit

Permalink
Deprecate com.oracle.truffle.api.vm and com.oracle.truffle.api.intero…
Browse files Browse the repository at this point in the history
…p.java.
  • Loading branch information
chumer committed Mar 26, 2018
1 parent d71e967 commit c6c956c
Show file tree
Hide file tree
Showing 173 changed files with 1,498 additions and 982 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,11 @@
import com.oracle.truffle.api.instrumentation.SourceSectionFilter;
import com.oracle.truffle.api.instrumentation.StandardTags;
import com.oracle.truffle.api.instrumentation.TruffleInstrument;
import com.oracle.truffle.api.interop.ForeignAccess;
import com.oracle.truffle.api.interop.Message;
import com.oracle.truffle.api.interop.TruffleObject;
import com.oracle.truffle.api.interop.java.JavaInterop;
import com.oracle.truffle.api.interop.UnknownIdentifierException;
import com.oracle.truffle.api.interop.UnsupportedMessageException;
import com.oracle.truffle.api.nodes.LanguageInfo;
import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.api.source.SourceSection;
Expand Down Expand Up @@ -131,6 +134,12 @@ private TypeProfileEventFactory() {
@Override
public ExecutionEventNode create(final EventContext context) {
return new ExecutionEventNode() {

@Child private Node keysNode = Message.KEYS.createNode();
@Child private Node readNode = Message.READ.createNode();
@Child private Node readKeyNode = Message.READ.createNode();
@Child private Node getSizeNode = Message.GET_SIZE.createNode();

@Override
protected void onEnter(VirtualFrame frame) {
super.onEnter(frame);
Expand All @@ -146,31 +155,35 @@ protected void onReturnValue(VirtualFrame frame, Object result) {
final SourceSection section = context.getInstrumentedSourceSection();
processReturnValue(result, rootNode, section);
}
};
}

@CompilerDirectives.TruffleBoundary
private void processArguments(final MaterializedFrame frame, final Node node, final SourceSection section) {
final Iterator<Scope> scopes = env.findLocalScopes(node, frame).iterator();
if (!scopes.hasNext()) {
return;
}
final Scope functionScope = scopes.next();
final Object argsObject = functionScope.getArguments();
if (argsObject instanceof TruffleObject) {
final LanguageInfo language = node.getRootNode().getLanguageInfo();
final Map<?, ?> arguments = JavaInterop.asJavaObject(Map.class, (TruffleObject) argsObject);
arguments.entrySet().forEach(entry -> {
Object argument = entry.getValue();
if (argument != null) {
final String retType = env.toString(language, env.findMetaObject(language, argument));
SourceSection argSection = getArgSection(section, entry.getKey());
if (argSection != null) {
profileMap.computeIfAbsent(argSection, s -> new SectionTypeProfile(s)).types.add(retType);
@CompilerDirectives.TruffleBoundary
private void processArguments(final MaterializedFrame frame, final Node node, final SourceSection section) {
final Iterator<Scope> scopes = env.findLocalScopes(node, frame).iterator();
if (!scopes.hasNext()) {
return;
}
final Scope functionScope = scopes.next();
final Object argsObject = functionScope.getArguments();
if (argsObject instanceof TruffleObject) {
final LanguageInfo language = node.getRootNode().getLanguageInfo();
try {
TruffleObject keys = ForeignAccess.sendKeys(keysNode, (TruffleObject) argsObject);
int size = ((Number) ForeignAccess.sendGetSize(getSizeNode, keys)).intValue();
for (int i = 0; i < size; i++) {
Object key = ForeignAccess.sendRead(readKeyNode, keys, i);
Object argument = ForeignAccess.sendRead(readNode, (TruffleObject) argsObject, key);
final String retType = env.toString(language, env.findMetaObject(language, argument));
SourceSection argSection = getArgSection(section, key);
if (argSection != null) {
profileMap.computeIfAbsent(argSection, s -> new SectionTypeProfile(s)).types.add(retType);
}
}
} catch (UnsupportedMessageException | UnknownIdentifierException e) {
throw new AssertionError(e);
}
}
});
}
}
};
}

@CompilerDirectives.TruffleBoundary
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
package com.oracle.truffle.tools.profiler.test;

import java.io.ByteArrayOutputStream;
import java.io.IOException;

import org.graalvm.polyglot.Context;
import org.graalvm.polyglot.Source;
Expand Down Expand Up @@ -58,11 +57,7 @@ public abstract class AbstractProfilerTest {
")");

protected Source makeSource(String s) {
try {
return Source.newBuilder(InstrumentationTestLanguage.ID, s, "test").build();
} catch (IOException ioe) {
throw new RuntimeException(ioe);
}
return Source.newBuilder(InstrumentationTestLanguage.ID, s, "test").buildLiteral();
}

protected static final SourceSectionFilter NO_INTERNAL_ROOT_TAG_FILTER = SourceSectionFilter.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,23 @@
*/
package com.oracle.truffle.tools.profiler.test;


import com.oracle.truffle.tools.profiler.CPUSampler;
import com.oracle.truffle.tools.profiler.ProfilerNode;
import com.oracle.truffle.tools.profiler.impl.CPUSamplerInstrument;
import org.graalvm.polyglot.Instrument;

import java.util.Collection;
import java.util.Iterator;

import org.graalvm.polyglot.Source;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;

import java.util.Collection;
import java.util.Iterator;
import com.oracle.truffle.tools.profiler.CPUSampler;
import com.oracle.truffle.tools.profiler.ProfilerNode;

public class CPUSamplerTest extends AbstractProfilerTest {

Expand All @@ -45,9 +50,7 @@ public class CPUSamplerTest extends AbstractProfilerTest {

@Before
public void setupSampler() {
Instrument instrument = context.getEngine().getInstruments().get(CPUSamplerInstrument.ID);
Assert.assertNotNull(instrument);
sampler = instrument.lookup(CPUSampler.class);
sampler = CPUSampler.find(context.getEngine());
Assert.assertNotNull(sampler);
synchronized (sampler) {
sampler.setGatherSelfHitTimes(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,15 @@
import org.junit.Before;
import org.junit.Test;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import com.oracle.truffle.tools.profiler.CPUTracer;

public class CPUTracerTest extends AbstractProfilerTest {

private CPUTracer tracer;

@Before
public void setupTracer() {
Instrument instrument = context.getEngine().getInstruments().get(CPUTracerInstrument.ID);
Assert.assertNotNull(instrument);
tracer = instrument.lookup(CPUTracer.class);
tracer = CPUTracer.find(context.getEngine());
Assert.assertNotNull(tracer);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,16 @@
import org.junit.Before;
import org.junit.Test;

import java.util.Collection;
import com.oracle.truffle.tools.profiler.MemoryTracer;
import com.oracle.truffle.tools.profiler.ProfilerNode;

public class MemoryTracerTest extends AbstractProfilerTest {

private MemoryTracer tracer;

@Before
public void setupTracer() {
Instrument instrument = context.getEngine().getInstruments().get(MemoryTracerInstrument.ID);
Assert.assertNotNull(instrument);
tracer = instrument.lookup(MemoryTracer.class);
tracer = MemoryTracer.find(context.getEngine());
Assert.assertNotNull(tracer);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,19 @@
*/
package com.oracle.truffle.tools.profiler;

import java.io.Closeable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.atomic.AtomicLong;

import org.graalvm.polyglot.Context;
import org.graalvm.polyglot.Engine;

import com.oracle.truffle.api.TruffleContext;
import com.oracle.truffle.api.instrumentation.ContextsListener;
import com.oracle.truffle.api.instrumentation.EventBinding;
Expand All @@ -33,21 +46,9 @@
import com.oracle.truffle.api.instrumentation.TruffleInstrument;
import com.oracle.truffle.api.instrumentation.TruffleInstrument.Env;
import com.oracle.truffle.api.nodes.LanguageInfo;
import com.oracle.truffle.api.source.Source;
import com.oracle.truffle.api.vm.PolyglotEngine;
import com.oracle.truffle.tools.profiler.impl.CPUSamplerInstrument;
import com.oracle.truffle.tools.profiler.impl.ProfilerToolFactory;

import java.io.Closeable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.atomic.AtomicLong;

/**
* Implementation of a sampling based profiler for
* {@linkplain com.oracle.truffle.api.TruffleLanguage Truffle languages} built on top of the
Expand Down Expand Up @@ -256,8 +257,20 @@ public void onContextClosed(TruffleContext context) {
* @param engine the engine to find debugger for
* @return an instance of associated {@link CPUSampler}
* @since 0.30
* @deprecated use {@link #find(Engine)} instead
*/
@Deprecated
@SuppressWarnings("deprecation")
public static CPUSampler find(com.oracle.truffle.api.vm.PolyglotEngine engine) {
return CPUSamplerInstrument.getSampler(engine);
}

/**
* Finds {@link CPUSampler} associated with given engine.
*
* @since 0.33
*/
public static CPUSampler find(PolyglotEngine engine) {
public static CPUSampler find(Engine engine) {
return CPUSamplerInstrument.getSampler(engine);
}

Expand Down Expand Up @@ -622,14 +635,11 @@ class CPUSamplerSnippets {
public void example() {
// @formatter:off
// BEGIN: CPUSamplerSnippets#example
PolyglotEngine engine = PolyglotEngine.newBuilder().build();
Context context = Context.create();

CPUSampler sampler = CPUSampler.find(engine);
CPUSampler sampler = CPUSampler.find(context.getEngine());
sampler.setCollecting(true);
Source someCode = Source.newBuilder("...").
mimeType("...").
name("example").build();
engine.eval(someCode);
context.eval("...", "...");
sampler.setCollecting(false);
sampler.close();
// Read information about the roots of the tree.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@
*/
package com.oracle.truffle.tools.profiler;

import java.io.Closeable;
import java.util.Collection;
import java.util.Collections;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

import org.graalvm.polyglot.Context;
import org.graalvm.polyglot.Engine;

import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.instrumentation.EventBinding;
Expand All @@ -35,19 +45,10 @@
import com.oracle.truffle.api.instrumentation.TruffleInstrument;
import com.oracle.truffle.api.instrumentation.TruffleInstrument.Env;
import com.oracle.truffle.api.nodes.NodeCost;
import com.oracle.truffle.api.source.Source;
import com.oracle.truffle.api.source.SourceSection;
import com.oracle.truffle.api.vm.PolyglotEngine;
import com.oracle.truffle.tools.profiler.impl.CPUTracerInstrument;
import com.oracle.truffle.tools.profiler.impl.ProfilerToolFactory;

import java.io.Closeable;
import java.util.Collection;
import java.util.Collections;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

/**
* Implementation of a tracing based profiler for {@linkplain com.oracle.truffle.api.TruffleLanguage
* Truffle languages} built on top of the {@linkplain TruffleInstrument Truffle instrumentation
Expand Down Expand Up @@ -80,14 +81,28 @@ public final class CPUTracer implements Closeable {

private final Map<SourceSection, Payload> payloadMap = new ConcurrentHashMap<>();

/**
* Finds {@link CPUTracer} associated with given engine.
*
* @param engine the engine to find debugger for
* @return an instance of associated {@link CPUTracer}
* @since 0.30
* @deprecated use {@link #find(Engine)} instead
*/
@Deprecated
@SuppressWarnings("deprecation")
public static CPUTracer find(com.oracle.truffle.api.vm.PolyglotEngine engine) {
return CPUTracerInstrument.getTracer(engine);
}

/**
* Finds {@link CPUTracer} associated with given engine.
*
* @param engine the engine to find debugger for
* @return an instance of associated {@link CPUTracer}
* @since 0.30
*/
public static CPUTracer find(PolyglotEngine engine) {
public static CPUTracer find(Engine engine) {
return CPUTracerInstrument.getTracer(engine);
}

Expand Down Expand Up @@ -313,13 +328,10 @@ class CPUTracerSnippets {
public void example() {
// @formatter:off
// BEGIN: CPUTracerSnippets#example
PolyglotEngine engine = PolyglotEngine.newBuilder().build();
CPUTracer tracer = CPUTracer.find(engine);
Context context = Context.create();
CPUTracer tracer = CPUTracer.find(context.getEngine());
tracer.setCollecting(true);
Source someCode = Source.newBuilder("...").
mimeType("...").
name("example").build();
engine.eval(someCode);
context.eval("...", "...");
tracer.setCollecting(false);
tracer.close();
// Read information about execution counts of elements.
Expand Down
Loading

0 comments on commit c6c956c

Please sign in to comment.