Index: src/heap/spaces.h |
diff --git a/src/heap/spaces.h b/src/heap/spaces.h |
index 69a8d89fccba5c5aa06f91d2a1995870b70ef033..01676397b96d65272ea741c18dd5f77e1a798b79 100644 |
--- a/src/heap/spaces.h |
+++ b/src/heap/spaces.h |
@@ -2461,6 +2461,42 @@ class NewSpacePageIterator BASE_EMBEDDED { |
}; |
+class InlineAllocationObserver { |
Hannes Payer (out of office)
2015/10/16 15:31:17
This class needs a description and a few comments.
ofrobots
2015/10/16 21:26:35
Done.
|
+ public: |
+ typedef void (*callback_t)(int bytes_allocated, void* arg); |
+ |
+ InlineAllocationObserver(intptr_t step_size, callback_t callback, |
+ void* callback_arg) |
+ : step_size_(step_size), |
+ callback_(callback), |
+ callback_arg_(callback_arg), |
+ bytes_to_next_step_(step_size) { |
+ DCHECK(step_size > 0); |
+ } |
+ |
+ InlineAllocationObserver(const InlineAllocationObserver&) = default; |
+ InlineAllocationObserver& operator=(const InlineAllocationObserver&) = |
+ default; |
+ |
+ void step(int bytes_allocated) { |
+ bytes_to_next_step_ -= bytes_allocated; |
+ if (bytes_to_next_step_ <= 0) { |
+ callback_(static_cast<int>(step_size_ - bytes_to_next_step_), |
+ callback_arg_); |
+ bytes_to_next_step_ = step_size_; |
+ } |
+ } |
+ |
+ intptr_t step_size() const { return step_size_; } |
+ callback_t callback() const { return callback_; } |
+ |
+ private: |
+ intptr_t step_size_; |
+ callback_t callback_; |
+ void* callback_arg_; |
+ intptr_t bytes_to_next_step_; |
+}; |
+ |
// ----------------------------------------------------------------------------- |
// The young generation space. |
// |
@@ -2649,10 +2685,16 @@ class NewSpace : public Space { |
void ResetAllocationInfo(); |
void UpdateInlineAllocationLimit(int size_in_bytes); |
- void LowerInlineAllocationLimit(intptr_t step) { |
- inline_allocation_limit_step_ = step; |
+ |
+ void AddInlineAllocationObserver( |
+ intptr_t step_size, InlineAllocationObserver::callback_t callback, |
+ void* callback_arg); |
+ void RemoveInlineAllocationObserver( |
+ InlineAllocationObserver::callback_t callback); |
+ void DisableInlineAllocationSteps() { |
+ inline_allocation_limit_step_ = 0; |
+ top_on_previous_step_ = 0; |
UpdateInlineAllocationLimit(0); |
- top_on_previous_step_ = step ? allocation_info_.top() : 0; |
} |
// Get the extent of the inactive semispace (for use as a marking stack, |
@@ -2728,6 +2770,8 @@ class NewSpace : public Space { |
// Update allocation info to match the current to-space page. |
void UpdateAllocationInfo(); |
+ void UpdateInlineAllocationLimitStep(); |
+ |
Address chunk_base_; |
uintptr_t chunk_size_; |
@@ -2747,11 +2791,13 @@ class NewSpace : public Space { |
// mark-compact collection. |
AllocationInfo allocation_info_; |
- // When incremental marking is active we will set allocation_info_.limit |
- // to be lower than actual limit and then will gradually increase it |
- // in steps to guarantee that we do incremental marking steps even |
- // when all allocation is performed from inlined generated code. |
+ // When inline allocation stepping is active, either because of incremental |
+ // marking or because of idle scavenge, we 'interrupt' inline allocation every |
+ // once in a while. This is done by setting allocation_info_.limit to be lower |
+ // than the actual limit and and increasing it in steps to guarantee that the |
+ // observers are notified periodically. |
intptr_t inline_allocation_limit_step_; |
+ List<InlineAllocationObserver> inline_allocation_observers_; |
Address top_on_previous_step_; |
@@ -2761,8 +2807,7 @@ class NewSpace : public Space { |
bool EnsureAllocation(int size_in_bytes, AllocationAlignment alignment); |
// If we are doing inline allocation in steps, this method performs the 'step' |
- // operation. Right now incremental marking is the only consumer of inline |
- // allocation steps. top is the memory address of the bump pointer at the last |
+ // operation. top is the memory address of the bump pointer at the last |
// inline allocation (i.e. it determines the numbers of bytes actually |
// allocated since the last step.) new_top is the address of the bump pointer |
// where the next byte is going to be allocated from. top and new_top may be |