Commit f0aed849 authored by Kunshan Wang's avatar Kunshan Wang

Test memory access.

parent d7234e90
......@@ -32,16 +32,6 @@ class ClientAgent(microVM: MicroVM) {
val mutator = microVM.memoryManager.heap.makeMutator()
/** Help the Client look up the ID of a name */
def idOf(name: String): Int = {
microVM.globalBundle.allNs(name).id
}
/** Help the Client look up the optional name of an ID */
def nameOf(id: Int): Option[String] = {
microVM.globalBundle.allNs(id).name
}
def close(): Unit = {
handles.clear()
mutator.close()
......@@ -250,7 +240,7 @@ class ClientAgent(microVM: MicroVM) {
}
def load(ord: MemoryOrder, loc: Handle): Handle = {
val ty = loc.ty
val ty = loc.ty.asInstanceOf[TypeIRef].ty
val uty = InternalTypePool.unmarkedOf(ty)
val b = loc.vb.asInstanceOf[BoxIRef]
val iRef = b.objRef + b.offset
......@@ -292,13 +282,26 @@ class ClientAgent(microVM: MicroVM) {
case _: TypeTagRef64 =>
val raw = MemorySupport.loadLong(iRef)
BoxTagRef64(raw)
case TypeVector(ety, len) =>
ety match {
case TypeInt(32) =>
val vs = for (i <- (0L until len)) yield MemorySupport.loadInt(iRef + i * 4L)
BoxVector(vs.map(v => BoxInt(OpHelper.unprepare(v, 32))))
case _: TypeFloat =>
val vs = for (i <- (0L until len)) yield MemorySupport.loadFloat(iRef + i * 4L)
BoxVector(vs.map(v => BoxFloat(v)))
case _: TypeDouble =>
val vs = for (i <- (0L until len)) yield MemorySupport.loadDouble(iRef + i * 8L)
BoxVector(vs.map(v => BoxDouble(v)))
case _ => throw new UvmRefImplException("Loading of vector type with element type %s is not supporing".format(ety.getClass.getName))
}
case _ => throw new UvmRefImplException("Loading of type %s is not supporing".format(uty.getClass.getName))
}
newHandle(uty, nb)
}
def store(ord: MemoryOrder, loc: Handle, newVal: Handle): Unit = {
val ty = loc.ty
val ty = loc.ty.asInstanceOf[TypeIRef].ty
val uty = InternalTypePool.unmarkedOf(ty)
val lb = loc.vb.asInstanceOf[BoxIRef]
val iRef = lb.objRef + lb.offset
......@@ -339,12 +342,23 @@ class ClientAgent(microVM: MicroVM) {
case _: TypeTagRef64 =>
val raw = nvb.asInstanceOf[BoxTagRef64].raw
MemorySupport.storeLong(iRef, raw)
case TypeVector(ety, len) =>
val vbs = nvb.asInstanceOf[BoxVector].values
ety match {
case TypeInt(32) =>
for (i <- (0L until len)) MemorySupport.storeInt(iRef + i * 4L, vbs(i.toInt).asInstanceOf[BoxInt].value.intValue)
case _: TypeFloat =>
for (i <- (0L until len)) MemorySupport.storeFloat(iRef + i * 4L, vbs(i.toInt).asInstanceOf[BoxFloat].value)
case _: TypeDouble =>
for (i <- (0L until len)) MemorySupport.storeDouble(iRef + i * 8L, vbs(i.toInt).asInstanceOf[BoxDouble].value)
case _ => throw new UvmRefImplException("Storing of vector type with element type %s is not supporing".format(ety.getClass.getName))
}
case _ => throw new UvmRefImplException("Storing of type %s is not supporing".format(uty.getClass.getName))
}
}
def cmpXchg(ordSucc: MemoryOrder, ordFail: MemoryOrder, weak: Boolean, loc: Handle, expected: Handle, desired: Handle): (Boolean, Handle) = {
val ty = loc.ty
val ty = loc.ty.asInstanceOf[TypeIRef].ty
val uty = InternalTypePool.unmarkedOf(ty)
val lb = loc.vb.asInstanceOf[BoxIRef]
val iRef = lb.objRef + lb.offset
......@@ -406,7 +420,7 @@ class ClientAgent(microVM: MicroVM) {
}
def atomicRMW(ord: MemoryOrder, op: AtomicRMWOptr, loc: Handle, opnd: Handle): Handle = {
val ty = loc.ty
val ty = loc.ty.asInstanceOf[TypeIRef].ty
val uty = InternalTypePool.unmarkedOf(ty)
val lb = loc.vb.asInstanceOf[BoxIRef]
val iRef = lb.objRef + lb.offset
......
......@@ -18,12 +18,20 @@ class ThreadStackManager(microVM: MicroVM) {
private var nextStackID: Int = 1
private def makeStackID(): Int = {val id = nextStackID; nextStackID += 1; id}
private def makeStackID(): Int = { val id = nextStackID; nextStackID += 1; id }
private var nextThreadID: Int = 1
private def makeThreadID(): Int = {val id = nextThreadID; nextThreadID += 1; id}
private def makeThreadID(): Int = { val id = nextThreadID; nextThreadID += 1; id }
/**
* Create a new stack with function and args as the stack-bottom function and its arguments.
* <p>
* About mutator: "Bring your own mutator!" A mutator object is needed to allocate the stack memory. This means all
* callers of the newStack function must have a mutator. Currently they are either ClientAgents which can create stack
* via the "new_stack" message or µVM threads (the InterpreterThread class) which can execute the NEWSTACK
* instruction.
*/
def newStack(function: Function, args: Seq[ValueBox], mutator: Mutator): InterpreterStack = {
val stackMemory = microVM.memoryManager.makeStackMemory(mutator)
val id = makeStackID()
......
......@@ -121,7 +121,7 @@ object TypeSizes {
}
def structPrefixSizeOf(ty: TypeStruct, prefixLen: Int): Word = {
val sz = ty.fieldTy.foldLeft(0L) { (oldSz, nextTy) =>
val sz = ty.fieldTy.take(prefixLen).foldLeft(0L) { (oldSz, nextTy) =>
alignUp(oldSz, alignOf(nextTy)) + sizeOf(nextTy)
}
return sz
......
......@@ -11,6 +11,9 @@
.typedef @irv = iref<@void>
.typedef @wrv = weakref<@void>
.const @NULLRV <@rv> = NULL
.const @NULLIRV <@irv> = NULL
.typedef @ri16 = ref<@i16>
.typedef @s1 = struct<@i8 @i16 @i32 @i64 @float @double @rv @irv @wrv @ri16>
......@@ -42,6 +45,15 @@
.typedef @st = stack
.typedef @tr64 = tagref64
.typedef @i6 = int<6>
.typedef @i52 = int<52>
.typedef @s2 = struct<@f0 @th @st @tr64>
.typedef @4xfloat = vector <@float 4>
.typedef @4xi32 = vector <@i32 4>
.typedef @2xdouble = vector <@double 2>
\ No newline at end of file
.typedef @2xdouble = vector <@double 2>
.funcdecl @fun <@sig0>
.funcdecl @fun2 <@sig0>
.const @NULLF0 <@f0> = NULL
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment