Commit fa530822 authored by mvstanton's avatar mvstanton Committed by Commit bot

Make type-feedback-vector.h usable without objects-inl.h header (and others).

Pure refactoring to further reduce the header dependency tangle.

BUG=
R=mstarzinger@chromium.org

Review URL: https://codereview.chromium.org/1309303008

Cr-Commit-Position: refs/heads/master@{#30508}
parent af1b9521
...@@ -10,11 +10,118 @@ ...@@ -10,11 +10,118 @@
namespace v8 { namespace v8 {
namespace internal { namespace internal {
// static
TypeFeedbackVector* TypeFeedbackVector::cast(Object* obj) {
DCHECK(obj->IsTypeFeedbackVector());
return reinterpret_cast<TypeFeedbackVector*>(obj);
}
int TypeFeedbackVector::first_ic_slot_index() const {
DCHECK(length() >= kReservedIndexCount);
return Smi::cast(get(kFirstICSlotIndex))->value();
}
int TypeFeedbackVector::ic_with_type_info_count() {
return length() > 0 ? Smi::cast(get(kWithTypesIndex))->value() : 0;
}
void TypeFeedbackVector::change_ic_with_type_info_count(int delta) {
if (delta == 0) return;
int value = ic_with_type_info_count() + delta;
// Could go negative because of the debugger.
if (value >= 0) {
set(kWithTypesIndex, Smi::FromInt(value));
}
}
int TypeFeedbackVector::ic_generic_count() {
return length() > 0 ? Smi::cast(get(kGenericCountIndex))->value() : 0;
}
void TypeFeedbackVector::change_ic_generic_count(int delta) {
if (delta == 0) return;
int value = ic_generic_count() + delta;
if (value >= 0) {
set(kGenericCountIndex, Smi::FromInt(value));
}
}
int TypeFeedbackVector::Slots() const {
if (length() == 0) return 0;
return Max(
0, first_ic_slot_index() - ic_metadata_length() - kReservedIndexCount);
}
int TypeFeedbackVector::ICSlots() const {
if (length() == 0) return 0;
return (length() - first_ic_slot_index()) / elements_per_ic_slot();
}
int TypeFeedbackVector::ic_metadata_length() const { int TypeFeedbackVector::ic_metadata_length() const {
return VectorICComputer::word_count(ICSlots()); return VectorICComputer::word_count(ICSlots());
} }
// Conversion from a slot or ic slot to an integer index to the underlying
// array.
int TypeFeedbackVector::GetIndex(FeedbackVectorSlot slot) const {
DCHECK(slot.ToInt() < first_ic_slot_index());
return kReservedIndexCount + ic_metadata_length() + slot.ToInt();
}
int TypeFeedbackVector::GetIndex(FeedbackVectorICSlot slot) const {
int first_ic_slot = first_ic_slot_index();
DCHECK(slot.ToInt() < ICSlots());
return first_ic_slot + slot.ToInt() * elements_per_ic_slot();
}
// Conversion from an integer index to either a slot or an ic slot. The caller
// should know what kind she expects.
FeedbackVectorSlot TypeFeedbackVector::ToSlot(int index) const {
DCHECK(index >= kReservedIndexCount && index < first_ic_slot_index());
return FeedbackVectorSlot(index - ic_metadata_length() - kReservedIndexCount);
}
FeedbackVectorICSlot TypeFeedbackVector::ToICSlot(int index) const {
DCHECK(index >= first_ic_slot_index() && index < length());
int ic_slot = (index - first_ic_slot_index()) / elements_per_ic_slot();
return FeedbackVectorICSlot(ic_slot);
}
Object* TypeFeedbackVector::Get(FeedbackVectorSlot slot) const {
return get(GetIndex(slot));
}
void TypeFeedbackVector::Set(FeedbackVectorSlot slot, Object* value,
WriteBarrierMode mode) {
set(GetIndex(slot), value, mode);
}
Object* TypeFeedbackVector::Get(FeedbackVectorICSlot slot) const {
return get(GetIndex(slot));
}
void TypeFeedbackVector::Set(FeedbackVectorICSlot slot, Object* value,
WriteBarrierMode mode) {
set(GetIndex(slot), value, mode);
}
Handle<Object> TypeFeedbackVector::UninitializedSentinel(Isolate* isolate) { Handle<Object> TypeFeedbackVector::UninitializedSentinel(Isolate* isolate) {
return isolate->factory()->uninitialized_symbol(); return isolate->factory()->uninitialized_symbol();
} }
...@@ -33,6 +140,32 @@ Handle<Object> TypeFeedbackVector::PremonomorphicSentinel(Isolate* isolate) { ...@@ -33,6 +140,32 @@ Handle<Object> TypeFeedbackVector::PremonomorphicSentinel(Isolate* isolate) {
Object* TypeFeedbackVector::RawUninitializedSentinel(Heap* heap) { Object* TypeFeedbackVector::RawUninitializedSentinel(Heap* heap) {
return heap->uninitialized_symbol(); return heap->uninitialized_symbol();
} }
Object* FeedbackNexus::GetFeedback() const { return vector()->Get(slot()); }
Object* FeedbackNexus::GetFeedbackExtra() const {
DCHECK(TypeFeedbackVector::elements_per_ic_slot() > 1);
int extra_index = vector()->GetIndex(slot()) + 1;
return vector()->get(extra_index);
}
void FeedbackNexus::SetFeedback(Object* feedback, WriteBarrierMode mode) {
vector()->Set(slot(), feedback, mode);
}
void FeedbackNexus::SetFeedbackExtra(Object* feedback_extra,
WriteBarrierMode mode) {
DCHECK(TypeFeedbackVector::elements_per_ic_slot() > 1);
int index = vector()->GetIndex(slot()) + 1;
vector()->set(index, feedback_extra, mode);
}
Isolate* FeedbackNexus::GetIsolate() const { return vector()->GetIsolate(); }
} }
} // namespace v8::internal } // namespace v8::internal
......
...@@ -87,10 +87,7 @@ class ZoneFeedbackVectorSpec { ...@@ -87,10 +87,7 @@ class ZoneFeedbackVectorSpec {
class TypeFeedbackVector : public FixedArray { class TypeFeedbackVector : public FixedArray {
public: public:
// Casting. // Casting.
static TypeFeedbackVector* cast(Object* obj) { static inline TypeFeedbackVector* cast(Object* obj);
DCHECK(obj->IsTypeFeedbackVector());
return reinterpret_cast<TypeFeedbackVector*>(obj);
}
static const int kReservedIndexCount = 3; static const int kReservedIndexCount = 3;
static const int kFirstICSlotIndex = 0; static const int kFirstICSlotIndex = 0;
...@@ -99,89 +96,33 @@ class TypeFeedbackVector : public FixedArray { ...@@ -99,89 +96,33 @@ class TypeFeedbackVector : public FixedArray {
static int elements_per_ic_slot() { return 2; } static int elements_per_ic_slot() { return 2; }
int first_ic_slot_index() const { inline int first_ic_slot_index() const;
DCHECK(length() >= kReservedIndexCount); inline int ic_with_type_info_count();
return Smi::cast(get(kFirstICSlotIndex))->value(); inline void change_ic_with_type_info_count(int delta);
} inline int ic_generic_count();
inline void change_ic_generic_count(int delta);
int ic_with_type_info_count() {
return length() > 0 ? Smi::cast(get(kWithTypesIndex))->value() : 0;
}
void change_ic_with_type_info_count(int delta) {
if (delta == 0) return;
int value = ic_with_type_info_count() + delta;
// Could go negative because of the debugger.
if (value >= 0) {
set(kWithTypesIndex, Smi::FromInt(value));
}
}
int ic_generic_count() {
return length() > 0 ? Smi::cast(get(kGenericCountIndex))->value() : 0;
}
void change_ic_generic_count(int delta) {
if (delta == 0) return;
int value = ic_generic_count() + delta;
if (value >= 0) {
set(kGenericCountIndex, Smi::FromInt(value));
}
}
inline int ic_metadata_length() const; inline int ic_metadata_length() const;
bool SpecDiffersFrom(const ZoneFeedbackVectorSpec* other_spec) const; bool SpecDiffersFrom(const ZoneFeedbackVectorSpec* other_spec) const;
int Slots() const { inline int Slots() const;
if (length() == 0) return 0; inline int ICSlots() const;
return Max(
0, first_ic_slot_index() - ic_metadata_length() - kReservedIndexCount);
}
int ICSlots() const {
if (length() == 0) return 0;
return (length() - first_ic_slot_index()) / elements_per_ic_slot();
}
// Conversion from a slot or ic slot to an integer index to the underlying // Conversion from a slot or ic slot to an integer index to the underlying
// array. // array.
int GetIndex(FeedbackVectorSlot slot) const { inline int GetIndex(FeedbackVectorSlot slot) const;
DCHECK(slot.ToInt() < first_ic_slot_index()); inline int GetIndex(FeedbackVectorICSlot slot) const;
return kReservedIndexCount + ic_metadata_length() + slot.ToInt();
}
int GetIndex(FeedbackVectorICSlot slot) const {
int first_ic_slot = first_ic_slot_index();
DCHECK(slot.ToInt() < ICSlots());
return first_ic_slot + slot.ToInt() * elements_per_ic_slot();
}
// Conversion from an integer index to either a slot or an ic slot. The caller // Conversion from an integer index to either a slot or an ic slot. The caller
// should know what kind she expects. // should know what kind she expects.
FeedbackVectorSlot ToSlot(int index) const { inline FeedbackVectorSlot ToSlot(int index) const;
DCHECK(index >= kReservedIndexCount && index < first_ic_slot_index()); inline FeedbackVectorICSlot ToICSlot(int index) const;
return FeedbackVectorSlot(index - ic_metadata_length() - inline Object* Get(FeedbackVectorSlot slot) const;
kReservedIndexCount); inline void Set(FeedbackVectorSlot slot, Object* value,
} WriteBarrierMode mode = UPDATE_WRITE_BARRIER);
inline Object* Get(FeedbackVectorICSlot slot) const;
FeedbackVectorICSlot ToICSlot(int index) const { inline void Set(FeedbackVectorICSlot slot, Object* value,
DCHECK(index >= first_ic_slot_index() && index < length()); WriteBarrierMode mode = UPDATE_WRITE_BARRIER);
int ic_slot = (index - first_ic_slot_index()) / elements_per_ic_slot();
return FeedbackVectorICSlot(ic_slot);
}
Object* Get(FeedbackVectorSlot slot) const { return get(GetIndex(slot)); }
void Set(FeedbackVectorSlot slot, Object* value,
WriteBarrierMode mode = UPDATE_WRITE_BARRIER) {
set(GetIndex(slot), value, mode);
}
Object* Get(FeedbackVectorICSlot slot) const { return get(GetIndex(slot)); }
void Set(FeedbackVectorICSlot slot, Object* value,
WriteBarrierMode mode = UPDATE_WRITE_BARRIER) {
set(GetIndex(slot), value, mode);
}
// IC slots need metadata to recognize the type of IC. // IC slots need metadata to recognize the type of IC.
Code::Kind GetKind(FeedbackVectorICSlot slot) const; Code::Kind GetKind(FeedbackVectorICSlot slot) const;
...@@ -320,27 +261,16 @@ class FeedbackNexus { ...@@ -320,27 +261,16 @@ class FeedbackNexus {
virtual void ConfigurePremonomorphic(); virtual void ConfigurePremonomorphic();
virtual void ConfigureMegamorphic(); virtual void ConfigureMegamorphic();
Object* GetFeedback() const { return vector()->Get(slot()); } inline Object* GetFeedback() const;
Object* GetFeedbackExtra() const { inline Object* GetFeedbackExtra() const;
DCHECK(TypeFeedbackVector::elements_per_ic_slot() > 1);
int extra_index = vector()->GetIndex(slot()) + 1;
return vector()->get(extra_index);
}
protected: protected:
Isolate* GetIsolate() const { return vector()->GetIsolate(); } inline Isolate* GetIsolate() const;
void SetFeedback(Object* feedback, inline void SetFeedback(Object* feedback,
WriteBarrierMode mode = UPDATE_WRITE_BARRIER) { WriteBarrierMode mode = UPDATE_WRITE_BARRIER);
vector()->Set(slot(), feedback, mode); inline void SetFeedbackExtra(Object* feedback_extra,
} WriteBarrierMode mode = UPDATE_WRITE_BARRIER);
void SetFeedbackExtra(Object* feedback_extra,
WriteBarrierMode mode = UPDATE_WRITE_BARRIER) {
DCHECK(TypeFeedbackVector::elements_per_ic_slot() > 1);
int index = vector()->GetIndex(slot()) + 1;
vector()->set(index, feedback_extra, mode);
}
Handle<FixedArray> EnsureArrayOfSize(int length); Handle<FixedArray> EnsureArrayOfSize(int length);
Handle<FixedArray> EnsureExtraArrayOfSize(int length); Handle<FixedArray> EnsureExtraArrayOfSize(int length);
......
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