blob: 2ffaf9810354d415aaf7a3bbc07bab9f02639886 [file] [log] [blame]
Vladimir Marko7624d252014-05-02 14:40:15 +01001/*
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 Markod3083dd2018-05-17 08:43:47 +010022#include "arch/instruction_set.h"
Mathieu Chartiere401d142015-04-22 13:56:20 -070023#include "art_method.h"
Andreas Gampe8228cdf2017-05-30 15:03:54 -070024#include "base/callee_save_type.h"
Vladimir Marko78baed52018-10-11 10:44:58 +010025#include "base/casts.h"
Andreas Gampe44f67602018-11-28 08:27:27 -080026#include "base/mutex.h"
Vladimir Markod3083dd2018-05-17 08:43:47 +010027#include "entrypoints/quick/callee_save_frame.h"
Andreas Gampec15a2f42017-04-21 12:09:39 -070028#include "gc_root-inl.h"
David Srbecky28f6cff2018-10-16 15:07:28 +010029#include "interpreter/mterp/mterp.h"
Mathieu Chartier8778c522016-10-04 19:06:30 -070030#include "obj_ptr-inl.h"
David Srbecky28f6cff2018-10-16 15:07:28 +010031#include "thread_list.h"
Ian Rogerse63db272014-07-15 15:36:11 -070032
Vladimir Marko7624d252014-05-02 14:40:15 +010033namespace art {
34
Mathieu Chartier8778c522016-10-04 19:06:30 -070035inline bool Runtime::IsClearedJniWeakGlobal(ObjPtr<mirror::Object> obj) {
Ian Rogersc0542af2014-09-03 16:16:56 -070036 return obj == GetClearedJniWeakGlobal();
37}
38
39inline mirror::Object* Runtime::GetClearedJniWeakGlobal() {
40 mirror::Object* obj = sentinel_.Read();
Hiroshi Yamauchi8a741172014-09-08 13:22:56 -070041 DCHECK(obj != nullptr);
Ian Rogersc0542af2014-09-03 16:16:56 -070042 return obj;
43}
44
Mathieu Chartiere401d142015-04-22 13:56:20 -070045inline QuickMethodFrameInfo Runtime::GetRuntimeMethodFrameInfo(ArtMethod* method) {
Vladimir Marko7624d252014-05-02 14:40:15 +010046 DCHECK(method != nullptr);
Vladimir Markod3083dd2018-05-17 08:43:47 +010047 DCHECK_EQ(instruction_set_, kRuntimeISA);
Vladimir Marko7624d252014-05-02 14:40:15 +010048 // Cannot be imt-conflict-method or resolution-method.
Mathieu Chartiere401d142015-04-22 13:56:20 -070049 DCHECK_NE(method, GetImtConflictMethod());
50 DCHECK_NE(method, GetResolutionMethod());
Vladimir Marko7624d252014-05-02 14:40:15 +010051 // Don't use GetCalleeSaveMethod(), some tests don't set all callee save methods.
Andreas Gampe8228cdf2017-05-30 15:03:54 -070052 if (method == GetCalleeSaveMethodUnchecked(CalleeSaveType::kSaveRefsAndArgs)) {
Vladimir Markod3083dd2018-05-17 08:43:47 +010053 return RuntimeCalleeSaveFrame::GetMethodFrameInfo(CalleeSaveType::kSaveRefsAndArgs);
Andreas Gampe8228cdf2017-05-30 15:03:54 -070054 } else if (method == GetCalleeSaveMethodUnchecked(CalleeSaveType::kSaveAllCalleeSaves)) {
Vladimir Markod3083dd2018-05-17 08:43:47 +010055 return RuntimeCalleeSaveFrame::GetMethodFrameInfo(CalleeSaveType::kSaveAllCalleeSaves);
Andreas Gampe8228cdf2017-05-30 15:03:54 -070056 } else if (method == GetCalleeSaveMethodUnchecked(CalleeSaveType::kSaveRefsOnly)) {
Vladimir Markod3083dd2018-05-17 08:43:47 +010057 return RuntimeCalleeSaveFrame::GetMethodFrameInfo(CalleeSaveType::kSaveRefsOnly);
Vladimir Marko952dbb12016-07-28 12:01:51 +010058 } else {
Mingyao Yang0a87a652017-04-12 13:43:15 -070059 DCHECK(method == GetCalleeSaveMethodUnchecked(CalleeSaveType::kSaveEverything) ||
60 method == GetCalleeSaveMethodUnchecked(CalleeSaveType::kSaveEverythingForClinit) ||
61 method == GetCalleeSaveMethodUnchecked(CalleeSaveType::kSaveEverythingForSuspendCheck));
Vladimir Markod3083dd2018-05-17 08:43:47 +010062 return RuntimeCalleeSaveFrame::GetMethodFrameInfo(CalleeSaveType::kSaveEverything);
Vladimir Marko7624d252014-05-02 14:40:15 +010063 }
64}
65
Mathieu Chartiere401d142015-04-22 13:56:20 -070066inline ArtMethod* Runtime::GetResolutionMethod() {
Ian Rogerse63db272014-07-15 15:36:11 -070067 CHECK(HasResolutionMethod());
Mathieu Chartiere401d142015-04-22 13:56:20 -070068 return resolution_method_;
Ian Rogerse63db272014-07-15 15:36:11 -070069}
70
Mathieu Chartiere401d142015-04-22 13:56:20 -070071inline ArtMethod* Runtime::GetImtConflictMethod() {
Ian Rogerse63db272014-07-15 15:36:11 -070072 CHECK(HasImtConflictMethod());
Mathieu Chartiere401d142015-04-22 13:56:20 -070073 return imt_conflict_method_;
Ian Rogerse63db272014-07-15 15:36:11 -070074}
75
Mathieu Chartiere401d142015-04-22 13:56:20 -070076inline ArtMethod* Runtime::GetImtUnimplementedMethod() {
77 CHECK(imt_unimplemented_method_ != nullptr);
78 return imt_unimplemented_method_;
Mathieu Chartier2d2621a2014-10-23 16:48:06 -070079}
80
Mathieu Chartiere401d142015-04-22 13:56:20 -070081inline ArtMethod* Runtime::GetCalleeSaveMethod(CalleeSaveType type)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070082 REQUIRES_SHARED(Locks::mutator_lock_) {
Ian Rogerse63db272014-07-15 15:36:11 -070083 DCHECK(HasCalleeSaveMethod(type));
Mathieu Chartiere401d142015-04-22 13:56:20 -070084 return GetCalleeSaveMethodUnchecked(type);
Ian Rogerse63db272014-07-15 15:36:11 -070085}
86
Mathieu Chartiere401d142015-04-22 13:56:20 -070087inline ArtMethod* Runtime::GetCalleeSaveMethodUnchecked(CalleeSaveType type)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070088 REQUIRES_SHARED(Locks::mutator_lock_) {
Vladimir Marko78baed52018-10-11 10:44:58 +010089 return reinterpret_cast64<ArtMethod*>(callee_save_methods_[static_cast<size_t>(type)]);
Ian Rogerse63db272014-07-15 15:36:11 -070090}
91
David Srbecky28f6cff2018-10-16 15:07:28 +010092template<typename Action>
David Srbeckyd3883902019-02-26 17:29:32 +000093void Runtime::DoAndMaybeSwitchInterpreter(Action lamda) {
94 MutexLock tll_mu(Thread::Current(), *Locks::thread_list_lock_);
95 lamda();
96 Runtime::Current()->GetThreadList()->ForEach([](Thread* thread, void*) {
97 thread->tls32_.use_mterp.store(interpreter::CanUseMterp());
98 }, nullptr);
David Srbecky28f6cff2018-10-16 15:07:28 +010099}
100
Vladimir Marko7624d252014-05-02 14:40:15 +0100101} // namespace art
102
103#endif // ART_RUNTIME_RUNTIME_INL_H_