Revision: 12262
Author:   [email protected]
Date:     Mon Aug  6 06:49:13 2012
Log:      Make AdjustAmountOfExternalAllocatedMemory() more robust.

Do not crash if called from a thread without V8 isolate, reset the external
memory counters in case of overflow, bump the external allocation limit.

This will allow us to track typed array allocation and deallocation in WebKit.

BUG=v8:2022,122097,42342
[email protected]

Review URL: https://chromiumcodereview.appspot.com/10837122
http://code.google.com/p/v8/source/detail?r=12262

Modified:
 /branches/bleeding_edge/src/api.cc
 /branches/bleeding_edge/src/heap-inl.h
 /branches/bleeding_edge/src/heap.cc

=======================================
--- /branches/bleeding_edge/src/api.cc  Mon Aug  6 00:55:05 2012
+++ /branches/bleeding_edge/src/api.cc  Mon Aug  6 06:49:13 2012
@@ -5275,8 +5275,9 @@


intptr_t V8::AdjustAmountOfExternalAllocatedMemory(intptr_t change_in_bytes) {
-  i::Isolate* isolate = i::Isolate::Current();
- if (IsDeadCheck(isolate, "v8::V8::AdjustAmountOfExternalAllocatedMemory()")) {
+  i::Isolate* isolate = i::Isolate::UncheckedCurrent();
+  if (isolate == NULL || !isolate->IsInitialized() ||
+ IsDeadCheck(isolate, "v8::V8::AdjustAmountOfExternalAllocatedMemory()")) {
     return 0;
   }
   return isolate->heap()->AdjustAmountOfExternalAllocatedMemory(
=======================================
--- /branches/bleeding_edge/src/heap-inl.h      Wed Aug  1 02:43:05 2012
+++ /branches/bleeding_edge/src/heap-inl.h      Mon Aug  6 06:49:13 2012
@@ -468,10 +468,12 @@
     // Avoid overflow.
     if (amount > amount_of_external_allocated_memory_) {
       amount_of_external_allocated_memory_ = amount;
-    }
-    intptr_t amount_since_last_global_gc =
-        amount_of_external_allocated_memory_ -
-        amount_of_external_allocated_memory_at_last_global_gc_;
+    } else {
+      // Give up and reset the counters in case of an overflow.
+      amount_of_external_allocated_memory_ = 0;
+      amount_of_external_allocated_memory_at_last_global_gc_ = 0;
+    }
+    intptr_t amount_since_last_global_gc = PromotedExternalMemorySize();
     if (amount_since_last_global_gc > external_allocation_limit_) {
CollectAllGarbage(kNoGCFlags, "external memory allocation limit reached");
     }
@@ -479,6 +481,10 @@
     // Avoid underflow.
     if (amount >= 0) {
       amount_of_external_allocated_memory_ = amount;
+    } else {
+      // Give up and reset the counters in case of an overflow.
+      amount_of_external_allocated_memory_ = 0;
+      amount_of_external_allocated_memory_at_last_global_gc_ = 0;
     }
   }
   ASSERT(amount_of_external_allocated_memory_ >= 0);
=======================================
--- /branches/bleeding_edge/src/heap.cc Tue Jul 31 02:25:23 2012
+++ /branches/bleeding_edge/src/heap.cc Mon Aug  6 06:49:13 2012
@@ -5793,7 +5793,7 @@
   max_semispace_size_ = RoundUpToPowerOf2(max_semispace_size_);
   reserved_semispace_size_ = RoundUpToPowerOf2(reserved_semispace_size_);
initial_semispace_size_ = Min(initial_semispace_size_, max_semispace_size_);
-  external_allocation_limit_ = 10 * max_semispace_size_;
+  external_allocation_limit_ = 16 * max_semispace_size_;

// The old generation is paged and needs at least one page for each space.
   int paged_space_count = LAST_PAGED_SPACE - FIRST_PAGED_SPACE + 1;

--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev

Reply via email to