Make NoOp GC support multiple mutators
This commit is contained in:
committed by
Space
parent
792ac6ab63
commit
73533e4b19
@@ -1092,8 +1092,11 @@ standaloneTest("leakMemoryWithWorkerTermination") {
|
||||
disabled = (project.testTarget == 'wasm32') || // Needs pthreads.
|
||||
isExperimentalMM // Experimental MM doesn't support multiple mutators yet.
|
||||
source = "runtime/workers/leak_memory_with_worker_termination.kt"
|
||||
expectedExitStatusChecker = { it != 0 }
|
||||
outputChecker = { s -> s.contains("Memory leaks detected, 1 objects leaked!") }
|
||||
|
||||
if (!isExperimentalMM) { // Experimental MM will not report memory leaks.
|
||||
expectedExitStatusChecker = { it != 0 }
|
||||
outputChecker = { s -> s.contains("Memory leaks detected, 1 objects leaked!") }
|
||||
}
|
||||
}
|
||||
|
||||
task superFunCall(type: KonanLocalTest) {
|
||||
@@ -4494,9 +4497,15 @@ standaloneTest("interop_objc_illegal_sharing") {
|
||||
isExperimentalMM // Experimental MM doesn't support multiple mutators and thread state switching for ObjC interop yet.
|
||||
source = "interop/objc/illegal_sharing.kt"
|
||||
UtilsKt.dependsOnPlatformLibs(it)
|
||||
expectedExitStatusChecker = { it != 0 }
|
||||
outputChecker = {
|
||||
it.startsWith("Before") && !it.contains("After")
|
||||
if (isExperimentalMM) {
|
||||
outputChecker = {
|
||||
it.startsWith("Before") && it.contains("After")
|
||||
}
|
||||
} else {
|
||||
expectedExitStatusChecker = { it != 0 }
|
||||
outputChecker = {
|
||||
it.startsWith("Before") && !it.contains("After")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4614,6 +4623,9 @@ dynamicTest("interop_migrating_main_thread") {
|
||||
isExperimentalMM // Experimental MM doesn't support multiple mutators yet.
|
||||
source = "interop/migrating_main_thread/lib.kt"
|
||||
flags = ['-Xdestroy-runtime-mode=on-shutdown']
|
||||
if (isExperimentalMM) {
|
||||
clangFlags = ['-DEXPERIMENTAL_MM']
|
||||
}
|
||||
cSource = "$projectDir/interop/migrating_main_thread/main.cpp"
|
||||
clangTool = "clang++"
|
||||
}
|
||||
|
||||
@@ -24,6 +24,9 @@ int main() {
|
||||
#if defined(IS_LEGACY)
|
||||
// Globals were reinitialized.
|
||||
assert(testlib_symbols()->kotlin.root.tryReadFromA(kErrorValue) == kInitialValue);
|
||||
#elif defined(EXPERIMENTAL_MM)
|
||||
// Globals are preserved.
|
||||
assert(testlib_symbols()->kotlin.root.tryReadFromA(kErrorValue) == kNewValue);
|
||||
#else
|
||||
// Globals are not accessible.
|
||||
assert(testlib_symbols()->kotlin.root.tryReadFromA(kErrorValue) == kErrorValue);
|
||||
|
||||
@@ -10,17 +10,24 @@ import kotlin.test.*
|
||||
import kotlin.native.concurrent.*
|
||||
import kotlinx.cinterop.*
|
||||
|
||||
class Holder(val value: Int)
|
||||
|
||||
@Test
|
||||
fun runTest1() {
|
||||
val worker = Worker.start()
|
||||
|
||||
val future = worker.execute(TransferMode.SAFE, { }) {
|
||||
StableRef.create(Any())
|
||||
StableRef.create(Holder(42))
|
||||
}
|
||||
val ref = future.result
|
||||
assertFailsWith<IncorrectDereferenceException> {
|
||||
if (kotlin.native.Platform.memoryModel == kotlin.native.MemoryModel.EXPERIMENTAL) {
|
||||
val value = ref.get()
|
||||
println(value.toString())
|
||||
assertEquals(value.value, 42)
|
||||
} else {
|
||||
assertFailsWith<IncorrectDereferenceException> {
|
||||
val value = ref.get()
|
||||
println(value.value)
|
||||
}
|
||||
}
|
||||
|
||||
worker.requestTermination().result
|
||||
@@ -30,15 +37,20 @@ fun runTest1() {
|
||||
fun runTest2() {
|
||||
val worker = Worker.start()
|
||||
|
||||
val mainThreadRef = StableRef.create(Any())
|
||||
val mainThreadRef = StableRef.create(Holder(42))
|
||||
// Simulate this going through interop as raw C pointer.
|
||||
val pointerValue: Long = mainThreadRef.asCPointer().toLong()
|
||||
val future = worker.execute(TransferMode.SAFE, { pointerValue }) {
|
||||
val pointer: COpaquePointer = it.toCPointer()!!
|
||||
assertFailsWith<IncorrectDereferenceException> {
|
||||
// Even attempting to convert a pointer to StableRef should fail.
|
||||
val otherThreadRef: StableRef<Any> = pointer.asStableRef()
|
||||
println(otherThreadRef.toString())
|
||||
if (kotlin.native.Platform.memoryModel == kotlin.native.MemoryModel.EXPERIMENTAL) {
|
||||
val otherThreadRef: StableRef<Holder> = pointer.asStableRef()
|
||||
assertEquals(otherThreadRef.get().value, 42)
|
||||
} else {
|
||||
assertFailsWith<IncorrectDereferenceException> {
|
||||
// Even attempting to convert a pointer to StableRef should fail.
|
||||
val otherThreadRef: StableRef<Holder> = pointer.asStableRef()
|
||||
println(otherThreadRef.get().value)
|
||||
}
|
||||
}
|
||||
Unit
|
||||
}
|
||||
|
||||
@@ -28,11 +28,16 @@ val int2 = 77
|
||||
int1++
|
||||
withWorker {
|
||||
executeAfter(0, {
|
||||
assertFailsWith<IncorrectDereferenceException> {
|
||||
if (kotlin.native.Platform.memoryModel == kotlin.native.MemoryModel.EXPERIMENTAL) {
|
||||
int1++
|
||||
assertEquals(3, int1)
|
||||
} else {
|
||||
assertFailsWith<IncorrectDereferenceException> {
|
||||
int1++
|
||||
}
|
||||
assertEquals(2, int1)
|
||||
}
|
||||
assertEquals(2, int1)
|
||||
assertEquals(77, int2)
|
||||
}.freeze())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user