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" |
Mathieu Chartier | cbb2d20 | 2013-11-14 17:45:16 -0800 | [diff] [blame] | 21 | #include "gc/heap.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 22 | |
| 23 | namespace art { |
| 24 | namespace mirror { |
| 25 | |
| 26 | template<class T> |
| 27 | class MANAGED ObjectArray : public Array { |
| 28 | public: |
Mathieu Chartier | cbb2d20 | 2013-11-14 17:45:16 -0800 | [diff] [blame] | 29 | static ObjectArray<T>* Alloc(Thread* self, Class* object_array_class, int32_t length, |
| 30 | gc::AllocatorType allocator_type) |
| 31 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 32 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 33 | static ObjectArray<T>* Alloc(Thread* self, Class* object_array_class, int32_t length) |
| 34 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 35 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 36 | T* Get(int32_t i) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 37 | |
Sebastien Hertz | 6bdd8f4 | 2013-05-17 14:44:01 +0200 | [diff] [blame] | 38 | // Returns true if the object can be stored into the array. If not, throws |
| 39 | // an ArrayStoreException and returns false. |
| 40 | bool CheckAssignable(T* object) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 41 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 42 | 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^] | 43 | // TODO fix thread safety analysis: should be SHARED_LOCKS_REQUIRED(Locks::mutator_lock_). |
| 44 | template<bool kTransactionActive, bool kCheckTransaction = true> |
| 45 | void Set(int32_t i, T* object) NO_THREAD_SAFETY_ANALYSIS; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 46 | |
| 47 | // 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^] | 48 | // circumstances, such as during boot image writing. |
| 49 | // TODO fix thread safety analysis broken by the use of template. This should be |
| 50 | // SHARED_LOCKS_REQUIRED(Locks::mutator_lock_). |
| 51 | template<bool kTransactionActive, bool kCheckTransaction = true> |
| 52 | void SetWithoutChecks(int32_t i, T* object) NO_THREAD_SAFETY_ANALYSIS; |
| 53 | // TODO fix thread safety analysis broken by the use of template. This should be |
| 54 | // SHARED_LOCKS_REQUIRED(Locks::mutator_lock_). |
| 55 | template<bool kTransactionActive, bool kCheckTransaction = true> |
| 56 | void SetWithoutChecksAndWriteBarrier(int32_t i, T* object) NO_THREAD_SAFETY_ANALYSIS; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 57 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 58 | T* GetWithoutChecks(int32_t i) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 59 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 60 | // Copy src into this array (dealing with overlaps as memmove does) without assignability checks. |
| 61 | void AssignableMemmove(int32_t dst_pos, ObjectArray<T>* src, int32_t src_pos, |
| 62 | int32_t count) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 63 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 64 | // Copy src into this array assuming no overlap and without assignability checks. |
| 65 | void AssignableMemcpy(int32_t dst_pos, ObjectArray<T>* src, int32_t src_pos, |
| 66 | int32_t count) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 67 | |
| 68 | // Copy src into this array with assignability checks. |
| 69 | void AssignableCheckingMemcpy(int32_t dst_pos, ObjectArray<T>* src, int32_t src_pos, |
| 70 | int32_t count, bool throw_exception) |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 71 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 72 | |
| 73 | ObjectArray<T>* CopyOf(Thread* self, int32_t new_length) |
| 74 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 75 | |
| 76 | private: |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 77 | static MemberOffset OffsetOfElement(int32_t i); |
| 78 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 79 | DISALLOW_IMPLICIT_CONSTRUCTORS(ObjectArray); |
| 80 | }; |
| 81 | |
| 82 | } // namespace mirror |
| 83 | } // namespace art |
| 84 | |
Brian Carlstrom | fc0e321 | 2013-07-17 14:40:12 -0700 | [diff] [blame] | 85 | #endif // ART_RUNTIME_MIRROR_OBJECT_ARRAY_H_ |