Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(134)

Unified Diff: test/cctest/cctest.h

Issue 22852024: Track JS allocations as they arrive with no affection on performance when tracking is switched off (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Deoptimize code and generate optimized code when switching allocations tracking Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: test/cctest/cctest.h
diff --git a/test/cctest/cctest.h b/test/cctest/cctest.h
index 122d36d5b8383fb30abbcb4fbb359f22ebfc21fb..7621f0b0d8b1a830b9471382c7dfc917288c252b 100644
--- a/test/cctest/cctest.h
+++ b/test/cctest/cctest.h
@@ -79,6 +79,17 @@ typedef v8::internal::EnumSet<CcTestExtensionIds> CcTestExtensionFlags;
#undef DEFINE_EXTENSION_FLAG
+void RunAndTrackAllocations(void (*test)());
+
+#ifndef TEST_TRACK_ALLOCATIONS
+#define TEST_TRACK_ALLOCATIONS(Name) \
+ static void Test##Name(); \
+ TEST(Name##TrackAllocations) { \
+ RunAndTrackAllocations(&Test##Name); \
+ } \
+ TEST(Name)
+#endif
+
class CcTest {
public:
typedef void (TestFunction)();
@@ -340,4 +351,33 @@ static inline void SimulateFullSpace(v8::internal::PagedSpace* space) {
}
+// Helper class for new allocations tracking and checking.
+// To use checking of JS allocations tracking in a test,
+// use TEST_TRACK_ALLOCATIONS macro or just create an instance
+// of this class.
+class HeapObjectsTracker {
+ public:
+ HeapObjectsTracker() {
+ heap_profiler_ = i::Isolate::Current()->heap_profiler();
+ CHECK_NE(NULL, heap_profiler_);
+ heap_profiler_->StartHeapAllocationsRecording();
+ untracked_on_start_ = heap_profiler_->FindUntrackedObjects();
+ }
+
+ virtual ~HeapObjectsTracker() {
+ i::Isolate::Current()->heap()->CollectAllAvailableGarbage();
+ CHECK_EQ(0, CountUntrackedObjects());
+ heap_profiler_->StopHeapAllocationsRecording();
+ }
+
+ private:
+ int CountUntrackedObjects() {
+ return heap_profiler_->FindUntrackedObjects() - untracked_on_start_;
+ }
+
+ i::HeapProfiler* heap_profiler_;
+ int untracked_on_start_;
+};
+
+
#endif // ifndef CCTEST_H_
« no previous file with comments | « src/x64/macro-assembler-x64.cc ('k') | test/cctest/cctest.cc » ('j') | test/cctest/cctest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698