Skip to content

Commit c7ca3fe

Browse files
authored
Don't serialize IC opcodes (bellard#334)
Translate IC opcodes to their non-IC variants before writing them out. Before this commit they were not byte-swapped properly, breaking the ability to load serialized bytecode containing ICs on systems with different endianness. Inline caches are recomputed as needed now. A pleasing side effect of this change is that serialized bytecode is, on average, a little smaller because fewer atoms are duplicated now.
1 parent f02ed18 commit c7ca3fe

File tree

7 files changed

+9667
-9761
lines changed

7 files changed

+9667
-9761
lines changed

gen/function_source.c

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
#include "quickjs-libc.h"
44

5-
const uint32_t qjsc_function_source_size = 393;
5+
const uint32_t qjsc_function_source_size = 384;
66

7-
const uint8_t qjsc_function_source[393] = {
8-
0x08, 0x06, 0x0c, 0x61, 0x63, 0x74, 0x75, 0x61,
7+
const uint8_t qjsc_function_source[384] = {
8+
0x09, 0x06, 0x0c, 0x61, 0x63, 0x74, 0x75, 0x61,
99
0x6c, 0x02, 0x66, 0x0c, 0x65, 0x78, 0x70, 0x65,
1010
0x63, 0x74, 0x14, 0x75, 0x73, 0x65, 0x20, 0x73,
1111
0x74, 0x72, 0x69, 0x63, 0x74, 0x34, 0x66, 0x75,
@@ -46,15 +46,13 @@ const uint8_t qjsc_function_source[393] = {
4646
0x0c, 0x06, 0x11, 0x18, 0x2a, 0x1c, 0x37, 0x41,
4747
0x21, 0x1c, 0x34, 0x18, 0x1b, 0x04, 0x26, 0x11,
4848
0x3f, 0x1d, 0x0c, 0x06, 0x11, 0x18, 0x2a, 0x1c,
49-
0x53, 0x41, 0x00, 0xff, 0x49, 0x43, 0x01, 0x6c,
50-
0x0c, 0x43, 0x02, 0x01, 0xae, 0x03, 0x00, 0x00,
51-
0x00, 0x01, 0x00, 0x00, 0x03, 0x00, 0xbb, 0x2a,
52-
0x28, 0xb6, 0x03, 0x03, 0x01, 0x04, 0x02, 0x1e,
53-
0x0c, 0x0e, 0x1a, 0x66, 0x75, 0x6e, 0x63, 0x74,
54-
0x69, 0x6f, 0x6e, 0x20, 0x66, 0x28, 0x29, 0x20,
55-
0x7b, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e,
56-
0x20, 0x34, 0x32, 0x20, 0x7d, 0xff, 0x49, 0x43,
57-
0x00,
49+
0x53, 0x41, 0x00, 0x0c, 0x43, 0x02, 0x01, 0xae,
50+
0x03, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x03,
51+
0x00, 0xbb, 0x2a, 0x28, 0xb6, 0x03, 0x03, 0x01,
52+
0x04, 0x02, 0x1e, 0x0c, 0x0e, 0x1a, 0x66, 0x75,
53+
0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x66,
54+
0x28, 0x29, 0x20, 0x7b, 0x20, 0x72, 0x65, 0x74,
55+
0x75, 0x72, 0x6e, 0x20, 0x34, 0x32, 0x20, 0x7d,
5856
};
5957

6058
static JSContext *JS_NewCustomContext(JSRuntime *rt)

gen/hello.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
#include "quickjs-libc.h"
44

5-
const uint32_t qjsc_hello_size = 95;
5+
const uint32_t qjsc_hello_size = 89;
66

7-
const uint8_t qjsc_hello[95] = {
8-
0x08, 0x04, 0x0e, 0x63, 0x6f, 0x6e, 0x73, 0x6f,
7+
const uint8_t qjsc_hello[89] = {
8+
0x09, 0x04, 0x0e, 0x63, 0x6f, 0x6e, 0x73, 0x6f,
99
0x6c, 0x65, 0x06, 0x6c, 0x6f, 0x67, 0x16, 0x48,
1010
0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x57, 0x6f, 0x72,
1111
0x6c, 0x64, 0x22, 0x65, 0x78, 0x61, 0x6d, 0x70,
@@ -16,7 +16,7 @@ const uint8_t qjsc_hello[95] = {
1616
0xd6, 0x00, 0x00, 0x00, 0x42, 0xd7, 0x00, 0x00,
1717
0x00, 0x04, 0xd8, 0x00, 0x00, 0x00, 0x24, 0x01,
1818
0x00, 0xcc, 0x28, 0xb2, 0x03, 0x01, 0x01, 0x00,
19-
0x00, 0xff, 0x49, 0x43, 0x01, 0xae, 0x03,
19+
0x00,
2020
};
2121

2222
static JSContext *JS_NewCustomContext(JSRuntime *rt)

gen/hello_module.c

Lines changed: 36 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
#include "quickjs-libc.h"
44

5-
const uint32_t qjsc_fib_module_size = 318;
5+
const uint32_t qjsc_fib_module_size = 310;
66

7-
const uint8_t qjsc_fib_module[318] = {
8-
0x08, 0x03, 0x2c, 0x65, 0x78, 0x61, 0x6d, 0x70,
7+
const uint8_t qjsc_fib_module[310] = {
8+
0x09, 0x03, 0x2c, 0x65, 0x78, 0x61, 0x6d, 0x70,
99
0x6c, 0x65, 0x73, 0x2f, 0x66, 0x69, 0x62, 0x5f,
1010
0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x2e, 0x6a,
1111
0x73, 0x06, 0x66, 0x69, 0x62, 0x02, 0x6e, 0x0d,
@@ -15,42 +15,41 @@ const uint8_t qjsc_fib_module[318] = {
1515
0xae, 0x03, 0x00, 0x01, 0x08, 0xe9, 0x05, 0xbe,
1616
0x00, 0xe0, 0x29, 0x06, 0x2e, 0xac, 0x03, 0x01,
1717
0x01, 0x06, 0x01, 0x01, 0x00, 0x07, 0x14, 0x02,
18-
0x00, 0xff, 0x49, 0x43, 0x00, 0x0c, 0x43, 0x02,
19-
0x01, 0xae, 0x03, 0x01, 0x00, 0x01, 0x04, 0x01,
20-
0x00, 0x1a, 0x01, 0xb0, 0x03, 0x00, 0x01, 0x00,
21-
0xae, 0x03, 0x00, 0x00, 0xd0, 0xb3, 0xa7, 0xe9,
22-
0x03, 0xb3, 0x28, 0xd0, 0xb4, 0xac, 0xe9, 0x03,
23-
0xb4, 0x28, 0xdc, 0xd0, 0xb4, 0x9e, 0xee, 0xdc,
24-
0xd0, 0xb5, 0x9e, 0xee, 0x9d, 0x28, 0xac, 0x03,
25-
0x02, 0x08, 0x20, 0x04, 0x00, 0x07, 0x06, 0x07,
26-
0x06, 0x12, 0x09, 0x08, 0x07, 0x07, 0x10, 0x07,
27-
0x06, 0x07, 0x06, 0x12, 0x13, 0x08, 0x07, 0x08,
28-
0x16, 0x0c, 0x0c, 0x07, 0x04, 0x0c, 0x0a, 0x0c,
29-
0x0c, 0x07, 0x04, 0x8d, 0x01, 0x66, 0x75, 0x6e,
30-
0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x66, 0x69,
31-
0x62, 0x28, 0x6e, 0x29, 0x0a, 0x7b, 0x0a, 0x20,
32-
0x20, 0x20, 0x20, 0x69, 0x66, 0x20, 0x28, 0x6e,
33-
0x20, 0x3c, 0x3d, 0x20, 0x30, 0x29, 0x0a, 0x20,
34-
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x72,
35-
0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x30, 0x3b,
36-
0x0a, 0x20, 0x20, 0x20, 0x20, 0x65, 0x6c, 0x73,
37-
0x65, 0x20, 0x69, 0x66, 0x20, 0x28, 0x6e, 0x20,
38-
0x3d, 0x3d, 0x20, 0x31, 0x29, 0x0a, 0x20, 0x20,
39-
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x72, 0x65,
40-
0x74, 0x75, 0x72, 0x6e, 0x20, 0x31, 0x3b, 0x0a,
41-
0x20, 0x20, 0x20, 0x20, 0x65, 0x6c, 0x73, 0x65,
42-
0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
43-
0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20,
44-
0x66, 0x69, 0x62, 0x28, 0x6e, 0x20, 0x2d, 0x20,
45-
0x31, 0x29, 0x20, 0x2b, 0x20, 0x66, 0x69, 0x62,
46-
0x28, 0x6e, 0x20, 0x2d, 0x20, 0x32, 0x29, 0x3b,
47-
0x0a, 0x7d, 0xff, 0x49, 0x43, 0x00,
18+
0x00, 0x0c, 0x43, 0x02, 0x01, 0xae, 0x03, 0x01,
19+
0x00, 0x01, 0x04, 0x01, 0x00, 0x1a, 0x01, 0xb0,
20+
0x03, 0x00, 0x01, 0x00, 0xae, 0x03, 0x00, 0x00,
21+
0xd0, 0xb3, 0xa7, 0xe9, 0x03, 0xb3, 0x28, 0xd0,
22+
0xb4, 0xac, 0xe9, 0x03, 0xb4, 0x28, 0xdc, 0xd0,
23+
0xb4, 0x9e, 0xee, 0xdc, 0xd0, 0xb5, 0x9e, 0xee,
24+
0x9d, 0x28, 0xac, 0x03, 0x02, 0x08, 0x20, 0x04,
25+
0x00, 0x07, 0x06, 0x07, 0x06, 0x12, 0x09, 0x08,
26+
0x07, 0x07, 0x10, 0x07, 0x06, 0x07, 0x06, 0x12,
27+
0x13, 0x08, 0x07, 0x08, 0x16, 0x0c, 0x0c, 0x07,
28+
0x04, 0x0c, 0x0a, 0x0c, 0x0c, 0x07, 0x04, 0x8d,
29+
0x01, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f,
30+
0x6e, 0x20, 0x66, 0x69, 0x62, 0x28, 0x6e, 0x29,
31+
0x0a, 0x7b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x69,
32+
0x66, 0x20, 0x28, 0x6e, 0x20, 0x3c, 0x3d, 0x20,
33+
0x30, 0x29, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20,
34+
0x20, 0x20, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72,
35+
0x6e, 0x20, 0x30, 0x3b, 0x0a, 0x20, 0x20, 0x20,
36+
0x20, 0x65, 0x6c, 0x73, 0x65, 0x20, 0x69, 0x66,
37+
0x20, 0x28, 0x6e, 0x20, 0x3d, 0x3d, 0x20, 0x31,
38+
0x29, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
39+
0x20, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e,
40+
0x20, 0x31, 0x3b, 0x0a, 0x20, 0x20, 0x20, 0x20,
41+
0x65, 0x6c, 0x73, 0x65, 0x0a, 0x20, 0x20, 0x20,
42+
0x20, 0x20, 0x20, 0x20, 0x20, 0x72, 0x65, 0x74,
43+
0x75, 0x72, 0x6e, 0x20, 0x66, 0x69, 0x62, 0x28,
44+
0x6e, 0x20, 0x2d, 0x20, 0x31, 0x29, 0x20, 0x2b,
45+
0x20, 0x66, 0x69, 0x62, 0x28, 0x6e, 0x20, 0x2d,
46+
0x20, 0x32, 0x29, 0x3b, 0x0a, 0x7d,
4847
};
4948

50-
const uint32_t qjsc_hello_module_size = 183;
49+
const uint32_t qjsc_hello_module_size = 177;
5150

52-
const uint8_t qjsc_hello_module[183] = {
53-
0x08, 0x07, 0x30, 0x65, 0x78, 0x61, 0x6d, 0x70,
51+
const uint8_t qjsc_hello_module[177] = {
52+
0x09, 0x07, 0x30, 0x65, 0x78, 0x61, 0x6d, 0x70,
5453
0x6c, 0x65, 0x73, 0x2f, 0x68, 0x65, 0x6c, 0x6c,
5554
0x6f, 0x5f, 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65,
5655
0x2e, 0x6a, 0x73, 0x1e, 0x2e, 0x2f, 0x66, 0x69,
@@ -72,7 +71,7 @@ const uint8_t qjsc_hello_module[183] = {
7271
0xbb, 0x0a, 0xee, 0x24, 0x02, 0x00, 0x0e, 0x06,
7372
0x2e, 0xac, 0x03, 0x01, 0x01, 0x0a, 0x01, 0x01,
7473
0x00, 0x04, 0x0a, 0x02, 0x62, 0x00, 0x4d, 0x30,
75-
0x00, 0xff, 0x49, 0x43, 0x01, 0xb4, 0x03,
74+
0x00,
7675
};
7776

7877
static JSContext *JS_NewCustomContext(JSRuntime *rt)

0 commit comments

Comments
 (0)