[torque] Improve field types in template.tq

This is a partial reland of https://crrev.com/c/v8/v8/+/2199640 .

Change-Id: I49b4858e69db58f45c28e4cb03ccc16b7e632fdf
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2216305
Reviewed-by: Toon Verwaest <verwaest@chromium.org>
Reviewed-by: Tobias Tebbi <tebbi@chromium.org>
Commit-Queue: Seth Brenith <seth.brenith@microsoft.com>
Cr-Commit-Position: refs/heads/master@{#68047}
This commit is contained in:
Seth Brenith 2020-05-26 10:53:49 -07:00 committed by Commit Bot
parent 8377a2b393
commit 62b1e59878
8 changed files with 100 additions and 106 deletions

View File

@ -371,7 +371,7 @@ MaybeHandle<JSObject> InstantiateObject(Isolate* isolate,
Handle<JSReceiver> new_target,
bool is_prototype) {
Handle<JSFunction> constructor;
int serial_number = Smi::ToInt(info->serial_number());
int serial_number = info->serial_number();
if (!new_target.is_null()) {
if (IsSimpleInstantiation(isolate, *info, *new_target)) {
constructor = Handle<JSFunction>::cast(new_target);
@ -462,7 +462,7 @@ MaybeHandle<Object> GetInstancePrototype(Isolate* isolate,
MaybeHandle<JSFunction> InstantiateFunction(
Isolate* isolate, Handle<NativeContext> native_context,
Handle<FunctionTemplateInfo> data, MaybeHandle<Name> maybe_name) {
int serial_number = Smi::ToInt(data->serial_number());
int serial_number = data->serial_number();
if (serial_number) {
Handle<JSObject> result;
if (ProbeInstantiationsCache(isolate, native_context, serial_number,

View File

@ -1276,7 +1276,7 @@ void Context::SetAlignedPointerInEmbedderData(int index, void* value) {
static void InitializeTemplate(i::Handle<i::TemplateInfo> that, int type) {
that->set_number_of_properties(0);
that->set_tag(i::Smi::FromInt(type));
that->set_tag(type);
}
void Template::Set(v8::Local<Name> name, v8::Local<Data> value,
@ -1288,7 +1288,7 @@ void Template::Set(v8::Local<Name> name, v8::Local<Data> value,
auto value_obj = Utils::OpenHandle(*value);
CHECK(!value_obj->IsJSReceiver() || value_obj->IsTemplateInfo());
if (value_obj->IsObjectTemplateInfo()) {
templ->set_serial_number(i::Smi::zero());
templ->set_serial_number(0);
if (templ->IsFunctionTemplateInfo()) {
i::Handle<i::FunctionTemplateInfo>::cast(templ)->set_do_not_cache(true);
}
@ -1338,7 +1338,7 @@ Local<ObjectTemplate> FunctionTemplate::PrototypeTemplate() {
auto self = Utils::OpenHandle(this);
i::Isolate* i_isolate = self->GetIsolate();
ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate);
i::Handle<i::Object> result(self->GetPrototypeTemplate(), i_isolate);
i::Handle<i::HeapObject> result(self->GetPrototypeTemplate(), i_isolate);
if (result->IsUndefined(i_isolate)) {
// Do not cache prototype objects.
result = Utils::OpenHandle(
@ -1353,7 +1353,8 @@ void FunctionTemplate::SetPrototypeProviderTemplate(
auto self = Utils::OpenHandle(this);
i::Isolate* i_isolate = self->GetIsolate();
ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate);
i::Handle<i::Object> result = Utils::OpenHandle(*prototype_provider);
i::Handle<i::FunctionTemplateInfo> result =
Utils::OpenHandle(*prototype_provider);
CHECK(self->GetPrototypeTemplate().IsUndefined(i_isolate));
CHECK(self->GetParentTemplate().IsUndefined(i_isolate));
i::FunctionTemplateInfo::SetPrototypeProviderTemplate(i_isolate, self,
@ -1396,7 +1397,7 @@ static Local<FunctionTemplate> FunctionTemplateNew(
if (!do_not_cache) {
next_serial_number = isolate->heap()->GetNextTemplateSerialNumber();
}
obj->set_serial_number(i::Smi::FromInt(next_serial_number));
obj->set_serial_number(next_serial_number);
}
if (callback != nullptr) {
Utils::ToLocal(obj)->SetCallHandler(callback, data, side_effect_type,
@ -1607,15 +1608,19 @@ static Local<ObjectTemplate> ObjectTemplateNew(
i::OBJECT_TEMPLATE_INFO_TYPE, i::AllocationType::kOld);
i::Handle<i::ObjectTemplateInfo> obj =
i::Handle<i::ObjectTemplateInfo>::cast(struct_obj);
InitializeTemplate(obj, Consts::OBJECT_TEMPLATE);
int next_serial_number = 0;
if (!do_not_cache) {
next_serial_number = isolate->heap()->GetNextTemplateSerialNumber();
{
// Disallow GC until all fields of obj have acceptable types.
i::DisallowHeapAllocation no_gc;
InitializeTemplate(obj, Consts::OBJECT_TEMPLATE);
int next_serial_number = 0;
if (!do_not_cache) {
next_serial_number = isolate->heap()->GetNextTemplateSerialNumber();
}
obj->set_serial_number(next_serial_number);
obj->set_data(0);
}
obj->set_serial_number(i::Smi::FromInt(next_serial_number));
if (!constructor.IsEmpty())
obj->set_constructor(*Utils::OpenHandle(*constructor));
obj->set_data(i::Smi::zero());
return Utils::ToLocal(obj);
}
@ -5804,9 +5809,9 @@ static i::Handle<ObjectType> CreateEnvironment(
v8::Local<ObjectTemplate> proxy_template;
i::Handle<i::FunctionTemplateInfo> proxy_constructor;
i::Handle<i::FunctionTemplateInfo> global_constructor;
i::Handle<i::Object> named_interceptor(
i::Handle<i::HeapObject> named_interceptor(
isolate->factory()->undefined_value());
i::Handle<i::Object> indexed_interceptor(
i::Handle<i::HeapObject> indexed_interceptor(
isolate->factory()->undefined_value());
if (!maybe_global_template.IsEmpty()) {

View File

@ -606,7 +606,7 @@ void CallOrConstructBuiltinsAssembler::CallFunctionTemplate(
TNode<IntPtrT> function_template_info_flags = LoadAndUntagObjectField(
function_template_info, FunctionTemplateInfo::kFlagOffset);
Branch(IsSetWord(function_template_info_flags,
1 << FunctionTemplateInfo::kAcceptAnyReceiver),
1 << FunctionTemplateInfo::AcceptAnyReceiverBit::kShift),
&receiver_done, &receiver_needs_access_check);
BIND(&receiver_needs_access_check);

View File

@ -1924,8 +1924,8 @@ void FunctionTemplateInfo::FunctionTemplateInfoPrint(
std::ostream& os) { // NOLINT
PrintHeader(os, "FunctionTemplateInfo");
os << "\n - class name: " << Brief(class_name());
os << "\n - tag: " << Brief(tag());
os << "\n - serial_number: " << Brief(serial_number());
os << "\n - tag: " << tag();
os << "\n - serial_number: " << serial_number();
os << "\n - property_list: " << Brief(property_list());
os << "\n - call_code: " << Brief(call_code());
os << "\n - property_accessors: " << Brief(property_accessors());
@ -1938,21 +1938,6 @@ void FunctionTemplateInfo::FunctionTemplateInfoPrint(
os << "\n";
}
void FunctionTemplateRareData::FunctionTemplateRareDataPrint(
std::ostream& os) { // NOLINT
PrintHeader(os, "FunctionTemplateRareData");
os << "\n - prototype_template: " << Brief(prototype_template());
os << "\n - prototype_provider_template: "
<< Brief(prototype_provider_template());
os << "\n - parent_template: " << Brief(parent_template());
os << "\n - named_property_handler: " << Brief(named_property_handler());
os << "\n - indexed_property_handler: " << Brief(indexed_property_handler());
os << "\n - instance_template: " << Brief(instance_template());
os << "\n - instance_call_handler: " << Brief(instance_call_handler());
os << "\n - access_check_info: " << Brief(access_check_info());
os << "\n";
}
void WasmCapiFunctionData::WasmCapiFunctionDataPrint(
std::ostream& os) { // NOLINT
PrintHeader(os, "WasmCapiFunctionData");
@ -1979,8 +1964,8 @@ void WasmIndirectFunctionTable::WasmIndirectFunctionTablePrint(
void ObjectTemplateInfo::ObjectTemplateInfoPrint(std::ostream& os) { // NOLINT
PrintHeader(os, "ObjectTemplateInfo");
os << "\n - tag: " << Brief(tag());
os << "\n - serial_number: " << Brief(serial_number());
os << "\n - tag: " << tag();
os << "\n - serial_number: " << serial_number();
os << "\n - property_list: " << Brief(property_list());
os << "\n - property_accessors: " << Brief(property_accessors());
os << "\n - constructor: " << Brief(constructor());

View File

@ -5,46 +5,56 @@
@abstract
@generateCppClass
extern class TemplateInfo extends Struct {
tag: Object;
serial_number: Object;
tag: Smi;
serial_number: Smi;
number_of_properties: Smi;
property_list: Object;
property_accessors: Object;
property_list: TemplateList|Undefined;
property_accessors: TemplateList|Undefined;
}
@generateCppClass
@generatePrint
extern class FunctionTemplateRareData extends Struct {
// See DECL_RARE_ACCESSORS in FunctionTemplateInfo.
prototype_template: Object;
prototype_provider_template: Object;
parent_template: Object;
named_property_handler: Object;
indexed_property_handler: Object;
instance_template: Object;
instance_call_handler: Object;
access_check_info: Object;
c_function: Foreign|Smi;
c_signature: Foreign|Smi;
prototype_template: ObjectTemplateInfo|Undefined;
prototype_provider_template: FunctionTemplateInfo|Undefined;
parent_template: FunctionTemplateInfo|Undefined;
named_property_handler: InterceptorInfo|Undefined;
indexed_property_handler: InterceptorInfo|Undefined;
instance_template: ObjectTemplateInfo|Undefined;
instance_call_handler: CallHandlerInfo|Undefined;
access_check_info: AccessCheckInfo|Undefined;
c_function: Foreign|Zero;
c_signature: Foreign|Zero;
}
bitfield struct FunctionTemplateInfoFlags extends uint31 {
undetectable: bool: 1 bit;
needs_access_check: bool: 1 bit;
read_only_prototype: bool: 1 bit;
remove_prototype: bool: 1 bit;
do_not_cache: bool: 1 bit;
accept_any_receiver: bool: 1 bit;
}
@generateCppClass
extern class FunctionTemplateInfo extends TemplateInfo {
// Handler invoked when calling an instance of this FunctionTemplateInfo.
// Either CallHandlerInfo or Undefined.
call_code: Object;
class_name: Object;
call_code: CallHandlerInfo|Undefined;
class_name: String|Undefined;
// If the signature is a FunctionTemplateInfo it is used to check whether the
// receiver calling the associated JSFunction is a compatible receiver, i.e.
// it is an instance of the signature FunctionTemplateInfo or any of the
// receiver's prototypes are.
signature: Object;
signature: FunctionTemplateInfo|Undefined;
// If any of the setters declared by DECL_RARE_ACCESSORS are used then a
// FunctionTemplateRareData will be stored here. Until then this contains
// undefined.
rare_data: HeapObject;
shared_function_info: Object;
rare_data: FunctionTemplateRareData|Undefined;
shared_function_info: SharedFunctionInfo|Undefined;
// Internal field to store a flag bitfield.
flag: Smi;
flag: SmiTagged<FunctionTemplateInfoFlags>;
// "length" property of the final JSFunction.
length: Smi;
// Either the_hole or a private symbol. Used to cache the result on
@ -53,8 +63,13 @@ extern class FunctionTemplateInfo extends TemplateInfo {
cached_property_name: Object;
}
bitfield struct ObjectTemplateInfoFlags extends uint31 {
is_immutable_prototype: bool: 1 bit;
embedder_field_count: int32: 29 bit;
}
@generateCppClass
extern class ObjectTemplateInfo extends TemplateInfo {
constructor: Object;
data: Object;
constructor: FunctionTemplateInfo|Undefined;
data: SmiTagged<ObjectTemplateInfoFlags>;
}

View File

@ -24,16 +24,17 @@ TQ_OBJECT_CONSTRUCTORS_IMPL(FunctionTemplateRareData)
NEVER_READ_ONLY_SPACE_IMPL(TemplateInfo)
BOOL_ACCESSORS(FunctionTemplateInfo, flag, undetectable, kUndetectableBit)
BOOL_ACCESSORS(FunctionTemplateInfo, flag, undetectable,
UndetectableBit::kShift)
BOOL_ACCESSORS(FunctionTemplateInfo, flag, needs_access_check,
kNeedsAccessCheckBit)
NeedsAccessCheckBit::kShift)
BOOL_ACCESSORS(FunctionTemplateInfo, flag, read_only_prototype,
kReadOnlyPrototypeBit)
ReadOnlyPrototypeBit::kShift)
BOOL_ACCESSORS(FunctionTemplateInfo, flag, remove_prototype,
kRemovePrototypeBit)
BOOL_ACCESSORS(FunctionTemplateInfo, flag, do_not_cache, kDoNotCacheBit)
RemovePrototypeBit::kShift)
BOOL_ACCESSORS(FunctionTemplateInfo, flag, do_not_cache, DoNotCacheBit::kShift)
BOOL_ACCESSORS(FunctionTemplateInfo, flag, accept_any_receiver,
kAcceptAnyReceiver)
AcceptAnyReceiverBit::kShift)
// static
FunctionTemplateRareData FunctionTemplateInfo::EnsureFunctionTemplateRareData(
@ -61,16 +62,18 @@ FunctionTemplateRareData FunctionTemplateInfo::EnsureFunctionTemplateRareData(
rare_data.set_##Name(*Name); \
}
RARE_ACCESSORS(prototype_template, PrototypeTemplate, Object, undefined)
RARE_ACCESSORS(prototype_provider_template, PrototypeProviderTemplate, Object,
RARE_ACCESSORS(prototype_template, PrototypeTemplate, HeapObject, undefined)
RARE_ACCESSORS(prototype_provider_template, PrototypeProviderTemplate,
HeapObject, undefined)
RARE_ACCESSORS(parent_template, ParentTemplate, HeapObject, undefined)
RARE_ACCESSORS(named_property_handler, NamedPropertyHandler, HeapObject,
undefined)
RARE_ACCESSORS(parent_template, ParentTemplate, Object, undefined)
RARE_ACCESSORS(named_property_handler, NamedPropertyHandler, Object, undefined)
RARE_ACCESSORS(indexed_property_handler, IndexedPropertyHandler, Object,
RARE_ACCESSORS(indexed_property_handler, IndexedPropertyHandler, HeapObject,
undefined)
RARE_ACCESSORS(instance_template, InstanceTemplate, Object, undefined)
RARE_ACCESSORS(instance_call_handler, InstanceCallHandler, Object, undefined)
RARE_ACCESSORS(access_check_info, AccessCheckInfo, Object, undefined)
RARE_ACCESSORS(instance_template, InstanceTemplate, HeapObject, undefined)
RARE_ACCESSORS(instance_call_handler, InstanceCallHandler, HeapObject,
undefined)
RARE_ACCESSORS(access_check_info, AccessCheckInfo, HeapObject, undefined)
RARE_ACCESSORS(c_function, CFunction, Object, Smi(0))
RARE_ACCESSORS(c_signature, CSignature, Object, Smi(0))
#undef RARE_ACCESSORS
@ -110,26 +113,20 @@ ObjectTemplateInfo ObjectTemplateInfo::GetParent(Isolate* isolate) {
}
int ObjectTemplateInfo::embedder_field_count() const {
Object value = data();
DCHECK(value.IsSmi());
return EmbedderFieldCount::decode(Smi::ToInt(value));
return EmbedderFieldCountBits::decode(data());
}
void ObjectTemplateInfo::set_embedder_field_count(int count) {
DCHECK_LE(count, JSObject::kMaxEmbedderFields);
return set_data(
Smi::FromInt(EmbedderFieldCount::update(Smi::ToInt(data()), count)));
return set_data(EmbedderFieldCountBits::update(data(), count));
}
bool ObjectTemplateInfo::immutable_proto() const {
Object value = data();
DCHECK(value.IsSmi());
return IsImmutablePrototype::decode(Smi::ToInt(value));
return IsImmutablePrototypeBit::decode(data());
}
void ObjectTemplateInfo::set_immutable_proto(bool immutable) {
return set_data(Smi::FromInt(
IsImmutablePrototype::update(Smi::ToInt(data()), immutable)));
return set_data(IsImmutablePrototypeBit::update(data(), immutable));
}
bool FunctionTemplateInfo::IsTemplateFor(JSObject object) {

View File

@ -6,6 +6,7 @@
#define V8_OBJECTS_TEMPLATES_H_
#include "src/objects/struct.h"
#include "torque-generated/bit-fields-tq.h"
// Has to be the last include (doesn't have include guards):
#include "src/objects/object-macros.h"
@ -32,9 +33,6 @@ class FunctionTemplateRareData
: public TorqueGeneratedFunctionTemplateRareData<FunctionTemplateRareData,
Struct> {
public:
// Dispatched behavior.
DECL_PRINTER(FunctionTemplateRareData)
TQ_OBJECT_CONSTRUCTORS(FunctionTemplateRareData)
};
@ -51,36 +49,37 @@ class FunctionTemplateInfo
// ObjectTemplateInfo or Undefined, used for the prototype property of the
// resulting JSFunction instance of this FunctionTemplate.
DECL_RARE_ACCESSORS(prototype_template, PrototypeTemplate, Object)
DECL_RARE_ACCESSORS(prototype_template, PrototypeTemplate, HeapObject)
// In the case the prototype_template is Undefined we use the
// prototype_provider_template to retrieve the instance prototype. Either
// contains an ObjectTemplateInfo or Undefined.
// contains an FunctionTemplateInfo or Undefined.
DECL_RARE_ACCESSORS(prototype_provider_template, PrototypeProviderTemplate,
Object)
HeapObject)
// Used to create prototype chains. The parent_template's prototype is set as
// __proto__ of this FunctionTemplate's instance prototype. Is either a
// FunctionTemplateInfo or Undefined.
DECL_RARE_ACCESSORS(parent_template, ParentTemplate, Object)
DECL_RARE_ACCESSORS(parent_template, ParentTemplate, HeapObject)
// Returns an InterceptorInfo or Undefined for named properties.
DECL_RARE_ACCESSORS(named_property_handler, NamedPropertyHandler, Object)
DECL_RARE_ACCESSORS(named_property_handler, NamedPropertyHandler, HeapObject)
// Returns an InterceptorInfo or Undefined for indexed properties/elements.
DECL_RARE_ACCESSORS(indexed_property_handler, IndexedPropertyHandler, Object)
DECL_RARE_ACCESSORS(indexed_property_handler, IndexedPropertyHandler,
HeapObject)
// An ObjectTemplateInfo that is used when instantiating the JSFunction
// associated with this FunctionTemplateInfo. Contains either an
// ObjectTemplateInfo or Undefined. A default instance_template is assigned
// upon first instantiation if it's Undefined.
DECL_RARE_ACCESSORS(instance_template, InstanceTemplate, Object)
DECL_RARE_ACCESSORS(instance_template, InstanceTemplate, HeapObject)
// Either a CallHandlerInfo or Undefined. If an instance_call_handler is
// provided the instances created from the associated JSFunction are marked as
// callable.
DECL_RARE_ACCESSORS(instance_call_handler, InstanceCallHandler, Object)
DECL_RARE_ACCESSORS(instance_call_handler, InstanceCallHandler, HeapObject)
DECL_RARE_ACCESSORS(access_check_info, AccessCheckInfo, Object)
DECL_RARE_ACCESSORS(access_check_info, AccessCheckInfo, HeapObject)
DECL_RARE_ACCESSORS(c_function, CFunction, Object)
DECL_RARE_ACCESSORS(c_signature, CSignature, Object)
@ -138,12 +137,7 @@ class FunctionTemplateInfo
Handle<Object> getter);
// Bit position in the flag, from least significant bit position.
static const int kUndetectableBit = 0;
static const int kNeedsAccessCheckBit = 1;
static const int kReadOnlyPrototypeBit = 2;
static const int kRemovePrototypeBit = 3;
static const int kDoNotCacheBit = 4;
static const int kAcceptAnyReceiver = 5;
DEFINE_TORQUE_GENERATED_FUNCTION_TEMPLATE_INFO_FLAGS()
private:
static inline FunctionTemplateRareData EnsureFunctionTemplateRareData(
@ -170,8 +164,7 @@ class ObjectTemplateInfo
inline ObjectTemplateInfo GetParent(Isolate* isolate);
private:
using IsImmutablePrototype = base::BitField<bool, 0, 1>;
using EmbedderFieldCount = IsImmutablePrototype::Next<int, 29>;
DEFINE_TORQUE_GENERATED_OBJECT_TEMPLATE_INFO_FLAGS()
TQ_OBJECT_CONSTRUCTORS(ObjectTemplateInfo)
};

View File

@ -21737,11 +21737,10 @@ THREADED_TEST(FunctionNew) {
CHECK(v8::Integer::New(isolate, 17)->Equals(env.local(), result).FromJust());
// Serial number should be invalid => should not be cached.
auto serial_number =
i::Smi::cast(i::Handle<i::JSFunction>::cast(v8::Utils::OpenHandle(*func))
->shared()
.get_api_func_data()
.serial_number())
.value();
i::Handle<i::JSFunction>::cast(v8::Utils::OpenHandle(*func))
->shared()
.get_api_func_data()
.serial_number();
CHECK_EQ(i::FunctionTemplateInfo::kInvalidSerialNumber, serial_number);
// Verify that each Function::New creates a new function instance