pike.git / src / program.c

version» Context lines:

pike.git/src/program.c:1:   /*   || This file is part of Pike. For copyright information see COPYRIGHT.   || Pike is distributed under GPL, LGPL and MPL. See the file COPYING   || for more information. - || $Id: program.c,v 1.494 2005/03/22 11:47:29 jonasw Exp $ + || $Id: program.c,v 1.495 2005/05/26 12:00:56 grubba Exp $   */      #include "global.h" - RCSID("$Id: program.c,v 1.494 2005/03/22 11:47:29 jonasw Exp $"); + RCSID("$Id: program.c,v 1.495 2005/05/26 12:00:56 grubba Exp $");   #include "program.h"   #include "object.h"   #include "dynamic_buffer.h"   #include "pike_types.h"   #include "stralloc.h"   #include "las.h"   #include "language.h"   #include "lex.h"   #include "pike_macros.h"   #include "fsort.h"
pike.git/src/program.c:789:   #define RELOCATE_linenumbers(ORIG,NEW)   #define RELOCATE_identifier_index(ORIG,NEW)   #define RELOCATE_variable_index(ORIG,NEW)   #define RELOCATE_identifier_references(ORIG,NEW)   #define RELOCATE_strings(ORIG,NEW)   #define RELOCATE_inherits(ORIG,NEW)   #define RELOCATE_identifiers(ORIG,NEW)   #define RELOCATE_constants(ORIG,NEW)   #define RELOCATE_relocations(ORIG,NEW)    + #ifdef PIKE_USE_MACHINE_CODE + /* Special cases for low_add_to_program and add_to_program since +  * many OSes require us to use mmap to allocate memory for our +  * machine code. +  */ + #define BAR(NUMTYPE,TYPE,NAME) \ + void PIKE_CONCAT(low_add_to_,NAME) (struct program_state *state, \ +  TYPE ARG) { \ +  if(state->malloc_size_program->PIKE_CONCAT(num_,NAME) == \ +  state->new_program->PIKE_CONCAT(num_,NAME)) { \ +  TYPE *tmp; \ +  state->malloc_size_program->PIKE_CONCAT(num_,NAME) *= 2; \ +  state->malloc_size_program->PIKE_CONCAT(num_,NAME)++; \ +  tmp = mexec_realloc((void *)state->new_program->NAME, \ +  sizeof(TYPE) * \ +  state->malloc_size_program-> \ +  PIKE_CONCAT(num_,NAME)); \ +  if(!tmp) Pike_fatal("Out of memory.\n"); \ +  PIKE_CONCAT(RELOCATE_,NAME)(state->new_program, tmp); \ +  state->new_program->NAME=tmp; \ +  } \ +  state->new_program-> \ +  NAME[state->new_program->PIKE_CONCAT(num_,NAME)++]=(ARG); \ + } \ + void PIKE_CONCAT(add_to_,NAME) (TYPE ARG) { \ +  CHECK_FOO(NUMTYPE,TYPE,NAME); \ +  PIKE_CONCAT(low_add_to_,NAME) ( Pike_compiler, ARG ); \ + } + #endif /* PIKE_USE_MACHINE_CODE */ +    #define FOO(NUMTYPE,TYPE,NAME) \   void PIKE_CONCAT(low_add_to_,NAME) (struct program_state *state, \    TYPE ARG) { \    if(state->malloc_size_program->PIKE_CONCAT(num_,NAME) == \    state->new_program->PIKE_CONCAT(num_,NAME)) { \    TYPE *tmp; \    state->malloc_size_program->PIKE_CONCAT(num_,NAME) *= 2; \    state->malloc_size_program->PIKE_CONCAT(num_,NAME)++; \    tmp = realloc((void *)state->new_program->NAME, \    sizeof(TYPE) * \
pike.git/src/program.c:1283:    * 3) localizes memory access (decreases paging)    */   void optimize_program(struct program *p)   {    size_t size=0;    char *data;       /* Already done (shouldn't happen, but who knows?) */    if(p->flags & PROGRAM_OPTIMIZED) return;    + #ifdef PIKE_USE_MACHINE_CODE +  /* Don't move our mexec-allocated memory into the malloc... */ + #define BAR(NUMTYPE,TYPE,NAME) + #endif /* PIKE_USE_MACHINE_CODE */ +    #define FOO(NUMTYPE,TYPE,NAME) \    size=DO_ALIGN(size, ALIGNOF(TYPE)); \    size+=p->PIKE_CONCAT(num_,NAME)*sizeof(p->NAME[0]);   #include "program_areas.h"       data=malloc(size);    if(!data)    {    make_program_executable(p);    return; /* We are out of memory, but we don't care! */    }       size=0;    -  + #ifdef PIKE_USE_MACHINE_CODE +  /* As above. */ + #define BAR(NUMTYPE,TYPE,NAME) + #endif /* PIKE_USE_MACHINE_CODE */ +    #define FOO(NUMTYPE,TYPE,NAME) \    size=DO_ALIGN(size, ALIGNOF(TYPE)); \    MEMCPY(data+size,p->NAME,p->PIKE_CONCAT(num_,NAME)*sizeof(p->NAME[0])); \    PIKE_CONCAT(RELOCATE_,NAME)(p, (TYPE *)(data+size)); \    dmfree((char *)p->NAME); \    p->NAME=(TYPE *)(data+size); \    size+=p->PIKE_CONCAT(num_,NAME)*sizeof(p->NAME[0]);   #include "program_areas.h"       p->total_size=size + sizeof(struct program);
pike.git/src/program.c:1823:    memcpy(str->str, file, len<<shift);    Pike_compiler->last_file = end_shared_string(str);    }    }       }else{    static struct pike_string *s;    struct inherit i;      #define START_SIZE 64 + #ifdef PIKE_USE_MACHINE_CODE + #define BAR(NUMTYPE,TYPE,NAME) \ +  if (Pike_compiler->new_program->NAME) { \ +  mexec_free(Pike_compiler->new_program->NAME); \ +  Pike_compiler->new_program->PIKE_CONCAT(num_,NAME) = 0; \ +  } \ +  Pike_compiler->malloc_size_program->PIKE_CONCAT(num_,NAME) = \ +  START_SIZE; \ +  Pike_compiler->new_program->NAME = \ +  (TYPE *)mexec_alloc(sizeof(TYPE) * START_SIZE); + #endif /* PIKE_USE_MACHINE_CODE */   #define FOO(NUMTYPE,TYPE,NAME) \    if (Pike_compiler->new_program->NAME) { \    free (Pike_compiler->new_program->NAME); \    Pike_compiler->new_program->PIKE_CONCAT(num_,NAME) = 0; \    } \    Pike_compiler->malloc_size_program->PIKE_CONCAT(num_,NAME)=START_SIZE; \    Pike_compiler->new_program->NAME=(TYPE *)xalloc(sizeof(TYPE) * START_SIZE);   #include "program_areas.h"       i.prog=Pike_compiler->new_program;
pike.git/src/program.c:1950:    {    if(p->inherits[e].prog)    free_program(p->inherits[e].prog);    }    if(p->inherits[e].parent)    free_object(p->inherits[e].parent);    }       DOUBLEUNLINK(first_program, p);    + #if defined(PIKE_USE_MACHINE_CODE) && defined(VALGRIND_DISCARD_TRANSLATIONS) +  if(p->program) { +  VALGRIND_DISCARD_TRANSLATIONS(p->program, +  p->num_program*sizeof(p->program[0])); +  } + #endif /* PIKE_USE_MACHINE_CODE && VALGRIND_DISCARD_TRANSLATIONS */    if(p->flags & PROGRAM_OPTIMIZED)    {    if(p->program) {   #ifdef PIKE_USE_MACHINE_CODE - #ifdef VALGRIND_DISCARD_TRANSLATIONS -  VALGRIND_DISCARD_TRANSLATIONS(p->program, -  p->num_program*sizeof(p->program[0])); - #endif /* VALGRIND_DISCARD_TRANSLATIONS */ - #endif /* PIKE_USE_MACHINE_CODE */ +  mexec_free(p->program); + #else /* PIKE_USE_MACHINE_CODE */    dmfree(p->program); -  + #endif /* PIKE_USE_MACHINE_CODE */    }   #define FOO(NUMTYPE,TYPE,NAME) p->NAME=0;   #include "program_areas.h"    }else{ -  + #ifdef PIKE_USE_MACHINE_CODE + #define BAR(NUMTYPE,TYPE,NAME) \ +  if(p->NAME) { mexec_free((char *)p->NAME); p->NAME=0; } + #endif /* PIKE_USE_MACHINE_CODE */   #define FOO(NUMTYPE,TYPE,NAME) \    if(p->NAME) { dmfree((char *)p->NAME); p->NAME=0; }   #include "program_areas.h"    }       EXIT_PIKE_MEMOBJ(p);       GC_FREE(p);   }