2010-12-15 08:07:27 +00:00
|
|
|
// Copyright 2009-2010 the V8 project authors. All rights reserved.
|
2009-09-16 13:41:24 +00:00
|
|
|
// Redistribution and use in source and binary forms, with or without
|
|
|
|
// modification, are permitted provided that the following conditions are
|
|
|
|
// met:
|
|
|
|
//
|
|
|
|
// * Redistributions of source code must retain the above copyright
|
|
|
|
// notice, this list of conditions and the following disclaimer.
|
|
|
|
// * Redistributions in binary form must reproduce the above
|
|
|
|
// copyright notice, this list of conditions and the following
|
|
|
|
// disclaimer in the documentation and/or other materials provided
|
|
|
|
// with the distribution.
|
|
|
|
// * Neither the name of Google Inc. nor the names of its
|
|
|
|
// contributors may be used to endorse or promote products derived
|
|
|
|
// from this software without specific prior written permission.
|
|
|
|
//
|
|
|
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
#include "v8.h"
|
|
|
|
|
|
|
|
#include "heap-profiler.h"
|
2013-02-21 12:10:40 +00:00
|
|
|
#include "heap-snapshot-generator-inl.h"
|
2009-09-16 13:41:24 +00:00
|
|
|
|
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
|
2013-02-11 13:02:20 +00:00
|
|
|
HeapProfiler::HeapProfiler(Heap* heap)
|
|
|
|
: snapshots_(new HeapSnapshotsCollection(heap)),
|
2013-10-14 12:41:28 +00:00
|
|
|
next_snapshot_uid_(1),
|
2013-11-29 09:47:32 +00:00
|
|
|
is_tracking_allocations_(false),
|
|
|
|
is_tracking_object_moves_(false) {
|
2010-06-15 11:44:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
HeapProfiler::~HeapProfiler() {
|
|
|
|
delete snapshots_;
|
|
|
|
}
|
|
|
|
|
2011-03-22 16:10:01 +00:00
|
|
|
|
2013-04-02 08:03:01 +00:00
|
|
|
void HeapProfiler::DeleteAllSnapshots() {
|
2013-02-11 13:02:20 +00:00
|
|
|
Heap* the_heap = heap();
|
2011-03-22 16:10:01 +00:00
|
|
|
delete snapshots_;
|
2013-02-11 13:02:20 +00:00
|
|
|
snapshots_ = new HeapSnapshotsCollection(the_heap);
|
2011-03-22 16:10:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-10 12:05:31 +00:00
|
|
|
void HeapProfiler::DefineWrapperClass(
|
|
|
|
uint16_t class_id, v8::HeapProfiler::WrapperInfoCallback callback) {
|
2011-03-10 12:22:59 +00:00
|
|
|
ASSERT(class_id != v8::HeapProfiler::kPersistentHandleNoClassId);
|
2011-03-18 20:35:07 +00:00
|
|
|
if (wrapper_callbacks_.length() <= class_id) {
|
|
|
|
wrapper_callbacks_.AddBlock(
|
|
|
|
NULL, class_id - wrapper_callbacks_.length() + 1);
|
2011-03-10 12:05:31 +00:00
|
|
|
}
|
2011-03-18 20:35:07 +00:00
|
|
|
wrapper_callbacks_[class_id] = callback;
|
2011-03-10 12:05:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
v8::RetainedObjectInfo* HeapProfiler::ExecuteWrapperClassCallback(
|
|
|
|
uint16_t class_id, Object** wrapper) {
|
2011-03-18 20:35:07 +00:00
|
|
|
if (wrapper_callbacks_.length() <= class_id) return NULL;
|
|
|
|
return wrapper_callbacks_[class_id](
|
2011-03-10 12:05:31 +00:00
|
|
|
class_id, Utils::ToLocal(Handle<Object>(wrapper)));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-02 08:03:01 +00:00
|
|
|
HeapSnapshot* HeapProfiler::TakeSnapshot(
|
2012-12-04 17:17:55 +00:00
|
|
|
const char* name,
|
|
|
|
v8::ActivityControl* control,
|
|
|
|
v8::HeapProfiler::ObjectNameResolver* resolver) {
|
2013-04-02 08:09:59 +00:00
|
|
|
HeapSnapshot* result = snapshots_->NewSnapshot(name, next_snapshot_uid_++);
|
|
|
|
{
|
|
|
|
HeapSnapshotGenerator generator(result, control, resolver, heap());
|
|
|
|
if (!generator.GenerateSnapshot()) {
|
|
|
|
delete result;
|
|
|
|
result = NULL;
|
2010-08-18 08:19:29 +00:00
|
|
|
}
|
2010-12-13 10:42:06 +00:00
|
|
|
}
|
|
|
|
snapshots_->SnapshotGenerationFinished(result);
|
2013-11-29 09:47:32 +00:00
|
|
|
is_tracking_object_moves_ = true;
|
2010-06-15 11:44:07 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-02 08:03:01 +00:00
|
|
|
HeapSnapshot* HeapProfiler::TakeSnapshot(
|
2012-12-04 17:17:55 +00:00
|
|
|
String* name,
|
|
|
|
v8::ActivityControl* control,
|
|
|
|
v8::HeapProfiler::ObjectNameResolver* resolver) {
|
2013-04-02 08:09:59 +00:00
|
|
|
return TakeSnapshot(snapshots_->names()->GetName(name), control, resolver);
|
2010-06-15 11:44:07 +00:00
|
|
|
}
|
|
|
|
|
2013-07-05 09:52:11 +00:00
|
|
|
|
2013-12-02 14:27:24 +00:00
|
|
|
void HeapProfiler::StartHeapObjectsTracking(bool track_allocations) {
|
|
|
|
snapshots_->StartHeapObjectsTracking(track_allocations);
|
2013-11-29 09:47:32 +00:00
|
|
|
is_tracking_object_moves_ = true;
|
2013-12-02 14:27:24 +00:00
|
|
|
ASSERT(!is_tracking_allocations_);
|
|
|
|
if (track_allocations) {
|
|
|
|
heap()->DisableInlineAllocation();
|
|
|
|
is_tracking_allocations_ = true;
|
|
|
|
}
|
2012-04-13 08:52:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-02 08:03:01 +00:00
|
|
|
SnapshotObjectId HeapProfiler::PushHeapObjectsStats(OutputStream* stream) {
|
2012-06-01 16:10:52 +00:00
|
|
|
return snapshots_->PushHeapObjectsStats(stream);
|
2012-04-13 08:52:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-02 08:03:01 +00:00
|
|
|
void HeapProfiler::StopHeapObjectsTracking() {
|
2012-04-13 08:52:25 +00:00
|
|
|
snapshots_->StopHeapObjectsTracking();
|
2013-12-02 14:27:24 +00:00
|
|
|
if (is_tracking_allocations_) {
|
|
|
|
heap()->EnableInlineAllocation();
|
|
|
|
is_tracking_allocations_ = false;
|
|
|
|
}
|
2012-04-13 08:52:25 +00:00
|
|
|
}
|
|
|
|
|
2010-06-15 11:44:07 +00:00
|
|
|
|
2012-06-13 11:02:24 +00:00
|
|
|
size_t HeapProfiler::GetMemorySizeUsedByProfiler() {
|
2013-04-02 08:03:01 +00:00
|
|
|
return snapshots_->GetUsedMemorySize();
|
2012-06-13 11:02:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-06-15 11:44:07 +00:00
|
|
|
int HeapProfiler::GetSnapshotsCount() {
|
2013-04-02 08:03:01 +00:00
|
|
|
return snapshots_->snapshots()->length();
|
2010-06-15 11:44:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
HeapSnapshot* HeapProfiler::GetSnapshot(int index) {
|
2013-04-02 08:03:01 +00:00
|
|
|
return snapshots_->snapshots()->at(index);
|
2010-06-15 11:44:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-04-16 15:36:19 +00:00
|
|
|
SnapshotObjectId HeapProfiler::GetSnapshotObjectId(Handle<Object> obj) {
|
|
|
|
if (!obj->IsHeapObject())
|
|
|
|
return v8::HeapProfiler::kUnknownObjectId;
|
2013-04-02 08:03:01 +00:00
|
|
|
return snapshots_->FindObjectId(HeapObject::cast(*obj)->address());
|
2011-03-22 16:10:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-10-14 12:41:28 +00:00
|
|
|
void HeapProfiler::ObjectMoveEvent(Address from, Address to, int size) {
|
|
|
|
snapshots_->ObjectMoveEvent(from, to, size);
|
2010-07-15 13:21:50 +00:00
|
|
|
}
|
|
|
|
|
2013-10-14 12:41:28 +00:00
|
|
|
|
2013-11-29 09:54:38 +00:00
|
|
|
void HeapProfiler::AllocationEvent(Address addr, int size) {
|
|
|
|
snapshots_->AllocationEvent(addr, size);
|
2013-10-14 12:41:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void HeapProfiler::UpdateObjectSizeEvent(Address addr, int size) {
|
|
|
|
snapshots_->UpdateObjectSizeEvent(addr, size);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-24 15:59:23 +00:00
|
|
|
void HeapProfiler::SetRetainedObjectInfo(UniqueId id,
|
|
|
|
RetainedObjectInfo* info) {
|
|
|
|
// TODO(yurus, marja): Don't route this information through GlobalHandles.
|
|
|
|
heap()->isolate()->global_handles()->SetRetainedObjectInfo(id, info);
|
|
|
|
}
|
2009-09-16 13:41:24 +00:00
|
|
|
|
2013-10-14 12:41:28 +00:00
|
|
|
|
2009-09-16 13:41:24 +00:00
|
|
|
} } // namespace v8::internal
|