Modify the snapshot API functions to expect a 32-bit aligned buffer pointer (#1655)
JerryScript-DCO-1.0-Signed-off-by: Robert Sipka rsipka.uszeged@partner.samsung.com
This commit is contained in:
@@ -226,7 +226,7 @@ ecma_find_or_create_literal_number (ecma_number_t number_arg) /**< number to be
|
||||
* false - otherwise.
|
||||
*/
|
||||
bool
|
||||
ecma_save_literals_for_snapshot (uint8_t *buffer_p, /**< [out] output snapshot buffer */
|
||||
ecma_save_literals_for_snapshot (uint32_t *buffer_p, /**< [out] output snapshot buffer */
|
||||
size_t buffer_size, /**< size of the buffer */
|
||||
size_t *in_out_buffer_offset_p, /**< [in,out] write position in the buffer */
|
||||
lit_mem_to_snapshot_id_map_entry_t **out_map_p, /**< [out] map from literal identifiers
|
||||
@@ -294,7 +294,8 @@ ecma_save_literals_for_snapshot (uint8_t *buffer_p, /**< [out] output snapshot b
|
||||
map_p = jmem_heap_alloc_block (total_count * sizeof (lit_mem_to_snapshot_id_map_entry_t));
|
||||
|
||||
/* Set return values (no error is possible from here). */
|
||||
buffer_p += *in_out_buffer_offset_p;
|
||||
JERRY_ASSERT ((*in_out_buffer_offset_p % sizeof (uint32_t)) == 0);
|
||||
buffer_p += *in_out_buffer_offset_p / sizeof (uint32_t);
|
||||
*in_out_buffer_offset_p += lit_table_size;
|
||||
*out_map_p = map_p;
|
||||
*out_map_len_p = total_count;
|
||||
@@ -306,12 +307,14 @@ ecma_save_literals_for_snapshot (uint8_t *buffer_p, /**< [out] output snapshot b
|
||||
* constant so the first literal must have offset one. */
|
||||
uint32_t literal_offset = JERRY_SNAPSHOT_LITERAL_ALIGNMENT;
|
||||
|
||||
((uint32_t *) buffer_p)[0] = string_count;
|
||||
((uint32_t *) buffer_p)[1] = number_count;
|
||||
buffer_p += 2 * sizeof (uint32_t);
|
||||
buffer_p[0] = string_count;
|
||||
buffer_p[1] = number_count;
|
||||
buffer_p += 2;
|
||||
|
||||
string_list_p = JERRY_CONTEXT (string_list_first_p);
|
||||
|
||||
uint16_t *destination_p = (uint16_t *) buffer_p;
|
||||
|
||||
while (string_list_p != NULL)
|
||||
{
|
||||
for (int i = 0; i < ECMA_LIT_STORAGE_VALUE_COUNT; i++)
|
||||
@@ -327,13 +330,14 @@ ecma_save_literals_for_snapshot (uint8_t *buffer_p, /**< [out] output snapshot b
|
||||
|
||||
ecma_length_t length = ecma_string_get_size (string_p);
|
||||
|
||||
*((uint16_t *) buffer_p) = (uint16_t) length;
|
||||
ecma_string_to_utf8_bytes (string_p, buffer_p + sizeof (uint16_t), length);
|
||||
*destination_p = (uint16_t) length;
|
||||
ecma_string_to_utf8_bytes (string_p, ((lit_utf8_byte_t *) destination_p) + sizeof (uint16_t), length);
|
||||
|
||||
length = JERRY_ALIGNUP (sizeof (uint16_t) + length,
|
||||
JERRY_SNAPSHOT_LITERAL_ALIGNMENT);
|
||||
|
||||
buffer_p += length;
|
||||
JERRY_ASSERT ((length % sizeof (uint16_t)) == 0);
|
||||
destination_p += length / sizeof (uint16_t);
|
||||
literal_offset += length;
|
||||
}
|
||||
}
|
||||
@@ -359,12 +363,13 @@ ecma_save_literals_for_snapshot (uint8_t *buffer_p, /**< [out] output snapshot b
|
||||
JERRY_ASSERT (ECMA_STRING_GET_CONTAINER (value_p) == ECMA_STRING_LITERAL_NUMBER);
|
||||
|
||||
ecma_number_t num = ecma_get_number_from_value (value_p->u.lit_number);
|
||||
memcpy (buffer_p, &num, sizeof (ecma_number_t));
|
||||
memcpy (destination_p, &num, sizeof (ecma_number_t));
|
||||
|
||||
ecma_length_t length = JERRY_ALIGNUP (sizeof (ecma_number_t),
|
||||
JERRY_SNAPSHOT_LITERAL_ALIGNMENT);
|
||||
|
||||
buffer_p += length;
|
||||
JERRY_ASSERT ((length % sizeof (uint16_t)) == 0);
|
||||
destination_p += length / sizeof (uint16_t);
|
||||
literal_offset += length;
|
||||
}
|
||||
}
|
||||
@@ -388,7 +393,7 @@ ecma_save_literals_for_snapshot (uint8_t *buffer_p, /**< [out] output snapshot b
|
||||
* false - otherwise (i.e. buffer length is incorrect).
|
||||
*/
|
||||
static inline bool __attr_always_inline___
|
||||
ecma_load_literals_from_buffer (const uint8_t *buffer_p, /**< buffer with literal table in snapshot */
|
||||
ecma_load_literals_from_buffer (const uint16_t *buffer_p, /**< buffer with literal table in snapshot */
|
||||
uint32_t lit_table_size, /**< size of literal table in snapshot */
|
||||
lit_mem_to_snapshot_id_map_entry_t *map_p, /**< literal map */
|
||||
uint32_t string_count, /**< number of strings */
|
||||
@@ -407,7 +412,7 @@ ecma_load_literals_from_buffer (const uint8_t *buffer_p, /**< buffer with litera
|
||||
return false;
|
||||
}
|
||||
|
||||
lit_utf8_size_t length = *((uint16_t *) buffer_p);
|
||||
lit_utf8_size_t length = *buffer_p;
|
||||
lit_utf8_size_t aligned_length = JERRY_ALIGNUP (sizeof (uint16_t) + length,
|
||||
JERRY_SNAPSHOT_LITERAL_ALIGNMENT);
|
||||
|
||||
@@ -417,11 +422,12 @@ ecma_load_literals_from_buffer (const uint8_t *buffer_p, /**< buffer with litera
|
||||
return false;
|
||||
}
|
||||
|
||||
map_p->literal_id = ecma_find_or_create_literal_string (buffer_p + sizeof (uint16_t), length);
|
||||
map_p->literal_id = ecma_find_or_create_literal_string (((lit_utf8_byte_t *) buffer_p) + sizeof (uint16_t), length);
|
||||
map_p->literal_offset = (jmem_cpointer_t) (literal_offset >> JERRY_SNAPSHOT_LITERAL_ALIGNMENT_LOG);
|
||||
map_p++;
|
||||
|
||||
buffer_p += aligned_length;
|
||||
JERRY_ASSERT ((aligned_length % sizeof (uint16_t)) == 0);
|
||||
buffer_p += aligned_length / sizeof (uint16_t);
|
||||
literal_offset += aligned_length;
|
||||
|
||||
string_count--;
|
||||
@@ -446,7 +452,8 @@ ecma_load_literals_from_buffer (const uint8_t *buffer_p, /**< buffer with litera
|
||||
ecma_length_t length = JERRY_ALIGNUP (sizeof (ecma_number_t),
|
||||
JERRY_SNAPSHOT_LITERAL_ALIGNMENT);
|
||||
|
||||
buffer_p += length;
|
||||
JERRY_ASSERT ((length % sizeof (uint16_t)) == 0);
|
||||
buffer_p += length / sizeof (uint16_t);
|
||||
literal_offset += length;
|
||||
|
||||
number_count--;
|
||||
@@ -462,7 +469,7 @@ ecma_load_literals_from_buffer (const uint8_t *buffer_p, /**< buffer with litera
|
||||
* false - otherwise (i.e. snapshot is incorrect).
|
||||
*/
|
||||
bool
|
||||
ecma_load_literals_from_snapshot (const uint8_t *buffer_p, /**< buffer with literal table in snapshot */
|
||||
ecma_load_literals_from_snapshot (const uint32_t *buffer_p, /**< buffer with literal table in snapshot */
|
||||
uint32_t lit_table_size, /**< size of literal table in snapshot */
|
||||
lit_mem_to_snapshot_id_map_entry_t **out_map_p, /**< [out] map from literal offsets
|
||||
* in snapshot to identifiers
|
||||
@@ -478,9 +485,9 @@ ecma_load_literals_from_snapshot (const uint8_t *buffer_p, /**< buffer with lite
|
||||
return false;
|
||||
}
|
||||
|
||||
uint32_t string_count = ((uint32_t *) buffer_p)[0];
|
||||
uint32_t number_count = ((uint32_t *) buffer_p)[1];
|
||||
buffer_p += 2 * sizeof (uint32_t);
|
||||
uint32_t string_count = buffer_p[0];
|
||||
uint32_t number_count = buffer_p[1];
|
||||
buffer_p += 2;
|
||||
|
||||
uint32_t total_count = string_count + number_count;
|
||||
lit_mem_to_snapshot_id_map_entry_t *map_p;
|
||||
@@ -495,7 +502,7 @@ ecma_load_literals_from_snapshot (const uint8_t *buffer_p, /**< buffer with lite
|
||||
map_p = jmem_heap_alloc_block (total_count * sizeof (lit_mem_to_snapshot_id_map_entry_t));
|
||||
*out_map_p = map_p;
|
||||
|
||||
if (ecma_load_literals_from_buffer (buffer_p, lit_table_size, map_p, string_count, number_count))
|
||||
if (ecma_load_literals_from_buffer ((uint16_t *) buffer_p, lit_table_size, map_p, string_count, number_count))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -43,13 +43,13 @@ jmem_cpointer_t ecma_find_or_create_literal_number (ecma_number_t number_arg);
|
||||
|
||||
#ifdef JERRY_ENABLE_SNAPSHOT_SAVE
|
||||
bool
|
||||
ecma_save_literals_for_snapshot (uint8_t *, size_t, size_t *,
|
||||
ecma_save_literals_for_snapshot (uint32_t *, size_t, size_t *,
|
||||
lit_mem_to_snapshot_id_map_entry_t **, uint32_t *, uint32_t *);
|
||||
#endif /* JERRY_ENABLE_SNAPSHOT_SAVE */
|
||||
|
||||
#ifdef JERRY_ENABLE_SNAPSHOT_EXEC
|
||||
bool
|
||||
ecma_load_literals_from_snapshot (const uint8_t *, uint32_t,
|
||||
ecma_load_literals_from_snapshot (const uint32_t *, uint32_t,
|
||||
lit_mem_to_snapshot_id_map_entry_t **, uint32_t *);
|
||||
#endif /* JERRY_ENABLE_SNAPSHOT_EXEC */
|
||||
|
||||
|
||||
Reference in New Issue
Block a user