本文整理汇总了Java中com.oracle.truffle.api.Truffle类的典型用法代码示例。如果您正苦于以下问题:Java Truffle类的具体用法?Java Truffle怎么用?Java Truffle使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Truffle类属于com.oracle.truffle.api包,在下文中一共展示了Truffle类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: Context
import com.oracle.truffle.api.Truffle; //导入依赖的package包/类
public Context(Language language, TruffleLanguage.Env env) {
this.language = language;
this.globalFrame = Truffle.getRuntime().createMaterializedFrame(null);
this.functions = new HashMap<>();
set("*language*", "Java");
set("*implementation*", "Truffle / " + Truffle.getRuntime().getName());
set("*porters*", new String("Ragnar Dahlén".getBytes(), Charset.forName("ISO-8859-1")));
set("*port*", "0.1");
set("*stinput*", env.in());
set("*stoutput*", env.out());
set("*home-directory*", System.getProperty("user.dir"));
for(NodeFactory nodeFactory : Builtins.NODE_FACTORIES) {
installBuiltin(nodeFactory);
}
}
示例2: installBuiltin
import com.oracle.truffle.api.Truffle; //导入依赖的package包/类
public void installBuiltin(NodeFactory<? extends BuiltinNode> factory) {
int argumentCount = factory.getExecutionSignature().size();
ExpressionNode[] argumentNodes = new ExpressionNode[argumentCount];
for (int i = 0; i < argumentCount; i++) {
argumentNodes[i] = new ReadArgumentNode(i+1);
}
BuiltinNode builtinBodyNode = factory.createNode(argumentNodes, this);
//builtinBodyNode.addRootTag();
/* The name of the builtin function is specified via an annotation on the node class. */
String name = lookupNodeInfo(builtinBodyNode.getClass()).shortName();
//final SourceSection srcSection = BUILTIN_SOURCE.createUnavailableSection();
//builtinBodyNode.setSourceSection(srcSection);
RootNode rootNode = new RootNode(language, new FrameDescriptor(), builtinBodyNode, name);
Function f = new Function(Truffle.getRuntime().createCallTarget(rootNode), argumentCount);
f.setName(name);
registerFunction(name, f);
}
示例3: addNodeFactories
import com.oracle.truffle.api.Truffle; //导入依赖的package包/类
private void addNodeFactories(List<? extends NodeFactory<? extends HBNode>> factories) {
for (NodeFactory<? extends HBNode> factory : factories) {
Class<?> nodeClass = factory.getClass().getAnnotation(GeneratedBy.class).value();
BuiltinMethod methodAnnotation = this.getMethodAnnotation(nodeClass);
BuiltinClass classAnnotation = this.getClassAnnotation(nodeClass);
String methodName = methodAnnotation.value();
String className = classAnnotation.value();
MethodTargets methodTargets = this.getOrCreateMethodTargets(className);
HBNode bodyNode = this.createNode(factory, methodAnnotation);
HBBuiltinRootNode rootNode = new HBBuiltinRootNode(
this.language,
new FrameDescriptor(),
bodyNode
);
CallTarget callTarget = Truffle.getRuntime().createCallTarget(rootNode);
methodTargets.put(methodName, callTarget);
}
}
示例4: parse
import com.oracle.truffle.api.Truffle; //导入依赖的package包/类
@Override
protected CallTarget parse(ParsingRequest request) throws Exception {
Source source = request.getSource();
HBSourceRootNode program = ParserWrapper.parse(this, source);
System.out.println(program.toString());
// Bootstrap the builtin node targets and the builtin types in the
// type-system.
BuiltinNodes builtinNodes = BuiltinNodes.bootstrap(this);
Index index = Index.bootstrap(builtinNodes);
InferenceVisitor visitor = new InferenceVisitor(index);
program.accept(visitor);
return Truffle.getRuntime().createCallTarget(program);
}
示例5: findDuplicateCallTargets
import com.oracle.truffle.api.Truffle; //导入依赖的package包/类
/**
* Finds all call targets available for the same original call target. This might be useful if a
* {@link CallTarget} got duplicated due to splitting.
*/
@SuppressWarnings("deprecation")
@TruffleBoundary
protected static final Set<OptimizedCallTarget> findDuplicateCallTargets(OptimizedCallTarget originalCallTarget) {
final Set<OptimizedCallTarget> allCallTargets = new HashSet<>();
allCallTargets.add(originalCallTarget);
for (RootCallTarget target : Truffle.getRuntime().getCallTargets()) {
if (target instanceof OptimizedCallTarget) {
OptimizedCallTarget oct = (OptimizedCallTarget) target;
if (oct.getSourceCallTarget() == originalCallTarget) {
allCallTargets.add(oct);
}
}
}
return allCallTargets;
}
示例6: twoIfsTest
import com.oracle.truffle.api.Truffle; //导入依赖的package包/类
@Test
public void twoIfsTest() {
InstrumentPhase.Instrumentation instrumentation = ((GraalTruffleRuntime) Truffle.getRuntime()).getInstrumentation();
FrameDescriptor descriptor = new FrameDescriptor();
TwoIfsTestNode result = new TwoIfsTestNode(5, -1);
RootTestNode rootNode = new RootTestNode(descriptor, "twoIfsRoot", result);
OptimizedCallTarget target = compileHelper("twoIfsRoot", rootNode, new Object[0]);
Assert.assertTrue(target.isValid());
// We run this twice to make sure that it comes first in the sorted access list.
target.call();
target.call();
String stackOutput1 = instrumentation.accessTableToList(getOptions()).get(0);
Assert.assertTrue(stackOutput1.contains("org.graalvm.compiler.truffle.test.InstrumentBranchesPhaseTest$TwoIfsTestNode.execute(InstrumentBranchesPhaseTest.java"));
Assert.assertTrue(stackOutput1.contains("[bci: 4]\n[1] state = ELSE(if=0#, else=2#)"));
String stackOutput2 = instrumentation.accessTableToList(getOptions()).get(1);
Assert.assertTrue(stackOutput2.contains("org.graalvm.compiler.truffle.test.InstrumentBranchesPhaseTest$TwoIfsTestNode.execute(InstrumentBranchesPhaseTest.java"));
Assert.assertTrue(stackOutput2.contains("[bci: 18]\n[2] state = IF(if=2#, else=0#)"));
}
示例7: testCanBeClonedWithoutParent
import com.oracle.truffle.api.Truffle; //导入依赖的package包/类
@Test
public void testCanBeClonedWithoutParent() {
final RootNode rootNode = new RootNode(null) {
@Override
public Object execute(VirtualFrame frame) {
return 42;
}
@Override
public boolean isCloningAllowed() {
return true;
}
};
final CallTarget callTarget = Truffle.getRuntime().createCallTarget(rootNode);
final DirectCallNode callNode = Truffle.getRuntime().createDirectCallNode(callTarget);
assertTrue(callNode.isCallTargetCloningAllowed());
assertTrue(callNode.cloneCallTarget());
}
示例8: checkStackTrace
import com.oracle.truffle.api.Truffle; //导入依赖的package包/类
@TruffleBoundary
private void checkStackTrace() {
final OptimizedOSRLoopNode loop = (OptimizedOSRLoopNode) getParent();
final OptimizedCallTarget compiledLoop = loop.getCompiledOSRLoop();
Truffle.getRuntime().iterateFrames(new FrameInstanceVisitor<Void>() {
@Override
public Void visitFrame(FrameInstance frameInstance) {
Assert.assertNotSame(compiledLoop, frameInstance.getCallTarget());
return null;
}
});
}
示例9: TruffleCompiler
import com.oracle.truffle.api.Truffle; //导入依赖的package包/类
public TruffleCompiler(Plugins plugins, Suites suites, LIRSuites lirSuites, Backend backend, SnippetReflectionProvider snippetReflection) {
GraalTruffleRuntime graalTruffleRuntime = ((GraalTruffleRuntime) Truffle.getRuntime());
this.compilationNotify = graalTruffleRuntime.getCompilationNotify();
this.backend = backend;
this.snippetReflection = snippetReflection;
this.providers = backend.getProviders();
this.suites = suites;
this.lirSuites = lirSuites;
ResolvedJavaType[] skippedExceptionTypes = getSkippedExceptionTypes(providers.getMetaAccess());
boolean needSourcePositions = graalTruffleRuntime.enableInfopoints() || TruffleCompilerOptions.getValue(TruffleEnableInfopoints) ||
TruffleCompilerOptions.getValue(TruffleInstrumentBranches) || TruffleCompilerOptions.getValue(TruffleInstrumentBoundaries);
GraphBuilderConfiguration baseConfig = GraphBuilderConfiguration.getDefault(new Plugins(plugins)).withNodeSourcePosition(needSourcePositions);
this.config = baseConfig.withSkippedExceptionTypes(skippedExceptionTypes).withOmitAssertions(TruffleCompilerOptions.getValue(TruffleExcludeAssertions)).withBytecodeExceptionMode(
BytecodeExceptionMode.ExplicitOnly);
this.partialEvaluator = createPartialEvaluator();
if (Debug.isEnabled()) {
DebugEnvironment.ensureInitialized(TruffleCompilerOptions.getOptions(), graalTruffleRuntime.getRequiredGraalCapability(SnippetReflectionProvider.class));
}
graalTruffleRuntime.reinstallStubs();
}
示例10: propagateLoopCount
import com.oracle.truffle.api.Truffle; //导入依赖的package包/类
public static void propagateLoopCount(final long count) {
CompilerAsserts.neverPartOfCompilation("Primitive.pLC(.)");
// we need to skip the primitive and get to the method that called the primitive
FrameInstance caller = Truffle.getRuntime().getCallerFrame();
RootCallTarget ct = (RootCallTarget) caller.getCallTarget(); // caller method
Invokable m = (Invokable) ct.getRootNode();
if (m instanceof Primitive) {
// the caller is a primitive, that doesn't help, we need to skip it and
// find a proper method
m = getNextMethodOnStack();
}
if (m != null && !(m instanceof Primitive)) {
m.propagateLoopCountThroughoutMethodScope(count);
}
}
示例11: AbstractWhileNode
import com.oracle.truffle.api.Truffle; //导入依赖的package包/类
public AbstractWhileNode(final SBlock rcvr, final SBlock arg,
final boolean predicateBool, final SourceSection source) {
super(false, source);
CallTarget callTargetCondition = rcvr.getMethod().getCallTarget();
conditionValueSend = Truffle.getRuntime().createDirectCallNode(
callTargetCondition);
CallTarget callTargetBody = arg.getMethod().getCallTarget();
bodyValueSend = Truffle.getRuntime().createDirectCallNode(
callTargetBody);
this.predicateBool = predicateBool;
}
示例12: IfTrueIfFalseMessageNode
import com.oracle.truffle.api.Truffle; //导入依赖的package包/类
public IfTrueIfFalseMessageNode(final IfTrueIfFalseMessageNode node) {
super(false, node.sourceSection);
trueMethod = node.trueMethod;
if (node.trueMethod != null) {
trueValueSend = Truffle.getRuntime().createDirectCallNode(
trueMethod.getCallTarget());
}
falseMethod = node.falseMethod;
if (node.falseMethod != null) {
falseValueSend = Truffle.getRuntime().createDirectCallNode(
falseMethod.getCallTarget());
}
call = Truffle.getRuntime().createIndirectCallNode();
}
示例13: main
import com.oracle.truffle.api.Truffle; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
CharStream in = new ANTLRInputStream(new FileInputStream(args[0]));
TuberBasicLexer lexer = new TuberBasicLexer(in);
TokenStream tokens = new CommonTokenStream(lexer);
TuberBasicParser parser = new TuberBasicParser(tokens);
ParserRuleContext tree = parser.statements();
Visitor visitor = new Visitor();
TuberNode ast = visitor.visit(tree);
TruffleRuntime runtime = Truffle.getRuntime();
TuberRootNode rootNode = new TuberRootNode(ast);
CallTarget target = runtime.createCallTarget(rootNode);
Object result = target.call();
System.out.println(result);
}
示例14: stackDepth
import com.oracle.truffle.api.Truffle; //导入依赖的package包/类
public static int stackDepth() {
final StringBuilder str = new StringBuilder();
Truffle.getRuntime().iterateFrames(new FrameInstanceVisitor<Integer>() {
@Override
public Integer visitFrame(FrameInstance frameInstance) {
CallTarget callTarget = frameInstance.getCallTarget();
RootNode rn = ((RootCallTarget) callTarget).getRootNode();
if (rn.getClass().getName().contains("DynSemRuleForeignAccess")) {
return 1;
}
str.append(" ");
return null;
}
});
return str.length();
}
示例15: execute
import com.oracle.truffle.api.Truffle; //导入依赖的package包/类
@ExplodeLoop
public RuleResult execute(final Object[] arguments) {
CompilerAsserts.compilationConstant(rules.length);
PatternMatchFailure lastFailure = null;
for (int i = 0; i < rules.length; i++) {
try {
final Rule r = rules[i];
return r.execute(Truffle.getRuntime().createVirtualFrame(arguments, r.getFrameDescriptor()));
} catch (PatternMatchFailure pmfx) {
lastFailure = pmfx;
}
}
// there are no rules or all rules have failed. we throw a soft exception to allow alternative rules to be tried
if (lastFailure != null) {
throw lastFailure;
} else {
throw PatternMatchFailure.INSTANCE;
}
}