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 | |
| 34 | #include "art_jvmti.h" |
| 35 | #include "art_method-inl.h" |
| 36 | #include "base/enums.h" |
Andreas Gampe | 27dfa05 | 2017-02-16 15:04:36 -0800 | [diff] [blame] | 37 | #include "dex_file_annotations.h" |
Alex Light | d78ddec | 2017-04-18 15:20:38 -0700 | [diff] [blame] | 38 | #include "events-inl.h" |
Andreas Gampe | 13b2784 | 2016-11-07 16:48:23 -0800 | [diff] [blame] | 39 | #include "jni_internal.h" |
Andreas Gampe | 27dfa05 | 2017-02-16 15:04:36 -0800 | [diff] [blame] | 40 | #include "mirror/object_array-inl.h" |
Andreas Gampe | 36bcd4f | 2016-10-28 18:07:18 -0700 | [diff] [blame] | 41 | #include "modifiers.h" |
Alex Light | d78ddec | 2017-04-18 15:20:38 -0700 | [diff] [blame] | 42 | #include "runtime_callbacks.h" |
Andreas Gampe | 3c252f0 | 2016-10-27 18:25:17 -0700 | [diff] [blame] | 43 | #include "scoped_thread_state_change-inl.h" |
Alex Light | d78ddec | 2017-04-18 15:20:38 -0700 | [diff] [blame] | 44 | #include "ScopedLocalRef.h" |
Andreas Gampe | b486a98 | 2017-06-01 13:45:54 -0700 | [diff] [blame] | 45 | #include "thread-current-inl.h" |
Alex Light | d78ddec | 2017-04-18 15:20:38 -0700 | [diff] [blame] | 46 | #include "thread_list.h" |
Alex Light | 0af8cde | 2017-04-20 13:35:05 -0700 | [diff] [blame] | 47 | #include "ti_phase.h" |
Andreas Gampe | 3c252f0 | 2016-10-27 18:25:17 -0700 | [diff] [blame] | 48 | |
| 49 | namespace openjdkjvmti { |
| 50 | |
Alex Light | d78ddec | 2017-04-18 15:20:38 -0700 | [diff] [blame] | 51 | struct TiMethodCallback : public art::MethodCallback { |
| 52 | void RegisterNativeMethod(art::ArtMethod* method, |
| 53 | const void* cur_method, |
| 54 | /*out*/void** new_method) |
| 55 | OVERRIDE REQUIRES_SHARED(art::Locks::mutator_lock_) { |
| 56 | if (event_handler->IsEventEnabledAnywhere(ArtJvmtiEvent::kNativeMethodBind)) { |
| 57 | art::Thread* thread = art::Thread::Current(); |
Alex Light | 0af8cde | 2017-04-20 13:35:05 -0700 | [diff] [blame] | 58 | art::JNIEnvExt* jnienv = thread->GetJniEnv(); |
Alex Light | d78ddec | 2017-04-18 15:20:38 -0700 | [diff] [blame] | 59 | ScopedLocalRef<jthread> thread_jni( |
Alex Light | 0af8cde | 2017-04-20 13:35:05 -0700 | [diff] [blame] | 60 | jnienv, PhaseUtil::IsLivePhase() ? jnienv->AddLocalReference<jthread>(thread->GetPeer()) |
| 61 | : nullptr); |
Alex Light | d78ddec | 2017-04-18 15:20:38 -0700 | [diff] [blame] | 62 | art::ScopedThreadSuspension sts(thread, art::ThreadState::kNative); |
| 63 | event_handler->DispatchEvent<ArtJvmtiEvent::kNativeMethodBind>( |
| 64 | thread, |
Alex Light | 0af8cde | 2017-04-20 13:35:05 -0700 | [diff] [blame] | 65 | static_cast<JNIEnv*>(jnienv), |
Alex Light | d78ddec | 2017-04-18 15:20:38 -0700 | [diff] [blame] | 66 | thread_jni.get(), |
| 67 | art::jni::EncodeArtMethod(method), |
| 68 | const_cast<void*>(cur_method), |
| 69 | new_method); |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | EventHandler* event_handler = nullptr; |
| 74 | }; |
| 75 | |
| 76 | TiMethodCallback gMethodCallback; |
| 77 | |
| 78 | void MethodUtil::Register(EventHandler* handler) { |
| 79 | gMethodCallback.event_handler = handler; |
| 80 | art::ScopedThreadStateChange stsc(art::Thread::Current(), |
| 81 | art::ThreadState::kWaitingForDebuggerToAttach); |
| 82 | art::ScopedSuspendAll ssa("Add method callback"); |
| 83 | art::Runtime::Current()->GetRuntimeCallbacks()->AddMethodCallback(&gMethodCallback); |
| 84 | } |
| 85 | |
| 86 | void MethodUtil::Unregister() { |
| 87 | art::ScopedThreadStateChange stsc(art::Thread::Current(), |
| 88 | art::ThreadState::kWaitingForDebuggerToAttach); |
| 89 | art::ScopedSuspendAll ssa("Remove method callback"); |
| 90 | art::Runtime* runtime = art::Runtime::Current(); |
| 91 | runtime->GetRuntimeCallbacks()->RemoveMethodCallback(&gMethodCallback); |
| 92 | } |
| 93 | |
Alex Light | 4c17428 | 2017-07-05 10:18:18 -0700 | [diff] [blame^] | 94 | jvmtiError MethodUtil::GetBytecodes(jvmtiEnv* env, |
| 95 | jmethodID method, |
| 96 | jint* size_ptr, |
| 97 | unsigned char** bytecode_ptr) { |
| 98 | if (method == nullptr) { |
| 99 | return ERR(INVALID_METHODID); |
| 100 | } |
| 101 | art::ArtMethod* art_method = art::jni::DecodeArtMethod(method); |
| 102 | |
| 103 | if (art_method->IsNative()) { |
| 104 | return ERR(NATIVE_METHOD); |
| 105 | } |
| 106 | |
| 107 | if (size_ptr == nullptr || bytecode_ptr == nullptr) { |
| 108 | return ERR(NULL_POINTER); |
| 109 | } |
| 110 | |
| 111 | art::ScopedObjectAccess soa(art::Thread::Current()); |
| 112 | const art::DexFile::CodeItem* code_item = art_method->GetCodeItem(); |
| 113 | if (code_item == nullptr) { |
| 114 | *size_ptr = 0; |
| 115 | *bytecode_ptr = nullptr; |
| 116 | return OK; |
| 117 | } |
| 118 | // 2 bytes per instruction for dex code. |
| 119 | *size_ptr = code_item->insns_size_in_code_units_ * 2; |
| 120 | jvmtiError err = env->Allocate(*size_ptr, bytecode_ptr); |
| 121 | if (err != OK) { |
| 122 | return err; |
| 123 | } |
| 124 | memcpy(*bytecode_ptr, code_item->insns_, *size_ptr); |
| 125 | return OK; |
| 126 | } |
| 127 | |
Andreas Gampe | f71832e | 2017-01-09 11:38:04 -0800 | [diff] [blame] | 128 | jvmtiError MethodUtil::GetArgumentsSize(jvmtiEnv* env ATTRIBUTE_UNUSED, |
| 129 | jmethodID method, |
| 130 | jint* size_ptr) { |
| 131 | if (method == nullptr) { |
| 132 | return ERR(INVALID_METHODID); |
| 133 | } |
| 134 | art::ArtMethod* art_method = art::jni::DecodeArtMethod(method); |
| 135 | |
| 136 | if (art_method->IsNative()) { |
| 137 | return ERR(NATIVE_METHOD); |
| 138 | } |
| 139 | |
| 140 | if (size_ptr == nullptr) { |
| 141 | return ERR(NULL_POINTER); |
| 142 | } |
| 143 | |
| 144 | art::ScopedObjectAccess soa(art::Thread::Current()); |
| 145 | if (art_method->IsProxyMethod() || art_method->IsAbstract()) { |
Andreas Gampe | e1f79b6 | 2017-04-12 21:11:28 -0700 | [diff] [blame] | 146 | // Use the shorty. |
| 147 | art::ArtMethod* base_method = art_method->GetInterfaceMethodIfProxy(art::kRuntimePointerSize); |
| 148 | size_t arg_count = art::ArtMethod::NumArgRegisters(base_method->GetShorty()); |
| 149 | if (!base_method->IsStatic()) { |
| 150 | arg_count++; |
| 151 | } |
| 152 | *size_ptr = static_cast<jint>(arg_count); |
Andreas Gampe | f71832e | 2017-01-09 11:38:04 -0800 | [diff] [blame] | 153 | return ERR(NONE); |
| 154 | } |
| 155 | |
| 156 | DCHECK_NE(art_method->GetCodeItemOffset(), 0u); |
| 157 | *size_ptr = art_method->GetCodeItem()->ins_size_; |
| 158 | |
| 159 | return ERR(NONE); |
| 160 | } |
| 161 | |
| 162 | jvmtiError MethodUtil::GetMaxLocals(jvmtiEnv* env ATTRIBUTE_UNUSED, |
| 163 | jmethodID method, |
| 164 | jint* max_ptr) { |
| 165 | if (method == nullptr) { |
| 166 | return ERR(INVALID_METHODID); |
| 167 | } |
| 168 | art::ArtMethod* art_method = art::jni::DecodeArtMethod(method); |
| 169 | |
| 170 | if (art_method->IsNative()) { |
| 171 | return ERR(NATIVE_METHOD); |
| 172 | } |
| 173 | |
| 174 | if (max_ptr == nullptr) { |
| 175 | return ERR(NULL_POINTER); |
| 176 | } |
| 177 | |
| 178 | art::ScopedObjectAccess soa(art::Thread::Current()); |
| 179 | if (art_method->IsProxyMethod() || art_method->IsAbstract()) { |
| 180 | // This isn't specified as an error case, so return 0. |
| 181 | *max_ptr = 0; |
| 182 | return ERR(NONE); |
| 183 | } |
| 184 | |
| 185 | DCHECK_NE(art_method->GetCodeItemOffset(), 0u); |
| 186 | *max_ptr = art_method->GetCodeItem()->registers_size_; |
| 187 | |
| 188 | return ERR(NONE); |
| 189 | } |
| 190 | |
Andreas Gampe | 3c252f0 | 2016-10-27 18:25:17 -0700 | [diff] [blame] | 191 | jvmtiError MethodUtil::GetMethodName(jvmtiEnv* env, |
| 192 | jmethodID method, |
| 193 | char** name_ptr, |
| 194 | char** signature_ptr, |
| 195 | char** generic_ptr) { |
| 196 | art::ScopedObjectAccess soa(art::Thread::Current()); |
Andreas Gampe | 13b2784 | 2016-11-07 16:48:23 -0800 | [diff] [blame] | 197 | art::ArtMethod* art_method = art::jni::DecodeArtMethod(method); |
Andreas Gampe | 3c252f0 | 2016-10-27 18:25:17 -0700 | [diff] [blame] | 198 | art_method = art_method->GetInterfaceMethodIfProxy(art::kRuntimePointerSize); |
| 199 | |
Andreas Gampe | 5471141 | 2017-02-21 12:41:43 -0800 | [diff] [blame] | 200 | JvmtiUniquePtr<char[]> name_copy; |
Andreas Gampe | 3c252f0 | 2016-10-27 18:25:17 -0700 | [diff] [blame] | 201 | if (name_ptr != nullptr) { |
| 202 | const char* method_name = art_method->GetName(); |
| 203 | if (method_name == nullptr) { |
| 204 | method_name = "<error>"; |
| 205 | } |
Andreas Gampe | 5471141 | 2017-02-21 12:41:43 -0800 | [diff] [blame] | 206 | jvmtiError ret; |
| 207 | name_copy = CopyString(env, method_name, &ret); |
| 208 | if (name_copy == nullptr) { |
Andreas Gampe | 3c252f0 | 2016-10-27 18:25:17 -0700 | [diff] [blame] | 209 | return ret; |
| 210 | } |
Andreas Gampe | 5471141 | 2017-02-21 12:41:43 -0800 | [diff] [blame] | 211 | *name_ptr = name_copy.get(); |
Andreas Gampe | 3c252f0 | 2016-10-27 18:25:17 -0700 | [diff] [blame] | 212 | } |
| 213 | |
Andreas Gampe | 5471141 | 2017-02-21 12:41:43 -0800 | [diff] [blame] | 214 | JvmtiUniquePtr<char[]> signature_copy; |
Andreas Gampe | 3c252f0 | 2016-10-27 18:25:17 -0700 | [diff] [blame] | 215 | if (signature_ptr != nullptr) { |
| 216 | const art::Signature sig = art_method->GetSignature(); |
| 217 | std::string str = sig.ToString(); |
Andreas Gampe | 5471141 | 2017-02-21 12:41:43 -0800 | [diff] [blame] | 218 | jvmtiError ret; |
| 219 | signature_copy = CopyString(env, str.c_str(), &ret); |
| 220 | if (signature_copy == nullptr) { |
Andreas Gampe | 3c252f0 | 2016-10-27 18:25:17 -0700 | [diff] [blame] | 221 | return ret; |
| 222 | } |
Andreas Gampe | 5471141 | 2017-02-21 12:41:43 -0800 | [diff] [blame] | 223 | *signature_ptr = signature_copy.get(); |
Andreas Gampe | 3c252f0 | 2016-10-27 18:25:17 -0700 | [diff] [blame] | 224 | } |
| 225 | |
Andreas Gampe | 862bdd8 | 2016-11-18 13:31:13 -0800 | [diff] [blame] | 226 | if (generic_ptr != nullptr) { |
| 227 | *generic_ptr = nullptr; |
Andreas Gampe | 27dfa05 | 2017-02-16 15:04:36 -0800 | [diff] [blame] | 228 | if (!art_method->GetDeclaringClass()->IsProxyClass()) { |
| 229 | art::mirror::ObjectArray<art::mirror::String>* str_array = |
| 230 | art::annotations::GetSignatureAnnotationForMethod(art_method); |
| 231 | if (str_array != nullptr) { |
| 232 | std::ostringstream oss; |
| 233 | for (int32_t i = 0; i != str_array->GetLength(); ++i) { |
| 234 | oss << str_array->Get(i)->ToModifiedUtf8(); |
| 235 | } |
| 236 | std::string output_string = oss.str(); |
Andreas Gampe | 5471141 | 2017-02-21 12:41:43 -0800 | [diff] [blame] | 237 | jvmtiError ret; |
| 238 | JvmtiUniquePtr<char[]> generic_copy = CopyString(env, output_string.c_str(), &ret); |
| 239 | if (generic_copy == nullptr) { |
Andreas Gampe | 27dfa05 | 2017-02-16 15:04:36 -0800 | [diff] [blame] | 240 | return ret; |
| 241 | } |
Andreas Gampe | 5471141 | 2017-02-21 12:41:43 -0800 | [diff] [blame] | 242 | *generic_ptr = generic_copy.release(); |
Andreas Gampe | 27dfa05 | 2017-02-16 15:04:36 -0800 | [diff] [blame] | 243 | } else if (soa.Self()->IsExceptionPending()) { |
| 244 | // TODO: Should we report an error here? |
| 245 | soa.Self()->ClearException(); |
| 246 | } |
| 247 | } |
Andreas Gampe | 862bdd8 | 2016-11-18 13:31:13 -0800 | [diff] [blame] | 248 | } |
Andreas Gampe | 3c252f0 | 2016-10-27 18:25:17 -0700 | [diff] [blame] | 249 | |
| 250 | // Everything is fine, release the buffers. |
| 251 | name_copy.release(); |
| 252 | signature_copy.release(); |
| 253 | |
| 254 | return ERR(NONE); |
| 255 | } |
| 256 | |
Andreas Gampe | 368a208 | 2016-10-28 17:33:13 -0700 | [diff] [blame] | 257 | jvmtiError MethodUtil::GetMethodDeclaringClass(jvmtiEnv* env ATTRIBUTE_UNUSED, |
| 258 | jmethodID method, |
| 259 | jclass* declaring_class_ptr) { |
| 260 | if (declaring_class_ptr == nullptr) { |
| 261 | return ERR(NULL_POINTER); |
| 262 | } |
| 263 | |
Andreas Gampe | 13b2784 | 2016-11-07 16:48:23 -0800 | [diff] [blame] | 264 | art::ArtMethod* art_method = art::jni::DecodeArtMethod(method); |
Andreas Gampe | 368a208 | 2016-10-28 17:33:13 -0700 | [diff] [blame] | 265 | // Note: No GetInterfaceMethodIfProxy, we want to actual class. |
| 266 | |
Andreas Gampe | 13b2784 | 2016-11-07 16:48:23 -0800 | [diff] [blame] | 267 | art::ScopedObjectAccess soa(art::Thread::Current()); |
Andreas Gampe | 368a208 | 2016-10-28 17:33:13 -0700 | [diff] [blame] | 268 | art::mirror::Class* klass = art_method->GetDeclaringClass(); |
| 269 | *declaring_class_ptr = soa.AddLocalReference<jclass>(klass); |
| 270 | |
| 271 | return ERR(NONE); |
| 272 | } |
| 273 | |
Andreas Gampe | f71832e | 2017-01-09 11:38:04 -0800 | [diff] [blame] | 274 | jvmtiError MethodUtil::GetMethodLocation(jvmtiEnv* env ATTRIBUTE_UNUSED, |
| 275 | jmethodID method, |
| 276 | jlocation* start_location_ptr, |
| 277 | jlocation* end_location_ptr) { |
| 278 | if (method == nullptr) { |
| 279 | return ERR(INVALID_METHODID); |
| 280 | } |
| 281 | art::ArtMethod* art_method = art::jni::DecodeArtMethod(method); |
| 282 | |
| 283 | if (art_method->IsNative()) { |
| 284 | return ERR(NATIVE_METHOD); |
| 285 | } |
| 286 | |
| 287 | if (start_location_ptr == nullptr || end_location_ptr == nullptr) { |
| 288 | return ERR(NULL_POINTER); |
| 289 | } |
| 290 | |
| 291 | art::ScopedObjectAccess soa(art::Thread::Current()); |
| 292 | if (art_method->IsProxyMethod() || art_method->IsAbstract()) { |
Andreas Gampe | e1f79b6 | 2017-04-12 21:11:28 -0700 | [diff] [blame] | 293 | // This isn't specified as an error case, so return -1/-1 as the RI does. |
| 294 | *start_location_ptr = -1; |
| 295 | *end_location_ptr = -1; |
Andreas Gampe | f71832e | 2017-01-09 11:38:04 -0800 | [diff] [blame] | 296 | return ERR(NONE); |
| 297 | } |
| 298 | |
| 299 | DCHECK_NE(art_method->GetCodeItemOffset(), 0u); |
| 300 | *start_location_ptr = 0; |
| 301 | *end_location_ptr = art_method->GetCodeItem()->insns_size_in_code_units_ - 1; |
| 302 | |
| 303 | return ERR(NONE); |
| 304 | } |
| 305 | |
Andreas Gampe | 36bcd4f | 2016-10-28 18:07:18 -0700 | [diff] [blame] | 306 | jvmtiError MethodUtil::GetMethodModifiers(jvmtiEnv* env ATTRIBUTE_UNUSED, |
| 307 | jmethodID method, |
| 308 | jint* modifiers_ptr) { |
| 309 | if (modifiers_ptr == nullptr) { |
| 310 | return ERR(NULL_POINTER); |
| 311 | } |
| 312 | |
Andreas Gampe | 13b2784 | 2016-11-07 16:48:23 -0800 | [diff] [blame] | 313 | art::ArtMethod* art_method = art::jni::DecodeArtMethod(method); |
Andreas Gampe | 36bcd4f | 2016-10-28 18:07:18 -0700 | [diff] [blame] | 314 | uint32_t modifiers = art_method->GetAccessFlags(); |
| 315 | |
| 316 | // Note: Keep this code in sync with Executable.fixMethodFlags. |
| 317 | if ((modifiers & art::kAccAbstract) != 0) { |
| 318 | modifiers &= ~art::kAccNative; |
| 319 | } |
| 320 | modifiers &= ~art::kAccSynchronized; |
| 321 | if ((modifiers & art::kAccDeclaredSynchronized) != 0) { |
| 322 | modifiers |= art::kAccSynchronized; |
| 323 | } |
| 324 | modifiers &= art::kAccJavaFlagsMask; |
| 325 | |
| 326 | *modifiers_ptr = modifiers; |
| 327 | return ERR(NONE); |
| 328 | } |
| 329 | |
Andreas Gampe | da3e561 | 2016-12-13 19:00:53 -0800 | [diff] [blame] | 330 | using LineNumberContext = std::vector<jvmtiLineNumberEntry>; |
| 331 | |
| 332 | static bool CollectLineNumbers(void* void_context, const art::DexFile::PositionInfo& entry) { |
| 333 | LineNumberContext* context = reinterpret_cast<LineNumberContext*>(void_context); |
| 334 | jvmtiLineNumberEntry jvmti_entry = { static_cast<jlocation>(entry.address_), |
| 335 | static_cast<jint>(entry.line_) }; |
| 336 | context->push_back(jvmti_entry); |
| 337 | return false; // Collect all, no early exit. |
| 338 | } |
| 339 | |
| 340 | jvmtiError MethodUtil::GetLineNumberTable(jvmtiEnv* env, |
| 341 | jmethodID method, |
| 342 | jint* entry_count_ptr, |
| 343 | jvmtiLineNumberEntry** table_ptr) { |
| 344 | if (method == nullptr) { |
| 345 | return ERR(NULL_POINTER); |
| 346 | } |
| 347 | art::ArtMethod* art_method = art::jni::DecodeArtMethod(method); |
| 348 | DCHECK(!art_method->IsRuntimeMethod()); |
| 349 | |
| 350 | const art::DexFile::CodeItem* code_item; |
| 351 | const art::DexFile* dex_file; |
| 352 | { |
| 353 | art::ScopedObjectAccess soa(art::Thread::Current()); |
| 354 | |
| 355 | if (art_method->IsProxyMethod()) { |
| 356 | return ERR(ABSENT_INFORMATION); |
| 357 | } |
| 358 | if (art_method->IsNative()) { |
| 359 | return ERR(NATIVE_METHOD); |
| 360 | } |
| 361 | if (entry_count_ptr == nullptr || table_ptr == nullptr) { |
| 362 | return ERR(NULL_POINTER); |
| 363 | } |
| 364 | |
| 365 | code_item = art_method->GetCodeItem(); |
| 366 | dex_file = art_method->GetDexFile(); |
| 367 | DCHECK(code_item != nullptr) << art_method->PrettyMethod() << " " << dex_file->GetLocation(); |
| 368 | } |
| 369 | |
| 370 | LineNumberContext context; |
| 371 | bool success = dex_file->DecodeDebugPositionInfo(code_item, CollectLineNumbers, &context); |
| 372 | if (!success) { |
| 373 | return ERR(ABSENT_INFORMATION); |
| 374 | } |
| 375 | |
| 376 | unsigned char* data; |
| 377 | jlong mem_size = context.size() * sizeof(jvmtiLineNumberEntry); |
| 378 | jvmtiError alloc_error = env->Allocate(mem_size, &data); |
| 379 | if (alloc_error != ERR(NONE)) { |
| 380 | return alloc_error; |
| 381 | } |
| 382 | *table_ptr = reinterpret_cast<jvmtiLineNumberEntry*>(data); |
| 383 | memcpy(*table_ptr, context.data(), mem_size); |
| 384 | *entry_count_ptr = static_cast<jint>(context.size()); |
| 385 | |
| 386 | return ERR(NONE); |
| 387 | } |
| 388 | |
Andreas Gampe | fdeef52 | 2017-01-09 14:40:25 -0800 | [diff] [blame] | 389 | template <typename T> |
| 390 | static jvmtiError IsMethodT(jvmtiEnv* env ATTRIBUTE_UNUSED, |
| 391 | jmethodID method, |
| 392 | T test, |
| 393 | jboolean* is_t_ptr) { |
| 394 | if (method == nullptr) { |
| 395 | return ERR(INVALID_METHODID); |
| 396 | } |
| 397 | if (is_t_ptr == nullptr) { |
| 398 | return ERR(NULL_POINTER); |
| 399 | } |
| 400 | |
| 401 | art::ArtMethod* art_method = art::jni::DecodeArtMethod(method); |
| 402 | *is_t_ptr = test(art_method) ? JNI_TRUE : JNI_FALSE; |
| 403 | |
| 404 | return ERR(NONE); |
| 405 | } |
| 406 | |
| 407 | jvmtiError MethodUtil::IsMethodNative(jvmtiEnv* env, jmethodID m, jboolean* is_native_ptr) { |
| 408 | auto test = [](art::ArtMethod* method) { |
| 409 | return method->IsNative(); |
| 410 | }; |
| 411 | return IsMethodT(env, m, test, is_native_ptr); |
| 412 | } |
| 413 | |
| 414 | jvmtiError MethodUtil::IsMethodObsolete(jvmtiEnv* env, jmethodID m, jboolean* is_obsolete_ptr) { |
| 415 | auto test = [](art::ArtMethod* method) { |
| 416 | return method->IsObsolete(); |
| 417 | }; |
| 418 | return IsMethodT(env, m, test, is_obsolete_ptr); |
| 419 | } |
| 420 | |
| 421 | jvmtiError MethodUtil::IsMethodSynthetic(jvmtiEnv* env, jmethodID m, jboolean* is_synthetic_ptr) { |
| 422 | auto test = [](art::ArtMethod* method) { |
| 423 | return method->IsSynthetic(); |
| 424 | }; |
| 425 | return IsMethodT(env, m, test, is_synthetic_ptr); |
| 426 | } |
| 427 | |
Andreas Gampe | 3c252f0 | 2016-10-27 18:25:17 -0700 | [diff] [blame] | 428 | } // namespace openjdkjvmti |