Home | History | Annotate | Download | only in OldJIT
      1 /*
      2  * copyright 2010, 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 BCC_CONTEXTMANAGER_H
     18 #define BCC_CONTEXTMANAGER_H
     19 
     20 #include <Config.h>
     21 
     22 #include <llvm/Support/Mutex.h>
     23 
     24 #include <unistd.h>
     25 #include <stddef.h>
     26 
     27 
     28 namespace bcc {
     29 
     30   class ContextManager {
     31   public:
     32     // Starting address of context slot address space
     33     static char * const ContextFixedAddr;
     34 
     35     // Number of the context slots
     36     static size_t const ContextSlotCount = BCC_CONTEXT_SLOT_COUNT_;
     37 
     38     // Context size
     39     static size_t const ContextCodeSize = BCC_CONTEXT_CODE_SIZE_;
     40     static size_t const ContextDataSize = BCC_CONTEXT_DATA_SIZE_;
     41     static size_t const ContextSize = ContextCodeSize + ContextDataSize;
     42 
     43   private:
     44     // Context manager singleton
     45     static ContextManager TheContextManager;
     46 
     47   private:
     48     // Mutex lock for context slot occupation table
     49     mutable llvm::sys::Mutex mContextSlotOccupiedLock;
     50 
     51     // Context slot occupation table
     52     bool mContextSlotOccupied[ContextSlotCount];
     53 
     54     ContextManager();
     55 
     56   public:
     57     static ContextManager &get() {
     58       return TheContextManager;
     59     }
     60 
     61     char *allocateContext();
     62     char *allocateContext(char *addr, int imageFd, off_t imageOffset);
     63     void deallocateContext(char *addr);
     64 
     65     bool isManagingContext(char *addr) const;
     66 
     67   private:
     68     static ssize_t getSlotIndexFromAddress(char *addr);
     69 
     70   };
     71 
     72 } // namespace bcc
     73 
     74 #endif // BCC_CONTEXTMANAGER_H
     75