Skip to content

Commit 7a23313

Browse files
committed
Document JIT compile size limit and give more info in pcre2test.
1 parent 860b6f2 commit 7a23313

File tree

4 files changed

+39
-18
lines changed

4 files changed

+39
-18
lines changed

ChangeLog

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,9 @@ newline sequence.
304304
90. Run test 8 (internal offsets and code sizes) for link sizes 3 and 4 as well
305305
as for link size 2.
306306

307+
91. Document that JIT has a limit on pattern size, and give more information
308+
about JIT compile failures in pcre2test.
309+
307310

308311
Version 10.20 30-June-2015
309312
--------------------------

doc/pcre2jit.3

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.TH PCRE2JIT 3 "28 July 2014" "PCRE2 10.21"
1+
.TH PCRE2JIT 3 "14 November 2015" "PCRE2 10.21"
22
.SH NAME
33
PCRE2 - Perl-compatible regular expressions (revised API)
44
.SH "PCRE2 JUST-IN-TIME COMPILER SUPPORT"
@@ -61,6 +61,12 @@ much faster than the normal interpretive code, but yields exactly the same
6161
results. The returned value from \fBpcre2_jit_compile()\fP is zero on success,
6262
or a negative error code.
6363
.P
64+
There is a limit to the size of pattern that JIT supports, imposed by the size
65+
of machine stack that it uses. The exact rules are not documented because they
66+
may change at any time, in particular, when new optimizations are introduced.
67+
If a pattern is too big, a call to \fBpcre2_jit_compile()\fB returns
68+
PCRE2_ERROR_NOMEMORY.
69+
.P
6470
PCRE2_JIT_COMPLETE requests the JIT compiler to generate code for complete
6571
matches. If you want to run partial matches using the PCRE2_PARTIAL_HARD or
6672
PCRE2_PARTIAL_SOFT options of \fBpcre2_match()\fP, you should set one or both
@@ -404,6 +410,6 @@ Cambridge, England.
404410
.rs
405411
.sp
406412
.nf
407-
Last updated: 28 July 2015
413+
Last updated: 14 November 2015
408414
Copyright (c) 1997-2015 University of Cambridge.
409415
.fi

src/pcre2test.c

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -735,6 +735,7 @@ static BOOL restrict_for_perl_test = FALSE;
735735
static BOOL show_memory = FALSE;
736736

737737
static int code_unit_size; /* Bytes */
738+
static int jitrc; /* Return from JIT compile */
738739
static int test_mode = DEFAULT_TEST_MODE;
739740
static int timeit = 0;
740741
static int timeitm = 0;
@@ -936,10 +937,10 @@ are supported. */
936937
else \
937938
a = pcre2_get_startchar_32(G(b,32))
938939

939-
#define PCRE2_JIT_COMPILE(a,b) \
940-
if (test_mode == PCRE8_MODE) pcre2_jit_compile_8(G(a,8),b); \
941-
else if (test_mode == PCRE16_MODE) pcre2_jit_compile_16(G(a,16),b); \
942-
else pcre2_jit_compile_32(G(a,32),b)
940+
#define PCRE2_JIT_COMPILE(r,a,b) \
941+
if (test_mode == PCRE8_MODE) r = pcre2_jit_compile_8(G(a,8),b); \
942+
else if (test_mode == PCRE16_MODE) r = pcre2_jit_compile_16(G(a,16),b); \
943+
else r = pcre2_jit_compile_32(G(a,32),b)
943944

944945
#define PCRE2_JIT_FREE_UNUSED_MEMORY(a) \
945946
if (test_mode == PCRE8_MODE) pcre2_jit_free_unused_memory_8(G(a,8)); \
@@ -1379,11 +1380,11 @@ the three different cases. */
13791380
else \
13801381
a = G(pcre2_get_startchar_,BITTWO)(G(b,BITTWO))
13811382

1382-
#define PCRE2_JIT_COMPILE(a,b) \
1383+
#define PCRE2_JIT_COMPILE(r,a,b) \
13831384
if (test_mode == G(G(PCRE,BITONE),_MODE)) \
1384-
G(pcre2_jit_compile_,BITONE)(G(a,BITONE),b); \
1385+
r = G(pcre2_jit_compile_,BITONE)(G(a,BITONE),b); \
13851386
else \
1386-
G(pcre2_jit_compile_,BITTWO)(G(a,BITTWO),b)
1387+
r = G(pcre2_jit_compile_,BITTWO)(G(a,BITTWO),b)
13871388

13881389
#define PCRE2_JIT_FREE_UNUSED_MEMORY(a) \
13891390
if (test_mode == G(G(PCRE,BITONE),_MODE)) \
@@ -1690,7 +1691,7 @@ the three different cases. */
16901691
r = pcre2_get_error_message_8(a,G(b,8),G(G(b,8),_size))
16911692
#define PCRE2_GET_OVECTOR_COUNT(a,b) a = pcre2_get_ovector_count_8(G(b,8))
16921693
#define PCRE2_GET_STARTCHAR(a,b) a = pcre2_get_startchar_8(G(b,8))
1693-
#define PCRE2_JIT_COMPILE(a,b) pcre2_jit_compile_8(G(a,8),b)
1694+
#define PCRE2_JIT_COMPILE(r,a,b) r = pcre2_jit_compile_8(G(a,8),b)
16941695
#define PCRE2_JIT_FREE_UNUSED_MEMORY(a) pcre2_jit_free_unused_memory_8(G(a,8))
16951696
#define PCRE2_JIT_MATCH(a,b,c,d,e,f,g,h) \
16961697
a = pcre2_jit_match_8(G(b,8),(PCRE2_SPTR8)c,d,e,f,G(g,8),h)
@@ -1783,7 +1784,7 @@ the three different cases. */
17831784
r = pcre2_get_error_message_16(a,G(b,16),G(G(b,16),_size))
17841785
#define PCRE2_GET_OVECTOR_COUNT(a,b) a = pcre2_get_ovector_count_16(G(b,16))
17851786
#define PCRE2_GET_STARTCHAR(a,b) a = pcre2_get_startchar_16(G(b,16))
1786-
#define PCRE2_JIT_COMPILE(a,b) pcre2_jit_compile_16(G(a,16),b)
1787+
#define PCRE2_JIT_COMPILE(r,a,b) r = pcre2_jit_compile_16(G(a,16),b)
17871788
#define PCRE2_JIT_FREE_UNUSED_MEMORY(a) pcre2_jit_free_unused_memory_16(G(a,16))
17881789
#define PCRE2_JIT_MATCH(a,b,c,d,e,f,g,h) \
17891790
a = pcre2_jit_match_16(G(b,16),(PCRE2_SPTR16)c,d,e,f,G(g,16),h)
@@ -1876,7 +1877,7 @@ the three different cases. */
18761877
r = pcre2_get_error_message_32(a,G(b,32),G(G(b,32),_size))
18771878
#define PCRE2_GET_OVECTOR_COUNT(a,b) a = pcre2_get_ovector_count_32(G(b,32))
18781879
#define PCRE2_GET_STARTCHAR(a,b) a = pcre2_get_startchar_32(G(b,32))
1879-
#define PCRE2_JIT_COMPILE(a,b) pcre2_jit_compile_32(G(a,32),b)
1880+
#define PCRE2_JIT_COMPILE(r,a,b) r = pcre2_jit_compile_32(G(a,32),b)
18801881
#define PCRE2_JIT_FREE_UNUSED_MEMORY(a) pcre2_jit_free_unused_memory_32(G(a,32))
18811882
#define PCRE2_JIT_MATCH(a,b,c,d,e,f,g,h) \
18821883
a = pcre2_jit_match_32(G(b,32),(PCRE2_SPTR32)c,d,e,f,G(g,32),h)
@@ -3976,11 +3977,22 @@ if ((pat_patctl.control & CTL_INFO) != 0)
39763977
if (FLD(compiled_code, executable_jit) != NULL)
39773978
fprintf(outfile, "JIT compilation was successful\n");
39783979
else
3980+
{
39793981
#ifdef SUPPORT_JIT
3980-
fprintf(outfile, "JIT compilation was not successful\n");
3982+
int len;
3983+
fprintf(outfile, "JIT compilation was not successful");
3984+
if (jitrc != 0)
3985+
{
3986+
fprintf(outfile, " (");
3987+
PCRE2_GET_ERROR_MESSAGE(len, jitrc, pbuffer);
3988+
PCHARSV(CASTVAR(void *, pbuffer), 0, len, FALSE, outfile);
3989+
fprintf(outfile, ")");
3990+
}
3991+
fprintf(outfile, "\n");
39813992
#else
39823993
fprintf(outfile, "JIT support is not available in this version of PCRE2\n");
39833994
#endif
3995+
}
39843996
}
39853997
}
39863998

@@ -4191,7 +4203,7 @@ switch(cmd)
41914203
SET(compiled_code, patstack[--patstacknext]);
41924204
if (pat_patctl.jit != 0)
41934205
{
4194-
PCRE2_JIT_COMPILE(compiled_code, pat_patctl.jit);
4206+
PCRE2_JIT_COMPILE(jitrc, compiled_code, pat_patctl.jit);
41954207
}
41964208
if ((pat_patctl.control & CTL_MEMORY) != 0) show_memory_info();
41974209
if ((pat_patctl.control & CTL_ANYINFO) != 0)
@@ -4776,7 +4788,7 @@ if (pat_patctl.jit != 0)
47764788
pat_patctl.options|forbid_utf, &errorcode, &erroroffset,
47774789
use_pat_context);
47784790
start_time = clock();
4779-
PCRE2_JIT_COMPILE(compiled_code, pat_patctl.jit);
4791+
PCRE2_JIT_COMPILE(jitrc,compiled_code, pat_patctl.jit);
47804792
time_taken += clock() - start_time;
47814793
}
47824794
total_jit_compile_time += time_taken;
@@ -4786,7 +4798,7 @@ if (pat_patctl.jit != 0)
47864798
}
47874799
else
47884800
{
4789-
PCRE2_JIT_COMPILE(compiled_code, pat_patctl.jit);
4801+
PCRE2_JIT_COMPILE(jitrc, compiled_code, pat_patctl.jit);
47904802
}
47914803
}
47924804

0 commit comments

Comments
 (0)