-
Notifications
You must be signed in to change notification settings - Fork 683
Literal storage #148
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
Literal storage #148
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -66,9 +66,9 @@ static ecma_length_t ecma_magic_string_max_length; | |
#endif /* !JERRY_NDEBUG */ | ||
|
||
static void | ||
ecma_init_ecma_string_from_lit_index (ecma_string_t *string_p, | ||
literal_index_t lit_index, | ||
bool is_stack_var); | ||
ecma_init_ecma_string_from_lit_cp (ecma_string_t *string_p, | ||
lit_cpointer_t lit_index, | ||
bool is_stack_var); | ||
static void | ||
ecma_init_ecma_string_from_magic_string_id (ecma_string_t *string_p, | ||
ecma_magic_string_id_t magic_string_id, | ||
|
@@ -370,42 +370,42 @@ ecma_get_magic_string_ex_count (void) | |
* Initialize ecma-string descriptor with string described by index in literal table | ||
*/ | ||
static void | ||
ecma_init_ecma_string_from_lit_index (ecma_string_t *string_p, /**< descriptor to initialize */ | ||
literal_index_t lit_index, /**< index in the literal table */ | ||
bool is_stack_var) /**< flag indicating whether the string descriptor | ||
ecma_init_ecma_string_from_lit_cp (ecma_string_t *string_p, /**< descriptor to initialize */ | ||
lit_cpointer_t lit_cp, /**< compressed pointer to literal */ | ||
bool is_stack_var) /**< flag indicating whether the string descriptor | ||
is placed on stack (true) or in the heap (false) */ | ||
{ | ||
#ifndef JERRY_NDEBUG | ||
JERRY_ASSERT (is_stack_var == (!mem_is_heap_pointer (string_p))); | ||
#endif /* !JERRY_NDEBUG */ | ||
|
||
const literal lit = serializer_get_literal_by_id (lit_index); | ||
if (lit.type == LIT_MAGIC_STR) | ||
literal_t lit = lit_get_literal_by_cp (lit_cp); | ||
if (lit->get_type () == LIT_MAGIC_STR_T) | ||
{ | ||
ecma_init_ecma_string_from_magic_string_id (string_p, | ||
lit.data.magic_str_id, | ||
lit_magic_record_get_magic_str_id (lit), | ||
is_stack_var); | ||
|
||
return; | ||
} | ||
else if (lit.type == LIT_MAGIC_STR_EX) | ||
else if (lit->get_type () == LIT_MAGIC_STR_EX_T) | ||
{ | ||
ecma_init_ecma_string_from_magic_string_ex_id (string_p, | ||
lit.data.magic_str_ex_id, | ||
lit_magic_record_ex_get_magic_str_id (lit), | ||
is_stack_var); | ||
|
||
return; | ||
} | ||
JERRY_ASSERT (lit.type == LIT_STR); | ||
|
||
JERRY_ASSERT (lit->get_type () == LIT_STR_T); | ||
|
||
string_p->refs = 1; | ||
string_p->is_stack_var = (is_stack_var != 0); | ||
string_p->container = ECMA_STRING_CONTAINER_LIT_TABLE; | ||
string_p->hash = lit.data.lp.hash; | ||
string_p->hash = lit_charset_literal_get_hash (lit); | ||
|
||
string_p->u.common_field = 0; | ||
string_p->u.lit_index = lit_index; | ||
} /* ecma_init_ecma_string_from_lit_index */ | ||
string_p->u.lit_cp = lit_cp; | ||
} /* ecma_init_ecma_string_from_lit_cp */ | ||
|
||
/** | ||
* Initialize ecma-string descriptor with specified magic string | ||
|
@@ -591,27 +591,27 @@ ecma_new_ecma_string_from_number (ecma_number_t num) /**< ecma-number */ | |
* with string described by index in literal table | ||
*/ | ||
void | ||
ecma_new_ecma_string_on_stack_from_lit_index (ecma_string_t *string_p, /**< pointer to the ecma-string | ||
ecma_new_ecma_string_on_stack_from_lit_cp (ecma_string_t *string_p, /**< pointer to the ecma-string | ||
descriptor to initialize */ | ||
literal_index_t lit_index) /**< index in the literal table */ | ||
lit_cpointer_t lit_cp) /**< compressed pointer to literal */ | ||
{ | ||
ecma_init_ecma_string_from_lit_index (string_p, lit_index, true); | ||
} /* ecma_new_ecma_string_on_stack_from_lit_index */ | ||
ecma_init_ecma_string_from_lit_cp (string_p, lit_cp, true); | ||
} /* ecma_new_ecma_string_on_stack_from_lit_cp */ | ||
|
||
/** | ||
* Allocate new ecma-string and fill it with reference to string literal | ||
* | ||
* @return pointer to ecma-string descriptor | ||
*/ | ||
ecma_string_t* | ||
ecma_new_ecma_string_from_lit_index (literal_index_t lit_index) /**< index in the literal table */ | ||
ecma_new_ecma_string_from_lit_cp (lit_cpointer_t lit_cp) /**< index in the literal table */ | ||
{ | ||
ecma_string_t* string_desc_p = ecma_alloc_string (); | ||
|
||
ecma_init_ecma_string_from_lit_index (string_desc_p, lit_index, false); | ||
ecma_init_ecma_string_from_lit_cp (string_desc_p, lit_cp, false); | ||
|
||
return string_desc_p; | ||
} /* ecma_new_ecma_string_from_lit_index */ | ||
} /* ecma_new_ecma_string_from_lit_cp */ | ||
|
||
/** | ||
* Initialize ecma-string descriptor placed on stack with specified magic string | ||
|
@@ -1037,13 +1037,9 @@ ecma_string_to_zt_string (const ecma_string_t *string_desc_p, /**< ecma-string d | |
} | ||
case ECMA_STRING_CONTAINER_LIT_TABLE: | ||
{ | ||
const literal lit = serializer_get_literal_by_id (string_desc_p->u.lit_index); | ||
JERRY_ASSERT (lit.type == LIT_STR); | ||
const ecma_char_t *str_p = literal_to_zt (lit); | ||
JERRY_ASSERT (str_p != NULL); | ||
|
||
ecma_copy_zt_string_to_buffer (str_p, buffer_p, required_buffer_size); | ||
|
||
literal_t lit = lit_get_literal_by_cp (string_desc_p->u.lit_cp); | ||
JERRY_ASSERT (lit->get_type () == LIT_STR_T); | ||
lit_literal_to_charset (lit, buffer_p, (size_t) required_buffer_size); | ||
break; | ||
} | ||
case ECMA_STRING_CONTAINER_UINT32_IN_DESC: | ||
|
@@ -1141,7 +1137,7 @@ ecma_compare_ecma_strings_longpath (const ecma_string_t *string1_p, /* ecma-stri | |
{ | ||
if (string1_p->container == ECMA_STRING_CONTAINER_LIT_TABLE) | ||
{ | ||
JERRY_ASSERT (string1_p->u.lit_index != string2_p->u.lit_index); | ||
JERRY_ASSERT (string1_p->u.lit_cp.packed_value != string2_p->u.lit_cp.packed_value); | ||
|
||
return false; | ||
} | ||
|
@@ -1214,7 +1210,7 @@ ecma_compare_ecma_strings_longpath (const ecma_string_t *string1_p, /* ecma-stri | |
} | ||
case ECMA_STRING_CONTAINER_LIT_TABLE: | ||
{ | ||
JERRY_ASSERT (string1_p->u.lit_index != string2_p->u.lit_index); | ||
JERRY_ASSERT (string1_p->u.lit_cp.packed_value != string2_p->u.lit_cp.packed_value); | ||
|
||
return false; | ||
} | ||
|
@@ -1346,74 +1342,56 @@ ecma_compare_ecma_strings_relational (const ecma_string_t *string1_p, /**< ecma- | |
ecma_char_t zt_string1_buffer[ECMA_MAX_CHARS_IN_STRINGIFIED_NUMBER + 1]; | ||
ecma_char_t zt_string2_buffer[ECMA_MAX_CHARS_IN_STRINGIFIED_NUMBER + 1]; | ||
|
||
if (string1_p->container == ECMA_STRING_CONTAINER_LIT_TABLE) | ||
{ | ||
const literal lit = serializer_get_literal_by_id (string1_p->u.lit_index); | ||
JERRY_ASSERT (lit.type == LIT_STR); | ||
zt_string1_p = literal_to_zt (lit); | ||
} | ||
else | ||
{ | ||
ssize_t req_size = ecma_string_to_zt_string (string1_p, | ||
zt_string1_buffer, | ||
sizeof (zt_string1_buffer)); | ||
ssize_t req_size = ecma_string_to_zt_string (string1_p, | ||
zt_string1_buffer, | ||
sizeof (zt_string1_buffer)); | ||
|
||
if (req_size < 0) | ||
if (req_size < 0) | ||
{ | ||
ecma_char_t *heap_buffer_p = (ecma_char_t*) mem_heap_alloc_block ((size_t) -req_size, MEM_HEAP_ALLOC_SHORT_TERM); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Call to |
||
if (heap_buffer_p == NULL) | ||
{ | ||
ecma_char_t *heap_buffer_p = (ecma_char_t*) mem_heap_alloc_block ((size_t) -req_size, MEM_HEAP_ALLOC_SHORT_TERM); | ||
if (heap_buffer_p == NULL) | ||
{ | ||
jerry_fatal (ERR_OUT_OF_MEMORY); | ||
} | ||
jerry_fatal (ERR_OUT_OF_MEMORY); | ||
} | ||
|
||
ssize_t bytes_copied = ecma_string_to_zt_string (string1_p, | ||
heap_buffer_p, | ||
-req_size); | ||
ssize_t bytes_copied = ecma_string_to_zt_string (string1_p, | ||
heap_buffer_p, | ||
-req_size); | ||
|
||
JERRY_ASSERT (bytes_copied > 0); | ||
JERRY_ASSERT (bytes_copied > 0); | ||
|
||
zt_string1_p = heap_buffer_p; | ||
is_zt_string1_on_heap = true; | ||
} | ||
else | ||
{ | ||
zt_string1_p = zt_string1_buffer; | ||
} | ||
} | ||
|
||
if (string2_p->container == ECMA_STRING_CONTAINER_LIT_TABLE) | ||
{ | ||
const literal lit = serializer_get_literal_by_id (string2_p->u.lit_index); | ||
JERRY_ASSERT (lit.type == LIT_STR); | ||
zt_string2_p = literal_to_zt (lit); | ||
zt_string1_p = heap_buffer_p; | ||
is_zt_string1_on_heap = true; | ||
} | ||
else | ||
{ | ||
ssize_t req_size = ecma_string_to_zt_string (string2_p, | ||
zt_string2_buffer, | ||
sizeof (zt_string2_buffer)); | ||
zt_string1_p = zt_string1_buffer; | ||
} | ||
|
||
if (req_size < 0) | ||
req_size = ecma_string_to_zt_string (string2_p, | ||
zt_string2_buffer, | ||
sizeof (zt_string2_buffer)); | ||
|
||
if (req_size < 0) | ||
{ | ||
ecma_char_t *heap_buffer_p = (ecma_char_t*) mem_heap_alloc_block ((size_t) -req_size, MEM_HEAP_ALLOC_SHORT_TERM); | ||
if (heap_buffer_p == NULL) | ||
{ | ||
ecma_char_t *heap_buffer_p = (ecma_char_t*) mem_heap_alloc_block ((size_t) -req_size, MEM_HEAP_ALLOC_SHORT_TERM); | ||
if (heap_buffer_p == NULL) | ||
{ | ||
jerry_fatal (ERR_OUT_OF_MEMORY); | ||
} | ||
jerry_fatal (ERR_OUT_OF_MEMORY); | ||
} | ||
|
||
ssize_t bytes_copied = ecma_string_to_zt_string (string2_p, | ||
heap_buffer_p, | ||
-req_size); | ||
ssize_t bytes_copied = ecma_string_to_zt_string (string2_p, | ||
heap_buffer_p, | ||
-req_size); | ||
|
||
JERRY_ASSERT (bytes_copied > 0); | ||
JERRY_ASSERT (bytes_copied > 0); | ||
|
||
zt_string2_p = heap_buffer_p; | ||
is_zt_string2_on_heap = true; | ||
} | ||
else | ||
{ | ||
zt_string2_p = zt_string2_buffer; | ||
} | ||
zt_string2_p = heap_buffer_p; | ||
is_zt_string2_on_heap = true; | ||
} | ||
else | ||
{ | ||
zt_string2_p = zt_string2_buffer; | ||
} | ||
|
||
bool is_first_less_than_second = ecma_compare_zt_strings_relational (zt_string1_p, | ||
|
@@ -1445,9 +1423,9 @@ ecma_string_get_length (const ecma_string_t *string_p) /**< ecma-string */ | |
|
||
if (container == ECMA_STRING_CONTAINER_LIT_TABLE) | ||
{ | ||
const literal lit = serializer_get_literal_by_id (string_p->u.lit_index); | ||
|
||
return lit.data.lp.length; | ||
literal_t lit = lit_get_literal_by_cp (string_p->u.lit_cp); | ||
JERRY_ASSERT (lit->get_type () == LIT_STR_T); | ||
return lit_charset_record_get_length (lit); | ||
} | ||
else if (container == ECMA_STRING_CONTAINER_MAGIC_STRING) | ||
{ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -214,4 +214,16 @@ extern void __noreturn jerry_fatal (jerry_fatal_code_t code); | |
#define JERRY_MIN(v1, v2) ((v1 < v2) ? v1 : v2) | ||
#define JERRY_MAX(v1, v2) ((v1 < v2) ? v2 : v1) | ||
|
||
/** | ||
* Placement new operator (constructs an object on a pre-allocated buffer) | ||
* | ||
* Our version of the libc library doesn't support calling the constructors and destructors of the static variables. | ||
* It is proposed to use placement new operator. Generally it is available via #include <new>, | ||
* To fix the unavailability of the header in some configurations placement new operator is implemented here. | ||
*/ | ||
inline void* operator new (size_t, void* where) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please, add comment to the code with proper explanation. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok |
||
{ | ||
return where; | ||
} /* operator new */ | ||
|
||
#endif /* !JERRY_GLOBALS_H */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we move this to lit-literal.h?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ruben-ayrapetyan I suppose we should, but
ecma-globals.h
has dependencies onlit_cpointer_t
, whilelit_*
depends onecma_globals.h
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@egavrin, I see. In the case, probably we should update the 'FIXME' comment above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ruben-ayrapetyan we may leave it as is, since we're going to fix anyway. But with a separate pr.