diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/JavaMainWrapper.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/JavaMainWrapper.java index e6fb30ca62ca..046421a9670d 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/JavaMainWrapper.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/JavaMainWrapper.java @@ -67,6 +67,7 @@ import com.oracle.svm.core.jdk.InternalVMMethod; import com.oracle.svm.core.jdk.RuntimeSupport; import com.oracle.svm.core.log.Log; +import com.oracle.svm.core.os.VirtualMemoryProvider; import com.oracle.svm.core.sampler.ProfilingSampler; import com.oracle.svm.core.thread.JavaThreads; import com.oracle.svm.core.thread.PlatformThreads; @@ -218,11 +219,19 @@ public static int run(int argc, CCharPointerPointer argv) { } } + private static final CGlobalData PAGE_SIZE_CHECK_FAIL_MESSAGE = CGlobalDataFactory + .createCString("Image page size does not match the page size at run-time. Use -H:PageSize=[pagesize] to set appropriately."); + @Uninterruptible(reason = "Thread state not setup yet.") private static int doRun(int argc, CCharPointerPointer argv) { try { CPUFeatureAccess cpuFeatureAccess = ImageSingletons.lookup(CPUFeatureAccess.class); cpuFeatureAccess.verifyHostSupportsArchitectureEarlyOrExit(); + if (VirtualMemoryProvider.get().getGranularity().notEqual(SubstrateOptions.getPageSize())) { + CEntryPointActions.failFatally(CEntryPointErrors.PAGE_SIZE_CHECK_FAILED, PAGE_SIZE_CHECK_FAIL_MESSAGE.get()); + return 1; + } + // Create the isolate and attach the current C thread as the main Java thread. EnterCreateIsolateWithCArgumentsPrologue.enter(argc, argv); assert !VMThreads.wasStartedByCurrentIsolate(CurrentIsolate.getCurrentThread()) : "re-attach would cause issues otherwise"; diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/SubstrateOptions.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/SubstrateOptions.java index 2ae67b2309ba..5f3a4048faa9 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/SubstrateOptions.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/SubstrateOptions.java @@ -820,6 +820,7 @@ public ReportingSupport(String reportingPath) { @Option(help = "Define PageSize of a machine that runs the image. The default = 0 (== same as host machine page size)")// protected static final HostedOptionKey PageSize = new HostedOptionKey<>(0); + @Fold public static int getPageSize() { int value = PageSize.getValue(); if (value == 0) { diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/c/function/CEntryPointErrors.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/c/function/CEntryPointErrors.java index 772924d5353d..ebe28689bc82 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/c/function/CEntryPointErrors.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/c/function/CEntryPointErrors.java @@ -125,6 +125,9 @@ private CEntryPointErrors() { @Description("Current target does not support the following CPU features that are required by the image.") // public static final int CPU_FEATURE_CHECK_FAILED = 23; + @Description("Image page size does not match the page size at run-time.") // + public static final int PAGE_SIZE_CHECK_FAILED = 24; + public static String getDescription(int code) { String result = null; if (code >= 0 && code < DESCRIPTIONS.length) { diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/graal/snippets/CEntryPointSnippets.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/graal/snippets/CEntryPointSnippets.java index e99967118b0d..201cd05a4a6f 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/graal/snippets/CEntryPointSnippets.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/graal/snippets/CEntryPointSnippets.java @@ -94,6 +94,7 @@ import com.oracle.svm.core.log.Log; import com.oracle.svm.core.option.RuntimeOptionParser; import com.oracle.svm.core.os.MemoryProtectionProvider; +import com.oracle.svm.core.os.VirtualMemoryProvider; import com.oracle.svm.core.snippets.SnippetRuntime; import com.oracle.svm.core.snippets.SnippetRuntime.SubstrateForeignCallDescriptor; import com.oracle.svm.core.snippets.SubstrateForeignCallTarget; @@ -205,6 +206,9 @@ private static int createIsolate(CEntryPointCreateIsolateParameters parameters, if (cpuFeatureAccess.verifyHostSupportsArchitectureEarly() != 0) { return CEntryPointErrors.CPU_FEATURE_CHECK_FAILED; } + if (VirtualMemoryProvider.get().getGranularity().notEqual(SubstrateOptions.getPageSize())) { + return CEntryPointErrors.PAGE_SIZE_CHECK_FAILED; + } CLongPointer parsedArgs = StackValue.get(IsolateArgumentParser.getStructSize()); IsolateArgumentParser.parse(parameters, parsedArgs);