Home | History | Annotate | Download | only in driver
      1 /*
      2  * Copyright (C) 2012 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_DRIVER_DEX_COMPILATION_UNIT_H_
     18 #define ART_COMPILER_DRIVER_DEX_COMPILATION_UNIT_H_
     19 
     20 #include <stdint.h>
     21 
     22 #include "base/arena_object.h"
     23 #include "dex/code_item_accessors.h"
     24 #include "dex/dex_file.h"
     25 #include "handle.h"
     26 #include "jni.h"
     27 
     28 namespace art {
     29 namespace mirror {
     30 class ClassLoader;
     31 class DexCache;
     32 }  // namespace mirror
     33 class ClassLinker;
     34 class VerifiedMethod;
     35 
     36 class DexCompilationUnit : public DeletableArenaObject<kArenaAllocMisc> {
     37  public:
     38   DexCompilationUnit(Handle<mirror::ClassLoader> class_loader,
     39                      ClassLinker* class_linker,
     40                      const DexFile& dex_file,
     41                      const DexFile::CodeItem* code_item,
     42                      uint16_t class_def_idx,
     43                      uint32_t method_idx,
     44                      uint32_t access_flags,
     45                      const VerifiedMethod* verified_method,
     46                      Handle<mirror::DexCache> dex_cache);
     47 
     48   Handle<mirror::ClassLoader> GetClassLoader() const {
     49     return class_loader_;
     50   }
     51 
     52   ClassLinker* GetClassLinker() const {
     53     return class_linker_;
     54   }
     55 
     56   const DexFile* GetDexFile() const {
     57     return dex_file_;
     58   }
     59 
     60   uint16_t GetClassDefIndex() const {
     61     return class_def_idx_;
     62   }
     63 
     64   uint32_t GetDexMethodIndex() const {
     65     return dex_method_idx_;
     66   }
     67 
     68   const DexFile::CodeItem* GetCodeItem() const {
     69     return code_item_;
     70   }
     71 
     72   const char* GetShorty() const {
     73     const DexFile::MethodId& method_id = dex_file_->GetMethodId(dex_method_idx_);
     74     return dex_file_->GetMethodShorty(method_id);
     75   }
     76 
     77   const char* GetShorty(uint32_t* shorty_len) const {
     78     const DexFile::MethodId& method_id = dex_file_->GetMethodId(dex_method_idx_);
     79     return dex_file_->GetMethodShorty(method_id, shorty_len);
     80   }
     81 
     82   uint32_t GetAccessFlags() const {
     83     return access_flags_;
     84   }
     85 
     86   bool IsConstructor() const {
     87     return ((access_flags_ & kAccConstructor) != 0);
     88   }
     89 
     90   bool IsNative() const {
     91     return ((access_flags_ & kAccNative) != 0);
     92   }
     93 
     94   bool IsStatic() const {
     95     return ((access_flags_ & kAccStatic) != 0);
     96   }
     97 
     98   bool IsSynchronized() const {
     99     return ((access_flags_ & kAccSynchronized) != 0);
    100   }
    101 
    102   const VerifiedMethod* GetVerifiedMethod() const {
    103     return verified_method_;
    104   }
    105 
    106   void ClearVerifiedMethod() {
    107     verified_method_ = nullptr;
    108   }
    109 
    110   const std::string& GetSymbol();
    111 
    112   Handle<mirror::DexCache> GetDexCache() const {
    113     return dex_cache_;
    114   }
    115 
    116   const CodeItemDataAccessor& GetCodeItemAccessor() const {
    117     return code_item_accessor_;
    118   }
    119 
    120  private:
    121   const Handle<mirror::ClassLoader> class_loader_;
    122 
    123   ClassLinker* const class_linker_;
    124 
    125   const DexFile* const dex_file_;
    126 
    127   const DexFile::CodeItem* const code_item_;
    128   const uint16_t class_def_idx_;
    129   const uint32_t dex_method_idx_;
    130   const uint32_t access_flags_;
    131   const VerifiedMethod* verified_method_;
    132 
    133   const Handle<mirror::DexCache> dex_cache_;
    134 
    135   const CodeItemDataAccessor code_item_accessor_;
    136 
    137   std::string symbol_;
    138 };
    139 
    140 }  // namespace art
    141 
    142 #endif  // ART_COMPILER_DRIVER_DEX_COMPILATION_UNIT_H_
    143