• 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_CLASS_LOADER_H_
18 #define ART_RUNTIME_MIRROR_CLASS_LOADER_H_
19 
20 #include "base/mutex.h"
21 #include "object.h"
22 #include "object_reference.h"
23 #include "obj_ptr.h"
24 
25 namespace art {
26 
27 struct ClassLoaderOffsets;
28 class ClassTable;
29 class LinearAlloc;
30 
31 namespace mirror {
32 
33 class Class;
34 
35 // C++ mirror of java.lang.ClassLoader
36 class MANAGED ClassLoader : public Object {
37  public:
38   // Size of an instance of java.lang.ClassLoader.
InstanceSize()39   static constexpr uint32_t InstanceSize() {
40     return sizeof(ClassLoader);
41   }
42 
GetParent()43   ClassLoader* GetParent() REQUIRES_SHARED(Locks::mutator_lock_) {
44     return GetFieldObject<ClassLoader>(OFFSET_OF_OBJECT_MEMBER(ClassLoader, parent_));
45   }
46 
GetClassTable()47   ClassTable* GetClassTable() REQUIRES_SHARED(Locks::mutator_lock_) {
48     return reinterpret_cast<ClassTable*>(
49         GetField64(OFFSET_OF_OBJECT_MEMBER(ClassLoader, class_table_)));
50   }
51 
SetClassTable(ClassTable * class_table)52   void SetClassTable(ClassTable* class_table) REQUIRES_SHARED(Locks::mutator_lock_) {
53     SetField64<false>(OFFSET_OF_OBJECT_MEMBER(ClassLoader, class_table_),
54                       reinterpret_cast<uint64_t>(class_table));
55   }
56 
GetAllocator()57   LinearAlloc* GetAllocator() REQUIRES_SHARED(Locks::mutator_lock_) {
58     return reinterpret_cast<LinearAlloc*>(
59         GetField64(OFFSET_OF_OBJECT_MEMBER(ClassLoader, allocator_)));
60   }
61 
SetAllocator(LinearAlloc * allocator)62   void SetAllocator(LinearAlloc* allocator) REQUIRES_SHARED(Locks::mutator_lock_) {
63     SetField64<false>(OFFSET_OF_OBJECT_MEMBER(ClassLoader, allocator_),
64                       reinterpret_cast<uint64_t>(allocator));
65   }
66 
67  private:
68   // Visit instance fields of the class loader as well as its associated classes.
69   // Null class loader is handled by ClassLinker::VisitClassRoots.
70   template <bool kVisitClasses,
71             VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
72             ReadBarrierOption kReadBarrierOption = kWithReadBarrier,
73             typename Visitor>
74   void VisitReferences(ObjPtr<Class> klass, const Visitor& visitor)
75       REQUIRES_SHARED(Locks::mutator_lock_)
76       REQUIRES(!Locks::classlinker_classes_lock_);
77 
78   // Field order required by test "ValidateFieldOrderOfJavaCppUnionClasses".
79   HeapReference<Object> packages_;
80   HeapReference<ClassLoader> parent_;
81   HeapReference<Object> proxyCache_;
82   // Native pointer to class table, need to zero this out when image writing.
83   uint32_t padding_ ATTRIBUTE_UNUSED;
84   uint64_t allocator_;
85   uint64_t class_table_;
86 
87   friend struct art::ClassLoaderOffsets;  // for verifying offset information
88   friend class Object;  // For VisitReferences
89   DISALLOW_IMPLICIT_CONSTRUCTORS(ClassLoader);
90 };
91 
92 }  // namespace mirror
93 }  // namespace art
94 
95 #endif  // ART_RUNTIME_MIRROR_CLASS_LOADER_H_
96