Hewlett-Packard Development Company, LP
Igalia, S.L.
Joyent, Inc.
-Bloomberg Finance L.P.
Akinori MUSHA <knu@FreeBSD.org>
Alexander Botero-Lowry <alexbl@FreeBSD.org>
/** Returns function entry UID. */
unsigned GetCallUid() const;
- /** Returns id of the node. The id is unique within the tree */
- unsigned GetNodeId() const;
-
/** Returns child nodes count of the node. */
int GetChildrenCount() const;
const CpuProfileNode* GetTopDownRoot() const;
/**
- * Returns number of samples recorded. The samples are not recorded unless
- * |record_samples| parameter of CpuProfiler::StartCpuProfiling is true.
- */
- int GetSamplesCount() const;
-
- /**
- * Returns profile node corresponding to the top frame the sample at
- * the given index.
- */
- const CpuProfileNode* GetSample(int index) const;
-
- /**
* Deletes the profile and removes it from CpuProfiler's list.
* All pointers to nodes previously returned become invalid.
* Profiles with the same uid but obtained using different
/**
- * Interface for controlling CPU profiling. Instance of the
- * profiler can be retrieved using v8::Isolate::GetCpuProfiler.
+ * Interface for controlling CPU profiling.
*/
class V8EXPORT CpuProfiler {
public:
* obtaining profiling results.
*/
- /** Deprecated. Use GetProfileCount instead. */
- static int GetProfilesCount();
/**
* Returns the number of profiles collected (doesn't include
* profiles that are being collected at the moment of call.)
*/
- int GetProfileCount();
+ static int GetProfilesCount();
- /** Deprecated. Use GetCpuProfile instead. */
- static const CpuProfile* GetProfile(
- int index,
- Handle<Value> security_token = Handle<Value>());
/** Returns a profile by index. */
- const CpuProfile* GetCpuProfile(
+ static const CpuProfile* GetProfile(
int index,
Handle<Value> security_token = Handle<Value>());
- /** Deprecated. Use FindProfile instead. */
- static const CpuProfile* FindProfile(
- unsigned uid,
- Handle<Value> security_token = Handle<Value>());
/** Returns a profile by uid. */
- const CpuProfile* FindCpuProfile(
+ static const CpuProfile* FindProfile(
unsigned uid,
Handle<Value> security_token = Handle<Value>());
- /** Deprecated. Use StartCpuProfiling instead. */
- static void StartProfiling(Handle<String> title, bool record_samples = false);
/**
* Starts collecting CPU profile. Title may be an empty string. It
* is allowed to have several profiles being collected at
* title are silently ignored. While collecting a profile, functions
* from all security contexts are included in it. The token-based
* filtering is only performed when querying for a profile.
- *
- * |record_samples| parameter controls whether individual samples should
- * be recorded in addition to the aggregated tree.
*/
- void StartCpuProfiling(Handle<String> title, bool record_samples = false);
+ static void StartProfiling(Handle<String> title);
- /** Deprecated. Use StopCpuProfiling instead. */
- static const CpuProfile* StopProfiling(
- Handle<String> title,
- Handle<Value> security_token = Handle<Value>());
/**
* Stops collecting CPU profile with a given title and returns it.
* If the title given is empty, finishes the last profile started.
*/
- const CpuProfile* StopCpuProfiling(
+ static const CpuProfile* StopProfiling(
Handle<String> title,
Handle<Value> security_token = Handle<Value>());
- /** Deprecated. Use DeleteAllCpuProfiles instead. */
- static void DeleteAllProfiles();
/**
* Deletes all existing profiles, also cancelling all profiling
* activity. All previously returned pointers to profiles and their
* contents become invalid after this call.
*/
- void DeleteAllCpuProfiles();
-
- private:
- CpuProfiler();
- ~CpuProfiler();
- CpuProfiler(const CpuProfiler&);
- CpuProfiler& operator=(const CpuProfiler&);
+ static void DeleteAllProfiles();
};
kJSON = 0 // See format description near 'Serialize' method.
};
- /** Deprecated. Returns kFull. */
- V8_DEPRECATED(Type GetType() const);
+ /** Returns heap snapshot type. */
+ Type GetType() const;
/** Returns heap snapshot UID (assigned by the profiler.) */
unsigned GetUid() const;
class RetainedObjectInfo;
/**
- * Interface for controlling heap profiling. Instance of the
- * profiler can be retrieved using v8::Isolate::GetHeapProfiler.
+ * Interface for controlling heap profiling.
*/
class V8EXPORT HeapProfiler {
public:
typedef RetainedObjectInfo* (*WrapperInfoCallback)
(uint16_t class_id, Handle<Value> wrapper);
- /** Deprecated. Use GetSnapshotCount instead. */
- static int GetSnapshotsCount();
/** Returns the number of snapshots taken. */
- int GetSnapshotCount();
+ static int GetSnapshotsCount();
- /** Deprecated. Use GetHeapSnapshot instead. */
- static const HeapSnapshot* GetSnapshot(int index);
/** Returns a snapshot by index. */
- const HeapSnapshot* GetHeapSnapshot(int index);
+ static const HeapSnapshot* GetSnapshot(int index);
- /** Deprecated. Use FindHeapSnapshot instead. */
- static const HeapSnapshot* FindSnapshot(unsigned uid);
/** Returns a profile by uid. */
- const HeapSnapshot* FindHeapSnapshot(unsigned uid);
+ static const HeapSnapshot* FindSnapshot(unsigned uid);
- /** Deprecated. Use GetObjectId instead. */
- static SnapshotObjectId GetSnapshotObjectId(Handle<Value> value);
/**
* Returns SnapshotObjectId for a heap object referenced by |value| if
* it has been seen by the heap profiler, kUnknownObjectId otherwise.
*/
- SnapshotObjectId GetObjectId(Handle<Value> value);
+ static SnapshotObjectId GetSnapshotObjectId(Handle<Value> value);
/**
* A constant for invalid SnapshotObjectId. GetSnapshotObjectId will return
* Callback interface for retrieving user friendly names of global objects.
*/
class ObjectNameResolver {
- public:
+ public:
/**
* Returns name to be used in the heap snapshot for given node. Returned
* string must stay alive until snapshot collection is completed.
*/
virtual const char* GetName(Handle<Object> object) = 0;
- protected:
+ protected:
virtual ~ObjectNameResolver() {}
};
- /** Deprecated. Use TakeHeapSnapshot instead. */
- static const HeapSnapshot* TakeSnapshot(
- Handle<String> title,
- HeapSnapshot::Type type = HeapSnapshot::kFull,
- ActivityControl* control = NULL,
- ObjectNameResolver* global_object_name_resolver = NULL);
/**
* Takes a heap snapshot and returns it. Title may be an empty string.
+ * See HeapSnapshot::Type for types description.
*/
- const HeapSnapshot* TakeHeapSnapshot(
+ static const HeapSnapshot* TakeSnapshot(
Handle<String> title,
+ HeapSnapshot::Type type = HeapSnapshot::kFull,
ActivityControl* control = NULL,
ObjectNameResolver* global_object_name_resolver = NULL);
-
- /** Deprecated. Use StartTrackingHeapObjects instead. */
- static void StartHeapObjectsTracking();
/**
* Starts tracking of heap objects population statistics. After calling
* this method, all heap objects relocations done by the garbage collector
* are being registered.
*/
- void StartTrackingHeapObjects();
+ static void StartHeapObjectsTracking();
- /** Deprecated. Use GetHeapStats instead. */
- static SnapshotObjectId PushHeapObjectsStats(OutputStream* stream);
/**
* Adds a new time interval entry to the aggregated statistics array. The
* time interval entry contains information on the current heap objects
* HeapStatsUpdate structure instances.
* The return value of the function is the last seen heap object Id.
*
- * StartTrackingHeapObjects must be called before the first call to this
+ * StartHeapObjectsTracking must be called before the first call to this
* method.
*/
- SnapshotObjectId GetHeapStats(OutputStream* stream);
+ static SnapshotObjectId PushHeapObjectsStats(OutputStream* stream);
- /** Deprecated. Use StopTrackingHeapObjects instead. */
- static void StopHeapObjectsTracking();
/**
* Stops tracking of heap objects population statistics, cleans up all
* collected data. StartHeapObjectsTracking must be called again prior to
* calling PushHeapObjectsStats next time.
*/
- void StopTrackingHeapObjects();
+ static void StopHeapObjectsTracking();
- /** Deprecated. Use DeleteAllHeapSnapshots instead. */
- static void DeleteAllSnapshots();
/**
* Deletes all snapshots taken. All previously returned pointers to
* snapshots and their contents become invalid after this call.
*/
- void DeleteAllHeapSnapshots();
+ static void DeleteAllSnapshots();
- /** Deprecated. Use SetWrapperClassInfoProvider instead. */
- static void DefineWrapperClass(
- uint16_t class_id,
- WrapperInfoCallback callback);
/** Binds a callback to embedder's class ID. */
- void SetWrapperClassInfoProvider(
+ static void DefineWrapperClass(
uint16_t class_id,
WrapperInfoCallback callback);
*/
static const uint16_t kPersistentHandleNoClassId = 0;
- /**
- * Deprecated. Returns the number of currently existing persistent handles.
- */
+ /** Returns the number of currently existing persistent handles. */
static int GetPersistentHandleCount();
- /** Deprecated. Use GetHeapProfilerMemorySize instead. */
- static size_t GetMemorySizeUsedByProfiler();
/** Returns memory used for profiler internal data and snapshots. */
- size_t GetProfilerMemorySize();
-
- private:
- HeapProfiler();
- ~HeapProfiler();
- HeapProfiler(const HeapProfiler&);
- HeapProfiler& operator=(const HeapProfiler&);
+ static size_t GetMemorySizeUsedByProfiler();
};
/**
* A struct for exporting HeapStats data from V8, using "push" model.
- * See HeapProfiler::GetHeapStats.
+ * See HeapProfiler::PushHeapObjectsStats.
*/
struct HeapStatsUpdate {
HeapStatsUpdate(uint32_t index, uint32_t count, uint32_t size)
class Boolean;
class BooleanObject;
class Context;
-class CpuProfiler;
class Data;
class Date;
class DeclaredAccessorDescriptor;
class External;
class Function;
class FunctionTemplate;
-class HeapProfiler;
class ImplementationUtilities;
class Int32;
class Integer;
*/
intptr_t AdjustAmountOfExternalAllocatedMemory(intptr_t change_in_bytes);
- /**
- * Returns heap profiler for this isolate. Will return NULL until the isolate
- * is initialized.
- */
- HeapProfiler* GetHeapProfiler();
-
- /**
- * Returns CPU profiler for this isolate. Will return NULL until the isolate
- * is initialized.
- */
- CpuProfiler* GetCpuProfiler();
-
private:
Isolate();
Isolate(const Isolate&);
static bool IsExecutionTerminating(Isolate* isolate = NULL);
/**
- * Resume execution capability in the given isolate, whose execution
- * was previously forcefully terminated using TerminateExecution().
- *
- * When execution is forcefully terminated using TerminateExecution(),
- * the isolate can not resume execution until all JavaScript frames
- * have propagated the uncatchable exception which is generated. This
- * method allows the program embedding the engine to handle the
- * termination event and resume execution capability, even if
- * JavaScript frames remain on the stack.
- *
- * This method can be used by any thread even if that thread has not
- * acquired the V8 lock with a Locker object.
- *
- * \param isolate The isolate in which to resume execution capability.
- */
- static void CancelTerminateExecution(Isolate* isolate);
-
- /**
* Releases any resources used by v8 and stops any utility threads
* that may be running. Note that disposing v8 is permanent, it
* cannot be reinitialized.
bool HasCaught() const;
/**
- * For certain types of exceptions, it makes no sense to continue execution.
- *
- * If CanContinue returns false, the correct action is to perform any C++
- * cleanup needed and then return. If CanContinue returns false and
- * HasTerminated returns true, it is possible to call
- * CancelTerminateExecution in order to continue calling into the engine.
- */
- bool CanContinue() const;
-
- /**
- * Returns true if an exception has been caught due to script execution
- * being terminated.
+ * For certain types of exceptions, it makes no sense to continue
+ * execution.
*
- * There is no JavaScript representation of an execution termination
- * exception. Such exceptions are thrown when the TerminateExecution
- * methods are called to terminate a long-running script.
+ * Currently, the only type of exception that can be caught by a
+ * TryCatch handler and for which it does not make sense to continue
+ * is termination exception. Such exceptions are thrown when the
+ * TerminateExecution methods are called to terminate a long-running
+ * script.
*
- * If such an exception has been thrown, HasTerminated will return true,
- * indicating that it is possible to call CancelTerminateExecution in order
- * to continue calling into the engine.
+ * If CanContinue returns false, the correct action is to perform
+ * any C++ cleanup needed and then return.
*/
- bool HasTerminated() const;
+ bool CanContinue() const;
/**
* Throws the exception caught by this TryCatch in a way that avoids
bool can_continue_ : 1;
bool capture_message_ : 1;
bool rethrow_ : 1;
- bool has_terminated_ : 1;
friend class v8::internal::Isolate;
};
is_verbose_(false),
can_continue_(true),
capture_message_(true),
- rethrow_(false),
- has_terminated_(false) {
+ rethrow_(false) {
isolate_->RegisterTryCatchHandler(this);
}
}
-bool v8::TryCatch::HasTerminated() const {
- return has_terminated_;
-}
-
-
v8::Handle<v8::Value> v8::TryCatch::ReThrow() {
if (!HasCaught()) return v8::Local<v8::Value>();
rethrow_ = true;
}
-HeapProfiler* Isolate::GetHeapProfiler() {
- i::HeapProfiler* heap_profiler =
- reinterpret_cast<i::Isolate*>(this)->heap_profiler();
- return reinterpret_cast<HeapProfiler*>(heap_profiler);
-}
-
-
-CpuProfiler* Isolate::GetCpuProfiler() {
- i::CpuProfiler* cpu_profiler =
- reinterpret_cast<i::Isolate*>(this)->cpu_profiler();
- return reinterpret_cast<CpuProfiler*>(cpu_profiler);
-}
-
-
void V8::SetGlobalGCPrologueCallback(GCCallback callback) {
i::Isolate* isolate = i::Isolate::Current();
if (IsDeadCheck(isolate, "v8::V8::SetGlobalGCPrologueCallback()")) return;
}
-void V8::CancelTerminateExecution(Isolate* isolate) {
- i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
- i_isolate->stack_guard()->CancelTerminateExecution();
-}
-
-
Isolate* Isolate::GetCurrent() {
i::Isolate* isolate = i::Isolate::UncheckedCurrent();
return reinterpret_cast<Isolate*>(isolate);
}
-unsigned CpuProfileNode::GetNodeId() const {
- return reinterpret_cast<const i::ProfileNode*>(this)->id();
-}
-
-
int CpuProfileNode::GetChildrenCount() const {
i::Isolate* isolate = i::Isolate::Current();
IsDeadCheck(isolate, "v8::CpuProfileNode::GetChildrenCount");
void CpuProfile::Delete() {
i::Isolate* isolate = i::Isolate::Current();
IsDeadCheck(isolate, "v8::CpuProfile::Delete");
- i::CpuProfiler* profiler = isolate->cpu_profiler();
- ASSERT(profiler != NULL);
- profiler->DeleteProfile(reinterpret_cast<i::CpuProfile*>(this));
- if (profiler->GetProfilesCount() == 0 && !profiler->HasDetachedProfiles()) {
+ i::CpuProfiler::DeleteProfile(reinterpret_cast<i::CpuProfile*>(this));
+ if (i::CpuProfiler::GetProfilesCount() == 0 &&
+ !i::CpuProfiler::HasDetachedProfiles()) {
// If this was the last profile, clean up all accessory data as well.
- profiler->DeleteAllProfiles();
+ i::CpuProfiler::DeleteAllProfiles();
}
}
}
-const CpuProfileNode* CpuProfile::GetSample(int index) const {
- const i::CpuProfile* profile = reinterpret_cast<const i::CpuProfile*>(this);
- return reinterpret_cast<const CpuProfileNode*>(profile->sample(index));
-}
-
-
-int CpuProfile::GetSamplesCount() const {
- return reinterpret_cast<const i::CpuProfile*>(this)->samples_count();
-}
-
-
int CpuProfiler::GetProfilesCount() {
i::Isolate* isolate = i::Isolate::Current();
IsDeadCheck(isolate, "v8::CpuProfiler::GetProfilesCount");
- i::CpuProfiler* profiler = isolate->cpu_profiler();
- ASSERT(profiler != NULL);
- return profiler->GetProfilesCount();
-}
-
-
-int CpuProfiler::GetProfileCount() {
- return reinterpret_cast<i::CpuProfiler*>(this)->GetProfilesCount();
+ return i::CpuProfiler::GetProfilesCount();
}
Handle<Value> security_token) {
i::Isolate* isolate = i::Isolate::Current();
IsDeadCheck(isolate, "v8::CpuProfiler::GetProfile");
- i::CpuProfiler* profiler = isolate->cpu_profiler();
- ASSERT(profiler != NULL);
return reinterpret_cast<const CpuProfile*>(
- profiler->GetProfile(
- security_token.IsEmpty() ? NULL : *Utils::OpenHandle(*security_token),
- index));
-}
-
-
-const CpuProfile* CpuProfiler::GetCpuProfile(int index,
- Handle<Value> security_token) {
- return reinterpret_cast<const CpuProfile*>(
- reinterpret_cast<i::CpuProfiler*>(this)->GetProfile(
+ i::CpuProfiler::GetProfile(
security_token.IsEmpty() ? NULL : *Utils::OpenHandle(*security_token),
index));
}
Handle<Value> security_token) {
i::Isolate* isolate = i::Isolate::Current();
IsDeadCheck(isolate, "v8::CpuProfiler::FindProfile");
- i::CpuProfiler* profiler = isolate->cpu_profiler();
- ASSERT(profiler != NULL);
- return reinterpret_cast<const CpuProfile*>(
- profiler->FindProfile(
- security_token.IsEmpty() ? NULL : *Utils::OpenHandle(*security_token),
- uid));
-}
-
-
-const CpuProfile* CpuProfiler::FindCpuProfile(unsigned uid,
- Handle<Value> security_token) {
return reinterpret_cast<const CpuProfile*>(
- reinterpret_cast<i::CpuProfiler*>(this)->FindProfile(
+ i::CpuProfiler::FindProfile(
security_token.IsEmpty() ? NULL : *Utils::OpenHandle(*security_token),
uid));
}
-void CpuProfiler::StartProfiling(Handle<String> title, bool record_samples) {
+void CpuProfiler::StartProfiling(Handle<String> title) {
i::Isolate* isolate = i::Isolate::Current();
IsDeadCheck(isolate, "v8::CpuProfiler::StartProfiling");
- i::CpuProfiler* profiler = isolate->cpu_profiler();
- ASSERT(profiler != NULL);
- profiler->StartProfiling(*Utils::OpenHandle(*title), record_samples);
-}
-
-
-void CpuProfiler::StartCpuProfiling(Handle<String> title, bool record_samples) {
- reinterpret_cast<i::CpuProfiler*>(this)->StartProfiling(
- *Utils::OpenHandle(*title), record_samples);
+ i::CpuProfiler::StartProfiling(*Utils::OpenHandle(*title));
}
Handle<Value> security_token) {
i::Isolate* isolate = i::Isolate::Current();
IsDeadCheck(isolate, "v8::CpuProfiler::StopProfiling");
- i::CpuProfiler* profiler = isolate->cpu_profiler();
- ASSERT(profiler != NULL);
- return reinterpret_cast<const CpuProfile*>(
- profiler->StopProfiling(
- security_token.IsEmpty() ? NULL : *Utils::OpenHandle(*security_token),
- *Utils::OpenHandle(*title)));
-}
-
-
-const CpuProfile* CpuProfiler::StopCpuProfiling(Handle<String> title,
- Handle<Value> security_token) {
return reinterpret_cast<const CpuProfile*>(
- reinterpret_cast<i::CpuProfiler*>(this)->StopProfiling(
+ i::CpuProfiler::StopProfiling(
security_token.IsEmpty() ? NULL : *Utils::OpenHandle(*security_token),
*Utils::OpenHandle(*title)));
}
void CpuProfiler::DeleteAllProfiles() {
i::Isolate* isolate = i::Isolate::Current();
IsDeadCheck(isolate, "v8::CpuProfiler::DeleteAllProfiles");
- i::CpuProfiler* profiler = isolate->cpu_profiler();
- ASSERT(profiler != NULL);
- profiler->DeleteAllProfiles();
-}
-
-
-void CpuProfiler::DeleteAllCpuProfiles() {
- reinterpret_cast<i::CpuProfiler*>(this)->DeleteAllProfiles();
+ i::CpuProfiler::DeleteAllProfiles();
}
void HeapSnapshot::Delete() {
i::Isolate* isolate = i::Isolate::Current();
IsDeadCheck(isolate, "v8::HeapSnapshot::Delete");
- if (isolate->heap_profiler()->GetSnapshotsCount() > 1) {
+ if (i::HeapProfiler::GetSnapshotsCount() > 1) {
ToInternal(this)->Delete();
} else {
// If this is the last snapshot, clean up all accessory data as well.
- isolate->heap_profiler()->DeleteAllSnapshots();
+ i::HeapProfiler::DeleteAllSnapshots();
}
}
HeapSnapshot::Type HeapSnapshot::GetType() const {
i::Isolate* isolate = i::Isolate::Current();
IsDeadCheck(isolate, "v8::HeapSnapshot::GetType");
- return kFull;
+ return static_cast<HeapSnapshot::Type>(ToInternal(this)->type());
}
int HeapProfiler::GetSnapshotsCount() {
i::Isolate* isolate = i::Isolate::Current();
IsDeadCheck(isolate, "v8::HeapProfiler::GetSnapshotsCount");
- return isolate->heap_profiler()->GetSnapshotsCount();
-}
-
-
-int HeapProfiler::GetSnapshotCount() {
- return reinterpret_cast<i::HeapProfiler*>(this)->GetSnapshotsCount();
+ return i::HeapProfiler::GetSnapshotsCount();
}
i::Isolate* isolate = i::Isolate::Current();
IsDeadCheck(isolate, "v8::HeapProfiler::GetSnapshot");
return reinterpret_cast<const HeapSnapshot*>(
- isolate->heap_profiler()->GetSnapshot(index));
-}
-
-
-const HeapSnapshot* HeapProfiler::GetHeapSnapshot(int index) {
- return reinterpret_cast<const HeapSnapshot*>(
- reinterpret_cast<i::HeapProfiler*>(this)->GetSnapshot(index));
+ i::HeapProfiler::GetSnapshot(index));
}
i::Isolate* isolate = i::Isolate::Current();
IsDeadCheck(isolate, "v8::HeapProfiler::FindSnapshot");
return reinterpret_cast<const HeapSnapshot*>(
- isolate->heap_profiler()->FindSnapshot(uid));
-}
-
-
-const HeapSnapshot* HeapProfiler::FindHeapSnapshot(unsigned uid) {
- return reinterpret_cast<const HeapSnapshot*>(
- reinterpret_cast<i::HeapProfiler*>(this)->FindSnapshot(uid));
+ i::HeapProfiler::FindSnapshot(uid));
}
i::Isolate* isolate = i::Isolate::Current();
IsDeadCheck(isolate, "v8::HeapProfiler::GetSnapshotObjectId");
i::Handle<i::Object> obj = Utils::OpenHandle(*value);
- return isolate->heap_profiler()->GetSnapshotObjectId(obj);
-}
-
-
-SnapshotObjectId HeapProfiler::GetObjectId(Handle<Value> value) {
- i::Handle<i::Object> obj = Utils::OpenHandle(*value);
- return reinterpret_cast<i::HeapProfiler*>(this)->GetSnapshotObjectId(obj);
+ return i::HeapProfiler::GetSnapshotObjectId(obj);
}
ObjectNameResolver* resolver) {
i::Isolate* isolate = i::Isolate::Current();
IsDeadCheck(isolate, "v8::HeapProfiler::TakeSnapshot");
+ i::HeapSnapshot::Type internal_type = i::HeapSnapshot::kFull;
+ switch (type) {
+ case HeapSnapshot::kFull:
+ internal_type = i::HeapSnapshot::kFull;
+ break;
+ default:
+ UNREACHABLE();
+ }
return reinterpret_cast<const HeapSnapshot*>(
- isolate->heap_profiler()->TakeSnapshot(
- *Utils::OpenHandle(*title), control, resolver));
-}
-
-
-const HeapSnapshot* HeapProfiler::TakeHeapSnapshot(
- Handle<String> title,
- ActivityControl* control,
- ObjectNameResolver* resolver) {
- return reinterpret_cast<const HeapSnapshot*>(
- reinterpret_cast<i::HeapProfiler*>(this)->TakeSnapshot(
- *Utils::OpenHandle(*title), control, resolver));
+ i::HeapProfiler::TakeSnapshot(
+ *Utils::OpenHandle(*title), internal_type, control, resolver));
}
void HeapProfiler::StartHeapObjectsTracking() {
i::Isolate* isolate = i::Isolate::Current();
IsDeadCheck(isolate, "v8::HeapProfiler::StartHeapObjectsTracking");
- isolate->heap_profiler()->StartHeapObjectsTracking();
-}
-
-
-void HeapProfiler::StartTrackingHeapObjects() {
- reinterpret_cast<i::HeapProfiler*>(this)->StartHeapObjectsTracking();
+ i::HeapProfiler::StartHeapObjectsTracking();
}
void HeapProfiler::StopHeapObjectsTracking() {
i::Isolate* isolate = i::Isolate::Current();
IsDeadCheck(isolate, "v8::HeapProfiler::StopHeapObjectsTracking");
- isolate->heap_profiler()->StopHeapObjectsTracking();
-}
-
-
-void HeapProfiler::StopTrackingHeapObjects() {
- reinterpret_cast<i::HeapProfiler*>(this)->StopHeapObjectsTracking();
+ i::HeapProfiler::StopHeapObjectsTracking();
}
SnapshotObjectId HeapProfiler::PushHeapObjectsStats(OutputStream* stream) {
i::Isolate* isolate = i::Isolate::Current();
IsDeadCheck(isolate, "v8::HeapProfiler::PushHeapObjectsStats");
- return isolate->heap_profiler()->PushHeapObjectsStats(stream);
-}
-
-
-SnapshotObjectId HeapProfiler::GetHeapStats(OutputStream* stream) {
- return reinterpret_cast<i::HeapProfiler*>(this)->PushHeapObjectsStats(stream);
+ return i::HeapProfiler::PushHeapObjectsStats(stream);
}
void HeapProfiler::DeleteAllSnapshots() {
i::Isolate* isolate = i::Isolate::Current();
IsDeadCheck(isolate, "v8::HeapProfiler::DeleteAllSnapshots");
- isolate->heap_profiler()->DeleteAllSnapshots();
-}
-
-
-void HeapProfiler::DeleteAllHeapSnapshots() {
- reinterpret_cast<i::HeapProfiler*>(this)->DeleteAllSnapshots();
+ i::HeapProfiler::DeleteAllSnapshots();
}
}
-void HeapProfiler::SetWrapperClassInfoProvider(uint16_t class_id,
- WrapperInfoCallback callback) {
- reinterpret_cast<i::HeapProfiler*>(this)->DefineWrapperClass(class_id,
- callback);
-}
-
-
int HeapProfiler::GetPersistentHandleCount() {
i::Isolate* isolate = i::Isolate::Current();
return isolate->global_handles()->NumberOfGlobalHandles();
size_t HeapProfiler::GetMemorySizeUsedByProfiler() {
- return i::Isolate::Current()->heap_profiler()->GetMemorySizeUsedByProfiler();
-}
-
-
-size_t HeapProfiler::GetProfilerMemorySize() {
- return reinterpret_cast<i::HeapProfiler*>(this)->
- GetMemorySizeUsedByProfiler();
+ return i::HeapProfiler::GetMemorySizeUsedByProfiler();
}
bool CodeGenerator::ShouldGenerateLog(Expression* type) {
ASSERT(type != NULL);
Isolate* isolate = Isolate::Current();
- if (!isolate->logger()->is_logging() &&
- !isolate->cpu_profiler()->is_profiling()) {
+ if (!isolate->logger()->is_logging() && !CpuProfiler::is_profiling(isolate)) {
return false;
}
Handle<String> name = Handle<String>::cast(type->AsLiteral()->handle());
// script name and line number. Check explicitly whether logging is
// enabled as finding the line number is not free.
if (info->isolate()->logger()->is_logging_code_events() ||
- info->isolate()->cpu_profiler()->is_profiling()) {
+ CpuProfiler::is_profiling(info->isolate())) {
Handle<Script> script = info->script();
Handle<Code> code = info->code();
if (*code == info->isolate()->builtins()->builtin(Builtins::kLazyCompile))
}
+void CpuProfiler::StartProfiling(const char* title) {
+ ASSERT(Isolate::Current()->cpu_profiler() != NULL);
+ Isolate::Current()->cpu_profiler()->StartCollectingProfile(title);
+}
+
+
+void CpuProfiler::StartProfiling(String* title) {
+ ASSERT(Isolate::Current()->cpu_profiler() != NULL);
+ Isolate::Current()->cpu_profiler()->StartCollectingProfile(title);
+}
+
+
+CpuProfile* CpuProfiler::StopProfiling(const char* title) {
+ Isolate* isolate = Isolate::Current();
+ return is_profiling(isolate) ?
+ isolate->cpu_profiler()->StopCollectingProfile(title) : NULL;
+}
+
+
+CpuProfile* CpuProfiler::StopProfiling(Object* security_token, String* title) {
+ Isolate* isolate = Isolate::Current();
+ return is_profiling(isolate) ?
+ isolate->cpu_profiler()->StopCollectingProfile(
+ security_token, title) : NULL;
+}
+
+
int CpuProfiler::GetProfilesCount() {
+ ASSERT(Isolate::Current()->cpu_profiler() != NULL);
// The count of profiles doesn't depend on a security token.
- return profiles_->Profiles(TokenEnumerator::kNoSecurityToken)->length();
+ return Isolate::Current()->cpu_profiler()->profiles_->Profiles(
+ TokenEnumerator::kNoSecurityToken)->length();
}
CpuProfile* CpuProfiler::GetProfile(Object* security_token, int index) {
- const int token = token_enumerator_->GetTokenId(security_token);
- return profiles_->Profiles(token)->at(index);
+ ASSERT(Isolate::Current()->cpu_profiler() != NULL);
+ CpuProfiler* profiler = Isolate::Current()->cpu_profiler();
+ const int token = profiler->token_enumerator_->GetTokenId(security_token);
+ return profiler->profiles_->Profiles(token)->at(index);
}
CpuProfile* CpuProfiler::FindProfile(Object* security_token, unsigned uid) {
- const int token = token_enumerator_->GetTokenId(security_token);
- return profiles_->GetProfile(token, uid);
+ ASSERT(Isolate::Current()->cpu_profiler() != NULL);
+ CpuProfiler* profiler = Isolate::Current()->cpu_profiler();
+ const int token = profiler->token_enumerator_->GetTokenId(security_token);
+ return profiler->profiles_->GetProfile(token, uid);
}
-TickSample* CpuProfiler::TickSampleEvent() {
- if (is_profiling_) return processor_->TickSampleEvent();
- return NULL;
+TickSample* CpuProfiler::TickSampleEvent(Isolate* isolate) {
+ if (CpuProfiler::is_profiling(isolate)) {
+ return isolate->cpu_profiler()->processor_->TickSampleEvent();
+ } else {
+ return NULL;
+ }
}
void CpuProfiler::DeleteAllProfiles() {
- if (is_profiling_) StopProcessor();
- ResetProfiles();
+ Isolate* isolate = Isolate::Current();
+ ASSERT(isolate->cpu_profiler() != NULL);
+ if (is_profiling(isolate)) {
+ isolate->cpu_profiler()->StopProcessor();
+ }
+ isolate->cpu_profiler()->ResetProfiles();
}
void CpuProfiler::DeleteProfile(CpuProfile* profile) {
- profiles_->RemoveProfile(profile);
+ ASSERT(Isolate::Current()->cpu_profiler() != NULL);
+ Isolate::Current()->cpu_profiler()->profiles_->RemoveProfile(profile);
delete profile;
}
bool CpuProfiler::HasDetachedProfiles() {
- return profiles_->HasDetachedProfiles();
+ ASSERT(Isolate::Current()->cpu_profiler() != NULL);
+ return Isolate::Current()->cpu_profiler()->profiles_->HasDetachedProfiles();
}
void CpuProfiler::CallbackEvent(Name* name, Address entry_point) {
- processor_->CallbackCreateEvent(
+ Isolate::Current()->cpu_profiler()->processor_->CallbackCreateEvent(
Logger::CALLBACK_TAG, CodeEntry::kEmptyNamePrefix, name, entry_point);
}
void CpuProfiler::CodeCreateEvent(Logger::LogEventsAndTags tag,
Code* code, const char* comment) {
- processor_->CodeCreateEvent(
+ Isolate::Current()->cpu_profiler()->processor_->CodeCreateEvent(
tag, comment, code->address(), code->ExecutableSize());
}
void CpuProfiler::CodeCreateEvent(Logger::LogEventsAndTags tag,
Code* code, Name* name) {
- processor_->CodeCreateEvent(
+ Isolate* isolate = Isolate::Current();
+ isolate->cpu_profiler()->processor_->CodeCreateEvent(
tag,
name,
- isolate_->heap()->empty_string(),
+ isolate->heap()->empty_string(),
v8::CpuProfileNode::kNoLineNumberInfo,
code->address(),
code->ExecutableSize(),
Code* code,
SharedFunctionInfo* shared,
Name* name) {
- processor_->CodeCreateEvent(
+ Isolate* isolate = Isolate::Current();
+ isolate->cpu_profiler()->processor_->CodeCreateEvent(
tag,
name,
- isolate_->heap()->empty_string(),
+ isolate->heap()->empty_string(),
v8::CpuProfileNode::kNoLineNumberInfo,
code->address(),
code->ExecutableSize(),
Code* code,
SharedFunctionInfo* shared,
String* source, int line) {
- processor_->CodeCreateEvent(
+ Isolate::Current()->cpu_profiler()->processor_->CodeCreateEvent(
tag,
shared->DebugName(),
source,
void CpuProfiler::CodeCreateEvent(Logger::LogEventsAndTags tag,
Code* code, int args_count) {
- processor_->CodeCreateEvent(
+ Isolate::Current()->cpu_profiler()->processor_->CodeCreateEvent(
tag,
args_count,
code->address(),
void CpuProfiler::CodeMoveEvent(Address from, Address to) {
- processor_->CodeMoveEvent(from, to);
+ Isolate::Current()->cpu_profiler()->processor_->CodeMoveEvent(from, to);
}
void CpuProfiler::SharedFunctionInfoMoveEvent(Address from, Address to) {
- processor_->SharedFunctionInfoMoveEvent(from, to);
+ CpuProfiler* profiler = Isolate::Current()->cpu_profiler();
+ profiler->processor_->SharedFunctionInfoMoveEvent(from, to);
}
void CpuProfiler::GetterCallbackEvent(Name* name, Address entry_point) {
- processor_->CallbackCreateEvent(
+ Isolate::Current()->cpu_profiler()->processor_->CallbackCreateEvent(
Logger::CALLBACK_TAG, "get ", name, entry_point);
}
void CpuProfiler::RegExpCodeCreateEvent(Code* code, String* source) {
- processor_->RegExpCodeCreateEvent(
+ Isolate::Current()->cpu_profiler()->processor_->RegExpCodeCreateEvent(
Logger::REG_EXP_TAG,
"RegExp: ",
source,
void CpuProfiler::SetterCallbackEvent(Name* name, Address entry_point) {
- processor_->CallbackCreateEvent(
+ Isolate::Current()->cpu_profiler()->processor_->CallbackCreateEvent(
Logger::CALLBACK_TAG, "set ", name, entry_point);
}
-CpuProfiler::CpuProfiler(Isolate* isolate)
- : isolate_(isolate),
- profiles_(new CpuProfilesCollection()),
+CpuProfiler::CpuProfiler()
+ : profiles_(new CpuProfilesCollection()),
next_profile_uid_(1),
token_enumerator_(new TokenEnumerator()),
generator_(NULL),
profiles_ = new CpuProfilesCollection();
}
-void CpuProfiler::StartProfiling(const char* title, bool record_samples) {
- if (profiles_->StartProfiling(title, next_profile_uid_++, record_samples)) {
+void CpuProfiler::StartCollectingProfile(const char* title) {
+ if (profiles_->StartProfiling(title, next_profile_uid_++)) {
StartProcessorIfNotStarted();
}
processor_->AddCurrentStack();
}
-void CpuProfiler::StartProfiling(String* title, bool record_samples) {
- StartProfiling(profiles_->GetName(title), record_samples);
+void CpuProfiler::StartCollectingProfile(String* title) {
+ StartCollectingProfile(profiles_->GetName(title));
}
void CpuProfiler::StartProcessorIfNotStarted() {
if (processor_ == NULL) {
+ Isolate* isolate = Isolate::Current();
+
// Disable logging when using the new implementation.
- saved_logging_nesting_ = isolate_->logger()->logging_nesting_;
- isolate_->logger()->logging_nesting_ = 0;
+ saved_logging_nesting_ = isolate->logger()->logging_nesting_;
+ isolate->logger()->logging_nesting_ = 0;
generator_ = new ProfileGenerator(profiles_);
processor_ = new ProfilerEventsProcessor(generator_);
is_profiling_ = true;
processor_->Start();
// Enumerate stuff we already have in the heap.
- if (isolate_->heap()->HasBeenSetUp()) {
+ if (isolate->heap()->HasBeenSetUp()) {
if (!FLAG_prof_browser_mode) {
bool saved_log_code_flag = FLAG_log_code;
FLAG_log_code = true;
- isolate_->logger()->LogCodeObjects();
+ isolate->logger()->LogCodeObjects();
FLAG_log_code = saved_log_code_flag;
}
- isolate_->logger()->LogCompiledFunctions();
- isolate_->logger()->LogAccessorCallbacks();
+ isolate->logger()->LogCompiledFunctions();
+ isolate->logger()->LogAccessorCallbacks();
}
// Enable stack sampling.
- Sampler* sampler = reinterpret_cast<Sampler*>(isolate_->logger()->ticker_);
+ Sampler* sampler = reinterpret_cast<Sampler*>(isolate->logger()->ticker_);
if (!sampler->IsActive()) {
sampler->Start();
need_to_stop_sampler_ = true;
}
-CpuProfile* CpuProfiler::StopProfiling(const char* title) {
- if (!is_profiling_) return NULL;
+CpuProfile* CpuProfiler::StopCollectingProfile(const char* title) {
const double actual_sampling_rate = generator_->actual_sampling_rate();
StopProcessorIfLastProfile(title);
CpuProfile* result =
}
-CpuProfile* CpuProfiler::StopProfiling(Object* security_token, String* title) {
- if (!is_profiling_) return NULL;
+CpuProfile* CpuProfiler::StopCollectingProfile(Object* security_token,
+ String* title) {
const double actual_sampling_rate = generator_->actual_sampling_rate();
const char* profile_title = profiles_->GetName(title);
StopProcessorIfLastProfile(profile_title);
void CpuProfiler::StopProcessor() {
- Logger* logger = isolate_->logger();
+ Logger* logger = Isolate::Current()->logger();
Sampler* sampler = reinterpret_cast<Sampler*>(logger->ticker_);
sampler->DecreaseProfilingDepth();
if (need_to_stop_sampler_) {
}
+void CpuProfiler::SetUp() {
+ Isolate* isolate = Isolate::Current();
+ if (isolate->cpu_profiler() == NULL) {
+ isolate->set_cpu_profiler(new CpuProfiler());
+ }
+}
+
+
+void CpuProfiler::TearDown() {
+ Isolate* isolate = Isolate::Current();
+ if (isolate->cpu_profiler() != NULL) {
+ delete isolate->cpu_profiler();
+ }
+ isolate->set_cpu_profiler(NULL);
+}
+
} } // namespace v8::internal
unsigned enqueue_order_;
};
+} } // namespace v8::internal
+
-#define PROFILE(IsolateGetter, Call) \
- do { \
- Isolate* cpu_profiler_isolate = (IsolateGetter); \
- LOG_CODE_EVENT(cpu_profiler_isolate, Call); \
- CpuProfiler* cpu_profiler = cpu_profiler_isolate->cpu_profiler(); \
- if (cpu_profiler->is_profiling()) { \
- cpu_profiler->Call; \
- } \
+#define PROFILE(isolate, Call) \
+ LOG_CODE_EVENT(isolate, Call); \
+ do { \
+ if (v8::internal::CpuProfiler::is_profiling(isolate)) { \
+ v8::internal::CpuProfiler::Call; \
+ } \
} while (false)
+namespace v8 {
+namespace internal {
+
+
+// TODO(isolates): isolatify this class.
class CpuProfiler {
public:
- explicit CpuProfiler(Isolate* isolate);
- ~CpuProfiler();
-
- void StartProfiling(const char* title, bool record_samples = false);
- void StartProfiling(String* title, bool record_samples);
- CpuProfile* StopProfiling(const char* title);
- CpuProfile* StopProfiling(Object* security_token, String* title);
- int GetProfilesCount();
- CpuProfile* GetProfile(Object* security_token, int index);
- CpuProfile* FindProfile(Object* security_token, unsigned uid);
- void DeleteAllProfiles();
- void DeleteProfile(CpuProfile* profile);
- bool HasDetachedProfiles();
+ static void SetUp();
+ static void TearDown();
+
+ static void StartProfiling(const char* title);
+ static void StartProfiling(String* title);
+ static CpuProfile* StopProfiling(const char* title);
+ static CpuProfile* StopProfiling(Object* security_token, String* title);
+ static int GetProfilesCount();
+ static CpuProfile* GetProfile(Object* security_token, int index);
+ static CpuProfile* FindProfile(Object* security_token, unsigned uid);
+ static void DeleteAllProfiles();
+ static void DeleteProfile(CpuProfile* profile);
+ static bool HasDetachedProfiles();
// Invoked from stack sampler (thread or signal handler.)
- TickSample* TickSampleEvent();
+ static TickSample* TickSampleEvent(Isolate* isolate);
// Must be called via PROFILE macro, otherwise will crash when
// profiling is not enabled.
- void CallbackEvent(Name* name, Address entry_point);
- void CodeCreateEvent(Logger::LogEventsAndTags tag,
- Code* code, const char* comment);
- void CodeCreateEvent(Logger::LogEventsAndTags tag,
- Code* code, Name* name);
- void CodeCreateEvent(Logger::LogEventsAndTags tag,
- Code* code,
+ static void CallbackEvent(Name* name, Address entry_point);
+ static void CodeCreateEvent(Logger::LogEventsAndTags tag,
+ Code* code, const char* comment);
+ static void CodeCreateEvent(Logger::LogEventsAndTags tag,
+ Code* code, Name* name);
+ static void CodeCreateEvent(Logger::LogEventsAndTags tag,
+ Code* code,
SharedFunctionInfo* shared,
Name* name);
- void CodeCreateEvent(Logger::LogEventsAndTags tag,
- Code* code,
- SharedFunctionInfo* shared,
- String* source, int line);
- void CodeCreateEvent(Logger::LogEventsAndTags tag,
- Code* code, int args_count);
- void CodeMovingGCEvent() {}
- void CodeMoveEvent(Address from, Address to);
- void CodeDeleteEvent(Address from);
- void GetterCallbackEvent(Name* name, Address entry_point);
- void RegExpCodeCreateEvent(Code* code, String* source);
- void SetterCallbackEvent(Name* name, Address entry_point);
- void SharedFunctionInfoMoveEvent(Address from, Address to);
-
- INLINE(bool is_profiling() const) { return is_profiling_; }
+ static void CodeCreateEvent(Logger::LogEventsAndTags tag,
+ Code* code,
+ SharedFunctionInfo* shared,
+ String* source, int line);
+ static void CodeCreateEvent(Logger::LogEventsAndTags tag,
+ Code* code, int args_count);
+ static void CodeMovingGCEvent() {}
+ static void CodeMoveEvent(Address from, Address to);
+ static void CodeDeleteEvent(Address from);
+ static void GetterCallbackEvent(Name* name, Address entry_point);
+ static void RegExpCodeCreateEvent(Code* code, String* source);
+ static void SetterCallbackEvent(Name* name, Address entry_point);
+ static void SharedFunctionInfoMoveEvent(Address from, Address to);
+
+ static INLINE(bool is_profiling(Isolate* isolate)) {
+ CpuProfiler* profiler = isolate->cpu_profiler();
+ return profiler != NULL && profiler->is_profiling_;
+ }
private:
+ CpuProfiler();
+ ~CpuProfiler();
+ void StartCollectingProfile(const char* title);
+ void StartCollectingProfile(String* title);
void StartProcessorIfNotStarted();
+ CpuProfile* StopCollectingProfile(const char* title);
+ CpuProfile* StopCollectingProfile(Object* security_token, String* title);
void StopProcessorIfLastProfile(const char* title);
void StopProcessor();
void ResetProfiles();
- Isolate* isolate_;
CpuProfilesCollection* profiles_;
unsigned next_profile_uid_;
TokenEnumerator* token_enumerator_;
}
-void StackGuard::CancelTerminateExecution() {
- ExecutionAccess access(isolate_);
- Continue(TERMINATE);
- isolate_->CancelTerminateExecution();
-}
-
-
void StackGuard::TerminateExecution() {
ExecutionAccess access(isolate_);
thread_local_.interrupt_flags_ |= TERMINATE;
void Interrupt();
bool IsTerminateExecution();
void TerminateExecution();
- void CancelTerminateExecution();
#ifdef ENABLE_DEBUGGER_SUPPORT
bool IsDebugBreak();
void DebugBreak();
}
-void HeapProfiler::DeleteAllSnapshots() {
+void HeapProfiler::ResetSnapshots() {
Heap* the_heap = heap();
delete snapshots_;
snapshots_ = new HeapSnapshotsCollection(the_heap);
}
+void HeapProfiler::SetUp() {
+ Isolate* isolate = Isolate::Current();
+ if (isolate->heap_profiler() == NULL) {
+ isolate->set_heap_profiler(new HeapProfiler(isolate->heap()));
+ }
+}
+
+
+void HeapProfiler::TearDown() {
+ Isolate* isolate = Isolate::Current();
+ delete isolate->heap_profiler();
+ isolate->set_heap_profiler(NULL);
+}
+
+
+HeapSnapshot* HeapProfiler::TakeSnapshot(
+ const char* name,
+ int type,
+ v8::ActivityControl* control,
+ v8::HeapProfiler::ObjectNameResolver* resolver) {
+ ASSERT(Isolate::Current()->heap_profiler() != NULL);
+ return Isolate::Current()->heap_profiler()->TakeSnapshotImpl(name,
+ type,
+ control,
+ resolver);
+}
+
+
+HeapSnapshot* HeapProfiler::TakeSnapshot(
+ String* name,
+ int type,
+ v8::ActivityControl* control,
+ v8::HeapProfiler::ObjectNameResolver* resolver) {
+ ASSERT(Isolate::Current()->heap_profiler() != NULL);
+ return Isolate::Current()->heap_profiler()->TakeSnapshotImpl(name,
+ type,
+ control,
+ resolver);
+}
+
+
+void HeapProfiler::StartHeapObjectsTracking() {
+ ASSERT(Isolate::Current()->heap_profiler() != NULL);
+ Isolate::Current()->heap_profiler()->StartHeapObjectsTrackingImpl();
+}
+
+
+void HeapProfiler::StopHeapObjectsTracking() {
+ ASSERT(Isolate::Current()->heap_profiler() != NULL);
+ Isolate::Current()->heap_profiler()->StopHeapObjectsTrackingImpl();
+}
+
+
+SnapshotObjectId HeapProfiler::PushHeapObjectsStats(v8::OutputStream* stream) {
+ ASSERT(Isolate::Current()->heap_profiler() != NULL);
+ return Isolate::Current()->heap_profiler()->PushHeapObjectsStatsImpl(stream);
+}
+
+
void HeapProfiler::DefineWrapperClass(
uint16_t class_id, v8::HeapProfiler::WrapperInfoCallback callback) {
ASSERT(class_id != v8::HeapProfiler::kPersistentHandleNoClassId);
}
-HeapSnapshot* HeapProfiler::TakeSnapshot(
+HeapSnapshot* HeapProfiler::TakeSnapshotImpl(
const char* name,
+ int type,
v8::ActivityControl* control,
v8::HeapProfiler::ObjectNameResolver* resolver) {
- HeapSnapshot* result = snapshots_->NewSnapshot(name, next_snapshot_uid_++);
- {
- HeapSnapshotGenerator generator(result, control, resolver, heap());
- if (!generator.GenerateSnapshot()) {
- delete result;
- result = NULL;
+ HeapSnapshot::Type s_type = static_cast<HeapSnapshot::Type>(type);
+ HeapSnapshot* result =
+ snapshots_->NewSnapshot(s_type, name, next_snapshot_uid_++);
+ bool generation_completed = true;
+ switch (s_type) {
+ case HeapSnapshot::kFull: {
+ HeapSnapshotGenerator generator(result, control, resolver, heap());
+ generation_completed = generator.GenerateSnapshot();
+ break;
}
+ default:
+ UNREACHABLE();
+ }
+ if (!generation_completed) {
+ delete result;
+ result = NULL;
}
snapshots_->SnapshotGenerationFinished(result);
return result;
}
-HeapSnapshot* HeapProfiler::TakeSnapshot(
+HeapSnapshot* HeapProfiler::TakeSnapshotImpl(
String* name,
+ int type,
v8::ActivityControl* control,
v8::HeapProfiler::ObjectNameResolver* resolver) {
- return TakeSnapshot(snapshots_->names()->GetName(name), control, resolver);
+ return TakeSnapshotImpl(snapshots_->names()->GetName(name), type, control,
+ resolver);
}
-void HeapProfiler::StartHeapObjectsTracking() {
+void HeapProfiler::StartHeapObjectsTrackingImpl() {
snapshots_->StartHeapObjectsTracking();
}
-SnapshotObjectId HeapProfiler::PushHeapObjectsStats(OutputStream* stream) {
+SnapshotObjectId HeapProfiler::PushHeapObjectsStatsImpl(OutputStream* stream) {
return snapshots_->PushHeapObjectsStats(stream);
}
-void HeapProfiler::StopHeapObjectsTracking() {
+void HeapProfiler::StopHeapObjectsTrackingImpl() {
snapshots_->StopHeapObjectsTracking();
}
size_t HeapProfiler::GetMemorySizeUsedByProfiler() {
- return snapshots_->GetUsedMemorySize();
+ HeapProfiler* profiler = Isolate::Current()->heap_profiler();
+ ASSERT(profiler != NULL);
+ size_t size = profiler->snapshots_->GetUsedMemorySize();
+ return size;
}
int HeapProfiler::GetSnapshotsCount() {
- return snapshots_->snapshots()->length();
+ HeapProfiler* profiler = Isolate::Current()->heap_profiler();
+ ASSERT(profiler != NULL);
+ return profiler->snapshots_->snapshots()->length();
}
HeapSnapshot* HeapProfiler::GetSnapshot(int index) {
- return snapshots_->snapshots()->at(index);
+ HeapProfiler* profiler = Isolate::Current()->heap_profiler();
+ ASSERT(profiler != NULL);
+ return profiler->snapshots_->snapshots()->at(index);
}
HeapSnapshot* HeapProfiler::FindSnapshot(unsigned uid) {
- return snapshots_->GetSnapshot(uid);
+ HeapProfiler* profiler = Isolate::Current()->heap_profiler();
+ ASSERT(profiler != NULL);
+ return profiler->snapshots_->GetSnapshot(uid);
}
SnapshotObjectId HeapProfiler::GetSnapshotObjectId(Handle<Object> obj) {
if (!obj->IsHeapObject())
return v8::HeapProfiler::kUnknownObjectId;
- return snapshots_->FindObjectId(HeapObject::cast(*obj)->address());
+ HeapProfiler* profiler = Isolate::Current()->heap_profiler();
+ ASSERT(profiler != NULL);
+ return profiler->snapshots_->FindObjectId(HeapObject::cast(*obj)->address());
+}
+
+
+void HeapProfiler::DeleteAllSnapshots() {
+ HeapProfiler* profiler = Isolate::Current()->heap_profiler();
+ ASSERT(profiler != NULL);
+ profiler->ResetSnapshots();
}
class HeapProfiler {
public:
- explicit HeapProfiler(Heap* heap);
- ~HeapProfiler();
+ static void SetUp();
+ static void TearDown();
- size_t GetMemorySizeUsedByProfiler();
+ static size_t GetMemorySizeUsedByProfiler();
- HeapSnapshot* TakeSnapshot(
+ static HeapSnapshot* TakeSnapshot(
const char* name,
+ int type,
v8::ActivityControl* control,
v8::HeapProfiler::ObjectNameResolver* resolver);
- HeapSnapshot* TakeSnapshot(
+ static HeapSnapshot* TakeSnapshot(
String* name,
+ int type,
v8::ActivityControl* control,
v8::HeapProfiler::ObjectNameResolver* resolver);
- void StartHeapObjectsTracking();
- void StopHeapObjectsTracking();
- SnapshotObjectId PushHeapObjectsStats(OutputStream* stream);
- int GetSnapshotsCount();
- HeapSnapshot* GetSnapshot(int index);
- HeapSnapshot* FindSnapshot(unsigned uid);
- SnapshotObjectId GetSnapshotObjectId(Handle<Object> obj);
- void DeleteAllSnapshots();
+ static void StartHeapObjectsTracking();
+ static void StopHeapObjectsTracking();
+ static SnapshotObjectId PushHeapObjectsStats(OutputStream* stream);
+ static int GetSnapshotsCount();
+ static HeapSnapshot* GetSnapshot(int index);
+ static HeapSnapshot* FindSnapshot(unsigned uid);
+ static SnapshotObjectId GetSnapshotObjectId(Handle<Object> obj);
+ static void DeleteAllSnapshots();
void ObjectMoveEvent(Address from, Address to);
}
private:
+ explicit HeapProfiler(Heap* heap);
+ ~HeapProfiler();
+ HeapSnapshot* TakeSnapshotImpl(
+ const char* name,
+ int type,
+ v8::ActivityControl* control,
+ v8::HeapProfiler::ObjectNameResolver* resolver);
+ HeapSnapshot* TakeSnapshotImpl(
+ String* name,
+ int type,
+ v8::ActivityControl* control,
+ v8::HeapProfiler::ObjectNameResolver* resolver);
+ void ResetSnapshots();
+
+ void StartHeapObjectsTrackingImpl();
+ void StopHeapObjectsTrackingImpl();
+ SnapshotObjectId PushHeapObjectsStatsImpl(OutputStream* stream);
+
Heap* heap() const { return snapshots_->heap(); }
HeapSnapshotsCollection* snapshots_;
static const int kExpectedHeapGraphEdgeSize = 12;
static const int kExpectedHeapEntrySize = 24;
static const int kExpectedHeapSnapshotsCollectionSize = 100;
- static const int kExpectedHeapSnapshotSize = 132;
+ static const int kExpectedHeapSnapshotSize = 136;
static const size_t kMaxSerializableSnapshotRawSize = 256 * MB;
};
static const int kExpectedHeapGraphEdgeSize = 24;
static const int kExpectedHeapEntrySize = 32;
static const int kExpectedHeapSnapshotsCollectionSize = 152;
- static const int kExpectedHeapSnapshotSize = 160;
+ static const int kExpectedHeapSnapshotSize = 168;
static const uint64_t kMaxSerializableSnapshotRawSize =
static_cast<uint64_t>(6000) * MB;
};
} // namespace
HeapSnapshot::HeapSnapshot(HeapSnapshotsCollection* collection,
+ HeapSnapshot::Type type,
const char* title,
unsigned uid)
: collection_(collection),
+ type_(type),
title_(title),
uid_(uid),
root_index_(HeapEntry::kNoEntry),
}
-HeapSnapshot* HeapSnapshotsCollection::NewSnapshot(const char* name,
+HeapSnapshot* HeapSnapshotsCollection::NewSnapshot(HeapSnapshot::Type type,
+ const char* name,
unsigned uid) {
is_tracking_objects_ = true; // Start watching for heap objects moves.
- return new HeapSnapshot(this, name, uid);
+ return new HeapSnapshot(this, type, name, uid);
}
HeapSnapshot* HeapSnapshotJSONSerializer::CreateFakeSnapshot() {
HeapSnapshot* result = new HeapSnapshot(snapshot_->collection(),
+ HeapSnapshot::kFull,
snapshot_->title(),
snapshot_->uid());
result->AddRootEntry();
// HeapSnapshotGenerator fills in a HeapSnapshot.
class HeapSnapshot {
public:
+ enum Type {
+ kFull = v8::HeapSnapshot::kFull
+ };
+
HeapSnapshot(HeapSnapshotsCollection* collection,
+ Type type,
const char* title,
unsigned uid);
void Delete();
HeapSnapshotsCollection* collection() { return collection_; }
+ Type type() { return type_; }
const char* title() { return title_; }
unsigned uid() { return uid_; }
size_t RawSnapshotSize() const;
private:
HeapSnapshotsCollection* collection_;
+ Type type_;
const char* title_;
unsigned uid_;
int root_index_;
void StartHeapObjectsTracking() { is_tracking_objects_ = true; }
void StopHeapObjectsTracking() { ids_.StopHeapObjectsTracking(); }
- HeapSnapshot* NewSnapshot(const char* name, unsigned uid);
+ HeapSnapshot* NewSnapshot(
+ HeapSnapshot::Type type, const char* name, unsigned uid);
void SnapshotGenerationFinished(HeapSnapshot* snapshot);
List<HeapSnapshot*>* snapshots() { return &snapshots_; }
HeapSnapshot* GetSnapshot(unsigned uid);
HEAP_PROFILE(heap, ObjectMoveEvent(source->address(), target->address()));
Isolate* isolate = heap->isolate();
if (isolate->logger()->is_logging_code_events() ||
- isolate->cpu_profiler()->is_profiling()) {
+ CpuProfiler::is_profiling(isolate)) {
if (target->IsSharedFunctionInfo()) {
PROFILE(isolate, SharedFunctionInfoMoveEvent(
source->address(), target->address()));
void Heap::SelectScavengingVisitorsTable() {
bool logging_and_profiling =
isolate()->logger()->is_logging() ||
- isolate()->cpu_profiler()->is_profiling() ||
+ CpuProfiler::is_profiling(isolate()) ||
(isolate()->heap_profiler() != NULL &&
isolate()->heap_profiler()->is_profiling());
}
-void Isolate::CancelTerminateExecution() {
- if (try_catch_handler()) {
- try_catch_handler()->has_terminated_ = false;
- }
- if (has_pending_exception() &&
- pending_exception() == heap_.termination_exception()) {
- thread_local_top()->external_caught_exception_ = false;
- clear_pending_exception();
- }
- if (has_scheduled_exception() &&
- scheduled_exception() == heap_.termination_exception()) {
- thread_local_top()->external_caught_exception_ = false;
- clear_scheduled_exception();
- }
-}
-
-
Failure* Isolate::Throw(Object* exception, MessageLocation* location) {
DoThrow(exception, location);
return Failure::Exception();
date_cache_(NULL),
code_stub_interface_descriptors_(NULL),
context_exit_happened_(false),
- cpu_profiler_(NULL),
- heap_profiler_(NULL),
deferred_handles_head_(NULL),
optimizing_compiler_thread_(this),
marking_thread_(NULL),
preallocated_message_space_ = NULL;
PreallocatedMemoryThreadStop();
- delete heap_profiler_;
- heap_profiler_ = NULL;
- delete cpu_profiler_;
- cpu_profiler_ = NULL;
-
+ HeapProfiler::TearDown();
+ CpuProfiler::TearDown();
if (runtime_profiler_ != NULL) {
runtime_profiler_->TearDown();
delete runtime_profiler_;
} else if (thread_local_top_.pending_exception_ ==
heap()->termination_exception()) {
try_catch_handler()->can_continue_ = false;
- try_catch_handler()->has_terminated_ = true;
try_catch_handler()->exception_ = heap()->null_value();
} else {
// At this point all non-object (failure) exceptions have
// been dealt with so this shouldn't fail.
ASSERT(!pending_exception()->IsFailure());
try_catch_handler()->can_continue_ = true;
- try_catch_handler()->has_terminated_ = false;
try_catch_handler()->exception_ = pending_exception();
if (!thread_local_top_.pending_message_obj_->IsTheHole()) {
try_catch_handler()->message_ = thread_local_top_.pending_message_obj_;
// Enable logging before setting up the heap
logger_->SetUp();
- cpu_profiler_ = new CpuProfiler(this);
- heap_profiler_ = new HeapProfiler(heap());
+ CpuProfiler::SetUp();
+ HeapProfiler::SetUp();
// Initialize other runtime facilities
#if defined(USE_SIMULATOR)
V(FunctionInfoListener*, active_function_info_listener, NULL) \
/* State for Relocatable. */ \
V(Relocatable*, relocatable_top, NULL) \
+ /* State for CodeEntry in profile-generator. */ \
+ V(CodeGenerator*, current_code_generator, NULL) \
+ V(bool, jump_target_compiling_deferred_code, false) \
V(DebugObjectCache*, string_stream_debug_object_cache, NULL) \
V(Object*, string_stream_current_security_token, NULL) \
/* TODO(isolates): Release this on destruction? */ \
V(unsigned, ast_node_count, 0) \
/* SafeStackFrameIterator activations count. */ \
V(int, safe_stack_iterator_counter, 0) \
+ V(CpuProfiler*, cpu_profiler, NULL) \
+ V(HeapProfiler*, heap_profiler, NULL) \
V(bool, observer_delivery_pending, false) \
V(HStatistics*, hstatistics, NULL) \
V(HTracer*, htracer, NULL) \
// Out of resource exception helpers.
Failure* StackOverflow();
Failure* TerminateExecution();
- void CancelTerminateExecution();
// Administration
void Iterate(ObjectVisitor* v);
inline bool IsDebuggerActive();
inline bool DebuggerHasBreakPoints();
- CpuProfiler* cpu_profiler() const { return cpu_profiler_; }
- HeapProfiler* heap_profiler() const { return heap_profiler_; }
-
#ifdef DEBUG
HistogramInfo* heap_histograms() { return heap_histograms_; }
Debugger* debugger_;
Debug* debug_;
#endif
- CpuProfiler* cpu_profiler_;
- HeapProfiler* heap_profiler_;
#define GLOBAL_BACKING_STORE(type, name, initialvalue) \
type name##_;
tag = Logger::KEYED_CALL_IC_TAG;
break;
}
- PROFILE(isolate_, CodeCreateEvent(tag, code_object, description));
+ PROFILE(ISOLATE, CodeCreateEvent(tag, code_object, description));
}
}
Handle<String> script_name(String::cast(script->name()));
int line_num = GetScriptLineNumber(script, shared->start_position());
if (line_num > 0) {
- PROFILE(isolate_,
+ PROFILE(ISOLATE,
CodeCreateEvent(
Logger::ToNativeByScript(Logger::LAZY_COMPILE_TAG, *script),
*code, *shared,
*script_name, line_num + 1));
} else {
// Can't distinguish eval and script here, so always use Script.
- PROFILE(isolate_,
+ PROFILE(ISOLATE,
CodeCreateEvent(
Logger::ToNativeByScript(Logger::SCRIPT_TAG, *script),
*code, *shared, *script_name));
}
} else {
- PROFILE(isolate_,
+ PROFILE(ISOLATE,
CodeCreateEvent(
Logger::ToNativeByScript(Logger::LAZY_COMPILE_TAG, *script),
*code, *shared, *func_name));
CallHandlerInfo* call_data = CallHandlerInfo::cast(raw_call_data);
Object* callback_obj = call_data->callback();
Address entry_point = v8::ToCData<Address>(callback_obj);
- PROFILE(isolate_, CallbackEvent(*func_name, entry_point));
+ PROFILE(ISOLATE, CallbackEvent(*func_name, entry_point));
}
} else {
- PROFILE(isolate_,
+ PROFILE(ISOLATE,
CodeCreateEvent(
Logger::LAZY_COMPILE_TAG, *code, *shared, *func_name));
}
Address getter_entry = v8::ToCData<Address>(ai->getter());
Name* name = Name::cast(ai->name());
if (getter_entry != 0) {
- PROFILE(isolate_, GetterCallbackEvent(name, getter_entry));
+ PROFILE(ISOLATE, GetterCallbackEvent(name, getter_entry));
}
Address setter_entry = v8::ToCData<Address>(ai->setter());
if (setter_entry != 0) {
- PROFILE(isolate_, SetterCallbackEvent(name, setter_entry));
+ PROFILE(ISOLATE, SetterCallbackEvent(name, setter_entry));
}
}
}
class Ticker;
class Isolate;
class PositionsRecorder;
-class CpuProfiler;
#undef LOG
#define LOG(isolate, Call) \
CONTEXT context;
memset(&context, 0, sizeof(context));
- Isolate* isolate = sampler->isolate();
TickSample sample_obj;
- TickSample* sample = isolate->cpu_profiler()->TickSampleEvent();
+ TickSample* sample = CpuProfiler::TickSampleEvent(sampler->isolate());
if (sample == NULL) sample = &sample_obj;
static const DWORD kSuspendFailed = static_cast<DWORD>(-1);
if (SuspendThread(profiled_thread) == kSuspendFailed) return;
- sample->state = isolate->current_vm_state();
+ sample->state = sampler->isolate()->current_vm_state();
context.ContextFlags = CONTEXT_FULL;
if (GetThreadContext(profiled_thread, &context) != 0) {
if (sampler == NULL || !sampler->IsActive()) return;
TickSample sample_obj;
- TickSample* sample = isolate->cpu_profiler()->TickSampleEvent();
+ TickSample* sample = CpuProfiler::TickSampleEvent(isolate);
if (sample == NULL) sample = &sample_obj;
// Extracting the sample from the context is extremely machine dependent.
if (sampler == NULL || !sampler->IsActive()) return;
TickSample sample_obj;
- TickSample* sample = isolate->cpu_profiler()->TickSampleEvent();
+ TickSample* sample = CpuProfiler::TickSampleEvent(isolate);
if (sample == NULL) sample = &sample_obj;
// Extracting the sample from the context is extremely machine dependent.
void SampleContext(Sampler* sampler) {
thread_act_t profiled_thread = sampler->platform_data()->profiled_thread();
- Isolate* isolate = sampler->isolate();
TickSample sample_obj;
- TickSample* sample = isolate->cpu_profiler()->TickSampleEvent();
+ TickSample* sample = CpuProfiler::TickSampleEvent(sampler->isolate());
if (sample == NULL) sample = &sample_obj;
if (KERN_SUCCESS != thread_suspend(profiled_thread)) return;
flavor,
reinterpret_cast<natural_t*>(&state),
&count) == KERN_SUCCESS) {
- sample->state = isolate->current_vm_state();
+ sample->state = sampler->isolate()->current_vm_state();
sample->pc = reinterpret_cast<Address>(state.REGISTER_FIELD(ip));
sample->sp = reinterpret_cast<Address>(state.REGISTER_FIELD(sp));
sample->fp = reinterpret_cast<Address>(state.REGISTER_FIELD(bp));
if (sampler == NULL || !sampler->IsActive()) return;
TickSample sample_obj;
- TickSample* sample = isolate->cpu_profiler()->TickSampleEvent();
+ TickSample* sample = CpuProfiler::TickSampleEvent(isolate);
if (sample == NULL) sample = &sample_obj;
// Extracting the sample from the context is extremely machine dependent.
if (sampler == NULL || !sampler->IsActive()) return;
TickSample sample_obj;
- TickSample* sample = isolate->cpu_profiler()->TickSampleEvent();
+ TickSample* sample = CpuProfiler::TickSampleEvent(isolate);
if (sample == NULL) sample = &sample_obj;
// Extracting the sample from the context is extremely machine dependent.
CONTEXT context;
memset(&context, 0, sizeof(context));
- Isolate* isolate = sampler->isolate();
TickSample sample_obj;
- TickSample* sample = isolate->cpu_profiler()->TickSampleEvent();
+ TickSample* sample = CpuProfiler::TickSampleEvent(sampler->isolate());
if (sample == NULL) sample = &sample_obj;
static const DWORD kSuspendFailed = static_cast<DWORD>(-1);
if (SuspendThread(profiled_thread) == kSuspendFailed) return;
- sample->state = isolate->current_vm_state();
+ sample->state = sampler->isolate()->current_vm_state();
context.ContextFlags = CONTEXT_FULL;
if (GetThreadContext(profiled_thread, &context) != 0) {
entry_(entry),
total_ticks_(0),
self_ticks_(0),
- children_(CodeEntriesMatch),
- id_(tree->next_node_id()) {
+ children_(CodeEntriesMatch) {
}
"",
0,
TokenEnumerator::kNoSecurityToken),
- next_node_id_(1),
root_(new ProfileNode(this, &root_entry_)) {
}
}
-ProfileNode* ProfileTree::AddPathFromEnd(const Vector<CodeEntry*>& path) {
+void ProfileTree::AddPathFromEnd(const Vector<CodeEntry*>& path) {
ProfileNode* node = root_;
for (CodeEntry** entry = path.start() + path.length() - 1;
entry != path.start() - 1;
}
}
node->IncrementSelfTicks();
- return node;
}
void CpuProfile::AddPath(const Vector<CodeEntry*>& path) {
- ProfileNode* top_frame_node = top_down_.AddPathFromEnd(path);
- if (record_samples_) samples_.Add(top_frame_node);
+ top_down_.AddPathFromEnd(path);
}
CpuProfile* CpuProfile::FilteredClone(int security_token_id) {
ASSERT(security_token_id != TokenEnumerator::kNoSecurityToken);
- CpuProfile* clone = new CpuProfile(title_, uid_, false);
+ CpuProfile* clone = new CpuProfile(title_, uid_);
clone->top_down_.FilteredClone(&top_down_, security_token_id);
return clone;
}
}
-bool CpuProfilesCollection::StartProfiling(const char* title, unsigned uid,
- bool record_samples) {
+bool CpuProfilesCollection::StartProfiling(const char* title, unsigned uid) {
ASSERT(uid > 0);
current_profiles_semaphore_->Wait();
if (current_profiles_.length() >= kMaxSimultaneousProfiles) {
return false;
}
}
- current_profiles_.Add(new CpuProfile(title, uid, record_samples));
+ current_profiles_.Add(new CpuProfile(title, uid));
current_profiles_semaphore_->Signal();
return true;
}
+bool CpuProfilesCollection::StartProfiling(String* title, unsigned uid) {
+ return StartProfiling(GetName(title), uid);
+}
+
+
CpuProfile* CpuProfilesCollection::StopProfiling(int security_token_id,
const char* title,
double actual_sampling_rate) {
INLINE(const List<ProfileNode*>* children() const) { return &children_list_; }
double GetSelfMillis() const;
double GetTotalMillis() const;
- unsigned id() const { return id_; }
void Print(int indent);
// Mapping from CodeEntry* to ProfileNode*
HashMap children_;
List<ProfileNode*> children_list_;
- unsigned id_;
DISALLOW_COPY_AND_ASSIGN(ProfileNode);
};
ProfileTree();
~ProfileTree();
- ProfileNode* AddPathFromEnd(const Vector<CodeEntry*>& path);
+ void AddPathFromEnd(const Vector<CodeEntry*>& path);
void AddPathFromStart(const Vector<CodeEntry*>& path);
void CalculateTotalTicks();
void FilteredClone(ProfileTree* src, int security_token_id);
ProfileNode* root() const { return root_; }
void SetTickRatePerMs(double ticks_per_ms);
- unsigned next_node_id() { return next_node_id_++; }
-
void ShortPrint();
void Print() {
root_->Print(0);
void TraverseDepthFirst(Callback* callback);
CodeEntry root_entry_;
- unsigned next_node_id_;
ProfileNode* root_;
double ms_to_ticks_scale_;
class CpuProfile {
public:
- CpuProfile(const char* title, unsigned uid, bool record_samples)
- : title_(title), uid_(uid), record_samples_(record_samples) { }
+ CpuProfile(const char* title, unsigned uid)
+ : title_(title), uid_(uid) { }
// Add pc -> ... -> main() call path to the profile.
void AddPath(const Vector<CodeEntry*>& path);
INLINE(unsigned uid() const) { return uid_; }
INLINE(const ProfileTree* top_down() const) { return &top_down_; }
- INLINE(int samples_count() const) { return samples_.length(); }
- INLINE(ProfileNode* sample(int index) const) { return samples_.at(index); }
-
void UpdateTicksScale();
void ShortPrint();
private:
const char* title_;
unsigned uid_;
- bool record_samples_;
- List<ProfileNode*> samples_;
ProfileTree top_down_;
DISALLOW_COPY_AND_ASSIGN(CpuProfile);
CpuProfilesCollection();
~CpuProfilesCollection();
- bool StartProfiling(const char* title, unsigned uid, bool record_samples);
+ bool StartProfiling(const char* title, unsigned uid);
+ bool StartProfiling(String* title, unsigned uid);
CpuProfile* StopProfiling(int security_token_id,
const char* title,
double actual_sampling_rate);
target->set_literals(*literals);
if (isolate->logger()->is_logging_code_events() ||
- isolate->cpu_profiler()->is_profiling()) {
+ CpuProfiler::is_profiling(isolate)) {
isolate->logger()->LogExistingFunction(
source_shared, Handle<Code>(source_shared->code()));
}
i::Factory* factory = isolate->factory();
TestSetup test_setup;
CpuProfilesCollection profiles;
- profiles.StartProfiling("", 1, false);
+ profiles.StartProfiling("", 1);
ProfileGenerator generator(&profiles);
ProfilerEventsProcessor processor(&generator);
processor.Start();
TEST(TickEvents) {
TestSetup test_setup;
CpuProfilesCollection profiles;
- profiles.StartProfiling("", 1, false);
+ profiles.StartProfiling("", 1);
ProfileGenerator generator(&profiles);
ProfilerEventsProcessor processor(&generator);
processor.Start();
TEST(CrashIfStoppingLastNonExistentProfile) {
InitializeVM();
TestSetup test_setup;
- CpuProfiler* profiler = i::Isolate::Current()->cpu_profiler();
- profiler->StartProfiling("1");
- profiler->StopProfiling("2");
- profiler->StartProfiling("1");
- profiler->StopProfiling("");
+ CpuProfiler::SetUp();
+ CpuProfiler::StartProfiling("1");
+ CpuProfiler::StopProfiling("2");
+ CpuProfiler::StartProfiling("1");
+ CpuProfiler::StopProfiling("");
+ CpuProfiler::TearDown();
}
TEST(Issue1398) {
TestSetup test_setup;
CpuProfilesCollection profiles;
- profiles.StartProfiling("", 1, false);
+ profiles.StartProfiling("", 1);
ProfileGenerator generator(&profiles);
ProfilerEventsProcessor processor(&generator);
processor.Start();
TEST(DeleteAllCpuProfiles) {
InitializeVM();
TestSetup test_setup;
- CpuProfiler* profiler = i::Isolate::Current()->cpu_profiler();
- CHECK_EQ(0, profiler->GetProfilesCount());
- profiler->DeleteAllProfiles();
- CHECK_EQ(0, profiler->GetProfilesCount());
-
- profiler->StartProfiling("1");
- profiler->StopProfiling("1");
- CHECK_EQ(1, profiler->GetProfilesCount());
- profiler->DeleteAllProfiles();
- CHECK_EQ(0, profiler->GetProfilesCount());
- profiler->StartProfiling("1");
- profiler->StartProfiling("2");
- profiler->StopProfiling("2");
- profiler->StopProfiling("1");
- CHECK_EQ(2, profiler->GetProfilesCount());
- profiler->DeleteAllProfiles();
- CHECK_EQ(0, profiler->GetProfilesCount());
+ CpuProfiler::SetUp();
+ CHECK_EQ(0, CpuProfiler::GetProfilesCount());
+ CpuProfiler::DeleteAllProfiles();
+ CHECK_EQ(0, CpuProfiler::GetProfilesCount());
+
+ CpuProfiler::StartProfiling("1");
+ CpuProfiler::StopProfiling("1");
+ CHECK_EQ(1, CpuProfiler::GetProfilesCount());
+ CpuProfiler::DeleteAllProfiles();
+ CHECK_EQ(0, CpuProfiler::GetProfilesCount());
+ CpuProfiler::StartProfiling("1");
+ CpuProfiler::StartProfiling("2");
+ CpuProfiler::StopProfiling("2");
+ CpuProfiler::StopProfiling("1");
+ CHECK_EQ(2, CpuProfiler::GetProfilesCount());
+ CpuProfiler::DeleteAllProfiles();
+ CHECK_EQ(0, CpuProfiler::GetProfilesCount());
// Test profiling cancellation by the 'delete' command.
- profiler->StartProfiling("1");
- profiler->StartProfiling("2");
- CHECK_EQ(0, profiler->GetProfilesCount());
- profiler->DeleteAllProfiles();
- CHECK_EQ(0, profiler->GetProfilesCount());
+ CpuProfiler::StartProfiling("1");
+ CpuProfiler::StartProfiling("2");
+ CHECK_EQ(0, CpuProfiler::GetProfilesCount());
+ CpuProfiler::DeleteAllProfiles();
+ CHECK_EQ(0, CpuProfiler::GetProfilesCount());
+
+ CpuProfiler::TearDown();
}
TEST(DeleteCpuProfile) {
LocalContext env;
v8::HandleScope scope(env->GetIsolate());
- v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler();
- CHECK_EQ(0, cpu_profiler->GetProfileCount());
+ CHECK_EQ(0, v8::CpuProfiler::GetProfilesCount());
v8::Local<v8::String> name1 = v8::String::New("1");
- cpu_profiler->StartCpuProfiling(name1);
- const v8::CpuProfile* p1 = cpu_profiler->StopCpuProfiling(name1);
+ v8::CpuProfiler::StartProfiling(name1);
+ const v8::CpuProfile* p1 = v8::CpuProfiler::StopProfiling(name1);
CHECK_NE(NULL, p1);
- CHECK_EQ(1, cpu_profiler->GetProfileCount());
+ CHECK_EQ(1, v8::CpuProfiler::GetProfilesCount());
unsigned uid1 = p1->GetUid();
- CHECK_EQ(p1, cpu_profiler->FindCpuProfile(uid1));
+ CHECK_EQ(p1, v8::CpuProfiler::FindProfile(uid1));
const_cast<v8::CpuProfile*>(p1)->Delete();
- CHECK_EQ(0, cpu_profiler->GetProfileCount());
- CHECK_EQ(NULL, cpu_profiler->FindCpuProfile(uid1));
+ CHECK_EQ(0, CpuProfiler::GetProfilesCount());
+ CHECK_EQ(NULL, v8::CpuProfiler::FindProfile(uid1));
v8::Local<v8::String> name2 = v8::String::New("2");
- cpu_profiler->StartCpuProfiling(name2);
- const v8::CpuProfile* p2 = cpu_profiler->StopCpuProfiling(name2);
+ v8::CpuProfiler::StartProfiling(name2);
+ const v8::CpuProfile* p2 = v8::CpuProfiler::StopProfiling(name2);
CHECK_NE(NULL, p2);
- CHECK_EQ(1, cpu_profiler->GetProfileCount());
+ CHECK_EQ(1, v8::CpuProfiler::GetProfilesCount());
unsigned uid2 = p2->GetUid();
CHECK_NE(static_cast<int>(uid1), static_cast<int>(uid2));
- CHECK_EQ(p2, cpu_profiler->FindCpuProfile(uid2));
- CHECK_EQ(NULL, cpu_profiler->FindCpuProfile(uid1));
+ CHECK_EQ(p2, v8::CpuProfiler::FindProfile(uid2));
+ CHECK_EQ(NULL, v8::CpuProfiler::FindProfile(uid1));
v8::Local<v8::String> name3 = v8::String::New("3");
- cpu_profiler->StartCpuProfiling(name3);
- const v8::CpuProfile* p3 = cpu_profiler->StopCpuProfiling(name3);
+ v8::CpuProfiler::StartProfiling(name3);
+ const v8::CpuProfile* p3 = v8::CpuProfiler::StopProfiling(name3);
CHECK_NE(NULL, p3);
- CHECK_EQ(2, cpu_profiler->GetProfileCount());
+ CHECK_EQ(2, v8::CpuProfiler::GetProfilesCount());
unsigned uid3 = p3->GetUid();
CHECK_NE(static_cast<int>(uid1), static_cast<int>(uid3));
- CHECK_EQ(p3, cpu_profiler->FindCpuProfile(uid3));
- CHECK_EQ(NULL, cpu_profiler->FindCpuProfile(uid1));
+ CHECK_EQ(p3, v8::CpuProfiler::FindProfile(uid3));
+ CHECK_EQ(NULL, v8::CpuProfiler::FindProfile(uid1));
const_cast<v8::CpuProfile*>(p2)->Delete();
- CHECK_EQ(1, cpu_profiler->GetProfileCount());
- CHECK_EQ(NULL, cpu_profiler->FindCpuProfile(uid2));
- CHECK_EQ(p3, cpu_profiler->FindCpuProfile(uid3));
+ CHECK_EQ(1, v8::CpuProfiler::GetProfilesCount());
+ CHECK_EQ(NULL, v8::CpuProfiler::FindProfile(uid2));
+ CHECK_EQ(p3, v8::CpuProfiler::FindProfile(uid3));
const_cast<v8::CpuProfile*>(p3)->Delete();
- CHECK_EQ(0, cpu_profiler->GetProfileCount());
- CHECK_EQ(NULL, cpu_profiler->FindCpuProfile(uid3));
- CHECK_EQ(NULL, cpu_profiler->FindCpuProfile(uid2));
- CHECK_EQ(NULL, cpu_profiler->FindCpuProfile(uid1));
+ CHECK_EQ(0, CpuProfiler::GetProfilesCount());
+ CHECK_EQ(NULL, v8::CpuProfiler::FindProfile(uid3));
+ CHECK_EQ(NULL, v8::CpuProfiler::FindProfile(uid2));
+ CHECK_EQ(NULL, v8::CpuProfiler::FindProfile(uid1));
}
TEST(DeleteCpuProfileDifferentTokens) {
LocalContext env;
v8::HandleScope scope(env->GetIsolate());
- v8::CpuProfiler* cpu_profiler = env->GetIsolate()->GetCpuProfiler();
- CHECK_EQ(0, cpu_profiler->GetProfileCount());
+ CHECK_EQ(0, v8::CpuProfiler::GetProfilesCount());
v8::Local<v8::String> name1 = v8::String::New("1");
- cpu_profiler->StartCpuProfiling(name1);
- const v8::CpuProfile* p1 = cpu_profiler->StopCpuProfiling(name1);
+ v8::CpuProfiler::StartProfiling(name1);
+ const v8::CpuProfile* p1 = v8::CpuProfiler::StopProfiling(name1);
CHECK_NE(NULL, p1);
- CHECK_EQ(1, cpu_profiler->GetProfileCount());
+ CHECK_EQ(1, v8::CpuProfiler::GetProfilesCount());
unsigned uid1 = p1->GetUid();
- CHECK_EQ(p1, cpu_profiler->FindCpuProfile(uid1));
+ CHECK_EQ(p1, v8::CpuProfiler::FindProfile(uid1));
v8::Local<v8::String> token1 = v8::String::New("token1");
- const v8::CpuProfile* p1_t1 = cpu_profiler->FindCpuProfile(uid1, token1);
+ const v8::CpuProfile* p1_t1 = v8::CpuProfiler::FindProfile(uid1, token1);
CHECK_NE(NULL, p1_t1);
CHECK_NE(p1, p1_t1);
- CHECK_EQ(1, cpu_profiler->GetProfileCount());
+ CHECK_EQ(1, v8::CpuProfiler::GetProfilesCount());
const_cast<v8::CpuProfile*>(p1)->Delete();
- CHECK_EQ(0, cpu_profiler->GetProfileCount());
- CHECK_EQ(NULL, cpu_profiler->FindCpuProfile(uid1));
- CHECK_EQ(NULL, cpu_profiler->FindCpuProfile(uid1, token1));
+ CHECK_EQ(0, CpuProfiler::GetProfilesCount());
+ CHECK_EQ(NULL, v8::CpuProfiler::FindProfile(uid1));
+ CHECK_EQ(NULL, v8::CpuProfiler::FindProfile(uid1, token1));
const_cast<v8::CpuProfile*>(p1_t1)->Delete();
- CHECK_EQ(0, cpu_profiler->GetProfileCount());
+ CHECK_EQ(0, CpuProfiler::GetProfilesCount());
v8::Local<v8::String> name2 = v8::String::New("2");
- cpu_profiler->StartCpuProfiling(name2);
+ v8::CpuProfiler::StartProfiling(name2);
v8::Local<v8::String> token2 = v8::String::New("token2");
- const v8::CpuProfile* p2_t2 = cpu_profiler->StopCpuProfiling(name2, token2);
+ const v8::CpuProfile* p2_t2 = v8::CpuProfiler::StopProfiling(name2, token2);
CHECK_NE(NULL, p2_t2);
- CHECK_EQ(1, cpu_profiler->GetProfileCount());
+ CHECK_EQ(1, v8::CpuProfiler::GetProfilesCount());
unsigned uid2 = p2_t2->GetUid();
CHECK_NE(static_cast<int>(uid1), static_cast<int>(uid2));
- const v8::CpuProfile* p2 = cpu_profiler->FindCpuProfile(uid2);
+ const v8::CpuProfile* p2 = v8::CpuProfiler::FindProfile(uid2);
CHECK_NE(p2_t2, p2);
v8::Local<v8::String> name3 = v8::String::New("3");
- cpu_profiler->StartCpuProfiling(name3);
- const v8::CpuProfile* p3 = cpu_profiler->StopCpuProfiling(name3);
+ v8::CpuProfiler::StartProfiling(name3);
+ const v8::CpuProfile* p3 = v8::CpuProfiler::StopProfiling(name3);
CHECK_NE(NULL, p3);
- CHECK_EQ(2, cpu_profiler->GetProfileCount());
+ CHECK_EQ(2, v8::CpuProfiler::GetProfilesCount());
unsigned uid3 = p3->GetUid();
CHECK_NE(static_cast<int>(uid1), static_cast<int>(uid3));
- CHECK_EQ(p3, cpu_profiler->FindCpuProfile(uid3));
+ CHECK_EQ(p3, v8::CpuProfiler::FindProfile(uid3));
const_cast<v8::CpuProfile*>(p2_t2)->Delete();
- CHECK_EQ(1, cpu_profiler->GetProfileCount());
- CHECK_EQ(NULL, cpu_profiler->FindCpuProfile(uid2));
- CHECK_EQ(p3, cpu_profiler->FindCpuProfile(uid3));
+ CHECK_EQ(1, v8::CpuProfiler::GetProfilesCount());
+ CHECK_EQ(NULL, v8::CpuProfiler::FindProfile(uid2));
+ CHECK_EQ(p3, v8::CpuProfiler::FindProfile(uid3));
const_cast<v8::CpuProfile*>(p2)->Delete();
- CHECK_EQ(1, cpu_profiler->GetProfileCount());
- CHECK_EQ(NULL, cpu_profiler->FindCpuProfile(uid2));
- CHECK_EQ(p3, cpu_profiler->FindCpuProfile(uid3));
+ CHECK_EQ(1, v8::CpuProfiler::GetProfilesCount());
+ CHECK_EQ(NULL, v8::CpuProfiler::FindProfile(uid2));
+ CHECK_EQ(p3, v8::CpuProfiler::FindProfile(uid3));
const_cast<v8::CpuProfile*>(p3)->Delete();
- CHECK_EQ(0, cpu_profiler->GetProfileCount());
- CHECK_EQ(NULL, cpu_profiler->FindCpuProfile(uid3));
+ CHECK_EQ(0, CpuProfiler::GetProfilesCount());
+ CHECK_EQ(NULL, v8::CpuProfiler::FindProfile(uid3));
}
TEST(HeapSnapshot) {
LocalContext env2;
v8::HandleScope scope(env2->GetIsolate());
- v8::HeapProfiler* heap_profiler = env2->GetIsolate()->GetHeapProfiler();
CompileRun(
"function A2() {}\n"
"var b2_1 = new B2(a2), b2_2 = new B2(a2);\n"
"var c2 = new C2(a2);");
const v8::HeapSnapshot* snapshot_env2 =
- heap_profiler->TakeHeapSnapshot(v8_str("env2"));
+ v8::HeapProfiler::TakeSnapshot(v8_str("env2"));
const v8::HeapGraphNode* global_env2 = GetGlobalObject(snapshot_env2);
// Verify, that JS global object of env2 has '..2' properties.
TEST(HeapSnapshotObjectSizes) {
LocalContext env;
v8::HandleScope scope(env->GetIsolate());
- v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
// -a-> X1 --a
// x -b-> X2 <-|
"dummy = new X();\n"
"(function() { x.a.a = x.b; })();");
const v8::HeapSnapshot* snapshot =
- heap_profiler->TakeHeapSnapshot(v8_str("sizes"));
+ v8::HeapProfiler::TakeSnapshot(v8_str("sizes"));
const v8::HeapGraphNode* global = GetGlobalObject(snapshot);
const v8::HeapGraphNode* x =
GetProperty(global, v8::HeapGraphEdge::kProperty, "x");
TEST(BoundFunctionInSnapshot) {
LocalContext env;
v8::HandleScope scope(env->GetIsolate());
- v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
CompileRun(
"function myFunction(a, b) { this.a = a; this.b = b; }\n"
"function AAAAA() {}\n"
"boundFunction = myFunction.bind(new AAAAA(), 20, new Number(12)); \n");
const v8::HeapSnapshot* snapshot =
- heap_profiler->TakeHeapSnapshot(v8_str("sizes"));
+ v8::HeapProfiler::TakeSnapshot(v8_str("sizes"));
const v8::HeapGraphNode* global = GetGlobalObject(snapshot);
const v8::HeapGraphNode* f =
GetProperty(global, v8::HeapGraphEdge::kProperty, "boundFunction");
TEST(HeapSnapshotEntryChildren) {
LocalContext env;
v8::HandleScope scope(env->GetIsolate());
- v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
CompileRun(
"function A() { }\n"
"a = new A;");
const v8::HeapSnapshot* snapshot =
- heap_profiler->TakeHeapSnapshot(v8_str("children"));
+ v8::HeapProfiler::TakeSnapshot(v8_str("children"));
const v8::HeapGraphNode* global = GetGlobalObject(snapshot);
for (int i = 0, count = global->GetChildrenCount(); i < count; ++i) {
const v8::HeapGraphEdge* prop = global->GetChild(i);
TEST(HeapSnapshotCodeObjects) {
LocalContext env;
v8::HandleScope scope(env->GetIsolate());
- v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
CompileRun(
"function lazy(x) { return x - 1; }\n"
"var anonymous = (function() { return function() { return 0; } })();\n"
"compiled(1)");
const v8::HeapSnapshot* snapshot =
- heap_profiler->TakeHeapSnapshot(v8_str("code"));
+ v8::HeapProfiler::TakeSnapshot(v8_str("code"));
const v8::HeapGraphNode* global = GetGlobalObject(snapshot);
const v8::HeapGraphNode* compiled =
TEST(HeapSnapshotHeapNumbers) {
LocalContext env;
v8::HandleScope scope(env->GetIsolate());
- v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
CompileRun(
"a = 1; // a is Smi\n"
"b = 2.5; // b is HeapNumber");
const v8::HeapSnapshot* snapshot =
- heap_profiler->TakeHeapSnapshot(v8_str("numbers"));
+ v8::HeapProfiler::TakeSnapshot(v8_str("numbers"));
const v8::HeapGraphNode* global = GetGlobalObject(snapshot);
CHECK_EQ(NULL, GetProperty(global, v8::HeapGraphEdge::kProperty, "a"));
const v8::HeapGraphNode* b =
TEST(HeapSnapshotSlicedString) {
LocalContext env;
v8::HandleScope scope(env->GetIsolate());
- v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
CompileRun(
"parent_string = \"123456789.123456789.123456789.123456789.123456789."
"123456789.123456789.123456789.123456789.123456789."
"123456789.123456789.123456789.123456789.123456789.\";"
"child_string = parent_string.slice(100);");
const v8::HeapSnapshot* snapshot =
- heap_profiler->TakeHeapSnapshot(v8_str("strings"));
+ v8::HeapProfiler::TakeSnapshot(v8_str("strings"));
const v8::HeapGraphNode* global = GetGlobalObject(snapshot);
const v8::HeapGraphNode* parent_string =
GetProperty(global, v8::HeapGraphEdge::kProperty, "parent_string");
}
TEST(HeapSnapshotInternalReferences) {
- v8::Isolate* isolate = v8::Isolate::GetCurrent();
- v8::HandleScope scope(isolate);
+ v8::HandleScope scope(v8::Isolate::GetCurrent());
v8::Local<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New();
global_template->SetInternalFieldCount(2);
LocalContext env(NULL, global_template);
v8::Local<v8::Object> obj = v8::Object::New();
global->SetInternalField(0, v8_num(17));
global->SetInternalField(1, obj);
- v8::HeapProfiler* heap_profiler = isolate->GetHeapProfiler();
const v8::HeapSnapshot* snapshot =
- heap_profiler->TakeHeapSnapshot(v8_str("internals"));
+ v8::HeapProfiler::TakeSnapshot(v8_str("internals"));
const v8::HeapGraphNode* global_node = GetGlobalObject(snapshot);
// The first reference will not present, because it's a Smi.
CHECK_EQ(NULL, GetProperty(global_node, v8::HeapGraphEdge::kInternal, "0"));
TEST(HeapSnapshotAddressReuse) {
LocalContext env;
v8::HandleScope scope(env->GetIsolate());
- v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
CompileRun(
"function A() {}\n"
"for (var i = 0; i < 10000; ++i)\n"
" a[i] = new A();\n");
const v8::HeapSnapshot* snapshot1 =
- heap_profiler->TakeHeapSnapshot(v8_str("snapshot1"));
+ v8::HeapProfiler::TakeSnapshot(v8_str("snapshot1"));
v8::SnapshotObjectId maxId1 = snapshot1->GetMaxSnapshotJSObjectId();
CompileRun(
HEAP->CollectAllGarbage(i::Heap::kNoGCFlags);
const v8::HeapSnapshot* snapshot2 =
- heap_profiler->TakeHeapSnapshot(v8_str("snapshot2"));
+ v8::HeapProfiler::TakeSnapshot(v8_str("snapshot2"));
const v8::HeapGraphNode* global2 = GetGlobalObject(snapshot2);
const v8::HeapGraphNode* array_node =
TEST(HeapEntryIdsAndArrayShift) {
LocalContext env;
v8::HandleScope scope(env->GetIsolate());
- v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
CompileRun(
"function AnObject() {\n"
"for (var i = 0; i < 10; ++i)\n"
" a.push(new AnObject());\n");
const v8::HeapSnapshot* snapshot1 =
- heap_profiler->TakeHeapSnapshot(v8_str("s1"));
+ v8::HeapProfiler::TakeSnapshot(v8_str("s1"));
CompileRun(
"for (var i = 0; i < 1; ++i)\n"
HEAP->CollectAllGarbage(i::Heap::kNoGCFlags);
const v8::HeapSnapshot* snapshot2 =
- heap_profiler->TakeHeapSnapshot(v8_str("s2"));
+ v8::HeapProfiler::TakeSnapshot(v8_str("s2"));
const v8::HeapGraphNode* global1 = GetGlobalObject(snapshot1);
const v8::HeapGraphNode* global2 = GetGlobalObject(snapshot2);
TEST(HeapEntryIdsAndGC) {
LocalContext env;
v8::HandleScope scope(env->GetIsolate());
- v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
CompileRun(
"function A() {}\n"
v8::Local<v8::String> s1_str = v8_str("s1");
v8::Local<v8::String> s2_str = v8_str("s2");
const v8::HeapSnapshot* snapshot1 =
- heap_profiler->TakeHeapSnapshot(s1_str);
+ v8::HeapProfiler::TakeSnapshot(s1_str);
HEAP->CollectAllGarbage(i::Heap::kNoGCFlags);
const v8::HeapSnapshot* snapshot2 =
- heap_profiler->TakeHeapSnapshot(s2_str);
+ v8::HeapProfiler::TakeSnapshot(s2_str);
CHECK_GT(snapshot1->GetMaxSnapshotJSObjectId(), 7000);
CHECK(snapshot1->GetMaxSnapshotJSObjectId() <=
TEST(HeapSnapshotRootPreservedAfterSorting) {
LocalContext env;
v8::HandleScope scope(env->GetIsolate());
- v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
const v8::HeapSnapshot* snapshot =
- heap_profiler->TakeHeapSnapshot(v8_str("s"));
+ v8::HeapProfiler::TakeSnapshot(v8_str("s"));
const v8::HeapGraphNode* root1 = snapshot->GetRoot();
const_cast<i::HeapSnapshot*>(reinterpret_cast<const i::HeapSnapshot*>(
snapshot))->GetSortedEntriesList();
TEST(HeapSnapshotJSONSerialization) {
LocalContext env;
v8::HandleScope scope(env->GetIsolate());
- v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
#define STRING_LITERAL_FOR_TEST \
"\"String \\n\\r\\u0008\\u0081\\u0101\\u0801\\u8001\""
"var a = new A(" STRING_LITERAL_FOR_TEST ");\n"
"var b = new B(a);");
const v8::HeapSnapshot* snapshot =
- heap_profiler->TakeHeapSnapshot(v8_str("json"));
+ v8::HeapProfiler::TakeSnapshot(v8_str("json"));
TestJSONStream stream;
snapshot->Serialize(&stream, v8::HeapSnapshot::kJSON);
CHECK_GT(stream.size(), 0);
TEST(HeapSnapshotJSONSerializationAborting) {
LocalContext env;
v8::HandleScope scope(env->GetIsolate());
- v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
const v8::HeapSnapshot* snapshot =
- heap_profiler->TakeHeapSnapshot(v8_str("abort"));
+ v8::HeapProfiler::TakeSnapshot(v8_str("abort"));
TestJSONStream stream(5);
snapshot->Serialize(&stream, v8::HeapSnapshot::kJSON);
CHECK_GT(stream.size(), 0);
} // namespace
static TestStatsStream GetHeapStatsUpdate(
- v8::HeapProfiler* heap_profiler,
v8::SnapshotObjectId* object_id = NULL) {
TestStatsStream stream;
- v8::SnapshotObjectId last_seen_id = heap_profiler->GetHeapStats(&stream);
+ v8::SnapshotObjectId last_seen_id =
+ v8::HeapProfiler::PushHeapObjectsStats(&stream);
if (object_id)
*object_id = last_seen_id;
CHECK_EQ(1, stream.eos_signaled());
TEST(HeapSnapshotObjectsStats) {
LocalContext env;
v8::HandleScope scope(env->GetIsolate());
- v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
- heap_profiler->StartTrackingHeapObjects();
+ v8::HeapProfiler::StartHeapObjectsTracking();
// We have to call GC 6 times. In other case the garbage will be
// the reason of flakiness.
for (int i = 0; i < 6; ++i) {
v8::SnapshotObjectId initial_id;
{
// Single chunk of data expected in update. Initial data.
- TestStatsStream stats_update = GetHeapStatsUpdate(heap_profiler,
- &initial_id);
+ TestStatsStream stats_update = GetHeapStatsUpdate(&initial_id);
CHECK_EQ(1, stats_update.intervals_count());
CHECK_EQ(1, stats_update.updates_written());
CHECK_LT(0, stats_update.entries_size());
// No data expected in update because nothing has happened.
v8::SnapshotObjectId same_id;
- CHECK_EQ(0, GetHeapStatsUpdate(heap_profiler, &same_id).updates_written());
+ CHECK_EQ(0, GetHeapStatsUpdate(&same_id).updates_written());
CHECK_EQ_SNAPSHOT_OBJECT_ID(initial_id, same_id);
{
v8_str("string1");
{
// Single chunk of data with one new entry expected in update.
- TestStatsStream stats_update = GetHeapStatsUpdate(heap_profiler,
- &additional_string_id);
+ TestStatsStream stats_update = GetHeapStatsUpdate(&additional_string_id);
CHECK_LT(same_id, additional_string_id);
CHECK_EQ(1, stats_update.intervals_count());
CHECK_EQ(1, stats_update.updates_written());
// No data expected in update because nothing happened.
v8::SnapshotObjectId last_id;
- CHECK_EQ(0, GetHeapStatsUpdate(heap_profiler, &last_id).updates_written());
+ CHECK_EQ(0, GetHeapStatsUpdate(&last_id).updates_written());
CHECK_EQ_SNAPSHOT_OBJECT_ID(additional_string_id, last_id);
{
{
// Single chunk of data with three new entries expected in update.
- TestStatsStream stats_update = GetHeapStatsUpdate(heap_profiler);
+ TestStatsStream stats_update = GetHeapStatsUpdate();
CHECK_EQ(1, stats_update.intervals_count());
CHECK_EQ(1, stats_update.updates_written());
CHECK_LT(0, entries_size = stats_update.entries_size());
{
// Single chunk of data with two left entries expected in update.
- TestStatsStream stats_update = GetHeapStatsUpdate(heap_profiler);
+ TestStatsStream stats_update = GetHeapStatsUpdate();
CHECK_EQ(1, stats_update.intervals_count());
CHECK_EQ(1, stats_update.updates_written());
CHECK_GT(entries_size, stats_update.entries_size());
{
// Single chunk of data with 0 left entries expected in update.
- TestStatsStream stats_update = GetHeapStatsUpdate(heap_profiler);
+ TestStatsStream stats_update = GetHeapStatsUpdate();
CHECK_EQ(1, stats_update.intervals_count());
CHECK_EQ(1, stats_update.updates_written());
CHECK_EQ(0, stats_update.entries_size());
}
{
// Single chunk of data with 0 left entries expected in update.
- TestStatsStream stats_update = GetHeapStatsUpdate(heap_profiler);
+ TestStatsStream stats_update = GetHeapStatsUpdate();
CHECK_EQ(1, stats_update.intervals_count());
CHECK_EQ(1, stats_update.updates_written());
CHECK_EQ(0, stats_update.entries_size());
uint32_t entries_size;
{
// Single chunk of data with 2 entries expected in update.
- TestStatsStream stats_update = GetHeapStatsUpdate(heap_profiler);
+ TestStatsStream stats_update = GetHeapStatsUpdate();
CHECK_EQ(1, stats_update.intervals_count());
CHECK_EQ(1, stats_update.updates_written());
CHECK_LT(0, entries_size = stats_update.entries_size());
{
// Single chunk of data with 1 entry expected in update.
- TestStatsStream stats_update = GetHeapStatsUpdate(heap_profiler);
+ TestStatsStream stats_update = GetHeapStatsUpdate();
CHECK_EQ(1, stats_update.intervals_count());
// The first interval was changed because old buffer was collected.
// The second interval was changed because new buffer was allocated.
CHECK_EQ(8, stats_update.first_interval_index());
}
- heap_profiler->StopTrackingHeapObjects();
+ v8::HeapProfiler::StopHeapObjectsTracking();
}
TEST(HeapSnapshotGetNodeById) {
LocalContext env;
v8::HandleScope scope(env->GetIsolate());
- v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
const v8::HeapSnapshot* snapshot =
- heap_profiler->TakeHeapSnapshot(v8_str("id"));
+ v8::HeapProfiler::TakeSnapshot(v8_str("id"));
const v8::HeapGraphNode* root = snapshot->GetRoot();
CheckChildrenIds(snapshot, root, 0, 3);
// Check a big id, which should not exist yet.
TEST(HeapSnapshotGetSnapshotObjectId) {
LocalContext env;
v8::HandleScope scope(env->GetIsolate());
- v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
CompileRun("globalObject = {};\n");
const v8::HeapSnapshot* snapshot =
- heap_profiler->TakeHeapSnapshot(v8_str("get_snapshot_object_id"));
+ v8::HeapProfiler::TakeSnapshot(v8_str("get_snapshot_object_id"));
const v8::HeapGraphNode* global = GetGlobalObject(snapshot);
const v8::HeapGraphNode* global_object =
GetProperty(global, v8::HeapGraphEdge::kProperty, "globalObject");
CHECK(!globalObjectHandle.IsEmpty());
CHECK(globalObjectHandle->IsObject());
- v8::SnapshotObjectId id = heap_profiler->GetObjectId(globalObjectHandle);
+ v8::SnapshotObjectId id =
+ v8::HeapProfiler::GetSnapshotObjectId(globalObjectHandle);
CHECK_NE(static_cast<int>(v8::HeapProfiler::kUnknownObjectId),
id);
CHECK_EQ(static_cast<int>(id), global_object->GetId());
TEST(HeapSnapshotUnknownSnapshotObjectId) {
LocalContext env;
v8::HandleScope scope(env->GetIsolate());
- v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
CompileRun("globalObject = {};\n");
const v8::HeapSnapshot* snapshot =
- heap_profiler->TakeHeapSnapshot(v8_str("unknown_object_id"));
+ v8::HeapProfiler::TakeSnapshot(v8_str("unknown_object_id"));
const v8::HeapGraphNode* node =
snapshot->GetNodeById(v8::HeapProfiler::kUnknownObjectId);
CHECK_EQ(NULL, node);
LocalContext env;
v8::HandleScope scope(env->GetIsolate());
- v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
- const int snapshots_count = heap_profiler->GetSnapshotCount();
+ const int snapshots_count = v8::HeapProfiler::GetSnapshotsCount();
TestActivityControl aborting_control(1);
const v8::HeapSnapshot* no_snapshot =
- heap_profiler->TakeHeapSnapshot(v8_str("abort"),
+ v8::HeapProfiler::TakeSnapshot(v8_str("abort"),
+ v8::HeapSnapshot::kFull,
&aborting_control);
CHECK_EQ(NULL, no_snapshot);
- CHECK_EQ(snapshots_count, heap_profiler->GetSnapshotCount());
+ CHECK_EQ(snapshots_count, v8::HeapProfiler::GetSnapshotsCount());
CHECK_GT(aborting_control.total(), aborting_control.done());
TestActivityControl control(-1); // Don't abort.
const v8::HeapSnapshot* snapshot =
- heap_profiler->TakeHeapSnapshot(v8_str("full"),
+ v8::HeapProfiler::TakeSnapshot(v8_str("full"),
+ v8::HeapSnapshot::kFull,
&control);
CHECK_NE(NULL, snapshot);
- CHECK_EQ(snapshots_count + 1, heap_profiler->GetSnapshotCount());
+ CHECK_EQ(snapshots_count + 1, v8::HeapProfiler::GetSnapshotsCount());
CHECK_EQ(control.total(), control.done());
CHECK_GT(control.total(), 0);
}
LocalContext env;
v8::Isolate* isolate = env->GetIsolate();
v8::HandleScope scope(isolate);
- v8::HeapProfiler* heap_profiler = isolate->GetHeapProfiler();
- heap_profiler->SetWrapperClassInfoProvider(
+ v8::HeapProfiler::DefineWrapperClass(
1, TestRetainedObjectInfo::WrapperInfoCallback);
- heap_profiler->SetWrapperClassInfoProvider(
+ v8::HeapProfiler::DefineWrapperClass(
2, TestRetainedObjectInfo::WrapperInfoCallback);
v8::Persistent<v8::String> p_AAA =
v8::Persistent<v8::String>::New(isolate, v8_str("AAA"));
p_CCC.SetWrapperClassId(isolate, 2);
CHECK_EQ(0, TestRetainedObjectInfo::instances.length());
const v8::HeapSnapshot* snapshot =
- heap_profiler->TakeHeapSnapshot(v8_str("retained"));
+ v8::HeapProfiler::TakeSnapshot(v8_str("retained"));
CHECK_EQ(3, TestRetainedObjectInfo::instances.length());
for (int i = 0; i < TestRetainedObjectInfo::instances.length(); ++i) {
TEST(HeapSnapshotImplicitReferences) {
LocalContext env;
v8::HandleScope scope(env->GetIsolate());
- v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
GraphWithImplicitRefs graph(&env);
v8::V8::AddGCPrologueCallback(&GraphWithImplicitRefs::gcPrologue);
const v8::HeapSnapshot* snapshot =
- heap_profiler->TakeHeapSnapshot(v8_str("implicit_refs"));
+ v8::HeapProfiler::TakeSnapshot(v8_str("implicit_refs"));
const v8::HeapGraphNode* global_object = GetGlobalObject(snapshot);
const v8::HeapGraphNode* obj0 = GetProperty(
TEST(DeleteAllHeapSnapshots) {
LocalContext env;
v8::HandleScope scope(env->GetIsolate());
- v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
-
- CHECK_EQ(0, heap_profiler->GetSnapshotCount());
- heap_profiler->DeleteAllHeapSnapshots();
- CHECK_EQ(0, heap_profiler->GetSnapshotCount());
- CHECK_NE(NULL, heap_profiler->TakeHeapSnapshot(v8_str("1")));
- CHECK_EQ(1, heap_profiler->GetSnapshotCount());
- heap_profiler->DeleteAllHeapSnapshots();
- CHECK_EQ(0, heap_profiler->GetSnapshotCount());
- CHECK_NE(NULL, heap_profiler->TakeHeapSnapshot(v8_str("1")));
- CHECK_NE(NULL, heap_profiler->TakeHeapSnapshot(v8_str("2")));
- CHECK_EQ(2, heap_profiler->GetSnapshotCount());
- heap_profiler->DeleteAllHeapSnapshots();
- CHECK_EQ(0, heap_profiler->GetSnapshotCount());
+
+ CHECK_EQ(0, v8::HeapProfiler::GetSnapshotsCount());
+ v8::HeapProfiler::DeleteAllSnapshots();
+ CHECK_EQ(0, v8::HeapProfiler::GetSnapshotsCount());
+ CHECK_NE(NULL, v8::HeapProfiler::TakeSnapshot(v8_str("1")));
+ CHECK_EQ(1, v8::HeapProfiler::GetSnapshotsCount());
+ v8::HeapProfiler::DeleteAllSnapshots();
+ CHECK_EQ(0, v8::HeapProfiler::GetSnapshotsCount());
+ CHECK_NE(NULL, v8::HeapProfiler::TakeSnapshot(v8_str("1")));
+ CHECK_NE(NULL, v8::HeapProfiler::TakeSnapshot(v8_str("2")));
+ CHECK_EQ(2, v8::HeapProfiler::GetSnapshotsCount());
+ v8::HeapProfiler::DeleteAllSnapshots();
+ CHECK_EQ(0, v8::HeapProfiler::GetSnapshotsCount());
}
TEST(DeleteHeapSnapshot) {
LocalContext env;
v8::HandleScope scope(env->GetIsolate());
- v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
- CHECK_EQ(0, heap_profiler->GetSnapshotCount());
+ CHECK_EQ(0, v8::HeapProfiler::GetSnapshotsCount());
const v8::HeapSnapshot* s1 =
- heap_profiler->TakeHeapSnapshot(v8_str("1"));
+ v8::HeapProfiler::TakeSnapshot(v8_str("1"));
CHECK_NE(NULL, s1);
- CHECK_EQ(1, heap_profiler->GetSnapshotCount());
+ CHECK_EQ(1, v8::HeapProfiler::GetSnapshotsCount());
unsigned uid1 = s1->GetUid();
- CHECK_EQ(s1, heap_profiler->FindHeapSnapshot(uid1));
+ CHECK_EQ(s1, v8::HeapProfiler::FindSnapshot(uid1));
const_cast<v8::HeapSnapshot*>(s1)->Delete();
- CHECK_EQ(0, heap_profiler->GetSnapshotCount());
- CHECK_EQ(NULL, heap_profiler->FindHeapSnapshot(uid1));
+ CHECK_EQ(0, v8::HeapProfiler::GetSnapshotsCount());
+ CHECK_EQ(NULL, v8::HeapProfiler::FindSnapshot(uid1));
const v8::HeapSnapshot* s2 =
- heap_profiler->TakeHeapSnapshot(v8_str("2"));
+ v8::HeapProfiler::TakeSnapshot(v8_str("2"));
CHECK_NE(NULL, s2);
- CHECK_EQ(1, heap_profiler->GetSnapshotCount());
+ CHECK_EQ(1, v8::HeapProfiler::GetSnapshotsCount());
unsigned uid2 = s2->GetUid();
CHECK_NE(static_cast<int>(uid1), static_cast<int>(uid2));
- CHECK_EQ(s2, heap_profiler->FindHeapSnapshot(uid2));
+ CHECK_EQ(s2, v8::HeapProfiler::FindSnapshot(uid2));
const v8::HeapSnapshot* s3 =
- heap_profiler->TakeHeapSnapshot(v8_str("3"));
+ v8::HeapProfiler::TakeSnapshot(v8_str("3"));
CHECK_NE(NULL, s3);
- CHECK_EQ(2, heap_profiler->GetSnapshotCount());
+ CHECK_EQ(2, v8::HeapProfiler::GetSnapshotsCount());
unsigned uid3 = s3->GetUid();
CHECK_NE(static_cast<int>(uid1), static_cast<int>(uid3));
- CHECK_EQ(s3, heap_profiler->FindHeapSnapshot(uid3));
+ CHECK_EQ(s3, v8::HeapProfiler::FindSnapshot(uid3));
const_cast<v8::HeapSnapshot*>(s2)->Delete();
- CHECK_EQ(1, heap_profiler->GetSnapshotCount());
- CHECK_EQ(NULL, heap_profiler->FindHeapSnapshot(uid2));
- CHECK_EQ(s3, heap_profiler->FindHeapSnapshot(uid3));
+ CHECK_EQ(1, v8::HeapProfiler::GetSnapshotsCount());
+ CHECK_EQ(NULL, v8::HeapProfiler::FindSnapshot(uid2));
+ CHECK_EQ(s3, v8::HeapProfiler::FindSnapshot(uid3));
const_cast<v8::HeapSnapshot*>(s3)->Delete();
- CHECK_EQ(0, heap_profiler->GetSnapshotCount());
- CHECK_EQ(NULL, heap_profiler->FindHeapSnapshot(uid3));
+ CHECK_EQ(0, v8::HeapProfiler::GetSnapshotsCount());
+ CHECK_EQ(NULL, v8::HeapProfiler::FindSnapshot(uid3));
}
TEST(GlobalObjectName) {
LocalContext env;
v8::HandleScope scope(env->GetIsolate());
- v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
CompileRun("document = { URL:\"abcdefgh\" };");
NameResolver name_resolver;
const v8::HeapSnapshot* snapshot =
- heap_profiler->TakeHeapSnapshot(v8_str("document"),
+ v8::HeapProfiler::TakeSnapshot(v8_str("document"),
+ v8::HeapSnapshot::kFull,
NULL,
&name_resolver);
const v8::HeapGraphNode* global = GetGlobalObject(snapshot);
TEST(NoHandleLeaks) {
LocalContext env;
v8::HandleScope scope(env->GetIsolate());
- v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
CompileRun("document = { URL:\"abcdefgh\" };");
v8::Handle<v8::String> name(v8_str("leakz"));
i::Isolate* isolate = i::Isolate::Current();
int count_before = i::HandleScope::NumberOfHandles(isolate);
- heap_profiler->TakeHeapSnapshot(name);
+ v8::HeapProfiler::TakeSnapshot(name);
int count_after = i::HandleScope::NumberOfHandles(isolate);
CHECK_EQ(count_before, count_after);
}
TEST(NodesIteration) {
LocalContext env;
v8::HandleScope scope(env->GetIsolate());
- v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
const v8::HeapSnapshot* snapshot =
- heap_profiler->TakeHeapSnapshot(v8_str("iteration"));
+ v8::HeapProfiler::TakeSnapshot(v8_str("iteration"));
const v8::HeapGraphNode* global = GetGlobalObject(snapshot);
CHECK_NE(NULL, global);
// Verify that we can find this object by iteration.
TEST(GetHeapValue) {
LocalContext env;
v8::HandleScope scope(env->GetIsolate());
- v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
CompileRun("a = { s_prop: \'value\', n_prop: 0.1 };");
const v8::HeapSnapshot* snapshot =
- heap_profiler->TakeHeapSnapshot(v8_str("value"));
+ v8::HeapProfiler::TakeSnapshot(v8_str("value"));
const v8::HeapGraphNode* global = GetGlobalObject(snapshot);
CHECK(global->GetHeapValue()->IsObject());
v8::Local<v8::Object> js_global =
TEST(GetHeapValueForDeletedObject) {
LocalContext env;
v8::HandleScope scope(env->GetIsolate());
- v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
// It is impossible to delete a global property, so we are about to delete a
// property of the "a" object. Also, the "p" object can't be an empty one
// because the empty object is static and isn't actually deleted.
CompileRun("a = { p: { r: {} } };");
const v8::HeapSnapshot* snapshot =
- heap_profiler->TakeHeapSnapshot(v8_str("snapshot"));
+ v8::HeapProfiler::TakeSnapshot(v8_str("snapshot"));
const v8::HeapGraphNode* global = GetGlobalObject(snapshot);
const v8::HeapGraphNode* obj = GetProperty(
global, v8::HeapGraphEdge::kProperty, "a");
TEST(FastCaseGetter) {
LocalContext env;
v8::HandleScope scope(env->GetIsolate());
- v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
CompileRun("var obj1 = {};\n"
"obj1.__defineGetter__('propWithGetter', function Y() {\n"
" return this.value_ = value;\n"
"});\n");
const v8::HeapSnapshot* snapshot =
- heap_profiler->TakeHeapSnapshot(v8_str("fastCaseGetter"));
+ v8::HeapProfiler::TakeSnapshot(v8_str("fastCaseGetter"));
const v8::HeapGraphNode* global = GetGlobalObject(snapshot);
CHECK_NE(NULL, global);
TEST(HiddenPropertiesFastCase) {
LocalContext env;
v8::HandleScope scope(env->GetIsolate());
- v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
CompileRun(
"function C(x) { this.a = this; this.b = x; }\n"
"c = new C(2012);\n");
const v8::HeapSnapshot* snapshot =
- heap_profiler->TakeHeapSnapshot(v8_str("HiddenPropertiesFastCase1"));
+ v8::HeapProfiler::TakeSnapshot(v8_str("HiddenPropertiesFastCase1"));
const v8::HeapGraphNode* global = GetGlobalObject(snapshot);
const v8::HeapGraphNode* c =
GetProperty(global, v8::HeapGraphEdge::kProperty, "c");
CHECK(!cHandle.IsEmpty() && cHandle->IsObject());
cHandle->ToObject()->SetHiddenValue(v8_str("key"), v8_str("val"));
- snapshot = heap_profiler->TakeHeapSnapshot(
+ snapshot = v8::HeapProfiler::TakeSnapshot(
v8_str("HiddenPropertiesFastCase2"));
global = GetGlobalObject(snapshot);
c = GetProperty(global, v8::HeapGraphEdge::kProperty, "c");
bool HasWeakGlobalHandle() {
- v8::Isolate* isolate = v8::Isolate::GetCurrent();
- v8::HeapProfiler* heap_profiler = isolate->GetHeapProfiler();
const v8::HeapSnapshot* snapshot =
- heap_profiler->TakeHeapSnapshot(v8_str("weaks"));
+ v8::HeapProfiler::TakeSnapshot(v8_str("weaks"));
const v8::HeapGraphNode* gc_roots = GetNode(
snapshot->GetRoot(), v8::HeapGraphNode::kObject, "(GC roots)");
CHECK_NE(NULL, gc_roots);
TEST(WeakNativeContextRefs) {
LocalContext env;
v8::HandleScope scope(env->GetIsolate());
- v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
const v8::HeapSnapshot* snapshot =
- heap_profiler->TakeHeapSnapshot(v8_str("weaks"));
+ v8::HeapProfiler::TakeSnapshot(v8_str("weaks"));
const v8::HeapGraphNode* gc_roots = GetNode(
snapshot->GetRoot(), v8::HeapGraphNode::kObject, "(GC roots)");
CHECK_NE(NULL, gc_roots);
TEST(SfiAndJsFunctionWeakRefs) {
LocalContext env;
v8::HandleScope scope(env->GetIsolate());
- v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
CompileRun(
"fun = (function (x) { return function () { return x + 1; } })(1);");
const v8::HeapSnapshot* snapshot =
- heap_profiler->TakeHeapSnapshot(v8_str("fun"));
+ v8::HeapProfiler::TakeSnapshot(v8_str("fun"));
const v8::HeapGraphNode* global = GetGlobalObject(snapshot);
CHECK_NE(NULL, global);
const v8::HeapGraphNode* fun =
TEST(NoDebugObjectInSnapshot) {
LocalContext env;
v8::HandleScope scope(env->GetIsolate());
- v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
v8::internal::Isolate::Current()->debug()->Load();
CompileRun("foo = {};");
const v8::HeapSnapshot* snapshot =
- heap_profiler->TakeHeapSnapshot(v8_str("snapshot"));
+ v8::HeapProfiler::TakeSnapshot(v8_str("snapshot"));
const v8::HeapGraphNode* root = snapshot->GetRoot();
int globals_count = 0;
for (int i = 0; i < root->GetChildrenCount(); ++i) {
TEST(AllStrongGcRootsHaveNames) {
LocalContext env;
v8::HandleScope scope(env->GetIsolate());
- v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
CompileRun("foo = {};");
const v8::HeapSnapshot* snapshot =
- heap_profiler->TakeHeapSnapshot(v8_str("snapshot"));
+ v8::HeapProfiler::TakeSnapshot(v8_str("snapshot"));
const v8::HeapGraphNode* gc_roots = GetNode(
snapshot->GetRoot(), v8::HeapGraphNode::kObject, "(GC roots)");
CHECK_NE(NULL, gc_roots);
TEST(NoRefsToNonEssentialEntries) {
LocalContext env;
v8::HandleScope scope(env->GetIsolate());
- v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
CompileRun("global_object = {};\n");
const v8::HeapSnapshot* snapshot =
- heap_profiler->TakeHeapSnapshot(v8_str("snapshot"));
+ v8::HeapProfiler::TakeSnapshot(v8_str("snapshot"));
const v8::HeapGraphNode* global = GetGlobalObject(snapshot);
const v8::HeapGraphNode* global_object =
GetProperty(global, v8::HeapGraphEdge::kProperty, "global_object");
TEST(MapHasDescriptorsAndTransitions) {
LocalContext env;
v8::HandleScope scope(env->GetIsolate());
- v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
CompileRun("obj = { a: 10 };\n");
const v8::HeapSnapshot* snapshot =
- heap_profiler->TakeHeapSnapshot(v8_str("snapshot"));
+ v8::HeapProfiler::TakeSnapshot(v8_str("snapshot"));
const v8::HeapGraphNode* global = GetGlobalObject(snapshot);
const v8::HeapGraphNode* global_object =
GetProperty(global, v8::HeapGraphEdge::kProperty, "obj");
TEST(ManyLocalsInSharedContext) {
+ v8::HandleScope scope;
LocalContext env;
- v8::HandleScope scope(env->GetIsolate());
- v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
int num_objects = 6000;
CompileRun(
"var n = 6000;"
"result.push('})()');"
"var ok = eval(result.join('\\n'));");
const v8::HeapSnapshot* snapshot =
- heap_profiler->TakeHeapSnapshot(v8_str("snapshot"));
+ v8::HeapProfiler::TakeSnapshot(v8_str("snapshot"));
const v8::HeapGraphNode* global = GetGlobalObject(snapshot);
CHECK_NE(NULL, global);
const v8::HeapGraphNode* ok_object =
TEST(ProfileNodeFindOrAddChild) {
- ProfileTree tree;
- ProfileNode node(&tree, NULL);
+ ProfileNode node(NULL, NULL);
CodeEntry entry1(i::Logger::FUNCTION_TAG, "", "aaa", "", 0,
TokenEnumerator::kNoSecurityToken);
ProfileNode* childNode1 = node.FindOrAddChild(&entry1);
TEST(ProfileNodeFindOrAddChildForSameFunction) {
const char* empty = "";
const char* aaa = "aaa";
- ProfileTree tree;
- ProfileNode node(&tree, NULL);
+ ProfileNode node(NULL, NULL);
CodeEntry entry1(i::Logger::FUNCTION_TAG, empty, aaa, empty, 0,
TokenEnumerator::kNoSecurityToken);
ProfileNode* childNode1 = node.FindOrAddChild(&entry1);
TEST(RecordTickSample) {
TestSetup test_setup;
CpuProfilesCollection profiles;
- profiles.StartProfiling("", 1, false);
+ profiles.StartProfiling("", 1);
ProfileGenerator generator(&profiles);
CodeEntry* entry1 = generator.NewCodeEntry(i::Logger::FUNCTION_TAG, "aaa");
CodeEntry* entry2 = generator.NewCodeEntry(i::Logger::FUNCTION_TAG, "bbb");
}
-static void CheckNodeIds(ProfileNode* node, int* expectedId) {
- CHECK_EQ((*expectedId)++, node->id());
- for (int i = 0; i < node->children()->length(); i++) {
- CheckNodeIds(node->children()->at(i), expectedId);
- }
-}
-
-TEST(SampleIds) {
- TestSetup test_setup;
- CpuProfilesCollection profiles;
- profiles.StartProfiling("", 1, true);
- ProfileGenerator generator(&profiles);
- CodeEntry* entry1 = generator.NewCodeEntry(i::Logger::FUNCTION_TAG, "aaa");
- CodeEntry* entry2 = generator.NewCodeEntry(i::Logger::FUNCTION_TAG, "bbb");
- CodeEntry* entry3 = generator.NewCodeEntry(i::Logger::FUNCTION_TAG, "ccc");
- generator.code_map()->AddCode(ToAddress(0x1500), entry1, 0x200);
- generator.code_map()->AddCode(ToAddress(0x1700), entry2, 0x100);
- generator.code_map()->AddCode(ToAddress(0x1900), entry3, 0x50);
-
- // We are building the following calls tree:
- // -> aaa #3 - sample1
- // (root)#1 -> aaa #2 -> bbb #4 -> ccc #5 - sample2
- // -> ccc #6 -> aaa #7 - sample3
- TickSample sample1;
- sample1.pc = ToAddress(0x1600);
- sample1.stack[0] = ToAddress(0x1510);
- sample1.frames_count = 1;
- generator.RecordTickSample(sample1);
- TickSample sample2;
- sample2.pc = ToAddress(0x1925);
- sample2.stack[0] = ToAddress(0x1780);
- sample2.stack[1] = ToAddress(0x10000); // non-existent.
- sample2.stack[2] = ToAddress(0x1620);
- sample2.frames_count = 3;
- generator.RecordTickSample(sample2);
- TickSample sample3;
- sample3.pc = ToAddress(0x1510);
- sample3.stack[0] = ToAddress(0x1910);
- sample3.stack[1] = ToAddress(0x1610);
- sample3.frames_count = 2;
- generator.RecordTickSample(sample3);
-
- CpuProfile* profile =
- profiles.StopProfiling(TokenEnumerator::kNoSecurityToken, "", 1);
- int nodeId = 1;
- CheckNodeIds(profile->top_down()->root(), &nodeId);
- CHECK_EQ(7, nodeId - 1);
-
- CHECK_EQ(3, profile->samples_count());
- int expected_id[] = {3, 5, 7};
- for (int i = 0; i < 3; i++) {
- CHECK_EQ(expected_id[i], profile->sample(i)->id());
- }
-}
-
-
-TEST(NoSamples) {
- TestSetup test_setup;
- CpuProfilesCollection profiles;
- profiles.StartProfiling("", 1, false);
- ProfileGenerator generator(&profiles);
- CodeEntry* entry1 = generator.NewCodeEntry(i::Logger::FUNCTION_TAG, "aaa");
- generator.code_map()->AddCode(ToAddress(0x1500), entry1, 0x200);
-
- // We are building the following calls tree:
- // (root)#1 -> aaa #2 -> aaa #3 - sample1
- TickSample sample1;
- sample1.pc = ToAddress(0x1600);
- sample1.stack[0] = ToAddress(0x1510);
- sample1.frames_count = 1;
- generator.RecordTickSample(sample1);
-
- CpuProfile* profile =
- profiles.StopProfiling(TokenEnumerator::kNoSecurityToken, "", 1);
- int nodeId = 1;
- CheckNodeIds(profile->top_down()->root(), &nodeId);
- CHECK_EQ(3, nodeId - 1);
-
- CHECK_EQ(0, profile->samples_count());
-}
-
-
// --- P r o f i l e r E x t e n s i o n ---
class ProfilerExtension : public v8::Extension {
v8::Handle<v8::Value> ProfilerExtension::StartProfiling(
const v8::Arguments& args) {
- v8::CpuProfiler* cpu_profiler = args.GetIsolate()->GetCpuProfiler();
if (args.Length() > 0)
- cpu_profiler->StartCpuProfiling(args[0].As<v8::String>());
+ v8::CpuProfiler::StartProfiling(args[0].As<v8::String>());
else
- cpu_profiler->StartCpuProfiling(v8::String::New(""));
+ v8::CpuProfiler::StartProfiling(v8::String::New(""));
return v8::Undefined();
}
v8::Handle<v8::Value> ProfilerExtension::StopProfiling(
const v8::Arguments& args) {
- v8::CpuProfiler* cpu_profiler = args.GetIsolate()->GetCpuProfiler();
if (args.Length() > 0)
- cpu_profiler->StopCpuProfiling(args[0].As<v8::String>());
+ v8::CpuProfiler::StopProfiling(args[0].As<v8::String>());
else
- cpu_profiler->StopCpuProfiling(v8::String::New(""));
+ v8::CpuProfiler::StopProfiling(v8::String::New(""));
return v8::Undefined();
}
v8::HandleScope scope(v8::Isolate::GetCurrent());
env->Enter();
- CpuProfiler* profiler = i::Isolate::Current()->cpu_profiler();
- CHECK_EQ(0, profiler->GetProfilesCount());
+ CHECK_EQ(0, CpuProfiler::GetProfilesCount());
CompileRun(
"function c() { startProfiling(); }\n"
"function b() { c(); }\n"
"function a() { b(); }\n"
"a();\n"
"stopProfiling();");
- CHECK_EQ(1, profiler->GetProfilesCount());
- CpuProfile* profile = profiler->GetProfile(NULL, 0);
+ CHECK_EQ(1, CpuProfiler::GetProfilesCount());
+ CpuProfile* profile =
+ CpuProfiler::GetProfile(NULL, 0);
const ProfileTree* topDown = profile->top_down();
const ProfileNode* current = topDown->root();
const_cast<ProfileNode*>(current)->Print(0);
for (int i = 0; i < CpuProfilesCollection::kMaxSimultaneousProfiles; ++i) {
i::Vector<char> title = i::Vector<char>::New(16);
i::OS::SNPrintF(title, "%d", i);
- // UID must be > 0.
- CHECK(collection.StartProfiling(title.start(), i + 1, false));
+ CHECK(collection.StartProfiling(title.start(), i + 1)); // UID must be > 0.
titles[i] = title.start();
}
CHECK(!collection.StartProfiling(
- "maximum", CpuProfilesCollection::kMaxSimultaneousProfiles + 1, false));
+ "maximum", CpuProfilesCollection::kMaxSimultaneousProfiles + 1));
for (int i = 0; i < CpuProfilesCollection::kMaxSimultaneousProfiles; ++i)
i::DeleteArray(titles[i]);
}
"f()"))->Run()->IsTrue());
context.Dispose(context->GetIsolate());
}
-
-v8::Handle<v8::Value> DoLoopCancelTerminate(const v8::Arguments& args) {
- v8::TryCatch try_catch;
- CHECK(!v8::V8::IsExecutionTerminating());
- v8::Script::Compile(v8::String::New("var term = true;"
- "while(true) {"
- " if (term) terminate();"
- " term = false;"
- "}"
- "fail();"))->Run();
- CHECK(try_catch.HasCaught());
- CHECK(try_catch.Exception()->IsNull());
- CHECK(try_catch.Message().IsEmpty());
- CHECK(!try_catch.CanContinue());
- CHECK(v8::V8::IsExecutionTerminating());
- CHECK(try_catch.HasTerminated());
- v8::V8::CancelTerminateExecution(v8::Isolate::GetCurrent());
- CHECK(!v8::V8::IsExecutionTerminating());
- return v8::Undefined();
-}
-
-// Test that a single thread of JavaScript execution can terminate
-// itself and then resume execution.
-TEST(TerminateCancelTerminateFromThreadItself) {
- v8::HandleScope scope;
- v8::Handle<v8::ObjectTemplate> global =
- CreateGlobalTemplate(TerminateCurrentThread, DoLoopCancelTerminate);
- v8::Persistent<v8::Context> context = v8::Context::New(NULL, global);
- v8::Context::Scope context_scope(context);
- CHECK(!v8::V8::IsExecutionTerminating());
- v8::Handle<v8::String> source =
- v8::String::New("try { doloop(); } catch(e) { fail(); } 'completed';");
- // Check that execution completed with correct return value.
- CHECK(v8::Script::Compile(source)->Run()->Equals(v8_str("completed")));
- context.Dispose(context->GetIsolate());
-}
-