blob: e391a9d680fd64afb931b31bfac5eb74b4760b5b [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.
81 *generic_ptr = nullptr;
82
83 // Everything is fine, release the buffers.
84 name_copy.release();
85 signature_copy.release();
86
87 return ERR(NONE);
88}
89
Andreas Gampe368a2082016-10-28 17:33:13 -070090jvmtiError MethodUtil::GetMethodDeclaringClass(jvmtiEnv* env ATTRIBUTE_UNUSED,
91 jmethodID method,
92 jclass* declaring_class_ptr) {
93 if (declaring_class_ptr == nullptr) {
94 return ERR(NULL_POINTER);
95 }
96
Andreas Gampe13b27842016-11-07 16:48:23 -080097 art::ArtMethod* art_method = art::jni::DecodeArtMethod(method);
Andreas Gampe368a2082016-10-28 17:33:13 -070098 // Note: No GetInterfaceMethodIfProxy, we want to actual class.
99
Andreas Gampe13b27842016-11-07 16:48:23 -0800100 art::ScopedObjectAccess soa(art::Thread::Current());
Andreas Gampe368a2082016-10-28 17:33:13 -0700101 art::mirror::Class* klass = art_method->GetDeclaringClass();
102 *declaring_class_ptr = soa.AddLocalReference<jclass>(klass);
103
104 return ERR(NONE);
105}
106
Andreas Gampe36bcd4f2016-10-28 18:07:18 -0700107jvmtiError MethodUtil::GetMethodModifiers(jvmtiEnv* env ATTRIBUTE_UNUSED,
108 jmethodID method,
109 jint* modifiers_ptr) {
110 if (modifiers_ptr == nullptr) {
111 return ERR(NULL_POINTER);
112 }
113
Andreas Gampe13b27842016-11-07 16:48:23 -0800114 art::ArtMethod* art_method = art::jni::DecodeArtMethod(method);
Andreas Gampe36bcd4f2016-10-28 18:07:18 -0700115 uint32_t modifiers = art_method->GetAccessFlags();
116
117 // Note: Keep this code in sync with Executable.fixMethodFlags.
118 if ((modifiers & art::kAccAbstract) != 0) {
119 modifiers &= ~art::kAccNative;
120 }
121 modifiers &= ~art::kAccSynchronized;
122 if ((modifiers & art::kAccDeclaredSynchronized) != 0) {
123 modifiers |= art::kAccSynchronized;
124 }
125 modifiers &= art::kAccJavaFlagsMask;
126
127 *modifiers_ptr = modifiers;
128 return ERR(NONE);
129}
130
Andreas Gampe3c252f02016-10-27 18:25:17 -0700131} // namespace openjdkjvmti