Commit b7a9c022 authored by Camillo Bruni's avatar Camillo Bruni Committed by Commit Bot

[cleanup] Introduce more const methods

Change-Id: I703c90cfbb91f4afc035fb32a44f33af9fe736f3
Reviewed-on: https://chromium-review.googlesource.com/548459
Commit-Queue: Camillo Bruni <cbruni@chromium.org>
Reviewed-by: 's avatarMichael Lippautz <mlippautz@chromium.org>
Reviewed-by: 's avatarJakob Kummerow <jkummerow@chromium.org>
Cr-Commit-Position: refs/heads/master@{#46392}
parent 9cb2211c
......@@ -11,8 +11,7 @@
namespace v8 {
namespace internal {
inline FieldIndex FieldIndex::ForInObjectOffset(int offset, Map* map) {
inline FieldIndex FieldIndex::ForInObjectOffset(int offset, const Map* map) {
DCHECK((offset % kPointerSize) == 0);
int index = offset / kPointerSize;
DCHECK(map == NULL ||
......@@ -21,8 +20,7 @@ inline FieldIndex FieldIndex::ForInObjectOffset(int offset, Map* map) {
return FieldIndex(true, index, false, 0, 0, true);
}
inline FieldIndex FieldIndex::ForPropertyIndex(Map* map,
inline FieldIndex FieldIndex::ForPropertyIndex(const Map* map,
int property_index,
bool is_double) {
DCHECK(map->instance_type() >= FIRST_NONSTRING_TYPE);
......@@ -42,7 +40,8 @@ inline FieldIndex FieldIndex::ForPropertyIndex(Map* map,
// Takes an index as computed by GetLoadByFieldIndex and reconstructs a
// FieldIndex object from it.
inline FieldIndex FieldIndex::ForLoadByFieldIndex(Map* map, int orig_index) {
inline FieldIndex FieldIndex::ForLoadByFieldIndex(const Map* map,
int orig_index) {
int field_index = orig_index;
bool is_inobject = true;
bool is_double = field_index & 1;
......@@ -85,7 +84,8 @@ inline int FieldIndex::GetLoadByFieldIndex() const {
return is_double() ? (result | 1) : result;
}
inline FieldIndex FieldIndex::ForDescriptor(Map* map, int descriptor_index) {
inline FieldIndex FieldIndex::ForDescriptor(const Map* map,
int descriptor_index) {
PropertyDetails details =
map->instance_descriptors()->GetDetails(descriptor_index);
int field_index = details.field_index();
......
......@@ -21,12 +21,11 @@ class FieldIndex final {
public:
FieldIndex() : bit_field_(0) {}
static FieldIndex ForPropertyIndex(Map* map,
int index,
static FieldIndex ForPropertyIndex(const Map* map, int index,
bool is_double = false);
static FieldIndex ForInObjectOffset(int offset, Map* map = NULL);
static FieldIndex ForDescriptor(Map* map, int descriptor_index);
static FieldIndex ForLoadByFieldIndex(Map* map, int index);
static FieldIndex ForInObjectOffset(int offset, const Map* map = NULL);
static FieldIndex ForDescriptor(const Map* map, int descriptor_index);
static FieldIndex ForLoadByFieldIndex(const Map* map, int index);
static FieldIndex FromFieldAccessStubKey(int key);
int GetLoadByFieldIndex() const;
......
......@@ -3088,8 +3088,7 @@ Heap::RootListIndex Heap::RootIndexForEmptyFixedTypedArray(
}
}
FixedTypedArrayBase* Heap::EmptyFixedTypedArrayForMap(Map* map) {
FixedTypedArrayBase* Heap::EmptyFixedTypedArrayForMap(const Map* map) {
return FixedTypedArrayBase::cast(
roots_[RootIndexForEmptyFixedTypedArray(map->elements_kind())]);
}
......
......@@ -1115,7 +1115,7 @@ class Heap {
RootListIndex RootIndexForFixedTypedArray(ExternalArrayType array_type);
RootListIndex RootIndexForEmptyFixedTypedArray(ElementsKind kind);
FixedTypedArrayBase* EmptyFixedTypedArrayForMap(Map* map);
FixedTypedArrayBase* EmptyFixedTypedArrayForMap(const Map* map);
void RegisterStrongRoots(Object** start, Object** end);
void UnregisterStrongRoots(Object** start);
......
This diff is collapsed.
......@@ -2144,7 +2144,7 @@ Maybe<bool> JSReceiver::SetOrCopyDataProperties(
return Just(true);
}
Map* Object::GetPrototypeChainRootMap(Isolate* isolate) {
Map* Object::GetPrototypeChainRootMap(Isolate* isolate) const {
DisallowHeapAllocation no_alloc;
if (IsSmi()) {
Context* native_context = isolate->context()->native_context();
......@@ -2153,14 +2153,14 @@ Map* Object::GetPrototypeChainRootMap(Isolate* isolate) {
// The object is either a number, a string, a symbol, a boolean, a real JS
// object, or a Harmony proxy.
HeapObject* heap_object = HeapObject::cast(this);
const HeapObject* heap_object = HeapObject::cast(this);
return heap_object->map()->GetPrototypeChainRootMap(isolate);
}
Map* Map::GetPrototypeChainRootMap(Isolate* isolate) {
Map* Map::GetPrototypeChainRootMap(Isolate* isolate) const {
DisallowHeapAllocation no_alloc;
if (IsJSReceiverMap()) {
return this;
return const_cast<Map*>(this);
}
int constructor_function_index = GetConstructorFunctionIndex();
if (constructor_function_index != Map::kNoConstructorFunctionIndex) {
......@@ -3458,11 +3458,13 @@ Handle<Context> JSReceiver::GetCreationContext() {
: Handle<Context>::null();
}
// static
Handle<Object> Map::WrapFieldType(Handle<FieldType> type) {
if (type->IsClass()) return Map::WeakCellForMap(type->AsClass());
return type;
}
// static
FieldType* Map::UnwrapFieldType(Object* wrapped_type) {
Object* value = wrapped_type;
if (value->IsWeakCell()) {
......@@ -3550,7 +3552,7 @@ const char* Representation::Mnemonic() const {
}
}
bool Map::TransitionRemovesTaggedField(Map* target) {
bool Map::TransitionRemovesTaggedField(Map* target) const {
int inobject = NumberOfFields();
int target_inobject = target->NumberOfFields();
for (int i = target_inobject; i < inobject; i++) {
......@@ -3560,7 +3562,7 @@ bool Map::TransitionRemovesTaggedField(Map* target) {
return false;
}
bool Map::TransitionChangesTaggedFieldToUntaggedField(Map* target) {
bool Map::TransitionChangesTaggedFieldToUntaggedField(Map* target) const {
int inobject = NumberOfFields();
int target_inobject = target->NumberOfFields();
int limit = Min(inobject, target_inobject);
......@@ -3573,12 +3575,12 @@ bool Map::TransitionChangesTaggedFieldToUntaggedField(Map* target) {
return false;
}
bool Map::TransitionRequiresSynchronizationWithGC(Map* target) {
bool Map::TransitionRequiresSynchronizationWithGC(Map* target) const {
return TransitionRemovesTaggedField(target) ||
TransitionChangesTaggedFieldToUntaggedField(target);
}
bool Map::InstancesNeedRewriting(Map* target) {
bool Map::InstancesNeedRewriting(Map* target) const {
int target_number_of_fields = target->NumberOfFields();
int target_inobject = target->GetInObjectProperties();
int target_unused = target->unused_property_fields();
......@@ -3591,7 +3593,7 @@ bool Map::InstancesNeedRewriting(Map* target) {
bool Map::InstancesNeedRewriting(Map* target, int target_number_of_fields,
int target_inobject, int target_unused,
int* old_number_of_fields) {
int* old_number_of_fields) const {
// If fields were added (or removed), rewrite the instance.
*old_number_of_fields = NumberOfFields();
DCHECK(target_number_of_fields >= *old_number_of_fields);
......@@ -4051,7 +4053,7 @@ void JSObject::ForceSetPrototype(Handle<JSObject> object,
JSObject::MigrateToMap(object, new_map);
}
int Map::NumberOfFields() {
int Map::NumberOfFields() const {
DescriptorArray* descriptors = instance_descriptors();
int result = 0;
for (int i = 0; i < NumberOfOwnDescriptors(); i++) {
......@@ -4175,9 +4177,8 @@ void Map::ReplaceDescriptors(DescriptorArray* new_descriptors,
set_owns_descriptors(false);
}
Map* Map::FindRootMap() {
Map* result = this;
Map* Map::FindRootMap() const {
const Map* result = this;
Isolate* isolate = GetIsolate();
while (true) {
Object* back = result->GetBackPointer();
......@@ -4187,26 +4188,25 @@ Map* Map::FindRootMap() {
DCHECK(result->owns_descriptors());
DCHECK_EQ(result->NumberOfOwnDescriptors(),
result->instance_descriptors()->number_of_descriptors());
return result;
return const_cast<Map*>(result);
}
result = Map::cast(back);
}
}
Map* Map::FindFieldOwner(int descriptor) {
Map* Map::FindFieldOwner(int descriptor) const {
DisallowHeapAllocation no_allocation;
DCHECK_EQ(kField, instance_descriptors()->GetDetails(descriptor).location());
Map* result = this;
const Map* result = this;
Isolate* isolate = GetIsolate();
while (true) {
Object* back = result->GetBackPointer();
if (back->IsUndefined(isolate)) break;
Map* parent = Map::cast(back);
const Map* parent = Map::cast(back);
if (parent->NumberOfOwnDescriptors() <= descriptor) break;
result = parent;
}
return result;
return const_cast<Map*>(result);
}
void Map::UpdateFieldType(int descriptor, Handle<Name> name,
......@@ -5112,8 +5112,7 @@ Map* Map::LookupElementsTransitionMap(ElementsKind to_kind) {
return nullptr;
}
bool Map::IsMapInArrayPrototypeChain() {
bool Map::IsMapInArrayPrototypeChain() const {
Isolate* isolate = GetIsolate();
if (isolate->initial_array_prototype()->map() == this) {
return true;
......@@ -8278,7 +8277,7 @@ bool JSObject::HasEnumerableElements() {
UNREACHABLE();
}
int Map::NumberOfEnumerableProperties() {
int Map::NumberOfEnumerableProperties() const {
int result = 0;
DescriptorArray* descs = instance_descriptors();
int limit = NumberOfOwnDescriptors();
......@@ -8291,8 +8290,7 @@ int Map::NumberOfEnumerableProperties() {
return result;
}
int Map::NextFreePropertyIndex() {
int Map::NextFreePropertyIndex() const {
int free_index = 0;
int number_of_own_descriptors = NumberOfOwnDescriptors();
DescriptorArray* descs = instance_descriptors();
......@@ -8306,8 +8304,7 @@ int Map::NextFreePropertyIndex() {
return free_index;
}
bool Map::OnlyHasSimpleProperties() {
bool Map::OnlyHasSimpleProperties() const {
// Wrapped string elements aren't explicitly stored in the elements backing
// store, but are loaded indirectly from the underlying string.
return !IsStringWrapperElementsKind(elements_kind()) &&
......@@ -11976,7 +11973,7 @@ int Map::Hash() {
namespace {
bool CheckEquivalent(Map* first, Map* second) {
bool CheckEquivalent(const Map* first, const Map* second) {
return first->GetConstructor() == second->GetConstructor() &&
first->prototype() == second->prototype() &&
first->instance_type() == second->instance_type() &&
......@@ -11988,8 +11985,7 @@ bool CheckEquivalent(Map* first, Map* second) {
} // namespace
bool Map::EquivalentToForTransition(Map* other) {
bool Map::EquivalentToForTransition(const Map* other) const {
if (!CheckEquivalent(this, other)) return false;
if (instance_type() == JS_FUNCTION_TYPE) {
// JSFunctions require more checks to ensure that sloppy function is
......@@ -12001,9 +11997,8 @@ bool Map::EquivalentToForTransition(Map* other) {
return true;
}
bool Map::EquivalentToForNormalization(Map* other,
PropertyNormalizationMode mode) {
bool Map::EquivalentToForNormalization(const Map* other,
PropertyNormalizationMode mode) const {
int properties =
mode == CLEAR_INOBJECT_PROPERTIES ? 0 : other->GetInObjectProperties();
return CheckEquivalent(this, other) && bit_field2() == other->bit_field2() &&
......
This diff is collapsed.
......@@ -68,13 +68,13 @@ class BaseShape {
class V8_EXPORT_PRIVATE HashTableBase : public NON_EXPORTED_BASE(FixedArray) {
public:
// Returns the number of elements in the hash table.
inline int NumberOfElements();
inline int NumberOfElements() const;
// Returns the number of deleted elements in the hash table.
inline int NumberOfDeletedElements();
inline int NumberOfDeletedElements() const;
// Returns the capacity of the hash table.
inline int Capacity();
inline int Capacity() const;
// ElementAdded should be called whenever an element is added to a
// hash table.
......@@ -678,7 +678,9 @@ class SmallOrderedHashTable : public HeapObject {
return ((padding_offset + kPointerSize - 1) / kPointerSize) * kPointerSize;
}
int GetDataTableStartOffset() { return GetDataTableStartOffset(Capacity()); }
int GetDataTableStartOffset() const {
return GetDataTableStartOffset(Capacity());
}
static int Size(int capacity) {
int data_table_start = GetDataTableStartOffset(capacity);
......@@ -686,39 +688,45 @@ class SmallOrderedHashTable : public HeapObject {
return data_table_start + data_table_size;
}
int Size() { return Size(Capacity()); }
int Size() const { return Size(Capacity()); }
void SetFirstEntry(int bucket, byte value) {
set(kBucketsStartOffset + bucket, value);
}
int GetFirstEntry(int bucket) { return get(kBucketsStartOffset + bucket); }
int GetFirstEntry(int bucket) const {
return get(kBucketsStartOffset + bucket);
}
void SetNextEntry(int entry, int next_entry) {
set(GetChainTableOffset() + entry, next_entry);
}
int GetNextEntry(int entry) { return get(GetChainTableOffset() + entry); }
int GetNextEntry(int entry) const {
return get(GetChainTableOffset() + entry);
}
Object* GetDataEntry(int entry, int relative_index) {
int entry_offset = GetDataEntryOffset(entry, relative_index);
return READ_FIELD(this, entry_offset);
}
Object* KeyAt(int entry) {
Object* KeyAt(int entry) const {
int entry_offset = GetDataEntryOffset(entry, Derived::kKeyIndex);
return READ_FIELD(this, entry_offset);
}
int HashToBucket(int hash) { return hash & (NumberOfBuckets() - 1); }
int HashToBucket(int hash) const { return hash & (NumberOfBuckets() - 1); }
int HashToFirstEntry(int hash) {
int HashToFirstEntry(int hash) const {
int bucket = HashToBucket(hash);
int entry = GetFirstEntry(bucket);
return entry;
}
int GetChainTableOffset() { return kBucketsStartOffset + NumberOfBuckets(); }
int GetChainTableOffset() const {
return kBucketsStartOffset + NumberOfBuckets();
}
void SetNumberOfBuckets(int num) { set(kNumberOfBucketsOffset, num); }
......@@ -728,11 +736,13 @@ class SmallOrderedHashTable : public HeapObject {
set(kNumberOfDeletedElementsOffset, num);
}
int NumberOfElements() { return get(kNumberOfElementsOffset); }
int NumberOfElements() const { return get(kNumberOfElementsOffset); }
int NumberOfDeletedElements() { return get(kNumberOfDeletedElementsOffset); }
int NumberOfDeletedElements() const {
return get(kNumberOfDeletedElementsOffset);
}
int NumberOfBuckets() { return get(kNumberOfBucketsOffset); }
int NumberOfBuckets() const { return get(kNumberOfBucketsOffset); }
static const byte kNotFound = 0xFF;
static const int kMinCapacity = 4;
......@@ -768,7 +778,7 @@ class SmallOrderedHashTable : public HeapObject {
protected:
// This is used for accessing the non |DataTable| part of the
// structure.
byte get(int index) {
byte get(int index) const {
return READ_BYTE_FIELD(this, kHeaderSize + (index * kOneByteSize));
}
......@@ -776,7 +786,7 @@ class SmallOrderedHashTable : public HeapObject {
WRITE_BYTE_FIELD(this, kHeaderSize + (index * kOneByteSize), value);
}
int GetDataEntryOffset(int entry, int relative_index) {
int GetDataEntryOffset(int entry, int relative_index) const {
int datatable_start = GetDataTableStartOffset();
int offset_in_datatable = entry * Derived::kEntrySize * kPointerSize;
int offset_in_entry = relative_index * kPointerSize;
......@@ -784,9 +794,11 @@ class SmallOrderedHashTable : public HeapObject {
}
// Returns the number elements that can fit into the allocated buffer.
int Capacity() { return NumberOfBuckets() * kLoadFactor; }
int Capacity() const { return NumberOfBuckets() * kLoadFactor; }
int UsedCapacity() { return NumberOfElements() + NumberOfDeletedElements(); }
int UsedCapacity() const {
return NumberOfElements() + NumberOfDeletedElements();
}
};
class SmallOrderedHashSet : public SmallOrderedHashTable<SmallOrderedHashSet> {
......
This diff is collapsed.
......@@ -248,7 +248,7 @@
#define RELAXED_READ_BYTE_FIELD(p, offset) \
static_cast<byte>(base::Relaxed_Load( \
reinterpret_cast<base::Atomic8*>(FIELD_ADDR(p, offset))))
reinterpret_cast<const base::Atomic8*>(FIELD_ADDR_CONST(p, offset))))
#define WRITE_BYTE_FIELD(p, offset, value) \
(*reinterpret_cast<byte*>(FIELD_ADDR(p, offset)) = value)
......
......@@ -181,7 +181,7 @@ Map* TransitionArray::SearchTransition(Map* map, PropertyKind kind, Name* name,
// static
Map* TransitionArray::SearchSpecial(Map* map, Symbol* name) {
Map* TransitionArray::SearchSpecial(const Map* map, Symbol* name) {
Object* raw_transitions = map->raw_transitions();
if (IsFullTransitionArray(raw_transitions)) {
TransitionArray* transitions = TransitionArray::cast(raw_transitions);
......
......@@ -51,7 +51,7 @@ class TransitionArray: public FixedArray {
return MaybeHandle<Map>();
}
static Map* SearchSpecial(Map* map, Symbol* name);
static Map* SearchSpecial(const Map* map, Symbol* name);
static Handle<Map> FindTransitionToField(Handle<Map> map, Handle<Name> name);
......
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