blob: a7d21f74f4df98f6bf339ec0cbf88499fcec1f29 [file] [log] [blame]
Loganf7f0ac52011-01-07 03:53:43 +08001/*
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
Shih-wei Liao3cafd222011-06-21 11:58:27 -070017#include "Config.h"
18
Loganf7f0ac52011-01-07 03:53:43 +080019#include "ScriptCached.h"
20
21#include <bcc/bcc_cache.h>
22
Logan Chiend2a5f302011-07-19 20:32:25 +080023#if USE_OLD_JIT
24#include "OldJIT/ContextManager.h"
25#endif
26
Logan4dcd6792011-02-28 05:12:00 +080027#include "DebugHelper.h"
Loganf7f0ac52011-01-07 03:53:43 +080028
Logan856ceb22011-01-07 05:21:26 +080029#include <stdlib.h>
30
Loganf7f0ac52011-01-07 03:53:43 +080031namespace bcc {
32
33ScriptCached::~ScriptCached() {
34 // Deallocate the bcc script context
Logan Chiend2a5f302011-07-19 20:32:25 +080035#if USE_OLD_JIT
Loganf7f0ac52011-01-07 03:53:43 +080036 if (mContext) {
Logan1dc63142011-02-25 17:14:51 +080037 ContextManager::get().deallocateContext(mContext);
Loganf7f0ac52011-01-07 03:53:43 +080038 }
Logan Chiend2a5f302011-07-19 20:32:25 +080039#endif
Loganf7f0ac52011-01-07 03:53:43 +080040
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); }
Stephen Hines071288a2011-01-27 14:38:26 -080045 if (mpObjectSlotList) { free(mpObjectSlotList); }
Loganf7f0ac52011-01-07 03:53:43 +080046}
47
Loganbe79ada2011-01-13 01:33:45 +080048void ScriptCached::getExportVarList(size_t varListSize, void **varList) {
49 if (varList) {
50 size_t varCount = getExportVarCount();
Loganf7f0ac52011-01-07 03:53:43 +080051
Loganbe79ada2011-01-13 01:33:45 +080052 if (varCount > varListSize) {
53 varCount = varListSize;
Loganf7f0ac52011-01-07 03:53:43 +080054 }
Loganbe79ada2011-01-13 01:33:45 +080055
56 memcpy(varList, mpExportVars->cached_addr_list, sizeof(void *) * varCount);
Loganf7f0ac52011-01-07 03:53:43 +080057 }
58}
59
60
Loganbe79ada2011-01-13 01:33:45 +080061void ScriptCached::getExportFuncList(size_t funcListSize, void **funcList) {
62 if (funcList) {
63 size_t funcCount = getExportFuncCount();
Loganf7f0ac52011-01-07 03:53:43 +080064
Loganbe79ada2011-01-13 01:33:45 +080065 if (funcCount > funcListSize) {
66 funcCount = funcListSize;
Loganf7f0ac52011-01-07 03:53:43 +080067 }
Loganbe79ada2011-01-13 01:33:45 +080068
69 memcpy(funcList, mpExportFuncs->cached_addr_list,
70 sizeof(void *) * funcCount);
Loganf7f0ac52011-01-07 03:53:43 +080071 }
72}
73
74
Loganbe79ada2011-01-13 01:33:45 +080075void ScriptCached::getPragmaList(size_t pragmaListSize,
76 char const **keyList,
77 char const **valueList) {
78 size_t pragmaCount = getPragmaCount();
Loganf7f0ac52011-01-07 03:53:43 +080079
Loganbe79ada2011-01-13 01:33:45 +080080 if (pragmaCount > pragmaListSize) {
81 pragmaCount = pragmaListSize;
82 }
Loganf7f0ac52011-01-07 03:53:43 +080083
Loganbe79ada2011-01-13 01:33:45 +080084 if (keyList) {
85 for (size_t i = 0; i < pragmaCount; ++i) {
86 *keyList++ = mPragmas[i].first;
87 }
88 }
Loganf7f0ac52011-01-07 03:53:43 +080089
Loganbe79ada2011-01-13 01:33:45 +080090 if (valueList) {
91 for (size_t i = 0; i < pragmaCount; ++i) {
92 *valueList++ = mPragmas[i].second;
Loganf7f0ac52011-01-07 03:53:43 +080093 }
94 }
95}
96
97
Stephen Hines071288a2011-01-27 14:38:26 -080098void 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
Loganf7f0ac52011-01-07 03:53:43 +0800113void *ScriptCached::lookup(const char *name) {
Shih-wei Liao5e3e0ce2011-06-17 13:59:46 -0700114#if USE_MCJIT
115 return rsloaderGetSymbolAddress(mRSExecutable, name);
116#endif
Logan216ec712011-01-07 12:12:31 +0800117 FuncTable::const_iterator I = mFunctions.find(name);
118 return (I == mFunctions.end()) ? NULL : I->second.first;
Loganf7f0ac52011-01-07 03:53:43 +0800119}
120
Loganf340bf72011-01-14 17:51:40 +0800121void ScriptCached::getFuncInfoList(size_t funcInfoListSize,
122 FuncInfo *funcInfoList) {
123 if (funcInfoList) {
Loganbe79ada2011-01-13 01:33:45 +0800124 size_t funcCount = getFuncCount();
Loganf7f0ac52011-01-07 03:53:43 +0800125
Loganf340bf72011-01-14 17:51:40 +0800126 if (funcCount > funcInfoListSize) {
127 funcCount = funcInfoListSize;
Loganbe79ada2011-01-13 01:33:45 +0800128 }
129
Loganf340bf72011-01-14 17:51:40 +0800130 FuncInfo *info = funcInfoList;
Logan216ec712011-01-07 12:12:31 +0800131 for (FuncTable::const_iterator
132 I = mFunctions.begin(), E = mFunctions.end();
Loganf340bf72011-01-14 17:51:40 +0800133 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;
Logan216ec712011-01-07 12:12:31 +0800137 }
Loganf7f0ac52011-01-07 03:53:43 +0800138 }
139}
140
141
Loganf7f0ac52011-01-07 03:53:43 +0800142} // namespace bcc