Ejemplo n.º 1
0
address OsMemory_allocate_chunk(size_t initial_size,
                                size_t max_size, size_t alignment)
{
  GUARANTEE(chunks[0] == NULL || chunks[1] == NULL,
            "OsMemory_allocate_chunk supports only 2 chunks");
  int i;

  if (chunks[0] == NULL) {
    i = 0;
  } else {
    i = 1;
  }

  chunks_orig[i] = (address)OsMemory_allocate(max_size + alignment);
  if (chunks_orig[i] == NULL) {
    return NULL;
  }

  chunks[i] = (address)align_size_up((size_t)chunks_orig[i], alignment);

  max_chunk_size[i] = max_size;
  cur_chunk_size[i] = initial_size;

  AZZERT_ONLY(mark_unused_chunk_space(i));

  return chunks[i];
}
Ejemplo n.º 2
0
int
JVM_InitializeMemory(char* start, int size) {
    _JvmMemHdrPtr jvmMemoryHdr;

    if (JvmMemoryStart != NULL) {
        /* avoid a double init */
        return 0;
    }

    if (size < 0) {
        /* size not specified, use the default */
        size = DEFAULT_POOL_SIZE;
    }

    if(jvm_trace_malloc) {
        tty->print_cr("size = %d", size);
    }

    if(start == NULL)  {
        /* Need malloc the memory pool dynamically */

        /* allocate the chunk of memory to C heap */
#ifdef JVM_MALLOC_USE_CLDC_HI
        JvmMemory = (char*) OsMemory_allocate(size);
#else
        JvmMemory = (char*)malloc(size);
#endif
        if (JvmMemory == NULL) {
            return -1;
        }

     } else {
        
#define JVM_MALLOC_USE_STATIC
        JvmMemory = start;
     }

    JvmMemoryStart = JvmMemory;
    JvmMemoryEnd   = JvmMemory + size - sizeof(_JvmMemHdr);

    /* Word alignment */
    while (((long)JvmMemoryStart & ALIGNMENT) != 0) {
        JvmMemoryStart++;
    }

    jvmMemoryHdr = (_JvmMemHdrPtr)JvmMemoryStart;
    jvmMemoryHdr->magic = MAGIC;
    jvmMemoryHdr->free  = 1;
    jvmMemoryHdr->size  = (JvmMemory - JvmMemoryStart)
                           + size - sizeof(_JvmMemHdr);
    return size;
}
Ejemplo n.º 3
0
/*
 * Parses MethodTrap=... command-line argument.
 * @param p - pointer to the first char after MethodTrap=
 */
bool Arguments::parse_method_trap_param(const char* arg) {
  // Discard superfluous MethodTrap arguments issuing the warning message
  MethodTrapDesc* mt = MethodTrap::find_slot();
  if (mt == NULL) {
    tty->print_cr("WARNING: too many MethodTrap arguments, superfluous will be ignored");
    return true;
  }

  // Simple correctness test
  if (jvm_strchr(arg, '.') <= arg) {
    return false;
  }

  // Copy all chars after MethodTrap=
  char* p = (char*)OsMemory_allocate(jvm_strlen(arg) + 1);
  jvm_strcpy(p, arg);

  // Parse ACTION parameter if exists
  int action = ACTION_CALLBACK;
  char* q = jvm_strchr(p, ':');
  if (q != NULL) {
    *q++ = 0;
    if (jvm_strncmp(q, "call", 4) == 0) {
      action = ACTION_CALLBACK;
    } else if (jvm_strncmp(q, "exit", 4) == 0) {
      action = ACTION_EXIT;
    } else if (jvm_strncmp(q, "stop", 4) == 0) {
      action = ACTION_STOP_ISOLATE;
    } else if (jvm_strncmp(q, "break", 5) == 0) {
      action = ACTION_BREAKPOINT;
    } else {
      action = jvm_atoi(q);
    }
  }
  
  // Parse CALL_COUNT parameter if exists
  int call_count = 0;
  q = jvm_strchr(p, ',');
  if (q != NULL) {
    *q++ = 0;
    call_count = jvm_atoi(q);
  }

  mt->set_method_name(p);
  mt->set_parameters(call_count, action, 0);
  return true;
}
Ejemplo n.º 4
0
void EventLogger::log(EventType type) {
  if (!UseEventLogger) {
    return;
  }
  if (_tail == NULL || _tail->_used_count >= BLOCK_SIZE) {
    size_t size = sizeof(LogEntryBlock) + sizeof(LogEntry[BLOCK_SIZE-1]);
    LogEntryBlock *blk = (LogEntryBlock*)OsMemory_allocate(size);
    if (_head == NULL) {
      _head = _tail = blk;
    } else {
      _tail->_next = blk;
      _tail = blk;
    }
    blk->_used_count = 0;
    blk->_next = NULL;
  }

  GUARANTEE(_tail != NULL && _tail->_used_count < BLOCK_SIZE, "sanity");
  LogEntry *entry = &_tail->_entries[_tail->_used_count++];
  jlong now_hrticks = Os::elapsed_counter();
  entry->_hrtick_delta = (int)(now_hrticks - _last_hrticks);
  entry->_type = type;
  _last_hrticks = now_hrticks;
}
Ejemplo n.º 5
0
inline void EventLogger::Block::allocate ( void ) {
  Block* block = (Block*)OsMemory_allocate( sizeof( Block ) );
  block->_next = NULL;
  *_tail = block;
  _used = 0;
}
Ejemplo n.º 6
0
 static void* malloc_bytes(size_t size) {
   void* result = OsMemory_allocate(size);
   return result;
 }
Ejemplo n.º 7
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;
}