From 6786707fb72e7c7e7101e56c6a71c235978cb1c5 Mon Sep 17 00:00:00 2001 From: Georg Neis <neis@chromium.org> Date: Mon, 8 Jul 2019 12:56:21 +0200 Subject: [PATCH] Prefer type NativeContext over Context in more places Change-Id: Ie0f54dd36a7af9503306d756182d98fc2273b48a Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1690828 Auto-Submit: Georg Neis <neis@chromium.org> Commit-Queue: Benedikt Meurer <bmeurer@chromium.org> Reviewed-by: Benedikt Meurer <bmeurer@chromium.org> Cr-Commit-Position: refs/heads/master@{#62558} --- src/deoptimizer/deoptimizer.cc | 4 ++-- src/init/bootstrapper.cc | 2 +- src/objects/code.cc | 7 ++++--- src/objects/code.h | 2 +- src/objects/contexts.cc | 26 ++++++++------------------ src/objects/contexts.h | 24 ++++++++++++------------ 6 files changed, 28 insertions(+), 37 deletions(-) diff --git a/src/deoptimizer/deoptimizer.cc b/src/deoptimizer/deoptimizer.cc index 0daf78f463..ee4cf2c2fe 100644 --- a/src/deoptimizer/deoptimizer.cc +++ b/src/deoptimizer/deoptimizer.cc @@ -159,7 +159,7 @@ Code Deoptimizer::FindDeoptimizingCode(Address addr) { if (function_.IsHeapObject()) { // Search all deoptimizing code in the native context of the function. Isolate* isolate = isolate_; - Context native_context = function_.context().native_context(); + NativeContext native_context = function_.context().native_context(); Object element = native_context.DeoptimizedCodeListHead(); while (!element.IsUndefined(isolate)) { Code code = Code::cast(element); @@ -590,7 +590,7 @@ int Deoptimizer::GetDeoptimizedCodeCount(Isolate* isolate) { // Count all entries in the deoptimizing code list of every context. Object context = isolate->heap()->native_contexts_list(); while (!context.IsUndefined(isolate)) { - Context native_context = Context::cast(context); + NativeContext native_context = NativeContext::cast(context); Object element = native_context.DeoptimizedCodeListHead(); while (!element.IsUndefined(isolate)) { Code code = Code::cast(element); diff --git a/src/init/bootstrapper.cc b/src/init/bootstrapper.cc index 84421f0e74..f3ae678f83 100644 --- a/src/init/bootstrapper.cc +++ b/src/init/bootstrapper.cc @@ -343,7 +343,7 @@ void Bootstrapper::LogAllMaps() { void Bootstrapper::DetachGlobal(Handle<Context> env) { isolate_->counters()->errors_thrown_per_context()->AddSample( - env->GetErrorsThrown()); + env->native_context().GetErrorsThrown()); ReadOnlyRoots roots(isolate_); Handle<JSGlobalProxy> global_proxy(env->global_proxy(), isolate_); diff --git a/src/objects/code.cc b/src/objects/code.cc index 228d08bd67..a51a8c5b79 100644 --- a/src/objects/code.cc +++ b/src/objects/code.cc @@ -352,7 +352,8 @@ bool Code::Inlines(SharedFunctionInfo sfi) { Code::OptimizedCodeIterator::OptimizedCodeIterator(Isolate* isolate) { isolate_ = isolate; Object list = isolate->heap()->native_contexts_list(); - next_context_ = list.IsUndefined(isolate_) ? Context() : Context::cast(list); + next_context_ = + list.IsUndefined(isolate_) ? NativeContext() : NativeContext::cast(list); } Code Code::OptimizedCodeIterator::Next() { @@ -366,8 +367,8 @@ Code Code::OptimizedCodeIterator::Next() { next = next_context_.OptimizedCodeListHead(); Object next_context = next_context_.next_context_link(); next_context_ = next_context.IsUndefined(isolate_) - ? Context() - : Context::cast(next_context); + ? NativeContext() + : NativeContext::cast(next_context); } else { // Exhausted contexts. return Code(); diff --git a/src/objects/code.h b/src/objects/code.h index 6e3c8fce6c..655eed3d24 100644 --- a/src/objects/code.h +++ b/src/objects/code.h @@ -476,7 +476,7 @@ class Code::OptimizedCodeIterator { Code Next(); private: - Context next_context_; + NativeContext next_context_; Code current_code_; Isolate* isolate_; diff --git a/src/objects/contexts.cc b/src/objects/contexts.cc index 80b323a152..861e06d87f 100644 --- a/src/objects/contexts.cc +++ b/src/objects/contexts.cc @@ -396,31 +396,26 @@ Handle<Object> Context::Lookup(Handle<Context> context, Handle<String> name, return Handle<Object>::null(); } -void Context::AddOptimizedCode(Code code) { - DCHECK(IsNativeContext()); +void NativeContext::AddOptimizedCode(Code code) { DCHECK(code.kind() == Code::OPTIMIZED_FUNCTION); DCHECK(code.next_code_link().IsUndefined()); code.set_next_code_link(get(OPTIMIZED_CODE_LIST)); set(OPTIMIZED_CODE_LIST, code, UPDATE_WEAK_WRITE_BARRIER); } -void Context::SetOptimizedCodeListHead(Object head) { - DCHECK(IsNativeContext()); +void NativeContext::SetOptimizedCodeListHead(Object head) { set(OPTIMIZED_CODE_LIST, head, UPDATE_WEAK_WRITE_BARRIER); } -Object Context::OptimizedCodeListHead() { - DCHECK(IsNativeContext()); +Object NativeContext::OptimizedCodeListHead() { return get(OPTIMIZED_CODE_LIST); } -void Context::SetDeoptimizedCodeListHead(Object head) { - DCHECK(IsNativeContext()); +void NativeContext::SetDeoptimizedCodeListHead(Object head) { set(DEOPTIMIZED_CODE_LIST, head, UPDATE_WEAK_WRITE_BARRIER); } -Object Context::DeoptimizedCodeListHead() { - DCHECK(IsNativeContext()); +Object NativeContext::DeoptimizedCodeListHead() { return get(DEOPTIMIZED_CODE_LIST); } @@ -476,19 +471,14 @@ bool Context::IsBootstrappingOrValidParentContext(Object object, #endif -void Context::ResetErrorsThrown() { - DCHECK(IsNativeContext()); - set_errors_thrown(Smi::FromInt(0)); -} - -void Context::IncrementErrorsThrown() { - DCHECK(IsNativeContext()); +void NativeContext::ResetErrorsThrown() { set_errors_thrown(Smi::FromInt(0)); } +void NativeContext::IncrementErrorsThrown() { int previous_value = errors_thrown().value(); set_errors_thrown(Smi::FromInt(previous_value + 1)); } -int Context::GetErrorsThrown() { return errors_thrown().value(); } +int NativeContext::GetErrorsThrown() { return errors_thrown().value(); } STATIC_ASSERT(Context::MIN_CONTEXT_SLOTS == 4); STATIC_ASSERT(NativeContext::kScopeInfoOffset == diff --git a/src/objects/contexts.h b/src/objects/contexts.h index 1138130894..24d2005f71 100644 --- a/src/objects/contexts.h +++ b/src/objects/contexts.h @@ -534,10 +534,6 @@ class Context : public HeapObject { static const int kNoContext = 0; static const int kInvalidContext = 1; - void ResetErrorsThrown(); - void IncrementErrorsThrown(); - int GetErrorsThrown(); - // Direct slot access. inline void set_scope_info(ScopeInfo scope_info); @@ -594,14 +590,6 @@ class Context : public HeapObject { inline bool HasSameSecurityTokenAs(Context that) const; - // The native context also stores a list of all optimized code and a - // list of all deoptimized code, which are needed by the deoptimizer. - V8_EXPORT_PRIVATE void AddOptimizedCode(Code code); - void SetOptimizedCodeListHead(Object head); - Object OptimizedCodeListHead(); - void SetDeoptimizedCodeListHead(Object head); - Object DeoptimizedCodeListHead(); - Handle<Object> ErrorMessageForCodeGenerationFromStrings(); static int IntrinsicIndexForName(Handle<String> name); @@ -706,6 +694,18 @@ class NativeContext : public Context { class BodyDescriptor; + // The native context stores a list of all optimized code and a list of all + // deoptimized code, which are needed by the deoptimizer. + V8_EXPORT_PRIVATE void AddOptimizedCode(Code code); + void SetOptimizedCodeListHead(Object head); + Object OptimizedCodeListHead(); + void SetDeoptimizedCodeListHead(Object head); + Object DeoptimizedCodeListHead(); + + void ResetErrorsThrown(); + void IncrementErrorsThrown(); + int GetErrorsThrown(); + private: STATIC_ASSERT(OffsetOfElementAt(EMBEDDER_DATA_INDEX) == Internals::kNativeContextEmbedderDataOffset);