WARNING! Access to this system is limited to authorised users only.
Unauthorised users may be subject to prosecution.
Unauthorised access to this system is a criminal offence under Australian law (Federal Crimes Act 1914 Part VIA)
It is a criminal offence to:
(1) Obtain access to data without authority. -Penalty 2 years imprisonment.
(2) Damage, delete, alter or insert data without authority. -Penalty 10 years imprisonment.
User activity is monitored and recorded. Anyone using this system expressly consents to such monitoring and recording.

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

Commit 58b25069 authored by Kunshan Wang's avatar Kunshan Wang
Browse files

GC tests (partial)

parent e8e8cf3b
package uvm.refimpl.itpr
import org.scalatest._
import java.io.FileReader
import uvm._
import uvm.types._
import uvm.ssavariables._
import uvm.refimpl._
import uvm.refimpl.itpr._
import MemoryOrder._
import AtomicRMWOptr._
import uvm.refimpl.mem.TypeSizes.Word
import ch.qos.logback.classic.Level._
import uvm.refimpl.UvmBundleTesterBase
class UvmInterpreterGCTests extends UvmBundleTesterBase {
setLogLevels(
ROOT_LOGGER_NAME -> INFO,
"uvm.refimpl.itpr" -> DEBUG,
"uvm.refimpl.mem" -> DEBUG)
preloadBundles("tests/uvm-refimpl-test/gc-tests.uir")
def gc() = microVM.memoryManager.heap.mutatorTriggerAndWaitForGCEnd(false)
"The memory manager" should "retain global reference between gc." in {
val ca = microVM.newClientAgent()
val func = ca.putFunction("@keepglobal")
testFunc(ca, func, Seq()) { (ca, th, st, wp) =>
gc()
TrapRebindPassVoid(st)
}
ca.close()
}
}
\ No newline at end of file
......@@ -18,6 +18,45 @@
.const @TRUE <@i64> = 1
.const @FALSE <@i64> = 0
.const @I32_0 <@i32> = 0
.const @I32_1 <@i32> = 1
.const @I32_2 <@i32> = 2
.const @I32_3 <@i32> = 3
.const @I32_4 <@i32> = 4
.const @I32_5 <@i32> = 5
.const @I32_6 <@i32> = 6
.const @I32_7 <@i32> = 7
.const @I64_0 <@i64> = 0
.const @I64_1 <@i64> = 1
.const @I64_2 <@i64> = 2
.const @I64_3 <@i64> = 3
.const @I64_4 <@i64> = 4
.const @I64_5 <@i64> = 5
.const @I64_6 <@i64> = 6
.const @I64_7 <@i64> = 7
.const @I64_42 <@i64> = 42
.const @I64_1024 <@i64> = 1024
.const @I64_30000 <@i64> = 30000
.const @F_0 <@float> = 0.0f
.const @F_1 <@float> = 1.0f
.const @F_2 <@float> = 2.0f
.const @F_3 <@float> = 3.0f
.const @F_4 <@float> = 4.0f
.const @F_5 <@float> = 5.0f
.const @F_6 <@float> = 6.0f
.const @F_7 <@float> = 7.0f
.const @D_0 <@double> = 0.0d
.const @D_1 <@double> = 1.0d
.const @D_2 <@double> = 2.0d
.const @D_3 <@double> = 3.0d
.const @D_4 <@double> = 4.0d
.const @D_5 <@double> = 5.0d
.const @D_6 <@double> = 6.0d
.const @D_7 <@double> = 7.0d
.funcsig @i_ii = @i64 (@i64 @i64)
.typedef @refvoid = ref<@void>
......@@ -27,7 +66,7 @@
.typedef @StructFoo = struct <@i32 @i64 @float @double>
.const @STRUCT_FOO <@StructFoo> = {1 2 3.0f 4.0d}
.const @STRUCT_FOO <@StructFoo> = {@I32_1 @I64_2 @F_3 @D_4}
.typedef @refi64 = ref<@i64>
.typedef @irefi64 = iref<@i64>
......@@ -44,12 +83,9 @@
.typedef @hCharArray = hybrid<@i64 @i8>
.typedef @ArrayBaz = array <@i16 1024>
.const @THREE <@i64> = 3
.typedef @JavaLikeByteArray = hybrid <@i32 @i8>
.const @I64_1024 <@i64> = 1024
.global @g_i8 <@i8>
.global @g_i16 <@i16>
.global @g_i32 <@i32>
......@@ -66,86 +102,82 @@
.global @g_sta <@stack>
.global @g_tr64 <@tagref64>
.const @I64_30000 <@i64> = 30000
.const @CRAZY_ALLOC_COUNT <@i64> = 100
.const @RI64_NULL <@refi64> = NULL
.global @g_refi64 <@refi64>
.funcdef @keepglobal <@noparamsnoret> () {
.funcdef @keepglobal VERSION @keepglobal_v1 <@noparamsnoret> () {
%entry:
CALL <@noparamsnoret> @storeglobal ()
%gctrap = TRAP <@void> %next %next KEEPALIVE ()
%next:
%gctrap = TRAP <@void>
%obj2 = LOAD <@refi64> @g_refi64
%obj2iref = GETIREF <@i64> %obj2
%obj2val = LOAD <@i64> %obj2iref
%checktrap = TRAP <@void> %exit %exit KEEPALIVE (%obj2 %obj2val)
%checktrap = TRAP <@void> KEEPALIVE (%obj2 %obj2val)
%exit:
STORE <@refi64> @g_refi64 NULL
ICALL @uvm.thread_exit()
THROW @NULLREF
STORE <@refi64> @g_refi64 @RI64_NULL
COMMINST @uvm.thread_exit
}
.funcdef @storeglobal <@noparamsnoret> () {
.funcdef @storeglobal VERSION @storeglobal_v1 <@noparamsnoret> () {
%entry:
%obj = NEW <@i64>
STORE <@refi64> @g_refi64 %obj
%iref = GETIREF <@i64> %obj
STORE <@i64> %iref 42
STORE <@i64> %iref @I64_42
RETVOID
}
.funcdef @nokeepalloca <@noparamsnoret> () {
.funcdef @nokeepalloca VERSION @nokeepalloca_v1 <@noparamsnoret> () {
%entry:
CALL <@noparamsnoret> @allocatest ()
%gctrap = TRAP <@void> %next %next KEEPALIVE ()
%next:
ICALL @uvm.thread_exit()
THROW @NULLREF
%gctrap = TRAP <@void>
COMMINST @uvm.thread_exit
}
.funcdef @allocatest <@noparamsnoret> () {
.funcdef @allocatest VERSION @allocatest_v1 <@noparamsnoret> () {
%entry:
%alloca = ALLOCA <@refi64>
CALL <@allocasettersig> @allocasetter (%alloca)
%gctrap = TRAP <@void> %next %next KEEPALIVE ()
%next:
%gctrap = TRAP <@void>
RETVOID
}
.funcsig @allocasettersig = @void (@irefi64)
.funcdef @allocasetter <@allocasettersig> (%ir) {
.funcdef @allocasetter VERSION @allocasetter_v1 <@allocasettersig> (%ir) {
%entry:
%obj = NEW <@i64>
%iref = GETIREF <@i64> %obj
STORE <@i64> %iref 42
STORE <@i64> %iref @I64_42
STORE <@refi64> %ir %obj
RETVOID
}
.funcdef @crazy_allocator <@noparamsnoret> () {
%entry:
.funcdef @crazy_allocator VERSION @crazy_allocator_v1 <@noparamsnoret> () {
%entry:
BRANCH %head
%head:
%head:
%togo = PHI <@i64> { %entry: @CRAZY_ALLOC_COUNT; %body: %togo2; }
%nz = NE <@i64> %togo 0
%nz = NE <@i64> %togo @I64_0
BRANCH2 %nz %body %exit
%body:
NEWHYBRID <@hCharArray> @I64_30000
%togo2 = SUB <@i64> %togo 1
%body:
NEWHYBRID <@hCharArray @i64> @I64_30000
%togo2 = SUB <@i64> %togo @I64_1
BRANCH %head
%exit:
%exit:
RETVOID
}
......@@ -155,181 +187,175 @@
.const @REM_PER_ALLOC <@i64> = 100000
.const @NALLOCS <@i64> = 2000000
.funcdef @breadcrumbs <@noparamsnoret> () {
%entry:
%remember = NEWHYBRID <@refi64array> @REM_SZ
.funcdef @breadcrumbs VERSION @breadcrumbs_v1 <@noparamsnoret> () {
%entry:
%remember = NEWHYBRID <@refi64array @i64> @REM_SZ
%rememberiref = GETIREF <@refi64array> %remember
%remv = GETVARPARTIREF <@refi64array> %rememberiref
BRANCH %head
%head:
%i = PHI <@i64> { %entry: 0; %next: %i2; }
%nrem = PHI <@i64> { %entry: 0; %next: %nrem3; }
%head:
%i = PHI <@i64> { %entry: @I64_0; %next: %i2; }
%nrem = PHI <@i64> { %entry: @I64_0; %next: %nrem3; }
%enough = SLT <@i64> %i @NALLOCS
BRANCH2 %enough %body %exit
%body:
%body:
%obj = NEW <@i64>
%rem = SREM <@i64> %i @REM_PER_ALLOC
%z = EQ <@i64> %rem 0
%z = EQ <@i64> %rem @I64_0
BRANCH2 %z %body2 %next
%body2:
%loc = SHIFTIREF <@refi64> %remv %nrem
%body2:
%loc = SHIFTIREF <@refi64 @i64> %remv %nrem
STORE <@refi64> %loc %obj
%nrem2 = ADD <@i64> %nrem 1
%nrem2 = ADD <@i64> %nrem @I64_1
BRANCH %next
%next:
%next:
%nrem3 = PHI <@i64> { %body: %nrem; %body2: %nrem2; }
%i2 = ADD <@i64> %i 1
%i2 = ADD <@i64> %i @I64_1
BRANCH %head
%exit:
ICALL @uvm.thread_exit()
THROW @NULLREF
%exit:
COMMINST @uvm.thread_exit
}
.typedef @WRI64Cell = iref<@weakrefi64>
.funcsig @makestorewri64sig = @void (@WRI64Cell)
.funcdef @makestorewri64 <@makestorewri64sig> (%cell) {
.funcdef @makestorewri64 VERSION @makestorewri64_v1 <@makestorewri64sig> (%cell) {
%entry:
%ri64 = NEW <@i64>
%iri64 = GETIREF <@i64> %ri64
STORE <@i64> %iri64 42
STORE <@i64> %iri64 @I64_42
STORE <@weakrefi64> %cell %ri64
RETVOID
}
.funcdef @peekweakref <@makestorewri64sig> (%cell) {
.funcdef @peekweakref VERSION @peekweakref_v1 <@makestorewri64sig> (%cell) {
%entry:
%refval = LOAD <@weakrefi64> %cell
%checknztrap = TRAP <@void> %exit %exit KEEPALIVE (%refval)
%exit:
%checknztrap = TRAP <@void> KEEPALIVE (%refval)
RETVOID
}
.funcdef @testweakref <@noparamsnoret> () {
.funcdef @testweakref VERSION @testweakref_v1 <@noparamsnoret> () {
%entry:
%irwr = ALLOCA <@weakrefi64>
CALL <@makestorewri64sig> @makestorewri64 (%irwr)
CALL <@makestorewri64sig> @peekweakref (%irwr)
%gctrap = TRAP <@void> %next %next KEEPALIVE ()
%gctrap = TRAP <@void>
%next:
%refval = LOAD <@weakrefi64> %irwr
%checkztrap = TRAP <@void> %exit %exit KEEPALIVE (%refval)
%checkztrap = TRAP <@void> KEEPALIVE (%refval)
%exit:
ICALL @uvm.thread_exit ()
THROW @NULLREF
COMMINST @uvm.thread_exit
}
.typedef @i6 = int<6>
.const @I6_13 <@i6> = 13
.funcdef @maketr64intref <@tagref64 ()> () {
.funcsig @maketr64intref_sig = @tagref64 ()
.funcdef @maketr64intref VERSION @maketr64intref_v1 <@maketr64intref_sig> () {
%entry:
%refi64 = NEW <@i64>
%irefi64 = GETIREF <@i64> %refi64
STORE <@i64> %irefi64 42
STORE <@i64> %irefi64 @I64_42
%refv = REFCAST <@refi64 @refvoid> %refi64
%tr = ICALL @uvm.tr64.from_ref (%refv @I6_13)
%tr = COMMINST @uvm.tr64.from_ref (%refv @I6_13)
RET <@tagref64> %tr
}
.funcdef @testtagrefgc <@noparamsnoret> () {
%tr = CALL <@tagref64 ()> @maketr64intref ()
%gctrap = TRAP <@void> %next %next KEEPALIVE ()
.funcdef @testtagrefgc VERSION @testtagrefgc_v1 <@noparamsnoret> () {
%entry:
%tr = CALL <@maketr64intref_sig> @maketr64intref ()
%gctrap = TRAP <@void>
%next:
%refv = ICALL @uvm.tr64.to_ref(%tr)
%tagv = ICALL @uvm.tr64.to_tag(%tr)
%next:
%refv = COMMINST @uvm.tr64.to_ref(%tr)
%tagv = COMMINST @uvm.tr64.to_tag(%tr)
%refi = REFCAST <@refvoid @refi64> %refv
%irefi = GETIREF <@i64> %refi
%iv = LOAD <@i64> %irefi
%checktrap = TRAP <@void> %exit %exit KEEPALIVE (%tr %refv %tagv %iv)
%checktrap = TRAP <@void> KEEPALIVE (%tr %refv %tagv %iv)
%exit:
ICALL @uvm.thread_exit ()
THROW @NULLREF
COMMINST @uvm.thread_exit
}
.typedef @ireftr64 = iref<@tagref64>
.funcdef @settr64intref <@void (@ireftr64)> (%ireftr64) {
.funcsig @settr64intref_sig = @void (@ireftr64)
.funcdef @settr64intref VERSION @settr64intref_v1 <@settr64intref_sig> (%ireftr64) {
%entry:
%refi64 = NEW <@i64>
%irefi64 = GETIREF <@i64> %refi64
STORE <@i64> %irefi64 42
STORE <@i64> %irefi64 @I64_42
%refv = REFCAST <@refi64 @refvoid> %refi64
%tr = ICALL @uvm.tr64.from_ref (%refv @I6_13)
%tr = COMMINST @uvm.tr64.from_ref (%refv @I6_13)
STORE <@tagref64> %ireftr64 %tr
RETVOID
}
.funcdef @testtagrefgcmem <@noparamsnoret> () {
.funcdef @testtagrefgcmem VERSION @testtagrefgcmem_v1 <@noparamsnoret> () {
%entry:
%ireftr64 = ALLOCA <@tagref64>
CALL <@void (@ireftr64)> @settr64intref (%ireftr64)
%gctrap = TRAP <@void> %next %next KEEPALIVE ()
CALL <@settr64intref_sig> @settr64intref (%ireftr64)
%gctrap = TRAP <@void>
%next:
%tr = LOAD <@tagref64> %ireftr64
%refv = ICALL @uvm.tr64.to_ref(%tr)
%tagv = ICALL @uvm.tr64.to_tag(%tr)
%refv = COMMINST @uvm.tr64.to_ref(%tr)
%tagv = COMMINST @uvm.tr64.to_tag(%tr)
%refi = REFCAST <@refvoid @refi64> %refv
%irefi = GETIREF <@i64> %refi
%iv = LOAD <@i64> %irefi
%checktrap = TRAP <@void> %exit %exit KEEPALIVE (%tr %refv %tagv %iv)
%checktrap = TRAP <@void> KEEPALIVE (%tr %refv %tagv %iv)
%exit:
ICALL @uvm.thread_exit ()
THROW @NULLREF
COMMINST @uvm.thread_exit
}
.typedef @tr64array = hybrid <@void @tagref64>
.const @REM_SZ <@i64> = 2000
.const @REM_PER_ALLOC <@i64> = 100000
.const @NALLOCS <@i64> = 2000000
.funcdef @breadcrumbstr64 <@noparamsnoret> () {
%entry:
%remember = NEWHYBRID <@tr64array> @REM_SZ
.funcdef @breadcrumbstr64 VERSION @breadcrumbstr64_v1 <@noparamsnoret> () {
%entry:
%remember = NEWHYBRID <@tr64array @i64> @REM_SZ
%rememberiref = GETIREF <@tr64array> %remember
%remv = GETVARPARTIREF <@tr64array> %rememberiref
BRANCH %head
%head:
%i = PHI <@i64> { %entry: 0; %next: %i2; }
%nrem = PHI <@i64> { %entry: 0; %next: %nrem3; }
%head:
%i = PHI <@i64> { %entry: @I64_0; %next: %i2; }
%nrem = PHI <@i64> { %entry: @I64_0; %next: %nrem3; }
%enough = SLT <@i64> %i @NALLOCS
BRANCH2 %enough %body %exit
%body:
%body:
%obj = NEW <@i64>
%rem = SREM <@i64> %i @REM_PER_ALLOC
%z = EQ <@i64> %rem 0
%z = EQ <@i64> %rem @I64_0
BRANCH2 %z %body2 %next
%body2:
%loc = SHIFTIREF <@tagref64> %remv %nrem
%body2:
%loc = SHIFTIREF <@tagref64 @i64> %remv %nrem
%objv = REFCAST <@refi64 @refvoid> %obj
%tr = ICALL @uvm.tr64.from_ref(%objv @I6_13)
%tr = COMMINST @uvm.tr64.from_ref(%objv @I6_13)
STORE <@tagref64> %loc %tr
%nrem2 = ADD <@i64> %nrem 1
%nrem2 = ADD <@i64> %nrem @I64_1
BRANCH %next
%next:
%next:
%nrem3 = PHI <@i64> { %body: %nrem; %body2: %nrem2; }
%i2 = ADD <@i64> %i 1
%i2 = ADD <@i64> %i @I64_1
BRANCH %head
%exit:
ICALL @uvm.thread_exit()
THROW @NULLREF
%exit:
COMMINST @uvm.thread_exit()
}
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