Commit 55674264 authored by yurys@chromium.org's avatar yurys@chromium.org

Do not put allocated block into HeapObjectsMap

Heap allocation reported to AllocationTracker may be later divided into several objects so it is incorrect to put the block as a new HeapObject into the map. We will match allocated block with actual HeapObjects later when iterating Heap (will be addressed in another patch). Since the objects are not assigned an id immediately after creation we need to call FindOrAddEntry when finding id for SharedFunctionInfo during stack crawling.

Removed hooks for tracking creation of AllocationMemento. AllocationMemento is not a HeapObject and should be considered as implementation overhead.

Renamed NewObjectEvent to AllocationEvent which is more precise in case of folded allocations and when a part of the new block becomes AllocationMemento.

BUG=None
LOG=N
R=loislo@chromium.org, mstarzinger@chromium.org

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

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@18151 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent c8bfa60c
......@@ -169,7 +169,7 @@ void AllocationTracker::PrepareForSerialization() {
}
void AllocationTracker::NewObjectEvent(Address addr, int size) {
void AllocationTracker::AllocationEvent(Address addr, int size) {
DisallowHeapAllocation no_allocation;
Heap* heap = ids_->heap();
......@@ -185,7 +185,8 @@ void AllocationTracker::NewObjectEvent(Address addr, int size) {
while (!it.done() && length < kMaxAllocationTraceLength) {
JavaScriptFrame* frame = it.frame();
SharedFunctionInfo* shared = frame->function()->shared();
SnapshotObjectId id = ids_->FindEntry(shared->address());
SnapshotObjectId id = ids_->FindOrAddEntry(
shared->address(), shared->Size(), false);
allocation_trace_buffer_[length++] = id;
AddFunctionInfo(shared, id);
it.Advance();
......
......@@ -96,7 +96,7 @@ class AllocationTracker {
~AllocationTracker();
void PrepareForSerialization();
void NewObjectEvent(Address addr, int size);
void AllocationEvent(Address addr, int size);
AllocationTraceTree* trace_tree() { return &trace_tree_; }
HashMap* id_to_function_info() { return &id_to_function_info_; }
......
......@@ -281,11 +281,6 @@ static FixedArrayBase* LeftTrimFixedArray(Heap* heap,
new_elms->address(),
new_elms->Size());
}
if (profiler->is_tracking_allocations()) {
// Report filler object as a new allocation.
// Otherwise it will become an untracked object.
profiler->NewObjectEvent(elms->address(), elms->Size());
}
return new_elms;
}
......
......@@ -236,7 +236,7 @@ MaybeObject* Heap::AllocateRaw(int size_in_bytes,
space = retry_space;
} else {
if (profiler->is_tracking_allocations() && result->To(&object)) {
profiler->NewObjectEvent(object->address(), size_in_bytes);
profiler->AllocationEvent(object->address(), size_in_bytes);
}
return result;
}
......@@ -260,7 +260,7 @@ MaybeObject* Heap::AllocateRaw(int size_in_bytes,
}
if (result->IsFailure()) old_gen_exhausted_ = true;
if (profiler->is_tracking_allocations() && result->To(&object)) {
profiler->NewObjectEvent(object->address(), size_in_bytes);
profiler->AllocationEvent(object->address(), size_in_bytes);
}
return result;
}
......
......@@ -141,8 +141,8 @@ void HeapProfiler::ObjectMoveEvent(Address from, Address to, int size) {
}
void HeapProfiler::NewObjectEvent(Address addr, int size) {
snapshots_->NewObjectEvent(addr, size);
void HeapProfiler::AllocationEvent(Address addr, int size) {
snapshots_->AllocationEvent(addr, size);
}
......
......@@ -64,7 +64,7 @@ class HeapProfiler {
void ObjectMoveEvent(Address from, Address to, int size);
void NewObjectEvent(Address addr, int size);
void AllocationEvent(Address addr, int size);
void UpdateObjectSizeEvent(Address addr, int size);
......
......@@ -446,18 +446,6 @@ void HeapObjectsMap::MoveObject(Address from, Address to, int object_size) {
}
void HeapObjectsMap::NewObject(Address addr, int size) {
if (FLAG_heap_profiler_trace_objects) {
PrintF("New object : %p %6d. Next address is %p\n",
addr,
size,
addr + size);
}
ASSERT(addr != NULL);
FindOrAddEntry(addr, size, false);
}
void HeapObjectsMap::UpdateObjectSize(Address addr, int size) {
FindOrAddEntry(addr, size, false);
}
......@@ -823,11 +811,10 @@ Handle<HeapObject> HeapSnapshotsCollection::FindHeapObjectById(
}
void HeapSnapshotsCollection::NewObjectEvent(Address addr, int size) {
void HeapSnapshotsCollection::AllocationEvent(Address addr, int size) {
DisallowHeapAllocation no_allocation;
ids_.NewObject(addr, size);
if (allocation_tracker_ != NULL) {
allocation_tracker_->NewObjectEvent(addr, size);
allocation_tracker_->AllocationEvent(addr, size);
}
}
......
......@@ -233,7 +233,6 @@ class HeapObjectsMap {
unsigned int size,
bool accessed = true);
void MoveObject(Address from, Address to, int size);
void NewObject(Address addr, int size);
void UpdateObjectSize(Address addr, int size);
SnapshotObjectId last_assigned_id() const {
return next_id_ - kObjectIdStep;
......@@ -318,7 +317,7 @@ class HeapSnapshotsCollection {
void ObjectMoveEvent(Address from, Address to, int size) {
ids_.MoveObject(from, to, size);
}
void NewObjectEvent(Address addr, int size);
void AllocationEvent(Address addr, int size);
void UpdateObjectSizeEvent(Address addr, int size) {
ids_.UpdateObjectSize(addr, size);
}
......
......@@ -4885,13 +4885,6 @@ MaybeObject* Heap::CopyJSObject(JSObject* source, AllocationSite* site) {
AllocationMemento* alloc_memento = reinterpret_cast<AllocationMemento*>(
reinterpret_cast<Address>(clone) + object_size);
InitializeAllocationMemento(alloc_memento, site);
HeapProfiler* profiler = isolate()->heap_profiler();
if (profiler->is_tracking_allocations()) {
profiler->UpdateObjectSizeEvent(HeapObject::cast(clone)->address(),
object_size);
profiler->NewObjectEvent(alloc_memento->address(),
AllocationMemento::kSize);
}
}
}
......
......@@ -364,7 +364,7 @@ class Deserializer: public SerializerDeserializer {
high_water_[space_index] = address + size;
HeapProfiler* profiler = isolate_->heap_profiler();
if (profiler->is_tracking_allocations()) {
profiler->NewObjectEvent(address, size);
profiler->AllocationEvent(address, size);
}
return address;
}
......
......@@ -2066,26 +2066,6 @@ v8::DeclareExtension kHeapProfilerExtensionDeclaration(
&kHeapProfilerExtension);
// This is an example of using checking of JS allocations tracking in a test.
TEST(HeapObjectsTracker) {
const char* extensions[] = { HeapProfilerExtension::kName };
v8::ExtensionConfiguration config(1, extensions);
LocalContext env(&config);
v8::HandleScope scope(env->GetIsolate());
HeapObjectsTracker tracker;
CompileRun("var a = 1.2");
CompileRun("var a = 1.2; var b = 1.0; var c = 1.0;");
CompileRun(
"var a = [];\n"
"for (var i = 0; i < 5; ++i)\n"
" a[i] = i;\n"
"findUntrackedObjects();\n"
"for (var i = 0; i < 3; ++i)\n"
" a.shift();\n"
"findUntrackedObjects();\n");
}
static const v8::HeapGraphNode* GetNodeByPath(const v8::HeapSnapshot* snapshot,
const char* path[],
int depth) {
......@@ -2207,6 +2187,39 @@ static AllocationTraceNode* FindNode(
}
TEST(ArrayGrowLeftTrim) {
LocalContext env;
v8::HandleScope scope(env->GetIsolate());
v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
heap_profiler->StartRecordingHeapAllocations();
CompileRun(
"var a = [];\n"
"for (var i = 0; i < 5; ++i)\n"
" a[i] = i;\n"
"for (var i = 0; i < 3; ++i)\n"
" a.shift();\n");
const char* names[] = { "(anonymous function)" };
const v8::HeapSnapshot* snapshot = heap_profiler->TakeHeapSnapshot(
v8::String::NewFromUtf8(env->GetIsolate(), "Test1"));
i::HeapSnapshotsCollection* collection = ToInternal(snapshot)->collection();
AllocationTracker* tracker = collection->allocation_tracker();
CHECK_NE(NULL, tracker);
// Resolve all function locations.
tracker->PrepareForSerialization();
// Print for better diagnostics in case of failure.
tracker->trace_tree()->Print(tracker);
AllocationTraceNode* node =
FindNode(tracker, Vector<const char*>(names, ARRAY_SIZE(names)));
CHECK_NE(NULL, node);
CHECK_GE(node->allocation_count(), 2);
CHECK_GE(node->allocation_size(), 4 * 5);
heap_profiler->StopRecordingHeapAllocations();
}
TEST(TrackHeapAllocations) {
v8::HandleScope scope(v8::Isolate::GetCurrent());
LocalContext env;
......
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