diff options
author | Michaƫl Zasso <targos@protonmail.com> | 2017-09-12 11:34:59 +0200 |
---|---|---|
committer | Anna Henningsen <anna@addaleax.net> | 2017-09-13 16:15:18 +0200 |
commit | d82e1075dbc2cec2d6598ade10c1f43805f690fd (patch) | |
tree | ccd242b9b491dfc341d1099fe11b0ef528839877 /deps/v8/src/contexts.cc | |
parent | b4b7ac6ae811b2b5a3082468115dfb5a5246fe3f (diff) | |
download | android-node-v8-d82e1075dbc2cec2d6598ade10c1f43805f690fd.tar.gz android-node-v8-d82e1075dbc2cec2d6598ade10c1f43805f690fd.tar.bz2 android-node-v8-d82e1075dbc2cec2d6598ade10c1f43805f690fd.zip |
deps: update V8 to 6.1.534.36
PR-URL: https://github.com/nodejs/node/pull/14730
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Ali Ijaz Sheikh <ofrobots@google.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Diffstat (limited to 'deps/v8/src/contexts.cc')
-rw-r--r-- | deps/v8/src/contexts.cc | 205 |
1 files changed, 30 insertions, 175 deletions
diff --git a/deps/v8/src/contexts.cc b/deps/v8/src/contexts.cc index a4795af0f2..725e55e72f 100644 --- a/deps/v8/src/contexts.cc +++ b/deps/v8/src/contexts.cc @@ -4,6 +4,7 @@ #include "src/contexts.h" +#include "src/ast/modules.h" #include "src/bootstrapper.h" #include "src/debug/debug.h" #include "src/isolate-inl.h" @@ -199,7 +200,6 @@ Handle<Object> Context::Lookup(Handle<String> name, ContextLookupFlags flags, int* index, PropertyAttributes* attributes, InitializationFlag* init_flag, VariableMode* variable_mode) { - DCHECK(!IsModuleContext()); Isolate* isolate = GetIsolate(); Handle<Context> context(this, isolate); @@ -305,7 +305,8 @@ Handle<Object> Context::Lookup(Handle<String> name, ContextLookupFlags flags, // 2. Check the context proper if it has slots. if (context->IsFunctionContext() || context->IsBlockContext() || - context->IsScriptContext() || context->IsEvalContext()) { + context->IsScriptContext() || context->IsEvalContext() || + context->IsModuleContext()) { // Use serialized scope information of functions and blocks to search // for the context index. Handle<ScopeInfo> scope_info(context->scope_info()); @@ -346,6 +347,27 @@ Handle<Object> Context::Lookup(Handle<String> name, ContextLookupFlags flags, } } + // Lookup variable in module imports and exports. + if (context->IsModuleContext()) { + VariableMode mode; + InitializationFlag flag; + MaybeAssignedFlag maybe_assigned_flag; + int cell_index = + scope_info->ModuleIndex(name, &mode, &flag, &maybe_assigned_flag); + if (cell_index != 0) { + if (FLAG_trace_contexts) { + PrintF("=> found in module imports or exports\n"); + } + *index = cell_index; + *variable_mode = mode; + *init_flag = flag; + *attributes = ModuleDescriptor::GetCellIndexKind(cell_index) == + ModuleDescriptor::kExport + ? GetAttributesForMode(mode) + : READ_ONLY; + return handle(context->module(), isolate); + } + } } else if (context->IsCatchContext()) { // Catch contexts have the variable name in the extension slot. if (String::Equals(name, handle(context->catch_name()))) { @@ -398,9 +420,11 @@ Handle<Object> Context::Lookup(Handle<String> name, ContextLookupFlags flags, do { context = Handle<Context>(context->previous(), isolate); // If we come across a whitelist context, and the name is not - // whitelisted, then only consider with, script or native contexts. + // whitelisted, then only consider with, script, module or native + // contexts. } while (failed_whitelist && !context->IsScriptContext() && - !context->IsNativeContext() && !context->IsWithContext()); + !context->IsNativeContext() && !context->IsWithContext() && + !context->IsModuleContext()); } } while (follow_context_chain); @@ -410,171 +434,10 @@ Handle<Object> Context::Lookup(Handle<String> name, ContextLookupFlags flags, return Handle<Object>::null(); } -static const int kSharedOffset = 0; -static const int kCachedCodeOffset = 1; -static const int kOsrAstIdOffset = 2; -static const int kEntryLength = 3; -static const int kInitialLength = kEntryLength; - -int Context::SearchOSROptimizedCodeCacheEntry(SharedFunctionInfo* shared, - BailoutId osr_ast_id) { - DisallowHeapAllocation no_gc; - DCHECK(this->IsNativeContext()); - DCHECK(!osr_ast_id.IsNone()); - if (!OSROptimizedCodeCacheIsCleared()) { - FixedArray* osr_code_table = this->osr_code_table(); - int length = osr_code_table->length(); - Smi* osr_ast_id_smi = Smi::FromInt(osr_ast_id.ToInt()); - for (int i = 0; i < length; i += kEntryLength) { - if (WeakCell::cast(osr_code_table->get(i + kSharedOffset))->value() == - shared && - osr_code_table->get(i + kOsrAstIdOffset) == osr_ast_id_smi) { - return i; - } - } - } - return -1; -} - -Code* Context::SearchOSROptimizedCodeCache(SharedFunctionInfo* shared, - BailoutId osr_ast_id) { - DCHECK(this->IsNativeContext()); - int entry = SearchOSROptimizedCodeCacheEntry(shared, osr_ast_id); - if (entry != -1) { - FixedArray* code_map = osr_code_table(); - DCHECK_LE(entry + kEntryLength, code_map->length()); - WeakCell* cell = WeakCell::cast(code_map->get(entry + kCachedCodeOffset)); - return cell->cleared() ? nullptr : Code::cast(cell->value()); - } - return nullptr; -} - -void Context::AddToOSROptimizedCodeCache(Handle<Context> native_context, - Handle<SharedFunctionInfo> shared, - Handle<Code> code, - BailoutId osr_ast_id) { - DCHECK(native_context->IsNativeContext()); - DCHECK(!osr_ast_id.IsNone()); - DCHECK(code->kind() == Code::OPTIMIZED_FUNCTION); - Isolate* isolate = native_context->GetIsolate(); - if (isolate->serializer_enabled()) return; - - STATIC_ASSERT(kEntryLength == 3); - Handle<FixedArray> new_code_map; - int entry; - - if (native_context->OSROptimizedCodeCacheIsCleared()) { - new_code_map = isolate->factory()->NewFixedArray(kInitialLength, TENURED); - entry = 0; - } else { - Handle<FixedArray> old_code_map(native_context->osr_code_table(), isolate); - entry = - native_context->SearchOSROptimizedCodeCacheEntry(*shared, osr_ast_id); - if (entry >= 0) { - // Just set the code of the entry. - Handle<WeakCell> code_cell = isolate->factory()->NewWeakCell(code); - old_code_map->set(entry + kCachedCodeOffset, *code_cell); - return; - } - - // Can we reuse an entry? - DCHECK(entry < 0); - int length = old_code_map->length(); - for (int i = 0; i < length; i += kEntryLength) { - if (WeakCell::cast(old_code_map->get(i + kSharedOffset))->cleared()) { - new_code_map = old_code_map; - entry = i; - break; - } - } - - if (entry < 0) { - // Copy old optimized code map and append one new entry. - new_code_map = isolate->factory()->CopyFixedArrayAndGrow( - old_code_map, kEntryLength, TENURED); - entry = old_code_map->length(); - } - } - - Handle<WeakCell> code_cell = isolate->factory()->NewWeakCell(code); - Handle<WeakCell> shared_cell = isolate->factory()->NewWeakCell(shared); - - new_code_map->set(entry + kSharedOffset, *shared_cell); - new_code_map->set(entry + kCachedCodeOffset, *code_cell); - new_code_map->set(entry + kOsrAstIdOffset, Smi::FromInt(osr_ast_id.ToInt())); - -#ifdef DEBUG - for (int i = 0; i < new_code_map->length(); i += kEntryLength) { - WeakCell* cell = WeakCell::cast(new_code_map->get(i + kSharedOffset)); - DCHECK(cell->cleared() || cell->value()->IsSharedFunctionInfo()); - cell = WeakCell::cast(new_code_map->get(i + kCachedCodeOffset)); - DCHECK(cell->cleared() || - (cell->value()->IsCode() && - Code::cast(cell->value())->kind() == Code::OPTIMIZED_FUNCTION)); - DCHECK(new_code_map->get(i + kOsrAstIdOffset)->IsSmi()); - } -#endif - - FixedArray* old_code_map = native_context->osr_code_table(); - if (old_code_map != *new_code_map) { - native_context->set_osr_code_table(*new_code_map); - } -} - -void Context::EvictFromOSROptimizedCodeCache(Code* optimized_code, - const char* reason) { - DCHECK(IsNativeContext()); - DisallowHeapAllocation no_gc; - if (OSROptimizedCodeCacheIsCleared()) return; - - Heap* heap = GetHeap(); - FixedArray* code_map = osr_code_table(); - int dst = 0; - int length = code_map->length(); - for (int src = 0; src < length; src += kEntryLength) { - if (WeakCell::cast(code_map->get(src + kCachedCodeOffset))->value() == - optimized_code) { - BailoutId osr(Smi::cast(code_map->get(src + kOsrAstIdOffset))->value()); - if (FLAG_trace_opt) { - PrintF( - "[evicting entry from native context optimizing code map (%s) for ", - reason); - ShortPrint(); - DCHECK(!osr.IsNone()); - PrintF(" (osr ast id %d)]\n", osr.ToInt()); - } - // Evict the src entry by not copying it to the dst entry. - continue; - } - // Keep the src entry by copying it to the dst entry. - if (dst != src) { - code_map->set(dst + kSharedOffset, code_map->get(src + kSharedOffset)); - code_map->set(dst + kCachedCodeOffset, - code_map->get(src + kCachedCodeOffset)); - code_map->set(dst + kOsrAstIdOffset, - code_map->get(src + kOsrAstIdOffset)); - } - dst += kEntryLength; - } - if (dst != length) { - // Always trim even when array is cleared because of heap verifier. - heap->RightTrimFixedArray(code_map, length - dst); - if (code_map->length() == 0) { - ClearOSROptimizedCodeCache(); - } - } -} - -void Context::ClearOSROptimizedCodeCache() { - DCHECK(IsNativeContext()); - FixedArray* empty_fixed_array = GetHeap()->empty_fixed_array(); - set_osr_code_table(empty_fixed_array); -} - void Context::AddOptimizedFunction(JSFunction* function) { DCHECK(IsNativeContext()); - Isolate* isolate = GetIsolate(); #ifdef ENABLE_SLOW_DCHECKS + Isolate* isolate = GetIsolate(); if (FLAG_enable_slow_asserts) { Object* element = get(OPTIMIZED_FUNCTIONS_LIST); while (!element->IsUndefined(isolate)) { @@ -596,15 +459,7 @@ void Context::AddOptimizedFunction(JSFunction* function) { CHECK(found); #endif - // If the function link field is already used then the function was - // enqueued as a code flushing candidate and we remove it now. - if (!function->next_function_link()->IsUndefined(isolate)) { - CodeFlusher* flusher = GetHeap()->mark_compact_collector()->code_flusher(); - flusher->EvictCandidate(function); - } - - DCHECK(function->next_function_link()->IsUndefined(isolate)); - + DCHECK(function->next_function_link()->IsUndefined(GetIsolate())); function->set_next_function_link(get(OPTIMIZED_FUNCTIONS_LIST), UPDATE_WEAK_WRITE_BARRIER); set(OPTIMIZED_FUNCTIONS_LIST, function, UPDATE_WEAK_WRITE_BARRIER); |