-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
src: fix timing of snapshot serialize callback #60434
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
Closed
Closed
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
0f2ecc3
src: add COUNT_GENERIC_USAGE utility for tests
joyeecheung 454caf1
src: fix timing of snapshot serialize callback
joyeecheung 998b033
fixup! src: fix timing of snapshot serialize callback
joyeecheung d6d4659
fixup! fixup! src: fix timing of snapshot serialize callback
joyeecheung File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -8,6 +8,7 @@ | |||||
| #include "v8-fast-api-calls.h" | ||||||
| #include "v8.h" | ||||||
|
|
||||||
| #include <string> | ||||||
| #include <string_view> | ||||||
| #include <unordered_map> | ||||||
| #endif // DEBUG | ||||||
|
|
@@ -23,9 +24,20 @@ using v8::Number; | |||||
| using v8::Object; | ||||||
| using v8::Value; | ||||||
|
|
||||||
| thread_local std::unordered_map<std::string, int> generic_usage_counters; | ||||||
| thread_local std::unordered_map<FastStringKey, int, FastStringKey::Hash> | ||||||
| v8_fast_api_call_counts; | ||||||
|
|
||||||
| void CountGenericUsage(const char* counter_name) { | ||||||
| if (generic_usage_counters.find(counter_name) == generic_usage_counters.end()) | ||||||
| generic_usage_counters[counter_name] = 0; | ||||||
|
Comment on lines
+32
to
+33
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
... since this doesn't actually do anything, right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. will do a separate PR – #60447 |
||||||
| generic_usage_counters[counter_name]++; | ||||||
| } | ||||||
|
|
||||||
| int GetGenericUsageCount(const char* counter_name) { | ||||||
| return generic_usage_counters[counter_name]; | ||||||
| } | ||||||
|
|
||||||
| void TrackV8FastApiCall(FastStringKey key) { | ||||||
| v8_fast_api_call_counts[key]++; | ||||||
| } | ||||||
|
|
@@ -34,6 +46,17 @@ int GetV8FastApiCallCount(FastStringKey key) { | |||||
| return v8_fast_api_call_counts[key]; | ||||||
| } | ||||||
|
|
||||||
| void GetGenericUsageCount(const FunctionCallbackInfo<Value>& args) { | ||||||
| Environment* env = Environment::GetCurrent(args); | ||||||
| if (!args[0]->IsString()) { | ||||||
| env->ThrowError("getGenericUsageCount must be called with a string"); | ||||||
| return; | ||||||
| } | ||||||
| Utf8Value utf8_key(env->isolate(), args[0]); | ||||||
| args.GetReturnValue().Set( | ||||||
| GetGenericUsageCount(utf8_key.ToStringView().data())); | ||||||
| } | ||||||
|
|
||||||
| void GetV8FastApiCallCount(const FunctionCallbackInfo<Value>& args) { | ||||||
| Environment* env = Environment::GetCurrent(args); | ||||||
| if (!args[0]->IsString()) { | ||||||
|
|
@@ -89,6 +112,7 @@ void Initialize(Local<Object> target, | |||||
| Local<Context> context, | ||||||
| void* priv) { | ||||||
| SetMethod(context, target, "getV8FastApiCallCount", GetV8FastApiCallCount); | ||||||
| SetMethod(context, target, "getGenericUsageCount", GetGenericUsageCount); | ||||||
| SetFastMethod(context, target, "isEven", SlowIsEven, &fast_is_even); | ||||||
| SetFastMethod(context, target, "isOdd", SlowIsOdd, &fast_is_odd); | ||||||
| } | ||||||
|
|
||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
test/parallel/test-buffer-alloc-unsafe-is-initialized-with-zero-fill-flag.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| // Flags: --expose-internals --zero-fill-buffers | ||
| // Verifies that Buffer.allocUnsafe() allocates initialized memory under --zero-fill-buffers by | ||
| // checking the usage count of the relevant native allocator code path. | ||
| 'use strict'; | ||
|
|
||
| const common = require('../common'); | ||
| if (!common.isDebug) { | ||
| common.skip('Only works in debug mode'); | ||
| } | ||
| const { internalBinding } = require('internal/test/binding'); | ||
| const { getGenericUsageCount } = internalBinding('debug'); | ||
| const assert = require('assert'); | ||
|
|
||
| const initialCount = getGenericUsageCount('NodeArrayBufferAllocator.Allocate.ZeroFilled'); | ||
| const buffer = Buffer.allocUnsafe(Buffer.poolSize + 1); | ||
| assert.strictEqual(buffer.every((b) => b === 0), true); | ||
| const newCount = getGenericUsageCount('NodeArrayBufferAllocator.Allocate.ZeroFilled'); | ||
| assert.notStrictEqual(newCount, initialCount); |
20 changes: 20 additions & 0 deletions
20
test/parallel/test-buffer-alloc-unsafe-is-uninitialized.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| // Flags: --expose-internals | ||
joyeecheung marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| // Verifies that Buffer.allocUnsafe() indeed allocates uninitialized memory by checking | ||
| // the usage count of the relevant native allocator code path. | ||
| 'use strict'; | ||
|
|
||
| const common = require('../common'); | ||
| if (!common.isDebug) { | ||
| common.skip('Only works in debug mode'); | ||
| } | ||
| const { internalBinding } = require('internal/test/binding'); | ||
| const { getGenericUsageCount } = internalBinding('debug'); | ||
| const assert = require('assert'); | ||
|
|
||
| const initialCount = getGenericUsageCount('NodeArrayBufferAllocator.Allocate.Uninitialized'); | ||
| Buffer.allocUnsafe(Buffer.poolSize + 1); | ||
| // We can't reliably check the contents of the buffer here because the OS or memory allocator | ||
| // used might zero-fill memory for us, or they might happen to return reused memory that was | ||
| // previously used by a process that zero-filled it. | ||
| const newCount = getGenericUsageCount('NodeArrayBufferAllocator.Allocate.Uninitialized'); | ||
| assert.notStrictEqual(newCount, initialCount); | ||
aduh95 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's make this use
FastStringKeyas well, that is useful here for the same reason as it is for fast API call count tracking