[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 <mslekova@chromium.org>
Commit-Queue: Dan Elphick <delphick@chromium.org>
Cr-Commit-Position: refs/heads/master@{#75120}
This commit is contained in:
Dan Elphick 2021-06-14 09:26:41 +01:00 committed by V8 LUCI CQ
parent 5f8a28f00b
commit 9444600b5b
10 changed files with 157 additions and 133 deletions

View File

@ -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",

View File

@ -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"

View File

@ -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"

View File

@ -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"

View File

@ -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):

View File

@ -1287,100 +1287,6 @@ bool Object::ToInt32(int32_t* value) {
return false;
}
Handle<SharedFunctionInfo> FunctionTemplateInfo::GetOrCreateSharedFunctionInfo(
Isolate* isolate, Handle<FunctionTemplateInfo> info,
MaybeHandle<Name> maybe_name) {
Object current_info = info->shared_function_info();
if (current_info.IsSharedFunctionInfo()) {
return handle(SharedFunctionInfo::cast(current_info), isolate);
}
Handle<Name> name;
Handle<String> name_string;
if (maybe_name.ToHandle(&name) && name->IsString()) {
name_string = Handle<String>::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<SharedFunctionInfo> 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<FunctionTemplateInfo> function_template_info) {
DCHECK(function_template_info->rare_data(kAcquireLoad).IsUndefined(isolate));
Handle<FunctionTemplateRareData> rare_data =
isolate->factory()->NewFunctionTemplateRareData();
function_template_info->set_rare_data(*rare_data, kReleaseStore);
return *rare_data;
}
// static
Handle<TemplateList> TemplateList::New(Isolate* isolate, int size) {
Handle<FixedArray> list =
@ -6693,35 +6599,6 @@ AccessCheckInfo AccessCheckInfo::Get(Isolate* isolate,
return AccessCheckInfo::cast(data_obj);
}
base::Optional<Name> 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<Address>(FixedArray::cast(GetCFunctionOverloads())
.get(index * kFunctionOverloadEntrySize));
}
const CFunctionInfo* FunctionTemplateInfo::GetCSignature(int index) const {
i::DisallowHeapAllocation no_gc;
return v8::ToCData<CFunctionInfo*>(
FixedArray::cast(GetCFunctionOverloads())
.get(index * kFunctionOverloadEntrySize + 1));
}
Address Smi::LexicographicCompare(Isolate* isolate, Smi x, Smi y) {
DisallowGarbageCollection no_gc;
DisallowJavascriptExecution no_js(isolate);

View File

@ -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"

View File

@ -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);

145
src/objects/templates.cc Normal file
View File

@ -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<SharedFunctionInfo> FunctionTemplateInfo::GetOrCreateSharedFunctionInfo(
Isolate* isolate, Handle<FunctionTemplateInfo> info,
MaybeHandle<Name> maybe_name) {
Object current_info = info->shared_function_info();
if (current_info.IsSharedFunctionInfo()) {
return handle(SharedFunctionInfo::cast(current_info), isolate);
}
Handle<Name> name;
Handle<String> name_string;
if (maybe_name.ToHandle(&name) && name->IsString()) {
name_string = Handle<String>::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<SharedFunctionInfo> 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<FunctionTemplateInfo> function_template_info) {
DCHECK(function_template_info->rare_data(kAcquireLoad).IsUndefined(isolate));
Handle<FunctionTemplateRareData> rare_data =
isolate->factory()->NewFunctionTemplateRareData();
function_template_info->set_rare_data(*rare_data, kReleaseStore);
return *rare_data;
}
base::Optional<Name> 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<Address>(FixedArray::cast(GetCFunctionOverloads())
.get(index * kFunctionOverloadEntrySize));
}
const CFunctionInfo* FunctionTemplateInfo::GetCSignature(int index) const {
i::DisallowHeapAllocation no_gc;
return v8::ToCData<CFunctionInfo*>(
FixedArray::cast(GetCFunctionOverloads())
.get(index * kFunctionOverloadEntrySize + 1));
}
} // namespace internal
} // namespace v8

View File

@ -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<Name> TryGetCachedPropertyName(Isolate* isolate,