use of com.oracle.truffle.api.TruffleRuntime in project graal by oracle.
the class ArgumentsTest method test.
@Test
public void test() {
TruffleRuntime runtime = Truffle.getRuntime();
TestRootNode rootNode = new TestRootNode(new TestArgumentNode[] { new TestArgumentNode(0), new TestArgumentNode(1) });
CallTarget target = runtime.createCallTarget(rootNode);
Object result = target.call(new Object[] { 20, 22 });
Assert.assertEquals(42, result);
}
use of com.oracle.truffle.api.TruffleRuntime in project graal by oracle.
the class AssumptionInvalidationTest method test.
@Test
public void test() throws InterruptedException {
TruffleRuntime runtime = Truffle.getRuntime();
Assumption assumption = runtime.createAssumption("propagated assumption invalidation");
CountingNode countingNode = new CountingNode(assumption);
TestRootNode countingRootNode = new TestRootNode(countingNode);
final CallTarget countingTarget = runtime.createCallTarget(countingRootNode);
Thread thread = new Thread(new Runnable() {
public void run() {
countingTarget.call();
}
});
thread.start();
// Give a chance for CountingNode.execute to OSR compile
Thread.sleep(100);
assumption.invalidate();
thread.join(100);
assertEquals("Thread ought to be notified of invalidation in reasonable time.", false, thread.isAlive());
}
use of com.oracle.truffle.api.TruffleRuntime in project graal by oracle.
the class ChildNodeTest method test.
@Test
public void test() {
TruffleRuntime runtime = Truffle.getRuntime();
TestChildNode leftChild = new TestChildNode();
TestChildNode rightChild = new TestChildNode();
TestRootNode rootNode = new TestRootNode(leftChild, rightChild);
CallTarget target = runtime.createCallTarget(rootNode);
assertEquals(rootNode, leftChild.getParent());
assertEquals(rootNode, rightChild.getParent());
Iterator<Node> iterator = rootNode.getChildren().iterator();
assertEquals(leftChild, iterator.next());
assertEquals(rightChild, iterator.next());
assertFalse(iterator.hasNext());
Object result = target.call();
assertEquals(42, result);
}
use of com.oracle.truffle.api.TruffleRuntime in project graal by oracle.
the class Target_com_oracle_truffle_api_interop_java_ObjectProxyHandler method beforeAnalysis.
@SuppressWarnings("deprecation")
@Override
public void beforeAnalysis(BeforeAnalysisAccess access) {
BeforeAnalysisAccessImpl config = (BeforeAnalysisAccessImpl) access;
getLanguageClasses().forEach(config::registerForReflectiveInstantiation);
config.registerHierarchyForReflectiveInstantiation(TruffleInstrument.class);
config.registerHierarchyForReflectiveInstantiation(com.oracle.truffle.api.instrumentation.InstrumentableFactory.class);
if (useTruffleCompiler()) {
SubstrateTruffleRuntime truffleRuntime = (SubstrateTruffleRuntime) Truffle.getRuntime();
GraalFeature graalFeature = ImageSingletons.lookup(GraalFeature.class);
SnippetReflectionProvider snippetReflection = graalFeature.getHostedProviders().getSnippetReflection();
SubstrateTruffleCompiler truffleCompiler = truffleRuntime.initTruffleCompiler();
truffleRuntime.lookupCallMethods(config.getMetaAccess());
PartialEvaluator partialEvaluator = truffleCompiler.getPartialEvaluator();
registerKnownTruffleFields(config, partialEvaluator.getKnownTruffleTypes());
support.registerInterpreterEntryMethodsAsCompiled(partialEvaluator, access);
GraphBuilderConfiguration graphBuilderConfig = partialEvaluator.getConfigForParsing();
if (Options.TruffleInlineDuringParsing.getValue()) {
graphBuilderConfig.getPlugins().appendInlineInvokePlugin(new TruffleParsingInlineInvokePlugin(graalFeature.getHostedProviders().getReplacements(), graphBuilderConfig.getPlugins().getInvocationPlugins(), partialEvaluator, method -> includeCallee(method, null, null)));
}
registerNeverPartOfCompilation(graphBuilderConfig.getPlugins().getInvocationPlugins());
graphBuilderConfig.getPlugins().getInvocationPlugins().closeRegistration();
HostedProviders newHostedProviders = new HostedProviders(partialEvaluator.getProviders().getMetaAccess(), partialEvaluator.getProviders().getCodeCache(), partialEvaluator.getProviders().getConstantReflection(), new HostedTruffleConstantFieldProvider(partialEvaluator.getProviders().getConstantFieldProvider()), partialEvaluator.getProviders().getForeignCalls(), partialEvaluator.getProviders().getLowerer(), partialEvaluator.getProviders().getReplacements(), partialEvaluator.getProviders().getStampProvider(), snippetReflection, graalFeature.getHostedProviders().getWordTypes());
newHostedProviders.setGraphBuilderPlugins(graphBuilderConfig.getPlugins());
graalFeature.initializeRuntimeCompilationConfiguration(newHostedProviders, graphBuilderConfig, this::includeCallee, this::deoptimizeOnException);
for (ResolvedJavaMethod method : partialEvaluator.getCompilationRootMethods()) {
graalFeature.prepareMethodForRuntimeCompilation(method, config);
}
initializeMethodBlacklist(config.getMetaAccess());
/*
* Stack frames that are visited by Truffle-level stack walking must have full frame
* information available, otherwise SubstrateStackIntrospection cannot visit them.
*/
for (ResolvedJavaMethod method : truffleRuntime.getAnyFrameMethod()) {
graalFeature.requireFrameInformationForMethod(method);
/*
* To avoid corner case errors, we also force compilation of these methods. This
* only affects builds where no Truffle language is included, because any real
* language makes these methods reachable (and therefore compiled).
*/
config.registerAsCompiled((AnalysisMethod) method);
}
}
firstAnalysisRun = true;
}
use of com.oracle.truffle.api.TruffleRuntime in project graal by oracle.
the class Target_com_oracle_truffle_api_interop_java_ObjectProxyHandler method afterRegistration.
@Override
public void afterRegistration(AfterRegistrationAccess a) {
if (support == null) {
support = new Support();
}
TruffleRuntime runtime = Truffle.getRuntime();
UserError.guarantee(runtime != null, "TruffleRuntime not available via Truffle.getRuntime()");
UserError.guarantee(runtime instanceof SubstrateTruffleRuntime || runtime instanceof DefaultTruffleRuntime, "Unsupported TruffleRuntime " + runtime.getName() + " (only SubstrateTruffleRuntime or DefaultTruffleRuntime allowed)");
if (useTruffleCompiler()) {
SubstrateTruffleRuntime truffleRuntime = (SubstrateTruffleRuntime) runtime;
truffleRuntime.resetHosted();
}
/* sun.nio.fs.GnomeFileTypeDetector is currently not supported (GR-4863) */
AfterRegistrationAccessImpl access = (AfterRegistrationAccessImpl) a;
access.findSubclasses(FileTypeDetector.class).stream().filter(detector -> !detector.getClass().getName().equals("sun.nio.fs.GnomeFileTypeDetector")).filter(detector -> !Modifier.isAbstract(detector.getModifiers())).forEach(this::safeLoadFileDetector);
initializeTruffleReflectively(Thread.currentThread().getContextClassLoader());
}
Aggregations