Log C++ stack when exceeding the memory limit

Summary: We've been trying to stop native code from breaking the request memory limit,
but it's sometimes difficult to figure out what code is responsible for the
large allocations.  This diff logs the C++ stack at the moment the limit is
exceeded, which will let us find the culprits in production.

Reviewed By: @edwinsmith

Differential Revision: D1551189
Use folly connectionmanager intead

Summary: Split D1519919 in to two diffs so that open source builds could all work correctly

Reviewed By: @dcsommer

Differential Revision: D1563999
Move s_classesMutex out of Unit

Summary: It would ideally be hidden in a separate loader module but we don't
have one yet (maybe I'll do that at some point).  This doesn't make a very
substantive improvement but at least it gets it out of sight in the data layout
for a Unit.

Reviewed By: @jasone

Differential Revision: D1561947
Remove friend class FuncDict from Unit

Summary: Never heard of it, and neither has grep.

Reviewed By: @alexmalyshev

Differential Revision: D1561959
Use malloc instead of mmap in ReadOnlyArena

Summary: So it's visible to various memory tools.

Reviewed By: @jasone

Differential Revision: D1561849
Clean up in UnitRepoProxy

Summary: Reduce function arity and code duplication by calling back to
UnitEmitter for blob usage in insertUnit/getUnit.  Remove a bunch of
repo::Stmts that don't exist.

Reviewed By: @jasone

Differential Revision: D1562169
Use more unique_ptr<Unit> in unit creation

Summary: I thought I needed to allocate something in UnitEmitter::create that
the unit destructor is responsible for freeing, but now I'm not sure.  This is
worth landing anyway though (so we know that we destruct units if we don't
finish making them, if we throw exceptions or whatever).

Reviewed By: @swtaarrs

Differential Revision: D1562586
Remove the block end hash set from Func::SharedData

Summary: We only need it for profiling translations, and we don't need it after
we've reoptimized them.  We were spending 48 bytes per Func, plus whatever the
table allocates (each offset should probably take 32 bytes for the node, plus
whatever we had to allocate for the table itself).

Reviewed By: @swtaarrs

Differential Revision: D1559077
Move profCounter out of Func and into type-profile.cpp

Summary: type-profile.cpp handled marking them hot based on it anyway, and
knows when the data can't be used anymore to throw it away.  Doing this lets us
shuffle the fields slightly to go from 136 bytes (where I guess jemalloc will
allocate 160) to 128 (a size class).  Unfortunately for closures we're usually
going to waste 24 bytes now (or for funcs with more prologues than the fixed
number it could be similar).  We might want to consider putting that stuff
somewhere else so all Funcs can be the same size?  (Then we could pool allocate
them and not worry about mapping to a size class exactly.)

Reviewed By: @jasone

Differential Revision: D1560194
Remove FixupMap test from translator_tests

Summary: It allocates Funcs and Units on the stack, which is really not ok.
Reworking it doesn't seem worth it: I think it's never caught a bug, so it's
probably served its purpose by now (ostensibly for helping with initial
development of FixupMap).

Reviewed By: @bertmaher

Differential Revision: D1563063
Trim some fat off Unit (mostly related to line number information)

Summary: Move 'extended' line number info into a side-table---we only need it
for the debugger.  And shuffle stuff around to pack better.  Unit goes from 304
bytes (320 bytes per allocation) to 192 bytes.

This code is copy constructing these maps a lot, but I left that alone.  This
does fix an unlocked assignment of that std::map though (how were we getting
away with that?  Maybe just because people don't actually try to set
breakpoints on the same file from two hphpd clients simultaneously?)

Reviewed By: @jasone

Differential Revision: D1563130
Split Func::SharedData into an ExtendedSharedData to make it smaller (usually)

Summary: Most funcs aren't builtins, and most funcs are not gigantic.  We can
bring SharedData from 160 bytes down to the 128 byte size class in these common
cases by splitting uncommon cases out.  Costs a branch when you check whether
things are builtins, and a branch to get line2() or past(), but grepping
callsites didn't find anything for those two that looked hot (mostly JIT-time
stuff for past() and reflection/debugger for lines).

Reviewed By: @jasone

Differential Revision: D1560352
Some cleanup in ConcurrentTableSharedStore---fix bug in EntryInfo

Summary: Some formatting normalization, and fix EntryInfo's copy constructor.
(We're using them in std vectors---and if it ever copied them it would cause a
double free.)

Reviewed By: @markw65

Differential Revision: D1564376
Remove support for ConcurrentTableLockFree (it's fundamentally broken)

Summary: It uses "sleep" to implement thread safety.

Reviewed By: @edwinsmith

Differential Revision: D1564401
Remove ConditionalReadLock

Summary: The only use was in APC for ConcurrentTableSharedStore in "lock free"
mode.  (Incidentally: apparently we're making calls into this lock profiler
thing all the time from there ...)  Also fix copy constructor bug.

Reviewed By: @markw65

Differential Revision: D1564442
Make APC priming methods not leak if you prime the same key multiple times

Summary: This probably never happens but it bothered me while trying to
understand this code.

Reviewed By: @markw65

Differential Revision: D1564613
posix_getgrnam returns false when no group gound

Summary: getgrnam_r and getgrgid_r return zero on success and an error number on failure.
If no matching group was found they return 0 and store NULL in *result.

This fixes three zend tests. Two of them have the exact same content though (lol)
Closes https://github.com/facebook/hhvm/pull/3722

Reviewed By: @fredemmott

Differential Revision: D1548070
Reorganize some TARGETs files to avoid "../" warnings

Summary: Just a bit of cleanup. Removes all the .cpp related warnings
from fbconfig -r hphp.

Reviewed By: @edwinsmith

Differential Revision: D1556540
Fix gmp_strval base issue

Summary: We were using the supplied input base value meant for output on the input, causing bad mojo.  This fixes it to only use the base for creating the output string.

Fixes #3793
Closes https://github.com/facebook/hhvm/pull/3794

Reviewed By: @fredemmott

Differential Revision: D1566171
Fix "wholecfg" region selector

Summary: With the "wholecfg" region selector, a bunch of tests were failing
because of some recent changes to check the region.  The main issue
was that the arcs were being inserted before the involved blocks in
the region.  This diff fixes that and rewrites some things along the
way.

Reviewed By: @alexmalyshev

Differential Revision: D1564686