Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v20.x] backport vm-related memory fixes #49874

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
0fbbe49
doc: promote fetch/webstreams from experimental to stable
styfle Sep 24, 2023
6a88c6a
doc: add mertcanaltin as a triager
Sep 23, 2023
9600928
node-api: enable uncaught exceptions policy by default
legendecas Sep 25, 2023
ddf0e17
doc,tools: switch to `@node-core/utils`
targos Sep 25, 2023
eded29c
test: use mustSucceed instead of mustCall
SiddharthDevulapalli Sep 25, 2023
1f16df2
deps: V8: cherry-pick b33bf2dfd261
joyeecheung Jul 20, 2023
aea7371
deps: V8: backport de9a5de2274f
joyeecheung Sep 18, 2023
f4041ce
doc: deprecate `fs.F_OK`, `fs.R_OK`, `fs.W_OK`, `fs.X_OK`
LiviaMedeiros Sep 25, 2023
690cca3
doc: fix `DEP0176` number
LiviaMedeiros Sep 25, 2023
d2bcdcb
test: mark test-runner-output as flaky
joyeecheung Sep 25, 2023
07d0518
fs: improve `readFileSync` with file descriptors
anonrig Sep 25, 2023
6db0d3d
tools: support updating @reporters/github manually
MoLow Sep 26, 2023
7d91a73
url: improve invalid url performance
anonrig Sep 26, 2023
12fe6a0
stream: use bitmap in writable state
rluvaton Sep 26, 2023
d44a812
test: deflake test-runner-output
MoLow Sep 26, 2023
f40b5ed
perf_hooks: reduce overhead of new performance_entries
H4ad Sep 27, 2023
e82e46c
fs: improve error performance for `unlinkSync`
CanadaHonk Sep 27, 2023
9363179
fs: replace `SetMethodNoSideEffect` in node_file
CanadaHonk Sep 27, 2023
1a18034
test: add os setPriority, getPriority test coverage
waelsy123 Sep 27, 2023
f656122
deps: add v8::Object::SetInternalFieldForNodeCore()
joyeecheung Sep 26, 2023
35735ba
module: use symbol in WeakMap to manage host defined options
joyeecheung Jun 21, 2023
23edd1d
module: fix leak of vm.SyntheticModule
joyeecheung Jun 21, 2023
2920904
module: fix the leak in SourceTextModule and ContextifySript
joyeecheung Jun 23, 2023
7d916e2
test: add checkIfCollectable to test/common/gc.js
joyeecheung Sep 16, 2023
8a47a18
test: use checkIfCollectable in vm leak tests
joyeecheung Sep 16, 2023
1985233
test: deflake test-vm-contextified-script-leak
joyeecheung Sep 23, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/auto-start-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ jobs:
with:
node-version: ${{ env.NODE_VERSION }}

- name: Install node-core-utils
run: npm install -g node-core-utils
- name: Install @node-core/utils
run: npm install -g @node-core/utils

- name: Setup node-core-utils
- name: Setup @node-core/utils
run: |
ncu-config set username ${{ secrets.JENKINS_USER }}
ncu-config set token "${{ secrets.GH_USER_TOKEN }}"
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/commit-queue.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,15 @@ jobs:
uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d # v3.8.1
with:
node-version: ${{ env.NODE_VERSION }}
- name: Install node-core-utils
run: npm install -g node-core-utils@latest
- name: Install @node-core/utils
run: npm install -g @node-core/utils

- name: Set variables
run: |
echo "REPOSITORY=$(echo ${{ github.repository }} | cut -d/ -f2)" >> $GITHUB_ENV
echo "OWNER=${{ github.repository_owner }}" >> $GITHUB_ENV

- name: Configure node-core-utils
- name: Configure @node-core/utils
run: |
ncu-config set branch ${GITHUB_REF_NAME}
ncu-config set upstream origin
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/tools.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ on:
- corepack
- doc
- eslint
- github_reporter
- googletest
- histogram
- icu
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/update-v8.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ jobs:
uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d # v3.8.1
with:
node-version: ${{ env.NODE_VERSION }}
- name: Install node-core-utils
run: npm install -g node-core-utils@latest
- name: Install @node-core/utils
run: npm install -g @node-core/utils
- name: Check and download new V8 version
run: |
./tools/dep_updaters/update-v8-patch.sh > temp-output
Expand Down
2 changes: 1 addition & 1 deletion .gitpod.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Ref: https://github.com/gitpod-io/gitpod/issues/6283#issuecomment-1001043454
tasks:
- init: ./configure && timeout 50m make -j16 || true
- init: pnpm i -g node-core-utils
- init: pnpm i -g @node-core/utils

# Ref: https://www.gitpod.io/docs/prebuilds#github-specific-configuration
github:
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -721,6 +721,8 @@ maintaining the Node.js project.
**Akhil Marsonya** <<akhil.marsonya27@gmail.com>> (he/him)
* [meixg](https://github.com/meixg) -
**Xuguang Mei** <<meixuguang@gmail.com>> (he/him)
* [mertcanaltin](https://github.com/mertcanaltin) -
**Mert Can Altin** <<mertgold60@gmail.com>>
* [Mesteery](https://github.com/Mesteery) -
**Mestery** <<mestery@protonmail.com>> (he/him)
* [preveen-stack](https://github.com/preveen-stack) -
Expand Down
43 changes: 43 additions & 0 deletions benchmark/fs/bench-unlinkSync.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
'use strict';

const common = require('../common');
const fs = require('fs');
const tmpdir = require('../../test/common/tmpdir');
tmpdir.refresh();

const bench = common.createBenchmark(main, {
type: ['existing', 'non-existing'],
n: [1e3],
});

function main({ n, type }) {
let files;

switch (type) {
case 'existing':
files = [];

// Populate tmpdir with mock files
for (let i = 0; i < n; i++) {
const path = tmpdir.resolve(`unlinksync-bench-file-${i}`);
fs.writeFileSync(path, 'bench');
files.push(path);
}
break;
case 'non-existing':
files = new Array(n).fill(tmpdir.resolve(`.non-existing-file-${Date.now()}`));
break;
default:
new Error('Invalid type');
}

bench.start();
for (let i = 0; i < n; i++) {
try {
fs.unlinkSync(files[i]);
} catch {
// do nothing
}
}
bench.end(n);
}
18 changes: 15 additions & 3 deletions benchmark/fs/readFileSync.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,21 @@ const fs = require('fs');
const bench = common.createBenchmark(main, {
encoding: ['undefined', 'utf8'],
path: ['existing', 'non-existing'],
n: [60e1],
hasFileDescriptor: ['true', 'false'],
n: [1e4],
});

function main({ n, encoding, path }) {
function main({ n, encoding, path, hasFileDescriptor }) {
const enc = encoding === 'undefined' ? undefined : encoding;
const file = path === 'existing' ? __filename : '/tmp/not-found';
let file;
let shouldClose = false;

if (hasFileDescriptor === 'true') {
shouldClose = path === 'existing';
file = path === 'existing' ? fs.openSync(__filename) : -1;
} else {
file = path === 'existing' ? __filename : '/tmp/not-found';
}
bench.start();
for (let i = 0; i < n; ++i) {
try {
Expand All @@ -21,4 +30,7 @@ function main({ n, encoding, path }) {
}
}
bench.end(n);
if (shouldClose) {
fs.closeSync(file);
}
}
36 changes: 36 additions & 0 deletions benchmark/perf_hooks/timerfied.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
'use strict';

const assert = require('assert');
const common = require('../common.js');

const {
PerformanceObserver,
performance,
} = require('perf_hooks');

function randomFn() {
return Math.random();
}

const bench = common.createBenchmark(main, {
n: [1e5],
observe: ['function'],
});

let _result;

function main({ n, observe }) {
const obs = new PerformanceObserver(() => {
bench.end(n);
});
obs.observe({ entryTypes: [observe], buffered: true });

const timerfied = performance.timerify(randomFn);

bench.start();
for (let i = 0; i < n; i++)
_result = timerfied();

// Avoid V8 deadcode (elimination)
assert.ok(_result);
}
23 changes: 23 additions & 0 deletions benchmark/url/whatwg-url-validity.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
'use strict';
const common = require('../common.js');
const url = require('url');
const URL = url.URL;

const bench = common.createBenchmark(main, {
type: ['valid', 'invalid'],
e: [1e5],
});

// This benchmark is used to compare the `Invalid URL` path of the URL parser
function main({ type, e }) {
const url = type === 'valid' ? 'https://www.nodejs.org' : 'www.nodejs.org';
bench.start();
for (let i = 0; i < e; i++) {
try {
new URL(url);
} catch {
// do nothing
}
}
bench.end(e);
}
2 changes: 1 addition & 1 deletion common.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

# Reset this number to 0 on major V8 upgrades.
# Increment by one for each non-official patch applied to deps/v8.
'v8_embedder_string': '-node.15',
'v8_embedder_string': '-node.16',

##### V8 defaults for Node.js #####

Expand Down
17 changes: 17 additions & 0 deletions deps/v8/include/v8-object.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ class Function;
class FunctionTemplate;
template <typename T>
class PropertyCallbackInfo;
class Module;
class UnboundScript;

/**
* A private symbol
Expand Down Expand Up @@ -480,6 +482,21 @@ class V8_EXPORT Object : public Value {
/** Sets the value in an internal field. */
void SetInternalField(int index, Local<Value> value);

/**
* Warning: These are Node.js-specific extentions used to avoid breaking
* changes in Node.js v20.x. They do not exist in V8 upstream and will
* not exist in Node.js v21.x. Node.js embedders and addon authors should
* not use them from v20.x.
*/
#ifndef NODE_WANT_INTERNALS
V8_DEPRECATED("This extention should only be used by Node.js core")
#endif
void SetInternalFieldForNodeCore(int index, Local<Module> value);
#ifndef NODE_WANT_INTERNALS
V8_DEPRECATED("This extention should only be used by Node.js core")
#endif
void SetInternalFieldForNodeCore(int index, Local<UnboundScript> value);

/**
* Gets a 2-byte-aligned native pointer from an internal field. This field
* must have been set by SetAlignedPointerInInternalField, everything else
Expand Down
23 changes: 21 additions & 2 deletions deps/v8/src/api/api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6338,14 +6338,33 @@ Local<Value> v8::Object::SlowGetInternalField(int index) {
return Utils::ToLocal(value);
}

void v8::Object::SetInternalField(int index, v8::Local<Value> value) {
i::Handle<i::JSReceiver> obj = Utils::OpenHandle(this);
template<typename T>
void SetInternalFieldImpl(v8::Object* receiver, int index, v8::Local<T> value) {
i::Handle<i::JSReceiver> obj = Utils::OpenHandle(receiver);
const char* location = "v8::Object::SetInternalField()";
if (!InternalFieldOK(obj, index, location)) return;
i::Handle<i::Object> val = Utils::OpenHandle(*value);
i::Handle<i::JSObject>::cast(obj)->SetEmbedderField(index, *val);
}

void v8::Object::SetInternalField(int index, v8::Local<Value> value) {
SetInternalFieldImpl(this, index, value);
}

/**
* These are Node.js-specific extentions used to avoid breaking changes in
* Node.js v20.x.
*/
void v8::Object::SetInternalFieldForNodeCore(int index,
v8::Local<Module> value) {
SetInternalFieldImpl(this, index, value);
}

void v8::Object::SetInternalFieldForNodeCore(int index,
v8::Local<UnboundScript> value) {
SetInternalFieldImpl(this, index, value);
}

void* v8::Object::SlowGetAlignedPointerFromInternalField(int index) {
i::Handle<i::JSReceiver> obj = Utils::OpenHandle(this);
const char* location = "v8::Object::GetAlignedPointerFromInternalField()";
Expand Down