blob: 2589638461a040aa06b46ec216031a8c60630c04 [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;
Ian Rogers1b09b092012-08-20 15:35:52 -070046class Thread;
Ian Rogers62d6c772013-02-27 08:32:07 -080047class ThrowLocation;
Elliott Hughes872d4ec2011-10-21 17:07:15 -070048
49/*
50 * Invoke-during-breakpoint support.
51 */
52struct DebugInvokeReq {
Elliott Hughes7b3cdfc2011-12-08 21:28:17 -080053 DebugInvokeReq()
Sebastien Hertzd38667a2013-11-25 15:43:54 +010054 : ready(false), invoke_needed(false),
55 receiver(NULL), thread(NULL), klass(NULL), method(NULL),
56 arg_count(0), arg_values(NULL), options(0), error(JDWP::ERR_NONE),
Ian Rogers00f7d0e2012-07-19 15:28:27 -070057 result_tag(JDWP::JT_VOID), exception(0),
Sebastien Hertzd38667a2013-11-25 15:43:54 +010058 lock("a DebugInvokeReq lock", kBreakpointInvokeLock),
59 cond("a DebugInvokeReq condition variable", lock) {
Elliott Hughes475fc232011-10-25 15:00:35 -070060 }
61
Elliott Hughes872d4ec2011-10-21 17:07:15 -070062 /* boolean; only set when we're in the tail end of an event handler */
63 bool ready;
64
65 /* boolean; set if the JDWP thread wants this thread to do work */
Sebastien Hertzd38667a2013-11-25 15:43:54 +010066 bool invoke_needed;
Elliott Hughes872d4ec2011-10-21 17:07:15 -070067
68 /* request */
Sebastien Hertzd38667a2013-11-25 15:43:54 +010069 mirror::Object* receiver; /* not used for ClassType.InvokeMethod */
70 mirror::Object* thread;
71 mirror::Class* klass;
72 mirror::ArtMethod* method;
73 uint32_t arg_count;
74 uint64_t* arg_values; /* will be NULL if arg_count_ == 0 */
75 uint32_t options;
Elliott Hughes872d4ec2011-10-21 17:07:15 -070076
77 /* result */
Elliott Hughes475fc232011-10-25 15:00:35 -070078 JDWP::JdwpError error;
Elliott Hughesd07986f2011-12-06 18:27:45 -080079 JDWP::JdwpTag result_tag;
Elliott Hughes475fc232011-10-25 15:00:35 -070080 JValue result_value;
81 JDWP::ObjectId exception;
Elliott Hughes872d4ec2011-10-21 17:07:15 -070082
83 /* condition variable to wait on while the method executes */
Sebastien Hertzd38667a2013-11-25 15:43:54 +010084 Mutex lock DEFAULT_MUTEX_ACQUIRED_AFTER;
85 ConditionVariable cond GUARDED_BY(lock);
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +010086
Mathieu Chartier3b05e9b2014-03-25 09:29:43 -070087 void VisitRoots(RootCallback* callback, void* arg, uint32_t tid, RootType root_type)
88 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
89
Sebastien Hertzbb43b432014-04-14 11:59:08 +020090 void Clear();
91
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +010092 private:
93 DISALLOW_COPY_AND_ASSIGN(DebugInvokeReq);
94};
95
96// Thread local data-structure that holds fields for controlling single-stepping.
97struct SingleStepControl {
98 SingleStepControl()
99 : is_active(false), step_size(JDWP::SS_MIN), step_depth(JDWP::SD_INTO),
100 method(nullptr), stack_depth(0) {
101 }
102
103 // Are we single-stepping right now?
104 bool is_active;
105
106 // See JdwpStepSize and JdwpStepDepth for details.
107 JDWP::JdwpStepSize step_size;
108 JDWP::JdwpStepDepth step_depth;
109
110 // The location this single-step was initiated from.
111 // A single-step is initiated in a suspended thread. We save here the current method and the
112 // set of DEX pcs associated to the source line number where the suspension occurred.
113 // This is used to support SD_INTO and SD_OVER single-step depths so we detect when a single-step
114 // causes the execution of an instruction in a different method or at a different line number.
115 mirror::ArtMethod* method;
116 std::set<uint32_t> dex_pcs;
117
118 // The stack depth when this single-step was initiated. This is used to support SD_OVER and SD_OUT
119 // single-step depth.
120 int stack_depth;
121
Mathieu Chartier3b05e9b2014-03-25 09:29:43 -0700122 void VisitRoots(RootCallback* callback, void* arg, uint32_t tid, RootType root_type)
123 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
124
Sebastien Hertzbb43b432014-04-14 11:59:08 +0200125 bool ContainsDexPc(uint32_t dex_pc) const;
126
127 void Clear();
128
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +0100129 private:
130 DISALLOW_COPY_AND_ASSIGN(SingleStepControl);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700131};
132
Sebastien Hertz42cd43f2014-05-13 14:15:41 +0200133// TODO rename to InstrumentationRequest.
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100134struct DeoptimizationRequest {
135 enum Kind {
136 kNothing, // no action.
Sebastien Hertz42cd43f2014-05-13 14:15:41 +0200137 kRegisterForEvent, // start listening for instrumentation event.
138 kUnregisterForEvent, // stop listening for instrumentation event.
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100139 kFullDeoptimization, // deoptimize everything.
140 kFullUndeoptimization, // undeoptimize everything.
141 kSelectiveDeoptimization, // deoptimize one method.
142 kSelectiveUndeoptimization // undeoptimize one method.
143 };
144
Sebastien Hertz42cd43f2014-05-13 14:15:41 +0200145 DeoptimizationRequest() : kind(kNothing), instrumentation_event(0), method(nullptr) {}
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100146
147 void VisitRoots(RootCallback* callback, void* arg);
148
149 Kind kind;
150
Sebastien Hertz42cd43f2014-05-13 14:15:41 +0200151 // TODO we could use a union to hold the instrumentation_event and the method since they
152 // respectively have sense only for kRegisterForEvent/kUnregisterForEvent and
153 // kSelectiveDeoptimization/kSelectiveUndeoptimization.
154
155 // Event to start or stop listening to. Only for kRegisterForEvent and kUnregisterForEvent.
156 uint32_t instrumentation_event;
157
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100158 // Method for selective deoptimization.
159 mirror::ArtMethod* method;
160};
161
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700162class Dbg {
Elliott Hughesff17f1f2012-01-24 18:12:29 -0800163 public:
Mathieu Chartier4345c462014-06-27 10:20:14 -0700164 class TypeCache {
165 public:
166 // Returns a weak global for the input type. Deduplicates.
167 jobject Add(mirror::Class* t) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
168 // Clears the type cache and deletes all the weak global refs.
169 void Clear();
170
171 private:
172 std::multimap<int32_t, jobject> objects_;
173 };
174
Elliott Hughes3bb81562011-10-21 18:52:59 -0700175 static bool ParseJdwpOptions(const std::string& options);
Elliott Hughes4ffd3132011-10-24 12:06:42 -0700176 static void SetJdwpAllowed(bool allowed);
177
Elliott Hughesd1cc8362011-10-24 16:58:50 -0700178 static void StartJdwp();
179 static void StopJdwp();
180
Elliott Hughes767a1472011-10-26 18:49:02 -0700181 // Invoked by the GC in case we need to keep DDMS informed.
Ian Rogersb726dcb2012-09-05 08:57:23 -0700182 static void GcDidFinish() LOCKS_EXCLUDED(Locks::mutator_lock_);
Elliott Hughes767a1472011-10-26 18:49:02 -0700183
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700184 // Return the DebugInvokeReq for the current thread.
185 static DebugInvokeReq* GetInvokeReq();
186
Elliott Hughes475fc232011-10-25 15:00:35 -0700187 static Thread* GetDebugThread();
188 static void ClearWaitForEventThread();
189
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700190 /*
191 * Enable/disable breakpoints and step modes. Used to provide a heads-up
192 * when the debugger attaches.
193 */
194 static void Connected();
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100195 static void GoActive()
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100196 LOCKS_EXCLUDED(Locks::breakpoint_lock_, deoptimization_lock_, Locks::mutator_lock_);
197 static void Disconnected() LOCKS_EXCLUDED(deoptimization_lock_, Locks::mutator_lock_);
Elliott Hughes86964332012-02-15 19:37:42 -0800198 static void Disposed();
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700199
Elliott Hughesc0f09332012-03-26 13:27:06 -0700200 // Returns true if we're actually debugging with a real debugger, false if it's
201 // just DDMS (or nothing at all).
202 static bool IsDebuggerActive();
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700203
Elliott Hughesc0f09332012-03-26 13:27:06 -0700204 // Returns true if we had -Xrunjdwp or -agentlib:jdwp= on the command line.
205 static bool IsJdwpConfigured();
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700206
Elliott Hughes86964332012-02-15 19:37:42 -0800207 static bool IsDisposed();
208
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700209 /*
210 * Time, in milliseconds, since the last debugger activity. Does not
211 * include DDMS activity. Returns -1 if there has been no activity.
212 * Returns 0 if we're in the middle of handling a debugger request.
213 */
214 static int64_t LastDebuggerActivity();
215
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700216 static void UndoDebuggerSuspensions();
217
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700218 /*
219 * Class, Object, Array
220 */
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700221 static std::string GetClassName(JDWP::RefTypeId id)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700222 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800223 static JDWP::JdwpError GetClassObject(JDWP::RefTypeId id, JDWP::ObjectId& class_object_id)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700224 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800225 static JDWP::JdwpError GetSuperclass(JDWP::RefTypeId id, JDWP::RefTypeId& superclass_id)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700226 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700227 static JDWP::JdwpError GetClassLoader(JDWP::RefTypeId id, JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700228 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700229 static JDWP::JdwpError GetModifiers(JDWP::RefTypeId id, JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700230 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800231 static JDWP::JdwpError GetReflectedType(JDWP::RefTypeId class_id, JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700232 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700233 static void GetClassList(std::vector<JDWP::RefTypeId>& classes)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700234 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800235 static JDWP::JdwpError GetClassInfo(JDWP::RefTypeId class_id, JDWP::JdwpTypeTag* pTypeTag,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700236 uint32_t* pStatus, std::string* pDescriptor)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700237 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700238 static void FindLoadedClassBySignature(const char* descriptor, std::vector<JDWP::RefTypeId>& ids)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700239 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes64f574f2013-02-20 14:57:12 -0800240 static JDWP::JdwpError GetReferenceType(JDWP::ObjectId object_id, JDWP::ExpandBuf* pReply)
241 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersfc0e94b2013-09-23 23:51:32 -0700242 static JDWP::JdwpError GetSignature(JDWP::RefTypeId ref_type_id, std::string* signature)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700243 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800244 static JDWP::JdwpError GetSourceFile(JDWP::RefTypeId ref_type_id, std::string& source_file)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700245 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800246 static JDWP::JdwpError GetObjectTag(JDWP::ObjectId object_id, uint8_t& tag)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700247 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughesaed4be92011-12-02 16:16:23 -0800248 static size_t GetTagWidth(JDWP::JdwpTag tag);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700249
Elliott Hughes88d63092013-01-09 09:55:54 -0800250 static JDWP::JdwpError GetArrayLength(JDWP::ObjectId array_id, int& length)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700251 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800252 static JDWP::JdwpError OutputArray(JDWP::ObjectId array_id, int offset, int count,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700253 JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700254 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800255 static JDWP::JdwpError SetArrayElements(JDWP::ObjectId array_id, int offset, int count,
Elliott Hughes4b9702c2013-02-20 18:13:24 -0800256 JDWP::Request& request)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700257 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700258
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700259 static JDWP::ObjectId CreateString(const std::string& str)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700260 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800261 static JDWP::JdwpError CreateObject(JDWP::RefTypeId class_id, JDWP::ObjectId& new_object)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700262 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800263 static JDWP::JdwpError CreateArrayObject(JDWP::RefTypeId array_class_id, uint32_t length,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700264 JDWP::ObjectId& new_array)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700265 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700266
Elliott Hughes88d63092013-01-09 09:55:54 -0800267 static bool MatchType(JDWP::RefTypeId instance_class_id, JDWP::RefTypeId class_id)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700268 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700269
Elliott Hughesec0f83d2013-01-15 16:54:08 -0800270 //
271 // Monitors.
272 //
273 static JDWP::JdwpError GetMonitorInfo(JDWP::ObjectId object_id, JDWP::ExpandBuf* reply)
274 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
275 static JDWP::JdwpError GetOwnedMonitors(JDWP::ObjectId thread_id,
276 std::vector<JDWP::ObjectId>& monitors,
277 std::vector<uint32_t>& stack_depths)
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100278 LOCKS_EXCLUDED(Locks::thread_list_lock_)
Elliott Hughesec0f83d2013-01-15 16:54:08 -0800279 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100280 static JDWP::JdwpError GetContendedMonitor(JDWP::ObjectId thread_id,
281 JDWP::ObjectId& contended_monitor)
282 LOCKS_EXCLUDED(Locks::thread_list_lock_)
Elliott Hughesec0f83d2013-01-15 16:54:08 -0800283 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
284
285 //
286 // Heap.
287 //
288 static JDWP::JdwpError GetInstanceCounts(const std::vector<JDWP::RefTypeId>& class_ids,
289 std::vector<uint64_t>& counts)
290 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes3b78c942013-01-15 17:35:41 -0800291 static JDWP::JdwpError GetInstances(JDWP::RefTypeId class_id, int32_t max_count,
292 std::vector<JDWP::ObjectId>& instances)
293 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes0cbaff52013-01-16 15:28:01 -0800294 static JDWP::JdwpError GetReferringObjects(JDWP::ObjectId object_id, int32_t max_count,
295 std::vector<JDWP::ObjectId>& referring_objects)
296 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes64f574f2013-02-20 14:57:12 -0800297 static JDWP::JdwpError DisableCollection(JDWP::ObjectId object_id)
298 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
299 static JDWP::JdwpError EnableCollection(JDWP::ObjectId object_id)
300 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
301 static JDWP::JdwpError IsCollected(JDWP::ObjectId object_id, bool& is_collected)
302 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
303 static void DisposeObject(JDWP::ObjectId object_id, uint32_t reference_count)
304 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughesec0f83d2013-01-15 16:54:08 -0800305
Elliott Hughes9777ba22013-01-17 09:04:19 -0800306 //
307 // Methods and fields.
308 //
Elliott Hughesa96836a2013-01-17 12:27:49 -0800309 static std::string GetMethodName(JDWP::MethodId method_id)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700310 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800311 static JDWP::JdwpError OutputDeclaredFields(JDWP::RefTypeId ref_type_id, bool with_generic,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700312 JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700313 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800314 static JDWP::JdwpError OutputDeclaredMethods(JDWP::RefTypeId ref_type_id, bool with_generic,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700315 JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700316 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800317 static JDWP::JdwpError OutputDeclaredInterfaces(JDWP::RefTypeId ref_type_id,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700318 JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700319 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800320 static void OutputLineTable(JDWP::RefTypeId ref_type_id, JDWP::MethodId method_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 void OutputVariableTable(JDWP::RefTypeId ref_type_id, JDWP::MethodId id, bool with_generic,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700324 JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700325 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Jeff Hao579b0242013-11-18 13:16:49 -0800326 static void OutputMethodReturnValue(JDWP::MethodId method_id, const JValue* return_value,
327 JDWP::ExpandBuf* pReply)
328 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertz3f52eaf2014-04-04 17:50:18 +0200329 static void OutputFieldValue(JDWP::FieldId field_id, const JValue* field_value,
330 JDWP::ExpandBuf* pReply)
331 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes9777ba22013-01-17 09:04:19 -0800332 static JDWP::JdwpError GetBytecodes(JDWP::RefTypeId class_id, JDWP::MethodId method_id,
333 std::vector<uint8_t>& bytecodes)
334 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700335
Elliott Hughesa96836a2013-01-17 12:27:49 -0800336 static std::string GetFieldName(JDWP::FieldId field_id)
337 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800338 static JDWP::JdwpTag GetFieldBasicTag(JDWP::FieldId field_id)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700339 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800340 static JDWP::JdwpTag GetStaticFieldBasicTag(JDWP::FieldId field_id)
Brian Carlstromf69863b2013-07-17 21:53:13 -0700341 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800342 static JDWP::JdwpError GetFieldValue(JDWP::ObjectId object_id, JDWP::FieldId field_id,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700343 JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700344 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800345 static JDWP::JdwpError SetFieldValue(JDWP::ObjectId object_id, JDWP::FieldId field_id,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700346 uint64_t value, int width)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700347 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800348 static JDWP::JdwpError GetStaticFieldValue(JDWP::RefTypeId ref_type_id, JDWP::FieldId field_id,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700349 JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700350 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800351 static JDWP::JdwpError SetStaticFieldValue(JDWP::FieldId field_id, uint64_t value, int width)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700352 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700353
Elliott Hughes88d63092013-01-09 09:55:54 -0800354 static std::string StringToUtf8(JDWP::ObjectId string_id)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700355 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Jeff Hao579b0242013-11-18 13:16:49 -0800356 static void OutputJValue(JDWP::JdwpTag tag, const JValue* return_value, JDWP::ExpandBuf* pReply)
357 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700358
359 /*
360 * Thread, ThreadGroup, Frame
361 */
Elliott Hughes88d63092013-01-09 09:55:54 -0800362 static JDWP::JdwpError GetThreadName(JDWP::ObjectId thread_id, std::string& name)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700363 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_)
364 LOCKS_EXCLUDED(Locks::thread_list_lock_);
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100365 static JDWP::JdwpError GetThreadGroup(JDWP::ObjectId thread_id, JDWP::ExpandBuf* pReply)
366 LOCKS_EXCLUDED(Locks::thread_list_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800367 static std::string GetThreadGroupName(JDWP::ObjectId thread_group_id);
368 static JDWP::ObjectId GetThreadGroupParent(JDWP::ObjectId thread_group_id)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700369 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700370 static JDWP::ObjectId GetSystemThreadGroupId()
Ian Rogersb726dcb2012-09-05 08:57:23 -0700371 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700372 static JDWP::ObjectId GetMainThreadGroupId();
373
Jeff Hao920af3e2013-08-28 15:46:38 -0700374 static JDWP::JdwpThreadStatus ToJdwpThreadStatus(ThreadState state);
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100375 static JDWP::JdwpError GetThreadStatus(JDWP::ObjectId thread_id,
376 JDWP::JdwpThreadStatus* pThreadStatus,
377 JDWP::JdwpSuspendStatus* pSuspendStatus)
378 LOCKS_EXCLUDED(Locks::thread_list_lock_);
379 static JDWP::JdwpError GetThreadDebugSuspendCount(JDWP::ObjectId thread_id,
380 JDWP::ExpandBuf* pReply)
381 LOCKS_EXCLUDED(Locks::thread_list_lock_,
382 Locks::thread_suspend_count_lock_);
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700383 // static void WaitForSuspend(JDWP::ObjectId thread_id);
Elliott Hughescaf76542012-06-28 16:08:22 -0700384
Elliott Hughes026b1462012-06-28 20:43:49 -0700385 // Fills 'thread_ids' with the threads in the given thread group. If thread_group_id == 0,
Elliott Hughescaf76542012-06-28 16:08:22 -0700386 // returns all threads.
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700387 static void GetThreads(JDWP::ObjectId thread_group_id, std::vector<JDWP::ObjectId>& thread_ids)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700388 LOCKS_EXCLUDED(Locks::thread_list_lock_)
389 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughescaf76542012-06-28 16:08:22 -0700390 static void GetChildThreadGroups(JDWP::ObjectId thread_group_id, std::vector<JDWP::ObjectId>& child_thread_group_ids);
391
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100392 static JDWP::JdwpError GetThreadFrameCount(JDWP::ObjectId thread_id, size_t& result)
393 LOCKS_EXCLUDED(Locks::thread_list_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700394 static JDWP::JdwpError GetThreadFrames(JDWP::ObjectId thread_id, size_t start_frame,
395 size_t frame_count, JDWP::ExpandBuf* buf)
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100396 LOCKS_EXCLUDED(Locks::thread_list_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700397 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700398
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700399 static JDWP::ObjectId GetThreadSelfId()
Ian Rogersb726dcb2012-09-05 08:57:23 -0700400 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700401 static void SuspendVM()
Ian Rogersb726dcb2012-09-05 08:57:23 -0700402 LOCKS_EXCLUDED(Locks::thread_list_lock_,
403 Locks::thread_suspend_count_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700404 static void ResumeVM();
Elliott Hughes88d63092013-01-09 09:55:54 -0800405 static JDWP::JdwpError SuspendThread(JDWP::ObjectId thread_id, bool request_suspension = true)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700406 LOCKS_EXCLUDED(Locks::mutator_lock_,
407 Locks::thread_list_lock_,
408 Locks::thread_suspend_count_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700409
Elliott Hughes88d63092013-01-09 09:55:54 -0800410 static void ResumeThread(JDWP::ObjectId thread_id)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700411 LOCKS_EXCLUDED(Locks::thread_list_lock_,
412 Locks::thread_suspend_count_lock_)
413 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700414 static void SuspendSelf();
415
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700416 static JDWP::JdwpError GetThisObject(JDWP::ObjectId thread_id, JDWP::FrameId frame_id,
417 JDWP::ObjectId* result)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700418 LOCKS_EXCLUDED(Locks::thread_list_lock_,
419 Locks::thread_suspend_count_lock_)
420 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertzcb19ebf2014-03-11 15:26:35 +0100421 static JDWP::JdwpError GetLocalValue(JDWP::ObjectId thread_id, JDWP::FrameId frame_id, int slot,
422 JDWP::JdwpTag tag, uint8_t* buf, size_t expectedLen)
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100423 LOCKS_EXCLUDED(Locks::thread_list_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700424 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertzcb19ebf2014-03-11 15:26:35 +0100425 static JDWP::JdwpError SetLocalValue(JDWP::ObjectId thread_id, JDWP::FrameId frame_id, int slot,
426 JDWP::JdwpTag tag, uint64_t value, size_t width)
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100427 LOCKS_EXCLUDED(Locks::thread_list_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700428 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700429
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100430 static JDWP::JdwpError Interrupt(JDWP::ObjectId thread_id)
431 LOCKS_EXCLUDED(Locks::thread_list_lock_);
Elliott Hughesf9501702013-01-11 11:22:27 -0800432
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700433 /*
434 * Debugger notification
435 */
436 enum {
Elliott Hughes86964332012-02-15 19:37:42 -0800437 kBreakpoint = 0x01,
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700438 kSingleStep = 0x02,
439 kMethodEntry = 0x04,
440 kMethodExit = 0x08,
441 };
Sebastien Hertz3f52eaf2014-04-04 17:50:18 +0200442 static void PostFieldAccessEvent(mirror::ArtMethod* m, int dex_pc, mirror::Object* this_object,
443 mirror::ArtField* f)
444 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
445 static void PostFieldModificationEvent(mirror::ArtMethod* m, int dex_pc,
446 mirror::Object* this_object, mirror::ArtField* f,
447 const JValue* field_value)
448 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
449 static void PostException(const ThrowLocation& throw_location, mirror::ArtMethod* catch_method,
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800450 uint32_t catch_dex_pc, mirror::Throwable* exception)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700451 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700452 static void PostThreadStart(Thread* t)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700453 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700454 static void PostThreadDeath(Thread* t)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700455 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800456 static void PostClassPrepare(mirror::Class* c)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700457 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700458
Ian Rogers62d6c772013-02-27 08:32:07 -0800459 static void UpdateDebugger(Thread* thread, mirror::Object* this_object,
Sebastien Hertz8379b222014-02-24 17:38:15 +0100460 mirror::ArtMethod* method, uint32_t new_dex_pc,
461 int event_flags, const JValue* return_value)
jeffhao09bfc6a2012-12-11 18:11:43 -0800462 LOCKS_EXCLUDED(Locks::breakpoint_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700463 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes91bf6cd2012-02-14 17:27:48 -0800464
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100465 // Records deoptimization request in the queue.
466 static void RequestDeoptimization(const DeoptimizationRequest& req)
467 LOCKS_EXCLUDED(deoptimization_lock_)
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100468 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
469
Sebastien Hertz7ec2f1c2014-03-27 20:06:47 +0100470 // Support delayed full undeoptimization requests. This is currently only used for single-step
471 // events.
472 static void DelayFullUndeoptimization() LOCKS_EXCLUDED(deoptimization_lock_);
473 static void ProcessDelayedFullUndeoptimizations()
474 LOCKS_EXCLUDED(deoptimization_lock_)
475 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
476
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100477 // Manage deoptimization after updating JDWP events list. Suspends all threads, processes each
478 // request and finally resumes all threads.
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100479 static void ManageDeoptimization()
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100480 LOCKS_EXCLUDED(deoptimization_lock_)
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100481 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
482
483 // Breakpoints.
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100484 static void WatchLocation(const JDWP::JdwpLocation* pLoc, DeoptimizationRequest* req)
485 LOCKS_EXCLUDED(Locks::breakpoint_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700486 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100487 static void UnwatchLocation(const JDWP::JdwpLocation* pLoc, DeoptimizationRequest* req)
488 LOCKS_EXCLUDED(Locks::breakpoint_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700489 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100490
491 // Single-stepping.
Elliott Hughes88d63092013-01-09 09:55:54 -0800492 static JDWP::JdwpError ConfigureStep(JDWP::ObjectId thread_id, JDWP::JdwpStepSize size,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700493 JDWP::JdwpStepDepth depth)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700494 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +0100495 static void UnconfigureStep(JDWP::ObjectId thread_id)
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100496 LOCKS_EXCLUDED(Locks::thread_list_lock_)
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +0100497 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700498
Elliott Hughes88d63092013-01-09 09:55:54 -0800499 static JDWP::JdwpError InvokeMethod(JDWP::ObjectId thread_id, JDWP::ObjectId object_id,
500 JDWP::RefTypeId class_id, JDWP::MethodId method_id,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700501 uint32_t arg_count, uint64_t* arg_values,
502 JDWP::JdwpTag* arg_types, uint32_t options,
503 JDWP::JdwpTag* pResultTag, uint64_t* pResultValue,
504 JDWP::ObjectId* pExceptObj)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700505 LOCKS_EXCLUDED(Locks::thread_list_lock_,
506 Locks::thread_suspend_count_lock_)
507 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700508 static void ExecuteMethod(DebugInvokeReq* pReq);
509
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700510 /*
511 * DDM support.
512 */
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700513 static void DdmSendThreadNotification(Thread* t, uint32_t type)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700514 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100515 static void DdmSetThreadNotification(bool enable)
516 LOCKS_EXCLUDED(Locks::thread_list_lock_);
Elliott Hughes4b9702c2013-02-20 18:13:24 -0800517 static bool DdmHandlePacket(JDWP::Request& request, uint8_t** pReplyBuf, int* pReplyLen);
Ian Rogersb726dcb2012-09-05 08:57:23 -0700518 static void DdmConnected() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
519 static void DdmDisconnected() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700520 static void DdmSendChunk(uint32_t type, const std::vector<uint8_t>& bytes)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700521 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700522 static void DdmSendChunk(uint32_t type, size_t len, const uint8_t* buf)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700523 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700524 static void DdmSendChunkV(uint32_t type, const iovec* iov, int iov_count)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700525 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes767a1472011-10-26 18:49:02 -0700526
Mathieu Chartier3b05e9b2014-03-25 09:29:43 -0700527 static void VisitRoots(RootCallback* callback, void* arg)
528 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
529
Elliott Hughes545a0642011-11-08 19:10:03 -0800530 /*
531 * Recent allocation tracking support.
532 */
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800533 static void RecordAllocation(mirror::Class* type, size_t byte_count)
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100534 LOCKS_EXCLUDED(alloc_tracker_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700535 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100536 static void SetAllocTrackingEnabled(bool enabled) LOCKS_EXCLUDED(alloc_tracker_lock_);
Ian Rogers719d1a32014-03-06 12:13:39 -0800537 static bool IsAllocTrackingEnabled() {
538 return recent_allocation_records_ != nullptr;
539 }
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100540 static jbyteArray GetRecentAllocations()
541 LOCKS_EXCLUDED(alloc_tracker_lock_)
542 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers719d1a32014-03-06 12:13:39 -0800543 static size_t HeadIndex() EXCLUSIVE_LOCKS_REQUIRED(alloc_tracker_lock_);
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100544 static void DumpRecentAllocations() LOCKS_EXCLUDED(alloc_tracker_lock_);
Elliott Hughes545a0642011-11-08 19:10:03 -0800545
Elliott Hughes767a1472011-10-26 18:49:02 -0700546 enum HpifWhen {
547 HPIF_WHEN_NEVER = 0,
548 HPIF_WHEN_NOW = 1,
549 HPIF_WHEN_NEXT_GC = 2,
550 HPIF_WHEN_EVERY_GC = 3
551 };
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700552 static int DdmHandleHpifChunk(HpifWhen when)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700553 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes767a1472011-10-26 18:49:02 -0700554
555 enum HpsgWhen {
556 HPSG_WHEN_NEVER = 0,
557 HPSG_WHEN_EVERY_GC = 1,
558 };
559 enum HpsgWhat {
560 HPSG_WHAT_MERGED_OBJECTS = 0,
561 HPSG_WHAT_DISTINCT_OBJECTS = 1,
562 };
563 static bool DdmHandleHpsgNhsgChunk(HpsgWhen when, HpsgWhat what, bool native);
564
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700565 static void DdmSendHeapInfo(HpifWhen reason)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700566 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700567 static void DdmSendHeapSegments(bool native)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700568 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes545a0642011-11-08 19:10:03 -0800569
Mathieu Chartier4345c462014-06-27 10:20:14 -0700570 static TypeCache& GetTypeCache() {
571 return type_cache_;
572 }
573
Elliott Hughes545a0642011-11-08 19:10:03 -0800574 private:
Brian Carlstrom2d888622013-07-18 17:02:00 -0700575 static void DdmBroadcast(bool connect) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700576 static void PostThreadStartOrStop(Thread*, uint32_t)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700577 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughesa2155262011-11-16 16:26:58 -0800578
Sebastien Hertz8379b222014-02-24 17:38:15 +0100579 static void PostLocationEvent(mirror::ArtMethod* method, int pcOffset,
580 mirror::Object* thisPtr, int eventFlags,
581 const JValue* return_value)
582 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
583
Sebastien Hertz3f52eaf2014-04-04 17:50:18 +0200584 static JDWP::ObjectId GetThisObjectIdForEvent(mirror::Object* this_object)
585 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
586
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100587 static void ProcessDeoptimizationRequest(const DeoptimizationRequest& request)
588 EXCLUSIVE_LOCKS_REQUIRED(Locks::mutator_lock_);
589
Sebastien Hertz7ec2f1c2014-03-27 20:06:47 +0100590 static void RequestDeoptimizationLocked(const DeoptimizationRequest& req)
591 EXCLUSIVE_LOCKS_REQUIRED(deoptimization_lock_)
592 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
593
Ian Rogers719d1a32014-03-06 12:13:39 -0800594 static Mutex* alloc_tracker_lock_ DEFAULT_MUTEX_ACQUIRED_AFTER;
595
596 static AllocRecord* recent_allocation_records_ PT_GUARDED_BY(alloc_tracker_lock_);
597 static size_t alloc_record_max_ GUARDED_BY(alloc_tracker_lock_);
598 static size_t alloc_record_head_ GUARDED_BY(alloc_tracker_lock_);
599 static size_t alloc_record_count_ GUARDED_BY(alloc_tracker_lock_);
600
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100601 // Guards deoptimization requests.
Sebastien Hertz42cd43f2014-05-13 14:15:41 +0200602 // TODO rename to instrumentation_update_lock.
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100603 static Mutex* deoptimization_lock_ ACQUIRED_AFTER(Locks::breakpoint_lock_);
604
605 // Deoptimization requests to be processed each time the event list is updated. This is used when
606 // registering and unregistering events so we do not deoptimize while holding the event list
607 // lock.
Sebastien Hertz42cd43f2014-05-13 14:15:41 +0200608 // TODO rename to instrumentation_requests.
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100609 static std::vector<DeoptimizationRequest> deoptimization_requests_ GUARDED_BY(deoptimization_lock_);
610
611 // Count the number of events requiring full deoptimization. When the counter is > 0, everything
612 // is deoptimized, otherwise everything is undeoptimized.
613 // Note: we fully deoptimize on the first event only (when the counter is set to 1). We fully
614 // undeoptimize when the last event is unregistered (when the counter is set to 0).
615 static size_t full_deoptimization_event_count_ GUARDED_BY(deoptimization_lock_);
616
Sebastien Hertz7ec2f1c2014-03-27 20:06:47 +0100617 // Count the number of full undeoptimization requests delayed to next resume or end of debug
618 // session.
619 static size_t delayed_full_undeoptimization_count_ GUARDED_BY(deoptimization_lock_);
620
Sebastien Hertz42cd43f2014-05-13 14:15:41 +0200621 static size_t* GetReferenceCounterForEvent(uint32_t instrumentation_event);
622
Mathieu Chartier4345c462014-06-27 10:20:14 -0700623 // Weak global type cache, TODO improve this.
624 static TypeCache type_cache_;
625
Sebastien Hertz42cd43f2014-05-13 14:15:41 +0200626 // Instrumentation event reference counters.
627 // TODO we could use an array instead of having all these dedicated counters. Instrumentation
628 // events are bits of a mask so we could convert them to array index.
629 static size_t dex_pc_change_event_ref_count_ GUARDED_BY(deoptimization_lock_);
630 static size_t method_enter_event_ref_count_ GUARDED_BY(deoptimization_lock_);
631 static size_t method_exit_event_ref_count_ GUARDED_BY(deoptimization_lock_);
632 static size_t field_read_event_ref_count_ GUARDED_BY(deoptimization_lock_);
633 static size_t field_write_event_ref_count_ GUARDED_BY(deoptimization_lock_);
634 static size_t exception_catch_event_ref_count_ GUARDED_BY(deoptimization_lock_);
635 static uint32_t instrumentation_events_ GUARDED_BY(Locks::mutator_lock_);
636
Ian Rogers719d1a32014-03-06 12:13:39 -0800637 DISALLOW_COPY_AND_ASSIGN(Dbg);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700638};
639
640#define CHUNK_TYPE(_name) \
Elliott Hughes82188472011-11-07 18:11:48 -0800641 static_cast<uint32_t>((_name)[0] << 24 | (_name)[1] << 16 | (_name)[2] << 8 | (_name)[3])
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700642
643} // namespace art
644
Brian Carlstromfc0e3212013-07-17 14:40:12 -0700645#endif // ART_RUNTIME_DEBUGGER_H_