jvm-profiling-tools / honest-profiler

A sampling JVM profiler without the safepoint sample bias
https://github.com/RichardWarburton/honest-profiler/wiki
MIT License
1.25k stars 146 forks source link

Build Fails on macOS with XCode 9.3 #242

Closed tobias-bahls closed 6 years ago

tobias-bahls commented 6 years ago

Trying to build the project on macOS 10.13.4 with the latest XCode 9.3 fails with this error:

Scanning dependencies of target lagent
[  5%] Building CXX object CMakeFiles/lagent.dir/src/main/cpp/agent.cpp.o
In file included from /src/main/cpp/agent.cpp:4:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/string:470:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/string_view:169:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/__string:56:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/algorithm:643:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/memory:2051:9: error:
      cannot initialize a member subobject of type 'map::JobCoordinator::Job **' with an
      rvalue of type 'long'
      : __value_(_VSTD::forward<_Up>(__u)){};
        ^        ~~~~~~~~~~~~~~~~~~~~~~~~
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/memory:2141:9: note:
      in instantiation of function template specialization
      'std::__1::__compressed_pair_elem<map::JobCoordinator::Job **, 0,
      false>::__compressed_pair_elem<long, void>' requested here
      : _Base1(std::forward<_Tp>(__t)), _Base2() {}
        ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/vector:423:7: note:
      in instantiation of function template specialization
      'std::__1::__compressed_pair<map::JobCoordinator::Job **,
      std::__1::allocator<map::JobCoordinator::Job *> >::__compressed_pair<long, true>'
      requested here
      __end_cap_(nullptr)
      ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/vector:473:5: note:
      in instantiation of member function 'std::__1::__vector_base<map::JobCoordinator::Job
      *, std::__1::allocator<map::JobCoordinator::Job *> >::__vector_base' requested here
    vector() _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
    ^
honest-profiler/src/main/cpp/concurrent_map.h:207:2: note: in instantiation of
      member function 'std::__1::vector<map::JobCoordinator::Job *,
      std::__1::allocator<map::JobCoordinator::Job *> >::vector' requested here
        GC() : totalThreads(0), globalEpoch(1), remaining(0) {
        ^
In file included from honest-profiler/src/main/cpp/agent.cpp:4:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/string:470:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/string_view:169:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/__string:56:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/algorithm:643:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/memory:2151:9: error:
      no matching constructor for initialization of
      '__compressed_pair_elem<map::JobCoordinator::Job **, 0>'
      : _Base1(std::forward<_U1>(__t1)), _Base2(std::forward<_U2>(__t2)) {}
        ^      ~~~~~~~~~~~~~~~~~~~~~~~
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/__split_buffer:309:7: note:
      in instantiation of function template specialization
      'std::__1::__compressed_pair<map::JobCoordinator::Job **,
      std::__1::allocator<map::JobCoordinator::Job *> &>::__compressed_pair<long,
      std::__1::allocator<map::JobCoordinator::Job *> &>' requested here
    : __end_cap_(nullptr, __a)
      ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/vector:1567:49: note:
      in instantiation of member function
      'std::__1::__split_buffer<map::JobCoordinator::Job *,
      std::__1::allocator<map::JobCoordinator::Job *> &>::__split_buffer' requested here
    __split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), size(), __a);
                                                ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/vector:1588:9: note:
      in instantiation of function template specialization
      'std::__1::vector<map::JobCoordinator::Job *,
      std::__1::allocator<map::JobCoordinator::Job *>
      >::__push_back_slow_path<map::JobCoordinator::Job *const &>' requested here
        __push_back_slow_path(__x);
        ^
honest-profiler/src/main/cpp/concurrent_map.h:263:17: note: in instantiation
      of member function 'std::__1::vector<map::JobCoordinator::Job *,
      std::__1::allocator<map::JobCoordinator::Job *> >::push_back' requested here
                recentGarbage.push_back(successfulMigration);
                              ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/memory:2037:8: note:
      candidate constructor (the implicit copy constructor) not viable: no known conversion
      from 'long' to 'const std::__1::__compressed_pair_elem<map::JobCoordinator::Job **,
      0, false>' for 1st argument
struct __compressed_pair_elem {
       ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/memory:2037:8: note:
      candidate constructor (the implicit move constructor) not viable: no known conversion
      from 'long' to 'std::__1::__compressed_pair_elem<map::JobCoordinator::Job **, 0,
      false>' for 1st argument
struct __compressed_pair_elem {
       ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/memory:2050:3: note:
      candidate template ignored: substitution failure [with _Up = long, $1 = void]
  __compressed_pair_elem(_Up&& __u)
  ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/memory:2055:3: note:
      candidate constructor template not viable: requires 3 arguments, but 1 was provided
  __compressed_pair_elem(piecewise_construct_t, tuple<_Args...> __args,
  ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/memory:2043:39: note:
      candidate constructor not viable: requires 0 arguments, but 1 was provided
  _LIBCPP_INLINE_VISIBILITY constexpr __compressed_pair_elem() : __value_() {}
                                      ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/memory:2051:9: error:
      cannot initialize a member subobject of type 'map::Migration::Source *' with an
      rvalue of type 'long'
      : __value_(_VSTD::forward<_Up>(__u)){};
        ^        ~~~~~~~~~~~~~~~~~~~~~~~~
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/memory:2141:9: note:
      in instantiation of function template specialization
      'std::__1::__compressed_pair_elem<map::Migration::Source *, 0,
      false>::__compressed_pair_elem<long, void>' requested here
      : _Base1(std::forward<_Tp>(__t)), _Base2() {}
        ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/vector:423:7: note:
      in instantiation of function template specialization
      'std::__1::__compressed_pair<map::Migration::Source *,
      std::__1::allocator<map::Migration::Source> >::__compressed_pair<long, true>'
      requested here
      __end_cap_(nullptr)
      ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/vector:491:14: note:
      in instantiation of member function 'std::__1::__vector_base<map::Migration::Source,
      std::__1::allocator<map::Migration::Source> >::__vector_base' requested here
    explicit vector(size_type __n);
             ^
/src/main/cpp/concurrent_map.h:446:70: note: in instantiation
      of member function 'std::__1::vector<map::Migration::Source,
      std::__1::allocator<map::Migration::Source> >::vector' requested here
  ...map(self), dest(new HashTable(destSize)), nSources(numSources), sources(numSources),

Now, after some research I was able to pinpoint this macro definition as the cause of the error: https://github.com/jvm-profiling-tools/honest-profiler/blob/391256d84d6a9a0adcb5672e68bbc631bf3df893/src/main/cpp/concurrent_map.h#L26-L28

When removing this code, the build succeeds again. Unfortunately, I don't know enough C++ to know if this might break anything else, which is why I opted for creating this issue instead of opening a PR.

ikavalio commented 6 years ago

Hi @tobias-bahls, thanks very much for your research. This macro was added to support gcc-4.4 on linux as far as I know, so can you please try to replace it with:

#if __cplusplus < 201103L
#  define nullptr NULL
#endif

__cplusplus is 1 for gcc < 4.7 and should be at least 201103L after. The same is hopefully true for clang on macOS.

breskeby commented 6 years ago

@ikavalio your snippet solved that issue for me