[Pcre-svn] [780] code/trunk: Preserve the size of JIT compil…

Top Page
Delete this message
Author: Subversion repository
Date:  
To: pcre-svn
Subject: [Pcre-svn] [780] code/trunk: Preserve the size of JIT compiled code.
Revision: 780
          http://vcs.pcre.org/viewvc?view=rev&revision=780
Author:   ph10
Date:     2011-12-02 11:39:21 +0000 (Fri, 02 Dec 2011)


Log Message:
-----------
Preserve the size of JIT compiled code. Add PCRE_INFO_JITSIZE and use it for
the /M option in pcretest.

Modified Paths:
--------------
    code/trunk/ChangeLog
    code/trunk/doc/pcreapi.3
    code/trunk/doc/pcretest.1
    code/trunk/pcre.h.in
    code/trunk/pcre_fullinfo.c
    code/trunk/pcre_internal.h
    code/trunk/pcre_jit_compile.c
    code/trunk/pcretest.c


Modified: code/trunk/ChangeLog
===================================================================
--- code/trunk/ChangeLog    2011-12-02 10:39:32 UTC (rev 779)
+++ code/trunk/ChangeLog    2011-12-02 11:39:21 UTC (rev 780)
@@ -96,6 +96,9 @@


 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

Modified: code/trunk/doc/pcreapi.3
===================================================================
--- code/trunk/doc/pcreapi.3    2011-12-02 10:39:32 UTC (rev 779)
+++ code/trunk/doc/pcreapi.3    2011-12-02 11:39:21 UTC (rev 780)
@@ -1147,6 +1147,12 @@
 .\"
 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 @@
 .rs
 .sp
 .nf
-Last updated: 01 December 2011
+Last updated: 02 December 2011
 Copyright (c) 1997-2011 University of Cambridge.
 .fi


Modified: code/trunk/doc/pcretest.1
===================================================================
--- code/trunk/doc/pcretest.1    2011-12-02 10:39:32 UTC (rev 779)
+++ code/trunk/doc/pcretest.1    2011-12-02 11:39:21 UTC (rev 780)
@@ -319,7 +319,10 @@
 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 @@
 .rs
 .sp
 .nf
-Last updated: 26 August 2011
+Last updated: 02 December 2011
 Copyright (c) 1997-2011 University of Cambridge.
 .fi


Modified: code/trunk/pcre.h.in
===================================================================
--- code/trunk/pcre.h.in    2011-12-02 10:39:32 UTC (rev 779)
+++ code/trunk/pcre.h.in    2011-12-02 11:39:21 UTC (rev 780)
@@ -216,6 +216,7 @@
 #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. */

Modified: code/trunk/pcre_fullinfo.c
===================================================================
--- code/trunk/pcre_fullinfo.c    2011-12-02 10:39:32 UTC (rev 779)
+++ code/trunk/pcre_fullinfo.c    2011-12-02 11:39:21 UTC (rev 780)
@@ -99,6 +99,19 @@
   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;

Modified: code/trunk/pcre_internal.h
===================================================================
--- code/trunk/pcre_internal.h    2011-12-02 10:39:32 UTC (rev 779)
+++ code/trunk/pcre_internal.h    2011-12-02 11:39:21 UTC (rev 780)
@@ -1953,6 +1953,7 @@
 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) */

Modified: code/trunk/pcre_jit_compile.c
===================================================================
--- code/trunk/pcre_jit_compile.c    2011-12-02 10:39:32 UTC (rev 779)
+++ code/trunk/pcre_jit_compile.c    2011-12-02 11:39:21 UTC (rev 780)
@@ -166,6 +166,7 @@
   void *executable_func;
   pcre_jit_callback callback;
   void *userdata;
+  sljit_uw executable_size; 
 } executable_function;


typedef struct jump_list {
@@ -6099,6 +6100,7 @@
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 @@

 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 @@
   }


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(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)
{

Modified: code/trunk/pcretest.c
===================================================================
--- code/trunk/pcretest.c    2011-12-02 10:39:32 UTC (rev 779)
+++ code/trunk/pcretest.c    2011-12-02 11:39:21 UTC (rev 780)
@@ -1854,22 +1854,20 @@
     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",
         (int)(first_gotten_store -
               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 @@
       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 @@
         }
       }


-    /* 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: