问题描述
我正在提取 Node.js 生成的字节码,如下所示:'node --print-bytecode ~/example.js'.输出看起来与 d8 的输出几乎相同.但是,有一些细微的差异.以这个函数为例:
I'm extracting the bytecode generated by Node.js like so: 'node --print-bytecode ~/example.js'. The output looks almost identical as the output of d8. However, there are a couple of minor differences.Take for example this function:
`[generated bytecode for function: emitPromiseRejectionWarnings]
Parameter count 1
Frame size 120
2658 E> 0x20948dedb3ba @ 0 : a0 StackCheck
2702 S> 0x20948dedb3bb @ 1 : 1b 08 LdaImmutableCurrentContextSlot [8]
0x20948dedb3bd @ 3 : a5 00 ThrowReferenceErrorIfHole [0]
0x20948dedb3bf @ 5 : 26 f1 Star r10
2695 E> 0x20948dedb3c1 @ 7 : 28 f1 01 00 LdaNamedProperty r10, [1], [0]
0x20948dedb3c5 @ 11 : 26 f1 Star r10
0x20948dedb3c7 @ 13 : 0b LdaZero
2702 E> 0x20948dedb3c8 @ 14 : 67 f1 02 TestGreaterThan r10, [2]
0x20948dedb3cb @ 17 : 94 5d JumpIfFalse [93] (0x20948dedb428 @ 110)
2665 E> 0x20948dedb3cd @ 19 : a0 StackCheck
0x20948dedb3ce @ 20 : 1b 08 LdaImmutableCurrentContextSlot [8]
2742 E> 0x20948dedb3d0 @ 22 : a5 00 ThrowReferenceErrorIfHole [0]
0x20948dedb3d2 @ 24 : 26 f0 Star r11
2765 E> 0x20948dedb3d4 @ 26 : 28 f0 02 03 LdaNamedProperty r11, [2], [3]
0x20948dedb3d8 @ 30 : 26 f1 Star r10
2765 E> 0x20948dedb3da @ 32 : 56 f1 f0 05 CallProperty0 r10, r11, [5]
0x20948dedb3de @ 36 : 26 f5 Star r6
0x20948dedb3e0 @ 38 : 97 06 JumpIfUndefined [6] (0x20948dedb3e6 @ 44)
0x20948dedb3e2 @ 40 : 25 f5 Ldar r6
0x20948dedb3e4 @ 42 : 96 10 JumpIfNotNull [16] (0x20948dedb3f4 @ 58)
0x20948dedb3e6 @ 44 : 0c 4d LdaSmi [77]
0x20948dedb3e8 @ 46 : 26 f1 Star r10
0x20948dedb3ea @ 48 : 12 03 LdaConstant [3]
0x20948dedb3ec @ 50 : 26 f0 Star r11
0x20948dedb3ee @ 52 : 5e c1 00 f1 02 CallRuntime [NewTypeError], r10-r11
2721 E> 0x20948dedb3f3 @ 57 : a2 Throw
2742 S> 0x20948dedb3f4 @ 58 : 28 f5 03 07 LdaNamedProperty r6, [3], [7]
0x20948dedb3f8 @ 62 : 26 f7 Star r4
2742 S> 0x20948dedb3fa @ 64 : 28 f5 04 09 LdaNamedProperty r6, [4], [9]
0x20948dedb3fe @ 68 : 26 f6 Star r5
2778 S> 0x20948dedb400 @ 70 : 1b 04 LdaImmutableCurrentContextSlot [4]
0x20948dedb402 @ 72 : 26 f0 Star r11
2791 E> 0x20948dedb404 @ 74 : 28 f0 05 0b LdaNamedProperty r11, [5], [11]
0x20948dedb408 @ 78 : 26 f1 Star r10
0x20948dedb40a @ 80 : 12 06 LdaConstant [6]
0x20948dedb40c @ 82 : 26 ef Star r12
2791 E> 0x20948dedb40e @ 84 : 58 f1 f0 ef f7 0d CallProperty2 r10, r11, r12, r4, [13]
0x20948dedb414 @ 90 : 91 11 JumpIfToBooleanTrue [17] (0x20948dedb425 @ 107)
2834 S> 0x20948dedb416 @ 92 : 1b 04 LdaImmutableCurrentContextSlot [4]
0x20948dedb418 @ 94 : 26 f0 Star r11
2842 E> 0x20948dedb41a @ 96 : 28 f0 07 0f LdaNamedProperty r11, [7], [15]
0x20948dedb41e @ 100 : 26 f1 Star r10
2842 E> 0x20948dedb420 @ 102 : 57 f1 f0 f6 11 CallProperty1 r10, r11, r5, [17]
0x20948dedb425 @ 107 : 85 6a 00 JumpLoop [106], [0] (0x20948dedb3bb @ 1)
2896 S> 0x20948dedb428 @ 110 : 11 LdaFalse
0x20948dedb429 @ 111 : 26 f4 Star r7
2915 S> 0x20948dedb42b @ 113 : 1b 07 LdaImmutableCurrentContextSlot [7]
0x20948dedb42d @ 115 : a5 08 ThrowReferenceErrorIfHole [8]
0x20948dedb42f @ 117 : 26 f1 Star r10
2942 E> 0x20948dedb431 @ 119 : 28 f1 01 13 LdaNamedProperty r10, [1], [19]
0x20948dedb435 @ 123 : 26 f3 Star r8
2962 S> 0x20948dedb437 @ 125 : 25 f3 Ldar r8
0x20948dedb439 @ 127 : 73 15 ToNumeric [21]
0x20948dedb43b @ 129 : 26 f1 Star r10
0x20948dedb43d @ 131 : 4b 15 Dec [21]
0x20948dedb43f @ 133 : 26 f3 Star r8
0x20948dedb441 @ 135 : 25 f1 Ldar r10
2962 E> 0x20948dedb443 @ 137 : 92 80 JumpIfToBooleanFalse [128] (0x20948dedb4c3 @ 265)
2952 E> 0x20948dedb445 @ 139 : a0 StackCheck
2988 S> 0x20948dedb446 @ 140 : 1b 07 LdaImmutableCurrentContextSlot [7]
0x20948dedb448 @ 142 : a5 08 ThrowReferenceErrorIfHole [8]
0x20948dedb44a @ 144 : 26 f0 Star r11
3015 E> 0x20948dedb44c @ 146 : 28 f0 02 16 LdaNamedProperty r11, [2], [22]
0x20948dedb450 @ 150 : 26 f1 Star r10
3015 E> 0x20948dedb452 @ 152 : 56 f1 f0 18 CallProperty0 r10, r11, [24]
0x20948dedb456 @ 156 : 26 f9 Star r2
3048 S> 0x20948dedb458 @ 158 : 1b 06 LdaImmutableCurrentContextSlot [6]
0x20948dedb45a @ 160 : a5 09 ThrowReferenceErrorIfHole [9]
0x20948dedb45c @ 162 : 26 f0 Star r11
3071 E> 0x20948dedb45e @ 164 : 28 f0 0a 1a LdaNamedProperty r11, [10], [26]
0x20948dedb462 @ 168 : 26 f1 Star r10
3071 E> 0x20948dedb464 @ 170 : 57 f1 f0 f9 1c CallProperty1 r10, r11, r2, [28]
0x20948dedb469 @ 175 : 26 f8 Star r3
3089 S> 0x20948dedb46b @ 177 : 97 55 JumpIfUndefined [85] (0x20948dedb4c0 @ 262)
3128 S> 0x20948dedb46d @ 179 : 10 LdaTrue
3147 E> 0x20948dedb46e @ 180 : 2c f8 0b 1e StaNamedProperty r3, [11], [30]
0x20948dedb472 @ 184 : 27 f8 f2 Mov r3, r9
0x20948dedb475 @ 187 : 25 f2 Ldar r9
0x20948dedb477 @ 189 : 97 06 JumpIfUndefined [6] (0x20948dedb47d @ 195)
0x20948dedb479 @ 191 : 25 f2 Ldar r9
0x20948dedb47b @ 193 : 96 10 JumpIfNotNull [16] (0x20948dedb48b @ 209)
0x20948dedb47d @ 195 : 0c 4d LdaSmi [77]
0x20948dedb47f @ 197 : 26 f1 Star r10
0x20948dedb481 @ 199 : 12 0c LdaConstant [12]
0x20948dedb483 @ 201 : 26 f0 Star r11
3185 E> 0x20948dedb485 @ 203 : 5e c1 00 f1 02 CallRuntime [NewTypeError], r10-r11
3169 E> 0x20948dedb48a @ 208 : a2 Throw
3185 S> 0x20948dedb48b @ 209 : 28 f2 0c 20 LdaNamedProperty r9, [12], [32]
0x20948dedb48f @ 213 : 26 fb Star r0
3185 S> 0x20948dedb491 @ 215 : 28 f2 0d 22 LdaNamedProperty r9, [13], [34]
0x20948dedb495 @ 219 : 26 fa Star r1
3204 S> 0x20948dedb497 @ 221 : 1b 04 LdaImmutableCurrentContextSlot [4]
0x20948dedb499 @ 223 : 26 f0 Star r11
3217 E> 0x20948dedb49b @ 225 : 28 f0 05 24 LdaNamedProperty r11, [5], [36]
0x20948dedb49f @ 229 : 26 f1 Star r10
0x20948dedb4a1 @ 231 : 12 0e LdaConstant [14]
0x20948dedb4a3 @ 233 : 26 ef Star r12
0x20948dedb4a5 @ 235 : 27 fb ee Mov r0, r13
0x20948dedb4a8 @ 238 : 27 f9 ed Mov r2, r14
3217 E> 0x20948dedb4ab @ 241 : 55 f1 f0 04 26 CallProperty r10, r11-r14, [38]
0x20948dedb4b0 @ 246 : 91 0d JumpIfToBooleanTrue [13] (0x20948dedb4bd @ 259)
3272 S> 0x20948dedb4b2 @ 248 : 1b 0d LdaImmutableCurrentContextSlot [13]
0x20948dedb4b4 @ 250 : 26 f1 Star r10
3272 E> 0x20948dedb4b6 @ 252 : 5c f1 fa fb 28 CallUndefinedReceiver2 r10, r1, r0, [40]
0x20948dedb4bb @ 257 : 86 05 Jump [5] (0x20948dedb4c0 @ 262)
3321 S> 0x20948dedb4bd @ 259 : 10 LdaTrue
0x20948dedb4be @ 260 : 26 f4 Star r7
0x20948dedb4c0 @ 262 : 85 89 00 JumpLoop [137], [0] (0x20948dedb437 @ 125)
3362 S> 0x20948dedb4c3 @ 265 : 25 f4 Ldar r7
0x20948dedb4c5 @ 267 : 91 13 JumpIfToBooleanTrue [19] (0x20948dedb4d8 @ 286)
0x20948dedb4c7 @ 269 : 1b 07 LdaImmutableCurrentContextSlot [7]
3385 E> 0x20948dedb4c9 @ 271 : a5 08 ThrowReferenceErrorIfHole [8]
0x20948dedb4cb @ 273 : 26 f1 Star r10
3412 E> 0x20948dedb4cd @ 275 : 28 f1 01 2a LdaNamedProperty r10, [1], [42]
0x20948dedb4d1 @ 279 : 26 f1 Star r10
0x20948dedb4d3 @ 281 : 0b LdaZero
3419 E> 0x20948dedb4d4 @ 282 : 65 f1 2c TestEqualStrict r10, [44]
0x20948dedb4d7 @ 285 : 4f LogicalNot
3425 S> 0x20948dedb4d8 @ 286 : a4 Return
Constant pool (size = 15)
Handler Table (size = 0)
`
在 d8 的输出中,访问了一个常量表,例如根据 LdaConstant 指令,列在常量池"下.Node.js 的输出只包含这个表的大小,而不包含内容.有没有办法也可以输出这些信息?
In d8's output, a constant table accessed e.g. by the LdaConstant instruction, was listed under "Constant pool". Node.js' output only contains the size of this table, but not the content. Is there a way to enable outputting this information also?
谢谢.
推荐答案
看源码:
os << "Constant pool (size = " << constant_pool()->length() << ")\n";
#ifdef OBJECT_PRINT
if (constant_pool()->length() > 0) {
constant_pool()->Print();
}
#endif
表明如果要打印常量池条目,则必须使用 OBJECT_PRINT 进行编译.在独立的 V8 中,您可以通过将 v8_enable_object_print = true
添加到您的 args.gn
来实现.我不知道如何在 Node.js 中做到这一点.V8 和 Node 的调试版本应该默认启用它.
reveals that you'll have to compile with OBJECT_PRINT if you want to print the constant pool entries. In standalone V8, you do that by adding v8_enable_object_print = true
to your args.gn
. I don't know how to do it in Node. Debug builds of both V8 and Node should enable it by default.
这篇关于Node.js 字节码常量池输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!