diff options
| author | 2017-10-24 13:26:01 +0000 | |
|---|---|---|
| committer | 2017-10-24 13:26:01 +0000 | |
| commit | 2897ca8520df514bbb70b61f3bb69ed686f160f9 (patch) | |
| tree | 37738a6a7e8a73bd76dc93ec970678d73547665f | |
| parent | fa3fc51c254d726e9d5e1037726c9b2cf90965fc (diff) | |
| parent | 358347ae8fcf662def560367fe35a9ed9ee3b187 (diff) | |
Merge "Ensure GetSourceDebugExtension works with Proxy classes."
am: 358347ae8f
Change-Id: I0365076d92bfbfed0347a6b8d354c145409d94b6
| -rw-r--r-- | runtime/dex_file_annotations.cc | 15 | ||||
| -rw-r--r-- | test/992-source-data/expected.txt | 12 | ||||
| -rw-r--r-- | test/992-source-data/source_file.cc | 13 | ||||
| -rw-r--r-- | test/992-source-data/src/art/Test992.java | 21 |
4 files changed, 57 insertions, 4 deletions
diff --git a/runtime/dex_file_annotations.cc b/runtime/dex_file_annotations.cc index fe33bded2b..6075230f4a 100644 --- a/runtime/dex_file_annotations.cc +++ b/runtime/dex_file_annotations.cc @@ -134,8 +134,12 @@ const DexFile::AnnotationSetItem* FindAnnotationSetForField(ArtField* field) REQUIRES_SHARED(Locks::mutator_lock_) { const DexFile* dex_file = field->GetDexFile(); ObjPtr<mirror::Class> klass = field->GetDeclaringClass(); + const DexFile::ClassDef* class_def = klass->GetClassDef(); + if (class_def == nullptr) { + return nullptr; + } const DexFile::AnnotationsDirectoryItem* annotations_dir = - dex_file->GetAnnotationsDirectory(*klass->GetClassDef()); + dex_file->GetAnnotationsDirectory(*class_def); if (annotations_dir == nullptr) { return nullptr; } @@ -258,6 +262,9 @@ const uint8_t* SearchEncodedAnnotation(const DexFile& dex_file, const DexFile::AnnotationSetItem* FindAnnotationSetForMethod(ArtMethod* method) REQUIRES_SHARED(Locks::mutator_lock_) { + if (method->IsProxyMethod()) { + return nullptr; + } const DexFile* dex_file = method->GetDexFile(); const DexFile::AnnotationsDirectoryItem* annotations_dir = dex_file->GetAnnotationsDirectory(method->GetClassDef()); @@ -305,8 +312,12 @@ const DexFile::ParameterAnnotationsItem* FindAnnotationsItemForMethod(ArtMethod* const DexFile::AnnotationSetItem* FindAnnotationSetForClass(const ClassData& klass) REQUIRES_SHARED(Locks::mutator_lock_) { const DexFile& dex_file = klass.GetDexFile(); + const DexFile::ClassDef* class_def = klass.GetClassDef(); + if (class_def == nullptr) { + return nullptr; + } const DexFile::AnnotationsDirectoryItem* annotations_dir = - dex_file.GetAnnotationsDirectory(*klass.GetClassDef()); + dex_file.GetAnnotationsDirectory(*class_def); if (annotations_dir == nullptr) { return nullptr; } diff --git a/test/992-source-data/expected.txt b/test/992-source-data/expected.txt index 4db8df0ada..7f59682b1d 100644 --- a/test/992-source-data/expected.txt +++ b/test/992-source-data/expected.txt @@ -1,10 +1,22 @@ class art.Test992 is defined in file "Test992.java" +class art.Test992 does not have a known source file extension because java.lang.RuntimeException: JVMTI_ERROR_ABSENT_INFORMATION class art.Test992$Target1 is defined in file "Test992.java" +class art.Test992$Target1 does not have a known source file extension because java.lang.RuntimeException: JVMTI_ERROR_ABSENT_INFORMATION class art.Target2 is defined in file "Target2.java" +class art.Target2 does not have a known source file extension because java.lang.RuntimeException: JVMTI_ERROR_ABSENT_INFORMATION int does not have a known source file because java.lang.RuntimeException: JVMTI_ERROR_ABSENT_INFORMATION +int does not have a known source file extension because java.lang.RuntimeException: JVMTI_ERROR_ABSENT_INFORMATION class java.lang.Integer is defined in file "Integer.java" +class java.lang.Integer does not have a known source file extension because java.lang.RuntimeException: JVMTI_ERROR_ABSENT_INFORMATION class java.lang.Object is defined in file "Object.java" +class java.lang.Object does not have a known source file extension because java.lang.RuntimeException: JVMTI_ERROR_ABSENT_INFORMATION interface java.lang.Runnable is defined in file "Runnable.java" +interface java.lang.Runnable does not have a known source file extension because java.lang.RuntimeException: JVMTI_ERROR_ABSENT_INFORMATION class [Ljava.lang.Object; does not have a known source file because java.lang.RuntimeException: JVMTI_ERROR_ABSENT_INFORMATION +class [Ljava.lang.Object; does not have a known source file extension because java.lang.RuntimeException: JVMTI_ERROR_ABSENT_INFORMATION class [I does not have a known source file because java.lang.RuntimeException: JVMTI_ERROR_ABSENT_INFORMATION +class [I does not have a known source file extension because java.lang.RuntimeException: JVMTI_ERROR_ABSENT_INFORMATION null does not have a known source file because java.lang.RuntimeException: JVMTI_ERROR_INVALID_CLASS +null does not have a known source file extension because java.lang.RuntimeException: JVMTI_ERROR_INVALID_CLASS +Proxy of [interface java.lang.Runnable] does not have a known source file because java.lang.RuntimeException: JVMTI_ERROR_ABSENT_INFORMATION +Proxy of [interface java.lang.Runnable] does not have a known source file extension because java.lang.RuntimeException: JVMTI_ERROR_ABSENT_INFORMATION diff --git a/test/992-source-data/source_file.cc b/test/992-source-data/source_file.cc index 46d197d048..78687ff005 100644 --- a/test/992-source-data/source_file.cc +++ b/test/992-source-data/source_file.cc @@ -49,6 +49,19 @@ jstring JNICALL Java_art_Test992_getSourceFileName(JNIEnv* env, return ret; } +extern "C" JNIEXPORT +jstring JNICALL Java_art_Test992_getSourceDebugExtension(JNIEnv* env, + jclass klass ATTRIBUTE_UNUSED, + jclass target) { + char* ext = nullptr; + if (JvmtiErrorToException(env, jvmti_env, jvmti_env->GetSourceDebugExtension(target, &ext))) { + return nullptr; + } + jstring ret = env->NewStringUTF(ext); + jvmti_env->Deallocate(reinterpret_cast<unsigned char*>(ext)); + return ret; +} + } // namespace Test992SourceFile } // namespace art diff --git a/test/992-source-data/src/art/Test992.java b/test/992-source-data/src/art/Test992.java index d9ab112726..cc4f0c724c 100644 --- a/test/992-source-data/src/art/Test992.java +++ b/test/992-source-data/src/art/Test992.java @@ -16,6 +16,8 @@ package art; +import java.lang.reflect.Proxy; +import java.util.Arrays; import java.util.Base64; public class Test992 { @@ -33,15 +35,30 @@ public class Test992 { doTest(new Object[0].getClass()); doTest(new int[0].getClass()); doTest(null); + doTest(Proxy.getProxyClass(Test992.class.getClassLoader(), Runnable.class)); } + public static String printClass(Class<?> k) { + if (k != null && Proxy.class.isAssignableFrom(k)) { + return String.format("Proxy of %s", Arrays.toString(k.getInterfaces())); + } else { + return String.format("%s", k); + } + } public static void doTest(Class<?> k) { + String pk = printClass(k); + try { + System.out.println(pk + " is defined in file \"" + getSourceFileName(k) + "\""); + } catch (Exception e) { + System.out.println(pk + " does not have a known source file because " + e); + } try { - System.out.println(k + " is defined in file \"" + getSourceFileName(k) + "\""); + System.out.println(pk + " has extension \"" + getSourceDebugExtension(k) + "\""); } catch (Exception e) { - System.out.println(k + " does not have a known source file because " + e); + System.out.println(pk + " does not have a known source file extension because " + e); } } public static native String getSourceFileName(Class<?> k) throws Exception; + public static native String getSourceDebugExtension(Class<?> k) throws Exception; } |