jeffhao | e343b76 | 2011-12-05 16:36:44 -0800 | [diff] [blame] | 1 | // Copyright 2011 Google Inc. All Rights Reserved. |
| 2 | |
| 3 | #ifndef ART_SRC_TRACE_H_ |
| 4 | #define ART_SRC_TRACE_H_ |
| 5 | |
| 6 | #include <map> |
| 7 | |
| 8 | #include "globals.h" |
| 9 | #include "macros.h" |
| 10 | |
| 11 | namespace art { |
| 12 | |
| 13 | class Method; |
| 14 | |
| 15 | struct TraceStackFrame { |
| 16 | TraceStackFrame(Method* method, uintptr_t return_pc) |
| 17 | : method_(method), return_pc_(return_pc) { |
| 18 | } |
| 19 | |
| 20 | Method* method_; |
| 21 | uintptr_t return_pc_; |
| 22 | }; |
| 23 | |
| 24 | class Trace { |
| 25 | public: |
| 26 | static void Start(const char* trace_filename, int trace_fd, int buffer_size, int flags, bool direct_to_ddms); |
| 27 | static void Stop(); |
| 28 | |
| 29 | static bool IsMethodTracingActive(); |
| 30 | static void SetMethodTracingActive(bool value); |
| 31 | |
| 32 | static void AddSavedCodeToMap(const Method* method, const void* code); |
| 33 | static void RemoveSavedCodeFromMap(const Method* method); |
| 34 | static const void* GetSavedCodeFromMap(const Method* method); |
| 35 | |
| 36 | static void SaveAndUpdateCode(Method* method, const void* new_code); |
| 37 | static void ResetSavedCode(Method* method); |
| 38 | |
| 39 | private: |
| 40 | // Replaces code of each method with a pointer to a stub for method tracing. |
| 41 | static void InstallStubs(); |
| 42 | |
| 43 | // Restores original code for each method and fixes the return values of each thread's stack. |
| 44 | static void UninstallStubs(); |
| 45 | |
| 46 | static bool method_tracing_active_; |
| 47 | |
| 48 | // Maps a method to its original code pointer |
| 49 | static std::map<const Method*, const void*> saved_code_map_; |
| 50 | |
| 51 | DISALLOW_COPY_AND_ASSIGN(Trace); |
| 52 | }; |
| 53 | |
| 54 | } // namespace art |
| 55 | |
| 56 | #endif // ART_SRC_TRACE_H_ |