<html>
  <head>
    <meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    <font face="Georgia">I'm not sure all the reasons that led you to
      the tricky solution, but less tricky alternatives could use some
      sort of shared dictionary. This would need cleaning from time to
      time, but that wouldn't be hard.<br>
      ---------------------<br>
      Using a class variable<br>
    </font><br>
    <font face="Georgia">foo2: theSession</font><br>
    <font face="Georgia">"</font><br>
    <font face="Georgia">SomeClass new foo2: 'thisIsMySession',Time now
      asString; writeBarrier</font><br>
    <font face="Georgia">"</font><br>
    <font face="Georgia">    </font><br>
    <font face="Georgia">    SomeClassDictionary ifNil:
      [SomeClassDictionary _ Dictionary new].</font><br>
    <font face="Georgia">    SomeClassCounter ifNil: [SomeClassCounter _
      0].</font><br>
    <font face="Georgia">    SomeClassCounter _ SomeClassCounter + 1.</font><br>
    <font face="Georgia">    SomeClassDictionary at: SomeClassCounter
      put: (WeakArray with: theSession).</font><br>
    <font face="Georgia">    self class compileSilently:</font><br>
    <font face="Georgia">                 'writeBarrier</font><br>
    <font face="Georgia">                       ^ (SomeClassDictionary
      at: ',SomeClassCounter,') first'</font><br>
    <font face="Georgia">        classified: 'accessing'.</font><br>
    <font face="Georgia"><br>
      generates something like this:<br>
      <br>
      writeBarrier<br>
          ^ (SomeClassDictionary at: 7) first<br>
    </font><font face="Georgia"><br>
      ---------------<br>
      Using a pool dictionary <br>
      <br>
      foo1: theSession<br>
      "<br>
      SomeClass new foo1: 'thisIsMySession',Time now asString;
      writeBarrier<br>
      "<br>
          | id |<br>
          <br>
          SomeClassCounter ifNil: [SomeClassCounter _ 0].<br>
          SomeClassCounter _ SomeClassCounter + 1.<br>
          id _ ('MyPoolID',SomeClassCounter asString) asSymbol.<br>
          SomeClassPool at: id put: (WeakArray with: theSession).<br>
          self class compileSilently:<br>
                       'writeBarrier<br>
                             ^ ',id,' first'<br>
              classified: 'accessing'.<br>
      <br>
      generates something like this:<br>
      <br>
      writeBarrier<br>
          ^ MyPoolID8 first<br>
      ------------------<br>
      <br>
      Either might be a bit less fragile.<br>
      <br>
      Cheers,<br>
      Bob<br>
    </font><br>
    <div class="moz-cite-prefix">On 12/27/12 10:20 AM, Chris Muller
      wrote:<br>
    </div>
    <blockquote
cite="mid:CANzdToFE=q6=vHokYvOZRp=rxe6f=_UU4pOT6NdJ-GaFLVanRw@mail.gmail.com"
      type="cite">
      <pre wrap="">That's a great suggestion.  I did it and, so far, the issue has not
occurred.  It might be fixed, thank you!

On Wed, Dec 26, 2012 at 11:47 AM, Bob Arning <a class="moz-txt-link-rfc2396E" href="mailto:arning315@comcast.net">&lt;arning315@comcast.net&gt;</a> wrote:
</pre>
      <blockquote type="cite">
        <pre wrap="">What if, instead of substituting a new literal in the CM, you tried
modifying the literal itself? Maybe COG would not object to that.

   myDomainSubclass
        compileSilently:
                 'writeBarrier
                       ^ #(foo) first first'
        classified: 'accessing'.

   ((myDomainSubclass methodDictionary at: #writeBarrier)
       literalAt: 2) at: 1
       put: (WeakArray with: theSession)


On 12/26/12 12:09 PM, Chris Muller wrote:

With Eliot's latest Cog things are really rocking!  But I am still
having one issue which seems to be related to a Cog code-generation /
timing issue.

It relates to a hack that dynamically creates a subclass of a domain
class to generate overrides of all of its methods that potentially
change the state of the object (e.g., a write-barrier).

In addition to the overriding methods, it also must generate one
accessor method which is used to refer to a Session object, so that
the overriding methods can notify it if, in fact, an inst-var changed.

When I generate the subclass, I _cannot_ add any new inst-vars to hold
the Session (because primChangeClassTo: requires the same physical
shape).  So, to make the hack work at all, first I compile the
following method to establish slots for a couple of literals:

   myDomainSubclass
        compileSilently:
                 'writeBarrier
                       ^ Object first'
        classified: 'accessing'.

Then slap in the Session object I want into the second slot:

   (myDomainSubclass methodDictionary at: #writeBarrier)
       literalAt: 2
       put: #Object -&gt; (WeakArray with: theSession)

Voila!  theSession has now been hacked into the CM at literal 2.
"Object" in the code now refers to the WeakArray holding my Session
rather than the Object class.

I wouldn't do this at all if it wasn't for the 3X improvement in
commit performance.  However, about once or twice a day, I encounter a
debugger which indicates, by the accessing attempt, it thinks that
literal 2 is an Integer or a Character.  Most of the time simply
printing "self writeBarrier" right there in the debugger produces the
correct answer (the Session object) -- as if Cog suddenly "caught up"
with it.

Any suggestions are greatly appreciated, thank you!






</pre>
      </blockquote>
      <pre wrap="">

</pre>
    </blockquote>
    <br>
  </body>
</html>