blob: a9fa6ce8cb637824492f231f50d1e5b2b6dfcccb [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
Mathieu Chartiere34fa1d2015-01-14 14:55:47 -080030#include "gc_root.h"
Elliott Hughes872d4ec2011-10-21 17:07:15 -070031#include "jdwp/jdwp.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080032#include "jni.h"
33#include "jvalue.h"
Jeff Hao920af3e2013-08-28 15:46:38 -070034#include "thread_state.h"
Elliott Hughes872d4ec2011-10-21 17:07:15 -070035
36namespace art {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080037namespace mirror {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080038class Class;
39class Object;
40class Throwable;
41} // namespace mirror
Mathieu Chartierc7853442015-03-27 14:35:38 -070042class ArtField;
Mathieu Chartiere401d142015-04-22 13:56:20 -070043class ArtMethod;
Sebastien Hertz6995c602014-09-09 12:10:13 +020044class ObjectRegistry;
Sebastien Hertzcbc50642015-06-01 17:33:12 +020045class ScopedObjectAccess;
Sebastien Hertz6995c602014-09-09 12:10:13 +020046class ScopedObjectAccessUnchecked;
Sebastien Hertz8009f392014-09-01 17:07:11 +020047class StackVisitor;
Ian Rogers1b09b092012-08-20 15:35:52 -070048class Thread;
Elliott Hughes872d4ec2011-10-21 17:07:15 -070049
50/*
51 * Invoke-during-breakpoint support.
52 */
53struct DebugInvokeReq {
Sebastien Hertzcbc50642015-06-01 17:33:12 +020054 DebugInvokeReq(uint32_t invoke_request_id, JDWP::ObjectId invoke_thread_id,
55 mirror::Object* invoke_receiver, mirror::Class* invoke_class,
Mathieu Chartiere401d142015-04-22 13:56:20 -070056 ArtMethod* invoke_method, uint32_t invoke_options,
Sebastien Hertzcbc50642015-06-01 17:33:12 +020057 uint64_t args[], uint32_t args_count)
58 : request_id(invoke_request_id), thread_id(invoke_thread_id), receiver(invoke_receiver),
59 klass(invoke_class), method(invoke_method), arg_count(args_count), arg_values(args),
60 options(invoke_options), reply(JDWP::expandBufAlloc()) {
Elliott Hughes475fc232011-10-25 15:00:35 -070061 }
62
Sebastien Hertzcbc50642015-06-01 17:33:12 +020063 ~DebugInvokeReq() {
64 JDWP::expandBufFree(reply);
65 }
66
67 // Request
68 const uint32_t request_id;
69 const JDWP::ObjectId thread_id;
70 GcRoot<mirror::Object> receiver; // not used for ClassType.InvokeMethod.
Sebastien Hertz1558b572015-02-25 15:05:59 +010071 GcRoot<mirror::Class> klass;
Sebastien Hertzcbc50642015-06-01 17:33:12 +020072 ArtMethod* const method;
Sebastien Hertz1558b572015-02-25 15:05:59 +010073 const uint32_t arg_count;
Sebastien Hertzcbc50642015-06-01 17:33:12 +020074 std::unique_ptr<uint64_t[]> arg_values; // will be null if arg_count_ == 0. We take ownership
75 // of this array so we must delete it upon destruction.
Sebastien Hertz1558b572015-02-25 15:05:59 +010076 const uint32_t options;
Elliott Hughes872d4ec2011-10-21 17:07:15 -070077
Sebastien Hertzcbc50642015-06-01 17:33:12 +020078 // Reply
79 JDWP::ExpandBuf* const reply;
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +010080
Mathieu Chartierbb87e0f2015-04-03 11:21:55 -070081 void VisitRoots(RootVisitor* visitor, const RootInfo& root_info)
Mathieu Chartier90443472015-07-16 20:32:27 -070082 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartier3b05e9b2014-03-25 09:29:43 -070083
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +010084 private:
85 DISALLOW_COPY_AND_ASSIGN(DebugInvokeReq);
86};
87
88// Thread local data-structure that holds fields for controlling single-stepping.
Sebastien Hertz597c4f02015-01-26 17:37:14 +010089class SingleStepControl {
90 public:
91 SingleStepControl(JDWP::JdwpStepSize step_size, JDWP::JdwpStepDepth step_depth,
Mathieu Chartiere401d142015-04-22 13:56:20 -070092 int stack_depth, ArtMethod* method)
Sebastien Hertz597c4f02015-01-26 17:37:14 +010093 : step_size_(step_size), step_depth_(step_depth),
94 stack_depth_(stack_depth), method_(method) {
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +010095 }
96
Sebastien Hertz597c4f02015-01-26 17:37:14 +010097 JDWP::JdwpStepSize GetStepSize() const {
98 return step_size_;
99 }
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +0100100
Sebastien Hertz597c4f02015-01-26 17:37:14 +0100101 JDWP::JdwpStepDepth GetStepDepth() const {
102 return step_depth_;
103 }
104
105 int GetStackDepth() const {
106 return stack_depth_;
107 }
108
Mathieu Chartiere401d142015-04-22 13:56:20 -0700109 ArtMethod* GetMethod() const {
110 return method_;
Sebastien Hertz597c4f02015-01-26 17:37:14 +0100111 }
112
113 const std::set<uint32_t>& GetDexPcs() const {
114 return dex_pcs_;
115 }
116
Sebastien Hertz597c4f02015-01-26 17:37:14 +0100117 void AddDexPc(uint32_t dex_pc);
118
119 bool ContainsDexPc(uint32_t dex_pc) const;
120
121 private:
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +0100122 // See JdwpStepSize and JdwpStepDepth for details.
Sebastien Hertz597c4f02015-01-26 17:37:14 +0100123 const JDWP::JdwpStepSize step_size_;
124 const JDWP::JdwpStepDepth step_depth_;
125
126 // The stack depth when this single-step was initiated. This is used to support SD_OVER and SD_OUT
127 // single-step depth.
128 const int stack_depth_;
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +0100129
130 // The location this single-step was initiated from.
131 // A single-step is initiated in a suspended thread. We save here the current method and the
132 // set of DEX pcs associated to the source line number where the suspension occurred.
133 // This is used to support SD_INTO and SD_OVER single-step depths so we detect when a single-step
134 // causes the execution of an instruction in a different method or at a different line number.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700135 ArtMethod* method_;
136
Sebastien Hertz597c4f02015-01-26 17:37:14 +0100137 std::set<uint32_t> dex_pcs_;
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +0100138
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +0100139 DISALLOW_COPY_AND_ASSIGN(SingleStepControl);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700140};
141
Sebastien Hertz42cd43f2014-05-13 14:15:41 +0200142// TODO rename to InstrumentationRequest.
Hiroshi Yamauchi0ec17d22014-07-07 13:07:08 -0700143class DeoptimizationRequest {
144 public:
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100145 enum Kind {
146 kNothing, // no action.
Sebastien Hertz42cd43f2014-05-13 14:15:41 +0200147 kRegisterForEvent, // start listening for instrumentation event.
148 kUnregisterForEvent, // stop listening for instrumentation event.
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100149 kFullDeoptimization, // deoptimize everything.
150 kFullUndeoptimization, // undeoptimize everything.
151 kSelectiveDeoptimization, // deoptimize one method.
152 kSelectiveUndeoptimization // undeoptimize one method.
153 };
154
Hiroshi Yamauchi0ec17d22014-07-07 13:07:08 -0700155 DeoptimizationRequest() : kind_(kNothing), instrumentation_event_(0), method_(nullptr) {}
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100156
Hiroshi Yamauchi0ec17d22014-07-07 13:07:08 -0700157 DeoptimizationRequest(const DeoptimizationRequest& other)
Mathieu Chartier90443472015-07-16 20:32:27 -0700158 SHARED_REQUIRES(Locks::mutator_lock_)
Hiroshi Yamauchi0ec17d22014-07-07 13:07:08 -0700159 : kind_(other.kind_), instrumentation_event_(other.instrumentation_event_) {
160 // Create a new JNI global reference for the method.
161 SetMethod(other.Method());
162 }
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100163
Mathieu Chartier90443472015-07-16 20:32:27 -0700164 ArtMethod* Method() const SHARED_REQUIRES(Locks::mutator_lock_);
Hiroshi Yamauchi0ec17d22014-07-07 13:07:08 -0700165
Mathieu Chartier90443472015-07-16 20:32:27 -0700166 void SetMethod(ArtMethod* m) SHARED_REQUIRES(Locks::mutator_lock_);
Hiroshi Yamauchi0ec17d22014-07-07 13:07:08 -0700167
168 // Name 'Kind()' would collide with the above enum name.
169 Kind GetKind() const {
170 return kind_;
171 }
172
173 void SetKind(Kind kind) {
174 kind_ = kind;
175 }
176
177 uint32_t InstrumentationEvent() const {
178 return instrumentation_event_;
179 }
180
181 void SetInstrumentationEvent(uint32_t instrumentation_event) {
182 instrumentation_event_ = instrumentation_event;
183 }
184
185 private:
186 Kind kind_;
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100187
Sebastien Hertz42cd43f2014-05-13 14:15:41 +0200188 // TODO we could use a union to hold the instrumentation_event and the method since they
189 // respectively have sense only for kRegisterForEvent/kUnregisterForEvent and
190 // kSelectiveDeoptimization/kSelectiveUndeoptimization.
191
192 // Event to start or stop listening to. Only for kRegisterForEvent and kUnregisterForEvent.
Hiroshi Yamauchi0ec17d22014-07-07 13:07:08 -0700193 uint32_t instrumentation_event_;
Sebastien Hertz42cd43f2014-05-13 14:15:41 +0200194
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100195 // Method for selective deoptimization.
Hiroshi Yamauchi0ec17d22014-07-07 13:07:08 -0700196 jmethodID method_;
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100197};
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700198std::ostream& operator<<(std::ostream& os, const DeoptimizationRequest::Kind& rhs);
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100199
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700200class Dbg {
Elliott Hughesff17f1f2012-01-24 18:12:29 -0800201 public:
Elliott Hughes4ffd3132011-10-24 12:06:42 -0700202 static void SetJdwpAllowed(bool allowed);
203
Sebastien Hertzb3b173b2015-02-06 09:16:32 +0100204 static void StartJdwp();
Elliott Hughesd1cc8362011-10-24 16:58:50 -0700205 static void StopJdwp();
206
Elliott Hughes767a1472011-10-26 18:49:02 -0700207 // Invoked by the GC in case we need to keep DDMS informed.
Mathieu Chartier90443472015-07-16 20:32:27 -0700208 static void GcDidFinish() REQUIRES(!Locks::mutator_lock_);
Elliott Hughes767a1472011-10-26 18:49:02 -0700209
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700210 // Return the DebugInvokeReq for the current thread.
211 static DebugInvokeReq* GetInvokeReq();
212
Elliott Hughes475fc232011-10-25 15:00:35 -0700213 static Thread* GetDebugThread();
214 static void ClearWaitForEventThread();
215
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700216 /*
217 * Enable/disable breakpoints and step modes. Used to provide a heads-up
218 * when the debugger attaches.
219 */
220 static void Connected();
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100221 static void GoActive()
Mathieu Chartier90443472015-07-16 20:32:27 -0700222 REQUIRES(!Locks::breakpoint_lock_, !Locks::deoptimization_lock_, !Locks::mutator_lock_);
223 static void Disconnected() REQUIRES(!Locks::deoptimization_lock_, !Locks::mutator_lock_);
Sebastien Hertz4e5b2082015-03-24 19:03:40 +0100224 static void Dispose() {
225 gDisposed = true;
226 }
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700227
Elliott Hughesc0f09332012-03-26 13:27:06 -0700228 // Returns true if we're actually debugging with a real debugger, false if it's
229 // just DDMS (or nothing at all).
Daniel Mihalyieb076692014-08-22 17:33:31 +0200230 static bool IsDebuggerActive() {
231 return gDebuggerActive;
232 }
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700233
Sebastien Hertzb3b173b2015-02-06 09:16:32 +0100234 // Configures JDWP with parsed command-line options.
235 static void ConfigureJdwp(const JDWP::JdwpOptions& jdwp_options);
236
Elliott Hughesc0f09332012-03-26 13:27:06 -0700237 // Returns true if we had -Xrunjdwp or -agentlib:jdwp= on the command line.
238 static bool IsJdwpConfigured();
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700239
Mathieu Chartierd8565452015-03-26 09:41:50 -0700240 // Returns true if a method has any breakpoints.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700241 static bool MethodHasAnyBreakpoints(ArtMethod* method)
Mathieu Chartier90443472015-07-16 20:32:27 -0700242 SHARED_REQUIRES(Locks::mutator_lock_) REQUIRES(!Locks::breakpoint_lock_);
Mathieu Chartierd8565452015-03-26 09:41:50 -0700243
Sebastien Hertz4e5b2082015-03-24 19:03:40 +0100244 static bool IsDisposed() {
245 return gDisposed;
246 }
Elliott Hughes86964332012-02-15 19:37:42 -0800247
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700248 /*
249 * Time, in milliseconds, since the last debugger activity. Does not
250 * include DDMS activity. Returns -1 if there has been no activity.
251 * Returns 0 if we're in the middle of handling a debugger request.
252 */
253 static int64_t LastDebuggerActivity();
254
Sebastien Hertz253fa552014-10-14 17:27:15 +0200255 static void UndoDebuggerSuspensions()
Mathieu Chartier90443472015-07-16 20:32:27 -0700256 REQUIRES(!Locks::thread_list_lock_, !Locks::thread_suspend_count_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700257
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700258 /*
259 * Class, Object, Array
260 */
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700261 static std::string GetClassName(JDWP::RefTypeId id)
Mathieu Chartier90443472015-07-16 20:32:27 -0700262 SHARED_REQUIRES(Locks::mutator_lock_);
Sebastien Hertz6995c602014-09-09 12:10:13 +0200263 static std::string GetClassName(mirror::Class* klass)
Mathieu Chartier90443472015-07-16 20:32:27 -0700264 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogersc0542af2014-09-03 16:16:56 -0700265 static JDWP::JdwpError GetClassObject(JDWP::RefTypeId id, JDWP::ObjectId* class_object_id)
Mathieu Chartier90443472015-07-16 20:32:27 -0700266 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogersc0542af2014-09-03 16:16:56 -0700267 static JDWP::JdwpError GetSuperclass(JDWP::RefTypeId id, JDWP::RefTypeId* superclass_id)
Mathieu Chartier90443472015-07-16 20:32:27 -0700268 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700269 static JDWP::JdwpError GetClassLoader(JDWP::RefTypeId id, JDWP::ExpandBuf* pReply)
Mathieu Chartier90443472015-07-16 20:32:27 -0700270 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700271 static JDWP::JdwpError GetModifiers(JDWP::RefTypeId id, JDWP::ExpandBuf* pReply)
Mathieu Chartier90443472015-07-16 20:32:27 -0700272 SHARED_REQUIRES(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800273 static JDWP::JdwpError GetReflectedType(JDWP::RefTypeId class_id, JDWP::ExpandBuf* pReply)
Mathieu Chartier90443472015-07-16 20:32:27 -0700274 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogersc0542af2014-09-03 16:16:56 -0700275 static void GetClassList(std::vector<JDWP::RefTypeId>* classes)
Mathieu Chartier90443472015-07-16 20:32:27 -0700276 SHARED_REQUIRES(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800277 static JDWP::JdwpError GetClassInfo(JDWP::RefTypeId class_id, JDWP::JdwpTypeTag* pTypeTag,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700278 uint32_t* pStatus, std::string* pDescriptor)
Mathieu Chartier90443472015-07-16 20:32:27 -0700279 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogersc0542af2014-09-03 16:16:56 -0700280 static void FindLoadedClassBySignature(const char* descriptor, std::vector<JDWP::RefTypeId>* ids)
Mathieu Chartier90443472015-07-16 20:32:27 -0700281 SHARED_REQUIRES(Locks::mutator_lock_);
Elliott Hughes64f574f2013-02-20 14:57:12 -0800282 static JDWP::JdwpError GetReferenceType(JDWP::ObjectId object_id, JDWP::ExpandBuf* pReply)
Mathieu Chartier90443472015-07-16 20:32:27 -0700283 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogersfc0e94b2013-09-23 23:51:32 -0700284 static JDWP::JdwpError GetSignature(JDWP::RefTypeId ref_type_id, std::string* signature)
Mathieu Chartier90443472015-07-16 20:32:27 -0700285 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogersc0542af2014-09-03 16:16:56 -0700286 static JDWP::JdwpError GetSourceFile(JDWP::RefTypeId ref_type_id, std::string* source_file)
Mathieu Chartier90443472015-07-16 20:32:27 -0700287 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogersc0542af2014-09-03 16:16:56 -0700288 static JDWP::JdwpError GetObjectTag(JDWP::ObjectId object_id, uint8_t* tag)
Mathieu Chartier90443472015-07-16 20:32:27 -0700289 SHARED_REQUIRES(Locks::mutator_lock_);
Elliott Hughesaed4be92011-12-02 16:16:23 -0800290 static size_t GetTagWidth(JDWP::JdwpTag tag);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700291
Ian Rogersc0542af2014-09-03 16:16:56 -0700292 static JDWP::JdwpError GetArrayLength(JDWP::ObjectId array_id, int32_t* length)
Mathieu Chartier90443472015-07-16 20:32:27 -0700293 SHARED_REQUIRES(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800294 static JDWP::JdwpError OutputArray(JDWP::ObjectId array_id, int offset, int count,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700295 JDWP::ExpandBuf* pReply)
Mathieu Chartier90443472015-07-16 20:32:27 -0700296 SHARED_REQUIRES(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800297 static JDWP::JdwpError SetArrayElements(JDWP::ObjectId array_id, int offset, int count,
Ian Rogersc0542af2014-09-03 16:16:56 -0700298 JDWP::Request* request)
Mathieu Chartier90443472015-07-16 20:32:27 -0700299 SHARED_REQUIRES(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700300
Sebastien Hertz2c3e77a2015-04-02 16:26:48 +0200301 static JDWP::JdwpError CreateString(const std::string& str, JDWP::ObjectId* new_string_id)
Mathieu Chartier90443472015-07-16 20:32:27 -0700302 SHARED_REQUIRES(Locks::mutator_lock_);
Sebastien Hertz2c3e77a2015-04-02 16:26:48 +0200303 static JDWP::JdwpError CreateObject(JDWP::RefTypeId class_id, JDWP::ObjectId* new_object_id)
Mathieu Chartier90443472015-07-16 20:32:27 -0700304 SHARED_REQUIRES(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800305 static JDWP::JdwpError CreateArrayObject(JDWP::RefTypeId array_class_id, uint32_t length,
Sebastien Hertz2c3e77a2015-04-02 16:26:48 +0200306 JDWP::ObjectId* new_array_id)
Mathieu Chartier90443472015-07-16 20:32:27 -0700307 SHARED_REQUIRES(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700308
Sebastien Hertz6995c602014-09-09 12:10:13 +0200309 //
310 // Event filtering.
311 //
312 static bool MatchThread(JDWP::ObjectId expected_thread_id, Thread* event_thread)
Mathieu Chartier90443472015-07-16 20:32:27 -0700313 SHARED_REQUIRES(Locks::mutator_lock_);
Sebastien Hertz6995c602014-09-09 12:10:13 +0200314
315 static bool MatchLocation(const JDWP::JdwpLocation& expected_location,
316 const JDWP::EventLocation& event_location)
Mathieu Chartier90443472015-07-16 20:32:27 -0700317 SHARED_REQUIRES(Locks::mutator_lock_);
Sebastien Hertz6995c602014-09-09 12:10:13 +0200318
319 static bool MatchType(mirror::Class* event_class, JDWP::RefTypeId class_id)
Mathieu Chartier90443472015-07-16 20:32:27 -0700320 SHARED_REQUIRES(Locks::mutator_lock_);
Sebastien Hertz6995c602014-09-09 12:10:13 +0200321
322 static bool MatchField(JDWP::RefTypeId expected_type_id, JDWP::FieldId expected_field_id,
Mathieu Chartierc7853442015-03-27 14:35:38 -0700323 ArtField* event_field)
Mathieu Chartier90443472015-07-16 20:32:27 -0700324 SHARED_REQUIRES(Locks::mutator_lock_);
Sebastien Hertz6995c602014-09-09 12:10:13 +0200325
326 static bool MatchInstance(JDWP::ObjectId expected_instance_id, mirror::Object* event_instance)
Mathieu Chartier90443472015-07-16 20:32:27 -0700327 SHARED_REQUIRES(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700328
Elliott Hughesec0f83d2013-01-15 16:54:08 -0800329 //
330 // Monitors.
331 //
332 static JDWP::JdwpError GetMonitorInfo(JDWP::ObjectId object_id, JDWP::ExpandBuf* reply)
Mathieu Chartier90443472015-07-16 20:32:27 -0700333 SHARED_REQUIRES(Locks::mutator_lock_);
Elliott Hughesec0f83d2013-01-15 16:54:08 -0800334 static JDWP::JdwpError GetOwnedMonitors(JDWP::ObjectId thread_id,
Ian Rogersc0542af2014-09-03 16:16:56 -0700335 std::vector<JDWP::ObjectId>* monitors,
336 std::vector<uint32_t>* stack_depths)
Mathieu Chartier90443472015-07-16 20:32:27 -0700337 REQUIRES(!Locks::thread_list_lock_) SHARED_REQUIRES(Locks::mutator_lock_);
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100338 static JDWP::JdwpError GetContendedMonitor(JDWP::ObjectId thread_id,
Ian Rogersc0542af2014-09-03 16:16:56 -0700339 JDWP::ObjectId* contended_monitor)
Mathieu Chartier90443472015-07-16 20:32:27 -0700340 REQUIRES(!Locks::thread_list_lock_) SHARED_REQUIRES(Locks::mutator_lock_);
Elliott Hughesec0f83d2013-01-15 16:54:08 -0800341
342 //
343 // Heap.
344 //
345 static JDWP::JdwpError GetInstanceCounts(const std::vector<JDWP::RefTypeId>& class_ids,
Ian Rogersc0542af2014-09-03 16:16:56 -0700346 std::vector<uint64_t>* counts)
Mathieu Chartier90443472015-07-16 20:32:27 -0700347 SHARED_REQUIRES(Locks::mutator_lock_);
Elliott Hughes3b78c942013-01-15 17:35:41 -0800348 static JDWP::JdwpError GetInstances(JDWP::RefTypeId class_id, int32_t max_count,
Ian Rogersc0542af2014-09-03 16:16:56 -0700349 std::vector<JDWP::ObjectId>* instances)
Mathieu Chartier90443472015-07-16 20:32:27 -0700350 SHARED_REQUIRES(Locks::mutator_lock_);
Elliott Hughes0cbaff52013-01-16 15:28:01 -0800351 static JDWP::JdwpError GetReferringObjects(JDWP::ObjectId object_id, int32_t max_count,
Ian Rogersc0542af2014-09-03 16:16:56 -0700352 std::vector<JDWP::ObjectId>* referring_objects)
Mathieu Chartier90443472015-07-16 20:32:27 -0700353 SHARED_REQUIRES(Locks::mutator_lock_);
Elliott Hughes64f574f2013-02-20 14:57:12 -0800354 static JDWP::JdwpError DisableCollection(JDWP::ObjectId object_id)
Mathieu Chartier90443472015-07-16 20:32:27 -0700355 SHARED_REQUIRES(Locks::mutator_lock_);
Elliott Hughes64f574f2013-02-20 14:57:12 -0800356 static JDWP::JdwpError EnableCollection(JDWP::ObjectId object_id)
Mathieu Chartier90443472015-07-16 20:32:27 -0700357 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogersc0542af2014-09-03 16:16:56 -0700358 static JDWP::JdwpError IsCollected(JDWP::ObjectId object_id, bool* is_collected)
Mathieu Chartier90443472015-07-16 20:32:27 -0700359 SHARED_REQUIRES(Locks::mutator_lock_);
Elliott Hughes64f574f2013-02-20 14:57:12 -0800360 static void DisposeObject(JDWP::ObjectId object_id, uint32_t reference_count)
Mathieu Chartier90443472015-07-16 20:32:27 -0700361 SHARED_REQUIRES(Locks::mutator_lock_);
Elliott Hughesec0f83d2013-01-15 16:54:08 -0800362
Elliott Hughes9777ba22013-01-17 09:04:19 -0800363 //
364 // Methods and fields.
365 //
Elliott Hughesa96836a2013-01-17 12:27:49 -0800366 static std::string GetMethodName(JDWP::MethodId method_id)
Mathieu Chartier90443472015-07-16 20:32:27 -0700367 SHARED_REQUIRES(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800368 static JDWP::JdwpError OutputDeclaredFields(JDWP::RefTypeId ref_type_id, bool with_generic,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700369 JDWP::ExpandBuf* pReply)
Mathieu Chartier90443472015-07-16 20:32:27 -0700370 SHARED_REQUIRES(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800371 static JDWP::JdwpError OutputDeclaredMethods(JDWP::RefTypeId ref_type_id, bool with_generic,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700372 JDWP::ExpandBuf* pReply)
Mathieu Chartier90443472015-07-16 20:32:27 -0700373 SHARED_REQUIRES(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800374 static JDWP::JdwpError OutputDeclaredInterfaces(JDWP::RefTypeId ref_type_id,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700375 JDWP::ExpandBuf* pReply)
Mathieu Chartier90443472015-07-16 20:32:27 -0700376 SHARED_REQUIRES(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800377 static void OutputLineTable(JDWP::RefTypeId ref_type_id, JDWP::MethodId method_id,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700378 JDWP::ExpandBuf* pReply)
Mathieu Chartier90443472015-07-16 20:32:27 -0700379 SHARED_REQUIRES(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800380 static void OutputVariableTable(JDWP::RefTypeId ref_type_id, JDWP::MethodId id, bool with_generic,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700381 JDWP::ExpandBuf* pReply)
Mathieu Chartier90443472015-07-16 20:32:27 -0700382 SHARED_REQUIRES(Locks::mutator_lock_);
Jeff Hao579b0242013-11-18 13:16:49 -0800383 static void OutputMethodReturnValue(JDWP::MethodId method_id, const JValue* return_value,
384 JDWP::ExpandBuf* pReply)
Mathieu Chartier90443472015-07-16 20:32:27 -0700385 SHARED_REQUIRES(Locks::mutator_lock_);
Sebastien Hertz3f52eaf2014-04-04 17:50:18 +0200386 static void OutputFieldValue(JDWP::FieldId field_id, const JValue* field_value,
387 JDWP::ExpandBuf* pReply)
Mathieu Chartier90443472015-07-16 20:32:27 -0700388 SHARED_REQUIRES(Locks::mutator_lock_);
Elliott Hughes9777ba22013-01-17 09:04:19 -0800389 static JDWP::JdwpError GetBytecodes(JDWP::RefTypeId class_id, JDWP::MethodId method_id,
Ian Rogersc0542af2014-09-03 16:16:56 -0700390 std::vector<uint8_t>* bytecodes)
Mathieu Chartier90443472015-07-16 20:32:27 -0700391 SHARED_REQUIRES(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700392
Elliott Hughesa96836a2013-01-17 12:27:49 -0800393 static std::string GetFieldName(JDWP::FieldId field_id)
Mathieu Chartier90443472015-07-16 20:32:27 -0700394 SHARED_REQUIRES(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800395 static JDWP::JdwpTag GetFieldBasicTag(JDWP::FieldId field_id)
Mathieu Chartier90443472015-07-16 20:32:27 -0700396 SHARED_REQUIRES(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800397 static JDWP::JdwpTag GetStaticFieldBasicTag(JDWP::FieldId field_id)
Mathieu Chartier90443472015-07-16 20:32:27 -0700398 SHARED_REQUIRES(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800399 static JDWP::JdwpError GetFieldValue(JDWP::ObjectId object_id, JDWP::FieldId field_id,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700400 JDWP::ExpandBuf* pReply)
Mathieu Chartier90443472015-07-16 20:32:27 -0700401 SHARED_REQUIRES(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800402 static JDWP::JdwpError SetFieldValue(JDWP::ObjectId object_id, JDWP::FieldId field_id,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700403 uint64_t value, int width)
Mathieu Chartier90443472015-07-16 20:32:27 -0700404 SHARED_REQUIRES(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800405 static JDWP::JdwpError GetStaticFieldValue(JDWP::RefTypeId ref_type_id, JDWP::FieldId field_id,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700406 JDWP::ExpandBuf* pReply)
Mathieu Chartier90443472015-07-16 20:32:27 -0700407 SHARED_REQUIRES(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800408 static JDWP::JdwpError SetStaticFieldValue(JDWP::FieldId field_id, uint64_t value, int width)
Mathieu Chartier90443472015-07-16 20:32:27 -0700409 SHARED_REQUIRES(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700410
Sebastien Hertzb0b0b492014-09-15 11:27:27 +0200411 static JDWP::JdwpError StringToUtf8(JDWP::ObjectId string_id, std::string* str)
Mathieu Chartier90443472015-07-16 20:32:27 -0700412 SHARED_REQUIRES(Locks::mutator_lock_);
Jeff Hao579b0242013-11-18 13:16:49 -0800413 static void OutputJValue(JDWP::JdwpTag tag, const JValue* return_value, JDWP::ExpandBuf* pReply)
Mathieu Chartier90443472015-07-16 20:32:27 -0700414 SHARED_REQUIRES(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700415
416 /*
417 * Thread, ThreadGroup, Frame
418 */
Ian Rogersc0542af2014-09-03 16:16:56 -0700419 static JDWP::JdwpError GetThreadName(JDWP::ObjectId thread_id, std::string* name)
Mathieu Chartier90443472015-07-16 20:32:27 -0700420 SHARED_REQUIRES(Locks::mutator_lock_) REQUIRES(!Locks::thread_list_lock_);
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100421 static JDWP::JdwpError GetThreadGroup(JDWP::ObjectId thread_id, JDWP::ExpandBuf* pReply)
Mathieu Chartier90443472015-07-16 20:32:27 -0700422 SHARED_REQUIRES(Locks::mutator_lock_) REQUIRES(!Locks::thread_list_lock_);
Sebastien Hertza06430c2014-09-15 19:21:30 +0200423 static JDWP::JdwpError GetThreadGroupName(JDWP::ObjectId thread_group_id,
424 JDWP::ExpandBuf* pReply)
Mathieu Chartier90443472015-07-16 20:32:27 -0700425 SHARED_REQUIRES(Locks::mutator_lock_);
Sebastien Hertza06430c2014-09-15 19:21:30 +0200426 static JDWP::JdwpError GetThreadGroupParent(JDWP::ObjectId thread_group_id,
427 JDWP::ExpandBuf* pReply)
Mathieu Chartier90443472015-07-16 20:32:27 -0700428 SHARED_REQUIRES(Locks::mutator_lock_);
Sebastien Hertza06430c2014-09-15 19:21:30 +0200429 static JDWP::JdwpError GetThreadGroupChildren(JDWP::ObjectId thread_group_id,
430 JDWP::ExpandBuf* pReply)
Mathieu Chartier90443472015-07-16 20:32:27 -0700431 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700432 static JDWP::ObjectId GetSystemThreadGroupId()
Mathieu Chartier90443472015-07-16 20:32:27 -0700433 SHARED_REQUIRES(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700434
Jeff Hao920af3e2013-08-28 15:46:38 -0700435 static JDWP::JdwpThreadStatus ToJdwpThreadStatus(ThreadState state);
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100436 static JDWP::JdwpError GetThreadStatus(JDWP::ObjectId thread_id,
437 JDWP::JdwpThreadStatus* pThreadStatus,
438 JDWP::JdwpSuspendStatus* pSuspendStatus)
Mathieu Chartier90443472015-07-16 20:32:27 -0700439 REQUIRES(!Locks::thread_list_lock_);
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100440 static JDWP::JdwpError GetThreadDebugSuspendCount(JDWP::ObjectId thread_id,
441 JDWP::ExpandBuf* pReply)
Mathieu Chartier90443472015-07-16 20:32:27 -0700442 REQUIRES(!Locks::thread_list_lock_, !Locks::thread_suspend_count_lock_);
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700443 // static void WaitForSuspend(JDWP::ObjectId thread_id);
Elliott Hughescaf76542012-06-28 16:08:22 -0700444
Elliott Hughes026b1462012-06-28 20:43:49 -0700445 // Fills 'thread_ids' with the threads in the given thread group. If thread_group_id == 0,
Elliott Hughescaf76542012-06-28 16:08:22 -0700446 // returns all threads.
Sebastien Hertza06430c2014-09-15 19:21:30 +0200447 static void GetThreads(mirror::Object* thread_group, std::vector<JDWP::ObjectId>* thread_ids)
Mathieu Chartier90443472015-07-16 20:32:27 -0700448 REQUIRES(!Locks::thread_list_lock_) SHARED_REQUIRES(Locks::mutator_lock_);
Elliott Hughescaf76542012-06-28 16:08:22 -0700449
Ian Rogersc0542af2014-09-03 16:16:56 -0700450 static JDWP::JdwpError GetThreadFrameCount(JDWP::ObjectId thread_id, size_t* result)
Mathieu Chartier90443472015-07-16 20:32:27 -0700451 REQUIRES(!Locks::thread_list_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700452 static JDWP::JdwpError GetThreadFrames(JDWP::ObjectId thread_id, size_t start_frame,
453 size_t frame_count, JDWP::ExpandBuf* buf)
Mathieu Chartier90443472015-07-16 20:32:27 -0700454 REQUIRES(!Locks::thread_list_lock_) SHARED_REQUIRES(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700455
Mathieu Chartier90443472015-07-16 20:32:27 -0700456 static JDWP::ObjectId GetThreadSelfId() SHARED_REQUIRES(Locks::mutator_lock_);
457 static JDWP::ObjectId GetThreadId(Thread* thread) SHARED_REQUIRES(Locks::mutator_lock_);
Sebastien Hertz6995c602014-09-09 12:10:13 +0200458
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700459 static void SuspendVM()
Mathieu Chartier90443472015-07-16 20:32:27 -0700460 REQUIRES(!Locks::thread_list_lock_, !Locks::thread_suspend_count_lock_);
Sebastien Hertz253fa552014-10-14 17:27:15 +0200461 static void ResumeVM()
Mathieu Chartier90443472015-07-16 20:32:27 -0700462 REQUIRES(!Locks::thread_list_lock_, !Locks::thread_suspend_count_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800463 static JDWP::JdwpError SuspendThread(JDWP::ObjectId thread_id, bool request_suspension = true)
Mathieu Chartier90443472015-07-16 20:32:27 -0700464 REQUIRES(!Locks::mutator_lock_, !Locks::thread_list_lock_,
465 !Locks::thread_suspend_count_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700466
Elliott Hughes88d63092013-01-09 09:55:54 -0800467 static void ResumeThread(JDWP::ObjectId thread_id)
Mathieu Chartier90443472015-07-16 20:32:27 -0700468 REQUIRES(!Locks::thread_list_lock_, !Locks::thread_suspend_count_lock_)
469 SHARED_REQUIRES(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700470 static void SuspendSelf();
471
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700472 static JDWP::JdwpError GetThisObject(JDWP::ObjectId thread_id, JDWP::FrameId frame_id,
473 JDWP::ObjectId* result)
Mathieu Chartier90443472015-07-16 20:32:27 -0700474 REQUIRES(!Locks::thread_list_lock_, !Locks::thread_suspend_count_lock_)
475 SHARED_REQUIRES(Locks::mutator_lock_);
Sebastien Hertz8009f392014-09-01 17:07:11 +0200476 static JDWP::JdwpError GetLocalValues(JDWP::Request* request, JDWP::ExpandBuf* pReply)
Mathieu Chartier90443472015-07-16 20:32:27 -0700477 REQUIRES(!Locks::thread_list_lock_) SHARED_REQUIRES(Locks::mutator_lock_);
Sebastien Hertz8009f392014-09-01 17:07:11 +0200478 static JDWP::JdwpError SetLocalValues(JDWP::Request* request)
Mathieu Chartier90443472015-07-16 20:32:27 -0700479 REQUIRES(!Locks::thread_list_lock_) SHARED_REQUIRES(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700480
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100481 static JDWP::JdwpError Interrupt(JDWP::ObjectId thread_id)
Mathieu Chartier90443472015-07-16 20:32:27 -0700482 REQUIRES(!Locks::thread_list_lock_);
Elliott Hughesf9501702013-01-11 11:22:27 -0800483
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700484 /*
485 * Debugger notification
486 */
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700487 enum EventFlag {
Elliott Hughes86964332012-02-15 19:37:42 -0800488 kBreakpoint = 0x01,
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700489 kSingleStep = 0x02,
490 kMethodEntry = 0x04,
491 kMethodExit = 0x08,
492 };
Mathieu Chartiere401d142015-04-22 13:56:20 -0700493 static void PostFieldAccessEvent(ArtMethod* m, int dex_pc, mirror::Object* this_object,
Mathieu Chartierc7853442015-03-27 14:35:38 -0700494 ArtField* f)
Mathieu Chartier90443472015-07-16 20:32:27 -0700495 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700496 static void PostFieldModificationEvent(ArtMethod* m, int dex_pc,
Mathieu Chartierc7853442015-03-27 14:35:38 -0700497 mirror::Object* this_object, ArtField* f,
Sebastien Hertz3f52eaf2014-04-04 17:50:18 +0200498 const JValue* field_value)
Mathieu Chartier90443472015-07-16 20:32:27 -0700499 SHARED_REQUIRES(Locks::mutator_lock_);
Nicolas Geoffray14691c52015-03-05 10:40:17 +0000500 static void PostException(mirror::Throwable* exception)
Mathieu Chartier90443472015-07-16 20:32:27 -0700501 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700502 static void PostThreadStart(Thread* t)
Mathieu Chartier90443472015-07-16 20:32:27 -0700503 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700504 static void PostThreadDeath(Thread* t)
Mathieu Chartier90443472015-07-16 20:32:27 -0700505 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800506 static void PostClassPrepare(mirror::Class* c)
Mathieu Chartier90443472015-07-16 20:32:27 -0700507 SHARED_REQUIRES(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700508
Ian Rogers62d6c772013-02-27 08:32:07 -0800509 static void UpdateDebugger(Thread* thread, mirror::Object* this_object,
Mathieu Chartiere401d142015-04-22 13:56:20 -0700510 ArtMethod* method, uint32_t new_dex_pc,
Sebastien Hertz8379b222014-02-24 17:38:15 +0100511 int event_flags, const JValue* return_value)
Mathieu Chartier90443472015-07-16 20:32:27 -0700512 REQUIRES(!Locks::breakpoint_lock_) SHARED_REQUIRES(Locks::mutator_lock_);
Elliott Hughes91bf6cd2012-02-14 17:27:48 -0800513
Sebastien Hertzf3928792014-11-17 19:00:37 +0100514 // Indicates whether we need deoptimization for debugging.
515 static bool RequiresDeoptimization();
516
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100517 // Records deoptimization request in the queue.
518 static void RequestDeoptimization(const DeoptimizationRequest& req)
Mathieu Chartier90443472015-07-16 20:32:27 -0700519 REQUIRES(!Locks::deoptimization_lock_) SHARED_REQUIRES(Locks::mutator_lock_);
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100520
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100521 // Manage deoptimization after updating JDWP events list. Suspends all threads, processes each
522 // request and finally resumes all threads.
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100523 static void ManageDeoptimization()
Mathieu Chartier90443472015-07-16 20:32:27 -0700524 REQUIRES(!Locks::deoptimization_lock_) SHARED_REQUIRES(Locks::mutator_lock_);
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100525
526 // Breakpoints.
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100527 static void WatchLocation(const JDWP::JdwpLocation* pLoc, DeoptimizationRequest* req)
Mathieu Chartier90443472015-07-16 20:32:27 -0700528 REQUIRES(!Locks::breakpoint_lock_) SHARED_REQUIRES(Locks::mutator_lock_);
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100529 static void UnwatchLocation(const JDWP::JdwpLocation* pLoc, DeoptimizationRequest* req)
Mathieu Chartier90443472015-07-16 20:32:27 -0700530 REQUIRES(!Locks::breakpoint_lock_) SHARED_REQUIRES(Locks::mutator_lock_);
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100531
Daniel Mihalyieb076692014-08-22 17:33:31 +0200532 /*
533 * Forced interpreter checkers for single-step and continue support.
534 */
535
536 // Indicates whether we need to force the use of interpreter to invoke a method.
537 // This allows to single-step or continue into the called method.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700538 static bool IsForcedInterpreterNeededForCalling(Thread* thread, ArtMethod* m)
Mathieu Chartier90443472015-07-16 20:32:27 -0700539 SHARED_REQUIRES(Locks::mutator_lock_) {
Daniel Mihalyieb076692014-08-22 17:33:31 +0200540 if (!IsDebuggerActive()) {
541 return false;
542 }
543 return IsForcedInterpreterNeededForCallingImpl(thread, m);
544 }
545
546 // Indicates whether we need to force the use of interpreter entrypoint when calling a
547 // method through the resolution trampoline. This allows to single-step or continue into
548 // the called method.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700549 static bool IsForcedInterpreterNeededForResolution(Thread* thread, ArtMethod* m)
Mathieu Chartier90443472015-07-16 20:32:27 -0700550 SHARED_REQUIRES(Locks::mutator_lock_) {
Daniel Mihalyieb076692014-08-22 17:33:31 +0200551 if (!IsDebuggerActive()) {
552 return false;
553 }
554 return IsForcedInterpreterNeededForResolutionImpl(thread, m);
555 }
556
557 // Indicates whether we need to force the use of instrumentation entrypoint when calling
558 // a method through the resolution trampoline. This allows to deoptimize the stack for
559 // debugging when we returned from the called method.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700560 static bool IsForcedInstrumentationNeededForResolution(Thread* thread, ArtMethod* m)
Mathieu Chartier90443472015-07-16 20:32:27 -0700561 SHARED_REQUIRES(Locks::mutator_lock_) {
Daniel Mihalyieb076692014-08-22 17:33:31 +0200562 if (!IsDebuggerActive()) {
563 return false;
564 }
565 return IsForcedInstrumentationNeededForResolutionImpl(thread, m);
566 }
567
568 // Indicates whether we need to force the use of interpreter when returning from the
569 // interpreter into the runtime. This allows to deoptimize the stack and continue
570 // execution with interpreter for debugging.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700571 static bool IsForcedInterpreterNeededForUpcall(Thread* thread, ArtMethod* m)
Mathieu Chartier90443472015-07-16 20:32:27 -0700572 SHARED_REQUIRES(Locks::mutator_lock_) {
Daniel Mihalyieb076692014-08-22 17:33:31 +0200573 if (!IsDebuggerActive()) {
574 return false;
575 }
576 return IsForcedInterpreterNeededForUpcallImpl(thread, m);
577 }
578
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100579 // Single-stepping.
Elliott Hughes88d63092013-01-09 09:55:54 -0800580 static JDWP::JdwpError ConfigureStep(JDWP::ObjectId thread_id, JDWP::JdwpStepSize size,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700581 JDWP::JdwpStepDepth depth)
Mathieu Chartier90443472015-07-16 20:32:27 -0700582 SHARED_REQUIRES(Locks::mutator_lock_);
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +0100583 static void UnconfigureStep(JDWP::ObjectId thread_id)
Mathieu Chartier90443472015-07-16 20:32:27 -0700584 REQUIRES(!Locks::thread_list_lock_) SHARED_REQUIRES(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700585
Sebastien Hertzcbc50642015-06-01 17:33:12 +0200586 /*
587 * Invoke support
588 */
589
590 // Called by the JDWP thread to prepare invocation in the event thread (suspended on an event).
591 // If the information sent by the debugger is incorrect, it will send a reply with the
592 // appropriate error code. Otherwise, it will attach a DebugInvokeReq object to the event thread
593 // and resume it (and possibly other threads depending on the invoke options).
594 // Unlike other commands, the JDWP thread will not send the reply to the debugger (see
595 // JdwpState::ProcessRequest). The reply will be sent by the event thread itself after method
596 // invocation completes (see FinishInvokeMethod). This is required to allow the JDWP thread to
597 // process incoming commands from the debugger while the invocation is still in progress in the
598 // event thread, especially if it gets suspended by a debug event occurring in another thread.
599 static JDWP::JdwpError PrepareInvokeMethod(uint32_t request_id, JDWP::ObjectId thread_id,
600 JDWP::ObjectId object_id, JDWP::RefTypeId class_id,
601 JDWP::MethodId method_id, uint32_t arg_count,
602 uint64_t arg_values[], JDWP::JdwpTag* arg_types,
603 uint32_t options)
Mathieu Chartier90443472015-07-16 20:32:27 -0700604 REQUIRES(!Locks::thread_list_lock_, !Locks::thread_suspend_count_lock_)
605 SHARED_REQUIRES(Locks::mutator_lock_);
Sebastien Hertzcbc50642015-06-01 17:33:12 +0200606
607 // Called by the event thread to execute a method prepared by the JDWP thread in the given
608 // DebugInvokeReq object. Once the invocation completes, the event thread attaches a reply
609 // to that DebugInvokeReq object so it can be sent to the debugger only when the event thread
610 // is ready to suspend (see FinishInvokeMethod).
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700611 static void ExecuteMethod(DebugInvokeReq* pReq);
612
Sebastien Hertzcbc50642015-06-01 17:33:12 +0200613 // Called by the event thread to send the reply of the invoke (created in ExecuteMethod)
614 // before suspending itself. This is to ensure the thread is ready to suspend before the
615 // debugger receives the reply.
616 static void FinishInvokeMethod(DebugInvokeReq* pReq);
617
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700618 /*
619 * DDM support.
620 */
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700621 static void DdmSendThreadNotification(Thread* t, uint32_t type)
Mathieu Chartier90443472015-07-16 20:32:27 -0700622 SHARED_REQUIRES(Locks::mutator_lock_);
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100623 static void DdmSetThreadNotification(bool enable)
Mathieu Chartier90443472015-07-16 20:32:27 -0700624 REQUIRES(!Locks::thread_list_lock_);
Ian Rogersc0542af2014-09-03 16:16:56 -0700625 static bool DdmHandlePacket(JDWP::Request* request, uint8_t** pReplyBuf, int* pReplyLen);
Mathieu Chartier90443472015-07-16 20:32:27 -0700626 static void DdmConnected() SHARED_REQUIRES(Locks::mutator_lock_);
627 static void DdmDisconnected() SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700628 static void DdmSendChunk(uint32_t type, const std::vector<uint8_t>& bytes)
Mathieu Chartier90443472015-07-16 20:32:27 -0700629 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700630 static void DdmSendChunk(uint32_t type, size_t len, const uint8_t* buf)
Mathieu Chartier90443472015-07-16 20:32:27 -0700631 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700632 static void DdmSendChunkV(uint32_t type, const iovec* iov, int iov_count)
Mathieu Chartier90443472015-07-16 20:32:27 -0700633 SHARED_REQUIRES(Locks::mutator_lock_);
Elliott Hughes767a1472011-10-26 18:49:02 -0700634
Mathieu Chartierbb87e0f2015-04-03 11:21:55 -0700635 static void VisitRoots(RootVisitor* visitor)
Mathieu Chartier90443472015-07-16 20:32:27 -0700636 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartier3b05e9b2014-03-25 09:29:43 -0700637
Elliott Hughes545a0642011-11-08 19:10:03 -0800638 /*
Man Cao8c2ff642015-05-27 17:25:30 -0700639 * Allocation tracking support.
Elliott Hughes545a0642011-11-08 19:10:03 -0800640 */
Mathieu Chartier90443472015-07-16 20:32:27 -0700641 static void SetAllocTrackingEnabled(bool enabled) REQUIRES(!Locks::alloc_tracker_lock_);
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100642 static jbyteArray GetRecentAllocations()
Mathieu Chartier90443472015-07-16 20:32:27 -0700643 REQUIRES(!Locks::alloc_tracker_lock_) SHARED_REQUIRES(Locks::mutator_lock_);
644 static void DumpRecentAllocations() REQUIRES(!Locks::alloc_tracker_lock_);
Elliott Hughes545a0642011-11-08 19:10:03 -0800645
Elliott Hughes767a1472011-10-26 18:49:02 -0700646 enum HpifWhen {
647 HPIF_WHEN_NEVER = 0,
648 HPIF_WHEN_NOW = 1,
649 HPIF_WHEN_NEXT_GC = 2,
650 HPIF_WHEN_EVERY_GC = 3
651 };
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700652 static int DdmHandleHpifChunk(HpifWhen when)
Mathieu Chartier90443472015-07-16 20:32:27 -0700653 SHARED_REQUIRES(Locks::mutator_lock_);
Elliott Hughes767a1472011-10-26 18:49:02 -0700654
655 enum HpsgWhen {
656 HPSG_WHEN_NEVER = 0,
657 HPSG_WHEN_EVERY_GC = 1,
658 };
659 enum HpsgWhat {
660 HPSG_WHAT_MERGED_OBJECTS = 0,
661 HPSG_WHAT_DISTINCT_OBJECTS = 1,
662 };
663 static bool DdmHandleHpsgNhsgChunk(HpsgWhen when, HpsgWhat what, bool native);
664
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700665 static void DdmSendHeapInfo(HpifWhen reason)
Mathieu Chartier90443472015-07-16 20:32:27 -0700666 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700667 static void DdmSendHeapSegments(bool native)
Mathieu Chartier90443472015-07-16 20:32:27 -0700668 SHARED_REQUIRES(Locks::mutator_lock_);
Elliott Hughes545a0642011-11-08 19:10:03 -0800669
Sebastien Hertz6995c602014-09-09 12:10:13 +0200670 static ObjectRegistry* GetObjectRegistry() {
671 return gRegistry;
672 }
673
674 static JDWP::JdwpTag TagFromObject(const ScopedObjectAccessUnchecked& soa, mirror::Object* o)
Mathieu Chartier90443472015-07-16 20:32:27 -0700675 SHARED_REQUIRES(Locks::mutator_lock_);
Sebastien Hertz6995c602014-09-09 12:10:13 +0200676
677 static JDWP::JdwpTypeTag GetTypeTag(mirror::Class* klass)
Mathieu Chartier90443472015-07-16 20:32:27 -0700678 SHARED_REQUIRES(Locks::mutator_lock_);
Sebastien Hertz6995c602014-09-09 12:10:13 +0200679
Mathieu Chartierc7853442015-03-27 14:35:38 -0700680 static JDWP::FieldId ToFieldId(const ArtField* f)
Mathieu Chartier90443472015-07-16 20:32:27 -0700681 SHARED_REQUIRES(Locks::mutator_lock_);
Sebastien Hertz6995c602014-09-09 12:10:13 +0200682
Mathieu Chartiere401d142015-04-22 13:56:20 -0700683 static void SetJdwpLocation(JDWP::JdwpLocation* location, ArtMethod* m, uint32_t dex_pc)
Mathieu Chartier90443472015-07-16 20:32:27 -0700684 SHARED_REQUIRES(Locks::mutator_lock_)
685 REQUIRES(!Locks::thread_list_lock_, !Locks::thread_suspend_count_lock_);
Sebastien Hertz6995c602014-09-09 12:10:13 +0200686
Mathieu Chartierad466ad2015-01-08 16:28:08 -0800687 static JDWP::JdwpState* GetJdwpState();
688
Mathieu Chartier90443472015-07-16 20:32:27 -0700689 static uint32_t GetInstrumentationEvents() SHARED_REQUIRES(Locks::mutator_lock_) {
Sebastien Hertz9d6bf692015-04-10 12:12:33 +0200690 return instrumentation_events_;
691 }
692
Elliott Hughes545a0642011-11-08 19:10:03 -0800693 private:
Sebastien Hertzcbc50642015-06-01 17:33:12 +0200694 static void ExecuteMethodWithoutPendingException(ScopedObjectAccess& soa, DebugInvokeReq* pReq)
Mathieu Chartier90443472015-07-16 20:32:27 -0700695 SHARED_REQUIRES(Locks::mutator_lock_);
Sebastien Hertzcbc50642015-06-01 17:33:12 +0200696
697 static void BuildInvokeReply(JDWP::ExpandBuf* pReply, uint32_t request_id,
698 JDWP::JdwpTag result_tag, uint64_t result_value,
699 JDWP::ObjectId exception)
Mathieu Chartier90443472015-07-16 20:32:27 -0700700 SHARED_REQUIRES(Locks::mutator_lock_);
Sebastien Hertzcbc50642015-06-01 17:33:12 +0200701
Sebastien Hertz8009f392014-09-01 17:07:11 +0200702 static JDWP::JdwpError GetLocalValue(const StackVisitor& visitor,
703 ScopedObjectAccessUnchecked& soa, int slot,
704 JDWP::JdwpTag tag, uint8_t* buf, size_t width)
Mathieu Chartier90443472015-07-16 20:32:27 -0700705 REQUIRES(!Locks::thread_list_lock_) SHARED_REQUIRES(Locks::mutator_lock_);
Sebastien Hertz8009f392014-09-01 17:07:11 +0200706 static JDWP::JdwpError SetLocalValue(StackVisitor& visitor, int slot, JDWP::JdwpTag tag,
707 uint64_t value, size_t width)
Mathieu Chartier90443472015-07-16 20:32:27 -0700708 REQUIRES(!Locks::thread_list_lock_) SHARED_REQUIRES(Locks::mutator_lock_);
Sebastien Hertz8009f392014-09-01 17:07:11 +0200709
Mathieu Chartier90443472015-07-16 20:32:27 -0700710 static void DdmBroadcast(bool connect) SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700711 static void PostThreadStartOrStop(Thread*, uint32_t)
Mathieu Chartier90443472015-07-16 20:32:27 -0700712 SHARED_REQUIRES(Locks::mutator_lock_);
Elliott Hughesa2155262011-11-16 16:26:58 -0800713
Mathieu Chartiere401d142015-04-22 13:56:20 -0700714 static void PostLocationEvent(ArtMethod* method, int pcOffset,
Sebastien Hertz8379b222014-02-24 17:38:15 +0100715 mirror::Object* thisPtr, int eventFlags,
716 const JValue* return_value)
Mathieu Chartier90443472015-07-16 20:32:27 -0700717 SHARED_REQUIRES(Locks::mutator_lock_);
Sebastien Hertz8379b222014-02-24 17:38:15 +0100718
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100719 static void ProcessDeoptimizationRequest(const DeoptimizationRequest& request)
Mathieu Chartier90443472015-07-16 20:32:27 -0700720 REQUIRES(Locks::mutator_lock_);
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100721
Sebastien Hertz7ec2f1c2014-03-27 20:06:47 +0100722 static void RequestDeoptimizationLocked(const DeoptimizationRequest& req)
Mathieu Chartier90443472015-07-16 20:32:27 -0700723 REQUIRES(Locks::deoptimization_lock_) SHARED_REQUIRES(Locks::mutator_lock_);
Sebastien Hertz7ec2f1c2014-03-27 20:06:47 +0100724
Mathieu Chartiere401d142015-04-22 13:56:20 -0700725 static bool IsForcedInterpreterNeededForCallingImpl(Thread* thread, ArtMethod* m)
Mathieu Chartier90443472015-07-16 20:32:27 -0700726 SHARED_REQUIRES(Locks::mutator_lock_);
Daniel Mihalyieb076692014-08-22 17:33:31 +0200727
Mathieu Chartiere401d142015-04-22 13:56:20 -0700728 static bool IsForcedInterpreterNeededForResolutionImpl(Thread* thread, ArtMethod* m)
Mathieu Chartier90443472015-07-16 20:32:27 -0700729 SHARED_REQUIRES(Locks::mutator_lock_);
Daniel Mihalyieb076692014-08-22 17:33:31 +0200730
Mathieu Chartiere401d142015-04-22 13:56:20 -0700731 static bool IsForcedInstrumentationNeededForResolutionImpl(Thread* thread, ArtMethod* m)
Mathieu Chartier90443472015-07-16 20:32:27 -0700732 SHARED_REQUIRES(Locks::mutator_lock_);
Daniel Mihalyieb076692014-08-22 17:33:31 +0200733
Mathieu Chartiere401d142015-04-22 13:56:20 -0700734 static bool IsForcedInterpreterNeededForUpcallImpl(Thread* thread, ArtMethod* m)
Mathieu Chartier90443472015-07-16 20:32:27 -0700735 SHARED_REQUIRES(Locks::mutator_lock_);
Daniel Mihalyieb076692014-08-22 17:33:31 +0200736
Daniel Mihalyieb076692014-08-22 17:33:31 +0200737 // Indicates whether the debugger is making requests.
738 static bool gDebuggerActive;
739
Sebastien Hertz4e5b2082015-03-24 19:03:40 +0100740 // Indicates whether we should drop the JDWP connection because the runtime stops or the
741 // debugger called VirtualMachine.Dispose.
742 static bool gDisposed;
743
Daniel Mihalyieb076692014-08-22 17:33:31 +0200744 // The registry mapping objects to JDWP ids.
Sebastien Hertz6995c602014-09-09 12:10:13 +0200745 static ObjectRegistry* gRegistry;
746
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100747 // Deoptimization requests to be processed each time the event list is updated. This is used when
748 // registering and unregistering events so we do not deoptimize while holding the event list
749 // lock.
Sebastien Hertz42cd43f2014-05-13 14:15:41 +0200750 // TODO rename to instrumentation_requests.
Brian Carlstrom306db812014-09-05 13:01:41 -0700751 static std::vector<DeoptimizationRequest> deoptimization_requests_ GUARDED_BY(Locks::deoptimization_lock_);
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100752
753 // Count the number of events requiring full deoptimization. When the counter is > 0, everything
754 // is deoptimized, otherwise everything is undeoptimized.
755 // Note: we fully deoptimize on the first event only (when the counter is set to 1). We fully
756 // undeoptimize when the last event is unregistered (when the counter is set to 0).
Brian Carlstrom306db812014-09-05 13:01:41 -0700757 static size_t full_deoptimization_event_count_ GUARDED_BY(Locks::deoptimization_lock_);
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100758
Sebastien Hertz42cd43f2014-05-13 14:15:41 +0200759 static size_t* GetReferenceCounterForEvent(uint32_t instrumentation_event);
760
761 // Instrumentation event reference counters.
762 // TODO we could use an array instead of having all these dedicated counters. Instrumentation
763 // events are bits of a mask so we could convert them to array index.
Brian Carlstrom306db812014-09-05 13:01:41 -0700764 static size_t dex_pc_change_event_ref_count_ GUARDED_BY(Locks::deoptimization_lock_);
765 static size_t method_enter_event_ref_count_ GUARDED_BY(Locks::deoptimization_lock_);
766 static size_t method_exit_event_ref_count_ GUARDED_BY(Locks::deoptimization_lock_);
767 static size_t field_read_event_ref_count_ GUARDED_BY(Locks::deoptimization_lock_);
768 static size_t field_write_event_ref_count_ GUARDED_BY(Locks::deoptimization_lock_);
769 static size_t exception_catch_event_ref_count_ GUARDED_BY(Locks::deoptimization_lock_);
Sebastien Hertz42cd43f2014-05-13 14:15:41 +0200770 static uint32_t instrumentation_events_ GUARDED_BY(Locks::mutator_lock_);
771
Ian Rogers719d1a32014-03-06 12:13:39 -0800772 DISALLOW_COPY_AND_ASSIGN(Dbg);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700773};
774
775#define CHUNK_TYPE(_name) \
Elliott Hughes82188472011-11-07 18:11:48 -0800776 static_cast<uint32_t>((_name)[0] << 24 | (_name)[1] << 16 | (_name)[2] << 8 | (_name)[3])
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700777
778} // namespace art
779
Brian Carlstromfc0e3212013-07-17 14:40:12 -0700780#endif // ART_RUNTIME_DEBUGGER_H_