To protect your data, the CISO officer has suggested users to enable GitLab 2FA as soon as possible.

UvmInterpreterStackGCTests.scala 1.71 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
package uvm.refimpl.itpr

import org.scalatest._
import java.io.FileReader
import uvm._
import uvm.types._
import uvm.ssavariables._
import uvm.refimpl._
import uvm.refimpl.itpr._
import MemoryOrder._
import AtomicRMWOptr._
import uvm.refimpl.mem.TypeSizes.Word
import ch.qos.logback.classic.Level._
import uvm.refimpl.UvmBundleTesterBase

class UvmInterpreterStackGCTests extends UvmBundleTesterBase {
  setLogLevels(
    ROOT_LOGGER_NAME -> INFO,
    "uvm.refimpl.itpr" -> DEBUG,
    "uvm.refimpl.mem" -> DEBUG)

Kunshan Wang's avatar
Kunshan Wang committed
22
  preloadBundles("tests/uvm-refimpl-test/primitives.uir", "tests/uvm-refimpl-test/gc-tests.uir")
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45

  def gc() = microVM.memoryManager.heap.mutatorTriggerAndWaitForGCEnd(false)

  /** Disable some logger for allocation-heavy parts. */
  def quiet[T](f: => T): T = {
    setLogLevels(
      "uvm.refimpl.itpr" -> INFO,
      "uvm.refimpl.mem.simpleimmix.SimpleImmixMutator$" -> INFO,
      "uvm.refimpl.mem.HeaderUtils" -> INFO)

    val rv = f

    setLogLevels("uvm.refimpl.itpr" -> DEBUG,
      "uvm.refimpl.mem.simpleimmix.SimpleImmixMutator$" -> null,
      "uvm.refimpl.mem.HeaderUtils" -> null)

    rv
  }

  // Half of the heap (1MB) space is LOS. It can accommodate 16 stacks.
  override def makeMicroVM = new MicroVM(heapSize = 2L * 1024L * 1024L, stackSize = 63L * 1024L)

  "The memory manager" should "collect unreachable stacks." in {
Kunshan Wang's avatar
Kunshan Wang committed
46
    val ctx = microVM.newContext()
47
    
Kunshan Wang's avatar
Kunshan Wang committed
48
    val nStacks = ctx.handleFromInt64( 13)
49

Kunshan Wang's avatar
Kunshan Wang committed
50
51
52
    val func = ctx.handleFromFunc("@stackcollecttest")
    testFunc(ctx, func, Seq(nStacks)) { (ctx, th, st, wp) =>
      nameOf(ctx.curInst(st, 0)) match {
53
        case "@stackcollecttest_v1.endloop.trap" => {
54
          gc()
Kunshan Wang's avatar
Kunshan Wang committed
55
          returnFromTrap(st)
56
57
58
59
        }
      }
    }

Kunshan Wang's avatar
Kunshan Wang committed
60
    ctx.closeContext()
61
62
  }
}