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

Side by Side 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: Make separate API for JS allocations recording, add example of checking JS allocations recording in… 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2008 the V8 project authors. All rights reserved. 1 // Copyright 2008 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 #undef DEFINE_EXTENSION_ID 64 #undef DEFINE_EXTENSION_ID
65 65
66 typedef v8::internal::EnumSet<CcTestExtensionIds> CcTestExtensionFlags; 66 typedef v8::internal::EnumSet<CcTestExtensionIds> CcTestExtensionFlags;
67 #define DEFINE_EXTENSION_FLAG(Name, Ident) \ 67 #define DEFINE_EXTENSION_FLAG(Name, Ident) \
68 static const CcTestExtensionFlags Name(1 << Name##_ID); 68 static const CcTestExtensionFlags Name(1 << Name##_ID);
69 static const CcTestExtensionFlags NO_EXTENSIONS(0); 69 static const CcTestExtensionFlags NO_EXTENSIONS(0);
70 static const CcTestExtensionFlags ALL_EXTENSIONS((1 << kMaxExtensions) - 1); 70 static const CcTestExtensionFlags ALL_EXTENSIONS((1 << kMaxExtensions) - 1);
71 EXTENSION_LIST(DEFINE_EXTENSION_FLAG) 71 EXTENSION_LIST(DEFINE_EXTENSION_FLAG)
72 #undef DEFINE_EXTENSION_FLAG 72 #undef DEFINE_EXTENSION_FLAG
73 73
74 void RunAndTrackAllocations(void (*test)());
75
76 #ifndef TEST_TRACK_ALLOCATIONS
77 #define TEST_TRACK_ALLOCATIONS(Name) \
78 static void Test##Name(); \
79 TEST(Name##TrackAllocations) { \
80 RunAndTrackAllocations(&Test##Name); \
81 } \
82 TEST(Name)
83 #endif
84
74 class CcTest { 85 class CcTest {
75 public: 86 public:
76 typedef void (TestFunction)(); 87 typedef void (TestFunction)();
77 CcTest(TestFunction* callback, const char* file, const char* name, 88 CcTest(TestFunction* callback, const char* file, const char* name,
78 const char* dependency, bool enabled); 89 const char* dependency, bool enabled);
79 void Run() { callback_(); } 90 void Run() { callback_(); }
80 static CcTest* last() { return last_; } 91 static CcTest* last() { return last_; }
81 CcTest* prev() { return prev_; } 92 CcTest* prev() { return prev_; }
82 const char* file() { return file_; } 93 const char* file() { return file_; }
83 const char* name() { return name_; } 94 const char* name() { return name_; }
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 // Helper function that simulates a full old-space in the heap. 304 // Helper function that simulates a full old-space in the heap.
294 static inline void SimulateFullSpace(v8::internal::PagedSpace* space) { 305 static inline void SimulateFullSpace(v8::internal::PagedSpace* space) {
295 int old_linear_size = static_cast<int>(space->limit() - space->top()); 306 int old_linear_size = static_cast<int>(space->limit() - space->top());
296 space->Free(space->top(), old_linear_size); 307 space->Free(space->top(), old_linear_size);
297 space->SetTop(space->limit(), space->limit()); 308 space->SetTop(space->limit(), space->limit());
298 space->ResetFreeList(); 309 space->ResetFreeList();
299 space->ClearStats(); 310 space->ClearStats();
300 } 311 }
301 312
302 313
314 // Helper class for new allocations tracking and checking.
315 // To use checking of JS allocations tracking in a test,
316 // use TEST_TRACK_ALLOCATIONS macro or just create an instance
317 // of this class.
318 class HeapObjectsTracker {
319 public:
320 HeapObjectsTracker() {
321 heap_profiler_ = i::Isolate::Current()->heap_profiler();
322 CHECK_NE(NULL, heap_profiler_);
323
324 heap_profiler_->StartHeapAllocationsRecording();
325
326 HEAP->CollectAllAvailableGarbage();
327 HEAP->CollectAllAvailableGarbage();
328 HEAP->CollectAllAvailableGarbage();
329 untracked_on_start_ = heap_profiler_->FindUntrackedObjects();
330 }
331
332 virtual ~HeapObjectsTracker() {
333 CHECK_GE(0, CountUntrackedObjects());
334 heap_profiler_->StopHeapAllocationsRecording();
335 }
336
337 private:
338 int CountUntrackedObjects() {
339 HEAP->CollectAllAvailableGarbage();
340 HEAP->CollectAllAvailableGarbage();
341 HEAP->CollectAllAvailableGarbage();
342
343 return heap_profiler_->FindUntrackedObjects() - untracked_on_start_;
344 }
345
346 i::HeapProfiler* heap_profiler_;
347 int untracked_on_start_;
348 };
349
350
303 #endif // ifndef CCTEST_H_ 351 #endif // ifndef CCTEST_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698