Revision: 777
http://vcs.pcre.org/viewvc?view=rev&revision=777
Author: zherczeg
Date: 2011-12-01 15:15:31 +0000 (Thu, 01 Dec 2011)
Log Message:
-----------
Retrieve executable code size support for the JIT compiler and fixing some warnings.
Modified Paths:
--------------
code/trunk/ChangeLog
code/trunk/sljit/sljitConfigInternal.h
code/trunk/sljit/sljitExecAllocator.c
code/trunk/sljit/sljitLir.h
code/trunk/sljit/sljitNativeARM_Thumb2.c
code/trunk/sljit/sljitNativeARM_v5.c
code/trunk/sljit/sljitNativeMIPS_common.c
code/trunk/sljit/sljitNativePPC_common.c
code/trunk/sljit/sljitNativeX86_common.c
Modified: code/trunk/ChangeLog
===================================================================
--- code/trunk/ChangeLog 2011-12-01 11:02:56 UTC (rev 776)
+++ code/trunk/ChangeLog 2011-12-01 15:15:31 UTC (rev 777)
@@ -87,7 +87,10 @@
19. If the /S+ option was used in pcretest to study a pattern using JIT,
subsequent uses of /S (without +) incorrectly behaved like /S+.
+21. Retrieve executable code size support for the JIT compiler and fixing
+ some warnings.
+
Version 8.20 21-Oct-2011
------------------------
Modified: code/trunk/sljit/sljitConfigInternal.h
===================================================================
--- code/trunk/sljit/sljitConfigInternal.h 2011-12-01 11:02:56 UTC (rev 776)
+++ code/trunk/sljit/sljitConfigInternal.h 2011-12-01 15:15:31 UTC (rev 777)
@@ -354,8 +354,8 @@
#endif /* !SLJIT_UNALIGNED */
#if (defined SLJIT_EXECUTABLE_ALLOCATOR && SLJIT_EXECUTABLE_ALLOCATOR)
-void* sljit_malloc_exec(sljit_uw size);
-void sljit_free_exec(void* ptr);
+SLJIT_API_FUNC_ATTRIBUTE void* sljit_malloc_exec(sljit_uw size);
+SLJIT_API_FUNC_ATTRIBUTE void sljit_free_exec(void* ptr);
#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 2011-12-01 11:02:56 UTC (rev 776)
+++ code/trunk/sljit/sljitExecAllocator.c 2011-12-01 15:15:31 UTC (rev 777)
@@ -163,7 +163,7 @@
}
}
-void* sljit_malloc_exec(sljit_uw size)
+SLJIT_API_FUNC_ATTRIBUTE void* sljit_malloc_exec(sljit_uw size)
{
struct block_header *header;
struct block_header *next_header;
@@ -231,7 +231,7 @@
return MEM_START(header);
}
-void sljit_free_exec(void* ptr)
+SLJIT_API_FUNC_ATTRIBUTE void sljit_free_exec(void* ptr)
{
struct block_header *header;
struct free_block* free_block;
Modified: code/trunk/sljit/sljitLir.h
===================================================================
--- code/trunk/sljit/sljitLir.h 2011-12-01 11:02:56 UTC (rev 776)
+++ code/trunk/sljit/sljitLir.h 2011-12-01 15:15:31 UTC (rev 777)
@@ -195,6 +195,8 @@
int local_size;
/* Code size. */
sljit_uw size;
+ /* For statistical purposes. */
+ sljit_uw executable_size;
#if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
int args;
@@ -291,6 +293,15 @@
SLJIT_API_FUNC_ATTRIBUTE void* sljit_generate_code(struct sljit_compiler *compiler);
SLJIT_API_FUNC_ATTRIBUTE void sljit_free_code(void* code);
+/*
+ After the code generation we can retrieve the allocated executable memory size,
+ although this area may not be fully filled with instructions depending on some
+ optimizations. This function is useful only for statistical purposes.
+
+ Before a successful code generation, this function returns with 0.
+*/
+static SLJIT_INLINE sljit_uw sljit_get_generated_code_size(struct sljit_compiler *compiler) { return compiler->executable_size; }
+
/* Instruction generation. Returns with error code. */
/*
Modified: code/trunk/sljit/sljitNativeARM_Thumb2.c
===================================================================
--- code/trunk/sljit/sljitNativeARM_Thumb2.c 2011-12-01 11:02:56 UTC (rev 776)
+++ code/trunk/sljit/sljitNativeARM_Thumb2.c 2011-12-01 15:15:31 UTC (rev 777)
@@ -416,6 +416,7 @@
SLJIT_CACHE_FLUSH(code, code_ptr);
compiler->error = SLJIT_ERR_COMPILED;
+ compiler->executable_size = compiler->size * sizeof(sljit_uh);
/* Set thumb mode flag. */
return (void*)((sljit_uw)code | 0x1);
}
Modified: code/trunk/sljit/sljitNativeARM_v5.c
===================================================================
--- code/trunk/sljit/sljitNativeARM_v5.c 2011-12-01 11:02:56 UTC (rev 776)
+++ code/trunk/sljit/sljitNativeARM_v5.c 2011-12-01 15:15:31 UTC (rev 777)
@@ -788,6 +788,7 @@
SLJIT_CACHE_FLUSH(code, code_ptr);
compiler->error = SLJIT_ERR_COMPILED;
+ compiler->executable_size = size * sizeof(sljit_uw);
return code;
}
Modified: code/trunk/sljit/sljitNativeMIPS_common.c
===================================================================
--- code/trunk/sljit/sljitNativeMIPS_common.c 2011-12-01 11:02:56 UTC (rev 776)
+++ code/trunk/sljit/sljitNativeMIPS_common.c 2011-12-01 15:15:31 UTC (rev 777)
@@ -397,6 +397,7 @@
}
compiler->error = SLJIT_ERR_COMPILED;
+ compiler->executable_size = compiler->size * sizeof(sljit_ins);
#ifndef __GNUC__
SLJIT_CACHE_FLUSH(code, code_ptr);
#else
Modified: code/trunk/sljit/sljitNativePPC_common.c
===================================================================
--- code/trunk/sljit/sljitNativePPC_common.c 2011-12-01 11:02:56 UTC (rev 776)
+++ code/trunk/sljit/sljitNativePPC_common.c 2011-12-01 15:15:31 UTC (rev 777)
@@ -354,6 +354,7 @@
SLJIT_CACHE_FLUSH(code, code_ptr);
compiler->error = SLJIT_ERR_COMPILED;
+ compiler->executable_size = compiler->size * sizeof(sljit_ins);
#if (defined SLJIT_CONFIG_PPC_64 && SLJIT_CONFIG_PPC_64)
if (((sljit_w)code_ptr) & 0x4)
Modified: code/trunk/sljit/sljitNativeX86_common.c
===================================================================
--- code/trunk/sljit/sljitNativeX86_common.c 2011-12-01 11:02:56 UTC (rev 776)
+++ code/trunk/sljit/sljitNativeX86_common.c 2011-12-01 15:15:31 UTC (rev 777)
@@ -357,22 +357,22 @@
while (jump) {
if (jump->flags & PATCH_MB) {
SLJIT_ASSERT((sljit_w)(jump->u.label->addr - (jump->addr + sizeof(sljit_b))) >= -128 && (sljit_w)(jump->u.label->addr - (jump->addr + sizeof(sljit_b))) <= 127);
- *(sljit_ub*)jump->addr = jump->u.label->addr - (jump->addr + sizeof(sljit_b));
+ *(sljit_ub*)jump->addr = (sljit_ub)(jump->u.label->addr - (jump->addr + sizeof(sljit_b)));
} else if (jump->flags & PATCH_MW) {
if (jump->flags & JUMP_LABEL) {
#if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
- *(sljit_w*)jump->addr = jump->u.label->addr - (jump->addr + sizeof(sljit_w));
+ *(sljit_w*)jump->addr = (sljit_w)(jump->u.label->addr - (jump->addr + sizeof(sljit_w)));
#else
SLJIT_ASSERT((sljit_w)(jump->u.label->addr - (jump->addr + sizeof(sljit_hw))) >= -0x80000000ll && (sljit_w)(jump->u.label->addr - (jump->addr + sizeof(sljit_hw))) <= 0x7fffffffll);
- *(sljit_hw*)jump->addr = jump->u.label->addr - (jump->addr + sizeof(sljit_hw));
+ *(sljit_hw*)jump->addr = (sljit_hw)(jump->u.label->addr - (jump->addr + sizeof(sljit_hw)));
#endif
}
else {
#if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32)
- *(sljit_w*)jump->addr = jump->u.target - (jump->addr + sizeof(sljit_w));
+ *(sljit_w*)jump->addr = (sljit_w)(jump->u.target - (jump->addr + sizeof(sljit_w)));
#else
SLJIT_ASSERT((sljit_w)(jump->u.target - (jump->addr + sizeof(sljit_hw))) >= -0x80000000ll && (sljit_w)(jump->u.target - (jump->addr + sizeof(sljit_hw))) <= 0x7fffffffll);
- *(sljit_hw*)jump->addr = jump->u.target - (jump->addr + sizeof(sljit_hw));
+ *(sljit_hw*)jump->addr = (sljit_hw)(jump->u.target - (jump->addr + sizeof(sljit_hw)));
#endif
}
}
@@ -387,6 +387,7 @@
/* Maybe we waste some space because of short jumps. */
SLJIT_ASSERT(code_ptr <= code + compiler->size);
compiler->error = SLJIT_ERR_COMPILED;
+ compiler->executable_size = compiler->size;
return (void*)code;
}
@@ -1360,7 +1361,7 @@
code = (sljit_ub*)ensure_buf(compiler, 1 + 4);
FAIL_IF(!code);
INC_CSIZE(4);
- *(sljit_hw*)code = src1w;
+ *(sljit_hw*)code = (sljit_hw)src1w;
}
else {
EMIT_MOV(compiler, TMP_REG2, 0, SLJIT_IMM, src1w);
@@ -1403,7 +1404,7 @@
code = (sljit_ub*)ensure_buf(compiler, 1 + 4);
FAIL_IF(!code);
INC_CSIZE(4);
- *(sljit_hw*)code = src2w;
+ *(sljit_hw*)code = (sljit_hw)src2w;
}
else {
EMIT_MOV(compiler, TMP_REG2, 0, SLJIT_IMM, src1w);