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() {
bool Deserializer::ReserveSpace() {
#ifdef DEBUG
for (int i = NEW_SPACE; i < kNumberOfSpaces; ++i) {
DCHECK(reservations_[i].size() > 0);
DCHECK_GT(reservations_[i].size(), 0);
}
#endif // DEBUG
DCHECK(allocated_maps_.empty());
......@@ -202,8 +202,8 @@ void Deserializer::DeserializeDeferredObjects() {
break;
default: {
int space = code & kSpaceMask;
DCHECK(space <= kNumberOfSpaces);
DCHECK(code - space == kNewObject);
DCHECK_LE(space, kNumberOfSpaces);
DCHECK_EQ(code - space, kNewObject);
HeapObject* object = GetBackReferencedObject(space);
int size = source_.GetInt() << kPointerSizeLog2;
Address obj_address = object->address();
......@@ -354,7 +354,7 @@ HeapObject* Deserializer::GetBackReferencedObject(int space) {
DCHECK(index < next_map_index_);
obj = HeapObject::FromAddress(allocated_maps_[index]);
} else {
DCHECK(space < kNumberOfPreallocatedSpaces);
DCHECK_LT(space, kNumberOfPreallocatedSpaces);
uint32_t chunk_index = back_reference.chunk_index();
DCHECK_LE(chunk_index, current_chunk_[space]);
uint32_t chunk_offset = back_reference.chunk_offset();
......@@ -447,7 +447,7 @@ Address Deserializer::Allocate(int space_index, int size) {
DCHECK_EQ(Map::kSize, size);
return allocated_maps_[next_map_index_++];
} else {
DCHECK(space_index < kNumberOfPreallocatedSpaces);
DCHECK_LT(space_index, kNumberOfPreallocatedSpaces);
Address address = high_water_[space_index];
DCHECK_NOT_NULL(address);
high_water_[space_index] += size;
......@@ -618,7 +618,7 @@ bool Deserializer::ReadData(Object** current, Object** limit, int source_space,
case kNextChunk: {
int space = source_.Get();
DCHECK(space < kNumberOfPreallocatedSpaces);
DCHECK_LT(space, kNumberOfPreallocatedSpaces);
int chunk_index = current_chunk_[space];
const Heap::Reservation& reservation = reservations_[space];
// Make sure the current chunk is indeed exhausted.
......@@ -829,13 +829,13 @@ Object** Deserializer::ReadDataCase(Isolate* isolate, Object** current,
new_object = *attached_objects_[index];
emit_write_barrier = isolate->heap()->InNewSpace(new_object);
} else {
DCHECK(where == kBuiltin);
DCHECK_EQ(where, kBuiltin);
int builtin_id = MaybeReplaceWithDeserializeLazy(source_.GetInt());
new_object = isolate->builtins()->builtin(builtin_id);
emit_write_barrier = false;
}
if (within == kInnerPointer) {
DCHECK(how == kFromCode);
DCHECK_EQ(how, kFromCode);
if (where == kBuiltin) {
// At this point, new_object may still be uninitialized, thus the
// unchecked Code cast.
......
......@@ -15,7 +15,7 @@ NativesExternalStringResource::NativesExternalStringResource(NativeType type,
int index)
: type_(type), index_(index) {
Vector<const char> source;
DCHECK(0 <= index);
DCHECK_LE(0, index);
switch (type_) {
case CORE:
DCHECK(index < Natives::GetBuiltinsCount());
......
......@@ -159,7 +159,7 @@ void SetNativesFromFile(StartupData* natives_blob) {
DCHECK(!natives_blob_);
DCHECK(natives_blob);
DCHECK(natives_blob->data);
DCHECK(natives_blob->raw_size > 0);
DCHECK_GT(natives_blob->raw_size, 0);
natives_blob_ = natives_blob;
ReadNatives();
......
......@@ -97,7 +97,7 @@ void ObjectDeserializer::
}
void ObjectDeserializer::CommitPostProcessedObjects() {
CHECK(new_internalized_strings().size() <= kMaxInt);
CHECK_LE(new_internalized_strings().size(), kMaxInt);
StringTable::EnsureCapacityForDeserialization(
isolate(), static_cast<int>(new_internalized_strings().size()));
for (Handle<String> string : new_internalized_strings()) {
......
......@@ -67,8 +67,8 @@ void PartialDeserializer::DeserializeEmbedderFields(
code = source()->Get()) {
HandleScope scope(isolate());
int space = code & kSpaceMask;
DCHECK(space <= kNumberOfSpaces);
DCHECK(code - space == kNewObject);
DCHECK_LE(space, kNumberOfSpaces);
DCHECK_EQ(code - space, kNewObject);
Handle<JSObject> obj(JSObject::cast(GetBackReferencedObject(space)),
isolate());
int index = source()->GetInt();
......
......@@ -389,7 +389,7 @@ void Serializer<AllocatorT>::ObjectSerializer::FixupIfNeutered() {
if (!array->WasNeutered()) return;
FixedTypedArrayBase* fta = FixedTypedArrayBase::cast(array->elements());
DCHECK(fta->base_pointer() == nullptr);
DCHECK_NULL(fta->base_pointer());
fta->set_external_pointer(Smi::kZero);
fta->set_length(0);
}
......@@ -416,7 +416,7 @@ void Serializer<AllocatorT>::ObjectSerializer::SerializeFixedTypedArray() {
FixedTypedArrayBase* fta = FixedTypedArrayBase::cast(object_);
void* backing_store = fta->DataPtr();
// 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());
// The heap contains empty FixedTypedArrays for each type, with a byte_length
......@@ -795,7 +795,7 @@ void Serializer<AllocatorT>::ObjectSerializer::OutputRawData(Address up_to) {
int to_skip = up_to_offset - bytes_processed_so_far_;
int bytes_to_output = to_skip;
bytes_processed_so_far_ += to_skip;
DCHECK(to_skip >= 0);
DCHECK_GE(to_skip, 0);
if (bytes_to_output != 0) {
DCHECK(to_skip == bytes_to_output);
if (IsAligned(bytes_to_output, kPointerAlignment) &&
......@@ -822,7 +822,7 @@ int Serializer<AllocatorT>::ObjectSerializer::SkipTo(Address to) {
bytes_processed_so_far_ += to_skip;
// 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.
DCHECK(to_skip >= 0);
DCHECK_GE(to_skip, 0);
return to_skip;
}
......
......@@ -74,11 +74,11 @@ class CodeAddressMap : public CodeEventLogger {
void Move(Address from, Address to) {
if (from == to) return;
base::HashMap::Entry* from_entry = FindEntry(from);
DCHECK(from_entry != nullptr);
DCHECK_NOT_NULL(from_entry);
void* value = from_entry->value;
RemoveEntry(from_entry);
base::HashMap::Entry* to_entry = FindOrCreateEntry(to);
DCHECK(to_entry->value == nullptr);
DCHECK_NULL(to_entry->value);
to_entry->value = value;
}
......
......@@ -27,7 +27,7 @@ void SetSnapshotFromFile(StartupData* snapshot_blob) {
external_startup_data_mutex.Pointer());
DCHECK(snapshot_blob);
DCHECK(snapshot_blob->data);
DCHECK(snapshot_blob->raw_size > 0);
DCHECK_GT(snapshot_blob->raw_size, 0);
DCHECK(!external_startup_blob.data);
DCHECK(Snapshot::SnapshotIsValid(snapshot_blob));
external_startup_blob = *snapshot_blob;
......
......@@ -13,7 +13,7 @@ namespace v8 {
namespace internal {
void SnapshotByteSink::PutInt(uintptr_t integer, const char* description) {
DCHECK(integer < 1 << 30);
DCHECK_LT(integer, 1 << 30);
integer <<= 2;
int bytes = 1;
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