コード例 #1
0
void Compilation::generate_exception_handler_table() {
  // Generate an ExceptionHandlerTable from the exception handler
  // information accumulated during the compilation.
  ExceptionInfoList* info_list = exception_info_list();

  if (info_list->length() == 0) {
    return;
  }

  // allocate some arrays for use by the collection code.
  const int num_handlers = 5;
  GrowableArray<intptr_t>* bcis = new GrowableArray<intptr_t>(num_handlers);
  GrowableArray<intptr_t>* scope_depths = new GrowableArray<intptr_t>(num_handlers);
  GrowableArray<intptr_t>* pcos = new GrowableArray<intptr_t>(num_handlers);

  for (int i = 0; i < info_list->length(); i++) {
    ExceptionInfo* info = info_list->at(i);
    XHandlers* handlers = info->exception_handlers();

    // empty the arrays
    bcis->trunc_to(0);
    scope_depths->trunc_to(0);
    pcos->trunc_to(0);

    for (int i = 0; i < handlers->length(); i++) {
      XHandler* handler = handlers->handler_at(i);
      assert(handler->entry_pco() != -1, "must have been generated");

      int e = bcis->find(handler->handler_bci());
      if (e >= 0 && scope_depths->at(e) == handler->scope_count()) {
        // two different handlers are declared to dispatch to the same
        // catch bci.  During parsing we created edges for each
        // handler but we really only need one.  The exception handler
        // table will also get unhappy if we try to declare both since
        // it's nonsensical.  Just skip this handler.
        continue;
      }

      bcis->append(handler->handler_bci());
      if (handler->handler_bci() == -1) {
        // insert a wildcard handler at scope depth 0 so that the
        // exception lookup logic with find it.
        scope_depths->append(0);
      } else {
        scope_depths->append(handler->scope_count());
    }
      pcos->append(handler->entry_pco());

      // stop processing once we hit a catch any
      if (handler->is_catch_all()) {
        assert(i == handlers->length() - 1, "catch all must be last handler");
  }
    }
    exception_handler_table()->add_subtable(info->pco(), bcis, scope_depths, pcos);
  }
}
コード例 #2
0
void LIR_Assembler::emit_exception_entries(ExceptionInfoList* info_list) {
    for (int i = 0; i < info_list->length(); i++) {
        XHandlers* handlers = info_list->at(i)->exception_handlers();

        for (int j = 0; j < handlers->length(); j++) {
            XHandler* handler = handlers->handler_at(j);
            assert(handler->lir_op_id() != -1, "handler not processed by LinearScan");
            assert(handler->entry_code() == NULL ||
                   handler->entry_code()->instructions_list()->last()->code() == lir_branch ||
                   handler->entry_code()->instructions_list()->last()->code() == lir_delay_slot, "last operation must be branch");

            if (handler->entry_pco() == -1) {
                // entry code not emitted yet
                if (handler->entry_code() != NULL && handler->entry_code()->instructions_list()->length() > 1) {
                    handler->set_entry_pco(code_offset());
                    if (CommentedAssembly) {
                        _masm->block_comment("Exception adapter block");
                    }
                    emit_lir_list(handler->entry_code());
                } else {
                    handler->set_entry_pco(handler->entry_block()->exception_handler_pco());
                }

                assert(handler->entry_pco() != -1, "must be set now");
            }
        }
    }
}
コード例 #3
0
ファイル: events.cpp プロジェクト: BeyondSora/HelicopterGame
void pollForEvents (EventsArg *eventsArg) {
    Resources       *resources = eventsArg->resources_;
    XHandler        *xhandler  = eventsArg->xhandler_;
    pthread_mutex_t *mutex     = eventsArg->mutex_;

    Display *display = xhandler->display();
    Window   window  = xhandler->window();
    XSelectInput(display, window,
                 KeyPressMask |
                 KeyReleaseMask |
                 StructureNotifyMask);

    Helicopter &helicopter = resources->heli_;
    KeySym key;
    XWindowAttributes attr;

    XEvent event;
    while (true) {
        XNextEvent(display, &event);

        if (pthread_mutex_lock(mutex) == -1) {
            error("cannot lock mutex in control thread");
        }

        switch (event.type) {
            case ConfigureNotify:
                if (event.xconfigure.width  != attr.width ||
                        event.xconfigure.height != attr.height) {
                    XGetWindowAttributes(display, window, &attr);

                    attr::DrawableBase::ScaleX = (double)PLANE_W / (double)attr.width;
                    attr::DrawableBase::ScaleY = (double)PLANE_H / (double)attr.height;

                    std::cout << attr::DrawableBase::ScaleX << std::endl;
                    std::cout << attr::DrawableBase::ScaleY << std::endl;
                    std::cout << "w: " << attr.width << std::endl;
                    std::cout << "h: " << attr.height << std::endl;

                    xhandler->updateAttr(&attr);
                }

                break;

            case KeyPress:
                XLookupString(&event.xkey, NULL, 0, &key, NULL);
                switch (key) {
                    case XK_f:
                        if (xhandler->showCredit()) {
                            xhandler->setShowCredit(false);
                        }
                        else {
                            xhandler->setShowCredit(true);
                        }
                        break;

                    case XK_Up:
                        helicopter.up_ = true;
                        break;
                    case XK_Down:
                        helicopter.down_ = true;
                        break;
                    case XK_Left:
                        helicopter.left_ = true;
                        break;
                    case XK_Right:
                        helicopter.right_ = true;
                        break;

                    case XK_a:
                        Tower::incSpeed();
                        Missile::incSpeed();
                        break;
                    case XK_z:
                        Tower::decSpeed();
                        Missile::decSpeed();
                        break;

                    /*
                    case XK_q:  // slow down scroll speed
                        Tower::incDelay(1);
                        Missile::incDelay(1);
                        Bomb::incDelay(2);
                        break;
                    case XK_w:  // speed up scroll speed
                        Tower::decDelay(1);
                        Missile::decDelay(1);
                        Bomb::decDelay(2);
                        break;

                    */
                    case XK_d:
                        if (helicopter.right_) {
                            int x = helicopter.x() + helicopter.w() * 0.8;
                            int y = helicopter.y() + helicopter.h() * 0.8;
                            resources->bombs_.addBomb(x,
                                                      y,
                                                      Bomb::FORWARD);
                        }
                        else if (helicopter.left_) {
                            int x = helicopter.x() + helicopter.w() * 0.8;
                            int y = helicopter.y() + helicopter.h() * 0.8;
                            resources->bombs_.addBomb(x,
                                                      y,
                                                      Bomb::BACKWARD);
                        }
                        else {
                            int x = helicopter.x() + helicopter.w() * 0.8;
                            int y = helicopter.y() + helicopter.h() * 0.8;
                            resources->bombs_.addBomb(x,
                                                      y,
                                                      Bomb::NUL);
                        }

                        /*
                        if (helicopter.movement() == Helicopter::LEFT) {
                            resources->bombs_.push_back(
                                    Bomb(
                                        helicopter.x() + Helicopter::w(),
                                        helicopter.y() + Helicopter::h(),
                                        false));
                        }
                        else {
                            resources->bombs_.push_back(
                                    Bomb(
                                        helicopter.x() + Helicopter::w(),
                                        helicopter.y() + Helicopter::h(),
                                        true));
                        }
                        */
                        break;

                    default:
                        break;
                }
                break;

            case KeyRelease:
                XLookupString(&event.xkey, NULL, 0, &key, NULL);
                switch (key) {
                    case XK_Up:
                        helicopter.up_ = false;
                        helicopter.delayUp_ = 30;
                        break;
                    case XK_Down:
                        helicopter.down_ = false;
                        helicopter.delayDown_ = 30;
                        break;
                    case XK_Left:
                        helicopter.left_ = false;
                        helicopter.delayLeft_ = 30;
                        break;
                    case XK_Right:
                        helicopter.right_ = false;
                        helicopter.delayRight_ = 30;
                        break;
                    default:
                        break;
                }
                break;

            default:
                break;

        }

        if (pthread_mutex_unlock(mutex) == -1) {
            error("cannot unlock mutex in control thread");
        }
    }
}
コード例 #4
0
void LIR_Assembler::emit_exception_entries(ExceptionInfoList* info_list) {
  // tell these to the MacroAssembler 

  for (int i = 0; i < info_list->length(); i++) {
    XHandlers* handlers = info_list->at(i)->exception_handlers();

    for (int j = 0; j < handlers->length(); j++) {
      XHandler* handler = handlers->handler_at(j);
      assert(handler->lir_op_id() != -1, "handler not processed by LinearScan");
      assert(handler->entry_code() == NULL ||
handler->entry_code()->instructions_list()->last()->code()==lir_branch,"last operation must be branch");

      if (!handler->entry_lbl()) {
        // entry code not emitted yet
        if (handler->entry_code() != NULL && handler->entry_code()->instructions_list()->length() > 1) {
          handler->set_entry_lbl(new Label(_masm)); // bind label here
          _masm->block_comment("Exception adapter block");
          emit_lir_list(handler->entry_code());
        } else {
handler->set_entry_lbl(handler->entry_block()->label());
        }
      }
    }
  }
}