Parser optimizations.

- parser is now non-recursive (i.e. parse function is not called recursively in any case);
 - byte-code is now more compact:
    - constants are now not immediately dumped upon occurence, but later - where necessary;
    - assignments are combined with unary / binary operations;
    - binary operations are encoded more compactly in many cases;
 - byte-code arrays are now allocated separately for each scope (so, GC of the scopes now becomes possible);
 - byte-code is dumped directly into corresponding byte-code arrays:
   - linked lists of op_meta are not now used for main code of a scope.

JerryScript-DCO-1.0-Signed-off-by: Ruben Ayrapetyan r.ayrapetyan@samsung.com
JerryScript-DCO-1.0-Signed-off-by: Andrey Shitov a.shitov@samsung.com
This commit is contained in:
Andrey Shitov
2015-11-03 19:14:19 +03:00
committed by Ruben Ayrapetyan
parent b1de93abd6
commit 50d124bfc3
51 changed files with 9044 additions and 7401 deletions
+44 -40
View File
@@ -685,55 +685,59 @@ main (void)
jerry_cleanup ();
// Dump / execute snapshot
static uint8_t global_mode_snapshot_buffer[1024];
static uint8_t eval_mode_snapshot_buffer[1024];
// FIXME: support save/load snapshot for optimized parser
if (false)
{
static uint8_t global_mode_snapshot_buffer[1024];
static uint8_t eval_mode_snapshot_buffer[1024];
const char *code_to_snapshot_p = "(function () { return 'string from snapshot'; }) ();";
const char *code_to_snapshot_p = "(function () { return 'string from snapshot'; }) ();";
jerry_init (JERRY_FLAG_SHOW_OPCODES);
size_t global_mode_snapshot_size = jerry_parse_and_save_snapshot ((jerry_api_char_t *) code_to_snapshot_p,
jerry_init (JERRY_FLAG_SHOW_OPCODES);
size_t global_mode_snapshot_size = jerry_parse_and_save_snapshot ((jerry_api_char_t *) code_to_snapshot_p,
strlen (code_to_snapshot_p),
true,
global_mode_snapshot_buffer,
sizeof (global_mode_snapshot_buffer));
JERRY_ASSERT (global_mode_snapshot_size != 0);
jerry_cleanup ();
jerry_init (JERRY_FLAG_SHOW_OPCODES);
size_t eval_mode_snapshot_size = jerry_parse_and_save_snapshot ((jerry_api_char_t *) code_to_snapshot_p,
strlen (code_to_snapshot_p),
true,
global_mode_snapshot_buffer,
sizeof (global_mode_snapshot_buffer));
JERRY_ASSERT (global_mode_snapshot_size != 0);
jerry_cleanup ();
false,
eval_mode_snapshot_buffer,
sizeof (eval_mode_snapshot_buffer));
JERRY_ASSERT (eval_mode_snapshot_size != 0);
jerry_cleanup ();
jerry_init (JERRY_FLAG_SHOW_OPCODES);
size_t eval_mode_snapshot_size = jerry_parse_and_save_snapshot ((jerry_api_char_t *) code_to_snapshot_p,
strlen (code_to_snapshot_p),
false,
eval_mode_snapshot_buffer,
sizeof (eval_mode_snapshot_buffer));
JERRY_ASSERT (eval_mode_snapshot_size != 0);
jerry_cleanup ();
jerry_init (JERRY_FLAG_SHOW_OPCODES);
jerry_init (JERRY_FLAG_SHOW_OPCODES);
is_ok = (jerry_exec_snapshot (global_mode_snapshot_buffer,
global_mode_snapshot_size,
false,
&res) == JERRY_COMPLETION_CODE_OK);
is_ok = (jerry_exec_snapshot (global_mode_snapshot_buffer,
global_mode_snapshot_size,
false,
&res) == JERRY_COMPLETION_CODE_OK);
JERRY_ASSERT (is_ok
&& res.type == JERRY_API_DATA_TYPE_UNDEFINED);
jerry_api_release_value (&res);
JERRY_ASSERT (is_ok
&& res.type == JERRY_API_DATA_TYPE_UNDEFINED);
jerry_api_release_value (&res);
is_ok = (jerry_exec_snapshot (eval_mode_snapshot_buffer,
eval_mode_snapshot_size,
false,
&res) == JERRY_COMPLETION_CODE_OK);
is_ok = (jerry_exec_snapshot (eval_mode_snapshot_buffer,
eval_mode_snapshot_size,
false,
&res) == JERRY_COMPLETION_CODE_OK);
JERRY_ASSERT (is_ok
&& res.type == JERRY_API_DATA_TYPE_STRING);
sz = jerry_api_string_to_char_buffer (res.v_string, NULL, 0);
JERRY_ASSERT (sz == -20);
sz = jerry_api_string_to_char_buffer (res.v_string, (jerry_api_char_t *) buffer, -sz);
JERRY_ASSERT (sz == 20);
jerry_api_release_value (&res);
JERRY_ASSERT (!strncmp (buffer, "string from snapshot", (size_t) sz));
JERRY_ASSERT (is_ok
&& res.type == JERRY_API_DATA_TYPE_STRING);
sz = jerry_api_string_to_char_buffer (res.v_string, NULL, 0);
JERRY_ASSERT (sz == -20);
sz = jerry_api_string_to_char_buffer (res.v_string, (jerry_api_char_t *) buffer, -sz);
JERRY_ASSERT (sz == 20);
jerry_api_release_value (&res);
JERRY_ASSERT (!strncmp (buffer, "string from snapshot", (size_t) sz));
jerry_cleanup ();
jerry_cleanup ();
}
return 0;
}
+9 -14
View File
@@ -13,11 +13,10 @@
* limitations under the License.
*/
#include "bytecode-data.h"
#include "mem-allocator.h"
#include "opcodes.h"
#include "parser.h"
#include "serializer.h"
#include "test-common.h"
static bool
@@ -109,7 +108,7 @@ main (int __attr_unused___ argc,
// #1
char program1[] = "a=1;var a;";
serializer_init ();
lit_init ();
parser_set_show_instrs (true);
parse_status = parser_parse_script ((jerry_api_char_t *) program1, strlen (program1), &bytecode_data_p);
@@ -117,31 +116,27 @@ main (int __attr_unused___ argc,
vm_instr_t instrs[] =
{
getop_meta (OPCODE_META_TYPE_SCOPE_CODE_FLAGS, // [ ]
OPCODE_SCOPE_CODE_FLAGS_NOT_REF_ARGUMENTS_IDENTIFIER
| OPCODE_SCOPE_CODE_FLAGS_NOT_REF_EVAL_IDENTIFIER,
VM_IDX_EMPTY),
getop_reg_var_decl (1u, 0u, 0u),
getop_var_decl (0), // var a;
getop_assignment (VM_REG_GENERAL_FIRST, 1, 1), // $tmp0 = 1;
getop_assignment (0, 6, VM_REG_GENERAL_FIRST), // a = $tmp0;
getop_assignment (0, 1, 1), // a = 1 (SMALLINT);
getop_ret () // return;
};
JERRY_ASSERT (instrs_equal (bytecode_data_p->instrs_p, instrs, 5));
JERRY_ASSERT (instrs_equal (bytecode_data_p->instrs_p, instrs, 3));
serializer_free ();
lit_finalize ();
bc_finalize ();
// #2
char program2[] = "var var;";
serializer_init ();
lit_init ();
parser_set_show_instrs (true);
parse_status = parser_parse_script ((jerry_api_char_t *) program2, strlen (program2), &bytecode_data_p);
JERRY_ASSERT (parse_status == JSP_STATUS_SYNTAX_ERROR && bytecode_data_p == NULL);
serializer_free ();
lit_finalize ();
bc_finalize ();
mem_finalize (false);