Example #1
0
/*
 * 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;
}
Example #2
0
int Arguments::parse_one_arg(int argc, char** argv) {
  if (argc <= 0) {
    // we already finished parsing.
    return 0;
  }

  int count = 1; // in most cases we find an argument of 1 word

#if ENABLE_MULTIPLE_PROFILES_SUPPORT
  if ((jvm_strcmp(argv[0], "-profile") == 0) && argc >= 2) {
    JVM_SetProfile(argv[1]);
    count = 2;
  } else
#endif // ENABLE_MULTIPLE_PROFILES_SUPPORT
  if (jvm_strcmp(argv[0], "-version") == 0) {
    Globals::print_version();
    JVMSPI_Exit(0);
    ::jvm_exit(0);
  }
  else if ((jvm_strcmp(argv[0], "-?") == 0) ||
           (jvm_strcmp(argv[0], "-help") == 0)) {
    JVMSPI_DisplayUsage(NULL);
    JVMSPI_Exit(1);
    ::jvm_exit(1);
  }
  else if (((jvm_strcmp(argv[0], "-classpath") == 0) ||
            (jvm_strcmp(argv[0], "-cp") == 0)) && argc >= 2) {
    set_pathname_from_const_ascii(&_classpath, argv[1]);
    count = 2;
  }
  else if (jvm_strcmp(argv[0], "-int") == 0) {
    UseCompiler = false;
  }
  else if (jvm_strcmp(argv[0], "-comp") == 0) {
    MixedMode = false;
    UseCompiler = true;
  }
  else if ((*argv[0] == '-') && (*(argv[0]+1) == 'D')) {
    char *key;
    char *value;

    key = argv[0] + 2;
    for (value = key; *value ; value++) {
        if (*value == '=') {
          *value++ = 0;
          break;
        }
    }
    JVMSPI_SetSystemProperty(key, value);
  }

#if ENABLE_INTERPRETER_GENERATOR || USE_SOURCE_IMAGE_GENERATOR
  else if (jvm_strcmp(argv[0], "-outputdir") == 0) {
    set_pathname_from_const_ascii(&_generator_output_dir, argv[1]);
    count = 2;
  }
  else if (jvm_strcmp(argv[0], "-generate") == 0) {
    GenerateDebugAssembly = true;
    GenerateAssemblyCode = true;
  }
  else if (jvm_strcmp(argv[0], "-generateoptimized") == 0) {
    GenerateDebugAssembly = false;
    GenerateAssemblyCode = true;
  }
#endif

#if ENABLE_JVMPI_PROFILE 
  //  To get the library name to be loaded
  else if(jvm_strncmp(argv[0], "-Xrun", 5) == 0) {
    Arguments::_jvmpi_profiler_lib = (char*)OsMemory_allocate(jvm_strlen(argv[0]) + 2);
    jvm_strcpy(Arguments::_jvmpi_profiler_lib, "lib");
    jvm_strcat(Arguments::_jvmpi_profiler_lib, &(argv[0][5]));
    jvm_strcat(Arguments::_jvmpi_profiler_lib, ".so");
  }
#endif

#if ENABLE_ROM_GENERATOR

#if USE_SOURCE_IMAGE_GENERATOR
  else if (jvm_strcmp(argv[0], "-romconfig") == 0) {
    set_pathname_from_const_ascii(&_rom_config_file, argv[1]);
    count = 2;
  }
  else if (jvm_strcmp(argv[0], "-romincludepath") == 0) {
    ROMIncludePath *ptr =
      (ROMIncludePath*)OsMemory_allocate(sizeof(ROMIncludePath));
    ptr->_next = _rom_include_paths;
    ptr->_file._path = NULL;
    set_pathname_from_const_ascii(&(ptr->_file), argv[1]);
    _rom_include_paths = ptr;
    count = 2;
  }
  else if (jvm_strcmp(argv[0], "-romize") == 0) {
    // Romize the system classes
    GenerateROMImage = true;
#if ENABLE_TTY_TRACE
    TraceMirandaMethods = true;
#endif
    count = 1;
  }
#endif // USE_SOURCE_IMAGE_GENERATOR

#if USE_BINARY_IMAGE_GENERATOR
  else if (jvm_strcmp(argv[0], "-convert") == 0) {
    // Romize an application
    GenerateROMImage = true;
#if ENABLE_TTY_TRACE
    TraceMirandaMethods = true;
#endif
    count = 1;
  }
#if ENABLE_LIB_IMAGES
  else if (jvm_strcmp(argv[0], "-convertshared") == 0) {
    // Romize a library, so it could be used shared 
    GenerateSharedROMImage = true;
    GenerateROMImage = true;
#if ENABLE_TTY_TRACE
    TraceMirandaMethods = true;
#endif
    count = 1;
  }
#endif
#endif

  else if (jvm_strcmp(argv[0], "-romoutputfile") == 0) {
    set_pathname_from_const_ascii(&_rom_output_file, argv[1]);
    count = 2;
  }

#endif // ENABLE_ROM_GENERATOR

#if USE_DEBUG_PRINTING
  else if (jvm_strcmp(argv[0], "-definitions") == 0) {
    Globals::print_definitions();
    JVMSPI_Exit(1);
    ::jvm_exit(1);
  }
  else if (jvm_strcmp(argv[0], "-flags") == 0) {
    Globals::print_flags();
    JVMSPI_Exit(1);
    ::jvm_exit(1);
  }
  else if (jvm_strcmp(argv[0], "-buildopts") == 0) {
    Globals::print_build_options();
    JVMSPI_Exit(1);
    ::jvm_exit(1);
  }
  else if (jvm_strcmp(argv[0], "-errorcodes") == 0) {
    Globals::print_error_codes();
    JVMSPI_Exit(1);
    ::jvm_exit(1);
  }
#endif

#if !defined(PRODUCT) || ENABLE_TTY_TRACE
  else if (jvm_strcmp(argv[0], "-verbose") == 0) {
#if ENABLE_TTY_TRACE
    VerboseGC = true;
    VerboseClassLoading = true;
#endif
  }
  // Parse the CompileOnlyXXX= option, if present, and record the
  // classes and methods that should always be compiled.  This must
  // be done before the following to allow correct handling of
  // classes which start with the letters K or M
  else if (jvm_strncmp(argv[0], COMPILE_ONLY_METHOD,
                       STATIC_STRLEN(COMPILE_ONLY_METHOD)) == 0) {
    _method_CompileOnly = argv[0] + STATIC_STRLEN(COMPILE_ONLY_METHOD);
  }
  else if (jvm_strncmp(argv[0], COMPILE_ONLY_CLASS,
                       STATIC_STRLEN(COMPILE_ONLY_CLASS)) == 0) {
    _class_CompileOnly = argv[0] + STATIC_STRLEN(COMPILE_ONLY_CLASS);
  }
#endif
#if !defined(PRODUCT)
  else if (jvm_strcmp(argv[0], "-compilertestconfig") == 0) {
    if (argc < 2) {
      JVMSPI_DisplayUsage((char*)"Compiler test config file not specified.");
      JVMSPI_Exit(1);
      ::jvm_exit(1);
    }
    RunCompilerTests = true;
    set_pathname_from_const_ascii(&_compiler_test_config_file, argv[1]);
    count = 2;
  }
#endif /* NOT PRODUCT */
#if ENABLE_METHOD_TRAPS
  else if (jvm_strncmp(argv[0], METHOD_TRAP, STATIC_STRLEN(METHOD_TRAP)) == 0) {
    if (!parse_method_trap_param(argv[0] + STATIC_STRLEN(METHOD_TRAP))) {
      JVMSPI_DisplayUsage((char*)"Invalid usage of MethodTrap argument");
      JVMSPI_Exit(1);
      ::jvm_exit(1);
    }
  }
#endif
#if ENABLE_REMOTE_TRACER
  else if (((jvm_strcmp(argv[0], "-tracehost") == 0)) && argc > 2) {
    traceHost = argv[1];
    count = 2;
  }
#endif
#if ENABLE_JAVA_DEBUGGER
  else if (jvm_strcmp(argv[0], "-debugger") == 0) {
    JavaDebugger::set_debugger_option_on(true);
  } else if (jvm_strcmp(argv[0], "-port") == 0) {
    _debugger_port = jvm_atoi(argv[1]);
    count=2;
  } else if (jvm_strcmp(argv[0], "-suspend") == 0) {
    JavaDebugger::set_suspend(true);
  } else if (jvm_strcmp(argv[0], "-nosuspend") == 0) {
    JavaDebugger::set_suspend(false);
  }
#if ENABLE_ISOLATES
  else if (jvm_strcmp(argv[0], "-debug_isolate") == 0) {
    JavaDebugger::set_debug_isolate_option_on(true);
  }
  else if (jvm_strcmp(argv[0], "-debug_main") == 0) {
    JavaDebugger::set_debug_main_option_on(true);
  }
#endif
#endif
#if ENABLE_MEMORY_PROFILER
  else if (jvm_strcmp(argv[0], "-memory_profiler") == 0) {
    JavaDebugger::set_debugger_option_on(true);
  }
#endif
#if ENABLE_MEMORY_MONITOR
  else if (jvm_strcmp(argv[0], "-monitormemory") == 0) {
    Arguments::_monitor_memory = 1;
  }
#endif
  else if ((argv[0][0] == '-')||(argv[0][0] == '+') || (argv[0][0] == '=')) {
    if (!Globals::parse_argument(argv[0])) {
      count = -1; // Indicate parse error
    }
#if ENABLE_ROM_GENERATOR
    if (jvm_strcmp(argv[0], "+EnableAllROMOptimizations") == 0) {
      // Turn on all available ROM optimizations, so you don't have to
      // enable them individually
      //
      // This also means you can selectively turn off some ROM
      // optimizations such as "+EnableAllROMOptimizations
      // -CompactROMFieldTables". Note that the order is important.
      AggressiveROMSymbolRenaming = true;
      CompactROMFieldTables       = true;
      CompactROMMethodTables      = true;
      CompactROMBytecodes         = true;
      RenameNonPublicROMClasses   = true;
      RenameNonPublicROMSymbols   = true;
      SimpleROMInliner            = true;
      RemoveDuplicatedROMStackmaps= true;
      RemoveDeadMethods           = true;
    }
#if ENABLE_ROM_JAVA_DEBUGGER
    if (jvm_strcmp(argv[0], "+MakeROMDebuggable") == 0) {
      // Turn off any optimizations that would change bytecode offsets
      CompactROMFieldTables = false;
      CompactROMMethodTables = false;
      CompactROMBytecodes         = false;
      RenameNonPublicROMSymbols   = false;
      AggressiveROMSymbolRenaming = false;
    }
#endif
    if (jvm_strcmp(argv[0], "-EnableBaseOptimizations") == 0) {
      // Turn off all optimizations
      AggressiveROMSymbolRenaming = false;
      CompactROMFieldTables       = false;
      CompactROMMethodTables      = false;
      CompactROMBytecodes         = false;
      RenameNonPublicROMClasses   = false;
      RenameNonPublicROMSymbols   = false;
      SimpleROMInliner            = false;
      RemoveDuplicatedROMStackmaps= false;
      RemoveDeadMethods           = false;
      RewriteROMConstantPool      = false;
    }
#endif
  }
  else {
    /* We don't recognize argv[0] as an argument */
    count = 0;
  }

  return count;
}