src: use predefined AliasedBuffer types in the code base by joyeecheung · Pull Request #27334 · nodejs/node · GitHub
Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 31 additions & 27 deletions src/aliased_buffer.h
24 changes: 9 additions & 15 deletions src/env-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,16 +101,15 @@ inline AsyncHooks::AsyncHooks()
NODE_ASYNC_PROVIDER_TYPES(V)
#undef V
}

inline AliasedBuffer<uint32_t, v8::Uint32Array>& AsyncHooks::fields() {
inline AliasedUint32Array& AsyncHooks::fields() {
return fields_;
}

inline AliasedBuffer<double, v8::Float64Array>& AsyncHooks::async_id_fields() {
inline AliasedFloat64Array& AsyncHooks::async_id_fields() {
return async_id_fields_;
}

inline AliasedBuffer<double, v8::Float64Array>& AsyncHooks::async_ids_stack() {
inline AliasedFloat64Array& AsyncHooks::async_ids_stack() {
return async_ids_stack_;
}

Expand Down Expand Up @@ -235,8 +234,7 @@ inline void Environment::PopAsyncCallbackScope() {
inline ImmediateInfo::ImmediateInfo(v8::Isolate* isolate)
: fields_(isolate, kFieldsCount) {}

inline AliasedBuffer<uint32_t, v8::Uint32Array>&
ImmediateInfo::fields() {
inline AliasedUint32Array& ImmediateInfo::fields() {
return fields_;
}

Expand Down Expand Up @@ -271,7 +269,7 @@ inline void ImmediateInfo::ref_count_dec(uint32_t decrement) {
inline TickInfo::TickInfo(v8::Isolate* isolate)
: fields_(isolate, kFieldsCount) {}

inline AliasedBuffer<uint8_t, v8::Uint8Array>& TickInfo::fields() {
inline AliasedUint8Array& TickInfo::fields() {
return fields_;
}

Expand Down Expand Up @@ -478,13 +476,11 @@ inline void Environment::set_abort_on_uncaught_exception(bool value) {
options_->abort_on_uncaught_exception = value;
}

inline AliasedBuffer<uint32_t, v8::Uint32Array>&
Environment::should_abort_on_uncaught_toggle() {
inline AliasedUint32Array& Environment::should_abort_on_uncaught_toggle() {
return should_abort_on_uncaught_toggle_;
}

inline AliasedBuffer<int32_t, v8::Int32Array>&
Environment::stream_base_state() {
inline AliasedInt32Array& Environment::stream_base_state() {
return stream_base_state_;
}

Expand Down Expand Up @@ -614,13 +610,11 @@ void Environment::set_debug_enabled(DebugCategory category, bool enabled) {
debug_enabled_[static_cast<int>(category)] = enabled;
}

inline AliasedBuffer<double, v8::Float64Array>*
Environment::fs_stats_field_array() {
inline AliasedFloat64Array* Environment::fs_stats_field_array() {
return &fs_stats_field_array_;
}

inline AliasedBuffer<uint64_t, v8::BigUint64Array>*
Environment::fs_stats_field_bigint_array() {
inline AliasedBigUint64Array* Environment::fs_stats_field_bigint_array() {
return &fs_stats_field_bigint_array_;
}

Expand Down
38 changes: 18 additions & 20 deletions src/env.h
Original file line number Diff line number Diff line change
Expand Up @@ -605,9 +605,9 @@ class AsyncHooks : public MemoryRetainer {
kUidFieldsCount,
};

inline AliasedBuffer<uint32_t, v8::Uint32Array>& fields();
inline AliasedBuffer<double, v8::Float64Array>& async_id_fields();
inline AliasedBuffer<double, v8::Float64Array>& async_ids_stack();
inline AliasedUint32Array& fields();
inline AliasedFloat64Array& async_id_fields();
inline AliasedFloat64Array& async_ids_stack();

inline v8::Local<v8::String> provider_string(int idx);

Expand Down Expand Up @@ -646,12 +646,12 @@ class AsyncHooks : public MemoryRetainer {
// Keep a list of all Persistent strings used for Provider types.
std::array<v8::Eternal<v8::String>, AsyncWrap::PROVIDERS_LENGTH> providers_;
// Stores the ids of the current execution context stack.
AliasedBuffer<double, v8::Float64Array> async_ids_stack_;
AliasedFloat64Array async_ids_stack_;
// Attached to a Uint32Array that tracks the number of active hooks for
// each type.
AliasedBuffer<uint32_t, v8::Uint32Array> fields_;
AliasedUint32Array fields_;
// Attached to a Float64Array that tracks the state of async resources.
AliasedBuffer<double, v8::Float64Array> async_id_fields_;
AliasedFloat64Array async_id_fields_;

void grow_async_ids_stack();
};
Expand All @@ -670,7 +670,7 @@ class AsyncCallbackScope {

class ImmediateInfo : public MemoryRetainer {
public:
inline AliasedBuffer<uint32_t, v8::Uint32Array>& fields();
inline AliasedUint32Array& fields();
inline uint32_t count() const;
inline uint32_t ref_count() const;
inline bool has_outstanding() const;
Expand All @@ -692,12 +692,12 @@ class ImmediateInfo : public MemoryRetainer {

enum Fields { kCount, kRefCount, kHasOutstanding, kFieldsCount };

AliasedBuffer<uint32_t, v8::Uint32Array> fields_;
AliasedUint32Array fields_;
};

class TickInfo : public MemoryRetainer {
public:
inline AliasedBuffer<uint8_t, v8::Uint8Array>& fields();
inline AliasedUint8Array& fields();
inline bool has_tick_scheduled() const;
inline bool has_rejection_to_warn() const;

Expand All @@ -714,7 +714,7 @@ class TickInfo : public MemoryRetainer {

enum Fields { kHasTickScheduled = 0, kHasRejectionToWarn, kFieldsCount };

AliasedBuffer<uint8_t, v8::Uint8Array> fields_;
AliasedUint8Array fields_;
};

class TrackingTraceStateObserver :
Expand Down Expand Up @@ -902,10 +902,9 @@ class Environment : public MemoryRetainer {
// This is a pseudo-boolean that keeps track of whether an uncaught exception
// should abort the process or not if --abort-on-uncaught-exception was
// passed to Node. If the flag was not passed, it is ignored.
inline AliasedBuffer<uint32_t, v8::Uint32Array>&
should_abort_on_uncaught_toggle();
inline AliasedUint32Array& should_abort_on_uncaught_toggle();

inline AliasedBuffer<int32_t, v8::Int32Array>& stream_base_state();
inline AliasedInt32Array& stream_base_state();

// The necessary API for async_hooks.
inline double new_async_id();
Expand Down Expand Up @@ -951,9 +950,8 @@ class Environment : public MemoryRetainer {
inline void set_debug_enabled(DebugCategory category, bool enabled);
void set_debug_categories(const std::string& cats, bool enabled);

inline AliasedBuffer<double, v8::Float64Array>* fs_stats_field_array();
inline AliasedBuffer<uint64_t, v8::BigUint64Array>*
fs_stats_field_bigint_array();
inline AliasedFloat64Array* fs_stats_field_array();
inline AliasedBigUint64Array* fs_stats_field_bigint_array();

inline std::vector<std::unique_ptr<fs::FileHandleReadWrap>>&
file_handle_read_wrap_freelist();
Expand Down Expand Up @@ -1192,12 +1190,12 @@ class Environment : public MemoryRetainer {
uint32_t script_id_counter_ = 0;
uint32_t function_id_counter_ = 0;

AliasedBuffer<uint32_t, v8::Uint32Array> should_abort_on_uncaught_toggle_;
AliasedUint32Array should_abort_on_uncaught_toggle_;
int should_not_abort_scope_counter_ = 0;

std::unique_ptr<TrackingTraceStateObserver> trace_state_observer_;

AliasedBuffer<int32_t, v8::Int32Array> stream_base_state_;
AliasedInt32Array stream_base_state_;

std::unique_ptr<performance::performance_state> performance_state_;
std::unordered_map<std::string, uint64_t> performance_marks_;
Expand Down Expand Up @@ -1240,8 +1238,8 @@ class Environment : public MemoryRetainer {

bool debug_enabled_[static_cast<int>(DebugCategory::CATEGORY_COUNT)] = {0};

AliasedBuffer<double, v8::Float64Array> fs_stats_field_array_;
AliasedBuffer<uint64_t, v8::BigUint64Array> fs_stats_field_bigint_array_;
AliasedFloat64Array fs_stats_field_array_;
AliasedBigUint64Array fs_stats_field_bigint_array_;

std::vector<std::unique_ptr<fs::FileHandleReadWrap>>
file_handle_read_wrap_freelist_;
Expand Down
2 changes: 1 addition & 1 deletion src/memory_tracker-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ void MemoryTracker::TrackField(const char* name,

template <class NativeT, class V8T>
void MemoryTracker::TrackField(const char* name,
const AliasedBuffer<NativeT, V8T>& value,
const AliasedBufferBase<NativeT, V8T>& value,
const char* node_name) {
TrackField(name, value.GetJSArray(), "AliasedBuffer");
}
Expand Down
2 changes: 1 addition & 1 deletion src/memory_tracker.h
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ class MemoryTracker {
const char* node_name = nullptr);
template <class NativeT, class V8T>
inline void TrackField(const char* edge_name,
const AliasedBuffer<NativeT, V8T>& value,
const AliasedBufferBase<NativeT, V8T>& value,
const char* node_name = nullptr);

// Put a memory container into the graph, create an edge from
Expand Down
4 changes: 2 additions & 2 deletions src/node_file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -756,9 +756,9 @@ inline FSReqBase* GetReqWrap(Environment* env, Local<Value> value,
return Unwrap<FSReqBase>(value.As<Object>());
} else if (value->StrictEquals(env->fs_use_promises_symbol())) {
if (use_bigint) {
return FSReqPromise<uint64_t, BigUint64Array>::New(env, use_bigint);
return FSReqPromise<AliasedBigUint64Array>::New(env, use_bigint);
} else {
return FSReqPromise<double, Float64Array>::New(env, use_bigint);
return FSReqPromise<AliasedFloat64Array>::New(env, use_bigint);
}
}
return nullptr;
Expand Down
9 changes: 5 additions & 4 deletions src/node_file.h
Loading