use of org.graalvm.nativeimage.Platforms in project graal by oracle.
the class EncodedLineNumberTable method encode.
@Platforms(Platform.HOSTED_ONLY.class)
public static byte[] encode(LineNumberTable table) {
if (table == null) {
return null;
}
int[] lineNumbers = table.getLineNumbers();
int[] bcis = table.getBcis();
assert lineNumbers.length == bcis.length;
UnsafeArrayTypeWriter encodingBuffer = UnsafeArrayTypeWriter.create(ByteArrayReader.supportsUnalignedMemoryAccess());
int lastLineNumber = 0;
int lastBci = 0;
encodingBuffer.putUV(lineNumbers.length);
for (int i = 0; i < lineNumbers.length; i++) {
encodingBuffer.putSV(lineNumbers[i] - lastLineNumber);
encodingBuffer.putSV(bcis[i] - lastBci);
lastLineNumber = lineNumbers[i];
lastBci = bcis[i];
}
byte[] encodedTable = encodingBuffer.toArray(new byte[TypeConversion.asS4(encodingBuffer.getBytesWritten())]);
assert verifyTable(table, decode(encodedTable));
return encodedTable;
}
use of org.graalvm.nativeimage.Platforms in project graal by oracle.
the class SubstrateReplacements method registerSnippet.
/**
* Compiles the snippet and stores the graph.
*/
@Platforms(Platform.HOSTED_ONLY.class)
@Override
public void registerSnippet(ResolvedJavaMethod method, boolean trackNodeSourcePosition) {
assert method.getAnnotation(Snippet.class) != null : "Snippet must be annotated with @" + Snippet.class.getSimpleName();
assert method.hasBytecodes() : "Snippet must not be abstract or native";
assert builder.graphs.get(method) == null : "snippet registered twice: " + method.getName();
try (DebugContext debug = openDebugContext("Snippet_", method)) {
StructuredGraph graph = makeGraph(debug, defaultBytecodeProvider, method, null, null, trackNodeSourcePosition, null);
// Check if all methods which should be inlined are really inlined.
for (MethodCallTargetNode callTarget : graph.getNodes(MethodCallTargetNode.TYPE)) {
ResolvedJavaMethod callee = callTarget.targetMethod();
if (!builder.delayedInvocationPluginMethods.contains(callee)) {
throw shouldNotReachHere("method " + callee.getName() + " not inlined in snippet " + method.getName() + " (maybe not final?)");
}
}
builder.graphs.put(method, graph);
}
}
use of org.graalvm.nativeimage.Platforms in project graal by oracle.
the class SubstrateReplacements method makeInvocationPlugins.
@Platforms(Platform.HOSTED_ONLY.class)
private static InvocationPlugins makeInvocationPlugins(GraphBuilderConfiguration.Plugins plugins, Builder builder, Function<Object, Object> objectReplacer) {
Map<ResolvedJavaMethod, InvocationPlugin> result = new HashMap<>(builder.delayedInvocationPluginMethods.size());
for (ResolvedJavaMethod method : builder.delayedInvocationPluginMethods) {
ResolvedJavaMethod replacedMethod = (ResolvedJavaMethod) objectReplacer.apply(method);
InvocationPlugin plugin = plugins.getInvocationPlugins().lookupInvocation(replacedMethod);
assert plugin != null : "expected invocation plugin for " + replacedMethod;
result.put(replacedMethod, plugin);
}
return new InvocationPlugins(result, null);
}
use of org.graalvm.nativeimage.Platforms in project graal by oracle.
the class SubstrateReplacements method encodeSnippets.
@Platforms(Platform.HOSTED_ONLY.class)
public void encodeSnippets() {
GraphEncoder encoder = new GraphEncoder(ConfigurationValues.getTarget().arch);
for (StructuredGraph graph : builder.graphs.values()) {
encoder.prepare(graph);
}
encoder.finishPrepare();
snippetStartOffsets = new HashMap<>();
for (Map.Entry<ResolvedJavaMethod, StructuredGraph> entry : builder.graphs.entrySet()) {
snippetStartOffsets.put(entry.getKey(), encoder.encode(entry.getValue()));
}
snippetEncoding = encoder.getEncoding();
snippetObjects = encoder.getObjects();
snippetNodeClasses = encoder.getNodeClasses();
snippetInvocationPlugins = makeInvocationPlugins(getGraphBuilderPlugins(), builder, Function.identity());
}
use of org.graalvm.nativeimage.Platforms in project graal by oracle.
the class SubstrateTruffleRuntime method initTruffleCompiler.
@Platforms(Platform.HOSTED_ONLY.class)
public SubstrateTruffleCompiler initTruffleCompiler() {
assert truffleCompiler == null : "Cannot re-initialize Substrate TruffleCompiler";
GraalFeature graalFeature = ImageSingletons.lookup(GraalFeature.class);
SnippetReflectionProvider snippetReflection = graalFeature.getHostedProviders().getSnippetReflection();
SubstrateTruffleCompiler compiler = new SubstrateTruffleCompiler(this, graalFeature.getHostedProviders().getGraphBuilderPlugins(), GraalSupport.getSuites(), GraalSupport.getLIRSuites(), GraalSupport.getRuntimeConfig().getBackendForNormalMethod(), snippetReflection);
truffleCompiler = compiler;
return compiler;
}
Aggregations