<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>84927</bug_id>
          
          <creation_ts>2012-04-25 21:11:55 -0700</creation_ts>
          <short_desc>End of Interpreter::tryCacheGetByID can trigger the garbage collector</short_desc>
          <delta_ts>2012-04-30 12:19:23 -0700</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>JavaScriptCore</component>
          <version>528+ (Nightly build)</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>0</everconfirmed>
          <reporter name="Myles C. Maxfield">litherum</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>barraclough</cc>
    
    <cc>ggaren</cc>
    
    <cc>mhahnenberg</cc>
    
    <cc>oliver</cc>
    
    <cc>webkit.review.bot</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>610328</commentid>
    <comment_count>0</comment_count>
    <who name="Myles C. Maxfield">litherum</who>
    <bug_when>2012-04-25 21:11:55 -0700</bug_when>
    <thetext>Here is what I believe is going on:

1. The BytecodeGenerator runs emitGetById() in order to emit an op_get_by_id instruction.
        a. This calls m_codeBlock-&gt;addPropertyAccessInstruction, which saves the current index as a property access instruction (I&apos;m using the classic interpreter).
2. Upon execution, Interpreter::privateExecute encounters the op_get_by_id and calls Interpreter::tryCacheGetByID.
3. Interpreter::tryCacheGetByID falls through to the very bottom, where it:
        a. Overwrites the opcode with a op_get_by_id_chain
        b. fills in vPC[7] and vPC[4]
        c. Tries to fill in vPC[5] with structure-&gt;prototypeChain(callFrame). Note that the call itself happens before vPC[5] gets assigned.
4. the cached prototype chain isn&apos;t valid, so Structure::prototypeChain calls StructureChain::create(), which uses placement new to call allocateCell&lt;StructureChain&gt;()
5. allocateCell can, under the right circumstances, cause m_heap-&gt;collect(Heap::DoNotSweep) in MarkedAllocator::allocateSlowCase
6. The collection routine walks the C++ stack, looking for valid pointers. One of the pointers it finds is a pointer to the CodeBlock/ScriptExecutable object.
7. While trying to drain the CodeBlock object, it tries to visit each of its children. It does this by going through each of the property access instructions (step 1) to access each of the properties. One of the indices it comes across points to the instruction that was just overwritten in step 3)
8. Believing the opcode to be a correctly-formed op_get_by_id_chain instruction, it attempts to append vPC[5], which hasn&apos;t been set yet.

The solution is probably to move the structure-&gt;prototypeChain(callFrame) before any modification to vPC in Interpreter::tryCacheGetByID. oliver@apple.com: How does this sound to you? I&apos;ll upload a patch if this sounds reasonable.

Should I try to create an example javascript program that triggers this?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>612758</commentid>
    <comment_count>1</comment_count>
      <attachid>139479</attachid>
    <who name="Myles C. Maxfield">litherum</who>
    <bug_when>2012-04-30 10:58:58 -0700</bug_when>
    <thetext>Created attachment 139479
Patch</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>612780</commentid>
    <comment_count>2</comment_count>
    <who name="Geoffrey Garen">ggaren</who>
    <bug_when>2012-04-30 11:17:51 -0700</bug_when>
    <thetext>I&apos;m starting to think we should just generally prohibit GC in C++ code, except in certain rare cases like JSON processing or re-entry from C++ into the VM.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>612867</commentid>
    <comment_count>3</comment_count>
      <attachid>139479</attachid>
    <who name="WebKit Review Bot">webkit.review.bot</who>
    <bug_when>2012-04-30 12:19:19 -0700</bug_when>
    <thetext>Comment on attachment 139479
Patch

Clearing flags on attachment: 139479

Committed r115657: &lt;http://trac.webkit.org/changeset/115657&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>612868</commentid>
    <comment_count>4</comment_count>
    <who name="WebKit Review Bot">webkit.review.bot</who>
    <bug_when>2012-04-30 12:19:23 -0700</bug_when>
    <thetext>All reviewed patches have been landed.  Closing bug.</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="1"
              isprivate="0"
          >
            <attachid>139479</attachid>
            <date>2012-04-30 10:58:58 -0700</date>
            <delta_ts>2012-04-30 12:19:18 -0700</delta_ts>
            <desc>Patch</desc>
            <filename>bug-84927-20120430105900.patch</filename>
            <type>text/plain</type>
            <size>1634</size>
            <attacher name="Myles C. Maxfield">litherum</attacher>
            
              <data encoding="base64">SW5kZXg6IFNvdXJjZS9KYXZhU2NyaXB0Q29yZS9DaGFuZ2VMb2cKPT09PT09PT09PT09PT09PT09
PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PQotLS0gU291
cmNlL0phdmFTY3JpcHRDb3JlL0NoYW5nZUxvZwkocmV2aXNpb24gMTE1NjUyKQorKysgU291cmNl
L0phdmFTY3JpcHRDb3JlL0NoYW5nZUxvZwkod29ya2luZyBjb3B5KQpAQCAtMSwzICsxLDEzIEBA
CisyMDEyLTA0LTMwICBNeWxlcyBNYXhmaWVsZCAgPG1tYXhmaWVsZEBnb29nbGUuY29tPgorCisg
ICAgICAgIEVuZCBvZiBJbnRlcnByZXRlcjo6dHJ5Q2FjaGVHZXRCeUlEIGNhbiB0cmlnZ2VyIHRo
ZSBnYXJiYWdlIGNvbGxlY3RvcgorICAgICAgICBodHRwczovL2J1Z3Mud2Via2l0Lm9yZy9zaG93
X2J1Zy5jZ2k/aWQ9ODQ5MjcKKworICAgICAgICBSZXZpZXdlZCBieSBOT0JPRFkgKE9PUFMhKS4K
KworICAgICAgICAqIGludGVycHJldGVyL0ludGVycHJldGVy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