Skip to content

Storing byte code size in the byte code header. #948

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 16, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions jerry-core/ecma/base/ecma-globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -741,17 +741,15 @@ typedef uintptr_t ecma_external_pointer_t;
*/
typedef struct
{
uint16_t status_flags; /**< various status flags */
uint16_t size; /**< real size >> MEM_ALIGNMENT_LOG */
uint16_t refs; /**< reference counter for the byte code */
uint16_t status_flags; /**< various status flags:
* CBC_CODE_FLAGS_FUNCTION flag tells whether
* the byte code is function or regular expression.
* If function, the other flags must be CBC_CODE_FLAGS...
* If regexp, the other flags must be RE_FLAG... */
} ecma_compiled_code_t;

/**
* Shift value for byte code reference counting.
* The last 10 bit of the first uint16_t value
* of compact byte code or regexp byte code
* is reserved for reference counting.
*/
#define ECMA_BYTECODE_REF_SHIFT 6

/**
* @}
*/
Expand Down
13 changes: 7 additions & 6 deletions jerry-core/ecma/base/ecma-helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -1316,12 +1316,12 @@ void
ecma_bytecode_ref (ecma_compiled_code_t *bytecode_p) /**< byte code pointer */
{
/* Abort program if maximum reference number is reached. */
if ((bytecode_p->status_flags >> ECMA_BYTECODE_REF_SHIFT) >= 0x3ff)
if (bytecode_p->refs >= UINT16_MAX)
{
jerry_fatal (ERR_REF_COUNT_LIMIT);
}

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

/**
Expand All @@ -1331,11 +1331,11 @@ ecma_bytecode_ref (ecma_compiled_code_t *bytecode_p) /**< byte code pointer */
void
ecma_bytecode_deref (ecma_compiled_code_t *bytecode_p) /**< byte code pointer */
{
JERRY_ASSERT ((bytecode_p->status_flags >> ECMA_BYTECODE_REF_SHIFT) > 0);
JERRY_ASSERT (bytecode_p->refs > 0);

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

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

mem_heap_free_block_size_stored (bytecode_p);
mem_heap_free_block (bytecode_p,
((size_t) bytecode_p->size) << MEM_ALIGNMENT_LOG);
} /* ecma_bytecode_deref */

/**
Expand Down
4 changes: 2 additions & 2 deletions jerry-core/ecma/operations/ecma-regexp-object.c
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ ecma_op_create_regexp_object_from_bytecode (re_compiled_code_t *bytecode_p) /**<
/* Initialize RegExp object properties */
re_initialize_props (obj_p,
ECMA_GET_NON_NULL_POINTER (ecma_string_t, bytecode_p->pattern_cp),
bytecode_p->flags);
bytecode_p->header.status_flags);

return ecma_make_object_value (obj_p);
} /* ecma_op_create_regexp_object_from_bytecode */
Expand Down Expand Up @@ -1298,7 +1298,7 @@ ecma_regexp_exec_helper (ecma_value_t regexp_value, /**< RegExp object */
re_ctx.input_end_p = input_end_p;

/* 1. Read bytecode header and init regexp matcher context. */
re_ctx.flags = bc_p->flags;
re_ctx.flags = bc_p->header.status_flags;

if (ignore_global)
{
Expand Down
24 changes: 8 additions & 16 deletions jerry-core/jerry-snapshot.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,27 +24,19 @@
*/
typedef struct
{
uint32_t last_compiled_code_offset; /**< offset of the last compiled code */
/* The size of this structure is recommended to be divisible by
* MEM_ALIGNMENT. Otherwise some bytes after the header are wasted. */
uint32_t version; /**< version number */
uint32_t lit_table_offset; /**< offset of the literal table */
uint32_t lit_table_size; /**< size of literal table */
__extension__ uint32_t is_run_global : 1; /**< flag, indicating whether the snapshot
* was dumped as 'Global scope'-mode code (true)
* or as eval-mode code (false) */
uint32_t is_run_global; /**< flag, indicating whether the snapshot
* was dumped as 'Global scope'-mode code (true)
* or as eval-mode code (false) */
} jerry_snapshot_header_t;

/**
* Jerry snapshot format version
*/
#define JERRY_SNAPSHOT_VERSION (3u)

#ifdef JERRY_ENABLE_SNAPSHOT_SAVE

/* Snapshot support functions */

extern bool snapshot_report_byte_code_compilation;

extern void
snapshot_add_compiled_code (ecma_compiled_code_t *, const uint8_t *, uint32_t);

#endif /* JERRY_ENABLE_SNAPSHOT_SAVE */
#define JERRY_SNAPSHOT_VERSION (4u)

#endif /* !JERRY_SNAPSHOT_H */
Loading