Beispiel #1
0
  void test_find_and_activate() {
    Thread* cur = Thread::current(state);
    Thread* thread = Thread::create(state);

    thread->wakeup(state);
    state->queue_thread(thread);

    bool ret = state->find_and_activate_thread();
    TS_ASSERT_EQUALS(true, ret);

    TS_ASSERT_EQUALS(Qfalse, thread->queued());
    TS_ASSERT_EQUALS(thread, Thread::current(state));

    TS_ASSERT_EQUALS(Qtrue, cur->queued());
  }
Beispiel #2
0
  Object* Thread::raise(STATE, GCToken gct, Exception* exc) {
    utilities::thread::SpinLock::LockGuard lg(init_lock_);
    Thread* self = this;
    OnStack<2> os(state, self, exc);

    VM* vm = self->vm_;
    if(!vm) {
      return cNil;
    }

    vm->register_raise(state, exc);

    vm->wakeup(state, gct);
    return exc;
  }
Beispiel #3
0
int main(int argc, const char* argv[])
{
  if (argc > 2)
  {
    // TODO(bob): Show usage, etc.
    std::cout << "magpie [script]" << std::endl;
    return 1;
  }

  VM vm;

  if (argc == 1) return repl(vm);

  bool success = vm.runProgram(String::create(argv[1]));
  return success ? 0 : 1;
}
Beispiel #4
0
  void test_symbol() {
    mar->sstream.str(std::string("x\n4\nblah\n"));
    Object* obj = mar->unmarshal();

    TS_ASSERT(obj->symbol_p());
    TS_ASSERT_EQUALS(obj, state->symbol("blah"));
  }
Vector<BasicBlockRange> ControlFlowProfiler::getBasicBlocksForSourceID(intptr_t sourceID, VM& vm) const 
{
    Vector<BasicBlockRange> result(0);
    auto bucketFindResult = m_sourceIDBuckets.find(sourceID);
    if (bucketFindResult == m_sourceIDBuckets.end())
        return result;

    const BlockLocationCache& cache = bucketFindResult->value;
    for (const BasicBlockLocation* block : cache.values()) {
        bool hasExecuted = block->hasExecuted();
        const Vector<BasicBlockLocation::Gap>& blockRanges = block->getExecutedRanges();
        for (BasicBlockLocation::Gap gap : blockRanges) {
            BasicBlockRange range;
            range.m_hasExecuted = hasExecuted;
            range.m_startOffset = gap.first;
            range.m_endOffset = gap.second;
            result.append(range);
        }
    }

    const Vector<std::tuple<bool, unsigned, unsigned>>& unexecutedFunctionRanges = vm.functionHasExecutedCache()->getFunctionRanges(sourceID);
    for (const auto& functionRange : unexecutedFunctionRanges) {
        BasicBlockRange range;
        range.m_hasExecuted = std::get<0>(functionRange);
        range.m_startOffset = static_cast<int>(std::get<1>(functionRange));
        range.m_endOffset = static_cast<int>(std::get<2>(functionRange));
        result.append(range);
    }

    return result;
}
Beispiel #6
0
void VirshGui::toggleVMStatus()
{
    string vmname = ui->vmnameLabel->text().toStdString();
    VM vm = vmlist[vmname];
    try {
        if (vm.getStatus() == VMStatus::shutoff) {
            vm.start();
        } else if (vm.getStatus() == VMStatus::running) {
            vm.destroy();
        }
    } catch (ssh::SshException e) {
        handleDisconnect();
    }

    refreshVmList();
}
Beispiel #7
0
  void test_activate_thread_sets_as_current() {
    Thread* thread = Thread::create(state);

    state->activate_thread(thread);

    TS_ASSERT_EQUALS(thread, Thread::current(state));
  }
Beispiel #8
0
  void test_mono_inline_cache_locate_succeeded() {
    Message msg(state);
    Symbol* sym = state->symbol("blah");
    SendSite* ss = SendSite::create(state, sym);
    Class* meta = G(object)->metaclass(state);
    CompiledMethod* cm = CompiledMethod::create(state);
    CompiledMethod* g_cm = CompiledMethod::create(state);

    TS_ASSERT_EQUALS(MonomorphicInlineCacheResolver::resolve, ss->resolver);

    ss->recv_class(state, meta);
    ss->module(state, G(object));
    ss->method(state, cm);
    ss->hits = 1U;

    msg.name = sym;
    msg.lookup_from = meta;
    msg.recv = G(object);
    msg.send_site = ss;
    msg.module = meta;
    msg.method = cm;

    state->global_cache->retain(state, meta, sym, meta, g_cm, false);

    TS_ASSERT(ss->locate(state, msg));
    TS_ASSERT_EQUALS(2U, ss->hits);
    TS_ASSERT_EQUALS(0U, ss->misses);
    TS_ASSERT_EQUALS(cm, msg.method);
    TS_ASSERT_EQUALS(G(object), msg.module);
  }
Beispiel #9
0
void Watchdog::setTimeLimit(VM& vm, std::chrono::microseconds limit,
    ShouldTerminateCallback callback, void* data1, void* data2)
{
    bool wasEnabled = isEnabled();

    if (!m_isStopped)
        stopCountdown();

    m_didFire = false; // Reset the watchdog.

    m_limit = limit;
    m_callback = callback;
    m_callbackData1 = data1;
    m_callbackData2 = data2;

    // If this is the first time that timeout is being enabled, then any
    // previously JIT compiled code will not have the needed polling checks.
    // Hence, we need to flush all the pre-existing compiled code.
    //
    // However, if the timeout is already enabled, and we're just changing the
    // timeout value, then any existing JITted code will have the appropriate
    // polling checks. Hence, there is no need to re-do this flushing.
    if (!wasEnabled) {
        // And if we've previously compiled any functions, we need to revert
        // them because they don't have the needed polling checks yet.
        vm.releaseExecutableMemory();
    }

    startCountdownIfNeeded();
}
Beispiel #10
0
void AddConsole(VM &vm)
{
    vm.setConsole(&con);
    vm.sios.addSIO(&con);

    vm.sios.addSIO(&sio1);
    vm.sios.addSIO(&sio2);
    vm.sios.addSIO(&sio3);
    vm.sios.addSIO(&sio4);
    vm.sios.addSIO(&sio5);
    vm.sios.addSIO(&sio6);
    vm.sios.addSIO(&sio7);
    vm.sios.addSIO(&sio8);
    vm.sios.addSIO(&mouse);

    server.addClient(&sio1);
    server.addClient(&sio2);
    server.addClient(&sio3);
    server.addClient(&sio4);
    server.addClient(&sio5);
    server.addClient(&sio6);
    server.addClient(&sio7);
    server.addClient(&sio8);

    server.start();
}
Beispiel #11
0
  Thread* Thread::wakeup(STATE, GCToken gct) {
    init_lock_.lock();
    Thread* self = this;
    OnStack<1> os(state, self);

    VM* vm = self->vm_;
    if(alive() == cFalse || !vm) {
      self->init_lock_.unlock();
      return force_as<Thread>(Primitives::failure());
    }

    vm->wakeup(state, gct);

    self->init_lock_.unlock();
    return self;
  }
Beispiel #12
0
  gc<ClassObject> AtomObject::getClass(VM& vm) const
  {
    switch (atom_)
    {
      case ATOM_FALSE:
      case ATOM_TRUE:
        return vm.getClass(CLASS_BOOL);
      case ATOM_NOTHING: return vm.getClass(CLASS_NOTHING);
      case ATOM_DONE: return vm.getClass(CLASS_DONE);
      case ATOM_NO_METHOD:
        ASSERT(false, "NO_METHOD shouldn't be in AtomObject.");
    }

    ASSERT(false, "Unexpected atom value.");
    return NULL;
  }
Beispiel #13
0
string CViewRenderer::renderFile(const IRenderingContext * context, const string & sourceFile, CDT & data, bool ret) throw (CException)
{
    boost::filesystem::path sourcePath(sourceFile);
    if (!boost::filesystem::exists(sourcePath)) {
        throw CException("View file \"" + sourceFile + "\" does not exist.");
    }
    string viewFile = getViewFile(sourceFile);
    boost::filesystem::path viewPath(viewFile);
    if (!boost::filesystem::exists(viewPath) || boost::filesystem::last_write_time(sourcePath) > boost::filesystem::last_write_time(viewPath)) {
        if (generateViewFile(sourceFile, viewFile)) {
            chmod(viewFile.c_str(), filePermission);
        } else {
            throw CException("Can't generate view file \"" + viewFile + "\" from source file \"" + sourceFile + "\".");
        }
    }

    if (context != 0) {
    	return context->renderInternal(viewFile, data, ret);
    }

	stringstream os;
	StreamOutputCollector outputCollector(os);
    TDynamicTemplateCacheMap::const_iterator found = _templateCache.find(viewFile);

	VMLoader * oLoader = 0;
	if (found == _templateCache.end()) {
		oLoader = new VMFileLoader(viewFile.c_str());
		_templateCache[viewFile.c_str()] = boost::shared_ptr<VMLoader>(oLoader);
	} else {
		oLoader = found->second.get();
	}

	PROFILE_BEGIN("CViewRenderer::rendering template bytecode of \"" + viewFile + "\"")
	UINT_32 iIP = 0;
	VM * vm = Cws::app()->getTemplateEngine()->getVM();
	const VMMemoryCore * pVMMemoryCore = oLoader->GetCore();
	vm->Init(pVMMemoryCore, &outputCollector, 0);
	vm->Run(pVMMemoryCore, &outputCollector, iIP, data, 0);
	PROFILE_END()

	if (ret) {
		return os.str();
	} else {
		Cws::app()->getOutputStack().top()->echo(os.str());
		return "";
	}
}
Beispiel #14
0
int main(int argc, const char **argv)
{
	// Usage information.
	if (argc < 2)
	{
		cout<<"Usage: " <<argv[0] <<" <file>\n";
		return 0;
	}
	char *buffer;
	istream *f;
	// If it's -, read from stdin.
	if (strcmp(argv[1], "-") == 0)
	{
		std::stringstream *stream = new std::stringstream();
		*stream << cin.rdbuf();
		f = stream;
	}
	// Otherwise, just open the file.
	else
	{
		f = new ifstream(argv[1]);
	}
	if (f->fail())
	{
		cout<<"Input error" <<endl;
		delete f;
		return 1;
	}
	// Determine the size.
	f->seekg(0, ios::end);
	int l = f->tellg();
	f->seekg(0, ios::beg);
	// Allocate a buffer.
	buffer = new char[l];
	// Read the data.
	f->read(buffer, l);
	delete f;
	// Create a VM.
	VM vm;
	// Create a parser and let it parse
	// the file for us.
	Parser p(&vm);
	p.parseBlob(buffer, l);
	// And start the main loop!
	vm.run();
	return 0;
}
Beispiel #15
0
  Object* Thread::raise(STATE, GCToken gct, Exception* exc) {
    init_lock_.lock();
    Thread* self = this;
    OnStack<2> os(state, self, exc);

    VM* vm = self->vm_;
    if(!vm) {
      self->init_lock_.unlock();
      return cNil;
    }

    vm->register_raise(state, exc);

    vm->wakeup(state, gct);
    self->init_lock_.unlock();
    return exc;
  }
Beispiel #16
0
 STARTDECL(read_file) (VM &vm, Value &file) {
     string buf;
     auto l = LoadFile(file.sval()->strv(), &buf);
     file.DECRT(vm);
     if (l < 0) return Value();
     auto s = vm.NewString(buf);
     return Value(s);
 }
Beispiel #17
0
  void test_hits_prim() {
    Symbol* sym = state->symbol("blah");
    SendSite* ss = SendSite::create(state, sym);

    ss->hits = 10;

    TS_ASSERT_EQUALS(Fixnum::from(10), (Fixnum*)ss->hits_prim(state));
  }
Beispiel #18
0
  void test_queue_already_queued_thread_is_noop() {
    Thread* thread = Thread::create(state);
    thread->queued(state, Qtrue);

    state->queue_thread(thread);

    TS_ASSERT_EQUALS(Qtrue, thread->queued());
  }
Beispiel #19
0
  void test_dequeue_thread_sets_queued_false() {
    Thread* thread = Thread::create(state);
    thread->queued(state, Qtrue);

    state->dequeue_thread(thread);
    
    TS_ASSERT_EQUALS(Qfalse, thread->queued());
  }
Beispiel #20
0
  void test_activate_thread_queues_previous_current() {
    Thread* cur = Thread::current(state);
    Thread* thread = Thread::create(state);

    state->activate_thread(thread);

    TS_ASSERT_EQUALS(Qtrue, cur->queued());
  }
Beispiel #21
0
  void Module::addImports(VM& vm, ErrorReporter& reporter)
  {
    // Implicitly import core (unless we are core).
    if (*name_ != "core")
    {
      vm.importModule(reporter, this, NULL, String::create("core"));
    }

    // Load all of the imports.
    for (int i = 0; i < ast_->body()->expressions().count(); i++)
    {
      ImportExpr* import = ast_->body()->expressions()[i]->asImportExpr();
      if (import == NULL) continue;

      vm.importModule(reporter, this, import->pos(), import->name());
    }
  }
Beispiel #22
0
    void test_access_variable() {
        AccessVariable* av = AccessVariable::allocate(state);
        Task* task = Task::create(state, 10);
        Message msg(state);
        msg.recv = G(object);
        msg.method = av;
        msg.use_from_task(task, 0);
        av->name(state, state->symbol("@blah"));

        G(object)->set_ivar(state, av->name(), state->symbol("Sweet"));

        TS_ASSERT(!av->execute(state, task, msg));
        Object* ret = task->pop();
        TS_ASSERT(try_as<Symbol>(ret));

        TS_ASSERT_EQUALS(std::string("Sweet"), as<Symbol>(ret)->c_str(state));
    }
Beispiel #23
0
void JSCallBase::link(VM& vm, LinkBuffer& linkBuffer)
{
    linkBuffer.link(
        m_slowCall, FunctionPtr(vm.getCTIStub(linkCallThunkGenerator).code().executableAddress()));

    m_callLinkInfo->setCallLocations(linkBuffer.locationOfNearCall(m_slowCall),
        linkBuffer.locationOf(m_targetToCheck), linkBuffer.locationOfNearCall(m_fastCall));
}
Beispiel #24
0
int main (int argc, char *argv[])
{
  try {
    get_opt& _ = get_opt::instance();

    _.parse_cmdline(argc, argv);

    VM vm;
    vm.load_image (_.inp_name);
    vm.interprete ();
  }

  catch (exception& e) {
    cerr << e.what() << endl;
    return EXIT_FAILURE;
  }
}
Beispiel #25
0
  void test_sendsite() {
    mar->sstream.str(std::string("S\n4\nblah\n"));
    Object* obj = mar->unmarshal();

    TS_ASSERT(kind_of<SendSite>(obj));

    TS_ASSERT_EQUALS(as<SendSite>(obj)->name(), state->symbol("blah"));
  }
Beispiel #26
0
void VirshGui::vncDisplay()
{
    string vmname = ui->vmnameLabel->text().toStdString();
    VM vm = vmlist[vmname];

    int vncport = 0;
    try {
        vncport = stoi(vm.getVNCPort());
    } catch (ssh::SshException e) {
        handleDisconnect();
    }

    vncclientwidget2cls *vnc = new vncclientwidget2cls();
    vnc->connectVNCTCP(QString::fromStdString(ssh->getHost()), vncport);
    vnc->setWindowTitle(QString::fromStdString(vm.getName()));
    vnc->showNormal();
}
Beispiel #27
0
bool checkSyntax(VM& vm, const SourceCode& source, ParserError& error)
{
    JSLockHolder lock(vm);
    RELEASE_ASSERT(vm.atomicStringTable() == wtfThreadData().atomicStringTable());
    return !!parse<ProgramNode>(
        &vm, source, Identifier(), JSParserBuiltinMode::NotBuiltin,
        JSParserStrictMode::NotStrict, SourceParseMode::ProgramMode, SuperBinding::NotNeeded, error);
}
  void* InternalThread::run(void* ptr) {
    InternalThread* thread = reinterpret_cast<InternalThread*>(ptr);
    VM* vm = thread->vm();

    SharedState& shared = vm->shared;
    State state_obj(vm), *state = &state_obj;

    vm->set_current_thread();
    vm->set_run_state(ManagedThread::eIndependent);

    RUBINIUS_THREAD_START(
        const_cast<RBX_DTRACE_CHAR_P>(vm->name().c_str()), vm->thread_id(), 1);

    NativeMethod::init_thread(state);

    thread->thread_running_ = true;

    thread->run(state);

    thread->thread_running_ = false;

    NativeMethod::cleanup_thread(state);

    RUBINIUS_THREAD_STOP(
        const_cast<RBX_DTRACE_CHAR_P>(vm->name().c_str()), vm->thread_id(), 1);

    shared.gc_independent();

    return 0;
  }
void JSFloat64Array::finishCreation(VM& vm)
{
    Base::finishCreation(vm);
    TypedArrayDescriptor descriptor(&JSFloat64Array::s_info, OBJECT_OFFSETOF(JSFloat64Array, m_storage), OBJECT_OFFSETOF(JSFloat64Array, m_storageLength));
    vm.registerTypedArrayDescriptor(impl(), descriptor);
    m_storage = impl()->data();
    m_storageLength = impl()->length();
    ASSERT(inherits(&s_info));
}
Beispiel #30
0
as_object::as_object(VM& vm)
    :
    GcResource(vm.getRoot().gc()),
    _displayObject(nullptr),
    _array(false),
    _vm(vm),
    _members(*this)
{
}