7875fe1acd
1) JIT compilation/optimization now occurs per-function, and only when functions are first used. We're now officially a whole-method JIT rather than an AOT compiler (albiet, still a simple JIT). This has two implications: Functions are now much better abstracted internally, and loading a plugin is now much less expensive. If a function contains calls to other functions, THOSE functions are only compiled when they're invoked as well. 2) I've removed debug mode. We always show full backtraces now, as there was a very cheap way to implement this which really cleaned up everything. This is great for a number of reasons -- there's less code, the JIT is better designed, we don't need to relocate debug tables, and best of all we no longer have to tell users to enable debug mode at their own expense. --HG-- extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%402459
145 lines
3.0 KiB
C++
145 lines
3.0 KiB
C++
#include "NativeOwner.h"
|
|
#include "ShareSys.h"
|
|
#include "PluginSys.h"
|
|
|
|
CNativeOwner::CNativeOwner() : m_nMarkSerial(0)
|
|
{
|
|
}
|
|
|
|
void CNativeOwner::SetMarkSerial(unsigned int serial)
|
|
{
|
|
m_nMarkSerial = serial;
|
|
}
|
|
|
|
unsigned int CNativeOwner::GetMarkSerial()
|
|
{
|
|
return m_nMarkSerial;
|
|
}
|
|
|
|
void CNativeOwner::AddDependent(CPlugin *pPlugin)
|
|
{
|
|
m_Dependents.push_back(pPlugin);
|
|
}
|
|
|
|
void CNativeOwner::AddWeakRef(const WeakNative & ref)
|
|
{
|
|
m_WeakRefs.push_back(ref);
|
|
}
|
|
|
|
void CNativeOwner::AddNatives(const sp_nativeinfo_t *natives)
|
|
{
|
|
NativeEntry *pEntry;
|
|
|
|
for (unsigned int i = 0; natives[i].func != NULL && natives[i].name != NULL; i++)
|
|
{
|
|
if ((pEntry = g_ShareSys.AddNativeToCache(this, &natives[i])) == NULL)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
m_Natives.push_back(pEntry);
|
|
}
|
|
}
|
|
|
|
void CNativeOwner::PropogateMarkSerial(unsigned int serial)
|
|
{
|
|
CNativeOwner *pOwner;
|
|
List<CPlugin *>::iterator iter;
|
|
|
|
for (iter = m_Dependents.begin();
|
|
iter != m_Dependents.end();
|
|
iter++)
|
|
{
|
|
pOwner = (*iter);
|
|
pOwner->SetMarkSerial(serial);
|
|
}
|
|
}
|
|
|
|
void CNativeOwner::UnbindWeakRef(const WeakNative & ref)
|
|
{
|
|
sp_native_t *native;
|
|
IPluginContext *pContext;
|
|
|
|
pContext = ref.pl->GetBaseContext();
|
|
if ((pContext->GetNativeByIndex(ref.idx, &native)) == SP_ERROR_NONE)
|
|
{
|
|
/* If there is no reference, the native must be unbound */
|
|
if (ref.entry == NULL)
|
|
{
|
|
native->status = SP_NATIVE_UNBOUND;
|
|
native->pfn = NULL;
|
|
}
|
|
/* If we've cached a reference, it's a core native we can
|
|
* rebind back to its original (this was a replacement).
|
|
*/
|
|
else
|
|
{
|
|
native->pfn = ref.entry->func;
|
|
}
|
|
}
|
|
}
|
|
|
|
void CNativeOwner::DropEverything()
|
|
{
|
|
NativeEntry *pEntry;
|
|
List<WeakNative>::iterator iter;
|
|
List<NativeEntry *>::iterator ntv_iter;
|
|
|
|
/* Unbind and remove all weak references to us */
|
|
iter = m_WeakRefs.begin();
|
|
while (iter != m_WeakRefs.end())
|
|
{
|
|
UnbindWeakRef((*iter));
|
|
iter = m_WeakRefs.erase(iter);
|
|
}
|
|
|
|
/* Unmark our replacement natives */
|
|
ntv_iter = m_ReplacedNatives.begin();
|
|
while (ntv_iter != m_ReplacedNatives.end())
|
|
{
|
|
pEntry = (*ntv_iter);
|
|
pEntry->replacement.func = NULL;
|
|
pEntry->replacement.owner = NULL;
|
|
ntv_iter = m_ReplacedNatives.erase(ntv_iter);
|
|
}
|
|
|
|
/* Strip all of our natives from the cache */
|
|
ntv_iter = m_Natives.begin();
|
|
while (ntv_iter != m_Natives.end())
|
|
{
|
|
g_ShareSys.ClearNativeFromCache(this, (*ntv_iter)->name);
|
|
ntv_iter = m_Natives.erase(ntv_iter);
|
|
}
|
|
}
|
|
|
|
void CNativeOwner::DropWeakRefsTo(CPlugin *pPlugin)
|
|
{
|
|
List<WeakNative>::iterator iter;
|
|
|
|
iter = m_WeakRefs.begin();
|
|
while (iter != m_WeakRefs.end())
|
|
{
|
|
WeakNative & ref = (*iter);
|
|
|
|
if (ref.pl == pPlugin)
|
|
{
|
|
iter = m_WeakRefs.erase(iter);
|
|
}
|
|
else
|
|
{
|
|
iter++;
|
|
}
|
|
}
|
|
}
|
|
|
|
void CNativeOwner::DropRefsTo(CPlugin *pPlugin)
|
|
{
|
|
m_Dependents.remove(pPlugin);
|
|
DropWeakRefsTo(pPlugin);
|
|
}
|
|
|
|
void CNativeOwner::AddReplacedNative(NativeEntry *pEntry)
|
|
{
|
|
m_ReplacedNatives.push_back(pEntry);
|
|
}
|