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