blob: 347494e2abb33b7d5aa5769d0a78594ff94d8fda [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"
Mathieu Chartiercbb2d202013-11-14 17:45:16 -080021#include "gc/heap.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080022
23namespace art {
24namespace mirror {
25
26template<class T>
27class MANAGED ObjectArray : public Array {
28 public:
Mathieu Chartiercbb2d202013-11-14 17:45:16 -080029 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 Rogers2dd0e2c2013-01-24 12:42:14 -080033 static ObjectArray<T>* Alloc(Thread* self, Class* object_array_class, int32_t length)
34 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
35
Ian Rogersef7d42f2014-01-06 12:55:46 -080036 T* Get(int32_t i) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080037
Sebastien Hertz6bdd8f42013-05-17 14:44:01 +020038 // 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 Rogers2dd0e2c2013-01-24 12:42:14 -080042 void Set(int32_t i, T* object) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
43
44 // Set element without bound and element type checks, to be used in limited
45 // circumstances, such as during boot image writing
46 void SetWithoutChecks(int32_t i, T* object) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogersef7d42f2014-01-06 12:55:46 -080047 void SetWithoutChecksAndWriteBarrier(int32_t i, T* object)
48 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080049
Ian Rogersef7d42f2014-01-06 12:55:46 -080050 T* GetWithoutChecks(int32_t i) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080051
Ian Rogersef7d42f2014-01-06 12:55:46 -080052 // Copy src into this array (dealing with overlaps as memmove does) without assignability checks.
53 void AssignableMemmove(int32_t dst_pos, ObjectArray<T>* src, int32_t src_pos,
54 int32_t count) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080055
Ian Rogersef7d42f2014-01-06 12:55:46 -080056 // Copy src into this array assuming no overlap and without assignability checks.
57 void AssignableMemcpy(int32_t dst_pos, ObjectArray<T>* src, int32_t src_pos,
58 int32_t count) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
59
60 // Copy src into this array with assignability checks.
61 void AssignableCheckingMemcpy(int32_t dst_pos, ObjectArray<T>* src, int32_t src_pos,
62 int32_t count, bool throw_exception)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080063 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
64
65 ObjectArray<T>* CopyOf(Thread* self, int32_t new_length)
66 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
67
68 private:
Ian Rogersef7d42f2014-01-06 12:55:46 -080069 static MemberOffset OffsetOfElement(int32_t i);
70
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080071 DISALLOW_IMPLICIT_CONSTRUCTORS(ObjectArray);
72};
73
74} // namespace mirror
75} // namespace art
76
Brian Carlstromfc0e3212013-07-17 14:40:12 -070077#endif // ART_RUNTIME_MIRROR_OBJECT_ARRAY_H_