use of com.oracle.truffle.api.frame.VirtualFrame in project graal by oracle.
the class EngineTest method testLanguageAccess.
@Test
public void testLanguageAccess() {
final PolyglotEngine.Builder builder = createBuilderInternal();
ForkingLanguageChannel channel = new ForkingLanguageChannel(builder::build);
PolyglotEngine vm = builder.config(ForkingLanguage.MIME_TYPE, "channel", channel).build();
vm.eval(Source.newBuilder("").name("").mimeType(ForkingLanguage.MIME_TYPE).build()).get();
RootNode root = new RootNode(channel.language) {
@Override
public Object execute(VirtualFrame frame) {
return null;
}
};
try {
// no access using a TruffleLanguage hack
root.getLanguage(TruffleLanguage.class);
fail();
} catch (ClassCastException e) {
}
Class<?> oClass = Object.class;
Class<? extends TruffleLanguage> lang = (Class<? extends TruffleLanguage>) oClass;
try {
// no access using a TruffleLanguage class cast
root.getLanguage(lang);
fail();
} catch (ClassCastException e) {
}
oClass = SecretInterfaceType.class;
Class<? extends TruffleLanguage> secretInterface = (Class<? extends TruffleLanguage>) oClass;
try {
// no access using secret interface
root.getLanguage(secretInterface);
fail();
} catch (ClassCastException e) {
}
// this should work as expected
assertNotNull(root.getLanguage(ForkingLanguage.class));
}
use of com.oracle.truffle.api.frame.VirtualFrame in project graal by oracle.
the class GenerateWrapperTest method testDelegateAbstractMethod.
public void testDelegateAbstractMethod() {
AtomicInteger foobarInvocations = new AtomicInteger();
DelegateAbstractMethod node = new DelegateAbstractMethod() {
@Override
public void execute(VirtualFrame frame) {
}
@Override
public void foobar() {
foobarInvocations.incrementAndGet();
}
};
DelegateAbstractMethod wrapper = new DelegateAbstractMethodWrapper(node, null);
wrapper.foobar();
assertEquals(1, foobarInvocations.get());
}
use of com.oracle.truffle.api.frame.VirtualFrame in project graal by oracle.
the class InputFilterTest method assertCleanedUp.
private void assertCleanedUp(String code) {
// first we capture all root nodes used by the code.
Set<RootNode> rootNodes = new HashSet<>();
EventBinding<?> binding = instrumenter.attachExecutionEventListener(SourceSectionFilter.ANY, new ExecutionEventListener() {
public void onEnter(EventContext c, VirtualFrame frame) {
addRoot(c);
}
@TruffleBoundary
private void addRoot(EventContext c) {
rootNodes.add(c.getInstrumentedNode().getRootNode());
}
public void onReturnValue(EventContext c, VirtualFrame frame, Object result) {
}
public void onReturnExceptional(EventContext c, VirtualFrame frame, Throwable exception) {
}
});
execute(code);
binding.dispose();
// we execute again to let the instrumentation wrappers be cleaned up
execute(code);
for (RootNode root : rootNodes) {
// all frame slots got removed
assertEquals(new HashSet<>(), root.getFrameDescriptor().getIdentifiers());
// no wrappers left
root.accept(new NodeVisitor() {
public boolean visit(Node node) {
if (node instanceof WrapperNode) {
throw new AssertionError();
}
return true;
}
});
}
}
use of com.oracle.truffle.api.frame.VirtualFrame in project graal by oracle.
the class TruffleBoundaryExceptionsTest method testExceptionOnTruffleBoundaryDoesNotDeop.
@Test
public void testExceptionOnTruffleBoundaryDoesNotDeop() {
final int compilationThreshold = TruffleCompilerOptions.getValue(TruffleCompilationThreshold);
class DeoptCountingExceptionOverBoundaryRootNode extends RootNode {
protected DeoptCountingExceptionOverBoundaryRootNode() {
super(null);
}
int deopCounter = 0;
int catchCounter = 0;
int interpretCount = 0;
@Override
public Object execute(VirtualFrame frame) {
boolean startedCompiled = CompilerDirectives.inCompiledCode();
if (!startedCompiled) {
interpretCount++;
}
try {
throwExceptionBoundary();
} catch (RuntimeException e) {
catchCounter++;
}
if (startedCompiled && CompilerDirectives.inInterpreter()) {
deopCounter++;
}
return null;
}
@CompilerDirectives.TruffleBoundary
public void throwExceptionBoundary() {
throw new RuntimeException();
}
}
final int[] compilationCount = { 0 };
GraalTruffleRuntimeListener listener = new GraalTruffleRuntimeListener() {
@Override
public void onCompilationStarted(OptimizedCallTarget target) {
compilationCount[0]++;
}
};
final OptimizedCallTarget outerTarget = (OptimizedCallTarget) runtime.createCallTarget(new DeoptCountingExceptionOverBoundaryRootNode());
for (int i = 0; i < compilationThreshold; i++) {
outerTarget.call();
}
assertCompiled(outerTarget);
runtime.addListener(listener);
final int execCount = 10;
for (int i = 0; i < execCount; i++) {
outerTarget.call();
}
final int totalExecutions = compilationThreshold + execCount;
int catchCount = ((DeoptCountingExceptionOverBoundaryRootNode) outerTarget.getRootNode()).catchCounter;
Assert.assertEquals("Incorrect number of catch block executions", totalExecutions, catchCount);
int interpretCount = ((DeoptCountingExceptionOverBoundaryRootNode) outerTarget.getRootNode()).interpretCount;
int deopCount = ((DeoptCountingExceptionOverBoundaryRootNode) outerTarget.getRootNode()).deopCounter;
Assert.assertEquals("Incorrect number of deops detected!", totalExecutions - interpretCount, deopCount);
Assert.assertEquals("Compilation happened!", 0, compilationCount[0]);
runtime.removeListener(listener);
}
use of com.oracle.truffle.api.frame.VirtualFrame in project graal by oracle.
the class TruffleBoundaryExceptionsTest method testExceptionOnTruffleBoundaryWithNoCatchTransferFalse.
@Test
public void testExceptionOnTruffleBoundaryWithNoCatchTransferFalse() {
final int compilationThreshold = TruffleCompilerOptions.getValue(TruffleCompilationThreshold);
class DeoptCountingExceptionOverBoundaryRootNode extends RootNode {
protected DeoptCountingExceptionOverBoundaryRootNode() {
super(null);
}
int deopCounter = 0;
@Override
public Object execute(VirtualFrame frame) {
boolean startedCompiled = CompilerDirectives.inCompiledCode();
throwExceptionBoundary();
if (startedCompiled && CompilerDirectives.inInterpreter()) {
deopCounter++;
}
return null;
}
@CompilerDirectives.TruffleBoundary(transferToInterpreterOnException = false)
public void throwExceptionBoundary() {
throw new RuntimeException();
}
}
final OptimizedCallTarget outerTarget = (OptimizedCallTarget) runtime.createCallTarget(new DeoptCountingExceptionOverBoundaryRootNode());
for (int i = 0; i < compilationThreshold; i++) {
try {
outerTarget.call();
} catch (RuntimeException e) {
// do nothing
}
}
assertCompiled(outerTarget);
final int execCount = 10;
for (int i = 0; i < execCount; i++) {
try {
outerTarget.call();
} catch (RuntimeException e) {
// do nothing
}
}
int deopCount = ((DeoptCountingExceptionOverBoundaryRootNode) outerTarget.getRootNode()).deopCounter;
Assert.assertEquals("Incorrect number of deops detected!", 0, deopCount);
}
Aggregations