blob: 607b0004881f704e64a5fc9d6350db700281cf8d [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 Chartier90443472015-07-16 20:32:27 -070040 T* Get(int32_t i) ALWAYS_INLINE SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080041
Sebastien Hertz6bdd8f42013-05-17 14:44:01 +020042 // Returns true if the object can be stored into the array. If not, throws
43 // an ArrayStoreException and returns false.
Mathieu Chartier90443472015-07-16 20:32:27 -070044 // TODO fix thread safety analysis: should be SHARED_REQUIRES(Locks::mutator_lock_).
Mathieu Chartier4e305412014-02-19 10:54:44 -080045 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
46 bool CheckAssignable(T* object) NO_THREAD_SAFETY_ANALYSIS;
Sebastien Hertz6bdd8f42013-05-17 14:44:01 +020047
Mathieu Chartier90443472015-07-16 20:32:27 -070048 ALWAYS_INLINE void Set(int32_t i, T* object) SHARED_REQUIRES(Locks::mutator_lock_);
49 // TODO fix thread safety analysis: should be SHARED_REQUIRES(Locks::mutator_lock_).
Mathieu Chartier4e305412014-02-19 10:54:44 -080050 template<bool kTransactionActive, bool kCheckTransaction = true,
51 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mathieu Chartier2d2621a2014-10-23 16:48:06 -070052 ALWAYS_INLINE void Set(int32_t i, T* object) NO_THREAD_SAFETY_ANALYSIS;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080053
54 // Set element without bound and element type checks, to be used in limited
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +010055 // circumstances, such as during boot image writing.
56 // TODO fix thread safety analysis broken by the use of template. This should be
Mathieu Chartier90443472015-07-16 20:32:27 -070057 // SHARED_REQUIRES(Locks::mutator_lock_).
Mathieu Chartier4e305412014-02-19 10:54:44 -080058 template<bool kTransactionActive, bool kCheckTransaction = true,
59 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mathieu Chartier2d2621a2014-10-23 16:48:06 -070060 ALWAYS_INLINE void SetWithoutChecks(int32_t i, T* object) NO_THREAD_SAFETY_ANALYSIS;
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +010061 // TODO fix thread safety analysis broken by the use of template. This should be
Mathieu Chartier90443472015-07-16 20:32:27 -070062 // SHARED_REQUIRES(Locks::mutator_lock_).
Mathieu Chartier4e305412014-02-19 10:54:44 -080063 template<bool kTransactionActive, bool kCheckTransaction = true,
64 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Mathieu Chartier2d2621a2014-10-23 16:48:06 -070065 ALWAYS_INLINE void SetWithoutChecksAndWriteBarrier(int32_t i, T* object)
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070066 NO_THREAD_SAFETY_ANALYSIS;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080067
Mathieu Chartier90443472015-07-16 20:32:27 -070068 ALWAYS_INLINE T* GetWithoutChecks(int32_t i) SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080069
Ian Rogersef7d42f2014-01-06 12:55:46 -080070 // Copy src into this array (dealing with overlaps as memmove does) without assignability checks.
71 void AssignableMemmove(int32_t dst_pos, ObjectArray<T>* src, int32_t src_pos,
Mathieu Chartier90443472015-07-16 20:32:27 -070072 int32_t count) SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080073
Ian Rogersef7d42f2014-01-06 12:55:46 -080074 // Copy src into this array assuming no overlap and without assignability checks.
75 void AssignableMemcpy(int32_t dst_pos, ObjectArray<T>* src, int32_t src_pos,
Mathieu Chartier90443472015-07-16 20:32:27 -070076 int32_t count) SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogersef7d42f2014-01-06 12:55:46 -080077
78 // Copy src into this array with assignability checks.
79 void AssignableCheckingMemcpy(int32_t dst_pos, ObjectArray<T>* src, int32_t src_pos,
80 int32_t count, bool throw_exception)
Mathieu Chartier90443472015-07-16 20:32:27 -070081 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080082
83 ObjectArray<T>* CopyOf(Thread* self, int32_t new_length)
Mathieu Chartier4e2cb092015-07-22 16:17:51 -070084 SHARED_REQUIRES(Locks::mutator_lock_) REQUIRES(!Roles::uninterruptible_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080085
Mathieu Chartier407f7022014-02-18 14:37:05 -080086 // TODO fix thread safety analysis broken by the use of template. This should be
Mathieu Chartier90443472015-07-16 20:32:27 -070087 // SHARED_REQUIRES(Locks::mutator_lock_).
Mathieu Chartier407f7022014-02-18 14:37:05 -080088 template<const bool kVisitClass, typename Visitor>
89 void VisitReferences(const Visitor& visitor) NO_THREAD_SAFETY_ANALYSIS;
90
Ian Rogersef7d42f2014-01-06 12:55:46 -080091 static MemberOffset OffsetOfElement(int32_t i);
92
Andreas Gampe9c3b0892014-04-24 17:33:34 +000093 private:
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080094 DISALLOW_IMPLICIT_CONSTRUCTORS(ObjectArray);
95};
96
97} // namespace mirror
98} // namespace art
99
Brian Carlstromfc0e3212013-07-17 14:40:12 -0700100#endif // ART_RUNTIME_MIRROR_OBJECT_ARRAY_H_