diff options
author | ph10 <ph10@2f5784b3-3f2a-0410-8824-cb99058d5e15> | 2011-12-02 11:39:21 +0000 |
---|---|---|
committer | ph10 <ph10@2f5784b3-3f2a-0410-8824-cb99058d5e15> | 2011-12-02 11:39:21 +0000 |
commit | 0ca9f2fe960116f87e44542eb426f4f6dc5ec522 (patch) | |
tree | 4ed103c208086e65b3529c2fd74d34afc5891e59 | |
parent | 3d39f0a5f16085686668180e80e3008cb3fe878f (diff) | |
download | pcre-0ca9f2fe960116f87e44542eb426f4f6dc5ec522.tar.gz |
Preserve the size of JIT compiled code. Add PCRE_INFO_JITSIZE and use it for
the /M option in pcretest.
git-svn-id: svn://vcs.exim.org/pcre/code/trunk@780 2f5784b3-3f2a-0410-8824-cb99058d5e15
-rw-r--r-- | ChangeLog | 3 | ||||
-rw-r--r-- | doc/pcreapi.3 | 8 | ||||
-rw-r--r-- | doc/pcretest.1 | 7 | ||||
-rw-r--r-- | pcre.h.in | 1 | ||||
-rw-r--r-- | pcre_fullinfo.c | 13 | ||||
-rw-r--r-- | pcre_internal.h | 1 | ||||
-rw-r--r-- | pcre_jit_compile.c | 10 | ||||
-rw-r--r-- | pcretest.c | 31 |
8 files changed, 60 insertions, 14 deletions
@@ -96,6 +96,9 @@ Version 8.21 23. Added some (int) casts to non-JIT modules to reduce warnings on 64-bit systems. + +24. Added PCRE_INFO_JITSIZE to pass on the value from (21) above, and also + output it when the /M option is used in pcretest. Version 8.20 21-Oct-2011 diff --git a/doc/pcreapi.3 b/doc/pcreapi.3 index 22b9d15..7a352fd 100644 --- a/doc/pcreapi.3 +++ b/doc/pcreapi.3 @@ -1147,6 +1147,12 @@ particular pattern. See the .\" documentation for details of what can and cannot be handled. .sp + PCRE_INFO_JITSIZE +.sp +If the pattern was successfully studied with the PCRE_STUDY_JIT_COMPILE option, +return the size of the JIT compiled code, otherwise return zero. The fourth +argument should point to a \fBsize_t\fP variable. +.sp PCRE_INFO_LASTLITERAL .sp Return the value of the rightmost literal byte that must exist in any matched @@ -2547,6 +2553,6 @@ Cambridge CB2 3QH, England. .rs .sp .nf -Last updated: 01 December 2011 +Last updated: 02 December 2011 Copyright (c) 1997-2011 University of Cambridge. .fi diff --git a/doc/pcretest.1 b/doc/pcretest.1 index 2689bfa..31656cf 100644 --- a/doc/pcretest.1 +++ b/doc/pcretest.1 @@ -319,7 +319,10 @@ as the tables pointer; that is, \fB/L\fP applies only to the expression on which it appears. .P The \fB/M\fP modifier causes the size of memory block used to hold the compiled -pattern to be output. +pattern to be output. This does not include the size of the \fBpcre\fP block; +it is just the actual compiled data. If the pattern is successfully studied +with the PCRE_STUDY_JIT_COMPILE option, the size of the JIT compiled code is +also output. .P If the \fB/S\fP modifier appears once, it causes \fBpcre_study()\fP to be called after the expression has been compiled, and the results used when the @@ -875,6 +878,6 @@ Cambridge CB2 3QH, England. .rs .sp .nf -Last updated: 26 August 2011 +Last updated: 02 December 2011 Copyright (c) 1997-2011 University of Cambridge. .fi @@ -216,6 +216,7 @@ compiling). */ #define PCRE_INFO_HASCRORLF 14 #define PCRE_INFO_MINLENGTH 15 #define PCRE_INFO_JIT 16 +#define PCRE_INFO_JITSIZE 17 /* Request types for pcre_config(). Do not re-arrange, in order to remain compatible. */ diff --git a/pcre_fullinfo.c b/pcre_fullinfo.c index 57971a8..33f0b3a 100644 --- a/pcre_fullinfo.c +++ b/pcre_fullinfo.c @@ -99,6 +99,19 @@ switch (what) case PCRE_INFO_STUDYSIZE: *((size_t *)where) = (study == NULL)? 0 : study->size; break; + + case PCRE_INFO_JITSIZE: +#ifdef SUPPORT_JIT + *((size_t *)where) = + (extra_data != NULL && + (extra_data->flags & PCRE_EXTRA_EXECUTABLE_JIT) != 0 && + extra_data->executable_jit != NULL)? + _pcre_jit_get_size(extra_data->executable_jit) : 0; +#else + *((size_t *)where) = 0; +#endif + + break; case PCRE_INFO_CAPTURECOUNT: *((int *)where) = re->top_bracket; diff --git a/pcre_internal.h b/pcre_internal.h index 5e0c67c..26cc835 100644 --- a/pcre_internal.h +++ b/pcre_internal.h @@ -1953,6 +1953,7 @@ extern void _pcre_jit_compile(const real_pcre *, pcre_extra *); extern int _pcre_jit_exec(const real_pcre *, void *, PCRE_SPTR, int, int, int, int, int *, int); extern void _pcre_jit_free(void *); +extern int _pcre_jit_get_size(void *); #endif /* Unicode character database (UCD) */ diff --git a/pcre_jit_compile.c b/pcre_jit_compile.c index 3f8259d..e23e41b 100644 --- a/pcre_jit_compile.c +++ b/pcre_jit_compile.c @@ -166,6 +166,7 @@ typedef struct executable_function { void *executable_func; pcre_jit_callback callback; void *userdata; + sljit_uw executable_size; } executable_function; typedef struct jump_list { @@ -6099,6 +6100,7 @@ pcre_study_data *study; uschar *ccend; executable_function *function; void *executable_func; +sljit_uw executable_size; struct sljit_label *leave; struct sljit_label *mainloop = NULL; struct sljit_label *empty_match_found; @@ -6428,6 +6430,7 @@ if (common->getucd != NULL) SLJIT_FREE(common->localptrs); executable_func = sljit_generate_code(compiler); +executable_size = sljit_get_generated_code_size(compiler); sljit_free_compiler(compiler); if (executable_func == NULL) return; @@ -6442,6 +6445,7 @@ if (function == NULL) } function->executable_func = executable_func; +function->executable_size = executable_size; function->callback = NULL; function->userdata = NULL; extra->executable_jit = function; @@ -6530,6 +6534,12 @@ sljit_free_code(function->executable_func); SLJIT_FREE(function); } +int +_pcre_jit_get_size(void *executable_func) +{ +return ((executable_function*)executable_func)->executable_size; +} + PCRE_EXP_DECL pcre_jit_stack * pcre_jit_stack_alloc(int startsize, int maxsize) { @@ -1854,9 +1854,13 @@ while (!done) new_info(re, NULL, PCRE_INFO_OPTIONS, &get_options); if ((get_options & PCRE_UTF8) != 0) use_utf8 = 1; - /* Print information if required. There are now two info-returning - functions. The old one has a limited interface and returns only limited - data. Check that it agrees with the newer one. */ + /* Extract the size for possible writing before possibly flipping it, + and remember the store that was got. */ + + true_size = ((real_pcre *)re)->size; + regex_gotten_store = first_gotten_store; + + /* Output code size information if requested */ if (log_store) fprintf(outfile, "Memory allocation (code space): %d\n", @@ -1864,12 +1868,6 @@ while (!done) sizeof(real_pcre) - ((real_pcre *)re)->name_count * ((real_pcre *)re)->name_entry_size)); - /* Extract the size for possible writing before possibly flipping it, - and remember the store that was got. */ - - true_size = ((real_pcre *)re)->size; - regex_gotten_store = first_gotten_store; - /* If -s or /S was present, study the regex to generate additional info to help with the matching, unless the pattern has the SS option, which suppresses the effect of /S (used for a few test patterns where studying is @@ -1894,9 +1892,18 @@ while (!done) if (error != NULL) fprintf(outfile, "Failed to study: %s\n", error); else if (extra != NULL) + { true_study_size = ((pcre_study_data *)(extra->study_data))->size; + if (log_store) + { + size_t jitsize; + new_info(re, extra, PCRE_INFO_JITSIZE, &jitsize); + if (jitsize != 0) + fprintf(outfile, "Memory allocation (JIT code): %d\n", jitsize); + } + } } - + /* If /K was present, we set up for handling MARK data. */ if (do_mark) @@ -1947,7 +1954,9 @@ while (!done) } } - /* Extract information from the compiled data if required */ + /* Extract information from the compiled data if required. There are now + two info-returning functions. The old one has a limited interface and + returns only limited data. Check that it agrees with the newer one. */ SHOW_INFO: |