Revision: 15205
Author: [email protected]
Date: Wed Jun 19 04:53:30 2013
Log: Do not use weak handles for ArrayBuffers.
Instead of allocating weak handles to free ArrayBuffer backing store,
dispose of memory while walking the weak list of ArrayBuffers on GC.
Also, free all array buffers on isolate tear-down.
[email protected]
Review URL: https://codereview.chromium.org/16950013
http://code.google.com/p/v8/source/detail?r=15205
Modified:
/branches/bleeding_edge/src/heap.cc
/branches/bleeding_edge/src/heap.h
/branches/bleeding_edge/src/runtime.cc
/branches/bleeding_edge/src/runtime.h
/branches/bleeding_edge/test/cctest/test-weaktypedarrays.cc
=======================================
--- /branches/bleeding_edge/src/heap.cc Fri Jun 14 09:06:12 2013
+++ /branches/bleeding_edge/src/heap.cc Wed Jun 19 04:53:30 2013
@@ -1568,6 +1568,8 @@
// tail is a live object, visit it.
WeakListVisitor<T>::VisitLiveObject(
heap, tail, retainer, record_slots);
+ } else {
+ WeakListVisitor<T>::VisitPhantomObject(heap, candidate);
}
// Move to next element in the list.
@@ -1599,6 +1601,9 @@
static void VisitLiveObject(Heap*, JSFunction*,
WeakObjectRetainer*, bool) {
}
+
+ static void VisitPhantomObject(Heap*, JSFunction*) {
+ }
};
@@ -1636,6 +1641,9 @@
optimized_functions, optimized_functions, function_list_head);
}
}
+
+ static void VisitPhantomObject(Heap*, Context*) {
+ }
static int WeakNextOffset() {
return FixedArray::SizeFor(Context::NEXT_CONTEXT_LINK);
@@ -1679,6 +1687,8 @@
JSTypedArray* obj,
WeakObjectRetainer* retainer,
bool record_slots) {}
+
+ static void VisitPhantomObject(Heap*, JSTypedArray*) {}
static int WeakNextOffset() {
return JSTypedArray::kWeakNextOffset;
@@ -1712,6 +1722,10 @@
heap->mark_compact_collector()->RecordSlot(slot, slot,
typed_array_obj);
}
}
+
+ static void VisitPhantomObject(Heap* heap, JSArrayBuffer* phantom) {
+ Runtime::FreeArrayBuffer(heap->isolate(), phantom);
+ }
static int WeakNextOffset() {
return JSArrayBuffer::kWeakNextOffset;
@@ -1727,6 +1741,17 @@
retainer, record_slots);
set_array_buffers_list(array_buffer_obj);
}
+
+
+void Heap::TearDownArrayBuffers() {
+ Object* undefined = undefined_value();
+ for (Object* o = array_buffers_list(); o != undefined;) {
+ JSArrayBuffer* buffer = JSArrayBuffer::cast(o);
+ Runtime::FreeArrayBuffer(isolate(), buffer);
+ o = buffer->weak_next();
+ }
+ array_buffers_list_ = undefined;
+}
void Heap::VisitExternalResources(v8::ExternalResourceVisitor* visitor) {
@@ -6868,6 +6893,8 @@
PrintF("total_sweeping_time=%.1f ", sweeping_time());
PrintF("\n\n");
}
+
+ TearDownArrayBuffers();
isolate_->global_handles()->TearDown();
=======================================
--- /branches/bleeding_edge/src/heap.h Fri Jun 14 09:06:12 2013
+++ /branches/bleeding_edge/src/heap.h Wed Jun 19 04:53:30 2013
@@ -2192,6 +2192,9 @@
void ProcessNativeContexts(WeakObjectRetainer* retainer, bool
record_slots);
void ProcessArrayBuffers(WeakObjectRetainer* retainer, bool
record_slots);
+ // Called on heap tear-down.
+ void TearDownArrayBuffers();
+
// Record statistics before and after garbage collection.
void ReportStatisticsBeforeGC();
void ReportStatisticsAfterGC();
=======================================
--- /branches/bleeding_edge/src/runtime.cc Wed Jun 19 02:38:28 2013
+++ /branches/bleeding_edge/src/runtime.cc Wed Jun 19 04:53:30 2013
@@ -650,23 +650,17 @@
}
-static void ArrayBufferWeakCallback(v8::Isolate* external_isolate,
- Persistent<Value>* object,
- void* data) {
- Isolate* isolate = reinterpret_cast<Isolate*>(external_isolate);
- HandleScope scope(isolate);
- Handle<Object> internal_object = Utils::OpenPersistent(object);
- Handle<JSArrayBuffer>
array_buffer(JSArrayBuffer::cast(*internal_object));
+void Runtime::FreeArrayBuffer(Isolate* isolate,
+ JSArrayBuffer* phantom_array_buffer) {
+ if (phantom_array_buffer->is_external()) return;
- if (!array_buffer->is_external()) {
- size_t allocated_length = NumberToSize(
- isolate, array_buffer->byte_length());
- isolate->heap()->AdjustAmountOfExternalAllocatedMemory(
- -static_cast<intptr_t>(allocated_length));
- CHECK(V8::ArrayBufferAllocator() != NULL);
- V8::ArrayBufferAllocator()->Free(data);
- }
- object->Dispose(external_isolate);
+ size_t allocated_length = NumberToSize(
+ isolate, phantom_array_buffer->byte_length());
+
+ isolate->heap()->AdjustAmountOfExternalAllocatedMemory(
+ -static_cast<intptr_t>(allocated_length));
+ CHECK(V8::ArrayBufferAllocator() != NULL);
+ V8::ArrayBufferAllocator()->Free(phantom_array_buffer->backing_store());
}
@@ -711,10 +705,6 @@
SetupArrayBuffer(isolate, array_buffer, false, data, allocated_length);
- Handle<Object> persistent =
isolate->global_handles()->Create(*array_buffer);
- GlobalHandles::MakeWeak(persistent.location(), data,
ArrayBufferWeakCallback);
- GlobalHandles::MarkIndependent(persistent.location());
-
isolate->heap()->AdjustAmountOfExternalAllocatedMemory(allocated_length);
return true;
=======================================
--- /branches/bleeding_edge/src/runtime.h Mon Jun 17 09:27:18 2013
+++ /branches/bleeding_edge/src/runtime.h Wed Jun 19 04:53:30 2013
@@ -769,6 +769,10 @@
Handle<JSArrayBuffer> array_buffer,
size_t allocated_length);
+ static void FreeArrayBuffer(
+ Isolate* isolate,
+ JSArrayBuffer* phantom_array_buffer);
+
// Helper functions used stubs.
static void PerformGC(Object* result);
=======================================
--- /branches/bleeding_edge/test/cctest/test-weaktypedarrays.cc Wed Jun 19
01:58:09 2013
+++ /branches/bleeding_edge/test/cctest/test-weaktypedarrays.cc Wed Jun 19
04:53:30 2013
@@ -104,7 +104,6 @@
CHECK(HasArrayBufferInWeakList(isolate->heap(), *iab1));
CHECK(HasArrayBufferInWeakList(isolate->heap(), *iab2));
}
- isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags);
isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags);
CHECK_EQ(1, CountArrayBuffersInWeakList(isolate->heap()));
{
@@ -115,7 +114,6 @@
}
}
- isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags);
isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags);
CHECK_EQ(0, CountArrayBuffersInWeakList(isolate->heap()));
}
@@ -158,7 +156,6 @@
i::OS::SNPrintF(source, "ab%d = null;", i);
CompileRun(source.start());
isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags);
- isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags);
CHECK_EQ(2, CountArrayBuffersInWeakList(isolate->heap()));
@@ -177,7 +174,6 @@
CompileRun("ab1 = null; ab2 = null; ab3 = null;");
}
- isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags);
isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags);
CHECK_EQ(0, CountArrayBuffersInWeakList(isolate->heap()));
}
@@ -205,13 +201,11 @@
CHECK(HasTypedArrayInWeakList(*iab, *ita1));
CHECK(HasTypedArrayInWeakList(*iab, *ita2));
}
- isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags);
isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags);
CHECK_EQ(1, CountTypedArrays(*iab));
Handle<JSTypedArray> ita1 = v8::Utils::OpenHandle(*ta1);
CHECK(HasTypedArrayInWeakList(*iab, *ita1));
}
- isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags);
isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags);
CHECK_EQ(0, CountTypedArrays(*iab));
@@ -305,7 +299,6 @@
i::OS::SNPrintF(source, "ta%d = null;", i);
CompileRun(source.start());
isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags);
- isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags);
CHECK_EQ(1, CountArrayBuffersInWeakList(isolate->heap()));
@@ -326,7 +319,6 @@
CompileRun("ta1 = null; ta2 = null; ta3 = null;");
isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags);
- isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags);
CHECK_EQ(1, CountArrayBuffersInWeakList(isolate->heap()));
--
--
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.