blob: 74018137a0b43717a21492a02986bb880fe48c96 [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 {
57 bool IsMethodBeingInspected(ArtMethod* method) OVERRIDE REQUIRES_SHARED(Locks::mutator_lock_);
58 bool IsMethodSafeToJit(ArtMethod* method) OVERRIDE REQUIRES_SHARED(Locks::mutator_lock_);
59};
60
Alex Light8c2b9292017-11-09 13:21:01 -080061struct DebuggerDdmCallback : public DdmCallback {
62 void DdmPublishChunk(uint32_t type, const ArrayRef<const uint8_t>& data)
63 OVERRIDE REQUIRES_SHARED(Locks::mutator_lock_);
64};
65
Alex Light40320712017-12-14 11:52:04 -080066struct InternalDebuggerControlCallback : public DebuggerControlCallback {
67 void StartDebugger() OVERRIDE;
68 void StopDebugger() OVERRIDE;
69 bool IsDebuggerConfigured() OVERRIDE;
Alex Light21611932017-09-26 13:07:39 -070070};
71
Elliott Hughes872d4ec2011-10-21 17:07:15 -070072/*
73 * Invoke-during-breakpoint support.
74 */
75struct DebugInvokeReq {
Sebastien Hertzcbc50642015-06-01 17:33:12 +020076 DebugInvokeReq(uint32_t invoke_request_id, JDWP::ObjectId invoke_thread_id,
77 mirror::Object* invoke_receiver, mirror::Class* invoke_class,
Mathieu Chartiere401d142015-04-22 13:56:20 -070078 ArtMethod* invoke_method, uint32_t invoke_options,
Sebastien Hertzcbc50642015-06-01 17:33:12 +020079 uint64_t args[], uint32_t args_count)
80 : request_id(invoke_request_id), thread_id(invoke_thread_id), receiver(invoke_receiver),
81 klass(invoke_class), method(invoke_method), arg_count(args_count), arg_values(args),
82 options(invoke_options), reply(JDWP::expandBufAlloc()) {
Elliott Hughes475fc232011-10-25 15:00:35 -070083 }
84
Sebastien Hertzcbc50642015-06-01 17:33:12 +020085 ~DebugInvokeReq() {
86 JDWP::expandBufFree(reply);
87 }
88
89 // Request
90 const uint32_t request_id;
91 const JDWP::ObjectId thread_id;
92 GcRoot<mirror::Object> receiver; // not used for ClassType.InvokeMethod.
Sebastien Hertz1558b572015-02-25 15:05:59 +010093 GcRoot<mirror::Class> klass;
Sebastien Hertzcbc50642015-06-01 17:33:12 +020094 ArtMethod* const method;
Sebastien Hertz1558b572015-02-25 15:05:59 +010095 const uint32_t arg_count;
Sebastien Hertzcbc50642015-06-01 17:33:12 +020096 std::unique_ptr<uint64_t[]> arg_values; // will be null if arg_count_ == 0. We take ownership
97 // of this array so we must delete it upon destruction.
Sebastien Hertz1558b572015-02-25 15:05:59 +010098 const uint32_t options;
Elliott Hughes872d4ec2011-10-21 17:07:15 -070099
Sebastien Hertzcbc50642015-06-01 17:33:12 +0200100 // Reply
101 JDWP::ExpandBuf* const reply;
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +0100102
Mathieu Chartierbb87e0f2015-04-03 11:21:55 -0700103 void VisitRoots(RootVisitor* visitor, const RootInfo& root_info)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700104 REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartier3b05e9b2014-03-25 09:29:43 -0700105
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +0100106 private:
107 DISALLOW_COPY_AND_ASSIGN(DebugInvokeReq);
108};
109
110// Thread local data-structure that holds fields for controlling single-stepping.
Sebastien Hertz597c4f02015-01-26 17:37:14 +0100111class SingleStepControl {
112 public:
113 SingleStepControl(JDWP::JdwpStepSize step_size, JDWP::JdwpStepDepth step_depth,
Mathieu Chartiere401d142015-04-22 13:56:20 -0700114 int stack_depth, ArtMethod* method)
Sebastien Hertz597c4f02015-01-26 17:37:14 +0100115 : step_size_(step_size), step_depth_(step_depth),
116 stack_depth_(stack_depth), method_(method) {
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +0100117 }
118
Sebastien Hertz597c4f02015-01-26 17:37:14 +0100119 JDWP::JdwpStepSize GetStepSize() const {
120 return step_size_;
121 }
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +0100122
Sebastien Hertz597c4f02015-01-26 17:37:14 +0100123 JDWP::JdwpStepDepth GetStepDepth() const {
124 return step_depth_;
125 }
126
127 int GetStackDepth() const {
128 return stack_depth_;
129 }
130
Mathieu Chartiere401d142015-04-22 13:56:20 -0700131 ArtMethod* GetMethod() const {
132 return method_;
Sebastien Hertz597c4f02015-01-26 17:37:14 +0100133 }
134
135 const std::set<uint32_t>& GetDexPcs() const {
136 return dex_pcs_;
137 }
138
Sebastien Hertz597c4f02015-01-26 17:37:14 +0100139 void AddDexPc(uint32_t dex_pc);
140
141 bool ContainsDexPc(uint32_t dex_pc) const;
142
143 private:
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +0100144 // See JdwpStepSize and JdwpStepDepth for details.
Sebastien Hertz597c4f02015-01-26 17:37:14 +0100145 const JDWP::JdwpStepSize step_size_;
146 const JDWP::JdwpStepDepth step_depth_;
147
148 // The stack depth when this single-step was initiated. This is used to support SD_OVER and SD_OUT
149 // single-step depth.
150 const int stack_depth_;
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +0100151
152 // The location this single-step was initiated from.
153 // A single-step is initiated in a suspended thread. We save here the current method and the
154 // set of DEX pcs associated to the source line number where the suspension occurred.
155 // This is used to support SD_INTO and SD_OVER single-step depths so we detect when a single-step
156 // causes the execution of an instruction in a different method or at a different line number.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700157 ArtMethod* method_;
158
Sebastien Hertz597c4f02015-01-26 17:37:14 +0100159 std::set<uint32_t> dex_pcs_;
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +0100160
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +0100161 DISALLOW_COPY_AND_ASSIGN(SingleStepControl);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700162};
163
Sebastien Hertz42cd43f2014-05-13 14:15:41 +0200164// TODO rename to InstrumentationRequest.
Hiroshi Yamauchi0ec17d22014-07-07 13:07:08 -0700165class DeoptimizationRequest {
166 public:
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100167 enum Kind {
168 kNothing, // no action.
Sebastien Hertz42cd43f2014-05-13 14:15:41 +0200169 kRegisterForEvent, // start listening for instrumentation event.
170 kUnregisterForEvent, // stop listening for instrumentation event.
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100171 kFullDeoptimization, // deoptimize everything.
172 kFullUndeoptimization, // undeoptimize everything.
173 kSelectiveDeoptimization, // deoptimize one method.
174 kSelectiveUndeoptimization // undeoptimize one method.
175 };
176
Hiroshi Yamauchi0ec17d22014-07-07 13:07:08 -0700177 DeoptimizationRequest() : kind_(kNothing), instrumentation_event_(0), method_(nullptr) {}
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100178
Hiroshi Yamauchi0ec17d22014-07-07 13:07:08 -0700179 DeoptimizationRequest(const DeoptimizationRequest& other)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700180 REQUIRES_SHARED(Locks::mutator_lock_)
Hiroshi Yamauchi0ec17d22014-07-07 13:07:08 -0700181 : kind_(other.kind_), instrumentation_event_(other.instrumentation_event_) {
182 // Create a new JNI global reference for the method.
183 SetMethod(other.Method());
184 }
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100185
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700186 ArtMethod* Method() const REQUIRES_SHARED(Locks::mutator_lock_);
Hiroshi Yamauchi0ec17d22014-07-07 13:07:08 -0700187
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700188 void SetMethod(ArtMethod* m) REQUIRES_SHARED(Locks::mutator_lock_);
Hiroshi Yamauchi0ec17d22014-07-07 13:07:08 -0700189
190 // Name 'Kind()' would collide with the above enum name.
191 Kind GetKind() const {
192 return kind_;
193 }
194
195 void SetKind(Kind kind) {
196 kind_ = kind;
197 }
198
199 uint32_t InstrumentationEvent() const {
200 return instrumentation_event_;
201 }
202
203 void SetInstrumentationEvent(uint32_t instrumentation_event) {
204 instrumentation_event_ = instrumentation_event;
205 }
206
207 private:
208 Kind kind_;
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100209
Sebastien Hertz42cd43f2014-05-13 14:15:41 +0200210 // TODO we could use a union to hold the instrumentation_event and the method since they
211 // respectively have sense only for kRegisterForEvent/kUnregisterForEvent and
212 // kSelectiveDeoptimization/kSelectiveUndeoptimization.
213
214 // Event to start or stop listening to. Only for kRegisterForEvent and kUnregisterForEvent.
Hiroshi Yamauchi0ec17d22014-07-07 13:07:08 -0700215 uint32_t instrumentation_event_;
Sebastien Hertz42cd43f2014-05-13 14:15:41 +0200216
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100217 // Method for selective deoptimization.
Hiroshi Yamauchi0ec17d22014-07-07 13:07:08 -0700218 jmethodID method_;
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100219};
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700220std::ostream& operator<<(std::ostream& os, const DeoptimizationRequest::Kind& rhs);
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100221
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700222class Dbg {
Elliott Hughesff17f1f2012-01-24 18:12:29 -0800223 public:
Elliott Hughes4ffd3132011-10-24 12:06:42 -0700224 static void SetJdwpAllowed(bool allowed);
Leonard Mosescueb842212016-10-06 17:26:36 -0700225 static bool IsJdwpAllowed();
Elliott Hughes4ffd3132011-10-24 12:06:42 -0700226
Sebastien Hertzb3b173b2015-02-06 09:16:32 +0100227 static void StartJdwp();
Elliott Hughesd1cc8362011-10-24 16:58:50 -0700228 static void StopJdwp();
229
Elliott Hughes767a1472011-10-26 18:49:02 -0700230 // Invoked by the GC in case we need to keep DDMS informed.
Mathieu Chartier90443472015-07-16 20:32:27 -0700231 static void GcDidFinish() REQUIRES(!Locks::mutator_lock_);
Elliott Hughes767a1472011-10-26 18:49:02 -0700232
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700233 // Return the DebugInvokeReq for the current thread.
234 static DebugInvokeReq* GetInvokeReq();
235
Elliott Hughes475fc232011-10-25 15:00:35 -0700236 static Thread* GetDebugThread();
237 static void ClearWaitForEventThread();
238
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700239 /*
240 * Enable/disable breakpoints and step modes. Used to provide a heads-up
241 * when the debugger attaches.
242 */
243 static void Connected();
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100244 static void GoActive()
Mathieu Chartier90443472015-07-16 20:32:27 -0700245 REQUIRES(!Locks::breakpoint_lock_, !Locks::deoptimization_lock_, !Locks::mutator_lock_);
246 static void Disconnected() REQUIRES(!Locks::deoptimization_lock_, !Locks::mutator_lock_);
Sebastien Hertz4e5b2082015-03-24 19:03:40 +0100247 static void Dispose() {
248 gDisposed = true;
249 }
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700250
Elliott Hughesc0f09332012-03-26 13:27:06 -0700251 // Returns true if we're actually debugging with a real debugger, false if it's
252 // just DDMS (or nothing at all).
Daniel Mihalyieb076692014-08-22 17:33:31 +0200253 static bool IsDebuggerActive() {
254 return gDebuggerActive;
255 }
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700256
Sebastien Hertzb3b173b2015-02-06 09:16:32 +0100257 // Configures JDWP with parsed command-line options.
Alex Light40320712017-12-14 11:52:04 -0800258 static void ConfigureJdwp(const JDWP::JdwpOptions& jdwp_options)
259 REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertzb3b173b2015-02-06 09:16:32 +0100260
Elliott Hughesc0f09332012-03-26 13:27:06 -0700261 // Returns true if we had -Xrunjdwp or -agentlib:jdwp= on the command line.
262 static bool IsJdwpConfigured();
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700263
Mathieu Chartierd8565452015-03-26 09:41:50 -0700264 // Returns true if a method has any breakpoints.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700265 static bool MethodHasAnyBreakpoints(ArtMethod* method)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700266 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!Locks::breakpoint_lock_);
Mathieu Chartierd8565452015-03-26 09:41:50 -0700267
Sebastien Hertz4e5b2082015-03-24 19:03:40 +0100268 static bool IsDisposed() {
269 return gDisposed;
270 }
Elliott Hughes86964332012-02-15 19:37:42 -0800271
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700272 /*
273 * Time, in milliseconds, since the last debugger activity. Does not
274 * include DDMS activity. Returns -1 if there has been no activity.
275 * Returns 0 if we're in the middle of handling a debugger request.
276 */
277 static int64_t LastDebuggerActivity();
278
Sebastien Hertz253fa552014-10-14 17:27:15 +0200279 static void UndoDebuggerSuspensions()
Mathieu Chartier90443472015-07-16 20:32:27 -0700280 REQUIRES(!Locks::thread_list_lock_, !Locks::thread_suspend_count_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700281
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700282 /*
283 * Class, Object, Array
284 */
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700285 static std::string GetClassName(JDWP::RefTypeId id)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700286 REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertz6995c602014-09-09 12:10:13 +0200287 static std::string GetClassName(mirror::Class* klass)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700288 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogersc0542af2014-09-03 16:16:56 -0700289 static JDWP::JdwpError GetClassObject(JDWP::RefTypeId id, JDWP::ObjectId* class_object_id)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700290 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogersc0542af2014-09-03 16:16:56 -0700291 static JDWP::JdwpError GetSuperclass(JDWP::RefTypeId id, JDWP::RefTypeId* superclass_id)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700292 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700293 static JDWP::JdwpError GetClassLoader(JDWP::RefTypeId id, JDWP::ExpandBuf* pReply)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700294 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700295 static JDWP::JdwpError GetModifiers(JDWP::RefTypeId id, JDWP::ExpandBuf* pReply)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700296 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800297 static JDWP::JdwpError GetReflectedType(JDWP::RefTypeId class_id, JDWP::ExpandBuf* pReply)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700298 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogersc0542af2014-09-03 16:16:56 -0700299 static void GetClassList(std::vector<JDWP::RefTypeId>* classes)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700300 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800301 static JDWP::JdwpError GetClassInfo(JDWP::RefTypeId class_id, JDWP::JdwpTypeTag* pTypeTag,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700302 uint32_t* pStatus, std::string* pDescriptor)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700303 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogersc0542af2014-09-03 16:16:56 -0700304 static void FindLoadedClassBySignature(const char* descriptor, std::vector<JDWP::RefTypeId>* ids)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700305 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes64f574f2013-02-20 14:57:12 -0800306 static JDWP::JdwpError GetReferenceType(JDWP::ObjectId object_id, JDWP::ExpandBuf* pReply)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700307 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogersfc0e94b2013-09-23 23:51:32 -0700308 static JDWP::JdwpError GetSignature(JDWP::RefTypeId ref_type_id, std::string* signature)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700309 REQUIRES_SHARED(Locks::mutator_lock_);
Orion Hodson77d8a1c2017-04-24 14:53:19 +0100310 static JDWP::JdwpError GetSourceDebugExtension(JDWP::RefTypeId ref_type_id,
311 std::string* extension_data)
312 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogersc0542af2014-09-03 16:16:56 -0700313 static JDWP::JdwpError GetSourceFile(JDWP::RefTypeId ref_type_id, std::string* source_file)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700314 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogersc0542af2014-09-03 16:16:56 -0700315 static JDWP::JdwpError GetObjectTag(JDWP::ObjectId object_id, uint8_t* tag)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700316 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughesaed4be92011-12-02 16:16:23 -0800317 static size_t GetTagWidth(JDWP::JdwpTag tag);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700318
Ian Rogersc0542af2014-09-03 16:16:56 -0700319 static JDWP::JdwpError GetArrayLength(JDWP::ObjectId array_id, int32_t* length)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700320 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800321 static JDWP::JdwpError OutputArray(JDWP::ObjectId array_id, int offset, int count,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700322 JDWP::ExpandBuf* pReply)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700323 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800324 static JDWP::JdwpError SetArrayElements(JDWP::ObjectId array_id, int offset, int count,
Ian Rogersc0542af2014-09-03 16:16:56 -0700325 JDWP::Request* request)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700326 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700327
Sebastien Hertz2c3e77a2015-04-02 16:26:48 +0200328 static JDWP::JdwpError CreateString(const std::string& str, JDWP::ObjectId* new_string_id)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700329 REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertz2c3e77a2015-04-02 16:26:48 +0200330 static JDWP::JdwpError CreateObject(JDWP::RefTypeId class_id, JDWP::ObjectId* new_object_id)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700331 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800332 static JDWP::JdwpError CreateArrayObject(JDWP::RefTypeId array_class_id, uint32_t length,
Sebastien Hertz2c3e77a2015-04-02 16:26:48 +0200333 JDWP::ObjectId* new_array_id)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700334 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700335
Sebastien Hertz6995c602014-09-09 12:10:13 +0200336 //
337 // Event filtering.
338 //
339 static bool MatchThread(JDWP::ObjectId expected_thread_id, Thread* event_thread)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700340 REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertz6995c602014-09-09 12:10:13 +0200341
342 static bool MatchLocation(const JDWP::JdwpLocation& expected_location,
343 const JDWP::EventLocation& event_location)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700344 REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertz6995c602014-09-09 12:10:13 +0200345
Mathieu Chartier3398c782016-09-30 10:27:43 -0700346 static bool MatchType(ObjPtr<mirror::Class> event_class, JDWP::RefTypeId class_id)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700347 REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertz6995c602014-09-09 12:10:13 +0200348
349 static bool MatchField(JDWP::RefTypeId expected_type_id, JDWP::FieldId expected_field_id,
Mathieu Chartierc7853442015-03-27 14:35:38 -0700350 ArtField* event_field)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700351 REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertz6995c602014-09-09 12:10:13 +0200352
353 static bool MatchInstance(JDWP::ObjectId expected_instance_id, mirror::Object* event_instance)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700354 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700355
Elliott Hughesec0f83d2013-01-15 16:54:08 -0800356 //
357 // Monitors.
358 //
359 static JDWP::JdwpError GetMonitorInfo(JDWP::ObjectId object_id, JDWP::ExpandBuf* reply)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700360 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughesec0f83d2013-01-15 16:54:08 -0800361 static JDWP::JdwpError GetOwnedMonitors(JDWP::ObjectId thread_id,
Ian Rogersc0542af2014-09-03 16:16:56 -0700362 std::vector<JDWP::ObjectId>* monitors,
363 std::vector<uint32_t>* stack_depths)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700364 REQUIRES(!Locks::thread_list_lock_) REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100365 static JDWP::JdwpError GetContendedMonitor(JDWP::ObjectId thread_id,
Ian Rogersc0542af2014-09-03 16:16:56 -0700366 JDWP::ObjectId* contended_monitor)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700367 REQUIRES(!Locks::thread_list_lock_) REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughesec0f83d2013-01-15 16:54:08 -0800368
369 //
370 // Heap.
371 //
372 static JDWP::JdwpError GetInstanceCounts(const std::vector<JDWP::RefTypeId>& class_ids,
Ian Rogersc0542af2014-09-03 16:16:56 -0700373 std::vector<uint64_t>* counts)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700374 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes3b78c942013-01-15 17:35:41 -0800375 static JDWP::JdwpError GetInstances(JDWP::RefTypeId class_id, int32_t max_count,
Ian Rogersc0542af2014-09-03 16:16:56 -0700376 std::vector<JDWP::ObjectId>* instances)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700377 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes0cbaff52013-01-16 15:28:01 -0800378 static JDWP::JdwpError GetReferringObjects(JDWP::ObjectId object_id, int32_t max_count,
Ian Rogersc0542af2014-09-03 16:16:56 -0700379 std::vector<JDWP::ObjectId>* referring_objects)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700380 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes64f574f2013-02-20 14:57:12 -0800381 static JDWP::JdwpError DisableCollection(JDWP::ObjectId object_id)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700382 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes64f574f2013-02-20 14:57:12 -0800383 static JDWP::JdwpError EnableCollection(JDWP::ObjectId object_id)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700384 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogersc0542af2014-09-03 16:16:56 -0700385 static JDWP::JdwpError IsCollected(JDWP::ObjectId object_id, bool* is_collected)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700386 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes64f574f2013-02-20 14:57:12 -0800387 static void DisposeObject(JDWP::ObjectId object_id, uint32_t reference_count)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700388 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughesec0f83d2013-01-15 16:54:08 -0800389
Elliott Hughes9777ba22013-01-17 09:04:19 -0800390 //
391 // Methods and fields.
392 //
Elliott Hughesa96836a2013-01-17 12:27:49 -0800393 static std::string GetMethodName(JDWP::MethodId method_id)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700394 REQUIRES_SHARED(Locks::mutator_lock_);
Alex Light73376312017-04-06 10:10:51 -0700395 static bool IsMethodObsolete(JDWP::MethodId method_id)
396 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800397 static JDWP::JdwpError OutputDeclaredFields(JDWP::RefTypeId ref_type_id, bool with_generic,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700398 JDWP::ExpandBuf* pReply)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700399 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800400 static JDWP::JdwpError OutputDeclaredMethods(JDWP::RefTypeId ref_type_id, bool with_generic,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700401 JDWP::ExpandBuf* pReply)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700402 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800403 static JDWP::JdwpError OutputDeclaredInterfaces(JDWP::RefTypeId ref_type_id,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700404 JDWP::ExpandBuf* pReply)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700405 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800406 static void OutputLineTable(JDWP::RefTypeId ref_type_id, JDWP::MethodId method_id,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700407 JDWP::ExpandBuf* pReply)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700408 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800409 static void OutputVariableTable(JDWP::RefTypeId ref_type_id, JDWP::MethodId id, bool with_generic,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700410 JDWP::ExpandBuf* pReply)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700411 REQUIRES_SHARED(Locks::mutator_lock_);
Jeff Hao579b0242013-11-18 13:16:49 -0800412 static void OutputMethodReturnValue(JDWP::MethodId method_id, const JValue* return_value,
413 JDWP::ExpandBuf* pReply)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700414 REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertz3f52eaf2014-04-04 17:50:18 +0200415 static void OutputFieldValue(JDWP::FieldId field_id, const JValue* field_value,
416 JDWP::ExpandBuf* pReply)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700417 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes9777ba22013-01-17 09:04:19 -0800418 static JDWP::JdwpError GetBytecodes(JDWP::RefTypeId class_id, JDWP::MethodId method_id,
Ian Rogersc0542af2014-09-03 16:16:56 -0700419 std::vector<uint8_t>* bytecodes)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700420 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700421
Elliott Hughesa96836a2013-01-17 12:27:49 -0800422 static std::string GetFieldName(JDWP::FieldId field_id)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700423 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800424 static JDWP::JdwpTag GetFieldBasicTag(JDWP::FieldId field_id)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700425 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800426 static JDWP::JdwpTag GetStaticFieldBasicTag(JDWP::FieldId field_id)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700427 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800428 static JDWP::JdwpError GetFieldValue(JDWP::ObjectId object_id, JDWP::FieldId field_id,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700429 JDWP::ExpandBuf* pReply)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700430 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800431 static JDWP::JdwpError SetFieldValue(JDWP::ObjectId object_id, JDWP::FieldId field_id,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700432 uint64_t value, int width)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700433 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800434 static JDWP::JdwpError GetStaticFieldValue(JDWP::RefTypeId ref_type_id, JDWP::FieldId field_id,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700435 JDWP::ExpandBuf* pReply)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700436 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800437 static JDWP::JdwpError SetStaticFieldValue(JDWP::FieldId field_id, uint64_t value, int width)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700438 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700439
Sebastien Hertzb0b0b492014-09-15 11:27:27 +0200440 static JDWP::JdwpError StringToUtf8(JDWP::ObjectId string_id, std::string* str)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700441 REQUIRES_SHARED(Locks::mutator_lock_);
Jeff Hao579b0242013-11-18 13:16:49 -0800442 static void OutputJValue(JDWP::JdwpTag tag, const JValue* return_value, JDWP::ExpandBuf* pReply)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700443 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700444
445 /*
446 * Thread, ThreadGroup, Frame
447 */
Ian Rogersc0542af2014-09-03 16:16:56 -0700448 static JDWP::JdwpError GetThreadName(JDWP::ObjectId thread_id, std::string* name)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700449 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!Locks::thread_list_lock_);
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100450 static JDWP::JdwpError GetThreadGroup(JDWP::ObjectId thread_id, JDWP::ExpandBuf* pReply)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700451 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!Locks::thread_list_lock_);
Sebastien Hertza06430c2014-09-15 19:21:30 +0200452 static JDWP::JdwpError GetThreadGroupName(JDWP::ObjectId thread_group_id,
453 JDWP::ExpandBuf* pReply)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700454 REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertza06430c2014-09-15 19:21:30 +0200455 static JDWP::JdwpError GetThreadGroupParent(JDWP::ObjectId thread_group_id,
456 JDWP::ExpandBuf* pReply)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700457 REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertza06430c2014-09-15 19:21:30 +0200458 static JDWP::JdwpError GetThreadGroupChildren(JDWP::ObjectId thread_group_id,
459 JDWP::ExpandBuf* pReply)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700460 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700461 static JDWP::ObjectId GetSystemThreadGroupId()
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700462 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700463
Jeff Hao920af3e2013-08-28 15:46:38 -0700464 static JDWP::JdwpThreadStatus ToJdwpThreadStatus(ThreadState state);
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100465 static JDWP::JdwpError GetThreadStatus(JDWP::ObjectId thread_id,
466 JDWP::JdwpThreadStatus* pThreadStatus,
467 JDWP::JdwpSuspendStatus* pSuspendStatus)
Mathieu Chartier90443472015-07-16 20:32:27 -0700468 REQUIRES(!Locks::thread_list_lock_);
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100469 static JDWP::JdwpError GetThreadDebugSuspendCount(JDWP::ObjectId thread_id,
470 JDWP::ExpandBuf* pReply)
Mathieu Chartier90443472015-07-16 20:32:27 -0700471 REQUIRES(!Locks::thread_list_lock_, !Locks::thread_suspend_count_lock_);
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700472 // static void WaitForSuspend(JDWP::ObjectId thread_id);
Elliott Hughescaf76542012-06-28 16:08:22 -0700473
Elliott Hughes026b1462012-06-28 20:43:49 -0700474 // Fills 'thread_ids' with the threads in the given thread group. If thread_group_id == 0,
Elliott Hughescaf76542012-06-28 16:08:22 -0700475 // returns all threads.
Sebastien Hertza06430c2014-09-15 19:21:30 +0200476 static void GetThreads(mirror::Object* thread_group, std::vector<JDWP::ObjectId>* thread_ids)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700477 REQUIRES(!Locks::thread_list_lock_) REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughescaf76542012-06-28 16:08:22 -0700478
Ian Rogersc0542af2014-09-03 16:16:56 -0700479 static JDWP::JdwpError GetThreadFrameCount(JDWP::ObjectId thread_id, size_t* result)
Mathieu Chartier90443472015-07-16 20:32:27 -0700480 REQUIRES(!Locks::thread_list_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700481 static JDWP::JdwpError GetThreadFrames(JDWP::ObjectId thread_id, size_t start_frame,
482 size_t frame_count, JDWP::ExpandBuf* buf)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700483 REQUIRES(!Locks::thread_list_lock_) REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700484
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700485 static JDWP::ObjectId GetThreadSelfId() REQUIRES_SHARED(Locks::mutator_lock_);
486 static JDWP::ObjectId GetThreadId(Thread* thread) REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertz6995c602014-09-09 12:10:13 +0200487
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700488 static void SuspendVM()
Mathieu Chartier90443472015-07-16 20:32:27 -0700489 REQUIRES(!Locks::thread_list_lock_, !Locks::thread_suspend_count_lock_);
Sebastien Hertz253fa552014-10-14 17:27:15 +0200490 static void ResumeVM()
Mathieu Chartier90443472015-07-16 20:32:27 -0700491 REQUIRES(!Locks::thread_list_lock_, !Locks::thread_suspend_count_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800492 static JDWP::JdwpError SuspendThread(JDWP::ObjectId thread_id, bool request_suspension = true)
Mathieu Chartier90443472015-07-16 20:32:27 -0700493 REQUIRES(!Locks::mutator_lock_, !Locks::thread_list_lock_,
494 !Locks::thread_suspend_count_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700495
Elliott Hughes88d63092013-01-09 09:55:54 -0800496 static void ResumeThread(JDWP::ObjectId thread_id)
Mathieu Chartier90443472015-07-16 20:32:27 -0700497 REQUIRES(!Locks::thread_list_lock_, !Locks::thread_suspend_count_lock_)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700498 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700499 static void SuspendSelf();
500
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700501 static JDWP::JdwpError GetThisObject(JDWP::ObjectId thread_id, JDWP::FrameId frame_id,
502 JDWP::ObjectId* result)
Mathieu Chartier90443472015-07-16 20:32:27 -0700503 REQUIRES(!Locks::thread_list_lock_, !Locks::thread_suspend_count_lock_)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700504 REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertz8009f392014-09-01 17:07:11 +0200505 static JDWP::JdwpError GetLocalValues(JDWP::Request* request, JDWP::ExpandBuf* pReply)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700506 REQUIRES(!Locks::thread_list_lock_) REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertz8009f392014-09-01 17:07:11 +0200507 static JDWP::JdwpError SetLocalValues(JDWP::Request* request)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700508 REQUIRES(!Locks::thread_list_lock_) REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700509
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100510 static JDWP::JdwpError Interrupt(JDWP::ObjectId thread_id)
Mathieu Chartier90443472015-07-16 20:32:27 -0700511 REQUIRES(!Locks::thread_list_lock_);
Elliott Hughesf9501702013-01-11 11:22:27 -0800512
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700513 /*
514 * Debugger notification
515 */
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700516 enum EventFlag {
Elliott Hughes86964332012-02-15 19:37:42 -0800517 kBreakpoint = 0x01,
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700518 kSingleStep = 0x02,
519 kMethodEntry = 0x04,
520 kMethodExit = 0x08,
521 };
Mathieu Chartiere401d142015-04-22 13:56:20 -0700522 static void PostFieldAccessEvent(ArtMethod* m, int dex_pc, mirror::Object* this_object,
Mathieu Chartierc7853442015-03-27 14:35:38 -0700523 ArtField* f)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700524 REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700525 static void PostFieldModificationEvent(ArtMethod* m, int dex_pc,
Mathieu Chartierc7853442015-03-27 14:35:38 -0700526 mirror::Object* this_object, ArtField* f,
Sebastien Hertz3f52eaf2014-04-04 17:50:18 +0200527 const JValue* field_value)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700528 REQUIRES_SHARED(Locks::mutator_lock_);
Nicolas Geoffray14691c52015-03-05 10:40:17 +0000529 static void PostException(mirror::Throwable* exception)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700530 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700531
Ian Rogers62d6c772013-02-27 08:32:07 -0800532 static void UpdateDebugger(Thread* thread, mirror::Object* this_object,
Mathieu Chartiere401d142015-04-22 13:56:20 -0700533 ArtMethod* method, uint32_t new_dex_pc,
Sebastien Hertz8379b222014-02-24 17:38:15 +0100534 int event_flags, const JValue* return_value)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700535 REQUIRES(!Locks::breakpoint_lock_) REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes91bf6cd2012-02-14 17:27:48 -0800536
Sebastien Hertzf3928792014-11-17 19:00:37 +0100537 // Indicates whether we need deoptimization for debugging.
538 static bool RequiresDeoptimization();
539
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100540 // Records deoptimization request in the queue.
541 static void RequestDeoptimization(const DeoptimizationRequest& req)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700542 REQUIRES(!Locks::deoptimization_lock_) REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100543
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100544 // Manage deoptimization after updating JDWP events list. Suspends all threads, processes each
545 // request and finally resumes all threads.
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100546 static void ManageDeoptimization()
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700547 REQUIRES(!Locks::deoptimization_lock_) REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100548
549 // Breakpoints.
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100550 static void WatchLocation(const JDWP::JdwpLocation* pLoc, DeoptimizationRequest* req)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700551 REQUIRES(!Locks::breakpoint_lock_) REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100552 static void UnwatchLocation(const JDWP::JdwpLocation* pLoc, DeoptimizationRequest* req)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700553 REQUIRES(!Locks::breakpoint_lock_) REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100554
Daniel Mihalyieb076692014-08-22 17:33:31 +0200555 /*
556 * Forced interpreter checkers for single-step and continue support.
557 */
558
559 // Indicates whether we need to force the use of interpreter to invoke a method.
560 // This allows to single-step or continue into the called method.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700561 static bool IsForcedInterpreterNeededForCalling(Thread* thread, ArtMethod* m)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700562 REQUIRES_SHARED(Locks::mutator_lock_) {
Daniel Mihalyieb076692014-08-22 17:33:31 +0200563 if (!IsDebuggerActive()) {
564 return false;
565 }
566 return IsForcedInterpreterNeededForCallingImpl(thread, m);
567 }
568
569 // Indicates whether we need to force the use of interpreter entrypoint when calling a
570 // method through the resolution trampoline. This allows to single-step or continue into
571 // the called method.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700572 static bool IsForcedInterpreterNeededForResolution(Thread* thread, ArtMethod* m)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700573 REQUIRES_SHARED(Locks::mutator_lock_) {
Daniel Mihalyieb076692014-08-22 17:33:31 +0200574 if (!IsDebuggerActive()) {
575 return false;
576 }
577 return IsForcedInterpreterNeededForResolutionImpl(thread, m);
578 }
579
580 // Indicates whether we need to force the use of instrumentation entrypoint when calling
581 // a method through the resolution trampoline. This allows to deoptimize the stack for
582 // debugging when we returned from the called method.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700583 static bool IsForcedInstrumentationNeededForResolution(Thread* thread, ArtMethod* m)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700584 REQUIRES_SHARED(Locks::mutator_lock_) {
Daniel Mihalyieb076692014-08-22 17:33:31 +0200585 if (!IsDebuggerActive()) {
586 return false;
587 }
588 return IsForcedInstrumentationNeededForResolutionImpl(thread, m);
589 }
590
591 // Indicates whether we need to force the use of interpreter when returning from the
592 // interpreter into the runtime. This allows to deoptimize the stack and continue
593 // execution with interpreter for debugging.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700594 static bool IsForcedInterpreterNeededForUpcall(Thread* thread, ArtMethod* m)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700595 REQUIRES_SHARED(Locks::mutator_lock_) {
Mingyao Yang99170c62015-07-06 11:10:37 -0700596 if (!IsDebuggerActive() && !thread->HasDebuggerShadowFrames()) {
Daniel Mihalyieb076692014-08-22 17:33:31 +0200597 return false;
598 }
599 return IsForcedInterpreterNeededForUpcallImpl(thread, m);
600 }
601
Sebastien Hertz520633b2015-09-08 17:03:36 +0200602 // Indicates whether we need to force the use of interpreter when handling an
603 // exception. This allows to deoptimize the stack and continue execution with
604 // the interpreter.
605 // Note: the interpreter will start by handling the exception when executing
606 // the deoptimized frames.
607 static bool IsForcedInterpreterNeededForException(Thread* thread)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700608 REQUIRES_SHARED(Locks::mutator_lock_) {
Mingyao Yang99170c62015-07-06 11:10:37 -0700609 if (!IsDebuggerActive() && !thread->HasDebuggerShadowFrames()) {
Sebastien Hertz520633b2015-09-08 17:03:36 +0200610 return false;
611 }
612 return IsForcedInterpreterNeededForExceptionImpl(thread);
613 }
614
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100615 // Single-stepping.
Elliott Hughes88d63092013-01-09 09:55:54 -0800616 static JDWP::JdwpError ConfigureStep(JDWP::ObjectId thread_id, JDWP::JdwpStepSize size,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700617 JDWP::JdwpStepDepth depth)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700618 REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +0100619 static void UnconfigureStep(JDWP::ObjectId thread_id)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700620 REQUIRES(!Locks::thread_list_lock_) REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700621
Sebastien Hertzcbc50642015-06-01 17:33:12 +0200622 /*
623 * Invoke support
624 */
625
626 // Called by the JDWP thread to prepare invocation in the event thread (suspended on an event).
627 // If the information sent by the debugger is incorrect, it will send a reply with the
628 // appropriate error code. Otherwise, it will attach a DebugInvokeReq object to the event thread
629 // and resume it (and possibly other threads depending on the invoke options).
630 // Unlike other commands, the JDWP thread will not send the reply to the debugger (see
631 // JdwpState::ProcessRequest). The reply will be sent by the event thread itself after method
632 // invocation completes (see FinishInvokeMethod). This is required to allow the JDWP thread to
633 // process incoming commands from the debugger while the invocation is still in progress in the
634 // event thread, especially if it gets suspended by a debug event occurring in another thread.
635 static JDWP::JdwpError PrepareInvokeMethod(uint32_t request_id, JDWP::ObjectId thread_id,
636 JDWP::ObjectId object_id, JDWP::RefTypeId class_id,
637 JDWP::MethodId method_id, uint32_t arg_count,
638 uint64_t arg_values[], JDWP::JdwpTag* arg_types,
639 uint32_t options)
Mathieu Chartier90443472015-07-16 20:32:27 -0700640 REQUIRES(!Locks::thread_list_lock_, !Locks::thread_suspend_count_lock_)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700641 REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertzcbc50642015-06-01 17:33:12 +0200642
643 // Called by the event thread to execute a method prepared by the JDWP thread in the given
644 // DebugInvokeReq object. Once the invocation completes, the event thread attaches a reply
645 // to that DebugInvokeReq object so it can be sent to the debugger only when the event thread
646 // is ready to suspend (see FinishInvokeMethod).
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700647 static void ExecuteMethod(DebugInvokeReq* pReq);
648
Sebastien Hertzcbc50642015-06-01 17:33:12 +0200649 // Called by the event thread to send the reply of the invoke (created in ExecuteMethod)
650 // before suspending itself. This is to ensure the thread is ready to suspend before the
651 // debugger receives the reply.
652 static void FinishInvokeMethod(DebugInvokeReq* pReq);
653
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700654 /*
655 * DDM support.
656 */
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700657 static void DdmSendThreadNotification(Thread* t, uint32_t type)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700658 REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100659 static void DdmSetThreadNotification(bool enable)
Mathieu Chartier90443472015-07-16 20:32:27 -0700660 REQUIRES(!Locks::thread_list_lock_);
Alex Light8c2b9292017-11-09 13:21:01 -0800661 static bool DdmHandleChunk(
662 JNIEnv* env,
663 uint32_t type,
664 const ArrayRef<const jbyte>& data,
665 /*out*/uint32_t* out_type,
666 /*out*/std::vector<uint8_t>* out_data);
Ian Rogersc0542af2014-09-03 16:16:56 -0700667 static bool DdmHandlePacket(JDWP::Request* request, uint8_t** pReplyBuf, int* pReplyLen);
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700668 static void DdmConnected() REQUIRES_SHARED(Locks::mutator_lock_);
669 static void DdmDisconnected() REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes767a1472011-10-26 18:49:02 -0700670
Mathieu Chartiera6b1ead2015-10-06 10:32:38 -0700671 // Visit breakpoint roots, used to prevent unloading of methods with breakpoints.
Mathieu Chartierbb87e0f2015-04-03 11:21:55 -0700672 static void VisitRoots(RootVisitor* visitor)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700673 REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartier3b05e9b2014-03-25 09:29:43 -0700674
Elliott Hughes545a0642011-11-08 19:10:03 -0800675 /*
Man Cao8c2ff642015-05-27 17:25:30 -0700676 * Allocation tracking support.
Elliott Hughes545a0642011-11-08 19:10:03 -0800677 */
Mathieu Chartier90443472015-07-16 20:32:27 -0700678 static void SetAllocTrackingEnabled(bool enabled) REQUIRES(!Locks::alloc_tracker_lock_);
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100679 static jbyteArray GetRecentAllocations()
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700680 REQUIRES(!Locks::alloc_tracker_lock_) REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartier90443472015-07-16 20:32:27 -0700681 static void DumpRecentAllocations() REQUIRES(!Locks::alloc_tracker_lock_);
Elliott Hughes545a0642011-11-08 19:10:03 -0800682
Elliott Hughes767a1472011-10-26 18:49:02 -0700683 enum HpifWhen {
684 HPIF_WHEN_NEVER = 0,
685 HPIF_WHEN_NOW = 1,
686 HPIF_WHEN_NEXT_GC = 2,
687 HPIF_WHEN_EVERY_GC = 3
688 };
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700689 static int DdmHandleHpifChunk(HpifWhen when)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700690 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes767a1472011-10-26 18:49:02 -0700691
692 enum HpsgWhen {
693 HPSG_WHEN_NEVER = 0,
694 HPSG_WHEN_EVERY_GC = 1,
695 };
696 enum HpsgWhat {
697 HPSG_WHAT_MERGED_OBJECTS = 0,
698 HPSG_WHAT_DISTINCT_OBJECTS = 1,
699 };
700 static bool DdmHandleHpsgNhsgChunk(HpsgWhen when, HpsgWhat what, bool native);
701
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700702 static void DdmSendHeapInfo(HpifWhen reason)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700703 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700704 static void DdmSendHeapSegments(bool native)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700705 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes545a0642011-11-08 19:10:03 -0800706
Sebastien Hertz6995c602014-09-09 12:10:13 +0200707 static ObjectRegistry* GetObjectRegistry() {
708 return gRegistry;
709 }
710
711 static JDWP::JdwpTag TagFromObject(const ScopedObjectAccessUnchecked& soa, mirror::Object* o)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700712 REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertz6995c602014-09-09 12:10:13 +0200713
Mathieu Chartier3398c782016-09-30 10:27:43 -0700714 static JDWP::JdwpTypeTag GetTypeTag(ObjPtr<mirror::Class> klass)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700715 REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertz6995c602014-09-09 12:10:13 +0200716
Mathieu Chartierc7853442015-03-27 14:35:38 -0700717 static JDWP::FieldId ToFieldId(const ArtField* f)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700718 REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertz6995c602014-09-09 12:10:13 +0200719
Mathieu Chartiere401d142015-04-22 13:56:20 -0700720 static void SetJdwpLocation(JDWP::JdwpLocation* location, ArtMethod* m, uint32_t dex_pc)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700721 REQUIRES_SHARED(Locks::mutator_lock_)
Mathieu Chartier90443472015-07-16 20:32:27 -0700722 REQUIRES(!Locks::thread_list_lock_, !Locks::thread_suspend_count_lock_);
Sebastien Hertz6995c602014-09-09 12:10:13 +0200723
Mathieu Chartierad466ad2015-01-08 16:28:08 -0800724 static JDWP::JdwpState* GetJdwpState();
725
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700726 static uint32_t GetInstrumentationEvents() REQUIRES_SHARED(Locks::mutator_lock_) {
Sebastien Hertz9d6bf692015-04-10 12:12:33 +0200727 return instrumentation_events_;
728 }
729
Andreas Gampe04bbb5b2017-01-19 17:49:03 +0000730 static ThreadLifecycleCallback* GetThreadLifecycleCallback() {
731 return &thread_lifecycle_callback_;
732 }
Andreas Gampe0f01b582017-01-18 15:22:37 -0800733 static ClassLoadCallback* GetClassLoadCallback() {
734 return &class_load_callback_;
735 }
Andreas Gampe04bbb5b2017-01-19 17:49:03 +0000736
Elliott Hughes545a0642011-11-08 19:10:03 -0800737 private:
Sebastien Hertzcbc50642015-06-01 17:33:12 +0200738 static void ExecuteMethodWithoutPendingException(ScopedObjectAccess& soa, DebugInvokeReq* pReq)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700739 REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertzcbc50642015-06-01 17:33:12 +0200740
741 static void BuildInvokeReply(JDWP::ExpandBuf* pReply, uint32_t request_id,
742 JDWP::JdwpTag result_tag, uint64_t result_value,
743 JDWP::ObjectId exception)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700744 REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertzcbc50642015-06-01 17:33:12 +0200745
Sebastien Hertz8009f392014-09-01 17:07:11 +0200746 static JDWP::JdwpError GetLocalValue(const StackVisitor& visitor,
747 ScopedObjectAccessUnchecked& soa, int slot,
748 JDWP::JdwpTag tag, uint8_t* buf, size_t width)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700749 REQUIRES(!Locks::thread_list_lock_) REQUIRES_SHARED(Locks::mutator_lock_);
Mingyao Yang99170c62015-07-06 11:10:37 -0700750 static JDWP::JdwpError SetLocalValue(Thread* thread, StackVisitor& visitor, int slot,
751 JDWP::JdwpTag tag, uint64_t value, size_t width)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700752 REQUIRES(!Locks::thread_list_lock_) REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertz8009f392014-09-01 17:07:11 +0200753
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700754 static void DdmBroadcast(bool connect) REQUIRES_SHARED(Locks::mutator_lock_);
Andreas Gampe04bbb5b2017-01-19 17:49:03 +0000755
756 static void PostThreadStart(Thread* t)
757 REQUIRES_SHARED(Locks::mutator_lock_);
758 static void PostThreadDeath(Thread* t)
759 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700760 static void PostThreadStartOrStop(Thread*, uint32_t)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700761 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughesa2155262011-11-16 16:26:58 -0800762
Andreas Gampe0f01b582017-01-18 15:22:37 -0800763 static void PostClassPrepare(mirror::Class* c)
764 REQUIRES_SHARED(Locks::mutator_lock_);
765
Mathieu Chartiere401d142015-04-22 13:56:20 -0700766 static void PostLocationEvent(ArtMethod* method, int pcOffset,
Sebastien Hertz8379b222014-02-24 17:38:15 +0100767 mirror::Object* thisPtr, int eventFlags,
768 const JValue* return_value)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700769 REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertz8379b222014-02-24 17:38:15 +0100770
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100771 static void ProcessDeoptimizationRequest(const DeoptimizationRequest& request)
Mathieu Chartieraa516822015-10-02 15:53:37 -0700772 REQUIRES(Locks::mutator_lock_, Roles::uninterruptible_);
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100773
Sebastien Hertz7ec2f1c2014-03-27 20:06:47 +0100774 static void RequestDeoptimizationLocked(const DeoptimizationRequest& req)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700775 REQUIRES(Locks::deoptimization_lock_) REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertz7ec2f1c2014-03-27 20:06:47 +0100776
Mathieu Chartiere401d142015-04-22 13:56:20 -0700777 static bool IsForcedInterpreterNeededForCallingImpl(Thread* thread, ArtMethod* m)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700778 REQUIRES_SHARED(Locks::mutator_lock_);
Daniel Mihalyieb076692014-08-22 17:33:31 +0200779
Mathieu Chartiere401d142015-04-22 13:56:20 -0700780 static bool IsForcedInterpreterNeededForResolutionImpl(Thread* thread, ArtMethod* m)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700781 REQUIRES_SHARED(Locks::mutator_lock_);
Daniel Mihalyieb076692014-08-22 17:33:31 +0200782
Mathieu Chartiere401d142015-04-22 13:56:20 -0700783 static bool IsForcedInstrumentationNeededForResolutionImpl(Thread* thread, ArtMethod* m)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700784 REQUIRES_SHARED(Locks::mutator_lock_);
Daniel Mihalyieb076692014-08-22 17:33:31 +0200785
Mathieu Chartiere401d142015-04-22 13:56:20 -0700786 static bool IsForcedInterpreterNeededForUpcallImpl(Thread* thread, ArtMethod* m)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700787 REQUIRES_SHARED(Locks::mutator_lock_);
Daniel Mihalyieb076692014-08-22 17:33:31 +0200788
Sebastien Hertz520633b2015-09-08 17:03:36 +0200789 static bool IsForcedInterpreterNeededForExceptionImpl(Thread* thread)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700790 REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertz520633b2015-09-08 17:03:36 +0200791
Daniel Mihalyieb076692014-08-22 17:33:31 +0200792 // Indicates whether the debugger is making requests.
793 static bool gDebuggerActive;
794
Alex Light21611932017-09-26 13:07:39 -0700795 static DebuggerActiveMethodInspectionCallback gDebugActiveCallback;
Alex Light8c2b9292017-11-09 13:21:01 -0800796 static DebuggerDdmCallback gDebugDdmCallback;
Alex Light40320712017-12-14 11:52:04 -0800797 static InternalDebuggerControlCallback gDebuggerControlCallback;
Alex Light21611932017-09-26 13:07:39 -0700798
Sebastien Hertz4e5b2082015-03-24 19:03:40 +0100799 // Indicates whether we should drop the JDWP connection because the runtime stops or the
800 // debugger called VirtualMachine.Dispose.
801 static bool gDisposed;
802
Daniel Mihalyieb076692014-08-22 17:33:31 +0200803 // The registry mapping objects to JDWP ids.
Sebastien Hertz6995c602014-09-09 12:10:13 +0200804 static ObjectRegistry* gRegistry;
805
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100806 // Deoptimization requests to be processed each time the event list is updated. This is used when
807 // registering and unregistering events so we do not deoptimize while holding the event list
808 // lock.
Sebastien Hertz42cd43f2014-05-13 14:15:41 +0200809 // TODO rename to instrumentation_requests.
Brian Carlstrom306db812014-09-05 13:01:41 -0700810 static std::vector<DeoptimizationRequest> deoptimization_requests_ GUARDED_BY(Locks::deoptimization_lock_);
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100811
812 // Count the number of events requiring full deoptimization. When the counter is > 0, everything
813 // is deoptimized, otherwise everything is undeoptimized.
814 // Note: we fully deoptimize on the first event only (when the counter is set to 1). We fully
815 // undeoptimize when the last event is unregistered (when the counter is set to 0).
Brian Carlstrom306db812014-09-05 13:01:41 -0700816 static size_t full_deoptimization_event_count_ GUARDED_BY(Locks::deoptimization_lock_);
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100817
Sebastien Hertz42cd43f2014-05-13 14:15:41 +0200818 static size_t* GetReferenceCounterForEvent(uint32_t instrumentation_event);
819
820 // Instrumentation event reference counters.
821 // TODO we could use an array instead of having all these dedicated counters. Instrumentation
822 // events are bits of a mask so we could convert them to array index.
Brian Carlstrom306db812014-09-05 13:01:41 -0700823 static size_t dex_pc_change_event_ref_count_ GUARDED_BY(Locks::deoptimization_lock_);
824 static size_t method_enter_event_ref_count_ GUARDED_BY(Locks::deoptimization_lock_);
825 static size_t method_exit_event_ref_count_ GUARDED_BY(Locks::deoptimization_lock_);
826 static size_t field_read_event_ref_count_ GUARDED_BY(Locks::deoptimization_lock_);
827 static size_t field_write_event_ref_count_ GUARDED_BY(Locks::deoptimization_lock_);
828 static size_t exception_catch_event_ref_count_ GUARDED_BY(Locks::deoptimization_lock_);
Sebastien Hertz42cd43f2014-05-13 14:15:41 +0200829 static uint32_t instrumentation_events_ GUARDED_BY(Locks::mutator_lock_);
830
Andreas Gampe04bbb5b2017-01-19 17:49:03 +0000831 class DbgThreadLifecycleCallback : public ThreadLifecycleCallback {
832 public:
833 void ThreadStart(Thread* self) OVERRIDE REQUIRES_SHARED(Locks::mutator_lock_);
834 void ThreadDeath(Thread* self) OVERRIDE REQUIRES_SHARED(Locks::mutator_lock_);
835 };
836
Andreas Gampe0f01b582017-01-18 15:22:37 -0800837 class DbgClassLoadCallback : public ClassLoadCallback {
838 public:
839 void ClassLoad(Handle<mirror::Class> klass) OVERRIDE REQUIRES_SHARED(Locks::mutator_lock_);
840 void ClassPrepare(Handle<mirror::Class> temp_klass,
841 Handle<mirror::Class> klass) OVERRIDE REQUIRES_SHARED(Locks::mutator_lock_);
842 };
843
Andreas Gampe04bbb5b2017-01-19 17:49:03 +0000844 static DbgThreadLifecycleCallback thread_lifecycle_callback_;
Andreas Gampe0f01b582017-01-18 15:22:37 -0800845 static DbgClassLoadCallback class_load_callback_;
Andreas Gampe04bbb5b2017-01-19 17:49:03 +0000846
Ian Rogers719d1a32014-03-06 12:13:39 -0800847 DISALLOW_COPY_AND_ASSIGN(Dbg);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700848};
849
850#define CHUNK_TYPE(_name) \
Elliott Hughes82188472011-11-07 18:11:48 -0800851 static_cast<uint32_t>((_name)[0] << 24 | (_name)[1] << 16 | (_name)[2] << 8 | (_name)[3])
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700852
853} // namespace art
854
Brian Carlstromfc0e3212013-07-17 14:40:12 -0700855#endif // ART_RUNTIME_DEBUGGER_H_