Skip to content

Commit

Permalink
Deprecate the GraalWasm AsyncParsing options
Browse files Browse the repository at this point in the history
  • Loading branch information
jirkamarsik committed Jan 14, 2025
1 parent c4b0e2b commit f395058
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 46 deletions.
1 change: 1 addition & 0 deletions wasm/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ This changelog summarizes major changes to the WebAssembly engine implemented in
## Version 24.2.0

* Updated developer metadata of Maven artifacts.
* Deprecated the `--wasm.AsyncParsingBinarySize` and `--wasm.AsyncParsingStackSize` options. These options no longer have any effect and will be removed in a future release.

## Version 24.1.0

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
Expand Down Expand Up @@ -50,8 +50,6 @@
import org.graalvm.collections.MapCursor;
import org.graalvm.wasm.constants.BytecodeBitEncoding;
import org.graalvm.wasm.constants.SegmentMode;
import org.graalvm.wasm.exception.Failure;
import org.graalvm.wasm.exception.WasmException;
import org.graalvm.wasm.memory.WasmMemory;
import org.graalvm.wasm.memory.WasmMemoryFactory;
import org.graalvm.wasm.nodes.WasmCallStubNode;
Expand All @@ -74,22 +72,6 @@
* Creates wasm instances by converting parser nodes into Truffle nodes.
*/
public class WasmInstantiator {
private static final int MIN_DEFAULT_STACK_SIZE = 1_000_000;
private static final int MAX_DEFAULT_ASYNC_STACK_SIZE = 10_000_000;

private static class ParsingExceptionHandler implements Thread.UncaughtExceptionHandler {
private Throwable parsingException = null;

@Override
public void uncaughtException(Thread t, Throwable e) {
this.parsingException = e;
}

public Throwable parsingException() {
return parsingException;
}
}

private final WasmLanguage language;

@TruffleBoundary
Expand All @@ -101,30 +83,7 @@ public WasmInstantiator(WasmLanguage language) {
public WasmInstance createInstance(WasmContext context, WasmModule module, TruffleContext truffleContext) {
WasmInstance instance = new WasmInstance(context, module, truffleContext);
instance.createLinkActions();
int binarySize = instance.module().bytecodeLength();
final int asyncParsingBinarySize = WasmOptions.AsyncParsingBinarySize.getValue(context.environment().getOptions());
if (binarySize < asyncParsingBinarySize || !context.environment().isCreateThreadAllowed()) {
instantiateCodeEntries(context, instance);
} else {
final Runnable parsing = () -> instantiateCodeEntries(context, instance);
final String name = "wasm-parsing-thread(" + instance.name() + ")";
final int requestedSize = WasmOptions.AsyncParsingStackSize.getValue(context.environment().getOptions()) * 1000;
final int defaultSize = Math.max(MIN_DEFAULT_STACK_SIZE, Math.min(2 * binarySize, MAX_DEFAULT_ASYNC_STACK_SIZE));
final int stackSize = requestedSize != 0 ? requestedSize : defaultSize;
final Thread parsingThread = context.environment().newTruffleThreadBuilder(parsing).stackSize(stackSize).build();
parsingThread.setName(name);
final ParsingExceptionHandler handler = new ParsingExceptionHandler();
parsingThread.setUncaughtExceptionHandler(handler);
parsingThread.start();
try {
parsingThread.join();
if (handler.parsingException() != null) {
throw WasmException.create(Failure.UNSPECIFIED_INVALID, "Asynchronous parsing failed.");
}
} catch (InterruptedException e) {
throw WasmException.create(Failure.UNSPECIFIED_INVALID, "Asynchronous parsing interrupted.");
}
}
instantiateCodeEntries(context, instance);
return instance;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
Expand Down Expand Up @@ -51,10 +51,12 @@ public class WasmOptions {
@Option(help = "A comma-separated list of builtin modules to use.", category = OptionCategory.USER, stability = OptionStability.STABLE, usageSyntax = "[<linkingName>:]<builtinModuleName>,[<linkingName>:]<builtinModuleName>,...")//
public static final OptionKey<String> Builtins = new OptionKey<>("");

@Option(help = "The minimal binary size for which to use async parsing. If threads are not supported, async parsing will not be used.", category = OptionCategory.USER, stability = OptionStability.STABLE, usageSyntax = "[0, inf)")//
@Option(help = "The minimal binary size for which to use async parsing. If threads are not supported, async parsing will not be used.", category = OptionCategory.USER, stability = OptionStability.STABLE, usageSyntax = "[0, inf)", //
deprecated = true, deprecationMessage = "Option no longer has any effect and can be safely omitted.")//
public static final OptionKey<Integer> AsyncParsingBinarySize = new OptionKey<>(100_000);

@Option(help = "The stack size in kilobytes to use during async parsing, or zero to use defaults.", category = OptionCategory.USER, stability = OptionStability.STABLE, usageSyntax = "[0, inf)")//
@Option(help = "The stack size in kilobytes to use during async parsing, or zero to use defaults.", category = OptionCategory.USER, stability = OptionStability.STABLE, usageSyntax = "[0, inf)", //
deprecated = true, deprecationMessage = "Option no longer has any effect and can be safely omitted.")//
public static final OptionKey<Integer> AsyncParsingStackSize = new OptionKey<>(0);

@Option(help = "A comma-separated list of pre-opened Wasi directories.", category = OptionCategory.USER, stability = OptionStability.STABLE, usageSyntax = "[<virtualDir>::]<hostDir>,[<virtualDir>::]<hostDir>,...")//
Expand Down

0 comments on commit f395058

Please sign in to comment.