int main(int argc, char **argv) { #if ENABLE_PCSL pcsl_mem_initialize(NULL, 0); #endif // Call this before any other Jvm_ functions. JVM_Initialize(); // Ignore arg[0] -- the name of the program. argc --; argv ++; while (true) { int n = JVM_ParseOneArg(argc, argv); if (n < 0) { JVMSPI_DisplayUsage(NULL); return -1; } else if (n == 0) { break; } argc -= n; argv += n; } int rv; if (JVM_GetConfig(JVM_CONFIG_SLAVE_MODE) == KNI_FALSE) { // Run the VM in regular mode -- JVM_Start won't return until // the VM completes execution. rv = JVM_Start(NULL, NULL, argc, argv); } else { JVM_Start(NULL, NULL, argc, argv); for (;;) { jlong timeout = JVM_TimeSlice(); if (timeout <= ((jlong)-2)) { break; } else { int blocked_threads_count; JVMSPI_BlockedThreadInfo * blocked_threads; blocked_threads = SNI_GetBlockedThreads(&blocked_threads_count); JVMSPI_CheckEvents(blocked_threads, blocked_threads_count, timeout); } } rv = JVM_CleanUp(); } printf("ADSEXITCODE=%d\n", rv); #if ENABLE_PCSL pcsl_mem_finalize(); #endif return rv; }
/** * Runs the VM in either master or slave mode depending on the * platform. It does not return until the VM is finished. In slave mode * it will contain a system event loop. * * @param classPath string containing the class path * @param mainClass string containing the main class for the VM to run. * @param argc the number of arguments to pass to the main method * @param argv the arguments to pass to the main method * * @return exit status of the VM */ int midpRunVm(JvmPathChar* classPath, char* mainClass, int argc, char** argv) { /* Master mode does not need VM time slice requests. */ midp_thread_set_timeslice_proc(NULL); return JVM_Start(classPath, mainClass, argc, argv); }
/* * We can't run the VM in the main thread (because it has to handle events). * So we run the VM in this thread. */ static DWORD WINAPI vm_thread_routine(LPVOID lpvParam) { // Print arguments that we are using JVMSPI_PrintRaw("Running VM"); JVMSPI_PrintRaw("\n"); for (int i = 1; i < _argc; i++) { JVMSPI_PrintRaw(" "); JVMSPI_PrintRaw(_argv[i]); JVMSPI_PrintRaw("\n"); } // Call this before any other Jvm_ functions. JVM_Initialize(); int argc = _argc; char ** argv = _argv; // Ignore arg[0] -- the name of the program. argc --; argv ++; while (true) { int n = JVM_ParseOneArg(argc, argv); if (n < 0) { JVMSPI_DisplayUsage(NULL); return -1; } else if (n == 0) { break; } argc -= n; argv += n; } if (LogConsole) { write_console("Console output logged at \n"); write_console(logfilename); write_console("\n"); for (int index=0; index<_argc; index++) { log_console(_argv[index]); log_console(" "); } log_console("\n"); } if (!WriteConsole) { write_console("On-screen console output disabled.\n"); } int code = JVM_Start(NULL, NULL, argc, argv); JVMSPI_Exit(code); SHOULD_NOT_REACH_HERE(); return 0; }
void FOX_FASTCALL(midp_check_events)(jlonglong timeout) { #else void midp_check_events(JVMSPI_BlockedThreadInfo *blocked_threads, int blocked_threads_count, jlong timeout) { if (midp_waitWhileSuspended()) { /* System has been requested to resume. Returning control to VM * to perform java-side resume routines. Timeout may be too long * here or even -1, thus do not check other events this time. */ return; } #endif newSignal.waitingFor = NO_SIGNAL; newSignal.pResult = ADDR_ZERO; MIDP_EVENT_INITIALIZE(newMidpEvent); checkForSystemSignal(&newSignal, &newMidpEvent, timeout); switch (newSignal.waitingFor) { #if ENABLE_JAVA_DEBUGGER case VM_DEBUG_SIGNAL: if (midp_isDebuggerActive()) { JVM_ProcessDebuggerCmds(); } break; #endif // ENABLE_JAVA_DEBUGGER case AMS_SIGNAL: midpStoreEventAndSignalAms(newMidpEvent); break; case UI_SIGNAL: midpStoreEventAndSignalForeground(newMidpEvent); break; case NETWORK_READ_SIGNAL: #ifdef FEATURE_PHONEME FASTIVA_DBREAK(); #else if (eventUnblockJavaThread(blocked_threads, blocked_threads_count, newSignal.waitingFor, newSignal.descriptor, newSignal.status)) /* Processing is done in eventUnblockJavaThread. */; else if (findPushBlockedHandle(newSignal.descriptor) != 0) { /* The push system is waiting for a read on this descriptor */ midp_thread_signal_list(blocked_threads, blocked_threads_count, PUSH_SIGNAL, 0, 0); } #endif #if (ENABLE_JSR_120 || ENABLE_JSR_205) else jsr120_check_signal(newSignal.waitingFor, newSignal.descriptor); #endif break; case HOST_NAME_LOOKUP_SIGNAL: case NETWORK_WRITE_SIGNAL: #if (ENABLE_JSR_120 || ENABLE_JSR_205) if (!jsr120_check_signal(newSignal.waitingFor, newSignal.descriptor)) #endif #ifdef FEATURE_PHONEME FASTIVA_DBREAK(); #else midp_thread_signal_list(blocked_threads, blocked_threads_count, newSignal.waitingFor, newSignal.descriptor, newSignal.status); #endif break; case NETWORK_EXCEPTION_SIGNAL: #ifdef FEATURE_PHONEME FASTIVA_DBREAK(); #else /* Find both the read and write threads and signal the status. */ eventUnblockJavaThread(blocked_threads, blocked_threads_count, NETWORK_READ_SIGNAL, newSignal.descriptor, newSignal.status); eventUnblockJavaThread(blocked_threads, blocked_threads_count, NETWORK_WRITE_SIGNAL, newSignal.descriptor, newSignal.status); #endif return; case PUSH_ALARM_SIGNAL: #ifdef FEATURE_PHONEME FASTIVA_DBREAK(); #else if (findPushTimerBlockedHandle(newSignal.descriptor) != 0) { /* The push system is waiting for this alarm */ midp_thread_signal_list(blocked_threads, blocked_threads_count, PUSH_SIGNAL, 0, 0); } #endif break; #if (ENABLE_JSR_135 || ENABLE_JSR_234) case MEDIA_EVENT_SIGNAL: StoreMIDPEventInVmThread(newMidpEvent, newMidpEvent.MM_ISOLATE); eventUnblockJavaThread(blocked_threads, blocked_threads_count, MEDIA_EVENT_SIGNAL, newSignal.descriptor, newSignal.status); break; case MEDIA_SNAPSHOT_SIGNAL: eventUnblockJavaThread(blocked_threads, blocked_threads_count, MEDIA_SNAPSHOT_SIGNAL, newSignal.descriptor, newSignal.status); break; #endif #ifdef ENABLE_JSR_179 case JSR179_LOCATION_SIGNAL: midp_thread_signal_list(blocked_threads, blocked_threads_count, JSR179_LOCATION_SIGNAL, newSignal.descriptor, newSignal.status); break; #endif /* ENABLE_JSR_179 */ #if (ENABLE_JSR_120 || ENABLE_JSR_205) case WMA_SMS_READ_SIGNAL: case WMA_CBS_READ_SIGNAL: case WMA_MMS_READ_SIGNAL: case WMA_SMS_WRITE_SIGNAL: case WMA_MMS_WRITE_SIGNAL: jsr120_check_signal(newSignal.waitingFor, newSignal.descriptor); break; #endif #ifdef ENABLE_JSR_177 case CARD_READER_DATA_SIGNAL: midp_thread_signal_list(blocked_threads, blocked_threads_count, newSignal.waitingFor, newSignal.descriptor, newSignal.status); break; #endif /* ENABLE_JSR_177 */ default: break; } /* switch */ } /** * Runs the VM in either master or slave mode depending on the * platform. It does not return until the VM is finished. In slave mode * it will contain a system event loop. * * @param classPath string containing the class path * @param mainClass string containing the main class for the VM to run. * @param argc the number of arguments to pass to the main method * @param argv the arguments to pass to the main method * * @return exit status of the VM */ #if 0 int midpRunVm(JvmPathChar* classPath, char* mainClass, int argc, char** argv) { /* Master mode does not need VM time slice requests. */ midp_thread_set_timeslice_proc(ADDR_ZERO); return JVM_Start(classPath, mainClass, argc, argv); }
int main(int argc, char **argv) { int code = 0; #if ENABLE_PCSL pcsl_mem_initialize(NULL, 0); #endif // Call this before any other Jvm_ functions. JVM_Initialize(); // Ignore arg[0] -- the name of the program. argc --; argv ++; while (true) { int n = JVM_ParseOneArg(argc, argv); if (n < 0) { printf("Unknown argument: %s\n", argv[0]); JVMSPI_DisplayUsage(NULL); code = -1; goto end; } else if (n == 0) { break; } argc -= n; argv += n; } if (JVM_GetConfig(JVM_CONFIG_SLAVE_MODE) == KNI_FALSE) { // Run the VM in regular mode -- JVM_Start won't return until // the VM completes execution. code = JVM_Start(NULL, NULL, argc, argv); } else { // Run the VM in slave mode -- we keep calling JVM_TimeSlice(), // which executes bytecodes for a small amount and returns. This // mode is necessary for platforms that need to keep the main // control loop outside of of the VM. // // Note that this mode is not necessary on Win32. We do it here // just as a demo. JVM_Start(NULL, NULL, argc, argv); for (;;) { jlong timeout = JVM_TimeSlice(); if (timeout <= -2) { break; } else { int blocked_threads_count; JVMSPI_BlockedThreadInfo * blocked_threads; blocked_threads = SNI_GetBlockedThreads(&blocked_threads_count); JVMSPI_CheckEvents(blocked_threads, blocked_threads_count, timeout); } } code = JVM_CleanUp(); } end: #if ENABLE_PCSL pcsl_mem_finalize(); #endif return code; }