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