-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cache ReentrantRewriteLocks if they are created statically Replace ExecutorService with a lightweight HelperThread Save recordings to recording folder if Fray is not in explore mode Shadow apache.common in gradle plugin
- Loading branch information
Showing
18 changed files
with
174 additions
and
58 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
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
36 changes: 34 additions & 2 deletions
36
core/src/main/kotlin/org/pastalab/fray/core/concurrency/HelperThread.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 |
---|---|---|
@@ -1,5 +1,37 @@ | ||
package org.pastalab.fray.core.concurrency | ||
|
||
open class HelperThread(runnable: Runnable?) : Thread(runnable) { | ||
constructor() : this(null) | ||
import org.pastalab.fray.core.utils.Utils | ||
|
||
class HelperThread : Thread("fray-helper-thread") { | ||
var shouldStop = false | ||
var currentRunnable: Runnable? = null | ||
|
||
override fun run() { | ||
while (!shouldStop) { | ||
val job: Runnable? | ||
synchronized(this) { | ||
while (currentRunnable == null && !shouldStop) { | ||
(this as Object).wait() | ||
} | ||
job = currentRunnable | ||
currentRunnable = null | ||
} | ||
job?.run() | ||
} | ||
} | ||
|
||
fun submit(runnable: Runnable) { | ||
synchronized(this) { | ||
Utils.verifyOrReport(currentRunnable == null, "Helper thread is already running a job") | ||
currentRunnable = runnable | ||
(this as Object).notify() | ||
} | ||
} | ||
|
||
fun stopHelperThread() { | ||
synchronized(this) { | ||
shouldStop = true | ||
(this as Object).notify() | ||
} | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
core/src/main/kotlin/org/pastalab/fray/core/concurrency/ReentrantReadWriteLockCache.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,30 @@ | ||
package org.pastalab.fray.core.concurrency | ||
|
||
import java.lang.ref.WeakReference | ||
import java.util.concurrent.locks.ReentrantReadWriteLock | ||
import java.util.concurrent.locks.ReentrantReadWriteLock.ReadLock | ||
import java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock | ||
import org.pastalab.fray.core.concurrency.primitives.ReferencedContextManager | ||
|
||
/** | ||
* We need a static object to store the [ReadLock] and [WriteLock] because if the lock is created | ||
* statically, we may lose track of the lock owner across test runs. | ||
*/ | ||
object ReentrantReadWriteLockCache { | ||
val lockCache = | ||
ReferencedContextManager<WeakReference<ReentrantReadWriteLock>>({ | ||
throw RuntimeException("Should not be called") | ||
}) | ||
|
||
fun getLock(obj: Any): ReentrantReadWriteLock? { | ||
if (lockCache.hasContext(obj)) { | ||
return lockCache.getContext(obj).get() | ||
} | ||
return null | ||
} | ||
|
||
fun registerLock(lock: ReentrantReadWriteLock) { | ||
lockCache.addContext(lock.readLock(), WeakReference(lock)) | ||
lockCache.addContext(lock.writeLock(), WeakReference(lock)) | ||
} | ||
} |
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
3 changes: 3 additions & 0 deletions
3
core/src/main/kotlin/org/pastalab/fray/core/utils/FrayBackgroundExecutor.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,3 @@ | ||
package org.pastalab.fray.core.utils | ||
|
||
class FrayBackgroundExecutor {} |
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
kotlin.code.style=official | ||
group=org.pastalab.fray | ||
version=0.1.10 | ||
version=0.2.0 | ||
org.gradle.jvmargs=-Xmx2g -XX:MaxMetaspaceSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 |
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
8 changes: 8 additions & 0 deletions
8
...java/org/pastalab/fray/test/success/rwlock/StaticReentrantReadWriteLockMultipleTests.java
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,8 @@ | ||
package org.pastalab.fray.test.success.rwlock; | ||
|
||
public class StaticReentrantReadWriteLockMultipleTests { | ||
public static void main(String[] args) { | ||
StaticReentrantReadWriteLockNormal.lock.readLock().lock(); | ||
StaticReentrantReadWriteLockNormal.lock.readLock().unlock(); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
...c/main/java/org/pastalab/fray/test/success/rwlock/StaticReentrantReadWriteLockNormal.java
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,12 @@ | ||
package org.pastalab.fray.test.success.rwlock; | ||
|
||
import java.util.concurrent.locks.ReentrantReadWriteLock; | ||
|
||
public class StaticReentrantReadWriteLockNormal { | ||
public static ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); | ||
|
||
public static void main(String[] args) throws InterruptedException { | ||
lock.readLock().lock(); | ||
lock.readLock().unlock(); | ||
} | ||
} |
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
Oops, something went wrong.