Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(147)

Unified Diff: src/heap-inl.h

Issue 253293003: Replace heap object access macros with functions and move them to the heap class (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Switched to V8_INLINE, rebase Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/heap.h ('k') | src/objects-inl.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/heap-inl.h
diff --git a/src/heap-inl.h b/src/heap-inl.h
index a728777df19b9b93d196320807fa56118d60991a..d747ef2694fd44e40caa8af2781ee21752597e68 100644
--- a/src/heap-inl.h
+++ b/src/heap-inl.h
@@ -178,6 +178,173 @@ MaybeObject* Heap::CopyConstantPoolArray(ConstantPoolArray* src) {
}
+#define FIELD_ADDR(p, offset) \
+ (reinterpret_cast<byte*>(p) + offset - kHeapObjectTag)
+
+
+Object* Heap::read_field(HeapObject* p, int offset) {
+ return *reinterpret_cast<Object**>(FIELD_ADDR(p, offset));
+}
+
+
+intptr_t Heap::read_intptr_field(HeapObject* p, int offset) {
+ return *reinterpret_cast<intptr_t*>(FIELD_ADDR(p, offset));
+}
+
+
+int Heap::read_int_field(HeapObject* p, int offset) {
+ return *reinterpret_cast<int*>(FIELD_ADDR(p, offset));
+}
+
+
+int32_t Heap::read_int32_field(HeapObject* p, int offset) {
+ return *reinterpret_cast<int32_t*>(FIELD_ADDR(p, offset));
+}
+
+
+uint32_t Heap::read_uint32_field(HeapObject* p, int offset) {
+ return *reinterpret_cast<uint32_t*>(FIELD_ADDR(p, offset));
+}
+
+
+int64_t Heap::read_int64_field(HeapObject* p, int offset) {
+ return *reinterpret_cast<int64_t*>(FIELD_ADDR(p, offset));
+}
+
+
+int16_t Heap::read_short_field(HeapObject* p, int offset) {
+ return *reinterpret_cast<int16_t*>(FIELD_ADDR(p, offset));
+}
+
+
+byte Heap::read_byte_field(HeapObject* p, int offset) {
+ return *reinterpret_cast<byte*>(FIELD_ADDR(p, offset));
+}
+
+
+double Heap::read_double_field(HeapObject* p, int offset) {
+#ifndef V8_TARGET_ARCH_MIPS
+ return *reinterpret_cast<double*>(FIELD_ADDR(p, offset));
+#else // V8_TARGET_ARCH_MIPS
+ // Prevent gcc from using load-double (mips ldc1) on (possibly)
+ // non-64-bit aligned HeapNumber::value.
+ union conversion {
+ double d;
+ uint32_t u[2];
+ } c;
+ c.u[0] = (*reinterpret_cast<uint32_t*>(FIELD_ADDR(p, offset)));
+ c.u[1] = (*reinterpret_cast<uint32_t*>(FIELD_ADDR(p, offset + 4)));
+ return c.d;
+#endif // V8_TARGET_ARCH_MIPS
+}
+
+
+void Heap::write_field(HeapObject* p,
+ int offset,
+ Object* value,
+ WriteBarrierMode mode) {
+ *reinterpret_cast<Object**>(FIELD_ADDR(p, offset)) = value;
+ if (mode == UPDATE_WRITE_BARRIER) {
+ Heap* heap = p->GetHeap();
+ heap->incremental_marking()->RecordWrite(
+ p, HeapObject::RawField(p, offset), value);
+ if (heap->InNewSpace(value)) {
+ heap->RecordWrite(p->address(), offset);
+ }
+ }
+}
+
+void Heap::write_intptr_field(HeapObject* p,
+ int offset,
+ intptr_t value) {
+ *reinterpret_cast<intptr_t*>(FIELD_ADDR(p, offset)) = value;
+}
+
+void Heap::write_int_field(HeapObject* p, int offset, int value) {
+ *reinterpret_cast<int*>(FIELD_ADDR(p, offset)) = value;
+}
+
+void Heap::write_int32_field(HeapObject* p, int offset, int32_t value) {
+ *reinterpret_cast<int32_t*>(FIELD_ADDR(p, offset)) = value;
+}
+
+void Heap::write_uint32_field(HeapObject* p,
+ int offset,
+ uint32_t value) {
+ *reinterpret_cast<uint32_t*>(FIELD_ADDR(p, offset)) = value;
+}
+
+void Heap::write_int64_field(HeapObject* p, int offset, int64_t value) {
+ *reinterpret_cast<int64_t*>(FIELD_ADDR(p, offset)) = value;
+}
+
+void Heap::write_short_field(HeapObject* p, int offset, int16_t value) {
+ *reinterpret_cast<int16_t*>(FIELD_ADDR(p, offset)) = value;
+}
+
+void Heap::write_byte_field(HeapObject* p, int offset, byte value) {
+ *reinterpret_cast<byte*>(FIELD_ADDR(p, offset)) = value;
+}
+
+void Heap::write_double_field(HeapObject* p, int offset, double value) {
+#ifndef V8_TARGET_ARCH_MIPS
+ *reinterpret_cast<double*>(FIELD_ADDR(p, offset)) = value;
+#else // V8_TARGET_ARCH_MIPS
+ // Prevent gcc from using store-double (mips sdc1) on (possibly)
+ // non-64-bit aligned HeapNumber::value.
+ union conversion {
+ double d;
+ uint32_t u[2];
+ } c;
+ c.d = value;
+ (*reinterpret_cast<uint32_t*>(FIELD_ADDR(p, offset))) = c.u[0];
+ (*reinterpret_cast<uint32_t*>(FIELD_ADDR(p, offset + 4))) = c.u[1];
+#endif // V8_TARGET_ARCH_MIPS
+}
+
+Address Heap::get_field_address(HeapObject* p, int offset) {
+ return reinterpret_cast<Address>(FIELD_ADDR(p, offset));
+}
+
+Object* Heap::acquire_read_field(HeapObject* p, int offset) {
+ return reinterpret_cast<Object*>(
+ Acquire_Load(reinterpret_cast<AtomicWord*>(FIELD_ADDR(p, offset))));
+}
+
+Object* Heap::nobarrier_read_field(HeapObject* p, int offset) {
+ return reinterpret_cast<Object*>(
+ NoBarrier_Load(reinterpret_cast<AtomicWord*>(FIELD_ADDR(p, offset))));
+}
+
+void Heap::release_write_field(HeapObject* p,
+ int offset,
+ Object* value) {
+ Release_Store(reinterpret_cast<AtomicWord*>(FIELD_ADDR(p, offset)),
+ reinterpret_cast<AtomicWord>(value));
+}
+
+void Heap::nobarrier_write_field(HeapObject* p,
+ int offset,
+ Object* value) {
+ NoBarrier_Store(reinterpret_cast<AtomicWord*>(FIELD_ADDR(p, offset)),
+ reinterpret_cast<AtomicWord>(value));
+}
+
+byte Heap::nobarrier_read_byte_field(HeapObject* p, int offset) {
+ return static_cast<byte>(NoBarrier_Load(
+ reinterpret_cast<Atomic8*>(FIELD_ADDR(p, offset))));
+}
+
+void Heap::nobarrier_write_byte_field(HeapObject* p,
+ int offset,
+ byte value) {
+ NoBarrier_Store(reinterpret_cast<Atomic8*>(FIELD_ADDR(p, offset)),
+ static_cast<Atomic8>(value));
+}
+
+#undef FIELD_ADDR
+
+
MaybeObject* Heap::AllocateRaw(int size_in_bytes,
AllocationSpace space,
AllocationSpace retry_space) {
@@ -441,11 +608,6 @@ void Heap::MoveBlock(Address dst, Address src, int byte_size) {
}
-void Heap::ScavengePointer(HeapObject** p) {
- ScavengeObject(p, *p);
-}
-
-
AllocationMemento* Heap::FindAllocationMemento(HeapObject* object) {
// Check if there is potentially a memento behind the object. If
// the last word of the momento is on another page we return
« no previous file with comments | « src/heap.h ('k') | src/objects-inl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698