V8 Project
heap-profiler.cc
Go to the documentation of this file.
1 // Copyright 2009-2010 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "src/v8.h"
6 
7 #include "src/heap-profiler.h"
8 
11 
12 namespace v8 {
13 namespace internal {
14 
16  : ids_(new HeapObjectsMap(heap)),
17  names_(new StringsStorage(heap)),
18  next_snapshot_uid_(1),
19  is_tracking_object_moves_(false) {
20 }
21 
22 
23 static void DeleteHeapSnapshot(HeapSnapshot** snapshot_ptr) {
24  delete *snapshot_ptr;
25 }
26 
27 
30  snapshots_.Clear();
31 }
32 
33 
36  snapshots_.Clear();
37  names_.Reset(new StringsStorage(heap()));
38 }
39 
40 
42  snapshots_.RemoveElement(snapshot);
43 }
44 
45 
49  if (wrapper_callbacks_.length() <= class_id) {
51  NULL, class_id - wrapper_callbacks_.length() + 1);
52  }
53  wrapper_callbacks_[class_id] = callback;
54 }
55 
56 
58  uint16_t class_id, Object** wrapper) {
59  if (wrapper_callbacks_.length() <= class_id) return NULL;
60  return wrapper_callbacks_[class_id](
61  class_id, Utils::ToLocal(Handle<Object>(wrapper)));
62 }
63 
64 
66  const char* name,
67  v8::ActivityControl* control,
69  HeapSnapshot* result = new HeapSnapshot(this, name, next_snapshot_uid_++);
70  {
71  HeapSnapshotGenerator generator(result, control, resolver, heap());
72  if (!generator.GenerateSnapshot()) {
73  delete result;
74  result = NULL;
75  } else {
76  snapshots_.Add(result);
77  }
78  }
79  ids_->RemoveDeadEntries();
81  return result;
82 }
83 
84 
86  String* name,
87  v8::ActivityControl* control,
89  return TakeSnapshot(names_->GetName(name), control, resolver);
90 }
91 
92 
93 void HeapProfiler::StartHeapObjectsTracking(bool track_allocations) {
94  ids_->UpdateHeapObjectsMap();
97  if (track_allocations) {
98  allocation_tracker_.Reset(new AllocationTracker(ids_.get(), names_.get()));
100  }
101 }
102 
103 
105  return ids_->PushHeapObjectsStats(stream);
106 }
107 
108 
110  ids_->StopHeapObjectsTracking();
111  if (is_tracking_allocations()) {
112  allocation_tracker_.Reset(NULL);
114  }
115 }
116 
117 
119  size_t size = sizeof(*this);
120  size += names_->GetUsedMemorySize();
121  size += ids_->GetUsedMemorySize();
123  for (int i = 0; i < snapshots_.length(); ++i) {
124  size += snapshots_[i]->RawSnapshotSize();
125  }
126  return size;
127 }
128 
129 
131  return snapshots_.length();
132 }
133 
134 
136  return snapshots_.at(index);
137 }
138 
139 
141  if (!obj->IsHeapObject())
143  return ids_->FindEntry(HeapObject::cast(*obj)->address());
144 }
145 
146 
148  bool known_object = ids_->MoveObject(from, to, size);
149  if (!known_object && !allocation_tracker_.is_empty()) {
150  allocation_tracker_->address_to_trace()->MoveObject(from, to, size);
151  }
152 }
153 
154 
156  DisallowHeapAllocation no_allocation;
157  if (!allocation_tracker_.is_empty()) {
158  allocation_tracker_->AllocationEvent(addr, size);
159  }
160 }
161 
162 
164  ids_->UpdateObjectSize(addr, size);
165 }
166 
167 
169  RetainedObjectInfo* info) {
170  // TODO(yurus, marja): Don't route this information through GlobalHandles.
172 }
173 
174 
176  HeapObject* object = NULL;
177  HeapIterator iterator(heap(), HeapIterator::kFilterUnreachable);
178  // Make sure that object with the given id is still reachable.
179  for (HeapObject* obj = iterator.next();
180  obj != NULL;
181  obj = iterator.next()) {
182  if (ids_->FindEntry(obj->address()) == id) {
183  DCHECK(object == NULL);
184  object = obj;
185  // Can't break -- kFilterUnreachable requires full heap traversal.
186  }
187  }
188  return object != NULL ? Handle<HeapObject>(object) : Handle<HeapObject>();
189 }
190 
191 
193  ids_.Reset(new HeapObjectsMap(heap()));
195 }
196 
197 
198 } } // namespace v8::internal
An interface for reporting progress and controlling long-running activities.
Definition: v8-profiler.h:371
Callback interface for retrieving user friendly names of global objects.
Definition: v8-profiler.h:436
static const uint16_t kPersistentHandleNoClassId
Default value of persistent handle class ID.
Definition: v8-profiler.h:503
RetainedObjectInfo *(* WrapperInfoCallback)(uint16_t class_id, Handle< Value > wrapper)
Callback function invoked for obtaining RetainedObjectInfo for the given JavaScript wrapper object.
Definition: v8-profiler.h:399
static const SnapshotObjectId kUnknownObjectId
A constant for invalid SnapshotObjectId.
Definition: v8-profiler.h:431
An interface for exporting data from V8, using "push" model.
Definition: v8-profiler.h:272
Interface for providing information about embedder's objects held by global handles.
Definition: v8-profiler.h:545
General purpose unique identifier.
Definition: v8.h:144
static Local< Context > ToLocal(v8::internal::Handle< v8::internal::Context > obj)
void SetRetainedObjectInfo(UniqueId id, RetainedObjectInfo *info)
HeapSnapshot * TakeSnapshot(const char *name, v8::ActivityControl *control, v8::HeapProfiler::ObjectNameResolver *resolver)
SmartPointer< HeapObjectsMap > ids_
Definition: heap-profiler.h:73
SmartPointer< StringsStorage > names_
Definition: heap-profiler.h:75
v8::RetainedObjectInfo * ExecuteWrapperClassCallback(uint16_t class_id, Object **wrapper)
List< v8::HeapProfiler::WrapperInfoCallback > wrapper_callbacks_
Definition: heap-profiler.h:77
SmartPointer< AllocationTracker > allocation_tracker_
Definition: heap-profiler.h:78
void SetRetainedObjectInfo(UniqueId id, RetainedObjectInfo *info)
void DefineWrapperClass(uint16_t class_id, v8::HeapProfiler::WrapperInfoCallback callback)
void AllocationEvent(Address addr, int size)
HeapSnapshot * GetSnapshot(int index)
void StartHeapObjectsTracking(bool track_allocations)
SnapshotObjectId PushHeapObjectsStats(OutputStream *stream)
void RemoveSnapshot(HeapSnapshot *snapshot)
Handle< HeapObject > FindHeapObjectById(SnapshotObjectId id)
SnapshotObjectId GetSnapshotObjectId(Handle< Object > obj)
void ObjectMoveEvent(Address from, Address to, int size)
bool is_tracking_allocations() const
Definition: heap-profiler.h:62
List< HeapSnapshot * > snapshots_
Definition: heap-profiler.h:74
void UpdateObjectSizeEvent(Address addr, int size)
Isolate * isolate()
Definition: heap-inl.h:589
void DisableInlineAllocation()
Definition: heap.cc:5034
void EnableInlineAllocation()
Definition: heap.cc:5025
GlobalHandles * global_handles()
Definition: isolate.h:917
Vector< T > AddBlock(T value, int count, AllocationPolicy allocator=AllocationPolicy())
Definition: list-inl.h:77
enable harmony numeric enable harmony object literal extensions Optimize object Array DOM strings and string trace pretenuring decisions of HAllocate instructions Enables optimizations which favor memory size over execution speed maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining trace the tracking of allocation sites deoptimize every n garbage collections perform array bounds checks elimination analyze liveness of environment slots and zap dead values flushes the cache of optimized code for closures on every GC allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes enable context specialization in TurboFan execution budget before interrupt is triggered max percentage of megamorphic generic ICs to allow optimization enable use of SAHF instruction if enable use of VFP3 instructions if available enable use of NEON instructions if enable use of SDIV and UDIV instructions if enable use of MLS instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of d16 d31 registers on ARM this requires VFP3 force all emitted branches to be in long enable alignment of csp to bytes on platforms which prefer the register to always be expose gc extension under the specified name show built in functions in stack traces use random jit cookie to mask large constants minimum length for automatic enable preparsing CPU profiler sampling interval in microseconds trace out of bounds accesses to external arrays default size of stack region v8 is allowed to maximum length of function source code printed in a stack trace min size of a semi the new space consists of two semi spaces print one trace line following each garbage collection do not print trace line after scavenger collection print cumulative GC statistics in only print modified registers Trace simulator debug messages Implied by trace sim abort randomize hashes to avoid predictable hash Fixed seed to use to hash property Print the time it takes to deserialize the snapshot A filename with extra code to be included in the A file to write the raw snapshot bytes to(mksnapshot only)") DEFINE_STRING(raw_context_file
enable harmony numeric enable harmony object literal extensions Optimize object size
enable harmony numeric enable harmony object literal extensions Optimize object Array DOM strings and string trace pretenuring decisions of HAllocate instructions Enables optimizations which favor memory size over execution speed maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining trace the tracking of allocation sites deoptimize every n garbage collections perform array bounds checks elimination analyze liveness of environment slots and zap dead values flushes the cache of optimized code for closures on every GC allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes enable context specialization in TurboFan execution budget before interrupt is triggered max percentage of megamorphic generic ICs to allow optimization enable use of SAHF instruction if enable use of VFP3 instructions if available enable use of NEON instructions if enable use of SDIV and UDIV instructions if enable use of MLS instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of d16 d31 registers on ARM this requires VFP3 force all emitted branches to be in long enable alignment of csp to bytes on platforms which prefer the register to always be expose gc extension under the specified name show built in functions in stack traces use random jit cookie to mask large constants minimum length for automatic enable preparsing CPU profiler sampling interval in microseconds trace out of bounds accesses to external arrays default size of stack region v8 is allowed to maximum length of function source code printed in a stack trace min size of a semi the new space consists of two semi spaces print one trace line following each garbage collection do not print trace line after scavenger collection print cumulative GC statistics in name
enable harmony numeric enable harmony object literal extensions Optimize object Array DOM strings and string trace pretenuring decisions of HAllocate instructions Enables optimizations which favor memory size over execution speed maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining trace the tracking of allocation sites deoptimize every n garbage collections perform array bounds checks elimination analyze liveness of environment slots and zap dead values flushes the cache of optimized code for closures on every GC allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes enable context specialization in TurboFan execution budget before interrupt is triggered max percentage of megamorphic generic ICs to allow optimization enable use of SAHF instruction if enable use of VFP3 instructions if available enable use of NEON instructions if enable use of SDIV and UDIV instructions if enable use of MLS instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of d16 d31 registers on ARM this requires VFP3 force all emitted branches to be in long enable alignment of csp to bytes on platforms which prefer the register to always be expose gc extension under the specified name show built in functions in stack traces use random jit cookie to mask large constants minimum length for automatic enable preparsing CPU profiler sampling interval in microseconds trace out of bounds accesses to external arrays default size of stack region v8 is allowed to maximum length of function source code printed in a stack trace min size of a semi the new space consists of two semi spaces print one trace line following each garbage collection do not print trace line after scavenger collection print cumulative GC statistics in only print modified registers Trace simulator debug messages Implied by trace sim abort randomize hashes to avoid predictable hash Fixed seed to use to hash property Print the time it takes to deserialize the snapshot A filename with extra code to be included in the snapshot(mksnapshot only)") DEFINE_STRING(raw_file
enable harmony numeric enable harmony object literal extensions Optimize object Array DOM strings and string trace pretenuring decisions of HAllocate instructions Enables optimizations which favor memory size over execution speed maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining trace the tracking of allocation sites deoptimize every n garbage collections perform array bounds checks elimination analyze liveness of environment slots and zap dead values flushes the cache of optimized code for closures on every GC allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes enable context specialization in TurboFan execution budget before interrupt is triggered max percentage of megamorphic generic ICs to allow optimization enable use of SAHF instruction if enable use of VFP3 instructions if available enable use of NEON instructions if enable use of SDIV and UDIV instructions if enable use of MLS instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of d16 d31 registers on ARM this requires VFP3 force all emitted branches to be in long enable alignment of csp to bytes on platforms which prefer the register to always be NULL
#define DCHECK(condition)
Definition: logging.h:205
unsigned short uint16_t
Definition: unicode.cc:23
size_t GetMemoryUsedByList(const List< T, P > &list)
Definition: list.h:184
byte * Address
Definition: globals.h:101
static void DeleteHeapSnapshot(HeapSnapshot **snapshot_ptr)
Debugger support for the V8 JavaScript engine.
Definition: accessors.cc:20