summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Neil Fuller <nfuller@google.com> 2016-09-01 15:32:44 +0100
committer Neil Fuller <nfuller@google.com> 2016-09-07 11:12:02 +0100
commit60458a072c4f0b24038420b0f1bed0fe94c72965 (patch)
treee1e10a29c99f99538695c12da1af914d84ddd4c3
parent9d185da3bef8caf015d3dbf4ad79c520af7ce3b1 (diff)
Track libcore Executable.getParameter() changes
Executable.getParameter() has been added which added two new fields to java.lang.reflect.Executable, impacting class arrangements and padding. The java.lang.reflect.Parameter class has been added which has some associated native code and support methods in DexFile. Test: make test-art-host Bug: 28666126 Change-Id: I4ff6469388879651a6c9e568eca0b1cd716f0c0d
-rw-r--r--runtime/Android.bp1
-rw-r--r--runtime/class_linker_test.cc3
-rw-r--r--runtime/dex_file.cc28
-rw-r--r--runtime/dex_file.h4
-rw-r--r--runtime/mirror/abstract_method.h2
-rw-r--r--runtime/mirror/accessible_object.h5
-rw-r--r--runtime/mirror/executable.h3
-rw-r--r--runtime/mirror/field.h3
-rw-r--r--runtime/native/java_lang_reflect_Parameter.cc70
-rw-r--r--runtime/native/java_lang_reflect_Parameter.h28
-rw-r--r--runtime/runtime.cc2
11 files changed, 145 insertions, 4 deletions
diff --git a/runtime/Android.bp b/runtime/Android.bp
index 22d79cb737..0cc94c4341 100644
--- a/runtime/Android.bp
+++ b/runtime/Android.bp
@@ -156,6 +156,7 @@ cc_defaults {
"native/java_lang_reflect_Constructor.cc",
"native/java_lang_reflect_Field.cc",
"native/java_lang_reflect_Method.cc",
+ "native/java_lang_reflect_Parameter.cc",
"native/java_lang_reflect_Proxy.cc",
"native/java_util_concurrent_atomic_AtomicLong.cc",
"native/libcore_util_CharsetUtils.cc",
diff --git a/runtime/class_linker_test.cc b/runtime/class_linker_test.cc
index 3be39a1f79..5e0ee6fe23 100644
--- a/runtime/class_linker_test.cc
+++ b/runtime/class_linker_test.cc
@@ -697,6 +697,9 @@ struct FieldOffsets : public CheckOffsets<mirror::Field> {
struct ExecutableOffsets : public CheckOffsets<mirror::Executable> {
ExecutableOffsets() : CheckOffsets<mirror::Executable>(
false, "Ljava/lang/reflect/Executable;") {
+ addOffset(OFFSETOF_MEMBER(mirror::Executable, has_real_parameter_data_),
+ "hasRealParameterData");
+ addOffset(OFFSETOF_MEMBER(mirror::Executable, parameters_), "parameters");
};
};
diff --git a/runtime/dex_file.cc b/runtime/dex_file.cc
index ebadd7951c..76cd348d8e 100644
--- a/runtime/dex_file.cc
+++ b/runtime/dex_file.cc
@@ -1431,6 +1431,34 @@ mirror::ObjectArray<mirror::Object>* DexFile::GetParameterAnnotations(ArtMethod*
return ProcessAnnotationSetRefList(method_class, set_ref_list, size);
}
+mirror::Object* DexFile::GetAnnotationForMethodParameter(ArtMethod* method,
+ uint32_t parameter_idx,
+ Handle<mirror::Class> annotation_class)
+ const {
+ const ParameterAnnotationsItem* parameter_annotations = FindAnnotationsItemForMethod(method);
+ if (parameter_annotations == nullptr) {
+ return nullptr;
+ }
+ const AnnotationSetRefList* set_ref_list =
+ GetParameterAnnotationSetRefList(parameter_annotations);
+ if (set_ref_list == nullptr) {
+ return nullptr;
+ }
+
+ if (parameter_idx >= set_ref_list->size_) {
+ return nullptr;
+ }
+ const AnnotationSetRefItem* annotation_set_ref = &set_ref_list->list_[parameter_idx];
+ const AnnotationSetItem* annotation_set = GetSetRefItemItem(annotation_set_ref);
+
+ StackHandleScope<1> hs(Thread::Current());
+ Handle<mirror::Class> method_class(hs.NewHandle(method->GetDeclaringClass()));
+ return GetAnnotationObjectFromAnnotationSet(method_class,
+ annotation_set,
+ kDexVisibilityRuntime,
+ annotation_class);
+}
+
mirror::ObjectArray<mirror::String>* DexFile::GetSignatureAnnotationForMethod(ArtMethod* method)
const {
const AnnotationSetItem* annotation_set = FindAnnotationSetForMethod(method);
diff --git a/runtime/dex_file.h b/runtime/dex_file.h
index ebbde0a602..23676bdbf7 100644
--- a/runtime/dex_file.h
+++ b/runtime/dex_file.h
@@ -953,6 +953,10 @@ class DexFile {
REQUIRES_SHARED(Locks::mutator_lock_);
mirror::Object* GetAnnotationForMethod(ArtMethod* method, Handle<mirror::Class> annotation_class)
const REQUIRES_SHARED(Locks::mutator_lock_);
+ mirror::Object* GetAnnotationForMethodParameter(ArtMethod* method,
+ uint32_t parameter_idx,
+ Handle<mirror::Class> annotation_class) const
+ REQUIRES_SHARED(Locks::mutator_lock_);
mirror::ObjectArray<mirror::Object>* GetAnnotationsForMethod(ArtMethod* method) const
REQUIRES_SHARED(Locks::mutator_lock_);
mirror::ObjectArray<mirror::Class>* GetExceptionTypesForMethod(ArtMethod* method) const
diff --git a/runtime/mirror/abstract_method.h b/runtime/mirror/abstract_method.h
index 22a3ea860b..9c2061387e 100644
--- a/runtime/mirror/abstract_method.h
+++ b/runtime/mirror/abstract_method.h
@@ -63,8 +63,8 @@ class MANAGED AbstractMethod : public Executable {
HeapReference<mirror::Class> declaring_class_;
HeapReference<mirror::Class> declaring_class_of_overridden_method_;
- uint32_t access_flags_;
uint64_t art_method_;
+ uint32_t access_flags_;
uint32_t dex_method_index_;
friend struct art::AbstractMethodOffsets; // for verifying offset information
diff --git a/runtime/mirror/accessible_object.h b/runtime/mirror/accessible_object.h
index 1d934a8eed..2581ac214f 100644
--- a/runtime/mirror/accessible_object.h
+++ b/runtime/mirror/accessible_object.h
@@ -47,9 +47,8 @@ class MANAGED AccessibleObject : public Object {
private:
uint8_t flag_;
- // Padding required for now since "packed" will cause reflect.Field fields to not be aligned
- // otherwise.
- uint8_t padding_[3];
+ // Padding required for correct alignment of subclasses like Executable, Field, etc.
+ uint8_t padding_[1];
DISALLOW_IMPLICIT_CONSTRUCTORS(AccessibleObject);
};
diff --git a/runtime/mirror/executable.h b/runtime/mirror/executable.h
index 87866579f5..232fce8693 100644
--- a/runtime/mirror/executable.h
+++ b/runtime/mirror/executable.h
@@ -33,6 +33,9 @@ namespace mirror {
// C++ mirror of java.lang.reflect.Executable.
class MANAGED Executable : public AccessibleObject {
private:
+ uint16_t has_real_parameter_data_;
+ HeapReference<mirror::Array> parameters_;
+
friend struct art::ExecutableOffsets; // for verifying offset information
DISALLOW_IMPLICIT_CONSTRUCTORS(Executable);
};
diff --git a/runtime/mirror/field.h b/runtime/mirror/field.h
index 7eb9da4126..f378568258 100644
--- a/runtime/mirror/field.h
+++ b/runtime/mirror/field.h
@@ -99,6 +99,9 @@ class MANAGED Field : public AccessibleObject {
REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!Roles::uninterruptible_);
private:
+ // Padding required for matching alignment with the Java peer.
+ uint8_t padding_[2];
+
HeapReference<mirror::Class> declaring_class_;
HeapReference<mirror::Class> type_;
int32_t access_flags_;
diff --git a/runtime/native/java_lang_reflect_Parameter.cc b/runtime/native/java_lang_reflect_Parameter.cc
new file mode 100644
index 0000000000..8fe3bb590e
--- /dev/null
+++ b/runtime/native/java_lang_reflect_Parameter.cc
@@ -0,0 +1,70 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "java_lang_reflect_Parameter.h"
+
+#include "art_method-inl.h"
+#include "common_throws.h"
+#include "dex_file-inl.h"
+#include "jni_internal.h"
+#include "scoped_fast_native_object_access.h"
+#include "utils.h"
+
+namespace art {
+
+static jobject Parameter_getAnnotationNative(JNIEnv* env,
+ jclass,
+ jobject javaMethod,
+ jint parameterIndex,
+ jclass annotationType) {
+ ScopedFastNativeObjectAccess soa(env);
+ if (UNLIKELY(javaMethod == nullptr)) {
+ ThrowNullPointerException("javaMethod == null");
+ return nullptr;
+ }
+
+ ArtMethod* method = ArtMethod::FromReflectedMethod(soa, javaMethod);
+ if (method->IsProxyMethod()) {
+ return nullptr;
+ }
+
+ uint32_t parameter_count = method->GetParameterTypeList()->Size();
+ if (UNLIKELY(parameterIndex < 0 || static_cast<uint32_t>(parameterIndex) >= parameter_count)) {
+ ThrowIllegalArgumentException(
+ StringPrintf("Illegal parameterIndex %d for %s, parameter_count is %d",
+ parameterIndex,
+ PrettyMethod(method).c_str(),
+ parameter_count).c_str());
+ return nullptr;
+ }
+
+ StackHandleScope<1> hs(soa.Self());
+ Handle<mirror::Class> klass(hs.NewHandle(soa.Decode<mirror::Class*>(annotationType)));
+ return soa.AddLocalReference<jobject>(
+ method->GetDexFile()->GetAnnotationForMethodParameter(method, parameterIndex, klass));
+}
+
+static JNINativeMethod gMethods[] = {
+ NATIVE_METHOD(Parameter,
+ getAnnotationNative,
+ "!(Ljava/lang/reflect/Executable;ILjava/lang/Class;)Ljava/lang/annotation/Annotation;"),
+};
+
+void register_java_lang_reflect_Parameter(JNIEnv* env) {
+ REGISTER_NATIVE_METHODS("java/lang/reflect/Parameter");
+}
+
+} // namespace art
diff --git a/runtime/native/java_lang_reflect_Parameter.h b/runtime/native/java_lang_reflect_Parameter.h
new file mode 100644
index 0000000000..f6322b146f
--- /dev/null
+++ b/runtime/native/java_lang_reflect_Parameter.h
@@ -0,0 +1,28 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef ART_RUNTIME_NATIVE_JAVA_LANG_REFLECT_PARAMETER_H_
+#define ART_RUNTIME_NATIVE_JAVA_LANG_REFLECT_PARAMETER_H_
+
+#include <jni.h>
+
+namespace art {
+
+void register_java_lang_reflect_Parameter(JNIEnv* env);
+
+} // namespace art
+
+#endif // ART_RUNTIME_NATIVE_JAVA_LANG_REFLECT_PARAMETER_H_
diff --git a/runtime/runtime.cc b/runtime/runtime.cc
index a365a737d8..45ccbe066d 100644
--- a/runtime/runtime.cc
+++ b/runtime/runtime.cc
@@ -111,6 +111,7 @@
#include "native/java_lang_reflect_Constructor.h"
#include "native/java_lang_reflect_Field.h"
#include "native/java_lang_reflect_Method.h"
+#include "native/java_lang_reflect_Parameter.h"
#include "native/java_lang_reflect_Proxy.h"
#include "native/java_util_concurrent_atomic_AtomicLong.h"
#include "native/libcore_util_CharsetUtils.h"
@@ -1404,6 +1405,7 @@ void Runtime::RegisterRuntimeNativeMethods(JNIEnv* env) {
register_java_lang_reflect_Constructor(env);
register_java_lang_reflect_Field(env);
register_java_lang_reflect_Method(env);
+ register_java_lang_reflect_Parameter(env);
register_java_lang_reflect_Proxy(env);
register_java_lang_ref_Reference(env);
register_java_lang_String(env);