blob: 42573968c9cee8bb6309f0a38c55b1f98fe34888 [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"
21
22namespace art {
23namespace mirror {
24
25template<class T>
Mingyao Yang98d1cc82014-05-15 17:02:16 -070026class MANAGED ObjectArray: public Array {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080027 public:
Mingyao Yang98d1cc82014-05-15 17:02:16 -070028 // The size of Object[].class.
Mathieu Chartiere401d142015-04-22 13:56:20 -070029 static uint32_t ClassSize(size_t pointer_size) {
30 return Array::ClassSize(pointer_size);
Mingyao Yang98d1cc82014-05-15 17:02:16 -070031 }
32
Mathieu Chartiercbb2d202013-11-14 17:45:16 -080033 static ObjectArray<T>* Alloc(Thread* self, Class* object_array_class, int32_t length,
34 gc::AllocatorType allocator_type)
Mathieu Chartier4e2cb092015-07-22 16:17:51 -070035 SHARED_REQUIRES(Locks::mutator_lock_) REQUIRES(!Roles::uninterruptible_);
Mathieu Chartiercbb2d202013-11-14 17:45:16 -080036
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080037 static ObjectArray<T>* Alloc(Thread* self, Class* object_array_class, int32_t length)
Mathieu Chartier4e2cb092015-07-22 16:17:51 -070038 SHARED_REQUIRES(Locks::mutator_lock_) REQUIRES(!Roles::uninterruptible_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080039
Mathieu Chartierfbc31082016-01-24 11:59:56 -080040 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
41 ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
42 ALWAYS_INLINE T* Get(int32_t i) SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080043
Sebastien Hertz6bdd8f42013-05-17 14:44:01 +020044 // Returns true if the object can be stored into the array. If not, throws
45 // an ArrayStoreException and returns false.
Mathieu Chartier90443472015-07-16 20:32:27 -070046 // TODO fix thread safety analysis: should be SHARED_REQUIRES(Locks::mutator_lock_).
Mathieu Chartier4e305412014-02-19 10:54:44 -080047 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
48 bool CheckAssignable(T* object) NO_THREAD_SAFETY_ANALYSIS;
Sebastien Hertz6bdd8f42013-05-17 14:44:01 +020049
Mathieu Chartier90443472015-07-16 20:32:27 -070050 ALWAYS_INLINE void Set(int32_t i, T* object) SHARED_REQUIRES(Locks::mutator_lock_);
51 // TODO fix thread safety analysis: should be SHARED_REQUIRES(Locks::mutator_lock_).
Mathieu Chartier4e305412014-02-19 10:54:44 -080052 template<bool kTransactionActive, bool kCheckTransaction = true,
53 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mathieu Chartier2d2621a2014-10-23 16:48:06 -070054 ALWAYS_INLINE void Set(int32_t i, T* object) NO_THREAD_SAFETY_ANALYSIS;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080055
56 // Set element without bound and element type checks, to be used in limited
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +010057 // circumstances, such as during boot image writing.
58 // TODO fix thread safety analysis broken by the use of template. This should be
Mathieu Chartier90443472015-07-16 20:32:27 -070059 // SHARED_REQUIRES(Locks::mutator_lock_).
Mathieu Chartier4e305412014-02-19 10:54:44 -080060 template<bool kTransactionActive, bool kCheckTransaction = true,
61 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mathieu Chartier2d2621a2014-10-23 16:48:06 -070062 ALWAYS_INLINE void SetWithoutChecks(int32_t i, T* object) NO_THREAD_SAFETY_ANALYSIS;
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +010063 // TODO fix thread safety analysis broken by the use of template. This should be
Mathieu Chartier90443472015-07-16 20:32:27 -070064 // SHARED_REQUIRES(Locks::mutator_lock_).
Mathieu Chartier4e305412014-02-19 10:54:44 -080065 template<bool kTransactionActive, bool kCheckTransaction = true,
66 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mathieu Chartier2d2621a2014-10-23 16:48:06 -070067 ALWAYS_INLINE void SetWithoutChecksAndWriteBarrier(int32_t i, T* object)
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070068 NO_THREAD_SAFETY_ANALYSIS;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080069
Mathieu Chartier90443472015-07-16 20:32:27 -070070 ALWAYS_INLINE T* GetWithoutChecks(int32_t i) SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080071
Ian Rogersef7d42f2014-01-06 12:55:46 -080072 // Copy src into this array (dealing with overlaps as memmove does) without assignability checks.
73 void AssignableMemmove(int32_t dst_pos, ObjectArray<T>* src, int32_t src_pos,
Mathieu Chartier90443472015-07-16 20:32:27 -070074 int32_t count) SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080075
Ian Rogersef7d42f2014-01-06 12:55:46 -080076 // Copy src into this array assuming no overlap and without assignability checks.
77 void AssignableMemcpy(int32_t dst_pos, ObjectArray<T>* src, int32_t src_pos,
Mathieu Chartier90443472015-07-16 20:32:27 -070078 int32_t count) SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogersef7d42f2014-01-06 12:55:46 -080079
80 // Copy src into this array with assignability checks.
Andreas Gampe4a5fcd82016-03-31 13:30:53 -070081 template<bool kTransactionActive>
Ian Rogersef7d42f2014-01-06 12:55:46 -080082 void AssignableCheckingMemcpy(int32_t dst_pos, ObjectArray<T>* src, int32_t src_pos,
83 int32_t count, bool throw_exception)
Mathieu Chartier90443472015-07-16 20:32:27 -070084 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080085
86 ObjectArray<T>* CopyOf(Thread* self, int32_t new_length)
Mathieu Chartier4e2cb092015-07-22 16:17:51 -070087 SHARED_REQUIRES(Locks::mutator_lock_) REQUIRES(!Roles::uninterruptible_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080088
Ian Rogersef7d42f2014-01-06 12:55:46 -080089 static MemberOffset OffsetOfElement(int32_t i);
90
Andreas Gampe9c3b0892014-04-24 17:33:34 +000091 private:
Mathieu Chartier059ef3d2015-08-18 13:54:21 -070092 // TODO fix thread safety analysis broken by the use of template. This should be
93 // SHARED_REQUIRES(Locks::mutator_lock_).
94 template<typename Visitor>
95 void VisitReferences(const Visitor& visitor) NO_THREAD_SAFETY_ANALYSIS;
96
97 friend class Object; // For VisitReferences
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080098 DISALLOW_IMPLICIT_CONSTRUCTORS(ObjectArray);
99};
100
101} // namespace mirror
102} // namespace art
103
Brian Carlstromfc0e3212013-07-17 14:40:12 -0700104#endif // ART_RUNTIME_MIRROR_OBJECT_ARRAY_H_