bool OopNCode::switch_pointers(oop from, oop to, nmethodBList* nmethods_to_invalidate) { Unused(nmethods_to_invalidate); ResourceMark m; bool needToInvalICache = false; char* bound = Memory->new_gen->boundary(); addrDesc* p = locs(), *end = locsEnd(); LocChange* changes = NEW_RESOURCE_ARRAY( LocChange, end - p); int32 locLen = 0; for (; p < end; p++) { if (!p->isOop()) { // no oops here } else { oop oldOop = (oop)p->referent(this); if (oldOop == from) { changes[locLen].p = p; locLen ++; check_store(to, bound); needToInvalICache = true; } } } for (LocChange* l = &changes[0]; locLen > 0; locLen--, l++) { l->p->set_referent(this, (char*)to); } return needToInvalICache; }
bool OopNCode::code_oops_do(oopsDoFn f) { ResourceMark m; bool needToInvalICache = false; char* bound = Memory->new_gen->boundary(); addrDesc* p = locs(), *end = locsEnd(); LocChange* changes = NEW_RESOURCE_ARRAY( LocChange, end - p); int32 locLen = 0; for (; p < end; p++) { if (!p->isOop()) { // no oops here } else { oop oldOop = (oop)p->referent(this); oop newOop = oldOop; OOPS_DO_TEMPLATE(&newOop, f); if (newOop != oldOop) { changes[locLen].p = p; changes[locLen].newOop = newOop; locLen ++; check_store(newOop, bound); needToInvalICache = true; } } } for (LocChange* l = &changes[0]; locLen > 0; locLen--, l++) { l->p->set_referent(this, (char*)l->newOop); } return needToInvalICache; }
bool OopNCode::scavenge_contents() { ResourceMark m; bool needToInvalICache = false; char* bound = Memory->new_gen->boundary(); rememberLink.init(); addrDesc* p = locs(), *end = locsEnd(); LocChange* changes = NEW_RESOURCE_ARRAY( LocChange, end - p); int32 locLen = 0; for (; p < end; p++) { if (p->isOop()) { oop oldOop = (oop)p->referent(this); oop newOop = oldOop->scavenge(); if (newOop != oldOop) { changes[locLen].p = p; changes[locLen].newOop = newOop; locLen ++; needToInvalICache = true; } check_store(newOop, bound); } } for (LocChange* l = &changes[0]; locLen > 0; locLen--, l++) { l->p->set_referent(this, (char*)l->newOop); } return needToInvalICache; }
bool OopNCode::gc_unmark_contents() { ResourceMark m; bool needToInvalICache = false; addrDesc* p = locs(), *end = locsEnd(); LocChange* changes = NEW_RESOURCE_ARRAY( LocChange, end - p); int32 locLen = 0; for (; p < end; p++) { if (!p->isOop()) { // no oops here } else { oop oldOop = (oop)p->referent(this); oop newOop = oldOop; UNMARK_TEMPLATE(&newOop); if (newOop != oldOop) { changes[locLen].p = p; changes[locLen].newOop = newOop; locLen ++; needToInvalICache = true; } } } for (LocChange* l = &changes[0]; locLen > 0; locLen--, l++) { l->p->set_referent(this, (char*)l->newOop); } return needToInvalICache; }
fint nmethod::nsends(bool includeAll) { // add up the inlinable sends of the nmethod (i.e. those sent by inline // caches with comparing stubs); if includeAll, also count non-inlinable // sends fint nsends = 0; bool isNIC = compiler() == NIC; for (addrDesc* a = locs(), *aend = locsEnd(); a < aend; a++) { if (a->isSendDesc()) { sendDesc* sd = a->asSendDesc(this); if (!sd->isUninlinable()) { nsends += sd->nsends(); } else if (isNIC && sd->countType() == Counting) { // must be a method containing _Restart nsends += sd->nsends(); } else if (isNIC) { // NIC methods have no count stubs (to save space) but count the // # of invocations; assume all sends in NIC method are executed // once per execution of the method nsends += useCount[id]; } else if (includeAll) { nsends += sd->nsends(); } } } return nsends; }
bool nmethod::encompasses(void* p) { return includes(p, this, this + 1) || includes(p, deps(), depsEnd()) || includes(p, insts(), instsEnd()) || includes(p, locs(), locsEnd()) || scopes->includes((ScopeDesc*) p) || includes(p, pcs(), pcsEnd()); }
void nmethod::printLocs() { ResourceMark m; // in case methods get printed from gdb printIndent(); lprintf("locations:\n"); Indent ++; for (addrDesc* l = locs(); l < locsEnd(); l ++) l->print(this); Indent --; }
void ErrorMessageVerbose() const { std::list<ErrorLogger::ErrorMessage::FileLocation> locs(1, fooCpp5); ErrorMessage msg(locs, emptyString, Severity::error, "Programming error.\nVerbose error", "errorId", false); ASSERT_EQUALS(1, (int)msg._callStack.size()); ASSERT_EQUALS("Programming error.", msg.shortMessage()); ASSERT_EQUALS("Verbose error", msg.verboseMessage()); ASSERT_EQUALS("[foo.cpp:5]: (error) Programming error.", msg.toString(false)); ASSERT_EQUALS("[foo.cpp:5]: (error) Verbose error", msg.toString(true)); }
void CustomFormat2() const { std::list<ErrorLogger::ErrorMessage::FileLocation> locs(1, fooCpp5); ErrorMessage msg(locs, emptyString, Severity::error, "Programming error.\nVerbose error", "errorId", false); ASSERT_EQUALS(1, (int)msg._callStack.size()); ASSERT_EQUALS("Programming error.", msg.shortMessage()); ASSERT_EQUALS("Verbose error", msg.verboseMessage()); ASSERT_EQUALS("Programming error. - foo.cpp(5):(error,errorId)", msg.toString(false, "{message} - {file}({line}):({severity},{id})")); ASSERT_EQUALS("Verbose error - foo.cpp(5):(error,errorId)", msg.toString(true, "{message} - {file}({line}):({severity},{id})")); }
// unlink di Links and save them int32 nmethod::unlinkDI(nmln*& savedDIChildren) { int32 nlinks = 0; savedDIChildren = NEW_RESOURCE_ARRAY(nmln, locsEnd() - locs()); for (addrDesc* p = locs(), *pend = locsEnd(); p < pend; p++) { if (p->isDIDesc()) { nmln* l = p->asDIDesc(this)->dependency(); savedDIChildren[nlinks].init(); if (l->notEmpty()) { assert(l->next->next == l, "should be a pair"); l->next->rebind(&savedDIChildren[nlinks]); assert(savedDIChildren[nlinks].notEmpty(), "should have saved link"); } assert(p->asDIDesc(this)->dependency()->isEmpty(), "should be empty now"); nlinks++; } } return nlinks; }
int main(int argc, char *argv[]) { int *ids; loginit(NULL); Rng r; int usdargs = rng(&r, argc, argv); argc -= usdargs; argv += usdargs; int n = idargs(argc, argv, &ids); if (argc < 3) fatal("usage: enmgen [-s <seed>] <ID>+ <num>"); long num = strtol(argv[argc-1], NULL, 10); if (num == LLONG_MIN || num == LLONG_MAX) fatal("Invalid number: %s", argv[argc-1]); Zone *zn = zoneread(stdin); if (!zn) die("Failed to read the zone: %s", miderrstr()); Loc ls[zn->lvl->d * zn->lvl->w * zn->lvl->h]; int nls = locs(zn, ls); int i; for (i = 0; i < num && nls > 0; i++) { int idind = rngintincl(&r, 0, n); int lind = rngintincl(&r, 0, nls); Loc l = ls[lind]; if (nls > 1) ls[lind] = ls[nls-1]; nls--; Enemy enm; if (!enemyinit(&enm, ids[idind], l.p.x, l.p.y)) fatal("Failed to initialize enemy with ID: %d", ids[idind]); if (!zoneaddenemy(zn, l.z, enm)) { nls = rmz(ls, nls, l.z); num--; } } if (i < num) fatal("Failed to place all items"); zonewrite(stdout, zn); zonefree(zn); xfree(ids); return 0; }
void InconclusiveXml() const { // Location std::list<ErrorLogger::ErrorMessage::FileLocation> locs(1, fooCpp5); // Inconclusive error message ErrorMessage msg(locs, emptyString, Severity::error, "Programming error", "errorId", true); // xml version 2 error message ASSERT_EQUALS(" <error id=\"errorId\" severity=\"error\" msg=\"Programming error\" verbose=\"Programming error\" inconclusive=\"true\">\n" " <location file=\"foo.cpp\" line=\"5\"/>\n" " </error>", msg.toXML()); }
void ToXmlV2() const { std::list<ErrorLogger::ErrorMessage::FileLocation> locs(1, fooCpp5); ErrorMessage msg(locs, emptyString, Severity::error, "Programming error.\nVerbose error", "errorId", false); std::string header("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<results version=\"2\">\n"); header += " <cppcheck version=\""; header += CppCheck::version(); header += "\"/>\n <errors>"; ASSERT_EQUALS(header, ErrorLogger::ErrorMessage::getXMLHeader()); ASSERT_EQUALS(" </errors>\n</results>", ErrorLogger::ErrorMessage::getXMLFooter()); std::string message(" <error id=\"errorId\" severity=\"error\""); message += " msg=\"Programming error.\" verbose=\"Verbose error\">\n"; message += " <location file=\"foo.cpp\" line=\"5\"/>\n </error>"; ASSERT_EQUALS(message, msg.toXML()); }
// remove this methods PICs; return total size of flushed PICs int32 nmethod::flushPICs() { int32 flushed = 0; for (addrDesc* p = locs(), *pend = locsEnd(); p < pend; p++) { if (p->isSendDesc()) { sendDesc* sd = p->asSendDesc(this); CacheStub* s = sd->pic(); if (s) { flushed += s->size(); s->deallocate(); } } } MachineCache::flush_instruction_cache_for_debugging(); return flushed; }
arma_hot inline void spop_htrans::apply(SpMat<typename T1::elem_type>& out, const SpOp<T1,spop_htrans>& in, const typename arma_cx_only<typename T1::elem_type>::result* junk) { arma_extra_debug_sigprint(); arma_ignore(junk); typedef typename T1::elem_type eT; typedef typename umat::elem_type ueT; const SpProxy<T1> p(in.m); const uword N = p.get_n_nonzero(); if(N == uword(0)) { out.set_size(p.get_n_cols(), p.get_n_rows()); return; } umat locs(2, N); Col<eT> vals(N); eT* vals_ptr = vals.memptr(); typename SpProxy<T1>::const_iterator_type it = p.begin(); for(uword count = 0; count < N; ++count) { ueT* locs_ptr = locs.colptr(count); locs_ptr[0] = it.col(); locs_ptr[1] = it.row(); vals_ptr[count] = std::conj(*it); ++it; } SpMat<eT> tmp(locs, vals, p.get_n_cols(), p.get_n_rows()); out.steal_mem(tmp); }
arma_hot inline void spop_strans::apply_proxy(SpMat<typename T1::elem_type>& out, const T1& X) { arma_extra_debug_sigprint(); typedef typename T1::elem_type eT; typedef typename umat::elem_type ueT; const SpProxy<T1> p(X); const uword N = p.get_n_nonzero(); if(N == uword(0)) { out.zeros(p.get_n_cols(), p.get_n_rows()); return; } umat locs(2, N); Col<eT> vals(N); eT* vals_ptr = vals.memptr(); typename SpProxy<T1>::const_iterator_type it = p.begin(); for(uword count = 0; count < N; ++count) { ueT* locs_ptr = locs.colptr(count); locs_ptr[0] = it.col(); locs_ptr[1] = it.row(); vals_ptr[count] = (*it); ++it; } SpMat<eT> tmp(locs, vals, p.get_n_cols(), p.get_n_rows()); out.steal_mem(tmp); }
void nmethod::relinkDI(int32 n, nmln*& savedDIChildren) { Unused(n); int32 nlinks = 0; for (addrDesc* p = locs(), *pend = locsEnd(); p < pend; p++) { if (p->isDIDesc()) { assert(nlinks < n, "too many DI caches in method"); nmln* l = p->asDIDesc(this)->dependency(); assert(l->isEmpty(), "should be empty"); if (savedDIChildren[nlinks].notEmpty()) { nmln* ln = savedDIChildren[nlinks].next; // cfront bug! ln->rebind(l); nmethod* target = findNMethod(ln); p->asDIDesc(this)->set_jump_addr(target->insts()); assert(p->asDIDesc(this)->dependency()->notEmpty(), "should be rebound now"); } nlinks++; } } MachineCache::flush_instruction_cache_for_debugging(); assert(n == nlinks, "too few DI links in method"); }
void scatter(std::vector<hpx::id_type> const & localities, hpx::util::serialize_buffer<char> buffer, std::size_t chunk_size) { std::vector<hpx::future<void> > scatter_futures; scatter_futures.reserve(localities.size() / chunk_size); typedef std::vector<hpx::id_type>::const_iterator iterator; iterator begin = localities.cbegin() + 1; if(localities.size() > 1) { for(std::size_t i = 0; i < chunk_size; ++i) { iterator end = (i == chunk_size-1) ? localities.cend() : begin + (localities.size() - 1)/chunk_size + 1; std::vector<hpx::id_type> locs(begin, end); if(locs.size() > 0) { hpx::id_type dst = locs[0]; scatter_futures.push_back( hpx::async<scatter_action>(dst, boost::move(locs), buffer, chunk_size) ); } begin = end; } } // Call some action for this locality here ... if(scatter_futures.size() > 0) { hpx::wait_all(scatter_futures); } }
void OopNCode::relocate() { ResourceMark m; addrDesc* p = locs(), *end = locsEnd(); LocChange* changes = NEW_RESOURCE_ARRAY( LocChange, end - p); int32 locLen = 0; for (; p < end; p++) { if (!p->isOop()) { // no oops here } else { oop oldOop = (oop)p->referent(this); oop newOop = oldOop; RELOCATE_TEMPLATE(&newOop); if (newOop != oldOop) { changes[locLen].p = p; changes[locLen].newOop = newOop; locLen ++; } } } for (LocChange* l = &changes[0]; locLen > 0; locLen--, l++) { l->p->set_referent(this, (char*)l->newOop); } }
arma_hot inline void spop_strans::apply_spmat(SpMat<eT>& out, const SpMat<eT>& X) { arma_extra_debug_sigprint(); typedef typename umat::elem_type ueT; const uword N = X.n_nonzero; if(N == uword(0)) { out.zeros(X.n_cols, X.n_rows); return; } umat locs(2, N); typename SpMat<eT>::const_iterator it = X.begin(); for(uword count = 0; count < N; ++count) { ueT* locs_ptr = locs.colptr(count); locs_ptr[0] = it.col(); locs_ptr[1] = it.row(); ++it; } const Col<eT> vals(const_cast<eT*>(X.values), N, false); SpMat<eT> tmp(locs, vals, X.n_cols, X.n_rows); out.steal_mem(tmp); }
bool OopNCode::verify() { bool r = true; const char* name = isNMethod() ? "nmethod" : (isCacheStub() ? " PIC" : "count stub"); NCodeBase::verify2(name); if (!rememberLink.verify_list_integrity()) { lprintf("\tof rememberLink of %s %#lx\n", name, this); r = false; } for (addrDesc* l = locs(); l < locsEnd(); l++) { bool ok = isNMethod() ? l->verify((nmethod*)this) : l->verify((CacheStub*)this); if (! ok) { lprintf("\t\tin %s at %#lx\n", name, this); r = false; } else if (l->isOop() && // not no oops here oop(l->referent(this))->is_new() && rememberLink.isEmpty()) { error2("%s %#lx should be remembered", name, this); r = false; } } return r; }
static void find_routes(const gamemap& map, const unit_map& units, const unit& u, const map_location& loc, int move_left, paths::dest_vect &destinations, std::vector<team> const &teams, bool force_ignore_zocs, bool allow_teleport, int turns_left, const team &viewing_team, bool see_all, bool ignore_units) { const team& current_team = teams[u.side() - 1]; std::set<map_location> teleports; if (allow_teleport) { teleports = get_teleport_locations(u, units, viewing_team, see_all, ignore_units); } const int total_movement = u.total_movement(); std::vector<map_location> locs(6 + teleports.size()); std::copy(teleports.begin(), teleports.end(), locs.begin() + 6); search_counter += 2; if (search_counter == 0) search_counter = 2; static std::vector<node> nodes; nodes.resize(map.w() * map.h()); indexer index(map.w(), map.h()); comp node_comp(nodes); int xmin = loc.x, xmax = loc.x, ymin = loc.y, ymax = loc.y, nb_dest = 1; nodes[index(loc)] = node(move_left, turns_left, map_location::null_location, loc); std::vector<int> pq; pq.push_back(index(loc)); while (!pq.empty()) { node& n = nodes[pq.front()]; std::pop_heap(pq.begin(), pq.end(), node_comp); pq.pop_back(); n.in = search_counter; get_adjacent_tiles(n.curr, &locs[0]); for (int i = teleports.count(n.curr) ? locs.size() : 6; i-- > 0; ) { if (!locs[i].valid(map.w(), map.h())) continue; node& next = nodes[index(locs[i])]; bool next_visited = next.in - search_counter <= 1u; // Classic Dijkstra allow to skip chosen nodes (with next.in==search_counter) // But the cost function and hex grid allow to also skip visited nodes: // if next was visited, then we already have a path 'src-..-n2-next' // - n2 was chosen before n, meaning that it is nearer to src. // - the cost of 'n-next' can't be smaller than 'n2-next' because // cost is independent of direction and we don't have more MP at n // (important because more MP may allow to avoid waiting next turn) // Thus, 'src-..-n-next' can't be shorter. if (next_visited) continue; const int move_cost = u.movement_cost(map[locs[i]]); node t = node(n.movement_left, n.turns_left, n.curr, locs[i]); if (t.movement_left < move_cost) { t.movement_left = total_movement; t.turns_left--; } if (t.movement_left < move_cost || t.turns_left < 0) continue; t.movement_left -= move_cost; if (!ignore_units) { const unit *v = get_visible_unit(units, locs[i], viewing_team, see_all); if (v && current_team.is_enemy(v->side())) continue; if (!force_ignore_zocs && t.movement_left > 0 && enemy_zoc(units, teams, locs[i], viewing_team, u.side(), see_all) && !u.get_ability_bool("skirmisher", locs[i])) { t.movement_left = 0; } } ++nb_dest; int x = locs[i].x; if (x < xmin) xmin = x; if (xmax < x) xmax = x; int y = locs[i].y; if (y < ymin) ymin = y; if (ymax < y) ymax = y; bool in_list = next.in == search_counter + 1; t.in = search_counter + 1; next = t; // if already in the priority queue then we just update it, else push it. if (in_list) { // never happen see next_visited above std::push_heap(pq.begin(), std::find(pq.begin(), pq.end(), index(locs[i])) + 1, node_comp); } else { pq.push_back(index(locs[i])); std::push_heap(pq.begin(), pq.end(), node_comp); } } } // Build the routes for every map_location that we reached. // The ordering must be compatible with map_location::operator<. destinations.reserve(nb_dest); for (int x = xmin; x <= xmax; ++x) { for (int y = ymin; y <= ymax; ++y) { const node &n = nodes[index(map_location(x, y))]; if (n.in - search_counter > 1u) continue; paths::step s = { n.curr, n.prev, n.movement_left + n.turns_left * total_movement }; destinations.push_back(s); } } }
int symex_parseoptionst::doit() { if(cmdline.isset("version")) { std::cout << CBMC_VERSION << std::endl; return 0; } register_language(new_ansi_c_language); register_language(new_cpp_language); // // command line options // optionst options; get_command_line_options(options); eval_verbosity(); goto_functionst goto_functions; if(get_goto_program(options, goto_functions)) return 6; label_properties(goto_functions); if(cmdline.isset("show-properties")) { const namespacet ns(symbol_table); show_properties(ns, get_ui(), goto_functions); return 0; } if(set_properties(goto_functions)) return 7; if(cmdline.isset("show-locs")) { const namespacet ns(symbol_table); locst locs(ns); locs.build(goto_functions); locs.output(std::cout); return 0; } // do actual Symex try { const namespacet ns(symbol_table); path_searcht path_search(ns); path_search.set_message_handler(get_message_handler()); path_search.set_verbosity(get_verbosity()); if(cmdline.isset("depth")) path_search.depth_limit=unsafe_string2unsigned(cmdline.getval("depth")); if(cmdline.isset("context-bound")) path_search.context_bound=unsafe_string2unsigned(cmdline.getval("context-bound")); if(cmdline.isset("unwind")) path_search.unwind_limit=unsafe_string2unsigned(cmdline.getval("unwind")); if(cmdline.isset("show-vcc")) { path_search.show_vcc=true; path_search(goto_functions); return 0; } // do actual symex switch(path_search(goto_functions)) { case safety_checkert::SAFE: report_properties(path_search.property_map); report_success(); return 0; case safety_checkert::UNSAFE: report_properties(path_search.property_map); report_failure(); return 10; default: return 8; } } catch(const std::string error_msg) { error() << error_msg << messaget::eom; return 8; } catch(const char *error_msg) { error() << error_msg << messaget::eom; return 8; } #if 0 // let's log some more statistics debug() << "Memory consumption:" << messaget::endl; memory_info(debug()); debug() << eom; #endif }
/* * Testing the perturbers */ int main(int argc, char** argv) { if (argc != 2) BNB_ERROR_REPORT("Usage: searchmbh.exe json_file\n"); std::string jsons; FileUtils::getStringFromFile(argv[1], jsons); lur::ParseJson::parseModelData(jsons, mm); double ev; lur::ParseJson::parseLatticeData(jsons, mm, ev, x); #if 0 lur::PotentialCutter pc(6, 0.5, lur::ljpotent); lur::PairPotentialEnergy enrg(mm, pc); #endif #if 0 // Morse lur::PairPotentialEnergy enrg(mm, morsepotent); #endif #if 1 // Tersoff lur::TersoffParams tparam; lur::fillCarbonParametersTersoffOriginal(tparam); lur::TersoffUtils tutils(tparam); lur::TersoffEnergy enrg(mm, tutils); //enrg.setFixedAtoms(true); #endif const int N = mm.mNumLayers * 3; lur::LurieObj obj(enrg, mm); NumGradObjective<double> nobj(obj); nobj.setH(1E-8); Box<double> box(N); lur::ParseJson::parseBoxData(jsons, box); NlpProblem<double> prob; prob.mBox = box; prob.mObj = &obj; BBStopper stp; BBBoxDescent<double> locs(box, &stp); locs.getOptions().mHInit = 4; locs.getOptions().mDec = 0.5; locs.getOptions().mHLB = 1e-6; locs.getOptions().mInc = 1.75; locs.setObjective(&nobj); RndFill<double> rfill(box); Box<double> vicinity(N); initVicinity(N, vicinity); #if 0 StaticPerturber<double> perturber(prob, vicinity); #else AdaptPerturber<double> perturber(prob, vicinity, AdaptPerturber<double>::Params({1, .01, 2, 0.1, 1.1})); #endif #if 0 MBHBoxCon<double> mbhbc(prob, perturber, H); #else MBHBoxCon<double> mbhbc(prob, perturber, H, &locs); #endif signal(SIGINT, output); bv = mbhbc.search(x); std::cout << "Found v = " << bv << "\n"; VecUtils::vecPrint(N, x); std::string json; json += "{\n"; lur::GenJSON::genModel(mm, json); json += ", \n"; lur::GenJSON::genBox(box, json); json += ", \n"; lur::GenJSON::genLattice(mm, bv, x, json); json += "\n}\n"; std::cout << json << "\n"; return 0; }
int DispBeamColumn2d::getResponse(int responseID, Information &eleInfo) { double V; double L = crdTransf->getInitialLength(); if (responseID == 1) return eleInfo.setVector(this->getResistingForce()); else if (responseID == 12) { P.Zero(); P.addVector(1.0, this->getRayleighDampingForces(), 1.0); return eleInfo.setVector(P); } else if (responseID == 2) { P(3) = q(0); P(0) = -q(0)+p0[0]; P(2) = q(1); P(5) = q(2); V = (q(1)+q(2))/L; P(1) = V+p0[1]; P(4) = -V+p0[2]; return eleInfo.setVector(P); } else if (responseID == 9) { return eleInfo.setVector(q); } else if (responseID == 19) { static Matrix kb(3,3); this->getBasicStiff(kb); return eleInfo.setMatrix(kb); } // Chord rotation else if (responseID == 3) { return eleInfo.setVector(crdTransf->getBasicTrialDisp()); } // Plastic rotation else if (responseID == 4) { static Vector vp(3); static Vector ve(3); const Matrix &kb = this->getInitialBasicStiff(); kb.Solve(q, ve); vp = crdTransf->getBasicTrialDisp(); vp -= ve; return eleInfo.setVector(vp); } // Curvature sensitivity else if (responseID == 5) { /* Vector curv(numSections); const Vector &v = crdTransf->getBasicDispGradient(1); double L = crdTransf->getInitialLength(); double oneOverL = 1.0/L; //const Matrix &pts = quadRule.getIntegrPointCoords(numSections); double pts[2]; pts[0] = 0.0; pts[1] = 1.0; // Loop over the integration points for (int i = 0; i < numSections; i++) { int order = theSections[i]->getOrder(); const ID &code = theSections[i]->getType(); //double xi6 = 6.0*pts(i,0); double xi6 = 6.0*pts[i]; curv(i) = oneOverL*((xi6-4.0)*v(1) + (xi6-2.0)*v(2)); } return eleInfo.setVector(curv); */ Vector curv(numSections); /* // Loop over the integration points for (int i = 0; i < numSections; i++) { int order = theSections[i]->getOrder(); const ID &code = theSections[i]->getType(); const Vector &dedh = theSections[i]->getdedh(); for (int j = 0; j < order; j++) { if (code(j) == SECTION_RESPONSE_MZ) curv(i) = dedh(j); } } */ return eleInfo.setVector(curv); } // Basic deformation sensitivity else if (responseID == 6) { const Vector &dvdh = crdTransf->getBasicDisplSensitivity(1); return eleInfo.setVector(dvdh); } else if (responseID == 7) { //const Matrix &pts = quadRule.getIntegrPointCoords(numSections); double xi[maxNumSections]; beamInt->getSectionLocations(numSections, L, xi); Vector locs(numSections); for (int i = 0; i < numSections; i++) locs(i) = xi[i]*L; return eleInfo.setVector(locs); } else if (responseID == 8) { //const Vector &wts = quadRule.getIntegrPointWeights(numSections); double wt[maxNumSections]; beamInt->getSectionWeights(numSections, L, wt); Vector weights(numSections); for (int i = 0; i < numSections; i++) weights(i) = wt[i]*L; return eleInfo.setVector(weights); } else return Element::getResponse(responseID, eleInfo); }
path_searcht::resultt path_searcht::operator()( const goto_functionst &goto_functions) { #ifdef PATH_SYMEX_FORK // Disable output because there is no meaningful way // to write text when multiple path_search processes // run concurrently. This could be remedied by piping // to individual files or inter-process communication, // a performance bottleneck, however. *messaget::mstream.message_handler=NULL; #endif locst locs(ns); var_mapt var_map(ns); locs.build(goto_functions); // this is the container for the history-forest path_symex_historyt history; queue.push_back(initial_state(var_map, locs, history)); // set up the statistics number_of_paths=0; number_of_instructions=0; number_of_dropped_states=0; number_of_VCCs=0; number_of_VCCs_after_simplification=0; number_of_failed_properties=0; number_of_fast_forward_steps=0; // stop the time start_time=current_time(); initialize_property_map(goto_functions); while(!queue.empty()) { // Pick a state from the queue, // according to some heuristic. queuet::iterator state=pick_state(); // fast forwarding required? if(state->is_lazy()) { assert(state->is_executable()); assert(state->history.is_nil()); // keep allocated memory, this is faster than // instantiating a new empty vector and map history.clear(); var_map.clear(); state->history=path_symex_step_reft(history); // restore all fields of a lazy state by symbolic // execution along previously recorded branches const queuet::size_type queue_size=queue.size(); do { number_of_fast_forward_steps++; path_symex(*state, queue); #ifdef PATH_SYMEX_OUTPUT status() << "Fast forward thread " << state->get_current_thread() << "/" << state->threads.size() << " PC " << state->pc() << messaget::eom; #endif } while(state->is_lazy() && state->is_executable()); assert(queue.size() == queue_size); } // TODO: check lazy states before fast forwarding, or perhaps it // is better to even check before inserting into queue if(drop_state(*state)) { number_of_dropped_states++; queue.erase(state); continue; } if(!state->is_executable()) { queue.erase(state); continue; } // count only executable instructions number_of_instructions++; #ifdef PATH_SYMEX_OUTPUT status() << "Queue " << queue.size() << " thread " << state->get_current_thread() << "/" << state->threads.size() << " PC " << state->pc() << messaget::eom; #endif // an error, possibly? if(state->get_instruction()->is_assert()) { if(show_vcc) do_show_vcc(*state, ns); else { check_assertion(*state, ns); // all assertions failed? if(number_of_failed_properties==property_map.size()) break; } } #ifdef PATH_SYMEX_FORK if(try_await()) { debug() << "Child process has terminated " "so exit parent" << messaget::eom; break; } #endif // execute and record whether a "branch" occurred const queuet::size_type queue_size = queue.size(); path_symex(*state, queue); assert(queue_size <= queue.size()); number_of_paths += (queue.size() - queue_size); } #ifdef PATH_SYMEX_FORK int exit_status=await(); if(exit_status==0 && number_of_failed_properties!=0) { // the eldest child process (if any) reports found bugs report_statistics(); return UNSAFE; } else { // either a child found and reported a bug or // the parent's search partition is safe switch (exit_status) { case 0: return SAFE; case 10: return UNSAFE; default: return ERROR; } } #else report_statistics(); return number_of_failed_properties==0?SAFE:UNSAFE; #endif }
int ElasticForceBeamColumn2d::getResponse(int responseID, Information &eleInfo) { static Vector Se(NEBD); static Vector vp(NEBD); static Matrix fe(NEBD,NEBD); if (responseID == 1) return eleInfo.setVector(this->getResistingForce()); else if (responseID == 2) { double p0[3]; p0[0] = 0.0; p0[1] = 0.0; p0[2] = 0.0; if (numEleLoads > 0) this->computeReactions(p0); this->computeBasicForces(Se); theVector(3) = Se(0); theVector(0) = -Se(0)+p0[0]; theVector(2) = Se(1); theVector(5) = Se(2); double V = (Se(1)+Se(2))/crdTransf->getInitialLength(); theVector(1) = V+p0[1]; theVector(4) = -V+p0[2]; return eleInfo.setVector(theVector); } // Chord rotation else if (responseID == 7) { this->computeBasicForces(Se); return eleInfo.setVector(Se); } // Chord rotation else if (responseID == 3) { vp = crdTransf->getBasicTrialDisp(); return eleInfo.setVector(vp); } // Plastic rotation else if (responseID == 4) { this->computeBasicForces(Se); this->getInitialFlexibility(fe); vp = crdTransf->getBasicTrialDisp(); vp.addMatrixVector(1.0, fe, Se, -1.0); return eleInfo.setVector(vp); } // Point of inflection else if (responseID == 5) { double LI = 0.0; this->computeBasicForces(Se); if (fabs(Se(1)+Se(2)) > DBL_EPSILON) { double L = crdTransf->getInitialLength(); LI = Se(1)/(Se(1)+Se(2))*L; } return eleInfo.setDouble(LI); } else if (responseID == 7) { this->computeBasicForces(Se); return eleInfo.setVector(Se); } else if (responseID == 10) { double L = crdTransf->getInitialLength(); double pts[maxNumSections]; beamIntegr->getSectionLocations(numSections, L, pts); Vector locs(numSections); for (int i = 0; i < numSections; i++) locs(i) = pts[i]*L; return eleInfo.setVector(locs); } else if (responseID == 11) { double L = crdTransf->getInitialLength(); double wts[maxNumSections]; beamIntegr->getSectionWeights(numSections, L, wts); Vector weights(numSections); for (int i = 0; i < numSections; i++) weights(i) = wts[i]*L; return eleInfo.setVector(weights); } else return -1; }
IntVect iMultiFab::maxIndex (int comp, int nghost) const { BL_ASSERT(nghost >= 0 && nghost <= n_grow); IntVect loc; int mx = -std::numeric_limits<int>::max(); #ifdef _OPENMP #pragma omp parallel #endif { IntVect priv_loc; int priv_mx = -std::numeric_limits<int>::max(); for (MFIter mfi(*this); mfi.isValid(); ++mfi) { const Box& box = BoxLib::grow(mfi.validbox(),nghost); const int lmx = get(mfi).max(box,comp); if (lmx > priv_mx) { priv_mx = lmx; priv_loc = get(mfi).maxIndex(box,comp); } } #ifdef _OPENMP #pragma omp critical (imultifab_maxindex) #endif { if (priv_mx > mx) { mx = priv_mx; loc = priv_loc; } } } const int NProcs = ParallelDescriptor::NProcs(); if (NProcs > 1) { Array<int> mxs(1); Array<int> locs(1); if (ParallelDescriptor::IOProcessor()) { mxs.resize(NProcs); locs.resize(NProcs*BL_SPACEDIM); } const int IOProc = ParallelDescriptor::IOProcessorNumber(); ParallelDescriptor::Gather(&mx, 1, mxs.dataPtr(), 1, IOProc); BL_ASSERT(sizeof(IntVect) == sizeof(int)*BL_SPACEDIM); ParallelDescriptor::Gather(loc.getVect(), BL_SPACEDIM, locs.dataPtr(), BL_SPACEDIM, IOProc); if (ParallelDescriptor::IOProcessor()) { mx = mxs[0]; loc = IntVect(D_DECL(locs[0],locs[1],locs[2])); for (int i = 1; i < NProcs; i++) { if (mxs[i] > mx) { mx = mxs[i]; const int j = BL_SPACEDIM * i; loc = IntVect(D_DECL(locs[j+0],locs[j+1],locs[j+2])); } } } ParallelDescriptor::Bcast(const_cast<int*>(loc.getVect()), BL_SPACEDIM, IOProc); } return loc; }
bool nmethod::verify() { bool r = true; ResourceMark rm; r &= OopNCode::verify2("nmethod"); if (insts() != (char*)(this + 1)) { error1("nmethod at 0x%lx has incorrect insts pointer", this); r = false; } if (!Memory->code->contains(this)) { error1("nmethod at 0x%lx not in zone", this); r = false; } if (!zoneLink.verify_list_integrity()) { lprintf("\tof zoneLink of nmethod 0x%lx\n", this); r = false; } { FOR_MY_CODETABLE_ENTRIES(e) if (e->nm != this) { error1("bad code table link for nmethod %#lx\n", this); r = false; } } bool isAligned = (frame_size & (frame_word_alignment-1)) == 0; if (!isAligned) { lprintf("nmethod at %#lx: frame size is not multiple of %d words\n", (long unsigned)this, frame_word_alignment); r = false; } if (codeTableLink != NULL) { nmethod *tableResult = isDebug() ? Memory->code->debugTable->lookup(key) : Memory->code->table ->lookup(key); if (tableResult != this) { error1("nmethod at %#lx: code table lookup failed", this); r = false; } } if (!key.verify()) { lprintf("\tof key of nmethod 0x%lx\n", this); r = false; } { FOR_MY_CODETABLE_ENTRIES(e) if (!e->key.verify()) { lprintf("\tof code table key %#lx of nmethod 0x%lx\n", (long unsigned)&e->key, (long unsigned)this); r = false; } } if (!linkedSends.verify_list_integrity()) { lprintf("\tof linkedSends of nmethod 0x%lx\n", this); r = false; } if (!diLink.verify_list_integrity()) { lprintf("\tof diLink of nmethod 0x%lx\n", this); r = false; } r &= scopes->verify(); for (PcDesc* p = pcs(); p < pcsEnd(); p++) { if (! p->verify(this)) { lprintf("\t\tin nmethod at %#lx (pcs)\n", this); r = false; } } // more checks in ncode::verify called above bool shouldBeDI = diLink.notEmpty(); for (addrDesc* l = locs(); l < locsEnd(); l++) { if (l->isDIDesc()) { shouldBeDI = true; } } if (shouldBeDI && !isDI()) { error1("nmethod %#lx should be marked isDI", this); r = false; } else if (!shouldBeDI && isDI()) { error1("nmethod %#lx should not be marked isDI", this); r = false; } if (! key.receiverMap()->is_block() ) { for (nmln* d = deps(); d < depsEnd(); d++) { if (! d->verify_list_integrity()) { lprintf("\tin nmethod at %#lx (deps)\n", this); r = false; } } } if (frame_chain != NoFrameChain) { error1("nmethod %#lx has non-zero frame chain value", this); r = false; } if (findNMethod( instsEnd() - oopSize) != this) { error1("findNMethod did not find this nmethod (%#lx)", this); r = false; } return r; }
void nmethod::moveTo_inner(NCodeBase* p, int32 delta, int32 size) { nmethod* to = (nmethod*)p; if (this == to) return; if (PrintCodeCompaction) { lprintf("*moving nmethod %#lx (", this); printName(0, key.selector); lprintf(") to %#lx\n", to); } OopNCode::moveTo_inner(to, delta, size); assert(iabs((char*)to - (char*)this) >= sizeof(NCodeBase), "nmethods overlap too much"); assert(sizeof(NCodeBase) % oopSize == 0, "should be word-aligned"); // init to's vtable copy_words((int32*)this, (int32*)to, sizeof(NCodeBase) / sizeof(int32)); scopes->_nmethod_backPointer = to; *dBackLinkAddr() = to; flatProfiler->move(insts(), instsEnd(), to->insts()); zoneLink.shift(delta); FOR_MY_CODETABLE_ENTRIES(e) { e->nm= to; } for (nmln *x = linkedSends.next, *y = x->next; x != &linkedSends; x = y, y = y->next) { NCodeBase* s = findThing(x); s->shift_target(x, delta); } linkedSends.shift(delta, this); if (diLink.notEmpty()) { assert(diLink.next->next == &diLink, "diLink should be a pair"); diLink.next->asDIDesc()->shift_jump_addr(delta); } diLink.shift(delta); for (addrDesc* q = locs(), *pend = locsEnd(); q < pend; q++) { if (q->isSendDesc()) { sendDesc* sd = q->asSendDesc(this); sd->shift(delta, this); } else if (q->isDIDesc()) { nmln* l = q->asDIDesc(this)->dependency(); l->shift(delta); } q->shift(this, delta); } if (frame_chain != NoFrameChain && frame_chain != SavedFrameChain) frame_chain->nmethod_moved_by(delta, this); }