## GC: Solution for GroupdEx6.2

Hoang
Erstie
Beiträge: 11
Registriert: 6. Nov 2013 15:02

### GC: Solution for GroupdEx6.2

Hi

I have some questions regarding the solution for the GC task (GroupEx6.2):

1 - In the store before GC there are numbers which are noted as:
The numbers in the Data column are store locations and are referencing
the same Scala object the given store location, e.g. store location 2 references
So are they basically Box Values (one can see that after reading the interpreter code) ? For example, the first 3 locations are:
0 - Num(10)
1 - Box(0)
2 - 1
Is this equivalent to:
0 - Num(10)
1 - Box(0)
2 - Box(0)
?

2 - The solution for no-moving GC: Why are the location 5, 7, 11, 12 not cleaned up? For example there is no reference to location 5. At location 6 (where a live value is stored) there is the number "5" But this only means (regarding the GC implementation for SRCFLAE) that the value at location 6 is the same value stored at location 5.

Or the language addressed in this exercise is Scala, not SRCFLAE and its GC implementation? So my last question is:
3 - Will the store look the same if we consider SRCFLAE and the given GC implementation?

Best regards

timw
Neuling
Beiträge: 7
Registriert: 13. Apr 2015 15:48

### Re: GC: Solution for GroupdEx6.2

Probably this thread helps you with the first two questions.

Hoang
Erstie
Beiträge: 11
Registriert: 6. Nov 2013 15:02

### Re: GC: Solution for GroupdEx6.2

Thanks! The answer of someone there is the same as what I suppose above about the meaning of the task definition.

So there is a big difference between the "memory model" for SRCFLAE and the one of Scala.

In SRCFLAE we have stack and store. The store is the "end memory". But the Scala's store mentioned in the task is basically not the "end memory", in other words it does not store values but references to values. This may confuse people including me as I'm still not sure if we understand the task correctly.

Jannis
Mausschubser
Beiträge: 63
Registriert: 15. Apr 2015 17:10

### Re: GC: Solution for GroupdEx6.2

The store mentioned in the task is actually also the "end memory". Maybe it gets more clear in the following example:

Code: Alles auswählen

sealed abstract class Val(var marked: Boolean = false)
case class SomeValue(field: String) extends Val

object Test {
def main(args: Array[String]) : Unit = {
val v = SomeValue("foo")
val memory = new scala.collection.mutable.ArraySeq[Val](10) // same as the MarkAndSweepStore
memory.update(1, v)
memory.update(2, memory(1)) // simulate the "Id lookup" and insert the value at a new location
println(memory(1).marked + " / " + memory(2).marked)
v.marked = true
println(memory(1).marked + " / " + memory(2).marked)
}
}

The first println command prints "false / false" and the second one "true / true" because both locations in the memory contain the same object. I guess that Scala works the same as Java at that part. This means that internally v is just a reference to an instance of SomeValue. Therefore memory(1) and memory(2) contain references to the same instance which implies that mutating one of them also mutates the observed value at the other index.

Hoang
Erstie
Beiträge: 11
Registriert: 6. Nov 2013 15:02

### Re: GC: Solution for GroupdEx6.2

Hi Jannis

With "end memory" I mean the one which is equivalent to the store of SRCFLA. The "end memory" is the real "physical memory" (as modeled in SRCFLA).

If the task addresses SRCFLA (as implemented in the svn folder), the given solution would not be correct, I think

mirko-koehler
Mausschubser
Beiträge: 66
Registriert: 16. Okt 2017 12:28

### Re: GC: Solution for GroupdEx6.2

When you run the program in SRCFLAE then you get the following stores:

Before GC
= ArraySeq(NumV(10), Box(0), Box(0), Box(2), NumV(11), Box(4), Box(4), Box(6), Box(0), Box(8), Box(6), Box(10), Box(10), Box(12), Box(10), Box(14))

After GC (concrete call: store.gc(List(Map('res -> 15))) )
= ArraySeq(null, null, null, null, NumV(11), Box(4), Box(4), Box(6), null, null, Box(6), Box(10), Box(10), null, Box(10), Box(14))

This is the same as the non-moving GC in Task 6.2.