Example #1
0
jboolean initGC(Options* options) {
    GC_set_no_dls(1);
    GC_set_java_finalization(1);
    GC_INIT();
    if (options->maxHeapSize > 0) {
        GC_set_max_heap_size(options->maxHeapSize);
    }
    if (options->initialHeapSize > 0) {
        size_t now = GC_get_heap_size();
        if (options->initialHeapSize > now) {
            GC_expand_hp(options->initialHeapSize - now);
        }
    }

    objectGCKind = GC_new_kind(GC_new_free_list(), GC_MAKE_PROC(GC_new_proc(markObject), 0), 0, 1);
    largeArrayGCKind = GC_new_kind(GC_new_free_list(), GC_DS_LENGTH, 1, 1);
    atomicObjectGCKind = GC_new_kind(GC_new_free_list(), GC_DS_LENGTH, 0, 1);
    referentEntryGCKind = gcNewDirectBitmapKind(REFERENT_ENTRY_GC_BITMAP);

    if (rvmInitMutex(&referentsLock) != 0) {
        return FALSE;
    }
    if (rvmInitMutex(&gcRootsLock) != 0) {
        return FALSE;
    }

    GC_set_warn_proc(gcWarnProc);

    return TRUE;
}
Example #2
0
File: RT0.c Project: AlexIljin/oo2c
void OOC_RT0_init() {
#ifdef USE_BOEHM_GC
    GC_all_interior_pointers = 0;
    GC_INIT();
    /* tell GC to accept pointers with an offset of 8/16/24 as references to
       a given object; this is necessary if the GC is running with the
       ALL_INTERIOR_POINTERS option; the offsets cover records and open
       arrays with up to 5 free dimensions on 32 bit architectures */
    GC_REGISTER_DISPLACEMENT(8);
    GC_REGISTER_DISPLACEMENT(16);
    GC_REGISTER_DISPLACEMENT(24);
#endif

    modules = RT0__NewBlock(sizeModules*sizeof(RT0__Module));

    PS(RT0__boolean  , "BOOLEAN",  RT0__strBoolean  , sizeof(OOC_BOOLEAN));
    PS(RT0__char     , "CHAR",     RT0__strChar     , sizeof(OOC_CHAR8));
    PS(RT0__longchar , "LONGCHAR", RT0__strLongchar , sizeof(OOC_CHAR16));
    PS(RT0__ucs4char , "UCS4CHAR", RT0__strUCS4Char , sizeof(OOC_CHAR32));
    PS(RT0__shortint , "SHORTINT", RT0__strShortint , sizeof(OOC_INT8));
    PS(RT0__integer  , "INTEGER",  RT0__strInteger  , sizeof(OOC_INT16));
    PS(RT0__longint  , "LONGINT",  RT0__strLongint  , sizeof(OOC_INT32));
    PS(RT0__real     , "REAL",     RT0__strReal     , sizeof(OOC_REAL32));
    PS(RT0__longreal , "LONGREAL", RT0__strLongreal , sizeof(OOC_REAL64));
    PS(RT0__set32    , "SET",      RT0__strSet32    , sizeof(OOC_UINT32));
    PS(RT0__byte     , "BYTE",     RT0__strByte     , sizeof(OOC_BYTE));
    PS(RT0__ptr      , "PTR",      RT0__strPtr      , sizeof(OOC_PTR));
    PS(RT0__procedure, "$PROC",    RT0__strProcedure, sizeof(OOC_PTR));
}
Example #3
0
int main(int argc, char **argv)
{
  GC_INIT();
  IM2_initialize();
  ::testing::InitGoogleTest(&argc, argv);
  return RUN_ALL_TESTS();
}
Example #4
0
void ILGCInit(unsigned long maxSize)
{
	GC_INIT();		/* For shared library initialization on sparc */	
	GC_set_max_heap_size((size_t)maxSize);
	
	/* Set up the finalization system the way we want it */
	GC_finalize_on_demand = 1;
	GC_java_finalization = 1;
	GC_finalizer_notifier = GCNotifyFinalize;
	_FinalizersDisabled = 0;

	_ILMutexCreate(&_FinalizerLock);

	/* Create the finalizer thread */
	_FinalizerStopFlag = 0;	
	_FinalizerThread = ILThreadCreate(_FinalizerThreadFunc, 0);
	
	if (_FinalizerThread)
	{
		_FinalizerSignal = ILWaitEventCreate(1, 0);
		_FinalizerResponse = ILWaitEventCreate(1, 0);

		/* Make the finalizer thread a background thread */
		ILThreadSetBackground(_FinalizerThread, 1);

		/* To speed up simple command line apps, the finalizer thread doesn't start
		    until it is first needed */
	}
}
Example #5
0
File: bacon.c Project: wbhart/bacon
int main(void)
{
   ast_t * a;
   int jval;
   jit_t * jit;
   
   GC_INIT();
   GREG g;
 
   ast_init();
   sym_tab_init();
   types_init();
   scope_init();
   loc_tab_init();
   intrinsics_init();
   jit = llvm_init();
   ZZ_init(jit);
   
   yyinit(&g);

   printf("Welcome to Bacon v0.1\n\n");
   printf("> ");

   while (1)
   {
      if (!(jval = setjmp(exc)))
      {
         if (!yyparse(&g))
         {
            printf("Error parsing\n");
            abort();
         } else if (root)
         {
#if DEBUG1
            printf("\n");
            ast_print(root, 0);
#endif
            inference(root);
#if DEBUG2
            printf("\n");
            /*ast2_print(root, 0);*/
#endif
            exec_root(jit, root);
            root = NULL;
         }
      } else if (jval == 1)
         root = NULL;
      else /* jval == 2 */
         break;
      
      printf("\n> ");
   }

   llvm_cleanup(jit);
   yydeinit(&g);
    
   printf("\n");

   return 0;
}
Example #6
0
int main(void)
{
    GC_INIT();

    GC_set_max_heap_size(100*1024*1024);
        /* Otherwise heap expansion aborts when deallocating large block. */
        /* That's OK.  We test this corner case mostly to make sure that  */
        /* it fails predictably.                                          */
    GC_expand_hp(1024*1024*5);
    if (sizeof(long) == sizeof(void *)) {
        void *r = GC_MALLOC(LONG_MAX-1024);
        if (0 != r) {
            fprintf(stderr,
                    "Size LONG_MAX-1024 allocation unexpectedly succeeded\n");
            exit(1);
        }
        r = GC_MALLOC(LONG_MAX);
        if (0 != r) {
            fprintf(stderr,
                    "Size LONG_MAX allocation unexpectedly succeeded\n");
            exit(1);
        }
        r = GC_MALLOC((size_t)LONG_MAX + 1024);
        if (0 != r) {
            fprintf(stderr,
                    "Size LONG_MAX+1024 allocation unexpectedly succeeded\n");
            exit(1);
        }
    }
    return 0;
}
Example #7
0
int main() {
  int i;

  GC_INIT();

  uniq("%s:%d: error: gc library doesn't find all the active pointers in registers or on the stack!\n"
       "           Perhaps GC_push_regs was configured incorrectly.\n",
       GC_malloc(12), GC_malloc(12), GC_malloc(12), (GC_gcollect(),GC_malloc(12)),
       GC_malloc(12), GC_malloc(12), GC_malloc(12), (GC_gcollect(),GC_malloc(12)),
       GC_malloc(12), GC_malloc(12), GC_malloc(12), (GC_gcollect(),GC_malloc(12)),
       GC_malloc(12), GC_malloc(12), GC_malloc(12), (GC_gcollect(),GC_malloc(12)),
       GC_malloc(12), GC_malloc(12), GC_malloc(12), (GC_gcollect(),GC_malloc(12)),
       (void *)0);

  for (i=0; i<20; i++) {
       if (i%4 == 3) GC_gcollect();
       x[i] = GC_malloc(12);
  }
  uniq("%s:%d: error: gc library doesn't find all the active pointers in static memory!\n"
        "           Perhaps GC_add_roots needs to be told about static memory.\n",
       x[0],x[1],x[2],x[3],x[4],x[5],x[6],x[7],x[8],x[9],x[10],x[11],x[12],x[13],x[14],x[15],x[16],x[17],x[18],x[19], (void *)0);


  for (i=0; i<20; i++) {
       reg(GC_malloc(12));
  }
  GC_gcollect();		/* just to see if finalizers get called */

  return had_error;
}
Example #8
0
int libxl_sched_credit2_params_set(libxl_ctx *ctx, uint32_t poolid,
                                   libxl_sched_credit2_params *scinfo)
{
    struct xen_sysctl_credit2_schedule sparam;
    int r, rc;
    GC_INIT(ctx);

    rc = sched_ratelimit_check(gc, scinfo->ratelimit_us);
    if (rc) goto out;

    sparam.ratelimit_us = scinfo->ratelimit_us;

    r = xc_sched_credit2_params_set(ctx->xch, poolid, &sparam);
    if (r < 0) {
        LOGE(ERROR, "Setting Credit2 scheduler parameters");
        rc = ERROR_FAIL;
        goto out;
    }

    scinfo->ratelimit_us = sparam.ratelimit_us;

    rc = 0;
 out:
    GC_FREE;
    return rc;
}
int main (void)
{
  int i;
  GC_INIT ();

# ifdef GC_SOLARIS_THREADS
    pthread_key_create (&key, on_thread_exit);
# else
    pthread_once (&key_once, make_key);
# endif
  for (i = 0; i < NTHREADS; i++) {
    pthread_t t;

    if (GC_pthread_create(&t, NULL, entry, NULL) == 0) {
      void *res;
      int code = (i & 1) != 0 ? GC_pthread_join(t, &res)
                                : GC_pthread_detach(t);

      if (code != 0) {
        fprintf(stderr, "Thread %s failed %d\n",
                (i & 1) != 0 ? "join" : "detach", code);
        exit(2);
      }
    }
  }
  return 0;
}
Example #10
0
int main(int argc, char * const argv[])
{
    ParserContext context;
    GC_INIT();
    const char *syntax_file = NULL;
    const char *orig_argv0 = argv[0];
    int opt;
    while ((opt = getopt(argc, argv, "f:")) != -1) {
        switch (opt) {
        case 'f':
            syntax_file = optarg;
            break;
        default: /* '?' */
            pegvm_usage(orig_argv0);
        }
    }
    if (syntax_file == NULL) {
        pegvm_usage(orig_argv0);
    }
    argc -= optind;
    argv += optind;
    if (argc == 0) {
        pegvm_usage(orig_argv0);
    }
    ParserContext_Init(&context);
    if (ParserContext_LoadSyntax(&context, syntax_file)) {
        pegvm_error("invalid bytecode");
    }
    if (ParserContext_ParseFiles(&context, argc, (char **)argv)) {
        pegvm_error(context.last_error);
    }
    ParserContext_Dispose(&context);
    return 0;
}
Example #11
0
int initialize_memory()
{
  GC_INIT();
  POINTER_MASK = 0xFFFFFFFFFFFFFFF0;

  return 0;
}
Example #12
0
int
main (int argc, char **argv)
{
  // Set exit routines
  atexit (GC_gcollect);
  atexit (close_libs);
  atexit (thread_cleanup);

  // Start the garbage collector
  GC_INIT ();

  // Set up GMP library
  mp_set_memory_functions (&FACT_malloc,
			   &gmp_realloc_wrapper,
			   &gmp_free_wrapper);

  // Start the main thread
  root_thread = FACT_malloc (sizeof (FACT_thread_t));
  root_thread->tid = pthread_self ();
  root_thread->exited  = false;
  root_thread->destroy = false;
  root_thread->next = NULL;
  root_thread->prev = NULL;
  root_thread->root = NULL;
  root_thread->nid  = 0;
  pthread_mutex_init (&root_thread->queue_lock, NULL);

  // Process the arguments and start the interpreter.
  process_args (argc, argv);

  // Exit.
  exit (0);
}
Example #13
0
  GC_TEST_EXPORT_API void * libsrl_init(void)
  {
#   ifndef STATICROOTSLIB_INIT_IN_MAIN
      GC_INIT();
#   endif
    return GC_MALLOC(sizeof(struct treenode));
  }
Example #14
0
int main() {
  GC_INIT();
  const RRB *rrb = rrb_create();

  for (uintptr_t i = 0; i < 33; i++) {
    rrb = rrb_push(rrb, (void *) i);
  }
  int file_size = rrb_to_dot_file(rrb, "foo.dot");
  switch (file_size) {
  case -1:
    puts("Had trouble either opening or closing \"foo.dot\".");
    return 1;
  case -2:
    puts("Had trouble writing to the file \"foo.dot\".");
    return 1;
  default:
    printf("The file \"foo.dot\" contains an RRB-tree in dot format "
           "(%d bytes)\n", file_size);
    if (RRB_BITS != 2) {
      puts("\n"
"(If you want to use the code for visualising RRB-trees, I'd recommend to use the\n"
" settings `CFLAGS='-Ofast' ./configure --with-branching=2` instead. It is much\n"
" easier to visualise/comprehend with 4 elements per trie node instead of 32.)");
    }
    return 0;
  }
}
Example #15
0
_hidden int libxl__init_recursive_mutex(libxl_ctx *ctx, pthread_mutex_t *lock)
{
    GC_INIT(ctx);
    pthread_mutexattr_t attr;
    int rc = 0;

    if (pthread_mutexattr_init(&attr) != 0) {
        LOGE(ERROR, "Failed to init mutex attributes");
        rc = ERROR_FAIL;
        goto out;
    }
    if (pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE) != 0) {
        LOGE(ERROR, "Failed to set mutex attributes");
        rc = ERROR_FAIL;
        goto out;
    }
    if (pthread_mutex_init(lock, &attr) != 0) {
        LOGE(ERROR, "Failed to init mutex");
        rc = ERROR_FAIL;
        goto out;
    }
out:
    pthread_mutexattr_destroy(&attr);
    GC_FREE;
    return rc;
}
Example #16
0
int libxl_vcpu_sched_params_get_all(libxl_ctx *ctx, uint32_t domid,
                                    libxl_vcpu_sched_params *scinfo)
{
    GC_INIT(ctx);
    int rc;

    scinfo->sched = libxl__domain_scheduler(gc, domid);

    switch (scinfo->sched) {
    case LIBXL_SCHEDULER_SEDF:
        LOGD(ERROR, domid, "SEDF scheduler is no longer available");
        rc = ERROR_FEATURE_REMOVED;
        break;
    case LIBXL_SCHEDULER_CREDIT:
    case LIBXL_SCHEDULER_CREDIT2:
    case LIBXL_SCHEDULER_ARINC653:
    case LIBXL_SCHEDULER_NULL:
        LOGD(ERROR, domid, "per-VCPU parameter getting not supported for this scheduler");
        rc = ERROR_INVAL;
        break;
    case LIBXL_SCHEDULER_RTDS:
        rc = sched_rtds_vcpu_get_all(gc, domid, scinfo);
        break;
    default:
        LOGD(ERROR, domid, "Unknown scheduler");
        rc = ERROR_INVAL;
        break;
    }

    GC_FREE;
    return rc;
}
Example #17
0
int main() {
  GC_INIT();
  // Create the input file.
  // Right now, this requires an actual file, but on non-mac os x
  // systems, there is a function fmemopen() which lets you open
  // an in-memory buffer as a file handle. There are shims for it on
  // mac os x, but its more complex than it needs to be
  FILE *input = fopen("example.lisp", "r");
  
  // Create the parser state object. This could probably be moved into parse()
  // but for now you need to do it seperately
  struct p_state state = new_p_state(input);
  
  // parse the lisp code into an ast
  struct sexp *parsed = parse(&state);
  
  // Display the resulting ast
  print_ast_node(parsed[0]);

  printf("\n********************\n");

  scm *res = run_lisp(parsed[0]);
  
  printf("RESULT: ");
  print_scm(res);
  printf("\n");
}
Example #18
0
int main(void) {
    GC_INIT();
    GREG g;
 
    int jval, jval2;
    char c;

    sym_tab_init();
    ast_init();
    type_init();
    scope_init();
    rel_assign_init();

    jit_t * jit = llvm_init();

    yyinit(&g);

    printf("Welcome to Cesium v 0.2\n");
    printf("To exit press CTRL-D\n\n");

    printf("> ");

    while (1)
    {
       if (!(jval = setjmp(exc)))
       {
          if (!yyparse(&g))
          {
             printf("Error parsing\n");
             abort();
          } else if (root != NULL)
          {
             rel_stack_init();
             rel_assign_mark();
             scope_mark();
             annotate_ast(root);
             if (TRACE) 
                ast_print(root, 0);
             unify(rel_stack, rel_assign);
             if (TRACE)
                print_assigns(rel_assign);
             exec_root(jit, root);
             if (root->tag != AST_FNDEC)
                 rel_assign_rewind();
           }
        } else if (jval == 1)
              root = NULL;
        else if (jval == 2)
              break;
        printf("\n> ");
    }
  
    yydeinit(&g);
    llvm_cleanup(jit);

    return 0;
}
Example #19
0
void* Object::operator new( size_t size) {
    if(SYLPH_UNLIKELY(!Object::gc_inited)) {
        GC_INIT();
        Object::gc_inited = true;
    }
    void * toReturn = GC_MALLOC(size);
    if (!toReturn) throw std::bad_alloc();
    else return toReturn;
}
int
main (int argc, char **argv)
{
  GC_INIT ();
  setlocale (LC_ALL, "");
  printf ("%s|", GFileGetUserDataDir ());
  ulc_fprintf (stdout, "%U|", u8_GFileGetUserDataDir ());
  return 0;
}
Example #21
0
int main(int argc, char **argv)
{
    int i;
    int model, model_min, model_max;
    testobj_t *keep_arr;

    GC_INIT();
    GC_init_finalized_malloc();

    keep_arr = GC_MALLOC(sizeof(void *)*KEEP_CNT);

    if (argc == 2 && strcmp(argv[1], "--help") == 0) {
        fprintf(stderr,
                "Usage: %s [FINALIZATION_MODEL]\n"
                "\t0 -- original finalization\n"
                "\t1 -- finalization on reclaim\n"
                "\t2 -- no finalization\n", argv[0]);
        return 1;
    }
    if (argc == 2) {
        model_min = model_max = atoi(argv[1]);
        if (model_min < 0 || model_max > 2)
            exit(2);
    }
    else {
        model_min = 0;
        model_max = 2;
    }

    printf("\t\t\tfin. ratio       time/s    time/fin.\n");
    for (model = model_min; model <= model_max; ++model) {
        double t = 0.0;
        free_count = 0;

#       ifdef CLOCK_TYPE
            CLOCK_TYPE tI, tF;
            GET_TIME(tI);
#       endif
        for (i = 0; i < ALLOC_CNT; ++i) {
            int k = rand() % KEEP_CNT;
            keep_arr[k] = testobj_new(model);
        }
        GC_gcollect();
#       ifdef CLOCK_TYPE
            GET_TIME(tF);
            t = MS_TIME_DIFF(tF, tI)*1e-3;
#       endif

        if (model < 2)
            printf("%20s: %12.4lf %12lg %12lg\n", model_str[model],
                   free_count/(double)ALLOC_CNT, t, t/free_count);
        else
            printf("%20s: %12.4lf %12lg %12s\n",
                   model_str[model], 0.0, t, "N/A");
    }
    return 0;
}
Example #22
0
int libxl_domain_rename(libxl_ctx *ctx, uint32_t domid,
                        const char *old_name, const char *new_name)
{
    GC_INIT(ctx);
    int rc;
    rc = libxl__domain_rename(gc, domid, old_name, new_name, XBT_NULL);
    GC_FREE;
    return rc;
}
Example #23
0
static hlt_match_token_state* _match_token_init(hlt_regexp* re, hlt_exception** excpt, hlt_execution_context* ctx)
{
    hlt_match_token_state* state = GC_NEW(hlt_match_token_state, ctx);
    GC_INIT(state->re, re, hlt_regexp, ctx);
    state->acc = 0;
    state->first = JRX_ASSERTION_BOL | JRX_ASSERTION_BOD;
    jrx_match_state_init(&re->regexp, 0, &state->ms);

    return state;
}
Example #24
0
int libxl_get_memory_target(libxl_ctx *ctx, uint32_t domid,
                            uint64_t *out_target)
{
    GC_INIT(ctx);
    int rc;

    rc = libxl__get_memory_target(gc, domid, out_target, NULL);

    GC_FREE;
    return rc;
}
Example #25
0
int main (void)
{
  GC_set_all_interior_pointers(0);
  GC_set_max_heap_size(16000000);
  /*GC_set_java_finalization(1);*/
  GC_INIT();

  myTest();

  return 0;
}
Example #26
0
int main() {
  GC_INIT();
  randomize_rand();

  int fail = 0;
  
  const RRB *rrb = rrb_create();
  for (uint32_t i = 0; i < SIZE; i++) {
    rrb = rrb_push(rrb, (void *)((intptr_t) rand() % 10000));
  }

  const RRB **sliced = GC_MALLOC(sizeof(RRB *) * SLICED);
  for (uint32_t i = 0; i < SLICED; i++) {
    uint32_t from = (uint32_t) rand() % SIZE;
    uint32_t to = (uint32_t) (rand() % (SIZE - from)) + from;
    sliced[i] = rrb_slice(rrb, from, to);
  }

  for (uint32_t i = 0; i < CATTED; i++) {
    const RRB *multicat = rrb_create(); // Originally empty
    uint32_t tot_cats = (uint32_t) rand() % TOT_CATTED;
    uint32_t *merged_in = GC_MALLOC_ATOMIC(sizeof(uint32_t) * tot_cats);
    for (uint32_t cat_num = 0; cat_num < tot_cats; cat_num++) {
      merged_in[cat_num] = (uint32_t) rand() % SLICED;
      multicat = rrb_concat(multicat, sliced[merged_in[cat_num]]);
    }
    
    // checking consistency here
    uint32_t pos = 0;
    uint32_t merged_pos = 0;
    while (pos < rrb_count(multicat)) {
      const RRB *merged = sliced[merged_in[merged_pos]];
      
      for (uint32_t merged_i = 0; merged_i < rrb_count(merged);
           merged_i++, pos++) {
        intptr_t expected = (intptr_t) rrb_nth(merged, merged_i);
        intptr_t actual = (intptr_t) rrb_nth(multicat, pos);
        if (expected != actual) {
          printf("On multicatted object #%u, at merged element %u:\n",
                 i, merged_pos);
          printf("  Expected val at pos %u (%u in merged) to be %ld, but was %ld\n",
                 pos, merged_i, expected, actual);
          printf("  Size of merged: %u, is at index %u\n", rrb_count(merged),
                 merged_in[merged_pos]);
          printf("Sliced lists:\n");
          fail = 1;
          return fail;
        }
      }
      merged_pos++;
    }
  }
  return fail;
}
Example #27
0
int main(void)
{
#   ifdef THINK_C
        printf("cordtest:\n");
#   endif
    GC_INIT();
    test_basics();
    test_extras();
    test_printf();
    CORD_fprintf(stdout, "SUCCEEDED\n");
    return(0);
}
Example #28
0
File: init.c Project: seanofw/smile
/// <summary>
/// Initialize the Smile runtime.  This must be performed at least once on startup.
/// </summary>
void Smile_Init(void)
{
	if (Smile_IsInitialized) return;

	Smile_InitTicks();

	GC_INIT();

	Smile_HashOracle = (UInt32)GetBaselineEntropy();

	Smile_ResetEnvironment();
}
Example #29
0
void* Object::operator new( size_t size, GCPlacement gcp) {
    if(SYLPH_UNLIKELY(!Object::gc_inited)) {
        GC_INIT();
        Object::gc_inited = true;
    }
    void * toReturn;
    if (gcp == UseGC) toReturn = GC_MALLOC(size);
    else if (gcp == PointerFreeGC) toReturn = GC_MALLOC_ATOMIC(size);
    else toReturn = GC_MALLOC_UNCOLLECTABLE(size);
    if (!toReturn) throw std::bad_alloc();
    else return toReturn;
}
Example #30
0
int libxl_domain_get_nodeaffinity(libxl_ctx *ctx, uint32_t domid,
                                  libxl_bitmap *nodemap)
{
    GC_INIT(ctx);
    if (xc_domain_node_getaffinity(ctx->xch, domid, nodemap->map)) {
        LOGED(ERROR, domid, "Getting node affinity");
        GC_FREE;
        return ERROR_FAIL;
    }
    GC_FREE;
    return 0;
}