midp_run.c
来自「This is a resource based on j2me embedde」· C语言 代码 · 共 1,116 行 · 第 1/3 页
C
1,116 行
/* * * * Copyright 1990-2008 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License version * 2 only, as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License version 2 for more details (a copy is * included at /legal/license.txt). * * You should have received a copy of the GNU General Public License * version 2 along with this work; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA * * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa * Clara, CA 95054 or visit www.sun.com if you need additional * information or have any questions. */#include <string.h>#include <jvmconfig.h>#include <kni.h>#include <jvm.h>#include <jvmspi.h>#include <sni.h>#include <pcsl_print.h>#include <pcsl_memory.h>#include <midpAMS.h>#include <midpInit.h>#include <midpMalloc.h>#include <midpCommandState.h>#include <midpStorage.h>#include <midpServices.h>#include <midp_properties_port.h>#include <midpTimeZone.h>#include <midp_logging.h>#include <midp_properties_port.h>#include <midpMIDletProxyList.h>#include <midpEvents.h>#include <suitestore_task_manager.h>#include <midpError.h>#include <midp_run_vm.h>#include <midp_check_events.h>#include <midpMidletSuiteUtils.h>#if (ENABLE_JSR_205 || ENABLE_JSR_120)#include <jsr120_types.h>#include <wmaInterface.h>#endif#include <lcdlf_export.h>#include <midpUtilKni.h>#include <push_server_export.h>#if !ENABLE_CDC#include <suspend_resume.h>#endif#include <stdio.h>#include <stdlib.h>/** * @file * * Platform-specific VM startup and shutdown routines. * * This file provides platform-specific virtual machine * startup and shutdown routines. Refer to file * "/src/vm/share/runtime/JVM.hpp" and the Porting * Guide for details. *//** * @def MAX_VM_PROFILE_LEN * Maximal length of the VM profile name. */#define MAX_VM_PROFILE_LEN 256/** * @def ROTATION_ARG * Name of the system property with initial screen rotation mode. * The property can be set to 1 for rotated mode, any other value * is ignored and normal screen mode is used. */#define ROTATION_ARG "rotation"static JvmPathChar getCharPathSeparator();static MIDP_ERROR getClassPathPlus(SuiteIdType storageName, JvmPathChar** userClassPath, char* classPathExt);#if VERIFY_ONCEstatic MIDP_ERROR getClassPathForVerifyOnce( JvmPathChar** classPath, SuiteIdType suiteId, const pcsl_string* midletName, const pcsl_string* jarPath);#endif#if (REPORT_LEVEL <= LOG_INFORMATION) && !ENABLE_CONTROL_ARGS_FROM_JAD#define STACK_SIZE 8192/* Stack grows down */void measureStack(int clearStack) { char stack[STACK_SIZE]; char tag = (char)0xef; int i; if (clearStack) { for (i = 0; i < STACK_SIZE; i++) { stack[i] = tag; } } else { for (i = 0; i < STACK_SIZE; i++) { if (stack[i] != tag) { reportToLog(LOG_INFORMATION, LC_CORE_STACK, "Max Native Stack Size: %d", (STACK_SIZE - i)); break; } } }}#undef STACK_SIZE#elsevoid measureStack(int clearStack) { (void)clearStack; return;}#endif#if 0void monitorHeap() { static const int EXPECTED_HEAP_DELTA = 256; /* bytes */ /* Remember initial free heap size */ static int firstHeap = 0; /* Compare free memory before each VM run, to detect memory leak */ int currentHeap = midpGetFreeHeap(); if (firstHeap == 0) { firstHeap = currentHeap; } else if (firstHeap - currentHeap > EXPECTED_HEAP_DELTA) { printf("Possible memory leak between VM runs : %d", firstHeap - currentHeap); }}#else#define monitorHeap()#endif#if ENABLE_MONET/** * Convert Java classes to Monet bundle (In-Place Execution format) * upon the first run of a newly installed MIDletSuite. * * @param userClassPath pointer to current classpath string. */static void setMonetClassPath(JvmPathChar **userClassPath, int pathLen) { if (*userClassPath != NULL && pathLen > 0 && (*userClassPath)[pathLen - 4] == (JvmPathChar)'.' && (*userClassPath)[pathLen - 3] == (JvmPathChar)'j' && (*userClassPath)[pathLen - 2] == (JvmPathChar)'a' && (*userClassPath)[pathLen - 1] == (JvmPathChar)'r') { int i; int j; pcsl_string uBinFile = PCSL_STRING_NULL; int errorcode;#ifdef PRODUCT char* suffix = ".bun";#elif defined(AZZERT) char* suffix = "_g.bun";#else char* suffix = "_r.bun";#endif int suffixLen = strlen(suffix); /* add the new suffix, but don't include ".jar" */ int binNameLen = pathLen - 4 + suffixLen; JvmPathChar *binFile = (JvmPathChar*)midpMalloc( (binNameLen + 1) * sizeof (JvmPathChar)); /* * JvmPathChars can be either 16 bits or 8 bits so we can't * assume either. */ memcpy(binFile, *userClassPath, pathLen * sizeof (JvmPathChar)); /* replace the ".jar" with a new suffix */ for (i = pathLen - 4, j = 0; j < suffixLen; i++, j++) { binFile[i] = (JvmPathChar)suffix[j]; } binFile[i] = 0; ASSERT(sizeof(JvmPathChar) == sizeof(jchar)); /* * Assuming that JvmPathChar is 16-bit (jchar): this is always true if * CLDC is based on PCSL. * In other case (which shouldn't happen) build error "Incompatible * pointer types" will occur. Then the following code should be used * instead of simple conversion from UTF-16: * * if (sizeof(JvmPathChar) == 1) { * pcsl_string_convert_from_utf8(binFile, i, &uBinFile); * } else { * pcsl_string_convert_from_utf16(binFile, i, &uBinFile); * } */ pcsl_string_convert_from_utf16(binFile, i, &uBinFile); /* IMPL_NOTE: can we do anything meaningful in case of out-of-memory? */ /* If Monet bundle file does not exist, convert now */ if (storage_file_exists(&uBinFile) == 0) { errorcode = JVM_CreateAppImage(*userClassPath, binFile, JVM_REMOVE_CLASSES_FROM_JAR); } else { errorcode = 0; } /* Once we have monet bundle, we set classpath to be: * <monet_bundle>:<original_jar> * The original jar is still needed because it may still * contain resource files. */ if (errorcode == 0) { /* binary file + separator + jar file + terminator */ int newPathLen = binNameLen + 1 + pathLen + 1; JvmPathChar *newPath = (JvmPathChar*)midpMalloc(newPathLen * sizeof (JvmPathChar)); int j; for (i = 0; i < binNameLen; i++) { newPath[i] = binFile[i]; } newPath[i] = getCharPathSeparator(); i++; for (j = 0; j < pathLen; i++, j++) { newPath[i] = (*userClassPath)[j]; } newPath[i] = 0; midpFree(*userClassPath); *userClassPath = newPath; } pcsl_string_free(&uBinFile); midpFree(binFile); }}#else#define setMonetClassPath(x, y)#endif/** The name of the runtime main internal class. */#define MIDP_MAIN "com.sun.midp.main.MIDletSuiteLoader"char*JVMSPI_GetSystemProperty(const char* prop_name) { char *result = (char *)getSystemProperty(prop_name); if (result == NULL && prop_name != NULL) { if (strcmp(prop_name, TIMEZONE_PROP_NAME) == 0) { /* Get the local timezone from the native platform */ result = getLocalTimeZone(); } } return result;}voidJVMSPI_SetSystemProperty(const char* propName, const char* value) { /* * override internal configuration parameters. */ setInternalProperty(propName, value); /* * Also override System.getProperty() for backward compatibility * with CLDC uses of property vales. */ setSystemProperty(propName, value);}voidJVMSPI_FreeSystemProperty(const char* prop_value) { (void)prop_value; /* No-op */}voidJVMSPI_DisplayUsage(char* message) { (void)message; /* No-op */}jbooleanJVMSPI_CheckExit(void) { return KNI_FALSE; /* Never allow System.exit() to succeed */}voidJVMSPI_Exit(int code) { midpFinalize(); exit(code);}/** * This function is called by the VM periodically. It has to check if * any of the blocked threads are ready for execution, and call * SNI_UnblockThread() on those threads that are ready. * * @param blocked_threads Array of blocked threads * @param blocked_threads_count Number of threads in the blocked_threads array * @param timeout Values for the paramater: * >0 = Block until an event happens, or until <timeout> * milliseconds has elapsed. * 0 = Check the events sources but do not block. Return to the * caller immediately regardless of the status of the event * sources. * -1 = Do not timeout. Block until an event happens. */void JVMSPI_CheckEvents(JVMSPI_BlockedThreadInfo *blocked_threads, int blocked_threads_count, jlong timeout) { midp_check_events(blocked_threads, blocked_threads_count, timeout);}#if ENABLE_JAVA_DEBUGGERvoidJVMSPI_DebuggerNotification(jboolean is_active) { /* Avoid a compiler warning. */ (void)is_active; return;}#endif/** * This function provides an implementation * used by the logging service, as well as by the * Java system output streams (System.out.println(), etc.) * * @param s a string sent to a system specific output stream */void JVMSPI_PrintRaw(const char* s) { pcsl_print(s);}/** * Initializes the AMS. */static voidmidpInitializeAMS(void) { /* * Set AMS memory limits */#if ENABLE_MULTIPLE_ISOLATES { int reserved; int limit;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?