Split opcode and instruction entities and perform related renamings: opcode_t is now vm_instr_t, opcode position is instruction position, etc.

JerryScript-DCO-1.0-Signed-off-by: Ruben Ayrapetyan r.ayrapetyan@samsung.com
This commit is contained in:
Ruben Ayrapetyan
2015-07-21 19:14:06 +03:00
committed by Evgeny Gavrin
parent 1990762cf0
commit 502f4c4623
43 changed files with 1096 additions and 1085 deletions
+78 -78
View File
@@ -44,9 +44,9 @@ static const opfunc __opfuncs[VM_OP__COUNT] =
#include "vm-opcodes.inc.h"
};
JERRY_STATIC_ASSERT (sizeof (opcode_t) <= 4);
JERRY_STATIC_ASSERT (sizeof (vm_instr_t) <= 4);
const opcode_t *__program = NULL;
const vm_instr_t *__program = NULL;
#ifdef MEM_STATS
static const char *__op_names[VM_OP__COUNT] =
@@ -120,8 +120,8 @@ interp_mem_get_stats (mem_heap_stats_t *out_heap_stats_p,
}
static void
interp_mem_stats_context_enter (vm_frame_ctx_t *int_data_p,
opcode_counter_t block_position)
interp_mem_stats_context_enter (vm_frame_ctx_t *frame_ctx_p,
vm_instr_counter_t block_position)
{
if (likely (!interp_mem_stats_enabled))
{
@@ -136,13 +136,13 @@ interp_mem_stats_context_enter (vm_frame_ctx_t *int_data_p,
indent_prefix[indentation] = '|';
indent_prefix[indentation + 1] = '\0';
int_data_p->context_peak_allocated_heap_bytes = 0;
int_data_p->context_peak_waste_heap_bytes = 0;
int_data_p->context_peak_pools_count = 0;
int_data_p->context_peak_allocated_pool_chunks = 0;
frame_ctx_p->context_peak_allocated_heap_bytes = 0;
frame_ctx_p->context_peak_waste_heap_bytes = 0;
frame_ctx_p->context_peak_pools_count = 0;
frame_ctx_p->context_peak_allocated_pool_chunks = 0;
interp_mem_get_stats (&int_data_p->heap_stats_context_enter,
&int_data_p->pools_stats_context_enter,
interp_mem_get_stats (&frame_ctx_p->heap_stats_context_enter,
&frame_ctx_p->pools_stats_context_enter,
false, false);
printf ("\n%s--- Beginning interpretation of a block at position %u ---\n"
@@ -151,15 +151,15 @@ interp_mem_stats_context_enter (vm_frame_ctx_t *int_data_p,
"%s Pools: %5u\n"
"%s Allocated pool chunks: %5u\n\n",
indent_prefix, (uint32_t) block_position,
indent_prefix, (uint32_t) int_data_p->heap_stats_context_enter.allocated_bytes,
indent_prefix, (uint32_t) int_data_p->heap_stats_context_enter.waste_bytes,
indent_prefix, (uint32_t) int_data_p->pools_stats_context_enter.pools_count,
indent_prefix, (uint32_t) int_data_p->pools_stats_context_enter.allocated_chunks);
indent_prefix, (uint32_t) frame_ctx_p->heap_stats_context_enter.allocated_bytes,
indent_prefix, (uint32_t) frame_ctx_p->heap_stats_context_enter.waste_bytes,
indent_prefix, (uint32_t) frame_ctx_p->pools_stats_context_enter.pools_count,
indent_prefix, (uint32_t) frame_ctx_p->pools_stats_context_enter.allocated_chunks);
}
static void
interp_mem_stats_context_exit (vm_frame_ctx_t *int_data_p,
opcode_counter_t block_position)
interp_mem_stats_context_exit (vm_frame_ctx_t *frame_ctx_p,
vm_instr_counter_t block_position)
{
if (likely (!interp_mem_stats_enabled))
{
@@ -181,46 +181,46 @@ interp_mem_stats_context_exit (vm_frame_ctx_t *int_data_p,
&pools_stats_context_exit,
false, true);
int_data_p->context_peak_allocated_heap_bytes -= JERRY_MAX (int_data_p->heap_stats_context_enter.allocated_bytes,
frame_ctx_p->context_peak_allocated_heap_bytes -= JERRY_MAX (frame_ctx_p->heap_stats_context_enter.allocated_bytes,
heap_stats_context_exit.allocated_bytes);
int_data_p->context_peak_waste_heap_bytes -= JERRY_MAX (int_data_p->heap_stats_context_enter.waste_bytes,
frame_ctx_p->context_peak_waste_heap_bytes -= JERRY_MAX (frame_ctx_p->heap_stats_context_enter.waste_bytes,
heap_stats_context_exit.waste_bytes);
int_data_p->context_peak_pools_count -= JERRY_MAX (int_data_p->pools_stats_context_enter.pools_count,
frame_ctx_p->context_peak_pools_count -= JERRY_MAX (frame_ctx_p->pools_stats_context_enter.pools_count,
pools_stats_context_exit.pools_count);
int_data_p->context_peak_allocated_pool_chunks -= JERRY_MAX (int_data_p->pools_stats_context_enter.allocated_chunks,
frame_ctx_p->context_peak_allocated_pool_chunks -= JERRY_MAX (frame_ctx_p->pools_stats_context_enter.allocated_chunks,
pools_stats_context_exit.allocated_chunks);
printf ("%sAllocated heap bytes in the context: %5u -> %5u (%+5d, local %5u, peak %5u)\n",
indent_prefix,
(uint32_t) int_data_p->heap_stats_context_enter.allocated_bytes,
(uint32_t) frame_ctx_p->heap_stats_context_enter.allocated_bytes,
(uint32_t) heap_stats_context_exit.allocated_bytes,
(uint32_t) (heap_stats_context_exit.allocated_bytes - int_data_p->heap_stats_context_enter.allocated_bytes),
(uint32_t) int_data_p->context_peak_allocated_heap_bytes,
(uint32_t) (heap_stats_context_exit.allocated_bytes - frame_ctx_p->heap_stats_context_enter.allocated_bytes),
(uint32_t) frame_ctx_p->context_peak_allocated_heap_bytes,
(uint32_t) heap_stats_context_exit.global_peak_allocated_bytes);
printf ("%sWaste heap bytes in the context: %5u -> %5u (%+5d, local %5u, peak %5u)\n",
indent_prefix,
(uint32_t) int_data_p->heap_stats_context_enter.waste_bytes,
(uint32_t) frame_ctx_p->heap_stats_context_enter.waste_bytes,
(uint32_t) heap_stats_context_exit.waste_bytes,
(uint32_t) (heap_stats_context_exit.waste_bytes - int_data_p->heap_stats_context_enter.waste_bytes),
(uint32_t) int_data_p->context_peak_waste_heap_bytes,
(uint32_t) (heap_stats_context_exit.waste_bytes - frame_ctx_p->heap_stats_context_enter.waste_bytes),
(uint32_t) frame_ctx_p->context_peak_waste_heap_bytes,
(uint32_t) heap_stats_context_exit.global_peak_waste_bytes);
printf ("%sPools count in the context: %5u -> %5u (%+5d, local %5u, peak %5u)\n",
indent_prefix,
(uint32_t) int_data_p->pools_stats_context_enter.pools_count,
(uint32_t) frame_ctx_p->pools_stats_context_enter.pools_count,
(uint32_t) pools_stats_context_exit.pools_count,
(uint32_t) (pools_stats_context_exit.pools_count - int_data_p->pools_stats_context_enter.pools_count),
(uint32_t) int_data_p->context_peak_pools_count,
(uint32_t) (pools_stats_context_exit.pools_count - frame_ctx_p->pools_stats_context_enter.pools_count),
(uint32_t) frame_ctx_p->context_peak_pools_count,
(uint32_t) pools_stats_context_exit.global_peak_pools_count);
printf ("%sAllocated pool chunks in the context: %5u -> %5u (%+5d, local %5u, peak %5u)\n",
indent_prefix,
(uint32_t) int_data_p->pools_stats_context_enter.allocated_chunks,
(uint32_t) frame_ctx_p->pools_stats_context_enter.allocated_chunks,
(uint32_t) pools_stats_context_exit.allocated_chunks,
(uint32_t) (pools_stats_context_exit.allocated_chunks -
int_data_p->pools_stats_context_enter.allocated_chunks),
(uint32_t) int_data_p->context_peak_allocated_pool_chunks,
frame_ctx_p->pools_stats_context_enter.allocated_chunks),
(uint32_t) frame_ctx_p->context_peak_allocated_pool_chunks,
(uint32_t) pools_stats_context_exit.global_peak_allocated_chunks);
printf ("\n%s--- End of interpretation of a block at position %u ---\n\n",
@@ -228,8 +228,8 @@ interp_mem_stats_context_exit (vm_frame_ctx_t *int_data_p,
}
static void
interp_mem_stats_opcode_enter (const opcode_t *opcodes_p,
opcode_counter_t opcode_position,
interp_mem_stats_opcode_enter (const vm_instr_t *instrs_p,
vm_instr_counter_t instr_position,
mem_heap_stats_t *out_heap_stats_p,
mem_pools_stats_t *out_pools_stats_p)
{
@@ -250,17 +250,17 @@ interp_mem_stats_opcode_enter (const opcode_t *opcodes_p,
out_pools_stats_p,
true, false);
opcode_t opcode = vm_get_opcode (opcodes_p, opcode_position);
vm_instr_t instr = vm_get_instr (instrs_p, instr_position);
printf ("%s-- Opcode: %s (position %u) --\n",
indent_prefix, __op_names[opcode.op_idx], (uint32_t) opcode_position);
indent_prefix, __op_names[instr.op_idx], (uint32_t) instr_position);
interp_mem_stats_print_indentation += INTERP_MEM_PRINT_INDENTATION_STEP;
}
static void
interp_mem_stats_opcode_exit (vm_frame_ctx_t *int_data_p,
opcode_counter_t opcode_position,
interp_mem_stats_opcode_exit (vm_frame_ctx_t *frame_ctx_p,
vm_instr_counter_t instr_position,
mem_heap_stats_t *heap_stats_before_p,
mem_pools_stats_t *pools_stats_before_p)
{
@@ -286,16 +286,16 @@ interp_mem_stats_opcode_exit (vm_frame_ctx_t *int_data_p,
&pools_stats_after,
false, true);
int_data_p->context_peak_allocated_heap_bytes = JERRY_MAX (int_data_p->context_peak_allocated_heap_bytes,
frame_ctx_p->context_peak_allocated_heap_bytes = JERRY_MAX (frame_ctx_p->context_peak_allocated_heap_bytes,
heap_stats_after.allocated_bytes);
int_data_p->context_peak_waste_heap_bytes = JERRY_MAX (int_data_p->context_peak_waste_heap_bytes,
frame_ctx_p->context_peak_waste_heap_bytes = JERRY_MAX (frame_ctx_p->context_peak_waste_heap_bytes,
heap_stats_after.waste_bytes);
int_data_p->context_peak_pools_count = JERRY_MAX (int_data_p->context_peak_pools_count,
frame_ctx_p->context_peak_pools_count = JERRY_MAX (frame_ctx_p->context_peak_pools_count,
pools_stats_after.pools_count);
int_data_p->context_peak_allocated_pool_chunks = JERRY_MAX (int_data_p->context_peak_allocated_pool_chunks,
frame_ctx_p->context_peak_allocated_pool_chunks = JERRY_MAX (frame_ctx_p->context_peak_allocated_pool_chunks,
pools_stats_after.allocated_chunks);
opcode_t opcode = vm_get_opcode (int_data_p->opcodes_p, opcode_position);
vm_instr_t instr = vm_get_instr (frame_ctx_p->instrs_p, instr_position);
printf ("%s Allocated heap bytes: %5u -> %5u (%+5d, local %5u, peak %5u)\n",
indent_prefix,
@@ -343,7 +343,7 @@ interp_mem_stats_opcode_exit (vm_frame_ctx_t *int_data_p,
}
printf ("%s-- End of execution of opcode %s (position %u) --\n\n",
indent_prefix, __op_names[opcode.op_idx], opcode_position);
indent_prefix, __op_names[instr.op_idx], instr_position);
}
#endif /* MEM_STATS */
@@ -351,8 +351,8 @@ interp_mem_stats_opcode_exit (vm_frame_ctx_t *int_data_p,
* Initialize interpreter.
*/
void
vm_init (const opcode_t *program_p, /**< pointer to byte-code program */
bool dump_mem_stats) /** dump per-opcode memory usage change statistics */
vm_init (const vm_instr_t *program_p, /**< pointer to byte-code program */
bool dump_mem_stats) /** dump per-instruction memory usage change statistics */
{
#ifdef MEM_STATS
interp_mem_stats_enabled = dump_mem_stats;
@@ -392,7 +392,7 @@ vm_run_global (void)
#endif /* MEM_STATS */
bool is_strict = false;
opcode_counter_t start_pos = 0;
vm_instr_counter_t start_pos = 0;
opcode_scope_code_flags_t scope_flags = vm_get_scope_flags (__program,
start_pos++);
@@ -448,7 +448,7 @@ vm_run_global (void)
* Otherwise - the completion value is discarded and normal empty completion value is returned.
*/
ecma_completion_value_t
vm_loop (vm_frame_ctx_t *int_data_p, /**< interpreter context */
vm_loop (vm_frame_ctx_t *frame_ctx_p, /**< interpreter context */
vm_run_scope_t *run_scope_p) /**< current run scope,
* or NULL - if there is no active run scope */
{
@@ -467,29 +467,29 @@ vm_loop (vm_frame_ctx_t *int_data_p, /**< interpreter context */
do
{
JERRY_ASSERT (run_scope_p == NULL
|| (run_scope_p->start_oc <= int_data_p->pos
&& int_data_p->pos <= run_scope_p->end_oc));
|| (run_scope_p->start_oc <= frame_ctx_p->pos
&& frame_ctx_p->pos <= run_scope_p->end_oc));
const opcode_t *curr = &int_data_p->opcodes_p[int_data_p->pos];
const vm_instr_t *curr = &frame_ctx_p->instrs_p[frame_ctx_p->pos];
#ifdef MEM_STATS
const opcode_counter_t opcode_pos = int_data_p->pos;
const vm_instr_counter_t instr_pos = frame_ctx_p->pos;
interp_mem_stats_opcode_enter (int_data_p->opcodes_p,
opcode_pos,
interp_mem_stats_opcode_enter (frame_ctx_p->instrs_p,
instr_pos,
&heap_stats_before,
&pools_stats_before);
#endif /* MEM_STATS */
completion = __opfuncs[curr->op_idx] (*curr, int_data_p);
completion = __opfuncs[curr->op_idx] (*curr, frame_ctx_p);
#ifdef CONFIG_VM_RUN_GC_AFTER_EACH_OPCODE
ecma_gc_run ();
#endif /* CONFIG_VM_RUN_GC_AFTER_EACH_OPCODE */
#ifdef MEM_STATS
interp_mem_stats_opcode_exit (int_data_p,
opcode_pos,
interp_mem_stats_opcode_exit (frame_ctx_p,
instr_pos,
&heap_stats_before,
&pools_stats_before);
#endif /* MEM_STATS */
@@ -501,7 +501,7 @@ vm_loop (vm_frame_ctx_t *int_data_p, /**< interpreter context */
if (ecma_is_completion_value_jump (completion))
{
opcode_counter_t target = ecma_get_jump_target_from_completion_value (completion);
vm_instr_counter_t target = ecma_get_jump_target_from_completion_value (completion);
/*
* TODO:
@@ -512,7 +512,7 @@ vm_loop (vm_frame_ctx_t *int_data_p, /**< interpreter context */
|| (target >= run_scope_p->start_oc /* or target is within the current run scope */
&& target <= run_scope_p->end_oc))
{
int_data_p->pos = target;
frame_ctx_p->pos = target;
continue;
}
@@ -528,11 +528,11 @@ vm_loop (vm_frame_ctx_t *int_data_p, /**< interpreter context */
} /* vm_loop */
/**
* Run the code, starting from specified opcode
* Run the code, starting from specified instruction position
*/
ecma_completion_value_t
vm_run_from_pos (const opcode_t *opcodes_p, /**< byte-code array */
opcode_counter_t start_pos, /**< identifier of starting opcode */
vm_run_from_pos (const vm_instr_t *instrs_p, /**< byte-code array */
vm_instr_counter_t start_pos, /**< position of starting instruction */
ecma_value_t this_binding_value, /**< value of 'ThisBinding' */
ecma_object_t *lex_env_p, /**< lexical environment to use */
bool is_strict, /**< is the code is strict mode code (ECMA-262 v5, 10.1.1) */
@@ -540,7 +540,7 @@ vm_run_from_pos (const opcode_t *opcodes_p, /**< byte-code array */
{
ecma_completion_value_t completion;
const opcode_t *curr = &opcodes_p[start_pos];
const vm_instr_t *curr = &instrs_p[start_pos];
JERRY_ASSERT (curr->op_idx == VM_OP_REG_VAR_DECL);
const idx_t min_reg_num = curr->data.reg_var_decl.min;
@@ -552,8 +552,8 @@ vm_run_from_pos (const opcode_t *opcodes_p, /**< byte-code array */
MEM_DEFINE_LOCAL_ARRAY (regs, regs_num, ecma_value_t);
vm_frame_ctx_t frame_ctx;
frame_ctx.opcodes_p = opcodes_p;
frame_ctx.pos = (opcode_counter_t) (start_pos + 1);
frame_ctx.instrs_p = instrs_p;
frame_ctx.pos = (vm_instr_counter_t) (start_pos + 1);
frame_ctx.this_binding = this_binding_value;
frame_ctx.lex_env_p = lex_env_p;
frame_ctx.is_strict = is_strict;
@@ -592,28 +592,28 @@ vm_run_from_pos (const opcode_t *opcodes_p, /**< byte-code array */
} /* vm_run_from_pos */
/**
* Get specified opcode from the program.
* Get specified instruction from the program.
*/
opcode_t
vm_get_opcode (const opcode_t *opcodes_p, /**< byte-code array */
opcode_counter_t counter) /**< opcode counter */
vm_instr_t
vm_get_instr (const vm_instr_t *instrs_p, /**< byte-code array */
vm_instr_counter_t counter) /**< instruction counter */
{
return opcodes_p[ counter ];
} /* vm_get_opcode */
return instrs_p[ counter ];
} /* vm_get_instr */
/**
* Get scope code flags from opcode specified by opcode counter
* Get scope code flags from instruction at specified position
*
* @return mask of scope code flags
*/
opcode_scope_code_flags_t
vm_get_scope_flags (const opcode_t *opcodes_p, /**< byte-code array */
opcode_counter_t counter) /**< opcode counter */
vm_get_scope_flags (const vm_instr_t *instrs_p, /**< byte-code array */
vm_instr_counter_t counter) /**< instruction counter */
{
opcode_t flags_opcode = vm_get_opcode (opcodes_p, counter);
JERRY_ASSERT (flags_opcode.op_idx == VM_OP_META
&& flags_opcode.data.meta.type == OPCODE_META_TYPE_SCOPE_CODE_FLAGS);
return (opcode_scope_code_flags_t) flags_opcode.data.meta.data_1;
vm_instr_t flags_instr = vm_get_instr (instrs_p, counter);
JERRY_ASSERT (flags_instr.op_idx == VM_OP_META
&& flags_instr.data.meta.type == OPCODE_META_TYPE_SCOPE_CODE_FLAGS);
return (opcode_scope_code_flags_t) flags_instr.data.meta.data_1;
} /* vm_get_scope_flags */
/**