/** * Get maximal allowed number of isolates in the case of MVM mode. * For SVM, simply return 1. */ int getMaxIsolates() { #if ENABLE_MULTIPLE_ISOLATES static int midpMaxIsolates = 0; if (midpMaxIsolates == 0) { int jvmMaxIsolates = JVM_MaxIsolates(); midpMaxIsolates = getInternalPropertyInt("MAX_ISOLATES"); if (0 == midpMaxIsolates) { REPORT_INFO(LC_AMS, "MAX_ISOLATES property not set"); midpMaxIsolates = MAX_ISOLATES; } if (midpMaxIsolates > jvmMaxIsolates){ REPORT_WARN1(LC_AMS, "MAX_ISOLATES exceeds VM limit %d, decreased", jvmMaxIsolates); midpMaxIsolates = jvmMaxIsolates; } setMaxIsolates(midpMaxIsolates); } return midpMaxIsolates; #else return 1; #endif /* ENABLE_MULTIPLE_ISOLATES */ }
/** * Initializes the event system. * <p> * <b>NOTE:</b> The event system must be explicitly initialize so the * VM can shutdown and restart cleanly. * * @return 0 for success, or non-zero if the MIDP implementation is * out of memory */ int InitializeEvents(void) { int sizeInBytes; if (NULL != pEventQueues) { /* already done */ return 0; } #if ENABLE_MULTIPLE_ISOLATES maxIsolates = JVM_MaxIsolates(); #endif sizeInBytes = maxIsolates * sizeof (EventQueue); pEventQueues = midpMalloc(sizeInBytes); if (NULL == pEventQueues) { return -1; } memset(pEventQueues, 0, sizeInBytes); midp_createEventQueueLock(); return 0; }
/** * Shutdowns Links subsystem. */ void midp_links_shutdown() { if (portals != NULL) { int i; for (i = 0; i < JVM_MaxIsolates(); i++) { portal_free(&portals[i]); } pcsl_mem_free(portals); portals = NULL; } }
/** * private static native void setLinks0(int isolateid, Link[] linkarray); */ KNIEXPORT KNI_RETURNTYPE_VOID Java_com_sun_midp_links_LinkPortal_setLinks0(void) { int targetIsolate; int len; int i; int ok = 1; rendezvous *rp; rendezvous **newrppa = NULL; KNI_StartHandles(2); KNI_DeclareHandle(linkArray); KNI_DeclareHandle(linkObj); targetIsolate = KNI_GetParameterAsInt(1); KNI_GetParameterAsObject(2, linkArray); if (KNI_IsNullHandle(linkArray)) { len = 0; } else { len = KNI_GetArrayLength(linkArray); } for (i = 0; i < len; i++) { KNI_GetObjectArrayElement(linkArray, i, linkObj); rp = getNativePointer(linkObj); if (rp == NULL || rp->state == CLOSED) { ok = 0; KNI_ThrowNew(midpIllegalArgumentException, NULL); break; } } if (ok && portals == NULL) { portals = (portal *)pcsl_mem_malloc(JVM_MaxIsolates() * sizeof(portal)); if (portals == NULL) { ok = 0; KNI_ThrowNew(midpOutOfMemoryError, NULL); } else { int i; for (i = 0; i < JVM_MaxIsolates(); i++) { portals[i].count = -1; portals[i].rppa = NULL; } } } if (ok && len > 0) { newrppa = (rendezvous **)pcsl_mem_malloc(len * sizeof(rendezvous *)); if (newrppa == NULL) { KNI_ThrowNew(midpOutOfMemoryError, NULL); ok = 0; } } if (ok) { portal *pp = &portals[targetIsolate]; portal_free(pp); /* at this point the portal's count is zero and rppa is null */ if (len > 0) { for (i = 0; i < len; i++) { KNI_GetObjectArrayElement(linkArray, i, linkObj); rp = getNativePointer(linkObj); /* rp not null, checked above */ newrppa[i] = rp; rp_incref(rp); } pp->count = len; pp->rppa = newrppa; } else if (KNI_IsNullHandle(linkArray)) { pp->count = -1; pp->rppa = NULL; } else { /* len == 0 */ pp->count = 0; pp->rppa = NULL; } midp_thread_signal(LINK_PORTAL_SIGNAL, targetIsolate, 0); } KNI_EndHandles(); KNI_ReturnVoid(); }