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