Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef BASE_ALLOCATOR_TYPE_PROFILER_H_ | |
| 6 #define BASE_ALLOCATOR_TYPE_PROFILER_H_ | |
| 7 | |
| 8 #if defined(TYPE_PROFILING) | |
| 9 | |
| 10 #include <cstddef> // for size_t | |
| 11 #include <typeinfo> // for std::typeinfo | |
| 12 | |
| 13 // These two functions wrap all 'new' and 'delete' expressions. | |
| 14 // They are called by a modified version of Clang checked-in | |
| 15 // at deps/third_party/llvm-allocated-type. | |
| 16 // These prototype declarations are required to make them friends of | |
| 17 // InterceptFunctions below. | |
| 18 | |
| 19 void* __op_new_intercept__(void* ptr, | |
| 20 size_t size, | |
| 21 const std::type_info& type); | |
| 22 | |
| 23 void* __op_delete_intercept__(void* ptr, | |
| 24 size_t size, | |
| 25 const std::type_info& type); | |
| 26 | |
| 27 namespace base { | |
| 28 namespace type_profiler { | |
| 29 | |
| 30 typedef void* InterceptFunction(void*, size_t, const std::type_info&); | |
| 31 | |
| 32 class InterceptFunctions { | |
| 33 public: | |
| 34 // It must be called only once in a process while it is in single-thread. | |
| 35 // For now, ContentMainRunnerImpl::Initialize is the only supposed caller | |
| 36 // of this function except for single-threaded unit tests. | |
| 37 static void SetFunctions(InterceptFunction* new_intercept, | |
| 38 InterceptFunction* delete_intercept); | |
| 39 | |
| 40 private: | |
| 41 friend class TypeProfilerTest; | |
| 42 friend void* ::__op_new_intercept__(void*, size_t, const std::type_info&); | |
| 43 friend void* ::__op_delete_intercept__(void*, size_t, const std::type_info&); | |
|
jar (doing other things)
2012/09/12 00:34:09
Why does this require a pre-declaration of the fun
Dai Mikurube (NOT FULLTIME)
2012/09/12 04:26:27
Clang without any compiler option says as follows
| |
| 44 | |
| 45 // These functions are not thread safe. | |
| 46 // They must be used only from single-threaded unit tests. | |
| 47 static void ResetFunctions(); | |
| 48 static bool IsAvailable(); | |
| 49 | |
| 50 static InterceptFunction* new_intercept_; | |
| 51 static InterceptFunction* delete_intercept_; | |
| 52 }; | |
| 53 | |
| 54 } // namespace type_profiler | |
| 55 } // namespace base | |
| 56 | |
| 57 #endif // defined(TYPE_PROFILING) | |
| 58 | |
| 59 #endif // BASE_ALLOCATOR_TYPE_PROFILER_H_ | |
| OLD | NEW |