Ticket #3708: JS_ShutDown.patch

File JS_ShutDown.patch, 6.7 KB (added by Itms, 8 years ago)
  • source/main.cpp

     
    422422        return;
    423423    }
    424424
    425     // We need to initialise libxml2 in the main thread before
    426     // any thread uses it. So initialise it here before we
    427     // might run Atlas.
    428     CXeromyces::Startup();
    429 
    430     // Atlas handles the whole init/shutdown/etc sequence by itself;
    431     if (ATLAS_RunIfOnCmdLine(args, false))
    432         return;
    433 
    434425    const bool isReplay = args.Has("replay");
    435426    const bool isVisualReplay = args.Has("replay-visual");
    436427    const std::string replayFile = isReplay ? args.Get("replay") : (isVisualReplay ? args.Get("replay-visual") : "");
     
    450441        }
    451442    }
    452443
     444    // We need to initialize libxml2 and SpiderMonkey in the main thread before
     445    // any thread uses them. So initialize them here before we might run Atlas.
     446    CXeromyces::Startup();
     447    JS_Init();
     448
     449    if (ATLAS_RunIfOnCmdLine(args, false))
     450    {
     451        JS_ShutDown();
     452        CXeromyces::Terminate();
     453        return;
     454    }
     455
    453456    // run non-visual simulation replay if requested
    454457    if (isReplay)
    455458    {
     
    456459        if (!args.Has("mod"))
    457460        {
    458461            LOGERROR("At least one mod should be specified! Did you mean to add the argument '-mod=public'?");
     462
     463            JS_ShutDown();
    459464            CXeromyces::Terminate();
    460465            return;
    461466        }
     
    472477
    473478        g_VFS.reset();
    474479
     480        JS_ShutDown();
    475481        CXeromyces::Terminate();
    476482        return;
    477483    }
     
    498504
    499505        builder.Build(zip, args.Has("archivebuild-compress"));
    500506
     507        JS_ShutDown();
    501508        CXeromyces::Terminate();
    502509        return;
    503510    }
     
    527534    } while (restart);
    528535
    529536    if (restart_in_atlas)
    530     {
    531537        ATLAS_RunIfOnCmdLine(args, true);
    532         return;
    533     }
    534538
    535     // Shut down libxml2 (done here to match the Startup call)
     539    // Shut down libxml2 and SpiderMonkey (done here to match the Startup call)
     540    JS_ShutDown();
    536541    CXeromyces::Terminate();
    537542}
    538543
  • source/scriptinterface/ScriptInterface.cpp

     
    433433    }
    434434}
    435435
    436 void ScriptInterface::ShutDown()
    437 {
    438     JS_ShutDown();
    439 }
    440 
    441436void ScriptInterface::SetCallbackData(void* pCBData)
    442437{
    443438    m_CxPrivate.pCBData = pCBData;
  • source/scriptinterface/ScriptInterface.h

     
    9797
    9898    ~ScriptInterface();
    9999
    100     /**
    101      * Shut down the JS system to clean up memory. Must only be called when there
    102      * are no ScriptInterfaces alive.
    103      */
    104     static void ShutDown();
    105 
    106100    struct CxPrivate
    107101    {
    108102        ScriptInterface* pScriptInterface; // the ScriptInterface object the current context belongs to
  • source/scriptinterface/ScriptRuntime.cpp

     
    104104    m_FinalizationListObjectIdCache.push_back(obj);
    105105}
    106106
    107 bool ScriptRuntime::m_Initialized = false;
    108 
    109107ScriptRuntime::ScriptRuntime(shared_ptr<ScriptRuntime> parentRuntime, int runtimeSize, int heapGrowthBytesGCTrigger):
    110108    m_LastGCBytes(0),
    111109    m_LastGCCheck(0.0f),
     
    112110    m_HeapGrowthBytesGCTrigger(heapGrowthBytesGCTrigger),
    113111    m_RuntimeSize(runtimeSize)
    114112{
    115     if (!m_Initialized)
    116     {
    117         ENSURE(JS_Init());
    118         m_Initialized = true;
    119     }
    120 
    121113    JSRuntime* parentJSRuntime = parentRuntime ? parentRuntime->m_rt : nullptr;
    122114    m_rt = JS_NewRuntime(runtimeSize, JS_USE_HELPER_THREADS, parentJSRuntime);
    123115    ENSURE(m_rt); // TODO: error handling
  • source/scriptinterface/ScriptRuntime.h

     
    3434 * (One means to share data between threads and runtimes is to create
    3535 * a ScriptInterface::StructuredClone.)
    3636 */
    37  
     37
    3838class ScriptRuntime
    3939{
    4040public:
     
    4242    ~ScriptRuntime();
    4343
    4444    /**
    45      * MaybeIncrementalRuntimeGC tries to determine whether a runtime-wide garbage collection would free up enough memory to 
     45     * MaybeIncrementalRuntimeGC tries to determine whether a runtime-wide garbage collection would free up enough memory to
    4646     * be worth the amount of time it would take. It does this with our own logic and NOT some predefined JSAPI logic because
    4747     * such functionality currently isn't available out of the box.
    4848     * It does incremental GC which means it will collect one slice each time it's called until the garbage collection is done.
    4949     * This can and should be called quite regularly. The delay parameter allows you to specify a minimum time since the last GC
    50      * in seconds (the delay should be a fraction of a second in most cases though). 
    51      * It will only start a new incremental GC or another GC slice if this time is exceeded. The user of this function is 
     50     * in seconds (the delay should be a fraction of a second in most cases though).
     51     * It will only start a new incremental GC or another GC slice if this time is exceeded. The user of this function is
    5252     * responsible for ensuring that GC can run with a small enough delay to get done with the work.
    5353     */
    5454    void MaybeIncrementalGC(double delay);
     
    7373
    7474    void PrepareContextsForIncrementalGC();
    7575    void GCCallbackMember();
    76    
     76
    7777    // Workaround for: https://bugzilla.mozilla.org/show_bug.cgi?id=890243
    7878    JSContext* m_dummyContext;
    79    
     79
    8080    std::list<JSContext*> m_Contexts;
    8181    std::vector<std::shared_ptr<void> > m_FinalizationListObjectIdCache;
    82     static bool m_Initialized;
    8382
    8483    int m_RuntimeSize;
    8584    int m_HeapGrowthBytesGCTrigger;
  • source/test_setup.cpp

     
    1 /* Copyright (C) 2014 Wildfire Games.
     1/* Copyright (C) 2016 Wildfire Games.
    22 * This file is part of 0 A.D.
    33 *
    44 * 0 A.D. is free software: you can redistribute it and/or modify
     
    4242{
    4343    virtual bool tearDownWorld()
    4444    {
    45         // Shut down JS to prevent leak reports from it
    46         ScriptInterface::ShutDown();
    47 
    4845        // Enable leak reporting on exit.
    4946        // (This is done in tearDownWorld so that it doesn't report 'leaks'
    5047        // if the program is aborted before finishing cleanly.)
     
    7067{
    7168    virtual bool setUpWorld()
    7269    {
     70        JS_Init();
     71
    7372        // Timer must be initialised, else things will break when tests do IO
    7473        timer_LatchStartTime();
    7574
     
    9089    {
    9190        g_ScriptRuntime.reset();
    9291        g_Profiler2.Shutdown();
     92        JS_ShutDown();
    9393
    9494        return true;
    9595    }