void BitKey::ReAllocate(uint32_t i_len) { if(i_len > iv_Capacity) // never shrink { bool wasDirect = IsDirect(); uint32_t oldSize = iv_Capacity; uint32_t * oldPtr = DataPtr(); uint32_t wordsize = getWordSize(i_len); iv_Capacity = 32*wordsize; bool isDirect = IsDirect(); if(!isDirect) // to indirect { uint32_t * newBuffer = new uint32_t[wordsize]; BitString dbs(iv_Capacity,newBuffer); dbs.Pattern(0x00000000); BitString sbs(oldSize,oldPtr); dbs.SetBits(sbs); iv_storage1 = 0; if(!wasDirect) // from indirect { delete [] iv_rep.buffer; } iv_rep.buffer = newBuffer; } } }
void VMError::report_and_die() { // Don't allocate large buffer on stack static char buffer[O_BUFLEN]; // An error could happen before tty is initialized or after it has been // destroyed. Here we use a very simple unbuffered fdStream for printing. // Only out.print_raw() and out.print_raw_cr() should be used, as other // printing methods need to allocate large buffer on stack. To format a // string, use jio_snprintf() with a static buffer or use staticBufferStream. static fdStream out(defaultStream::output_fd()); // How many errors occurred in error handler when reporting first_error. static int recursive_error_count; // We will first print a brief message to standard out (verbose = false), // then save detailed information in log file (verbose = true). static bool out_done = false; // done printing to standard out static bool log_done = false; // done saving error log static bool transmit_report_done = false; // done error reporting static fdStream log; // error log if (SuppressFatalErrorMessage) { os::abort(); } jlong mytid = os::current_thread_id(); if (first_error == NULL && Atomic::cmpxchg_ptr(this, &first_error, NULL) == NULL) { // first time first_error_tid = mytid; set_error_reported(); if (ShowMessageBoxOnError || PauseAtExit) { show_message_box(buffer, sizeof(buffer)); // User has asked JVM to abort. Reset ShowMessageBoxOnError so the // WatcherThread can kill JVM if the error handler hangs. ShowMessageBoxOnError = false; } // Write a minidump on Windows, check core dump limits on Linux/Solaris os::check_or_create_dump(_siginfo, _context, buffer, sizeof(buffer)); // reset signal handlers or exception filter; make sure recursive crashes // are handled properly. reset_signal_handlers(); } else { // If UseOsErrorReporting we call this for each level of the call stack // while searching for the exception handler. Only the first level needs // to be reported. if (UseOSErrorReporting && log_done) return; // This is not the first error, see if it happened in a different thread // or in the same thread during error reporting. if (first_error_tid != mytid) { jio_snprintf(buffer, sizeof(buffer), "[thread " INT64_FORMAT " also had an error]", mytid); out.print_raw_cr(buffer); // error reporting is not MT-safe, block current thread os::infinite_sleep(); } else { if (recursive_error_count++ > 30) { out.print_raw_cr("[Too many errors, abort]"); os::die(); } jio_snprintf(buffer, sizeof(buffer), "[error occurred during error reporting %s, id 0x%x]", first_error ? first_error->_current_step_info : "", _id); if (log.is_open()) { log.cr(); log.print_raw_cr(buffer); log.cr(); } else { out.cr(); out.print_raw_cr(buffer); out.cr(); } } } // print to screen if (!out_done) { first_error->_verbose = false; staticBufferStream sbs(buffer, sizeof(buffer), &out); first_error->report(&sbs); out_done = true; first_error->_current_step = 0; // reset current_step first_error->_current_step_info = ""; // reset current_step string } // print to error log file if (!log_done) { first_error->_verbose = true; // see if log file is already open if (!log.is_open()) { // open log file int fd = -1; if (ErrorFile != NULL) { bool copy_ok = Arguments::copy_expand_pid(ErrorFile, strlen(ErrorFile), buffer, sizeof(buffer)); if (copy_ok) { fd = open(buffer, O_RDWR | O_CREAT | O_TRUNC, 0666); } } if (fd == -1) { const char *cwd = os::get_current_directory(buffer, sizeof(buffer)); size_t len = strlen(cwd); // either user didn't specify, or the user's location failed, // so use the default name in the current directory jio_snprintf(&buffer[len], sizeof(buffer)-len, "%shs_err_pid%u.log", os::file_separator(), os::current_process_id()); fd = open(buffer, O_RDWR | O_CREAT | O_TRUNC, 0666); } if (fd == -1) { const char * tmpdir = os::get_temp_directory(); // try temp directory if it exists. if (tmpdir != NULL && tmpdir[0] != '\0') { jio_snprintf(buffer, sizeof(buffer), "%s%shs_err_pid%u.log", tmpdir, os::file_separator(), os::current_process_id()); fd = open(buffer, O_RDWR | O_CREAT | O_TRUNC, 0666); } } if (fd != -1) { out.print_raw("# An error report file with more information is saved as:\n# "); out.print_raw_cr(buffer); os::set_error_file(buffer); log.set_fd(fd); } else { out.print_raw_cr("# Can not save log file, dump to screen.."); log.set_fd(defaultStream::output_fd()); /* Error reporting currently needs dumpfile. * Maybe implement direct streaming in the future.*/ transmit_report_done = true; } } staticBufferStream sbs(buffer, O_BUFLEN, &log); first_error->report(&sbs); first_error->_current_step = 0; // reset current_step first_error->_current_step_info = ""; // reset current_step string // Run error reporting to determine whether or not to report the crash. if (!transmit_report_done && should_report_bug(first_error->_id)) { transmit_report_done = true; FILE* hs_err = ::fdopen(log.fd(), "r"); if (NULL != hs_err) { ErrorReporter er; er.call(hs_err, buffer, O_BUFLEN); } } if (log.fd() != defaultStream::output_fd()) { close(log.fd()); } log.set_fd(-1); log_done = true; } static bool skip_OnError = false; if (!skip_OnError && OnError && OnError[0]) { skip_OnError = true; out.print_raw_cr("#"); out.print_raw ("# -XX:OnError=\""); out.print_raw (OnError); out.print_raw_cr("\""); char* cmd; const char* ptr = OnError; while ((cmd = next_OnError_command(buffer, sizeof(buffer), &ptr)) != NULL){ out.print_raw ("# Executing "); #if defined(LINUX) || defined(_ALLBSD_SOURCE) out.print_raw ("/bin/sh -c "); #elif defined(SOLARIS) out.print_raw ("/usr/bin/sh -c "); #endif out.print_raw ("\""); out.print_raw (cmd); out.print_raw_cr("\" ..."); os::fork_and_exec(cmd); } // done with OnError OnError = NULL; } static bool skip_bug_url = !should_report_bug(first_error->_id); if (!skip_bug_url) { skip_bug_url = true; out.print_raw_cr("#"); print_bug_submit_message(&out, _thread); } if (!UseOSErrorReporting) { // os::abort() will call abort hooks, try it first. static bool skip_os_abort = false; if (!skip_os_abort) { skip_os_abort = true; bool dump_core = should_report_bug(first_error->_id); os::abort(dump_core); } // if os::abort() doesn't abort, try os::die(); os::die(); } }
int main(int argc, char **argv) { int tmode, ans_fi, target, fold, knum; unsigned int seed; int tflag = 0, eval_time = 0, skip_flag = 0; double ans_value; Data dat; FInfo fs; /* 引数の読み込み */ read_opt(argc, argv, &dat, &fs, SBS, &tmode, &knum, &fold, &seed); /* 各分割におけるデータの個数を初期化 */ dat.split_num = set_split(fold, dat.total); /* 配列の初期化 */ alloc_prm(&dat, &fs); /* データの読み込み */ read_data(&dat); /* 実験の初期化 */ shuffle(&dat, seed); skip_flag = init_step(&dat, &fs, &eval_time, INITIAL, fold, knum, SBS); if(!skip_flag){ /* SBS開始 */ while(1){ /* Backward Step: SBSで評価関数の値を最も少なく減少させる特徴を一つ削除する。 削除したらFoward Stepへ。 */ sbs(&dat, &fs, &ans_value, fold, &target, &eval_time, knum); ans_fi = target; /* 最も不要な特徴を除いた特徴集合を作成 */ remove_one(&fs, target, ans_value); print_fs(&fs, eval_time, BACKWARD); /* tmodeモードの時は、最も評価関数の値が大きい特徴集合を保存する */ if(tmode) eval_best(&fs); if(fs.sel.num == fs.ext_num){ print_fs(&fs, eval_time, FINAL); tflag = 1; break; } }; /* 全体のループ */ } /* 選択した特徴集合を出力する */ output(&fs, tmode, eval_time); /* 確保した配列を解放する */ free_prm(&dat, &fs); exit(0); }
void VMError::report_and_die() { // Don't allocate large buffer on stack static char buffer[O_BUFLEN]; // How many errors occurred in error handler when reporting first_error. static int recursive_error_count; // We will first print a brief message to standard out (verbose = false), // then save detailed information in log file (verbose = true). static bool out_done = false; // done printing to standard out static bool log_done = false; // done saving error log static bool transmit_report_done = false; // done error reporting // disble NMT to avoid further exception MemTracker::shutdown(MemTracker::NMT_error_reporting); if (SuppressFatalErrorMessage) { os::abort(); } jlong mytid = os::current_thread_id(); if (first_error == NULL && Atomic::cmpxchg_ptr(this, &first_error, NULL) == NULL) { // first time first_error_tid = mytid; set_error_reported(); if (ShowMessageBoxOnError || PauseAtExit) { show_message_box(buffer, sizeof(buffer)); // User has asked JVM to abort. Reset ShowMessageBoxOnError so the // WatcherThread can kill JVM if the error handler hangs. ShowMessageBoxOnError = false; } // Write a minidump on Windows, check core dump limits on Linux/Solaris os::check_or_create_dump(_siginfo, _context, buffer, sizeof(buffer)); // reset signal handlers or exception filter; make sure recursive crashes // are handled properly. reset_signal_handlers(); } else { // If UseOsErrorReporting we call this for each level of the call stack // while searching for the exception handler. Only the first level needs // to be reported. if (UseOSErrorReporting && log_done) return; // This is not the first error, see if it happened in a different thread // or in the same thread during error reporting. if (first_error_tid != mytid) { char msgbuf[64]; jio_snprintf(msgbuf, sizeof(msgbuf), "[thread " INT64_FORMAT " also had an error]", mytid); out.print_raw_cr(msgbuf); // error reporting is not MT-safe, block current thread os::infinite_sleep(); } else { if (recursive_error_count++ > 30) { out.print_raw_cr("[Too many errors, abort]"); os::die(); } jio_snprintf(buffer, sizeof(buffer), "[error occurred during error reporting %s, id 0x%x]", first_error ? first_error->_current_step_info : "", _id); if (log.is_open()) { log.cr(); log.print_raw_cr(buffer); log.cr(); } else { out.cr(); out.print_raw_cr(buffer); out.cr(); } } } // print to screen if (!out_done) { first_error->_verbose = false; staticBufferStream sbs(buffer, sizeof(buffer), &out); first_error->report(&sbs); out_done = true; first_error->_current_step = 0; // reset current_step first_error->_current_step_info = ""; // reset current_step string } // print to error log file if (!log_done) { first_error->_verbose = true; // see if log file is already open if (!log.is_open()) { // open log file int fd = prepare_log_file(ErrorFile, "hs_err_pid%p.log", buffer, sizeof(buffer)); if (fd != -1) { out.print_raw("# An error report file with more information is saved as:\n# "); out.print_raw_cr(buffer); os::set_error_file(buffer); log.set_fd(fd); } else { out.print_raw_cr("# Can not save log file, dump to screen.."); log.set_fd(defaultStream::output_fd()); /* Error reporting currently needs dumpfile. * Maybe implement direct streaming in the future.*/ transmit_report_done = true; } } staticBufferStream sbs(buffer, O_BUFLEN, &log); first_error->report(&sbs); first_error->_current_step = 0; // reset current_step first_error->_current_step_info = ""; // reset current_step string // Run error reporting to determine whether or not to report the crash. if (!transmit_report_done && should_report_bug(first_error->_id)) { transmit_report_done = true; FILE* hs_err = os::open(log.fd(), "r"); if (NULL != hs_err) { ErrorReporter er; er.call(hs_err, buffer, O_BUFLEN); } } if (log.fd() != defaultStream::output_fd()) { close(log.fd()); } log.set_fd(-1); log_done = true; } static bool skip_OnError = false; if (!skip_OnError && OnError && OnError[0]) { skip_OnError = true; out.print_raw_cr("#"); out.print_raw ("# -XX:OnError=\""); out.print_raw (OnError); out.print_raw_cr("\""); char* cmd; const char* ptr = OnError; while ((cmd = next_OnError_command(buffer, sizeof(buffer), &ptr)) != NULL){ out.print_raw ("# Executing "); #if defined(LINUX) || defined(_ALLBSD_SOURCE) out.print_raw ("/bin/sh -c "); #elif defined(SOLARIS) out.print_raw ("/usr/bin/sh -c "); #endif out.print_raw ("\""); out.print_raw (cmd); out.print_raw_cr("\" ..."); os::fork_and_exec(cmd); } // done with OnError OnError = NULL; } static bool skip_replay = ReplayCompiles; // Do not overwrite file during replay if (DumpReplayDataOnError && _thread && _thread->is_Compiler_thread() && !skip_replay) { skip_replay = true; ciEnv* env = ciEnv::current(); if (env != NULL) { int fd = prepare_log_file(ReplayDataFile, "replay_pid%p.log", buffer, sizeof(buffer)); if (fd != -1) { FILE* replay_data_file = os::open(fd, "w"); if (replay_data_file != NULL) { fileStream replay_data_stream(replay_data_file, /*need_close=*/true); env->dump_replay_data_unsafe(&replay_data_stream); out.print_raw("#\n# Compiler replay data is saved as:\n# "); out.print_raw_cr(buffer); } else { out.print_raw("#\n# Can't open file to dump replay data. Error: "); out.print_raw_cr(strerror(os::get_last_error())); } } } } static bool skip_bug_url = !should_report_bug(first_error->_id); if (!skip_bug_url) { skip_bug_url = true; out.print_raw_cr("#"); print_bug_submit_message(&out, _thread); } if (!UseOSErrorReporting) { // os::abort() will call abort hooks, try it first. static bool skip_os_abort = false; if (!skip_os_abort) { skip_os_abort = true; bool dump_core = should_report_bug(first_error->_id); os::abort(dump_core); } // if os::abort() doesn't abort, try os::die(); os::die(); } }
RBScene* ParseTreeModel::render(ProjectModel* project, DeviceState* device, SkinDocument* doc, const QString* file) { scene->clear(); /* Setting the background */ scene->setBackgroundBrush(QBrush(QPixmap(":/render/scenebg.png"))); /* Preparing settings */ QMap<QString, QString> settings; if(project) settings = project->getSettings(); /* Setting themebase if it can't be derived from the project */ if(settings.value("themebase", "") == "" && file && QFile::exists(*file)) { QDir base(*file); base.cdUp(); settings.insert("themebase", base.canonicalPath()); } /* Finding imagebase and determining remote/wps status */ bool remote = false; bool wps = false; if(file) { QString skinFile = *file; QStringList decomp = skinFile.split("/"); skinFile = decomp[decomp.count() - 1]; skinFile.chop(skinFile.length() - skinFile.lastIndexOf(".")); settings.insert("imagepath", settings.value("themebase","") + "/wps/" + skinFile); decomp = file->split("."); QString extension = decomp.last(); if(extension[0] == 'r') remote = true; if(extension.right(3).toLower() == "wps" || extension.right(3).toLower() == "fms") wps = true; } /* Rendering SBS, if necessary */ RBScreen* screen = 0; if(wps && device->data("rendersbs").toBool()) { QString sbsFile = settings.value(remote ? "rsbs" : "sbs", ""); sbsFile.replace("/.rockbox" , settings.value("themebase","")); if(QFile::exists(sbsFile)) { QFile sbs(sbsFile); sbs.open(QFile::ReadOnly | QFile::Text); if(sbsModel) sbsModel->deleteLater(); sbsModel = new ParseTreeModel(QString(sbs.readAll()).toAscii()); if(sbsModel->root != 0) { RBRenderInfo sbsInfo(sbsModel, project, doc, &settings, device, screen); screen = new RBScreen(sbsInfo, remote); scene->addItem(screen); sbsInfo = RBRenderInfo(sbsModel, project, doc, &settings, device, screen); sbsModel->root->render(sbsInfo); screen->endSbsRender(); setChildrenUnselectable(screen); } } } RBRenderInfo info(this, project, doc, &settings, device, screen); /* Adding the screen */ if(!screen) { screen = new RBScreen(info, remote); scene->addItem(screen); } scene->setScreenSize(screen->boundingRect()); info = RBRenderInfo(this, project, doc, &settings, device, screen); /* Rendering the tree */ if(root) root->render(info); return scene; }