Home | History | Annotate | Download | only in utils
      1 /*
      2  * Copyright (C) 2015 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_COMPILER_UTILS_DEX_CACHE_ARRAYS_LAYOUT_H_
     18 #define ART_COMPILER_UTILS_DEX_CACHE_ARRAYS_LAYOUT_H_
     19 
     20 namespace art {
     21 
     22 /**
     23  * @class DexCacheArraysLayout
     24  * @details This class provides the layout information for the type, method, field and
     25  * string arrays for a DexCache with a fixed arrays' layout (such as in the boot image),
     26  */
     27 class DexCacheArraysLayout {
     28  public:
     29   // Construct an invalid layout.
     30   DexCacheArraysLayout()
     31       : /* types_offset_ is always 0u */
     32         pointer_size_(0u),
     33         methods_offset_(0u),
     34         strings_offset_(0u),
     35         fields_offset_(0u),
     36         size_(0u) {
     37   }
     38 
     39   // Construct a layout for a particular dex file.
     40   explicit DexCacheArraysLayout(size_t pointer_size, const DexFile* dex_file);
     41 
     42   bool Valid() const {
     43     return Size() != 0u;
     44   }
     45 
     46   size_t Size() const {
     47     return size_;
     48   }
     49 
     50   size_t TypesOffset() const {
     51     return types_offset_;
     52   }
     53 
     54   size_t TypeOffset(uint32_t type_idx) const;
     55 
     56   size_t TypesSize(size_t num_elements) const;
     57 
     58   size_t MethodsOffset() const {
     59     return methods_offset_;
     60   }
     61 
     62   size_t MethodOffset(uint32_t method_idx) const;
     63 
     64   size_t MethodsSize(size_t num_elements) const;
     65 
     66   size_t StringsOffset() const {
     67     return strings_offset_;
     68   }
     69 
     70   size_t StringOffset(uint32_t string_idx) const;
     71 
     72   size_t StringsSize(size_t num_elements) const;
     73 
     74   size_t FieldsOffset() const {
     75     return fields_offset_;
     76   }
     77 
     78   size_t FieldOffset(uint32_t field_idx) const;
     79 
     80   size_t FieldsSize(size_t num_elements) const;
     81 
     82  private:
     83   static constexpr size_t types_offset_ = 0u;
     84   const size_t pointer_size_;  // Must be first for construction initialization order.
     85   const size_t methods_offset_;
     86   const size_t strings_offset_;
     87   const size_t fields_offset_;
     88   const size_t size_;
     89 
     90   static size_t ElementOffset(size_t element_size, uint32_t idx);
     91 
     92   static size_t ArraySize(size_t element_size, uint32_t num_elements);
     93 };
     94 
     95 }  // namespace art
     96 
     97 #endif  // ART_COMPILER_UTILS_DEX_CACHE_ARRAYS_LAYOUT_H_
     98