osr.cc revision 891bc286963892ed96134ca1adb7822737af9710
1/* 2 * Copyright (C) 2016 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 "art_method.h" 18#include "jit/jit.h" 19#include "jit/jit_code_cache.h" 20#include "oat_quick_method_header.h" 21#include "scoped_thread_state_change.h" 22#include "stack_map.h" 23 24namespace art { 25 26class OsrVisitor : public StackVisitor { 27 public: 28 explicit OsrVisitor(Thread* thread) 29 SHARED_REQUIRES(Locks::mutator_lock_) 30 : StackVisitor(thread, nullptr, StackVisitor::StackWalkKind::kIncludeInlinedFrames), 31 in_osr_method_(false) {} 32 33 bool VisitFrame() SHARED_REQUIRES(Locks::mutator_lock_) { 34 ArtMethod* m = GetMethod(); 35 std::string m_name(m->GetName()); 36 37 if ((m_name.compare("$noinline$returnInt") == 0) || 38 (m_name.compare("$noinline$returnFloat") == 0) || 39 (m_name.compare("$noinline$returnDouble") == 0) || 40 (m_name.compare("$noinline$returnLong") == 0) || 41 (m_name.compare("$noinline$deopt") == 0)) { 42 const OatQuickMethodHeader* header = 43 Runtime::Current()->GetJit()->GetCodeCache()->LookupOsrMethodHeader(m); 44 if (header != nullptr && header == GetCurrentOatQuickMethodHeader()) { 45 in_osr_method_ = true; 46 } 47 return false; 48 } 49 return true; 50 } 51 52 bool in_osr_method_; 53}; 54 55extern "C" JNIEXPORT jboolean JNICALL Java_Main_ensureInOsrCode(JNIEnv*, jclass) { 56 jit::Jit* jit = Runtime::Current()->GetJit(); 57 if (jit == nullptr) { 58 // Just return true for non-jit configurations to stop the infinite loop. 59 return JNI_TRUE; 60 } 61 ScopedObjectAccess soa(Thread::Current()); 62 OsrVisitor visitor(soa.Self()); 63 visitor.WalkStack(); 64 return visitor.in_osr_method_; 65} 66 67} // namespace art 68