blob: 09900e1f739d73d6a39d98b9615a82508a4dda52 [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
Yi Kongc57c6802018-10-29 14:28:56 -070032#include <memory>
Alex Light9c20a142016-08-23 15:05:12 -070033#include <string>
Andreas Gampef37e3022017-01-13 17:54:46 -080034#include <type_traits>
Alex Light9c20a142016-08-23 15:05:12 -070035#include <vector>
36
Andreas Gampe57943812017-12-06 21:39:13 -080037#include <android-base/logging.h>
38
Alex Light49948e92016-08-11 15:35:28 -070039#include <jni.h>
Alex Light9c20a142016-08-23 15:05:12 -070040
Andreas Gampe5e03a302017-03-13 13:10:00 -070041#include "jvmti.h"
Alex Light49948e92016-08-11 15:35:28 -070042
Alex Light986914b2019-11-19 01:12:25 +000043#include "alloc_manager.h"
Andreas Gampedb6dcb62016-09-13 09:05:59 -070044#include "art_jvmti.h"
Andreas Gampe170331f2017-12-07 18:41:03 -080045#include "base/logging.h" // For gLogVerbosity.
Andreas Gampe77708d92016-10-07 11:48:21 -070046#include "base/mutex.h"
47#include "events-inl.h"
Vladimir Markoa3ad0cd2018-05-04 10:06:38 +010048#include "jni/jni_env_ext-inl.h"
Andreas Gampe6dee92e2016-09-12 19:58:13 -070049#include "obj_ptr-inl.h"
Alex Lighta01de592016-11-15 10:43:06 -080050#include "object_tagging.h"
Alex Light9c20a142016-08-23 15:05:12 -070051#include "runtime.h"
Andreas Gampe6dee92e2016-09-12 19:58:13 -070052#include "scoped_thread_state_change-inl.h"
Andreas Gampeb486a982017-06-01 13:45:54 -070053#include "thread-current-inl.h"
Alex Lighta01de592016-11-15 10:43:06 -080054#include "thread_list.h"
Alex Lightbf64a572017-07-05 10:34:49 -070055#include "ti_allocator.h"
Alex Lighta26e3492017-06-27 17:55:37 -070056#include "ti_breakpoint.h"
Andreas Gampee492ae32016-10-28 19:34:57 -070057#include "ti_class.h"
Andreas Gampeeb0cea12017-01-23 08:50:04 -080058#include "ti_dump.h"
Alex Light3f33c0a2017-11-08 10:17:37 -080059#include "ti_extension.h"
Andreas Gampeab2f0d02017-01-05 17:23:45 -080060#include "ti_field.h"
Andreas Gampeba8df692016-11-01 10:30:44 -070061#include "ti_heap.h"
Andreas Gampe6f8e4f02017-01-16 18:18:14 -080062#include "ti_jni.h"
Alex Lightae45cbb2018-10-18 15:49:56 -070063#include "ti_logging.h"
Andreas Gampe3c252f02016-10-27 18:25:17 -070064#include "ti_method.h"
Andreas Gampe319dbe82017-01-09 16:42:21 -080065#include "ti_monitor.h"
Andreas Gampe50a4e492017-01-06 18:00:20 -080066#include "ti_object.h"
Andreas Gampe96eca782017-01-19 19:45:30 -080067#include "ti_phase.h"
Andreas Gampe1bdaf732017-01-09 19:21:06 -080068#include "ti_properties.h"
Alex Lighta01de592016-11-15 10:43:06 -080069#include "ti_redefine.h"
Andreas Gampece7732b2017-01-17 15:50:26 -080070#include "ti_search.h"
Andreas Gampeb5eb94a2016-10-27 19:23:09 -070071#include "ti_stack.h"
Andreas Gampeaf13ab92017-01-11 20:57:40 -080072#include "ti_thread.h"
Andreas Gamped18d9e22017-01-16 16:08:45 +000073#include "ti_threadgroup.h"
Andreas Gampe35bcf812017-01-13 16:24:17 -080074#include "ti_timers.h"
Alex Light9c20a142016-08-23 15:05:12 -070075#include "transform.h"
Alex Light49948e92016-08-11 15:35:28 -070076
Alex Light49948e92016-08-11 15:35:28 -070077namespace openjdkjvmti {
78
Alex Light0e841182018-02-12 17:42:50 +000079// NB These are heap allocated to avoid the static destructors being run if an agent calls exit(3).
80// These should never be null.
81EventHandler* gEventHandler;
82DeoptManager* gDeoptManager;
Alex Light986914b2019-11-19 01:12:25 +000083AllocationManager* gAllocManager;
Andreas Gampe6dee92e2016-09-12 19:58:13 -070084
Alex Lighte6574242016-08-17 09:56:24 -070085#define ENSURE_NON_NULL(n) \
86 do { \
87 if ((n) == nullptr) { \
88 return ERR(NULL_POINTER); \
89 } \
90 } while (false)
91
Alex Light2ce6fc82017-12-18 16:42:36 -080092// Returns whether we are able to use all jvmti features.
93static bool IsFullJvmtiAvailable() {
94 art::Runtime* runtime = art::Runtime::Current();
95 return runtime->GetInstrumentation()->IsForcedInterpretOnly() || runtime->IsJavaDebuggable();
96}
97
Alex Light49948e92016-08-11 15:35:28 -070098class JvmtiFunctions {
99 private:
Alex Light1edc8cf2017-03-24 14:22:56 -0700100 static jvmtiError getEnvironmentError(jvmtiEnv* env) {
101 if (env == nullptr) {
102 return ERR(INVALID_ENVIRONMENT);
103 } else if (art::Thread::Current() == nullptr) {
104 return ERR(UNATTACHED_THREAD);
105 } else {
106 return OK;
107 }
Alex Light49948e92016-08-11 15:35:28 -0700108 }
109
Alex Light1edc8cf2017-03-24 14:22:56 -0700110#define ENSURE_VALID_ENV(env) \
111 do { \
112 jvmtiError ensure_valid_env_ ## __LINE__ = getEnvironmentError(env); \
113 if (ensure_valid_env_ ## __LINE__ != OK) { \
114 return ensure_valid_env_ ## __LINE__ ; \
115 } \
Alex Lighte6574242016-08-17 09:56:24 -0700116 } while (false)
117
118#define ENSURE_HAS_CAP(env, cap) \
119 do { \
Alex Lighte6574242016-08-17 09:56:24 -0700120 if (ArtJvmTiEnv::AsArtJvmTiEnv(env)->capabilities.cap != 1) { \
121 return ERR(MUST_POSSESS_CAPABILITY); \
122 } \
123 } while (false)
124
Alex Light49948e92016-08-11 15:35:28 -0700125 public:
126 static jvmtiError Allocate(jvmtiEnv* env, jlong size, unsigned char** mem_ptr) {
Alex Light6a399f32018-01-10 16:31:55 -0800127 jvmtiError err = getEnvironmentError(env);
128 // Allow UNATTACHED_THREAD since we don't really care about that for this function.
129 if (err != OK && err != ERR(UNATTACHED_THREAD)) {
130 return err;
131 }
Alex Lighte6574242016-08-17 09:56:24 -0700132 ENSURE_NON_NULL(mem_ptr);
Alex Lightbf64a572017-07-05 10:34:49 -0700133 return AllocUtil::Allocate(env, size, mem_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700134 }
135
136 static jvmtiError Deallocate(jvmtiEnv* env, unsigned char* mem) {
Alex Light6a399f32018-01-10 16:31:55 -0800137 jvmtiError err = getEnvironmentError(env);
138 // Allow UNATTACHED_THREAD since we don't really care about that for this function.
139 if (err != OK && err != ERR(UNATTACHED_THREAD)) {
140 return err;
141 }
Alex Lightbf64a572017-07-05 10:34:49 -0700142 return AllocUtil::Deallocate(env, mem);
Alex Light49948e92016-08-11 15:35:28 -0700143 }
144
145 static jvmtiError GetThreadState(jvmtiEnv* env, jthread thread, jint* thread_state_ptr) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700146 ENSURE_VALID_ENV(env);
Andreas Gampe72c19832017-01-12 13:22:16 -0800147 return ThreadUtil::GetThreadState(env, thread, thread_state_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700148 }
149
150 static jvmtiError GetCurrentThread(jvmtiEnv* env, jthread* thread_ptr) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700151 ENSURE_VALID_ENV(env);
Andreas Gampeaf13ab92017-01-11 20:57:40 -0800152 return ThreadUtil::GetCurrentThread(env, thread_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700153 }
154
155 static jvmtiError GetAllThreads(jvmtiEnv* env, jint* threads_count_ptr, jthread** threads_ptr) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700156 ENSURE_VALID_ENV(env);
Andreas Gampe85807442017-01-13 14:40:58 -0800157 return ThreadUtil::GetAllThreads(env, threads_count_ptr, threads_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700158 }
159
Alex Light88fd7202017-06-30 08:31:59 -0700160 static jvmtiError SuspendThread(jvmtiEnv* env, jthread thread) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700161 ENSURE_VALID_ENV(env);
Alex Light9db679d2017-01-25 15:28:04 -0800162 ENSURE_HAS_CAP(env, can_suspend);
Alex Light88fd7202017-06-30 08:31:59 -0700163 return ThreadUtil::SuspendThread(env, thread);
Alex Light49948e92016-08-11 15:35:28 -0700164 }
165
166 static jvmtiError SuspendThreadList(jvmtiEnv* env,
Alex Light88fd7202017-06-30 08:31:59 -0700167 jint request_count,
168 const jthread* request_list,
169 jvmtiError* results) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700170 ENSURE_VALID_ENV(env);
Alex Light9db679d2017-01-25 15:28:04 -0800171 ENSURE_HAS_CAP(env, can_suspend);
Alex Light88fd7202017-06-30 08:31:59 -0700172 return ThreadUtil::SuspendThreadList(env, request_count, request_list, results);
Alex Light49948e92016-08-11 15:35:28 -0700173 }
174
Alex Light88fd7202017-06-30 08:31:59 -0700175 static jvmtiError ResumeThread(jvmtiEnv* env, jthread thread) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700176 ENSURE_VALID_ENV(env);
Alex Light9db679d2017-01-25 15:28:04 -0800177 ENSURE_HAS_CAP(env, can_suspend);
Alex Light88fd7202017-06-30 08:31:59 -0700178 return ThreadUtil::ResumeThread(env, thread);
Alex Light49948e92016-08-11 15:35:28 -0700179 }
180
181 static jvmtiError ResumeThreadList(jvmtiEnv* env,
Alex Light88fd7202017-06-30 08:31:59 -0700182 jint request_count,
183 const jthread* request_list,
184 jvmtiError* results) {
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_suspend);
Alex Light88fd7202017-06-30 08:31:59 -0700187 return ThreadUtil::ResumeThreadList(env, request_count, request_list, results);
Alex Light49948e92016-08-11 15:35:28 -0700188 }
189
Alex Light54d39dc2017-09-25 17:00:16 -0700190 static jvmtiError StopThread(jvmtiEnv* env, jthread thread, jobject exception) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700191 ENSURE_VALID_ENV(env);
Alex Light9db679d2017-01-25 15:28:04 -0800192 ENSURE_HAS_CAP(env, can_signal_thread);
Alex Light54d39dc2017-09-25 17:00:16 -0700193 return ThreadUtil::StopThread(env, thread, exception);
Alex Light49948e92016-08-11 15:35:28 -0700194 }
195
Alex Light54d39dc2017-09-25 17:00:16 -0700196 static jvmtiError InterruptThread(jvmtiEnv* env, jthread thread) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700197 ENSURE_VALID_ENV(env);
Alex Light9db679d2017-01-25 15:28:04 -0800198 ENSURE_HAS_CAP(env, can_signal_thread);
Alex Light54d39dc2017-09-25 17:00:16 -0700199 return ThreadUtil::InterruptThread(env, thread);
Alex Light49948e92016-08-11 15:35:28 -0700200 }
201
202 static jvmtiError GetThreadInfo(jvmtiEnv* env, jthread thread, jvmtiThreadInfo* info_ptr) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700203 ENSURE_VALID_ENV(env);
Andreas Gampeaf13ab92017-01-11 20:57:40 -0800204 return ThreadUtil::GetThreadInfo(env, thread, info_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700205 }
206
207 static jvmtiError GetOwnedMonitorInfo(jvmtiEnv* env,
Alex Light88e1ddd2017-08-21 13:09:55 -0700208 jthread thread,
209 jint* owned_monitor_count_ptr,
210 jobject** owned_monitors_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_info);
Alex Light88e1ddd2017-08-21 13:09:55 -0700213 return StackUtil::GetOwnedMonitorInfo(env,
214 thread,
215 owned_monitor_count_ptr,
216 owned_monitors_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700217 }
218
Alex Light88e1ddd2017-08-21 13:09:55 -0700219 static jvmtiError GetOwnedMonitorStackDepthInfo(jvmtiEnv* env,
220 jthread thread,
221 jint* monitor_info_count_ptr,
222 jvmtiMonitorStackDepthInfo** monitor_info_ptr) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700223 ENSURE_VALID_ENV(env);
Alex Light9db679d2017-01-25 15:28:04 -0800224 ENSURE_HAS_CAP(env, can_get_owned_monitor_stack_depth_info);
Alex Light88e1ddd2017-08-21 13:09:55 -0700225 return StackUtil::GetOwnedMonitorStackDepthInfo(env,
226 thread,
227 monitor_info_count_ptr,
228 monitor_info_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700229 }
230
231 static jvmtiError GetCurrentContendedMonitor(jvmtiEnv* env,
Alex Light41006c62017-09-14 09:51:14 -0700232 jthread thread,
233 jobject* monitor_ptr) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700234 ENSURE_VALID_ENV(env);
Alex Light9db679d2017-01-25 15:28:04 -0800235 ENSURE_HAS_CAP(env, can_get_current_contended_monitor);
Alex Light41006c62017-09-14 09:51:14 -0700236 return MonitorUtil::GetCurrentContendedMonitor(env, thread, monitor_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700237 }
238
239 static jvmtiError RunAgentThread(jvmtiEnv* env,
240 jthread thread,
241 jvmtiStartFunction proc,
242 const void* arg,
243 jint priority) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700244 ENSURE_VALID_ENV(env);
Andreas Gampe732b0ac2017-01-18 15:23:39 -0800245 return ThreadUtil::RunAgentThread(env, thread, proc, arg, priority);
Alex Light49948e92016-08-11 15:35:28 -0700246 }
247
248 static jvmtiError SetThreadLocalStorage(jvmtiEnv* env, jthread thread, const void* data) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700249 ENSURE_VALID_ENV(env);
Andreas Gampe7b3b3262017-01-19 20:40:42 -0800250 return ThreadUtil::SetThreadLocalStorage(env, thread, data);
Alex Light49948e92016-08-11 15:35:28 -0700251 }
252
253 static jvmtiError GetThreadLocalStorage(jvmtiEnv* env, jthread thread, void** data_ptr) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700254 ENSURE_VALID_ENV(env);
Andreas Gampe7b3b3262017-01-19 20:40:42 -0800255 return ThreadUtil::GetThreadLocalStorage(env, thread, data_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700256 }
257
258 static jvmtiError GetTopThreadGroups(jvmtiEnv* env,
259 jint* group_count_ptr,
260 jthreadGroup** groups_ptr) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700261 ENSURE_VALID_ENV(env);
Andreas Gamped18d9e22017-01-16 16:08:45 +0000262 return ThreadGroupUtil::GetTopThreadGroups(env, group_count_ptr, groups_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700263 }
264
265 static jvmtiError GetThreadGroupInfo(jvmtiEnv* env,
266 jthreadGroup group,
267 jvmtiThreadGroupInfo* info_ptr) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700268 ENSURE_VALID_ENV(env);
Andreas Gamped18d9e22017-01-16 16:08:45 +0000269 return ThreadGroupUtil::GetThreadGroupInfo(env, group, info_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700270 }
271
272 static jvmtiError GetThreadGroupChildren(jvmtiEnv* env,
273 jthreadGroup group,
274 jint* thread_count_ptr,
275 jthread** threads_ptr,
276 jint* group_count_ptr,
277 jthreadGroup** groups_ptr) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700278 ENSURE_VALID_ENV(env);
Andreas Gamped18d9e22017-01-16 16:08:45 +0000279 return ThreadGroupUtil::GetThreadGroupChildren(env,
280 group,
281 thread_count_ptr,
282 threads_ptr,
283 group_count_ptr,
284 groups_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700285 }
286
287 static jvmtiError GetStackTrace(jvmtiEnv* env,
288 jthread thread,
289 jint start_depth,
290 jint max_frame_count,
291 jvmtiFrameInfo* frame_buffer,
292 jint* count_ptr) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700293 ENSURE_VALID_ENV(env);
Andreas Gampeb5eb94a2016-10-27 19:23:09 -0700294 return StackUtil::GetStackTrace(env,
295 thread,
296 start_depth,
297 max_frame_count,
298 frame_buffer,
299 count_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700300 }
301
302 static jvmtiError GetAllStackTraces(jvmtiEnv* env,
303 jint max_frame_count,
304 jvmtiStackInfo** stack_info_ptr,
305 jint* thread_count_ptr) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700306 ENSURE_VALID_ENV(env);
Andreas Gampea1a27c62017-01-11 16:37:16 -0800307 return StackUtil::GetAllStackTraces(env, max_frame_count, stack_info_ptr, thread_count_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700308 }
309
310 static jvmtiError GetThreadListStackTraces(jvmtiEnv* env,
311 jint thread_count,
312 const jthread* thread_list,
313 jint max_frame_count,
314 jvmtiStackInfo** stack_info_ptr) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700315 ENSURE_VALID_ENV(env);
Andreas Gampeeba32fb2017-01-12 17:40:05 -0800316 return StackUtil::GetThreadListStackTraces(env,
317 thread_count,
318 thread_list,
319 max_frame_count,
320 stack_info_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700321 }
322
323 static jvmtiError GetFrameCount(jvmtiEnv* env, jthread thread, jint* count_ptr) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700324 ENSURE_VALID_ENV(env);
Andreas Gampef6f3b5f2017-01-13 09:21:42 -0800325 return StackUtil::GetFrameCount(env, thread, count_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700326 }
327
Alex Light0aa7a5a2018-10-10 15:58:14 +0000328 static jvmtiError PopFrame(jvmtiEnv* env, jthread thread) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700329 ENSURE_VALID_ENV(env);
Alex Light9db679d2017-01-25 15:28:04 -0800330 ENSURE_HAS_CAP(env, can_pop_frame);
Alex Light0aa7a5a2018-10-10 15:58:14 +0000331 return StackUtil::PopFrame(env, thread);
Alex Light49948e92016-08-11 15:35:28 -0700332 }
333
334 static jvmtiError GetFrameLocation(jvmtiEnv* env,
335 jthread thread,
336 jint depth,
337 jmethodID* method_ptr,
338 jlocation* location_ptr) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700339 ENSURE_VALID_ENV(env);
Andreas Gampef6f3b5f2017-01-13 09:21:42 -0800340 return StackUtil::GetFrameLocation(env, thread, depth, method_ptr, location_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700341 }
342
Alex Lighte814f9d2017-07-31 16:14:39 -0700343 static jvmtiError NotifyFramePop(jvmtiEnv* env, jthread thread, jint depth) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700344 ENSURE_VALID_ENV(env);
Alex Light9db679d2017-01-25 15:28:04 -0800345 ENSURE_HAS_CAP(env, can_generate_frame_pop_events);
Alex Lighte814f9d2017-07-31 16:14:39 -0700346 return StackUtil::NotifyFramePop(env, thread, depth);
Alex Light49948e92016-08-11 15:35:28 -0700347 }
348
Alex Lightb7c640d2019-03-20 15:52:13 -0700349 static jvmtiError ForceEarlyReturnObject(jvmtiEnv* env, jthread thread, jobject value) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700350 ENSURE_VALID_ENV(env);
Alex Light9db679d2017-01-25 15:28:04 -0800351 ENSURE_HAS_CAP(env, can_force_early_return);
Alex Lightb7c640d2019-03-20 15:52:13 -0700352 return StackUtil::ForceEarlyReturn(env, gEventHandler, thread, value);
Alex Light49948e92016-08-11 15:35:28 -0700353 }
354
Alex Lightb7c640d2019-03-20 15:52:13 -0700355 static jvmtiError ForceEarlyReturnInt(jvmtiEnv* env, jthread thread, jint value) {
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 Lightb7c640d2019-03-20 15:52:13 -0700358 return StackUtil::ForceEarlyReturn(env, gEventHandler, thread, value);
Alex Light49948e92016-08-11 15:35:28 -0700359 }
360
Alex Lightb7c640d2019-03-20 15:52:13 -0700361 static jvmtiError ForceEarlyReturnLong(jvmtiEnv* env, jthread thread, jlong value) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700362 ENSURE_VALID_ENV(env);
Alex Light9db679d2017-01-25 15:28:04 -0800363 ENSURE_HAS_CAP(env, can_force_early_return);
Alex Lightb7c640d2019-03-20 15:52:13 -0700364 return StackUtil::ForceEarlyReturn(env, gEventHandler, thread, value);
Alex Light49948e92016-08-11 15:35:28 -0700365 }
366
Alex Lightb7c640d2019-03-20 15:52:13 -0700367 static jvmtiError ForceEarlyReturnFloat(jvmtiEnv* env, jthread thread, jfloat value) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700368 ENSURE_VALID_ENV(env);
Alex Light9db679d2017-01-25 15:28:04 -0800369 ENSURE_HAS_CAP(env, can_force_early_return);
Alex Lightb7c640d2019-03-20 15:52:13 -0700370 return StackUtil::ForceEarlyReturn(env, gEventHandler, thread, value);
Alex Light49948e92016-08-11 15:35:28 -0700371 }
372
Alex Lightb7c640d2019-03-20 15:52:13 -0700373 static jvmtiError ForceEarlyReturnDouble(jvmtiEnv* env, jthread thread, jdouble value) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700374 ENSURE_VALID_ENV(env);
Alex Light9db679d2017-01-25 15:28:04 -0800375 ENSURE_HAS_CAP(env, can_force_early_return);
Alex Lightb7c640d2019-03-20 15:52:13 -0700376 return StackUtil::ForceEarlyReturn(env, gEventHandler, thread, value);
Alex Light49948e92016-08-11 15:35:28 -0700377 }
378
Alex Lightb7c640d2019-03-20 15:52:13 -0700379 static jvmtiError ForceEarlyReturnVoid(jvmtiEnv* env, jthread thread) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700380 ENSURE_VALID_ENV(env);
Alex Light9db679d2017-01-25 15:28:04 -0800381 ENSURE_HAS_CAP(env, can_force_early_return);
Alex Lightb7c640d2019-03-20 15:52:13 -0700382 return StackUtil::ForceEarlyReturn<nullptr_t>(env, gEventHandler, thread, nullptr);
Alex Light49948e92016-08-11 15:35:28 -0700383 }
384
385 static jvmtiError FollowReferences(jvmtiEnv* env,
386 jint heap_filter,
387 jclass klass,
388 jobject initial_object,
389 const jvmtiHeapCallbacks* callbacks,
390 const void* user_data) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700391 ENSURE_VALID_ENV(env);
Alex Light9db679d2017-01-25 15:28:04 -0800392 ENSURE_HAS_CAP(env, can_tag_objects);
Andreas Gampede19eb92017-02-24 16:21:18 -0800393 HeapUtil heap_util(ArtJvmTiEnv::AsArtJvmTiEnv(env)->object_tag_table.get());
Andreas Gampe70bfc8a2016-11-03 11:04:15 -0700394 return heap_util.FollowReferences(env,
395 heap_filter,
396 klass,
397 initial_object,
398 callbacks,
399 user_data);
Alex Light49948e92016-08-11 15:35:28 -0700400 }
401
402 static jvmtiError IterateThroughHeap(jvmtiEnv* env,
403 jint heap_filter,
404 jclass klass,
405 const jvmtiHeapCallbacks* callbacks,
406 const void* user_data) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700407 ENSURE_VALID_ENV(env);
Alex Lighte6574242016-08-17 09:56:24 -0700408 ENSURE_HAS_CAP(env, can_tag_objects);
Andreas Gampede19eb92017-02-24 16:21:18 -0800409 HeapUtil heap_util(ArtJvmTiEnv::AsArtJvmTiEnv(env)->object_tag_table.get());
Andreas Gampee54d9922016-10-11 19:55:37 -0700410 return heap_util.IterateThroughHeap(env, heap_filter, klass, callbacks, user_data);
Alex Light49948e92016-08-11 15:35:28 -0700411 }
412
413 static jvmtiError GetTag(jvmtiEnv* env, jobject object, jlong* tag_ptr) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700414 ENSURE_VALID_ENV(env);
Alex Lighte6574242016-08-17 09:56:24 -0700415 ENSURE_HAS_CAP(env, can_tag_objects);
Andreas Gampe6dee92e2016-09-12 19:58:13 -0700416
417 JNIEnv* jni_env = GetJniEnv(env);
418 if (jni_env == nullptr) {
419 return ERR(INTERNAL);
420 }
421
422 art::ScopedObjectAccess soa(jni_env);
423 art::ObjPtr<art::mirror::Object> obj = soa.Decode<art::mirror::Object>(object);
Andreas Gampede19eb92017-02-24 16:21:18 -0800424 if (!ArtJvmTiEnv::AsArtJvmTiEnv(env)->object_tag_table->GetTag(obj.Ptr(), tag_ptr)) {
Andreas Gampe6dee92e2016-09-12 19:58:13 -0700425 *tag_ptr = 0;
426 }
427
428 return ERR(NONE);
Alex Light49948e92016-08-11 15:35:28 -0700429 }
430
431 static jvmtiError SetTag(jvmtiEnv* env, jobject object, jlong tag) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700432 ENSURE_VALID_ENV(env);
Alex Lighte6574242016-08-17 09:56:24 -0700433 ENSURE_HAS_CAP(env, can_tag_objects);
434
Andreas Gampe6dee92e2016-09-12 19:58:13 -0700435 if (object == nullptr) {
436 return ERR(NULL_POINTER);
437 }
438
439 JNIEnv* jni_env = GetJniEnv(env);
440 if (jni_env == nullptr) {
441 return ERR(INTERNAL);
442 }
443
444 art::ScopedObjectAccess soa(jni_env);
445 art::ObjPtr<art::mirror::Object> obj = soa.Decode<art::mirror::Object>(object);
Andreas Gampede19eb92017-02-24 16:21:18 -0800446 ArtJvmTiEnv::AsArtJvmTiEnv(env)->object_tag_table->Set(obj.Ptr(), tag);
Andreas Gampe6dee92e2016-09-12 19:58:13 -0700447
448 return ERR(NONE);
Alex Light49948e92016-08-11 15:35:28 -0700449 }
450
451 static jvmtiError GetObjectsWithTags(jvmtiEnv* env,
452 jint tag_count,
453 const jlong* tags,
454 jint* count_ptr,
455 jobject** object_result_ptr,
456 jlong** tag_result_ptr) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700457 ENSURE_VALID_ENV(env);
Alex Lighte6574242016-08-17 09:56:24 -0700458 ENSURE_HAS_CAP(env, can_tag_objects);
459
Andreas Gampe5e6046b2016-10-25 12:05:53 -0700460 JNIEnv* jni_env = GetJniEnv(env);
461 if (jni_env == nullptr) {
462 return ERR(INTERNAL);
463 }
464
465 art::ScopedObjectAccess soa(jni_env);
Andreas Gampede19eb92017-02-24 16:21:18 -0800466 return ArtJvmTiEnv::AsArtJvmTiEnv(env)->object_tag_table->GetTaggedObjects(env,
467 tag_count,
468 tags,
469 count_ptr,
470 object_result_ptr,
471 tag_result_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700472 }
473
474 static jvmtiError ForceGarbageCollection(jvmtiEnv* env) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700475 ENSURE_VALID_ENV(env);
Andreas Gampe8da6d032016-10-31 19:31:03 -0700476 return HeapUtil::ForceGarbageCollection(env);
Alex Light49948e92016-08-11 15:35:28 -0700477 }
478
479 static jvmtiError IterateOverObjectsReachableFromObject(
480 jvmtiEnv* env,
Alex Light6a3fd512017-02-27 14:34:32 -0800481 jobject object ATTRIBUTE_UNUSED,
482 jvmtiObjectReferenceCallback object_reference_callback ATTRIBUTE_UNUSED,
483 const void* user_data ATTRIBUTE_UNUSED) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700484 ENSURE_VALID_ENV(env);
Alex Light9db679d2017-01-25 15:28:04 -0800485 ENSURE_HAS_CAP(env, can_tag_objects);
Alex Light49948e92016-08-11 15:35:28 -0700486 return ERR(NOT_IMPLEMENTED);
487 }
488
Alex Light6a3fd512017-02-27 14:34:32 -0800489 static jvmtiError IterateOverReachableObjects(
490 jvmtiEnv* env,
491 jvmtiHeapRootCallback heap_root_callback ATTRIBUTE_UNUSED,
492 jvmtiStackReferenceCallback stack_ref_callback ATTRIBUTE_UNUSED,
493 jvmtiObjectReferenceCallback object_ref_callback ATTRIBUTE_UNUSED,
494 const void* user_data ATTRIBUTE_UNUSED) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700495 ENSURE_VALID_ENV(env);
Alex Light9db679d2017-01-25 15:28:04 -0800496 ENSURE_HAS_CAP(env, can_tag_objects);
Alex Light49948e92016-08-11 15:35:28 -0700497 return ERR(NOT_IMPLEMENTED);
498 }
499
500 static jvmtiError IterateOverHeap(jvmtiEnv* env,
Alex Light6a3fd512017-02-27 14:34:32 -0800501 jvmtiHeapObjectFilter object_filter ATTRIBUTE_UNUSED,
502 jvmtiHeapObjectCallback heap_object_callback ATTRIBUTE_UNUSED,
503 const void* user_data ATTRIBUTE_UNUSED) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700504 ENSURE_VALID_ENV(env);
Alex Light9db679d2017-01-25 15:28:04 -0800505 ENSURE_HAS_CAP(env, can_tag_objects);
Alex Light49948e92016-08-11 15:35:28 -0700506 return ERR(NOT_IMPLEMENTED);
507 }
508
Alex Light6a3fd512017-02-27 14:34:32 -0800509 static jvmtiError IterateOverInstancesOfClass(
510 jvmtiEnv* env,
Alex Lightbbbcb532018-08-30 12:50:27 -0700511 jclass klass,
512 jvmtiHeapObjectFilter object_filter,
513 jvmtiHeapObjectCallback heap_object_callback,
514 const void* user_data) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700515 ENSURE_VALID_ENV(env);
Alex Light9db679d2017-01-25 15:28:04 -0800516 ENSURE_HAS_CAP(env, can_tag_objects);
Alex Lightbbbcb532018-08-30 12:50:27 -0700517 HeapUtil heap_util(ArtJvmTiEnv::AsArtJvmTiEnv(env)->object_tag_table.get());
518 return heap_util.IterateOverInstancesOfClass(
519 env, klass, object_filter, heap_object_callback, user_data);
Alex Light49948e92016-08-11 15:35:28 -0700520 }
521
522 static jvmtiError GetLocalObject(jvmtiEnv* env,
Alex Lightbebd7bd2017-07-25 14:05:52 -0700523 jthread thread,
524 jint depth,
525 jint slot,
526 jobject* value_ptr) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700527 ENSURE_VALID_ENV(env);
Alex Light9db679d2017-01-25 15:28:04 -0800528 ENSURE_HAS_CAP(env, can_access_local_variables);
Alex Lightbebd7bd2017-07-25 14:05:52 -0700529 return MethodUtil::GetLocalVariable(env, thread, depth, slot, value_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700530 }
531
532 static jvmtiError GetLocalInstance(jvmtiEnv* env,
Alex Lightbebd7bd2017-07-25 14:05:52 -0700533 jthread thread,
534 jint depth,
535 jobject* value_ptr) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700536 ENSURE_VALID_ENV(env);
Alex Light9db679d2017-01-25 15:28:04 -0800537 ENSURE_HAS_CAP(env, can_access_local_variables);
Alex Lightbebd7bd2017-07-25 14:05:52 -0700538 return MethodUtil::GetLocalInstance(env, thread, depth, value_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700539 }
540
541 static jvmtiError GetLocalInt(jvmtiEnv* env,
Alex Lightbebd7bd2017-07-25 14:05:52 -0700542 jthread thread,
543 jint depth,
544 jint slot,
545 jint* value_ptr) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700546 ENSURE_VALID_ENV(env);
Alex Light9db679d2017-01-25 15:28:04 -0800547 ENSURE_HAS_CAP(env, can_access_local_variables);
Alex Lightbebd7bd2017-07-25 14:05:52 -0700548 return MethodUtil::GetLocalVariable(env, thread, depth, slot, value_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700549 }
550
551 static jvmtiError GetLocalLong(jvmtiEnv* env,
Alex Lightbebd7bd2017-07-25 14:05:52 -0700552 jthread thread,
553 jint depth,
554 jint slot,
555 jlong* value_ptr) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700556 ENSURE_VALID_ENV(env);
Alex Light9db679d2017-01-25 15:28:04 -0800557 ENSURE_HAS_CAP(env, can_access_local_variables);
Alex Lightbebd7bd2017-07-25 14:05:52 -0700558 return MethodUtil::GetLocalVariable(env, thread, depth, slot, value_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700559 }
560
561 static jvmtiError GetLocalFloat(jvmtiEnv* env,
Alex Lightbebd7bd2017-07-25 14:05:52 -0700562 jthread thread,
563 jint depth,
564 jint slot,
565 jfloat* value_ptr) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700566 ENSURE_VALID_ENV(env);
Alex Light9db679d2017-01-25 15:28:04 -0800567 ENSURE_HAS_CAP(env, can_access_local_variables);
Alex Lightbebd7bd2017-07-25 14:05:52 -0700568 return MethodUtil::GetLocalVariable(env, thread, depth, slot, value_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700569 }
570
571 static jvmtiError GetLocalDouble(jvmtiEnv* env,
Alex Lightbebd7bd2017-07-25 14:05:52 -0700572 jthread thread,
573 jint depth,
574 jint slot,
575 jdouble* value_ptr) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700576 ENSURE_VALID_ENV(env);
Alex Light9db679d2017-01-25 15:28:04 -0800577 ENSURE_HAS_CAP(env, can_access_local_variables);
Alex Lightbebd7bd2017-07-25 14:05:52 -0700578 return MethodUtil::GetLocalVariable(env, thread, depth, slot, value_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700579 }
580
581 static jvmtiError SetLocalObject(jvmtiEnv* env,
Alex Lightbebd7bd2017-07-25 14:05:52 -0700582 jthread thread,
583 jint depth,
584 jint slot,
585 jobject value) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700586 ENSURE_VALID_ENV(env);
Alex Light9db679d2017-01-25 15:28:04 -0800587 ENSURE_HAS_CAP(env, can_access_local_variables);
Alex Lightbebd7bd2017-07-25 14:05:52 -0700588 return MethodUtil::SetLocalVariable(env, thread, depth, slot, value);
Alex Light49948e92016-08-11 15:35:28 -0700589 }
590
591 static jvmtiError SetLocalInt(jvmtiEnv* env,
Alex Lightbebd7bd2017-07-25 14:05:52 -0700592 jthread thread,
593 jint depth,
594 jint slot,
595 jint value) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700596 ENSURE_VALID_ENV(env);
Alex Light9db679d2017-01-25 15:28:04 -0800597 ENSURE_HAS_CAP(env, can_access_local_variables);
Alex Lightbebd7bd2017-07-25 14:05:52 -0700598 return MethodUtil::SetLocalVariable(env, thread, depth, slot, value);
Alex Light49948e92016-08-11 15:35:28 -0700599 }
600
601 static jvmtiError SetLocalLong(jvmtiEnv* env,
Alex Lightbebd7bd2017-07-25 14:05:52 -0700602 jthread thread,
603 jint depth,
604 jint slot,
605 jlong value) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700606 ENSURE_VALID_ENV(env);
Alex Light9db679d2017-01-25 15:28:04 -0800607 ENSURE_HAS_CAP(env, can_access_local_variables);
Alex Lightbebd7bd2017-07-25 14:05:52 -0700608 return MethodUtil::SetLocalVariable(env, thread, depth, slot, value);
Alex Light49948e92016-08-11 15:35:28 -0700609 }
610
611 static jvmtiError SetLocalFloat(jvmtiEnv* env,
Alex Lightbebd7bd2017-07-25 14:05:52 -0700612 jthread thread,
613 jint depth,
614 jint slot,
615 jfloat value) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700616 ENSURE_VALID_ENV(env);
Alex Light9db679d2017-01-25 15:28:04 -0800617 ENSURE_HAS_CAP(env, can_access_local_variables);
Alex Lightbebd7bd2017-07-25 14:05:52 -0700618 return MethodUtil::SetLocalVariable(env, thread, depth, slot, value);
Alex Light49948e92016-08-11 15:35:28 -0700619 }
620
621 static jvmtiError SetLocalDouble(jvmtiEnv* env,
Alex Lightbebd7bd2017-07-25 14:05:52 -0700622 jthread thread,
623 jint depth,
624 jint slot,
625 jdouble value) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700626 ENSURE_VALID_ENV(env);
Alex Light9db679d2017-01-25 15:28:04 -0800627 ENSURE_HAS_CAP(env, can_access_local_variables);
Alex Lightbebd7bd2017-07-25 14:05:52 -0700628 return MethodUtil::SetLocalVariable(env, thread, depth, slot, value);
Alex Light49948e92016-08-11 15:35:28 -0700629 }
630
Alex Lighta26e3492017-06-27 17:55:37 -0700631
632 static jvmtiError SetBreakpoint(jvmtiEnv* env, jmethodID method, jlocation location) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700633 ENSURE_VALID_ENV(env);
Alex Light9db679d2017-01-25 15:28:04 -0800634 ENSURE_HAS_CAP(env, can_generate_breakpoint_events);
Alex Lighta26e3492017-06-27 17:55:37 -0700635 return BreakpointUtil::SetBreakpoint(env, method, location);
Alex Light49948e92016-08-11 15:35:28 -0700636 }
637
Alex Lighta26e3492017-06-27 17:55:37 -0700638 static jvmtiError ClearBreakpoint(jvmtiEnv* env, jmethodID method, jlocation location) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700639 ENSURE_VALID_ENV(env);
Alex Light9db679d2017-01-25 15:28:04 -0800640 ENSURE_HAS_CAP(env, can_generate_breakpoint_events);
Alex Lighta26e3492017-06-27 17:55:37 -0700641 return BreakpointUtil::ClearBreakpoint(env, method, location);
Alex Light49948e92016-08-11 15:35:28 -0700642 }
643
Alex Light084fa372017-06-16 08:58:34 -0700644 static jvmtiError SetFieldAccessWatch(jvmtiEnv* env, jclass klass, jfieldID field) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700645 ENSURE_VALID_ENV(env);
Alex Light9db679d2017-01-25 15:28:04 -0800646 ENSURE_HAS_CAP(env, can_generate_field_access_events);
Alex Light084fa372017-06-16 08:58:34 -0700647 return FieldUtil::SetFieldAccessWatch(env, klass, field);
Alex Light49948e92016-08-11 15:35:28 -0700648 }
649
Alex Light084fa372017-06-16 08:58:34 -0700650 static jvmtiError ClearFieldAccessWatch(jvmtiEnv* env, jclass klass, jfieldID field) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700651 ENSURE_VALID_ENV(env);
Alex Light9db679d2017-01-25 15:28:04 -0800652 ENSURE_HAS_CAP(env, can_generate_field_access_events);
Alex Light084fa372017-06-16 08:58:34 -0700653 return FieldUtil::ClearFieldAccessWatch(env, klass, field);
Alex Light49948e92016-08-11 15:35:28 -0700654 }
655
Alex Light084fa372017-06-16 08:58:34 -0700656 static jvmtiError SetFieldModificationWatch(jvmtiEnv* env, jclass klass, jfieldID field) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700657 ENSURE_VALID_ENV(env);
Alex Light9db679d2017-01-25 15:28:04 -0800658 ENSURE_HAS_CAP(env, can_generate_field_modification_events);
Alex Light084fa372017-06-16 08:58:34 -0700659 return FieldUtil::SetFieldModificationWatch(env, klass, field);
Alex Light49948e92016-08-11 15:35:28 -0700660 }
661
Alex Light084fa372017-06-16 08:58:34 -0700662 static jvmtiError ClearFieldModificationWatch(jvmtiEnv* env, jclass klass, jfieldID field) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700663 ENSURE_VALID_ENV(env);
Alex Light9db679d2017-01-25 15:28:04 -0800664 ENSURE_HAS_CAP(env, can_generate_field_modification_events);
Alex Light084fa372017-06-16 08:58:34 -0700665 return FieldUtil::ClearFieldModificationWatch(env, klass, field);
Alex Light49948e92016-08-11 15:35:28 -0700666 }
667
668 static jvmtiError GetLoadedClasses(jvmtiEnv* env, jint* class_count_ptr, jclass** classes_ptr) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700669 ENSURE_VALID_ENV(env);
Andreas Gampede19eb92017-02-24 16:21:18 -0800670 HeapUtil heap_util(ArtJvmTiEnv::AsArtJvmTiEnv(env)->object_tag_table.get());
Andreas Gampeaa8b60c2016-10-12 12:51:25 -0700671 return heap_util.GetLoadedClasses(env, class_count_ptr, classes_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700672 }
673
674 static jvmtiError GetClassLoaderClasses(jvmtiEnv* env,
675 jobject initiating_loader,
676 jint* class_count_ptr,
677 jclass** classes_ptr) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700678 ENSURE_VALID_ENV(env);
Andreas Gampe70f16392017-01-16 14:20:10 -0800679 return ClassUtil::GetClassLoaderClasses(env, initiating_loader, class_count_ptr, classes_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700680 }
681
682 static jvmtiError GetClassSignature(jvmtiEnv* env,
683 jclass klass,
684 char** signature_ptr,
685 char** generic_ptr) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700686 ENSURE_VALID_ENV(env);
Andreas Gampee492ae32016-10-28 19:34:57 -0700687 return ClassUtil::GetClassSignature(env, klass, signature_ptr, generic_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700688 }
689
690 static jvmtiError GetClassStatus(jvmtiEnv* env, jclass klass, jint* status_ptr) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700691 ENSURE_VALID_ENV(env);
Andreas Gampeff9d2092017-01-06 09:12:49 -0800692 return ClassUtil::GetClassStatus(env, klass, status_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700693 }
694
Alex Light6fa7b812017-06-16 09:04:29 -0700695 static jvmtiError GetSourceFileName(jvmtiEnv* env, jclass klass, char** source_name_ptr) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700696 ENSURE_VALID_ENV(env);
Alex Light9db679d2017-01-25 15:28:04 -0800697 ENSURE_HAS_CAP(env, can_get_source_file_name);
Alex Light6fa7b812017-06-16 09:04:29 -0700698 return ClassUtil::GetSourceFileName(env, klass, source_name_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700699 }
700
701 static jvmtiError GetClassModifiers(jvmtiEnv* env, jclass klass, jint* modifiers_ptr) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700702 ENSURE_VALID_ENV(env);
Andreas Gampe64013e52017-01-06 13:07:19 -0800703 return ClassUtil::GetClassModifiers(env, klass, modifiers_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700704 }
705
706 static jvmtiError GetClassMethods(jvmtiEnv* env,
707 jclass klass,
708 jint* method_count_ptr,
709 jmethodID** methods_ptr) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700710 ENSURE_VALID_ENV(env);
Andreas Gampe18fee4d2017-01-06 11:36:35 -0800711 return ClassUtil::GetClassMethods(env, klass, method_count_ptr, methods_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700712 }
713
714 static jvmtiError GetClassFields(jvmtiEnv* env,
715 jclass klass,
716 jint* field_count_ptr,
717 jfieldID** fields_ptr) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700718 ENSURE_VALID_ENV(env);
Andreas Gampeac587272017-01-05 15:21:34 -0800719 return ClassUtil::GetClassFields(env, klass, field_count_ptr, fields_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700720 }
721
722 static jvmtiError GetImplementedInterfaces(jvmtiEnv* env,
723 jclass klass,
724 jint* interface_count_ptr,
725 jclass** interfaces_ptr) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700726 ENSURE_VALID_ENV(env);
Andreas Gampe8b07e472017-01-06 14:20:39 -0800727 return ClassUtil::GetImplementedInterfaces(env, klass, interface_count_ptr, interfaces_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700728 }
729
730 static jvmtiError GetClassVersionNumbers(jvmtiEnv* env,
731 jclass klass,
732 jint* minor_version_ptr,
733 jint* major_version_ptr) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700734 ENSURE_VALID_ENV(env);
Andreas Gampe812a2442017-01-19 22:04:46 -0800735 return ClassUtil::GetClassVersionNumbers(env, klass, minor_version_ptr, major_version_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700736 }
737
738 static jvmtiError GetConstantPool(jvmtiEnv* env,
Alex Light6a3fd512017-02-27 14:34:32 -0800739 jclass klass ATTRIBUTE_UNUSED,
740 jint* constant_pool_count_ptr ATTRIBUTE_UNUSED,
741 jint* constant_pool_byte_count_ptr ATTRIBUTE_UNUSED,
742 unsigned char** constant_pool_bytes_ptr ATTRIBUTE_UNUSED) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700743 ENSURE_VALID_ENV(env);
Alex Light9db679d2017-01-25 15:28:04 -0800744 ENSURE_HAS_CAP(env, can_get_constant_pool);
Alex Light49948e92016-08-11 15:35:28 -0700745 return ERR(NOT_IMPLEMENTED);
746 }
747
748 static jvmtiError IsInterface(jvmtiEnv* env, jclass klass, jboolean* is_interface_ptr) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700749 ENSURE_VALID_ENV(env);
Andreas Gampe4fd66ec2017-01-05 14:42:13 -0800750 return ClassUtil::IsInterface(env, klass, is_interface_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700751 }
752
753 static jvmtiError IsArrayClass(jvmtiEnv* env,
754 jclass klass,
755 jboolean* is_array_class_ptr) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700756 ENSURE_VALID_ENV(env);
Andreas Gampe4fd66ec2017-01-05 14:42:13 -0800757 return ClassUtil::IsArrayClass(env, klass, is_array_class_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700758 }
759
760 static jvmtiError IsModifiableClass(jvmtiEnv* env,
761 jclass klass,
762 jboolean* is_modifiable_class_ptr) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700763 ENSURE_VALID_ENV(env);
Alex Lighte4a88632017-01-10 07:41:24 -0800764 return Redefiner::IsModifiableClass(env, klass, is_modifiable_class_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700765 }
766
767 static jvmtiError GetClassLoader(jvmtiEnv* env, jclass klass, jobject* classloader_ptr) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700768 ENSURE_VALID_ENV(env);
Andreas Gampe8f5b6032017-01-06 15:50:55 -0800769 return ClassUtil::GetClassLoader(env, klass, classloader_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700770 }
771
772 static jvmtiError GetSourceDebugExtension(jvmtiEnv* env,
Alex Light6fa7b812017-06-16 09:04:29 -0700773 jclass klass,
774 char** source_debug_extension_ptr) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700775 ENSURE_VALID_ENV(env);
Alex Light9db679d2017-01-25 15:28:04 -0800776 ENSURE_HAS_CAP(env, can_get_source_debug_extension);
Alex Light6fa7b812017-06-16 09:04:29 -0700777 return ClassUtil::GetSourceDebugExtension(env, klass, source_debug_extension_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700778 }
779
780 static jvmtiError RetransformClasses(jvmtiEnv* env, jint class_count, const jclass* classes) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700781 ENSURE_VALID_ENV(env);
Alex Light9db679d2017-01-25 15:28:04 -0800782 ENSURE_HAS_CAP(env, can_retransform_classes);
Alex Light3732beb2019-10-04 13:35:34 -0700783 return Transformer::RetransformClasses(env, class_count, classes);
Alex Light49948e92016-08-11 15:35:28 -0700784 }
785
786 static jvmtiError RedefineClasses(jvmtiEnv* env,
787 jint class_count,
788 const jvmtiClassDefinition* class_definitions) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700789 ENSURE_VALID_ENV(env);
Alex Light9db679d2017-01-25 15:28:04 -0800790 ENSURE_HAS_CAP(env, can_redefine_classes);
Alex Light3732beb2019-10-04 13:35:34 -0700791 return Redefiner::RedefineClasses(env, class_count, class_definitions);
Alex Light49948e92016-08-11 15:35:28 -0700792 }
793
794 static jvmtiError GetObjectSize(jvmtiEnv* env, jobject object, jlong* size_ptr) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700795 ENSURE_VALID_ENV(env);
Andreas Gampe50a4e492017-01-06 18:00:20 -0800796 return ObjectUtil::GetObjectSize(env, object, size_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700797 }
798
799 static jvmtiError GetObjectHashCode(jvmtiEnv* env, jobject object, jint* hash_code_ptr) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700800 ENSURE_VALID_ENV(env);
Andreas Gampe50a4e492017-01-06 18:00:20 -0800801 return ObjectUtil::GetObjectHashCode(env, object, hash_code_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700802 }
803
804 static jvmtiError GetObjectMonitorUsage(jvmtiEnv* env,
Alex Lightce568642017-09-05 16:54:25 -0700805 jobject object,
806 jvmtiMonitorUsage* info_ptr) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700807 ENSURE_VALID_ENV(env);
Alex Light9db679d2017-01-25 15:28:04 -0800808 ENSURE_HAS_CAP(env, can_get_monitor_info);
Alex Lightce568642017-09-05 16:54:25 -0700809 return ObjectUtil::GetObjectMonitorUsage(env, object, info_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700810 }
811
812 static jvmtiError GetFieldName(jvmtiEnv* env,
813 jclass klass,
814 jfieldID field,
815 char** name_ptr,
816 char** signature_ptr,
817 char** generic_ptr) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700818 ENSURE_VALID_ENV(env);
Andreas Gampeab2f0d02017-01-05 17:23:45 -0800819 return FieldUtil::GetFieldName(env, klass, field, name_ptr, signature_ptr, generic_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700820 }
821
822 static jvmtiError GetFieldDeclaringClass(jvmtiEnv* env,
823 jclass klass,
824 jfieldID field,
825 jclass* declaring_class_ptr) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700826 ENSURE_VALID_ENV(env);
Andreas Gampeab2f0d02017-01-05 17:23:45 -0800827 return FieldUtil::GetFieldDeclaringClass(env, klass, field, declaring_class_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700828 }
829
830 static jvmtiError GetFieldModifiers(jvmtiEnv* env,
831 jclass klass,
832 jfieldID field,
833 jint* modifiers_ptr) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700834 ENSURE_VALID_ENV(env);
Andreas Gampeab2f0d02017-01-05 17:23:45 -0800835 return FieldUtil::GetFieldModifiers(env, klass, field, modifiers_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700836 }
837
838 static jvmtiError IsFieldSynthetic(jvmtiEnv* env,
839 jclass klass,
840 jfieldID field,
841 jboolean* is_synthetic_ptr) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700842 ENSURE_VALID_ENV(env);
Alex Light9db679d2017-01-25 15:28:04 -0800843 ENSURE_HAS_CAP(env, can_get_synthetic_attribute);
Andreas Gampeab2f0d02017-01-05 17:23:45 -0800844 return FieldUtil::IsFieldSynthetic(env, klass, field, is_synthetic_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700845 }
846
847 static jvmtiError GetMethodName(jvmtiEnv* env,
848 jmethodID method,
849 char** name_ptr,
850 char** signature_ptr,
851 char** generic_ptr) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700852 ENSURE_VALID_ENV(env);
Andreas Gampe3c252f02016-10-27 18:25:17 -0700853 return MethodUtil::GetMethodName(env, method, name_ptr, signature_ptr, generic_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700854 }
855
856 static jvmtiError GetMethodDeclaringClass(jvmtiEnv* env,
857 jmethodID method,
858 jclass* declaring_class_ptr) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700859 ENSURE_VALID_ENV(env);
Andreas Gampe368a2082016-10-28 17:33:13 -0700860 return MethodUtil::GetMethodDeclaringClass(env, method, declaring_class_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700861 }
862
863 static jvmtiError GetMethodModifiers(jvmtiEnv* env,
864 jmethodID method,
865 jint* modifiers_ptr) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700866 ENSURE_VALID_ENV(env);
Andreas Gampe36bcd4f2016-10-28 18:07:18 -0700867 return MethodUtil::GetMethodModifiers(env, method, modifiers_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700868 }
869
870 static jvmtiError GetMaxLocals(jvmtiEnv* env,
871 jmethodID method,
872 jint* max_ptr) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700873 ENSURE_VALID_ENV(env);
Andreas Gampef71832e2017-01-09 11:38:04 -0800874 return MethodUtil::GetMaxLocals(env, method, max_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700875 }
876
877 static jvmtiError GetArgumentsSize(jvmtiEnv* env,
878 jmethodID method,
879 jint* size_ptr) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700880 ENSURE_VALID_ENV(env);
Andreas Gampef71832e2017-01-09 11:38:04 -0800881 return MethodUtil::GetArgumentsSize(env, method, size_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700882 }
883
884 static jvmtiError GetLineNumberTable(jvmtiEnv* env,
885 jmethodID method,
886 jint* entry_count_ptr,
887 jvmtiLineNumberEntry** table_ptr) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700888 ENSURE_VALID_ENV(env);
Alex Light9db679d2017-01-25 15:28:04 -0800889 ENSURE_HAS_CAP(env, can_get_line_numbers);
Andreas Gampeda3e5612016-12-13 19:00:53 -0800890 return MethodUtil::GetLineNumberTable(env, method, entry_count_ptr, table_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700891 }
892
893 static jvmtiError GetMethodLocation(jvmtiEnv* env,
894 jmethodID method,
895 jlocation* start_location_ptr,
896 jlocation* end_location_ptr) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700897 ENSURE_VALID_ENV(env);
Andreas Gampef71832e2017-01-09 11:38:04 -0800898 return MethodUtil::GetMethodLocation(env, method, start_location_ptr, end_location_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700899 }
900
901 static jvmtiError GetLocalVariableTable(jvmtiEnv* env,
Alex Lightce68cc62017-07-26 10:30:38 -0700902 jmethodID method,
903 jint* entry_count_ptr,
904 jvmtiLocalVariableEntry** table_ptr) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700905 ENSURE_VALID_ENV(env);
Alex Light9db679d2017-01-25 15:28:04 -0800906 ENSURE_HAS_CAP(env, can_access_local_variables);
Alex Lightce68cc62017-07-26 10:30:38 -0700907 return MethodUtil::GetLocalVariableTable(env, method, entry_count_ptr, table_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700908 }
909
910 static jvmtiError GetBytecodes(jvmtiEnv* env,
Alex Light4c174282017-07-05 10:18:18 -0700911 jmethodID method,
912 jint* bytecode_count_ptr,
913 unsigned char** bytecodes_ptr) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700914 ENSURE_VALID_ENV(env);
Alex Light9db679d2017-01-25 15:28:04 -0800915 ENSURE_HAS_CAP(env, can_get_bytecodes);
Alex Light4c174282017-07-05 10:18:18 -0700916 return MethodUtil::GetBytecodes(env, method, bytecode_count_ptr, bytecodes_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700917 }
918
919 static jvmtiError IsMethodNative(jvmtiEnv* env, jmethodID method, jboolean* is_native_ptr) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700920 ENSURE_VALID_ENV(env);
Andreas Gampefdeef522017-01-09 14:40:25 -0800921 return MethodUtil::IsMethodNative(env, method, is_native_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700922 }
923
924 static jvmtiError IsMethodSynthetic(jvmtiEnv* env, jmethodID method, jboolean* is_synthetic_ptr) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700925 ENSURE_VALID_ENV(env);
Alex Light9db679d2017-01-25 15:28:04 -0800926 ENSURE_HAS_CAP(env, can_get_synthetic_attribute);
Andreas Gampefdeef522017-01-09 14:40:25 -0800927 return MethodUtil::IsMethodSynthetic(env, method, is_synthetic_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700928 }
929
930 static jvmtiError IsMethodObsolete(jvmtiEnv* env, jmethodID method, jboolean* is_obsolete_ptr) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700931 ENSURE_VALID_ENV(env);
Andreas Gampefdeef522017-01-09 14:40:25 -0800932 return MethodUtil::IsMethodObsolete(env, method, is_obsolete_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700933 }
934
Alex Light6a3fd512017-02-27 14:34:32 -0800935 static jvmtiError SetNativeMethodPrefix(jvmtiEnv* env, const char* prefix ATTRIBUTE_UNUSED) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700936 ENSURE_VALID_ENV(env);
Alex Light9db679d2017-01-25 15:28:04 -0800937 ENSURE_HAS_CAP(env, can_set_native_method_prefix);
Alex Light49948e92016-08-11 15:35:28 -0700938 return ERR(NOT_IMPLEMENTED);
939 }
940
Alex Light6a3fd512017-02-27 14:34:32 -0800941 static jvmtiError SetNativeMethodPrefixes(jvmtiEnv* env,
942 jint prefix_count ATTRIBUTE_UNUSED,
943 char** prefixes ATTRIBUTE_UNUSED) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700944 ENSURE_VALID_ENV(env);
Alex Light9db679d2017-01-25 15:28:04 -0800945 ENSURE_HAS_CAP(env, can_set_native_method_prefix);
Alex Light49948e92016-08-11 15:35:28 -0700946 return ERR(NOT_IMPLEMENTED);
947 }
948
949 static jvmtiError CreateRawMonitor(jvmtiEnv* env, const char* name, jrawMonitorID* monitor_ptr) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700950 ENSURE_VALID_ENV(env);
Andreas Gampe319dbe82017-01-09 16:42:21 -0800951 return MonitorUtil::CreateRawMonitor(env, name, monitor_ptr);
Alex Light49948e92016-08-11 15:35:28 -0700952 }
953
954 static jvmtiError DestroyRawMonitor(jvmtiEnv* env, jrawMonitorID monitor) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700955 ENSURE_VALID_ENV(env);
Andreas Gampe319dbe82017-01-09 16:42:21 -0800956 return MonitorUtil::DestroyRawMonitor(env, monitor);
Alex Light49948e92016-08-11 15:35:28 -0700957 }
958
959 static jvmtiError RawMonitorEnter(jvmtiEnv* env, jrawMonitorID monitor) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700960 ENSURE_VALID_ENV(env);
Andreas Gampe319dbe82017-01-09 16:42:21 -0800961 return MonitorUtil::RawMonitorEnter(env, monitor);
Alex Light49948e92016-08-11 15:35:28 -0700962 }
963
964 static jvmtiError RawMonitorExit(jvmtiEnv* env, jrawMonitorID monitor) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700965 ENSURE_VALID_ENV(env);
Andreas Gampe319dbe82017-01-09 16:42:21 -0800966 return MonitorUtil::RawMonitorExit(env, monitor);
Alex Light49948e92016-08-11 15:35:28 -0700967 }
968
969 static jvmtiError RawMonitorWait(jvmtiEnv* env, jrawMonitorID monitor, jlong millis) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700970 ENSURE_VALID_ENV(env);
Andreas Gampe319dbe82017-01-09 16:42:21 -0800971 return MonitorUtil::RawMonitorWait(env, monitor, millis);
Alex Light49948e92016-08-11 15:35:28 -0700972 }
973
974 static jvmtiError RawMonitorNotify(jvmtiEnv* env, jrawMonitorID monitor) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700975 ENSURE_VALID_ENV(env);
Andreas Gampe319dbe82017-01-09 16:42:21 -0800976 return MonitorUtil::RawMonitorNotify(env, monitor);
Alex Light49948e92016-08-11 15:35:28 -0700977 }
978
979 static jvmtiError RawMonitorNotifyAll(jvmtiEnv* env, jrawMonitorID monitor) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700980 ENSURE_VALID_ENV(env);
Andreas Gampe319dbe82017-01-09 16:42:21 -0800981 return MonitorUtil::RawMonitorNotifyAll(env, monitor);
Alex Light49948e92016-08-11 15:35:28 -0700982 }
983
984 static jvmtiError SetJNIFunctionTable(jvmtiEnv* env, const jniNativeInterface* function_table) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700985 ENSURE_VALID_ENV(env);
Andreas Gampe6f8e4f02017-01-16 18:18:14 -0800986 return JNIUtil::SetJNIFunctionTable(env, function_table);
Alex Light49948e92016-08-11 15:35:28 -0700987 }
988
989 static jvmtiError GetJNIFunctionTable(jvmtiEnv* env, jniNativeInterface** function_table) {
Alex Light1edc8cf2017-03-24 14:22:56 -0700990 ENSURE_VALID_ENV(env);
Andreas Gampe6f8e4f02017-01-16 18:18:14 -0800991 return JNIUtil::GetJNIFunctionTable(env, function_table);
Alex Light49948e92016-08-11 15:35:28 -0700992 }
993
Andreas Gampe77708d92016-10-07 11:48:21 -0700994 // TODO: This will require locking, so that an agent can't remove callbacks when we're dispatching
995 // an event.
Alex Light49948e92016-08-11 15:35:28 -0700996 static jvmtiError SetEventCallbacks(jvmtiEnv* env,
997 const jvmtiEventCallbacks* callbacks,
998 jint size_of_callbacks) {
Alex Lighte6574242016-08-17 09:56:24 -0700999 ENSURE_VALID_ENV(env);
Andreas Gampe77708d92016-10-07 11:48:21 -07001000 if (size_of_callbacks < 0) {
1001 return ERR(ILLEGAL_ARGUMENT);
1002 }
1003
1004 if (callbacks == nullptr) {
1005 ArtJvmTiEnv::AsArtJvmTiEnv(env)->event_callbacks.reset();
1006 return ERR(NONE);
1007 }
1008
Alex Light8c2b9292017-11-09 13:21:01 -08001009 // Lock the event_info_mutex_ while we replace the callbacks.
1010 ArtJvmTiEnv* art_env = ArtJvmTiEnv::AsArtJvmTiEnv(env);
1011 art::WriterMutexLock lk(art::Thread::Current(), art_env->event_info_mutex_);
1012 std::unique_ptr<ArtJvmtiEventCallbacks> tmp(new ArtJvmtiEventCallbacks());
1013 // Copy over the extension events.
1014 tmp->CopyExtensionsFrom(art_env->event_callbacks.get());
1015 // Never overwrite the extension events.
Andreas Gampe77708d92016-10-07 11:48:21 -07001016 size_t copy_size = std::min(sizeof(jvmtiEventCallbacks),
1017 static_cast<size_t>(size_of_callbacks));
1018 copy_size = art::RoundDown(copy_size, sizeof(void*));
Alex Light8c2b9292017-11-09 13:21:01 -08001019 // Copy non-extension events.
Andreas Gampe77708d92016-10-07 11:48:21 -07001020 memcpy(tmp.get(), callbacks, copy_size);
1021
Alex Light8c2b9292017-11-09 13:21:01 -08001022 // replace the event table.
1023 art_env->event_callbacks = std::move(tmp);
Andreas Gampe77708d92016-10-07 11:48:21 -07001024
1025 return ERR(NONE);
Alex Light49948e92016-08-11 15:35:28 -07001026 }
1027
1028 static jvmtiError SetEventNotificationMode(jvmtiEnv* env,
1029 jvmtiEventMode mode,
1030 jvmtiEvent event_type,
1031 jthread event_thread,
1032 ...) {
Alex Lighte6574242016-08-17 09:56:24 -07001033 ENSURE_VALID_ENV(env);
Alex Light40d87f42017-01-18 10:27:06 -08001034 ArtJvmTiEnv* art_env = ArtJvmTiEnv::AsArtJvmTiEnv(env);
Alex Light0e841182018-02-12 17:42:50 +00001035 return gEventHandler->SetEvent(art_env,
Alex Light3dacdd62019-03-12 15:45:47 +00001036 event_thread,
Alex Light0e841182018-02-12 17:42:50 +00001037 GetArtJvmtiEvent(art_env, event_type),
1038 mode);
Alex Light49948e92016-08-11 15:35:28 -07001039 }
1040
Alex Light1edc8cf2017-03-24 14:22:56 -07001041 static jvmtiError GenerateEvents(jvmtiEnv* env,
Alex Light6a3fd512017-02-27 14:34:32 -08001042 jvmtiEvent event_type ATTRIBUTE_UNUSED) {
Alex Light1edc8cf2017-03-24 14:22:56 -07001043 ENSURE_VALID_ENV(env);
Alex Light6a3fd512017-02-27 14:34:32 -08001044 return OK;
Alex Light49948e92016-08-11 15:35:28 -07001045 }
1046
Alex Light1edc8cf2017-03-24 14:22:56 -07001047 static jvmtiError GetExtensionFunctions(jvmtiEnv* env,
Alex Light49948e92016-08-11 15:35:28 -07001048 jint* extension_count_ptr,
1049 jvmtiExtensionFunctionInfo** extensions) {
Alex Light1edc8cf2017-03-24 14:22:56 -07001050 ENSURE_VALID_ENV(env);
Andreas Gamped73aba42017-05-03 21:40:26 -07001051 ENSURE_NON_NULL(extension_count_ptr);
1052 ENSURE_NON_NULL(extensions);
Alex Light3f33c0a2017-11-08 10:17:37 -08001053 return ExtensionUtil::GetExtensionFunctions(env, extension_count_ptr, extensions);
Alex Light49948e92016-08-11 15:35:28 -07001054 }
1055
Alex Light1edc8cf2017-03-24 14:22:56 -07001056 static jvmtiError GetExtensionEvents(jvmtiEnv* env,
Alex Light49948e92016-08-11 15:35:28 -07001057 jint* extension_count_ptr,
1058 jvmtiExtensionEventInfo** extensions) {
Alex Light1edc8cf2017-03-24 14:22:56 -07001059 ENSURE_VALID_ENV(env);
Alex Light3f33c0a2017-11-08 10:17:37 -08001060 ENSURE_NON_NULL(extension_count_ptr);
1061 ENSURE_NON_NULL(extensions);
1062 return ExtensionUtil::GetExtensionEvents(env, extension_count_ptr, extensions);
Alex Light49948e92016-08-11 15:35:28 -07001063 }
1064
Alex Light1edc8cf2017-03-24 14:22:56 -07001065 static jvmtiError SetExtensionEventCallback(jvmtiEnv* env,
Alex Light3f33c0a2017-11-08 10:17:37 -08001066 jint extension_event_index,
1067 jvmtiExtensionEvent callback) {
Alex Light1edc8cf2017-03-24 14:22:56 -07001068 ENSURE_VALID_ENV(env);
Alex Light8c2b9292017-11-09 13:21:01 -08001069 return ExtensionUtil::SetExtensionEventCallback(env,
1070 extension_event_index,
1071 callback,
Alex Light0e841182018-02-12 17:42:50 +00001072 gEventHandler);
Alex Light49948e92016-08-11 15:35:28 -07001073 }
1074
Alex Light2ce6fc82017-12-18 16:42:36 -08001075#define FOR_ALL_CAPABILITIES(FUN) \
1076 FUN(can_tag_objects) \
1077 FUN(can_generate_field_modification_events) \
1078 FUN(can_generate_field_access_events) \
1079 FUN(can_get_bytecodes) \
1080 FUN(can_get_synthetic_attribute) \
1081 FUN(can_get_owned_monitor_info) \
1082 FUN(can_get_current_contended_monitor) \
1083 FUN(can_get_monitor_info) \
1084 FUN(can_pop_frame) \
1085 FUN(can_redefine_classes) \
1086 FUN(can_signal_thread) \
1087 FUN(can_get_source_file_name) \
1088 FUN(can_get_line_numbers) \
1089 FUN(can_get_source_debug_extension) \
1090 FUN(can_access_local_variables) \
1091 FUN(can_maintain_original_method_order) \
1092 FUN(can_generate_single_step_events) \
1093 FUN(can_generate_exception_events) \
1094 FUN(can_generate_frame_pop_events) \
1095 FUN(can_generate_breakpoint_events) \
1096 FUN(can_suspend) \
1097 FUN(can_redefine_any_class) \
1098 FUN(can_get_current_thread_cpu_time) \
1099 FUN(can_get_thread_cpu_time) \
1100 FUN(can_generate_method_entry_events) \
1101 FUN(can_generate_method_exit_events) \
1102 FUN(can_generate_all_class_hook_events) \
1103 FUN(can_generate_compiled_method_load_events) \
1104 FUN(can_generate_monitor_events) \
1105 FUN(can_generate_vm_object_alloc_events) \
1106 FUN(can_generate_native_method_bind_events) \
1107 FUN(can_generate_garbage_collection_events) \
1108 FUN(can_generate_object_free_events) \
1109 FUN(can_force_early_return) \
1110 FUN(can_get_owned_monitor_stack_depth_info) \
1111 FUN(can_get_constant_pool) \
1112 FUN(can_set_native_method_prefix) \
1113 FUN(can_retransform_classes) \
1114 FUN(can_retransform_any_class) \
1115 FUN(can_generate_resource_exhaustion_heap_events) \
1116 FUN(can_generate_resource_exhaustion_threads_events)
1117
Alex Light49948e92016-08-11 15:35:28 -07001118 static jvmtiError GetPotentialCapabilities(jvmtiEnv* env, jvmtiCapabilities* capabilities_ptr) {
Alex Lighte6574242016-08-17 09:56:24 -07001119 ENSURE_VALID_ENV(env);
1120 ENSURE_NON_NULL(capabilities_ptr);
1121 *capabilities_ptr = kPotentialCapabilities;
Alex Light2ce6fc82017-12-18 16:42:36 -08001122 if (UNLIKELY(!IsFullJvmtiAvailable())) {
1123#define REMOVE_NONDEBUGGABLE_UNSUPPORTED(e) \
1124 do { \
1125 if (kNonDebuggableUnsupportedCapabilities.e == 1) { \
1126 capabilities_ptr->e = 0; \
1127 } \
1128 } while (false);
1129
1130 FOR_ALL_CAPABILITIES(REMOVE_NONDEBUGGABLE_UNSUPPORTED);
1131#undef REMOVE_NONDEBUGGABLE_UNSUPPORTED
1132 }
Alex Lighte6574242016-08-17 09:56:24 -07001133 return OK;
Alex Light49948e92016-08-11 15:35:28 -07001134 }
1135
1136 static jvmtiError AddCapabilities(jvmtiEnv* env, const jvmtiCapabilities* capabilities_ptr) {
Alex Lighte6574242016-08-17 09:56:24 -07001137 ENSURE_VALID_ENV(env);
1138 ENSURE_NON_NULL(capabilities_ptr);
1139 ArtJvmTiEnv* art_env = static_cast<ArtJvmTiEnv*>(env);
1140 jvmtiError ret = OK;
Alex Light34d8e082017-03-27 09:50:36 -07001141 jvmtiCapabilities changed = {};
1142 jvmtiCapabilities potential_capabilities = {};
Alex Light1d224962017-02-27 10:26:35 -08001143 ret = env->GetPotentialCapabilities(&potential_capabilities);
1144 if (ret != OK) {
1145 return ret;
1146 }
Alex Lighte6574242016-08-17 09:56:24 -07001147#define ADD_CAPABILITY(e) \
1148 do { \
1149 if (capabilities_ptr->e == 1) { \
Alex Light1d224962017-02-27 10:26:35 -08001150 if (potential_capabilities.e == 1) { \
Alex Light73afd322017-01-18 11:17:47 -08001151 if (art_env->capabilities.e != 1) { \
1152 art_env->capabilities.e = 1; \
1153 changed.e = 1; \
1154 }\
Alex Lighte6574242016-08-17 09:56:24 -07001155 } else { \
1156 ret = ERR(NOT_AVAILABLE); \
1157 } \
1158 } \
Alex Light2ce6fc82017-12-18 16:42:36 -08001159 } while (false);
Alex Lighte6574242016-08-17 09:56:24 -07001160
Alex Light2ce6fc82017-12-18 16:42:36 -08001161 FOR_ALL_CAPABILITIES(ADD_CAPABILITY);
Alex Lighte6574242016-08-17 09:56:24 -07001162#undef ADD_CAPABILITY
Alex Light0e841182018-02-12 17:42:50 +00001163 gEventHandler->HandleChangedCapabilities(ArtJvmTiEnv::AsArtJvmTiEnv(env),
1164 changed,
Andreas Gampe6e897762018-10-16 13:09:32 -07001165 /*added=*/true);
Alex Lighte6574242016-08-17 09:56:24 -07001166 return ret;
Alex Light49948e92016-08-11 15:35:28 -07001167 }
1168
1169 static jvmtiError RelinquishCapabilities(jvmtiEnv* env,
1170 const jvmtiCapabilities* capabilities_ptr) {
Alex Lighte6574242016-08-17 09:56:24 -07001171 ENSURE_VALID_ENV(env);
1172 ENSURE_NON_NULL(capabilities_ptr);
1173 ArtJvmTiEnv* art_env = reinterpret_cast<ArtJvmTiEnv*>(env);
Alex Light34d8e082017-03-27 09:50:36 -07001174 jvmtiCapabilities changed = {};
Alex Lighte6574242016-08-17 09:56:24 -07001175#define DEL_CAPABILITY(e) \
1176 do { \
1177 if (capabilities_ptr->e == 1) { \
Alex Light73afd322017-01-18 11:17:47 -08001178 if (art_env->capabilities.e == 1) { \
1179 art_env->capabilities.e = 0;\
1180 changed.e = 1; \
1181 } \
Alex Lighte6574242016-08-17 09:56:24 -07001182 } \
Alex Light2ce6fc82017-12-18 16:42:36 -08001183 } while (false);
Alex Lighte6574242016-08-17 09:56:24 -07001184
Alex Light2ce6fc82017-12-18 16:42:36 -08001185 FOR_ALL_CAPABILITIES(DEL_CAPABILITY);
Alex Lighte6574242016-08-17 09:56:24 -07001186#undef DEL_CAPABILITY
Alex Light0e841182018-02-12 17:42:50 +00001187 gEventHandler->HandleChangedCapabilities(ArtJvmTiEnv::AsArtJvmTiEnv(env),
1188 changed,
Andreas Gampe6e897762018-10-16 13:09:32 -07001189 /*added=*/false);
Alex Lighte6574242016-08-17 09:56:24 -07001190 return OK;
Alex Light49948e92016-08-11 15:35:28 -07001191 }
1192
Alex Light2ce6fc82017-12-18 16:42:36 -08001193#undef FOR_ALL_CAPABILITIES
1194
Alex Light49948e92016-08-11 15:35:28 -07001195 static jvmtiError GetCapabilities(jvmtiEnv* env, jvmtiCapabilities* capabilities_ptr) {
Alex Lighte6574242016-08-17 09:56:24 -07001196 ENSURE_VALID_ENV(env);
1197 ENSURE_NON_NULL(capabilities_ptr);
1198 ArtJvmTiEnv* artenv = reinterpret_cast<ArtJvmTiEnv*>(env);
1199 *capabilities_ptr = artenv->capabilities;
1200 return OK;
Alex Light49948e92016-08-11 15:35:28 -07001201 }
1202
Alex Light6a3fd512017-02-27 14:34:32 -08001203 static jvmtiError GetCurrentThreadCpuTimerInfo(jvmtiEnv* env,
1204 jvmtiTimerInfo* info_ptr ATTRIBUTE_UNUSED) {
Alex Light1edc8cf2017-03-24 14:22:56 -07001205 ENSURE_VALID_ENV(env);
Alex Light9db679d2017-01-25 15:28:04 -08001206 ENSURE_HAS_CAP(env, can_get_current_thread_cpu_time);
Alex Light49948e92016-08-11 15:35:28 -07001207 return ERR(NOT_IMPLEMENTED);
1208 }
1209
Alex Light6a3fd512017-02-27 14:34:32 -08001210 static jvmtiError GetCurrentThreadCpuTime(jvmtiEnv* env, jlong* nanos_ptr ATTRIBUTE_UNUSED) {
Alex Light1edc8cf2017-03-24 14:22:56 -07001211 ENSURE_VALID_ENV(env);
Alex Light9db679d2017-01-25 15:28:04 -08001212 ENSURE_HAS_CAP(env, can_get_current_thread_cpu_time);
Alex Light49948e92016-08-11 15:35:28 -07001213 return ERR(NOT_IMPLEMENTED);
1214 }
1215
Alex Light6a3fd512017-02-27 14:34:32 -08001216 static jvmtiError GetThreadCpuTimerInfo(jvmtiEnv* env,
1217 jvmtiTimerInfo* info_ptr ATTRIBUTE_UNUSED) {
Alex Light1edc8cf2017-03-24 14:22:56 -07001218 ENSURE_VALID_ENV(env);
Alex Light9db679d2017-01-25 15:28:04 -08001219 ENSURE_HAS_CAP(env, can_get_thread_cpu_time);
Alex Light49948e92016-08-11 15:35:28 -07001220 return ERR(NOT_IMPLEMENTED);
1221 }
1222
Alex Light6a3fd512017-02-27 14:34:32 -08001223 static jvmtiError GetThreadCpuTime(jvmtiEnv* env,
1224 jthread thread ATTRIBUTE_UNUSED,
1225 jlong* nanos_ptr ATTRIBUTE_UNUSED) {
Alex Light1edc8cf2017-03-24 14:22:56 -07001226 ENSURE_VALID_ENV(env);
Alex Light9db679d2017-01-25 15:28:04 -08001227 ENSURE_HAS_CAP(env, can_get_thread_cpu_time);
Alex Light49948e92016-08-11 15:35:28 -07001228 return ERR(NOT_IMPLEMENTED);
1229 }
1230
1231 static jvmtiError GetTimerInfo(jvmtiEnv* env, jvmtiTimerInfo* info_ptr) {
Alex Light1edc8cf2017-03-24 14:22:56 -07001232 ENSURE_VALID_ENV(env);
Andreas Gampe35bcf812017-01-13 16:24:17 -08001233 return TimerUtil::GetTimerInfo(env, info_ptr);
Alex Light49948e92016-08-11 15:35:28 -07001234 }
1235
1236 static jvmtiError GetTime(jvmtiEnv* env, jlong* nanos_ptr) {
Alex Light1edc8cf2017-03-24 14:22:56 -07001237 ENSURE_VALID_ENV(env);
Andreas Gampe35bcf812017-01-13 16:24:17 -08001238 return TimerUtil::GetTime(env, nanos_ptr);
Alex Light49948e92016-08-11 15:35:28 -07001239 }
1240
1241 static jvmtiError GetAvailableProcessors(jvmtiEnv* env, jint* processor_count_ptr) {
Alex Light1edc8cf2017-03-24 14:22:56 -07001242 ENSURE_VALID_ENV(env);
Andreas Gampe35bcf812017-01-13 16:24:17 -08001243 return TimerUtil::GetAvailableProcessors(env, processor_count_ptr);
Alex Light49948e92016-08-11 15:35:28 -07001244 }
1245
1246 static jvmtiError AddToBootstrapClassLoaderSearch(jvmtiEnv* env, const char* segment) {
Alex Light1edc8cf2017-03-24 14:22:56 -07001247 ENSURE_VALID_ENV(env);
Andreas Gampece7732b2017-01-17 15:50:26 -08001248 return SearchUtil::AddToBootstrapClassLoaderSearch(env, segment);
Alex Light49948e92016-08-11 15:35:28 -07001249 }
1250
1251 static jvmtiError AddToSystemClassLoaderSearch(jvmtiEnv* env, const char* segment) {
Alex Light1edc8cf2017-03-24 14:22:56 -07001252 ENSURE_VALID_ENV(env);
Andreas Gampece7732b2017-01-17 15:50:26 -08001253 return SearchUtil::AddToSystemClassLoaderSearch(env, segment);
Alex Light49948e92016-08-11 15:35:28 -07001254 }
1255
1256 static jvmtiError GetSystemProperties(jvmtiEnv* env, jint* count_ptr, char*** property_ptr) {
Alex Light1edc8cf2017-03-24 14:22:56 -07001257 ENSURE_VALID_ENV(env);
Andreas Gampe1bdaf732017-01-09 19:21:06 -08001258 return PropertiesUtil::GetSystemProperties(env, count_ptr, property_ptr);
Alex Light49948e92016-08-11 15:35:28 -07001259 }
1260
1261 static jvmtiError GetSystemProperty(jvmtiEnv* env, const char* property, char** value_ptr) {
Alex Light1edc8cf2017-03-24 14:22:56 -07001262 ENSURE_VALID_ENV(env);
Andreas Gampe1bdaf732017-01-09 19:21:06 -08001263 return PropertiesUtil::GetSystemProperty(env, property, value_ptr);
Alex Light49948e92016-08-11 15:35:28 -07001264 }
1265
1266 static jvmtiError SetSystemProperty(jvmtiEnv* env, const char* property, const char* value) {
Alex Light1edc8cf2017-03-24 14:22:56 -07001267 ENSURE_VALID_ENV(env);
Andreas Gampe1bdaf732017-01-09 19:21:06 -08001268 return PropertiesUtil::SetSystemProperty(env, property, value);
Alex Light49948e92016-08-11 15:35:28 -07001269 }
1270
1271 static jvmtiError GetPhase(jvmtiEnv* env, jvmtiPhase* phase_ptr) {
Alex Light1edc8cf2017-03-24 14:22:56 -07001272 ENSURE_VALID_ENV(env);
Andreas Gampe96eca782017-01-19 19:45:30 -08001273 return PhaseUtil::GetPhase(env, phase_ptr);
Alex Light49948e92016-08-11 15:35:28 -07001274 }
1275
1276 static jvmtiError DisposeEnvironment(jvmtiEnv* env) {
Alex Lighte6574242016-08-17 09:56:24 -07001277 ENSURE_VALID_ENV(env);
Alex Light092a4042017-07-12 08:46:44 -07001278 ArtJvmTiEnv* tienv = ArtJvmTiEnv::AsArtJvmTiEnv(env);
Alex Light0e841182018-02-12 17:42:50 +00001279 gEventHandler->RemoveArtJvmTiEnv(tienv);
Alex Light092a4042017-07-12 08:46:44 -07001280 art::Runtime::Current()->RemoveSystemWeakHolder(tienv->object_tag_table.get());
1281 ThreadUtil::RemoveEnvironment(tienv);
1282 delete tienv;
Alex Light49948e92016-08-11 15:35:28 -07001283 return OK;
1284 }
1285
1286 static jvmtiError SetEnvironmentLocalStorage(jvmtiEnv* env, const void* data) {
Alex Lighte6574242016-08-17 09:56:24 -07001287 ENSURE_VALID_ENV(env);
Alex Light49948e92016-08-11 15:35:28 -07001288 reinterpret_cast<ArtJvmTiEnv*>(env)->local_data = const_cast<void*>(data);
1289 return OK;
1290 }
1291
1292 static jvmtiError GetEnvironmentLocalStorage(jvmtiEnv* env, void** data_ptr) {
Alex Lighte6574242016-08-17 09:56:24 -07001293 ENSURE_VALID_ENV(env);
Alex Light49948e92016-08-11 15:35:28 -07001294 *data_ptr = reinterpret_cast<ArtJvmTiEnv*>(env)->local_data;
1295 return OK;
1296 }
1297
1298 static jvmtiError GetVersionNumber(jvmtiEnv* env, jint* version_ptr) {
Alex Lighte6574242016-08-17 09:56:24 -07001299 ENSURE_VALID_ENV(env);
Alex Light2ce6fc82017-12-18 16:42:36 -08001300 *version_ptr = ArtJvmTiEnv::AsArtJvmTiEnv(env)->ti_version;
Alex Light49948e92016-08-11 15:35:28 -07001301 return OK;
1302 }
1303
1304 static jvmtiError GetErrorName(jvmtiEnv* env, jvmtiError error, char** name_ptr) {
Alex Lighte6574242016-08-17 09:56:24 -07001305 ENSURE_NON_NULL(name_ptr);
Andreas Gampe95c466d2017-05-08 14:50:47 -07001306 auto copy_fn = [&](const char* name_cstr) {
1307 jvmtiError res;
1308 JvmtiUniquePtr<char[]> copy = CopyString(env, name_cstr, &res);
1309 if (copy == nullptr) {
1310 *name_ptr = nullptr;
1311 return res;
1312 } else {
1313 *name_ptr = copy.release();
1314 return OK;
1315 }
1316 };
Alex Light49948e92016-08-11 15:35:28 -07001317 switch (error) {
Andreas Gampe95c466d2017-05-08 14:50:47 -07001318#define ERROR_CASE(e) case (JVMTI_ERROR_ ## e) : \
1319 return copy_fn("JVMTI_ERROR_"#e);
Alex Light49948e92016-08-11 15:35:28 -07001320 ERROR_CASE(NONE);
1321 ERROR_CASE(INVALID_THREAD);
1322 ERROR_CASE(INVALID_THREAD_GROUP);
1323 ERROR_CASE(INVALID_PRIORITY);
1324 ERROR_CASE(THREAD_NOT_SUSPENDED);
Andreas Gampe95c466d2017-05-08 14:50:47 -07001325 ERROR_CASE(THREAD_SUSPENDED);
Alex Light49948e92016-08-11 15:35:28 -07001326 ERROR_CASE(THREAD_NOT_ALIVE);
1327 ERROR_CASE(INVALID_OBJECT);
1328 ERROR_CASE(INVALID_CLASS);
1329 ERROR_CASE(CLASS_NOT_PREPARED);
1330 ERROR_CASE(INVALID_METHODID);
1331 ERROR_CASE(INVALID_LOCATION);
1332 ERROR_CASE(INVALID_FIELDID);
1333 ERROR_CASE(NO_MORE_FRAMES);
1334 ERROR_CASE(OPAQUE_FRAME);
1335 ERROR_CASE(TYPE_MISMATCH);
1336 ERROR_CASE(INVALID_SLOT);
1337 ERROR_CASE(DUPLICATE);
1338 ERROR_CASE(NOT_FOUND);
1339 ERROR_CASE(INVALID_MONITOR);
1340 ERROR_CASE(NOT_MONITOR_OWNER);
1341 ERROR_CASE(INTERRUPT);
1342 ERROR_CASE(INVALID_CLASS_FORMAT);
1343 ERROR_CASE(CIRCULAR_CLASS_DEFINITION);
1344 ERROR_CASE(FAILS_VERIFICATION);
1345 ERROR_CASE(UNSUPPORTED_REDEFINITION_METHOD_ADDED);
1346 ERROR_CASE(UNSUPPORTED_REDEFINITION_SCHEMA_CHANGED);
1347 ERROR_CASE(INVALID_TYPESTATE);
1348 ERROR_CASE(UNSUPPORTED_REDEFINITION_HIERARCHY_CHANGED);
1349 ERROR_CASE(UNSUPPORTED_REDEFINITION_METHOD_DELETED);
1350 ERROR_CASE(UNSUPPORTED_VERSION);
1351 ERROR_CASE(NAMES_DONT_MATCH);
1352 ERROR_CASE(UNSUPPORTED_REDEFINITION_CLASS_MODIFIERS_CHANGED);
1353 ERROR_CASE(UNSUPPORTED_REDEFINITION_METHOD_MODIFIERS_CHANGED);
1354 ERROR_CASE(UNMODIFIABLE_CLASS);
1355 ERROR_CASE(NOT_AVAILABLE);
1356 ERROR_CASE(MUST_POSSESS_CAPABILITY);
1357 ERROR_CASE(NULL_POINTER);
1358 ERROR_CASE(ABSENT_INFORMATION);
1359 ERROR_CASE(INVALID_EVENT_TYPE);
1360 ERROR_CASE(ILLEGAL_ARGUMENT);
1361 ERROR_CASE(NATIVE_METHOD);
1362 ERROR_CASE(CLASS_LOADER_UNSUPPORTED);
1363 ERROR_CASE(OUT_OF_MEMORY);
1364 ERROR_CASE(ACCESS_DENIED);
1365 ERROR_CASE(WRONG_PHASE);
1366 ERROR_CASE(INTERNAL);
1367 ERROR_CASE(UNATTACHED_THREAD);
1368 ERROR_CASE(INVALID_ENVIRONMENT);
1369#undef ERROR_CASE
Alex Light49948e92016-08-11 15:35:28 -07001370 }
Andreas Gampe95c466d2017-05-08 14:50:47 -07001371
1372 return ERR(ILLEGAL_ARGUMENT);
Alex Light49948e92016-08-11 15:35:28 -07001373 }
1374
Alex Light1edc8cf2017-03-24 14:22:56 -07001375 static jvmtiError SetVerboseFlag(jvmtiEnv* env,
Alex Light6a3fd512017-02-27 14:34:32 -08001376 jvmtiVerboseFlag flag,
1377 jboolean value) {
Alex Light1edc8cf2017-03-24 14:22:56 -07001378 ENSURE_VALID_ENV(env);
Alex Light8f951832020-02-24 14:31:54 -08001379 return LogUtil::SetVerboseFlag(env, flag, value);
Alex Light49948e92016-08-11 15:35:28 -07001380 }
1381
Alex Light1edc8cf2017-03-24 14:22:56 -07001382 static jvmtiError GetJLocationFormat(jvmtiEnv* env, jvmtiJlocationFormat* format_ptr) {
1383 ENSURE_VALID_ENV(env);
Andreas Gampeacfc9572017-01-17 18:36:56 -08001384 // Report BCI as jlocation format. We report dex bytecode indices.
1385 if (format_ptr == nullptr) {
1386 return ERR(NULL_POINTER);
1387 }
1388 *format_ptr = jvmtiJlocationFormat::JVMTI_JLOCATION_JVMBCI;
1389 return ERR(NONE);
Alex Light49948e92016-08-11 15:35:28 -07001390 }
1391};
1392
1393static bool IsJvmtiVersion(jint version) {
1394 return version == JVMTI_VERSION_1 ||
1395 version == JVMTI_VERSION_1_0 ||
1396 version == JVMTI_VERSION_1_1 ||
1397 version == JVMTI_VERSION_1_2 ||
1398 version == JVMTI_VERSION;
1399}
1400
Andreas Gampede19eb92017-02-24 16:21:18 -08001401extern const jvmtiInterface_1 gJvmtiInterface;
Alex Light092a4042017-07-12 08:46:44 -07001402
Alex Light2ce6fc82017-12-18 16:42:36 -08001403ArtJvmTiEnv::ArtJvmTiEnv(art::JavaVMExt* runtime, EventHandler* event_handler, jint version)
Andreas Gampede19eb92017-02-24 16:21:18 -08001404 : art_vm(runtime),
1405 local_data(nullptr),
Alex Light2ce6fc82017-12-18 16:42:36 -08001406 ti_version(version),
Alex Lightb6106d52017-10-18 15:02:15 -07001407 capabilities(),
Alex Lightae45cbb2018-10-18 15:49:56 -07001408 event_info_mutex_("jvmtiEnv_EventInfoMutex"),
1409 last_error_mutex_("jvmtiEnv_LastErrorMutex", art::LockLevel::kGenericBottomLock) {
Yi Kongc57c6802018-10-29 14:28:56 -07001410 object_tag_table = std::make_unique<ObjectTagTable>(event_handler, this);
Andreas Gampede19eb92017-02-24 16:21:18 -08001411 functions = &gJvmtiInterface;
1412}
1413
Alex Light49948e92016-08-11 15:35:28 -07001414// Creates a jvmtiEnv and returns it with the art::ti::Env that is associated with it. new_art_ti
1415// is a pointer to the uninitialized memory for an art::ti::Env.
Alex Light2ce6fc82017-12-18 16:42:36 -08001416static void CreateArtJvmTiEnv(art::JavaVMExt* vm, jint version, /*out*/void** new_jvmtiEnv) {
Alex Light0e841182018-02-12 17:42:50 +00001417 struct ArtJvmTiEnv* env = new ArtJvmTiEnv(vm, gEventHandler, version);
Alex Light49948e92016-08-11 15:35:28 -07001418 *new_jvmtiEnv = env;
Andreas Gampe77708d92016-10-07 11:48:21 -07001419
Alex Light0e841182018-02-12 17:42:50 +00001420 gEventHandler->RegisterArtJvmTiEnv(env);
Andreas Gampede19eb92017-02-24 16:21:18 -08001421
1422 art::Runtime::Current()->AddSystemWeakHolder(
1423 ArtJvmTiEnv::AsArtJvmTiEnv(env)->object_tag_table.get());
Alex Light49948e92016-08-11 15:35:28 -07001424}
1425
1426// A hook that the runtime uses to allow plugins to handle GetEnv calls. It returns true and
1427// places the return value in 'env' if this library can handle the GetEnv request. Otherwise
1428// returns false and does not modify the 'env' pointer.
1429static jint GetEnvHandler(art::JavaVMExt* vm, /*out*/void** env, jint version) {
Alex Light2ce6fc82017-12-18 16:42:36 -08001430 // JavaDebuggable will either be set by the runtime as it is starting up or the plugin if it's
1431 // loaded early enough. If this is false we cannot guarantee conformance to all JVMTI behaviors
1432 // due to optimizations. We will only allow agents to get ArtTiEnvs using the kArtTiVersion.
1433 if (IsFullJvmtiAvailable() && IsJvmtiVersion(version)) {
1434 CreateArtJvmTiEnv(vm, JVMTI_VERSION, env);
1435 return JNI_OK;
1436 } else if (version == kArtTiVersion) {
1437 CreateArtJvmTiEnv(vm, kArtTiVersion, env);
Alex Light49948e92016-08-11 15:35:28 -07001438 return JNI_OK;
1439 } else {
1440 printf("version 0x%x is not valid!", version);
Alex Light0fba1862021-01-27 16:14:30 -08001441 if (IsJvmtiVersion(version)) {
1442 LOG(ERROR) << "JVMTI Version 0x" << std::hex << version << " requested but the runtime is not"
1443 << " debuggable! Only limited, best effort kArtTiVersion"
1444 << " (0x" << std::hex << kArtTiVersion << ") environments are available. If"
1445 << " possible, rebuild your apk in debuggable mode or start the runtime with"
1446 << " the `-Xcompiler-option --debuggable` flags.";
1447 }
Alex Light49948e92016-08-11 15:35:28 -07001448 return JNI_EVERSION;
1449 }
1450}
1451
1452// The plugin initialization function. This adds the jvmti environment.
1453extern "C" bool ArtPlugin_Initialize() {
Andreas Gampee08a2be2016-10-06 13:13:30 -07001454 art::Runtime* runtime = art::Runtime::Current();
Andreas Gampe96eca782017-01-19 19:45:30 -08001455
Alex Light986914b2019-11-19 01:12:25 +00001456 gAllocManager = new AllocationManager;
Alex Light0e841182018-02-12 17:42:50 +00001457 gDeoptManager = new DeoptManager;
1458 gEventHandler = new EventHandler;
1459
1460 gDeoptManager->Setup();
Andreas Gampe96eca782017-01-19 19:45:30 -08001461 if (runtime->IsStarted()) {
1462 PhaseUtil::SetToLive();
1463 } else {
1464 PhaseUtil::SetToOnLoad();
1465 }
Alex Light0e841182018-02-12 17:42:50 +00001466 PhaseUtil::Register(gEventHandler);
1467 ThreadUtil::Register(gEventHandler);
1468 ClassUtil::Register(gEventHandler);
1469 DumpUtil::Register(gEventHandler);
1470 MethodUtil::Register(gEventHandler);
Alex Light72d7e942019-07-23 13:10:20 -07001471 HeapExtensions::Register(gEventHandler);
Andreas Gampecefaa142017-01-23 15:04:59 -08001472 SearchUtil::Register();
Andreas Gampe9e38a502017-03-06 08:19:26 -08001473 HeapUtil::Register();
Alex Lightc18eba32019-09-24 14:36:27 -07001474 FieldUtil::Register(gEventHandler);
1475 BreakpointUtil::Register(gEventHandler);
Alex Light3732beb2019-10-04 13:35:34 -07001476 Transformer::Register(gEventHandler);
Andreas Gampe96eca782017-01-19 19:45:30 -08001477
Alex Light2ce6fc82017-12-18 16:42:36 -08001478 {
1479 // Make sure we can deopt anything we need to.
Nicolas Geoffray226805d2018-12-14 10:59:02 +00001480 art::ScopedSuspendAll ssa(__FUNCTION__);
Alex Light0e841182018-02-12 17:42:50 +00001481 gDeoptManager->FinishSetup();
Alex Light2ce6fc82017-12-18 16:42:36 -08001482 }
1483
Andreas Gampee08a2be2016-10-06 13:13:30 -07001484 runtime->GetJavaVM()->AddEnvironmentHook(GetEnvHandler);
Andreas Gampe96eca782017-01-19 19:45:30 -08001485
Alex Light49948e92016-08-11 15:35:28 -07001486 return true;
1487}
1488
Andreas Gampeeafaf572017-01-20 12:34:15 -08001489extern "C" bool ArtPlugin_Deinitialize() {
Alex Light0e841182018-02-12 17:42:50 +00001490 gEventHandler->Shutdown();
1491 gDeoptManager->Shutdown();
Andreas Gampeeafaf572017-01-20 12:34:15 -08001492 PhaseUtil::Unregister();
1493 ThreadUtil::Unregister();
Andreas Gampee6377462017-01-20 17:37:50 -08001494 ClassUtil::Unregister();
Andreas Gampeeb0cea12017-01-23 08:50:04 -08001495 DumpUtil::Unregister();
Alex Lightd78ddec2017-04-18 15:20:38 -07001496 MethodUtil::Unregister();
Andreas Gampecefaa142017-01-23 15:04:59 -08001497 SearchUtil::Unregister();
Andreas Gampe9e38a502017-03-06 08:19:26 -08001498 HeapUtil::Unregister();
Alex Lightc18eba32019-09-24 14:36:27 -07001499 FieldUtil::Unregister();
1500 BreakpointUtil::Unregister();
Andreas Gampeeafaf572017-01-20 12:34:15 -08001501
Alex Light0e841182018-02-12 17:42:50 +00001502 // TODO It would be good to delete the gEventHandler and gDeoptManager here but we cannot since
1503 // daemon threads might be suspended and we want to make sure that even if they wake up briefly
1504 // they won't hit deallocated memory. By this point none of the functions will do anything since
1505 // they have already shutdown.
1506
Andreas Gampeeafaf572017-01-20 12:34:15 -08001507 return true;
1508}
1509
Alex Light49948e92016-08-11 15:35:28 -07001510// The actual struct holding all of the entrypoints into the jvmti interface.
1511const jvmtiInterface_1 gJvmtiInterface = {
Alex Light6ac57502017-01-19 15:05:06 -08001512 nullptr, // reserved1
Alex Light49948e92016-08-11 15:35:28 -07001513 JvmtiFunctions::SetEventNotificationMode,
Alex Light0e692732017-01-10 15:00:05 -08001514 nullptr, // reserved3
Alex Light49948e92016-08-11 15:35:28 -07001515 JvmtiFunctions::GetAllThreads,
1516 JvmtiFunctions::SuspendThread,
1517 JvmtiFunctions::ResumeThread,
1518 JvmtiFunctions::StopThread,
1519 JvmtiFunctions::InterruptThread,
1520 JvmtiFunctions::GetThreadInfo,
1521 JvmtiFunctions::GetOwnedMonitorInfo, // 10
1522 JvmtiFunctions::GetCurrentContendedMonitor,
1523 JvmtiFunctions::RunAgentThread,
1524 JvmtiFunctions::GetTopThreadGroups,
1525 JvmtiFunctions::GetThreadGroupInfo,
1526 JvmtiFunctions::GetThreadGroupChildren,
1527 JvmtiFunctions::GetFrameCount,
1528 JvmtiFunctions::GetThreadState,
1529 JvmtiFunctions::GetCurrentThread,
1530 JvmtiFunctions::GetFrameLocation,
1531 JvmtiFunctions::NotifyFramePop, // 20
1532 JvmtiFunctions::GetLocalObject,
1533 JvmtiFunctions::GetLocalInt,
1534 JvmtiFunctions::GetLocalLong,
1535 JvmtiFunctions::GetLocalFloat,
1536 JvmtiFunctions::GetLocalDouble,
1537 JvmtiFunctions::SetLocalObject,
1538 JvmtiFunctions::SetLocalInt,
1539 JvmtiFunctions::SetLocalLong,
1540 JvmtiFunctions::SetLocalFloat,
1541 JvmtiFunctions::SetLocalDouble, // 30
1542 JvmtiFunctions::CreateRawMonitor,
1543 JvmtiFunctions::DestroyRawMonitor,
1544 JvmtiFunctions::RawMonitorEnter,
1545 JvmtiFunctions::RawMonitorExit,
1546 JvmtiFunctions::RawMonitorWait,
1547 JvmtiFunctions::RawMonitorNotify,
1548 JvmtiFunctions::RawMonitorNotifyAll,
1549 JvmtiFunctions::SetBreakpoint,
1550 JvmtiFunctions::ClearBreakpoint,
1551 nullptr, // reserved40
1552 JvmtiFunctions::SetFieldAccessWatch,
1553 JvmtiFunctions::ClearFieldAccessWatch,
1554 JvmtiFunctions::SetFieldModificationWatch,
1555 JvmtiFunctions::ClearFieldModificationWatch,
1556 JvmtiFunctions::IsModifiableClass,
1557 JvmtiFunctions::Allocate,
1558 JvmtiFunctions::Deallocate,
1559 JvmtiFunctions::GetClassSignature,
1560 JvmtiFunctions::GetClassStatus,
1561 JvmtiFunctions::GetSourceFileName, // 50
1562 JvmtiFunctions::GetClassModifiers,
1563 JvmtiFunctions::GetClassMethods,
1564 JvmtiFunctions::GetClassFields,
1565 JvmtiFunctions::GetImplementedInterfaces,
1566 JvmtiFunctions::IsInterface,
1567 JvmtiFunctions::IsArrayClass,
1568 JvmtiFunctions::GetClassLoader,
1569 JvmtiFunctions::GetObjectHashCode,
1570 JvmtiFunctions::GetObjectMonitorUsage,
1571 JvmtiFunctions::GetFieldName, // 60
1572 JvmtiFunctions::GetFieldDeclaringClass,
1573 JvmtiFunctions::GetFieldModifiers,
1574 JvmtiFunctions::IsFieldSynthetic,
1575 JvmtiFunctions::GetMethodName,
1576 JvmtiFunctions::GetMethodDeclaringClass,
1577 JvmtiFunctions::GetMethodModifiers,
1578 nullptr, // reserved67
1579 JvmtiFunctions::GetMaxLocals,
1580 JvmtiFunctions::GetArgumentsSize,
1581 JvmtiFunctions::GetLineNumberTable, // 70
1582 JvmtiFunctions::GetMethodLocation,
1583 JvmtiFunctions::GetLocalVariableTable,
1584 JvmtiFunctions::SetNativeMethodPrefix,
1585 JvmtiFunctions::SetNativeMethodPrefixes,
1586 JvmtiFunctions::GetBytecodes,
1587 JvmtiFunctions::IsMethodNative,
1588 JvmtiFunctions::IsMethodSynthetic,
1589 JvmtiFunctions::GetLoadedClasses,
1590 JvmtiFunctions::GetClassLoaderClasses,
1591 JvmtiFunctions::PopFrame, // 80
1592 JvmtiFunctions::ForceEarlyReturnObject,
1593 JvmtiFunctions::ForceEarlyReturnInt,
1594 JvmtiFunctions::ForceEarlyReturnLong,
1595 JvmtiFunctions::ForceEarlyReturnFloat,
1596 JvmtiFunctions::ForceEarlyReturnDouble,
1597 JvmtiFunctions::ForceEarlyReturnVoid,
1598 JvmtiFunctions::RedefineClasses,
1599 JvmtiFunctions::GetVersionNumber,
1600 JvmtiFunctions::GetCapabilities,
1601 JvmtiFunctions::GetSourceDebugExtension, // 90
1602 JvmtiFunctions::IsMethodObsolete,
1603 JvmtiFunctions::SuspendThreadList,
1604 JvmtiFunctions::ResumeThreadList,
1605 nullptr, // reserved94
1606 nullptr, // reserved95
1607 nullptr, // reserved96
1608 nullptr, // reserved97
1609 nullptr, // reserved98
1610 nullptr, // reserved99
1611 JvmtiFunctions::GetAllStackTraces, // 100
1612 JvmtiFunctions::GetThreadListStackTraces,
1613 JvmtiFunctions::GetThreadLocalStorage,
1614 JvmtiFunctions::SetThreadLocalStorage,
1615 JvmtiFunctions::GetStackTrace,
1616 nullptr, // reserved105
1617 JvmtiFunctions::GetTag,
1618 JvmtiFunctions::SetTag,
1619 JvmtiFunctions::ForceGarbageCollection,
1620 JvmtiFunctions::IterateOverObjectsReachableFromObject,
1621 JvmtiFunctions::IterateOverReachableObjects, // 110
1622 JvmtiFunctions::IterateOverHeap,
1623 JvmtiFunctions::IterateOverInstancesOfClass,
1624 nullptr, // reserved113
1625 JvmtiFunctions::GetObjectsWithTags,
1626 JvmtiFunctions::FollowReferences,
1627 JvmtiFunctions::IterateThroughHeap,
1628 nullptr, // reserved117
1629 nullptr, // reserved118
1630 nullptr, // reserved119
1631 JvmtiFunctions::SetJNIFunctionTable, // 120
1632 JvmtiFunctions::GetJNIFunctionTable,
1633 JvmtiFunctions::SetEventCallbacks,
1634 JvmtiFunctions::GenerateEvents,
1635 JvmtiFunctions::GetExtensionFunctions,
1636 JvmtiFunctions::GetExtensionEvents,
1637 JvmtiFunctions::SetExtensionEventCallback,
1638 JvmtiFunctions::DisposeEnvironment,
1639 JvmtiFunctions::GetErrorName,
1640 JvmtiFunctions::GetJLocationFormat,
1641 JvmtiFunctions::GetSystemProperties, // 130
1642 JvmtiFunctions::GetSystemProperty,
1643 JvmtiFunctions::SetSystemProperty,
1644 JvmtiFunctions::GetPhase,
1645 JvmtiFunctions::GetCurrentThreadCpuTimerInfo,
1646 JvmtiFunctions::GetCurrentThreadCpuTime,
1647 JvmtiFunctions::GetThreadCpuTimerInfo,
1648 JvmtiFunctions::GetThreadCpuTime,
1649 JvmtiFunctions::GetTimerInfo,
1650 JvmtiFunctions::GetTime,
1651 JvmtiFunctions::GetPotentialCapabilities, // 140
1652 nullptr, // reserved141
1653 JvmtiFunctions::AddCapabilities,
1654 JvmtiFunctions::RelinquishCapabilities,
1655 JvmtiFunctions::GetAvailableProcessors,
1656 JvmtiFunctions::GetClassVersionNumbers,
1657 JvmtiFunctions::GetConstantPool,
1658 JvmtiFunctions::GetEnvironmentLocalStorage,
1659 JvmtiFunctions::SetEnvironmentLocalStorage,
1660 JvmtiFunctions::AddToBootstrapClassLoaderSearch,
1661 JvmtiFunctions::SetVerboseFlag, // 150
1662 JvmtiFunctions::AddToSystemClassLoaderSearch,
1663 JvmtiFunctions::RetransformClasses,
1664 JvmtiFunctions::GetOwnedMonitorStackDepthInfo,
1665 JvmtiFunctions::GetObjectSize,
1666 JvmtiFunctions::GetLocalInstance,
1667};
1668
1669}; // namespace openjdkjvmti