Closed Bug 1278303 Opened 8 years ago Closed 8 years ago

Make it possible to use fallible TempAllocator with MIR Instructions.

Categories

(Core :: JavaScript Engine: JIT, defect, P5)

defect

Tracking

()

RESOLVED FIXED
mozilla50
Tracking Status
firefox49 --- wontfix
firefox-esr45 --- fixed
firefox50 --- fixed
firefox51 --- fixed
firefox52 --- fixed

People

(Reporter: nbp, Assigned: nbp)

References

Details

Attachments

(4 files)

The goal of this bug is to pave the way towards idiomatic OOM handling, which means that any call to a fallible allocator should be syntactically different than a call to an infallible allocator.  Thus, a reviewer can catch a mistake without reading extra context, and have the type of the arguments enforced by the type system.

Thus, if the ::New call is fallible, then this should be mirrored at the caller level.

  MFoo* f = MFoo::New(alloc.fallible(), a, b);
  if (!f)
      return false;

  MQux* q = MQux::New(alloc, a, b);

For convenience, any infallible allocation can also be allocated with the fallible version of the allocator, which is equivalent of folding the ensureBallast call into the instruction allocation.
This patch ensures that we have to use MFoo::New or any other member to
allocate MFoo objects.

Unfortunately, I do not see a proper way to handle fallible allocations of
the init functions, nor to expose both arguments of the init function and
the constructor argument without adding too much of a burden.  So, let's at
least ensure that we only support one way of allocating MIR instructions.
Attachment #8760354 - Flags: review?(jdemooij)
This patch adds a new macro used to introduced the New members of MIR
instructions.  These macro are used to define an infallible New allocator
member, and a fallible New allocator members.

This patch also replaces redundant lines, when a trivial New function exist
without any overloaded definition.
Comment on attachment 8760354 [details] [diff] [review]
part 1 - Prevent uses of TempObject new operator on MIR Instructions.

Review of attachment 8760354 [details] [diff] [review]:
-----------------------------------------------------------------

Nice

::: js/src/jit/MIR.h
@@ +1021,5 @@
>  
> +  protected:
> +    // All MInstructions are using the "MFoo::New(alloc)" notation instead of
> +    // the TempObject new operator. This code redefine the new operator as
> +    // protected, and delegate to the TempObject new operator. Thus, the

Nit: s/redefine/redefines/, s/delegate/delegates/
Attachment #8760354 - Flags: review?(jdemooij) → review+
Attachment #8760357 - Flags: review?(jdemooij)
While I was replacing redundant lines with macros, I thought that I could go
a bit futher ...

Thus, here is another simple patch which adds a macro to define all the
getOperands accessors of MIR Instructions.

Note, this new syntax is also quite helpful to easily catch copy&pasta
errors (as highlighted by the upcoming part 4)
Attachment #8760825 - Flags: review?(jdemooij)
Comment on attachment 8760357 [details] [diff] [review]
part 2 - Add MInstruction::New(TempAllocator::Fallible, ...) overload to all trivial MIR Instructions.

Review of attachment 8760357 [details] [diff] [review]:
-----------------------------------------------------------------

Nice!

::: js/src/jit/MIR.h
@@ +5130,5 @@
>  class MToFloat32
>    : public MToFPInstruction
>  {
>    protected:
> +    MToFloat32(MDefinition* def, ConversionKind conversion = NonStringPrimitives)

Nit: this now needs `explicit`

@@ +5406,5 @@
>  {
>      bool canBeNegativeZero_;
>      MacroAssembler::IntConversionInputKind conversion_;
>  
> +    MToInt32(MDefinition* def, MacroAssembler::IntConversionInputKind conversion =

And here.
Attachment #8760357 - Flags: review?(jdemooij) → review+
Comment on attachment 8760825 [details] [diff] [review]
part 3 - Use a macro to define a list of getOperand accessors.

Review of attachment 8760825 [details] [diff] [review]:
-----------------------------------------------------------------

Cool.

::: js/src/jit/MIR.h
@@ +1122,5 @@
>  
> +
> +// These macros are used as a syntactic sugar for writting getOperand
> +// accessors. They are meant to be used in the body of MIR Instructions as
> +// follow:

Nit: s/follow/follows/
Attachment #8760825 - Flags: review?(jdemooij) → review+
Comment on attachment 8760825 [details] [diff] [review]
part 3 - Use a macro to define a list of getOperand accessors.

Review of attachment 8760825 [details] [diff] [review]:
-----------------------------------------------------------------

(drive by nit)

::: js/src/jit/MIR.h
@@ +7504,5 @@
>  
>    public:
>      INSTRUCTION_HEADER(LexicalCheck)
>      TRIVIAL_NEW_WRAPPERS
> +    NAMED_OPERANDS((0, input))

Actually this could be removed: MLexicalCheck is a MUnaryInstruction, which already defines input() as getOperand(0).
Attachment #8760826 - Flags: review?(efaustbmo)
Status: NEW → ASSIGNED
Keywords: leave-open
Attachment #8760826 - Flags: review?(efaustbmo) → review+
Pushed by npierron@mozilla.com:
https://hg.mozilla.org/integration/mozilla-inbound/rev/74d0a284f6ff
part 1 - Prevent uses of TempObject new operator on MIR Instructions. r=jandem
https://hg.mozilla.org/integration/mozilla-inbound/rev/c255a40804be
part 2 - Add MInstruction::New(TempAllocator::Fallible, ...) overload to all trivial MIR Instructions. r=jandem
https://hg.mozilla.org/integration/mozilla-inbound/rev/bf9adef81e8d
part 3 - Use a macro to define a list of getOperand accessors. r=jandem
https://hg.mozilla.org/integration/mozilla-inbound/rev/09359e9505b1
part 4 - Fix correctness issue of MCreateThis new-target operand index. r=efaust
Pushed by npierron@mozilla.com:
https://hg.mozilla.org/integration/mozilla-inbound/rev/9ec710e102b1
part 1 - Prevent uses of TempObject new operator on MIR Instructions. r=jandem
https://hg.mozilla.org/integration/mozilla-inbound/rev/b2d1cf0313a3
part 2 - Add MInstruction::New(TempAllocator::Fallible, ...) overload to all trivial MIR Instructions. r=jandem
https://hg.mozilla.org/integration/mozilla-inbound/rev/e42076de2370
part 3 - Use a macro to define a list of getOperand accessors. r=jandem
https://hg.mozilla.org/integration/mozilla-inbound/rev/fd1f56dfff60
part 4 - Fix correctness issue of MCreateThis new-target operand index. r=efaust
Flags: needinfo?(nicolas.b.pierron)
Depends on: 1284491
Status: ASSIGNED → RESOLVED
Closed: 8 years ago
Keywords: leave-open
Priority: -- → P5
Resolution: --- → FIXED
Target Milestone: --- → mozilla50
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: