• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
17 #ifndef ART_RUNTIME_MIRROR_OBJECT_ARRAY_H_
18 #define ART_RUNTIME_MIRROR_OBJECT_ARRAY_H_
19 
20 #include "array.h"
21 
22 namespace art {
23 namespace mirror {
24 
25 template<class T>
26 class MANAGED ObjectArray: public Array {
27  public:
28   // The size of Object[].class.
ClassSize(size_t pointer_size)29   static uint32_t ClassSize(size_t pointer_size) {
30     return Array::ClassSize(pointer_size);
31   }
32 
33   static ObjectArray<T>* Alloc(Thread* self, Class* object_array_class, int32_t length,
34                                gc::AllocatorType allocator_type)
35       SHARED_REQUIRES(Locks::mutator_lock_) REQUIRES(!Roles::uninterruptible_);
36 
37   static ObjectArray<T>* Alloc(Thread* self, Class* object_array_class, int32_t length)
38       SHARED_REQUIRES(Locks::mutator_lock_) REQUIRES(!Roles::uninterruptible_);
39 
40   template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
41            ReadBarrierOption kReadBarrierOption = kWithReadBarrier>
42   ALWAYS_INLINE T* Get(int32_t i) SHARED_REQUIRES(Locks::mutator_lock_);
43 
44   // Returns true if the object can be stored into the array. If not, throws
45   // an ArrayStoreException and returns false.
46   // TODO fix thread safety analysis: should be SHARED_REQUIRES(Locks::mutator_lock_).
47   template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
48   bool CheckAssignable(T* object) NO_THREAD_SAFETY_ANALYSIS;
49 
50   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_).
52   template<bool kTransactionActive, bool kCheckTransaction = true,
53       VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
54   ALWAYS_INLINE void Set(int32_t i, T* object) NO_THREAD_SAFETY_ANALYSIS;
55 
56   // Set element without bound and element type checks, to be used in limited
57   // circumstances, such as during boot image writing.
58   // TODO fix thread safety analysis broken by the use of template. This should be
59   // SHARED_REQUIRES(Locks::mutator_lock_).
60   template<bool kTransactionActive, bool kCheckTransaction = true,
61       VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
62   ALWAYS_INLINE void SetWithoutChecks(int32_t i, T* object) NO_THREAD_SAFETY_ANALYSIS;
63   // TODO fix thread safety analysis broken by the use of template. This should be
64   // SHARED_REQUIRES(Locks::mutator_lock_).
65   template<bool kTransactionActive, bool kCheckTransaction = true,
66       VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags>
67   ALWAYS_INLINE void SetWithoutChecksAndWriteBarrier(int32_t i, T* object)
68       NO_THREAD_SAFETY_ANALYSIS;
69 
70   ALWAYS_INLINE T* GetWithoutChecks(int32_t i) SHARED_REQUIRES(Locks::mutator_lock_);
71 
72   // 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,
74                          int32_t count) SHARED_REQUIRES(Locks::mutator_lock_);
75 
76   // 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,
78                         int32_t count) SHARED_REQUIRES(Locks::mutator_lock_);
79 
80   // Copy src into this array with assignability checks.
81   template<bool kTransactionActive>
82   void AssignableCheckingMemcpy(int32_t dst_pos, ObjectArray<T>* src, int32_t src_pos,
83                                 int32_t count, bool throw_exception)
84       SHARED_REQUIRES(Locks::mutator_lock_);
85 
86   ObjectArray<T>* CopyOf(Thread* self, int32_t new_length)
87       SHARED_REQUIRES(Locks::mutator_lock_) REQUIRES(!Roles::uninterruptible_);
88 
89   static MemberOffset OffsetOfElement(int32_t i);
90 
91  private:
92   // 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
98   DISALLOW_IMPLICIT_CONSTRUCTORS(ObjectArray);
99 };
100 
101 }  // namespace mirror
102 }  // namespace art
103 
104 #endif  // ART_RUNTIME_MIRROR_OBJECT_ARRAY_H_
105