Ver código fonte

more accurate/faster function resolution from stack

Nicolas Cannasse 9 anos atrás
pai
commit
05412ca982
3 arquivos alterados com 14 adições e 25 exclusões
  1. 2 2
      src/hlmodule.h
  2. 7 7
      src/jit.c
  3. 5 16
      src/module.c

+ 2 - 2
src/hlmodule.h

@@ -85,7 +85,7 @@ typedef struct {
 	void **functions_ptrs;
 	void **functions_ptrs;
 	int *functions_indexes;
 	int *functions_indexes;
 	void *jit_code;
 	void *jit_code;
-	int **jit_debug;
+	int *jit_debug;
 	hl_module_context ctx;
 	hl_module_context ctx;
 } hl_module;
 } hl_module;
 
 
@@ -110,5 +110,5 @@ void hl_jit_free( jit_ctx *ctx );
 void hl_jit_init( jit_ctx *ctx, hl_module *m );
 void hl_jit_init( jit_ctx *ctx, hl_module *m );
 int hl_jit_init_callback( jit_ctx *ctx );
 int hl_jit_init_callback( jit_ctx *ctx );
 int hl_jit_function( jit_ctx *ctx, hl_module *m, hl_function *f );
 int hl_jit_function( jit_ctx *ctx, hl_module *m, hl_function *f );
-void *hl_jit_code( jit_ctx *ctx, hl_module *m, int *codesize, int ***debug );
+void *hl_jit_code( jit_ctx *ctx, hl_module *m, int *codesize, int **debug );
 
 

+ 7 - 7
src/jit.c

@@ -259,7 +259,7 @@ struct jit_ctx {
 	hl_alloc falloc; // cleared per-function
 	hl_alloc falloc; // cleared per-function
 	hl_alloc galloc;
 	hl_alloc galloc;
 	vclosure *closure_list;
 	vclosure *closure_list;
-	int **debug;
+	int *debug;
 };
 };
 
 
 #define jit_exit() { hl_debug_break(); exit(-1); }
 #define jit_exit() { hl_debug_break(); exit(-1); }
@@ -331,13 +331,13 @@ static void jit_buf( jit_ctx *ctx ) {
 		ctx->buf.b = nbuf + curpos;
 		ctx->buf.b = nbuf + curpos;
 		ctx->bufSize = nsize;
 		ctx->bufSize = nsize;
 		if( ctx->m->code->hasdebug ) {
 		if( ctx->m->code->hasdebug ) {
-			int **ndebug = (int**)malloc(sizeof(int**) * (nsize >> JIT_CALL_PRECISION));
+			int *ndebug = (int*)malloc(sizeof(int) * (nsize >> JIT_CALL_PRECISION));
 			if( ndebug == NULL ) ASSERT(nsize);
 			if( ndebug == NULL ) ASSERT(nsize);
 			if( ctx->debug ) {
 			if( ctx->debug ) {
-				memcpy(ndebug,ctx->debug,(curpos>>JIT_CALL_PRECISION) * sizeof(int*));
+				memcpy(ndebug,ctx->debug,(curpos>>JIT_CALL_PRECISION) * sizeof(int));
 				free(ctx->debug);
 				free(ctx->debug);
 			}
 			}
-			memset(ndebug + (curpos>>JIT_CALL_PRECISION), 0, ((nsize - curpos) >> JIT_CALL_PRECISION) * sizeof(int*));
+			memset(ndebug + (curpos>>JIT_CALL_PRECISION), 0, ((nsize - curpos) >> JIT_CALL_PRECISION) * sizeof(int));
 			ctx->debug = ndebug;
 			ctx->debug = ndebug;
 		}
 		}
 	}
 	}
@@ -760,7 +760,7 @@ static void op( jit_ctx *ctx, CpuOp o, preg *a, preg *b, bool mode64 ) {
 	if( ctx->debug && o == CALL && ctx->f ) {
 	if( ctx->debug && o == CALL && ctx->f ) {
 		int pos = BUF_POS() >> JIT_CALL_PRECISION;
 		int pos = BUF_POS() >> JIT_CALL_PRECISION;
 		preg p;
 		preg p;
-		ctx->debug[pos] = ctx->f->debug + (ctx->currentPos - 1) * 2;
+		ctx->debug[pos] = (ctx->f->findex<<16) | ((ctx->currentPos - 1)&0xFFFF);
 		op(ctx,MOV,pmem(&p,Esp,-HL_WSIZE),PEBP,true); // erase EIP (clean stack report)
 		op(ctx,MOV,pmem(&p,Esp,-HL_WSIZE),PEBP,true); // erase EIP (clean stack report)
 	}
 	}
 }
 }
@@ -1219,7 +1219,7 @@ static int prepare_call_args( jit_ctx *ctx, int count, int *args, vreg *vregs, b
 #	pragma optimize( "", off )
 #	pragma optimize( "", off )
 #endif
 #endif
 
 
-static void hl_null_access( uchar *str ) {
+static void hl_null_access() {
 	hl_error_msg(USTR("Null access"));
 	hl_error_msg(USTR("Null access"));
 }
 }
 
 
@@ -3239,7 +3239,7 @@ int hl_jit_function( jit_ctx *ctx, hl_module *m, hl_function *f ) {
 	return codePos;
 	return codePos;
 }
 }
 
 
-void *hl_jit_code( jit_ctx *ctx, hl_module *m, int *codesize, int ***debug ) {
+void *hl_jit_code( jit_ctx *ctx, hl_module *m, int *codesize, int **debug ) {
 	jlist *c;
 	jlist *c;
 	int size = BUF_POS();
 	int size = BUF_POS();
 	unsigned char *code;
 	unsigned char *code;

+ 5 - 16
src/module.c

@@ -36,27 +36,16 @@ static void *stack_top;
 
 
 static uchar *module_resolve_symbol( void *addr, uchar *out, int *outSize ) {
 static uchar *module_resolve_symbol( void *addr, uchar *out, int *outSize ) {
 	int code_pos = ((int)(int_val)((unsigned char*)addr - (unsigned char*)cur_module->jit_code)) >> JIT_CALL_PRECISION;
 	int code_pos = ((int)(int_val)((unsigned char*)addr - (unsigned char*)cur_module->jit_code)) >> JIT_CALL_PRECISION;
-	int *debug_addr = cur_module->jit_debug[code_pos];
+	int debug_pos = cur_module->jit_debug[code_pos];
+	int *debug_addr;
 	int file, line;
 	int file, line;
 	int size = *outSize;
 	int size = *outSize;
 	int pos = 0;
 	int pos = 0;
 	hl_function *fdebug;
 	hl_function *fdebug;
-	if( !debug_addr )
+	if( !debug_pos )
 		return NULL;
 		return NULL;
-	{
-		// resolve function from its debug addr
-		int min = 0;
-		int max = cur_module->code->nfunctions;
-		while( min < max ) {
-			int mid = (min + max) >> 1;
-			hl_function *f = cur_module->code->functions + mid;
-			if( debug_addr < f->debug )
-				max = mid;
-			else
-				min = mid + 1;
-		}
-		fdebug = cur_module->code->functions + (((min + max) >> 1) - 1);
-	}
+	fdebug = cur_module->code->functions + cur_module->functions_indexes[((unsigned)debug_pos)>>16];
+	debug_addr = fdebug->debug + ((debug_pos&0xFFFF) * 2);
 	file = debug_addr[0];
 	file = debug_addr[0];
 	line = debug_addr[1];
 	line = debug_addr[1];
 	if( fdebug->obj )
 	if( fdebug->obj )