tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

JitHints-inl.h (1949B)


      1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
      2 * vim: set ts=8 sts=2 et sw=2 tw=80:
      3 * This Source Code Form is subject to the terms of the Mozilla Public
      4 * License, v. 2.0. If a copy of the MPL was not distributed with this
      5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      6 
      7 #ifndef jit_JitHints_inl_h
      8 #define jit_JitHints_inl_h
      9 
     10 #include "jit/JitHints.h"
     11 #include "mozilla/HashFunctions.h"
     12 
     13 namespace js::jit {
     14 
     15 inline JitHintsMap::ScriptKey JitHintsMap::getScriptKey(
     16    JSScript* script) const {
     17  ScriptKey filenameHash = script->filenameHash();
     18  // Do not include scrips that have an introducer filename.  These include
     19  // dynamically created scripts such as eval() and new Function() which
     20  // have a high probability of containing difference source.
     21  if (filenameHash && !script->scriptSource()->hasIntroducerFilename()) {
     22    return mozilla::AddToHash(filenameHash, script->sourceStart());
     23  }
     24  return 0;
     25 }
     26 
     27 inline void JitHintsMap::incrementBaselineEntryCount() {
     28  // Clear the cache if we've exceeded the false positivity rate
     29  // calculated by MaxEntries.
     30  if (++baselineEntryCount_ > MaxEntries_) {
     31    baselineHintMap_.clear();
     32    baselineEntryCount_ = 0;
     33  }
     34 }
     35 
     36 inline void JitHintsMap::setEagerBaselineHint(JSScript* script) {
     37  ScriptKey key = getScriptKey(script);
     38  if (!key) {
     39    return;
     40  }
     41 
     42  // If the entry already exists, don't increment entryCount.
     43  if (baselineHintMap_.mightContain(key)) {
     44    return;
     45  }
     46 
     47  // Increment entry count, and possibly clear the cache.
     48  incrementBaselineEntryCount();
     49 
     50  script->setNoEagerBaselineHint(false);
     51  baselineHintMap_.add(key);
     52 }
     53 
     54 inline bool JitHintsMap::mightHaveEagerBaselineHint(JSScript* script) const {
     55  if (ScriptKey key = getScriptKey(script)) {
     56    return baselineHintMap_.mightContain(key);
     57  }
     58  script->setNoEagerBaselineHint(true);
     59  return false;
     60 }
     61 
     62 }  // namespace js::jit
     63 
     64 #endif /* jit_JitHints_inl_h */