예제 #1
0
  /**
   * Runs rbx from the filesystem. Searches for the Rubinius runtime files
   * according to the algorithm in find_runtime().
   */
  void Environment::run_from_filesystem() {
    int i = 0;
    state->vm()->set_root_stack(reinterpret_cast<uintptr_t>(&i),
                                VM::cStackDepthMax);

    std::string runtime = system_prefix() + RBX_RUNTIME_PATH;

    load_platform_conf(runtime);
    boot_vm();
    start_finalizer();

    load_argv(argc_, argv_);

    start_signals();
    state->vm()->initialize_config();

    load_tool();

    G(rubinius)->set_const(state, "Signature", Integer::from(state, signature_));

    if(LANGUAGE_20_ENABLED(state)) {
      runtime += "/20";
    } else if(LANGUAGE_19_ENABLED(state)) {
      runtime += "/19";
    } else {
      runtime += "/18";
    }
    G(rubinius)->set_const(state, "RUNTIME_PATH", String::create(state,
                           runtime.c_str(), runtime.size()));

    load_kernel(runtime);
    shared->finalizer_handler()->start_thread(state);

    run_file(runtime + "/loader.rbc");

    state->vm()->thread_state()->clear();

    Object* loader = G(rubinius)->get_const(state, state->symbol("Loader"));
    if(loader->nil_p()) {
      rubinius::bug("Unable to find loader");
    }

    OnStack<1> os(state, loader);

    Object* inst = loader->send(state, 0, state->symbol("new"));
    if(inst) {
      OnStack<1> os2(state, inst);

      inst->send(state, 0, state->symbol("main"));
    } else {
      rubinius::bug("Unable to instantiate loader");
    }
  }
예제 #2
0
  void Environment::boot() {
    state->shared().start_diagnostics(state);

    std::string codedb_path = system_prefix() + RBX_CODEDB_PATH;

    {
      timer::StopWatch<timer::microseconds> timer(
          state->shared().boot_metrics()->platform_us);

      load_platform_conf(codedb_path);
    }

    {
      timer::StopWatch<timer::microseconds> timer(
          state->shared().boot_metrics()->memory_us);

      shared->om = new Memory(state->vm(), *shared);
    }

    shared->set_initialized();

    state->vm()->managed_phase(state);

    {
      timer::StopWatch<timer::microseconds> timer(
          state->shared().boot_metrics()->fields_us);

      TypeInfo::auto_learn_fields(state);
    }

    {
      timer::StopWatch<timer::microseconds> timer(
          state->shared().boot_metrics()->ontology_us);

      state->vm()->bootstrap_ontology(state);
    }

    start_finalizer(state);

    load_argv(argc_, argv_);

    // Start the main Ruby thread.
    Thread* main = 0;
    OnStack<1> os(state, main);

    {
      timer::StopWatch<timer::microseconds> timer(
          state->shared().boot_metrics()->main_thread_us);

      main = Thread::create(state, state->vm(), Thread::main_thread);
      main->start_thread(state, Thread::run);
    }

    VM* vm = SignalThread::new_vm(state);
    vm->set_stack_bounds(state->vm()->stack_size());

    State main_state(vm);
    state->shared().start_signals(&main_state);

    state->shared().set_running();
  }