-
-
Couldn't load subscription status.
- Fork 33.6k
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
Changes from 2 commits
0f2ecc3
454caf1
998b033
d6d4659
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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); | ||||||
| } | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| // 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); | ||
| const newCount = getGenericUsageCount('NodeArrayBufferAllocator.Allocate.Uninitialized'); | ||
| assert.notStrictEqual(newCount, initialCount); | ||
aduh95 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
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