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) {
}
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);
} else {
FeedbackMetadataIterator iter(*this);
......
......@@ -846,14 +846,13 @@ void FeedbackVectorSpec::Print() {
}
void FeedbackVectorSpec::FeedbackVectorSpecPrint(std::ostream& os) { // NOLINT
int slot_count = slots();
os << " - slot_count: " << slot_count;
if (slot_count == 0) {
os << " - slot_count: " << slot_count();
if (slot_count() == 0) {
os << " (empty)\n";
return;
}
for (int slot = 0; slot < slot_count;) {
for (int slot = 0; slot < slot_count();) {
FeedbackSlotKind kind = GetKind(FeedbackSlot(slot));
int entry_size = FeedbackMetadata::GetSlotSize(kind);
DCHECK_LT(0, entry_size);
......@@ -866,6 +865,7 @@ void FeedbackVectorSpec::FeedbackVectorSpecPrint(std::ostream& os) { // NOLINT
void FeedbackMetadata::FeedbackMetadataPrint(std::ostream& os) {
PrintHeader(os, "FeedbackMetadata");
os << "\n - slot_count: " << slot_count();
os << "\n - create_closure_slot_count: " << create_closure_slot_count();
FeedbackMetadataIterator iter(*this);
while (iter.HasNext()) {
......
......@@ -409,14 +409,14 @@ FactoryBase<Impl>::NewTemplateObjectDescription(
template <typename Impl>
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);
int size = FeedbackMetadata::SizeFor(slot_count);
HeapObject result = AllocateRawWithImmortalMap(
size, allocation, read_only_roots().feedback_metadata_map());
Handle<FeedbackMetadata> data(FeedbackMetadata::cast(result), isolate());
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.
int data_size = size - FeedbackMetadata::kHeaderSize;
......
......@@ -137,7 +137,7 @@ class EXPORT_TEMPLATE_DECLARE(V8_EXPORT_PRIVATE) FactoryBase {
// Allocates a FeedbackMedata object and zeroes the data section.
Handle<FeedbackMetadata> NewFeedbackMetadata(
int slot_count, int feedback_cell_count,
int slot_count, int create_closure_slot_count,
AllocationType allocation = AllocationType::kOld);
Handle<CoverageInfo> NewCoverageInfo(const ZoneVector<SourceRange>& slots);
......
......@@ -2531,7 +2531,7 @@ void BytecodeGenerator::BuildInstanceMemberInitialization(Register constructor,
void BytecodeGenerator::VisitNativeFunctionLiteral(
NativeFunctionLiteral* expr) {
size_t entry = builder()->AllocateDeferredConstantPoolEntry();
int index = feedback_spec()->AddFeedbackCellForCreateClosure();
int index = feedback_spec()->AddCreateClosureSlot();
uint8_t flags = CreateClosureFlags::Encode(false, false, false);
builder()->CreateClosure(entry, index, flags);
native_function_literals_.push_back(std::make_pair(expr, entry));
......@@ -6658,7 +6658,7 @@ int BytecodeGenerator::GetCachedCreateClosureSlot(FunctionLiteral* literal) {
if (index != -1) {
return index;
}
index = feedback_spec()->AddFeedbackCellForCreateClosure();
index = feedback_spec()->AddCreateClosureSlot();
feedback_slot_cache()->Put(slot_kind, literal, index);
return index;
}
......
......@@ -35,8 +35,8 @@ CAST_ACCESSOR(ClosureFeedbackCellArray)
INT32_ACCESSORS(FeedbackMetadata, slot_count, kSlotCountOffset)
INT32_ACCESSORS(FeedbackMetadata, closure_feedback_cell_count,
kFeedbackCellCountOffset)
INT32_ACCESSORS(FeedbackMetadata, create_closure_slot_count,
kCreateClosureSlotCountOffset)
int32_t FeedbackMetadata::synchronized_slot_count() const {
return base::Acquire_Load(
......
......@@ -20,7 +20,7 @@ namespace v8 {
namespace internal {
FeedbackSlot FeedbackVectorSpec::AddSlot(FeedbackSlotKind kind) {
int slot = slots();
int slot = slot_count();
int entries_per_slot = FeedbackMetadata::GetSlotSize(kind);
append(kind);
for (int i = 1; i < entries_per_slot; i++) {
......@@ -39,9 +39,7 @@ FeedbackSlot FeedbackVectorSpec::AddTypeProfileSlot() {
bool FeedbackVectorSpec::HasTypeProfileSlot() const {
FeedbackSlot slot =
FeedbackVector::ToSlot(FeedbackVectorSpec::kTypeProfileSlotIndex);
if (slots() <= slot.ToInt()) {
return false;
}
if (slot_count() <= slot.ToInt()) return false;
return GetKind(slot) == FeedbackSlotKind::kTypeProfile;
}
......@@ -82,10 +80,10 @@ Handle<FeedbackMetadata> FeedbackMetadata::New(LocalIsolate* isolate,
const FeedbackVectorSpec* spec) {
auto* factory = isolate->factory();
const int slot_count = spec == nullptr ? 0 : spec->slots();
const int closure_feedback_cell_count =
spec == nullptr ? 0 : spec->closure_feedback_cells();
if (slot_count == 0 && closure_feedback_cell_count == 0) {
const int slot_count = spec == nullptr ? 0 : spec->slot_count();
const int create_closure_slot_count =
spec == nullptr ? 0 : spec->create_closure_slot_count();
if (slot_count == 0 && create_closure_slot_count == 0) {
return factory->empty_feedback_metadata();
}
#ifdef DEBUG
......@@ -102,7 +100,7 @@ Handle<FeedbackMetadata> FeedbackMetadata::New(LocalIsolate* isolate,
#endif
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
// NewFeedbackMetadata.
......@@ -123,7 +121,7 @@ template Handle<FeedbackMetadata> FeedbackMetadata::New(
bool FeedbackMetadata::SpecDiffersFrom(
const FeedbackVectorSpec* other_spec) const {
if (other_spec->slots() != slot_count()) {
if (other_spec->slot_count() != slot_count()) {
return true;
}
......@@ -221,7 +219,7 @@ Handle<ClosureFeedbackCellArray> ClosureFeedbackCellArray::New(
Factory* factory = isolate->factory();
int num_feedback_cells =
shared->feedback_metadata().closure_feedback_cell_count();
shared->feedback_metadata().create_closure_slot_count();
Handle<ClosureFeedbackCellArray> feedback_cell_array =
factory->NewClosureFeedbackCellArray(num_feedback_cells);
......
......@@ -26,7 +26,7 @@ namespace internal {
class IsCompiledScope;
enum class FeedbackSlotKind {
enum class FeedbackSlotKind : uint8_t {
// This kind means that the slot points to the middle of other slot
// which occupies more than one feedback vector element.
// There must be no such slots in the system.
......@@ -344,20 +344,17 @@ class FeedbackVector
class V8_EXPORT_PRIVATE FeedbackVectorSpec {
public:
explicit FeedbackVectorSpec(Zone* zone)
: slot_kinds_(zone), num_closure_feedback_cells_(0) {
explicit FeedbackVectorSpec(Zone* zone) : slot_kinds_(zone) {
slot_kinds_.reserve(16);
}
int slots() const { return static_cast<int>(slot_kinds_.size()); }
int closure_feedback_cells() const { return num_closure_feedback_cells_; }
int slot_count() const { return static_cast<int>(slot_kinds_.size()); }
int create_closure_slot_count() const { return create_closure_slot_count_; }
int AddFeedbackCellForCreateClosure() {
return num_closure_feedback_cells_++;
}
int AddCreateClosureSlot() { return create_closure_slot_count_++; }
FeedbackSlotKind GetKind(FeedbackSlot slot) const {
return static_cast<FeedbackSlotKind>(slot_kinds_.at(slot.ToInt()));
return slot_kinds_.at(slot.ToInt());
}
bool HasTypeProfileSlot() const;
......@@ -458,12 +455,11 @@ class V8_EXPORT_PRIVATE FeedbackVectorSpec {
private:
FeedbackSlot AddSlot(FeedbackSlotKind kind);
void append(FeedbackSlotKind kind) {
slot_kinds_.push_back(static_cast<unsigned char>(kind));
}
void append(FeedbackSlotKind kind) { slot_kinds_.push_back(kind); }
ZoneVector<unsigned char> slot_kinds_;
unsigned int num_closure_feedback_cells_;
STATIC_ASSERT(sizeof(FeedbackSlotKind) == sizeof(uint8_t));
ZoneVector<FeedbackSlotKind> slot_kinds_;
int create_closure_slot_count_ = 0;
friend class SharedFeedbackSlot;
};
......@@ -502,7 +498,7 @@ class FeedbackMetadata : public HeapObject {
// int32.
// TODO(mythria): Consider using 16 bits for this and slot_count so that we
// 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.
inline int32_t synchronized_slot_count() const;
......@@ -535,9 +531,13 @@ class FeedbackMetadata : public HeapObject {
return OBJECT_POINTER_ALIGN(kHeaderSize + length(slot_count) * kInt32Size);
}
static const int kSlotCountOffset = HeapObject::kHeaderSize;
static const int kFeedbackCellCountOffset = kSlotCountOffset + kInt32Size;
static const int kHeaderSize = kFeedbackCellCountOffset + kInt32Size;
#define FIELDS(V) \
V(kSlotCountOffset, kInt32Size) \
V(kCreateClosureSlotCountOffset, kInt32Size) \
V(kHeaderSize, 0)
DEFINE_FIELD_OFFSET_CONSTANTS(HeapObject::kHeaderSize, FIELDS)
#undef FIELDS
class BodyDescriptor;
......
......@@ -89,7 +89,7 @@ TEST(VectorStructure) {
{
FeedbackVectorSpec spec(&zone);
spec.AddForInSlot();
spec.AddFeedbackCellForCreateClosure();
spec.AddCreateClosureSlot();
spec.AddForInSlot();
vector = NewFeedbackVector(isolate, &spec);
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