blob: cb7adae47acfe0fee5cfc5dfaf6ad423f794365b [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};
192
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700193class Dbg {
Elliott Hughesff17f1f2012-01-24 18:12:29 -0800194 public:
Mathieu Chartier4345c462014-06-27 10:20:14 -0700195 class TypeCache {
196 public:
197 // Returns a weak global for the input type. Deduplicates.
Brian Carlstrom306db812014-09-05 13:01:41 -0700198 jobject Add(mirror::Class* t) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_,
199 Locks::alloc_tracker_lock_);
Mathieu Chartier4345c462014-06-27 10:20:14 -0700200 // Clears the type cache and deletes all the weak global refs.
Brian Carlstrom306db812014-09-05 13:01:41 -0700201 void Clear() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_,
202 Locks::alloc_tracker_lock_);
Mathieu Chartier4345c462014-06-27 10:20:14 -0700203
204 private:
205 std::multimap<int32_t, jobject> objects_;
206 };
207
Elliott Hughes3bb81562011-10-21 18:52:59 -0700208 static bool ParseJdwpOptions(const std::string& options);
Elliott Hughes4ffd3132011-10-24 12:06:42 -0700209 static void SetJdwpAllowed(bool allowed);
210
Elliott Hughesd1cc8362011-10-24 16:58:50 -0700211 static void StartJdwp();
212 static void StopJdwp();
213
Elliott Hughes767a1472011-10-26 18:49:02 -0700214 // Invoked by the GC in case we need to keep DDMS informed.
Ian Rogersb726dcb2012-09-05 08:57:23 -0700215 static void GcDidFinish() LOCKS_EXCLUDED(Locks::mutator_lock_);
Elliott Hughes767a1472011-10-26 18:49:02 -0700216
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700217 // Return the DebugInvokeReq for the current thread.
218 static DebugInvokeReq* GetInvokeReq();
219
Elliott Hughes475fc232011-10-25 15:00:35 -0700220 static Thread* GetDebugThread();
221 static void ClearWaitForEventThread();
222
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700223 /*
224 * Enable/disable breakpoints and step modes. Used to provide a heads-up
225 * when the debugger attaches.
226 */
227 static void Connected();
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100228 static void GoActive()
Brian Carlstrom306db812014-09-05 13:01:41 -0700229 LOCKS_EXCLUDED(Locks::breakpoint_lock_, Locks::deoptimization_lock_, Locks::mutator_lock_);
230 static void Disconnected() LOCKS_EXCLUDED(Locks::deoptimization_lock_, Locks::mutator_lock_);
Elliott Hughes86964332012-02-15 19:37:42 -0800231 static void Disposed();
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700232
Elliott Hughesc0f09332012-03-26 13:27:06 -0700233 // Returns true if we're actually debugging with a real debugger, false if it's
234 // just DDMS (or nothing at all).
235 static bool IsDebuggerActive();
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700236
Elliott Hughesc0f09332012-03-26 13:27:06 -0700237 // Returns true if we had -Xrunjdwp or -agentlib:jdwp= on the command line.
238 static bool IsJdwpConfigured();
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700239
Elliott Hughes86964332012-02-15 19:37:42 -0800240 static bool IsDisposed();
241
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700242 /*
243 * Time, in milliseconds, since the last debugger activity. Does not
244 * include DDMS activity. Returns -1 if there has been no activity.
245 * Returns 0 if we're in the middle of handling a debugger request.
246 */
247 static int64_t LastDebuggerActivity();
248
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700249 static void UndoDebuggerSuspensions();
250
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700251 /*
252 * Class, Object, Array
253 */
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700254 static std::string GetClassName(JDWP::RefTypeId id)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700255 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertz6995c602014-09-09 12:10:13 +0200256 static std::string GetClassName(mirror::Class* klass)
257 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersc0542af2014-09-03 16:16:56 -0700258 static JDWP::JdwpError GetClassObject(JDWP::RefTypeId id, JDWP::ObjectId* class_object_id)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700259 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersc0542af2014-09-03 16:16:56 -0700260 static JDWP::JdwpError GetSuperclass(JDWP::RefTypeId id, JDWP::RefTypeId* superclass_id)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700261 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700262 static JDWP::JdwpError GetClassLoader(JDWP::RefTypeId id, JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700263 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700264 static JDWP::JdwpError GetModifiers(JDWP::RefTypeId id, JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700265 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800266 static JDWP::JdwpError GetReflectedType(JDWP::RefTypeId class_id, JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700267 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersc0542af2014-09-03 16:16:56 -0700268 static void GetClassList(std::vector<JDWP::RefTypeId>* classes)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700269 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800270 static JDWP::JdwpError GetClassInfo(JDWP::RefTypeId class_id, JDWP::JdwpTypeTag* pTypeTag,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700271 uint32_t* pStatus, std::string* pDescriptor)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700272 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersc0542af2014-09-03 16:16:56 -0700273 static void FindLoadedClassBySignature(const char* descriptor, std::vector<JDWP::RefTypeId>* ids)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700274 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes64f574f2013-02-20 14:57:12 -0800275 static JDWP::JdwpError GetReferenceType(JDWP::ObjectId object_id, JDWP::ExpandBuf* pReply)
276 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersfc0e94b2013-09-23 23:51:32 -0700277 static JDWP::JdwpError GetSignature(JDWP::RefTypeId ref_type_id, std::string* signature)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700278 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersc0542af2014-09-03 16:16:56 -0700279 static JDWP::JdwpError GetSourceFile(JDWP::RefTypeId ref_type_id, std::string* source_file)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700280 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersc0542af2014-09-03 16:16:56 -0700281 static JDWP::JdwpError GetObjectTag(JDWP::ObjectId object_id, uint8_t* tag)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700282 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughesaed4be92011-12-02 16:16:23 -0800283 static size_t GetTagWidth(JDWP::JdwpTag tag);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700284
Ian Rogersc0542af2014-09-03 16:16:56 -0700285 static JDWP::JdwpError GetArrayLength(JDWP::ObjectId array_id, int32_t* length)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700286 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800287 static JDWP::JdwpError OutputArray(JDWP::ObjectId array_id, int offset, int count,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700288 JDWP::ExpandBuf* pReply)
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 SetArrayElements(JDWP::ObjectId array_id, int offset, int count,
Ian Rogersc0542af2014-09-03 16:16:56 -0700291 JDWP::Request* request)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700292 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700293
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700294 static JDWP::ObjectId CreateString(const std::string& str)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700295 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersc0542af2014-09-03 16:16:56 -0700296 static JDWP::JdwpError CreateObject(JDWP::RefTypeId class_id, JDWP::ObjectId* new_object)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700297 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800298 static JDWP::JdwpError CreateArrayObject(JDWP::RefTypeId array_class_id, uint32_t length,
Ian Rogersc0542af2014-09-03 16:16:56 -0700299 JDWP::ObjectId* new_array)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700300 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700301
Sebastien Hertz6995c602014-09-09 12:10:13 +0200302 //
303 // Event filtering.
304 //
305 static bool MatchThread(JDWP::ObjectId expected_thread_id, Thread* event_thread)
306 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
307
308 static bool MatchLocation(const JDWP::JdwpLocation& expected_location,
309 const JDWP::EventLocation& event_location)
310 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
311
312 static bool MatchType(mirror::Class* event_class, JDWP::RefTypeId class_id)
313 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
314
315 static bool MatchField(JDWP::RefTypeId expected_type_id, JDWP::FieldId expected_field_id,
316 mirror::ArtField* event_field)
317 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
318
319 static bool MatchInstance(JDWP::ObjectId expected_instance_id, mirror::Object* event_instance)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700320 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700321
Elliott Hughesec0f83d2013-01-15 16:54:08 -0800322 //
323 // Monitors.
324 //
325 static JDWP::JdwpError GetMonitorInfo(JDWP::ObjectId object_id, JDWP::ExpandBuf* reply)
326 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
327 static JDWP::JdwpError GetOwnedMonitors(JDWP::ObjectId thread_id,
Ian Rogersc0542af2014-09-03 16:16:56 -0700328 std::vector<JDWP::ObjectId>* monitors,
329 std::vector<uint32_t>* stack_depths)
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100330 LOCKS_EXCLUDED(Locks::thread_list_lock_)
Elliott Hughesec0f83d2013-01-15 16:54:08 -0800331 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100332 static JDWP::JdwpError GetContendedMonitor(JDWP::ObjectId thread_id,
Ian Rogersc0542af2014-09-03 16:16:56 -0700333 JDWP::ObjectId* contended_monitor)
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100334 LOCKS_EXCLUDED(Locks::thread_list_lock_)
Elliott Hughesec0f83d2013-01-15 16:54:08 -0800335 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
336
337 //
338 // Heap.
339 //
340 static JDWP::JdwpError GetInstanceCounts(const std::vector<JDWP::RefTypeId>& class_ids,
Ian Rogersc0542af2014-09-03 16:16:56 -0700341 std::vector<uint64_t>* counts)
Elliott Hughesec0f83d2013-01-15 16:54:08 -0800342 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes3b78c942013-01-15 17:35:41 -0800343 static JDWP::JdwpError GetInstances(JDWP::RefTypeId class_id, int32_t max_count,
Ian Rogersc0542af2014-09-03 16:16:56 -0700344 std::vector<JDWP::ObjectId>* instances)
Elliott Hughes3b78c942013-01-15 17:35:41 -0800345 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes0cbaff52013-01-16 15:28:01 -0800346 static JDWP::JdwpError GetReferringObjects(JDWP::ObjectId object_id, int32_t max_count,
Ian Rogersc0542af2014-09-03 16:16:56 -0700347 std::vector<JDWP::ObjectId>* referring_objects)
Elliott Hughes0cbaff52013-01-16 15:28:01 -0800348 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes64f574f2013-02-20 14:57:12 -0800349 static JDWP::JdwpError DisableCollection(JDWP::ObjectId object_id)
350 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
351 static JDWP::JdwpError EnableCollection(JDWP::ObjectId object_id)
352 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersc0542af2014-09-03 16:16:56 -0700353 static JDWP::JdwpError IsCollected(JDWP::ObjectId object_id, bool* is_collected)
Elliott Hughes64f574f2013-02-20 14:57:12 -0800354 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
355 static void DisposeObject(JDWP::ObjectId object_id, uint32_t reference_count)
356 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughesec0f83d2013-01-15 16:54:08 -0800357
Elliott Hughes9777ba22013-01-17 09:04:19 -0800358 //
359 // Methods and fields.
360 //
Elliott Hughesa96836a2013-01-17 12:27:49 -0800361 static std::string GetMethodName(JDWP::MethodId method_id)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700362 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800363 static JDWP::JdwpError OutputDeclaredFields(JDWP::RefTypeId ref_type_id, bool with_generic,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700364 JDWP::ExpandBuf* pReply)
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 OutputDeclaredMethods(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 OutputDeclaredInterfaces(JDWP::RefTypeId ref_type_id,
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 void OutputLineTable(JDWP::RefTypeId ref_type_id, JDWP::MethodId method_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 OutputVariableTable(JDWP::RefTypeId ref_type_id, JDWP::MethodId id, bool with_generic,
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_);
Jeff Hao579b0242013-11-18 13:16:49 -0800378 static void OutputMethodReturnValue(JDWP::MethodId method_id, const JValue* return_value,
379 JDWP::ExpandBuf* pReply)
380 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertz3f52eaf2014-04-04 17:50:18 +0200381 static void OutputFieldValue(JDWP::FieldId field_id, const JValue* field_value,
382 JDWP::ExpandBuf* pReply)
383 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes9777ba22013-01-17 09:04:19 -0800384 static JDWP::JdwpError GetBytecodes(JDWP::RefTypeId class_id, JDWP::MethodId method_id,
Ian Rogersc0542af2014-09-03 16:16:56 -0700385 std::vector<uint8_t>* bytecodes)
Elliott Hughes9777ba22013-01-17 09:04:19 -0800386 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700387
Elliott Hughesa96836a2013-01-17 12:27:49 -0800388 static std::string GetFieldName(JDWP::FieldId field_id)
389 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800390 static JDWP::JdwpTag GetFieldBasicTag(JDWP::FieldId field_id)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700391 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800392 static JDWP::JdwpTag GetStaticFieldBasicTag(JDWP::FieldId field_id)
Brian Carlstromf69863b2013-07-17 21:53:13 -0700393 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800394 static JDWP::JdwpError GetFieldValue(JDWP::ObjectId object_id, JDWP::FieldId field_id,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700395 JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700396 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800397 static JDWP::JdwpError SetFieldValue(JDWP::ObjectId object_id, JDWP::FieldId field_id,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700398 uint64_t value, int width)
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 GetStaticFieldValue(JDWP::RefTypeId ref_type_id, JDWP::FieldId field_id,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700401 JDWP::ExpandBuf* pReply)
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 SetStaticFieldValue(JDWP::FieldId field_id, uint64_t value, int width)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700404 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700405
Sebastien Hertzb0b0b492014-09-15 11:27:27 +0200406 static JDWP::JdwpError StringToUtf8(JDWP::ObjectId string_id, std::string* str)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700407 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Jeff Hao579b0242013-11-18 13:16:49 -0800408 static void OutputJValue(JDWP::JdwpTag tag, const JValue* return_value, JDWP::ExpandBuf* pReply)
409 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700410
411 /*
412 * Thread, ThreadGroup, Frame
413 */
Ian Rogersc0542af2014-09-03 16:16:56 -0700414 static JDWP::JdwpError GetThreadName(JDWP::ObjectId thread_id, std::string* name)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700415 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_)
416 LOCKS_EXCLUDED(Locks::thread_list_lock_);
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100417 static JDWP::JdwpError GetThreadGroup(JDWP::ObjectId thread_id, JDWP::ExpandBuf* pReply)
Sebastien Hertza06430c2014-09-15 19:21:30 +0200418 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_)
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100419 LOCKS_EXCLUDED(Locks::thread_list_lock_);
Sebastien Hertza06430c2014-09-15 19:21:30 +0200420 static JDWP::JdwpError GetThreadGroupName(JDWP::ObjectId thread_group_id,
421 JDWP::ExpandBuf* pReply)
422 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
423 static JDWP::JdwpError GetThreadGroupParent(JDWP::ObjectId thread_group_id,
424 JDWP::ExpandBuf* pReply)
425 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
426 static JDWP::JdwpError GetThreadGroupChildren(JDWP::ObjectId thread_group_id,
427 JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700428 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700429 static JDWP::ObjectId GetSystemThreadGroupId()
Ian Rogersb726dcb2012-09-05 08:57:23 -0700430 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700431
Jeff Hao920af3e2013-08-28 15:46:38 -0700432 static JDWP::JdwpThreadStatus ToJdwpThreadStatus(ThreadState state);
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100433 static JDWP::JdwpError GetThreadStatus(JDWP::ObjectId thread_id,
434 JDWP::JdwpThreadStatus* pThreadStatus,
435 JDWP::JdwpSuspendStatus* pSuspendStatus)
436 LOCKS_EXCLUDED(Locks::thread_list_lock_);
437 static JDWP::JdwpError GetThreadDebugSuspendCount(JDWP::ObjectId thread_id,
438 JDWP::ExpandBuf* pReply)
439 LOCKS_EXCLUDED(Locks::thread_list_lock_,
440 Locks::thread_suspend_count_lock_);
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700441 // static void WaitForSuspend(JDWP::ObjectId thread_id);
Elliott Hughescaf76542012-06-28 16:08:22 -0700442
Elliott Hughes026b1462012-06-28 20:43:49 -0700443 // Fills 'thread_ids' with the threads in the given thread group. If thread_group_id == 0,
Elliott Hughescaf76542012-06-28 16:08:22 -0700444 // returns all threads.
Sebastien Hertza06430c2014-09-15 19:21:30 +0200445 static void GetThreads(mirror::Object* thread_group, std::vector<JDWP::ObjectId>* thread_ids)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700446 LOCKS_EXCLUDED(Locks::thread_list_lock_)
447 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughescaf76542012-06-28 16:08:22 -0700448
Ian Rogersc0542af2014-09-03 16:16:56 -0700449 static JDWP::JdwpError GetThreadFrameCount(JDWP::ObjectId thread_id, size_t* result)
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100450 LOCKS_EXCLUDED(Locks::thread_list_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700451 static JDWP::JdwpError GetThreadFrames(JDWP::ObjectId thread_id, size_t start_frame,
452 size_t frame_count, JDWP::ExpandBuf* buf)
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100453 LOCKS_EXCLUDED(Locks::thread_list_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700454 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700455
Sebastien Hertz6995c602014-09-09 12:10:13 +0200456 static JDWP::ObjectId GetThreadSelfId() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
457 static JDWP::ObjectId GetThreadId(Thread* thread) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
458
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700459 static void SuspendVM()
Ian Rogersb726dcb2012-09-05 08:57:23 -0700460 LOCKS_EXCLUDED(Locks::thread_list_lock_,
461 Locks::thread_suspend_count_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700462 static void ResumeVM();
Elliott Hughes88d63092013-01-09 09:55:54 -0800463 static JDWP::JdwpError SuspendThread(JDWP::ObjectId thread_id, bool request_suspension = true)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700464 LOCKS_EXCLUDED(Locks::mutator_lock_,
465 Locks::thread_list_lock_,
466 Locks::thread_suspend_count_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700467
Elliott Hughes88d63092013-01-09 09:55:54 -0800468 static void ResumeThread(JDWP::ObjectId thread_id)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700469 LOCKS_EXCLUDED(Locks::thread_list_lock_,
470 Locks::thread_suspend_count_lock_)
471 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700472 static void SuspendSelf();
473
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700474 static JDWP::JdwpError GetThisObject(JDWP::ObjectId thread_id, JDWP::FrameId frame_id,
475 JDWP::ObjectId* result)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700476 LOCKS_EXCLUDED(Locks::thread_list_lock_,
477 Locks::thread_suspend_count_lock_)
478 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertz8009f392014-09-01 17:07:11 +0200479 static JDWP::JdwpError GetLocalValues(JDWP::Request* request, JDWP::ExpandBuf* pReply)
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100480 LOCKS_EXCLUDED(Locks::thread_list_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700481 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertz8009f392014-09-01 17:07:11 +0200482 static JDWP::JdwpError SetLocalValues(JDWP::Request* request)
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100483 LOCKS_EXCLUDED(Locks::thread_list_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700484 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700485
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100486 static JDWP::JdwpError Interrupt(JDWP::ObjectId thread_id)
487 LOCKS_EXCLUDED(Locks::thread_list_lock_);
Elliott Hughesf9501702013-01-11 11:22:27 -0800488
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700489 /*
490 * Debugger notification
491 */
492 enum {
Elliott Hughes86964332012-02-15 19:37:42 -0800493 kBreakpoint = 0x01,
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700494 kSingleStep = 0x02,
495 kMethodEntry = 0x04,
496 kMethodExit = 0x08,
497 };
Sebastien Hertz3f52eaf2014-04-04 17:50:18 +0200498 static void PostFieldAccessEvent(mirror::ArtMethod* m, int dex_pc, mirror::Object* this_object,
499 mirror::ArtField* f)
500 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
501 static void PostFieldModificationEvent(mirror::ArtMethod* m, int dex_pc,
502 mirror::Object* this_object, mirror::ArtField* f,
503 const JValue* field_value)
504 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
505 static void PostException(const ThrowLocation& throw_location, mirror::ArtMethod* catch_method,
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800506 uint32_t catch_dex_pc, mirror::Throwable* exception)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700507 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700508 static void PostThreadStart(Thread* t)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700509 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700510 static void PostThreadDeath(Thread* t)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700511 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800512 static void PostClassPrepare(mirror::Class* c)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700513 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700514
Ian Rogers62d6c772013-02-27 08:32:07 -0800515 static void UpdateDebugger(Thread* thread, mirror::Object* this_object,
Sebastien Hertz8379b222014-02-24 17:38:15 +0100516 mirror::ArtMethod* method, uint32_t new_dex_pc,
517 int event_flags, const JValue* return_value)
jeffhao09bfc6a2012-12-11 18:11:43 -0800518 LOCKS_EXCLUDED(Locks::breakpoint_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700519 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes91bf6cd2012-02-14 17:27:48 -0800520
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100521 // Records deoptimization request in the queue.
522 static void RequestDeoptimization(const DeoptimizationRequest& req)
Brian Carlstrom306db812014-09-05 13:01:41 -0700523 LOCKS_EXCLUDED(Locks::deoptimization_lock_)
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100524 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
525
Sebastien Hertz7ec2f1c2014-03-27 20:06:47 +0100526 // Support delayed full undeoptimization requests. This is currently only used for single-step
527 // events.
Brian Carlstrom306db812014-09-05 13:01:41 -0700528 static void DelayFullUndeoptimization() LOCKS_EXCLUDED(Locks::deoptimization_lock_);
Sebastien Hertz7ec2f1c2014-03-27 20:06:47 +0100529 static void ProcessDelayedFullUndeoptimizations()
Brian Carlstrom306db812014-09-05 13:01:41 -0700530 LOCKS_EXCLUDED(Locks::deoptimization_lock_)
Sebastien Hertz7ec2f1c2014-03-27 20:06:47 +0100531 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
532
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100533 // Manage deoptimization after updating JDWP events list. Suspends all threads, processes each
534 // request and finally resumes all threads.
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100535 static void ManageDeoptimization()
Brian Carlstrom306db812014-09-05 13:01:41 -0700536 LOCKS_EXCLUDED(Locks::deoptimization_lock_)
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100537 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
538
539 // Breakpoints.
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100540 static void WatchLocation(const JDWP::JdwpLocation* pLoc, DeoptimizationRequest* req)
541 LOCKS_EXCLUDED(Locks::breakpoint_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700542 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100543 static void UnwatchLocation(const JDWP::JdwpLocation* pLoc, DeoptimizationRequest* req)
544 LOCKS_EXCLUDED(Locks::breakpoint_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700545 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100546
547 // Single-stepping.
Elliott Hughes88d63092013-01-09 09:55:54 -0800548 static JDWP::JdwpError ConfigureStep(JDWP::ObjectId thread_id, JDWP::JdwpStepSize size,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700549 JDWP::JdwpStepDepth depth)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700550 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +0100551 static void UnconfigureStep(JDWP::ObjectId thread_id)
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100552 LOCKS_EXCLUDED(Locks::thread_list_lock_)
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +0100553 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700554
Elliott Hughes88d63092013-01-09 09:55:54 -0800555 static JDWP::JdwpError InvokeMethod(JDWP::ObjectId thread_id, JDWP::ObjectId object_id,
556 JDWP::RefTypeId class_id, JDWP::MethodId method_id,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700557 uint32_t arg_count, uint64_t* arg_values,
558 JDWP::JdwpTag* arg_types, uint32_t options,
559 JDWP::JdwpTag* pResultTag, uint64_t* pResultValue,
560 JDWP::ObjectId* pExceptObj)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700561 LOCKS_EXCLUDED(Locks::thread_list_lock_,
562 Locks::thread_suspend_count_lock_)
563 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700564 static void ExecuteMethod(DebugInvokeReq* pReq);
565
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700566 /*
567 * DDM support.
568 */
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700569 static void DdmSendThreadNotification(Thread* t, uint32_t type)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700570 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100571 static void DdmSetThreadNotification(bool enable)
572 LOCKS_EXCLUDED(Locks::thread_list_lock_);
Ian Rogersc0542af2014-09-03 16:16:56 -0700573 static bool DdmHandlePacket(JDWP::Request* request, uint8_t** pReplyBuf, int* pReplyLen);
Ian Rogersb726dcb2012-09-05 08:57:23 -0700574 static void DdmConnected() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
575 static void DdmDisconnected() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700576 static void DdmSendChunk(uint32_t type, const std::vector<uint8_t>& bytes)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700577 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700578 static void DdmSendChunk(uint32_t type, size_t len, const uint8_t* buf)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700579 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700580 static void DdmSendChunkV(uint32_t type, const iovec* iov, int iov_count)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700581 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes767a1472011-10-26 18:49:02 -0700582
Mathieu Chartier3b05e9b2014-03-25 09:29:43 -0700583 static void VisitRoots(RootCallback* callback, void* arg)
584 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
585
Elliott Hughes545a0642011-11-08 19:10:03 -0800586 /*
587 * Recent allocation tracking support.
588 */
Ian Rogers844506b2014-09-12 19:59:33 -0700589 static void RecordAllocation(Thread* self, mirror::Class* type, size_t byte_count)
Brian Carlstrom306db812014-09-05 13:01:41 -0700590 LOCKS_EXCLUDED(Locks::alloc_tracker_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700591 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom306db812014-09-05 13:01:41 -0700592 static void SetAllocTrackingEnabled(bool enabled) LOCKS_EXCLUDED(Locks::alloc_tracker_lock_);
Ian Rogers719d1a32014-03-06 12:13:39 -0800593 static bool IsAllocTrackingEnabled() {
594 return recent_allocation_records_ != nullptr;
595 }
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100596 static jbyteArray GetRecentAllocations()
Brian Carlstrom306db812014-09-05 13:01:41 -0700597 LOCKS_EXCLUDED(Locks::alloc_tracker_lock_)
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100598 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom306db812014-09-05 13:01:41 -0700599 static size_t HeadIndex() EXCLUSIVE_LOCKS_REQUIRED(Locks::alloc_tracker_lock_);
600 static void DumpRecentAllocations() LOCKS_EXCLUDED(Locks::alloc_tracker_lock_);
Elliott Hughes545a0642011-11-08 19:10:03 -0800601
Elliott Hughes767a1472011-10-26 18:49:02 -0700602 enum HpifWhen {
603 HPIF_WHEN_NEVER = 0,
604 HPIF_WHEN_NOW = 1,
605 HPIF_WHEN_NEXT_GC = 2,
606 HPIF_WHEN_EVERY_GC = 3
607 };
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700608 static int DdmHandleHpifChunk(HpifWhen when)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700609 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes767a1472011-10-26 18:49:02 -0700610
611 enum HpsgWhen {
612 HPSG_WHEN_NEVER = 0,
613 HPSG_WHEN_EVERY_GC = 1,
614 };
615 enum HpsgWhat {
616 HPSG_WHAT_MERGED_OBJECTS = 0,
617 HPSG_WHAT_DISTINCT_OBJECTS = 1,
618 };
619 static bool DdmHandleHpsgNhsgChunk(HpsgWhen when, HpsgWhat what, bool native);
620
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700621 static void DdmSendHeapInfo(HpifWhen reason)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700622 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700623 static void DdmSendHeapSegments(bool native)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700624 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes545a0642011-11-08 19:10:03 -0800625
Sebastien Hertz6995c602014-09-09 12:10:13 +0200626 static ObjectRegistry* GetObjectRegistry() {
627 return gRegistry;
628 }
629
630 static JDWP::JdwpTag TagFromObject(const ScopedObjectAccessUnchecked& soa, mirror::Object* o)
631 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
632
633 static JDWP::JdwpTypeTag GetTypeTag(mirror::Class* klass)
634 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
635
636 static JDWP::FieldId ToFieldId(const mirror::ArtField* f)
637 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
638
639 static void SetJdwpLocation(JDWP::JdwpLocation* location, mirror::ArtMethod* m, uint32_t dex_pc)
640 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
641
Elliott Hughes545a0642011-11-08 19:10:03 -0800642 private:
Sebastien Hertz8009f392014-09-01 17:07:11 +0200643 static JDWP::JdwpError GetLocalValue(const StackVisitor& visitor,
644 ScopedObjectAccessUnchecked& soa, int slot,
645 JDWP::JdwpTag tag, uint8_t* buf, size_t width)
646 LOCKS_EXCLUDED(Locks::thread_list_lock_)
647 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
648 static JDWP::JdwpError SetLocalValue(StackVisitor& visitor, int slot, JDWP::JdwpTag tag,
649 uint64_t value, size_t width)
650 LOCKS_EXCLUDED(Locks::thread_list_lock_)
651 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
652
Brian Carlstrom2d888622013-07-18 17:02:00 -0700653 static void DdmBroadcast(bool connect) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700654 static void PostThreadStartOrStop(Thread*, uint32_t)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700655 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughesa2155262011-11-16 16:26:58 -0800656
Sebastien Hertz8379b222014-02-24 17:38:15 +0100657 static void PostLocationEvent(mirror::ArtMethod* method, int pcOffset,
658 mirror::Object* thisPtr, int eventFlags,
659 const JValue* return_value)
660 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
661
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100662 static void ProcessDeoptimizationRequest(const DeoptimizationRequest& request)
663 EXCLUSIVE_LOCKS_REQUIRED(Locks::mutator_lock_);
664
Sebastien Hertz7ec2f1c2014-03-27 20:06:47 +0100665 static void RequestDeoptimizationLocked(const DeoptimizationRequest& req)
Brian Carlstrom306db812014-09-05 13:01:41 -0700666 EXCLUSIVE_LOCKS_REQUIRED(Locks::deoptimization_lock_)
Sebastien Hertz7ec2f1c2014-03-27 20:06:47 +0100667 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
668
Brian Carlstrom306db812014-09-05 13:01:41 -0700669 static AllocRecord* recent_allocation_records_ PT_GUARDED_BY(Locks::alloc_tracker_lock_);
670 static size_t alloc_record_max_ GUARDED_BY(Locks::alloc_tracker_lock_);
671 static size_t alloc_record_head_ GUARDED_BY(Locks::alloc_tracker_lock_);
672 static size_t alloc_record_count_ GUARDED_BY(Locks::alloc_tracker_lock_);
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100673
Sebastien Hertz6995c602014-09-09 12:10:13 +0200674 static ObjectRegistry* gRegistry;
675
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100676 // Deoptimization requests to be processed each time the event list is updated. This is used when
677 // registering and unregistering events so we do not deoptimize while holding the event list
678 // lock.
Sebastien Hertz42cd43f2014-05-13 14:15:41 +0200679 // TODO rename to instrumentation_requests.
Brian Carlstrom306db812014-09-05 13:01:41 -0700680 static std::vector<DeoptimizationRequest> deoptimization_requests_ GUARDED_BY(Locks::deoptimization_lock_);
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100681
682 // Count the number of events requiring full deoptimization. When the counter is > 0, everything
683 // is deoptimized, otherwise everything is undeoptimized.
684 // Note: we fully deoptimize on the first event only (when the counter is set to 1). We fully
685 // undeoptimize when the last event is unregistered (when the counter is set to 0).
Brian Carlstrom306db812014-09-05 13:01:41 -0700686 static size_t full_deoptimization_event_count_ GUARDED_BY(Locks::deoptimization_lock_);
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100687
Sebastien Hertz7ec2f1c2014-03-27 20:06:47 +0100688 // Count the number of full undeoptimization requests delayed to next resume or end of debug
689 // session.
Brian Carlstrom306db812014-09-05 13:01:41 -0700690 static size_t delayed_full_undeoptimization_count_ GUARDED_BY(Locks::deoptimization_lock_);
Sebastien Hertz7ec2f1c2014-03-27 20:06:47 +0100691
Sebastien Hertz42cd43f2014-05-13 14:15:41 +0200692 static size_t* GetReferenceCounterForEvent(uint32_t instrumentation_event);
693
Mathieu Chartier4345c462014-06-27 10:20:14 -0700694 // Weak global type cache, TODO improve this.
Brian Carlstrom306db812014-09-05 13:01:41 -0700695 static TypeCache type_cache_ GUARDED_BY(Locks::alloc_tracker_lock_);
Mathieu Chartier4345c462014-06-27 10:20:14 -0700696
Sebastien Hertz42cd43f2014-05-13 14:15:41 +0200697 // Instrumentation event reference counters.
698 // TODO we could use an array instead of having all these dedicated counters. Instrumentation
699 // events are bits of a mask so we could convert them to array index.
Brian Carlstrom306db812014-09-05 13:01:41 -0700700 static size_t dex_pc_change_event_ref_count_ GUARDED_BY(Locks::deoptimization_lock_);
701 static size_t method_enter_event_ref_count_ GUARDED_BY(Locks::deoptimization_lock_);
702 static size_t method_exit_event_ref_count_ GUARDED_BY(Locks::deoptimization_lock_);
703 static size_t field_read_event_ref_count_ GUARDED_BY(Locks::deoptimization_lock_);
704 static size_t field_write_event_ref_count_ GUARDED_BY(Locks::deoptimization_lock_);
705 static size_t exception_catch_event_ref_count_ GUARDED_BY(Locks::deoptimization_lock_);
Sebastien Hertz42cd43f2014-05-13 14:15:41 +0200706 static uint32_t instrumentation_events_ GUARDED_BY(Locks::mutator_lock_);
707
Brian Carlstrom306db812014-09-05 13:01:41 -0700708 friend class AllocRecord; // For type_cache_ with proper annotalysis.
Ian Rogers719d1a32014-03-06 12:13:39 -0800709 DISALLOW_COPY_AND_ASSIGN(Dbg);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700710};
711
712#define CHUNK_TYPE(_name) \
Elliott Hughes82188472011-11-07 18:11:48 -0800713 static_cast<uint32_t>((_name)[0] << 24 | (_name)[1] << 16 | (_name)[2] << 8 | (_name)[3])
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700714
715} // namespace art
716
Brian Carlstromfc0e3212013-07-17 14:40:12 -0700717#endif // ART_RUNTIME_DEBUGGER_H_