blob: 95cfca04b181b284abefcf7b856286cfd004563d [file] [log] [blame]
Elliott Hughes872d4ec2011-10-21 17:07:15 -07001/*
2 * Copyright (C) 2008 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/*
18 * Dalvik-specific side of debugger support. (The JDWP code is intended to
19 * be relatively generic.)
20 */
Brian Carlstromfc0e3212013-07-17 14:40:12 -070021#ifndef ART_RUNTIME_DEBUGGER_H_
22#define ART_RUNTIME_DEBUGGER_H_
Elliott Hughes872d4ec2011-10-21 17:07:15 -070023
24#include <pthread.h>
25
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +010026#include <set>
Elliott Hughes3bb81562011-10-21 18:52:59 -070027#include <string>
Sebastien Hertz4d25df32014-03-21 17:44:46 +010028#include <vector>
Elliott Hughes3bb81562011-10-21 18:52:59 -070029
Alex Light8c2b9292017-11-09 13:21:01 -080030#include "base/array_ref.h"
Andreas Gampe0f01b582017-01-18 15:22:37 -080031#include "class_linker.h"
Andreas Gampe8cf9cb32017-07-19 09:28:38 -070032#include "gc_root.h"
Andreas Gampe0f01b582017-01-18 15:22:37 -080033#include "handle.h"
Elliott Hughes872d4ec2011-10-21 17:07:15 -070034#include "jdwp/jdwp.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080035#include "jni.h"
36#include "jvalue.h"
Mathieu Chartier3398c782016-09-30 10:27:43 -070037#include "obj_ptr.h"
Alex Light21611932017-09-26 13:07:39 -070038#include "runtime_callbacks.h"
Mingyao Yang99170c62015-07-06 11:10:37 -070039#include "thread.h"
Jeff Hao920af3e2013-08-28 15:46:38 -070040#include "thread_state.h"
Elliott Hughes872d4ec2011-10-21 17:07:15 -070041
42namespace art {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080043namespace mirror {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080044class Class;
45class Object;
46class Throwable;
47} // namespace mirror
Mathieu Chartierc7853442015-03-27 14:35:38 -070048class ArtField;
Mathieu Chartiere401d142015-04-22 13:56:20 -070049class ArtMethod;
Sebastien Hertz6995c602014-09-09 12:10:13 +020050class ObjectRegistry;
Sebastien Hertzcbc50642015-06-01 17:33:12 +020051class ScopedObjectAccess;
Sebastien Hertz6995c602014-09-09 12:10:13 +020052class ScopedObjectAccessUnchecked;
Sebastien Hertz8009f392014-09-01 17:07:11 +020053class StackVisitor;
Ian Rogers1b09b092012-08-20 15:35:52 -070054class Thread;
Elliott Hughes872d4ec2011-10-21 17:07:15 -070055
Alex Light40320712017-12-14 11:52:04 -080056struct DebuggerActiveMethodInspectionCallback : public MethodInspectionCallback {
Roland Levillainbbc6e7e2018-08-24 16:58:47 +010057 bool IsMethodBeingInspected(ArtMethod* method) override REQUIRES_SHARED(Locks::mutator_lock_);
58 bool IsMethodSafeToJit(ArtMethod* method) override REQUIRES_SHARED(Locks::mutator_lock_);
59 bool MethodNeedsDebugVersion(ArtMethod* method) override REQUIRES_SHARED(Locks::mutator_lock_);
Alex Light40320712017-12-14 11:52:04 -080060};
61
Alex Light8c2b9292017-11-09 13:21:01 -080062struct DebuggerDdmCallback : public DdmCallback {
63 void DdmPublishChunk(uint32_t type, const ArrayRef<const uint8_t>& data)
Roland Levillainbbc6e7e2018-08-24 16:58:47 +010064 override REQUIRES_SHARED(Locks::mutator_lock_);
Alex Light8c2b9292017-11-09 13:21:01 -080065};
66
Alex Light40320712017-12-14 11:52:04 -080067struct InternalDebuggerControlCallback : public DebuggerControlCallback {
Roland Levillainbbc6e7e2018-08-24 16:58:47 +010068 void StartDebugger() override;
69 void StopDebugger() override;
70 bool IsDebuggerConfigured() override;
Alex Light21611932017-09-26 13:07:39 -070071};
72
Elliott Hughes872d4ec2011-10-21 17:07:15 -070073/*
74 * Invoke-during-breakpoint support.
75 */
76struct DebugInvokeReq {
Vladimir Marko4617d582019-03-28 13:48:31 +000077 DebugInvokeReq(uint32_t invoke_request_id,
78 JDWP::ObjectId invoke_thread_id,
79 ObjPtr<mirror::Object> invoke_receiver,
80 ObjPtr<mirror::Class> invoke_class,
81 ArtMethod* invoke_method,
82 uint32_t invoke_options,
83 uint64_t args[],
84 uint32_t args_count)
85 : request_id(invoke_request_id),
86 thread_id(invoke_thread_id),
87 receiver(invoke_receiver),
88 klass(invoke_class),
89 method(invoke_method),
90 arg_count(args_count),
91 arg_values(args),
92 options(invoke_options),
93 reply(JDWP::expandBufAlloc()) {
Elliott Hughes475fc232011-10-25 15:00:35 -070094 }
95
Sebastien Hertzcbc50642015-06-01 17:33:12 +020096 ~DebugInvokeReq() {
97 JDWP::expandBufFree(reply);
98 }
99
100 // Request
101 const uint32_t request_id;
102 const JDWP::ObjectId thread_id;
103 GcRoot<mirror::Object> receiver; // not used for ClassType.InvokeMethod.
Sebastien Hertz1558b572015-02-25 15:05:59 +0100104 GcRoot<mirror::Class> klass;
Sebastien Hertzcbc50642015-06-01 17:33:12 +0200105 ArtMethod* const method;
Sebastien Hertz1558b572015-02-25 15:05:59 +0100106 const uint32_t arg_count;
Sebastien Hertzcbc50642015-06-01 17:33:12 +0200107 std::unique_ptr<uint64_t[]> arg_values; // will be null if arg_count_ == 0. We take ownership
108 // of this array so we must delete it upon destruction.
Sebastien Hertz1558b572015-02-25 15:05:59 +0100109 const uint32_t options;
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700110
Sebastien Hertzcbc50642015-06-01 17:33:12 +0200111 // Reply
112 JDWP::ExpandBuf* const reply;
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +0100113
Mathieu Chartierbb87e0f2015-04-03 11:21:55 -0700114 void VisitRoots(RootVisitor* visitor, const RootInfo& root_info)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700115 REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartier3b05e9b2014-03-25 09:29:43 -0700116
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +0100117 private:
118 DISALLOW_COPY_AND_ASSIGN(DebugInvokeReq);
119};
120
121// Thread local data-structure that holds fields for controlling single-stepping.
Sebastien Hertz597c4f02015-01-26 17:37:14 +0100122class SingleStepControl {
123 public:
124 SingleStepControl(JDWP::JdwpStepSize step_size, JDWP::JdwpStepDepth step_depth,
Mathieu Chartiere401d142015-04-22 13:56:20 -0700125 int stack_depth, ArtMethod* method)
Sebastien Hertz597c4f02015-01-26 17:37:14 +0100126 : step_size_(step_size), step_depth_(step_depth),
127 stack_depth_(stack_depth), method_(method) {
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +0100128 }
129
Sebastien Hertz597c4f02015-01-26 17:37:14 +0100130 JDWP::JdwpStepSize GetStepSize() const {
131 return step_size_;
132 }
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +0100133
Sebastien Hertz597c4f02015-01-26 17:37:14 +0100134 JDWP::JdwpStepDepth GetStepDepth() const {
135 return step_depth_;
136 }
137
138 int GetStackDepth() const {
139 return stack_depth_;
140 }
141
Mathieu Chartiere401d142015-04-22 13:56:20 -0700142 ArtMethod* GetMethod() const {
143 return method_;
Sebastien Hertz597c4f02015-01-26 17:37:14 +0100144 }
145
146 const std::set<uint32_t>& GetDexPcs() const {
147 return dex_pcs_;
148 }
149
Sebastien Hertz597c4f02015-01-26 17:37:14 +0100150 void AddDexPc(uint32_t dex_pc);
151
152 bool ContainsDexPc(uint32_t dex_pc) const;
153
154 private:
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +0100155 // See JdwpStepSize and JdwpStepDepth for details.
Sebastien Hertz597c4f02015-01-26 17:37:14 +0100156 const JDWP::JdwpStepSize step_size_;
157 const JDWP::JdwpStepDepth step_depth_;
158
159 // The stack depth when this single-step was initiated. This is used to support SD_OVER and SD_OUT
160 // single-step depth.
161 const int stack_depth_;
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +0100162
163 // The location this single-step was initiated from.
164 // A single-step is initiated in a suspended thread. We save here the current method and the
165 // set of DEX pcs associated to the source line number where the suspension occurred.
166 // This is used to support SD_INTO and SD_OVER single-step depths so we detect when a single-step
167 // causes the execution of an instruction in a different method or at a different line number.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700168 ArtMethod* method_;
169
Sebastien Hertz597c4f02015-01-26 17:37:14 +0100170 std::set<uint32_t> dex_pcs_;
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +0100171
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +0100172 DISALLOW_COPY_AND_ASSIGN(SingleStepControl);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700173};
174
Sebastien Hertz42cd43f2014-05-13 14:15:41 +0200175// TODO rename to InstrumentationRequest.
Hiroshi Yamauchi0ec17d22014-07-07 13:07:08 -0700176class DeoptimizationRequest {
177 public:
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100178 enum Kind {
179 kNothing, // no action.
Sebastien Hertz42cd43f2014-05-13 14:15:41 +0200180 kRegisterForEvent, // start listening for instrumentation event.
181 kUnregisterForEvent, // stop listening for instrumentation event.
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100182 kFullDeoptimization, // deoptimize everything.
183 kFullUndeoptimization, // undeoptimize everything.
184 kSelectiveDeoptimization, // deoptimize one method.
185 kSelectiveUndeoptimization // undeoptimize one method.
186 };
187
Hiroshi Yamauchi0ec17d22014-07-07 13:07:08 -0700188 DeoptimizationRequest() : kind_(kNothing), instrumentation_event_(0), method_(nullptr) {}
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100189
Hiroshi Yamauchi0ec17d22014-07-07 13:07:08 -0700190 DeoptimizationRequest(const DeoptimizationRequest& other)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700191 REQUIRES_SHARED(Locks::mutator_lock_)
Hiroshi Yamauchi0ec17d22014-07-07 13:07:08 -0700192 : kind_(other.kind_), instrumentation_event_(other.instrumentation_event_) {
193 // Create a new JNI global reference for the method.
194 SetMethod(other.Method());
195 }
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100196
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700197 ArtMethod* Method() const REQUIRES_SHARED(Locks::mutator_lock_);
Hiroshi Yamauchi0ec17d22014-07-07 13:07:08 -0700198
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700199 void SetMethod(ArtMethod* m) REQUIRES_SHARED(Locks::mutator_lock_);
Hiroshi Yamauchi0ec17d22014-07-07 13:07:08 -0700200
201 // Name 'Kind()' would collide with the above enum name.
202 Kind GetKind() const {
203 return kind_;
204 }
205
206 void SetKind(Kind kind) {
207 kind_ = kind;
208 }
209
210 uint32_t InstrumentationEvent() const {
211 return instrumentation_event_;
212 }
213
214 void SetInstrumentationEvent(uint32_t instrumentation_event) {
215 instrumentation_event_ = instrumentation_event;
216 }
217
218 private:
219 Kind kind_;
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100220
Sebastien Hertz42cd43f2014-05-13 14:15:41 +0200221 // TODO we could use a union to hold the instrumentation_event and the method since they
222 // respectively have sense only for kRegisterForEvent/kUnregisterForEvent and
223 // kSelectiveDeoptimization/kSelectiveUndeoptimization.
224
225 // Event to start or stop listening to. Only for kRegisterForEvent and kUnregisterForEvent.
Hiroshi Yamauchi0ec17d22014-07-07 13:07:08 -0700226 uint32_t instrumentation_event_;
Sebastien Hertz42cd43f2014-05-13 14:15:41 +0200227
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100228 // Method for selective deoptimization.
Hiroshi Yamauchi0ec17d22014-07-07 13:07:08 -0700229 jmethodID method_;
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100230};
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700231std::ostream& operator<<(std::ostream& os, const DeoptimizationRequest::Kind& rhs);
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100232
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700233class Dbg {
Elliott Hughesff17f1f2012-01-24 18:12:29 -0800234 public:
Elliott Hughes4ffd3132011-10-24 12:06:42 -0700235 static void SetJdwpAllowed(bool allowed);
Leonard Mosescueb842212016-10-06 17:26:36 -0700236 static bool IsJdwpAllowed();
Elliott Hughes4ffd3132011-10-24 12:06:42 -0700237
Sebastien Hertzb3b173b2015-02-06 09:16:32 +0100238 static void StartJdwp();
Elliott Hughesd1cc8362011-10-24 16:58:50 -0700239 static void StopJdwp();
240
Elliott Hughes767a1472011-10-26 18:49:02 -0700241 // Invoked by the GC in case we need to keep DDMS informed.
Mathieu Chartier90443472015-07-16 20:32:27 -0700242 static void GcDidFinish() REQUIRES(!Locks::mutator_lock_);
Elliott Hughes767a1472011-10-26 18:49:02 -0700243
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700244 // Return the DebugInvokeReq for the current thread.
245 static DebugInvokeReq* GetInvokeReq();
246
Elliott Hughes475fc232011-10-25 15:00:35 -0700247 static Thread* GetDebugThread();
248 static void ClearWaitForEventThread();
249
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700250 /*
251 * Enable/disable breakpoints and step modes. Used to provide a heads-up
252 * when the debugger attaches.
253 */
254 static void Connected();
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100255 static void GoActive()
Mathieu Chartier90443472015-07-16 20:32:27 -0700256 REQUIRES(!Locks::breakpoint_lock_, !Locks::deoptimization_lock_, !Locks::mutator_lock_);
257 static void Disconnected() REQUIRES(!Locks::deoptimization_lock_, !Locks::mutator_lock_);
Sebastien Hertz4e5b2082015-03-24 19:03:40 +0100258 static void Dispose() {
259 gDisposed = true;
260 }
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700261
Elliott Hughesc0f09332012-03-26 13:27:06 -0700262 // Returns true if we're actually debugging with a real debugger, false if it's
263 // just DDMS (or nothing at all).
Daniel Mihalyieb076692014-08-22 17:33:31 +0200264 static bool IsDebuggerActive() {
265 return gDebuggerActive;
266 }
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700267
Sebastien Hertzb3b173b2015-02-06 09:16:32 +0100268 // Configures JDWP with parsed command-line options.
Alex Light40320712017-12-14 11:52:04 -0800269 static void ConfigureJdwp(const JDWP::JdwpOptions& jdwp_options)
270 REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertzb3b173b2015-02-06 09:16:32 +0100271
Elliott Hughesc0f09332012-03-26 13:27:06 -0700272 // Returns true if we had -Xrunjdwp or -agentlib:jdwp= on the command line.
273 static bool IsJdwpConfigured();
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700274
Mathieu Chartierd8565452015-03-26 09:41:50 -0700275 // Returns true if a method has any breakpoints.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700276 static bool MethodHasAnyBreakpoints(ArtMethod* method)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700277 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!Locks::breakpoint_lock_);
Mathieu Chartierd8565452015-03-26 09:41:50 -0700278
Sebastien Hertz4e5b2082015-03-24 19:03:40 +0100279 static bool IsDisposed() {
280 return gDisposed;
281 }
Elliott Hughes86964332012-02-15 19:37:42 -0800282
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700283 /*
284 * Time, in milliseconds, since the last debugger activity. Does not
285 * include DDMS activity. Returns -1 if there has been no activity.
286 * Returns 0 if we're in the middle of handling a debugger request.
287 */
288 static int64_t LastDebuggerActivity();
289
Sebastien Hertz253fa552014-10-14 17:27:15 +0200290 static void UndoDebuggerSuspensions()
Mathieu Chartier90443472015-07-16 20:32:27 -0700291 REQUIRES(!Locks::thread_list_lock_, !Locks::thread_suspend_count_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700292
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700293 /*
294 * Class, Object, Array
295 */
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700296 static std::string GetClassName(JDWP::RefTypeId id)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700297 REQUIRES_SHARED(Locks::mutator_lock_);
Vladimir Marko4617d582019-03-28 13:48:31 +0000298 static std::string GetClassName(ObjPtr<mirror::Class> klass)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700299 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogersc0542af2014-09-03 16:16:56 -0700300 static JDWP::JdwpError GetClassObject(JDWP::RefTypeId id, JDWP::ObjectId* class_object_id)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700301 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogersc0542af2014-09-03 16:16:56 -0700302 static JDWP::JdwpError GetSuperclass(JDWP::RefTypeId id, JDWP::RefTypeId* superclass_id)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700303 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700304 static JDWP::JdwpError GetClassLoader(JDWP::RefTypeId id, JDWP::ExpandBuf* pReply)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700305 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700306 static JDWP::JdwpError GetModifiers(JDWP::RefTypeId id, JDWP::ExpandBuf* pReply)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700307 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800308 static JDWP::JdwpError GetReflectedType(JDWP::RefTypeId class_id, JDWP::ExpandBuf* pReply)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700309 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogersc0542af2014-09-03 16:16:56 -0700310 static void GetClassList(std::vector<JDWP::RefTypeId>* classes)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700311 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800312 static JDWP::JdwpError GetClassInfo(JDWP::RefTypeId class_id, JDWP::JdwpTypeTag* pTypeTag,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700313 uint32_t* pStatus, std::string* pDescriptor)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700314 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogersc0542af2014-09-03 16:16:56 -0700315 static void FindLoadedClassBySignature(const char* descriptor, std::vector<JDWP::RefTypeId>* ids)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700316 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes64f574f2013-02-20 14:57:12 -0800317 static JDWP::JdwpError GetReferenceType(JDWP::ObjectId object_id, JDWP::ExpandBuf* pReply)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700318 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogersfc0e94b2013-09-23 23:51:32 -0700319 static JDWP::JdwpError GetSignature(JDWP::RefTypeId ref_type_id, std::string* signature)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700320 REQUIRES_SHARED(Locks::mutator_lock_);
Orion Hodson77d8a1c2017-04-24 14:53:19 +0100321 static JDWP::JdwpError GetSourceDebugExtension(JDWP::RefTypeId ref_type_id,
322 std::string* extension_data)
323 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogersc0542af2014-09-03 16:16:56 -0700324 static JDWP::JdwpError GetSourceFile(JDWP::RefTypeId ref_type_id, std::string* source_file)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700325 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogersc0542af2014-09-03 16:16:56 -0700326 static JDWP::JdwpError GetObjectTag(JDWP::ObjectId object_id, uint8_t* tag)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700327 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughesaed4be92011-12-02 16:16:23 -0800328 static size_t GetTagWidth(JDWP::JdwpTag tag);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700329
Ian Rogersc0542af2014-09-03 16:16:56 -0700330 static JDWP::JdwpError GetArrayLength(JDWP::ObjectId array_id, int32_t* length)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700331 REQUIRES_SHARED(Locks::mutator_lock_);
Vladimir Marko4617d582019-03-28 13:48:31 +0000332 static JDWP::JdwpError OutputArray(JDWP::ObjectId array_id,
333 int offset,
334 int count,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700335 JDWP::ExpandBuf* pReply)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700336 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800337 static JDWP::JdwpError SetArrayElements(JDWP::ObjectId array_id, int offset, int count,
Ian Rogersc0542af2014-09-03 16:16:56 -0700338 JDWP::Request* request)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700339 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700340
Sebastien Hertz2c3e77a2015-04-02 16:26:48 +0200341 static JDWP::JdwpError CreateString(const std::string& str, JDWP::ObjectId* new_string_id)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700342 REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertz2c3e77a2015-04-02 16:26:48 +0200343 static JDWP::JdwpError CreateObject(JDWP::RefTypeId class_id, JDWP::ObjectId* new_object_id)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700344 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800345 static JDWP::JdwpError CreateArrayObject(JDWP::RefTypeId array_class_id, uint32_t length,
Sebastien Hertz2c3e77a2015-04-02 16:26:48 +0200346 JDWP::ObjectId* new_array_id)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700347 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700348
Sebastien Hertz6995c602014-09-09 12:10:13 +0200349 //
350 // Event filtering.
351 //
352 static bool MatchThread(JDWP::ObjectId expected_thread_id, Thread* event_thread)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700353 REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertz6995c602014-09-09 12:10:13 +0200354
355 static bool MatchLocation(const JDWP::JdwpLocation& expected_location,
356 const JDWP::EventLocation& event_location)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700357 REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertz6995c602014-09-09 12:10:13 +0200358
Mathieu Chartier3398c782016-09-30 10:27:43 -0700359 static bool MatchType(ObjPtr<mirror::Class> event_class, JDWP::RefTypeId class_id)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700360 REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertz6995c602014-09-09 12:10:13 +0200361
Vladimir Marko83114892019-04-11 13:05:50 +0100362 static bool MatchField(JDWP::RefTypeId expected_type_id,
363 JDWP::FieldId expected_field_id,
Mathieu Chartierc7853442015-03-27 14:35:38 -0700364 ArtField* event_field)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700365 REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertz6995c602014-09-09 12:10:13 +0200366
Vladimir Marko83114892019-04-11 13:05:50 +0100367 static bool MatchInstance(JDWP::ObjectId expected_instance_id,
368 ObjPtr<mirror::Object> event_instance)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700369 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700370
Elliott Hughesec0f83d2013-01-15 16:54:08 -0800371 //
372 // Monitors.
373 //
374 static JDWP::JdwpError GetMonitorInfo(JDWP::ObjectId object_id, JDWP::ExpandBuf* reply)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700375 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughesec0f83d2013-01-15 16:54:08 -0800376 static JDWP::JdwpError GetOwnedMonitors(JDWP::ObjectId thread_id,
Ian Rogersc0542af2014-09-03 16:16:56 -0700377 std::vector<JDWP::ObjectId>* monitors,
378 std::vector<uint32_t>* stack_depths)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700379 REQUIRES(!Locks::thread_list_lock_) REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100380 static JDWP::JdwpError GetContendedMonitor(JDWP::ObjectId thread_id,
Ian Rogersc0542af2014-09-03 16:16:56 -0700381 JDWP::ObjectId* contended_monitor)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700382 REQUIRES(!Locks::thread_list_lock_) REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughesec0f83d2013-01-15 16:54:08 -0800383
384 //
385 // Heap.
386 //
387 static JDWP::JdwpError GetInstanceCounts(const std::vector<JDWP::RefTypeId>& class_ids,
Ian Rogersc0542af2014-09-03 16:16:56 -0700388 std::vector<uint64_t>* counts)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700389 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes3b78c942013-01-15 17:35:41 -0800390 static JDWP::JdwpError GetInstances(JDWP::RefTypeId class_id, int32_t max_count,
Ian Rogersc0542af2014-09-03 16:16:56 -0700391 std::vector<JDWP::ObjectId>* instances)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700392 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes0cbaff52013-01-16 15:28:01 -0800393 static JDWP::JdwpError GetReferringObjects(JDWP::ObjectId object_id, int32_t max_count,
Ian Rogersc0542af2014-09-03 16:16:56 -0700394 std::vector<JDWP::ObjectId>* referring_objects)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700395 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes64f574f2013-02-20 14:57:12 -0800396 static JDWP::JdwpError DisableCollection(JDWP::ObjectId object_id)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700397 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes64f574f2013-02-20 14:57:12 -0800398 static JDWP::JdwpError EnableCollection(JDWP::ObjectId object_id)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700399 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogersc0542af2014-09-03 16:16:56 -0700400 static JDWP::JdwpError IsCollected(JDWP::ObjectId object_id, bool* is_collected)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700401 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes64f574f2013-02-20 14:57:12 -0800402 static void DisposeObject(JDWP::ObjectId object_id, uint32_t reference_count)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700403 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughesec0f83d2013-01-15 16:54:08 -0800404
Elliott Hughes9777ba22013-01-17 09:04:19 -0800405 //
406 // Methods and fields.
407 //
Elliott Hughesa96836a2013-01-17 12:27:49 -0800408 static std::string GetMethodName(JDWP::MethodId method_id)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700409 REQUIRES_SHARED(Locks::mutator_lock_);
Alex Light73376312017-04-06 10:10:51 -0700410 static bool IsMethodObsolete(JDWP::MethodId method_id)
411 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800412 static JDWP::JdwpError OutputDeclaredFields(JDWP::RefTypeId ref_type_id, bool with_generic,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700413 JDWP::ExpandBuf* pReply)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700414 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800415 static JDWP::JdwpError OutputDeclaredMethods(JDWP::RefTypeId ref_type_id, bool with_generic,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700416 JDWP::ExpandBuf* pReply)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700417 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800418 static JDWP::JdwpError OutputDeclaredInterfaces(JDWP::RefTypeId ref_type_id,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700419 JDWP::ExpandBuf* pReply)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700420 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800421 static void OutputLineTable(JDWP::RefTypeId ref_type_id, JDWP::MethodId method_id,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700422 JDWP::ExpandBuf* pReply)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700423 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800424 static void OutputVariableTable(JDWP::RefTypeId ref_type_id, JDWP::MethodId id, bool with_generic,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700425 JDWP::ExpandBuf* pReply)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700426 REQUIRES_SHARED(Locks::mutator_lock_);
Jeff Hao579b0242013-11-18 13:16:49 -0800427 static void OutputMethodReturnValue(JDWP::MethodId method_id, const JValue* return_value,
428 JDWP::ExpandBuf* pReply)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700429 REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertz3f52eaf2014-04-04 17:50:18 +0200430 static void OutputFieldValue(JDWP::FieldId field_id, const JValue* field_value,
431 JDWP::ExpandBuf* pReply)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700432 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes9777ba22013-01-17 09:04:19 -0800433 static JDWP::JdwpError GetBytecodes(JDWP::RefTypeId class_id, JDWP::MethodId method_id,
Ian Rogersc0542af2014-09-03 16:16:56 -0700434 std::vector<uint8_t>* bytecodes)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700435 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700436
Elliott Hughesa96836a2013-01-17 12:27:49 -0800437 static std::string GetFieldName(JDWP::FieldId field_id)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700438 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800439 static JDWP::JdwpTag GetFieldBasicTag(JDWP::FieldId field_id)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700440 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800441 static JDWP::JdwpTag GetStaticFieldBasicTag(JDWP::FieldId field_id)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700442 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800443 static JDWP::JdwpError GetFieldValue(JDWP::ObjectId object_id, JDWP::FieldId field_id,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700444 JDWP::ExpandBuf* pReply)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700445 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800446 static JDWP::JdwpError SetFieldValue(JDWP::ObjectId object_id, JDWP::FieldId field_id,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700447 uint64_t value, int width)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700448 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800449 static JDWP::JdwpError GetStaticFieldValue(JDWP::RefTypeId ref_type_id, JDWP::FieldId field_id,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700450 JDWP::ExpandBuf* pReply)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700451 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800452 static JDWP::JdwpError SetStaticFieldValue(JDWP::FieldId field_id, uint64_t value, int width)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700453 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700454
Sebastien Hertzb0b0b492014-09-15 11:27:27 +0200455 static JDWP::JdwpError StringToUtf8(JDWP::ObjectId string_id, std::string* str)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700456 REQUIRES_SHARED(Locks::mutator_lock_);
Jeff Hao579b0242013-11-18 13:16:49 -0800457 static void OutputJValue(JDWP::JdwpTag tag, const JValue* return_value, JDWP::ExpandBuf* pReply)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700458 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700459
460 /*
461 * Thread, ThreadGroup, Frame
462 */
Ian Rogersc0542af2014-09-03 16:16:56 -0700463 static JDWP::JdwpError GetThreadName(JDWP::ObjectId thread_id, std::string* name)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700464 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!Locks::thread_list_lock_);
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100465 static JDWP::JdwpError GetThreadGroup(JDWP::ObjectId thread_id, JDWP::ExpandBuf* pReply)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700466 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!Locks::thread_list_lock_);
Sebastien Hertza06430c2014-09-15 19:21:30 +0200467 static JDWP::JdwpError GetThreadGroupName(JDWP::ObjectId thread_group_id,
468 JDWP::ExpandBuf* pReply)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700469 REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertza06430c2014-09-15 19:21:30 +0200470 static JDWP::JdwpError GetThreadGroupParent(JDWP::ObjectId thread_group_id,
471 JDWP::ExpandBuf* pReply)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700472 REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertza06430c2014-09-15 19:21:30 +0200473 static JDWP::JdwpError GetThreadGroupChildren(JDWP::ObjectId thread_group_id,
474 JDWP::ExpandBuf* pReply)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700475 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700476 static JDWP::ObjectId GetSystemThreadGroupId()
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700477 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700478
Jeff Hao920af3e2013-08-28 15:46:38 -0700479 static JDWP::JdwpThreadStatus ToJdwpThreadStatus(ThreadState state);
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100480 static JDWP::JdwpError GetThreadStatus(JDWP::ObjectId thread_id,
481 JDWP::JdwpThreadStatus* pThreadStatus,
482 JDWP::JdwpSuspendStatus* pSuspendStatus)
Mathieu Chartier90443472015-07-16 20:32:27 -0700483 REQUIRES(!Locks::thread_list_lock_);
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100484 static JDWP::JdwpError GetThreadDebugSuspendCount(JDWP::ObjectId thread_id,
485 JDWP::ExpandBuf* pReply)
Mathieu Chartier90443472015-07-16 20:32:27 -0700486 REQUIRES(!Locks::thread_list_lock_, !Locks::thread_suspend_count_lock_);
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700487 // static void WaitForSuspend(JDWP::ObjectId thread_id);
Elliott Hughescaf76542012-06-28 16:08:22 -0700488
Elliott Hughes026b1462012-06-28 20:43:49 -0700489 // Fills 'thread_ids' with the threads in the given thread group. If thread_group_id == 0,
Elliott Hughescaf76542012-06-28 16:08:22 -0700490 // returns all threads.
Vladimir Marko83114892019-04-11 13:05:50 +0100491 static void GetThreads(ObjPtr<mirror::Object> thread_group,
492 std::vector<JDWP::ObjectId>* thread_ids)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700493 REQUIRES(!Locks::thread_list_lock_) REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughescaf76542012-06-28 16:08:22 -0700494
Ian Rogersc0542af2014-09-03 16:16:56 -0700495 static JDWP::JdwpError GetThreadFrameCount(JDWP::ObjectId thread_id, size_t* result)
Mathieu Chartier90443472015-07-16 20:32:27 -0700496 REQUIRES(!Locks::thread_list_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700497 static JDWP::JdwpError GetThreadFrames(JDWP::ObjectId thread_id, size_t start_frame,
498 size_t frame_count, JDWP::ExpandBuf* buf)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700499 REQUIRES(!Locks::thread_list_lock_) REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700500
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700501 static JDWP::ObjectId GetThreadSelfId() REQUIRES_SHARED(Locks::mutator_lock_);
502 static JDWP::ObjectId GetThreadId(Thread* thread) REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertz6995c602014-09-09 12:10:13 +0200503
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700504 static void SuspendVM()
Mathieu Chartier90443472015-07-16 20:32:27 -0700505 REQUIRES(!Locks::thread_list_lock_, !Locks::thread_suspend_count_lock_);
Sebastien Hertz253fa552014-10-14 17:27:15 +0200506 static void ResumeVM()
Mathieu Chartier90443472015-07-16 20:32:27 -0700507 REQUIRES(!Locks::thread_list_lock_, !Locks::thread_suspend_count_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800508 static JDWP::JdwpError SuspendThread(JDWP::ObjectId thread_id, bool request_suspension = true)
Mathieu Chartier90443472015-07-16 20:32:27 -0700509 REQUIRES(!Locks::mutator_lock_, !Locks::thread_list_lock_,
510 !Locks::thread_suspend_count_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700511
Elliott Hughes88d63092013-01-09 09:55:54 -0800512 static void ResumeThread(JDWP::ObjectId thread_id)
Mathieu Chartier90443472015-07-16 20:32:27 -0700513 REQUIRES(!Locks::thread_list_lock_, !Locks::thread_suspend_count_lock_)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700514 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700515 static void SuspendSelf();
516
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700517 static JDWP::JdwpError GetThisObject(JDWP::ObjectId thread_id, JDWP::FrameId frame_id,
518 JDWP::ObjectId* result)
Mathieu Chartier90443472015-07-16 20:32:27 -0700519 REQUIRES(!Locks::thread_list_lock_, !Locks::thread_suspend_count_lock_)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700520 REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertz8009f392014-09-01 17:07:11 +0200521 static JDWP::JdwpError GetLocalValues(JDWP::Request* request, JDWP::ExpandBuf* pReply)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700522 REQUIRES(!Locks::thread_list_lock_) REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertz8009f392014-09-01 17:07:11 +0200523 static JDWP::JdwpError SetLocalValues(JDWP::Request* request)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700524 REQUIRES(!Locks::thread_list_lock_) REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700525
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100526 static JDWP::JdwpError Interrupt(JDWP::ObjectId thread_id)
Mathieu Chartier90443472015-07-16 20:32:27 -0700527 REQUIRES(!Locks::thread_list_lock_);
Elliott Hughesf9501702013-01-11 11:22:27 -0800528
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700529 /*
530 * Debugger notification
531 */
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700532 enum EventFlag {
Elliott Hughes86964332012-02-15 19:37:42 -0800533 kBreakpoint = 0x01,
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700534 kSingleStep = 0x02,
535 kMethodEntry = 0x04,
536 kMethodExit = 0x08,
537 };
Vladimir Marko83114892019-04-11 13:05:50 +0100538 static void PostFieldAccessEvent(ArtMethod* m,
539 int dex_pc,
540 ObjPtr<mirror::Object> this_object,
Mathieu Chartierc7853442015-03-27 14:35:38 -0700541 ArtField* f)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700542 REQUIRES_SHARED(Locks::mutator_lock_);
Vladimir Marko83114892019-04-11 13:05:50 +0100543 static void PostFieldModificationEvent(ArtMethod* m,
544 int dex_pc,
545 ObjPtr<mirror::Object> this_object,
546 ArtField* f,
Sebastien Hertz3f52eaf2014-04-04 17:50:18 +0200547 const JValue* field_value)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700548 REQUIRES_SHARED(Locks::mutator_lock_);
Vladimir Marko83114892019-04-11 13:05:50 +0100549 static void PostException(ObjPtr<mirror::Throwable> exception)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700550 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700551
Vladimir Marko83114892019-04-11 13:05:50 +0100552 static void UpdateDebugger(Thread* thread,
553 ObjPtr<mirror::Object> this_object,
554 ArtMethod* method,
555 uint32_t new_dex_pc,
556 int event_flags,
557 const JValue* return_value)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700558 REQUIRES(!Locks::breakpoint_lock_) REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes91bf6cd2012-02-14 17:27:48 -0800559
Sebastien Hertzf3928792014-11-17 19:00:37 +0100560 // Indicates whether we need deoptimization for debugging.
561 static bool RequiresDeoptimization();
562
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100563 // Records deoptimization request in the queue.
564 static void RequestDeoptimization(const DeoptimizationRequest& req)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700565 REQUIRES(!Locks::deoptimization_lock_) REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100566
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100567 // Manage deoptimization after updating JDWP events list. Suspends all threads, processes each
568 // request and finally resumes all threads.
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100569 static void ManageDeoptimization()
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700570 REQUIRES(!Locks::deoptimization_lock_) REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100571
572 // Breakpoints.
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100573 static void WatchLocation(const JDWP::JdwpLocation* pLoc, DeoptimizationRequest* req)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700574 REQUIRES(!Locks::breakpoint_lock_) REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100575 static void UnwatchLocation(const JDWP::JdwpLocation* pLoc, DeoptimizationRequest* req)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700576 REQUIRES(!Locks::breakpoint_lock_) REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100577
Daniel Mihalyieb076692014-08-22 17:33:31 +0200578 /*
579 * Forced interpreter checkers for single-step and continue support.
580 */
581
582 // Indicates whether we need to force the use of interpreter to invoke a method.
583 // This allows to single-step or continue into the called method.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700584 static bool IsForcedInterpreterNeededForCalling(Thread* thread, ArtMethod* m)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700585 REQUIRES_SHARED(Locks::mutator_lock_) {
Daniel Mihalyieb076692014-08-22 17:33:31 +0200586 if (!IsDebuggerActive()) {
587 return false;
588 }
589 return IsForcedInterpreterNeededForCallingImpl(thread, m);
590 }
591
592 // Indicates whether we need to force the use of interpreter entrypoint when calling a
593 // method through the resolution trampoline. This allows to single-step or continue into
594 // the called method.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700595 static bool IsForcedInterpreterNeededForResolution(Thread* thread, ArtMethod* m)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700596 REQUIRES_SHARED(Locks::mutator_lock_) {
Daniel Mihalyieb076692014-08-22 17:33:31 +0200597 if (!IsDebuggerActive()) {
598 return false;
599 }
600 return IsForcedInterpreterNeededForResolutionImpl(thread, m);
601 }
602
603 // Indicates whether we need to force the use of instrumentation entrypoint when calling
604 // a method through the resolution trampoline. This allows to deoptimize the stack for
605 // debugging when we returned from the called method.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700606 static bool IsForcedInstrumentationNeededForResolution(Thread* thread, ArtMethod* m)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700607 REQUIRES_SHARED(Locks::mutator_lock_) {
Daniel Mihalyieb076692014-08-22 17:33:31 +0200608 if (!IsDebuggerActive()) {
609 return false;
610 }
611 return IsForcedInstrumentationNeededForResolutionImpl(thread, m);
612 }
613
614 // Indicates whether we need to force the use of interpreter when returning from the
615 // interpreter into the runtime. This allows to deoptimize the stack and continue
616 // execution with interpreter for debugging.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700617 static bool IsForcedInterpreterNeededForUpcall(Thread* thread, ArtMethod* m)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700618 REQUIRES_SHARED(Locks::mutator_lock_) {
Mingyao Yang99170c62015-07-06 11:10:37 -0700619 if (!IsDebuggerActive() && !thread->HasDebuggerShadowFrames()) {
Daniel Mihalyieb076692014-08-22 17:33:31 +0200620 return false;
621 }
622 return IsForcedInterpreterNeededForUpcallImpl(thread, m);
623 }
624
Sebastien Hertz520633b2015-09-08 17:03:36 +0200625 // Indicates whether we need to force the use of interpreter when handling an
626 // exception. This allows to deoptimize the stack and continue execution with
627 // the interpreter.
628 // Note: the interpreter will start by handling the exception when executing
629 // the deoptimized frames.
630 static bool IsForcedInterpreterNeededForException(Thread* thread)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700631 REQUIRES_SHARED(Locks::mutator_lock_) {
Mingyao Yang99170c62015-07-06 11:10:37 -0700632 if (!IsDebuggerActive() && !thread->HasDebuggerShadowFrames()) {
Sebastien Hertz520633b2015-09-08 17:03:36 +0200633 return false;
634 }
635 return IsForcedInterpreterNeededForExceptionImpl(thread);
636 }
637
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100638 // Single-stepping.
Elliott Hughes88d63092013-01-09 09:55:54 -0800639 static JDWP::JdwpError ConfigureStep(JDWP::ObjectId thread_id, JDWP::JdwpStepSize size,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700640 JDWP::JdwpStepDepth depth)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700641 REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +0100642 static void UnconfigureStep(JDWP::ObjectId thread_id)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700643 REQUIRES(!Locks::thread_list_lock_) REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700644
Sebastien Hertzcbc50642015-06-01 17:33:12 +0200645 /*
646 * Invoke support
647 */
648
649 // Called by the JDWP thread to prepare invocation in the event thread (suspended on an event).
650 // If the information sent by the debugger is incorrect, it will send a reply with the
651 // appropriate error code. Otherwise, it will attach a DebugInvokeReq object to the event thread
652 // and resume it (and possibly other threads depending on the invoke options).
653 // Unlike other commands, the JDWP thread will not send the reply to the debugger (see
654 // JdwpState::ProcessRequest). The reply will be sent by the event thread itself after method
655 // invocation completes (see FinishInvokeMethod). This is required to allow the JDWP thread to
656 // process incoming commands from the debugger while the invocation is still in progress in the
657 // event thread, especially if it gets suspended by a debug event occurring in another thread.
658 static JDWP::JdwpError PrepareInvokeMethod(uint32_t request_id, JDWP::ObjectId thread_id,
659 JDWP::ObjectId object_id, JDWP::RefTypeId class_id,
660 JDWP::MethodId method_id, uint32_t arg_count,
661 uint64_t arg_values[], JDWP::JdwpTag* arg_types,
662 uint32_t options)
Mathieu Chartier90443472015-07-16 20:32:27 -0700663 REQUIRES(!Locks::thread_list_lock_, !Locks::thread_suspend_count_lock_)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700664 REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertzcbc50642015-06-01 17:33:12 +0200665
666 // Called by the event thread to execute a method prepared by the JDWP thread in the given
667 // DebugInvokeReq object. Once the invocation completes, the event thread attaches a reply
668 // to that DebugInvokeReq object so it can be sent to the debugger only when the event thread
669 // is ready to suspend (see FinishInvokeMethod).
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700670 static void ExecuteMethod(DebugInvokeReq* pReq);
671
Sebastien Hertzcbc50642015-06-01 17:33:12 +0200672 // Called by the event thread to send the reply of the invoke (created in ExecuteMethod)
673 // before suspending itself. This is to ensure the thread is ready to suspend before the
674 // debugger receives the reply.
675 static void FinishInvokeMethod(DebugInvokeReq* pReq);
676
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700677 /*
678 * DDM support.
679 */
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700680 static void DdmSendThreadNotification(Thread* t, uint32_t type)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700681 REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100682 static void DdmSetThreadNotification(bool enable)
Mathieu Chartier90443472015-07-16 20:32:27 -0700683 REQUIRES(!Locks::thread_list_lock_);
Alex Light8c2b9292017-11-09 13:21:01 -0800684 static bool DdmHandleChunk(
685 JNIEnv* env,
686 uint32_t type,
687 const ArrayRef<const jbyte>& data,
688 /*out*/uint32_t* out_type,
689 /*out*/std::vector<uint8_t>* out_data);
Ian Rogersc0542af2014-09-03 16:16:56 -0700690 static bool DdmHandlePacket(JDWP::Request* request, uint8_t** pReplyBuf, int* pReplyLen);
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700691 static void DdmConnected() REQUIRES_SHARED(Locks::mutator_lock_);
692 static void DdmDisconnected() REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes767a1472011-10-26 18:49:02 -0700693
Mathieu Chartiera6b1ead2015-10-06 10:32:38 -0700694 // Visit breakpoint roots, used to prevent unloading of methods with breakpoints.
Mathieu Chartierbb87e0f2015-04-03 11:21:55 -0700695 static void VisitRoots(RootVisitor* visitor)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700696 REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartier3b05e9b2014-03-25 09:29:43 -0700697
Elliott Hughes545a0642011-11-08 19:10:03 -0800698 /*
Man Cao8c2ff642015-05-27 17:25:30 -0700699 * Allocation tracking support.
Elliott Hughes545a0642011-11-08 19:10:03 -0800700 */
Mathieu Chartier90443472015-07-16 20:32:27 -0700701 static void SetAllocTrackingEnabled(bool enabled) REQUIRES(!Locks::alloc_tracker_lock_);
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100702 static jbyteArray GetRecentAllocations()
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700703 REQUIRES(!Locks::alloc_tracker_lock_) REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartier90443472015-07-16 20:32:27 -0700704 static void DumpRecentAllocations() REQUIRES(!Locks::alloc_tracker_lock_);
Elliott Hughes545a0642011-11-08 19:10:03 -0800705
Elliott Hughes767a1472011-10-26 18:49:02 -0700706 enum HpifWhen {
707 HPIF_WHEN_NEVER = 0,
708 HPIF_WHEN_NOW = 1,
709 HPIF_WHEN_NEXT_GC = 2,
710 HPIF_WHEN_EVERY_GC = 3
711 };
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700712 static int DdmHandleHpifChunk(HpifWhen when)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700713 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes767a1472011-10-26 18:49:02 -0700714
715 enum HpsgWhen {
716 HPSG_WHEN_NEVER = 0,
717 HPSG_WHEN_EVERY_GC = 1,
718 };
719 enum HpsgWhat {
720 HPSG_WHAT_MERGED_OBJECTS = 0,
721 HPSG_WHAT_DISTINCT_OBJECTS = 1,
722 };
723 static bool DdmHandleHpsgNhsgChunk(HpsgWhen when, HpsgWhat what, bool native);
724
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700725 static void DdmSendHeapInfo(HpifWhen reason)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700726 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700727 static void DdmSendHeapSegments(bool native)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700728 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes545a0642011-11-08 19:10:03 -0800729
Sebastien Hertz6995c602014-09-09 12:10:13 +0200730 static ObjectRegistry* GetObjectRegistry() {
731 return gRegistry;
732 }
733
Vladimir Marko423bebb2019-03-26 15:17:21 +0000734 static JDWP::JdwpTag TagFromObject(const ScopedObjectAccessUnchecked& soa,
735 ObjPtr<mirror::Object> o)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700736 REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertz6995c602014-09-09 12:10:13 +0200737
Mathieu Chartier3398c782016-09-30 10:27:43 -0700738 static JDWP::JdwpTypeTag GetTypeTag(ObjPtr<mirror::Class> klass)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700739 REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertz6995c602014-09-09 12:10:13 +0200740
Mathieu Chartierc7853442015-03-27 14:35:38 -0700741 static JDWP::FieldId ToFieldId(const ArtField* f)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700742 REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertz6995c602014-09-09 12:10:13 +0200743
Mathieu Chartiere401d142015-04-22 13:56:20 -0700744 static void SetJdwpLocation(JDWP::JdwpLocation* location, ArtMethod* m, uint32_t dex_pc)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700745 REQUIRES_SHARED(Locks::mutator_lock_)
Mathieu Chartier90443472015-07-16 20:32:27 -0700746 REQUIRES(!Locks::thread_list_lock_, !Locks::thread_suspend_count_lock_);
Sebastien Hertz6995c602014-09-09 12:10:13 +0200747
Mathieu Chartierad466ad2015-01-08 16:28:08 -0800748 static JDWP::JdwpState* GetJdwpState();
749
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700750 static uint32_t GetInstrumentationEvents() REQUIRES_SHARED(Locks::mutator_lock_) {
Sebastien Hertz9d6bf692015-04-10 12:12:33 +0200751 return instrumentation_events_;
752 }
753
Andreas Gampe04bbb5b2017-01-19 17:49:03 +0000754 static ThreadLifecycleCallback* GetThreadLifecycleCallback() {
755 return &thread_lifecycle_callback_;
756 }
Andreas Gampe0f01b582017-01-18 15:22:37 -0800757 static ClassLoadCallback* GetClassLoadCallback() {
758 return &class_load_callback_;
759 }
Andreas Gampe04bbb5b2017-01-19 17:49:03 +0000760
Elliott Hughes545a0642011-11-08 19:10:03 -0800761 private:
Sebastien Hertzcbc50642015-06-01 17:33:12 +0200762 static void ExecuteMethodWithoutPendingException(ScopedObjectAccess& soa, DebugInvokeReq* pReq)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700763 REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertzcbc50642015-06-01 17:33:12 +0200764
765 static void BuildInvokeReply(JDWP::ExpandBuf* pReply, uint32_t request_id,
766 JDWP::JdwpTag result_tag, uint64_t result_value,
767 JDWP::ObjectId exception)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700768 REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertzcbc50642015-06-01 17:33:12 +0200769
Sebastien Hertz8009f392014-09-01 17:07:11 +0200770 static JDWP::JdwpError GetLocalValue(const StackVisitor& visitor,
771 ScopedObjectAccessUnchecked& soa, int slot,
772 JDWP::JdwpTag tag, uint8_t* buf, size_t width)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700773 REQUIRES(!Locks::thread_list_lock_) REQUIRES_SHARED(Locks::mutator_lock_);
Mingyao Yang99170c62015-07-06 11:10:37 -0700774 static JDWP::JdwpError SetLocalValue(Thread* thread, StackVisitor& visitor, int slot,
775 JDWP::JdwpTag tag, uint64_t value, size_t width)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700776 REQUIRES(!Locks::thread_list_lock_) REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertz8009f392014-09-01 17:07:11 +0200777
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700778 static void DdmBroadcast(bool connect) REQUIRES_SHARED(Locks::mutator_lock_);
Andreas Gampe04bbb5b2017-01-19 17:49:03 +0000779
780 static void PostThreadStart(Thread* t)
781 REQUIRES_SHARED(Locks::mutator_lock_);
782 static void PostThreadDeath(Thread* t)
783 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700784 static void PostThreadStartOrStop(Thread*, uint32_t)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700785 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughesa2155262011-11-16 16:26:58 -0800786
Vladimir Marko83114892019-04-11 13:05:50 +0100787 static void PostClassPrepare(ObjPtr<mirror::Class> c)
Andreas Gampe0f01b582017-01-18 15:22:37 -0800788 REQUIRES_SHARED(Locks::mutator_lock_);
789
Vladimir Marko83114892019-04-11 13:05:50 +0100790 static void PostLocationEvent(ArtMethod* method,
791 int pcOffset,
792 ObjPtr<mirror::Object> thisPtr,
793 int eventFlags,
Sebastien Hertz8379b222014-02-24 17:38:15 +0100794 const JValue* return_value)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700795 REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertz8379b222014-02-24 17:38:15 +0100796
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100797 static void ProcessDeoptimizationRequest(const DeoptimizationRequest& request)
Mathieu Chartieraa516822015-10-02 15:53:37 -0700798 REQUIRES(Locks::mutator_lock_, Roles::uninterruptible_);
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100799
Sebastien Hertz7ec2f1c2014-03-27 20:06:47 +0100800 static void RequestDeoptimizationLocked(const DeoptimizationRequest& req)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700801 REQUIRES(Locks::deoptimization_lock_) REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertz7ec2f1c2014-03-27 20:06:47 +0100802
Mathieu Chartiere401d142015-04-22 13:56:20 -0700803 static bool IsForcedInterpreterNeededForCallingImpl(Thread* thread, ArtMethod* m)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700804 REQUIRES_SHARED(Locks::mutator_lock_);
Daniel Mihalyieb076692014-08-22 17:33:31 +0200805
Mathieu Chartiere401d142015-04-22 13:56:20 -0700806 static bool IsForcedInterpreterNeededForResolutionImpl(Thread* thread, ArtMethod* m)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700807 REQUIRES_SHARED(Locks::mutator_lock_);
Daniel Mihalyieb076692014-08-22 17:33:31 +0200808
Mathieu Chartiere401d142015-04-22 13:56:20 -0700809 static bool IsForcedInstrumentationNeededForResolutionImpl(Thread* thread, ArtMethod* m)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700810 REQUIRES_SHARED(Locks::mutator_lock_);
Daniel Mihalyieb076692014-08-22 17:33:31 +0200811
Mathieu Chartiere401d142015-04-22 13:56:20 -0700812 static bool IsForcedInterpreterNeededForUpcallImpl(Thread* thread, ArtMethod* m)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700813 REQUIRES_SHARED(Locks::mutator_lock_);
Daniel Mihalyieb076692014-08-22 17:33:31 +0200814
Sebastien Hertz520633b2015-09-08 17:03:36 +0200815 static bool IsForcedInterpreterNeededForExceptionImpl(Thread* thread)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700816 REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertz520633b2015-09-08 17:03:36 +0200817
Daniel Mihalyieb076692014-08-22 17:33:31 +0200818 // Indicates whether the debugger is making requests.
819 static bool gDebuggerActive;
820
Alex Light21611932017-09-26 13:07:39 -0700821 static DebuggerActiveMethodInspectionCallback gDebugActiveCallback;
Alex Light8c2b9292017-11-09 13:21:01 -0800822 static DebuggerDdmCallback gDebugDdmCallback;
Alex Light40320712017-12-14 11:52:04 -0800823 static InternalDebuggerControlCallback gDebuggerControlCallback;
Alex Light21611932017-09-26 13:07:39 -0700824
Sebastien Hertz4e5b2082015-03-24 19:03:40 +0100825 // Indicates whether we should drop the JDWP connection because the runtime stops or the
826 // debugger called VirtualMachine.Dispose.
827 static bool gDisposed;
828
Daniel Mihalyieb076692014-08-22 17:33:31 +0200829 // The registry mapping objects to JDWP ids.
Sebastien Hertz6995c602014-09-09 12:10:13 +0200830 static ObjectRegistry* gRegistry;
831
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100832 // Deoptimization requests to be processed each time the event list is updated. This is used when
833 // registering and unregistering events so we do not deoptimize while holding the event list
834 // lock.
Sebastien Hertz42cd43f2014-05-13 14:15:41 +0200835 // TODO rename to instrumentation_requests.
Brian Carlstrom306db812014-09-05 13:01:41 -0700836 static std::vector<DeoptimizationRequest> deoptimization_requests_ GUARDED_BY(Locks::deoptimization_lock_);
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100837
838 // Count the number of events requiring full deoptimization. When the counter is > 0, everything
839 // is deoptimized, otherwise everything is undeoptimized.
840 // Note: we fully deoptimize on the first event only (when the counter is set to 1). We fully
841 // undeoptimize when the last event is unregistered (when the counter is set to 0).
Brian Carlstrom306db812014-09-05 13:01:41 -0700842 static size_t full_deoptimization_event_count_ GUARDED_BY(Locks::deoptimization_lock_);
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100843
Sebastien Hertz42cd43f2014-05-13 14:15:41 +0200844 static size_t* GetReferenceCounterForEvent(uint32_t instrumentation_event);
845
846 // Instrumentation event reference counters.
847 // TODO we could use an array instead of having all these dedicated counters. Instrumentation
848 // events are bits of a mask so we could convert them to array index.
Brian Carlstrom306db812014-09-05 13:01:41 -0700849 static size_t dex_pc_change_event_ref_count_ GUARDED_BY(Locks::deoptimization_lock_);
850 static size_t method_enter_event_ref_count_ GUARDED_BY(Locks::deoptimization_lock_);
851 static size_t method_exit_event_ref_count_ GUARDED_BY(Locks::deoptimization_lock_);
852 static size_t field_read_event_ref_count_ GUARDED_BY(Locks::deoptimization_lock_);
853 static size_t field_write_event_ref_count_ GUARDED_BY(Locks::deoptimization_lock_);
854 static size_t exception_catch_event_ref_count_ GUARDED_BY(Locks::deoptimization_lock_);
Sebastien Hertz42cd43f2014-05-13 14:15:41 +0200855 static uint32_t instrumentation_events_ GUARDED_BY(Locks::mutator_lock_);
856
Andreas Gampe04bbb5b2017-01-19 17:49:03 +0000857 class DbgThreadLifecycleCallback : public ThreadLifecycleCallback {
858 public:
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100859 void ThreadStart(Thread* self) override REQUIRES_SHARED(Locks::mutator_lock_);
860 void ThreadDeath(Thread* self) override REQUIRES_SHARED(Locks::mutator_lock_);
Andreas Gampe04bbb5b2017-01-19 17:49:03 +0000861 };
862
Andreas Gampe0f01b582017-01-18 15:22:37 -0800863 class DbgClassLoadCallback : public ClassLoadCallback {
864 public:
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100865 void ClassLoad(Handle<mirror::Class> klass) override REQUIRES_SHARED(Locks::mutator_lock_);
Andreas Gampe0f01b582017-01-18 15:22:37 -0800866 void ClassPrepare(Handle<mirror::Class> temp_klass,
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100867 Handle<mirror::Class> klass) override REQUIRES_SHARED(Locks::mutator_lock_);
Andreas Gampe0f01b582017-01-18 15:22:37 -0800868 };
869
Andreas Gampe04bbb5b2017-01-19 17:49:03 +0000870 static DbgThreadLifecycleCallback thread_lifecycle_callback_;
Andreas Gampe0f01b582017-01-18 15:22:37 -0800871 static DbgClassLoadCallback class_load_callback_;
Andreas Gampe04bbb5b2017-01-19 17:49:03 +0000872
Ian Rogers719d1a32014-03-06 12:13:39 -0800873 DISALLOW_COPY_AND_ASSIGN(Dbg);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700874};
875
876#define CHUNK_TYPE(_name) \
Elliott Hughes82188472011-11-07 18:11:48 -0800877 static_cast<uint32_t>((_name)[0] << 24 | (_name)[1] << 16 | (_name)[2] << 8 | (_name)[3])
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700878
879} // namespace art
880
Brian Carlstromfc0e3212013-07-17 14:40:12 -0700881#endif // ART_RUNTIME_DEBUGGER_H_