From 9444600b5b9f95cb367d7799b18efd32852717be Mon Sep 17 00:00:00 2001 From: Dan Elphick Date: Mon, 14 Jun 2021 09:26:41 +0100 Subject: [PATCH] [build] Move FunctionTemplateInfo methods out of objects.cc This moves all of the FunctionTemplateInfo code into templates.cc and removes the inline keyword from BreakAtEntry which is moved out of templates-inl.h. As a result templates-inl.h no longer depends on shared-function-info-inl.h. This in turn uncovered lots of other missing includes which are now in place. Change-Id: I9bc152d5e3db0e793db135a8cfcf97f6d8bcbb8a Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2953295 Reviewed-by: Maya Lekova Commit-Queue: Dan Elphick Cr-Commit-Position: refs/heads/master@{#75120} --- BUILD.gn | 1 + src/objects/code-inl.h | 2 +- src/objects/feedback-cell-inl.h | 4 +- src/objects/map-inl.h | 2 +- src/objects/module-inl.h | 1 + src/objects/objects.cc | 123 --------------------- src/objects/shared-function-info-inl.h | 2 +- src/objects/templates-inl.h | 8 +- src/objects/templates.cc | 145 +++++++++++++++++++++++++ src/objects/templates.h | 2 +- 10 files changed, 157 insertions(+), 133 deletions(-) create mode 100644 src/objects/templates.cc diff --git a/BUILD.gn b/BUILD.gn index 9d5e64c854..0761edbe6b 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -3955,6 +3955,7 @@ v8_source_set("v8_base_without_compiler") { "src/objects/synthetic-module.cc", "src/objects/tagged-impl.cc", "src/objects/template-objects.cc", + "src/objects/templates.cc", "src/objects/transitions.cc", "src/objects/type-hints.cc", "src/objects/value-serializer.cc", diff --git a/src/objects/code-inl.h b/src/objects/code-inl.h index 28b7b430c8..b50190963b 100644 --- a/src/objects/code-inl.h +++ b/src/objects/code-inl.h @@ -17,7 +17,7 @@ #include "src/objects/map-inl.h" #include "src/objects/maybe-object-inl.h" #include "src/objects/oddball.h" -#include "src/objects/shared-function-info.h" +#include "src/objects/shared-function-info-inl.h" #include "src/objects/smi-inl.h" #include "src/utils/utils.h" diff --git a/src/objects/feedback-cell-inl.h b/src/objects/feedback-cell-inl.h index bd7c71d88b..84257e544c 100644 --- a/src/objects/feedback-cell-inl.h +++ b/src/objects/feedback-cell-inl.h @@ -5,9 +5,9 @@ #ifndef V8_OBJECTS_FEEDBACK_CELL_INL_H_ #define V8_OBJECTS_FEEDBACK_CELL_INL_H_ -#include "src/objects/feedback-cell.h" - #include "src/heap/heap-write-barrier-inl.h" +#include "src/objects/feedback-cell.h" +#include "src/objects/feedback-vector-inl.h" #include "src/objects/objects-inl.h" #include "src/objects/struct-inl.h" diff --git a/src/objects/map-inl.h b/src/objects/map-inl.h index 0c75391ffb..5da85f5b93 100644 --- a/src/objects/map-inl.h +++ b/src/objects/map-inl.h @@ -16,7 +16,7 @@ #include "src/objects/objects-inl.h" #include "src/objects/property.h" #include "src/objects/prototype-info-inl.h" -#include "src/objects/shared-function-info.h" +#include "src/objects/shared-function-info-inl.h" #include "src/objects/templates-inl.h" #include "src/objects/transitions-inl.h" #include "src/objects/transitions.h" diff --git a/src/objects/module-inl.h b/src/objects/module-inl.h index d9ec56d578..a01c258e02 100644 --- a/src/objects/module-inl.h +++ b/src/objects/module-inl.h @@ -9,6 +9,7 @@ #include "src/objects/objects-inl.h" // Needed for write barriers #include "src/objects/scope-info.h" #include "src/objects/source-text-module.h" +#include "src/objects/string-inl.h" #include "src/objects/synthetic-module.h" // Has to be the last include (doesn't have include guards): diff --git a/src/objects/objects.cc b/src/objects/objects.cc index eec3ae3958..177e00fb72 100644 --- a/src/objects/objects.cc +++ b/src/objects/objects.cc @@ -1287,100 +1287,6 @@ bool Object::ToInt32(int32_t* value) { return false; } -Handle FunctionTemplateInfo::GetOrCreateSharedFunctionInfo( - Isolate* isolate, Handle info, - MaybeHandle maybe_name) { - Object current_info = info->shared_function_info(); - if (current_info.IsSharedFunctionInfo()) { - return handle(SharedFunctionInfo::cast(current_info), isolate); - } - Handle name; - Handle name_string; - if (maybe_name.ToHandle(&name) && name->IsString()) { - name_string = Handle::cast(name); - } else if (info->class_name().IsString()) { - name_string = handle(String::cast(info->class_name()), isolate); - } else { - name_string = isolate->factory()->empty_string(); - } - FunctionKind function_kind; - if (info->remove_prototype()) { - function_kind = kConciseMethod; - } else { - function_kind = kNormalFunction; - } - Handle result = - isolate->factory()->NewSharedFunctionInfoForApiFunction(name_string, info, - function_kind); - - result->set_length(info->length()); - result->DontAdaptArguments(); - DCHECK(result->IsApiFunction()); - - info->set_shared_function_info(*result); - return result; -} - -bool FunctionTemplateInfo::IsTemplateFor(Map map) const { - RCS_SCOPE( - LocalHeap::Current() == nullptr - ? GetIsolate()->counters()->runtime_call_stats() - : LocalIsolate::FromHeap(LocalHeap::Current())->runtime_call_stats(), - RuntimeCallCounterId::kIsTemplateFor); - - // There is a constraint on the object; check. - if (!map.IsJSObjectMap()) return false; - // Fetch the constructor function of the object. - Object cons_obj = map.GetConstructor(); - Object type; - if (cons_obj.IsJSFunction()) { - JSFunction fun = JSFunction::cast(cons_obj); - type = fun.shared().function_data(kAcquireLoad); - } else if (cons_obj.IsFunctionTemplateInfo()) { - type = FunctionTemplateInfo::cast(cons_obj); - } else { - return false; - } - // Iterate through the chain of inheriting function templates to - // see if the required one occurs. - while (type.IsFunctionTemplateInfo()) { - if (type == *this) return true; - type = FunctionTemplateInfo::cast(type).GetParentTemplate(); - } - // Didn't find the required type in the inheritance chain. - return false; -} - -bool FunctionTemplateInfo::IsLeafTemplateForApiObject(Object object) const { - i::DisallowGarbageCollection no_gc; - - if (!object.IsJSApiObject()) { - return false; - } - - bool result = false; - Map map = HeapObject::cast(object).map(); - Object constructor_obj = map.GetConstructor(); - if (constructor_obj.IsJSFunction()) { - JSFunction fun = JSFunction::cast(constructor_obj); - result = (*this == fun.shared().function_data(kAcquireLoad)); - } else if (constructor_obj.IsFunctionTemplateInfo()) { - result = (*this == constructor_obj); - } - DCHECK_IMPLIES(result, IsTemplateFor(map)); - return result; -} - -// static -FunctionTemplateRareData FunctionTemplateInfo::AllocateFunctionTemplateRareData( - Isolate* isolate, Handle function_template_info) { - DCHECK(function_template_info->rare_data(kAcquireLoad).IsUndefined(isolate)); - Handle rare_data = - isolate->factory()->NewFunctionTemplateRareData(); - function_template_info->set_rare_data(*rare_data, kReleaseStore); - return *rare_data; -} - // static Handle TemplateList::New(Isolate* isolate, int size) { Handle list = @@ -6693,35 +6599,6 @@ AccessCheckInfo AccessCheckInfo::Get(Isolate* isolate, return AccessCheckInfo::cast(data_obj); } -base::Optional FunctionTemplateInfo::TryGetCachedPropertyName( - Isolate* isolate, Object getter) { - DisallowGarbageCollection no_gc; - if (!getter.IsFunctionTemplateInfo()) return {}; - // Check if the accessor uses a cached property. - Object maybe_name = FunctionTemplateInfo::cast(getter).cached_property_name(); - if (maybe_name.IsTheHole(isolate)) return {}; - return Name::cast(maybe_name); -} - -int FunctionTemplateInfo::GetCFunctionsCount() const { - i::DisallowHeapAllocation no_gc; - return FixedArray::cast(GetCFunctionOverloads()).length() / - kFunctionOverloadEntrySize; -} - -Address FunctionTemplateInfo::GetCFunction(int index) const { - i::DisallowHeapAllocation no_gc; - return v8::ToCData
(FixedArray::cast(GetCFunctionOverloads()) - .get(index * kFunctionOverloadEntrySize)); -} - -const CFunctionInfo* FunctionTemplateInfo::GetCSignature(int index) const { - i::DisallowHeapAllocation no_gc; - return v8::ToCData( - FixedArray::cast(GetCFunctionOverloads()) - .get(index * kFunctionOverloadEntrySize + 1)); -} - Address Smi::LexicographicCompare(Isolate* isolate, Smi x, Smi y) { DisallowGarbageCollection no_gc; DisallowJavascriptExecution no_js(isolate); diff --git a/src/objects/shared-function-info-inl.h b/src/objects/shared-function-info-inl.h index a87602275b..bb4b2624eb 100644 --- a/src/objects/shared-function-info-inl.h +++ b/src/objects/shared-function-info-inl.h @@ -14,7 +14,7 @@ #include "src/objects/scope-info-inl.h" #include "src/objects/script-inl.h" #include "src/objects/shared-function-info.h" -#include "src/objects/templates.h" +#include "src/objects/templates-inl.h" #if V8_ENABLE_WEBASSEMBLY #include "src/wasm/wasm-module.h" diff --git a/src/objects/templates-inl.h b/src/objects/templates-inl.h index d2d5076246..81d9d75b48 100644 --- a/src/objects/templates-inl.h +++ b/src/objects/templates-inl.h @@ -5,11 +5,11 @@ #ifndef V8_OBJECTS_TEMPLATES_INL_H_ #define V8_OBJECTS_TEMPLATES_INL_H_ -#include "src/objects/templates.h" - #include "src/heap/heap-write-barrier-inl.h" +#include "src/objects/objects-inl.h" #include "src/objects/oddball.h" -#include "src/objects/shared-function-info-inl.h" +#include "src/objects/shared-function-info.h" +#include "src/objects/templates.h" // Has to be the last include (doesn't have include guards): #include "src/objects/object-macros.h" @@ -89,7 +89,7 @@ bool FunctionTemplateInfo::instantiated() { return shared_function_info().IsSharedFunctionInfo(); } -bool FunctionTemplateInfo::BreakAtEntry() { +inline bool FunctionTemplateInfo::BreakAtEntry() { Object maybe_shared = shared_function_info(); if (maybe_shared.IsSharedFunctionInfo()) { SharedFunctionInfo shared = SharedFunctionInfo::cast(maybe_shared); diff --git a/src/objects/templates.cc b/src/objects/templates.cc new file mode 100644 index 0000000000..e5a8beff71 --- /dev/null +++ b/src/objects/templates.cc @@ -0,0 +1,145 @@ +// Copyright 2021 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "src/objects/templates.h" + +#include "src/api/api-inl.h" +#include "src/execution/isolate.h" +#include "src/heap/factory.h" +#include "src/objects/function-kind.h" +#include "src/objects/instance-type-inl.h" +#include "src/objects/js-function-inl.h" +#include "src/objects/map-inl.h" +#include "src/objects/name-inl.h" +#include "src/objects/shared-function-info-inl.h" +#include "src/objects/string-inl.h" + +namespace v8 { +namespace internal { + +Handle FunctionTemplateInfo::GetOrCreateSharedFunctionInfo( + Isolate* isolate, Handle info, + MaybeHandle maybe_name) { + Object current_info = info->shared_function_info(); + if (current_info.IsSharedFunctionInfo()) { + return handle(SharedFunctionInfo::cast(current_info), isolate); + } + Handle name; + Handle name_string; + if (maybe_name.ToHandle(&name) && name->IsString()) { + name_string = Handle::cast(name); + } else if (info->class_name().IsString()) { + name_string = handle(String::cast(info->class_name()), isolate); + } else { + name_string = isolate->factory()->empty_string(); + } + FunctionKind function_kind; + if (info->remove_prototype()) { + function_kind = kConciseMethod; + } else { + function_kind = kNormalFunction; + } + Handle result = + isolate->factory()->NewSharedFunctionInfoForApiFunction(name_string, info, + function_kind); + + result->set_length(info->length()); + result->DontAdaptArguments(); + DCHECK(result->IsApiFunction()); + + info->set_shared_function_info(*result); + return result; +} + +bool FunctionTemplateInfo::IsTemplateFor(Map map) const { + RCS_SCOPE( + LocalHeap::Current() == nullptr + ? GetIsolate()->counters()->runtime_call_stats() + : LocalIsolate::FromHeap(LocalHeap::Current())->runtime_call_stats(), + RuntimeCallCounterId::kIsTemplateFor); + + // There is a constraint on the object; check. + if (!map.IsJSObjectMap()) return false; + // Fetch the constructor function of the object. + Object cons_obj = map.GetConstructor(); + Object type; + if (cons_obj.IsJSFunction()) { + JSFunction fun = JSFunction::cast(cons_obj); + type = fun.shared().function_data(kAcquireLoad); + } else if (cons_obj.IsFunctionTemplateInfo()) { + type = FunctionTemplateInfo::cast(cons_obj); + } else { + return false; + } + // Iterate through the chain of inheriting function templates to + // see if the required one occurs. + while (type.IsFunctionTemplateInfo()) { + if (type == *this) return true; + type = FunctionTemplateInfo::cast(type).GetParentTemplate(); + } + // Didn't find the required type in the inheritance chain. + return false; +} + +bool FunctionTemplateInfo::IsLeafTemplateForApiObject(Object object) const { + i::DisallowGarbageCollection no_gc; + + if (!object.IsJSApiObject()) { + return false; + } + + bool result = false; + Map map = HeapObject::cast(object).map(); + Object constructor_obj = map.GetConstructor(); + if (constructor_obj.IsJSFunction()) { + JSFunction fun = JSFunction::cast(constructor_obj); + result = (*this == fun.shared().function_data(kAcquireLoad)); + } else if (constructor_obj.IsFunctionTemplateInfo()) { + result = (*this == constructor_obj); + } + DCHECK_IMPLIES(result, IsTemplateFor(map)); + return result; +} + +// static +FunctionTemplateRareData FunctionTemplateInfo::AllocateFunctionTemplateRareData( + Isolate* isolate, Handle function_template_info) { + DCHECK(function_template_info->rare_data(kAcquireLoad).IsUndefined(isolate)); + Handle rare_data = + isolate->factory()->NewFunctionTemplateRareData(); + function_template_info->set_rare_data(*rare_data, kReleaseStore); + return *rare_data; +} + +base::Optional FunctionTemplateInfo::TryGetCachedPropertyName( + Isolate* isolate, Object getter) { + DisallowGarbageCollection no_gc; + if (!getter.IsFunctionTemplateInfo()) return {}; + // Check if the accessor uses a cached property. + Object maybe_name = FunctionTemplateInfo::cast(getter).cached_property_name(); + if (maybe_name.IsTheHole(isolate)) return {}; + return Name::cast(maybe_name); +} + +int FunctionTemplateInfo::GetCFunctionsCount() const { + i::DisallowHeapAllocation no_gc; + return FixedArray::cast(GetCFunctionOverloads()).length() / + kFunctionOverloadEntrySize; +} + +Address FunctionTemplateInfo::GetCFunction(int index) const { + i::DisallowHeapAllocation no_gc; + return v8::ToCData
(FixedArray::cast(GetCFunctionOverloads()) + .get(index * kFunctionOverloadEntrySize)); +} + +const CFunctionInfo* FunctionTemplateInfo::GetCSignature(int index) const { + i::DisallowHeapAllocation no_gc; + return v8::ToCData( + FixedArray::cast(GetCFunctionOverloads()) + .get(index * kFunctionOverloadEntrySize + 1)); +} + +} // namespace internal +} // namespace v8 diff --git a/src/objects/templates.h b/src/objects/templates.h index b240173432..dd890780bd 100644 --- a/src/objects/templates.h +++ b/src/objects/templates.h @@ -150,7 +150,7 @@ class FunctionTemplateInfo bool IsLeafTemplateForApiObject(Object object) const; inline bool instantiated(); - inline bool BreakAtEntry(); + bool BreakAtEntry(); // Helper function for cached accessors. static base::Optional TryGetCachedPropertyName(Isolate* isolate,