示例#1
0
文件: instance.c 项目: ahua/java
/*
 * Execute the ANEWARRAY instruction
 */
void op_anewarray() {
    Ref type = resolve(u16(1), ID_TYPE);
    if (type == NULL) { return; } // rollback, gc done
    Ref arrayType = getRef(type, TYPE_ARRAY_TYPE);

    // resolve array type
    if (arrayType == NULL) {
        Ref target = getRef(core, OBJECT_TYPE);
        Ref method = getRef(core, CORE_RESOLVE_METHOD);
        executeMethod(target, method, 0);
        return; // rollback
    }

    // allocate space
    int length = peekInt(); // don't pop yet in case gc runs
    int numWords = ARRAY_DATA + length;
    Ref array = allocate(numWords, HEADER_OBJECT_ARRAY);
    if (array == NULL) { return; } // rollback, gc done
    popInt(); // pop length

    // initialise array object and push on stack
    int hash = (char*) array - (char*) core;
    setInt(array, OBJECT_HASHCODE, hash);
    setRef(array, OBJECT_TYPE, arrayType);
    setInt(array, ARRAY_LENGTH, length);
    pushRef(array);
    pc += 3;
}
示例#2
0
文件: exceptions.c 项目: ahua/java
/*
 * Execute the ATHROW instruction
 */
void op_athrow() {
    // check for null pointer
    Ref exception = popRef();
    if (exception == NULL) {
        throwException(CORE_THROW_NULL_POINTER);
        return;
    }

    // search for exception handler
    Ref exceptionType = getRef(exception, OBJECT_TYPE);
    while (frame != NULL) {
        // search in current method...
        if (searchForHandler(exception, exceptionType)) { return; }

        // ...otherwise pop to previous method frame
        unlockIfSynchronized();
        Ref previous = getRef(frame, FRAME_RETURN_FRAME);
        setRef(thread, THREAD_FRAME, previous);
        if (previous != NULL) { loadRegisters(); }
    }

    // no handler was found in any frame so exit thread
    thread = NULL;
    printf("Illegal State: thread exiting\n");
    exit(1);
}
示例#3
0
文件: monitor.c 项目: ahua/java
/*
 * Relinquish control of the given lock to the next thread in the queue
 */
static void relinquishLock(Ref lock) {
    // set ownership to next in queue...
    Ref thread = getRef(lock, LOCK_LOCK_HEAD);
    if (thread != NULL) {
        // move thread at head of queue to owner
        setRef(lock, LOCK_OWNER, thread);
        Int count = getInt(thread, THREAD_LOCK_COUNT);
        setInt(lock, LOCK_COUNT, count);

        // point head of queue to next in line
        Ref next = getRef(thread, THREAD_NEXT_LOCK);
        setRef(lock, LOCK_LOCK_HEAD, next);
        if (next == NULL) { setRef(lock, LOCK_LOCK_TAIL, NULL); }
        else { setRef(next, THREAD_PREV_LOCK, NULL); }

        // thread no longer in queue, schedule new owner
        setRef(thread, THREAD_NEXT_LOCK, NULL);
        setRef(thread, THREAD_LOCK, NULL);
        schedule(thread);
    }

    // ...unless there's nothing waiting
    else {
        setRef(lock, LOCK_OWNER, NULL);
        setInt(lock, LOCK_COUNT, 0);
    }
}
示例#4
0
void MPHFAlgorithm<span,Abundance_t,NodeState_t>::ProgressCustom::reset (u_int64_t ntasks)
{
    const char* label = nbReset < sizeof(messages)/sizeof(messages[0]) ? messages[nbReset++] : "other";

    getRef()->reset(ntasks);
    getRef()->setMessage (label);
    getRef()->init();
}
示例#5
0
文件: interpreter.c 项目: ahua/java
/*
 * Retrieve the constant pool entry at the given index. If the id of the
 * entry does not match the given id call the resolve method of the core
 * object and return null. The code in the core object will replace
 * the placeholder entry with the resolved object.
 */
Ref resolve(int index, int id) {
    Ref entry = getPoolEntry(index);
    if (getInt(entry, ENTRY_ID) != id) {
        Ref type = getRef(core, OBJECT_TYPE);
        Ref method = getRef(core, CORE_RESOLVE_METHOD);
        executeMethod(type, method, 0);
        return NULL;
    }
    return entry;
}
示例#6
0
文件: interpreter.c 项目: ahua/java
/*
 * Load the values of the virtual registers using the
 * current value of the thread register.
 */
void loadRegisters() {
    frame = getRef(thread, THREAD_FRAME);
    method = getRef(frame, FRAME_METHOD);
    pool = getRef(method, METHOD_POOL);
    locals = (Var*) (frame + FRAME_LOCALS);
    int sp = getInt(frame, FRAME_SP);
    stack = (Var*) ((char*) frame + sp);
    code = (unsigned char*) (getRef(method, METHOD_CODE) + ARRAY_DATA);
    pc = getInt(frame, FRAME_PC);
}
示例#7
0
SoBase* SoXipData::getRefByType(SoType type) const
{
	for (int i = 0; i < getNumRef(); i++)
	{
		if (getRef(i)->isOfType(type))
			return getRef(i);
	}

	return 0;
}
示例#8
0
文件: instance.c 项目: ahua/java
/*
 * Return true if type b is amoung the listed interfaces of type a
 */
static int isDeclaredImplementationOf(Ref a, Ref b) {
    Ref interfaces = getRef(a, TYPE_INTERFACE_TYPES);
    if (interfaces != NULL) {
        Int length = getInt(interfaces, ARRAY_LENGTH);
        int i = 0;
        for (; i < length; i++) {
            Ref next = getRef(interfaces, ARRAY_DATA + i);
            if (next == b) { return TRUE; }
        }
    }
    return FALSE;
}
示例#9
0
文件: invoke.c 项目: ahua/java
/*
 * Find the method matching the given name and descriptor in the
 * given class. If no method is found, return null.
 */
static Ref findMethod(Ref type, Ref name, Ref desc) {
    Ref array = getRef(type, TYPE_METHODS);
    if (array != NULL) {
        Int length = getInt(array, ARRAY_LENGTH);
        int i;
        for (i = 0; i < length; i++) {
            Ref m = getRef(array, ARRAY_DATA + i);
            Ref mName = getRef(m, ENTRY_NAME);
            Ref mDesc = getRef(m, ENTRY_DESCRIPTOR);
            if (name == mName && desc == mDesc) { return m; }
        }
    }
    return NULL;
}
void IWORKStyleRefContext::endOfElement()
{
  if (getRef())
  {
    const IWORKStyleMap_t::const_iterator it = m_styleMap.find(get(getRef()));
    if (m_styleMap.end() != it)
    {
      const IWORKStylePtr_t &style = it->second;
      if (style->getIdent() && getState().m_stylesheet && !m_nested)
        getState().m_stylesheet->m_styles[get(style->getIdent())] = style;
      if (isCollector())
        getCollector().collectStyle(style);
    }
  }
}
示例#11
0
void nmodel<VALTYPE>::readNTable(const char *filename){
  /* This function reads the n table from a file.
     Each line is of the format:  source_word_id p0 p1 p2 ... pn
     This is the inverse operation of the printTable function.
     NAS, 7/11/99
  */
  ifstream inf(filename);
  cerr << "Reading fertility table from " << filename << "\n";
  if(!inf){
    cerr << "\nERROR: Cannot open " << filename <<"\n";
    return;
  }

  VALTYPE prob;
  WordIndex tok, i;
  int nFert=0;
  while(!inf.eof()){
    nFert++;
    inf >> ws >> tok;
    if (tok > MAX_VOCAB_SIZE){
      cerr << "NTables:readNTable(): unrecognized token id: " << tok
    <<'\n';
    exit(-1);
  }
    for(i = 0; i < MAX_FERTILITY; i++){
      inf >> ws >> prob;
      getRef(tok, i)=prob;
    }
  }
  cerr << "Read " << nFert << " entries in fertility table.\n";
  inf.close();
}
示例#12
0
SysStatus
HATDefaultBase<ALLOC>::unmapPage(uval vaddr)
{
    SysStatus rc;
    SegmentHATRef segmentHATRef;
    HATRef hatRef = getRef();

    TraceOSMemHatDefDetReg(vaddr, PAGE_SIZE);

    rc = findSegmentGlobal(vaddr, segmentHATRef, 0);
    if (_FAILURE(rc)) {
	return 0;
    }

    /* shared segments are never really "unmapped" via the hat
     * rather, the FCM calls unmapPage on the SegmentHAT.
     * But on some machines, the TLB must be invalidated for
     * each region mapping the shared segment.  On these,
     * we go throught the region unmap interface and when
     * we get here call unmapSharedPage which does the tlb
     * invalidate.
     * For private mappings, this is the normal unmap path
     */
    return DREF(segmentHATRef)->unmapSharedPage(hatRef, vaddr);
}
示例#13
0
void FusionMapper::removeAlignables() {
    FastaReader* ref = getRef();
    if(ref == NULL)
        return ;

    vector<Sequence> seqs;

    // first pass to gather all sequences
    for(int i=0; i<mFusionMatchSize; i++) {
        for(int m=0; m< fusionMatches[i].size(); m++) {
            seqs.push_back(fusionMatches[i][m]->getRead()->mSeq);
        }
    }

    Matcher matcher(ref, seqs);

    int removed = 0;
    // second pass to remove alignable sequences
    for(int i=0; i<mFusionMatchSize; i++) {
        for(int m=fusionMatches[i].size()-1 ;m>=0; m--) {
            MatchResult* mr = matcher.match(fusionMatches[i][m]->getRead()->mSeq);
            if(mr != NULL) {
                //fusionMatches[i][m]->getRead()->mSeq.print();
                //cout<<endl;
                //mr->print();
                delete fusionMatches[i][m];
                fusionMatches[i].erase(fusionMatches[i].begin() + m);
                removed++;
            }
        }
    }
    loginfo( string("removeAlignables: ") + string( int2str(removed )));
}
示例#14
0
bool SSoundBuffer::loadResource()
{
	mSBuffer = new sf::SoundBuffer();
	bool success = mSBuffer->loadFromFile(getRef());
	SAssert(success, "Loading failed for some reason.");
	return success;
}
示例#15
0
folly::StringPiece getString(const LuaObject& obj) {
  auto& pobj = obj.value;
  if (pobj.__isset.stringVal) return pobj.stringVal;
  auto& ref = getRef(obj);
  if (ref.__isset.stringVal) return ref.stringVal;
  throw std::invalid_argument("LuaObject of wrong type");
}
示例#16
0
文件: interpreter.c 项目: ahua/java
/*
 * This function contains the main interpreter loop. Java
 * ByteCode instructions are executed one at a time. Before
 * calling this function the core register should contain
 * the correct value.
 */
execute() {
    // initialise register values
    printf("Interpreter started\n");
    initCollector();
    thread = getRef(core, CORE_RUNNING);
    loadRegisters();   

    // used to mimic a time slice
    int maxSize = 50;
    int count = 0;
    
    // execute the next instruction, indefinitely
    void (*implementation)();
    int index;
    unsigned char bytecode;
    for (;;) {
        bytecode = code[pc];
        dbgCodes[dbgIndex++] = bytecode;
        if (dbgIndex == 50) { dbgIndex = 0; }
        //printf("0x%X\n", bytecode);
        implementation = distributor[bytecode];
        implementation();
        count++;

        // check if another thread needs to be scheduled
        if (thread == NULL || count >= maxSize) {
            if (thread != NULL) { saveRegisters(); }
            scheduleNextThread();
            //wakeSleepingThreads();
            count = 0;
        }
    }
}
示例#17
0
void Image::copy(const Image& img) {
	for (int x = 0; x < img.width(); ++x) {
		for (int y = 0; y < img.height(); ++y) {
			getRef(x, y) = img.get(x, y);
		}
	}
}
示例#18
0
void Image::set(const int x, const int y, const Color& c) {
	if (x < WIDTH && y < HEIGHT) {
		getRef(x, y) = c;
	}
	else
		throw std::out_of_range("");
}
示例#19
0
SysStatus
HATDefaultBase<ALLOC>::detachVP(VPNum vp)
{
    SysStatus rc;
    SegmentList<ALLOC>* restart;
    SegmentHATRef ref;
    HATRef hatRef = getRef();
    uval segmentAddr, segmentEnd;
    VPSet* dummy;

    byVP[vp].lock.acquire();
    tassertMsg(byVP[vp].pp == Scheduler::GetVP(),
	       "detachVP called on wrong pp\n");
    tassertMsg(byVP[vp].segps != exceptionLocal.currentSegmentTable,
	       "detaching current segment table\n");
    restart = &(byVP[vp].segmentList);
    while (0<=SegmentList<ALLOC>::FindNextSegment(
	0, uval(-1), segmentAddr, segmentEnd, ref, dummy, restart)) {
	rc = DREF(ref)->unmapRange(hatRef, segmentAddr, segmentEnd,
				   0, uval(-1), vp);
	tassertMsg(_SUCCESS(rc), "oops\n");
    }
    byVP[vp].lock.release();
    return 0;
}
示例#20
0
/* virtual */ SysStatus
ProcessShared<ALLOC>::Factory::create(ProcessRef& outPref, HATRef h, PMRef pm,
                                      ProcessRef caller, const char *name)
{
    // LOCKING: see comment top of ProcessShared.H
    SysStatus rc = 0;
    ProcessShared* newProcess =
	new ProcessShared(h, pm, /*userMode*/ 1, /*isKern*/ 0, name);
    newProcess->factoryRef = (FactoryRef)getRef();
    newProcess->updatedFlagDoNotDestroy = false;

    // Enter Process into the Translation Table
    new typename ProcessShared<ALLOC>::Root(newProcess);
    outPref = (ProcessRef)newProcess->getRef();

    DREF(h)->attachProcess(outPref);

    DREF(pm)->attachRef();

    DREFGOBJ(TheProcessSetRef)->
	addEntry(_SGETUVAL(newProcess->getPID()), (BaseProcessRef&)outPref);

    if (_FAILURE(rc)) {
	newProcess->destroy();
	return rc;
    }

    registerInstance((CORef)outPref); /* FIXME: check return value */

    return 0;
}
示例#21
0
void LuaInterface::getWeakRef(int weakRef)
{
    // pushes weak_table[weakRef]
    getRef(m_weakTableRef);
    rawGeti(weakRef);
    remove(-2);
}
示例#22
0
/*
 * N.B. Although this routine is called locked, it releases
 * and re-acquires the lock.  Take care.
 *
 */
SysStatus
FCMDefault::getFrame(uval& paddr, uval flags)
{
    SysStatus rc;

    _ASSERT_HELD(lock);

    uval virtAddr;
    // release lock while allocating
    lock.release();

    rc = DREF(pmRef)->allocPages(getRef(), virtAddr, pageSize, pageable, 
				 flags, numanode);

    lock.acquire();

    if (_FAILURE(rc)) return rc;

    paddr = PageAllocatorKernPinned::virtToReal(virtAddr);

#if 0
    // some debugging stuff
    if (numanode != PageAllocator::LOCAL_NUMANODE
	&& !DREFGOBJK(ThePinnedPageAllocatorRef)->isLocalAddr(virtAddr)
	&& (DREFGOBJK(ThePinnedPageAllocatorRef)->addrToNumaNode(virtAddr)
	    == numanode)) {
	err_printf("Got Remote allocation for %ld: p %lx, n %d\n",
		   numanode, virtAddr, DREFGOBJK(ThePinnedPageAllocatorRef)->
		   addrToNumaNode(virtAddr));
    }
#endif /* #if 0 */

    return 0;
}
示例#23
0
/* virtual */ SysStatus
FileLinuxFile::processCallBack(uval request)
{
    FLFDEBUG("processCallBack");

    SysStatus rc;

    AutoLock<StreamLockType> al(&streamLock); // locks now, unlocks on return

    uval flen, off;
#ifndef LAZY_SHARING_SETUP
    flen = uval(~0);
#endif // #ifndef LAZY_SHARING_SETUP

    if (request == CALLBACK_REQUEST_SWITCH) {
	useType = SHARED;
#ifndef LAZY_SHARING_SETUP
	if (buffer) {
	    // FIXME: for now only from exclusive to shared
	    buffer->switchToShared(flen, off);
	}
#else
	// FIXME: for now only from exclusive to shared
	buffer->switchToShared(flen, off);
#endif // #ifndef LAZY_SHARING_SETUP
    } else {
#ifndef LAZY_SHARING_SETUP
	if (buffer) {
	    tassertMsg(request == CALLBACK_REQUEST_INFO, "req is %ld\n",
		       (uval) request);
	    rc = buffer->getLengthOffset(flen, off);
	    tassertMsg(_SUCCESS(rc), "?");
	}
#else
	tassertMsg(request == CALLBACK_REQUEST_INFO, "req is %ld\n",
		   (uval) request);
	rc = buffer->getLengthOffset(flen, off);
	tassertMsg(_SUCCESS(rc), "?");
#endif // #ifndef LAZY_SHARING_SETUP
    }

    tassertMsg(callBackUseTypeRegistered == 1, "how come? it is %ld\n",
	       callBackUseTypeRegistered);
    tassertMsg(stub.getOH().valid(), "stub not valid\n");

#ifdef DEBUG_USE_TYPE
#ifdef HACK_FOR_FR_FILENAMES
    char name[255];
    SysStatusUval rclen = stub._getFileName(name, sizeof(name));
    tassertMsg(_SUCCESS(rclen), "?");
    err_printf("processCallBack(%s) for request %ld returning flen %ld off %ld\n",
	       name, request, flen, off);
#endif // #ifdef HACK_FOR_FR_FILENAMES
#endif // #ifdef DEBUG_USE_TYPE

    rc = stub._ackUseTypeCallBack(request, flen, off);
    tassertMsg(_SUCCESS(rc), "how? ref %p\n", getRef());

    return 0;
}
示例#24
0
文件: exceptions.c 项目: ahua/java
/*
 * Search for an appropriate handler in the current method
 * and return true if one is found, false otherwise.
 */
static int searchForHandler(Ref exception, Ref exceptionType) {
    // make sure exception table exists
    Ref exceptionTable = getRef(method, METHOD_EXCEPTIONS);
    if (exceptionTable == NULL) { return FALSE; }

    // loop through exception table entries
    int length = getInt(exceptionTable, ARRAY_LENGTH);
    unsigned short* ps = (unsigned short*) (exceptionTable + ARRAY_DATA);
    int i = 0;
    for (; i < length; i += 4) {
        // read table entry
        int start_pc = ps[i];
        int end_pc = ps[i + 1];
        int handler_pc = ps[i + 2];
        int catch_type = ps[i + 3];

        // check range
        Ref catchTypeEntry = getPoolEntry(catch_type);
        int inRange = (pc >= start_pc) && (pc < end_pc);
        int handled = (catch_type == 0)
                || isSubClassOf(exceptionType, catchTypeEntry);
        if (inRange && handled) {
            pc = handler_pc;
            int frameSize = frame[OBJECT_SIZE].i;

            // clear stack
            Var* max = (Var*) (frame + frameSize);
            for (; stack < max; stack++) { stack->flag = FALSE; }
            pushRef(exception);
            return TRUE;
        }
    }
    return FALSE;
}
示例#25
0
文件: exceptions.c 项目: ahua/java
/*
 * If the current method is synchronized, unlock it
 */
static void unlockIfSynchronized() {
    int flags = getInt(method, ENTRY_FLAGS);
    if (flags && ACC_SYNCHRONIZED) {
        Ref lock = getRef(frame, OBJECT_LOCK);
        if (lock != NULL) { unlockLock(lock); }
    }
}
示例#26
0
文件: BaseObj.C 项目: BillTheBest/k42
SysStatus
BaseObj::destroyUnchecked()
{
    SysStatus retvalue;
    retvalue = DREFGOBJ(TheCOSMgrRef)
	    ->destroyCO((CORef)getRef(), (COSMissHandler *)myRoot);
    return (retvalue);
}
示例#27
0
void LuaInterface::setGlobalEnvironment(int env)
{
    pushThread();
    getRef(env);
    assert(isTable());
    setEnv();
    pop();
}
示例#28
0
文件: FRCRW.C 项目: BillTheBest/k42
void
FRCRW::init(FRRef baseFR, uval _numanode)
{
    //N.B. this call creates the ref
    FRComputation::init(_numanode);
    FCMComputation::Create(
	fcmRef, (FRRef)getRef(), baseFR, pageSize, pageable);
}
示例#29
0
/*virtual*/ SysStatus
ProcessShared<ALLOC>::destroy()
{
    SysStatus rc;

    /* FIXME: we want to destroy ourselves, just not the nested data structures
     * we have passed on in a hot-swap */
    if (updatedFlagDoNotDestroy) {
        return 0;
    }

    // delete all the fault notifications and annexes
    vpList.deleteAll();

    {   // remove all ObjRefs to this object
	SysStatus rc=closeExportedXObjectList();
	// most likely cause is that another destroy is in progress
	// in which case we return success
	if (_FAILURE(rc)) return _SCLSCD(rc)==1?0:rc;
    }

    // **************************************************************
    // From here on, only one destroy can be in progress.  see
    // closeExportedXObjectList for implementation of this syncronization

    lazyState.detach();

    // remove all ObjRefs owned by the process
    rc=closeMatchedXObjectList();
    tassert(_SUCCESS(rc),
	    err_printf("Free of process owned ObjRefs failed %p\n", this));

    // remove reference to us from processset - must be done after
    // closeMatchedXObjectList since XBaseObjs record ProcID's and must
    // be able to convert them to ProcessRefs.
    rc = DREFGOBJ(TheProcessSetRef)->remove(_SGETUVAL(getPID()));
    tassertWrn(_SUCCESS(rc), "Removing pid failed.\n");

    // delete all the regions we are using
    rlst.deleteRegionsAll();

    // now free the HAT
    DREF(hatRefProcess)->destroy();

    // tell pm we are releasing our reference
    DREF(pmRef)->detachRef();

    // more to do here ...
    // ports and procs - unless we just punt till they go away.

#ifdef USE_PROCESS_FACTORIES
    DREF(factoryRef)->destroy(getRef());
#else
    destroyUnchecked();
#endif

    return (0);
}
void IWORKStyleRefContext::endOfElement()
{
  const boost::optional<std::string> dummyIdent;
  const boost::optional<IWORKPropertyMap> dummyProps;

  // TODO: need to get the style
  switch (m_id)
  {
  case IWORKToken::NS_URI_SF | IWORKToken::cell_style_ref :
    getCollector()->collectStyle(IWORKStylePtr_t(), m_anonymous);
    break;
  case IWORKToken::NS_URI_SF | IWORKToken::characterstyle_ref :
  {
    IWORKStylePtr_t style;
    if (getRef())
    {
      const IWORKStyleMap_t::const_iterator it = getDictionary().m_characterStyles.find(get(getRef()));
      if (getDictionary().m_characterStyles.end() != it)
        style = it->second;
    }
    getCollector()->collectStyle(style, m_anonymous);
    break;
  }
  case IWORKToken::NS_URI_SF | IWORKToken::liststyle_ref :
    getCollector()->collectStyle(IWORKStylePtr_t(), m_anonymous);
    break;
  case IWORKToken::NS_URI_SF | IWORKToken::paragraphstyle_ref :
  {
    IWORKStylePtr_t style;
    if (getRef())
    {
      const IWORKStyleMap_t::const_iterator it = getDictionary().m_paragraphStyles.find(get(getRef()));
      if (getDictionary().m_paragraphStyles.end() != it)
        style = it->second;
    }
    getCollector()->collectStyle(style, m_anonymous);
    break;
  }
  case IWORKToken::NS_URI_SF | IWORKToken::vector_style_ref :
    getCollector()->collectStyle(IWORKStylePtr_t(), m_anonymous);
    break;
  default :
    break;
  }
}