1 /*
2  * Copyright (C) 2017 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 "dex/dex_file.h"
18 
19 #include "art_method-inl.h"
20 #include "dex/method_reference.h"
21 #include "jit/jit.h"
22 #include "jit/jit_code_cache.h"
23 #include "jni.h"
24 #include "mirror/class-inl.h"
25 #include "mirror/executable.h"
26 #include "runtime.h"
27 #include "scoped_thread_state_change-inl.h"
28 #include "thread.h"
29 
30 namespace art {
31 namespace {
32 
Java_Main_testCompiled(JNIEnv * env,jclass,jobject method)33 extern "C" JNIEXPORT jboolean JNICALL Java_Main_testCompiled(JNIEnv* env,
34                                                              jclass,
35                                                              jobject method) {
36   CHECK(method != nullptr);
37   ScopedObjectAccess soa(env);
38   ObjPtr<mirror::Executable> exec = soa.Decode<mirror::Executable>(method);
39   ArtMethod* art_method = exec->GetArtMethod();
40 
41   if (art_method->IsNative() || !art_method->IsInvokable() || art_method->IsProxyMethod()) {
42     return JNI_FALSE;
43   }
44 
45   // Check whether the JIT has compiled it.
46   Runtime* runtime = Runtime::Current();
47   jit::Jit* jit = runtime->GetJit();
48   if (jit != nullptr && jit->GetCodeCache()->ContainsMethod(art_method)) {
49     return JNI_TRUE;
50   }
51 
52   // Check whether we have AOT code.
53   return art_method->GetOatMethodQuickCode(kRuntimePointerSize) != nullptr ? JNI_TRUE : JNI_FALSE;
54 }
55 
56 }  // namespace
57 }  // namespace art
58