Bug 141211 - Remove BytecodeGenerator::preserveLastVar() and replace it with a more robust mechanism for preserving non-temporary registers
Summary: Remove BytecodeGenerator::preserveLastVar() and replace it with a more robust...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: 528+ (Nightly build)
Hardware: All All
: P2 Normal
Assignee: Filip Pizlo
URL:
Keywords:
Depends on:
Blocks: 141174
  Show dependency treegraph
 
Reported: 2015-02-03 14:40 PST by Filip Pizlo
Modified: 2015-02-06 08:05 PST (History)
10 users (show)

See Also:


Attachments
the patch (2.90 KB, patch)
2015-02-03 14:42 PST, Filip Pizlo
fpizlo: review-
Details | Formatted Diff | Diff
the patch (4.34 KB, patch)
2015-02-03 14:57 PST, Filip Pizlo
no flags Details | Formatted Diff | Diff
the patch (5.78 KB, patch)
2015-02-03 15:07 PST, Filip Pizlo
mark.lam: review+
Details | Formatted Diff | Diff
the patch (5.82 KB, patch)
2015-02-04 08:57 PST, Filip Pizlo
mark.lam: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Filip Pizlo 2015-02-03 14:40:00 PST
Get rid of it.
Comment 1 Filip Pizlo 2015-02-03 14:42:32 PST
Created attachment 245969 [details]
the patch
Comment 2 Mark Lam 2015-02-03 14:43:23 PST
Comment on attachment 245969 [details]
the patch

r=me
Comment 3 Filip Pizlo 2015-02-03 14:51:44 PST
(In reply to comment #2)
> Comment on attachment 245969 [details]
> the patch
> 
> r=me

Invalid patch, will upload a new one.
Comment 4 Filip Pizlo 2015-02-03 14:57:27 PST
Created attachment 245970 [details]
the patch
Comment 5 Filip Pizlo 2015-02-03 15:07:21 PST
Created attachment 245971 [details]
the patch
Comment 6 Mark Lam 2015-02-03 15:08:39 PST
Comment on attachment 245971 [details]
the patch

r=me
Comment 7 Filip Pizlo 2015-02-03 15:13:32 PST
(In reply to comment #6)
> Comment on attachment 245971 [details]
> the patch
> 
> r=me

Lol, my patch is still wrong. ;-)
Comment 8 Filip Pizlo 2015-02-04 08:57:39 PST
Created attachment 246035 [details]
the patch

For real this time!
Comment 9 Mark Lam 2015-02-04 09:32:44 PST
Comment on attachment 246035 [details]
the patch

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

> Source/JavaScriptCore/ChangeLog:47
> +2015-02-03  Filip Pizlo  <fpizlo@apple.com>
> +
> +        Reviewed by NOBODY (OOPS!).
> +        
> +        Also removes the localArgumentsRegister local variable in BytecodeGenerator's
> +        constructor. It's not used.
> +
> +        * bytecompiler/BytecodeGenerator.cpp:
> +        (JSC::BytecodeGenerator::BytecodeGenerator):
> +        (JSC::BytecodeGenerator::preserveLastVar): Deleted.
> +        * bytecompiler/BytecodeGenerator.h:
> +        (JSC::BytecodeGenerator::addVar):
> +

Leftover edit that should have been removed?

> Source/JavaScriptCore/bytecompiler/RegisterID.h:75
> -            ASSERT(!m_refCount);
>  #ifndef NDEBUG
>              m_didSetIndex = true;
>  #endif

I think the main reason for the ASSERT(!m_refCount) is to ensure that the index is only set once before use.  Though the previous implementation allows us to “change our minds” and set the index to something else (which I don’t think is likely to happen) as long as we haven’t started using the RegisterID yet, I think the real bug it’s trying to watch out for is that we don’t use the RegisterID’s index in one place and then change it before using it in another (which is also unlikely to happen but if it does, it can cause havoc).

How about you replace this assert with ASSERT(!m_didSetIndex) in the #ifndef NDEBUG section instead?  Would that work?
Comment 10 Filip Pizlo 2015-02-04 09:39:42 PST
(In reply to comment #9)
> Comment on attachment 246035 [details]
> the patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=246035&action=review
> 
> > Source/JavaScriptCore/ChangeLog:47
> > +2015-02-03  Filip Pizlo  <fpizlo@apple.com>
> > +
> > +        Reviewed by NOBODY (OOPS!).
> > +        
> > +        Also removes the localArgumentsRegister local variable in BytecodeGenerator's
> > +        constructor. It's not used.
> > +
> > +        * bytecompiler/BytecodeGenerator.cpp:
> > +        (JSC::BytecodeGenerator::BytecodeGenerator):
> > +        (JSC::BytecodeGenerator::preserveLastVar): Deleted.
> > +        * bytecompiler/BytecodeGenerator.h:
> > +        (JSC::BytecodeGenerator::addVar):
> > +
> 
> Leftover edit that should have been removed?

Yup, I removed it locally.

> 
> > Source/JavaScriptCore/bytecompiler/RegisterID.h:75
> > -            ASSERT(!m_refCount);
> >  #ifndef NDEBUG
> >              m_didSetIndex = true;
> >  #endif
> 
> I think the main reason for the ASSERT(!m_refCount) is to ensure that the
> index is only set once before use.  Though the previous implementation
> allows us to “change our minds” and set the index to something else (which I
> don’t think is likely to happen) as long as we haven’t started using the
> RegisterID yet, I think the real bug it’s trying to watch out for is that we
> don’t use the RegisterID’s index in one place and then change it before
> using it in another (which is also unlikely to happen but if it does, it can
> cause havoc).
> 
> How about you replace this assert with ASSERT(!m_didSetIndex) in the #ifndef
> NDEBUG section instead?  Would that work?

But this does get called when m_didSetIndex is true.
Comment 11 Mark Lam 2015-02-04 09:43:29 PST
Comment on attachment 246035 [details]
the patch

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

r=me with ChangeLog fix.

>>> Source/JavaScriptCore/bytecompiler/RegisterID.h:75
>>>  #endif
>> 
>> I think the main reason for the ASSERT(!m_refCount) is to ensure that the index is only set once before use.  Though the previous implementation allows us to “change our minds” and set the index to something else (which I don’t think is likely to happen) as long as we haven’t started using the RegisterID yet, I think the real bug it’s trying to watch out for is that we don’t use the RegisterID’s index in one place and then change it before using it in another (which is also unlikely to happen but if it does, it can cause havoc).
>> 
>> How about you replace this assert with ASSERT(!m_didSetIndex) in the #ifndef NDEBUG section instead?  Would that work?
> 
> But this does get called when m_didSetIndex is true.

OK.  For Filip explained offline that for a scenario like:  function(a) { var a; }, the var a overrides argument a.  As such, the index for a’s RegisterID will be changed to match that of the argument’s.  Hence, m_didSetIndex is already true there.
Comment 12 Mark Lam 2015-02-04 09:44:27 PST
(In reply to comment #11)
> OK.  For Filip explained offline that ...

I meant: For the record, Filip explained ...

Ahh typos.
Comment 13 Filip Pizlo 2015-02-06 08:05:04 PST
Landed in http://trac.webkit.org/changeset/179746