ART: Fix for no-opt debug (-O0) builds
Currently, the build process of debug builds with no optimization fails
due to missing symbol definitions.
For example, it throws errors like the following one:
ld.lld: error:
undefined symbol:
art::gc::collector::MarkSweep::MarkStackTask<false>::kMaxSize
This patch changes the missing symbols from constants to constant
expressions as a way to fix those issues. The optimized builds
get away with this issue because the values are optimized
to be inlined and not referenced.
The code at https://godbolt.org/z/3oYKoPzGj depicts similar
behaviour. Additionally, there are comments describing why
this issue occurs.
Test: ART_DEBUG_OPT_FLAG="-O0" art/tools/buildbot-build.sh --host
Change-Id: I66b5cfc885dfdfc82e3e4008b1e40fd68c19c999
diff --git a/compiler/utils/assembler.h b/compiler/utils/assembler.h
index 67f38bc..4b4fb14 100644
--- a/compiler/utils/assembler.h
+++ b/compiler/utils/assembler.h
@@ -250,7 +250,7 @@
// The limit is set to kMinimumGap bytes before the end of the data area.
// This leaves enough space for the longest possible instruction and allows
// for a single, fast space check per instruction.
- static const int kMinimumGap = 32;
+ static constexpr int kMinimumGap = 32;
ArenaAllocator* const allocator_;
uint8_t* contents_;
diff --git a/compiler/utils/managed_register.h b/compiler/utils/managed_register.h
index 2afdc04..a3b33ba 100644
--- a/compiler/utils/managed_register.h
+++ b/compiler/utils/managed_register.h
@@ -74,7 +74,7 @@
explicit constexpr ManagedRegister(int reg_id) : id_(reg_id) { }
protected:
- static const int kNoRegister = -1;
+ static constexpr int kNoRegister = -1;
constexpr ManagedRegister() : id_(kNoRegister) { }
diff --git a/runtime/class_table.h b/runtime/class_table.h
index dfae1fd..0ea6245 100644
--- a/runtime/class_table.h
+++ b/runtime/class_table.h
@@ -98,7 +98,7 @@
// Data contains the class pointer GcRoot as well as the low bits of the descriptor hash.
mutable Atomic<uint32_t> data_;
- static const uint32_t kHashMask = kObjectAlignment - 1;
+ static constexpr uint32_t kHashMask = kObjectAlignment - 1;
};
using DescriptorHashPair = std::pair<const char*, uint32_t>;
diff --git a/runtime/gc/allocator/rosalloc.h b/runtime/gc/allocator/rosalloc.h
index a5bfd8f..9a09c88 100644
--- a/runtime/gc/allocator/rosalloc.h
+++ b/runtime/gc/allocator/rosalloc.h
@@ -621,7 +621,7 @@
// A memory allocation request larger than this size is treated as a large object and allocated
// at a page-granularity.
- static const size_t kLargeSizeThreshold = 2048;
+ static constexpr size_t kLargeSizeThreshold = 2048;
// If true, check that the returned memory is actually zero.
static constexpr bool kCheckZeroMemory = kIsDebugBuild;
@@ -662,14 +662,14 @@
// We use thread-local runs for the size brackets whose indexes
// are less than this index. We use shared (current) runs for the rest.
// Sync this with the length of Thread::rosalloc_runs_.
- static const size_t kNumThreadLocalSizeBrackets = 16;
+ static constexpr size_t kNumThreadLocalSizeBrackets = 16;
static_assert(kNumThreadLocalSizeBrackets == kNumRosAllocThreadLocalSizeBracketsInThread,
"Mismatch between kNumThreadLocalSizeBrackets and "
"kNumRosAllocThreadLocalSizeBracketsInThread");
// The size of the largest bracket we use thread-local runs for.
// This should be equal to bracketSizes[kNumThreadLocalSizeBrackets - 1].
- static const size_t kMaxThreadLocalBracketSize = 128;
+ static constexpr size_t kMaxThreadLocalBracketSize = 128;
// We use regular (8 or 16-bytes increment) runs for the size brackets whose indexes are less than
// this index.
@@ -677,7 +677,7 @@
// The size of the largest regular (8 or 16-byte increment) bracket. Non-regular brackets are the
// 1 KB and the 2 KB brackets. This should be equal to bracketSizes[kNumRegularSizeBrackets - 1].
- static const size_t kMaxRegularBracketSize = 512;
+ static constexpr size_t kMaxRegularBracketSize = 512;
// The bracket size increment for the thread-local brackets (<= kMaxThreadLocalBracketSize bytes).
static constexpr size_t kThreadLocalBracketQuantumSize = 8;
diff --git a/runtime/gc/collector/mark_sweep.cc b/runtime/gc/collector/mark_sweep.cc
index 9e5cb9c..ebac36d 100644
--- a/runtime/gc/collector/mark_sweep.cc
+++ b/runtime/gc/collector/mark_sweep.cc
@@ -688,7 +688,7 @@
}
}
- static const size_t kMaxSize = 1 * KB;
+ static constexpr size_t kMaxSize = 1 * KB;
protected:
class MarkObjectParallelVisitor {