Improve storing the line info data during parsing (#4735)

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
This commit is contained in:
Zoltan Herczeg 2021-08-17 08:29:30 +02:00 committed by GitHub
parent fc29019165
commit 74e5ccd434
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 87 additions and 71 deletions

View File

@ -490,7 +490,6 @@ typedef struct
typedef struct
{
parser_mem_page_t *first_page_p; /**< first page of line info data */
parser_mem_page_t *last_page_p; /**< last page of line info data */
uint32_t byte_code_position; /**< last byte code position */
parser_line_counter_t line; /**< last line */
@ -538,7 +537,7 @@ typedef struct parser_saved_context_t
#endif /* !JERRY_NDEBUG */
#if JERRY_LINE_INFO
parser_line_info_data_t line_info; /**< line info data */
parser_line_info_data_t *line_info_p; /**< line info data */
#endif /* JERRY_LINE_INFO */
} parser_saved_context_t;
@ -638,8 +637,7 @@ typedef struct
#endif /* JERRY_DEBUGGER */
#if JERRY_LINE_INFO
parser_line_info_data_t line_info; /**< line info data */
parser_line_counter_t last_line_info_line; /**< last line where line info has been inserted */
parser_line_info_data_t *line_info_p; /**< line info data */
#endif /* JERRY_LINE_INFO */
} parser_context_t;

View File

@ -97,19 +97,43 @@
#define PARSER_LINE_INFO_STREAM_SIZE_LIMIT \
(ECMA_LINE_INFO_STREAM_SIZE_MIN + UINT8_MAX - ((2 * PARSER_LINE_INFO_BUFFER_MAX_SIZE) + 1))
/**
* Page size of line info pages excluding the first one.
*/
#define PARSER_LINE_INFO_PAGE_SIZE \
(sizeof (parser_mem_page_t *) + PARSER_STACK_PAGE_SIZE)
/**
* Page size of the first line info page.
*/
#define PARSER_LINE_INFO_FIRST_PAGE_SIZE \
(sizeof (parser_line_info_data_t) + PARSER_LINE_INFO_PAGE_SIZE)
/**
* Get memory data of the first page.
*/
#define PARSER_LINE_INFO_GET_FIRST_PAGE(line_info_p) \
(((parser_mem_page_t *) ((line_info_p) + 1)))
/**
* Free line info temporary data collected during parsing.
*/
void
parser_line_info_free (parser_line_info_data_t *line_info_p)
{
parser_mem_page_t *current_page_p = line_info_p->first_page_p;
if (line_info_p == NULL)
{
return;
}
parser_mem_page_t *current_page_p = PARSER_LINE_INFO_GET_FIRST_PAGE (line_info_p)->next_p;
parser_free (line_info_p, PARSER_LINE_INFO_FIRST_PAGE_SIZE);
while (current_page_p != NULL)
{
parser_mem_page_t *next_p = current_page_p->next_p;
parser_free (current_page_p, sizeof (parser_mem_page_t *) + PARSER_STACK_PAGE_SIZE);
parser_free (current_page_p, PARSER_LINE_INFO_PAGE_SIZE);
current_page_p = next_p;
}
} /* parser_line_info_free */
@ -204,39 +228,31 @@ static void
parser_line_info_append_number (parser_context_t *context_p, /**< context */
uint32_t value) /**< value to be encoded */
{
parser_line_info_data_t *line_info_p = context_p->line_info_p;
uint8_t buffer[PARSER_LINE_INFO_BUFFER_MAX_SIZE];
JERRY_ASSERT (line_info_p != NULL);
uint32_t length = parser_line_info_encode_vlq (buffer, value);
uint8_t offset = line_info_p->last_page_p->bytes[0];
if (context_p->line_info.last_page_p != NULL
&& context_p->line_info.last_page_p->bytes[0] + length <= PARSER_STACK_PAGE_SIZE)
if (offset + length <= PARSER_STACK_PAGE_SIZE)
{
memcpy (context_p->line_info.last_page_p->bytes + context_p->line_info.last_page_p->bytes[0],
buffer,
length);
memcpy (line_info_p->last_page_p->bytes + offset, buffer, length);
length += context_p->line_info.last_page_p->bytes[0];
context_p->line_info.last_page_p->bytes[0] = (uint8_t) length;
line_info_p->last_page_p->bytes[0] = (uint8_t) (length + offset);
return;
}
size_t size = sizeof (parser_mem_page_t *) + PARSER_STACK_PAGE_SIZE;
parser_mem_page_t *new_page_p = (parser_mem_page_t *) parser_malloc (context_p, size);
parser_mem_page_t *new_page_p;
new_page_p = (parser_mem_page_t *) parser_malloc (context_p, PARSER_LINE_INFO_PAGE_SIZE);
new_page_p->next_p = NULL;
if (context_p->line_info.first_page_p == NULL)
{
context_p->line_info.first_page_p = new_page_p;
context_p->line_info.last_page_p = new_page_p;
}
else
{
context_p->line_info.last_page_p->next_p = new_page_p;
context_p->line_info.last_page_p = new_page_p;
}
line_info_p->last_page_p->next_p = new_page_p;
line_info_p->last_page_p = new_page_p;
context_p->line_info.last_page_p->bytes[0] = (uint8_t) (length + 1);
new_page_p->bytes[0] = (uint8_t) (length + 1);
memcpy (new_page_p->bytes + 1, buffer, length);
} /* parser_line_info_append_number */
@ -248,31 +264,53 @@ parser_line_info_append (parser_context_t *context_p, /**< context */
parser_line_counter_t line, /**< line */
parser_line_counter_t column) /**< column */
{
if (context_p->line_info.first_page_p != NULL
&& (context_p->byte_code_size == context_p->line_info.byte_code_position
|| (context_p->line_info.line == line
&& context_p->line_info.column == column)))
parser_line_info_data_t *line_info_p = context_p->line_info_p;
uint32_t value;
if (line_info_p != NULL)
{
return;
if (line_info_p->byte_code_position == context_p->byte_code_size
|| (line_info_p->line == line && line_info_p->column == column))
{
return;
}
/* Sets ECMA_LINE_INFO_HAS_LINE bit. */
value = (uint32_t) (line != line_info_p->line);
}
else
{
line_info_p = (parser_line_info_data_t *) parser_malloc (context_p, PARSER_LINE_INFO_FIRST_PAGE_SIZE);
context_p->line_info_p = line_info_p;
parser_mem_page_t *page_p = PARSER_LINE_INFO_GET_FIRST_PAGE (line_info_p);
page_p->next_p = NULL;
page_p->bytes[0] = 1;
line_info_p->last_page_p = page_p;
line_info_p->byte_code_position = 0;
line_info_p->line = 1;
line_info_p->column = 1;
/* Sets ECMA_LINE_INFO_HAS_LINE bit. */
value = (uint32_t) (line != 1);
}
/* Sets ECMA_LINE_INFO_HAS_LINE bit. */
uint32_t value = (((context_p->byte_code_size - context_p->line_info.byte_code_position) << 1)
| (uint32_t) (context_p->line_info.line != line));
value |= ((context_p->byte_code_size - line_info_p->byte_code_position) << 1);
parser_line_info_append_number (context_p, value);
context_p->line_info.byte_code_position = context_p->byte_code_size;
line_info_p->byte_code_position = context_p->byte_code_size;
if (value & ECMA_LINE_INFO_HAS_LINE)
{
value = parser_line_info_difference_get (line, context_p->line_info.line);
value = parser_line_info_difference_get (line, line_info_p->line);
parser_line_info_append_number (context_p, value);
context_p->line_info.line = line;
line_info_p->line = line;
}
value = parser_line_info_difference_get (column, context_p->line_info.column);
value = parser_line_info_difference_get (column, line_info_p->column);
parser_line_info_append_number (context_p, value);
context_p->line_info.column = column;
line_info_p->column = column;
} /* parser_line_info_append */
/**
@ -348,7 +386,7 @@ parser_line_info_generate (parser_context_t *context_p) /**< context */
uint32_t stream_value_count = 0;
uint32_t value;
iterator.current_page_p = context_p->line_info.first_page_p;
iterator.current_page_p = PARSER_LINE_INFO_GET_FIRST_PAGE (context_p->line_info_p);
iterator.offset = 1;
do

View File

@ -1830,10 +1830,6 @@ parser_parse_switch_statement_start (parser_context_t *context_p) /**< context *
switch_case_was_found = false;
default_case_was_found = false;
#if JERRY_LINE_INFO
uint32_t last_line_info_line = context_p->last_line_info_line;
#endif /* JERRY_LINE_INFO */
do
{
scanner_set_location (context_p, &case_info_p->location);
@ -1904,10 +1900,6 @@ parser_parse_switch_statement_start (parser_context_t *context_p) /**< context *
JERRY_ASSERT (switch_case_was_found || default_case_was_found);
#if JERRY_LINE_INFO
context_p->last_line_info_line = last_line_info_line;
#endif /* JERRY_LINE_INFO */
if (!switch_case_was_found)
{
/* There was no case statement, so the expression result
@ -2791,10 +2783,6 @@ parser_parse_statements (parser_context_t *context_p) /**< context */
}
#endif /* JERRY_DEBUGGER */
#if JERRY_LINE_INFO
context_p->last_line_info_line = 0;
#endif /* JERRY_LINE_INFO */
while (context_p->token.type == LEXER_LITERAL
&& context_p->token.lit_location.type == LEXER_STRING_LITERAL)
{
@ -3352,7 +3340,7 @@ parser_parse_statements (parser_context_t *context_p) /**< context */
if (context_p->status_flags & PARSER_IS_CLOSURE)
{
#if JERRY_LINE_INFO
if (context_p->line_info.first_page_p == NULL)
if (context_p->line_info_p == NULL)
{
parser_line_info_append (context_p, context_p->token.line, context_p->token.column);
}
@ -3522,7 +3510,7 @@ consume_last_statement:
}
#if JERRY_LINE_INFO
if (context_p->line_info.first_page_p == NULL)
if (context_p->line_info_p == NULL)
{
parser_line_info_append (context_p, context_p->token.line, context_p->token.column);
}

View File

@ -634,7 +634,7 @@ parser_post_processing (parser_context_t *context_p) /**< context */
#endif /* JERRY_ESNEXT */
#if JERRY_LINE_INFO
JERRY_ASSERT (context_p->line_info.first_page_p != NULL);
JERRY_ASSERT (context_p->line_info_p != NULL);
#endif /* JERRY_LINE_INFO */
JERRY_ASSERT (context_p->stack_depth == 0);
@ -1972,11 +1972,7 @@ parser_parse_source (void *source_p, /**< source code */
#endif /* !JERRY_NDEBUG */
#if JERRY_LINE_INFO
context.line_info.first_page_p = NULL;
context.line_info.last_page_p = NULL;
context.line_info.byte_code_position = 0;
context.line_info.line = 1;
context.line_info.column = 1;
context.line_info_p = NULL;
#endif /* JERRY_LINE_INFO */
#if JERRY_PARSER_DUMP_BYTE_CODE
@ -2168,7 +2164,7 @@ parser_parse_source (void *source_p, /**< source code */
}
#if JERRY_LINE_INFO
parser_line_info_free (&context.line_info);
parser_line_info_free (context.line_info_p);
#endif /* JERRY_LINE_INFO */
#if JERRY_PARSER_DUMP_BYTE_CODE
@ -2314,7 +2310,7 @@ parser_save_context (parser_context_t *context_p, /**< context */
#endif /* !JERRY_NDEBUG */
#if JERRY_LINE_INFO
saved_context_p->line_info = context_p->line_info;
saved_context_p->line_info_p = context_p->line_info_p;
#endif /* JERRY_LINE_INFO */
/* Reset private part of the context. */
@ -2349,11 +2345,7 @@ parser_save_context (parser_context_t *context_p, /**< context */
#endif /* !JERRY_NDEBUG */
#if JERRY_LINE_INFO
context_p->line_info.first_page_p = NULL;
context_p->line_info.last_page_p = NULL;
context_p->line_info.byte_code_position = 0;
context_p->line_info.line = 1;
context_p->line_info.column = 1;
context_p->line_info_p = NULL;
#endif /* JERRY_LINE_INFO */
} /* parser_save_context */
@ -2372,7 +2364,7 @@ parser_restore_context (parser_context_t *context_p, /**< context */
}
#if JERRY_LINE_INFO
parser_line_info_free (&context_p->line_info);
parser_line_info_free (context_p->line_info_p);
#endif /* JERRY_LINE_INFO */
/* Restore private part of the context. */
@ -2409,7 +2401,7 @@ parser_restore_context (parser_context_t *context_p, /**< context */
#endif /* !JERRY_NDEBUG */
#if JERRY_LINE_INFO
context_p->line_info = saved_context_p->line_info;
context_p->line_info_p = saved_context_p->line_info_p;
#endif /* JERRY_LINE_INFO */
} /* parser_restore_context */
@ -2768,7 +2760,7 @@ parser_parse_class_fields (parser_context_t *context_p) /**< context */
scanner_set_location (context_p, &end_location);
#if JERRY_LINE_INFO
if (context_p->line_info.first_page_p == NULL)
if (context_p->line_info_p == NULL)
{
parser_line_info_append (context_p, context_p->token.line, context_p->token.column);
}
@ -2959,7 +2951,7 @@ parser_raise_error (parser_context_t *context_p, /**< context */
#endif /* JERRY_ESNEXT */
#if JERRY_LINE_INFO
parser_line_info_free (&saved_context_p->line_info);
parser_line_info_free (saved_context_p->line_info_p);
#endif /* JERRY_LINE_INFO */
saved_context_p = saved_context_p->prev_context_p;