Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
[squash] bnoordhuis comments
  • Loading branch information
addaleax committed Dec 21, 2017
commit 24c80e7a803fa812e1608ecf1ea274218c2771f3
8 changes: 3 additions & 5 deletions lib/internal/async_hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ const active_hooks = {
// for a given step, that step can bail out early.
const { kInit, kBefore, kAfter, kDestroy, kPromiseResolve,
kCheck, kExecutionAsyncId, kAsyncIdCounter, kTriggerAsyncId,
kDefaultTriggerAsyncId, kStackLength,
kStackCapacity } = async_wrap.constants;
kDefaultTriggerAsyncId, kStackLength } = async_wrap.constants;

// Used in AsyncHook and AsyncResource.
const init_symbol = Symbol('init');
Expand Down Expand Up @@ -341,10 +340,9 @@ function emitDestroyScript(asyncId) {

// This is the equivalent of the native push_async_ids() call.
function pushAsyncIds(asyncId, triggerAsyncId) {
Comment thread
AndreasMadsen marked this conversation as resolved.
const stackLength = async_hook_fields[kStackLength];
if (stackLength >= async_hook_fields[kStackCapacity])
const offset = async_hook_fields[kStackLength];
if (offset * 2 >= async_wrap.async_ids_stack.length)
return pushAsyncIds_(asyncId, triggerAsyncId);
const offset = stackLength;
async_wrap.async_ids_stack[offset * 2] = async_id_fields[kExecutionAsyncId];
async_wrap.async_ids_stack[offset * 2 + 1] = async_id_fields[kTriggerAsyncId];
async_hook_fields[kStackLength]++;
Expand Down
4 changes: 4 additions & 0 deletions src/aliased_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,10 @@ class AliasedBuffer {
return GetValue(index);
}

size_t Length() const {
return count_;
}

private:
v8::Isolate* isolate_;
size_t count_;
Expand Down
1 change: 0 additions & 1 deletion src/async_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,6 @@ void AsyncWrap::Initialize(Local<Object> target,
SET_HOOKS_CONSTANT(kAsyncIdCounter);
SET_HOOKS_CONSTANT(kDefaultTriggerAsyncId);
SET_HOOKS_CONSTANT(kStackLength);
SET_HOOKS_CONSTANT(kStackCapacity);
#undef SET_HOOKS_CONSTANT
FORCE_SET_TARGET_FIELD(target, "constants", constants);

Expand Down
6 changes: 1 addition & 5 deletions src/env-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,6 @@ inline Environment::AsyncHooks::AsyncHooks()
// and flag changes won't be included.
fields_[kCheck] = 1;

// async_ids_stack_ was initialized to store 16 async_context structs.
fields_[kStackCapacity] = 16;

// kDefaultTriggerAsyncId should be -1, this indicates that there is no
// specified default value and it should fallback to the executionAsyncId.
// 0 is not used as the magic value, because that indicates a missing context
Expand Down Expand Up @@ -133,7 +130,7 @@ inline void Environment::AsyncHooks::push_async_ids(double async_id,
}

uint32_t offset = fields_[kStackLength];
if (offset >= fields_[kStackCapacity])
if (offset * 2 >= async_ids_stack_.Length())
grow_async_ids_stack();
async_ids_stack_[2 * offset] = async_id_fields_[kExecutionAsyncId];
async_ids_stack_[2 * offset + 1] = async_id_fields_[kTriggerAsyncId];
Expand Down Expand Up @@ -168,7 +165,6 @@ inline bool Environment::AsyncHooks::pop_async_id(double async_id) {
}

uint32_t offset = fields_[kStackLength] - 1;
CHECK_LT(offset, fields_[kStackCapacity]);
async_id_fields_[kExecutionAsyncId] = async_ids_stack_[2 * offset];
async_id_fields_[kTriggerAsyncId] = async_ids_stack_[2 * offset + 1];
fields_[kStackLength] = offset;
Expand Down
3 changes: 1 addition & 2 deletions src/env.cc
Original file line number Diff line number Diff line change
Expand Up @@ -405,15 +405,14 @@ void Environment::CollectUVExceptionInfo(v8::Local<v8::Value> object,


void Environment::AsyncHooks::grow_async_ids_stack() {
const uint32_t old_capacity = fields_[kStackCapacity];
const uint32_t old_capacity = async_ids_stack_.Length() / 2;
const uint32_t new_capacity = old_capacity * 1.5;
AliasedBuffer<double, v8::Float64Array> new_buffer(
env()->isolate(), new_capacity * 2);

for (uint32_t i = 0; i < old_capacity * 2; ++i)
new_buffer[i] = async_ids_stack_[i];
async_ids_stack_ = std::move(new_buffer);
fields_[kStackCapacity] = new_capacity;

env()->async_hooks_binding()->Set(
env()->context(),
Expand Down
2 changes: 0 additions & 2 deletions src/env.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
#include <map>
#include <stdint.h>
#include <vector>
#include <stack>
#include <unordered_map>

struct nghttp2_rcbuf;
Expand Down Expand Up @@ -372,7 +371,6 @@ class Environment {
kTotals,
kCheck,
kStackLength,
kStackCapacity,
kFieldsCount,
};

Expand Down