Skip to content

Commit 5ea8ee7

Browse files
committed
[GR-54516] Support an arbitrary amount of threads in ThreadLocalHandshake
PullRequest: graal/18051
2 parents b211b3c + 61793ea commit 5ea8ee7

File tree

10 files changed

+494
-172
lines changed

10 files changed

+494
-172
lines changed

sdk/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ This changelog summarizes major changes between GraalVM SDK versions. The main f
1010
* GR-54310 Removed disabled-by-default class-path isolation feature if polyglot is used from the class-path. The option `-Dpolyglotimpl.DisableClassPathIsolation` has no longer any effect.
1111
* GR-49484 Added `PolyglotException.StackFrame.getBytecodeIndex()` which allows to access the internal bytecode index that the language uses to identify an execution location.
1212
* GR-47956 Added the option `engine.InterpreterCallStackHeadRoom` to protect against stack overflow in the middle of a guest method execution in the interpreter. For the UNTRUSTED polyglot sandbox policy, the value for the option is computed automatically based on the value of the mandatory option `sandbox.MaxASTDepth`, the option `sandbox.MaxStackFrames` is no longer mandatory. The new option is available only in the AOT mode.
13-
* GR-40931 Added experimental support for virtual threads on HotSpot. Not all languages are currently supported for use with virtual threads, please check the language changelog for further information. Truffle debugging, CPU time limits and some memory limits are currently not supported on virtual threads. The number of threads is currently limited to 65535 threads entered per context.
13+
* GR-40931 Added experimental support for virtual threads on HotSpot. Not all languages are currently supported for use with virtual threads, please check the language changelog for further information. Truffle debugging, CPU time limits and some memory limits are currently not supported on virtual threads.
1414
* GR-40931 Using virtual threads in a native-image will now emulate virtual threads using platform threads until Loom support for Truffle languages in native-image is implemented.
1515
* GR-48481: It is now possible to depend on platform-specific Maven artifacts when using polyglot isolates. The `-isolate` Maven artifacts remain platform-independent. However, if platform specific builds are required, consider adding a platform specific suffix to the Maven artifact name, such as `-isolate-linux-amd64`. The reduced binary size of platform specific dependencies can improve build times and reduce the distribution size of your application. For more details, see [Embedding Languages](https://www.graalvm.org/latest/reference-manual/embed-languages/#polyglot-isolates).
1616
* GR-48481: The Python language is now available as a polyglot isolate.

truffle/CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,12 @@ This changelog summarizes major changes between Truffle versions relevant to lan
2323
* GR-28866 Deprecated `TruffleLanguage.Env.isPolyglotEvalAllowed()`. Replace usages with `TruffleLanguage.Env.isPolyglotEvalAllowed(LanguageInfo)`. Please see javadoc for the updated usage.
2424
* GR-52843 Deprecated `Node.getCost()` and the associated `NodeCost` class without replacement. Truffle DSL no longer generates implementations of this method automatically and will therefore always return `NodeCost.MONOMORPHIC` by default. This is intended to reduce the binary footprint.
2525
* GR-52843 Added the `UnadoptableNode` interface. This is interface should be preferred to overriding `Node.isAdoptable()` if the result is statically known.
26-
* GR-40931 Virtual threads with a polyglot context are now experimentally supported on HotSpot. Experimental because access to caller frames in write or materialize mode is not yet supported and maximum 65535 threads concurrently accessing the context.
26+
* GR-40931 Virtual threads with a polyglot context are now experimentally supported on HotSpot. Experimental because access to caller frames in write or materialize mode is not yet supported.
2727
* GR-40931 Using virtual threads in a native-image will now emulate virtual threads using platform threads until Loom support for Truffle languages in native-image is implemented.
2828
* GR-40931 Added [`TruffleThreadBuilder#virtual()`](https://www.graalvm.org/truffle/javadoc/com/oracle/truffle/api/TruffleThreadBuilder.html#virtual(boolean)) for languages to create virtual threads.
2929
* GR-53454 Added warning in the annotation processor when `@ReportPolymorphism` is used incorrectly.
30+
* GR-54516 The `Future` returned by submitting `ThreadLocalAction` now throws `CancellationException` on `Future#get()` when the future is cancelled, as it should per `Future` interface semantics.
31+
* GR-54516 Synchronous `ThreadLocalAction`s which wait longer than `--engine.SynchronousThreadLocalActionMaxWait` (default 60) seconds for all threads to start executing that action now show a warning and are automatically cancelled to prevent applications to hang.
3032

3133
## Version 24.0.0
3234

truffle/docs/Options.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ They are useful to users and language and tool implementers.
5050
```shell
5151
- `--engine.PreinitializeContexts` : Preinitialize language contexts for given languages.
5252
- `--engine.RelaxStaticObjectSafetyChecks` : On property accesses, the Static Object Model does not perform shape checks and uses unsafe casts
53+
- `--engine.SynchronousThreadLocalActionMaxWait=[0, inf)` : How long to wait for other threads to reach a synchronous ThreadLocalAction before cancelling it, in seconds. 0 means no limit.
54+
- `--engine.SynchronousThreadLocalActionPrintStackTraces` : Print thread stacktraces when a synchronous ThreadLocalAction is waiting for more than SynchronousThreadLocalActionMaxWait seconds.
5355
- `--engine.TraceStackTraceInterval=[1, inf)` : Prints the stack trace for all threads for a time interval. By default 0, which disables the output.
5456
- `--engine.DebugCacheCompileUseLastTier=true|false` : If true uses the last tier instead of the first tier compiler. By default the last tier compiler is used (default: true).
5557
- `--engine.BackgroundCompilation=true|false` : Enable asynchronous truffle compilation in background threads (default: true)
@@ -114,7 +116,7 @@ These are internal options for debugging language implementations and tools.
114116
- `--engine.StaticObjectStorageStrategy=default|array-based|field-based` : Set the storage strategy used by the Static Object Model. Accepted values are: ['default', 'array-based', 'field-based']
115117
- `--engine.TraceCodeSharing` : Enables printing of code sharing related information to the logger. This option is intended to support debugging language implementations.
116118
- `--engine.TraceMissingSafepointPollInterval=[0, inf)` : Show Java stacktraces for missing polls longer than the supplied number of milliseconds. Implies SafepointALot.
117-
- `--engine.TraceThreadLocalActions` : Traces thread local events and when they are processed on the individual threads.Prints messages with the [engine] [tl] prefix.
119+
- `--engine.TraceThreadLocalActions` : Traces thread local events and when they are processed on the individual threads. Prints messages with the [engine] [tl] prefix.
118120
- `--engine.TriggerUncaughtExceptionHandlerForCancel` : Propagates cancel execution exception into UncaughtExceptionHandler. For testing purposes only.
119121
- `--engine.UseConservativeContextReferences` : Enables conservative context references. This allows invalid sharing between contexts. For testing purposes only.
120122
- `--engine.UsePreInitializedContext=true|false` : Use pre-initialized context when it's available (default: true).

truffle/src/com.oracle.truffle.api.instrumentation.test/src/com/oracle/truffle/api/instrumentation/test/ContextPauseTest.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,12 @@
4545
import java.util.concurrent.CountDownLatch;
4646
import java.util.concurrent.ExecutionException;
4747
import java.util.concurrent.ExecutorService;
48-
import java.util.concurrent.Executors;
4948
import java.util.concurrent.Future;
5049
import java.util.concurrent.TimeUnit;
5150
import java.util.concurrent.TimeoutException;
5251
import java.util.concurrent.atomic.AtomicBoolean;
5352

53+
import com.oracle.truffle.api.test.polyglot.AbstractThreadedPolyglotTest;
5454
import org.graalvm.polyglot.Context;
5555
import org.graalvm.polyglot.PolyglotException;
5656
import org.junit.After;
@@ -67,8 +67,12 @@
6767
import com.oracle.truffle.api.instrumentation.SourceSectionFilter;
6868
import com.oracle.truffle.api.instrumentation.TruffleInstrument;
6969
import com.oracle.truffle.api.test.polyglot.AbstractPolyglotTest;
70+
import org.junit.runner.RunWith;
71+
import org.junit.runners.Parameterized;
7072

71-
public class ContextPauseTest {
73+
@SuppressWarnings("hiding")
74+
@RunWith(Parameterized.class)
75+
public class ContextPauseTest extends AbstractThreadedPolyglotTest {
7276

7377
private static final String TEST_EXECUTION_STOPPED = "Test execution stopped!";
7478

@@ -85,9 +89,15 @@ private interface AfterPauseAction {
8589
}
8690

8791
private static void testCommon(OnEnterAction onEnterAction, GuestAction guestAction, boolean waitForPause, AfterPauseAction afterPauseAction) throws ExecutionException, InterruptedException {
92+
int processors = Runtime.getRuntime().availableProcessors();
8893
for (int nThreads = 1; nThreads <= 10; nThreads += 3) {
94+
if (vthreads && nThreads > processors) {
95+
// Can hang, see https://bugs.openjdk.org/browse/JDK-8334304
96+
continue;
97+
}
98+
8999
for (int nPauses = 1; nPauses <= 3; nPauses++) {
90-
ExecutorService executorService = Executors.newFixedThreadPool(nThreads);
100+
ExecutorService executorService = threadPool(nThreads, vthreads);
91101
try (Context context = Context.create()) {
92102
context.initialize(InstrumentationTestLanguage.ID);
93103
TruffleInstrument.Env instrumentEnv = context.getEngine().getInstruments().get("InstrumentationUpdateInstrument").lookup(TruffleInstrument.Env.class);

0 commit comments

Comments
 (0)