blob: 5f81bc811b5db8e0435bdedc7c93d5ceaf952109 [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 Hertzd5391672014-09-09 12:10:13 +020046class ObjectRegistry;
47class ScopedObjectAccessUnchecked;
Ian Rogers1b09b092012-08-20 15:35:52 -070048class Thread;
Ian Rogers62d6c772013-02-27 08:32:07 -080049class ThrowLocation;
Elliott Hughes872d4ec2011-10-21 17:07:15 -070050
51/*
52 * Invoke-during-breakpoint support.
53 */
54struct DebugInvokeReq {
Elliott Hughes7b3cdfc2011-12-08 21:28:17 -080055 DebugInvokeReq()
Sebastien Hertzd38667a2013-11-25 15:43:54 +010056 : ready(false), invoke_needed(false),
57 receiver(NULL), thread(NULL), klass(NULL), method(NULL),
58 arg_count(0), arg_values(NULL), options(0), error(JDWP::ERR_NONE),
Ian Rogers00f7d0e2012-07-19 15:28:27 -070059 result_tag(JDWP::JT_VOID), exception(0),
Sebastien Hertzd38667a2013-11-25 15:43:54 +010060 lock("a DebugInvokeReq lock", kBreakpointInvokeLock),
61 cond("a DebugInvokeReq condition variable", lock) {
Elliott Hughes475fc232011-10-25 15:00:35 -070062 }
63
Elliott Hughes872d4ec2011-10-21 17:07:15 -070064 /* boolean; only set when we're in the tail end of an event handler */
65 bool ready;
66
67 /* boolean; set if the JDWP thread wants this thread to do work */
Sebastien Hertzd38667a2013-11-25 15:43:54 +010068 bool invoke_needed;
Elliott Hughes872d4ec2011-10-21 17:07:15 -070069
70 /* request */
Sebastien Hertzd38667a2013-11-25 15:43:54 +010071 mirror::Object* receiver; /* not used for ClassType.InvokeMethod */
72 mirror::Object* thread;
73 mirror::Class* klass;
74 mirror::ArtMethod* method;
75 uint32_t arg_count;
76 uint64_t* arg_values; /* will be NULL if arg_count_ == 0 */
77 uint32_t options;
Elliott Hughes872d4ec2011-10-21 17:07:15 -070078
79 /* result */
Elliott Hughes475fc232011-10-25 15:00:35 -070080 JDWP::JdwpError error;
Elliott Hughesd07986f2011-12-06 18:27:45 -080081 JDWP::JdwpTag result_tag;
Elliott Hughes475fc232011-10-25 15:00:35 -070082 JValue result_value;
83 JDWP::ObjectId exception;
Elliott Hughes872d4ec2011-10-21 17:07:15 -070084
85 /* condition variable to wait on while the method executes */
Sebastien Hertzd38667a2013-11-25 15:43:54 +010086 Mutex lock DEFAULT_MUTEX_ACQUIRED_AFTER;
87 ConditionVariable cond GUARDED_BY(lock);
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +010088
Mathieu Chartier3b05e9b2014-03-25 09:29:43 -070089 void VisitRoots(RootCallback* callback, void* arg, uint32_t tid, RootType root_type)
90 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
91
Sebastien Hertzbb43b432014-04-14 11:59:08 +020092 void Clear();
93
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +010094 private:
95 DISALLOW_COPY_AND_ASSIGN(DebugInvokeReq);
96};
97
98// Thread local data-structure that holds fields for controlling single-stepping.
99struct SingleStepControl {
100 SingleStepControl()
101 : is_active(false), step_size(JDWP::SS_MIN), step_depth(JDWP::SD_INTO),
102 method(nullptr), stack_depth(0) {
103 }
104
105 // Are we single-stepping right now?
106 bool is_active;
107
108 // See JdwpStepSize and JdwpStepDepth for details.
109 JDWP::JdwpStepSize step_size;
110 JDWP::JdwpStepDepth step_depth;
111
112 // The location this single-step was initiated from.
113 // A single-step is initiated in a suspended thread. We save here the current method and the
114 // set of DEX pcs associated to the source line number where the suspension occurred.
115 // This is used to support SD_INTO and SD_OVER single-step depths so we detect when a single-step
116 // causes the execution of an instruction in a different method or at a different line number.
117 mirror::ArtMethod* method;
118 std::set<uint32_t> dex_pcs;
119
120 // The stack depth when this single-step was initiated. This is used to support SD_OVER and SD_OUT
121 // single-step depth.
122 int stack_depth;
123
Mathieu Chartier3b05e9b2014-03-25 09:29:43 -0700124 void VisitRoots(RootCallback* callback, void* arg, uint32_t tid, RootType root_type)
125 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
126
Sebastien Hertzbb43b432014-04-14 11:59:08 +0200127 bool ContainsDexPc(uint32_t dex_pc) const;
128
129 void Clear();
130
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +0100131 private:
132 DISALLOW_COPY_AND_ASSIGN(SingleStepControl);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700133};
134
Sebastien Hertz42cd43f2014-05-13 14:15:41 +0200135// TODO rename to InstrumentationRequest.
Hiroshi Yamauchi0ec17d22014-07-07 13:07:08 -0700136class DeoptimizationRequest {
137 public:
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100138 enum Kind {
139 kNothing, // no action.
Sebastien Hertz42cd43f2014-05-13 14:15:41 +0200140 kRegisterForEvent, // start listening for instrumentation event.
141 kUnregisterForEvent, // stop listening for instrumentation event.
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100142 kFullDeoptimization, // deoptimize everything.
143 kFullUndeoptimization, // undeoptimize everything.
144 kSelectiveDeoptimization, // deoptimize one method.
145 kSelectiveUndeoptimization // undeoptimize one method.
146 };
147
Hiroshi Yamauchi0ec17d22014-07-07 13:07:08 -0700148 DeoptimizationRequest() : kind_(kNothing), instrumentation_event_(0), method_(nullptr) {}
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100149
Hiroshi Yamauchi0ec17d22014-07-07 13:07:08 -0700150 DeoptimizationRequest(const DeoptimizationRequest& other)
151 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_)
152 : kind_(other.kind_), instrumentation_event_(other.instrumentation_event_) {
153 // Create a new JNI global reference for the method.
154 SetMethod(other.Method());
155 }
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100156
Hiroshi Yamauchi0ec17d22014-07-07 13:07:08 -0700157 mirror::ArtMethod* Method() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
158
159 void SetMethod(mirror::ArtMethod* m) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
160
161 // Name 'Kind()' would collide with the above enum name.
162 Kind GetKind() const {
163 return kind_;
164 }
165
166 void SetKind(Kind kind) {
167 kind_ = kind;
168 }
169
170 uint32_t InstrumentationEvent() const {
171 return instrumentation_event_;
172 }
173
174 void SetInstrumentationEvent(uint32_t instrumentation_event) {
175 instrumentation_event_ = instrumentation_event;
176 }
177
178 private:
179 Kind kind_;
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100180
Sebastien Hertz42cd43f2014-05-13 14:15:41 +0200181 // TODO we could use a union to hold the instrumentation_event and the method since they
182 // respectively have sense only for kRegisterForEvent/kUnregisterForEvent and
183 // kSelectiveDeoptimization/kSelectiveUndeoptimization.
184
185 // Event to start or stop listening to. Only for kRegisterForEvent and kUnregisterForEvent.
Hiroshi Yamauchi0ec17d22014-07-07 13:07:08 -0700186 uint32_t instrumentation_event_;
Sebastien Hertz42cd43f2014-05-13 14:15:41 +0200187
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100188 // Method for selective deoptimization.
Hiroshi Yamauchi0ec17d22014-07-07 13:07:08 -0700189 jmethodID method_;
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100190};
191
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700192class Dbg {
Elliott Hughesff17f1f2012-01-24 18:12:29 -0800193 public:
Mathieu Chartier4345c462014-06-27 10:20:14 -0700194 class TypeCache {
195 public:
196 // Returns a weak global for the input type. Deduplicates.
Brian Carlstromf4cb0362014-09-04 22:15:18 -0700197 jobject Add(mirror::Class* t) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_,
198 Locks::alloc_tracker_lock_);
Mathieu Chartier4345c462014-06-27 10:20:14 -0700199 // Clears the type cache and deletes all the weak global refs.
Brian Carlstromf4cb0362014-09-04 22:15:18 -0700200 void Clear() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_,
201 Locks::alloc_tracker_lock_);
Mathieu Chartier4345c462014-06-27 10:20:14 -0700202
203 private:
204 std::multimap<int32_t, jobject> objects_;
205 };
206
Elliott Hughes3bb81562011-10-21 18:52:59 -0700207 static bool ParseJdwpOptions(const std::string& options);
Elliott Hughes4ffd3132011-10-24 12:06:42 -0700208 static void SetJdwpAllowed(bool allowed);
209
Elliott Hughesd1cc8362011-10-24 16:58:50 -0700210 static void StartJdwp();
211 static void StopJdwp();
212
Elliott Hughes767a1472011-10-26 18:49:02 -0700213 // Invoked by the GC in case we need to keep DDMS informed.
Ian Rogersb726dcb2012-09-05 08:57:23 -0700214 static void GcDidFinish() LOCKS_EXCLUDED(Locks::mutator_lock_);
Elliott Hughes767a1472011-10-26 18:49:02 -0700215
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700216 // Return the DebugInvokeReq for the current thread.
217 static DebugInvokeReq* GetInvokeReq();
218
Elliott Hughes475fc232011-10-25 15:00:35 -0700219 static Thread* GetDebugThread();
220 static void ClearWaitForEventThread();
221
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700222 /*
223 * Enable/disable breakpoints and step modes. Used to provide a heads-up
224 * when the debugger attaches.
225 */
226 static void Connected();
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100227 static void GoActive()
Brian Carlstromf4cb0362014-09-04 22:15:18 -0700228 LOCKS_EXCLUDED(Locks::breakpoint_lock_, Locks::deoptimization_lock_, Locks::mutator_lock_);
229 static void Disconnected() LOCKS_EXCLUDED(Locks::deoptimization_lock_, Locks::mutator_lock_);
Elliott Hughes86964332012-02-15 19:37:42 -0800230 static void Disposed();
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700231
Elliott Hughesc0f09332012-03-26 13:27:06 -0700232 // Returns true if we're actually debugging with a real debugger, false if it's
233 // just DDMS (or nothing at all).
234 static bool IsDebuggerActive();
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700235
Elliott Hughesc0f09332012-03-26 13:27:06 -0700236 // Returns true if we had -Xrunjdwp or -agentlib:jdwp= on the command line.
237 static bool IsJdwpConfigured();
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700238
Elliott Hughes86964332012-02-15 19:37:42 -0800239 static bool IsDisposed();
240
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700241 /*
242 * Time, in milliseconds, since the last debugger activity. Does not
243 * include DDMS activity. Returns -1 if there has been no activity.
244 * Returns 0 if we're in the middle of handling a debugger request.
245 */
246 static int64_t LastDebuggerActivity();
247
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700248 static void UndoDebuggerSuspensions();
249
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700250 /*
251 * Class, Object, Array
252 */
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700253 static std::string GetClassName(JDWP::RefTypeId id)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700254 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertzd5391672014-09-09 12:10:13 +0200255 static std::string GetClassName(mirror::Class* klass)
256 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800257 static JDWP::JdwpError GetClassObject(JDWP::RefTypeId id, JDWP::ObjectId& class_object_id)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700258 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800259 static JDWP::JdwpError GetSuperclass(JDWP::RefTypeId id, JDWP::RefTypeId& superclass_id)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700260 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700261 static JDWP::JdwpError GetClassLoader(JDWP::RefTypeId id, JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700262 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700263 static JDWP::JdwpError GetModifiers(JDWP::RefTypeId id, JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700264 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800265 static JDWP::JdwpError GetReflectedType(JDWP::RefTypeId class_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 void GetClassList(std::vector<JDWP::RefTypeId>& classes)
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 GetClassInfo(JDWP::RefTypeId class_id, JDWP::JdwpTypeTag* pTypeTag,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700270 uint32_t* pStatus, std::string* pDescriptor)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700271 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700272 static void FindLoadedClassBySignature(const char* descriptor, std::vector<JDWP::RefTypeId>& ids)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700273 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes64f574f2013-02-20 14:57:12 -0800274 static JDWP::JdwpError GetReferenceType(JDWP::ObjectId object_id, JDWP::ExpandBuf* pReply)
275 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersfc0e94b2013-09-23 23:51:32 -0700276 static JDWP::JdwpError GetSignature(JDWP::RefTypeId ref_type_id, std::string* signature)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700277 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800278 static JDWP::JdwpError GetSourceFile(JDWP::RefTypeId ref_type_id, std::string& source_file)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700279 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800280 static JDWP::JdwpError GetObjectTag(JDWP::ObjectId object_id, uint8_t& tag)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700281 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughesaed4be92011-12-02 16:16:23 -0800282 static size_t GetTagWidth(JDWP::JdwpTag tag);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700283
Elliott Hughes88d63092013-01-09 09:55:54 -0800284 static JDWP::JdwpError GetArrayLength(JDWP::ObjectId array_id, int& length)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700285 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800286 static JDWP::JdwpError OutputArray(JDWP::ObjectId array_id, int offset, int count,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700287 JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700288 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800289 static JDWP::JdwpError SetArrayElements(JDWP::ObjectId array_id, int offset, int count,
Elliott Hughes4b9702c2013-02-20 18:13:24 -0800290 JDWP::Request& request)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700291 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700292
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700293 static JDWP::ObjectId CreateString(const std::string& str)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700294 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800295 static JDWP::JdwpError CreateObject(JDWP::RefTypeId class_id, JDWP::ObjectId& new_object)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700296 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800297 static JDWP::JdwpError CreateArrayObject(JDWP::RefTypeId array_class_id, uint32_t length,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700298 JDWP::ObjectId& new_array)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700299 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700300
Sebastien Hertzd5391672014-09-09 12:10:13 +0200301 //
302 // Event filtering.
303 //
304 static bool MatchThread(JDWP::ObjectId expected_thread_id, Thread* event_thread)
305 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
306
307 static bool MatchLocation(const JDWP::JdwpLocation& expected_location,
308 const JDWP::EventLocation& event_location)
309 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
310
311 static bool MatchType(mirror::Class* event_class, JDWP::RefTypeId class_id)
312 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
313
314 static bool MatchField(JDWP::RefTypeId expected_type_id, JDWP::FieldId expected_field_id,
315 mirror::ArtField* event_field)
316 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
317
318 static bool MatchInstance(JDWP::ObjectId expected_instance_id, mirror::Object* event_instance)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700319 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700320
Elliott Hughesec0f83d2013-01-15 16:54:08 -0800321 //
322 // Monitors.
323 //
324 static JDWP::JdwpError GetMonitorInfo(JDWP::ObjectId object_id, JDWP::ExpandBuf* reply)
325 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
326 static JDWP::JdwpError GetOwnedMonitors(JDWP::ObjectId thread_id,
327 std::vector<JDWP::ObjectId>& monitors,
328 std::vector<uint32_t>& stack_depths)
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100329 LOCKS_EXCLUDED(Locks::thread_list_lock_)
Elliott Hughesec0f83d2013-01-15 16:54:08 -0800330 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100331 static JDWP::JdwpError GetContendedMonitor(JDWP::ObjectId thread_id,
332 JDWP::ObjectId& contended_monitor)
333 LOCKS_EXCLUDED(Locks::thread_list_lock_)
Elliott Hughesec0f83d2013-01-15 16:54:08 -0800334 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
335
336 //
337 // Heap.
338 //
339 static JDWP::JdwpError GetInstanceCounts(const std::vector<JDWP::RefTypeId>& class_ids,
340 std::vector<uint64_t>& counts)
341 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes3b78c942013-01-15 17:35:41 -0800342 static JDWP::JdwpError GetInstances(JDWP::RefTypeId class_id, int32_t max_count,
343 std::vector<JDWP::ObjectId>& instances)
344 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes0cbaff52013-01-16 15:28:01 -0800345 static JDWP::JdwpError GetReferringObjects(JDWP::ObjectId object_id, int32_t max_count,
346 std::vector<JDWP::ObjectId>& referring_objects)
347 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes64f574f2013-02-20 14:57:12 -0800348 static JDWP::JdwpError DisableCollection(JDWP::ObjectId object_id)
349 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
350 static JDWP::JdwpError EnableCollection(JDWP::ObjectId object_id)
351 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
352 static JDWP::JdwpError IsCollected(JDWP::ObjectId object_id, bool& is_collected)
353 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
354 static void DisposeObject(JDWP::ObjectId object_id, uint32_t reference_count)
355 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughesec0f83d2013-01-15 16:54:08 -0800356
Elliott Hughes9777ba22013-01-17 09:04:19 -0800357 //
358 // Methods and fields.
359 //
Elliott Hughesa96836a2013-01-17 12:27:49 -0800360 static std::string GetMethodName(JDWP::MethodId method_id)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700361 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800362 static JDWP::JdwpError OutputDeclaredFields(JDWP::RefTypeId ref_type_id, bool with_generic,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700363 JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700364 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800365 static JDWP::JdwpError OutputDeclaredMethods(JDWP::RefTypeId ref_type_id, bool with_generic,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700366 JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700367 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800368 static JDWP::JdwpError OutputDeclaredInterfaces(JDWP::RefTypeId ref_type_id,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700369 JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700370 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800371 static void OutputLineTable(JDWP::RefTypeId ref_type_id, JDWP::MethodId method_id,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700372 JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700373 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800374 static void OutputVariableTable(JDWP::RefTypeId ref_type_id, JDWP::MethodId id, bool with_generic,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700375 JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700376 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Jeff Hao579b0242013-11-18 13:16:49 -0800377 static void OutputMethodReturnValue(JDWP::MethodId method_id, const JValue* return_value,
378 JDWP::ExpandBuf* pReply)
379 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertz3f52eaf2014-04-04 17:50:18 +0200380 static void OutputFieldValue(JDWP::FieldId field_id, const JValue* field_value,
381 JDWP::ExpandBuf* pReply)
382 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes9777ba22013-01-17 09:04:19 -0800383 static JDWP::JdwpError GetBytecodes(JDWP::RefTypeId class_id, JDWP::MethodId method_id,
384 std::vector<uint8_t>& bytecodes)
385 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700386
Elliott Hughesa96836a2013-01-17 12:27:49 -0800387 static std::string GetFieldName(JDWP::FieldId field_id)
388 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800389 static JDWP::JdwpTag GetFieldBasicTag(JDWP::FieldId field_id)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700390 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800391 static JDWP::JdwpTag GetStaticFieldBasicTag(JDWP::FieldId field_id)
Brian Carlstromf69863b2013-07-17 21:53:13 -0700392 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800393 static JDWP::JdwpError GetFieldValue(JDWP::ObjectId object_id, JDWP::FieldId field_id,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700394 JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700395 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800396 static JDWP::JdwpError SetFieldValue(JDWP::ObjectId object_id, JDWP::FieldId field_id,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700397 uint64_t value, int width)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700398 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800399 static JDWP::JdwpError GetStaticFieldValue(JDWP::RefTypeId ref_type_id, JDWP::FieldId field_id,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700400 JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700401 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800402 static JDWP::JdwpError SetStaticFieldValue(JDWP::FieldId field_id, uint64_t value, int width)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700403 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700404
Elliott Hughes88d63092013-01-09 09:55:54 -0800405 static std::string StringToUtf8(JDWP::ObjectId string_id)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700406 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Jeff Hao579b0242013-11-18 13:16:49 -0800407 static void OutputJValue(JDWP::JdwpTag tag, const JValue* return_value, JDWP::ExpandBuf* pReply)
408 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700409
410 /*
411 * Thread, ThreadGroup, Frame
412 */
Elliott Hughes88d63092013-01-09 09:55:54 -0800413 static JDWP::JdwpError GetThreadName(JDWP::ObjectId thread_id, std::string& name)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700414 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_)
415 LOCKS_EXCLUDED(Locks::thread_list_lock_);
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100416 static JDWP::JdwpError GetThreadGroup(JDWP::ObjectId thread_id, JDWP::ExpandBuf* pReply)
417 LOCKS_EXCLUDED(Locks::thread_list_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800418 static std::string GetThreadGroupName(JDWP::ObjectId thread_group_id);
419 static JDWP::ObjectId GetThreadGroupParent(JDWP::ObjectId thread_group_id)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700420 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700421 static JDWP::ObjectId GetSystemThreadGroupId()
Ian Rogersb726dcb2012-09-05 08:57:23 -0700422 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700423 static JDWP::ObjectId GetMainThreadGroupId();
424
Jeff Hao920af3e2013-08-28 15:46:38 -0700425 static JDWP::JdwpThreadStatus ToJdwpThreadStatus(ThreadState state);
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100426 static JDWP::JdwpError GetThreadStatus(JDWP::ObjectId thread_id,
427 JDWP::JdwpThreadStatus* pThreadStatus,
428 JDWP::JdwpSuspendStatus* pSuspendStatus)
429 LOCKS_EXCLUDED(Locks::thread_list_lock_);
430 static JDWP::JdwpError GetThreadDebugSuspendCount(JDWP::ObjectId thread_id,
431 JDWP::ExpandBuf* pReply)
432 LOCKS_EXCLUDED(Locks::thread_list_lock_,
433 Locks::thread_suspend_count_lock_);
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700434 // static void WaitForSuspend(JDWP::ObjectId thread_id);
Elliott Hughescaf76542012-06-28 16:08:22 -0700435
Elliott Hughes026b1462012-06-28 20:43:49 -0700436 // Fills 'thread_ids' with the threads in the given thread group. If thread_group_id == 0,
Elliott Hughescaf76542012-06-28 16:08:22 -0700437 // returns all threads.
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700438 static void GetThreads(JDWP::ObjectId thread_group_id, std::vector<JDWP::ObjectId>& thread_ids)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700439 LOCKS_EXCLUDED(Locks::thread_list_lock_)
440 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughescaf76542012-06-28 16:08:22 -0700441 static void GetChildThreadGroups(JDWP::ObjectId thread_group_id, std::vector<JDWP::ObjectId>& child_thread_group_ids);
442
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100443 static JDWP::JdwpError GetThreadFrameCount(JDWP::ObjectId thread_id, size_t& result)
444 LOCKS_EXCLUDED(Locks::thread_list_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700445 static JDWP::JdwpError GetThreadFrames(JDWP::ObjectId thread_id, size_t start_frame,
446 size_t frame_count, JDWP::ExpandBuf* buf)
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100447 LOCKS_EXCLUDED(Locks::thread_list_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700448 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700449
Sebastien Hertzd5391672014-09-09 12:10:13 +0200450 static JDWP::ObjectId GetThreadSelfId() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
451 static JDWP::ObjectId GetThreadId(Thread* thread) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
452
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700453 static void SuspendVM()
Ian Rogersb726dcb2012-09-05 08:57:23 -0700454 LOCKS_EXCLUDED(Locks::thread_list_lock_,
455 Locks::thread_suspend_count_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700456 static void ResumeVM();
Elliott Hughes88d63092013-01-09 09:55:54 -0800457 static JDWP::JdwpError SuspendThread(JDWP::ObjectId thread_id, bool request_suspension = true)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700458 LOCKS_EXCLUDED(Locks::mutator_lock_,
459 Locks::thread_list_lock_,
460 Locks::thread_suspend_count_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700461
Elliott Hughes88d63092013-01-09 09:55:54 -0800462 static void ResumeThread(JDWP::ObjectId thread_id)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700463 LOCKS_EXCLUDED(Locks::thread_list_lock_,
464 Locks::thread_suspend_count_lock_)
465 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700466 static void SuspendSelf();
467
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700468 static JDWP::JdwpError GetThisObject(JDWP::ObjectId thread_id, JDWP::FrameId frame_id,
469 JDWP::ObjectId* result)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700470 LOCKS_EXCLUDED(Locks::thread_list_lock_,
471 Locks::thread_suspend_count_lock_)
472 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertzcb19ebf2014-03-11 15:26:35 +0100473 static JDWP::JdwpError GetLocalValue(JDWP::ObjectId thread_id, JDWP::FrameId frame_id, int slot,
474 JDWP::JdwpTag tag, uint8_t* buf, size_t expectedLen)
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100475 LOCKS_EXCLUDED(Locks::thread_list_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700476 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertzcb19ebf2014-03-11 15:26:35 +0100477 static JDWP::JdwpError SetLocalValue(JDWP::ObjectId thread_id, JDWP::FrameId frame_id, int slot,
478 JDWP::JdwpTag tag, uint64_t value, size_t width)
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100479 LOCKS_EXCLUDED(Locks::thread_list_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700480 SHARED_LOCKS_REQUIRED(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)
483 LOCKS_EXCLUDED(Locks::thread_list_lock_);
Elliott Hughesf9501702013-01-11 11:22:27 -0800484
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700485 /*
486 * Debugger notification
487 */
488 enum {
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 };
Sebastien Hertz3f52eaf2014-04-04 17:50:18 +0200494 static void PostFieldAccessEvent(mirror::ArtMethod* m, int dex_pc, mirror::Object* this_object,
495 mirror::ArtField* f)
496 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
497 static void PostFieldModificationEvent(mirror::ArtMethod* m, int dex_pc,
498 mirror::Object* this_object, mirror::ArtField* f,
499 const JValue* field_value)
500 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
501 static void PostException(const ThrowLocation& throw_location, mirror::ArtMethod* catch_method,
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800502 uint32_t catch_dex_pc, mirror::Throwable* exception)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700503 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700504 static void PostThreadStart(Thread* t)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700505 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700506 static void PostThreadDeath(Thread* t)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700507 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800508 static void PostClassPrepare(mirror::Class* c)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700509 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700510
Ian Rogers62d6c772013-02-27 08:32:07 -0800511 static void UpdateDebugger(Thread* thread, mirror::Object* this_object,
Sebastien Hertz8379b222014-02-24 17:38:15 +0100512 mirror::ArtMethod* method, uint32_t new_dex_pc,
513 int event_flags, const JValue* return_value)
jeffhao09bfc6a2012-12-11 18:11:43 -0800514 LOCKS_EXCLUDED(Locks::breakpoint_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700515 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes91bf6cd2012-02-14 17:27:48 -0800516
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100517 // Records deoptimization request in the queue.
518 static void RequestDeoptimization(const DeoptimizationRequest& req)
Brian Carlstromf4cb0362014-09-04 22:15:18 -0700519 LOCKS_EXCLUDED(Locks::deoptimization_lock_)
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100520 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
521
Sebastien Hertz7ec2f1c2014-03-27 20:06:47 +0100522 // Support delayed full undeoptimization requests. This is currently only used for single-step
523 // events.
Brian Carlstromf4cb0362014-09-04 22:15:18 -0700524 static void DelayFullUndeoptimization() LOCKS_EXCLUDED(Locks::deoptimization_lock_);
Sebastien Hertz7ec2f1c2014-03-27 20:06:47 +0100525 static void ProcessDelayedFullUndeoptimizations()
Brian Carlstromf4cb0362014-09-04 22:15:18 -0700526 LOCKS_EXCLUDED(Locks::deoptimization_lock_)
Sebastien Hertz7ec2f1c2014-03-27 20:06:47 +0100527 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
528
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100529 // Manage deoptimization after updating JDWP events list. Suspends all threads, processes each
530 // request and finally resumes all threads.
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100531 static void ManageDeoptimization()
Brian Carlstromf4cb0362014-09-04 22:15:18 -0700532 LOCKS_EXCLUDED(Locks::deoptimization_lock_)
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100533 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
534
535 // Breakpoints.
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100536 static void WatchLocation(const JDWP::JdwpLocation* pLoc, DeoptimizationRequest* req)
537 LOCKS_EXCLUDED(Locks::breakpoint_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700538 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100539 static void UnwatchLocation(const JDWP::JdwpLocation* pLoc, DeoptimizationRequest* req)
540 LOCKS_EXCLUDED(Locks::breakpoint_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700541 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100542
543 // Single-stepping.
Elliott Hughes88d63092013-01-09 09:55:54 -0800544 static JDWP::JdwpError ConfigureStep(JDWP::ObjectId thread_id, JDWP::JdwpStepSize size,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700545 JDWP::JdwpStepDepth depth)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700546 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +0100547 static void UnconfigureStep(JDWP::ObjectId thread_id)
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100548 LOCKS_EXCLUDED(Locks::thread_list_lock_)
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +0100549 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700550
Elliott Hughes88d63092013-01-09 09:55:54 -0800551 static JDWP::JdwpError InvokeMethod(JDWP::ObjectId thread_id, JDWP::ObjectId object_id,
552 JDWP::RefTypeId class_id, JDWP::MethodId method_id,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700553 uint32_t arg_count, uint64_t* arg_values,
554 JDWP::JdwpTag* arg_types, uint32_t options,
555 JDWP::JdwpTag* pResultTag, uint64_t* pResultValue,
556 JDWP::ObjectId* pExceptObj)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700557 LOCKS_EXCLUDED(Locks::thread_list_lock_,
558 Locks::thread_suspend_count_lock_)
559 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700560 static void ExecuteMethod(DebugInvokeReq* pReq);
561
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700562 /*
563 * DDM support.
564 */
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700565 static void DdmSendThreadNotification(Thread* t, uint32_t type)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700566 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100567 static void DdmSetThreadNotification(bool enable)
568 LOCKS_EXCLUDED(Locks::thread_list_lock_);
Elliott Hughes4b9702c2013-02-20 18:13:24 -0800569 static bool DdmHandlePacket(JDWP::Request& request, uint8_t** pReplyBuf, int* pReplyLen);
Ian Rogersb726dcb2012-09-05 08:57:23 -0700570 static void DdmConnected() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
571 static void DdmDisconnected() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700572 static void DdmSendChunk(uint32_t type, const std::vector<uint8_t>& bytes)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700573 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700574 static void DdmSendChunk(uint32_t type, size_t len, const uint8_t* buf)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700575 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700576 static void DdmSendChunkV(uint32_t type, const iovec* iov, int iov_count)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700577 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes767a1472011-10-26 18:49:02 -0700578
Mathieu Chartier3b05e9b2014-03-25 09:29:43 -0700579 static void VisitRoots(RootCallback* callback, void* arg)
580 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
581
Elliott Hughes545a0642011-11-08 19:10:03 -0800582 /*
583 * Recent allocation tracking support.
584 */
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800585 static void RecordAllocation(mirror::Class* type, size_t byte_count)
Brian Carlstromf4cb0362014-09-04 22:15:18 -0700586 LOCKS_EXCLUDED(Locks::alloc_tracker_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700587 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstromf4cb0362014-09-04 22:15:18 -0700588 static void SetAllocTrackingEnabled(bool enabled) LOCKS_EXCLUDED(Locks::alloc_tracker_lock_);
Ian Rogers719d1a32014-03-06 12:13:39 -0800589 static bool IsAllocTrackingEnabled() {
590 return recent_allocation_records_ != nullptr;
591 }
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100592 static jbyteArray GetRecentAllocations()
Brian Carlstromf4cb0362014-09-04 22:15:18 -0700593 LOCKS_EXCLUDED(Locks::alloc_tracker_lock_)
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100594 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstromf4cb0362014-09-04 22:15:18 -0700595 static size_t HeadIndex() EXCLUSIVE_LOCKS_REQUIRED(Locks::alloc_tracker_lock_);
596 static void DumpRecentAllocations() LOCKS_EXCLUDED(Locks::alloc_tracker_lock_);
Elliott Hughes545a0642011-11-08 19:10:03 -0800597
Elliott Hughes767a1472011-10-26 18:49:02 -0700598 enum HpifWhen {
599 HPIF_WHEN_NEVER = 0,
600 HPIF_WHEN_NOW = 1,
601 HPIF_WHEN_NEXT_GC = 2,
602 HPIF_WHEN_EVERY_GC = 3
603 };
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700604 static int DdmHandleHpifChunk(HpifWhen when)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700605 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes767a1472011-10-26 18:49:02 -0700606
607 enum HpsgWhen {
608 HPSG_WHEN_NEVER = 0,
609 HPSG_WHEN_EVERY_GC = 1,
610 };
611 enum HpsgWhat {
612 HPSG_WHAT_MERGED_OBJECTS = 0,
613 HPSG_WHAT_DISTINCT_OBJECTS = 1,
614 };
615 static bool DdmHandleHpsgNhsgChunk(HpsgWhen when, HpsgWhat what, bool native);
616
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700617 static void DdmSendHeapInfo(HpifWhen reason)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700618 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700619 static void DdmSendHeapSegments(bool native)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700620 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes545a0642011-11-08 19:10:03 -0800621
Sebastien Hertzd5391672014-09-09 12:10:13 +0200622 static ObjectRegistry* GetObjectRegistry() {
623 return gRegistry;
624 }
625
626 static JDWP::JdwpTag TagFromObject(const ScopedObjectAccessUnchecked& soa, mirror::Object* o)
627 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
628
629 static JDWP::JdwpTypeTag GetTypeTag(mirror::Class* klass)
630 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
631
632 static JDWP::FieldId ToFieldId(const mirror::ArtField* f)
633 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
634
635 static void SetJdwpLocation(JDWP::JdwpLocation* location, mirror::ArtMethod* m, uint32_t dex_pc)
636 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
637
Elliott Hughes545a0642011-11-08 19:10:03 -0800638 private:
Brian Carlstrom2d888622013-07-18 17:02:00 -0700639 static void DdmBroadcast(bool connect) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700640 static void PostThreadStartOrStop(Thread*, uint32_t)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700641 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughesa2155262011-11-16 16:26:58 -0800642
Sebastien Hertz8379b222014-02-24 17:38:15 +0100643 static void PostLocationEvent(mirror::ArtMethod* method, int pcOffset,
644 mirror::Object* thisPtr, int eventFlags,
645 const JValue* return_value)
646 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
647
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100648 static void ProcessDeoptimizationRequest(const DeoptimizationRequest& request)
649 EXCLUSIVE_LOCKS_REQUIRED(Locks::mutator_lock_);
650
Sebastien Hertz7ec2f1c2014-03-27 20:06:47 +0100651 static void RequestDeoptimizationLocked(const DeoptimizationRequest& req)
Brian Carlstromf4cb0362014-09-04 22:15:18 -0700652 EXCLUSIVE_LOCKS_REQUIRED(Locks::deoptimization_lock_)
Sebastien Hertz7ec2f1c2014-03-27 20:06:47 +0100653 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
654
Brian Carlstromf4cb0362014-09-04 22:15:18 -0700655 static AllocRecord* recent_allocation_records_ PT_GUARDED_BY(Locks::alloc_tracker_lock_);
656 static size_t alloc_record_max_ GUARDED_BY(Locks::alloc_tracker_lock_);
657 static size_t alloc_record_head_ GUARDED_BY(Locks::alloc_tracker_lock_);
658 static size_t alloc_record_count_ GUARDED_BY(Locks::alloc_tracker_lock_);
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100659
Sebastien Hertzd5391672014-09-09 12:10:13 +0200660 static ObjectRegistry* gRegistry;
661
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100662 // Deoptimization requests to be processed each time the event list is updated. This is used when
663 // registering and unregistering events so we do not deoptimize while holding the event list
664 // lock.
Sebastien Hertz42cd43f2014-05-13 14:15:41 +0200665 // TODO rename to instrumentation_requests.
Brian Carlstromf4cb0362014-09-04 22:15:18 -0700666 static std::vector<DeoptimizationRequest> deoptimization_requests_ GUARDED_BY(Locks::deoptimization_lock_);
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100667
668 // Count the number of events requiring full deoptimization. When the counter is > 0, everything
669 // is deoptimized, otherwise everything is undeoptimized.
670 // Note: we fully deoptimize on the first event only (when the counter is set to 1). We fully
671 // undeoptimize when the last event is unregistered (when the counter is set to 0).
Brian Carlstromf4cb0362014-09-04 22:15:18 -0700672 static size_t full_deoptimization_event_count_ GUARDED_BY(Locks::deoptimization_lock_);
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100673
Sebastien Hertz7ec2f1c2014-03-27 20:06:47 +0100674 // Count the number of full undeoptimization requests delayed to next resume or end of debug
675 // session.
Brian Carlstromf4cb0362014-09-04 22:15:18 -0700676 static size_t delayed_full_undeoptimization_count_ GUARDED_BY(Locks::deoptimization_lock_);
Sebastien Hertz7ec2f1c2014-03-27 20:06:47 +0100677
Sebastien Hertz42cd43f2014-05-13 14:15:41 +0200678 static size_t* GetReferenceCounterForEvent(uint32_t instrumentation_event);
679
Mathieu Chartier4345c462014-06-27 10:20:14 -0700680 // Weak global type cache, TODO improve this.
Brian Carlstromf4cb0362014-09-04 22:15:18 -0700681 static TypeCache type_cache_ GUARDED_BY(Locks::alloc_tracker_lock_);
Mathieu Chartier4345c462014-06-27 10:20:14 -0700682
Sebastien Hertz42cd43f2014-05-13 14:15:41 +0200683 // Instrumentation event reference counters.
684 // TODO we could use an array instead of having all these dedicated counters. Instrumentation
685 // events are bits of a mask so we could convert them to array index.
Brian Carlstromf4cb0362014-09-04 22:15:18 -0700686 static size_t dex_pc_change_event_ref_count_ GUARDED_BY(Locks::deoptimization_lock_);
687 static size_t method_enter_event_ref_count_ GUARDED_BY(Locks::deoptimization_lock_);
688 static size_t method_exit_event_ref_count_ GUARDED_BY(Locks::deoptimization_lock_);
689 static size_t field_read_event_ref_count_ GUARDED_BY(Locks::deoptimization_lock_);
690 static size_t field_write_event_ref_count_ GUARDED_BY(Locks::deoptimization_lock_);
691 static size_t exception_catch_event_ref_count_ GUARDED_BY(Locks::deoptimization_lock_);
Sebastien Hertz42cd43f2014-05-13 14:15:41 +0200692 static uint32_t instrumentation_events_ GUARDED_BY(Locks::mutator_lock_);
693
Brian Carlstromf4cb0362014-09-04 22:15:18 -0700694 friend class AllocRecord; // For type_cache_ with proper annotalysis.
Ian Rogers719d1a32014-03-06 12:13:39 -0800695 DISALLOW_COPY_AND_ASSIGN(Dbg);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700696};
697
698#define CHUNK_TYPE(_name) \
Elliott Hughes82188472011-11-07 18:11:48 -0800699 static_cast<uint32_t>((_name)[0] << 24 | (_name)[1] << 16 | (_name)[2] << 8 | (_name)[3])
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700700
701} // namespace art
702
Brian Carlstromfc0e3212013-07-17 14:40:12 -0700703#endif // ART_RUNTIME_DEBUGGER_H_