blob: f88e81dc61b2cb9f22f8805fca1a35407f310ea4 [file] [log] [blame]
Elliott Hughes0f3c5532012-03-30 14:51:51 -07001/*
2 * Copyright (C) 2012 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 */
buzbee54330722011-08-23 16:46:55 -070016
Ian Rogers7655f292013-07-29 11:07:13 -070017#ifndef ART_RUNTIME_ENTRYPOINTS_ENTRYPOINT_UTILS_H_
18#define ART_RUNTIME_ENTRYPOINTS_ENTRYPOINT_UTILS_H_
Ian Rogers450dcb52013-09-20 17:36:02 -070019
Mingyao Yang98d1cc82014-05-15 17:02:16 -070020#include <jni.h>
21#include <stdint.h>
22
Ian Rogers450dcb52013-09-20 17:36:02 -070023#include "base/macros.h"
Mingyao Yang98d1cc82014-05-15 17:02:16 -070024#include "base/mutex.h"
Ian Rogers832336b2014-10-08 15:35:22 -070025#include "dex_instruction.h"
Mingyao Yang98d1cc82014-05-15 17:02:16 -070026#include "gc/allocator_type.h"
Elliott Hughes0f3c5532012-03-30 14:51:51 -070027#include "invoke_type.h"
Mingyao Yang98d1cc82014-05-15 17:02:16 -070028#include "jvalue.h"
Nicolas Geoffray1920c102015-09-29 18:00:03 +000029#include "runtime.h"
Ian Rogers57b86d42012-03-27 16:05:41 -070030
Shih-wei Liao2d831012011-09-28 22:06:53 -070031namespace art {
Ian Rogers848871b2013-08-05 10:56:33 -070032
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080033namespace mirror {
Mingyao Yang98d1cc82014-05-15 17:02:16 -070034 class Array;
Mathieu Chartierc7853442015-03-27 14:35:38 -070035 class Class;
Ian Rogers848871b2013-08-05 10:56:33 -070036 class Object;
Mingyao Yang98d1cc82014-05-15 17:02:16 -070037 class String;
Ian Rogers848871b2013-08-05 10:56:33 -070038} // namespace mirror
Ian Rogers57b86d42012-03-27 16:05:41 -070039
Mathieu Chartierc7853442015-03-27 14:35:38 -070040class ArtField;
Mathieu Chartiere401d142015-04-22 13:56:20 -070041class ArtMethod;
Nicolas Geoffray524e7ea2015-10-16 17:13:34 +010042class OatQuickMethodHeader;
Mingyao Yang98d1cc82014-05-15 17:02:16 -070043class ScopedObjectAccessAlreadyRunnable;
44class Thread;
45
Mathieu Chartiercbb2d202013-11-14 17:45:16 -080046template <const bool kAccessCheck>
Andreas Gampe9f612ff2014-11-24 13:42:22 -080047ALWAYS_INLINE inline mirror::Class* CheckObjectAlloc(uint32_t type_idx,
Mathieu Chartiere401d142015-04-22 13:56:20 -070048 ArtMethod* method,
Andreas Gampe9f612ff2014-11-24 13:42:22 -080049 Thread* self, bool* slow_path)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070050 REQUIRES_SHARED(Locks::mutator_lock_);
Hiroshi Yamauchi3b4c1892013-09-12 21:33:12 -070051
Andreas Gampe9f612ff2014-11-24 13:42:22 -080052ALWAYS_INLINE inline mirror::Class* CheckClassInitializedForObjectAlloc(mirror::Class* klass,
53 Thread* self,
54 bool* slow_path)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070055 REQUIRES_SHARED(Locks::mutator_lock_);
Hiroshi Yamauchibe1ca552014-01-15 11:46:48 -080056
Ian Rogers57b86d42012-03-27 16:05:41 -070057// Given the context of a calling Method, use its DexCache to resolve a type to a Class. If it
58// cannot be resolved, throw an error. If it can, use it to create an instance.
59// When verification/compiler hasn't been able to verify access, optionally perform an access
60// check.
Mathieu Chartiercbb2d202013-11-14 17:45:16 -080061template <bool kAccessCheck, bool kInstrumented>
Andreas Gampe9f612ff2014-11-24 13:42:22 -080062ALWAYS_INLINE inline mirror::Object* AllocObjectFromCode(uint32_t type_idx,
Mathieu Chartiere401d142015-04-22 13:56:20 -070063 ArtMethod* method,
Andreas Gampe9f612ff2014-11-24 13:42:22 -080064 Thread* self,
65 gc::AllocatorType allocator_type)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070066 REQUIRES_SHARED(Locks::mutator_lock_);
Hiroshi Yamauchi3b4c1892013-09-12 21:33:12 -070067
Hiroshi Yamauchibe1ca552014-01-15 11:46:48 -080068// Given the context of a calling Method and a resolved class, create an instance.
Hiroshi Yamauchibe1ca552014-01-15 11:46:48 -080069template <bool kInstrumented>
Andreas Gampe9f612ff2014-11-24 13:42:22 -080070ALWAYS_INLINE inline mirror::Object* AllocObjectFromCodeResolved(mirror::Class* klass,
71 Thread* self,
72 gc::AllocatorType allocator_type)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070073 REQUIRES_SHARED(Locks::mutator_lock_);
Hiroshi Yamauchibe1ca552014-01-15 11:46:48 -080074
75// Given the context of a calling Method and an initialized class, create an instance.
Hiroshi Yamauchibe1ca552014-01-15 11:46:48 -080076template <bool kInstrumented>
Andreas Gampe9f612ff2014-11-24 13:42:22 -080077ALWAYS_INLINE inline mirror::Object* AllocObjectFromCodeInitialized(mirror::Class* klass,
78 Thread* self,
79 gc::AllocatorType allocator_type)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070080 REQUIRES_SHARED(Locks::mutator_lock_);
Hiroshi Yamauchibe1ca552014-01-15 11:46:48 -080081
82
Mathieu Chartiercbb2d202013-11-14 17:45:16 -080083template <bool kAccessCheck>
Andreas Gampe9f612ff2014-11-24 13:42:22 -080084ALWAYS_INLINE inline mirror::Class* CheckArrayAlloc(uint32_t type_idx,
Andreas Gampe9f612ff2014-11-24 13:42:22 -080085 int32_t component_count,
Mathieu Chartiere401d142015-04-22 13:56:20 -070086 ArtMethod* method,
Andreas Gampe9f612ff2014-11-24 13:42:22 -080087 bool* slow_path)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070088 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers57b86d42012-03-27 16:05:41 -070089
90// Given the context of a calling Method, use its DexCache to resolve a type to an array Class. If
91// it cannot be resolved, throw an error. If it can, use it to create an array.
92// When verification/compiler hasn't been able to verify access, optionally perform an access
93// check.
Mathieu Chartiercbb2d202013-11-14 17:45:16 -080094template <bool kAccessCheck, bool kInstrumented>
Andreas Gampe9f612ff2014-11-24 13:42:22 -080095ALWAYS_INLINE inline mirror::Array* AllocArrayFromCode(uint32_t type_idx,
Andreas Gampe9f612ff2014-11-24 13:42:22 -080096 int32_t component_count,
Mathieu Chartiere401d142015-04-22 13:56:20 -070097 ArtMethod* method,
Andreas Gampe9f612ff2014-11-24 13:42:22 -080098 Thread* self,
99 gc::AllocatorType allocator_type)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700100 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers57b86d42012-03-27 16:05:41 -0700101
Hiroshi Yamauchibb8f0ab2014-01-27 16:50:29 -0800102template <bool kAccessCheck, bool kInstrumented>
Andreas Gampe9f612ff2014-11-24 13:42:22 -0800103ALWAYS_INLINE inline mirror::Array* AllocArrayFromCodeResolved(mirror::Class* klass,
Andreas Gampe9f612ff2014-11-24 13:42:22 -0800104 int32_t component_count,
Mathieu Chartiere401d142015-04-22 13:56:20 -0700105 ArtMethod* method,
Andreas Gampe9f612ff2014-11-24 13:42:22 -0800106 Thread* self,
107 gc::AllocatorType allocator_type)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700108 REQUIRES_SHARED(Locks::mutator_lock_);
Hiroshi Yamauchibb8f0ab2014-01-27 16:50:29 -0800109
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800110extern mirror::Array* CheckAndAllocArrayFromCode(uint32_t type_idx, int32_t component_count,
Mathieu Chartiere401d142015-04-22 13:56:20 -0700111 ArtMethod* method, Thread* self,
Mathieu Chartiercbb2d202013-11-14 17:45:16 -0800112 bool access_check,
113 gc::AllocatorType allocator_type)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700114 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers57b86d42012-03-27 16:05:41 -0700115
Mathieu Chartiercbb2d202013-11-14 17:45:16 -0800116extern mirror::Array* CheckAndAllocArrayFromCodeInstrumented(uint32_t type_idx,
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800117 int32_t component_count,
Mathieu Chartiere401d142015-04-22 13:56:20 -0700118 ArtMethod* method,
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800119 Thread* self,
Mathieu Chartiercbb2d202013-11-14 17:45:16 -0800120 bool access_check,
121 gc::AllocatorType allocator_type)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700122 REQUIRES_SHARED(Locks::mutator_lock_);
Hiroshi Yamauchi3b4c1892013-09-12 21:33:12 -0700123
Ian Rogers08f753d2012-08-24 14:35:25 -0700124// Type of find field operation for fast and slow case.
125enum FindFieldType {
126 InstanceObjectRead,
127 InstanceObjectWrite,
128 InstancePrimitiveRead,
129 InstancePrimitiveWrite,
130 StaticObjectRead,
131 StaticObjectWrite,
132 StaticPrimitiveRead,
133 StaticPrimitiveWrite,
134};
135
Sebastien Hertzd4beb6b2013-10-02 17:07:20 +0200136template<FindFieldType type, bool access_check>
Mathieu Chartiere401d142015-04-22 13:56:20 -0700137inline ArtField* FindFieldFromCode(
138 uint32_t field_idx, ArtMethod* referrer, Thread* self, size_t expected_size)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700139 REQUIRES_SHARED(Locks::mutator_lock_);
Sebastien Hertzd4beb6b2013-10-02 17:07:20 +0200140
141template<InvokeType type, bool access_check>
Mathieu Chartiere401d142015-04-22 13:56:20 -0700142inline ArtMethod* FindMethodFromCode(
Andreas Gampe3a357142015-08-07 17:20:11 -0700143 uint32_t method_idx, mirror::Object** this_object, ArtMethod* referrer, Thread* self)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700144 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers57b86d42012-03-27 16:05:41 -0700145
Ian Rogers08f753d2012-08-24 14:35:25 -0700146// Fast path field resolution that can't initialize classes or throw exceptions.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700147inline ArtField* FindFieldFast(
148 uint32_t field_idx, ArtMethod* referrer, FindFieldType type, size_t expected_size)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700149 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers57b86d42012-03-27 16:05:41 -0700150
Ian Rogers08f753d2012-08-24 14:35:25 -0700151// Fast path method resolution that can't throw exceptions.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700152inline ArtMethod* FindMethodFast(
153 uint32_t method_idx, mirror::Object* this_object, ArtMethod* referrer, bool access_check,
154 InvokeType type)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700155 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers57b86d42012-03-27 16:05:41 -0700156
Mathieu Chartiere401d142015-04-22 13:56:20 -0700157inline mirror::Class* ResolveVerifyAndClinit(
158 uint32_t type_idx, ArtMethod* referrer, Thread* self, bool can_run_clinit, bool verify_access)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700159 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers57b86d42012-03-27 16:05:41 -0700160
Mathieu Chartiere401d142015-04-22 13:56:20 -0700161inline mirror::String* ResolveStringFromCode(ArtMethod* referrer, uint32_t string_idx)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700162 REQUIRES_SHARED(Locks::mutator_lock_);
Shih-wei Liao2d831012011-09-28 22:06:53 -0700163
Ian Rogerse5877a12014-07-16 12:06:35 -0700164// TODO: annotalysis disabled as monitor semantics are maintained in Java code.
Andreas Gampe9f612ff2014-11-24 13:42:22 -0800165inline void UnlockJniSynchronizedMethod(jobject locked, Thread* self)
Ian Rogerse5877a12014-07-16 12:06:35 -0700166 NO_THREAD_SAFETY_ANALYSIS;
TDYa1273d71d802012-08-15 03:47:03 -0700167
Ian Rogerse5877a12014-07-16 12:06:35 -0700168void CheckReferenceResult(mirror::Object* o, Thread* self)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700169 REQUIRES_SHARED(Locks::mutator_lock_);
TDYa1273d71d802012-08-15 03:47:03 -0700170
Mathieu Chartier2b7c4d12014-05-19 10:52:16 -0700171JValue InvokeProxyInvocationHandler(ScopedObjectAccessAlreadyRunnable& soa, const char* shorty,
Brian Carlstromea46f952013-07-30 01:26:50 -0700172 jobject rcvr_jobj, jobject interface_art_method_jobj,
Ian Rogersaf6e67a2013-01-16 08:38:37 -0800173 std::vector<jvalue>& args)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700174 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogersaf6e67a2013-01-16 08:38:37 -0800175
Ian Rogers832336b2014-10-08 15:35:22 -0700176bool FillArrayData(mirror::Object* obj, const Instruction::ArrayDataPayload* payload)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700177 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers832336b2014-10-08 15:35:22 -0700178
Ian Rogers450dcb52013-09-20 17:36:02 -0700179template <typename INT_TYPE, typename FLOAT_TYPE>
Andreas Gampe9f612ff2014-11-24 13:42:22 -0800180inline INT_TYPE art_float_to_integral(FLOAT_TYPE f);
Ian Rogers450dcb52013-09-20 17:36:02 -0700181
Nicolas Geoffray1920c102015-09-29 18:00:03 +0000182ArtMethod* GetCalleeSaveMethodCaller(ArtMethod** sp,
183 Runtime::CalleeSaveType type,
184 bool do_caller_check = false);
185
Shih-wei Liao2d831012011-09-28 22:06:53 -0700186} // namespace art
Ian Rogersad42e132011-09-17 20:23:33 -0700187
Ian Rogers7655f292013-07-29 11:07:13 -0700188#endif // ART_RUNTIME_ENTRYPOINTS_ENTRYPOINT_UTILS_H_