Beispiel #1
0
static value cache_find( request_rec *r ) {
	cache *c = (cache*)local_get(cache_root);
	cache *prev = NULL;
	value fname = alloc_string(r->filename);
	while( c != NULL ) {
		if( val_compare(fname,c->file) == 0 ) {
			if( config.use_cache && FTIME(r) == c->time ) {
				c->hits++;
				return c->main;
			}
			if( prev == NULL )
				local_set(cache_root,c->next);
			else
				prev->next = c->next;
			free_root((value*)c);
			// try to lower memory partitioning
			// when a module is updated
			c = NULL;
			gc_major();
			break;
		}
		prev = c;
		c = c->next;
	}
	return NULL;
}
Beispiel #2
0
static int neko_handler( request_rec *r ) {
	int ret;
	if( strcmp(r->handler,"neko-handler") != 0)
		return DECLINED;
	if( config.use_stats ) neko_stats_measure(NULL,r->hostname,1);
	ret = neko_handler_rec(r);
	neko_vm_select(NULL);
	if( config.use_stats ) neko_stats_measure(NULL,r->hostname,0);
	gc_major();
	return ret;
}
/* allocate a heap record of specified number of words */
uintptr_t *heapalloc(size_t words) {
  uintptr_t *p;

  // printf during heap alloc expensive/slow for large heap sizes
  // only enable when testing small heaps
#ifdef DEBUG_ALLOC
  printf("heapalloc request num words: %zu\n", words);
#endif

  if (heap->end - heap->nursery_avail < words) {
    // perform minor collection
    gc_minor();
    if ((heap->end_old - heap->start) > ((heap->end - heap->start) /
                                         MAX_OLD_TO_HEAP_RATIO)) {
      // old generation has become too large - time to collect
      gc_major();
    }
    // verify heap space is sufficient to continue
    // after major collection - if old space is larger than reserve than cannot continue
    // if nursery is not large enough to allocate the word - cannot continue
    if ((heap->end_old - heap->start) > (heap->end_reserve - heap->end_old)
        || (heap->end - heap->nursery_avail < words)) {

      print_heap_region();
      printf("heapalloc request num words: %zu\n", words);
      printf("heap nursery avail: %zu\n", (uintptr_t)heap->nursery_avail);

      die_w_msg("out of heap space");
    }
  }
  p = heap->nursery_avail;
  heap->nursery_avail += words;

#ifdef DEBUG_ALLOC
  printf("allocated from nursery at %zu\n", (uintptr_t)p);
#endif

  return p;
}