Skip to content

Enable Native Image Layers on Windows, macOS, and aarch64.#13018

Open
emberian wants to merge 2 commits intooracle:masterfrom
emberian:ember/windows-layers
Open

Enable Native Image Layers on Windows, macOS, and aarch64.#13018
emberian wants to merge 2 commits intooracle:masterfrom
emberian:ember/windows-layers

Conversation

@emberian
Copy link

@emberian emberian commented Feb 20, 2026

Summary

AArch64 backend changes

  • Add forceIndirectCall() to shouldEmitIndirectCall(), matching the AMD64 backend
  • Handle cross-layer method calls in emitIndirectForeignCallAddress() via DynamicImageLayerInfo (both delayed and prior-layer methods)
  • Implement createLoadMethodPointerConstant() for extension layers (previously threw VMError.unimplemented)
  • Add addend constructor to AArch64CGlobalDataLoadAddressOp for prior-layer method offset calculation
  • Skip cross-layer callees in LIRNativeImageCodeCache.addDirectCallTrampolines()

Darwin platform changes

  • Extend DarwinImageHeapProvider with full layered image heap initialization using vm_copy() per layer section, with read-only page protection
  • Extract platform-independent patching code from LinuxImageHeapProvider into new shared LayeredImageHeapSupport class
  • Update all Darwin singleton annotations from Disallowed to appropriate layered kinds (InitialLayerOnly / Independent)
  • Make IMAGE_LAYER file suffix format-aware (.dylib on macOS, .so on Linux)
  • Add IMAGE_LAYER case to DarwinCCLinkerInvocation

Platform gate

  • Add DARWIN_AARCH64 and LINUX_AARCH64 to HostedImageLayerBuildingSupport.supportedPlatform()

Windows platform changes

  • Extends Native Image Layers support to Windows AMD64 and Windows AArch64
  • Adds WINDOWS_AMD64 and WINDOWS_AARCH64 to the layers platform gate
  • Implements layered heap initialization in WindowsImageHeapProvider, mirroring the Darwin implementation: reserves address space, iterates layer sections, copies each layer's heap via commitAndCopyMemory(), protects read-only pages, and delegates to LayeredImageHeapSupport.patchLayeredImageHeap() for cross-layer patching
  • Updates singleton trait annotations across 14 Windows platform files, replacing other = Disallowed.class with layeredInstallationKind = InitialLayerOnly.class (and NoLayeredCallbacksSingleLayer where needed)
  • Adds firstImageBuild() guards to WindowsFeature and WindowsSystemPropertiesFeature to prevent double-registration in extension layers
  • Removes Disallowed from WindowsCCompilerInvoker (matching Linux/Darwin)

Test plan

  • Build and test base layer creation on Windows AMD64: mx native-image -H:LayerCreate=base,+module=java.base -o base Hello.java
  • Build and test extension layer on Windows AMD64: mx native-image -H:LayerUse=base -o hello Hello.java
  • Run hello.exe to verify correct execution
  • Verify no regressions on Linux AMD64 layers
  • Verify no regressions on Darwin AArch64 layers

🤖 Generated with Claude Code

Previously, Native Image Layers were restricted to Linux AMD64. This
change extends layer support to Darwin/AArch64 and Linux/AArch64 by:

AArch64 backend:
- Add forceIndirectCall() check to shouldEmitIndirectCall(), matching AMD64
- Handle cross-layer method calls in emitIndirectForeignCallAddress() via
  DynamicImageLayerInfo for both delayed and prior-layer methods
- Implement createLoadMethodPointerConstant() for extension layers
  (previously threw VMError.unimplemented)
- Add addend constructor to AArch64CGlobalDataLoadAddressOp for
  prior-layer method offset support
- Skip cross-layer callees in trampoline calculation

Darwin platform:
- Extend DarwinImageHeapProvider with layered image heap initialization
  using vm_copy per layer section, with read-only page protection
- Extract platform-independent patching code from LinuxImageHeapProvider
  into new LayeredImageHeapSupport class (shared by both platforms)
- Update Darwin singleton annotations from Disallowed to their
  appropriate layered kinds (InitialLayerOnly/Independent)
- Make IMAGE_LAYER file suffix format-aware (.dylib on macOS)
- Add IMAGE_LAYER case to DarwinCCLinkerInvocation

Tested end-to-end: base layer (shared library) + extension layer
(thin executable) builds and runs correctly on macOS/aarch64.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@oracle-contributor-agreement oracle-contributor-agreement bot added the OCA Verified All contributors have signed the Oracle Contributor Agreement. label Feb 20, 2026
@emberian emberian force-pushed the ember/windows-layers branch 4 times, most recently from 8176a76 to 8429a8d Compare February 20, 2026 12:39
@emberian emberian changed the title [GR-53498] Enable Native Image Layers on Windows [GR-53498] Enable Native Image Layers on Windows, macOS, and aarch64. Feb 20, 2026
@emberian emberian force-pushed the ember/windows-layers branch from 8429a8d to e5918a5 Compare February 20, 2026 13:07
@emberian emberian changed the title [GR-53498] Enable Native Image Layers on Windows, macOS, and aarch64. Enable Native Image Layers on Windows, macOS, and aarch64. Feb 20, 2026
@emberian emberian force-pushed the ember/windows-layers branch 4 times, most recently from 9df0f51 to 38b260d Compare February 20, 2026 19:57
@oracle-contributor-agreement
Copy link

Thank you for your pull request and welcome to our community! To contribute, please sign the Oracle Contributor Agreement (OCA).
The following contributors of this PR have not signed the OCA:

To sign the OCA, please create an Oracle account and sign the OCA in Oracle's Contributor Agreement Application.

When signing the OCA, please provide your GitHub username. After signing the OCA and getting an OCA approval from Oracle, this PR will be automatically updated.

If you are an Oracle employee, please make sure that you are a member of the main Oracle GitHub organization, and your membership in this organization is public.

@oracle-contributor-agreement oracle-contributor-agreement bot added OCA Required At least one contributor does not have an approved Oracle Contributor Agreement. and removed OCA Verified All contributors have signed the Oracle Contributor Agreement. labels Feb 21, 2026
@emberian emberian force-pushed the ember/windows-layers branch 5 times, most recently from 7b2304e to 6aa7406 Compare February 21, 2026 18:27
Extend native image layer support to Windows, completing coverage across
all major platforms (Linux, macOS, Windows) for both AMD64 and AArch64.

Key changes:

Platform gate and singleton annotations:
- Add WINDOWS_AMD64 and WINDOWS_AARCH64 to supportedPlatform()
- Fix singleton annotations on 13 Windows files: change Disallowed to
  InitialLayerOnly with SingleLayer callbacks
- Add firstImageBuild() guards to WindowsFeature and
  WindowsSystemPropertiesFeature

WindowsImageHeapProvider - layered heap initialization:
- Override initialize() for layered builds with per-layer heap copying
- Add patchNextSectionPointers() to resolve NEXT_SECTION linked list
  at runtime via GetProcAddress (MSVC linker can't resolve forward refs)
- Add resolveForwardSymbolReferences() to patch CGlobal slots before
  argument parsing reads them

PE/COFF CGlobal fixup mechanism (.svm_fix section):
- In NativeImage.java, build a fixup table mapping CGlobal slot offsets
  to symbol names for forward-reference CGlobals
- At runtime, WindowsImageHeapProvider resolves each symbol via
  GetProcAddress on the extension layer's module
- Add ImageHeapProvider.resolveForwardSymbolReferences() default method,
  called from CEntryPointSnippets.createIsolate() before argument parsing

PE/COFF linker and object file fixes:
- Handle IMAGE_LAYER output as .dll on PE/COFF
- Suppress auto-exports to stay under PE/COFF 65535 export limit
- Fix duplicate static libraries in linker command
- Fix import library placement and library naming
- Support unresolved forward references in shared layer DLLs
- Fix cross-layer IAT (Import Address Table) symbol references

Misc fixes:
- Fix TimeZoneSupport singleton for layered builds
- Skip file mapping optimization for layered heaps (must copy to
  preserve cross-layer patches)
- Fix vtable symbols and codeSynchronization for Windows layers

Testing:
- Add mx layeredhelloworld command and gate task that builds base +
  extension layers and validates the output on all platforms
- Remove outdated Darwin/AArch64 skip from layereddebuginfotest

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@emberian emberian force-pushed the ember/windows-layers branch from 6aa7406 to 41aea63 Compare February 21, 2026 19:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

OCA Required At least one contributor does not have an approved Oracle Contributor Agreement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants