Skip to content

Commit 6745833

Browse files
committed
Storing byte code size in the byte code header. This reduces the
memory consumption, because the new allocator uses less memory if the size as available when a block is freed. Snapshot generation is also simplified. JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg [email protected]
1 parent 66c94b7 commit 6745833

18 files changed

+255
-324
lines changed

jerry-core/ecma/base/ecma-globals.h

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -741,17 +741,15 @@ typedef uintptr_t ecma_external_pointer_t;
741741
*/
742742
typedef struct
743743
{
744-
uint16_t status_flags; /**< various status flags */
744+
uint16_t size; /**< real size >> MEM_ALIGNMENT_LOG */
745+
uint16_t refs; /**< reference counter for the byte code */
746+
uint16_t status_flags; /**< various status flags:
747+
* CBC_CODE_FLAGS_FUNCTION flag tells whether
748+
* the byte code is function or regular expression.
749+
* If function, the other flags must be CBC_CODE_FLAGS...
750+
* If regexp, the other flags must be RE_FLAG... */
745751
} ecma_compiled_code_t;
746752

747-
/**
748-
* Shift value for byte code reference counting.
749-
* The last 10 bit of the first uint16_t value
750-
* of compact byte code or regexp byte code
751-
* is reserved for reference counting.
752-
*/
753-
#define ECMA_BYTECODE_REF_SHIFT 6
754-
755753
/**
756754
* @}
757755
*/

jerry-core/ecma/base/ecma-helpers.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1316,12 +1316,12 @@ void
13161316
ecma_bytecode_ref (ecma_compiled_code_t *bytecode_p) /**< byte code pointer */
13171317
{
13181318
/* Abort program if maximum reference number is reached. */
1319-
if ((bytecode_p->status_flags >> ECMA_BYTECODE_REF_SHIFT) >= 0x3ff)
1319+
if (bytecode_p->refs >= UINT16_MAX)
13201320
{
13211321
jerry_fatal (ERR_REF_COUNT_LIMIT);
13221322
}
13231323

1324-
bytecode_p->status_flags = (uint16_t) (bytecode_p->status_flags + (1u << ECMA_BYTECODE_REF_SHIFT));
1324+
bytecode_p->refs++;
13251325
} /* ecma_bytecode_ref */
13261326

13271327
/**
@@ -1331,11 +1331,11 @@ ecma_bytecode_ref (ecma_compiled_code_t *bytecode_p) /**< byte code pointer */
13311331
void
13321332
ecma_bytecode_deref (ecma_compiled_code_t *bytecode_p) /**< byte code pointer */
13331333
{
1334-
JERRY_ASSERT ((bytecode_p->status_flags >> ECMA_BYTECODE_REF_SHIFT) > 0);
1334+
JERRY_ASSERT (bytecode_p->refs > 0);
13351335

1336-
bytecode_p->status_flags = (uint16_t) (bytecode_p->status_flags - (1u << ECMA_BYTECODE_REF_SHIFT));
1336+
bytecode_p->refs--;
13371337

1338-
if (bytecode_p->status_flags >= (1u << ECMA_BYTECODE_REF_SHIFT))
1338+
if (bytecode_p->refs > 0)
13391339
{
13401340
/* Non-zero reference counter. */
13411341
return;
@@ -1388,7 +1388,8 @@ ecma_bytecode_deref (ecma_compiled_code_t *bytecode_p) /**< byte code pointer */
13881388
#endif /* !CONFIG_ECMA_COMPACT_PROFILE_DISABLE_REGEXP_BUILTIN */
13891389
}
13901390

1391-
mem_heap_free_block_size_stored (bytecode_p);
1391+
mem_heap_free_block (bytecode_p,
1392+
((size_t) bytecode_p->size) << MEM_ALIGNMENT_LOG);
13921393
} /* ecma_bytecode_deref */
13931394

13941395
/**

jerry-core/jerry-snapshot.h

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,27 +24,17 @@
2424
*/
2525
typedef struct
2626
{
27-
uint32_t last_compiled_code_offset; /**< offset of the last compiled code */
27+
uint32_t version; /**< version number */
28+
uint32_t lit_table_offset; /**< offset of the literal table */
2829
uint32_t lit_table_size; /**< size of literal table */
29-
__extension__ uint32_t is_run_global : 1; /**< flag, indicating whether the snapshot
30-
* was dumped as 'Global scope'-mode code (true)
31-
* or as eval-mode code (false) */
30+
uint32_t is_run_global; /**< flag, indicating whether the snapshot
31+
* was dumped as 'Global scope'-mode code (true)
32+
* or as eval-mode code (false) */
3233
} jerry_snapshot_header_t;
3334

3435
/**
3536
* Jerry snapshot format version
3637
*/
37-
#define JERRY_SNAPSHOT_VERSION (3u)
38-
39-
#ifdef JERRY_ENABLE_SNAPSHOT_SAVE
40-
41-
/* Snapshot support functions */
42-
43-
extern bool snapshot_report_byte_code_compilation;
44-
45-
extern void
46-
snapshot_add_compiled_code (ecma_compiled_code_t *, const uint8_t *, uint32_t);
47-
48-
#endif /* JERRY_ENABLE_SNAPSHOT_SAVE */
38+
#define JERRY_SNAPSHOT_VERSION (4u)
4939

5040
#endif /* !JERRY_SNAPSHOT_H */

0 commit comments

Comments
 (0)