-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
168 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
src/jvm/main/org/jetbrains/kotlinx/lincheck/runner/ActorCrashHandlerGenerator.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
* Lincheck | ||
* | ||
* Copyright (C) 2019 - 2021 JetBrains s.r.o. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Lesser Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Lesser Public | ||
* License along with this program. If not, see | ||
* <http://www.gnu.org/licenses/lgpl-3.0.html> | ||
*/ | ||
|
||
package org.jetbrains.kotlinx.lincheck.runner | ||
|
||
import org.jetbrains.kotlinx.lincheck.CrashResult | ||
import org.jetbrains.kotlinx.lincheck.nvm.CrashError | ||
import org.objectweb.asm.Label | ||
import org.objectweb.asm.Type | ||
import org.objectweb.asm.commons.GeneratorAdapter | ||
import org.objectweb.asm.commons.Method | ||
|
||
private val CRASH_ERROR_TYPE = Type.getType(CrashError::class.java) | ||
private val CRASH_RESULT_TYPE = Type.getType(CrashResult::class.java) | ||
private val RESULT_KT_CREATE_CRASH_RESULT_METHOD = | ||
Method("creteCrashResult", CRASH_RESULT_TYPE, arrayOf(CRASH_ERROR_TYPE)) | ||
|
||
|
||
open class ActorCrashHandlerGenerator { | ||
open fun addCrashTryBlock(start: Label, end: Label, mv: GeneratorAdapter) {} | ||
open fun addCrashCatchBlock(mv: GeneratorAdapter, resLocal: Int, iLocal: Int, skip: Label) {} | ||
} | ||
|
||
class DurableActorCrashHandlerGenerator : ActorCrashHandlerGenerator() { | ||
private lateinit var handlerLabel: Label | ||
|
||
override fun addCrashTryBlock(start: Label, end: Label, mv: GeneratorAdapter) { | ||
super.addCrashTryBlock(start, end, mv) | ||
handlerLabel = mv.newLabel() | ||
mv.visitTryCatchBlock(start, end, handlerLabel, CRASH_ERROR_TYPE.internalName) | ||
} | ||
|
||
override fun addCrashCatchBlock(mv: GeneratorAdapter, resLocal: Int, iLocal: Int, skip: Label) { | ||
super.addCrashCatchBlock(mv, resLocal, iLocal, skip) | ||
mv.visitLabel(handlerLabel) | ||
storeExceptionResultFromCrash(mv, resLocal, iLocal, skip) | ||
} | ||
|
||
private fun storeExceptionResultFromCrash(mv: GeneratorAdapter, resLocal: Int, iLocal: Int, skip: Label) { | ||
mv.checkCast(CRASH_ERROR_TYPE) | ||
val eLocal = mv.newLocal(CRASH_ERROR_TYPE) | ||
mv.storeLocal(eLocal) | ||
|
||
mv.loadLocal(resLocal) | ||
mv.loadLocal(iLocal) | ||
|
||
// Load exception result | ||
mv.loadLocal(eLocal) | ||
// Create crash result instance | ||
mv.invokeStatic(TestThreadExecutionGenerator.RESULT_KT_TYPE, RESULT_KT_CREATE_CRASH_RESULT_METHOD) | ||
mv.checkCast(TestThreadExecutionGenerator.RESULT_TYPE) | ||
mv.arrayStore(TestThreadExecutionGenerator.RESULT_TYPE) | ||
|
||
mv.goTo(skip) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters