void Translator::addTranslation(const TransRec& transRec) { if (Trace::moduleEnabledRelease(Trace::trans, 1)) { // Log the translation's size, creation time, SrcKey, and size Trace::traceRelease("New translation: %" PRId64 " %s %u %u %d\n", HPHP::Timer::GetCurrentTimeMicros() - m_createdTime, folly::format("{}:{}:{}", transRec.src.unit()->filepath(), transRec.src.funcID(), transRec.src.offset()).str().c_str(), transRec.aLen, transRec.acoldLen, static_cast<int>(transRec.kind)); } if (!isTransDBEnabled()) return; mcg->assertOwnsCodeLock(); TransID id = transRec.id == kInvalidTransID ? m_translations.size() : transRec.id; if (id >= m_translations.size()) { m_translations.resize(id + 1); } m_translations[id] = transRec; m_translations[id].id = id; if (transRec.aLen > 0) { m_transDB[transRec.aStart] = id; } if (transRec.acoldLen > 0) { m_transDB[transRec.acoldStart] = id; } // Optimize storage of the created TransRec. m_translations[id].optimizeForMemory(); }
void Translator::addTranslation(const TransRec& transRec) { if (Trace::moduleEnabledRelease(Trace::trans, 1)) { // Log the translation's size, creation time, SrcKey, and size Trace::traceRelease("New translation: %" PRId64 " %s %u %u %d\n", HPHP::Timer::GetCurrentTimeMicros() - m_createdTime, folly::format("{}:{}:{}", transRec.src.unit()->filepath(), transRec.src.funcID(), transRec.src.offset()).str().c_str(), transRec.aLen, transRec.acoldLen, static_cast<int>(transRec.kind)); } if (!isTransDBEnabled()) return; uint32_t id = getCurrentTransID(); m_translations.emplace_back(transRec); auto& newTransRec = m_translations[id]; newTransRec.id = id; if (transRec.aLen > 0) { m_transDB[transRec.aStart] = id; } if (transRec.acoldLen > 0) { m_transDB[transRec.acoldStart] = id; } // Optimize storage of the created TransRec. newTransRec.optimizeForMemory(); }
uint64_t Translator::getTransCounter(TransID transId) const { if (!isTransDBEnabled()) return -1ul; assertx(transId < m_translations.size()); uint64_t counter; if (transId / transCountersPerChunk >= m_transCounters.size()) { counter = 0; } else { counter = m_transCounters[transId / transCountersPerChunk] [transId % transCountersPerChunk]; } return counter; }
uint64_t* Translator::getTransCounterAddr() { if (!isTransDBEnabled()) return nullptr; TransID id = m_translations.size(); // allocate a new chunk of counters if necessary if (id >= m_transCounters.size() * transCountersPerChunk) { uint32_t size = sizeof(uint64_t) * transCountersPerChunk; auto *chunk = (uint64_t*)malloc(size); bzero(chunk, size); m_transCounters.push_back(chunk); } assertx(id / transCountersPerChunk < m_transCounters.size()); return &(m_transCounters[id / transCountersPerChunk] [id % transCountersPerChunk]); }