Index: src/type-feedback-vector.cc |
diff --git a/src/type-feedback-vector.cc b/src/type-feedback-vector.cc |
index a3fe0707c7d578fbbbcf204dc51a68694308b271..dcae7c72e657bacba67c4ee206fb28c57365098f 100644 |
--- a/src/type-feedback-vector.cc |
+++ b/src/type-feedback-vector.cc |
@@ -4,6 +4,7 @@ |
#include "src/v8.h" |
+#include "src/ic/ic-state.h" |
#include "src/objects.h" |
#include "src/type-feedback-vector-inl.h" |
@@ -11,6 +12,36 @@ namespace v8 { |
namespace internal { |
// static |
+Handle<TypeFeedbackVector> TypeFeedbackVector::Allocate(Isolate* isolate, |
+ int slot_count, |
+ int ic_slot_count) { |
+ int length = slot_count + ic_slot_count + kReservedIndexCount; |
+ if (length == kReservedIndexCount) { |
+ return Handle<TypeFeedbackVector>::cast( |
+ isolate->factory()->empty_fixed_array()); |
+ } |
+ |
+ Handle<FixedArray> array = isolate->factory()->NewFixedArray(length, TENURED); |
+ if (ic_slot_count > 0) { |
+ array->set(kFirstICSlotIndex, |
+ Smi::FromInt(slot_count + kReservedIndexCount)); |
+ } else { |
+ array->set(kFirstICSlotIndex, Smi::FromInt(length)); |
+ } |
+ array->set(kWithTypesIndex, Smi::FromInt(0)); |
+ array->set(kGenericCountIndex, Smi::FromInt(0)); |
+ |
+ // Ensure we can skip the write barrier |
+ Handle<Object> uninitialized_sentinel = UninitializedSentinel(isolate); |
+ DCHECK_EQ(isolate->heap()->uninitialized_symbol(), *uninitialized_sentinel); |
+ for (int i = kReservedIndexCount; i < length; i++) { |
+ array->set(i, *uninitialized_sentinel, SKIP_WRITE_BARRIER); |
+ } |
+ return Handle<TypeFeedbackVector>::cast(array); |
+} |
+ |
+ |
+// static |
Handle<TypeFeedbackVector> TypeFeedbackVector::Copy( |
Isolate* isolate, Handle<TypeFeedbackVector> vector) { |
Handle<TypeFeedbackVector> result; |
@@ -18,5 +49,42 @@ Handle<TypeFeedbackVector> TypeFeedbackVector::Copy( |
isolate->factory()->CopyFixedArray(Handle<FixedArray>::cast(vector))); |
return result; |
} |
+ |
+ |
+void TypeFeedbackVector::ClearSlots(SharedFunctionInfo* shared) { |
+ int slots = Slots(); |
+ Isolate* isolate = GetIsolate(); |
+ Object* uninitialized_sentinel = |
+ TypeFeedbackVector::RawUninitializedSentinel(isolate->heap()); |
+ |
+ for (int i = 0; i < slots; i++) { |
+ FeedbackVectorSlot slot(i); |
+ Object* obj = Get(slot); |
+ if (obj->IsHeapObject()) { |
+ InstanceType instance_type = |
+ HeapObject::cast(obj)->map()->instance_type(); |
+ // AllocationSites are exempt from clearing. They don't store Maps |
+ // or Code pointers which can cause memory leaks if not cleared |
+ // regularly. |
+ if (instance_type != ALLOCATION_SITE_TYPE) { |
+ Set(slot, uninitialized_sentinel, SKIP_WRITE_BARRIER); |
+ } |
+ } |
+ } |
+ |
+ slots = ICSlots(); |
+ if (slots == 0) return; |
+ |
+ // Now clear vector-based ICs. They are all CallICs. |
+ // Try and pass the containing code (the "host"). |
+ Code* host = shared->code(); |
+ for (int i = 0; i < slots; i++) { |
+ FeedbackVectorICSlot slot(i); |
+ Object* obj = Get(slot); |
+ if (obj != uninitialized_sentinel) { |
+ ICUtility::Clear(isolate, Code::CALL_IC, host, this, slot); |
+ } |
+ } |
+} |
} |
} // namespace v8::internal |