Bug 179518 - Increase the alignment requirement of WKObject's wrapped C++ object
Summary: Increase the alignment requirement of WKObject's wrapped C++ object
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: Tim Horton
URL:
Keywords: InRadar
Depends on: 199523
Blocks:
  Show dependency treegraph
 
Reported: 2017-11-09 18:41 PST by Tim Horton
Modified: 2019-07-08 15:24 PDT (History)
10 users (show)

See Also:


Attachments
Patch (7.65 KB, patch)
2017-11-09 18:41 PST, Tim Horton
buildbot: commit-queue-
Details | Formatted Diff | Diff
Archive of layout-test-results from ews107 for mac-elcapitan-wk2 (752.78 KB, application/zip)
2017-11-09 19:30 PST, Build Bot
no flags Details
Archive of layout-test-results from ews126 for ios-simulator-wk2 (2.81 MB, application/zip)
2017-11-09 20:01 PST, Build Bot
no flags Details
Patch (7.00 KB, patch)
2017-11-10 15:36 PST, Tim Horton
no flags Details | Formatted Diff | Diff
Patch (7.00 KB, patch)
2017-11-11 01:19 PST, Tim Horton
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Tim Horton 2017-11-09 18:41:21 PST
Increase the alignment requirement of WKObject's wrapped C++ object
Comment 1 Tim Horton 2017-11-09 18:41:36 PST
Created attachment 326529 [details]
Patch
Comment 2 Build Bot 2017-11-09 19:30:05 PST
Comment on attachment 326529 [details]
Patch

Attachment 326529 [details] did not pass mac-wk2-ews (mac-wk2):
Output: http://webkit-queues.webkit.org/results/5172330

Number of test failures exceeded the failure limit.
Comment 3 Build Bot 2017-11-09 19:30:06 PST
Created attachment 326535 [details]
Archive of layout-test-results from ews107 for mac-elcapitan-wk2

The attached test failures were seen while running run-webkit-tests on the mac-wk2-ews.
Bot: ews107  Port: mac-elcapitan-wk2  Platform: Mac OS X 10.11.6
Comment 4 Build Bot 2017-11-09 20:01:21 PST
Comment on attachment 326529 [details]
Patch

Attachment 326529 [details] did not pass ios-sim-ews (ios-simulator-wk2):
Output: http://webkit-queues.webkit.org/results/5172450

Number of test failures exceeded the failure limit.
Comment 5 Build Bot 2017-11-09 20:01:22 PST
Created attachment 326537 [details]
Archive of layout-test-results from ews126 for ios-simulator-wk2

The attached test failures were seen while running run-webkit-tests on the ios-sim-ews.
Bot: ews126  Port: ios-simulator-wk2  Platform: Mac OS X 10.12.6
Comment 6 Tim Horton 2017-11-10 15:36:30 PST
Created attachment 326643 [details]
Patch
Comment 7 Ryosuke Niwa 2017-11-10 15:44:53 PST
Comment on attachment 326643 [details]
Patch

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

> Source/WebKit/Shared/Cocoa/APIObject.mm:86
> +static const size_t minimumObjectAlignment = 8;
> +static const size_t maximumExtraSpaceForAlignment = minimumObjectAlignment - alignof(void*);
> +static_assert(minimumObjectAlignment >= alignof(void*), "Objects should always be at least pointer-aligned.");

Do we really always want to do this alignment? Or just in some platform?
Comment 8 mitz 2017-11-11 00:07:05 PST
Comment on attachment 326643 [details]
Patch

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

> Source/WebKit/Shared/Cocoa/APIObject.mm:87
> +

I'd put the assertion before the subtraction it's guarding against underflow.

> Source/WebKit/Shared/Cocoa/APIObject.mm:111
> +    void* api = object_getIndexedIvars(obj);
> +    api = std::align(minimumObjectAlignment, size, api, spaceAvailable);
> +    return *static_cast<API::Object*>(api);

I’d have probably written this entire function as just two statements. Can you at least combine 109 with 110, or is there something about std::align that makes that impossible?
Comment 9 Tim Horton 2017-11-11 01:12:50 PST
Comment on attachment 326643 [details]
Patch

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

>> Source/WebKit/Shared/Cocoa/APIObject.mm:86
>> +static_assert(minimumObjectAlignment >= alignof(void*), "Objects should always be at least pointer-aligned.");
> 
> Do we really always want to do this alignment? Or just in some platform?

We do, as mentioned on IRC.

>> Source/WebKit/Shared/Cocoa/APIObject.mm:87
>> +
> 
> I'd put the assertion before the subtraction it's guarding against underflow.

Seems reasonable.

>> Source/WebKit/Shared/Cocoa/APIObject.mm:111
>> +    return *static_cast<API::Object*>(api);
> 
> I’d have probably written this entire function as just two statements. Can you at least combine 109 with 110, or is there something about std::align that makes that impossible?

For whatever reason, std::align is void* align( std::size_t, std::size_t, void*&, std::size_t&); so I /think/ the best I can do is merge the last two lines.
Comment 10 Tim Horton 2017-11-11 01:13:46 PST
(In reply to Tim Horton from comment #9)
> Comment on attachment 326643 [details]
> Patch
> >> Source/WebKit/Shared/Cocoa/APIObject.mm:111
> >> +    return *static_cast<API::Object*>(api);
> > 
> > I’d have probably written this entire function as just two statements. Can you at least combine 109 with 110, or is there something about std::align that makes that impossible?
> 
> For whatever reason, std::align is void* align( std::size_t, std::size_t,
> void*&, std::size_t&); so I /think/ the best I can do is merge the last two
> lines.

Otherwise, lots of "non-const lvalue reference cannot bind to a temporary..."
Comment 11 Tim Horton 2017-11-11 01:19:10 PST
Created attachment 326686 [details]
Patch
Comment 12 WebKit Commit Bot 2017-11-11 01:42:10 PST
Comment on attachment 326686 [details]
Patch

Clearing flags on attachment: 326686

Committed r224729: <https://trac.webkit.org/changeset/224729>
Comment 13 WebKit Commit Bot 2017-11-11 01:42:11 PST
All reviewed patches have been landed.  Closing bug.
Comment 14 Radar WebKit Bug Importer 2017-11-15 09:38:18 PST
<rdar://problem/35562125>