/**
 * 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 */
}
示例#2
0
/**
 * Reads named property with heap size parameter and returns it in bytes.
 * When the property is not found provided default value is used instead.
 *
 * @param propertyName name of heap size property
 * @param defaultValue default value for the case of missing property
 * @return size value in bytes
 */
static int getHeapSizeProperty(const char *propertyName, int defaultValue) {

    int value;
    value = getInternalPropertyInt(propertyName);
    if (0 == value) {
        REPORT_WARN1(LC_AMS, "%s property not set", propertyName);
        value = defaultValue;
    }
    /* Check overflow */
    value = (value < 0 || value > 0x200000) ?
        0x7FFFFFFF /* MAX_INT */ :
        value * 1024;
    return value;
}
/**
 * Helper function to read memory parameters and initialize memory
 *
 * @return JAVACALL_OK if memory successfully initialized
 */
static javacall_result
initialize_memory_slavemode(void) {
    int main_memory_chunk_size;

    /* Get java heap memory size */
    main_memory_chunk_size = getInternalPropertyInt("MAIN_MEMORY_CHUNK_SIZE");
    if (0 == main_memory_chunk_size){
        REPORT_ERROR(LC_AMS, "javanotify_start(): Missing MAIN_MEMORY_CHUNK_SIZE property."
                      "System will exit!\n");
        main_memory_chunk_size = DEFAULT_MEMORY_CHUNK_SIZE;
        return JAVACALL_FAIL;
    }

    /* Initialize midp memory pool */
    if (midpInitializeMemory(main_memory_chunk_size) != 0) {
        REPORT_ERROR(LC_AMS, "javanotify_start(): Cannot initialize MIDP memory\n");
        return JAVACALL_OUT_OF_MEMORY;
    }

    return JAVACALL_OK;
}
示例#4
0
/**
 * Reads JAVA_HEAP_SIZE property and returns it as required heap size.
 * If JAVA_HEAP_SIZE has not been found, then reads MAX_ISOLATES property,
 * calculates and returns size of the required heap. If the MAX_ISOLATES
 * has not been found, default heap size is returned.
 *
 * @return <tt>heap size</tt>
 */
 int getHeapRequirement() {
    int maxIsolates;
    int midpHeapRequirement;

    midpHeapRequirement = getInternalPropertyInt("JAVA_HEAP_SIZE");
    if (midpHeapRequirement > 0) {
        return midpHeapRequirement;
    }

    maxIsolates = getMaxIsolates();

    /*
     * Calculate heap size.
     *
     * IMPL_NOTE: bellow ENABLE_NATIVE_APP_MANAGER value is checked instead of
     * moving this part into a separate library
     * (for ex., ams/example/ams_parameters)
     * because currently amount of memory needed for AMS isolate is the only
     * property that has different values for JAMS and NAMS. If new such values
     * are added, a new library should be introduced.
     */
#if ENABLE_NATIVE_APP_MANAGER
    /*
     * Actually, when using NAMS, AMS isolate requires less then 1024K memory,
     * so the value bellow can be tuned for each particular project.
     */
    midpHeapRequirement = maxIsolates * 1024 * 1024;
#else
    /*
     * In JAMS AMS isolate requires a little bit more memory because
     * it holds skin images that are shared among all isolates.
     */
    midpHeapRequirement = 1280 * 1024 + (maxIsolates - 1) * 1024 * 1024;
#endif

    return midpHeapRequirement;
}
/**
 * An entry point of a thread devoted to run java
 */
void JavaTask(void) {
    midp_jc_event_union event;
    javacall_bool res = JAVACALL_OK;
    javacall_bool JavaTaskIsGoOn = JAVACALL_TRUE;
    long timeTowaitInMillisec = -1;
    int outEventLen;
    int main_memory_chunk_size;

    /* Get java heap memory size */
    main_memory_chunk_size = getInternalPropertyInt("MAIN_MEMORY_CHUNK_SIZE");
    if (main_memory_chunk_size == 0) {
	main_memory_chunk_size = -1;
    }

    /* Outer Event Loop */
    while (JavaTaskIsGoOn) {

        if (midpInitializeMemory(main_memory_chunk_size) != 0) {
            REPORT_CRIT(LC_CORE,"JavaTask() >> midpInitializeMemory()  Not enough memory.\n");
            break;
        }
        REPORT_INFO(LC_CORE,"JavaTask() >> memory initialized.\n");

#if !ENABLE_CDC
        res = javacall_event_receive(timeTowaitInMillisec,
            (unsigned char *)&event, sizeof(midp_jc_event_union), &outEventLen);
#else
        res = javacall_event_receive_cvm(MIDP_EVENT_QUEUE_ID,
            (unsigned char *)&event, sizeof(midp_jc_event_union), &outEventLen);
#endif

        if (!JAVACALL_SUCCEEDED(res)) {
            REPORT_ERROR(LC_CORE,"JavaTask() >> Error javacall_event_receive()\n");
            continue;
        }

        switch (event.eventType) {
        case MIDP_JC_EVENT_START_ARBITRARY_ARG:
            REPORT_INFO(LC_CORE, "JavaTask() MIDP_JC_EVENT_START_ARBITRARY_ARG >>\n");
            javacall_lifecycle_state_changed(JAVACALL_LIFECYCLE_MIDLET_STARTED,
                                             JAVACALL_OK,
                                             NULL);
            JavaTaskImpl(event.data.startMidletArbitraryArgEvent.argc,
                         event.data.startMidletArbitraryArgEvent.argv);

            JavaTaskIsGoOn = JAVACALL_FALSE;
            break;

        case MIDP_JC_EVENT_SET_VM_ARGS:
            REPORT_INFO(LC_CORE, "JavaTask() MIDP_JC_EVENT_SET_VM_ARGS >>\n");
            midpHandleSetVmArgs(event.data.startMidletArbitraryArgEvent.argc,
                                event.data.startMidletArbitraryArgEvent.argv);
            break;

        case MIDP_JC_EVENT_SET_HEAP_SIZE:
            REPORT_INFO(LC_CORE, "JavaTask() MIDP_JC_EVENT_SET_HEAP_SIZE >>\n");
            midpHandleSetHeapSize(event.data.heap_size);
            break;

        case MIDP_JC_EVENT_LIST_MIDLETS:
            REPORT_INFO(LC_CORE, "JavaTask() MIDP_JC_EVENT_LIST_MIDLETS >>\n");
            midpHandleListMIDlets();
            JavaTaskIsGoOn = JAVACALL_FALSE;
            break;

        case MIDP_JC_EVENT_LIST_STORAGE_NAMES:
            REPORT_INFO(LC_CORE, "JavaTask() MIDP_JC_EVENT_LIST_STORAGE_NAMES >>\n");
            midpHandleListStorageNames();
            JavaTaskIsGoOn = JAVACALL_FALSE;
            break;

        case MIDP_JC_EVENT_REMOVE_MIDLET:
            REPORT_INFO(LC_CORE, "JavaTask() MIDP_JC_EVENT_REMOVE_MIDLET >>\n");
            midpHandleRemoveMIDlet(event.data.removeMidletEvent);
            JavaTaskIsGoOn = JAVACALL_FALSE;
            break;


        case MIDP_JC_EVENT_END:
            REPORT_INFO(LC_CORE,"JavaTask() >> MIDP_JC_EVENT_END\n");
            JavaTaskIsGoOn = JAVACALL_FALSE;
            break;

        default:
            REPORT_ERROR(LC_CORE,"Unknown event.\n");
            break;

        } /* end of switch */

        midpFinalizeMemory();

    }   /* end of while 'JavaTaskIsGoOn' */

} /* end of JavaTask */
示例#6
0
    /**
    * Gets the severity per channel using the property mechanism.
    */
int get_allowed_severity_c(int channelID) {
    
    switch(channelID) {
        case LC_NONE:
            return(getInternalPropertyInt("NONE"));  
        case LC_AMS:
            return(getInternalPropertyInt("AMS"));
        case LC_CORE:
            return(getInternalPropertyInt("CORE"));
        case LC_LOWUI:
            return(getInternalPropertyInt("LOWUI"));
        case LC_HIGHUI:
            return(getInternalPropertyInt("HIGHUI"));
        case LC_PROTOCOL:
            return(getInternalPropertyInt("PROTOCOL"));
        case LC_RMS:
            return(getInternalPropertyInt("RMS"));
        case LC_SECURITY:
            return(getInternalPropertyInt("SECURITY"));
        case LC_SERVICES:
            return(getInternalPropertyInt("SERVICES"));
        case LC_STORAGE:
            return(getInternalPropertyInt("STORAGE"));
        case LC_PUSH:
            return(getInternalPropertyInt("PUSH"));
        case LC_MMAPI:
            return(getInternalPropertyInt("MMAPI"));
        case LC_LIFECYCLE:
            return(getInternalPropertyInt("LIFECYCLE"));
        case LC_MIDPSTRING:
            return(getInternalPropertyInt("MIDPSTRING"));
        case LC_MALLOC:
            return(getInternalPropertyInt("MALLOC"));
        case LC_CORE_STACK:
            return(getInternalPropertyInt("CORE_STACK"));   
        case LC_I18N:
            return(getInternalPropertyInt("I18N"));
        case LC_HIGHUI_ITEM_LAYOUT:
            return(getInternalPropertyInt("HIGHUI_ITEM_LAYOUT"));
        case LC_HIGHUI_ITEM_REPAINT:
            return(getInternalPropertyInt("HIGHUI_ITEM_REPAINT"));
        case LC_HIGHUI_FORM_LAYOUT:
            return(getInternalPropertyInt("HIGHUI_FORM_LAYOUT"));
        case LC_HIGHUI_ITEM_PAINT:
            return(getInternalPropertyInt("HIGHUI_ITEM_PAINT"));      
        case LC_TOOL:
            return(getInternalPropertyInt("TOOL"));
        case LC_JSR180:
            return(getInternalPropertyInt("JSR180"));
        case LC_JSR290:
            return(getInternalPropertyInt("JSR290"));
        case LC_EVENTS:
            return(getInternalPropertyInt("EVENTS"));

        default: 
            return(LOG_DISABLED);
    }

}