Commit 19463165 authored by Jakob Gruber's avatar Jakob Gruber Committed by Commit Bot

[feedback] Minor name and type changes

Minor refactors to improve readability and consistency between
FeedbackVectorSpec and FeedbackMetadata:

- Rename FeedbackVectorSpec::slots to slot_count.
- Rename FeedbackVectorSpec::closure_feedback_cells to
  create_closure_slot_count, likewise all related fields.
- Store FeedbackVectorSpec::slot_kinds_ as an array of
  FeedbackSlotKind.

Bug: v8:8888
Change-Id: I3a45177163d1484b1625de8dfba5c6c05cfc426d
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2512908Reviewed-by: 's avatarMythri Alle <mythria@chromium.org>
Reviewed-by: 's avatarDominik Inführ <dinfuehr@chromium.org>
Reviewed-by: 's avatarMichael Stanton <mvstanton@chromium.org>
Commit-Queue: Michael Stanton <mvstanton@chromium.org>
Auto-Submit: Jakob Gruber <jgruber@chromium.org>
Cr-Commit-Position: refs/heads/master@{#70943}
parent 7c437e98
...@@ -583,7 +583,7 @@ void NativeContext::NativeContextVerify(Isolate* isolate) { ...@@ -583,7 +583,7 @@ void NativeContext::NativeContextVerify(Isolate* isolate) {
} }
void FeedbackMetadata::FeedbackMetadataVerify(Isolate* isolate) { void FeedbackMetadata::FeedbackMetadataVerify(Isolate* isolate) {
if (slot_count() == 0 && closure_feedback_cell_count() == 0) { if (slot_count() == 0 && create_closure_slot_count() == 0) {
CHECK_EQ(ReadOnlyRoots(isolate).empty_feedback_metadata(), *this); CHECK_EQ(ReadOnlyRoots(isolate).empty_feedback_metadata(), *this);
} else { } else {
FeedbackMetadataIterator iter(*this); FeedbackMetadataIterator iter(*this);
......
...@@ -846,14 +846,13 @@ void FeedbackVectorSpec::Print() { ...@@ -846,14 +846,13 @@ void FeedbackVectorSpec::Print() {
} }
void FeedbackVectorSpec::FeedbackVectorSpecPrint(std::ostream& os) { // NOLINT void FeedbackVectorSpec::FeedbackVectorSpecPrint(std::ostream& os) { // NOLINT
int slot_count = slots(); os << " - slot_count: " << slot_count();
os << " - slot_count: " << slot_count; if (slot_count() == 0) {
if (slot_count == 0) {
os << " (empty)\n"; os << " (empty)\n";
return; return;
} }
for (int slot = 0; slot < slot_count;) { for (int slot = 0; slot < slot_count();) {
FeedbackSlotKind kind = GetKind(FeedbackSlot(slot)); FeedbackSlotKind kind = GetKind(FeedbackSlot(slot));
int entry_size = FeedbackMetadata::GetSlotSize(kind); int entry_size = FeedbackMetadata::GetSlotSize(kind);
DCHECK_LT(0, entry_size); DCHECK_LT(0, entry_size);
...@@ -866,6 +865,7 @@ void FeedbackVectorSpec::FeedbackVectorSpecPrint(std::ostream& os) { // NOLINT ...@@ -866,6 +865,7 @@ void FeedbackVectorSpec::FeedbackVectorSpecPrint(std::ostream& os) { // NOLINT
void FeedbackMetadata::FeedbackMetadataPrint(std::ostream& os) { void FeedbackMetadata::FeedbackMetadataPrint(std::ostream& os) {
PrintHeader(os, "FeedbackMetadata"); PrintHeader(os, "FeedbackMetadata");
os << "\n - slot_count: " << slot_count(); os << "\n - slot_count: " << slot_count();
os << "\n - create_closure_slot_count: " << create_closure_slot_count();
FeedbackMetadataIterator iter(*this); FeedbackMetadataIterator iter(*this);
while (iter.HasNext()) { while (iter.HasNext()) {
......
...@@ -409,14 +409,14 @@ FactoryBase<Impl>::NewTemplateObjectDescription( ...@@ -409,14 +409,14 @@ FactoryBase<Impl>::NewTemplateObjectDescription(
template <typename Impl> template <typename Impl>
Handle<FeedbackMetadata> FactoryBase<Impl>::NewFeedbackMetadata( Handle<FeedbackMetadata> FactoryBase<Impl>::NewFeedbackMetadata(
int slot_count, int feedback_cell_count, AllocationType allocation) { int slot_count, int create_closure_slot_count, AllocationType allocation) {
DCHECK_LE(0, slot_count); DCHECK_LE(0, slot_count);
int size = FeedbackMetadata::SizeFor(slot_count); int size = FeedbackMetadata::SizeFor(slot_count);
HeapObject result = AllocateRawWithImmortalMap( HeapObject result = AllocateRawWithImmortalMap(
size, allocation, read_only_roots().feedback_metadata_map()); size, allocation, read_only_roots().feedback_metadata_map());
Handle<FeedbackMetadata> data(FeedbackMetadata::cast(result), isolate()); Handle<FeedbackMetadata> data(FeedbackMetadata::cast(result), isolate());
data->set_slot_count(slot_count); data->set_slot_count(slot_count);
data->set_closure_feedback_cell_count(feedback_cell_count); data->set_create_closure_slot_count(create_closure_slot_count);
// Initialize the data section to 0. // Initialize the data section to 0.
int data_size = size - FeedbackMetadata::kHeaderSize; int data_size = size - FeedbackMetadata::kHeaderSize;
......
...@@ -137,7 +137,7 @@ class EXPORT_TEMPLATE_DECLARE(V8_EXPORT_PRIVATE) FactoryBase { ...@@ -137,7 +137,7 @@ class EXPORT_TEMPLATE_DECLARE(V8_EXPORT_PRIVATE) FactoryBase {
// Allocates a FeedbackMedata object and zeroes the data section. // Allocates a FeedbackMedata object and zeroes the data section.
Handle<FeedbackMetadata> NewFeedbackMetadata( Handle<FeedbackMetadata> NewFeedbackMetadata(
int slot_count, int feedback_cell_count, int slot_count, int create_closure_slot_count,
AllocationType allocation = AllocationType::kOld); AllocationType allocation = AllocationType::kOld);
Handle<CoverageInfo> NewCoverageInfo(const ZoneVector<SourceRange>& slots); Handle<CoverageInfo> NewCoverageInfo(const ZoneVector<SourceRange>& slots);
......
...@@ -2531,7 +2531,7 @@ void BytecodeGenerator::BuildInstanceMemberInitialization(Register constructor, ...@@ -2531,7 +2531,7 @@ void BytecodeGenerator::BuildInstanceMemberInitialization(Register constructor,
void BytecodeGenerator::VisitNativeFunctionLiteral( void BytecodeGenerator::VisitNativeFunctionLiteral(
NativeFunctionLiteral* expr) { NativeFunctionLiteral* expr) {
size_t entry = builder()->AllocateDeferredConstantPoolEntry(); size_t entry = builder()->AllocateDeferredConstantPoolEntry();
int index = feedback_spec()->AddFeedbackCellForCreateClosure(); int index = feedback_spec()->AddCreateClosureSlot();
uint8_t flags = CreateClosureFlags::Encode(false, false, false); uint8_t flags = CreateClosureFlags::Encode(false, false, false);
builder()->CreateClosure(entry, index, flags); builder()->CreateClosure(entry, index, flags);
native_function_literals_.push_back(std::make_pair(expr, entry)); native_function_literals_.push_back(std::make_pair(expr, entry));
...@@ -6658,7 +6658,7 @@ int BytecodeGenerator::GetCachedCreateClosureSlot(FunctionLiteral* literal) { ...@@ -6658,7 +6658,7 @@ int BytecodeGenerator::GetCachedCreateClosureSlot(FunctionLiteral* literal) {
if (index != -1) { if (index != -1) {
return index; return index;
} }
index = feedback_spec()->AddFeedbackCellForCreateClosure(); index = feedback_spec()->AddCreateClosureSlot();
feedback_slot_cache()->Put(slot_kind, literal, index); feedback_slot_cache()->Put(slot_kind, literal, index);
return index; return index;
} }
......
...@@ -35,8 +35,8 @@ CAST_ACCESSOR(ClosureFeedbackCellArray) ...@@ -35,8 +35,8 @@ CAST_ACCESSOR(ClosureFeedbackCellArray)
INT32_ACCESSORS(FeedbackMetadata, slot_count, kSlotCountOffset) INT32_ACCESSORS(FeedbackMetadata, slot_count, kSlotCountOffset)
INT32_ACCESSORS(FeedbackMetadata, closure_feedback_cell_count, INT32_ACCESSORS(FeedbackMetadata, create_closure_slot_count,
kFeedbackCellCountOffset) kCreateClosureSlotCountOffset)
int32_t FeedbackMetadata::synchronized_slot_count() const { int32_t FeedbackMetadata::synchronized_slot_count() const {
return base::Acquire_Load( return base::Acquire_Load(
......
...@@ -20,7 +20,7 @@ namespace v8 { ...@@ -20,7 +20,7 @@ namespace v8 {
namespace internal { namespace internal {
FeedbackSlot FeedbackVectorSpec::AddSlot(FeedbackSlotKind kind) { FeedbackSlot FeedbackVectorSpec::AddSlot(FeedbackSlotKind kind) {
int slot = slots(); int slot = slot_count();
int entries_per_slot = FeedbackMetadata::GetSlotSize(kind); int entries_per_slot = FeedbackMetadata::GetSlotSize(kind);
append(kind); append(kind);
for (int i = 1; i < entries_per_slot; i++) { for (int i = 1; i < entries_per_slot; i++) {
...@@ -39,9 +39,7 @@ FeedbackSlot FeedbackVectorSpec::AddTypeProfileSlot() { ...@@ -39,9 +39,7 @@ FeedbackSlot FeedbackVectorSpec::AddTypeProfileSlot() {
bool FeedbackVectorSpec::HasTypeProfileSlot() const { bool FeedbackVectorSpec::HasTypeProfileSlot() const {
FeedbackSlot slot = FeedbackSlot slot =
FeedbackVector::ToSlot(FeedbackVectorSpec::kTypeProfileSlotIndex); FeedbackVector::ToSlot(FeedbackVectorSpec::kTypeProfileSlotIndex);
if (slots() <= slot.ToInt()) { if (slot_count() <= slot.ToInt()) return false;
return false;
}
return GetKind(slot) == FeedbackSlotKind::kTypeProfile; return GetKind(slot) == FeedbackSlotKind::kTypeProfile;
} }
...@@ -82,10 +80,10 @@ Handle<FeedbackMetadata> FeedbackMetadata::New(LocalIsolate* isolate, ...@@ -82,10 +80,10 @@ Handle<FeedbackMetadata> FeedbackMetadata::New(LocalIsolate* isolate,
const FeedbackVectorSpec* spec) { const FeedbackVectorSpec* spec) {
auto* factory = isolate->factory(); auto* factory = isolate->factory();
const int slot_count = spec == nullptr ? 0 : spec->slots(); const int slot_count = spec == nullptr ? 0 : spec->slot_count();
const int closure_feedback_cell_count = const int create_closure_slot_count =
spec == nullptr ? 0 : spec->closure_feedback_cells(); spec == nullptr ? 0 : spec->create_closure_slot_count();
if (slot_count == 0 && closure_feedback_cell_count == 0) { if (slot_count == 0 && create_closure_slot_count == 0) {
return factory->empty_feedback_metadata(); return factory->empty_feedback_metadata();
} }
#ifdef DEBUG #ifdef DEBUG
...@@ -102,7 +100,7 @@ Handle<FeedbackMetadata> FeedbackMetadata::New(LocalIsolate* isolate, ...@@ -102,7 +100,7 @@ Handle<FeedbackMetadata> FeedbackMetadata::New(LocalIsolate* isolate,
#endif #endif
Handle<FeedbackMetadata> metadata = Handle<FeedbackMetadata> metadata =
factory->NewFeedbackMetadata(slot_count, closure_feedback_cell_count); factory->NewFeedbackMetadata(slot_count, create_closure_slot_count);
// Initialize the slots. The raw data section has already been pre-zeroed in // Initialize the slots. The raw data section has already been pre-zeroed in
// NewFeedbackMetadata. // NewFeedbackMetadata.
...@@ -123,7 +121,7 @@ template Handle<FeedbackMetadata> FeedbackMetadata::New( ...@@ -123,7 +121,7 @@ template Handle<FeedbackMetadata> FeedbackMetadata::New(
bool FeedbackMetadata::SpecDiffersFrom( bool FeedbackMetadata::SpecDiffersFrom(
const FeedbackVectorSpec* other_spec) const { const FeedbackVectorSpec* other_spec) const {
if (other_spec->slots() != slot_count()) { if (other_spec->slot_count() != slot_count()) {
return true; return true;
} }
...@@ -221,7 +219,7 @@ Handle<ClosureFeedbackCellArray> ClosureFeedbackCellArray::New( ...@@ -221,7 +219,7 @@ Handle<ClosureFeedbackCellArray> ClosureFeedbackCellArray::New(
Factory* factory = isolate->factory(); Factory* factory = isolate->factory();
int num_feedback_cells = int num_feedback_cells =
shared->feedback_metadata().closure_feedback_cell_count(); shared->feedback_metadata().create_closure_slot_count();
Handle<ClosureFeedbackCellArray> feedback_cell_array = Handle<ClosureFeedbackCellArray> feedback_cell_array =
factory->NewClosureFeedbackCellArray(num_feedback_cells); factory->NewClosureFeedbackCellArray(num_feedback_cells);
......
...@@ -26,7 +26,7 @@ namespace internal { ...@@ -26,7 +26,7 @@ namespace internal {
class IsCompiledScope; class IsCompiledScope;
enum class FeedbackSlotKind { enum class FeedbackSlotKind : uint8_t {
// This kind means that the slot points to the middle of other slot // This kind means that the slot points to the middle of other slot
// which occupies more than one feedback vector element. // which occupies more than one feedback vector element.
// There must be no such slots in the system. // There must be no such slots in the system.
...@@ -344,20 +344,17 @@ class FeedbackVector ...@@ -344,20 +344,17 @@ class FeedbackVector
class V8_EXPORT_PRIVATE FeedbackVectorSpec { class V8_EXPORT_PRIVATE FeedbackVectorSpec {
public: public:
explicit FeedbackVectorSpec(Zone* zone) explicit FeedbackVectorSpec(Zone* zone) : slot_kinds_(zone) {
: slot_kinds_(zone), num_closure_feedback_cells_(0) {
slot_kinds_.reserve(16); slot_kinds_.reserve(16);
} }
int slots() const { return static_cast<int>(slot_kinds_.size()); } int slot_count() const { return static_cast<int>(slot_kinds_.size()); }
int closure_feedback_cells() const { return num_closure_feedback_cells_; } int create_closure_slot_count() const { return create_closure_slot_count_; }
int AddFeedbackCellForCreateClosure() { int AddCreateClosureSlot() { return create_closure_slot_count_++; }
return num_closure_feedback_cells_++;
}
FeedbackSlotKind GetKind(FeedbackSlot slot) const { FeedbackSlotKind GetKind(FeedbackSlot slot) const {
return static_cast<FeedbackSlotKind>(slot_kinds_.at(slot.ToInt())); return slot_kinds_.at(slot.ToInt());
} }
bool HasTypeProfileSlot() const; bool HasTypeProfileSlot() const;
...@@ -458,12 +455,11 @@ class V8_EXPORT_PRIVATE FeedbackVectorSpec { ...@@ -458,12 +455,11 @@ class V8_EXPORT_PRIVATE FeedbackVectorSpec {
private: private:
FeedbackSlot AddSlot(FeedbackSlotKind kind); FeedbackSlot AddSlot(FeedbackSlotKind kind);
void append(FeedbackSlotKind kind) { void append(FeedbackSlotKind kind) { slot_kinds_.push_back(kind); }
slot_kinds_.push_back(static_cast<unsigned char>(kind));
}
ZoneVector<unsigned char> slot_kinds_; STATIC_ASSERT(sizeof(FeedbackSlotKind) == sizeof(uint8_t));
unsigned int num_closure_feedback_cells_; ZoneVector<FeedbackSlotKind> slot_kinds_;
int create_closure_slot_count_ = 0;
friend class SharedFeedbackSlot; friend class SharedFeedbackSlot;
}; };
...@@ -502,7 +498,7 @@ class FeedbackMetadata : public HeapObject { ...@@ -502,7 +498,7 @@ class FeedbackMetadata : public HeapObject {
// int32. // int32.
// TODO(mythria): Consider using 16 bits for this and slot_count so that we // TODO(mythria): Consider using 16 bits for this and slot_count so that we
// can save 4 bytes. // can save 4 bytes.
DECL_INT32_ACCESSORS(closure_feedback_cell_count) DECL_INT32_ACCESSORS(create_closure_slot_count)
// Get slot_count using an acquire load. // Get slot_count using an acquire load.
inline int32_t synchronized_slot_count() const; inline int32_t synchronized_slot_count() const;
...@@ -535,9 +531,13 @@ class FeedbackMetadata : public HeapObject { ...@@ -535,9 +531,13 @@ class FeedbackMetadata : public HeapObject {
return OBJECT_POINTER_ALIGN(kHeaderSize + length(slot_count) * kInt32Size); return OBJECT_POINTER_ALIGN(kHeaderSize + length(slot_count) * kInt32Size);
} }
static const int kSlotCountOffset = HeapObject::kHeaderSize; #define FIELDS(V) \
static const int kFeedbackCellCountOffset = kSlotCountOffset + kInt32Size; V(kSlotCountOffset, kInt32Size) \
static const int kHeaderSize = kFeedbackCellCountOffset + kInt32Size; V(kCreateClosureSlotCountOffset, kInt32Size) \
V(kHeaderSize, 0)
DEFINE_FIELD_OFFSET_CONSTANTS(HeapObject::kHeaderSize, FIELDS)
#undef FIELDS
class BodyDescriptor; class BodyDescriptor;
......
...@@ -89,7 +89,7 @@ TEST(VectorStructure) { ...@@ -89,7 +89,7 @@ TEST(VectorStructure) {
{ {
FeedbackVectorSpec spec(&zone); FeedbackVectorSpec spec(&zone);
spec.AddForInSlot(); spec.AddForInSlot();
spec.AddFeedbackCellForCreateClosure(); spec.AddCreateClosureSlot();
spec.AddForInSlot(); spec.AddForInSlot();
vector = NewFeedbackVector(isolate, &spec); vector = NewFeedbackVector(isolate, &spec);
FeedbackVectorHelper helper(vector); FeedbackVectorHelper helper(vector);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment