QUrl::QUrl( const QUrl& url, const QString& relUrl, bool checkSlash )
{
    d = new QUrlPrivate;
    QString rel = relUrl;
    slashify( rel );

    QUrl urlTmp( url );
    if ( !urlTmp.isValid() ) {
	urlTmp.reset();
    }
    if ( isRelativeUrl( rel ) ) {
	if ( rel[ 0 ] == '#' ) {
	    *this = urlTmp;
	    rel.remove( (uint)0, 1 );
	    decode( rel );
	    setRef( rel );
	} else if ( rel[ 0 ] == '?' ) {
	    *this = urlTmp;
	    rel.remove( (uint)0, 1 );
	    setQuery( rel );
	} else {
	    decode( rel );
	    *this = urlTmp;
	    setRef( QString::null );
	    if ( checkSlash && d->cleanPath[(int)path().length()-1] != '/' ) {
		if ( isRelativeUrl( path() ) )
		    setEncodedPathAndQuery( rel );
		else
		    setFileName( rel );
	    } else {
		QString p = urlTmp.path();
		if ( p.isEmpty() ) {
		    // allow URLs like "file:foo"
		    if ( !d->host.isEmpty() && !d->user.isEmpty() && !d->pass.isEmpty() )
			p = "/";
		}
		if ( !p.isEmpty() && p.right(1)!="/" )
		    p += "/";
		p += rel;
		d->path = p;
		d->cleanPathDirty = TRUE;
	    }
	}
    } else {
	if ( rel[ 0 ] == QChar( '/' ) ) {
	    *this = urlTmp;
	    setEncodedPathAndQuery( rel );
	} else {
	    *this = rel;
	}
    }
}
Exemple #2
0
/*
 * Execute the PUTFIELD instruction
 */
void op_putfield() {
    Ref field = resolve(u16(1), ID_FIELD);
    if (field == NULL) { return; } // rollback

    // read values from stack
    Int size = getInt(field, FIELD_SIZE);
    Int flag = getInt(field, FIELD_REFERENCE_FLAG);
    Int value2 = (size == 2) ? popInt() : 0;
    Word value1;
    if (flag) { value1.r = popRef(); }
    else { value1.i = popInt(); }
    Ref object = popRef();

    // check for null pointer
    if (object == NULL) {
        throwException(CORE_THROW_NULL_POINTER);
        return;
    }

    // store the values
    Int index = getInt(field, FIELD_INDEX) + OBJECT_FIELDS;
    if (flag) { setRef(object, index, value1.r); }
    else { setInt(object, index, value1.i); }
    if (size == 2) { setInt(object, index + 1, value2); }
    pc += 3;
}
 PooledString::Ref &PooledString::Ref::operator=(const Ref &ref) {
     if(ref.realString != realString) {
         removeRef();
         setRef(ref);
     }
     return *this;
 }
Exemple #4
0
 /** Set the current data as a part of a referenced another data.
  * \param[in] ref : data referred by the current instance.
  * \param[in] offset : the current data will begin 'offset' bytes from the beginning of the referred data.
  * \param[in] length : size of the data */
 void setRef (Vector* ref, size_t offset, size_t length)
 {
     setRef (ref);
     _buffer      = _ref->_buffer + offset;
     _size        = length;
     _isAllocated = false;
 }
Exemple #5
0
    /** Destructor. */
    ~Vector ()
    {
        if (_isAllocated && _buffer) {  FREE (_buffer); }

        /** We get rid of the referred data if any. */
        setRef (0);
    }
Exemple #6
0
/*
 * 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;
}
Exemple #7
0
/*
 * 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);
}
Exemple #8
0
 /** Constructor. Cache size is in terms of number of items (I think) */
 BagCache (Bag<Item>* ref, size_t cacheSize, system::ISynchronizer* synchro=0)
     : _ref(0), _synchro(0), _items(0), _nbMax(cacheSize), _idx(0)
 {
     setRef     (ref);
     setSynchro (synchro);
     _items = (Item*) CALLOC (_nbMax, sizeof(Item));
     system::impl::System::memory().memset (_items, 0, _nbMax*sizeof(Item));
 }
Exemple #9
0
/*
 * Add the specified thread to the lock queue of the given lock
 */
void addToLockQueue(Ref thread, Ref lock) {
    // either the queue is empty...
    Ref lockTail = getRef(lock, LOCK_LOCK_TAIL);
    if (lockTail == NULL) {
        setRef(lock, LOCK_LOCK_HEAD, thread);
    }
    
    // ...or the thread can be appended
    else {
        setRef(lockTail, THREAD_NEXT_LOCK, thread);
        setRef(thread, THREAD_PREV_LOCK, lockTail);
    }

    // either way the thread becomes the new tail
    setRef(lock, LOCK_LOCK_TAIL, thread);
    setRef(thread, THREAD_LOCK, lock);
}
Exemple #10
0
int main(int argc, char* argv[]){
    char buffer[BUFFER_SIZE];
    int index, pages;
    int requests = 0;
    int faults = 0;
    
    if(argc < 1){
        printf("Too many arguments. Please look at documentation to compile.\n");
        return 0;
    }

    sscanf(argv[1], "%d", &pages);

    Set* set = create(pages);

    FILE* fp = fopen("out.txt", "w");
    assert(fp != NULL);
    
    while(fgets(buffer, sizeof(buffer), stdin) != NULL) {

        if(!isdigit((int)buffer[0]))
            continue;

        sscanf(buffer, "%d", &index);

        requests++;
        if(findNode(set, index) >= 0){
            setRef(set, index, requests);
        }
        else{
            if(getSize(set) == pages)
                eraseNode(set, findMin(set));

            insertNode(set, index, 0);
            setRef(set, index, requests);
            faults++;
            assert(fprintf(fp, "%d \n", index) >= 0);
        }

    } // while
    fclose(fp);
    free(set); 
    printf("Number of page requests: %d \nNumber of page faults: %d \n", requests, faults);
    return 1;
}
Exemple #11
0
/*
 * 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);
    }
}
Exemple #12
0
    BagCache (const BagCache<Item>& b)
        : _ref(0), _synchro(0), _items (0), _nbMax(b._nbMax), _idx(0)
    {
        setRef     (b._ref);
        setSynchro (b._synchro);

        _items = (Item*) CALLOC (_nbMax, sizeof(Item));
        system::impl::System::memory().memset (_items, 0, _nbMax*sizeof(Item));
    }
Exemple #13
0
/*
 * Return the lock for the specified object. Allocate a new lock object
 * if necessary. If this allocation is interrupted by the garbage
 * collector, return null.
 */
Ref getLock(Ref object) {
    Ref result = getRef(object, OBJECT_LOCK);
    if (result == NULL) {
        result = allocate(LOCK_WAIT_TAIL + 1, HEADER_INSTANCE);
        if (result == NULL) { return NULL; } // rollback, gc done

        // initialise
        Ref lockType = getRef(core, CORE_LOCK_TYPE);
        int hash = (char*) result - (char*) core;
        setRef(result, OBJECT_TYPE, lockType);
        setInt(result, OBJECT_HASHCODE, hash);
        // all fields in new lock are initially null

        // point object to its new lock
        setRef(object, OBJECT_LOCK, result);
    }
    return result;
}
Exemple #14
0
void Switch::createSettings(QGridLayout *layout) {
    layout->addWidget(new QLabel("Label", layout->parentWidget()));
    QLineEdit *labelEdit = new QLineEdit(_label, layout->parentWidget());
    connect(labelEdit, SIGNAL(textChanged(QString)), this, SLOT(setLabel(QString)));
    layout->addWidget(labelEdit);

    layout->addWidget(new QLabel("Dataref", layout->parentWidget()));
    QLineEdit *refEdit = new QLineEdit(_refname, layout->parentWidget());
    connect(refEdit, SIGNAL(textChanged(QString)), this, SLOT(setRef(QString)));
    layout->addWidget(refEdit);
}
Exemple #15
0
void RotaryKnob::createSettings(QGridLayout *layout) {
    layout->addWidget(new QLabel("Dataref", layout->parentWidget()));
    QLineEdit *refEdit = new QLineEdit(_refname, layout->parentWidget());
    connect(refEdit, SIGNAL(textChanged(QString)), this, SLOT(setRef(QString)));
    layout->addWidget(refEdit);

    layout->addWidget(new QLabel("Change amount", layout->parentWidget()));
    QLineEdit *changeEdit = new QLineEdit(QString::number(_change), layout->parentWidget());
    connect(changeEdit, SIGNAL(textChanged(QString)), this, SLOT(setChangeString(QString)));
    layout->addWidget(changeEdit);
}
Exemple #16
0
    /** Destructor. */
    virtual ~BagCache ()
    {
        /** We flush the potential remaining stuf. */
        flush ();

        /** We clean resources. */
        setRef     (0);
        setSynchro (0);

        FREE (_items);
    }
Exemple #17
0
int main(int argc, char* argv[]){
    char buffer[BUFFER_SIZE];
    int index, pages;
    int requests = 0;
    int faults = 0;
    
    if(argc < 1){
        printf("Too many arguments. Please look at documentation to compile.\n");
        return 0;
    }

    sscanf(argv[1], "%d", &pages);

    Queue* queue = create(pages);

    FILE* fp = fopen("out.txt", "w");
    assert(fp != NULL);
    
    while(fgets(buffer, sizeof(buffer), stdin) != NULL) {

        if(!isdigit((int)buffer[0]))
            continue;

        sscanf(buffer, "%d", &index);

        if(!findNode(queue, index)){
            if(size(queue) < pages) {
                enqueue(queue, index, 1);
            }
            else {
                while(getFrontRef(queue))
                    enqueue(queue, dequeue(queue), 0);

                dequeue(queue);
                enqueue(queue, index, 1);
            }
            faults++;
            assert(fprintf(fp, "%d \n", index) >= 0);

        } // if
        else {
            setRef(queue, index, 1);
        }
        requests++;

    } // while
    fclose(fp);
    free(queue); 
    printf("Number of page requests: %d \nNumber of page faults: %d \n", requests, faults);
    return 1;
}
Exemple #18
0
/*
 * Execute the NEW instruction
 */
void op_new() {
    // resolve the type
    Ref type = resolve(u16(1), ID_TYPE);
    if (type == NULL) { return; } // rollback, gc done

    // allocate space
    int numFields = getInt(type, TYPE_INSTANCE_FIELD_COUNT);
    int numWords = OBJECT_FIELDS + numFields;
    Ref object = allocate(numWords, HEADER_INSTANCE);
    if (object == NULL) { return; } // rollback, gc done
    
    // set headers and push on stack
    int hash = (char*) object - (char*) core;
    setInt(object, OBJECT_HASHCODE, hash);
    setRef(object, OBJECT_TYPE, type);
    pushRef(object);
    pc += 3;
}
Exemple #19
0
/*
 * Execute the PUTSTATIC instruction
 */
void op_putstatic() {
    Ref field = resolve(u16(1), ID_FIELD);
    if (field == NULL) { return; } // rollback
    
    // read field values
    Ref type = getRef(field, ENTRY_OWNER);
    Ref statics = getRef(type, TYPE_STATICS);
    Int index = getInt(field, FIELD_INDEX);
    Int flag = getInt(field, FIELD_REFERENCE_FLAG);
    Int size = getInt(field, FIELD_SIZE);
    int offset = STATICS_FIELDS + index;
    
    // pop values from stack and store
    if (size == 2) { setInt(statics, offset, popInt()); }
    if (flag) { setRef(statics, offset, popRef()); }
    else { setInt(statics, offset, popInt()); }
    pc += 3;
}
void Point::changerDeReferentiel(Referentiel* newRef)
{
    if( ref_ && (ref_ != newRef) )
    {
        // Les deux origines sont exprimées dans le référentiel de référence
        Vecteur entreOrigines = ref()->origin() - newRef->origin();

        entreOrigines.changerDeReferentiel(newRef);

        if(!estNul())
        {
            Vecteur::changerDeReferentiel(newRef);
        }

        *this += entreOrigines;

        setRef(newRef);
    }
}
Exemple #21
0
/*
 * Called when the given thread wants to acquire the specified
 * lock. If the thread must wait in the queue it is unscheduled.
 * The lock count is incremented by the specified amount
 * after acquisition.
 */
void acquireLock(Ref thread, Ref lock, int increment) {
    // either the lock currently has no owner...
    Ref owner = getRef(lock, LOCK_OWNER);
    if (owner == NULL) {
        setRef(lock, LOCK_OWNER, thread);
        setInt(lock, LOCK_COUNT, increment);
    }

    // ...or the current thread already holds the lock...
    else if (owner == thread) {
        Int count = getInt(lock, LOCK_COUNT);
        setInt(lock, LOCK_COUNT, count + increment);
    }

    // ...or the current thread has to wait in line to obtain the lock
    else {
        setInt(thread, THREAD_LOCK_COUNT, increment);
        addToLockQueue(thread, lock);
        unschedule(thread);
    }
}
Exemple #22
0
/*
 * Execute the NEWARRAY instruction
 */
void op_newarray() {
    // figure out the required size
    int atype = u8(1);
    int width = getWidth(atype);
    int length = peekInt(); // don't pop in case rolled back later
    int numBytes = length * width;
    int extra = ((numBytes % 4) == 0) ? 0 : 1;
    int numDataWords = (numBytes / 4) + extra;
    int numWords = numDataWords + ARRAY_DATA;

    // allocate space
    Ref array = allocate(numWords, HEADER_DATA_ARRAY);
    if (array == NULL) { return; } // rollback, gc done
    popInt(); // can pop the length now

    // initialise new array and push address on stack
    int hash = (char*) array - (char*) core;
    Ref type = getRef(core, CORE_ARRAYS + atype);
    setInt(array, OBJECT_HASHCODE, hash);
    setRef(array, OBJECT_TYPE, type);
    setInt(array, ARRAY_LENGTH, length);
    pushRef(array);
    pc += 2;
}
ExpresionVar::ExpresionVar(char *referencia)
{
	this->ref = setRef(referencia);

	//this->ref = new Cadena(referencia);
}
ExpresionVar::ExpresionVar(const ExpresionVar &exp)
{
	this->ref = setRef(exp.ref);
	
}
 PooledString::Ref::Ref(const Ref &ref) {
     realString = NULL;
     setRef(ref);
 }
double flow_poster_prob_calc::best_hyp(flow_list *alter_hyp, flow_list *read_list, int cov, float vh, char *line_out)
{
    int num_hyp = alter_hyp->num_list();
    int best = -1;
    double bscore = 1e20;
    double sbscore = 1e20;
    int i, num_r = read_list->num_list();
    unsigned char *s;
    int *f;
    int len;
    if (num_hyp == 0) return 0.0;
    for (i = 0; i < num_hyp; i++) {
	int j;
	double prior;
	alter_hyp->get_list(i, s, f, len, prior);
	setRef(len, s, f);
	double score = 0.0;
    	unsigned char *s1;
    	int *f1;
    	int len1;
	if (debug) alter_hyp->output_hyp(i);
	for (j = 0; j < num_r; j++) {
	    double p1;
	    read_list->get_list(j, s1, f1, len1, p1);
	    double x = calc_post_prob(len1, s1, f1, (p1 >0.0)? 1:-1);
	    score += x;
	}
	score -= log10(prior)*10.0;

	if (score < bscore) {
	    sbscore = bscore;
	    bscore = score;
	    best = i;
	} else if (score < sbscore) {
	    sbscore  = score;
	}
    }
    if (debug) printf("best =%f  second=%f\n", bscore, sbscore);
    double ex =-(sbscore-bscore)/num_r/10.0;
    ex = pow(10.0, ex);
    if (num_r > cov) ex = ex*(cov+num_r);
    else ex = ex*cov;
    double xxx = poisson(num_r, ex);
    if (num_r > cov) xxx = xxx*cov/num_r;
    if (vh > 75.0 && (best == 0 || xxx < 1.0)) {
	best = 1;
	xxx = vh*2.0;
    }
    //xxx = -log10(xxx)*10.0;
    //printf("PPP=log odd p-value=%f %f %f %f %f\n", (float) (sbscore-bscore), (float) sbscore, (float) bscore, (float) xxx, (float) ex);
    
    int is_hotspot = 0;
    if (alter_hyp->is_indel()) {
 	is_hotspot =  check_is_hotspot(line_out);
    }
    if (best != 0) {
	//printf("PPP=Refe="); alter_hyp->output_hyp(0); 
    	//printf("PPP=Call="); alter_hyp->output_hyp(best);
	xxx = xxx*0.63;  // normalization
	output_line(xxx, line_out, is_hotspot);
    } else {
	//printf("PPP1=Refe="); alter_hyp->output_hyp(0);
	output_line(0.0, line_out, is_hotspot);
	xxx = 0.0;
	//fprintf(outp, "Bayesian_Score=0\n");
    }
    return xxx;
}
Exemple #27
0
void Switch::loadSettings(QSettings &settings) {
    PanelItem::loadSettings(settings);
    setLabel(settings.value("label", "Switch").toString());
    setRef(settings.value("dataref", "").toString());
}
ArrayData* NameValueTableWrapper::setRef(int64_t k, CVarRef v, bool copy) {
  return setRef(String(k), v, copy);
}
Exemple #29
0
/*
 * Execute the specified native method. Return true if the method
 * is executed, false if it is rolled back for garbage collection.
 */
int executeNativeMethod(Ref target, Ref method, int offset) {
    int magic = getInt(method, METHOD_MAGIC);
    if (magic == 0) {
        printf("Native method not supported\n");
        debugTrace();
        exit(1);
    }
    switch (magic) {
        // print a debug message
        case MAGIC_RUNTIME_CORE_DEBUG:
            debugLine(popRef());
            pc += offset;
            break;

        // execute the given static method
        case MAGIC_RUNTIME_CORE_EXECUTE_STATIC:
            {
                Ref staticMethod = popRef();
                if (staticMethod  == NULL) {
                    throwException(CORE_THROW_NULL_POINTER);
                    return;
                }
                Ref owner = getRef(staticMethod, ENTRY_OWNER);
                if (!executeMethod(owner, staticMethod, offset)) {
                    // restore stack if rolled back for gc
                    pushRef(staticMethod); 
                }
            }
            break;

        // return the current frame
        case MAGIC_RUNTIME_FRAME_CURRENT:
            pushRef(frame);
            pc += offset;
            break;

        // return the core object
        case MAGIC_RUNTIME_CORE_GET:
            pushRef(core);
            pc += offset;
            break;

        // create a statics object
        case MAGIC_RUNTIME_STATICS_CREATE:
            {
                // allocate space for statics object
                Ref type = popRef();
                Int numStaticFields = getInt(type, TYPE_STATIC_FIELD_COUNT);
                Int numWords = STATICS_FIELDS + numStaticFields;
                Ref statics = allocate(numWords, HEADER_STATIC_FIELDS);
                if (statics == NULL) {
                    pushRef(type); // restore stack
                    return; // rollback, gc done
                }

                // initialise statics object and set in type object
                int hash = (char*) statics - (char*) core;
                setInt(statics, OBJECT_HASHCODE, hash);
                Ref staticsType = getRef(core, CORE_STATICS_TYPE);
                setRef(statics, OBJECT_TYPE, staticsType);
                Ref map = getRef(type, TYPE_STATIC_MAP);
                setRef(statics, STATICS_MAP, map);
                setRef(type, TYPE_STATICS, statics);
            }
            pc += offset;
            break;

        // read the type from a class
        case MAGIC_RUNTIME_CORE_GET_TYPE:
            {
                Ref class = popRef();
                // type is first field in class...
                Ref type = getRef(class, OBJECT_FIELDS);
                pushRef(type);
            }
            pc += offset;
            break;

        // put system to sleep to avoid wasting processor time while idle
        case MAGIC_RUNTIME_IDLE_SLEEP:
            idleSleep();
            pc += offset;
            break;

        // return the currently executing thread
        case MAGIC_RUNTIME_THREAD_CURRENT:
            pushRef(thread);
            pc += offset;
            break;

        // start a new thread
        case MAGIC_RUNTIME_THREAD_START_HOOK:
            startNewThread(offset);
            break;

        // return an object's class
        case MAGIC_JAVA_OBJECT_GET_CLASS:
            {
                Ref obj = popRef();
                Ref type = getRef(obj, OBJECT_TYPE);
                Ref peer = getRef(type, TYPE_PEER);
                pushRef(peer);
            }
            pc += offset;
            break;

        // set system output stream
        case MAGIC_JAVA_SYSTEM_SET_OUT:
            {
                Ref arg = popRef();
                Ref type = getRef(method, ENTRY_OWNER);
                Ref statics = getRef(type, TYPE_STATICS);
                setRef(statics, STATICS_FIELDS + SYSTEM_OUT, arg);
            }
            pc += offset;
            break;

        // set system error stream
        case MAGIC_JAVA_SYSTEM_SET_ERR:
            {
                Ref arg = popRef();
                Ref type = getRef(method, ENTRY_OWNER);
                Ref statics = getRef(type, TYPE_STATICS);
                setRef(statics, STATICS_FIELDS + SYSTEM_ERR, arg);
            }
            pc += offset;
            break;

        // set system input stream
        case MAGIC_JAVA_SYSTEM_SET_IN:
            {
                Ref arg = popRef();
                Ref type = getRef(method, ENTRY_OWNER);
                Ref statics = getRef(type, TYPE_STATICS);
                setRef(statics, STATICS_FIELDS + SYSTEM_IN, arg);
            }
            pc += offset;
            break;

        // read an ascii character from the console
        case MAGIC_TEST_READ_FROM_CONSOLE:
            {
                char c = readFromConsole();
                pushInt(c);
            }
            pc += offset;
            break;
            
        // write an ascii character to the console
        case MAGIC_TEST_WRITE_TO_CONSOLE:
            {
                char c = popInt() & 0xFF;
                printf("%c", c);
            }
            pc += offset;
            break;

        // read a byte from the floppy drive
        case MAGIC_TEST_READ_FROM_FLOPPY:
            {
                Int pos = popInt();
                pushInt(readFromFloppy(pos));
            }
            pc += offset;
            break;
			
        // magic id not recognised
        default:
            printf("Invalid magic method id: %d\n", magic);
            exit(1);
            break;
    }
}
Exemple #30
0
/*
 * Execute the specified method. Return true if the method is executed,
 * false if it is rolled back for garbage collection.
 *
 * target: object for instance methods, class for static
 * method: the method to be run
 * offset: amount to increment program counter
 */
int executeMethod(Ref target, Ref method, int offset) {
/*
printf("[");
if (method[ENTRY_FLAGS].i & ACC_STATIC) { debugString(target[TYPE_NAME].s); }
else { debugString(method[ENTRY_OWNER].s[TYPE_NAME].s); }
printf(".");
debugString(method[ENTRY_NAME].s);
debugString(method[ENTRY_DESCRIPTOR].s);
printf("]\n");
*/
    // check for native method
    Int argcount = getInt(method, METHOD_ARG_COUNT);
    Int flags = getInt(method, ENTRY_FLAGS);
    if (flags & ACC_NATIVE) {
        return executeNativeMethod(target, method, offset);
    }

    // if synchronized, acquire the lock
    Ref lock = NULL;
    if (flags & ACC_SYNCHRONIZED) {
        lock = getLock(target);
        if (lock == NULL) { return FALSE; } // rollback, gc done
        acquireLock(thread, lock, 0);
        if (thread == NULL) { return FALSE; } // rollback, wait for lock 
    }

    // allocate space for new frame
    Int maxLocals = getInt(method, METHOD_MAX_LOCALS);
    Int maxStack = getInt(method, METHOD_MAX_STACK);
    int numWords = FRAME_LOCALS + 2*maxLocals + 2*maxStack;
    Ref newFrame = allocate(numWords, HEADER_STACK_FRAME);
    if (newFrame == NULL) { return FALSE; } // rollback, gc done

    // increment lock count now that instruction can't be rolled back
    if (flags & ACC_SYNCHRONIZED) {
        Int count = getInt(lock, LOCK_COUNT);
        setInt(lock, LOCK_COUNT, count + 1);
    }

    // initialise new frame
    int hash = (char*) newFrame - (char*) core;
    Ref frameType = getRef(frame, OBJECT_TYPE);
    setInt(newFrame, OBJECT_HASHCODE, hash);
    setRef(newFrame, OBJECT_LOCK, lock);
    setRef(newFrame, OBJECT_TYPE, frameType);
    setRef(newFrame, FRAME_RETURN_FRAME, frame);
    setRef(newFrame, FRAME_METHOD, method);
    setInt(newFrame, FRAME_RETURN_PC, pc + offset);
    setInt(newFrame, FRAME_PC, 0);
    setInt(newFrame, FRAME_SP, numWords * 4);

    // pop arguments off current stack and write to new frame
    int index = argcount;
    while (--index >= 0) {
        if (refOnStack()) { setLocalRef(index, popRef(), newFrame); }
        else { setLocalInt(index, popInt(), newFrame); }
    }

    // point current thread to new frame
    saveRegisters();
    setRef(thread, THREAD_FRAME, newFrame);
    loadRegisters();
    return TRUE;
}