blob: f893e58f3924c356214804b49993a56045df8fd6 [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"
37#include "scoped_thread_state_change-inl.h"
38
39namespace openjdkjvmti {
40
Andreas Gampe3c252f02016-10-27 18:25:17 -070041jvmtiError MethodUtil::GetMethodName(jvmtiEnv* env,
42 jmethodID method,
43 char** name_ptr,
44 char** signature_ptr,
45 char** generic_ptr) {
46 art::ScopedObjectAccess soa(art::Thread::Current());
47 art::ArtMethod* art_method = soa.DecodeMethod(method);
48 art_method = art_method->GetInterfaceMethodIfProxy(art::kRuntimePointerSize);
49
50 JvmtiUniquePtr name_copy;
51 if (name_ptr != nullptr) {
52 const char* method_name = art_method->GetName();
53 if (method_name == nullptr) {
54 method_name = "<error>";
55 }
56 unsigned char* tmp;
57 jvmtiError ret = CopyString(env, method_name, &tmp);
58 if (ret != ERR(NONE)) {
59 return ret;
60 }
61 name_copy = MakeJvmtiUniquePtr(env, tmp);
62 *name_ptr = reinterpret_cast<char*>(tmp);
63 }
64
65 JvmtiUniquePtr signature_copy;
66 if (signature_ptr != nullptr) {
67 const art::Signature sig = art_method->GetSignature();
68 std::string str = sig.ToString();
69 unsigned char* tmp;
70 jvmtiError ret = CopyString(env, str.c_str(), &tmp);
71 if (ret != ERR(NONE)) {
72 return ret;
73 }
74 signature_copy = MakeJvmtiUniquePtr(env, tmp);
75 *signature_ptr = reinterpret_cast<char*>(tmp);
76 }
77
78 // TODO: Support generic signature.
79 *generic_ptr = nullptr;
80
81 // Everything is fine, release the buffers.
82 name_copy.release();
83 signature_copy.release();
84
85 return ERR(NONE);
86}
87
88} // namespace openjdkjvmti