Author: mladen.turk(a)jboss.com
Date: 2007-10-22 05:22:07 -0400 (Mon, 22 Oct 2007)
New Revision: 1141
Modified:
trunk/sight/native/os/linux/module.c
Log:
Make sure modules are listed only once for each module with calculated mutiple sizes
Modified: trunk/sight/native/os/linux/module.c
===================================================================
--- trunk/sight/native/os/linux/module.c 2007-10-22 06:58:23 UTC (rev 1140)
+++ trunk/sight/native/os/linux/module.c 2007-10-22 09:22:07 UTC (rev 1141)
@@ -95,6 +95,13 @@
sight_unload_class(_E, &_clazzn);
}
+typedef struct module_addr_t module_addr_t;
+struct module_addr_t {
+ const char *path;
+ unsigned long long base;
+ unsigned long long size;
+};
+
static jobject new_module_class(SIGHT_STDARGS, jint pid, jint id)
{
if (_clazzn.i && _m0000n.i)
@@ -110,7 +117,8 @@
char spath[SIGHT_SBUFFER_SIZ];
jsize j, i = 0, nmods = 0;
jobjectArray mods = NULL;
- sight_arr_t *amods;
+ sight_arr_t *amods = NULL;
+ cache_table_t *cmods = NULL;
UNREFERENCED_O;
if (pid < 0)
@@ -121,41 +129,65 @@
throwAprIOException(_E, apr_get_os_error());
goto cleanup;
}
+ if (!(cmods = cache_new(4))) {
+ throwAprMemoryException(_E, THROW_FMARK,
+ apr_get_os_error());
+ goto cleanup;
+ }
+
for (j = 0; j < amods->siz; j++) {
- if (strchr(amods->arr[j], '/'))
- nmods++;
+ char *bp;
+ if (((bp = strchr(amods->arr[j], '/'))) {
+ module_addr_t *ma;
+ cache_entry_t *me;
+ char *bn = NULL;
+ char *p;
+ unsigned long long b, o;
+
+ if ((bn = strrchr(bp, '/')))
+ bn++;
+ else
+ continue;
+
+ me = cache_add(cmods, bn);
+ if (!me->data) {
+ if (!(ma = (module_addr_t *)sight_calloc(_E,
+ sizeof(module_addr_t),
+ THROW_FMARK))) {
+ goto cleanup;
+ }
+ ma->path = bp;
+ me->data = ma;
+ nmods++;
+ }
+ else
+ ma = (module_addr_t *)me->data;
+ b = strtoull(amods->arr[j], &p, 16);
+ if (p && *p == '-')
+ o = strtoull(p + 1, NULL, 16) - b;
+ else
+ o = 0;
+ if (!ma->base)
+ ma->base = b;
+ ma->size += o;
+ }
}
mods = (*_E)->NewObjectArray(_E, nmods, _clazzn.a, NULL);
if (!mods || (*_E)->ExceptionCheck(_E)) {
goto cleanup;
}
- for (j = 0; j < amods->siz; j++) {
- jobject m;
- char *bp = NULL;
- char *bn = NULL;
- char *p;
- unsigned long long b, o;
- if ((bp = strchr(amods->arr[j], '/'))) {
- if ((bn = strrchr(bp, '/')))
- bn++;
- }
- else
- continue;
- m = new_module_class(_E, _O, pid, i);
+ for (j = 0; j < cmods->siz; j++) {
+ module_addr_t *ma = (module_addr_t *)cmods->list[j]->data;
+ jobject m = new_module_class(_E, _O, pid, i);
if (!m || (*_E)->ExceptionCheck(_E)) {
mods = NULL;
goto cleanup;
}
- SET_IFIELD_S(0000, m, bn);
- SET_IFIELD_S(0001, m, bp);
- b = strtoull(amods->arr[j], &p, 16);
- if (p && *p == '-')
- o = strtoull(p + 1, NULL, 16) - b;
- else
- o = 0;
- SET_IFIELD_J(0002, m, b);
- SET_IFIELD_J(0003, m, o);
+ SET_IFIELD_S(0000, m, cmods->list[j]->key);
+ SET_IFIELD_S(0001, m, ma->path);
+ SET_IFIELD_J(0002, m, ma->base);
+ SET_IFIELD_J(0003, m, ma->size);
(*_E)->SetObjectArrayElement(_E, mods, i++, m);
(*_E)->DeleteLocalRef(_E, m);
@@ -166,5 +198,8 @@
cleanup:
if (amods)
sight_arr_free(amods);
+ if (cmods)
+ cache_free(cmods, NULL);
+
return mods;
}