Skip to content

Commit a4e3a8b

Browse files
[GR-68493] Web-image support for running espresso in web-image
PullRequest: graal/21778
2 parents e324a6a + 59b93b6 commit a4e3a8b

File tree

4 files changed

+99
-3
lines changed

4 files changed

+99
-3
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/WebImageSystemPropertiesSupport.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,12 @@ protected String javaIoTmpdirValue() {
5757

5858
@Override
5959
protected String osNameValue() {
60-
return "Unknown";
60+
return "Web Image";
6161
}
6262

6363
@Override
6464
protected String osVersionValue() {
65-
return "Unknown";
65+
return "0.0";
6666
}
6767

6868
}

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: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import com.oracle.svm.core.annotate.Substitute;
2828
import com.oracle.svm.core.annotate.TargetClass;
2929
import com.oracle.svm.webimage.functionintrinsics.JSFunctionIntrinsics;
30+
import jdk.internal.misc.Signal;
3031

3132
@TargetClass(className = "jdk.internal.misc.VM")
3233
@SuppressWarnings("unused")
@@ -56,6 +57,62 @@ public static long getNanoTimeAdjustment(long offsetInSeconds) {
5657
}
5758
}
5859

60+
@TargetClass(className = "jdk.internal.misc.Signal")
61+
final class Target_jdk_internal_misc_Signal_Web {
62+
63+
/**
64+
* Uses POSIX signal numbers. May be incomplete, extend as necessary.
65+
* <p>
66+
* Signals are not supported in Web Image, but instances of {@code Signal} may still exist, so
67+
* this method must return something.
68+
* <p>
69+
* Signal numbers taken from {@code man 7 signal} for the intel architecture.
70+
*/
71+
@Substitute
72+
private static int findSignal0(String sigName) {
73+
return switch (sigName) {
74+
case "HUP" -> 1;
75+
case "INT" -> 2;
76+
case "QUIT" -> 3;
77+
case "ILL" -> 4;
78+
case "TRAP" -> 5;
79+
case "ABRT" -> 6;
80+
case "BUS" -> 7;
81+
case "FPE" -> 8;
82+
case "KILL" -> 9;
83+
case "USR1" -> 10;
84+
case "SEGV" -> 11;
85+
case "USR2" -> 12;
86+
case "PIPE" -> 13;
87+
case "ALRM" -> 14;
88+
case "TERM" -> 15;
89+
case "STKFLT" -> 16;
90+
case "CHLD" -> 17;
91+
case "CONT" -> 18;
92+
case "STOP" -> 19;
93+
case "TSTP" -> 20;
94+
case "TTIN" -> 21;
95+
case "TTOU" -> 22;
96+
case "URG" -> 23;
97+
case "XCPU" -> 24;
98+
case "XFSZ" -> 25;
99+
case "VTALRM" -> 26;
100+
case "PROF" -> 27;
101+
case "WINCH" -> 28;
102+
case "IO" -> 29;
103+
case "PWR" -> 30;
104+
case "SYS" -> 31;
105+
default -> -1;
106+
};
107+
}
108+
109+
@Substitute
110+
@SuppressWarnings("unused")
111+
public static Signal.Handler handle(Signal sig, Signal.Handler handler) throws IllegalArgumentException {
112+
throw new IllegalArgumentException("cannot register signal handles in webimage.");
113+
}
114+
}
115+
59116
/** Dummy class to have a class with the file's name. */
60117
public final class WebImageSunMiscSubstitutions {
61118
}

0 commit comments

Comments
 (0)