summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Vladimir Marko <vmarko@google.com> 2018-03-29 17:07:17 +0100
committer Vladimir Marko <vmarko@google.com> 2018-03-29 17:39:44 +0100
commitc4b1c0c42a707675755a468ba36026d7166a3cc0 (patch)
tree8e271a164f8bf584bff623a926d4ef323ee2f1c6
parent8068bc3bc68e9560cc4650c6fb261ec9b8648fbd (diff)
Fix failure to initialize AnnotatedStackTraceElement.
Test: 171-init-aste Test: testrunner.py --host --interpreter Bug: 76208924 Change-Id: I2a0892c5cc8ab5cbc54a94c25a02add1031e68f5
-rw-r--r--runtime/thread.cc11
-rw-r--r--test/171-init-aste/expected.txt1
-rw-r--r--test/171-init-aste/info.txt1
-rw-r--r--test/171-init-aste/src-art/Main.java37
-rw-r--r--test/171-init-aste/src/Main.java24
5 files changed, 74 insertions, 0 deletions
diff --git a/runtime/thread.cc b/runtime/thread.cc
index b13d8ec42a..d17f409a7d 100644
--- a/runtime/thread.cc
+++ b/runtime/thread.cc
@@ -2881,6 +2881,17 @@ jobjectArray Thread::CreateAnnotatedStackTrace(const ScopedObjectAccessAlreadyRu
Handle<mirror::Class> h_aste_class(hs.NewHandle<mirror::Class>(
h_aste_array_class->GetComponentType()));
+
+ // Make sure the AnnotatedStackTraceElement.class is initialized, b/76208924 .
+ class_linker->EnsureInitialized(soa.Self(),
+ h_aste_class,
+ /* can_init_fields */ true,
+ /* can_init_parents */ true);
+ if (soa.Self()->IsExceptionPending()) {
+ // This should not fail in a healthy runtime.
+ return nullptr;
+ }
+
ArtField* stack_trace_element_field = h_aste_class->FindField(
soa.Self(), h_aste_class.Get(), "stackTraceElement", "Ljava/lang/StackTraceElement;");
DCHECK(stack_trace_element_field != nullptr);
diff --git a/test/171-init-aste/expected.txt b/test/171-init-aste/expected.txt
new file mode 100644
index 0000000000..b0aad4deb5
--- /dev/null
+++ b/test/171-init-aste/expected.txt
@@ -0,0 +1 @@
+passed
diff --git a/test/171-init-aste/info.txt b/test/171-init-aste/info.txt
new file mode 100644
index 0000000000..201e8ada57
--- /dev/null
+++ b/test/171-init-aste/info.txt
@@ -0,0 +1 @@
+Regression test for failure to initialize dalvik.system.AnnotatedStackTraceElement.
diff --git a/test/171-init-aste/src-art/Main.java b/test/171-init-aste/src-art/Main.java
new file mode 100644
index 0000000000..9d3661022e
--- /dev/null
+++ b/test/171-init-aste/src-art/Main.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2018 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.
+ */
+
+import java.lang.reflect.Method;
+import dalvik.system.AnnotatedStackTraceElement;
+
+public class Main {
+ public static void main(String args[]) throws Exception {
+ Class<?> vmStack = Class.forName("dalvik.system.VMStack");
+ Method getAnnotatedThreadStackTrace =
+ vmStack.getDeclaredMethod("getAnnotatedThreadStackTrace", Thread.class);
+ Object[] annotatedStackTrace =
+ (Object[]) getAnnotatedThreadStackTrace.invoke(null, Thread.currentThread());
+ AnnotatedStackTraceElement annotatedElement =
+ (AnnotatedStackTraceElement) annotatedStackTrace[0];
+ // This used to fail an assertion that the AnnotatedStackTraceElement.class
+ // is at least initializing (i.e. initializing, initialized or resolved-erroneous).
+ // Note: We cannot use reflection for this test because getDeclaredMethod() would
+ // initialize the class and hide the failure.
+ annotatedElement.getStackTraceElement();
+
+ System.out.println("passed");
+ }
+}
diff --git a/test/171-init-aste/src/Main.java b/test/171-init-aste/src/Main.java
new file mode 100644
index 0000000000..4479cb4373
--- /dev/null
+++ b/test/171-init-aste/src/Main.java
@@ -0,0 +1,24 @@
+/*
+ * Copyright (C) 2018 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.
+ */
+
+public class Main {
+ // Note: This file is used for the RI which does not support
+ // dalvik.system.AnnotatedStackTraceElement (see src-art/Main.java),
+ // so that we do not need an exclusion in known failures.
+ public static void main(String args[]) throws Exception {
+ System.out.println("passed");
+ }
+}