From 0eb36438abb475aeffb8611cb99d1502e0df32fc Mon Sep 17 00:00:00 2001 From: Andreas Gampe Date: Wed, 15 Feb 2017 18:36:14 -0800 Subject: [PATCH] ART: Add support for generic class signature Add support for generic_ptr to GetClassSignature. Bug: 34615460 Test: m test-art-host-run-test-912-classes Change-Id: Ie123879ec90b116d25c522035f8806f05253a0ec --- runtime/openjdkjvmti/ti_class.cc | 25 ++++++++++++++++++++++++- test/912-classes/expected.txt | 4 ++-- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/runtime/openjdkjvmti/ti_class.cc b/runtime/openjdkjvmti/ti_class.cc index 7ca233fb1..a8a0ded7d 100644 --- a/runtime/openjdkjvmti/ti_class.cc +++ b/runtime/openjdkjvmti/ti_class.cc @@ -41,6 +41,7 @@ #include "class_table-inl.h" #include "class_linker.h" #include "common_throws.h" +#include "dex_file_annotations.h" #include "events-inl.h" #include "gc/heap.h" #include "gc_root.h" @@ -50,6 +51,7 @@ #include "mirror/array-inl.h" #include "mirror/class-inl.h" #include "mirror/class_ext.h" +#include "mirror/object_array-inl.h" #include "mirror/object_reference.h" #include "mirror/object-inl.h" #include "mirror/reference.h" @@ -685,9 +687,30 @@ jvmtiError ClassUtil::GetClassSignature(jvmtiEnv* env, *signature_ptr = reinterpret_cast(tmp); } - // TODO: Support generic signature. if (generic_ptr != nullptr) { *generic_ptr = nullptr; + if (!klass->IsProxyClass() && klass->GetDexCache() != nullptr) { + art::StackHandleScope<1> hs(soa.Self()); + art::Handle h_klass = hs.NewHandle(klass); + art::mirror::ObjectArray* str_array = + art::annotations::GetSignatureAnnotationForClass(h_klass); + if (str_array != nullptr) { + std::ostringstream oss; + for (int32_t i = 0; i != str_array->GetLength(); ++i) { + oss << str_array->Get(i)->ToModifiedUtf8(); + } + std::string output_string = oss.str(); + unsigned char* tmp; + jvmtiError ret = CopyString(env, output_string.c_str(), &tmp); + if (ret != ERR(NONE)) { + return ret; + } + *generic_ptr = reinterpret_cast(tmp); + } else if (soa.Self()->IsExceptionPending()) { + // TODO: Should we report an error here? + soa.Self()->ClearException(); + } + } } // Everything is fine, release the buffers. diff --git a/test/912-classes/expected.txt b/test/912-classes/expected.txt index 328216b32..e932b206c 100644 --- a/test/912-classes/expected.txt +++ b/test/912-classes/expected.txt @@ -1,10 +1,10 @@ [Ljava/lang/Object;, null] 1 -[Ljava/lang/String;, null] +[Ljava/lang/String;, Ljava/lang/Object;Ljava/io/Serializable;Ljava/lang/Comparable;Ljava/lang/CharSequence;] 11 [Ljava/lang/Math;, null] 11 -[Ljava/util/List;, null] +[Ljava/util/List;, Ljava/lang/Object;Ljava/util/Collection;] 601 [L$Proxy0;, null] 11 -- 2.11.0