blob: e908304977e723278ef0deb206224862ce5a9b4e [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"
Mingyao Yang99170c62015-07-06 11:10:37 -070034#include "thread.h"
Jeff Hao920af3e2013-08-28 15:46:38 -070035#include "thread_state.h"
Elliott Hughes872d4ec2011-10-21 17:07:15 -070036
37namespace art {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080038namespace mirror {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080039class Class;
40class Object;
41class Throwable;
42} // namespace mirror
Mathieu Chartierc7853442015-03-27 14:35:38 -070043class ArtField;
Mathieu Chartiere401d142015-04-22 13:56:20 -070044class ArtMethod;
Sebastien Hertz6995c602014-09-09 12:10:13 +020045class ObjectRegistry;
Sebastien Hertzcbc50642015-06-01 17:33:12 +020046class ScopedObjectAccess;
Sebastien Hertz6995c602014-09-09 12:10:13 +020047class ScopedObjectAccessUnchecked;
Sebastien Hertz8009f392014-09-01 17:07:11 +020048class StackVisitor;
Ian Rogers1b09b092012-08-20 15:35:52 -070049class Thread;
Elliott Hughes872d4ec2011-10-21 17:07:15 -070050
51/*
52 * Invoke-during-breakpoint support.
53 */
54struct DebugInvokeReq {
Sebastien Hertzcbc50642015-06-01 17:33:12 +020055 DebugInvokeReq(uint32_t invoke_request_id, JDWP::ObjectId invoke_thread_id,
56 mirror::Object* invoke_receiver, mirror::Class* invoke_class,
Mathieu Chartiere401d142015-04-22 13:56:20 -070057 ArtMethod* invoke_method, uint32_t invoke_options,
Sebastien Hertzcbc50642015-06-01 17:33:12 +020058 uint64_t args[], uint32_t args_count)
59 : request_id(invoke_request_id), thread_id(invoke_thread_id), receiver(invoke_receiver),
60 klass(invoke_class), method(invoke_method), arg_count(args_count), arg_values(args),
61 options(invoke_options), reply(JDWP::expandBufAlloc()) {
Elliott Hughes475fc232011-10-25 15:00:35 -070062 }
63
Sebastien Hertzcbc50642015-06-01 17:33:12 +020064 ~DebugInvokeReq() {
65 JDWP::expandBufFree(reply);
66 }
67
68 // Request
69 const uint32_t request_id;
70 const JDWP::ObjectId thread_id;
71 GcRoot<mirror::Object> receiver; // not used for ClassType.InvokeMethod.
Sebastien Hertz1558b572015-02-25 15:05:59 +010072 GcRoot<mirror::Class> klass;
Sebastien Hertzcbc50642015-06-01 17:33:12 +020073 ArtMethod* const method;
Sebastien Hertz1558b572015-02-25 15:05:59 +010074 const uint32_t arg_count;
Sebastien Hertzcbc50642015-06-01 17:33:12 +020075 std::unique_ptr<uint64_t[]> arg_values; // will be null if arg_count_ == 0. We take ownership
76 // of this array so we must delete it upon destruction.
Sebastien Hertz1558b572015-02-25 15:05:59 +010077 const uint32_t options;
Elliott Hughes872d4ec2011-10-21 17:07:15 -070078
Sebastien Hertzcbc50642015-06-01 17:33:12 +020079 // Reply
80 JDWP::ExpandBuf* const reply;
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +010081
Mathieu Chartierbb87e0f2015-04-03 11:21:55 -070082 void VisitRoots(RootVisitor* visitor, const RootInfo& root_info)
Mathieu Chartier90443472015-07-16 20:32:27 -070083 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartier3b05e9b2014-03-25 09:29:43 -070084
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +010085 private:
86 DISALLOW_COPY_AND_ASSIGN(DebugInvokeReq);
87};
88
89// Thread local data-structure that holds fields for controlling single-stepping.
Sebastien Hertz597c4f02015-01-26 17:37:14 +010090class SingleStepControl {
91 public:
92 SingleStepControl(JDWP::JdwpStepSize step_size, JDWP::JdwpStepDepth step_depth,
Mathieu Chartiere401d142015-04-22 13:56:20 -070093 int stack_depth, ArtMethod* method)
Sebastien Hertz597c4f02015-01-26 17:37:14 +010094 : step_size_(step_size), step_depth_(step_depth),
95 stack_depth_(stack_depth), method_(method) {
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +010096 }
97
Sebastien Hertz597c4f02015-01-26 17:37:14 +010098 JDWP::JdwpStepSize GetStepSize() const {
99 return step_size_;
100 }
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +0100101
Sebastien Hertz597c4f02015-01-26 17:37:14 +0100102 JDWP::JdwpStepDepth GetStepDepth() const {
103 return step_depth_;
104 }
105
106 int GetStackDepth() const {
107 return stack_depth_;
108 }
109
Mathieu Chartiere401d142015-04-22 13:56:20 -0700110 ArtMethod* GetMethod() const {
111 return method_;
Sebastien Hertz597c4f02015-01-26 17:37:14 +0100112 }
113
114 const std::set<uint32_t>& GetDexPcs() const {
115 return dex_pcs_;
116 }
117
Sebastien Hertz597c4f02015-01-26 17:37:14 +0100118 void AddDexPc(uint32_t dex_pc);
119
120 bool ContainsDexPc(uint32_t dex_pc) const;
121
122 private:
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +0100123 // See JdwpStepSize and JdwpStepDepth for details.
Sebastien Hertz597c4f02015-01-26 17:37:14 +0100124 const JDWP::JdwpStepSize step_size_;
125 const JDWP::JdwpStepDepth step_depth_;
126
127 // The stack depth when this single-step was initiated. This is used to support SD_OVER and SD_OUT
128 // single-step depth.
129 const int stack_depth_;
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +0100130
131 // The location this single-step was initiated from.
132 // A single-step is initiated in a suspended thread. We save here the current method and the
133 // set of DEX pcs associated to the source line number where the suspension occurred.
134 // This is used to support SD_INTO and SD_OVER single-step depths so we detect when a single-step
135 // causes the execution of an instruction in a different method or at a different line number.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700136 ArtMethod* method_;
137
Sebastien Hertz597c4f02015-01-26 17:37:14 +0100138 std::set<uint32_t> dex_pcs_;
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +0100139
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +0100140 DISALLOW_COPY_AND_ASSIGN(SingleStepControl);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700141};
142
Sebastien Hertz42cd43f2014-05-13 14:15:41 +0200143// TODO rename to InstrumentationRequest.
Hiroshi Yamauchi0ec17d22014-07-07 13:07:08 -0700144class DeoptimizationRequest {
145 public:
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100146 enum Kind {
147 kNothing, // no action.
Sebastien Hertz42cd43f2014-05-13 14:15:41 +0200148 kRegisterForEvent, // start listening for instrumentation event.
149 kUnregisterForEvent, // stop listening for instrumentation event.
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100150 kFullDeoptimization, // deoptimize everything.
151 kFullUndeoptimization, // undeoptimize everything.
152 kSelectiveDeoptimization, // deoptimize one method.
153 kSelectiveUndeoptimization // undeoptimize one method.
154 };
155
Hiroshi Yamauchi0ec17d22014-07-07 13:07:08 -0700156 DeoptimizationRequest() : kind_(kNothing), instrumentation_event_(0), method_(nullptr) {}
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100157
Hiroshi Yamauchi0ec17d22014-07-07 13:07:08 -0700158 DeoptimizationRequest(const DeoptimizationRequest& other)
Mathieu Chartier90443472015-07-16 20:32:27 -0700159 SHARED_REQUIRES(Locks::mutator_lock_)
Hiroshi Yamauchi0ec17d22014-07-07 13:07:08 -0700160 : kind_(other.kind_), instrumentation_event_(other.instrumentation_event_) {
161 // Create a new JNI global reference for the method.
162 SetMethod(other.Method());
163 }
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100164
Mathieu Chartier90443472015-07-16 20:32:27 -0700165 ArtMethod* Method() const SHARED_REQUIRES(Locks::mutator_lock_);
Hiroshi Yamauchi0ec17d22014-07-07 13:07:08 -0700166
Mathieu Chartier90443472015-07-16 20:32:27 -0700167 void SetMethod(ArtMethod* m) SHARED_REQUIRES(Locks::mutator_lock_);
Hiroshi Yamauchi0ec17d22014-07-07 13:07:08 -0700168
169 // Name 'Kind()' would collide with the above enum name.
170 Kind GetKind() const {
171 return kind_;
172 }
173
174 void SetKind(Kind kind) {
175 kind_ = kind;
176 }
177
178 uint32_t InstrumentationEvent() const {
179 return instrumentation_event_;
180 }
181
182 void SetInstrumentationEvent(uint32_t instrumentation_event) {
183 instrumentation_event_ = instrumentation_event;
184 }
185
186 private:
187 Kind kind_;
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100188
Sebastien Hertz42cd43f2014-05-13 14:15:41 +0200189 // TODO we could use a union to hold the instrumentation_event and the method since they
190 // respectively have sense only for kRegisterForEvent/kUnregisterForEvent and
191 // kSelectiveDeoptimization/kSelectiveUndeoptimization.
192
193 // Event to start or stop listening to. Only for kRegisterForEvent and kUnregisterForEvent.
Hiroshi Yamauchi0ec17d22014-07-07 13:07:08 -0700194 uint32_t instrumentation_event_;
Sebastien Hertz42cd43f2014-05-13 14:15:41 +0200195
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100196 // Method for selective deoptimization.
Hiroshi Yamauchi0ec17d22014-07-07 13:07:08 -0700197 jmethodID method_;
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100198};
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700199std::ostream& operator<<(std::ostream& os, const DeoptimizationRequest::Kind& rhs);
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100200
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700201class Dbg {
Elliott Hughesff17f1f2012-01-24 18:12:29 -0800202 public:
Elliott Hughes4ffd3132011-10-24 12:06:42 -0700203 static void SetJdwpAllowed(bool allowed);
204
Sebastien Hertzb3b173b2015-02-06 09:16:32 +0100205 static void StartJdwp();
Elliott Hughesd1cc8362011-10-24 16:58:50 -0700206 static void StopJdwp();
207
Elliott Hughes767a1472011-10-26 18:49:02 -0700208 // Invoked by the GC in case we need to keep DDMS informed.
Mathieu Chartier90443472015-07-16 20:32:27 -0700209 static void GcDidFinish() REQUIRES(!Locks::mutator_lock_);
Elliott Hughes767a1472011-10-26 18:49:02 -0700210
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700211 // Return the DebugInvokeReq for the current thread.
212 static DebugInvokeReq* GetInvokeReq();
213
Elliott Hughes475fc232011-10-25 15:00:35 -0700214 static Thread* GetDebugThread();
215 static void ClearWaitForEventThread();
216
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700217 /*
218 * Enable/disable breakpoints and step modes. Used to provide a heads-up
219 * when the debugger attaches.
220 */
221 static void Connected();
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100222 static void GoActive()
Mathieu Chartier90443472015-07-16 20:32:27 -0700223 REQUIRES(!Locks::breakpoint_lock_, !Locks::deoptimization_lock_, !Locks::mutator_lock_);
224 static void Disconnected() REQUIRES(!Locks::deoptimization_lock_, !Locks::mutator_lock_);
Sebastien Hertz4e5b2082015-03-24 19:03:40 +0100225 static void Dispose() {
226 gDisposed = true;
227 }
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700228
Elliott Hughesc0f09332012-03-26 13:27:06 -0700229 // Returns true if we're actually debugging with a real debugger, false if it's
230 // just DDMS (or nothing at all).
Daniel Mihalyieb076692014-08-22 17:33:31 +0200231 static bool IsDebuggerActive() {
232 return gDebuggerActive;
233 }
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700234
Sebastien Hertzb3b173b2015-02-06 09:16:32 +0100235 // Configures JDWP with parsed command-line options.
236 static void ConfigureJdwp(const JDWP::JdwpOptions& jdwp_options);
237
Elliott Hughesc0f09332012-03-26 13:27:06 -0700238 // Returns true if we had -Xrunjdwp or -agentlib:jdwp= on the command line.
239 static bool IsJdwpConfigured();
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700240
Mathieu Chartierd8565452015-03-26 09:41:50 -0700241 // Returns true if a method has any breakpoints.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700242 static bool MethodHasAnyBreakpoints(ArtMethod* method)
Mathieu Chartier90443472015-07-16 20:32:27 -0700243 SHARED_REQUIRES(Locks::mutator_lock_) REQUIRES(!Locks::breakpoint_lock_);
Mathieu Chartierd8565452015-03-26 09:41:50 -0700244
Sebastien Hertz4e5b2082015-03-24 19:03:40 +0100245 static bool IsDisposed() {
246 return gDisposed;
247 }
Elliott Hughes86964332012-02-15 19:37:42 -0800248
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700249 /*
250 * Time, in milliseconds, since the last debugger activity. Does not
251 * include DDMS activity. Returns -1 if there has been no activity.
252 * Returns 0 if we're in the middle of handling a debugger request.
253 */
254 static int64_t LastDebuggerActivity();
255
Sebastien Hertz253fa552014-10-14 17:27:15 +0200256 static void UndoDebuggerSuspensions()
Mathieu Chartier90443472015-07-16 20:32:27 -0700257 REQUIRES(!Locks::thread_list_lock_, !Locks::thread_suspend_count_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700258
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700259 /*
260 * Class, Object, Array
261 */
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700262 static std::string GetClassName(JDWP::RefTypeId id)
Mathieu Chartier90443472015-07-16 20:32:27 -0700263 SHARED_REQUIRES(Locks::mutator_lock_);
Sebastien Hertz6995c602014-09-09 12:10:13 +0200264 static std::string GetClassName(mirror::Class* klass)
Mathieu Chartier90443472015-07-16 20:32:27 -0700265 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogersc0542af2014-09-03 16:16:56 -0700266 static JDWP::JdwpError GetClassObject(JDWP::RefTypeId id, JDWP::ObjectId* class_object_id)
Mathieu Chartier90443472015-07-16 20:32:27 -0700267 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogersc0542af2014-09-03 16:16:56 -0700268 static JDWP::JdwpError GetSuperclass(JDWP::RefTypeId id, JDWP::RefTypeId* superclass_id)
Mathieu Chartier90443472015-07-16 20:32:27 -0700269 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700270 static JDWP::JdwpError GetClassLoader(JDWP::RefTypeId id, JDWP::ExpandBuf* pReply)
Mathieu Chartier90443472015-07-16 20:32:27 -0700271 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700272 static JDWP::JdwpError GetModifiers(JDWP::RefTypeId id, JDWP::ExpandBuf* pReply)
Mathieu Chartier90443472015-07-16 20:32:27 -0700273 SHARED_REQUIRES(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800274 static JDWP::JdwpError GetReflectedType(JDWP::RefTypeId class_id, JDWP::ExpandBuf* pReply)
Mathieu Chartier90443472015-07-16 20:32:27 -0700275 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogersc0542af2014-09-03 16:16:56 -0700276 static void GetClassList(std::vector<JDWP::RefTypeId>* classes)
Mathieu Chartier90443472015-07-16 20:32:27 -0700277 SHARED_REQUIRES(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800278 static JDWP::JdwpError GetClassInfo(JDWP::RefTypeId class_id, JDWP::JdwpTypeTag* pTypeTag,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700279 uint32_t* pStatus, std::string* pDescriptor)
Mathieu Chartier90443472015-07-16 20:32:27 -0700280 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogersc0542af2014-09-03 16:16:56 -0700281 static void FindLoadedClassBySignature(const char* descriptor, std::vector<JDWP::RefTypeId>* ids)
Mathieu Chartier90443472015-07-16 20:32:27 -0700282 SHARED_REQUIRES(Locks::mutator_lock_);
Elliott Hughes64f574f2013-02-20 14:57:12 -0800283 static JDWP::JdwpError GetReferenceType(JDWP::ObjectId object_id, JDWP::ExpandBuf* pReply)
Mathieu Chartier90443472015-07-16 20:32:27 -0700284 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogersfc0e94b2013-09-23 23:51:32 -0700285 static JDWP::JdwpError GetSignature(JDWP::RefTypeId ref_type_id, std::string* signature)
Mathieu Chartier90443472015-07-16 20:32:27 -0700286 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogersc0542af2014-09-03 16:16:56 -0700287 static JDWP::JdwpError GetSourceFile(JDWP::RefTypeId ref_type_id, std::string* source_file)
Mathieu Chartier90443472015-07-16 20:32:27 -0700288 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogersc0542af2014-09-03 16:16:56 -0700289 static JDWP::JdwpError GetObjectTag(JDWP::ObjectId object_id, uint8_t* tag)
Mathieu Chartier90443472015-07-16 20:32:27 -0700290 SHARED_REQUIRES(Locks::mutator_lock_);
Elliott Hughesaed4be92011-12-02 16:16:23 -0800291 static size_t GetTagWidth(JDWP::JdwpTag tag);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700292
Ian Rogersc0542af2014-09-03 16:16:56 -0700293 static JDWP::JdwpError GetArrayLength(JDWP::ObjectId array_id, int32_t* length)
Mathieu Chartier90443472015-07-16 20:32:27 -0700294 SHARED_REQUIRES(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800295 static JDWP::JdwpError OutputArray(JDWP::ObjectId array_id, int offset, int count,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700296 JDWP::ExpandBuf* pReply)
Mathieu Chartier90443472015-07-16 20:32:27 -0700297 SHARED_REQUIRES(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800298 static JDWP::JdwpError SetArrayElements(JDWP::ObjectId array_id, int offset, int count,
Ian Rogersc0542af2014-09-03 16:16:56 -0700299 JDWP::Request* request)
Mathieu Chartier90443472015-07-16 20:32:27 -0700300 SHARED_REQUIRES(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700301
Sebastien Hertz2c3e77a2015-04-02 16:26:48 +0200302 static JDWP::JdwpError CreateString(const std::string& str, JDWP::ObjectId* new_string_id)
Mathieu Chartier90443472015-07-16 20:32:27 -0700303 SHARED_REQUIRES(Locks::mutator_lock_);
Sebastien Hertz2c3e77a2015-04-02 16:26:48 +0200304 static JDWP::JdwpError CreateObject(JDWP::RefTypeId class_id, JDWP::ObjectId* new_object_id)
Mathieu Chartier90443472015-07-16 20:32:27 -0700305 SHARED_REQUIRES(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800306 static JDWP::JdwpError CreateArrayObject(JDWP::RefTypeId array_class_id, uint32_t length,
Sebastien Hertz2c3e77a2015-04-02 16:26:48 +0200307 JDWP::ObjectId* new_array_id)
Mathieu Chartier90443472015-07-16 20:32:27 -0700308 SHARED_REQUIRES(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700309
Sebastien Hertz6995c602014-09-09 12:10:13 +0200310 //
311 // Event filtering.
312 //
313 static bool MatchThread(JDWP::ObjectId expected_thread_id, Thread* event_thread)
Mathieu Chartier90443472015-07-16 20:32:27 -0700314 SHARED_REQUIRES(Locks::mutator_lock_);
Sebastien Hertz6995c602014-09-09 12:10:13 +0200315
316 static bool MatchLocation(const JDWP::JdwpLocation& expected_location,
317 const JDWP::EventLocation& event_location)
Mathieu Chartier90443472015-07-16 20:32:27 -0700318 SHARED_REQUIRES(Locks::mutator_lock_);
Sebastien Hertz6995c602014-09-09 12:10:13 +0200319
320 static bool MatchType(mirror::Class* event_class, JDWP::RefTypeId class_id)
Mathieu Chartier90443472015-07-16 20:32:27 -0700321 SHARED_REQUIRES(Locks::mutator_lock_);
Sebastien Hertz6995c602014-09-09 12:10:13 +0200322
323 static bool MatchField(JDWP::RefTypeId expected_type_id, JDWP::FieldId expected_field_id,
Mathieu Chartierc7853442015-03-27 14:35:38 -0700324 ArtField* event_field)
Mathieu Chartier90443472015-07-16 20:32:27 -0700325 SHARED_REQUIRES(Locks::mutator_lock_);
Sebastien Hertz6995c602014-09-09 12:10:13 +0200326
327 static bool MatchInstance(JDWP::ObjectId expected_instance_id, mirror::Object* event_instance)
Mathieu Chartier90443472015-07-16 20:32:27 -0700328 SHARED_REQUIRES(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700329
Elliott Hughesec0f83d2013-01-15 16:54:08 -0800330 //
331 // Monitors.
332 //
333 static JDWP::JdwpError GetMonitorInfo(JDWP::ObjectId object_id, JDWP::ExpandBuf* reply)
Mathieu Chartier90443472015-07-16 20:32:27 -0700334 SHARED_REQUIRES(Locks::mutator_lock_);
Elliott Hughesec0f83d2013-01-15 16:54:08 -0800335 static JDWP::JdwpError GetOwnedMonitors(JDWP::ObjectId thread_id,
Ian Rogersc0542af2014-09-03 16:16:56 -0700336 std::vector<JDWP::ObjectId>* monitors,
337 std::vector<uint32_t>* stack_depths)
Mathieu Chartier90443472015-07-16 20:32:27 -0700338 REQUIRES(!Locks::thread_list_lock_) SHARED_REQUIRES(Locks::mutator_lock_);
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100339 static JDWP::JdwpError GetContendedMonitor(JDWP::ObjectId thread_id,
Ian Rogersc0542af2014-09-03 16:16:56 -0700340 JDWP::ObjectId* contended_monitor)
Mathieu Chartier90443472015-07-16 20:32:27 -0700341 REQUIRES(!Locks::thread_list_lock_) SHARED_REQUIRES(Locks::mutator_lock_);
Elliott Hughesec0f83d2013-01-15 16:54:08 -0800342
343 //
344 // Heap.
345 //
346 static JDWP::JdwpError GetInstanceCounts(const std::vector<JDWP::RefTypeId>& class_ids,
Ian Rogersc0542af2014-09-03 16:16:56 -0700347 std::vector<uint64_t>* counts)
Mathieu Chartier90443472015-07-16 20:32:27 -0700348 SHARED_REQUIRES(Locks::mutator_lock_);
Elliott Hughes3b78c942013-01-15 17:35:41 -0800349 static JDWP::JdwpError GetInstances(JDWP::RefTypeId class_id, int32_t max_count,
Ian Rogersc0542af2014-09-03 16:16:56 -0700350 std::vector<JDWP::ObjectId>* instances)
Mathieu Chartier90443472015-07-16 20:32:27 -0700351 SHARED_REQUIRES(Locks::mutator_lock_);
Elliott Hughes0cbaff52013-01-16 15:28:01 -0800352 static JDWP::JdwpError GetReferringObjects(JDWP::ObjectId object_id, int32_t max_count,
Ian Rogersc0542af2014-09-03 16:16:56 -0700353 std::vector<JDWP::ObjectId>* referring_objects)
Mathieu Chartier90443472015-07-16 20:32:27 -0700354 SHARED_REQUIRES(Locks::mutator_lock_);
Elliott Hughes64f574f2013-02-20 14:57:12 -0800355 static JDWP::JdwpError DisableCollection(JDWP::ObjectId object_id)
Mathieu Chartier90443472015-07-16 20:32:27 -0700356 SHARED_REQUIRES(Locks::mutator_lock_);
Elliott Hughes64f574f2013-02-20 14:57:12 -0800357 static JDWP::JdwpError EnableCollection(JDWP::ObjectId object_id)
Mathieu Chartier90443472015-07-16 20:32:27 -0700358 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogersc0542af2014-09-03 16:16:56 -0700359 static JDWP::JdwpError IsCollected(JDWP::ObjectId object_id, bool* is_collected)
Mathieu Chartier90443472015-07-16 20:32:27 -0700360 SHARED_REQUIRES(Locks::mutator_lock_);
Elliott Hughes64f574f2013-02-20 14:57:12 -0800361 static void DisposeObject(JDWP::ObjectId object_id, uint32_t reference_count)
Mathieu Chartier90443472015-07-16 20:32:27 -0700362 SHARED_REQUIRES(Locks::mutator_lock_);
Elliott Hughesec0f83d2013-01-15 16:54:08 -0800363
Elliott Hughes9777ba22013-01-17 09:04:19 -0800364 //
365 // Methods and fields.
366 //
Elliott Hughesa96836a2013-01-17 12:27:49 -0800367 static std::string GetMethodName(JDWP::MethodId method_id)
Mathieu Chartier90443472015-07-16 20:32:27 -0700368 SHARED_REQUIRES(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800369 static JDWP::JdwpError OutputDeclaredFields(JDWP::RefTypeId ref_type_id, bool with_generic,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700370 JDWP::ExpandBuf* pReply)
Mathieu Chartier90443472015-07-16 20:32:27 -0700371 SHARED_REQUIRES(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800372 static JDWP::JdwpError OutputDeclaredMethods(JDWP::RefTypeId ref_type_id, bool with_generic,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700373 JDWP::ExpandBuf* pReply)
Mathieu Chartier90443472015-07-16 20:32:27 -0700374 SHARED_REQUIRES(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800375 static JDWP::JdwpError OutputDeclaredInterfaces(JDWP::RefTypeId ref_type_id,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700376 JDWP::ExpandBuf* pReply)
Mathieu Chartier90443472015-07-16 20:32:27 -0700377 SHARED_REQUIRES(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800378 static void OutputLineTable(JDWP::RefTypeId ref_type_id, JDWP::MethodId method_id,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700379 JDWP::ExpandBuf* pReply)
Mathieu Chartier90443472015-07-16 20:32:27 -0700380 SHARED_REQUIRES(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800381 static void OutputVariableTable(JDWP::RefTypeId ref_type_id, JDWP::MethodId id, bool with_generic,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700382 JDWP::ExpandBuf* pReply)
Mathieu Chartier90443472015-07-16 20:32:27 -0700383 SHARED_REQUIRES(Locks::mutator_lock_);
Jeff Hao579b0242013-11-18 13:16:49 -0800384 static void OutputMethodReturnValue(JDWP::MethodId method_id, const JValue* return_value,
385 JDWP::ExpandBuf* pReply)
Mathieu Chartier90443472015-07-16 20:32:27 -0700386 SHARED_REQUIRES(Locks::mutator_lock_);
Sebastien Hertz3f52eaf2014-04-04 17:50:18 +0200387 static void OutputFieldValue(JDWP::FieldId field_id, const JValue* field_value,
388 JDWP::ExpandBuf* pReply)
Mathieu Chartier90443472015-07-16 20:32:27 -0700389 SHARED_REQUIRES(Locks::mutator_lock_);
Elliott Hughes9777ba22013-01-17 09:04:19 -0800390 static JDWP::JdwpError GetBytecodes(JDWP::RefTypeId class_id, JDWP::MethodId method_id,
Ian Rogersc0542af2014-09-03 16:16:56 -0700391 std::vector<uint8_t>* bytecodes)
Mathieu Chartier90443472015-07-16 20:32:27 -0700392 SHARED_REQUIRES(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700393
Elliott Hughesa96836a2013-01-17 12:27:49 -0800394 static std::string GetFieldName(JDWP::FieldId field_id)
Mathieu Chartier90443472015-07-16 20:32:27 -0700395 SHARED_REQUIRES(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800396 static JDWP::JdwpTag GetFieldBasicTag(JDWP::FieldId field_id)
Mathieu Chartier90443472015-07-16 20:32:27 -0700397 SHARED_REQUIRES(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800398 static JDWP::JdwpTag GetStaticFieldBasicTag(JDWP::FieldId field_id)
Mathieu Chartier90443472015-07-16 20:32:27 -0700399 SHARED_REQUIRES(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800400 static JDWP::JdwpError GetFieldValue(JDWP::ObjectId object_id, JDWP::FieldId field_id,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700401 JDWP::ExpandBuf* pReply)
Mathieu Chartier90443472015-07-16 20:32:27 -0700402 SHARED_REQUIRES(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800403 static JDWP::JdwpError SetFieldValue(JDWP::ObjectId object_id, JDWP::FieldId field_id,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700404 uint64_t value, int width)
Mathieu Chartier90443472015-07-16 20:32:27 -0700405 SHARED_REQUIRES(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800406 static JDWP::JdwpError GetStaticFieldValue(JDWP::RefTypeId ref_type_id, JDWP::FieldId field_id,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700407 JDWP::ExpandBuf* pReply)
Mathieu Chartier90443472015-07-16 20:32:27 -0700408 SHARED_REQUIRES(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800409 static JDWP::JdwpError SetStaticFieldValue(JDWP::FieldId field_id, uint64_t value, int width)
Mathieu Chartier90443472015-07-16 20:32:27 -0700410 SHARED_REQUIRES(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700411
Sebastien Hertzb0b0b492014-09-15 11:27:27 +0200412 static JDWP::JdwpError StringToUtf8(JDWP::ObjectId string_id, std::string* str)
Mathieu Chartier90443472015-07-16 20:32:27 -0700413 SHARED_REQUIRES(Locks::mutator_lock_);
Jeff Hao579b0242013-11-18 13:16:49 -0800414 static void OutputJValue(JDWP::JdwpTag tag, const JValue* return_value, JDWP::ExpandBuf* pReply)
Mathieu Chartier90443472015-07-16 20:32:27 -0700415 SHARED_REQUIRES(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700416
417 /*
418 * Thread, ThreadGroup, Frame
419 */
Ian Rogersc0542af2014-09-03 16:16:56 -0700420 static JDWP::JdwpError GetThreadName(JDWP::ObjectId thread_id, std::string* name)
Mathieu Chartier90443472015-07-16 20:32:27 -0700421 SHARED_REQUIRES(Locks::mutator_lock_) REQUIRES(!Locks::thread_list_lock_);
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100422 static JDWP::JdwpError GetThreadGroup(JDWP::ObjectId thread_id, JDWP::ExpandBuf* pReply)
Mathieu Chartier90443472015-07-16 20:32:27 -0700423 SHARED_REQUIRES(Locks::mutator_lock_) REQUIRES(!Locks::thread_list_lock_);
Sebastien Hertza06430c2014-09-15 19:21:30 +0200424 static JDWP::JdwpError GetThreadGroupName(JDWP::ObjectId thread_group_id,
425 JDWP::ExpandBuf* pReply)
Mathieu Chartier90443472015-07-16 20:32:27 -0700426 SHARED_REQUIRES(Locks::mutator_lock_);
Sebastien Hertza06430c2014-09-15 19:21:30 +0200427 static JDWP::JdwpError GetThreadGroupParent(JDWP::ObjectId thread_group_id,
428 JDWP::ExpandBuf* pReply)
Mathieu Chartier90443472015-07-16 20:32:27 -0700429 SHARED_REQUIRES(Locks::mutator_lock_);
Sebastien Hertza06430c2014-09-15 19:21:30 +0200430 static JDWP::JdwpError GetThreadGroupChildren(JDWP::ObjectId thread_group_id,
431 JDWP::ExpandBuf* pReply)
Mathieu Chartier90443472015-07-16 20:32:27 -0700432 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700433 static JDWP::ObjectId GetSystemThreadGroupId()
Mathieu Chartier90443472015-07-16 20:32:27 -0700434 SHARED_REQUIRES(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700435
Jeff Hao920af3e2013-08-28 15:46:38 -0700436 static JDWP::JdwpThreadStatus ToJdwpThreadStatus(ThreadState state);
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100437 static JDWP::JdwpError GetThreadStatus(JDWP::ObjectId thread_id,
438 JDWP::JdwpThreadStatus* pThreadStatus,
439 JDWP::JdwpSuspendStatus* pSuspendStatus)
Mathieu Chartier90443472015-07-16 20:32:27 -0700440 REQUIRES(!Locks::thread_list_lock_);
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100441 static JDWP::JdwpError GetThreadDebugSuspendCount(JDWP::ObjectId thread_id,
442 JDWP::ExpandBuf* pReply)
Mathieu Chartier90443472015-07-16 20:32:27 -0700443 REQUIRES(!Locks::thread_list_lock_, !Locks::thread_suspend_count_lock_);
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700444 // static void WaitForSuspend(JDWP::ObjectId thread_id);
Elliott Hughescaf76542012-06-28 16:08:22 -0700445
Elliott Hughes026b1462012-06-28 20:43:49 -0700446 // Fills 'thread_ids' with the threads in the given thread group. If thread_group_id == 0,
Elliott Hughescaf76542012-06-28 16:08:22 -0700447 // returns all threads.
Sebastien Hertza06430c2014-09-15 19:21:30 +0200448 static void GetThreads(mirror::Object* thread_group, std::vector<JDWP::ObjectId>* thread_ids)
Mathieu Chartier90443472015-07-16 20:32:27 -0700449 REQUIRES(!Locks::thread_list_lock_) SHARED_REQUIRES(Locks::mutator_lock_);
Elliott Hughescaf76542012-06-28 16:08:22 -0700450
Ian Rogersc0542af2014-09-03 16:16:56 -0700451 static JDWP::JdwpError GetThreadFrameCount(JDWP::ObjectId thread_id, size_t* result)
Mathieu Chartier90443472015-07-16 20:32:27 -0700452 REQUIRES(!Locks::thread_list_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700453 static JDWP::JdwpError GetThreadFrames(JDWP::ObjectId thread_id, size_t start_frame,
454 size_t frame_count, JDWP::ExpandBuf* buf)
Mathieu Chartier90443472015-07-16 20:32:27 -0700455 REQUIRES(!Locks::thread_list_lock_) SHARED_REQUIRES(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700456
Mathieu Chartier90443472015-07-16 20:32:27 -0700457 static JDWP::ObjectId GetThreadSelfId() SHARED_REQUIRES(Locks::mutator_lock_);
458 static JDWP::ObjectId GetThreadId(Thread* thread) SHARED_REQUIRES(Locks::mutator_lock_);
Sebastien Hertz6995c602014-09-09 12:10:13 +0200459
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700460 static void SuspendVM()
Mathieu Chartier90443472015-07-16 20:32:27 -0700461 REQUIRES(!Locks::thread_list_lock_, !Locks::thread_suspend_count_lock_);
Sebastien Hertz253fa552014-10-14 17:27:15 +0200462 static void ResumeVM()
Mathieu Chartier90443472015-07-16 20:32:27 -0700463 REQUIRES(!Locks::thread_list_lock_, !Locks::thread_suspend_count_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800464 static JDWP::JdwpError SuspendThread(JDWP::ObjectId thread_id, bool request_suspension = true)
Mathieu Chartier90443472015-07-16 20:32:27 -0700465 REQUIRES(!Locks::mutator_lock_, !Locks::thread_list_lock_,
466 !Locks::thread_suspend_count_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700467
Elliott Hughes88d63092013-01-09 09:55:54 -0800468 static void ResumeThread(JDWP::ObjectId thread_id)
Mathieu Chartier90443472015-07-16 20:32:27 -0700469 REQUIRES(!Locks::thread_list_lock_, !Locks::thread_suspend_count_lock_)
470 SHARED_REQUIRES(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700471 static void SuspendSelf();
472
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700473 static JDWP::JdwpError GetThisObject(JDWP::ObjectId thread_id, JDWP::FrameId frame_id,
474 JDWP::ObjectId* result)
Mathieu Chartier90443472015-07-16 20:32:27 -0700475 REQUIRES(!Locks::thread_list_lock_, !Locks::thread_suspend_count_lock_)
476 SHARED_REQUIRES(Locks::mutator_lock_);
Sebastien Hertz8009f392014-09-01 17:07:11 +0200477 static JDWP::JdwpError GetLocalValues(JDWP::Request* request, JDWP::ExpandBuf* pReply)
Mathieu Chartier90443472015-07-16 20:32:27 -0700478 REQUIRES(!Locks::thread_list_lock_) SHARED_REQUIRES(Locks::mutator_lock_);
Sebastien Hertz8009f392014-09-01 17:07:11 +0200479 static JDWP::JdwpError SetLocalValues(JDWP::Request* request)
Mathieu Chartier90443472015-07-16 20:32:27 -0700480 REQUIRES(!Locks::thread_list_lock_) SHARED_REQUIRES(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700481
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100482 static JDWP::JdwpError Interrupt(JDWP::ObjectId thread_id)
Mathieu Chartier90443472015-07-16 20:32:27 -0700483 REQUIRES(!Locks::thread_list_lock_);
Elliott Hughesf9501702013-01-11 11:22:27 -0800484
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700485 /*
486 * Debugger notification
487 */
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700488 enum EventFlag {
Elliott Hughes86964332012-02-15 19:37:42 -0800489 kBreakpoint = 0x01,
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700490 kSingleStep = 0x02,
491 kMethodEntry = 0x04,
492 kMethodExit = 0x08,
493 };
Mathieu Chartiere401d142015-04-22 13:56:20 -0700494 static void PostFieldAccessEvent(ArtMethod* m, int dex_pc, mirror::Object* this_object,
Mathieu Chartierc7853442015-03-27 14:35:38 -0700495 ArtField* f)
Mathieu Chartier90443472015-07-16 20:32:27 -0700496 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700497 static void PostFieldModificationEvent(ArtMethod* m, int dex_pc,
Mathieu Chartierc7853442015-03-27 14:35:38 -0700498 mirror::Object* this_object, ArtField* f,
Sebastien Hertz3f52eaf2014-04-04 17:50:18 +0200499 const JValue* field_value)
Mathieu Chartier90443472015-07-16 20:32:27 -0700500 SHARED_REQUIRES(Locks::mutator_lock_);
Nicolas Geoffray14691c52015-03-05 10:40:17 +0000501 static void PostException(mirror::Throwable* exception)
Mathieu Chartier90443472015-07-16 20:32:27 -0700502 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700503 static void PostThreadStart(Thread* t)
Mathieu Chartier90443472015-07-16 20:32:27 -0700504 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700505 static void PostThreadDeath(Thread* t)
Mathieu Chartier90443472015-07-16 20:32:27 -0700506 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800507 static void PostClassPrepare(mirror::Class* c)
Mathieu Chartier90443472015-07-16 20:32:27 -0700508 SHARED_REQUIRES(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700509
Ian Rogers62d6c772013-02-27 08:32:07 -0800510 static void UpdateDebugger(Thread* thread, mirror::Object* this_object,
Mathieu Chartiere401d142015-04-22 13:56:20 -0700511 ArtMethod* method, uint32_t new_dex_pc,
Sebastien Hertz8379b222014-02-24 17:38:15 +0100512 int event_flags, const JValue* return_value)
Mathieu Chartier90443472015-07-16 20:32:27 -0700513 REQUIRES(!Locks::breakpoint_lock_) SHARED_REQUIRES(Locks::mutator_lock_);
Elliott Hughes91bf6cd2012-02-14 17:27:48 -0800514
Sebastien Hertzf3928792014-11-17 19:00:37 +0100515 // Indicates whether we need deoptimization for debugging.
516 static bool RequiresDeoptimization();
517
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100518 // Records deoptimization request in the queue.
519 static void RequestDeoptimization(const DeoptimizationRequest& req)
Mathieu Chartier90443472015-07-16 20:32:27 -0700520 REQUIRES(!Locks::deoptimization_lock_) SHARED_REQUIRES(Locks::mutator_lock_);
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100521
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100522 // Manage deoptimization after updating JDWP events list. Suspends all threads, processes each
523 // request and finally resumes all threads.
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100524 static void ManageDeoptimization()
Mathieu Chartier90443472015-07-16 20:32:27 -0700525 REQUIRES(!Locks::deoptimization_lock_) SHARED_REQUIRES(Locks::mutator_lock_);
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100526
527 // Breakpoints.
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100528 static void WatchLocation(const JDWP::JdwpLocation* pLoc, DeoptimizationRequest* req)
Mathieu Chartier90443472015-07-16 20:32:27 -0700529 REQUIRES(!Locks::breakpoint_lock_) SHARED_REQUIRES(Locks::mutator_lock_);
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100530 static void UnwatchLocation(const JDWP::JdwpLocation* pLoc, DeoptimizationRequest* req)
Mathieu Chartier90443472015-07-16 20:32:27 -0700531 REQUIRES(!Locks::breakpoint_lock_) SHARED_REQUIRES(Locks::mutator_lock_);
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100532
Daniel Mihalyieb076692014-08-22 17:33:31 +0200533 /*
534 * Forced interpreter checkers for single-step and continue support.
535 */
536
537 // Indicates whether we need to force the use of interpreter to invoke a method.
538 // This allows to single-step or continue into the called method.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700539 static bool IsForcedInterpreterNeededForCalling(Thread* thread, ArtMethod* m)
Mathieu Chartier90443472015-07-16 20:32:27 -0700540 SHARED_REQUIRES(Locks::mutator_lock_) {
Daniel Mihalyieb076692014-08-22 17:33:31 +0200541 if (!IsDebuggerActive()) {
542 return false;
543 }
544 return IsForcedInterpreterNeededForCallingImpl(thread, m);
545 }
546
547 // Indicates whether we need to force the use of interpreter entrypoint when calling a
548 // method through the resolution trampoline. This allows to single-step or continue into
549 // the called method.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700550 static bool IsForcedInterpreterNeededForResolution(Thread* thread, ArtMethod* m)
Mathieu Chartier90443472015-07-16 20:32:27 -0700551 SHARED_REQUIRES(Locks::mutator_lock_) {
Daniel Mihalyieb076692014-08-22 17:33:31 +0200552 if (!IsDebuggerActive()) {
553 return false;
554 }
555 return IsForcedInterpreterNeededForResolutionImpl(thread, m);
556 }
557
558 // Indicates whether we need to force the use of instrumentation entrypoint when calling
559 // a method through the resolution trampoline. This allows to deoptimize the stack for
560 // debugging when we returned from the called method.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700561 static bool IsForcedInstrumentationNeededForResolution(Thread* thread, ArtMethod* m)
Mathieu Chartier90443472015-07-16 20:32:27 -0700562 SHARED_REQUIRES(Locks::mutator_lock_) {
Daniel Mihalyieb076692014-08-22 17:33:31 +0200563 if (!IsDebuggerActive()) {
564 return false;
565 }
566 return IsForcedInstrumentationNeededForResolutionImpl(thread, m);
567 }
568
569 // Indicates whether we need to force the use of interpreter when returning from the
570 // interpreter into the runtime. This allows to deoptimize the stack and continue
571 // execution with interpreter for debugging.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700572 static bool IsForcedInterpreterNeededForUpcall(Thread* thread, ArtMethod* m)
Mathieu Chartier90443472015-07-16 20:32:27 -0700573 SHARED_REQUIRES(Locks::mutator_lock_) {
Mingyao Yang99170c62015-07-06 11:10:37 -0700574 if (!IsDebuggerActive() && !thread->HasDebuggerShadowFrames()) {
Daniel Mihalyieb076692014-08-22 17:33:31 +0200575 return false;
576 }
577 return IsForcedInterpreterNeededForUpcallImpl(thread, m);
578 }
579
Sebastien Hertz520633b2015-09-08 17:03:36 +0200580 // Indicates whether we need to force the use of interpreter when handling an
581 // exception. This allows to deoptimize the stack and continue execution with
582 // the interpreter.
583 // Note: the interpreter will start by handling the exception when executing
584 // the deoptimized frames.
585 static bool IsForcedInterpreterNeededForException(Thread* thread)
586 SHARED_REQUIRES(Locks::mutator_lock_) {
Mingyao Yang99170c62015-07-06 11:10:37 -0700587 if (!IsDebuggerActive() && !thread->HasDebuggerShadowFrames()) {
Sebastien Hertz520633b2015-09-08 17:03:36 +0200588 return false;
589 }
590 return IsForcedInterpreterNeededForExceptionImpl(thread);
591 }
592
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100593 // Single-stepping.
Elliott Hughes88d63092013-01-09 09:55:54 -0800594 static JDWP::JdwpError ConfigureStep(JDWP::ObjectId thread_id, JDWP::JdwpStepSize size,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700595 JDWP::JdwpStepDepth depth)
Mathieu Chartier90443472015-07-16 20:32:27 -0700596 SHARED_REQUIRES(Locks::mutator_lock_);
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +0100597 static void UnconfigureStep(JDWP::ObjectId thread_id)
Mathieu Chartier90443472015-07-16 20:32:27 -0700598 REQUIRES(!Locks::thread_list_lock_) SHARED_REQUIRES(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700599
Sebastien Hertzcbc50642015-06-01 17:33:12 +0200600 /*
601 * Invoke support
602 */
603
604 // Called by the JDWP thread to prepare invocation in the event thread (suspended on an event).
605 // If the information sent by the debugger is incorrect, it will send a reply with the
606 // appropriate error code. Otherwise, it will attach a DebugInvokeReq object to the event thread
607 // and resume it (and possibly other threads depending on the invoke options).
608 // Unlike other commands, the JDWP thread will not send the reply to the debugger (see
609 // JdwpState::ProcessRequest). The reply will be sent by the event thread itself after method
610 // invocation completes (see FinishInvokeMethod). This is required to allow the JDWP thread to
611 // process incoming commands from the debugger while the invocation is still in progress in the
612 // event thread, especially if it gets suspended by a debug event occurring in another thread.
613 static JDWP::JdwpError PrepareInvokeMethod(uint32_t request_id, JDWP::ObjectId thread_id,
614 JDWP::ObjectId object_id, JDWP::RefTypeId class_id,
615 JDWP::MethodId method_id, uint32_t arg_count,
616 uint64_t arg_values[], JDWP::JdwpTag* arg_types,
617 uint32_t options)
Mathieu Chartier90443472015-07-16 20:32:27 -0700618 REQUIRES(!Locks::thread_list_lock_, !Locks::thread_suspend_count_lock_)
619 SHARED_REQUIRES(Locks::mutator_lock_);
Sebastien Hertzcbc50642015-06-01 17:33:12 +0200620
621 // Called by the event thread to execute a method prepared by the JDWP thread in the given
622 // DebugInvokeReq object. Once the invocation completes, the event thread attaches a reply
623 // to that DebugInvokeReq object so it can be sent to the debugger only when the event thread
624 // is ready to suspend (see FinishInvokeMethod).
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700625 static void ExecuteMethod(DebugInvokeReq* pReq);
626
Sebastien Hertzcbc50642015-06-01 17:33:12 +0200627 // Called by the event thread to send the reply of the invoke (created in ExecuteMethod)
628 // before suspending itself. This is to ensure the thread is ready to suspend before the
629 // debugger receives the reply.
630 static void FinishInvokeMethod(DebugInvokeReq* pReq);
631
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700632 /*
633 * DDM support.
634 */
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700635 static void DdmSendThreadNotification(Thread* t, uint32_t type)
Mathieu Chartier90443472015-07-16 20:32:27 -0700636 SHARED_REQUIRES(Locks::mutator_lock_);
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100637 static void DdmSetThreadNotification(bool enable)
Mathieu Chartier90443472015-07-16 20:32:27 -0700638 REQUIRES(!Locks::thread_list_lock_);
Ian Rogersc0542af2014-09-03 16:16:56 -0700639 static bool DdmHandlePacket(JDWP::Request* request, uint8_t** pReplyBuf, int* pReplyLen);
Mathieu Chartier90443472015-07-16 20:32:27 -0700640 static void DdmConnected() SHARED_REQUIRES(Locks::mutator_lock_);
641 static void DdmDisconnected() SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700642 static void DdmSendChunk(uint32_t type, const std::vector<uint8_t>& bytes)
Mathieu Chartier90443472015-07-16 20:32:27 -0700643 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700644 static void DdmSendChunk(uint32_t type, size_t len, const uint8_t* buf)
Mathieu Chartier90443472015-07-16 20:32:27 -0700645 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700646 static void DdmSendChunkV(uint32_t type, const iovec* iov, int iov_count)
Mathieu Chartier90443472015-07-16 20:32:27 -0700647 SHARED_REQUIRES(Locks::mutator_lock_);
Elliott Hughes767a1472011-10-26 18:49:02 -0700648
Mathieu Chartiera6b1ead2015-10-06 10:32:38 -0700649 // Visit breakpoint roots, used to prevent unloading of methods with breakpoints.
Mathieu Chartierbb87e0f2015-04-03 11:21:55 -0700650 static void VisitRoots(RootVisitor* visitor)
Mathieu Chartier90443472015-07-16 20:32:27 -0700651 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartier3b05e9b2014-03-25 09:29:43 -0700652
Elliott Hughes545a0642011-11-08 19:10:03 -0800653 /*
Man Cao8c2ff642015-05-27 17:25:30 -0700654 * Allocation tracking support.
Elliott Hughes545a0642011-11-08 19:10:03 -0800655 */
Mathieu Chartier90443472015-07-16 20:32:27 -0700656 static void SetAllocTrackingEnabled(bool enabled) REQUIRES(!Locks::alloc_tracker_lock_);
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100657 static jbyteArray GetRecentAllocations()
Mathieu Chartier90443472015-07-16 20:32:27 -0700658 REQUIRES(!Locks::alloc_tracker_lock_) SHARED_REQUIRES(Locks::mutator_lock_);
659 static void DumpRecentAllocations() REQUIRES(!Locks::alloc_tracker_lock_);
Elliott Hughes545a0642011-11-08 19:10:03 -0800660
Elliott Hughes767a1472011-10-26 18:49:02 -0700661 enum HpifWhen {
662 HPIF_WHEN_NEVER = 0,
663 HPIF_WHEN_NOW = 1,
664 HPIF_WHEN_NEXT_GC = 2,
665 HPIF_WHEN_EVERY_GC = 3
666 };
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700667 static int DdmHandleHpifChunk(HpifWhen when)
Mathieu Chartier90443472015-07-16 20:32:27 -0700668 SHARED_REQUIRES(Locks::mutator_lock_);
Elliott Hughes767a1472011-10-26 18:49:02 -0700669
670 enum HpsgWhen {
671 HPSG_WHEN_NEVER = 0,
672 HPSG_WHEN_EVERY_GC = 1,
673 };
674 enum HpsgWhat {
675 HPSG_WHAT_MERGED_OBJECTS = 0,
676 HPSG_WHAT_DISTINCT_OBJECTS = 1,
677 };
678 static bool DdmHandleHpsgNhsgChunk(HpsgWhen when, HpsgWhat what, bool native);
679
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700680 static void DdmSendHeapInfo(HpifWhen reason)
Mathieu Chartier90443472015-07-16 20:32:27 -0700681 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700682 static void DdmSendHeapSegments(bool native)
Mathieu Chartier90443472015-07-16 20:32:27 -0700683 SHARED_REQUIRES(Locks::mutator_lock_);
Elliott Hughes545a0642011-11-08 19:10:03 -0800684
Sebastien Hertz6995c602014-09-09 12:10:13 +0200685 static ObjectRegistry* GetObjectRegistry() {
686 return gRegistry;
687 }
688
689 static JDWP::JdwpTag TagFromObject(const ScopedObjectAccessUnchecked& soa, mirror::Object* o)
Mathieu Chartier90443472015-07-16 20:32:27 -0700690 SHARED_REQUIRES(Locks::mutator_lock_);
Sebastien Hertz6995c602014-09-09 12:10:13 +0200691
692 static JDWP::JdwpTypeTag GetTypeTag(mirror::Class* klass)
Mathieu Chartier90443472015-07-16 20:32:27 -0700693 SHARED_REQUIRES(Locks::mutator_lock_);
Sebastien Hertz6995c602014-09-09 12:10:13 +0200694
Mathieu Chartierc7853442015-03-27 14:35:38 -0700695 static JDWP::FieldId ToFieldId(const ArtField* f)
Mathieu Chartier90443472015-07-16 20:32:27 -0700696 SHARED_REQUIRES(Locks::mutator_lock_);
Sebastien Hertz6995c602014-09-09 12:10:13 +0200697
Mathieu Chartiere401d142015-04-22 13:56:20 -0700698 static void SetJdwpLocation(JDWP::JdwpLocation* location, ArtMethod* m, uint32_t dex_pc)
Mathieu Chartier90443472015-07-16 20:32:27 -0700699 SHARED_REQUIRES(Locks::mutator_lock_)
700 REQUIRES(!Locks::thread_list_lock_, !Locks::thread_suspend_count_lock_);
Sebastien Hertz6995c602014-09-09 12:10:13 +0200701
Mathieu Chartierad466ad2015-01-08 16:28:08 -0800702 static JDWP::JdwpState* GetJdwpState();
703
Mathieu Chartier90443472015-07-16 20:32:27 -0700704 static uint32_t GetInstrumentationEvents() SHARED_REQUIRES(Locks::mutator_lock_) {
Sebastien Hertz9d6bf692015-04-10 12:12:33 +0200705 return instrumentation_events_;
706 }
707
Elliott Hughes545a0642011-11-08 19:10:03 -0800708 private:
Sebastien Hertzcbc50642015-06-01 17:33:12 +0200709 static void ExecuteMethodWithoutPendingException(ScopedObjectAccess& soa, DebugInvokeReq* pReq)
Mathieu Chartier90443472015-07-16 20:32:27 -0700710 SHARED_REQUIRES(Locks::mutator_lock_);
Sebastien Hertzcbc50642015-06-01 17:33:12 +0200711
712 static void BuildInvokeReply(JDWP::ExpandBuf* pReply, uint32_t request_id,
713 JDWP::JdwpTag result_tag, uint64_t result_value,
714 JDWP::ObjectId exception)
Mathieu Chartier90443472015-07-16 20:32:27 -0700715 SHARED_REQUIRES(Locks::mutator_lock_);
Sebastien Hertzcbc50642015-06-01 17:33:12 +0200716
Sebastien Hertz8009f392014-09-01 17:07:11 +0200717 static JDWP::JdwpError GetLocalValue(const StackVisitor& visitor,
718 ScopedObjectAccessUnchecked& soa, int slot,
719 JDWP::JdwpTag tag, uint8_t* buf, size_t width)
Mathieu Chartier90443472015-07-16 20:32:27 -0700720 REQUIRES(!Locks::thread_list_lock_) SHARED_REQUIRES(Locks::mutator_lock_);
Mingyao Yang99170c62015-07-06 11:10:37 -0700721 static JDWP::JdwpError SetLocalValue(Thread* thread, StackVisitor& visitor, int slot,
722 JDWP::JdwpTag tag, uint64_t value, size_t width)
Mathieu Chartier90443472015-07-16 20:32:27 -0700723 REQUIRES(!Locks::thread_list_lock_) SHARED_REQUIRES(Locks::mutator_lock_);
Sebastien Hertz8009f392014-09-01 17:07:11 +0200724
Mathieu Chartier90443472015-07-16 20:32:27 -0700725 static void DdmBroadcast(bool connect) SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700726 static void PostThreadStartOrStop(Thread*, uint32_t)
Mathieu Chartier90443472015-07-16 20:32:27 -0700727 SHARED_REQUIRES(Locks::mutator_lock_);
Elliott Hughesa2155262011-11-16 16:26:58 -0800728
Mathieu Chartiere401d142015-04-22 13:56:20 -0700729 static void PostLocationEvent(ArtMethod* method, int pcOffset,
Sebastien Hertz8379b222014-02-24 17:38:15 +0100730 mirror::Object* thisPtr, int eventFlags,
731 const JValue* return_value)
Mathieu Chartier90443472015-07-16 20:32:27 -0700732 SHARED_REQUIRES(Locks::mutator_lock_);
Sebastien Hertz8379b222014-02-24 17:38:15 +0100733
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100734 static void ProcessDeoptimizationRequest(const DeoptimizationRequest& request)
Mathieu Chartieraa516822015-10-02 15:53:37 -0700735 REQUIRES(Locks::mutator_lock_, Roles::uninterruptible_);
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100736
Sebastien Hertz7ec2f1c2014-03-27 20:06:47 +0100737 static void RequestDeoptimizationLocked(const DeoptimizationRequest& req)
Mathieu Chartier90443472015-07-16 20:32:27 -0700738 REQUIRES(Locks::deoptimization_lock_) SHARED_REQUIRES(Locks::mutator_lock_);
Sebastien Hertz7ec2f1c2014-03-27 20:06:47 +0100739
Mathieu Chartiere401d142015-04-22 13:56:20 -0700740 static bool IsForcedInterpreterNeededForCallingImpl(Thread* thread, ArtMethod* m)
Mathieu Chartier90443472015-07-16 20:32:27 -0700741 SHARED_REQUIRES(Locks::mutator_lock_);
Daniel Mihalyieb076692014-08-22 17:33:31 +0200742
Mathieu Chartiere401d142015-04-22 13:56:20 -0700743 static bool IsForcedInterpreterNeededForResolutionImpl(Thread* thread, ArtMethod* m)
Mathieu Chartier90443472015-07-16 20:32:27 -0700744 SHARED_REQUIRES(Locks::mutator_lock_);
Daniel Mihalyieb076692014-08-22 17:33:31 +0200745
Mathieu Chartiere401d142015-04-22 13:56:20 -0700746 static bool IsForcedInstrumentationNeededForResolutionImpl(Thread* thread, ArtMethod* m)
Mathieu Chartier90443472015-07-16 20:32:27 -0700747 SHARED_REQUIRES(Locks::mutator_lock_);
Daniel Mihalyieb076692014-08-22 17:33:31 +0200748
Mathieu Chartiere401d142015-04-22 13:56:20 -0700749 static bool IsForcedInterpreterNeededForUpcallImpl(Thread* thread, ArtMethod* m)
Mathieu Chartier90443472015-07-16 20:32:27 -0700750 SHARED_REQUIRES(Locks::mutator_lock_);
Daniel Mihalyieb076692014-08-22 17:33:31 +0200751
Sebastien Hertz520633b2015-09-08 17:03:36 +0200752 static bool IsForcedInterpreterNeededForExceptionImpl(Thread* thread)
753 SHARED_REQUIRES(Locks::mutator_lock_);
754
Daniel Mihalyieb076692014-08-22 17:33:31 +0200755 // Indicates whether the debugger is making requests.
756 static bool gDebuggerActive;
757
Sebastien Hertz4e5b2082015-03-24 19:03:40 +0100758 // Indicates whether we should drop the JDWP connection because the runtime stops or the
759 // debugger called VirtualMachine.Dispose.
760 static bool gDisposed;
761
Daniel Mihalyieb076692014-08-22 17:33:31 +0200762 // The registry mapping objects to JDWP ids.
Sebastien Hertz6995c602014-09-09 12:10:13 +0200763 static ObjectRegistry* gRegistry;
764
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100765 // Deoptimization requests to be processed each time the event list is updated. This is used when
766 // registering and unregistering events so we do not deoptimize while holding the event list
767 // lock.
Sebastien Hertz42cd43f2014-05-13 14:15:41 +0200768 // TODO rename to instrumentation_requests.
Brian Carlstrom306db812014-09-05 13:01:41 -0700769 static std::vector<DeoptimizationRequest> deoptimization_requests_ GUARDED_BY(Locks::deoptimization_lock_);
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100770
771 // Count the number of events requiring full deoptimization. When the counter is > 0, everything
772 // is deoptimized, otherwise everything is undeoptimized.
773 // Note: we fully deoptimize on the first event only (when the counter is set to 1). We fully
774 // undeoptimize when the last event is unregistered (when the counter is set to 0).
Brian Carlstrom306db812014-09-05 13:01:41 -0700775 static size_t full_deoptimization_event_count_ GUARDED_BY(Locks::deoptimization_lock_);
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100776
Sebastien Hertz42cd43f2014-05-13 14:15:41 +0200777 static size_t* GetReferenceCounterForEvent(uint32_t instrumentation_event);
778
779 // Instrumentation event reference counters.
780 // TODO we could use an array instead of having all these dedicated counters. Instrumentation
781 // events are bits of a mask so we could convert them to array index.
Brian Carlstrom306db812014-09-05 13:01:41 -0700782 static size_t dex_pc_change_event_ref_count_ GUARDED_BY(Locks::deoptimization_lock_);
783 static size_t method_enter_event_ref_count_ GUARDED_BY(Locks::deoptimization_lock_);
784 static size_t method_exit_event_ref_count_ GUARDED_BY(Locks::deoptimization_lock_);
785 static size_t field_read_event_ref_count_ GUARDED_BY(Locks::deoptimization_lock_);
786 static size_t field_write_event_ref_count_ GUARDED_BY(Locks::deoptimization_lock_);
787 static size_t exception_catch_event_ref_count_ GUARDED_BY(Locks::deoptimization_lock_);
Sebastien Hertz42cd43f2014-05-13 14:15:41 +0200788 static uint32_t instrumentation_events_ GUARDED_BY(Locks::mutator_lock_);
789
Ian Rogers719d1a32014-03-06 12:13:39 -0800790 DISALLOW_COPY_AND_ASSIGN(Dbg);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700791};
792
793#define CHUNK_TYPE(_name) \
Elliott Hughes82188472011-11-07 18:11:48 -0800794 static_cast<uint32_t>((_name)[0] << 24 | (_name)[1] << 16 | (_name)[2] << 8 | (_name)[3])
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700795
796} // namespace art
797
Brian Carlstromfc0e3212013-07-17 14:40:12 -0700798#endif // ART_RUNTIME_DEBUGGER_H_