Skip to content
This repository was archived by the owner on Oct 15, 2020. It is now read-only.

Commit 5298047

Browse files
chakrabotjackhorton
authored andcommitted
Merge nodejs/master
Merge 1c07724 as of 2017-10-28. This is an automatically created merge. For any problems please contact @kunalspathak.
2 parents 8eefbbb + 1c07724 commit 5298047

File tree

19 files changed

+90
-25
lines changed

19 files changed

+90
-25
lines changed

common.gypi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
# Reset this number to 0 on major V8 upgrades.
3131
# Increment by one for each non-official patch applied to deps/v8.
32-
'v8_embedder_string': '-node.4',
32+
'v8_embedder_string': '-node.7',
3333

3434
# Enable disassembler for `--print-code` v8 options
3535
'v8_enable_disassembler': 1,

deps/v8/src/heap/gc-tracer.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,8 @@ void GCTracer::PrintNVP() const {
490490
"promotion_rate=%.1f%% "
491491
"semi_space_copy_rate=%.1f%% "
492492
"new_space_allocation_throughput=%.1f "
493+
"unmapper_chunks=%d "
494+
"unmapper_delayed_chunks=%d "
493495
"context_disposal_rate=%.1f\n",
494496
duration, spent_in_mutator, current_.TypeName(true),
495497
current_.reduce_memory, current_.scopes[Scope::HEAP_PROLOGUE],
@@ -520,6 +522,8 @@ void GCTracer::PrintNVP() const {
520522
AverageSurvivalRatio(), heap_->promotion_rate_,
521523
heap_->semi_space_copied_rate_,
522524
NewSpaceAllocationThroughputInBytesPerMillisecond(),
525+
heap_->memory_allocator()->unmapper()->NumberOfChunks(),
526+
heap_->memory_allocator()->unmapper()->NumberOfDelayedChunks(),
523527
ContextDisposalRateInMilliseconds());
524528
break;
525529
case Event::MINOR_MARK_COMPACTOR:
@@ -654,6 +658,8 @@ void GCTracer::PrintNVP() const {
654658
"promotion_rate=%.1f%% "
655659
"semi_space_copy_rate=%.1f%% "
656660
"new_space_allocation_throughput=%.1f "
661+
"unmapper_chunks=%d "
662+
"unmapper_delayed_chunks=%d "
657663
"context_disposal_rate=%.1f "
658664
"compaction_speed=%.f\n",
659665
duration, spent_in_mutator, current_.TypeName(true),
@@ -731,6 +737,8 @@ void GCTracer::PrintNVP() const {
731737
AverageSurvivalRatio(), heap_->promotion_rate_,
732738
heap_->semi_space_copied_rate_,
733739
NewSpaceAllocationThroughputInBytesPerMillisecond(),
740+
heap_->memory_allocator()->unmapper()->NumberOfChunks(),
741+
heap_->memory_allocator()->unmapper()->NumberOfDelayedChunks(),
734742
ContextDisposalRateInMilliseconds(),
735743
CompactionSpeedInBytesPerMillisecond());
736744
break;

deps/v8/src/heap/heap.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1885,6 +1885,12 @@ void Heap::Scavenge() {
18851885
IncrementalMarking::PauseBlackAllocationScope pause_black_allocation(
18861886
incremental_marking());
18871887

1888+
if (mark_compact_collector()->sweeper().sweeping_in_progress() &&
1889+
memory_allocator_->unmapper()->NumberOfDelayedChunks() >
1890+
static_cast<int>(new_space_->MaximumCapacity() / Page::kPageSize)) {
1891+
mark_compact_collector()->EnsureSweepingCompleted();
1892+
}
1893+
18881894
mark_compact_collector()->sweeper().EnsureNewSpaceCompleted();
18891895

18901896
SetGCState(SCAVENGE);

deps/v8/src/heap/spaces.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,15 @@ void MemoryAllocator::Unmapper::ReconsiderDelayedChunks() {
408408
}
409409
}
410410

411+
int MemoryAllocator::Unmapper::NumberOfChunks() {
412+
base::LockGuard<base::Mutex> guard(&mutex_);
413+
size_t result = 0;
414+
for (int i = 0; i < kNumberOfChunkQueues; i++) {
415+
result += chunks_[i].size();
416+
}
417+
return static_cast<int>(result);
418+
}
419+
411420
bool MemoryAllocator::CanFreeMemoryChunk(MemoryChunk* chunk) {
412421
MarkCompactCollector* mc = isolate_->heap()->mark_compact_collector();
413422
// We cannot free a memory chunk in new space while the sweeper is running

deps/v8/src/heap/spaces.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1199,6 +1199,13 @@ class V8_EXPORT_PRIVATE MemoryAllocator {
11991199

12001200
bool has_delayed_chunks() { return delayed_regular_chunks_.size() > 0; }
12011201

1202+
int NumberOfDelayedChunks() {
1203+
base::LockGuard<base::Mutex> guard(&mutex_);
1204+
return static_cast<int>(delayed_regular_chunks_.size());
1205+
}
1206+
1207+
int NumberOfChunks();
1208+
12021209
private:
12031210
static const int kReservedQueueingSlots = 64;
12041211
static const int kMaxUnmapperTasks = 24;

lib/internal/loader/Loader.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@
22

33
const { getURLFromFilePath } = require('internal/url');
44

5-
const {
6-
getNamespaceOfModuleWrap,
7-
createDynamicModule
8-
} = require('internal/loader/ModuleWrap');
5+
const { createDynamicModule } = require('internal/loader/ModuleWrap');
96

107
const ModuleMap = require('internal/loader/ModuleMap');
118
const ModuleJob = require('internal/loader/ModuleJob');
@@ -100,7 +97,7 @@ class Loader {
10097
async import(specifier, parentURL = this.base) {
10198
const job = await this.getModuleJob(specifier, parentURL);
10299
const module = await job.run();
103-
return getNamespaceOfModuleWrap(module);
100+
return module.namespace();
104101
}
105102
}
106103
Object.setPrototypeOf(Loader.prototype, null);

lib/internal/loader/ModuleWrap.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,6 @@ const debug = require('util').debuglog('esm');
55
const ArrayJoin = Function.call.bind(Array.prototype.join);
66
const ArrayMap = Function.call.bind(Array.prototype.map);
77

8-
const getNamespaceOfModuleWrap = (m) => {
9-
const tmp = new ModuleWrap('import * as _ from "";_;', '');
10-
tmp.link(async () => m);
11-
tmp.instantiate();
12-
return tmp.evaluate();
13-
};
14-
158
const createDynamicModule = (exports, url = '', evaluate) => {
169
debug(
1710
`creating ESM facade for ${url} with exports: ${ArrayJoin(exports, ', ')}`
@@ -56,6 +49,5 @@ const createDynamicModule = (exports, url = '', evaluate) => {
5649

5750
module.exports = {
5851
createDynamicModule,
59-
getNamespaceOfModuleWrap,
6052
ModuleWrap
6153
};

lib/module.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -431,11 +431,12 @@ Module._load = function(request, parent, isMain) {
431431
ESMLoader = new Loader();
432432
const userLoader = process.binding('config').userLoader;
433433
if (userLoader) {
434-
const hooks = await new Loader().import(userLoader);
434+
const hooks = await ESMLoader.import(userLoader);
435+
ESMLoader = new Loader();
435436
ESMLoader.hook(hooks);
436437
}
437438
}
438-
await ESMLoader.import(getURLFromFilePath(request).href);
439+
await ESMLoader.import(getURLFromFilePath(request).pathname);
439440
})()
440441
.catch((e) => {
441442
console.error(e);

src/module_wrap.cc

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,29 @@ void ModuleWrap::Evaluate(const FunctionCallbackInfo<Value>& args) {
207207
args.GetReturnValue().Set(ret);
208208
}
209209

210+
void ModuleWrap::Namespace(const FunctionCallbackInfo<Value>& args) {
211+
Environment* env = Environment::GetCurrent(args);
212+
auto isolate = args.GetIsolate();
213+
auto that = args.This();
214+
ModuleWrap* obj = Unwrap<ModuleWrap>(that);
215+
CHECK_NE(obj, nullptr);
216+
217+
auto module = obj->module_.Get(isolate);
218+
219+
switch (module->GetStatus()) {
220+
default:
221+
return env->ThrowError(
222+
"cannot get namespace, Module has not been instantiated");
223+
case v8::Module::Status::kInstantiated:
224+
case v8::Module::Status::kEvaluating:
225+
case v8::Module::Status::kEvaluated:
226+
break;
227+
}
228+
229+
auto result = module->GetModuleNamespace();
230+
args.GetReturnValue().Set(result);
231+
}
232+
210233
MaybeLocal<Module> ModuleWrap::ResolveCallback(Local<Context> context,
211234
Local<String> specifier,
212235
Local<Module> referrer) {
@@ -520,6 +543,7 @@ void ModuleWrap::Initialize(Local<Object> target,
520543
env->SetProtoMethod(tpl, "link", Link);
521544
env->SetProtoMethod(tpl, "instantiate", Instantiate);
522545
env->SetProtoMethod(tpl, "evaluate", Evaluate);
546+
env->SetProtoMethod(tpl, "namespace", Namespace);
523547

524548
target->Set(FIXED_ONE_BYTE_STRING(isolate, "ModuleWrap"), tpl->GetFunction());
525549
env->SetMethod(target, "resolve", node::loader::ModuleWrap::Resolve);

src/module_wrap.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class ModuleWrap : public BaseObject {
3434
static void Link(const v8::FunctionCallbackInfo<v8::Value>& args);
3535
static void Instantiate(const v8::FunctionCallbackInfo<v8::Value>& args);
3636
static void Evaluate(const v8::FunctionCallbackInfo<v8::Value>& args);
37+
static void Namespace(const v8::FunctionCallbackInfo<v8::Value>& args);
3738
static void GetUrl(v8::Local<v8::String> property,
3839
const v8::PropertyCallbackInfo<v8::Value>& info);
3940
static void Resolve(const v8::FunctionCallbackInfo<v8::Value>& args);

0 commit comments

Comments
 (0)