Updating submodules
[hiphop-php.git] / hphp / runtime / base / runtime-option.h
bloba3659f58583a41a03d020378c60d6c3d7fb72811
1 /*
2 +----------------------------------------------------------------------+
3 | HipHop for PHP |
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010-present Facebook, Inc. (http://www.facebook.com) |
6 +----------------------------------------------------------------------+
7 | This source file is subject to version 3.01 of the PHP license, |
8 | that is bundled with this package in the file LICENSE, and is |
9 | available through the world-wide-web at the following url: |
10 | http://www.php.net/license/3_01.txt |
11 | If you did not receive a copy of the PHP license and are unable to |
12 | obtain it through the world-wide-web, please send a note to |
13 | license@php.net so we can mail you a copy immediately. |
14 +----------------------------------------------------------------------+
17 #pragma once
19 #include <unordered_map>
20 #include <algorithm>
21 #include <vector>
22 #include <string>
23 #include <map>
24 #include <set>
25 #include <boost/container/flat_set.hpp>
26 #include <memory>
27 #include <sys/stat.h>
28 #include <folly/json/dynamic.h>
30 #include "hphp/runtime/base/config.h"
31 #include "hphp/runtime/base/configs/repo-options-flags-generated.h"
32 #include "hphp/runtime/base/package.h"
33 #include "hphp/runtime/base/typed-value.h"
34 #include "hphp/runtime/base/types.h"
36 #include "hphp/util/compilation-flags.h"
37 #include "hphp/util/configs/autoload.h"
38 #include "hphp/util/configs/hacklang.h"
39 #include "hphp/util/configs/jit.h"
40 #include "hphp/util/configs/php7.h"
41 #include "hphp/util/configs/server.h"
42 #include "hphp/util/functional.h"
43 #include "hphp/util/hash-map.h"
44 #include "hphp/util/sha1.h"
46 #include "hphp/hack/src/parser/ffi_bridge/parser_ffi.rs.h"
48 namespace HPHP {
49 ///////////////////////////////////////////////////////////////////////////////
51 struct AccessLogFileData;
52 struct ErrorLogFileData;
53 struct VirtualHost;
54 struct IpBlockMap;
55 struct SatelliteServerInfo;
56 struct FilesMatch;
57 struct Hdf;
58 struct IniSettingMap;
60 constexpr const char* kPackagesToml = "PACKAGES.toml";
62 using StringToIntMap = std::unordered_map<std::string, int>;
64 enum class JitSerdesMode {
65 // NB: if changing the encoding here, make sure to update isJitSerializing()
66 // and isJitDeserializing() as needed.
68 // Bit 0: serialize
69 // Bit 1: deserialize
70 Off = 0x0,
71 Serialize = 0x1, // 00001
72 SerializeAndExit = 0x5, // 00101
73 Deserialize = 0x2, // 00010
74 DeserializeOrFail = 0x6, // 00110
75 DeserializeOrGenerate = 0xa, // 01010
76 DeserializeAndDelete = 0xe, // 01110
77 DeserializeAndExit = 0x12, // 10010
80 enum class RepoMode {
81 Closed = 0,
82 ReadOnly = 1,
83 ReadWrite = 2,
86 namespace hackc {
87 struct NativeEnv;
88 struct HhbcFlags;
89 struct ParserFlags;
90 struct DeclParserConfig;
93 namespace Facts {
94 // SQLFacts version number representing the DB's schema. This number is
95 // determined randomly, but should match the number in the SQL Facts
96 // implementation. We use this when we make a change that invalidates
97 // the cache, such as adding a new table which would otherwise be
98 // unpopulated without a cache rebuild.
99 constexpr size_t kSchemaVersion = 1916337637;
103 * The bare RepoOptions information that the parser cares about.
105 struct RepoOptionsFlags {
107 #define S(name) friend Cfg::name;
108 SECTIONS_FOR_REPOOPTIONSFLAGS()
109 #undef S
111 const PackageInfo& packageInfo() const { return m_packageInfo; }
112 const SHA1& cacheKeySha1() const { return m_sha1; }
114 ParserEnv getParserEnvironment() const;
115 void initDeclConfig(hackc::DeclParserConfig&) const;
116 void initHhbcFlags(hackc::HhbcFlags&) const;
117 void initParserFlags(hackc::ParserFlags&) const;
118 void initAliasedNamespaces(hackc::NativeEnv&) const;
120 std::string autoloadQuery() const { return Query; }
121 folly::dynamic autoloadQueryObj() const { return m_cachedQuery; }
122 std::string trustedDBPath() const { return TrustedDBPath; }
123 const std::vector<std::string>& autoloadRepoBuildSearchDirs() const {
124 return RepoBuildSearchDirs;
128 * Allowlist consisting of the attributes, marking methods, which Facts
129 * should index
131 const Cfg::StringVector& indexedMethodAttributes() const {
132 return IndexedMethodAttributes;
135 // NB: Everything serialized here affects the cache for RE. Do not
136 // put anything unnecessary or that changes spuriously.
137 template <typename SerDe> void serde(SerDe& sd) {
138 #define C(t, n) sd(n);
139 CONFIGS_FOR_REPOOPTIONSFLAGS()
140 #undef C
142 sd(m_packageInfo);
143 sd(m_sha1);
144 sd(m_factsCacheBreaker);
146 if constexpr (SerDe::deserializing) calcCachedQuery();
149 template <typename SerDe>
150 static RepoOptionsFlags makeForSerde(SerDe& sd) {
151 RepoOptionsFlags f;
152 sd(f);
153 return f;
156 const std::string& getFactsCacheBreaker() const { return m_factsCacheBreaker;}
157 void calcCachedQuery();
159 private:
160 RepoOptionsFlags() = default;
162 #define C(t, n) t n;
163 CONFIGS_FOR_REPOOPTIONSFLAGS()
164 #undef C
166 PackageInfo m_packageInfo;
168 SHA1 m_sha1;
169 std::string m_factsCacheBreaker;
171 // The query to be used for autoloading
172 folly::dynamic m_cachedQuery;
174 friend struct RepoOptions;
177 namespace Stream {
178 struct Wrapper;
181 struct RepoOptionStats {
182 RepoOptionStats() = default;
183 RepoOptionStats(const std::string&, Stream::Wrapper*);
184 bool missing() const {
185 return !m_configStat.has_value() && !m_packageStat.has_value();
188 Optional<struct stat> m_configStat;
189 Optional<struct stat> m_packageStat;
193 * RepoOptionsFlags plus extra state
195 struct RepoOptions {
196 RepoOptions(const RepoOptions&) = default;
197 RepoOptions(RepoOptions&&) = default;
199 const RepoOptionsFlags& flags() const { return m_flags; }
200 const PackageInfo& packageInfo() const { return flags().packageInfo(); }
201 const std::filesystem::path& path() const { return m_path; }
202 const RepoOptionStats& stat() const { return m_stat; }
204 const std::filesystem::path& dir() const { return m_repo; }
205 const std::filesystem::path& autoloadDB() const { return m_autoloadDB; }
207 bool operator==(const RepoOptions& o) const {
208 // If we have hash collisions of unequal RepoOptions, we have
209 // bigger problems.
210 return m_flags.m_sha1 == o.m_flags.m_sha1;
212 bool operator!=(const RepoOptions& o) const { return !(*this == o); }
214 static const RepoOptions& defaults();
215 static const RepoOptions& defaultsForSystemlib();
216 static void setDefaults(const Hdf& hdf, const IniSettingMap& ini);
218 static const RepoOptions& forFile(const std::string& path);
219 private:
220 RepoOptions() = default;
221 RepoOptions(const char* str, const char* file);
223 void filterNamespaces();
224 void initDefaults(const Hdf& hdf, const IniSettingMap& ini);
225 void initDefaultsForSystemlib();
226 void calcCacheKey();
227 void calcDynamic();
228 void calcAutoloadDB();
230 RepoOptionsFlags m_flags;
232 // Path to .hhvmconfg.hdf
233 std::filesystem::path m_path;
234 RepoOptionStats m_stat;
236 // Canonical path of repo root directory that contains .hhvmconfig.hdf
237 std::filesystem::path m_repo;
239 // The autoload DB specified by these repo options
240 std::filesystem::path m_autoloadDB;
242 bool m_init = false;
244 static RepoOptions s_defaults;
245 static RepoOptions s_defaultsForSystemlib;
249 * Configurable options set from command line or configurable file at startup
250 * time.
252 struct RuntimeOption {
253 static void Load(
254 IniSettingMap &ini, Hdf& config,
255 const std::vector<std::string>& iniClis = std::vector<std::string>(),
256 const std::vector<std::string>& hdfClis = std::vector<std::string>(),
257 std::vector<std::string>* messages = nullptr,
258 std::string cmd = "");
260 static bool ServerExecutionMode() {
261 return Cfg::Server::Mode;
264 static bool GcSamplingEnabled() {
265 return EvalGCSampleRate > 0;
268 static bool JitSamplingEnabled() {
269 return Cfg::Jit::Enabled && Cfg::Jit::SampleRate > 0;
272 static void ReadSatelliteInfo(
273 const IniSettingMap& ini,
274 const Hdf& hdf,
275 std::vector<std::shared_ptr<SatelliteServerInfo>>& infos
278 static Optional<std::filesystem::path> GetHomePath(
279 const folly::StringPiece user);
281 static std::string GetDefaultUser();
284 * Find a config file corresponding to the given user and parse its
285 * settings into the given ini and hdf objects.
287 * Return true on success and false on failure.
289 static bool ReadPerUserSettings(const std::filesystem::path& confFileName,
290 IniSettingMap& ini, Hdf& config);
292 static std::string getTraceOutputFile();
294 // Store the list of input values used to calculate the tier overwrites
295 static std::map<std::string, std::string> TierOverwriteInputs;
296 static void StoreTierOverwriteInputs(const std::string &machine, const std::string &tier,
297 const std::string &task, const std::string &cpu, const std::string &tiers, const std::string &tags);
299 static std::string BuildId;
300 static std::string InstanceId;
301 static std::string DeploymentId; // ID for set of instances deployed at once
302 static int64_t ConfigId; // Queryable to verify a specific config was read
303 static std::string PidFile;
305 static std::map<std::string, ErrorLogFileData> ErrorLogs;
306 static std::string LogFile;
307 static std::string LogFileSymLink;
308 static uint16_t LogFilePeriodMultiplier;
310 static int LogHeaderMangle;
311 static bool AlwaysEscapeLog;
312 static bool AlwaysLogUnhandledExceptions;
313 static bool NoSilencer;
314 static int RuntimeErrorReportingLevel;
315 static int ForceErrorReportingLevel; // Bitmask ORed with the reporting level
317 static int RaiseDebuggingFrequency;
318 static int64_t SerializationSizeLimit;
320 static std::string AccessLogDefaultFormat;
321 static std::map<std::string, AccessLogFileData> AccessLogs;
323 static std::string AdminLogFormat;
324 static std::string AdminLogFile;
325 static std::string AdminLogSymLink;
327 static std::map<std::string, AccessLogFileData> RPCLogs;
329 static const std::string& GetServerPrimaryIPv4();
330 static const std::string& GetServerPrimaryIPv6();
331 static std::vector<std::shared_ptr<VirtualHost>> VirtualHosts;
332 static std::shared_ptr<IpBlockMap> IpBlocks;
333 static std::vector<std::shared_ptr<SatelliteServerInfo>>
334 SatelliteServerInfos;
337 * Legal root directory expressions in an include expression. For example,
339 * include_once $PHP_ROOT . '/lib.php';
341 * Here, "$PHP_ROOT" is a legal include root. Stores what it resolves to.
343 * RuntimeOption::IncludeRoots["$PHP_ROOT"] = "";
344 * RuntimeOption::IncludeRoots["$LIB_ROOT"] = "lib";
346 static std::map<std::string, std::string> IncludeRoots;
348 static hphp_string_imap<std::string> StaticFileExtensions;
349 static hphp_string_imap<std::string> PhpFileExtensions;
350 static std::set<std::string> StaticFileGenerators;
351 static std::vector<std::shared_ptr<FilesMatch>> FilesMatches;
353 static std::string AdminServerIP;
354 static int AdminServerPort;
355 static int AdminThreadCount;
356 static bool AdminServerEnableSSLWithPlainText;
357 static bool AdminServerStatsNeedPassword;
358 static std::string AdminPassword;
359 static std::set<std::string> AdminPasswords;
360 static std::set<std::string> HashedAdminPasswords;
362 static std::string AdminDumpPath;
364 static int HttpDefaultTimeout;
365 static int HttpSlowQueryThreshold;
367 static bool NativeStackTrace;
368 static bool ServerErrorMessage;
369 static bool RecordInput;
370 static bool ClearInputOnSuccess;
371 static std::string ProfilerOutputDir;
372 static std::string CoreDumpEmail;
373 static bool CoreDumpReport;
374 static std::string CoreDumpReportDirectory;
375 static std::string StackTraceFilename;
376 static int StackTraceTimeout;
377 static std::string RemoteTraceOutputDir;
378 static std::set<std::string, stdltistr> TraceFunctions;
380 static bool EnableStats;
381 static bool EnableAPCStats;
382 static bool EnableWebStats;
383 static bool EnableMemoryStats;
384 static bool EnableSQLStats;
385 static bool EnableSQLTableStats;
386 static bool EnableNetworkIOStatus;
387 static std::string StatsXSL;
388 static std::string StatsXSLProxy;
389 static uint32_t StatsSlotDuration;
390 static uint32_t StatsMaxSlot;
391 static std::vector<std::string> StatsTrackedKeys;
393 static int32_t ProfilerTraceBuffer;
394 static double ProfilerTraceExpansion;
395 static int32_t ProfilerMaxTraceBuffer;
397 static int64_t MaxSQLRowCount;
398 static int64_t SocketDefaultTimeout;
400 static bool DisableSmallAllocator;
402 static std::map<std::string, std::string> ServerVariables;
404 static std::map<std::string, std::string> EnvVariables;
406 // Eval options
407 static bool EnableXHP;
408 static bool CheckSymLink;
409 static bool TrustAutoloaderPath;
410 static bool EnableArgsInBacktraces;
411 static bool EnableZendIniCompat;
412 static bool TimeoutsUseWallTime;
413 static bool EvalAuthoritativeMode;
414 static int CheckCLIClientCommands;
415 static JitSerdesMode EvalJitSerdesMode;
416 static int ProfDataTTLHours;
417 static std::string EvalJitSerdesFile;
418 static std::string ProfDataTag;
419 static bool DumpPreciseProfData;
420 static bool KeepProfData;
422 static std::string WatchmanRootSocket;
423 static std::string WatchmanDefaultSocket;
425 static hphp_string_map<TypedValue> ConstantFunctions;
427 static std::vector<std::string> TzdataSearchPaths;
429 static hphp_fast_string_set ActiveExperiments;
430 static hphp_fast_string_set InactiveExperiments;
432 #define EVALFLAGS() \
433 /* F(type, name, defaultVal) */ \
434 /* \
435 * Maximum number of elements on the VM execution stack. \
436 */ \
437 F(uint64_t, VMStackElms, kEvalVMStackElmsDefault) \
438 F(int, StackCheckLeafPadding, 100) \
439 F(bool, EnableAsyncJIT, false) \
440 F(int, AsyncJitWorkerThreads, 4) \
441 /* \
442 * Initial space reserved for the global variable environment (in \
443 * number of global variables). \
444 */ \
445 F(uint32_t, VMInitialGlobalTableSize, \
446 kEvalVMInitialGlobalTableSizeDefault) \
447 F(bool, RecordSubprocessTimes, false) \
448 F(bool, AllowHhas, false) \
449 F(bool, GenerateDocComments, true) \
450 F(bool, DisassemblerDocComments, true) \
451 F(bool, DisassemblerPropDocComments, true) \
452 F(bool, LoadFilepathFromUnitCache, false) \
453 F(bool, WarnOnSkipFrameLookup, true) \
454 /* \
455 * 0 - Code coverage cannot be enabled through request param \
456 * 1 - Code coverage can be enabled through request param \
457 * 2 - Code coverage enabled \
458 */ \
459 F(uint32_t, EnableCodeCoverage, 0) \
460 /* \
461 * 0 - Per-file coverage cannot be enabled through request param \
462 * 1 - Per-file coverage can be enabled through request param \
463 * 2 - Per-file coverage enabled \
464 */ \
465 F(uint32_t, EnablePerFileCoverage, 0) \
466 F(bool, EnableFuncCoverage, false) \
467 /* The number of worker threads to spawn for facts extraction. */ \
468 F(uint64_t, FactsWorkers, Process::GetCPUCount()) \
469 /* Whether the HackC compiler should inherit the compiler config of the
470 HHVM process that launches it. */ \
471 F(bool, HackCompilerInheritConfig, true) \
472 /* enable decl-directed bytecode compilation */ \
473 F(bool, EnableDecl, false) \
474 F(uint32_t, LogDeclDeps, 0) \
475 F(uint32_t, LogDeclErrors, 0) \
476 F(bool, LogAllDeclTearing, false) \
477 /* When using embedded data, extract it to the ExtractPath or the
478 * ExtractFallback. */ \
479 F(string, EmbeddedDataExtractPath, "/var/run/hhvm_%{type}_%{buildid}") \
480 F(string, EmbeddedDataFallbackPath, "/tmp/hhvm_%{type}_%{buildid}_XXXXXX") \
481 /* Whether to trust existing versions of extracted embedded data. */ \
482 F(bool, EmbeddedDataTrustExtract, true) \
483 F(bool, LogThreadCreateBacktraces, false) \
484 F(bool, FailJitPrologs, false) \
485 F(bool, UseHHBBC, !getenv("HHVM_DISABLE_HHBBC")) \
486 /* Threshold number of units to log to hhvm_whole_program table.
487 systemlib has around 200 units, so use a larger default to avoid
488 logging for unit tests. */ \
489 F(uint32_t, HHBBCMinUnitsToLog, 1000) \
490 F(bool, CachePerRepoOptionsPath, true) \
491 F(bool, LogHackcMemStats, false) \
492 F(uint32_t, TsameCollisionSampleRate, 1) \
493 /* CheckBuiltinParamTypeHints
494 * 0 - Do not check parameter type hints of builtins
495 * 1 - Treat builtin parameter type hints as <<__Soft>>
496 * 2 - Enforce builtin parameter type hints
497 */ \
498 F(int32_t, CheckBuiltinParamTypeHints, 2) \
499 /* Unused. Scheduled for removal: T175741557 */ \
500 F(int32_t, EnforceGenericsUB, 2) \
501 /* WarnOnTooManyArguments:
502 * 0 -> no warning, 1 -> warning, 2 -> exception
503 */ \
504 F(uint32_t, WarnOnTooManyArguments, 0) \
505 /* GetClassBadArgument:
506 * 0 -> no warning, 1 -> warning, 2 -> exception
507 */ \
508 F(uint32_t, GetClassBadArgument, 0) \
509 /* WarnOnIncDecInvalidType:
510 * 0 - No restrictions on types that can be incremented or decremented
511 * 1 - Warn when incrementing or decrementing non numeric types
512 * 2 - Throw when incrementing or decrementing non numeric types
513 */ \
514 F(uint32_t, WarnOnIncDecInvalidType, 0) \
515 /* WarnOnImplicitCoercionOfEnumValue
516 * This flag exists to control behaviour when implicit coercion is
517 * taking place on an enum value.
518 * 0 - No warning
519 * 1 - Warning
520 * 2 - Do not do implicit coercion
521 */ \
522 F(uint32_t, WarnOnImplicitCoercionOfEnumValue, 0) \
523 F(bool, EnableLogBridge, true) \
524 F(bool, MoreAccurateMemStats, true) \
525 F(bool, MemInfoCheckCgroup2, true) \
526 F(bool, SpinOnCrash, false) \
527 F(uint32_t, DumpRingBufferOnCrash, 0) \
528 F(bool, PerfPidMap, true) \
529 F(bool, PerfPidMapIncludeFilePath, true) \
530 F(bool, PerfJitDump, false) \
531 F(string, PerfJitDumpDir, "/tmp") \
532 F(bool, PerfDataMap, false) \
533 F(bool, KeepPerfPidMap, false) \
534 F(uint32_t, ThreadTCMainBufferSize, 6 << 20) \
535 F(uint32_t, ThreadTCColdBufferSize, 6 << 20) \
536 F(uint32_t, ThreadTCFrozenBufferSize,4 << 20) \
537 F(uint32_t, ThreadTCDataBufferSize, 256 << 10) \
538 F(uint32_t, RDSSize, 64 << 20) \
539 F(uint32_t, HHBCArenaChunkSize, 10 << 20) \
540 F(bool, ProfileBC, false) \
541 F(bool, ProfileHeapAcrossRequests, false) \
542 F(bool, ProfileHWEnable, true) \
543 F(string, ProfileHWEvents, std::string("")) \
544 F(bool, ProfileHWExcludeKernel, false) \
545 F(bool, ProfileHWFastReads, false) \
546 F(bool, ProfileHWStructLog, false) \
547 F(int32_t, ProfileHWExportInterval, 30) \
548 F(string, ReorderProps, reorderPropsDefault()) \
549 F(bool, ReorderRDS, true) \
550 F(double, RDSReorderThreshold, 0.0005) \
551 F(uint32_t, ProfileGlobalsLimit, 200) \
552 F(double, ProfileGlobalsSlowExitThreshold, 0.98) \
553 F(uint32_t, GdbSyncChunks, 128) \
554 F(bool, TraceCommandLineRequest, true) \
555 F(bool, EmitDebuggerIntrCheck, true) \
556 /* Log the profile used to optimize array-like gets and sets. */ \
557 F(bool, LogArrayAccessProfile, false) \
558 F(double, CoeffectFunParamProfileThreshold, 0.10) \
559 F(bool, AssemblerFoldDefaultValues, true) \
560 F(uint64_t, AssemblerMaxScalarSize, 2147483648) /* 2GB */ \
561 F(uint64_t, FuncCountHint, 10000) \
562 F(uint64_t, PGOFuncCountHint, 1000) \
563 F(bool, RegionRelaxGuards, true) \
564 /* DumpBytecode =1 dumps user php, =2 dumps systemlib & user php */ \
565 F(int32_t, DumpBytecode, 0) \
566 /* DumpHhas =1 dumps user php, =2 dumps systemlib & user php */ \
567 F(int32_t, DumpHhas, 0) \
568 F(string, DumpHhasToFile, "") \
569 F(bool, DumpTC, false) \
570 F(string, DumpTCPath, "/tmp") \
571 F(bool, DumpTCAnchors, false) \
572 F(uint32_t, DumpIR, 0) \
573 F(uint32_t, DumpIRJson, 0) \
574 F(bool, DumpTCAnnotationsForAllTrans,debug) \
575 /* DumpInlDecision 0=none ; 1=refuses ; 2=refuses+accepts */ \
576 F(uint32_t, DumpInlDecision, 0) \
577 F(uint32_t, DumpRegion, 0) \
578 F(bool, DumpCallTargets, false) \
579 F(bool, DumpLayoutCFG, false) \
580 F(bool, DumpHHIRInLoops, false) \
581 F(bool, DumpVBC, false) \
582 F(bool, DumpArrAccProf, false) \
583 F(bool, DumpCoeffectFunParamProf,false) \
584 F(bool, DumpAst, false) \
585 F(bool, DumpTargetProfiles, false) \
586 F(bool, DumpJitProfileStats, false) \
587 F(bool, DumpJitEnableRenameFunctionStats, false) \
588 F(bool, MapTgtCacheHuge, false) \
589 F(bool, NewTHPHotText, false) \
590 F(bool, FileBackedColdArena, useFileBackedArenaDefault()) \
591 F(string, ColdArenaFileDir, "/tmp") \
592 F(uint32_t, MaxHotTextHugePages, hotTextHugePagesDefault()) \
593 F(uint32_t, MaxLowMemHugePages, hugePagesSoundNice() ? 8 : 0) \
594 F(uint32_t, MaxHighArenaHugePages, 0) \
595 F(uint32_t, Num1GPagesForReqHeap, 0) \
596 F(uint32_t, Num2MPagesForReqHeap, 0) \
597 F(uint32_t, NumReservedSlabs, 0) \
598 F(uint32_t, NumReservedMBForSlabs, 0) \
599 F(uint32_t, Num1GPagesForA0, 0) \
600 F(uint32_t, Num2MPagesForA0, 0) \
601 F(bool, BigAllocUseLocalArena, true) \
602 F(bool, JsonParserUseLocalArena, true) \
603 F(bool, XmlParserUseLocalArena, true) \
604 F(bool, LowStaticArrays, (!use_lowptr || \
605 !ServerExecutionMode())) \
606 F(bool, RecycleAProf, true) \
607 F(int64_t, HeapPurgeWindowSize, 5 * 1000000) \
608 F(uint64_t, HeapPurgeThreshold, 128 * 1024 * 1024) \
609 /* GC Options: See heap-collect.cpp for more details */ \
610 F(bool, EagerGC, eagerGcDefault()) \
611 F(bool, FilterGCPoints, true) \
612 F(bool, Quarantine, eagerGcDefault()) \
613 F(bool, SanitizeReqHeap, false) \
614 F(bool, HeapAllocSampleNativeStack, false) \
615 F(bool, LogKilledRequests, true) \
616 F(uint32_t, GCSampleRate, 0) \
617 F(uint32_t, HeapAllocSampleRequests, 0) \
618 F(uint32_t, HeapAllocSampleBytes, 256 * 1024) \
619 F(uint32_t, SlabAllocAlign, 64) \
620 F(uint32_t, MemTrackStart, 3500) \
621 F(uint32_t, MemTrackEnd, 3700) \
622 F(int64_t, GCMinTrigger, 64L<<20) \
623 F(double, GCTriggerPct, 0.5) \
624 F(bool, TwoPhaseGC, false) \
625 F(bool, EnableGC, enableGcDefault()) \
626 /* End of GC Options */ \
627 F(bool, Verify, getenv("HHVM_VERIFY")) \
628 F(bool, VerifyOnly, false) \
629 F(bool, FatalOnVerifyError, !RepoAuthoritative) \
630 F(bool, AbortBuildOnVerifyError, true) \
631 F(bool, AbortBuildOnCompilerError, true) \
632 F(bool, VerifySystemLibHasNativeImpl, true) \
633 F(uint32_t, StaticContentsLogRate, 100) \
634 F(uint32_t, LogUnitLoadRate, 0) \
635 F(uint32_t, MaxDeferredErrors, 50) \
636 F(uint32_t, SerDesSampleRate, 0) \
637 F(int, SimpleJsonMaxLength, 2 << 20) \
638 F(uint32_t, TraceServerRequestRate, 0) \
639 /* Tracing Options */ \
640 /* Base tracing sample rate for all requests */ \
641 F(uint32_t, TracingSampleRate, 0) \
642 /* Tracing sample rate for first N requests */ \
643 F(uint32_t, TracingPerRequestCount, 0) \
644 F(uint32_t, TracingPerRequestSampleRate, 0) \
645 /* Tracing sample rate for first N requests per URL */ \
646 F(uint32_t, TracingFirstRequestsCount, 0) \
647 F(uint32_t, TracingFirstRequestsSampleRate, 0) \
648 /* Empty string disables any Artillery tracing */ \
649 F(std::string, ArtilleryTracePolicy, "") \
650 /* Opaque tag to add to each trace. Useful for aggregation */ \
651 F(std::string, TracingTagId, "") \
652 F(bool, EnableCompactBacktrace, true) \
653 F(bool, EnableNuma, (numa_num_nodes > 1) && ServerExecutionMode()) \
654 F(bool, EnableCallBuiltin, true) \
655 F(bool, EnableReusableTC, reuseTCDefault()) \
656 F(bool, LogServerRestartStats, false) \
657 /* Extra bytes added to each area (Hot/Cold/Frozen) of a translation. \
658 * If we don't end up using a reusable TC, we'll drop the padding. */ \
659 F(uint32_t, ReusableTCPadding, 128) \
660 F(int64_t, StressUnitCacheFreq, 0) \
661 /* Perf warning sampling rates. The SelectHotCFG warning is noisy. */ \
662 F(int64_t, PerfWarningSampleRate, 1) \
663 F(int64_t, SelectHotCFGSampleRate, 100) \
664 F(int64_t, FunctionCallSampleRate, 0) \
665 F(double, InitialLoadFactor, 1.0) \
666 /* Controls emitting checks for bespoke arrays and using logging \
667 * arrays at runtime. \
669 * 0 - Disable bespokes. We assume that all array-likes have their \
670 * standard (aka "vanilla") layouts. \
671 * 1 - Test bespokes. We emit checks for vanilla layouts and produce \
672 * logging arrays based on the request ID. If rid % 2 == 1, then \
673 * a logging array is generated. \
674 * 2 - Production bespokes. We emit checks as in (1), and produce \
675 * logging arrays based on per creation site sampling with the \
676 * sample rate specified by EmitLoggingArraySampleRate. If the \
677 * sample rate is 0, logging arrays are never constructed. \
678 * Logging arrays are only created before RTA has begun. */ \
679 F(int32_t, BespokeArrayLikeMode, 2) \
680 F(uint64_t, BespokeEscalationSampleRate, 0) \
681 F(uint64_t, EmitLoggingArraySampleRate, 17) \
682 F(string, ExportLoggingArrayDataPath, "") \
683 /* Should we use structs? \
684 * If so, how many layouts and how big can they get? \
685 */ \
686 F(bool, EmitBespokeStructDicts, true) \
687 F(uint16_t, BespokeMaxNumStructLayouts, 1 << 14) \
688 /* Do not use! Use StructLayout::maxNumKeys instead */ \
689 F(uint16_t, BespokeStructDictMaxNumKeys, 2048) \
690 F(double, BespokeStructDictKeyCoverageThreshold, 95.0) \
691 F(uint8_t, BespokeStructDictMinKeys, 128) \
692 F(double, BespokeStructDictMaxSizeRatio, 2.0) \
693 /* What is the maximum number of keys to track in key order \
694 * profiles? */ \
695 F(uint64_t, BespokeMaxTrackedKeys, 2048) \
696 F(bool, EmitAPCBespokeArrays, true) \
697 /* Should we use monotypes? */ \
698 F(bool, EmitBespokeMonotypes, false) \
699 F(int64_t, ObjProfMaxNesting, 2000) \
700 /* Choice of layout selection algorithms: \
702 * 0 - Default layout selection algorithm based on profiling. \
703 * May use a mix of vanilla and bespoke array-likes. \
704 * 1 - Specialize all sources and sinks on vanilla layouts. \
705 * 2 - Specialize sources on vanilla, but sinks on top. */ \
706 F(int32_t, BespokeArraySpecializationMode, 0) \
707 /* We will use specialized layouts for a given array if they cover \
708 * the given percent of operations logged during profiling. \
710 * We can generate code for a bespoke sink in three ways: \
711 * 1. We can do "top codegen" that handles any array layout. \
712 * 2. We can specialize layouts and fall back to top codegen. \
713 * 3. We can specialize layouts and side-exit on guard failure. \
715 * We use a couple heuristics to choose between these options. If we \
716 * see one layout that covers `SideExitThreshold` percent cases, and \
717 * we saw at most `SideExitMaxSources` sources reach this sink, with \
718 * at least `SideExitMinSampleCount` samples each, we'll side-exit. \
720 * Else, if multiple layouts cover SpecializationThreshold and at at \
721 * least one of them covers SpecializationMinThreshold we will \
722 * specialize to both layouts and fall back to top codegen. If one \
723 * layout covers `SpecializationThreshold` percent, we will \
724 * specialize and fall back to top codegen. Otherwise, we'll do top \
725 * codegen. */ \
726 F(double, BespokeArraySourceSpecializationThreshold, 95.0) \
727 F(double, BespokeArraySinkSpecializationThreshold, 95.0) \
728 F(double, BespokeArraySinkIteratorSpecializationThreshold, 92.0) \
729 F(double, BespokeArraySinkSpecializationMinThreshold, 85.0) \
730 F(double, BespokeArraySinkMultiLayoutThreshold, 0.999) \
731 F(double, BespokeArraySinkSideExitThreshold, 95.0) \
732 F(uint64_t, BespokeArraySinkSideExitMaxSources, 64) \
733 F(uint64_t, BespokeArraySinkSideExitMinSampleCount, 4) \
734 /* When this flag is on, var_export outputs d/varrays. */ \
735 F(bool, HackArrDVArrVarExport, false) \
736 /* Raise a notice when the result of appending to a dict or darray \
737 * is affected by removing keys from that array-like. */ \
738 F(bool, DictDArrayAppendNotices, true) \
739 /* Warn if is expression are used with type aliases that cannot be |
740 * resolved */ \
741 F(bool, IsExprEnableUnresolvedWarning, false) \
742 /* Raise a notice if a Class type is used as a memo key */ \
743 F(bool, ClassMemoNotices, false) \
744 /* Raise a notice if a ClsMeth type is passed to a function that
745 * expects a vec/varray */ \
746 F(bool, VecHintNotices, false) \
747 /* Switches on miscellaneous junk. */ \
748 F(bool, NoticeOnCreateDynamicProp, false) \
749 F(bool, NoticeOnReadDynamicProp, false) \
750 F(bool, NoticeOnImplicitInvokeToString, false) \
751 F(bool, FatalOnConvertObjectToString, false) \
752 /* When this flag is on, var_dump for
753 * classes and lazy classes outputs string(...). */ \
754 F(bool, ClassAsStringVarDump, true) \
755 /* When this flag is on, var_export for
756 * classes and lazy classes outputs a string. */ \
757 F(bool, ClassAsStringVarExport, false) \
758 /* When this flag is on, gettype for
759 * classes and lazy classes outputs string. */ \
760 F(bool, ClassAsStringPrintR, false) \
761 /* When this flag is on, print_r for
762 * classes and lazy classes outputs a string. */ \
763 F(bool, ClassAsStringGetType, true) \
764 /* trigger E_USER_WARNING error when getClassName()/getMethodName()
765 * is used on __SystemLib\MethCallerHelper */ \
766 F(bool, NoticeOnMethCallerHelperUse, false) \
767 /* \
768 * Control dynamic calls to functions and dynamic constructs of \
769 * classes which haven't opted into being called that way. \
771 * 0 - Do nothing \
772 * 1 - Warn if meth_caller is apc serialized \
773 * 2 - Throw exception if meth_caller is apc serialized \
774 */ \
775 F(int32_t, ForbidMethCallerAPCSerialize, 0) \
776 F(int32_t, ForbidMethCallerHelperSerialize, 0) \
777 F(bool, NoticeOnMethCallerHelperIsObject, false) \
778 F(bool, NoticeOnCollectionToBool, false) \
779 F(bool, NoticeOnSimpleXMLBehavior, false) \
780 /* \
781 * Don't allow unserializing to __PHP_Incomplete_Class \
782 * 0 - Nothing \
783 * 1 - Warn \
784 * 2 - Throw exception \
785 */ \
786 F(int32_t, ForbidUnserializeIncompleteClass, 0) \
787 /* \
788 * Map from coeffect name to enforcement level \
789 * e.g. {'pure' => 2, 'rx' => 1} \
790 */ \
791 F(StringToIntMap, CoeffectEnforcementLevels, coeffectEnforcementLevelsDefaults()) \
792 F(uint64_t, CoeffectViolationWarningMax, std::numeric_limits<uint64_t>::max()) \
793 /* \
794 * Enforce deployment boundaries. \
795 */ \
796 F(bool, EnforceDeployment, true) \
797 F(uint32_t, DeploymentViolationWarningSampleRate, 1) \
799 * Enforce top level and method level internal keyword \
800 * 0 - Nothing \
801 * 1 - Warn \
802 * 2 - Throw exception \
803 */ \
804 F(uint32_t, EnforceModules, 0) \
805 /* \
806 * Controls behavior on reflection to default value expressions \
807 * that throw during evaluation \
808 * 0 - Nothing \
809 * 1 - Warn and retain current behavior \
810 * 2 - Return null for parameter value \
811 */ \
812 F(int32_t, FixDefaultArgReflection, 2) \
813 F(int32_t, ServerOOMAdj, 0) \
814 F(std::string, PreludePath, "") \
815 F(uint32_t, NonSharedInstanceMemoCaches, 10) \
816 F(bool, UseGraphColor, true) \
817 F(std::vector<std::string>, IniGetHide, std::vector<std::string>()) \
818 F(std::string, UseRemoteUnixServer, "no") \
819 F(std::string, UnixServerPath, "") \
820 F(uint32_t, UnixServerWorkers, Process::GetCPUCount()) \
821 F(bool, UnixServerFailWhenBusy, false) \
822 F(std::vector<std::string>, UnixServerAllowedUsers, \
823 std::vector<std::string>()) \
824 F(std::vector<std::string>, UnixServerAllowedGroups, \
825 std::vector<std::string>()) \
826 F(bool, UnixServerRunPSPInBackground, true) \
827 F(bool, UnixServerProxyXbox, true) \
828 F(bool, UnixServerAssumeRepoReadable, true) \
829 F(bool, UnixServerAssumeRepoRealpath, true) \
830 /* Options for testing */ \
831 F(bool, TrashFillOnRequestExit, false) \
832 /******************** \
833 | Profiling flags. | \
834 ********************/ \
835 /* Whether to maintain the address-to-VM-object mapping. */ \
836 F(bool, EnableReverseDataMap, true) \
837 /* Turn on perf-mem-event sampling roughly every this many requests. \
838 * To maintain the same overall sampling rate, the ratio between the \
839 * request and sample frequencies should be kept constant. */ \
840 F(uint32_t, PerfMemEventRequestFreq, 0) \
841 /* Sample this many memory instructions per second. This should be \
842 * kept low to avoid the risk of collecting a sample while we're \
843 * processing a previous sample. */ \
844 F(uint32_t, PerfMemEventSampleFreq, 80) \
845 /* Sampling frequency for TC branch profiling. */ \
846 F(uint32_t, ProfBranchSampleFreq, 0) \
847 /* Record the first N units loaded via StructuredLog::log() */ \
848 F(uint64_t, RecordFirstUnits, 0) \
849 /* More aggressively reuse already compiled units based on SHA1 */ \
850 F(bool, CheckUnitSHA1, true) \
851 F(bool, ReuseUnitsByHash, false) \
852 F(bool, UseEdenFS, true) \
853 /* Arbitrary string to force different unit-cache hashes */ \
854 F(std::string, UnitCacheBreaker, "") \
855 /* When dynamic_fun is called on a function not marked as
856 __DynamicallyCallable:
858 0 - do nothing
859 1 - raise a warning
860 2 - throw */ \
861 F(uint64_t, DynamicFunLevel, 1) \
862 /* When dynamic_class_meth is called on a method not marked as
863 __DynamicallyCallable:
865 0 - do nothing
866 1 - raise a warning
867 2 - throw */ \
868 F(uint64_t, DynamicClsMethLevel, 1) \
869 /* When dynamic_meth_caller is called on a static method or
870 a method not marked as __DynamicallyCallable:
872 0 - do nothing
873 1 - raise a warning
874 2 - throw */ \
875 F(uint64_t, DynamicMethCallerLevel, 1) \
876 F(bool, APCSerializeFuncs, true) \
877 F(bool, APCSerializeClsMeth, true) \
878 F(bool, LogOnIsArrayFunction, false) \
879 /* Unit prefetching options */ \
880 F(uint32_t, UnitPrefetcherMaxThreads, 0) \
881 F(uint32_t, UnitPrefetcherMinThreads, 0) \
882 F(uint32_t, UnitPrefetcherIdleThreadTimeoutSecs, 60) \
883 /* Delete any Unit not used in last N seconds */ \
884 F(uint32_t, IdleUnitTimeoutSecs, 0) \
885 /* Don't reap total Units below threshold */ \
886 F(uint32_t, IdleUnitMinThreshold, 0) \
887 /* 0 nothing, 1 notice, 2 error */ \
888 F(int32_t, NoticeOnCoerceForStrConcat, 0) \
889 /* 0 nothing, 1 notice, 2 error */ \
890 F(int32_t, NoticeOnCoerceForStrConcat2, 0) \
891 F(string, TaoMigrationOverride, std::string("")) \
892 F(string, SRRouteMigrationOverride, std::string("")) \
893 F(int32_t, SampleRequestTearing, 0) \
894 F(int32_t, RequestTearingSkewMicros, 1500) \
895 F(bool, SampleRequestTearingForce, true) \
896 F(bool, EnableAbstractContextConstants, true) \
897 /* The maximum number of resolved variants allowed in a single case
898 type. This value is determined after flattening. */ \
899 F(uint32_t, MaxCaseTypeVariants, 48) \
900 F(uint32_t, LogSlowWatchmanQueriesMsec, 500) \
901 F(uint32_t, LogSlowWatchmanQueriesRate, 1) \
902 F(uint32_t, StartOptionLogRate, 0) \
903 F(std::string, StartOptionLogCache, "/tmp/hhvm-options-%{user}-%{hash}")\
904 F(uint64_t, StartOptionLogWindow, 86400) \
905 F(hphp_fast_string_set, StartOptionLogOptions, {}) \
906 F(hphp_fast_string_set, StartOptionLogExcludeOptions, {}) \
907 F(bool, RecordReplay, false) \
908 /* Format: _SUPERGLOBAL.Key=Value[&_SUPERGLOBAL.Key=Value...] */ \
909 /* Example: _SERVER.SCRIPT_URL=/foo&_POST.key=value */ \
910 F(string, RecordSampleFilter, std::string("")) \
911 F(uint64_t, RecordSampleRate, 0) \
912 F(string, RecordDir, std::string("")) \
913 F(bool, Replay, false) \
914 F(bool, DumpStacktraceToErrorLogOnCrash, true) \
915 F(bool, IncludeReopOptionsInFactsCacheBreaker, false) \
916 F(bool, AutoloadEagerSyncUnitCache, true) \
917 F(bool, AutoloadEagerReloadUnitCache, true) \
918 F(bool, AutoloadInitEarly, false) \
919 /* Whether we should dump the request headers into $_SERVER */ \
920 F(bool, SetHeadersInServerSuperGlobal, true) \
921 /* Whether we should stop parsing cookies out of the headers and
922 setting it into a few super globals - including fully removing
923 the existance of the $_COOKIE superglobal */ \
924 F(bool, DisableParsedCookies, false) \
925 /* Whether to remove the existence of the REQUEST superglobal */ \
926 F(bool, DisableRequestSuperglobal, false) \
927 /* Enables the non-surprise flag based implementation of
928 fb_intercept2 */ \
929 F(bool, FastMethodIntercept, false) \
930 F(bool, LogHttpServerSignalSource, true) \
931 F(bool, CrashOnStaticAnalysisError, debug) \
932 /* */
934 private:
935 using string = std::string;
937 // Custom settings. This should be accessed via the GetServerCustomSetting
938 // APIs.
939 static std::map<std::string, std::string> CustomSettings;
941 public:
942 #define F(type, name, unused) \
943 static type Eval ## name;
944 EVALFLAGS()
945 #undef F
947 static bool RecordCodeCoverage;
948 static std::string CodeCoverageOutputFile;
950 // Repo (hhvm bytecode repository) options
951 static std::string RepoPath;
952 static bool RepoLitstrLazyLoad;
953 static bool RepoDebugInfo;
954 static bool RepoAuthoritative;
956 // These are (functionally) unused
957 static RepoMode RepoLocalMode;
958 static std::string RepoLocalPath;
959 static RepoMode RepoCentralMode;
960 static std::string RepoCentralPath;
961 static int32_t RepoCentralFileMode;
962 static std::string RepoCentralFileUser;
963 static std::string RepoCentralFileGroup;
964 static bool RepoAllowFallbackPath;
965 static std::string RepoJournal;
966 static bool RepoCommit;
967 static uint32_t RepoBusyTimeoutMS;
969 // pprof/hhprof options
970 static bool HHProfEnabled;
971 static bool HHProfActive;
972 static bool HHProfAccum;
973 static bool HHProfRequest;
974 static bool TrackPerUnitMemory;
976 // Sandbox options
977 static bool SandboxMode;
978 static bool SandboxSpeculate;
979 static std::string SandboxPattern;
980 static std::string SandboxHome;
981 static std::string SandboxFallback;
982 static std::string SandboxConfFile;
983 static std::map<std::string, std::string> SandboxServerVariables;
984 static bool SandboxFromCommonRoot;
985 static std::string SandboxDirectoriesRoot;
986 static std::string SandboxLogsRoot;
987 static std::string SandboxDefaultUserFile;
988 static std::string SandboxHostAlias;
990 // Mail options
991 static std::string SendmailPath;
992 static std::string MailForceExtraParameters;
994 // SimpleXML options
995 static bool SimpleXMLEmptyNamespaceMatchesAll;
997 #ifdef HHVM_FACEBOOK
998 // ThriftFBServer
999 static int ThriftFBServerWorkerThreads;
1000 static int ThriftFBServerPoolThreads;
1002 // fb303 server
1003 static bool EnableFb303Server;
1004 static int Fb303ServerPort;
1005 static std::string Fb303ServerIP;
1006 static int Fb303ServerWorkerThreads;
1007 static int Fb303ServerPoolThreads;
1008 static bool Fb303ServerExposeSensitiveMethods;
1010 // Experimental thread tuning options, allows threads to be adjusted by
1011 // thread controller (host stats monitor). `ThreadTuneDebug` is meant to allow
1012 // additional debugging metrics/logs to be exported. `ThreadTuneSkipWarmup`
1013 // will skip the warmup period (jit maturity = 100). Maximum adjustment is
1014 // defined by the `ThreadTuneAdjustmentPct` of the configured thread count,
1015 // and the step size is defined by `ThreadTuneStepPct`. Thread tuning is
1016 // turned off when `ThreadTuneAdjustmentPct` is set to 0 (default).
1017 static bool ThreadTuneDebug;
1018 static bool ThreadTuneSkipWarmup;
1019 static double ThreadTuneAdjustmentPct;
1020 static double ThreadTuneAdjustmentDownPct;
1021 static double ThreadTuneStepPct;
1022 // CPU high threshold is used for determining when to adjust threads. If the
1023 // host CPU is > this threshold no adjustments will be made.
1024 static double ThreadTuneCPUThreshold;
1025 // Thread utilization threshold is used for determining when to adjust threads,
1026 // threads will be increased if other criteria match and the current thread
1027 // utilization is above this threshold.
1028 static double ThreadTuneThreadUtilizationThreshold;
1029 #endif
1031 // Xenon options
1032 static double XenonPeriodSeconds;
1033 static uint32_t XenonRequestFreq;
1034 static bool XenonForceAlwaysOn;
1035 static bool XenonTrackActiveWorkers;
1037 // Strobelight options
1038 static bool StrobelightEnabled;
1040 static bool SetProfileNullThisObject;
1042 static bool funcIsRenamable(const StringData* name);
1044 static_assert(sizeof(RuntimeOption) == 1, "no instance variables");
1046 using RO = RuntimeOption;
1048 inline bool isJitDeserializing() {
1049 auto const m = RuntimeOption::EvalJitSerdesMode;
1050 return static_cast<std::underlying_type<JitSerdesMode>::type>(m) & 0x2;
1053 inline bool isJitSerializing() {
1054 auto const m = RuntimeOption::EvalJitSerdesMode;
1055 return static_cast<std::underlying_type<JitSerdesMode>::type>(m) & 0x1;
1058 inline bool unitPrefetchingEnabled() {
1059 return RO::EvalUnitPrefetcherMaxThreads > 0;
1062 inline StringToIntMap coeffectEnforcementLevelsDefaults() {
1063 #ifdef HHVM_FACEBOOK
1064 return {{"zoned", 2}};
1065 #else
1066 return {};
1067 #endif
1070 uintptr_t lowArenaMinAddr();
1072 ///////////////////////////////////////////////////////////////////////////////