I have a function that's supposed to round X to the nearest multiple of A.
Here's the code in JavaScript:
var round = function (x, a) {
"use strict";
if (typeof a === "undefined") {
return Math.round(x);
}
var half = a / 2,
sign = this.sign(x),
absolute = Math.abs(x),
factor = absolute / a|0,
remainder = absolute % a;
return sign * a * (factor + (remainder < half ? 0 : 1));
};
When I do a --trace_deopt --code_comments
in Chrome's V8 I get this message in the logs:
[deoptimizing (DEOPT eager): begin 0x988464b35b1 round (opt #13) @13, FP to SP delta: 24]
591 ;;; deoptimize at <0:70499> tagged-to-i: not a heap number
592 translating round => node=67, height=48
593 0x7fff571f2ed0: [top + 96] <- 0x11b5fb674cf9 ; rdi 0x11b5fb674cf9 <JS Object>
594 0x7fff571f2ec8: [top + 88] <- 0x2459b11f1d89 ; r8 0x2459b11f1d89 <Number: 45>
595 0x7fff571f2ec0: [top + 80] <- 0x2d00000000 ; [sp + 40] 45
596 0x7fff571f2eb8: [top + 72] <- 0xbef1cdacfe5 ; caller's pc
597 0x7fff571f2eb0: [top + 64] <- 0x7fff571f3090 ; caller's fp
598 0x7fff571f2ea8: [top + 56] <- 0x11b5fb674d61 ; [sp + 0] 0x11b5fb674d61 <FixedArray[133]>
599 0x7fff571f2ea8: [top + 56] <- 0x11b5fb674d61; context
600 0x7fff571f2ea0: [top + 48] <- 0x988464b35b1; function
601 0x7fff571f2e98: [top + 40] <- 22 ; rcx (smi)
602 0x7fff571f2e90: [top + 32] <- 0x34565d404121 <undefined> ; literal
603 0x7fff571f2e88: [top + 24] <- 0x34565d404121 <undefined> ; literal
604 0x7fff571f2e80: [top + 16] <- 0x34565d404121 <undefined> ; literal
605 0x7fff571f2e78: [top + 8] <- 0x34565d404121 <undefined> ; literal
606 0x7fff571f2e70: [top + 0] <- 1 ; rsi (smi)
607 [deoptimizing (eager): end 0x988464b35b1 round @13 => node=67, pc=0xbef1cd97be6, state=TOS_REG, alignment=no padding, took 0.084 ms]
608 [removing optimized code for: round]
609 [evicting entry from optimizing code map (notify deoptimized) for 0x34565d492be1 <SharedFunctionInfo round>]
Does anyone know what tagged-to-i: not a heap number
mean?
Thanks in advance!
tagged-to-i: not a heap number
essentially means an V8 is attempting to convert a value that is not a primitive number to an integer.
Originally I thought that the first argument (x
) from the translation frame is a Number
object because it is printed as <Number: 45>
, but as it turns out V8 prints HeapNumber
objects this way[1]. Under normal circumstances an attempt to unbox a heap number should not cause not a heap number deoptimization. So it's either a deopt due to different variable - or deoptimization reason is not accurate.
;; this
0x7fff571f2ed0: [top + 96] <- 0x11b5fb674cf9 ; rdi 0x11b5fb674cf9 <JS Object>
;; x
0x7fff571f2ec8: [top + 88] <- 0x2459b11f1d89 ; r8 0x2459b11f1d89 <Number: 45>
;; a
0x7fff571f2ec0: [top + 80] <- 0x2d00000000 ; [sp + 40] 45