GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — src: fix timing of snapshot serialize callback · nodejs/node@dc93d69

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • lib/internal
    • main
      • mksnapshot.js
    • v8
      • startup_snapshot.js
  • test/parallel
    • test-buffer-alloc-unsafe-is-initialized-with-zero-fill-flag.js
    • test-buffer-alloc-unsafe-is-uninitialized.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎lib/internal/main/mksnapshot.js‎

Copy file name to clipboardExpand all lines: lib/internal/main/mksnapshot.js
-2Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ const { emitExperimentalWarning } = require('internal/util');
2121
const { emitWarningSync } = require('internal/process/warning');
2222

2323
const {
24-
initializeCallbacks,
2524
namespace: {
2625
addDeserializeCallback,
2726
isBuildingSnapshot,
@@ -139,7 +138,6 @@ function requireForUserSnapshot(id) {
139138

140139
function main() {
141140
prepareMainThreadExecution(false, false);
142-
initializeCallbacks();
143141

144142
// In a context created for building snapshots, V8 does not install Error.stackTraceLimit and as
145143
// a result, if an error is created during the snapshot building process, error.stack would be
Collapse file

‎lib/internal/v8/startup_snapshot.js‎

Copy file name to clipboardExpand all lines: lib/internal/v8/startup_snapshot.js
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,8 @@ function setDeserializeMainFunction(callback, data) {
115115
});
116116
}
117117

118+
initializeCallbacks();
118119
module.exports = {
119-
initializeCallbacks,
120120
runDeserializeCallbacks,
121121
throwIfBuildingSnapshot,
122122
// Exposed to require('v8').startupSnapshot
Collapse file

‎test/parallel/test-buffer-alloc-unsafe-is-initialized-with-zero-fill-flag.js‎

Copy file name to clipboard
+21Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Flags: --expose-internals --zero-fill-buffers
2+
// Verifies that Buffer.allocUnsafe() allocates initialized memory under --zero-fill-buffers by
3+
// checking the usage count of the relevant native allocator code path.
4+
'use strict';
5+
6+
const common = require('../common');
7+
if (!common.isDebug) {
8+
common.skip('Only works in debug mode');
9+
}
10+
const { internalBinding } = require('internal/test/binding');
11+
const { getGenericUsageCount } = internalBinding('debug');
12+
const assert = require('assert');
13+
14+
const initialUninitializedCount = getGenericUsageCount('NodeArrayBufferAllocator.Allocate.Uninitialized');
15+
const initialZeroFilledCount = getGenericUsageCount('NodeArrayBufferAllocator.Allocate.ZeroFilled');
16+
const buffer = Buffer.allocUnsafe(Buffer.poolSize + 1);
17+
assert(buffer.every((b) => b === 0));
18+
const newUninitializedCount = getGenericUsageCount('NodeArrayBufferAllocator.Allocate.Uninitialized');
19+
const newZeroFilledCount = getGenericUsageCount('NodeArrayBufferAllocator.Allocate.ZeroFilled');
20+
assert.strictEqual(newUninitializedCount, initialUninitializedCount);
21+
assert.notStrictEqual(newZeroFilledCount, initialZeroFilledCount);
Collapse file

‎test/parallel/test-buffer-alloc-unsafe-is-uninitialized.js‎

Copy file name to clipboard
+23Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Flags: --expose-internals
2+
// Verifies that Buffer.allocUnsafe() indeed allocates uninitialized memory by checking
3+
// the usage count of the relevant native allocator code path.
4+
'use strict';
5+
6+
const common = require('../common');
7+
if (!common.isDebug) {
8+
common.skip('Only works in debug mode');
9+
}
10+
const { internalBinding } = require('internal/test/binding');
11+
const { getGenericUsageCount } = internalBinding('debug');
12+
const assert = require('assert');
13+
14+
const initialUninitializedCount = getGenericUsageCount('NodeArrayBufferAllocator.Allocate.Uninitialized');
15+
const initialZeroFilledCount = getGenericUsageCount('NodeArrayBufferAllocator.Allocate.ZeroFilled');
16+
Buffer.allocUnsafe(Buffer.poolSize + 1);
17+
// We can't reliably check the contents of the buffer here because the OS or memory allocator
18+
// used might zero-fill memory for us, or they might happen to return reused memory that was
19+
// previously used by a process that zero-filled it. So instead we just check the usage counts.
20+
const newUninitializedCount = getGenericUsageCount('NodeArrayBufferAllocator.Allocate.Uninitialized');
21+
const newZeroFilledCount = getGenericUsageCount('NodeArrayBufferAllocator.Allocate.ZeroFilled');
22+
assert.notStrictEqual(newUninitializedCount, initialUninitializedCount);
23+
assert.strictEqual(newZeroFilledCount, initialZeroFilledCount);

0 commit comments

Comments
0 (0)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.