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

Commit

Permalink
Merge nodejs/master
Browse files Browse the repository at this point in the history
Merge 1c07724 as of 2017-10-28.
This is an automatically created merge. For any problems please
contact @kunalspathak.
  • Loading branch information
chakrabot authored and jackhorton committed Nov 6, 2017
2 parents 8eefbbb + 1c07724 commit 5298047
Show file tree
Hide file tree
Showing 19 changed files with 90 additions and 25 deletions.
2 changes: 1 addition & 1 deletion common.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

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

# Enable disassembler for `--print-code` v8 options
'v8_enable_disassembler': 1,
Expand Down
8 changes: 8 additions & 0 deletions deps/v8/src/heap/gc-tracer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,8 @@ void GCTracer::PrintNVP() const {
"promotion_rate=%.1f%% "
"semi_space_copy_rate=%.1f%% "
"new_space_allocation_throughput=%.1f "
"unmapper_chunks=%d "
"unmapper_delayed_chunks=%d "
"context_disposal_rate=%.1f\n",
duration, spent_in_mutator, current_.TypeName(true),
current_.reduce_memory, current_.scopes[Scope::HEAP_PROLOGUE],
Expand Down Expand Up @@ -520,6 +522,8 @@ void GCTracer::PrintNVP() const {
AverageSurvivalRatio(), heap_->promotion_rate_,
heap_->semi_space_copied_rate_,
NewSpaceAllocationThroughputInBytesPerMillisecond(),
heap_->memory_allocator()->unmapper()->NumberOfChunks(),
heap_->memory_allocator()->unmapper()->NumberOfDelayedChunks(),
ContextDisposalRateInMilliseconds());
break;
case Event::MINOR_MARK_COMPACTOR:
Expand Down Expand Up @@ -654,6 +658,8 @@ void GCTracer::PrintNVP() const {
"promotion_rate=%.1f%% "
"semi_space_copy_rate=%.1f%% "
"new_space_allocation_throughput=%.1f "
"unmapper_chunks=%d "
"unmapper_delayed_chunks=%d "
"context_disposal_rate=%.1f "
"compaction_speed=%.f\n",
duration, spent_in_mutator, current_.TypeName(true),
Expand Down Expand Up @@ -731,6 +737,8 @@ void GCTracer::PrintNVP() const {
AverageSurvivalRatio(), heap_->promotion_rate_,
heap_->semi_space_copied_rate_,
NewSpaceAllocationThroughputInBytesPerMillisecond(),
heap_->memory_allocator()->unmapper()->NumberOfChunks(),
heap_->memory_allocator()->unmapper()->NumberOfDelayedChunks(),
ContextDisposalRateInMilliseconds(),
CompactionSpeedInBytesPerMillisecond());
break;
Expand Down
6 changes: 6 additions & 0 deletions deps/v8/src/heap/heap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1885,6 +1885,12 @@ void Heap::Scavenge() {
IncrementalMarking::PauseBlackAllocationScope pause_black_allocation(
incremental_marking());

if (mark_compact_collector()->sweeper().sweeping_in_progress() &&
memory_allocator_->unmapper()->NumberOfDelayedChunks() >
static_cast<int>(new_space_->MaximumCapacity() / Page::kPageSize)) {
mark_compact_collector()->EnsureSweepingCompleted();
}

mark_compact_collector()->sweeper().EnsureNewSpaceCompleted();

SetGCState(SCAVENGE);
Expand Down
9 changes: 9 additions & 0 deletions deps/v8/src/heap/spaces.cc
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,15 @@ void MemoryAllocator::Unmapper::ReconsiderDelayedChunks() {
}
}

int MemoryAllocator::Unmapper::NumberOfChunks() {
base::LockGuard<base::Mutex> guard(&mutex_);
size_t result = 0;
for (int i = 0; i < kNumberOfChunkQueues; i++) {
result += chunks_[i].size();
}
return static_cast<int>(result);
}

bool MemoryAllocator::CanFreeMemoryChunk(MemoryChunk* chunk) {
MarkCompactCollector* mc = isolate_->heap()->mark_compact_collector();
// We cannot free a memory chunk in new space while the sweeper is running
Expand Down
7 changes: 7 additions & 0 deletions deps/v8/src/heap/spaces.h
Original file line number Diff line number Diff line change
Expand Up @@ -1199,6 +1199,13 @@ class V8_EXPORT_PRIVATE MemoryAllocator {

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

int NumberOfDelayedChunks() {
base::LockGuard<base::Mutex> guard(&mutex_);
return static_cast<int>(delayed_regular_chunks_.size());
}

int NumberOfChunks();

private:
static const int kReservedQueueingSlots = 64;
static const int kMaxUnmapperTasks = 24;
Expand Down
7 changes: 2 additions & 5 deletions lib/internal/loader/Loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@

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

const {
getNamespaceOfModuleWrap,
createDynamicModule
} = require('internal/loader/ModuleWrap');
const { createDynamicModule } = require('internal/loader/ModuleWrap');

const ModuleMap = require('internal/loader/ModuleMap');
const ModuleJob = require('internal/loader/ModuleJob');
Expand Down Expand Up @@ -100,7 +97,7 @@ class Loader {
async import(specifier, parentURL = this.base) {
const job = await this.getModuleJob(specifier, parentURL);
const module = await job.run();
return getNamespaceOfModuleWrap(module);
return module.namespace();
}
}
Object.setPrototypeOf(Loader.prototype, null);
Expand Down
8 changes: 0 additions & 8 deletions lib/internal/loader/ModuleWrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,6 @@ const debug = require('util').debuglog('esm');
const ArrayJoin = Function.call.bind(Array.prototype.join);
const ArrayMap = Function.call.bind(Array.prototype.map);

const getNamespaceOfModuleWrap = (m) => {
const tmp = new ModuleWrap('import * as _ from "";_;', '');
tmp.link(async () => m);
tmp.instantiate();
return tmp.evaluate();
};

const createDynamicModule = (exports, url = '', evaluate) => {
debug(
`creating ESM facade for ${url} with exports: ${ArrayJoin(exports, ', ')}`
Expand Down Expand Up @@ -56,6 +49,5 @@ const createDynamicModule = (exports, url = '', evaluate) => {

module.exports = {
createDynamicModule,
getNamespaceOfModuleWrap,
ModuleWrap
};
5 changes: 3 additions & 2 deletions lib/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -431,11 +431,12 @@ Module._load = function(request, parent, isMain) {
ESMLoader = new Loader();
const userLoader = process.binding('config').userLoader;
if (userLoader) {
const hooks = await new Loader().import(userLoader);
const hooks = await ESMLoader.import(userLoader);
ESMLoader = new Loader();
ESMLoader.hook(hooks);
}
}
await ESMLoader.import(getURLFromFilePath(request).href);
await ESMLoader.import(getURLFromFilePath(request).pathname);
})()
.catch((e) => {
console.error(e);
Expand Down
24 changes: 24 additions & 0 deletions src/module_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,29 @@ void ModuleWrap::Evaluate(const FunctionCallbackInfo<Value>& args) {
args.GetReturnValue().Set(ret);
}

void ModuleWrap::Namespace(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);
auto isolate = args.GetIsolate();
auto that = args.This();
ModuleWrap* obj = Unwrap<ModuleWrap>(that);
CHECK_NE(obj, nullptr);

auto module = obj->module_.Get(isolate);

switch (module->GetStatus()) {
default:
return env->ThrowError(
"cannot get namespace, Module has not been instantiated");
case v8::Module::Status::kInstantiated:
case v8::Module::Status::kEvaluating:
case v8::Module::Status::kEvaluated:
break;
}

auto result = module->GetModuleNamespace();
args.GetReturnValue().Set(result);
}

MaybeLocal<Module> ModuleWrap::ResolveCallback(Local<Context> context,
Local<String> specifier,
Local<Module> referrer) {
Expand Down Expand Up @@ -520,6 +543,7 @@ void ModuleWrap::Initialize(Local<Object> target,
env->SetProtoMethod(tpl, "link", Link);
env->SetProtoMethod(tpl, "instantiate", Instantiate);
env->SetProtoMethod(tpl, "evaluate", Evaluate);
env->SetProtoMethod(tpl, "namespace", Namespace);

target->Set(FIXED_ONE_BYTE_STRING(isolate, "ModuleWrap"), tpl->GetFunction());
env->SetMethod(target, "resolve", node::loader::ModuleWrap::Resolve);
Expand Down
1 change: 1 addition & 0 deletions src/module_wrap.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class ModuleWrap : public BaseObject {
static void Link(const v8::FunctionCallbackInfo<v8::Value>& args);
static void Instantiate(const v8::FunctionCallbackInfo<v8::Value>& args);
static void Evaluate(const v8::FunctionCallbackInfo<v8::Value>& args);
static void Namespace(const v8::FunctionCallbackInfo<v8::Value>& args);
static void GetUrl(v8::Local<v8::String> property,
const v8::PropertyCallbackInfo<v8::Value>& info);
static void Resolve(const v8::FunctionCallbackInfo<v8::Value>& args);
Expand Down
2 changes: 1 addition & 1 deletion src/node_http2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -824,7 +824,7 @@ int Http2Session::DoWrite(WriteWrap* req_wrap,
return 0;
}

void Http2Session::AllocateSend(size_t recommended, uv_buf_t* buf) {
void Http2Session::AllocateSend(uv_buf_t* buf) {
buf->base = stream_alloc();
buf->len = kAllocBufferSize;
}
Expand Down
5 changes: 3 additions & 2 deletions src/node_http2.h
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,8 @@ class Http2Options {
padding_strategy_type padding_strategy_ = PADDING_STRATEGY_NONE;
};

static const size_t kAllocBufferSize = 64 * 1024;
// This allows for 4 default-sized frames with their frame headers
static const size_t kAllocBufferSize = 4 * (16384 + 9);

typedef uint32_t(*get_setting)(nghttp2_session* session,
nghttp2_settings_id id);
Expand Down Expand Up @@ -414,7 +415,7 @@ class Http2Session : public AsyncWrap,
void OnFrameError(int32_t id, uint8_t type, int error_code) override;
void OnTrailers(Nghttp2Stream* stream,
const SubmitTrailers& submit_trailers) override;
void AllocateSend(size_t recommended, uv_buf_t* buf) override;
void AllocateSend(uv_buf_t* buf) override;

int DoWrite(WriteWrap* w, uv_buf_t* bufs, size_t count,
uv_stream_t* send_handle) override;
Expand Down
2 changes: 1 addition & 1 deletion src/node_http2_core-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ inline void Nghttp2Session::SendPendingData() {
return;

uv_buf_t dest;
AllocateSend(SEND_BUFFER_RECOMMENDED_SIZE, &dest);
AllocateSend(&dest);
size_t destLength = 0; // amount of data stored in dest
size_t destRemaining = dest.len; // amount space remaining in dest
size_t destOffset = 0; // current write offset of dest
Expand Down
3 changes: 1 addition & 2 deletions src/node_http2_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ class Nghttp2Stream;
struct nghttp2_stream_write_t;

#define MAX_BUFFER_COUNT 16
#define SEND_BUFFER_RECOMMENDED_SIZE 4096

enum nghttp2_session_type {
NGHTTP2_SESSION_SERVER,
Expand Down Expand Up @@ -178,7 +177,7 @@ class Nghttp2Session {
virtual ssize_t GetPadding(size_t frameLength,
size_t maxFrameLength) { return 0; }
virtual void OnFreeSession() {}
virtual void AllocateSend(size_t suggested_size, uv_buf_t* buf) = 0;
virtual void AllocateSend(uv_buf_t* buf) = 0;

virtual bool HasGetPaddingCallback() { return false; }

Expand Down
5 changes: 5 additions & 0 deletions test/es-module/test-esm-loader-dependency.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Flags: --experimental-modules --loader ./test/fixtures/es-module-loaders/loader-with-dep.mjs
/* eslint-disable required-modules */
import './test-esm-ok.mjs';

// We just test that this module doesn't fail loading
1 change: 1 addition & 0 deletions test/fixtures/es-module-loaders/loader-dep.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
exports.format = 'esm';
7 changes: 7 additions & 0 deletions test/fixtures/es-module-loaders/loader-with-dep.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import dep from './loader-dep.js';
export function resolve (specifier, base, defaultResolve) {
return {
url: defaultResolve(specifier, base).url,
format: dep.format
};
}
7 changes: 7 additions & 0 deletions test/parallel/test-module-main-extension-lookup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
'use strict';
require('../common');
const { execFileSync } = require('child_process');

const node = process.argv[0];

execFileSync(node, ['--experimental-modules', 'test/es-module/test-esm-ok']);
6 changes: 3 additions & 3 deletions tools/cpplint.py
Original file line number Diff line number Diff line change
Expand Up @@ -1074,8 +1074,8 @@ def RepositoryName(self):
"""
fullname = self.FullName()
# XXX(bnoordhuis) Expects that cpplint.py lives in the tools/ directory.
toplevel = os.path.abspath(
os.path.join(os.path.dirname(__file__), '..')).replace('\\', '/')
toplevel = os.path.abspath(os.path.join(os.path.dirname(__file__), '..')) \
.replace('\\', '/').decode('utf-8')
prefix = os.path.commonprefix([fullname, toplevel])
return fullname[len(prefix) + 1:]

Expand Down Expand Up @@ -6084,7 +6084,7 @@ def main():

_cpplint_state.ResetErrorCounts()
for filename in filenames:
ProcessFile(filename, _cpplint_state.verbose_level)
ProcessFile(filename.decode('utf-8'), _cpplint_state.verbose_level)
_cpplint_state.PrintErrorCounts()

sys.exit(_cpplint_state.error_count > 0)
Expand Down

0 comments on commit 5298047

Please sign in to comment.