To protect your data, the CISO officer has suggested users to enable 2FA as soon as possible.
Currently 2.8% of users enabled 2FA.

fieldHandling.scala 5.54 KB
Newer Older
1
2
package uvm.refimpl.mem.scanning

3
import org.slf4j.LoggerFactory
Kunshan Wang's avatar
Kunshan Wang committed
4

5
import com.typesafe.scalalogging.Logger
Kunshan Wang's avatar
Kunshan Wang committed
6

7
import uvm.Function
Kunshan Wang's avatar
Kunshan Wang committed
8
import uvm.ir.irbuilder.IRBuilder
9
import uvm.refimpl.Word
Kunshan Wang's avatar
Kunshan Wang committed
10
import uvm.refimpl.itpr.BoxStack
11
import uvm.refimpl.itpr.FrameCursor
Kunshan Wang's avatar
Kunshan Wang committed
12
13
14
15
16
import uvm.refimpl.itpr.HasObjRef
import uvm.refimpl.itpr.InterpreterStack
import uvm.refimpl.itpr.InterpreterThread
import uvm.refimpl.itpr.OpHelper
import uvm.refimpl.mem.MemorySupport
17
18
19
20
21
22
23
24

/**
 * Handle general reference fields in the memory. This trait is mostly useful for the boot image builder.
 * <p>
 * As a convention, the parameter name "objRef" means the "beginning of an allocation unit", not limited to heap
 * object; "iRef" is the address of the field itself.
 */
trait MemoryFieldHandler {
25
  def visitUPtrField(objRef: Word, iRef: Word, toAddr: Word): Unit
Kunshan Wang's avatar
Kunshan Wang committed
26
  def visitUFPField(objRef: Word, iRef: Word, toAddr: Word): Unit
27

28
29
30
31
32
33
34
35
36
37
  def visitRefField(objRef: Word, iRef: Word, toObj: Word, isWeak: Boolean): Unit
  def visitIRefField(objRef: Word, iRef: Word, toObj: Word, toOffset: Word): Unit

  /** This function is called only when the tagref is holding a reference. */
  def visitTagRefField(objRef: Word, iRef: Word, toObj: Word): Unit

  def visitFuncRefField(objRef: Word, iRef: Word, toFunc: Option[Function]): Unit
  def visitStackRefField(objRef: Word, iRef: Word, toStack: Option[InterpreterStack]): Unit
  def visitThreadRefField(objRef: Word, iRef: Word, toThread: Option[InterpreterThread]): Unit
  def visitFCRefField(objRef: Word, iRef: Word, toFCRef: Option[FrameCursor]): Unit
Kunshan Wang's avatar
Kunshan Wang committed
38
  def visitIRBuilderRefField(objRef: Word, iRef: Word, toIRNode: Option[IRBuilder]): Unit
39
}
40

Kunshan Wang's avatar
Kunshan Wang committed
41
/**
Kunshan Wang's avatar
Kunshan Wang committed
42
43
44
45
46
 * Handle references in the memory, value boxes or other Micro VM structures such as threads and stacks.
 * <ul>
 * <li>The caller invokes the methods on all boxes/locations it finds, no matter whether it is NULL or not.</li>
 * <li>The callee checks if the box/location actually contain non-null references.</li>
 * </ul>
Kunshan Wang's avatar
Kunshan Wang committed
47
 * <p>
Kunshan Wang's avatar
Kunshan Wang committed
48
49
 * The return value of the methods will be queued for recursive traversing. They should be the old value,
 * the updated value by the copying GC, or None if the reference should not be followed.
Kunshan Wang's avatar
Kunshan Wang committed
50
 */
51
trait RefFieldHandler extends MemoryFieldHandler {
Kunshan Wang's avatar
Kunshan Wang committed
52
53
54
55
56
57
58
59
60
61
62
63
  /** A stack value box referring to a heap object. */
  def boxToHeap(box: HasObjRef): Option[Word]
  /** A stack value box referring to a "stack"-typed value. */
  def boxToStack(box: BoxStack): Option[InterpreterStack]
  /** A memory location referring to a heap object. */
  def memToHeap(objRef: Word, iRef: Word, toObj: Word, isWeak: Boolean, isTR64: Boolean): Option[Word]
  /** A memory location referring to a heap object.  Return the new stack ID or 0. */
  def memToStack(objRef: Word, iRef: Word, toStack: Option[InterpreterStack]): Option[InterpreterStack]
  /** An InterpreterStack object referring to its stackMemory field. Stack memory cannot move. */
  def stackToStackMem(stack: InterpreterStack, toObj: Word): Option[Word]
  /** An InterpreterThread referring to its stack. GC cannot rebind stacks. */
  def threadToStack(thread: InterpreterThread, toStack: Option[InterpreterStack]): Option[InterpreterStack]
Kunshan Wang's avatar
Kunshan Wang committed
64
65
  /** Pin set referring to the memory. Pinned objects cannot be moved. */
  def pinSetToMem(toObj: Word): Option[Word]
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83

  def visitRefField(objRef: Word, iRef: Word, toObj: Word, isWeak: Boolean): Unit = {
    memToHeap(objRef, iRef, toObj, isWeak, false)
  }

  def visitIRefField(objRef: Word, iRef: Word, toObj: Word, toOffset: Word): Unit = {
    memToHeap(objRef, iRef, toObj, false, false)
  }

  /** This function is called only when the tagref is holding a reference. */
  def visitTagRefField(objRef: Word, iRef: Word, toObj: Word): Unit = {
    memToHeap(objRef, iRef, toObj, false, true)
  }

  def visitStackRefField(objRef: Word, iRef: Word, toStack: Option[InterpreterStack]): Unit = {
    memToStack(objRef, iRef, toStack)
  }

84
  def visitUPtrField(objRef: Word, iRef: Word, toAddr: Word): Unit = {}
Kunshan Wang's avatar
Kunshan Wang committed
85
  def visitUFPField(objRef: Word, iRef: Word, toAddr: Word): Unit = {}
86
87
88
  def visitFuncRefField(objRef: Word, iRef: Word, toFunc: Option[Function]): Unit = {}
  def visitThreadRefField(objRef: Word, iRef: Word, toThread: Option[InterpreterThread]): Unit = {}
  def visitFCRefField(objRef: Word, iRef: Word, toFCRef: Option[FrameCursor]): Unit = {}
Kunshan Wang's avatar
Kunshan Wang committed
89
  def visitIRBuilderRefField(objRef: Word, iRef: Word, toIRNode: Option[IRBuilder]): Unit = {}
90
91
92
}

object RefFieldUpdater {
93
94
  val logger = Logger(LoggerFactory.getLogger(getClass.getName))

Kunshan Wang's avatar
Kunshan Wang committed
95
  def updateBoxToHeap(box: HasObjRef, newObjRef: Word): Unit = box.setObjRef(newObjRef)
Kunshan Wang's avatar
Kunshan Wang committed
96
  def updateBoxToStack(box: BoxStack, newStack: Option[InterpreterStack]) = box.obj = newStack
97
  def updateMemToHeap(iRef: Word, isTR64: Boolean, newObjRef: Word)(implicit memorySupport: MemorySupport): Unit = {
98
    if (isTR64) {
99
      val oldRaw = memorySupport.loadLong(iRef)
100
101
      val oldTag = OpHelper.tr64ToTag(oldRaw)
      val newRaw = OpHelper.refToTr64(newObjRef, oldTag)
102
103
104
105
106
      logger.debug {
        val oldObjRef = OpHelper.tr64ToRef(oldRaw)
        "Updating tagref field [0x%x] = 0x%x -> 0x%x; ref: 0x%x -> 0x%x".format(
          iRef, oldRaw, newRaw, oldObjRef, newObjRef)
      }
107
      memorySupport.storeLong(iRef, newRaw)
108
    } else {
109
110
111
112
      logger.debug {
        val oldObjRef = memorySupport.loadLong(iRef)
        "Updating ref field [0x%x] = 0x%x -> 0x%x".format(iRef, oldObjRef, newObjRef)
      }
113
      memorySupport.storeLong(iRef, newObjRef)
114
115
    }
  }
116
117
  def updateMemToStack(iRef: Word, newStack: Option[InterpreterStack])(implicit memorySupport: MemorySupport): Unit = {
    memorySupport.storeLong(iRef, newStack.map(_.id).getOrElse(0).toLong)
Kunshan Wang's avatar
Kunshan Wang committed
118
  }
119
}