Bug 156123

Summary: Migrate BidiRunList and BidiRun to automatic memory management
Product: WebKit Reporter: Myles C. Maxfield <mmaxfield>
Component: New BugsAssignee: Myles C. Maxfield <mmaxfield>
Status: RESOLVED FIXED    
Severity: Normal CC: commit-queue, dino, esprehn+autocc, glenn, hyatt, jonlee, kondapallykalyan, simon.fraser, thorton
Priority: P2    
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
Patch
none
Patch
none
Patch
simon.fraser: review+
Addressing Darin's comments none

Description Myles C. Maxfield 2016-04-01 17:53:30 PDT
Migrate BidiRunList and BidiRun to automatic memory management
Comment 1 Myles C. Maxfield 2016-04-01 17:55:00 PDT
Created attachment 275451 [details]
Patch
Comment 2 Myles C. Maxfield 2016-04-01 18:06:09 PDT
This is fixing a problem that has been around since r3627 (February 2003)!!!
Comment 3 Myles C. Maxfield 2016-04-01 18:13:08 PDT
Created attachment 275452 [details]
Patch
Comment 4 Myles C. Maxfield 2016-04-01 18:19:47 PDT
Created attachment 275453 [details]
Patch
Comment 5 Simon Fraser (smfr) 2016-04-01 20:39:55 PDT
Comment on attachment 275453 [details]
Patch

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

> Source/WebCore/platform/text/BidiResolver.h:160
> +        , m_override(context->override())

Why isn't m_level initialized here?

> Source/WebCore/platform/text/BidiResolver.h:197
> -    // Do not add anything apart from bitfields until after m_next. See https://bugs.webkit.org/show_bug.cgi?id=100173
> -    bool m_override : 1;
> -    bool m_hasHyphen : 1; // Used by BidiRun subclass which is a layering violation but enables us to save 8 bytes per object on 64-bit.
> -    unsigned char m_level;
> -    BidiCharacterRun* m_next;
> +private:
> +    std::unique_ptr<BidiCharacterRun> m_next;
> +
> +public:
>      int m_start;
>      int m_stop;
> +    unsigned char m_level;
> +    bool m_override : 1;
> +    bool m_hasHyphen : 1; // Used by BidiRun subclass which is a layering violation but enables us to save 8 bytes per object on 64-bit.

What is the size change after these changes?

> Source/WebCore/platform/text/BidiRunList.h:67
>      Run* m_lastRun;
>      Run* m_logicallyLastRun;

Would be nice to have comments saying who owns these raw pointers.
Comment 6 Myles C. Maxfield 2016-04-01 23:23:27 PDT
Comment on attachment 275453 [details]
Patch

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

>> Source/WebCore/platform/text/BidiResolver.h:160
>> +        , m_override(context->override())
> 
> Why isn't m_level initialized here?

It is initialized on line 166 / 165 below.

>> Source/WebCore/platform/text/BidiResolver.h:197
>> +    bool m_hasHyphen : 1; // Used by BidiRun subclass which is a layering violation but enables us to save 8 bytes per object on 64-bit.
> 
> What is the size change after these changes?

It stays 24 bytes.
Comment 7 Myles C. Maxfield 2016-04-02 00:01:41 PDT
Committed r198970: <http://trac.webkit.org/changeset/198970>
Comment 8 Darin Adler 2016-04-02 20:34:01 PDT
Comment on attachment 275453 [details]
Patch

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

> Source/WebCore/platform/text/BidiRunList.h:182
> +    m_firstRun = nullptr;

There’s one significant difference from the old algorithm for deleting the linked list and the new one. This new algorithm uses recursion to delete the linked list, using stack proportional to the length of the list. The old algorithm used iteration instead. I don’t think that change is an improvement. This can be fixed in a couple ways. One way is to add this implementation of ~BidiCharacterRun instead of letting the compiler generate the default implementation:

    ~BidiCharacterRun()
    {
        // Delete the linked list in a loop to prevent destructor recursion.
        auto next = WTFMove(m_next);
        while (next)
            next = WTFMove(next->m_next);
    }

On the other hand, it’s possible that the recursive algorithm is acceptable, or even that the compiler is clever enough to turn this into tail recursion and optimize that to not use stack.
Comment 9 Myles C. Maxfield 2016-04-04 11:22:10 PDT
Reopening to attach new patch.
Comment 10 Myles C. Maxfield 2016-04-04 11:22:13 PDT
Created attachment 275561 [details]
Addressing Darin's comments
Comment 11 Myles C. Maxfield 2016-04-04 12:41:25 PDT
Committed r199015: <http://trac.webkit.org/changeset/199015>