Changeset 115579 in webkit for trunk/Source/JavaScriptCore/ChangeLog
- Timestamp:
- Apr 28, 2012, 1:51:27 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/ChangeLog
r115548 r115579 1 2012-04-28 Geoffrey Garen <[email protected]> 2 3 Clarified JSGlobalData (JavaScript VM) lifetime 4 https://bugs.webkit.org/show_bug.cgi?id=85142 5 6 Reviewed by Anders Carlsson. 7 8 This was so confusing that I didn't feel like I could reason about 9 memory lifetime in the heap without fixing it. 10 11 The rules are: 12 13 (1) JSGlobalData owns the virtual machine and all memory in it. 14 15 (2) Deleting a JSGlobalData frees the virtual machine and all memory 16 in it. 17 18 (Caveat emptor: if you delete the virtual machine while you're running 19 JIT code or accessing GC objects, you're gonna have a bad time.) 20 21 (I opted not to make arbitrary sub-objects keep the virtual machine 22 alive automatically because: 23 24 (a) doing that right would be complex and slow; 25 26 (b) in the case of an exiting thread or process, there's no 27 clear way to give the garbage collector a chance to try again 28 later; 29 30 (c) continuing to run the garbage collector after we've been 31 asked to shut down the virtual machine seems rude; 32 33 (d) we've never really supported that feature, anyway.) 34 35 (3) Normal ref-counting will do. No need to call a battery of 36 specialty functions to tear down a JSGlobalData. Its foibles 37 notwithstanding, C++ does in fact know how to execute destructors in 38 order. 39 40 * API/JSContextRef.cpp: 41 (JSGlobalContextCreate): Removed compatibility shim for older 42 operating systems because it's no longer used. 43 44 (JSGlobalContextRelease): Now that we can rely on JSGlobalData to "do 45 the right thing", this code is much simpler. We still have one special 46 case to notify the garbage collector if we're removing the last 47 reference to the global object, since this can improve memory behavior. 48 49 * heap/CopiedSpace.cpp: 50 (JSC::CopiedSpace::freeAllBlocks): 51 * heap/CopiedSpace.h: 52 (CopiedSpace): Renamed "destroy" => "freeAllBlocks" because true 53 destruction-time behaviors should be limited to our C++ destructor. 54 55 * heap/Heap.cpp: 56 (JSC::Heap::~Heap): 57 (JSC): 58 (JSC::Heap::lastChanceToFinalize): 59 * heap/Heap.h: 60 (Heap): 61 (JSC::Heap::heap): Renamed "destroy" => "lastChanceToFinalize" because 62 true destruction-time behaviors should be limited to our C++ 63 destructor. 64 65 Reorganized the code, putting code that must run before any objects 66 get torn down into lastChanceToFinalize, and code that just tears down 67 objects into our destructor. 68 69 * heap/Local.h: 70 (JSC::LocalStack::LocalStack): 71 (JSC::LocalStack::push): 72 (LocalStack): See rule (2). 73 74 * jsc.cpp: 75 (functionQuit): 76 (main): 77 (printUsageStatement): 78 (parseArguments): 79 (jscmain): 80 * testRegExp.cpp: 81 (main): 82 (printUsageStatement): 83 (parseArguments): 84 (realMain): See rule (3). 85 86 I removed the feature of ensuring orderly tear-down when calling quit() 87 or running in --help mode because it didn't seem very useful and 88 making it work with Windows structured exception handling and 89 NO_RETURN didn't seem like a fun way to spend a Saturday. 90 91 * runtime/JSGlobalData.h: 92 * runtime/JSGlobalData.cpp: 93 (JSC::JSGlobalData::JSGlobalData): Moved heap to be the first data 94 member in JSGlobalData to ensure that it's destructed last, so other 95 objects that reference it destruct without crashing. This allowed me 96 to remove clearBuiltinStructures() altogether, and helped guarantee 97 rule (3). 98 99 (JSC::JSGlobalData::~JSGlobalData): Explicitly call 100 lastChanceToFinalize() at the head of our destructor to ensure that 101 all pending finalizers run while the virtual machine is still in a 102 valid state. Trying to resurrect (re-ref) the virtual machine at this 103 point is not valid, but all other operations are. 104 105 Changed a null to a 0xbbadbeef to clarify just how bad this beef is. 106 107 * runtime/JSGlobalObject.cpp: 108 (JSC::JSGlobalObject::init): 109 * runtime/JSGlobalObject.h: 110 (JSGlobalObject): 111 (JSC::JSGlobalObject::globalData): See rule (3). 112 1 113 2012-04-27 Geoffrey Garen <[email protected]> 2 114
Note:
See TracChangeset
for help on using the changeset viewer.