Replace some run-time assertions with compile-time ones in ART.
Change-Id: I16c3fad45c4b98b94b7c83d071374096e81d407a
diff --git a/compiler/optimizing/code_generator_arm.cc b/compiler/optimizing/code_generator_arm.cc
index f6ae452..bb5debb 100644
--- a/compiler/optimizing/code_generator_arm.cc
+++ b/compiler/optimizing/code_generator_arm.cc
@@ -3370,7 +3370,8 @@
case Primitive::kPrimInt:
case Primitive::kPrimNot: {
- DCHECK_EQ(sizeof(mirror::HeapReference<mirror::Object>), sizeof(int32_t));
+ static_assert(sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t),
+ "art::mirror::HeapReference<mirror::Object> and int32_t have different sizes.");
uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
Register out = locations->Out().AsRegister<Register>();
if (index.IsConstant()) {
diff --git a/compiler/optimizing/code_generator_x86_64.cc b/compiler/optimizing/code_generator_x86_64.cc
index bfc827d..4da5bc4 100644
--- a/compiler/optimizing/code_generator_x86_64.cc
+++ b/compiler/optimizing/code_generator_x86_64.cc
@@ -3503,7 +3503,8 @@
case Primitive::kPrimInt:
case Primitive::kPrimNot: {
- DCHECK_EQ(sizeof(mirror::HeapReference<mirror::Object>), sizeof(int32_t));
+ static_assert(sizeof(mirror::HeapReference<mirror::Object>) == sizeof(int32_t),
+ "art::mirror::HeapReference<mirror::Object> and int32_t have different sizes.");
uint32_t data_offset = mirror::Array::DataOffset(sizeof(int32_t)).Uint32Value();
CpuRegister out = locations->Out().AsRegister<CpuRegister>();
if (index.IsConstant()) {
diff --git a/runtime/arch/x86/thread_x86.cc b/runtime/arch/x86/thread_x86.cc
index b97c143..3d19f06 100644
--- a/runtime/arch/x86/thread_x86.cc
+++ b/runtime/arch/x86/thread_x86.cc
@@ -79,7 +79,8 @@
}
#else
// Read current LDT entries.
- CHECK_EQ((size_t)LDT_ENTRY_SIZE, sizeof(uint64_t));
+ static_assert(static_cast<size_t>(LDT_ENTRY_SIZE) == sizeof(uint64_t),
+ "LDT_ENTRY_SIZE is different from sizeof(uint64_t).");
std::vector<uint64_t> ldt(LDT_ENTRIES);
size_t ldt_size(sizeof(uint64_t) * ldt.size());
memset(&ldt[0], 0, ldt_size);
diff --git a/runtime/debugger.cc b/runtime/debugger.cc
index 5918c10..f84e10c 100644
--- a/runtime/debugger.cc
+++ b/runtime/debugger.cc
@@ -3942,7 +3942,7 @@
<< " arg_count=" << pReq->arg_count;
CHECK(m != nullptr);
- CHECK_EQ(sizeof(jvalue), sizeof(uint64_t));
+ static_assert(sizeof(jvalue) == sizeof(uint64_t), "jvalue and uint64_t have different sizes.");
// Invoke the method.
ScopedLocalRef<jobject> ref(soa.Env(), soa.AddLocalReference<jobject>(pReq->receiver.Read()));
diff --git a/runtime/mirror/class-inl.h b/runtime/mirror/class-inl.h
index 8c9222f..122cc6b 100644
--- a/runtime/mirror/class-inl.h
+++ b/runtime/mirror/class-inl.h
@@ -552,7 +552,8 @@
template<VerifyObjectFlags kVerifyFlags>
inline Primitive::Type Class::GetPrimitiveType() {
- DCHECK_EQ(sizeof(Primitive::Type), sizeof(int32_t));
+ static_assert(sizeof(Primitive::Type) == sizeof(int32_t),
+ "art::Primitive::Type and int32_t have different sizes.");
int32_t v32 = GetField32<kVerifyFlags>(OFFSET_OF_OBJECT_MEMBER(Class, primitive_type_));
Primitive::Type type = static_cast<Primitive::Type>(v32 & 0xFFFF);
DCHECK_EQ(static_cast<size_t>(v32 >> 16), Primitive::ComponentSizeShift(type));
@@ -561,7 +562,8 @@
template<VerifyObjectFlags kVerifyFlags>
inline size_t Class::GetPrimitiveTypeSizeShift() {
- DCHECK_EQ(sizeof(Primitive::Type), sizeof(int32_t));
+ static_assert(sizeof(Primitive::Type) == sizeof(int32_t),
+ "art::Primitive::Type and int32_t have different sizes.");
int32_t v32 = GetField32<kVerifyFlags>(OFFSET_OF_OBJECT_MEMBER(Class, primitive_type_));
size_t size_shift = static_cast<Primitive::Type>(v32 >> 16);
DCHECK_EQ(size_shift, Primitive::ComponentSizeShift(static_cast<Primitive::Type>(v32 & 0xFFFF)));
diff --git a/runtime/mirror/object_array-inl.h b/runtime/mirror/object_array-inl.h
index bef4af6..4a7e7b3 100644
--- a/runtime/mirror/object_array-inl.h
+++ b/runtime/mirror/object_array-inl.h
@@ -129,7 +129,8 @@
}
}
// Perform the memmove using int memmove then perform the write barrier.
- CHECK_EQ(sizeof(HeapReference<T>), sizeof(uint32_t));
+ static_assert(sizeof(HeapReference<T>) == sizeof(uint32_t),
+ "art::mirror::HeapReference<T> and uint32_t have different sizes.");
IntArray* dstAsIntArray = reinterpret_cast<IntArray*>(this);
IntArray* srcAsIntArray = reinterpret_cast<IntArray*>(src);
if (kUseReadBarrier) {
@@ -172,7 +173,8 @@
}
}
// Perform the memmove using int memcpy then perform the write barrier.
- CHECK_EQ(sizeof(HeapReference<T>), sizeof(uint32_t));
+ static_assert(sizeof(HeapReference<T>) == sizeof(uint32_t),
+ "art::mirror::HeapReference<T> and uint32_t have different sizes.");
IntArray* dstAsIntArray = reinterpret_cast<IntArray*>(this);
IntArray* srcAsIntArray = reinterpret_cast<IntArray*>(src);
if (kUseReadBarrier) {
diff --git a/runtime/thread.cc b/runtime/thread.cc
index fe8b0d8..348d685 100644
--- a/runtime/thread.cc
+++ b/runtime/thread.cc
@@ -1277,7 +1277,8 @@
tlsPtr_.name = new std::string(kThreadNameDuringStartup);
tlsPtr_.nested_signal_state = static_cast<jmp_buf*>(malloc(sizeof(jmp_buf)));
- CHECK_EQ((sizeof(Thread) % 4), 0U) << sizeof(Thread);
+ static_assert((sizeof(Thread) % 4) == 0U,
+ "art::Thread has a size which is not a multiple of 4.");
tls32_.state_and_flags.as_struct.flags = 0;
tls32_.state_and_flags.as_struct.state = kNative;
memset(&tlsPtr_.held_mutexes[0], 0, sizeof(tlsPtr_.held_mutexes));