int main(int argc, char *argv[]) { Class *array_class, *main_class; Object *system_loader, *array; MethodBlock *mb; InitArgs args; int class_arg; char *cpntr; int status; int i; setDefaultInitArgs(&args); class_arg = parseCommandLine(argc, argv, &args); args.main_stack_base = &array_class; if(!initVM(&args)) { printf("Could not initialise VM. Aborting.\n"); exit(1); } if((system_loader = getSystemClassLoader()) == NULL) goto error; mainThreadSetContextClassLoader(system_loader); for(cpntr = argv[class_arg]; *cpntr; cpntr++) if(*cpntr == '.') *cpntr = '/'; main_class = findClassFromClassLoader(argv[class_arg], system_loader); if(main_class != NULL) initClass(main_class); if(exceptionOccurred()) goto error; mb = lookupMethod(main_class, SYMBOL(main), SYMBOL(_array_java_lang_String__V)); if(mb == NULL || !(mb->access_flags & ACC_STATIC)) { signalException(java_lang_NoSuchMethodError, "main"); goto error; } /* Create the String array holding the command line args */ i = class_arg + 1; if((array_class = findArrayClass(SYMBOL(array_java_lang_String))) && (array = allocArray(array_class, argc - i, sizeof(Object*)))) { Object **args = ARRAY_DATA(array, Object*) - i; for(; i < argc; i++) if(!(args[i] = Cstr2String(argv[i]))) break; /* Call the main method */ if(i == argc) executeStaticMethod(main_class, mb, array); }
int classlibThreadPostInit() { Class *system = findSystemClass(SYMBOL(java_lang_System)); if(system != NULL) { MethodBlock *init = findMethod(system, SYMBOL(initializeSystemClass), SYMBOL(___V)); if(init != NULL) { executeStaticMethod(system, init); return !exceptionOccurred(); } } return FALSE; }
void exitVM(int status) { main_exited = TRUE; /* Execute System.exit() to run any registered shutdown hooks. In the unlikely event that System.exit() can't be found, or it returns, fall through and exit. */ if(!VMInitialising()) { Class *system = findSystemClass(SYMBOL(java_lang_System)); if(system) { MethodBlock *exit = findMethod(system, SYMBOL(exit), SYMBOL(_I__V)); if(exit) { DummyFrame dummy; executeStaticMethod(&dummy, system, exit, status); } } } jamvm_exit(status); }
int classlibThreadPostInit() { Class *system; #ifdef JSR292 /* Initialise lock used in Method Handle resolution - this must be done before any invokedynamic instruction is executed */ initVMLock(resolve_lock); #endif /* Initialise System class */ system = findSystemClass(SYMBOL(java_lang_System)); if(system != NULL) { MethodBlock *init = findMethod(system, SYMBOL(initializeSystemClass), SYMBOL(___V)); if(init != NULL) { executeStaticMethod(system, init); return !exceptionOccurred(); } } return FALSE; }
int main(int argc, char *argv[]) { Class *array_class, *main_class; Object *system_loader, *array; MethodBlock *mb; InitArgs args; int class_arg; char *cpntr; int status; int i; setDefaultInitArgs(&args); class_arg = parseCommandLine(argc, argv, &args); args.main_stack_base = &array_class; initVM(&args); if((system_loader = getSystemClassLoader()) == NULL) { printf("Cannot create system class loader\n"); printException(); exitVM(1); } mainThreadSetContextClassLoader(system_loader); for(cpntr = argv[class_arg]; *cpntr; cpntr++) if(*cpntr == '.') *cpntr = '/'; if((main_class = findClassFromClassLoader(argv[class_arg], system_loader)) != NULL) initClass(main_class); if(exceptionOccurred()) { printException(); exitVM(1); } mb = lookupMethod(main_class, SYMBOL(main), SYMBOL(_array_java_lang_String__V)); if(!mb || !(mb->access_flags & ACC_STATIC)) { printf("Static method \"main\" not found in %s\n", argv[class_arg]); exitVM(1); } /* Create the String array holding the command line args */ i = class_arg + 1; if((array_class = findArrayClass(SYMBOL(array_java_lang_String))) && (array = allocArray(array_class, argc - i, sizeof(Object*)))) { Object **args = (Object**)ARRAY_DATA(array) - i; for(; i < argc; i++) if(!(args[i] = Cstr2String(argv[i]))) break; /* Call the main method */ if(i == argc) executeStaticMethod(main_class, mb, array); } /* ExceptionOccurred returns the exception or NULL, which is OK for normal conditionals, but not here... */ if((status = exceptionOccurred() ? 1 : 0)) printException(); /* Wait for all but daemon threads to die */ mainThreadWaitToExitVM(); exitVM(status); }