blob: 54d12401feee4ad6f2b459b61235eb7fb1506893 [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>
26class MANAGED ObjectArray : public Array {
27 public:
Mathieu Chartiercbb2d202013-11-14 17:45:16 -080028 static ObjectArray<T>* Alloc(Thread* self, Class* object_array_class, int32_t length,
29 gc::AllocatorType allocator_type)
30 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
31
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080032 static ObjectArray<T>* Alloc(Thread* self, Class* object_array_class, int32_t length)
33 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
34
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070035 T* Get(int32_t i) ALWAYS_INLINE SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080036
Sebastien Hertz6bdd8f42013-05-17 14:44:01 +020037 // Returns true if the object can be stored into the array. If not, throws
38 // an ArrayStoreException and returns false.
Mathieu Chartier4e305412014-02-19 10:54:44 -080039 // TODO fix thread safety analysis: should be SHARED_LOCKS_REQUIRED(Locks::mutator_lock_).
40 template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
41 bool CheckAssignable(T* object) NO_THREAD_SAFETY_ANALYSIS;
Sebastien Hertz6bdd8f42013-05-17 14:44:01 +020042
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070043 void Set(int32_t i, T* object) ALWAYS_INLINE SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +010044 // TODO fix thread safety analysis: should be SHARED_LOCKS_REQUIRED(Locks::mutator_lock_).
Mathieu Chartier4e305412014-02-19 10:54:44 -080045 template<bool kTransactionActive, bool kCheckTransaction = true,
46 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070047 void Set(int32_t i, T* object) ALWAYS_INLINE NO_THREAD_SAFETY_ANALYSIS;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080048
49 // Set element without bound and element type checks, to be used in limited
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +010050 // circumstances, such as during boot image writing.
51 // TODO fix thread safety analysis broken by the use of template. This should be
52 // SHARED_LOCKS_REQUIRED(Locks::mutator_lock_).
Mathieu Chartier4e305412014-02-19 10:54:44 -080053 template<bool kTransactionActive, bool kCheckTransaction = true,
54 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070055 void SetWithoutChecks(int32_t i, T* object) ALWAYS_INLINE NO_THREAD_SAFETY_ANALYSIS;
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +010056 // TODO fix thread safety analysis broken by the use of template. This should be
57 // SHARED_LOCKS_REQUIRED(Locks::mutator_lock_).
Mathieu Chartier4e305412014-02-19 10:54:44 -080058 template<bool kTransactionActive, bool kCheckTransaction = true,
59 VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070060 void SetWithoutChecksAndWriteBarrier(int32_t i, T* object) ALWAYS_INLINE
61 NO_THREAD_SAFETY_ANALYSIS;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080062
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070063 T* GetWithoutChecks(int32_t i) ALWAYS_INLINE SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080064
Ian Rogersef7d42f2014-01-06 12:55:46 -080065 // Copy src into this array (dealing with overlaps as memmove does) without assignability checks.
66 void AssignableMemmove(int32_t dst_pos, ObjectArray<T>* src, int32_t src_pos,
67 int32_t count) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080068
Ian Rogersef7d42f2014-01-06 12:55:46 -080069 // Copy src into this array assuming no overlap and without assignability checks.
70 void AssignableMemcpy(int32_t dst_pos, ObjectArray<T>* src, int32_t src_pos,
71 int32_t count) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
72
73 // Copy src into this array with assignability checks.
74 void AssignableCheckingMemcpy(int32_t dst_pos, ObjectArray<T>* src, int32_t src_pos,
75 int32_t count, bool throw_exception)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080076 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
77
78 ObjectArray<T>* CopyOf(Thread* self, int32_t new_length)
79 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
80
Mathieu Chartier407f7022014-02-18 14:37:05 -080081 // TODO fix thread safety analysis broken by the use of template. This should be
82 // SHARED_LOCKS_REQUIRED(Locks::mutator_lock_).
83 template<const bool kVisitClass, typename Visitor>
84 void VisitReferences(const Visitor& visitor) NO_THREAD_SAFETY_ANALYSIS;
85
Ian Rogersef7d42f2014-01-06 12:55:46 -080086 static MemberOffset OffsetOfElement(int32_t i);
87
Andreas Gampe9c3b0892014-04-24 17:33:34 +000088 private:
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080089 DISALLOW_IMPLICIT_CONSTRUCTORS(ObjectArray);
90};
91
92} // namespace mirror
93} // namespace art
94
Brian Carlstromfc0e3212013-07-17 14:40:12 -070095#endif // ART_RUNTIME_MIRROR_OBJECT_ARRAY_H_