Reviewers: ulan,
Message:
PTAL.
Description:
Prevent overflow in FreeArrayBuffer from triggering needless GC at isolate
teardown
Please review this at https://codereview.chromium.org/70233010/
SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge
Affected files (+25, -22 lines):
M include/v8.h
M src/api.cc
M src/heap-inl.h
M src/heap.h
M src/heap.cc
M src/runtime.cc
Index: include/v8.h
diff --git a/include/v8.h b/include/v8.h
index
f0b627e7b79c16c05f5c64beedb572587889291e..fb72d6503e7545e557a1b02b0b52f49449f32cfb
100644
--- a/include/v8.h
+++ b/include/v8.h
@@ -4077,7 +4077,7 @@ class V8_EXPORT Isolate {
* kept alive by JavaScript objects.
* \returns the adjusted value.
*/
- intptr_t AdjustAmountOfExternalAllocatedMemory(intptr_t change_in_bytes);
+ int64_t AdjustAmountOfExternalAllocatedMemory(int64_t change_in_bytes);
/**
* Returns heap profiler for this isolate. Will return NULL until the
isolate
@@ -4660,8 +4660,8 @@ class V8_EXPORT V8 {
V8_DEPRECATED(
"Use Isolate::AdjustAmountOfExternalAllocatedMemory instead",
- static intptr_t AdjustAmountOfExternalAllocatedMemory(
- intptr_t change_in_bytes));
+ static int64_t AdjustAmountOfExternalAllocatedMemory(
+ int64_t change_in_bytes));
/**
* Forcefully terminate the current thread of JavaScript execution
Index: src/api.cc
diff --git a/src/api.cc b/src/api.cc
index
736f0b00d7ac833ca3409ebd703a90f8ef49a5bc..ef9eec38e20bfe1d75c9f96e885ea665be3a760c
100644
--- a/src/api.cc
+++ b/src/api.cc
@@ -6386,14 +6386,14 @@ void V8::SetFailedAccessCheckCallbackFunction(
}
-intptr_t Isolate::AdjustAmountOfExternalAllocatedMemory(
- intptr_t change_in_bytes) {
+int64_t Isolate::AdjustAmountOfExternalAllocatedMemory(
+ int64_t change_in_bytes) {
i::Heap* heap = reinterpret_cast<i::Isolate*>(this)->heap();
return heap->AdjustAmountOfExternalAllocatedMemory(change_in_bytes);
}
-intptr_t V8::AdjustAmountOfExternalAllocatedMemory(intptr_t
change_in_bytes) {
+int64_t V8::AdjustAmountOfExternalAllocatedMemory(int64_t change_in_bytes)
{
i::Isolate* isolate = i::Isolate::UncheckedCurrent();
if (isolate == NULL || !isolate->IsInitialized()) {
return 0;
Index: src/heap-inl.h
diff --git a/src/heap-inl.h b/src/heap-inl.h
index
168aa50b36e540b2467c9a2d63da90f0c3c7cbb2..9d57c995ca0a566f40de9848491743655b3dd9b7
100644
--- a/src/heap-inl.h
+++ b/src/heap-inl.h
@@ -541,10 +541,10 @@ MaybeObject* Heap::PrepareForCompare(String* str) {
}
-intptr_t Heap::AdjustAmountOfExternalAllocatedMemory(
- intptr_t change_in_bytes) {
+int64_t Heap::AdjustAmountOfExternalAllocatedMemory(
+ int64_t change_in_bytes) {
ASSERT(HasBeenSetUp());
- intptr_t amount = amount_of_external_allocated_memory_ + change_in_bytes;
+ int64_t amount = amount_of_external_allocated_memory_ + change_in_bytes;
if (change_in_bytes > 0) {
// Avoid overflow.
if (amount > amount_of_external_allocated_memory_) {
@@ -554,7 +554,7 @@ intptr_t Heap::AdjustAmountOfExternalAllocatedMemory(
amount_of_external_allocated_memory_ = 0;
amount_of_external_allocated_memory_at_last_global_gc_ = 0;
}
- intptr_t amount_since_last_global_gc = PromotedExternalMemorySize();
+ int64_t amount_since_last_global_gc = PromotedExternalMemorySize();
if (amount_since_last_global_gc > external_allocation_limit_) {
CollectAllGarbage(kNoGCFlags, "external memory allocation limit
reached");
}
@@ -573,9 +573,9 @@ intptr_t Heap::AdjustAmountOfExternalAllocatedMemory(
PrintF("Adjust amount of external memory: delta=%6" V8_PTR_PREFIX "d
KB, "
"amount=%6" V8_PTR_PREFIX "d KB, since_gc=%6" V8_PTR_PREFIX "d
KB, "
"isolate=0x%08" V8PRIxPTR ".\n",
- change_in_bytes / KB,
- amount_of_external_allocated_memory_ / KB,
- PromotedExternalMemorySize() / KB,
+ static_cast<intptr_t>(change_in_bytes / KB),
+ static_cast<intptr_t>(amount_of_external_allocated_memory_ /
KB),
+ static_cast<intptr_t>(PromotedExternalMemorySize() / KB),
reinterpret_cast<intptr_t>(isolate()));
}
ASSERT(amount_of_external_allocated_memory_ >= 0);
Index: src/heap.cc
diff --git a/src/heap.cc b/src/heap.cc
index
3283c95648ee8ee87ca07cff5ff936ec0284fbdc..3b3dc44c6b8fd5721de390da0273c8dd01b6df77
100644
--- a/src/heap.cc
+++ b/src/heap.cc
@@ -411,7 +411,7 @@ void Heap::PrintShortHeapStatistics() {
this->Available() / KB,
this->CommittedMemory() / KB);
PrintPID("External memory reported: %6" V8_PTR_PREFIX "d KB\n",
- amount_of_external_allocated_memory_ / KB);
+ static_cast<intptr_t>(amount_of_external_allocated_memory_ /
KB));
PrintPID("Total time spent in GC : %.1f ms\n", total_gc_time_ms_);
}
@@ -6578,7 +6578,7 @@ intptr_t Heap::PromotedSpaceSizeOfObjects() {
}
-intptr_t Heap::PromotedExternalMemorySize() {
+int64_t Heap::PromotedExternalMemorySize() {
if (amount_of_external_allocated_memory_
<= amount_of_external_allocated_memory_at_last_global_gc_) return 0;
return amount_of_external_allocated_memory_
Index: src/heap.h
diff --git a/src/heap.h b/src/heap.h
index
7e2eda2529cdd42e2eed94127c5421f46f0c019b..cbe9805929b51c7096f8e408e6f64b2674f79326
100644
--- a/src/heap.h
+++ b/src/heap.h
@@ -1497,8 +1497,8 @@ class Heap {
// Adjusts the amount of registered external memory.
// Returns the adjusted value.
- inline intptr_t AdjustAmountOfExternalAllocatedMemory(
- intptr_t change_in_bytes);
+ inline int64_t AdjustAmountOfExternalAllocatedMemory(
+ int64_t change_in_bytes);
// This is only needed for testing high promotion mode.
void SetNewSpaceHighPromotionModeActive(bool mode) {
@@ -1517,7 +1517,10 @@ class Heap {
}
inline intptr_t PromotedTotalSize() {
- return PromotedSpaceSizeOfObjects() + PromotedExternalMemorySize();
+ int64_t total = PromotedSpaceSizeOfObjects() +
PromotedExternalMemorySize();
+ if (total > kMaxInt) return static_cast<intptr_t>(kMaxInt);
+ if (total < 0) return 0;
+ return static_cast<intptr_t>(total);
}
inline intptr_t OldGenerationSpaceAvailable() {
@@ -1930,7 +1933,7 @@ class Heap {
int gc_post_processing_depth_;
// Returns the amount of external memory registered since last global gc.
- intptr_t PromotedExternalMemorySize();
+ int64_t PromotedExternalMemorySize();
unsigned int ms_count_; // how many mark-sweep collections happened
unsigned int gc_count_; // how many gc happened
@@ -1984,10 +1987,10 @@ class Heap {
// The amount of external memory registered through the API kept alive
// by global handles
- intptr_t amount_of_external_allocated_memory_;
+ int64_t amount_of_external_allocated_memory_;
// Caches the amount of external memory registered at the last global gc.
- intptr_t amount_of_external_allocated_memory_at_last_global_gc_;
+ int64_t amount_of_external_allocated_memory_at_last_global_gc_;
// Indicates that an allocation has failed in the old generation since
the
// last GC.
Index: src/runtime.cc
diff --git a/src/runtime.cc b/src/runtime.cc
index
9df3ff882e61479fe3953a122d74a3705a103de6..58d4326cc86b6a46641f2f13cf205e20afb97596
100644
--- a/src/runtime.cc
+++ b/src/runtime.cc
@@ -700,7 +700,7 @@ void Runtime::FreeArrayBuffer(Isolate* isolate,
isolate, phantom_array_buffer->byte_length());
isolate->heap()->AdjustAmountOfExternalAllocatedMemory(
- -static_cast<intptr_t>(allocated_length));
+ -static_cast<int64_t>(allocated_length));
CHECK(V8::ArrayBufferAllocator() != NULL);
V8::ArrayBufferAllocator()->Free(
phantom_array_buffer->backing_store(),
--
--
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.