summaryrefslogtreecommitdiffstats
path: root/test/461-get-reference-vreg
diff options
context:
space:
mode:
authorNicolas Geoffray <ngeoffray@google.com>2015-03-11 15:11:19 +0000
committerNicolas Geoffray <ngeoffray@google.com>2015-03-12 17:55:01 +0000
commit915b9d0c13bb5091875d868fbfa551d7b65d7477 (patch)
tree63822d7081b0da33ccda2019dd52025f0ecedb35 /test/461-get-reference-vreg
parentbf5565a75876a84c8c2401df597d922a7870a8f2 (diff)
downloadart-915b9d0c13bb5091875d868fbfa551d7b65d7477.zip
art-915b9d0c13bb5091875d868fbfa551d7b65d7477.tar.gz
art-915b9d0c13bb5091875d868fbfa551d7b65d7477.tar.bz2
Tweak liveness when instructions are used in environments.
Instructions remain live when debuggable, but only instructions with object types remain live when non-debuggable. Enable StackVisitor::GetThisObject for optimizing. Change-Id: Id87b2cbf33a02450059acc9993995782e5f28987
Diffstat (limited to 'test/461-get-reference-vreg')
-rw-r--r--test/461-get-reference-vreg/expected.txt0
-rw-r--r--test/461-get-reference-vreg/get_reference_vreg_jni.cc86
-rw-r--r--test/461-get-reference-vreg/info.txt1
-rw-r--r--test/461-get-reference-vreg/src/Main.java65
4 files changed, 152 insertions, 0 deletions
diff --git a/test/461-get-reference-vreg/expected.txt b/test/461-get-reference-vreg/expected.txt
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/test/461-get-reference-vreg/expected.txt
diff --git a/test/461-get-reference-vreg/get_reference_vreg_jni.cc b/test/461-get-reference-vreg/get_reference_vreg_jni.cc
new file mode 100644
index 0000000..f0b78e1
--- /dev/null
+++ b/test/461-get-reference-vreg/get_reference_vreg_jni.cc
@@ -0,0 +1,86 @@
+/*
+ * Copyright (C) 2015 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 "arch/context.h"
+#include "jni.h"
+#include "mirror/art_method-inl.h"
+#include "scoped_thread_state_change.h"
+#include "stack.h"
+#include "thread.h"
+
+namespace art {
+
+namespace {
+
+class TestVisitor : public StackVisitor {
+ public:
+ TestVisitor(Thread* thread, Context* context, mirror::Object* this_value)
+ SHARED_LOCKS_REQUIRED(Locks::mutator_lock_)
+ : StackVisitor(thread, context), this_value_(this_value), found_method_index_(0) {}
+
+ bool VisitFrame() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
+ mirror::ArtMethod* m = GetMethod();
+ std::string m_name(m->GetName());
+
+ if (m_name.compare("testThisWithInstanceCall") == 0) {
+ found_method_index_ = 1;
+ uint32_t value = 0;
+ CHECK(GetVReg(m, 1, kReferenceVReg, &value));
+ CHECK_EQ(reinterpret_cast<mirror::Object*>(value), this_value_);
+ CHECK_EQ(GetThisObject(), this_value_);
+ } else if (m_name.compare("testThisWithStaticCall") == 0) {
+ found_method_index_ = 2;
+ uint32_t value = 0;
+ CHECK(GetVReg(m, 1, kReferenceVReg, &value));
+ } else if (m_name.compare("testParameter") == 0) {
+ found_method_index_ = 3;
+ uint32_t value = 0;
+ CHECK(GetVReg(m, 1, kReferenceVReg, &value));
+ } else if (m_name.compare("testObjectInScope") == 0) {
+ found_method_index_ = 4;
+ uint32_t value = 0;
+ CHECK(GetVReg(m, 0, kReferenceVReg, &value));
+ }
+
+ return true;
+ }
+
+ mirror::Object* this_value_;
+
+ // Value returned to Java to ensure the methods testSimpleVReg and testPairVReg
+ // have been found and tested.
+ jint found_method_index_;
+};
+
+extern "C" JNIEXPORT jint JNICALL Java_Main_doNativeCallRef(JNIEnv*, jobject value) {
+ ScopedObjectAccess soa(Thread::Current());
+ std::unique_ptr<Context> context(Context::Create());
+ TestVisitor visitor(soa.Self(), context.get(), soa.Decode<mirror::Object*>(value));
+ visitor.WalkStack();
+ return visitor.found_method_index_;
+}
+
+extern "C" JNIEXPORT jint JNICALL Java_Main_doStaticNativeCallRef(JNIEnv*, jclass) {
+ ScopedObjectAccess soa(Thread::Current());
+ std::unique_ptr<Context> context(Context::Create());
+ TestVisitor visitor(soa.Self(), context.get(), nullptr);
+ visitor.WalkStack();
+ return visitor.found_method_index_;
+}
+
+} // namespace
+
+} // namespace art
diff --git a/test/461-get-reference-vreg/info.txt b/test/461-get-reference-vreg/info.txt
new file mode 100644
index 0000000..1e5e971
--- /dev/null
+++ b/test/461-get-reference-vreg/info.txt
@@ -0,0 +1 @@
+Tests for inspecting DEX registers holding references.
diff --git a/test/461-get-reference-vreg/src/Main.java b/test/461-get-reference-vreg/src/Main.java
new file mode 100644
index 0000000..a94c6fb
--- /dev/null
+++ b/test/461-get-reference-vreg/src/Main.java
@@ -0,0 +1,65 @@
+/*
+ * Copyright (C) 2015 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 {
+ public Main() {
+ }
+
+ int testThisWithInstanceCall() {
+ return doNativeCallRef();
+ }
+
+ int testThisWithStaticCall() {
+ return doStaticNativeCallRef();
+ }
+
+ static int testParameter(Object a) {
+ return doStaticNativeCallRef();
+ }
+
+ static int testObjectInScope() {
+ Object a = array[0];
+ return doStaticNativeCallRef();
+ }
+
+ native int doNativeCallRef();
+ static native int doStaticNativeCallRef();
+
+ static {
+ System.loadLibrary("arttest");
+ }
+
+ public static void main(String[] args) {
+ Main rm = new Main();
+ if (rm.testThisWithInstanceCall() != 1) {
+ throw new Error("Expected 1");
+ }
+
+ if (rm.testThisWithStaticCall() != 2) {
+ throw new Error("Expected 2");
+ }
+
+ if (testParameter(new Object()) != 3) {
+ throw new Error("Expected 3");
+ }
+
+ if (testObjectInScope() != 4) {
+ throw new Error("Expected 4");
+ }
+ }
+
+ static Object[] array = new Object[] { new Object() };
+}