Remove OLD_JIT support from libbcc.

BUG=6051742

This change removes some legacy defines and files related to the original
LLVM JIT path. A follow-up change should remove MCJIT-related defines, since
we are not a JIT, but instead using MC CodeGen to emit ELF.

Change-Id: I193235a7716e5f8c653a617a2fb74840bf3406e0
diff --git a/lib/ExecutionEngine/Android.mk b/lib/ExecutionEngine/Android.mk
index 2e2a4fa..ffc6088 100644
--- a/lib/ExecutionEngine/Android.mk
+++ b/lib/ExecutionEngine/Android.mk
@@ -33,18 +33,7 @@
   ScriptCompiled.cpp \
   SourceInfo.cpp
 
-ifeq ($(libbcc_USE_OLD_JIT),1)
-libbcc_executionengine_SRC_FILES += \
-  OldJIT/ContextManager.cpp
-endif
-
 ifeq ($(libbcc_USE_CACHE),1)
-ifeq ($(libbcc_USE_OLD_JIT),1)
-libbcc_executionengine_SRC_FILES += \
-  OldJIT/CacheReader.cpp \
-  OldJIT/CacheWriter.cpp
-endif
-
 ifeq ($(libbcc_USE_MCJIT),1)
 libbcc_executionengine_SRC_FILES += \
   MCCacheWriter.cpp \
diff --git a/lib/ExecutionEngine/Compiler.cpp b/lib/ExecutionEngine/Compiler.cpp
index e7bdd52..8f29e27 100644
--- a/lib/ExecutionEngine/Compiler.cpp
+++ b/lib/ExecutionEngine/Compiler.cpp
@@ -19,10 +19,6 @@
 #include "Config.h"
 #include <bcinfo/MetadataExtractor.h>
 
-#if USE_OLD_JIT
-#include "OldJIT/ContextManager.h"
-#endif
-
 #if USE_DISASSEMBLER
 #include "Disassembler/Disassembler.h"
 #endif
@@ -229,22 +225,6 @@
 }
 
 
-#if USE_OLD_JIT
-CodeMemoryManager *Compiler::createCodeMemoryManager() {
-  mCodeMemMgr.reset(new CodeMemoryManager());
-  return mCodeMemMgr.get();
-}
-#endif
-
-
-#if USE_OLD_JIT
-CodeEmitter *Compiler::createCodeEmitter() {
-  mCodeEmitter.reset(new CodeEmitter(mpResult, mCodeMemMgr.get()));
-  return mCodeEmitter.get();
-}
-#endif
-
-
 Compiler::Compiler(ScriptCompiled *result)
   : mpResult(result),
 #if USE_MCJIT
@@ -413,13 +393,6 @@
   }
 
   // Perform code generation
-#if USE_OLD_JIT
-  if (runCodeGen(new llvm::TargetData(*TD), TM,
-                 ExportVarMetadata, ExportFuncMetadata) != 0) {
-    goto on_bcc_compile_error;
-  }
-#endif
-
 #if USE_MCJIT
   if (runMCCodeGen(new llvm::TargetData(*TD), TM) != 0) {
     goto on_bcc_compile_error;
@@ -507,132 +480,6 @@
 }
 
 
-#if USE_OLD_JIT
-int Compiler::runCodeGen(llvm::TargetData *TD, llvm::TargetMachine *TM,
-                         llvm::NamedMDNode const *ExportVarMetadata,
-                         llvm::NamedMDNode const *ExportFuncMetadata) {
-  // Create memory manager for creation of code emitter later.
-  if (!mCodeMemMgr.get() && !createCodeMemoryManager()) {
-    setError("Failed to startup memory management for further compilation");
-    return 1;
-  }
-
-  mpResult->mContext = (char *) (mCodeMemMgr.get()->getCodeMemBase());
-
-  // Create code emitter
-  if (!mCodeEmitter.get()) {
-    if (!createCodeEmitter()) {
-      setError("Failed to create machine code emitter for compilation");
-      return 1;
-    }
-  } else {
-    // Reuse the code emitter
-    mCodeEmitter->reset();
-  }
-
-  mCodeEmitter->setTargetMachine(*TM);
-  mCodeEmitter->registerSymbolCallback(mpSymbolLookupFn,
-                                       mpSymbolLookupContext);
-
-  // Create code-gen pass to run the code emitter
-  llvm::OwningPtr<llvm::FunctionPassManager> CodeGenPasses(
-    new llvm::FunctionPassManager(mModule));
-
-  // Add TargetData to code generation pass manager
-  CodeGenPasses->add(TD);
-
-  // Add code emit passes
-  if (TM->addPassesToEmitMachineCode(*CodeGenPasses,
-                                     *mCodeEmitter,
-                                     CodeGenOptLevel)) {
-    setError("The machine code emission is not supported on '" + Triple + "'");
-    return 1;
-  }
-
-  // Run the code emitter on every non-declaration function in the module
-  CodeGenPasses->doInitialization();
-  for (llvm::Module::iterator
-       I = mModule->begin(), E = mModule->end(); I != E; I++) {
-    if (!I->isDeclaration()) {
-      CodeGenPasses->run(*I);
-    }
-  }
-
-  CodeGenPasses->doFinalization();
-
-  // Copy the global address mapping from code emitter and remapping
-  if (ExportVarMetadata) {
-    ScriptCompiled::ExportVarList &varList = mpResult->mExportVars;
-
-    for (int i = 0, e = ExportVarMetadata->getNumOperands(); i != e; i++) {
-      llvm::MDNode *ExportVar = ExportVarMetadata->getOperand(i);
-      if (ExportVar != NULL && ExportVar->getNumOperands() > 1) {
-        llvm::Value *ExportVarNameMDS = ExportVar->getOperand(0);
-        if (ExportVarNameMDS->getValueID() == llvm::Value::MDStringVal) {
-          llvm::StringRef ExportVarName =
-            static_cast<llvm::MDString*>(ExportVarNameMDS)->getString();
-
-          CodeEmitter::global_addresses_const_iterator I, E;
-          for (I = mCodeEmitter->global_address_begin(),
-               E = mCodeEmitter->global_address_end();
-               I != E; I++) {
-            if (I->first->getValueID() != llvm::Value::GlobalVariableVal)
-              continue;
-            if (ExportVarName == I->first->getName()) {
-              varList.push_back(I->second);
-#if DEBUG_BCC_REFLECT
-              ALOGD("runCodeGen(): Exported VAR: %s @ %p\n", ExportVarName.str().c_str(), I->second);
-#endif
-              break;
-            }
-          }
-          if (I != mCodeEmitter->global_address_end())
-            continue;  // found
-
-#if DEBUG_BCC_REFLECT
-          ALOGD("runCodeGen(): Exported VAR: %s @ %p\n",
-               ExportVarName.str().c_str(), (void *)0);
-#endif
-        }
-      }
-      // if reaching here, we know the global variable record in metadata is
-      // not found. So we make an empty slot
-      varList.push_back(NULL);
-    }
-
-    bccAssert((varList.size() == ExportVarMetadata->getNumOperands()) &&
-              "Number of slots doesn't match the number of export variables!");
-  }
-
-  if (ExportFuncMetadata) {
-    ScriptCompiled::ExportFuncList &funcList = mpResult->mExportFuncs;
-
-    for (int i = 0, e = ExportFuncMetadata->getNumOperands(); i != e; i++) {
-      llvm::MDNode *ExportFunc = ExportFuncMetadata->getOperand(i);
-      if (ExportFunc != NULL && ExportFunc->getNumOperands() > 0) {
-        llvm::Value *ExportFuncNameMDS = ExportFunc->getOperand(0);
-        if (ExportFuncNameMDS->getValueID() == llvm::Value::MDStringVal) {
-          llvm::StringRef ExportFuncName =
-            static_cast<llvm::MDString*>(ExportFuncNameMDS)->getString();
-          funcList.push_back(mpResult->lookup(ExportFuncName.str().c_str()));
-#if DEBUG_BCC_REFLECT
-          ALOGD("runCodeGen(): Exported Func: %s @ %p\n", ExportFuncName.str().c_str(),
-               funcList.back());
-#endif
-        }
-      }
-    }
-  }
-
-  // Tell code emitter now can release the memory using during the JIT since
-  // we have done the code emission
-  mCodeEmitter->releaseUnnecessary();
-
-  return 0;
-}
-#endif // USE_OLD_JIT
-
-
 #if USE_MCJIT
 int Compiler::runMCCodeGen(llvm::TargetData *TD, llvm::TargetMachine *TM) {
   // Decorate mEmittedELFExecutable with formatted ostream
diff --git a/lib/ExecutionEngine/Compiler.h b/lib/ExecutionEngine/Compiler.h
index eebe550..301daed 100644
--- a/lib/ExecutionEngine/Compiler.h
+++ b/lib/ExecutionEngine/Compiler.h
@@ -19,8 +19,7 @@
 
 #include <bcc/bcc.h>
 
-#include "CodeGen/CodeEmitter.h"
-#include "CodeGen/CodeMemoryManager.h"
+#include <Config.h>
 
 #if USE_MCJIT
 #include "librsloader.h"
@@ -85,14 +84,6 @@
 
     std::string mError;
 
-#if USE_OLD_JIT
-    // The memory manager for code emitter
-    llvm::OwningPtr<CodeMemoryManager> mCodeMemMgr;
-
-    // The CodeEmitter
-    llvm::OwningPtr<CodeEmitter> mCodeEmitter;
-#endif
-
 #if USE_MCJIT
     // Compilation buffer for MCJIT
     llvm::SmallVector<char, 1024> mEmittedELFExecutable;
@@ -126,12 +117,6 @@
       mpSymbolLookupContext = pContext;
     }
 
-#if USE_OLD_JIT
-    CodeMemoryManager *createCodeMemoryManager();
-
-    CodeEmitter *createCodeEmitter();
-#endif
-
 #if USE_MCJIT
     void *getSymbolAddress(char const *name);
 
diff --git a/lib/ExecutionEngine/OldJIT/CacheReader.cpp b/lib/ExecutionEngine/OldJIT/CacheReader.cpp
deleted file mode 100644
index 8eceb5f..0000000
--- a/lib/ExecutionEngine/OldJIT/CacheReader.cpp
+++ /dev/null
@@ -1,453 +0,0 @@
-/*
- * Copyright 2010, The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "CacheReader.h"
-
-#include "ContextManager.h"
-#include "DebugHelper.h"
-#include "FileHandle.h"
-#include "ScriptCached.h"
-
-#include <bcc/bcc_cache.h>
-
-#include <llvm/ADT/OwningPtr.h>
-
-#include <errno.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-
-#include <utility>
-#include <vector>
-
-#include <new>
-
-#include <stdlib.h>
-#include <string.h>
-
-using namespace std;
-
-
-namespace bcc {
-
-CacheReader::~CacheReader() {
-  if (mpHeader) { free(mpHeader); }
-  if (mpCachedDependTable) { free(mpCachedDependTable); }
-  if (mpPragmaList) { free(mpPragmaList); }
-  if (mpFuncTable) { free(mpFuncTable); }
-}
-
-ScriptCached *CacheReader::readCacheFile(FileHandle *objFile,
-                                         FileHandle *infoFile,
-                                         Script *S) {
-  // Check file handle
-  if (!objFile || objFile->getFD() < 0 ||
-      !infoFile || infoFile->getFD() < 0) {
-    return NULL;
-  }
-
-  mObjFile = objFile;
-  mInfoFile = infoFile;
-
-  // Allocate ScriptCached object
-  mpResult.reset(new (nothrow) ScriptCached(S));
-
-  if (!mpResult) {
-    ALOGE("Unable to allocate ScriptCached object.\n");
-    return NULL;
-  }
-
-  bool result = checkFileSize()
-             && readHeader()
-             && checkHeader()
-             && checkMachineIntType()
-             && checkSectionOffsetAndSize()
-             && readStringPool()
-             && checkStringPool()
-             && readDependencyTable()
-             && checkDependency()
-             && readExportVarList()
-             && readExportFuncList()
-             && readPragmaList()
-             && readFuncTable()
-             && readObjectSlotList()
-             && readContext()
-             && checkContext()
-             //&& readRelocationTable()
-             //&& relocate()
-             ;
-
-  return result ? mpResult.take() : NULL;
-}
-
-
-bool CacheReader::checkFileSize() {
-  struct stat stfile;
-
-  if (fstat(mInfoFile->getFD(), &stfile) < 0) {
-    ALOGE("Unable to stat metadata information file.\n");
-    return false;
-  }
-
-  mInfoFileSize = stfile.st_size;
-
-  if (mInfoFileSize < (off_t)sizeof(OBCC_Header)) {
-    ALOGE("Metadata information file is too small to be correct.\n");
-    return false;
-  }
-
-  if (fstat(mObjFile->getFD(), &stfile) < 0) {
-    ALOGE("Unable to stat executable file.\n");
-    return false;
-  }
-
-  if (stfile.st_size < (off_t)ContextManager::ContextSize) {
-    ALOGE("Executable file is too small to be correct.\n");
-    return false;
-  }
-
-  return true;
-}
-
-
-bool CacheReader::readHeader() {
-  if (mInfoFile->seek(0, SEEK_SET) != 0) {
-    ALOGE("Unable to seek to 0. (reason: %s)\n", strerror(errno));
-    return false;
-  }
-
-  mpHeader = (OBCC_Header *)malloc(sizeof(OBCC_Header));
-  if (!mpHeader) {
-    ALOGE("Unable to allocate for cache header.\n");
-    return false;
-  }
-
-  if (mInfoFile->read((char *)mpHeader, sizeof(OBCC_Header)) !=
-      (ssize_t)sizeof(OBCC_Header)) {
-    ALOGE("Unable to read cache header.\n");
-    return false;
-  }
-
-  // Dirty hack for libRS.
-  // TODO(all): This should be removed in the future.
-  if (mpHeader->libRS_threadable) {
-    mpResult->mLibRSThreadable = true;
-  }
-
-  return true;
-}
-
-
-bool CacheReader::checkHeader() {
-  if (memcmp(mpHeader->magic, OBCC_MAGIC, 4) != 0) {
-    ALOGE("Bad magic word\n");
-    return false;
-  }
-
-  if (memcmp(mpHeader->version, OBCC_VERSION, 4) != 0) {
-    mpHeader->version[4 - 1] = '\0'; // ensure c-style string terminated
-    ALOGI("Cache file format version mismatch: now %s cached %s\n",
-         OBCC_VERSION, mpHeader->version);
-    return false;
-  }
-  return true;
-}
-
-
-bool CacheReader::checkMachineIntType() {
-  uint32_t number = 0x00000001;
-
-  bool isLittleEndian = (*reinterpret_cast<char *>(&number) == 1);
-  if ((isLittleEndian && mpHeader->endianness != 'e') ||
-      (!isLittleEndian && mpHeader->endianness != 'E')) {
-    ALOGE("Machine endianness mismatch.\n");
-    return false;
-  }
-
-  if ((unsigned int)mpHeader->sizeof_off_t != sizeof(off_t) ||
-      (unsigned int)mpHeader->sizeof_size_t != sizeof(size_t) ||
-      (unsigned int)mpHeader->sizeof_ptr_t != sizeof(void *)) {
-    ALOGE("Machine integer size mismatch.\n");
-    return false;
-  }
-
-  return true;
-}
-
-
-bool CacheReader::checkSectionOffsetAndSize() {
-#define CHECK_SECTION_OFFSET(NAME)                                          \
-  do {                                                                      \
-    off_t offset = mpHeader-> NAME##_offset;                                \
-    off_t size = (off_t)mpHeader-> NAME##_size;                             \
-                                                                            \
-    if (mInfoFileSize < offset || mInfoFileSize < offset + size) {          \
-      ALOGE(#NAME " section overflow.\n");                                   \
-      return false;                                                         \
-    }                                                                       \
-                                                                            \
-    if (offset % sizeof(int) != 0) {                                        \
-      ALOGE(#NAME " offset must aligned to %d.\n", (int)sizeof(int));        \
-      return false;                                                         \
-    }                                                                       \
-                                                                            \
-    if (size < static_cast<off_t>(sizeof(size_t))) {                        \
-      ALOGE(#NAME " size is too small to be correct.\n");                    \
-      return false;                                                         \
-    }                                                                       \
-  } while (0)
-
-  CHECK_SECTION_OFFSET(str_pool);
-  CHECK_SECTION_OFFSET(depend_tab);
-  //CHECK_SECTION_OFFSET(reloc_tab);
-  CHECK_SECTION_OFFSET(export_var_list);
-  CHECK_SECTION_OFFSET(export_func_list);
-  CHECK_SECTION_OFFSET(pragma_list);
-
-#undef CHECK_SECTION_OFFSET
-
-  // TODO(logan): Move this to some where else.
-  long pagesize = sysconf(_SC_PAGESIZE);
-  if ((uintptr_t)mpHeader->context_cached_addr % pagesize != 0) {
-    ALOGE("cached address is not aligned to pagesize.\n");
-    return false;
-  }
-
-  return true;
-}
-
-
-#define CACHE_READER_READ_SECTION(TYPE, AUTO_MANAGED_HOLDER, NAME)          \
-  TYPE *NAME##_raw = (TYPE *)malloc(mpHeader->NAME##_size);                 \
-                                                                            \
-  if (!NAME##_raw) {                                                        \
-    ALOGE("Unable to allocate for " #NAME "\n");                             \
-    return false;                                                           \
-  }                                                                         \
-                                                                            \
-  /* We have to ensure that some one will deallocate NAME##_raw */          \
-  AUTO_MANAGED_HOLDER = NAME##_raw;                                         \
-                                                                            \
-  if (mInfoFile->seek(mpHeader->NAME##_offset, SEEK_SET) == -1) {           \
-    ALOGE("Unable to seek to " #NAME " section\n");                          \
-    return false;                                                           \
-  }                                                                         \
-                                                                            \
-  if (mInfoFile->read(reinterpret_cast<char *>(NAME##_raw),                 \
-                  mpHeader->NAME##_size) != (ssize_t)mpHeader->NAME##_size) \
-  {                                                                         \
-    ALOGE("Unable to read " #NAME ".\n");                                    \
-    return false;                                                           \
-  }
-
-
-bool CacheReader::readStringPool() {
-  CACHE_READER_READ_SECTION(OBCC_StringPool,
-                            mpResult->mpStringPoolRaw, str_pool);
-
-  char *str_base = reinterpret_cast<char *>(str_pool_raw);
-
-  vector<char const *> &pool = mpResult->mStringPool;
-  for (size_t i = 0; i < str_pool_raw->count; ++i) {
-    char *str = str_base + str_pool_raw->list[i].offset;
-    pool.push_back(str);
-  }
-
-  return true;
-}
-
-
-bool CacheReader::checkStringPool() {
-  OBCC_StringPool *poolR = mpResult->mpStringPoolRaw;
-  vector<char const *> &pool = mpResult->mStringPool;
-
-  // Ensure that every c-style string is ended with '\0'
-  for (size_t i = 0; i < poolR->count; ++i) {
-    if (pool[i][poolR->list[i].length] != '\0') {
-      ALOGE("The %lu-th string does not end with '\\0'.\n", (unsigned long)i);
-      return false;
-    }
-  }
-
-  return true;
-}
-
-
-bool CacheReader::readDependencyTable() {
-  CACHE_READER_READ_SECTION(OBCC_DependencyTable, mpCachedDependTable,
-                            depend_tab);
-  return true;
-}
-
-
-bool CacheReader::checkDependency() {
-  if (mDependencies.size() != mpCachedDependTable->count) {
-    ALOGE("Dependencies count mismatch. (%lu vs %lu)\n",
-         (unsigned long)mDependencies.size(),
-         (unsigned long)mpCachedDependTable->count);
-    return false;
-  }
-
-  vector<char const *> &strPool = mpResult->mStringPool;
-  map<string, pair<uint32_t, unsigned char const *> >::iterator dep;
-
-  dep = mDependencies.begin();
-  for (size_t i = 0; i < mpCachedDependTable->count; ++i, ++dep) {
-    string const &depName = dep->first;
-    uint32_t depType = dep->second.first;
-    unsigned char const *depSHA1 = dep->second.second;
-
-    OBCC_Dependency *depCached =&mpCachedDependTable->table[i];
-    char const *depCachedName = strPool[depCached->res_name_strp_index];
-    uint32_t depCachedType = depCached->res_type;
-    unsigned char const *depCachedSHA1 = depCached->sha1;
-
-    if (depName != depCachedName) {
-      ALOGE("Cache dependency name mismatch:\n");
-      ALOGE("  given:  %s\n", depName.c_str());
-      ALOGE("  cached: %s\n", depCachedName);
-
-      return false;
-    }
-
-    if (memcmp(depSHA1, depCachedSHA1, 20) != 0) {
-      ALOGE("Cache dependency %s sha1 mismatch:\n", depCachedName);
-
-#define PRINT_SHA1(PREFIX, X, POSTFIX) \
-      ALOGE(PREFIX "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x" \
-                  "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x" POSTFIX, \
-           X[0], X[1], X[2], X[3], X[4], X[5], X[6], X[7], X[8], X[9], \
-           X[10],X[11],X[12],X[13],X[14],X[15],X[16],X[17],X[18],X[19]);
-
-      PRINT_SHA1("  given:  ", depSHA1, "\n");
-      PRINT_SHA1("  cached: ", depCachedSHA1, "\n");
-
-#undef PRINT_SHA1
-
-      return false;
-    }
-
-    if (depType != depCachedType) {
-      ALOGE("Cache dependency %s resource type mismatch.\n", depCachedName);
-      return false;
-    }
-  }
-
-  return true;
-}
-
-bool CacheReader::readExportVarList() {
-  CACHE_READER_READ_SECTION(OBCC_ExportVarList,
-                            mpResult->mpExportVars, export_var_list);
-  return true;
-}
-
-
-bool CacheReader::readExportFuncList() {
-  CACHE_READER_READ_SECTION(OBCC_ExportFuncList,
-                            mpResult->mpExportFuncs, export_func_list);
-  return true;
-}
-
-
-bool CacheReader::readPragmaList() {
-  CACHE_READER_READ_SECTION(OBCC_PragmaList, mpPragmaList, pragma_list);
-
-  vector<char const *> const &strPool = mpResult->mStringPool;
-  ScriptCached::PragmaList &pragmas = mpResult->mPragmas;
-
-  for (size_t i = 0; i < pragma_list_raw->count; ++i) {
-    OBCC_Pragma *pragma = &pragma_list_raw->list[i];
-    pragmas.push_back(make_pair(strPool[pragma->key_strp_index],
-                                strPool[pragma->value_strp_index]));
-  }
-
-  return true;
-}
-
-
-bool CacheReader::readObjectSlotList() {
-  CACHE_READER_READ_SECTION(OBCC_ObjectSlotList,
-                            mpResult->mpObjectSlotList, object_slot_list);
-  return true;
-}
-
-
-bool CacheReader::readFuncTable() {
-  CACHE_READER_READ_SECTION(OBCC_FuncTable, mpFuncTable, func_table);
-
-  vector<char const *> &strPool = mpResult->mStringPool;
-  ScriptCached::FuncTable &table = mpResult->mFunctions;
-  for (size_t i = 0; i < func_table_raw->count; ++i) {
-    OBCC_FuncInfo *func = &func_table_raw->table[i];
-    table.insert(make_pair(strPool[func->name_strp_index],
-                           make_pair(func->cached_addr, func->size)));
-  }
-
-  return true;
-}
-
-#undef CACHE_READER_READ_SECTION
-
-
-bool CacheReader::readContext() {
-  mpResult->mContext =
-    ContextManager::get().allocateContext(mpHeader->context_cached_addr,
-                                          mObjFile->getFD(), 0);
-
-  if (!mpResult->mContext) {
-    // Unable to allocate at cached address.  Give up.
-    mIsContextSlotNotAvail = true;
-    return false;
-
-    // TODO(logan): If relocation is fixed, we should try to allocate the
-    // code in different location, and relocate the context.
-  }
-
-  return true;
-}
-
-
-bool CacheReader::checkContext() {
-  uint32_t sum = mpHeader->context_parity_checksum;
-  uint32_t *ptr = reinterpret_cast<uint32_t *>(mpResult->mContext);
-
-  for (size_t i = 0; i < ContextManager::ContextSize / sizeof(uint32_t); ++i) {
-    sum ^= *ptr++;
-  }
-
-  if (sum != 0) {
-    ALOGE("Checksum check failed\n");
-    return false;
-  }
-
-  ALOGI("Passed checksum even parity verification.\n");
-  return true;
-}
-
-
-bool CacheReader::readRelocationTable() {
-  // TODO(logan): Not finished.
-  return true;
-}
-
-
-bool CacheReader::relocate() {
-  // TODO(logan): Not finished.
-  return true;
-}
-
-
-} // namespace bcc
diff --git a/lib/ExecutionEngine/OldJIT/CacheReader.h b/lib/ExecutionEngine/OldJIT/CacheReader.h
deleted file mode 100644
index a208ed6..0000000
--- a/lib/ExecutionEngine/OldJIT/CacheReader.h
+++ /dev/null
@@ -1,104 +0,0 @@
-/*
- * Copyright 2010, The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef BCC_CACHEREADER_H
-#define BCC_CACHEREADER_H
-
-#include "ScriptCached.h"
-
-#include <llvm/ADT/OwningPtr.h>
-
-#include <map>
-#include <string>
-#include <utility>
-
-#include <stddef.h>
-#include <stdint.h>
-
-struct OBCC_Header;
-
-namespace bcc {
-  class FileHandle;
-  class Script;
-
-  class CacheReader {
-  private:
-    FileHandle *mObjFile;
-    FileHandle *mInfoFile;
-    off_t mInfoFileSize;
-
-    OBCC_Header *mpHeader;
-    OBCC_DependencyTable *mpCachedDependTable;
-    OBCC_PragmaList *mpPragmaList;
-    OBCC_FuncTable *mpFuncTable;
-
-    llvm::OwningPtr<ScriptCached> mpResult;
-
-    std::map<std::string,
-             std::pair<uint32_t, unsigned char const *> > mDependencies;
-
-    bool mIsContextSlotNotAvail;
-
-  public:
-    CacheReader()
-      : mObjFile(NULL), mInfoFile(NULL), mInfoFileSize(0), mpHeader(NULL),
-        mpCachedDependTable(NULL), mpPragmaList(NULL), mpFuncTable(NULL),
-        mIsContextSlotNotAvail(false) {
-    }
-
-    ~CacheReader();
-
-    void addDependency(OBCC_ResourceType resType,
-                       std::string const &resName,
-                       unsigned char const *sha1) {
-      mDependencies.insert(std::make_pair(resName,
-                           std::make_pair((uint32_t)resType, sha1)));
-    }
-
-    ScriptCached *readCacheFile(FileHandle *objFile,
-                                FileHandle *infoFile,
-                                Script *s);
-
-    bool isContextSlotNotAvail() const {
-      return mIsContextSlotNotAvail;
-    }
-
-  private:
-    bool readHeader();
-    bool readStringPool();
-    bool readDependencyTable();
-    bool readExportVarList();
-    bool readExportFuncList();
-    bool readPragmaList();
-    bool readFuncTable();
-    bool readObjectSlotList();
-    bool readContext();
-    bool readRelocationTable();
-
-    bool checkFileSize();
-    bool checkHeader();
-    bool checkMachineIntType();
-    bool checkSectionOffsetAndSize();
-    bool checkStringPool();
-    bool checkDependency();
-    bool checkContext();
-
-    bool relocate();
-  };
-
-} // namespace bcc
-
-#endif // BCC_CACHEREADER_H
diff --git a/lib/ExecutionEngine/OldJIT/CacheWriter.cpp b/lib/ExecutionEngine/OldJIT/CacheWriter.cpp
deleted file mode 100644
index 36bf281..0000000
--- a/lib/ExecutionEngine/OldJIT/CacheWriter.cpp
+++ /dev/null
@@ -1,427 +0,0 @@
-/*
- * Copyright 2010, The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "CacheWriter.h"
-
-#include "ContextManager.h"
-#include "DebugHelper.h"
-#include "FileHandle.h"
-#include "Script.h"
-
-#include <map>
-#include <string>
-#include <vector>
-#include <utility>
-
-#include <stdint.h>
-#include <stdlib.h>
-#include <string.h>
-
-using namespace std;
-
-namespace bcc {
-
-CacheWriter::~CacheWriter() {
-#define CHECK_AND_FREE(VAR) if (VAR) { free(VAR); }
-
-  CHECK_AND_FREE(mpHeaderSection);
-  CHECK_AND_FREE(mpStringPoolSection);
-  CHECK_AND_FREE(mpDependencyTableSection);
-  //CHECK_AND_FREE(mpRelocationTableSection);
-  CHECK_AND_FREE(mpExportVarListSection);
-  CHECK_AND_FREE(mpExportFuncListSection);
-  CHECK_AND_FREE(mpPragmaListSection);
-  CHECK_AND_FREE(mpFuncTableSection);
-  CHECK_AND_FREE(mpObjectSlotSection);
-
-#undef CHECK_AND_FREE
-}
-
-bool CacheWriter::writeCacheFile(FileHandle *objFile,
-                                 FileHandle *infoFile,
-                                 Script *S,
-                                 uint32_t libRS_threadable) {
-  if (!objFile || objFile->getFD() < 0 ||
-      !infoFile || infoFile->getFD() < 0) {
-    return false;
-  }
-
-  mObjFile = objFile;
-  mInfoFile = infoFile;
-  mpOwner = S;
-
-  bool result = prepareHeader(libRS_threadable)
-             && prepareDependencyTable()
-             && prepareFuncTable()
-             && preparePragmaList()
-             //&& prepareRelocationTable()
-             && prepareStringPool()
-             && prepareExportVarList()
-             && prepareExportFuncList()
-             && prepareObjectSlotList()
-             && calcSectionOffset()
-             && calcContextChecksum()
-             && writeAll()
-             ;
-
-  return result;
-}
-
-
-bool CacheWriter::prepareHeader(uint32_t libRS_threadable) {
-  OBCC_Header *header = (OBCC_Header *)malloc(sizeof(OBCC_Header));
-
-  if (!header) {
-    ALOGE("Unable to allocate for header.\n");
-    return false;
-  }
-
-  mpHeaderSection = header;
-
-  // Initialize
-  memset(header, '\0', sizeof(OBCC_Header));
-
-  // Magic word and version
-  memcpy(header->magic, OBCC_MAGIC, 4);
-  memcpy(header->version, OBCC_VERSION, 4);
-
-  // Machine Integer Type
-  uint32_t number = 0x00000001;
-  header->endianness = (*reinterpret_cast<char *>(&number) == 1) ? 'e' : 'E';
-  header->sizeof_off_t = sizeof(off_t);
-  header->sizeof_size_t = sizeof(size_t);
-  header->sizeof_ptr_t = sizeof(void *);
-
-  // Context
-  header->context_cached_addr = mpOwner->getContext();
-
-  // libRS is threadable dirty hack
-  // TODO: This should be removed in the future
-  header->libRS_threadable = libRS_threadable;
-
-  return true;
-}
-
-
-bool CacheWriter::prepareDependencyTable() {
-  size_t tableSize = sizeof(OBCC_DependencyTable) +
-                     sizeof(OBCC_Dependency) * mDependencies.size();
-
-  OBCC_DependencyTable *tab = (OBCC_DependencyTable *)malloc(tableSize);
-
-  if (!tab) {
-    ALOGE("Unable to allocate for dependency table section.\n");
-    return false;
-  }
-
-  mpDependencyTableSection = tab;
-  mpHeaderSection->depend_tab_size = tableSize;
-
-  tab->count = mDependencies.size();
-
-  size_t i = 0;
-  for (map<string, pair<uint32_t, unsigned char const *> >::iterator
-       I = mDependencies.begin(), E = mDependencies.end(); I != E; ++I, ++i) {
-    OBCC_Dependency *dep = &tab->table[i];
-
-    dep->res_name_strp_index = addString(I->first.c_str(), I->first.size());
-    dep->res_type = I->second.first;
-    memcpy(dep->sha1, I->second.second, 20);
-  }
-
-  return true;
-}
-
-
-bool CacheWriter::prepareFuncTable() {
-  size_t funcCount = mpOwner->getFuncCount();
-
-  size_t tableSize = sizeof(OBCC_FuncTable) +
-                     sizeof(OBCC_FuncInfo) * funcCount;
-
-  OBCC_FuncTable *tab = (OBCC_FuncTable *)malloc(tableSize);
-
-  if (!tab) {
-    ALOGE("Unable to allocate for function table section.\n");
-    return false;
-  }
-
-  mpFuncTableSection = tab;
-  mpHeaderSection->func_table_size = tableSize;
-
-  tab->count = static_cast<size_t>(funcCount);
-
-  // Get the function informations
-  vector<FuncInfo> funcInfoList(funcCount);
-  mpOwner->getFuncInfoList(funcCount, &*funcInfoList.begin());
-
-  for (size_t i = 0; i < funcCount; ++i) {
-    FuncInfo *info = &funcInfoList[i];
-    OBCC_FuncInfo *outputInfo = &tab->table[i];
-
-    outputInfo->name_strp_index = addString(info->name, strlen(info->name));
-    outputInfo->cached_addr = info->addr;
-    outputInfo->size = info->size;
-  }
-
-  return true;
-}
-
-
-bool CacheWriter::preparePragmaList() {
-  size_t pragmaCount = mpOwner->getPragmaCount();
-
-  size_t listSize = sizeof(OBCC_PragmaList) +
-                    sizeof(OBCC_Pragma) * pragmaCount;
-
-  OBCC_PragmaList *list = (OBCC_PragmaList *)malloc(listSize);
-
-  if (!list) {
-    ALOGE("Unable to allocate for pragma list\n");
-    return false;
-  }
-
-  mpPragmaListSection = list;
-  mpHeaderSection->pragma_list_size = listSize;
-
-  list->count = pragmaCount;
-
-  vector<char const *> keyList(pragmaCount);
-  vector<char const *> valueList(pragmaCount);
-  mpOwner->getPragmaList(pragmaCount, &*keyList.begin(), &*valueList.begin());
-
-  for (size_t i = 0; i < pragmaCount; ++i) {
-    char const *key = keyList[i];
-    char const *value = valueList[i];
-
-    size_t keyLen = strlen(key);
-    size_t valueLen = strlen(value);
-
-    OBCC_Pragma *pragma = &list->list[i];
-    pragma->key_strp_index = addString(key, keyLen);
-    pragma->value_strp_index = addString(value, valueLen);
-  }
-
-  return true;
-}
-
-
-bool CacheWriter::prepareRelocationTable() {
-  // TODO(logan): Implement relocation table cache write.
-  return false;
-}
-
-
-bool CacheWriter::prepareStringPool() {
-  // Calculate string pool size
-  size_t size = sizeof(OBCC_StringPool) +
-                sizeof(OBCC_String) * mStringPool.size();
-
-  off_t strOffset = size;
-
-  for (size_t i = 0; i < mStringPool.size(); ++i) {
-    size += mStringPool[i].second + 1;
-  }
-
-  // Create string pool
-  OBCC_StringPool *pool = (OBCC_StringPool *)malloc(size);
-
-  if (!pool) {
-    ALOGE("Unable to allocate string pool.\n");
-    return false;
-  }
-
-  mpStringPoolSection = pool;
-  mpHeaderSection->str_pool_size = size;
-
-  pool->count = mStringPool.size();
-
-  char *strPtr = reinterpret_cast<char *>(pool) + strOffset;
-
-  for (size_t i = 0; i < mStringPool.size(); ++i) {
-    OBCC_String *str = &pool->list[i];
-
-    str->length = mStringPool[i].second;
-    str->offset = strOffset;
-    memcpy(strPtr, mStringPool[i].first, str->length);
-
-    strPtr += str->length;
-    *strPtr++ = '\0';
-
-    strOffset += str->length + 1;
-  }
-
-  return true;
-}
-
-
-bool CacheWriter::prepareExportVarList() {
-  size_t varCount = mpOwner->getExportVarCount();
-  size_t listSize = sizeof(OBCC_ExportVarList) + sizeof(void *) * varCount;
-
-  OBCC_ExportVarList *list = (OBCC_ExportVarList *)malloc(listSize);
-
-  if (!list) {
-    ALOGE("Unable to allocate for export variable list\n");
-    return false;
-  }
-
-  mpExportVarListSection = list;
-  mpHeaderSection->export_var_list_size = listSize;
-
-  list->count = static_cast<size_t>(varCount);
-
-  mpOwner->getExportVarList(varCount, list->cached_addr_list);
-  return true;
-}
-
-
-bool CacheWriter::prepareExportFuncList() {
-  size_t funcCount = mpOwner->getExportFuncCount();
-  size_t listSize = sizeof(OBCC_ExportFuncList) + sizeof(void *) * funcCount;
-
-  OBCC_ExportFuncList *list = (OBCC_ExportFuncList *)malloc(listSize);
-
-  if (!list) {
-    ALOGE("Unable to allocate for export function list\n");
-    return false;
-  }
-
-  mpExportFuncListSection = list;
-  mpHeaderSection->export_func_list_size = listSize;
-
-  list->count = static_cast<size_t>(funcCount);
-
-  mpOwner->getExportFuncList(funcCount, list->cached_addr_list);
-  return true;
-}
-
-
-bool CacheWriter::prepareObjectSlotList() {
-  size_t objectSlotCount = mpOwner->getObjectSlotCount();
-
-  size_t listSize = sizeof(OBCC_ObjectSlotList) +
-                    sizeof(uint32_t) * objectSlotCount;
-
-  OBCC_ObjectSlotList *list = (OBCC_ObjectSlotList *)malloc(listSize);
-
-  if (!list) {
-    ALOGE("Unable to allocate for object slot list\n");
-    return false;
-  }
-
-  mpObjectSlotSection = list;
-  mpHeaderSection->object_slot_list_size = listSize;
-
-  list->count = objectSlotCount;
-
-  mpOwner->getObjectSlotList(objectSlotCount, list->object_slot_list);
-  return true;
-}
-
-
-bool CacheWriter::calcSectionOffset() {
-  size_t offset = sizeof(OBCC_Header);
-
-#define OFFSET_INCREASE(NAME)                                               \
-  do {                                                                      \
-    /* Align to a word */                                                   \
-    size_t rem = offset % sizeof(int);                                      \
-    if (rem > 0) {                                                          \
-      offset += sizeof(int) - rem;                                          \
-    }                                                                       \
-                                                                            \
-    /* Save the offset and increase it */                                   \
-    mpHeaderSection->NAME##_offset = offset;                                \
-    offset += mpHeaderSection->NAME##_size;                                 \
-  } while (0)
-
-  OFFSET_INCREASE(str_pool);
-  OFFSET_INCREASE(depend_tab);
-  //OFFSET_INCREASE(reloc_tab);
-  OFFSET_INCREASE(export_var_list);
-  OFFSET_INCREASE(export_func_list);
-  OFFSET_INCREASE(pragma_list);
-  OFFSET_INCREASE(func_table);
-  OFFSET_INCREASE(object_slot_list);
-
-#undef OFFSET_INCREASE
-  return true;
-}
-
-
-bool CacheWriter::calcContextChecksum() {
-  uint32_t sum = 0;
-  uint32_t *ptr = reinterpret_cast<uint32_t *>(mpOwner->getContext());
-
-  for (size_t i = 0; i < ContextManager::ContextSize / sizeof(uint32_t); ++i) {
-    sum ^= *ptr++;
-  }
-
-  mpHeaderSection->context_parity_checksum = sum;
-  return true;
-}
-
-
-bool CacheWriter::writeAll() {
-#define WRITE_SECTION(NAME, OFFSET, SIZE, SECTION)                          \
-  do {                                                                      \
-    if (mInfoFile->seek(OFFSET, SEEK_SET) == -1) {                          \
-      ALOGE("Unable to seek to " #NAME " section for writing.\n");           \
-      return false;                                                         \
-    }                                                                       \
-                                                                            \
-    if (mInfoFile->write(reinterpret_cast<char *>(SECTION), (SIZE)) !=      \
-        static_cast<ssize_t>(SIZE)) {                                       \
-      ALOGE("Unable to write " #NAME " section to cache file.\n");           \
-      return false;                                                         \
-    }                                                                       \
-  } while (0)
-
-#define WRITE_SECTION_SIMPLE(NAME, SECTION)                                 \
-  WRITE_SECTION(NAME,                                                       \
-                mpHeaderSection->NAME##_offset,                             \
-                mpHeaderSection->NAME##_size,                               \
-                SECTION)
-
-  WRITE_SECTION(header, 0, sizeof(OBCC_Header), mpHeaderSection);
-
-  WRITE_SECTION_SIMPLE(str_pool, mpStringPoolSection);
-  WRITE_SECTION_SIMPLE(depend_tab, mpDependencyTableSection);
-  //WRITE_SECTION_SIMPLE(reloc_tab, mpRelocationTableSection);
-  WRITE_SECTION_SIMPLE(export_var_list, mpExportVarListSection);
-  WRITE_SECTION_SIMPLE(export_func_list, mpExportFuncListSection);
-  WRITE_SECTION_SIMPLE(pragma_list, mpPragmaListSection);
-  WRITE_SECTION_SIMPLE(func_table, mpFuncTableSection);
-  WRITE_SECTION_SIMPLE(object_slot_list, mpObjectSlotSection);
-
-#undef WRITE_SECTION_SIMPLE
-#undef WRITE_SECTION
-
-
-  // Write Context to Executable File
-  char const *context = (char const *)mpOwner->getContext();
-  size_t context_size = ContextManager::ContextSize;
-  if (mObjFile->write(context, context_size) != (ssize_t)context_size) {
-    ALOGE("Unable to write context image to executable file\n");
-    return false;
-  }
-
-  return true;
-}
-
-
-} // namespace bcc
diff --git a/lib/ExecutionEngine/OldJIT/CacheWriter.h b/lib/ExecutionEngine/OldJIT/CacheWriter.h
deleted file mode 100644
index d492d4a..0000000
--- a/lib/ExecutionEngine/OldJIT/CacheWriter.h
+++ /dev/null
@@ -1,101 +0,0 @@
-/*
- * Copyright 2010, The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef BCC_CACHEWRITER_H
-#define BCC_CACHEWRITER_H
-
-#include <bcc/bcc_cache.h>
-
-#include "FileHandle.h"
-
-#include <map>
-#include <string>
-#include <utility>
-#include <vector>
-
-namespace bcc {
-  class Script;
-
-  class CacheWriter {
-  private:
-    Script *mpOwner;
-
-    FileHandle *mObjFile;
-    FileHandle *mInfoFile;
-
-    std::vector<std::pair<char const *, size_t> > mStringPool;
-
-    std::map<std::string,
-             std::pair<uint32_t, unsigned char const *> > mDependencies;
-
-    OBCC_Header *mpHeaderSection;
-    OBCC_StringPool *mpStringPoolSection;
-    OBCC_DependencyTable *mpDependencyTableSection;
-    //OBCC_RelocationTable *mpRelocationTableSection;
-    OBCC_ExportVarList *mpExportVarListSection;
-    OBCC_ExportFuncList *mpExportFuncListSection;
-    OBCC_PragmaList *mpPragmaListSection;
-    OBCC_FuncTable *mpFuncTableSection;
-    OBCC_ObjectSlotList *mpObjectSlotSection;
-
-  public:
-    CacheWriter()
-      : mpHeaderSection(NULL), mpStringPoolSection(NULL),
-        mpDependencyTableSection(NULL), mpExportVarListSection(NULL),
-        mpExportFuncListSection(NULL), mpPragmaListSection(NULL),
-        mpFuncTableSection(NULL), mpObjectSlotSection(NULL) {
-    }
-
-    ~CacheWriter();
-
-    bool writeCacheFile(FileHandle *objFile,
-                        FileHandle *infoFile,
-                        Script *S,
-                        uint32_t libRS_threadable);
-
-    void addDependency(OBCC_ResourceType resType,
-                       std::string const &resName,
-                       unsigned char const *sha1) {
-      mDependencies.insert(std::make_pair(resName,
-                           std::make_pair((uint32_t)resType, sha1)));
-    }
-
-  private:
-    bool prepareHeader(uint32_t libRS_threadable);
-    bool prepareStringPool();
-    bool prepareDependencyTable();
-    bool prepareRelocationTable();
-    bool prepareExportVarList();
-    bool prepareExportFuncList();
-    bool preparePragmaList();
-    bool prepareFuncTable();
-    bool prepareObjectSlotList();
-
-    bool writeAll();
-
-    bool calcSectionOffset();
-    bool calcContextChecksum();
-
-    size_t addString(char const *str, size_t size) {
-      mStringPool.push_back(std::make_pair(str, size));
-      return mStringPool.size() - 1;
-    }
-
-  };
-
-} // namespace bcc
-
-#endif // BCC_CACHEWRITER_H
diff --git a/lib/ExecutionEngine/OldJIT/ContextManager.cpp b/lib/ExecutionEngine/OldJIT/ContextManager.cpp
deleted file mode 100644
index 5dca382..0000000
--- a/lib/ExecutionEngine/OldJIT/ContextManager.cpp
+++ /dev/null
@@ -1,197 +0,0 @@
-/*
- * copyright 2010, the android open source project
- *
- * licensed under the apache license, version 2.0 (the "license");
- * you may not use this file except in compliance with the license.
- * you may obtain a copy of the license at
- *
- *     http://www.apache.org/licenses/license-2.0
- *
- * unless required by applicable law or agreed to in writing, software
- * distributed under the license is distributed on an "as is" basis,
- * without warranties or conditions of any kind, either express or implied.
- * see the license for the specific language governing permissions and
- * limitations under the license.
- */
-
-#include "ContextManager.h"
-
-#include "DebugHelper.h"
-
-#include <llvm/Support/Mutex.h>
-#include <llvm/Support/MutexGuard.h>
-
-#include <errno.h>
-#include <sys/mman.h>
-#include <utils/threads.h>
-
-#include <stddef.h>
-#include <string.h>
-
-
-namespace bcc {
-
-// Starting address for context slots
-char * const ContextManager::ContextFixedAddr = BCC_CONTEXT_FIXED_ADDR_;
-
-// ContextManager singleton object
-ContextManager ContextManager::TheContextManager;
-
-
-ContextManager::ContextManager() {
-  // Initialize context slot occupation table to false
-  for (size_t i = 0; i < ContextSlotCount; ++i) {
-    mContextSlotOccupied[i] = false;
-  }
-}
-
-char *ContextManager::allocateContext() {
-  {
-    // Acquire mContextSlotOccupiedLock
-    llvm::MutexGuard Locked(mContextSlotOccupiedLock);
-
-    // Try to allocate context on the managed context slot.
-    for (size_t i = 0; i < ContextSlotCount; ++i) {
-      if (mContextSlotOccupied[i]) {
-        continue;
-      }
-
-      void *addr = ContextFixedAddr + ContextSize * i;
-      void *result = mmap(addr, ContextSize,
-                          PROT_READ | PROT_WRITE | PROT_EXEC,
-                          MAP_PRIVATE | MAP_ANON, -1, 0);
-
-      if (result == addr) {
-        ALOGI("Allocate bcc context. addr=%p\n", result);
-        mContextSlotOccupied[i] = true;
-        return static_cast<char *>(result);
-      }
-
-      if (result && result != MAP_FAILED) {
-        ALOGE("Unable to allocate. suggested=%p, result=%p\n", addr, result);
-        munmap(result, ContextSize);
-      }
-
-      ALOGE("Unable to allocate. addr=%p.  Retry ...\n", addr);
-    }
-    // Release mContextSlotOccupiedLock
-  }
-
-  // No slot available, allocate at arbitary address.
-  void *result = mmap(0, ContextSize, PROT_READ | PROT_WRITE | PROT_EXEC,
-                      MAP_PRIVATE | MAP_ANON, -1, 0);
-
-  if (!result || result == MAP_FAILED) {
-    ALOGE("Unable to mmap. (reason: %s)\n", strerror(errno));
-    return NULL;
-  }
-
-  ALOGI("Allocate bcc context. addr=%p\n", result);
-  return static_cast<char *>(result);
-}
-
-
-char *ContextManager::allocateContext(char *addr,
-                                      int imageFd, off_t imageOffset) {
-  // This function should only allocate context when address is an context
-  // slot address.  And the image offset is aligned to the pagesize.
-
-  if (imageFd < 0) {
-    ALOGE("Invalid file descriptor for bcc context image\n");
-    return NULL;
-  }
-
-  unsigned long pagesize = (unsigned long)sysconf(_SC_PAGESIZE);
-
-  if (imageOffset % pagesize > 0) {
-    ALOGE("BCC context image offset is not aligned to page size\n");
-    return NULL;
-  }
-
-  ssize_t slot = getSlotIndexFromAddress(addr);
-  if (slot < 0) {
-    ALOGE("Suggested address is not a bcc context slot address\n");
-    return NULL;
-  }
-
-  llvm::MutexGuard Locked(mContextSlotOccupiedLock);
-  if (mContextSlotOccupied[slot]) {
-    ALOGW("Suggested bcc context slot has been occupied.\n");
-    return NULL;
-  }
-
-  // ALOGI("addr=%x, imageFd=%d, imageOffset=%x", addr, imageFd, imageOffset);
-  void *result = mmap(addr, ContextSize,
-                      PROT_READ | PROT_WRITE | PROT_EXEC,
-                      MAP_PRIVATE, imageFd, imageOffset);
-
-  if (!result || result == MAP_FAILED) {
-    ALOGE("Unable to allocate. addr=%p\n", addr);
-    return NULL;
-  }
-
-  if (result != addr) {
-    ALOGE("Unable to allocate at suggested=%p, result=%p\n", addr, result);
-    munmap(result, ContextSize);
-    return NULL;
-  }
-
-  ALOGI("Allocate bcc context. addr=%p\n", addr);
-  mContextSlotOccupied[slot] = true;
-  return static_cast<char *>(result);
-}
-
-
-void ContextManager::deallocateContext(char *addr) {
-  if (!addr) {
-    return;
-  }
-
-  llvm::MutexGuard Locked(mContextSlotOccupiedLock);
-
-  ALOGI("Deallocate bcc context. addr=%p\n", addr);
-
-  // Unmap
-  if (munmap(addr, ContextSize) < 0) {
-    ALOGE("Unable to unmap. addr=%p (reason: %s)\n", addr, strerror(errno));
-    return;
-  }
-
-  // If the address is one of the context slot, then mark such slot
-  // freely available as well.
-  ssize_t slot = getSlotIndexFromAddress(addr);
-  if (slot >= 0) {
-    // Give the context slot back.
-    mContextSlotOccupied[slot] = false;
-  }
-}
-
-
-bool ContextManager::isManagingContext(char *addr) const {
-  ssize_t slot = getSlotIndexFromAddress(addr);
-
-  if (slot < 0) {
-    return false;
-  }
-
-  llvm::MutexGuard Locked(mContextSlotOccupiedLock);
-  return mContextSlotOccupied[slot];
-}
-
-
-ssize_t ContextManager::getSlotIndexFromAddress(char *addr) {
-  if (addr >= ContextFixedAddr) {
-    size_t offset = (size_t)(addr - ContextFixedAddr);
-    if (offset % ContextSize == 0) {
-      size_t slot = offset / ContextSize;
-      if (slot < ContextSlotCount) {
-        return slot;
-      }
-    }
-  }
-  return -1;
-}
-
-
-
-} // namespace bcc
diff --git a/lib/ExecutionEngine/OldJIT/ContextManager.h b/lib/ExecutionEngine/OldJIT/ContextManager.h
deleted file mode 100644
index f23c4a1..0000000
--- a/lib/ExecutionEngine/OldJIT/ContextManager.h
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * copyright 2010, the android open source project
- *
- * licensed under the apache license, version 2.0 (the "license");
- * you may not use this file except in compliance with the license.
- * you may obtain a copy of the license at
- *
- *     http://www.apache.org/licenses/license-2.0
- *
- * unless required by applicable law or agreed to in writing, software
- * distributed under the license is distributed on an "as is" basis,
- * without warranties or conditions of any kind, either express or implied.
- * see the license for the specific language governing permissions and
- * limitations under the license.
- */
-
-#ifndef BCC_CONTEXTMANAGER_H
-#define BCC_CONTEXTMANAGER_H
-
-#include <Config.h>
-
-#include <llvm/Support/Mutex.h>
-
-#include <unistd.h>
-#include <stddef.h>
-
-
-namespace bcc {
-
-  class ContextManager {
-  public:
-    // Starting address of context slot address space
-    static char * const ContextFixedAddr;
-
-    // Number of the context slots
-    static size_t const ContextSlotCount = BCC_CONTEXT_SLOT_COUNT_;
-
-    // Context size
-    static size_t const ContextCodeSize = BCC_CONTEXT_CODE_SIZE_;
-    static size_t const ContextDataSize = BCC_CONTEXT_DATA_SIZE_;
-    static size_t const ContextSize = ContextCodeSize + ContextDataSize;
-
-  private:
-    // Context manager singleton
-    static ContextManager TheContextManager;
-
-  private:
-    // Mutex lock for context slot occupation table
-    mutable llvm::sys::Mutex mContextSlotOccupiedLock;
-
-    // Context slot occupation table
-    bool mContextSlotOccupied[ContextSlotCount];
-
-    ContextManager();
-
-  public:
-    static ContextManager &get() {
-      return TheContextManager;
-    }
-
-    char *allocateContext();
-    char *allocateContext(char *addr, int imageFd, off_t imageOffset);
-    void deallocateContext(char *addr);
-
-    bool isManagingContext(char *addr) const;
-
-  private:
-    static ssize_t getSlotIndexFromAddress(char *addr);
-
-  };
-
-} // namespace bcc
-
-#endif // BCC_CONTEXTMANAGER_H
diff --git a/lib/ExecutionEngine/Script.cpp b/lib/ExecutionEngine/Script.cpp
index 4b0b406..3b67e04 100644
--- a/lib/ExecutionEngine/Script.cpp
+++ b/lib/ExecutionEngine/Script.cpp
@@ -18,19 +18,10 @@
 
 #include "Config.h"
 
-#if USE_OLD_JIT
-#include "OldJIT/CacheReader.h"
-#include "OldJIT/CacheWriter.h"
-#endif
-
 #include "MCCacheReader.h"
 #include "MCCacheWriter.h"
 #include "CompilerOption.h"
 
-#if USE_OLD_JIT
-#include "OldJIT/ContextManager.h"
-#endif
-
 #include "DebugHelper.h"
 #include "FileHandle.h"
 #include "GDBJITRegistrar.h"
@@ -294,9 +285,7 @@
     return 1;
   }
 
-#if USE_OLD_JIT
-  CacheReader reader;
-#elif USE_MCJIT
+#if USE_MCJIT
   MCCacheReader reader;
 
   // Register symbol lookup function
@@ -413,12 +402,7 @@
   // Note: If the address of the context is not in the context slot, then
   // we don't have to cache it.
 
-  if (
-#if USE_OLD_JIT
-      !mIsContextSlotNotAvail &&
-      ContextManager::get().isManagingContext(getContext()) &&
-#endif
-      isCacheable()) {
+  if (isCacheable()) {
 
     std::string objPath = getCachedObjectPath();
     std::string infoPath = getCacheInfoPath();
@@ -428,7 +412,7 @@
     // to modify its contents.  (The same script may be running concurrently in
     // the same process or a different process!)
     ::unlink(objPath.c_str());
-#if !USE_OLD_JIT && USE_MCJIT
+#if USE_MCJIT
     ::unlink(infoPath.c_str());
 #endif
 
@@ -438,9 +422,7 @@
     if (objFile.open(objPath.c_str(), OpenMode::Write) >= 0 &&
         infoFile.open(infoPath.c_str(), OpenMode::Write) >= 0) {
 
-#if USE_OLD_JIT
-      CacheWriter writer;
-#elif USE_MCJIT
+#if USE_MCJIT
       MCCacheWriter writer;
 #endif
 
@@ -798,29 +780,6 @@
 }
 
 
-#if USE_OLD_JIT
-char *Script::getContext() {
-  switch (mStatus) {
-
-#if USE_CACHE
-    case ScriptStatus::Cached: {
-      return mCached->getContext();
-    }
-#endif
-
-    case ScriptStatus::Compiled: {
-      return mCompiled->getContext();
-    }
-
-    default: {
-      mErrorCode = BCC_INVALID_OPERATION;
-      return NULL;
-    }
-  }
-}
-#endif
-
-
 int Script::registerSymbolCallback(BCCSymbolLookupFn pFn, void *pContext) {
   mpExtSymbolLookupFn = pFn;
   mpExtSymbolLookupFnContext = pContext;
diff --git a/lib/ExecutionEngine/Script.h b/lib/ExecutionEngine/Script.h
index b05fc07..9253871 100644
--- a/lib/ExecutionEngine/Script.h
+++ b/lib/ExecutionEngine/Script.h
@@ -81,17 +81,13 @@
     std::string mCacheName;
 
     inline std::string getCachedObjectPath() const {
-#if USE_OLD_JIT
-      return std::string(mCacheDir + mCacheName + ".jit-image");
-#elif USE_MCJIT
+#if USE_MCJIT
       return std::string(mCacheDir + mCacheName + ".o");
 #endif
     }
 
     inline std::string getCacheInfoPath() const {
-#if USE_OLD_JIT
-      return getCachedObjectPath().append(".oBCC");
-#elif USE_MCJIT
+#if USE_MCJIT
       return getCachedObjectPath().append(".info");
 #endif
     }
@@ -217,10 +213,6 @@
 
     int registerSymbolCallback(BCCSymbolLookupFn pFn, void *pContext);
 
-#if USE_OLD_JIT
-    char *getContext();
-#endif
-
     bool isCacheable() const;
 
     void setError(int error) {
diff --git a/lib/ExecutionEngine/ScriptCached.cpp b/lib/ExecutionEngine/ScriptCached.cpp
index 30fc3fd..03a4f7a 100644
--- a/lib/ExecutionEngine/ScriptCached.cpp
+++ b/lib/ExecutionEngine/ScriptCached.cpp
@@ -20,10 +20,6 @@
 
 #include <bcc/bcc_cache.h>
 
-#if USE_OLD_JIT
-#include "OldJIT/ContextManager.h"
-#endif
-
 #include "DebugHelper.h"
 
 #include <stdlib.h>
@@ -31,13 +27,6 @@
 namespace bcc {
 
 ScriptCached::~ScriptCached() {
-  // Deallocate the bcc script context
-#if USE_OLD_JIT
-  if (mContext) {
-    ContextManager::get().deallocateContext(mContext);
-  }
-#endif
-
   // Deallocate string pool, exported var list, exported func list
   if (mpStringPoolRaw) { free(mpStringPoolRaw); }
   if (mpExportVars) { free(mpExportVars); }
diff --git a/lib/ExecutionEngine/ScriptCached.h b/lib/ExecutionEngine/ScriptCached.h
index f18cb88..338dbdb 100644
--- a/lib/ExecutionEngine/ScriptCached.h
+++ b/lib/ExecutionEngine/ScriptCached.h
@@ -67,10 +67,6 @@
 
     FuncTable mFunctions;
 
-#if USE_OLD_JIT
-    char *mContext;
-#endif
-
 #if USE_MCJIT
     RSExecRef mRSExecutable;
     llvm::SmallVector<char, 1024> mCachedELFExecutable;
@@ -88,9 +84,6 @@
         mpExportFuncs(NULL),
         mpExportForEach(NULL),
         mpObjectSlotList(NULL),
-#if USE_OLD_JIT
-        mContext(NULL),
-#endif
         mpStringPoolRaw(NULL),
         mLibRSThreadable(false) {
     }
@@ -139,12 +132,6 @@
     void getObjectSlotList(size_t objectSlotListSize,
                            uint32_t *objectSlotList);
 
-#if USE_OLD_JIT
-    char *getContext() {
-      return mContext;
-    }
-#endif
-
 #if USE_MCJIT
     const char *getELF() const {
       return &*mCachedELFExecutable.begin();
diff --git a/lib/ExecutionEngine/ScriptCompiled.cpp b/lib/ExecutionEngine/ScriptCompiled.cpp
index 47f2bb4..3de7a7f 100644
--- a/lib/ExecutionEngine/ScriptCompiled.cpp
+++ b/lib/ExecutionEngine/ScriptCompiled.cpp
@@ -17,28 +17,11 @@
 #include "ScriptCompiled.h"
 
 #include "bcc_internal.h"
-#if USE_OLD_JIT
-#include "OldJIT/ContextManager.h"
-#endif
 #include "DebugHelper.h"
 
 namespace bcc {
 
 ScriptCompiled::~ScriptCompiled() {
-#if USE_OLD_JIT
-  // Deallocate the BCC context
-  if (mContext) {
-    ContextManager::get().deallocateContext(mContext);
-  }
-
-  // Delete the emitted function information
-  for (FuncInfoMap::iterator I = mEmittedFunctions.begin(),
-       E = mEmittedFunctions.end(); I != E; I++) {
-    if (I->second != NULL) {
-      delete I->second;
-    }
-  }
-#endif
 }
 
 void ScriptCompiled::getExportVarList(size_t varListSize, void **varList) {
@@ -126,11 +109,6 @@
 
 
 void *ScriptCompiled::lookup(const char *name) {
-#if USE_OLD_JIT
-  FuncInfoMap::const_iterator I = mEmittedFunctions.find(name);
-  return (I == mEmittedFunctions.end()) ? NULL : I->second->addr;
-#endif
-
 #if USE_MCJIT
   return mCompiler.getSymbolAddress(name);
 #endif
diff --git a/lib/ExecutionEngine/ScriptCompiled.h b/lib/ExecutionEngine/ScriptCompiled.h
index 4498f1a..36ef24d 100644
--- a/lib/ExecutionEngine/ScriptCompiled.h
+++ b/lib/ExecutionEngine/ScriptCompiled.h
@@ -65,16 +65,9 @@
 
     FuncInfoMap mEmittedFunctions;
 
-#if USE_OLD_JIT
-    char *mContext; // Context of BCC script (code and data)
-#endif
-
   public:
     ScriptCompiled(Script *owner)
       : mpOwner(owner), mCompiler(this)
-#if USE_OLD_JIT
-        , mContext(NULL)
-#endif
     {
     }
 
@@ -149,12 +142,6 @@
       return mpOwner->getUserDefinedExternalSymbols();
     }
 
-#if USE_OLD_JIT
-    char *getContext() {
-      return mContext;
-    }
-#endif
-
 #if USE_MCJIT
     const char *getELF() const {
       return &*mCompiler.getELF().begin();
diff --git a/lib/ExecutionEngine/SourceInfo.cpp b/lib/ExecutionEngine/SourceInfo.cpp
index 25c53e8..6efdf7e 100644
--- a/lib/ExecutionEngine/SourceInfo.cpp
+++ b/lib/ExecutionEngine/SourceInfo.cpp
@@ -17,10 +17,6 @@
 #include "SourceInfo.h"
 
 #if USE_CACHE
-#if USE_OLD_JIT
-#include "OldJIT/CacheReader.h"
-#include "OldJIT/CacheWriter.h"
-#endif
 #if USE_MCJIT
 #include "MCCacheWriter.h"
 #include "MCCacheReader.h"
@@ -216,11 +212,6 @@
   }
 }
 
-#if USE_OLD_JIT
-template void SourceInfo::introDependency<CacheReader>(CacheReader &);
-template void SourceInfo::introDependency<CacheWriter>(CacheWriter &);
-#endif
-
 #if USE_MCJIT
 template void SourceInfo::introDependency<MCCacheWriter>(MCCacheWriter &);
 template void SourceInfo::introDependency<MCCacheReader>(MCCacheReader &);