[JSC] `op_call_varargs_with_spread` new opcode
Component: JSC | c3b920b
JSTests/stress/varargs-spread-fusion-checkpoint-length-overflow.js
f(a, ...b, c)처럼 spread가 섞인 호출은 이전에는 op_new_array_with_spread로 컴파일되었습니다. 이 과정에서 임시 array가 생성되고, op_call_varargs가 이를 다시 callee frame으로 복사했습니다. 반면 f(...x)처럼 spread 하나만 있는 호출은 spread의 butterfly를 그대로 전달하므로 이 경로를 거치지 않았습니다.
op_call_varargs는 checkpoint 기반으로 동작합니다. 즉 argument 개수를 계산한 뒤 frame을 채우기 전의 시점에서 OSR exit가 발생할 수 있습니다. 한편 DFG의 arguments elimination phase는 NewArrayWithSpread를 제거할 수 있습니다. 이때 각 spread operand를 forwarded rest parameter, constant butterfly, materialized array 중 하나로 추적합니다.
새 bytecode는 interleave된 argv/argc와 spread bitVector를 받아 callee frame을 직접 구성합니다. 이 과정에서 op_call_varargs의 checkpoint 구조는 그대로 유지되었습니다. DFG에는 CallVarargsWithSpread, VarargsLengthWithSpread, LoadVarargsWithSpread node가 추가되었습니다. FTL lowering도 함께 구현되었고, 크기가 작고 hole이 없는 contiguous array를 위한 inline frame-setup fast path도 새로 도입되었습니다. 결과적으로 arguments elimination은 이제 spread operand를 하나씩 개별적으로 처리합니다.
Before: After:
f(a, ...b, c) f(a, ...b, c)
└─► NewArrayWithSpread └─► CallVarargsWithSpread(argv, argc, bits)
└─► temp heap array ├─► size frame from operands (ckpt)
└─► CallVarargs └─► copy operands into callee frame
└─► copy into frame (inline: small dense contiguous)
Significance
기존에는 FTL에서만 제거되던 일회성 array allocation이, 이제 LLInt, Baseline, DFG의 mixed spread 호출에서도 제거되었습니다. 동시에 모든 tier에서 varargs frame 구성 로직이 새로 구현되었습니다. 해당 영역은 역사적으로 JSC에서 버그가 가장 많이 발생해 온 곳 중 하나입니다.
Audit directions
Inline fast path는 butterfly slot을 argument slot으로 그대로 복사합니다. 따라서 이 경로의 진입 조건을 점검할 필요가 있습니다. indexing type 구분(Int32/Contiguous vs Double/ArrayStorage), hole 처리, length bounds, COW literal butterfly가 주요 대상입니다. 또한 check와 copy 사이에 shape이나 length가 바뀔 수 있는지도 확인해야 합니다. spread operand의 side effect, getter, iterator, array mutation이 그런 경로가 될 수 있습니다.
Checkpoint 측면에서는 세 요소가 live tmp와 operand에 대해 서로 일치하는지 검증해야 합니다. tmpLivenessForCheckpoint에 대한 bytecode liveness, OSR availability analysis, handleVarargsWithSpreadCheckpoint가 그 대상입니다. 여기에는 inlined call의 exit 경로(callerReturnPC, llint_slow_path_checkpoint_osr_exit_from_inlined_call)도 포함됩니다.
다수의 operand와 spread length를 합산하는 과정도 주의가 필요합니다. stack-limit check 이전에 argument count나 frame size가 overflow될 수 있기 때문입니다. 실제로 이를 겨냥한 전용 length-overflow test가 추가되었습니다. 공유 COW butterfly를 1024번 spread하여 2^32개 argument에 도달하는 테스트로, 이 문제가 이미 우려 대상이었음을 드러냅니다.
범위를 넓히면, 제거된 spread와 materialize된 spread가 섞이는 arguments elimination 경로도 살펴볼 필요가 있습니다. varargsSpreadScratchBufferSize, varargsSpreadForwardDescriptors, 그리고 length pass와 load pass 간의 일관성이 대상입니다. 세 신규 node의 abstract interpreter, clobberize, doesGC, mayExit, safeToExecute 항목도 점검해야 합니다. clobber set이나 GC flag가 잘못 지정되면, 해당 node를 사이에 둔 type confusion으로 이어지게 됩니다.
operand가 많은 호출에 대해서는 bitVector encoding도 stress test해 볼 필요가 있습니다. 현재 테스트는 10~20개 범위만 다루고 있습니다.
판별 단서: slow path가 수행할 수 있는 동작보다 clobberize 항목이 좁게 정의된 신규 DFG node.