blob: fe90eb613ec1edf8144ca403485dd40d3cbf6303 [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 {
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;
Mathieu Chartierc7853442015-03-27 14:35:38 -070046class ArtField;
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;
Elliott Hughes872d4ec2011-10-21 17:07:15 -070051
52/*
53 * Invoke-during-breakpoint support.
54 */
55struct DebugInvokeReq {
Sebastien Hertz1558b572015-02-25 15:05:59 +010056 DebugInvokeReq(mirror::Object* invoke_receiver, mirror::Class* invoke_class,
57 mirror::ArtMethod* invoke_method, uint32_t invoke_options,
58 uint64_t* args, uint32_t args_count)
59 : receiver(invoke_receiver), klass(invoke_class), method(invoke_method),
60 arg_count(args_count), arg_values(args), options(invoke_options),
61 error(JDWP::ERR_NONE), result_tag(JDWP::JT_VOID), result_value(0), 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 /* request */
Sebastien Hertz1558b572015-02-25 15:05:59 +010067 GcRoot<mirror::Object> receiver; // not used for ClassType.InvokeMethod
68 GcRoot<mirror::Class> klass;
69 GcRoot<mirror::ArtMethod> method;
70 const uint32_t arg_count;
Mathieu Chartier2cebb242015-04-21 16:50:40 -070071 uint64_t* const arg_values; // will be null if arg_count_ == 0
Sebastien Hertz1558b572015-02-25 15:05:59 +010072 const uint32_t options;
Elliott Hughes872d4ec2011-10-21 17:07:15 -070073
74 /* result */
Elliott Hughes475fc232011-10-25 15:00:35 -070075 JDWP::JdwpError error;
Elliott Hughesd07986f2011-12-06 18:27:45 -080076 JDWP::JdwpTag result_tag;
Sebastien Hertz1558b572015-02-25 15:05:59 +010077 uint64_t result_value; // either a primitive value or an ObjectId
Elliott Hughes475fc232011-10-25 15:00:35 -070078 JDWP::ObjectId exception;
Elliott Hughes872d4ec2011-10-21 17:07:15 -070079
80 /* condition variable to wait on while the method executes */
Sebastien Hertzd38667a2013-11-25 15:43:54 +010081 Mutex lock DEFAULT_MUTEX_ACQUIRED_AFTER;
82 ConditionVariable cond GUARDED_BY(lock);
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +010083
Mathieu Chartierbb87e0f2015-04-03 11:21:55 -070084 void VisitRoots(RootVisitor* visitor, const RootInfo& root_info)
Mathieu Chartier3b05e9b2014-03-25 09:29:43 -070085 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
86
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +010087 private:
88 DISALLOW_COPY_AND_ASSIGN(DebugInvokeReq);
89};
90
91// Thread local data-structure that holds fields for controlling single-stepping.
Sebastien Hertz597c4f02015-01-26 17:37:14 +010092class SingleStepControl {
93 public:
94 SingleStepControl(JDWP::JdwpStepSize step_size, JDWP::JdwpStepDepth step_depth,
95 int stack_depth, mirror::ArtMethod* method)
96 : step_size_(step_size), step_depth_(step_depth),
97 stack_depth_(stack_depth), method_(method) {
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +010098 }
99
Sebastien Hertz597c4f02015-01-26 17:37:14 +0100100 JDWP::JdwpStepSize GetStepSize() const {
101 return step_size_;
102 }
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +0100103
Sebastien Hertz597c4f02015-01-26 17:37:14 +0100104 JDWP::JdwpStepDepth GetStepDepth() const {
105 return step_depth_;
106 }
107
108 int GetStackDepth() const {
109 return stack_depth_;
110 }
111
112 mirror::ArtMethod* GetMethod() const {
113 return method_;
114 }
115
116 const std::set<uint32_t>& GetDexPcs() const {
117 return dex_pcs_;
118 }
119
Mathieu Chartierbb87e0f2015-04-03 11:21:55 -0700120 void VisitRoots(RootVisitor* visitor, const RootInfo& root_info)
Sebastien Hertz597c4f02015-01-26 17:37:14 +0100121 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
122
123 void AddDexPc(uint32_t dex_pc);
124
125 bool ContainsDexPc(uint32_t dex_pc) const;
126
127 private:
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +0100128 // See JdwpStepSize and JdwpStepDepth for details.
Sebastien Hertz597c4f02015-01-26 17:37:14 +0100129 const JDWP::JdwpStepSize step_size_;
130 const JDWP::JdwpStepDepth step_depth_;
131
132 // The stack depth when this single-step was initiated. This is used to support SD_OVER and SD_OUT
133 // single-step depth.
134 const int stack_depth_;
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +0100135
136 // The location this single-step was initiated from.
137 // A single-step is initiated in a suspended thread. We save here the current method and the
138 // set of DEX pcs associated to the source line number where the suspension occurred.
139 // This is used to support SD_INTO and SD_OVER single-step depths so we detect when a single-step
140 // causes the execution of an instruction in a different method or at a different line number.
Sebastien Hertz597c4f02015-01-26 17:37:14 +0100141 mirror::ArtMethod* method_;
142 std::set<uint32_t> dex_pcs_;
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +0100143
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +0100144 DISALLOW_COPY_AND_ASSIGN(SingleStepControl);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700145};
146
Sebastien Hertz42cd43f2014-05-13 14:15:41 +0200147// TODO rename to InstrumentationRequest.
Hiroshi Yamauchi0ec17d22014-07-07 13:07:08 -0700148class DeoptimizationRequest {
149 public:
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100150 enum Kind {
151 kNothing, // no action.
Sebastien Hertz42cd43f2014-05-13 14:15:41 +0200152 kRegisterForEvent, // start listening for instrumentation event.
153 kUnregisterForEvent, // stop listening for instrumentation event.
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100154 kFullDeoptimization, // deoptimize everything.
155 kFullUndeoptimization, // undeoptimize everything.
156 kSelectiveDeoptimization, // deoptimize one method.
157 kSelectiveUndeoptimization // undeoptimize one method.
158 };
159
Hiroshi Yamauchi0ec17d22014-07-07 13:07:08 -0700160 DeoptimizationRequest() : kind_(kNothing), instrumentation_event_(0), method_(nullptr) {}
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100161
Hiroshi Yamauchi0ec17d22014-07-07 13:07:08 -0700162 DeoptimizationRequest(const DeoptimizationRequest& other)
163 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_)
164 : kind_(other.kind_), instrumentation_event_(other.instrumentation_event_) {
165 // Create a new JNI global reference for the method.
166 SetMethod(other.Method());
167 }
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100168
Hiroshi Yamauchi0ec17d22014-07-07 13:07:08 -0700169 mirror::ArtMethod* Method() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
170
171 void SetMethod(mirror::ArtMethod* m) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
172
173 // Name 'Kind()' would collide with the above enum name.
174 Kind GetKind() const {
175 return kind_;
176 }
177
178 void SetKind(Kind kind) {
179 kind_ = kind;
180 }
181
182 uint32_t InstrumentationEvent() const {
183 return instrumentation_event_;
184 }
185
186 void SetInstrumentationEvent(uint32_t instrumentation_event) {
187 instrumentation_event_ = instrumentation_event;
188 }
189
190 private:
191 Kind kind_;
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100192
Sebastien Hertz42cd43f2014-05-13 14:15:41 +0200193 // TODO we could use a union to hold the instrumentation_event and the method since they
194 // respectively have sense only for kRegisterForEvent/kUnregisterForEvent and
195 // kSelectiveDeoptimization/kSelectiveUndeoptimization.
196
197 // Event to start or stop listening to. Only for kRegisterForEvent and kUnregisterForEvent.
Hiroshi Yamauchi0ec17d22014-07-07 13:07:08 -0700198 uint32_t instrumentation_event_;
Sebastien Hertz42cd43f2014-05-13 14:15:41 +0200199
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100200 // Method for selective deoptimization.
Hiroshi Yamauchi0ec17d22014-07-07 13:07:08 -0700201 jmethodID method_;
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100202};
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700203std::ostream& operator<<(std::ostream& os, const DeoptimizationRequest::Kind& rhs);
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100204
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700205class Dbg {
Elliott Hughesff17f1f2012-01-24 18:12:29 -0800206 public:
Mathieu Chartier4345c462014-06-27 10:20:14 -0700207 class TypeCache {
208 public:
209 // Returns a weak global for the input type. Deduplicates.
Brian Carlstrom306db812014-09-05 13:01:41 -0700210 jobject Add(mirror::Class* t) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_,
211 Locks::alloc_tracker_lock_);
Mathieu Chartier4345c462014-06-27 10:20:14 -0700212 // Clears the type cache and deletes all the weak global refs.
Brian Carlstrom306db812014-09-05 13:01:41 -0700213 void Clear() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_,
214 Locks::alloc_tracker_lock_);
Mathieu Chartier4345c462014-06-27 10:20:14 -0700215
216 private:
217 std::multimap<int32_t, jobject> objects_;
218 };
219
Elliott Hughes4ffd3132011-10-24 12:06:42 -0700220 static void SetJdwpAllowed(bool allowed);
221
Sebastien Hertzb3b173b2015-02-06 09:16:32 +0100222 static void StartJdwp();
Elliott Hughesd1cc8362011-10-24 16:58:50 -0700223 static void StopJdwp();
224
Elliott Hughes767a1472011-10-26 18:49:02 -0700225 // Invoked by the GC in case we need to keep DDMS informed.
Ian Rogersb726dcb2012-09-05 08:57:23 -0700226 static void GcDidFinish() LOCKS_EXCLUDED(Locks::mutator_lock_);
Elliott Hughes767a1472011-10-26 18:49:02 -0700227
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700228 // Return the DebugInvokeReq for the current thread.
229 static DebugInvokeReq* GetInvokeReq();
230
Elliott Hughes475fc232011-10-25 15:00:35 -0700231 static Thread* GetDebugThread();
232 static void ClearWaitForEventThread();
233
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700234 /*
235 * Enable/disable breakpoints and step modes. Used to provide a heads-up
236 * when the debugger attaches.
237 */
238 static void Connected();
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100239 static void GoActive()
Brian Carlstrom306db812014-09-05 13:01:41 -0700240 LOCKS_EXCLUDED(Locks::breakpoint_lock_, Locks::deoptimization_lock_, Locks::mutator_lock_);
241 static void Disconnected() LOCKS_EXCLUDED(Locks::deoptimization_lock_, Locks::mutator_lock_);
Sebastien Hertz4e5b2082015-03-24 19:03:40 +0100242 static void Dispose() {
243 gDisposed = true;
244 }
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700245
Elliott Hughesc0f09332012-03-26 13:27:06 -0700246 // Returns true if we're actually debugging with a real debugger, false if it's
247 // just DDMS (or nothing at all).
Daniel Mihalyieb076692014-08-22 17:33:31 +0200248 static bool IsDebuggerActive() {
249 return gDebuggerActive;
250 }
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700251
Sebastien Hertzb3b173b2015-02-06 09:16:32 +0100252 // Configures JDWP with parsed command-line options.
253 static void ConfigureJdwp(const JDWP::JdwpOptions& jdwp_options);
254
Elliott Hughesc0f09332012-03-26 13:27:06 -0700255 // Returns true if we had -Xrunjdwp or -agentlib:jdwp= on the command line.
256 static bool IsJdwpConfigured();
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700257
Mathieu Chartierd8565452015-03-26 09:41:50 -0700258 // Returns true if a method has any breakpoints.
259 static bool MethodHasAnyBreakpoints(mirror::ArtMethod* method)
Sebastien Hertz4e5b2082015-03-24 19:03:40 +0100260 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_)
261 LOCKS_EXCLUDED(Locks::breakpoint_lock_);
Mathieu Chartierd8565452015-03-26 09:41:50 -0700262
Sebastien Hertz4e5b2082015-03-24 19:03:40 +0100263 static bool IsDisposed() {
264 return gDisposed;
265 }
Elliott Hughes86964332012-02-15 19:37:42 -0800266
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700267 /*
268 * Time, in milliseconds, since the last debugger activity. Does not
269 * include DDMS activity. Returns -1 if there has been no activity.
270 * Returns 0 if we're in the middle of handling a debugger request.
271 */
272 static int64_t LastDebuggerActivity();
273
Sebastien Hertz253fa552014-10-14 17:27:15 +0200274 static void UndoDebuggerSuspensions()
275 LOCKS_EXCLUDED(Locks::thread_list_lock_,
276 Locks::thread_suspend_count_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700277
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700278 /*
279 * Class, Object, Array
280 */
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700281 static std::string GetClassName(JDWP::RefTypeId id)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700282 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertz6995c602014-09-09 12:10:13 +0200283 static std::string GetClassName(mirror::Class* klass)
284 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersc0542af2014-09-03 16:16:56 -0700285 static JDWP::JdwpError GetClassObject(JDWP::RefTypeId id, JDWP::ObjectId* class_object_id)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700286 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersc0542af2014-09-03 16:16:56 -0700287 static JDWP::JdwpError GetSuperclass(JDWP::RefTypeId id, JDWP::RefTypeId* superclass_id)
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 GetClassLoader(JDWP::RefTypeId id, JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700290 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700291 static JDWP::JdwpError GetModifiers(JDWP::RefTypeId id, JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700292 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800293 static JDWP::JdwpError GetReflectedType(JDWP::RefTypeId class_id, JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700294 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersc0542af2014-09-03 16:16:56 -0700295 static void GetClassList(std::vector<JDWP::RefTypeId>* classes)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700296 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800297 static JDWP::JdwpError GetClassInfo(JDWP::RefTypeId class_id, JDWP::JdwpTypeTag* pTypeTag,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700298 uint32_t* pStatus, std::string* pDescriptor)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700299 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersc0542af2014-09-03 16:16:56 -0700300 static void FindLoadedClassBySignature(const char* descriptor, std::vector<JDWP::RefTypeId>* ids)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700301 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes64f574f2013-02-20 14:57:12 -0800302 static JDWP::JdwpError GetReferenceType(JDWP::ObjectId object_id, JDWP::ExpandBuf* pReply)
303 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersfc0e94b2013-09-23 23:51:32 -0700304 static JDWP::JdwpError GetSignature(JDWP::RefTypeId ref_type_id, std::string* signature)
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 GetSourceFile(JDWP::RefTypeId ref_type_id, std::string* source_file)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700307 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersc0542af2014-09-03 16:16:56 -0700308 static JDWP::JdwpError GetObjectTag(JDWP::ObjectId object_id, uint8_t* tag)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700309 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughesaed4be92011-12-02 16:16:23 -0800310 static size_t GetTagWidth(JDWP::JdwpTag tag);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700311
Ian Rogersc0542af2014-09-03 16:16:56 -0700312 static JDWP::JdwpError GetArrayLength(JDWP::ObjectId array_id, int32_t* length)
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 OutputArray(JDWP::ObjectId array_id, int offset, int count,
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 SetArrayElements(JDWP::ObjectId array_id, int offset, int count,
Ian Rogersc0542af2014-09-03 16:16:56 -0700318 JDWP::Request* request)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700319 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700320
Sebastien Hertz2c3e77a2015-04-02 16:26:48 +0200321 static JDWP::JdwpError CreateString(const std::string& str, JDWP::ObjectId* new_string_id)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700322 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertz2c3e77a2015-04-02 16:26:48 +0200323 static JDWP::JdwpError CreateObject(JDWP::RefTypeId class_id, JDWP::ObjectId* new_object_id)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700324 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800325 static JDWP::JdwpError CreateArrayObject(JDWP::RefTypeId array_class_id, uint32_t length,
Sebastien Hertz2c3e77a2015-04-02 16:26:48 +0200326 JDWP::ObjectId* new_array_id)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700327 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700328
Sebastien Hertz6995c602014-09-09 12:10:13 +0200329 //
330 // Event filtering.
331 //
332 static bool MatchThread(JDWP::ObjectId expected_thread_id, Thread* event_thread)
333 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
334
335 static bool MatchLocation(const JDWP::JdwpLocation& expected_location,
336 const JDWP::EventLocation& event_location)
337 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
338
339 static bool MatchType(mirror::Class* event_class, JDWP::RefTypeId class_id)
340 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
341
342 static bool MatchField(JDWP::RefTypeId expected_type_id, JDWP::FieldId expected_field_id,
Mathieu Chartierc7853442015-03-27 14:35:38 -0700343 ArtField* event_field)
Sebastien Hertz6995c602014-09-09 12:10:13 +0200344 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
345
346 static bool MatchInstance(JDWP::ObjectId expected_instance_id, mirror::Object* event_instance)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700347 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700348
Elliott Hughesec0f83d2013-01-15 16:54:08 -0800349 //
350 // Monitors.
351 //
352 static JDWP::JdwpError GetMonitorInfo(JDWP::ObjectId object_id, JDWP::ExpandBuf* reply)
353 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
354 static JDWP::JdwpError GetOwnedMonitors(JDWP::ObjectId thread_id,
Ian Rogersc0542af2014-09-03 16:16:56 -0700355 std::vector<JDWP::ObjectId>* monitors,
356 std::vector<uint32_t>* stack_depths)
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100357 LOCKS_EXCLUDED(Locks::thread_list_lock_)
Elliott Hughesec0f83d2013-01-15 16:54:08 -0800358 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100359 static JDWP::JdwpError GetContendedMonitor(JDWP::ObjectId thread_id,
Ian Rogersc0542af2014-09-03 16:16:56 -0700360 JDWP::ObjectId* contended_monitor)
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100361 LOCKS_EXCLUDED(Locks::thread_list_lock_)
Elliott Hughesec0f83d2013-01-15 16:54:08 -0800362 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
363
364 //
365 // Heap.
366 //
367 static JDWP::JdwpError GetInstanceCounts(const std::vector<JDWP::RefTypeId>& class_ids,
Ian Rogersc0542af2014-09-03 16:16:56 -0700368 std::vector<uint64_t>* counts)
Elliott Hughesec0f83d2013-01-15 16:54:08 -0800369 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes3b78c942013-01-15 17:35:41 -0800370 static JDWP::JdwpError GetInstances(JDWP::RefTypeId class_id, int32_t max_count,
Ian Rogersc0542af2014-09-03 16:16:56 -0700371 std::vector<JDWP::ObjectId>* instances)
Elliott Hughes3b78c942013-01-15 17:35:41 -0800372 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes0cbaff52013-01-16 15:28:01 -0800373 static JDWP::JdwpError GetReferringObjects(JDWP::ObjectId object_id, int32_t max_count,
Ian Rogersc0542af2014-09-03 16:16:56 -0700374 std::vector<JDWP::ObjectId>* referring_objects)
Elliott Hughes0cbaff52013-01-16 15:28:01 -0800375 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes64f574f2013-02-20 14:57:12 -0800376 static JDWP::JdwpError DisableCollection(JDWP::ObjectId object_id)
377 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
378 static JDWP::JdwpError EnableCollection(JDWP::ObjectId object_id)
379 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersc0542af2014-09-03 16:16:56 -0700380 static JDWP::JdwpError IsCollected(JDWP::ObjectId object_id, bool* is_collected)
Elliott Hughes64f574f2013-02-20 14:57:12 -0800381 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
382 static void DisposeObject(JDWP::ObjectId object_id, uint32_t reference_count)
383 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughesec0f83d2013-01-15 16:54:08 -0800384
Elliott Hughes9777ba22013-01-17 09:04:19 -0800385 //
386 // Methods and fields.
387 //
Elliott Hughesa96836a2013-01-17 12:27:49 -0800388 static std::string GetMethodName(JDWP::MethodId method_id)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700389 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800390 static JDWP::JdwpError OutputDeclaredFields(JDWP::RefTypeId ref_type_id, bool with_generic,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700391 JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700392 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800393 static JDWP::JdwpError OutputDeclaredMethods(JDWP::RefTypeId ref_type_id, bool with_generic,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700394 JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700395 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800396 static JDWP::JdwpError OutputDeclaredInterfaces(JDWP::RefTypeId ref_type_id,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700397 JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700398 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800399 static void OutputLineTable(JDWP::RefTypeId ref_type_id, JDWP::MethodId method_id,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700400 JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700401 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800402 static void OutputVariableTable(JDWP::RefTypeId ref_type_id, JDWP::MethodId id, bool with_generic,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700403 JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700404 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Jeff Hao579b0242013-11-18 13:16:49 -0800405 static void OutputMethodReturnValue(JDWP::MethodId method_id, const JValue* return_value,
406 JDWP::ExpandBuf* pReply)
407 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertz3f52eaf2014-04-04 17:50:18 +0200408 static void OutputFieldValue(JDWP::FieldId field_id, const JValue* field_value,
409 JDWP::ExpandBuf* pReply)
410 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes9777ba22013-01-17 09:04:19 -0800411 static JDWP::JdwpError GetBytecodes(JDWP::RefTypeId class_id, JDWP::MethodId method_id,
Ian Rogersc0542af2014-09-03 16:16:56 -0700412 std::vector<uint8_t>* bytecodes)
Elliott Hughes9777ba22013-01-17 09:04:19 -0800413 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700414
Elliott Hughesa96836a2013-01-17 12:27:49 -0800415 static std::string GetFieldName(JDWP::FieldId field_id)
416 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800417 static JDWP::JdwpTag GetFieldBasicTag(JDWP::FieldId field_id)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700418 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800419 static JDWP::JdwpTag GetStaticFieldBasicTag(JDWP::FieldId field_id)
Brian Carlstromf69863b2013-07-17 21:53:13 -0700420 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800421 static JDWP::JdwpError GetFieldValue(JDWP::ObjectId object_id, JDWP::FieldId field_id,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700422 JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700423 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800424 static JDWP::JdwpError SetFieldValue(JDWP::ObjectId object_id, JDWP::FieldId field_id,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700425 uint64_t value, int width)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700426 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800427 static JDWP::JdwpError GetStaticFieldValue(JDWP::RefTypeId ref_type_id, JDWP::FieldId field_id,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700428 JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700429 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800430 static JDWP::JdwpError SetStaticFieldValue(JDWP::FieldId field_id, uint64_t value, int width)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700431 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700432
Sebastien Hertzb0b0b492014-09-15 11:27:27 +0200433 static JDWP::JdwpError StringToUtf8(JDWP::ObjectId string_id, std::string* str)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700434 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Jeff Hao579b0242013-11-18 13:16:49 -0800435 static void OutputJValue(JDWP::JdwpTag tag, const JValue* return_value, JDWP::ExpandBuf* pReply)
436 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700437
438 /*
439 * Thread, ThreadGroup, Frame
440 */
Ian Rogersc0542af2014-09-03 16:16:56 -0700441 static JDWP::JdwpError GetThreadName(JDWP::ObjectId thread_id, std::string* name)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700442 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_)
443 LOCKS_EXCLUDED(Locks::thread_list_lock_);
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100444 static JDWP::JdwpError GetThreadGroup(JDWP::ObjectId thread_id, JDWP::ExpandBuf* pReply)
Sebastien Hertza06430c2014-09-15 19:21:30 +0200445 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_)
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100446 LOCKS_EXCLUDED(Locks::thread_list_lock_);
Sebastien Hertza06430c2014-09-15 19:21:30 +0200447 static JDWP::JdwpError GetThreadGroupName(JDWP::ObjectId thread_group_id,
448 JDWP::ExpandBuf* pReply)
449 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
450 static JDWP::JdwpError GetThreadGroupParent(JDWP::ObjectId thread_group_id,
451 JDWP::ExpandBuf* pReply)
452 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
453 static JDWP::JdwpError GetThreadGroupChildren(JDWP::ObjectId thread_group_id,
454 JDWP::ExpandBuf* pReply)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700455 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700456 static JDWP::ObjectId GetSystemThreadGroupId()
Ian Rogersb726dcb2012-09-05 08:57:23 -0700457 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700458
Jeff Hao920af3e2013-08-28 15:46:38 -0700459 static JDWP::JdwpThreadStatus ToJdwpThreadStatus(ThreadState state);
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100460 static JDWP::JdwpError GetThreadStatus(JDWP::ObjectId thread_id,
461 JDWP::JdwpThreadStatus* pThreadStatus,
462 JDWP::JdwpSuspendStatus* pSuspendStatus)
463 LOCKS_EXCLUDED(Locks::thread_list_lock_);
464 static JDWP::JdwpError GetThreadDebugSuspendCount(JDWP::ObjectId thread_id,
465 JDWP::ExpandBuf* pReply)
466 LOCKS_EXCLUDED(Locks::thread_list_lock_,
467 Locks::thread_suspend_count_lock_);
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700468 // static void WaitForSuspend(JDWP::ObjectId thread_id);
Elliott Hughescaf76542012-06-28 16:08:22 -0700469
Elliott Hughes026b1462012-06-28 20:43:49 -0700470 // Fills 'thread_ids' with the threads in the given thread group. If thread_group_id == 0,
Elliott Hughescaf76542012-06-28 16:08:22 -0700471 // returns all threads.
Sebastien Hertza06430c2014-09-15 19:21:30 +0200472 static void GetThreads(mirror::Object* thread_group, std::vector<JDWP::ObjectId>* thread_ids)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700473 LOCKS_EXCLUDED(Locks::thread_list_lock_)
474 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughescaf76542012-06-28 16:08:22 -0700475
Ian Rogersc0542af2014-09-03 16:16:56 -0700476 static JDWP::JdwpError GetThreadFrameCount(JDWP::ObjectId thread_id, size_t* result)
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100477 LOCKS_EXCLUDED(Locks::thread_list_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700478 static JDWP::JdwpError GetThreadFrames(JDWP::ObjectId thread_id, size_t start_frame,
479 size_t frame_count, JDWP::ExpandBuf* buf)
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100480 LOCKS_EXCLUDED(Locks::thread_list_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700481 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700482
Sebastien Hertz6995c602014-09-09 12:10:13 +0200483 static JDWP::ObjectId GetThreadSelfId() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
484 static JDWP::ObjectId GetThreadId(Thread* thread) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
485
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700486 static void SuspendVM()
Ian Rogersb726dcb2012-09-05 08:57:23 -0700487 LOCKS_EXCLUDED(Locks::thread_list_lock_,
488 Locks::thread_suspend_count_lock_);
Sebastien Hertz253fa552014-10-14 17:27:15 +0200489 static void ResumeVM()
490 LOCKS_EXCLUDED(Locks::thread_list_lock_,
491 Locks::thread_suspend_count_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800492 static JDWP::JdwpError SuspendThread(JDWP::ObjectId thread_id, bool request_suspension = true)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700493 LOCKS_EXCLUDED(Locks::mutator_lock_,
494 Locks::thread_list_lock_,
495 Locks::thread_suspend_count_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700496
Elliott Hughes88d63092013-01-09 09:55:54 -0800497 static void ResumeThread(JDWP::ObjectId thread_id)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700498 LOCKS_EXCLUDED(Locks::thread_list_lock_,
499 Locks::thread_suspend_count_lock_)
500 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700501 static void SuspendSelf();
502
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700503 static JDWP::JdwpError GetThisObject(JDWP::ObjectId thread_id, JDWP::FrameId frame_id,
504 JDWP::ObjectId* result)
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_);
Sebastien Hertz8009f392014-09-01 17:07:11 +0200508 static JDWP::JdwpError GetLocalValues(JDWP::Request* request, JDWP::ExpandBuf* pReply)
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100509 LOCKS_EXCLUDED(Locks::thread_list_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700510 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertz8009f392014-09-01 17:07:11 +0200511 static JDWP::JdwpError SetLocalValues(JDWP::Request* request)
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100512 LOCKS_EXCLUDED(Locks::thread_list_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700513 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700514
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100515 static JDWP::JdwpError Interrupt(JDWP::ObjectId thread_id)
516 LOCKS_EXCLUDED(Locks::thread_list_lock_);
Elliott Hughesf9501702013-01-11 11:22:27 -0800517
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700518 /*
519 * Debugger notification
520 */
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700521 enum EventFlag {
Elliott Hughes86964332012-02-15 19:37:42 -0800522 kBreakpoint = 0x01,
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700523 kSingleStep = 0x02,
524 kMethodEntry = 0x04,
525 kMethodExit = 0x08,
526 };
Sebastien Hertz3f52eaf2014-04-04 17:50:18 +0200527 static void PostFieldAccessEvent(mirror::ArtMethod* m, int dex_pc, mirror::Object* this_object,
Mathieu Chartierc7853442015-03-27 14:35:38 -0700528 ArtField* f)
Sebastien Hertz3f52eaf2014-04-04 17:50:18 +0200529 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
530 static void PostFieldModificationEvent(mirror::ArtMethod* m, int dex_pc,
Mathieu Chartierc7853442015-03-27 14:35:38 -0700531 mirror::Object* this_object, ArtField* f,
Sebastien Hertz3f52eaf2014-04-04 17:50:18 +0200532 const JValue* field_value)
533 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Nicolas Geoffray14691c52015-03-05 10:40:17 +0000534 static void PostException(mirror::Throwable* exception)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700535 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700536 static void PostThreadStart(Thread* t)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700537 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700538 static void PostThreadDeath(Thread* t)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700539 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800540 static void PostClassPrepare(mirror::Class* c)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700541 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700542
Ian Rogers62d6c772013-02-27 08:32:07 -0800543 static void UpdateDebugger(Thread* thread, mirror::Object* this_object,
Sebastien Hertz8379b222014-02-24 17:38:15 +0100544 mirror::ArtMethod* method, uint32_t new_dex_pc,
545 int event_flags, const JValue* return_value)
jeffhao09bfc6a2012-12-11 18:11:43 -0800546 LOCKS_EXCLUDED(Locks::breakpoint_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700547 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes91bf6cd2012-02-14 17:27:48 -0800548
Sebastien Hertzf3928792014-11-17 19:00:37 +0100549 // Indicates whether we need deoptimization for debugging.
550 static bool RequiresDeoptimization();
551
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100552 // Records deoptimization request in the queue.
553 static void RequestDeoptimization(const DeoptimizationRequest& req)
Brian Carlstrom306db812014-09-05 13:01:41 -0700554 LOCKS_EXCLUDED(Locks::deoptimization_lock_)
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100555 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
556
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100557 // Manage deoptimization after updating JDWP events list. Suspends all threads, processes each
558 // request and finally resumes all threads.
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100559 static void ManageDeoptimization()
Brian Carlstrom306db812014-09-05 13:01:41 -0700560 LOCKS_EXCLUDED(Locks::deoptimization_lock_)
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100561 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
562
563 // Breakpoints.
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100564 static void WatchLocation(const JDWP::JdwpLocation* pLoc, DeoptimizationRequest* req)
565 LOCKS_EXCLUDED(Locks::breakpoint_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700566 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100567 static void UnwatchLocation(const JDWP::JdwpLocation* pLoc, DeoptimizationRequest* req)
568 LOCKS_EXCLUDED(Locks::breakpoint_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700569 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100570
Daniel Mihalyieb076692014-08-22 17:33:31 +0200571 /*
572 * Forced interpreter checkers for single-step and continue support.
573 */
574
575 // Indicates whether we need to force the use of interpreter to invoke a method.
576 // This allows to single-step or continue into the called method.
577 static bool IsForcedInterpreterNeededForCalling(Thread* thread, mirror::ArtMethod* m)
578 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
579 if (!IsDebuggerActive()) {
580 return false;
581 }
582 return IsForcedInterpreterNeededForCallingImpl(thread, m);
583 }
584
585 // Indicates whether we need to force the use of interpreter entrypoint when calling a
586 // method through the resolution trampoline. This allows to single-step or continue into
587 // the called method.
588 static bool IsForcedInterpreterNeededForResolution(Thread* thread, mirror::ArtMethod* m)
589 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
590 if (!IsDebuggerActive()) {
591 return false;
592 }
593 return IsForcedInterpreterNeededForResolutionImpl(thread, m);
594 }
595
596 // Indicates whether we need to force the use of instrumentation entrypoint when calling
597 // a method through the resolution trampoline. This allows to deoptimize the stack for
598 // debugging when we returned from the called method.
599 static bool IsForcedInstrumentationNeededForResolution(Thread* thread, mirror::ArtMethod* m)
600 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
601 if (!IsDebuggerActive()) {
602 return false;
603 }
604 return IsForcedInstrumentationNeededForResolutionImpl(thread, m);
605 }
606
607 // Indicates whether we need to force the use of interpreter when returning from the
608 // interpreter into the runtime. This allows to deoptimize the stack and continue
609 // execution with interpreter for debugging.
610 static bool IsForcedInterpreterNeededForUpcall(Thread* thread, mirror::ArtMethod* m)
611 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
612 if (!IsDebuggerActive()) {
613 return false;
614 }
615 return IsForcedInterpreterNeededForUpcallImpl(thread, m);
616 }
617
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100618 // Single-stepping.
Elliott Hughes88d63092013-01-09 09:55:54 -0800619 static JDWP::JdwpError ConfigureStep(JDWP::ObjectId thread_id, JDWP::JdwpStepSize size,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700620 JDWP::JdwpStepDepth depth)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700621 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +0100622 static void UnconfigureStep(JDWP::ObjectId thread_id)
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100623 LOCKS_EXCLUDED(Locks::thread_list_lock_)
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +0100624 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700625
Sebastien Hertz1558b572015-02-25 15:05:59 +0100626 // Invoke support for commands ClassType.InvokeMethod, ClassType.NewInstance and
627 // ObjectReference.InvokeMethod.
Elliott Hughes88d63092013-01-09 09:55:54 -0800628 static JDWP::JdwpError InvokeMethod(JDWP::ObjectId thread_id, JDWP::ObjectId object_id,
629 JDWP::RefTypeId class_id, JDWP::MethodId method_id,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700630 uint32_t arg_count, uint64_t* arg_values,
631 JDWP::JdwpTag* arg_types, uint32_t options,
632 JDWP::JdwpTag* pResultTag, uint64_t* pResultValue,
633 JDWP::ObjectId* pExceptObj)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700634 LOCKS_EXCLUDED(Locks::thread_list_lock_,
635 Locks::thread_suspend_count_lock_)
636 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700637 static void ExecuteMethod(DebugInvokeReq* pReq);
638
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700639 /*
640 * DDM support.
641 */
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700642 static void DdmSendThreadNotification(Thread* t, uint32_t type)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700643 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100644 static void DdmSetThreadNotification(bool enable)
645 LOCKS_EXCLUDED(Locks::thread_list_lock_);
Ian Rogersc0542af2014-09-03 16:16:56 -0700646 static bool DdmHandlePacket(JDWP::Request* request, uint8_t** pReplyBuf, int* pReplyLen);
Ian Rogersb726dcb2012-09-05 08:57:23 -0700647 static void DdmConnected() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
648 static void DdmDisconnected() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700649 static void DdmSendChunk(uint32_t type, const std::vector<uint8_t>& bytes)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700650 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700651 static void DdmSendChunk(uint32_t type, size_t len, const uint8_t* buf)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700652 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700653 static void DdmSendChunkV(uint32_t type, const iovec* iov, int iov_count)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700654 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes767a1472011-10-26 18:49:02 -0700655
Mathieu Chartierbb87e0f2015-04-03 11:21:55 -0700656 static void VisitRoots(RootVisitor* visitor)
Mathieu Chartier3b05e9b2014-03-25 09:29:43 -0700657 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
658
Elliott Hughes545a0642011-11-08 19:10:03 -0800659 /*
660 * Recent allocation tracking support.
661 */
Ian Rogers844506b2014-09-12 19:59:33 -0700662 static void RecordAllocation(Thread* self, mirror::Class* type, size_t byte_count)
Brian Carlstrom306db812014-09-05 13:01:41 -0700663 LOCKS_EXCLUDED(Locks::alloc_tracker_lock_)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700664 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom306db812014-09-05 13:01:41 -0700665 static void SetAllocTrackingEnabled(bool enabled) LOCKS_EXCLUDED(Locks::alloc_tracker_lock_);
Ian Rogers719d1a32014-03-06 12:13:39 -0800666 static bool IsAllocTrackingEnabled() {
667 return recent_allocation_records_ != nullptr;
668 }
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100669 static jbyteArray GetRecentAllocations()
Brian Carlstrom306db812014-09-05 13:01:41 -0700670 LOCKS_EXCLUDED(Locks::alloc_tracker_lock_)
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100671 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Brian Carlstrom306db812014-09-05 13:01:41 -0700672 static size_t HeadIndex() EXCLUSIVE_LOCKS_REQUIRED(Locks::alloc_tracker_lock_);
673 static void DumpRecentAllocations() LOCKS_EXCLUDED(Locks::alloc_tracker_lock_);
Elliott Hughes545a0642011-11-08 19:10:03 -0800674
Elliott Hughes767a1472011-10-26 18:49:02 -0700675 enum HpifWhen {
676 HPIF_WHEN_NEVER = 0,
677 HPIF_WHEN_NOW = 1,
678 HPIF_WHEN_NEXT_GC = 2,
679 HPIF_WHEN_EVERY_GC = 3
680 };
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700681 static int DdmHandleHpifChunk(HpifWhen when)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700682 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes767a1472011-10-26 18:49:02 -0700683
684 enum HpsgWhen {
685 HPSG_WHEN_NEVER = 0,
686 HPSG_WHEN_EVERY_GC = 1,
687 };
688 enum HpsgWhat {
689 HPSG_WHAT_MERGED_OBJECTS = 0,
690 HPSG_WHAT_DISTINCT_OBJECTS = 1,
691 };
692 static bool DdmHandleHpsgNhsgChunk(HpsgWhen when, HpsgWhat what, bool native);
693
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700694 static void DdmSendHeapInfo(HpifWhen reason)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700695 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700696 static void DdmSendHeapSegments(bool native)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700697 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughes545a0642011-11-08 19:10:03 -0800698
Sebastien Hertz6995c602014-09-09 12:10:13 +0200699 static ObjectRegistry* GetObjectRegistry() {
700 return gRegistry;
701 }
702
703 static JDWP::JdwpTag TagFromObject(const ScopedObjectAccessUnchecked& soa, mirror::Object* o)
704 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
705
706 static JDWP::JdwpTypeTag GetTypeTag(mirror::Class* klass)
707 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
708
Mathieu Chartierc7853442015-03-27 14:35:38 -0700709 static JDWP::FieldId ToFieldId(const ArtField* f)
Sebastien Hertz6995c602014-09-09 12:10:13 +0200710 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
711
712 static void SetJdwpLocation(JDWP::JdwpLocation* location, mirror::ArtMethod* m, uint32_t dex_pc)
713 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
714
Mathieu Chartierad466ad2015-01-08 16:28:08 -0800715 static JDWP::JdwpState* GetJdwpState();
716
Elliott Hughes545a0642011-11-08 19:10:03 -0800717 private:
Sebastien Hertz8009f392014-09-01 17:07:11 +0200718 static JDWP::JdwpError GetLocalValue(const StackVisitor& visitor,
719 ScopedObjectAccessUnchecked& soa, int slot,
720 JDWP::JdwpTag tag, uint8_t* buf, size_t width)
721 LOCKS_EXCLUDED(Locks::thread_list_lock_)
722 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
723 static JDWP::JdwpError SetLocalValue(StackVisitor& visitor, int slot, JDWP::JdwpTag tag,
724 uint64_t value, size_t width)
725 LOCKS_EXCLUDED(Locks::thread_list_lock_)
726 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
727
Brian Carlstrom2d888622013-07-18 17:02:00 -0700728 static void DdmBroadcast(bool connect) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700729 static void PostThreadStartOrStop(Thread*, uint32_t)
Ian Rogersb726dcb2012-09-05 08:57:23 -0700730 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Elliott Hughesa2155262011-11-16 16:26:58 -0800731
Sebastien Hertz8379b222014-02-24 17:38:15 +0100732 static void PostLocationEvent(mirror::ArtMethod* method, int pcOffset,
733 mirror::Object* thisPtr, int eventFlags,
734 const JValue* return_value)
735 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
736
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100737 static void ProcessDeoptimizationRequest(const DeoptimizationRequest& request)
738 EXCLUSIVE_LOCKS_REQUIRED(Locks::mutator_lock_);
739
Sebastien Hertz7ec2f1c2014-03-27 20:06:47 +0100740 static void RequestDeoptimizationLocked(const DeoptimizationRequest& req)
Brian Carlstrom306db812014-09-05 13:01:41 -0700741 EXCLUSIVE_LOCKS_REQUIRED(Locks::deoptimization_lock_)
Sebastien Hertz7ec2f1c2014-03-27 20:06:47 +0100742 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
743
Daniel Mihalyieb076692014-08-22 17:33:31 +0200744 static bool IsForcedInterpreterNeededForCallingImpl(Thread* thread, mirror::ArtMethod* m)
745 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
746
747 static bool IsForcedInterpreterNeededForResolutionImpl(Thread* thread, mirror::ArtMethod* m)
748 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
749
750 static bool IsForcedInstrumentationNeededForResolutionImpl(Thread* thread, mirror::ArtMethod* m)
751 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
752
753 static bool IsForcedInterpreterNeededForUpcallImpl(Thread* thread, mirror::ArtMethod* m)
754 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
755
Brian Carlstrom306db812014-09-05 13:01:41 -0700756 static AllocRecord* recent_allocation_records_ PT_GUARDED_BY(Locks::alloc_tracker_lock_);
757 static size_t alloc_record_max_ GUARDED_BY(Locks::alloc_tracker_lock_);
758 static size_t alloc_record_head_ GUARDED_BY(Locks::alloc_tracker_lock_);
759 static size_t alloc_record_count_ GUARDED_BY(Locks::alloc_tracker_lock_);
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100760
Daniel Mihalyieb076692014-08-22 17:33:31 +0200761 // Indicates whether the debugger is making requests.
762 static bool gDebuggerActive;
763
Sebastien Hertz4e5b2082015-03-24 19:03:40 +0100764 // Indicates whether we should drop the JDWP connection because the runtime stops or the
765 // debugger called VirtualMachine.Dispose.
766 static bool gDisposed;
767
Daniel Mihalyieb076692014-08-22 17:33:31 +0200768 // The registry mapping objects to JDWP ids.
Sebastien Hertz6995c602014-09-09 12:10:13 +0200769 static ObjectRegistry* gRegistry;
770
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100771 // Deoptimization requests to be processed each time the event list is updated. This is used when
772 // registering and unregistering events so we do not deoptimize while holding the event list
773 // lock.
Sebastien Hertz42cd43f2014-05-13 14:15:41 +0200774 // TODO rename to instrumentation_requests.
Brian Carlstrom306db812014-09-05 13:01:41 -0700775 static std::vector<DeoptimizationRequest> deoptimization_requests_ GUARDED_BY(Locks::deoptimization_lock_);
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100776
777 // Count the number of events requiring full deoptimization. When the counter is > 0, everything
778 // is deoptimized, otherwise everything is undeoptimized.
779 // Note: we fully deoptimize on the first event only (when the counter is set to 1). We fully
780 // undeoptimize when the last event is unregistered (when the counter is set to 0).
Brian Carlstrom306db812014-09-05 13:01:41 -0700781 static size_t full_deoptimization_event_count_ GUARDED_BY(Locks::deoptimization_lock_);
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100782
Sebastien Hertz42cd43f2014-05-13 14:15:41 +0200783 static size_t* GetReferenceCounterForEvent(uint32_t instrumentation_event);
784
Mathieu Chartier4345c462014-06-27 10:20:14 -0700785 // Weak global type cache, TODO improve this.
Brian Carlstrom306db812014-09-05 13:01:41 -0700786 static TypeCache type_cache_ GUARDED_BY(Locks::alloc_tracker_lock_);
Mathieu Chartier4345c462014-06-27 10:20:14 -0700787
Sebastien Hertz42cd43f2014-05-13 14:15:41 +0200788 // Instrumentation event reference counters.
789 // TODO we could use an array instead of having all these dedicated counters. Instrumentation
790 // events are bits of a mask so we could convert them to array index.
Brian Carlstrom306db812014-09-05 13:01:41 -0700791 static size_t dex_pc_change_event_ref_count_ GUARDED_BY(Locks::deoptimization_lock_);
792 static size_t method_enter_event_ref_count_ GUARDED_BY(Locks::deoptimization_lock_);
793 static size_t method_exit_event_ref_count_ GUARDED_BY(Locks::deoptimization_lock_);
794 static size_t field_read_event_ref_count_ GUARDED_BY(Locks::deoptimization_lock_);
795 static size_t field_write_event_ref_count_ GUARDED_BY(Locks::deoptimization_lock_);
796 static size_t exception_catch_event_ref_count_ GUARDED_BY(Locks::deoptimization_lock_);
Sebastien Hertz42cd43f2014-05-13 14:15:41 +0200797 static uint32_t instrumentation_events_ GUARDED_BY(Locks::mutator_lock_);
798
Brian Carlstrom306db812014-09-05 13:01:41 -0700799 friend class AllocRecord; // For type_cache_ with proper annotalysis.
Ian Rogers719d1a32014-03-06 12:13:39 -0800800 DISALLOW_COPY_AND_ASSIGN(Dbg);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700801};
802
803#define CHUNK_TYPE(_name) \
Elliott Hughes82188472011-11-07 18:11:48 -0800804 static_cast<uint32_t>((_name)[0] << 24 | (_name)[1] << 16 | (_name)[2] << 8 | (_name)[3])
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700805
806} // namespace art
807
Brian Carlstromfc0e3212013-07-17 14:40:12 -0700808#endif // ART_RUNTIME_DEBUGGER_H_