Skip to content

Commit

Permalink
Automatic merge of master into galahad
Browse files Browse the repository at this point in the history
  • Loading branch information
OracleLabsAutomation committed May 27, 2024
2 parents 8117fee + b4c2ef5 commit ceaac5f
Show file tree
Hide file tree
Showing 24 changed files with 320 additions and 92 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.util.concurrent.CyclicBarrier;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.function.Supplier;
import java.util.logging.Handler;
import java.util.logging.LogRecord;

Expand Down Expand Up @@ -94,7 +95,7 @@ public void onCompilationSuccess(OptimizedCallTarget target, AbstractCompilation
}

@Override
public void onCompilationFailed(OptimizedCallTarget target, String reason, boolean bailout, boolean permanentBailout, int tier) {
public void onCompilationFailed(OptimizedCallTarget target, String reason, boolean bailout, boolean permanentBailout, int tier, Supplier<String> serializedException) {
TTY.printf(FORMAT_FAILURE, target.getName(), reason);
printCommon();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.function.Supplier;

import com.oracle.truffle.api.test.SubprocessTestUtils;
import com.oracle.truffle.compiler.TruffleCompilerListener;
Expand Down Expand Up @@ -425,7 +426,7 @@ public void onCompilationSuccess(OptimizedCallTarget target, AbstractCompilation
}

@Override
public void onCompilationFailed(OptimizedCallTarget target, String reason, boolean bailout, boolean permanentBailout, int tier) {
public void onCompilationFailed(OptimizedCallTarget target, String reason, boolean bailout, boolean permanentBailout, int tier, Supplier<String> serializedException) {
if ((isImportant(target))) {
events.add(EventType.COMPILATION_FAILURE);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,6 @@ public void onTruffleTierFinished(TruffleCompilable compilable, TruffleCompilati
@Override
public void onGraalTierFinished(TruffleCompilable compilable, GraphInfo graph) {
}

@Override
public void onSuccess(TruffleCompilable compilable, TruffleCompilationTask task, GraphInfo graphInfo, CompilationResultInfo compilationResultInfo, int tier) {
}

@Override
public void onFailure(TruffleCompilable compilable, String reason, boolean bailout, boolean permanentBailout, int tier) {
}
}

private static class TestTruffleCompilationTask implements TruffleCompilationTask {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ private void compileAST(TruffleCompilationWrapper wrapper, DebugContext debug) {
if (wrapper.listener != null) {
BailoutException bailout = t instanceof BailoutException ? (BailoutException) t : null;
boolean permanentBailout = bailout != null ? bailout.isPermanent() : false;
wrapper.listener.onFailure(compilable, t.toString(), bailout != null, permanentBailout, task.tier());
wrapper.listener.onFailure(compilable, t.toString(), bailout != null, permanentBailout, task.tier(), bailout != null ? null : () -> TruffleCompilable.serializeException(t));
}
throw t;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import static org.graalvm.jniutils.JNIUtil.createHSString;

import java.io.Closeable;
import java.util.function.Supplier;

import org.graalvm.jniutils.HSObject;
import org.graalvm.jniutils.JNI.JNIEnv;
Expand Down Expand Up @@ -98,11 +99,13 @@ public void onGraalTierFinished(TruffleCompilable compilable, GraphInfo graph) {

@TruffleFromLibGraal(OnFailure)
@Override
public void onFailure(TruffleCompilable compilable, String serializedException, boolean bailout, boolean permanentBailout, int tier) {
JObject hsCompilable = ((HSTruffleCompilable) compilable).getHandle();
JNIEnv env = JNIMethodScope.env();
JString hsReason = createHSString(env, serializedException);
callOnFailure(calls, env, getHandle(), hsCompilable, hsReason, bailout, permanentBailout, tier);
public void onFailure(TruffleCompilable compilable, String reason, boolean bailout, boolean permanentBailout, int tier, Supplier<String> lazyStackTrace) {
try (LibGraalObjectHandleScope lazyStackTraceScope = lazyStackTrace != null ? LibGraalObjectHandleScope.forObject(lazyStackTrace) : null) {
JObject hsCompilable = ((HSTruffleCompilable) compilable).getHandle();
JNIEnv env = JNIMethodScope.env();
JString hsReason = createHSString(env, reason);
callOnFailure(calls, env, getHandle(), hsCompilable, hsReason, bailout, permanentBailout, tier, lazyStackTraceScope != null ? lazyStackTraceScope.getHandle() : 0L);
}
}

@TruffleFromLibGraal(OnCompilationRetry)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,24 +170,10 @@ private static ClientHandle<SpeculationLog> getCompilationSpeculationLog0(@Suppr
@CEntryPoint(include = CEntryPoint.NotIncludedAutomatically.class, publishAs = CEntryPoint.Publish.NotPublished)
private static void onCompilationFailed0(@SuppressWarnings("unused") ClientIsolateThread client, ClientHandle<SubstrateCompilableTruffleAST> compilableHandle,
CompilerHandle<Supplier<String>> serializedExceptionHandle, boolean silent, boolean bailout, boolean permanentBailout, boolean graphTooBig) {

Supplier<String> serializedException = new Supplier<>() {
@Override
public String get() {
ClientHandle<String> resultHandle = getReasonAndStackTrace0(IsolatedCompileClient.get().getCompiler(), serializedExceptionHandle);
return IsolatedCompileClient.get().unhand(resultHandle);
}
};
Supplier<String> serializedException = new IsolatedStringSupplier(serializedExceptionHandle);
IsolatedCompileClient.get().unhand(compilableHandle).onCompilationFailed(serializedException, silent, bailout, permanentBailout, graphTooBig);
}

@CEntryPoint(include = CEntryPoint.NotIncludedAutomatically.class, publishAs = CEntryPoint.Publish.NotPublished)
private static ClientHandle<String> getReasonAndStackTrace0(@SuppressWarnings("unused") CompilerIsolateThread compiler, CompilerHandle<Supplier<String>> reasonAndStackTraceHandle) {

Supplier<String> supplier = IsolatedCompileContext.get().unhand(reasonAndStackTraceHandle);
return IsolatedCompileContext.get().createStringInClient(supplier.get());
}

@CEntryPoint(include = CEntryPoint.NotIncludedAutomatically.class, publishAs = CEntryPoint.Publish.NotPublished)
private static CompilerHandle<String> getName0(@SuppressWarnings("unused") ClientIsolateThread client, ClientHandle<SubstrateCompilableTruffleAST> compilableHandle) {
String name = IsolatedCompileClient.get().unhand(compilableHandle).getName();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Copyright (c) 2024, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.oracle.svm.truffle.isolated;

import com.oracle.svm.graal.isolated.ClientHandle;
import com.oracle.svm.graal.isolated.CompilerHandle;
import com.oracle.svm.graal.isolated.CompilerIsolateThread;
import com.oracle.svm.graal.isolated.IsolatedCompileClient;
import com.oracle.svm.graal.isolated.IsolatedCompileContext;
import org.graalvm.nativeimage.c.function.CEntryPoint;

import java.util.function.Supplier;

final class IsolatedStringSupplier implements Supplier<String> {

private final CompilerHandle<Supplier<String>> originalObjectHandle;

IsolatedStringSupplier(CompilerHandle<Supplier<String>> originalObjectHandle) {
this.originalObjectHandle = originalObjectHandle;
}

@Override
public String get() {
ClientHandle<String> resultHandle = getReasonAndStackTrace0(IsolatedCompileClient.get().getCompiler(), originalObjectHandle);
return IsolatedCompileClient.get().unhand(resultHandle);
}

@CEntryPoint(include = CEntryPoint.NotIncludedAutomatically.class, publishAs = CEntryPoint.Publish.NotPublished)
private static ClientHandle<String> getReasonAndStackTrace0(@SuppressWarnings("unused") CompilerIsolateThread compiler, CompilerHandle<Supplier<String>> reasonAndStackTraceHandle) {
Supplier<String> supplier = IsolatedCompileContext.get().unhand(reasonAndStackTraceHandle);
return IsolatedCompileContext.get().createStringInClient(supplier.get());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
*/
package com.oracle.svm.truffle.isolated;

import com.oracle.svm.graal.isolated.IsolatedHandles;
import org.graalvm.nativeimage.StackValue;
import org.graalvm.nativeimage.c.function.CEntryPoint;
import org.graalvm.nativeimage.c.struct.RawField;
Expand All @@ -45,6 +46,8 @@
import com.oracle.truffle.compiler.TruffleCompilerListener.CompilationResultInfo;
import com.oracle.truffle.compiler.TruffleCompilerListener.GraphInfo;

import java.util.function.Supplier;

final class IsolatedTruffleCompilerEventForwarder implements TruffleCompilerListener {
private final ClientHandle<IsolatedEventContext> contextHandle;

Expand Down Expand Up @@ -76,9 +79,10 @@ public void onSuccess(TruffleCompilable compilable, TruffleCompilationTask task,
}

@Override
public void onFailure(TruffleCompilable compilable, String reason, boolean bailout, boolean permanentBailout, int tier) {
public void onFailure(TruffleCompilable compilable, String reason, boolean bailout, boolean permanentBailout, int tier, Supplier<String> lazyStackTrace) {
try (CCharPointerHolder reasonCstr = CTypeConversion.toCString(reason)) {
onFailure0(IsolatedCompileContext.get().getClient(), contextHandle, reasonCstr.get(), bailout, permanentBailout, tier);
onFailure0(IsolatedCompileContext.get().getClient(), contextHandle, reasonCstr.get(), bailout, permanentBailout, tier,
lazyStackTrace == null ? IsolatedHandles.nullHandle() : IsolatedCompileContext.get().hand(lazyStackTrace));
}
}

Expand Down Expand Up @@ -111,9 +115,10 @@ private static void onSuccess0(@SuppressWarnings("unused") ClientIsolateThread c

@CEntryPoint(include = CEntryPoint.NotIncludedAutomatically.class, publishAs = CEntryPoint.Publish.NotPublished)
private static void onFailure0(@SuppressWarnings("unused") ClientIsolateThread client, ClientHandle<IsolatedEventContext> contextHandle,
CCharPointer reason, boolean bailout, boolean permanentBailout, int tier) {
CCharPointer reason, boolean bailout, boolean permanentBailout, int tier, CompilerHandle<Supplier<String>> lazyStackTraceHandle) {
IsolatedEventContext context = IsolatedCompileClient.get().unhand(contextHandle);
context.listener.onFailure(context.compilable, CTypeConversion.toJavaString(reason), bailout, permanentBailout, tier);
context.listener.onFailure(context.compilable, CTypeConversion.toJavaString(reason), bailout, permanentBailout, tier,
lazyStackTraceHandle.equal(IsolatedHandles.nullHandle()) ? null : new IsolatedStringSupplier(lazyStackTraceHandle));
}

@CEntryPoint(include = CEntryPoint.NotIncludedAutomatically.class, publishAs = CEntryPoint.Publish.NotPublished)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import com.oracle.svm.graal.isolated.ClientHandle;
import com.oracle.svm.graal.isolated.ClientIsolateThread;
import com.oracle.svm.graal.isolated.CompilerHandle;
import com.oracle.svm.graal.isolated.CompilerIsolateThread;
import com.oracle.svm.graal.isolated.ImageHeapObjects;
import com.oracle.svm.graal.isolated.ImageHeapRef;
import com.oracle.svm.graal.isolated.IsolatedCodeInstallBridge;
Expand Down Expand Up @@ -175,23 +174,11 @@ public static TriState tryIsSuppressedFailure(TruffleCompilable compilable, Supp
@CEntryPoint(include = CEntryPoint.NotIncludedAutomatically.class, publishAs = CEntryPoint.Publish.NotPublished)
private static boolean isSuppressedFailure0(@SuppressWarnings("unused") ClientIsolateThread client, ClientHandle<SubstrateCompilableTruffleAST> ast,
CompilerHandle<Supplier<String>> serializedExceptionHandle) {
Supplier<String> serializedException = new Supplier<>() {
@Override
public String get() {
ClientHandle<String> resultHandle = getReasonAndStackTrace0(IsolatedCompileClient.get().getCompiler(), serializedExceptionHandle);
return IsolatedCompileClient.get().unhand(resultHandle);
}
};
Supplier<String> serializedException = new IsolatedStringSupplier(serializedExceptionHandle);
SubstrateTruffleRuntime runtime = (SubstrateTruffleRuntime) SubstrateTruffleRuntime.getRuntime();
return runtime.isSuppressedFailure(IsolatedCompileClient.get().unhand(ast), serializedException);
}

@CEntryPoint(include = CEntryPoint.NotIncludedAutomatically.class, publishAs = CEntryPoint.Publish.NotPublished)
private static ClientHandle<String> getReasonAndStackTrace0(@SuppressWarnings("unused") CompilerIsolateThread compiler, CompilerHandle<Supplier<String>> reasonAndStackTraceHandle) {
Supplier<String> supplier = IsolatedCompileContext.get().unhand(reasonAndStackTraceHandle);
return IsolatedCompileContext.get().createStringInClient(supplier.get());
}

private IsolatedTruffleRuntimeSupport() {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
*/
package com.oracle.truffle.compiler;

import java.util.function.Supplier;

/**
* A listener for events related to the compilation of a {@link TruffleCompilable}. The events are
* described only in terms of types that can be easily serialized or proxied across a heap boundary.
Expand Down Expand Up @@ -150,6 +152,9 @@ default void onSuccess(TruffleCompilable compilable, TruffleCompilationTask task

/**
* Notifies this object when compilation of {@code compilable} fails.
* <p>
* GR-54187: Remove in graalvm-25.1
* </p>
*
* @param compilable the Truffle AST whose compilation failed
* @param reason the reason compilation failed
Expand All @@ -161,9 +166,34 @@ default void onSuccess(TruffleCompilable compilable, TruffleCompilationTask task
* change if the {@code target} is compiled again. This value is meaningless if
* {@code bailout == false}.
* @param tier Which compilation tier was the compilation
* @deprecated use
* {@link #onFailure(TruffleCompilable, String, boolean, boolean, int, Supplier)}
*/
@Deprecated(since = "24.1")
default void onFailure(TruffleCompilable compilable, String reason, boolean bailout, boolean permanentBailout, int tier) {
onFailure(compilable, reason, bailout, permanentBailout, tier, null);
}

/**
* Notifies this object when compilation of {@code compilable} fails.
*
* @param compilable the Truffle AST whose compilation failed
* @param reason the reason compilation failed
* @param bailout specifies whether the failure was a bailout or an error in the compiler. A
* bailout means the compiler aborted the compilation based on some of property of
* {@code target} (e.g., too big). A non-bailout means an unexpected error in the
* compiler itself.
* @param permanentBailout specifies if a bailout is due to a condition that probably won't
* change if the {@code target} is compiled again. This value is meaningless if
* {@code bailout == false}.
* @param tier Which compilation tier was the compilation
* @param lazyStackTrace a serialized representation of the exception indicating the reason and
* stack trace for a compilation failure, or {@code null} in the case of a bailout or
* when the compiler does not provide a stack trace. See
* {@link TruffleCompilable#serializeException(Throwable)}.
*
*/
default void onFailure(TruffleCompilable compilable, String reason, boolean bailout, boolean permanentBailout, int tier, Supplier<String> lazyStackTrace) {
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ enum Id implements FromLibGraalId {
OnCompilationFailed,
@Signature({void.class, Object.class, Object.class, Object.class})
OnCompilationRetry,
@Signature({void.class, Object.class, Object.class, String.class, boolean.class, boolean.class, int.class})
@Signature({void.class, Object.class, Object.class, String.class, boolean.class, boolean.class, int.class, long.class})
OnFailure,
@Signature({void.class, Object.class, Object.class, long.class})
OnGraalTierFinished,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -916,7 +916,7 @@ private void compileImpl(OptimizedCallTarget callTarget, AbstractCompilationTask
private void notifyCompilationFailure(OptimizedCallTarget callTarget, Throwable t, boolean compilationStarted, int tier) {
try {
if (compilationStarted) {
listeners.onCompilationFailed(callTarget, t.toString(), false, false, tier);
listeners.onCompilationFailed(callTarget, t.toString(), false, false, tier, () -> TruffleCompilable.serializeException(t));
} else {
listeners.onCompilationDequeued(callTarget, this, String.format("Failed to create Truffle compiler due to %s.", t.getMessage()), tier);
}
Expand Down
Loading

0 comments on commit ceaac5f

Please sign in to comment.