5 years agovarious improvements to the Synchronized tests
Adam Simpkins [Wed, 6 Jul 2016 23:21:37 +0000 (16:21 -0700)]
various improvements to the Synchronized tests

Add a runParallel() helper function, to clean up logic that was copy-and-pasted
through most of the test functions.  Additionally, clean up the tests to avoid
unnecessary sleeps.  Also fix backwards arguments to EXPECT_EQ() calls--gtest
assumes the first argument is the expected value, and the second argument is
the value being checked.

Reviewed By: yfeldblum

Differential Revision: D3521565

fbshipit-source-id: e4f007d52c114080cff1fd7a0a407fba39fa8b0e

5 years agoRemove LockTraitsBoost from Synchronized.h
Adam Simpkins [Wed, 6 Jul 2016 23:21:34 +0000 (16:21 -0700)]
Remove LockTraitsBoost from Synchronized.h

Update Synchronized.h to no longer include LockTraitsBoost.h
Callers that want to use folly::Synchronized with a boost lock type will now
need to explicitly include LockTraitsBoost.h on their own.

Reviewed By: yfeldblum

Differential Revision: D3521168

fbshipit-source-id: 08f0041f51fe2e9566bde58e9f039a6d187b54e3

5 years agoRemove extra ';' from used macros in Traits.h
Mohamed Amin JABRI [Wed, 6 Jul 2016 21:23:51 +0000 (14:23 -0700)]
Remove extra ';' from used macros in Traits.h

Using folly on OSX using gcc-5.3 causes errors due to extra ';' in macro expansion in Traits.h.

Reviewed By: yfeldblum

Differential Revision: D3205265

Pulled By: elliottneilclark

fbshipit-source-id: f49ab04add382660719b3bb83bce3c8dc303db8b

5 years agoClean up int128_t macro gating
Michael Lee [Wed, 6 Jul 2016 20:41:57 +0000 (13:41 -0700)]
Clean up int128_t macro gating

Summary: There is inconsistent use of `#ifdef` and `#if`. Cleaning this up

Reviewed By: yfeldblum

Differential Revision: D3523561

fbshipit-source-id: 23f62d632efeb1b9b137b3e3582c37aae591d901

5 years agoCleanup of how we use BIO/BIO_METHODs
Anirudh Ramachandran [Wed, 6 Jul 2016 16:57:59 +0000 (09:57 -0700)]
Cleanup of how we use BIO/BIO_METHODs

AsyncSSLSocket's eorAwareBioWrite does some invasive stuff like
reaching into a BIO and replacing its method (and the 'write' funcptr). This
approach won't work with OpenSSL 1.1.0 or BoringSSL due to API changes and
structs being made opaque. This diff adds a layer of wrappers for some BIO
operations. Note that this is still only tested on 1.0.2

Reviewed By: siyengar

Differential Revision: D3338861

fbshipit-source-id: 2ac9318b0df1709873511bfde0fa85d87c5dd29a

5 years agoRefactor folly::to<>
Marcus Holland-Moritz [Wed, 6 Jul 2016 10:56:58 +0000 (03:56 -0700)]
Refactor folly::to<>

This is the main diff of the series. Its main purpose is to make
the internals of folly::to<> propagate error codes instead of
throwing exceptions. Along with this, it makes the following

- Move most of the string-to-int implementation out of the header file

- Unify error/exception strings across conversion routines

- Introduce a ConversionError class that derives from std::range_error

- Capture an error code in ConversionError in addition to a string

- Optimize tolower() calls in Conv.cpp

- Introduce ConversionResult<>, which is used as the internal result wrapper

- Get rid of all error checking macros

There are quite a few benefits here.

== Faster conversions ==

For a large set of conversions, the performance is unchanged. I've removed
all benchmarks that were unchanged from the table below for simplicity.

A few things stand out:

- `follyAtoiMeasure` is consistently faster, sometimes by quite a large margin

- The cost of throwing exceptions is significantly reduced, as throwing them
  further down on the call stack will reduce the amount of stack unwinding

- String-to-boolean and string-to-float conversions are significantly faster
  when passing in a string representation (e.g. "off" or "infinity") thanks
  to the optimized tolower_ascii() call (column `New+Ascii` in the table)

- Conversions between int and float are significantly faster and almost back
  at the performance of before the undefined behaviour fix

- All string-to-(int|float|bool) conversions are consistently faster

The columns in the table are as follows:

  Original:  Original code before the undefined behaviour fix
  Fix UB:    Code with the undefined behaviour fix; this impacts mostly the
             float <-> int conversions, but appears to have a small effect
             on some other benchmarks
  New:       New code introduced by this diff, but without the tolower_ascii()
  New+Ascii: New code, including the tolower_ascii() optimization

                                                   Original   Fix UB     New        New+Ascii
  folly/test/ConvBenchmark.cpp                     time/iter  time/iter  time/iter  time/iter
  handwrittenAtoiMeasure(1)                           3.95ns     3.95ns     3.95ns     3.95ns
  follyAtoiMeasure(1)                                 6.08ns     6.08ns     3.95ns     3.95ns
  handwrittenAtoiMeasure(2)                           5.47ns     5.47ns     5.47ns     5.47ns
  follyAtoiMeasure(2)                                 5.77ns     5.77ns     3.95ns     3.95ns
  handwrittenAtoiMeasure(3)                           6.08ns     6.08ns     6.08ns     6.08ns
  follyAtoiMeasure(3)                                 6.08ns     6.08ns     4.25ns     4.25ns
  handwrittenAtoiMeasure(4)                           6.99ns     6.99ns     6.99ns     6.99ns
  follyAtoiMeasure(4)                                 6.99ns     6.99ns     4.56ns     4.56ns
  handwrittenAtoiMeasure(5)                           7.90ns     8.20ns     7.90ns     7.90ns
  follyAtoiMeasure(5)                                 7.29ns     7.29ns     4.86ns     4.86ns
  handwrittenAtoiMeasure(6)                           8.81ns     9.42ns     8.81ns     8.81ns
  follyAtoiMeasure(6)                                 7.29ns     7.29ns     4.86ns     4.86ns
  handwrittenAtoiMeasure(7)                           9.72ns    10.63ns     9.72ns     9.72ns
  follyAtoiMeasure(7)                                 7.60ns     7.60ns     5.16ns     5.16ns
  handwrittenAtoiMeasure(8)                          10.63ns    11.85ns    10.63ns    10.63ns
  follyAtoiMeasure(8)                                 8.51ns     8.51ns     6.08ns     6.08ns
  handwrittenAtoiMeasure(9)                          11.54ns    13.07ns    11.54ns    11.54ns
  follyAtoiMeasure(9)                                 8.81ns     8.81ns     6.08ns     6.08ns
  handwrittenAtoiMeasure(10)                         12.46ns    14.28ns    12.46ns    12.46ns
  follyAtoiMeasure(10)                                8.81ns     8.81ns     6.38ns     6.38ns
  handwrittenAtoiMeasure(11)                         13.37ns    15.50ns    13.37ns    13.37ns
  follyAtoiMeasure(11)                                9.12ns     9.12ns     6.38ns     6.38ns
  handwrittenAtoiMeasure(12)                         14.28ns    16.71ns    14.28ns    14.28ns
  follyAtoiMeasure(12)                               10.03ns    10.03ns     7.29ns     7.29ns
  handwrittenAtoiMeasure(13)                         15.19ns    17.92ns    15.19ns    15.19ns
  follyAtoiMeasure(13)                               10.33ns    10.33ns     7.60ns     7.60ns
  handwrittenAtoiMeasure(14)                         16.10ns    19.14ns    16.10ns    16.10ns
  follyAtoiMeasure(14)                               10.33ns    10.33ns     7.60ns     7.60ns
  handwrittenAtoiMeasure(15)                         17.01ns    20.36ns    17.01ns    17.01ns
  follyAtoiMeasure(15)                               10.63ns    10.63ns     7.90ns     7.90ns
  handwrittenAtoiMeasure(16)                         17.92ns    21.57ns    17.92ns    17.92ns
  follyAtoiMeasure(16)                               11.55ns    11.55ns     8.81ns     8.81ns
  handwrittenAtoiMeasure(17)                         18.84ns    22.79ns    18.84ns    18.84ns
  follyAtoiMeasure(17)                               11.85ns    11.85ns     8.81ns     8.81ns
  handwrittenAtoiMeasure(18)                         19.75ns    24.00ns    19.75ns    19.75ns
  follyAtoiMeasure(18)                               11.85ns    11.85ns     9.12ns     9.12ns
  handwrittenAtoiMeasure(19)                         20.66ns    25.22ns    20.66ns    20.66ns
  follyAtoiMeasure(19)                               12.16ns    12.16ns     9.11ns     9.11ns
  stringToBoolNumClassic                             12.76ns    12.76ns    11.96ns    12.15ns
  stringToBoolNumClassicError                         3.19us     3.18us     1.58us     1.58us
  stringToBoolStrClassic                             17.92ns    17.92ns    15.50ns     7.60ns
  stringToBoolStrClassicError                         3.21us     3.18us     1.57us     1.57us
  stringToFloatNumClassic                            32.96ns    32.81ns    32.10ns    31.12ns
  stringToFloatNumClassicError                        2.73us     2.69us     1.65us     1.66us
  stringToFloatStrClassic                            37.37ns    38.58ns    36.76ns    16.71ns
  stringToFloatStrClassicError                        2.87us     2.87us     1.60us     1.59us
  stringToDoubleNumClassic                           31.30ns    31.82ns    29.77ns    29.17ns
  stringToDoubleNumClassicError                       2.69us     2.66us     1.65us     1.66us
  stringToDoubleStrClassic                           37.67ns    37.67ns    35.84ns    16.71ns
  stringToDoubleStrClassicError                       2.87us     2.86us     1.58us     1.58us
  stringToCharSignedClassic                          16.71ns    18.08ns    15.49ns    14.59ns
  stringToCharSignedClassicError                      3.87us     3.82us     1.61us     1.61us
  stringToCharUnsignedClassic                        15.49ns    15.19ns    12.46ns    12.66ns
  stringToCharUnsignedClassicError                    2.73us     2.70us     1.62us     1.62us
  stringToIntSignedClassic                           21.26ns    19.44ns    17.92ns    18.40ns
  stringToIntSignedClassicError                       3.94us     3.89us     1.64us     1.64us
  stringToIntUnsignedClassic                         17.93ns    18.53ns    15.50ns    15.50ns
  stringToIntUnsignedClassicError                     2.72us     2.71us     1.62us     1.61us
  stringToLongLongSignedClassic                      34.63ns    30.58ns    27.04ns    27.04ns
  stringToLongLongSignedClassicError                  3.94us     3.90us     1.63us     1.63us
  stringToLongLongUnsignedClassic                    51.04ns    47.96ns    46.44ns    46.68ns
  stringToLongLongUnsignedClassicError                2.73us     2.71us     1.61us     1.61us
  ptrPairToCharSignedClassic                          5.16ns     5.16ns     3.34ns     3.65ns
  ptrPairToCharSignedClassicError                     3.56us     3.54us     1.61us     1.61us
  ptrPairToCharUnsignedClassic                        2.43ns     2.43ns     2.13ns     2.13ns
  ptrPairToCharUnsignedClassicError                   2.63us     2.63us     1.61us     1.61us
  ptrPairToIntSignedClassic                           6.99ns     6.99ns     5.16ns     5.16ns
  ptrPairToIntSignedClassicError                      4.08us     4.06us     1.61us     1.61us
  ptrPairToIntUnsignedClassic                         4.25ns     4.56ns     3.34ns     3.34ns
  ptrPairToIntUnsignedClassicError                    2.70us     2.70us     1.60us     1.60us
  ptrPairToLongLongSignedClassic                     12.16ns    12.16ns     9.72ns     9.72ns
  ptrPairToLongLongSignedClassicError                 4.06us     4.06us     1.61us     1.61us
  ptrPairToLongLongUnsignedClassic                   29.13ns    29.13ns    27.61ns    27.61ns
  ptrPairToLongLongUnsignedClassicError               2.71us     2.72us     1.63us     1.64us
  intToCharSignedClassic                            405.02ps   506.35ps   405.02ps   405.02ps
  intToCharSignedClassicError                         2.10us     2.09us     1.63us     1.64us
  intToCharUnsignedClassic                          303.79ps   303.78ps   303.77ps   303.77ps
  intToCharUnsignedClassicError                       2.10us     2.09us     1.63us     1.64us
  intToIntSignedClassic                             405.02ps   405.02ps   405.01ps   405.01ps
  intToIntSignedClassicError                          1.99us     1.98us     1.72us     1.72us
  intToIntUnsignedClassic                           405.03ps   405.03ps   379.71ps   379.71ps
  intToIntUnsignedClassicError                        2.09us     2.09us     1.63us     1.63us
  intToFloatClassic                                 545.11ps     3.34ns     1.23ns     1.23ns
  intToFloatClassicError                              1.67us     2.37us     1.73us     1.72us
  floatToFloatClassic                               759.47ps   759.47ps   759.45ps   759.45ps
  floatToFloatClassicError                            6.45us     6.44us     1.77us     1.77us
  floatToIntClassic                                 637.82ps     2.89ns     1.50ns     1.50ns
  floatToIntClassicError                              1.92us     2.61us     1.82us     1.83us

== Improved build times ==

I've checked this with gcc 4.9.3, and compile times for both ConvTest and
ConvBenchmark are reduced by roughly 10%:

                    original  new code
  ConvTest.o         14.788s   13.361s
  ConvBenchmark.o    16.148s   14.578s

== Smaller binary size ==

Again, checked with gcc 4.9.3, stripped binaries are slightly smaller with
the new code:

                    original  new code
  conv_test           761704    749384
  conv_benchmark      539632    510928

== Ability to add new non-throwing interfaces ==

This change sticks to the original API that will throw an exception in case
of an error. A subsequent diff will introduce non-throwing interfaces with
a minimum of additional code.

Reviewed By: ericniebler

Differential Revision: D3433856

fbshipit-source-id: 9bc976ebc181fe2f172ae47c78edf407e9ee7bb0

5 years agoupdate Synchronized to use LockTraits
Adam Simpkins [Wed, 6 Jul 2016 01:26:33 +0000 (18:26 -0700)]
update Synchronized to use LockTraits

Update the Synchronized code to use the new LockTraits added in D3504625.
This also removes the acquireRead*() and releaseRead*() adapter functions that
had been defined for various other lock types, which are no longer needed.

Reviewed By: yfeldblum

Differential Revision: D3512310

fbshipit-source-id: daedd47c0378aebd479dbfe7aba24978deb9cc05

5 years agoadd LockTraits
Adam Simpkins [Wed, 6 Jul 2016 01:26:31 +0000 (18:26 -0700)]
add LockTraits

This adds a new LockTraits template class, for specifying how to use arbitrary
custom mutex types.

The goal of this new class is to replace the acquireRead(), acquireReadWrite(),
releaseRead(), and releaseReadWrite() functions currently defined in
Synchronized.h.  I have not replaced these functions yet in this diff, but will
do so in a follow-up diff.

LockTraits has a few advantages over the existing methods:
* It provides mechanisms for telling if a given mutex supports shared access
  and timed access.
* The default LockTraits implementation automatically figures out the correct
  behavior for classes that define lock(), unlock(), methods.  It automatically
  detects sharing and timed support based on the presence of lock_shared() and
  try_lock_for() methods.

LockTraits can be specialized for custom lock types that do not conform with
the lock method names used by the C++ standard.  This does differ slightly from
the argument dependent lookup mechanism used by the acquireRead() functions.

Reviewed By: yfeldblum

Differential Revision: D3504625

fbshipit-source-id: 40320997e9ae2147baecd10b70e8dc06a35e49e1

5 years agoDisable PthreadKeyUnregister on iOS and MSVC
Andrii Grynenko [Tue, 5 Jul 2016 18:34:29 +0000 (11:34 -0700)]
Disable PthreadKeyUnregister on iOS and MSVC

Summary: ~PthreadKeyUnregister logic is not safe if we can't guarantee that it has the maximum pririty (i.e. is the last to be run on shutdown).

Reviewed By: ericniebler

Differential Revision: D3517589

fbshipit-source-id: 3340e2e19cf52973ee677288bc4ac6105f3f2543

5 years agofix flaky ConnectTFOTimeout and ConnectTFOFallbackTimeout tests
Adam Simpkins [Tue, 5 Jul 2016 18:20:28 +0000 (11:20 -0700)]
fix flaky ConnectTFOTimeout and ConnectTFOFallbackTimeout tests

In the ConnectTFOTimeout and ConnectTFOFallbackTimeout tests in
AsyncSSLSocketTest.cpp, the client runs for 1ms before timing out and quitting.
It may end up shutting down the server thread before the server has even
received the TCP connect callback.  If this happened it would cause the test to
fail, since the server code checked to make sure the callback was invoked.

This diff creates a new ConnectTimeoutCallback server-side callback for these
tests to use, which doesn't care if it gets told about a new connection or not.

Reviewed By: siyengar

Differential Revision: D3512809

fbshipit-source-id: ce77fe944fb06a38a84c1458356f161cec7387b3

5 years agoAdd sa_len for sockaddr conversions
Subodh Iyengar [Tue, 5 Jul 2016 05:46:06 +0000 (22:46 -0700)]
Add sa_len for sockaddr conversions

Some platforms like Apple add a additional
field to sockaddr called sa_len.

This is not normally required by POSIX, so
all posix methods work correctly when a sockaddr
is passed in without a sa_len set.

However other functions which are not defined
by posix such as connectx require this field to
operate correctly.

Reviewed By: yfeldblum

Differential Revision: D3514266

fbshipit-source-id: f8e2941f337222486c81c911dbd06a2ce35e4f00

5 years agofolly:thread_local_test: avoid test failure due to dlopen of *SAN-enabled binary...
Jim Meyering [Sat, 2 Jul 2016 16:31:28 +0000 (09:31 -0700)]
folly:thread_local_test: avoid test failure due to dlopen of *SAN-enabled binary: skip it

The ThreadLocal.SharedLibrary test would fail when compiled with any sanitizer.
Skip that test when any sanitizer is enabled.

Reviewed By: Mizuchi

Differential Revision: D3508099

fbshipit-source-id: 0419269f6454ee4edb93fe00b6f0e79756e609d0

5 years agoInclude the correct headers in various tests
Christopher Dykes [Sat, 2 Jul 2016 04:33:07 +0000 (21:33 -0700)]
Include the correct headers in various tests

Summary: There are two types of includes this adds. The first are standard library headers that weer previously included by transitive dependencies, but aren't included under MSVC, so need to be explicitly included. The second type is a couple of portability headers.

Reviewed By: yfeldblum

Differential Revision: D3513196

fbshipit-source-id: 4f2ac1207aee887ba41c19f5490003e5fe4088f4

5 years agoDon't do #if in the middle of a parameter to a preprocessor macro
Christopher Dykes [Sat, 2 Jul 2016 04:32:07 +0000 (21:32 -0700)]
Don't do #if in the middle of a parameter to a preprocessor macro

Summary: Because MSVC doesn't let you do this. Separate the tests out and disable the entire thing instead.

Reviewed By: yfeldblum

Differential Revision: D3513174

fbshipit-source-id: 7411418204083f172883ca96eff3785c912a9647

5 years agoMark a few constants as constexpr so VLAs aren't required
Christopher Dykes [Sat, 2 Jul 2016 04:31:35 +0000 (21:31 -0700)]
Mark a few constants as constexpr so VLAs aren't required

Summary: Because MSVC doesn't support VLAs.

Reviewed By: yfeldblum

Differential Revision: D3513143

fbshipit-source-id: 256e9e843004a3c37821b3dddc6ecd4c6b5645d9

5 years agoUse a defined form of uniform_int_distribution
Christopher Dykes [Sat, 2 Jul 2016 03:39:26 +0000 (20:39 -0700)]
Use a defined form of uniform_int_distribution

Summary: As per the behavior of using `uint8_t` as the template parameter is undefined, and is not supported on MSVC, so use `unsigned short` instead, which is a defined form.

Reviewed By: yfeldblum

Differential Revision: D3507309

fbshipit-source-id: c4c830371d08aee4a3de90bb394d22d92ad9a575

5 years agoDon't use a VLA for the dest buffer when testing wide FBString to multi-byte FBString
Christopher Dykes [Sat, 2 Jul 2016 03:34:53 +0000 (20:34 -0700)]
Don't use a VLA for the dest buffer when testing wide FBString to multi-byte FBString

Summary: Because MSVC doesn't support VLA's.

Reviewed By: yfeldblum

Differential Revision: D3507441

fbshipit-source-id: a50bdbad31674d236e4994903c75232d70f32bc0

5 years agoboost::filesystem::path is a wide string on Windows
Christopher Dykes [Sat, 2 Jul 2016 02:28:10 +0000 (19:28 -0700)]
boost::filesystem::path is a wide string on Windows

Summary: Which means `.native()` returns a `wstring`, and `.c_str()` returns a `wchar_t*`. As we're using them in places expecting a `char*`, convert to `string` first.

Reviewed By: yfeldblum

Differential Revision: D3506911

fbshipit-source-id: ca34b9888f98106914438490bbd860f9b922ad5e

5 years agoMoved object destructor should not log
Aravind Anbudurai [Sat, 2 Jul 2016 02:27:31 +0000 (19:27 -0700)]
Moved object destructor should not log

I introduced a helper method to make an AutoTimer and forced default move-ctor.
That caused moved object's destruction to log and that is undesirable.
This defines a custom move-ctor to set a direct the moved object to not log.

Reviewed By: yfeldblum

Differential Revision: D3511206

fbshipit-source-id: 38ae6de5fe76077c5e5ed10f64ebe959f5674fa7

5 years agofix the ThreadLocal test in open source builds
Adam Simpkins [Fri, 1 Jul 2016 22:02:40 +0000 (15:02 -0700)]
fix the ThreadLocal test in open source builds

The ThreadLocalTest has been broken in open source builds ever since D2678401,
because was never updated to build the helper shared library needed
by the test.

This updates to build the shared library.

Reviewed By: yfeldblum

Differential Revision: D3511125

fbshipit-source-id: 4684dbc32acf6ffbfc07079da91a1da480259502

5 years agoMake AutoTimer work with std::chrono::duration instead of seconds with type double
Aravind Anbudurai [Fri, 1 Jul 2016 17:10:43 +0000 (10:10 -0700)]
Make AutoTimer work with std::chrono::duration instead of seconds with type double

Currently, AutoTimer outputs duration as a double with seconds as units.
This is limiting and I'm making it return std::chrono::duration. Users can specify the type with DurationType.

This is needed for me because the library that I am going to use inside the callback I pass in using chrono::duration and it feels hacky to go from duration -> double -> duration.

Reviewed By: yfeldblum

Differential Revision: D3506557

fbshipit-source-id: 0a5e9e16181bfac3a10df6a253716c0499cff5df

6 years agoConstantRNG should implement UniformRandomBitGenerator
Christopher Dykes [Fri, 1 Jul 2016 05:01:48 +0000 (22:01 -0700)]
ConstantRNG should implement UniformRandomBitGenerator

Summary: As per it was almost there, except that `min()` and `max()` need to be static members.

Reviewed By: yfeldblum

Differential Revision: D3507595

fbshipit-source-id: 5e0b321c477e37ab8a3487ad643caa83cc6cfc9d

6 years agoclang-format AutoTimer.h
Aravind Anbudurai [Fri, 1 Jul 2016 03:52:41 +0000 (20:52 -0700)]
clang-format AutoTimer.h

Somehow the formatting is messed up and it was triggering my OCD.
Sending a diff before I go crazy

Depends on D3506557

Reviewed By: yfeldblum

Differential Revision: D3506618

fbshipit-source-id: 218ce2100cc45c5017328e97344029061fe2eff5

6 years agoDon't use named variadic macro parameters
Christopher Dykes [Fri, 1 Jul 2016 01:47:32 +0000 (18:47 -0700)]
Don't use named variadic macro parameters

Summary: MSVC doesn't support them, so use `__VA_ARGS__` instead.

Reviewed By: yfeldblum

Differential Revision: D3507071

fbshipit-source-id: 186834c87e74257c709fcbc08e3bda7b1b55d02b

6 years agoUse asm_volatile_memory() for portable memory barriors in LifoSemTests
Christopher Dykes [Fri, 1 Jul 2016 01:21:53 +0000 (18:21 -0700)]
Use asm_volatile_memory() for portable memory barriors in LifoSemTests

Summary: The portability headers exist for a reason, so use them.

Reviewed By: yfeldblum

Differential Revision: D3507031

fbshipit-source-id: f88c8ed37e648d38231c1d923c1d69d551beabff

6 years agoUse UTF-8 strings for strings with multi-byte Unicode code points in them
Christopher Dykes [Fri, 1 Jul 2016 01:20:43 +0000 (18:20 -0700)]
Use UTF-8 strings for strings with multi-byte Unicode code points in them

Summary: Because MSVC doesn't support strings with multi-byte Unicode code points in them unless it's in a UTF-8 string.

Reviewed By: yfeldblum

Differential Revision: D3507197

fbshipit-source-id: 27bff1efee03180716418fbfa9ef98f9c04929d9

6 years agoUse decltype rather than typeof
Christopher Dykes [Fri, 1 Jul 2016 01:20:26 +0000 (18:20 -0700)]
Use decltype rather than typeof

Summary: Because `typeof` is a GCC specific extension whose standardized version is called `decltype`.

Reviewed By: yfeldblum

Differential Revision: D3506960

fbshipit-source-id: 0e7495028632b23f149bf8d0163d2000ebec2fcc

6 years agoRename SIZE to kSize
Christopher Dykes [Fri, 1 Jul 2016 01:19:55 +0000 (18:19 -0700)]
Rename SIZE to kSize

Summary: Because `SIZE` is a defined type on Windows.

Reviewed By: yfeldblum

Differential Revision: D3507144

fbshipit-source-id: ee9fd9bb7c35055ca69719717aa10d8e9c8701c2

6 years agoUse uint32_t rather than uint
Christopher Dykes [Fri, 1 Jul 2016 01:19:27 +0000 (18:19 -0700)]
Use uint32_t rather than uint

Summary: Because `uint32_t` is standardized, and MSVC doesn't have `uint`.

Reviewed By: yfeldblum

Differential Revision: D3507011

fbshipit-source-id: ac0abb4ad1b2dbaa890554589817ce75abdd987e

6 years agoUse std::vector in the CacheLocalityBenchmark rather than a VLA
Christopher Dykes [Fri, 1 Jul 2016 01:19:14 +0000 (18:19 -0700)]
Use std::vector in the CacheLocalityBenchmark rather than a VLA

Summary: Because MSVC doesn't support VLAs.

Reviewed By: yfeldblum

Differential Revision: D3506835

fbshipit-source-id: 8683b5c513ed25e7f47642c8493f8b10da9906be

6 years agoUse float literals when initializing float values
Christopher Dykes [Fri, 1 Jul 2016 01:18:57 +0000 (18:18 -0700)]
Use float literals when initializing float values

Summary: MSVC was correctly warning that we were initializing `float` variables with `double` literals. This just adds the explicit suffix so they are `float` literals instead.

Reviewed By: yfeldblum

Differential Revision: D3506797

fbshipit-source-id: 7eb4588958eddb984ba830e2599ac505d495783e

6 years agoLong is not long enough for a long long
Christopher Dykes [Fri, 1 Jul 2016 01:11:51 +0000 (18:11 -0700)]
Long is not long enough for a long long

Summary: Thus `1UL << 63 == 0` which is not the intended behavior.

Reviewed By: yfeldblum

Differential Revision: D3478480

fbshipit-source-id: a31dba7f5a503be2b34a4cb66bc7039076f158a0

6 years agoDon't try and instantiate an invalid function in DiscriminatedPtrDetail
Christopher Dykes [Fri, 1 Jul 2016 01:09:29 +0000 (18:09 -0700)]
Don't try and instantiate an invalid function in DiscriminatedPtrDetail

THe issue is quite simple: Regardless of the control flow, the previous implementation of this was instantiating `ApplyVisitor1<V,R>` which declares a return type, but never returns.
This refactors `ApplyVisitor1` and `ApplyConstVisitor1` so that the part of the control flow that was previously never reached simply doesn't exist anymore.

Reviewed By: yfeldblum

Differential Revision: D3479584

fbshipit-source-id: 605a48e39bba6dc14df1af1e76b55ea60f3e69d5

6 years agoDon't use stderr as an identifier name
Christopher Dykes [Fri, 1 Jul 2016 01:09:19 +0000 (18:09 -0700)]
Don't use stderr as an identifier name

Summary: Because it is defined as a macro that calls a function to get the error stream. It is also defined as a macro in musl libc.

Reviewed By: yfeldblum

Differential Revision: D3506283

fbshipit-source-id: 0652288adfe64010798017e46d962fdc18d2ff56

6 years agostop_watch is moved to folly
Misha Shneerson [Fri, 1 Jul 2016 00:22:39 +0000 (17:22 -0700)]
stop_watch is moved to folly

moved stop_watch to folly
defined aliases for backward compact. These alias will be removed in next diff.

Reviewed By: juchem

Differential Revision: D3474035

fbshipit-source-id: 74ee8bb7f2db46434c937eecf121d1cba473178a

6 years agosuppress unused variable warnings
Tianjiao Yin [Thu, 30 Jun 2016 19:21:28 +0000 (12:21 -0700)]
suppress unused variable warnings

Reviewed By: yfeldblum

Differential Revision: D3501266

fbshipit-source-id: 2ac3b6e2785792ccc45f4568ceff7fd05f0262f3

6 years agoMake AutoTimer usable with Closures
Aravind Anbudurai [Thu, 30 Jun 2016 07:48:22 +0000 (00:48 -0700)]
Make AutoTimer usable with Closures

Currently, AutoTimer works only with FunctionObjects that are default constructible because it constructs Logger each time it needs to log. This diff makes AutoTimer work with closures too. This will help in making AutoTimer more flexible because the user can capture necessary dependencies in the lambda.

This diff also cleans up the constructors on AutoTimer by making it take an
std::string&& instead of Args... that is passed into folly::to<..>. Although
this makes the instantiation a bit harder, the simplicity of constructor seems
worth it.

This also refactors the callsites of setMinLogTime to directly pass the
value into the ctor and changes callsites on fbcode

Reviewed By: yfeldblum

Differential Revision: D3487868

fbshipit-source-id: 52fa1099a5e39b791972cc0d3f678d44ea4ba288

6 years agoGive each eventbase a wheeltimer
Scott Michelson [Thu, 30 Jun 2016 00:57:13 +0000 (17:57 -0700)]
Give each eventbase a wheeltimer

This gives each eventbase a wheeltimer. Construction is on demand, so there's no penalty if it isn't used. Why do this? 3 immediate reasons:

1) some clients already do this outside of the interface: diffusion/FBS/browse/master/fbcode/servicerouter/client/common/ThriftDispatcher.h$302,607?view=highlighted
2) inefficient timers can be easily avoided: diffusion/FBS/browse/master/fbcode/thrift/lib/cpp2/async/HeaderClientChannel.h;64fb260ea4bd235ba79414a78002fd68cf0453a8$319
3) D2379210 indicates we can do a better job with this than cob timeout

Reviewed By: andriigrynenko, djwatson

Differential Revision: D3460792

fbshipit-source-id: a7bb6fdd90ca95b6aef8af952d7a66dd0dc260c1

6 years agogcc-4.8 is not decaying types correctly in lambda init captures. Help it out. Fixes...
Eric Niebler [Wed, 29 Jun 2016 22:43:31 +0000 (15:43 -0700)]
gcc-4.8 is not decaying types correctly in lambda init captures. Help it out. Fixes open source build.

Summary: Trivial change gets folly::ThreadLocal building again with gcc-4.8, needed by the Open Source build.

Reviewed By: chadparry, yfeldblum

Differential Revision: D3498657

fbshipit-source-id: cf36f2bef7f1d03d133d16bfd063f7a2ce681822

6 years agoFix FiberManager.RequestContext unit test
Mirek Klimos [Wed, 29 Jun 2016 22:42:34 +0000 (15:42 -0700)]
Fix FiberManager.RequestContext unit test

Summary: with the added blocks, pointer to RequestContext needs to be captured by value, not reference

Differential Revision: D3499921

fbshipit-source-id: 76ff22869228fbdd7ef1651cd2814550f6abc301

6 years agofix the open source ssl_test target
Eric Niebler [Wed, 29 Jun 2016 22:40:56 +0000 (15:40 -0700)]
fix the open source ssl_test target

Summary: 'make check' is failing since the path to OpenSSLHashTest.cpp is wrong and because ssl_test is not linked to libcrypto.

Reviewed By: mhx

Differential Revision: D3498207

fbshipit-source-id: 0f443d1f1b76c537d211dc148df0cd3fdfb8eead

6 years agoReplace RequestContext::create with RequestContextScopeGuard in tests
Mirek Klimos [Wed, 29 Jun 2016 00:58:52 +0000 (17:58 -0700)]
Replace RequestContext::create with RequestContextScopeGuard in tests

Summary: RequestContextScopeGuard should be preferred to RequestContext::create because it makes sure that RequestContext is cleared afterwards - need to create more examples of this in the codebase, migrating unit tests should be safe

Reviewed By: interwq

Differential Revision: D3489969

fbshipit-source-id: 202fec93116db3d435c108fafecad26a4ed9b603

6 years agoAllow unchecked conversion from floating point to bool
Marcus Holland-Moritz [Mon, 27 Jun 2016 23:39:27 +0000 (16:39 -0700)]
Allow unchecked conversion from floating point to bool

In order to be consistent with integral-to-bool conversion, this
change allows conversion from floating point values to bool following
the same rule that is to be consistent with C(++) conventions. Also,
any arithmetic value can be converted to bool without potential for
undefined behaviour, so no extra checks are required.

Differential Revision: D3483760

fbshipit-source-id: 024b58d348ef679079aba4d9d5277acb46aba2a1

6 years agoFolly parseJson doesn't handle minInt properly
Bo You [Mon, 27 Jun 2016 16:17:21 +0000 (09:17 -0700)]
Folly parseJson doesn't handle minInt properly

Right now in ##parseNumber## in ##folly/json.cpp##, when a negative number is provided, both the minus sign and the digits are stored in the variable ##integral##:

This causes problem when the exact min int is provided (-9223372036854775808). Because now ##integral.size()## equals 20 (including the minus sign), which is greater than ##maxIntLen## (which is 19). We need to handle negatives separately to get the correct result.

Reviewed By: yfeldblum

Differential Revision: D3479054

fbshipit-source-id: 15c782962a5f5ee845a2a18f2145c7695ec2d546

6 years agofix typo in documentation
David Lam [Sun, 26 Jun 2016 00:03:42 +0000 (17:03 -0700)]
fix typo in documentation

Summary: #accept2ship

Reviewed By: Orvid

Differential Revision: D3486732

fbshipit-source-id: 45bfe1daa1dbd1e427fcd18e71e6b9eeb6d6b2b7

6 years agofolly: fix clang's -Wundefined-var-template
Eric Niebler [Sat, 25 Jun 2016 18:48:12 +0000 (11:48 -0700)]
folly: fix clang's -Wundefined-var-template

[temp] (14)/6:

> A function template, member function of a class template, variable template, or static data member of a class template shall be defined in every translation unit in which it is implicitly instantiated (14.7.1) unless the corresponding specialization is explicitly instantiated (14.7.2) in some translation unit; no diagnostic is required.

`-Wundefined-var-template` warns on any implicit instantiations that are needed but could not be performed because the definition is not available. In particular, for valid code, this warns on templates/temploids which have their definition and all relevant explicit instantiations tucked away in some source file (but for which no explicit instantiation declarations are provided in the relevant header file) - used a few times in folly. This seems a bad style, the static data member template should either be defined in the header file or should be explicitly instantiated in each .cpp file.

Reviewed By: igorsugak

Differential Revision: D3447679

fbshipit-source-id: 22c90c19e2c7a9b6d772058f2c7e350b890b6c0a

6 years agofix bug for negative shift value
Haocheng Zhang [Fri, 24 Jun 2016 19:34:59 +0000 (12:34 -0700)]
fix bug for negative shift value

Reviewed By: luciang

Differential Revision: D3407128

fbshipit-source-id: 2c00387d6e068f9e052f539198ae2f985d265c74

6 years agoFix uses of std::nextafter on Android
Marcus Holland-Moritz [Fri, 24 Jun 2016 18:23:42 +0000 (11:23 -0700)]
Fix uses of std::nextafter on Android

On Android, std::nextafter isn't implemented. However, the C functions and
compiler builtins are still provided.

This change adds a portability abstraction as folly::nextafter.

Reviewed By: mzlee, yfeldblum

Differential Revision: D3478081

fbshipit-source-id: 54fec1ca8bdec24ba45d51e07020259fdbae61b4

6 years agoIOBuf: add a method to signal the underlying buffer as externally shared
Huapeng Zhou [Fri, 24 Jun 2016 17:45:37 +0000 (10:45 -0700)]
IOBuf: add a method to signal the underlying buffer as externally shared

There are use cases where 1). the underlying buffer is externally managed (e.g. by a slab allocator) and 2). we need to do bookkeeping when the wrapped IOBuf gets destroyed (e.g. reference counting). This diff adds a another method to mark the underlying buffer as shared with the external memory management mechanism.

The `takeOwnership` doesn't meet the criteria since it assumes the ownership of the buffer, while in this case we need to signal it as externally managed so that hopefully callers won't try to modify the underlying buffer.

Reviewed By: simpkins

Differential Revision: D2662954

fbshipit-source-id: e908c3ebeeefe9a5d332c75070f377fb1dad5acb

6 years agostd::aligned_storage<>::type is not a dependent type
Christopher Dykes [Fri, 24 Jun 2016 17:42:45 +0000 (10:42 -0700)]
std::aligned_storage<>::type is not a dependent type

Summary: Which causes MSVC to get grumpy when you tell it that it is.

Reviewed By: yfeldblum

Differential Revision: D3479016

fbshipit-source-id: e674b210aaa5a644c5ed884a7077a5cf33b05196

6 years agoUse FOLLY_TLS rather than __thread
Christopher Dykes [Fri, 24 Jun 2016 17:42:21 +0000 (10:42 -0700)]
Use FOLLY_TLS rather than __thread

Summary: We define `FOLLY_TLS` for a reason, so use it.

Reviewed By: yfeldblum

Differential Revision: D3479880

fbshipit-source-id: 2aa11c2900cdb012cf96d4f084fe81a0428f53d3

6 years agoDear Elias Fano Bit Vector: You do not require GCC
Christopher Dykes [Fri, 24 Jun 2016 17:40:14 +0000 (10:40 -0700)]
Dear Elias Fano Bit Vector: You do not require GCC

Summary: There is nothing directly in these that requires GCC.

Reviewed By: pixelb

Differential Revision: D3479392

fbshipit-source-id: 6b5ae0115cad666f29db6c7b123b9d1a1013e3b0

6 years agoFix code for anything-to-string space estimation
Marcus Holland-Moritz [Fri, 24 Jun 2016 02:38:40 +0000 (19:38 -0700)]
Fix code for anything-to-string space estimation

When looking at the benchmark for 64-bit integer-to-string conversion,
I noticed something strange:

  folly/test/ConvBenchmark.cpp              time/iter
  u64ToStringFollyMeasure(12)                 26.59ns
  u64ToStringFollyMeasure(13)                 26.89ns
  u64ToStringFollyMeasure(14)                 28.26ns  <---
  u64ToStringFollyMeasure(15)                 52.06ns  <---
  u64ToStringFollyMeasure(16)                 54.44ns
  u64ToStringFollyMeasure(17)                 55.96ns

There was a sudden, unexpected jump in latency going from 14 digits to
15 digits. Profiling showed that this was due to malloc() and free()
calls for the 15 digit benchmark that didn't occur when converting
only 14 digit numbers. This was surprising, knowing that fbstrings
should be able to store up to 23 digits inline.

Even though the code to estimate the number of digits is correct, the
code to estimate the space needed within the string was off by 9 bytes.

The reason for that is that reserveInTarget() and reserveInTargetDelim()
are called with the target string as the last parameter. However, the
parameter processing in estimateSpaceToReserve() didn't consider this,
and so reserved space for the size of the pointer + 1, which explains
the wrap at 15 digits.

The fix is to make all overloads of estimateSpaceToReserve() consider
the target parameter correctly.

The benchmark shows there's no jump in latency with the fix:

  folly/test/ConvBenchmark.cpp             time/iter   time/iter
  preallocateTestNoFloat                    590.12ns    599.20ns
  preallocateTestFloat                      580.25ns    581.72ns
  preallocateTestInt8                       116.27ns    119.08ns
  preallocateTestInt16                      130.03ns    131.89ns
  preallocateTestInt32                      156.24ns    154.91ns
  preallocateTestInt64                      210.66ns    207.04ns
  preallocateTestInt128                       4.56us      4.54us
  preallocateTestNoFloatWithInt128            4.27us      4.26us
  u64ToStringFollyMeasure(1)                 15.49ns     15.19ns
  u64ToStringFollyMeasure(2)                 16.10ns     15.80ns
  u64ToStringFollyMeasure(3)                 17.32ns     17.01ns
  u64ToStringFollyMeasure(4)                 18.53ns     18.23ns
  u64ToStringFollyMeasure(5)                 18.84ns     18.53ns
  u64ToStringFollyMeasure(6)                 20.19ns     19.83ns
  u64ToStringFollyMeasure(7)                 21.42ns     21.11ns
  u64ToStringFollyMeasure(8)                 22.48ns     22.33ns
  u64ToStringFollyMeasure(9)                 22.94ns     22.63ns
  u64ToStringFollyMeasure(10)                24.12ns     23.82ns
  u64ToStringFollyMeasure(11)                25.53ns     25.25ns
  u64ToStringFollyMeasure(12)                26.59ns     26.36ns
  u64ToStringFollyMeasure(13)                26.89ns     26.67ns
  u64ToStringFollyMeasure(14)                28.26ns     28.01ns
  u64ToStringFollyMeasure(15)                52.06ns     29.44ns
  u64ToStringFollyMeasure(16)                54.44ns     31.05ns
  u64ToStringFollyMeasure(17)                55.96ns     34.64ns
  u64ToStringFollyMeasure(18)                57.69ns     35.10ns
  u64ToStringFollyMeasure(19)                59.45ns     36.46ns
  u64ToStringFollyMeasure(20)                60.91ns     38.17ns

Reviewed By: meyering

Differential Revision: D3455825

fbshipit-source-id: 0146cbfc0105f0d709b64bcf1ed297c4e27d1129

6 years agoSimplify unsigned-to-string conversion code and improve performance
Marcus Holland-Moritz [Fri, 24 Jun 2016 02:36:52 +0000 (19:36 -0700)]
Simplify unsigned-to-string conversion code and improve performance

This seemingly trivial change has a surprisingly significant performance
impact. It changes the call to append() on a string-like object from using
an iterator pair to using a char* / length pair for 64-bit unsigned-to-string
conversion. This brings it in line with code for signed-to-string conversion,
which had already been using this overload of append.

  folly/test/ConvBenchmark.cpp            time/iter   time/iter
  preallocateTestNoFloat                   640.47ns    590.12ns
  preallocateTestFloat                     569.32ns    580.25ns
  preallocateTestInt8                      133.65ns    116.27ns
  preallocateTestInt16                     147.05ns    130.03ns
  preallocateTestInt32                     169.98ns    156.24ns
  preallocateTestInt64                     228.31ns    210.66ns
  preallocateTestInt128                      4.53us      4.56us
  preallocateTestNoFloatWithInt128           4.32us      4.27us
  u64ToStringFollyMeasure(1)                17.32ns     15.49ns
  i64ToStringFollyMeasurePos(1)             15.80ns     15.80ns
  i64ToStringFollyMeasureNeg(1)             21.91ns     21.91ns
  u64ToStringFollyMeasure(2)                18.23ns     16.10ns
  i64ToStringFollyMeasurePos(2)             16.71ns     16.71ns
  i64ToStringFollyMeasureNeg(2)             21.90ns     21.90ns
  u64ToStringFollyMeasure(3)                19.44ns     17.32ns
  i64ToStringFollyMeasurePos(3)             17.01ns     17.01ns
  i64ToStringFollyMeasureNeg(3)             21.96ns     21.96ns
  u64ToStringFollyMeasure(4)                20.35ns     18.53ns
  i64ToStringFollyMeasurePos(4)             18.23ns     18.23ns
  i64ToStringFollyMeasureNeg(4)             22.19ns     22.22ns
  u64ToStringFollyMeasure(5)                20.66ns     18.84ns
  i64ToStringFollyMeasurePos(5)             19.47ns     19.54ns
  i64ToStringFollyMeasureNeg(5)             22.66ns     22.68ns
  u64ToStringFollyMeasure(6)                21.89ns     20.19ns
  i64ToStringFollyMeasurePos(6)             20.74ns     20.72ns
  i64ToStringFollyMeasureNeg(6)             23.81ns     23.83ns
  u64ToStringFollyMeasure(7)                23.09ns     21.42ns
  i64ToStringFollyMeasurePos(7)             21.11ns     21.12ns
  i64ToStringFollyMeasureNeg(7)             24.92ns     24.92ns
  u64ToStringFollyMeasure(8)                24.00ns     22.48ns
  i64ToStringFollyMeasurePos(8)             22.18ns     22.18ns
  i64ToStringFollyMeasureNeg(8)             26.20ns     26.20ns
  u64ToStringFollyMeasure(9)                24.31ns     22.94ns
  i64ToStringFollyMeasurePos(9)             23.39ns     23.53ns
  i64ToStringFollyMeasureNeg(9)             26.44ns     26.44ns
  u64ToStringFollyMeasure(10)               25.52ns     24.12ns
  i64ToStringFollyMeasurePos(10)            24.69ns     24.69ns
  i64ToStringFollyMeasureNeg(10)            27.77ns     27.80ns
  u64ToStringFollyMeasure(11)               26.74ns     25.53ns
  i64ToStringFollyMeasurePos(11)            25.07ns     25.07ns
  i64ToStringFollyMeasureNeg(11)            28.87ns     28.87ns
  u64ToStringFollyMeasure(12)               28.25ns     26.59ns
  i64ToStringFollyMeasurePos(12)            26.21ns     26.34ns
  i64ToStringFollyMeasureNeg(12)            30.08ns     30.08ns
  u64ToStringFollyMeasure(13)               29.38ns     26.89ns
  i64ToStringFollyMeasurePos(13)            27.60ns     27.65ns
  i64ToStringFollyMeasureNeg(13)            30.62ns     30.69ns
  u64ToStringFollyMeasure(14)               30.91ns     28.26ns
  i64ToStringFollyMeasurePos(14)            28.58ns     28.57ns
  i64ToStringFollyMeasureNeg(14)            55.27ns     55.27ns
  u64ToStringFollyMeasure(15)               54.71ns     52.06ns
  i64ToStringFollyMeasurePos(15)            52.79ns     52.84ns
  i64ToStringFollyMeasureNeg(15)            57.45ns     57.50ns
  u64ToStringFollyMeasure(16)               57.14ns     54.44ns
  i64ToStringFollyMeasurePos(16)            55.26ns     55.29ns
  i64ToStringFollyMeasureNeg(16)            59.18ns     59.19ns
  u64ToStringFollyMeasure(17)               58.89ns     55.96ns
  i64ToStringFollyMeasurePos(17)            57.10ns     57.14ns
  i64ToStringFollyMeasureNeg(17)            60.89ns     60.88ns
  u64ToStringFollyMeasure(18)               60.33ns     57.69ns
  i64ToStringFollyMeasurePos(18)            58.59ns     58.63ns
  i64ToStringFollyMeasureNeg(18)            62.46ns     62.50ns
  u64ToStringFollyMeasure(19)               62.22ns     59.45ns
  i64ToStringFollyMeasurePos(19)            60.23ns     60.25ns
  i64ToStringFollyMeasureNeg(19)            64.21ns     64.20ns
  u64ToStringFollyMeasure(20)               63.79ns     60.91ns

Reviewed By: yfeldblum

Differential Revision: D3455819

fbshipit-source-id: bc57a0e5bd1d1dca22a37c8b7306e05493e6bd5f

6 years agoFix undefined behaviour in 128-bit integer-to-string conversion
Marcus Holland-Moritz [Fri, 24 Jun 2016 02:34:48 +0000 (19:34 -0700)]
Fix undefined behaviour in 128-bit integer-to-string conversion

The code to convert signed 128-bit integer values to strings would trigger
undefined behaviour when trying to convert the most negative possible value,
as exposed by the new test cases.

The fix is to negate the corresponding unsigned value (just like it's already
done for the 64-bit code).

This change doesn't have any performance impact.

Reviewed By: yfeldblum

Differential Revision: D3455817

fbshipit-source-id: 83782992324f443789760a0e61cd9b889faaf317

6 years agoAdd more benchmarks for integer-to-string conversion
Marcus Holland-Moritz [Fri, 24 Jun 2016 02:04:09 +0000 (19:04 -0700)]
Add more benchmarks for integer-to-string conversion

In preparation for some changes to the integer-to-string conversion
code, this change adds, this adds some more benchmarks, and attempts
to update the existing ones to be less prone to the optimizations
where the compiler already knows about the constant values being
passed in.

There also were a couple of flaws in the existing benchmarks, where
instead of computing the value to be converted from a start value
and the loop counter, it rather added the (constant) total iteration
count to the value, ending up with a constant. But, worse than just
using a constant, the code that was trying to evaluate the cost of
converting a single-digit would generally end up computing the cost
of a five-digit number, which resulted in the benchmarks showing
identical figures regardless of the number of digits for small digit

The change also adds benchmarks for positive/negative signed integers
and 128-bit integers.

Reviewed By: yfeldblum

Differential Revision: D3455815

fbshipit-source-id: a20821c7d460bc05453655d0c848a0c9a47520fd

6 years agoFix conversion from bool to floating point value
Marcus Holland-Moritz [Fri, 24 Jun 2016 00:22:33 +0000 (17:22 -0700)]
Fix conversion from bool to floating point value

Due to the definition of how floating point values convert to boolean,
the check for undefined behaviour wouldn't work correctly. The result
of (1 - 0.9999999999999999) would yield 0 when converted to an integer,
but yields true (1) when converted to a boolean.

As all floating point values can thus be converted to boolean without
triggering undefined behaviour, this change overloads checkConversion()

Reviewed By: yfeldblum

Differential Revision: D3477368

fbshipit-source-id: 5b2aeb6194629cf3a6195529aac2362c0d35799c

6 years agoClean up Conv.cpp / Conv.h
Marcus Holland-Moritz [Thu, 23 Jun 2016 03:28:37 +0000 (20:28 -0700)]
Clean up Conv.cpp / Conv.h

A bit of tidying up:

- Remove unused digit1 / digit2 arrays
- Remove unused MaxString<bool>
- Move MaxString<> entirely to Conv.cpp, as it's not used in Conv.h
- Extend anonymous namespace in Conv.cpp
- Sort headers in Conv.h

Reviewed By: yfeldblum

Differential Revision: D3433767

fbshipit-source-id: 224a68f22505c0f2014ac376154d004eca1658a9

6 years agoFix undefined behaviour in float<->int conversion
Marcus Holland-Moritz [Thu, 23 Jun 2016 03:28:36 +0000 (20:28 -0700)]
Fix undefined behaviour in float<->int conversion

This change fixes a case of undefined behaviour when converting between
floating point and integral values using folly::to<>. Undefined behaviour
is triggered when a floating point value is cast into an integral value
that cannot represent the source value. This happens in both cases,
float-to-int and int-to-float conversion, with folly::to<> due to the
check for loss of precision.

The new test cases expose the undefined behaviour.

The fix is a series of extra checks, the majority of which will only
kick in if the value to be converted is close to the boundary of the
range of the target type. These checks ensure that the conversion will
only be performed if the source value is within the range representable
by the target type.

The extra checks /will/ make the code slower. However, a later change
in this series, which refactors the implementation of folly::to<>, will
restore some of the performance.

Reviewed By: yfeldblum

Differential Revision: D3433757

fbshipit-source-id: 43495d18f831206ef48f74332663263d789a4f8a

6 years agoAdded missing m4 file ax_boost_chrono
Bruno Goncalves [Wed, 22 Jun 2016 20:25:33 +0000 (13:25 -0700)]
Added missing m4 file ax_boost_chrono

To avoid error while running ./configure command:
 ./configure: line 18976: AX_BOOST_CHRONO: command not found

Besides in my Fedora 23 the following error ocurred when not linked with -lboost_chrono running 'make check':
/usr/bin/ld: SynchronizedTest.o: undefined reference to symbol 'boost::chrono::steady_clock::now()''
/usr/lib64/ error adding symbols: DSO missing from command line

Differential Revision: D3457939

Pulled By: elliottneilclark

fbshipit-source-id: ec7a8d30d4812f197e2813e611cde0e33eab680a

6 years agoAdd more benchmarks for various conversions
Marcus Holland-Moritz [Wed, 22 Jun 2016 00:26:01 +0000 (17:26 -0700)]
Add more benchmarks for various conversions

This adds a couple of new benchmarks that will be used as a basis to
check the performance of a series of upcoming changes to folly::to<>.

It exercises both successful and unsuccessful conversion paths for
string-to-anything, int-to-int, int-to-float, float-to-int, and pair-
of-pointers-to-int conversions.

The following table only shows the newly added benchmarks:

  folly/test/ConvBenchmark.cpp                time/iter  iters/s
  stringToBoolNumClassic                        12.76ns   78.37M
  stringToBoolNumClassicError                    3.19us  313.37K
  stringToBoolStrClassic                        17.92ns   55.79M
  stringToBoolStrClassicError                    3.21us  311.73K
  stringToFloatNumClassic                       32.96ns   30.34M
  stringToFloatNumClassicError                   2.73us  366.49K
  stringToFloatStrClassic                       37.37ns   26.76M
  stringToFloatStrClassicError                   2.87us  348.81K
  stringToDoubleNumClassic                      31.30ns   31.95M
  stringToDoubleNumClassicError                  2.69us  371.26K
  stringToDoubleStrClassic                      37.67ns   26.54M
  stringToDoubleStrClassicError                  2.87us  348.97K
  stringToCharSignedClassic                     16.71ns   59.85M
  stringToCharSignedClassicError                 3.87us  258.50K
  stringToCharUnsignedClassic                   15.49ns   64.54M
  stringToCharUnsignedClassicError               2.73us  366.88K
  stringToIntSignedClassic                      21.26ns   47.03M
  stringToIntSignedClassicError                  3.94us  253.82K
  stringToIntUnsignedClassic                    17.93ns   55.79M
  stringToIntUnsignedClassicError                2.72us  367.93K
  stringToLongLongSignedClassic                 34.63ns   28.88M
  stringToLongLongSignedClassicError             3.94us  253.52K
  stringToLongLongUnsignedClassic               51.04ns   19.59M
  stringToLongLongUnsignedClassicError           2.73us  366.58K
  ptrPairToCharSignedClassic                     5.16ns  193.62M
  ptrPairToCharSignedClassicError                3.56us  280.99K
  ptrPairToCharUnsignedClassic                   2.43ns  411.44M
  ptrPairToCharUnsignedClassicError              2.63us  380.42K
  ptrPairToIntSignedClassic                      6.99ns  143.09M
  ptrPairToIntSignedClassicError                 4.08us  245.27K
  ptrPairToIntUnsignedClassic                    4.25ns  235.09M
  ptrPairToIntUnsignedClassicError               2.70us  370.55K
  ptrPairToLongLongSignedClassic                12.16ns   82.27M
  ptrPairToLongLongSignedClassicError            4.06us  246.17K
  ptrPairToLongLongUnsignedClassic              29.13ns   34.33M
  ptrPairToLongLongUnsignedClassicError          2.71us  369.33K
  intToCharSignedClassic                       405.02ps    2.47G
  intToCharSignedClassicError                    2.10us  475.11K
  intToCharUnsignedClassic                     303.79ps    3.29G
  intToCharUnsignedClassicError                  2.10us  475.18K
  intToIntSignedClassic                        405.02ps    2.47G
  intToIntSignedClassicError                     1.99us  501.60K
  intToIntUnsignedClassic                      405.03ps    2.47G
  intToIntUnsignedClassicError                   2.09us  478.47K
  intToFloatClassic                            545.11ps    1.83G
  intToFloatClassicError                         1.67us  599.38K
  floatToFloatClassic                          759.47ps    1.32G
  floatToFloatClassicError                       6.45us  154.98K
  floatToIntClassic                            637.82ps    1.57G
  floatToIntClassicError                         1.92us  520.16K

Reviewed By: yfeldblum

Differential Revision: D3433745

fbshipit-source-id: 6ab1ede32c07e7fc29b982e8705ecc0138fa6384

6 years agofolly:: singleton: ubsan: fix calling overriden method from ctor
Lucian Grijincu [Tue, 21 Jun 2016 20:40:46 +0000 (13:40 -0700)]
folly:: singleton: ubsan: fix calling overriden method from ctor

Ubsan complains when overriden method is called from ctor:
0x000000b04d40: note: object is of type 'folly::detail::SingletonHolder<XYZ>' 00 00 00 00  08 50 c3 8d da 7f 00 00  e8 4f c3 8d da 7f 00 00  18 0d 4c b4 da 7f 00 00  a0 16 90 00
              vptr for 'folly::detail::SingletonHolder<XYZ>'

called from `folly::SingletonVault::registerSingleton(folly::detail::SingletonHolderBase*)`

Reviewed By: ot

Differential Revision: D3462037

fbshipit-source-id: 6df283dd53df42d5d318990f60aba370ceed6395

6 years agoAdjust the way Future<Unit>'s constructor is defined
Christopher Dykes [Mon, 20 Jun 2016 18:29:55 +0000 (11:29 -0700)]
Adjust the way Future<Unit>'s constructor is defined

Summary: This is needed to work around a limitation in MSVC's SFINAE support.

Reviewed By: yfeldblum

Differential Revision: D3271292

fbshipit-source-id: 88052beaa97a297c6eb3eb5047c8fed48c8155af

6 years agoAdd very basic compatibility with folly locks for synchronized
Caren Thomas [Fri, 17 Jun 2016 18:24:54 +0000 (11:24 -0700)]
Add very basic compatibility with folly locks for synchronized

Summary: Add folly locks to the HasLockUnlock struct so that they can be used inside Synchronized. acquireReadWrite() and releaseReadWrite() functions are added to each lock class so that their .lock and .unlock methods are accessible by Synchronized. These changes allow an extremely basic level of compatibility for the purpose of running benchmarks and so compatibility with dual_locking, etc. have not been tested.

Reviewed By: simpkins

Differential Revision: D3434621

fbshipit-source-id: d55cffbb1eccaf23645384b9a41f85c5df593ffe

6 years agoWrappers for some of OpenSSL's crypto hash functions
Yedidya Feldblum [Fri, 17 Jun 2016 01:30:25 +0000 (18:30 -0700)]
Wrappers for some of OpenSSL's crypto hash functions

[Folly] Wrappers for some of OpenSSL's crypto hash functions.

Wraps some of the OpenSSL crypto hash functions with variants that take `ByteRange` for input and `MutableByteRange` for output, and also variants that take `const IOBuf&` for input as well.

These are a bit nicer to use than passing pointers and lengths separately.

Reviewed By: ivmaykov

Differential Revision: D3434562

fbshipit-source-id: 3688ef11680a029b7664ac417a7781e70f9c6926

6 years agoFix infinite recursion in sorted_vector_{set|map}::insert(const value_type&)
Christopher Dykes [Fri, 17 Jun 2016 01:12:47 +0000 (18:12 -0700)]
Fix infinite recursion in sorted_vector_{set|map}::insert(const value_type&)

We were calling ourself, which MSVC correctly identified:
warning C4717: 'folly::sorted_vector_set<int,`anonymous namespace'::less_invert<int>,std::allocator<int>,void>::insert': recursive on all control paths, function will cause runtime stack overflow

Just add an explicit `std::move` in to solve the problem.

Reviewed By: yfeldblum

Differential Revision: D3447922

fbshipit-source-id: 803f79510b3dbfeea32a9629238448f69f5b78dc

6 years agoReverted commit D3270439
Jinlong Zhou [Thu, 16 Jun 2016 20:26:54 +0000 (13:26 -0700)]
Reverted commit D3270439

[temp] (14)/6:
> A function template, member function of a class template, variable template, or static data member of a class template shall be defined in every translation unit in which it is implicitly instantiated (14.7.1) unless the corresponding specialization is explicitly instantiated (14.7.2) in some translation unit; no diagnostic is required.

`-Wundefined-var-template` warns on any implicit instantiations that are needed but could not be performed because the definition is not available. In particular, for valid code, this warns on templates/temploids which have their definition and all relevant explicit instantiations tucked away in some source file (but for which no explicit instantiation declarations are provided in the relevant header file) - used a few times in folly. This seems a bad style, the static data member template should either be defined in the header file or should be explicitly instantiated in each .cpp file.

Reviewed By: igorsugak

Differential Revision: D3270439

fbshipit-source-id: e8cdb0452c2f6240a348b93cdbf9975813f27bfe

6 years agoUse the standard intrinsics for crc32c
Christopher Dykes [Thu, 16 Jun 2016 19:42:33 +0000 (12:42 -0700)]
Use the standard intrinsics for crc32c

Summary: This mass of conditions is completely pointless, because GCC has supported the standard intrinsics since at least 4.4.7, which is as far back as godbolt lets me test.

Reviewed By: yfeldblum

Differential Revision: D3373640

fbshipit-source-id: 619e971034db9249a9b312d18870bc7e4d579d50

6 years agofolly: fix clang's -Wundefined-var-template
Eric Niebler [Thu, 16 Jun 2016 17:08:54 +0000 (10:08 -0700)]
folly: fix clang's -Wundefined-var-template

[temp] (14)/6:
> A function template, member function of a class template, variable template, or static data member of a class template shall be defined in every translation unit in which it is implicitly instantiated (14.7.1) unless the corresponding specialization is explicitly instantiated (14.7.2) in some translation unit; no diagnostic is required.

`-Wundefined-var-template` warns on any implicit instantiations that are needed but could not be performed because the definition is not available. In particular, for valid code, this warns on templates/temploids which have their definition and all relevant explicit instantiations tucked away in some source file (but for which no explicit instantiation declarations are provided in the relevant header file) - used a few times in folly. This seems a bad style, the static data member template should either be defined in the header file or should be explicitly instantiated in each .cpp file.

Reviewed By: igorsugak

Differential Revision: D3270439

fbshipit-source-id: bf305fde3af575a265d65a0ae0bf95db5597587f

6 years agoAdded limited list of supported ciphers
Blake Lawson [Thu, 16 Jun 2016 01:21:44 +0000 (18:21 -0700)]
Added limited list of supported ciphers

Summary: Added method to enable server support for a specific elliptic curve encryption algorithm.

Reviewed By: siyengar

Differential Revision: D3432860

fbshipit-source-id: 078531eead48ea156a68a109f8a62dc4907ac1ec

6 years agofix bug for nullptr in qfind
Haocheng Zhang [Wed, 15 Jun 2016 03:25:09 +0000 (20:25 -0700)]
fix bug for nullptr in qfind

Summary: Fix bug for passing null pointer to memchr function, which requires the first argument to never be null.

Reviewed By: luciang

Differential Revision: D3432130

fbshipit-source-id: 419924dd214d9f641d3d46335dae6abbe44ca751

6 years agoAdd constructor for MultiLevelTimeSeries class that uses initializer_list and add...
Caren Thomas [Wed, 15 Jun 2016 00:52:36 +0000 (17:52 -0700)]
Add constructor for MultiLevelTimeSeries class that uses initializer_list and add stat methods that uses duration as a parameter.

Summary: Introduce a constructor that takes in an initializer list of 'TimeType' objects for the durations. New methods for sum/avg/rate/count/countrate are created with a 'TimeType' parameter - this makes it possible to call these methods using the duration that specifies the level. Previously, these methods could only be called using the index of the level in the levels_ vector. These methods first do a linear scan through levels_ using the method getLevelsByDuration to find the corresponding index, and then perform the function they specify on the level.

Differential Revision: D3414343

fbshipit-source-id: 8e1fcc16fd013d0b8b855a1eebbeff417e945b07

6 years agoAdd conv_benchmark target to
Marcus Holland-Moritz [Tue, 14 Jun 2016 23:47:40 +0000 (16:47 -0700)]
Add conv_benchmark target to

Summary: It's useful to be able to build & run the benchmark.

Differential Revision: D3433731

fbshipit-source-id: c37bd5be3da0f89d4792747857d2e7548aea08ba

6 years agoReverted commit D3427621
Michael Lee [Tue, 14 Jun 2016 00:50:11 +0000 (17:50 -0700)]
Reverted commit D3427621

Summary: The iOS sdk adds `clock_gettime` support.

Reviewed By: clementgenzmer

Differential Revision: D3427621

fbshipit-source-id: 534276ba1e0ade185e3af0665f419f3c51d3f980

6 years agoEventBase keepAlive counter is not atomic
Joseph Griego [Tue, 14 Jun 2016 00:49:38 +0000 (17:49 -0700)]
EventBase keepAlive counter is not atomic

Summary: Since loopKeepAlive() is always used from the EventBase thread, there's no need for the overhead of an shared_ptr (and therefore, an atomic ref counter); we can get away without thread safety. This also allows us to discard the (sometimes incorrect) optimization of not returning a handle when it appears the loop will continue running anyways

Reviewed By: andriigrynenko

Differential Revision: D3375503

fbshipit-source-id: 474e4fcf992bdc4fcca9370d3c57bdcc4e042386

6 years agoTime.h portability for iOS 10.
Michael Lee [Tue, 14 Jun 2016 00:05:24 +0000 (17:05 -0700)]
Time.h portability for iOS 10.

Summary: The iOS sdk adds `clock_gettime` support.

Reviewed By: clementgenzmer

Differential Revision: D3427621

fbshipit-source-id: fcd3022c5ea05ceb8e289fbeb1ae845155d2dea9

6 years agoDCHECK on reentrant invocations of loop()
Alexey Spiridonov [Sat, 11 Jun 2016 02:12:36 +0000 (19:12 -0700)]
DCHECK on reentrant invocations of loop()

I had a crash bug where an `EventBase` handler called a function, which tried to use the thread's EventBase as if it were its own:

auto evb = folly::EventBaseManager::get()->getEventBase();
// schedule work on evb, which calls evb->terminateLoopSoon() on completion

This ended up invoking the `event_base_loop()` reentrantly, and corrupting the heap in a hard-to-debug way.

Reviewed By: djwatson

Differential Revision: D3408155

fbshipit-source-id: b8855aa3b390fa33e032ab295d386122d2cb872a

6 years agoMake Fibers library conditional on working Boost.Context fcontext_t
Ben Hamilton [Fri, 10 Jun 2016 23:01:34 +0000 (16:01 -0700)]
Make Fibers library conditional on working Boost.Context fcontext_t

Boost 1.61 removes the `boost::context::fcontext_t` type
which Folly Fibers depends on.

This makes the Fibers library conditional on a working `fcontext_t`,
so Folly will build (just without Fibers) if it's not present.

Depends On D3419638


Reviewed By: Orvid

Differential Revision: D3420097

fbshipit-source-id: 876f8f76a2d0dda4ce5085c27875ab6aaa7b86c0

6 years agoFix folly::fibers on OSX with boost 1.60
Andrii Grynenko [Fri, 10 Jun 2016 22:25:44 +0000 (15:25 -0700)]
Fix folly::fibers on OSX with boost 1.60

Summary: We only need fcontext.hpp, so let's include it directly. all.hpp includes other headers, which use thread-locals (doesn't work with our OSX build).

Reviewed By: igorsugak, bhamiltoncx

Differential Revision: D3419638

fbshipit-source-id: b4fa1bd14454bcd75eaece52c398ac6510273773

6 years agoAdded support for std::mutex in folly Deterministic Schedule
Maged Michael [Fri, 10 Jun 2016 15:53:32 +0000 (08:53 -0700)]
Added support for std::mutex in folly Deterministic Schedule

Added the class `DeterministicMutex`, a wrapper for `std::mutex`, in `folly/test/DeterministicSchedule.h`. Added a test to `folly/test/DeterministicScheduleTest.cpp` to test the correct behavior of `DeterministicMutex` functions and that deterministic schedule is able to detect race conditions that involve `DeterministicMutex`.

Note: Bootcamp task

Reviewed By: djwatson

Differential Revision: D3412579

fbshipit-source-id: c12861c4ec1cfeadcef027be4513e8e4cb7e0176

6 years agoGet rid of circular dependency when including ExceptionWrapper.h from Conv.h
Marcus Holland-Moritz [Fri, 10 Jun 2016 06:40:54 +0000 (23:40 -0700)]
Get rid of circular dependency when including ExceptionWrapper.h from Conv.h

This is needed in order to be able to use folly::Try<> with folly::to<> for
non-throwing conversions.

Reviewed By: meyering

Differential Revision: D3411003

fbshipit-source-id: 1f20e7871b9cedda2b35527dac70381579abd708

6 years agoUse intrinsics rather than inline assembly where possible
Christopher Dykes [Thu, 9 Jun 2016 23:01:25 +0000 (16:01 -0700)]
Use intrinsics rather than inline assembly where possible

I would switch these to just use the intrinsic functions, but GCC 4.8 doesn't support them.
MSVC supports the intrinsics, which is the primary reason for the switch.

Reviewed By: philippv

Differential Revision: D3278901

fbshipit-source-id: 60103ac7cf7ddfb529f65f4aadc687dbdaf423a1

6 years agoAllow a timer with pending callbacks to be destroyed
Chad Parry [Thu, 9 Jun 2016 22:07:58 +0000 (15:07 -0700)]
Allow a timer with pending callbacks to be destroyed

This diff is part of a string of changes that is getting `HHWheelTimer` to use standard smart pointers.

D2617966 is being reverted. The `DestructorGuard` that was added for safety is not possible without intrusive reference counting.
That means that the `count_` (of pending callbacks) will still be correct, but there will be nothing to check it against. Because of that, I removed the assertions to make sure that the count of pending callbacks matches the count of active guards. Anyway, there were already ways to defeat that test, such as by creating a `DestructorGuard` from any client code.
As long as the assertions are gone, the `cancelAll` can be moved to the destructor. It only ever got run when `destroy` was called and `count_` was `0`, which means that `~HHWheelTimer` was also going to get called at the same time.

Reviewed By: djwatson

Differential Revision: D3349303

fbshipit-source-id: 433fa6605ee9921833328e2f82bd07b2e17e42c5

6 years agoFix typo in docs/
pravic [Thu, 9 Jun 2016 22:01:51 +0000 (15:01 -0700)]
Fix typo in docs/

Summary: Closes

Reviewed By: yfeldblum

Differential Revision: D3413832

Pulled By: elliottneilclark

fbshipit-source-id: 7af1462c250c8d6b5d6f5dfcb3f3117dff7877c9

6 years agoFix a data race found by TSAN in folly::fibers::Baton
Martin Martin [Thu, 9 Jun 2016 18:53:14 +0000 (11:53 -0700)]
Fix a data race found by TSAN in folly::fibers::Baton

Summary: Fix a data race found by TSAN in folly::fibers::Baton by changing a memory_order_relaxed to memory_order_acquire.  Nathan Bronson says that TSAN is correct and the C++ memory model requires _acquire here.

Reviewed By: andriigrynenko

Differential Revision: D3412519

fbshipit-source-id: bd0043b41d145e689a97fc7ef47aa6e116ea9194

6 years agofix command line parsing
David Callahan [Thu, 9 Jun 2016 01:31:19 +0000 (18:31 -0700)]
fix command line parsing

Summary: parse command line flags to pick up -json flag

Reviewed By: mzlee

Differential Revision: D3405794

fbshipit-source-id: e2d216c74f04c15d7470c70abfc2bd25c2ceda98

6 years agoAllow const mapped types in folly::AtomicHash(Array|Map)
Brett Simmers [Thu, 9 Jun 2016 00:19:20 +0000 (17:19 -0700)]
Allow const mapped types in folly::AtomicHash(Array|Map)

Without this const_cast, it's impossible to insert anything into an
AHA with a const mapped_type, making it effectively useless.

Reviewed By: yfeldblum

Differential Revision: D3405687

fbshipit-source-id: 3ecba19e0e92661c2c537c747b4927176104939f

6 years agomake Range::size() constexpr
Adam Simpkins [Wed, 8 Jun 2016 23:15:18 +0000 (16:15 -0700)]
make Range::size() constexpr

Declare size() to return a constexpr value, so it can be called on constexpr
Range objects.

This unfortunately does drop the existing assert() check, due to a gcc bug:

Reviewed By: lbrandy

Differential Revision: D3394612

fbshipit-source-id: 77ea3b961dc323a39dea6f0e5850f9a311210d09

6 years agoPack PackedSyncPtr
Christopher Dykes [Wed, 8 Jun 2016 19:51:28 +0000 (12:51 -0700)]
Pack PackedSyncPtr

Summary: The comment was right about the packed attribute not liking private members, so pack `PackedSyncPtr` to get GCC to pack structs containing it correctly.

Reviewed By: yfeldblum

Differential Revision: D3402936

fbshipit-source-id: 11d9def132d5dedf04b0e263c379cac339a52fa3

6 years agoadd hexlify() and unhexlify() convenience methods
Adam Simpkins [Wed, 8 Jun 2016 19:49:45 +0000 (12:49 -0700)]
add hexlify() and unhexlify() convenience methods

Add new versions of hexlify() and unhexlify() that directly return a
std::string, similar to the helper functions that already exist for humanify()
and backslashify().

The function signatures for these helpers are different than the humanify() and
backslashify() helpers--these functions always accept StringPiece or ByteRange
arguments.  This allows them to easily accept "const char*" arguments, without
having to convert the arguments to a std::string.  (I think we probably should
fix the humanify() and backslashify() helpers to be similar in a separate

Reviewed By: yfeldblum

Differential Revision: D3403863

fbshipit-source-id: a2df49d5857e1d34caac3d78283dc293f4ef1ab6

6 years agoDisable SIGSEGV signal handler if run in JVM
Andrii Grynenko [Wed, 8 Jun 2016 01:30:18 +0000 (18:30 -0700)]
Disable SIGSEGV signal handler if run in JVM

Reviewed By: ldemailly

Differential Revision: D3402550

fbshipit-source-id: 3de47c569868545c3861dab9a7b244ed8fb1fadf

6 years agoExpose current observer from FiberManager
Adam Radziwonczyk-Syta [Tue, 7 Jun 2016 19:59:48 +0000 (12:59 -0700)]
Expose current observer from FiberManager

Inteded use case is to write tracing code in common components that can adjust its behavior to the current observer. E.g.
  auto* observer = FiberManager::getUnsafe()->getObserver();
  if (auto* specific_observer = dynamic_cast<SpecificObserver*>(observer)) {

Reviewed By: andriigrynenko

Differential Revision: D3392890

fbshipit-source-id: 284b4964bbb17e9a081779b870af68e8f1a81634

6 years agoAdd TFO support to AsyncSSLSocket
Subodh Iyengar [Tue, 7 Jun 2016 14:43:37 +0000 (07:43 -0700)]
Add TFO support to AsyncSSLSocket

This adds TFO support to AsyncSSLSocket which
uses the support for TFO from AsyncSocket.

Because of the way AsyncSSLSocket inherits from
AsyncSocket it is tricky.

The following changes were made:
1. Openssl internally will treat only errors with return
code -1 as READ_REQUIRED or WRITE_REQUIRED errors. So this
diff changes the return value of the errors in the TFO fallback
cases to -1.

2. In case we fallback after SSL_connect() to a normal connect,
we would have to restart the connection process after connect
succeeds. To do this this overrides the connection success callback
and restarts the connection before sending the callback to AsyncSocket
because sometimes callbacks might synchronously call sslConn() in the
normal connect cases.

3. Delegated bioWrite to call sendSocketMessage instead of sendmsg directly.

Reviewed By: djwatson

Differential Revision: D3391735

fbshipit-source-id: 61434f6de4a9c3d03973c9ab9e51eb49e751e5cf

6 years agofolly: define FOLLY_SANITIZE_THREAD convenience macro for TSAN
Kenny Yu [Mon, 6 Jun 2016 23:20:39 +0000 (16:20 -0700)]
folly: define FOLLY_SANITIZE_THREAD convenience macro for TSAN

This defines the macro `FOLLY_SANITIZE_THREAD`, similar to `FOLLY_SANITIZE_ADDRESS`.

Note that gcc *just* landed support for the `__SANITIZE_THREAD__` macro two weeks

Reviewed By: igorsugak

Differential Revision: D3389021

fbshipit-source-id: df6497a7741657c297ee812ed07cbae102b6810d

6 years agoAllow constexpr construction of AtomicStruct under MSVC
Christopher Dykes [Sat, 4 Jun 2016 00:43:42 +0000 (17:43 -0700)]
Allow constexpr construction of AtomicStruct under MSVC

Summary: Attempting to use this under MSVC, as `MemoryIdler::defaultIdleTimeout` does, generated warnings about the symbol being dynamically initialized due to an implementation limation. Solve this by defining a union instead of calling `encode` in the constructor.

Reviewed By: yfeldblum

Differential Revision: D3387916

fbshipit-source-id: b0d628b6d086960e94121b6183a31348fb151aac

6 years agoDeal with a couple of warnings from MSVC
Christopher Dykes [Sat, 4 Jun 2016 00:43:13 +0000 (17:43 -0700)]
Deal with a couple of warnings from MSVC

Summary: MSVC is warning that `client` may be uninitialized, which is possible if the callback doesn't actually set them for some reason. Solve that by explicitly initializing it to `nullptr`. Also deal with the warning about the initialization of `dynamic::array` using braced syntax by not using that syntax.

Reviewed By: yfeldblum

Differential Revision: D3387782

fbshipit-source-id: e4d25ad32e99a73d7d062be9a2f2b5bde5d17396

6 years agoRemove a couple of MSVC portability defines
Christopher Dykes [Sat, 4 Jun 2016 00:42:35 +0000 (17:42 -0700)]
Remove a couple of MSVC portability defines

Summary: The first is both wrong (due to the difference in semantics) and unneeded, as MSVC 2015 supports `snprintf` natively and with the correct semantics. The second is simply never used.

Reviewed By: yfeldblum

Differential Revision: D3387551

fbshipit-source-id: ea666a60ce859a59ad3d3ff961b4d7d642fd86eb

6 years agoAdd a SIGSEGV signal handler which detects stack overflow
Andrii Grynenko [Fri, 3 Jun 2016 22:01:28 +0000 (15:01 -0700)]
Add a SIGSEGV signal handler which detects stack overflow

Summary: GuardPageAllocator now keeps a track of all protected pages. If SIGSEGV occurs, signal handler can check address at fault against protected pages and if it matches - we got a fiber stack overflow.

Reviewed By: yfeldblum

Differential Revision: D3386960

fbshipit-source-id: 775b36ee08fecbbd87da0025f794717c222f5cce

6 years agoAlways override write bio method
Subodh Iyengar [Fri, 3 Jun 2016 19:40:37 +0000 (12:40 -0700)]
Always override write bio method

Always overriding write bio method
allows us to more cleanly implement
features like eor tracking, support
multiple ssl libraries, and also TFO

Reviewed By: anirudhvr

Differential Revision: D3350482

fbshipit-source-id: ddd2333431f9d636d69c8325b2c18d7cc043b848

6 years agoUpdate folly OSS build to use 1y
Elliott Clark [Thu, 2 Jun 2016 22:37:35 +0000 (15:37 -0700)]
Update folly OSS build to use 1y

Summary: use std=c++1y for compiling since we use c+=14 feautures but don't want to require a recent gcc.

Reviewed By: bhamiltoncx

Differential Revision: D3380287

fbshipit-source-id: 8ece6007cf613d307bafe692f1af70f5359df95a