Andreas Gampe | 3c252f0 | 2016-10-27 18:25:17 -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 | |
| 32 | #include "ti_method.h" |
| 33 | |
Andreas Gampe | 49fc60e | 2017-08-24 13:19:59 -0700 | [diff] [blame] | 34 | #include <type_traits> |
| 35 | |
Andreas Gampe | e5d2398 | 2019-01-08 10:34:26 -0800 | [diff] [blame] | 36 | #include "arch/context.h" |
Andreas Gampe | 3c252f0 | 2016-10-27 18:25:17 -0700 | [diff] [blame] | 37 | #include "art_jvmti.h" |
| 38 | #include "art_method-inl.h" |
| 39 | #include "base/enums.h" |
Alex Light | bebd7bd | 2017-07-25 14:05:52 -0700 | [diff] [blame] | 40 | #include "base/mutex-inl.h" |
Alex Light | a4cdd36 | 2019-04-18 09:17:10 -0700 | [diff] [blame^] | 41 | #include "deopt_manager.h" |
David Sehr | 9e734c7 | 2018-01-04 17:56:19 -0800 | [diff] [blame] | 42 | #include "dex/code_item_accessors-inl.h" |
| 43 | #include "dex/dex_file_annotations.h" |
| 44 | #include "dex/dex_file_types.h" |
David Sehr | 8c0961f | 2018-01-23 16:11:38 -0800 | [diff] [blame] | 45 | #include "dex/modifiers.h" |
Alex Light | d78ddec | 2017-04-18 15:20:38 -0700 | [diff] [blame] | 46 | #include "events-inl.h" |
Alex Light | 318afe6 | 2018-03-22 16:50:10 -0700 | [diff] [blame] | 47 | #include "gc_root-inl.h" |
Alex Light | 0a5ec3d | 2017-07-25 16:50:26 -0700 | [diff] [blame] | 48 | #include "jit/jit.h" |
Vladimir Marko | a3ad0cd | 2018-05-04 10:06:38 +0100 | [diff] [blame] | 49 | #include "jni/jni_internal.h" |
Alex Light | bebd7bd | 2017-07-25 14:05:52 -0700 | [diff] [blame] | 50 | #include "mirror/class-inl.h" |
| 51 | #include "mirror/class_loader.h" |
| 52 | #include "mirror/object-inl.h" |
Andreas Gampe | 27dfa05 | 2017-02-16 15:04:36 -0800 | [diff] [blame] | 53 | #include "mirror/object_array-inl.h" |
Andreas Gampe | 373a9b5 | 2017-10-18 09:01:57 -0700 | [diff] [blame] | 54 | #include "nativehelper/scoped_local_ref.h" |
Nicolas Geoffray | 58cc1cb | 2017-11-20 13:27:29 +0000 | [diff] [blame] | 55 | #include "oat_file.h" |
Alex Light | a4cdd36 | 2019-04-18 09:17:10 -0700 | [diff] [blame^] | 56 | #include "obj_ptr.h" |
Alex Light | d78ddec | 2017-04-18 15:20:38 -0700 | [diff] [blame] | 57 | #include "runtime_callbacks.h" |
Andreas Gampe | 3c252f0 | 2016-10-27 18:25:17 -0700 | [diff] [blame] | 58 | #include "scoped_thread_state_change-inl.h" |
Alex Light | bebd7bd | 2017-07-25 14:05:52 -0700 | [diff] [blame] | 59 | #include "stack.h" |
Andreas Gampe | b486a98 | 2017-06-01 13:45:54 -0700 | [diff] [blame] | 60 | #include "thread-current-inl.h" |
Alex Light | a4cdd36 | 2019-04-18 09:17:10 -0700 | [diff] [blame^] | 61 | #include "thread.h" |
Alex Light | d78ddec | 2017-04-18 15:20:38 -0700 | [diff] [blame] | 62 | #include "thread_list.h" |
Alex Light | e814f9d | 2017-07-31 16:14:39 -0700 | [diff] [blame] | 63 | #include "ti_stack.h" |
Alex Light | bebd7bd | 2017-07-25 14:05:52 -0700 | [diff] [blame] | 64 | #include "ti_thread.h" |
Alex Light | 0af8cde | 2017-04-20 13:35:05 -0700 | [diff] [blame] | 65 | #include "ti_phase.h" |
Andreas Gampe | 3c252f0 | 2016-10-27 18:25:17 -0700 | [diff] [blame] | 66 | |
| 67 | namespace openjdkjvmti { |
| 68 | |
Alex Light | d78ddec | 2017-04-18 15:20:38 -0700 | [diff] [blame] | 69 | struct TiMethodCallback : public art::MethodCallback { |
| 70 | void RegisterNativeMethod(art::ArtMethod* method, |
| 71 | const void* cur_method, |
| 72 | /*out*/void** new_method) |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 73 | override REQUIRES_SHARED(art::Locks::mutator_lock_) { |
Alex Light | d78ddec | 2017-04-18 15:20:38 -0700 | [diff] [blame] | 74 | if (event_handler->IsEventEnabledAnywhere(ArtJvmtiEvent::kNativeMethodBind)) { |
| 75 | art::Thread* thread = art::Thread::Current(); |
Alex Light | 0af8cde | 2017-04-20 13:35:05 -0700 | [diff] [blame] | 76 | art::JNIEnvExt* jnienv = thread->GetJniEnv(); |
Alex Light | d78ddec | 2017-04-18 15:20:38 -0700 | [diff] [blame] | 77 | ScopedLocalRef<jthread> thread_jni( |
Alex Light | 0af8cde | 2017-04-20 13:35:05 -0700 | [diff] [blame] | 78 | jnienv, PhaseUtil::IsLivePhase() ? jnienv->AddLocalReference<jthread>(thread->GetPeer()) |
| 79 | : nullptr); |
Alex Light | d78ddec | 2017-04-18 15:20:38 -0700 | [diff] [blame] | 80 | art::ScopedThreadSuspension sts(thread, art::ThreadState::kNative); |
| 81 | event_handler->DispatchEvent<ArtJvmtiEvent::kNativeMethodBind>( |
| 82 | thread, |
Alex Light | 0af8cde | 2017-04-20 13:35:05 -0700 | [diff] [blame] | 83 | static_cast<JNIEnv*>(jnienv), |
Alex Light | d78ddec | 2017-04-18 15:20:38 -0700 | [diff] [blame] | 84 | thread_jni.get(), |
| 85 | art::jni::EncodeArtMethod(method), |
| 86 | const_cast<void*>(cur_method), |
| 87 | new_method); |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | EventHandler* event_handler = nullptr; |
| 92 | }; |
| 93 | |
| 94 | TiMethodCallback gMethodCallback; |
| 95 | |
| 96 | void MethodUtil::Register(EventHandler* handler) { |
| 97 | gMethodCallback.event_handler = handler; |
| 98 | art::ScopedThreadStateChange stsc(art::Thread::Current(), |
| 99 | art::ThreadState::kWaitingForDebuggerToAttach); |
| 100 | art::ScopedSuspendAll ssa("Add method callback"); |
Alex Light | 2161193 | 2017-09-26 13:07:39 -0700 | [diff] [blame] | 101 | art::RuntimeCallbacks* callbacks = art::Runtime::Current()->GetRuntimeCallbacks(); |
| 102 | callbacks->AddMethodCallback(&gMethodCallback); |
Alex Light | d78ddec | 2017-04-18 15:20:38 -0700 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | void MethodUtil::Unregister() { |
| 106 | art::ScopedThreadStateChange stsc(art::Thread::Current(), |
| 107 | art::ThreadState::kWaitingForDebuggerToAttach); |
| 108 | art::ScopedSuspendAll ssa("Remove method callback"); |
Alex Light | 2161193 | 2017-09-26 13:07:39 -0700 | [diff] [blame] | 109 | art::RuntimeCallbacks* callbacks = art::Runtime::Current()->GetRuntimeCallbacks(); |
| 110 | callbacks->RemoveMethodCallback(&gMethodCallback); |
Alex Light | d78ddec | 2017-04-18 15:20:38 -0700 | [diff] [blame] | 111 | } |
| 112 | |
Alex Light | 4c17428 | 2017-07-05 10:18:18 -0700 | [diff] [blame] | 113 | jvmtiError MethodUtil::GetBytecodes(jvmtiEnv* env, |
| 114 | jmethodID method, |
| 115 | jint* size_ptr, |
| 116 | unsigned char** bytecode_ptr) { |
| 117 | if (method == nullptr) { |
| 118 | return ERR(INVALID_METHODID); |
| 119 | } |
| 120 | art::ArtMethod* art_method = art::jni::DecodeArtMethod(method); |
| 121 | |
| 122 | if (art_method->IsNative()) { |
| 123 | return ERR(NATIVE_METHOD); |
| 124 | } |
| 125 | |
| 126 | if (size_ptr == nullptr || bytecode_ptr == nullptr) { |
| 127 | return ERR(NULL_POINTER); |
| 128 | } |
| 129 | |
| 130 | art::ScopedObjectAccess soa(art::Thread::Current()); |
David Sehr | 0225f8e | 2018-01-31 08:52:24 +0000 | [diff] [blame] | 131 | art::CodeItemInstructionAccessor accessor(art_method->DexInstructions()); |
Mathieu Chartier | 808c7a5 | 2017-12-15 11:19:33 -0800 | [diff] [blame] | 132 | if (!accessor.HasCodeItem()) { |
Alex Light | 4c17428 | 2017-07-05 10:18:18 -0700 | [diff] [blame] | 133 | *size_ptr = 0; |
| 134 | *bytecode_ptr = nullptr; |
| 135 | return OK; |
| 136 | } |
| 137 | // 2 bytes per instruction for dex code. |
Mathieu Chartier | 808c7a5 | 2017-12-15 11:19:33 -0800 | [diff] [blame] | 138 | *size_ptr = accessor.InsnsSizeInCodeUnits() * 2; |
Alex Light | 4c17428 | 2017-07-05 10:18:18 -0700 | [diff] [blame] | 139 | jvmtiError err = env->Allocate(*size_ptr, bytecode_ptr); |
| 140 | if (err != OK) { |
| 141 | return err; |
| 142 | } |
Mathieu Chartier | 808c7a5 | 2017-12-15 11:19:33 -0800 | [diff] [blame] | 143 | memcpy(*bytecode_ptr, accessor.Insns(), *size_ptr); |
Alex Light | 4c17428 | 2017-07-05 10:18:18 -0700 | [diff] [blame] | 144 | return OK; |
| 145 | } |
| 146 | |
Andreas Gampe | f71832e | 2017-01-09 11:38:04 -0800 | [diff] [blame] | 147 | jvmtiError MethodUtil::GetArgumentsSize(jvmtiEnv* env ATTRIBUTE_UNUSED, |
| 148 | jmethodID method, |
| 149 | jint* size_ptr) { |
| 150 | if (method == nullptr) { |
| 151 | return ERR(INVALID_METHODID); |
| 152 | } |
| 153 | art::ArtMethod* art_method = art::jni::DecodeArtMethod(method); |
| 154 | |
| 155 | if (art_method->IsNative()) { |
| 156 | return ERR(NATIVE_METHOD); |
| 157 | } |
| 158 | |
| 159 | if (size_ptr == nullptr) { |
| 160 | return ERR(NULL_POINTER); |
| 161 | } |
| 162 | |
| 163 | art::ScopedObjectAccess soa(art::Thread::Current()); |
| 164 | if (art_method->IsProxyMethod() || art_method->IsAbstract()) { |
Andreas Gampe | e1f79b6 | 2017-04-12 21:11:28 -0700 | [diff] [blame] | 165 | // Use the shorty. |
| 166 | art::ArtMethod* base_method = art_method->GetInterfaceMethodIfProxy(art::kRuntimePointerSize); |
| 167 | size_t arg_count = art::ArtMethod::NumArgRegisters(base_method->GetShorty()); |
| 168 | if (!base_method->IsStatic()) { |
| 169 | arg_count++; |
| 170 | } |
| 171 | *size_ptr = static_cast<jint>(arg_count); |
Andreas Gampe | f71832e | 2017-01-09 11:38:04 -0800 | [diff] [blame] | 172 | return ERR(NONE); |
| 173 | } |
| 174 | |
| 175 | DCHECK_NE(art_method->GetCodeItemOffset(), 0u); |
David Sehr | 0225f8e | 2018-01-31 08:52:24 +0000 | [diff] [blame] | 176 | *size_ptr = art_method->DexInstructionData().InsSize(); |
Andreas Gampe | f71832e | 2017-01-09 11:38:04 -0800 | [diff] [blame] | 177 | |
| 178 | return ERR(NONE); |
| 179 | } |
| 180 | |
Alex Light | ce68cc6 | 2017-07-26 10:30:38 -0700 | [diff] [blame] | 181 | jvmtiError MethodUtil::GetLocalVariableTable(jvmtiEnv* env, |
| 182 | jmethodID method, |
| 183 | jint* entry_count_ptr, |
| 184 | jvmtiLocalVariableEntry** table_ptr) { |
| 185 | if (method == nullptr) { |
| 186 | return ERR(INVALID_METHODID); |
| 187 | } |
| 188 | art::ArtMethod* art_method = art::jni::DecodeArtMethod(method); |
| 189 | |
| 190 | if (art_method->IsNative()) { |
| 191 | return ERR(NATIVE_METHOD); |
| 192 | } |
| 193 | |
| 194 | if (entry_count_ptr == nullptr || table_ptr == nullptr) { |
| 195 | return ERR(NULL_POINTER); |
| 196 | } |
| 197 | |
| 198 | art::ScopedObjectAccess soa(art::Thread::Current()); |
Mathieu Chartier | 31f4c9f | 2017-12-08 15:46:11 -0800 | [diff] [blame] | 199 | |
| 200 | const art::DexFile* const dex_file = art_method->GetDexFile(); |
| 201 | if (dex_file == nullptr) { |
| 202 | return ERR(ABSENT_INFORMATION); |
| 203 | } |
| 204 | |
| 205 | // TODO HasCodeItem == false means that the method is abstract (or native, but we check that |
Alex Light | ce68cc6 | 2017-07-26 10:30:38 -0700 | [diff] [blame] | 206 | // earlier). We should check what is returned by the RI in this situation since it's not clear |
| 207 | // what the appropriate return value is from the spec. |
David Sehr | 0225f8e | 2018-01-31 08:52:24 +0000 | [diff] [blame] | 208 | art::CodeItemDebugInfoAccessor accessor(art_method->DexInstructionDebugInfo()); |
Mathieu Chartier | 31f4c9f | 2017-12-08 15:46:11 -0800 | [diff] [blame] | 209 | if (!accessor.HasCodeItem()) { |
Alex Light | ce68cc6 | 2017-07-26 10:30:38 -0700 | [diff] [blame] | 210 | return ERR(ABSENT_INFORMATION); |
| 211 | } |
| 212 | |
Mathieu Chartier | e5afbf3 | 2018-09-12 17:51:54 -0700 | [diff] [blame] | 213 | std::vector<jvmtiLocalVariableEntry> variables; |
| 214 | jvmtiError err = OK; |
Alex Light | ce68cc6 | 2017-07-26 10:30:38 -0700 | [diff] [blame] | 215 | |
Mathieu Chartier | e5afbf3 | 2018-09-12 17:51:54 -0700 | [diff] [blame] | 216 | auto release = [&](jint* out_entry_count_ptr, jvmtiLocalVariableEntry** out_table_ptr) { |
| 217 | jlong table_size = sizeof(jvmtiLocalVariableEntry) * variables.size(); |
| 218 | if (err != OK || |
| 219 | (err = env->Allocate(table_size, |
| 220 | reinterpret_cast<unsigned char**>(out_table_ptr))) != OK) { |
| 221 | for (jvmtiLocalVariableEntry& e : variables) { |
| 222 | env->Deallocate(reinterpret_cast<unsigned char*>(e.name)); |
| 223 | env->Deallocate(reinterpret_cast<unsigned char*>(e.signature)); |
| 224 | env->Deallocate(reinterpret_cast<unsigned char*>(e.generic_signature)); |
| 225 | } |
| 226 | return err; |
Alex Light | ce68cc6 | 2017-07-26 10:30:38 -0700 | [diff] [blame] | 227 | } |
Mathieu Chartier | e5afbf3 | 2018-09-12 17:51:54 -0700 | [diff] [blame] | 228 | *out_entry_count_ptr = variables.size(); |
| 229 | memcpy(*out_table_ptr, variables.data(), table_size); |
| 230 | return OK; |
Alex Light | ce68cc6 | 2017-07-26 10:30:38 -0700 | [diff] [blame] | 231 | }; |
| 232 | |
Mathieu Chartier | e5afbf3 | 2018-09-12 17:51:54 -0700 | [diff] [blame] | 233 | auto visitor = [&](const art::DexFile::LocalInfo& entry) { |
| 234 | if (err != OK) { |
| 235 | return; |
| 236 | } |
| 237 | JvmtiUniquePtr<char[]> name_str = CopyString(env, entry.name_, &err); |
| 238 | if (err != OK) { |
| 239 | return; |
| 240 | } |
| 241 | JvmtiUniquePtr<char[]> sig_str = CopyString(env, entry.descriptor_, &err); |
| 242 | if (err != OK) { |
| 243 | return; |
| 244 | } |
| 245 | JvmtiUniquePtr<char[]> generic_sig_str = CopyString(env, entry.signature_, &err); |
| 246 | if (err != OK) { |
| 247 | return; |
| 248 | } |
| 249 | variables.push_back({ |
| 250 | .start_location = static_cast<jlocation>(entry.start_address_), |
| 251 | .length = static_cast<jint>(entry.end_address_ - entry.start_address_), |
| 252 | .name = name_str.release(), |
| 253 | .signature = sig_str.release(), |
| 254 | .generic_signature = generic_sig_str.release(), |
| 255 | .slot = entry.reg_, |
| 256 | }); |
| 257 | }; |
| 258 | |
Mathieu Chartier | 808c7a5 | 2017-12-15 11:19:33 -0800 | [diff] [blame] | 259 | if (!accessor.DecodeDebugLocalInfo(art_method->IsStatic(), |
| 260 | art_method->GetDexMethodIndex(), |
Mathieu Chartier | e5afbf3 | 2018-09-12 17:51:54 -0700 | [diff] [blame] | 261 | visitor)) { |
Alex Light | ce68cc6 | 2017-07-26 10:30:38 -0700 | [diff] [blame] | 262 | // Something went wrong with decoding the debug information. It might as well not be there. |
| 263 | return ERR(ABSENT_INFORMATION); |
Alex Light | ce68cc6 | 2017-07-26 10:30:38 -0700 | [diff] [blame] | 264 | } |
Mathieu Chartier | e5afbf3 | 2018-09-12 17:51:54 -0700 | [diff] [blame] | 265 | return release(entry_count_ptr, table_ptr); |
Alex Light | ce68cc6 | 2017-07-26 10:30:38 -0700 | [diff] [blame] | 266 | } |
| 267 | |
Andreas Gampe | f71832e | 2017-01-09 11:38:04 -0800 | [diff] [blame] | 268 | jvmtiError MethodUtil::GetMaxLocals(jvmtiEnv* env ATTRIBUTE_UNUSED, |
| 269 | jmethodID method, |
| 270 | jint* max_ptr) { |
| 271 | if (method == nullptr) { |
| 272 | return ERR(INVALID_METHODID); |
| 273 | } |
| 274 | art::ArtMethod* art_method = art::jni::DecodeArtMethod(method); |
| 275 | |
| 276 | if (art_method->IsNative()) { |
| 277 | return ERR(NATIVE_METHOD); |
| 278 | } |
| 279 | |
| 280 | if (max_ptr == nullptr) { |
| 281 | return ERR(NULL_POINTER); |
| 282 | } |
| 283 | |
| 284 | art::ScopedObjectAccess soa(art::Thread::Current()); |
| 285 | if (art_method->IsProxyMethod() || art_method->IsAbstract()) { |
| 286 | // This isn't specified as an error case, so return 0. |
| 287 | *max_ptr = 0; |
| 288 | return ERR(NONE); |
| 289 | } |
| 290 | |
| 291 | DCHECK_NE(art_method->GetCodeItemOffset(), 0u); |
David Sehr | 0225f8e | 2018-01-31 08:52:24 +0000 | [diff] [blame] | 292 | *max_ptr = art_method->DexInstructionData().RegistersSize(); |
Andreas Gampe | f71832e | 2017-01-09 11:38:04 -0800 | [diff] [blame] | 293 | |
| 294 | return ERR(NONE); |
| 295 | } |
| 296 | |
Andreas Gampe | 3c252f0 | 2016-10-27 18:25:17 -0700 | [diff] [blame] | 297 | jvmtiError MethodUtil::GetMethodName(jvmtiEnv* env, |
| 298 | jmethodID method, |
| 299 | char** name_ptr, |
| 300 | char** signature_ptr, |
| 301 | char** generic_ptr) { |
| 302 | art::ScopedObjectAccess soa(art::Thread::Current()); |
Andreas Gampe | 13b2784 | 2016-11-07 16:48:23 -0800 | [diff] [blame] | 303 | art::ArtMethod* art_method = art::jni::DecodeArtMethod(method); |
Andreas Gampe | 3c252f0 | 2016-10-27 18:25:17 -0700 | [diff] [blame] | 304 | art_method = art_method->GetInterfaceMethodIfProxy(art::kRuntimePointerSize); |
| 305 | |
Andreas Gampe | 5471141 | 2017-02-21 12:41:43 -0800 | [diff] [blame] | 306 | JvmtiUniquePtr<char[]> name_copy; |
Andreas Gampe | 3c252f0 | 2016-10-27 18:25:17 -0700 | [diff] [blame] | 307 | if (name_ptr != nullptr) { |
| 308 | const char* method_name = art_method->GetName(); |
| 309 | if (method_name == nullptr) { |
| 310 | method_name = "<error>"; |
| 311 | } |
Andreas Gampe | 5471141 | 2017-02-21 12:41:43 -0800 | [diff] [blame] | 312 | jvmtiError ret; |
| 313 | name_copy = CopyString(env, method_name, &ret); |
| 314 | if (name_copy == nullptr) { |
Andreas Gampe | 3c252f0 | 2016-10-27 18:25:17 -0700 | [diff] [blame] | 315 | return ret; |
| 316 | } |
Andreas Gampe | 5471141 | 2017-02-21 12:41:43 -0800 | [diff] [blame] | 317 | *name_ptr = name_copy.get(); |
Andreas Gampe | 3c252f0 | 2016-10-27 18:25:17 -0700 | [diff] [blame] | 318 | } |
| 319 | |
Andreas Gampe | 5471141 | 2017-02-21 12:41:43 -0800 | [diff] [blame] | 320 | JvmtiUniquePtr<char[]> signature_copy; |
Andreas Gampe | 3c252f0 | 2016-10-27 18:25:17 -0700 | [diff] [blame] | 321 | if (signature_ptr != nullptr) { |
| 322 | const art::Signature sig = art_method->GetSignature(); |
| 323 | std::string str = sig.ToString(); |
Andreas Gampe | 5471141 | 2017-02-21 12:41:43 -0800 | [diff] [blame] | 324 | jvmtiError ret; |
| 325 | signature_copy = CopyString(env, str.c_str(), &ret); |
| 326 | if (signature_copy == nullptr) { |
Andreas Gampe | 3c252f0 | 2016-10-27 18:25:17 -0700 | [diff] [blame] | 327 | return ret; |
| 328 | } |
Andreas Gampe | 5471141 | 2017-02-21 12:41:43 -0800 | [diff] [blame] | 329 | *signature_ptr = signature_copy.get(); |
Andreas Gampe | 3c252f0 | 2016-10-27 18:25:17 -0700 | [diff] [blame] | 330 | } |
| 331 | |
Andreas Gampe | 862bdd8 | 2016-11-18 13:31:13 -0800 | [diff] [blame] | 332 | if (generic_ptr != nullptr) { |
| 333 | *generic_ptr = nullptr; |
Andreas Gampe | 27dfa05 | 2017-02-16 15:04:36 -0800 | [diff] [blame] | 334 | if (!art_method->GetDeclaringClass()->IsProxyClass()) { |
Vladimir Marko | acb906d | 2018-05-30 10:23:49 +0100 | [diff] [blame] | 335 | art::ObjPtr<art::mirror::ObjectArray<art::mirror::String>> str_array = |
Andreas Gampe | 27dfa05 | 2017-02-16 15:04:36 -0800 | [diff] [blame] | 336 | art::annotations::GetSignatureAnnotationForMethod(art_method); |
| 337 | if (str_array != nullptr) { |
| 338 | std::ostringstream oss; |
| 339 | for (int32_t i = 0; i != str_array->GetLength(); ++i) { |
| 340 | oss << str_array->Get(i)->ToModifiedUtf8(); |
| 341 | } |
| 342 | std::string output_string = oss.str(); |
Andreas Gampe | 5471141 | 2017-02-21 12:41:43 -0800 | [diff] [blame] | 343 | jvmtiError ret; |
| 344 | JvmtiUniquePtr<char[]> generic_copy = CopyString(env, output_string.c_str(), &ret); |
| 345 | if (generic_copy == nullptr) { |
Andreas Gampe | 27dfa05 | 2017-02-16 15:04:36 -0800 | [diff] [blame] | 346 | return ret; |
| 347 | } |
Andreas Gampe | 5471141 | 2017-02-21 12:41:43 -0800 | [diff] [blame] | 348 | *generic_ptr = generic_copy.release(); |
Andreas Gampe | 27dfa05 | 2017-02-16 15:04:36 -0800 | [diff] [blame] | 349 | } else if (soa.Self()->IsExceptionPending()) { |
| 350 | // TODO: Should we report an error here? |
| 351 | soa.Self()->ClearException(); |
| 352 | } |
| 353 | } |
Andreas Gampe | 862bdd8 | 2016-11-18 13:31:13 -0800 | [diff] [blame] | 354 | } |
Andreas Gampe | 3c252f0 | 2016-10-27 18:25:17 -0700 | [diff] [blame] | 355 | |
| 356 | // Everything is fine, release the buffers. |
| 357 | name_copy.release(); |
| 358 | signature_copy.release(); |
| 359 | |
| 360 | return ERR(NONE); |
| 361 | } |
| 362 | |
Andreas Gampe | 368a208 | 2016-10-28 17:33:13 -0700 | [diff] [blame] | 363 | jvmtiError MethodUtil::GetMethodDeclaringClass(jvmtiEnv* env ATTRIBUTE_UNUSED, |
| 364 | jmethodID method, |
| 365 | jclass* declaring_class_ptr) { |
| 366 | if (declaring_class_ptr == nullptr) { |
| 367 | return ERR(NULL_POINTER); |
| 368 | } |
| 369 | |
Andreas Gampe | 13b2784 | 2016-11-07 16:48:23 -0800 | [diff] [blame] | 370 | art::ArtMethod* art_method = art::jni::DecodeArtMethod(method); |
Andreas Gampe | 368a208 | 2016-10-28 17:33:13 -0700 | [diff] [blame] | 371 | // Note: No GetInterfaceMethodIfProxy, we want to actual class. |
| 372 | |
Andreas Gampe | 13b2784 | 2016-11-07 16:48:23 -0800 | [diff] [blame] | 373 | art::ScopedObjectAccess soa(art::Thread::Current()); |
Vladimir Marko | d93e374 | 2018-07-18 10:58:13 +0100 | [diff] [blame] | 374 | art::ObjPtr<art::mirror::Class> klass = art_method->GetDeclaringClass(); |
Andreas Gampe | 368a208 | 2016-10-28 17:33:13 -0700 | [diff] [blame] | 375 | *declaring_class_ptr = soa.AddLocalReference<jclass>(klass); |
| 376 | |
| 377 | return ERR(NONE); |
| 378 | } |
| 379 | |
Andreas Gampe | f71832e | 2017-01-09 11:38:04 -0800 | [diff] [blame] | 380 | jvmtiError MethodUtil::GetMethodLocation(jvmtiEnv* env ATTRIBUTE_UNUSED, |
| 381 | jmethodID method, |
| 382 | jlocation* start_location_ptr, |
| 383 | jlocation* end_location_ptr) { |
| 384 | if (method == nullptr) { |
| 385 | return ERR(INVALID_METHODID); |
| 386 | } |
| 387 | art::ArtMethod* art_method = art::jni::DecodeArtMethod(method); |
| 388 | |
| 389 | if (art_method->IsNative()) { |
| 390 | return ERR(NATIVE_METHOD); |
| 391 | } |
| 392 | |
| 393 | if (start_location_ptr == nullptr || end_location_ptr == nullptr) { |
| 394 | return ERR(NULL_POINTER); |
| 395 | } |
| 396 | |
| 397 | art::ScopedObjectAccess soa(art::Thread::Current()); |
| 398 | if (art_method->IsProxyMethod() || art_method->IsAbstract()) { |
Andreas Gampe | e1f79b6 | 2017-04-12 21:11:28 -0700 | [diff] [blame] | 399 | // This isn't specified as an error case, so return -1/-1 as the RI does. |
| 400 | *start_location_ptr = -1; |
| 401 | *end_location_ptr = -1; |
Andreas Gampe | f71832e | 2017-01-09 11:38:04 -0800 | [diff] [blame] | 402 | return ERR(NONE); |
| 403 | } |
| 404 | |
| 405 | DCHECK_NE(art_method->GetCodeItemOffset(), 0u); |
| 406 | *start_location_ptr = 0; |
Mathieu Chartier | 808c7a5 | 2017-12-15 11:19:33 -0800 | [diff] [blame] | 407 | *end_location_ptr = art_method->DexInstructions().InsnsSizeInCodeUnits() - 1; |
Andreas Gampe | f71832e | 2017-01-09 11:38:04 -0800 | [diff] [blame] | 408 | |
| 409 | return ERR(NONE); |
| 410 | } |
| 411 | |
Andreas Gampe | 36bcd4f | 2016-10-28 18:07:18 -0700 | [diff] [blame] | 412 | jvmtiError MethodUtil::GetMethodModifiers(jvmtiEnv* env ATTRIBUTE_UNUSED, |
| 413 | jmethodID method, |
| 414 | jint* modifiers_ptr) { |
| 415 | if (modifiers_ptr == nullptr) { |
| 416 | return ERR(NULL_POINTER); |
| 417 | } |
| 418 | |
Andreas Gampe | 13b2784 | 2016-11-07 16:48:23 -0800 | [diff] [blame] | 419 | art::ArtMethod* art_method = art::jni::DecodeArtMethod(method); |
Andreas Gampe | 36bcd4f | 2016-10-28 18:07:18 -0700 | [diff] [blame] | 420 | uint32_t modifiers = art_method->GetAccessFlags(); |
| 421 | |
| 422 | // Note: Keep this code in sync with Executable.fixMethodFlags. |
| 423 | if ((modifiers & art::kAccAbstract) != 0) { |
| 424 | modifiers &= ~art::kAccNative; |
| 425 | } |
| 426 | modifiers &= ~art::kAccSynchronized; |
| 427 | if ((modifiers & art::kAccDeclaredSynchronized) != 0) { |
| 428 | modifiers |= art::kAccSynchronized; |
| 429 | } |
| 430 | modifiers &= art::kAccJavaFlagsMask; |
| 431 | |
| 432 | *modifiers_ptr = modifiers; |
| 433 | return ERR(NONE); |
| 434 | } |
| 435 | |
Andreas Gampe | da3e561 | 2016-12-13 19:00:53 -0800 | [diff] [blame] | 436 | jvmtiError MethodUtil::GetLineNumberTable(jvmtiEnv* env, |
| 437 | jmethodID method, |
| 438 | jint* entry_count_ptr, |
| 439 | jvmtiLineNumberEntry** table_ptr) { |
| 440 | if (method == nullptr) { |
| 441 | return ERR(NULL_POINTER); |
| 442 | } |
| 443 | art::ArtMethod* art_method = art::jni::DecodeArtMethod(method); |
| 444 | DCHECK(!art_method->IsRuntimeMethod()); |
| 445 | |
Mathieu Chartier | 31f4c9f | 2017-12-08 15:46:11 -0800 | [diff] [blame] | 446 | art::CodeItemDebugInfoAccessor accessor; |
Andreas Gampe | da3e561 | 2016-12-13 19:00:53 -0800 | [diff] [blame] | 447 | const art::DexFile* dex_file; |
| 448 | { |
| 449 | art::ScopedObjectAccess soa(art::Thread::Current()); |
| 450 | |
| 451 | if (art_method->IsProxyMethod()) { |
| 452 | return ERR(ABSENT_INFORMATION); |
| 453 | } |
| 454 | if (art_method->IsNative()) { |
| 455 | return ERR(NATIVE_METHOD); |
| 456 | } |
| 457 | if (entry_count_ptr == nullptr || table_ptr == nullptr) { |
| 458 | return ERR(NULL_POINTER); |
| 459 | } |
| 460 | |
David Sehr | 0225f8e | 2018-01-31 08:52:24 +0000 | [diff] [blame] | 461 | accessor = art::CodeItemDebugInfoAccessor(art_method->DexInstructionDebugInfo()); |
Andreas Gampe | da3e561 | 2016-12-13 19:00:53 -0800 | [diff] [blame] | 462 | dex_file = art_method->GetDexFile(); |
Mathieu Chartier | 31f4c9f | 2017-12-08 15:46:11 -0800 | [diff] [blame] | 463 | DCHECK(accessor.HasCodeItem()) << art_method->PrettyMethod() << " " << dex_file->GetLocation(); |
Andreas Gampe | da3e561 | 2016-12-13 19:00:53 -0800 | [diff] [blame] | 464 | } |
| 465 | |
Mathieu Chartier | 3e2e123 | 2018-09-11 12:35:30 -0700 | [diff] [blame] | 466 | std::vector<jvmtiLineNumberEntry> context; |
| 467 | bool success = accessor.DecodeDebugPositionInfo([&](const art::DexFile::PositionInfo& entry) { |
| 468 | context.push_back({static_cast<jlocation>(entry.address_), static_cast<jint>(entry.line_)}); |
| 469 | return false; |
| 470 | }); |
Andreas Gampe | da3e561 | 2016-12-13 19:00:53 -0800 | [diff] [blame] | 471 | if (!success) { |
| 472 | return ERR(ABSENT_INFORMATION); |
| 473 | } |
| 474 | |
| 475 | unsigned char* data; |
| 476 | jlong mem_size = context.size() * sizeof(jvmtiLineNumberEntry); |
| 477 | jvmtiError alloc_error = env->Allocate(mem_size, &data); |
| 478 | if (alloc_error != ERR(NONE)) { |
| 479 | return alloc_error; |
| 480 | } |
| 481 | *table_ptr = reinterpret_cast<jvmtiLineNumberEntry*>(data); |
| 482 | memcpy(*table_ptr, context.data(), mem_size); |
| 483 | *entry_count_ptr = static_cast<jint>(context.size()); |
| 484 | |
| 485 | return ERR(NONE); |
| 486 | } |
| 487 | |
Andreas Gampe | fdeef52 | 2017-01-09 14:40:25 -0800 | [diff] [blame] | 488 | template <typename T> |
| 489 | static jvmtiError IsMethodT(jvmtiEnv* env ATTRIBUTE_UNUSED, |
| 490 | jmethodID method, |
| 491 | T test, |
| 492 | jboolean* is_t_ptr) { |
| 493 | if (method == nullptr) { |
| 494 | return ERR(INVALID_METHODID); |
| 495 | } |
| 496 | if (is_t_ptr == nullptr) { |
| 497 | return ERR(NULL_POINTER); |
| 498 | } |
| 499 | |
| 500 | art::ArtMethod* art_method = art::jni::DecodeArtMethod(method); |
| 501 | *is_t_ptr = test(art_method) ? JNI_TRUE : JNI_FALSE; |
| 502 | |
| 503 | return ERR(NONE); |
| 504 | } |
| 505 | |
| 506 | jvmtiError MethodUtil::IsMethodNative(jvmtiEnv* env, jmethodID m, jboolean* is_native_ptr) { |
| 507 | auto test = [](art::ArtMethod* method) { |
| 508 | return method->IsNative(); |
| 509 | }; |
| 510 | return IsMethodT(env, m, test, is_native_ptr); |
| 511 | } |
| 512 | |
| 513 | jvmtiError MethodUtil::IsMethodObsolete(jvmtiEnv* env, jmethodID m, jboolean* is_obsolete_ptr) { |
| 514 | auto test = [](art::ArtMethod* method) { |
| 515 | return method->IsObsolete(); |
| 516 | }; |
| 517 | return IsMethodT(env, m, test, is_obsolete_ptr); |
| 518 | } |
| 519 | |
| 520 | jvmtiError MethodUtil::IsMethodSynthetic(jvmtiEnv* env, jmethodID m, jboolean* is_synthetic_ptr) { |
| 521 | auto test = [](art::ArtMethod* method) { |
| 522 | return method->IsSynthetic(); |
| 523 | }; |
| 524 | return IsMethodT(env, m, test, is_synthetic_ptr); |
| 525 | } |
| 526 | |
Alex Light | bebd7bd | 2017-07-25 14:05:52 -0700 | [diff] [blame] | 527 | class CommonLocalVariableClosure : public art::Closure { |
| 528 | public: |
Alex Light | 318afe6 | 2018-03-22 16:50:10 -0700 | [diff] [blame] | 529 | CommonLocalVariableClosure(jint depth, jint slot) |
| 530 | : result_(ERR(INTERNAL)), depth_(depth), slot_(slot) {} |
Alex Light | bebd7bd | 2017-07-25 14:05:52 -0700 | [diff] [blame] | 531 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 532 | void Run(art::Thread* self) override REQUIRES(art::Locks::mutator_lock_) { |
Alex Light | bebd7bd | 2017-07-25 14:05:52 -0700 | [diff] [blame] | 533 | art::Locks::mutator_lock_->AssertSharedHeld(art::Thread::Current()); |
Alex Light | a4cdd36 | 2019-04-18 09:17:10 -0700 | [diff] [blame^] | 534 | bool needs_instrument; |
| 535 | { |
| 536 | art::ScopedAssertNoThreadSuspension sants("CommonLocalVariableClosure::Run"); |
| 537 | std::unique_ptr<art::Context> context(art::Context::Create()); |
| 538 | FindFrameAtDepthVisitor visitor(self, context.get(), depth_); |
| 539 | visitor.WalkStack(); |
| 540 | if (!visitor.FoundFrame()) { |
| 541 | // Must have been a bad depth. |
| 542 | result_ = ERR(NO_MORE_FRAMES); |
| 543 | return; |
| 544 | } |
| 545 | art::ArtMethod* method = visitor.GetMethod(); |
| 546 | // Native and 'art' proxy methods don't have registers. |
| 547 | if (method->IsNative() || method->IsProxyMethod()) { |
| 548 | // TODO It might be useful to fake up support for get at least on proxy frames. |
| 549 | result_ = ERR(OPAQUE_FRAME); |
| 550 | return; |
| 551 | } else if (method->DexInstructionData().RegistersSize() <= slot_) { |
| 552 | result_ = ERR(INVALID_SLOT); |
| 553 | return; |
| 554 | } |
| 555 | needs_instrument = !visitor.IsShadowFrame(); |
| 556 | uint32_t pc = visitor.GetDexPc(/*abort_on_failure=*/false); |
| 557 | if (pc == art::dex::kDexNoIndex) { |
| 558 | // Cannot figure out current PC. |
| 559 | result_ = ERR(OPAQUE_FRAME); |
| 560 | return; |
| 561 | } |
| 562 | std::string descriptor; |
| 563 | art::Primitive::Type slot_type = art::Primitive::kPrimVoid; |
| 564 | jvmtiError err = GetSlotType(method, pc, &descriptor, &slot_type); |
| 565 | if (err != OK) { |
| 566 | result_ = err; |
| 567 | return; |
| 568 | } |
Alex Light | bebd7bd | 2017-07-25 14:05:52 -0700 | [diff] [blame] | 569 | |
Alex Light | a4cdd36 | 2019-04-18 09:17:10 -0700 | [diff] [blame^] | 570 | err = GetTypeError(method, slot_type, descriptor); |
| 571 | if (err != OK) { |
| 572 | result_ = err; |
| 573 | return; |
| 574 | } |
| 575 | result_ = Execute(method, visitor); |
Alex Light | bebd7bd | 2017-07-25 14:05:52 -0700 | [diff] [blame] | 576 | } |
Alex Light | 0a5ec3d | 2017-07-25 16:50:26 -0700 | [diff] [blame] | 577 | if (needs_instrument) { |
Alex Light | a4cdd36 | 2019-04-18 09:17:10 -0700 | [diff] [blame^] | 578 | DeoptManager::Get()->DeoptimizeThread(self); |
Alex Light | 0a5ec3d | 2017-07-25 16:50:26 -0700 | [diff] [blame] | 579 | } |
Alex Light | bebd7bd | 2017-07-25 14:05:52 -0700 | [diff] [blame] | 580 | } |
| 581 | |
Alex Light | 318afe6 | 2018-03-22 16:50:10 -0700 | [diff] [blame] | 582 | virtual jvmtiError GetResult() { |
Alex Light | bebd7bd | 2017-07-25 14:05:52 -0700 | [diff] [blame] | 583 | return result_; |
| 584 | } |
| 585 | |
| 586 | protected: |
| 587 | virtual jvmtiError Execute(art::ArtMethod* method, art::StackVisitor& visitor) |
Alex Light | 318afe6 | 2018-03-22 16:50:10 -0700 | [diff] [blame] | 588 | REQUIRES_SHARED(art::Locks::mutator_lock_) = 0; |
Alex Light | bebd7bd | 2017-07-25 14:05:52 -0700 | [diff] [blame] | 589 | virtual jvmtiError GetTypeError(art::ArtMethod* method, |
| 590 | art::Primitive::Type type, |
| 591 | const std::string& descriptor) |
Alex Light | 318afe6 | 2018-03-22 16:50:10 -0700 | [diff] [blame] | 592 | REQUIRES_SHARED(art::Locks::mutator_lock_) = 0; |
Alex Light | bebd7bd | 2017-07-25 14:05:52 -0700 | [diff] [blame] | 593 | |
| 594 | jvmtiError GetSlotType(art::ArtMethod* method, |
| 595 | uint32_t dex_pc, |
| 596 | /*out*/std::string* descriptor, |
| 597 | /*out*/art::Primitive::Type* type) |
| 598 | REQUIRES(art::Locks::mutator_lock_) { |
| 599 | const art::DexFile* dex_file = method->GetDexFile(); |
Mathieu Chartier | 31f4c9f | 2017-12-08 15:46:11 -0800 | [diff] [blame] | 600 | if (dex_file == nullptr) { |
| 601 | return ERR(OPAQUE_FRAME); |
| 602 | } |
David Sehr | 0225f8e | 2018-01-31 08:52:24 +0000 | [diff] [blame] | 603 | art::CodeItemDebugInfoAccessor accessor(method->DexInstructionDebugInfo()); |
Mathieu Chartier | 31f4c9f | 2017-12-08 15:46:11 -0800 | [diff] [blame] | 604 | if (!accessor.HasCodeItem()) { |
Alex Light | bebd7bd | 2017-07-25 14:05:52 -0700 | [diff] [blame] | 605 | return ERR(OPAQUE_FRAME); |
| 606 | } |
Mathieu Chartier | e5afbf3 | 2018-09-12 17:51:54 -0700 | [diff] [blame] | 607 | bool found = false; |
| 608 | *type = art::Primitive::kPrimVoid; |
| 609 | descriptor->clear(); |
| 610 | auto visitor = [&](const art::DexFile::LocalInfo& entry) { |
| 611 | if (!found && |
| 612 | entry.start_address_ <= dex_pc && |
| 613 | entry.end_address_ > dex_pc && |
| 614 | entry.reg_ == slot_) { |
| 615 | found = true; |
| 616 | *type = art::Primitive::GetType(entry.descriptor_[0]); |
| 617 | *descriptor = entry.descriptor_; |
Alex Light | bebd7bd | 2017-07-25 14:05:52 -0700 | [diff] [blame] | 618 | } |
Alex Light | bebd7bd | 2017-07-25 14:05:52 -0700 | [diff] [blame] | 619 | }; |
Mathieu Chartier | e5afbf3 | 2018-09-12 17:51:54 -0700 | [diff] [blame] | 620 | if (!accessor.DecodeDebugLocalInfo(method->IsStatic(), method->GetDexMethodIndex(), visitor) || |
| 621 | !found) { |
Alex Light | bebd7bd | 2017-07-25 14:05:52 -0700 | [diff] [blame] | 622 | // Something went wrong with decoding the debug information. It might as well not be there. |
| 623 | return ERR(INVALID_SLOT); |
Alex Light | bebd7bd | 2017-07-25 14:05:52 -0700 | [diff] [blame] | 624 | } |
Mathieu Chartier | e5afbf3 | 2018-09-12 17:51:54 -0700 | [diff] [blame] | 625 | return OK; |
Alex Light | bebd7bd | 2017-07-25 14:05:52 -0700 | [diff] [blame] | 626 | } |
| 627 | |
| 628 | jvmtiError result_; |
Alex Light | bebd7bd | 2017-07-25 14:05:52 -0700 | [diff] [blame] | 629 | jint depth_; |
| 630 | jint slot_; |
| 631 | }; |
| 632 | |
| 633 | class GetLocalVariableClosure : public CommonLocalVariableClosure { |
| 634 | public: |
Alex Light | 318afe6 | 2018-03-22 16:50:10 -0700 | [diff] [blame] | 635 | GetLocalVariableClosure(jint depth, |
Alex Light | bebd7bd | 2017-07-25 14:05:52 -0700 | [diff] [blame] | 636 | jint slot, |
| 637 | art::Primitive::Type type, |
| 638 | jvalue* val) |
Alex Light | 318afe6 | 2018-03-22 16:50:10 -0700 | [diff] [blame] | 639 | : CommonLocalVariableClosure(depth, slot), |
| 640 | type_(type), |
| 641 | val_(val), |
| 642 | obj_val_(nullptr) {} |
| 643 | |
Andreas Gampe | fa6a1b0 | 2018-09-07 08:11:55 -0700 | [diff] [blame] | 644 | jvmtiError GetResult() override REQUIRES_SHARED(art::Locks::mutator_lock_) { |
Alex Light | 318afe6 | 2018-03-22 16:50:10 -0700 | [diff] [blame] | 645 | if (result_ == OK && type_ == art::Primitive::kPrimNot) { |
Alex Light | a4cdd36 | 2019-04-18 09:17:10 -0700 | [diff] [blame^] | 646 | if (obj_val_ == nullptr) { |
| 647 | val_->l = nullptr; |
| 648 | } else { |
| 649 | art::JNIEnvExt* jni = art::Thread::Current()->GetJniEnv(); |
| 650 | val_->l = static_cast<JNIEnv*>(jni)->NewLocalRef(obj_val_); |
| 651 | jni->DeleteGlobalRef(obj_val_); |
| 652 | obj_val_ = nullptr; |
| 653 | } |
Alex Light | 318afe6 | 2018-03-22 16:50:10 -0700 | [diff] [blame] | 654 | } |
| 655 | return CommonLocalVariableClosure::GetResult(); |
| 656 | } |
Alex Light | bebd7bd | 2017-07-25 14:05:52 -0700 | [diff] [blame] | 657 | |
| 658 | protected: |
| 659 | jvmtiError GetTypeError(art::ArtMethod* method ATTRIBUTE_UNUSED, |
| 660 | art::Primitive::Type slot_type, |
| 661 | const std::string& descriptor ATTRIBUTE_UNUSED) |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 662 | override REQUIRES_SHARED(art::Locks::mutator_lock_) { |
Alex Light | bebd7bd | 2017-07-25 14:05:52 -0700 | [diff] [blame] | 663 | switch (slot_type) { |
| 664 | case art::Primitive::kPrimByte: |
| 665 | case art::Primitive::kPrimChar: |
| 666 | case art::Primitive::kPrimInt: |
| 667 | case art::Primitive::kPrimShort: |
| 668 | case art::Primitive::kPrimBoolean: |
| 669 | return type_ == art::Primitive::kPrimInt ? OK : ERR(TYPE_MISMATCH); |
| 670 | case art::Primitive::kPrimLong: |
| 671 | case art::Primitive::kPrimFloat: |
| 672 | case art::Primitive::kPrimDouble: |
| 673 | case art::Primitive::kPrimNot: |
| 674 | return type_ == slot_type ? OK : ERR(TYPE_MISMATCH); |
| 675 | case art::Primitive::kPrimVoid: |
| 676 | LOG(FATAL) << "Unexpected primitive type " << slot_type; |
| 677 | UNREACHABLE(); |
| 678 | } |
| 679 | } |
| 680 | |
| 681 | jvmtiError Execute(art::ArtMethod* method, art::StackVisitor& visitor) |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 682 | override REQUIRES_SHARED(art::Locks::mutator_lock_) { |
Alex Light | bebd7bd | 2017-07-25 14:05:52 -0700 | [diff] [blame] | 683 | switch (type_) { |
| 684 | case art::Primitive::kPrimNot: { |
| 685 | uint32_t ptr_val; |
| 686 | if (!visitor.GetVReg(method, |
| 687 | static_cast<uint16_t>(slot_), |
| 688 | art::kReferenceVReg, |
| 689 | &ptr_val)) { |
| 690 | return ERR(OPAQUE_FRAME); |
| 691 | } |
Alex Light | a4cdd36 | 2019-04-18 09:17:10 -0700 | [diff] [blame^] | 692 | art::JNIEnvExt* jni = art::Thread::Current()->GetJniEnv(); |
| 693 | art::ObjPtr<art::mirror::Object> obj(reinterpret_cast<art::mirror::Object*>(ptr_val)); |
| 694 | ScopedLocalRef<jobject> local(jni, jni->AddLocalReference<jobject>(obj)); |
| 695 | obj_val_ = jni->NewGlobalRef(local.get()); |
Alex Light | bebd7bd | 2017-07-25 14:05:52 -0700 | [diff] [blame] | 696 | break; |
| 697 | } |
| 698 | case art::Primitive::kPrimInt: |
| 699 | case art::Primitive::kPrimFloat: { |
| 700 | if (!visitor.GetVReg(method, |
| 701 | static_cast<uint16_t>(slot_), |
| 702 | type_ == art::Primitive::kPrimFloat ? art::kFloatVReg : art::kIntVReg, |
| 703 | reinterpret_cast<uint32_t*>(&val_->i))) { |
| 704 | return ERR(OPAQUE_FRAME); |
| 705 | } |
| 706 | break; |
| 707 | } |
| 708 | case art::Primitive::kPrimDouble: |
| 709 | case art::Primitive::kPrimLong: { |
| 710 | auto lo_type = type_ == art::Primitive::kPrimLong ? art::kLongLoVReg : art::kDoubleLoVReg; |
| 711 | auto high_type = type_ == art::Primitive::kPrimLong ? art::kLongHiVReg : art::kDoubleHiVReg; |
| 712 | if (!visitor.GetVRegPair(method, |
| 713 | static_cast<uint16_t>(slot_), |
| 714 | lo_type, |
| 715 | high_type, |
| 716 | reinterpret_cast<uint64_t*>(&val_->j))) { |
| 717 | return ERR(OPAQUE_FRAME); |
| 718 | } |
| 719 | break; |
| 720 | } |
| 721 | default: { |
| 722 | LOG(FATAL) << "unexpected register type " << type_; |
| 723 | UNREACHABLE(); |
| 724 | } |
| 725 | } |
| 726 | return OK; |
| 727 | } |
| 728 | |
| 729 | private: |
| 730 | art::Primitive::Type type_; |
| 731 | jvalue* val_; |
Alex Light | a4cdd36 | 2019-04-18 09:17:10 -0700 | [diff] [blame^] | 732 | // A global reference to the return value. We use the global reference to safely transfer the |
| 733 | // value between threads. |
| 734 | jobject obj_val_; |
Alex Light | bebd7bd | 2017-07-25 14:05:52 -0700 | [diff] [blame] | 735 | }; |
| 736 | |
| 737 | jvmtiError MethodUtil::GetLocalVariableGeneric(jvmtiEnv* env ATTRIBUTE_UNUSED, |
| 738 | jthread thread, |
| 739 | jint depth, |
| 740 | jint slot, |
| 741 | art::Primitive::Type type, |
| 742 | jvalue* val) { |
| 743 | if (depth < 0) { |
| 744 | return ERR(ILLEGAL_ARGUMENT); |
| 745 | } |
| 746 | art::Thread* self = art::Thread::Current(); |
| 747 | art::ScopedObjectAccess soa(self); |
Alex Light | b1e31a8 | 2017-10-04 16:57:36 -0700 | [diff] [blame] | 748 | art::Locks::thread_list_lock_->ExclusiveLock(self); |
Alex Light | 7ddc23d | 2017-09-22 15:33:41 -0700 | [diff] [blame] | 749 | art::Thread* target = nullptr; |
| 750 | jvmtiError err = ERR(INTERNAL); |
| 751 | if (!ThreadUtil::GetAliveNativeThread(thread, soa, &target, &err)) { |
Alex Light | b1e31a8 | 2017-10-04 16:57:36 -0700 | [diff] [blame] | 752 | art::Locks::thread_list_lock_->ExclusiveUnlock(self); |
Alex Light | 7ddc23d | 2017-09-22 15:33:41 -0700 | [diff] [blame] | 753 | return err; |
Alex Light | bebd7bd | 2017-07-25 14:05:52 -0700 | [diff] [blame] | 754 | } |
Alex Light | 318afe6 | 2018-03-22 16:50:10 -0700 | [diff] [blame] | 755 | GetLocalVariableClosure c(depth, slot, type, val); |
Alex Light | a4cdd36 | 2019-04-18 09:17:10 -0700 | [diff] [blame^] | 756 | // RequestSynchronousCheckpoint releases the thread_list_lock_ as a part of its execution. |
| 757 | if (!target->RequestSynchronousCheckpoint(&c)) { |
Alex Light | bebd7bd | 2017-07-25 14:05:52 -0700 | [diff] [blame] | 758 | return ERR(THREAD_NOT_ALIVE); |
| 759 | } else { |
| 760 | return c.GetResult(); |
| 761 | } |
| 762 | } |
| 763 | |
| 764 | class SetLocalVariableClosure : public CommonLocalVariableClosure { |
| 765 | public: |
| 766 | SetLocalVariableClosure(art::Thread* caller, |
| 767 | jint depth, |
| 768 | jint slot, |
| 769 | art::Primitive::Type type, |
| 770 | jvalue val) |
Alex Light | 318afe6 | 2018-03-22 16:50:10 -0700 | [diff] [blame] | 771 | : CommonLocalVariableClosure(depth, slot), caller_(caller), type_(type), val_(val) {} |
Alex Light | bebd7bd | 2017-07-25 14:05:52 -0700 | [diff] [blame] | 772 | |
| 773 | protected: |
| 774 | jvmtiError GetTypeError(art::ArtMethod* method, |
| 775 | art::Primitive::Type slot_type, |
| 776 | const std::string& descriptor) |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 777 | override REQUIRES_SHARED(art::Locks::mutator_lock_) { |
Alex Light | bebd7bd | 2017-07-25 14:05:52 -0700 | [diff] [blame] | 778 | switch (slot_type) { |
| 779 | case art::Primitive::kPrimNot: { |
| 780 | if (type_ != art::Primitive::kPrimNot) { |
| 781 | return ERR(TYPE_MISMATCH); |
| 782 | } else if (val_.l == nullptr) { |
| 783 | return OK; |
| 784 | } else { |
| 785 | art::ClassLinker* cl = art::Runtime::Current()->GetClassLinker(); |
| 786 | art::ObjPtr<art::mirror::Class> set_class = |
| 787 | caller_->DecodeJObject(val_.l)->GetClass(); |
| 788 | art::ObjPtr<art::mirror::ClassLoader> loader = |
| 789 | method->GetDeclaringClass()->GetClassLoader(); |
| 790 | art::ObjPtr<art::mirror::Class> slot_class = |
| 791 | cl->LookupClass(caller_, descriptor.c_str(), loader); |
| 792 | DCHECK(!slot_class.IsNull()); |
| 793 | return slot_class->IsAssignableFrom(set_class) ? OK : ERR(TYPE_MISMATCH); |
| 794 | } |
| 795 | } |
| 796 | case art::Primitive::kPrimByte: |
| 797 | case art::Primitive::kPrimChar: |
| 798 | case art::Primitive::kPrimInt: |
| 799 | case art::Primitive::kPrimShort: |
| 800 | case art::Primitive::kPrimBoolean: |
| 801 | return type_ == art::Primitive::kPrimInt ? OK : ERR(TYPE_MISMATCH); |
| 802 | case art::Primitive::kPrimLong: |
| 803 | case art::Primitive::kPrimFloat: |
| 804 | case art::Primitive::kPrimDouble: |
| 805 | return type_ == slot_type ? OK : ERR(TYPE_MISMATCH); |
| 806 | case art::Primitive::kPrimVoid: |
| 807 | LOG(FATAL) << "Unexpected primitive type " << slot_type; |
| 808 | UNREACHABLE(); |
| 809 | } |
| 810 | } |
| 811 | |
| 812 | jvmtiError Execute(art::ArtMethod* method, art::StackVisitor& visitor) |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 813 | override REQUIRES_SHARED(art::Locks::mutator_lock_) { |
Alex Light | bebd7bd | 2017-07-25 14:05:52 -0700 | [diff] [blame] | 814 | switch (type_) { |
| 815 | case art::Primitive::kPrimNot: { |
| 816 | uint32_t ptr_val; |
| 817 | art::ObjPtr<art::mirror::Object> obj(caller_->DecodeJObject(val_.l)); |
| 818 | ptr_val = static_cast<uint32_t>(reinterpret_cast<uintptr_t>(obj.Ptr())); |
| 819 | if (!visitor.SetVReg(method, |
| 820 | static_cast<uint16_t>(slot_), |
| 821 | ptr_val, |
| 822 | art::kReferenceVReg)) { |
| 823 | return ERR(OPAQUE_FRAME); |
| 824 | } |
| 825 | break; |
| 826 | } |
| 827 | case art::Primitive::kPrimInt: |
| 828 | case art::Primitive::kPrimFloat: { |
| 829 | if (!visitor.SetVReg(method, |
| 830 | static_cast<uint16_t>(slot_), |
| 831 | static_cast<uint32_t>(val_.i), |
| 832 | type_ == art::Primitive::kPrimFloat ? art::kFloatVReg |
| 833 | : art::kIntVReg)) { |
| 834 | return ERR(OPAQUE_FRAME); |
| 835 | } |
| 836 | break; |
| 837 | } |
| 838 | case art::Primitive::kPrimDouble: |
| 839 | case art::Primitive::kPrimLong: { |
| 840 | auto lo_type = type_ == art::Primitive::kPrimLong ? art::kLongLoVReg : art::kDoubleLoVReg; |
| 841 | auto high_type = type_ == art::Primitive::kPrimLong ? art::kLongHiVReg : art::kDoubleHiVReg; |
| 842 | if (!visitor.SetVRegPair(method, |
| 843 | static_cast<uint16_t>(slot_), |
| 844 | static_cast<uint64_t>(val_.j), |
| 845 | lo_type, |
| 846 | high_type)) { |
| 847 | return ERR(OPAQUE_FRAME); |
| 848 | } |
| 849 | break; |
| 850 | } |
| 851 | default: { |
| 852 | LOG(FATAL) << "unexpected register type " << type_; |
| 853 | UNREACHABLE(); |
| 854 | } |
| 855 | } |
| 856 | return OK; |
| 857 | } |
| 858 | |
| 859 | private: |
Alex Light | 318afe6 | 2018-03-22 16:50:10 -0700 | [diff] [blame] | 860 | art::Thread* caller_; |
Alex Light | bebd7bd | 2017-07-25 14:05:52 -0700 | [diff] [blame] | 861 | art::Primitive::Type type_; |
| 862 | jvalue val_; |
| 863 | }; |
| 864 | |
| 865 | jvmtiError MethodUtil::SetLocalVariableGeneric(jvmtiEnv* env ATTRIBUTE_UNUSED, |
| 866 | jthread thread, |
| 867 | jint depth, |
| 868 | jint slot, |
| 869 | art::Primitive::Type type, |
| 870 | jvalue val) { |
| 871 | if (depth < 0) { |
| 872 | return ERR(ILLEGAL_ARGUMENT); |
| 873 | } |
Alex Light | f285863 | 2018-04-02 11:28:50 -0700 | [diff] [blame] | 874 | // Make sure that we know not to do any OSR anymore. |
| 875 | // TODO We should really keep track of this at the Frame granularity. |
| 876 | DeoptManager::Get()->SetLocalsUpdated(); |
Alex Light | bebd7bd | 2017-07-25 14:05:52 -0700 | [diff] [blame] | 877 | art::Thread* self = art::Thread::Current(); |
| 878 | art::ScopedObjectAccess soa(self); |
Alex Light | b1e31a8 | 2017-10-04 16:57:36 -0700 | [diff] [blame] | 879 | art::Locks::thread_list_lock_->ExclusiveLock(self); |
Alex Light | 7ddc23d | 2017-09-22 15:33:41 -0700 | [diff] [blame] | 880 | art::Thread* target = nullptr; |
| 881 | jvmtiError err = ERR(INTERNAL); |
| 882 | if (!ThreadUtil::GetAliveNativeThread(thread, soa, &target, &err)) { |
Alex Light | b1e31a8 | 2017-10-04 16:57:36 -0700 | [diff] [blame] | 883 | art::Locks::thread_list_lock_->ExclusiveUnlock(self); |
Alex Light | 7ddc23d | 2017-09-22 15:33:41 -0700 | [diff] [blame] | 884 | return err; |
Alex Light | bebd7bd | 2017-07-25 14:05:52 -0700 | [diff] [blame] | 885 | } |
| 886 | SetLocalVariableClosure c(self, depth, slot, type, val); |
Alex Light | b1e31a8 | 2017-10-04 16:57:36 -0700 | [diff] [blame] | 887 | // RequestSynchronousCheckpoint releases the thread_list_lock_ as a part of its execution. |
Alex Light | 318afe6 | 2018-03-22 16:50:10 -0700 | [diff] [blame] | 888 | if (!target->RequestSynchronousCheckpoint(&c)) { |
Alex Light | bebd7bd | 2017-07-25 14:05:52 -0700 | [diff] [blame] | 889 | return ERR(THREAD_NOT_ALIVE); |
| 890 | } else { |
| 891 | return c.GetResult(); |
| 892 | } |
| 893 | } |
| 894 | |
| 895 | class GetLocalInstanceClosure : public art::Closure { |
| 896 | public: |
Alex Light | 318afe6 | 2018-03-22 16:50:10 -0700 | [diff] [blame] | 897 | explicit GetLocalInstanceClosure(jint depth) |
Alex Light | bebd7bd | 2017-07-25 14:05:52 -0700 | [diff] [blame] | 898 | : result_(ERR(INTERNAL)), |
Alex Light | bebd7bd | 2017-07-25 14:05:52 -0700 | [diff] [blame] | 899 | depth_(depth), |
Alex Light | 318afe6 | 2018-03-22 16:50:10 -0700 | [diff] [blame] | 900 | val_(nullptr) {} |
Alex Light | bebd7bd | 2017-07-25 14:05:52 -0700 | [diff] [blame] | 901 | |
Roland Levillain | bbc6e7e | 2018-08-24 16:58:47 +0100 | [diff] [blame] | 902 | void Run(art::Thread* self) override REQUIRES(art::Locks::mutator_lock_) { |
Alex Light | 318afe6 | 2018-03-22 16:50:10 -0700 | [diff] [blame] | 903 | art::ScopedAssertNoThreadSuspension sants("GetLocalInstanceClosure::Run"); |
Alex Light | bebd7bd | 2017-07-25 14:05:52 -0700 | [diff] [blame] | 904 | art::Locks::mutator_lock_->AssertSharedHeld(art::Thread::Current()); |
| 905 | std::unique_ptr<art::Context> context(art::Context::Create()); |
| 906 | FindFrameAtDepthVisitor visitor(self, context.get(), depth_); |
| 907 | visitor.WalkStack(); |
| 908 | if (!visitor.FoundFrame()) { |
| 909 | // Must have been a bad depth. |
| 910 | result_ = ERR(NO_MORE_FRAMES); |
| 911 | return; |
| 912 | } |
Alex Light | bebd7bd | 2017-07-25 14:05:52 -0700 | [diff] [blame] | 913 | result_ = OK; |
Alex Light | 318afe6 | 2018-03-22 16:50:10 -0700 | [diff] [blame] | 914 | val_ = art::GcRoot<art::mirror::Object>(visitor.GetThisObject()); |
Alex Light | bebd7bd | 2017-07-25 14:05:52 -0700 | [diff] [blame] | 915 | } |
| 916 | |
Alex Light | 318afe6 | 2018-03-22 16:50:10 -0700 | [diff] [blame] | 917 | jvmtiError GetResult(jobject* data_out) REQUIRES_SHARED(art::Locks::mutator_lock_) { |
| 918 | if (result_ == OK) { |
| 919 | *data_out = val_.IsNull() |
| 920 | ? nullptr |
| 921 | : art::Thread::Current()->GetJniEnv()->AddLocalReference<jobject>(val_.Read()); |
| 922 | } |
Alex Light | bebd7bd | 2017-07-25 14:05:52 -0700 | [diff] [blame] | 923 | return result_; |
| 924 | } |
| 925 | |
| 926 | private: |
| 927 | jvmtiError result_; |
Alex Light | bebd7bd | 2017-07-25 14:05:52 -0700 | [diff] [blame] | 928 | jint depth_; |
Alex Light | 318afe6 | 2018-03-22 16:50:10 -0700 | [diff] [blame] | 929 | art::GcRoot<art::mirror::Object> val_; |
Alex Light | bebd7bd | 2017-07-25 14:05:52 -0700 | [diff] [blame] | 930 | }; |
| 931 | |
| 932 | jvmtiError MethodUtil::GetLocalInstance(jvmtiEnv* env ATTRIBUTE_UNUSED, |
| 933 | jthread thread, |
| 934 | jint depth, |
| 935 | jobject* data) { |
| 936 | if (depth < 0) { |
| 937 | return ERR(ILLEGAL_ARGUMENT); |
| 938 | } |
| 939 | art::Thread* self = art::Thread::Current(); |
| 940 | art::ScopedObjectAccess soa(self); |
Alex Light | b1e31a8 | 2017-10-04 16:57:36 -0700 | [diff] [blame] | 941 | art::Locks::thread_list_lock_->ExclusiveLock(self); |
Alex Light | 7ddc23d | 2017-09-22 15:33:41 -0700 | [diff] [blame] | 942 | art::Thread* target = nullptr; |
| 943 | jvmtiError err = ERR(INTERNAL); |
| 944 | if (!ThreadUtil::GetAliveNativeThread(thread, soa, &target, &err)) { |
Alex Light | b1e31a8 | 2017-10-04 16:57:36 -0700 | [diff] [blame] | 945 | art::Locks::thread_list_lock_->ExclusiveUnlock(self); |
Alex Light | 7ddc23d | 2017-09-22 15:33:41 -0700 | [diff] [blame] | 946 | return err; |
Alex Light | bebd7bd | 2017-07-25 14:05:52 -0700 | [diff] [blame] | 947 | } |
Alex Light | 318afe6 | 2018-03-22 16:50:10 -0700 | [diff] [blame] | 948 | art::ScopedAssertNoThreadSuspension sants("Performing GetLocalInstance"); |
| 949 | GetLocalInstanceClosure c(depth); |
| 950 | // RequestSynchronousCheckpoint releases the thread_list_lock_ as a part of its execution. We |
| 951 | // need to avoid suspending as we wait for the checkpoint to occur since we are (potentially) |
| 952 | // transfering a GcRoot across threads. |
| 953 | if (!target->RequestSynchronousCheckpoint(&c, art::ThreadState::kRunnable)) { |
Alex Light | bebd7bd | 2017-07-25 14:05:52 -0700 | [diff] [blame] | 954 | return ERR(THREAD_NOT_ALIVE); |
| 955 | } else { |
Alex Light | 318afe6 | 2018-03-22 16:50:10 -0700 | [diff] [blame] | 956 | return c.GetResult(data); |
Alex Light | bebd7bd | 2017-07-25 14:05:52 -0700 | [diff] [blame] | 957 | } |
| 958 | } |
| 959 | |
| 960 | #define FOR_JVMTI_JVALUE_TYPES(fn) \ |
| 961 | fn(jint, art::Primitive::kPrimInt, i) \ |
| 962 | fn(jlong, art::Primitive::kPrimLong, j) \ |
| 963 | fn(jfloat, art::Primitive::kPrimFloat, f) \ |
| 964 | fn(jdouble, art::Primitive::kPrimDouble, d) \ |
| 965 | fn(jobject, art::Primitive::kPrimNot, l) |
| 966 | |
| 967 | namespace impl { |
| 968 | |
| 969 | template<typename T> void WriteJvalue(T, jvalue*); |
| 970 | template<typename T> void ReadJvalue(jvalue, T*); |
| 971 | template<typename T> art::Primitive::Type GetJNIType(); |
| 972 | |
| 973 | #define JNI_TYPE_CHAR(type, prim, id) \ |
| 974 | template<> art::Primitive::Type GetJNIType<type>() { \ |
| 975 | return prim; \ |
| 976 | } |
| 977 | |
| 978 | FOR_JVMTI_JVALUE_TYPES(JNI_TYPE_CHAR); |
| 979 | |
| 980 | #undef JNI_TYPE_CHAR |
| 981 | |
Andreas Gampe | 49fc60e | 2017-08-24 13:19:59 -0700 | [diff] [blame] | 982 | #define RW_JVALUE(srctype, prim, id) \ |
| 983 | template<> void ReadJvalue<srctype>(jvalue in, std::add_pointer<srctype>::type out) { \ |
Alex Light | bebd7bd | 2017-07-25 14:05:52 -0700 | [diff] [blame] | 984 | *out = in.id; \ |
| 985 | } \ |
Andreas Gampe | 49fc60e | 2017-08-24 13:19:59 -0700 | [diff] [blame] | 986 | template<> void WriteJvalue<srctype>(srctype in, jvalue* out) { \ |
Alex Light | bebd7bd | 2017-07-25 14:05:52 -0700 | [diff] [blame] | 987 | out->id = in; \ |
| 988 | } |
| 989 | |
| 990 | FOR_JVMTI_JVALUE_TYPES(RW_JVALUE); |
| 991 | |
| 992 | #undef RW_JVALUE |
| 993 | |
| 994 | } // namespace impl |
| 995 | |
| 996 | template<typename T> |
| 997 | jvmtiError MethodUtil::SetLocalVariable(jvmtiEnv* env, |
| 998 | jthread thread, |
| 999 | jint depth, |
| 1000 | jint slot, |
| 1001 | T data) { |
| 1002 | jvalue v = {.j = 0}; |
| 1003 | art::Primitive::Type type = impl::GetJNIType<T>(); |
| 1004 | impl::WriteJvalue(data, &v); |
| 1005 | return SetLocalVariableGeneric(env, thread, depth, slot, type, v); |
| 1006 | } |
| 1007 | |
| 1008 | template<typename T> |
| 1009 | jvmtiError MethodUtil::GetLocalVariable(jvmtiEnv* env, |
| 1010 | jthread thread, |
| 1011 | jint depth, |
| 1012 | jint slot, |
| 1013 | T* data) { |
| 1014 | if (data == nullptr) { |
| 1015 | return ERR(NULL_POINTER); |
| 1016 | } |
| 1017 | jvalue v = {.j = 0}; |
| 1018 | art::Primitive::Type type = impl::GetJNIType<T>(); |
| 1019 | jvmtiError err = GetLocalVariableGeneric(env, thread, depth, slot, type, &v); |
| 1020 | if (err != OK) { |
| 1021 | return err; |
| 1022 | } else { |
| 1023 | impl::ReadJvalue(v, data); |
| 1024 | return OK; |
| 1025 | } |
| 1026 | } |
| 1027 | |
Andreas Gampe | 49fc60e | 2017-08-24 13:19:59 -0700 | [diff] [blame] | 1028 | #define GET_SET_LV(srctype, prim, id) \ |
| 1029 | template jvmtiError MethodUtil::GetLocalVariable<srctype>(jvmtiEnv*, \ |
| 1030 | jthread, \ |
| 1031 | jint, \ |
| 1032 | jint, \ |
| 1033 | std::add_pointer<srctype>::type); \ |
| 1034 | template jvmtiError MethodUtil::SetLocalVariable<srctype>(jvmtiEnv*, \ |
| 1035 | jthread, \ |
| 1036 | jint, \ |
| 1037 | jint, \ |
| 1038 | srctype); |
Alex Light | bebd7bd | 2017-07-25 14:05:52 -0700 | [diff] [blame] | 1039 | |
| 1040 | FOR_JVMTI_JVALUE_TYPES(GET_SET_LV); |
| 1041 | |
| 1042 | #undef GET_SET_LV |
| 1043 | |
| 1044 | #undef FOR_JVMTI_JVALUE_TYPES |
| 1045 | |
Andreas Gampe | 3c252f0 | 2016-10-27 18:25:17 -0700 | [diff] [blame] | 1046 | } // namespace openjdkjvmti |