Bug 159048 - We should have a DFG intrinsic that checks if a value is a TypedArrayView
Summary: We should have a DFG intrinsic that checks if a value is a TypedArrayView
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Keith Miller
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-06-22 16:58 PDT by Keith Miller
Modified: 2016-06-22 18:39 PDT (History)
4 users (show)

See Also:


Attachments
Patch (21.83 KB, patch)
2016-06-22 17:02 PDT, Keith Miller
no flags Details | Formatted Diff | Diff
Patch (21.92 KB, patch)
2016-06-22 17:10 PDT, Keith Miller
no flags Details | Formatted Diff | Diff
Patch for landing (21.91 KB, patch)
2016-06-22 18:10 PDT, Keith Miller
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Keith Miller 2016-06-22 16:58:14 PDT
We should have a DFG intrinsic that checks if a value is a TypedArrayView
Comment 1 Keith Miller 2016-06-22 17:02:55 PDT
Created attachment 281887 [details]
Patch
Comment 2 Keith Miller 2016-06-22 17:10:23 PDT
Created attachment 281888 [details]
Patch
Comment 3 Saam Barati 2016-06-22 17:34:10 PDT
Comment on attachment 281888 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=281888&action=review

> Source/JavaScriptCore/dfg/DFGAbstractInterpreterInlines.h:1276
> +            if (!(child.m_type & ~SpecTypedArrayView)) {

Shouldn't this also check !!child.m_type?

> Source/JavaScriptCore/dfg/DFGAbstractInterpreterInlines.h:1281
> +            if (!(child.m_type & SpecTypedArrayView)) {

ditto

> Source/JavaScriptCore/ftl/FTLLowerDFGToB3.cpp:6121
> +        m_out.branch(isCell(value, provenType(m_node->child1())), unsure(isCellCase), unsure(continuation));

I would guess the isCellCase is likely.

> Source/JavaScriptCore/runtime/JSGlobalObject.cpp:707
> +        GlobalPropertyInfo(vm.propertyNames->builtinNames().isTypedArrayViewPrivateName(), privateFuncIsTypedArrayView, DontEnum | DontDelete | ReadOnly),

Where is this used from besides the test?

> Source/JavaScriptCore/runtime/JSTypedArrayViewPrototype.cpp:70
> +    return JSValue::encode(jsBoolean(value.isObject() && isTypedView(value.getObject()->classInfo()->typedArrayStorageType)));

I think this would be faster as:
jsBoolean(value.isCell() && isTypedView(value.asCell()->classInfo()->typedArrayStorageType))
because most cells you will see are going to be objects.

> Source/JavaScriptCore/tests/stress/istypedarrayview-intrinsic.js:4
> +    let foo = createBuiltin(`(function (a) { "use strict"; return @isTypedArrayView(a); })`);

Neat.
Comment 4 Saam Barati 2016-06-22 17:35:12 PDT
Comment on attachment 281888 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=281888&action=review

>> Source/JavaScriptCore/dfg/DFGAbstractInterpreterInlines.h:1281
>> +            if (!(child.m_type & SpecTypedArrayView)) {
> 
> ditto

ignore this ditto
Comment 5 Keith Miller 2016-06-22 18:04:26 PDT
Comment on attachment 281888 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=281888&action=review

>> Source/JavaScriptCore/dfg/DFGAbstractInterpreterInlines.h:1276
>> +            if (!(child.m_type & ~SpecTypedArrayView)) {
> 
> Shouldn't this also check !!child.m_type?

I'm pretty sure that we force OSR if the child has no speculated type.

>> Source/JavaScriptCore/ftl/FTLLowerDFGToB3.cpp:6121
>> +        m_out.branch(isCell(value, provenType(m_node->child1())), unsure(isCellCase), unsure(continuation));
> 
> I would guess the isCellCase is likely.

While I agree with you in general, my thought process is that this node will be eliminated in most of the cases where the value is a TypedArray. In the cases where we can't eliminate the node I think its harder to claim the value is a usually a cell.

>> Source/JavaScriptCore/runtime/JSGlobalObject.cpp:707
>> +        GlobalPropertyInfo(vm.propertyNames->builtinNames().isTypedArrayViewPrivateName(), privateFuncIsTypedArrayView, DontEnum | DontDelete | ReadOnly),
> 
> Where is this used from besides the test?

I'm going to use this when I move subarray to a builtin. Currently it is not used elsewhere.

>> Source/JavaScriptCore/runtime/JSTypedArrayViewPrototype.cpp:70
>> +    return JSValue::encode(jsBoolean(value.isObject() && isTypedView(value.getObject()->classInfo()->typedArrayStorageType)));
> 
> I think this would be faster as:
> jsBoolean(value.isCell() && isTypedView(value.asCell()->classInfo()->typedArrayStorageType))
> because most cells you will see are going to be objects.

Fixed.
Comment 6 Keith Miller 2016-06-22 18:10:48 PDT
Created attachment 281892 [details]
Patch for landing
Comment 7 WebKit Commit Bot 2016-06-22 18:39:13 PDT
Comment on attachment 281892 [details]
Patch for landing

Clearing flags on attachment: 281892

Committed r202363: <http://trac.webkit.org/changeset/202363>
Comment 8 WebKit Commit Bot 2016-06-22 18:39:17 PDT
All reviewed patches have been landed.  Closing bug.