Skip to content

Commit a223133

Browse files
committed
Remove serializer.
JerryScript-DCO-1.0-Signed-off-by: Andrey Shitov a.shitov@samsung.com
1 parent e9b61a4 commit a223133

19 files changed

+297
-366
lines changed

jerry-core/ecma/base/ecma-helpers-string.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
* @{
2121
*/
2222

23+
#include "bytecode-data.h"
2324
#include "ecma-alloc.h"
2425
#include "ecma-gc.h"
2526
#include "ecma-globals.h"
@@ -29,7 +30,6 @@
2930
#include "jrt-libc-includes.h"
3031
#include "lit-char-helpers.h"
3132
#include "lit-magic-strings.h"
32-
#include "serializer.h"
3333
#include "vm.h"
3434

3535
/**

jerry-core/ecma/builtin-objects/ecma-builtin-function.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
#include "ecma-function-object.h"
2222
#include "ecma-lex-env.h"
2323
#include "ecma-try-catch-macro.h"
24-
#include "serializer.h"
2524
#include "lit-magic-strings.h"
2625
#include "parser.h"
2726

jerry-core/ecma/operations/ecma-eval.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* limitations under the License.
1414
*/
1515

16+
#include "bytecode-data.h"
1617
#include "ecma-builtins.h"
1718
#include "ecma-exceptions.h"
1819
#include "ecma-eval.h"
@@ -21,7 +22,6 @@
2122
#include "ecma-helpers.h"
2223
#include "ecma-lex-env.h"
2324
#include "parser.h"
24-
#include "serializer.h"
2525
#include "vm.h"
2626

2727
/** \addtogroup ecma ECMA

jerry-core/jerry.cpp

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
#include <stdio.h>
1717

18+
#include "bytecode-data.h"
1819
#include "ecma-alloc.h"
1920
#include "ecma-array-object.h"
2021
#include "ecma-builtins.h"
@@ -26,9 +27,9 @@
2627
#include "ecma-init-finalize.h"
2728
#include "ecma-objects.h"
2829
#include "ecma-objects-general.h"
30+
#include "lit-literal.h"
2931
#include "lit-magic-strings.h"
3032
#include "parser.h"
31-
#include "serializer.h"
3233

3334
#define JERRY_INTERNAL
3435
#include "jerry-internal.h"
@@ -1366,7 +1367,8 @@ jerry_cleanup (void)
13661367
bool is_show_mem_stats = ((jerry_flags & JERRY_FLAG_MEM_STATS) != 0);
13671368

13681369
ecma_finalize ();
1369-
serializer_free ();
1370+
lit_finalize ();
1371+
jsp_bc_finalize ();
13701372
mem_finalize (is_show_mem_stats);
13711373
vm_finalize ();
13721374
} /* jerry_cleanup */
@@ -1638,14 +1640,14 @@ jerry_parse_and_save_snapshot (const jerry_api_char_t* source_p, /**< script sou
16381640
size_t bytecode_offset = sizeof (version) + sizeof (jerry_snapshot_header_t) + header.lit_table_size;
16391641
JERRY_ASSERT (JERRY_ALIGNUP (bytecode_offset, MEM_ALIGNMENT) == bytecode_offset);
16401642

1641-
bool is_ok = serializer_dump_bytecode_with_idx_map (buffer_p,
1642-
buffer_size,
1643-
&buffer_write_offset,
1644-
bytecode_data_p,
1645-
lit_map_p,
1646-
literals_num,
1647-
&header.bytecode_size,
1648-
&header.idx_to_lit_map_size);
1643+
bool is_ok = bc_save_bytecode_with_idx_map (buffer_p,
1644+
buffer_size,
1645+
&buffer_write_offset,
1646+
bytecode_data_p,
1647+
lit_map_p,
1648+
literals_num,
1649+
&header.bytecode_size,
1650+
&header.idx_to_lit_map_size);
16491651

16501652
if (lit_map_p != NULL)
16511653
{
@@ -1747,12 +1749,12 @@ jerry_exec_snapshot (const void *snapshot_p, /**< snapshot */
17471749
}
17481750

17491751
const bytecode_data_header_t *bytecode_data_p;
1750-
bytecode_data_p = serializer_load_bytecode_with_idx_map (snapshot_data_p + snapshot_read,
1751-
header_p->bytecode_size,
1752-
header_p->idx_to_lit_map_size,
1753-
lit_map_p,
1754-
literals_num,
1755-
is_copy);
1752+
bytecode_data_p = bc_load_bytecode_with_idx_map (snapshot_data_p + snapshot_read,
1753+
header_p->bytecode_size,
1754+
header_p->idx_to_lit_map_size,
1755+
lit_map_p,
1756+
literals_num,
1757+
is_copy);
17561758

17571759
if (lit_map_p != NULL)
17581760
{

jerry-core/parser/js/bc/bytecode-data.cpp

Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,3 +152,176 @@ jsp_bc_finalize ()
152152
}
153153
} /* jsp_bc_finalize */
154154

155+
/**
156+
* Convert literal id (operand value of instruction) to compressed pointer to literal
157+
*
158+
* Bytecode is divided into blocks of fixed size and each block has independent encoding of variable names,
159+
* which are represented by 8 bit numbers - ids.
160+
* This function performs conversion from id to literal.
161+
*
162+
* @return compressed pointer to literal
163+
*/
164+
lit_cpointer_t
165+
bc_get_literal_cp_by_uid (uint8_t id, /**< literal idx */
166+
const bytecode_data_header_t *bytecode_data_p, /**< pointer to bytecode */
167+
vm_instr_counter_t oc) /**< position in the bytecode */
168+
{
169+
JERRY_ASSERT (bytecode_data_p);
170+
171+
lit_id_hash_table *lit_id_hash = null_hash;
172+
lit_id_hash = MEM_CP_GET_POINTER (lit_id_hash_table, bytecode_data_p->lit_id_hash_cp);
173+
174+
if (lit_id_hash == null_hash)
175+
{
176+
return INVALID_LITERAL;
177+
}
178+
179+
return lit_id_hash_table_lookup (lit_id_hash, id, oc);
180+
} /* serializer_get_literal_cp_by_uid */
181+
182+
#ifdef JERRY_ENABLE_SNAPSHOT
183+
/**
184+
* Dump byte-code and idx-to-literal map to snapshot
185+
*
186+
* @return true, upon success (i.e. buffer size is enough),
187+
* false - otherwise.
188+
*/
189+
bool
190+
bc_save_bytecode_with_idx_map (uint8_t *buffer_p, /**< buffer to dump to */
191+
size_t buffer_size, /**< buffer size */
192+
size_t *in_out_buffer_offset_p, /**< in-out: buffer write offset */
193+
const bytecode_data_header_t *bytecode_data_p, /**< byte-code data */
194+
const lit_mem_to_snapshot_id_map_entry_t *lit_map_p, /**< map from literal
195+
* identifiers in
196+
* literal storage
197+
* to literal offsets
198+
* in snapshot */
199+
uint32_t literals_num, /**< literals number */
200+
uint32_t *out_bytecode_size_p, /**< out: size of dumped instructions array */
201+
uint32_t *out_idx_to_lit_map_size_p) /**< out: side of dumped
202+
* idx to literals map */
203+
{
204+
JERRY_ASSERT (bytecode_data_p->next_header_cp == MEM_CP_NULL);
205+
206+
vm_instr_counter_t instrs_num = bytecode_data_p->instrs_count;
207+
208+
const size_t instrs_array_size = sizeof (vm_instr_t) * instrs_num;
209+
if (*in_out_buffer_offset_p + instrs_array_size > buffer_size)
210+
{
211+
return false;
212+
}
213+
memcpy (buffer_p + *in_out_buffer_offset_p, bytecode_data_p->instrs_p, instrs_array_size);
214+
*in_out_buffer_offset_p += instrs_array_size;
215+
216+
*out_bytecode_size_p = (uint32_t) (sizeof (vm_instr_t) * instrs_num);
217+
218+
lit_id_hash_table *lit_id_hash_p = MEM_CP_GET_POINTER (lit_id_hash_table, bytecode_data_p->lit_id_hash_cp);
219+
uint32_t idx_to_lit_map_size = lit_id_hash_table_dump_for_snapshot (buffer_p,
220+
buffer_size,
221+
in_out_buffer_offset_p,
222+
lit_id_hash_p,
223+
lit_map_p,
224+
literals_num,
225+
instrs_num);
226+
227+
if (idx_to_lit_map_size == 0)
228+
{
229+
return false;
230+
}
231+
else
232+
{
233+
*out_idx_to_lit_map_size_p = idx_to_lit_map_size;
234+
235+
return true;
236+
}
237+
} /* serializer_dump_bytecode_with_idx_map */
238+
239+
/**
240+
* Register bytecode and idx map from snapshot
241+
*
242+
* NOTE:
243+
* If is_copy flag is set, bytecode is copied from snapshot, else bytecode is referenced directly
244+
* from snapshot
245+
*
246+
* @return pointer to byte-code header, upon success,
247+
* NULL - upon failure (i.e., in case snapshot format is not valid)
248+
*/
249+
const bytecode_data_header_t *
250+
bc_load_bytecode_with_idx_map (const uint8_t *bytecode_and_idx_map_p, /**< buffer with instructions array
251+
* and idx to literals map from
252+
* snapshot */
253+
uint32_t bytecode_size, /**< size of instructions array */
254+
uint32_t idx_to_lit_map_size, /**< size of the idx to literals map */
255+
const lit_mem_to_snapshot_id_map_entry_t *lit_map_p, /**< map of in-snapshot
256+
* literal offsets
257+
* to literal identifiers,
258+
* created in literal
259+
* storage */
260+
uint32_t literals_num, /**< number of literals */
261+
bool is_copy) /** flag, indicating whether the passed in-snapshot data
262+
* should be copied to engine's memory (true),
263+
* or it can be referenced until engine is stopped
264+
* (i.e. until call to jerry_cleanup) */
265+
{
266+
const uint8_t *idx_to_lit_map_p = bytecode_and_idx_map_p + bytecode_size;
267+
268+
size_t instructions_number = bytecode_size / sizeof (vm_instr_t);
269+
size_t blocks_count = JERRY_ALIGNUP (instructions_number, BLOCK_SIZE) / BLOCK_SIZE;
270+
271+
uint32_t idx_num_total;
272+
size_t idx_to_lit_map_offset = 0;
273+
if (!jrt_read_from_buffer_by_offset (idx_to_lit_map_p,
274+
idx_to_lit_map_size,
275+
&idx_to_lit_map_offset,
276+
&idx_num_total))
277+
{
278+
return NULL;
279+
}
280+
281+
const size_t bytecode_alloc_size = JERRY_ALIGNUP (bytecode_size, MEM_ALIGNMENT);
282+
const size_t hash_table_size = lit_id_hash_table_get_size_for_table (idx_num_total, blocks_count);
283+
const size_t header_and_hash_table_size = JERRY_ALIGNUP (sizeof (bytecode_data_header_t) + hash_table_size,
284+
MEM_ALIGNMENT);
285+
const size_t alloc_size = header_and_hash_table_size + (is_copy ? bytecode_alloc_size : 0);
286+
287+
uint8_t *buffer_p = (uint8_t*) mem_heap_alloc_block (alloc_size, MEM_HEAP_ALLOC_LONG_TERM);
288+
bytecode_data_header_t *header_p = (bytecode_data_header_t *) buffer_p;
289+
290+
vm_instr_t *instrs_p;
291+
vm_instr_t *snapshot_instrs_p = (vm_instr_t *) bytecode_and_idx_map_p;
292+
if (is_copy)
293+
{
294+
instrs_p = (vm_instr_t *) (buffer_p + header_and_hash_table_size);
295+
memcpy (instrs_p, snapshot_instrs_p, bytecode_size);
296+
}
297+
else
298+
{
299+
instrs_p = snapshot_instrs_p;
300+
}
301+
302+
uint8_t *lit_id_hash_table_buffer_p = buffer_p + sizeof (bytecode_data_header_t);
303+
if (lit_id_hash_table_load_from_snapshot (blocks_count,
304+
idx_num_total,
305+
idx_to_lit_map_p + idx_to_lit_map_offset,
306+
idx_to_lit_map_size - idx_to_lit_map_offset,
307+
lit_map_p,
308+
literals_num,
309+
lit_id_hash_table_buffer_p,
310+
hash_table_size)
311+
&& (vm_instr_counter_t) instructions_number == instructions_number)
312+
{
313+
jsp_bc_add_bytecode_data (header_p,
314+
(lit_id_hash_table *) lit_id_hash_table_buffer_p,
315+
instrs_p,
316+
(vm_instr_counter_t) instructions_number);
317+
318+
return header_p;
319+
}
320+
else
321+
{
322+
mem_heap_free_block (buffer_p);
323+
return NULL;
324+
}
325+
} /* serializer_load_bytecode_with_idx_map */
326+
327+
#endif /* JERRY_ENABLE_SNAPSHOT */

jerry-core/parser/js/bc/bytecode-data.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,23 @@ const bytecode_data_header_t *bc_merge_scopes_into_bytecode (scopes_tree, bool);
6767

6868
void jsp_bc_finalize ();
6969

70+
lit_cpointer_t
71+
bc_get_literal_cp_by_uid (uint8_t,
72+
const bytecode_data_header_t *,
73+
vm_instr_counter_t);
74+
75+
76+
#ifdef JERRY_ENABLE_SNAPSHOT
77+
/*
78+
* Snapshot-related
79+
*/
80+
bool bc_save_bytecode_with_idx_map (uint8_t *, size_t, size_t *, const bytecode_data_header_t *,
81+
const lit_mem_to_snapshot_id_map_entry_t *, uint32_t,
82+
uint32_t *, uint32_t *);
83+
84+
const bytecode_data_header_t *
85+
bc_load_bytecode_with_idx_map (const uint8_t *, uint32_t, uint32_t,
86+
const lit_mem_to_snapshot_id_map_entry_t *, uint32_t, bool);
87+
#endif /* JERRY_ENABLE_SNAPSHOT */
88+
7089
#endif /* BYTECODE_DATA_H */

0 commit comments

Comments
 (0)