Diff
Modified: trunk/LayoutTests/ChangeLog (197542 => 197543)
--- trunk/LayoutTests/ChangeLog 2016-03-04 02:43:53 UTC (rev 197542)
+++ trunk/LayoutTests/ChangeLog 2016-03-04 03:19:11 UTC (rev 197543)
@@ -1,3 +1,15 @@
+2016-03-03 Keith Miller <[email protected]>
+
+ JSArrayBuffers should be collected less aggressively
+ https://bugs.webkit.org/show_bug.cgi?id=154982
+
+ Reviewed by Geoffrey Garen.
+
+ * js/arraybuffer-wrappers-expected.txt: Added.
+ * js/arraybuffer-wrappers.html: Added.
+ * js/script-tests/arraybuffer-wrappers.js: Added.
+ (prototype.types.forEach):
+
2016-03-03 Simon Fraser <[email protected]>
Use larger tiles when possible to reduce per-tile painting overhead
Added: trunk/LayoutTests/js/arraybuffer-wrappers-expected.txt (0 => 197543)
--- trunk/LayoutTests/js/arraybuffer-wrappers-expected.txt (rev 0)
+++ trunk/LayoutTests/js/arraybuffer-wrappers-expected.txt 2016-03-04 03:19:11 UTC (rev 197543)
@@ -0,0 +1,44 @@
+Tests wrappers for ArrayBuffer objects are not GCed when they shouldn't be
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+Test subclassing
+PASS foo.buffer instanceof C is true
+PASS foo.buffer instanceof C is true
+PASS foo.buffer instanceof C is true
+PASS foo.buffer instanceof C is true
+PASS foo.buffer instanceof C is true
+PASS foo.buffer instanceof C is true
+PASS foo.buffer instanceof C is true
+PASS foo.buffer instanceof C is true
+PASS foo.buffer instanceof C is true
+PASS foo.buffer instanceof C is true
+
+Test properties
+PASS foo.buffer.bar is 1
+PASS foo.buffer.bar is 1
+PASS foo.buffer.bar is 1
+PASS foo.buffer.bar is 1
+PASS foo.buffer.bar is 1
+PASS foo.buffer.bar is 1
+PASS foo.buffer.bar is 1
+PASS foo.buffer.bar is 1
+PASS foo.buffer.bar is 1
+PASS foo.buffer.bar is 1
+
+Test WeakMap
+PASS ws.has(foo.buffer) is true
+PASS ws.has(foo.buffer) is true
+PASS ws.has(foo.buffer) is true
+PASS ws.has(foo.buffer) is true
+PASS ws.has(foo.buffer) is true
+PASS ws.has(foo.buffer) is true
+PASS ws.has(foo.buffer) is true
+PASS ws.has(foo.buffer) is true
+PASS ws.has(foo.buffer) is true
+PASS ws.has(foo.buffer) is true
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
Added: trunk/LayoutTests/js/arraybuffer-wrappers.html (0 => 197543)
--- trunk/LayoutTests/js/arraybuffer-wrappers.html (rev 0)
+++ trunk/LayoutTests/js/arraybuffer-wrappers.html 2016-03-04 03:19:11 UTC (rev 197543)
@@ -0,0 +1,10 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<script src=""
+</head>
+<body>
+<script src=""
+<script src=""
+</body>
+</html>
Added: trunk/LayoutTests/js/script-tests/arraybuffer-wrappers.js (0 => 197543)
--- trunk/LayoutTests/js/script-tests/arraybuffer-wrappers.js (rev 0)
+++ trunk/LayoutTests/js/script-tests/arraybuffer-wrappers.js 2016-03-04 03:19:11 UTC (rev 197543)
@@ -0,0 +1,47 @@
+description("Tests wrappers for ArrayBuffer objects are not GCed when they shouldn't be");
+
+let types = [Int8Array, Uint8Array, Uint8ClampedArray, Int16Array, Uint16Array, Int32Array, Uint32Array, Float32Array, Float64Array, DataView];
+
+debug("Test subclassing");
+
+types.forEach(function(type) {
+ C = class extends ArrayBuffer { }
+
+ let b = new C(8);
+ foo = new type(b);
+
+ b = null;
+ gc();
+
+ shouldBeTrue("foo.buffer instanceof C");
+});
+
+debug("");
+debug("Test properties");
+
+types.forEach(function(type) {
+ b = new ArrayBuffer(8);
+ b.bar = 1;
+
+ foo = new Int32Array(b);
+ b = null;
+ gc();
+
+ shouldBe("foo.buffer.bar", "1");
+});
+
+debug("");
+debug("Test WeakMap");
+
+types.forEach(function(type) {
+ ws = new WeakSet();
+ b = new ArrayBuffer(8);
+
+ ws.add(b);
+ foo = new Int32Array(b);
+ b = null;
+
+ gc();
+
+ shouldBeTrue("ws.has(foo.buffer)");
+});
Modified: trunk/Source/_javascript_Core/ChangeLog (197542 => 197543)
--- trunk/Source/_javascript_Core/ChangeLog 2016-03-04 02:43:53 UTC (rev 197542)
+++ trunk/Source/_javascript_Core/ChangeLog 2016-03-04 03:19:11 UTC (rev 197543)
@@ -1,3 +1,46 @@
+2016-03-03 Keith Miller <[email protected]>
+
+ JSArrayBuffers should be collected less aggressively
+ https://bugs.webkit.org/show_bug.cgi?id=154982
+
+ Reviewed by Geoffrey Garen.
+
+ We are currently too aggressive in our collection of ArrayBuffer wrappers.
+ There are three cases where we need to avoid collecting ArrayBuffer wrappers.
+ 1. If the wrapper has custom properties.
+ 2. If the wrapper is a subclass of ArrayBuffer.
+ 3. If the wrapper is in a WeakMap/WeakSet.
+
+ Currently, we only pass the first case in WebCore and none in the jsc CLI.
+ This patch removes some optimizations that cause us to collect when we
+ should not. Namely, always skipping the object unless it has custom
+ properties. Additionally, in the case of subclassing, we also need a way
+ for custom JSArrayBuffer objects to register themselves as the wrapper for
+ an ArrayBuffer class.
+
+ Finally, this patch fixes an issue where views would not mark their ArrayBuffer
+ as an opaque root. This patch also moves an associated ASSERT that the
+ ArrayBuffer held by a view is not null in JSGenericTypedArrayView::visitChildren
+ into JSArrayBufferView::visitChildren, where we add the opaque root.
+
+ * runtime/JSArrayBuffer.cpp:
+ (JSC::JSArrayBuffer::finishCreation):
+ (JSC::JSArrayBuffer::create):
+ (JSC::JSArrayBuffer::createWithoutWrapping):
+ * runtime/JSArrayBuffer.h:
+ * runtime/JSArrayBufferView.cpp:
+ (JSC::JSArrayBufferView::visitChildren):
+ * runtime/JSArrayBufferView.h:
+ * runtime/JSGenericTypedArrayViewInlines.h:
+ (JSC::JSGenericTypedArrayView<Adaptor>::visitChildren): Deleted.
+ * runtime/SimpleTypedArrayController.cpp:
+ (JSC::SimpleTypedArrayController::toJS):
+ (JSC::SimpleTypedArrayController::registerWrapper):
+ (JSC::SimpleTypedArrayController::JSArrayBufferOwner::isReachableFromOpaqueRoots):
+ (JSC::SimpleTypedArrayController::JSArrayBufferOwner::finalize):
+ * runtime/SimpleTypedArrayController.h:
+ * runtime/TypedArrayController.h:
+
2016-03-03 Filip Pizlo <[email protected]>
Octane/regexp's Exec function should benefit from array length accessor inlining
Modified: trunk/Source/_javascript_Core/runtime/JSArrayBuffer.cpp (197542 => 197543)
--- trunk/Source/_javascript_Core/runtime/JSArrayBuffer.cpp 2016-03-04 02:43:53 UTC (rev 197542)
+++ trunk/Source/_javascript_Core/runtime/JSArrayBuffer.cpp 2016-03-04 03:19:11 UTC (rev 197543)
@@ -40,10 +40,11 @@
{
}
-void JSArrayBuffer::finishCreation(VM& vm)
+void JSArrayBuffer::finishCreation(VM& vm, JSGlobalObject* globalObject)
{
Base::finishCreation(vm);
vm.heap.addReference(this, m_impl);
+ vm.m_typedArrayController->registerWrapper(globalObject, m_impl, this);
}
JSArrayBuffer* JSArrayBuffer::create(
@@ -53,7 +54,7 @@
JSArrayBuffer* result =
new (NotNull, allocateCell<JSArrayBuffer>(vm.heap))
JSArrayBuffer(vm, structure, buffer);
- result->finishCreation(vm);
+ result->finishCreation(vm, structure->globalObject());
return result;
}
Modified: trunk/Source/_javascript_Core/runtime/JSArrayBuffer.h (197542 => 197543)
--- trunk/Source/_javascript_Core/runtime/JSArrayBuffer.h 2016-03-04 02:43:53 UTC (rev 197542)
+++ trunk/Source/_javascript_Core/runtime/JSArrayBuffer.h 2016-03-04 03:19:11 UTC (rev 197543)
@@ -38,11 +38,12 @@
protected:
JSArrayBuffer(VM&, Structure*, PassRefPtr<ArrayBuffer>);
- void finishCreation(VM&);
+ void finishCreation(VM&, JSGlobalObject*);
public:
+ // This function will register the new wrapper with the vm's TypedArrayController.
JS_EXPORT_PRIVATE static JSArrayBuffer* create(VM&, Structure*, PassRefPtr<ArrayBuffer>);
-
+
ArrayBuffer* impl() const { return m_impl; }
static Structure* createStructure(VM&, JSGlobalObject*, JSValue prototype);
Modified: trunk/Source/_javascript_Core/runtime/JSArrayBufferView.cpp (197542 => 197543)
--- trunk/Source/_javascript_Core/runtime/JSArrayBufferView.cpp 2016-03-04 02:43:53 UTC (rev 197542)
+++ trunk/Source/_javascript_Core/runtime/JSArrayBufferView.cpp 2016-03-04 03:19:11 UTC (rev 197543)
@@ -151,6 +151,19 @@
return Base::getOwnPropertySlot(thisObject, exec, propertyName, slot);
}
+void JSArrayBufferView::visitChildren(JSCell* cell, SlotVisitor& visitor)
+{
+ JSArrayBufferView* thisObject = jsCast<JSArrayBufferView*>(cell);
+
+ if (thisObject->hasArrayBuffer()) {
+ ArrayBuffer* buffer = thisObject->buffer();
+ RELEASE_ASSERT(buffer);
+ visitor.addOpaqueRoot(buffer);
+ }
+
+ Base::visitChildren(thisObject, visitor);
+}
+
void JSArrayBufferView::put(
JSCell* cell, ExecState* exec, PropertyName propertyName, JSValue value,
PutPropertySlot& slot)
Modified: trunk/Source/_javascript_Core/runtime/JSArrayBufferView.h (197542 => 197543)
--- trunk/Source/_javascript_Core/runtime/JSArrayBufferView.h 2016-03-04 02:43:53 UTC (rev 197542)
+++ trunk/Source/_javascript_Core/runtime/JSArrayBufferView.h 2016-03-04 03:19:11 UTC (rev 197543)
@@ -150,6 +150,8 @@
static void put(JSCell*, ExecState*, PropertyName, JSValue, PutPropertySlot&);
static bool defineOwnProperty(JSObject*, ExecState*, PropertyName, const PropertyDescriptor&, bool shouldThrow);
static bool deleteProperty(JSCell*, ExecState*, PropertyName);
+
+ static void visitChildren(JSCell*, SlotVisitor&);
static void getOwnNonIndexPropertyNames(JSObject*, ExecState*, PropertyNameArray&, EnumerationMode);
Modified: trunk/Source/_javascript_Core/runtime/JSGenericTypedArrayViewInlines.h (197542 => 197543)
--- trunk/Source/_javascript_Core/runtime/JSGenericTypedArrayViewInlines.h 2016-03-04 02:43:53 UTC (rev 197542)
+++ trunk/Source/_javascript_Core/runtime/JSGenericTypedArrayViewInlines.h 2016-03-04 03:19:11 UTC (rev 197543)
@@ -436,7 +436,6 @@
}
case WastefulTypedArray:
- RELEASE_ASSERT(thisObject->existingBufferInButterfly());
break;
case DataViewMode:
Modified: trunk/Source/_javascript_Core/runtime/SimpleTypedArrayController.cpp (197542 => 197543)
--- trunk/Source/_javascript_Core/runtime/SimpleTypedArrayController.cpp 2016-03-04 02:43:53 UTC (rev 197542)
+++ trunk/Source/_javascript_Core/runtime/SimpleTypedArrayController.cpp 2016-03-04 03:19:11 UTC (rev 197543)
@@ -40,12 +40,26 @@
{
if (JSArrayBuffer* buffer = native->m_wrapper.get())
return buffer;
-
+
+ // The JSArrayBuffer::create function will register the wrapper in finishCreation.
JSArrayBuffer* result = JSArrayBuffer::create(
exec->vm(), globalObject->arrayBufferStructure(), native);
- native->m_wrapper = Weak<JSArrayBuffer>(result);
return result;
}
+void SimpleTypedArrayController::registerWrapper(JSGlobalObject*, ArrayBuffer* native, JSArrayBuffer* wrapper)
+{
+ ASSERT(!native->m_wrapper);
+ native->m_wrapper = Weak<JSArrayBuffer>(wrapper, &m_owner);
+}
+
+bool SimpleTypedArrayController::JSArrayBufferOwner::isReachableFromOpaqueRoots(JSC::Handle<JSC::Unknown> handle, void*, JSC::SlotVisitor& visitor)
+{
+ auto& wrapper = *JSC::jsCast<JSC::JSArrayBuffer*>(handle.slot()->asCell());
+ return visitor.containsOpaqueRoot(wrapper.impl());
+}
+
+void SimpleTypedArrayController::JSArrayBufferOwner::finalize(JSC::Handle<JSC::Unknown>, void*) { }
+
} // namespace JSC
Modified: trunk/Source/_javascript_Core/runtime/SimpleTypedArrayController.h (197542 => 197543)
--- trunk/Source/_javascript_Core/runtime/SimpleTypedArrayController.h 2016-03-04 02:43:53 UTC (rev 197542)
+++ trunk/Source/_javascript_Core/runtime/SimpleTypedArrayController.h 2016-03-04 03:19:11 UTC (rev 197543)
@@ -28,6 +28,7 @@
#include "Handle.h"
#include "TypedArrayController.h"
+#include "WeakHandleOwner.h"
namespace JSC {
@@ -38,6 +39,10 @@
//
// - If the JSArrayBuffer is live, then the ArrayBuffer stays alive.
//
+// - If there is a JSArrayBufferView that is holding an ArrayBuffer
+// then any existing wrapper for that ArrayBuffer will be kept
+// alive.
+//
// - If you ask an ArrayBuffer for a JSArrayBuffer after one had
// already been created and it didn't die, then you get the same
// one.
@@ -48,6 +53,16 @@
virtual ~SimpleTypedArrayController();
virtual JSArrayBuffer* toJS(ExecState*, JSGlobalObject*, ArrayBuffer*) override;
+ virtual void registerWrapper(JSGlobalObject*, ArrayBuffer*, JSArrayBuffer*) override;
+
+private:
+ class JSArrayBufferOwner : public WeakHandleOwner {
+ public:
+ virtual bool isReachableFromOpaqueRoots(JSC::Handle<JSC::Unknown>, void* context, SlotVisitor&) override;
+ virtual void finalize(JSC::Handle<JSC::Unknown>, void* context) override;
+ };
+
+ JSArrayBufferOwner m_owner;
};
} // namespace JSC
Modified: trunk/Source/_javascript_Core/runtime/TypedArrayController.h (197542 => 197543)
--- trunk/Source/_javascript_Core/runtime/TypedArrayController.h 2016-03-04 02:43:53 UTC (rev 197542)
+++ trunk/Source/_javascript_Core/runtime/TypedArrayController.h 2016-03-04 03:19:11 UTC (rev 197543)
@@ -41,6 +41,7 @@
JS_EXPORT_PRIVATE virtual ~TypedArrayController();
virtual JSArrayBuffer* toJS(ExecState*, JSGlobalObject*, ArrayBuffer*) = 0;
+ virtual void registerWrapper(JSGlobalObject*, ArrayBuffer*, JSArrayBuffer*) = 0;
};
} // namespace JSC
Modified: trunk/Source/WebCore/ChangeLog (197542 => 197543)
--- trunk/Source/WebCore/ChangeLog 2016-03-04 02:43:53 UTC (rev 197542)
+++ trunk/Source/WebCore/ChangeLog 2016-03-04 03:19:11 UTC (rev 197543)
@@ -1,3 +1,42 @@
+2016-03-03 Keith Miller <[email protected]>
+
+ JSArrayBuffers should be collected less aggressively
+ https://bugs.webkit.org/show_bug.cgi?id=154982
+
+ Reviewed by Geoffrey Garen.
+
+ We are currently too aggressive in our collection of ArrayBuffer wrappers.
+ There are three cases where we need to avoid collecting ArrayBuffer wrappers.
+ 1. If the wrapper has custom properties.
+ 2. If the wrapper is a subclass of ArrayBuffer.
+ 3. If the wrapper is in a WeakMap/WeakSet.
+
+ Currently, we only pass the first case in WebCore and none in the jsc CLI.
+ This patch removes some optimizations that cause us to collect when we
+ should not. Namely, always skipping the object unless it has custom
+ properties. Additionally, in the case of subclassing, we also need a way
+ for custom JSArrayBuffer objects to register themselves as the wrapper for
+ an ArrayBuffer class.
+
+ Finally, this patch removes an unnecessary ref() and deref() of
+ ArrayBuffer objects during the creation/destruction of the wrapper.
+ Since an ArrayBuffer object's GC lifetime will be at least as long
+ as the lifetime of the wrapper we are creating for it we don't need
+ to ref() and deref() the ArrayBuffer object. This lifetime is
+ guaranteed because ArrayBuffer objects are both GCed and refcounted
+ and any new wrapper will visit the ArrayBuffer object as long as the
+ wrapper is still alive.
+
+ Test: js/arraybuffer-wrappers.html
+
+ * bindings/js/JSDOMBinding.h:
+ (WebCore::toJS):
+ * bindings/js/WebCoreTypedArrayController.cpp:
+ (WebCore::WebCoreTypedArrayController::registerWrapper):
+ (WebCore::WebCoreTypedArrayController::JSArrayBufferOwner::finalize):
+ (WebCore::WebCoreTypedArrayController::JSArrayBufferOwner::isReachableFromOpaqueRoots): Deleted.
+ * bindings/js/WebCoreTypedArrayController.h:
+
2016-03-03 Simon Fraser <[email protected]>
Use larger tiles when possible to reduce per-tile painting overhead
Modified: trunk/Source/WebCore/bindings/js/JSDOMBinding.h (197542 => 197543)
--- trunk/Source/WebCore/bindings/js/JSDOMBinding.h 2016-03-04 02:43:53 UTC (rev 197542)
+++ trunk/Source/WebCore/bindings/js/JSDOMBinding.h 2016-03-04 03:19:11 UTC (rev 197543)
@@ -410,9 +410,9 @@
return JSC::jsNull();
if (JSC::JSValue result = getExistingWrapper<JSC::JSArrayBuffer>(globalObject, buffer))
return result;
- buffer->ref();
+
+ // The JSArrayBuffer::create function will register the wrapper in finishCreation.
JSC::JSArrayBuffer* wrapper = JSC::JSArrayBuffer::create(exec->vm(), globalObject->arrayBufferStructure(), buffer);
- cacheWrapper(globalObject->world(), buffer, wrapper);
return wrapper;
}
Modified: trunk/Source/WebCore/bindings/js/WebCoreTypedArrayController.cpp (197542 => 197543)
--- trunk/Source/WebCore/bindings/js/WebCoreTypedArrayController.cpp 2016-03-04 02:43:53 UTC (rev 197542)
+++ trunk/Source/WebCore/bindings/js/WebCoreTypedArrayController.cpp 2016-03-04 03:19:11 UTC (rev 197543)
@@ -47,20 +47,21 @@
return JSC::jsCast<JSC::JSArrayBuffer*>(WebCore::toJS(state, JSC::jsCast<JSDOMGlobalObject*>(globalObject), buffer));
}
+void WebCoreTypedArrayController::registerWrapper(JSC::JSGlobalObject* globalObject, JSC::ArrayBuffer* native, JSC::JSArrayBuffer* wrapper)
+{
+ cacheWrapper(JSC::jsCast<JSDOMGlobalObject*>(globalObject)->world(), native, wrapper);
+}
+
bool WebCoreTypedArrayController::JSArrayBufferOwner::isReachableFromOpaqueRoots(JSC::Handle<JSC::Unknown> handle, void*, JSC::SlotVisitor& visitor)
{
auto& wrapper = *JSC::jsCast<JSC::JSArrayBuffer*>(handle.slot()->asCell());
- if (!wrapper.hasCustomProperties())
- return false;
return visitor.containsOpaqueRoot(wrapper.impl());
}
void WebCoreTypedArrayController::JSArrayBufferOwner::finalize(JSC::Handle<JSC::Unknown> handle, void* context)
{
auto& wrapper = *static_cast<JSC::JSArrayBuffer*>(handle.slot()->asCell());
- auto& buffer = *wrapper.impl();
- uncacheWrapper(*static_cast<DOMWrapperWorld*>(context), &buffer, &wrapper);
- buffer.deref();
+ uncacheWrapper(*static_cast<DOMWrapperWorld*>(context), wrapper.impl(), &wrapper);
}
} // namespace WebCore
Modified: trunk/Source/WebCore/bindings/js/WebCoreTypedArrayController.h (197542 => 197543)
--- trunk/Source/WebCore/bindings/js/WebCoreTypedArrayController.h 2016-03-04 02:43:53 UTC (rev 197542)
+++ trunk/Source/WebCore/bindings/js/WebCoreTypedArrayController.h 2016-03-04 03:19:11 UTC (rev 197543)
@@ -41,7 +41,8 @@
virtual ~WebCoreTypedArrayController();
virtual JSC::JSArrayBuffer* toJS(JSC::ExecState*, JSC::JSGlobalObject*, JSC::ArrayBuffer*) override;
-
+ virtual void registerWrapper(JSC::JSGlobalObject*, ArrayBuffer*, JSC::JSArrayBuffer*) override;
+
JSC::WeakHandleOwner* wrapperOwner() { return &m_owner; }
private: