blob: 1ad1a00736a7061d67fa45572ba606157379cae4 [file] [log] [blame]
Elliott Hughes872d4ec2011-10-21 17:07:15 -07001/*
2 * Copyright (C) 2008 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17/*
18 * Dalvik-specific side of debugger support. (The JDWP code is intended to
19 * be relatively generic.)
20 */
Brian Carlstromfc0e3212013-07-17 14:40:12 -070021#ifndef ART_RUNTIME_DEBUGGER_H_
22#define ART_RUNTIME_DEBUGGER_H_
Elliott Hughes872d4ec2011-10-21 17:07:15 -070023
24#include <pthread.h>
25
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +010026#include <set>
Elliott Hughes3bb81562011-10-21 18:52:59 -070027#include <string>
Sebastien Hertz4d25df32014-03-21 17:44:46 +010028#include <vector>
Elliott Hughes3bb81562011-10-21 18:52:59 -070029
Elliott Hughes872d4ec2011-10-21 17:07:15 -070030#include "jdwp/jdwp.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080031#include "jni.h"
32#include "jvalue.h"
Mathieu Chartier83c8ee02014-01-28 14:50:23 -080033#include "object_callbacks.h"
Jeff Hao920af3e2013-08-28 15:46:38 -070034#include "thread_state.h"
Elliott Hughes872d4ec2011-10-21 17:07:15 -070035
36namespace art {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080037namespace mirror {
Sebastien Hertz3f52eaf2014-04-04 17:50:18 +020038class ArtField;
Brian Carlstromea46f952013-07-30 01:26:50 -070039class ArtMethod;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080040class Class;
41class Object;
42class Throwable;
43} // namespace mirror
Elliott Hughes545a0642011-11-08 19:10:03 -080044struct AllocRecord;
Ian Rogers1b09b092012-08-20 15:35:52 -070045class Thread;
Ian Rogers62d6c772013-02-27 08:32:07 -080046class ThrowLocation;
Elliott Hughes872d4ec2011-10-21 17:07:15 -070047
48/*
49 * Invoke-during-breakpoint support.
50 */
51struct DebugInvokeReq {
Elliott Hughes7b3cdfc2011-12-08 21:28:17 -080052 DebugInvokeReq()
Sebastien Hertzd38667a2013-11-25 15:43:54 +010053 : ready(false), invoke_needed(false),
54 receiver(NULL), thread(NULL), klass(NULL), method(NULL),
55 arg_count(0), arg_values(NULL), options(0), error(JDWP::ERR_NONE),
Ian Rogers00f7d0e2012-07-19 15:28:27 -070056 result_tag(JDWP::JT_VOID), exception(0),
Sebastien Hertzd38667a2013-11-25 15:43:54 +010057 lock("a DebugInvokeReq lock", kBreakpointInvokeLock),
58 cond("a DebugInvokeReq condition variable", lock) {
Elliott Hughes475fc232011-10-25 15:00:35 -070059 }
60
Elliott Hughes872d4ec2011-10-21 17:07:15 -070061 /* boolean; only set when we're in the tail end of an event handler */
62 bool ready;
63
64 /* boolean; set if the JDWP thread wants this thread to do work */
Sebastien Hertzd38667a2013-11-25 15:43:54 +010065 bool invoke_needed;
Elliott Hughes872d4ec2011-10-21 17:07:15 -070066
67 /* request */
Sebastien Hertzd38667a2013-11-25 15:43:54 +010068 mirror::Object* receiver; /* not used for ClassType.InvokeMethod */
69 mirror::Object* thread;
70 mirror::Class* klass;
71 mirror::ArtMethod* method;
72 uint32_t arg_count;
73 uint64_t* arg_values; /* will be NULL if arg_count_ == 0 */
74 uint32_t options;
Elliott Hughes872d4ec2011-10-21 17:07:15 -070075
76 /* result */
Elliott Hughes475fc232011-10-25 15:00:35 -070077 JDWP::JdwpError error;
Elliott Hughesd07986f2011-12-06 18:27:45 -080078 JDWP::JdwpTag result_tag;
Elliott Hughes475fc232011-10-25 15:00:35 -070079 JValue result_value;
80 JDWP::ObjectId exception;
Elliott Hughes872d4ec2011-10-21 17:07:15 -070081
82 /* condition variable to wait on while the method executes */
Sebastien Hertzd38667a2013-11-25 15:43:54 +010083 Mutex lock DEFAULT_MUTEX_ACQUIRED_AFTER;
84 ConditionVariable cond GUARDED_BY(lock);
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +010085
Mathieu Chartier3b05e9b2014-03-25 09:29:43 -070086 void VisitRoots(RootCallback* callback, void* arg, uint32_t tid, RootType root_type)
87 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
88
Sebastien Hertzbb43b432014-04-14 11:59:08 +020089 void Clear();
90
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +010091 private:
92 DISALLOW_COPY_AND_ASSIGN(DebugInvokeReq);
93};
94
95// Thread local data-structure that holds fields for controlling single-stepping.
96struct SingleStepControl {
97 SingleStepControl()
98 : is_active(false), step_size(JDWP::SS_MIN), step_depth(JDWP::SD_INTO),
99 method(nullptr), stack_depth(0) {
100 }
101
102 // Are we single-stepping right now?
103 bool is_active;
104
105 // See JdwpStepSize and JdwpStepDepth for details.
106 JDWP::JdwpStepSize step_size;
107 JDWP::JdwpStepDepth step_depth;
108
109 // The location this single-step was initiated from.
110 // A single-step is initiated in a suspended thread. We save here the current method and the
111 // set of DEX pcs associated to the source line number where the suspension occurred.
112 // This is used to support SD_INTO and SD_OVER single-step depths so we detect when a single-step
113 // causes the execution of an instruction in a different method or at a different line number.
114 mirror::ArtMethod* method;
115 std::set<uint32_t> dex_pcs;
116
117 // The stack depth when this single-step was initiated. This is used to support SD_OVER and SD_OUT
118 // single-step depth.
119 int stack_depth;
120
Mathieu Chartier3b05e9b2014-03-25 09:29:43 -0700121 void VisitRoots(RootCallback* callback, void* arg, uint32_t tid, RootType root_type)
122 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
123
Sebastien Hertzbb43b432014-04-14 11:59:08 +0200124 bool ContainsDexPc(uint32_t dex_pc) const;
125
126 void Clear();
127
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +0100128 private:
129 DISALLOW_COPY_AND_ASSIGN(SingleStepControl);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700130};
131
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100132struct DeoptimizationRequest {
133 enum Kind {
134 kNothing, // no action.
135 kFullDeoptimization, // deoptimize everything.
136 kFullUndeoptimization, // undeoptimize everything.
137 kSelectiveDeoptimization, // deoptimize one method.
138 kSelectiveUndeoptimization // undeoptimize one method.
139 };
140
141 DeoptimizationRequest() : kind(kNothing), method(nullptr) {}
142
143 void VisitRoots(RootCallback* callback, void* arg);
144
145 Kind kind;
146
147 // Method for selective deoptimization.
148 mirror::ArtMethod* method;
149};
150
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700151class Dbg {
Elliott Hughesff17f1f2012-01-24 18:12:29 -0800152 public:
Elliott Hughes3bb81562011-10-21 18:52:59 -0700153 static bool ParseJdwpOptions(const std::string& options);
Elliott Hughes4ffd3132011-10-24 12:06:42 -0700154 static void SetJdwpAllowed(bool allowed);
155
Elliott Hughesd1cc8362011-10-24 16:58:50 -0700156 static void StartJdwp();
157 static void StopJdwp();
158
Elliott Hughes767a1472011-10-26 18:49:02 -0700159 // Invoked by the GC in case we need to keep DDMS informed.
Ian Rogersb726dcb2012-09-05 08:57:23 -0700160 static void GcDidFinish() LOCKS_EXCLUDED(Locks::mutator_lock_);
Elliott Hughes767a1472011-10-26 18:49:02 -0700161
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700162 // Return the DebugInvokeReq for the current thread.
163 static DebugInvokeReq* GetInvokeReq();
164
Elliott Hughes475fc232011-10-25 15:00:35 -0700165 static Thread* GetDebugThread();
166 static void ClearWaitForEventThread();
167
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700168 /*
169 * Enable/disable breakpoints and step modes. Used to provide a heads-up
170 * when the debugger attaches.
171 */
172 static void Connected();
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100173 static void GoActive()
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100174 LOCKS_EXCLUDED(Locks::breakpoint_lock_, deoptimization_lock_, Locks::mutator_lock_);
175 static void Disconnected() LOCKS_EXCLUDED(deoptimization_lock_, Locks::mutator_lock_);
Elliott Hughes86964332012-02-15 19:37:42 -0800176 static void Disposed();
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700177
Elliott Hughesc0f09332012-03-26 13:27:06 -0700178 // Returns true if we're actually debugging with a real debugger, false if it's
179 // just DDMS (or nothing at all).
180 static bool IsDebuggerActive();
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700181
Elliott Hughesc0f09332012-03-26 13:27:06 -0700182 // Returns true if we had -Xrunjdwp or -agentlib:jdwp= on the command line.
183 static bool IsJdwpConfigured();
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700184
Elliott Hughes86964332012-02-15 19:37:42 -0800185 static bool IsDisposed();
186
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700187 /*
188 * Time, in milliseconds, since the last debugger activity. Does not
189 * include DDMS activity. Returns -1 if there has been no activity.
190 * Returns 0 if we're in the middle of handling a debugger request.
191 */
192 static int64_t LastDebuggerActivity();
193
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700194 static void UndoDebuggerSuspensions();
195
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700196 /*
197 * Class, Object, Array
198 */
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700199 static std::string GetClassName(JDWP::RefTypeId id)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700200 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800201 static JDWP::JdwpError GetClassObject(JDWP::RefTypeId id, JDWP::ObjectId& class_object_id)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700202 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800203 static JDWP::JdwpError GetSuperclass(JDWP::RefTypeId id, JDWP::RefTypeId& superclass_id)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700204 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700205 static JDWP::JdwpError GetClassLoader(JDWP::RefTypeId id, JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700206 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700207 static JDWP::JdwpError GetModifiers(JDWP::RefTypeId id, JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700208 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800209 static JDWP::JdwpError GetReflectedType(JDWP::RefTypeId class_id, JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700210 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700211 static void GetClassList(std::vector<JDWP::RefTypeId>& classes)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700212 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800213 static JDWP::JdwpError GetClassInfo(JDWP::RefTypeId class_id, JDWP::JdwpTypeTag* pTypeTag,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700214 uint32_t* pStatus, std::string* pDescriptor)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700215 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700216 static void FindLoadedClassBySignature(const char* descriptor, std::vector<JDWP::RefTypeId>& ids)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700217 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes64f574f2013-02-20 14:57:12 -0800218 static JDWP::JdwpError GetReferenceType(JDWP::ObjectId object_id, JDWP::ExpandBuf* pReply)
219 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersfc0e94b2013-09-23 23:51:32 -0700220 static JDWP::JdwpError GetSignature(JDWP::RefTypeId ref_type_id, std::string* signature)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700221 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800222 static JDWP::JdwpError GetSourceFile(JDWP::RefTypeId ref_type_id, std::string& source_file)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700223 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800224 static JDWP::JdwpError GetObjectTag(JDWP::ObjectId object_id, uint8_t& tag)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700225 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughesaed4be92011-12-02 16:16:23 -0800226 static size_t GetTagWidth(JDWP::JdwpTag tag);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700227
Elliott Hughes88d63092013-01-09 09:55:54 -0800228 static JDWP::JdwpError GetArrayLength(JDWP::ObjectId array_id, int& length)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700229 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800230 static JDWP::JdwpError OutputArray(JDWP::ObjectId array_id, int offset, int count,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700231 JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700232 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800233 static JDWP::JdwpError SetArrayElements(JDWP::ObjectId array_id, int offset, int count,
Elliott Hughes4b9702c2013-02-20 18:13:24 -0800234 JDWP::Request& request)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700235 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700236
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700237 static JDWP::ObjectId CreateString(const std::string& str)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700238 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800239 static JDWP::JdwpError CreateObject(JDWP::RefTypeId class_id, JDWP::ObjectId& new_object)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700240 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800241 static JDWP::JdwpError CreateArrayObject(JDWP::RefTypeId array_class_id, uint32_t length,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700242 JDWP::ObjectId& new_array)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700243 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700244
Elliott Hughes88d63092013-01-09 09:55:54 -0800245 static bool MatchType(JDWP::RefTypeId instance_class_id, JDWP::RefTypeId class_id)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700246 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700247
Elliott Hughesec0f83d2013-01-15 16:54:08 -0800248 //
249 // Monitors.
250 //
251 static JDWP::JdwpError GetMonitorInfo(JDWP::ObjectId object_id, JDWP::ExpandBuf* reply)
252 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
253 static JDWP::JdwpError GetOwnedMonitors(JDWP::ObjectId thread_id,
254 std::vector<JDWP::ObjectId>& monitors,
255 std::vector<uint32_t>& stack_depths)
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100256 LOCKS_EXCLUDED(Locks::thread_list_lock_)
Elliott Hughesec0f83d2013-01-15 16:54:08 -0800257 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100258 static JDWP::JdwpError GetContendedMonitor(JDWP::ObjectId thread_id,
259 JDWP::ObjectId& contended_monitor)
260 LOCKS_EXCLUDED(Locks::thread_list_lock_)
Elliott Hughesec0f83d2013-01-15 16:54:08 -0800261 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
262
263 //
264 // Heap.
265 //
266 static JDWP::JdwpError GetInstanceCounts(const std::vector<JDWP::RefTypeId>& class_ids,
267 std::vector<uint64_t>& counts)
268 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes3b78c942013-01-15 17:35:41 -0800269 static JDWP::JdwpError GetInstances(JDWP::RefTypeId class_id, int32_t max_count,
270 std::vector<JDWP::ObjectId>& instances)
271 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes0cbaff52013-01-16 15:28:01 -0800272 static JDWP::JdwpError GetReferringObjects(JDWP::ObjectId object_id, int32_t max_count,
273 std::vector<JDWP::ObjectId>& referring_objects)
274 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes64f574f2013-02-20 14:57:12 -0800275 static JDWP::JdwpError DisableCollection(JDWP::ObjectId object_id)
276 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
277 static JDWP::JdwpError EnableCollection(JDWP::ObjectId object_id)
278 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
279 static JDWP::JdwpError IsCollected(JDWP::ObjectId object_id, bool& is_collected)
280 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
281 static void DisposeObject(JDWP::ObjectId object_id, uint32_t reference_count)
282 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughesec0f83d2013-01-15 16:54:08 -0800283
Elliott Hughes9777ba22013-01-17 09:04:19 -0800284 //
285 // Methods and fields.
286 //
Elliott Hughesa96836a2013-01-17 12:27:49 -0800287 static std::string GetMethodName(JDWP::MethodId method_id)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700288 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800289 static JDWP::JdwpError OutputDeclaredFields(JDWP::RefTypeId ref_type_id, bool with_generic,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700290 JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700291 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800292 static JDWP::JdwpError OutputDeclaredMethods(JDWP::RefTypeId ref_type_id, bool with_generic,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700293 JDWP::ExpandBuf* pReply)
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 OutputDeclaredInterfaces(JDWP::RefTypeId ref_type_id,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700296 JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700297 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800298 static void OutputLineTable(JDWP::RefTypeId ref_type_id, JDWP::MethodId method_id,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700299 JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700300 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800301 static void OutputVariableTable(JDWP::RefTypeId ref_type_id, JDWP::MethodId id, bool with_generic,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700302 JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700303 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Jeff Hao579b0242013-11-18 13:16:49 -0800304 static void OutputMethodReturnValue(JDWP::MethodId method_id, const JValue* return_value,
305 JDWP::ExpandBuf* pReply)
306 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertz3f52eaf2014-04-04 17:50:18 +0200307 static void OutputFieldValue(JDWP::FieldId field_id, const JValue* field_value,
308 JDWP::ExpandBuf* pReply)
309 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes9777ba22013-01-17 09:04:19 -0800310 static JDWP::JdwpError GetBytecodes(JDWP::RefTypeId class_id, JDWP::MethodId method_id,
311 std::vector<uint8_t>& bytecodes)
312 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700313
Elliott Hughesa96836a2013-01-17 12:27:49 -0800314 static std::string GetFieldName(JDWP::FieldId field_id)
315 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800316 static JDWP::JdwpTag GetFieldBasicTag(JDWP::FieldId field_id)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700317 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800318 static JDWP::JdwpTag GetStaticFieldBasicTag(JDWP::FieldId field_id)
Brian Carlstromf69863b2013-07-17 21:53:13 -0700319 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800320 static JDWP::JdwpError GetFieldValue(JDWP::ObjectId object_id, JDWP::FieldId field_id,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700321 JDWP::ExpandBuf* pReply)
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 SetFieldValue(JDWP::ObjectId object_id, JDWP::FieldId field_id,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700324 uint64_t value, int width)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700325 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800326 static JDWP::JdwpError GetStaticFieldValue(JDWP::RefTypeId ref_type_id, JDWP::FieldId field_id,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700327 JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700328 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800329 static JDWP::JdwpError SetStaticFieldValue(JDWP::FieldId field_id, uint64_t value, int width)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700330 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700331
Elliott Hughes88d63092013-01-09 09:55:54 -0800332 static std::string StringToUtf8(JDWP::ObjectId string_id)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700333 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Jeff Hao579b0242013-11-18 13:16:49 -0800334 static void OutputJValue(JDWP::JdwpTag tag, const JValue* return_value, JDWP::ExpandBuf* pReply)
335 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700336
337 /*
338 * Thread, ThreadGroup, Frame
339 */
Elliott Hughes88d63092013-01-09 09:55:54 -0800340 static JDWP::JdwpError GetThreadName(JDWP::ObjectId thread_id, std::string& name)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700341 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_)
342 LOCKS_EXCLUDED(Locks::thread_list_lock_);
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100343 static JDWP::JdwpError GetThreadGroup(JDWP::ObjectId thread_id, JDWP::ExpandBuf* pReply)
344 LOCKS_EXCLUDED(Locks::thread_list_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800345 static std::string GetThreadGroupName(JDWP::ObjectId thread_group_id);
346 static JDWP::ObjectId GetThreadGroupParent(JDWP::ObjectId thread_group_id)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700347 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700348 static JDWP::ObjectId GetSystemThreadGroupId()
Ian Rogersb726dcb2012-09-05 08:57:23 -0700349 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700350 static JDWP::ObjectId GetMainThreadGroupId();
351
Jeff Hao920af3e2013-08-28 15:46:38 -0700352 static JDWP::JdwpThreadStatus ToJdwpThreadStatus(ThreadState state);
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100353 static JDWP::JdwpError GetThreadStatus(JDWP::ObjectId thread_id,
354 JDWP::JdwpThreadStatus* pThreadStatus,
355 JDWP::JdwpSuspendStatus* pSuspendStatus)
356 LOCKS_EXCLUDED(Locks::thread_list_lock_);
357 static JDWP::JdwpError GetThreadDebugSuspendCount(JDWP::ObjectId thread_id,
358 JDWP::ExpandBuf* pReply)
359 LOCKS_EXCLUDED(Locks::thread_list_lock_,
360 Locks::thread_suspend_count_lock_);
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700361 // static void WaitForSuspend(JDWP::ObjectId thread_id);
Elliott Hughescaf76542012-06-28 16:08:22 -0700362
Elliott Hughes026b1462012-06-28 20:43:49 -0700363 // Fills 'thread_ids' with the threads in the given thread group. If thread_group_id == 0,
Elliott Hughescaf76542012-06-28 16:08:22 -0700364 // returns all threads.
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700365 static void GetThreads(JDWP::ObjectId thread_group_id, std::vector<JDWP::ObjectId>& thread_ids)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700366 LOCKS_EXCLUDED(Locks::thread_list_lock_)
367 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughescaf76542012-06-28 16:08:22 -0700368 static void GetChildThreadGroups(JDWP::ObjectId thread_group_id, std::vector<JDWP::ObjectId>& child_thread_group_ids);
369
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100370 static JDWP::JdwpError GetThreadFrameCount(JDWP::ObjectId thread_id, size_t& result)
371 LOCKS_EXCLUDED(Locks::thread_list_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700372 static JDWP::JdwpError GetThreadFrames(JDWP::ObjectId thread_id, size_t start_frame,
373 size_t frame_count, JDWP::ExpandBuf* buf)
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100374 LOCKS_EXCLUDED(Locks::thread_list_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700375 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700376
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700377 static JDWP::ObjectId GetThreadSelfId()
Ian Rogersb726dcb2012-09-05 08:57:23 -0700378 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700379 static void SuspendVM()
Ian Rogersb726dcb2012-09-05 08:57:23 -0700380 LOCKS_EXCLUDED(Locks::thread_list_lock_,
381 Locks::thread_suspend_count_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700382 static void ResumeVM();
Elliott Hughes88d63092013-01-09 09:55:54 -0800383 static JDWP::JdwpError SuspendThread(JDWP::ObjectId thread_id, bool request_suspension = true)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700384 LOCKS_EXCLUDED(Locks::mutator_lock_,
385 Locks::thread_list_lock_,
386 Locks::thread_suspend_count_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700387
Elliott Hughes88d63092013-01-09 09:55:54 -0800388 static void ResumeThread(JDWP::ObjectId thread_id)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700389 LOCKS_EXCLUDED(Locks::thread_list_lock_,
390 Locks::thread_suspend_count_lock_)
391 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700392 static void SuspendSelf();
393
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700394 static JDWP::JdwpError GetThisObject(JDWP::ObjectId thread_id, JDWP::FrameId frame_id,
395 JDWP::ObjectId* result)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700396 LOCKS_EXCLUDED(Locks::thread_list_lock_,
397 Locks::thread_suspend_count_lock_)
398 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertzcb19ebf2014-03-11 15:26:35 +0100399 static JDWP::JdwpError GetLocalValue(JDWP::ObjectId thread_id, JDWP::FrameId frame_id, int slot,
400 JDWP::JdwpTag tag, uint8_t* buf, size_t expectedLen)
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100401 LOCKS_EXCLUDED(Locks::thread_list_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700402 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertzcb19ebf2014-03-11 15:26:35 +0100403 static JDWP::JdwpError SetLocalValue(JDWP::ObjectId thread_id, JDWP::FrameId frame_id, int slot,
404 JDWP::JdwpTag tag, uint64_t value, size_t width)
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100405 LOCKS_EXCLUDED(Locks::thread_list_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700406 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700407
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100408 static JDWP::JdwpError Interrupt(JDWP::ObjectId thread_id)
409 LOCKS_EXCLUDED(Locks::thread_list_lock_);
Elliott Hughesf9501702013-01-11 11:22:27 -0800410
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700411 /*
412 * Debugger notification
413 */
414 enum {
Elliott Hughes86964332012-02-15 19:37:42 -0800415 kBreakpoint = 0x01,
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700416 kSingleStep = 0x02,
417 kMethodEntry = 0x04,
418 kMethodExit = 0x08,
419 };
Sebastien Hertz3f52eaf2014-04-04 17:50:18 +0200420 static void PostFieldAccessEvent(mirror::ArtMethod* m, int dex_pc, mirror::Object* this_object,
421 mirror::ArtField* f)
422 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
423 static void PostFieldModificationEvent(mirror::ArtMethod* m, int dex_pc,
424 mirror::Object* this_object, mirror::ArtField* f,
425 const JValue* field_value)
426 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
427 static void PostException(const ThrowLocation& throw_location, mirror::ArtMethod* catch_method,
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800428 uint32_t catch_dex_pc, mirror::Throwable* exception)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700429 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700430 static void PostThreadStart(Thread* t)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700431 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700432 static void PostThreadDeath(Thread* t)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700433 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800434 static void PostClassPrepare(mirror::Class* c)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700435 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700436
Ian Rogers62d6c772013-02-27 08:32:07 -0800437 static void UpdateDebugger(Thread* thread, mirror::Object* this_object,
Sebastien Hertz8379b222014-02-24 17:38:15 +0100438 mirror::ArtMethod* method, uint32_t new_dex_pc,
439 int event_flags, const JValue* return_value)
jeffhao09bfc6a2012-12-11 18:11:43 -0800440 LOCKS_EXCLUDED(Locks::breakpoint_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700441 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes91bf6cd2012-02-14 17:27:48 -0800442
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100443 // Records deoptimization request in the queue.
444 static void RequestDeoptimization(const DeoptimizationRequest& req)
445 LOCKS_EXCLUDED(deoptimization_lock_)
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100446 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
447
Sebastien Hertz7ec2f1c2014-03-27 20:06:47 +0100448 // Support delayed full undeoptimization requests. This is currently only used for single-step
449 // events.
450 static void DelayFullUndeoptimization() LOCKS_EXCLUDED(deoptimization_lock_);
451 static void ProcessDelayedFullUndeoptimizations()
452 LOCKS_EXCLUDED(deoptimization_lock_)
453 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
454
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100455 // Manage deoptimization after updating JDWP events list. Suspends all threads, processes each
456 // request and finally resumes all threads.
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100457 static void ManageDeoptimization()
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100458 LOCKS_EXCLUDED(deoptimization_lock_)
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100459 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
460
461 // Breakpoints.
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100462 static void WatchLocation(const JDWP::JdwpLocation* pLoc, DeoptimizationRequest* req)
463 LOCKS_EXCLUDED(Locks::breakpoint_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700464 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100465 static void UnwatchLocation(const JDWP::JdwpLocation* pLoc, DeoptimizationRequest* req)
466 LOCKS_EXCLUDED(Locks::breakpoint_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700467 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100468
469 // Single-stepping.
Elliott Hughes88d63092013-01-09 09:55:54 -0800470 static JDWP::JdwpError ConfigureStep(JDWP::ObjectId thread_id, JDWP::JdwpStepSize size,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700471 JDWP::JdwpStepDepth depth)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700472 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +0100473 static void UnconfigureStep(JDWP::ObjectId thread_id)
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100474 LOCKS_EXCLUDED(Locks::thread_list_lock_)
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +0100475 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700476
Elliott Hughes88d63092013-01-09 09:55:54 -0800477 static JDWP::JdwpError InvokeMethod(JDWP::ObjectId thread_id, JDWP::ObjectId object_id,
478 JDWP::RefTypeId class_id, JDWP::MethodId method_id,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700479 uint32_t arg_count, uint64_t* arg_values,
480 JDWP::JdwpTag* arg_types, uint32_t options,
481 JDWP::JdwpTag* pResultTag, uint64_t* pResultValue,
482 JDWP::ObjectId* pExceptObj)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700483 LOCKS_EXCLUDED(Locks::thread_list_lock_,
484 Locks::thread_suspend_count_lock_)
485 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700486 static void ExecuteMethod(DebugInvokeReq* pReq);
487
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700488 /*
489 * DDM support.
490 */
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700491 static void DdmSendThreadNotification(Thread* t, uint32_t type)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700492 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100493 static void DdmSetThreadNotification(bool enable)
494 LOCKS_EXCLUDED(Locks::thread_list_lock_);
Elliott Hughes4b9702c2013-02-20 18:13:24 -0800495 static bool DdmHandlePacket(JDWP::Request& request, uint8_t** pReplyBuf, int* pReplyLen);
Ian Rogersb726dcb2012-09-05 08:57:23 -0700496 static void DdmConnected() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
497 static void DdmDisconnected() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700498 static void DdmSendChunk(uint32_t type, const std::vector<uint8_t>& bytes)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700499 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700500 static void DdmSendChunk(uint32_t type, size_t len, const uint8_t* buf)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700501 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700502 static void DdmSendChunkV(uint32_t type, const iovec* iov, int iov_count)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700503 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes767a1472011-10-26 18:49:02 -0700504
Mathieu Chartier3b05e9b2014-03-25 09:29:43 -0700505 static void VisitRoots(RootCallback* callback, void* arg)
506 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
507
Elliott Hughes545a0642011-11-08 19:10:03 -0800508 /*
509 * Recent allocation tracking support.
510 */
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800511 static void RecordAllocation(mirror::Class* type, size_t byte_count)
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100512 LOCKS_EXCLUDED(alloc_tracker_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700513 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100514 static void SetAllocTrackingEnabled(bool enabled) LOCKS_EXCLUDED(alloc_tracker_lock_);
Ian Rogers719d1a32014-03-06 12:13:39 -0800515 static bool IsAllocTrackingEnabled() {
516 return recent_allocation_records_ != nullptr;
517 }
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100518 static jbyteArray GetRecentAllocations()
519 LOCKS_EXCLUDED(alloc_tracker_lock_)
520 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers719d1a32014-03-06 12:13:39 -0800521 static size_t HeadIndex() EXCLUSIVE_LOCKS_REQUIRED(alloc_tracker_lock_);
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100522 static void DumpRecentAllocations() LOCKS_EXCLUDED(alloc_tracker_lock_);
Elliott Hughes545a0642011-11-08 19:10:03 -0800523
Mathieu Chartier412c7fc2014-02-07 12:18:39 -0800524 // Updates the stored direct object pointers (called from SweepSystemWeaks).
Mathieu Chartier83c8ee02014-01-28 14:50:23 -0800525 static void UpdateObjectPointers(IsMarkedCallback* callback, void* arg)
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100526 LOCKS_EXCLUDED(alloc_tracker_lock_)
Mathieu Chartier412c7fc2014-02-07 12:18:39 -0800527 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
528
Elliott Hughes767a1472011-10-26 18:49:02 -0700529 enum HpifWhen {
530 HPIF_WHEN_NEVER = 0,
531 HPIF_WHEN_NOW = 1,
532 HPIF_WHEN_NEXT_GC = 2,
533 HPIF_WHEN_EVERY_GC = 3
534 };
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700535 static int DdmHandleHpifChunk(HpifWhen when)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700536 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes767a1472011-10-26 18:49:02 -0700537
538 enum HpsgWhen {
539 HPSG_WHEN_NEVER = 0,
540 HPSG_WHEN_EVERY_GC = 1,
541 };
542 enum HpsgWhat {
543 HPSG_WHAT_MERGED_OBJECTS = 0,
544 HPSG_WHAT_DISTINCT_OBJECTS = 1,
545 };
546 static bool DdmHandleHpsgNhsgChunk(HpsgWhen when, HpsgWhat what, bool native);
547
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700548 static void DdmSendHeapInfo(HpifWhen reason)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700549 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700550 static void DdmSendHeapSegments(bool native)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700551 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes545a0642011-11-08 19:10:03 -0800552
Mathieu Chartier412c7fc2014-02-07 12:18:39 -0800553 static void AllowNewObjectRegistryObjects() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
554 static void DisallowNewObjectRegistryObjects() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
555
Elliott Hughes545a0642011-11-08 19:10:03 -0800556 private:
Brian Carlstrom2d888622013-07-18 17:02:00 -0700557 static void DdmBroadcast(bool connect) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700558 static void PostThreadStartOrStop(Thread*, uint32_t)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700559 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughesa2155262011-11-16 16:26:58 -0800560
Sebastien Hertz8379b222014-02-24 17:38:15 +0100561 static void PostLocationEvent(mirror::ArtMethod* method, int pcOffset,
562 mirror::Object* thisPtr, int eventFlags,
563 const JValue* return_value)
564 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
565
Sebastien Hertz3f52eaf2014-04-04 17:50:18 +0200566 static JDWP::ObjectId GetThisObjectIdForEvent(mirror::Object* this_object)
567 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
568
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100569 static void ProcessDeoptimizationRequest(const DeoptimizationRequest& request)
570 EXCLUSIVE_LOCKS_REQUIRED(Locks::mutator_lock_);
571
Sebastien Hertz7ec2f1c2014-03-27 20:06:47 +0100572 static void RequestDeoptimizationLocked(const DeoptimizationRequest& req)
573 EXCLUSIVE_LOCKS_REQUIRED(deoptimization_lock_)
574 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
575
Ian Rogers719d1a32014-03-06 12:13:39 -0800576 static Mutex* alloc_tracker_lock_ DEFAULT_MUTEX_ACQUIRED_AFTER;
577
578 static AllocRecord* recent_allocation_records_ PT_GUARDED_BY(alloc_tracker_lock_);
579 static size_t alloc_record_max_ GUARDED_BY(alloc_tracker_lock_);
580 static size_t alloc_record_head_ GUARDED_BY(alloc_tracker_lock_);
581 static size_t alloc_record_count_ GUARDED_BY(alloc_tracker_lock_);
582
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100583 // Guards deoptimization requests.
584 static Mutex* deoptimization_lock_ ACQUIRED_AFTER(Locks::breakpoint_lock_);
585
586 // Deoptimization requests to be processed each time the event list is updated. This is used when
587 // registering and unregistering events so we do not deoptimize while holding the event list
588 // lock.
589 static std::vector<DeoptimizationRequest> deoptimization_requests_ GUARDED_BY(deoptimization_lock_);
590
591 // Count the number of events requiring full deoptimization. When the counter is > 0, everything
592 // is deoptimized, otherwise everything is undeoptimized.
593 // Note: we fully deoptimize on the first event only (when the counter is set to 1). We fully
594 // undeoptimize when the last event is unregistered (when the counter is set to 0).
595 static size_t full_deoptimization_event_count_ GUARDED_BY(deoptimization_lock_);
596
Sebastien Hertz7ec2f1c2014-03-27 20:06:47 +0100597 // Count the number of full undeoptimization requests delayed to next resume or end of debug
598 // session.
599 static size_t delayed_full_undeoptimization_count_ GUARDED_BY(deoptimization_lock_);
600
Ian Rogers719d1a32014-03-06 12:13:39 -0800601 DISALLOW_COPY_AND_ASSIGN(Dbg);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700602};
603
604#define CHUNK_TYPE(_name) \
Elliott Hughes82188472011-11-07 18:11:48 -0800605 static_cast<uint32_t>((_name)[0] << 24 | (_name)[1] << 16 | (_name)[2] << 8 | (_name)[3])
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700606
607} // namespace art
608
Brian Carlstromfc0e3212013-07-17 14:40:12 -0700609#endif // ART_RUNTIME_DEBUGGER_H_