diff options
| author | 2015-09-30 13:13:21 -0700 | |
|---|---|---|
| committer | 2015-09-30 13:13:21 -0700 | |
| commit | 89df7bfc41a4de9685f84e7db07f77db3fd485fc (patch) | |
| tree | f1a266870d0020b9b814022698569affc90e3844 | |
| parent | 931e26843bbb688eacfa67b40414c6b8f221a56a (diff) | |
ART: Refactor libarttest C++ code
Refactor some libarttest JNI functions into a common directory, so
they can be easily used by multiple tests without code duplication.
This is preparation for better deoptimization state testing.
Change-Id: I43f7340b699b26930aabfd665c707e0485b17fc8
| -rw-r--r-- | test/088-monitor-verification/expected.txt | 6 | ||||
| -rw-r--r-- | test/088-monitor-verification/src/Main.java | 9 | ||||
| -rw-r--r-- | test/116-nodex2oat/nodex2oat.cc | 44 | ||||
| -rw-r--r-- | test/116-nodex2oat/src/Main.java | 8 | ||||
| -rw-r--r-- | test/118-noimage-dex2oat/noimage-dex2oat.cc | 44 | ||||
| -rw-r--r-- | test/Android.libarttest.mk | 5 | ||||
| -rw-r--r-- | test/common/runtime_state.cc | 69 | ||||
| -rw-r--r-- | test/common/stack_inspect.cc (renamed from test/088-monitor-verification/stack_inspect.cc) | 43 |
8 files changed, 101 insertions, 127 deletions
diff --git a/test/088-monitor-verification/expected.txt b/test/088-monitor-verification/expected.txt index f252f6f2ee..2cb8f2cdf2 100644 --- a/test/088-monitor-verification/expected.txt +++ b/test/088-monitor-verification/expected.txt @@ -5,9 +5,3 @@ constantLock ok notNested ok twoPath ok triplet ok -OK -TooDeep -NotStructuredOverUnlock -NotStructuredUnderUnlock -UnbalancedJoin -UnbalancedStraight diff --git a/test/088-monitor-verification/src/Main.java b/test/088-monitor-verification/src/Main.java index 53b72e9f5c..fc5755b06f 100644 --- a/test/088-monitor-verification/src/Main.java +++ b/test/088-monitor-verification/src/Main.java @@ -220,6 +220,11 @@ public class Main { // Smali testing code. private static void runSmaliTests() { + if (!hasOatFile() || runtimeIsSoftFail() || isCallerInterpreted()) { + // Skip test, this seems to be a non-compiled code test configuration. + return; + } + runTest("OK", new Object[] { new Object(), new Object() }, null); runTest("TooDeep", new Object[] { new Object() }, null); runTest("NotStructuredOverUnlock", new Object[] { new Object() }, @@ -231,7 +236,6 @@ public class Main { } private static void runTest(String className, Object[] parameters, Class<?> excType) { - System.out.println(className); try { Class<?> c = Class.forName(className); @@ -275,4 +279,7 @@ public class Main { // Helpers for the smali code. public static native void assertCallerIsInterpreted(); public static native void assertCallerIsManaged(); + public static native boolean hasOatFile(); + public static native boolean runtimeIsSoftFail(); + public static native boolean isCallerInterpreted(); } diff --git a/test/116-nodex2oat/nodex2oat.cc b/test/116-nodex2oat/nodex2oat.cc deleted file mode 100644 index 131af312be..0000000000 --- a/test/116-nodex2oat/nodex2oat.cc +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (C) 2014 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 "class_linker.h" -#include "dex_file-inl.h" -#include "mirror/class-inl.h" -#include "scoped_thread_state_change.h" -#include "thread.h" - -namespace art { - -class NoDex2OatTest { - public: - static bool hasOat(jclass cls) { - ScopedObjectAccess soa(Thread::Current()); - mirror::Class* klass = soa.Decode<mirror::Class*>(cls); - const DexFile& dex_file = klass->GetDexFile(); - const OatFile::OatDexFile* oat_dex_file = dex_file.GetOatDexFile(); - return oat_dex_file != nullptr; - } -}; - -extern "C" JNIEXPORT jboolean JNICALL Java_Main_hasOat(JNIEnv*, jclass cls) { - return NoDex2OatTest::hasOat(cls); -} - -extern "C" JNIEXPORT jboolean JNICALL Java_Main_isDex2OatEnabled(JNIEnv*, jclass) { - return Runtime::Current()->IsDex2OatEnabled(); -} - -} // namespace art diff --git a/test/116-nodex2oat/src/Main.java b/test/116-nodex2oat/src/Main.java index 086ffb9295..229735f4b8 100644 --- a/test/116-nodex2oat/src/Main.java +++ b/test/116-nodex2oat/src/Main.java @@ -18,16 +18,16 @@ public class Main { public static void main(String[] args) { System.loadLibrary(args[0]); System.out.println( - "Has oat is " + hasOat() + ", is dex2oat enabled is " + isDex2OatEnabled() + "."); + "Has oat is " + hasOatFile() + ", is dex2oat enabled is " + isDex2OatEnabled() + "."); - if (hasOat() && !isDex2OatEnabled()) { + if (hasOatFile() && !isDex2OatEnabled()) { throw new Error("Application with dex2oat disabled runs with an oat file"); - } else if (!hasOat() && isDex2OatEnabled()) { + } else if (!hasOatFile() && isDex2OatEnabled()) { throw new Error("Application with dex2oat enabled runs without an oat file"); } } - private native static boolean hasOat(); + private native static boolean hasOatFile(); private native static boolean isDex2OatEnabled(); } diff --git a/test/118-noimage-dex2oat/noimage-dex2oat.cc b/test/118-noimage-dex2oat/noimage-dex2oat.cc deleted file mode 100644 index aacf00f300..0000000000 --- a/test/118-noimage-dex2oat/noimage-dex2oat.cc +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (C) 2014 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 "class_linker.h" -#include "dex_file-inl.h" -#include "mirror/class-inl.h" -#include "scoped_thread_state_change.h" -#include "thread.h" - -namespace art { - -class NoDex2OatTest { - public: - static bool hasOat(jclass cls) { - ScopedObjectAccess soa(Thread::Current()); - mirror::Class* klass = soa.Decode<mirror::Class*>(cls); - const DexFile& dex_file = klass->GetDexFile(); - const OatFile::OatDexFile* oat_dex_file = dex_file.GetOatDexFile(); - return oat_dex_file != nullptr; - } -}; - -extern "C" JNIEXPORT jboolean JNICALL Java_Main_hasImage(JNIEnv*, jclass) { - return Runtime::Current()->GetHeap()->HasImageSpace(); -} - -extern "C" JNIEXPORT jboolean JNICALL Java_Main_isImageDex2OatEnabled(JNIEnv*, jclass) { - return Runtime::Current()->IsImageDex2OatEnabled(); -} - -} // namespace art diff --git a/test/Android.libarttest.mk b/test/Android.libarttest.mk index e43ea90ba6..bffd0e0aa6 100644 --- a/test/Android.libarttest.mk +++ b/test/Android.libarttest.mk @@ -19,6 +19,8 @@ LOCAL_PATH := $(call my-dir) include art/build/Android.common_build.mk LIBARTTEST_COMMON_SRC_FILES := \ + common/runtime_state.cc \ + common/stack_inspect.cc \ 004-JniTest/jni_test.cc \ 004-SignalTest/signaltest.cc \ 004-ReferenceMap/stack_walk_refmap_jni.cc \ @@ -26,10 +28,7 @@ LIBARTTEST_COMMON_SRC_FILES := \ 004-UnsafeTest/unsafe_test.cc \ 044-proxy/native_proxy.cc \ 051-thread/thread_test.cc \ - 088-monitor-verification/stack_inspect.cc \ - 116-nodex2oat/nodex2oat.cc \ 117-nopatchoat/nopatchoat.cc \ - 118-noimage-dex2oat/noimage-dex2oat.cc \ 1337-gc-coverage/gc_coverage.cc \ 137-cfi/cfi.cc \ 139-register-natives/regnative.cc \ diff --git a/test/common/runtime_state.cc b/test/common/runtime_state.cc new file mode 100644 index 0000000000..042b03bfb6 --- /dev/null +++ b/test/common/runtime_state.cc @@ -0,0 +1,69 @@ +/* + * 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 "jni.h" + +#include "base/logging.h" +#include "dex_file-inl.h" +#include "mirror/class-inl.h" +#include "nth_caller_visitor.h" +#include "runtime.h" +#include "scoped_thread_state_change.h" +#include "stack.h" +#include "thread-inl.h" + +namespace art { + +// public static native boolean hasOatFile(); + +extern "C" JNIEXPORT jboolean JNICALL Java_Main_hasOatFile(JNIEnv* env, jclass cls) { + ScopedObjectAccess soa(env); + + mirror::Class* klass = soa.Decode<mirror::Class*>(cls); + const DexFile& dex_file = klass->GetDexFile(); + const OatFile::OatDexFile* oat_dex_file = dex_file.GetOatDexFile(); + return (oat_dex_file != nullptr) ? JNI_TRUE : JNI_FALSE; +} + +// public static native boolean runtimeIsSoftFail(); + +extern "C" JNIEXPORT jboolean JNICALL Java_Main_runtimeIsSoftFail(JNIEnv* env ATTRIBUTE_UNUSED, + jclass cls ATTRIBUTE_UNUSED) { + return Runtime::Current()->IsVerificationSoftFail() ? JNI_TRUE : JNI_FALSE; +} + +// public static native boolean isDex2OatEnabled(); + +extern "C" JNIEXPORT jboolean JNICALL Java_Main_isDex2OatEnabled(JNIEnv* env ATTRIBUTE_UNUSED, + jclass cls ATTRIBUTE_UNUSED) { + return Runtime::Current()->IsDex2OatEnabled(); +} + +// public static native boolean hasImage(); + +extern "C" JNIEXPORT jboolean JNICALL Java_Main_hasImage(JNIEnv* env ATTRIBUTE_UNUSED, + jclass cls ATTRIBUTE_UNUSED) { + return Runtime::Current()->GetHeap()->HasImageSpace(); +} + +// public static native boolean isImageDex2OatEnabled(); + +extern "C" JNIEXPORT jboolean JNICALL Java_Main_isImageDex2OatEnabled(JNIEnv* env ATTRIBUTE_UNUSED, + jclass cls ATTRIBUTE_UNUSED) { + return Runtime::Current()->IsImageDex2OatEnabled(); +} + +} // namespace art diff --git a/test/088-monitor-verification/stack_inspect.cc b/test/common/stack_inspect.cc index e2899c3d68..d22cf52882 100644 --- a/test/088-monitor-verification/stack_inspect.cc +++ b/test/common/stack_inspect.cc @@ -27,25 +27,26 @@ namespace art { -// public static native void assertCallerIsInterpreted(); - -extern "C" JNIEXPORT void JNICALL Java_Main_assertCallerIsInterpreted(JNIEnv* env, jclass) { - LOG(INFO) << "assertCallerIsInterpreted"; +// public static native boolean isCallerInterpreted(); +extern "C" JNIEXPORT jboolean JNICALL Java_Main_isCallerInterpreted(JNIEnv* env, jclass) { ScopedObjectAccess soa(env); NthCallerVisitor caller(soa.Self(), 1, false); caller.WalkStack(); CHECK(caller.caller != nullptr); - LOG(INFO) << PrettyMethod(caller.caller); - CHECK(caller.GetCurrentShadowFrame() != nullptr); + return caller.GetCurrentShadowFrame() != nullptr ? JNI_TRUE : JNI_FALSE; } -// public static native void assertCallerIsManaged(); +// public static native void assertCallerIsInterpreted(); + +extern "C" JNIEXPORT void JNICALL Java_Main_assertCallerIsInterpreted(JNIEnv* env, jclass klass) { + CHECK(Java_Main_isCallerInterpreted(env, klass)); +} -extern "C" JNIEXPORT void JNICALL Java_Main_assertCallerIsManaged(JNIEnv* env, jclass cls) { - // Note: needs some smarts to not fail if there is no managed code, at all. - LOG(INFO) << "assertCallerIsManaged"; +// public static native boolean isCallerManaged(); + +extern "C" JNIEXPORT jboolean JNICALL Java_Main_isCallerManaged(JNIEnv* env, jclass cls) { ScopedObjectAccess soa(env); mirror::Class* klass = soa.Decode<mirror::Class*>(cls); @@ -54,28 +55,20 @@ extern "C" JNIEXPORT void JNICALL Java_Main_assertCallerIsManaged(JNIEnv* env, j if (oat_dex_file == nullptr) { // No oat file, this must be a test configuration that doesn't compile at all. Ignore that the // result will be that we're running the interpreter. - return; + return JNI_FALSE; } NthCallerVisitor caller(soa.Self(), 1, false); caller.WalkStack(); CHECK(caller.caller != nullptr); - LOG(INFO) << PrettyMethod(caller.caller); - if (caller.GetCurrentShadowFrame() == nullptr) { - // Not a shadow frame, this looks good. - return; - } + return caller.GetCurrentShadowFrame() != nullptr ? JNI_FALSE : JNI_TRUE; +} - // This could be an interpret-only or a verify-at-runtime compilation, or a read-barrier variant, - // or... It's not really safe to just reject now. Let's look at the access flags. If the method - // was successfully verified, its access flags should be set to mark it preverified, except when - // we're running soft-fail tests. - if (Runtime::Current()->IsVerificationSoftFail()) { - // Soft-fail config. Everything should be running with interpreter access checks, potentially. - return; - } - CHECK(caller.caller->IsPreverified()); +// public static native void assertCallerIsManaged(); + +extern "C" JNIEXPORT void JNICALL Java_Main_assertCallerIsManaged(JNIEnv* env, jclass cls) { + CHECK(Java_Main_isCallerManaged(env, cls)); } } // namespace art |