GitLab will be upgraded on 30 Jan 2023 from 2.00 pm (AEDT) to 3.00 pm (AEDT). During the update, GitLab and Mattermost services will not be available. If you have any concerns with this, please talk to us at N110 (b) CSIT building.

HeaderUtils.scala 1.24 KB
Newer Older
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
package uvm.refimpl.mem

import uvm.types.Type
import uvm.refimpl.MicroVM
import uvm.refimpl.mem.TypeSizes.Word
import com.typesafe.scalalogging._
import org.slf4j.LoggerFactory

object HeaderUtils extends StrictLogging {

  def postAllocScalar(addr: Word, tag: Long) {
    setTag(addr, tag)
  }

  def postAllocHybrid(addr: Word, tag: Long, len: Long) {
    postAllocScalar(addr, tag)
    setVarLength(addr, len)
  }

  def getTag(objRef: Word): Long = {
    MemorySupport.loadLong(objRef + TypeSizes.GC_HEADER_OFFSET_TAG)
  }

  def getVarLength(objRef: Word): Long = {
    MemorySupport.loadLong(objRef + TypeSizes.GC_HEADER_OFFSET_HYBRID_LENGTH)
  }

  def setTag(objRef: Word, tag: Long) {
    logger.debug(s"Storing tag ${tag} at addr ${TypeSizes.GC_HEADER_OFFSET_TAG}")
    MemorySupport.storeLong(objRef + TypeSizes.GC_HEADER_OFFSET_TAG, tag)
  }

  def setVarLength(objRef: Word, len: Long) {
    MemorySupport.storeLong(objRef + TypeSizes.GC_HEADER_OFFSET_HYBRID_LENGTH, len)
  }

  def getTypeID(tag: Long): Int = (tag & 0x00000000ffffffffL).toInt

  def getType(microVM: MicroVM, tag: Long): Type = {
    val typeID = getTypeID(tag)
    microVM.globalBundle.typeNs(typeID)
  }

  def getForwardedDest(oldHeader: Long): Long = oldHeader & 0x0000ffffffffffffL
}