[Pcre-svn] [1338] code/trunk: Add pcre[16|32] _jit_free_unu…

トップ ページ
このメッセージを削除
著者: Subversion repository
日付:  
To: pcre-svn
題目: [Pcre-svn] [1338] code/trunk: Add pcre[16|32] _jit_free_unused_memory to forcibly free unused JIT executable memory.
Revision: 1338
          http://vcs.pcre.org/viewvc?view=rev&revision=1338
Author:   zherczeg
Date:     2013-06-14 08:54:36 +0100 (Fri, 14 Jun 2013)


Log Message:
-----------
Add pcre[16|32]_jit_free_unused_memory to forcibly free unused JIT executable memory. Patch inspired by Carsten Klein.

Modified Paths:
--------------
    code/trunk/ChangeLog
    code/trunk/configure.ac
    code/trunk/pcre.h.in
    code/trunk/pcre_jit_compile.c
    code/trunk/sljit/sljitConfigInternal.h
    code/trunk/sljit/sljitExecAllocator.c


Modified: code/trunk/ChangeLog
===================================================================
--- code/trunk/ChangeLog    2013-06-11 16:27:16 UTC (rev 1337)
+++ code/trunk/ChangeLog    2013-06-14 07:54:36 UTC (rev 1338)
@@ -1,6 +1,13 @@
 ChangeLog for PCRE
 ------------------


+Version 8.34 xx-xxxx-201x
+--------------------------
+
+1.  Add pcre[16|32]_jit_free_unused_memory to forcibly free unused JIT
+    executable memory. Patch inspired by Carsten Klein.
+
+
 Version 8.33 28-May-2013
 --------------------------



Modified: code/trunk/configure.ac
===================================================================
--- code/trunk/configure.ac    2013-06-11 16:27:16 UTC (rev 1337)
+++ code/trunk/configure.ac    2013-06-14 07:54:36 UTC (rev 1338)
@@ -9,9 +9,9 @@
 dnl be defined as -RC2, for example. For real releases, it should be empty.


m4_define(pcre_major, [8])
-m4_define(pcre_minor, [33])
-m4_define(pcre_prerelease, [])
-m4_define(pcre_date, [2013-05-28])
+m4_define(pcre_minor, [34])
+m4_define(pcre_prerelease, [-RC])
+m4_define(pcre_date, [2013-06-14])

# NOTE: The CMakeLists.txt file searches for the above variables in the first
# 50 lines of this file. Please update that if the variables above are moved.

Modified: code/trunk/pcre.h.in
===================================================================
--- code/trunk/pcre.h.in    2013-06-11 16:27:16 UTC (rev 1337)
+++ code/trunk/pcre.h.in    2013-06-14 07:54:36 UTC (rev 1338)
@@ -655,6 +655,9 @@
                   pcre16_jit_callback, void *);
 PCRE_EXP_DECL void pcre32_assign_jit_stack(pcre32_extra *,
                   pcre32_jit_callback, void *);
+PCRE_EXP_DECL void pcre_jit_free_unused_memory(void);
+PCRE_EXP_DECL void pcre16_jit_free_unused_memory(void);
+PCRE_EXP_DECL void pcre32_jit_free_unused_memory(void);


#ifdef __cplusplus
} /* extern "C" */

Modified: code/trunk/pcre_jit_compile.c
===================================================================
--- code/trunk/pcre_jit_compile.c    2013-06-11 16:27:16 UTC (rev 1337)
+++ code/trunk/pcre_jit_compile.c    2013-06-14 07:54:36 UTC (rev 1338)
@@ -9696,6 +9696,20 @@
   }
 }


+#if defined COMPILE_PCRE8
+PCRE_EXP_DECL void
+pcre_jit_free_unused_memory(void)
+#elif defined COMPILE_PCRE16
+PCRE_EXP_DECL void
+pcre16_jit_free_unused_memory(void)
+#elif defined COMPILE_PCRE32
+PCRE_EXP_DECL void
+pcre32_jit_free_unused_memory(void)
+#endif
+{
+sljit_free_unused_memory_exec();
+}
+
#else /* SUPPORT_JIT */

/* These are dummy functions to avoid linking errors when JIT support is not
@@ -9747,6 +9761,19 @@
(void)userdata;
}

+#if defined COMPILE_PCRE8
+PCRE_EXP_DECL void
+pcre_jit_free_unused_memory(void)
+#elif defined COMPILE_PCRE16
+PCRE_EXP_DECL void
+pcre16_jit_free_unused_memory(void)
+#elif defined COMPILE_PCRE32
+PCRE_EXP_DECL void
+pcre32_jit_free_unused_memory(void)
#endif
+{
+}

+#endif
+
/* End of pcre_jit_compile.c */

Modified: code/trunk/sljit/sljitConfigInternal.h
===================================================================
--- code/trunk/sljit/sljitConfigInternal.h    2013-06-11 16:27:16 UTC (rev 1337)
+++ code/trunk/sljit/sljitConfigInternal.h    2013-06-14 07:54:36 UTC (rev 1338)
@@ -417,6 +417,7 @@
 #if (defined SLJIT_EXECUTABLE_ALLOCATOR && SLJIT_EXECUTABLE_ALLOCATOR)
 SLJIT_API_FUNC_ATTRIBUTE void* sljit_malloc_exec(sljit_uw size);
 SLJIT_API_FUNC_ATTRIBUTE void sljit_free_exec(void* ptr);
+SLJIT_API_FUNC_ATTRIBUTE void sljit_free_unused_memory_exec(void);
 #define SLJIT_MALLOC_EXEC(size) sljit_malloc_exec(size)
 #define SLJIT_FREE_EXEC(ptr) sljit_free_exec(ptr)
 #endif


Modified: code/trunk/sljit/sljitExecAllocator.c
===================================================================
--- code/trunk/sljit/sljitExecAllocator.c    2013-06-11 16:27:16 UTC (rev 1337)
+++ code/trunk/sljit/sljitExecAllocator.c    2013-06-14 07:54:36 UTC (rev 1338)
@@ -287,3 +287,26 @@


     allocator_release_lock();
 }
+
+SLJIT_API_FUNC_ATTRIBUTE void sljit_free_unused_memory_exec(void)
+{
+    struct free_block* free_block;
+    struct free_block* next_free_block;
+
+    allocator_grab_lock();
+
+    free_block = free_blocks;
+    while (free_block) {
+        next_free_block = free_block->next;
+        if (!free_block->header.prev_size && 
+                AS_BLOCK_HEADER(free_block, free_block->size)->size == 1) {
+            total_size -= free_block->size;
+            sljit_remove_free_block(free_block);
+            free_chunk(free_block, free_block->size + sizeof(struct block_header));
+        }
+        free_block = next_free_block;
+    }
+
+    SLJIT_ASSERT((total_size && free_blocks) || (!total_size && !free_blocks));
+    allocator_release_lock();
+}