Skip to content

Commit 8eec4e0

Browse files
committed
src: modernize likely/unlikely hints
nodejs/node#55155
1 parent 2a1c1ec commit 8eec4e0

File tree

2 files changed

+35
-56
lines changed

2 files changed

+35
-56
lines changed

patches/node/build_enable_perfetto.patch

Lines changed: 14 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -285,22 +285,8 @@ index 8f053efe93324b9acbb4e85f7b974b4f7712e200..e331ed5567caa39ade90ce28cea69f1d
285285
void NodeTraceWriter::FlushPrivate() {
286286
std::string str;
287287
int highest_request_id;
288-
diff --git a/src/tracing/node_trace_writer.h b/src/tracing/node_trace_writer.h
289-
index cd965d77b7859ff2edcf781a934594b5a9b6d251..fe1714ba77fddef693d37eeb8c7a196ddfd15c26 100644
290-
--- a/src/tracing/node_trace_writer.h
291-
+++ b/src/tracing/node_trace_writer.h
292-
@@ -20,7 +20,9 @@ class NodeTraceWriter : public AsyncTraceWriter {
293-
~NodeTraceWriter() override;
294-
295-
void InitializeOnThread(uv_loop_t* loop) override;
296-
+#ifndef V8_USE_PERFETTO
297-
void AppendTraceEvent(TraceObject* trace_event) override;
298-
+#endif
299-
void Flush(bool blocking) override;
300-
301-
static const int kTracesPerFile = 1 << 19;
302288
diff --git a/src/tracing/trace_event.h b/src/tracing/trace_event.h
303-
index be0f55a409a71bf9c1763c36fdc252857228742e..827b5330b2f8c545338a46c548f8abf4aab7f50c 100644
289+
index a662a081dc3bf356bf93e4063fcb043e4d8df07b..c89cdfe2b2681fbf9946200a03d7d1f7bad21226 100644
304290
--- a/src/tracing/trace_event.h
305291
+++ b/src/tracing/trace_event.h
306292
@@ -69,8 +69,16 @@ enum CategoryGroupEnabledFlags {
@@ -336,36 +322,31 @@ index be0f55a409a71bf9c1763c36fdc252857228742e..827b5330b2f8c545338a46c548f8abf4
336322

337323
// Adds a metadata event to the trace log. The |AppendValueAsTraceFormat| method
338324
// on the convertable value will be called at flush time.
339-
@@ -319,10 +332,13 @@ class TraceEventHelper {
325+
@@ -319,12 +332,15 @@ class TraceEventHelper {
340326
static void SetAgent(Agent* agent);
341327

342328
static inline const uint8_t* GetCategoryGroupEnabled(const char* group) {
343329
+#ifndef V8_USE_PERFETTO
344330
v8::TracingController* controller = GetTracingController();
345331
static const uint8_t disabled = 0;
346-
if (UNLIKELY(controller == nullptr)) return &disabled;
332+
if (controller == nullptr) [[unlikely]] {
333+
return &disabled;
334+
}
347335
return controller->GetCategoryGroupEnabled(group);
348336
+#endif
349337
+ return 0;
350338
}
351339
};
352340

353-
@@ -460,6 +476,7 @@ static inline uint64_t AddTraceEventImpl(
341+
@@ -462,6 +478,7 @@ static inline uint64_t AddTraceEventImpl(
354342
const char* scope, uint64_t id, uint64_t bind_id, int32_t num_args,
355343
const char** arg_names, const uint8_t* arg_types,
356344
const uint64_t* arg_values, unsigned int flags) {
357345
+#ifndef V8_USE_PERFETTO
358346
std::unique_ptr<v8::ConvertableToTraceFormat> arg_convertibles[2];
359347
if (num_args > 0 && arg_types[0] == TRACE_VALUE_TYPE_CONVERTABLE) {
360348
arg_convertibles[0].reset(reinterpret_cast<v8::ConvertableToTraceFormat*>(
361-
@@ -469,13 +486,14 @@ static inline uint64_t AddTraceEventImpl(
362-
arg_convertibles[1].reset(reinterpret_cast<v8::ConvertableToTraceFormat*>(
363-
static_cast<intptr_t>(arg_values[1])));
364-
}
365-
- // DCHECK(num_args, 2);
366-
v8::TracingController* controller =
367-
node::tracing::TraceEventHelper::GetTracingController();
368-
if (controller == nullptr) return 0;
349+
@@ -478,6 +495,8 @@ static inline uint64_t AddTraceEventImpl(
369350
return controller->AddTraceEvent(phase, category_group_enabled, name, scope, id,
370351
bind_id, num_args, arg_names, arg_types,
371352
arg_values, arg_convertibles, flags);
@@ -374,25 +355,18 @@ index be0f55a409a71bf9c1763c36fdc252857228742e..827b5330b2f8c545338a46c548f8abf4
374355
}
375356

376357
static V8_INLINE uint64_t AddTraceEventWithTimestampImpl(
377-
@@ -483,6 +501,7 @@ static V8_INLINE uint64_t AddTraceEventWithTimestampImpl(
358+
@@ -485,6 +504,7 @@ static V8_INLINE uint64_t AddTraceEventWithTimestampImpl(
378359
const char* scope, uint64_t id, uint64_t bind_id, int32_t num_args,
379360
const char** arg_names, const uint8_t* arg_types,
380361
const uint64_t* arg_values, unsigned int flags, int64_t timestamp) {
381362
+#ifndef V8_USE_PERFETTO
382-
std::unique_ptr<v8::ConvertableToTraceFormat> arg_convertables[2];
363+
std::unique_ptr<v8::ConvertableToTraceFormat> arg_convertibles[2];
383364
if (num_args > 0 && arg_types[0] == TRACE_VALUE_TYPE_CONVERTABLE) {
384-
arg_convertables[0].reset(reinterpret_cast<v8::ConvertableToTraceFormat*>(
385-
@@ -492,19 +511,21 @@ static V8_INLINE uint64_t AddTraceEventWithTimestampImpl(
386-
arg_convertables[1].reset(reinterpret_cast<v8::ConvertableToTraceFormat*>(
387-
static_cast<intptr_t>(arg_values[1])));
388-
}
389-
- // DCHECK_LE(num_args, 2);
390-
v8::TracingController* controller =
391-
node::tracing::TraceEventHelper::GetTracingController();
392-
if (controller == nullptr) return 0;
365+
arg_convertibles[0].reset(reinterpret_cast<v8::ConvertableToTraceFormat*>(
366+
@@ -501,12 +521,15 @@ static V8_INLINE uint64_t AddTraceEventWithTimestampImpl(
393367
return controller->AddTraceEventWithTimestamp(
394368
phase, category_group_enabled, name, scope, id, bind_id, num_args,
395-
arg_names, arg_types, arg_values, arg_convertables, flags, timestamp);
369+
arg_names, arg_types, arg_values, arg_convertibles, flags, timestamp);
396370
+#endif
397371
+ return 0;
398372
}
@@ -405,11 +379,12 @@ index be0f55a409a71bf9c1763c36fdc252857228742e..827b5330b2f8c545338a46c548f8abf4
405379
std::unique_ptr<v8::ConvertableToTraceFormat> arg_convertibles[2];
406380
if (num_args > 0 && arg_types[0] == TRACE_VALUE_TYPE_CONVERTABLE) {
407381
arg_convertibles[0].reset(reinterpret_cast<v8::ConvertableToTraceFormat*>(
408-
@@ -520,6 +541,7 @@ static V8_INLINE void AddMetadataEventImpl(
382+
@@ -522,6 +545,7 @@ static V8_INLINE void AddMetadataEventImpl(
409383
return agent->GetTracingController()->AddMetadataEvent(
410384
category_group_enabled, name, num_args, arg_names, arg_types, arg_values,
411385
arg_convertibles, flags);
412386
+#endif
413387
}
414388

415389
// Define SetTraceValue for each allowed type. It stores the type and
390+

patches/node/src_stop_using_deprecated_fields_of_fastapicallbackoptions.patch

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,13 @@ index 4dbdea9be5721486d71a9dda77311b4919d450a3..4aacaa2a5d12533a039b4b96cb7f1fd7
4040
}
4141
HistogramBase* histogram;
4242
diff --git a/src/node_file.cc b/src/node_file.cc
43-
index b565beae625d970ba92ab667a145d8897d4e8a6e..31c2fe82299d6905855c4efffeea4a4d161a88d5 100644
43+
index 6b98a13099990918dc619c47124c8538bbee5e2d..307492bf3dfce7b4a476c448bec666b8116dc431 100644
4444
--- a/src/node_file.cc
4545
+++ b/src/node_file.cc
46-
@@ -1049,23 +1049,10 @@ static int32_t FastInternalModuleStat(
47-
const FastOneByteString& input,
46+
@@ -1060,22 +1060,10 @@ static int32_t FastInternalModuleStat(
4847
// NOLINTNEXTLINE(runtime/references) This is V8 api.
4948
FastApiCallbackOptions& options) {
50-
- // This needs a HandleScope which needs an isolate.
49+
// This needs a HandleScope which needs an isolate.
5150
- Isolate* isolate = Isolate::TryGetCurrent();
5251
- if (!isolate) {
5352
- options.fallback = true;
@@ -60,34 +59,39 @@ index b565beae625d970ba92ab667a145d8897d4e8a6e..31c2fe82299d6905855c4efffeea4a4d
6059
+ HandleScope scope(env->isolate());
6160

6261
auto path = std::filesystem::path(input.data, input.data + input.length);
63-
- if (UNLIKELY(!env->permission()->is_granted(
64-
- env, permission::PermissionScope::kFileSystemRead, path.string()))) {
62+
- if (!env->permission()->is_granted(
63+
- env, permission::PermissionScope::kFileSystemRead, path.string()))
64+
- [[unlikely]] {
6565
- options.fallback = true;
6666
- return -1;
6767
- }
68-
-
68+
6969
switch (std::filesystem::status(path).type()) {
7070
case std::filesystem::file_type::directory:
71-
return 1;
7271
diff --git a/src/node_wasi.cc b/src/node_wasi.cc
73-
index ad1da44a01f437c97e06a3857eebd2edcebc83da..7123278e1a0942b61a76e9b1e7464eb8b5064079 100644
72+
index 468c2e59903fefe58d9c178d3afac3ef5b09f611..9788b8fa4dd949c3625548179546f645bc9493c5 100644
7473
--- a/src/node_wasi.cc
7574
+++ b/src/node_wasi.cc
76-
@@ -248,17 +248,18 @@ R WASI::WasiFunction<FT, F, R, Args...>::FastCallback(
77-
WASI* wasi = reinterpret_cast<WASI*>(BaseObject::FromJSObject(receiver));
78-
if (UNLIKELY(wasi == nullptr)) return EinvalError<R>();
79-
80-
- if (UNLIKELY(options.wasm_memory == nullptr || wasi->memory_.IsEmpty())) {
81-
- // fallback to slow path which to throw an error about missing memory.
82-
- options.fallback = true;
75+
@@ -246,22 +246,19 @@ R WASI::WasiFunction<FT, F, R, Args...>::FastCallback(
76+
Args... args,
77+
// NOLINTNEXTLINE(runtime/references) This is V8 api.
78+
FastApiCallbackOptions& options) {
79+
- WASI* wasi = reinterpret_cast<WASI*>(BaseObject::FromJSObject(receiver));
80+
- if (wasi == nullptr) [[unlikely]] {
8381
+ v8::Isolate* isolate = receiver->GetIsolate();
8482
+ v8::HandleScope handle_scope(isolate);
8583
+ if (wasi->memory_.IsEmpty()) {
8684
+ THROW_ERR_WASI_NOT_STARTED(isolate);
8785
return EinvalError<R>();
8886
}
87+
88+
- if (options.wasm_memory == nullptr || wasi->memory_.IsEmpty()) [[unlikely]] {
89+
- // fallback to slow path which to throw an error about missing memory.
90+
- options.fallback = true;
91+
- return EinvalError<R>();
92+
- }
8993
- uint8_t* memory = nullptr;
90-
- CHECK(LIKELY(options.wasm_memory->getStorageIfAligned(&memory)));
94+
- CHECK(options.wasm_memory->getStorageIfAligned(&memory));
9195
+ Local<ArrayBuffer> ab = wasi->memory_.Get(isolate)->Buffer();
9296
+ size_t mem_size = ab->ByteLength();
9397
+ char* mem_data = static_cast<char*>(ab->Data());

0 commit comments

Comments
 (0)