MemoryManager.scala 971 Bytes
Newer Older
1 2
package uvm.refimpl.mem

3 4 5
import uvm.refimpl._
import TypeSizes._
import uvm.refimpl.mem.simpleimmix._
6

7 8 9 10
class MemoryManager(val heapSize: Word, val globalSize: Word, val stackSize: Word)(implicit microVM: MicroVM) {
  
  val totalMemorySize = heapSize + globalSize
  
11 12
  // Allocate slightly more memory to meet the SimpleImmixSpace's alignment requirement.
  implicit val memorySupport = new MemorySupport(totalMemorySize + SimpleImmixSpace.BLOCK_SIZE) 
13 14 15 16 17 18
  
  val memoryBegin = memorySupport.muMemoryBegin
  val heapBegin = TypeSizes.alignUp(memoryBegin, SimpleImmixSpace.BLOCK_SIZE)
  
  val heap = new SimpleImmixHeap(heapBegin, heapSize)
  val globalMemory = new GlobalMemory(heapBegin + heapSize, globalSize)
19

20
  def makeMutator(): Mutator = heap.makeMutator()
21

Kunshan Wang's avatar
Kunshan Wang committed
22 23
  def makeStackMemory(mutator: Mutator): StackMemory = {
    val objRef = mutator.newHybrid(InternalTypes.BYTE_ARRAY, stackSize)
24
    val stackMemory = new StackMemory(objRef, stackSize)
25 26
    stackMemory
  }
27
}