use of org.graalvm.compiler.hotspot.CompilationContext in project graal by oracle.
the class TruffleToLibGraalEntryPoints method doCompile.
@TruffleToLibGraal(DoCompile)
@SuppressWarnings({ "unused", "try" })
@CEntryPoint(name = "Java_org_graalvm_compiler_truffle_runtime_hotspot_libgraal_TruffleToLibGraalCalls_doCompile")
public static void doCompile(JNIEnv env, JClass hsClazz, @CEntryPoint.IsolateThreadContext long isolateThreadId, long compilerHandle, long debugContextHandle, long compilationHandle, JByteArray hsOptions, JObject hsTask, JObject hsListener) {
try (JNIMethodScope scope = LibGraalUtil.openScope(TruffleToLibGraalEntryPoints.class, DoCompile, env)) {
TruffleCompilationIdentifier compilation = LibGraalObjectHandles.resolve(compilationHandle, TruffleCompilationIdentifier.class);
try (CompilationContext hotSpotObjectConstantScope = HotSpotGraalServices.openLocalCompilationContext(compilation)) {
HotSpotTruffleCompilerImpl compiler = LibGraalObjectHandles.resolve(compilerHandle, HotSpotTruffleCompilerImpl.class);
TruffleDebugContext debugContext = LibGraalObjectHandles.resolve(debugContextHandle, TruffleDebugContext.class);
Map<String, Object> options = decodeOptions(env, hsOptions);
TruffleCompilationTask task = hsTask.isNull() ? null : new HSTruffleCompilationTask(hsTask);
TruffleCompilerListener listener = hsListener.isNull() ? null : new HSTruffleCompilerListener(scope, hsListener);
compiler.doCompile(debugContext, compilation, options, task, listener);
}
} catch (Throwable t) {
JNIExceptionWrapper.throwInHotSpot(env, t);
}
}
use of org.graalvm.compiler.hotspot.CompilationContext in project graal by oracle.
the class LibGraalEntryPoints method compileMethod.
/**
* The implementation of
* {@code org.graalvm.compiler.hotspot.test.CompileTheWorld.compileMethodInLibgraal()}.
*
* @param methodHandle the method to be compiled. This is a handle to a
* {@link HotSpotResolvedJavaMethod} in HotSpot's heap. A value of 0L can be passed
* to use this method for the side effect of initializing a
* {@link HotSpotGraalCompiler} instance without doing any compilation.
* @param useProfilingInfo specifies if profiling info should be used during the compilation
* @param installAsDefault specifies if the compiled code should be installed for the
* {@code Method*} associated with {@code methodHandle}
* @param printMetrics specifies if global metrics should be printed and reset
* @param optionsAddress native byte buffer storing a serialized {@link OptionValues} object
* @param optionsSize the number of bytes in the buffer
* @param optionsHash hash code of bytes in the buffer (computed with
* {@link Arrays#hashCode(byte[])})
* @param stackTraceAddress a native buffer in which a serialized stack trace can be returned.
* The caller will only read from this buffer if this method returns 0. A returned
* serialized stack trace is returned in this buffer with the following format:
*
* <pre>
* struct {
* int length;
* byte data[length]; // Bytes from a stack trace printed to a ByteArrayOutputStream.
* }
* </pre>
*
* where {@code length} truncated to {@code stackTraceCapacity - 4} if necessary
*
* @param stackTraceCapacity the size of the stack trace buffer
* @return a handle to a {@link InstalledCode} in HotSpot's heap or 0 if compilation failed
*/
@SuppressWarnings({ "unused", "try" })
@CEntryPoint(name = "Java_org_graalvm_compiler_hotspot_test_CompileTheWorld_compileMethodInLibgraal", include = LibGraalFeature.IsEnabled.class)
private static long compileMethod(PointerBase jniEnv, PointerBase jclass, @CEntryPoint.IsolateThreadContext long isolateThread, long methodHandle, boolean useProfilingInfo, boolean installAsDefault, boolean printMetrics, long optionsAddress, int optionsSize, int optionsHash, long stackTraceAddress, int stackTraceCapacity) {
try {
HotSpotJVMCIRuntime runtime = runtime();
HotSpotGraalCompiler compiler = (HotSpotGraalCompiler) runtime.getCompiler();
if (methodHandle == 0L) {
return 0L;
}
HotSpotResolvedJavaMethod method = LibGraal.unhand(HotSpotResolvedJavaMethod.class, methodHandle);
int entryBCI = JVMCICompiler.INVOCATION_ENTRY_BCI;
HotSpotCompilationRequest request = new HotSpotCompilationRequest(method, entryBCI, 0L);
try (CompilationContext scope = HotSpotGraalServices.openLocalCompilationContext(request)) {
OptionValues options = decodeOptions(optionsAddress, optionsSize, optionsHash);
CompilationTask task = new CompilationTask(runtime, compiler, request, useProfilingInfo, installAsDefault);
task.runCompilation(options);
HotSpotInstalledCode installedCode = task.getInstalledCode();
if (printMetrics) {
GlobalMetrics metricValues = ((HotSpotGraalRuntime) compiler.getGraalRuntime()).getMetricValues();
metricValues.print(options);
metricValues.clear();
}
return LibGraal.translate(installedCode);
}
} catch (Throwable t) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
t.printStackTrace(new PrintStream(baos));
byte[] stackTrace = baos.toByteArray();
int length = Math.min(stackTraceCapacity - Integer.BYTES, stackTrace.length);
UNSAFE.putInt(stackTraceAddress, length);
UNSAFE.copyMemory(stackTrace, ARRAY_BYTE_BASE_OFFSET, null, stackTraceAddress + Integer.BYTES, length);
return 0L;
} finally {
/*
* libgraal doesn't use a dedicated reference handler thread, so we trigger the
* reference handling manually when a compilation finishes.
*/
Heap.getHeap().doReferenceHandling();
}
}
Aggregations