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