Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2012 Google Inc. All Rights Reserved. | |
| 2 // Author: nricci@google.com (Nathan Ricci) | |
|
siva
2012/12/05 16:06:40
This copyright doesn't seem to be standard.
cshapiro
2012/12/08 03:23:08
It is standard, but not the standard we use. Fixe
| |
| 3 | |
| 4 #ifndef VM_HEAP_TRACE_H_ | |
| 5 #define VM_HEAP_TRACE_H_ | |
| 6 | |
| 7 #include "include/dart_api.h" | |
|
siva
2012/12/05 16:06:40
blank line.
cshapiro
2012/12/08 03:23:08
Done.
| |
| 8 #include "vm/globals.h" | |
| 9 #include "vm/object_set.h" | |
| 10 | |
| 11 namespace dart { | |
| 12 | |
| 13 // Forward declarations. | |
| 14 class HeapTraceVisitor; | |
| 15 class Isolate; | |
| 16 class RawClass; | |
| 17 class RawObject; | |
| 18 class RawString; | |
| 19 class BaseZone; | |
| 20 | |
| 21 class HeapTrace { | |
| 22 public: | |
| 23 enum RecordSize { | |
| 24 kRootSize = 5, | |
| 25 kAllocSize = 9, | |
| 26 kSnapshotAllocSize = 9, | |
| 27 kCopySize = 9, | |
| 28 kStoreSize = 13, | |
| 29 kSweepSize = 5, | |
| 30 kDeathRangeSize = 9, | |
| 31 kPromotionSize = 9, | |
| 32 kAllocZoneHandleSize = 9, | |
| 33 kDeleteZoneSize = 5, | |
| 34 kRegisterClassSize = 5, | |
| 35 kAllocScopedHandleSize = 5, | |
| 36 kDeleteScopedHandlesSize = 1, | |
| 37 kMarkSweepStartSize = 1, | |
| 38 kMarkSweepFinishSize = 1, | |
| 39 kObjectStoreSize = 5 | |
| 40 }; | |
|
siva
2012/12/05 16:06:40
These constants don't seem to be an increasing seq
cshapiro
2012/12/08 03:23:08
I think the enum makes it a bit more descriptive w
| |
| 41 | |
| 42 enum RecordType { | |
| 43 kRootType = 'R', | |
| 44 kAllocType = 'A', | |
| 45 kSnapshotAllocType = 'B', | |
| 46 kCopyType = 'C', | |
| 47 kStoreType = 'U', | |
| 48 kSweepType = 'S', | |
| 49 kDeathRangeType = 'L', | |
| 50 kPromotionType = 'P', | |
| 51 kAllocZoneHandleType = 'Z', | |
| 52 kDeleteZoneType = 'z', | |
| 53 kRegisterClassType = 'K', | |
| 54 kAllocScopedHandleType = 'H', | |
| 55 kDeleteScopedHandlesType = 'h', | |
| 56 kMarkSweepStartType = '{', | |
| 57 kMarkSweepFinishType = '}', | |
| 58 kObjectStoreType = 'O' | |
| 59 }; | |
|
siva
2012/12/05 16:06:40
Ditto.
| |
| 60 | |
| 61 template <RecordType T, RecordSize N> | |
| 62 class Record { | |
| 63 public: | |
| 64 explicit Record(HeapTrace* trace): cursor_(0), trace_(trace) { | |
| 65 ASSERT(N >= 1); | |
| 66 buffer_[0] = T; | |
| 67 ++cursor_; | |
| 68 } | |
| 69 ~Record() { | |
| 70 (*trace_->write_callback_)(Buffer(), Length(), trace_->output_stream_); | |
| 71 } | |
| 72 | |
| 73 void Write(uword word) { | |
| 74 ASSERT(cursor_ + sizeof(word) <= N); | |
| 75 memmove(&buffer_[cursor_], &word, sizeof(word)); | |
| 76 cursor_ += sizeof(word); | |
| 77 } | |
| 78 | |
| 79 intptr_t Length() { return cursor_; } | |
|
siva
2012/12/05 16:06:40
intptr_t Length() const { ... }
cshapiro
2012/12/08 03:23:08
Done.
| |
| 80 | |
| 81 const uint8_t* Buffer() { | |
|
siva
2012/12/05 16:06:40
Ditto.
cshapiro
2012/12/08 03:23:08
Done.
| |
| 82 ASSERT(cursor_ == N); | |
| 83 return buffer_; | |
| 84 } | |
| 85 | |
| 86 private: | |
| 87 uint8_t buffer_[N]; | |
| 88 intptr_t cursor_; | |
| 89 HeapTrace* trace_; | |
|
siva
2012/12/05 16:06:40
Missing DISALLOW stuff?
cshapiro
2012/12/08 03:23:08
Done.
| |
| 90 }; | |
| 91 | |
| 92 typedef Record<kRootType, kRootSize> RootRecord; | |
| 93 typedef Record<kAllocType, kAllocSize> AllocationRecord; | |
| 94 typedef Record<kSnapshotAllocType, kSnapshotAllocSize> | |
| 95 SnapshotAllocationRecord; | |
| 96 typedef Record<kCopyType, kCopySize> CopyRecord; | |
| 97 typedef Record<kStoreType, kStoreSize> StoreRecord; | |
| 98 typedef Record<kSweepType, kSweepSize> SweepRecord; | |
| 99 typedef Record<kDeathRangeType, kDeathRangeSize> DeathRangeRecord; | |
| 100 typedef Record<kPromotionType, kPromotionSize> PromotionRecord; | |
| 101 typedef Record<kAllocZoneHandleType, kAllocZoneHandleSize> | |
| 102 AllocZoneHandleRecord; | |
| 103 typedef Record<kDeleteZoneType, kDeleteZoneSize> | |
| 104 DeleteZoneRecord; | |
| 105 typedef Record<kRegisterClassType, kRegisterClassSize> RegisterClassRecord; | |
| 106 typedef Record<kAllocScopedHandleType, kAllocScopedHandleSize> | |
| 107 AllocScopedHandleRecord; | |
| 108 typedef Record<kDeleteScopedHandlesType, kDeleteScopedHandlesSize> | |
| 109 DeleteScopedHandlesRecord; | |
| 110 typedef Record<kMarkSweepStartType, kMarkSweepStartSize> MarkSweepStartRecord; | |
| 111 typedef Record<kMarkSweepFinishType, kMarkSweepFinishSize> | |
| 112 MarkSweepFinishRecord; | |
| 113 typedef Record<kObjectStoreType, kObjectStoreSize> ObjectStoreRecord; | |
| 114 | |
| 115 HeapTrace(); | |
| 116 ~HeapTrace(); | |
| 117 | |
| 118 // Called by the isoalte just before EnableGrowthControl. | |
| 119 // Indicates the Isolate is initialized and enables tracing. | |
| 120 void InitializeIsolateTracing(Isolate* isolate); | |
| 121 | |
| 122 // Called when an object is allocated in the heap. | |
| 123 void TraceAllocation(uword addr, intptr_t size); | |
| 124 | |
| 125 // Invoked after the snapshot is loaded at Isoalte startup time. | |
| 126 void TraceSnapshotAlloc(RawObject* obj, intptr_t size); | |
| 127 | |
| 128 // Rename to something like TraceAllocateZoneHandle (or whatever) | |
| 129 void TraceAllocateZoneHandle(uword handle, uword zone_addr); | |
| 130 | |
| 131 // Invoked when a Zone block is deleted. | |
| 132 void TraceDeleteZone(Zone* zone); | |
| 133 | |
| 134 // Invoked whenever the scoped handles are delelted. | |
| 135 void TraceDeleteScopedHandles(); | |
| 136 | |
| 137 // Invoked when objects are coped from the from space to the to space | |
| 138 // by the scavenger. | |
| 139 void TraceCopy(uword old_addr, uword forwarding_addr); | |
| 140 | |
| 141 // Invoked on each pointer in the object store. | |
| 142 void TraceObjectStorePointer(uword addr); | |
| 143 | |
| 144 // Invoked when an object is promoted from the new space to the old space. | |
| 145 void TracePromotion(uword old_addr, uword promoted_addr); | |
| 146 | |
| 147 // Invoked after a scavenge with the addressed range of from-space | |
| 148 void TraceDeathRange(uword inclusive_start, uword exclusive_end); | |
| 149 | |
| 150 // Invoked whenever a class is registered in the class table. | |
| 151 void TraceRegisterClass(RawClass* klass); | |
| 152 | |
| 153 // Invoked when an address is swept. | |
| 154 void TraceSweep(uword sweept_addr); | |
| 155 | |
| 156 // Invoked when storing value into origin, and value is an object. | |
| 157 void TraceStoreIntoObject(uword origin_object_addr, | |
| 158 uword slot_addr, | |
| 159 uword value); | |
| 160 | |
| 161 // Invoked when starting a mark-sweep collection on old space | |
| 162 void TraceMarkSweepStart(); | |
| 163 | |
| 164 // Invoked after finishing a mark sweep collection on old space. | |
| 165 void TraceMarkSweepFinish(); | |
| 166 | |
| 167 // Initialize tracing globablly across the VM. Invidual isolates | |
| 168 // will still have to initialized themselves when they are started. | |
| 169 static void InitTracing(Dart_FileOpenCallback open_callback, | |
| 170 Dart_FileWriteCallback write_callback, | |
| 171 Dart_FileCloseCallback close_callback, | |
| 172 const char* prefix); | |
| 173 | |
| 174 // Returns true if tracign is enabled for the VM. | |
| 175 static bool is_enabled() { return tracing_enabled_; } | |
| 176 | |
| 177 private: | |
| 178 ObjectSet* CreateEmptyObjectSet() const; | |
| 179 void ResizeObjectSet(); | |
| 180 | |
| 181 void TraceScopedHandle(uword handle); | |
| 182 | |
| 183 // A helper for PutRoots, called by HeapTraceVisitor. | |
| 184 void TraceSingleRoot(uword root); | |
| 185 | |
| 186 // Invoked while tracing an allocation. | |
| 187 void TraceRoots(Isolate* isolate); | |
| 188 | |
| 189 // Is the isoalte we are tracing initialized? | |
| 190 bool isolate_initialized_; | |
| 191 | |
| 192 void* output_stream_; | |
| 193 | |
| 194 ObjectSet object_set_; | |
| 195 | |
| 196 static Dart_FileOpenCallback open_callback_; | |
| 197 static Dart_FileWriteCallback write_callback_; | |
| 198 static Dart_FileCloseCallback close_callback_; | |
| 199 | |
| 200 static bool tracing_enabled_; | |
| 201 static const char* file_name_prefix_; | |
| 202 | |
| 203 friend class HeapTraceVisitor; | |
| 204 friend class HeapTraceScopedHandleVisitor; | |
| 205 friend class HeapTraceObjectStoreVisitor; | |
| 206 friend class HeapTraceDebugObjectVisitor; | |
| 207 | |
| 208 DISALLOW_COPY_AND_ASSIGN(HeapTrace); | |
| 209 }; | |
| 210 | |
| 211 } // namespace dart | |
| 212 | |
| 213 #endif // VM_HEAP_TRACE_H_ | |
| OLD | NEW |