Commit f2796382 authored by mstarzinger's avatar mstarzinger Committed by Commit bot

Make heap.h usable without objects-inl.h header.

This CL us a pure refactoring that makes an empty compilation unit
including just "heap.h" but not "objects-inl.h" compile without
warnings or errors. This is needed to further reduce the header
dependency tangle.

R=mlippautz@chromium.org

Review URL: https://codereview.chromium.org/1301583003

Cr-Commit-Position: refs/heads/master@{#30227}
parent f36cc258
...@@ -46,6 +46,44 @@ void PromotionQueue::insert(HeapObject* target, int size) { ...@@ -46,6 +46,44 @@ void PromotionQueue::insert(HeapObject* target, int size) {
} }
#define ROOT_ACCESSOR(type, name, camel_name) \
type* Heap::name() { return type::cast(roots_[k##camel_name##RootIndex]); }
ROOT_LIST(ROOT_ACCESSOR)
#undef ROOT_ACCESSOR
#define STRUCT_MAP_ACCESSOR(NAME, Name, name) \
Map* Heap::name##_map() { return Map::cast(roots_[k##Name##MapRootIndex]); }
STRUCT_LIST(STRUCT_MAP_ACCESSOR)
#undef STRUCT_MAP_ACCESSOR
#define STRING_ACCESSOR(name, str) \
String* Heap::name() { return String::cast(roots_[k##name##RootIndex]); }
INTERNALIZED_STRING_LIST(STRING_ACCESSOR)
#undef STRING_ACCESSOR
#define SYMBOL_ACCESSOR(name) \
Symbol* Heap::name() { return Symbol::cast(roots_[k##name##RootIndex]); }
PRIVATE_SYMBOL_LIST(SYMBOL_ACCESSOR)
#undef SYMBOL_ACCESSOR
#define SYMBOL_ACCESSOR(name, varname, description) \
Symbol* Heap::name() { return Symbol::cast(roots_[k##name##RootIndex]); }
PUBLIC_SYMBOL_LIST(SYMBOL_ACCESSOR)
#undef SYMBOL_ACCESSOR
#define ROOT_ACCESSOR(type, name, camel_name) \
void Heap::set_##name(type* value) { \
/* The deserializer makes use of the fact that these common roots are */ \
/* never in new space and never on a page that is being compacted. */ \
DCHECK(!deserialization_complete() || \
RootCanBeWrittenAfterInitialization(k##camel_name##RootIndex)); \
DCHECK(k##camel_name##RootIndex >= kOldSpaceRoots || !InNewSpace(value)); \
roots_[k##camel_name##RootIndex] = value; \
}
ROOT_LIST(ROOT_ACCESSOR)
#undef ROOT_ACCESSOR
template <> template <>
bool inline Heap::IsOneByte(Vector<const char> str, int chars) { bool inline Heap::IsOneByte(Vector<const char> str, int chars) {
// TODO(dcarney): incorporate Latin-1 check when Latin-1 is supported? // TODO(dcarney): incorporate Latin-1 check when Latin-1 is supported?
...@@ -670,6 +708,46 @@ void Heap::CompletelyClearInstanceofCache() { ...@@ -670,6 +708,46 @@ void Heap::CompletelyClearInstanceofCache() {
} }
uint32_t Heap::HashSeed() {
uint32_t seed = static_cast<uint32_t>(hash_seed()->value());
DCHECK(FLAG_randomize_hashes || seed == 0);
return seed;
}
Smi* Heap::NextScriptId() {
int next_id = last_script_id()->value() + 1;
if (!Smi::IsValid(next_id) || next_id < 0) next_id = 1;
Smi* next_id_smi = Smi::FromInt(next_id);
set_last_script_id(next_id_smi);
return next_id_smi;
}
void Heap::SetArgumentsAdaptorDeoptPCOffset(int pc_offset) {
DCHECK(arguments_adaptor_deopt_pc_offset() == Smi::FromInt(0));
set_arguments_adaptor_deopt_pc_offset(Smi::FromInt(pc_offset));
}
void Heap::SetConstructStubDeoptPCOffset(int pc_offset) {
DCHECK(construct_stub_deopt_pc_offset() == Smi::FromInt(0));
set_construct_stub_deopt_pc_offset(Smi::FromInt(pc_offset));
}
void Heap::SetGetterStubDeoptPCOffset(int pc_offset) {
DCHECK(getter_stub_deopt_pc_offset() == Smi::FromInt(0));
set_getter_stub_deopt_pc_offset(Smi::FromInt(pc_offset));
}
void Heap::SetSetterStubDeoptPCOffset(int pc_offset) {
DCHECK(setter_stub_deopt_pc_offset() == Smi::FromInt(0));
set_setter_stub_deopt_pc_offset(Smi::FromInt(pc_offset));
}
AlwaysAllocateScope::AlwaysAllocateScope(Isolate* isolate) AlwaysAllocateScope::AlwaysAllocateScope(Isolate* isolate)
: heap_(isolate->heap()), daf_(isolate) { : heap_(isolate->heap()), daf_(isolate) {
heap_->always_allocate_scope_depth_++; heap_->always_allocate_scope_depth_++;
......
...@@ -2517,7 +2517,7 @@ class ScavengingVisitor : public StaticVisitorBase { ...@@ -2517,7 +2517,7 @@ class ScavengingVisitor : public StaticVisitorBase {
return; return;
} }
heap->DoScavengeObject(first->map(), slot, first); Heap::ScavengeObjectSlow(slot, first);
object->set_map_word(MapWord::FromForwardingAddress(*slot)); object->set_map_word(MapWord::FromForwardingAddress(*slot));
return; return;
} }
...@@ -2607,7 +2607,7 @@ void Heap::ScavengeObjectSlow(HeapObject** p, HeapObject* object) { ...@@ -2607,7 +2607,7 @@ void Heap::ScavengeObjectSlow(HeapObject** p, HeapObject* object) {
MapWord first_word = object->map_word(); MapWord first_word = object->map_word();
SLOW_DCHECK(!first_word.IsForwardingAddress()); SLOW_DCHECK(!first_word.IsForwardingAddress());
Map* map = first_word.ToMap(); Map* map = first_word.ToMap();
map->GetHeap()->DoScavengeObject(map, p, object); map->GetHeap()->scavenging_visitors_table_.GetVisitor(map)(map, p, object);
} }
......
...@@ -894,32 +894,28 @@ class Heap { ...@@ -894,32 +894,28 @@ class Heap {
// You can't use type::cast during GC because the assert fails. // You can't use type::cast during GC because the assert fails.
// TODO(1490): Try removing the unchecked accessors, now that GC marking does // TODO(1490): Try removing the unchecked accessors, now that GC marking does
// not corrupt the map. // not corrupt the map.
#define ROOT_ACCESSOR(type, name, camel_name) \ #define ROOT_ACCESSOR(type, name, camel_name) \
type* name() { return type::cast(roots_[k##camel_name##RootIndex]); } \ inline type* name(); \
type* raw_unchecked_##name() { \ type* raw_unchecked_##name() { \
return reinterpret_cast<type*>(roots_[k##camel_name##RootIndex]); \ return reinterpret_cast<type*>(roots_[k##camel_name##RootIndex]); \
} }
ROOT_LIST(ROOT_ACCESSOR) ROOT_LIST(ROOT_ACCESSOR)
#undef ROOT_ACCESSOR #undef ROOT_ACCESSOR
// Utility type maps // Utility type maps
#define STRUCT_MAP_ACCESSOR(NAME, Name, name) \ #define STRUCT_MAP_ACCESSOR(NAME, Name, name) inline Map* name##_map();
Map* name##_map() { return Map::cast(roots_[k##Name##MapRootIndex]); }
STRUCT_LIST(STRUCT_MAP_ACCESSOR) STRUCT_LIST(STRUCT_MAP_ACCESSOR)
#undef STRUCT_MAP_ACCESSOR #undef STRUCT_MAP_ACCESSOR
#define STRING_ACCESSOR(name, str) \ #define STRING_ACCESSOR(name, str) inline String* name();
String* name() { return String::cast(roots_[k##name##RootIndex]); }
INTERNALIZED_STRING_LIST(STRING_ACCESSOR) INTERNALIZED_STRING_LIST(STRING_ACCESSOR)
#undef STRING_ACCESSOR #undef STRING_ACCESSOR
#define SYMBOL_ACCESSOR(name) \ #define SYMBOL_ACCESSOR(name) inline Symbol* name();
Symbol* name() { return Symbol::cast(roots_[k##name##RootIndex]); }
PRIVATE_SYMBOL_LIST(SYMBOL_ACCESSOR) PRIVATE_SYMBOL_LIST(SYMBOL_ACCESSOR)
#undef SYMBOL_ACCESSOR #undef SYMBOL_ACCESSOR
#define SYMBOL_ACCESSOR(name, varname, description) \ #define SYMBOL_ACCESSOR(name, varname, description) inline Symbol* name();
Symbol* name() { return Symbol::cast(roots_[k##name##RootIndex]); }
PUBLIC_SYMBOL_LIST(SYMBOL_ACCESSOR) PUBLIC_SYMBOL_LIST(SYMBOL_ACCESSOR)
#undef SYMBOL_ACCESSOR #undef SYMBOL_ACCESSOR
...@@ -1101,6 +1097,9 @@ class Heap { ...@@ -1101,6 +1097,9 @@ class Heap {
static inline void ScavengePointer(HeapObject** p); static inline void ScavengePointer(HeapObject** p);
static inline void ScavengeObject(HeapObject** p, HeapObject* object); static inline void ScavengeObject(HeapObject** p, HeapObject* object);
// Slow part of scavenge object.
static void ScavengeObjectSlow(HeapObject** p, HeapObject* object);
enum ScratchpadSlotMode { IGNORE_SCRATCHPAD_SLOT, RECORD_SCRATCHPAD_SLOT }; enum ScratchpadSlotMode { IGNORE_SCRATCHPAD_SLOT, RECORD_SCRATCHPAD_SLOT };
// If an object has an AllocationMemento trailing it, return it, otherwise // If an object has an AllocationMemento trailing it, return it, otherwise
...@@ -1432,10 +1431,6 @@ class Heap { ...@@ -1432,10 +1431,6 @@ class Heap {
inline bool OldGenerationAllocationLimitReached(); inline bool OldGenerationAllocationLimitReached();
inline void DoScavengeObject(Map* map, HeapObject** slot, HeapObject* obj) {
scavenging_visitors_table_.GetVisitor(map)(map, slot, obj);
}
void QueueMemoryChunkForFree(MemoryChunk* chunk); void QueueMemoryChunkForFree(MemoryChunk* chunk);
void FreeQueuedChunks(); void FreeQueuedChunks();
...@@ -1450,39 +1445,14 @@ class Heap { ...@@ -1450,39 +1445,14 @@ class Heap {
// The roots that have an index less than this are always in old space. // The roots that have an index less than this are always in old space.
static const int kOldSpaceRoots = 0x20; static const int kOldSpaceRoots = 0x20;
uint32_t HashSeed() { inline uint32_t HashSeed();
uint32_t seed = static_cast<uint32_t>(hash_seed()->value());
DCHECK(FLAG_randomize_hashes || seed == 0);
return seed;
}
Smi* NextScriptId() {
int next_id = last_script_id()->value() + 1;
if (!Smi::IsValid(next_id) || next_id < 0) next_id = 1;
Smi* next_id_smi = Smi::FromInt(next_id);
set_last_script_id(next_id_smi);
return next_id_smi;
}
void SetArgumentsAdaptorDeoptPCOffset(int pc_offset) {
DCHECK(arguments_adaptor_deopt_pc_offset() == Smi::FromInt(0));
set_arguments_adaptor_deopt_pc_offset(Smi::FromInt(pc_offset));
}
void SetConstructStubDeoptPCOffset(int pc_offset) { inline Smi* NextScriptId();
DCHECK(construct_stub_deopt_pc_offset() == Smi::FromInt(0));
set_construct_stub_deopt_pc_offset(Smi::FromInt(pc_offset));
}
void SetGetterStubDeoptPCOffset(int pc_offset) { inline void SetArgumentsAdaptorDeoptPCOffset(int pc_offset);
DCHECK(getter_stub_deopt_pc_offset() == Smi::FromInt(0)); inline void SetConstructStubDeoptPCOffset(int pc_offset);
set_getter_stub_deopt_pc_offset(Smi::FromInt(pc_offset)); inline void SetGetterStubDeoptPCOffset(int pc_offset);
} inline void SetSetterStubDeoptPCOffset(int pc_offset);
void SetSetterStubDeoptPCOffset(int pc_offset) {
DCHECK(setter_stub_deopt_pc_offset() == Smi::FromInt(0));
set_setter_stub_deopt_pc_offset(Smi::FromInt(pc_offset));
}
// For post mortem debugging. // For post mortem debugging.
void RememberUnmappedPage(Address page, bool compacted); void RememberUnmappedPage(Address page, bool compacted);
...@@ -1779,15 +1749,8 @@ class Heap { ...@@ -1779,15 +1749,8 @@ class Heap {
// Total length of the strings we failed to flatten since the last GC. // Total length of the strings we failed to flatten since the last GC.
int unflattened_strings_length_; int unflattened_strings_length_;
#define ROOT_ACCESSOR(type, name, camel_name) \ #define ROOT_ACCESSOR(type, name, camel_name) \
inline void set_##name(type* value) { \ inline void set_##name(type* value);
/* The deserializer makes use of the fact that these common roots are */ \
/* never in new space and never on a page that is being compacted. */ \
DCHECK(!deserialization_complete() || \
RootCanBeWrittenAfterInitialization(k##camel_name##RootIndex)); \
DCHECK(k##camel_name##RootIndex >= kOldSpaceRoots || !InNewSpace(value)); \
roots_[k##camel_name##RootIndex] = value; \
}
ROOT_LIST(ROOT_ACCESSOR) ROOT_LIST(ROOT_ACCESSOR)
#undef ROOT_ACCESSOR #undef ROOT_ACCESSOR
...@@ -2142,9 +2105,6 @@ class Heap { ...@@ -2142,9 +2105,6 @@ class Heap {
void ReportStatisticsBeforeGC(); void ReportStatisticsBeforeGC();
void ReportStatisticsAfterGC(); void ReportStatisticsAfterGC();
// Slow part of scavenge object.
static void ScavengeObjectSlow(HeapObject** p, HeapObject* object);
// Total RegExp code ever generated // Total RegExp code ever generated
double total_regexp_code_generated_; double total_regexp_code_generated_;
......
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
#include "src/heap/identity-map.h" #include "src/heap/identity-map.h"
#include "src/heap/heap.h" #include "src/heap/heap.h"
#include "src/objects-inl.h" // TODO(mstarzinger): Temporary cycle breaker!
#include "src/zone-containers.h" #include "src/zone-containers.h"
namespace v8 { namespace v8 {
......
...@@ -12,6 +12,13 @@ ...@@ -12,6 +12,13 @@
namespace v8 { namespace v8 {
namespace internal { namespace internal {
template <typename Callback>
Callback VisitorDispatchTable<Callback>::GetVisitor(Map* map) {
return reinterpret_cast<Callback>(callbacks_[map->visitor_id()]);
}
template <typename StaticVisitor> template <typename StaticVisitor>
void StaticNewSpaceVisitor<StaticVisitor>::Initialize() { void StaticNewSpaceVisitor<StaticVisitor>::Initialize() {
table_.Register( table_.Register(
......
...@@ -148,14 +148,12 @@ class VisitorDispatchTable { ...@@ -148,14 +148,12 @@ class VisitorDispatchTable {
} }
} }
inline Callback GetVisitor(Map* map);
inline Callback GetVisitorById(StaticVisitorBase::VisitorId id) { inline Callback GetVisitorById(StaticVisitorBase::VisitorId id) {
return reinterpret_cast<Callback>(callbacks_[id]); return reinterpret_cast<Callback>(callbacks_[id]);
} }
inline Callback GetVisitor(Map* map) {
return reinterpret_cast<Callback>(callbacks_[map->visitor_id()]);
}
void Register(StaticVisitorBase::VisitorId id, Callback callback) { void Register(StaticVisitorBase::VisitorId id, Callback callback) {
DCHECK(id < StaticVisitorBase::kVisitorIdCount); // id is unsigned. DCHECK(id < StaticVisitorBase::kVisitorIdCount); // id is unsigned.
callbacks_[id] = reinterpret_cast<base::AtomicWord>(callback); callbacks_[id] = reinterpret_cast<base::AtomicWord>(callback);
......
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