Move the eager vm save to enterTCHelper

Summary: We always save rVmFp and rVmSp as part of the service
request stub; but we could just as easily do it in
enterTCHelper, and reduce the size of the stubs.

When I went to reduce the size of the stubs, I saw that we
were already somewhat undercounting - although we never come
close to the worst case in practice. So maxStubSpace is
actually unchanged by this diff (although the actual space
for non-ephemeral stubs will be reduced).

Reviewed By: @jdelong

Differential Revision: D1632905
Don't use KindOfAny in predictOutputs() and friends

Reviewed By: @jdelong

Differential Revision: D1615152
Eliminate KindOfAny and KindOfNone

Summary: We replace them with:
- separate enum types, KindOf{None,Any}Type, for use in function argument
  discrimination.
- MaybeDataType, for members that stand for either (DataType|KindOfAny)
  or (DataType|KindOfNone); this is context-dependent.
- a pile of booleans for members that need (DataType|Any|None).
- gross and ugly #define's in bootstrap/idl.h, which should go away
  eventually anyway.

Reviewed By: @jdelong

Differential Revision: D1620231
s/KindOfUnknown/KindOfInvalid

Reviewed By: @edwinsmith

Differential Revision: D1624837
Remove some uses of KindOfInvalid

Summary: This takes care of three easily-removed sorts of uses of KindOfInvalid.

The first is dead code; this includes:
  - Type::getDataType() and Type::getHhvmDataType() in the compiler
  - getArgType() in ext/extension.h

The second is easy, file-local conversions to MaybeDataType; these
include:
  - EmitterVisitor::analyzeSwitch()
  - get_option_value_type() in ext_mysqli
  - convert_for_pow() in ext_math

The last is cases where we can't convert to MaybeDataType because the
DataType is part of a TypedValue.  For these, we introduce
kInvalidDataType, which is identical to KindOfInvalid but is not part of
the DataType enum, so that we can expunge KindOfInvalid from case
statements when the remaining uses are deleted.  These include:
  - logic around `mainReturn' in the compiler
  - MixedArray
  - HashCollection
  - NameValueTable

Finally, one miscellaneous s/KindOfInvalid/kInvalidDataType was made:
  - The DataType serialized in `constant->valueText' in
    ClassInfoUnique(); not sure where this comes from.

Reviewed By: @jdelong

Differential Revision: D1624839
Kill KindOfInvalid

Summary: Remove all the remaining uses of KindOfInvalid.  Primarily, this entails
converting:
  - TypeAnnotation::dataType()
  - Func::ParamInfo::builtinType
  - Func::SharedData::m_returnType
  - FuncEmitter::returnType
  - TypeConstraint::underlyingDataType()
and related functions and members to use MaybeDataType.

Reviewed By: @jdelong

Differential Revision: D1624851
Convert server to HNI

Summary: fixes #3948

Reviewed By: @ptarjan

Differential Revision: D1615453
Convert LDAP to HNI

Summary: fixes #3931

Reviewed By: @ptarjan

Differential Revision: D1615345
Eliminate Vmeta

Summary: It was useful during transition to vasm, when we needed to
track program points across multiple Vunits. No longer useful.

Reviewed By: @swtaarrs

Differential Revision: D1631688
Don't pass userdata to callback in array_walk unless it was specified

Summary: Fixes #3022

Reviewed By: @ptarjan

Differential Revision: D1634275
Move CodeGenerator::m_unit and m_frozen to CodegenState

Reviewed By: @jdelong

Differential Revision: D1631629
Standardize on lea for address computations (including sp adjustments)

Summary: It's the same size in every situation we use it in, it doesn't modify
eflags, and Intel explicitly recommends using it for values that will be used
as pointers in loads or stores later on down the line.

Reviewed By: @edwinsmith

Differential Revision: D1631697
Tweak to enable more refcount optimizations

Summary: When a value is known to exist in many places, observeValue() will not
insert any IncRef before a DecRef. That's bad because it ends up
preventing some IncRef/DecRef pairs from being eliminated because the
IncRef is pushed down past the DecRef.  This diff makes sure that we
always drop an IncRef before a DecRef, which then enables more
IncRef/DecRef pairs to be eliminated.

Reviewed By: @swtaarrs

Differential Revision: D1631498
Add native data serialization support

Summary: If a native data class contains the following function, it is considered serializable.

Variant sleep()
void wakeup(const Variant& content)

All serialized native content will be stored along with other user-defined serializable properties.
Native content is stored using a reserved key "[underscore][underscore]native".
The key value pair [underscore][underscore]native will not appear in the serialized map if sleep() returns null.

Reviewed By: @elgenie

Differential Revision: D1582161
Add a thread filter to the ring buffer

Summary: Typically you just want to know what was happening recently on
the thread that crashed, so add a thread parameter. 0 means all threads.

Reviewed By: @swtaarrs

Differential Revision: D1634720
emitFuncGuard should use prepareForSmash

Summary: We don't want to recreate the alignment logic
in lots of places, and we need to tag the guard so that
future relocations know its alignment requirements

Reviewed By: @swtaarrs

Differential Revision: D1634806
Add ReflectionClass::getAttribute to HHI

Summary: Already there for functions and parameters, was missing for classes. Fixes facebook/hhvm#4049

Reviewed By: @jano

Differential Revision: D1634952
Micro-optimize InitPackedArrayLoop

Summary: Its okay to use SIMD registers to move values from the stack to
the array, because PackedArray doesn't use TypedValueAux's m_aux
field. Use the flags from subqi instead of cmp(0,j).

Once those changes were done I noticed an xchg crept into the
code (due to lack of phi-hinting), so fiddled the initialization
order to suppress the xchg.

Reviewed By: @mhahnenberg

Differential Revision: D1632139
Fix PCRE cache, and related code cleanup

When the PCRE cache fills up, memory is leaked since the static string
created by insert_cached_pcre() cannot be freed. Also, queueing cached
regexes for deletion on request termination is not good policy -- it is
effectively a memory leak for long-running scripts.

Also, when the PCRE cache is full, new regexes need to be recompiled on
every call to preg_match() etc. so the performance of an app using
dynamically-generated regex strings will degrade once the limit is
reached.

So:
* Introduce a thread-local PCRE cache with LRU eviction, used alongside
  the existing cache.
* Do not place an entry in the shared cache unless the input text is a
  static string. This prevents pollution of the shared cache with
  regexes derived from user input.
* If the shared cache is full, or if the regex text is non-static, store
  the pcre object in the local cache.
* Use reference counting for local cache entries so that recursive code
  which requires more than 1024 regexes to be active at a given time
  will not crash. But for entries in the shared cache, do not update the
  reference count, to avoid degrading performance due bus activity.
* Retain the thread-local cache beyond the end of the request. This is
  basically the same as the way Zend manages its PCRE cache, and should
  reduce startup overhead.
* Remove m_overflow and associated functions.
* Make the "bump" regex a static string so that its regex will be
  shared.

Also:
* Use tl_ prefix for thread-local variables, per convention.
* Note that "const pcre_cache_entry*" becomes non-const
  pcre_cache_entry_ptr in a few places, since "const SmartPtr" would be
  equivalent to "pcre_cache_entry const*". There's no equivalent for
  a non-const SmartPtr which wraps a const.