Skip to content

Conversation

@dylan-conway
Copy link
Member

Summary

  • Fix mi_manage_os_memory_ex2 assertion failure when using mimalloc for the structure heap on Windows
  • The structure heap memory passed to mimalloc was offset by MarkedBlock::blockSize (16KB), but mimalloc v3 requires MI_ARENA_SLICE_SIZE (64KB) alignment for arena memory
  • Use std::max(MarkedBlock::blockSize, MI_ARENA_SLICE_SIZE) as the offset to ensure proper alignment

🤖 Generated with Claude Code

@dylan-conway
Copy link
Member Author

/build-preview

@github-actions
Copy link

🔄 Preview build started

Release tag: autobuild-preview-pr-143-fda7c35b
Workflow: View progress

@coderabbitai
Copy link

coderabbitai bot commented Jan 23, 2026

Walkthrough

Passes the full structure-heap region to mimalloc registration (adjusting pointer/size calculations and offset logic) and enables mimalloc across Windows, macOS, Docker (including musl) and shared build flags; several CMake lists updated to conditionally link/include mimalloc and workflow trigger/commenting logic revised.

Changes

Cohort / File(s) Summary
Structure heap / mimalloc integration
Source/JavaScriptCore/heap/StructureAlignedMemoryAllocator.cpp
Add mimalloc/types.h include; compute offset as max(MarkedBlock::blockSize, MI_ARENA_SLICE_SIZE); adjust memory pointer/size math; call mi_manage_os_memory/registration with the adjusted region; retain mi_heap_new_in_arena allocation path.
Windows release script
windows-release.ps1
CMake invocation: removed -DUSE_LIBPAS=ON and changed -DUSE_MIMALLOC from OFF to ON.
macOS release script
mac-release.bash
Add -DUSE_MIMALLOC=ON to cmake invocations; simplified malloc-heap-breakdown default to OFF.
Docker builds
Dockerfile, Dockerfile.musl
Add -DUSE_MIMALLOC=ON to WebKit CMake build steps.
Shared build flags
build.ts
Add -DUSE_MIMALLOC=ON to common flags; remove -DUSE_SYSTEM_MALLOC=ON from Windows flags.
CMakeLists / mimalloc object linkage
Source/JavaScriptCore/shell/CMakeLists.txt, Source/bmalloc/CMakeLists.txt, Source/bmalloc/mimalloc/CMakeLists.txt
shell/CMakeLists.txt: append $<TARGET_OBJECTS:mimalloc-obj> to jsc_LIBRARIES when USE_MIMALLOC and USE_BUN_JSC_ADDITIONS are true. bmalloc/CMakeLists.txt: append mimalloc include dir to bmalloc_INTERFACE_INCLUDE_DIRECTORIES when USE_MIMALLOC; only append $<TARGET_OBJECTS:mimalloc-obj> when USE_MIMALLOC AND NOT USE_BUN_JSC_ADDITIONS. mimalloc/CMakeLists.txt: set MI_USE_CXX ON when USE_BUN_JSC_ADDITIONS is defined.
CI / workflow
.github/workflows/build-preview.yml
Switch trigger from issue_comment to pull_request; derive sha, pr_number, and release_tag from PR context; simplify PR number sourcing; rewrite PR comment logic to update a single table-based comment and remove reaction/start comments.

Possibly related PRs

  • Fix Windows build #142 — Modifies Windows CMake invocation to enable mimalloc / replace system-malloc flags; overlaps the Windows build-flag changes in this PR.
🚥 Pre-merge checks | ✅ 1 | ❌ 1
❌ Failed checks (1 inconclusive)
Check name Status Explanation Resolution
Description check ❓ Inconclusive The PR description provides a clear summary of the fix and its rationale, but does not follow the WebKit project template (missing Bugzilla link, reviewer line, and standard commit message format). Add Bugzilla bug reference link, format as per WebKit template with 'Reviewed by' line, and list affected files with their modified functions to meet repository standards.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Fix mimalloc arena alignment assertion for structure heap' directly and clearly describes the main change: fixing an alignment issue in mimalloc's arena handling for the structure heap.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

Warning

Review ran into problems

🔥 Problems

Git: Failed to clone repository. Please run the @coderabbitai full review command to re-trigger a full review. If the issue persists, set path_filters to include or exclude specific files.


Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Fix all issues with AI agents
In `@Source/JavaScriptCore/heap/StructureAlignedMemoryAllocator.cpp`:
- Around line 142-145: The code computes offset = max(MarkedBlock::blockSize,
MI_ARENA_SLICE_SIZE) and then subtracts it from g_jscConfig.sizeOfStructureHeap
to get size, which can underflow if sizeOfStructureHeap <= offset; update the
allocation path around mi_manage_os_memory_ex to validate and clamp/abort when
g_jscConfig.sizeOfStructureHeap <= offset (or compute size as 0 and fail early),
e.g. check g_jscConfig.sizeOfStructureHeap > offset before performing size =
g_jscConfig.sizeOfStructureHeap - offset and only call mi_manage_os_memory_ex
when size > 0 (or return an error/RELEASE_ASSERT with a clear message),
referencing offset, g_jscConfig.sizeOfStructureHeap, MarkedBlock::blockSize,
MI_ARENA_SLICE_SIZE, mi_manage_os_memory_ex, and structureArena so the guard is
placed immediately before the current subtraction and call.

In `@windows-release.ps1`:
- Around line 383-384: The CMake flag -DUSE_LIBPAS=OFF is unused and should be
removed from the Windows release script; locate the cmake invocation in
windows-release.ps1 where the flags include -DUSE_MIMALLOC=ON and
-DUSE_LIBPAS=OFF and delete the -DUSE_LIBPAS=OFF entry so only effective/defined
options (e.g., -DUSE_MIMALLOC=ON) remain.

@github-actions
Copy link

⚠️ Preview build was cancelled

This may have been caused by a newer build being triggered for the same PR.

@dylan-conway
Copy link
Member Author

/build-preview

@github-actions
Copy link

🔄 Preview build started

Release tag: autobuild-preview-pr-143-ab2470a3
Workflow: View progress

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@Source/JavaScriptCore/heap/StructureAlignedMemoryAllocator.cpp`:
- Around line 142-146: The comment and call to mi_manage_os_memory_ex assume
mimalloc won't allocate at offset 0, which is false and risks allocating at
StructureID(0); update the code to explicitly reserve offset 0 by either
adjusting the managed range passed to mi_manage_os_memory_ex (advance
g_jscConfig.startOfStructureHeap by MI_ARENA_SLICE_SIZE and reduce
g_jscConfig.sizeOfStructureHeap accordingly) or implement a guard that blocks
allocations at offset 0 in structureArena, and fix the comment to accurately
describe mimalloc's mi_arena_meta_zalloc behavior; ensure changes reference
g_jscConfig.startOfStructureHeap, g_jscConfig.sizeOfStructureHeap,
mi_manage_os_memory_ex, structureArena and mention
StructureID(0)/MI_ARENA_SLICE_SIZE.

@dylan-conway
Copy link
Member Author

/build-preview

@github-actions
Copy link

⚠️ Preview build was cancelled

This may have been caused by a newer build being triggered for the same PR.

@github-actions
Copy link

🔄 Preview build started

Release tag: autobuild-preview-pr-143-ab2470a3
Workflow: View progress

@github-actions
Copy link

✅ Preview build completed

Release: autobuild-preview-pr-143-ab2470a3

@dylan-conway
Copy link
Member Author

/build-preview

@github-actions
Copy link

🔄 Preview build started

Release tag: autobuild-preview-pr-143-309346a9
Workflow: View progress

@dylan-conway
Copy link
Member Author

/build-preview

@github-actions
Copy link

⚠️ Preview build was cancelled

This may have been caused by a newer build being triggered for the same PR.

@github-actions
Copy link

🔄 Preview build started

Release tag: autobuild-preview-pr-143-2da75adf
Workflow: View progress

@github-actions
Copy link

⚠️ Preview build was cancelled

This may have been caused by a newer build being triggered for the same PR.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@mac-release.bash`:
- Around line 50-52: Remove the duplicate CMake flag by deleting one of the
repeated -DCMAKE_EXPORT_COMPILE_COMMANDS=ON entries in the mac-release.bash
invocation; keep the single occurrence and retain the other new flags
(-DUSE_BUN_JSC_ADDITIONS=ON and -DUSE_MIMALLOC=ON) so the CMake arguments list
is deduplicated and unchanged otherwise.

Comment on lines 50 to +52
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
-DUSE_BUN_JSC_ADDITIONS=ON \
-DUSE_MIMALLOC=ON \
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick | 🔵 Trivial

Minor: Duplicate CMake flag.

-DCMAKE_EXPORT_COMPILE_COMMANDS=ON is specified twice (lines 45 and 50). Consider removing one occurrence.

The -DUSE_MIMALLOC=ON addition looks correct and aligns with the PR objective.

Suggested cleanup
     -DENABLE_MALLOC_HEAP_BREAKDOWN=$ENABLE_MALLOC_HEAP_BREAKDOWN \
-    -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
     -DUSE_BUN_JSC_ADDITIONS=ON \
     -DUSE_MIMALLOC=ON \
🤖 Prompt for AI Agents
In `@mac-release.bash` around lines 50 - 52, Remove the duplicate CMake flag by
deleting one of the repeated -DCMAKE_EXPORT_COMPILE_COMMANDS=ON entries in the
mac-release.bash invocation; keep the single occurrence and retain the other new
flags (-DUSE_BUN_JSC_ADDITIONS=ON and -DUSE_MIMALLOC=ON) so the CMake arguments
list is deduplicated and unchanged otherwise.

@github-actions
Copy link

⚠️ Preview build was cancelled

This may have been caused by a newer commit being pushed to the same PR.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Fix all issues with AI agents
In @.github/workflows/build-preview.yml:
- Around line 114-129: The current extraction of previous table rows uses
lines.filter(l => l.startsWith('| `')), which is fragile; update the logic
around the existing variable where previousRows is computed (the lines,
tableLines, and previousRows variables) to more robustly detect table rows
(e.g., match lines that start with '|' and have three pipe-separated columns or
use a regex like /^\|\s*[^|]+\|\s*[^|]+\|\s*[^|]+\|/), ensure you preserve any
leading newline behavior (previousRows assignment), and keep the rest of the
body assembly (marker, '## Preview Builds', table header, newEntry +
previousRows) unchanged so existing consumers of body/newEntry continue to work.
- Around line 105-112: The listing of PR comments via
github.rest.issues.listComments with per_page: 100 can miss the marker comment
on very active PRs; update the logic (the call to
github.rest.issues.listComments and the subsequent comments.find(c =>
c.body.includes(marker)) usage) to paginate through all comment pages or
increase the page size and aggregate results before searching for marker,
ensuring the search for existing (the existing variable) checks the full set of
comments rather than only the first page.

Comment on lines +105 to +112
// Find existing comment
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: ${{ needs.trigger.outputs.pr_number }},
body: body
issue_number: prNumber,
per_page: 100
});
const existing = comments.find(c => c.body.includes(marker));
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick | 🔵 Trivial

Pagination may miss marker comment in highly active PRs.

With per_page: 100, the marker comment won't be found if there are more than 100 comments on the PR. This is an edge case but could result in duplicate preview build comments.

Consider paginating or using a higher limit if PRs with many comments are expected:

♻️ Optional: Add pagination or increase limit
             // Find existing comment
-            const { data: comments } = await github.rest.issues.listComments({
-              owner: context.repo.owner,
-              repo: context.repo.repo,
-              issue_number: prNumber,
-              per_page: 100
-            });
-            const existing = comments.find(c => c.body.includes(marker));
+            let existing = null;
+            for await (const { data: comments } of github.paginate.iterator(
+              github.rest.issues.listComments,
+              { owner: context.repo.owner, repo: context.repo.repo, issue_number: prNumber, per_page: 100 }
+            )) {
+              existing = comments.find(c => c.body.includes(marker));
+              if (existing) break;
+            }
🤖 Prompt for AI Agents
In @.github/workflows/build-preview.yml around lines 105 - 112, The listing of
PR comments via github.rest.issues.listComments with per_page: 100 can miss the
marker comment on very active PRs; update the logic (the call to
github.rest.issues.listComments and the subsequent comments.find(c =>
c.body.includes(marker)) usage) to paginate through all comment pages or
increase the page size and aggregate results before searching for marker,
ensuring the search for existing (the existing variable) checks the full set of
comments rather than only the first page.

Comment on lines +114 to +129
// Build table
let previousRows = '';
if (existing) {
const lines = existing.body.split('\n');
const tableLines = lines.filter(l => l.startsWith('| `'));
previousRows = tableLines.length > 0 ? '\n' + tableLines.join('\n') : '';
}
- name: React to failure
if: needs.build.result == 'failure' && github.event_name == 'issue_comment'
uses: actions/github-script@v7
with:
script: |
await github.rest.reactions.createForIssueComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: context.payload.comment.id,
content: '-1'
});
- name: Post failure comment
if: needs.build.result == 'failure'
uses: actions/github-script@v7
with:
script: |
const body = "❌ Preview build failed\n\n" +
"Check the [workflow run](" + context.serverUrl + "/" + context.repo.owner + "/" + context.repo.repo + "/actions/runs/" + context.runId + ") for details.";
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: ${{ needs.trigger.outputs.pr_number }},
body: body
});
- name: Post cancellation comment
if: needs.build.result == 'cancelled'
uses: actions/github-script@v7
with:
script: |
const body = "⚠️ Preview build was cancelled\n\n" +
"This may have been caused by a newer build being triggered for the same PR.";
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: ${{ needs.trigger.outputs.pr_number }},
body: body
});
const body = [
marker,
'## Preview Builds',
'',
'| Commit | Release | Date |',
'|--------|---------|------|',
newEntry + previousRows
].join('\n');
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick | 🔵 Trivial

Table row extraction relies on specific markdown format.

The filter l.startsWith('| \')` works for the current format but is fragile. If the table format changes (e.g., different cell content or spacing), previously appended rows may be lost.

This is acceptable for now but worth documenting or making more robust if the format evolves.

🤖 Prompt for AI Agents
In @.github/workflows/build-preview.yml around lines 114 - 129, The current
extraction of previous table rows uses lines.filter(l => l.startsWith('| `')),
which is fragile; update the logic around the existing variable where
previousRows is computed (the lines, tableLines, and previousRows variables) to
more robustly detect table rows (e.g., match lines that start with '|' and have
three pipe-separated columns or use a regex like
/^\|\s*[^|]+\|\s*[^|]+\|\s*[^|]+\|/), ensure you preserve any leading newline
behavior (previousRows assignment), and keep the rest of the body assembly
(marker, '## Preview Builds', table header, newEntry + previousRows) unchanged
so existing consumers of body/newEntry continue to work.

@github-actions
Copy link

github-actions bot commented Jan 23, 2026

Preview Builds

Commit Release Date
b31f5b3c autobuild-preview-pr-143-b31f5b3c 2026-01-24 02:36:51 UTC
1e0c7499 autobuild-preview-pr-143-1e0c7499 2026-01-23 23:52:03 UTC

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants