use of com.oracle.truffle.api.frame.VirtualFrame in project graal by oracle.
the class InstrumentationEventTest method setUp.
@Before
public final void setUp() {
this.context = Context.create();
this.instrument = context.getEngine().getInstruments().get(InputFilterTestInstrument.ID).lookup(InputFilterTestInstrument.class);
this.instrumenter = instrument.environment.getInstrumenter();
this.events = new ArrayList<>();
this.factory = new ExecutionEventNodeFactory() {
public ExecutionEventNode create(EventContext c) {
return new ExecutionEventNode() {
{
for (int i = 0; i < getInputCount(); i++) {
Assert.assertNotNull(getInputContext(i));
}
}
@Override
protected void onInputValue(VirtualFrame frame, EventContext inputContext, int inputIndex, Object inputValue) {
saveInputValue(frame, inputIndex, inputValue);
assertTrue(inputIndex < getInputCount());
assertSame(inputContext, getInputContext(inputIndex));
events.add(new Event(EventKind.INPUT_VALUE, c, frame, null, null, inputIndex, inputValue, createInputContexts()));
}
@Override
public void onEnter(VirtualFrame frame) {
events.add(new Event(EventKind.ENTER, c, frame, null, null, -1, null, createInputContexts()));
}
@Override
protected void onReturnValue(VirtualFrame frame, Object result) {
events.add(new Event(EventKind.RETURN_VALUE, c, frame, getSavedInputValues(frame), result, -1, null, createInputContexts()));
}
private EventContext[] createInputContexts() {
EventContext[] inputContexts = new EventContext[getInputCount()];
for (int i = 0; i < getInputCount(); i++) {
Assert.assertNotNull(getInputContext(i));
inputContexts[i] = getInputContext(i);
}
return inputContexts;
}
};
}
};
}
use of com.oracle.truffle.api.frame.VirtualFrame in project graal by oracle.
the class InstrumentationMultiThreadingTest method createDummyBindings.
private static EventBinding<?>[] createDummyBindings(Instrumenter instrumenter) {
EventBinding<?>[] bindings = new EventBinding<?>[5];
int bi = 0;
ExecutionEventListener dummyListener = new ExecutionEventListener() {
public void onReturnValue(EventContext context, VirtualFrame frame, Object result) {
}
public void onReturnExceptional(EventContext context, VirtualFrame frame, Throwable exception) {
}
public void onEnter(EventContext context, VirtualFrame frame) {
}
};
bindings[bi++] = instrumenter.attachExecutionEventListener(SourceSectionFilter.newBuilder().tagIs(InstrumentationTestLanguage.EXPRESSION).build(), dummyListener);
bindings[bi++] = instrumenter.attachExecutionEventListener(SourceSectionFilter.newBuilder().tagIs(InstrumentationTestLanguage.STATEMENT).build(), dummyListener);
bindings[bi++] = instrumenter.attachLoadSourceListener(SourceFilter.ANY, new LoadSourceListener() {
public void onLoad(LoadSourceEvent event) {
}
}, true);
bindings[bi++] = instrumenter.attachLoadSourceSectionListener(SourceSectionFilter.newBuilder().tagIs(InstrumentationTestLanguage.EXPRESSION).build(), new LoadSourceSectionListener() {
public void onLoad(LoadSourceSectionEvent event) {
}
}, true);
bindings[bi++] = instrumenter.attachLoadSourceSectionListener(SourceSectionFilter.newBuilder().tagIs(InstrumentationTestLanguage.STATEMENT).build(), new LoadSourceSectionListener() {
public void onLoad(LoadSourceSectionEvent event) {
}
}, true);
return bindings;
}
use of com.oracle.truffle.api.frame.VirtualFrame in project graal by oracle.
the class InstrumentationUpdateTest method setEventFilter.
private void setEventFilter(SourceSectionFilter filter) {
EventBinding<?> old = this.eventBinding;
eventBinding = instrumentEnv.getInstrumenter().attachExecutionEventListener(filter, new ExecutionEventListener() {
public void onReturnValue(EventContext ctx, VirtualFrame frame, Object result) {
}
public void onReturnExceptional(EventContext ctx, VirtualFrame frame, Throwable exception) {
}
public void onEnter(EventContext ctx, VirtualFrame frame) {
executionEvents.add(ctx);
}
});
instrumentEnv.getInstrumenter().attachLoadSourceSectionListener(filter, new LoadSourceSectionListener() {
public void onLoad(LoadSourceSectionEvent event) {
loadEvents.add(event);
}
}, true);
// dispose afterwards to avoid disposal of instrumentation wrappers
if (old != null) {
old.dispose();
}
}
use of com.oracle.truffle.api.frame.VirtualFrame in project graal by oracle.
the class SourceSectionFilterTest method createRootNode.
static RootNode createRootNode(Engine engine, final SourceSection section, final Boolean internal, Node... children) throws Exception {
Language language = engine.getLanguages().get(InstrumentationTestLanguage.ID);
Field impl = Language.class.getDeclaredField("impl");
ReflectionUtils.setAccessible(impl, true);
Object polyglotLanguage = impl.get(language);
Method ensureInitialized = polyglotLanguage.getClass().getDeclaredMethod("ensureInitialized");
ReflectionUtils.setAccessible(ensureInitialized, true);
ensureInitialized.invoke(polyglotLanguage);
Field info = polyglotLanguage.getClass().getDeclaredField("info");
ReflectionUtils.setAccessible(info, true);
LanguageInfo languageInfo = (LanguageInfo) info.get(polyglotLanguage);
Field spi = LanguageInfo.class.getDeclaredField("spi");
ReflectionUtils.setAccessible(spi, true);
TruffleLanguage<?> truffleLanguage = (TruffleLanguage<?>) spi.get(languageInfo);
return new RootNode(truffleLanguage) {
@Node.Children
Node[] rootChildren = children;
@Override
protected boolean isInstrumentable() {
return true;
}
@Override
public SourceSection getSourceSection() {
return section;
}
@Override
public boolean isInternal() {
if (internal == null) {
return super.isInternal();
} else {
return internal;
}
}
@Override
public Object execute(VirtualFrame frame) {
return null;
}
};
}
use of com.oracle.truffle.api.frame.VirtualFrame in project graal by oracle.
the class AllocationReporterPartialEvaluationTest method testConsistentAssertions.
@Test
public void testConsistentAssertions() {
// Test that onEnter()/onReturnValue() are not broken
// when only one of them is compiled with PE.
Context context = Context.newBuilder(AllocationReporterLanguage.ID).build();
context.initialize(AllocationReporterLanguage.ID);
final TestAllocationReporter tester = context.getEngine().getInstruments().get(TestAllocationReporter.ID).lookup(TestAllocationReporter.class);
assertNotNull(tester);
final AllocationReporter reporter = (AllocationReporter) context.getPolyglotBindings().getMember(AllocationReporter.class.getSimpleName()).asHostObject();
final Long[] value = new Long[] { 1L };
OptimizedCallTarget enterTarget = (OptimizedCallTarget) runtime.createCallTarget(new RootNode(null) {
@Override
public Object execute(VirtualFrame frame) {
reporter.onEnter(value[0], 4, 8);
return null;
}
});
OptimizedCallTarget returnTarget = (OptimizedCallTarget) runtime.createCallTarget(new RootNode(null) {
@Override
public Object execute(VirtualFrame frame) {
reporter.onReturnValue(value[0], 4, 8);
return null;
}
});
// Interpret both:
assertNotCompiled(enterTarget);
enterTarget.call();
assertNotCompiled(returnTarget);
returnTarget.call();
value[0]++;
enterTarget.compile();
returnTarget.compile();
assertCompiled(enterTarget);
assertCompiled(returnTarget);
long expectedCounters = allocCounter(value[0]);
assertEquals(expectedCounters, tester.getEnterCount());
assertEquals(expectedCounters, tester.getReturnCount());
for (int j = 0; j < 2; j++) {
// Compile both:
for (int i = 0; i < 5; i++) {
assertCompiled(enterTarget);
enterTarget.call();
assertCompiled(returnTarget);
returnTarget.call();
value[0]++;
}
expectedCounters = allocCounter(value[0]);
assertEquals(expectedCounters, tester.getEnterCount());
assertEquals(expectedCounters, tester.getReturnCount());
// Deoptimize enter:
enterTarget.invalidate(this, "test");
assertNotCompiled(enterTarget);
enterTarget.call();
assertCompiled(returnTarget);
returnTarget.call();
value[0]++;
enterTarget.compile();
returnTarget.compile();
assertCompiled(enterTarget);
assertCompiled(returnTarget);
// Deoptimize return:
returnTarget.invalidate(this, "test");
assertCompiled(enterTarget);
enterTarget.call();
assertNotCompiled(returnTarget);
returnTarget.call();
value[0]++;
enterTarget.compile();
returnTarget.compile();
assertCompiled(enterTarget);
assertCompiled(returnTarget);
// Deoptimize both:
enterTarget.invalidate(this, "test");
returnTarget.invalidate(this, "test");
assertNotCompiled(enterTarget);
enterTarget.call();
assertNotCompiled(returnTarget);
returnTarget.call();
value[0]++;
enterTarget.compile();
returnTarget.compile();
assertCompiled(enterTarget);
assertCompiled(returnTarget);
}
// Check that the allocation calls happened:
expectedCounters = allocCounter(value[0]);
assertEquals(expectedCounters, tester.getEnterCount());
assertEquals(expectedCounters, tester.getReturnCount());
assertCompiled(enterTarget);
assertCompiled(returnTarget);
// Verify that the assertions work in the compiled code:
value[0] = null;
boolean expectedFailure = true;
// Deoptimize for assertions to be active
enterTarget.invalidate(this, "test");
try {
enterTarget.call();
expectedFailure = false;
} catch (AssertionError err) {
// O.K.
}
assertTrue("onEnter(null) did not fail!", expectedFailure);
// Deoptimize for assertions to be active
returnTarget.invalidate(this, "test");
value[0] = Long.MIN_VALUE;
try {
returnTarget.call();
expectedFailure = false;
} catch (AssertionError err) {
// O.K.
}
assertTrue("onReturn(<unseen value>) did not fail!", expectedFailure);
}
Aggregations