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

Heap.scala 1.78 KB
Newer Older
Kunshan Wang's avatar
Kunshan Wang committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package uvm.refimpl.mem

import java.util.concurrent.locks._
import Heap._
import uvm.refimpl.UvmRefImplException

object Heap {
  protected val MUTATOR_RUNNING = 0
  protected val DOING_GC = 1
}

abstract class Heap {
  protected val lock: Lock = new ReentrantLock()

  protected val gcCanStart: Condition = lock.newCondition()

  protected val gcFinished: Condition = lock.newCondition()

  protected var gcState: Int = _

  protected var mustFreeSpace: Boolean = _

  def mutatorTriggerAndWaitForGCEnd(mustFreeSpace: Boolean) {
    lock.lock()
    try {
      triggerGC(mustFreeSpace)
      mutatorWaitForGCEnd()
    } finally {
      lock.unlock()
    }
  }

  private def triggerGC(mustFreeSpace: Boolean) {
    lock.lock()
    try {
      assert((gcState == MUTATOR_RUNNING))
      gcState = DOING_GC
      this.mustFreeSpace = mustFreeSpace
      gcCanStart.signalAll()
    } finally {
      lock.unlock()
    }
  }

  private def mutatorWaitForGCEnd() {
    lock.lock()
    try {
      while (gcState != MUTATOR_RUNNING) {
        try {
          gcFinished.await()
        } catch {
          case e: InterruptedException => throw new UvmRefImplException("Interrupted while waiting for GC. Stop.")
        }
      }
    } finally {
      lock.unlock()
    }
  }

  def untriggerGC() {
    lock.lock()
    try {
      assert((gcState == DOING_GC))
      gcState = MUTATOR_RUNNING
      gcFinished.signalAll()
    } finally {
      lock.unlock()
    }
  }

  def collectorWaitForGCStart() {
    lock.lock()
    while (gcState != DOING_GC) {
      try {
        gcCanStart.await()
      } catch {
        case e: InterruptedException => throw new UvmRefImplException("GC thread is interrupted.")
      }
    }
    lock.unlock()
  }

  def makeMutator(): Mutator

  def getMustFreeSpace(): Boolean = mustFreeSpace
}