Example #1
0
static void JNICALL dumperThreadMain(__UNUSED__ jvmtiEnv* jvmti, JNIEnv* jni_env, __UNUSED__ void* arg)
{
	char* internalLeaksString;

    if (JNI_FALSE != __sync_lock_test_and_set(&gdata->dumpInProgress, JNI_TRUE))
    {
    	alert("Another dump is already in progress");
    	return;
    }
	gdata->numberOfLeaks = 0;
	initThreadData(jni_env);

	if (gdata->run_gc)
	{
		jvmtiError err;
    	debug("jleaker: Running garbage collection\n");
    	err = (*jvmti)->ForceGarbageCollection(jvmti);
    	if (err) alert("jleaker: Failed to run GC\n");
	}

    establish_connection(gdata->tcp_port);

    begin_xml_output();
    open_xml_element("memory-leaks", NULL);

	startTimer(&getThreadData()->timer, 0);

	tagAllMapsAndCollections();
	findLeaksInTaggedObjects();

	close_xml_element("memory-leaks");

	close_connection();

	stopTimer(&getThreadData()->timer, "Finished leak detection");
    releaseThreadData();
    
	internalLeaksString = findInternalMallocsLeaks();
    if (NULL != internalLeaksString)
    {
		alert("Internal jleaker error: %s\n", internalLeaksString);
		free(internalLeaksString);
    }
    if (gdata->self_check)
    {
    	selfCheck();
    }
	gdata->dumpInProgress = JNI_FALSE;
}
void ProfilerCUDA::setCurrentThreadName(const std::string &name)
{
    {
        std::lock_guard<std::mutex> lock(m_mutex);

        //Search for a thread data with the same name
        for(auto it=m_threads.begin(),end=m_threads.end(); it!=end; ++it)
        {
            ProfilerCUDA::ThreadData &data = *it->second;
            if(data.getName() == name)
            {
                //Match!
                //Update the id
                data.setId(std::this_thread::get_id());

                //Update the thread map
                std::unique_ptr<ThreadData> dataPtr = std::move(it->second);
                m_threads.erase(it);
                m_threads.emplace(data.getId(), std::move(dataPtr));
                return;
            }
        }
    }

    //Nobody with the same name
    auto &data = *getThreadData();
    data.setName(name);
}
ProfilerCUDA::ProfilerCUDA(dwContextHandle_t ctx)
    : m_ctx(ctx)
    , m_showTotals(false)
    , m_totalsFactor(1)
{
    getThreadData()->setName("main");
}
Example #4
0
pte_osResult pte_osThreadStart(pte_osThreadHandle osThreadHandle)
{
    psl1ghtThreadData *pThreadData = getThreadData(osThreadHandle);

    sysThreadSetPriority(osThreadHandle, pThreadData->priority);

    return PTE_OS_OK;
}
Example #5
0
/*
 * This has to be cancellable, so we can't just call sceKernelWaitThreadEnd.
 * Instead, poll on this in a loop, like we do for a cancellable semaphore.
 */
pte_osResult pte_osThreadWaitForEnd(pte_osThreadHandle threadHandle)
{
    pte_osResult osResult;
    psl1ghtThreadData *pThreadData;
    u64 result;

    pThreadData = getThreadData(threadHandle);

    if (pThreadData == NULL)
    {
        sysThreadJoin (threadHandle, &result);
        osResult = PTE_OS_OK;
    }
    else
    {
        while (1)
        {
            if (pThreadData->ended == 1)
            {
                /* Thread has ended */
                osResult = PTE_OS_OK;
                break;
            }
            else
            {
                s32 count;

                if (sysSemGetValue (pThreadData->cancelSem, &count) == 0)
                {
                    if (count > 0)
                    {
                        osResult = PTE_OS_INTERRUPTED;
                        break;
                    }
                    else
                    {
                        /* Nothing found and not timed out yet; let's yield so we're not
                         * in busy loop.
                         */
                        sysThreadYield ();
                    }
                }
                else
                {
                    osResult = PTE_OS_GENERAL_FAILURE;
                    break;
                }
            }
        }
    }


    return osResult;
}
Example #6
0
void YAC_ThreadPool::setThreadData(YAC_ThreadPool::ThreadData *p)
{
    YAC_ThreadPool::ThreadData *pOld = getThreadData();
    if(pOld != NULL && pOld != p)
    {
        delete pOld;
    }

    int ret = pthread_setspecific(g_key, (void *)p);
    if(ret != 0)
    {
        throw YAC_ThreadPool_Exception("[YAC_ThreadPool::setThreadData] pthread_setspecific error", ret);
    }
}
Example #7
0
void TC_ThreadPool::setThreadData(pthread_key_t pkey, ThreadData *p)
{
    TC_ThreadPool::ThreadData *pOld = getThreadData(pkey);
    if(pOld != NULL && pOld != p)
    {
        delete pOld;
    }

    int ret = pthread_setspecific(pkey, (void *)p);
    if(ret != 0)
    {
        throw TC_ThreadPool_Exception("[TC_ThreadPool::setThreadData] pthread_setspecific error", ret);
    }
}
Example #8
0
void YAC_ThreadPool::exit()
{
    YAC_ThreadPool::ThreadData *p = getThreadData();
    if(p)
    {
        delete p;
        int ret = pthread_setspecific(g_key, NULL);
        if(ret != 0)
        {
            throw YAC_ThreadPool_Exception("[YAC_ThreadPool::setThreadData] pthread_setspecific error", ret);
        }
    }

    _jobqueue.clear();
}
Example #9
0
pte_osResult pte_osThreadDelete(pte_osThreadHandle handle)
{
    psl1ghtThreadData *pThreadData;
    void *pTls;

    pTls = getTlsStructFromThread(handle);

    pThreadData = getThreadData(handle);

    sysSemDestroy(pThreadData->cancelSem);

    free(pThreadData);

    pteTlsThreadDestroy(pTls);

    return PTE_OS_OK;
}
Example #10
0
pte_osResult pte_osThreadCancel(pte_osThreadHandle threadHandle)
{
    pte_osResult osResult;
    s32 result;
    psl1ghtThreadData *pThreadData;

    pThreadData = getThreadData(threadHandle);

    result = sysSemPost(pThreadData->cancelSem, 1);

    if (result == 0)
    {
        osResult = PTE_OS_OK;
    }
    else
    {
        osResult = PTE_OS_GENERAL_FAILURE;
    }

    return osResult;
}
Example #11
0
pte_osResult pte_osThreadCheckCancel(pte_osThreadHandle threadHandle)
{
    psl1ghtThreadData *pThreadData;
    pte_osResult result;

    pThreadData = getThreadData(threadHandle);

    if (pThreadData != NULL)
    {
        s32 count;

        if (sysSemGetValue (pThreadData->cancelSem, &count) == 0)
        {
            if (count > 0)
            {
                result = PTE_OS_INTERRUPTED;
            }
            else
            {
                result = PTE_OS_OK;
            }
        }
        else
        {
            /* sysSemGetValue returned an error */
            result = PTE_OS_GENERAL_FAILURE;
        }
    }
    else
    {
        /* For some reason, we couldn't get thread data */
        result = PTE_OS_GENERAL_FAILURE;
    }

    return result;
}
Example #12
0
/*
 * Pend on a semaphore- and allow the pend to be cancelled.
 *
 * PS3 OS provides no functionality to asynchronously interrupt a blocked call.  We simulte
 * this by polling on the main semaphore and the cancellation semaphore and sleeping in a loop.
 */
pte_osResult pte_osSemaphoreCancellablePend(pte_osSemaphoreHandle semHandle, unsigned int *pTimeout)
{
    psl1ghtThreadData *pThreadData;
    sys_ppu_thread_t threadId;

    sysThreadGetId (&threadId);
    pThreadData = getThreadData(threadId);

    clock_t start_time;
    s32 result =  0;
    u64 timeout;
    unsigned char timeoutEnabled;

    start_time = clock();

    // clock() is in microseconds, timeout as passed in was in milliseconds
    if (pTimeout == NULL)
    {
        timeout = 0;
        timeoutEnabled = 0;
    }
    else
    {
        timeout = *pTimeout * 1000;
        timeoutEnabled = 1;
    }

    while (1)
    {
        int status;

        /* Poll semaphore */
        status = sysSemTryWait(semHandle);

        if (status == 0)
        {
            /* User semaphore posted to */
            result = PTE_OS_OK;
            break;
        }
        else if ((timeoutEnabled) && ((clock() - start_time) > timeout))
        {
            /* Timeout expired */
            result = PTE_OS_TIMEOUT;
            break;
        }
        else
        {

            if (pThreadData != NULL)
            {
                s32 count;
                s32 osResult;

                osResult = sysSemGetValue (pThreadData->cancelSem, &count);

                if (osResult == 0)
                {
                    if (count > 0)
                    {
                        result = PTE_OS_INTERRUPTED;
                        break;
                    }
                    else
                    {
                        /* Nothing found and not timed out yet; let's yield so we're not
                         * in busy loop.
                         */
                        sysThreadYield ();
                    }
                }
                else
                {
                    result = PTE_OS_GENERAL_FAILURE;
                    break;
                }
            }
        }
    }

    return result;
}
Example #13
0
CVThreadData* CThreadPool::getCurrentThreadData()
{
	return(getThreadData(VThread::getCurrentThreadId()));
}