Changeset 620


Ignore:
Timestamp:
08/02/10 03:57:57 (18 months ago)
Author:
mooneer
Message:
  1. Reenabled increment optimization, a 5% max improvement on top of the previous changes. It probably improved things very little when first implemented.
  2. Added thread locking around parser entry points to ensure only a single thread can touch the text segment at a time.
Location:
interpreter/trunk/backend
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • interpreter/trunk/backend/common/kite_compiler.c

    r619 r620  
    103103    } 
    104104     
     105    #ifdef WIN32 
     106    WaitForSingleObject(thd->vm->compile_mtx, INFINITE); 
     107    #else 
     108    pthread_mutex_lock(&thd->vm->compile_mtx); 
     109    #endif /* WIN32 */ 
     110     
    105111    compiler->thd = thd; 
    106112    compiler->currentLine = 1; 
     
    126132    free(compiler); 
    127133#endif /* HAVE_GC_H */ 
     134 
     135    #ifdef WIN32 
     136    ReleaseMutex(thd->vm->compile_mtx); 
     137    #else 
     138    pthread_mutex_unlock(&thd->vm->compile_mtx); 
     139    #endif /* WIN32 */ 
     140     
    128141    return ret; 
    129142} 
     
    164177    } 
    165178 
     179    #ifdef WIN32 
     180    WaitForSingleObject(thd->vm->compile_mtx, INFINITE); 
     181    #else 
     182    pthread_mutex_lock(&thd->vm->compile_mtx); 
     183    #endif /* WIN32 */ 
     184     
    166185    compiler->thd = thd; 
    167186    compiler->currentLine = ln; 
     
    187206    free(compiler); 
    188207#endif /* HAVE_GC_H */ 
    189     return ret; 
    190 } 
     208 
     209    #ifdef WIN32 
     210    ReleaseMutex(thd->vm->compile_mtx); 
     211    #else 
     212    pthread_mutex_unlock(&thd->vm->compile_mtx); 
     213    #endif /* WIN32 */ 
     214 
     215    return ret; 
     216} 
  • interpreter/trunk/backend/kite-vm-1.0/kite_compile_bytecode.c

    r619 r620  
    2626static void kite_optimize_increment(kite_compiler_t *compiler, kite_opcode_t *o1, kite_opcode_t *o2) 
    2727{ 
    28     /*kite_thread_t *thd = compiler->thd; 
    29     kite_opcode_push *p1 = (kite_opcode_push*)o1; 
    30     kite_opcode_push *p2 = (kite_opcode_push*)o2; 
    31     if (o1->opcode == PUSH && o2->opcode == PUSH) { 
    32         if (p1->obj->type == OBJ_IDENT && p2->obj->type == OBJ_IDENT) { 
    33             if (strcmp(p1->obj->builtin_data.stringvalue.string, 
    34                        p2->obj->builtin_data.stringvalue.string) == 0) { 
    35                 if (o1->next && o2->next) { 
    36                     if (o1->next->opcode == DEREF_1 && o2->next->opcode == DEREF_1) { 
    37                         if (o1->next->next == o2) { 
    38                             kite_opcode_t *dupe = kite_compile_dupe_top(TRUE); 
    39                             dupe->file = strdup(o2->file); 
    40                             dupe->line = o2->line; 
    41                             o1->next->next = dupe; 
    42                             dupe->next = o2->next->next; 
    43                             o2->next->next = NULL; 
    44                             kite_free_instruction_list(thd, o2); 
    45                         } 
     28    kite_thread_t *thd = compiler->thd; 
     29    kite_vm_t *vm = thd->vm; 
     30    kite_opcode_t *p1 = (void*)vm->text_segment + (long)o1; 
     31    kite_opcode_t *p2 = (void*)vm->text_segment + (long)o2; 
     32    if (p1->opcode == PUSH && p2->opcode == PUSH) { 
     33        if (p1->op_arg.obj->type == OBJ_IDENT && p2->op_arg.obj->type == OBJ_IDENT) { 
     34            if (strcmp(p1->op_arg.obj->builtin_data.stringvalue.string, 
     35                       p2->op_arg.obj->builtin_data.stringvalue.string) == 0) { 
     36                if ((p1 + 1) < ((void*)vm->text_segment + vm->text_segment_length) && 
     37                    (p1 + 2) < ((void*)vm->text_segment + vm->text_segment_length)) { 
     38                    if ((p1 + 1)->opcode == DEREF_1 && (p2 + 1)->opcode == DEREF_1) { 
     39                        p2->opcode = DUPE_TOP; 
     40                        p2->op_arg.dupe_ref = TRUE; 
     41                        (p2 + 1)->opcode = NOP; 
    4642                    } 
    4743                } 
    4844            } 
    4945        } 
    50     }*/ 
     46    } 
    5147} 
    5248 
     
    524520         
    525521    if (opc->opcode == ARITH_OP && ((kite_opcode_arithop*)opc)->op_arg.operation == OP_ARRAY_DEREF) 
    526         return opc - compiler->thd->vm->text_segment; 
     522        return (void*)opc - (long)compiler->thd->vm->text_segment; 
    527523    else 
    528524        return NULL; 
     
    532528{ 
    533529    kite_opcode_t *op2; 
    534      
    535     /*if (op1 && op1->next && op1->next->next)  
     530    int has_possible_dupe = TRUE; 
     531    int i; 
     532    kite_vm_t *vm = compiler->thd->vm; 
     533     
     534    /* Ensure next two instructions are valid for dupe optimization.  
     535       Equivalent to op1 && op1->next && op1->next->next in old code. */ 
     536    op2 = (void*)vm->text_segment + (long)op1; 
     537    for (i = 0; i < 2; i++) 
    536538    { 
    537         op2 = op1->next->next; 
     539        if (op2->opcode == RETURN_NOW || ((void*)op2 - (long)vm->text_segment) >= vm->text_segment_length) 
     540        { 
     541            has_possible_dupe = FALSE; 
     542            break; 
     543        } 
     544        op2++; 
     545    } 
     546     
     547    /* Perform dupe optimization. */ 
     548    if (has_possible_dupe) 
     549    { 
     550        op2 = (void*)op2 - (long)vm->text_segment; 
    538551        kite_optimize_increment(compiler, op1, op2); 
    539     }*/ 
     552    } 
    540553     
    541554    if (!orig_op2) 
     
    772785{ 
    773786    kite_thread_t *thd = compiler->thd; 
     787    kite_vm_t *vm = thd->vm; 
    774788    kite_opcode_t *op = kite_compile_push(kite_new_ident(thd, name)); 
    775789    COMPILE_INSTRUCTION(op, line); 
     790    op = vm->cur_text_segment - sizeof(kite_opcode_t); 
    776791    COMPILE_INSTRUCTION(kite_compile_deref_1(TRUE), line); 
    777     return NULL; 
     792    return op; 
    778793} 
    779794 
Note: See TracChangeset for help on using the changeset viewer.