blob: a5ab650f88458137d93e0e3ecd4cc138f17c47ab [file] [log] [blame]
jeffhao725a9572012-11-13 18:20:12 -08001/*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef ART_SRC_INSTRUMENTATION_H_
18#define ART_SRC_INSTRUMENTATION_H_
19
20#include <ostream>
21#include <set>
22#include <string>
23
24#include "file.h"
25#include "globals.h"
26#include "macros.h"
27#include "safe_map.h"
28#include "trace.h"
29#include "UniquePtr.h"
30
31namespace art {
32
33class AbstractMethod;
34class Thread;
35
36uint32_t InstrumentationMethodUnwindFromCode(Thread* self);
37
38struct InstrumentationStackFrame {
39 InstrumentationStackFrame(AbstractMethod* method, uintptr_t return_pc)
40 : method_(method), return_pc_(return_pc) {
41 }
42
43 AbstractMethod* method_;
44 uintptr_t return_pc_;
45};
46
47class Instrumentation {
48 public:
49 Instrumentation() {}
50 ~Instrumentation();
51
52 // Replaces code of each method with a pointer to a stub for method tracing.
53 void InstallStubs();
54
55 // Restores original code for each method and fixes the return values of each thread's stack.
56 void UninstallStubs() LOCKS_EXCLUDED(Locks::thread_list_lock_);
57
58 const void* GetSavedCodeFromMap(const AbstractMethod* method);
59 void SaveAndUpdateCode(AbstractMethod* method);
60 void ResetSavedCode(AbstractMethod* method);
61
62 Trace* GetTrace() const;
63 void SetTrace(Trace* trace);
64 void RemoveTrace();
65
66 private:
67 void AddSavedCodeToMap(const AbstractMethod* method, const void* code);
68 void RemoveSavedCodeFromMap(const AbstractMethod* method);
69
70 // Maps a method to its original code pointer.
71 SafeMap<const AbstractMethod*, const void*> saved_code_map_;
72
73 Trace* trace_;
74
75 DISALLOW_COPY_AND_ASSIGN(Instrumentation);
76};
77
78} // namespace art
79
80#endif // ART_SRC_INSTRUMENTATION_H_