diff options
-rw-r--r-- | src/mongo/base/backtrace_visibility_test.cpp | 10 | ||||
-rw-r--r-- | src/mongo/base/backtrace_visibility_test.h | 4 | ||||
-rw-r--r-- | src/mongo/bson/bson_validate.cpp | 4 | ||||
-rw-r--r-- | src/mongo/bson/bsonelement.cpp | 5 | ||||
-rw-r--r-- | src/mongo/bson/inline_decls.h | 47 | ||||
-rw-r--r-- | src/mongo/bson/mutable/document.cpp | 3 | ||||
-rw-r--r-- | src/mongo/bson/util/builder.h | 1 | ||||
-rw-r--r-- | src/mongo/db/operation_context.cpp | 1 | ||||
-rw-r--r-- | src/mongo/platform/compiler.h | 7 | ||||
-rw-r--r-- | src/mongo/platform/compiler_gcc.h | 2 | ||||
-rw-r--r-- | src/mongo/platform/compiler_msvc.h | 2 | ||||
-rw-r--r-- | src/mongo/s/chunk_manager_refresh_bm.cpp | 11 | ||||
-rw-r--r-- | src/mongo/stdx/condition_variable_bm.cpp | 1 | ||||
-rw-r--r-- | src/mongo/unittest/unittest.h | 12 | ||||
-rw-r--r-- | src/mongo/util/assert_util.cpp | 50 | ||||
-rw-r--r-- | src/mongo/util/diagnostic_info_test.cpp | 3 | ||||
-rw-r--r-- | src/mongo/util/future.h | 4 | ||||
-rw-r--r-- | src/mongo/util/future_bm.cpp | 7 | ||||
-rw-r--r-- | src/mongo/util/future_test_shared_future.cpp | 2 |
19 files changed, 72 insertions, 104 deletions
diff --git a/src/mongo/base/backtrace_visibility_test.cpp b/src/mongo/base/backtrace_visibility_test.cpp index aa11d676141..1984829e93c 100644 --- a/src/mongo/base/backtrace_visibility_test.cpp +++ b/src/mongo/base/backtrace_visibility_test.cpp @@ -39,8 +39,8 @@ #include <sstream> -// "static" means internal linkage only for functions in global namespace. -NOINLINE_DECL static void static_function(std::string& s) { +// "static" means internal linkage only for functions at namespace scope. +MONGO_COMPILER_NOINLINE static void static_function(std::string& s) { std::ostringstream ostream; mongo::printStackTrace(ostream); s = ostream.str(); @@ -49,14 +49,14 @@ NOINLINE_DECL static void static_function(std::string& s) { } namespace { -NOINLINE_DECL void anonymous_namespace_function(std::string& s) { +MONGO_COMPILER_NOINLINE void anonymous_namespace_function(std::string& s) { static_function(s); // Prevent tail-call optimization. asm volatile(""); // NOLINT } } // namespace -NOINLINE_DECL MONGO_COMPILER_API_HIDDEN_FUNCTION void hidden_function(std::string& s) { +MONGO_COMPILER_NOINLINE MONGO_COMPILER_API_HIDDEN_FUNCTION void hidden_function(std::string& s) { anonymous_namespace_function(s); // Prevent tail-call optimization. asm volatile(""); // NOLINT @@ -65,7 +65,7 @@ NOINLINE_DECL MONGO_COMPILER_API_HIDDEN_FUNCTION void hidden_function(std::strin namespace mongo { namespace unwind_test_detail { -NOINLINE_DECL void normal_function(std::string& s) { +MONGO_COMPILER_NOINLINE void normal_function(std::string& s) { hidden_function(s); // Prevent tail-call optimization. asm volatile(""); // NOLINT diff --git a/src/mongo/base/backtrace_visibility_test.h b/src/mongo/base/backtrace_visibility_test.h index 9d8e248fad8..cb60120af9c 100644 --- a/src/mongo/base/backtrace_visibility_test.h +++ b/src/mongo/base/backtrace_visibility_test.h @@ -32,8 +32,6 @@ * functions appear in backtraces, see unwind_test.cpp. */ -#include "mongo/bson/inline_decls.h" - #include <string> namespace mongo { @@ -41,7 +39,7 @@ namespace mongo { namespace unwind_test_detail { // Store a stack trace in s. -NOINLINE_DECL void normal_function(std::string& s); +void normal_function(std::string& s); } // namespace unwind_test_detail diff --git a/src/mongo/bson/bson_validate.cpp b/src/mongo/bson/bson_validate.cpp index 40edd405c9b..3a7a9bf728e 100644 --- a/src/mongo/bson/bson_validate.cpp +++ b/src/mongo/bson/bson_validate.cpp @@ -48,7 +48,9 @@ namespace { * 'elemName' should be the known, validated field name of the element containing the error, if it * exists. Otherwise, it should be empty. */ -Status NOINLINE_DECL makeError(StringData baseMsg, BSONElement idElem, StringData elemName) { +MONGO_COMPILER_NOINLINE Status makeError(StringData baseMsg, + BSONElement idElem, + StringData elemName) { str::stream msg; msg << baseMsg; diff --git a/src/mongo/bson/bsonelement.cpp b/src/mongo/bson/bsonelement.cpp index 7562b7ca408..c72e61eb888 100644 --- a/src/mongo/bson/bsonelement.cpp +++ b/src/mongo/bson/bsonelement.cpp @@ -697,10 +697,11 @@ BSONElement BSONElement::operator[](StringData field) const { } namespace { -NOINLINE_DECL void msgAssertedBadType [[noreturn]] (int8_t type) { +MONGO_COMPILER_NOINLINE void msgAssertedBadType [[noreturn]] (int8_t type) { msgasserted(10320, str::stream() << "BSONElement: bad type " << (int)type); } } // namespace + int BSONElement::computeSize() const { enum SizeStyle : uint8_t { kFixed, // Total size is a fixed amount + key length. @@ -759,7 +760,7 @@ int BSONElement::computeSize() const { if (MONGO_likely(sizeInfo.style == SizeStyle::kIntPlusFixed)) return sizeInfo.bytes + fieldNameSize() + valuestrsize(); - return [this, type]() NOINLINE_DECL { + return [this, type]() { // Regex is two c-strings back-to-back. invariant(type == BSONType::RegEx); const char* p = value(); diff --git a/src/mongo/bson/inline_decls.h b/src/mongo/bson/inline_decls.h deleted file mode 100644 index 848050bf404..00000000000 --- a/src/mongo/bson/inline_decls.h +++ /dev/null @@ -1,47 +0,0 @@ -/** - * Copyright (C) 2018-present MongoDB, Inc. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the Server Side Public License, version 1, - * as published by MongoDB, Inc. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * Server Side Public License for more details. - * - * You should have received a copy of the Server Side Public License - * along with this program. If not, see - * <http://www.mongodb.com/licensing/server-side-public-license>. - * - * As a special exception, the copyright holders give permission to link the - * code of portions of this program with the OpenSSL library under certain - * conditions as described in each individual source file and distribute - * linked combinations including the program with the OpenSSL library. You - * must comply with the Server Side Public License in all respects for - * all of the code used other than as permitted herein. If you modify file(s) - * with this exception, you may extend this exception to your version of the - * file(s), but you are not obligated to do so. If you do not wish to do so, - * delete this exception statement from your version. If you delete this - * exception statement from all source files in the program, then also delete - * it in the license file. - */ - -#pragma once - -#if defined(__GNUC__) - -#define NOINLINE_DECL __attribute__((noinline)) -#define PACKED_DECL __attribute__((packed)) - -#elif defined(_MSC_VER) - -#define NOINLINE_DECL __declspec(noinline) -#define PACKED_DECL - -#else - -#define NOINLINE_DECL -#define PACKED_DECL - -#endif diff --git a/src/mongo/bson/mutable/document.cpp b/src/mongo/bson/mutable/document.cpp index 443c57cebf1..d042e2a458f 100644 --- a/src/mongo/bson/mutable/document.cpp +++ b/src/mongo/bson/mutable/document.cpp @@ -38,7 +38,6 @@ #include <vector> #include "mongo/base/static_assert.h" -#include "mongo/bson/inline_decls.h" #include "mongo/bson/mutable/damage_vector.h" #include "mongo/util/debug_util.h" @@ -559,7 +558,7 @@ bool canAttach(const Element::RepIdx id, const ElementRep& rep) { // Returns a Status describing why 'canAttach' returned false. This function should not // be inlined since it just makes the callers larger for no real gain. -NOINLINE_DECL Status getAttachmentError(const ElementRep& rep); +MONGO_COMPILER_NOINLINE Status getAttachmentError(const ElementRep& rep); Status getAttachmentError(const ElementRep& rep) { if (rep.sibling.left != Element::kInvalidRepIdx) return Status(ErrorCodes::IllegalOperation, "dangling left sibling"); diff --git a/src/mongo/bson/util/builder.h b/src/mongo/bson/util/builder.h index ce6c9b9779b..a6c821c5b0f 100644 --- a/src/mongo/bson/util/builder.h +++ b/src/mongo/bson/util/builder.h @@ -45,7 +45,6 @@ #include "mongo/base/static_assert.h" #include "mongo/base/string_data.h" #include "mongo/bson/bsontypes.h" -#include "mongo/bson/inline_decls.h" #include "mongo/platform/decimal128.h" #include "mongo/stdx/type_traits.h" #include "mongo/util/allocator.h" diff --git a/src/mongo/db/operation_context.cpp b/src/mongo/db/operation_context.cpp index 4690f4e38a2..46966d2d614 100644 --- a/src/mongo/db/operation_context.cpp +++ b/src/mongo/db/operation_context.cpp @@ -33,7 +33,6 @@ #include "mongo/db/operation_context.h" -#include "mongo/bson/inline_decls.h" #include "mongo/db/client.h" #include "mongo/db/service_context.h" #include "mongo/platform/random.h" diff --git a/src/mongo/platform/compiler.h b/src/mongo/platform/compiler.h index 02e66713329..25bb38678cd 100644 --- a/src/mongo/platform/compiler.h +++ b/src/mongo/platform/compiler.h @@ -146,6 +146,13 @@ * MONGO_COMPILER_NORETURN. In almost all cases MONGO_UNREACHABLE is preferred. * * + * MONGO_COMPILER_NOINLINE + * + * Tells the compiler that it should not attempt to inline a function. This option is not + * guaranteed to eliminate all optimizations, it only is used to prevent a function from being + * inlined. + * + * * MONGO_WARN_UNUSED_RESULT_CLASS * * Tells the compiler that a class defines a type for which checking results is necessary. Types diff --git a/src/mongo/platform/compiler_gcc.h b/src/mongo/platform/compiler_gcc.h index 839ef93e401..9f9ee2eb48b 100644 --- a/src/mongo/platform/compiler_gcc.h +++ b/src/mongo/platform/compiler_gcc.h @@ -95,3 +95,5 @@ #define MONGO_COMPILER_ALWAYS_INLINE [[gnu::always_inline]] #define MONGO_COMPILER_UNREACHABLE __builtin_unreachable() + +#define MONGO_COMPILER_NOINLINE [[gnu::noinline]] diff --git a/src/mongo/platform/compiler_msvc.h b/src/mongo/platform/compiler_msvc.h index ac71c1ddd24..72d21100f1c 100644 --- a/src/mongo/platform/compiler_msvc.h +++ b/src/mongo/platform/compiler_msvc.h @@ -52,6 +52,8 @@ #define MONGO_COMPILER_API_IMPORT __declspec(dllimport) #define MONGO_COMPILER_API_HIDDEN_FUNCTION +#define MONGO_COMPILER_NOINLINE __declspec(noinline) + #define MONGO_WARN_UNUSED_RESULT_CLASS #define MONGO_WARN_UNUSED_RESULT_FUNCTION diff --git a/src/mongo/s/chunk_manager_refresh_bm.cpp b/src/mongo/s/chunk_manager_refresh_bm.cpp index 3e02667abf6..6edc8c7deeb 100644 --- a/src/mongo/s/chunk_manager_refresh_bm.cpp +++ b/src/mongo/s/chunk_manager_refresh_bm.cpp @@ -32,7 +32,6 @@ #include <benchmark/benchmark.h> #include "mongo/base/init.h" -#include "mongo/bson/inline_decls.h" #include "mongo/db/s/collection_metadata.h" #include "mongo/platform/random.h" #include "mongo/s/chunk_manager.h" @@ -86,16 +85,18 @@ ShardId optimalShardSelector(int i, int nShards, int nChunks) { return ShardId(str::stream() << "shard" << shardNum); } -NOINLINE_DECL auto makeChunkManagerWithPessimalBalancedDistribution(int nShards, uint32_t nChunks) { +MONGO_COMPILER_NOINLINE auto makeChunkManagerWithPessimalBalancedDistribution(int nShards, + uint32_t nChunks) { return makeChunkManagerWithShardSelector(nShards, nChunks, pessimalShardSelector); } -NOINLINE_DECL auto makeChunkManagerWithOptimalBalancedDistribution(int nShards, uint32_t nChunks) { +MONGO_COMPILER_NOINLINE auto makeChunkManagerWithOptimalBalancedDistribution(int nShards, + uint32_t nChunks) { return makeChunkManagerWithShardSelector(nShards, nChunks, optimalShardSelector); } -NOINLINE_DECL auto runIncrementalUpdate(const CollectionMetadata& cm, - const std::vector<ChunkType>& newChunks) { +MONGO_COMPILER_NOINLINE auto runIncrementalUpdate(const CollectionMetadata& cm, + const std::vector<ChunkType>& newChunks) { auto rt = cm.getChunkManager()->getRoutingHistory()->makeUpdated(newChunks); return std::make_unique<CollectionMetadata>(std::make_shared<ChunkManager>(rt, boost::none), ShardId("shard0")); diff --git a/src/mongo/stdx/condition_variable_bm.cpp b/src/mongo/stdx/condition_variable_bm.cpp index f306e999dfc..a78e8e29411 100644 --- a/src/mongo/stdx/condition_variable_bm.cpp +++ b/src/mongo/stdx/condition_variable_bm.cpp @@ -31,7 +31,6 @@ #include <benchmark/benchmark.h> -#include "mongo/bson/inline_decls.h" #include "mongo/stdx/condition_variable.h" #include "mongo/stdx/mutex.h" #include "mongo/stdx/thread.h" diff --git a/src/mongo/unittest/unittest.h b/src/mongo/unittest/unittest.h index cbd24e73f05..2d32dbc9cad 100644 --- a/src/mongo/unittest/unittest.h +++ b/src/mongo/unittest/unittest.h @@ -661,12 +661,12 @@ private: } template <typename A, typename B> - NOINLINE_DECL ComparisonAssertion(const char* theFile, - unsigned theLine, - StringData aExpression, - StringData bExpression, - const A& a, - const B& b) { + MONGO_COMPILER_NOINLINE ComparisonAssertion(const char* theFile, + unsigned theLine, + StringData aExpression, + StringData bExpression, + const A& a, + const B& b) { if (comparator(OpTag<op>{})(a, b)) { return; } diff --git a/src/mongo/util/assert_util.cpp b/src/mongo/util/assert_util.cpp index cb9188590b7..6a8ef8b9c69 100644 --- a/src/mongo/util/assert_util.cpp +++ b/src/mongo/util/assert_util.cpp @@ -80,7 +80,7 @@ void DBException::traceIfNeeded(const DBException& e) { } } -NOINLINE_DECL void verifyFailed(const char* expr, const char* file, unsigned line) { +MONGO_COMPILER_NOINLINE void verifyFailed(const char* expr, const char* file, unsigned line) { assertionCount.condrollover(assertionCount.regular.addAndFetch(1)); error() << "Assertion failure " << expr << ' ' << file << ' ' << std::dec << line << std::endl; logContext(); @@ -97,17 +97,19 @@ NOINLINE_DECL void verifyFailed(const char* expr, const char* file, unsigned lin error_details::throwExceptionForStatus(Status(ErrorCodes::UnknownError, temp.str())); } -NOINLINE_DECL void invariantFailed(const char* expr, const char* file, unsigned line) noexcept { +MONGO_COMPILER_NOINLINE void invariantFailed(const char* expr, + const char* file, + unsigned line) noexcept { severe() << "Invariant failure " << expr << ' ' << file << ' ' << std::dec << line << std::endl; breakpoint(); severe() << "\n\n***aborting after invariant() failure\n\n" << std::endl; std::abort(); } -NOINLINE_DECL void invariantFailedWithMsg(const char* expr, - const std::string& msg, - const char* file, - unsigned line) noexcept { +MONGO_COMPILER_NOINLINE void invariantFailedWithMsg(const char* expr, + const std::string& msg, + const char* file, + unsigned line) noexcept { severe() << "Invariant failure " << expr << " " << msg << " " << file << ' ' << std::dec << line << std::endl; breakpoint(); @@ -115,10 +117,10 @@ NOINLINE_DECL void invariantFailedWithMsg(const char* expr, std::abort(); } -NOINLINE_DECL void invariantOKFailed(const char* expr, - const Status& status, - const char* file, - unsigned line) noexcept { +MONGO_COMPILER_NOINLINE void invariantOKFailed(const char* expr, + const Status& status, + const char* file, + unsigned line) noexcept { severe() << "Invariant failure: " << expr << " resulted in status " << redact(status) << " at " << file << ' ' << std::dec << line; breakpoint(); @@ -126,11 +128,11 @@ NOINLINE_DECL void invariantOKFailed(const char* expr, std::abort(); } -NOINLINE_DECL void invariantOKFailedWithMsg(const char* expr, - const Status& status, - const std::string& msg, - const char* file, - unsigned line) noexcept { +MONGO_COMPILER_NOINLINE void invariantOKFailedWithMsg(const char* expr, + const Status& status, + const std::string& msg, + const char* file, + unsigned line) noexcept { severe() << "Invariant failure: " << expr << " " << msg << " resulted in status " << redact(status) << " at " << file << ' ' << std::dec << line; breakpoint(); @@ -138,16 +140,18 @@ NOINLINE_DECL void invariantOKFailedWithMsg(const char* expr, std::abort(); } -NOINLINE_DECL void fassertFailedWithLocation(int msgid, const char* file, unsigned line) noexcept { +MONGO_COMPILER_NOINLINE void fassertFailedWithLocation(int msgid, + const char* file, + unsigned line) noexcept { severe() << "Fatal Assertion " << msgid << " at " << file << " " << std::dec << line; breakpoint(); severe() << "\n\n***aborting after fassert() failure\n\n" << std::endl; std::abort(); } -NOINLINE_DECL void fassertFailedNoTraceWithLocation(int msgid, - const char* file, - unsigned line) noexcept { +MONGO_COMPILER_NOINLINE void fassertFailedNoTraceWithLocation(int msgid, + const char* file, + unsigned line) noexcept { severe() << "Fatal Assertion " << msgid << " at " << file << " " << std::dec << line; breakpoint(); severe() << "\n\n***aborting after fassert() failure\n\n" << std::endl; @@ -176,13 +180,17 @@ MONGO_COMPILER_NORETURN void fassertFailedWithStatusNoTraceWithLocation(int msgi quickExit(EXIT_ABRUPT); } -NOINLINE_DECL void uassertedWithLocation(const Status& status, const char* file, unsigned line) { +MONGO_COMPILER_NOINLINE void uassertedWithLocation(const Status& status, + const char* file, + unsigned line) { assertionCount.condrollover(assertionCount.user.addAndFetch(1)); LOG(1) << "User Assertion: " << redact(status) << ' ' << file << ' ' << std::dec << line; error_details::throwExceptionForStatus(status); } -NOINLINE_DECL void msgassertedWithLocation(const Status& status, const char* file, unsigned line) { +MONGO_COMPILER_NOINLINE void msgassertedWithLocation(const Status& status, + const char* file, + unsigned line) { assertionCount.condrollover(assertionCount.msg.addAndFetch(1)); error() << "Assertion: " << redact(status) << ' ' << file << ' ' << std::dec << line; error_details::throwExceptionForStatus(status); diff --git a/src/mongo/util/diagnostic_info_test.cpp b/src/mongo/util/diagnostic_info_test.cpp index 45b51b13538..853962f515e 100644 --- a/src/mongo/util/diagnostic_info_test.cpp +++ b/src/mongo/util/diagnostic_info_test.cpp @@ -33,7 +33,6 @@ #include <string> -#include "mongo/bson/inline_decls.h" #include "mongo/unittest/unittest.h" #include "mongo/util/clock_source_mock.h" #include "mongo/util/log.h" @@ -138,7 +137,7 @@ TEST(DiagnosticInfo, StackTraceTest) { #endif } -void NOINLINE_DECL recurseAndCaptureInfo(MaybeDiagnosticInfo& info, size_t i) { +MONGO_COMPILER_NOINLINE void recurseAndCaptureInfo(MaybeDiagnosticInfo& info, size_t i) { // Prevent tail-call optimization. #ifndef _WIN32 asm volatile(""); // NOLINT diff --git a/src/mongo/util/future.h b/src/mongo/util/future.h index e8e3fad4972..237ed6e186b 100644 --- a/src/mongo/util/future.h +++ b/src/mongo/util/future.h @@ -689,7 +689,7 @@ private: } template <typename Sig> - NOINLINE_DECL auto wrapCBHelper(unique_function<Sig>&& func); + MONGO_COMPILER_NOINLINE auto wrapCBHelper(unique_function<Sig>&& func); using SemiFuture<T>::unsafeToInlineFuture; @@ -1123,7 +1123,7 @@ using FutureContinuationResult = template <typename T> template <typename Sig> -NOINLINE_DECL auto ExecutorFuture<T>::wrapCBHelper(unique_function<Sig>&& func) { +MONGO_COMPILER_NOINLINE auto ExecutorFuture<T>::wrapCBHelper(unique_function<Sig>&& func) { using namespace future_details; return [ func = std::move(func), diff --git a/src/mongo/util/future_bm.cpp b/src/mongo/util/future_bm.cpp index fa6bf6e01ea..d9ae5259451 100644 --- a/src/mongo/util/future_bm.cpp +++ b/src/mongo/util/future_bm.cpp @@ -31,12 +31,11 @@ #include <benchmark/benchmark.h> -#include "mongo/bson/inline_decls.h" #include "mongo/util/future.h" namespace mongo { -NOINLINE_DECL int makeReadyInt() { +MONGO_COMPILER_NOINLINE int makeReadyInt() { benchmark::ClobberMemory(); return 1; } @@ -47,7 +46,7 @@ void BM_plainIntReady(benchmark::State& state) { } } -NOINLINE_DECL Future<int> makeReadyFut() { +MONGO_COMPILER_NOINLINE Future<int> makeReadyFut() { benchmark::ClobberMemory(); return Future<int>::makeReady(1); } @@ -64,7 +63,7 @@ void BM_futureIntReadyThen(benchmark::State& state) { } } -NOINLINE_DECL Future<int> makeReadyFutWithPromise() { +MONGO_COMPILER_NOINLINE Future<int> makeReadyFutWithPromise() { benchmark::ClobberMemory(); auto pf = makePromiseFuture<int>(); pf.promise.emplaceValue(1); diff --git a/src/mongo/util/future_test_shared_future.cpp b/src/mongo/util/future_test_shared_future.cpp index aa38bc03221..140af5df573 100644 --- a/src/mongo/util/future_test_shared_future.cpp +++ b/src/mongo/util/future_test_shared_future.cpp @@ -139,7 +139,7 @@ TEST(SharedFuture, ModificationsArePrivate) { }); } -NOINLINE_DECL void useALotOfStackSpace() { +MONGO_COMPILER_NOINLINE void useALotOfStackSpace() { // Try to force the compiler to allocate 100K of stack. volatile char buffer[100'000]; // NOLINT buffer[99'999] = 'x'; |