Skip to content

Commit fe492c7

Browse files
Renegade334aduh95
authored andcommitted
process: fix hrtime fast call signatures
PR-URL: #59600 Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
1 parent 23468fd commit fe492c7

File tree

4 files changed

+55
-28
lines changed

4 files changed

+55
-28
lines changed

src/node_process.h

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
55

6+
#include "node_debug.h"
67
#include "node_snapshotable.h"
78
#include "v8-fast-api-calls.h"
89
#include "v8.h"
@@ -72,23 +73,23 @@ class BindingData : public SnapshotableObject {
7273
SET_SELF_SIZE(BindingData)
7374

7475
static BindingData* FromV8Value(v8::Local<v8::Value> receiver);
75-
static void NumberImpl(BindingData* receiver);
76+
static void HrtimeImpl(BindingData* receiver);
7677

77-
static void FastNumber(v8::Local<v8::Value> unused,
78-
v8::Local<v8::Value> receiver) {
79-
NumberImpl(FromV8Value(receiver));
78+
static void FastHrtime(v8::Local<v8::Value> receiver) {
79+
TRACK_V8_FAST_API_CALL("process.hrtime");
80+
HrtimeImpl(FromV8Value(receiver));
8081
}
8182

82-
static void SlowNumber(const v8::FunctionCallbackInfo<v8::Value>& args);
83+
static void SlowHrtime(const v8::FunctionCallbackInfo<v8::Value>& args);
8384

84-
static void BigIntImpl(BindingData* receiver);
85+
static void HrtimeBigIntImpl(BindingData* receiver);
8586

86-
static void FastBigInt(v8::Local<v8::Value> unused,
87-
v8::Local<v8::Value> receiver) {
88-
BigIntImpl(FromV8Value(receiver));
87+
static void FastHrtimeBigInt(v8::Local<v8::Value> receiver) {
88+
TRACK_V8_FAST_API_CALL("process.hrtimeBigInt");
89+
HrtimeBigIntImpl(FromV8Value(receiver));
8990
}
9091

91-
static void SlowBigInt(const v8::FunctionCallbackInfo<v8::Value>& args);
92+
static void SlowHrtimeBigInt(const v8::FunctionCallbackInfo<v8::Value>& args);
9293

9394
static void LoadEnvFile(const v8::FunctionCallbackInfo<v8::Value>& args);
9495

@@ -101,8 +102,8 @@ class BindingData : public SnapshotableObject {
101102
// These need to be static so that we have their addresses available to
102103
// register as external references in the snapshot at environment creation
103104
// time.
104-
static v8::CFunction fast_number_;
105-
static v8::CFunction fast_bigint_;
105+
static v8::CFunction fast_hrtime_;
106+
static v8::CFunction fast_hrtime_bigint_;
106107
};
107108

108109
} // namespace process

src/node_process_methods.cc

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -651,22 +651,22 @@ BindingData::BindingData(Realm* realm,
651651
hrtime_buffer_.MakeWeak();
652652
}
653653

654-
v8::CFunction BindingData::fast_number_(v8::CFunction::Make(FastNumber));
655-
v8::CFunction BindingData::fast_bigint_(v8::CFunction::Make(FastBigInt));
654+
CFunction BindingData::fast_hrtime_(CFunction::Make(FastHrtime));
655+
CFunction BindingData::fast_hrtime_bigint_(CFunction::Make(FastHrtimeBigInt));
656656

657657
void BindingData::AddMethods(Isolate* isolate, Local<ObjectTemplate> target) {
658658
SetFastMethodNoSideEffect(
659-
isolate, target, "hrtime", SlowNumber, &fast_number_);
659+
isolate, target, "hrtime", SlowHrtime, &fast_hrtime_);
660660
SetFastMethodNoSideEffect(
661-
isolate, target, "hrtimeBigInt", SlowBigInt, &fast_bigint_);
661+
isolate, target, "hrtimeBigInt", SlowHrtimeBigInt, &fast_hrtime_bigint_);
662662
}
663663

664664
void BindingData::RegisterExternalReferences(
665665
ExternalReferenceRegistry* registry) {
666-
registry->Register(SlowNumber);
667-
registry->Register(SlowBigInt);
668-
registry->Register(fast_number_);
669-
registry->Register(fast_bigint_);
666+
registry->Register(SlowHrtime);
667+
registry->Register(SlowHrtimeBigInt);
668+
registry->Register(fast_hrtime_);
669+
registry->Register(fast_hrtime_bigint_);
670670
}
671671

672672
BindingData* BindingData::FromV8Value(Local<Value> value) {
@@ -688,14 +688,14 @@ void BindingData::MemoryInfo(MemoryTracker* tracker) const {
688688
// broken into the upper/lower 32 bits to be converted back in JS,
689689
// because there is no Uint64Array in JS.
690690
// The third entry contains the remaining nanosecond part of the value.
691-
void BindingData::NumberImpl(BindingData* receiver) {
691+
void BindingData::HrtimeImpl(BindingData* receiver) {
692692
uint64_t t = uv_hrtime();
693693
receiver->hrtime_buffer_[0] = (t / NANOS_PER_SEC) >> 32;
694694
receiver->hrtime_buffer_[1] = (t / NANOS_PER_SEC) & 0xffffffff;
695695
receiver->hrtime_buffer_[2] = t % NANOS_PER_SEC;
696696
}
697697

698-
void BindingData::BigIntImpl(BindingData* receiver) {
698+
void BindingData::HrtimeBigIntImpl(BindingData* receiver) {
699699
uint64_t t = uv_hrtime();
700700
// The buffer is a Uint32Array, so we need to reinterpret it as a
701701
// Uint64Array to write the value. The buffer is valid at this scope so we
@@ -705,12 +705,12 @@ void BindingData::BigIntImpl(BindingData* receiver) {
705705
fields[0] = t;
706706
}
707707

708-
void BindingData::SlowBigInt(const FunctionCallbackInfo<Value>& args) {
709-
BigIntImpl(FromJSObject<BindingData>(args.This()));
708+
void BindingData::SlowHrtimeBigInt(const FunctionCallbackInfo<Value>& args) {
709+
HrtimeBigIntImpl(FromJSObject<BindingData>(args.This()));
710710
}
711711

712-
void BindingData::SlowNumber(const v8::FunctionCallbackInfo<v8::Value>& args) {
713-
NumberImpl(FromJSObject<BindingData>(args.This()));
712+
void BindingData::SlowHrtime(const FunctionCallbackInfo<Value>& args) {
713+
HrtimeImpl(FromJSObject<BindingData>(args.This()));
714714
}
715715

716716
bool BindingData::PrepareForSerialization(Local<Context> context,
Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,27 @@
1+
// Flags: --allow-natives-syntax --expose-internals --no-warnings
12
'use strict';
23

34
// Tests that process.hrtime.bigint() works.
45

5-
require('../common');
6+
const common = require('../common');
67
const assert = require('assert');
78

9+
const { internalBinding } = require('internal/test/binding');
10+
811
const start = process.hrtime.bigint();
912
assert.strictEqual(typeof start, 'bigint');
1013

1114
const end = process.hrtime.bigint();
1215
assert.strictEqual(typeof end, 'bigint');
1316

1417
assert(end - start >= 0n);
18+
19+
eval('%PrepareFunctionForOptimization(process.hrtime.bigint)');
20+
assert(process.hrtime.bigint());
21+
eval('%OptimizeFunctionOnNextCall(process.hrtime.bigint)');
22+
assert(process.hrtime.bigint());
23+
24+
if (common.isDebug) {
25+
const { getV8FastApiCallCount } = internalBinding('debug');
26+
assert.strictEqual(getV8FastApiCallCount('process.hrtimeBigInt'), 1);
27+
}

test/parallel/test-process-hrtime.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,13 @@
1919
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
2020
// USE OR OTHER DEALINGS IN THE SOFTWARE.
2121

22+
// Flags: --allow-natives-syntax --expose-internals --no-warnings
2223
'use strict';
23-
require('../common');
24+
const common = require('../common');
2425
const assert = require('assert');
2526

27+
const { internalBinding } = require('internal/test/binding');
28+
2629
// The default behavior, return an Array "tuple" of numbers
2730
const tuple = process.hrtime();
2831

@@ -72,3 +75,13 @@ function validateTuple(tuple) {
7275

7376
const diff = process.hrtime([0, 1e9 - 1]);
7477
assert(diff[1] >= 0); // https://github.com/nodejs/node/issues/4751
78+
79+
eval('%PrepareFunctionForOptimization(process.hrtime)');
80+
assert(process.hrtime());
81+
eval('%OptimizeFunctionOnNextCall(process.hrtime)');
82+
assert(process.hrtime());
83+
84+
if (common.isDebug) {
85+
const { getV8FastApiCallCount } = internalBinding('debug');
86+
assert.strictEqual(getV8FastApiCallCount('process.hrtime'), 1);
87+
}

0 commit comments

Comments
 (0)