Skip to content

Commit

Permalink
fix test.
Browse files Browse the repository at this point in the history
  • Loading branch information
aoli-al committed Apr 8, 2024
1 parent 5bb9952 commit ed85834
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 31 deletions.
4 changes: 1 addition & 3 deletions core/src/main/kotlin/cmu/pasta/sfuzz/core/GlobalContext.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@ import cmu.pasta.sfuzz.runtime.Delegate
import cmu.pasta.sfuzz.runtime.MemoryOpType
import cmu.pasta.sfuzz.runtime.Runtime
import cmu.pasta.sfuzz.runtime.TargetTerminateException
import java.io.ObjectStreamField
import java.io.PrintWriter
import java.io.StringWriter
import java.lang.invoke.VarHandle
import java.util.concurrent.CountDownLatch
import java.util.concurrent.Executors
import java.util.concurrent.Semaphore
Expand Down Expand Up @@ -696,7 +694,7 @@ object GlobalContext {
if (currentThread != nextThread && shouldBlockCurrentThread) {
currentThread.block()
}
} catch (e: Throwable) {
} catch (e: Throwable) {
throw e
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import cmu.pasta.sfuzz.core.concurrency.SFuzzThread
import cmu.pasta.sfuzz.runtime.Delegate
import cmu.pasta.sfuzz.runtime.MemoryOpType
import cmu.pasta.sfuzz.runtime.TargetTerminateException
import java.lang.invoke.VarHandle
import java.util.concurrent.CountDownLatch
import java.util.concurrent.Semaphore
import java.util.concurrent.locks.Condition
Expand Down
1 change: 0 additions & 1 deletion core/src/main/kotlin/cmu/pasta/sfuzz/core/TestRunner.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import cmu.pasta.sfuzz.core.logger.ConsoleLogger
import cmu.pasta.sfuzz.core.runtime.AnalysisResult
import cmu.pasta.sfuzz.runtime.Delegate
import cmu.pasta.sfuzz.runtime.Runtime
import java.lang.reflect.InvocationTargetException
import java.nio.file.Paths
import kotlin.io.path.ExperimentalPathApi
import kotlin.io.path.createDirectories
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package cmu.pasta.sfuzz.core.scheduler

import cmu.pasta.sfuzz.core.ThreadContext
import cmu.pasta.sfuzz.core.exception.SchedulerInternalException

class ReplayScheduler(val schedule: Schedule) : Scheduler {

Expand All @@ -13,7 +12,8 @@ class ReplayScheduler(val schedule: Schedule) : Scheduler {
}
if (index >= schedule.choices.size) {
return threads[0]
// throw SchedulerInternalException("Require more scheduling choices for replay scheduler")
// throw SchedulerInternalException("Require more scheduling choices for replay
// scheduler")
}
val choice = schedule.choices[index]
assert(choice.enabled == threads.size)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,36 @@ import org.objectweb.asm.Opcodes.ASM9
import org.objectweb.asm.Type
import org.objectweb.asm.commons.AdviceAdapter

class FieldInstanceReadWriteInstrumenter(cv: ClassVisitor): ClassVisitorBase(cv,
"java.lang.invoke.VarHandleInts\$FieldInstanceReadWrite",
"java.lang.invoke.VarHandleLongs\$FieldInstanceReadWrite",
"java.lang.invoke.VarHandleFloats\$FieldInstanceReadWrite",
"java.lang.invoke.VarHandleDoubles\$FieldInstanceReadWrite",
"java.lang.invoke.VarHandleBooleans\$FieldInstanceReadWrite",
"java.lang.invoke.VarHandleBytes\$FieldInstanceReadWrite",
"java.lang.invoke.VarHandleShorts\$FieldInstanceReadWrite",
"java.lang.invoke.VarHandleChars\$FieldInstanceReadWrite",
"java.lang.invoke.VarHandleReferences\$FieldInstanceReadWrite") {
class FieldInstanceReadWriteInstrumenter(cv: ClassVisitor) :
ClassVisitorBase(
cv,
"java.lang.invoke.VarHandleInts\$FieldInstanceReadWrite",
"java.lang.invoke.VarHandleLongs\$FieldInstanceReadWrite",
"java.lang.invoke.VarHandleFloats\$FieldInstanceReadWrite",
"java.lang.invoke.VarHandleDoubles\$FieldInstanceReadWrite",
"java.lang.invoke.VarHandleBooleans\$FieldInstanceReadWrite",
"java.lang.invoke.VarHandleBytes\$FieldInstanceReadWrite",
"java.lang.invoke.VarHandleShorts\$FieldInstanceReadWrite",
"java.lang.invoke.VarHandleChars\$FieldInstanceReadWrite",
"java.lang.invoke.VarHandleReferences\$FieldInstanceReadWrite") {

override fun instrumentMethod(
mv: MethodVisitor,
access: Int,
name: String,
descriptor: String,
signature: String?,
exceptions: Array<out String>?
mv: MethodVisitor,
access: Int,
name: String,
descriptor: String,
signature: String?,
exceptions: Array<out String>?
): MethodVisitor {
if (name == "compareAndSet") {
val type = Type.getArgumentTypes(descriptor)[2]!!
return object: AdviceAdapter(ASM9, mv, access, name, descriptor) {
return object : AdviceAdapter(ASM9, mv, access, name, descriptor) {
override fun visitMethodInsn(
opcodeAndSource: Int,
owner: String,
name: String,
descriptor: String,
isInterface: Boolean
opcodeAndSource: Int,
owner: String,
name: String,
descriptor: String,
isInterface: Boolean
) {
if (owner == "jdk/internal/misc/Unsafe" && name.contains("compareAndSet")) {
// Unsafe compareAndSet methods are called with the following arguments:
Expand All @@ -54,7 +56,8 @@ class FieldInstanceReadWriteInstrumenter(cv: ClassVisitor): ClassVisitorBase(cv,

loadLocal(offset)

visitMethodInsn(Opcodes.INVOKESTATIC,
visitMethodInsn(
Opcodes.INVOKESTATIC,
Runtime::class.java.name.replace(".", "/"),
Runtime::onUnsafeWriteVolatile.name,
Utils.kFunctionToJvmMethodDescriptor(Runtime::onUnsafeWriteVolatile),
Expand All @@ -70,5 +73,4 @@ class FieldInstanceReadWriteInstrumenter(cv: ClassVisitor): ClassVisitorBase(cv,
}
return mv
}

}

0 comments on commit ed85834

Please sign in to comment.