summaryrefslogtreecommitdiff
path: root/rts/RtsSymbolInfo.c
diff options
context:
space:
mode:
authorTamar Christina <tamar@zhox.com>2016-06-03 21:42:16 +0200
committerBen Gamari <ben@smart-cactus.org>2016-06-03 21:42:32 +0200
commit37473722960a1066c3b45c94377ba08769b1375b (patch)
treecdaebe9089fc39d1077c765cfe152f4176f2afb4 /rts/RtsSymbolInfo.c
parent1dadd9a91454bb098e9c47d6c034b07e2e1e2529 (diff)
downloadhaskell-37473722960a1066c3b45c94377ba08769b1375b.tar.gz
Refactored SymbolInfo to lower memory usage in RTS
Previously as part of #11223 a new struct `SymbolInfo` was introduced to keep track it the weak symbol status of a symbol. This structure also kept a copy of the calculated address of the symbol which turns out was useful in ignoring non-weak zero-valued symbols. The information was kept in an array so it means for every symbol two extra bytes were kept even though the vast majority of symbols are non-weak and non-zero valued. This changes the array into a sparse map keeping this information only for the symbols that are weak or zero-valued. This allows for a reduction in the amount of information needed to be kept while giving up a small (negligable) hit in performance as this information now has to be looked up in hashmaps. Test Plan: ./validate on all platforms that use the runtime linker. For unix platforms please ensure `DYNAMIC_GHC_PROGRAMS=NO` is added to your validate file. Reviewers: simonmar, austin, erikd, bgamari Reviewed By: simonmar, bgamari Subscribers: thomie, #ghc_windows_task_force Differential Revision: https://phabricator.haskell.org/D2184 GHC Trac Issues: #11816
Diffstat (limited to 'rts/RtsSymbolInfo.c')
-rw-r--r--rts/RtsSymbolInfo.c72
1 files changed, 72 insertions, 0 deletions
diff --git a/rts/RtsSymbolInfo.c b/rts/RtsSymbolInfo.c
new file mode 100644
index 0000000000..6688d9c9ba
--- /dev/null
+++ b/rts/RtsSymbolInfo.c
@@ -0,0 +1,72 @@
+/* -----------------------------------------------------------------------------
+ *
+ * (c) The GHC Team, 2000-2015
+ *
+ * RTS Symbols
+ *
+ * ---------------------------------------------------------------------------*/
+
+#include "ghcplatform.h"
+#include "RtsSymbolInfo.h"
+
+#include "Rts.h"
+#include "HsFFI.h"
+
+#include "Hash.h"
+#include "RtsUtils.h"
+
+typedef struct _SymbolInfo {
+ /* Determines if the
+ symbol is weak */
+ HsBool isWeak;
+
+} SymbolInfo;
+
+/* -----------------------------------------------------------------------------
+* Performs a check to see if the symbol at the given address
+* is a weak symbol or not.
+*
+* Returns: HS_BOOL_TRUE on symbol being weak, else HS_BOOL_FALSE
+*/
+HsBool isSymbolWeak(ObjectCode *owner, void *label)
+{
+ SymbolInfo *info;
+ if (owner
+ && label
+ && owner->extraInfos
+ && (info = lookupStrHashTable(owner->extraInfos, label)) != NULL)
+ {
+ return info->isWeak;
+ }
+
+ return HS_BOOL_FALSE;
+}
+
+/* -----------------------------------------------------------------------------
+* Marks the symbol at the given address as weak or not.
+* If the extra symbol infos table has not been initialized
+* yet this will create and allocate a new Hashtable
+*/
+void setWeakSymbol(ObjectCode *owner, void *label)
+{
+ SymbolInfo *info;
+ if (owner && label)
+ {
+ info = NULL;
+ if (!owner->extraInfos)
+ {
+ owner->extraInfos = allocStrHashTable();
+ }
+ else {
+ info = lookupStrHashTable(owner->extraInfos, label);
+ }
+
+ if (!info){
+ info = stgMallocBytes(sizeof(SymbolInfo), "setWeakSymbol");
+ }
+
+ info->isWeak = HS_BOOL_TRUE;
+
+ insertStrHashTable(owner->extraInfos, label, info);
+ }
+}