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}
This commit is contained in:
parent
af1b95217b
commit
fa530822fd
@ -10,11 +10,118 @@
|
||||
namespace v8 {
|
||||
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 {
|
||||
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) {
|
||||
return isolate->factory()->uninitialized_symbol();
|
||||
}
|
||||
@ -33,6 +140,32 @@ Handle<Object> TypeFeedbackVector::PremonomorphicSentinel(Isolate* isolate) {
|
||||
Object* TypeFeedbackVector::RawUninitializedSentinel(Heap* heap) {
|
||||
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
|
||||
|
||||
|
@ -87,10 +87,7 @@ class ZoneFeedbackVectorSpec {
|
||||
class TypeFeedbackVector : public FixedArray {
|
||||
public:
|
||||
// Casting.
|
||||
static TypeFeedbackVector* cast(Object* obj) {
|
||||
DCHECK(obj->IsTypeFeedbackVector());
|
||||
return reinterpret_cast<TypeFeedbackVector*>(obj);
|
||||
}
|
||||
static inline TypeFeedbackVector* cast(Object* obj);
|
||||
|
||||
static const int kReservedIndexCount = 3;
|
||||
static const int kFirstICSlotIndex = 0;
|
||||
@ -99,89 +96,33 @@ class TypeFeedbackVector : public FixedArray {
|
||||
|
||||
static int elements_per_ic_slot() { return 2; }
|
||||
|
||||
int first_ic_slot_index() const {
|
||||
DCHECK(length() >= kReservedIndexCount);
|
||||
return Smi::cast(get(kFirstICSlotIndex))->value();
|
||||
}
|
||||
|
||||
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 first_ic_slot_index() const;
|
||||
inline int ic_with_type_info_count();
|
||||
inline void change_ic_with_type_info_count(int delta);
|
||||
inline int ic_generic_count();
|
||||
inline void change_ic_generic_count(int delta);
|
||||
inline int ic_metadata_length() const;
|
||||
|
||||
bool SpecDiffersFrom(const ZoneFeedbackVectorSpec* other_spec) const;
|
||||
|
||||
int Slots() const {
|
||||
if (length() == 0) return 0;
|
||||
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();
|
||||
}
|
||||
inline int Slots() const;
|
||||
inline int ICSlots() const;
|
||||
|
||||
// Conversion from a slot or ic slot to an integer index to the underlying
|
||||
// array.
|
||||
int GetIndex(FeedbackVectorSlot slot) const {
|
||||
DCHECK(slot.ToInt() < first_ic_slot_index());
|
||||
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();
|
||||
}
|
||||
inline int GetIndex(FeedbackVectorSlot slot) const;
|
||||
inline int GetIndex(FeedbackVectorICSlot slot) const;
|
||||
|
||||
// Conversion from an integer index to either a slot or an ic slot. The caller
|
||||
// should know what kind she expects.
|
||||
FeedbackVectorSlot ToSlot(int index) const {
|
||||
DCHECK(index >= kReservedIndexCount && index < first_ic_slot_index());
|
||||
return FeedbackVectorSlot(index - ic_metadata_length() -
|
||||
kReservedIndexCount);
|
||||
}
|
||||
|
||||
FeedbackVectorICSlot 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* 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);
|
||||
}
|
||||
inline FeedbackVectorSlot ToSlot(int index) const;
|
||||
inline FeedbackVectorICSlot ToICSlot(int index) const;
|
||||
inline Object* Get(FeedbackVectorSlot slot) const;
|
||||
inline void Set(FeedbackVectorSlot slot, Object* value,
|
||||
WriteBarrierMode mode = UPDATE_WRITE_BARRIER);
|
||||
inline Object* Get(FeedbackVectorICSlot slot) const;
|
||||
inline void Set(FeedbackVectorICSlot slot, Object* value,
|
||||
WriteBarrierMode mode = UPDATE_WRITE_BARRIER);
|
||||
|
||||
// IC slots need metadata to recognize the type of IC.
|
||||
Code::Kind GetKind(FeedbackVectorICSlot slot) const;
|
||||
@ -320,27 +261,16 @@ class FeedbackNexus {
|
||||
virtual void ConfigurePremonomorphic();
|
||||
virtual void ConfigureMegamorphic();
|
||||
|
||||
Object* GetFeedback() const { return vector()->Get(slot()); }
|
||||
Object* GetFeedbackExtra() const {
|
||||
DCHECK(TypeFeedbackVector::elements_per_ic_slot() > 1);
|
||||
int extra_index = vector()->GetIndex(slot()) + 1;
|
||||
return vector()->get(extra_index);
|
||||
}
|
||||
inline Object* GetFeedback() const;
|
||||
inline Object* GetFeedbackExtra() const;
|
||||
|
||||
protected:
|
||||
Isolate* GetIsolate() const { return vector()->GetIsolate(); }
|
||||
inline Isolate* GetIsolate() const;
|
||||
|
||||
void SetFeedback(Object* feedback,
|
||||
WriteBarrierMode mode = UPDATE_WRITE_BARRIER) {
|
||||
vector()->Set(slot(), feedback, mode);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
inline void SetFeedback(Object* feedback,
|
||||
WriteBarrierMode mode = UPDATE_WRITE_BARRIER);
|
||||
inline void SetFeedbackExtra(Object* feedback_extra,
|
||||
WriteBarrierMode mode = UPDATE_WRITE_BARRIER);
|
||||
|
||||
Handle<FixedArray> EnsureArrayOfSize(int length);
|
||||
Handle<FixedArray> EnsureExtraArrayOfSize(int length);
|
||||
|
Loading…
Reference in New Issue
Block a user