Esempio n. 1
0
    /**
Copies an array from the specified source array, beginning at the specified position,
to the specified position of the destination array. A subsequence of array components
are copied from the source array referenced by src to the destination array referenced
by dest. The number of components copied is equal to the length argument. T
he components at positions srcPos through srcPos+length-1 in the source array are
copied into positions destPos through destPos+length-1, respectively, of the
destination array.

If the src and dest arguments refer to the same array object, then the copying is performed as if the components at positions srcPos through srcPos+length-1 were first copied to a temporary array with length components and then the contents of the temporary array were copied into positions destPos through destPos+length-1 of the destination array. 

If dest is null, then a NullPointerException is thrown. 

If src is null, then a NullPointerException is thrown and the destination array is not modified. 

Otherwise, if any of the following is true, an ArrayStoreException is thrown and the destination is not modified: 

The src argument refers to an object that is not an array. 
The dest argument refers to an object that is not an array. 
The src argument and dest argument refer to arrays whose component types are different primitive types. 
The src argument refers to an array with a primitive component type and the dest argument refers to an array with a reference component type. 
The src argument refers to an array with a reference component type and the dest argument refers to an array with a primitive component type. 
Otherwise, if any of the following is true, an IndexOutOfBoundsException is thrown and the destination is not modified: 

The srcPos argument is negative. 
The destPos argument is negative. 
The length argument is negative. 
srcPos+length is greater than src.length, the length of the source array. 
destPos+length is greater than dest.length, the length of the destination array. 
Otherwise, if any actual component of the source array from position srcPos through srcPos+length-1 cannot be converted to the component type of the destination array by assignment conversion, an ArrayStoreException is thrown. In this case, let k be the smallest nonnegative integer less than length such that src[srcPos+k] cannot be converted to the component type of the destination array; when the exception is thrown, source array components from positions srcPos through srcPos+k-1 will already have been copied to destination array positions destPos through destPos+k-1 and no other positions of the destination array will have been modified. (Because of the restrictions already itemized, this paragraph effectively applies only to the situation where both arrays have component types that are reference types.)

Parameters:
src the source array.
srcPos starting position in the source array.
dest the destination array.
destPos starting position in the destination data.
length the number of array elements to be copied.
Throws:
HaikuWRONG: IndexOutOfBoundsException - if copying would cause access of data outside array bounds.
Experiment (see ArrayIndexTest) shows that Sun'S JVM throws: ArrayIndexOutOfBoundsException
ArrayStoreException - if an element in the src array could not be stored into the dest array because of a type mismatch.
NullPointerException - if either src or dest is null.
     */
void native_java_lang_System_arraycopy_Ljava_lang_Object_ILjava_lang_Object_IIV() {
	int      length=  top.s1.i;
	int      destPos= ipop();
    array_t* dest=    (array_t*) apop();
	int      srcPos=  ipop();
	array_t* src=     (array_t*) apop();
	int size;
	popTop();

#if	HAIKU_InternalExceptionEnable & NullPointerException
	if (src==NULL || dest==NULL) {
		throwException(NullPointerException, 0);
		return;
	}
#endif
#if	HAIKU_InternalExceptionEnable & ArrayIndexOutOfBoundsException
	if ( srcPos<0 ||destPos<0 ||length <0 || srcPos+length > src->length || destPos+length >dest->length) throwException(ArrayIndexOutOfBoundsException, srcPos);
#endif

	if (length==0) return;

	size=getSize(dest); // Hierhin wg. möglicher integer div by 0 (if dest->length==0)

#if	HAIKU_InternalExceptionEnable & ArrayStoreException
	if (size!=getSize(src)) throwException(ArrayStoreException, size);
#endif

	if (!isExceptionThrown(NULL))
		memcpy(dest->array+destPos*size, src->array+srcPos*size, length*size);
}
/*
 * Proprietary HaikuVM stack to JNI interface function.
 * DO NOT EDIT THIS FUNCTION – it is machine generated.
 * 
 * Class:     processing.hardware.arduino.cores.arduino.ArduinoImpl
 * Method:    digitalWrite
 * Signature: (BB)V
 */
JNIEXPORT void native_processing_hardware_arduino_cores_arduino_ArduinoImpl_digitalWrite_BBV(void) {
    pushTop();    // Save variable top onto stack.
    {
        jbyte    arg2 = pop()->b;
        jbyte    arg1 = pop()->b;
        jclass     obj = NULL;
        JNIEnv     *env = NULL; // not used in HaikuVM
        Java_processing_hardware_arduino_cores_arduino_ArduinoImpl_digitalWrite(env, obj, arg1, arg2);
    }
    popTop();
}
Esempio n. 3
0
/*
Remove an item from the Deque
*/
bool removeItem(Deque* d, int item)
{
    Node* h = d->head; // get pointer to head and tail of Deque
    Node* t = d->tail; // iterate front to back and back to front simultaneously
    while (true) {
        if (h->data == item) { // iterate forwards
            if (h->prev == NULL) {
                popTop(d);
            } else {
                Node* n = h;
                n->prev->next = h->next;
                n->next->prev = h->prev;
            }
            return true;
        } else if (t->data == item) { // iterate backwards
            if (t->next == NULL) {
                popBottom(d);
            } else {
                Node* n = t;
                n->prev->next = t->next;
                n->next->prev = t->prev;
            }
            return true;
        }

        h = h->next;

        // if pointing to same value, i.e. meet in the middle of the Deque, return
        if (h == t) return false;

        t = t->prev;

        // if end of deque has been reached (shouldn't occur because of if(h == t)
        if (h == NULL || t == NULL) return false;
    }

    return false;
}
Esempio n. 4
0
int main(int argc, char** argv)
{
    if (argc != 4) {
        printf("Incorrect number of arguments.\n"
               "1: Number of frames\n"
               "2: traces file name\n"
               "3: LRU or LFU\n");
    }

    int nFrames = atoi(argv[1]);
    char* fName = argv[2];
    char* opt = argv[3];

    const unsigned int pageTableSize = 1024;
    bool mode = 0;
    int numFaults = 0;
    int numUsedFrames = 0;

    int tlbMisses = 0;
    int tlbCount = 0;

    if (strcmp(opt, "LRU") == 0 || strcmp(opt, "LFU") == 0) {
        mode = strcmp(opt, "LRU") == 0 ? LRU : LFU;
    } else {
        printf("Wrong input. Need LRU or LFU.\n");
        exit(EXIT_FAILURE);
    }

    Deque* traces = parseFile(fName); // read in page table
    Deque* lru = getDeque(); // most recent on top, oldest on bottom

    // initialize transitive lookaside buffer
    TlbInfoEntry* tlb = (TlbInfoEntry*)malloc(sizeof(TlbInfoEntry) * TLB_SIZE);
    for (int i = 0; i < TLB_SIZE; i++) {
        tlb[i].frameNum = -1;
        tlb[i].hitCount = 0;
        tlb[i].pageNum = -1;
    }

    // initialize page table
    PageInfoEntry* pageTable = (PageInfoEntry*) malloc(sizeof(PageInfoEntry) * pageTableSize);
    for (int i = 0; i < pageTableSize; i++) {
        pageTable[i].frameNumber = 0;
        pageTable[i].numReferences = 0;
        pageTable[i].valid = false;
    }

    while (traces->size > 0) {
        int pageIndex = popTop(traces); // get next trace

        pageTable[pageIndex].numReferences++; // page is referenced, add to count (for LFU), not LRU

        if (pageTable[pageIndex].valid) { // if page is valid, remove it

            // simulate parallel TLB lookup of page #.  (Serial lookup must be done for simulation)
            bool inTlb = false;
            for (int i = 0; i < TLB_SIZE; i++) {
                if (tlb[i].pageNum == pageIndex) {
                    int frameNum = tlb[i].frameNum;
                    /*
                    Code that uses actual physical frame memory
                    */
                    tlb[i].hitCount++;
                    inTlb = true;
                }
            }
            if (!inTlb) {
                tlbMisses++;
                // add missed item to tlb;
                if (tlbCount < TLB_SIZE) {
                    tlb[tlbCount].pageNum  = pageIndex;
                    tlb[tlbCount].frameNum = pageTable[pageIndex].frameNumber;
                } else {
                    // find the least recently used page #, and replace it
                    int minHitCount = INT_MAX, minHitIndex = 0;
                    for (int i = 0; i < TLB_SIZE; i++) {
                        if (tlb[i].hitCount < minHitCount) {
                            minHitCount = tlb[i].hitCount;
                            minHitIndex = i;
                        }
                    }
                    tlb[minHitIndex].pageNum = pageIndex;
                    tlb[minHitIndex].frameNum = pageTable[pageIndex].frameNumber;
                }

                // if the page# was not found in the TLB, use page table instead
                if (mode == LRU) {            // and place back at bottom of Deque
                    removeItem(lru, pageIndex);
                    pushTop(lru, pageIndex);
                }
            }
        } else {
            numFaults++; // item not valid -> numFaults++

            int frameId = 0;
            if (numUsedFrames < nFrames) {
                frameId = numUsedFrames++;
                pushBottom(lru, frameId); // push to bottom of lru stack
            } else {
                switch (mode) {
                    case LRU:
                    {// find least recently used item --> i.e. top of lru stack.
                        int topFrameId = popTop(lru); // remove top item in lru stack
                        frameId = pageTable[topFrameId].frameNumber; // get the frame id
                        pageTable[topFrameId].valid = false; // mark old frame index as invalid
                        pushBottom(lru, topFrameId); // push the new frame id to bottom of lru stack
                        break;
                    }
                    case LFU: // opposite of LRU --> find items which have been used the least
                    {
                        // find items with min. references (closest to 0)
                        // Grab first valid frame with 0 references, or minimum otherwise
                        int minIndex = 0;
                        int minRefs = INT_MAX;
                        for (int i = 0; i < pageTableSize; i++) {
                            if (pageTable[i].valid) {
                                if (pageTable[i].numReferences == 0) {
                                    minIndex = i;
                                    break;
                                }
                                if (pageTable[i].numReferences < minRefs) {
                                    minRefs = pageTable[i].numReferences;
                                    minIndex = i;
                                }
                            }
                        }
                        pageTable[minIndex].valid = false; // Since used, make invalid
                        frameId = pageTable[minIndex].frameNumber; // update new frame number (frameId)
                        break;
                    }
                    default:
                        break;
                }
            }
            pageTable[pageIndex].frameNumber = frameId; // update frame, and reset staistics
            pageTable[pageIndex].numReferences = 0;
            pageTable[pageIndex].valid = true;
        }
    }

    freeDeque(lru); // free all allocated memory
    freeDeque(traces);
    free(pageTable);

    printf("The number of Page Faults was: %d\n"
           "The number of TLB misses was:  %d\n", numFaults, tlbMisses);

    //getchar();

    return EXIT_SUCCESS;
}
Esempio n. 5
0
void native_haiku_vm_MemoryAccess_setMemory16_IIV() {
	uint16_t      value=  top.s1.i;
	uint16_t *    mem_addr=  (uint16_t *)ipop();
	*mem_addr=value;
	popTop();
}
Esempio n. 6
0
void native_haiku_vm_MemoryAccess_setMemory16_IIV() {
	uint16_t      value=  top.s1.i;
	uint8_t *    mem_addr= &mem[ipop()];
	setMemory16(mem_addr, value);
	popTop();
}