Commit 61c7af2e authored by Clemens Hammacher's avatar Clemens Hammacher Committed by Commit Bot

[cleanup] Fix (D)CHECK macros in src/snapshot

Use the (D)CHECK_{EQ,NE,GT,...} macros instead of (D)CHECK with an
embedded comparison. This gives better error messages and also does the
right comparison for signed/unsigned mismatches.

This will allow us to reenable the readability/check cpplint check.

R=yangguo@chromium.org

Bug: v8:6837, v8:6921
Change-Id: I0c2deaea3f2ff5b5b25ba658470850534f1900ac
Reviewed-on: https://chromium-review.googlesource.com/681435
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Reviewed-by: 's avatarYang Guo <yangguo@chromium.org>
Cr-Commit-Position: refs/heads/master@{#48594}
parent af49af00
...@@ -43,7 +43,7 @@ void Deserializer::RegisterDeserializedObjectsForBlackAllocation() { ...@@ -43,7 +43,7 @@ void Deserializer::RegisterDeserializedObjectsForBlackAllocation() {
bool Deserializer::ReserveSpace() { bool Deserializer::ReserveSpace() {
#ifdef DEBUG #ifdef DEBUG
for (int i = NEW_SPACE; i < kNumberOfSpaces; ++i) { for (int i = NEW_SPACE; i < kNumberOfSpaces; ++i) {
DCHECK(reservations_[i].size() > 0); DCHECK_GT(reservations_[i].size(), 0);
} }
#endif // DEBUG #endif // DEBUG
DCHECK(allocated_maps_.empty()); DCHECK(allocated_maps_.empty());
...@@ -202,8 +202,8 @@ void Deserializer::DeserializeDeferredObjects() { ...@@ -202,8 +202,8 @@ void Deserializer::DeserializeDeferredObjects() {
break; break;
default: { default: {
int space = code & kSpaceMask; int space = code & kSpaceMask;
DCHECK(space <= kNumberOfSpaces); DCHECK_LE(space, kNumberOfSpaces);
DCHECK(code - space == kNewObject); DCHECK_EQ(code - space, kNewObject);
HeapObject* object = GetBackReferencedObject(space); HeapObject* object = GetBackReferencedObject(space);
int size = source_.GetInt() << kPointerSizeLog2; int size = source_.GetInt() << kPointerSizeLog2;
Address obj_address = object->address(); Address obj_address = object->address();
...@@ -354,7 +354,7 @@ HeapObject* Deserializer::GetBackReferencedObject(int space) { ...@@ -354,7 +354,7 @@ HeapObject* Deserializer::GetBackReferencedObject(int space) {
DCHECK(index < next_map_index_); DCHECK(index < next_map_index_);
obj = HeapObject::FromAddress(allocated_maps_[index]); obj = HeapObject::FromAddress(allocated_maps_[index]);
} else { } else {
DCHECK(space < kNumberOfPreallocatedSpaces); DCHECK_LT(space, kNumberOfPreallocatedSpaces);
uint32_t chunk_index = back_reference.chunk_index(); uint32_t chunk_index = back_reference.chunk_index();
DCHECK_LE(chunk_index, current_chunk_[space]); DCHECK_LE(chunk_index, current_chunk_[space]);
uint32_t chunk_offset = back_reference.chunk_offset(); uint32_t chunk_offset = back_reference.chunk_offset();
...@@ -447,7 +447,7 @@ Address Deserializer::Allocate(int space_index, int size) { ...@@ -447,7 +447,7 @@ Address Deserializer::Allocate(int space_index, int size) {
DCHECK_EQ(Map::kSize, size); DCHECK_EQ(Map::kSize, size);
return allocated_maps_[next_map_index_++]; return allocated_maps_[next_map_index_++];
} else { } else {
DCHECK(space_index < kNumberOfPreallocatedSpaces); DCHECK_LT(space_index, kNumberOfPreallocatedSpaces);
Address address = high_water_[space_index]; Address address = high_water_[space_index];
DCHECK_NOT_NULL(address); DCHECK_NOT_NULL(address);
high_water_[space_index] += size; high_water_[space_index] += size;
...@@ -618,7 +618,7 @@ bool Deserializer::ReadData(Object** current, Object** limit, int source_space, ...@@ -618,7 +618,7 @@ bool Deserializer::ReadData(Object** current, Object** limit, int source_space,
case kNextChunk: { case kNextChunk: {
int space = source_.Get(); int space = source_.Get();
DCHECK(space < kNumberOfPreallocatedSpaces); DCHECK_LT(space, kNumberOfPreallocatedSpaces);
int chunk_index = current_chunk_[space]; int chunk_index = current_chunk_[space];
const Heap::Reservation& reservation = reservations_[space]; const Heap::Reservation& reservation = reservations_[space];
// Make sure the current chunk is indeed exhausted. // Make sure the current chunk is indeed exhausted.
...@@ -829,13 +829,13 @@ Object** Deserializer::ReadDataCase(Isolate* isolate, Object** current, ...@@ -829,13 +829,13 @@ Object** Deserializer::ReadDataCase(Isolate* isolate, Object** current,
new_object = *attached_objects_[index]; new_object = *attached_objects_[index];
emit_write_barrier = isolate->heap()->InNewSpace(new_object); emit_write_barrier = isolate->heap()->InNewSpace(new_object);
} else { } else {
DCHECK(where == kBuiltin); DCHECK_EQ(where, kBuiltin);
int builtin_id = MaybeReplaceWithDeserializeLazy(source_.GetInt()); int builtin_id = MaybeReplaceWithDeserializeLazy(source_.GetInt());
new_object = isolate->builtins()->builtin(builtin_id); new_object = isolate->builtins()->builtin(builtin_id);
emit_write_barrier = false; emit_write_barrier = false;
} }
if (within == kInnerPointer) { if (within == kInnerPointer) {
DCHECK(how == kFromCode); DCHECK_EQ(how, kFromCode);
if (where == kBuiltin) { if (where == kBuiltin) {
// At this point, new_object may still be uninitialized, thus the // At this point, new_object may still be uninitialized, thus the
// unchecked Code cast. // unchecked Code cast.
......
...@@ -15,7 +15,7 @@ NativesExternalStringResource::NativesExternalStringResource(NativeType type, ...@@ -15,7 +15,7 @@ NativesExternalStringResource::NativesExternalStringResource(NativeType type,
int index) int index)
: type_(type), index_(index) { : type_(type), index_(index) {
Vector<const char> source; Vector<const char> source;
DCHECK(0 <= index); DCHECK_LE(0, index);
switch (type_) { switch (type_) {
case CORE: case CORE:
DCHECK(index < Natives::GetBuiltinsCount()); DCHECK(index < Natives::GetBuiltinsCount());
......
...@@ -159,7 +159,7 @@ void SetNativesFromFile(StartupData* natives_blob) { ...@@ -159,7 +159,7 @@ void SetNativesFromFile(StartupData* natives_blob) {
DCHECK(!natives_blob_); DCHECK(!natives_blob_);
DCHECK(natives_blob); DCHECK(natives_blob);
DCHECK(natives_blob->data); DCHECK(natives_blob->data);
DCHECK(natives_blob->raw_size > 0); DCHECK_GT(natives_blob->raw_size, 0);
natives_blob_ = natives_blob; natives_blob_ = natives_blob;
ReadNatives(); ReadNatives();
......
...@@ -97,7 +97,7 @@ void ObjectDeserializer:: ...@@ -97,7 +97,7 @@ void ObjectDeserializer::
} }
void ObjectDeserializer::CommitPostProcessedObjects() { void ObjectDeserializer::CommitPostProcessedObjects() {
CHECK(new_internalized_strings().size() <= kMaxInt); CHECK_LE(new_internalized_strings().size(), kMaxInt);
StringTable::EnsureCapacityForDeserialization( StringTable::EnsureCapacityForDeserialization(
isolate(), static_cast<int>(new_internalized_strings().size())); isolate(), static_cast<int>(new_internalized_strings().size()));
for (Handle<String> string : new_internalized_strings()) { for (Handle<String> string : new_internalized_strings()) {
......
...@@ -67,8 +67,8 @@ void PartialDeserializer::DeserializeEmbedderFields( ...@@ -67,8 +67,8 @@ void PartialDeserializer::DeserializeEmbedderFields(
code = source()->Get()) { code = source()->Get()) {
HandleScope scope(isolate()); HandleScope scope(isolate());
int space = code & kSpaceMask; int space = code & kSpaceMask;
DCHECK(space <= kNumberOfSpaces); DCHECK_LE(space, kNumberOfSpaces);
DCHECK(code - space == kNewObject); DCHECK_EQ(code - space, kNewObject);
Handle<JSObject> obj(JSObject::cast(GetBackReferencedObject(space)), Handle<JSObject> obj(JSObject::cast(GetBackReferencedObject(space)),
isolate()); isolate());
int index = source()->GetInt(); int index = source()->GetInt();
......
...@@ -389,7 +389,7 @@ void Serializer<AllocatorT>::ObjectSerializer::FixupIfNeutered() { ...@@ -389,7 +389,7 @@ void Serializer<AllocatorT>::ObjectSerializer::FixupIfNeutered() {
if (!array->WasNeutered()) return; if (!array->WasNeutered()) return;
FixedTypedArrayBase* fta = FixedTypedArrayBase::cast(array->elements()); FixedTypedArrayBase* fta = FixedTypedArrayBase::cast(array->elements());
DCHECK(fta->base_pointer() == nullptr); DCHECK_NULL(fta->base_pointer());
fta->set_external_pointer(Smi::kZero); fta->set_external_pointer(Smi::kZero);
fta->set_length(0); fta->set_length(0);
} }
...@@ -416,7 +416,7 @@ void Serializer<AllocatorT>::ObjectSerializer::SerializeFixedTypedArray() { ...@@ -416,7 +416,7 @@ void Serializer<AllocatorT>::ObjectSerializer::SerializeFixedTypedArray() {
FixedTypedArrayBase* fta = FixedTypedArrayBase::cast(object_); FixedTypedArrayBase* fta = FixedTypedArrayBase::cast(object_);
void* backing_store = fta->DataPtr(); void* backing_store = fta->DataPtr();
// We cannot store byte_length larger than Smi range in the snapshot. // We cannot store byte_length larger than Smi range in the snapshot.
CHECK(fta->ByteLength() < Smi::kMaxValue); CHECK_LT(fta->ByteLength(), Smi::kMaxValue);
int32_t byte_length = static_cast<int32_t>(fta->ByteLength()); int32_t byte_length = static_cast<int32_t>(fta->ByteLength());
// The heap contains empty FixedTypedArrays for each type, with a byte_length // The heap contains empty FixedTypedArrays for each type, with a byte_length
...@@ -795,7 +795,7 @@ void Serializer<AllocatorT>::ObjectSerializer::OutputRawData(Address up_to) { ...@@ -795,7 +795,7 @@ void Serializer<AllocatorT>::ObjectSerializer::OutputRawData(Address up_to) {
int to_skip = up_to_offset - bytes_processed_so_far_; int to_skip = up_to_offset - bytes_processed_so_far_;
int bytes_to_output = to_skip; int bytes_to_output = to_skip;
bytes_processed_so_far_ += to_skip; bytes_processed_so_far_ += to_skip;
DCHECK(to_skip >= 0); DCHECK_GE(to_skip, 0);
if (bytes_to_output != 0) { if (bytes_to_output != 0) {
DCHECK(to_skip == bytes_to_output); DCHECK(to_skip == bytes_to_output);
if (IsAligned(bytes_to_output, kPointerAlignment) && if (IsAligned(bytes_to_output, kPointerAlignment) &&
...@@ -822,7 +822,7 @@ int Serializer<AllocatorT>::ObjectSerializer::SkipTo(Address to) { ...@@ -822,7 +822,7 @@ int Serializer<AllocatorT>::ObjectSerializer::SkipTo(Address to) {
bytes_processed_so_far_ += to_skip; bytes_processed_so_far_ += to_skip;
// This assert will fail if the reloc info gives us the target_address_address // This assert will fail if the reloc info gives us the target_address_address
// locations in a non-ascending order. Luckily that doesn't happen. // locations in a non-ascending order. Luckily that doesn't happen.
DCHECK(to_skip >= 0); DCHECK_GE(to_skip, 0);
return to_skip; return to_skip;
} }
......
...@@ -74,11 +74,11 @@ class CodeAddressMap : public CodeEventLogger { ...@@ -74,11 +74,11 @@ class CodeAddressMap : public CodeEventLogger {
void Move(Address from, Address to) { void Move(Address from, Address to) {
if (from == to) return; if (from == to) return;
base::HashMap::Entry* from_entry = FindEntry(from); base::HashMap::Entry* from_entry = FindEntry(from);
DCHECK(from_entry != nullptr); DCHECK_NOT_NULL(from_entry);
void* value = from_entry->value; void* value = from_entry->value;
RemoveEntry(from_entry); RemoveEntry(from_entry);
base::HashMap::Entry* to_entry = FindOrCreateEntry(to); base::HashMap::Entry* to_entry = FindOrCreateEntry(to);
DCHECK(to_entry->value == nullptr); DCHECK_NULL(to_entry->value);
to_entry->value = value; to_entry->value = value;
} }
......
...@@ -27,7 +27,7 @@ void SetSnapshotFromFile(StartupData* snapshot_blob) { ...@@ -27,7 +27,7 @@ void SetSnapshotFromFile(StartupData* snapshot_blob) {
external_startup_data_mutex.Pointer()); external_startup_data_mutex.Pointer());
DCHECK(snapshot_blob); DCHECK(snapshot_blob);
DCHECK(snapshot_blob->data); DCHECK(snapshot_blob->data);
DCHECK(snapshot_blob->raw_size > 0); DCHECK_GT(snapshot_blob->raw_size, 0);
DCHECK(!external_startup_blob.data); DCHECK(!external_startup_blob.data);
DCHECK(Snapshot::SnapshotIsValid(snapshot_blob)); DCHECK(Snapshot::SnapshotIsValid(snapshot_blob));
external_startup_blob = *snapshot_blob; external_startup_blob = *snapshot_blob;
......
...@@ -13,7 +13,7 @@ namespace v8 { ...@@ -13,7 +13,7 @@ namespace v8 {
namespace internal { namespace internal {
void SnapshotByteSink::PutInt(uintptr_t integer, const char* description) { void SnapshotByteSink::PutInt(uintptr_t integer, const char* description) {
DCHECK(integer < 1 << 30); DCHECK_LT(integer, 1 << 30);
integer <<= 2; integer <<= 2;
int bytes = 1; int bytes = 1;
if (integer > 0xff) bytes = 2; if (integer > 0xff) bytes = 2;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment