Skip to content

Commit

Permalink
skip print.
Browse files Browse the repository at this point in the history
  • Loading branch information
aoli-al committed Mar 28, 2024
1 parent 059f6c9 commit f417063
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 28 deletions.
37 changes: 19 additions & 18 deletions core/src/main/kotlin/cmu/pasta/sfuzz/core/GlobalContext.kt
Original file line number Diff line number Diff line change
Expand Up @@ -186,21 +186,26 @@ object GlobalContext {
}

fun threadCompleted(t: Thread) {
if (!errorFound) {
monitorEnter(t)
}
objectNotifyAll(t)
registeredThreads[t.id]?.state = ThreadState.Completed
// We do not want to send notify all because
// we don't have monitor lock here.
var size = 0
lockManager.getLockContext(t).wakingThreads.let {
for (thread in it) {
registeredThreads[thread]!!.state = ThreadState.Enabled
try {

if (!errorFound) {
monitorEnter(t)
}
objectNotifyAll(t)
registeredThreads[t.id]?.state = ThreadState.Completed
// We do not want to send notify all because
// we don't have monitor lock here.
var size = 0
lockManager.getLockContext(t).wakingThreads.let {
for (thread in it) {
registeredThreads[thread]!!.state = ThreadState.Enabled
}
size = it.size
}
size = it.size
syncManager.createWait(t, size)
} catch (e: Throwable) {
e.printStackTrace()
}
syncManager.createWait(t, size)

executor.submit {
while (t.isAlive) {
Expand Down Expand Up @@ -406,7 +411,7 @@ object GlobalContext {
// synchronized(lock) {
// lock.unlock();
// }
while (!lockManager.lock(lock, t, true, false) && !errorFound) {
while (!lockManager.lock(lock, t, true, false)) {
registeredThreads[t]?.state = ThreadState.Paused

// We want to block current thread because we do
Expand All @@ -415,10 +420,6 @@ object GlobalContext {
// threads hold the same lock.
scheduleNextOperation(true)
}

if (errorFound) {
throw TargetTerminateException(-2)
}
}

fun monitorEnter(lock: Any) {
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/kotlin/cmu/pasta/sfuzz/core/RuntimeDelegate.kt
Original file line number Diff line number Diff line change
Expand Up @@ -233,11 +233,11 @@ class RuntimeDelegate : Delegate() {
entered.set(false)
}

override fun onLoadClass() {
override fun onSkipMethod() {
skipFunctionEntered.set(1 + skipFunctionEntered.get())
}

override fun onLoadClassDone() {
override fun onSkipMethodDone() {
skipFunctionEntered.set(skipFunctionEntered.get() - 1)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ fun instrumentClass(path: String, inputStream: InputStream): ByteArray {
cv = VolatileFieldsInstrumenter(cv, true)
cv = UnsafeInstrumenter(cv)
cv = ClassloaderInstrumenter(cv)
cv = PrintStreamInstrumenter(cv)
cv = ObjectInstrumenter(cv)
cv = SemaphoreInstrumenter(cv)
cv = CountDownLatchInstrumenter(cv)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@ class ClassloaderInstrumenter(cv: ClassVisitor) : ClassVisitor(ASM9, cv) {
descriptor == "(Ljava/lang/String;)Ljava/lang/Class;" &&
className == "java/lang/ClassLoader") ||
(name == "makeImpl" && className == "java/lang/invoke/MethodType")) {
val eMv = MethodEnterVisitor(mv, Runtime::onLoadClass, access, name, descriptor, false, false)
val eMv =
MethodEnterVisitor(mv, Runtime::onSkipMethod, access, name, descriptor, false, false)
return MethodExitVisitor(
eMv, Runtime::onLoadClassDone, access, name, descriptor, false, false, true)
eMv, Runtime::onSkipMethodDone, access, name, descriptor, false, false, true)
}
return mv
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package cmu.pasta.sfuzz.instrumentation.visitors

import cmu.pasta.sfuzz.runtime.Runtime
import java.io.PrintStream
import org.objectweb.asm.ClassVisitor
import org.objectweb.asm.MethodVisitor

class PrintStreamInstrumenter(cv: ClassVisitor) :
ClassVisitorBase(cv, PrintStream::class.java.name) {
override fun instrumentMethod(
mv: MethodVisitor,
access: Int,
name: String,
descriptor: String,
signature: String?,
exceptions: Array<out String>?
): MethodVisitor {
if (name == "println" || name == "writeln" || name == "write") {
val eMv =
MethodEnterVisitor(mv, Runtime::onSkipMethod, access, name, descriptor, false, false)
return MethodExitVisitor(
eMv, Runtime::onSkipMethodDone, access, name, descriptor, false, false, false)
}
return super.instrumentMethod(mv, access, name, descriptor, signature, exceptions)
}
}
4 changes: 2 additions & 2 deletions runtime/src/main/java/cmu/pasta/sfuzz/runtime/Delegate.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,10 @@ public void onExit(int status) {
public void onYield() {
}

public void onLoadClass() {
public void onSkipMethod() {
}

public void onLoadClassDone() {
public void onSkipMethodDone() {
}

public void start() {
Expand Down
8 changes: 4 additions & 4 deletions runtime/src/main/java/cmu/pasta/sfuzz/runtime/Runtime.java
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,12 @@ public static void onYield() {
DELEGATE.onYield();
}

public static void onLoadClass() {
DELEGATE.onLoadClass();
public static void onSkipMethod() {
DELEGATE.onSkipMethod();
}

public static void onLoadClassDone() {
DELEGATE.onLoadClassDone();
public static void onSkipMethodDone() {
DELEGATE.onSkipMethodDone();
}

public static void start() {
Expand Down

0 comments on commit f417063

Please sign in to comment.