/usr/include/hphp/util/code-cache.h is in hhvm-dev 3.11.1+dfsg-1ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 | /*
+----------------------------------------------------------------------+
| HipHop for PHP |
+----------------------------------------------------------------------+
| Copyright (c) 2010-2015 Facebook, Inc. (http://www.facebook.com) |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| http://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
*/
#ifndef incl_HPHP_UTIL_CODE_CACHE_H_
#define incl_HPHP_UTIL_CODE_CACHE_H_
#include "hphp/util/data-block.h"
namespace HPHP {
#if defined(__APPLE__) || defined(__CYGWIN__) || defined(_MSC_VER)
extern const void* __hot_start;
extern const void* __hot_end;
#else
extern "C" {
void __attribute__((__weak__)) __hot_start();
void __attribute__((__weak__)) __hot_end();
}
#endif
struct CodeCache {
enum class Selection {
Default, // 'main'
Hot, // 'hot'
Profile, // 'prof' -- highest precedence
};
struct Selector;
/* Code block sizes read from configs. */
static uint64_t AHotSize;
static uint64_t ASize;
static uint64_t AProfSize;
static uint64_t AColdSize;
static uint64_t AFrozenSize;
static uint64_t GlobalDataSize;
static uint64_t AMaxUsage;
static bool MapTCHuge;
static uint32_t AutoTCShift;
static uint32_t TCNumHugeHotMB;
static uint32_t TCNumHugeColdMB;
CodeCache();
~CodeCache();
CodeBlock& blockFor(CodeAddress addr);
template<typename L>
void forEachBlock(L body) const {
body("hot", m_hot);
body("main", m_main);
body("prof", m_prof);
body("cold", m_cold);
body("frozen", m_frozen);
}
size_t codeSize() const { return m_codeSize; }
// Returns the total amount of code emitted to all blocks. Not synchronized,
// so the value may be stale by the time this function returns.
size_t totalUsed() const;
size_t mainUsed() const { return m_main.used(); }
size_t profUsed() const { return m_prof.used(); }
CodeAddress base() const { return m_base; }
bool isValidCodeAddress(CodeAddress addr) const;
void protect();
void unprotect();
CodeBlock& main();
const CodeBlock& main() const {
return const_cast<CodeCache&>(*this).main();
}
CodeBlock& cold();
const CodeBlock& cold() const {
return const_cast<CodeCache&>(*this).cold();
}
CodeBlock& frozen();
const CodeBlock& frozen() const {
return const_cast<CodeCache&>(*this).frozen();
}
CodeBlock& realMain() { return m_main; }
CodeBlock& realCold() { return m_cold; }
CodeBlock& realFrozen() { return m_frozen; }
const CodeBlock& realCold() const { return m_cold; }
const CodeBlock& realFrozen() const { return m_frozen; }
DataBlock& data() { return m_data; }
// Read-only access for MCGenerator::dumpTCCode()/dumpTCData()
const CodeBlock& prof() const { return m_prof; }
const CodeBlock& hot() const { return m_hot; }
void lock() { m_lock = true; }
void unlock() { m_lock = false; }
private:
CodeAddress m_base;
size_t m_codeSize;
size_t m_totalSize;
Selection m_selection;
/*
* Code blocks for emitting different kinds of code.
*
* See comment in runtime/vm/jit/block.h to see the meanings of different
* Block Hints.
*
* Code blocks with either a 'Likely' or 'Neither' Block Hint are emitted
* in m_main. Code blocks with an 'Unlikely' Block Hint are emitted in
* m_cold (except for profiling translations, see below). Code blocks
* with an 'Unused' Block Hint are emitted in m_frozen.
*
* The m_hot section is used for emitting optimzed translations of
* 'Hot' functions (functions marked with AttrHot). The m_prof is used
* for emitting profiling translations of Hot functions. Also, for profiling
* translations, the m_frozen section is used for 'Unlikely' blocks instead
* of m_cold.
*
*/
CodeBlock m_main; // used for hot code of non-AttrHot functions
CodeBlock m_cold; // used for cold or one time use code
CodeBlock m_hot; // used for hot code of AttrHot functions
CodeBlock m_prof; // used for hot code of profiling translations
CodeBlock m_frozen; // used for code that is (almost) never used
DataBlock m_data; // data to be used by translated code
bool m_lock; // don't allow access to main() or cold()
};
struct CodeCache::Selector {
struct Args {
explicit Args(CodeCache& cache)
: m_cache(cache)
, m_hot(false)
, m_profile(false)
{}
Args& hot(bool isHot) { m_hot = isHot; return *this; }
Args& profile(bool isProf) { m_profile = isProf; return *this; }
private:
friend class Selector;
CodeCache& m_cache;
bool m_hot;
bool m_profile;
};
explicit Selector(const Args& args);
~Selector();
private:
CodeCache& m_cache;
const Selection m_oldSelection;
};
}
#endif
|