blob: c3184e8374a6e498bfef68facdaa8187eccc5040 [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 Light8c2b9292017-11-09 13:21:01 -080056struct DebuggerDdmCallback : public DdmCallback {
57 void DdmPublishChunk(uint32_t type, const ArrayRef<const uint8_t>& data)
58 OVERRIDE REQUIRES_SHARED(Locks::mutator_lock_);
59};
60
Alex Light21611932017-09-26 13:07:39 -070061struct DebuggerActiveMethodInspectionCallback : public MethodInspectionCallback {
62 bool IsMethodBeingInspected(ArtMethod* m ATTRIBUTE_UNUSED)
63 OVERRIDE REQUIRES_SHARED(Locks::mutator_lock_);
Alex Light0fa17862017-10-24 13:43:05 -070064 bool IsMethodSafeToJit(ArtMethod* m) OVERRIDE REQUIRES_SHARED(Locks::mutator_lock_);
Alex Light21611932017-09-26 13:07:39 -070065};
66
67
Elliott Hughes872d4ec2011-10-21 17:07:15 -070068/*
69 * Invoke-during-breakpoint support.
70 */
71struct DebugInvokeReq {
Sebastien Hertzcbc50642015-06-01 17:33:12 +020072 DebugInvokeReq(uint32_t invoke_request_id, JDWP::ObjectId invoke_thread_id,
73 mirror::Object* invoke_receiver, mirror::Class* invoke_class,
Mathieu Chartiere401d142015-04-22 13:56:20 -070074 ArtMethod* invoke_method, uint32_t invoke_options,
Sebastien Hertzcbc50642015-06-01 17:33:12 +020075 uint64_t args[], uint32_t args_count)
76 : request_id(invoke_request_id), thread_id(invoke_thread_id), receiver(invoke_receiver),
77 klass(invoke_class), method(invoke_method), arg_count(args_count), arg_values(args),
78 options(invoke_options), reply(JDWP::expandBufAlloc()) {
Elliott Hughes475fc232011-10-25 15:00:35 -070079 }
80
Sebastien Hertzcbc50642015-06-01 17:33:12 +020081 ~DebugInvokeReq() {
82 JDWP::expandBufFree(reply);
83 }
84
85 // Request
86 const uint32_t request_id;
87 const JDWP::ObjectId thread_id;
88 GcRoot<mirror::Object> receiver; // not used for ClassType.InvokeMethod.
Sebastien Hertz1558b572015-02-25 15:05:59 +010089 GcRoot<mirror::Class> klass;
Sebastien Hertzcbc50642015-06-01 17:33:12 +020090 ArtMethod* const method;
Sebastien Hertz1558b572015-02-25 15:05:59 +010091 const uint32_t arg_count;
Sebastien Hertzcbc50642015-06-01 17:33:12 +020092 std::unique_ptr<uint64_t[]> arg_values; // will be null if arg_count_ == 0. We take ownership
93 // of this array so we must delete it upon destruction.
Sebastien Hertz1558b572015-02-25 15:05:59 +010094 const uint32_t options;
Elliott Hughes872d4ec2011-10-21 17:07:15 -070095
Sebastien Hertzcbc50642015-06-01 17:33:12 +020096 // Reply
97 JDWP::ExpandBuf* const reply;
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +010098
Mathieu Chartierbb87e0f2015-04-03 11:21:55 -070099 void VisitRoots(RootVisitor* visitor, const RootInfo& root_info)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700100 REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartier3b05e9b2014-03-25 09:29:43 -0700101
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +0100102 private:
103 DISALLOW_COPY_AND_ASSIGN(DebugInvokeReq);
104};
105
106// Thread local data-structure that holds fields for controlling single-stepping.
Sebastien Hertz597c4f02015-01-26 17:37:14 +0100107class SingleStepControl {
108 public:
109 SingleStepControl(JDWP::JdwpStepSize step_size, JDWP::JdwpStepDepth step_depth,
Mathieu Chartiere401d142015-04-22 13:56:20 -0700110 int stack_depth, ArtMethod* method)
Sebastien Hertz597c4f02015-01-26 17:37:14 +0100111 : step_size_(step_size), step_depth_(step_depth),
112 stack_depth_(stack_depth), method_(method) {
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +0100113 }
114
Sebastien Hertz597c4f02015-01-26 17:37:14 +0100115 JDWP::JdwpStepSize GetStepSize() const {
116 return step_size_;
117 }
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +0100118
Sebastien Hertz597c4f02015-01-26 17:37:14 +0100119 JDWP::JdwpStepDepth GetStepDepth() const {
120 return step_depth_;
121 }
122
123 int GetStackDepth() const {
124 return stack_depth_;
125 }
126
Mathieu Chartiere401d142015-04-22 13:56:20 -0700127 ArtMethod* GetMethod() const {
128 return method_;
Sebastien Hertz597c4f02015-01-26 17:37:14 +0100129 }
130
131 const std::set<uint32_t>& GetDexPcs() const {
132 return dex_pcs_;
133 }
134
Sebastien Hertz597c4f02015-01-26 17:37:14 +0100135 void AddDexPc(uint32_t dex_pc);
136
137 bool ContainsDexPc(uint32_t dex_pc) const;
138
139 private:
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +0100140 // See JdwpStepSize and JdwpStepDepth for details.
Sebastien Hertz597c4f02015-01-26 17:37:14 +0100141 const JDWP::JdwpStepSize step_size_;
142 const JDWP::JdwpStepDepth step_depth_;
143
144 // The stack depth when this single-step was initiated. This is used to support SD_OVER and SD_OUT
145 // single-step depth.
146 const int stack_depth_;
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +0100147
148 // The location this single-step was initiated from.
149 // A single-step is initiated in a suspended thread. We save here the current method and the
150 // set of DEX pcs associated to the source line number where the suspension occurred.
151 // This is used to support SD_INTO and SD_OVER single-step depths so we detect when a single-step
152 // causes the execution of an instruction in a different method or at a different line number.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700153 ArtMethod* method_;
154
Sebastien Hertz597c4f02015-01-26 17:37:14 +0100155 std::set<uint32_t> dex_pcs_;
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +0100156
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +0100157 DISALLOW_COPY_AND_ASSIGN(SingleStepControl);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700158};
159
Sebastien Hertz42cd43f2014-05-13 14:15:41 +0200160// TODO rename to InstrumentationRequest.
Hiroshi Yamauchi0ec17d22014-07-07 13:07:08 -0700161class DeoptimizationRequest {
162 public:
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100163 enum Kind {
164 kNothing, // no action.
Sebastien Hertz42cd43f2014-05-13 14:15:41 +0200165 kRegisterForEvent, // start listening for instrumentation event.
166 kUnregisterForEvent, // stop listening for instrumentation event.
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100167 kFullDeoptimization, // deoptimize everything.
168 kFullUndeoptimization, // undeoptimize everything.
169 kSelectiveDeoptimization, // deoptimize one method.
170 kSelectiveUndeoptimization // undeoptimize one method.
171 };
172
Hiroshi Yamauchi0ec17d22014-07-07 13:07:08 -0700173 DeoptimizationRequest() : kind_(kNothing), instrumentation_event_(0), method_(nullptr) {}
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100174
Hiroshi Yamauchi0ec17d22014-07-07 13:07:08 -0700175 DeoptimizationRequest(const DeoptimizationRequest& other)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700176 REQUIRES_SHARED(Locks::mutator_lock_)
Hiroshi Yamauchi0ec17d22014-07-07 13:07:08 -0700177 : kind_(other.kind_), instrumentation_event_(other.instrumentation_event_) {
178 // Create a new JNI global reference for the method.
179 SetMethod(other.Method());
180 }
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100181
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700182 ArtMethod* Method() const REQUIRES_SHARED(Locks::mutator_lock_);
Hiroshi Yamauchi0ec17d22014-07-07 13:07:08 -0700183
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700184 void SetMethod(ArtMethod* m) REQUIRES_SHARED(Locks::mutator_lock_);
Hiroshi Yamauchi0ec17d22014-07-07 13:07:08 -0700185
186 // Name 'Kind()' would collide with the above enum name.
187 Kind GetKind() const {
188 return kind_;
189 }
190
191 void SetKind(Kind kind) {
192 kind_ = kind;
193 }
194
195 uint32_t InstrumentationEvent() const {
196 return instrumentation_event_;
197 }
198
199 void SetInstrumentationEvent(uint32_t instrumentation_event) {
200 instrumentation_event_ = instrumentation_event;
201 }
202
203 private:
204 Kind kind_;
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100205
Sebastien Hertz42cd43f2014-05-13 14:15:41 +0200206 // TODO we could use a union to hold the instrumentation_event and the method since they
207 // respectively have sense only for kRegisterForEvent/kUnregisterForEvent and
208 // kSelectiveDeoptimization/kSelectiveUndeoptimization.
209
210 // Event to start or stop listening to. Only for kRegisterForEvent and kUnregisterForEvent.
Hiroshi Yamauchi0ec17d22014-07-07 13:07:08 -0700211 uint32_t instrumentation_event_;
Sebastien Hertz42cd43f2014-05-13 14:15:41 +0200212
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100213 // Method for selective deoptimization.
Hiroshi Yamauchi0ec17d22014-07-07 13:07:08 -0700214 jmethodID method_;
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100215};
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700216std::ostream& operator<<(std::ostream& os, const DeoptimizationRequest::Kind& rhs);
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100217
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700218class Dbg {
Elliott Hughesff17f1f2012-01-24 18:12:29 -0800219 public:
Elliott Hughes4ffd3132011-10-24 12:06:42 -0700220 static void SetJdwpAllowed(bool allowed);
Leonard Mosescueb842212016-10-06 17:26:36 -0700221 static bool IsJdwpAllowed();
Elliott Hughes4ffd3132011-10-24 12:06:42 -0700222
Sebastien Hertzb3b173b2015-02-06 09:16:32 +0100223 static void StartJdwp();
Elliott Hughesd1cc8362011-10-24 16:58:50 -0700224 static void StopJdwp();
225
Elliott Hughes767a1472011-10-26 18:49:02 -0700226 // Invoked by the GC in case we need to keep DDMS informed.
Mathieu Chartier90443472015-07-16 20:32:27 -0700227 static void GcDidFinish() REQUIRES(!Locks::mutator_lock_);
Elliott Hughes767a1472011-10-26 18:49:02 -0700228
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700229 // Return the DebugInvokeReq for the current thread.
230 static DebugInvokeReq* GetInvokeReq();
231
Elliott Hughes475fc232011-10-25 15:00:35 -0700232 static Thread* GetDebugThread();
233 static void ClearWaitForEventThread();
234
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700235 /*
236 * Enable/disable breakpoints and step modes. Used to provide a heads-up
237 * when the debugger attaches.
238 */
239 static void Connected();
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100240 static void GoActive()
Mathieu Chartier90443472015-07-16 20:32:27 -0700241 REQUIRES(!Locks::breakpoint_lock_, !Locks::deoptimization_lock_, !Locks::mutator_lock_);
242 static void Disconnected() REQUIRES(!Locks::deoptimization_lock_, !Locks::mutator_lock_);
Sebastien Hertz4e5b2082015-03-24 19:03:40 +0100243 static void Dispose() {
244 gDisposed = true;
245 }
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700246
Elliott Hughesc0f09332012-03-26 13:27:06 -0700247 // Returns true if we're actually debugging with a real debugger, false if it's
248 // just DDMS (or nothing at all).
Daniel Mihalyieb076692014-08-22 17:33:31 +0200249 static bool IsDebuggerActive() {
250 return gDebuggerActive;
251 }
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700252
Sebastien Hertzb3b173b2015-02-06 09:16:32 +0100253 // Configures JDWP with parsed command-line options.
254 static void ConfigureJdwp(const JDWP::JdwpOptions& jdwp_options);
255
Elliott Hughesc0f09332012-03-26 13:27:06 -0700256 // Returns true if we had -Xrunjdwp or -agentlib:jdwp= on the command line.
257 static bool IsJdwpConfigured();
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700258
Mathieu Chartierd8565452015-03-26 09:41:50 -0700259 // Returns true if a method has any breakpoints.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700260 static bool MethodHasAnyBreakpoints(ArtMethod* method)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700261 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!Locks::breakpoint_lock_);
Mathieu Chartierd8565452015-03-26 09:41:50 -0700262
Sebastien Hertz4e5b2082015-03-24 19:03:40 +0100263 static bool IsDisposed() {
264 return gDisposed;
265 }
Elliott Hughes86964332012-02-15 19:37:42 -0800266
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700267 /*
268 * Time, in milliseconds, since the last debugger activity. Does not
269 * include DDMS activity. Returns -1 if there has been no activity.
270 * Returns 0 if we're in the middle of handling a debugger request.
271 */
272 static int64_t LastDebuggerActivity();
273
Sebastien Hertz253fa552014-10-14 17:27:15 +0200274 static void UndoDebuggerSuspensions()
Mathieu Chartier90443472015-07-16 20:32:27 -0700275 REQUIRES(!Locks::thread_list_lock_, !Locks::thread_suspend_count_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700276
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700277 /*
278 * Class, Object, Array
279 */
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700280 static std::string GetClassName(JDWP::RefTypeId id)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700281 REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertz6995c602014-09-09 12:10:13 +0200282 static std::string GetClassName(mirror::Class* klass)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700283 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogersc0542af2014-09-03 16:16:56 -0700284 static JDWP::JdwpError GetClassObject(JDWP::RefTypeId id, JDWP::ObjectId* class_object_id)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700285 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogersc0542af2014-09-03 16:16:56 -0700286 static JDWP::JdwpError GetSuperclass(JDWP::RefTypeId id, JDWP::RefTypeId* superclass_id)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700287 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700288 static JDWP::JdwpError GetClassLoader(JDWP::RefTypeId id, JDWP::ExpandBuf* pReply)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700289 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700290 static JDWP::JdwpError GetModifiers(JDWP::RefTypeId id, JDWP::ExpandBuf* pReply)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700291 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800292 static JDWP::JdwpError GetReflectedType(JDWP::RefTypeId class_id, JDWP::ExpandBuf* pReply)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700293 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogersc0542af2014-09-03 16:16:56 -0700294 static void GetClassList(std::vector<JDWP::RefTypeId>* classes)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700295 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800296 static JDWP::JdwpError GetClassInfo(JDWP::RefTypeId class_id, JDWP::JdwpTypeTag* pTypeTag,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700297 uint32_t* pStatus, std::string* pDescriptor)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700298 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogersc0542af2014-09-03 16:16:56 -0700299 static void FindLoadedClassBySignature(const char* descriptor, std::vector<JDWP::RefTypeId>* ids)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700300 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes64f574f2013-02-20 14:57:12 -0800301 static JDWP::JdwpError GetReferenceType(JDWP::ObjectId object_id, JDWP::ExpandBuf* pReply)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700302 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogersfc0e94b2013-09-23 23:51:32 -0700303 static JDWP::JdwpError GetSignature(JDWP::RefTypeId ref_type_id, std::string* signature)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700304 REQUIRES_SHARED(Locks::mutator_lock_);
Orion Hodson77d8a1c2017-04-24 14:53:19 +0100305 static JDWP::JdwpError GetSourceDebugExtension(JDWP::RefTypeId ref_type_id,
306 std::string* extension_data)
307 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogersc0542af2014-09-03 16:16:56 -0700308 static JDWP::JdwpError GetSourceFile(JDWP::RefTypeId ref_type_id, std::string* source_file)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700309 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogersc0542af2014-09-03 16:16:56 -0700310 static JDWP::JdwpError GetObjectTag(JDWP::ObjectId object_id, uint8_t* tag)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700311 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughesaed4be92011-12-02 16:16:23 -0800312 static size_t GetTagWidth(JDWP::JdwpTag tag);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700313
Ian Rogersc0542af2014-09-03 16:16:56 -0700314 static JDWP::JdwpError GetArrayLength(JDWP::ObjectId array_id, int32_t* length)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700315 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800316 static JDWP::JdwpError OutputArray(JDWP::ObjectId array_id, int offset, int count,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700317 JDWP::ExpandBuf* pReply)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700318 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800319 static JDWP::JdwpError SetArrayElements(JDWP::ObjectId array_id, int offset, int count,
Ian Rogersc0542af2014-09-03 16:16:56 -0700320 JDWP::Request* request)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700321 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700322
Sebastien Hertz2c3e77a2015-04-02 16:26:48 +0200323 static JDWP::JdwpError CreateString(const std::string& str, JDWP::ObjectId* new_string_id)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700324 REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertz2c3e77a2015-04-02 16:26:48 +0200325 static JDWP::JdwpError CreateObject(JDWP::RefTypeId class_id, JDWP::ObjectId* new_object_id)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700326 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800327 static JDWP::JdwpError CreateArrayObject(JDWP::RefTypeId array_class_id, uint32_t length,
Sebastien Hertz2c3e77a2015-04-02 16:26:48 +0200328 JDWP::ObjectId* new_array_id)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700329 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700330
Sebastien Hertz6995c602014-09-09 12:10:13 +0200331 //
332 // Event filtering.
333 //
334 static bool MatchThread(JDWP::ObjectId expected_thread_id, Thread* event_thread)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700335 REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertz6995c602014-09-09 12:10:13 +0200336
337 static bool MatchLocation(const JDWP::JdwpLocation& expected_location,
338 const JDWP::EventLocation& event_location)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700339 REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertz6995c602014-09-09 12:10:13 +0200340
Mathieu Chartier3398c782016-09-30 10:27:43 -0700341 static bool MatchType(ObjPtr<mirror::Class> event_class, JDWP::RefTypeId class_id)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700342 REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertz6995c602014-09-09 12:10:13 +0200343
344 static bool MatchField(JDWP::RefTypeId expected_type_id, JDWP::FieldId expected_field_id,
Mathieu Chartierc7853442015-03-27 14:35:38 -0700345 ArtField* event_field)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700346 REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertz6995c602014-09-09 12:10:13 +0200347
348 static bool MatchInstance(JDWP::ObjectId expected_instance_id, mirror::Object* event_instance)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700349 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700350
Elliott Hughesec0f83d2013-01-15 16:54:08 -0800351 //
352 // Monitors.
353 //
354 static JDWP::JdwpError GetMonitorInfo(JDWP::ObjectId object_id, JDWP::ExpandBuf* reply)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700355 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughesec0f83d2013-01-15 16:54:08 -0800356 static JDWP::JdwpError GetOwnedMonitors(JDWP::ObjectId thread_id,
Ian Rogersc0542af2014-09-03 16:16:56 -0700357 std::vector<JDWP::ObjectId>* monitors,
358 std::vector<uint32_t>* stack_depths)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700359 REQUIRES(!Locks::thread_list_lock_) REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100360 static JDWP::JdwpError GetContendedMonitor(JDWP::ObjectId thread_id,
Ian Rogersc0542af2014-09-03 16:16:56 -0700361 JDWP::ObjectId* contended_monitor)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700362 REQUIRES(!Locks::thread_list_lock_) REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughesec0f83d2013-01-15 16:54:08 -0800363
364 //
365 // Heap.
366 //
367 static JDWP::JdwpError GetInstanceCounts(const std::vector<JDWP::RefTypeId>& class_ids,
Ian Rogersc0542af2014-09-03 16:16:56 -0700368 std::vector<uint64_t>* counts)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700369 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes3b78c942013-01-15 17:35:41 -0800370 static JDWP::JdwpError GetInstances(JDWP::RefTypeId class_id, int32_t max_count,
Ian Rogersc0542af2014-09-03 16:16:56 -0700371 std::vector<JDWP::ObjectId>* instances)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700372 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes0cbaff52013-01-16 15:28:01 -0800373 static JDWP::JdwpError GetReferringObjects(JDWP::ObjectId object_id, int32_t max_count,
Ian Rogersc0542af2014-09-03 16:16:56 -0700374 std::vector<JDWP::ObjectId>* referring_objects)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700375 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes64f574f2013-02-20 14:57:12 -0800376 static JDWP::JdwpError DisableCollection(JDWP::ObjectId object_id)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700377 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes64f574f2013-02-20 14:57:12 -0800378 static JDWP::JdwpError EnableCollection(JDWP::ObjectId object_id)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700379 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogersc0542af2014-09-03 16:16:56 -0700380 static JDWP::JdwpError IsCollected(JDWP::ObjectId object_id, bool* is_collected)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700381 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes64f574f2013-02-20 14:57:12 -0800382 static void DisposeObject(JDWP::ObjectId object_id, uint32_t reference_count)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700383 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughesec0f83d2013-01-15 16:54:08 -0800384
Elliott Hughes9777ba22013-01-17 09:04:19 -0800385 //
386 // Methods and fields.
387 //
Elliott Hughesa96836a2013-01-17 12:27:49 -0800388 static std::string GetMethodName(JDWP::MethodId method_id)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700389 REQUIRES_SHARED(Locks::mutator_lock_);
Alex Light73376312017-04-06 10:10:51 -0700390 static bool IsMethodObsolete(JDWP::MethodId method_id)
391 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800392 static JDWP::JdwpError OutputDeclaredFields(JDWP::RefTypeId ref_type_id, bool with_generic,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700393 JDWP::ExpandBuf* pReply)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700394 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800395 static JDWP::JdwpError OutputDeclaredMethods(JDWP::RefTypeId ref_type_id, bool with_generic,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700396 JDWP::ExpandBuf* pReply)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700397 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800398 static JDWP::JdwpError OutputDeclaredInterfaces(JDWP::RefTypeId ref_type_id,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700399 JDWP::ExpandBuf* pReply)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700400 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800401 static void OutputLineTable(JDWP::RefTypeId ref_type_id, JDWP::MethodId method_id,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700402 JDWP::ExpandBuf* pReply)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700403 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800404 static void OutputVariableTable(JDWP::RefTypeId ref_type_id, JDWP::MethodId id, bool with_generic,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700405 JDWP::ExpandBuf* pReply)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700406 REQUIRES_SHARED(Locks::mutator_lock_);
Jeff Hao579b0242013-11-18 13:16:49 -0800407 static void OutputMethodReturnValue(JDWP::MethodId method_id, const JValue* return_value,
408 JDWP::ExpandBuf* pReply)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700409 REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertz3f52eaf2014-04-04 17:50:18 +0200410 static void OutputFieldValue(JDWP::FieldId field_id, const JValue* field_value,
411 JDWP::ExpandBuf* pReply)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700412 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes9777ba22013-01-17 09:04:19 -0800413 static JDWP::JdwpError GetBytecodes(JDWP::RefTypeId class_id, JDWP::MethodId method_id,
Ian Rogersc0542af2014-09-03 16:16:56 -0700414 std::vector<uint8_t>* bytecodes)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700415 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700416
Elliott Hughesa96836a2013-01-17 12:27:49 -0800417 static std::string GetFieldName(JDWP::FieldId field_id)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700418 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800419 static JDWP::JdwpTag GetFieldBasicTag(JDWP::FieldId field_id)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700420 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800421 static JDWP::JdwpTag GetStaticFieldBasicTag(JDWP::FieldId field_id)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700422 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800423 static JDWP::JdwpError GetFieldValue(JDWP::ObjectId object_id, JDWP::FieldId field_id,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700424 JDWP::ExpandBuf* pReply)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700425 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800426 static JDWP::JdwpError SetFieldValue(JDWP::ObjectId object_id, JDWP::FieldId field_id,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700427 uint64_t value, int width)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700428 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800429 static JDWP::JdwpError GetStaticFieldValue(JDWP::RefTypeId ref_type_id, JDWP::FieldId field_id,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700430 JDWP::ExpandBuf* pReply)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700431 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800432 static JDWP::JdwpError SetStaticFieldValue(JDWP::FieldId field_id, uint64_t value, int width)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700433 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700434
Sebastien Hertzb0b0b492014-09-15 11:27:27 +0200435 static JDWP::JdwpError StringToUtf8(JDWP::ObjectId string_id, std::string* str)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700436 REQUIRES_SHARED(Locks::mutator_lock_);
Jeff Hao579b0242013-11-18 13:16:49 -0800437 static void OutputJValue(JDWP::JdwpTag tag, const JValue* return_value, JDWP::ExpandBuf* pReply)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700438 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700439
440 /*
441 * Thread, ThreadGroup, Frame
442 */
Ian Rogersc0542af2014-09-03 16:16:56 -0700443 static JDWP::JdwpError GetThreadName(JDWP::ObjectId thread_id, std::string* name)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700444 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!Locks::thread_list_lock_);
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100445 static JDWP::JdwpError GetThreadGroup(JDWP::ObjectId thread_id, JDWP::ExpandBuf* pReply)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700446 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!Locks::thread_list_lock_);
Sebastien Hertza06430c2014-09-15 19:21:30 +0200447 static JDWP::JdwpError GetThreadGroupName(JDWP::ObjectId thread_group_id,
448 JDWP::ExpandBuf* pReply)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700449 REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertza06430c2014-09-15 19:21:30 +0200450 static JDWP::JdwpError GetThreadGroupParent(JDWP::ObjectId thread_group_id,
451 JDWP::ExpandBuf* pReply)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700452 REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertza06430c2014-09-15 19:21:30 +0200453 static JDWP::JdwpError GetThreadGroupChildren(JDWP::ObjectId thread_group_id,
454 JDWP::ExpandBuf* pReply)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700455 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700456 static JDWP::ObjectId GetSystemThreadGroupId()
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700457 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700458
Jeff Hao920af3e2013-08-28 15:46:38 -0700459 static JDWP::JdwpThreadStatus ToJdwpThreadStatus(ThreadState state);
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100460 static JDWP::JdwpError GetThreadStatus(JDWP::ObjectId thread_id,
461 JDWP::JdwpThreadStatus* pThreadStatus,
462 JDWP::JdwpSuspendStatus* pSuspendStatus)
Mathieu Chartier90443472015-07-16 20:32:27 -0700463 REQUIRES(!Locks::thread_list_lock_);
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100464 static JDWP::JdwpError GetThreadDebugSuspendCount(JDWP::ObjectId thread_id,
465 JDWP::ExpandBuf* pReply)
Mathieu Chartier90443472015-07-16 20:32:27 -0700466 REQUIRES(!Locks::thread_list_lock_, !Locks::thread_suspend_count_lock_);
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700467 // static void WaitForSuspend(JDWP::ObjectId thread_id);
Elliott Hughescaf76542012-06-28 16:08:22 -0700468
Elliott Hughes026b1462012-06-28 20:43:49 -0700469 // Fills 'thread_ids' with the threads in the given thread group. If thread_group_id == 0,
Elliott Hughescaf76542012-06-28 16:08:22 -0700470 // returns all threads.
Sebastien Hertza06430c2014-09-15 19:21:30 +0200471 static void GetThreads(mirror::Object* thread_group, std::vector<JDWP::ObjectId>* thread_ids)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700472 REQUIRES(!Locks::thread_list_lock_) REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughescaf76542012-06-28 16:08:22 -0700473
Ian Rogersc0542af2014-09-03 16:16:56 -0700474 static JDWP::JdwpError GetThreadFrameCount(JDWP::ObjectId thread_id, size_t* result)
Mathieu Chartier90443472015-07-16 20:32:27 -0700475 REQUIRES(!Locks::thread_list_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700476 static JDWP::JdwpError GetThreadFrames(JDWP::ObjectId thread_id, size_t start_frame,
477 size_t frame_count, JDWP::ExpandBuf* buf)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700478 REQUIRES(!Locks::thread_list_lock_) REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700479
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700480 static JDWP::ObjectId GetThreadSelfId() REQUIRES_SHARED(Locks::mutator_lock_);
481 static JDWP::ObjectId GetThreadId(Thread* thread) REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertz6995c602014-09-09 12:10:13 +0200482
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700483 static void SuspendVM()
Mathieu Chartier90443472015-07-16 20:32:27 -0700484 REQUIRES(!Locks::thread_list_lock_, !Locks::thread_suspend_count_lock_);
Sebastien Hertz253fa552014-10-14 17:27:15 +0200485 static void ResumeVM()
Mathieu Chartier90443472015-07-16 20:32:27 -0700486 REQUIRES(!Locks::thread_list_lock_, !Locks::thread_suspend_count_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800487 static JDWP::JdwpError SuspendThread(JDWP::ObjectId thread_id, bool request_suspension = true)
Mathieu Chartier90443472015-07-16 20:32:27 -0700488 REQUIRES(!Locks::mutator_lock_, !Locks::thread_list_lock_,
489 !Locks::thread_suspend_count_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700490
Elliott Hughes88d63092013-01-09 09:55:54 -0800491 static void ResumeThread(JDWP::ObjectId thread_id)
Mathieu Chartier90443472015-07-16 20:32:27 -0700492 REQUIRES(!Locks::thread_list_lock_, !Locks::thread_suspend_count_lock_)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700493 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700494 static void SuspendSelf();
495
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700496 static JDWP::JdwpError GetThisObject(JDWP::ObjectId thread_id, JDWP::FrameId frame_id,
497 JDWP::ObjectId* result)
Mathieu Chartier90443472015-07-16 20:32:27 -0700498 REQUIRES(!Locks::thread_list_lock_, !Locks::thread_suspend_count_lock_)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700499 REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertz8009f392014-09-01 17:07:11 +0200500 static JDWP::JdwpError GetLocalValues(JDWP::Request* request, JDWP::ExpandBuf* pReply)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700501 REQUIRES(!Locks::thread_list_lock_) REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertz8009f392014-09-01 17:07:11 +0200502 static JDWP::JdwpError SetLocalValues(JDWP::Request* request)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700503 REQUIRES(!Locks::thread_list_lock_) REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700504
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100505 static JDWP::JdwpError Interrupt(JDWP::ObjectId thread_id)
Mathieu Chartier90443472015-07-16 20:32:27 -0700506 REQUIRES(!Locks::thread_list_lock_);
Elliott Hughesf9501702013-01-11 11:22:27 -0800507
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700508 /*
509 * Debugger notification
510 */
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700511 enum EventFlag {
Elliott Hughes86964332012-02-15 19:37:42 -0800512 kBreakpoint = 0x01,
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700513 kSingleStep = 0x02,
514 kMethodEntry = 0x04,
515 kMethodExit = 0x08,
516 };
Mathieu Chartiere401d142015-04-22 13:56:20 -0700517 static void PostFieldAccessEvent(ArtMethod* m, int dex_pc, mirror::Object* this_object,
Mathieu Chartierc7853442015-03-27 14:35:38 -0700518 ArtField* f)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700519 REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700520 static void PostFieldModificationEvent(ArtMethod* m, int dex_pc,
Mathieu Chartierc7853442015-03-27 14:35:38 -0700521 mirror::Object* this_object, ArtField* f,
Sebastien Hertz3f52eaf2014-04-04 17:50:18 +0200522 const JValue* field_value)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700523 REQUIRES_SHARED(Locks::mutator_lock_);
Nicolas Geoffray14691c52015-03-05 10:40:17 +0000524 static void PostException(mirror::Throwable* exception)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700525 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700526
Ian Rogers62d6c772013-02-27 08:32:07 -0800527 static void UpdateDebugger(Thread* thread, mirror::Object* this_object,
Mathieu Chartiere401d142015-04-22 13:56:20 -0700528 ArtMethod* method, uint32_t new_dex_pc,
Sebastien Hertz8379b222014-02-24 17:38:15 +0100529 int event_flags, const JValue* return_value)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700530 REQUIRES(!Locks::breakpoint_lock_) REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes91bf6cd2012-02-14 17:27:48 -0800531
Sebastien Hertzf3928792014-11-17 19:00:37 +0100532 // Indicates whether we need deoptimization for debugging.
533 static bool RequiresDeoptimization();
534
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100535 // Records deoptimization request in the queue.
536 static void RequestDeoptimization(const DeoptimizationRequest& req)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700537 REQUIRES(!Locks::deoptimization_lock_) REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100538
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100539 // Manage deoptimization after updating JDWP events list. Suspends all threads, processes each
540 // request and finally resumes all threads.
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100541 static void ManageDeoptimization()
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
544 // Breakpoints.
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100545 static void WatchLocation(const JDWP::JdwpLocation* pLoc, DeoptimizationRequest* req)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700546 REQUIRES(!Locks::breakpoint_lock_) REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100547 static void UnwatchLocation(const JDWP::JdwpLocation* pLoc, DeoptimizationRequest* req)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700548 REQUIRES(!Locks::breakpoint_lock_) REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100549
Daniel Mihalyieb076692014-08-22 17:33:31 +0200550 /*
551 * Forced interpreter checkers for single-step and continue support.
552 */
553
554 // Indicates whether we need to force the use of interpreter to invoke a method.
555 // This allows to single-step or continue into the called method.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700556 static bool IsForcedInterpreterNeededForCalling(Thread* thread, ArtMethod* m)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700557 REQUIRES_SHARED(Locks::mutator_lock_) {
Daniel Mihalyieb076692014-08-22 17:33:31 +0200558 if (!IsDebuggerActive()) {
559 return false;
560 }
561 return IsForcedInterpreterNeededForCallingImpl(thread, m);
562 }
563
564 // Indicates whether we need to force the use of interpreter entrypoint when calling a
565 // method through the resolution trampoline. This allows to single-step or continue into
566 // the called method.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700567 static bool IsForcedInterpreterNeededForResolution(Thread* thread, ArtMethod* m)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700568 REQUIRES_SHARED(Locks::mutator_lock_) {
Daniel Mihalyieb076692014-08-22 17:33:31 +0200569 if (!IsDebuggerActive()) {
570 return false;
571 }
572 return IsForcedInterpreterNeededForResolutionImpl(thread, m);
573 }
574
575 // Indicates whether we need to force the use of instrumentation entrypoint when calling
576 // a method through the resolution trampoline. This allows to deoptimize the stack for
577 // debugging when we returned from the called method.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700578 static bool IsForcedInstrumentationNeededForResolution(Thread* thread, ArtMethod* m)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700579 REQUIRES_SHARED(Locks::mutator_lock_) {
Daniel Mihalyieb076692014-08-22 17:33:31 +0200580 if (!IsDebuggerActive()) {
581 return false;
582 }
583 return IsForcedInstrumentationNeededForResolutionImpl(thread, m);
584 }
585
586 // Indicates whether we need to force the use of interpreter when returning from the
587 // interpreter into the runtime. This allows to deoptimize the stack and continue
588 // execution with interpreter for debugging.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700589 static bool IsForcedInterpreterNeededForUpcall(Thread* thread, ArtMethod* m)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700590 REQUIRES_SHARED(Locks::mutator_lock_) {
Mingyao Yang99170c62015-07-06 11:10:37 -0700591 if (!IsDebuggerActive() && !thread->HasDebuggerShadowFrames()) {
Daniel Mihalyieb076692014-08-22 17:33:31 +0200592 return false;
593 }
594 return IsForcedInterpreterNeededForUpcallImpl(thread, m);
595 }
596
Sebastien Hertz520633b2015-09-08 17:03:36 +0200597 // Indicates whether we need to force the use of interpreter when handling an
598 // exception. This allows to deoptimize the stack and continue execution with
599 // the interpreter.
600 // Note: the interpreter will start by handling the exception when executing
601 // the deoptimized frames.
602 static bool IsForcedInterpreterNeededForException(Thread* thread)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700603 REQUIRES_SHARED(Locks::mutator_lock_) {
Mingyao Yang99170c62015-07-06 11:10:37 -0700604 if (!IsDebuggerActive() && !thread->HasDebuggerShadowFrames()) {
Sebastien Hertz520633b2015-09-08 17:03:36 +0200605 return false;
606 }
607 return IsForcedInterpreterNeededForExceptionImpl(thread);
608 }
609
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100610 // Single-stepping.
Elliott Hughes88d63092013-01-09 09:55:54 -0800611 static JDWP::JdwpError ConfigureStep(JDWP::ObjectId thread_id, JDWP::JdwpStepSize size,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700612 JDWP::JdwpStepDepth depth)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700613 REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +0100614 static void UnconfigureStep(JDWP::ObjectId thread_id)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700615 REQUIRES(!Locks::thread_list_lock_) REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700616
Sebastien Hertzcbc50642015-06-01 17:33:12 +0200617 /*
618 * Invoke support
619 */
620
621 // Called by the JDWP thread to prepare invocation in the event thread (suspended on an event).
622 // If the information sent by the debugger is incorrect, it will send a reply with the
623 // appropriate error code. Otherwise, it will attach a DebugInvokeReq object to the event thread
624 // and resume it (and possibly other threads depending on the invoke options).
625 // Unlike other commands, the JDWP thread will not send the reply to the debugger (see
626 // JdwpState::ProcessRequest). The reply will be sent by the event thread itself after method
627 // invocation completes (see FinishInvokeMethod). This is required to allow the JDWP thread to
628 // process incoming commands from the debugger while the invocation is still in progress in the
629 // event thread, especially if it gets suspended by a debug event occurring in another thread.
630 static JDWP::JdwpError PrepareInvokeMethod(uint32_t request_id, JDWP::ObjectId thread_id,
631 JDWP::ObjectId object_id, JDWP::RefTypeId class_id,
632 JDWP::MethodId method_id, uint32_t arg_count,
633 uint64_t arg_values[], JDWP::JdwpTag* arg_types,
634 uint32_t options)
Mathieu Chartier90443472015-07-16 20:32:27 -0700635 REQUIRES(!Locks::thread_list_lock_, !Locks::thread_suspend_count_lock_)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700636 REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertzcbc50642015-06-01 17:33:12 +0200637
638 // Called by the event thread to execute a method prepared by the JDWP thread in the given
639 // DebugInvokeReq object. Once the invocation completes, the event thread attaches a reply
640 // to that DebugInvokeReq object so it can be sent to the debugger only when the event thread
641 // is ready to suspend (see FinishInvokeMethod).
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700642 static void ExecuteMethod(DebugInvokeReq* pReq);
643
Sebastien Hertzcbc50642015-06-01 17:33:12 +0200644 // Called by the event thread to send the reply of the invoke (created in ExecuteMethod)
645 // before suspending itself. This is to ensure the thread is ready to suspend before the
646 // debugger receives the reply.
647 static void FinishInvokeMethod(DebugInvokeReq* pReq);
648
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700649 /*
650 * DDM support.
651 */
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700652 static void DdmSendThreadNotification(Thread* t, uint32_t type)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700653 REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100654 static void DdmSetThreadNotification(bool enable)
Mathieu Chartier90443472015-07-16 20:32:27 -0700655 REQUIRES(!Locks::thread_list_lock_);
Alex Light8c2b9292017-11-09 13:21:01 -0800656 static bool DdmHandleChunk(
657 JNIEnv* env,
658 uint32_t type,
659 const ArrayRef<const jbyte>& data,
660 /*out*/uint32_t* out_type,
661 /*out*/std::vector<uint8_t>* out_data);
Ian Rogersc0542af2014-09-03 16:16:56 -0700662 static bool DdmHandlePacket(JDWP::Request* request, uint8_t** pReplyBuf, int* pReplyLen);
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700663 static void DdmConnected() REQUIRES_SHARED(Locks::mutator_lock_);
664 static void DdmDisconnected() REQUIRES_SHARED(Locks::mutator_lock_);
Alex Light8c2b9292017-11-09 13:21:01 -0800665 static void DdmSendChunk(uint32_t type, const ArrayRef<const uint8_t>& bytes)
666 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700667 static void DdmSendChunk(uint32_t type, const std::vector<uint8_t>& bytes)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700668 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700669 static void DdmSendChunk(uint32_t type, size_t len, const uint8_t* buf)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700670 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700671 static void DdmSendChunkV(uint32_t type, const iovec* iov, int iov_count)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700672 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes767a1472011-10-26 18:49:02 -0700673
Mathieu Chartiera6b1ead2015-10-06 10:32:38 -0700674 // Visit breakpoint roots, used to prevent unloading of methods with breakpoints.
Mathieu Chartierbb87e0f2015-04-03 11:21:55 -0700675 static void VisitRoots(RootVisitor* visitor)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700676 REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartier3b05e9b2014-03-25 09:29:43 -0700677
Elliott Hughes545a0642011-11-08 19:10:03 -0800678 /*
Man Cao8c2ff642015-05-27 17:25:30 -0700679 * Allocation tracking support.
Elliott Hughes545a0642011-11-08 19:10:03 -0800680 */
Mathieu Chartier90443472015-07-16 20:32:27 -0700681 static void SetAllocTrackingEnabled(bool enabled) REQUIRES(!Locks::alloc_tracker_lock_);
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100682 static jbyteArray GetRecentAllocations()
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700683 REQUIRES(!Locks::alloc_tracker_lock_) REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartier90443472015-07-16 20:32:27 -0700684 static void DumpRecentAllocations() REQUIRES(!Locks::alloc_tracker_lock_);
Elliott Hughes545a0642011-11-08 19:10:03 -0800685
Elliott Hughes767a1472011-10-26 18:49:02 -0700686 enum HpifWhen {
687 HPIF_WHEN_NEVER = 0,
688 HPIF_WHEN_NOW = 1,
689 HPIF_WHEN_NEXT_GC = 2,
690 HPIF_WHEN_EVERY_GC = 3
691 };
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700692 static int DdmHandleHpifChunk(HpifWhen when)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700693 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes767a1472011-10-26 18:49:02 -0700694
695 enum HpsgWhen {
696 HPSG_WHEN_NEVER = 0,
697 HPSG_WHEN_EVERY_GC = 1,
698 };
699 enum HpsgWhat {
700 HPSG_WHAT_MERGED_OBJECTS = 0,
701 HPSG_WHAT_DISTINCT_OBJECTS = 1,
702 };
703 static bool DdmHandleHpsgNhsgChunk(HpsgWhen when, HpsgWhat what, bool native);
704
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700705 static void DdmSendHeapInfo(HpifWhen reason)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700706 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700707 static void DdmSendHeapSegments(bool native)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700708 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes545a0642011-11-08 19:10:03 -0800709
Sebastien Hertz6995c602014-09-09 12:10:13 +0200710 static ObjectRegistry* GetObjectRegistry() {
711 return gRegistry;
712 }
713
714 static JDWP::JdwpTag TagFromObject(const ScopedObjectAccessUnchecked& soa, mirror::Object* o)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700715 REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertz6995c602014-09-09 12:10:13 +0200716
Mathieu Chartier3398c782016-09-30 10:27:43 -0700717 static JDWP::JdwpTypeTag GetTypeTag(ObjPtr<mirror::Class> klass)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700718 REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertz6995c602014-09-09 12:10:13 +0200719
Mathieu Chartierc7853442015-03-27 14:35:38 -0700720 static JDWP::FieldId ToFieldId(const ArtField* f)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700721 REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertz6995c602014-09-09 12:10:13 +0200722
Mathieu Chartiere401d142015-04-22 13:56:20 -0700723 static void SetJdwpLocation(JDWP::JdwpLocation* location, ArtMethod* m, uint32_t dex_pc)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700724 REQUIRES_SHARED(Locks::mutator_lock_)
Mathieu Chartier90443472015-07-16 20:32:27 -0700725 REQUIRES(!Locks::thread_list_lock_, !Locks::thread_suspend_count_lock_);
Sebastien Hertz6995c602014-09-09 12:10:13 +0200726
Mathieu Chartierad466ad2015-01-08 16:28:08 -0800727 static JDWP::JdwpState* GetJdwpState();
728
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700729 static uint32_t GetInstrumentationEvents() REQUIRES_SHARED(Locks::mutator_lock_) {
Sebastien Hertz9d6bf692015-04-10 12:12:33 +0200730 return instrumentation_events_;
731 }
732
Andreas Gampe04bbb5b2017-01-19 17:49:03 +0000733 static ThreadLifecycleCallback* GetThreadLifecycleCallback() {
734 return &thread_lifecycle_callback_;
735 }
Andreas Gampe0f01b582017-01-18 15:22:37 -0800736 static ClassLoadCallback* GetClassLoadCallback() {
737 return &class_load_callback_;
738 }
Andreas Gampe04bbb5b2017-01-19 17:49:03 +0000739
Elliott Hughes545a0642011-11-08 19:10:03 -0800740 private:
Sebastien Hertzcbc50642015-06-01 17:33:12 +0200741 static void ExecuteMethodWithoutPendingException(ScopedObjectAccess& soa, DebugInvokeReq* pReq)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700742 REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertzcbc50642015-06-01 17:33:12 +0200743
744 static void BuildInvokeReply(JDWP::ExpandBuf* pReply, uint32_t request_id,
745 JDWP::JdwpTag result_tag, uint64_t result_value,
746 JDWP::ObjectId exception)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700747 REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertzcbc50642015-06-01 17:33:12 +0200748
Sebastien Hertz8009f392014-09-01 17:07:11 +0200749 static JDWP::JdwpError GetLocalValue(const StackVisitor& visitor,
750 ScopedObjectAccessUnchecked& soa, int slot,
751 JDWP::JdwpTag tag, uint8_t* buf, size_t width)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700752 REQUIRES(!Locks::thread_list_lock_) REQUIRES_SHARED(Locks::mutator_lock_);
Mingyao Yang99170c62015-07-06 11:10:37 -0700753 static JDWP::JdwpError SetLocalValue(Thread* thread, StackVisitor& visitor, int slot,
754 JDWP::JdwpTag tag, uint64_t value, size_t width)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700755 REQUIRES(!Locks::thread_list_lock_) REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertz8009f392014-09-01 17:07:11 +0200756
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700757 static void DdmBroadcast(bool connect) REQUIRES_SHARED(Locks::mutator_lock_);
Andreas Gampe04bbb5b2017-01-19 17:49:03 +0000758
759 static void PostThreadStart(Thread* t)
760 REQUIRES_SHARED(Locks::mutator_lock_);
761 static void PostThreadDeath(Thread* t)
762 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700763 static void PostThreadStartOrStop(Thread*, uint32_t)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700764 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughesa2155262011-11-16 16:26:58 -0800765
Andreas Gampe0f01b582017-01-18 15:22:37 -0800766 static void PostClassPrepare(mirror::Class* c)
767 REQUIRES_SHARED(Locks::mutator_lock_);
768
Mathieu Chartiere401d142015-04-22 13:56:20 -0700769 static void PostLocationEvent(ArtMethod* method, int pcOffset,
Sebastien Hertz8379b222014-02-24 17:38:15 +0100770 mirror::Object* thisPtr, int eventFlags,
771 const JValue* return_value)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700772 REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertz8379b222014-02-24 17:38:15 +0100773
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100774 static void ProcessDeoptimizationRequest(const DeoptimizationRequest& request)
Mathieu Chartieraa516822015-10-02 15:53:37 -0700775 REQUIRES(Locks::mutator_lock_, Roles::uninterruptible_);
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100776
Sebastien Hertz7ec2f1c2014-03-27 20:06:47 +0100777 static void RequestDeoptimizationLocked(const DeoptimizationRequest& req)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700778 REQUIRES(Locks::deoptimization_lock_) REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertz7ec2f1c2014-03-27 20:06:47 +0100779
Mathieu Chartiere401d142015-04-22 13:56:20 -0700780 static bool IsForcedInterpreterNeededForCallingImpl(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 IsForcedInterpreterNeededForResolutionImpl(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 IsForcedInstrumentationNeededForResolutionImpl(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
Mathieu Chartiere401d142015-04-22 13:56:20 -0700789 static bool IsForcedInterpreterNeededForUpcallImpl(Thread* thread, ArtMethod* m)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700790 REQUIRES_SHARED(Locks::mutator_lock_);
Daniel Mihalyieb076692014-08-22 17:33:31 +0200791
Sebastien Hertz520633b2015-09-08 17:03:36 +0200792 static bool IsForcedInterpreterNeededForExceptionImpl(Thread* thread)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700793 REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertz520633b2015-09-08 17:03:36 +0200794
Daniel Mihalyieb076692014-08-22 17:33:31 +0200795 // Indicates whether the debugger is making requests.
796 static bool gDebuggerActive;
797
Alex Light21611932017-09-26 13:07:39 -0700798 static DebuggerActiveMethodInspectionCallback gDebugActiveCallback;
Alex Light8c2b9292017-11-09 13:21:01 -0800799 static DebuggerDdmCallback gDebugDdmCallback;
Alex Light21611932017-09-26 13:07:39 -0700800
Sebastien Hertz4e5b2082015-03-24 19:03:40 +0100801 // Indicates whether we should drop the JDWP connection because the runtime stops or the
802 // debugger called VirtualMachine.Dispose.
803 static bool gDisposed;
804
Daniel Mihalyieb076692014-08-22 17:33:31 +0200805 // The registry mapping objects to JDWP ids.
Sebastien Hertz6995c602014-09-09 12:10:13 +0200806 static ObjectRegistry* gRegistry;
807
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100808 // Deoptimization requests to be processed each time the event list is updated. This is used when
809 // registering and unregistering events so we do not deoptimize while holding the event list
810 // lock.
Sebastien Hertz42cd43f2014-05-13 14:15:41 +0200811 // TODO rename to instrumentation_requests.
Brian Carlstrom306db812014-09-05 13:01:41 -0700812 static std::vector<DeoptimizationRequest> deoptimization_requests_ GUARDED_BY(Locks::deoptimization_lock_);
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100813
814 // Count the number of events requiring full deoptimization. When the counter is > 0, everything
815 // is deoptimized, otherwise everything is undeoptimized.
816 // Note: we fully deoptimize on the first event only (when the counter is set to 1). We fully
817 // undeoptimize when the last event is unregistered (when the counter is set to 0).
Brian Carlstrom306db812014-09-05 13:01:41 -0700818 static size_t full_deoptimization_event_count_ GUARDED_BY(Locks::deoptimization_lock_);
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100819
Sebastien Hertz42cd43f2014-05-13 14:15:41 +0200820 static size_t* GetReferenceCounterForEvent(uint32_t instrumentation_event);
821
822 // Instrumentation event reference counters.
823 // TODO we could use an array instead of having all these dedicated counters. Instrumentation
824 // events are bits of a mask so we could convert them to array index.
Brian Carlstrom306db812014-09-05 13:01:41 -0700825 static size_t dex_pc_change_event_ref_count_ GUARDED_BY(Locks::deoptimization_lock_);
826 static size_t method_enter_event_ref_count_ GUARDED_BY(Locks::deoptimization_lock_);
827 static size_t method_exit_event_ref_count_ GUARDED_BY(Locks::deoptimization_lock_);
828 static size_t field_read_event_ref_count_ GUARDED_BY(Locks::deoptimization_lock_);
829 static size_t field_write_event_ref_count_ GUARDED_BY(Locks::deoptimization_lock_);
830 static size_t exception_catch_event_ref_count_ GUARDED_BY(Locks::deoptimization_lock_);
Sebastien Hertz42cd43f2014-05-13 14:15:41 +0200831 static uint32_t instrumentation_events_ GUARDED_BY(Locks::mutator_lock_);
832
Andreas Gampe04bbb5b2017-01-19 17:49:03 +0000833 class DbgThreadLifecycleCallback : public ThreadLifecycleCallback {
834 public:
835 void ThreadStart(Thread* self) OVERRIDE REQUIRES_SHARED(Locks::mutator_lock_);
836 void ThreadDeath(Thread* self) OVERRIDE REQUIRES_SHARED(Locks::mutator_lock_);
837 };
838
Andreas Gampe0f01b582017-01-18 15:22:37 -0800839 class DbgClassLoadCallback : public ClassLoadCallback {
840 public:
841 void ClassLoad(Handle<mirror::Class> klass) OVERRIDE REQUIRES_SHARED(Locks::mutator_lock_);
842 void ClassPrepare(Handle<mirror::Class> temp_klass,
843 Handle<mirror::Class> klass) OVERRIDE REQUIRES_SHARED(Locks::mutator_lock_);
844 };
845
Andreas Gampe04bbb5b2017-01-19 17:49:03 +0000846 static DbgThreadLifecycleCallback thread_lifecycle_callback_;
Andreas Gampe0f01b582017-01-18 15:22:37 -0800847 static DbgClassLoadCallback class_load_callback_;
Andreas Gampe04bbb5b2017-01-19 17:49:03 +0000848
Ian Rogers719d1a32014-03-06 12:13:39 -0800849 DISALLOW_COPY_AND_ASSIGN(Dbg);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700850};
851
852#define CHUNK_TYPE(_name) \
Elliott Hughes82188472011-11-07 18:11:48 -0800853 static_cast<uint32_t>((_name)[0] << 24 | (_name)[1] << 16 | (_name)[2] << 8 | (_name)[3])
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700854
855} // namespace art
856
Brian Carlstromfc0e3212013-07-17 14:40:12 -0700857#endif // ART_RUNTIME_DEBUGGER_H_