Skip to content

Commit 59b93b6

Browse files
[GR-68493] Web-image support for running espresso in web-image
1 parent 262036f commit 59b93b6

File tree

3 files changed

+42
-2
lines changed

3 files changed

+42
-2
lines changed

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/Target_java_lang_Thread.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,7 @@ private static void yield0() {
367367
PlatformThreads.singleton().yieldCurrent();
368368
}
369369

370+
@Platforms(InternalPlatform.NATIVE_ONLY.class)
370371
@Substitute
371372
private static void sleepNanos0(long nanos) throws InterruptedException {
372373
// Virtual threads are handled in sleep()

web-image/src/com.oracle.svm.webimage/src/com/oracle/svm/webimage/substitute/system/WebImageJavaLangSubstitutions.java

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
import com.oracle.svm.webimage.platform.WebImageJSPlatform;
6060
import com.oracle.svm.webimage.platform.WebImagePlatform;
6161
import com.oracle.svm.webimage.platform.WebImageWasmGCPlatform;
62+
import org.graalvm.nativeimage.ProcessProperties;
6263

6364
/*
6465
* Checkstyle: stop method name check
@@ -232,7 +233,11 @@ private static void yield() {
232233
}
233234

234235
@Substitute
235-
private static void sleep(long millis) throws InterruptedException {
236+
private static void sleep(long millis) {
237+
}
238+
239+
@Substitute
240+
private static void sleepNanos0(long nanos) {
236241
}
237242

238243
@Substitute
@@ -257,6 +262,16 @@ public static Map<Thread, StackTraceElement[]> getAllStackTraces() {
257262
}
258263
}
259264

265+
@TargetClass(className = "java.lang.VirtualThread")
266+
@SuppressWarnings("unused")
267+
final class Target_java_lang_VirtualThread_Web {
268+
@Substitute
269+
@SuppressWarnings("static-method")
270+
private void runContinuation() {
271+
throw new UnsupportedOperationException("VirtualThread.runContinuation");
272+
}
273+
}
274+
260275
@TargetClass(java.lang.System.class)
261276
@SuppressWarnings("unused")
262277
final class Target_java_lang_System_Web {
@@ -879,6 +894,29 @@ public static Logger getLogger(String name) {
879894
}
880895
}
881896

897+
@TargetClass(className = "java.lang.ProcessHandleImpl")
898+
@SuppressWarnings("unused")
899+
final class Target_java_lang_ProcessHandleImpl_Web {
900+
901+
@Substitute
902+
private static void initNative() {
903+
// Do nothing. Native code only gathers some information about the underlying system.
904+
}
905+
906+
@Substitute
907+
private static long getCurrentPid0() {
908+
return ProcessProperties.getProcessID();
909+
}
910+
911+
@Substitute
912+
private static long isAlive0(long pid) {
913+
if (pid == ProcessProperties.getProcessID()) {
914+
return 0L;
915+
}
916+
return -1L;
917+
}
918+
}
919+
882920
class IsLinux implements BooleanSupplier {
883921
@Override
884922
public boolean getAsBoolean() {

web-image/src/com.oracle.svm.webimage/src/com/oracle/svm/webimage/substitute/system/WebImageSunMiscSubstitutions.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@ private static int findSignal0(String sigName) {
107107
}
108108

109109
@Substitute
110-
public static synchronized Signal.Handler handle(Signal sig, Signal.Handler handler) throws IllegalArgumentException {
110+
@SuppressWarnings("unused")
111+
public static Signal.Handler handle(Signal sig, Signal.Handler handler) throws IllegalArgumentException {
111112
throw new IllegalArgumentException("cannot register signal handles in webimage.");
112113
}
113114
}

0 commit comments

Comments
 (0)