blob: be83d034b82029330d0e63af8e936cf229786e66 [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_IFTABLE_H_
18#define ART_RUNTIME_MIRROR_IFTABLE_H_
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080019
20#include "object_array.h"
21
22namespace art {
23namespace mirror {
24
25class MANAGED IfTable : public ObjectArray<Object> {
26 public:
Ian Rogersef7d42f2014-01-06 12:55:46 -080027 Class* GetInterface(int32_t i) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080028 Class* interface = Get((i * kMax) + kInterface)->AsClass();
29 DCHECK(interface != NULL);
30 return interface;
31 }
32
33 void SetInterface(int32_t i, Class* interface) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
34
Ian Rogersef7d42f2014-01-06 12:55:46 -080035 ObjectArray<ArtMethod>* GetMethodArray(int32_t i) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Brian Carlstromea46f952013-07-30 01:26:50 -070036 ObjectArray<ArtMethod>* method_array =
37 down_cast<ObjectArray<ArtMethod>*>(Get((i * kMax) + kMethodArray));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080038 DCHECK(method_array != NULL);
39 return method_array;
40 }
41
Ian Rogersef7d42f2014-01-06 12:55:46 -080042 size_t GetMethodArrayCount(int32_t i) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Brian Carlstromea46f952013-07-30 01:26:50 -070043 ObjectArray<ArtMethod>* method_array =
44 down_cast<ObjectArray<ArtMethod>*>(Get((i * kMax) + kMethodArray));
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080045 if (method_array == NULL) {
46 return 0;
47 }
48 return method_array->GetLength();
49 }
50
Brian Carlstromea46f952013-07-30 01:26:50 -070051 void SetMethodArray(int32_t i, ObjectArray<ArtMethod>* new_ma)
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080052 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
53 DCHECK(new_ma != NULL);
54 DCHECK(Get((i * kMax) + kMethodArray) == NULL);
55 Set((i * kMax) + kMethodArray, new_ma);
56 }
57
Ian Rogersef7d42f2014-01-06 12:55:46 -080058 size_t Count() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080059 return GetLength() / kMax;
60 }
61
62 enum {
63 // Points to the interface class.
64 kInterface = 0,
65 // Method pointers into the vtable, allow fast map from interface method index to concrete
66 // instance method.
67 kMethodArray = 1,
68 kMax = 2,
69 };
70
71 private:
72 DISALLOW_IMPLICIT_CONSTRUCTORS(IfTable);
73};
74
75} // namespace mirror
76} // namespace art
77
Brian Carlstromfc0e3212013-07-17 14:40:12 -070078#endif // ART_RUNTIME_MIRROR_IFTABLE_H_