Bug 79198
Summary: | Refactor op_new_array | ||
---|---|---|---|
Product: | WebKit | Reporter: | Mark Hahnenberg <mhahnenberg> |
Component: | JavaScriptCore | Assignee: | Benjamin Poulain <benjamin> |
Status: | NEW | ||
Severity: | Normal | CC: | benjamin |
Priority: | P2 | ||
Version: | 528+ (Nightly build) | ||
Hardware: | Unspecified | ||
OS: | Unspecified | ||
Bug Depends on: | 79199 | ||
Bug Blocks: |
Mark Hahnenberg
Imagine we have the following:
var arr = [a + b, c * d, e, f()];
Currently, we emit code that does the following:
calculate a + b and store in a temp
calculate c * d and store in another temp
calculate e and store in another temp
call f, and store the result in another temp
allocate a new array and store all of the temps above into their correct slots in the array
Sometimes it's even worse and we copy the temps to a temporary buffer and then copy them from that buffer to the array! All the while, these temporary variables are live, creating tremendous amounts of register pressure.
We can improve this situation significantly by splitting op_new_array into three new op codes that handle each of the individual semantics of op_new_array: op_alloc_array, op_put_array, and op_bless_array.
-op_alloc_array allocates the GC cell and the backing store for the array. It can have a fast path for both of these, but drop out to a C++ call if they require anything fancy.
-op_put_array puts a value directly into the array without doing any of the extra logic that is normally associated with a put by index. Each op_put_array follows the code to calculate the value it needs, thus keeping the liveness ranges of all temporaries used to calculate the value to a minimum.
-op_bless_array indicates that the initialization of the array is complete
In order for this scheme to work, we must make it possible for garbage collection to run while the array is still being allocated. This means that the cell for the array should be fully initialized and that the GC must be able to handle array backing stores that aren't yet fully initialized. One easy way to fix the issue with uninitialized backing stores would be to zero out all CopiedBlocks when we initialize them.
Attachments | ||
---|---|---|
Add attachment proposed patch, testcase, etc. |
Mark Hahnenberg
One thing that I realized while working on this patch is that having to grab the ArrayStorage from the JSArray for each op_put_array is a big waste of time, so I revised the opcodes so that I can give a raw pointer for the ArrayStorage to each op_put_array. I just thought I'd note that here for future reference.