Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 1 | /* |
| 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 Carlstrom | fc0e321 | 2013-07-17 14:40:12 -0700 | [diff] [blame] | 17 | #ifndef ART_RUNTIME_MIRROR_OBJECT_ARRAY_H_ |
| 18 | #define ART_RUNTIME_MIRROR_OBJECT_ARRAY_H_ |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 19 | |
| 20 | #include "array.h" |
| 21 | |
| 22 | namespace art { |
| 23 | namespace mirror { |
| 24 | |
| 25 | template<class T> |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 26 | class MANAGED ObjectArray: public Array { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 27 | public: |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 28 | // The size of Object[].class. |
| 29 | static uint32_t ClassSize() { |
| 30 | return Array::ClassSize(); |
| 31 | } |
| 32 | |
Mathieu Chartier | cbb2d20 | 2013-11-14 17:45:16 -0800 | [diff] [blame] | 33 | static ObjectArray<T>* Alloc(Thread* self, Class* object_array_class, int32_t length, |
| 34 | gc::AllocatorType allocator_type) |
| 35 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 36 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 37 | static ObjectArray<T>* Alloc(Thread* self, Class* object_array_class, int32_t length) |
| 38 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 39 | |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 40 | T* Get(int32_t i) ALWAYS_INLINE SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 41 | |
Sebastien Hertz | 6bdd8f4 | 2013-05-17 14:44:01 +0200 | [diff] [blame] | 42 | // Returns true if the object can be stored into the array. If not, throws |
| 43 | // an ArrayStoreException and returns false. |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 44 | // TODO fix thread safety analysis: should be SHARED_LOCKS_REQUIRED(Locks::mutator_lock_). |
| 45 | template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
| 46 | bool CheckAssignable(T* object) NO_THREAD_SAFETY_ANALYSIS; |
Sebastien Hertz | 6bdd8f4 | 2013-05-17 14:44:01 +0200 | [diff] [blame] | 47 | |
Mathieu Chartier | 2d2621a | 2014-10-23 16:48:06 -0700 | [diff] [blame^] | 48 | ALWAYS_INLINE void Set(int32_t i, T* object) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 49 | // TODO fix thread safety analysis: should be SHARED_LOCKS_REQUIRED(Locks::mutator_lock_). |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 50 | template<bool kTransactionActive, bool kCheckTransaction = true, |
| 51 | VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
Mathieu Chartier | 2d2621a | 2014-10-23 16:48:06 -0700 | [diff] [blame^] | 52 | ALWAYS_INLINE void Set(int32_t i, T* object) NO_THREAD_SAFETY_ANALYSIS; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 53 | |
| 54 | // Set element without bound and element type checks, to be used in limited |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 55 | // circumstances, such as during boot image writing. |
| 56 | // TODO fix thread safety analysis broken by the use of template. This should be |
| 57 | // SHARED_LOCKS_REQUIRED(Locks::mutator_lock_). |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 58 | template<bool kTransactionActive, bool kCheckTransaction = true, |
| 59 | VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
Mathieu Chartier | 2d2621a | 2014-10-23 16:48:06 -0700 | [diff] [blame^] | 60 | ALWAYS_INLINE void SetWithoutChecks(int32_t i, T* object) NO_THREAD_SAFETY_ANALYSIS; |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 61 | // TODO fix thread safety analysis broken by the use of template. This should be |
| 62 | // SHARED_LOCKS_REQUIRED(Locks::mutator_lock_). |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 63 | template<bool kTransactionActive, bool kCheckTransaction = true, |
| 64 | VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> |
Mathieu Chartier | 2d2621a | 2014-10-23 16:48:06 -0700 | [diff] [blame^] | 65 | ALWAYS_INLINE void SetWithoutChecksAndWriteBarrier(int32_t i, T* object) |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 66 | NO_THREAD_SAFETY_ANALYSIS; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 67 | |
Mathieu Chartier | 2d2621a | 2014-10-23 16:48:06 -0700 | [diff] [blame^] | 68 | ALWAYS_INLINE T* GetWithoutChecks(int32_t i) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 69 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 70 | // 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, |
| 72 | int32_t count) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 73 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 74 | // 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, |
| 76 | int32_t count) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 77 | |
| 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) |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 81 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 82 | |
| 83 | ObjectArray<T>* CopyOf(Thread* self, int32_t new_length) |
| 84 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 85 | |
Mathieu Chartier | 407f702 | 2014-02-18 14:37:05 -0800 | [diff] [blame] | 86 | // TODO fix thread safety analysis broken by the use of template. This should be |
| 87 | // SHARED_LOCKS_REQUIRED(Locks::mutator_lock_). |
| 88 | template<const bool kVisitClass, typename Visitor> |
| 89 | void VisitReferences(const Visitor& visitor) NO_THREAD_SAFETY_ANALYSIS; |
| 90 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 91 | static MemberOffset OffsetOfElement(int32_t i); |
| 92 | |
Andreas Gampe | 9c3b089 | 2014-04-24 17:33:34 +0000 | [diff] [blame] | 93 | private: |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 94 | DISALLOW_IMPLICIT_CONSTRUCTORS(ObjectArray); |
| 95 | }; |
| 96 | |
| 97 | } // namespace mirror |
| 98 | } // namespace art |
| 99 | |
Brian Carlstrom | fc0e321 | 2013-07-17 14:40:12 -0700 | [diff] [blame] | 100 | #endif // ART_RUNTIME_MIRROR_OBJECT_ARRAY_H_ |