Reviewers: mvstanton, Michael Starzinger,

https://codereview.chromium.org/143153008/diff/30001/src/heap.cc
File src/heap.cc (right):

https://codereview.chromium.org/143153008/diff/30001/src/heap.cc#newcode3626
src/heap.cc:3626: allocation_sites_scratchpad_length_, site);
On 2014/02/06 13:46:37, mvstanton wrote:
So both the scratchpad and the AllocationSite are in old space, what
should the
write barrier behavior be?

The allocation site may be on an evacuation candidate, i.e., the
allocation site may move after the scratchpad bookkeeping.

Description:
The allocation sites scratchpad becomes a heap data structure.

BUG=

Please review this at https://codereview.chromium.org/143153008/

SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge

Affected files (+63, -16 lines):
  M include/v8.h
  M src/heap-inl.h
  M src/heap.h
  M src/heap.cc


Index: include/v8.h
diff --git a/include/v8.h b/include/v8.h
index a019c9d561f92a00ece1efd263e5d0a0c1deb987..fe3b020417fadb42eeab6eefa03a4c79c06abe04 100644
--- a/include/v8.h
+++ b/include/v8.h
@@ -5398,7 +5398,7 @@ class Internals {
   static const int kNullValueRootIndex = 7;
   static const int kTrueValueRootIndex = 8;
   static const int kFalseValueRootIndex = 9;
-  static const int kEmptyStringRootIndex = 146;
+  static const int kEmptyStringRootIndex = 147;

   static const int kNodeClassIdOffset = 1 * kApiPointerSize;
   static const int kNodeFlagsOffset = 1 * kApiPointerSize + 3;
Index: src/heap-inl.h
diff --git a/src/heap-inl.h b/src/heap-inl.h
index 09d754ff82164aa961f6dceba941a0db3460a996..35bad4af39ec94937720004f4e760332c2a0e36b 100644
--- a/src/heap-inl.h
+++ b/src/heap-inl.h
@@ -517,12 +517,8 @@ void Heap::UpdateAllocationSiteFeedback(HeapObject* object) {
   AllocationMemento* memento = AllocationMemento::cast(candidate);
   if (!memento->IsValid()) return;

-  if (memento->GetAllocationSite()->IncrementMementoFoundCount() &&
-      heap->allocation_sites_scratchpad_length <
-      kAllocationSiteScratchpadSize) {
-    heap->allocation_sites_scratchpad[
-        heap->allocation_sites_scratchpad_length++] =
-        memento->GetAllocationSite();
+  if (memento->GetAllocationSite()->IncrementMementoFoundCount()) {
+    heap->AddAllocationSiteToScratchpad(memento->GetAllocationSite());
   }
 }

Index: src/heap.cc
diff --git a/src/heap.cc b/src/heap.cc
index e0b312067fc5c38013c36d76da9f69beae64c4a4..dfe98ec080c38009871c4f2357d532e5ec8d40d1 100644
--- a/src/heap.cc
+++ b/src/heap.cc
@@ -150,7 +150,7 @@ Heap::Heap()
 #ifdef VERIFY_HEAP
       no_weak_object_verification_scope_depth_(0),
 #endif
-      allocation_sites_scratchpad_length(0),
+      allocation_sites_scratchpad_length_(0),
       promotion_queue_(this),
       configured_(false),
       external_string_table_(this),
@@ -516,16 +516,17 @@ void Heap::ProcessPretenuringFeedback() {
     // If the scratchpad overflowed, we have to iterate over the allocation
     // sites list.
     bool use_scratchpad =
-        allocation_sites_scratchpad_length < kAllocationSiteScratchpadSize;
+ allocation_sites_scratchpad_length_ < kAllocationSiteScratchpadSize;

     int i = 0;
     Object* list_element = allocation_sites_list();
     bool trigger_deoptimization = false;
     while (use_scratchpad ?
-              i < allocation_sites_scratchpad_length :
+              i < allocation_sites_scratchpad_length_ :
               list_element->IsAllocationSite()) {
       AllocationSite* site = use_scratchpad ?
- allocation_sites_scratchpad[i] : AllocationSite::cast(list_element);
+          AllocationSite::cast(allocation_sites_scratchpad()->get(i)) :
+          AllocationSite::cast(list_element);
       allocation_mementos_found += site->memento_found_count();
       if (site->memento_found_count() > 0) {
         active_allocation_sites++;
@@ -546,7 +547,7 @@ void Heap::ProcessPretenuringFeedback() {

     if (trigger_deoptimization) isolate_->stack_guard()->DeoptMarkedCode();

-    allocation_sites_scratchpad_length = 0;
+    FlushAllocationSitesScratchpad();

     if (FLAG_trace_pretenuring_statistics &&
         (allocation_mementos_found > 0 ||
@@ -3300,6 +3301,12 @@ bool Heap::CreateInitialObjects() {
   // Handling of script id generation is in Factory::NewScript.
   set_last_script_id(Smi::FromInt(v8::Script::kNoScriptId));

+  { MaybeObject* maybe_obj = AllocateAllocationSitesScratchpad();
+    if (!maybe_obj->ToObject(&obj)) return false;
+  }
+  set_allocation_sites_scratchpad(FixedArray::cast(obj));
+  InitializeAllocationSitesScratchpad();
+
   // Initialize keyed lookup cache.
   isolate_->keyed_lookup_cache()->Clear();

@@ -3589,6 +3596,39 @@ MaybeObject* Heap::Uint32ToString(uint32_t value,
 }


+MaybeObject* Heap::AllocateAllocationSitesScratchpad() {
+  MaybeObject* maybe_obj =
+      AllocateFixedArray(kAllocationSiteScratchpadSize, TENURED);
+  return maybe_obj;
+}
+
+
+void Heap::FlushAllocationSitesScratchpad() {
+  for (int i = 0; i < allocation_sites_scratchpad_length_; i++) {
+    allocation_sites_scratchpad()->set_undefined(i);
+  }
+  allocation_sites_scratchpad_length_ = 0;
+}
+
+
+void Heap::InitializeAllocationSitesScratchpad() {
+  ASSERT(allocation_sites_scratchpad()->length() ==
+         kAllocationSiteScratchpadSize);
+  for (int i = 0; i < kAllocationSiteScratchpadSize; i++) {
+    allocation_sites_scratchpad()->set_undefined(i);
+  }
+}
+
+
+void Heap::AddAllocationSiteToScratchpad(AllocationSite* site) {
+ if (allocation_sites_scratchpad_length_ < kAllocationSiteScratchpadSize) {
+    allocation_sites_scratchpad()->set(
+        allocation_sites_scratchpad_length_, site);
+    allocation_sites_scratchpad_length_++;
+  }
+}
+
+
 Map* Heap::MapForExternalArrayType(ExternalArrayType array_type) {
   return Map::cast(roots_[RootIndexForExternalArrayType(array_type)]);
 }
Index: src/heap.h
diff --git a/src/heap.h b/src/heap.h
index 011ffd5e68b0179f4b524e8db227dbc952fe06b9..266cdb9684babcb887958522b7a5596aa181ff82 100644
--- a/src/heap.h
+++ b/src/heap.h
@@ -202,7 +202,8 @@ namespace internal {
V(SeededNumberDictionary, empty_slow_element_dictionary, \ EmptySlowElementDictionary) \ V(Symbol, observed_symbol, ObservedSymbol) \
-  V(FixedArray, materialized_objects, MaterializedObjects)
+ V(FixedArray, materialized_objects, MaterializedObjects) \
+  V(FixedArray, allocation_sites_scratchpad, AllocationSitesScratchpad)

 #define ROOT_LIST(V)                                  \
   STRONG_ROOT_LIST(V)                                 \
@@ -2285,6 +2286,18 @@ class Heap {
   // Flush the number to string cache.
   void FlushNumberStringCache();

+  // Allocates a fixed-size allocation sites scratchpad.
+  MUST_USE_RESULT MaybeObject* AllocateAllocationSitesScratchpad();
+
+  // Sets used allocation sites entries to undefined.
+  void FlushAllocationSitesScratchpad();
+
+  // Initializes the allocation sites scratchpad with undefined values.
+  void InitializeAllocationSitesScratchpad();
+
+  // Adds an allocation site to the scratchpad if there is space left.
+  void AddAllocationSiteToScratchpad(AllocationSite* site);
+
   void UpdateSurvivalRateTrend(int start_new_space_size);

   enum SurvivalRateTrend { INCREASING, STABLE, DECREASING, FLUCTUATING };
@@ -2457,10 +2470,8 @@ class Heap {
   int no_weak_object_verification_scope_depth_;
 #endif

-
   static const int kAllocationSiteScratchpadSize = 256;
-  int allocation_sites_scratchpad_length;
- AllocationSite* allocation_sites_scratchpad[kAllocationSiteScratchpadSize];
+  int allocation_sites_scratchpad_length_;

   static const int kMaxMarkSweepsInIdleRound = 7;
   static const int kIdleScavengeThreshold = 5;


--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to