OSDN Git Service

ART: Add support for generic class signature
authorAndreas Gampe <agampe@google.com>
Thu, 16 Feb 2017 02:36:14 +0000 (18:36 -0800)
committerAndreas Gampe <agampe@google.com>
Thu, 16 Feb 2017 18:33:50 +0000 (10:33 -0800)
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
test/912-classes/expected.txt

index 7ca233f..a8a0ded 100644 (file)
@@ -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<char*>(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<art::mirror::Class> h_klass = hs.NewHandle(klass);
+      art::mirror::ObjectArray<art::mirror::String>* 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<char*>(tmp);
+      } else if (soa.Self()->IsExceptionPending()) {
+        // TODO: Should we report an error here?
+        soa.Self()->ClearException();
+      }
+    }
   }
 
   // Everything is fine, release the buffers.
index 328216b..e932b20 100644 (file)
@@ -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/String;>;Ljava/lang/CharSequence;]
 11
 [Ljava/lang/Math;, null]
 11
-[Ljava/util/List;, null]
+[Ljava/util/List;, <E:Ljava/lang/Object;>Ljava/lang/Object;Ljava/util/Collection<TE;>;]
 601
 [L$Proxy0;, null]
 11