blob: b7a956176f7d3f85e77d4862e32c4c652a815a9b [file] [log] [blame]
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001/*
2 * Copyright (C) 2011 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
Brian Carlstromfc0e3212013-07-17 14:40:12 -070017#ifndef ART_RUNTIME_MIRROR_OBJECT_ARRAY_H_
18#define ART_RUNTIME_MIRROR_OBJECT_ARRAY_H_
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080019
20#include "array.h"
Mathieu Chartier1a5337f2016-10-13 13:48:23 -070021#include "obj_ptr.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080022
23namespace art {
24namespace mirror {
25
26template<class T>
Mingyao Yang98d1cc82014-05-15 17:02:16 -070027class MANAGED ObjectArray: public Array {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080028 public:
Mingyao Yang98d1cc82014-05-15 17:02:16 -070029 // The size of Object[].class.
Andreas Gampe542451c2016-07-26 09:02:02 -070030 static uint32_t ClassSize(PointerSize pointer_size) {
Mathieu Chartiere401d142015-04-22 13:56:20 -070031 return Array::ClassSize(pointer_size);
Mingyao Yang98d1cc82014-05-15 17:02:16 -070032 }
33
Mathieu Chartier1a5337f2016-10-13 13:48:23 -070034 static ObjectArray<T>* Alloc(Thread* self,
35 ObjPtr<Class> object_array_class,
36 int32_t length,
Mathieu Chartiercbb2d202013-11-14 17:45:16 -080037 gc::AllocatorType allocator_type)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070038 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!Roles::uninterruptible_);
Mathieu Chartiercbb2d202013-11-14 17:45:16 -080039
Mathieu Chartier1a5337f2016-10-13 13:48:23 -070040 static ObjectArray<T>* Alloc(Thread* self,
41 ObjPtr<Class> object_array_class,
42 int32_t length)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070043 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!Roles::uninterruptible_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080044
Mathieu Chartierfbc31082016-01-24 11:59:56 -080045 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
46 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070047 ALWAYS_INLINE T* Get(int32_t i) REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080048
Sebastien Hertz6bdd8f42013-05-17 14:44:01 +020049 // Returns true if the object can be stored into the array. If not, throws
50 // an ArrayStoreException and returns false.
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070051 // TODO fix thread safety analysis: should be REQUIRES_SHARED(Locks::mutator_lock_).
Mathieu Chartier4e305412014-02-19 10:54:44 -080052 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mathieu Chartier1a5337f2016-10-13 13:48:23 -070053 bool CheckAssignable(ObjPtr<T> object) NO_THREAD_SAFETY_ANALYSIS;
Sebastien Hertz6bdd8f42013-05-17 14:44:01 +020054
Mathieu Chartier1a5337f2016-10-13 13:48:23 -070055 ALWAYS_INLINE void Set(int32_t i, ObjPtr<T> object) REQUIRES_SHARED(Locks::mutator_lock_);
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070056 // TODO fix thread safety analysis: should be REQUIRES_SHARED(Locks::mutator_lock_).
Mathieu Chartier4e305412014-02-19 10:54:44 -080057 template<bool kTransactionActive, bool kCheckTransaction = true,
58 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mathieu Chartier1a5337f2016-10-13 13:48:23 -070059 ALWAYS_INLINE void Set(int32_t i, ObjPtr<T> object) NO_THREAD_SAFETY_ANALYSIS;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080060
61 // Set element without bound and element type checks, to be used in limited
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +010062 // circumstances, such as during boot image writing.
63 // TODO fix thread safety analysis broken by the use of template. This should be
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070064 // REQUIRES_SHARED(Locks::mutator_lock_).
Mathieu Chartier4e305412014-02-19 10:54:44 -080065 template<bool kTransactionActive, bool kCheckTransaction = true,
66 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mathieu Chartier1a5337f2016-10-13 13:48:23 -070067 ALWAYS_INLINE void SetWithoutChecks(int32_t i, ObjPtr<T> object) NO_THREAD_SAFETY_ANALYSIS;
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +010068 // TODO fix thread safety analysis broken by the use of template. This should be
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070069 // REQUIRES_SHARED(Locks::mutator_lock_).
Mathieu Chartier4e305412014-02-19 10:54:44 -080070 template<bool kTransactionActive, bool kCheckTransaction = true,
71 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mathieu Chartier1a5337f2016-10-13 13:48:23 -070072 ALWAYS_INLINE void SetWithoutChecksAndWriteBarrier(int32_t i, ObjPtr<T> object)
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070073 NO_THREAD_SAFETY_ANALYSIS;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080074
Hiroshi Yamauchie43b80e2016-11-14 13:42:50 -080075 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
76 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
Andreas Gampebdf7f1c2016-08-30 16:38:47 -070077 ALWAYS_INLINE T* GetWithoutChecks(int32_t i) REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080078
Ian Rogersef7d42f2014-01-06 12:55:46 -080079 // Copy src into this array (dealing with overlaps as memmove does) without assignability checks.
Mathieu Chartier1a5337f2016-10-13 13:48:23 -070080 void AssignableMemmove(int32_t dst_pos,
81 ObjPtr<ObjectArray<T>> src,
82 int32_t src_pos,
83 int32_t count)
84 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080085
Ian Rogersef7d42f2014-01-06 12:55:46 -080086 // Copy src into this array assuming no overlap and without assignability checks.
Mathieu Chartier1a5337f2016-10-13 13:48:23 -070087 void AssignableMemcpy(int32_t dst_pos,
88 ObjPtr<ObjectArray<T>> src,
89 int32_t src_pos,
90 int32_t count)
91 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogersef7d42f2014-01-06 12:55:46 -080092
93 // Copy src into this array with assignability checks.
Andreas Gampe85a098a2016-03-31 13:30:53 -070094 template<bool kTransactionActive>
Mathieu Chartier1a5337f2016-10-13 13:48:23 -070095 void AssignableCheckingMemcpy(int32_t dst_pos,
96 ObjPtr<ObjectArray<T>> src,
97 int32_t src_pos,
98 int32_t count,
99 bool throw_exception)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700100 REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800101
102 ObjectArray<T>* CopyOf(Thread* self, int32_t new_length)
Mathieu Chartier1a5337f2016-10-13 13:48:23 -0700103 REQUIRES_SHARED(Locks::mutator_lock_)
104 REQUIRES(!Roles::uninterruptible_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800105
Ian Rogersef7d42f2014-01-06 12:55:46 -0800106 static MemberOffset OffsetOfElement(int32_t i);
107
Andreas Gampe9c3b0892014-04-24 17:33:34 +0000108 private:
Mathieu Chartier059ef3d2015-08-18 13:54:21 -0700109 // TODO fix thread safety analysis broken by the use of template. This should be
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700110 // REQUIRES_SHARED(Locks::mutator_lock_).
Mathieu Chartier059ef3d2015-08-18 13:54:21 -0700111 template<typename Visitor>
112 void VisitReferences(const Visitor& visitor) NO_THREAD_SAFETY_ANALYSIS;
113
114 friend class Object; // For VisitReferences
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800115 DISALLOW_IMPLICIT_CONSTRUCTORS(ObjectArray);
116};
117
118} // namespace mirror
119} // namespace art
120
Brian Carlstromfc0e3212013-07-17 14:40:12 -0700121#endif // ART_RUNTIME_MIRROR_OBJECT_ARRAY_H_