| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 1 | /* 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 Kong | c57c680 | 2018-10-29 14:28:56 -0700 | [diff] [blame] | 32 | #include <memory> |
| Alex Light | 9c20a14 | 2016-08-23 15:05:12 -0700 | [diff] [blame] | 33 | #include <string> |
| Andreas Gampe | f37e302 | 2017-01-13 17:54:46 -0800 | [diff] [blame] | 34 | #include <type_traits> |
| Alex Light | 9c20a14 | 2016-08-23 15:05:12 -0700 | [diff] [blame] | 35 | #include <vector> |
| 36 | |
| Andreas Gampe | 5794381 | 2017-12-06 21:39:13 -0800 | [diff] [blame] | 37 | #include <android-base/logging.h> |
| 38 | |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 39 | #include <jni.h> |
| Alex Light | 9c20a14 | 2016-08-23 15:05:12 -0700 | [diff] [blame] | 40 | |
| Andreas Gampe | 5e03a30 | 2017-03-13 13:10:00 -0700 | [diff] [blame] | 41 | #include "jvmti.h" |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 42 | |
| Alex Light | 986914b | 2019-11-19 01:12:25 +0000 | [diff] [blame] | 43 | #include "alloc_manager.h" |
| Andreas Gampe | db6dcb6 | 2016-09-13 09:05:59 -0700 | [diff] [blame] | 44 | #include "art_jvmti.h" |
| Andreas Gampe | 170331f | 2017-12-07 18:41:03 -0800 | [diff] [blame] | 45 | #include "base/logging.h" // For gLogVerbosity. |
| Andreas Gampe | 77708d9 | 2016-10-07 11:48:21 -0700 | [diff] [blame] | 46 | #include "base/mutex.h" |
| 47 | #include "events-inl.h" |
| Vladimir Marko | a3ad0cd | 2018-05-04 10:06:38 +0100 | [diff] [blame] | 48 | #include "jni/jni_env_ext-inl.h" |
| Andreas Gampe | 6dee92e | 2016-09-12 19:58:13 -0700 | [diff] [blame] | 49 | #include "obj_ptr-inl.h" |
| Alex Light | a01de59 | 2016-11-15 10:43:06 -0800 | [diff] [blame] | 50 | #include "object_tagging.h" |
| Alex Light | 9c20a14 | 2016-08-23 15:05:12 -0700 | [diff] [blame] | 51 | #include "runtime.h" |
| Andreas Gampe | 6dee92e | 2016-09-12 19:58:13 -0700 | [diff] [blame] | 52 | #include "scoped_thread_state_change-inl.h" |
| Andreas Gampe | b486a98 | 2017-06-01 13:45:54 -0700 | [diff] [blame] | 53 | #include "thread-current-inl.h" |
| Alex Light | a01de59 | 2016-11-15 10:43:06 -0800 | [diff] [blame] | 54 | #include "thread_list.h" |
| Alex Light | bf64a57 | 2017-07-05 10:34:49 -0700 | [diff] [blame] | 55 | #include "ti_allocator.h" |
| Alex Light | a26e349 | 2017-06-27 17:55:37 -0700 | [diff] [blame] | 56 | #include "ti_breakpoint.h" |
| Andreas Gampe | e492ae3 | 2016-10-28 19:34:57 -0700 | [diff] [blame] | 57 | #include "ti_class.h" |
| Andreas Gampe | eb0cea1 | 2017-01-23 08:50:04 -0800 | [diff] [blame] | 58 | #include "ti_dump.h" |
| Alex Light | 3f33c0a | 2017-11-08 10:17:37 -0800 | [diff] [blame] | 59 | #include "ti_extension.h" |
| Andreas Gampe | ab2f0d0 | 2017-01-05 17:23:45 -0800 | [diff] [blame] | 60 | #include "ti_field.h" |
| Andreas Gampe | ba8df69 | 2016-11-01 10:30:44 -0700 | [diff] [blame] | 61 | #include "ti_heap.h" |
| Andreas Gampe | 6f8e4f0 | 2017-01-16 18:18:14 -0800 | [diff] [blame] | 62 | #include "ti_jni.h" |
| Alex Light | ae45cbb | 2018-10-18 15:49:56 -0700 | [diff] [blame] | 63 | #include "ti_logging.h" |
| Andreas Gampe | 3c252f0 | 2016-10-27 18:25:17 -0700 | [diff] [blame] | 64 | #include "ti_method.h" |
| Andreas Gampe | 319dbe8 | 2017-01-09 16:42:21 -0800 | [diff] [blame] | 65 | #include "ti_monitor.h" |
| Andreas Gampe | 50a4e49 | 2017-01-06 18:00:20 -0800 | [diff] [blame] | 66 | #include "ti_object.h" |
| Andreas Gampe | 96eca78 | 2017-01-19 19:45:30 -0800 | [diff] [blame] | 67 | #include "ti_phase.h" |
| Andreas Gampe | 1bdaf73 | 2017-01-09 19:21:06 -0800 | [diff] [blame] | 68 | #include "ti_properties.h" |
| Alex Light | a01de59 | 2016-11-15 10:43:06 -0800 | [diff] [blame] | 69 | #include "ti_redefine.h" |
| Andreas Gampe | ce7732b | 2017-01-17 15:50:26 -0800 | [diff] [blame] | 70 | #include "ti_search.h" |
| Andreas Gampe | b5eb94a | 2016-10-27 19:23:09 -0700 | [diff] [blame] | 71 | #include "ti_stack.h" |
| Andreas Gampe | af13ab9 | 2017-01-11 20:57:40 -0800 | [diff] [blame] | 72 | #include "ti_thread.h" |
| Andreas Gampe | d18d9e2 | 2017-01-16 16:08:45 +0000 | [diff] [blame] | 73 | #include "ti_threadgroup.h" |
| Andreas Gampe | 35bcf81 | 2017-01-13 16:24:17 -0800 | [diff] [blame] | 74 | #include "ti_timers.h" |
| Alex Light | 9c20a14 | 2016-08-23 15:05:12 -0700 | [diff] [blame] | 75 | #include "transform.h" |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 76 | |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 77 | namespace openjdkjvmti { |
| 78 | |
| Alex Light | 0e84118 | 2018-02-12 17:42:50 +0000 | [diff] [blame] | 79 | // NB These are heap allocated to avoid the static destructors being run if an agent calls exit(3). |
| 80 | // These should never be null. |
| 81 | EventHandler* gEventHandler; |
| 82 | DeoptManager* gDeoptManager; |
| Alex Light | 986914b | 2019-11-19 01:12:25 +0000 | [diff] [blame] | 83 | AllocationManager* gAllocManager; |
| Andreas Gampe | 6dee92e | 2016-09-12 19:58:13 -0700 | [diff] [blame] | 84 | |
| Alex Light | e657424 | 2016-08-17 09:56:24 -0700 | [diff] [blame] | 85 | #define ENSURE_NON_NULL(n) \ |
| 86 | do { \ |
| 87 | if ((n) == nullptr) { \ |
| 88 | return ERR(NULL_POINTER); \ |
| 89 | } \ |
| 90 | } while (false) |
| 91 | |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 92 | class JvmtiFunctions { |
| 93 | private: |
| Alex Light | 1edc8cf | 2017-03-24 14:22:56 -0700 | [diff] [blame] | 94 | static jvmtiError getEnvironmentError(jvmtiEnv* env) { |
| 95 | if (env == nullptr) { |
| 96 | return ERR(INVALID_ENVIRONMENT); |
| 97 | } else if (art::Thread::Current() == nullptr) { |
| 98 | return ERR(UNATTACHED_THREAD); |
| 99 | } else { |
| 100 | return OK; |
| 101 | } |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 102 | } |
| 103 | |
| Alex Light | 1edc8cf | 2017-03-24 14:22:56 -0700 | [diff] [blame] | 104 | #define ENSURE_VALID_ENV(env) \ |
| 105 | do { \ |
| 106 | jvmtiError ensure_valid_env_ ## __LINE__ = getEnvironmentError(env); \ |
| 107 | if (ensure_valid_env_ ## __LINE__ != OK) { \ |
| 108 | return ensure_valid_env_ ## __LINE__ ; \ |
| 109 | } \ |
| Alex Light | e657424 | 2016-08-17 09:56:24 -0700 | [diff] [blame] | 110 | } while (false) |
| 111 | |
| 112 | #define ENSURE_HAS_CAP(env, cap) \ |
| 113 | do { \ |
| Alex Light | e657424 | 2016-08-17 09:56:24 -0700 | [diff] [blame] | 114 | if (ArtJvmTiEnv::AsArtJvmTiEnv(env)->capabilities.cap != 1) { \ |
| 115 | return ERR(MUST_POSSESS_CAPABILITY); \ |
| 116 | } \ |
| 117 | } while (false) |
| 118 | |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 119 | public: |
| 120 | static jvmtiError Allocate(jvmtiEnv* env, jlong size, unsigned char** mem_ptr) { |
| Alex Light | 6a399f3 | 2018-01-10 16:31:55 -0800 | [diff] [blame] | 121 | jvmtiError err = getEnvironmentError(env); |
| 122 | // Allow UNATTACHED_THREAD since we don't really care about that for this function. |
| 123 | if (err != OK && err != ERR(UNATTACHED_THREAD)) { |
| 124 | return err; |
| 125 | } |
| Alex Light | e657424 | 2016-08-17 09:56:24 -0700 | [diff] [blame] | 126 | ENSURE_NON_NULL(mem_ptr); |
| Alex Light | bf64a57 | 2017-07-05 10:34:49 -0700 | [diff] [blame] | 127 | return AllocUtil::Allocate(env, size, mem_ptr); |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 128 | } |
| 129 | |
| 130 | static jvmtiError Deallocate(jvmtiEnv* env, unsigned char* mem) { |
| Alex Light | 6a399f3 | 2018-01-10 16:31:55 -0800 | [diff] [blame] | 131 | jvmtiError err = getEnvironmentError(env); |
| 132 | // Allow UNATTACHED_THREAD since we don't really care about that for this function. |
| 133 | if (err != OK && err != ERR(UNATTACHED_THREAD)) { |
| 134 | return err; |
| 135 | } |
| Alex Light | bf64a57 | 2017-07-05 10:34:49 -0700 | [diff] [blame] | 136 | return AllocUtil::Deallocate(env, mem); |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 137 | } |
| 138 | |
| 139 | static jvmtiError GetThreadState(jvmtiEnv* env, jthread thread, jint* thread_state_ptr) { |
| Alex Light | 1edc8cf | 2017-03-24 14:22:56 -0700 | [diff] [blame] | 140 | ENSURE_VALID_ENV(env); |
| Andreas Gampe | 72c1983 | 2017-01-12 13:22:16 -0800 | [diff] [blame] | 141 | return ThreadUtil::GetThreadState(env, thread, thread_state_ptr); |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 142 | } |
| 143 | |
| 144 | static jvmtiError GetCurrentThread(jvmtiEnv* env, jthread* thread_ptr) { |
| Alex Light | 1edc8cf | 2017-03-24 14:22:56 -0700 | [diff] [blame] | 145 | ENSURE_VALID_ENV(env); |
| Andreas Gampe | af13ab9 | 2017-01-11 20:57:40 -0800 | [diff] [blame] | 146 | return ThreadUtil::GetCurrentThread(env, thread_ptr); |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | static jvmtiError GetAllThreads(jvmtiEnv* env, jint* threads_count_ptr, jthread** threads_ptr) { |
| Alex Light | 1edc8cf | 2017-03-24 14:22:56 -0700 | [diff] [blame] | 150 | ENSURE_VALID_ENV(env); |
| Andreas Gampe | 8580744 | 2017-01-13 14:40:58 -0800 | [diff] [blame] | 151 | return ThreadUtil::GetAllThreads(env, threads_count_ptr, threads_ptr); |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 152 | } |
| 153 | |
| Alex Light | 88fd720 | 2017-06-30 08:31:59 -0700 | [diff] [blame] | 154 | static jvmtiError SuspendThread(jvmtiEnv* env, jthread thread) { |
| Alex Light | 1edc8cf | 2017-03-24 14:22:56 -0700 | [diff] [blame] | 155 | ENSURE_VALID_ENV(env); |
| Alex Light | 9db679d | 2017-01-25 15:28:04 -0800 | [diff] [blame] | 156 | ENSURE_HAS_CAP(env, can_suspend); |
| Alex Light | 88fd720 | 2017-06-30 08:31:59 -0700 | [diff] [blame] | 157 | return ThreadUtil::SuspendThread(env, thread); |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 158 | } |
| 159 | |
| 160 | static jvmtiError SuspendThreadList(jvmtiEnv* env, |
| Alex Light | 88fd720 | 2017-06-30 08:31:59 -0700 | [diff] [blame] | 161 | jint request_count, |
| 162 | const jthread* request_list, |
| 163 | jvmtiError* results) { |
| Alex Light | 1edc8cf | 2017-03-24 14:22:56 -0700 | [diff] [blame] | 164 | ENSURE_VALID_ENV(env); |
| Alex Light | 9db679d | 2017-01-25 15:28:04 -0800 | [diff] [blame] | 165 | ENSURE_HAS_CAP(env, can_suspend); |
| Alex Light | 88fd720 | 2017-06-30 08:31:59 -0700 | [diff] [blame] | 166 | return ThreadUtil::SuspendThreadList(env, request_count, request_list, results); |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 167 | } |
| 168 | |
| Alex Light | 88fd720 | 2017-06-30 08:31:59 -0700 | [diff] [blame] | 169 | static jvmtiError ResumeThread(jvmtiEnv* env, jthread thread) { |
| Alex Light | 1edc8cf | 2017-03-24 14:22:56 -0700 | [diff] [blame] | 170 | ENSURE_VALID_ENV(env); |
| Alex Light | 9db679d | 2017-01-25 15:28:04 -0800 | [diff] [blame] | 171 | ENSURE_HAS_CAP(env, can_suspend); |
| Alex Light | 88fd720 | 2017-06-30 08:31:59 -0700 | [diff] [blame] | 172 | return ThreadUtil::ResumeThread(env, thread); |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 173 | } |
| 174 | |
| 175 | static jvmtiError ResumeThreadList(jvmtiEnv* env, |
| Alex Light | 88fd720 | 2017-06-30 08:31:59 -0700 | [diff] [blame] | 176 | jint request_count, |
| 177 | const jthread* request_list, |
| 178 | jvmtiError* results) { |
| Alex Light | 1edc8cf | 2017-03-24 14:22:56 -0700 | [diff] [blame] | 179 | ENSURE_VALID_ENV(env); |
| Alex Light | 9db679d | 2017-01-25 15:28:04 -0800 | [diff] [blame] | 180 | ENSURE_HAS_CAP(env, can_suspend); |
| Alex Light | 88fd720 | 2017-06-30 08:31:59 -0700 | [diff] [blame] | 181 | return ThreadUtil::ResumeThreadList(env, request_count, request_list, results); |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 182 | } |
| 183 | |
| Alex Light | 54d39dc | 2017-09-25 17:00:16 -0700 | [diff] [blame] | 184 | static jvmtiError StopThread(jvmtiEnv* env, jthread thread, jobject exception) { |
| Alex Light | 1edc8cf | 2017-03-24 14:22:56 -0700 | [diff] [blame] | 185 | ENSURE_VALID_ENV(env); |
| Alex Light | 9db679d | 2017-01-25 15:28:04 -0800 | [diff] [blame] | 186 | ENSURE_HAS_CAP(env, can_signal_thread); |
| Alex Light | 54d39dc | 2017-09-25 17:00:16 -0700 | [diff] [blame] | 187 | return ThreadUtil::StopThread(env, thread, exception); |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 188 | } |
| 189 | |
| Alex Light | 54d39dc | 2017-09-25 17:00:16 -0700 | [diff] [blame] | 190 | static jvmtiError InterruptThread(jvmtiEnv* env, jthread thread) { |
| Alex Light | 1edc8cf | 2017-03-24 14:22:56 -0700 | [diff] [blame] | 191 | ENSURE_VALID_ENV(env); |
| Alex Light | 9db679d | 2017-01-25 15:28:04 -0800 | [diff] [blame] | 192 | ENSURE_HAS_CAP(env, can_signal_thread); |
| Alex Light | 54d39dc | 2017-09-25 17:00:16 -0700 | [diff] [blame] | 193 | return ThreadUtil::InterruptThread(env, thread); |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 194 | } |
| 195 | |
| 196 | static jvmtiError GetThreadInfo(jvmtiEnv* env, jthread thread, jvmtiThreadInfo* info_ptr) { |
| Alex Light | 1edc8cf | 2017-03-24 14:22:56 -0700 | [diff] [blame] | 197 | ENSURE_VALID_ENV(env); |
| Andreas Gampe | af13ab9 | 2017-01-11 20:57:40 -0800 | [diff] [blame] | 198 | return ThreadUtil::GetThreadInfo(env, thread, info_ptr); |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 199 | } |
| 200 | |
| 201 | static jvmtiError GetOwnedMonitorInfo(jvmtiEnv* env, |
| Alex Light | 88e1ddd | 2017-08-21 13:09:55 -0700 | [diff] [blame] | 202 | jthread thread, |
| 203 | jint* owned_monitor_count_ptr, |
| 204 | jobject** owned_monitors_ptr) { |
| Alex Light | 1edc8cf | 2017-03-24 14:22:56 -0700 | [diff] [blame] | 205 | ENSURE_VALID_ENV(env); |
| Alex Light | 9db679d | 2017-01-25 15:28:04 -0800 | [diff] [blame] | 206 | ENSURE_HAS_CAP(env, can_get_owned_monitor_info); |
| Alex Light | 88e1ddd | 2017-08-21 13:09:55 -0700 | [diff] [blame] | 207 | return StackUtil::GetOwnedMonitorInfo(env, |
| 208 | thread, |
| 209 | owned_monitor_count_ptr, |
| 210 | owned_monitors_ptr); |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 211 | } |
| 212 | |
| Alex Light | 88e1ddd | 2017-08-21 13:09:55 -0700 | [diff] [blame] | 213 | static jvmtiError GetOwnedMonitorStackDepthInfo(jvmtiEnv* env, |
| 214 | jthread thread, |
| 215 | jint* monitor_info_count_ptr, |
| 216 | jvmtiMonitorStackDepthInfo** monitor_info_ptr) { |
| Alex Light | 1edc8cf | 2017-03-24 14:22:56 -0700 | [diff] [blame] | 217 | ENSURE_VALID_ENV(env); |
| Alex Light | 9db679d | 2017-01-25 15:28:04 -0800 | [diff] [blame] | 218 | ENSURE_HAS_CAP(env, can_get_owned_monitor_stack_depth_info); |
| Alex Light | 88e1ddd | 2017-08-21 13:09:55 -0700 | [diff] [blame] | 219 | return StackUtil::GetOwnedMonitorStackDepthInfo(env, |
| 220 | thread, |
| 221 | monitor_info_count_ptr, |
| 222 | monitor_info_ptr); |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 223 | } |
| 224 | |
| 225 | static jvmtiError GetCurrentContendedMonitor(jvmtiEnv* env, |
| Alex Light | 41006c6 | 2017-09-14 09:51:14 -0700 | [diff] [blame] | 226 | jthread thread, |
| 227 | jobject* monitor_ptr) { |
| Alex Light | 1edc8cf | 2017-03-24 14:22:56 -0700 | [diff] [blame] | 228 | ENSURE_VALID_ENV(env); |
| Alex Light | 9db679d | 2017-01-25 15:28:04 -0800 | [diff] [blame] | 229 | ENSURE_HAS_CAP(env, can_get_current_contended_monitor); |
| Alex Light | 41006c6 | 2017-09-14 09:51:14 -0700 | [diff] [blame] | 230 | return MonitorUtil::GetCurrentContendedMonitor(env, thread, monitor_ptr); |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 231 | } |
| 232 | |
| 233 | static jvmtiError RunAgentThread(jvmtiEnv* env, |
| 234 | jthread thread, |
| 235 | jvmtiStartFunction proc, |
| 236 | const void* arg, |
| 237 | jint priority) { |
| Alex Light | 1edc8cf | 2017-03-24 14:22:56 -0700 | [diff] [blame] | 238 | ENSURE_VALID_ENV(env); |
| Andreas Gampe | 732b0ac | 2017-01-18 15:23:39 -0800 | [diff] [blame] | 239 | return ThreadUtil::RunAgentThread(env, thread, proc, arg, priority); |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 240 | } |
| 241 | |
| 242 | static jvmtiError SetThreadLocalStorage(jvmtiEnv* env, jthread thread, const void* data) { |
| Alex Light | 1edc8cf | 2017-03-24 14:22:56 -0700 | [diff] [blame] | 243 | ENSURE_VALID_ENV(env); |
| Andreas Gampe | 7b3b326 | 2017-01-19 20:40:42 -0800 | [diff] [blame] | 244 | return ThreadUtil::SetThreadLocalStorage(env, thread, data); |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 245 | } |
| 246 | |
| 247 | static jvmtiError GetThreadLocalStorage(jvmtiEnv* env, jthread thread, void** data_ptr) { |
| Alex Light | 1edc8cf | 2017-03-24 14:22:56 -0700 | [diff] [blame] | 248 | ENSURE_VALID_ENV(env); |
| Andreas Gampe | 7b3b326 | 2017-01-19 20:40:42 -0800 | [diff] [blame] | 249 | return ThreadUtil::GetThreadLocalStorage(env, thread, data_ptr); |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 250 | } |
| 251 | |
| 252 | static jvmtiError GetTopThreadGroups(jvmtiEnv* env, |
| 253 | jint* group_count_ptr, |
| 254 | jthreadGroup** groups_ptr) { |
| Alex Light | 1edc8cf | 2017-03-24 14:22:56 -0700 | [diff] [blame] | 255 | ENSURE_VALID_ENV(env); |
| Andreas Gampe | d18d9e2 | 2017-01-16 16:08:45 +0000 | [diff] [blame] | 256 | return ThreadGroupUtil::GetTopThreadGroups(env, group_count_ptr, groups_ptr); |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 257 | } |
| 258 | |
| 259 | static jvmtiError GetThreadGroupInfo(jvmtiEnv* env, |
| 260 | jthreadGroup group, |
| 261 | jvmtiThreadGroupInfo* info_ptr) { |
| Alex Light | 1edc8cf | 2017-03-24 14:22:56 -0700 | [diff] [blame] | 262 | ENSURE_VALID_ENV(env); |
| Andreas Gampe | d18d9e2 | 2017-01-16 16:08:45 +0000 | [diff] [blame] | 263 | return ThreadGroupUtil::GetThreadGroupInfo(env, group, info_ptr); |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 264 | } |
| 265 | |
| 266 | static jvmtiError GetThreadGroupChildren(jvmtiEnv* env, |
| 267 | jthreadGroup group, |
| 268 | jint* thread_count_ptr, |
| 269 | jthread** threads_ptr, |
| 270 | jint* group_count_ptr, |
| 271 | jthreadGroup** groups_ptr) { |
| Alex Light | 1edc8cf | 2017-03-24 14:22:56 -0700 | [diff] [blame] | 272 | ENSURE_VALID_ENV(env); |
| Andreas Gampe | d18d9e2 | 2017-01-16 16:08:45 +0000 | [diff] [blame] | 273 | return ThreadGroupUtil::GetThreadGroupChildren(env, |
| 274 | group, |
| 275 | thread_count_ptr, |
| 276 | threads_ptr, |
| 277 | group_count_ptr, |
| 278 | groups_ptr); |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 279 | } |
| 280 | |
| 281 | static jvmtiError GetStackTrace(jvmtiEnv* env, |
| 282 | jthread thread, |
| 283 | jint start_depth, |
| 284 | jint max_frame_count, |
| 285 | jvmtiFrameInfo* frame_buffer, |
| 286 | jint* count_ptr) { |
| Alex Light | 1edc8cf | 2017-03-24 14:22:56 -0700 | [diff] [blame] | 287 | ENSURE_VALID_ENV(env); |
| Andreas Gampe | b5eb94a | 2016-10-27 19:23:09 -0700 | [diff] [blame] | 288 | return StackUtil::GetStackTrace(env, |
| 289 | thread, |
| 290 | start_depth, |
| 291 | max_frame_count, |
| 292 | frame_buffer, |
| 293 | count_ptr); |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 294 | } |
| 295 | |
| 296 | static jvmtiError GetAllStackTraces(jvmtiEnv* env, |
| 297 | jint max_frame_count, |
| 298 | jvmtiStackInfo** stack_info_ptr, |
| 299 | jint* thread_count_ptr) { |
| Alex Light | 1edc8cf | 2017-03-24 14:22:56 -0700 | [diff] [blame] | 300 | ENSURE_VALID_ENV(env); |
| Andreas Gampe | a1a27c6 | 2017-01-11 16:37:16 -0800 | [diff] [blame] | 301 | return StackUtil::GetAllStackTraces(env, max_frame_count, stack_info_ptr, thread_count_ptr); |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 302 | } |
| 303 | |
| 304 | static jvmtiError GetThreadListStackTraces(jvmtiEnv* env, |
| 305 | jint thread_count, |
| 306 | const jthread* thread_list, |
| 307 | jint max_frame_count, |
| 308 | jvmtiStackInfo** stack_info_ptr) { |
| Alex Light | 1edc8cf | 2017-03-24 14:22:56 -0700 | [diff] [blame] | 309 | ENSURE_VALID_ENV(env); |
| Andreas Gampe | eba32fb | 2017-01-12 17:40:05 -0800 | [diff] [blame] | 310 | return StackUtil::GetThreadListStackTraces(env, |
| 311 | thread_count, |
| 312 | thread_list, |
| 313 | max_frame_count, |
| 314 | stack_info_ptr); |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 315 | } |
| 316 | |
| 317 | static jvmtiError GetFrameCount(jvmtiEnv* env, jthread thread, jint* count_ptr) { |
| Alex Light | 1edc8cf | 2017-03-24 14:22:56 -0700 | [diff] [blame] | 318 | ENSURE_VALID_ENV(env); |
| Andreas Gampe | f6f3b5f | 2017-01-13 09:21:42 -0800 | [diff] [blame] | 319 | return StackUtil::GetFrameCount(env, thread, count_ptr); |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 320 | } |
| 321 | |
| Alex Light | 0aa7a5a | 2018-10-10 15:58:14 +0000 | [diff] [blame] | 322 | static jvmtiError PopFrame(jvmtiEnv* env, jthread thread) { |
| Alex Light | 1edc8cf | 2017-03-24 14:22:56 -0700 | [diff] [blame] | 323 | ENSURE_VALID_ENV(env); |
| Alex Light | 9db679d | 2017-01-25 15:28:04 -0800 | [diff] [blame] | 324 | ENSURE_HAS_CAP(env, can_pop_frame); |
| Alex Light | 0aa7a5a | 2018-10-10 15:58:14 +0000 | [diff] [blame] | 325 | return StackUtil::PopFrame(env, thread); |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 326 | } |
| 327 | |
| 328 | static jvmtiError GetFrameLocation(jvmtiEnv* env, |
| 329 | jthread thread, |
| 330 | jint depth, |
| 331 | jmethodID* method_ptr, |
| 332 | jlocation* location_ptr) { |
| Alex Light | 1edc8cf | 2017-03-24 14:22:56 -0700 | [diff] [blame] | 333 | ENSURE_VALID_ENV(env); |
| Andreas Gampe | f6f3b5f | 2017-01-13 09:21:42 -0800 | [diff] [blame] | 334 | return StackUtil::GetFrameLocation(env, thread, depth, method_ptr, location_ptr); |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 335 | } |
| 336 | |
| Alex Light | e814f9d | 2017-07-31 16:14:39 -0700 | [diff] [blame] | 337 | static jvmtiError NotifyFramePop(jvmtiEnv* env, jthread thread, jint depth) { |
| Alex Light | 1edc8cf | 2017-03-24 14:22:56 -0700 | [diff] [blame] | 338 | ENSURE_VALID_ENV(env); |
| Alex Light | 9db679d | 2017-01-25 15:28:04 -0800 | [diff] [blame] | 339 | ENSURE_HAS_CAP(env, can_generate_frame_pop_events); |
| Alex Light | e814f9d | 2017-07-31 16:14:39 -0700 | [diff] [blame] | 340 | return StackUtil::NotifyFramePop(env, thread, depth); |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 341 | } |
| 342 | |
| Alex Light | b7c640d | 2019-03-20 15:52:13 -0700 | [diff] [blame] | 343 | static jvmtiError ForceEarlyReturnObject(jvmtiEnv* env, jthread thread, jobject value) { |
| Alex Light | 1edc8cf | 2017-03-24 14:22:56 -0700 | [diff] [blame] | 344 | ENSURE_VALID_ENV(env); |
| Alex Light | 9db679d | 2017-01-25 15:28:04 -0800 | [diff] [blame] | 345 | ENSURE_HAS_CAP(env, can_force_early_return); |
| Alex Light | b7c640d | 2019-03-20 15:52:13 -0700 | [diff] [blame] | 346 | return StackUtil::ForceEarlyReturn(env, gEventHandler, thread, value); |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 347 | } |
| 348 | |
| Alex Light | b7c640d | 2019-03-20 15:52:13 -0700 | [diff] [blame] | 349 | static jvmtiError ForceEarlyReturnInt(jvmtiEnv* env, jthread thread, jint value) { |
| Alex Light | 1edc8cf | 2017-03-24 14:22:56 -0700 | [diff] [blame] | 350 | ENSURE_VALID_ENV(env); |
| Alex Light | 9db679d | 2017-01-25 15:28:04 -0800 | [diff] [blame] | 351 | ENSURE_HAS_CAP(env, can_force_early_return); |
| Alex Light | b7c640d | 2019-03-20 15:52:13 -0700 | [diff] [blame] | 352 | return StackUtil::ForceEarlyReturn(env, gEventHandler, thread, value); |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 353 | } |
| 354 | |
| Alex Light | b7c640d | 2019-03-20 15:52:13 -0700 | [diff] [blame] | 355 | static jvmtiError ForceEarlyReturnLong(jvmtiEnv* env, jthread thread, jlong value) { |
| Alex Light | 1edc8cf | 2017-03-24 14:22:56 -0700 | [diff] [blame] | 356 | ENSURE_VALID_ENV(env); |
| Alex Light | 9db679d | 2017-01-25 15:28:04 -0800 | [diff] [blame] | 357 | ENSURE_HAS_CAP(env, can_force_early_return); |
| Alex Light | b7c640d | 2019-03-20 15:52:13 -0700 | [diff] [blame] | 358 | return StackUtil::ForceEarlyReturn(env, gEventHandler, thread, value); |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 359 | } |
| 360 | |
| Alex Light | b7c640d | 2019-03-20 15:52:13 -0700 | [diff] [blame] | 361 | static jvmtiError ForceEarlyReturnFloat(jvmtiEnv* env, jthread thread, jfloat value) { |
| Alex Light | 1edc8cf | 2017-03-24 14:22:56 -0700 | [diff] [blame] | 362 | ENSURE_VALID_ENV(env); |
| Alex Light | 9db679d | 2017-01-25 15:28:04 -0800 | [diff] [blame] | 363 | ENSURE_HAS_CAP(env, can_force_early_return); |
| Alex Light | b7c640d | 2019-03-20 15:52:13 -0700 | [diff] [blame] | 364 | return StackUtil::ForceEarlyReturn(env, gEventHandler, thread, value); |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 365 | } |
| 366 | |
| Alex Light | b7c640d | 2019-03-20 15:52:13 -0700 | [diff] [blame] | 367 | static jvmtiError ForceEarlyReturnDouble(jvmtiEnv* env, jthread thread, jdouble value) { |
| Alex Light | 1edc8cf | 2017-03-24 14:22:56 -0700 | [diff] [blame] | 368 | ENSURE_VALID_ENV(env); |
| Alex Light | 9db679d | 2017-01-25 15:28:04 -0800 | [diff] [blame] | 369 | ENSURE_HAS_CAP(env, can_force_early_return); |
| Alex Light | b7c640d | 2019-03-20 15:52:13 -0700 | [diff] [blame] | 370 | return StackUtil::ForceEarlyReturn(env, gEventHandler, thread, value); |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 371 | } |
| 372 | |
| Alex Light | b7c640d | 2019-03-20 15:52:13 -0700 | [diff] [blame] | 373 | static jvmtiError ForceEarlyReturnVoid(jvmtiEnv* env, jthread thread) { |
| Alex Light | 1edc8cf | 2017-03-24 14:22:56 -0700 | [diff] [blame] | 374 | ENSURE_VALID_ENV(env); |
| Alex Light | 9db679d | 2017-01-25 15:28:04 -0800 | [diff] [blame] | 375 | ENSURE_HAS_CAP(env, can_force_early_return); |
| Alex Light | b7c640d | 2019-03-20 15:52:13 -0700 | [diff] [blame] | 376 | return StackUtil::ForceEarlyReturn<nullptr_t>(env, gEventHandler, thread, nullptr); |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 377 | } |
| 378 | |
| 379 | static jvmtiError FollowReferences(jvmtiEnv* env, |
| 380 | jint heap_filter, |
| 381 | jclass klass, |
| 382 | jobject initial_object, |
| 383 | const jvmtiHeapCallbacks* callbacks, |
| 384 | const void* user_data) { |
| Alex Light | 1edc8cf | 2017-03-24 14:22:56 -0700 | [diff] [blame] | 385 | ENSURE_VALID_ENV(env); |
| Alex Light | 9db679d | 2017-01-25 15:28:04 -0800 | [diff] [blame] | 386 | ENSURE_HAS_CAP(env, can_tag_objects); |
| Andreas Gampe | de19eb9 | 2017-02-24 16:21:18 -0800 | [diff] [blame] | 387 | HeapUtil heap_util(ArtJvmTiEnv::AsArtJvmTiEnv(env)->object_tag_table.get()); |
| Andreas Gampe | 70bfc8a | 2016-11-03 11:04:15 -0700 | [diff] [blame] | 388 | return heap_util.FollowReferences(env, |
| 389 | heap_filter, |
| 390 | klass, |
| 391 | initial_object, |
| 392 | callbacks, |
| 393 | user_data); |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 394 | } |
| 395 | |
| 396 | static jvmtiError IterateThroughHeap(jvmtiEnv* env, |
| 397 | jint heap_filter, |
| 398 | jclass klass, |
| 399 | const jvmtiHeapCallbacks* callbacks, |
| 400 | const void* user_data) { |
| Alex Light | 1edc8cf | 2017-03-24 14:22:56 -0700 | [diff] [blame] | 401 | ENSURE_VALID_ENV(env); |
| Alex Light | e657424 | 2016-08-17 09:56:24 -0700 | [diff] [blame] | 402 | ENSURE_HAS_CAP(env, can_tag_objects); |
| Andreas Gampe | de19eb9 | 2017-02-24 16:21:18 -0800 | [diff] [blame] | 403 | HeapUtil heap_util(ArtJvmTiEnv::AsArtJvmTiEnv(env)->object_tag_table.get()); |
| Andreas Gampe | e54d992 | 2016-10-11 19:55:37 -0700 | [diff] [blame] | 404 | return heap_util.IterateThroughHeap(env, heap_filter, klass, callbacks, user_data); |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 405 | } |
| 406 | |
| 407 | static jvmtiError GetTag(jvmtiEnv* env, jobject object, jlong* tag_ptr) { |
| Alex Light | 1edc8cf | 2017-03-24 14:22:56 -0700 | [diff] [blame] | 408 | ENSURE_VALID_ENV(env); |
| Alex Light | e657424 | 2016-08-17 09:56:24 -0700 | [diff] [blame] | 409 | ENSURE_HAS_CAP(env, can_tag_objects); |
| Andreas Gampe | 6dee92e | 2016-09-12 19:58:13 -0700 | [diff] [blame] | 410 | |
| 411 | JNIEnv* jni_env = GetJniEnv(env); |
| 412 | if (jni_env == nullptr) { |
| 413 | return ERR(INTERNAL); |
| 414 | } |
| 415 | |
| 416 | art::ScopedObjectAccess soa(jni_env); |
| 417 | art::ObjPtr<art::mirror::Object> obj = soa.Decode<art::mirror::Object>(object); |
| Andreas Gampe | de19eb9 | 2017-02-24 16:21:18 -0800 | [diff] [blame] | 418 | if (!ArtJvmTiEnv::AsArtJvmTiEnv(env)->object_tag_table->GetTag(obj.Ptr(), tag_ptr)) { |
| Andreas Gampe | 6dee92e | 2016-09-12 19:58:13 -0700 | [diff] [blame] | 419 | *tag_ptr = 0; |
| 420 | } |
| 421 | |
| 422 | return ERR(NONE); |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 423 | } |
| 424 | |
| 425 | static jvmtiError SetTag(jvmtiEnv* env, jobject object, jlong tag) { |
| Alex Light | 1edc8cf | 2017-03-24 14:22:56 -0700 | [diff] [blame] | 426 | ENSURE_VALID_ENV(env); |
| Alex Light | e657424 | 2016-08-17 09:56:24 -0700 | [diff] [blame] | 427 | ENSURE_HAS_CAP(env, can_tag_objects); |
| 428 | |
| Andreas Gampe | 6dee92e | 2016-09-12 19:58:13 -0700 | [diff] [blame] | 429 | if (object == nullptr) { |
| 430 | return ERR(NULL_POINTER); |
| 431 | } |
| 432 | |
| 433 | JNIEnv* jni_env = GetJniEnv(env); |
| 434 | if (jni_env == nullptr) { |
| 435 | return ERR(INTERNAL); |
| 436 | } |
| 437 | |
| 438 | art::ScopedObjectAccess soa(jni_env); |
| 439 | art::ObjPtr<art::mirror::Object> obj = soa.Decode<art::mirror::Object>(object); |
| Andreas Gampe | de19eb9 | 2017-02-24 16:21:18 -0800 | [diff] [blame] | 440 | ArtJvmTiEnv::AsArtJvmTiEnv(env)->object_tag_table->Set(obj.Ptr(), tag); |
| Andreas Gampe | 6dee92e | 2016-09-12 19:58:13 -0700 | [diff] [blame] | 441 | |
| 442 | return ERR(NONE); |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 443 | } |
| 444 | |
| 445 | static jvmtiError GetObjectsWithTags(jvmtiEnv* env, |
| 446 | jint tag_count, |
| 447 | const jlong* tags, |
| 448 | jint* count_ptr, |
| 449 | jobject** object_result_ptr, |
| 450 | jlong** tag_result_ptr) { |
| Alex Light | 1edc8cf | 2017-03-24 14:22:56 -0700 | [diff] [blame] | 451 | ENSURE_VALID_ENV(env); |
| Alex Light | e657424 | 2016-08-17 09:56:24 -0700 | [diff] [blame] | 452 | ENSURE_HAS_CAP(env, can_tag_objects); |
| 453 | |
| Andreas Gampe | 5e6046b | 2016-10-25 12:05:53 -0700 | [diff] [blame] | 454 | JNIEnv* jni_env = GetJniEnv(env); |
| 455 | if (jni_env == nullptr) { |
| 456 | return ERR(INTERNAL); |
| 457 | } |
| 458 | |
| 459 | art::ScopedObjectAccess soa(jni_env); |
| Andreas Gampe | de19eb9 | 2017-02-24 16:21:18 -0800 | [diff] [blame] | 460 | return ArtJvmTiEnv::AsArtJvmTiEnv(env)->object_tag_table->GetTaggedObjects(env, |
| 461 | tag_count, |
| 462 | tags, |
| 463 | count_ptr, |
| 464 | object_result_ptr, |
| 465 | tag_result_ptr); |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 466 | } |
| 467 | |
| 468 | static jvmtiError ForceGarbageCollection(jvmtiEnv* env) { |
| Alex Light | 1edc8cf | 2017-03-24 14:22:56 -0700 | [diff] [blame] | 469 | ENSURE_VALID_ENV(env); |
| Andreas Gampe | 8da6d03 | 2016-10-31 19:31:03 -0700 | [diff] [blame] | 470 | return HeapUtil::ForceGarbageCollection(env); |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 471 | } |
| 472 | |
| 473 | static jvmtiError IterateOverObjectsReachableFromObject( |
| 474 | jvmtiEnv* env, |
| Stefano Cianciulli | 78f3c72 | 2023-05-16 10:32:54 +0000 | [diff] [blame] | 475 | [[maybe_unused]] jobject object, |
| 476 | [[maybe_unused]] jvmtiObjectReferenceCallback object_reference_callback, |
| 477 | [[maybe_unused]] const void* user_data) { |
| Alex Light | 1edc8cf | 2017-03-24 14:22:56 -0700 | [diff] [blame] | 478 | ENSURE_VALID_ENV(env); |
| Alex Light | 9db679d | 2017-01-25 15:28:04 -0800 | [diff] [blame] | 479 | ENSURE_HAS_CAP(env, can_tag_objects); |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 480 | return ERR(NOT_IMPLEMENTED); |
| 481 | } |
| 482 | |
| Alex Light | 6a3fd51 | 2017-02-27 14:34:32 -0800 | [diff] [blame] | 483 | static jvmtiError IterateOverReachableObjects( |
| 484 | jvmtiEnv* env, |
| Stefano Cianciulli | 78f3c72 | 2023-05-16 10:32:54 +0000 | [diff] [blame] | 485 | [[maybe_unused]] jvmtiHeapRootCallback heap_root_callback, |
| 486 | [[maybe_unused]] jvmtiStackReferenceCallback stack_ref_callback, |
| 487 | [[maybe_unused]] jvmtiObjectReferenceCallback object_ref_callback, |
| 488 | [[maybe_unused]] const void* user_data) { |
| Alex Light | 1edc8cf | 2017-03-24 14:22:56 -0700 | [diff] [blame] | 489 | ENSURE_VALID_ENV(env); |
| Alex Light | 9db679d | 2017-01-25 15:28:04 -0800 | [diff] [blame] | 490 | ENSURE_HAS_CAP(env, can_tag_objects); |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 491 | return ERR(NOT_IMPLEMENTED); |
| 492 | } |
| 493 | |
| 494 | static jvmtiError IterateOverHeap(jvmtiEnv* env, |
| Stefano Cianciulli | 78f3c72 | 2023-05-16 10:32:54 +0000 | [diff] [blame] | 495 | [[maybe_unused]] jvmtiHeapObjectFilter object_filter, |
| 496 | [[maybe_unused]] jvmtiHeapObjectCallback heap_object_callback, |
| 497 | [[maybe_unused]] const void* user_data) { |
| Alex Light | 1edc8cf | 2017-03-24 14:22:56 -0700 | [diff] [blame] | 498 | ENSURE_VALID_ENV(env); |
| Alex Light | 9db679d | 2017-01-25 15:28:04 -0800 | [diff] [blame] | 499 | ENSURE_HAS_CAP(env, can_tag_objects); |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 500 | return ERR(NOT_IMPLEMENTED); |
| 501 | } |
| 502 | |
| Alex Light | 6a3fd51 | 2017-02-27 14:34:32 -0800 | [diff] [blame] | 503 | static jvmtiError IterateOverInstancesOfClass( |
| 504 | jvmtiEnv* env, |
| Alex Light | bbbcb53 | 2018-08-30 12:50:27 -0700 | [diff] [blame] | 505 | jclass klass, |
| 506 | jvmtiHeapObjectFilter object_filter, |
| 507 | jvmtiHeapObjectCallback heap_object_callback, |
| 508 | const void* user_data) { |
| Alex Light | 1edc8cf | 2017-03-24 14:22:56 -0700 | [diff] [blame] | 509 | ENSURE_VALID_ENV(env); |
| Alex Light | 9db679d | 2017-01-25 15:28:04 -0800 | [diff] [blame] | 510 | ENSURE_HAS_CAP(env, can_tag_objects); |
| Alex Light | bbbcb53 | 2018-08-30 12:50:27 -0700 | [diff] [blame] | 511 | HeapUtil heap_util(ArtJvmTiEnv::AsArtJvmTiEnv(env)->object_tag_table.get()); |
| 512 | return heap_util.IterateOverInstancesOfClass( |
| 513 | env, klass, object_filter, heap_object_callback, user_data); |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 514 | } |
| 515 | |
| 516 | static jvmtiError GetLocalObject(jvmtiEnv* env, |
| Alex Light | bebd7bd | 2017-07-25 14:05:52 -0700 | [diff] [blame] | 517 | jthread thread, |
| 518 | jint depth, |
| 519 | jint slot, |
| 520 | jobject* value_ptr) { |
| Alex Light | 1edc8cf | 2017-03-24 14:22:56 -0700 | [diff] [blame] | 521 | ENSURE_VALID_ENV(env); |
| Alex Light | 9db679d | 2017-01-25 15:28:04 -0800 | [diff] [blame] | 522 | ENSURE_HAS_CAP(env, can_access_local_variables); |
| Alex Light | bebd7bd | 2017-07-25 14:05:52 -0700 | [diff] [blame] | 523 | return MethodUtil::GetLocalVariable(env, thread, depth, slot, value_ptr); |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 524 | } |
| 525 | |
| 526 | static jvmtiError GetLocalInstance(jvmtiEnv* env, |
| Alex Light | bebd7bd | 2017-07-25 14:05:52 -0700 | [diff] [blame] | 527 | jthread thread, |
| 528 | jint depth, |
| 529 | jobject* value_ptr) { |
| Alex Light | 1edc8cf | 2017-03-24 14:22:56 -0700 | [diff] [blame] | 530 | ENSURE_VALID_ENV(env); |
| Alex Light | 9db679d | 2017-01-25 15:28:04 -0800 | [diff] [blame] | 531 | ENSURE_HAS_CAP(env, can_access_local_variables); |
| Alex Light | bebd7bd | 2017-07-25 14:05:52 -0700 | [diff] [blame] | 532 | return MethodUtil::GetLocalInstance(env, thread, depth, value_ptr); |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 533 | } |
| 534 | |
| 535 | static jvmtiError GetLocalInt(jvmtiEnv* env, |
| Alex Light | bebd7bd | 2017-07-25 14:05:52 -0700 | [diff] [blame] | 536 | jthread thread, |
| 537 | jint depth, |
| 538 | jint slot, |
| 539 | jint* value_ptr) { |
| Alex Light | 1edc8cf | 2017-03-24 14:22:56 -0700 | [diff] [blame] | 540 | ENSURE_VALID_ENV(env); |
| Alex Light | 9db679d | 2017-01-25 15:28:04 -0800 | [diff] [blame] | 541 | ENSURE_HAS_CAP(env, can_access_local_variables); |
| Alex Light | bebd7bd | 2017-07-25 14:05:52 -0700 | [diff] [blame] | 542 | return MethodUtil::GetLocalVariable(env, thread, depth, slot, value_ptr); |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 543 | } |
| 544 | |
| 545 | static jvmtiError GetLocalLong(jvmtiEnv* env, |
| Alex Light | bebd7bd | 2017-07-25 14:05:52 -0700 | [diff] [blame] | 546 | jthread thread, |
| 547 | jint depth, |
| 548 | jint slot, |
| 549 | jlong* value_ptr) { |
| Alex Light | 1edc8cf | 2017-03-24 14:22:56 -0700 | [diff] [blame] | 550 | ENSURE_VALID_ENV(env); |
| Alex Light | 9db679d | 2017-01-25 15:28:04 -0800 | [diff] [blame] | 551 | ENSURE_HAS_CAP(env, can_access_local_variables); |
| Alex Light | bebd7bd | 2017-07-25 14:05:52 -0700 | [diff] [blame] | 552 | return MethodUtil::GetLocalVariable(env, thread, depth, slot, value_ptr); |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 553 | } |
| 554 | |
| 555 | static jvmtiError GetLocalFloat(jvmtiEnv* env, |
| Alex Light | bebd7bd | 2017-07-25 14:05:52 -0700 | [diff] [blame] | 556 | jthread thread, |
| 557 | jint depth, |
| 558 | jint slot, |
| 559 | jfloat* value_ptr) { |
| Alex Light | 1edc8cf | 2017-03-24 14:22:56 -0700 | [diff] [blame] | 560 | ENSURE_VALID_ENV(env); |
| Alex Light | 9db679d | 2017-01-25 15:28:04 -0800 | [diff] [blame] | 561 | ENSURE_HAS_CAP(env, can_access_local_variables); |
| Alex Light | bebd7bd | 2017-07-25 14:05:52 -0700 | [diff] [blame] | 562 | return MethodUtil::GetLocalVariable(env, thread, depth, slot, value_ptr); |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 563 | } |
| 564 | |
| 565 | static jvmtiError GetLocalDouble(jvmtiEnv* env, |
| Alex Light | bebd7bd | 2017-07-25 14:05:52 -0700 | [diff] [blame] | 566 | jthread thread, |
| 567 | jint depth, |
| 568 | jint slot, |
| 569 | jdouble* value_ptr) { |
| Alex Light | 1edc8cf | 2017-03-24 14:22:56 -0700 | [diff] [blame] | 570 | ENSURE_VALID_ENV(env); |
| Alex Light | 9db679d | 2017-01-25 15:28:04 -0800 | [diff] [blame] | 571 | ENSURE_HAS_CAP(env, can_access_local_variables); |
| Alex Light | bebd7bd | 2017-07-25 14:05:52 -0700 | [diff] [blame] | 572 | return MethodUtil::GetLocalVariable(env, thread, depth, slot, value_ptr); |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 573 | } |
| 574 | |
| 575 | static jvmtiError SetLocalObject(jvmtiEnv* env, |
| Alex Light | bebd7bd | 2017-07-25 14:05:52 -0700 | [diff] [blame] | 576 | jthread thread, |
| 577 | jint depth, |
| 578 | jint slot, |
| 579 | jobject value) { |
| Alex Light | 1edc8cf | 2017-03-24 14:22:56 -0700 | [diff] [blame] | 580 | ENSURE_VALID_ENV(env); |
| Alex Light | 9db679d | 2017-01-25 15:28:04 -0800 | [diff] [blame] | 581 | ENSURE_HAS_CAP(env, can_access_local_variables); |
| Alex Light | bebd7bd | 2017-07-25 14:05:52 -0700 | [diff] [blame] | 582 | return MethodUtil::SetLocalVariable(env, thread, depth, slot, value); |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 583 | } |
| 584 | |
| 585 | static jvmtiError SetLocalInt(jvmtiEnv* env, |
| Alex Light | bebd7bd | 2017-07-25 14:05:52 -0700 | [diff] [blame] | 586 | jthread thread, |
| 587 | jint depth, |
| 588 | jint slot, |
| 589 | jint value) { |
| Alex Light | 1edc8cf | 2017-03-24 14:22:56 -0700 | [diff] [blame] | 590 | ENSURE_VALID_ENV(env); |
| Alex Light | 9db679d | 2017-01-25 15:28:04 -0800 | [diff] [blame] | 591 | ENSURE_HAS_CAP(env, can_access_local_variables); |
| Alex Light | bebd7bd | 2017-07-25 14:05:52 -0700 | [diff] [blame] | 592 | return MethodUtil::SetLocalVariable(env, thread, depth, slot, value); |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 593 | } |
| 594 | |
| 595 | static jvmtiError SetLocalLong(jvmtiEnv* env, |
| Alex Light | bebd7bd | 2017-07-25 14:05:52 -0700 | [diff] [blame] | 596 | jthread thread, |
| 597 | jint depth, |
| 598 | jint slot, |
| 599 | jlong value) { |
| Alex Light | 1edc8cf | 2017-03-24 14:22:56 -0700 | [diff] [blame] | 600 | ENSURE_VALID_ENV(env); |
| Alex Light | 9db679d | 2017-01-25 15:28:04 -0800 | [diff] [blame] | 601 | ENSURE_HAS_CAP(env, can_access_local_variables); |
| Alex Light | bebd7bd | 2017-07-25 14:05:52 -0700 | [diff] [blame] | 602 | return MethodUtil::SetLocalVariable(env, thread, depth, slot, value); |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 603 | } |
| 604 | |
| 605 | static jvmtiError SetLocalFloat(jvmtiEnv* env, |
| Alex Light | bebd7bd | 2017-07-25 14:05:52 -0700 | [diff] [blame] | 606 | jthread thread, |
| 607 | jint depth, |
| 608 | jint slot, |
| 609 | jfloat value) { |
| Alex Light | 1edc8cf | 2017-03-24 14:22:56 -0700 | [diff] [blame] | 610 | ENSURE_VALID_ENV(env); |
| Alex Light | 9db679d | 2017-01-25 15:28:04 -0800 | [diff] [blame] | 611 | ENSURE_HAS_CAP(env, can_access_local_variables); |
| Alex Light | bebd7bd | 2017-07-25 14:05:52 -0700 | [diff] [blame] | 612 | return MethodUtil::SetLocalVariable(env, thread, depth, slot, value); |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 613 | } |
| 614 | |
| 615 | static jvmtiError SetLocalDouble(jvmtiEnv* env, |
| Alex Light | bebd7bd | 2017-07-25 14:05:52 -0700 | [diff] [blame] | 616 | jthread thread, |
| 617 | jint depth, |
| 618 | jint slot, |
| 619 | jdouble value) { |
| Alex Light | 1edc8cf | 2017-03-24 14:22:56 -0700 | [diff] [blame] | 620 | ENSURE_VALID_ENV(env); |
| Alex Light | 9db679d | 2017-01-25 15:28:04 -0800 | [diff] [blame] | 621 | ENSURE_HAS_CAP(env, can_access_local_variables); |
| Alex Light | bebd7bd | 2017-07-25 14:05:52 -0700 | [diff] [blame] | 622 | return MethodUtil::SetLocalVariable(env, thread, depth, slot, value); |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 623 | } |
| 624 | |
| Alex Light | a26e349 | 2017-06-27 17:55:37 -0700 | [diff] [blame] | 625 | |
| 626 | static jvmtiError SetBreakpoint(jvmtiEnv* env, jmethodID method, jlocation location) { |
| Alex Light | 1edc8cf | 2017-03-24 14:22:56 -0700 | [diff] [blame] | 627 | ENSURE_VALID_ENV(env); |
| Alex Light | 9db679d | 2017-01-25 15:28:04 -0800 | [diff] [blame] | 628 | ENSURE_HAS_CAP(env, can_generate_breakpoint_events); |
| Alex Light | a26e349 | 2017-06-27 17:55:37 -0700 | [diff] [blame] | 629 | return BreakpointUtil::SetBreakpoint(env, method, location); |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 630 | } |
| 631 | |
| Alex Light | a26e349 | 2017-06-27 17:55:37 -0700 | [diff] [blame] | 632 | static jvmtiError ClearBreakpoint(jvmtiEnv* env, jmethodID method, jlocation location) { |
| Alex Light | 1edc8cf | 2017-03-24 14:22:56 -0700 | [diff] [blame] | 633 | ENSURE_VALID_ENV(env); |
| Alex Light | 9db679d | 2017-01-25 15:28:04 -0800 | [diff] [blame] | 634 | ENSURE_HAS_CAP(env, can_generate_breakpoint_events); |
| Alex Light | a26e349 | 2017-06-27 17:55:37 -0700 | [diff] [blame] | 635 | return BreakpointUtil::ClearBreakpoint(env, method, location); |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 636 | } |
| 637 | |
| Alex Light | 084fa37 | 2017-06-16 08:58:34 -0700 | [diff] [blame] | 638 | static jvmtiError SetFieldAccessWatch(jvmtiEnv* env, jclass klass, jfieldID field) { |
| Alex Light | 1edc8cf | 2017-03-24 14:22:56 -0700 | [diff] [blame] | 639 | ENSURE_VALID_ENV(env); |
| Alex Light | 9db679d | 2017-01-25 15:28:04 -0800 | [diff] [blame] | 640 | ENSURE_HAS_CAP(env, can_generate_field_access_events); |
| Alex Light | 084fa37 | 2017-06-16 08:58:34 -0700 | [diff] [blame] | 641 | return FieldUtil::SetFieldAccessWatch(env, klass, field); |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 642 | } |
| 643 | |
| Alex Light | 084fa37 | 2017-06-16 08:58:34 -0700 | [diff] [blame] | 644 | static jvmtiError ClearFieldAccessWatch(jvmtiEnv* env, jclass klass, jfieldID field) { |
| Alex Light | 1edc8cf | 2017-03-24 14:22:56 -0700 | [diff] [blame] | 645 | ENSURE_VALID_ENV(env); |
| Alex Light | 9db679d | 2017-01-25 15:28:04 -0800 | [diff] [blame] | 646 | ENSURE_HAS_CAP(env, can_generate_field_access_events); |
| Alex Light | 084fa37 | 2017-06-16 08:58:34 -0700 | [diff] [blame] | 647 | return FieldUtil::ClearFieldAccessWatch(env, klass, field); |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 648 | } |
| 649 | |
| Alex Light | 084fa37 | 2017-06-16 08:58:34 -0700 | [diff] [blame] | 650 | static jvmtiError SetFieldModificationWatch(jvmtiEnv* env, jclass klass, jfieldID field) { |
| Alex Light | 1edc8cf | 2017-03-24 14:22:56 -0700 | [diff] [blame] | 651 | ENSURE_VALID_ENV(env); |
| Alex Light | 9db679d | 2017-01-25 15:28:04 -0800 | [diff] [blame] | 652 | ENSURE_HAS_CAP(env, can_generate_field_modification_events); |
| Alex Light | 084fa37 | 2017-06-16 08:58:34 -0700 | [diff] [blame] | 653 | return FieldUtil::SetFieldModificationWatch(env, klass, field); |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 654 | } |
| 655 | |
| Alex Light | 084fa37 | 2017-06-16 08:58:34 -0700 | [diff] [blame] | 656 | static jvmtiError ClearFieldModificationWatch(jvmtiEnv* env, jclass klass, jfieldID field) { |
| Alex Light | 1edc8cf | 2017-03-24 14:22:56 -0700 | [diff] [blame] | 657 | ENSURE_VALID_ENV(env); |
| Alex Light | 9db679d | 2017-01-25 15:28:04 -0800 | [diff] [blame] | 658 | ENSURE_HAS_CAP(env, can_generate_field_modification_events); |
| Alex Light | 084fa37 | 2017-06-16 08:58:34 -0700 | [diff] [blame] | 659 | return FieldUtil::ClearFieldModificationWatch(env, klass, field); |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 660 | } |
| 661 | |
| 662 | static jvmtiError GetLoadedClasses(jvmtiEnv* env, jint* class_count_ptr, jclass** classes_ptr) { |
| Alex Light | 1edc8cf | 2017-03-24 14:22:56 -0700 | [diff] [blame] | 663 | ENSURE_VALID_ENV(env); |
| Andreas Gampe | de19eb9 | 2017-02-24 16:21:18 -0800 | [diff] [blame] | 664 | HeapUtil heap_util(ArtJvmTiEnv::AsArtJvmTiEnv(env)->object_tag_table.get()); |
| Andreas Gampe | aa8b60c | 2016-10-12 12:51:25 -0700 | [diff] [blame] | 665 | return heap_util.GetLoadedClasses(env, class_count_ptr, classes_ptr); |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 666 | } |
| 667 | |
| 668 | static jvmtiError GetClassLoaderClasses(jvmtiEnv* env, |
| 669 | jobject initiating_loader, |
| 670 | jint* class_count_ptr, |
| 671 | jclass** classes_ptr) { |
| Alex Light | 1edc8cf | 2017-03-24 14:22:56 -0700 | [diff] [blame] | 672 | ENSURE_VALID_ENV(env); |
| Andreas Gampe | 70f1639 | 2017-01-16 14:20:10 -0800 | [diff] [blame] | 673 | return ClassUtil::GetClassLoaderClasses(env, initiating_loader, class_count_ptr, classes_ptr); |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 674 | } |
| 675 | |
| 676 | static jvmtiError GetClassSignature(jvmtiEnv* env, |
| 677 | jclass klass, |
| 678 | char** signature_ptr, |
| 679 | char** generic_ptr) { |
| Alex Light | 1edc8cf | 2017-03-24 14:22:56 -0700 | [diff] [blame] | 680 | ENSURE_VALID_ENV(env); |
| Andreas Gampe | e492ae3 | 2016-10-28 19:34:57 -0700 | [diff] [blame] | 681 | return ClassUtil::GetClassSignature(env, klass, signature_ptr, generic_ptr); |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 682 | } |
| 683 | |
| 684 | static jvmtiError GetClassStatus(jvmtiEnv* env, jclass klass, jint* status_ptr) { |
| Alex Light | 1edc8cf | 2017-03-24 14:22:56 -0700 | [diff] [blame] | 685 | ENSURE_VALID_ENV(env); |
| Andreas Gampe | ff9d209 | 2017-01-06 09:12:49 -0800 | [diff] [blame] | 686 | return ClassUtil::GetClassStatus(env, klass, status_ptr); |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 687 | } |
| 688 | |
| Alex Light | 6fa7b81 | 2017-06-16 09:04:29 -0700 | [diff] [blame] | 689 | static jvmtiError GetSourceFileName(jvmtiEnv* env, jclass klass, char** source_name_ptr) { |
| Alex Light | 1edc8cf | 2017-03-24 14:22:56 -0700 | [diff] [blame] | 690 | ENSURE_VALID_ENV(env); |
| Alex Light | 9db679d | 2017-01-25 15:28:04 -0800 | [diff] [blame] | 691 | ENSURE_HAS_CAP(env, can_get_source_file_name); |
| Alex Light | 6fa7b81 | 2017-06-16 09:04:29 -0700 | [diff] [blame] | 692 | return ClassUtil::GetSourceFileName(env, klass, source_name_ptr); |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 693 | } |
| 694 | |
| 695 | static jvmtiError GetClassModifiers(jvmtiEnv* env, jclass klass, jint* modifiers_ptr) { |
| Alex Light | 1edc8cf | 2017-03-24 14:22:56 -0700 | [diff] [blame] | 696 | ENSURE_VALID_ENV(env); |
| Andreas Gampe | 64013e5 | 2017-01-06 13:07:19 -0800 | [diff] [blame] | 697 | return ClassUtil::GetClassModifiers(env, klass, modifiers_ptr); |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 698 | } |
| 699 | |
| 700 | static jvmtiError GetClassMethods(jvmtiEnv* env, |
| 701 | jclass klass, |
| 702 | jint* method_count_ptr, |
| 703 | jmethodID** methods_ptr) { |
| Alex Light | 1edc8cf | 2017-03-24 14:22:56 -0700 | [diff] [blame] | 704 | ENSURE_VALID_ENV(env); |
| Andreas Gampe | 18fee4d | 2017-01-06 11:36:35 -0800 | [diff] [blame] | 705 | return ClassUtil::GetClassMethods(env, klass, method_count_ptr, methods_ptr); |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 706 | } |
| 707 | |
| 708 | static jvmtiError GetClassFields(jvmtiEnv* env, |
| 709 | jclass klass, |
| 710 | jint* field_count_ptr, |
| 711 | jfieldID** fields_ptr) { |
| Alex Light | 1edc8cf | 2017-03-24 14:22:56 -0700 | [diff] [blame] | 712 | ENSURE_VALID_ENV(env); |
| Andreas Gampe | ac58727 | 2017-01-05 15:21:34 -0800 | [diff] [blame] | 713 | return ClassUtil::GetClassFields(env, klass, field_count_ptr, fields_ptr); |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 714 | } |
| 715 | |
| 716 | static jvmtiError GetImplementedInterfaces(jvmtiEnv* env, |
| 717 | jclass klass, |
| 718 | jint* interface_count_ptr, |
| 719 | jclass** interfaces_ptr) { |
| Alex Light | 1edc8cf | 2017-03-24 14:22:56 -0700 | [diff] [blame] | 720 | ENSURE_VALID_ENV(env); |
| Andreas Gampe | 8b07e47 | 2017-01-06 14:20:39 -0800 | [diff] [blame] | 721 | return ClassUtil::GetImplementedInterfaces(env, klass, interface_count_ptr, interfaces_ptr); |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 722 | } |
| 723 | |
| 724 | static jvmtiError GetClassVersionNumbers(jvmtiEnv* env, |
| 725 | jclass klass, |
| 726 | jint* minor_version_ptr, |
| 727 | jint* major_version_ptr) { |
| Alex Light | 1edc8cf | 2017-03-24 14:22:56 -0700 | [diff] [blame] | 728 | ENSURE_VALID_ENV(env); |
| Andreas Gampe | 812a244 | 2017-01-19 22:04:46 -0800 | [diff] [blame] | 729 | return ClassUtil::GetClassVersionNumbers(env, klass, minor_version_ptr, major_version_ptr); |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 730 | } |
| 731 | |
| 732 | static jvmtiError GetConstantPool(jvmtiEnv* env, |
| Stefano Cianciulli | 78f3c72 | 2023-05-16 10:32:54 +0000 | [diff] [blame] | 733 | [[maybe_unused]] jclass klass, |
| 734 | [[maybe_unused]] jint* constant_pool_count_ptr, |
| 735 | [[maybe_unused]] jint* constant_pool_byte_count_ptr, |
| 736 | [[maybe_unused]] unsigned char** constant_pool_bytes_ptr) { |
| Alex Light | 1edc8cf | 2017-03-24 14:22:56 -0700 | [diff] [blame] | 737 | ENSURE_VALID_ENV(env); |
| Alex Light | 9db679d | 2017-01-25 15:28:04 -0800 | [diff] [blame] | 738 | ENSURE_HAS_CAP(env, can_get_constant_pool); |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 739 | return ERR(NOT_IMPLEMENTED); |
| 740 | } |
| 741 | |
| 742 | static jvmtiError IsInterface(jvmtiEnv* env, jclass klass, jboolean* is_interface_ptr) { |
| Alex Light | 1edc8cf | 2017-03-24 14:22:56 -0700 | [diff] [blame] | 743 | ENSURE_VALID_ENV(env); |
| Andreas Gampe | 4fd66ec | 2017-01-05 14:42:13 -0800 | [diff] [blame] | 744 | return ClassUtil::IsInterface(env, klass, is_interface_ptr); |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 745 | } |
| 746 | |
| 747 | static jvmtiError IsArrayClass(jvmtiEnv* env, |
| 748 | jclass klass, |
| 749 | jboolean* is_array_class_ptr) { |
| Alex Light | 1edc8cf | 2017-03-24 14:22:56 -0700 | [diff] [blame] | 750 | ENSURE_VALID_ENV(env); |
| Andreas Gampe | 4fd66ec | 2017-01-05 14:42:13 -0800 | [diff] [blame] | 751 | return ClassUtil::IsArrayClass(env, klass, is_array_class_ptr); |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 752 | } |
| 753 | |
| 754 | static jvmtiError IsModifiableClass(jvmtiEnv* env, |
| 755 | jclass klass, |
| 756 | jboolean* is_modifiable_class_ptr) { |
| Alex Light | 1edc8cf | 2017-03-24 14:22:56 -0700 | [diff] [blame] | 757 | ENSURE_VALID_ENV(env); |
| Alex Light | e4a8863 | 2017-01-10 07:41:24 -0800 | [diff] [blame] | 758 | return Redefiner::IsModifiableClass(env, klass, is_modifiable_class_ptr); |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 759 | } |
| 760 | |
| 761 | static jvmtiError GetClassLoader(jvmtiEnv* env, jclass klass, jobject* classloader_ptr) { |
| Alex Light | 1edc8cf | 2017-03-24 14:22:56 -0700 | [diff] [blame] | 762 | ENSURE_VALID_ENV(env); |
| Andreas Gampe | 8f5b603 | 2017-01-06 15:50:55 -0800 | [diff] [blame] | 763 | return ClassUtil::GetClassLoader(env, klass, classloader_ptr); |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 764 | } |
| 765 | |
| 766 | static jvmtiError GetSourceDebugExtension(jvmtiEnv* env, |
| Alex Light | 6fa7b81 | 2017-06-16 09:04:29 -0700 | [diff] [blame] | 767 | jclass klass, |
| 768 | char** source_debug_extension_ptr) { |
| Alex Light | 1edc8cf | 2017-03-24 14:22:56 -0700 | [diff] [blame] | 769 | ENSURE_VALID_ENV(env); |
| Alex Light | 9db679d | 2017-01-25 15:28:04 -0800 | [diff] [blame] | 770 | ENSURE_HAS_CAP(env, can_get_source_debug_extension); |
| Alex Light | 6fa7b81 | 2017-06-16 09:04:29 -0700 | [diff] [blame] | 771 | return ClassUtil::GetSourceDebugExtension(env, klass, source_debug_extension_ptr); |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 772 | } |
| 773 | |
| 774 | static jvmtiError RetransformClasses(jvmtiEnv* env, jint class_count, const jclass* classes) { |
| Alex Light | 1edc8cf | 2017-03-24 14:22:56 -0700 | [diff] [blame] | 775 | ENSURE_VALID_ENV(env); |
| Alex Light | 9db679d | 2017-01-25 15:28:04 -0800 | [diff] [blame] | 776 | ENSURE_HAS_CAP(env, can_retransform_classes); |
| Alex Light | 3732beb | 2019-10-04 13:35:34 -0700 | [diff] [blame] | 777 | return Transformer::RetransformClasses(env, class_count, classes); |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 778 | } |
| 779 | |
| 780 | static jvmtiError RedefineClasses(jvmtiEnv* env, |
| 781 | jint class_count, |
| 782 | const jvmtiClassDefinition* class_definitions) { |
| Alex Light | 1edc8cf | 2017-03-24 14:22:56 -0700 | [diff] [blame] | 783 | ENSURE_VALID_ENV(env); |
| Alex Light | 9db679d | 2017-01-25 15:28:04 -0800 | [diff] [blame] | 784 | ENSURE_HAS_CAP(env, can_redefine_classes); |
| Alex Light | 3732beb | 2019-10-04 13:35:34 -0700 | [diff] [blame] | 785 | return Redefiner::RedefineClasses(env, class_count, class_definitions); |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 786 | } |
| 787 | |
| 788 | static jvmtiError GetObjectSize(jvmtiEnv* env, jobject object, jlong* size_ptr) { |
| Alex Light | 1edc8cf | 2017-03-24 14:22:56 -0700 | [diff] [blame] | 789 | ENSURE_VALID_ENV(env); |
| Andreas Gampe | 50a4e49 | 2017-01-06 18:00:20 -0800 | [diff] [blame] | 790 | return ObjectUtil::GetObjectSize(env, object, size_ptr); |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 791 | } |
| 792 | |
| 793 | static jvmtiError GetObjectHashCode(jvmtiEnv* env, jobject object, jint* hash_code_ptr) { |
| Alex Light | 1edc8cf | 2017-03-24 14:22:56 -0700 | [diff] [blame] | 794 | ENSURE_VALID_ENV(env); |
| Andreas Gampe | 50a4e49 | 2017-01-06 18:00:20 -0800 | [diff] [blame] | 795 | return ObjectUtil::GetObjectHashCode(env, object, hash_code_ptr); |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 796 | } |
| 797 | |
| 798 | static jvmtiError GetObjectMonitorUsage(jvmtiEnv* env, |
| Alex Light | ce56864 | 2017-09-05 16:54:25 -0700 | [diff] [blame] | 799 | jobject object, |
| 800 | jvmtiMonitorUsage* info_ptr) { |
| Alex Light | 1edc8cf | 2017-03-24 14:22:56 -0700 | [diff] [blame] | 801 | ENSURE_VALID_ENV(env); |
| Alex Light | 9db679d | 2017-01-25 15:28:04 -0800 | [diff] [blame] | 802 | ENSURE_HAS_CAP(env, can_get_monitor_info); |
| Alex Light | ce56864 | 2017-09-05 16:54:25 -0700 | [diff] [blame] | 803 | return ObjectUtil::GetObjectMonitorUsage(env, object, info_ptr); |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 804 | } |
| 805 | |
| 806 | static jvmtiError GetFieldName(jvmtiEnv* env, |
| 807 | jclass klass, |
| 808 | jfieldID field, |
| 809 | char** name_ptr, |
| 810 | char** signature_ptr, |
| 811 | char** generic_ptr) { |
| Alex Light | 1edc8cf | 2017-03-24 14:22:56 -0700 | [diff] [blame] | 812 | ENSURE_VALID_ENV(env); |
| Andreas Gampe | ab2f0d0 | 2017-01-05 17:23:45 -0800 | [diff] [blame] | 813 | return FieldUtil::GetFieldName(env, klass, field, name_ptr, signature_ptr, generic_ptr); |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 814 | } |
| 815 | |
| 816 | static jvmtiError GetFieldDeclaringClass(jvmtiEnv* env, |
| 817 | jclass klass, |
| 818 | jfieldID field, |
| 819 | jclass* declaring_class_ptr) { |
| Alex Light | 1edc8cf | 2017-03-24 14:22:56 -0700 | [diff] [blame] | 820 | ENSURE_VALID_ENV(env); |
| Andreas Gampe | ab2f0d0 | 2017-01-05 17:23:45 -0800 | [diff] [blame] | 821 | return FieldUtil::GetFieldDeclaringClass(env, klass, field, declaring_class_ptr); |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 822 | } |
| 823 | |
| 824 | static jvmtiError GetFieldModifiers(jvmtiEnv* env, |
| 825 | jclass klass, |
| 826 | jfieldID field, |
| 827 | jint* modifiers_ptr) { |
| Alex Light | 1edc8cf | 2017-03-24 14:22:56 -0700 | [diff] [blame] | 828 | ENSURE_VALID_ENV(env); |
| Andreas Gampe | ab2f0d0 | 2017-01-05 17:23:45 -0800 | [diff] [blame] | 829 | return FieldUtil::GetFieldModifiers(env, klass, field, modifiers_ptr); |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 830 | } |
| 831 | |
| 832 | static jvmtiError IsFieldSynthetic(jvmtiEnv* env, |
| 833 | jclass klass, |
| 834 | jfieldID field, |
| 835 | jboolean* is_synthetic_ptr) { |
| Alex Light | 1edc8cf | 2017-03-24 14:22:56 -0700 | [diff] [blame] | 836 | ENSURE_VALID_ENV(env); |
| Alex Light | 9db679d | 2017-01-25 15:28:04 -0800 | [diff] [blame] | 837 | ENSURE_HAS_CAP(env, can_get_synthetic_attribute); |
| Andreas Gampe | ab2f0d0 | 2017-01-05 17:23:45 -0800 | [diff] [blame] | 838 | return FieldUtil::IsFieldSynthetic(env, klass, field, is_synthetic_ptr); |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 839 | } |
| 840 | |
| 841 | static jvmtiError GetMethodName(jvmtiEnv* env, |
| 842 | jmethodID method, |
| 843 | char** name_ptr, |
| 844 | char** signature_ptr, |
| 845 | char** generic_ptr) { |
| Alex Light | 1edc8cf | 2017-03-24 14:22:56 -0700 | [diff] [blame] | 846 | ENSURE_VALID_ENV(env); |
| Andreas Gampe | 3c252f0 | 2016-10-27 18:25:17 -0700 | [diff] [blame] | 847 | return MethodUtil::GetMethodName(env, method, name_ptr, signature_ptr, generic_ptr); |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 848 | } |
| 849 | |
| 850 | static jvmtiError GetMethodDeclaringClass(jvmtiEnv* env, |
| 851 | jmethodID method, |
| 852 | jclass* declaring_class_ptr) { |
| Alex Light | 1edc8cf | 2017-03-24 14:22:56 -0700 | [diff] [blame] | 853 | ENSURE_VALID_ENV(env); |
| Andreas Gampe | 368a208 | 2016-10-28 17:33:13 -0700 | [diff] [blame] | 854 | return MethodUtil::GetMethodDeclaringClass(env, method, declaring_class_ptr); |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 855 | } |
| 856 | |
| 857 | static jvmtiError GetMethodModifiers(jvmtiEnv* env, |
| 858 | jmethodID method, |
| 859 | jint* modifiers_ptr) { |
| Alex Light | 1edc8cf | 2017-03-24 14:22:56 -0700 | [diff] [blame] | 860 | ENSURE_VALID_ENV(env); |
| Andreas Gampe | 36bcd4f | 2016-10-28 18:07:18 -0700 | [diff] [blame] | 861 | return MethodUtil::GetMethodModifiers(env, method, modifiers_ptr); |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 862 | } |
| 863 | |
| 864 | static jvmtiError GetMaxLocals(jvmtiEnv* env, |
| 865 | jmethodID method, |
| 866 | jint* max_ptr) { |
| Alex Light | 1edc8cf | 2017-03-24 14:22:56 -0700 | [diff] [blame] | 867 | ENSURE_VALID_ENV(env); |
| Andreas Gampe | f71832e | 2017-01-09 11:38:04 -0800 | [diff] [blame] | 868 | return MethodUtil::GetMaxLocals(env, method, max_ptr); |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 869 | } |
| 870 | |
| 871 | static jvmtiError GetArgumentsSize(jvmtiEnv* env, |
| 872 | jmethodID method, |
| 873 | jint* size_ptr) { |
| Alex Light | 1edc8cf | 2017-03-24 14:22:56 -0700 | [diff] [blame] | 874 | ENSURE_VALID_ENV(env); |
| Andreas Gampe | f71832e | 2017-01-09 11:38:04 -0800 | [diff] [blame] | 875 | return MethodUtil::GetArgumentsSize(env, method, size_ptr); |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 876 | } |
| 877 | |
| 878 | static jvmtiError GetLineNumberTable(jvmtiEnv* env, |
| 879 | jmethodID method, |
| 880 | jint* entry_count_ptr, |
| 881 | jvmtiLineNumberEntry** table_ptr) { |
| Alex Light | 1edc8cf | 2017-03-24 14:22:56 -0700 | [diff] [blame] | 882 | ENSURE_VALID_ENV(env); |
| Alex Light | 9db679d | 2017-01-25 15:28:04 -0800 | [diff] [blame] | 883 | ENSURE_HAS_CAP(env, can_get_line_numbers); |
| Andreas Gampe | da3e561 | 2016-12-13 19:00:53 -0800 | [diff] [blame] | 884 | return MethodUtil::GetLineNumberTable(env, method, entry_count_ptr, table_ptr); |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 885 | } |
| 886 | |
| 887 | static jvmtiError GetMethodLocation(jvmtiEnv* env, |
| 888 | jmethodID method, |
| 889 | jlocation* start_location_ptr, |
| 890 | jlocation* end_location_ptr) { |
| Alex Light | 1edc8cf | 2017-03-24 14:22:56 -0700 | [diff] [blame] | 891 | ENSURE_VALID_ENV(env); |
| Andreas Gampe | f71832e | 2017-01-09 11:38:04 -0800 | [diff] [blame] | 892 | return MethodUtil::GetMethodLocation(env, method, start_location_ptr, end_location_ptr); |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 893 | } |
| 894 | |
| 895 | static jvmtiError GetLocalVariableTable(jvmtiEnv* env, |
| Alex Light | ce68cc6 | 2017-07-26 10:30:38 -0700 | [diff] [blame] | 896 | jmethodID method, |
| 897 | jint* entry_count_ptr, |
| 898 | jvmtiLocalVariableEntry** table_ptr) { |
| Alex Light | 1edc8cf | 2017-03-24 14:22:56 -0700 | [diff] [blame] | 899 | ENSURE_VALID_ENV(env); |
| Alex Light | 9db679d | 2017-01-25 15:28:04 -0800 | [diff] [blame] | 900 | ENSURE_HAS_CAP(env, can_access_local_variables); |
| Alex Light | ce68cc6 | 2017-07-26 10:30:38 -0700 | [diff] [blame] | 901 | return MethodUtil::GetLocalVariableTable(env, method, entry_count_ptr, table_ptr); |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 902 | } |
| 903 | |
| 904 | static jvmtiError GetBytecodes(jvmtiEnv* env, |
| Alex Light | 4c17428 | 2017-07-05 10:18:18 -0700 | [diff] [blame] | 905 | jmethodID method, |
| 906 | jint* bytecode_count_ptr, |
| 907 | unsigned char** bytecodes_ptr) { |
| Alex Light | 1edc8cf | 2017-03-24 14:22:56 -0700 | [diff] [blame] | 908 | ENSURE_VALID_ENV(env); |
| Alex Light | 9db679d | 2017-01-25 15:28:04 -0800 | [diff] [blame] | 909 | ENSURE_HAS_CAP(env, can_get_bytecodes); |
| Alex Light | 4c17428 | 2017-07-05 10:18:18 -0700 | [diff] [blame] | 910 | return MethodUtil::GetBytecodes(env, method, bytecode_count_ptr, bytecodes_ptr); |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 911 | } |
| 912 | |
| 913 | static jvmtiError IsMethodNative(jvmtiEnv* env, jmethodID method, jboolean* is_native_ptr) { |
| Alex Light | 1edc8cf | 2017-03-24 14:22:56 -0700 | [diff] [blame] | 914 | ENSURE_VALID_ENV(env); |
| Andreas Gampe | fdeef52 | 2017-01-09 14:40:25 -0800 | [diff] [blame] | 915 | return MethodUtil::IsMethodNative(env, method, is_native_ptr); |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 916 | } |
| 917 | |
| 918 | static jvmtiError IsMethodSynthetic(jvmtiEnv* env, jmethodID method, jboolean* is_synthetic_ptr) { |
| Alex Light | 1edc8cf | 2017-03-24 14:22:56 -0700 | [diff] [blame] | 919 | ENSURE_VALID_ENV(env); |
| Alex Light | 9db679d | 2017-01-25 15:28:04 -0800 | [diff] [blame] | 920 | ENSURE_HAS_CAP(env, can_get_synthetic_attribute); |
| Andreas Gampe | fdeef52 | 2017-01-09 14:40:25 -0800 | [diff] [blame] | 921 | return MethodUtil::IsMethodSynthetic(env, method, is_synthetic_ptr); |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 922 | } |
| 923 | |
| 924 | static jvmtiError IsMethodObsolete(jvmtiEnv* env, jmethodID method, jboolean* is_obsolete_ptr) { |
| Alex Light | 1edc8cf | 2017-03-24 14:22:56 -0700 | [diff] [blame] | 925 | ENSURE_VALID_ENV(env); |
| Andreas Gampe | fdeef52 | 2017-01-09 14:40:25 -0800 | [diff] [blame] | 926 | return MethodUtil::IsMethodObsolete(env, method, is_obsolete_ptr); |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 927 | } |
| 928 | |
| Stefano Cianciulli | 78f3c72 | 2023-05-16 10:32:54 +0000 | [diff] [blame] | 929 | static jvmtiError SetNativeMethodPrefix(jvmtiEnv* env, [[maybe_unused]] const char* prefix) { |
| Alex Light | 1edc8cf | 2017-03-24 14:22:56 -0700 | [diff] [blame] | 930 | ENSURE_VALID_ENV(env); |
| Alex Light | 9db679d | 2017-01-25 15:28:04 -0800 | [diff] [blame] | 931 | ENSURE_HAS_CAP(env, can_set_native_method_prefix); |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 932 | return ERR(NOT_IMPLEMENTED); |
| 933 | } |
| 934 | |
| Alex Light | 6a3fd51 | 2017-02-27 14:34:32 -0800 | [diff] [blame] | 935 | static jvmtiError SetNativeMethodPrefixes(jvmtiEnv* env, |
| Stefano Cianciulli | 78f3c72 | 2023-05-16 10:32:54 +0000 | [diff] [blame] | 936 | [[maybe_unused]] jint prefix_count, |
| 937 | [[maybe_unused]] char** prefixes) { |
| Alex Light | 1edc8cf | 2017-03-24 14:22:56 -0700 | [diff] [blame] | 938 | ENSURE_VALID_ENV(env); |
| Alex Light | 9db679d | 2017-01-25 15:28:04 -0800 | [diff] [blame] | 939 | ENSURE_HAS_CAP(env, can_set_native_method_prefix); |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 940 | return ERR(NOT_IMPLEMENTED); |
| 941 | } |
| 942 | |
| 943 | static jvmtiError CreateRawMonitor(jvmtiEnv* env, const char* name, jrawMonitorID* monitor_ptr) { |
| Alex Light | 1edc8cf | 2017-03-24 14:22:56 -0700 | [diff] [blame] | 944 | ENSURE_VALID_ENV(env); |
| Andreas Gampe | 319dbe8 | 2017-01-09 16:42:21 -0800 | [diff] [blame] | 945 | return MonitorUtil::CreateRawMonitor(env, name, monitor_ptr); |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 946 | } |
| 947 | |
| 948 | static jvmtiError DestroyRawMonitor(jvmtiEnv* env, jrawMonitorID monitor) { |
| Alex Light | 1edc8cf | 2017-03-24 14:22:56 -0700 | [diff] [blame] | 949 | ENSURE_VALID_ENV(env); |
| Andreas Gampe | 319dbe8 | 2017-01-09 16:42:21 -0800 | [diff] [blame] | 950 | return MonitorUtil::DestroyRawMonitor(env, monitor); |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 951 | } |
| 952 | |
| 953 | static jvmtiError RawMonitorEnter(jvmtiEnv* env, jrawMonitorID monitor) { |
| Alex Light | 1edc8cf | 2017-03-24 14:22:56 -0700 | [diff] [blame] | 954 | ENSURE_VALID_ENV(env); |
| Andreas Gampe | 319dbe8 | 2017-01-09 16:42:21 -0800 | [diff] [blame] | 955 | return MonitorUtil::RawMonitorEnter(env, monitor); |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 956 | } |
| 957 | |
| 958 | static jvmtiError RawMonitorExit(jvmtiEnv* env, jrawMonitorID monitor) { |
| Alex Light | 1edc8cf | 2017-03-24 14:22:56 -0700 | [diff] [blame] | 959 | ENSURE_VALID_ENV(env); |
| Andreas Gampe | 319dbe8 | 2017-01-09 16:42:21 -0800 | [diff] [blame] | 960 | return MonitorUtil::RawMonitorExit(env, monitor); |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 961 | } |
| 962 | |
| 963 | static jvmtiError RawMonitorWait(jvmtiEnv* env, jrawMonitorID monitor, jlong millis) { |
| Alex Light | 1edc8cf | 2017-03-24 14:22:56 -0700 | [diff] [blame] | 964 | ENSURE_VALID_ENV(env); |
| Andreas Gampe | 319dbe8 | 2017-01-09 16:42:21 -0800 | [diff] [blame] | 965 | return MonitorUtil::RawMonitorWait(env, monitor, millis); |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 966 | } |
| 967 | |
| 968 | static jvmtiError RawMonitorNotify(jvmtiEnv* env, jrawMonitorID monitor) { |
| Alex Light | 1edc8cf | 2017-03-24 14:22:56 -0700 | [diff] [blame] | 969 | ENSURE_VALID_ENV(env); |
| Andreas Gampe | 319dbe8 | 2017-01-09 16:42:21 -0800 | [diff] [blame] | 970 | return MonitorUtil::RawMonitorNotify(env, monitor); |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 971 | } |
| 972 | |
| 973 | static jvmtiError RawMonitorNotifyAll(jvmtiEnv* env, jrawMonitorID monitor) { |
| Alex Light | 1edc8cf | 2017-03-24 14:22:56 -0700 | [diff] [blame] | 974 | ENSURE_VALID_ENV(env); |
| Andreas Gampe | 319dbe8 | 2017-01-09 16:42:21 -0800 | [diff] [blame] | 975 | return MonitorUtil::RawMonitorNotifyAll(env, monitor); |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 976 | } |
| 977 | |
| 978 | static jvmtiError SetJNIFunctionTable(jvmtiEnv* env, const jniNativeInterface* function_table) { |
| Alex Light | 1edc8cf | 2017-03-24 14:22:56 -0700 | [diff] [blame] | 979 | ENSURE_VALID_ENV(env); |
| Andreas Gampe | 6f8e4f0 | 2017-01-16 18:18:14 -0800 | [diff] [blame] | 980 | return JNIUtil::SetJNIFunctionTable(env, function_table); |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 981 | } |
| 982 | |
| 983 | static jvmtiError GetJNIFunctionTable(jvmtiEnv* env, jniNativeInterface** function_table) { |
| Alex Light | 1edc8cf | 2017-03-24 14:22:56 -0700 | [diff] [blame] | 984 | ENSURE_VALID_ENV(env); |
| Andreas Gampe | 6f8e4f0 | 2017-01-16 18:18:14 -0800 | [diff] [blame] | 985 | return JNIUtil::GetJNIFunctionTable(env, function_table); |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 986 | } |
| 987 | |
| Andreas Gampe | 77708d9 | 2016-10-07 11:48:21 -0700 | [diff] [blame] | 988 | // TODO: This will require locking, so that an agent can't remove callbacks when we're dispatching |
| 989 | // an event. |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 990 | static jvmtiError SetEventCallbacks(jvmtiEnv* env, |
| 991 | const jvmtiEventCallbacks* callbacks, |
| 992 | jint size_of_callbacks) { |
| Alex Light | e657424 | 2016-08-17 09:56:24 -0700 | [diff] [blame] | 993 | ENSURE_VALID_ENV(env); |
| Andreas Gampe | 77708d9 | 2016-10-07 11:48:21 -0700 | [diff] [blame] | 994 | if (size_of_callbacks < 0) { |
| 995 | return ERR(ILLEGAL_ARGUMENT); |
| 996 | } |
| 997 | |
| 998 | if (callbacks == nullptr) { |
| 999 | ArtJvmTiEnv::AsArtJvmTiEnv(env)->event_callbacks.reset(); |
| 1000 | return ERR(NONE); |
| 1001 | } |
| 1002 | |
| Alex Light | 8c2b929 | 2017-11-09 13:21:01 -0800 | [diff] [blame] | 1003 | // Lock the event_info_mutex_ while we replace the callbacks. |
| 1004 | ArtJvmTiEnv* art_env = ArtJvmTiEnv::AsArtJvmTiEnv(env); |
| 1005 | art::WriterMutexLock lk(art::Thread::Current(), art_env->event_info_mutex_); |
| 1006 | std::unique_ptr<ArtJvmtiEventCallbacks> tmp(new ArtJvmtiEventCallbacks()); |
| 1007 | // Copy over the extension events. |
| 1008 | tmp->CopyExtensionsFrom(art_env->event_callbacks.get()); |
| 1009 | // Never overwrite the extension events. |
| Andreas Gampe | 77708d9 | 2016-10-07 11:48:21 -0700 | [diff] [blame] | 1010 | size_t copy_size = std::min(sizeof(jvmtiEventCallbacks), |
| 1011 | static_cast<size_t>(size_of_callbacks)); |
| 1012 | copy_size = art::RoundDown(copy_size, sizeof(void*)); |
| Alex Light | 8c2b929 | 2017-11-09 13:21:01 -0800 | [diff] [blame] | 1013 | // Copy non-extension events. |
| Andreas Gampe | 77708d9 | 2016-10-07 11:48:21 -0700 | [diff] [blame] | 1014 | memcpy(tmp.get(), callbacks, copy_size); |
| 1015 | |
| Alex Light | 8c2b929 | 2017-11-09 13:21:01 -0800 | [diff] [blame] | 1016 | // replace the event table. |
| 1017 | art_env->event_callbacks = std::move(tmp); |
| Andreas Gampe | 77708d9 | 2016-10-07 11:48:21 -0700 | [diff] [blame] | 1018 | |
| 1019 | return ERR(NONE); |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 1020 | } |
| 1021 | |
| 1022 | static jvmtiError SetEventNotificationMode(jvmtiEnv* env, |
| 1023 | jvmtiEventMode mode, |
| 1024 | jvmtiEvent event_type, |
| 1025 | jthread event_thread, |
| 1026 | ...) { |
| Alex Light | e657424 | 2016-08-17 09:56:24 -0700 | [diff] [blame] | 1027 | ENSURE_VALID_ENV(env); |
| Alex Light | 40d87f4 | 2017-01-18 10:27:06 -0800 | [diff] [blame] | 1028 | ArtJvmTiEnv* art_env = ArtJvmTiEnv::AsArtJvmTiEnv(env); |
| Alex Light | 0e84118 | 2018-02-12 17:42:50 +0000 | [diff] [blame] | 1029 | return gEventHandler->SetEvent(art_env, |
| Alex Light | 3dacdd6 | 2019-03-12 15:45:47 +0000 | [diff] [blame] | 1030 | event_thread, |
| Alex Light | 0e84118 | 2018-02-12 17:42:50 +0000 | [diff] [blame] | 1031 | GetArtJvmtiEvent(art_env, event_type), |
| 1032 | mode); |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 1033 | } |
| 1034 | |
| Stefano Cianciulli | 78f3c72 | 2023-05-16 10:32:54 +0000 | [diff] [blame] | 1035 | static jvmtiError GenerateEvents(jvmtiEnv* env, [[maybe_unused]] jvmtiEvent event_type) { |
| Alex Light | 1edc8cf | 2017-03-24 14:22:56 -0700 | [diff] [blame] | 1036 | ENSURE_VALID_ENV(env); |
| Alex Light | 6a3fd51 | 2017-02-27 14:34:32 -0800 | [diff] [blame] | 1037 | return OK; |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 1038 | } |
| 1039 | |
| Alex Light | 1edc8cf | 2017-03-24 14:22:56 -0700 | [diff] [blame] | 1040 | static jvmtiError GetExtensionFunctions(jvmtiEnv* env, |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 1041 | jint* extension_count_ptr, |
| 1042 | jvmtiExtensionFunctionInfo** extensions) { |
| Alex Light | 1edc8cf | 2017-03-24 14:22:56 -0700 | [diff] [blame] | 1043 | ENSURE_VALID_ENV(env); |
| Andreas Gampe | d73aba4 | 2017-05-03 21:40:26 -0700 | [diff] [blame] | 1044 | ENSURE_NON_NULL(extension_count_ptr); |
| 1045 | ENSURE_NON_NULL(extensions); |
| Alex Light | 3f33c0a | 2017-11-08 10:17:37 -0800 | [diff] [blame] | 1046 | return ExtensionUtil::GetExtensionFunctions(env, extension_count_ptr, extensions); |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 1047 | } |
| 1048 | |
| Alex Light | 1edc8cf | 2017-03-24 14:22:56 -0700 | [diff] [blame] | 1049 | static jvmtiError GetExtensionEvents(jvmtiEnv* env, |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 1050 | jint* extension_count_ptr, |
| 1051 | jvmtiExtensionEventInfo** extensions) { |
| Alex Light | 1edc8cf | 2017-03-24 14:22:56 -0700 | [diff] [blame] | 1052 | ENSURE_VALID_ENV(env); |
| Alex Light | 3f33c0a | 2017-11-08 10:17:37 -0800 | [diff] [blame] | 1053 | ENSURE_NON_NULL(extension_count_ptr); |
| 1054 | ENSURE_NON_NULL(extensions); |
| 1055 | return ExtensionUtil::GetExtensionEvents(env, extension_count_ptr, extensions); |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 1056 | } |
| 1057 | |
| Alex Light | 1edc8cf | 2017-03-24 14:22:56 -0700 | [diff] [blame] | 1058 | static jvmtiError SetExtensionEventCallback(jvmtiEnv* env, |
| Alex Light | 3f33c0a | 2017-11-08 10:17:37 -0800 | [diff] [blame] | 1059 | jint extension_event_index, |
| 1060 | jvmtiExtensionEvent callback) { |
| Alex Light | 1edc8cf | 2017-03-24 14:22:56 -0700 | [diff] [blame] | 1061 | ENSURE_VALID_ENV(env); |
| Alex Light | 8c2b929 | 2017-11-09 13:21:01 -0800 | [diff] [blame] | 1062 | return ExtensionUtil::SetExtensionEventCallback(env, |
| 1063 | extension_event_index, |
| 1064 | callback, |
| Alex Light | 0e84118 | 2018-02-12 17:42:50 +0000 | [diff] [blame] | 1065 | gEventHandler); |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 1066 | } |
| 1067 | |
| Alex Light | 2ce6fc8 | 2017-12-18 16:42:36 -0800 | [diff] [blame] | 1068 | #define FOR_ALL_CAPABILITIES(FUN) \ |
| 1069 | FUN(can_tag_objects) \ |
| 1070 | FUN(can_generate_field_modification_events) \ |
| 1071 | FUN(can_generate_field_access_events) \ |
| 1072 | FUN(can_get_bytecodes) \ |
| 1073 | FUN(can_get_synthetic_attribute) \ |
| 1074 | FUN(can_get_owned_monitor_info) \ |
| 1075 | FUN(can_get_current_contended_monitor) \ |
| 1076 | FUN(can_get_monitor_info) \ |
| 1077 | FUN(can_pop_frame) \ |
| 1078 | FUN(can_redefine_classes) \ |
| 1079 | FUN(can_signal_thread) \ |
| 1080 | FUN(can_get_source_file_name) \ |
| 1081 | FUN(can_get_line_numbers) \ |
| 1082 | FUN(can_get_source_debug_extension) \ |
| 1083 | FUN(can_access_local_variables) \ |
| 1084 | FUN(can_maintain_original_method_order) \ |
| 1085 | FUN(can_generate_single_step_events) \ |
| 1086 | FUN(can_generate_exception_events) \ |
| 1087 | FUN(can_generate_frame_pop_events) \ |
| 1088 | FUN(can_generate_breakpoint_events) \ |
| 1089 | FUN(can_suspend) \ |
| 1090 | FUN(can_redefine_any_class) \ |
| 1091 | FUN(can_get_current_thread_cpu_time) \ |
| 1092 | FUN(can_get_thread_cpu_time) \ |
| 1093 | FUN(can_generate_method_entry_events) \ |
| 1094 | FUN(can_generate_method_exit_events) \ |
| 1095 | FUN(can_generate_all_class_hook_events) \ |
| 1096 | FUN(can_generate_compiled_method_load_events) \ |
| 1097 | FUN(can_generate_monitor_events) \ |
| 1098 | FUN(can_generate_vm_object_alloc_events) \ |
| 1099 | FUN(can_generate_native_method_bind_events) \ |
| 1100 | FUN(can_generate_garbage_collection_events) \ |
| 1101 | FUN(can_generate_object_free_events) \ |
| 1102 | FUN(can_force_early_return) \ |
| 1103 | FUN(can_get_owned_monitor_stack_depth_info) \ |
| 1104 | FUN(can_get_constant_pool) \ |
| 1105 | FUN(can_set_native_method_prefix) \ |
| 1106 | FUN(can_retransform_classes) \ |
| 1107 | FUN(can_retransform_any_class) \ |
| 1108 | FUN(can_generate_resource_exhaustion_heap_events) \ |
| 1109 | FUN(can_generate_resource_exhaustion_threads_events) |
| 1110 | |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 1111 | static jvmtiError GetPotentialCapabilities(jvmtiEnv* env, jvmtiCapabilities* capabilities_ptr) { |
| Alex Light | e657424 | 2016-08-17 09:56:24 -0700 | [diff] [blame] | 1112 | ENSURE_VALID_ENV(env); |
| 1113 | ENSURE_NON_NULL(capabilities_ptr); |
| 1114 | *capabilities_ptr = kPotentialCapabilities; |
| Alex Light | 2ce6fc8 | 2017-12-18 16:42:36 -0800 | [diff] [blame] | 1115 | if (UNLIKELY(!IsFullJvmtiAvailable())) { |
| 1116 | #define REMOVE_NONDEBUGGABLE_UNSUPPORTED(e) \ |
| 1117 | do { \ |
| 1118 | if (kNonDebuggableUnsupportedCapabilities.e == 1) { \ |
| 1119 | capabilities_ptr->e = 0; \ |
| 1120 | } \ |
| 1121 | } while (false); |
| 1122 | |
| 1123 | FOR_ALL_CAPABILITIES(REMOVE_NONDEBUGGABLE_UNSUPPORTED); |
| 1124 | #undef REMOVE_NONDEBUGGABLE_UNSUPPORTED |
| 1125 | } |
| Alex Light | e657424 | 2016-08-17 09:56:24 -0700 | [diff] [blame] | 1126 | return OK; |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 1127 | } |
| 1128 | |
| 1129 | static jvmtiError AddCapabilities(jvmtiEnv* env, const jvmtiCapabilities* capabilities_ptr) { |
| Alex Light | e657424 | 2016-08-17 09:56:24 -0700 | [diff] [blame] | 1130 | ENSURE_VALID_ENV(env); |
| 1131 | ENSURE_NON_NULL(capabilities_ptr); |
| 1132 | ArtJvmTiEnv* art_env = static_cast<ArtJvmTiEnv*>(env); |
| 1133 | jvmtiError ret = OK; |
| Alex Light | 34d8e08 | 2017-03-27 09:50:36 -0700 | [diff] [blame] | 1134 | jvmtiCapabilities changed = {}; |
| 1135 | jvmtiCapabilities potential_capabilities = {}; |
| Alex Light | 1d22496 | 2017-02-27 10:26:35 -0800 | [diff] [blame] | 1136 | ret = env->GetPotentialCapabilities(&potential_capabilities); |
| 1137 | if (ret != OK) { |
| 1138 | return ret; |
| 1139 | } |
| Alex Light | e657424 | 2016-08-17 09:56:24 -0700 | [diff] [blame] | 1140 | #define ADD_CAPABILITY(e) \ |
| 1141 | do { \ |
| 1142 | if (capabilities_ptr->e == 1) { \ |
| Alex Light | 1d22496 | 2017-02-27 10:26:35 -0800 | [diff] [blame] | 1143 | if (potential_capabilities.e == 1) { \ |
| Alex Light | 73afd32 | 2017-01-18 11:17:47 -0800 | [diff] [blame] | 1144 | if (art_env->capabilities.e != 1) { \ |
| 1145 | art_env->capabilities.e = 1; \ |
| 1146 | changed.e = 1; \ |
| 1147 | }\ |
| Alex Light | e657424 | 2016-08-17 09:56:24 -0700 | [diff] [blame] | 1148 | } else { \ |
| 1149 | ret = ERR(NOT_AVAILABLE); \ |
| 1150 | } \ |
| 1151 | } \ |
| Alex Light | 2ce6fc8 | 2017-12-18 16:42:36 -0800 | [diff] [blame] | 1152 | } while (false); |
| Alex Light | e657424 | 2016-08-17 09:56:24 -0700 | [diff] [blame] | 1153 | |
| Alex Light | 2ce6fc8 | 2017-12-18 16:42:36 -0800 | [diff] [blame] | 1154 | FOR_ALL_CAPABILITIES(ADD_CAPABILITY); |
| Alex Light | e657424 | 2016-08-17 09:56:24 -0700 | [diff] [blame] | 1155 | #undef ADD_CAPABILITY |
| Alex Light | 0e84118 | 2018-02-12 17:42:50 +0000 | [diff] [blame] | 1156 | gEventHandler->HandleChangedCapabilities(ArtJvmTiEnv::AsArtJvmTiEnv(env), |
| 1157 | changed, |
| Andreas Gampe | 6e89776 | 2018-10-16 13:09:32 -0700 | [diff] [blame] | 1158 | /*added=*/true); |
| Alex Light | e657424 | 2016-08-17 09:56:24 -0700 | [diff] [blame] | 1159 | return ret; |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 1160 | } |
| 1161 | |
| 1162 | static jvmtiError RelinquishCapabilities(jvmtiEnv* env, |
| 1163 | const jvmtiCapabilities* capabilities_ptr) { |
| Alex Light | e657424 | 2016-08-17 09:56:24 -0700 | [diff] [blame] | 1164 | ENSURE_VALID_ENV(env); |
| 1165 | ENSURE_NON_NULL(capabilities_ptr); |
| 1166 | ArtJvmTiEnv* art_env = reinterpret_cast<ArtJvmTiEnv*>(env); |
| Alex Light | 34d8e08 | 2017-03-27 09:50:36 -0700 | [diff] [blame] | 1167 | jvmtiCapabilities changed = {}; |
| Alex Light | e657424 | 2016-08-17 09:56:24 -0700 | [diff] [blame] | 1168 | #define DEL_CAPABILITY(e) \ |
| 1169 | do { \ |
| 1170 | if (capabilities_ptr->e == 1) { \ |
| Alex Light | 73afd32 | 2017-01-18 11:17:47 -0800 | [diff] [blame] | 1171 | if (art_env->capabilities.e == 1) { \ |
| 1172 | art_env->capabilities.e = 0;\ |
| 1173 | changed.e = 1; \ |
| 1174 | } \ |
| Alex Light | e657424 | 2016-08-17 09:56:24 -0700 | [diff] [blame] | 1175 | } \ |
| Alex Light | 2ce6fc8 | 2017-12-18 16:42:36 -0800 | [diff] [blame] | 1176 | } while (false); |
| Alex Light | e657424 | 2016-08-17 09:56:24 -0700 | [diff] [blame] | 1177 | |
| Alex Light | 2ce6fc8 | 2017-12-18 16:42:36 -0800 | [diff] [blame] | 1178 | FOR_ALL_CAPABILITIES(DEL_CAPABILITY); |
| Alex Light | e657424 | 2016-08-17 09:56:24 -0700 | [diff] [blame] | 1179 | #undef DEL_CAPABILITY |
| Alex Light | 0e84118 | 2018-02-12 17:42:50 +0000 | [diff] [blame] | 1180 | gEventHandler->HandleChangedCapabilities(ArtJvmTiEnv::AsArtJvmTiEnv(env), |
| 1181 | changed, |
| Andreas Gampe | 6e89776 | 2018-10-16 13:09:32 -0700 | [diff] [blame] | 1182 | /*added=*/false); |
| Alex Light | e657424 | 2016-08-17 09:56:24 -0700 | [diff] [blame] | 1183 | return OK; |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 1184 | } |
| 1185 | |
| Alex Light | 2ce6fc8 | 2017-12-18 16:42:36 -0800 | [diff] [blame] | 1186 | #undef FOR_ALL_CAPABILITIES |
| 1187 | |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 1188 | static jvmtiError GetCapabilities(jvmtiEnv* env, jvmtiCapabilities* capabilities_ptr) { |
| Alex Light | e657424 | 2016-08-17 09:56:24 -0700 | [diff] [blame] | 1189 | ENSURE_VALID_ENV(env); |
| 1190 | ENSURE_NON_NULL(capabilities_ptr); |
| 1191 | ArtJvmTiEnv* artenv = reinterpret_cast<ArtJvmTiEnv*>(env); |
| 1192 | *capabilities_ptr = artenv->capabilities; |
| 1193 | return OK; |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 1194 | } |
| 1195 | |
| Alex Light | 6a3fd51 | 2017-02-27 14:34:32 -0800 | [diff] [blame] | 1196 | static jvmtiError GetCurrentThreadCpuTimerInfo(jvmtiEnv* env, |
| Stefano Cianciulli | 78f3c72 | 2023-05-16 10:32:54 +0000 | [diff] [blame] | 1197 | [[maybe_unused]] jvmtiTimerInfo* info_ptr) { |
| Alex Light | 1edc8cf | 2017-03-24 14:22:56 -0700 | [diff] [blame] | 1198 | ENSURE_VALID_ENV(env); |
| Alex Light | 9db679d | 2017-01-25 15:28:04 -0800 | [diff] [blame] | 1199 | ENSURE_HAS_CAP(env, can_get_current_thread_cpu_time); |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 1200 | return ERR(NOT_IMPLEMENTED); |
| 1201 | } |
| 1202 | |
| Stefano Cianciulli | 78f3c72 | 2023-05-16 10:32:54 +0000 | [diff] [blame] | 1203 | static jvmtiError GetCurrentThreadCpuTime(jvmtiEnv* env, [[maybe_unused]] jlong* nanos_ptr) { |
| Alex Light | 1edc8cf | 2017-03-24 14:22:56 -0700 | [diff] [blame] | 1204 | ENSURE_VALID_ENV(env); |
| Alex Light | 9db679d | 2017-01-25 15:28:04 -0800 | [diff] [blame] | 1205 | ENSURE_HAS_CAP(env, can_get_current_thread_cpu_time); |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 1206 | return ERR(NOT_IMPLEMENTED); |
| 1207 | } |
| 1208 | |
| Alex Light | 6a3fd51 | 2017-02-27 14:34:32 -0800 | [diff] [blame] | 1209 | static jvmtiError GetThreadCpuTimerInfo(jvmtiEnv* env, |
| Stefano Cianciulli | 78f3c72 | 2023-05-16 10:32:54 +0000 | [diff] [blame] | 1210 | [[maybe_unused]] jvmtiTimerInfo* info_ptr) { |
| Alex Light | 1edc8cf | 2017-03-24 14:22:56 -0700 | [diff] [blame] | 1211 | ENSURE_VALID_ENV(env); |
| Alex Light | 9db679d | 2017-01-25 15:28:04 -0800 | [diff] [blame] | 1212 | ENSURE_HAS_CAP(env, can_get_thread_cpu_time); |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 1213 | return ERR(NOT_IMPLEMENTED); |
| 1214 | } |
| 1215 | |
| Alex Light | 6a3fd51 | 2017-02-27 14:34:32 -0800 | [diff] [blame] | 1216 | static jvmtiError GetThreadCpuTime(jvmtiEnv* env, |
| Stefano Cianciulli | 78f3c72 | 2023-05-16 10:32:54 +0000 | [diff] [blame] | 1217 | [[maybe_unused]] jthread thread, |
| 1218 | [[maybe_unused]] jlong* nanos_ptr) { |
| Alex Light | 1edc8cf | 2017-03-24 14:22:56 -0700 | [diff] [blame] | 1219 | ENSURE_VALID_ENV(env); |
| Alex Light | 9db679d | 2017-01-25 15:28:04 -0800 | [diff] [blame] | 1220 | ENSURE_HAS_CAP(env, can_get_thread_cpu_time); |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 1221 | return ERR(NOT_IMPLEMENTED); |
| 1222 | } |
| 1223 | |
| 1224 | static jvmtiError GetTimerInfo(jvmtiEnv* env, jvmtiTimerInfo* info_ptr) { |
| Alex Light | 1edc8cf | 2017-03-24 14:22:56 -0700 | [diff] [blame] | 1225 | ENSURE_VALID_ENV(env); |
| Andreas Gampe | 35bcf81 | 2017-01-13 16:24:17 -0800 | [diff] [blame] | 1226 | return TimerUtil::GetTimerInfo(env, info_ptr); |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 1227 | } |
| 1228 | |
| 1229 | static jvmtiError GetTime(jvmtiEnv* env, jlong* nanos_ptr) { |
| Alex Light | 1edc8cf | 2017-03-24 14:22:56 -0700 | [diff] [blame] | 1230 | ENSURE_VALID_ENV(env); |
| Andreas Gampe | 35bcf81 | 2017-01-13 16:24:17 -0800 | [diff] [blame] | 1231 | return TimerUtil::GetTime(env, nanos_ptr); |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 1232 | } |
| 1233 | |
| 1234 | static jvmtiError GetAvailableProcessors(jvmtiEnv* env, jint* processor_count_ptr) { |
| Alex Light | 1edc8cf | 2017-03-24 14:22:56 -0700 | [diff] [blame] | 1235 | ENSURE_VALID_ENV(env); |
| Andreas Gampe | 35bcf81 | 2017-01-13 16:24:17 -0800 | [diff] [blame] | 1236 | return TimerUtil::GetAvailableProcessors(env, processor_count_ptr); |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 1237 | } |
| 1238 | |
| 1239 | static jvmtiError AddToBootstrapClassLoaderSearch(jvmtiEnv* env, const char* segment) { |
| Alex Light | 1edc8cf | 2017-03-24 14:22:56 -0700 | [diff] [blame] | 1240 | ENSURE_VALID_ENV(env); |
| Andreas Gampe | ce7732b | 2017-01-17 15:50:26 -0800 | [diff] [blame] | 1241 | return SearchUtil::AddToBootstrapClassLoaderSearch(env, segment); |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 1242 | } |
| 1243 | |
| 1244 | static jvmtiError AddToSystemClassLoaderSearch(jvmtiEnv* env, const char* segment) { |
| Alex Light | 1edc8cf | 2017-03-24 14:22:56 -0700 | [diff] [blame] | 1245 | ENSURE_VALID_ENV(env); |
| Andreas Gampe | ce7732b | 2017-01-17 15:50:26 -0800 | [diff] [blame] | 1246 | return SearchUtil::AddToSystemClassLoaderSearch(env, segment); |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 1247 | } |
| 1248 | |
| 1249 | static jvmtiError GetSystemProperties(jvmtiEnv* env, jint* count_ptr, char*** property_ptr) { |
| Alex Light | 1edc8cf | 2017-03-24 14:22:56 -0700 | [diff] [blame] | 1250 | ENSURE_VALID_ENV(env); |
| Andreas Gampe | 1bdaf73 | 2017-01-09 19:21:06 -0800 | [diff] [blame] | 1251 | return PropertiesUtil::GetSystemProperties(env, count_ptr, property_ptr); |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 1252 | } |
| 1253 | |
| 1254 | static jvmtiError GetSystemProperty(jvmtiEnv* env, const char* property, char** value_ptr) { |
| Alex Light | 1edc8cf | 2017-03-24 14:22:56 -0700 | [diff] [blame] | 1255 | ENSURE_VALID_ENV(env); |
| Andreas Gampe | 1bdaf73 | 2017-01-09 19:21:06 -0800 | [diff] [blame] | 1256 | return PropertiesUtil::GetSystemProperty(env, property, value_ptr); |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 1257 | } |
| 1258 | |
| 1259 | static jvmtiError SetSystemProperty(jvmtiEnv* env, const char* property, const char* value) { |
| Alex Light | 1edc8cf | 2017-03-24 14:22:56 -0700 | [diff] [blame] | 1260 | ENSURE_VALID_ENV(env); |
| Andreas Gampe | 1bdaf73 | 2017-01-09 19:21:06 -0800 | [diff] [blame] | 1261 | return PropertiesUtil::SetSystemProperty(env, property, value); |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 1262 | } |
| 1263 | |
| 1264 | static jvmtiError GetPhase(jvmtiEnv* env, jvmtiPhase* phase_ptr) { |
| Alex Light | 1edc8cf | 2017-03-24 14:22:56 -0700 | [diff] [blame] | 1265 | ENSURE_VALID_ENV(env); |
| Andreas Gampe | 96eca78 | 2017-01-19 19:45:30 -0800 | [diff] [blame] | 1266 | return PhaseUtil::GetPhase(env, phase_ptr); |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 1267 | } |
| 1268 | |
| 1269 | static jvmtiError DisposeEnvironment(jvmtiEnv* env) { |
| Alex Light | e657424 | 2016-08-17 09:56:24 -0700 | [diff] [blame] | 1270 | ENSURE_VALID_ENV(env); |
| Alex Light | 092a404 | 2017-07-12 08:46:44 -0700 | [diff] [blame] | 1271 | ArtJvmTiEnv* tienv = ArtJvmTiEnv::AsArtJvmTiEnv(env); |
| Alex Light | 0e84118 | 2018-02-12 17:42:50 +0000 | [diff] [blame] | 1272 | gEventHandler->RemoveArtJvmTiEnv(tienv); |
| Alex Light | 092a404 | 2017-07-12 08:46:44 -0700 | [diff] [blame] | 1273 | art::Runtime::Current()->RemoveSystemWeakHolder(tienv->object_tag_table.get()); |
| 1274 | ThreadUtil::RemoveEnvironment(tienv); |
| 1275 | delete tienv; |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 1276 | return OK; |
| 1277 | } |
| 1278 | |
| 1279 | static jvmtiError SetEnvironmentLocalStorage(jvmtiEnv* env, const void* data) { |
| Alex Light | e657424 | 2016-08-17 09:56:24 -0700 | [diff] [blame] | 1280 | ENSURE_VALID_ENV(env); |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 1281 | reinterpret_cast<ArtJvmTiEnv*>(env)->local_data = const_cast<void*>(data); |
| 1282 | return OK; |
| 1283 | } |
| 1284 | |
| 1285 | static jvmtiError GetEnvironmentLocalStorage(jvmtiEnv* env, void** data_ptr) { |
| Alex Light | e657424 | 2016-08-17 09:56:24 -0700 | [diff] [blame] | 1286 | ENSURE_VALID_ENV(env); |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 1287 | *data_ptr = reinterpret_cast<ArtJvmTiEnv*>(env)->local_data; |
| 1288 | return OK; |
| 1289 | } |
| 1290 | |
| 1291 | static jvmtiError GetVersionNumber(jvmtiEnv* env, jint* version_ptr) { |
| Alex Light | e657424 | 2016-08-17 09:56:24 -0700 | [diff] [blame] | 1292 | ENSURE_VALID_ENV(env); |
| Alex Light | 2ce6fc8 | 2017-12-18 16:42:36 -0800 | [diff] [blame] | 1293 | *version_ptr = ArtJvmTiEnv::AsArtJvmTiEnv(env)->ti_version; |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 1294 | return OK; |
| 1295 | } |
| 1296 | |
| 1297 | static jvmtiError GetErrorName(jvmtiEnv* env, jvmtiError error, char** name_ptr) { |
| Alex Light | e657424 | 2016-08-17 09:56:24 -0700 | [diff] [blame] | 1298 | ENSURE_NON_NULL(name_ptr); |
| Andreas Gampe | 95c466d | 2017-05-08 14:50:47 -0700 | [diff] [blame] | 1299 | auto copy_fn = [&](const char* name_cstr) { |
| 1300 | jvmtiError res; |
| 1301 | JvmtiUniquePtr<char[]> copy = CopyString(env, name_cstr, &res); |
| 1302 | if (copy == nullptr) { |
| 1303 | *name_ptr = nullptr; |
| 1304 | return res; |
| 1305 | } else { |
| 1306 | *name_ptr = copy.release(); |
| 1307 | return OK; |
| 1308 | } |
| 1309 | }; |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 1310 | switch (error) { |
| Andreas Gampe | 95c466d | 2017-05-08 14:50:47 -0700 | [diff] [blame] | 1311 | #define ERROR_CASE(e) case (JVMTI_ERROR_ ## e) : \ |
| 1312 | return copy_fn("JVMTI_ERROR_"#e); |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 1313 | ERROR_CASE(NONE); |
| 1314 | ERROR_CASE(INVALID_THREAD); |
| 1315 | ERROR_CASE(INVALID_THREAD_GROUP); |
| 1316 | ERROR_CASE(INVALID_PRIORITY); |
| 1317 | ERROR_CASE(THREAD_NOT_SUSPENDED); |
| Andreas Gampe | 95c466d | 2017-05-08 14:50:47 -0700 | [diff] [blame] | 1318 | ERROR_CASE(THREAD_SUSPENDED); |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 1319 | ERROR_CASE(THREAD_NOT_ALIVE); |
| 1320 | ERROR_CASE(INVALID_OBJECT); |
| 1321 | ERROR_CASE(INVALID_CLASS); |
| 1322 | ERROR_CASE(CLASS_NOT_PREPARED); |
| 1323 | ERROR_CASE(INVALID_METHODID); |
| 1324 | ERROR_CASE(INVALID_LOCATION); |
| 1325 | ERROR_CASE(INVALID_FIELDID); |
| 1326 | ERROR_CASE(NO_MORE_FRAMES); |
| 1327 | ERROR_CASE(OPAQUE_FRAME); |
| 1328 | ERROR_CASE(TYPE_MISMATCH); |
| 1329 | ERROR_CASE(INVALID_SLOT); |
| 1330 | ERROR_CASE(DUPLICATE); |
| 1331 | ERROR_CASE(NOT_FOUND); |
| 1332 | ERROR_CASE(INVALID_MONITOR); |
| 1333 | ERROR_CASE(NOT_MONITOR_OWNER); |
| 1334 | ERROR_CASE(INTERRUPT); |
| 1335 | ERROR_CASE(INVALID_CLASS_FORMAT); |
| 1336 | ERROR_CASE(CIRCULAR_CLASS_DEFINITION); |
| 1337 | ERROR_CASE(FAILS_VERIFICATION); |
| 1338 | ERROR_CASE(UNSUPPORTED_REDEFINITION_METHOD_ADDED); |
| 1339 | ERROR_CASE(UNSUPPORTED_REDEFINITION_SCHEMA_CHANGED); |
| 1340 | ERROR_CASE(INVALID_TYPESTATE); |
| 1341 | ERROR_CASE(UNSUPPORTED_REDEFINITION_HIERARCHY_CHANGED); |
| 1342 | ERROR_CASE(UNSUPPORTED_REDEFINITION_METHOD_DELETED); |
| 1343 | ERROR_CASE(UNSUPPORTED_VERSION); |
| 1344 | ERROR_CASE(NAMES_DONT_MATCH); |
| 1345 | ERROR_CASE(UNSUPPORTED_REDEFINITION_CLASS_MODIFIERS_CHANGED); |
| 1346 | ERROR_CASE(UNSUPPORTED_REDEFINITION_METHOD_MODIFIERS_CHANGED); |
| 1347 | ERROR_CASE(UNMODIFIABLE_CLASS); |
| 1348 | ERROR_CASE(NOT_AVAILABLE); |
| 1349 | ERROR_CASE(MUST_POSSESS_CAPABILITY); |
| 1350 | ERROR_CASE(NULL_POINTER); |
| 1351 | ERROR_CASE(ABSENT_INFORMATION); |
| 1352 | ERROR_CASE(INVALID_EVENT_TYPE); |
| 1353 | ERROR_CASE(ILLEGAL_ARGUMENT); |
| 1354 | ERROR_CASE(NATIVE_METHOD); |
| 1355 | ERROR_CASE(CLASS_LOADER_UNSUPPORTED); |
| 1356 | ERROR_CASE(OUT_OF_MEMORY); |
| 1357 | ERROR_CASE(ACCESS_DENIED); |
| 1358 | ERROR_CASE(WRONG_PHASE); |
| 1359 | ERROR_CASE(INTERNAL); |
| 1360 | ERROR_CASE(UNATTACHED_THREAD); |
| 1361 | ERROR_CASE(INVALID_ENVIRONMENT); |
| 1362 | #undef ERROR_CASE |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 1363 | } |
| Andreas Gampe | 95c466d | 2017-05-08 14:50:47 -0700 | [diff] [blame] | 1364 | |
| 1365 | return ERR(ILLEGAL_ARGUMENT); |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 1366 | } |
| 1367 | |
| Alex Light | 1edc8cf | 2017-03-24 14:22:56 -0700 | [diff] [blame] | 1368 | static jvmtiError SetVerboseFlag(jvmtiEnv* env, |
| Alex Light | 6a3fd51 | 2017-02-27 14:34:32 -0800 | [diff] [blame] | 1369 | jvmtiVerboseFlag flag, |
| 1370 | jboolean value) { |
| Alex Light | 1edc8cf | 2017-03-24 14:22:56 -0700 | [diff] [blame] | 1371 | ENSURE_VALID_ENV(env); |
| Alex Light | 8f95183 | 2020-02-24 14:31:54 -0800 | [diff] [blame] | 1372 | return LogUtil::SetVerboseFlag(env, flag, value); |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 1373 | } |
| 1374 | |
| Alex Light | 1edc8cf | 2017-03-24 14:22:56 -0700 | [diff] [blame] | 1375 | static jvmtiError GetJLocationFormat(jvmtiEnv* env, jvmtiJlocationFormat* format_ptr) { |
| 1376 | ENSURE_VALID_ENV(env); |
| Andreas Gampe | acfc957 | 2017-01-17 18:36:56 -0800 | [diff] [blame] | 1377 | // Report BCI as jlocation format. We report dex bytecode indices. |
| 1378 | if (format_ptr == nullptr) { |
| 1379 | return ERR(NULL_POINTER); |
| 1380 | } |
| 1381 | *format_ptr = jvmtiJlocationFormat::JVMTI_JLOCATION_JVMBCI; |
| 1382 | return ERR(NONE); |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 1383 | } |
| 1384 | }; |
| 1385 | |
| 1386 | static bool IsJvmtiVersion(jint version) { |
| 1387 | return version == JVMTI_VERSION_1 || |
| 1388 | version == JVMTI_VERSION_1_0 || |
| 1389 | version == JVMTI_VERSION_1_1 || |
| 1390 | version == JVMTI_VERSION_1_2 || |
| 1391 | version == JVMTI_VERSION; |
| 1392 | } |
| 1393 | |
| Andreas Gampe | de19eb9 | 2017-02-24 16:21:18 -0800 | [diff] [blame] | 1394 | extern const jvmtiInterface_1 gJvmtiInterface; |
| Alex Light | 092a404 | 2017-07-12 08:46:44 -0700 | [diff] [blame] | 1395 | |
| Alex Light | 2ce6fc8 | 2017-12-18 16:42:36 -0800 | [diff] [blame] | 1396 | ArtJvmTiEnv::ArtJvmTiEnv(art::JavaVMExt* runtime, EventHandler* event_handler, jint version) |
| Andreas Gampe | de19eb9 | 2017-02-24 16:21:18 -0800 | [diff] [blame] | 1397 | : art_vm(runtime), |
| 1398 | local_data(nullptr), |
| Alex Light | 2ce6fc8 | 2017-12-18 16:42:36 -0800 | [diff] [blame] | 1399 | ti_version(version), |
| Alex Light | b6106d5 | 2017-10-18 15:02:15 -0700 | [diff] [blame] | 1400 | capabilities(), |
| Alex Light | ae45cbb | 2018-10-18 15:49:56 -0700 | [diff] [blame] | 1401 | event_info_mutex_("jvmtiEnv_EventInfoMutex"), |
| 1402 | last_error_mutex_("jvmtiEnv_LastErrorMutex", art::LockLevel::kGenericBottomLock) { |
| Yi Kong | c57c680 | 2018-10-29 14:28:56 -0700 | [diff] [blame] | 1403 | object_tag_table = std::make_unique<ObjectTagTable>(event_handler, this); |
| Andreas Gampe | de19eb9 | 2017-02-24 16:21:18 -0800 | [diff] [blame] | 1404 | functions = &gJvmtiInterface; |
| 1405 | } |
| 1406 | |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 1407 | // Creates a jvmtiEnv and returns it with the art::ti::Env that is associated with it. new_art_ti |
| 1408 | // is a pointer to the uninitialized memory for an art::ti::Env. |
| Alex Light | 2ce6fc8 | 2017-12-18 16:42:36 -0800 | [diff] [blame] | 1409 | static void CreateArtJvmTiEnv(art::JavaVMExt* vm, jint version, /*out*/void** new_jvmtiEnv) { |
| Alex Light | 0e84118 | 2018-02-12 17:42:50 +0000 | [diff] [blame] | 1410 | struct ArtJvmTiEnv* env = new ArtJvmTiEnv(vm, gEventHandler, version); |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 1411 | *new_jvmtiEnv = env; |
| Andreas Gampe | 77708d9 | 2016-10-07 11:48:21 -0700 | [diff] [blame] | 1412 | |
| Alex Light | 0e84118 | 2018-02-12 17:42:50 +0000 | [diff] [blame] | 1413 | gEventHandler->RegisterArtJvmTiEnv(env); |
| Andreas Gampe | de19eb9 | 2017-02-24 16:21:18 -0800 | [diff] [blame] | 1414 | |
| 1415 | art::Runtime::Current()->AddSystemWeakHolder( |
| 1416 | ArtJvmTiEnv::AsArtJvmTiEnv(env)->object_tag_table.get()); |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 1417 | } |
| 1418 | |
| 1419 | // A hook that the runtime uses to allow plugins to handle GetEnv calls. It returns true and |
| 1420 | // places the return value in 'env' if this library can handle the GetEnv request. Otherwise |
| 1421 | // returns false and does not modify the 'env' pointer. |
| 1422 | static jint GetEnvHandler(art::JavaVMExt* vm, /*out*/void** env, jint version) { |
| Alex Light | 2ce6fc8 | 2017-12-18 16:42:36 -0800 | [diff] [blame] | 1423 | // JavaDebuggable will either be set by the runtime as it is starting up or the plugin if it's |
| 1424 | // loaded early enough. If this is false we cannot guarantee conformance to all JVMTI behaviors |
| 1425 | // due to optimizations. We will only allow agents to get ArtTiEnvs using the kArtTiVersion. |
| 1426 | if (IsFullJvmtiAvailable() && IsJvmtiVersion(version)) { |
| 1427 | CreateArtJvmTiEnv(vm, JVMTI_VERSION, env); |
| 1428 | return JNI_OK; |
| 1429 | } else if (version == kArtTiVersion) { |
| 1430 | CreateArtJvmTiEnv(vm, kArtTiVersion, env); |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 1431 | return JNI_OK; |
| 1432 | } else { |
| 1433 | printf("version 0x%x is not valid!", version); |
| Alex Light | 0fba186 | 2021-01-27 16:14:30 -0800 | [diff] [blame] | 1434 | if (IsJvmtiVersion(version)) { |
| 1435 | LOG(ERROR) << "JVMTI Version 0x" << std::hex << version << " requested but the runtime is not" |
| 1436 | << " debuggable! Only limited, best effort kArtTiVersion" |
| 1437 | << " (0x" << std::hex << kArtTiVersion << ") environments are available. If" |
| 1438 | << " possible, rebuild your apk in debuggable mode or start the runtime with" |
| 1439 | << " the `-Xcompiler-option --debuggable` flags."; |
| 1440 | } |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 1441 | return JNI_EVERSION; |
| 1442 | } |
| 1443 | } |
| 1444 | |
| 1445 | // The plugin initialization function. This adds the jvmti environment. |
| 1446 | extern "C" bool ArtPlugin_Initialize() { |
| Andreas Gampe | e08a2be | 2016-10-06 13:13:30 -0700 | [diff] [blame] | 1447 | art::Runtime* runtime = art::Runtime::Current(); |
| Andreas Gampe | 96eca78 | 2017-01-19 19:45:30 -0800 | [diff] [blame] | 1448 | |
| Alex Light | 986914b | 2019-11-19 01:12:25 +0000 | [diff] [blame] | 1449 | gAllocManager = new AllocationManager; |
| Alex Light | 0e84118 | 2018-02-12 17:42:50 +0000 | [diff] [blame] | 1450 | gDeoptManager = new DeoptManager; |
| 1451 | gEventHandler = new EventHandler; |
| 1452 | |
| 1453 | gDeoptManager->Setup(); |
| Andreas Gampe | 96eca78 | 2017-01-19 19:45:30 -0800 | [diff] [blame] | 1454 | if (runtime->IsStarted()) { |
| 1455 | PhaseUtil::SetToLive(); |
| 1456 | } else { |
| 1457 | PhaseUtil::SetToOnLoad(); |
| 1458 | } |
| Alex Light | 0e84118 | 2018-02-12 17:42:50 +0000 | [diff] [blame] | 1459 | PhaseUtil::Register(gEventHandler); |
| 1460 | ThreadUtil::Register(gEventHandler); |
| 1461 | ClassUtil::Register(gEventHandler); |
| 1462 | DumpUtil::Register(gEventHandler); |
| 1463 | MethodUtil::Register(gEventHandler); |
| Alex Light | 72d7e94 | 2019-07-23 13:10:20 -0700 | [diff] [blame] | 1464 | HeapExtensions::Register(gEventHandler); |
| Andreas Gampe | cefaa14 | 2017-01-23 15:04:59 -0800 | [diff] [blame] | 1465 | SearchUtil::Register(); |
| Andreas Gampe | 9e38a50 | 2017-03-06 08:19:26 -0800 | [diff] [blame] | 1466 | HeapUtil::Register(); |
| Alex Light | c18eba3 | 2019-09-24 14:36:27 -0700 | [diff] [blame] | 1467 | FieldUtil::Register(gEventHandler); |
| 1468 | BreakpointUtil::Register(gEventHandler); |
| Alex Light | 3732beb | 2019-10-04 13:35:34 -0700 | [diff] [blame] | 1469 | Transformer::Register(gEventHandler); |
| Mythri Alle | be282e1 | 2022-10-06 12:05:26 +0000 | [diff] [blame] | 1470 | gDeoptManager->FinishSetup(); |
| Andreas Gampe | e08a2be | 2016-10-06 13:13:30 -0700 | [diff] [blame] | 1471 | runtime->GetJavaVM()->AddEnvironmentHook(GetEnvHandler); |
| Andreas Gampe | 96eca78 | 2017-01-19 19:45:30 -0800 | [diff] [blame] | 1472 | |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 1473 | return true; |
| 1474 | } |
| 1475 | |
| Andreas Gampe | eafaf57 | 2017-01-20 12:34:15 -0800 | [diff] [blame] | 1476 | extern "C" bool ArtPlugin_Deinitialize() { |
| Mythri Alle | 1285ef9 | 2022-10-26 09:44:06 +0000 | [diff] [blame] | 1477 | // When runtime is shutting down, it is not necessary to unregister callbacks or update |
| 1478 | // instrumentation levels. Removing callbacks require a GC critical section in some cases and |
| 1479 | // when runtime is shutting down we already stop GC and hence it is not safe to request to |
| 1480 | // enter a GC critical section. |
| 1481 | if (art::Runtime::Current()->IsShuttingDown(art::Thread::Current())) { |
| 1482 | return true; |
| 1483 | } |
| 1484 | |
| Alex Light | 0e84118 | 2018-02-12 17:42:50 +0000 | [diff] [blame] | 1485 | gEventHandler->Shutdown(); |
| 1486 | gDeoptManager->Shutdown(); |
| Andreas Gampe | eafaf57 | 2017-01-20 12:34:15 -0800 | [diff] [blame] | 1487 | PhaseUtil::Unregister(); |
| 1488 | ThreadUtil::Unregister(); |
| Andreas Gampe | e637746 | 2017-01-20 17:37:50 -0800 | [diff] [blame] | 1489 | ClassUtil::Unregister(); |
| Andreas Gampe | eb0cea1 | 2017-01-23 08:50:04 -0800 | [diff] [blame] | 1490 | DumpUtil::Unregister(); |
| Alex Light | d78ddec | 2017-04-18 15:20:38 -0700 | [diff] [blame] | 1491 | MethodUtil::Unregister(); |
| Andreas Gampe | cefaa14 | 2017-01-23 15:04:59 -0800 | [diff] [blame] | 1492 | SearchUtil::Unregister(); |
| Andreas Gampe | 9e38a50 | 2017-03-06 08:19:26 -0800 | [diff] [blame] | 1493 | HeapUtil::Unregister(); |
| Alex Light | c18eba3 | 2019-09-24 14:36:27 -0700 | [diff] [blame] | 1494 | FieldUtil::Unregister(); |
| 1495 | BreakpointUtil::Unregister(); |
| Andreas Gampe | eafaf57 | 2017-01-20 12:34:15 -0800 | [diff] [blame] | 1496 | |
| Alex Light | 0e84118 | 2018-02-12 17:42:50 +0000 | [diff] [blame] | 1497 | // TODO It would be good to delete the gEventHandler and gDeoptManager here but we cannot since |
| 1498 | // daemon threads might be suspended and we want to make sure that even if they wake up briefly |
| 1499 | // they won't hit deallocated memory. By this point none of the functions will do anything since |
| 1500 | // they have already shutdown. |
| 1501 | |
| Andreas Gampe | eafaf57 | 2017-01-20 12:34:15 -0800 | [diff] [blame] | 1502 | return true; |
| 1503 | } |
| 1504 | |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 1505 | // The actual struct holding all of the entrypoints into the jvmti interface. |
| 1506 | const jvmtiInterface_1 gJvmtiInterface = { |
| Alex Light | 6ac5750 | 2017-01-19 15:05:06 -0800 | [diff] [blame] | 1507 | nullptr, // reserved1 |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 1508 | JvmtiFunctions::SetEventNotificationMode, |
| Alex Light | 0e69273 | 2017-01-10 15:00:05 -0800 | [diff] [blame] | 1509 | nullptr, // reserved3 |
| Alex Light | 49948e9 | 2016-08-11 15:35:28 -0700 | [diff] [blame] | 1510 | JvmtiFunctions::GetAllThreads, |
| 1511 | JvmtiFunctions::SuspendThread, |
| 1512 | JvmtiFunctions::ResumeThread, |
| 1513 | JvmtiFunctions::StopThread, |
| 1514 | JvmtiFunctions::InterruptThread, |
| 1515 | JvmtiFunctions::GetThreadInfo, |
| 1516 | JvmtiFunctions::GetOwnedMonitorInfo, // 10 |
| 1517 | JvmtiFunctions::GetCurrentContendedMonitor, |
| 1518 | JvmtiFunctions::RunAgentThread, |
| 1519 | JvmtiFunctions::GetTopThreadGroups, |
| 1520 | JvmtiFunctions::GetThreadGroupInfo, |
| 1521 | JvmtiFunctions::GetThreadGroupChildren, |
| 1522 | JvmtiFunctions::GetFrameCount, |
| 1523 | JvmtiFunctions::GetThreadState, |
| 1524 | JvmtiFunctions::GetCurrentThread, |
| 1525 | JvmtiFunctions::GetFrameLocation, |
| 1526 | JvmtiFunctions::NotifyFramePop, // 20 |
| 1527 | JvmtiFunctions::GetLocalObject, |
| 1528 | JvmtiFunctions::GetLocalInt, |
| 1529 | JvmtiFunctions::GetLocalLong, |
| 1530 | JvmtiFunctions::GetLocalFloat, |
| 1531 | JvmtiFunctions::GetLocalDouble, |
| 1532 | JvmtiFunctions::SetLocalObject, |
| 1533 | JvmtiFunctions::SetLocalInt, |
| 1534 | JvmtiFunctions::SetLocalLong, |
| 1535 | JvmtiFunctions::SetLocalFloat, |
| 1536 | JvmtiFunctions::SetLocalDouble, // 30 |
| 1537 | JvmtiFunctions::CreateRawMonitor, |
| 1538 | JvmtiFunctions::DestroyRawMonitor, |
| 1539 | JvmtiFunctions::RawMonitorEnter, |
| 1540 | JvmtiFunctions::RawMonitorExit, |
| 1541 | JvmtiFunctions::RawMonitorWait, |
| 1542 | JvmtiFunctions::RawMonitorNotify, |
| 1543 | JvmtiFunctions::RawMonitorNotifyAll, |
| 1544 | JvmtiFunctions::SetBreakpoint, |
| 1545 | JvmtiFunctions::ClearBreakpoint, |
| 1546 | nullptr, // reserved40 |
| 1547 | JvmtiFunctions::SetFieldAccessWatch, |
| 1548 | JvmtiFunctions::ClearFieldAccessWatch, |
| 1549 | JvmtiFunctions::SetFieldModificationWatch, |
| 1550 | JvmtiFunctions::ClearFieldModificationWatch, |
| 1551 | JvmtiFunctions::IsModifiableClass, |
| 1552 | JvmtiFunctions::Allocate, |
| 1553 | JvmtiFunctions::Deallocate, |
| 1554 | JvmtiFunctions::GetClassSignature, |
| 1555 | JvmtiFunctions::GetClassStatus, |
| 1556 | JvmtiFunctions::GetSourceFileName, // 50 |
| 1557 | JvmtiFunctions::GetClassModifiers, |
| 1558 | JvmtiFunctions::GetClassMethods, |
| 1559 | JvmtiFunctions::GetClassFields, |
| 1560 | JvmtiFunctions::GetImplementedInterfaces, |
| 1561 | JvmtiFunctions::IsInterface, |
| 1562 | JvmtiFunctions::IsArrayClass, |
| 1563 | JvmtiFunctions::GetClassLoader, |
| 1564 | JvmtiFunctions::GetObjectHashCode, |
| 1565 | JvmtiFunctions::GetObjectMonitorUsage, |
| 1566 | JvmtiFunctions::GetFieldName, // 60 |
| 1567 | JvmtiFunctions::GetFieldDeclaringClass, |
| 1568 | JvmtiFunctions::GetFieldModifiers, |
| 1569 | JvmtiFunctions::IsFieldSynthetic, |
| 1570 | JvmtiFunctions::GetMethodName, |
| 1571 | JvmtiFunctions::GetMethodDeclaringClass, |
| 1572 | JvmtiFunctions::GetMethodModifiers, |
| 1573 | nullptr, // reserved67 |
| 1574 | JvmtiFunctions::GetMaxLocals, |
| 1575 | JvmtiFunctions::GetArgumentsSize, |
| 1576 | JvmtiFunctions::GetLineNumberTable, // 70 |
| 1577 | JvmtiFunctions::GetMethodLocation, |
| 1578 | JvmtiFunctions::GetLocalVariableTable, |
| 1579 | JvmtiFunctions::SetNativeMethodPrefix, |
| 1580 | JvmtiFunctions::SetNativeMethodPrefixes, |
| 1581 | JvmtiFunctions::GetBytecodes, |
| 1582 | JvmtiFunctions::IsMethodNative, |
| 1583 | JvmtiFunctions::IsMethodSynthetic, |
| 1584 | JvmtiFunctions::GetLoadedClasses, |
| 1585 | JvmtiFunctions::GetClassLoaderClasses, |
| 1586 | JvmtiFunctions::PopFrame, // 80 |
| 1587 | JvmtiFunctions::ForceEarlyReturnObject, |
| 1588 | JvmtiFunctions::ForceEarlyReturnInt, |
| 1589 | JvmtiFunctions::ForceEarlyReturnLong, |
| 1590 | JvmtiFunctions::ForceEarlyReturnFloat, |
| 1591 | JvmtiFunctions::ForceEarlyReturnDouble, |
| 1592 | JvmtiFunctions::ForceEarlyReturnVoid, |
| 1593 | JvmtiFunctions::RedefineClasses, |
| 1594 | JvmtiFunctions::GetVersionNumber, |
| 1595 | JvmtiFunctions::GetCapabilities, |
| 1596 | JvmtiFunctions::GetSourceDebugExtension, // 90 |
| 1597 | JvmtiFunctions::IsMethodObsolete, |
| 1598 | JvmtiFunctions::SuspendThreadList, |
| 1599 | JvmtiFunctions::ResumeThreadList, |
| 1600 | nullptr, // reserved94 |
| 1601 | nullptr, // reserved95 |
| 1602 | nullptr, // reserved96 |
| 1603 | nullptr, // reserved97 |
| 1604 | nullptr, // reserved98 |
| 1605 | nullptr, // reserved99 |
| 1606 | JvmtiFunctions::GetAllStackTraces, // 100 |
| 1607 | JvmtiFunctions::GetThreadListStackTraces, |
| 1608 | JvmtiFunctions::GetThreadLocalStorage, |
| 1609 | JvmtiFunctions::SetThreadLocalStorage, |
| 1610 | JvmtiFunctions::GetStackTrace, |
| 1611 | nullptr, // reserved105 |
| 1612 | JvmtiFunctions::GetTag, |
| 1613 | JvmtiFunctions::SetTag, |
| 1614 | JvmtiFunctions::ForceGarbageCollection, |
| 1615 | JvmtiFunctions::IterateOverObjectsReachableFromObject, |
| 1616 | JvmtiFunctions::IterateOverReachableObjects, // 110 |
| 1617 | JvmtiFunctions::IterateOverHeap, |
| 1618 | JvmtiFunctions::IterateOverInstancesOfClass, |
| 1619 | nullptr, // reserved113 |
| 1620 | JvmtiFunctions::GetObjectsWithTags, |
| 1621 | JvmtiFunctions::FollowReferences, |
| 1622 | JvmtiFunctions::IterateThroughHeap, |
| 1623 | nullptr, // reserved117 |
| 1624 | nullptr, // reserved118 |
| 1625 | nullptr, // reserved119 |
| 1626 | JvmtiFunctions::SetJNIFunctionTable, // 120 |
| 1627 | JvmtiFunctions::GetJNIFunctionTable, |
| 1628 | JvmtiFunctions::SetEventCallbacks, |
| 1629 | JvmtiFunctions::GenerateEvents, |
| 1630 | JvmtiFunctions::GetExtensionFunctions, |
| 1631 | JvmtiFunctions::GetExtensionEvents, |
| 1632 | JvmtiFunctions::SetExtensionEventCallback, |
| 1633 | JvmtiFunctions::DisposeEnvironment, |
| 1634 | JvmtiFunctions::GetErrorName, |
| 1635 | JvmtiFunctions::GetJLocationFormat, |
| 1636 | JvmtiFunctions::GetSystemProperties, // 130 |
| 1637 | JvmtiFunctions::GetSystemProperty, |
| 1638 | JvmtiFunctions::SetSystemProperty, |
| 1639 | JvmtiFunctions::GetPhase, |
| 1640 | JvmtiFunctions::GetCurrentThreadCpuTimerInfo, |
| 1641 | JvmtiFunctions::GetCurrentThreadCpuTime, |
| 1642 | JvmtiFunctions::GetThreadCpuTimerInfo, |
| 1643 | JvmtiFunctions::GetThreadCpuTime, |
| 1644 | JvmtiFunctions::GetTimerInfo, |
| 1645 | JvmtiFunctions::GetTime, |
| 1646 | JvmtiFunctions::GetPotentialCapabilities, // 140 |
| 1647 | nullptr, // reserved141 |
| 1648 | JvmtiFunctions::AddCapabilities, |
| 1649 | JvmtiFunctions::RelinquishCapabilities, |
| 1650 | JvmtiFunctions::GetAvailableProcessors, |
| 1651 | JvmtiFunctions::GetClassVersionNumbers, |
| 1652 | JvmtiFunctions::GetConstantPool, |
| 1653 | JvmtiFunctions::GetEnvironmentLocalStorage, |
| 1654 | JvmtiFunctions::SetEnvironmentLocalStorage, |
| 1655 | JvmtiFunctions::AddToBootstrapClassLoaderSearch, |
| 1656 | JvmtiFunctions::SetVerboseFlag, // 150 |
| 1657 | JvmtiFunctions::AddToSystemClassLoaderSearch, |
| 1658 | JvmtiFunctions::RetransformClasses, |
| 1659 | JvmtiFunctions::GetOwnedMonitorStackDepthInfo, |
| 1660 | JvmtiFunctions::GetObjectSize, |
| 1661 | JvmtiFunctions::GetLocalInstance, |
| 1662 | }; |
| 1663 | |
| 1664 | }; // namespace openjdkjvmti |