Skip to content

Commit 3a4e016

Browse files
committed
Make the Vector API an optional dependency of GraalWasm
GraalWasm now requires jdk.incubator.vector using "requires static". If the jdk.incubator.vector was not provided, we fall back to our previous implementation. This makes incubator warnings opt in.
1 parent 2729ca2 commit 3a4e016

File tree

15 files changed

+1808
-1602
lines changed

15 files changed

+1808
-1602
lines changed

wasm/CHANGELOG.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@ This changelog summarizes major changes to the WebAssembly engine implemented in
2424
This aligns with the JS WebAssembly API and allows other members to be introduced on the module instance without potential name clashes.
2525
More information about these API changes and examples can be found in the [GraalWasm Polyglot API Migration Guide](docs/user/GraalWasmAPIMigration.md) and the [Readme](docs/user/README.md).
2626
* Implemented support for editing primitive values during debugging. Fixed several debugger-related issues.
27-
* The [SIMD](https://github.com/WebAssembly/simd) proposal is now implemented using the JDK's Vector API.
28-
This improves peak performance when running WebAssembly code which makes heavy use of the new instructions in the SIMD proposal.
29-
Since the Vector API is still incubating, you will see the following message when running GraalWasm on the JVM.
27+
* Added an implementation of the [SIMD](https://github.com/WebAssembly/simd) proposal using the JDK's Vector API. This improves peak performance when running WebAssembly code which makes heavy use of the new instructions in the SIMD proposal. This new implementation is always used in native image. On the JVM, it is opt-in and requires setting `--add-modules=jdk.incubator.vector`. Use of the incubating Vector API will result in the following error message being printed to stderr:
3028
```
3129
WARNING: Using incubator modules: jdk.incubator.vector
3230
```

wasm/mx.wasm/suite.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,7 @@
293293
"name" : "org.graalvm.wasm",
294294
"requires": [
295295
"org.graalvm.collections",
296+
"static jdk.incubator.vector", # Vector API
296297
],
297298
"exports" : [
298299
"* to org.graalvm.wasm.test",

wasm/scripts/run-c-micro-benchmarks

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ do
1616
"--results-file=${RESULTS_FILE_PATH}" \
1717
wasm:WASM_BENCHMARKCASES -- \
1818
--jvm ${VM} --jvm-config ${VM_CONFIG} \
19+
--add-modules=jdk.incubator.vector \
1920
-Dwasmbench.benchmarkName=$benchmark -- \
2021
CMicroBenchmarkSuite
2122

@@ -26,6 +27,8 @@ done
2627
mx --dy /compiler --kill-with-sigquit benchmark \
2728
"--machine-name=${MACHINE_NAME}" \
2829
"--results-file=${RESULTS_FILE_PATH}" \
29-
wasm-memory:* -- --jvm ${VM} --jvm-config ${VM_CONFIG}
30+
wasm-memory:* -- \
31+
--jvm ${VM} --jvm-config ${VM_CONFIG} \
32+
--add-modules=jdk.incubator.vector
3033

3134
${UPLOAD_CMD} "${RESULTS_FILE_PATH}"

wasm/src/org.graalvm.wasm.jdk25/src/org/graalvm/wasm/api/Vector128Ops.java renamed to wasm/src/org.graalvm.wasm.jdk25/src/org/graalvm/wasm/api/Vector128OpsVectorAPI.java

Lines changed: 95 additions & 82 deletions
Large diffs are not rendered by default.

wasm/src/org.graalvm.wasm/src/org/graalvm/wasm/api/Vector128Ops.java

Lines changed: 53 additions & 1418 deletions
Large diffs are not rendered by default.

wasm/src/org.graalvm.wasm/src/org/graalvm/wasm/api/Vector128OpsFallback.java

Lines changed: 1497 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Copyright (c) 2024, 2025, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* The Universal Permissive License (UPL), Version 1.0
6+
*
7+
* Subject to the condition set forth below, permission is hereby granted to any
8+
* person obtaining a copy of this software, associated documentation and/or
9+
* data (collectively the "Software"), free of charge and under any and all
10+
* copyright rights in the Software, and any and all patent rights owned or
11+
* freely licensable by each licensor hereunder covering either (i) the
12+
* unmodified Software as contributed to or provided by such licensor, or (ii)
13+
* the Larger Works (as defined below), to deal in both
14+
*
15+
* (a) the Software, and
16+
*
17+
* (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
18+
* one is included with the Software each a "Larger Work" to which the Software
19+
* is contributed by such licensors),
20+
*
21+
* without restriction, including without limitation the rights to copy, create
22+
* derivative works of, display, perform, and distribute the Software and make,
23+
* use, sell, offer for sale, import, export, have made, and have sold the
24+
* Software and the Larger Work(s), and to sublicense the foregoing rights on
25+
* either these or other terms.
26+
*
27+
* This license is subject to the following condition:
28+
*
29+
* The above copyright notice and either this complete permission notice or at a
30+
* minimum a reference to the UPL must be included in all copies or substantial
31+
* portions of the Software.
32+
*
33+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
34+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
35+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
36+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
37+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
38+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
39+
* SOFTWARE.
40+
*/
41+
42+
package org.graalvm.wasm.api;
43+
44+
public final class Vector128OpsVectorAPI {
45+
46+
public static Vector128Ops<?> create() {
47+
throw new UnsupportedOperationException();
48+
}
49+
}

wasm/src/org.graalvm.wasm/src/org/graalvm/wasm/memory/ByteArrayWasmMemory.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ public long load_i64_32u(Node node, long address) {
261261
@ExportMessage
262262
public Object load_i128(Node node, long address) {
263263
if (ByteArraySupport.littleEndian().inBounds(buffer(), address, Vector128.BYTES)) {
264-
return Vector128Ops.fromArray(buffer(), (int) address);
264+
return Vector128Ops.SINGLETON_IMPLEMENTATION.fromArray(buffer(), (int) address);
265265
} else {
266266
throw trapOutOfBounds(node, address, 16);
267267
}
@@ -352,7 +352,7 @@ public void store_i64_32(Node node, long address, int value) {
352352
@ExportMessage
353353
public void store_i128(Node node, long address, Object value) {
354354
if (ByteArraySupport.littleEndian().inBounds(buffer(), address, 16)) {
355-
Vector128Ops.intoArray(value, buffer(), (int) address);
355+
Vector128Ops.SINGLETON_IMPLEMENTATION.intoArray(Vector128Ops.cast(value), buffer(), (int) address);
356356
} else {
357357
throw trapOutOfBounds(node, address, 16);
358358
}

wasm/src/org.graalvm.wasm/src/org/graalvm/wasm/memory/NativeWasmMemory.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ public Object load_i128(Node node, long address) {
289289
byte[] bytes = new byte[Vector128.BYTES];
290290
unsafe.copyMemory(null, startAddress + address, bytes, Unsafe.ARRAY_BYTE_BASE_OFFSET, Vector128.BYTES);
291291
// Use ByteVector.fromMemorySegment after adopting FFM
292-
return Vector128Ops.fromArray(bytes);
292+
return Vector128Ops.SINGLETON_IMPLEMENTATION.fromArray(bytes);
293293
}
294294

295295
@ExportMessage
@@ -350,7 +350,7 @@ public void store_i64_32(Node node, long address, int value) {
350350
public void store_i128(Node node, long address, Object value) {
351351
validateAddress(node, address, 16);
352352
// Use intoMemorySegment after adopting the FFM API
353-
unsafe.copyMemory(Vector128Ops.toArray(value), Unsafe.ARRAY_BYTE_BASE_OFFSET, null, startAddress + address, 16);
353+
unsafe.copyMemory(Vector128Ops.SINGLETON_IMPLEMENTATION.toArray(Vector128Ops.cast(value)), Unsafe.ARRAY_BYTE_BASE_OFFSET, null, startAddress + address, 16);
354354
}
355355

356356
@ExportMessage

wasm/src/org.graalvm.wasm/src/org/graalvm/wasm/memory/UnsafeWasmMemory.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ public Object load_i128(Node node, long address) {
265265
byte[] bytes = new byte[Vector128.BYTES];
266266
unsafe.copyMemory(null, startAddress + address, bytes, Unsafe.ARRAY_BYTE_BASE_OFFSET, Vector128.BYTES);
267267
// Use ByteVector.fromMemorySegment after adopting FFM
268-
return Vector128Ops.fromArray(bytes);
268+
return Vector128Ops.SINGLETON_IMPLEMENTATION.fromArray(bytes);
269269
}
270270

271271
@ExportMessage
@@ -328,7 +328,7 @@ public void store_i64_32(Node node, long address, int value) {
328328
public void store_i128(Node node, long address, Object value) {
329329
validateAddress(node, address, 16);
330330
// Use intoMemorySegment after adopting the FFM API
331-
unsafe.copyMemory(Vector128Ops.toArray(value), Unsafe.ARRAY_BYTE_BASE_OFFSET, null, startAddress + address, 16);
331+
unsafe.copyMemory(Vector128Ops.SINGLETON_IMPLEMENTATION.toArray(Vector128Ops.cast(value)), Unsafe.ARRAY_BYTE_BASE_OFFSET, null, startAddress + address, 16);
332332
}
333333

334334
@ExportMessage

0 commit comments

Comments
 (0)