blob: ef5151990ca2b05fd5d19db8c70ee8135c3e64ba [file] [log] [blame]
Alex Light49948e92016-08-11 15:35:28 -07001/* Copyright (C) 2016 The Android Open Source Project
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3 *
4 * This file implements interfaces from the file jvmti.h. This implementation
5 * is licensed under the same terms as the file jvmti.h. The
6 * copyright and license information for the file jvmti.h follows.
7 *
8 * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
9 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
10 *
11 * This code is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License version 2 only, as
13 * published by the Free Software Foundation. Oracle designates this
14 * particular file as subject to the "Classpath" exception as provided
15 * by Oracle in the LICENSE file that accompanied this code.
16 *
17 * This code is distributed in the hope that it will be useful, but WITHOUT
18 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
19 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 * version 2 for more details (a copy is included in the LICENSE file that
21 * accompanied this code).
22 *
23 * You should have received a copy of the GNU General Public License version
24 * 2 along with this work; if not, write to the Free Software Foundation,
25 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
26 *
27 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
28 * or visit www.oracle.com if you need additional information or have any
29 * questions.
30 */
31
Alex Light9c20a142016-08-23 15:05:12 -070032#include <string>
Andreas Gampef37e3022017-01-13 17:54:46 -080033#include <type_traits>
Alex Light9c20a142016-08-23 15:05:12 -070034#include <vector>
35
Andreas Gampe57943812017-12-06 21:39:13 -080036#include <android-base/logging.h>
37
Alex Light49948e92016-08-11 15:35:28 -070038#include <jni.h>
Alex Light9c20a142016-08-23 15:05:12 -070039
Andreas Gampe5e03a302017-03-13 13:10:00 -070040#include "jvmti.h"
Alex Light49948e92016-08-11 15:35:28 -070041
Andreas Gampedb6dcb62016-09-13 09:05:59 -070042#include "art_jvmti.h"
Andreas Gampe170331f2017-12-07 18:41:03 -080043#include "base/logging.h" // For gLogVerbosity.
Andreas Gampe77708d92016-10-07 11:48:21 -070044#include "base/mutex.h"
45#include "events-inl.h"
Alex Light49948e92016-08-11 15:35:28 -070046#include "jni_env_ext-inl.h"
Andreas Gampe6dee92e2016-09-12 19:58:13 -070047#include "obj_ptr-inl.h"
Alex Lighta01de592016-11-15 10:43:06 -080048#include "object_tagging.h"
Alex Light9c20a142016-08-23 15:05:12 -070049#include "runtime.h"
Andreas Gampe6dee92e2016-09-12 19:58:13 -070050#include "scoped_thread_state_change-inl.h"
Andreas Gampeb486a982017-06-01 13:45:54 -070051#include "thread-current-inl.h"
Alex Lighta01de592016-11-15 10:43:06 -080052#include "thread_list.h"
Alex Lightbf64a572017-07-05 10:34:49 -070053#include "ti_allocator.h"
Alex Lighta26e3492017-06-27 17:55:37 -070054#include "ti_breakpoint.h"
Andreas Gampee492ae32016-10-28 19:34:57 -070055#include "ti_class.h"
Andreas Gampeeb0cea12017-01-23 08:50:04 -080056#include "ti_dump.h"
Alex Light3f33c0a2017-11-08 10:17:37 -080057#include "ti_extension.h"
Andreas Gampeab2f0d02017-01-05 17:23:45 -080058#include "ti_field.h"
Andreas Gampeba8df692016-11-01 10:30:44 -070059#include "ti_heap.h"
Andreas Gampe6f8e4f02017-01-16 18:18:14 -080060#include "ti_jni.h"
Andreas Gampe3c252f02016-10-27 18:25:17 -070061#include "ti_method.h"
Andreas Gampe319dbe82017-01-09 16:42:21 -080062#include "ti_monitor.h"
Andreas Gampe50a4e492017-01-06 18:00:20 -080063#include "ti_object.h"
Andreas Gampe96eca782017-01-19 19:45:30 -080064#include "ti_phase.h"
Andreas Gampe1bdaf732017-01-09 19:21:06 -080065#include "ti_properties.h"
Alex Lighta01de592016-11-15 10:43:06 -080066#include "ti_redefine.h"
Andreas Gampece7732b2017-01-17 15:50:26 -080067#include "ti_search.h"
Andreas Gampeb5eb94a2016-10-27 19:23:09 -070068#include "ti_stack.h"
Andreas Gampeaf13ab92017-01-11 20:57:40 -080069#include "ti_thread.h"
Andreas Gamped18d9e22017-01-16 16:08:45 +000070#include "ti_threadgroup.h"
Andreas Gampe35bcf812017-01-13 16:24:17 -080071#include "ti_timers.h"
Alex Light9c20a142016-08-23 15:05:12 -070072#include "transform.h"
Alex Light49948e92016-08-11 15:35:28 -070073
Alex Light49948e92016-08-11 15:35:28 -070074namespace openjdkjvmti {
75
Alex Light0e841182018-02-12 17:42:50 +000076// NB These are heap allocated to avoid the static destructors being run if an agent calls exit(3).
77// These should never be null.
78EventHandler* gEventHandler;
79DeoptManager* gDeoptManager;
Andreas Gampe6dee92e2016-09-12 19:58:13 -070080
Alex Lighte6574242016-08-17 09:56:24 -070081#define ENSURE_NON_NULL(n) \
82 do { \
83 if ((n) == nullptr) { \
84 return ERR(NULL_POINTER); \
85 } \
86 } while (false)
87
Alex Light2ce6fc82017-12-18 16:42:36 -080088// Returns whether we are able to use all jvmti features.
89static bool IsFullJvmtiAvailable() {
90 art::Runtime* runtime = art::Runtime::Current();
91 return runtime->GetInstrumentation()->IsForcedInterpretOnly() || runtime->IsJavaDebuggable();
92}
93
Alex Light49948e92016-08-11 15:35:28 -070094class JvmtiFunctions {
95 private:
Alex Light1edc8cf2017-03-24 14:22:56 -070096 static jvmtiError getEnvironmentError(jvmtiEnv* env) {
97 if (env == nullptr) {
98 return ERR(INVALID_ENVIRONMENT);
99 } else if (art::Thread::Current() == nullptr) {
100 return ERR(UNATTACHED_THREAD);
101 } else {
102 return OK;
103 }
Alex Light49948e92016-08-11 15:35:28 -0700104 }
105
Alex Light1edc8cf2017-03-24 14:22:56 -0700106#define ENSURE_VALID_ENV(env) \
107 do { \
108 jvmtiError ensure_valid_env_ ## __LINE__ = getEnvironmentError(env); \
109 if (ensure_valid_env_ ## __LINE__ != OK) { \
110 return ensure_valid_env_ ## __LINE__ ; \
111 } \
Alex Lighte6574242016-08-17 09:56:24 -0700112 } while (false)
113
114#define ENSURE_HAS_CAP(env, cap) \
115 do { \
Alex Lighte6574242016-08-17 09:56:24 -0700116 if (ArtJvmTiEnv::AsArtJvmTiEnv(env)->capabilities.cap != 1) { \
117 return ERR(MUST_POSSESS_CAPABILITY); \
118 } \
119 } while (false)
120
Alex Light49948e92016-08-11 15:35:28 -0700121 public:
122 static jvmtiError Allocate(jvmtiEnv* env, jlong size, unsigned char** mem_ptr) {
Alex Lighte6574242016-08-17 09:56:24 -0700123 ENSURE_VALID_ENV(env);
124 ENSURE_NON_NULL(mem_ptr);
Alex Lightbf64a572017-07-05 10:34:49 -0700125 return AllocUtil::Allocate(env, size, mem_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700126 }
127
128 static jvmtiError Deallocate(jvmtiEnv* env, unsigned char* mem) {
Alex Lighte6574242016-08-17 09:56:24 -0700129 ENSURE_VALID_ENV(env);
Alex Lightbf64a572017-07-05 10:34:49 -0700130 return AllocUtil::Deallocate(env, mem);
Alex Light49948e92016-08-11 15:35:28 -0700131 }
132
133 static jvmtiError GetThreadState(jvmtiEnv* env, jthread thread, jint* thread_state_ptr) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700134 ENSURE_VALID_ENV(env);
Andreas Gampe72c19832017-01-12 13:22:16 -0800135 return ThreadUtil::GetThreadState(env, thread, thread_state_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700136 }
137
138 static jvmtiError GetCurrentThread(jvmtiEnv* env, jthread* thread_ptr) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700139 ENSURE_VALID_ENV(env);
Andreas Gampeaf13ab92017-01-11 20:57:40 -0800140 return ThreadUtil::GetCurrentThread(env, thread_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700141 }
142
143 static jvmtiError GetAllThreads(jvmtiEnv* env, jint* threads_count_ptr, jthread** threads_ptr) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700144 ENSURE_VALID_ENV(env);
Andreas Gampe85807442017-01-13 14:40:58 -0800145 return ThreadUtil::GetAllThreads(env, threads_count_ptr, threads_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700146 }
147
Alex Light88fd7202017-06-30 08:31:59 -0700148 static jvmtiError SuspendThread(jvmtiEnv* env, jthread thread) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700149 ENSURE_VALID_ENV(env);
Alex Light9db679d2017-01-25 15:28:04 -0800150 ENSURE_HAS_CAP(env, can_suspend);
Alex Light88fd7202017-06-30 08:31:59 -0700151 return ThreadUtil::SuspendThread(env, thread);
Alex Light49948e92016-08-11 15:35:28 -0700152 }
153
154 static jvmtiError SuspendThreadList(jvmtiEnv* env,
Alex Light88fd7202017-06-30 08:31:59 -0700155 jint request_count,
156 const jthread* request_list,
157 jvmtiError* results) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700158 ENSURE_VALID_ENV(env);
Alex Light9db679d2017-01-25 15:28:04 -0800159 ENSURE_HAS_CAP(env, can_suspend);
Alex Light88fd7202017-06-30 08:31:59 -0700160 return ThreadUtil::SuspendThreadList(env, request_count, request_list, results);
Alex Light49948e92016-08-11 15:35:28 -0700161 }
162
Alex Light88fd7202017-06-30 08:31:59 -0700163 static jvmtiError ResumeThread(jvmtiEnv* env, jthread thread) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700164 ENSURE_VALID_ENV(env);
Alex Light9db679d2017-01-25 15:28:04 -0800165 ENSURE_HAS_CAP(env, can_suspend);
Alex Light88fd7202017-06-30 08:31:59 -0700166 return ThreadUtil::ResumeThread(env, thread);
Alex Light49948e92016-08-11 15:35:28 -0700167 }
168
169 static jvmtiError ResumeThreadList(jvmtiEnv* env,
Alex Light88fd7202017-06-30 08:31:59 -0700170 jint request_count,
171 const jthread* request_list,
172 jvmtiError* results) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700173 ENSURE_VALID_ENV(env);
Alex Light9db679d2017-01-25 15:28:04 -0800174 ENSURE_HAS_CAP(env, can_suspend);
Alex Light88fd7202017-06-30 08:31:59 -0700175 return ThreadUtil::ResumeThreadList(env, request_count, request_list, results);
Alex Light49948e92016-08-11 15:35:28 -0700176 }
177
Alex Light54d39dc2017-09-25 17:00:16 -0700178 static jvmtiError StopThread(jvmtiEnv* env, jthread thread, jobject exception) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700179 ENSURE_VALID_ENV(env);
Alex Light9db679d2017-01-25 15:28:04 -0800180 ENSURE_HAS_CAP(env, can_signal_thread);
Alex Light54d39dc2017-09-25 17:00:16 -0700181 return ThreadUtil::StopThread(env, thread, exception);
Alex Light49948e92016-08-11 15:35:28 -0700182 }
183
Alex Light54d39dc2017-09-25 17:00:16 -0700184 static jvmtiError InterruptThread(jvmtiEnv* env, jthread thread) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700185 ENSURE_VALID_ENV(env);
Alex Light9db679d2017-01-25 15:28:04 -0800186 ENSURE_HAS_CAP(env, can_signal_thread);
Alex Light54d39dc2017-09-25 17:00:16 -0700187 return ThreadUtil::InterruptThread(env, thread);
Alex Light49948e92016-08-11 15:35:28 -0700188 }
189
190 static jvmtiError GetThreadInfo(jvmtiEnv* env, jthread thread, jvmtiThreadInfo* info_ptr) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700191 ENSURE_VALID_ENV(env);
Andreas Gampeaf13ab92017-01-11 20:57:40 -0800192 return ThreadUtil::GetThreadInfo(env, thread, info_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700193 }
194
195 static jvmtiError GetOwnedMonitorInfo(jvmtiEnv* env,
Alex Light88e1ddd2017-08-21 13:09:55 -0700196 jthread thread,
197 jint* owned_monitor_count_ptr,
198 jobject** owned_monitors_ptr) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700199 ENSURE_VALID_ENV(env);
Alex Light9db679d2017-01-25 15:28:04 -0800200 ENSURE_HAS_CAP(env, can_get_owned_monitor_info);
Alex Light88e1ddd2017-08-21 13:09:55 -0700201 return StackUtil::GetOwnedMonitorInfo(env,
202 thread,
203 owned_monitor_count_ptr,
204 owned_monitors_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700205 }
206
Alex Light88e1ddd2017-08-21 13:09:55 -0700207 static jvmtiError GetOwnedMonitorStackDepthInfo(jvmtiEnv* env,
208 jthread thread,
209 jint* monitor_info_count_ptr,
210 jvmtiMonitorStackDepthInfo** monitor_info_ptr) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700211 ENSURE_VALID_ENV(env);
Alex Light9db679d2017-01-25 15:28:04 -0800212 ENSURE_HAS_CAP(env, can_get_owned_monitor_stack_depth_info);
Alex Light88e1ddd2017-08-21 13:09:55 -0700213 return StackUtil::GetOwnedMonitorStackDepthInfo(env,
214 thread,
215 monitor_info_count_ptr,
216 monitor_info_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700217 }
218
219 static jvmtiError GetCurrentContendedMonitor(jvmtiEnv* env,
Alex Light41006c62017-09-14 09:51:14 -0700220 jthread thread,
221 jobject* monitor_ptr) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700222 ENSURE_VALID_ENV(env);
Alex Light9db679d2017-01-25 15:28:04 -0800223 ENSURE_HAS_CAP(env, can_get_current_contended_monitor);
Alex Light41006c62017-09-14 09:51:14 -0700224 return MonitorUtil::GetCurrentContendedMonitor(env, thread, monitor_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700225 }
226
227 static jvmtiError RunAgentThread(jvmtiEnv* env,
228 jthread thread,
229 jvmtiStartFunction proc,
230 const void* arg,
231 jint priority) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700232 ENSURE_VALID_ENV(env);
Andreas Gampe732b0ac2017-01-18 15:23:39 -0800233 return ThreadUtil::RunAgentThread(env, thread, proc, arg, priority);
Alex Light49948e92016-08-11 15:35:28 -0700234 }
235
236 static jvmtiError SetThreadLocalStorage(jvmtiEnv* env, jthread thread, const void* data) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700237 ENSURE_VALID_ENV(env);
Andreas Gampe7b3b3262017-01-19 20:40:42 -0800238 return ThreadUtil::SetThreadLocalStorage(env, thread, data);
Alex Light49948e92016-08-11 15:35:28 -0700239 }
240
241 static jvmtiError GetThreadLocalStorage(jvmtiEnv* env, jthread thread, void** data_ptr) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700242 ENSURE_VALID_ENV(env);
Andreas Gampe7b3b3262017-01-19 20:40:42 -0800243 return ThreadUtil::GetThreadLocalStorage(env, thread, data_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700244 }
245
246 static jvmtiError GetTopThreadGroups(jvmtiEnv* env,
247 jint* group_count_ptr,
248 jthreadGroup** groups_ptr) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700249 ENSURE_VALID_ENV(env);
Andreas Gamped18d9e22017-01-16 16:08:45 +0000250 return ThreadGroupUtil::GetTopThreadGroups(env, group_count_ptr, groups_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700251 }
252
253 static jvmtiError GetThreadGroupInfo(jvmtiEnv* env,
254 jthreadGroup group,
255 jvmtiThreadGroupInfo* info_ptr) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700256 ENSURE_VALID_ENV(env);
Andreas Gamped18d9e22017-01-16 16:08:45 +0000257 return ThreadGroupUtil::GetThreadGroupInfo(env, group, info_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700258 }
259
260 static jvmtiError GetThreadGroupChildren(jvmtiEnv* env,
261 jthreadGroup group,
262 jint* thread_count_ptr,
263 jthread** threads_ptr,
264 jint* group_count_ptr,
265 jthreadGroup** groups_ptr) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700266 ENSURE_VALID_ENV(env);
Andreas Gamped18d9e22017-01-16 16:08:45 +0000267 return ThreadGroupUtil::GetThreadGroupChildren(env,
268 group,
269 thread_count_ptr,
270 threads_ptr,
271 group_count_ptr,
272 groups_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700273 }
274
275 static jvmtiError GetStackTrace(jvmtiEnv* env,
276 jthread thread,
277 jint start_depth,
278 jint max_frame_count,
279 jvmtiFrameInfo* frame_buffer,
280 jint* count_ptr) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700281 ENSURE_VALID_ENV(env);
Andreas Gampeb5eb94a2016-10-27 19:23:09 -0700282 return StackUtil::GetStackTrace(env,
283 thread,
284 start_depth,
285 max_frame_count,
286 frame_buffer,
287 count_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700288 }
289
290 static jvmtiError GetAllStackTraces(jvmtiEnv* env,
291 jint max_frame_count,
292 jvmtiStackInfo** stack_info_ptr,
293 jint* thread_count_ptr) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700294 ENSURE_VALID_ENV(env);
Andreas Gampea1a27c62017-01-11 16:37:16 -0800295 return StackUtil::GetAllStackTraces(env, max_frame_count, stack_info_ptr, thread_count_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700296 }
297
298 static jvmtiError GetThreadListStackTraces(jvmtiEnv* env,
299 jint thread_count,
300 const jthread* thread_list,
301 jint max_frame_count,
302 jvmtiStackInfo** stack_info_ptr) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700303 ENSURE_VALID_ENV(env);
Andreas Gampeeba32fb2017-01-12 17:40:05 -0800304 return StackUtil::GetThreadListStackTraces(env,
305 thread_count,
306 thread_list,
307 max_frame_count,
308 stack_info_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700309 }
310
311 static jvmtiError GetFrameCount(jvmtiEnv* env, jthread thread, jint* count_ptr) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700312 ENSURE_VALID_ENV(env);
Andreas Gampef6f3b5f2017-01-13 09:21:42 -0800313 return StackUtil::GetFrameCount(env, thread, count_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700314 }
315
Alex Light6a3fd512017-02-27 14:34:32 -0800316 static jvmtiError PopFrame(jvmtiEnv* env, jthread thread ATTRIBUTE_UNUSED) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700317 ENSURE_VALID_ENV(env);
Alex Light9db679d2017-01-25 15:28:04 -0800318 ENSURE_HAS_CAP(env, can_pop_frame);
Alex Light49948e92016-08-11 15:35:28 -0700319 return ERR(NOT_IMPLEMENTED);
320 }
321
322 static jvmtiError GetFrameLocation(jvmtiEnv* env,
323 jthread thread,
324 jint depth,
325 jmethodID* method_ptr,
326 jlocation* location_ptr) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700327 ENSURE_VALID_ENV(env);
Andreas Gampef6f3b5f2017-01-13 09:21:42 -0800328 return StackUtil::GetFrameLocation(env, thread, depth, method_ptr, location_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700329 }
330
Alex Lighte814f9d2017-07-31 16:14:39 -0700331 static jvmtiError NotifyFramePop(jvmtiEnv* env, jthread thread, jint depth) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700332 ENSURE_VALID_ENV(env);
Alex Light9db679d2017-01-25 15:28:04 -0800333 ENSURE_HAS_CAP(env, can_generate_frame_pop_events);
Alex Lighte814f9d2017-07-31 16:14:39 -0700334 return StackUtil::NotifyFramePop(env, thread, depth);
Alex Light49948e92016-08-11 15:35:28 -0700335 }
336
Alex Light6a3fd512017-02-27 14:34:32 -0800337 static jvmtiError ForceEarlyReturnObject(jvmtiEnv* env,
338 jthread thread ATTRIBUTE_UNUSED,
339 jobject value ATTRIBUTE_UNUSED) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700340 ENSURE_VALID_ENV(env);
Alex Light9db679d2017-01-25 15:28:04 -0800341 ENSURE_HAS_CAP(env, can_force_early_return);
Alex Light49948e92016-08-11 15:35:28 -0700342 return ERR(NOT_IMPLEMENTED);
343 }
344
Alex Light6a3fd512017-02-27 14:34:32 -0800345 static jvmtiError ForceEarlyReturnInt(jvmtiEnv* env,
346 jthread thread ATTRIBUTE_UNUSED,
347 jint value ATTRIBUTE_UNUSED) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700348 ENSURE_VALID_ENV(env);
Alex Light9db679d2017-01-25 15:28:04 -0800349 ENSURE_HAS_CAP(env, can_force_early_return);
Alex Light49948e92016-08-11 15:35:28 -0700350 return ERR(NOT_IMPLEMENTED);
351 }
352
Alex Light6a3fd512017-02-27 14:34:32 -0800353 static jvmtiError ForceEarlyReturnLong(jvmtiEnv* env,
354 jthread thread ATTRIBUTE_UNUSED,
355 jlong value ATTRIBUTE_UNUSED) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700356 ENSURE_VALID_ENV(env);
Alex Light9db679d2017-01-25 15:28:04 -0800357 ENSURE_HAS_CAP(env, can_force_early_return);
Alex Light49948e92016-08-11 15:35:28 -0700358 return ERR(NOT_IMPLEMENTED);
359 }
360
Alex Light6a3fd512017-02-27 14:34:32 -0800361 static jvmtiError ForceEarlyReturnFloat(jvmtiEnv* env,
362 jthread thread ATTRIBUTE_UNUSED,
363 jfloat value ATTRIBUTE_UNUSED) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700364 ENSURE_VALID_ENV(env);
Alex Light9db679d2017-01-25 15:28:04 -0800365 ENSURE_HAS_CAP(env, can_force_early_return);
Alex Light49948e92016-08-11 15:35:28 -0700366 return ERR(NOT_IMPLEMENTED);
367 }
368
Alex Light6a3fd512017-02-27 14:34:32 -0800369 static jvmtiError ForceEarlyReturnDouble(jvmtiEnv* env,
370 jthread thread ATTRIBUTE_UNUSED,
371 jdouble value ATTRIBUTE_UNUSED) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700372 ENSURE_VALID_ENV(env);
Alex Light9db679d2017-01-25 15:28:04 -0800373 ENSURE_HAS_CAP(env, can_force_early_return);
Alex Light49948e92016-08-11 15:35:28 -0700374 return ERR(NOT_IMPLEMENTED);
375 }
376
Alex Light6a3fd512017-02-27 14:34:32 -0800377 static jvmtiError ForceEarlyReturnVoid(jvmtiEnv* env, jthread thread ATTRIBUTE_UNUSED) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700378 ENSURE_VALID_ENV(env);
Alex Light9db679d2017-01-25 15:28:04 -0800379 ENSURE_HAS_CAP(env, can_force_early_return);
Alex Light49948e92016-08-11 15:35:28 -0700380 return ERR(NOT_IMPLEMENTED);
381 }
382
383 static jvmtiError FollowReferences(jvmtiEnv* env,
384 jint heap_filter,
385 jclass klass,
386 jobject initial_object,
387 const jvmtiHeapCallbacks* callbacks,
388 const void* user_data) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700389 ENSURE_VALID_ENV(env);
Alex Light9db679d2017-01-25 15:28:04 -0800390 ENSURE_HAS_CAP(env, can_tag_objects);
Andreas Gampede19eb92017-02-24 16:21:18 -0800391 HeapUtil heap_util(ArtJvmTiEnv::AsArtJvmTiEnv(env)->object_tag_table.get());
Andreas Gampe70bfc8a2016-11-03 11:04:15 -0700392 return heap_util.FollowReferences(env,
393 heap_filter,
394 klass,
395 initial_object,
396 callbacks,
397 user_data);
Alex Light49948e92016-08-11 15:35:28 -0700398 }
399
400 static jvmtiError IterateThroughHeap(jvmtiEnv* env,
401 jint heap_filter,
402 jclass klass,
403 const jvmtiHeapCallbacks* callbacks,
404 const void* user_data) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700405 ENSURE_VALID_ENV(env);
Alex Lighte6574242016-08-17 09:56:24 -0700406 ENSURE_HAS_CAP(env, can_tag_objects);
Andreas Gampede19eb92017-02-24 16:21:18 -0800407 HeapUtil heap_util(ArtJvmTiEnv::AsArtJvmTiEnv(env)->object_tag_table.get());
Andreas Gampee54d9922016-10-11 19:55:37 -0700408 return heap_util.IterateThroughHeap(env, heap_filter, klass, callbacks, user_data);
Alex Light49948e92016-08-11 15:35:28 -0700409 }
410
411 static jvmtiError GetTag(jvmtiEnv* env, jobject object, jlong* tag_ptr) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700412 ENSURE_VALID_ENV(env);
Alex Lighte6574242016-08-17 09:56:24 -0700413 ENSURE_HAS_CAP(env, can_tag_objects);
Andreas Gampe6dee92e2016-09-12 19:58:13 -0700414
415 JNIEnv* jni_env = GetJniEnv(env);
416 if (jni_env == nullptr) {
417 return ERR(INTERNAL);
418 }
419
420 art::ScopedObjectAccess soa(jni_env);
421 art::ObjPtr<art::mirror::Object> obj = soa.Decode<art::mirror::Object>(object);
Andreas Gampede19eb92017-02-24 16:21:18 -0800422 if (!ArtJvmTiEnv::AsArtJvmTiEnv(env)->object_tag_table->GetTag(obj.Ptr(), tag_ptr)) {
Andreas Gampe6dee92e2016-09-12 19:58:13 -0700423 *tag_ptr = 0;
424 }
425
426 return ERR(NONE);
Alex Light49948e92016-08-11 15:35:28 -0700427 }
428
429 static jvmtiError SetTag(jvmtiEnv* env, jobject object, jlong tag) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700430 ENSURE_VALID_ENV(env);
Alex Lighte6574242016-08-17 09:56:24 -0700431 ENSURE_HAS_CAP(env, can_tag_objects);
432
Andreas Gampe6dee92e2016-09-12 19:58:13 -0700433 if (object == nullptr) {
434 return ERR(NULL_POINTER);
435 }
436
437 JNIEnv* jni_env = GetJniEnv(env);
438 if (jni_env == nullptr) {
439 return ERR(INTERNAL);
440 }
441
442 art::ScopedObjectAccess soa(jni_env);
443 art::ObjPtr<art::mirror::Object> obj = soa.Decode<art::mirror::Object>(object);
Andreas Gampede19eb92017-02-24 16:21:18 -0800444 ArtJvmTiEnv::AsArtJvmTiEnv(env)->object_tag_table->Set(obj.Ptr(), tag);
Andreas Gampe6dee92e2016-09-12 19:58:13 -0700445
446 return ERR(NONE);
Alex Light49948e92016-08-11 15:35:28 -0700447 }
448
449 static jvmtiError GetObjectsWithTags(jvmtiEnv* env,
450 jint tag_count,
451 const jlong* tags,
452 jint* count_ptr,
453 jobject** object_result_ptr,
454 jlong** tag_result_ptr) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700455 ENSURE_VALID_ENV(env);
Alex Lighte6574242016-08-17 09:56:24 -0700456 ENSURE_HAS_CAP(env, can_tag_objects);
457
Andreas Gampe5e6046b2016-10-25 12:05:53 -0700458 JNIEnv* jni_env = GetJniEnv(env);
459 if (jni_env == nullptr) {
460 return ERR(INTERNAL);
461 }
462
463 art::ScopedObjectAccess soa(jni_env);
Andreas Gampede19eb92017-02-24 16:21:18 -0800464 return ArtJvmTiEnv::AsArtJvmTiEnv(env)->object_tag_table->GetTaggedObjects(env,
465 tag_count,
466 tags,
467 count_ptr,
468 object_result_ptr,
469 tag_result_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700470 }
471
472 static jvmtiError ForceGarbageCollection(jvmtiEnv* env) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700473 ENSURE_VALID_ENV(env);
Andreas Gampe8da6d032016-10-31 19:31:03 -0700474 return HeapUtil::ForceGarbageCollection(env);
Alex Light49948e92016-08-11 15:35:28 -0700475 }
476
477 static jvmtiError IterateOverObjectsReachableFromObject(
478 jvmtiEnv* env,
Alex Light6a3fd512017-02-27 14:34:32 -0800479 jobject object ATTRIBUTE_UNUSED,
480 jvmtiObjectReferenceCallback object_reference_callback ATTRIBUTE_UNUSED,
481 const void* user_data ATTRIBUTE_UNUSED) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700482 ENSURE_VALID_ENV(env);
Alex Light9db679d2017-01-25 15:28:04 -0800483 ENSURE_HAS_CAP(env, can_tag_objects);
Alex Light49948e92016-08-11 15:35:28 -0700484 return ERR(NOT_IMPLEMENTED);
485 }
486
Alex Light6a3fd512017-02-27 14:34:32 -0800487 static jvmtiError IterateOverReachableObjects(
488 jvmtiEnv* env,
489 jvmtiHeapRootCallback heap_root_callback ATTRIBUTE_UNUSED,
490 jvmtiStackReferenceCallback stack_ref_callback ATTRIBUTE_UNUSED,
491 jvmtiObjectReferenceCallback object_ref_callback ATTRIBUTE_UNUSED,
492 const void* user_data ATTRIBUTE_UNUSED) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700493 ENSURE_VALID_ENV(env);
Alex Light9db679d2017-01-25 15:28:04 -0800494 ENSURE_HAS_CAP(env, can_tag_objects);
Alex Light49948e92016-08-11 15:35:28 -0700495 return ERR(NOT_IMPLEMENTED);
496 }
497
498 static jvmtiError IterateOverHeap(jvmtiEnv* env,
Alex Light6a3fd512017-02-27 14:34:32 -0800499 jvmtiHeapObjectFilter object_filter ATTRIBUTE_UNUSED,
500 jvmtiHeapObjectCallback heap_object_callback ATTRIBUTE_UNUSED,
501 const void* user_data ATTRIBUTE_UNUSED) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700502 ENSURE_VALID_ENV(env);
Alex Light9db679d2017-01-25 15:28:04 -0800503 ENSURE_HAS_CAP(env, can_tag_objects);
Alex Light49948e92016-08-11 15:35:28 -0700504 return ERR(NOT_IMPLEMENTED);
505 }
506
Alex Light6a3fd512017-02-27 14:34:32 -0800507 static jvmtiError IterateOverInstancesOfClass(
508 jvmtiEnv* env,
509 jclass klass ATTRIBUTE_UNUSED,
510 jvmtiHeapObjectFilter object_filter ATTRIBUTE_UNUSED,
511 jvmtiHeapObjectCallback heap_object_callback ATTRIBUTE_UNUSED,
512 const void* user_data ATTRIBUTE_UNUSED) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700513 ENSURE_VALID_ENV(env);
Alex Light9db679d2017-01-25 15:28:04 -0800514 ENSURE_HAS_CAP(env, can_tag_objects);
Alex Light49948e92016-08-11 15:35:28 -0700515 return ERR(NOT_IMPLEMENTED);
516 }
517
518 static jvmtiError GetLocalObject(jvmtiEnv* env,
Alex Lightbebd7bd2017-07-25 14:05:52 -0700519 jthread thread,
520 jint depth,
521 jint slot,
522 jobject* value_ptr) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700523 ENSURE_VALID_ENV(env);
Alex Light9db679d2017-01-25 15:28:04 -0800524 ENSURE_HAS_CAP(env, can_access_local_variables);
Alex Lightbebd7bd2017-07-25 14:05:52 -0700525 return MethodUtil::GetLocalVariable(env, thread, depth, slot, value_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700526 }
527
528 static jvmtiError GetLocalInstance(jvmtiEnv* env,
Alex Lightbebd7bd2017-07-25 14:05:52 -0700529 jthread thread,
530 jint depth,
531 jobject* value_ptr) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700532 ENSURE_VALID_ENV(env);
Alex Light9db679d2017-01-25 15:28:04 -0800533 ENSURE_HAS_CAP(env, can_access_local_variables);
Alex Lightbebd7bd2017-07-25 14:05:52 -0700534 return MethodUtil::GetLocalInstance(env, thread, depth, value_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700535 }
536
537 static jvmtiError GetLocalInt(jvmtiEnv* env,
Alex Lightbebd7bd2017-07-25 14:05:52 -0700538 jthread thread,
539 jint depth,
540 jint slot,
541 jint* value_ptr) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700542 ENSURE_VALID_ENV(env);
Alex Light9db679d2017-01-25 15:28:04 -0800543 ENSURE_HAS_CAP(env, can_access_local_variables);
Alex Lightbebd7bd2017-07-25 14:05:52 -0700544 return MethodUtil::GetLocalVariable(env, thread, depth, slot, value_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700545 }
546
547 static jvmtiError GetLocalLong(jvmtiEnv* env,
Alex Lightbebd7bd2017-07-25 14:05:52 -0700548 jthread thread,
549 jint depth,
550 jint slot,
551 jlong* value_ptr) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700552 ENSURE_VALID_ENV(env);
Alex Light9db679d2017-01-25 15:28:04 -0800553 ENSURE_HAS_CAP(env, can_access_local_variables);
Alex Lightbebd7bd2017-07-25 14:05:52 -0700554 return MethodUtil::GetLocalVariable(env, thread, depth, slot, value_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700555 }
556
557 static jvmtiError GetLocalFloat(jvmtiEnv* env,
Alex Lightbebd7bd2017-07-25 14:05:52 -0700558 jthread thread,
559 jint depth,
560 jint slot,
561 jfloat* value_ptr) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700562 ENSURE_VALID_ENV(env);
Alex Light9db679d2017-01-25 15:28:04 -0800563 ENSURE_HAS_CAP(env, can_access_local_variables);
Alex Lightbebd7bd2017-07-25 14:05:52 -0700564 return MethodUtil::GetLocalVariable(env, thread, depth, slot, value_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700565 }
566
567 static jvmtiError GetLocalDouble(jvmtiEnv* env,
Alex Lightbebd7bd2017-07-25 14:05:52 -0700568 jthread thread,
569 jint depth,
570 jint slot,
571 jdouble* value_ptr) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700572 ENSURE_VALID_ENV(env);
Alex Light9db679d2017-01-25 15:28:04 -0800573 ENSURE_HAS_CAP(env, can_access_local_variables);
Alex Lightbebd7bd2017-07-25 14:05:52 -0700574 return MethodUtil::GetLocalVariable(env, thread, depth, slot, value_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700575 }
576
577 static jvmtiError SetLocalObject(jvmtiEnv* env,
Alex Lightbebd7bd2017-07-25 14:05:52 -0700578 jthread thread,
579 jint depth,
580 jint slot,
581 jobject value) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700582 ENSURE_VALID_ENV(env);
Alex Light9db679d2017-01-25 15:28:04 -0800583 ENSURE_HAS_CAP(env, can_access_local_variables);
Alex Lightbebd7bd2017-07-25 14:05:52 -0700584 return MethodUtil::SetLocalVariable(env, thread, depth, slot, value);
Alex Light49948e92016-08-11 15:35:28 -0700585 }
586
587 static jvmtiError SetLocalInt(jvmtiEnv* env,
Alex Lightbebd7bd2017-07-25 14:05:52 -0700588 jthread thread,
589 jint depth,
590 jint slot,
591 jint value) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700592 ENSURE_VALID_ENV(env);
Alex Light9db679d2017-01-25 15:28:04 -0800593 ENSURE_HAS_CAP(env, can_access_local_variables);
Alex Lightbebd7bd2017-07-25 14:05:52 -0700594 return MethodUtil::SetLocalVariable(env, thread, depth, slot, value);
Alex Light49948e92016-08-11 15:35:28 -0700595 }
596
597 static jvmtiError SetLocalLong(jvmtiEnv* env,
Alex Lightbebd7bd2017-07-25 14:05:52 -0700598 jthread thread,
599 jint depth,
600 jint slot,
601 jlong value) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700602 ENSURE_VALID_ENV(env);
Alex Light9db679d2017-01-25 15:28:04 -0800603 ENSURE_HAS_CAP(env, can_access_local_variables);
Alex Lightbebd7bd2017-07-25 14:05:52 -0700604 return MethodUtil::SetLocalVariable(env, thread, depth, slot, value);
Alex Light49948e92016-08-11 15:35:28 -0700605 }
606
607 static jvmtiError SetLocalFloat(jvmtiEnv* env,
Alex Lightbebd7bd2017-07-25 14:05:52 -0700608 jthread thread,
609 jint depth,
610 jint slot,
611 jfloat value) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700612 ENSURE_VALID_ENV(env);
Alex Light9db679d2017-01-25 15:28:04 -0800613 ENSURE_HAS_CAP(env, can_access_local_variables);
Alex Lightbebd7bd2017-07-25 14:05:52 -0700614 return MethodUtil::SetLocalVariable(env, thread, depth, slot, value);
Alex Light49948e92016-08-11 15:35:28 -0700615 }
616
617 static jvmtiError SetLocalDouble(jvmtiEnv* env,
Alex Lightbebd7bd2017-07-25 14:05:52 -0700618 jthread thread,
619 jint depth,
620 jint slot,
621 jdouble value) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700622 ENSURE_VALID_ENV(env);
Alex Light9db679d2017-01-25 15:28:04 -0800623 ENSURE_HAS_CAP(env, can_access_local_variables);
Alex Lightbebd7bd2017-07-25 14:05:52 -0700624 return MethodUtil::SetLocalVariable(env, thread, depth, slot, value);
Alex Light49948e92016-08-11 15:35:28 -0700625 }
626
Alex Lighta26e3492017-06-27 17:55:37 -0700627
628 static jvmtiError SetBreakpoint(jvmtiEnv* env, jmethodID method, jlocation location) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700629 ENSURE_VALID_ENV(env);
Alex Light9db679d2017-01-25 15:28:04 -0800630 ENSURE_HAS_CAP(env, can_generate_breakpoint_events);
Alex Lighta26e3492017-06-27 17:55:37 -0700631 return BreakpointUtil::SetBreakpoint(env, method, location);
Alex Light49948e92016-08-11 15:35:28 -0700632 }
633
Alex Lighta26e3492017-06-27 17:55:37 -0700634 static jvmtiError ClearBreakpoint(jvmtiEnv* env, jmethodID method, jlocation location) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700635 ENSURE_VALID_ENV(env);
Alex Light9db679d2017-01-25 15:28:04 -0800636 ENSURE_HAS_CAP(env, can_generate_breakpoint_events);
Alex Lighta26e3492017-06-27 17:55:37 -0700637 return BreakpointUtil::ClearBreakpoint(env, method, location);
Alex Light49948e92016-08-11 15:35:28 -0700638 }
639
Alex Light084fa372017-06-16 08:58:34 -0700640 static jvmtiError SetFieldAccessWatch(jvmtiEnv* env, jclass klass, jfieldID field) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700641 ENSURE_VALID_ENV(env);
Alex Light9db679d2017-01-25 15:28:04 -0800642 ENSURE_HAS_CAP(env, can_generate_field_access_events);
Alex Light084fa372017-06-16 08:58:34 -0700643 return FieldUtil::SetFieldAccessWatch(env, klass, field);
Alex Light49948e92016-08-11 15:35:28 -0700644 }
645
Alex Light084fa372017-06-16 08:58:34 -0700646 static jvmtiError ClearFieldAccessWatch(jvmtiEnv* env, jclass klass, jfieldID field) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700647 ENSURE_VALID_ENV(env);
Alex Light9db679d2017-01-25 15:28:04 -0800648 ENSURE_HAS_CAP(env, can_generate_field_access_events);
Alex Light084fa372017-06-16 08:58:34 -0700649 return FieldUtil::ClearFieldAccessWatch(env, klass, field);
Alex Light49948e92016-08-11 15:35:28 -0700650 }
651
Alex Light084fa372017-06-16 08:58:34 -0700652 static jvmtiError SetFieldModificationWatch(jvmtiEnv* env, jclass klass, jfieldID field) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700653 ENSURE_VALID_ENV(env);
Alex Light9db679d2017-01-25 15:28:04 -0800654 ENSURE_HAS_CAP(env, can_generate_field_modification_events);
Alex Light084fa372017-06-16 08:58:34 -0700655 return FieldUtil::SetFieldModificationWatch(env, klass, field);
Alex Light49948e92016-08-11 15:35:28 -0700656 }
657
Alex Light084fa372017-06-16 08:58:34 -0700658 static jvmtiError ClearFieldModificationWatch(jvmtiEnv* env, jclass klass, jfieldID field) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700659 ENSURE_VALID_ENV(env);
Alex Light9db679d2017-01-25 15:28:04 -0800660 ENSURE_HAS_CAP(env, can_generate_field_modification_events);
Alex Light084fa372017-06-16 08:58:34 -0700661 return FieldUtil::ClearFieldModificationWatch(env, klass, field);
Alex Light49948e92016-08-11 15:35:28 -0700662 }
663
664 static jvmtiError GetLoadedClasses(jvmtiEnv* env, jint* class_count_ptr, jclass** classes_ptr) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700665 ENSURE_VALID_ENV(env);
Andreas Gampede19eb92017-02-24 16:21:18 -0800666 HeapUtil heap_util(ArtJvmTiEnv::AsArtJvmTiEnv(env)->object_tag_table.get());
Andreas Gampeaa8b60c2016-10-12 12:51:25 -0700667 return heap_util.GetLoadedClasses(env, class_count_ptr, classes_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700668 }
669
670 static jvmtiError GetClassLoaderClasses(jvmtiEnv* env,
671 jobject initiating_loader,
672 jint* class_count_ptr,
673 jclass** classes_ptr) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700674 ENSURE_VALID_ENV(env);
Andreas Gampe70f16392017-01-16 14:20:10 -0800675 return ClassUtil::GetClassLoaderClasses(env, initiating_loader, class_count_ptr, classes_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700676 }
677
678 static jvmtiError GetClassSignature(jvmtiEnv* env,
679 jclass klass,
680 char** signature_ptr,
681 char** generic_ptr) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700682 ENSURE_VALID_ENV(env);
Andreas Gampee492ae32016-10-28 19:34:57 -0700683 return ClassUtil::GetClassSignature(env, klass, signature_ptr, generic_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700684 }
685
686 static jvmtiError GetClassStatus(jvmtiEnv* env, jclass klass, jint* status_ptr) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700687 ENSURE_VALID_ENV(env);
Andreas Gampeff9d2092017-01-06 09:12:49 -0800688 return ClassUtil::GetClassStatus(env, klass, status_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700689 }
690
Alex Light6fa7b812017-06-16 09:04:29 -0700691 static jvmtiError GetSourceFileName(jvmtiEnv* env, jclass klass, char** source_name_ptr) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700692 ENSURE_VALID_ENV(env);
Alex Light9db679d2017-01-25 15:28:04 -0800693 ENSURE_HAS_CAP(env, can_get_source_file_name);
Alex Light6fa7b812017-06-16 09:04:29 -0700694 return ClassUtil::GetSourceFileName(env, klass, source_name_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700695 }
696
697 static jvmtiError GetClassModifiers(jvmtiEnv* env, jclass klass, jint* modifiers_ptr) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700698 ENSURE_VALID_ENV(env);
Andreas Gampe64013e52017-01-06 13:07:19 -0800699 return ClassUtil::GetClassModifiers(env, klass, modifiers_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700700 }
701
702 static jvmtiError GetClassMethods(jvmtiEnv* env,
703 jclass klass,
704 jint* method_count_ptr,
705 jmethodID** methods_ptr) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700706 ENSURE_VALID_ENV(env);
Andreas Gampe18fee4d2017-01-06 11:36:35 -0800707 return ClassUtil::GetClassMethods(env, klass, method_count_ptr, methods_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700708 }
709
710 static jvmtiError GetClassFields(jvmtiEnv* env,
711 jclass klass,
712 jint* field_count_ptr,
713 jfieldID** fields_ptr) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700714 ENSURE_VALID_ENV(env);
Andreas Gampeac587272017-01-05 15:21:34 -0800715 return ClassUtil::GetClassFields(env, klass, field_count_ptr, fields_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700716 }
717
718 static jvmtiError GetImplementedInterfaces(jvmtiEnv* env,
719 jclass klass,
720 jint* interface_count_ptr,
721 jclass** interfaces_ptr) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700722 ENSURE_VALID_ENV(env);
Andreas Gampe8b07e472017-01-06 14:20:39 -0800723 return ClassUtil::GetImplementedInterfaces(env, klass, interface_count_ptr, interfaces_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700724 }
725
726 static jvmtiError GetClassVersionNumbers(jvmtiEnv* env,
727 jclass klass,
728 jint* minor_version_ptr,
729 jint* major_version_ptr) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700730 ENSURE_VALID_ENV(env);
Andreas Gampe812a2442017-01-19 22:04:46 -0800731 return ClassUtil::GetClassVersionNumbers(env, klass, minor_version_ptr, major_version_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700732 }
733
734 static jvmtiError GetConstantPool(jvmtiEnv* env,
Alex Light6a3fd512017-02-27 14:34:32 -0800735 jclass klass ATTRIBUTE_UNUSED,
736 jint* constant_pool_count_ptr ATTRIBUTE_UNUSED,
737 jint* constant_pool_byte_count_ptr ATTRIBUTE_UNUSED,
738 unsigned char** constant_pool_bytes_ptr ATTRIBUTE_UNUSED) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700739 ENSURE_VALID_ENV(env);
Alex Light9db679d2017-01-25 15:28:04 -0800740 ENSURE_HAS_CAP(env, can_get_constant_pool);
Alex Light49948e92016-08-11 15:35:28 -0700741 return ERR(NOT_IMPLEMENTED);
742 }
743
744 static jvmtiError IsInterface(jvmtiEnv* env, jclass klass, jboolean* is_interface_ptr) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700745 ENSURE_VALID_ENV(env);
Andreas Gampe4fd66ec2017-01-05 14:42:13 -0800746 return ClassUtil::IsInterface(env, klass, is_interface_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700747 }
748
749 static jvmtiError IsArrayClass(jvmtiEnv* env,
750 jclass klass,
751 jboolean* is_array_class_ptr) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700752 ENSURE_VALID_ENV(env);
Andreas Gampe4fd66ec2017-01-05 14:42:13 -0800753 return ClassUtil::IsArrayClass(env, klass, is_array_class_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700754 }
755
756 static jvmtiError IsModifiableClass(jvmtiEnv* env,
757 jclass klass,
758 jboolean* is_modifiable_class_ptr) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700759 ENSURE_VALID_ENV(env);
Alex Lighte4a88632017-01-10 07:41:24 -0800760 return Redefiner::IsModifiableClass(env, klass, is_modifiable_class_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700761 }
762
763 static jvmtiError GetClassLoader(jvmtiEnv* env, jclass klass, jobject* classloader_ptr) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700764 ENSURE_VALID_ENV(env);
Andreas Gampe8f5b6032017-01-06 15:50:55 -0800765 return ClassUtil::GetClassLoader(env, klass, classloader_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700766 }
767
768 static jvmtiError GetSourceDebugExtension(jvmtiEnv* env,
Alex Light6fa7b812017-06-16 09:04:29 -0700769 jclass klass,
770 char** source_debug_extension_ptr) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700771 ENSURE_VALID_ENV(env);
Alex Light9db679d2017-01-25 15:28:04 -0800772 ENSURE_HAS_CAP(env, can_get_source_debug_extension);
Alex Light6fa7b812017-06-16 09:04:29 -0700773 return ClassUtil::GetSourceDebugExtension(env, klass, source_debug_extension_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700774 }
775
776 static jvmtiError RetransformClasses(jvmtiEnv* env, jint class_count, const jclass* classes) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700777 ENSURE_VALID_ENV(env);
Alex Light9db679d2017-01-25 15:28:04 -0800778 ENSURE_HAS_CAP(env, can_retransform_classes);
Alex Light6ac57502017-01-19 15:05:06 -0800779 std::string error_msg;
780 jvmtiError res = Transformer::RetransformClasses(ArtJvmTiEnv::AsArtJvmTiEnv(env),
Alex Light0e841182018-02-12 17:42:50 +0000781 gEventHandler,
Alex Light6ac57502017-01-19 15:05:06 -0800782 art::Runtime::Current(),
783 art::Thread::Current(),
784 class_count,
785 classes,
786 &error_msg);
787 if (res != OK) {
788 LOG(WARNING) << "FAILURE TO RETRANFORM " << error_msg;
789 }
790 return res;
Alex Light49948e92016-08-11 15:35:28 -0700791 }
792
793 static jvmtiError RedefineClasses(jvmtiEnv* env,
794 jint class_count,
795 const jvmtiClassDefinition* class_definitions) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700796 ENSURE_VALID_ENV(env);
Alex Light9db679d2017-01-25 15:28:04 -0800797 ENSURE_HAS_CAP(env, can_redefine_classes);
Alex Light0e692732017-01-10 15:00:05 -0800798 std::string error_msg;
799 jvmtiError res = Redefiner::RedefineClasses(ArtJvmTiEnv::AsArtJvmTiEnv(env),
Alex Light0e841182018-02-12 17:42:50 +0000800 gEventHandler,
Alex Light0e692732017-01-10 15:00:05 -0800801 art::Runtime::Current(),
802 art::Thread::Current(),
803 class_count,
804 class_definitions,
805 &error_msg);
806 if (res != OK) {
807 LOG(WARNING) << "FAILURE TO REDEFINE " << error_msg;
808 }
809 return res;
Alex Light49948e92016-08-11 15:35:28 -0700810 }
811
812 static jvmtiError GetObjectSize(jvmtiEnv* env, jobject object, jlong* size_ptr) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700813 ENSURE_VALID_ENV(env);
Andreas Gampe50a4e492017-01-06 18:00:20 -0800814 return ObjectUtil::GetObjectSize(env, object, size_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700815 }
816
817 static jvmtiError GetObjectHashCode(jvmtiEnv* env, jobject object, jint* hash_code_ptr) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700818 ENSURE_VALID_ENV(env);
Andreas Gampe50a4e492017-01-06 18:00:20 -0800819 return ObjectUtil::GetObjectHashCode(env, object, hash_code_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700820 }
821
822 static jvmtiError GetObjectMonitorUsage(jvmtiEnv* env,
Alex Lightce568642017-09-05 16:54:25 -0700823 jobject object,
824 jvmtiMonitorUsage* info_ptr) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700825 ENSURE_VALID_ENV(env);
Alex Light9db679d2017-01-25 15:28:04 -0800826 ENSURE_HAS_CAP(env, can_get_monitor_info);
Alex Lightce568642017-09-05 16:54:25 -0700827 return ObjectUtil::GetObjectMonitorUsage(env, object, info_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700828 }
829
830 static jvmtiError GetFieldName(jvmtiEnv* env,
831 jclass klass,
832 jfieldID field,
833 char** name_ptr,
834 char** signature_ptr,
835 char** generic_ptr) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700836 ENSURE_VALID_ENV(env);
Andreas Gampeab2f0d02017-01-05 17:23:45 -0800837 return FieldUtil::GetFieldName(env, klass, field, name_ptr, signature_ptr, generic_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700838 }
839
840 static jvmtiError GetFieldDeclaringClass(jvmtiEnv* env,
841 jclass klass,
842 jfieldID field,
843 jclass* declaring_class_ptr) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700844 ENSURE_VALID_ENV(env);
Andreas Gampeab2f0d02017-01-05 17:23:45 -0800845 return FieldUtil::GetFieldDeclaringClass(env, klass, field, declaring_class_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700846 }
847
848 static jvmtiError GetFieldModifiers(jvmtiEnv* env,
849 jclass klass,
850 jfieldID field,
851 jint* modifiers_ptr) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700852 ENSURE_VALID_ENV(env);
Andreas Gampeab2f0d02017-01-05 17:23:45 -0800853 return FieldUtil::GetFieldModifiers(env, klass, field, modifiers_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700854 }
855
856 static jvmtiError IsFieldSynthetic(jvmtiEnv* env,
857 jclass klass,
858 jfieldID field,
859 jboolean* is_synthetic_ptr) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700860 ENSURE_VALID_ENV(env);
Alex Light9db679d2017-01-25 15:28:04 -0800861 ENSURE_HAS_CAP(env, can_get_synthetic_attribute);
Andreas Gampeab2f0d02017-01-05 17:23:45 -0800862 return FieldUtil::IsFieldSynthetic(env, klass, field, is_synthetic_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700863 }
864
865 static jvmtiError GetMethodName(jvmtiEnv* env,
866 jmethodID method,
867 char** name_ptr,
868 char** signature_ptr,
869 char** generic_ptr) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700870 ENSURE_VALID_ENV(env);
Andreas Gampe3c252f02016-10-27 18:25:17 -0700871 return MethodUtil::GetMethodName(env, method, name_ptr, signature_ptr, generic_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700872 }
873
874 static jvmtiError GetMethodDeclaringClass(jvmtiEnv* env,
875 jmethodID method,
876 jclass* declaring_class_ptr) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700877 ENSURE_VALID_ENV(env);
Andreas Gampe368a2082016-10-28 17:33:13 -0700878 return MethodUtil::GetMethodDeclaringClass(env, method, declaring_class_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700879 }
880
881 static jvmtiError GetMethodModifiers(jvmtiEnv* env,
882 jmethodID method,
883 jint* modifiers_ptr) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700884 ENSURE_VALID_ENV(env);
Andreas Gampe36bcd4f2016-10-28 18:07:18 -0700885 return MethodUtil::GetMethodModifiers(env, method, modifiers_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700886 }
887
888 static jvmtiError GetMaxLocals(jvmtiEnv* env,
889 jmethodID method,
890 jint* max_ptr) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700891 ENSURE_VALID_ENV(env);
Andreas Gampef71832e2017-01-09 11:38:04 -0800892 return MethodUtil::GetMaxLocals(env, method, max_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700893 }
894
895 static jvmtiError GetArgumentsSize(jvmtiEnv* env,
896 jmethodID method,
897 jint* size_ptr) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700898 ENSURE_VALID_ENV(env);
Andreas Gampef71832e2017-01-09 11:38:04 -0800899 return MethodUtil::GetArgumentsSize(env, method, size_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700900 }
901
902 static jvmtiError GetLineNumberTable(jvmtiEnv* env,
903 jmethodID method,
904 jint* entry_count_ptr,
905 jvmtiLineNumberEntry** table_ptr) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700906 ENSURE_VALID_ENV(env);
Alex Light9db679d2017-01-25 15:28:04 -0800907 ENSURE_HAS_CAP(env, can_get_line_numbers);
Andreas Gampeda3e5612016-12-13 19:00:53 -0800908 return MethodUtil::GetLineNumberTable(env, method, entry_count_ptr, table_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700909 }
910
911 static jvmtiError GetMethodLocation(jvmtiEnv* env,
912 jmethodID method,
913 jlocation* start_location_ptr,
914 jlocation* end_location_ptr) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700915 ENSURE_VALID_ENV(env);
Andreas Gampef71832e2017-01-09 11:38:04 -0800916 return MethodUtil::GetMethodLocation(env, method, start_location_ptr, end_location_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700917 }
918
919 static jvmtiError GetLocalVariableTable(jvmtiEnv* env,
Alex Lightce68cc62017-07-26 10:30:38 -0700920 jmethodID method,
921 jint* entry_count_ptr,
922 jvmtiLocalVariableEntry** table_ptr) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700923 ENSURE_VALID_ENV(env);
Alex Light9db679d2017-01-25 15:28:04 -0800924 ENSURE_HAS_CAP(env, can_access_local_variables);
Alex Lightce68cc62017-07-26 10:30:38 -0700925 return MethodUtil::GetLocalVariableTable(env, method, entry_count_ptr, table_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700926 }
927
928 static jvmtiError GetBytecodes(jvmtiEnv* env,
Alex Light4c174282017-07-05 10:18:18 -0700929 jmethodID method,
930 jint* bytecode_count_ptr,
931 unsigned char** bytecodes_ptr) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700932 ENSURE_VALID_ENV(env);
Alex Light9db679d2017-01-25 15:28:04 -0800933 ENSURE_HAS_CAP(env, can_get_bytecodes);
Alex Light4c174282017-07-05 10:18:18 -0700934 return MethodUtil::GetBytecodes(env, method, bytecode_count_ptr, bytecodes_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700935 }
936
937 static jvmtiError IsMethodNative(jvmtiEnv* env, jmethodID method, jboolean* is_native_ptr) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700938 ENSURE_VALID_ENV(env);
Andreas Gampefdeef522017-01-09 14:40:25 -0800939 return MethodUtil::IsMethodNative(env, method, is_native_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700940 }
941
942 static jvmtiError IsMethodSynthetic(jvmtiEnv* env, jmethodID method, jboolean* is_synthetic_ptr) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700943 ENSURE_VALID_ENV(env);
Alex Light9db679d2017-01-25 15:28:04 -0800944 ENSURE_HAS_CAP(env, can_get_synthetic_attribute);
Andreas Gampefdeef522017-01-09 14:40:25 -0800945 return MethodUtil::IsMethodSynthetic(env, method, is_synthetic_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700946 }
947
948 static jvmtiError IsMethodObsolete(jvmtiEnv* env, jmethodID method, jboolean* is_obsolete_ptr) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700949 ENSURE_VALID_ENV(env);
Andreas Gampefdeef522017-01-09 14:40:25 -0800950 return MethodUtil::IsMethodObsolete(env, method, is_obsolete_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700951 }
952
Alex Light6a3fd512017-02-27 14:34:32 -0800953 static jvmtiError SetNativeMethodPrefix(jvmtiEnv* env, const char* prefix ATTRIBUTE_UNUSED) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700954 ENSURE_VALID_ENV(env);
Alex Light9db679d2017-01-25 15:28:04 -0800955 ENSURE_HAS_CAP(env, can_set_native_method_prefix);
Alex Light49948e92016-08-11 15:35:28 -0700956 return ERR(NOT_IMPLEMENTED);
957 }
958
Alex Light6a3fd512017-02-27 14:34:32 -0800959 static jvmtiError SetNativeMethodPrefixes(jvmtiEnv* env,
960 jint prefix_count ATTRIBUTE_UNUSED,
961 char** prefixes ATTRIBUTE_UNUSED) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700962 ENSURE_VALID_ENV(env);
Alex Light9db679d2017-01-25 15:28:04 -0800963 ENSURE_HAS_CAP(env, can_set_native_method_prefix);
Alex Light49948e92016-08-11 15:35:28 -0700964 return ERR(NOT_IMPLEMENTED);
965 }
966
967 static jvmtiError CreateRawMonitor(jvmtiEnv* env, const char* name, jrawMonitorID* monitor_ptr) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700968 ENSURE_VALID_ENV(env);
Andreas Gampe319dbe82017-01-09 16:42:21 -0800969 return MonitorUtil::CreateRawMonitor(env, name, monitor_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700970 }
971
972 static jvmtiError DestroyRawMonitor(jvmtiEnv* env, jrawMonitorID monitor) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700973 ENSURE_VALID_ENV(env);
Andreas Gampe319dbe82017-01-09 16:42:21 -0800974 return MonitorUtil::DestroyRawMonitor(env, monitor);
Alex Light49948e92016-08-11 15:35:28 -0700975 }
976
977 static jvmtiError RawMonitorEnter(jvmtiEnv* env, jrawMonitorID monitor) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700978 ENSURE_VALID_ENV(env);
Andreas Gampe319dbe82017-01-09 16:42:21 -0800979 return MonitorUtil::RawMonitorEnter(env, monitor);
Alex Light49948e92016-08-11 15:35:28 -0700980 }
981
982 static jvmtiError RawMonitorExit(jvmtiEnv* env, jrawMonitorID monitor) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700983 ENSURE_VALID_ENV(env);
Andreas Gampe319dbe82017-01-09 16:42:21 -0800984 return MonitorUtil::RawMonitorExit(env, monitor);
Alex Light49948e92016-08-11 15:35:28 -0700985 }
986
987 static jvmtiError RawMonitorWait(jvmtiEnv* env, jrawMonitorID monitor, jlong millis) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700988 ENSURE_VALID_ENV(env);
Andreas Gampe319dbe82017-01-09 16:42:21 -0800989 return MonitorUtil::RawMonitorWait(env, monitor, millis);
Alex Light49948e92016-08-11 15:35:28 -0700990 }
991
992 static jvmtiError RawMonitorNotify(jvmtiEnv* env, jrawMonitorID monitor) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700993 ENSURE_VALID_ENV(env);
Andreas Gampe319dbe82017-01-09 16:42:21 -0800994 return MonitorUtil::RawMonitorNotify(env, monitor);
Alex Light49948e92016-08-11 15:35:28 -0700995 }
996
997 static jvmtiError RawMonitorNotifyAll(jvmtiEnv* env, jrawMonitorID monitor) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700998 ENSURE_VALID_ENV(env);
Andreas Gampe319dbe82017-01-09 16:42:21 -0800999 return MonitorUtil::RawMonitorNotifyAll(env, monitor);
Alex Light49948e92016-08-11 15:35:28 -07001000 }
1001
1002 static jvmtiError SetJNIFunctionTable(jvmtiEnv* env, const jniNativeInterface* function_table) {
Alex Light1edc8cf2017-03-24 14:22:56 -07001003 ENSURE_VALID_ENV(env);
Andreas Gampe6f8e4f02017-01-16 18:18:14 -08001004 return JNIUtil::SetJNIFunctionTable(env, function_table);
Alex Light49948e92016-08-11 15:35:28 -07001005 }
1006
1007 static jvmtiError GetJNIFunctionTable(jvmtiEnv* env, jniNativeInterface** function_table) {
Alex Light1edc8cf2017-03-24 14:22:56 -07001008 ENSURE_VALID_ENV(env);
Andreas Gampe6f8e4f02017-01-16 18:18:14 -08001009 return JNIUtil::GetJNIFunctionTable(env, function_table);
Alex Light49948e92016-08-11 15:35:28 -07001010 }
1011
Andreas Gampe77708d92016-10-07 11:48:21 -07001012 // TODO: This will require locking, so that an agent can't remove callbacks when we're dispatching
1013 // an event.
Alex Light49948e92016-08-11 15:35:28 -07001014 static jvmtiError SetEventCallbacks(jvmtiEnv* env,
1015 const jvmtiEventCallbacks* callbacks,
1016 jint size_of_callbacks) {
Alex Lighte6574242016-08-17 09:56:24 -07001017 ENSURE_VALID_ENV(env);
Andreas Gampe77708d92016-10-07 11:48:21 -07001018 if (size_of_callbacks < 0) {
1019 return ERR(ILLEGAL_ARGUMENT);
1020 }
1021
1022 if (callbacks == nullptr) {
1023 ArtJvmTiEnv::AsArtJvmTiEnv(env)->event_callbacks.reset();
1024 return ERR(NONE);
1025 }
1026
Alex Light8c2b9292017-11-09 13:21:01 -08001027 // Lock the event_info_mutex_ while we replace the callbacks.
1028 ArtJvmTiEnv* art_env = ArtJvmTiEnv::AsArtJvmTiEnv(env);
1029 art::WriterMutexLock lk(art::Thread::Current(), art_env->event_info_mutex_);
1030 std::unique_ptr<ArtJvmtiEventCallbacks> tmp(new ArtJvmtiEventCallbacks());
1031 // Copy over the extension events.
1032 tmp->CopyExtensionsFrom(art_env->event_callbacks.get());
1033 // Never overwrite the extension events.
Andreas Gampe77708d92016-10-07 11:48:21 -07001034 size_t copy_size = std::min(sizeof(jvmtiEventCallbacks),
1035 static_cast<size_t>(size_of_callbacks));
1036 copy_size = art::RoundDown(copy_size, sizeof(void*));
Alex Light8c2b9292017-11-09 13:21:01 -08001037 // Copy non-extension events.
Andreas Gampe77708d92016-10-07 11:48:21 -07001038 memcpy(tmp.get(), callbacks, copy_size);
1039
Alex Light8c2b9292017-11-09 13:21:01 -08001040 // replace the event table.
1041 art_env->event_callbacks = std::move(tmp);
Andreas Gampe77708d92016-10-07 11:48:21 -07001042
1043 return ERR(NONE);
Alex Light49948e92016-08-11 15:35:28 -07001044 }
1045
1046 static jvmtiError SetEventNotificationMode(jvmtiEnv* env,
1047 jvmtiEventMode mode,
1048 jvmtiEvent event_type,
1049 jthread event_thread,
1050 ...) {
Alex Lighte6574242016-08-17 09:56:24 -07001051 ENSURE_VALID_ENV(env);
Andreas Gampe77708d92016-10-07 11:48:21 -07001052 art::Thread* art_thread = nullptr;
1053 if (event_thread != nullptr) {
Alex Light7ddc23d2017-09-22 15:33:41 -07001054 // TODO The locking around this call is less then what we really want.
Andreas Gampe77708d92016-10-07 11:48:21 -07001055 art::ScopedObjectAccess soa(art::Thread::Current());
1056 art::MutexLock mu(soa.Self(), *art::Locks::thread_list_lock_);
Alex Light7ddc23d2017-09-22 15:33:41 -07001057 jvmtiError err = ERR(INTERNAL);
1058 if (!ThreadUtil::GetAliveNativeThread(event_thread, soa, &art_thread, &err)) {
1059 return err;
1060 } else if (art_thread->IsStillStarting()) {
Andreas Gampe77708d92016-10-07 11:48:21 -07001061 return ERR(THREAD_NOT_ALIVE);
1062 }
1063 }
1064
Alex Light40d87f42017-01-18 10:27:06 -08001065 ArtJvmTiEnv* art_env = ArtJvmTiEnv::AsArtJvmTiEnv(env);
Alex Light0e841182018-02-12 17:42:50 +00001066 return gEventHandler->SetEvent(art_env,
1067 art_thread,
1068 GetArtJvmtiEvent(art_env, event_type),
1069 mode);
Alex Light49948e92016-08-11 15:35:28 -07001070 }
1071
Alex Light1edc8cf2017-03-24 14:22:56 -07001072 static jvmtiError GenerateEvents(jvmtiEnv* env,
Alex Light6a3fd512017-02-27 14:34:32 -08001073 jvmtiEvent event_type ATTRIBUTE_UNUSED) {
Alex Light1edc8cf2017-03-24 14:22:56 -07001074 ENSURE_VALID_ENV(env);
Alex Light6a3fd512017-02-27 14:34:32 -08001075 return OK;
Alex Light49948e92016-08-11 15:35:28 -07001076 }
1077
Alex Light1edc8cf2017-03-24 14:22:56 -07001078 static jvmtiError GetExtensionFunctions(jvmtiEnv* env,
Alex Light49948e92016-08-11 15:35:28 -07001079 jint* extension_count_ptr,
1080 jvmtiExtensionFunctionInfo** extensions) {
Alex Light1edc8cf2017-03-24 14:22:56 -07001081 ENSURE_VALID_ENV(env);
Andreas Gamped73aba42017-05-03 21:40:26 -07001082 ENSURE_NON_NULL(extension_count_ptr);
1083 ENSURE_NON_NULL(extensions);
Alex Light3f33c0a2017-11-08 10:17:37 -08001084 return ExtensionUtil::GetExtensionFunctions(env, extension_count_ptr, extensions);
Alex Light49948e92016-08-11 15:35:28 -07001085 }
1086
Alex Light1edc8cf2017-03-24 14:22:56 -07001087 static jvmtiError GetExtensionEvents(jvmtiEnv* env,
Alex Light49948e92016-08-11 15:35:28 -07001088 jint* extension_count_ptr,
1089 jvmtiExtensionEventInfo** extensions) {
Alex Light1edc8cf2017-03-24 14:22:56 -07001090 ENSURE_VALID_ENV(env);
Alex Light3f33c0a2017-11-08 10:17:37 -08001091 ENSURE_NON_NULL(extension_count_ptr);
1092 ENSURE_NON_NULL(extensions);
1093 return ExtensionUtil::GetExtensionEvents(env, extension_count_ptr, extensions);
Alex Light49948e92016-08-11 15:35:28 -07001094 }
1095
Alex Light1edc8cf2017-03-24 14:22:56 -07001096 static jvmtiError SetExtensionEventCallback(jvmtiEnv* env,
Alex Light3f33c0a2017-11-08 10:17:37 -08001097 jint extension_event_index,
1098 jvmtiExtensionEvent callback) {
Alex Light1edc8cf2017-03-24 14:22:56 -07001099 ENSURE_VALID_ENV(env);
Alex Light8c2b9292017-11-09 13:21:01 -08001100 return ExtensionUtil::SetExtensionEventCallback(env,
1101 extension_event_index,
1102 callback,
Alex Light0e841182018-02-12 17:42:50 +00001103 gEventHandler);
Alex Light49948e92016-08-11 15:35:28 -07001104 }
1105
Alex Light2ce6fc82017-12-18 16:42:36 -08001106#define FOR_ALL_CAPABILITIES(FUN) \
1107 FUN(can_tag_objects) \
1108 FUN(can_generate_field_modification_events) \
1109 FUN(can_generate_field_access_events) \
1110 FUN(can_get_bytecodes) \
1111 FUN(can_get_synthetic_attribute) \
1112 FUN(can_get_owned_monitor_info) \
1113 FUN(can_get_current_contended_monitor) \
1114 FUN(can_get_monitor_info) \
1115 FUN(can_pop_frame) \
1116 FUN(can_redefine_classes) \
1117 FUN(can_signal_thread) \
1118 FUN(can_get_source_file_name) \
1119 FUN(can_get_line_numbers) \
1120 FUN(can_get_source_debug_extension) \
1121 FUN(can_access_local_variables) \
1122 FUN(can_maintain_original_method_order) \
1123 FUN(can_generate_single_step_events) \
1124 FUN(can_generate_exception_events) \
1125 FUN(can_generate_frame_pop_events) \
1126 FUN(can_generate_breakpoint_events) \
1127 FUN(can_suspend) \
1128 FUN(can_redefine_any_class) \
1129 FUN(can_get_current_thread_cpu_time) \
1130 FUN(can_get_thread_cpu_time) \
1131 FUN(can_generate_method_entry_events) \
1132 FUN(can_generate_method_exit_events) \
1133 FUN(can_generate_all_class_hook_events) \
1134 FUN(can_generate_compiled_method_load_events) \
1135 FUN(can_generate_monitor_events) \
1136 FUN(can_generate_vm_object_alloc_events) \
1137 FUN(can_generate_native_method_bind_events) \
1138 FUN(can_generate_garbage_collection_events) \
1139 FUN(can_generate_object_free_events) \
1140 FUN(can_force_early_return) \
1141 FUN(can_get_owned_monitor_stack_depth_info) \
1142 FUN(can_get_constant_pool) \
1143 FUN(can_set_native_method_prefix) \
1144 FUN(can_retransform_classes) \
1145 FUN(can_retransform_any_class) \
1146 FUN(can_generate_resource_exhaustion_heap_events) \
1147 FUN(can_generate_resource_exhaustion_threads_events)
1148
Alex Light49948e92016-08-11 15:35:28 -07001149 static jvmtiError GetPotentialCapabilities(jvmtiEnv* env, jvmtiCapabilities* capabilities_ptr) {
Alex Lighte6574242016-08-17 09:56:24 -07001150 ENSURE_VALID_ENV(env);
1151 ENSURE_NON_NULL(capabilities_ptr);
1152 *capabilities_ptr = kPotentialCapabilities;
Alex Light2ce6fc82017-12-18 16:42:36 -08001153 if (UNLIKELY(!IsFullJvmtiAvailable())) {
1154#define REMOVE_NONDEBUGGABLE_UNSUPPORTED(e) \
1155 do { \
1156 if (kNonDebuggableUnsupportedCapabilities.e == 1) { \
1157 capabilities_ptr->e = 0; \
1158 } \
1159 } while (false);
1160
1161 FOR_ALL_CAPABILITIES(REMOVE_NONDEBUGGABLE_UNSUPPORTED);
1162#undef REMOVE_NONDEBUGGABLE_UNSUPPORTED
1163 }
Alex Lighte6574242016-08-17 09:56:24 -07001164 return OK;
Alex Light49948e92016-08-11 15:35:28 -07001165 }
1166
1167 static jvmtiError AddCapabilities(jvmtiEnv* env, const jvmtiCapabilities* capabilities_ptr) {
Alex Lighte6574242016-08-17 09:56:24 -07001168 ENSURE_VALID_ENV(env);
1169 ENSURE_NON_NULL(capabilities_ptr);
1170 ArtJvmTiEnv* art_env = static_cast<ArtJvmTiEnv*>(env);
1171 jvmtiError ret = OK;
Alex Light34d8e082017-03-27 09:50:36 -07001172 jvmtiCapabilities changed = {};
1173 jvmtiCapabilities potential_capabilities = {};
Alex Light1d224962017-02-27 10:26:35 -08001174 ret = env->GetPotentialCapabilities(&potential_capabilities);
1175 if (ret != OK) {
1176 return ret;
1177 }
Alex Lighte6574242016-08-17 09:56:24 -07001178#define ADD_CAPABILITY(e) \
1179 do { \
1180 if (capabilities_ptr->e == 1) { \
Alex Light1d224962017-02-27 10:26:35 -08001181 if (potential_capabilities.e == 1) { \
Alex Light73afd322017-01-18 11:17:47 -08001182 if (art_env->capabilities.e != 1) { \
1183 art_env->capabilities.e = 1; \
1184 changed.e = 1; \
1185 }\
Alex Lighte6574242016-08-17 09:56:24 -07001186 } else { \
1187 ret = ERR(NOT_AVAILABLE); \
1188 } \
1189 } \
Alex Light2ce6fc82017-12-18 16:42:36 -08001190 } while (false);
Alex Lighte6574242016-08-17 09:56:24 -07001191
Alex Light2ce6fc82017-12-18 16:42:36 -08001192 FOR_ALL_CAPABILITIES(ADD_CAPABILITY);
Alex Lighte6574242016-08-17 09:56:24 -07001193#undef ADD_CAPABILITY
Alex Light0e841182018-02-12 17:42:50 +00001194 gEventHandler->HandleChangedCapabilities(ArtJvmTiEnv::AsArtJvmTiEnv(env),
1195 changed,
1196 /*added*/true);
Alex Lighte6574242016-08-17 09:56:24 -07001197 return ret;
Alex Light49948e92016-08-11 15:35:28 -07001198 }
1199
1200 static jvmtiError RelinquishCapabilities(jvmtiEnv* env,
1201 const jvmtiCapabilities* capabilities_ptr) {
Alex Lighte6574242016-08-17 09:56:24 -07001202 ENSURE_VALID_ENV(env);
1203 ENSURE_NON_NULL(capabilities_ptr);
1204 ArtJvmTiEnv* art_env = reinterpret_cast<ArtJvmTiEnv*>(env);
Alex Light34d8e082017-03-27 09:50:36 -07001205 jvmtiCapabilities changed = {};
Alex Lighte6574242016-08-17 09:56:24 -07001206#define DEL_CAPABILITY(e) \
1207 do { \
1208 if (capabilities_ptr->e == 1) { \
Alex Light73afd322017-01-18 11:17:47 -08001209 if (art_env->capabilities.e == 1) { \
1210 art_env->capabilities.e = 0;\
1211 changed.e = 1; \
1212 } \
Alex Lighte6574242016-08-17 09:56:24 -07001213 } \
Alex Light2ce6fc82017-12-18 16:42:36 -08001214 } while (false);
Alex Lighte6574242016-08-17 09:56:24 -07001215
Alex Light2ce6fc82017-12-18 16:42:36 -08001216 FOR_ALL_CAPABILITIES(DEL_CAPABILITY);
Alex Lighte6574242016-08-17 09:56:24 -07001217#undef DEL_CAPABILITY
Alex Light0e841182018-02-12 17:42:50 +00001218 gEventHandler->HandleChangedCapabilities(ArtJvmTiEnv::AsArtJvmTiEnv(env),
1219 changed,
1220 /*added*/false);
Alex Lighte6574242016-08-17 09:56:24 -07001221 return OK;
Alex Light49948e92016-08-11 15:35:28 -07001222 }
1223
Alex Light2ce6fc82017-12-18 16:42:36 -08001224#undef FOR_ALL_CAPABILITIES
1225
Alex Light49948e92016-08-11 15:35:28 -07001226 static jvmtiError GetCapabilities(jvmtiEnv* env, jvmtiCapabilities* capabilities_ptr) {
Alex Lighte6574242016-08-17 09:56:24 -07001227 ENSURE_VALID_ENV(env);
1228 ENSURE_NON_NULL(capabilities_ptr);
1229 ArtJvmTiEnv* artenv = reinterpret_cast<ArtJvmTiEnv*>(env);
1230 *capabilities_ptr = artenv->capabilities;
1231 return OK;
Alex Light49948e92016-08-11 15:35:28 -07001232 }
1233
Alex Light6a3fd512017-02-27 14:34:32 -08001234 static jvmtiError GetCurrentThreadCpuTimerInfo(jvmtiEnv* env,
1235 jvmtiTimerInfo* info_ptr ATTRIBUTE_UNUSED) {
Alex Light1edc8cf2017-03-24 14:22:56 -07001236 ENSURE_VALID_ENV(env);
Alex Light9db679d2017-01-25 15:28:04 -08001237 ENSURE_HAS_CAP(env, can_get_current_thread_cpu_time);
Alex Light49948e92016-08-11 15:35:28 -07001238 return ERR(NOT_IMPLEMENTED);
1239 }
1240
Alex Light6a3fd512017-02-27 14:34:32 -08001241 static jvmtiError GetCurrentThreadCpuTime(jvmtiEnv* env, jlong* nanos_ptr ATTRIBUTE_UNUSED) {
Alex Light1edc8cf2017-03-24 14:22:56 -07001242 ENSURE_VALID_ENV(env);
Alex Light9db679d2017-01-25 15:28:04 -08001243 ENSURE_HAS_CAP(env, can_get_current_thread_cpu_time);
Alex Light49948e92016-08-11 15:35:28 -07001244 return ERR(NOT_IMPLEMENTED);
1245 }
1246
Alex Light6a3fd512017-02-27 14:34:32 -08001247 static jvmtiError GetThreadCpuTimerInfo(jvmtiEnv* env,
1248 jvmtiTimerInfo* info_ptr ATTRIBUTE_UNUSED) {
Alex Light1edc8cf2017-03-24 14:22:56 -07001249 ENSURE_VALID_ENV(env);
Alex Light9db679d2017-01-25 15:28:04 -08001250 ENSURE_HAS_CAP(env, can_get_thread_cpu_time);
Alex Light49948e92016-08-11 15:35:28 -07001251 return ERR(NOT_IMPLEMENTED);
1252 }
1253
Alex Light6a3fd512017-02-27 14:34:32 -08001254 static jvmtiError GetThreadCpuTime(jvmtiEnv* env,
1255 jthread thread ATTRIBUTE_UNUSED,
1256 jlong* nanos_ptr ATTRIBUTE_UNUSED) {
Alex Light1edc8cf2017-03-24 14:22:56 -07001257 ENSURE_VALID_ENV(env);
Alex Light9db679d2017-01-25 15:28:04 -08001258 ENSURE_HAS_CAP(env, can_get_thread_cpu_time);
Alex Light49948e92016-08-11 15:35:28 -07001259 return ERR(NOT_IMPLEMENTED);
1260 }
1261
1262 static jvmtiError GetTimerInfo(jvmtiEnv* env, jvmtiTimerInfo* info_ptr) {
Alex Light1edc8cf2017-03-24 14:22:56 -07001263 ENSURE_VALID_ENV(env);
Andreas Gampe35bcf812017-01-13 16:24:17 -08001264 return TimerUtil::GetTimerInfo(env, info_ptr);
Alex Light49948e92016-08-11 15:35:28 -07001265 }
1266
1267 static jvmtiError GetTime(jvmtiEnv* env, jlong* nanos_ptr) {
Alex Light1edc8cf2017-03-24 14:22:56 -07001268 ENSURE_VALID_ENV(env);
Andreas Gampe35bcf812017-01-13 16:24:17 -08001269 return TimerUtil::GetTime(env, nanos_ptr);
Alex Light49948e92016-08-11 15:35:28 -07001270 }
1271
1272 static jvmtiError GetAvailableProcessors(jvmtiEnv* env, jint* processor_count_ptr) {
Alex Light1edc8cf2017-03-24 14:22:56 -07001273 ENSURE_VALID_ENV(env);
Andreas Gampe35bcf812017-01-13 16:24:17 -08001274 return TimerUtil::GetAvailableProcessors(env, processor_count_ptr);
Alex Light49948e92016-08-11 15:35:28 -07001275 }
1276
1277 static jvmtiError AddToBootstrapClassLoaderSearch(jvmtiEnv* env, const char* segment) {
Alex Light1edc8cf2017-03-24 14:22:56 -07001278 ENSURE_VALID_ENV(env);
Andreas Gampece7732b2017-01-17 15:50:26 -08001279 return SearchUtil::AddToBootstrapClassLoaderSearch(env, segment);
Alex Light49948e92016-08-11 15:35:28 -07001280 }
1281
1282 static jvmtiError AddToSystemClassLoaderSearch(jvmtiEnv* env, const char* segment) {
Alex Light1edc8cf2017-03-24 14:22:56 -07001283 ENSURE_VALID_ENV(env);
Andreas Gampece7732b2017-01-17 15:50:26 -08001284 return SearchUtil::AddToSystemClassLoaderSearch(env, segment);
Alex Light49948e92016-08-11 15:35:28 -07001285 }
1286
1287 static jvmtiError GetSystemProperties(jvmtiEnv* env, jint* count_ptr, char*** property_ptr) {
Alex Light1edc8cf2017-03-24 14:22:56 -07001288 ENSURE_VALID_ENV(env);
Andreas Gampe1bdaf732017-01-09 19:21:06 -08001289 return PropertiesUtil::GetSystemProperties(env, count_ptr, property_ptr);
Alex Light49948e92016-08-11 15:35:28 -07001290 }
1291
1292 static jvmtiError GetSystemProperty(jvmtiEnv* env, const char* property, char** value_ptr) {
Alex Light1edc8cf2017-03-24 14:22:56 -07001293 ENSURE_VALID_ENV(env);
Andreas Gampe1bdaf732017-01-09 19:21:06 -08001294 return PropertiesUtil::GetSystemProperty(env, property, value_ptr);
Alex Light49948e92016-08-11 15:35:28 -07001295 }
1296
1297 static jvmtiError SetSystemProperty(jvmtiEnv* env, const char* property, const char* value) {
Alex Light1edc8cf2017-03-24 14:22:56 -07001298 ENSURE_VALID_ENV(env);
Andreas Gampe1bdaf732017-01-09 19:21:06 -08001299 return PropertiesUtil::SetSystemProperty(env, property, value);
Alex Light49948e92016-08-11 15:35:28 -07001300 }
1301
1302 static jvmtiError GetPhase(jvmtiEnv* env, jvmtiPhase* phase_ptr) {
Alex Light1edc8cf2017-03-24 14:22:56 -07001303 ENSURE_VALID_ENV(env);
Andreas Gampe96eca782017-01-19 19:45:30 -08001304 return PhaseUtil::GetPhase(env, phase_ptr);
Alex Light49948e92016-08-11 15:35:28 -07001305 }
1306
1307 static jvmtiError DisposeEnvironment(jvmtiEnv* env) {
Alex Lighte6574242016-08-17 09:56:24 -07001308 ENSURE_VALID_ENV(env);
Alex Light092a4042017-07-12 08:46:44 -07001309 ArtJvmTiEnv* tienv = ArtJvmTiEnv::AsArtJvmTiEnv(env);
Alex Light0e841182018-02-12 17:42:50 +00001310 gEventHandler->RemoveArtJvmTiEnv(tienv);
Alex Light092a4042017-07-12 08:46:44 -07001311 art::Runtime::Current()->RemoveSystemWeakHolder(tienv->object_tag_table.get());
1312 ThreadUtil::RemoveEnvironment(tienv);
1313 delete tienv;
Alex Light49948e92016-08-11 15:35:28 -07001314 return OK;
1315 }
1316
1317 static jvmtiError SetEnvironmentLocalStorage(jvmtiEnv* env, const void* data) {
Alex Lighte6574242016-08-17 09:56:24 -07001318 ENSURE_VALID_ENV(env);
Alex Light49948e92016-08-11 15:35:28 -07001319 reinterpret_cast<ArtJvmTiEnv*>(env)->local_data = const_cast<void*>(data);
1320 return OK;
1321 }
1322
1323 static jvmtiError GetEnvironmentLocalStorage(jvmtiEnv* env, void** data_ptr) {
Alex Lighte6574242016-08-17 09:56:24 -07001324 ENSURE_VALID_ENV(env);
Alex Light49948e92016-08-11 15:35:28 -07001325 *data_ptr = reinterpret_cast<ArtJvmTiEnv*>(env)->local_data;
1326 return OK;
1327 }
1328
1329 static jvmtiError GetVersionNumber(jvmtiEnv* env, jint* version_ptr) {
Alex Lighte6574242016-08-17 09:56:24 -07001330 ENSURE_VALID_ENV(env);
Alex Light2ce6fc82017-12-18 16:42:36 -08001331 *version_ptr = ArtJvmTiEnv::AsArtJvmTiEnv(env)->ti_version;
Alex Light49948e92016-08-11 15:35:28 -07001332 return OK;
1333 }
1334
1335 static jvmtiError GetErrorName(jvmtiEnv* env, jvmtiError error, char** name_ptr) {
Alex Lighte6574242016-08-17 09:56:24 -07001336 ENSURE_NON_NULL(name_ptr);
Andreas Gampe95c466d2017-05-08 14:50:47 -07001337 auto copy_fn = [&](const char* name_cstr) {
1338 jvmtiError res;
1339 JvmtiUniquePtr<char[]> copy = CopyString(env, name_cstr, &res);
1340 if (copy == nullptr) {
1341 *name_ptr = nullptr;
1342 return res;
1343 } else {
1344 *name_ptr = copy.release();
1345 return OK;
1346 }
1347 };
Alex Light49948e92016-08-11 15:35:28 -07001348 switch (error) {
Andreas Gampe95c466d2017-05-08 14:50:47 -07001349#define ERROR_CASE(e) case (JVMTI_ERROR_ ## e) : \
1350 return copy_fn("JVMTI_ERROR_"#e);
Alex Light49948e92016-08-11 15:35:28 -07001351 ERROR_CASE(NONE);
1352 ERROR_CASE(INVALID_THREAD);
1353 ERROR_CASE(INVALID_THREAD_GROUP);
1354 ERROR_CASE(INVALID_PRIORITY);
1355 ERROR_CASE(THREAD_NOT_SUSPENDED);
Andreas Gampe95c466d2017-05-08 14:50:47 -07001356 ERROR_CASE(THREAD_SUSPENDED);
Alex Light49948e92016-08-11 15:35:28 -07001357 ERROR_CASE(THREAD_NOT_ALIVE);
1358 ERROR_CASE(INVALID_OBJECT);
1359 ERROR_CASE(INVALID_CLASS);
1360 ERROR_CASE(CLASS_NOT_PREPARED);
1361 ERROR_CASE(INVALID_METHODID);
1362 ERROR_CASE(INVALID_LOCATION);
1363 ERROR_CASE(INVALID_FIELDID);
1364 ERROR_CASE(NO_MORE_FRAMES);
1365 ERROR_CASE(OPAQUE_FRAME);
1366 ERROR_CASE(TYPE_MISMATCH);
1367 ERROR_CASE(INVALID_SLOT);
1368 ERROR_CASE(DUPLICATE);
1369 ERROR_CASE(NOT_FOUND);
1370 ERROR_CASE(INVALID_MONITOR);
1371 ERROR_CASE(NOT_MONITOR_OWNER);
1372 ERROR_CASE(INTERRUPT);
1373 ERROR_CASE(INVALID_CLASS_FORMAT);
1374 ERROR_CASE(CIRCULAR_CLASS_DEFINITION);
1375 ERROR_CASE(FAILS_VERIFICATION);
1376 ERROR_CASE(UNSUPPORTED_REDEFINITION_METHOD_ADDED);
1377 ERROR_CASE(UNSUPPORTED_REDEFINITION_SCHEMA_CHANGED);
1378 ERROR_CASE(INVALID_TYPESTATE);
1379 ERROR_CASE(UNSUPPORTED_REDEFINITION_HIERARCHY_CHANGED);
1380 ERROR_CASE(UNSUPPORTED_REDEFINITION_METHOD_DELETED);
1381 ERROR_CASE(UNSUPPORTED_VERSION);
1382 ERROR_CASE(NAMES_DONT_MATCH);
1383 ERROR_CASE(UNSUPPORTED_REDEFINITION_CLASS_MODIFIERS_CHANGED);
1384 ERROR_CASE(UNSUPPORTED_REDEFINITION_METHOD_MODIFIERS_CHANGED);
1385 ERROR_CASE(UNMODIFIABLE_CLASS);
1386 ERROR_CASE(NOT_AVAILABLE);
1387 ERROR_CASE(MUST_POSSESS_CAPABILITY);
1388 ERROR_CASE(NULL_POINTER);
1389 ERROR_CASE(ABSENT_INFORMATION);
1390 ERROR_CASE(INVALID_EVENT_TYPE);
1391 ERROR_CASE(ILLEGAL_ARGUMENT);
1392 ERROR_CASE(NATIVE_METHOD);
1393 ERROR_CASE(CLASS_LOADER_UNSUPPORTED);
1394 ERROR_CASE(OUT_OF_MEMORY);
1395 ERROR_CASE(ACCESS_DENIED);
1396 ERROR_CASE(WRONG_PHASE);
1397 ERROR_CASE(INTERNAL);
1398 ERROR_CASE(UNATTACHED_THREAD);
1399 ERROR_CASE(INVALID_ENVIRONMENT);
1400#undef ERROR_CASE
Alex Light49948e92016-08-11 15:35:28 -07001401 }
Andreas Gampe95c466d2017-05-08 14:50:47 -07001402
1403 return ERR(ILLEGAL_ARGUMENT);
Alex Light49948e92016-08-11 15:35:28 -07001404 }
1405
Alex Light1edc8cf2017-03-24 14:22:56 -07001406 static jvmtiError SetVerboseFlag(jvmtiEnv* env,
Alex Light6a3fd512017-02-27 14:34:32 -08001407 jvmtiVerboseFlag flag,
1408 jboolean value) {
Alex Light1edc8cf2017-03-24 14:22:56 -07001409 ENSURE_VALID_ENV(env);
Andreas Gampef37e3022017-01-13 17:54:46 -08001410 if (flag == jvmtiVerboseFlag::JVMTI_VERBOSE_OTHER) {
1411 // OTHER is special, as it's 0, so can't do a bit check.
1412 bool val = (value == JNI_TRUE) ? true : false;
1413
1414 art::gLogVerbosity.collector = val;
1415 art::gLogVerbosity.compiler = val;
1416 art::gLogVerbosity.deopt = val;
1417 art::gLogVerbosity.heap = val;
1418 art::gLogVerbosity.jdwp = val;
1419 art::gLogVerbosity.jit = val;
1420 art::gLogVerbosity.monitor = val;
1421 art::gLogVerbosity.oat = val;
1422 art::gLogVerbosity.profiler = val;
1423 art::gLogVerbosity.signals = val;
1424 art::gLogVerbosity.simulator = val;
1425 art::gLogVerbosity.startup = val;
1426 art::gLogVerbosity.third_party_jni = val;
1427 art::gLogVerbosity.threads = val;
1428 art::gLogVerbosity.verifier = val;
Andreas Gampe92d77202017-12-06 20:49:00 -08001429 // Do not set verifier-debug.
Andreas Gampef37e3022017-01-13 17:54:46 -08001430 art::gLogVerbosity.image = val;
1431
1432 // Note: can't switch systrace_lock_logging. That requires changing entrypoints.
1433
1434 art::gLogVerbosity.agents = val;
1435 } else {
1436 // Spec isn't clear whether "flag" is a mask or supposed to be single. We implement the mask
1437 // semantics.
1438 constexpr std::underlying_type<jvmtiVerboseFlag>::type kMask =
1439 jvmtiVerboseFlag::JVMTI_VERBOSE_GC |
1440 jvmtiVerboseFlag::JVMTI_VERBOSE_CLASS |
1441 jvmtiVerboseFlag::JVMTI_VERBOSE_JNI;
1442 if ((flag & ~kMask) != 0) {
1443 return ERR(ILLEGAL_ARGUMENT);
1444 }
1445
1446 bool val = (value == JNI_TRUE) ? true : false;
1447
1448 if ((flag & jvmtiVerboseFlag::JVMTI_VERBOSE_GC) != 0) {
1449 art::gLogVerbosity.gc = val;
1450 }
1451
1452 if ((flag & jvmtiVerboseFlag::JVMTI_VERBOSE_CLASS) != 0) {
1453 art::gLogVerbosity.class_linker = val;
1454 }
1455
1456 if ((flag & jvmtiVerboseFlag::JVMTI_VERBOSE_JNI) != 0) {
1457 art::gLogVerbosity.jni = val;
1458 }
1459 }
1460
1461 return ERR(NONE);
Alex Light49948e92016-08-11 15:35:28 -07001462 }
1463
Alex Light1edc8cf2017-03-24 14:22:56 -07001464 static jvmtiError GetJLocationFormat(jvmtiEnv* env, jvmtiJlocationFormat* format_ptr) {
1465 ENSURE_VALID_ENV(env);
Andreas Gampeacfc9572017-01-17 18:36:56 -08001466 // Report BCI as jlocation format. We report dex bytecode indices.
1467 if (format_ptr == nullptr) {
1468 return ERR(NULL_POINTER);
1469 }
1470 *format_ptr = jvmtiJlocationFormat::JVMTI_JLOCATION_JVMBCI;
1471 return ERR(NONE);
Alex Light49948e92016-08-11 15:35:28 -07001472 }
1473};
1474
1475static bool IsJvmtiVersion(jint version) {
1476 return version == JVMTI_VERSION_1 ||
1477 version == JVMTI_VERSION_1_0 ||
1478 version == JVMTI_VERSION_1_1 ||
1479 version == JVMTI_VERSION_1_2 ||
1480 version == JVMTI_VERSION;
1481}
1482
Andreas Gampede19eb92017-02-24 16:21:18 -08001483extern const jvmtiInterface_1 gJvmtiInterface;
Alex Light092a4042017-07-12 08:46:44 -07001484
Alex Light2ce6fc82017-12-18 16:42:36 -08001485ArtJvmTiEnv::ArtJvmTiEnv(art::JavaVMExt* runtime, EventHandler* event_handler, jint version)
Andreas Gampede19eb92017-02-24 16:21:18 -08001486 : art_vm(runtime),
1487 local_data(nullptr),
Alex Light2ce6fc82017-12-18 16:42:36 -08001488 ti_version(version),
Alex Lightb6106d52017-10-18 15:02:15 -07001489 capabilities(),
1490 event_info_mutex_("jvmtiEnv_EventInfoMutex") {
Andreas Gampea1705ea2017-03-28 20:12:13 -07001491 object_tag_table = std::unique_ptr<ObjectTagTable>(new ObjectTagTable(event_handler, this));
Andreas Gampede19eb92017-02-24 16:21:18 -08001492 functions = &gJvmtiInterface;
1493}
1494
Alex Light49948e92016-08-11 15:35:28 -07001495// Creates a jvmtiEnv and returns it with the art::ti::Env that is associated with it. new_art_ti
1496// is a pointer to the uninitialized memory for an art::ti::Env.
Alex Light2ce6fc82017-12-18 16:42:36 -08001497static void CreateArtJvmTiEnv(art::JavaVMExt* vm, jint version, /*out*/void** new_jvmtiEnv) {
Alex Light0e841182018-02-12 17:42:50 +00001498 struct ArtJvmTiEnv* env = new ArtJvmTiEnv(vm, gEventHandler, version);
Alex Light49948e92016-08-11 15:35:28 -07001499 *new_jvmtiEnv = env;
Andreas Gampe77708d92016-10-07 11:48:21 -07001500
Alex Light0e841182018-02-12 17:42:50 +00001501 gEventHandler->RegisterArtJvmTiEnv(env);
Andreas Gampede19eb92017-02-24 16:21:18 -08001502
1503 art::Runtime::Current()->AddSystemWeakHolder(
1504 ArtJvmTiEnv::AsArtJvmTiEnv(env)->object_tag_table.get());
Alex Light49948e92016-08-11 15:35:28 -07001505}
1506
1507// A hook that the runtime uses to allow plugins to handle GetEnv calls. It returns true and
1508// places the return value in 'env' if this library can handle the GetEnv request. Otherwise
1509// returns false and does not modify the 'env' pointer.
1510static jint GetEnvHandler(art::JavaVMExt* vm, /*out*/void** env, jint version) {
Alex Light2ce6fc82017-12-18 16:42:36 -08001511 // JavaDebuggable will either be set by the runtime as it is starting up or the plugin if it's
1512 // loaded early enough. If this is false we cannot guarantee conformance to all JVMTI behaviors
1513 // due to optimizations. We will only allow agents to get ArtTiEnvs using the kArtTiVersion.
1514 if (IsFullJvmtiAvailable() && IsJvmtiVersion(version)) {
1515 CreateArtJvmTiEnv(vm, JVMTI_VERSION, env);
1516 return JNI_OK;
1517 } else if (version == kArtTiVersion) {
1518 CreateArtJvmTiEnv(vm, kArtTiVersion, env);
Alex Light49948e92016-08-11 15:35:28 -07001519 return JNI_OK;
1520 } else {
1521 printf("version 0x%x is not valid!", version);
1522 return JNI_EVERSION;
1523 }
1524}
1525
1526// The plugin initialization function. This adds the jvmti environment.
1527extern "C" bool ArtPlugin_Initialize() {
Andreas Gampee08a2be2016-10-06 13:13:30 -07001528 art::Runtime* runtime = art::Runtime::Current();
Andreas Gampe96eca782017-01-19 19:45:30 -08001529
Alex Light0e841182018-02-12 17:42:50 +00001530 gDeoptManager = new DeoptManager;
1531 gEventHandler = new EventHandler;
1532
1533 gDeoptManager->Setup();
Andreas Gampe96eca782017-01-19 19:45:30 -08001534 if (runtime->IsStarted()) {
1535 PhaseUtil::SetToLive();
1536 } else {
1537 PhaseUtil::SetToOnLoad();
1538 }
Alex Light0e841182018-02-12 17:42:50 +00001539 PhaseUtil::Register(gEventHandler);
1540 ThreadUtil::Register(gEventHandler);
1541 ClassUtil::Register(gEventHandler);
1542 DumpUtil::Register(gEventHandler);
1543 MethodUtil::Register(gEventHandler);
Andreas Gampecefaa142017-01-23 15:04:59 -08001544 SearchUtil::Register();
Andreas Gampe9e38a502017-03-06 08:19:26 -08001545 HeapUtil::Register();
Alex Lightca97ada2018-02-02 09:25:31 -08001546 Transformer::Setup();
Andreas Gampe96eca782017-01-19 19:45:30 -08001547
Alex Light2ce6fc82017-12-18 16:42:36 -08001548 {
1549 // Make sure we can deopt anything we need to.
1550 art::ScopedObjectAccess soa(art::Thread::Current());
Alex Light0e841182018-02-12 17:42:50 +00001551 gDeoptManager->FinishSetup();
Alex Light2ce6fc82017-12-18 16:42:36 -08001552 }
1553
Andreas Gampee08a2be2016-10-06 13:13:30 -07001554 runtime->GetJavaVM()->AddEnvironmentHook(GetEnvHandler);
Andreas Gampe96eca782017-01-19 19:45:30 -08001555
Alex Light49948e92016-08-11 15:35:28 -07001556 return true;
1557}
1558
Andreas Gampeeafaf572017-01-20 12:34:15 -08001559extern "C" bool ArtPlugin_Deinitialize() {
Alex Light0e841182018-02-12 17:42:50 +00001560 gEventHandler->Shutdown();
1561 gDeoptManager->Shutdown();
Andreas Gampeeafaf572017-01-20 12:34:15 -08001562 PhaseUtil::Unregister();
1563 ThreadUtil::Unregister();
Andreas Gampee6377462017-01-20 17:37:50 -08001564 ClassUtil::Unregister();
Andreas Gampeeb0cea12017-01-23 08:50:04 -08001565 DumpUtil::Unregister();
Alex Lightd78ddec2017-04-18 15:20:38 -07001566 MethodUtil::Unregister();
Andreas Gampecefaa142017-01-23 15:04:59 -08001567 SearchUtil::Unregister();
Andreas Gampe9e38a502017-03-06 08:19:26 -08001568 HeapUtil::Unregister();
Andreas Gampeeafaf572017-01-20 12:34:15 -08001569
Alex Light0e841182018-02-12 17:42:50 +00001570 // TODO It would be good to delete the gEventHandler and gDeoptManager here but we cannot since
1571 // daemon threads might be suspended and we want to make sure that even if they wake up briefly
1572 // they won't hit deallocated memory. By this point none of the functions will do anything since
1573 // they have already shutdown.
1574
Andreas Gampeeafaf572017-01-20 12:34:15 -08001575 return true;
1576}
1577
Alex Light49948e92016-08-11 15:35:28 -07001578// The actual struct holding all of the entrypoints into the jvmti interface.
1579const jvmtiInterface_1 gJvmtiInterface = {
Alex Light6ac57502017-01-19 15:05:06 -08001580 nullptr, // reserved1
Alex Light49948e92016-08-11 15:35:28 -07001581 JvmtiFunctions::SetEventNotificationMode,
Alex Light0e692732017-01-10 15:00:05 -08001582 nullptr, // reserved3
Alex Light49948e92016-08-11 15:35:28 -07001583 JvmtiFunctions::GetAllThreads,
1584 JvmtiFunctions::SuspendThread,
1585 JvmtiFunctions::ResumeThread,
1586 JvmtiFunctions::StopThread,
1587 JvmtiFunctions::InterruptThread,
1588 JvmtiFunctions::GetThreadInfo,
1589 JvmtiFunctions::GetOwnedMonitorInfo, // 10
1590 JvmtiFunctions::GetCurrentContendedMonitor,
1591 JvmtiFunctions::RunAgentThread,
1592 JvmtiFunctions::GetTopThreadGroups,
1593 JvmtiFunctions::GetThreadGroupInfo,
1594 JvmtiFunctions::GetThreadGroupChildren,
1595 JvmtiFunctions::GetFrameCount,
1596 JvmtiFunctions::GetThreadState,
1597 JvmtiFunctions::GetCurrentThread,
1598 JvmtiFunctions::GetFrameLocation,
1599 JvmtiFunctions::NotifyFramePop, // 20
1600 JvmtiFunctions::GetLocalObject,
1601 JvmtiFunctions::GetLocalInt,
1602 JvmtiFunctions::GetLocalLong,
1603 JvmtiFunctions::GetLocalFloat,
1604 JvmtiFunctions::GetLocalDouble,
1605 JvmtiFunctions::SetLocalObject,
1606 JvmtiFunctions::SetLocalInt,
1607 JvmtiFunctions::SetLocalLong,
1608 JvmtiFunctions::SetLocalFloat,
1609 JvmtiFunctions::SetLocalDouble, // 30
1610 JvmtiFunctions::CreateRawMonitor,
1611 JvmtiFunctions::DestroyRawMonitor,
1612 JvmtiFunctions::RawMonitorEnter,
1613 JvmtiFunctions::RawMonitorExit,
1614 JvmtiFunctions::RawMonitorWait,
1615 JvmtiFunctions::RawMonitorNotify,
1616 JvmtiFunctions::RawMonitorNotifyAll,
1617 JvmtiFunctions::SetBreakpoint,
1618 JvmtiFunctions::ClearBreakpoint,
1619 nullptr, // reserved40
1620 JvmtiFunctions::SetFieldAccessWatch,
1621 JvmtiFunctions::ClearFieldAccessWatch,
1622 JvmtiFunctions::SetFieldModificationWatch,
1623 JvmtiFunctions::ClearFieldModificationWatch,
1624 JvmtiFunctions::IsModifiableClass,
1625 JvmtiFunctions::Allocate,
1626 JvmtiFunctions::Deallocate,
1627 JvmtiFunctions::GetClassSignature,
1628 JvmtiFunctions::GetClassStatus,
1629 JvmtiFunctions::GetSourceFileName, // 50
1630 JvmtiFunctions::GetClassModifiers,
1631 JvmtiFunctions::GetClassMethods,
1632 JvmtiFunctions::GetClassFields,
1633 JvmtiFunctions::GetImplementedInterfaces,
1634 JvmtiFunctions::IsInterface,
1635 JvmtiFunctions::IsArrayClass,
1636 JvmtiFunctions::GetClassLoader,
1637 JvmtiFunctions::GetObjectHashCode,
1638 JvmtiFunctions::GetObjectMonitorUsage,
1639 JvmtiFunctions::GetFieldName, // 60
1640 JvmtiFunctions::GetFieldDeclaringClass,
1641 JvmtiFunctions::GetFieldModifiers,
1642 JvmtiFunctions::IsFieldSynthetic,
1643 JvmtiFunctions::GetMethodName,
1644 JvmtiFunctions::GetMethodDeclaringClass,
1645 JvmtiFunctions::GetMethodModifiers,
1646 nullptr, // reserved67
1647 JvmtiFunctions::GetMaxLocals,
1648 JvmtiFunctions::GetArgumentsSize,
1649 JvmtiFunctions::GetLineNumberTable, // 70
1650 JvmtiFunctions::GetMethodLocation,
1651 JvmtiFunctions::GetLocalVariableTable,
1652 JvmtiFunctions::SetNativeMethodPrefix,
1653 JvmtiFunctions::SetNativeMethodPrefixes,
1654 JvmtiFunctions::GetBytecodes,
1655 JvmtiFunctions::IsMethodNative,
1656 JvmtiFunctions::IsMethodSynthetic,
1657 JvmtiFunctions::GetLoadedClasses,
1658 JvmtiFunctions::GetClassLoaderClasses,
1659 JvmtiFunctions::PopFrame, // 80
1660 JvmtiFunctions::ForceEarlyReturnObject,
1661 JvmtiFunctions::ForceEarlyReturnInt,
1662 JvmtiFunctions::ForceEarlyReturnLong,
1663 JvmtiFunctions::ForceEarlyReturnFloat,
1664 JvmtiFunctions::ForceEarlyReturnDouble,
1665 JvmtiFunctions::ForceEarlyReturnVoid,
1666 JvmtiFunctions::RedefineClasses,
1667 JvmtiFunctions::GetVersionNumber,
1668 JvmtiFunctions::GetCapabilities,
1669 JvmtiFunctions::GetSourceDebugExtension, // 90
1670 JvmtiFunctions::IsMethodObsolete,
1671 JvmtiFunctions::SuspendThreadList,
1672 JvmtiFunctions::ResumeThreadList,
1673 nullptr, // reserved94
1674 nullptr, // reserved95
1675 nullptr, // reserved96
1676 nullptr, // reserved97
1677 nullptr, // reserved98
1678 nullptr, // reserved99
1679 JvmtiFunctions::GetAllStackTraces, // 100
1680 JvmtiFunctions::GetThreadListStackTraces,
1681 JvmtiFunctions::GetThreadLocalStorage,
1682 JvmtiFunctions::SetThreadLocalStorage,
1683 JvmtiFunctions::GetStackTrace,
1684 nullptr, // reserved105
1685 JvmtiFunctions::GetTag,
1686 JvmtiFunctions::SetTag,
1687 JvmtiFunctions::ForceGarbageCollection,
1688 JvmtiFunctions::IterateOverObjectsReachableFromObject,
1689 JvmtiFunctions::IterateOverReachableObjects, // 110
1690 JvmtiFunctions::IterateOverHeap,
1691 JvmtiFunctions::IterateOverInstancesOfClass,
1692 nullptr, // reserved113
1693 JvmtiFunctions::GetObjectsWithTags,
1694 JvmtiFunctions::FollowReferences,
1695 JvmtiFunctions::IterateThroughHeap,
1696 nullptr, // reserved117
1697 nullptr, // reserved118
1698 nullptr, // reserved119
1699 JvmtiFunctions::SetJNIFunctionTable, // 120
1700 JvmtiFunctions::GetJNIFunctionTable,
1701 JvmtiFunctions::SetEventCallbacks,
1702 JvmtiFunctions::GenerateEvents,
1703 JvmtiFunctions::GetExtensionFunctions,
1704 JvmtiFunctions::GetExtensionEvents,
1705 JvmtiFunctions::SetExtensionEventCallback,
1706 JvmtiFunctions::DisposeEnvironment,
1707 JvmtiFunctions::GetErrorName,
1708 JvmtiFunctions::GetJLocationFormat,
1709 JvmtiFunctions::GetSystemProperties, // 130
1710 JvmtiFunctions::GetSystemProperty,
1711 JvmtiFunctions::SetSystemProperty,
1712 JvmtiFunctions::GetPhase,
1713 JvmtiFunctions::GetCurrentThreadCpuTimerInfo,
1714 JvmtiFunctions::GetCurrentThreadCpuTime,
1715 JvmtiFunctions::GetThreadCpuTimerInfo,
1716 JvmtiFunctions::GetThreadCpuTime,
1717 JvmtiFunctions::GetTimerInfo,
1718 JvmtiFunctions::GetTime,
1719 JvmtiFunctions::GetPotentialCapabilities, // 140
1720 nullptr, // reserved141
1721 JvmtiFunctions::AddCapabilities,
1722 JvmtiFunctions::RelinquishCapabilities,
1723 JvmtiFunctions::GetAvailableProcessors,
1724 JvmtiFunctions::GetClassVersionNumbers,
1725 JvmtiFunctions::GetConstantPool,
1726 JvmtiFunctions::GetEnvironmentLocalStorage,
1727 JvmtiFunctions::SetEnvironmentLocalStorage,
1728 JvmtiFunctions::AddToBootstrapClassLoaderSearch,
1729 JvmtiFunctions::SetVerboseFlag, // 150
1730 JvmtiFunctions::AddToSystemClassLoaderSearch,
1731 JvmtiFunctions::RetransformClasses,
1732 JvmtiFunctions::GetOwnedMonitorStackDepthInfo,
1733 JvmtiFunctions::GetObjectSize,
1734 JvmtiFunctions::GetLocalInstance,
1735};
1736
1737}; // namespace openjdkjvmti