Rename Compiler::mCodeDataAddr -> ScriptCompiled::mContext.
diff --git a/lib/bcc/CodeMemoryManager.cpp b/lib/bcc/CodeMemoryManager.cpp
index 805292e..054be1e 100644
--- a/lib/bcc/CodeMemoryManager.cpp
+++ b/lib/bcc/CodeMemoryManager.cpp
@@ -62,10 +62,6 @@
 
 
 CodeMemoryManager::~CodeMemoryManager() {
-  if (mpCodeMem) {
-    deallocateContext(mpCodeMem);
-  }
-
   mpCodeMem = 0;
   mpGVMem = 0;
 }
diff --git a/lib/bcc/Compiler.cpp b/lib/bcc/Compiler.cpp
index 326e503..b4611d8 100644
--- a/lib/bcc/Compiler.cpp
+++ b/lib/bcc/Compiler.cpp
@@ -265,7 +265,6 @@
     mUseCache(false),
     mCacheNew(false),
     mCacheLoadFailed(false),
-    mCodeDataAddr(NULL),
     mpSymbolLookupFn(NULL),
     mpSymbolLookupContext(NULL),
     mContext(NULL),
@@ -394,7 +393,8 @@
     setError("Failed to startup memory management for further compilation");
     goto on_bcc_compile_error;
   }
-  mCodeDataAddr = (char *) (mCodeMemMgr.get()->getCodeMemBase());
+
+  mpResult->mContext = (char *) (mCodeMemMgr.get()->getCodeMemBase());
 
   // Create code emitter
   if (!mCodeEmitter.get()) {
@@ -678,24 +678,6 @@
 
 
 Compiler::~Compiler() {
-#if 0
-  if (!mCodeMemMgr.get()) {
-    // mCodeDataAddr and mCacheMapAddr are from loadCacheFile and not
-    // managed by CodeMemoryManager.
-    LOGI("~Compiler(): mCodeDataAddr = %p\n", mCodeDataAddr); //sliao
-    if (mCodeDataAddr) {
-      deallocateContext(mCodeDataAddr);
-    }
-
-    if (mCacheMapAddr) {
-      free(mCacheMapAddr);
-    }
-
-    mCodeDataAddr = 0;
-    mCacheMapAddr = 0;
-  }
-#endif
-
   delete mModule;
   delete mContext;
 
diff --git a/lib/bcc/Compiler.h b/lib/bcc/Compiler.h
index 6d93c1a..8c83405 100644
--- a/lib/bcc/Compiler.h
+++ b/lib/bcc/Compiler.h
@@ -84,8 +84,6 @@
     bool mUseCache;         // Set by readBC()
     bool mCacheNew;         // Set by readBC()
     bool mCacheLoadFailed;  // Set by loadCacheFile() used by readBC()
-    char *mCodeDataAddr;    // Set by CodeMemoryManager if mCacheNew is true.
-                            // Used by genCacheFile() for dumping
 
     unsigned char mSourceSHA1[20];  // Set by readBC()
 
diff --git a/lib/bcc/Script.cpp b/lib/bcc/Script.cpp
index 74ecb98..6240ac7 100644
--- a/lib/bcc/Script.cpp
+++ b/lib/bcc/Script.cpp
@@ -331,6 +331,15 @@
   mCompiled->getFunctions(actualFunctionCount, maxFunctionCount, functions);
 }
 
+void const *Script::getContext() const {
+  if (mStatus != ScriptStatus::Compiled) {
+    //mErrorCode = BCC_INVALID_OPERATION;
+    return NULL;
+  }
+
+  return mCompiled->getContext();
+}
+
 
 void Script::getFunctionBinary(BCCchar *function,
                                BCCvoid **base,
diff --git a/lib/bcc/Script.h b/lib/bcc/Script.h
index 9326802..008f918 100644
--- a/lib/bcc/Script.h
+++ b/lib/bcc/Script.h
@@ -111,6 +111,8 @@
                            BCCvoid **base,
                            BCCsizei *length);
 
+    char const *getContext() const;
+
     void registerSymbolCallback(BCCSymbolLookupFn pFn, BCCvoid *pContext);
 
 
diff --git a/lib/bcc/ScriptCompiled.cpp b/lib/bcc/ScriptCompiled.cpp
index b34e949..5c07d99 100644
--- a/lib/bcc/ScriptCompiled.cpp
+++ b/lib/bcc/ScriptCompiled.cpp
@@ -19,48 +19,30 @@
 
 #include "ScriptCompiled.h"
 
+#include "ContextManager.h"
 #include "EmittedFuncInfo.h"
 
 namespace bcc {
 
 ScriptCompiled::~ScriptCompiled() {
+  // Deallocate the BCC context
+  if (mContext) {
+    deallocateContext(mContext);
+  }
+
+  // Delete the emitted function information
   for (EmittedFunctionsMapTy::iterator I = mEmittedFunctions.begin(),
        E = mEmittedFunctions.end(); I != E; I++) {
     if (I->second != NULL) {
       delete I->second;
     }
   }
-
-  mEmittedFunctions.clear();
 }
 
 void ScriptCompiled::getExportVars(BCCsizei *actualVarCount,
                                    BCCsizei maxVarCount,
                                    BCCvoid **vars) {
-  int varCount;
-
-#if 0
-  if (mUseCache && mCacheFd >= 0 && !mCacheNew) {
-    varCount = static_cast<int>(mCacheHdr->exportVarsCount);
-    if (actualVarCount)
-      *actualVarCount = varCount;
-    if (varCount > maxVarCount)
-      varCount = maxVarCount;
-    if (vars) {
-      uint32_t *cachedVars = (uint32_t *)(mCacheMapAddr +
-                                          mCacheHdr->exportVarsOffset);
-
-      for (int i = 0; i < varCount; i++) {
-        *vars = (BCCvoid *)((char *)(*cachedVars) + mCacheDiff);
-        vars++;
-        cachedVars++;
-      }
-    }
-    return;
-  }
-#endif
-
-  varCount = mExportVars.size();
+  int varCount = mExportVars.size();
   if (actualVarCount)
     *actualVarCount = varCount;
   if (varCount > maxVarCount)
@@ -77,30 +59,7 @@
 void ScriptCompiled::getExportFuncs(BCCsizei *actualFuncCount,
                                     BCCsizei maxFuncCount,
                                     BCCvoid **funcs) {
-  int funcCount;
-
-#if 0
-  if (mUseCache && mCacheFd >= 0 && !mCacheNew) {
-    funcCount = static_cast<int>(mCacheHdr->exportFuncsCount);
-    if (actualFuncCount)
-      *actualFuncCount = funcCount;
-    if (funcCount > maxFuncCount)
-      funcCount = maxFuncCount;
-    if (funcs) {
-      uint32_t *cachedFuncs = (uint32_t *)(mCacheMapAddr +
-                                           mCacheHdr->exportFuncsOffset);
-
-      for (int i = 0; i < funcCount; i++) {
-        *funcs = (BCCvoid *)((char *)(*cachedFuncs) + mCacheDiff);
-        funcs++;
-        cachedFuncs++;
-      }
-    }
-    return;
-  }
-#endif
-
-  funcCount = mExportFuncs.size();
+  int funcCount = mExportFuncs.size();
   if (actualFuncCount)
     *actualFuncCount = funcCount;
   if (funcCount > maxFuncCount)
@@ -117,34 +76,7 @@
 void ScriptCompiled::getPragmas(BCCsizei *actualStringCount,
                                 BCCsizei maxStringCount,
                                 BCCchar **strings) {
-  int stringCount;
-
-#if 0
-  if (mUseCache && mCacheFd >= 0 && !mCacheNew) {
-    stringCount = static_cast<int>(mCacheHdr->exportPragmasCount) * 2;
-
-    if (actualStringCount)
-      *actualStringCount = stringCount;
-
-    if (stringCount > maxStringCount)
-      stringCount = maxStringCount;
-
-    if (strings) {
-      char *pragmaTab = mCacheMapAddr + mCacheHdr->exportPragmasOffset;
-
-      oBCCPragmaEntry *cachedPragmaEntries = (oBCCPragmaEntry *)pragmaTab;
-
-      for (int i = 0; stringCount >= 2; stringCount -= 2, i++) {
-        *strings++ = pragmaTab + cachedPragmaEntries[i].pragmaNameOffset;
-        *strings++ = pragmaTab + cachedPragmaEntries[i].pragmaValueOffset;
-      }
-    }
-
-    return;
-  }
-#endif
-
-  stringCount = mPragmas.size() * 2;
+  int stringCount = mPragmas.size() * 2;
 
   if (actualStringCount)
     *actualStringCount = stringCount;
@@ -162,17 +94,6 @@
 
 
 void *ScriptCompiled::lookup(const char *name) {
-#if 0
-  if (mUseCache && mCacheFd >= 0 && !mCacheNew) {
-    if (!strcmp(name, "root")) {
-      addr = reinterpret_cast<void *>(mCacheHdr->rootAddr);
-    } else if (!strcmp(name, "init")) {
-      addr = reinterpret_cast<void *>(mCacheHdr->initAddr);
-    }
-    return addr;
-  }
-#endif
-
   EmittedFunctionsMapTy::const_iterator I = mEmittedFunctions.find(name);
   return (I == mEmittedFunctions.end()) ? NULL : I->second->Code;
 }
diff --git a/lib/bcc/ScriptCompiled.h b/lib/bcc/ScriptCompiled.h
index 786865d..ce0ad9c 100644
--- a/lib/bcc/ScriptCompiled.h
+++ b/lib/bcc/ScriptCompiled.h
@@ -50,11 +50,14 @@
 
     Compiler mCompiler;
 
-    PragmaList mPragmas;
     ExportVarList mExportVars;
     ExportFuncList mExportFuncs;
+    PragmaList mPragmas;
+
     EmittedFunctionsMapTy mEmittedFunctions;
 
+    char *mContext; // Context of BCC script (code and data)
+
   public:
     ScriptCompiled(Script *owner) : mpOwner(owner), mCompiler(this) {
     }
@@ -102,6 +105,10 @@
                            BCCvoid **base,
                            BCCsizei *length);
 
+    char const *getContext() const {
+      return mContext;
+    }
+
     void registerSymbolCallback(BCCSymbolLookupFn pFn, BCCvoid *pContext) {
       mCompiler.registerSymbolCallback(pFn, pContext);
     }