OSDN Git Service

ART: Add support for generic field signature
authorAndreas Gampe <agampe@google.com>
Thu, 16 Feb 2017 18:34:05 +0000 (10:34 -0800)
committerAndreas Gampe <agampe@google.com>
Thu, 16 Feb 2017 18:34:05 +0000 (10:34 -0800)
Add support for generic_ptr to GetFieldName.

Bug: 34615460
Test: m test-art-host-run-test-918-fields
Change-Id: If754461e1dbbfd775746d0883d0cb7e613b494e4

runtime/openjdkjvmti/ti_field.cc
test/918-fields/expected.txt
test/918-fields/src/Main.java

index a762830..131e6c3 100644 (file)
@@ -34,7 +34,9 @@
 #include "art_jvmti.h"
 #include "art_field-inl.h"
 #include "base/enums.h"
+#include "dex_file_annotations.h"
 #include "jni_internal.h"
+#include "mirror/object_array-inl.h"
 #include "modifiers.h"
 #include "scoped_thread_state_change-inl.h"
 #include "thread-inl.h"
@@ -91,6 +93,26 @@ jvmtiError FieldUtil::GetFieldName(jvmtiEnv* env,
   // TODO: Support generic signature.
   if (generic_ptr != nullptr) {
     *generic_ptr = nullptr;
+    if (!art_field->GetDeclaringClass()->IsProxyClass()) {
+      art::mirror::ObjectArray<art::mirror::String>* str_array =
+          art::annotations::GetSignatureAnnotationForField(art_field);
+      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 39d3e70..1a1209c 100644 (file)
@@ -14,3 +14,7 @@ true
 interface Main$Bar
 25
 false
+[generics, Ljava/lang/Object;, TT;]
+class Main$Generics
+0
+false
index 3ba535b..ad0d0c5 100644 (file)
@@ -27,6 +27,7 @@ public class Main {
     testField(Integer.class, "value");
     testField(Foo.class, "this$0");
     testField(Bar.class, "VAL");
+    testField(Generics.class, "generics");
   }
 
   private static void testField(Class<?> base, String fieldName)
@@ -65,4 +66,8 @@ public class Main {
   private static interface Bar {
     public static int VAL = 1;
   }
+
+  private static class Generics<T> {
+    T generics;
+  }
 }