blob: 0c22148c9964cad5fbcb1ab22a14d5dad1611c3d [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
Mathieu Chartiere34fa1d2015-01-14 14:55:47 -080031#include "gc_root.h"
Elliott Hughes872d4ec2011-10-21 17:07:15 -070032#include "jdwp/jdwp.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080033#include "jni.h"
34#include "jvalue.h"
Mathieu Chartier83c8ee02014-01-28 14:50:23 -080035#include "object_callbacks.h"
Jeff Hao920af3e2013-08-28 15:46:38 -070036#include "thread_state.h"
Elliott Hughes872d4ec2011-10-21 17:07:15 -070037
38namespace art {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080039namespace mirror {
Sebastien Hertz3f52eaf2014-04-04 17:50:18 +020040class ArtField;
Brian Carlstromea46f952013-07-30 01:26:50 -070041class ArtMethod;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080042class Class;
43class Object;
44class Throwable;
45} // namespace mirror
Hiroshi Yamauchib5a9e3d2014-06-09 12:11:20 -070046class AllocRecord;
Sebastien Hertz6995c602014-09-09 12:10:13 +020047class ObjectRegistry;
48class ScopedObjectAccessUnchecked;
Sebastien Hertz8009f392014-09-01 17:07:11 +020049class StackVisitor;
Ian Rogers1b09b092012-08-20 15:35:52 -070050class Thread;
Ian Rogers62d6c772013-02-27 08:32:07 -080051class ThrowLocation;
Elliott Hughes872d4ec2011-10-21 17:07:15 -070052
53/*
54 * Invoke-during-breakpoint support.
55 */
56struct DebugInvokeReq {
Elliott Hughes7b3cdfc2011-12-08 21:28:17 -080057 DebugInvokeReq()
Sebastien Hertzd38667a2013-11-25 15:43:54 +010058 : ready(false), invoke_needed(false),
59 receiver(NULL), thread(NULL), klass(NULL), method(NULL),
60 arg_count(0), arg_values(NULL), options(0), error(JDWP::ERR_NONE),
Ian Rogers00f7d0e2012-07-19 15:28:27 -070061 result_tag(JDWP::JT_VOID), exception(0),
Sebastien Hertzd38667a2013-11-25 15:43:54 +010062 lock("a DebugInvokeReq lock", kBreakpointInvokeLock),
63 cond("a DebugInvokeReq condition variable", lock) {
Elliott Hughes475fc232011-10-25 15:00:35 -070064 }
65
Elliott Hughes872d4ec2011-10-21 17:07:15 -070066 /* boolean; only set when we're in the tail end of an event handler */
67 bool ready;
68
69 /* boolean; set if the JDWP thread wants this thread to do work */
Sebastien Hertzd38667a2013-11-25 15:43:54 +010070 bool invoke_needed;
Elliott Hughes872d4ec2011-10-21 17:07:15 -070071
72 /* request */
Sebastien Hertzd38667a2013-11-25 15:43:54 +010073 mirror::Object* receiver; /* not used for ClassType.InvokeMethod */
74 mirror::Object* thread;
75 mirror::Class* klass;
76 mirror::ArtMethod* method;
77 uint32_t arg_count;
78 uint64_t* arg_values; /* will be NULL if arg_count_ == 0 */
79 uint32_t options;
Elliott Hughes872d4ec2011-10-21 17:07:15 -070080
81 /* result */
Elliott Hughes475fc232011-10-25 15:00:35 -070082 JDWP::JdwpError error;
Elliott Hughesd07986f2011-12-06 18:27:45 -080083 JDWP::JdwpTag result_tag;
Elliott Hughes475fc232011-10-25 15:00:35 -070084 JValue result_value;
85 JDWP::ObjectId exception;
Elliott Hughes872d4ec2011-10-21 17:07:15 -070086
87 /* condition variable to wait on while the method executes */
Sebastien Hertzd38667a2013-11-25 15:43:54 +010088 Mutex lock DEFAULT_MUTEX_ACQUIRED_AFTER;
89 ConditionVariable cond GUARDED_BY(lock);
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +010090
Mathieu Chartiere34fa1d2015-01-14 14:55:47 -080091 void VisitRoots(RootCallback* callback, void* arg, const RootInfo& root_info)
Mathieu Chartier3b05e9b2014-03-25 09:29:43 -070092 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
93
Sebastien Hertzbb43b432014-04-14 11:59:08 +020094 void Clear();
95
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +010096 private:
97 DISALLOW_COPY_AND_ASSIGN(DebugInvokeReq);
98};
99
100// Thread local data-structure that holds fields for controlling single-stepping.
Sebastien Hertz597c4f02015-01-26 17:37:14 +0100101class SingleStepControl {
102 public:
103 SingleStepControl(JDWP::JdwpStepSize step_size, JDWP::JdwpStepDepth step_depth,
104 int stack_depth, mirror::ArtMethod* method)
105 : step_size_(step_size), step_depth_(step_depth),
106 stack_depth_(stack_depth), method_(method) {
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +0100107 }
108
Sebastien Hertz597c4f02015-01-26 17:37:14 +0100109 JDWP::JdwpStepSize GetStepSize() const {
110 return step_size_;
111 }
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +0100112
Sebastien Hertz597c4f02015-01-26 17:37:14 +0100113 JDWP::JdwpStepDepth GetStepDepth() const {
114 return step_depth_;
115 }
116
117 int GetStackDepth() const {
118 return stack_depth_;
119 }
120
121 mirror::ArtMethod* GetMethod() const {
122 return method_;
123 }
124
125 const std::set<uint32_t>& GetDexPcs() const {
126 return dex_pcs_;
127 }
128
129 void VisitRoots(RootCallback* callback, void* arg, const RootInfo& root_info)
130 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
131
132 void AddDexPc(uint32_t dex_pc);
133
134 bool ContainsDexPc(uint32_t dex_pc) const;
135
136 private:
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +0100137 // See JdwpStepSize and JdwpStepDepth for details.
Sebastien Hertz597c4f02015-01-26 17:37:14 +0100138 const JDWP::JdwpStepSize step_size_;
139 const JDWP::JdwpStepDepth step_depth_;
140
141 // The stack depth when this single-step was initiated. This is used to support SD_OVER and SD_OUT
142 // single-step depth.
143 const int stack_depth_;
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +0100144
145 // The location this single-step was initiated from.
146 // A single-step is initiated in a suspended thread. We save here the current method and the
147 // set of DEX pcs associated to the source line number where the suspension occurred.
148 // This is used to support SD_INTO and SD_OVER single-step depths so we detect when a single-step
149 // causes the execution of an instruction in a different method or at a different line number.
Sebastien Hertz597c4f02015-01-26 17:37:14 +0100150 mirror::ArtMethod* method_;
151 std::set<uint32_t> dex_pcs_;
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +0100152
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +0100153 DISALLOW_COPY_AND_ASSIGN(SingleStepControl);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700154};
155
Sebastien Hertz42cd43f2014-05-13 14:15:41 +0200156// TODO rename to InstrumentationRequest.
Hiroshi Yamauchi0ec17d22014-07-07 13:07:08 -0700157class DeoptimizationRequest {
158 public:
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100159 enum Kind {
160 kNothing, // no action.
Sebastien Hertz42cd43f2014-05-13 14:15:41 +0200161 kRegisterForEvent, // start listening for instrumentation event.
162 kUnregisterForEvent, // stop listening for instrumentation event.
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100163 kFullDeoptimization, // deoptimize everything.
164 kFullUndeoptimization, // undeoptimize everything.
165 kSelectiveDeoptimization, // deoptimize one method.
166 kSelectiveUndeoptimization // undeoptimize one method.
167 };
168
Hiroshi Yamauchi0ec17d22014-07-07 13:07:08 -0700169 DeoptimizationRequest() : kind_(kNothing), instrumentation_event_(0), method_(nullptr) {}
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100170
Hiroshi Yamauchi0ec17d22014-07-07 13:07:08 -0700171 DeoptimizationRequest(const DeoptimizationRequest& other)
172 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_)
173 : kind_(other.kind_), instrumentation_event_(other.instrumentation_event_) {
174 // Create a new JNI global reference for the method.
175 SetMethod(other.Method());
176 }
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100177
Hiroshi Yamauchi0ec17d22014-07-07 13:07:08 -0700178 mirror::ArtMethod* Method() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
179
180 void SetMethod(mirror::ArtMethod* m) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
181
182 // Name 'Kind()' would collide with the above enum name.
183 Kind GetKind() const {
184 return kind_;
185 }
186
187 void SetKind(Kind kind) {
188 kind_ = kind;
189 }
190
191 uint32_t InstrumentationEvent() const {
192 return instrumentation_event_;
193 }
194
195 void SetInstrumentationEvent(uint32_t instrumentation_event) {
196 instrumentation_event_ = instrumentation_event;
197 }
198
199 private:
200 Kind kind_;
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100201
Sebastien Hertz42cd43f2014-05-13 14:15:41 +0200202 // TODO we could use a union to hold the instrumentation_event and the method since they
203 // respectively have sense only for kRegisterForEvent/kUnregisterForEvent and
204 // kSelectiveDeoptimization/kSelectiveUndeoptimization.
205
206 // Event to start or stop listening to. Only for kRegisterForEvent and kUnregisterForEvent.
Hiroshi Yamauchi0ec17d22014-07-07 13:07:08 -0700207 uint32_t instrumentation_event_;
Sebastien Hertz42cd43f2014-05-13 14:15:41 +0200208
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100209 // Method for selective deoptimization.
Hiroshi Yamauchi0ec17d22014-07-07 13:07:08 -0700210 jmethodID method_;
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100211};
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700212std::ostream& operator<<(std::ostream& os, const DeoptimizationRequest::Kind& rhs);
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100213
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700214class Dbg {
Elliott Hughesff17f1f2012-01-24 18:12:29 -0800215 public:
Mathieu Chartier4345c462014-06-27 10:20:14 -0700216 class TypeCache {
217 public:
218 // Returns a weak global for the input type. Deduplicates.
Brian Carlstrom306db812014-09-05 13:01:41 -0700219 jobject Add(mirror::Class* t) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_,
220 Locks::alloc_tracker_lock_);
Mathieu Chartier4345c462014-06-27 10:20:14 -0700221 // Clears the type cache and deletes all the weak global refs.
Brian Carlstrom306db812014-09-05 13:01:41 -0700222 void Clear() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_,
223 Locks::alloc_tracker_lock_);
Mathieu Chartier4345c462014-06-27 10:20:14 -0700224
225 private:
226 std::multimap<int32_t, jobject> objects_;
227 };
228
Elliott Hughes4ffd3132011-10-24 12:06:42 -0700229 static void SetJdwpAllowed(bool allowed);
230
Sebastien Hertzb3b173b2015-02-06 09:16:32 +0100231 static void StartJdwp();
Elliott Hughesd1cc8362011-10-24 16:58:50 -0700232 static void StopJdwp();
233
Elliott Hughes767a1472011-10-26 18:49:02 -0700234 // Invoked by the GC in case we need to keep DDMS informed.
Ian Rogersb726dcb2012-09-05 08:57:23 -0700235 static void GcDidFinish() LOCKS_EXCLUDED(Locks::mutator_lock_);
Elliott Hughes767a1472011-10-26 18:49:02 -0700236
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700237 // Return the DebugInvokeReq for the current thread.
238 static DebugInvokeReq* GetInvokeReq();
239
Elliott Hughes475fc232011-10-25 15:00:35 -0700240 static Thread* GetDebugThread();
241 static void ClearWaitForEventThread();
242
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700243 /*
244 * Enable/disable breakpoints and step modes. Used to provide a heads-up
245 * when the debugger attaches.
246 */
247 static void Connected();
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100248 static void GoActive()
Brian Carlstrom306db812014-09-05 13:01:41 -0700249 LOCKS_EXCLUDED(Locks::breakpoint_lock_, Locks::deoptimization_lock_, Locks::mutator_lock_);
250 static void Disconnected() LOCKS_EXCLUDED(Locks::deoptimization_lock_, Locks::mutator_lock_);
Elliott Hughes86964332012-02-15 19:37:42 -0800251 static void Disposed();
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700252
Elliott Hughesc0f09332012-03-26 13:27:06 -0700253 // Returns true if we're actually debugging with a real debugger, false if it's
254 // just DDMS (or nothing at all).
255 static bool IsDebuggerActive();
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700256
Sebastien Hertzb3b173b2015-02-06 09:16:32 +0100257 // Configures JDWP with parsed command-line options.
258 static void ConfigureJdwp(const JDWP::JdwpOptions& jdwp_options);
259
Elliott Hughesc0f09332012-03-26 13:27:06 -0700260 // Returns true if we had -Xrunjdwp or -agentlib:jdwp= on the command line.
261 static bool IsJdwpConfigured();
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700262
Elliott Hughes86964332012-02-15 19:37:42 -0800263 static bool IsDisposed();
264
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700265 /*
266 * Time, in milliseconds, since the last debugger activity. Does not
267 * include DDMS activity. Returns -1 if there has been no activity.
268 * Returns 0 if we're in the middle of handling a debugger request.
269 */
270 static int64_t LastDebuggerActivity();
271
Sebastien Hertz253fa552014-10-14 17:27:15 +0200272 static void UndoDebuggerSuspensions()
273 LOCKS_EXCLUDED(Locks::thread_list_lock_,
274 Locks::thread_suspend_count_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700275
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700276 /*
277 * Class, Object, Array
278 */
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700279 static std::string GetClassName(JDWP::RefTypeId id)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700280 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertz6995c602014-09-09 12:10:13 +0200281 static std::string GetClassName(mirror::Class* klass)
282 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersc0542af2014-09-03 16:16:56 -0700283 static JDWP::JdwpError GetClassObject(JDWP::RefTypeId id, JDWP::ObjectId* class_object_id)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700284 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersc0542af2014-09-03 16:16:56 -0700285 static JDWP::JdwpError GetSuperclass(JDWP::RefTypeId id, JDWP::RefTypeId* superclass_id)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700286 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700287 static JDWP::JdwpError GetClassLoader(JDWP::RefTypeId id, JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700288 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700289 static JDWP::JdwpError GetModifiers(JDWP::RefTypeId id, JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700290 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800291 static JDWP::JdwpError GetReflectedType(JDWP::RefTypeId class_id, JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700292 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersc0542af2014-09-03 16:16:56 -0700293 static void GetClassList(std::vector<JDWP::RefTypeId>* classes)
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 GetClassInfo(JDWP::RefTypeId class_id, JDWP::JdwpTypeTag* pTypeTag,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700296 uint32_t* pStatus, std::string* pDescriptor)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700297 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersc0542af2014-09-03 16:16:56 -0700298 static void FindLoadedClassBySignature(const char* descriptor, std::vector<JDWP::RefTypeId>* ids)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700299 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes64f574f2013-02-20 14:57:12 -0800300 static JDWP::JdwpError GetReferenceType(JDWP::ObjectId object_id, JDWP::ExpandBuf* pReply)
301 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersfc0e94b2013-09-23 23:51:32 -0700302 static JDWP::JdwpError GetSignature(JDWP::RefTypeId ref_type_id, std::string* signature)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700303 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersc0542af2014-09-03 16:16:56 -0700304 static JDWP::JdwpError GetSourceFile(JDWP::RefTypeId ref_type_id, std::string* source_file)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700305 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersc0542af2014-09-03 16:16:56 -0700306 static JDWP::JdwpError GetObjectTag(JDWP::ObjectId object_id, uint8_t* tag)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700307 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughesaed4be92011-12-02 16:16:23 -0800308 static size_t GetTagWidth(JDWP::JdwpTag tag);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700309
Ian Rogersc0542af2014-09-03 16:16:56 -0700310 static JDWP::JdwpError GetArrayLength(JDWP::ObjectId array_id, int32_t* length)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700311 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800312 static JDWP::JdwpError OutputArray(JDWP::ObjectId array_id, int offset, int count,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700313 JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700314 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800315 static JDWP::JdwpError SetArrayElements(JDWP::ObjectId array_id, int offset, int count,
Ian Rogersc0542af2014-09-03 16:16:56 -0700316 JDWP::Request* request)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700317 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700318
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700319 static JDWP::ObjectId CreateString(const std::string& str)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700320 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersc0542af2014-09-03 16:16:56 -0700321 static JDWP::JdwpError CreateObject(JDWP::RefTypeId class_id, JDWP::ObjectId* new_object)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700322 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800323 static JDWP::JdwpError CreateArrayObject(JDWP::RefTypeId array_class_id, uint32_t length,
Ian Rogersc0542af2014-09-03 16:16:56 -0700324 JDWP::ObjectId* new_array)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700325 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700326
Sebastien Hertz6995c602014-09-09 12:10:13 +0200327 //
328 // Event filtering.
329 //
330 static bool MatchThread(JDWP::ObjectId expected_thread_id, Thread* event_thread)
331 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
332
333 static bool MatchLocation(const JDWP::JdwpLocation& expected_location,
334 const JDWP::EventLocation& event_location)
335 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
336
337 static bool MatchType(mirror::Class* event_class, JDWP::RefTypeId class_id)
338 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
339
340 static bool MatchField(JDWP::RefTypeId expected_type_id, JDWP::FieldId expected_field_id,
341 mirror::ArtField* event_field)
342 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
343
344 static bool MatchInstance(JDWP::ObjectId expected_instance_id, mirror::Object* event_instance)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700345 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700346
Elliott Hughesec0f83d2013-01-15 16:54:08 -0800347 //
348 // Monitors.
349 //
350 static JDWP::JdwpError GetMonitorInfo(JDWP::ObjectId object_id, JDWP::ExpandBuf* reply)
351 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
352 static JDWP::JdwpError GetOwnedMonitors(JDWP::ObjectId thread_id,
Ian Rogersc0542af2014-09-03 16:16:56 -0700353 std::vector<JDWP::ObjectId>* monitors,
354 std::vector<uint32_t>* stack_depths)
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100355 LOCKS_EXCLUDED(Locks::thread_list_lock_)
Elliott Hughesec0f83d2013-01-15 16:54:08 -0800356 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100357 static JDWP::JdwpError GetContendedMonitor(JDWP::ObjectId thread_id,
Ian Rogersc0542af2014-09-03 16:16:56 -0700358 JDWP::ObjectId* contended_monitor)
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100359 LOCKS_EXCLUDED(Locks::thread_list_lock_)
Elliott Hughesec0f83d2013-01-15 16:54:08 -0800360 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
361
362 //
363 // Heap.
364 //
365 static JDWP::JdwpError GetInstanceCounts(const std::vector<JDWP::RefTypeId>& class_ids,
Ian Rogersc0542af2014-09-03 16:16:56 -0700366 std::vector<uint64_t>* counts)
Elliott Hughesec0f83d2013-01-15 16:54:08 -0800367 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes3b78c942013-01-15 17:35:41 -0800368 static JDWP::JdwpError GetInstances(JDWP::RefTypeId class_id, int32_t max_count,
Ian Rogersc0542af2014-09-03 16:16:56 -0700369 std::vector<JDWP::ObjectId>* instances)
Elliott Hughes3b78c942013-01-15 17:35:41 -0800370 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes0cbaff52013-01-16 15:28:01 -0800371 static JDWP::JdwpError GetReferringObjects(JDWP::ObjectId object_id, int32_t max_count,
Ian Rogersc0542af2014-09-03 16:16:56 -0700372 std::vector<JDWP::ObjectId>* referring_objects)
Elliott Hughes0cbaff52013-01-16 15:28:01 -0800373 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes64f574f2013-02-20 14:57:12 -0800374 static JDWP::JdwpError DisableCollection(JDWP::ObjectId object_id)
375 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
376 static JDWP::JdwpError EnableCollection(JDWP::ObjectId object_id)
377 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersc0542af2014-09-03 16:16:56 -0700378 static JDWP::JdwpError IsCollected(JDWP::ObjectId object_id, bool* is_collected)
Elliott Hughes64f574f2013-02-20 14:57:12 -0800379 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
380 static void DisposeObject(JDWP::ObjectId object_id, uint32_t reference_count)
381 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughesec0f83d2013-01-15 16:54:08 -0800382
Elliott Hughes9777ba22013-01-17 09:04:19 -0800383 //
384 // Methods and fields.
385 //
Elliott Hughesa96836a2013-01-17 12:27:49 -0800386 static std::string GetMethodName(JDWP::MethodId method_id)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700387 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800388 static JDWP::JdwpError OutputDeclaredFields(JDWP::RefTypeId ref_type_id, bool with_generic,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700389 JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700390 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800391 static JDWP::JdwpError OutputDeclaredMethods(JDWP::RefTypeId ref_type_id, bool with_generic,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700392 JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700393 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800394 static JDWP::JdwpError OutputDeclaredInterfaces(JDWP::RefTypeId ref_type_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 void OutputLineTable(JDWP::RefTypeId ref_type_id, JDWP::MethodId method_id,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700398 JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700399 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800400 static void OutputVariableTable(JDWP::RefTypeId ref_type_id, JDWP::MethodId id, bool with_generic,
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_);
Jeff Hao579b0242013-11-18 13:16:49 -0800403 static void OutputMethodReturnValue(JDWP::MethodId method_id, const JValue* return_value,
404 JDWP::ExpandBuf* pReply)
405 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertz3f52eaf2014-04-04 17:50:18 +0200406 static void OutputFieldValue(JDWP::FieldId field_id, const JValue* field_value,
407 JDWP::ExpandBuf* pReply)
408 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes9777ba22013-01-17 09:04:19 -0800409 static JDWP::JdwpError GetBytecodes(JDWP::RefTypeId class_id, JDWP::MethodId method_id,
Ian Rogersc0542af2014-09-03 16:16:56 -0700410 std::vector<uint8_t>* bytecodes)
Elliott Hughes9777ba22013-01-17 09:04:19 -0800411 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700412
Elliott Hughesa96836a2013-01-17 12:27:49 -0800413 static std::string GetFieldName(JDWP::FieldId field_id)
414 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800415 static JDWP::JdwpTag GetFieldBasicTag(JDWP::FieldId field_id)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700416 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800417 static JDWP::JdwpTag GetStaticFieldBasicTag(JDWP::FieldId field_id)
Brian Carlstromf69863b2013-07-17 21:53:13 -0700418 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800419 static JDWP::JdwpError GetFieldValue(JDWP::ObjectId object_id, JDWP::FieldId field_id,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700420 JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700421 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800422 static JDWP::JdwpError SetFieldValue(JDWP::ObjectId object_id, JDWP::FieldId field_id,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700423 uint64_t value, int width)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700424 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800425 static JDWP::JdwpError GetStaticFieldValue(JDWP::RefTypeId ref_type_id, JDWP::FieldId field_id,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700426 JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700427 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800428 static JDWP::JdwpError SetStaticFieldValue(JDWP::FieldId field_id, uint64_t value, int width)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700429 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700430
Sebastien Hertzb0b0b492014-09-15 11:27:27 +0200431 static JDWP::JdwpError StringToUtf8(JDWP::ObjectId string_id, std::string* str)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700432 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Jeff Hao579b0242013-11-18 13:16:49 -0800433 static void OutputJValue(JDWP::JdwpTag tag, const JValue* return_value, JDWP::ExpandBuf* pReply)
434 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700435
436 /*
437 * Thread, ThreadGroup, Frame
438 */
Ian Rogersc0542af2014-09-03 16:16:56 -0700439 static JDWP::JdwpError GetThreadName(JDWP::ObjectId thread_id, std::string* name)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700440 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_)
441 LOCKS_EXCLUDED(Locks::thread_list_lock_);
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100442 static JDWP::JdwpError GetThreadGroup(JDWP::ObjectId thread_id, JDWP::ExpandBuf* pReply)
Sebastien Hertza06430c2014-09-15 19:21:30 +0200443 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_)
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100444 LOCKS_EXCLUDED(Locks::thread_list_lock_);
Sebastien Hertza06430c2014-09-15 19:21:30 +0200445 static JDWP::JdwpError GetThreadGroupName(JDWP::ObjectId thread_group_id,
446 JDWP::ExpandBuf* pReply)
447 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
448 static JDWP::JdwpError GetThreadGroupParent(JDWP::ObjectId thread_group_id,
449 JDWP::ExpandBuf* pReply)
450 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
451 static JDWP::JdwpError GetThreadGroupChildren(JDWP::ObjectId thread_group_id,
452 JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700453 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700454 static JDWP::ObjectId GetSystemThreadGroupId()
Ian Rogersb726dcb2012-09-05 08:57:23 -0700455 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700456
Jeff Hao920af3e2013-08-28 15:46:38 -0700457 static JDWP::JdwpThreadStatus ToJdwpThreadStatus(ThreadState state);
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100458 static JDWP::JdwpError GetThreadStatus(JDWP::ObjectId thread_id,
459 JDWP::JdwpThreadStatus* pThreadStatus,
460 JDWP::JdwpSuspendStatus* pSuspendStatus)
461 LOCKS_EXCLUDED(Locks::thread_list_lock_);
462 static JDWP::JdwpError GetThreadDebugSuspendCount(JDWP::ObjectId thread_id,
463 JDWP::ExpandBuf* pReply)
464 LOCKS_EXCLUDED(Locks::thread_list_lock_,
465 Locks::thread_suspend_count_lock_);
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700466 // static void WaitForSuspend(JDWP::ObjectId thread_id);
Elliott Hughescaf76542012-06-28 16:08:22 -0700467
Elliott Hughes026b1462012-06-28 20:43:49 -0700468 // Fills 'thread_ids' with the threads in the given thread group. If thread_group_id == 0,
Elliott Hughescaf76542012-06-28 16:08:22 -0700469 // returns all threads.
Sebastien Hertza06430c2014-09-15 19:21:30 +0200470 static void GetThreads(mirror::Object* thread_group, std::vector<JDWP::ObjectId>* thread_ids)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700471 LOCKS_EXCLUDED(Locks::thread_list_lock_)
472 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughescaf76542012-06-28 16:08:22 -0700473
Ian Rogersc0542af2014-09-03 16:16:56 -0700474 static JDWP::JdwpError GetThreadFrameCount(JDWP::ObjectId thread_id, size_t* result)
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100475 LOCKS_EXCLUDED(Locks::thread_list_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700476 static JDWP::JdwpError GetThreadFrames(JDWP::ObjectId thread_id, size_t start_frame,
477 size_t frame_count, JDWP::ExpandBuf* buf)
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100478 LOCKS_EXCLUDED(Locks::thread_list_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700479 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700480
Sebastien Hertz6995c602014-09-09 12:10:13 +0200481 static JDWP::ObjectId GetThreadSelfId() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
482 static JDWP::ObjectId GetThreadId(Thread* thread) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
483
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700484 static void SuspendVM()
Ian Rogersb726dcb2012-09-05 08:57:23 -0700485 LOCKS_EXCLUDED(Locks::thread_list_lock_,
486 Locks::thread_suspend_count_lock_);
Sebastien Hertz253fa552014-10-14 17:27:15 +0200487 static void ResumeVM()
488 LOCKS_EXCLUDED(Locks::thread_list_lock_,
489 Locks::thread_suspend_count_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800490 static JDWP::JdwpError SuspendThread(JDWP::ObjectId thread_id, bool request_suspension = true)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700491 LOCKS_EXCLUDED(Locks::mutator_lock_,
492 Locks::thread_list_lock_,
493 Locks::thread_suspend_count_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700494
Elliott Hughes88d63092013-01-09 09:55:54 -0800495 static void ResumeThread(JDWP::ObjectId thread_id)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700496 LOCKS_EXCLUDED(Locks::thread_list_lock_,
497 Locks::thread_suspend_count_lock_)
498 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700499 static void SuspendSelf();
500
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700501 static JDWP::JdwpError GetThisObject(JDWP::ObjectId thread_id, JDWP::FrameId frame_id,
502 JDWP::ObjectId* result)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700503 LOCKS_EXCLUDED(Locks::thread_list_lock_,
504 Locks::thread_suspend_count_lock_)
505 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertz8009f392014-09-01 17:07:11 +0200506 static JDWP::JdwpError GetLocalValues(JDWP::Request* request, JDWP::ExpandBuf* pReply)
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100507 LOCKS_EXCLUDED(Locks::thread_list_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700508 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertz8009f392014-09-01 17:07:11 +0200509 static JDWP::JdwpError SetLocalValues(JDWP::Request* request)
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100510 LOCKS_EXCLUDED(Locks::thread_list_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700511 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700512
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100513 static JDWP::JdwpError Interrupt(JDWP::ObjectId thread_id)
514 LOCKS_EXCLUDED(Locks::thread_list_lock_);
Elliott Hughesf9501702013-01-11 11:22:27 -0800515
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700516 /*
517 * Debugger notification
518 */
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700519 enum EventFlag {
Elliott Hughes86964332012-02-15 19:37:42 -0800520 kBreakpoint = 0x01,
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700521 kSingleStep = 0x02,
522 kMethodEntry = 0x04,
523 kMethodExit = 0x08,
524 };
Sebastien Hertz3f52eaf2014-04-04 17:50:18 +0200525 static void PostFieldAccessEvent(mirror::ArtMethod* m, int dex_pc, mirror::Object* this_object,
526 mirror::ArtField* f)
527 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
528 static void PostFieldModificationEvent(mirror::ArtMethod* m, int dex_pc,
529 mirror::Object* this_object, mirror::ArtField* f,
530 const JValue* field_value)
531 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
532 static void PostException(const ThrowLocation& throw_location, mirror::ArtMethod* catch_method,
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800533 uint32_t catch_dex_pc, mirror::Throwable* exception)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700534 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700535 static void PostThreadStart(Thread* t)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700536 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700537 static void PostThreadDeath(Thread* t)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700538 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800539 static void PostClassPrepare(mirror::Class* c)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700540 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700541
Ian Rogers62d6c772013-02-27 08:32:07 -0800542 static void UpdateDebugger(Thread* thread, mirror::Object* this_object,
Sebastien Hertz8379b222014-02-24 17:38:15 +0100543 mirror::ArtMethod* method, uint32_t new_dex_pc,
544 int event_flags, const JValue* return_value)
jeffhao09bfc6a2012-12-11 18:11:43 -0800545 LOCKS_EXCLUDED(Locks::breakpoint_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700546 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes91bf6cd2012-02-14 17:27:48 -0800547
Sebastien Hertzf3928792014-11-17 19:00:37 +0100548 // Indicates whether we need deoptimization for debugging.
549 static bool RequiresDeoptimization();
550
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100551 // Records deoptimization request in the queue.
552 static void RequestDeoptimization(const DeoptimizationRequest& req)
Brian Carlstrom306db812014-09-05 13:01:41 -0700553 LOCKS_EXCLUDED(Locks::deoptimization_lock_)
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100554 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
555
Sebastien Hertz7ec2f1c2014-03-27 20:06:47 +0100556 // Support delayed full undeoptimization requests. This is currently only used for single-step
557 // events.
Brian Carlstrom306db812014-09-05 13:01:41 -0700558 static void DelayFullUndeoptimization() LOCKS_EXCLUDED(Locks::deoptimization_lock_);
Sebastien Hertz7ec2f1c2014-03-27 20:06:47 +0100559 static void ProcessDelayedFullUndeoptimizations()
Brian Carlstrom306db812014-09-05 13:01:41 -0700560 LOCKS_EXCLUDED(Locks::deoptimization_lock_)
Sebastien Hertz7ec2f1c2014-03-27 20:06:47 +0100561 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
562
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100563 // Manage deoptimization after updating JDWP events list. Suspends all threads, processes each
564 // request and finally resumes all threads.
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100565 static void ManageDeoptimization()
Brian Carlstrom306db812014-09-05 13:01:41 -0700566 LOCKS_EXCLUDED(Locks::deoptimization_lock_)
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100567 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
568
569 // Breakpoints.
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100570 static void WatchLocation(const JDWP::JdwpLocation* pLoc, DeoptimizationRequest* req)
571 LOCKS_EXCLUDED(Locks::breakpoint_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700572 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100573 static void UnwatchLocation(const JDWP::JdwpLocation* pLoc, DeoptimizationRequest* req)
574 LOCKS_EXCLUDED(Locks::breakpoint_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700575 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100576
577 // Single-stepping.
Elliott Hughes88d63092013-01-09 09:55:54 -0800578 static JDWP::JdwpError ConfigureStep(JDWP::ObjectId thread_id, JDWP::JdwpStepSize size,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700579 JDWP::JdwpStepDepth depth)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700580 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +0100581 static void UnconfigureStep(JDWP::ObjectId thread_id)
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100582 LOCKS_EXCLUDED(Locks::thread_list_lock_)
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +0100583 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700584
Elliott Hughes88d63092013-01-09 09:55:54 -0800585 static JDWP::JdwpError InvokeMethod(JDWP::ObjectId thread_id, JDWP::ObjectId object_id,
586 JDWP::RefTypeId class_id, JDWP::MethodId method_id,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700587 uint32_t arg_count, uint64_t* arg_values,
588 JDWP::JdwpTag* arg_types, uint32_t options,
589 JDWP::JdwpTag* pResultTag, uint64_t* pResultValue,
590 JDWP::ObjectId* pExceptObj)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700591 LOCKS_EXCLUDED(Locks::thread_list_lock_,
592 Locks::thread_suspend_count_lock_)
593 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700594 static void ExecuteMethod(DebugInvokeReq* pReq);
595
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700596 /*
597 * DDM support.
598 */
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700599 static void DdmSendThreadNotification(Thread* t, uint32_t type)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700600 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100601 static void DdmSetThreadNotification(bool enable)
602 LOCKS_EXCLUDED(Locks::thread_list_lock_);
Ian Rogersc0542af2014-09-03 16:16:56 -0700603 static bool DdmHandlePacket(JDWP::Request* request, uint8_t** pReplyBuf, int* pReplyLen);
Ian Rogersb726dcb2012-09-05 08:57:23 -0700604 static void DdmConnected() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
605 static void DdmDisconnected() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700606 static void DdmSendChunk(uint32_t type, const std::vector<uint8_t>& bytes)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700607 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700608 static void DdmSendChunk(uint32_t type, size_t len, const uint8_t* buf)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700609 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700610 static void DdmSendChunkV(uint32_t type, const iovec* iov, int iov_count)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700611 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes767a1472011-10-26 18:49:02 -0700612
Mathieu Chartier3b05e9b2014-03-25 09:29:43 -0700613 static void VisitRoots(RootCallback* callback, void* arg)
614 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
615
Elliott Hughes545a0642011-11-08 19:10:03 -0800616 /*
617 * Recent allocation tracking support.
618 */
Ian Rogers844506b2014-09-12 19:59:33 -0700619 static void RecordAllocation(Thread* self, mirror::Class* type, size_t byte_count)
Brian Carlstrom306db812014-09-05 13:01:41 -0700620 LOCKS_EXCLUDED(Locks::alloc_tracker_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700621 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom306db812014-09-05 13:01:41 -0700622 static void SetAllocTrackingEnabled(bool enabled) LOCKS_EXCLUDED(Locks::alloc_tracker_lock_);
Ian Rogers719d1a32014-03-06 12:13:39 -0800623 static bool IsAllocTrackingEnabled() {
624 return recent_allocation_records_ != nullptr;
625 }
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100626 static jbyteArray GetRecentAllocations()
Brian Carlstrom306db812014-09-05 13:01:41 -0700627 LOCKS_EXCLUDED(Locks::alloc_tracker_lock_)
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100628 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom306db812014-09-05 13:01:41 -0700629 static size_t HeadIndex() EXCLUSIVE_LOCKS_REQUIRED(Locks::alloc_tracker_lock_);
630 static void DumpRecentAllocations() LOCKS_EXCLUDED(Locks::alloc_tracker_lock_);
Elliott Hughes545a0642011-11-08 19:10:03 -0800631
Elliott Hughes767a1472011-10-26 18:49:02 -0700632 enum HpifWhen {
633 HPIF_WHEN_NEVER = 0,
634 HPIF_WHEN_NOW = 1,
635 HPIF_WHEN_NEXT_GC = 2,
636 HPIF_WHEN_EVERY_GC = 3
637 };
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700638 static int DdmHandleHpifChunk(HpifWhen when)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700639 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes767a1472011-10-26 18:49:02 -0700640
641 enum HpsgWhen {
642 HPSG_WHEN_NEVER = 0,
643 HPSG_WHEN_EVERY_GC = 1,
644 };
645 enum HpsgWhat {
646 HPSG_WHAT_MERGED_OBJECTS = 0,
647 HPSG_WHAT_DISTINCT_OBJECTS = 1,
648 };
649 static bool DdmHandleHpsgNhsgChunk(HpsgWhen when, HpsgWhat what, bool native);
650
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700651 static void DdmSendHeapInfo(HpifWhen reason)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700652 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700653 static void DdmSendHeapSegments(bool native)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700654 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes545a0642011-11-08 19:10:03 -0800655
Sebastien Hertz6995c602014-09-09 12:10:13 +0200656 static ObjectRegistry* GetObjectRegistry() {
657 return gRegistry;
658 }
659
660 static JDWP::JdwpTag TagFromObject(const ScopedObjectAccessUnchecked& soa, mirror::Object* o)
661 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
662
663 static JDWP::JdwpTypeTag GetTypeTag(mirror::Class* klass)
664 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
665
666 static JDWP::FieldId ToFieldId(const mirror::ArtField* f)
667 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
668
669 static void SetJdwpLocation(JDWP::JdwpLocation* location, mirror::ArtMethod* m, uint32_t dex_pc)
670 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
671
Mathieu Chartierad466ad2015-01-08 16:28:08 -0800672 static JDWP::JdwpState* GetJdwpState();
673
Elliott Hughes545a0642011-11-08 19:10:03 -0800674 private:
Sebastien Hertz8009f392014-09-01 17:07:11 +0200675 static JDWP::JdwpError GetLocalValue(const StackVisitor& visitor,
676 ScopedObjectAccessUnchecked& soa, int slot,
677 JDWP::JdwpTag tag, uint8_t* buf, size_t width)
678 LOCKS_EXCLUDED(Locks::thread_list_lock_)
679 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
680 static JDWP::JdwpError SetLocalValue(StackVisitor& visitor, int slot, JDWP::JdwpTag tag,
681 uint64_t value, size_t width)
682 LOCKS_EXCLUDED(Locks::thread_list_lock_)
683 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
684
Brian Carlstrom2d888622013-07-18 17:02:00 -0700685 static void DdmBroadcast(bool connect) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700686 static void PostThreadStartOrStop(Thread*, uint32_t)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700687 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughesa2155262011-11-16 16:26:58 -0800688
Sebastien Hertz8379b222014-02-24 17:38:15 +0100689 static void PostLocationEvent(mirror::ArtMethod* method, int pcOffset,
690 mirror::Object* thisPtr, int eventFlags,
691 const JValue* return_value)
692 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
693
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100694 static void ProcessDeoptimizationRequest(const DeoptimizationRequest& request)
695 EXCLUSIVE_LOCKS_REQUIRED(Locks::mutator_lock_);
696
Sebastien Hertz7ec2f1c2014-03-27 20:06:47 +0100697 static void RequestDeoptimizationLocked(const DeoptimizationRequest& req)
Brian Carlstrom306db812014-09-05 13:01:41 -0700698 EXCLUSIVE_LOCKS_REQUIRED(Locks::deoptimization_lock_)
Sebastien Hertz7ec2f1c2014-03-27 20:06:47 +0100699 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
700
Brian Carlstrom306db812014-09-05 13:01:41 -0700701 static AllocRecord* recent_allocation_records_ PT_GUARDED_BY(Locks::alloc_tracker_lock_);
702 static size_t alloc_record_max_ GUARDED_BY(Locks::alloc_tracker_lock_);
703 static size_t alloc_record_head_ GUARDED_BY(Locks::alloc_tracker_lock_);
704 static size_t alloc_record_count_ GUARDED_BY(Locks::alloc_tracker_lock_);
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100705
Sebastien Hertz6995c602014-09-09 12:10:13 +0200706 static ObjectRegistry* gRegistry;
707
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100708 // Deoptimization requests to be processed each time the event list is updated. This is used when
709 // registering and unregistering events so we do not deoptimize while holding the event list
710 // lock.
Sebastien Hertz42cd43f2014-05-13 14:15:41 +0200711 // TODO rename to instrumentation_requests.
Brian Carlstrom306db812014-09-05 13:01:41 -0700712 static std::vector<DeoptimizationRequest> deoptimization_requests_ GUARDED_BY(Locks::deoptimization_lock_);
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100713
714 // Count the number of events requiring full deoptimization. When the counter is > 0, everything
715 // is deoptimized, otherwise everything is undeoptimized.
716 // Note: we fully deoptimize on the first event only (when the counter is set to 1). We fully
717 // undeoptimize when the last event is unregistered (when the counter is set to 0).
Brian Carlstrom306db812014-09-05 13:01:41 -0700718 static size_t full_deoptimization_event_count_ GUARDED_BY(Locks::deoptimization_lock_);
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100719
Sebastien Hertz7ec2f1c2014-03-27 20:06:47 +0100720 // Count the number of full undeoptimization requests delayed to next resume or end of debug
721 // session.
Brian Carlstrom306db812014-09-05 13:01:41 -0700722 static size_t delayed_full_undeoptimization_count_ GUARDED_BY(Locks::deoptimization_lock_);
Sebastien Hertz7ec2f1c2014-03-27 20:06:47 +0100723
Sebastien Hertz42cd43f2014-05-13 14:15:41 +0200724 static size_t* GetReferenceCounterForEvent(uint32_t instrumentation_event);
725
Mathieu Chartier4345c462014-06-27 10:20:14 -0700726 // Weak global type cache, TODO improve this.
Brian Carlstrom306db812014-09-05 13:01:41 -0700727 static TypeCache type_cache_ GUARDED_BY(Locks::alloc_tracker_lock_);
Mathieu Chartier4345c462014-06-27 10:20:14 -0700728
Sebastien Hertz42cd43f2014-05-13 14:15:41 +0200729 // Instrumentation event reference counters.
730 // TODO we could use an array instead of having all these dedicated counters. Instrumentation
731 // events are bits of a mask so we could convert them to array index.
Brian Carlstrom306db812014-09-05 13:01:41 -0700732 static size_t dex_pc_change_event_ref_count_ GUARDED_BY(Locks::deoptimization_lock_);
733 static size_t method_enter_event_ref_count_ GUARDED_BY(Locks::deoptimization_lock_);
734 static size_t method_exit_event_ref_count_ GUARDED_BY(Locks::deoptimization_lock_);
735 static size_t field_read_event_ref_count_ GUARDED_BY(Locks::deoptimization_lock_);
736 static size_t field_write_event_ref_count_ GUARDED_BY(Locks::deoptimization_lock_);
737 static size_t exception_catch_event_ref_count_ GUARDED_BY(Locks::deoptimization_lock_);
Sebastien Hertz42cd43f2014-05-13 14:15:41 +0200738 static uint32_t instrumentation_events_ GUARDED_BY(Locks::mutator_lock_);
739
Brian Carlstrom306db812014-09-05 13:01:41 -0700740 friend class AllocRecord; // For type_cache_ with proper annotalysis.
Ian Rogers719d1a32014-03-06 12:13:39 -0800741 DISALLOW_COPY_AND_ASSIGN(Dbg);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700742};
743
744#define CHUNK_TYPE(_name) \
Elliott Hughes82188472011-11-07 18:11:48 -0800745 static_cast<uint32_t>((_name)[0] << 24 | (_name)[1] << 16 | (_name)[2] << 8 | (_name)[3])
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700746
747} // namespace art
748
Brian Carlstromfc0e3212013-07-17 14:40:12 -0700749#endif // ART_RUNTIME_DEBUGGER_H_