Closed Bug 977126 Opened 11 years ago Closed 11 years ago

Inline SetTypedObjectOffset() in ion

Categories

(Core :: JavaScript Engine: JIT, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla31

People

(Reporter: nmatsakis, Assigned: nmatsakis)

References

Details

(Keywords: perf, Whiteboard: [js:p2])

Attachments

(3 files, 4 obsolete files)

The intrinsic SetTypedObjectOffset() is used in self-hosted code in tight loops and should be inlined. It corresponds to some pointer bumps, very simple.
Assignee: nobody → lth
Blocks: PJS
The current C definition for SetTypedObjectOffset() reads the base pointer from the buffer. This is unnecessary and is not how the inlined code should work. We should apply this patch and then translate it: diff --git a/js/src/builtin/TypedObject.cpp b/js/src/builtin/TypedObject.cpp index 7898c12..23b1abb 100644 --- a/js/src/builtin/TypedObject.cpp +++ b/js/src/builtin/TypedObject.cpp @@ -2725,11 +2725,14 @@ js::SetTypedObjectOffset(ThreadSafeContext *, unsigned argc, Value *vp) JS_ASSERT(args[1].isInt32()); TypedObject &typedObj = args[0].toObject().as<TypedObject>(); - int32_t offset = args[1].toInt32(); + int32_t newOffset = args[1].toInt32(); JS_ASSERT(typedObj.typedMem() != nullptr); // must be attached already - typedObj.setPrivate(typedObj.owner().dataPointer() + offset); + int32_t oldOffset = typedObj.offset(); + uint32_t *basePointer = typedObj.dataPointer() - oldOffset; + JS_ASSERT(basePointer == typedObj.owner().dataPointer()); + typedObj.setPrivate(basePointer + offset); typedObj.setReservedSlot(JS_TYPEDOBJ_SLOT_BYTEOFFSET, Int32Value(offset)); return true; }
Assignee: lth → lhansen
Keywords: perf
OS: Linux → All
Hardware: x86 → All
Whiteboard: [js:p2]
Assignee: lhansen → nmatsakis
Attached patch Bug977126.diff (obsolete) — Splinter Review
Attachment #8393615 - Flags: review?(shu)
Comment on attachment 8393615 [details] [diff] [review] Bug977126.diff Cancelling review; I saw some test failures I want to track down first.
Attachment #8393615 - Flags: review?(shu)
Attached patch Bug977126.diff (obsolete) — Splinter Review
Better version of the patch that actually *passes* tests.
Attachment #8393615 - Attachment is obsolete: true
Attachment #8393725 - Flags: review?(shu)
Comment on attachment 8393725 [details] [diff] [review] Bug977126.diff Argh. And again further testing is revealing problems. Can't win with this patch. :)
Attachment #8393725 - Flags: review?(shu)
Attachment #8394139 - Flags: review?(mrosenberg)
Attached patch Bug977126-Part2.diff (obsolete) — Splinter Review
Attachment #8394140 - Flags: review?(jdemooij)
Attachment #8393725 - Attachment is obsolete: true
Attachment #8394141 - Flags: review?(shu)
OK, this version seems to actually work, though I haven't tested on ARM.
Attached patch Bug977126-Part2.diff (obsolete) — Splinter Review
That was an obsolete patch, sorry. Here is the updated one.
Attachment #8394140 - Attachment is obsolete: true
Attachment #8394140 - Flags: review?(jdemooij)
Attachment #8394214 - Flags: review?(jdemooij)
And...somehow I uploaded that stale patch AGAIN. Sorry.
Attachment #8394214 - Attachment is obsolete: true
Attachment #8394214 - Flags: review?(jdemooij)
Attachment #8394247 - Flags: review?(jdemooij)
Comment on attachment 8394247 [details] [diff] [review] Bug977126-Part2.diff Review of attachment 8394247 [details] [diff] [review]: ----------------------------------------------------------------- Looks good, r=me with nit below addressed. ::: js/src/jit/x64/Assembler-x64.h @@ +448,5 @@ > default: > MOZ_ASSUME_UNREACHABLE("unexpected operand kind"); > } > } > + void subq(const Register &src, const Address &dest) { Most Assembler methods take an Operand instead of Address, can you do that here too? Just add a switch that only handles the case we're interested in and a default with MOZ_ASSUME_UNREACHABLE. subPtr can then do Operand(dest), that also matches what the x86 version does.
Attachment #8394247 - Flags: review?(jdemooij) → review+
Comment on attachment 8394141 [details] [diff] [review] Bug977126-Part3.diff Review of attachment 8394141 [details] [diff] [review]: ----------------------------------------------------------------- Looks good to me. ::: js/src/builtin/TypedObject.h @@ +567,5 @@ > // by the JIT. > static size_t dataOffset(); > > + // Offset of the byte offset slot. > + static size_t byteOffsetOffset(); In general I believe these are named like |offsetOfByteOffset|. I see a lot of other methods in TO already named |xOffset| instead of |offsetOfX|, maybe a mass rename if it's not too much of a bother. ::: js/src/jit/CodeGenerator.cpp @@ +4051,5 @@ > + // but to make that work out we need the option to subtract from a > + // memory location in place. X86 can do this but ARM cannot, and > + // masm doesn't seem to have the relevant helper methods defined > + // as of the time of this writing (and I am too lazy^H^H^H^Hwise > + // to do it myself). Clean up comment to be less colorful. :) ::: js/src/jit/MCallOptimize.cpp @@ +1639,5 @@ > + case types::TemporaryTypeSet::ForAllResult::ALL_FALSE: > + case types::TemporaryTypeSet::ForAllResult::EMPTY: > + case types::TemporaryTypeSet::ForAllResult::MIXED: > + return InliningStatus_NotInlined; > + break; Superfluous break ::: js/src/jit/MIR.h @@ +5620,5 @@ > + : MBinaryInstruction(object, offset) > + { > + JS_ASSERT(object->type() == MIRType_Object); > + JS_ASSERT(offset->type() == MIRType_Int32); > + setResultType(MIRType_Undefined); This should be MIRType_None. In grepping around I also saw MAbortPar's result type being set as MIRType_UNdefined as well. Could you also change that to MIRType_None too?
Attachment #8394141 - Flags: review?(shu) → review+
Comment on attachment 8394139 [details] [diff] [review] Bug977126-Part1.diff Review of attachment 8394139 [details] [diff] [review]: ----------------------------------------------------------------- ::: js/src/jit/arm/MacroAssembler-arm.cpp @@ +2445,5 @@ > > void > +MacroAssemblerARMCompat::subPtr(const Register &src, const Address &dest) > +{ > + loadPtr(dest, ScratchRegister); If dest is going to be complex, (e.g. [r0, 5000], which will require multiple instructions), its value should probably be cached in the second scratch register.
Attachment #8394139 - Flags: review?(mrosenberg) → review+
(In reply to Marty Rosenberg [:mjrosenb] from comment #14) > If dest is going to be complex, (e.g. [r0, 5000], which will require > multiple instructions), its value should probably be cached in the second > scratch register. I don't know what the notation [r0, 5000] means, but the Address will typically be "reg+offset". Can you point me at an example that makes use of this second scratch register to do such caching? I didn't see one when poking around just now.
Flags: needinfo?(mrosenberg)
Indeed, my apologies! I overlooked that.
Flags: needinfo?(nmatsakis)
Try run with fix: https://tbpl.mozilla.org/?tree=Try&rev=527c8cb306ba Some reds, but everything looks independent of this patch. I retriggered a few runs just to check.
(In reply to Niko Matsakis [:nmatsakis] from comment #15) > (In reply to Marty Rosenberg [:mjrosenb] from comment #14) > > If dest is going to be complex, (e.g. [r0, 5000], which will require > > multiple instructions), its value should probably be cached in the second > > scratch register. > > I don't know what the notation [r0, 5000] means, but the Address will > typically be "reg+offset". Can you point me at an example that makes use of > this second scratch register to do such caching? I didn't see one when > poking around just now. The ARM instruction can only encode a small offset for the reg+offset addressing mode, so if the offset is large then it will need to be firstly loaded into a register. Marty suggests using the secondScratchReg which defaults to lr. See other uses in the source. Marty has a patch pending to detect overlapping uses of the scratch register.
The offset will always be fixed and small, in the current use at least.
I did another try run and don't see any windows mochitest bustage: https://tbpl.mozilla.org/?tree=Try&rev=82fd9e987cae
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: