Support for JIT code free and small partial match optimization.

This commit is contained in:
Zoltán Herczeg 2014-10-09 10:06:19 +00:00
parent 62746ceb10
commit 0907fc6e92
4 changed files with 25 additions and 11 deletions

View File

@ -677,7 +677,8 @@ pcre2_code_free(pcre2_code *code)
{
if (code != NULL)
{
if (code->executable_jit != NULL) PRIV(jit_free(code->executable_jit));
if (code->executable_jit != NULL)
PRIV(jit_free)(code->executable_jit, &code->memctl);
code->memctl.free(code, code->memctl.memory_data);
}
}

View File

@ -1878,7 +1878,7 @@ extern void _pcre2_compile_context_init(pcre2_compile_context *, BOOL);
extern PCRE2_SPTR _pcre2_find_bracket(PCRE2_SPTR, BOOL, int);
extern BOOL _pcre2_is_newline(PCRE2_SPTR, uint32_t, PCRE2_SPTR, uint32_t *,
BOOL);
extern void _pcre2_jit_free(void *);
extern void _pcre2_jit_free(void *, pcre2_memctl *);
extern size_t _pcre2_jit_get_size(void *);
extern void _pcre2_match_context_init(pcre2_match_context *, BOOL);
extern void *_pcre2_memctl_malloc(size_t, pcre2_memctl *);

View File

@ -352,6 +352,8 @@ typedef struct compiler_common {
int cbra_ptr;
/* Output vector starting point. Must be divisible by 2. */
int ovector_start;
/* Points to the starting character of the current match. */
int start_ptr;
/* Last known position of the requested byte. */
int req_char_ptr;
/* Head of the last recursion. */
@ -369,8 +371,6 @@ typedef struct compiler_common {
int control_head_ptr;
/* Points to the last matched capture block index. */
int capture_last_ptr;
/* Points to the starting position of the current match. */
int start_ptr;
/* Flipped and lower case tables. */
const sljit_ub *fcc;
@ -2271,7 +2271,7 @@ SLJIT_ASSERT(common->start_used_ptr != 0 && common->start_ptr != 0
OP1(SLJIT_MOV, SLJIT_R1, 0, ARGUMENTS, 0);
OP1(SLJIT_MOV, SLJIT_R2, 0, SLJIT_MEM1(SLJIT_SP),
common->mode == PCRE2_JIT_PARTIAL_SOFT ? (common->hit_start + sizeof(sljit_sw)) : common->start_ptr);
common->mode == PCRE2_JIT_PARTIAL_SOFT ? common->hit_start : common->start_ptr);
OP1(SLJIT_MOV, SLJIT_RETURN_REG, 0, SLJIT_IMM, PCRE2_ERROR_PARTIAL);
/* Store match begin and end. */
@ -9851,7 +9851,7 @@ if (mode != PCRE2_JIT_COMPLETE)
if (mode == PCRE2_JIT_PARTIAL_SOFT)
{
common->hit_start = common->ovector_start;
common->ovector_start += 2 * sizeof(sljit_sw);
common->ovector_start += sizeof(sljit_sw);
}
}
if ((re->overall_options & PCRE2_FIRSTLINE) != 0)
@ -10015,7 +10015,6 @@ if (mode == PCRE2_JIT_PARTIAL_SOFT)
{
jump = CMP(SLJIT_NOT_EQUAL, SLJIT_MEM1(SLJIT_SP), common->hit_start, SLJIT_IMM, -1);
OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), common->start_used_ptr, STR_PTR, 0);
OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), common->hit_start + sizeof(sljit_sw), STR_PTR, 0);
JUMPHERE(jump);
}
else if (mode == PCRE2_JIT_PARTIAL_HARD)
@ -10080,7 +10079,7 @@ if (mode == PCRE2_JIT_PARTIAL_SOFT)
{
/* Update hit_start only in the first time. */
jump = CMP(SLJIT_NOT_EQUAL, SLJIT_MEM1(SLJIT_SP), common->hit_start, SLJIT_IMM, 0);
OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), common->start_used_ptr);
OP1(SLJIT_MOV, TMP1, 0, SLJIT_MEM1(SLJIT_SP), common->start_ptr);
OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), common->start_used_ptr, SLJIT_IMM, -1);
OP1(SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), common->hit_start, TMP1, 0);
JUMPHERE(jump);
@ -10305,6 +10304,7 @@ if (mode == PCRE2_JIT_COMPLETE)
else
mode = (mode == PCRE2_JIT_PARTIAL_SOFT) ? 1 : 2;
SLJIT_ASSERT(mode >= 0 && mode < JIT_NUMBER_OF_COMPILE_MODES);
functions->executable_funcs[mode] = executable_func;
functions->read_only_data[mode] = common->read_only_data;
functions->executable_sizes[mode] = executable_size;

View File

@ -50,14 +50,26 @@ POSSIBILITY OF SUCH DAMAGE.
*************************************************/
void
PRIV(jit_free)(void *executable_jit)
PRIV(jit_free)(void *executable_jit, pcre2_memctl *memctl)
{
#ifndef SUPPORT_JIT
(void)executable_jit;
(void)memctl;
#else /* SUPPORT_JIT */
/* Dummy code */
(void)executable_jit;
executable_functions *functions = (executable_functions *)executable_jit;
void *allocator_data = memctl;
int i;
for (i = 0; i < JIT_NUMBER_OF_COMPILE_MODES; i++)
{
if (functions->executable_funcs[i] != NULL)
sljit_free_code(functions->executable_funcs[i]);
if (functions->read_only_data[i] != NULL)
SLJIT_FREE(functions->read_only_data[i], allocator_data);
}
SLJIT_FREE(functions, allocator_data);
#endif /* SUPPORT_JIT */
}
@ -192,6 +204,7 @@ return 0;
#else /* SUPPORT_JIT */
sljit_uw *executable_sizes = ((executable_functions *)executable_jit)->executable_sizes;
SLJIT_COMPILE_ASSERT(JIT_NUMBER_OF_COMPILE_MODES == 3, number_of_compile_modes_changed);
return executable_sizes[0] + executable_sizes[1] + executable_sizes[2];
#endif