Bug 167277

Summary: Harden how the compiler references GC objects
Product: WebKit Reporter: Saam Barati <saam>
Component: JavaScriptCoreAssignee: Saam Barati <saam>
Status: RESOLVED FIXED    
Severity: Normal CC: benjamin, buildbot, commit-queue, fpizlo, ggaren, gskachkov, jfbastien, keith_miller, mark.lam, msaboff, oliver, rniwa, ticaiolima, webkit-bug-importer, ysuzuki
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
WIP
none
WIP
none
WIP
none
patch
fpizlo: review+, buildbot: commit-queue-
Archive of layout-test-results from ews101 for mac-elcapitan
none
patch for landing
none
patch for landing
none
patch for landing
none
patch for landing
none
perf numbers
none
patch for landing none

Saam Barati
Reported 2017-01-20 18:32:27 PST
Now that we safepoint between each phase, we probably have bugs where we have references that never become known to the compiler. Let's harden how we do things to be consistent everywhere and hard to get wrong.
Attachments
WIP (47.78 KB, patch)
2017-01-21 17:30 PST, Saam Barati
no flags
WIP (74.80 KB, patch)
2017-01-22 15:16 PST, Saam Barati
no flags
WIP (150.75 KB, patch)
2017-01-23 14:31 PST, Saam Barati
no flags
patch (238.70 KB, patch)
2017-01-24 20:00 PST, Saam Barati
fpizlo: review+
buildbot: commit-queue-
Archive of layout-test-results from ews101 for mac-elcapitan (833.07 KB, application/zip)
2017-01-24 21:10 PST, Build Bot
no flags
patch for landing (247.68 KB, patch)
2017-01-26 14:03 PST, Saam Barati
no flags
patch for landing (247.55 KB, patch)
2017-01-26 14:11 PST, Saam Barati
no flags
patch for landing (247.92 KB, patch)
2017-01-26 14:14 PST, Saam Barati
no flags
patch for landing (247.92 KB, patch)
2017-01-26 14:16 PST, Saam Barati
no flags
perf numbers (87.28 KB, text/plain)
2017-01-26 14:17 PST, Saam Barati
no flags
patch for landing (247.92 KB, patch)
2017-01-26 15:10 PST, Saam Barati
no flags
Saam Barati
Comment 1 2017-01-21 17:30:34 PST
Created attachment 299450 [details] WIP It begins
Saam Barati
Comment 2 2017-01-22 15:16:53 PST
Created attachment 299488 [details] WIP A bit more. I want to find a way where using TrustedImmPtr(T*) where T inherits from HeapCell is a compile error. I've finished this for FTLOutput with FTLOutput::constIntPtr.
Saam Barati
Comment 3 2017-01-23 14:31:33 PST
Created attachment 299538 [details] WIP This now passes release JSC tests for me locally without running the structure registration phase. I want to read over my code and run debug tests before putting up for review. (Also, I think I probably caught a few legitimate, but probably almost impossible to reproduce bugs when doing this.)
WebKit Commit Bot
Comment 4 2017-01-23 14:33:59 PST
Attachment 299538 [details] did not pass style-queue: ERROR: Source/JavaScriptCore/dfg/DFGPlan.cpp:314: Should have a space between // and comment [whitespace/comments] [4] ERROR: Source/JavaScriptCore/dfg/DFGOpInfo.h:28: Alphabetical sorting problem. [build/include_order] [4] ERROR: Source/JavaScriptCore/dfg/DFGOpInfo.h:47: Should be indented on a separate line, with the colon or comma first on that line. [whitespace/indent] [4] ERROR: Source/JavaScriptCore/dfg/DFGOpInfo.h:48: Should be indented on a separate line, with the colon or comma first on that line. [whitespace/indent] [4] ERROR: Source/JavaScriptCore/dfg/DFGArrayifySlowPathGenerator.h:48: Wrong number of spaces before statement. (expected: 12) [whitespace/indent] [4] ERROR: Source/JavaScriptCore/dfg/DFGGraph.h:221: The parameter name "structure" adds no information, so it should be removed. [readability/parameter_name] [5] ERROR: Source/JavaScriptCore/dfg/DFGGraph.h:221: The parameter name "result" adds no information, so it should be removed. [readability/parameter_name] [5] ERROR: Source/JavaScriptCore/dfg/DFGStructureRegistrationPhase.cpp:89: Should have a space between // and comment [whitespace/comments] [4] ERROR: Source/JavaScriptCore/dfg/DFGStructureRegistrationPhase.cpp:90: Should have a space between // and comment [whitespace/comments] [4] Total errors found: 9 in 36 files If any of these errors are false positives, please file a bug against check-webkit-style.
Filip Pizlo
Comment 5 2017-01-24 12:53:58 PST
Comment on attachment 299538 [details] WIP View in context: https://bugs.webkit.org/attachment.cgi?id=299538&action=review > Source/JavaScriptCore/dfg/DFGJITCompiler.cpp:559 > + if (value.m_structure.isFinite()) > + m_graph.addStructureSet(value.m_structure.set()); Seems weird. Why don't we just have the guarantee that AbstractInterpreter registers structures before building sets out of them? I think that contract trivially works: the only structures that AbstractInterpreter can see are RegisteredStructures. > Source/JavaScriptCore/dfg/DFGJITCompiler.cpp:589 > + > + if (value.m_structure.isFinite()) > + m_graph.addStructureSet(value.m_structure.set()); Ditto. > Source/JavaScriptCore/ftl/FTLOutput.h:126 > + > + LValue constGCPointer(DFG::Graph& graph, JSCell* cell) > + { > + ASSERT(graph.m_plan.weakReferences.contains(cell)); > + > + if (sizeof(void*) == 8) > + return constInt64(bitwise_cast<intptr_t>(cell)); > + return constInt32(bitwise_cast<intptr_t>(cell)); > + } > + > + LValue constGCPointer(DFG::FrozenValue* value) > + { > + RELEASE_ASSERT(value->value().isCell()); > + > + if (sizeof(void*) == 8) > + return constInt64(bitwise_cast<intptr_t>(value->cell())); > + return constInt32(bitwise_cast<intptr_t>(value->cell())); > + } > + Why can't this be called weakPointer?
Filip Pizlo
Comment 6 2017-01-24 12:54:57 PST
This looks pretty good to me.
Radar WebKit Bug Importer
Comment 7 2017-01-24 18:17:35 PST
Saam Barati
Comment 8 2017-01-24 20:00:50 PST
WebKit Commit Bot
Comment 9 2017-01-24 20:03:23 PST
Attachment 299672 [details] did not pass style-queue: ERROR: Source/JavaScriptCore/dfg/DFGRegisteredStructure.cpp:39: More than one command on the same line [whitespace/newline] [4] ERROR: Source/JavaScriptCore/dfg/DFGStructureAbstractValue.h:34: Alphabetical sorting problem. [build/include_order] [4] ERROR: Source/JavaScriptCore/dfg/DFGStructureAbstractValue.h:135: The parameter name "structure" adds no information, so it should be removed. [readability/parameter_name] [5] ERROR: Source/JavaScriptCore/dfg/DFGStructureAbstractValue.h:234: The parameter name "structure" adds no information, so it should be removed. [readability/parameter_name] [5] ERROR: Source/JavaScriptCore/dfg/DFGOpInfo.h:28: Alphabetical sorting problem. [build/include_order] [4] ERROR: Source/JavaScriptCore/dfg/DFGOpInfo.h:47: Should be indented on a separate line, with the colon or comma first on that line. [whitespace/indent] [4] ERROR: Source/JavaScriptCore/dfg/DFGArrayifySlowPathGenerator.h:48: Wrong number of spaces before statement. (expected: 12) [whitespace/indent] [4] ERROR: Source/JavaScriptCore/dfg/DFGGraph.h:221: The parameter name "structure" adds no information, so it should be removed. [readability/parameter_name] [5] ERROR: Source/JavaScriptCore/dfg/DFGGraph.h:221: The parameter name "result" adds no information, so it should be removed. [readability/parameter_name] [5] Total errors found: 9 in 43 files If any of these errors are false positives, please file a bug against check-webkit-style.
Build Bot
Comment 10 2017-01-24 21:10:28 PST
Comment on attachment 299672 [details] patch Attachment 299672 [details] did not pass mac-ews (mac): Output: http://webkit-queues.webkit.org/results/2944589 New failing tests: imported/w3c/web-platform-tests/html/browsers/history/the-location-interface/location-protocol-setter-non-broken.html
Build Bot
Comment 11 2017-01-24 21:10:32 PST
Created attachment 299679 [details] Archive of layout-test-results from ews101 for mac-elcapitan The attached test failures were seen while running run-webkit-tests on the mac-ews. Bot: ews101 Port: mac-elcapitan Platform: Mac OS X 10.11.6
Filip Pizlo
Comment 12 2017-01-25 18:31:15 PST
Comment on attachment 299672 [details] patch View in context: https://bugs.webkit.org/attachment.cgi?id=299672&action=review This looks pretty good to me. > Source/JavaScriptCore/dfg/DFGRegisteredStructure.cpp:37 > +void RegisteredStructureSet::filter(const DFG::StructureAbstractValue& other) Can you put RegisteredStructureSet into its own file? > Source/JavaScriptCore/dfg/DFGRegisteredStructure.h:84 > +class RegisteredStructureSet : public TinyPtrSet<RegisteredStructure> { Separate file > Source/WTF/wtf/TinyPtrSet.h:479 > - return static_cast<T>(pointer()); > + return bitwise_cast<T>(pointer()); Wow
Saam Barati
Comment 13 2017-01-25 19:09:03 PST
This is a huge slowdown. I need to figure out why.
Saam Barati
Comment 14 2017-01-25 20:00:13 PST
(In reply to comment #13) > This is a huge slowdown. I need to figure out why. Not sure why yet. Using concurrentJIT=0 and the super sampler under Graph::registerStructure, the super sampler says we're spending no time there. Maybe I mistranslated code somewhere.
Saam Barati
Comment 15 2017-01-25 20:02:47 PST
reportTotalCompileTimes=true says we're spending way more time compiling. I'm not yet sure if this is because I mistranslated code and we do more compilations, or the compiler is just 6x more expensive with my patch.
Filip Pizlo
Comment 16 2017-01-25 20:11:02 PST
(In reply to comment #15) > reportTotalCompileTimes=true says we're spending way more time compiling. > I'm not yet sure if this is because I mistranslated code and we do more > compilations, or the compiler is just 6x more expensive with my patch. Could be OSR exiting like crazy. Maybe some references that were previously treated as strong are now treated as weak, or you are failing to transform Transition into a CodeBlock Transition constraint. Easy way to test that theory is to count the number of jettisons during GC.
Saam Barati
Comment 17 2017-01-25 20:46:40 PST
Ok, I've found the issue. An FTL CodeBlock had a weakPointer to itself, causing itself to get collected. I've fixed this bug. I'm now considering if we could even assert we never weakly point to a CodeBlock* just for sanity. Maybe I'll do this in a separate patch.
Saam Barati
Comment 18 2017-01-26 14:03:15 PST
Created attachment 299847 [details] patch for landing
Saam Barati
Comment 19 2017-01-26 14:05:41 PST
Comment on attachment 299847 [details] patch for landing View in context: https://bugs.webkit.org/attachment.cgi?id=299847&action=review > Source/JavaScriptCore/dfg/DFGGraph.cpp:1482 > + return; oops.
WebKit Commit Bot
Comment 20 2017-01-26 14:06:30 PST
Attachment 299847 [details] did not pass style-queue: ERROR: Source/JavaScriptCore/dfg/DFGOpInfo.h:47: Should be indented on a separate line, with the colon or comma first on that line. [whitespace/indent] [4] ERROR: Source/JavaScriptCore/dfg/DFGArrayifySlowPathGenerator.h:48: Wrong number of spaces before statement. (expected: 12) [whitespace/indent] [4] Total errors found: 2 in 47 files If any of these errors are false positives, please file a bug against check-webkit-style.
Saam Barati
Comment 21 2017-01-26 14:11:01 PST
Created attachment 299849 [details] patch for landing
WebKit Commit Bot
Comment 22 2017-01-26 14:12:44 PST
Attachment 299849 [details] did not pass style-queue: ERROR: Source/JavaScriptCore/dfg/DFGOpInfo.h:47: Should be indented on a separate line, with the colon or comma first on that line. [whitespace/indent] [4] ERROR: Source/JavaScriptCore/dfg/DFGArrayifySlowPathGenerator.h:48: Wrong number of spaces before statement. (expected: 12) [whitespace/indent] [4] Total errors found: 2 in 47 files If any of these errors are false positives, please file a bug against check-webkit-style.
Saam Barati
Comment 23 2017-01-26 14:14:19 PST
Created attachment 299851 [details] patch for landing
WebKit Commit Bot
Comment 24 2017-01-26 14:16:15 PST
Attachment 299851 [details] did not pass style-queue: ERROR: Source/JavaScriptCore/dfg/DFGOpInfo.h:47: Should be indented on a separate line, with the colon or comma first on that line. [whitespace/indent] [4] ERROR: Source/JavaScriptCore/dfg/DFGArrayifySlowPathGenerator.h:48: Wrong number of spaces before statement. (expected: 12) [whitespace/indent] [4] Total errors found: 2 in 47 files If any of these errors are false positives, please file a bug against check-webkit-style.
Saam Barati
Comment 25 2017-01-26 14:16:34 PST
Created attachment 299852 [details] patch for landing
Saam Barati
Comment 26 2017-01-26 14:17:11 PST
Created attachment 299853 [details] perf numbers
WebKit Commit Bot
Comment 27 2017-01-26 14:19:35 PST
Attachment 299852 [details] did not pass style-queue: ERROR: Source/JavaScriptCore/dfg/DFGOpInfo.h:47: Should be indented on a separate line, with the colon or comma first on that line. [whitespace/indent] [4] ERROR: Source/JavaScriptCore/dfg/DFGArrayifySlowPathGenerator.h:48: Wrong number of spaces before statement. (expected: 12) [whitespace/indent] [4] Total errors found: 2 in 47 files If any of these errors are false positives, please file a bug against check-webkit-style.
JF Bastien
Comment 28 2017-01-26 14:57:43 PST
Comment on attachment 299852 [details] patch for landing View in context: https://bugs.webkit.org/attachment.cgi?id=299852&action=review I looked over the new code. Neat! > Source/JavaScriptCore/ChangeLog:12 > + the compiler must be track of all the heap pointers that are part "must be track of" > Source/JavaScriptCore/dfg/DFGSpeculativeJIT.h:132 > + } You could make this a link error by declaring but not defining it. It's kinda ugly! You can make it more obvious with: void ErrorTrustedImmPtrCannotBeConstructedWithInt(); // Declared, not defined. explicit TrustedImmPtr(int) { ErrorTrustedImmPtrCannotBeConstructedWithInt(); }
Saam Barati
Comment 29 2017-01-26 15:10:59 PST
Created attachment 299861 [details] patch for landing
Saam Barati
Comment 30 2017-01-26 15:14:35 PST
(In reply to comment #28) > Comment on attachment 299852 [details] > patch for landing > > View in context: > https://bugs.webkit.org/attachment.cgi?id=299852&action=review > > I looked over the new code. Neat! > > > Source/JavaScriptCore/ChangeLog:12 > > + the compiler must be track of all the heap pointers that are part > > "must be track of" Fixed. > > > Source/JavaScriptCore/dfg/DFGSpeculativeJIT.h:132 > > + } > > You could make this a link error by declaring but not defining it. It's > kinda ugly! You can make it more obvious with: > > void ErrorTrustedImmPtrCannotBeConstructedWithInt(); // Declared, not > defined. > explicit TrustedImmPtr(int) { > ErrorTrustedImmPtrCannotBeConstructedWithInt(); } I did just to try to keep refactoring levels down since MacroAssembler::TrustedImmPtr does this. It would be nice if we could eventually remove it. But I think some callers really want to say I have an pointer sized integer with value zero, and I suspect MacroAssembler::TrustedImmPtr does this to not confuse the compiler between void* and size_t when the immediate is "0".
WebKit Commit Bot
Comment 31 2017-01-26 15:52:19 PST
Comment on attachment 299861 [details] patch for landing Clearing flags on attachment: 299861 Committed r211237: <http://trac.webkit.org/changeset/211237>
WebKit Commit Bot
Comment 32 2017-01-26 15:52:26 PST
All reviewed patches have been landed. Closing bug.
Note You need to log in before you can comment on or make changes to this bug.