blob: ffa5ac7e32372d132316ac5ca864699fa4aab094 [file] [log] [blame]
Andreas Gampe3c252f02016-10-27 18:25:17 -07001/* 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 Gampe13b27842016-11-07 16:48:23 -080037#include "jni_internal.h"
Andreas Gampe36bcd4f2016-10-28 18:07:18 -070038#include "modifiers.h"
Andreas Gampe3c252f02016-10-27 18:25:17 -070039#include "scoped_thread_state_change-inl.h"
40
41namespace openjdkjvmti {
42
Andreas Gampe3c252f02016-10-27 18:25:17 -070043jvmtiError MethodUtil::GetMethodName(jvmtiEnv* env,
44 jmethodID method,
45 char** name_ptr,
46 char** signature_ptr,
47 char** generic_ptr) {
48 art::ScopedObjectAccess soa(art::Thread::Current());
Andreas Gampe13b27842016-11-07 16:48:23 -080049 art::ArtMethod* art_method = art::jni::DecodeArtMethod(method);
Andreas Gampe3c252f02016-10-27 18:25:17 -070050 art_method = art_method->GetInterfaceMethodIfProxy(art::kRuntimePointerSize);
51
52 JvmtiUniquePtr name_copy;
53 if (name_ptr != nullptr) {
54 const char* method_name = art_method->GetName();
55 if (method_name == nullptr) {
56 method_name = "<error>";
57 }
58 unsigned char* tmp;
59 jvmtiError ret = CopyString(env, method_name, &tmp);
60 if (ret != ERR(NONE)) {
61 return ret;
62 }
63 name_copy = MakeJvmtiUniquePtr(env, tmp);
64 *name_ptr = reinterpret_cast<char*>(tmp);
65 }
66
67 JvmtiUniquePtr signature_copy;
68 if (signature_ptr != nullptr) {
69 const art::Signature sig = art_method->GetSignature();
70 std::string str = sig.ToString();
71 unsigned char* tmp;
72 jvmtiError ret = CopyString(env, str.c_str(), &tmp);
73 if (ret != ERR(NONE)) {
74 return ret;
75 }
76 signature_copy = MakeJvmtiUniquePtr(env, tmp);
77 *signature_ptr = reinterpret_cast<char*>(tmp);
78 }
79
80 // TODO: Support generic signature.
Andreas Gampe862bdd82016-11-18 13:31:13 -080081 if (generic_ptr != nullptr) {
82 *generic_ptr = nullptr;
83 }
Andreas Gampe3c252f02016-10-27 18:25:17 -070084
85 // Everything is fine, release the buffers.
86 name_copy.release();
87 signature_copy.release();
88
89 return ERR(NONE);
90}
91
Andreas Gampe368a2082016-10-28 17:33:13 -070092jvmtiError MethodUtil::GetMethodDeclaringClass(jvmtiEnv* env ATTRIBUTE_UNUSED,
93 jmethodID method,
94 jclass* declaring_class_ptr) {
95 if (declaring_class_ptr == nullptr) {
96 return ERR(NULL_POINTER);
97 }
98
Andreas Gampe13b27842016-11-07 16:48:23 -080099 art::ArtMethod* art_method = art::jni::DecodeArtMethod(method);
Andreas Gampe368a2082016-10-28 17:33:13 -0700100 // Note: No GetInterfaceMethodIfProxy, we want to actual class.
101
Andreas Gampe13b27842016-11-07 16:48:23 -0800102 art::ScopedObjectAccess soa(art::Thread::Current());
Andreas Gampe368a2082016-10-28 17:33:13 -0700103 art::mirror::Class* klass = art_method->GetDeclaringClass();
104 *declaring_class_ptr = soa.AddLocalReference<jclass>(klass);
105
106 return ERR(NONE);
107}
108
Andreas Gampe36bcd4f2016-10-28 18:07:18 -0700109jvmtiError MethodUtil::GetMethodModifiers(jvmtiEnv* env ATTRIBUTE_UNUSED,
110 jmethodID method,
111 jint* modifiers_ptr) {
112 if (modifiers_ptr == nullptr) {
113 return ERR(NULL_POINTER);
114 }
115
Andreas Gampe13b27842016-11-07 16:48:23 -0800116 art::ArtMethod* art_method = art::jni::DecodeArtMethod(method);
Andreas Gampe36bcd4f2016-10-28 18:07:18 -0700117 uint32_t modifiers = art_method->GetAccessFlags();
118
119 // Note: Keep this code in sync with Executable.fixMethodFlags.
120 if ((modifiers & art::kAccAbstract) != 0) {
121 modifiers &= ~art::kAccNative;
122 }
123 modifiers &= ~art::kAccSynchronized;
124 if ((modifiers & art::kAccDeclaredSynchronized) != 0) {
125 modifiers |= art::kAccSynchronized;
126 }
127 modifiers &= art::kAccJavaFlagsMask;
128
129 *modifiers_ptr = modifiers;
130 return ERR(NONE);
131}
132
Andreas Gampe3c252f02016-10-27 18:25:17 -0700133} // namespace openjdkjvmti