forked from GoogleCloudPlatform/cloud-debug-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebugger.cc
More file actions
150 lines (122 loc) · 4.51 KB
/
debugger.cc
File metadata and controls
150 lines (122 loc) · 4.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/**
* Copyright 2015 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "debugger.h"
#include <memory>
#include "jni_utils.h"
#include "jvm_breakpoint.h"
#include "jvm_breakpoints_manager.h"
#include "safe_method_caller.h"
#include "statistician.h"
#include "stopwatch.h"
DEFINE_int32(
cdbg_class_files_cache_size,
1024 * 1024, // 1 MB.
"Cache size for class files used in safe method caller");
namespace devtools {
namespace cdbg {
Debugger::Debugger(
Scheduler<>* scheduler,
Config* config,
EvalCallStack* eval_call_stack,
std::unique_ptr<MethodLocals> method_locals,
std::unique_ptr<ClassMetadataReader> class_metadata_reader,
ClassPathLookup* class_path_lookup,
std::function<std::unique_ptr<BreakpointLabelsProvider>()> labels_factory,
FormatQueue* format_queue,
CanaryControl* canary_control /* = nullptr */)
: config_(config),
eval_call_stack_(eval_call_stack),
method_locals_(std::move(method_locals)),
class_metadata_reader_(std::move(class_metadata_reader)),
object_evaluator_(&class_indexer_, class_metadata_reader_.get()),
class_files_cache_(&class_indexer_, FLAGS_cdbg_class_files_cache_size) {
evaluators_.class_path_lookup = class_path_lookup;
evaluators_.class_indexer = &class_indexer_;
evaluators_.eval_call_stack = eval_call_stack_;
evaluators_.method_locals = method_locals_.get();
evaluators_.class_metadata_reader = class_metadata_reader_.get();
evaluators_.object_evaluator = &object_evaluator_;
evaluators_.method_caller_factory = [this](Config::MethodCallQuotaType type) {
return std::unique_ptr<MethodCaller>(new SafeMethodCaller(
config_,
config_->GetQuota(type),
&class_indexer_,
&class_files_cache_));
};
evaluators_.labels_factory = labels_factory;
auto factory = [this, scheduler, format_queue](
BreakpointsManager* breakpoints_manager,
std::unique_ptr<BreakpointModel> breakpoint_definition) {
return std::make_shared<JvmBreakpoint>(
scheduler,
&evaluators_,
format_queue,
&dynamic_logger_,
breakpoints_manager,
std::move(breakpoint_definition));
};
breakpoints_manager_.reset(new JvmBreakpointsManager(
factory,
&evaluators_,
format_queue,
canary_control));
}
Debugger::~Debugger() {
breakpoints_manager_->Cleanup();
class_indexer_.Cleanup();
}
void Debugger::Initialize() {
Stopwatch stopwatch;
LOG(INFO) << "Initializing Java debuglet";
// Get the set of already loaded classes. Other classes will be indexed
// as they get loaded by JVM.
class_indexer_.Initialize();
// Initialize pretty printers.
object_evaluator_.Initialize();
// Create logger for dynamic logging.
dynamic_logger_.Initialize();
LOG(INFO) << "Debugger::Initialize initialization time: "
<< stopwatch.GetElapsedMillis() << " ms";
}
void Debugger::JvmtiOnClassPrepare(jthread thread, jclass cls) {
Stopwatch stopwatch;
// Index the new class.
class_indexer_.JvmtiOnClassPrepare(cls);
// Log the accumulated time. "OnClassPrepare" handler is a tax we are
// paying upfront whether debugger is used or not. It is therefore very
// important to keep this function fast.
statClassPrepareTime->add(stopwatch.GetElapsedMicros());
}
// Note: JNIEnv* is not available through jni() call.
void Debugger::JvmtiOnCompiledMethodUnload(
jmethodID method,
const void* code_addr) {
eval_call_stack_->JvmtiOnCompiledMethodUnload(method);
method_locals_->JvmtiOnCompiledMethodUnload(method);
breakpoints_manager_->JvmtiOnCompiledMethodUnload(method);
}
void Debugger::JvmtiOnBreakpoint(
jthread thread,
jmethodID method,
jlocation location) {
breakpoints_manager_->JvmtiOnBreakpoint(thread, method, location);
}
void Debugger::SetActiveBreakpointsList(
std::vector<std::unique_ptr<BreakpointModel>> breakpoints) {
breakpoints_manager_->SetActiveBreakpointsList(std::move(breakpoints));
}
} // namespace cdbg
} // namespace devtools