Vladimir Marko | 7624d25 | 2014-05-02 14:40:15 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 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 | #ifndef ART_RUNTIME_RUNTIME_INL_H_ |
| 18 | #define ART_RUNTIME_RUNTIME_INL_H_ |
| 19 | |
| 20 | #include "runtime.h" |
| 21 | |
Vladimir Marko | d3083dd | 2018-05-17 08:43:47 +0100 | [diff] [blame] | 22 | #include "arch/instruction_set.h" |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 23 | #include "art_method.h" |
Andreas Gampe | 8228cdf | 2017-05-30 15:03:54 -0700 | [diff] [blame] | 24 | #include "base/callee_save_type.h" |
Vladimir Marko | 78baed5 | 2018-10-11 10:44:58 +0100 | [diff] [blame] | 25 | #include "base/casts.h" |
Andreas Gampe | 44f6760 | 2018-11-28 08:27:27 -0800 | [diff] [blame] | 26 | #include "base/mutex.h" |
Vladimir Marko | d3083dd | 2018-05-17 08:43:47 +0100 | [diff] [blame] | 27 | #include "entrypoints/quick/callee_save_frame.h" |
Andreas Gampe | c15a2f4 | 2017-04-21 12:09:39 -0700 | [diff] [blame] | 28 | #include "gc_root-inl.h" |
David Srbecky | 28f6cff | 2018-10-16 15:07:28 +0100 | [diff] [blame] | 29 | #include "interpreter/mterp/mterp.h" |
Mathieu Chartier | 8778c52 | 2016-10-04 19:06:30 -0700 | [diff] [blame] | 30 | #include "obj_ptr-inl.h" |
David Srbecky | 817a47f | 2019-01-08 14:05:37 +0000 | [diff] [blame^] | 31 | #include "scoped_thread_state_change-inl.h" |
David Srbecky | 28f6cff | 2018-10-16 15:07:28 +0100 | [diff] [blame] | 32 | #include "thread_list.h" |
Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 33 | |
Vladimir Marko | 7624d25 | 2014-05-02 14:40:15 +0100 | [diff] [blame] | 34 | namespace art { |
| 35 | |
Mathieu Chartier | 8778c52 | 2016-10-04 19:06:30 -0700 | [diff] [blame] | 36 | inline bool Runtime::IsClearedJniWeakGlobal(ObjPtr<mirror::Object> obj) { |
Ian Rogers | c0542af | 2014-09-03 16:16:56 -0700 | [diff] [blame] | 37 | return obj == GetClearedJniWeakGlobal(); |
| 38 | } |
| 39 | |
| 40 | inline mirror::Object* Runtime::GetClearedJniWeakGlobal() { |
| 41 | mirror::Object* obj = sentinel_.Read(); |
Hiroshi Yamauchi | 8a74117 | 2014-09-08 13:22:56 -0700 | [diff] [blame] | 42 | DCHECK(obj != nullptr); |
Ian Rogers | c0542af | 2014-09-03 16:16:56 -0700 | [diff] [blame] | 43 | return obj; |
| 44 | } |
| 45 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 46 | inline QuickMethodFrameInfo Runtime::GetRuntimeMethodFrameInfo(ArtMethod* method) { |
Vladimir Marko | 7624d25 | 2014-05-02 14:40:15 +0100 | [diff] [blame] | 47 | DCHECK(method != nullptr); |
Vladimir Marko | d3083dd | 2018-05-17 08:43:47 +0100 | [diff] [blame] | 48 | DCHECK_EQ(instruction_set_, kRuntimeISA); |
Vladimir Marko | 7624d25 | 2014-05-02 14:40:15 +0100 | [diff] [blame] | 49 | // Cannot be imt-conflict-method or resolution-method. |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 50 | DCHECK_NE(method, GetImtConflictMethod()); |
| 51 | DCHECK_NE(method, GetResolutionMethod()); |
Vladimir Marko | 7624d25 | 2014-05-02 14:40:15 +0100 | [diff] [blame] | 52 | // Don't use GetCalleeSaveMethod(), some tests don't set all callee save methods. |
Andreas Gampe | 8228cdf | 2017-05-30 15:03:54 -0700 | [diff] [blame] | 53 | if (method == GetCalleeSaveMethodUnchecked(CalleeSaveType::kSaveRefsAndArgs)) { |
Vladimir Marko | d3083dd | 2018-05-17 08:43:47 +0100 | [diff] [blame] | 54 | return RuntimeCalleeSaveFrame::GetMethodFrameInfo(CalleeSaveType::kSaveRefsAndArgs); |
Andreas Gampe | 8228cdf | 2017-05-30 15:03:54 -0700 | [diff] [blame] | 55 | } else if (method == GetCalleeSaveMethodUnchecked(CalleeSaveType::kSaveAllCalleeSaves)) { |
Vladimir Marko | d3083dd | 2018-05-17 08:43:47 +0100 | [diff] [blame] | 56 | return RuntimeCalleeSaveFrame::GetMethodFrameInfo(CalleeSaveType::kSaveAllCalleeSaves); |
Andreas Gampe | 8228cdf | 2017-05-30 15:03:54 -0700 | [diff] [blame] | 57 | } else if (method == GetCalleeSaveMethodUnchecked(CalleeSaveType::kSaveRefsOnly)) { |
Vladimir Marko | d3083dd | 2018-05-17 08:43:47 +0100 | [diff] [blame] | 58 | return RuntimeCalleeSaveFrame::GetMethodFrameInfo(CalleeSaveType::kSaveRefsOnly); |
Vladimir Marko | 952dbb1 | 2016-07-28 12:01:51 +0100 | [diff] [blame] | 59 | } else { |
Mingyao Yang | 0a87a65 | 2017-04-12 13:43:15 -0700 | [diff] [blame] | 60 | DCHECK(method == GetCalleeSaveMethodUnchecked(CalleeSaveType::kSaveEverything) || |
| 61 | method == GetCalleeSaveMethodUnchecked(CalleeSaveType::kSaveEverythingForClinit) || |
| 62 | method == GetCalleeSaveMethodUnchecked(CalleeSaveType::kSaveEverythingForSuspendCheck)); |
Vladimir Marko | d3083dd | 2018-05-17 08:43:47 +0100 | [diff] [blame] | 63 | return RuntimeCalleeSaveFrame::GetMethodFrameInfo(CalleeSaveType::kSaveEverything); |
Vladimir Marko | 7624d25 | 2014-05-02 14:40:15 +0100 | [diff] [blame] | 64 | } |
| 65 | } |
| 66 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 67 | inline ArtMethod* Runtime::GetResolutionMethod() { |
Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 68 | CHECK(HasResolutionMethod()); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 69 | return resolution_method_; |
Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 70 | } |
| 71 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 72 | inline ArtMethod* Runtime::GetImtConflictMethod() { |
Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 73 | CHECK(HasImtConflictMethod()); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 74 | return imt_conflict_method_; |
Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 75 | } |
| 76 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 77 | inline ArtMethod* Runtime::GetImtUnimplementedMethod() { |
| 78 | CHECK(imt_unimplemented_method_ != nullptr); |
| 79 | return imt_unimplemented_method_; |
Mathieu Chartier | 2d2621a | 2014-10-23 16:48:06 -0700 | [diff] [blame] | 80 | } |
| 81 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 82 | inline ArtMethod* Runtime::GetCalleeSaveMethod(CalleeSaveType type) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 83 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 84 | DCHECK(HasCalleeSaveMethod(type)); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 85 | return GetCalleeSaveMethodUnchecked(type); |
Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 86 | } |
| 87 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 88 | inline ArtMethod* Runtime::GetCalleeSaveMethodUnchecked(CalleeSaveType type) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 89 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Vladimir Marko | 78baed5 | 2018-10-11 10:44:58 +0100 | [diff] [blame] | 90 | return reinterpret_cast64<ArtMethod*>(callee_save_methods_[static_cast<size_t>(type)]); |
Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 91 | } |
| 92 | |
David Srbecky | 28f6cff | 2018-10-16 15:07:28 +0100 | [diff] [blame] | 93 | template<typename Action> |
David Srbecky | 817a47f | 2019-01-08 14:05:37 +0000 | [diff] [blame^] | 94 | void Runtime::DoAndMaybeSwitchInterpreter(Action lambda) { |
| 95 | Thread* self = Thread::Current(); |
| 96 | if (Runtime::Current()->IsShuttingDown(self) || Locks::mutator_lock_->IsExclusiveHeld(self)) { |
| 97 | MutexLock tll_mu(self, *Locks::thread_list_lock_); |
| 98 | lambda(); |
| 99 | Runtime::Current()->GetThreadList()->ForEach([](Thread* thread, void*) { |
| 100 | thread->tls32_.use_mterp.store(interpreter::CanUseMterp()); |
| 101 | }, nullptr); |
| 102 | } else { |
| 103 | ScopedThreadStateChange tsc(self, kSuspended); |
| 104 | ScopedSuspendAll ssa(__FUNCTION__); |
| 105 | MutexLock tll_mu(self, *Locks::thread_list_lock_); |
| 106 | lambda(); |
| 107 | Runtime::Current()->GetThreadList()->ForEach([](Thread* thread, void*) { |
| 108 | thread->tls32_.use_mterp.store(interpreter::CanUseMterp()); |
| 109 | }, nullptr); |
| 110 | } |
David Srbecky | 28f6cff | 2018-10-16 15:07:28 +0100 | [diff] [blame] | 111 | } |
| 112 | |
Vladimir Marko | 7624d25 | 2014-05-02 14:40:15 +0100 | [diff] [blame] | 113 | } // namespace art |
| 114 | |
| 115 | #endif // ART_RUNTIME_RUNTIME_INL_H_ |