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 #include "Config.h" 18 19 #include "ScriptCached.h" 20 21 #include <bcc/bcc_cache.h> 22 23 #if USE_OLD_JIT 24 #include "OldJIT/ContextManager.h" 25 #endif 26 27 #include "DebugHelper.h" 28 29 #include <stdlib.h> 30 31 namespace bcc { 32 33 ScriptCached::~ScriptCached() { 34 // Deallocate the bcc script context 35 #if USE_OLD_JIT 36 if (mContext) { 37 ContextManager::get().deallocateContext(mContext); 38 } 39 #endif 40 41 // Deallocate string pool, exported var list, exported func list 42 if (mpStringPoolRaw) { free(mpStringPoolRaw); } 43 if (mpExportVars) { free(mpExportVars); } 44 if (mpExportFuncs) { free(mpExportFuncs); } 45 if (mpObjectSlotList) { free(mpObjectSlotList); } 46 } 47 48 void ScriptCached::getExportVarList(size_t varListSize, void **varList) { 49 if (varList) { 50 size_t varCount = getExportVarCount(); 51 52 if (varCount > varListSize) { 53 varCount = varListSize; 54 } 55 56 memcpy(varList, mpExportVars->cached_addr_list, sizeof(void *) * varCount); 57 } 58 } 59 60 61 void ScriptCached::getExportFuncList(size_t funcListSize, void **funcList) { 62 if (funcList) { 63 size_t funcCount = getExportFuncCount(); 64 65 if (funcCount > funcListSize) { 66 funcCount = funcListSize; 67 } 68 69 memcpy(funcList, mpExportFuncs->cached_addr_list, 70 sizeof(void *) * funcCount); 71 } 72 } 73 74 75 void ScriptCached::getPragmaList(size_t pragmaListSize, 76 char const **keyList, 77 char const **valueList) { 78 size_t pragmaCount = getPragmaCount(); 79 80 if (pragmaCount > pragmaListSize) { 81 pragmaCount = pragmaListSize; 82 } 83 84 if (keyList) { 85 for (size_t i = 0; i < pragmaCount; ++i) { 86 *keyList++ = mPragmas[i].first; 87 } 88 } 89 90 if (valueList) { 91 for (size_t i = 0; i < pragmaCount; ++i) { 92 *valueList++ = mPragmas[i].second; 93 } 94 } 95 } 96 97 98 void ScriptCached::getObjectSlotList(size_t objectSlotListSize, 99 uint32_t *objectSlotList) { 100 if (objectSlotList) { 101 size_t objectSlotCount = getObjectSlotCount(); 102 103 if (objectSlotCount > objectSlotListSize) { 104 objectSlotCount = objectSlotListSize; 105 } 106 107 memcpy(objectSlotList, mpObjectSlotList->object_slot_list, 108 sizeof(uint32_t) * objectSlotCount); 109 } 110 } 111 112 113 void *ScriptCached::lookup(const char *name) { 114 #if USE_MCJIT 115 return rsloaderGetSymbolAddress(mRSExecutable, name); 116 #endif 117 FuncTable::const_iterator I = mFunctions.find(name); 118 return (I == mFunctions.end()) ? NULL : I->second.first; 119 } 120 121 void ScriptCached::getFuncInfoList(size_t funcInfoListSize, 122 FuncInfo *funcInfoList) { 123 if (funcInfoList) { 124 size_t funcCount = getFuncCount(); 125 126 if (funcCount > funcInfoListSize) { 127 funcCount = funcInfoListSize; 128 } 129 130 FuncInfo *info = funcInfoList; 131 for (FuncTable::const_iterator 132 I = mFunctions.begin(), E = mFunctions.end(); 133 I != E && funcCount > 0; ++I, ++info, --funcCount) { 134 info->name = I->first.c_str(); 135 info->addr = I->second.first; 136 info->size = I->second.second; 137 } 138 } 139 } 140 141 142 } // namespace bcc 143