Seite 1 von 1

Assignment 08 Task 1

Verfasst: 12. Jun 2014 19:31
von Dennis Albrecht
Hey guys!

I think the description of the first task might be wrong:
Each GC must trigger all WeakRefV in the store to be invalid.
The formulation of this sentence is quite mistakable. Think of the following situation:

Code: Alles auswählen

Store = Array(NumV(42), WeakRefV(0), Box(0), ...)
Stack = List(Map('x -> 1, 'y -> 2), ...)
As both the WeakRef and the Box are referenced by the stack, the numerical value should be kept. One possible interpretation of this sentence could now be to not mark (or unmark) the numerical value at location 0. Or to remove the WeakRefV itself because it is meant to be invalid itself.
Your intention was probably somethink like: "The GC should not mark the target of a WeakRef"
For this purpose, rewrite the reference in the WeakRefV to the given value INVALID_LOC.
Whereas the first quoted sentence could be interpreted correctly (having the theory of weak references in mind), this sentence is totally wrong in my opinion. I can only think of one interpretation of this sentence, saying: "After GC all WeakRefs are pointing to the invalid location". In the situation of sentence 1 it would be against (at least my) expectation if the WeakRef wouldn't point to the NumV any more although the value still exists.

Any comments?

Greeets Dennis

PS: If I assume that my comments are correct, I would need to add the stack to the sweep-phase like for the moving store. Is this ok?
edit: Ok, I think, I night not need the stack for the sweep-phase

Re: Assignment 08 Task 1

Verfasst: 13. Jun 2014 00:29
von Boddlnagg
As I understand the task, we are actually supposed to render ALL weak references invalid, even if what it's pointing to is not garbage collected and the reference could still be alive. I implemented it that way and the tests passed, though this is certainly a bit weird. I'd appreciate if someone could explain this.

Re: Assignment 08 Task 1

Verfasst: 13. Jun 2014 09:21
von Sem
Boddlnagg hat geschrieben:ALL weak references invalid, even if what it's pointing to is not garbage collected
I also implemented it this way, but it confused me at most. Just curious whether it is correct.

Re: Assignment 08 Task 1

Verfasst: 14. Jun 2014 16:10
von tbecker
Hi,
Dennis Albrecht hat geschrieben: Think of the following situation:

Code: Alles auswählen

Store = Array(NumV(42), WeakRefV(0), Box(0), ...)
Stack = List(Map('x -> 1, 'y -> 2), ...)
I tried constructing your example for a test, but keep getting multiple NumV(42). Any sugggestion how to get to this particular store?

regards Tobias

Re: Assignment 08 Task 1

Verfasst: 15. Jun 2014 02:16
von Dennis Albrecht
I haven't tried it, but probably something like:

Code: Alles auswählen

Let('x, Num(42), Let('y, WeakRef(x), Let('z, OpenBox(x), [...] )))
If the execution reaches the [...]-term the Store should look like in my example.

But as the Stack would contain x, y and z in this example (but my example would only allow the references to y and z) you need a more complex program to "forget" about x:

Code: Alles auswählen

Let('refs,
   Let('x, Num(42),
      Let('y, WeakRef(x),
         Let('z, OpenBox(x),
            Ctor('Pair, List('y, 'z))
         )
      )
   ),
   Match(List(
      ('Pair, List('weakref, 'strongref), [...] )
   ))
)
No warranty that this would exactly produce the mentioned situation. And yes, this example requires Ctor- and Match-constructs that the task does not offer but who says that these two features (GC and Ctor) aren't combinable?!?

Greets Dennis

Re: Assignment 08 Task 1

Verfasst: 15. Jun 2014 02:24
von Dennis Albrecht
Ok, my last comment is an example for a real-life-situation but if you just want a test for this, it's much simpler:

Code: Alles auswählen

val (targetLoc, _) = st.malloc(emptyStack, NumV(42))
val (weakLoc, _) = st.malloc(emptyStack, WeakRefV(targetLoc))
val (strongLoc, _) = st.malloc(emptyStack, Box(targetLoc))
st.gc(List(Map('x -> weakLoc, 'y -> strongLoc)))
with store at least of size 3.

Greets Dennis