NEW 79198
Refactor op_new_array
https://bugs.webkit.org/show_bug.cgi?id=79198
Summary Refactor op_new_array
Mark Hahnenberg
Reported 2012-02-21 22:38:02 PST
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
Mark Hahnenberg
Comment 1 2012-04-23 10:37:46 PDT
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.
Note You need to log in before you can comment on or make changes to this bug.