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
@@ -1,128 +0,0 @@
/* Copyright 2014-2015 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "array-list.h"
#include "hash-table.h"
#include "jrt-libc-includes.h"
#include "jsp-mm.h"
typedef struct
{
uint16_t (*hash) (void *);
array_list *data;
uint16_t size;
uint8_t key_size;
uint8_t value_size;
} hash_table_int;
static hash_table_int *
extract_header (hash_table ht)
{
JERRY_ASSERT (ht != null_hash);
hash_table_int *hti = (hash_table_int *) ht;
return hti;
}
static uint8_t
bucket_size (hash_table_int *hti)
{
return (uint8_t) (hti->key_size + hti->value_size);
}
static array_list
get_list (hash_table_int *h, uint16_t i)
{
return h->data[i];
}
static void
set_list (hash_table_int *h, uint16_t i, array_list al)
{
h->data[i] = al;
}
void
hash_table_insert (hash_table ht, void *key, void *value)
{
hash_table_int *hti = extract_header (ht);
uint16_t index = hti->hash (key);
JERRY_ASSERT (index < hti->size);
array_list list = get_list (hti, index);
if (list == null_list)
{
list = array_list_init (bucket_size (hti));
}
uint8_t *bucket = (uint8_t *) jsp_mm_alloc (bucket_size (hti));
memcpy (bucket, key, hti->key_size);
memcpy (bucket + hti->key_size, value, hti->value_size);
list = array_list_append (list, bucket);
hti->data[index] = list;
jsp_mm_free (bucket);
}
void *
hash_table_lookup (hash_table ht, void *key)
{
JERRY_ASSERT (key != NULL);
hash_table_int *h = extract_header (ht);
uint16_t index = h->hash (key);
array_list al = get_list (h, index);
if (al == null_list)
{
return NULL;
}
for (uint16_t i = 0; i < array_list_len (al); i++)
{
uint8_t *bucket = (uint8_t*) array_list_element (al, i);
JERRY_ASSERT (bucket != NULL);
if (!memcmp (bucket, key, h->key_size))
{
return bucket + h->key_size;
}
}
return NULL;
}
hash_table
hash_table_init (uint8_t key_size, uint8_t value_size, uint16_t size,
uint16_t (*hash) (void *))
{
hash_table_int *res = (hash_table_int *) jsp_mm_alloc (sizeof (hash_table_int));
memset (res, 0, sizeof (hash_table_int));
res->key_size = key_size;
res->value_size = value_size;
res->size = size;
res->data = (array_list *) jsp_mm_alloc (size * sizeof (array_list));
memset (res->data, 0, size * sizeof (array_list));
res->hash = hash;
return res;
}
void
hash_table_free (hash_table ht)
{
hash_table_int *h = extract_header (ht);
for (uint16_t i = 0; i < h->size; i++)
{
array_list al = get_list (h, i);
if (al != null_list)
{
array_list_free (al);
set_list (h, i, null_list);
}
}
jsp_mm_free (h->data);
jsp_mm_free (h);
}
@@ -1,38 +0,0 @@
/* Copyright 2014 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
This file contains functions to create and manipulate hash-tables.
Before using the hash initialize it by calling hash_table_init function.
The function takes pointer to hash function as the last parameter.
URGENT: the result of the hash function must not be greater than size of the hash table.
To insert a key-value pair, use hash_table_insert function.
To lookup a value by the key, use hash_table_lookup function.
After using the hash, delete it by calling hash_table_free function.
*/
#ifndef HASH_TABLE_H
#define HASH_TABLE_H
#include "mem-heap.h"
typedef void *hash_table;
#define null_hash NULL
hash_table hash_table_init (uint8_t, uint8_t, uint16_t, uint16_t (*hash) (void *));
void hash_table_free (hash_table);
void hash_table_insert (hash_table, void *, void *);
void *hash_table_lookup (hash_table, void *);
#endif /* HASH_TABLE_H */
@@ -291,7 +291,6 @@ linked_list_remove_element (linked_list list, /**< linked list's identifier */
}
uint8_t *next_elem_iter_p = linked_list_switch_to_next_elem (header_p, &list_chunk_iter_p, element_iter_p);
JERRY_ASSERT (next_elem_iter_p != NULL);
linked_list_chunk_header *chunk_prev_to_chunk_with_last_elem_p = list_chunk_iter_p;
@@ -84,11 +84,12 @@ lit_id_hash_table_free (lit_id_hash_table *table_p) /**< table's header */
} /* lit_id_hash_table_free */
/**
* Register pair in the hash table
* Register literal in the hash table
*
* @return corresponding idx
*/
void
vm_idx_t
lit_id_hash_table_insert (lit_id_hash_table *table_p, /**< table's header */
vm_idx_t uid, /**< value of byte-code instruction's argument */
vm_instr_counter_t oc, /**< instruction counter of the instruction */
lit_cpointer_t lit_cp) /**< literal identifier */
{
@@ -101,8 +102,31 @@ lit_id_hash_table_insert (lit_id_hash_table *table_p, /**< table's header */
table_p->buckets[block_id] = table_p->raw_buckets + table_p->current_bucket_pos;
}
table_p->buckets[block_id][uid] = lit_cp;
table_p->current_bucket_pos++;
lit_cpointer_t *raw_bucket_iter_p = table_p->raw_buckets + table_p->current_bucket_pos;
JERRY_ASSERT (raw_bucket_iter_p >= table_p->buckets[block_id]);
ssize_t bucket_size = (raw_bucket_iter_p - table_p->buckets[block_id]);
int32_t index;
for (index = 0; index < bucket_size; index++)
{
if (table_p->buckets[block_id][index].packed_value == lit_cp.packed_value)
{
break;
}
}
if (index == bucket_size)
{
JERRY_ASSERT ((uint8_t *) (table_p->raw_buckets + table_p->current_bucket_pos) < (uint8_t *) (table_p->buckets));
table_p->buckets[block_id][index] = lit_cp;
table_p->current_bucket_pos++;
}
JERRY_ASSERT (index <= VM_IDX_LITERAL_LAST);
return (vm_idx_t) index;
} /* lit_id_hash_table_insert */
/**
@@ -194,17 +218,8 @@ lit_id_hash_table_dump_for_snapshot (uint8_t *buffer_p, /**< buffer to dump to *
{
lit_cpointer_t lit_cp = table_p->buckets[block_index][block_idx_pair_index];
uint32_t lit_index;
for (lit_index = 0; lit_index < literals_num; lit_index++)
{
if (lit_map_p[lit_index].literal_id.packed_value == lit_cp.packed_value)
{
break;
}
}
JERRY_ASSERT (lit_index < literals_num);
uint32_t offset = bc_find_lit_offset (lit_cp, lit_map_p, literals_num);
uint32_t offset = lit_map_p[lit_index].literal_offset;
if (!jrt_write_to_buffer_by_offset (buffer_p, buffer_size, in_out_buffer_offset_p, offset))
{
return 0;
@@ -31,7 +31,7 @@ typedef struct
lit_id_hash_table *lit_id_hash_table_init (uint8_t *, size_t, size_t, size_t);
size_t lit_id_hash_table_get_size_for_table (size_t, size_t);
void lit_id_hash_table_free (lit_id_hash_table *);
void lit_id_hash_table_insert (lit_id_hash_table *, vm_idx_t, vm_instr_counter_t, lit_cpointer_t);
vm_idx_t lit_id_hash_table_insert (lit_id_hash_table *,vm_instr_counter_t, lit_cpointer_t);
lit_cpointer_t lit_id_hash_table_lookup (lit_id_hash_table *, vm_idx_t, vm_instr_counter_t);
uint32_t lit_id_hash_table_dump_for_snapshot (uint8_t *, size_t, size_t *, lit_id_hash_table *,
const lit_mem_to_snapshot_id_map_entry_t *, uint32_t, vm_instr_counter_t);