Example #1
0
void xmlvm_init()
{
#ifdef XMLVM_ENABLE_STACK_TRACES
    threadToStackTraceMapPtr = malloc(sizeof(struct hash_struct**));
    struct hash_struct* map = NULL; // This must be set to NULL according to the UTHash documentation
    *threadToStackTraceMapPtr = map;

    JAVA_LONG nativeThreadId = (JAVA_LONG) pthread_self();
    createStackForNewThread(nativeThreadId);
#endif

#ifndef XMLVM_NO_GC
//#ifdef DEBUG
//    setenv("GC_PRINT_STATS", "1", 1);
//#endif
    GC_INIT();
    GC_enable_incremental();
#endif

    staticInitializerController = XMLVM_MALLOC(sizeof(XMLVM_STATIC_INITIALIZER_CONTROLLER));
    staticInitializerController->initMutex = XMLVM_MALLOC(sizeof(pthread_mutex_t));
    if (0 != pthread_mutex_init(staticInitializerController->initMutex, NULL)) {
        XMLVM_ERROR("Error initializing static initializer mutex", __FILE__, __FUNCTION__, __LINE__);
    }

    __INIT_org_xmlvm_runtime_XMLVMArray();
    java_lang_Class_initNativeLayer__();
    __INIT_java_lang_System();
    org_xmlvm_runtime_XMLVMUtil_init__();
    /*
     * The implementation of the constant pool makes use of cross-compiled Java data structures.
     * During initialization of the VM done up to this point there are some circular dependencies
     * between class initializers of various classes and the constant pool that lead to some
     * inconsistencies. The easiest way to fix this is to clear the constant pool cache.
     */
    xmlvm_clear_constant_pool_cache();
    
#ifndef XMLVM_NO_GC
    GC_finalize_on_demand = 1;
    GC_java_finalization = 1;
    java_lang_Thread* finalizerThread = (java_lang_Thread*) org_xmlvm_runtime_FinalizerNotifier_startFinalizerThread__();
    GC_finalizer_notifier = org_xmlvm_runtime_FinalizerNotifier_finalizerNotifier__;
#endif

	reference_array = XMLVMUtil_NEW_ArrayList();
}
Example #2
0
PCR_ERes
PCR_GC_Run(void)
{

    if( !PCR_Base_TestPCRArg("-nogc") ) {
        GC_quiet = ( PCR_Base_TestPCRArg("-gctrace") ? 0 : 1 );
        GC_use_debug = (GC_bool)PCR_Base_TestPCRArg("-debug_alloc");
        GC_init();
        if( !PCR_Base_TestPCRArg("-nogc_incremental") ) {
            /*
             * awful hack to test whether VD is implemented ...
             */
            if( PCR_VD_Start( 0, NIL, 0) != PCR_ERes_FromErr(ENOSYS) ) {
                GC_enable_incremental();
            }
        }
    }
    return PCR_ERes_okay;
}
Example #3
0
int APIENTRY WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
                      LPSTR command_line, int nCmdShow)
{
   MSG         msg;
   WNDCLASS    wndclass;
   HACCEL      hAccel;

   GC_set_find_leak(0);
   GC_INIT();
#  ifndef NO_INCREMENTAL
     GC_enable_incremental();
#  endif
#  if defined(CPPCHECK)
     GC_noop1((GC_word)&WinMain);
#  endif

   if (!hPrevInstance)
   {
      wndclass.style          = CS_HREDRAW | CS_VREDRAW;
      wndclass.lpfnWndProc    = WndProc;
      wndclass.cbClsExtra     = 0;
      wndclass.cbWndExtra     = DLGWINDOWEXTRA;
      wndclass.hInstance      = hInstance;
      wndclass.hIcon          = LoadIcon (hInstance, szAppName);
      wndclass.hCursor        = LoadCursor (NULL, IDC_ARROW);
      wndclass.hbrBackground  = (HBRUSH)GetStockObject(WHITE_BRUSH);
      wndclass.lpszMenuName   = TEXT("DE");
      wndclass.lpszClassName  = szAppName;

      if (RegisterClass (&wndclass) == 0) {
          de_error("RegisterClass error");
          return(0);
      }
   }

   /* Empirically, the command line does not include the command name ...
   if (command_line != 0) {
       while (isspace(*command_line)) command_line++;
       while (*command_line != 0 && !isspace(*command_line)) command_line++;
       while (isspace(*command_line)) command_line++;
   } */

   if (command_line == 0 || *command_line == 0) {
        de_error("File name argument required");
        return( 0 );
   } else {
        char *p = command_line;

        while (*p != 0 && !isspace(*(unsigned char *)p))
            p++;
        arg_file_name = CORD_to_char_star(
                            CORD_substr(command_line, 0, p - command_line));
   }

   hwnd = CreateWindow (szAppName,
                        TEXT("Demonstration Editor"),
                        WS_OVERLAPPEDWINDOW | WS_CAPTION, /* Window style */
                        CW_USEDEFAULT, 0, /* default pos. */
                        CW_USEDEFAULT, 0, /* default width, height */
                        NULL,   /* No parent */
                        NULL,   /* Window class menu */
                        hInstance, NULL);
   if (hwnd == NULL) {
        de_error("CreateWindow error");
        return(0);
   }

   ShowWindow (hwnd, nCmdShow);

   hAccel = LoadAccelerators( hInstance, szAppName );

   while (GetMessage (&msg, NULL, 0, 0))
   {
      if( !TranslateAccelerator( hwnd, hAccel, &msg ) )
      {
         TranslateMessage (&msg);
         DispatchMessage (&msg);
      }
   }
   return (int)msg.wParam;
}
Example #4
0
        void main() {
                Node    root;
                Node    longLivedTree;
                Node    tempTree;
                long    tStart, tFinish;
                long    tElapsed;

#ifdef GC
// GC_full_freq = 30;
GC_enable_incremental();
#endif
                cout << "Garbage Collector Test" << endl;
                cout << " Live storage will peak at "
                     << 2 * sizeof(Node0) * TreeSize(kLongLivedTreeDepth) +
                        sizeof(double) * kArraySize
                     << " bytes." << endl << endl;
                cout << " Stretching memory with a binary tree of depth "
                     << kStretchTreeDepth << endl;
                PrintDiagnostics();
               
                tStart = currentTime();
                
                // Stretch the memory space quickly
                tempTree = MakeTree(kStretchTreeDepth);
#		ifndef GC
                  delete tempTree;
#		endif
                tempTree = 0;

                // Create a long lived object
                cout << " Creating a long-lived binary tree of depth "
                     << kLongLivedTreeDepth << endl;
#		ifndef GC
                  longLivedTree = new Node0();
#		else 
                  longLivedTree = new (GC_NEW(Node0)) Node0();
#		endif
                Populate(kLongLivedTreeDepth, longLivedTree);

                // Create long-lived array, filling half of it
                cout << " Creating a long-lived array of "
                     << kArraySize << " doubles" << endl;
#		ifndef GC
                  double *array = new double[kArraySize];
#		else
                  double *array = (double *)
				GC_MALLOC_ATOMIC(sizeof(double) * kArraySize);
#		endif
                for (int i = 0; i < kArraySize/2; ++i) {
                        array[i] = 1.0/i;
                }
                PrintDiagnostics();

                for (int d = kMinTreeDepth; d <= kMaxTreeDepth; d += 2)
{
                        TimeConstruction(d);
                }

                if (longLivedTree == 0 || array[1000] != 1.0/1000)
                        cout << "Failed" << endl;
                                        // fake reference to LongLivedTree
                                        // and array
                                        // to keep them from being optimized away

                tFinish = currentTime();
                tElapsed = elapsedTime(tFinish-tStart);
                PrintDiagnostics();
                cout << "Completed in " << tElapsed << " msec" << endl;
#		ifdef GC
		  cout << "Completed " << GC_gc_no << " collections" <<endl;
		  cout << "Heap size is " << GC_get_heap_size() << endl;
#		endif
        }
Example #5
0
File: main.c Project: NX-Andro/x3
int main(int argc, char *argv[])
{
    int run_as_daemon;
    int debug;
    pid_t pid = 0;
    FILE *file_out;
    struct sigaction sv;

#if WITH_MALLOC_BOEHM_GC
    GC_find_leak = 1;
    GC_set_warn_proc(gc_warn_proc);
    GC_enable_incremental();
#endif

    run_as_daemon = 1;
    debug = 0;
    tools_init();

    /* set up some signal handlers */
    memset(&sv, 0, sizeof(sv));
    sigemptyset(&sv.sa_mask);
    sv.sa_handler = SIG_IGN;
    sigaction(SIGPIPE, &sv, NULL);
    sv.sa_handler = sigaction_rehash;
    sigaction(SIGHUP, &sv, NULL);
    sv.sa_handler = sigaction_writedb;
    sigaction(SIGINT, &sv, NULL);
    sv.sa_handler = sigaction_exit;
    sigaction(SIGQUIT, &sv, NULL);
    sv.sa_handler = sigaction_wait;
    sigaction(SIGCHLD, &sv, NULL);

    if (argc > 1) { /* parse command line, if any */
        int c;
        struct option options[] =
        {
            {"config", 1, 0, 'c'},
            {"debug", 0, 0, 'd'},
            {"foreground", 0, 0, 'f'},
            {"help", 0, 0, 'h'},
            {"check", 0, 0, 'k'},
            {"replay", 1, 0, 'r'},
            {"version", 0, 0, 'v'},
            {0, 0, 0, 0}
        };

        while ((c = getopt_long(argc, argv, "c:dfhkr:v", options, NULL)) != -1) {
            switch (c) {
            case 'c':
                services_config = optarg;
                break;
            case 'k':
                if (conf_read(services_config)) {
                    printf("%s appears to be a valid configuration file.\n", services_config);
                } else {
                    printf("%s is an invalid configuration file.\n", services_config);
                }
                exit(0);
            case 'r':
                replay_file = fopen(optarg, "r");
                if (!replay_file) {
                    fprintf(stderr, "Could not open %s for reading: %s (%d)\n",
                            optarg, strerror(errno), errno);
                    exit(0);
                }
                break;
            case 'd':
                debug = 1;
                break;
            case 'f':
                run_as_daemon = 0;
                break;
            case 'v':
                version();
                license();
                exit(0);
            case 'h':
            default:
                usage(argv[0]);
                exit(0);
            }
        }
    }

    version();

    if (replay_file) {
        /* We read a line here to "prime" the replay file parser, but
         * mostly to get the right value of "now" for when we do the
         * irc_introduce. */
        replay_read_line();
    } else {
        now = time(NULL);
    }
    boot_time = now;

    fprintf(stdout, "Initializing daemon...\n");
    if (!conf_read(services_config)) {
        fprintf(stderr, "Unable to read %s.\n", services_config);
        exit(1);
    }

    conf_register_reload(uplink_compile);

    if (run_as_daemon) {
        /* Attempt to fork into the background if daemon mode is on. */
        pid = fork();
        if (pid < 0) {
            fprintf(stderr, "Unable to fork: %s\n", strerror(errno));
        } else if (pid > 0) {
            fprintf(stdout, "Forking into the background (pid: %d)...\n", pid);
            exit(0);
        }
        setsid();
    }

    file_out = fopen(PID_FILE, "w");
    if (file_out == NULL) {
        /* Create the main process' pid file */
        fprintf(stderr, "Unable to create PID file: %s", strerror(errno));
    } else {
        fprintf(file_out, "%i\n", (int)getpid());
        fclose(file_out);
    }

    if (run_as_daemon) {
        /* Close these since we should not use them from now on. */
        fclose(stdin);
        fclose(stdout);
        fclose(stderr);
    }

    services_argc = argc;
    services_argv = argv;

    atexit(call_exit_funcs);
    reg_exit_func(main_shutdown, NULL);

    log_init();
    MAIN_LOG = log_register_type("x3", "file:main.log");
    if (debug)
        log_debug();
    ioset_init();
    init_structs();
    init_parse();
    modcmd_init();
    saxdb_init();
    sar_init();
    gline_init();
    shun_init();
    mail_init();
    helpfile_init();
    conf_globals(); /* initializes the core services */
    conf_rlimits();
    modules_init();
    message_register_table(msgtab);
    modcmd_finalize();
    saxdb_finalize();
    helpfile_finalize();
    modules_finalize();

    /* The first exit func to be called *should* be saxdb_write_all(). */
    reg_exit_func(saxdb_write_all, NULL);
    if (replay_file) {
        char *msg;
        log_module(MAIN_LOG, LOG_INFO, "Beginning replay...");
        srand(now);
        replay_event_loop();
        if ((msg = dict_sanity_check(clients))) {
            log_module(MAIN_LOG, LOG_ERROR, "Clients insanity: %s", msg);
            free(msg);
        }
        if ((msg = dict_sanity_check(channels))) {
            log_module(MAIN_LOG, LOG_ERROR, "Channels insanity: %s", msg);
            free(msg);
        }
        if ((msg = dict_sanity_check(servers))) {
            log_module(MAIN_LOG, LOG_ERROR, "Servers insanity: %s", msg);
            free(msg);
        }
    } else {
        now = time(NULL);
        srand(now);
        ioset_run();
    }
    return 0;
}