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 "dex_file.h"
     23 #include "jni.h"
     24 
     25 namespace art {
     26 namespace mirror {
     27 class ClassLoader;
     28 class DexCache;
     29 }  // namespace mirror
     30 class ClassLinker;
     31 struct CompilationUnit;
     32 class VerifiedMethod;
     33 
     34 class DexCompilationUnit {
     35  public:
     36   explicit DexCompilationUnit(CompilationUnit* cu);
     37 
     38   DexCompilationUnit(CompilationUnit* cu, jobject class_loader, ClassLinker* class_linker,
     39                      const DexFile& dex_file, const DexFile::CodeItem* code_item,
     40                      uint16_t class_def_idx, uint32_t method_idx, uint32_t access_flags,
     41                      const VerifiedMethod* verified_method);
     42 
     43   CompilationUnit* GetCompilationUnit() const {
     44     return cu_;
     45   }
     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   const std::string& GetSymbol();
    106 
    107  private:
    108   CompilationUnit* const cu_;
    109 
    110   const jobject class_loader_;
    111 
    112   ClassLinker* const class_linker_;
    113 
    114   const DexFile* const dex_file_;
    115 
    116   const DexFile::CodeItem* const code_item_;
    117   const uint16_t class_def_idx_;
    118   const uint32_t dex_method_idx_;
    119   const uint32_t access_flags_;
    120   const VerifiedMethod* const verified_method_;
    121 
    122   std::string symbol_;
    123 };
    124 
    125 }  // namespace art
    126 
    127 #endif  // ART_COMPILER_DRIVER_DEX_COMPILATION_UNIT_H_
    128