Assignment 08 Task 1

Dennis Albrecht
Sonntagsinformatiker
Sonntagsinformatiker
Beiträge: 222
Registriert: 4. Okt 2010 18:15

Assignment 08 Task 1

Beitrag 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

Boddlnagg
Mausschubser
Mausschubser
Beiträge: 54
Registriert: 10. Dez 2012 12:07

Re: Assignment 08 Task 1

Beitrag 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.

Sem
Erstie
Erstie
Beiträge: 21
Registriert: 20. Apr 2013 11:13

Re: Assignment 08 Task 1

Beitrag 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.

tbecker
Windoof-User
Windoof-User
Beiträge: 31
Registriert: 13. Okt 2008 23:31

Re: Assignment 08 Task 1

Beitrag 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
Tutor:
GdI I (SS12)
GdI I (WS12/13)

Dennis Albrecht
Sonntagsinformatiker
Sonntagsinformatiker
Beiträge: 222
Registriert: 4. Okt 2010 18:15

Re: Assignment 08 Task 1

Beitrag 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

Dennis Albrecht
Sonntagsinformatiker
Sonntagsinformatiker
Beiträge: 222
Registriert: 4. Okt 2010 18:15

Re: Assignment 08 Task 1

Beitrag 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

Antworten

Zurück zu „Archiv“