<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[246423] branches/safari-607-branch/Source/JavaScriptCore</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/246423">246423</a></dd>
<dt>Author</dt> <dd>kocsen_chung@apple.com</dd>
<dt>Date</dt> <dd>2019-06-13 19:59:16 -0700 (Thu, 13 Jun 2019)</dd>
</dl>

<h3>Log Message</h3>
<pre>Apply patch. rdar://problem/51656841</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#branchessafari607branchSourceJavaScriptCoreChangeLog">branches/safari-607-branch/Source/JavaScriptCore/ChangeLog</a></li>
<li><a href="#branchessafari607branchSourceJavaScriptCoreftlFTLLowerDFGToB3cpp">branches/safari-607-branch/Source/JavaScriptCore/ftl/FTLLowerDFGToB3.cpp</a></li>
<li><a href="#branchessafari607branchSourceJavaScriptCoreheapSlotVisitorcpp">branches/safari-607-branch/Source/JavaScriptCore/heap/SlotVisitor.cpp</a></li>
<li><a href="#branchessafari607branchSourceJavaScriptCorejitAssemblyHelperscpp">branches/safari-607-branch/Source/JavaScriptCore/jit/AssemblyHelpers.cpp</a></li>
<li><a href="#branchessafari607branchSourceJavaScriptCorejitAssemblyHelpersh">branches/safari-607-branch/Source/JavaScriptCore/jit/AssemblyHelpers.h</a></li>
<li><a href="#branchessafari607branchSourceJavaScriptCorejitSpecializedThunkJITh">branches/safari-607-branch/Source/JavaScriptCore/jit/SpecializedThunkJIT.h</a></li>
<li><a href="#branchessafari607branchSourceJavaScriptCorellintLowLevelInterpreterasm">branches/safari-607-branch/Source/JavaScriptCore/llint/LowLevelInterpreter.asm</a></li>
<li><a href="#branchessafari607branchSourceJavaScriptCorellintLowLevelInterpreter64asm">branches/safari-607-branch/Source/JavaScriptCore/llint/LowLevelInterpreter64.asm</a></li>
<li><a href="#branchessafari607branchSourceJavaScriptCoreruntimeStructureIDTablecpp">branches/safari-607-branch/Source/JavaScriptCore/runtime/StructureIDTable.cpp</a></li>
<li><a href="#branchessafari607branchSourceJavaScriptCoreruntimeStructureIDTableh">branches/safari-607-branch/Source/JavaScriptCore/runtime/StructureIDTable.h</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="branchessafari607branchSourceJavaScriptCoreChangeLog"></a>
<div class="modfile"><h4>Modified: branches/safari-607-branch/Source/JavaScriptCore/ChangeLog (246422 => 246423)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-607-branch/Source/JavaScriptCore/ChangeLog       2019-06-14 02:54:53 UTC (rev 246422)
+++ branches/safari-607-branch/Source/JavaScriptCore/ChangeLog  2019-06-14 02:59:16 UTC (rev 246423)
</span><span class="lines">@@ -1,5 +1,143 @@
</span><span class="cx"> 2019-06-13  Kocsen Chung  <kocsen_chung@apple.com>
</span><span class="cx"> 
</span><ins>+        Apply patch. rdar://problem/51656841
+
+    2019-06-13  Mark Lam  <mark.lam@apple.com>
+
+            Misc cleanup in StructureIDTable after r242096.
+            https://bugs.webkit.org/show_bug.cgi?id=195063
+
+            Reviewed by Saam Barati.
+
+            * runtime/StructureIDTable.cpp:
+            (JSC::StructureIDTable::allocateID):
+            - RELEASE_ASSERT that the StructureID allocation will succeed.
+
+            * runtime/StructureIDTable.h:
+            (JSC::StructureIDTable::decode):
+            (JSC::StructureIDTable::encode):
+            - Add back a comment that Yusuke requested but was lost when the patch was rolled
+              out and relanded.
+            - Applied bitwise_casts that Saam requested.
+
+2019-02-26  Mark Lam  <mark.lam@apple.com>
+
+        [Re-landing] Add some randomness into the StructureID.
+        https://bugs.webkit.org/show_bug.cgi?id=194989
+        <rdar://problem/47975563>
+
+        Reviewed by Yusuke Suzuki.
+
+        1. On 64-bit, the StructureID will now be encoded as:
+
+            ----------------------------------------------------------------
+            | 1 Nuke Bit | 24 StructureIDTable index bits | 7 entropy bits |
+            ----------------------------------------------------------------
+
+           The entropy bits are chosen at random and assigned when a StructureID is
+           allocated.
+
+        2. Instead of Structure pointers, the StructureIDTable will now contain
+           encodedStructureBits, which is encoded as such:
+
+            ----------------------------------------------------------------
+            | 7 entropy bits |                   57 structure pointer bits |
+            ----------------------------------------------------------------
+
+           The entropy bits here are the same 7 bits used in the encoding of the
+           StructureID for this structure entry in the StructureIDTable.
+
+        3. Retrieval of the structure pointer given a StructureID is now computed as
+           follows:
+
+                index = structureID >> 7; // with arithmetic shift.
+                encodedStructureBits = structureIDTable[index];
+                structure = encodedStructureBits ^ (structureID << 57);
+
+            We use an arithmetic shift for the right shift because that will preserve
+            the nuke bit in the high bit of the index if the StructureID was not
+            decontaminated before use as expected.
+
+        4. Remove unused function loadArgumentWithSpecificClass() in SpecializedThunkJIT.
+
+        5. Define StructureIDTable::m_size to be the number of allocated StructureIDs
+           instead of always being the same as m_capacity.
+
+        6. Change StructureIDTable::s_unusedID's value to 0.
+
+           Its previous value of unusedPointer i.e. 0xd1e7beef, does not make sense for
+           StructureID on 64-bit.  Also, there was never any code that initializes unused
+           IDs to the s_unusedID.  The only meaningful value for s_unusedID is 0, which
+           is the ID we'll get when the freelist is empty, prompting a resize of the
+           structureIDTable.
+
+        This patch appears to be perf neutral on JetStream 2 run via the cli on a
+        11" MacBook Air, 13" MacBook Pro, iPhone 6S, and iPhone XR.
+
+        * ftl/FTLLowerDFGToB3.cpp:
+        (JSC::FTL::DFG::LowerDFGToB3::loadStructure):
+        * heap/SlotVisitor.cpp:
+        (JSC::SlotVisitor::appendJSCellOrAuxiliary):
+        * jit/AssemblyHelpers.cpp:
+        (JSC::AssemblyHelpers::emitLoadStructure):
+        * jit/AssemblyHelpers.h:
+        * jit/SpecializedThunkJIT.h:
+        (JSC::SpecializedThunkJIT::loadArgumentWithSpecificClass): Deleted.
+        * llint/LowLevelInterpreter.asm:
+        * llint/LowLevelInterpreter64.asm:
+        * runtime/StructureIDTable.cpp:
+        (JSC::StructureIDTable::StructureIDTable):
+        (JSC::StructureIDTable::makeFreeListFromRange):
+        (JSC::StructureIDTable::resize):
+        (JSC::StructureIDTable::allocateID):
+        (JSC::StructureIDTable::deallocateID):
+        * runtime/StructureIDTable.h:
+        (JSC::StructureIDTable::decode):
+        (JSC::StructureIDTable::encode):
+        (JSC::StructureIDTable::get):
+        (JSC::StructureIDTable::isValid):
+
+2019-02-13  Mark Lam  <mark.lam@apple.com>
+
+        Create a randomized free list for new StructureIDs on StructureIDTable resize.
+        https://bugs.webkit.org/show_bug.cgi?id=194566
+        <rdar://problem/47975502>
+
+        Reviewed by Michael Saboff.
+
+        Also isolate 32-bit implementation of StructureIDTable out more so the 64-bit
+        implementation is a little easier to read.
+
+        This patch appears to be perf neutral on JetStream2 (as run from the command line).
+
+        * runtime/StructureIDTable.cpp:
+        (JSC::StructureIDTable::StructureIDTable):
+        (JSC::StructureIDTable::makeFreeListFromRange):
+        (JSC::StructureIDTable::resize):
+        (JSC::StructureIDTable::allocateID):
+        (JSC::StructureIDTable::deallocateID):
+        * runtime/StructureIDTable.h:
+        (JSC::StructureIDTable::get):
+        (JSC::StructureIDTable::deallocateID):
+        (JSC::StructureIDTable::allocateID):
+        (JSC::StructureIDTable::flushOldTables):
+
+2019-02-11  Mark Lam  <mark.lam@apple.com>
+
+        Randomize insertion of deallocated StructureIDs into the StructureIDTable's free list.
+        https://bugs.webkit.org/show_bug.cgi?id=194512
+        <rdar://problem/47975465>
+
+        Reviewed by Yusuke Suzuki.
+
+        * runtime/StructureIDTable.cpp:
+        (JSC::StructureIDTable::StructureIDTable):
+        (JSC::StructureIDTable::allocateID):
+        (JSC::StructureIDTable::deallocateID):
+        * runtime/StructureIDTable.h:
+
+2019-06-13  Kocsen Chung  <kocsen_chung@apple.com>
+
</ins><span class="cx">         Apply patch. rdar://problem/51656844
</span><span class="cx"> 
</span><span class="cx">     2019-06-13  Tadeu Zagallo  <tzagallo@apple.com>
</span></span></pre></div>
<a id="branchessafari607branchSourceJavaScriptCoreftlFTLLowerDFGToB3cpp"></a>
<div class="modfile"><h4>Modified: branches/safari-607-branch/Source/JavaScriptCore/ftl/FTLLowerDFGToB3.cpp (246422 => 246423)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-607-branch/Source/JavaScriptCore/ftl/FTLLowerDFGToB3.cpp 2019-06-14 02:54:53 UTC (rev 246422)
+++ branches/safari-607-branch/Source/JavaScriptCore/ftl/FTLLowerDFGToB3.cpp    2019-06-14 02:59:16 UTC (rev 246423)
</span><span class="lines">@@ -16928,12 +16928,13 @@
</span><span class="cx"> 
</span><span class="cx">     LValue loadStructure(LValue value)
</span><span class="cx">     {
</span><del>-        LValue tableIndex = m_out.load32(value, m_heaps.JSCell_structureID);
-        LValue tableBase = m_out.loadPtr(
-            m_out.absolute(vm().heap.structureIDTable().base()));
-        TypedPointer address = m_out.baseIndex(
-            m_heaps.structureTable, tableBase, m_out.zeroExtPtr(tableIndex));
-        return m_out.loadPtr(address);
</del><ins>+        LValue structureID = m_out.load32(value, m_heaps.JSCell_structureID);
+        LValue tableBase = m_out.loadPtr(m_out.absolute(vm().heap.structureIDTable().base()));
+        LValue tableIndex = m_out.aShr(structureID, m_out.constInt32(StructureIDTable::s_numberOfEntropyBits));
+        LValue entropyBits = m_out.shl(m_out.zeroExtPtr(structureID), m_out.constInt32(StructureIDTable::s_entropyBitsShiftForStructurePointer));
+        TypedPointer address = m_out.baseIndex(m_heaps.structureTable, tableBase, m_out.zeroExtPtr(tableIndex));
+        LValue encodedStructureBits = m_out.loadPtr(address);
+        return m_out.bitXor(encodedStructureBits, entropyBits);
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     LValue weakPointer(JSCell* pointer)
</span></span></pre></div>
<a id="branchessafari607branchSourceJavaScriptCoreheapSlotVisitorcpp"></a>
<div class="modfile"><h4>Modified: branches/safari-607-branch/Source/JavaScriptCore/heap/SlotVisitor.cpp (246422 => 246423)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-607-branch/Source/JavaScriptCore/heap/SlotVisitor.cpp    2019-06-14 02:54:53 UTC (rev 246422)
+++ branches/safari-607-branch/Source/JavaScriptCore/heap/SlotVisitor.cpp       2019-06-14 02:59:16 UTC (rev 246423)
</span><span class="lines">@@ -1,5 +1,5 @@
</span><span class="cx"> /*
</span><del>- * Copyright (C) 2012-2018 Apple Inc. All rights reserved.
</del><ins>+ * Copyright (C) 2012-2019 Apple Inc. All rights reserved.
</ins><span class="cx">  *
</span><span class="cx">  * Redistribution and use in source and binary forms, with or without
</span><span class="cx">  * modification, are permitted provided that the following conditions
</span><span class="lines">@@ -198,8 +198,8 @@
</span><span class="cx">         
</span><span class="cx"> #if USE(JSVALUE64)
</span><span class="cx">         // This detects the worst of the badness.
</span><del>-        if (structureID >= heap()->structureIDTable().size())
-            die("GC scan found corrupt object: structureID is out of bounds!\n");
</del><ins>+        if (!heap()->structureIDTable().isValid(structureID))
+            die("GC scan found corrupt object: structureID is invalid!\n");
</ins><span class="cx"> #endif
</span><span class="cx">     };
</span><span class="cx">     
</span></span></pre></div>
<a id="branchessafari607branchSourceJavaScriptCorejitAssemblyHelperscpp"></a>
<div class="modfile"><h4>Modified: branches/safari-607-branch/Source/JavaScriptCore/jit/AssemblyHelpers.cpp (246422 => 246423)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-607-branch/Source/JavaScriptCore/jit/AssemblyHelpers.cpp 2019-06-14 02:54:53 UTC (rev 246422)
+++ branches/safari-607-branch/Source/JavaScriptCore/jit/AssemblyHelpers.cpp    2019-06-14 02:59:16 UTC (rev 246423)
</span><span class="lines">@@ -1,5 +1,5 @@
</span><span class="cx"> /*
</span><del>- * Copyright (C) 2011-2018 Apple Inc. All rights reserved.
</del><ins>+ * Copyright (C) 2011-2019 Apple Inc. All rights reserved.
</ins><span class="cx">  *
</span><span class="cx">  * Redistribution and use in source and binary forms, with or without
</span><span class="cx">  * modification, are permitted provided that the following conditions
</span><span class="lines">@@ -369,15 +369,30 @@
</span><span class="cx"> void AssemblyHelpers::emitLoadStructure(VM& vm, RegisterID source, RegisterID dest, RegisterID scratch)
</span><span class="cx"> {
</span><span class="cx"> #if USE(JSVALUE64)
</span><ins>+#if CPU(ARM64)
+    RegisterID scratch2 = dataTempRegister;
+#elif CPU(X86_64)
+    RegisterID scratch2 = scratchRegister();
+#else
+#error "Unsupported cpu"
+#endif
+
</ins><span class="cx">     ASSERT(dest != scratch);
</span><del>-    load32(MacroAssembler::Address(source, JSCell::structureIDOffset()), dest);
</del><ins>+    ASSERT(dest != scratch2);
+    ASSERT(scratch != scratch2);
+
+    load32(MacroAssembler::Address(source, JSCell::structureIDOffset()), scratch2);
</ins><span class="cx">     loadPtr(vm.heap.structureIDTable().base(), scratch);
</span><ins>+    rshift32(scratch2, TrustedImm32(StructureIDTable::s_numberOfEntropyBits), dest);
</ins><span class="cx">     loadPtr(MacroAssembler::BaseIndex(scratch, dest, MacroAssembler::TimesEight), dest);
</span><del>-#else
</del><ins>+    lshiftPtr(TrustedImm32(StructureIDTable::s_entropyBitsShiftForStructurePointer), scratch2);
+    xorPtr(scratch2, dest);
+#else // not USE(JSVALUE64)
</ins><span class="cx">     UNUSED_PARAM(scratch);
</span><ins>+    UNUSED_PARAM(scratch2);
</ins><span class="cx">     UNUSED_PARAM(vm);
</span><span class="cx">     loadPtr(MacroAssembler::Address(source, JSCell::structureIDOffset()), dest);
</span><del>-#endif
</del><ins>+#endif // not USE(JSVALUE64)
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void AssemblyHelpers::makeSpaceOnStackForCCall()
</span></span></pre></div>
<a id="branchessafari607branchSourceJavaScriptCorejitAssemblyHelpersh"></a>
<div class="modfile"><h4>Modified: branches/safari-607-branch/Source/JavaScriptCore/jit/AssemblyHelpers.h (246422 => 246423)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-607-branch/Source/JavaScriptCore/jit/AssemblyHelpers.h   2019-06-14 02:54:53 UTC (rev 246422)
+++ branches/safari-607-branch/Source/JavaScriptCore/jit/AssemblyHelpers.h      2019-06-14 02:59:16 UTC (rev 246423)
</span><span class="lines">@@ -1,5 +1,5 @@
</span><span class="cx"> /*
</span><del>- * Copyright (C) 2011-2018 Apple Inc. All rights reserved.
</del><ins>+ * Copyright (C) 2011-2019 Apple Inc. All rights reserved.
</ins><span class="cx">  *
</span><span class="cx">  * Redistribution and use in source and binary forms, with or without
</span><span class="cx">  * modification, are permitted provided that the following conditions
</span><span class="lines">@@ -1781,7 +1781,7 @@
</span><span class="cx">         storePtr(TrustedImmPtr(nullptr), Address(resultGPR, JSObject::butterflyOffset()));
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    JumpList branchIfValue(VM&, JSValueRegs value, GPRReg scratch, GPRReg scratchIfShouldCheckMasqueradesAsUndefined, FPRReg, FPRReg, bool shouldCheckMasqueradesAsUndefined, JSGlobalObject*, bool negateResult);
</del><ins>+    JumpList branchIfValue(VM&, JSValueRegs, GPRReg scratch, GPRReg scratchIfShouldCheckMasqueradesAsUndefined, FPRReg, FPRReg, bool shouldCheckMasqueradesAsUndefined, JSGlobalObject*, bool negateResult);
</ins><span class="cx">     JumpList branchIfTruthy(VM& vm, JSValueRegs value, GPRReg scratch, GPRReg scratchIfShouldCheckMasqueradesAsUndefined, FPRReg scratchFPR0, FPRReg scratchFPR1, bool shouldCheckMasqueradesAsUndefined, JSGlobalObject* globalObject)
</span><span class="cx">     {
</span><span class="cx">         return branchIfValue(vm, value, scratch, scratchIfShouldCheckMasqueradesAsUndefined, scratchFPR0, scratchFPR1, shouldCheckMasqueradesAsUndefined, globalObject, false);
</span><span class="lines">@@ -1790,7 +1790,7 @@
</span><span class="cx">     {
</span><span class="cx">         return branchIfValue(vm, value, scratch, scratchIfShouldCheckMasqueradesAsUndefined, scratchFPR0, scratchFPR1, shouldCheckMasqueradesAsUndefined, globalObject, true);
</span><span class="cx">     }
</span><del>-    void emitConvertValueToBoolean(VM&, JSValueRegs value, GPRReg result, GPRReg scratchIfShouldCheckMasqueradesAsUndefined, FPRReg, FPRReg, bool shouldCheckMasqueradesAsUndefined, JSGlobalObject*, bool negateResult = false);
</del><ins>+    void emitConvertValueToBoolean(VM&, JSValueRegs, GPRReg result, GPRReg scratchIfShouldCheckMasqueradesAsUndefined, FPRReg, FPRReg, bool shouldCheckMasqueradesAsUndefined, JSGlobalObject*, bool negateResult = false);
</ins><span class="cx">     
</span><span class="cx">     template<typename ClassType>
</span><span class="cx">     void emitAllocateDestructibleObject(VM& vm, GPRReg resultGPR, Structure* structure, GPRReg scratchGPR1, GPRReg scratchGPR2, JumpList& slowPath)
</span></span></pre></div>
<a id="branchessafari607branchSourceJavaScriptCorejitSpecializedThunkJITh"></a>
<div class="modfile"><h4>Modified: branches/safari-607-branch/Source/JavaScriptCore/jit/SpecializedThunkJIT.h (246422 => 246423)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-607-branch/Source/JavaScriptCore/jit/SpecializedThunkJIT.h       2019-06-14 02:54:53 UTC (rev 246422)
+++ branches/safari-607-branch/Source/JavaScriptCore/jit/SpecializedThunkJIT.h  2019-06-14 02:59:16 UTC (rev 246423)
</span><span class="lines">@@ -1,5 +1,5 @@
</span><span class="cx"> /*
</span><del>- * Copyright (C) 2010-2018 Apple Inc. All rights reserved.
</del><ins>+ * Copyright (C) 2010-2019 Apple Inc. All rights reserved.
</ins><span class="cx">  *
</span><span class="cx">  * Redistribution and use in source and binary forms, with or without
</span><span class="cx">  * modification, are permitted provided that the following conditions
</span><span class="lines">@@ -71,15 +71,6 @@
</span><span class="cx">             m_failures.append(branchIfNotString(dst));
</span><span class="cx">         }
</span><span class="cx">         
</span><del>-        void loadArgumentWithSpecificClass(const ClassInfo* classInfo, int argument, RegisterID dst, RegisterID scratch)
-        {
-            loadCellArgument(argument, dst);
-            emitLoadStructure(*vm(), dst, scratch, dst);
-            appendFailure(branchPtr(NotEqual, Address(scratch, Structure::classInfoOffset()), TrustedImmPtr(PoisonedClassInfoPtr(classInfo).bits())));
-            // We have to reload the argument since emitLoadStructure clobbered it.
-            loadCellArgument(argument, dst);
-        }
-        
</del><span class="cx">         void loadInt32Argument(int argument, RegisterID dst, Jump& failTarget)
</span><span class="cx">         {
</span><span class="cx">             unsigned src = CallFrame::argumentOffset(argument);
</span></span></pre></div>
<a id="branchessafari607branchSourceJavaScriptCorellintLowLevelInterpreterasm"></a>
<div class="modfile"><h4>Modified: branches/safari-607-branch/Source/JavaScriptCore/llint/LowLevelInterpreter.asm (246422 => 246423)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-607-branch/Source/JavaScriptCore/llint/LowLevelInterpreter.asm   2019-06-14 02:54:53 UTC (rev 246422)
+++ branches/safari-607-branch/Source/JavaScriptCore/llint/LowLevelInterpreter.asm      2019-06-14 02:59:16 UTC (rev 246423)
</span><span class="lines">@@ -204,6 +204,11 @@
</span><span class="cx">     const LowestTag = constexpr JSValue::LowestTag
</span><span class="cx"> end
</span><span class="cx"> 
</span><ins>+if JSVALUE64
+    const NumberOfStructureIDEntropyBits = constexpr StructureIDTable::s_numberOfEntropyBits
+    const StructureEntropyBitsShift = constexpr StructureIDTable::s_entropyBitsShiftForStructurePointer
+end
+
</ins><span class="cx"> const CallOpCodeSize = constexpr op_call_length
</span><span class="cx"> 
</span><span class="cx"> const maxFrameExtentForSlowPathCall = constexpr maxFrameExtentForSlowPathCall
</span></span></pre></div>
<a id="branchessafari607branchSourceJavaScriptCorellintLowLevelInterpreter64asm"></a>
<div class="modfile"><h4>Modified: branches/safari-607-branch/Source/JavaScriptCore/llint/LowLevelInterpreter64.asm (246422 => 246423)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-607-branch/Source/JavaScriptCore/llint/LowLevelInterpreter64.asm 2019-06-14 02:54:53 UTC (rev 246422)
+++ branches/safari-607-branch/Source/JavaScriptCore/llint/LowLevelInterpreter64.asm    2019-06-14 02:59:16 UTC (rev 246423)
</span><span class="lines">@@ -535,8 +535,12 @@
</span><span class="cx">     loadp CodeBlock[cfr], scratch
</span><span class="cx">     loadp CodeBlock::m_poisonedVM[scratch], scratch
</span><span class="cx">     unpoison(_g_CodeBlockPoison, scratch, scratch2)
</span><ins>+    move structureIDThenStructure, scratch2
+    rshifti NumberOfStructureIDEntropyBits, scratch2
</ins><span class="cx">     loadp VM::heap + Heap::m_structureIDTable + StructureIDTable::m_table[scratch], scratch
</span><del>-    loadp [scratch, structureIDThenStructure, PtrSize], structureIDThenStructure
</del><ins>+    loadp [scratch, scratch2, PtrSize], scratch2
+    lshiftp StructureEntropyBitsShift, structureIDThenStructure
+    xorp scratch2, structureIDThenStructure
</ins><span class="cx"> end
</span><span class="cx"> 
</span><span class="cx"> macro loadStructureWithScratch(cell, structure, scratch, scratch2)
</span><span class="lines">@@ -1175,7 +1179,7 @@
</span><span class="cx">     move ValueFalse, t1
</span><span class="cx">     return(t1)
</span><span class="cx"> .masqueradesAsUndefined:
</span><del>-    loadStructureWithScratch(t0, t3, t1, t5)
</del><ins>+    loadStructureWithScratch(t0, t3, t1, t2)
</ins><span class="cx">     loadp CodeBlock[cfr], t1
</span><span class="cx">     loadp CodeBlock::m_globalObject[t1], t1
</span><span class="cx">     cpeq Structure::m_globalObject[t3], t1, t0
</span></span></pre></div>
<a id="branchessafari607branchSourceJavaScriptCoreruntimeStructureIDTablecpp"></a>
<div class="modfile"><h4>Modified: branches/safari-607-branch/Source/JavaScriptCore/runtime/StructureIDTable.cpp (246422 => 246423)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-607-branch/Source/JavaScriptCore/runtime/StructureIDTable.cpp    2019-06-14 02:54:53 UTC (rev 246422)
+++ branches/safari-607-branch/Source/JavaScriptCore/runtime/StructureIDTable.cpp       2019-06-14 02:59:16 UTC (rev 246423)
</span><span class="lines">@@ -1,5 +1,5 @@
</span><span class="cx"> /*
</span><del>- * Copyright (C) 2013 Apple Inc. All rights reserved.
</del><ins>+ * Copyright (C) 2013-2019 Apple Inc. All rights reserved.
</ins><span class="cx">  *
</span><span class="cx">  * Redistribution and use in source and binary forms, with or without
</span><span class="cx">  * modification, are permitted provided that the following conditions
</span><span class="lines">@@ -31,19 +31,77 @@
</span><span class="cx"> 
</span><span class="cx"> namespace JSC {
</span><span class="cx"> 
</span><ins>+#if USE(JSVALUE64)
+
</ins><span class="cx"> StructureIDTable::StructureIDTable()
</span><del>-    : m_firstFreeOffset(0)
-    , m_table(makeUniqueArray<StructureOrOffset>(s_initialSize))
-    , m_size(0)
</del><ins>+    : m_table(makeUniqueArray<StructureOrOffset>(s_initialSize))
+    , m_size(1)
</ins><span class="cx">     , m_capacity(s_initialSize)
</span><span class="cx"> {
</span><span class="cx">     // We pre-allocate the first offset so that the null Structure
</span><span class="cx">     // can still be represented as the StructureID '0'.
</span><del>-    allocateID(0);
</del><ins>+    table()[0].encodedStructureBits = 0;
+
+    makeFreeListFromRange(1, m_capacity - 1);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void StructureIDTable::makeFreeListFromRange(uint32_t first, uint32_t last)
+{
+    ASSERT(!m_firstFreeOffset);
+    ASSERT(!m_lastFreeOffset);
+
+    // Put all the new IDs on the free list sequentially.
+    uint32_t head = first;
+    uint32_t tail = last;
+    for (uint32_t i = first; i < last; ++i)
+        table()[i].offset = i + 1;
+    table()[last].offset = 0;
+
+    // Randomize the free list.
+    uint32_t size = last - first + 1;
+    uint32_t maxIterations = (size * 2) / 3;
+    for (uint32_t count = 0; count < maxIterations; ++count) {
+        // Move a random pick either to the head or the tail of the free list.
+        uint32_t random = m_weakRandom.getUint32();
+        uint32_t nodeBefore = first + (random % size);
+        uint32_t pick = table()[nodeBefore].offset;
+        if (pick) {
+            uint32_t nodeAfter = table()[pick].offset;
+            table()[nodeBefore].offset = nodeAfter;
+            if ((random & 1) || !nodeAfter) {
+                // Move to the head.
+                table()[pick].offset = head;
+                head = pick;
+                if (!nodeAfter)
+                    tail = nodeBefore;
+            } else {
+                // Move to the tail.
+                table()[pick].offset = 0;
+                table()[tail].offset = pick;
+                tail = pick;
+            }
+        }
+    }
+
+    // Cut list in half and swap halves.
+    uint32_t cut = first + (m_weakRandom.getUint32() % size);
+    uint32_t afterCut = table()[cut].offset;
+    if (afterCut) {
+        table()[tail].offset = head;
+        tail = cut;
+        head = afterCut;
+        table()[cut].offset = 0;
+    }
+
+    m_firstFreeOffset = head;
+    m_lastFreeOffset = tail;
+}
+
</ins><span class="cx"> void StructureIDTable::resize(size_t newCapacity)
</span><span class="cx"> {
</span><ins>+    if (newCapacity > s_maximumNumberOfStructures)
+        newCapacity = s_maximumNumberOfStructures;
+
</ins><span class="cx">     // Create the new table.
</span><span class="cx">     auto newTable = makeUniqueArray<StructureOrOffset>(newCapacity);
</span><span class="cx"> 
</span><span class="lines">@@ -61,6 +119,8 @@
</span><span class="cx"> 
</span><span class="cx">     // Update the capacity.
</span><span class="cx">     m_capacity = newCapacity;
</span><ins>+
+    makeFreeListFromRange(m_size, m_capacity - 1);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void StructureIDTable::flushOldTables()
</span><span class="lines">@@ -70,52 +130,62 @@
</span><span class="cx"> 
</span><span class="cx"> StructureID StructureIDTable::allocateID(Structure* structure)
</span><span class="cx"> {
</span><del>-#if USE(JSVALUE64)
-    if (!m_firstFreeOffset) {
-        RELEASE_ASSERT(m_capacity <= UINT_MAX);
-        if (m_size == m_capacity)
-            resize(m_capacity * 2);
</del><ins>+    if (UNLIKELY(!m_firstFreeOffset)) {
+        RELEASE_ASSERT(m_capacity <= s_maximumNumberOfStructures);
+        ASSERT(m_size == m_capacity);
+        resize(m_capacity * 2);
</ins><span class="cx">         ASSERT(m_size < m_capacity);
</span><ins>+        RELEASE_ASSERT(m_firstFreeOffset);
+    }
</ins><span class="cx"> 
</span><del>-        StructureOrOffset newEntry;
-        newEntry.structure = structure;
-
-        if (m_size == s_unusedID) {
-            m_size++;
-            return allocateID(structure);
-        }
-
-        StructureID result = m_size;
-        table()[result] = newEntry;
-        m_size++;
-        ASSERT(!isNuked(result));
-        return result;
</del><ins>+    // entropyBits must not be zero. This ensures that if a corrupted
+    // structureID is encountered (with incorrect entropyBits), the decoded
+    // structure pointer for that ID will be always be a bad pointer with
+    // high bits set.
+    constexpr uint32_t entropyBitsMask = (1 << s_numberOfEntropyBits) - 1;
+    uint32_t entropyBits = m_weakRandom.getUint32() & entropyBitsMask;
+    if (UNLIKELY(!entropyBits)) {
+        constexpr uint32_t numberOfValuesToPickFrom = entropyBitsMask;
+        entropyBits = (m_weakRandom.getUint32() % numberOfValuesToPickFrom) + 1;
</ins><span class="cx">     }
</span><span class="cx"> 
</span><del>-    ASSERT(m_firstFreeOffset != s_unusedID);
</del><ins>+    uint32_t structureIndex = m_firstFreeOffset;
+    m_firstFreeOffset = table()[m_firstFreeOffset].offset;
+    if (!m_firstFreeOffset)
+        m_lastFreeOffset = 0;
</ins><span class="cx"> 
</span><del>-    StructureID result = m_firstFreeOffset;
-    m_firstFreeOffset = table()[m_firstFreeOffset].offset;
-    table()[result].structure = structure;
</del><ins>+    StructureID result = (structureIndex << s_numberOfEntropyBits) | entropyBits;
+    table()[structureIndex].encodedStructureBits = encode(structure, result);
+    m_size++;
</ins><span class="cx">     ASSERT(!isNuked(result));
</span><span class="cx">     return result;
</span><del>-#else
-    ASSERT(!isNuked(structure));
-    return structure;
-#endif
</del><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void StructureIDTable::deallocateID(Structure* structure, StructureID structureID)
</span><span class="cx"> {
</span><del>-#if USE(JSVALUE64)
</del><span class="cx">     ASSERT(structureID != s_unusedID);
</span><del>-    RELEASE_ASSERT(table()[structureID].structure == structure);
-    table()[structureID].offset = m_firstFreeOffset;
-    m_firstFreeOffset = structureID;
-#else
-    UNUSED_PARAM(structure);
-    UNUSED_PARAM(structureID);
-#endif
</del><ins>+    uint32_t structureIndex = structureID >> s_numberOfEntropyBits;
+    ASSERT(structureIndex && structureIndex < s_maximumNumberOfStructures);
+    RELEASE_ASSERT(table()[structureIndex].encodedStructureBits == encode(structure, structureID));
+    m_size--;
+    if (!m_firstFreeOffset) {
+        table()[structureIndex].offset = 0;
+        m_firstFreeOffset = structureIndex;
+        m_lastFreeOffset = structureIndex;
+        return;
+    }
+
+    bool insertAtHead = m_weakRandom.getUint32() & 1;
+    if (insertAtHead) {
+        table()[structureIndex].offset = m_firstFreeOffset;
+        m_firstFreeOffset = structureIndex;
+    } else {
+        table()[structureIndex].offset = 0;
+        table()[m_lastFreeOffset].offset = structureIndex;
+        m_lastFreeOffset = structureIndex;
+    }
</ins><span class="cx"> }
</span><span class="cx"> 
</span><ins>+#endif // USE(JSVALUE64)
+
</ins><span class="cx"> } // namespace JSC
</span></span></pre></div>
<a id="branchessafari607branchSourceJavaScriptCoreruntimeStructureIDTableh"></a>
<div class="modfile"><h4>Modified: branches/safari-607-branch/Source/JavaScriptCore/runtime/StructureIDTable.h (246422 => 246423)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-607-branch/Source/JavaScriptCore/runtime/StructureIDTable.h      2019-06-14 02:54:53 UTC (rev 246422)
+++ branches/safari-607-branch/Source/JavaScriptCore/runtime/StructureIDTable.h 2019-06-14 02:59:16 UTC (rev 246423)
</span><span class="lines">@@ -1,5 +1,5 @@
</span><span class="cx"> /*
</span><del>- * Copyright (C) 2013 Apple Inc. All rights reserved.
</del><ins>+ * Copyright (C) 2013-2019 Apple Inc. All rights reserved.
</ins><span class="cx">  *
</span><span class="cx">  * Redistribution and use in source and binary forms, with or without
</span><span class="cx">  * modification, are permitted provided that the following conditions
</span><span class="lines">@@ -28,6 +28,7 @@
</span><span class="cx"> #include "UnusedPointer.h"
</span><span class="cx"> #include <wtf/UniqueArray.h>
</span><span class="cx"> #include <wtf/Vector.h>
</span><ins>+#include <wtf/WeakRandom.h>
</ins><span class="cx"> 
</span><span class="cx"> namespace JSC {
</span><span class="cx"> 
</span><span class="lines">@@ -55,7 +56,7 @@
</span><span class="cx"> {
</span><span class="cx">     return id & ~nukedStructureIDBit();
</span><span class="cx"> }
</span><del>-#else
</del><ins>+#else // not USE(JSVALUE64)
</ins><span class="cx"> typedef Structure* StructureID;
</span><span class="cx"> 
</span><span class="cx"> inline StructureID nukedStructureIDBit()
</span><span class="lines">@@ -77,8 +78,12 @@
</span><span class="cx"> {
</span><span class="cx">     return bitwise_cast<StructureID>(bitwise_cast<uintptr_t>(id) & ~bitwise_cast<uintptr_t>(nukedStructureIDBit()));
</span><span class="cx"> }
</span><del>-#endif
</del><ins>+#endif // not USE(JSVALUE64)
</ins><span class="cx"> 
</span><ins>+#if USE(JSVALUE64)
+
+using EncodedStructureBits = uintptr_t;
+
</ins><span class="cx"> class StructureIDTable {
</span><span class="cx">     friend class LLIntOffsetsExtractor;
</span><span class="cx"> public:
</span><span class="lines">@@ -86,6 +91,7 @@
</span><span class="cx"> 
</span><span class="cx">     void** base() { return reinterpret_cast<void**>(&m_table); }
</span><span class="cx"> 
</span><ins>+    bool isValid(StructureID);
</ins><span class="cx">     Structure* get(StructureID);
</span><span class="cx">     void deallocateID(Structure*, StructureID);
</span><span class="cx">     StructureID allocateID(Structure*);
</span><span class="lines">@@ -96,41 +102,114 @@
</span><span class="cx"> 
</span><span class="cx"> private:
</span><span class="cx">     void resize(size_t newCapacity);
</span><ins>+    void makeFreeListFromRange(uint32_t first, uint32_t last);
</ins><span class="cx"> 
</span><span class="cx">     union StructureOrOffset {
</span><span class="cx">         WTF_MAKE_FAST_ALLOCATED;
</span><span class="cx">     public:
</span><del>-        Structure* structure;
</del><ins>+        EncodedStructureBits encodedStructureBits;
</ins><span class="cx">         StructureID offset;
</span><span class="cx">     };
</span><span class="cx"> 
</span><span class="cx">     StructureOrOffset* table() const { return m_table.get(); }
</span><span class="cx">     
</span><del>-    static const size_t s_initialSize = 256;
</del><ins>+    static Structure* decode(EncodedStructureBits, StructureID);
+    static EncodedStructureBits encode(Structure*, StructureID);
</ins><span class="cx"> 
</span><ins>+    static constexpr size_t s_initialSize = 512;
+
</ins><span class="cx">     Vector<UniqueArray<StructureOrOffset>> m_oldTables;
</span><span class="cx"> 
</span><del>-    uint32_t m_firstFreeOffset;
</del><ins>+    uint32_t m_firstFreeOffset { 0 };
+    uint32_t m_lastFreeOffset { 0 };
</ins><span class="cx">     UniqueArray<StructureOrOffset> m_table;
</span><span class="cx"> 
</span><del>-    size_t m_size;
</del><ins>+    size_t m_size { 0 };
</ins><span class="cx">     size_t m_capacity;
</span><span class="cx"> 
</span><del>-#if USE(JSVALUE64)
-    static const StructureID s_unusedID = unusedPointer;
-#endif
</del><ins>+    WeakRandom m_weakRandom;
+
+    static constexpr StructureID s_unusedID = 0;
+
+public:
+    // 1. StructureID is encoded as:
+    //
+    //    ----------------------------------------------------------------
+    //    | 1 Nuke Bit | 24 StructureIDTable index bits | 7 entropy bits |
+    //    ----------------------------------------------------------------
+    //
+    //    The entropy bits are chosen at random and assigned when a StructureID
+    //    is allocated.
+    //
+    // 2. For each StructureID, the StructureIDTable stores encodedStructureBits
+    //    which are encoded from the structure pointer as such:
+    //
+    //    ----------------------------------------------------------------
+    //    | 7 entropy bits |                   57 structure pointer bits |
+    //    ----------------------------------------------------------------
+    //
+    //    The entropy bits here are the same 7 bits used in the encoding of the
+    //    StructureID for this structure entry in the StructureIDTable.
+
+    static constexpr uint32_t s_numberOfNukeBits = 1;
+    static constexpr uint32_t s_numberOfEntropyBits = 7;
+    static constexpr uint32_t s_entropyBitsShiftForStructurePointer = (sizeof(intptr_t) * 8) - s_numberOfEntropyBits;
+
+    static constexpr uint32_t s_maximumNumberOfStructures = 1 << (32 - s_numberOfEntropyBits - s_numberOfNukeBits);
</ins><span class="cx"> };
</span><span class="cx"> 
</span><ins>+ALWAYS_INLINE Structure* StructureIDTable::decode(EncodedStructureBits bits, StructureID structureID)
+{
+    return bitwise_cast<Structure*>(bits ^ (static_cast<uintptr_t>(structureID) << s_entropyBitsShiftForStructurePointer));
+}
+
+ALWAYS_INLINE EncodedStructureBits StructureIDTable::encode(Structure* structure, StructureID structureID)
+{
+    return bitwise_cast<EncodedStructureBits>(structure) ^ (static_cast<EncodedStructureBits>(structureID) << s_entropyBitsShiftForStructurePointer);
+}
+
</ins><span class="cx"> inline Structure* StructureIDTable::get(StructureID structureID)
</span><span class="cx"> {
</span><del>-#if USE(JSVALUE64)
</del><span class="cx">     ASSERT_WITH_SECURITY_IMPLICATION(structureID);
</span><span class="cx">     ASSERT_WITH_SECURITY_IMPLICATION(!isNuked(structureID));
</span><del>-    ASSERT_WITH_SECURITY_IMPLICATION(structureID < m_capacity);
-    return table()[structureID].structure;
-#else
-    return structureID;
</del><ins>+    uint32_t structureIndex = structureID >> s_numberOfEntropyBits;
+    ASSERT_WITH_SECURITY_IMPLICATION(structureIndex < m_capacity);
+    return decode(table()[structureIndex].encodedStructureBits, structureID);
+}
+
+inline bool StructureIDTable::isValid(StructureID structureID)
+{
+    if (!structureID)
+        return false;
+    uint32_t structureIndex = structureID >> s_numberOfEntropyBits;
+    if (structureIndex >= m_capacity)
+        return false;
+#if CPU(ADDRESS64)
+    Structure* structure = decode(table()[structureIndex].encodedStructureBits, structureID);
+    if (reinterpret_cast<uintptr_t>(structure) >> s_entropyBitsShiftForStructurePointer)
+        return false;
</ins><span class="cx"> #endif
</span><ins>+    return true;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><ins>+#else // not USE(JSVALUE64)
+
+class StructureIDTable {
+    friend class LLIntOffsetsExtractor;
+public:
+    StructureIDTable() = default;
+
+    Structure* get(StructureID structureID) { return structureID; }
+    void deallocateID(Structure*, StructureID) { }
+    StructureID allocateID(Structure* structure)
+    {
+        ASSERT(!isNuked(structure));
+        return structure;
+    };
+
+    void flushOldTables() { }
+};
+
+#endif // not USE(JSVALUE64)
+
</ins><span class="cx"> } // namespace JSC
</span></span></pre>
</div>
</div>

</body>
</html>