blob: ec37833f6d4465086afae1380ca1cbf15d1cdda7 [file] [log] [blame]
Elliott Hughes872d4ec2011-10-21 17:07:15 -07001/*
2 * Copyright (C) 2008 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17/*
18 * Dalvik-specific side of debugger support. (The JDWP code is intended to
19 * be relatively generic.)
20 */
Brian Carlstromfc0e3212013-07-17 14:40:12 -070021#ifndef ART_RUNTIME_DEBUGGER_H_
22#define ART_RUNTIME_DEBUGGER_H_
Elliott Hughes872d4ec2011-10-21 17:07:15 -070023
24#include <pthread.h>
25
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +010026#include <set>
Elliott Hughes3bb81562011-10-21 18:52:59 -070027#include <string>
Sebastien Hertz4d25df32014-03-21 17:44:46 +010028#include <vector>
Elliott Hughes3bb81562011-10-21 18:52:59 -070029
Andreas Gampe0f01b582017-01-18 15:22:37 -080030#include "class_linker.h"
Andreas Gampe8cf9cb32017-07-19 09:28:38 -070031#include "gc_root.h"
Andreas Gampe0f01b582017-01-18 15:22:37 -080032#include "handle.h"
Elliott Hughes872d4ec2011-10-21 17:07:15 -070033#include "jdwp/jdwp.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080034#include "jni.h"
35#include "jvalue.h"
Mathieu Chartier3398c782016-09-30 10:27:43 -070036#include "obj_ptr.h"
Alex Light21611932017-09-26 13:07:39 -070037#include "runtime_callbacks.h"
Mingyao Yang99170c62015-07-06 11:10:37 -070038#include "thread.h"
Jeff Hao920af3e2013-08-28 15:46:38 -070039#include "thread_state.h"
Elliott Hughes872d4ec2011-10-21 17:07:15 -070040
41namespace art {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080042namespace mirror {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080043class Class;
44class Object;
45class Throwable;
46} // namespace mirror
Mathieu Chartierc7853442015-03-27 14:35:38 -070047class ArtField;
Mathieu Chartiere401d142015-04-22 13:56:20 -070048class ArtMethod;
Sebastien Hertz6995c602014-09-09 12:10:13 +020049class ObjectRegistry;
Sebastien Hertzcbc50642015-06-01 17:33:12 +020050class ScopedObjectAccess;
Sebastien Hertz6995c602014-09-09 12:10:13 +020051class ScopedObjectAccessUnchecked;
Sebastien Hertz8009f392014-09-01 17:07:11 +020052class StackVisitor;
Ian Rogers1b09b092012-08-20 15:35:52 -070053class Thread;
Elliott Hughes872d4ec2011-10-21 17:07:15 -070054
Alex Light21611932017-09-26 13:07:39 -070055struct DebuggerActiveMethodInspectionCallback : public MethodInspectionCallback {
56 bool IsMethodBeingInspected(ArtMethod* m ATTRIBUTE_UNUSED)
57 OVERRIDE REQUIRES_SHARED(Locks::mutator_lock_);
Alex Light0fa17862017-10-24 13:43:05 -070058 bool IsMethodSafeToJit(ArtMethod* m) OVERRIDE REQUIRES_SHARED(Locks::mutator_lock_);
Alex Light21611932017-09-26 13:07:39 -070059};
60
61
Elliott Hughes872d4ec2011-10-21 17:07:15 -070062/*
63 * Invoke-during-breakpoint support.
64 */
65struct DebugInvokeReq {
Sebastien Hertzcbc50642015-06-01 17:33:12 +020066 DebugInvokeReq(uint32_t invoke_request_id, JDWP::ObjectId invoke_thread_id,
67 mirror::Object* invoke_receiver, mirror::Class* invoke_class,
Mathieu Chartiere401d142015-04-22 13:56:20 -070068 ArtMethod* invoke_method, uint32_t invoke_options,
Sebastien Hertzcbc50642015-06-01 17:33:12 +020069 uint64_t args[], uint32_t args_count)
70 : request_id(invoke_request_id), thread_id(invoke_thread_id), receiver(invoke_receiver),
71 klass(invoke_class), method(invoke_method), arg_count(args_count), arg_values(args),
72 options(invoke_options), reply(JDWP::expandBufAlloc()) {
Elliott Hughes475fc232011-10-25 15:00:35 -070073 }
74
Sebastien Hertzcbc50642015-06-01 17:33:12 +020075 ~DebugInvokeReq() {
76 JDWP::expandBufFree(reply);
77 }
78
79 // Request
80 const uint32_t request_id;
81 const JDWP::ObjectId thread_id;
82 GcRoot<mirror::Object> receiver; // not used for ClassType.InvokeMethod.
Sebastien Hertz1558b572015-02-25 15:05:59 +010083 GcRoot<mirror::Class> klass;
Sebastien Hertzcbc50642015-06-01 17:33:12 +020084 ArtMethod* const method;
Sebastien Hertz1558b572015-02-25 15:05:59 +010085 const uint32_t arg_count;
Sebastien Hertzcbc50642015-06-01 17:33:12 +020086 std::unique_ptr<uint64_t[]> arg_values; // will be null if arg_count_ == 0. We take ownership
87 // of this array so we must delete it upon destruction.
Sebastien Hertz1558b572015-02-25 15:05:59 +010088 const uint32_t options;
Elliott Hughes872d4ec2011-10-21 17:07:15 -070089
Sebastien Hertzcbc50642015-06-01 17:33:12 +020090 // Reply
91 JDWP::ExpandBuf* const reply;
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +010092
Mathieu Chartierbb87e0f2015-04-03 11:21:55 -070093 void VisitRoots(RootVisitor* visitor, const RootInfo& root_info)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070094 REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartier3b05e9b2014-03-25 09:29:43 -070095
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +010096 private:
97 DISALLOW_COPY_AND_ASSIGN(DebugInvokeReq);
98};
99
100// Thread local data-structure that holds fields for controlling single-stepping.
Sebastien Hertz597c4f02015-01-26 17:37:14 +0100101class SingleStepControl {
102 public:
103 SingleStepControl(JDWP::JdwpStepSize step_size, JDWP::JdwpStepDepth step_depth,
Mathieu Chartiere401d142015-04-22 13:56:20 -0700104 int stack_depth, ArtMethod* method)
Sebastien Hertz597c4f02015-01-26 17:37:14 +0100105 : step_size_(step_size), step_depth_(step_depth),
106 stack_depth_(stack_depth), method_(method) {
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +0100107 }
108
Sebastien Hertz597c4f02015-01-26 17:37:14 +0100109 JDWP::JdwpStepSize GetStepSize() const {
110 return step_size_;
111 }
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +0100112
Sebastien Hertz597c4f02015-01-26 17:37:14 +0100113 JDWP::JdwpStepDepth GetStepDepth() const {
114 return step_depth_;
115 }
116
117 int GetStackDepth() const {
118 return stack_depth_;
119 }
120
Mathieu Chartiere401d142015-04-22 13:56:20 -0700121 ArtMethod* GetMethod() const {
122 return method_;
Sebastien Hertz597c4f02015-01-26 17:37:14 +0100123 }
124
125 const std::set<uint32_t>& GetDexPcs() const {
126 return dex_pcs_;
127 }
128
Sebastien Hertz597c4f02015-01-26 17:37:14 +0100129 void AddDexPc(uint32_t dex_pc);
130
131 bool ContainsDexPc(uint32_t dex_pc) const;
132
133 private:
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +0100134 // See JdwpStepSize and JdwpStepDepth for details.
Sebastien Hertz597c4f02015-01-26 17:37:14 +0100135 const JDWP::JdwpStepSize step_size_;
136 const JDWP::JdwpStepDepth step_depth_;
137
138 // The stack depth when this single-step was initiated. This is used to support SD_OVER and SD_OUT
139 // single-step depth.
140 const int stack_depth_;
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +0100141
142 // The location this single-step was initiated from.
143 // A single-step is initiated in a suspended thread. We save here the current method and the
144 // set of DEX pcs associated to the source line number where the suspension occurred.
145 // This is used to support SD_INTO and SD_OVER single-step depths so we detect when a single-step
146 // causes the execution of an instruction in a different method or at a different line number.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700147 ArtMethod* method_;
148
Sebastien Hertz597c4f02015-01-26 17:37:14 +0100149 std::set<uint32_t> dex_pcs_;
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +0100150
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +0100151 DISALLOW_COPY_AND_ASSIGN(SingleStepControl);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700152};
153
Sebastien Hertz42cd43f2014-05-13 14:15:41 +0200154// TODO rename to InstrumentationRequest.
Hiroshi Yamauchi0ec17d22014-07-07 13:07:08 -0700155class DeoptimizationRequest {
156 public:
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100157 enum Kind {
158 kNothing, // no action.
Sebastien Hertz42cd43f2014-05-13 14:15:41 +0200159 kRegisterForEvent, // start listening for instrumentation event.
160 kUnregisterForEvent, // stop listening for instrumentation event.
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100161 kFullDeoptimization, // deoptimize everything.
162 kFullUndeoptimization, // undeoptimize everything.
163 kSelectiveDeoptimization, // deoptimize one method.
164 kSelectiveUndeoptimization // undeoptimize one method.
165 };
166
Hiroshi Yamauchi0ec17d22014-07-07 13:07:08 -0700167 DeoptimizationRequest() : kind_(kNothing), instrumentation_event_(0), method_(nullptr) {}
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100168
Hiroshi Yamauchi0ec17d22014-07-07 13:07:08 -0700169 DeoptimizationRequest(const DeoptimizationRequest& other)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700170 REQUIRES_SHARED(Locks::mutator_lock_)
Hiroshi Yamauchi0ec17d22014-07-07 13:07:08 -0700171 : kind_(other.kind_), instrumentation_event_(other.instrumentation_event_) {
172 // Create a new JNI global reference for the method.
173 SetMethod(other.Method());
174 }
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100175
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700176 ArtMethod* Method() const REQUIRES_SHARED(Locks::mutator_lock_);
Hiroshi Yamauchi0ec17d22014-07-07 13:07:08 -0700177
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700178 void SetMethod(ArtMethod* m) REQUIRES_SHARED(Locks::mutator_lock_);
Hiroshi Yamauchi0ec17d22014-07-07 13:07:08 -0700179
180 // Name 'Kind()' would collide with the above enum name.
181 Kind GetKind() const {
182 return kind_;
183 }
184
185 void SetKind(Kind kind) {
186 kind_ = kind;
187 }
188
189 uint32_t InstrumentationEvent() const {
190 return instrumentation_event_;
191 }
192
193 void SetInstrumentationEvent(uint32_t instrumentation_event) {
194 instrumentation_event_ = instrumentation_event;
195 }
196
197 private:
198 Kind kind_;
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100199
Sebastien Hertz42cd43f2014-05-13 14:15:41 +0200200 // TODO we could use a union to hold the instrumentation_event and the method since they
201 // respectively have sense only for kRegisterForEvent/kUnregisterForEvent and
202 // kSelectiveDeoptimization/kSelectiveUndeoptimization.
203
204 // Event to start or stop listening to. Only for kRegisterForEvent and kUnregisterForEvent.
Hiroshi Yamauchi0ec17d22014-07-07 13:07:08 -0700205 uint32_t instrumentation_event_;
Sebastien Hertz42cd43f2014-05-13 14:15:41 +0200206
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100207 // Method for selective deoptimization.
Hiroshi Yamauchi0ec17d22014-07-07 13:07:08 -0700208 jmethodID method_;
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100209};
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700210std::ostream& operator<<(std::ostream& os, const DeoptimizationRequest::Kind& rhs);
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100211
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700212class Dbg {
Elliott Hughesff17f1f2012-01-24 18:12:29 -0800213 public:
Elliott Hughes4ffd3132011-10-24 12:06:42 -0700214 static void SetJdwpAllowed(bool allowed);
Leonard Mosescueb842212016-10-06 17:26:36 -0700215 static bool IsJdwpAllowed();
Elliott Hughes4ffd3132011-10-24 12:06:42 -0700216
Sebastien Hertzb3b173b2015-02-06 09:16:32 +0100217 static void StartJdwp();
Elliott Hughesd1cc8362011-10-24 16:58:50 -0700218 static void StopJdwp();
219
Elliott Hughes767a1472011-10-26 18:49:02 -0700220 // Invoked by the GC in case we need to keep DDMS informed.
Mathieu Chartier90443472015-07-16 20:32:27 -0700221 static void GcDidFinish() REQUIRES(!Locks::mutator_lock_);
Elliott Hughes767a1472011-10-26 18:49:02 -0700222
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700223 // Return the DebugInvokeReq for the current thread.
224 static DebugInvokeReq* GetInvokeReq();
225
Elliott Hughes475fc232011-10-25 15:00:35 -0700226 static Thread* GetDebugThread();
227 static void ClearWaitForEventThread();
228
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700229 /*
230 * Enable/disable breakpoints and step modes. Used to provide a heads-up
231 * when the debugger attaches.
232 */
233 static void Connected();
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100234 static void GoActive()
Mathieu Chartier90443472015-07-16 20:32:27 -0700235 REQUIRES(!Locks::breakpoint_lock_, !Locks::deoptimization_lock_, !Locks::mutator_lock_);
236 static void Disconnected() REQUIRES(!Locks::deoptimization_lock_, !Locks::mutator_lock_);
Sebastien Hertz4e5b2082015-03-24 19:03:40 +0100237 static void Dispose() {
238 gDisposed = true;
239 }
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700240
Elliott Hughesc0f09332012-03-26 13:27:06 -0700241 // Returns true if we're actually debugging with a real debugger, false if it's
242 // just DDMS (or nothing at all).
Daniel Mihalyieb076692014-08-22 17:33:31 +0200243 static bool IsDebuggerActive() {
244 return gDebuggerActive;
245 }
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700246
Sebastien Hertzb3b173b2015-02-06 09:16:32 +0100247 // Configures JDWP with parsed command-line options.
248 static void ConfigureJdwp(const JDWP::JdwpOptions& jdwp_options);
249
Elliott Hughesc0f09332012-03-26 13:27:06 -0700250 // Returns true if we had -Xrunjdwp or -agentlib:jdwp= on the command line.
251 static bool IsJdwpConfigured();
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700252
Mathieu Chartierd8565452015-03-26 09:41:50 -0700253 // Returns true if a method has any breakpoints.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700254 static bool MethodHasAnyBreakpoints(ArtMethod* method)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700255 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!Locks::breakpoint_lock_);
Mathieu Chartierd8565452015-03-26 09:41:50 -0700256
Sebastien Hertz4e5b2082015-03-24 19:03:40 +0100257 static bool IsDisposed() {
258 return gDisposed;
259 }
Elliott Hughes86964332012-02-15 19:37:42 -0800260
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700261 /*
262 * Time, in milliseconds, since the last debugger activity. Does not
263 * include DDMS activity. Returns -1 if there has been no activity.
264 * Returns 0 if we're in the middle of handling a debugger request.
265 */
266 static int64_t LastDebuggerActivity();
267
Sebastien Hertz253fa552014-10-14 17:27:15 +0200268 static void UndoDebuggerSuspensions()
Mathieu Chartier90443472015-07-16 20:32:27 -0700269 REQUIRES(!Locks::thread_list_lock_, !Locks::thread_suspend_count_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700270
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700271 /*
272 * Class, Object, Array
273 */
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700274 static std::string GetClassName(JDWP::RefTypeId id)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700275 REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertz6995c602014-09-09 12:10:13 +0200276 static std::string GetClassName(mirror::Class* klass)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700277 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogersc0542af2014-09-03 16:16:56 -0700278 static JDWP::JdwpError GetClassObject(JDWP::RefTypeId id, JDWP::ObjectId* class_object_id)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700279 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogersc0542af2014-09-03 16:16:56 -0700280 static JDWP::JdwpError GetSuperclass(JDWP::RefTypeId id, JDWP::RefTypeId* superclass_id)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700281 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700282 static JDWP::JdwpError GetClassLoader(JDWP::RefTypeId id, JDWP::ExpandBuf* pReply)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700283 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700284 static JDWP::JdwpError GetModifiers(JDWP::RefTypeId id, JDWP::ExpandBuf* pReply)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700285 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800286 static JDWP::JdwpError GetReflectedType(JDWP::RefTypeId class_id, JDWP::ExpandBuf* pReply)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700287 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogersc0542af2014-09-03 16:16:56 -0700288 static void GetClassList(std::vector<JDWP::RefTypeId>* classes)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700289 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800290 static JDWP::JdwpError GetClassInfo(JDWP::RefTypeId class_id, JDWP::JdwpTypeTag* pTypeTag,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700291 uint32_t* pStatus, std::string* pDescriptor)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700292 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogersc0542af2014-09-03 16:16:56 -0700293 static void FindLoadedClassBySignature(const char* descriptor, std::vector<JDWP::RefTypeId>* ids)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700294 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes64f574f2013-02-20 14:57:12 -0800295 static JDWP::JdwpError GetReferenceType(JDWP::ObjectId object_id, JDWP::ExpandBuf* pReply)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700296 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogersfc0e94b2013-09-23 23:51:32 -0700297 static JDWP::JdwpError GetSignature(JDWP::RefTypeId ref_type_id, std::string* signature)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700298 REQUIRES_SHARED(Locks::mutator_lock_);
Orion Hodson77d8a1c2017-04-24 14:53:19 +0100299 static JDWP::JdwpError GetSourceDebugExtension(JDWP::RefTypeId ref_type_id,
300 std::string* extension_data)
301 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogersc0542af2014-09-03 16:16:56 -0700302 static JDWP::JdwpError GetSourceFile(JDWP::RefTypeId ref_type_id, std::string* source_file)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700303 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogersc0542af2014-09-03 16:16:56 -0700304 static JDWP::JdwpError GetObjectTag(JDWP::ObjectId object_id, uint8_t* tag)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700305 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughesaed4be92011-12-02 16:16:23 -0800306 static size_t GetTagWidth(JDWP::JdwpTag tag);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700307
Ian Rogersc0542af2014-09-03 16:16:56 -0700308 static JDWP::JdwpError GetArrayLength(JDWP::ObjectId array_id, int32_t* length)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700309 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800310 static JDWP::JdwpError OutputArray(JDWP::ObjectId array_id, int offset, int count,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700311 JDWP::ExpandBuf* pReply)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700312 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800313 static JDWP::JdwpError SetArrayElements(JDWP::ObjectId array_id, int offset, int count,
Ian Rogersc0542af2014-09-03 16:16:56 -0700314 JDWP::Request* request)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700315 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700316
Sebastien Hertz2c3e77a2015-04-02 16:26:48 +0200317 static JDWP::JdwpError CreateString(const std::string& str, JDWP::ObjectId* new_string_id)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700318 REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertz2c3e77a2015-04-02 16:26:48 +0200319 static JDWP::JdwpError CreateObject(JDWP::RefTypeId class_id, JDWP::ObjectId* new_object_id)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700320 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800321 static JDWP::JdwpError CreateArrayObject(JDWP::RefTypeId array_class_id, uint32_t length,
Sebastien Hertz2c3e77a2015-04-02 16:26:48 +0200322 JDWP::ObjectId* new_array_id)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700323 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700324
Sebastien Hertz6995c602014-09-09 12:10:13 +0200325 //
326 // Event filtering.
327 //
328 static bool MatchThread(JDWP::ObjectId expected_thread_id, Thread* event_thread)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700329 REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertz6995c602014-09-09 12:10:13 +0200330
331 static bool MatchLocation(const JDWP::JdwpLocation& expected_location,
332 const JDWP::EventLocation& event_location)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700333 REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertz6995c602014-09-09 12:10:13 +0200334
Mathieu Chartier3398c782016-09-30 10:27:43 -0700335 static bool MatchType(ObjPtr<mirror::Class> event_class, JDWP::RefTypeId class_id)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700336 REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertz6995c602014-09-09 12:10:13 +0200337
338 static bool MatchField(JDWP::RefTypeId expected_type_id, JDWP::FieldId expected_field_id,
Mathieu Chartierc7853442015-03-27 14:35:38 -0700339 ArtField* event_field)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700340 REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertz6995c602014-09-09 12:10:13 +0200341
342 static bool MatchInstance(JDWP::ObjectId expected_instance_id, mirror::Object* event_instance)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700343 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700344
Elliott Hughesec0f83d2013-01-15 16:54:08 -0800345 //
346 // Monitors.
347 //
348 static JDWP::JdwpError GetMonitorInfo(JDWP::ObjectId object_id, JDWP::ExpandBuf* reply)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700349 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughesec0f83d2013-01-15 16:54:08 -0800350 static JDWP::JdwpError GetOwnedMonitors(JDWP::ObjectId thread_id,
Ian Rogersc0542af2014-09-03 16:16:56 -0700351 std::vector<JDWP::ObjectId>* monitors,
352 std::vector<uint32_t>* stack_depths)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700353 REQUIRES(!Locks::thread_list_lock_) REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100354 static JDWP::JdwpError GetContendedMonitor(JDWP::ObjectId thread_id,
Ian Rogersc0542af2014-09-03 16:16:56 -0700355 JDWP::ObjectId* contended_monitor)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700356 REQUIRES(!Locks::thread_list_lock_) REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughesec0f83d2013-01-15 16:54:08 -0800357
358 //
359 // Heap.
360 //
361 static JDWP::JdwpError GetInstanceCounts(const std::vector<JDWP::RefTypeId>& class_ids,
Ian Rogersc0542af2014-09-03 16:16:56 -0700362 std::vector<uint64_t>* counts)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700363 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes3b78c942013-01-15 17:35:41 -0800364 static JDWP::JdwpError GetInstances(JDWP::RefTypeId class_id, int32_t max_count,
Ian Rogersc0542af2014-09-03 16:16:56 -0700365 std::vector<JDWP::ObjectId>* instances)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700366 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes0cbaff52013-01-16 15:28:01 -0800367 static JDWP::JdwpError GetReferringObjects(JDWP::ObjectId object_id, int32_t max_count,
Ian Rogersc0542af2014-09-03 16:16:56 -0700368 std::vector<JDWP::ObjectId>* referring_objects)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700369 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes64f574f2013-02-20 14:57:12 -0800370 static JDWP::JdwpError DisableCollection(JDWP::ObjectId object_id)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700371 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes64f574f2013-02-20 14:57:12 -0800372 static JDWP::JdwpError EnableCollection(JDWP::ObjectId object_id)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700373 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogersc0542af2014-09-03 16:16:56 -0700374 static JDWP::JdwpError IsCollected(JDWP::ObjectId object_id, bool* is_collected)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700375 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes64f574f2013-02-20 14:57:12 -0800376 static void DisposeObject(JDWP::ObjectId object_id, uint32_t reference_count)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700377 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughesec0f83d2013-01-15 16:54:08 -0800378
Elliott Hughes9777ba22013-01-17 09:04:19 -0800379 //
380 // Methods and fields.
381 //
Elliott Hughesa96836a2013-01-17 12:27:49 -0800382 static std::string GetMethodName(JDWP::MethodId method_id)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700383 REQUIRES_SHARED(Locks::mutator_lock_);
Alex Light73376312017-04-06 10:10:51 -0700384 static bool IsMethodObsolete(JDWP::MethodId method_id)
385 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800386 static JDWP::JdwpError OutputDeclaredFields(JDWP::RefTypeId ref_type_id, bool with_generic,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700387 JDWP::ExpandBuf* pReply)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700388 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800389 static JDWP::JdwpError OutputDeclaredMethods(JDWP::RefTypeId ref_type_id, bool with_generic,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700390 JDWP::ExpandBuf* pReply)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700391 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800392 static JDWP::JdwpError OutputDeclaredInterfaces(JDWP::RefTypeId ref_type_id,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700393 JDWP::ExpandBuf* pReply)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700394 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800395 static void OutputLineTable(JDWP::RefTypeId ref_type_id, JDWP::MethodId method_id,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700396 JDWP::ExpandBuf* pReply)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700397 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800398 static void OutputVariableTable(JDWP::RefTypeId ref_type_id, JDWP::MethodId id, bool with_generic,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700399 JDWP::ExpandBuf* pReply)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700400 REQUIRES_SHARED(Locks::mutator_lock_);
Jeff Hao579b0242013-11-18 13:16:49 -0800401 static void OutputMethodReturnValue(JDWP::MethodId method_id, const JValue* return_value,
402 JDWP::ExpandBuf* pReply)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700403 REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertz3f52eaf2014-04-04 17:50:18 +0200404 static void OutputFieldValue(JDWP::FieldId field_id, const JValue* field_value,
405 JDWP::ExpandBuf* pReply)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700406 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes9777ba22013-01-17 09:04:19 -0800407 static JDWP::JdwpError GetBytecodes(JDWP::RefTypeId class_id, JDWP::MethodId method_id,
Ian Rogersc0542af2014-09-03 16:16:56 -0700408 std::vector<uint8_t>* bytecodes)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700409 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700410
Elliott Hughesa96836a2013-01-17 12:27:49 -0800411 static std::string GetFieldName(JDWP::FieldId field_id)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700412 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800413 static JDWP::JdwpTag GetFieldBasicTag(JDWP::FieldId field_id)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700414 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800415 static JDWP::JdwpTag GetStaticFieldBasicTag(JDWP::FieldId field_id)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700416 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800417 static JDWP::JdwpError GetFieldValue(JDWP::ObjectId object_id, JDWP::FieldId field_id,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700418 JDWP::ExpandBuf* pReply)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700419 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800420 static JDWP::JdwpError SetFieldValue(JDWP::ObjectId object_id, JDWP::FieldId field_id,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700421 uint64_t value, int width)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700422 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800423 static JDWP::JdwpError GetStaticFieldValue(JDWP::RefTypeId ref_type_id, JDWP::FieldId field_id,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700424 JDWP::ExpandBuf* pReply)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700425 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800426 static JDWP::JdwpError SetStaticFieldValue(JDWP::FieldId field_id, uint64_t value, int width)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700427 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700428
Sebastien Hertzb0b0b492014-09-15 11:27:27 +0200429 static JDWP::JdwpError StringToUtf8(JDWP::ObjectId string_id, std::string* str)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700430 REQUIRES_SHARED(Locks::mutator_lock_);
Jeff Hao579b0242013-11-18 13:16:49 -0800431 static void OutputJValue(JDWP::JdwpTag tag, const JValue* return_value, JDWP::ExpandBuf* pReply)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700432 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700433
434 /*
435 * Thread, ThreadGroup, Frame
436 */
Ian Rogersc0542af2014-09-03 16:16:56 -0700437 static JDWP::JdwpError GetThreadName(JDWP::ObjectId thread_id, std::string* name)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700438 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!Locks::thread_list_lock_);
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100439 static JDWP::JdwpError GetThreadGroup(JDWP::ObjectId thread_id, JDWP::ExpandBuf* pReply)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700440 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!Locks::thread_list_lock_);
Sebastien Hertza06430c2014-09-15 19:21:30 +0200441 static JDWP::JdwpError GetThreadGroupName(JDWP::ObjectId thread_group_id,
442 JDWP::ExpandBuf* pReply)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700443 REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertza06430c2014-09-15 19:21:30 +0200444 static JDWP::JdwpError GetThreadGroupParent(JDWP::ObjectId thread_group_id,
445 JDWP::ExpandBuf* pReply)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700446 REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertza06430c2014-09-15 19:21:30 +0200447 static JDWP::JdwpError GetThreadGroupChildren(JDWP::ObjectId thread_group_id,
448 JDWP::ExpandBuf* pReply)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700449 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700450 static JDWP::ObjectId GetSystemThreadGroupId()
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700451 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700452
Jeff Hao920af3e2013-08-28 15:46:38 -0700453 static JDWP::JdwpThreadStatus ToJdwpThreadStatus(ThreadState state);
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100454 static JDWP::JdwpError GetThreadStatus(JDWP::ObjectId thread_id,
455 JDWP::JdwpThreadStatus* pThreadStatus,
456 JDWP::JdwpSuspendStatus* pSuspendStatus)
Mathieu Chartier90443472015-07-16 20:32:27 -0700457 REQUIRES(!Locks::thread_list_lock_);
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100458 static JDWP::JdwpError GetThreadDebugSuspendCount(JDWP::ObjectId thread_id,
459 JDWP::ExpandBuf* pReply)
Mathieu Chartier90443472015-07-16 20:32:27 -0700460 REQUIRES(!Locks::thread_list_lock_, !Locks::thread_suspend_count_lock_);
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700461 // static void WaitForSuspend(JDWP::ObjectId thread_id);
Elliott Hughescaf76542012-06-28 16:08:22 -0700462
Elliott Hughes026b1462012-06-28 20:43:49 -0700463 // Fills 'thread_ids' with the threads in the given thread group. If thread_group_id == 0,
Elliott Hughescaf76542012-06-28 16:08:22 -0700464 // returns all threads.
Sebastien Hertza06430c2014-09-15 19:21:30 +0200465 static void GetThreads(mirror::Object* thread_group, std::vector<JDWP::ObjectId>* thread_ids)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700466 REQUIRES(!Locks::thread_list_lock_) REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughescaf76542012-06-28 16:08:22 -0700467
Ian Rogersc0542af2014-09-03 16:16:56 -0700468 static JDWP::JdwpError GetThreadFrameCount(JDWP::ObjectId thread_id, size_t* result)
Mathieu Chartier90443472015-07-16 20:32:27 -0700469 REQUIRES(!Locks::thread_list_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700470 static JDWP::JdwpError GetThreadFrames(JDWP::ObjectId thread_id, size_t start_frame,
471 size_t frame_count, JDWP::ExpandBuf* buf)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700472 REQUIRES(!Locks::thread_list_lock_) REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700473
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700474 static JDWP::ObjectId GetThreadSelfId() REQUIRES_SHARED(Locks::mutator_lock_);
475 static JDWP::ObjectId GetThreadId(Thread* thread) REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertz6995c602014-09-09 12:10:13 +0200476
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700477 static void SuspendVM()
Mathieu Chartier90443472015-07-16 20:32:27 -0700478 REQUIRES(!Locks::thread_list_lock_, !Locks::thread_suspend_count_lock_);
Sebastien Hertz253fa552014-10-14 17:27:15 +0200479 static void ResumeVM()
Mathieu Chartier90443472015-07-16 20:32:27 -0700480 REQUIRES(!Locks::thread_list_lock_, !Locks::thread_suspend_count_lock_);
Elliott Hughes88d63092013-01-09 09:55:54 -0800481 static JDWP::JdwpError SuspendThread(JDWP::ObjectId thread_id, bool request_suspension = true)
Mathieu Chartier90443472015-07-16 20:32:27 -0700482 REQUIRES(!Locks::mutator_lock_, !Locks::thread_list_lock_,
483 !Locks::thread_suspend_count_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700484
Elliott Hughes88d63092013-01-09 09:55:54 -0800485 static void ResumeThread(JDWP::ObjectId thread_id)
Mathieu Chartier90443472015-07-16 20:32:27 -0700486 REQUIRES(!Locks::thread_list_lock_, !Locks::thread_suspend_count_lock_)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700487 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700488 static void SuspendSelf();
489
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700490 static JDWP::JdwpError GetThisObject(JDWP::ObjectId thread_id, JDWP::FrameId frame_id,
491 JDWP::ObjectId* result)
Mathieu Chartier90443472015-07-16 20:32:27 -0700492 REQUIRES(!Locks::thread_list_lock_, !Locks::thread_suspend_count_lock_)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700493 REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertz8009f392014-09-01 17:07:11 +0200494 static JDWP::JdwpError GetLocalValues(JDWP::Request* request, JDWP::ExpandBuf* pReply)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700495 REQUIRES(!Locks::thread_list_lock_) REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertz8009f392014-09-01 17:07:11 +0200496 static JDWP::JdwpError SetLocalValues(JDWP::Request* request)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700497 REQUIRES(!Locks::thread_list_lock_) REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700498
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100499 static JDWP::JdwpError Interrupt(JDWP::ObjectId thread_id)
Mathieu Chartier90443472015-07-16 20:32:27 -0700500 REQUIRES(!Locks::thread_list_lock_);
Elliott Hughesf9501702013-01-11 11:22:27 -0800501
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700502 /*
503 * Debugger notification
504 */
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700505 enum EventFlag {
Elliott Hughes86964332012-02-15 19:37:42 -0800506 kBreakpoint = 0x01,
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700507 kSingleStep = 0x02,
508 kMethodEntry = 0x04,
509 kMethodExit = 0x08,
510 };
Mathieu Chartiere401d142015-04-22 13:56:20 -0700511 static void PostFieldAccessEvent(ArtMethod* m, int dex_pc, mirror::Object* this_object,
Mathieu Chartierc7853442015-03-27 14:35:38 -0700512 ArtField* f)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700513 REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700514 static void PostFieldModificationEvent(ArtMethod* m, int dex_pc,
Mathieu Chartierc7853442015-03-27 14:35:38 -0700515 mirror::Object* this_object, ArtField* f,
Sebastien Hertz3f52eaf2014-04-04 17:50:18 +0200516 const JValue* field_value)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700517 REQUIRES_SHARED(Locks::mutator_lock_);
Nicolas Geoffray14691c52015-03-05 10:40:17 +0000518 static void PostException(mirror::Throwable* exception)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700519 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700520
Ian Rogers62d6c772013-02-27 08:32:07 -0800521 static void UpdateDebugger(Thread* thread, mirror::Object* this_object,
Mathieu Chartiere401d142015-04-22 13:56:20 -0700522 ArtMethod* method, uint32_t new_dex_pc,
Sebastien Hertz8379b222014-02-24 17:38:15 +0100523 int event_flags, const JValue* return_value)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700524 REQUIRES(!Locks::breakpoint_lock_) REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes91bf6cd2012-02-14 17:27:48 -0800525
Sebastien Hertzf3928792014-11-17 19:00:37 +0100526 // Indicates whether we need deoptimization for debugging.
527 static bool RequiresDeoptimization();
528
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100529 // Records deoptimization request in the queue.
530 static void RequestDeoptimization(const DeoptimizationRequest& req)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700531 REQUIRES(!Locks::deoptimization_lock_) REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100532
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100533 // Manage deoptimization after updating JDWP events list. Suspends all threads, processes each
534 // request and finally resumes all threads.
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100535 static void ManageDeoptimization()
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700536 REQUIRES(!Locks::deoptimization_lock_) REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100537
538 // Breakpoints.
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100539 static void WatchLocation(const JDWP::JdwpLocation* pLoc, DeoptimizationRequest* req)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700540 REQUIRES(!Locks::breakpoint_lock_) REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100541 static void UnwatchLocation(const JDWP::JdwpLocation* pLoc, DeoptimizationRequest* req)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700542 REQUIRES(!Locks::breakpoint_lock_) REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100543
Daniel Mihalyieb076692014-08-22 17:33:31 +0200544 /*
545 * Forced interpreter checkers for single-step and continue support.
546 */
547
548 // Indicates whether we need to force the use of interpreter to invoke a method.
549 // This allows to single-step or continue into the called method.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700550 static bool IsForcedInterpreterNeededForCalling(Thread* thread, ArtMethod* m)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700551 REQUIRES_SHARED(Locks::mutator_lock_) {
Daniel Mihalyieb076692014-08-22 17:33:31 +0200552 if (!IsDebuggerActive()) {
553 return false;
554 }
555 return IsForcedInterpreterNeededForCallingImpl(thread, m);
556 }
557
558 // Indicates whether we need to force the use of interpreter entrypoint when calling a
559 // method through the resolution trampoline. This allows to single-step or continue into
560 // the called method.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700561 static bool IsForcedInterpreterNeededForResolution(Thread* thread, ArtMethod* m)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700562 REQUIRES_SHARED(Locks::mutator_lock_) {
Daniel Mihalyieb076692014-08-22 17:33:31 +0200563 if (!IsDebuggerActive()) {
564 return false;
565 }
566 return IsForcedInterpreterNeededForResolutionImpl(thread, m);
567 }
568
569 // Indicates whether we need to force the use of instrumentation entrypoint when calling
570 // a method through the resolution trampoline. This allows to deoptimize the stack for
571 // debugging when we returned from the called method.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700572 static bool IsForcedInstrumentationNeededForResolution(Thread* thread, ArtMethod* m)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700573 REQUIRES_SHARED(Locks::mutator_lock_) {
Daniel Mihalyieb076692014-08-22 17:33:31 +0200574 if (!IsDebuggerActive()) {
575 return false;
576 }
577 return IsForcedInstrumentationNeededForResolutionImpl(thread, m);
578 }
579
580 // Indicates whether we need to force the use of interpreter when returning from the
581 // interpreter into the runtime. This allows to deoptimize the stack and continue
582 // execution with interpreter for debugging.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700583 static bool IsForcedInterpreterNeededForUpcall(Thread* thread, ArtMethod* m)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700584 REQUIRES_SHARED(Locks::mutator_lock_) {
Mingyao Yang99170c62015-07-06 11:10:37 -0700585 if (!IsDebuggerActive() && !thread->HasDebuggerShadowFrames()) {
Daniel Mihalyieb076692014-08-22 17:33:31 +0200586 return false;
587 }
588 return IsForcedInterpreterNeededForUpcallImpl(thread, m);
589 }
590
Sebastien Hertz520633b2015-09-08 17:03:36 +0200591 // Indicates whether we need to force the use of interpreter when handling an
592 // exception. This allows to deoptimize the stack and continue execution with
593 // the interpreter.
594 // Note: the interpreter will start by handling the exception when executing
595 // the deoptimized frames.
596 static bool IsForcedInterpreterNeededForException(Thread* thread)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700597 REQUIRES_SHARED(Locks::mutator_lock_) {
Mingyao Yang99170c62015-07-06 11:10:37 -0700598 if (!IsDebuggerActive() && !thread->HasDebuggerShadowFrames()) {
Sebastien Hertz520633b2015-09-08 17:03:36 +0200599 return false;
600 }
601 return IsForcedInterpreterNeededForExceptionImpl(thread);
602 }
603
Sebastien Hertz138dbfc2013-12-04 18:15:25 +0100604 // Single-stepping.
Elliott Hughes88d63092013-01-09 09:55:54 -0800605 static JDWP::JdwpError ConfigureStep(JDWP::ObjectId thread_id, JDWP::JdwpStepSize size,
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700606 JDWP::JdwpStepDepth depth)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700607 REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertz61b7f1b2013-11-15 15:59:30 +0100608 static void UnconfigureStep(JDWP::ObjectId thread_id)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700609 REQUIRES(!Locks::thread_list_lock_) REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700610
Sebastien Hertzcbc50642015-06-01 17:33:12 +0200611 /*
612 * Invoke support
613 */
614
615 // Called by the JDWP thread to prepare invocation in the event thread (suspended on an event).
616 // If the information sent by the debugger is incorrect, it will send a reply with the
617 // appropriate error code. Otherwise, it will attach a DebugInvokeReq object to the event thread
618 // and resume it (and possibly other threads depending on the invoke options).
619 // Unlike other commands, the JDWP thread will not send the reply to the debugger (see
620 // JdwpState::ProcessRequest). The reply will be sent by the event thread itself after method
621 // invocation completes (see FinishInvokeMethod). This is required to allow the JDWP thread to
622 // process incoming commands from the debugger while the invocation is still in progress in the
623 // event thread, especially if it gets suspended by a debug event occurring in another thread.
624 static JDWP::JdwpError PrepareInvokeMethod(uint32_t request_id, JDWP::ObjectId thread_id,
625 JDWP::ObjectId object_id, JDWP::RefTypeId class_id,
626 JDWP::MethodId method_id, uint32_t arg_count,
627 uint64_t arg_values[], JDWP::JdwpTag* arg_types,
628 uint32_t options)
Mathieu Chartier90443472015-07-16 20:32:27 -0700629 REQUIRES(!Locks::thread_list_lock_, !Locks::thread_suspend_count_lock_)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700630 REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertzcbc50642015-06-01 17:33:12 +0200631
632 // Called by the event thread to execute a method prepared by the JDWP thread in the given
633 // DebugInvokeReq object. Once the invocation completes, the event thread attaches a reply
634 // to that DebugInvokeReq object so it can be sent to the debugger only when the event thread
635 // is ready to suspend (see FinishInvokeMethod).
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700636 static void ExecuteMethod(DebugInvokeReq* pReq);
637
Sebastien Hertzcbc50642015-06-01 17:33:12 +0200638 // Called by the event thread to send the reply of the invoke (created in ExecuteMethod)
639 // before suspending itself. This is to ensure the thread is ready to suspend before the
640 // debugger receives the reply.
641 static void FinishInvokeMethod(DebugInvokeReq* pReq);
642
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700643 /*
644 * DDM support.
645 */
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700646 static void DdmSendThreadNotification(Thread* t, uint32_t type)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700647 REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100648 static void DdmSetThreadNotification(bool enable)
Mathieu Chartier90443472015-07-16 20:32:27 -0700649 REQUIRES(!Locks::thread_list_lock_);
Ian Rogersc0542af2014-09-03 16:16:56 -0700650 static bool DdmHandlePacket(JDWP::Request* request, uint8_t** pReplyBuf, int* pReplyLen);
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700651 static void DdmConnected() REQUIRES_SHARED(Locks::mutator_lock_);
652 static void DdmDisconnected() REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700653 static void DdmSendChunk(uint32_t type, const std::vector<uint8_t>& bytes)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700654 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700655 static void DdmSendChunk(uint32_t type, size_t len, const uint8_t* buf)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700656 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700657 static void DdmSendChunkV(uint32_t type, const iovec* iov, int iov_count)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700658 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes767a1472011-10-26 18:49:02 -0700659
Mathieu Chartiera6b1ead2015-10-06 10:32:38 -0700660 // Visit breakpoint roots, used to prevent unloading of methods with breakpoints.
Mathieu Chartierbb87e0f2015-04-03 11:21:55 -0700661 static void VisitRoots(RootVisitor* visitor)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700662 REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartier3b05e9b2014-03-25 09:29:43 -0700663
Elliott Hughes545a0642011-11-08 19:10:03 -0800664 /*
Man Cao8c2ff642015-05-27 17:25:30 -0700665 * Allocation tracking support.
Elliott Hughes545a0642011-11-08 19:10:03 -0800666 */
Mathieu Chartier90443472015-07-16 20:32:27 -0700667 static void SetAllocTrackingEnabled(bool enabled) REQUIRES(!Locks::alloc_tracker_lock_);
Sebastien Hertz52d131d2014-03-13 16:17:40 +0100668 static jbyteArray GetRecentAllocations()
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700669 REQUIRES(!Locks::alloc_tracker_lock_) REQUIRES_SHARED(Locks::mutator_lock_);
Mathieu Chartier90443472015-07-16 20:32:27 -0700670 static void DumpRecentAllocations() REQUIRES(!Locks::alloc_tracker_lock_);
Elliott Hughes545a0642011-11-08 19:10:03 -0800671
Elliott Hughes767a1472011-10-26 18:49:02 -0700672 enum HpifWhen {
673 HPIF_WHEN_NEVER = 0,
674 HPIF_WHEN_NOW = 1,
675 HPIF_WHEN_NEXT_GC = 2,
676 HPIF_WHEN_EVERY_GC = 3
677 };
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700678 static int DdmHandleHpifChunk(HpifWhen when)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700679 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes767a1472011-10-26 18:49:02 -0700680
681 enum HpsgWhen {
682 HPSG_WHEN_NEVER = 0,
683 HPSG_WHEN_EVERY_GC = 1,
684 };
685 enum HpsgWhat {
686 HPSG_WHAT_MERGED_OBJECTS = 0,
687 HPSG_WHAT_DISTINCT_OBJECTS = 1,
688 };
689 static bool DdmHandleHpsgNhsgChunk(HpsgWhen when, HpsgWhat what, bool native);
690
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700691 static void DdmSendHeapInfo(HpifWhen reason)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700692 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700693 static void DdmSendHeapSegments(bool native)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700694 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughes545a0642011-11-08 19:10:03 -0800695
Sebastien Hertz6995c602014-09-09 12:10:13 +0200696 static ObjectRegistry* GetObjectRegistry() {
697 return gRegistry;
698 }
699
700 static JDWP::JdwpTag TagFromObject(const ScopedObjectAccessUnchecked& soa, mirror::Object* o)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700701 REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertz6995c602014-09-09 12:10:13 +0200702
Mathieu Chartier3398c782016-09-30 10:27:43 -0700703 static JDWP::JdwpTypeTag GetTypeTag(ObjPtr<mirror::Class> klass)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700704 REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertz6995c602014-09-09 12:10:13 +0200705
Mathieu Chartierc7853442015-03-27 14:35:38 -0700706 static JDWP::FieldId ToFieldId(const ArtField* f)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700707 REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertz6995c602014-09-09 12:10:13 +0200708
Mathieu Chartiere401d142015-04-22 13:56:20 -0700709 static void SetJdwpLocation(JDWP::JdwpLocation* location, ArtMethod* m, uint32_t dex_pc)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700710 REQUIRES_SHARED(Locks::mutator_lock_)
Mathieu Chartier90443472015-07-16 20:32:27 -0700711 REQUIRES(!Locks::thread_list_lock_, !Locks::thread_suspend_count_lock_);
Sebastien Hertz6995c602014-09-09 12:10:13 +0200712
Mathieu Chartierad466ad2015-01-08 16:28:08 -0800713 static JDWP::JdwpState* GetJdwpState();
714
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700715 static uint32_t GetInstrumentationEvents() REQUIRES_SHARED(Locks::mutator_lock_) {
Sebastien Hertz9d6bf692015-04-10 12:12:33 +0200716 return instrumentation_events_;
717 }
718
Andreas Gampe04bbb5b2017-01-19 17:49:03 +0000719 static ThreadLifecycleCallback* GetThreadLifecycleCallback() {
720 return &thread_lifecycle_callback_;
721 }
Andreas Gampe0f01b582017-01-18 15:22:37 -0800722 static ClassLoadCallback* GetClassLoadCallback() {
723 return &class_load_callback_;
724 }
Andreas Gampe04bbb5b2017-01-19 17:49:03 +0000725
Elliott Hughes545a0642011-11-08 19:10:03 -0800726 private:
Sebastien Hertzcbc50642015-06-01 17:33:12 +0200727 static void ExecuteMethodWithoutPendingException(ScopedObjectAccess& soa, DebugInvokeReq* pReq)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700728 REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertzcbc50642015-06-01 17:33:12 +0200729
730 static void BuildInvokeReply(JDWP::ExpandBuf* pReply, uint32_t request_id,
731 JDWP::JdwpTag result_tag, uint64_t result_value,
732 JDWP::ObjectId exception)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700733 REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertzcbc50642015-06-01 17:33:12 +0200734
Sebastien Hertz8009f392014-09-01 17:07:11 +0200735 static JDWP::JdwpError GetLocalValue(const StackVisitor& visitor,
736 ScopedObjectAccessUnchecked& soa, int slot,
737 JDWP::JdwpTag tag, uint8_t* buf, size_t width)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700738 REQUIRES(!Locks::thread_list_lock_) REQUIRES_SHARED(Locks::mutator_lock_);
Mingyao Yang99170c62015-07-06 11:10:37 -0700739 static JDWP::JdwpError SetLocalValue(Thread* thread, StackVisitor& visitor, int slot,
740 JDWP::JdwpTag tag, uint64_t value, size_t width)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700741 REQUIRES(!Locks::thread_list_lock_) REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertz8009f392014-09-01 17:07:11 +0200742
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700743 static void DdmBroadcast(bool connect) REQUIRES_SHARED(Locks::mutator_lock_);
Andreas Gampe04bbb5b2017-01-19 17:49:03 +0000744
745 static void PostThreadStart(Thread* t)
746 REQUIRES_SHARED(Locks::mutator_lock_);
747 static void PostThreadDeath(Thread* t)
748 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700749 static void PostThreadStartOrStop(Thread*, uint32_t)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700750 REQUIRES_SHARED(Locks::mutator_lock_);
Elliott Hughesa2155262011-11-16 16:26:58 -0800751
Andreas Gampe0f01b582017-01-18 15:22:37 -0800752 static void PostClassPrepare(mirror::Class* c)
753 REQUIRES_SHARED(Locks::mutator_lock_);
754
Mathieu Chartiere401d142015-04-22 13:56:20 -0700755 static void PostLocationEvent(ArtMethod* method, int pcOffset,
Sebastien Hertz8379b222014-02-24 17:38:15 +0100756 mirror::Object* thisPtr, int eventFlags,
757 const JValue* return_value)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700758 REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertz8379b222014-02-24 17:38:15 +0100759
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100760 static void ProcessDeoptimizationRequest(const DeoptimizationRequest& request)
Mathieu Chartieraa516822015-10-02 15:53:37 -0700761 REQUIRES(Locks::mutator_lock_, Roles::uninterruptible_);
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100762
Sebastien Hertz7ec2f1c2014-03-27 20:06:47 +0100763 static void RequestDeoptimizationLocked(const DeoptimizationRequest& req)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700764 REQUIRES(Locks::deoptimization_lock_) REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertz7ec2f1c2014-03-27 20:06:47 +0100765
Mathieu Chartiere401d142015-04-22 13:56:20 -0700766 static bool IsForcedInterpreterNeededForCallingImpl(Thread* thread, ArtMethod* m)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700767 REQUIRES_SHARED(Locks::mutator_lock_);
Daniel Mihalyieb076692014-08-22 17:33:31 +0200768
Mathieu Chartiere401d142015-04-22 13:56:20 -0700769 static bool IsForcedInterpreterNeededForResolutionImpl(Thread* thread, ArtMethod* m)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700770 REQUIRES_SHARED(Locks::mutator_lock_);
Daniel Mihalyieb076692014-08-22 17:33:31 +0200771
Mathieu Chartiere401d142015-04-22 13:56:20 -0700772 static bool IsForcedInstrumentationNeededForResolutionImpl(Thread* thread, ArtMethod* m)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700773 REQUIRES_SHARED(Locks::mutator_lock_);
Daniel Mihalyieb076692014-08-22 17:33:31 +0200774
Mathieu Chartiere401d142015-04-22 13:56:20 -0700775 static bool IsForcedInterpreterNeededForUpcallImpl(Thread* thread, ArtMethod* m)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700776 REQUIRES_SHARED(Locks::mutator_lock_);
Daniel Mihalyieb076692014-08-22 17:33:31 +0200777
Sebastien Hertz520633b2015-09-08 17:03:36 +0200778 static bool IsForcedInterpreterNeededForExceptionImpl(Thread* thread)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700779 REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertz520633b2015-09-08 17:03:36 +0200780
Daniel Mihalyieb076692014-08-22 17:33:31 +0200781 // Indicates whether the debugger is making requests.
782 static bool gDebuggerActive;
783
Alex Light21611932017-09-26 13:07:39 -0700784 static DebuggerActiveMethodInspectionCallback gDebugActiveCallback;
785
Sebastien Hertz4e5b2082015-03-24 19:03:40 +0100786 // Indicates whether we should drop the JDWP connection because the runtime stops or the
787 // debugger called VirtualMachine.Dispose.
788 static bool gDisposed;
789
Daniel Mihalyieb076692014-08-22 17:33:31 +0200790 // The registry mapping objects to JDWP ids.
Sebastien Hertz6995c602014-09-09 12:10:13 +0200791 static ObjectRegistry* gRegistry;
792
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100793 // Deoptimization requests to be processed each time the event list is updated. This is used when
794 // registering and unregistering events so we do not deoptimize while holding the event list
795 // lock.
Sebastien Hertz42cd43f2014-05-13 14:15:41 +0200796 // TODO rename to instrumentation_requests.
Brian Carlstrom306db812014-09-05 13:01:41 -0700797 static std::vector<DeoptimizationRequest> deoptimization_requests_ GUARDED_BY(Locks::deoptimization_lock_);
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100798
799 // Count the number of events requiring full deoptimization. When the counter is > 0, everything
800 // is deoptimized, otherwise everything is undeoptimized.
801 // Note: we fully deoptimize on the first event only (when the counter is set to 1). We fully
802 // undeoptimize when the last event is unregistered (when the counter is set to 0).
Brian Carlstrom306db812014-09-05 13:01:41 -0700803 static size_t full_deoptimization_event_count_ GUARDED_BY(Locks::deoptimization_lock_);
Sebastien Hertz4d25df32014-03-21 17:44:46 +0100804
Sebastien Hertz42cd43f2014-05-13 14:15:41 +0200805 static size_t* GetReferenceCounterForEvent(uint32_t instrumentation_event);
806
807 // Instrumentation event reference counters.
808 // TODO we could use an array instead of having all these dedicated counters. Instrumentation
809 // events are bits of a mask so we could convert them to array index.
Brian Carlstrom306db812014-09-05 13:01:41 -0700810 static size_t dex_pc_change_event_ref_count_ GUARDED_BY(Locks::deoptimization_lock_);
811 static size_t method_enter_event_ref_count_ GUARDED_BY(Locks::deoptimization_lock_);
812 static size_t method_exit_event_ref_count_ GUARDED_BY(Locks::deoptimization_lock_);
813 static size_t field_read_event_ref_count_ GUARDED_BY(Locks::deoptimization_lock_);
814 static size_t field_write_event_ref_count_ GUARDED_BY(Locks::deoptimization_lock_);
815 static size_t exception_catch_event_ref_count_ GUARDED_BY(Locks::deoptimization_lock_);
Sebastien Hertz42cd43f2014-05-13 14:15:41 +0200816 static uint32_t instrumentation_events_ GUARDED_BY(Locks::mutator_lock_);
817
Andreas Gampe04bbb5b2017-01-19 17:49:03 +0000818 class DbgThreadLifecycleCallback : public ThreadLifecycleCallback {
819 public:
820 void ThreadStart(Thread* self) OVERRIDE REQUIRES_SHARED(Locks::mutator_lock_);
821 void ThreadDeath(Thread* self) OVERRIDE REQUIRES_SHARED(Locks::mutator_lock_);
822 };
823
Andreas Gampe0f01b582017-01-18 15:22:37 -0800824 class DbgClassLoadCallback : public ClassLoadCallback {
825 public:
826 void ClassLoad(Handle<mirror::Class> klass) OVERRIDE REQUIRES_SHARED(Locks::mutator_lock_);
827 void ClassPrepare(Handle<mirror::Class> temp_klass,
828 Handle<mirror::Class> klass) OVERRIDE REQUIRES_SHARED(Locks::mutator_lock_);
829 };
830
Andreas Gampe04bbb5b2017-01-19 17:49:03 +0000831 static DbgThreadLifecycleCallback thread_lifecycle_callback_;
Andreas Gampe0f01b582017-01-18 15:22:37 -0800832 static DbgClassLoadCallback class_load_callback_;
Andreas Gampe04bbb5b2017-01-19 17:49:03 +0000833
Ian Rogers719d1a32014-03-06 12:13:39 -0800834 DISALLOW_COPY_AND_ASSIGN(Dbg);
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700835};
836
837#define CHUNK_TYPE(_name) \
Elliott Hughes82188472011-11-07 18:11:48 -0800838 static_cast<uint32_t>((_name)[0] << 24 | (_name)[1] << 16 | (_name)[2] << 8 | (_name)[3])
Elliott Hughes872d4ec2011-10-21 17:07:15 -0700839
840} // namespace art
841
Brian Carlstromfc0e3212013-07-17 14:40:12 -0700842#endif // ART_RUNTIME_DEBUGGER_H_