JNIEXPORT jint JNICALL Java_mpi_MPI_InitThread_1jni( JNIEnv *env, jclass clazz, jobjectArray argv, jint required) { jsize i; int len = (*env)->GetArrayLength(env,argv); char **sargs = (char**)calloc(len+1, sizeof(char*)); for(i = 0; i < len; i++) { jstring jc = (jstring)(*env)->GetObjectArrayElement(env, argv, i); const char *s = (*env)->GetStringUTFChars(env, jc, 0); sargs[i] = (char*)calloc(strlen(s) + 1, sizeof(char)); strcpy(sargs[i], s); (*env)->ReleaseStringUTFChars(env, jc, s); (*env)->DeleteLocalRef(env, jc); } int provided; int rc = MPI_Init_thread(&len, &sargs, required, &provided); ompi_java_exceptionCheck(env, rc); findClasses(env); initFreeList(); return provided; }
void LinearScan::allocRegs(Trace* trace) { if (RuntimeOption::EvalHHIREnableCoalescing) { // <coalesce> doesn't need instruction numbering. coalesce(trace); } numberInstructions(trace); collectNatives(trace); computePreColoringHint(); initFreeList(); allocRegsToTraceAux(trace); // Renumber instructions, because we added spills and reloads. numberInstructions(trace); if (RuntimeOption::EvalHHIREnableRematerialization && m_slots.size() > 0) { // Don't bother rematerializing the trace if it has no Spill/Reload. if (RuntimeOption::EvalDumpIR > 5) { std::cout << "--------- HHIR before rematerialization ---------\n"; trace->print(std::cout, false); std::cout << "-------------------------------------------------\n"; } rematerialize(trace); } // assignSpillLoc needs next natives in order to decide whether we // can use MMX registers. collectNatives(trace); // Make sure rsp is 16-aligned. uint32 numSpillLocs = assignSpillLoc(trace); if (numSpillLocs % 2) { ++numSpillLocs; } assert(NumPreAllocatedSpillLocs % 2 == 0); if (numSpillLocs > 0) { preAllocSpillLoc(trace, numSpillLocs); if (numSpillLocs > (uint32)NumPreAllocatedSpillLocs) { /* * We only insert AllocSpill and FreeSpill when the pre-allocated * spill locations are not enough. * * AllocSpill and FreeSpill take the number of extra spill locations * besides the pre-allocated ones. * * TODO(#2044051) AllocSpill/FreeSpill are currently disabled * due to bugs. */ PUNT(LinearScan_AllocSpill); insertAllocFreeSpill(trace, numSpillLocs - NumPreAllocatedSpillLocs); } } numberInstructions(trace); // record the live out register set at each instruction LinearScan::computeLiveOutRegs(trace); }
/* initialize a queue, return a pointer to the queue */ Queue *initQueue() { Queue* queue = (Queue *) malloc (sizeof (Queue)); queue->flist = initFreeList(sizeof(QNode)); // Allocate a dummy item queue->front = queue->back = (QNode*) allocBlock (queue->flist); queue->front->next = queue->front; return queue; }
static void enlargeStablePtrTable(void) { nat old_SPT_size = SPT_size; // 2nd and subsequent times SPT_size *= 2; stable_ptr_table = stgReallocBytes(stable_ptr_table, SPT_size * sizeof(snEntry), "enlargeStablePtrTable"); initFreeList(stable_ptr_table + old_SPT_size, old_SPT_size, NULL); }
void* kma_malloc(kma_size_t size) { if (!INIT) { initFreeList(); INIT = TRUE; } size = roundUp(size); if(diff(size) > 8) return NULL; //larger than 8192 void** entry = FREE_LIST_HEAD + diff(size); if (*entry == NULL) { //allocate a new page and set the whole page same as size return initNewPage(size, entry); } else { //has free buffers return getBuffer(size, entry); } }
JNIEXPORT jobjectArray JNICALL Java_mpi_MPI_Init_1jni( JNIEnv *env, jclass clazz, jobjectArray argv) { jsize i; jclass string; jobject value; int len = (*env)->GetArrayLength(env, argv); char **sargs = (char**)calloc(len+1, sizeof(char*)); for(i = 0; i < len; i++) { jstring jc = (jstring)(*env)->GetObjectArrayElement(env, argv, i); const char *s = (*env)->GetStringUTFChars(env, jc, NULL); sargs[i] = strdup(s); (*env)->ReleaseStringUTFChars(env, jc, s); (*env)->DeleteLocalRef(env, jc); } int rc = MPI_Init(&len, &sargs); ompi_java_exceptionCheck(env, rc); mca_base_var_register("ompi", "mpi", "java", "eager", "Java buffers eager size", MCA_BASE_VAR_TYPE_INT, NULL, 0, 0, OPAL_INFO_LVL_5, MCA_BASE_VAR_SCOPE_READONLY, &ompi_mpi_java_eager); string = (*env)->FindClass(env, "java/lang/String"); value = (*env)->NewObjectArray(env, len, string, NULL); for(i = 0; i < len; i++) { jstring jc = (*env)->NewStringUTF(env, sargs[i]); (*env)->SetObjectArrayElement(env, value, i, jc); (*env)->DeleteLocalRef(env, jc); free (sargs[i]); } free (sargs); findClasses(env); initFreeList(); return value; }
//PAGEBREAK: 32 // Set up first user process. void userinit(void) { struct proc *p; extern char _binary_initcode_start[], _binary_initcode_size[]; #ifdef CS333_SCHEDULER acquire(&ptable.lock); initFreeList(); ptable.timeToReset = COUNT; release(&ptable.lock); #endif p = allocproc(); initproc = p; if((p->pgdir = setupkvm()) == 0) panic("userinit: out of memory?"); inituvm(p->pgdir, _binary_initcode_start, (int)_binary_initcode_size); p->sz = PGSIZE; memset(p->tf, 0, sizeof(*p->tf)); p->tf->cs = (SEG_UCODE << 3) | DPL_USER; p->tf->ds = (SEG_UDATA << 3) | DPL_USER; p->tf->es = p->tf->ds; p->tf->ss = p->tf->ds; p->tf->eflags = FL_IF; p->tf->esp = PGSIZE; p->tf->eip = 0; // beginning of initcode.S p->uid = USERID; p->gid = GROUPID; safestrcpy(p->name, "initcode", sizeof(p->name)); p->cwd = namei("/"); p->state = RUNNABLE; #ifdef CS333_SCHEDULER acquire(&ptable.lock); int i; for (i = 0; i < 3; ++i) { ptable.readyList[i] = 0; } putOnReadyList(p, p->priority); release(&ptable.lock); #endif }
void initStablePtrTable(void) { if (SPT_size > 0) return; SPT_size = INIT_SPT_SIZE; stable_ptr_table = stgMallocBytes(SPT_size * sizeof(snEntry), "initStablePtrTable"); /* we don't use index 0 in the stable name table, because that * would conflict with the hash table lookup operations which * return NULL if an entry isn't found in the hash table. */ initFreeList(stable_ptr_table+1,INIT_SPT_SIZE-1,NULL); addrToStableHash = allocHashTable(); #ifdef THREADED_RTS initMutex(&stable_mutex); #endif }
//locates the first available block that is free and can fit the sizeT requested void *findFirstFit(size_t sizeT) { size_t newSize; struct block *current = head; while(current != NULL) { if(current->isFree == true && current->size >= sizeT) { newSize = (current->size - sizeT); current->size = sizeT; current->isFree = false; current->isLast = false; current->next = initFreeList(newSize, current); return current->memPtr; } current = current->next; } return NULL; }
JNIEXPORT jobjectArray JNICALL Java_mpi_MPI_Init_1jni( JNIEnv *env, jclass clazz, jobjectArray argv) { jsize i; jclass string; jobject value; int len = (*env)->GetArrayLength(env, argv); char **sargs = (char**)calloc(len+1, sizeof(char*)); for(i = 0; i < len; i++) { jstring jc = (jstring)(*env)->GetObjectArrayElement(env, argv, i); const char *s = (*env)->GetStringUTFChars(env, jc, NULL); sargs[i] = (char*)calloc(strlen(s) + 1, sizeof(char)); strcpy(sargs[i], s); (*env)->ReleaseStringUTFChars(env, jc, s); (*env)->DeleteLocalRef(env, jc); } int rc = MPI_Init(&len, &sargs); ompi_java_exceptionCheck(env, rc); string = (*env)->FindClass(env, "java/lang/String"); value = (*env)->NewObjectArray(env, len, string, NULL); for(i = 0; i < len; i++) { jstring jc = (*env)->NewStringUTF(env, sargs[i]); (*env)->SetObjectArrayElement(env, value, i, jc); (*env)->DeleteLocalRef(env, jc); } findClasses(env); initFreeList(); return value; }
jint JNI_OnLoad(JavaVM *vm, void *reserved) { /* These are the equivalences between the Java and C types. */ if( sizeof(jbyte) != sizeof(char) || sizeof(jshort) != sizeof(int16_t) || sizeof(jint) != sizeof(int32_t) || sizeof(jlong) != sizeof(int64_t)) { fprintf(stderr, "C types not match with Java.\n"); exit(1); } liboshmem = dlopen("liboshmem." OPAL_DYN_LIB_SUFFIX, RTLD_NOW | RTLD_GLOBAL); if(liboshmem == NULL) { fprintf(stderr, "Java bindings failed to load liboshmem: %s\n",dlerror()); exit(1); } initFreeList(); return JNI_VERSION_1_6; }
/////////////////////////////////////////////////////////////////////////// // initialize the cluster list /////////////////////////////////////////////////////////////////////////// void initClusterList() { theList = initFreeList(sizeof(clusterNode)); }