Esempio n. 1
0
void run_gc()
{
    int my_run = gc_n_run;

    //hal_mutex_lock( &alloc_mutex );
    if(vm_alloc_mutex) hal_mutex_lock( vm_alloc_mutex );  // TODO avoid Giant lock

    if (my_run != gc_n_run) // lock acquired when concurrent gc run finished
    {
        if(vm_alloc_mutex) hal_mutex_unlock( vm_alloc_mutex );  // TODO avoid Giant lock
        //hal_mutex_unlock( &alloc_mutex );
        return;
    }
    gc_n_run++;

    gc_flags_last_generation++; // bump generation
    if (gc_flags_last_generation == 0)  gc_flags_last_generation++;  // != 0 'cause allocation reset gc_flags to zero

    //phantom_virtual_machine_threads_stopped++; // pretend we are stopped
    //TODO: refine sinchronization

    if (debug_memory_leaks) pvm_memcheck();  // visualization
    if (debug_memory_leaks) printf("gc started...  ");


    cycle_root_buffer_clear(); // so two types of gc could coexists


    // First pass - tree walk, mark visited.
    //
    // Root is always used. All other objects, including pvm_root and pvm_root.threads_list, should be reached from root...
    mark_tree( get_root_object_storage() );


    // Second pass - linear walk to free unused objects.
    //
    int freed = free_unmarked();

    if ( freed > 0 )
       printf("\ngc: %i objects freed\n", freed);

    if (debug_memory_leaks) printf("gc finished!\n");
    if (debug_memory_leaks) pvm_memcheck();  // visualization

    //TODO refine synchronization
    //phantom_virtual_machine_threads_stopped--;
    //hal_mutex_unlock( &alloc_mutex );
    if(vm_alloc_mutex) hal_mutex_unlock( vm_alloc_mutex );  // TODO avoid Giant lock
}
Esempio n. 2
0
/* Poor man's exceptions */
void pvm_exec_panic( const char *reason )
{
    // TO DO: longjmp?
    //panic("pvm_exec_throw: %s", reason );
    //syslog()
    printf("pvm_exec_panic: %s", reason );
    pvm_backtrace_current_thread();

    pvm_memcheck();
    hal_exit_kernel_thread();
}
Esempio n. 3
0
/* coverity[+kill] */
void pvm_exec_panic( const char *reason )
{
    // TO DO: longjmp?
    //panic("pvm_exec_throw: %s", reason );
    //syslog()
    printf("pvm_exec_panic: %s\n", reason );
    pvm_backtrace_current_thread();

    pvm_memcheck();
#if CONF_USE_E4C
    printf("pvm_exec_panic: throwing\n", reason );
    E4C_THROW( PvmException, reason );
#else // CONF_USE_E4C
    hal_exit_kernel_thread();
#endif // CONF_USE_E4C
}
Esempio n. 4
0
int main(int argc, char* argv[])
{
    printf("\n\n\n\n----- Phantom exec test v. 0.5\n\n");


    run_init_functions( INIT_LEVEL_PREPARE );
    run_init_functions( INIT_LEVEL_INIT ); // before video

    //drv_video_win32.mouse = mouse_callback;
    //video_drv = &drv_video_win32;
    //video_drv = &drv_video_x11;

    args(argc,argv);

    pvm_bulk_init( bulk_seek_f, bulk_read_f );

    pvm_video_init();
    video_drv->mouse = mouse_callback;

    drv_video_init_windows();
    init_main_event_q();
    init_new_windows();

    scr_mouse_set_cursor(drv_video_get_default_mouse_bmp());


    mem = malloc(size+1024*10);
    setDiffMem( mem, malloc(size+1024*10), size );

    hal_init( mem, size );
    //pvm_alloc_threaded_init(); // no threads yet - no lock

    run_init_functions( INIT_LEVEL_LATE );

#if 0
    videotest();
    //getchar();
    exit(0);
#endif

#if 0
    new_videotest();
    getchar();
    exit(0);
#endif


    char *dir = getenv("PHANTOM_HOME");
    char *rest = "plib/bin/classes";

    if( dir == NULL )
    {
        dir = "pcode";
        rest = "classes";
    }

    char fn[1024];
    snprintf( fn, 1024, "%s/%s", dir, rest );

    if( load_code( &bulk_code, &bulk_size, fn ) ) //"pcode/classes") )
    {
        printf("No bulk classes file '%s'\n", fn );
        exit(22);
    }
    bulk_read_pos = bulk_code;


    pvm_root_init();


    // TODO use stray catcher in pvm_test too
    //stray();

#if 0
//ui_loop( argc, argv, "test");
    printf("\nPhantom code finished\n" );
    //getchar();
    //{ char c; read( 0, &c, 1 ); }
	sleep(100);
#else
    dbg_init();
    kernel_debugger();
#endif

#if 0
    pvm_memcheck();

    printf("will run GC\n" );
    run_gc();

    printf("press enter\n" );
//    getchar();

    pvm_memcheck();

    save_mem(mem, size);
#endif
    return 0;
}