Object c_AwaitAllWaitHandle::ti_frommap(const Variant& dependencies) {
  if (LIKELY(dependencies.isObject())) {
    auto obj = dependencies.getObjectData();
    if (LIKELY(obj->isCollection() && isMapCollection(obj->collectionType()))) {
      assert(obj->instanceof(c_Map::classof()) ||
             obj->instanceof(c_ImmMap::classof()));
      return FromMap(static_cast<BaseMap*>(obj));
    }
  }
  failMap();
}
//virtual 
RStorage 
AbstractFilterWriter::getStorage()
{
  if (instanceof(_out, Storage) == true)
    return RStorage(_out);
  else if (instanceof(_out, FilterWriter) == true) {
    return RFilterWriter(_out)->getStorage();
  }
  THROW1(IOException, "Unknown Writer type for getOut" + ((RObject)_out)->toString());
  return Nil;
}
//virtual 
RStorage 
AbstractFilterReader::getStorage()
{
  if (instanceof(_in, Storage) == true)
    return RStorage(_in);
  else if (instanceof(_in, FilterReader) == true)
    return RFilterReader(_in)->getStorage();
  // Interface Writer to RefHolder<Object>

  THROW1(IOException, "Unknown Reader type for getIn" + ((RObject)_in)->toString());
  return Nil;
}
Object c_AwaitAllWaitHandle::ti_fromvector(const Variant& dependencies) {
  if (LIKELY(dependencies.isObject())) {
    auto obj = dependencies.getObjectData();
    if (LIKELY(obj->isCollection() &&
               isVectorCollection(obj->collectionType()))) {
      assert(obj->instanceof(c_Vector::classof()) ||
             obj->instanceof(c_ImmVector::classof()));
      return FromVector(static_cast<BaseVector*>(obj));
    }
  }
  failVector();
}
Exemple #5
0
UnwindAction checkHandlers(const EHEnt* eh,
                           const ActRec* const fp,
                           PC& pc,
                           Fault& fault) {
  auto const func = fp->m_func;
  FTRACE(1, "checkHandlers: func {} ({})\n",
         func->fullName()->data(),
         func->unit()->filepath()->data());

  // Always blindly propagate on fatal exception since those are
  // unrecoverable anyway.
  if (fault.m_faultType == Fault::Type::CppException) {
    return UnwindAction::Propagate;
  }

  for (int i = 0;; ++i) {
    // Skip the initial m_handledCount - 1 handlers that were
    // considered before.
    if (fault.m_handledCount <= i) {
      fault.m_handledCount++;
      switch (eh->m_type) {
      case EHEnt::Type::Fault:
        FTRACE(1, "checkHandlers: entering fault at {}: save {}\n",
               eh->m_fault,
               func->unit()->offsetOf(pc));
        pc = func->unit()->entry() + eh->m_fault;
        DEBUGGER_ATTACHED_ONLY(phpDebuggerExceptionHandlerHook());
        return UnwindAction::ResumeVM;
      case EHEnt::Type::Catch:
        // Note: we skip catch clauses if we have a pending C++ exception
        // as part of our efforts to avoid running more PHP code in the
        // face of such exceptions.
        if (fault.m_faultType == Fault::Type::UserException &&
            ThreadInfo::s_threadInfo->m_pendingException == nullptr) {
          auto const obj = fault.m_userException;
          for (auto& idOff : eh->m_catches) {
            FTRACE(1, "checkHandlers: catch candidate {}\n", idOff.second);
            auto handler = func->unit()->at(idOff.second);
            auto const cls = Unit::lookupClass(
              func->unit()->lookupNamedEntityId(idOff.first)
            );
            if (!cls || !obj->instanceof(cls)) continue;

            FTRACE(1, "checkHandlers: entering catch at {}\n", idOff.second);
            pc = handler;
            DEBUGGER_ATTACHED_ONLY(phpDebuggerExceptionHandlerHook());
            return UnwindAction::ResumeVM;
          }
        }
        break;
      }
    }
    if (eh->m_parentIndex != -1) {
      eh = &func->ehtab()[eh->m_parentIndex];
    } else {
      break;
    }
  }
  return UnwindAction::Propagate;
}
Exemple #6
0
Object c_GenMapWaitHandle::ti_create(const Variant& dependencies) {
  if (UNLIKELY(!dependencies.isObject() ||
      dependencies.getObjectData()->getCollectionType() !=
        Collection::MapType)) {
    Object e(SystemLib::AllocInvalidArgumentExceptionObject(
      "Expected dependencies to be an instance of Map"));
    throw e;
  }
  assert(dependencies.getObjectData()->instanceof(c_Map::classof()));
  auto deps = p_Map::attach(c_Map::Clone(dependencies.getObjectData()));
  for (ssize_t iter_pos = deps->iter_begin();
       deps->iter_valid(iter_pos);
       iter_pos = deps->iter_next(iter_pos)) {

    auto* current = tvAssertCell(deps->iter_value(iter_pos));
    if (UNLIKELY(!c_WaitHandle::fromCell(current))) {
      Object e(SystemLib::AllocInvalidArgumentExceptionObject(
        "Expected dependencies to be a map of WaitHandle instances"));
      throw e;
    }
  }

  Object exception;
  for (ssize_t iter_pos = deps->iter_begin();
       deps->iter_valid(iter_pos);
       iter_pos = deps->iter_next(iter_pos)) {

    auto* current = tvAssertCell(deps->iter_value(iter_pos));
    assert(current->m_type == KindOfObject);
    assert(current->m_data.pobj->instanceof(c_WaitHandle::classof()));
    auto child = static_cast<c_WaitHandle*>(current->m_data.pobj);

    if (child->isSucceeded()) {
      auto k = deps->iter_key(iter_pos);
      deps->set(k.asCell(), &child->getResult());
    } else if (child->isFailed()) {
      putException(exception, child->getException());
    } else {
      assert(child->instanceof(c_WaitableWaitHandle::classof()));
      auto child_wh = static_cast<c_WaitableWaitHandle*>(child);

      p_GenMapWaitHandle my_wh = NEWOBJ(c_GenMapWaitHandle)();
      my_wh->initialize(exception, deps.get(), iter_pos, child_wh);

      AsioSession* session = AsioSession::Get();
      if (UNLIKELY(session->hasOnGenMapCreateCallback())) {
        session->onGenMapCreate(my_wh.get(), dependencies);
      }

      return my_wh;
    }
  }

  if (exception.isNull()) {
    return Object::attach(c_StaticWaitHandle::CreateSucceeded(
      make_tv<KindOfObject>(deps.detach())));
  } else {
    return Object::attach(c_StaticWaitHandle::CreateFailed(exception.detach()));
  }
}
//virtual 
int 
LineNumberReader::read() 
{
  SYNCTHIS();
  if (_eof == 2)
    THROW0(EOFException);
  if (_eof == 1)
  {
    _eof = 2;
    return -1;
  }
  int byte_read = _read();
  if (byte_read == -1)
     return byte_read;
  if (byte_read == '\n') { 
    ++_lineNumber;
    _xPos = 0;
  } else if (byte_read == '\r') {
    int extra_byte_read = _read();
    if ((extra_byte_read != '\n') && (extra_byte_read != -1)) {
      if (instanceof(_in, PushbackReader)) {
        ((RPushbackReader)_in)->unread(extra_byte_read);
        --_xPos;
      } else {
        return extra_byte_read;
      }
    }
    byte_read = '\n';
    if (extra_byte_read  == -1)
      return extra_byte_read;
    ++_lineNumber;
  }
  return byte_read;
}
Exemple #8
0
std::shared_ptr<Object> read_meta(std::istream &in) {
  auto meta = read(in, true, Object::nil, true);
  if (typeid(*meta) == typeid(Symbol) || typeid(*meta) == typeid(String)) {
    meta = std::make_shared<Map>(std::list<std::shared_ptr<Object>>{Keyword::create("tag"), meta});
  } else if (typeid(*meta) == typeid(Keyword)) {
    meta = std::make_shared<Map>(std::list<std::shared_ptr<Object>>{meta, Object::T});
  } else if (typeid(*meta) != typeid(Map)) { // TODO: map interface
    throw "Metadata must be Symbol,Keyword,String or Map";
  }
  auto o = read(in, true, Object::nil, true);
  if (o->instanceof(typeid(Meta))) {
    // TODO: line number support
    // TODO: refs
    // merge metadata
    auto ometa = std::dynamic_pointer_cast<Meta>(o)->meta();
    for (auto it = std::dynamic_pointer_cast<Map>(meta)->begin(); 
        it != std::dynamic_pointer_cast<Map>(meta)->end();
        ++it) {
      auto r = *it;
      if (ometa == nullptr) {
        ometa = std::make_shared<Map>(std::list<std::shared_ptr<Object> >{ std::get<0>(r), std::get<1>(r) });
      } else {
        ometa = std::dynamic_pointer_cast<Map>(ometa)->assoc(std::get<0>(r), std::get<1>(r));
      }
    }
    return std::dynamic_pointer_cast<Meta>(o)->withMeta(ometa);
  }
  throw "Metadata can only be applied to IMetas";
}
Exemple #9
0
bool instanceof_anyt::operator ()(const typet &type) const
{
  if (types.empty()) return true;
  return types.end()
      != std::find_if(types.begin(), types.end(),
          [this, &type](const typet &rhs)
          { return instanceof(st, type, rhs);});
}
Exemple #10
0
Variant c_WaitHandle::t_join() {
  if (!isFinished()) {
    // run the full blown machinery
    assert(instanceof(c_WaitableWaitHandle::classof()));
    static_cast<c_WaitableWaitHandle*>(this)->join();
  }
  return result();
}
Exemple #11
0
// throws if cross-context cycle found
void c_WaitHandle::t_import() {
  if (isFinished()) {
    return;
  }

  assert(instanceof(c_WaitableWaitHandle::classof()));
  auto const ctx_idx = AsioSession::Get()->getCurrentContextIdx();
  asio::enter_context(static_cast<c_WaitableWaitHandle*>(this), ctx_idx);
}
Exemple #12
0
bool instanceof(const symbol_tablet &st, const typet &lhs, const typet &rhs)
{
  const namespacet ns(st);
  const typet &resolved_lhs=ns.follow(lhs);
  const typet &resolved_rhs=ns.follow(rhs);
  if (ID_class != resolved_lhs.id() || ID_class != resolved_rhs.id())
    return type_eq(resolved_lhs, resolved_rhs, ns);
  return instanceof(resolved_lhs, resolved_rhs, ns);
}
//virtual 
RReader 
JoinedReader::getStorageReader()
{
  if (_curPos == -1)
    return Nil;
  
  if (instanceof(_ins[_curPos], FilterReader) == true)
    return RFilterReader(_ins[_curPos])->getStorageReader();
  return _ins[_curPos];
}
Exemple #14
0
String c_WaitHandle::t_getname() {
  if (isSucceeded()) {
    return s_result;
  } else if (isFailed()) {
    return s_exception;
  }

  assert(instanceof(c_WaitableWaitHandle::classof()));
  return static_cast<c_WaitableWaitHandle*>(this)->getName();
}
Object c_GenVectorWaitHandle::ti_create(const Variant& dependencies) {
  if (UNLIKELY(!dependencies.isObject() ||
      dependencies.getObjectData()->getCollectionType() !=
        Collection::VectorType)) {
    Object e(SystemLib::AllocInvalidArgumentExceptionObject(
      "Expected dependencies to be an instance of Vector"));
    throw e;
  }
  assert(dependencies.getObjectData()->instanceof(c_Vector::classof()));
  auto deps = SmartObject<c_Vector>::attach(
    c_Vector::Clone(dependencies.getObjectData()));
  for (int64_t iter_pos = 0; iter_pos < deps->size(); ++iter_pos) {
    Cell* current = deps->at(iter_pos);

    if (UNLIKELY(!c_WaitHandle::fromCell(current))) {
      Object e(SystemLib::AllocInvalidArgumentExceptionObject(
        "Expected dependencies to be a vector of WaitHandle instances"));
      throw e;
    }
  }

  Object exception;
  for (int64_t iter_pos = 0; iter_pos < deps->size(); ++iter_pos) {

    auto current = tvAssertCell(deps->at(iter_pos));
    assert(current->m_type == KindOfObject);
    assert(current->m_data.pobj->instanceof(c_WaitHandle::classof()));
    auto child = static_cast<c_WaitHandle*>(current->m_data.pobj);

    if (child->isSucceeded()) {
      auto result = child->getResult();
      deps->set(iter_pos, &result);
    } else if (child->isFailed()) {
      putException(exception, child->getException());
    } else {
      assert(child->instanceof(c_WaitableWaitHandle::classof()));
      auto child_wh = static_cast<c_WaitableWaitHandle*>(child);

      SmartObject<c_GenVectorWaitHandle> my_wh(newobj<c_GenVectorWaitHandle>());
      my_wh->initialize(exception, deps.get(), iter_pos, child_wh);
      AsioSession* session = AsioSession::Get();
      if (UNLIKELY(session->hasOnGenVectorCreateCallback())) {
        session->onGenVectorCreate(my_wh.get(), dependencies);
      }
      return my_wh;
    }
  }

  if (exception.isNull()) {
    return Object::attach(c_StaticWaitHandle::CreateSucceeded(
      make_tv<KindOfObject>(deps.detach())));
  } else {
    return Object::attach(c_StaticWaitHandle::CreateFailed(exception.detach()));
  }
}
Exemple #16
0
static void Str_split(struct v7_c_func_arg *cfa) {
  const struct v7_string *s = &cfa->this_obj->v.str;
  const char *p1, *p2, *e = s->buf + s->len;
  int limit = cfa->num_args == 2 && cfa->args[1]->type == V7_TYPE_NUM ?
  cfa->args[1]->v.num : -1;
  int num_elems = 0;

  v7_set_class(cfa->result, V7_CLASS_ARRAY);
  if (cfa->num_args == 0) {
    v7_append(cfa->v7, cfa->result,
              v7_mkv(cfa->v7, V7_TYPE_STR, s->buf, s->len, 1));
  } else if (cfa->args[0]->type == V7_TYPE_STR) {
    const struct v7_string *sep = &cfa->args[0]->v.str;
    if (sep->len == 0) {
      // Separator is empty. Split string by characters.
      for (p1 = s->buf; p1 < e; p1++) {
        if (limit >= 0 && limit <= num_elems) return;
        v7_append(cfa->v7, cfa->result, v7_mkv(cfa->v7, V7_TYPE_STR, p1, 1, 1));
        num_elems++;
      }
    } else {
      p1 = s->buf;
      while ((p2 = memstr(p1, e - p1, sep->buf, sep->len)) != NULL) {
        if (limit >= 0 && limit <= num_elems) return;
        v7_append(cfa->v7, cfa->result,
                  v7_mkv(cfa->v7, V7_TYPE_STR, p1, p2 - p1, 1));
        p1 = p2 + sep->len;
        num_elems++;
      }
      if (limit < 0 || limit > num_elems) {
        v7_append(cfa->v7, cfa->result,
                  v7_mkv(cfa->v7, V7_TYPE_STR, p1, e - p1, 1));
      }
    }
  } else if (instanceof(cfa->args[0], &s_constructors[V7_CLASS_REGEXP])) {
    char regex[200];
    struct slre_cap caps[20];
    int n = 0;

    snprintf(regex, sizeof(regex), "(%s)", cfa->args[0]->v.regex);
    p1 = s->buf;
    while ((n = slre_match(regex, p1, e - p1, caps, ARRAY_SIZE(caps), 0)) > 0) {
      if (limit >= 0 && limit <= num_elems) return;
      v7_append(cfa->v7, cfa->result,
                v7_mkv(cfa->v7, V7_TYPE_STR, p1, caps[0].ptr - p1, 1));
      p1 += n;
      num_elems++;
    }
    if (limit < 0 || limit > num_elems) {
      v7_append(cfa->v7, cfa->result,
                v7_mkv(cfa->v7, V7_TYPE_STR, p1, e - p1, 1));
    }
  }
}
Exemple #17
0
// throws if cross-context cycle found
void c_WaitHandle::t_import() {
  if (isFinished()) {
    return;
  }

  context_idx_t ctx_idx = AsioSession::Get()->getCurrentContextIdx();
  if (ctx_idx) {
    assert(instanceof(c_WaitableWaitHandle::classof()));
    static_cast<c_WaitableWaitHandle*>(this)->enterContext(ctx_idx);
  }
}
Exemple #18
0
// An Await opcode is used in the codegen for an async function to suspend
// execution until the given wait handle is finished. In eager execution,
// the state is suspended into a new AsyncFunctionWaitHandle object so that
// the execution can continue later. We have just completed an Await, so
// the new AsyncFunctionWaitHandle is now available, and it can predict
// where execution will resume.
void CmdNext::stepAfterAwait() {
  auto topObj = vmsp()->m_data.pobj;
  assertx(topObj->instanceof(c_AsyncFunctionWaitHandle::classof()));
  auto wh = static_cast<c_AsyncFunctionWaitHandle*>(topObj);
  auto func = wh->actRec()->func();
  Offset nextInst = wh->getNextExecutionOffset();
  assertx(nextInst != InvalidAbsoluteOffset);
  m_stepResumableId = wh->actRec();
  TRACE(2,
        "CmdNext: patch for cont step after Await at '%s' offset %d\n",
        func->fullName()->data(), nextInst);
  m_stepResumable = StepDestination(func->unit(), nextInst);
}
Exemple #19
0
// A AsyncESuspend is used in the codegen for an async function to setup
// a Continuation and return a wait handle so execution can continue
// later. We have just completed a AsyncESuspend, so the new
// Continuation is available, and it can predict where execution will
// resume.
void CmdNext::stepAfterAsyncESuspend() {
  auto topObj = g_context->getStack().topTV()->m_data.pobj;
  assert(topObj->instanceof(c_AsyncFunctionWaitHandle::classof()));
  auto wh = static_cast<c_AsyncFunctionWaitHandle*>(topObj);
  auto func = wh->getActRec()->m_func;
  Offset nextInst = wh->getNextExecutionOffset();
  assert(nextInst != InvalidAbsoluteOffset);
  m_stepContTag = wh->getActRec();
  TRACE(2,
        "CmdNext: patch for cont step after AsyncESuspend at '%s' offset %d\n",
        func->fullName()->data(), nextInst);
  m_stepCont = StepDestination(func->unit(), nextInst);
}
Exemple #20
0
V7_PRIVATE enum v7_err check_str_re_conv(struct v7 *v7, struct v7_val **arg,
                                         int re_fl) {
  /* If argument is not (RegExp + re_fl) or string, do type conversion */
  if (!is_string(*arg) &&
      !(re_fl && instanceof(*arg, &s_constructors[V7_CLASS_REGEXP]))) {
    TRY(toString(v7, *arg));
    *arg = v7_top_val(v7);
    INC_REF_COUNT(*arg);
    TRY(inc_stack(v7, -2));
    TRY(v7_push(v7, *arg));
  }
  return V7_OK;
}
void LIRGenerator::do_InstanceOf(InstanceOf* x) {
  LIRItem obj(x->obj(), this);
  CodeEmitInfo* patching_info = NULL;
  if (!x->klass()->is_loaded() || PatchALot) {
    patching_info = state_for(x, x->state_before());
  }
  // ensure the result register is not the input register because the result is initialized before the patching safepoint
  obj.load_item();
  LIR_Opr out_reg = rlock_result(x);
  LIR_Opr tmp1 = FrameMap::G1_oop_opr;
  LIR_Opr tmp2 = FrameMap::G3_oop_opr;
  LIR_Opr tmp3 = FrameMap::G4_oop_opr;
  __ instanceof(out_reg, obj.result(), x->klass(), tmp1, tmp2, tmp3,  x->direct_compare(), patching_info);
}
Exemple #22
0
icu::TimeZone* IntlTimeZone::ParseArg(const Variant& arg,
                                      const String& funcname,
                                      IntlError* err) {
  String tzstr;

  if (arg.isNull()) {
    tzstr = f_date_default_timezone_get();
  } else if (arg.isObject()) {
    auto objarg = arg.toObject();
    auto cls = objarg->getVMClass();
    auto IntlTimeZone_Class = Unit::lookupClass(s_IntlTimeZone.get());
    if (IntlTimeZone_Class &&
        ((cls == IntlTimeZone_Class) || cls->classof(IntlTimeZone_Class))) {
      return IntlTimeZone::Get(objarg.get())->timezone()->clone();
    }
    if (objarg.instanceof(DateTimeZoneData::getClass())) {
      auto* dtz = Native::data<DateTimeZoneData>(objarg.get());
      tzstr = dtz->getName();
    } else {
      tzstr = arg.toString();
    }
  } else {
    tzstr = arg.toString();
  }

  UErrorCode error = U_ZERO_ERROR;
  icu::UnicodeString id;
  if (!ustring_from_char(id, tzstr, error)) {
    err->setError(error, "%s: Time zone identifier given is not a "
                         "valid UTF-8 string", funcname.c_str());
    return nullptr;
  }
  auto ret = icu::TimeZone::createTimeZone(id);
  if (!ret) {
    err->setError(U_MEMORY_ALLOCATION_ERROR,
                  "%s: could not create time zone", funcname.c_str());
    return nullptr;
  }
  icu::UnicodeString gottenId;
  if (ret->getID(gottenId) != id) {
    err->setError(U_ILLEGAL_ARGUMENT_ERROR,
                  "%s: no such time zone: '%s'",
                  funcname.c_str(), arg.toString().c_str());
    delete ret;
    return nullptr;
  }
  return ret;
}
Exemple #23
0
void c_GenMapWaitHandle::onUnblocked() {
  assert(getState() == STATE_BLOCKED);

  for (;
       m_deps->iter_valid(m_iterPos);
       m_iterPos = m_deps->iter_next(m_iterPos)) {

    auto* current = tvAssertCell(m_deps->iter_value(m_iterPos));
    assert(current->m_type == KindOfObject);
    assert(current->m_data.pobj->instanceof(c_WaitHandle::classof()));
    auto child = static_cast<c_WaitHandle*>(current->m_data.pobj);

    if (child->isSucceeded()) {
      auto k = m_deps->iter_key(m_iterPos);
      m_deps->set(k.asCell(), &child->getResult());
    } else if (child->isFailed()) {
      putException(m_exception, child->getException());
    } else {
      assert(child->instanceof(c_WaitHandle::classof()));
      auto child_wh = static_cast<c_WaitableWaitHandle*>(child);

      try {
        if (isInContext()) {
          child_wh->enterContext(getContextIdx());
        }
        detectCycle(child_wh);
        blockOn(child_wh);
        return;
      } catch (const Object& cycle_exception) {
        putException(m_exception, cycle_exception.get());
      }
    }
  }

  auto const parentChain = getFirstParent();
  if (m_exception.isNull()) {
    setState(STATE_SUCCEEDED);
    tvWriteObject(m_deps.get(), &m_resultOrException);
  } else {
    setState(STATE_FAILED);
    tvWriteObject(m_exception.get(), &m_resultOrException);
    m_exception = nullptr;
  }

  m_deps = nullptr;
  UnblockChain(parentChain);
  decRefObj(this);
}
Exemple #24
0
Variant c_WaitHandle::t_join() {
  if (!isFinished()) {
    // run the full blown machinery
    assert(instanceof(c_WaitableWaitHandle::classof()));
    static_cast<c_WaitableWaitHandle*>(this)->join();
  }
  assert(isFinished());

  if (LIKELY(isSucceeded())) {
    // succeeded? return result
    return cellAsCVarRef(getResult());
  } else {
    // failed? throw exception
    throw Object{getException()};
  }
}
Exemple #25
0
PropertyBag ActorSet::save(void) const
{
	PropertyBag xml;

	for(const_iterator i = begin(); i != end(); ++i)
	{
		Actor &a = *(i->second);

		// Do not save Creatures.  We are saving spawns instead and the player data is separate
		if(!instanceof(a, Creature))
		{
			xml.add("object", a.save());
		}
	}

	return xml;
}
void c_GenVectorWaitHandle::onUnblocked() {
  assert(getState() == STATE_BLOCKED);

  for (; m_iterPos < m_deps->size(); ++m_iterPos) {

    Cell* current = tvAssertCell(m_deps->at(m_iterPos));
    assert(current->m_type == KindOfObject);
    assert(current->m_data.pobj->instanceof(c_WaitHandle::classof()));
    auto child = static_cast<c_WaitHandle*>(current->m_data.pobj);

    if (child->isSucceeded()) {
      auto result = child->getResult();
      m_deps->set(m_iterPos, &result);
    } else if (child->isFailed()) {
      putException(m_exception, child->getException());
    } else {
      assert(child->instanceof(c_WaitableWaitHandle::classof()));
      auto child_wh = static_cast<c_WaitableWaitHandle*>(child);

      try {
        detectCycle(child_wh);
        child_wh->getParentChain()
          .addParent(m_blockable, AsioBlockable::Kind::GenVectorWaitHandle);
        return;
      } catch (const Object& cycle_exception) {
        putException(m_exception, cycle_exception.get());
      }
    }
  }

  auto parentChain = getParentChain();
  if (m_exception.isNull()) {
    setState(STATE_SUCCEEDED);
    tvWriteObject(m_deps.get(), &m_resultOrException);
  } else {
    setState(STATE_FAILED);
    tvWriteObject(m_exception.get(), &m_resultOrException);
    m_exception = nullptr;
  }

  m_deps = nullptr;
  parentChain.unblock();
  decRefObj(this);
}
void LIRGenerator::do_InstanceOf(InstanceOf* x) {
  LIRItem obj(x->obj(), this);

  // result and test object may not be in same register
  LIR_Opr reg = rlock_result(x);
  CodeEmitInfo* patching_info = NULL;
  if ((!x->klass()->is_loaded() || PatchALot)) {
    // must do this before locking the destination register as an oop register
    patching_info = state_for(x, x->state_before());
  }
  obj.load_item();
  LIR_Opr tmp3 = LIR_OprFact::illegalOpr;
  if (!x->klass()->is_loaded() || UseCompressedOops) {
    tmp3 = new_register(objectType);
  }
  __ instanceof(reg, obj.result(), x->klass(),
                new_register(objectType), new_register(objectType), tmp3,
                x->direct_compare(), patching_info, x->profiled_method(), x->profiled_bci());
}
void c_GenVectorWaitHandle::onUnblocked() {
  assert(getState() == STATE_BLOCKED);

  for (; m_iterPos < m_deps->size(); ++m_iterPos) {

    Cell* current = tvAssertCell(m_deps->at(m_iterPos));
    assert(current->m_type == KindOfObject);
    assert(current->m_data.pobj->instanceof(c_WaitHandle::classof()));
    auto child = static_cast<c_WaitHandle*>(current->m_data.pobj);

    if (child->isSucceeded()) {
      cellSet(child->getResult(), *current);
    } else if (child->isFailed()) {
      putException(m_exception, child->getException());
    } else {
      assert(child->instanceof(c_WaitableWaitHandle::classof()));
      auto child_wh = static_cast<c_WaitableWaitHandle*>(child);

      try {
        if (isInContext()) {
          child_wh->enterContext(getContextIdx());
        }
        detectCycle(child_wh);
        blockOn(child_wh);
        return;
      } catch (const Object& cycle_exception) {
        putException(m_exception, cycle_exception.get());
      }
    }
  }

  if (m_exception.isNull()) {
    setState(STATE_SUCCEEDED);
    tvWriteObject(m_deps.get(), &m_resultOrException);
  } else {
    setState(STATE_FAILED);
    tvWriteObject(m_exception.get(), &m_resultOrException);
    m_exception = nullptr;
  }

  m_deps = nullptr;
  done();
}
Object c_ConditionWaitHandle::ti_create(const Variant& child) {
  // Child not a WaitHandle?
  auto const child_wh = c_WaitHandle::fromCell(child.asCell());
  if (UNLIKELY(!child_wh)) {
    SystemLib::throwInvalidArgumentExceptionObject(
      "Expected child to be an instance of WaitHandle");
  }

  // Child finished before notification?
  if (UNLIKELY(child_wh->isFinished())) {
    throwNotNotifiedException();
  }

  assert(child_wh->instanceof(c_WaitableWaitHandle::classof()));
  auto const child_wwh = static_cast<c_WaitableWaitHandle*>(child_wh);

  auto wh = req::make<c_ConditionWaitHandle>();
  wh->initialize(child_wwh);
  return Object(std::move(wh));
}
void c_GenVectorWaitHandle::enterContextImpl(context_idx_t ctx_idx) {
  assert(getState() == STATE_BLOCKED);

  // recursively import current child
  {
    assert(m_iterPos < m_deps->size());
    Cell* current = tvAssertCell(m_deps->at(m_iterPos));

    assert(current->m_type == KindOfObject);
    assert(current->m_data.pobj->instanceof(c_WaitableWaitHandle::classof()));
    auto child_wh = static_cast<c_WaitableWaitHandle*>(current->m_data.pobj);
    child_wh->enterContext(ctx_idx);
  }

  // import ourselves
  setContextIdx(ctx_idx);

  // try to import other children
  try {
    for (int64_t iter_pos = m_iterPos + 1;
         iter_pos < m_deps->size();
         ++iter_pos) {

      Cell* current = tvAssertCell(m_deps->at(iter_pos));
      assert(current->m_type == KindOfObject);
      assert(current->m_data.pobj->instanceof(c_WaitHandle::classof()));
      auto child = static_cast<c_WaitHandle*>(current->m_data.pobj);

      if (child->isFinished()) {
        continue;
      }

      assert(child->instanceof(c_WaitableWaitHandle::classof()));
      auto child_wh = static_cast<c_WaitableWaitHandle*>(child);
      child_wh->enterContext(ctx_idx);
    }
  } catch (const Object& cycle_exception) {
    // exception will be eventually processed by onUnblocked()
  }
}