void Bytecodes::verify() { #if USE_DEBUG_PRINTING GUARANTEE(number_of_java_codes -1 <= 0xff, "Too many bytecodes"); int index = 0; for(BytecodeData* p = data; p->_name != NULL; p++) { GUARANTEE(p->_index == index, "index must match"); Code code = (Code) index; if (is_defined(code)) { GUARANTEE((int) jvm_strlen(p->_format) == length_for(code), "checking length"); } if (wide_is_defined(code)) { GUARANTEE((int) jvm_strlen(p->_wide_format) == wide_length_for(code), "checking length"); } if (is_defined(code)) { if ((code == Bytecodes::_goto) || (code == Bytecodes::_goto_w) || (code >= Bytecodes::_ireturn && code <= Bytecodes::_return) || (code == Bytecodes::_ret) || (code == Bytecodes::_tableswitch) || (code == Bytecodes::_lookupswitch) || (code == Bytecodes::_athrow) || (code == Bytecodes::_fast_invokenative)) { GUARANTEE(!can_fall_through(code), "cannot fall through"); } else { GUARANTEE(can_fall_through(code), "can fall through"); } } index++; } #endif }
void ClassInfo::iterate_tables(OopROMVisitor* visitor) { int index = 0; if (vtable_length() > 0) { visitor->do_comment("Virtual dispatch table"); for (index = 0; index < vtable_length(); index++) { IndexableField field(index, true); visitor->do_oop(&field, vtable_offset_from_index(index), true); } } if (itable_length() > 0){ visitor->do_comment("Interface dispatch table"); for (index = 0; index < itable_length(); index++) { { InstanceClass ic = itable_interface_at(index); Symbol name = ic.name(); char buffer[1024]; jvm_sprintf(buffer, "interface klass_index "); name.string_copy(buffer + jvm_strlen(buffer), sizeof(buffer) - jvm_strlen(buffer)); NamedField field(buffer, true); visitor->do_int(&field, itable_offset_from_index(index), true); } { NamedField field("offset", true); visitor->do_int(&field, itable_offset_from_index(index) + sizeof(jint), true); } } for (index = 0; index < itable_length(); index++) { int offset = itable_offset_at(index); // Some ROM's interfaces that implement other interfaces set // offset=0, since this information is actually needed by // anyone. if (offset > 0) { InstanceClass ic = itable_interface_at(index); Symbol name = ic.name(); ObjArray methods = ic.methods(); const int buffer_size = 256; char buffer[256]; jvm_sprintf(buffer, "Table for interface #%d: ", index); name.string_copy(buffer + jvm_strlen(buffer), buffer_size- jvm_strlen(buffer)); visitor->do_comment(buffer); for (int i = 0; i < methods.length(); i ++) { IndexableField field(i, true); visitor->do_oop(&field, offset + i * sizeof(jobject), true); } } } } }
void SourceAssembler::define_bytes(const char* s, bool word_align) { GUARANTEE(s != NULL, "string must exist"); int d = word_align ? (-(int)(jvm_strlen(s) + 1) & 3) : 0; int numbytes = (int)jvm_strlen(s) + d; if (GenerateGNUCode) { stream()->print("\t.ascii\t\"%s\\0", s); while (d-- > 0) stream()->print("\\0"); stream()->print("\""); } else { stream()->print("\tDCB\t\"%s\", 0", s); while (d-- > 0) stream()->print(", 0"); } emit_comment_and_cr(); _current_commented_offset += numbytes; }
KNIEXPORT void KNI_NewStringUTF(const char* utf8chars, jstring stringHandle) { SETUP_ERROR_CHECKER_ARG; kni_clear_handle(stringHandle); // just in case of OutOfMemory OopDesc *str = Universe::new_string(utf8chars, jvm_strlen(utf8chars) _KNI_CHECK) kni_set_handle(stringHandle, str); }
jboolean JarFileParser::suffix_match_filter(const char* name, void* caller_data) { SETUP_ERROR_CHECKER_ARG; SuffixMatchFilterData* data = (SuffixMatchFilterData*)caller_data; int length = jvm_strlen(name); if (name[length-1] == '/') { //this is directory. skip it return KNI_TRUE; } if (match(data->_suffix, name, length) == data->should_match) { data->_f((char*)name, length, data->_jf JVM_CHECK_0); } return KNI_TRUE; }
void SourceAssembler::comment(const char* fmt, ...) { if (!GenerateGPTableOnly) { if (jvm_strlen(fmt) == 0) { stream()->cr(); } else { va_list ap; va_start(ap, fmt); stream()->print("\t%s ", GenerateGNUCode ? "@ " : ";"); stream()->vprint(fmt, ap); stream()->cr(); va_end(ap); } } }
bool JarFileParser::match(const char *suffix, const char *name, int name_len) { int suffix_len = jvm_strlen(suffix); int skip = name_len - suffix_len; if (skip <= 0) { // i.e., the suffix ".class" matches with the name "x.class", but not with // the name ".class" return false; } name += skip; if (jvm_memcmp(name, suffix, suffix_len) == 0) { return true; } else { return false; } }
/* * 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; }
bool OsFile_exists(const char *name) { armulator_simulate_memory_change(jvm_strlen(name), 10 * FileSpeed); OsFile_Handle handle = NULL; // in special case of directories we always return false if (name && name[strlen(name)-1] == '/') { return false; } if ((handle = fopen(name,"r"))!=0) { fclose(handle); return true; } else { return false; } }
// // Exceptions and errors // KNIEXPORT jint KNI_ThrowNew(const char* name, const char* message) { if(_jvm_in_quick_native_method) { _jvm_quick_native_exception = (char*)name; return KNI_OK; } UsingFastOops fast_oops; SETUP_ERROR_CHECKER_ARG; //make sure consecutive ThrowNew calls don't destroy one another Thread::clear_current_pending_exception(); // (1) Lookup the exception class Symbol::Fast class_name = SymbolTable::symbol_for(name _KNI_OOME_CHECK_(KNI_ERR)); if (class_name.equals(Symbols::java_lang_OutOfMemoryError())) { // Avoid allocating the exception object when we're running out of memory. Throw::out_of_memory_error(JVM_SINGLE_ARG_NO_CHECK); return KNI_OK; } //The following call is necessary for adherence to the KNI spec. // KNI_ERR must be returned for bogus classnames. SystemDictionary::resolve(&class_name, ExceptionOnFailure _KNI_OOME_CHECK_(KNI_ERR)); String::Fast str; if(message != NULL) { str = Universe::new_string(message, jvm_strlen(message) _KNI_OOME_CHECK_(KNI_ERR)); } { Throwable::Raw exception = Throw::new_exception(&class_name, &str JVM_NO_CHECK); if (exception.not_null()) { Thread::set_current_pending_exception(&exception); } else { // OOME should be thrown by previous call automatically } } return KNI_OK; }
void DefaultStream::print_raw(const char* s) { JVMSPI_PrintRaw(s); // print to log file if (LogVMOutput && has_log_file()) { OsFile_write(_log_file, s, sizeof(char), jvm_strlen(s)); // OsFile_flush(_log_file); if (++__charcount == 200000000) { OsFile_flush(_log_file); JvmPathChar z = 'z'; JvmPathChar a = 'a'; __charcount = 0; OsFile_close(_log_file); _log_file = OsFile_open(__log_name, "w"); if (__log_name[5] == z) { __log_name[5] = a; } else { __log_name[5]++; } } } #if !defined(PRODUCT) || ENABLE_PROFILER || ENABLE_TTY_TRACE while (true) { char ch = *s++; if (ch == 0) { break; } else if (ch == '\n') { _position = 0; } else { _position += 1; } } #endif }
for (int i = 0; i < len; i++) { if (p[i] == '/') { // This makes external class names which already contain '/' instead // of '.' fail resolution p[i] = '.'; } else if (p[i] == '.') { p[i] = '/'; } } return symbol_for(&byte_array JVM_NO_CHECK_AT_BOTTOM_0); } // This function is not frequently used. No need to optimize. ReturnOop SymbolTable::slashified_symbol_for(const char* s JVM_TRAPS) { return slashified_symbol_for((utf8)s, jvm_strlen(s) JVM_NO_CHECK_AT_BOTTOM); } // This function is not frequently used (only by Class.forName()). // No need to optimize. ReturnOop SymbolTable::symbol_for(String* string, bool slashify JVM_TRAPS) { // Speculatively allocate 4 bytes per jchar, in any case more than // the maximum possible space needed for UTF-8 conversion. UsingFastOops fast_oops; TypeArray::Fast byte_array = Symbol::copy_string_to_byte_array(string->obj(), slashify JVM_CHECK_0); return symbol_for(&byte_array, (utf8)byte_array().base_address(), byte_array().length() JVM_NO_CHECK_AT_BOTTOM_0); } inline void SymbolTable::insert(Symbol* symbol) {
OsFile_Handle OsFile_open(const char *filename, const char *mode) { armulator_simulate_memory_change(jvm_strlen(filename), 10 * FileSpeed); return fopen(filename, mode); }
void report_error(bool is_vm_internal_error, const char* file_name, int line_no, const char* title, const char* format, ...) { static int error_level = 1; // Handle the recursive case switch(error_level++) { case 1: // first time, do nothing break; case 2: // second time print recursive problem tty->print_cr("[error occurred during error reporting]"); return; default: // otherwise just say NO. JVM::exit(-1); } // Compute the message char message[2*1024]; va_list ap; va_start(ap, format); jvm_vsprintf(message, format, ap); va_end(ap); if (is_vm_internal_error) { // Print error has happen tty->cr(); tty->print_cr("#"); tty->print_cr("# VM Error, %s", title); tty->print_cr("#"); char loc_buf[256]; if (file_name != NULL) { int len = jvm_strlen(file_name); jvm_strncpy(loc_buf, file_name, 256); if (len + 10 < 256) { jvm_sprintf(loc_buf + len, ", %d", line_no); } } else { jvm_strcpy(loc_buf, "<unknown>"); } tty->print_cr("# Error ID: %s", loc_buf); tty->print_cr("#"); } { char* begin = message; // print line by line for (;;) { char* end = (char *) jvm_strchr(begin, '\n'); if (!end) { break; } *end = '\0'; tty->print_raw("# "); tty->print_raw(begin); *end = '\n'; begin = end + 1; } // print last line if (*begin) { tty->print_raw("# "); tty->print_raw(begin); tty->cr(); } // print end mark tty->print_cr("#"); } error_level--; }
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; }