Skip to content
Permalink
Browse files
[v8] Improve performance of typed array set() taking Array
https://bugs.webkit.org/show_bug.cgi?id=63644

Patch by Ulan Degenbaev <ulan@chromium.org> on 2011-09-08
Reviewed by Kenneth Russell.

Overwrite the native 'set' method of the type arrays with JS
implementation after initialization of the global context.

Add tests for invalid and boundary offsets. No performance tests.

* LayoutTests/fast/canvas/webgl/array-unit-tests-expected.txt:
* LayoutTests/fast/canvas/webgl/array-unit-tests.html:
* Source/WebCore/WebCore.gyp/WebCore.gyp:
* Source/WebCore/WebCore.gypi:
* Source/WebCore/bindings/v8/V8BindingScripts.cpp: Added.
* Source/WebCore/bindings/v8/V8BindingScripts.h: Added.
* Source/WebCore/bindings/v8/V8DOMWindowShell.cpp:
* Source/WebCore/bindings/v8/WorkerContextExecutionProxy.cpp:
* Source/WebCore/bindings/v8/custom/V8ArrayBufferViewCustomScript.js: Added.

Canonical link: https://commits.webkit.org/83677@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@94783 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
ulan authored and webkit-commit-queue committed Sep 8, 2011
1 parent e4eb654 commit e4cc045cdae65a5c2b19271d3c2fb5d82faacfd0
@@ -1,3 +1,25 @@
2011-09-08 Ulan Degenbaev <ulan@chromium.org>

[v8] Improve performance of typed array set() taking Array
https://bugs.webkit.org/show_bug.cgi?id=63644

Reviewed by Kenneth Russell.

Overwrite the native 'set' method of the type arrays with JS
implementation after initialization of the global context.

Add tests for invalid and boundary offsets. No performance tests.

* LayoutTests/fast/canvas/webgl/array-unit-tests-expected.txt:
* LayoutTests/fast/canvas/webgl/array-unit-tests.html:
* Source/WebCore/WebCore.gyp/WebCore.gyp:
* Source/WebCore/WebCore.gypi:
* Source/WebCore/bindings/v8/V8BindingScripts.cpp: Added.
* Source/WebCore/bindings/v8/V8BindingScripts.h: Added.
* Source/WebCore/bindings/v8/V8DOMWindowShell.cpp:
* Source/WebCore/bindings/v8/WorkerContextExecutionProxy.cpp:
* Source/WebCore/bindings/v8/custom/V8ArrayBufferViewCustomScript.js: Added.

2011-09-08 Varun Jain <varunjain@google.com>

Split Tap gesture detection into TapDown and Tap.
@@ -43,8 +43,16 @@ PASS array.subarray(2).length is (32 / typeSize) - 2
PASS array.subarray(-2).length is 2
PASS array.subarray(-2147483648).length is (32 / typeSize)
PASS Setting Float32Array from array with out-of-range offset was caught
PASS Setting Float32Array from fake array with invalid length was caught
PASS Setting Float32Array from Float32Array with out-of-range offset was caught
PASS Setting Float32Array from array with negative offset was caught
PASS Setting Float32Array from Float32Array with negative offset was caught
PASS Setting Float32Array from array with -0 offset
PASS Setting Float32Array from Float32Array with -0 offset
PASS Setting Float32Array from array with boundary offset
PASS Setting Float32Array from Float32Array with boundary offset
PASS Setting Float32Array from array with non-integer offset
PASS Setting Float32Array from Float32Array with non-integer offset
PASS Setting Float32Array from fake array with invalid length was caught
PASS array.get is undefined.
PASS array.set(0, 1) threw exception.
PASS test storing NaN in Float32Array
@@ -89,8 +97,16 @@ PASS array.subarray(2).length is (32 / typeSize) - 2
PASS array.subarray(-2).length is 2
PASS array.subarray(-2147483648).length is (32 / typeSize)
PASS Setting Float64Array from array with out-of-range offset was caught
PASS Setting Float64Array from fake array with invalid length was caught
PASS Setting Float64Array from Float64Array with out-of-range offset was caught
PASS Setting Float64Array from array with negative offset was caught
PASS Setting Float64Array from Float64Array with negative offset was caught
PASS Setting Float64Array from array with -0 offset
PASS Setting Float64Array from Float64Array with -0 offset
PASS Setting Float64Array from array with boundary offset
PASS Setting Float64Array from Float64Array with boundary offset
PASS Setting Float64Array from array with non-integer offset
PASS Setting Float64Array from Float64Array with non-integer offset
PASS Setting Float64Array from fake array with invalid length was caught
PASS array.get is undefined.
PASS array.set(0, 1) threw exception.
PASS test storing NaN in Float64Array
@@ -131,8 +147,16 @@ PASS array.subarray(2).length is (32 / typeSize) - 2
PASS array.subarray(-2).length is 2
PASS array.subarray(-2147483648).length is (32 / typeSize)
PASS Setting Int8Array from array with out-of-range offset was caught
PASS Setting Int8Array from fake array with invalid length was caught
PASS Setting Int8Array from Int8Array with out-of-range offset was caught
PASS Setting Int8Array from array with negative offset was caught
PASS Setting Int8Array from Int8Array with negative offset was caught
PASS Setting Int8Array from array with -0 offset
PASS Setting Int8Array from Int8Array with -0 offset
PASS Setting Int8Array from array with boundary offset
PASS Setting Int8Array from Int8Array with boundary offset
PASS Setting Int8Array from array with non-integer offset
PASS Setting Int8Array from Int8Array with non-integer offset
PASS Setting Int8Array from fake array with invalid length was caught
PASS array.get is undefined.
PASS array.set(0, 1) threw exception.
PASS test storing NaN in Int8Array
@@ -178,8 +202,16 @@ PASS array.subarray(2).length is (32 / typeSize) - 2
PASS array.subarray(-2).length is 2
PASS array.subarray(-2147483648).length is (32 / typeSize)
PASS Setting Int16Array from array with out-of-range offset was caught
PASS Setting Int16Array from fake array with invalid length was caught
PASS Setting Int16Array from Int16Array with out-of-range offset was caught
PASS Setting Int16Array from array with negative offset was caught
PASS Setting Int16Array from Int16Array with negative offset was caught
PASS Setting Int16Array from array with -0 offset
PASS Setting Int16Array from Int16Array with -0 offset
PASS Setting Int16Array from array with boundary offset
PASS Setting Int16Array from Int16Array with boundary offset
PASS Setting Int16Array from array with non-integer offset
PASS Setting Int16Array from Int16Array with non-integer offset
PASS Setting Int16Array from fake array with invalid length was caught
PASS array.get is undefined.
PASS array.set(0, 1) threw exception.
PASS test storing NaN in Int16Array
@@ -225,8 +257,16 @@ PASS array.subarray(2).length is (32 / typeSize) - 2
PASS array.subarray(-2).length is 2
PASS array.subarray(-2147483648).length is (32 / typeSize)
PASS Setting Int32Array from array with out-of-range offset was caught
PASS Setting Int32Array from fake array with invalid length was caught
PASS Setting Int32Array from Int32Array with out-of-range offset was caught
PASS Setting Int32Array from array with negative offset was caught
PASS Setting Int32Array from Int32Array with negative offset was caught
PASS Setting Int32Array from array with -0 offset
PASS Setting Int32Array from Int32Array with -0 offset
PASS Setting Int32Array from array with boundary offset
PASS Setting Int32Array from Int32Array with boundary offset
PASS Setting Int32Array from array with non-integer offset
PASS Setting Int32Array from Int32Array with non-integer offset
PASS Setting Int32Array from fake array with invalid length was caught
PASS array.get is undefined.
PASS array.set(0, 1) threw exception.
PASS test storing NaN in Int32Array
@@ -267,8 +307,16 @@ PASS array.subarray(2).length is (32 / typeSize) - 2
PASS array.subarray(-2).length is 2
PASS array.subarray(-2147483648).length is (32 / typeSize)
PASS Setting Uint8Array from array with out-of-range offset was caught
PASS Setting Uint8Array from fake array with invalid length was caught
PASS Setting Uint8Array from Uint8Array with out-of-range offset was caught
PASS Setting Uint8Array from array with negative offset was caught
PASS Setting Uint8Array from Uint8Array with negative offset was caught
PASS Setting Uint8Array from array with -0 offset
PASS Setting Uint8Array from Uint8Array with -0 offset
PASS Setting Uint8Array from array with boundary offset
PASS Setting Uint8Array from Uint8Array with boundary offset
PASS Setting Uint8Array from array with non-integer offset
PASS Setting Uint8Array from Uint8Array with non-integer offset
PASS Setting Uint8Array from fake array with invalid length was caught
PASS array.get is undefined.
PASS array.set(0, 1) threw exception.
PASS test storing NaN in Uint8Array
@@ -314,8 +362,16 @@ PASS array.subarray(2).length is (32 / typeSize) - 2
PASS array.subarray(-2).length is 2
PASS array.subarray(-2147483648).length is (32 / typeSize)
PASS Setting Uint16Array from array with out-of-range offset was caught
PASS Setting Uint16Array from fake array with invalid length was caught
PASS Setting Uint16Array from Uint16Array with out-of-range offset was caught
PASS Setting Uint16Array from array with negative offset was caught
PASS Setting Uint16Array from Uint16Array with negative offset was caught
PASS Setting Uint16Array from array with -0 offset
PASS Setting Uint16Array from Uint16Array with -0 offset
PASS Setting Uint16Array from array with boundary offset
PASS Setting Uint16Array from Uint16Array with boundary offset
PASS Setting Uint16Array from array with non-integer offset
PASS Setting Uint16Array from Uint16Array with non-integer offset
PASS Setting Uint16Array from fake array with invalid length was caught
PASS array.get is undefined.
PASS array.set(0, 1) threw exception.
PASS test storing NaN in Uint16Array
@@ -361,8 +417,16 @@ PASS array.subarray(2).length is (32 / typeSize) - 2
PASS array.subarray(-2).length is 2
PASS array.subarray(-2147483648).length is (32 / typeSize)
PASS Setting Uint32Array from array with out-of-range offset was caught
PASS Setting Uint32Array from fake array with invalid length was caught
PASS Setting Uint32Array from Uint32Array with out-of-range offset was caught
PASS Setting Uint32Array from array with negative offset was caught
PASS Setting Uint32Array from Uint32Array with negative offset was caught
PASS Setting Uint32Array from array with -0 offset
PASS Setting Uint32Array from Uint32Array with -0 offset
PASS Setting Uint32Array from array with boundary offset
PASS Setting Uint32Array from Uint32Array with boundary offset
PASS Setting Uint32Array from array with non-integer offset
PASS Setting Uint32Array from Uint32Array with non-integer offset
PASS Setting Uint32Array from fake array with invalid length was caught
PASS array.get is undefined.
PASS array.set(0, 1) threw exception.
PASS test storing NaN in Uint32Array
@@ -616,20 +616,95 @@
}
}

function testSettingFromArrayWithOutOfRangeOffset(type, name) {
var webglArray = new type(32);
var array = [];
for (var i = 0; i < 16; i++) {
array.push(i);
function setWithInvalidOffset(type, name, length,
sourceType, sourceName, sourceLength,
offset, offsetDescription) {
var webglArray = new type(length);
var sourceArray = new sourceType(sourceLength);
for (var i = 0; i < sourceLength; i++)
sourceArray[i] = 42 + i;
try {
webglArray.set(sourceArray, offset);
testFailed("Setting " + name + " from " + sourceName + " with " +
offsetDescription + " offset was not caught");
} catch (e) {
testPassed("Setting " + name + " from " + sourceName + " with " +
offsetDescription + " offset was caught");
}
}

function setWithValidOffset(type, name, length,
sourceType, sourceName, sourceLength,
offset, offsetDescription) {
running("Setting " + name + " from " + sourceName + " with " +
offsetDescription + " offset");
var webglArray = new type(length);
var sourceArray = new sourceType(sourceLength);
for (var i = 0; i < sourceLength; i++)
sourceArray[i] = 42 + i;
try {
webglArray.set(array, 0x7FFFFFF8);
testFailed("Setting " + name + " from array with out-of-range offset was not caught");
webglArray.set(sourceArray, offset);
offset = Math.floor(offset);
for (var i = 0; i < sourceLength; i++) {
assertEq("Element " + i + offset, sourceArray[i], webglArray[i + offset]);
}
pass();
} catch (e) {
testPassed("Setting " + name + " from array with out-of-range offset was caught");
fail(e);
}
}


function testSettingFromArrayWithOutOfRangeOffset(type, name) {
setWithInvalidOffset(type, name, 32, Array, "array", 16,
0x7FFFFFF8, "out-of-range");
}

function testSettingFromTypedArrayWithOutOfRangeOffset(type, name) {
setWithInvalidOffset(type, name, 32, type, name, 16,
0x7FFFFFF8, "out-of-range");
}

function testSettingFromArrayWithNegativeOffset(type, name) {
setWithInvalidOffset(type, name, 32, Array, "array", 16,
-1, "negative");
}

function testSettingFromTypedArrayWithNegativeOffset(type, name) {
setWithInvalidOffset(type, name, 32, type, name, 16,
-1, "negative");
}

function testSettingFromArrayWithMinusZeroOffset(type, name) {
setWithValidOffset(type, name, 32, Array, "array", 16,
-0, "-0");
}

function testSettingFromTypedArrayWithMinusZeroOffset(type, name) {
setWithValidOffset(type, name, 32, type, name, 16,
-0, "-0");
}

function testSettingFromArrayWithBoundaryOffset(type, name) {
setWithValidOffset(type, name, 32, Array, "array", 16,
16, "boundary");
}

function testSettingFromTypedArrayWithBoundaryOffset(type, name) {
setWithValidOffset(type, name, 32, type, name, 16,
16, "boundary");
}

function testSettingFromArrayWithNonIntegerOffset(type, name) {
setWithValidOffset(type, name, 32, Array, "array", 16,
16.999, "non-integer");
}

function testSettingFromTypedArrayWithNonIntegerOffset(type, name) {
setWithValidOffset(type, name, 32, type, name, 16,
16.999, "non-integer");
}

function testSettingFromFakeArrayWithOutOfRangeLength(type, name) {
var webglArray = new type(32);
var array = {};
@@ -642,19 +717,6 @@
}
}

function testSettingFromTypedArrayWithOutOfRangeOffset(type, name) {
var webglArray = new type(32);
var srcArray = new type(16);
for (var i = 0; i < 16; i++) {
srcArray[i] = i;
}
try {
webglArray.set(srcArray, 0x7FFFFFF8);
testFailed("Setting " + name + " from " + name + " with out-of-range offset was not caught");
} catch (e) {
testPassed("Setting " + name + " from " + name + " with out-of-range offset was caught");
}
}

function negativeTestGetAndSetMethods(type, name) {
array = new type([2, 3]);
@@ -872,8 +934,16 @@
testSubarrayWithOutOfRangeValues(type, name, testCase.elementSizeInBytes);
testSubarrayWithDefaultValues(type, name, testCase.elementSizeInBytes);
testSettingFromArrayWithOutOfRangeOffset(type, name);
testSettingFromFakeArrayWithOutOfRangeLength(type, name);
testSettingFromTypedArrayWithOutOfRangeOffset(type, name);
testSettingFromArrayWithNegativeOffset(type, name);
testSettingFromTypedArrayWithNegativeOffset(type, name);
testSettingFromArrayWithMinusZeroOffset(type, name);
testSettingFromTypedArrayWithMinusZeroOffset(type, name);
testSettingFromArrayWithBoundaryOffset(type, name);
testSettingFromTypedArrayWithBoundaryOffset(type, name);
testSettingFromArrayWithNonIntegerOffset(type, name);
testSettingFromTypedArrayWithNonIntegerOffset(type, name);
testSettingFromFakeArrayWithOutOfRangeLength(type, name);
negativeTestGetAndSetMethods(type, name);
testNaNConversion(type, name);
}
@@ -479,6 +479,23 @@
],
'actions': [
# Actions to build derived sources.
{
'action_name': 'generateV8ArrayBufferViewCustomScript',
'inputs': [
'../bindings/v8/custom/V8ArrayBufferViewCustomScript.js',
],
'outputs': [
'<(SHARED_INTERMEDIATE_DIR)/webkit/V8ArrayBufferViewCustomScript.h',
],
'action': [
'perl',
'../inspector/xxd.pl',
'V8ArrayBufferViewCustomScript_js',
'<@(_inputs)',
'<@(_outputs)'
],
'message': 'Generating V8ArrayBufferViewCustomScript.h from V8ArrayBufferViewCustomScript.js',
},
{
'action_name': 'generateXMLViewerCSS',
'inputs': [
@@ -2063,6 +2063,8 @@
'bindings/v8/V8AbstractEventListener.h',
'bindings/v8/V8Binding.cpp',
'bindings/v8/V8Binding.h',
'bindings/v8/V8BindingScripts.cpp',
'bindings/v8/V8BindingScripts.h',
'bindings/v8/V8Collection.cpp',
'bindings/v8/V8Collection.h',
'bindings/v8/V8DOMMap.cpp',
@@ -0,0 +1,43 @@
/*
* Copyright (C) 2011 Google Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#include "config.h"

#include "V8BindingScripts.h"

#include "V8ArrayBufferViewCustomScript.h"
#include "V8Binding.h"

namespace WebCore {

void V8BindingScripts::runScripts(v8::Handle<v8::Context> v8Context)
{
v8::Context::Scope contextScope(v8Context);
String source(reinterpret_cast<const char*>(V8ArrayBufferViewCustomScript_js),
sizeof(V8ArrayBufferViewCustomScript_js));
v8::Handle<v8::Script> script = v8::Script::Compile(v8String(source));
script->Run();
}

}

0 comments on commit e4cc045

Please sign in to comment.