blob: 8f0db76c2bcb60db013628ee71f2456e41d6ba00 [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
Mathieu Chartier4345c462014-06-27 10:20:14 -070026#include <map>
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +010027#include <set>
Elliott Hughes3bb81562011-10-21 18:52:59 -070028#include <string>
Sebastien Hertz4d25df32014-03-21 17:44:46 +010029#include <vector>
Elliott Hughes3bb81562011-10-21 18:52:59 -070030
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"
Mathieu Chartier83c8ee02014-01-28 14:50:23 -080034#include "object_callbacks.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 {
Sebastien Hertz3f52eaf2014-04-04 17:50:18 +020039class ArtField;
Brian Carlstromea46f952013-07-30 01:26:50 -070040class ArtMethod;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080041class Class;
42class Object;
43class Throwable;
44} // namespace mirror
Hiroshi Yamauchib5a9e3d2014-06-09 12:11:20 -070045class AllocRecord;
Sebastien Hertz6995c602014-09-09 12:10:13 +020046class ObjectRegistry;
47class ScopedObjectAccessUnchecked;
Sebastien Hertz8009f392014-09-01 17:07:11 +020048class StackVisitor;
Ian Rogers1b09b092012-08-20 15:35:52 -070049class Thread;
Ian Rogers62d6c772013-02-27 08:32:07 -080050class ThrowLocation;
Elliott Hughes872d4ec2011-10-21 17:07:15 -070051
52/*
53 * Invoke-during-breakpoint support.
54 */
55struct DebugInvokeReq {
Elliott Hughes7b3cdfc2011-12-08 21:28:17 -080056 DebugInvokeReq()
Sebastien Hertzd38667a2013-11-25 15:43:54 +010057 : ready(false), invoke_needed(false),
58 receiver(NULL), thread(NULL), klass(NULL), method(NULL),
59 arg_count(0), arg_values(NULL), options(0), error(JDWP::ERR_NONE),
Ian Rogers00f7d0e2012-07-19 15:28:27 -070060 result_tag(JDWP::JT_VOID), exception(0),
Sebastien Hertzd38667a2013-11-25 15:43:54 +010061 lock("a DebugInvokeReq lock", kBreakpointInvokeLock),
62 cond("a DebugInvokeReq condition variable", lock) {
Elliott Hughes475fc232011-10-25 15:00:35 -070063 }
64
Elliott Hughes872d4ec2011-10-21 17:07:15 -070065 /* boolean; only set when we're in the tail end of an event handler */
66 bool ready;
67
68 /* boolean; set if the JDWP thread wants this thread to do work */
Sebastien Hertzd38667a2013-11-25 15:43:54 +010069 bool invoke_needed;
Elliott Hughes872d4ec2011-10-21 17:07:15 -070070
71 /* request */
Sebastien Hertzd38667a2013-11-25 15:43:54 +010072 mirror::Object* receiver; /* not used for ClassType.InvokeMethod */
73 mirror::Object* thread;
74 mirror::Class* klass;
75 mirror::ArtMethod* method;
76 uint32_t arg_count;
77 uint64_t* arg_values; /* will be NULL if arg_count_ == 0 */
78 uint32_t options;
Elliott Hughes872d4ec2011-10-21 17:07:15 -070079
80 /* result */
Elliott Hughes475fc232011-10-25 15:00:35 -070081 JDWP::JdwpError error;
Elliott Hughesd07986f2011-12-06 18:27:45 -080082 JDWP::JdwpTag result_tag;
Elliott Hughes475fc232011-10-25 15:00:35 -070083 JValue result_value;
84 JDWP::ObjectId exception;
Elliott Hughes872d4ec2011-10-21 17:07:15 -070085
86 /* condition variable to wait on while the method executes */
Sebastien Hertzd38667a2013-11-25 15:43:54 +010087 Mutex lock DEFAULT_MUTEX_ACQUIRED_AFTER;
88 ConditionVariable cond GUARDED_BY(lock);
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +010089
Mathieu Chartier3b05e9b2014-03-25 09:29:43 -070090 void VisitRoots(RootCallback* callback, void* arg, uint32_t tid, RootType root_type)
91 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
92
Sebastien Hertzbb43b432014-04-14 11:59:08 +020093 void Clear();
94
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +010095 private:
96 DISALLOW_COPY_AND_ASSIGN(DebugInvokeReq);
97};
98
99// Thread local data-structure that holds fields for controlling single-stepping.
100struct SingleStepControl {
101 SingleStepControl()
102 : is_active(false), step_size(JDWP::SS_MIN), step_depth(JDWP::SD_INTO),
103 method(nullptr), stack_depth(0) {
104 }
105
106 // Are we single-stepping right now?
107 bool is_active;
108
109 // See JdwpStepSize and JdwpStepDepth for details.
110 JDWP::JdwpStepSize step_size;
111 JDWP::JdwpStepDepth step_depth;
112
113 // The location this single-step was initiated from.
114 // A single-step is initiated in a suspended thread. We save here the current method and the
115 // set of DEX pcs associated to the source line number where the suspension occurred.
116 // This is used to support SD_INTO and SD_OVER single-step depths so we detect when a single-step
117 // causes the execution of an instruction in a different method or at a different line number.
118 mirror::ArtMethod* method;
119 std::set<uint32_t> dex_pcs;
120
121 // The stack depth when this single-step was initiated. This is used to support SD_OVER and SD_OUT
122 // single-step depth.
123 int stack_depth;
124
Mathieu Chartier3b05e9b2014-03-25 09:29:43 -0700125 void VisitRoots(RootCallback* callback, void* arg, uint32_t tid, RootType root_type)
126 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
127
Sebastien Hertzbb43b432014-04-14 11:59:08 +0200128 bool ContainsDexPc(uint32_t dex_pc) const;
129
130 void Clear();
131
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +0100132 private:
133 DISALLOW_COPY_AND_ASSIGN(SingleStepControl);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700134};
135
Sebastien Hertz42cd43f2014-05-13 14:15:41 +0200136// TODO rename to InstrumentationRequest.
Hiroshi Yamauchi0ec17d22014-07-07 13:07:08 -0700137class DeoptimizationRequest {
138 public:
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100139 enum Kind {
140 kNothing, // no action.
Sebastien Hertz42cd43f2014-05-13 14:15:41 +0200141 kRegisterForEvent, // start listening for instrumentation event.
142 kUnregisterForEvent, // stop listening for instrumentation event.
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100143 kFullDeoptimization, // deoptimize everything.
144 kFullUndeoptimization, // undeoptimize everything.
145 kSelectiveDeoptimization, // deoptimize one method.
146 kSelectiveUndeoptimization // undeoptimize one method.
147 };
148
Hiroshi Yamauchi0ec17d22014-07-07 13:07:08 -0700149 DeoptimizationRequest() : kind_(kNothing), instrumentation_event_(0), method_(nullptr) {}
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100150
Hiroshi Yamauchi0ec17d22014-07-07 13:07:08 -0700151 DeoptimizationRequest(const DeoptimizationRequest& other)
152 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_)
153 : kind_(other.kind_), instrumentation_event_(other.instrumentation_event_) {
154 // Create a new JNI global reference for the method.
155 SetMethod(other.Method());
156 }
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100157
Hiroshi Yamauchi0ec17d22014-07-07 13:07:08 -0700158 mirror::ArtMethod* Method() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
159
160 void SetMethod(mirror::ArtMethod* m) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
161
162 // Name 'Kind()' would collide with the above enum name.
163 Kind GetKind() const {
164 return kind_;
165 }
166
167 void SetKind(Kind kind) {
168 kind_ = kind;
169 }
170
171 uint32_t InstrumentationEvent() const {
172 return instrumentation_event_;
173 }
174
175 void SetInstrumentationEvent(uint32_t instrumentation_event) {
176 instrumentation_event_ = instrumentation_event;
177 }
178
179 private:
180 Kind kind_;
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100181
Sebastien Hertz42cd43f2014-05-13 14:15:41 +0200182 // TODO we could use a union to hold the instrumentation_event and the method since they
183 // respectively have sense only for kRegisterForEvent/kUnregisterForEvent and
184 // kSelectiveDeoptimization/kSelectiveUndeoptimization.
185
186 // Event to start or stop listening to. Only for kRegisterForEvent and kUnregisterForEvent.
Hiroshi Yamauchi0ec17d22014-07-07 13:07:08 -0700187 uint32_t instrumentation_event_;
Sebastien Hertz42cd43f2014-05-13 14:15:41 +0200188
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100189 // Method for selective deoptimization.
Hiroshi Yamauchi0ec17d22014-07-07 13:07:08 -0700190 jmethodID method_;
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100191};
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700192std::ostream& operator<<(std::ostream& os, const DeoptimizationRequest::Kind& rhs);
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100193
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700194class Dbg {
Elliott Hughesff17f1f2012-01-24 18:12:29 -0800195 public:
Mathieu Chartier4345c462014-06-27 10:20:14 -0700196 class TypeCache {
197 public:
198 // Returns a weak global for the input type. Deduplicates.
Brian Carlstrom306db812014-09-05 13:01:41 -0700199 jobject Add(mirror::Class* t) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_,
200 Locks::alloc_tracker_lock_);
Mathieu Chartier4345c462014-06-27 10:20:14 -0700201 // Clears the type cache and deletes all the weak global refs.
Brian Carlstrom306db812014-09-05 13:01:41 -0700202 void Clear() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_,
203 Locks::alloc_tracker_lock_);
Mathieu Chartier4345c462014-06-27 10:20:14 -0700204
205 private:
206 std::multimap<int32_t, jobject> objects_;
207 };
208
Elliott Hughes3bb81562011-10-21 18:52:59 -0700209 static bool ParseJdwpOptions(const std::string& options);
Elliott Hughes4ffd3132011-10-24 12:06:42 -0700210 static void SetJdwpAllowed(bool allowed);
211
Elliott Hughesd1cc8362011-10-24 16:58:50 -0700212 static void StartJdwp();
213 static void StopJdwp();
214
Elliott Hughes767a1472011-10-26 18:49:02 -0700215 // Invoked by the GC in case we need to keep DDMS informed.
Ian Rogersb726dcb2012-09-05 08:57:23 -0700216 static void GcDidFinish() LOCKS_EXCLUDED(Locks::mutator_lock_);
Elliott Hughes767a1472011-10-26 18:49:02 -0700217
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700218 // Return the DebugInvokeReq for the current thread.
219 static DebugInvokeReq* GetInvokeReq();
220
Elliott Hughes475fc232011-10-25 15:00:35 -0700221 static Thread* GetDebugThread();
222 static void ClearWaitForEventThread();
223
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700224 /*
225 * Enable/disable breakpoints and step modes. Used to provide a heads-up
226 * when the debugger attaches.
227 */
228 static void Connected();
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100229 static void GoActive()
Brian Carlstrom306db812014-09-05 13:01:41 -0700230 LOCKS_EXCLUDED(Locks::breakpoint_lock_, Locks::deoptimization_lock_, Locks::mutator_lock_);
231 static void Disconnected() LOCKS_EXCLUDED(Locks::deoptimization_lock_, Locks::mutator_lock_);
Elliott Hughes86964332012-02-15 19:37:42 -0800232 static void Disposed();
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700233
Elliott Hughesc0f09332012-03-26 13:27:06 -0700234 // Returns true if we're actually debugging with a real debugger, false if it's
235 // just DDMS (or nothing at all).
236 static bool IsDebuggerActive();
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700237
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
Elliott Hughes86964332012-02-15 19:37:42 -0800241 static bool IsDisposed();
242
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700243 /*
244 * Time, in milliseconds, since the last debugger activity. Does not
245 * include DDMS activity. Returns -1 if there has been no activity.
246 * Returns 0 if we're in the middle of handling a debugger request.
247 */
248 static int64_t LastDebuggerActivity();
249
Sebastien Hertz253fa552014-10-14 17:27:15 +0200250 static void UndoDebuggerSuspensions()
251 LOCKS_EXCLUDED(Locks::thread_list_lock_,
252 Locks::thread_suspend_count_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700253
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700254 /*
255 * Class, Object, Array
256 */
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700257 static std::string GetClassName(JDWP::RefTypeId id)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700258 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertz6995c602014-09-09 12:10:13 +0200259 static std::string GetClassName(mirror::Class* klass)
260 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersc0542af2014-09-03 16:16:56 -0700261 static JDWP::JdwpError GetClassObject(JDWP::RefTypeId id, JDWP::ObjectId* class_object_id)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700262 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersc0542af2014-09-03 16:16:56 -0700263 static JDWP::JdwpError GetSuperclass(JDWP::RefTypeId id, JDWP::RefTypeId* superclass_id)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700264 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700265 static JDWP::JdwpError GetClassLoader(JDWP::RefTypeId id, JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700266 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700267 static JDWP::JdwpError GetModifiers(JDWP::RefTypeId id, JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700268 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800269 static JDWP::JdwpError GetReflectedType(JDWP::RefTypeId class_id, JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700270 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersc0542af2014-09-03 16:16:56 -0700271 static void GetClassList(std::vector<JDWP::RefTypeId>* classes)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700272 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800273 static JDWP::JdwpError GetClassInfo(JDWP::RefTypeId class_id, JDWP::JdwpTypeTag* pTypeTag,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700274 uint32_t* pStatus, std::string* pDescriptor)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700275 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersc0542af2014-09-03 16:16:56 -0700276 static void FindLoadedClassBySignature(const char* descriptor, std::vector<JDWP::RefTypeId>* ids)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700277 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes64f574f2013-02-20 14:57:12 -0800278 static JDWP::JdwpError GetReferenceType(JDWP::ObjectId object_id, JDWP::ExpandBuf* pReply)
279 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersfc0e94b2013-09-23 23:51:32 -0700280 static JDWP::JdwpError GetSignature(JDWP::RefTypeId ref_type_id, std::string* signature)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700281 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersc0542af2014-09-03 16:16:56 -0700282 static JDWP::JdwpError GetSourceFile(JDWP::RefTypeId ref_type_id, std::string* source_file)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700283 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersc0542af2014-09-03 16:16:56 -0700284 static JDWP::JdwpError GetObjectTag(JDWP::ObjectId object_id, uint8_t* tag)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700285 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughesaed4be92011-12-02 16:16:23 -0800286 static size_t GetTagWidth(JDWP::JdwpTag tag);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700287
Ian Rogersc0542af2014-09-03 16:16:56 -0700288 static JDWP::JdwpError GetArrayLength(JDWP::ObjectId array_id, int32_t* length)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700289 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800290 static JDWP::JdwpError OutputArray(JDWP::ObjectId array_id, int offset, int count,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700291 JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700292 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800293 static JDWP::JdwpError SetArrayElements(JDWP::ObjectId array_id, int offset, int count,
Ian Rogersc0542af2014-09-03 16:16:56 -0700294 JDWP::Request* request)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700295 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700296
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700297 static JDWP::ObjectId CreateString(const std::string& str)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700298 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersc0542af2014-09-03 16:16:56 -0700299 static JDWP::JdwpError CreateObject(JDWP::RefTypeId class_id, JDWP::ObjectId* new_object)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700300 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800301 static JDWP::JdwpError CreateArrayObject(JDWP::RefTypeId array_class_id, uint32_t length,
Ian Rogersc0542af2014-09-03 16:16:56 -0700302 JDWP::ObjectId* new_array)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700303 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700304
Sebastien Hertz6995c602014-09-09 12:10:13 +0200305 //
306 // Event filtering.
307 //
308 static bool MatchThread(JDWP::ObjectId expected_thread_id, Thread* event_thread)
309 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
310
311 static bool MatchLocation(const JDWP::JdwpLocation& expected_location,
312 const JDWP::EventLocation& event_location)
313 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
314
315 static bool MatchType(mirror::Class* event_class, JDWP::RefTypeId class_id)
316 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
317
318 static bool MatchField(JDWP::RefTypeId expected_type_id, JDWP::FieldId expected_field_id,
319 mirror::ArtField* event_field)
320 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
321
322 static bool MatchInstance(JDWP::ObjectId expected_instance_id, mirror::Object* event_instance)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700323 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700324
Elliott Hughesec0f83d2013-01-15 16:54:08 -0800325 //
326 // Monitors.
327 //
328 static JDWP::JdwpError GetMonitorInfo(JDWP::ObjectId object_id, JDWP::ExpandBuf* reply)
329 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
330 static JDWP::JdwpError GetOwnedMonitors(JDWP::ObjectId thread_id,
Ian Rogersc0542af2014-09-03 16:16:56 -0700331 std::vector<JDWP::ObjectId>* monitors,
332 std::vector<uint32_t>* stack_depths)
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100333 LOCKS_EXCLUDED(Locks::thread_list_lock_)
Elliott Hughesec0f83d2013-01-15 16:54:08 -0800334 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100335 static JDWP::JdwpError GetContendedMonitor(JDWP::ObjectId thread_id,
Ian Rogersc0542af2014-09-03 16:16:56 -0700336 JDWP::ObjectId* contended_monitor)
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100337 LOCKS_EXCLUDED(Locks::thread_list_lock_)
Elliott Hughesec0f83d2013-01-15 16:54:08 -0800338 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
339
340 //
341 // Heap.
342 //
343 static JDWP::JdwpError GetInstanceCounts(const std::vector<JDWP::RefTypeId>& class_ids,
Ian Rogersc0542af2014-09-03 16:16:56 -0700344 std::vector<uint64_t>* counts)
Elliott Hughesec0f83d2013-01-15 16:54:08 -0800345 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes3b78c942013-01-15 17:35:41 -0800346 static JDWP::JdwpError GetInstances(JDWP::RefTypeId class_id, int32_t max_count,
Ian Rogersc0542af2014-09-03 16:16:56 -0700347 std::vector<JDWP::ObjectId>* instances)
Elliott Hughes3b78c942013-01-15 17:35:41 -0800348 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes0cbaff52013-01-16 15:28:01 -0800349 static JDWP::JdwpError GetReferringObjects(JDWP::ObjectId object_id, int32_t max_count,
Ian Rogersc0542af2014-09-03 16:16:56 -0700350 std::vector<JDWP::ObjectId>* referring_objects)
Elliott Hughes0cbaff52013-01-16 15:28:01 -0800351 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes64f574f2013-02-20 14:57:12 -0800352 static JDWP::JdwpError DisableCollection(JDWP::ObjectId object_id)
353 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
354 static JDWP::JdwpError EnableCollection(JDWP::ObjectId object_id)
355 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersc0542af2014-09-03 16:16:56 -0700356 static JDWP::JdwpError IsCollected(JDWP::ObjectId object_id, bool* is_collected)
Elliott Hughes64f574f2013-02-20 14:57:12 -0800357 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
358 static void DisposeObject(JDWP::ObjectId object_id, uint32_t reference_count)
359 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughesec0f83d2013-01-15 16:54:08 -0800360
Elliott Hughes9777ba22013-01-17 09:04:19 -0800361 //
362 // Methods and fields.
363 //
Elliott Hughesa96836a2013-01-17 12:27:49 -0800364 static std::string GetMethodName(JDWP::MethodId method_id)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700365 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800366 static JDWP::JdwpError OutputDeclaredFields(JDWP::RefTypeId ref_type_id, bool with_generic,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700367 JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700368 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800369 static JDWP::JdwpError OutputDeclaredMethods(JDWP::RefTypeId ref_type_id, bool with_generic,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700370 JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700371 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800372 static JDWP::JdwpError OutputDeclaredInterfaces(JDWP::RefTypeId ref_type_id,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700373 JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700374 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800375 static void OutputLineTable(JDWP::RefTypeId ref_type_id, JDWP::MethodId method_id,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700376 JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700377 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800378 static void OutputVariableTable(JDWP::RefTypeId ref_type_id, JDWP::MethodId id, bool with_generic,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700379 JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700380 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Jeff Hao579b0242013-11-18 13:16:49 -0800381 static void OutputMethodReturnValue(JDWP::MethodId method_id, const JValue* return_value,
382 JDWP::ExpandBuf* pReply)
383 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertz3f52eaf2014-04-04 17:50:18 +0200384 static void OutputFieldValue(JDWP::FieldId field_id, const JValue* field_value,
385 JDWP::ExpandBuf* pReply)
386 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes9777ba22013-01-17 09:04:19 -0800387 static JDWP::JdwpError GetBytecodes(JDWP::RefTypeId class_id, JDWP::MethodId method_id,
Ian Rogersc0542af2014-09-03 16:16:56 -0700388 std::vector<uint8_t>* bytecodes)
Elliott Hughes9777ba22013-01-17 09:04:19 -0800389 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700390
Elliott Hughesa96836a2013-01-17 12:27:49 -0800391 static std::string GetFieldName(JDWP::FieldId field_id)
392 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800393 static JDWP::JdwpTag GetFieldBasicTag(JDWP::FieldId field_id)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700394 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800395 static JDWP::JdwpTag GetStaticFieldBasicTag(JDWP::FieldId field_id)
Brian Carlstromf69863b2013-07-17 21:53:13 -0700396 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800397 static JDWP::JdwpError GetFieldValue(JDWP::ObjectId object_id, JDWP::FieldId field_id,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700398 JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700399 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800400 static JDWP::JdwpError SetFieldValue(JDWP::ObjectId object_id, JDWP::FieldId field_id,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700401 uint64_t value, int width)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700402 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800403 static JDWP::JdwpError GetStaticFieldValue(JDWP::RefTypeId ref_type_id, JDWP::FieldId field_id,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700404 JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700405 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800406 static JDWP::JdwpError SetStaticFieldValue(JDWP::FieldId field_id, uint64_t value, int width)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700407 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700408
Sebastien Hertzb0b0b492014-09-15 11:27:27 +0200409 static JDWP::JdwpError StringToUtf8(JDWP::ObjectId string_id, std::string* str)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700410 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Jeff Hao579b0242013-11-18 13:16:49 -0800411 static void OutputJValue(JDWP::JdwpTag tag, const JValue* return_value, JDWP::ExpandBuf* pReply)
412 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700413
414 /*
415 * Thread, ThreadGroup, Frame
416 */
Ian Rogersc0542af2014-09-03 16:16:56 -0700417 static JDWP::JdwpError GetThreadName(JDWP::ObjectId thread_id, std::string* name)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700418 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_)
419 LOCKS_EXCLUDED(Locks::thread_list_lock_);
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100420 static JDWP::JdwpError GetThreadGroup(JDWP::ObjectId thread_id, JDWP::ExpandBuf* pReply)
Sebastien Hertza06430c2014-09-15 19:21:30 +0200421 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_)
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100422 LOCKS_EXCLUDED(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)
425 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
426 static JDWP::JdwpError GetThreadGroupParent(JDWP::ObjectId thread_group_id,
427 JDWP::ExpandBuf* pReply)
428 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
429 static JDWP::JdwpError GetThreadGroupChildren(JDWP::ObjectId thread_group_id,
430 JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700431 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700432 static JDWP::ObjectId GetSystemThreadGroupId()
Ian Rogersb726dcb2012-09-05 08:57:23 -0700433 SHARED_LOCKS_REQUIRED(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)
439 LOCKS_EXCLUDED(Locks::thread_list_lock_);
440 static JDWP::JdwpError GetThreadDebugSuspendCount(JDWP::ObjectId thread_id,
441 JDWP::ExpandBuf* pReply)
442 LOCKS_EXCLUDED(Locks::thread_list_lock_,
443 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)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700449 LOCKS_EXCLUDED(Locks::thread_list_lock_)
450 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughescaf76542012-06-28 16:08:22 -0700451
Ian Rogersc0542af2014-09-03 16:16:56 -0700452 static JDWP::JdwpError GetThreadFrameCount(JDWP::ObjectId thread_id, size_t* result)
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100453 LOCKS_EXCLUDED(Locks::thread_list_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700454 static JDWP::JdwpError GetThreadFrames(JDWP::ObjectId thread_id, size_t start_frame,
455 size_t frame_count, JDWP::ExpandBuf* buf)
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100456 LOCKS_EXCLUDED(Locks::thread_list_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700457 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700458
Sebastien Hertz6995c602014-09-09 12:10:13 +0200459 static JDWP::ObjectId GetThreadSelfId() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
460 static JDWP::ObjectId GetThreadId(Thread* thread) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
461
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700462 static void SuspendVM()
Ian Rogersb726dcb2012-09-05 08:57:23 -0700463 LOCKS_EXCLUDED(Locks::thread_list_lock_,
464 Locks::thread_suspend_count_lock_);
Sebastien Hertz253fa552014-10-14 17:27:15 +0200465 static void ResumeVM()
466 LOCKS_EXCLUDED(Locks::thread_list_lock_,
467 Locks::thread_suspend_count_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800468 static JDWP::JdwpError SuspendThread(JDWP::ObjectId thread_id, bool request_suspension = true)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700469 LOCKS_EXCLUDED(Locks::mutator_lock_,
470 Locks::thread_list_lock_,
471 Locks::thread_suspend_count_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700472
Elliott Hughes88d63092013-01-09 09:55:54 -0800473 static void ResumeThread(JDWP::ObjectId thread_id)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700474 LOCKS_EXCLUDED(Locks::thread_list_lock_,
475 Locks::thread_suspend_count_lock_)
476 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700477 static void SuspendSelf();
478
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700479 static JDWP::JdwpError GetThisObject(JDWP::ObjectId thread_id, JDWP::FrameId frame_id,
480 JDWP::ObjectId* result)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700481 LOCKS_EXCLUDED(Locks::thread_list_lock_,
482 Locks::thread_suspend_count_lock_)
483 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertz8009f392014-09-01 17:07:11 +0200484 static JDWP::JdwpError GetLocalValues(JDWP::Request* request, JDWP::ExpandBuf* pReply)
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100485 LOCKS_EXCLUDED(Locks::thread_list_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700486 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertz8009f392014-09-01 17:07:11 +0200487 static JDWP::JdwpError SetLocalValues(JDWP::Request* request)
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100488 LOCKS_EXCLUDED(Locks::thread_list_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700489 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700490
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100491 static JDWP::JdwpError Interrupt(JDWP::ObjectId thread_id)
492 LOCKS_EXCLUDED(Locks::thread_list_lock_);
Elliott Hughesf9501702013-01-11 11:22:27 -0800493
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700494 /*
495 * Debugger notification
496 */
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700497 enum EventFlag {
Elliott Hughes86964332012-02-15 19:37:42 -0800498 kBreakpoint = 0x01,
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700499 kSingleStep = 0x02,
500 kMethodEntry = 0x04,
501 kMethodExit = 0x08,
502 };
Sebastien Hertz3f52eaf2014-04-04 17:50:18 +0200503 static void PostFieldAccessEvent(mirror::ArtMethod* m, int dex_pc, mirror::Object* this_object,
504 mirror::ArtField* f)
505 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
506 static void PostFieldModificationEvent(mirror::ArtMethod* m, int dex_pc,
507 mirror::Object* this_object, mirror::ArtField* f,
508 const JValue* field_value)
509 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
510 static void PostException(const ThrowLocation& throw_location, mirror::ArtMethod* catch_method,
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800511 uint32_t catch_dex_pc, mirror::Throwable* exception)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700512 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700513 static void PostThreadStart(Thread* t)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700514 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700515 static void PostThreadDeath(Thread* t)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700516 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800517 static void PostClassPrepare(mirror::Class* c)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700518 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700519
Ian Rogers62d6c772013-02-27 08:32:07 -0800520 static void UpdateDebugger(Thread* thread, mirror::Object* this_object,
Sebastien Hertz8379b222014-02-24 17:38:15 +0100521 mirror::ArtMethod* method, uint32_t new_dex_pc,
522 int event_flags, const JValue* return_value)
jeffhao09bfc6a2012-12-11 18:11:43 -0800523 LOCKS_EXCLUDED(Locks::breakpoint_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700524 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes91bf6cd2012-02-14 17:27:48 -0800525
Sebastien Hertzf3928792014-11-17 19:00:37 +0100526 // Indicates whether we need deoptimization for debugging.
527 static bool RequiresDeoptimization();
528
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100529 // Records deoptimization request in the queue.
530 static void RequestDeoptimization(const DeoptimizationRequest& req)
Brian Carlstrom306db812014-09-05 13:01:41 -0700531 LOCKS_EXCLUDED(Locks::deoptimization_lock_)
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100532 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
533
Sebastien Hertz7ec2f1c2014-03-27 20:06:47 +0100534 // Support delayed full undeoptimization requests. This is currently only used for single-step
535 // events.
Brian Carlstrom306db812014-09-05 13:01:41 -0700536 static void DelayFullUndeoptimization() LOCKS_EXCLUDED(Locks::deoptimization_lock_);
Sebastien Hertz7ec2f1c2014-03-27 20:06:47 +0100537 static void ProcessDelayedFullUndeoptimizations()
Brian Carlstrom306db812014-09-05 13:01:41 -0700538 LOCKS_EXCLUDED(Locks::deoptimization_lock_)
Sebastien Hertz7ec2f1c2014-03-27 20:06:47 +0100539 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
540
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100541 // Manage deoptimization after updating JDWP events list. Suspends all threads, processes each
542 // request and finally resumes all threads.
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100543 static void ManageDeoptimization()
Brian Carlstrom306db812014-09-05 13:01:41 -0700544 LOCKS_EXCLUDED(Locks::deoptimization_lock_)
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100545 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
546
547 // Breakpoints.
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100548 static void WatchLocation(const JDWP::JdwpLocation* pLoc, DeoptimizationRequest* req)
549 LOCKS_EXCLUDED(Locks::breakpoint_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700550 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100551 static void UnwatchLocation(const JDWP::JdwpLocation* pLoc, DeoptimizationRequest* req)
552 LOCKS_EXCLUDED(Locks::breakpoint_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700553 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100554
555 // Single-stepping.
Elliott Hughes88d63092013-01-09 09:55:54 -0800556 static JDWP::JdwpError ConfigureStep(JDWP::ObjectId thread_id, JDWP::JdwpStepSize size,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700557 JDWP::JdwpStepDepth depth)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700558 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +0100559 static void UnconfigureStep(JDWP::ObjectId thread_id)
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100560 LOCKS_EXCLUDED(Locks::thread_list_lock_)
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +0100561 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700562
Elliott Hughes88d63092013-01-09 09:55:54 -0800563 static JDWP::JdwpError InvokeMethod(JDWP::ObjectId thread_id, JDWP::ObjectId object_id,
564 JDWP::RefTypeId class_id, JDWP::MethodId method_id,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700565 uint32_t arg_count, uint64_t* arg_values,
566 JDWP::JdwpTag* arg_types, uint32_t options,
567 JDWP::JdwpTag* pResultTag, uint64_t* pResultValue,
568 JDWP::ObjectId* pExceptObj)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700569 LOCKS_EXCLUDED(Locks::thread_list_lock_,
570 Locks::thread_suspend_count_lock_)
571 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700572 static void ExecuteMethod(DebugInvokeReq* pReq);
573
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700574 /*
575 * DDM support.
576 */
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700577 static void DdmSendThreadNotification(Thread* t, uint32_t type)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700578 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100579 static void DdmSetThreadNotification(bool enable)
580 LOCKS_EXCLUDED(Locks::thread_list_lock_);
Ian Rogersc0542af2014-09-03 16:16:56 -0700581 static bool DdmHandlePacket(JDWP::Request* request, uint8_t** pReplyBuf, int* pReplyLen);
Ian Rogersb726dcb2012-09-05 08:57:23 -0700582 static void DdmConnected() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
583 static void DdmDisconnected() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700584 static void DdmSendChunk(uint32_t type, const std::vector<uint8_t>& bytes)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700585 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700586 static void DdmSendChunk(uint32_t type, size_t len, const uint8_t* buf)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700587 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700588 static void DdmSendChunkV(uint32_t type, const iovec* iov, int iov_count)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700589 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes767a1472011-10-26 18:49:02 -0700590
Mathieu Chartier3b05e9b2014-03-25 09:29:43 -0700591 static void VisitRoots(RootCallback* callback, void* arg)
592 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
593
Elliott Hughes545a0642011-11-08 19:10:03 -0800594 /*
595 * Recent allocation tracking support.
596 */
Ian Rogers844506b2014-09-12 19:59:33 -0700597 static void RecordAllocation(Thread* self, mirror::Class* type, size_t byte_count)
Brian Carlstrom306db812014-09-05 13:01:41 -0700598 LOCKS_EXCLUDED(Locks::alloc_tracker_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700599 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom306db812014-09-05 13:01:41 -0700600 static void SetAllocTrackingEnabled(bool enabled) LOCKS_EXCLUDED(Locks::alloc_tracker_lock_);
Ian Rogers719d1a32014-03-06 12:13:39 -0800601 static bool IsAllocTrackingEnabled() {
602 return recent_allocation_records_ != nullptr;
603 }
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100604 static jbyteArray GetRecentAllocations()
Brian Carlstrom306db812014-09-05 13:01:41 -0700605 LOCKS_EXCLUDED(Locks::alloc_tracker_lock_)
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100606 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom306db812014-09-05 13:01:41 -0700607 static size_t HeadIndex() EXCLUSIVE_LOCKS_REQUIRED(Locks::alloc_tracker_lock_);
608 static void DumpRecentAllocations() LOCKS_EXCLUDED(Locks::alloc_tracker_lock_);
Elliott Hughes545a0642011-11-08 19:10:03 -0800609
Elliott Hughes767a1472011-10-26 18:49:02 -0700610 enum HpifWhen {
611 HPIF_WHEN_NEVER = 0,
612 HPIF_WHEN_NOW = 1,
613 HPIF_WHEN_NEXT_GC = 2,
614 HPIF_WHEN_EVERY_GC = 3
615 };
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700616 static int DdmHandleHpifChunk(HpifWhen when)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700617 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes767a1472011-10-26 18:49:02 -0700618
619 enum HpsgWhen {
620 HPSG_WHEN_NEVER = 0,
621 HPSG_WHEN_EVERY_GC = 1,
622 };
623 enum HpsgWhat {
624 HPSG_WHAT_MERGED_OBJECTS = 0,
625 HPSG_WHAT_DISTINCT_OBJECTS = 1,
626 };
627 static bool DdmHandleHpsgNhsgChunk(HpsgWhen when, HpsgWhat what, bool native);
628
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700629 static void DdmSendHeapInfo(HpifWhen reason)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700630 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700631 static void DdmSendHeapSegments(bool native)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700632 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes545a0642011-11-08 19:10:03 -0800633
Sebastien Hertz6995c602014-09-09 12:10:13 +0200634 static ObjectRegistry* GetObjectRegistry() {
635 return gRegistry;
636 }
637
638 static JDWP::JdwpTag TagFromObject(const ScopedObjectAccessUnchecked& soa, mirror::Object* o)
639 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
640
641 static JDWP::JdwpTypeTag GetTypeTag(mirror::Class* klass)
642 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
643
644 static JDWP::FieldId ToFieldId(const mirror::ArtField* f)
645 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
646
647 static void SetJdwpLocation(JDWP::JdwpLocation* location, mirror::ArtMethod* m, uint32_t dex_pc)
648 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
649
Mathieu Chartierad466ad2015-01-08 16:28:08 -0800650 static JDWP::JdwpState* GetJdwpState();
651
Elliott Hughes545a0642011-11-08 19:10:03 -0800652 private:
Sebastien Hertz8009f392014-09-01 17:07:11 +0200653 static JDWP::JdwpError GetLocalValue(const StackVisitor& visitor,
654 ScopedObjectAccessUnchecked& soa, int slot,
655 JDWP::JdwpTag tag, uint8_t* buf, size_t width)
656 LOCKS_EXCLUDED(Locks::thread_list_lock_)
657 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
658 static JDWP::JdwpError SetLocalValue(StackVisitor& visitor, int slot, JDWP::JdwpTag tag,
659 uint64_t value, size_t width)
660 LOCKS_EXCLUDED(Locks::thread_list_lock_)
661 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
662
Brian Carlstrom2d888622013-07-18 17:02:00 -0700663 static void DdmBroadcast(bool connect) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700664 static void PostThreadStartOrStop(Thread*, uint32_t)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700665 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughesa2155262011-11-16 16:26:58 -0800666
Sebastien Hertz8379b222014-02-24 17:38:15 +0100667 static void PostLocationEvent(mirror::ArtMethod* method, int pcOffset,
668 mirror::Object* thisPtr, int eventFlags,
669 const JValue* return_value)
670 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
671
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100672 static void ProcessDeoptimizationRequest(const DeoptimizationRequest& request)
673 EXCLUSIVE_LOCKS_REQUIRED(Locks::mutator_lock_);
674
Sebastien Hertz7ec2f1c2014-03-27 20:06:47 +0100675 static void RequestDeoptimizationLocked(const DeoptimizationRequest& req)
Brian Carlstrom306db812014-09-05 13:01:41 -0700676 EXCLUSIVE_LOCKS_REQUIRED(Locks::deoptimization_lock_)
Sebastien Hertz7ec2f1c2014-03-27 20:06:47 +0100677 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
678
Brian Carlstrom306db812014-09-05 13:01:41 -0700679 static AllocRecord* recent_allocation_records_ PT_GUARDED_BY(Locks::alloc_tracker_lock_);
680 static size_t alloc_record_max_ GUARDED_BY(Locks::alloc_tracker_lock_);
681 static size_t alloc_record_head_ GUARDED_BY(Locks::alloc_tracker_lock_);
682 static size_t alloc_record_count_ GUARDED_BY(Locks::alloc_tracker_lock_);
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100683
Sebastien Hertz6995c602014-09-09 12:10:13 +0200684 static ObjectRegistry* gRegistry;
685
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100686 // Deoptimization requests to be processed each time the event list is updated. This is used when
687 // registering and unregistering events so we do not deoptimize while holding the event list
688 // lock.
Sebastien Hertz42cd43f2014-05-13 14:15:41 +0200689 // TODO rename to instrumentation_requests.
Brian Carlstrom306db812014-09-05 13:01:41 -0700690 static std::vector<DeoptimizationRequest> deoptimization_requests_ GUARDED_BY(Locks::deoptimization_lock_);
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100691
692 // Count the number of events requiring full deoptimization. When the counter is > 0, everything
693 // is deoptimized, otherwise everything is undeoptimized.
694 // Note: we fully deoptimize on the first event only (when the counter is set to 1). We fully
695 // undeoptimize when the last event is unregistered (when the counter is set to 0).
Brian Carlstrom306db812014-09-05 13:01:41 -0700696 static size_t full_deoptimization_event_count_ GUARDED_BY(Locks::deoptimization_lock_);
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100697
Sebastien Hertz7ec2f1c2014-03-27 20:06:47 +0100698 // Count the number of full undeoptimization requests delayed to next resume or end of debug
699 // session.
Brian Carlstrom306db812014-09-05 13:01:41 -0700700 static size_t delayed_full_undeoptimization_count_ GUARDED_BY(Locks::deoptimization_lock_);
Sebastien Hertz7ec2f1c2014-03-27 20:06:47 +0100701
Sebastien Hertz42cd43f2014-05-13 14:15:41 +0200702 static size_t* GetReferenceCounterForEvent(uint32_t instrumentation_event);
703
Mathieu Chartier4345c462014-06-27 10:20:14 -0700704 // Weak global type cache, TODO improve this.
Brian Carlstrom306db812014-09-05 13:01:41 -0700705 static TypeCache type_cache_ GUARDED_BY(Locks::alloc_tracker_lock_);
Mathieu Chartier4345c462014-06-27 10:20:14 -0700706
Sebastien Hertz42cd43f2014-05-13 14:15:41 +0200707 // Instrumentation event reference counters.
708 // TODO we could use an array instead of having all these dedicated counters. Instrumentation
709 // events are bits of a mask so we could convert them to array index.
Brian Carlstrom306db812014-09-05 13:01:41 -0700710 static size_t dex_pc_change_event_ref_count_ GUARDED_BY(Locks::deoptimization_lock_);
711 static size_t method_enter_event_ref_count_ GUARDED_BY(Locks::deoptimization_lock_);
712 static size_t method_exit_event_ref_count_ GUARDED_BY(Locks::deoptimization_lock_);
713 static size_t field_read_event_ref_count_ GUARDED_BY(Locks::deoptimization_lock_);
714 static size_t field_write_event_ref_count_ GUARDED_BY(Locks::deoptimization_lock_);
715 static size_t exception_catch_event_ref_count_ GUARDED_BY(Locks::deoptimization_lock_);
Sebastien Hertz42cd43f2014-05-13 14:15:41 +0200716 static uint32_t instrumentation_events_ GUARDED_BY(Locks::mutator_lock_);
717
Brian Carlstrom306db812014-09-05 13:01:41 -0700718 friend class AllocRecord; // For type_cache_ with proper annotalysis.
Ian Rogers719d1a32014-03-06 12:13:39 -0800719 DISALLOW_COPY_AND_ASSIGN(Dbg);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700720};
721
722#define CHUNK_TYPE(_name) \
Elliott Hughes82188472011-11-07 18:11:48 -0800723 static_cast<uint32_t>((_name)[0] << 24 | (_name)[1] << 16 | (_name)[2] << 8 | (_name)[3])
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700724
725} // namespace art
726
Brian Carlstromfc0e3212013-07-17 14:40:12 -0700727#endif // ART_RUNTIME_DEBUGGER_H_