Andreas Gampe | 89df7bf | 2015-09-30 13:13:21 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include "jni.h" |
| 18 | |
| 19 | #include "base/logging.h" |
| 20 | #include "dex_file-inl.h" |
| 21 | #include "mirror/class-inl.h" |
| 22 | #include "nth_caller_visitor.h" |
| 23 | #include "runtime.h" |
| 24 | #include "scoped_thread_state_change.h" |
| 25 | #include "stack.h" |
| 26 | #include "thread-inl.h" |
| 27 | |
| 28 | namespace art { |
| 29 | |
| 30 | // public static native boolean hasOatFile(); |
| 31 | |
| 32 | extern "C" JNIEXPORT jboolean JNICALL Java_Main_hasOatFile(JNIEnv* env, jclass cls) { |
| 33 | ScopedObjectAccess soa(env); |
| 34 | |
| 35 | mirror::Class* klass = soa.Decode<mirror::Class*>(cls); |
| 36 | const DexFile& dex_file = klass->GetDexFile(); |
| 37 | const OatFile::OatDexFile* oat_dex_file = dex_file.GetOatDexFile(); |
| 38 | return (oat_dex_file != nullptr) ? JNI_TRUE : JNI_FALSE; |
| 39 | } |
| 40 | |
| 41 | // public static native boolean runtimeIsSoftFail(); |
| 42 | |
| 43 | extern "C" JNIEXPORT jboolean JNICALL Java_Main_runtimeIsSoftFail(JNIEnv* env ATTRIBUTE_UNUSED, |
| 44 | jclass cls ATTRIBUTE_UNUSED) { |
| 45 | return Runtime::Current()->IsVerificationSoftFail() ? JNI_TRUE : JNI_FALSE; |
| 46 | } |
| 47 | |
| 48 | // public static native boolean isDex2OatEnabled(); |
| 49 | |
| 50 | extern "C" JNIEXPORT jboolean JNICALL Java_Main_isDex2OatEnabled(JNIEnv* env ATTRIBUTE_UNUSED, |
| 51 | jclass cls ATTRIBUTE_UNUSED) { |
| 52 | return Runtime::Current()->IsDex2OatEnabled(); |
| 53 | } |
| 54 | |
| 55 | // public static native boolean hasImage(); |
| 56 | |
| 57 | extern "C" JNIEXPORT jboolean JNICALL Java_Main_hasImage(JNIEnv* env ATTRIBUTE_UNUSED, |
| 58 | jclass cls ATTRIBUTE_UNUSED) { |
Jeff Hao | dcdc85b | 2015-12-04 14:06:18 -0800 | [diff] [blame] | 59 | return Runtime::Current()->GetHeap()->HasBootImageSpace(); |
Andreas Gampe | 89df7bf | 2015-09-30 13:13:21 -0700 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | // public static native boolean isImageDex2OatEnabled(); |
| 63 | |
| 64 | extern "C" JNIEXPORT jboolean JNICALL Java_Main_isImageDex2OatEnabled(JNIEnv* env ATTRIBUTE_UNUSED, |
| 65 | jclass cls ATTRIBUTE_UNUSED) { |
| 66 | return Runtime::Current()->IsImageDex2OatEnabled(); |
| 67 | } |
| 68 | |
Andreas Gampe | 0dfc9bc | 2015-09-30 17:13:59 -0700 | [diff] [blame] | 69 | // public static native boolean compiledWithOptimizing(); |
| 70 | // Did we use the optimizing compiler to compile this? |
| 71 | |
| 72 | extern "C" JNIEXPORT jboolean JNICALL Java_Main_compiledWithOptimizing(JNIEnv* env, jclass cls) { |
| 73 | ScopedObjectAccess soa(env); |
| 74 | |
| 75 | mirror::Class* klass = soa.Decode<mirror::Class*>(cls); |
| 76 | const DexFile& dex_file = klass->GetDexFile(); |
| 77 | const OatFile::OatDexFile* oat_dex_file = dex_file.GetOatDexFile(); |
| 78 | if (oat_dex_file == nullptr) { |
| 79 | // Could be JIT, which also uses optimizing, but conservatively say no. |
| 80 | return JNI_FALSE; |
| 81 | } |
| 82 | const OatFile* oat_file = oat_dex_file->GetOatFile(); |
| 83 | CHECK(oat_file != nullptr); |
| 84 | |
| 85 | const char* cmd_line = oat_file->GetOatHeader().GetStoreValueByKey(OatHeader::kDex2OatCmdLineKey); |
| 86 | CHECK(cmd_line != nullptr); // Huh? This should not happen. |
| 87 | |
| 88 | // Check the backend. |
| 89 | constexpr const char* kCompilerBackend = "--compiler-backend="; |
| 90 | const char* backend = strstr(cmd_line, kCompilerBackend); |
| 91 | if (backend != nullptr) { |
| 92 | // If it's set, make sure it's optimizing. |
| 93 | backend += strlen(kCompilerBackend); |
| 94 | if (strncmp(backend, "Optimizing", strlen("Optimizing")) != 0) { |
| 95 | return JNI_FALSE; |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | // Check the filter. |
| 100 | constexpr const char* kCompilerFilter = "--compiler-filter="; |
| 101 | const char* filter = strstr(cmd_line, kCompilerFilter); |
| 102 | if (filter != nullptr) { |
| 103 | // If it's set, make sure it's not interpret-only|verify-none|verify-at-runtime. |
| 104 | // Note: The space filter might have an impact on the test, but ignore that for now. |
| 105 | filter += strlen(kCompilerFilter); |
| 106 | constexpr const char* kInterpretOnly = "interpret-only"; |
| 107 | constexpr const char* kVerifyNone = "verify-none"; |
| 108 | constexpr const char* kVerifyAtRuntime = "verify-at-runtime"; |
| 109 | if (strncmp(filter, kInterpretOnly, strlen(kInterpretOnly)) == 0 || |
| 110 | strncmp(filter, kVerifyNone, strlen(kVerifyNone)) == 0 || |
| 111 | strncmp(filter, kVerifyAtRuntime, strlen(kVerifyAtRuntime)) == 0) { |
| 112 | return JNI_FALSE; |
| 113 | } |
| 114 | } |
| 115 | |
| 116 | return JNI_TRUE; |
| 117 | } |
| 118 | |
Andreas Gampe | 89df7bf | 2015-09-30 13:13:21 -0700 | [diff] [blame] | 119 | } // namespace art |