Ticket #3708: JS_ShutDown.patch
File JS_ShutDown.patch, 6.7 KB (added by , 8 years ago) |
---|
-
source/main.cpp
422 422 return; 423 423 } 424 424 425 // We need to initialise libxml2 in the main thread before426 // any thread uses it. So initialise it here before we427 // 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 434 425 const bool isReplay = args.Has("replay"); 435 426 const bool isVisualReplay = args.Has("replay-visual"); 436 427 const std::string replayFile = isReplay ? args.Get("replay") : (isVisualReplay ? args.Get("replay-visual") : ""); … … 450 441 } 451 442 } 452 443 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 453 456 // run non-visual simulation replay if requested 454 457 if (isReplay) 455 458 { … … 456 459 if (!args.Has("mod")) 457 460 { 458 461 LOGERROR("At least one mod should be specified! Did you mean to add the argument '-mod=public'?"); 462 463 JS_ShutDown(); 459 464 CXeromyces::Terminate(); 460 465 return; 461 466 } … … 472 477 473 478 g_VFS.reset(); 474 479 480 JS_ShutDown(); 475 481 CXeromyces::Terminate(); 476 482 return; 477 483 } … … 498 504 499 505 builder.Build(zip, args.Has("archivebuild-compress")); 500 506 507 JS_ShutDown(); 501 508 CXeromyces::Terminate(); 502 509 return; 503 510 } … … 527 534 } while (restart); 528 535 529 536 if (restart_in_atlas) 530 {531 537 ATLAS_RunIfOnCmdLine(args, true); 532 return;533 }534 538 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(); 536 541 CXeromyces::Terminate(); 537 542 } 538 543 -
source/scriptinterface/ScriptInterface.cpp
433 433 } 434 434 } 435 435 436 void ScriptInterface::ShutDown()437 {438 JS_ShutDown();439 }440 441 436 void ScriptInterface::SetCallbackData(void* pCBData) 442 437 { 443 438 m_CxPrivate.pCBData = pCBData; -
source/scriptinterface/ScriptInterface.h
97 97 98 98 ~ScriptInterface(); 99 99 100 /**101 * Shut down the JS system to clean up memory. Must only be called when there102 * are no ScriptInterfaces alive.103 */104 static void ShutDown();105 106 100 struct CxPrivate 107 101 { 108 102 ScriptInterface* pScriptInterface; // the ScriptInterface object the current context belongs to -
source/scriptinterface/ScriptRuntime.cpp
104 104 m_FinalizationListObjectIdCache.push_back(obj); 105 105 } 106 106 107 bool ScriptRuntime::m_Initialized = false;108 109 107 ScriptRuntime::ScriptRuntime(shared_ptr<ScriptRuntime> parentRuntime, int runtimeSize, int heapGrowthBytesGCTrigger): 110 108 m_LastGCBytes(0), 111 109 m_LastGCCheck(0.0f), … … 112 110 m_HeapGrowthBytesGCTrigger(heapGrowthBytesGCTrigger), 113 111 m_RuntimeSize(runtimeSize) 114 112 { 115 if (!m_Initialized)116 {117 ENSURE(JS_Init());118 m_Initialized = true;119 }120 121 113 JSRuntime* parentJSRuntime = parentRuntime ? parentRuntime->m_rt : nullptr; 122 114 m_rt = JS_NewRuntime(runtimeSize, JS_USE_HELPER_THREADS, parentJSRuntime); 123 115 ENSURE(m_rt); // TODO: error handling -
source/scriptinterface/ScriptRuntime.h
34 34 * (One means to share data between threads and runtimes is to create 35 35 * a ScriptInterface::StructuredClone.) 36 36 */ 37 37 38 38 class ScriptRuntime 39 39 { 40 40 public: … … 42 42 ~ScriptRuntime(); 43 43 44 44 /** 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 46 46 * be worth the amount of time it would take. It does this with our own logic and NOT some predefined JSAPI logic because 47 47 * such functionality currently isn't available out of the box. 48 48 * It does incremental GC which means it will collect one slice each time it's called until the garbage collection is done. 49 49 * 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 52 52 * responsible for ensuring that GC can run with a small enough delay to get done with the work. 53 53 */ 54 54 void MaybeIncrementalGC(double delay); … … 73 73 74 74 void PrepareContextsForIncrementalGC(); 75 75 void GCCallbackMember(); 76 76 77 77 // Workaround for: https://bugzilla.mozilla.org/show_bug.cgi?id=890243 78 78 JSContext* m_dummyContext; 79 79 80 80 std::list<JSContext*> m_Contexts; 81 81 std::vector<std::shared_ptr<void> > m_FinalizationListObjectIdCache; 82 static bool m_Initialized;83 82 84 83 int m_RuntimeSize; 85 84 int m_HeapGrowthBytesGCTrigger; -
source/test_setup.cpp
1 /* Copyright (C) 201 4Wildfire Games.1 /* Copyright (C) 2016 Wildfire Games. 2 2 * This file is part of 0 A.D. 3 3 * 4 4 * 0 A.D. is free software: you can redistribute it and/or modify … … 42 42 { 43 43 virtual bool tearDownWorld() 44 44 { 45 // Shut down JS to prevent leak reports from it46 ScriptInterface::ShutDown();47 48 45 // Enable leak reporting on exit. 49 46 // (This is done in tearDownWorld so that it doesn't report 'leaks' 50 47 // if the program is aborted before finishing cleanly.) … … 70 67 { 71 68 virtual bool setUpWorld() 72 69 { 70 JS_Init(); 71 73 72 // Timer must be initialised, else things will break when tests do IO 74 73 timer_LatchStartTime(); 75 74 … … 90 89 { 91 90 g_ScriptRuntime.reset(); 92 91 g_Profiler2.Shutdown(); 92 JS_ShutDown(); 93 93 94 94 return true; 95 95 }