├── .gitignore ├── LICENSE.txt ├── README.md ├── bitbucket-pipelines.yml ├── dxlab-mail.png ├── libtest ├── pom.xml └── src │ ├── main │ └── java │ │ ├── com │ │ └── github │ │ │ └── lock │ │ │ └── free │ │ │ └── queue │ │ │ ├── BlockingQueueAdapter.java │ │ │ ├── LockFreeQueue.java │ │ │ ├── Node.java │ │ │ └── SimpleQueue.java │ │ ├── org │ │ └── cliffc │ │ │ └── high_scale_lib │ │ │ └── old │ │ │ ├── AbstractEntry.java │ │ │ ├── ConcurrentAutoTable.java │ │ │ ├── Counter.java │ │ │ ├── IntIterator.java │ │ │ ├── NonBlockingHashMap.java │ │ │ ├── NonBlockingHashMapLong.java │ │ │ ├── NonBlockingHashSet.java │ │ │ ├── NonBlockingHashtable.java │ │ │ ├── NonBlockingIdentityHashMap.java │ │ │ ├── NonBlockingSetInt.java │ │ │ └── UtilUnsafe.java │ │ ├── psy │ │ └── lob │ │ │ └── saw │ │ │ └── queues │ │ │ ├── benchmarks │ │ │ ├── handrolled │ │ │ │ ├── QueueThroughputBusy.java │ │ │ │ └── QueueThroughputYield.java │ │ │ └── jmh │ │ │ │ ├── QueueBenchmark.java │ │ │ │ ├── QueueRoundTripLatency.java │ │ │ │ ├── QueueThroughputBusy.java │ │ │ │ ├── QueueThroughputYield.java │ │ │ │ ├── SingleThreadedOffer.java │ │ │ │ └── SingleThreadedPoll.java │ │ │ ├── common │ │ │ ├── CircularArray1ReadWrite.java │ │ │ ├── CircularArray2ReadWrite.java │ │ │ ├── CircularArray3ReadWrite.java │ │ │ ├── CircularArray4ReadWrite.java │ │ │ ├── CircularArrayQueue1.java │ │ │ ├── CircularArrayQueue2.java │ │ │ ├── CircularArrayQueue3.java │ │ │ ├── CircularArrayQueue4.java │ │ │ ├── Pow2.java │ │ │ ├── SPSCQueueFactory.java │ │ │ └── UnsafeAccess.java │ │ │ ├── ff │ │ │ ├── FastFlowQueue1.java │ │ │ └── FastFlowQueue2.java │ │ │ ├── lamport │ │ │ ├── LamportQueue1.java │ │ │ ├── LamportQueue2.java │ │ │ ├── LamportQueue3.java │ │ │ ├── LamportQueue4.java │ │ │ ├── LamportQueue5.java │ │ │ └── VolatileLongCell.java │ │ │ └── thompson │ │ │ ├── LongCell.java │ │ │ ├── ThompsonQueue1.java │ │ │ ├── ThompsonQueue2.java │ │ │ └── ThompsonQueue3.java │ │ ├── romix │ │ └── scala │ │ │ ├── None.java │ │ │ ├── Option.java │ │ │ ├── Some.java │ │ │ └── collection │ │ │ └── concurrent │ │ │ ├── BasicNode.java │ │ │ ├── CNodeBase.java │ │ │ ├── Gen.java │ │ │ ├── INodeBase.java │ │ │ ├── ListMap.java │ │ │ ├── MainNode.java │ │ │ ├── Pair.java │ │ │ └── TrieMap.java │ │ ├── tests │ │ └── custom │ │ │ ├── counter │ │ │ ├── Counter.java │ │ │ ├── CounterCorrect2.java │ │ │ ├── CounterGet.java │ │ │ ├── CounterWrong0.java │ │ │ ├── CounterWrong1.java │ │ │ └── CounterWrong2.java │ │ │ ├── queue │ │ │ ├── Queue.java │ │ │ ├── QueueEmptyException.java │ │ │ ├── QueueFullException.java │ │ │ ├── QueueSynchronized.java │ │ │ ├── QueueWrong1.java │ │ │ ├── QueueWrong2.java │ │ │ └── QueueWrong3.java │ │ │ └── transfer │ │ │ ├── Accounts.java │ │ │ ├── AccountsWrong1.java │ │ │ ├── AccountsWrong2.java │ │ │ ├── AccountsWrong3.java │ │ │ └── AccountsWrong4.java │ │ ├── thesis_example │ │ ├── Counter.java │ │ ├── CounterCorrect1.java │ │ ├── CounterCorrect2.java │ │ ├── CounterWrong1.java │ │ ├── CounterWrong2.java │ │ └── QueueCorrect.java │ │ └── z │ │ ├── annotation │ │ ├── InternalUse.java │ │ ├── NotThreadSafe.java │ │ ├── PerformanceDegraded.java │ │ └── ThreadSafe.java │ │ ├── channel │ │ ├── BroadcastChannel.java │ │ ├── Channel.java │ │ ├── Channels.java │ │ ├── GenericHyperLoop.java │ │ ├── GenericMPMCQueue.java │ │ ├── IntHyperLoop.java │ │ ├── LongHyperLoop.java │ │ ├── MPMCQueue.java │ │ └── ReceivePort.java │ │ ├── evil │ │ └── Intrinsics.java │ │ ├── exception │ │ └── ContractViolatedException.java │ │ ├── function │ │ ├── ExceptionalFunction0.java │ │ ├── ExceptionalRunnable.java │ │ ├── Function0.java │ │ ├── Function1.java │ │ ├── Function10.java │ │ ├── Function11.java │ │ ├── Function2.java │ │ ├── Function3.java │ │ ├── Function4.java │ │ ├── Function5.java │ │ ├── Function6.java │ │ ├── Function7.java │ │ ├── Function8.java │ │ ├── Function9.java │ │ ├── Functions.java │ │ ├── Pipe.java │ │ ├── Pipeline.java │ │ ├── ThrowableFunction0.java │ │ ├── ThrowableRunnable.java │ │ ├── ToBooleanFunction0.java │ │ ├── ToByteFunction0.java │ │ ├── ToCharFunction0.java │ │ ├── ToDoubleFunction0.java │ │ ├── ToFloatFunction0.java │ │ ├── ToIntFunction0.java │ │ ├── ToLongFunction0.java │ │ └── ToShortFunction0.java │ │ ├── module │ │ ├── License.java │ │ └── Module.java │ │ ├── offheap │ │ ├── buffer │ │ │ ├── Buffer.java │ │ │ ├── BufferStateException.java │ │ │ ├── Buffers.java │ │ │ ├── ByteBuffer.java │ │ │ ├── LittleEndianOrderBuffer.java │ │ │ ├── NativeOrderBuffer.java │ │ │ └── NetworkOrderBuffer.java │ │ └── zmalloc │ │ │ └── Allocator.java │ │ └── util │ │ ├── Contracts.java │ │ ├── MethodHandles.java │ │ ├── SystemProperty.java │ │ ├── Throwables.java │ │ ├── Unsafes.java │ │ ├── concurrent │ │ ├── ThreadLocalPool.java │ │ └── ThreadLocalValueHolder.java │ │ └── primitives │ │ ├── Bytes.java │ │ ├── Chars.java │ │ ├── Ints.java │ │ ├── Longs.java │ │ ├── Primitives.java │ │ ├── Shorts.java │ │ ├── UnsignedBytes.java │ │ ├── UnsignedInts.java │ │ └── UnsignedLongs.java │ └── test │ └── java │ └── com │ └── devexperts │ └── dxlab │ └── lincheck │ └── tests │ ├── LockFreeDeque.java │ ├── LockFreeDequeTest.kt │ ├── boundary │ ├── BitVectorCorrect1.java │ ├── MapCorrect1.java │ └── SetCorrect1.java │ ├── custom │ ├── counter │ │ ├── CounterGetTest.java │ │ ├── CounterTest1.java │ │ ├── CounterTest2.java │ │ ├── CounterTest3.java │ │ └── CounterTest4.java │ ├── queue │ │ ├── WrapperQueueCorrect1.java │ │ ├── WrapperQueueWrong1.java │ │ ├── WrapperQueueWrong2.java │ │ └── WrapperQueueWrong3.java │ └── transfer │ │ └── AccountsTest.java │ ├── guava │ ├── MultisetCorrect1.java │ └── SetCorrect1.java │ ├── juc │ ├── blocking_queue │ │ └── BlockingQueueTest1.java │ └── hash_map │ │ └── HashMapTest.java │ ├── lockfreequeue │ └── QueueCorrect1.java │ ├── romix │ └── TrieCorrect1.java │ └── zchannel │ ├── QueueCorrect1.java │ └── QueueCorrect2.java ├── lincheck ├── pom.xml └── src │ ├── main │ └── java │ │ └── com │ │ └── devexperts │ │ └── dxlab │ │ └── lincheck │ │ ├── Actor.java │ │ ├── CTestConfiguration.java │ │ ├── CTestStructure.java │ │ ├── ExecutionClassLoader.java │ │ ├── LinChecker.java │ │ ├── Options.java │ │ ├── Reporter.kt │ │ ├── Result.java │ │ ├── TransformationClassLoader.java │ │ ├── Utils.java │ │ ├── annotations │ │ ├── LogLevel.java │ │ ├── OpGroupConfig.java │ │ ├── Operation.java │ │ └── Param.java │ │ ├── execution │ │ ├── ActorGenerator.java │ │ ├── ExecutionGenerator.java │ │ ├── ExecutionResult.java │ │ ├── ExecutionScenario.java │ │ └── RandomExecutionGenerator.java │ │ ├── paramgen │ │ ├── ByteGen.java │ │ ├── DoubleGen.java │ │ ├── FloatGen.java │ │ ├── IntGen.java │ │ ├── LongGen.java │ │ ├── ParameterGenerator.java │ │ ├── ShortGen.java │ │ └── StringGen.java │ │ ├── runner │ │ ├── ParallelThreadsRunner.java │ │ ├── Runner.java │ │ ├── TestThreadExecution.java │ │ └── TestThreadExecutionGenerator.java │ │ ├── strategy │ │ ├── ManagedStrategy.java │ │ ├── ManagedStrategyHolder.java │ │ ├── ManagedStrategyTransformer.java │ │ ├── Strategy.java │ │ ├── randomswitch │ │ │ ├── RandomSwitchCTest.java │ │ │ ├── RandomSwitchCTestConfiguration.java │ │ │ ├── RandomSwitchOptions.java │ │ │ └── RandomSwitchStrategy.java │ │ └── stress │ │ │ ├── StressCTest.java │ │ │ ├── StressCTestConfiguration.java │ │ │ ├── StressOptions.java │ │ │ └── StressStrategy.java │ │ └── verifier │ │ ├── CachedVerifier.java │ │ ├── EpsilonVerifier.java │ │ ├── LTS.kt │ │ ├── RegularLTS.kt │ │ ├── Verifier.java │ │ ├── linearizability │ │ └── LinearizabilityVerifier.kt │ │ ├── quantitative │ │ ├── CostWithNextCostCounter.java │ │ ├── ExtendedLTS.kt │ │ ├── IterativePathCostFunctionCounter.java │ │ ├── PathCostFunction.java │ │ ├── QuantitativeRelaxationVerifier.kt │ │ ├── QuantitativeRelaxationVerifierConf.java │ │ └── QuantitativeRelaxed.java │ │ ├── quasi │ │ ├── QuasiLinearizabilityVerifier.kt │ │ └── QuasiLinearizabilityVerifierConf.java │ │ ├── quiescent │ │ ├── QuiescentConsistencyVerifier.java │ │ └── QuiescentConsistent.java │ │ └── serializability │ │ └── SerializabilityVerifier.java │ └── test │ └── java │ └── com │ └── devexperts │ └── dxlab │ └── lincheck │ └── test │ ├── ExceptionAsResultTest.java │ ├── NonParallelOpGroupTest.java │ ├── ResultAsParameterTest.java │ ├── RunOnceTest.java │ ├── runner │ └── TestThreadExecutionHelperTest.java │ ├── strategy │ ├── randomswitch │ │ ├── RandomSwitchCTestAnnTest.java │ │ └── RandomSwitchOptionsTest.java │ └── stress │ │ ├── StressCTestAnnTest.java │ │ └── StressOptionsTest.java │ └── verifier │ ├── EpsilonVerifierTest.kt │ ├── linearizability │ └── ConcurrentHashMapTest.java │ ├── quantitative │ ├── KPriorityQueueSimulation.java │ ├── KPriorityQueueTest.kt │ ├── KStackSimulation.kt │ ├── KStackTest.kt │ ├── QuantitativeStackTest.kt │ ├── StutteringCounterSimulation.java │ └── StutteringCounterTest.java │ ├── quasi │ ├── KRelaxedPopStack.kt │ ├── KRelaxedPopStackTest.kt │ ├── SegmentQueue.java │ └── SegmentQueueTest.kt │ ├── quiescent │ ├── LockFreeMPSCQueue.kt │ └── LockFreeMPSCQueueTest.java │ └── serializability │ ├── SerializableQueueSimulation.kt │ └── SerializableQueueSimulationTest.kt └── pom.xml /.gitignore: -------------------------------------------------------------------------------- 1 | ### Java template 2 | *.class 3 | 4 | # Mobile Tools for Java (J2ME) 5 | .mtj.tmp/ 6 | 7 | # Package Files # 8 | *.jar 9 | *.war 10 | *.ear 11 | 12 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 13 | hs_err_pid* 14 | ### JetBrains template 15 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio 16 | 17 | *.iml 18 | 19 | ## Directory-based project format: 20 | .idea/ 21 | # if you remove the above rule, at least ignore the following: 22 | 23 | # User-specific stuff: 24 | # .idea/workspace.xml 25 | # .idea/tasks.xml 26 | # .idea/dictionaries 27 | 28 | # Sensitive or high-churn files: 29 | # .idea/dataSources.ids 30 | # .idea/dataSources.xml 31 | # .idea/sqlDataSources.xml 32 | # .idea/dynamic.xml 33 | # .idea/uiDesigner.xml 34 | 35 | # Gradle: 36 | # .idea/gradle.xml 37 | #.idea/libraries 38 | 39 | # Mongo Explorer plugin: 40 | # .idea/mongoSettings.xml 41 | 42 | ## File-based project format: 43 | *.ipr 44 | *.iws 45 | 46 | ## Plugin-specific files: 47 | 48 | # IntelliJ 49 | /out/ 50 | 51 | # mpeltonen/sbt-idea plugin 52 | .idea_modules/ 53 | 54 | # JIRA plugin 55 | atlassian-ide-plugin.xml 56 | 57 | # Crashlytics plugin (for Android Studio and IntelliJ) 58 | com_crashlytics_export_strings.xml 59 | crashlytics.properties 60 | crashlytics-build.properties 61 | 62 | ### Maven template 63 | target/ 64 | pom.xml.tag 65 | pom.xml.releaseBackup 66 | pom.xml.versionsBackup 67 | pom.xml.next 68 | release.properties 69 | dependency-reduced-pom.xml 70 | buildNumber.properties 71 | .mvn/timing.properties 72 | 73 | # Created by .ignore support plugin (hsz.mobi) 74 | # common 75 | *~ 76 | *.bak 77 | .DS_Store 78 | .DS_Store? 79 | ._* -------------------------------------------------------------------------------- /bitbucket-pipelines.yml: -------------------------------------------------------------------------------- 1 | # This is a sample build configuration for Java (Maven). 2 | # Check our guides at https://confluence.atlassian.com/x/zd-5Mw for more examples. 3 | # Only use spaces to indent your .yml configuration. 4 | # ----- 5 | # You can specify a custom docker image from Docker Hub as your build environment. 6 | image: maven:3-jdk-8 7 | 8 | pipelines: 9 | default: 10 | - step: 11 | caches: 12 | - maven 13 | script: # Modify the commands below to build your repository. 14 | - mvn -B clean verify # -B batch mode makes Maven less verbose 15 | 16 | -------------------------------------------------------------------------------- /dxlab-mail.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/devexperts/lin-check/2653fd4ff9882c1fecd57781563af69e17e22173/dxlab-mail.png -------------------------------------------------------------------------------- /libtest/src/main/java/com/github/lock/free/queue/BlockingQueueAdapter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Lincheck - Linearizability checker 3 | * 4 | * Copyright (C) 2015-2022 Devexperts, LLC 5 | * Copyright (C) 2023 Devexperts Ireland Limited 6 | * 7 | * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. 8 | * If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | 11 | package com.github.lock.free.queue; 12 | 13 | import java.util.concurrent.BlockingQueue; 14 | import java.util.concurrent.LinkedBlockingQueue; 15 | 16 | /** 17 | */ 18 | public class BlockingQueueAdapter implements SimpleQueue { 19 | 20 | private final BlockingQueue queue; 21 | 22 | public BlockingQueueAdapter() { 23 | queue = new LinkedBlockingQueue(); 24 | } 25 | 26 | @Override 27 | public void add(T x) { 28 | queue.add(x); 29 | } 30 | 31 | @Override 32 | public T takeOrNull() { 33 | try { 34 | return queue.take(); 35 | } catch (InterruptedException e) { 36 | throw new RuntimeException(e); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /libtest/src/main/java/com/github/lock/free/queue/Node.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Lincheck - Linearizability checker 3 | * 4 | * Copyright (C) 2015-2022 Devexperts, LLC 5 | * Copyright (C) 2023 Devexperts Ireland Limited 6 | * 7 | * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. 8 | * If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | 11 | package com.github.lock.free.queue; 12 | 13 | import java.util.concurrent.atomic.AtomicReference; 14 | 15 | /** 16 | */ 17 | class Node { 18 | final AtomicReference> next = new AtomicReference>(); 19 | final T ref; 20 | Node(T ref) { 21 | this.ref = ref; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /libtest/src/main/java/com/github/lock/free/queue/SimpleQueue.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Lincheck - Linearizability checker 3 | * 4 | * Copyright (C) 2015-2022 Devexperts, LLC 5 | * Copyright (C) 2023 Devexperts Ireland Limited 6 | * 7 | * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. 8 | * If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | 11 | package com.github.lock.free.queue; 12 | 13 | /** 14 | */ 15 | public interface SimpleQueue { 16 | void add(T x); 17 | 18 | T takeOrNull(); 19 | } 20 | -------------------------------------------------------------------------------- /libtest/src/main/java/org/cliffc/high_scale_lib/old/AbstractEntry.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Written by Cliff Click and released to the public domain, as explained at 3 | * http://creativecommons.org/licenses/publicdomain 4 | */ 5 | 6 | package org.cliffc.high_scale_lib.old; 7 | 8 | import java.util.*; 9 | 10 | /** 11 | * A simple implementation of {@link Map.Entry}. 12 | * Does not implement {@link Map.Entry.setValue}, that is done by users of the class. 13 | * 14 | * @since 1.5 15 | * @author Cliff Click 16 | * @param the type of keys maintained by this map 17 | * @param the type of mapped values 18 | */ 19 | 20 | abstract class AbstractEntry implements Map.Entry { 21 | /** Strongly typed key */ 22 | protected final TypeK _key; 23 | /** Strongly typed value */ 24 | protected TypeV _val; 25 | 26 | public AbstractEntry(final TypeK key, final TypeV val) { _key = key; _val = val; } 27 | public AbstractEntry(final Map.Entry e ) { _key = e.getKey(); _val = e.getValue(); } 28 | /** Return "key=val" string */ 29 | public String toString() { return _key + "=" + _val; } 30 | /** Return key */ 31 | public TypeK getKey () { return _key; } 32 | /** Return val */ 33 | public TypeV getValue() { return _val; } 34 | 35 | /** Equal if the underlying key & value are equal */ 36 | public boolean equals(final Object o) { 37 | if (!(o instanceof Map.Entry)) return false; 38 | final Map.Entry e = (Map.Entry)o; 39 | return eq(_key, e.getKey()) && eq(_val, e.getValue()); 40 | } 41 | 42 | /** Compute "key.hashCode() ^ val.hashCode()" */ 43 | public int hashCode() { 44 | return 45 | ((_key == null) ? 0 : _key.hashCode()) ^ 46 | ((_val == null) ? 0 : _val.hashCode()); 47 | } 48 | 49 | private static boolean eq(final Object o1, final Object o2) { 50 | return (o1 == null ? o2 == null : o1.equals(o2)); 51 | } 52 | } 53 | 54 | -------------------------------------------------------------------------------- /libtest/src/main/java/org/cliffc/high_scale_lib/old/Counter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Written by Cliff Click and released to the public domain, as explained at 3 | * http://creativecommons.org/licenses/publicdomain 4 | */ 5 | 6 | package org.cliffc.high_scale_lib.old; 7 | 8 | /** 9 | * A simple high-performance counter. Merely renames the extended {@link 10 | * ConcurrentAutoTable} class to be more obvious. 11 | * {@link ConcurrentAutoTable} already has a decent 12 | * counting API. 13 | * 14 | * @since 1.5 15 | * @author Cliff Click 16 | */ 17 | 18 | public class Counter extends ConcurrentAutoTable { 19 | 20 | // Add the given value to current counter value. Concurrent updates will 21 | // not be lost, but addAndGet or getAndAdd are not implemented because but 22 | // the total counter value is not atomically updated. 23 | //public void add( long x ); 24 | //public void decrement(); 25 | //public void increment(); 26 | 27 | // Current value of the counter. Since other threads are updating furiously 28 | // the value is only approximate, but it includes all counts made by the 29 | // current thread. Requires a pass over all the striped counters. 30 | //public long get(); 31 | //public int intValue(); 32 | //public long longValue(); 33 | 34 | // A cheaper 'get'. Updated only once/millisecond, but fast as a simple 35 | // load instruction when not updating. 36 | //public long estimate_get( ); 37 | 38 | } 39 | 40 | -------------------------------------------------------------------------------- /libtest/src/main/java/org/cliffc/high_scale_lib/old/IntIterator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Lincheck - Linearizability checker 3 | * 4 | * Copyright (C) 2015-2022 Devexperts, LLC 5 | * Copyright (C) 2023 Devexperts Ireland Limited 6 | * 7 | * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. 8 | * If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | 11 | package org.cliffc.high_scale_lib.old; 12 | 13 | public interface IntIterator { 14 | public int next(); 15 | public boolean hasNext(); 16 | } 17 | -------------------------------------------------------------------------------- /libtest/src/main/java/org/cliffc/high_scale_lib/old/UtilUnsafe.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Lincheck - Linearizability checker 3 | * 4 | * Copyright (C) 2015-2022 Devexperts, LLC 5 | * Copyright (C) 2023 Devexperts Ireland Limited 6 | * 7 | * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. 8 | * If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | 11 | package org.cliffc.high_scale_lib.old; 12 | 13 | import java.lang.reflect.Field; 14 | import sun.misc.Unsafe; 15 | 16 | /** 17 | * Simple class to obtain access to the {@link Unsafe} object. {@link Unsafe} 18 | * is required to allow efficient CAS operations on arrays. Note that the 19 | * versions in {@link java.util.concurrent.atomic}, such as {@link 20 | * java.util.concurrent.atomic.AtomicLongArray}, require extra memory ordering 21 | * guarantees which are generally not needed in these algorithms and are also 22 | * expensive on most processors. 23 | */ 24 | class UtilUnsafe { 25 | private UtilUnsafe() { } // dummy private constructor 26 | /** Fetch the Unsafe. Use With Caution. */ 27 | public static Unsafe getUnsafe() { 28 | // Not on bootclasspath 29 | if( UtilUnsafe.class.getClassLoader() == null ) 30 | return Unsafe.getUnsafe(); 31 | try { 32 | final Field fld = Unsafe.class.getDeclaredField("theUnsafe"); 33 | fld.setAccessible(true); 34 | return (Unsafe) fld.get(UtilUnsafe.class); 35 | } catch (Exception e) { 36 | throw new RuntimeException("Could not obtain access to sun.misc.Unsafe", e); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /libtest/src/main/java/psy/lob/saw/queues/benchmarks/jmh/QueueBenchmark.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Lincheck - Linearizability checker 3 | * 4 | * Copyright (C) 2015-2022 Devexperts, LLC 5 | * Copyright (C) 2023 Devexperts Ireland Limited 6 | * 7 | * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. 8 | * If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | 11 | package psy.lob.saw.queues.benchmarks.jmh; 12 | 13 | import java.util.Queue; 14 | 15 | import psy.lob.saw.queues.common.SPSCQueueFactory; 16 | import org.openjdk.jmh.annotations.Level; 17 | import org.openjdk.jmh.annotations.Param; 18 | import org.openjdk.jmh.annotations.Scope; 19 | import org.openjdk.jmh.annotations.Setup; 20 | import org.openjdk.jmh.annotations.State; 21 | 22 | @State(Scope.Benchmark) 23 | public abstract class QueueBenchmark { 24 | @Param(value={"11","12","21","22","23","24","25","31","32","33","41","42"}) 25 | protected int queueType; 26 | @Param(value={"17"}) 27 | protected int queueScale; 28 | protected static Queue q; 29 | 30 | @Setup(Level.Trial) 31 | public void createQueue() 32 | { 33 | q = SPSCQueueFactory.createQueue(queueType, queueScale); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /libtest/src/main/java/psy/lob/saw/queues/benchmarks/jmh/SingleThreadedOffer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Lincheck - Linearizability checker 3 | * 4 | * Copyright (C) 2015-2022 Devexperts, LLC 5 | * Copyright (C) 2023 Devexperts Ireland Limited 6 | * 7 | * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. 8 | * If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | 11 | package psy.lob.saw.queues.benchmarks.jmh; 12 | 13 | import java.util.Queue; 14 | import java.util.concurrent.TimeUnit; 15 | 16 | import org.openjdk.jmh.annotations.BenchmarkMode; 17 | import org.openjdk.jmh.annotations.GenerateMicroBenchmark; 18 | import org.openjdk.jmh.annotations.Level; 19 | import org.openjdk.jmh.annotations.Measurement; 20 | import org.openjdk.jmh.annotations.Mode; 21 | import org.openjdk.jmh.annotations.OperationsPerInvocation; 22 | import org.openjdk.jmh.annotations.OutputTimeUnit; 23 | import org.openjdk.jmh.annotations.Scope; 24 | import org.openjdk.jmh.annotations.Setup; 25 | import org.openjdk.jmh.annotations.State; 26 | import org.openjdk.jmh.annotations.Warmup; 27 | 28 | @OutputTimeUnit(TimeUnit.NANOSECONDS) 29 | @BenchmarkMode({Mode.AverageTime}) 30 | @Warmup(iterations = 3, time = 1, timeUnit = TimeUnit.SECONDS) 31 | @Measurement(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS) 32 | @State(Scope.Thread) 33 | public class SingleThreadedOffer extends QueueBenchmark 34 | { 35 | public static final int CAPACITY = 1 << 15; 36 | public static final Integer TOKEN = 1; 37 | 38 | 39 | @Setup(Level.Invocation) 40 | public void clear() 41 | { 42 | q.clear(); 43 | } 44 | 45 | @GenerateMicroBenchmark 46 | @OperationsPerInvocation(CAPACITY) 47 | public void offer() 48 | { 49 | final Queue lq = q; 50 | for (int i = 0; i < CAPACITY; i++) 51 | { 52 | lq.offer(TOKEN); 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /libtest/src/main/java/psy/lob/saw/queues/benchmarks/jmh/SingleThreadedPoll.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Lincheck - Linearizability checker 3 | * 4 | * Copyright (C) 2015-2022 Devexperts, LLC 5 | * Copyright (C) 2023 Devexperts Ireland Limited 6 | * 7 | * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. 8 | * If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | 11 | package psy.lob.saw.queues.benchmarks.jmh; 12 | 13 | import java.util.Queue; 14 | import java.util.concurrent.TimeUnit; 15 | 16 | import org.openjdk.jmh.annotations.BenchmarkMode; 17 | import org.openjdk.jmh.annotations.GenerateMicroBenchmark; 18 | import org.openjdk.jmh.annotations.Level; 19 | import org.openjdk.jmh.annotations.Measurement; 20 | import org.openjdk.jmh.annotations.Mode; 21 | import org.openjdk.jmh.annotations.OperationsPerInvocation; 22 | import org.openjdk.jmh.annotations.OutputTimeUnit; 23 | import org.openjdk.jmh.annotations.Scope; 24 | import org.openjdk.jmh.annotations.Setup; 25 | import org.openjdk.jmh.annotations.State; 26 | import org.openjdk.jmh.annotations.Warmup; 27 | 28 | @OutputTimeUnit(TimeUnit.NANOSECONDS) 29 | @BenchmarkMode({Mode.AverageTime}) 30 | @Warmup(iterations = 3, time = 1, timeUnit = TimeUnit.SECONDS) 31 | @Measurement(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS) 32 | @State(Scope.Thread) 33 | public class SingleThreadedPoll extends QueueBenchmark 34 | { 35 | public static final int CAPACITY = 1 << 14; 36 | public static final Integer TOKEN = 1; 37 | 38 | @Setup(Level.Invocation) 39 | public void fill() 40 | { 41 | for( int i=0; i lq = q; 52 | for (int i = 0; i < CAPACITY; i++) 53 | { 54 | lq.poll(); 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /libtest/src/main/java/psy/lob/saw/queues/common/CircularArrayQueue1.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Lincheck - Linearizability checker 3 | * 4 | * Copyright (C) 2015-2022 Devexperts, LLC 5 | * Copyright (C) 2023 Devexperts Ireland Limited 6 | * 7 | * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. 8 | * If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | 11 | package psy.lob.saw.queues.common; 12 | 13 | import java.util.AbstractQueue; 14 | 15 | public abstract class CircularArrayQueue1 extends AbstractQueue { 16 | private final E[] buffer; 17 | 18 | @SuppressWarnings("unchecked") 19 | public CircularArrayQueue1(int capacity) { 20 | buffer = (E[]) new Object[capacity]; 21 | } 22 | 23 | protected final void spElement(int offset, final E e) { 24 | buffer[offset] = e; 25 | } 26 | 27 | protected final E lpElement(final int offset) { 28 | return buffer[offset]; 29 | } 30 | 31 | protected final int calcOffset(final long index) { 32 | return (int) (index % buffer.length); 33 | } 34 | 35 | protected final int capacity() { 36 | return buffer.length; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /libtest/src/main/java/psy/lob/saw/queues/common/CircularArrayQueue2.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Lincheck - Linearizability checker 3 | * 4 | * Copyright (C) 2015-2022 Devexperts, LLC 5 | * Copyright (C) 2023 Devexperts Ireland Limited 6 | * 7 | * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. 8 | * If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | 11 | package psy.lob.saw.queues.common; 12 | 13 | import java.util.AbstractQueue; 14 | 15 | public abstract class CircularArrayQueue2 extends AbstractQueue { 16 | private final int capacity; 17 | private final int mask; 18 | private final E[] buffer; 19 | 20 | @SuppressWarnings("unchecked") 21 | public CircularArrayQueue2(int capacity) { 22 | this.capacity = Pow2.findNextPositivePowerOfTwo(capacity); 23 | mask = capacity() - 1; 24 | buffer = (E[]) new Object[capacity]; 25 | } 26 | 27 | protected final void spElement(int offset, final E e) { 28 | buffer[offset] = e; 29 | } 30 | 31 | protected final E lpElement(final int offset) { 32 | return buffer[offset]; 33 | } 34 | 35 | protected final int calcOffset(final long index) { 36 | // was: return (int) (index % buffer.length); 37 | return ((int) index) & mask; 38 | } 39 | 40 | protected final int capacity() { 41 | // was: return buffer.length 42 | return capacity; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /libtest/src/main/java/psy/lob/saw/queues/common/CircularArrayQueue3.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Lincheck - Linearizability checker 3 | * 4 | * Copyright (C) 2015-2022 Devexperts, LLC 5 | * Copyright (C) 2023 Devexperts Ireland Limited 6 | * 7 | * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. 8 | * If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | 11 | package psy.lob.saw.queues.common; 12 | 13 | import java.util.AbstractQueue; 14 | abstract class CircularArrayQueue3PrePad extends AbstractQueue { 15 | protected long p00, p01, p02, p03, p04, p05, p06, p07; 16 | protected long p10, p11, p12, p13, p14, p15, p16, p17; 17 | } 18 | 19 | public abstract class CircularArrayQueue3 extends CircularArrayQueue3PrePad { 20 | private final int capacity; 21 | private final int mask; 22 | private final E[] buffer; 23 | 24 | @SuppressWarnings("unchecked") 25 | public CircularArrayQueue3(int capacity) { 26 | this.capacity = Pow2.findNextPositivePowerOfTwo(capacity); 27 | mask = capacity() - 1; 28 | buffer = (E[]) new Object[capacity]; 29 | } 30 | 31 | protected final void spElement(int offset, final E e) { 32 | buffer[offset] = e; 33 | } 34 | 35 | protected final E lpElement(final int offset) { 36 | return buffer[offset]; 37 | } 38 | 39 | protected final int calcOffset(final long index) { 40 | return ((int) index) & mask; 41 | } 42 | 43 | protected final int capacity() { 44 | return capacity; 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /libtest/src/main/java/psy/lob/saw/queues/common/Pow2.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Lincheck - Linearizability checker 3 | * 4 | * Copyright (C) 2015-2022 Devexperts, LLC 5 | * Copyright (C) 2023 Devexperts Ireland Limited 6 | * 7 | * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. 8 | * If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | 11 | package psy.lob.saw.queues.common; 12 | 13 | public class Pow2 { 14 | public static int findNextPositivePowerOfTwo(final int value) { 15 | return 1 << (32 - Integer.numberOfLeadingZeros(value - 1)); 16 | } 17 | public static boolean isPowerOf2(final int value){ 18 | return (value & (value-1)) == 0; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /libtest/src/main/java/psy/lob/saw/queues/common/UnsafeAccess.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Lincheck - Linearizability checker 3 | * 4 | * Copyright (C) 2015-2022 Devexperts, LLC 5 | * Copyright (C) 2023 Devexperts Ireland Limited 6 | * 7 | * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. 8 | * If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | 11 | package psy.lob.saw.queues.common; 12 | 13 | import java.lang.reflect.Field; 14 | 15 | import sun.misc.Unsafe; 16 | 17 | public class UnsafeAccess { 18 | public static final Unsafe UNSAFE; 19 | static { 20 | try { 21 | Field field = Unsafe.class.getDeclaredField("theUnsafe"); 22 | field.setAccessible(true); 23 | UNSAFE = (Unsafe) field.get(null); 24 | } catch (Exception e) { 25 | throw new RuntimeException(e); 26 | } 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /libtest/src/main/java/psy/lob/saw/queues/lamport/VolatileLongCell.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Lincheck - Linearizability checker 3 | * 4 | * Copyright (C) 2015-2022 Devexperts, LLC 5 | * Copyright (C) 2023 Devexperts Ireland Limited 6 | * 7 | * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. 8 | * If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | 11 | package psy.lob.saw.queues.lamport; 12 | 13 | import psy.lob.saw.queues.common.UnsafeAccess; 14 | 15 | 16 | abstract class VolatileLongCellPrePad{long p0,p1,p2,p3,p4,p5,p6;} 17 | abstract class VolatileLongCellValue extends VolatileLongCellPrePad { 18 | protected volatile long value; 19 | } 20 | public final class VolatileLongCell extends VolatileLongCellValue { 21 | long p10,p11,p12,p13,p14,p15,p16; 22 | private final static long VALUE_OFFSET; 23 | static { 24 | try { 25 | VALUE_OFFSET = UnsafeAccess.UNSAFE.objectFieldOffset(VolatileLongCellValue.class.getDeclaredField("value")); 26 | } catch (NoSuchFieldException e) { 27 | throw new RuntimeException(e); 28 | } 29 | } 30 | public VolatileLongCell(){ 31 | this(0L); 32 | } 33 | public VolatileLongCell(long v){ 34 | lazySet(v); 35 | } 36 | public void lazySet(long v) { 37 | UnsafeAccess.UNSAFE.putOrderedLong(this, VALUE_OFFSET, v); 38 | } 39 | public void set(long v){ 40 | this.value = v; 41 | } 42 | public long get(){ 43 | return this.value; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /libtest/src/main/java/psy/lob/saw/queues/thompson/LongCell.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Lincheck - Linearizability checker 3 | * 4 | * Copyright (C) 2015-2022 Devexperts, LLC 5 | * Copyright (C) 2023 Devexperts Ireland Limited 6 | * 7 | * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. 8 | * If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | 11 | package psy.lob.saw.queues.thompson; 12 | 13 | abstract class LongCellP0{long p0,p1,p2,p3,p4,p5,p6;} 14 | abstract class LongCellValue extends LongCellP0 { 15 | protected long value; 16 | } 17 | public final class LongCell extends LongCellValue { 18 | long p10,p11,p12,p13,p14,p15,p16; 19 | public void set(long v){ this.value = v; } 20 | public long get(){ return this.value; } 21 | } 22 | -------------------------------------------------------------------------------- /libtest/src/main/java/romix/scala/None.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Lincheck - Linearizability checker 3 | * 4 | * Copyright (C) 2015-2022 Devexperts, LLC 5 | * Copyright (C) 2023 Devexperts Ireland Limited 6 | * 7 | * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. 8 | * If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | 11 | package romix.scala; 12 | 13 | /** 14 | * Mimic None in Scala 15 | * 16 | * @author Roman Levenstein 17 | * 18 | * @param 19 | */ 20 | public class None extends Option { 21 | 22 | } 23 | -------------------------------------------------------------------------------- /libtest/src/main/java/romix/scala/Option.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Lincheck - Linearizability checker 3 | * 4 | * Copyright (C) 2015-2022 Devexperts, LLC 5 | * Copyright (C) 2023 Devexperts Ireland Limited 6 | * 7 | * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. 8 | * If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | 11 | package romix.scala; 12 | 13 | /** 14 | * Mimic Option in Scala 15 | * 16 | * @author Roman Levenstein 17 | * 18 | * @param 19 | */ 20 | @SuppressWarnings({"rawtypes", "unchecked"}) 21 | public class Option { 22 | static None none = new None(); 23 | public static Option makeOption(V o){ 24 | if(o!=null) 25 | return new Some(o); 26 | else 27 | return (Option)none; 28 | } 29 | 30 | public static Option makeOption(){ 31 | return (Option)none; 32 | } 33 | public boolean nonEmpty () { 34 | return false; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /libtest/src/main/java/romix/scala/Some.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Lincheck - Linearizability checker 3 | * 4 | * Copyright (C) 2015-2022 Devexperts, LLC 5 | * Copyright (C) 2023 Devexperts Ireland Limited 6 | * 7 | * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. 8 | * If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | 11 | package romix.scala; 12 | 13 | /** 14 | * Mimic Some in Scala 15 | * 16 | * @author Roman Levenstein 17 | * 18 | * @param 19 | */ 20 | public class Some extends Option { 21 | final V value; 22 | public Some(V v) { 23 | value = v; 24 | } 25 | 26 | public V get() { 27 | return value; 28 | } 29 | 30 | public boolean nonEmpty () { 31 | return value != null; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /libtest/src/main/java/romix/scala/collection/concurrent/BasicNode.java: -------------------------------------------------------------------------------- 1 | /* __ *\ 2 | ** ________ ___ / / ___ Scala API ** 3 | ** / __/ __// _ | / / / _ | (c) 2003-2012, LAMP/EPFL ** 4 | ** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** 5 | ** /____/\___/_/ |_/____/_/ | | ** 6 | ** |/ ** 7 | \* */ 8 | 9 | package romix.scala.collection.concurrent; 10 | 11 | abstract class BasicNode { 12 | 13 | public abstract String string(int lev); 14 | 15 | } 16 | -------------------------------------------------------------------------------- /libtest/src/main/java/romix/scala/collection/concurrent/CNodeBase.java: -------------------------------------------------------------------------------- 1 | /* __ *\ 2 | ** ________ ___ / / ___ Scala API ** 3 | ** / __/ __// _ | / / / _ | (c) 2003-2012, LAMP/EPFL ** 4 | ** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** 5 | ** /____/\___/_/ |_/____/_/ | | ** 6 | ** |/ ** 7 | \* */ 8 | 9 | package romix.scala.collection.concurrent; 10 | 11 | import java.util.concurrent.atomic.AtomicIntegerFieldUpdater; 12 | 13 | 14 | 15 | abstract class CNodeBase extends MainNode { 16 | 17 | public static final AtomicIntegerFieldUpdater updater = AtomicIntegerFieldUpdater.newUpdater(CNodeBase.class, "csize"); 18 | 19 | public volatile int csize = -1; 20 | 21 | public boolean CAS_SIZE(int oldval, int nval) { 22 | return updater.compareAndSet(this, oldval, nval); 23 | } 24 | 25 | public void WRITE_SIZE(int nval) { 26 | updater.set(this, nval); 27 | } 28 | 29 | public int READ_SIZE() { 30 | return updater.get(this); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /libtest/src/main/java/romix/scala/collection/concurrent/Gen.java: -------------------------------------------------------------------------------- 1 | /* __ *\ 2 | ** ________ ___ / / ___ Scala API ** 3 | ** / __/ __// _ | / / / _ | (c) 2003-2012, LAMP/EPFL ** 4 | ** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** 5 | ** /____/\___/_/ |_/____/_/ | | ** 6 | ** |/ ** 7 | \* */ 8 | 9 | package romix.scala.collection.concurrent; 10 | 11 | final class Gen { 12 | } 13 | -------------------------------------------------------------------------------- /libtest/src/main/java/romix/scala/collection/concurrent/INodeBase.java: -------------------------------------------------------------------------------- 1 | /* __ *\ 2 | ** ________ ___ / / ___ Scala API ** 3 | ** / __/ __// _ | / / / _ | (c) 2003-2012, LAMP/EPFL ** 4 | ** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** 5 | ** /____/\___/_/ |_/____/_/ | | ** 6 | ** |/ ** 7 | \* */ 8 | 9 | package romix.scala.collection.concurrent; 10 | 11 | import java.util.concurrent.atomic.AtomicReferenceFieldUpdater; 12 | 13 | 14 | 15 | abstract class INodeBase extends BasicNode { 16 | 17 | public static final AtomicReferenceFieldUpdater updater = AtomicReferenceFieldUpdater.newUpdater(INodeBase.class, MainNode.class, "mainnode"); 18 | 19 | public static final Object RESTART = new Object(); 20 | 21 | public volatile MainNode mainnode = null; 22 | 23 | public final Gen gen; 24 | 25 | public INodeBase(Gen generation) { 26 | gen = generation; 27 | } 28 | 29 | public BasicNode prev() { 30 | return null; 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /libtest/src/main/java/romix/scala/collection/concurrent/MainNode.java: -------------------------------------------------------------------------------- 1 | /* __ *\ 2 | ** ________ ___ / / ___ Scala API ** 3 | ** / __/ __// _ | / / / _ | (c) 2003-2012, LAMP/EPFL ** 4 | ** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** 5 | ** /____/\___/_/ |_/____/_/ | | ** 6 | ** |/ ** 7 | \* */ 8 | 9 | package romix.scala.collection.concurrent; 10 | 11 | import java.util.concurrent.atomic.AtomicReferenceFieldUpdater; 12 | 13 | abstract class MainNode extends BasicNode { 14 | 15 | public static final AtomicReferenceFieldUpdater updater = AtomicReferenceFieldUpdater.newUpdater (MainNode.class, MainNode.class, "prev"); 16 | 17 | public volatile MainNode prev = null; 18 | 19 | public abstract int cachedSize (Object ct); 20 | 21 | public boolean CAS_PREV (MainNode oldval, MainNode nval) { 22 | return updater.compareAndSet (this, oldval, nval); 23 | } 24 | 25 | public void WRITE_PREV (MainNode nval) { 26 | updater.set (this, nval); 27 | } 28 | 29 | // do we need this? unclear in the javadocs... 30 | // apparently not - volatile reads are supposed to be safe 31 | // regardless of whether there are concurrent ARFU updates 32 | public MainNode READ_PREV () { 33 | return updater.get (this); 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /libtest/src/main/java/romix/scala/collection/concurrent/Pair.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Lincheck - Linearizability checker 3 | * 4 | * Copyright (C) 2015-2022 Devexperts, LLC 5 | * Copyright (C) 2023 Devexperts Ireland Limited 6 | * 7 | * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. 8 | * If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | 11 | package romix.scala.collection.concurrent; 12 | 13 | import java.util.Map; 14 | 15 | /*** 16 | * Helper class simulating a tuple of 2 elements in Scala 17 | * 18 | * @author Roman Levenstein 19 | * 20 | * @param 21 | * @param 22 | */ 23 | public class Pair implements Map.Entry { 24 | 25 | final K k; 26 | final V v; 27 | 28 | Pair (K k, V v) { 29 | this.k = k; 30 | this.v = v; 31 | } 32 | 33 | @Override 34 | public K getKey () { 35 | // TODO Auto-generated method stub 36 | return k; 37 | } 38 | 39 | @Override 40 | public V getValue () { 41 | // TODO Auto-generated method stub 42 | return v; 43 | } 44 | 45 | @Override 46 | public V setValue (V value) { 47 | throw new RuntimeException ("Operation not supported"); 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /libtest/src/main/java/tests/custom/counter/Counter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Lincheck - Linearizability checker 3 | * 4 | * Copyright (C) 2015-2022 Devexperts, LLC 5 | * Copyright (C) 2023 Devexperts Ireland Limited 6 | * 7 | * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. 8 | * If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | 11 | package tests.custom.counter; 12 | 13 | public interface Counter { 14 | public int incrementAndGet(); 15 | } 16 | -------------------------------------------------------------------------------- /libtest/src/main/java/tests/custom/counter/CounterCorrect2.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Lincheck - Linearizability checker 3 | * 4 | * Copyright (C) 2015-2022 Devexperts, LLC 5 | * Copyright (C) 2023 Devexperts Ireland Limited 6 | * 7 | * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. 8 | * If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | 11 | package tests.custom.counter; 12 | 13 | import java.util.concurrent.atomic.AtomicInteger; 14 | 15 | public class CounterCorrect2 implements Counter { 16 | private AtomicInteger c; 17 | 18 | public CounterCorrect2() { 19 | c = new AtomicInteger(); 20 | } 21 | 22 | @Override 23 | public synchronized int incrementAndGet() { 24 | return c.incrementAndGet(); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /libtest/src/main/java/tests/custom/counter/CounterGet.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Lincheck - Linearizability checker 3 | * 4 | * Copyright (C) 2015-2022 Devexperts, LLC 5 | * Copyright (C) 2023 Devexperts Ireland Limited 6 | * 7 | * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. 8 | * If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | 11 | package tests.custom.counter; 12 | 13 | public class CounterGet{ 14 | private int c; 15 | 16 | public CounterGet() { 17 | c = 0; 18 | } 19 | 20 | public int get() { 21 | return c; 22 | } 23 | 24 | public synchronized int incrementAndGet() { 25 | return ++c; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /libtest/src/main/java/tests/custom/counter/CounterWrong0.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Lincheck - Linearizability checker 3 | * 4 | * Copyright (C) 2015-2022 Devexperts, LLC 5 | * Copyright (C) 2023 Devexperts Ireland Limited 6 | * 7 | * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. 8 | * If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | 11 | package tests.custom.counter; 12 | 13 | public class CounterWrong0 implements Counter { 14 | private int c; 15 | 16 | public CounterWrong0() { 17 | c = 0; 18 | } 19 | 20 | @Override 21 | public int incrementAndGet() { 22 | // c++; 23 | // return c; 24 | return ++c; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /libtest/src/main/java/tests/custom/counter/CounterWrong1.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Lincheck - Linearizability checker 3 | * 4 | * Copyright (C) 2015-2022 Devexperts, LLC 5 | * Copyright (C) 2023 Devexperts Ireland Limited 6 | * 7 | * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. 8 | * If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | 11 | package tests.custom.counter; 12 | 13 | public class CounterWrong1 implements Counter { 14 | private int c; 15 | 16 | public CounterWrong1() { 17 | c = 0; 18 | } 19 | 20 | @Override 21 | public int incrementAndGet() { 22 | c++; 23 | return c; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /libtest/src/main/java/tests/custom/counter/CounterWrong2.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Lincheck - Linearizability checker 3 | * 4 | * Copyright (C) 2015-2022 Devexperts, LLC 5 | * Copyright (C) 2023 Devexperts Ireland Limited 6 | * 7 | * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. 8 | * If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | 11 | package tests.custom.counter; 12 | 13 | public class CounterWrong2 implements Counter { 14 | private int c; 15 | 16 | public CounterWrong2() { 17 | c = 0; 18 | } 19 | 20 | @Override 21 | public int incrementAndGet() { 22 | return ++c; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /libtest/src/main/java/tests/custom/queue/Queue.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Lincheck - Linearizability checker 3 | * 4 | * Copyright (C) 2015-2022 Devexperts, LLC 5 | * Copyright (C) 2023 Devexperts Ireland Limited 6 | * 7 | * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. 8 | * If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | 11 | package tests.custom.queue; 12 | 13 | public interface Queue { 14 | public void put(int x) throws QueueFullException; 15 | public int get() throws QueueEmptyException; 16 | } 17 | -------------------------------------------------------------------------------- /libtest/src/main/java/tests/custom/queue/QueueEmptyException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Lincheck - Linearizability checker 3 | * 4 | * Copyright (C) 2015-2022 Devexperts, LLC 5 | * Copyright (C) 2023 Devexperts Ireland Limited 6 | * 7 | * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. 8 | * If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | 11 | package tests.custom.queue; 12 | 13 | public class QueueEmptyException extends Exception { 14 | public QueueEmptyException(String message) { 15 | super(message); 16 | } 17 | 18 | public QueueEmptyException() { 19 | 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /libtest/src/main/java/tests/custom/queue/QueueFullException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Lincheck - Linearizability checker 3 | * 4 | * Copyright (C) 2015-2022 Devexperts, LLC 5 | * Copyright (C) 2023 Devexperts Ireland Limited 6 | * 7 | * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. 8 | * If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | 11 | package tests.custom.queue; 12 | 13 | public class QueueFullException extends Exception { 14 | public QueueFullException(String message) { 15 | super(message); 16 | } 17 | 18 | public QueueFullException() { 19 | 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /libtest/src/main/java/tests/custom/queue/QueueSynchronized.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Lincheck - Linearizability checker 3 | * 4 | * Copyright (C) 2015-2022 Devexperts, LLC 5 | * Copyright (C) 2023 Devexperts Ireland Limited 6 | * 7 | * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. 8 | * If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | 11 | package tests.custom.queue; 12 | 13 | import java.util.Arrays; 14 | 15 | public class QueueSynchronized implements Queue { 16 | private int indGet; 17 | private int indPut; 18 | private int countElements; 19 | 20 | private int[] items; 21 | 22 | private int inc(int i) { 23 | return (++i == items.length ? 0 : i); 24 | } 25 | 26 | public QueueSynchronized(int capacity) { 27 | items = new int[capacity]; 28 | 29 | indPut = 0; 30 | indGet = 0; 31 | countElements = 0; 32 | 33 | } 34 | 35 | @Override 36 | public synchronized void put(int x) throws QueueFullException { 37 | if (countElements == items.length) { 38 | throw new QueueFullException(); 39 | } 40 | items[indPut] = x; 41 | indPut = inc(indPut); 42 | countElements++; 43 | } 44 | 45 | @Override 46 | public synchronized int get() throws QueueEmptyException { 47 | if (countElements == 0) { 48 | throw new QueueEmptyException(); 49 | } 50 | int ret = items[indGet]; 51 | indGet = inc(indGet); 52 | countElements--; 53 | return ret; 54 | } 55 | 56 | @Override 57 | public String toString() { 58 | return "QueueWithoutAnySync{" + 59 | "indGet=" + indGet + 60 | ", indPut=" + indPut + 61 | ", countElements=" + countElements + 62 | ", items=" + Arrays.toString(items) + 63 | '}'; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /libtest/src/main/java/tests/custom/queue/QueueWrong1.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Lincheck - Linearizability checker 3 | * 4 | * Copyright (C) 2015-2022 Devexperts, LLC 5 | * Copyright (C) 2023 Devexperts Ireland Limited 6 | * 7 | * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. 8 | * If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | 11 | package tests.custom.queue; 12 | 13 | import java.util.Arrays; 14 | 15 | public class QueueWrong1 implements Queue { 16 | private int indGet; 17 | private int indPut; 18 | private int countElements; 19 | 20 | private int[] items; 21 | 22 | private int inc(int i) { 23 | return (++i == items.length ? 0 : i); 24 | } 25 | 26 | public QueueWrong1(int capacity) { 27 | items = new int[capacity]; 28 | 29 | indPut = 0; 30 | indGet = 0; 31 | countElements = 0; 32 | 33 | } 34 | 35 | @Override 36 | public void put(int x) throws QueueFullException { 37 | if (countElements == items.length) { 38 | throw new QueueFullException(); 39 | } 40 | items[indPut] = x; 41 | indPut = inc(indPut); 42 | countElements++; 43 | } 44 | 45 | @Override 46 | public int get() throws QueueEmptyException { 47 | if (countElements == 0) { 48 | throw new QueueEmptyException(); 49 | } 50 | int ret = items[indGet]; 51 | indGet = inc(indGet); 52 | countElements--; 53 | return ret; 54 | } 55 | 56 | @Override 57 | public String toString() { 58 | return "QueueWithoutAnySync{" + 59 | "indGet=" + indGet + 60 | ", indPut=" + indPut + 61 | ", countElements=" + countElements + 62 | ", items=" + Arrays.toString(items) + 63 | '}'; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /libtest/src/main/java/tests/custom/queue/QueueWrong2.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Lincheck - Linearizability checker 3 | * 4 | * Copyright (C) 2015-2022 Devexperts, LLC 5 | * Copyright (C) 2023 Devexperts Ireland Limited 6 | * 7 | * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. 8 | * If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | 11 | package tests.custom.queue; 12 | 13 | import java.util.Arrays; 14 | 15 | public class QueueWrong2 implements Queue { 16 | private int indGet; 17 | private int indPut; 18 | private int countElements; 19 | 20 | private int[] items; 21 | 22 | private int inc(int i) { 23 | return (++i == items.length ? 0 : i); 24 | } 25 | 26 | public QueueWrong2(int capacity) { 27 | items = new int[capacity]; 28 | 29 | indPut = 0; 30 | indGet = 0; 31 | countElements = 0; 32 | 33 | } 34 | 35 | @Override 36 | public synchronized void put(int x) throws QueueFullException { 37 | if (countElements == items.length) { 38 | throw new QueueFullException(); 39 | } 40 | items[indPut] = x; 41 | indPut = inc(indPut); 42 | countElements++; 43 | } 44 | 45 | @Override 46 | public int get() throws QueueEmptyException { 47 | if (countElements == 0) { 48 | throw new QueueEmptyException(); 49 | } 50 | int ret = items[indGet]; 51 | indGet = inc(indGet); 52 | countElements--; 53 | return ret; 54 | } 55 | 56 | @Override 57 | public String toString() { 58 | return "QueueWithoutAnySync{" + 59 | "indGet=" + indGet + 60 | ", indPut=" + indPut + 61 | ", countElements=" + countElements + 62 | ", items=" + Arrays.toString(items) + 63 | '}'; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /libtest/src/main/java/tests/custom/queue/QueueWrong3.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Lincheck - Linearizability checker 3 | * 4 | * Copyright (C) 2015-2022 Devexperts, LLC 5 | * Copyright (C) 2023 Devexperts Ireland Limited 6 | * 7 | * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. 8 | * If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | 11 | package tests.custom.queue; 12 | 13 | import java.util.Arrays; 14 | 15 | public class QueueWrong3 implements Queue { 16 | private int indGet; 17 | private int indPut; 18 | private int countElements; 19 | 20 | private int[] items; 21 | 22 | private int inc(int i) { 23 | return (++i == items.length ? 0 : i); 24 | } 25 | 26 | public QueueWrong3(int capacity) { 27 | items = new int[capacity]; 28 | 29 | indPut = 0; 30 | indGet = 0; 31 | countElements = 0; 32 | 33 | } 34 | 35 | @Override 36 | public void put(int x) throws QueueFullException { 37 | if (countElements == items.length) { 38 | throw new QueueFullException(); 39 | } 40 | items[indPut] = x; 41 | indPut = inc(indPut); 42 | countElements++; 43 | } 44 | 45 | @Override 46 | public synchronized int get() throws QueueEmptyException { 47 | if (countElements == 0) { 48 | throw new QueueEmptyException(); 49 | } 50 | int ret = items[indGet]; 51 | indGet = inc(indGet); 52 | countElements--; 53 | return ret; 54 | } 55 | 56 | @Override 57 | public String toString() { 58 | return "QueueWithoutAnySync{" + 59 | "indGet=" + indGet + 60 | ", indPut=" + indPut + 61 | ", countElements=" + countElements + 62 | ", items=" + Arrays.toString(items) + 63 | '}'; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /libtest/src/main/java/tests/custom/transfer/Accounts.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Lincheck - Linearizability checker 3 | * 4 | * Copyright (C) 2015-2022 Devexperts, LLC 5 | * Copyright (C) 2023 Devexperts Ireland Limited 6 | * 7 | * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. 8 | * If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | 11 | package tests.custom.transfer; 12 | 13 | public interface Accounts { 14 | public Integer getAmount(int id); 15 | public void setAmount(int id, int value); 16 | public void transfer(int id1, int id2, int value); 17 | } 18 | -------------------------------------------------------------------------------- /libtest/src/main/java/tests/custom/transfer/AccountsWrong1.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Lincheck - Linearizability checker 3 | * 4 | * Copyright (C) 2015-2022 Devexperts, LLC 5 | * Copyright (C) 2023 Devexperts Ireland Limited 6 | * 7 | * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. 8 | * If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | 11 | package tests.custom.transfer; 12 | 13 | import java.util.HashMap; 14 | import java.util.Map; 15 | 16 | public class AccountsWrong1 implements Accounts { 17 | 18 | Map data; 19 | 20 | public AccountsWrong1() { 21 | data = new HashMap<>(); 22 | } 23 | 24 | @Override 25 | public Integer getAmount(int id) { 26 | if (data.containsKey(id)) { 27 | return data.get(id); 28 | } else { 29 | return 0; 30 | } 31 | } 32 | 33 | @Override 34 | public void setAmount(int id, int value) { 35 | data.put(id, value); 36 | } 37 | 38 | @Override 39 | public synchronized void transfer(int id1, int id2, int value) { 40 | if (id1 == id2) return; 41 | Integer v1 = data.get(id1); 42 | Integer v2 = data.get(id2); 43 | if (v1 == null) v1 = 0; 44 | if (v2 == null) v2 = 0; 45 | v1 -= value; 46 | v2 += value; 47 | data.put(id1, v1); 48 | // try { 49 | // Thread.sleep(10); 50 | // } catch (InterruptedException e) { 51 | // e.printStackTrace(); 52 | // } 53 | data.put(id2, v2); 54 | } 55 | 56 | @Override 57 | public String toString() { 58 | return "AccountsSynchronized{" + 59 | "data=" + data + 60 | '}'; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /libtest/src/main/java/tests/custom/transfer/AccountsWrong2.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Lincheck - Linearizability checker 3 | * 4 | * Copyright (C) 2015-2022 Devexperts, LLC 5 | * Copyright (C) 2023 Devexperts Ireland Limited 6 | * 7 | * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. 8 | * If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | 11 | package tests.custom.transfer; 12 | 13 | import java.util.HashMap; 14 | import java.util.Map; 15 | 16 | public class AccountsWrong2 implements Accounts { 17 | 18 | Map data; 19 | 20 | public AccountsWrong2() { 21 | data = new HashMap<>(); 22 | } 23 | 24 | @Override 25 | public Integer getAmount(int id) { 26 | if (data.containsKey(id)) { 27 | return data.get(id); 28 | } else { 29 | return 0; 30 | } 31 | } 32 | 33 | @Override 34 | public synchronized void setAmount(int id, int value) { 35 | data.put(id, value); 36 | } 37 | 38 | @Override 39 | public void transfer(int id1, int id2, int value) { 40 | if (id1 == id2) return; 41 | Integer v1 = data.get(id1); 42 | Integer v2 = data.get(id2); 43 | if (v1 == null) v1 = 0; 44 | if (v2 == null) v2 = 0; 45 | v1 -= value; 46 | v2 += value; 47 | data.put(id1, v1); 48 | // try { 49 | // Thread.sleep(10); 50 | // } catch (InterruptedException e) { 51 | // e.printStackTrace(); 52 | // } 53 | data.put(id2, v2); 54 | } 55 | 56 | @Override 57 | public String toString() { 58 | return "AccountsSynchronized{" + 59 | "data=" + data + 60 | '}'; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /libtest/src/main/java/tests/custom/transfer/AccountsWrong3.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Lincheck - Linearizability checker 3 | * 4 | * Copyright (C) 2015-2022 Devexperts, LLC 5 | * Copyright (C) 2023 Devexperts Ireland Limited 6 | * 7 | * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. 8 | * If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | 11 | package tests.custom.transfer; 12 | 13 | import java.util.HashMap; 14 | import java.util.Map; 15 | 16 | public class AccountsWrong3 implements Accounts { 17 | 18 | Map data; 19 | 20 | public AccountsWrong3() { 21 | data = new HashMap<>(); 22 | } 23 | 24 | @Override 25 | public Integer getAmount(int id) { 26 | if (data.containsKey(id)) { 27 | return data.get(id); 28 | } else { 29 | return 0; 30 | } 31 | } 32 | 33 | @Override 34 | public void setAmount(int id, int value) { 35 | data.put(id, value); 36 | } 37 | 38 | @Override 39 | public void transfer(int id1, int id2, int value) { 40 | if (id1 == id2) return; 41 | Integer v1 = data.get(id1); 42 | Integer v2 = data.get(id2); 43 | if (v1 == null) v1 = 0; 44 | if (v2 == null) v2 = 0; 45 | v1 -= value; 46 | v2 += value; 47 | data.put(id1, v1); 48 | // try { 49 | // Thread.sleep(10); 50 | // } catch (InterruptedException e) { 51 | // e.printStackTrace(); 52 | // } 53 | data.put(id2, v2); 54 | } 55 | 56 | @Override 57 | public String toString() { 58 | return "AccountsSynchronized{" + 59 | "data=" + data + 60 | '}'; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /libtest/src/main/java/tests/custom/transfer/AccountsWrong4.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Lincheck - Linearizability checker 3 | * 4 | * Copyright (C) 2015-2022 Devexperts, LLC 5 | * Copyright (C) 2023 Devexperts Ireland Limited 6 | * 7 | * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. 8 | * If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | 11 | package tests.custom.transfer; 12 | 13 | import java.util.HashMap; 14 | import java.util.Map; 15 | 16 | public class AccountsWrong4 implements Accounts { 17 | 18 | Map data; 19 | 20 | public AccountsWrong4() { 21 | data = new HashMap<>(1); 22 | } 23 | 24 | // This operation is not synchronized with others 25 | @Override 26 | public Integer getAmount(int id) { 27 | return data.getOrDefault(id, 0); 28 | } 29 | 30 | @Override 31 | public synchronized void setAmount(int id, int value) { 32 | data.put(id, value); 33 | } 34 | 35 | @Override 36 | public synchronized void transfer(int id1, int id2, int value) { 37 | if (id1 == id2) return; 38 | Integer v1 = data.get(id1); 39 | Integer v2 = data.get(id2); 40 | if (v1 == null) v1 = 0; 41 | if (v2 == null) v2 = 0; 42 | v1 -= value; 43 | v2 += value; 44 | data.put(id1, v1); 45 | data.put(id2, v2); 46 | } 47 | 48 | @Override 49 | public String toString() { 50 | return "AccountsSynchronized{" + 51 | "data=" + data + 52 | '}'; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /libtest/src/main/java/thesis_example/Counter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Lincheck - Linearizability checker 3 | * 4 | * Copyright (C) 2015-2022 Devexperts, LLC 5 | * Copyright (C) 2023 Devexperts Ireland Limited 6 | * 7 | * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. 8 | * If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | 11 | package thesis_example; 12 | 13 | public interface Counter { 14 | public int incrementAndGet(); 15 | } 16 | -------------------------------------------------------------------------------- /libtest/src/main/java/thesis_example/CounterCorrect1.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Lincheck - Linearizability checker 3 | * 4 | * Copyright (C) 2015-2022 Devexperts, LLC 5 | * Copyright (C) 2023 Devexperts Ireland Limited 6 | * 7 | * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. 8 | * If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | 11 | package thesis_example; 12 | 13 | public class CounterCorrect1 { 14 | private int c = 0; 15 | 16 | public synchronized int incrementAndGet() { 17 | c++; 18 | return c; 19 | } 20 | 21 | public static void main(String[] args) { 22 | System.out.println(new CounterCorrect1().incrementAndGet()); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /libtest/src/main/java/thesis_example/CounterCorrect2.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Lincheck - Linearizability checker 3 | * 4 | * Copyright (C) 2015-2022 Devexperts, LLC 5 | * Copyright (C) 2023 Devexperts Ireland Limited 6 | * 7 | * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. 8 | * If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | 11 | package thesis_example; 12 | 13 | import java.util.concurrent.atomic.AtomicInteger; 14 | 15 | 16 | public class CounterCorrect2 implements Counter { 17 | private AtomicInteger c; 18 | 19 | public CounterCorrect2() { 20 | c = new AtomicInteger(); 21 | } 22 | 23 | @Override 24 | public synchronized int incrementAndGet() { 25 | return c.incrementAndGet(); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /libtest/src/main/java/thesis_example/CounterWrong1.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Lincheck - Linearizability checker 3 | * 4 | * Copyright (C) 2015-2022 Devexperts, LLC 5 | * Copyright (C) 2023 Devexperts Ireland Limited 6 | * 7 | * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. 8 | * If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | 11 | package thesis_example; 12 | 13 | public class CounterWrong1 implements Counter { 14 | private int c; 15 | 16 | public CounterWrong1() { 17 | c = 0; 18 | } 19 | 20 | @Override 21 | public int incrementAndGet() { 22 | c++; 23 | return c; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /libtest/src/main/java/thesis_example/CounterWrong2.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Lincheck - Linearizability checker 3 | * 4 | * Copyright (C) 2015-2022 Devexperts, LLC 5 | * Copyright (C) 2023 Devexperts Ireland Limited 6 | * 7 | * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. 8 | * If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | 11 | package thesis_example; 12 | 13 | public class CounterWrong2 implements Counter { 14 | private int c; 15 | 16 | public CounterWrong2() { 17 | c = 0; 18 | } 19 | 20 | @Override 21 | public int incrementAndGet() { 22 | return ++c; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /libtest/src/main/java/thesis_example/QueueCorrect.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Lincheck - Linearizability checker 3 | * 4 | * Copyright (C) 2015-2022 Devexperts, LLC 5 | * Copyright (C) 2023 Devexperts Ireland Limited 6 | * 7 | * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. 8 | * If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | 11 | package thesis_example; 12 | 13 | import tests.custom.queue.QueueEmptyException; 14 | import tests.custom.queue.QueueFullException; 15 | 16 | public class QueueCorrect { 17 | private int indGet; 18 | private int indPut; 19 | private int countElements; 20 | 21 | private int[] items; 22 | 23 | private int inc(int i) { 24 | return (++i == items.length ? 0 : i); 25 | } 26 | 27 | public QueueCorrect(int capacity) { 28 | items = new int[capacity]; 29 | 30 | indPut = 0; 31 | indGet = 0; 32 | countElements = 0; 33 | 34 | } 35 | 36 | public synchronized void put(int x) throws QueueFullException { 37 | if (countElements == items.length) { 38 | throw new QueueFullException(); 39 | } 40 | items[indPut] = x; 41 | indPut = inc(indPut); 42 | countElements++; 43 | } 44 | 45 | public synchronized int get() throws QueueEmptyException { 46 | if (countElements == 0) { 47 | throw new QueueEmptyException(); 48 | } 49 | int ret = items[indGet]; 50 | indGet = inc(indGet); 51 | countElements--; 52 | return ret; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /libtest/src/main/java/z/annotation/InternalUse.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013, Landz and its contributors. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package z.annotation; 18 | 19 | import java.lang.annotation.Documented; 20 | import java.lang.annotation.Retention; 21 | import java.lang.annotation.RetentionPolicy; 22 | 23 | @Documented 24 | @Retention(RetentionPolicy.SOURCE) 25 | public @interface InternalUse { 26 | String value() default ""; 27 | } 28 | -------------------------------------------------------------------------------- /libtest/src/main/java/z/annotation/NotThreadSafe.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013, Landz and its contributors. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package z.annotation; 18 | 19 | import java.lang.annotation.Documented; 20 | import java.lang.annotation.Retention; 21 | import java.lang.annotation.RetentionPolicy; 22 | 23 | @Documented 24 | @Retention(RetentionPolicy.SOURCE) 25 | public @interface NotThreadSafe { 26 | String value() default ""; 27 | } 28 | -------------------------------------------------------------------------------- /libtest/src/main/java/z/annotation/PerformanceDegraded.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013, Landz and its contributors. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package z.annotation; 18 | 19 | import java.lang.annotation.Documented; 20 | import java.lang.annotation.Retention; 21 | import java.lang.annotation.RetentionPolicy; 22 | 23 | @Documented 24 | @Retention(RetentionPolicy.SOURCE) 25 | public @interface PerformanceDegraded { 26 | String value() default ""; 27 | } 28 | -------------------------------------------------------------------------------- /libtest/src/main/java/z/annotation/ThreadSafe.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013, Landz and its contributors. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package z.annotation; 18 | 19 | import java.lang.annotation.Documented; 20 | import java.lang.annotation.Retention; 21 | import java.lang.annotation.RetentionPolicy; 22 | 23 | @Documented 24 | @Retention(RetentionPolicy.SOURCE) 25 | public @interface ThreadSafe { 26 | String value() default ""; 27 | } 28 | -------------------------------------------------------------------------------- /libtest/src/main/java/z/channel/BroadcastChannel.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013, Landz and its contributors. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package z.channel; 18 | 19 | /** 20 | * BroadcastChannel, is a {@link z.channel.Channel} which support the 21 | * broadcast style message. 22 | */ 23 | public interface BroadcastChannel extends Channel { 24 | public ReceivePort createReceivePort(); 25 | } 26 | -------------------------------------------------------------------------------- /libtest/src/main/java/z/channel/Channel.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013, Landz and its contributors. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package z.channel; 18 | 19 | /** 20 | * Channel, is an abstract for all kinds of Inter-Thread-Communication(ITC) 21 | * mechanism. 22 | *

23 | * 24 | */ 25 | public interface Channel { 26 | public boolean trySend(T value); 27 | public void send(T value); 28 | } 29 | -------------------------------------------------------------------------------- /libtest/src/main/java/z/channel/Channels.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013, Landz and its contributors. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package z.channel; 18 | 19 | /** 20 | * Channels, is a factory for all kinds of {@link z.channel.Channel}. 21 | *

22 | * From the aspect of producer/consumer, this factory provides four kinds 23 | * channel: 24 | *

SPSC - 25 | *

SPMC - 26 | *

MPSC - 27 | *

MPMC - 28 | *

29 | * Different types of channels have different use conditions and different 30 | * performance. 31 | * 32 | */ 33 | public class Channels { 34 | 35 | public static BroadcastChannel createBoundedSPSCChannel(int size) { 36 | return new GenericHyperLoop(size); 37 | } 38 | 39 | public static BroadcastChannel createBoundedSPMCChannel(int size) { 40 | return new GenericHyperLoop(size); 41 | } 42 | 43 | public static Channel createBoundedMPSCChannel(int size) { 44 | return new GenericMPMCQueue(size); 45 | } 46 | 47 | public static Channel createBoundedMPMCChannel(int size) { 48 | return new GenericMPMCQueue(size); 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /libtest/src/main/java/z/channel/ReceivePort.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013, Landz and its contributors. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package z.channel; 18 | 19 | /** 20 | * OutPort, is used to express outside endpoints of {@link Channel}s which 21 | * support the broadcast style message. 22 | * 23 | */ 24 | public interface ReceivePort { 25 | public T receive(); 26 | public T tryReceive(); 27 | public boolean isReceivable(); 28 | public boolean notReceivable(); 29 | } 30 | -------------------------------------------------------------------------------- /libtest/src/main/java/z/evil/Intrinsics.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013, Landz and its contributors. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package z.evil; 18 | 19 | public class Intrinsics { 20 | 21 | /** 22 | * Tricks: 23 | * warmup several static methods around the whole Landz, 24 | * to enable the early join of Hotspot intrinsics. 25 | * This tricks is not much useful for long-run instances. 26 | * 27 | * NOTE: here, it is assumed that intrinsification is more early than 28 | * other optimizations. 29 | */ 30 | public static final void warmup() { 31 | // int COUNT = 5000_000; 32 | // for (int i = 0; i < COUNT; i++) { 33 | // Allocator.sizeClassIndex(i); 34 | // } 35 | } 36 | 37 | 38 | } 39 | -------------------------------------------------------------------------------- /libtest/src/main/java/z/exception/ContractViolatedException.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013, Landz and its contributors. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package z.exception; 18 | 19 | public class ContractViolatedException 20 | extends IllegalStateException 21 | { 22 | 23 | private static final long serialVersionUID = 440746453796123497L; 24 | 25 | /** 26 | * Constructs an instance of this class. 27 | */ 28 | public ContractViolatedException() { 29 | } 30 | 31 | /** 32 | * Constructs an instance of this class with the specified detailed message. 33 | */ 34 | public ContractViolatedException(String msg) { 35 | super(msg); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /libtest/src/main/java/z/function/ExceptionalFunction0.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013, Landz and its contributors. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package z.function; 18 | 19 | /** 20 | * Function of 0 parameters which throws Exception. 21 | * () -> R throws Exception 22 | * @param 23 | */ 24 | @FunctionalInterface 25 | public interface ExceptionalFunction0 { 26 | 27 | /** 28 | * Return the result of applying the lambda. 29 | * 30 | * @return the function result 31 | * 32 | * @throws Exception 33 | */ 34 | R apply() throws Exception; 35 | 36 | } 37 | -------------------------------------------------------------------------------- /libtest/src/main/java/z/function/ExceptionalRunnable.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013, Landz and its contributors. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package z.function; 18 | 19 | /** 20 | * Function, specialization for Runnable, which throws Exception. 21 | * () -> void throws Exception 22 | */ 23 | @FunctionalInterface 24 | public interface ExceptionalRunnable { 25 | 26 | /** 27 | * Return the result of applying the lambda. 28 | * 29 | * @throws Exception; 30 | */ 31 | void run() throws Exception; 32 | 33 | } 34 | -------------------------------------------------------------------------------- /libtest/src/main/java/z/function/Function0.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013, Landz and its contributors. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package z.function; 18 | 19 | /** 20 | * Function of 0 parameters. 21 | * () -> R 22 | * @param 23 | */ 24 | @FunctionalInterface 25 | public interface Function0 { 26 | 27 | /** 28 | * Return the result of applying the lambda. 29 | * 30 | * @return the function result 31 | */ 32 | R apply(); 33 | 34 | } 35 | -------------------------------------------------------------------------------- /libtest/src/main/java/z/function/Function1.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013, Landz and its contributors. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package z.function; 18 | 19 | /** 20 | * Function of 1 parameters. 21 | * (T) -> R 22 | * @param 23 | */ 24 | @FunctionalInterface 25 | public interface Function1 { 26 | 27 | /** 28 | * Return the result of applying the lambda. 29 | * 30 | * @return the function result 31 | */ 32 | R apply(T v); 33 | 34 | } 35 | -------------------------------------------------------------------------------- /libtest/src/main/java/z/function/Function10.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013, Landz and its contributors. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package z.function; 18 | 19 | /** 20 | * Function of 8 parameters. 21 | * (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10) -> R 22 | * @param 23 | */ 24 | @FunctionalInterface 25 | public interface Function10 { 26 | 27 | /** 28 | * Return the result of applying the lambda. 29 | * 30 | * @return the function result 31 | */ 32 | R apply(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9, T10 v10); 33 | 34 | } 35 | -------------------------------------------------------------------------------- /libtest/src/main/java/z/function/Function11.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013, Landz and its contributors. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package z.function; 18 | 19 | /** 20 | * Function of 8 parameters. 21 | * (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11) -> R 22 | * @param 23 | */ 24 | @FunctionalInterface 25 | public interface Function11 { 26 | 27 | /** 28 | * Return the result of applying the lambda. 29 | * 30 | * @return the function result 31 | */ 32 | R apply(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9, T10 v10, T11 v11); 33 | 34 | } 35 | -------------------------------------------------------------------------------- /libtest/src/main/java/z/function/Function2.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013, Landz and its contributors. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package z.function; 18 | 19 | /** 20 | * Function of 2 parameters. 21 | * (T1, T2) -> R 22 | * @param 23 | */ 24 | @FunctionalInterface 25 | public interface Function2 { 26 | 27 | /** 28 | * Return the result of applying the lambda. 29 | * 30 | * @return the function result 31 | */ 32 | R apply(T1 v1, T2 v2); 33 | 34 | } 35 | -------------------------------------------------------------------------------- /libtest/src/main/java/z/function/Function3.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013, Landz and its contributors. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package z.function; 18 | 19 | /** 20 | * Function of 3 parameters. 21 | * (T1, T2, T3) -> R 22 | * @param 23 | */ 24 | @FunctionalInterface 25 | public interface Function3 { 26 | 27 | /** 28 | * Return the result of applying the lambda. 29 | * 30 | * @return the function result 31 | */ 32 | R apply(T1 v1, T2 v2, T3 v3); 33 | 34 | } 35 | -------------------------------------------------------------------------------- /libtest/src/main/java/z/function/Function4.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013, Landz and its contributors. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package z.function; 18 | 19 | /** 20 | * Function of 4 parameters. 21 | * (T1, T2, T3, T4) -> R 22 | * @param 23 | */ 24 | @FunctionalInterface 25 | public interface Function4 { 26 | 27 | /** 28 | * Return the result of applying the lambda. 29 | * 30 | * @return the function result 31 | */ 32 | R apply(T1 v1, T2 v2, T3 v3, T4 v4); 33 | 34 | } 35 | -------------------------------------------------------------------------------- /libtest/src/main/java/z/function/Function5.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013, Landz and its contributors. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package z.function; 18 | 19 | /** 20 | * Function of 5 parameters. 21 | * (T1, T2, T3, T4, T5) -> R 22 | * @param 23 | */ 24 | @FunctionalInterface 25 | public interface Function5 { 26 | 27 | /** 28 | * Return the result of applying the lambda. 29 | * 30 | * @return the function result 31 | */ 32 | R apply(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5); 33 | 34 | } 35 | -------------------------------------------------------------------------------- /libtest/src/main/java/z/function/Function6.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013, Landz and its contributors. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package z.function; 18 | 19 | /** 20 | * Function of 6 parameters. 21 | * (T1, T2, T3, T4, T5, T6) -> R 22 | * @param 23 | */ 24 | @FunctionalInterface 25 | public interface Function6 { 26 | 27 | /** 28 | * Return the result of applying the lambda. 29 | * 30 | * @return the function result 31 | */ 32 | R apply(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6); 33 | 34 | } 35 | -------------------------------------------------------------------------------- /libtest/src/main/java/z/function/Function7.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013, Landz and its contributors. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package z.function; 18 | 19 | /** 20 | * Function of 7 parameters. 21 | * (T1, T2, T3, T4, T5, T6, T7) -> R 22 | * @param 23 | */ 24 | @FunctionalInterface 25 | public interface Function7 { 26 | 27 | /** 28 | * Return the result of applying the lambda. 29 | * 30 | * @return the function result 31 | */ 32 | R apply(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7); 33 | 34 | } 35 | -------------------------------------------------------------------------------- /libtest/src/main/java/z/function/Function8.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013, Landz and its contributors. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package z.function; 18 | 19 | /** 20 | * Function of 8 parameters. 21 | * (T1, T2, T3, T4, T5, T6, T7, T8) -> R 22 | * @param 23 | */ 24 | @FunctionalInterface 25 | public interface Function8 { 26 | 27 | /** 28 | * Return the result of applying the lambda. 29 | * 30 | * @return the function result 31 | */ 32 | R apply(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8); 33 | 34 | } 35 | -------------------------------------------------------------------------------- /libtest/src/main/java/z/function/Function9.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013, Landz and its contributors. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package z.function; 18 | 19 | /** 20 | * Function of 8 parameters. 21 | * (T1, T2, T3, T4, T5, T6, T7, T8, T9) -> R 22 | * @param 23 | */ 24 | @FunctionalInterface 25 | public interface Function9 { 26 | 27 | /** 28 | * Return the result of applying the lambda. 29 | * 30 | * @return the function result 31 | */ 32 | R apply(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5, T6 v6, T7 v7, T8 v8, T9 v9); 33 | 34 | } 35 | -------------------------------------------------------------------------------- /libtest/src/main/java/z/function/Functions.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013, Landz and its contributors. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package z.function; 18 | 19 | import java.util.function.BooleanSupplier; 20 | 21 | /** 22 | * Static utility methods kinds of Funcitons . 23 | * 24 | */ 25 | public class Functions { 26 | 27 | private Functions() {} 28 | 29 | /** 30 | * Returns a function whose {@code apply} method returns the provided 31 | * input. Useful when a {@code Function} is required and {@code } 32 | * and {@code } are the same type. 33 | */ 34 | public static BooleanSupplier toBooleanSupplier(ToBooleanFunction0 f) { 35 | return () -> f.apply(); 36 | } 37 | 38 | 39 | } 40 | -------------------------------------------------------------------------------- /libtest/src/main/java/z/function/Pipe.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013, Landz and its contributors. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package z.function; 18 | 19 | import java.util.function.Function; 20 | 21 | public class Pipe { 22 | 23 | Function function; 24 | Pipe next; 25 | 26 | public Pipe(Function function) { 27 | this.function = function; 28 | } 29 | 30 | void next(Pipe next) { 31 | this.next = next; 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /libtest/src/main/java/z/function/Pipeline.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013, Landz and its contributors. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package z.function; 18 | 19 | import java.util.function.Function; 20 | 21 | /** 22 | * 23 | * TODO: the logic of type inferencing still has some flaws, although works 24 | * basically. 25 | * 26 | */ 27 | public class Pipeline implements Function { 28 | 29 | Pipe head; 30 | Pipe tail; 31 | 32 | private Pipeline(Pipe head) { 33 | this.head = head; 34 | this.tail = head; 35 | } 36 | 37 | public static Pipeline create(Function head){ 38 | //TODO contract(head!=null) 39 | return new Pipeline(new Pipe(head)); 40 | } 41 | 42 | public Pipeline next(Function f) { 43 | Pipe np = new Pipe(f); 44 | tail.next(np); 45 | tail = np; 46 | return (Pipeline)this; 47 | } 48 | 49 | public Pipeline end() { 50 | return (Pipeline)this; 51 | } 52 | 53 | @Override 54 | public OUT apply(IN in) { 55 | Pipe n = head; 56 | Object r = n.function.apply(in); 57 | while ( (n = n.next)!=null ) { 58 | r = n.function.apply(r); 59 | } 60 | return (OUT)r; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /libtest/src/main/java/z/function/ThrowableFunction0.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013, Landz and its contributors. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package z.function; 18 | 19 | /** 20 | * Function of 0 parameters which throws Throwable. 21 | * () -> R throws Throwable 22 | * @param 23 | */ 24 | @FunctionalInterface 25 | public interface ThrowableFunction0 { 26 | 27 | /** 28 | * Return the result of applying the lambda. 29 | * 30 | * @return the function result 31 | * 32 | * @throws Throwable 33 | */ 34 | R apply() throws Throwable; 35 | 36 | } 37 | -------------------------------------------------------------------------------- /libtest/src/main/java/z/function/ThrowableRunnable.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013, Landz and its contributors. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package z.function; 18 | 19 | /** 20 | * Function, specialization for Runnable, which throws Throwable. 21 | * () -> void throws Throwable 22 | */ 23 | @FunctionalInterface 24 | public interface ThrowableRunnable { 25 | 26 | /** 27 | * Return the result of applying the lambda. 28 | * 29 | * @throws Throwable; 30 | */ 31 | void run() throws Throwable; 32 | 33 | } 34 | -------------------------------------------------------------------------------- /libtest/src/main/java/z/function/ToBooleanFunction0.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013, Landz and its contributors. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package z.function; 18 | 19 | /** 20 | * Function of 0 parameters, specialization for boolean return. 21 | * () -> boolean 22 | */ 23 | @FunctionalInterface 24 | public interface ToBooleanFunction0 { 25 | 26 | /** 27 | * Return the result of applying the lambda. 28 | * 29 | * @return the function result 30 | */ 31 | boolean apply(); 32 | 33 | } 34 | -------------------------------------------------------------------------------- /libtest/src/main/java/z/function/ToByteFunction0.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013, Landz and its contributors. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package z.function; 18 | 19 | /** 20 | * Function of 0 parameters, specialization for byte return. 21 | * () -> byte 22 | */ 23 | @FunctionalInterface 24 | public interface ToByteFunction0 { 25 | /** 26 | * Return the result of applying the lambda. 27 | * 28 | * @return the function result 29 | */ 30 | byte apply(); 31 | 32 | } 33 | -------------------------------------------------------------------------------- /libtest/src/main/java/z/function/ToCharFunction0.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013, Landz and its contributors. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package z.function; 18 | 19 | /** 20 | * Function of 0 parameters, specialization for char return. 21 | * () -> char 22 | */ 23 | @FunctionalInterface 24 | public interface ToCharFunction0 { 25 | /** 26 | * Return the result of applying the lambda. 27 | * 28 | * @return the function result 29 | */ 30 | char apply(); 31 | 32 | } 33 | -------------------------------------------------------------------------------- /libtest/src/main/java/z/function/ToDoubleFunction0.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013, Landz and its contributors. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package z.function; 18 | 19 | /** 20 | * Function of 0 parameters, specialization for double return. 21 | * () -> double 22 | */ 23 | @FunctionalInterface 24 | public interface ToDoubleFunction0 { 25 | /** 26 | * Return the result of applying the lambda. 27 | * 28 | * @return the function result 29 | */ 30 | double apply(); 31 | 32 | } 33 | -------------------------------------------------------------------------------- /libtest/src/main/java/z/function/ToFloatFunction0.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013, Landz and its contributors. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package z.function; 18 | 19 | /** 20 | * Function of 0 parameters, specialization for float return. 21 | * () -> float 22 | */ 23 | @FunctionalInterface 24 | public interface ToFloatFunction0 { 25 | /** 26 | * Return the result of applying the lambda. 27 | * 28 | * @return the function result 29 | */ 30 | float apply(); 31 | 32 | } 33 | -------------------------------------------------------------------------------- /libtest/src/main/java/z/function/ToIntFunction0.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013, Landz and its contributors. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package z.function; 18 | 19 | /** 20 | * Function of 0 parameters, specialization for int return. 21 | * () -> int 22 | */ 23 | @FunctionalInterface 24 | public interface ToIntFunction0 { 25 | 26 | /** 27 | * Return the result of applying the lambda. 28 | * 29 | * @return the function result 30 | */ 31 | int apply(); 32 | 33 | } 34 | -------------------------------------------------------------------------------- /libtest/src/main/java/z/function/ToLongFunction0.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013, Landz and its contributors. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package z.function; 18 | 19 | /** 20 | * Function of 0 parameters, specialization for long return. 21 | * () -> long 22 | */ 23 | @FunctionalInterface 24 | public interface ToLongFunction0 { 25 | 26 | /** 27 | * Return the result of applying the lambda. 28 | * 29 | * @return the function result 30 | */ 31 | long apply(); 32 | 33 | } 34 | -------------------------------------------------------------------------------- /libtest/src/main/java/z/function/ToShortFunction0.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013, Landz and its contributors. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package z.function; 18 | 19 | /** 20 | * Function of 0 parameters, specialization for short return. 21 | * () -> short 22 | */ 23 | @FunctionalInterface 24 | public interface ToShortFunction0 { 25 | /** 26 | * Return the result of applying the lambda. 27 | * 28 | * @return the function result 29 | */ 30 | short apply(); 31 | 32 | } 33 | -------------------------------------------------------------------------------- /libtest/src/main/java/z/module/Module.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013, Landz and its contributors. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package z.module; 18 | 19 | import java.lang.annotation.*; 20 | 21 | /** 22 | */ 23 | @Documented 24 | @Retention(RetentionPolicy.CLASS) 25 | @Target(ElementType.TYPE) 26 | public @interface Module { 27 | 28 | String name() default ""; 29 | 30 | String version() default "1.0"; 31 | 32 | String vendor() default ""; 33 | 34 | String description() default ""; 35 | 36 | License license() default License.UNKNOWN; 37 | 38 | String customLicense() default ""; 39 | 40 | String libraryPath() default "."; 41 | 42 | String override() default ""; 43 | 44 | } 45 | -------------------------------------------------------------------------------- /libtest/src/main/java/z/offheap/buffer/BufferStateException.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013, Landz and its contributors. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package z.offheap.buffer; 18 | 19 | /** 20 | */ 21 | public class BufferStateException extends IllegalStateException { 22 | public BufferStateException() { 23 | } 24 | 25 | public BufferStateException(String s) { 26 | super(s); 27 | } 28 | 29 | public BufferStateException(String message, Throwable cause) { 30 | super(message, cause); 31 | } 32 | 33 | public BufferStateException(Throwable cause) { 34 | super(cause); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /libtest/src/main/java/z/offheap/buffer/ByteBuffer.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013, Landz and its contributors. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package z.offheap.buffer; 18 | 19 | /** 20 | * Created by jin on 12/27/13. 21 | */ 22 | public interface ByteBuffer extends AutoCloseable { 23 | 24 | /** 25 | * Returns this buffer's capacity. 26 | * 27 | * @return The capacity of this buffer 28 | */ 29 | long capacity(); 30 | 31 | long address(); 32 | 33 | ByteBuffer clear(); 34 | 35 | long readCursor(); 36 | 37 | long writeCursor(); 38 | 39 | ByteBuffer reset(); 40 | 41 | boolean isReadable(); 42 | 43 | boolean isReadable(long numBytes); 44 | 45 | boolean isWritable(); 46 | 47 | boolean isWritable(long numBytes); 48 | 49 | long readableBytes(); 50 | 51 | long writableBytes(); 52 | 53 | byte read(); 54 | 55 | void skipRead(long length); 56 | 57 | void skipReadTo(long index); 58 | 59 | void readTo(ByteBuffer dstbuffer, long length); 60 | 61 | //FIXME: override to byte[] and nio buffer 62 | 63 | ByteBuffer write(byte value); 64 | 65 | NativeOrderBuffer nativeOrder(); 66 | 67 | NetworkOrderBuffer networkOrder(); 68 | 69 | LittleEndianOrderBuffer littleEndianOrder(); 70 | 71 | @Deprecated 72 | ByteBuffer skipWrite(long length); 73 | 74 | @Deprecated 75 | ByteBuffer skipWriteTo(long index); 76 | 77 | void close(); 78 | 79 | // @Override 80 | // void finalize(); 81 | } 82 | -------------------------------------------------------------------------------- /libtest/src/main/java/z/offheap/buffer/LittleEndianOrderBuffer.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013, Landz and its contributors. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package z.offheap.buffer; 18 | 19 | /** 20 | */ 21 | public interface LittleEndianOrderBuffer extends ByteBuffer { 22 | short readShortLE(); 23 | 24 | int readIntLE(); 25 | 26 | long readLongLE(); 27 | 28 | char readCharLE(); 29 | 30 | float readFloatLE(); 31 | 32 | double readDoubleLE(); 33 | 34 | LittleEndianOrderBuffer writeShortLE(short value); 35 | 36 | LittleEndianOrderBuffer writeIntLE(int value); 37 | 38 | LittleEndianOrderBuffer writeLongLE(long value); 39 | 40 | LittleEndianOrderBuffer writeCharLE(char value); 41 | 42 | LittleEndianOrderBuffer writeFloatLE(float value); 43 | 44 | LittleEndianOrderBuffer writeDoubleLE(double value); 45 | 46 | LittleEndianOrderBuffer write(byte value); 47 | } 48 | -------------------------------------------------------------------------------- /libtest/src/main/java/z/offheap/buffer/NativeOrderBuffer.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013, Landz and its contributors. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package z.offheap.buffer; 18 | 19 | /** 20 | */ 21 | public interface NativeOrderBuffer extends ByteBuffer { 22 | short readShort(); 23 | 24 | int readInt(); 25 | 26 | long readLong(); 27 | 28 | char readChar(); 29 | 30 | float readFloat(); 31 | 32 | double readDouble(); 33 | 34 | Buffer writeShort(short value); 35 | 36 | Buffer writeInt(int value); 37 | 38 | Buffer writeLong(long value); 39 | 40 | Buffer writeChar(char value); 41 | 42 | Buffer writeFloat(float value); 43 | 44 | Buffer writeDouble(double value); 45 | 46 | NativeOrderBuffer write(byte value); 47 | } 48 | -------------------------------------------------------------------------------- /libtest/src/main/java/z/offheap/buffer/NetworkOrderBuffer.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013, Landz and its contributors. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package z.offheap.buffer; 18 | 19 | /** 20 | */ 21 | public interface NetworkOrderBuffer extends ByteBuffer { 22 | short readShortN(); 23 | 24 | int readIntN(); 25 | 26 | long readLongN(); 27 | 28 | char readCharN(); 29 | 30 | float readFloatN(); 31 | 32 | double readDoubleN(); 33 | 34 | NetworkOrderBuffer writeShortN(short value); 35 | 36 | NetworkOrderBuffer writeIntN(int value); 37 | 38 | NetworkOrderBuffer writeLongN(long value); 39 | 40 | NetworkOrderBuffer writeCharN(char value); 41 | 42 | NetworkOrderBuffer writeFloatN(float value); 43 | 44 | NetworkOrderBuffer writeDoubleN(double value); 45 | 46 | NetworkOrderBuffer write(byte value); 47 | } 48 | -------------------------------------------------------------------------------- /libtest/src/main/java/z/util/MethodHandles.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2013, Landz and its contributors. All rights reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package z.util; 18 | 19 | import java.lang.reflect.Field; 20 | 21 | import static java.lang.invoke.MethodHandles.Lookup; 22 | import static z.util.Unsafes.UNSAFE; 23 | 24 | /** 25 | * All APIs to expose MethodHandles side things in Hotspot for use. 26 | * 27 | * @Performance, we keep all exposed publics in constant as possible 28 | * 29 | */ 30 | public class MethodHandles { 31 | 32 | public static final Lookup LOOKUP; 33 | static { 34 | //XXX: hack to be GOD?... 35 | Field f_IMPL_LOOKUP = Throwables.uncheckTo(() -> Lookup.class.getDeclaredField("IMPL_LOOKUP")); 36 | Object base = UNSAFE.staticFieldBase(Lookup.class); 37 | long offset = UNSAFE.staticFieldOffset(f_IMPL_LOOKUP); 38 | LOOKUP = (Lookup)UNSAFE.getObject(base, offset); 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /libtest/src/test/java/com/devexperts/dxlab/lincheck/tests/LockFreeDequeTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Lincheck - Linearizability checker 3 | * 4 | * Copyright (C) 2015-2022 Devexperts, LLC 5 | * Copyright (C) 2023 Devexperts Ireland Limited 6 | * 7 | * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. 8 | * If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | 11 | package com.devexperts.dxlab.lincheck.tests 12 | 13 | import com.devexperts.dxlab.lincheck.LinChecker 14 | import com.devexperts.dxlab.lincheck.annotations.Operation 15 | import com.devexperts.dxlab.lincheck.strategy.randomswitch.RandomSwitchCTest 16 | import com.devexperts.dxlab.lincheck.strategy.stress.StressCTest 17 | import org.junit.Test 18 | 19 | @StressCTest 20 | class DequeLinearizabilityTest { 21 | private val deque = LockFreeDeque(); 22 | 23 | @Operation 24 | fun pushLeft(value: Int) = deque.pushLeft(value) 25 | 26 | @Operation 27 | fun pushRight(value: Int) = deque.pushRight(value) 28 | 29 | @Operation 30 | fun popLeft(): Int? = deque.popLeft() 31 | 32 | @Operation 33 | fun popRight(): Int? = deque.popRight() 34 | 35 | @Test 36 | fun test() = LinChecker.check(DequeLinearizabilityTest::class.java) 37 | } 38 | -------------------------------------------------------------------------------- /libtest/src/test/java/com/devexperts/dxlab/lincheck/tests/boundary/BitVectorCorrect1.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Lincheck - Linearizability checker 3 | * 4 | * Copyright (C) 2015-2022 Devexperts, LLC 5 | * Copyright (C) 2023 Devexperts Ireland Limited 6 | * 7 | * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. 8 | * If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | 11 | package com.devexperts.dxlab.lincheck.tests.boundary; 12 | 13 | import com.devexperts.dxlab.lincheck.LinChecker; 14 | import com.devexperts.dxlab.lincheck.annotations.Operation; 15 | import com.devexperts.dxlab.lincheck.annotations.Param; 16 | import com.devexperts.dxlab.lincheck.paramgen.IntGen; 17 | import com.devexperts.dxlab.lincheck.strategy.stress.StressCTest; 18 | import org.cliffc.high_scale_lib.NonBlockingSetInt; 19 | import org.junit.Test; 20 | 21 | import java.util.Set; 22 | 23 | @StressCTest 24 | @Param(name = "key", gen = IntGen.class, conf = "1:10") 25 | public class BitVectorCorrect1 { 26 | private Set q = new NonBlockingSetInt(); 27 | 28 | @Operation(params = {"key"}) 29 | public boolean add(int key) { 30 | return q.add(key); 31 | } 32 | 33 | @Operation 34 | public boolean remove(@Param(name = "key") int key) { 35 | return q.remove(key); 36 | } 37 | 38 | @Test 39 | public void test() { 40 | LinChecker.check(BitVectorCorrect1.class); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /libtest/src/test/java/com/devexperts/dxlab/lincheck/tests/boundary/MapCorrect1.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Lincheck - Linearizability checker 3 | * 4 | * Copyright (C) 2015-2022 Devexperts, LLC 5 | * Copyright (C) 2023 Devexperts Ireland Limited 6 | * 7 | * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. 8 | * If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | 11 | package com.devexperts.dxlab.lincheck.tests.boundary; 12 | 13 | import com.devexperts.dxlab.lincheck.LinChecker; 14 | import com.devexperts.dxlab.lincheck.annotations.Operation; 15 | import com.devexperts.dxlab.lincheck.annotations.Param; 16 | import com.devexperts.dxlab.lincheck.paramgen.IntGen; 17 | import com.devexperts.dxlab.lincheck.strategy.stress.StressCTest; 18 | import org.cliffc.high_scale_lib.NonBlockingHashMap; 19 | import org.junit.Test; 20 | 21 | import java.util.Map; 22 | 23 | @StressCTest 24 | @Param(name = "key", gen = IntGen.class) 25 | @Param(name = "value", gen = IntGen.class) 26 | public class MapCorrect1 { 27 | private Map map = new NonBlockingHashMap<>(); 28 | 29 | @Operation 30 | public Integer put(Integer key, Integer value) { 31 | return map.put(key, value); 32 | } 33 | 34 | @Operation 35 | public Integer get(Integer key) { 36 | return map.get(key); 37 | } 38 | 39 | @Operation(handleExceptionsAsResult = NullPointerException.class) 40 | public int putIfAbsent(int key, int value) { 41 | return map.putIfAbsent(key, value); 42 | } 43 | 44 | @Test 45 | public void test() { 46 | LinChecker.check(MapCorrect1.class); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /libtest/src/test/java/com/devexperts/dxlab/lincheck/tests/boundary/SetCorrect1.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Lincheck - Linearizability checker 3 | * 4 | * Copyright (C) 2015-2022 Devexperts, LLC 5 | * Copyright (C) 2023 Devexperts Ireland Limited 6 | * 7 | * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. 8 | * If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | 11 | package com.devexperts.dxlab.lincheck.tests.boundary; 12 | 13 | import com.devexperts.dxlab.lincheck.LinChecker; 14 | import com.devexperts.dxlab.lincheck.annotations.Operation; 15 | import com.devexperts.dxlab.lincheck.annotations.Param; 16 | import com.devexperts.dxlab.lincheck.paramgen.IntGen; 17 | import com.devexperts.dxlab.lincheck.strategy.stress.StressCTest; 18 | import org.cliffc.high_scale_lib.NonBlockingHashSet; 19 | import org.junit.Test; 20 | 21 | @StressCTest 22 | @Param(name = "key", gen = IntGen.class) 23 | public class SetCorrect1 { 24 | private NonBlockingHashSet q = new NonBlockingHashSet<>(); 25 | 26 | @Operation(params = {"key"}) 27 | public boolean add(int key) { 28 | return q.add(key); 29 | } 30 | 31 | @Operation(params = {"key"}) 32 | public boolean remove(int key) { 33 | return q.remove(key); 34 | } 35 | 36 | @Test 37 | public void test() { 38 | LinChecker.check(SetCorrect1.class); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /libtest/src/test/java/com/devexperts/dxlab/lincheck/tests/custom/counter/CounterGetTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Lincheck - Linearizability checker 3 | * 4 | * Copyright (C) 2015-2022 Devexperts, LLC 5 | * Copyright (C) 2023 Devexperts Ireland Limited 6 | * 7 | * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. 8 | * If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | 11 | package com.devexperts.dxlab.lincheck.tests.custom.counter; 12 | 13 | import com.devexperts.dxlab.lincheck.LinChecker; 14 | import com.devexperts.dxlab.lincheck.annotations.Operation; 15 | import com.devexperts.dxlab.lincheck.strategy.stress.StressCTest; 16 | import org.junit.Test; 17 | import tests.custom.counter.CounterGet; 18 | 19 | @StressCTest 20 | public class CounterGetTest { 21 | private CounterGet counter = new CounterGet();; 22 | 23 | @Operation 24 | public int incAndGet() { 25 | return counter.incrementAndGet(); 26 | } 27 | 28 | @Operation 29 | public int get() { 30 | return counter.get(); 31 | } 32 | 33 | @Test 34 | public void test() { 35 | LinChecker.check(CounterGetTest.class); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /libtest/src/test/java/com/devexperts/dxlab/lincheck/tests/custom/counter/CounterTest1.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Lincheck - Linearizability checker 3 | * 4 | * Copyright (C) 2015-2022 Devexperts, LLC 5 | * Copyright (C) 2023 Devexperts Ireland Limited 6 | * 7 | * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. 8 | * If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | 11 | package com.devexperts.dxlab.lincheck.tests.custom.counter; 12 | 13 | import com.devexperts.dxlab.lincheck.LinChecker; 14 | import com.devexperts.dxlab.lincheck.annotations.Operation; 15 | import com.devexperts.dxlab.lincheck.strategy.stress.StressCTest; 16 | import org.junit.Test; 17 | import tests.custom.counter.Counter; 18 | import tests.custom.counter.CounterWrong0; 19 | 20 | @StressCTest 21 | public class CounterTest1 { 22 | private Counter counter = new CounterWrong0(); 23 | 24 | @Operation 25 | public int incAndGet() { 26 | return counter.incrementAndGet(); 27 | } 28 | 29 | @Test(expected = AssertionError.class) 30 | public void test() { 31 | LinChecker.check(CounterTest1.class); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /libtest/src/test/java/com/devexperts/dxlab/lincheck/tests/custom/counter/CounterTest2.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Lincheck - Linearizability checker 3 | * 4 | * Copyright (C) 2015-2022 Devexperts, LLC 5 | * Copyright (C) 2023 Devexperts Ireland Limited 6 | * 7 | * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. 8 | * If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | 11 | package com.devexperts.dxlab.lincheck.tests.custom.counter; 12 | 13 | import com.devexperts.dxlab.lincheck.LinChecker; 14 | import com.devexperts.dxlab.lincheck.annotations.Operation; 15 | import com.devexperts.dxlab.lincheck.strategy.stress.StressCTest; 16 | import org.junit.Test; 17 | import tests.custom.counter.Counter; 18 | import tests.custom.counter.CounterCorrect2; 19 | 20 | @StressCTest 21 | public class CounterTest2 { 22 | private Counter counter = new CounterCorrect2(); 23 | 24 | @Operation 25 | public int incAndGet() { 26 | return counter.incrementAndGet(); 27 | } 28 | 29 | @Test 30 | public void test() { 31 | LinChecker.check(CounterTest2.class); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /libtest/src/test/java/com/devexperts/dxlab/lincheck/tests/custom/counter/CounterTest3.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Lincheck - Linearizability checker 3 | * 4 | * Copyright (C) 2015-2022 Devexperts, LLC 5 | * Copyright (C) 2023 Devexperts Ireland Limited 6 | * 7 | * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. 8 | * If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | 11 | package com.devexperts.dxlab.lincheck.tests.custom.counter; 12 | 13 | import com.devexperts.dxlab.lincheck.LinChecker; 14 | import com.devexperts.dxlab.lincheck.annotations.Operation; 15 | import com.devexperts.dxlab.lincheck.strategy.stress.StressCTest; 16 | import org.junit.Test; 17 | import tests.custom.counter.Counter; 18 | import tests.custom.counter.CounterWrong1; 19 | 20 | @StressCTest 21 | public class CounterTest3 { 22 | private Counter counter = new CounterWrong1(); 23 | 24 | @Operation 25 | public int incAndGet() { 26 | return counter.incrementAndGet(); 27 | } 28 | 29 | @Test(expected = AssertionError.class) 30 | public void test() { 31 | LinChecker.check(CounterTest3.class); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /libtest/src/test/java/com/devexperts/dxlab/lincheck/tests/custom/counter/CounterTest4.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Lincheck - Linearizability checker 3 | * 4 | * Copyright (C) 2015-2022 Devexperts, LLC 5 | * Copyright (C) 2023 Devexperts Ireland Limited 6 | * 7 | * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. 8 | * If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | 11 | package com.devexperts.dxlab.lincheck.tests.custom.counter; 12 | 13 | import com.devexperts.dxlab.lincheck.LinChecker; 14 | import com.devexperts.dxlab.lincheck.annotations.Operation; 15 | import com.devexperts.dxlab.lincheck.strategy.stress.StressCTest; 16 | import org.junit.Test; 17 | import tests.custom.counter.Counter; 18 | import tests.custom.counter.CounterWrong2; 19 | 20 | @StressCTest 21 | public class CounterTest4 { 22 | private Counter counter = new CounterWrong2(); 23 | 24 | @Operation 25 | public int incAndGet() { 26 | return counter.incrementAndGet(); 27 | } 28 | 29 | @Test(expected = AssertionError.class) 30 | public void test() { 31 | LinChecker.check(CounterTest4.class); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /libtest/src/test/java/com/devexperts/dxlab/lincheck/tests/custom/queue/WrapperQueueCorrect1.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Lincheck - Linearizability checker 3 | * 4 | * Copyright (C) 2015-2022 Devexperts, LLC 5 | * Copyright (C) 2023 Devexperts Ireland Limited 6 | * 7 | * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. 8 | * If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | 11 | package com.devexperts.dxlab.lincheck.tests.custom.queue; 12 | 13 | import com.devexperts.dxlab.lincheck.LinChecker; 14 | import com.devexperts.dxlab.lincheck.annotations.Operation; 15 | import com.devexperts.dxlab.lincheck.annotations.Param; 16 | import com.devexperts.dxlab.lincheck.paramgen.IntGen; 17 | import com.devexperts.dxlab.lincheck.strategy.stress.StressCTest; 18 | import org.junit.Test; 19 | import tests.custom.queue.Queue; 20 | import tests.custom.queue.QueueEmptyException; 21 | import tests.custom.queue.QueueSynchronized; 22 | 23 | @StressCTest 24 | public class WrapperQueueCorrect1 { 25 | private Queue queue = new QueueSynchronized(10);; 26 | 27 | @Operation(handleExceptionsAsResult = QueueEmptyException.class) 28 | public void put(@Param(gen = IntGen.class)int args) throws Exception { 29 | queue.put(args); 30 | } 31 | 32 | @Operation(handleExceptionsAsResult = QueueEmptyException.class) 33 | public int get() throws Exception { 34 | return queue.get(); 35 | } 36 | 37 | @Test 38 | public void test() { 39 | LinChecker.check(WrapperQueueCorrect1.class); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /libtest/src/test/java/com/devexperts/dxlab/lincheck/tests/custom/queue/WrapperQueueWrong1.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Lincheck - Linearizability checker 3 | * 4 | * Copyright (C) 2015-2022 Devexperts, LLC 5 | * Copyright (C) 2023 Devexperts Ireland Limited 6 | * 7 | * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. 8 | * If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | 11 | package com.devexperts.dxlab.lincheck.tests.custom.queue; 12 | 13 | import com.devexperts.dxlab.lincheck.LinChecker; 14 | import com.devexperts.dxlab.lincheck.annotations.Operation; 15 | import com.devexperts.dxlab.lincheck.annotations.Param; 16 | import com.devexperts.dxlab.lincheck.paramgen.IntGen; 17 | import com.devexperts.dxlab.lincheck.strategy.stress.StressCTest; 18 | import org.junit.Test; 19 | import tests.custom.queue.Queue; 20 | import tests.custom.queue.QueueEmptyException; 21 | import tests.custom.queue.QueueWrong1; 22 | @StressCTest 23 | public class WrapperQueueWrong1 { 24 | private Queue queue = new QueueWrong1(10); 25 | 26 | @Operation(handleExceptionsAsResult = QueueEmptyException.class) 27 | public void put(@Param(gen = IntGen.class)int x) throws Exception { 28 | queue.put(x); 29 | } 30 | 31 | @Operation(handleExceptionsAsResult = QueueEmptyException.class) 32 | public int get() throws Exception { 33 | return queue.get(); 34 | } 35 | 36 | @Test(expected = AssertionError.class) 37 | public void test() { 38 | LinChecker.check(WrapperQueueWrong1.class); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /libtest/src/test/java/com/devexperts/dxlab/lincheck/tests/custom/queue/WrapperQueueWrong2.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Lincheck - Linearizability checker 3 | * 4 | * Copyright (C) 2015-2022 Devexperts, LLC 5 | * Copyright (C) 2023 Devexperts Ireland Limited 6 | * 7 | * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. 8 | * If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | 11 | package com.devexperts.dxlab.lincheck.tests.custom.queue; 12 | 13 | import com.devexperts.dxlab.lincheck.LinChecker; 14 | import com.devexperts.dxlab.lincheck.annotations.Operation; 15 | import com.devexperts.dxlab.lincheck.annotations.Param; 16 | import com.devexperts.dxlab.lincheck.paramgen.IntGen; 17 | import com.devexperts.dxlab.lincheck.strategy.stress.StressCTest; 18 | import org.junit.Test; 19 | import tests.custom.queue.Queue; 20 | import tests.custom.queue.QueueEmptyException; 21 | import tests.custom.queue.QueueWrong2; 22 | 23 | @StressCTest 24 | public class WrapperQueueWrong2 { 25 | private Queue queue = new QueueWrong2(10); 26 | 27 | @Operation(handleExceptionsAsResult = QueueEmptyException.class) 28 | public void put(@Param(gen = IntGen.class)int args) throws Exception { 29 | queue.put(args); 30 | } 31 | 32 | @Operation(handleExceptionsAsResult = QueueEmptyException.class) 33 | public int get() throws Exception { 34 | return queue.get(); 35 | } 36 | 37 | @Test(expected = AssertionError.class) 38 | public void test() throws Exception { 39 | LinChecker.check(WrapperQueueWrong2.class); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /libtest/src/test/java/com/devexperts/dxlab/lincheck/tests/custom/queue/WrapperQueueWrong3.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Lincheck - Linearizability checker 3 | * 4 | * Copyright (C) 2015-2022 Devexperts, LLC 5 | * Copyright (C) 2023 Devexperts Ireland Limited 6 | * 7 | * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. 8 | * If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | 11 | package com.devexperts.dxlab.lincheck.tests.custom.queue; 12 | 13 | import com.devexperts.dxlab.lincheck.LinChecker; 14 | import com.devexperts.dxlab.lincheck.annotations.Operation; 15 | import com.devexperts.dxlab.lincheck.annotations.Param; 16 | import com.devexperts.dxlab.lincheck.paramgen.IntGen; 17 | import com.devexperts.dxlab.lincheck.strategy.stress.StressCTest; 18 | import org.junit.Test; 19 | import tests.custom.queue.Queue; 20 | import tests.custom.queue.QueueEmptyException; 21 | import tests.custom.queue.QueueWrong3; 22 | 23 | @StressCTest 24 | public class WrapperQueueWrong3 { 25 | private Queue queue = new QueueWrong3(10); 26 | 27 | @Operation(handleExceptionsAsResult = QueueEmptyException.class) 28 | public void put(@Param(gen = IntGen.class)int args) throws Exception { 29 | queue.put(args); 30 | } 31 | 32 | @Operation(handleExceptionsAsResult = QueueEmptyException.class) 33 | public int get() throws Exception { 34 | return queue.get(); 35 | } 36 | 37 | @Test(expected = AssertionError.class) 38 | public void test() throws Exception { 39 | LinChecker.check(WrapperQueueWrong2.class); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /libtest/src/test/java/com/devexperts/dxlab/lincheck/tests/guava/MultisetCorrect1.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Lincheck - Linearizability checker 3 | * 4 | * Copyright (C) 2015-2022 Devexperts, LLC 5 | * Copyright (C) 2023 Devexperts Ireland Limited 6 | * 7 | * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. 8 | * If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | 11 | package com.devexperts.dxlab.lincheck.tests.guava; 12 | 13 | import com.devexperts.dxlab.lincheck.LinChecker; 14 | import com.devexperts.dxlab.lincheck.annotations.Operation; 15 | import com.devexperts.dxlab.lincheck.annotations.Param; 16 | import com.devexperts.dxlab.lincheck.paramgen.IntGen; 17 | import com.devexperts.dxlab.lincheck.strategy.stress.StressCTest; 18 | import com.google.common.collect.ConcurrentHashMultiset; 19 | import org.junit.Test; 20 | 21 | @StressCTest 22 | @Param(name = "value", gen = IntGen.class) 23 | @Param(name = "count", gen = IntGen.class, conf = "1:10") 24 | public class MultisetCorrect1 { 25 | private ConcurrentHashMultiset q = ConcurrentHashMultiset.create(); 26 | 27 | @Operation(params = {"value", "count"}) 28 | public int add(int value, int count) { 29 | return q.add(value, count); 30 | } 31 | 32 | @Operation(params = {"value", "count"}) 33 | public int remove(int value, int count) { 34 | return q.remove(value, count); 35 | } 36 | 37 | @Test 38 | public void test() { 39 | LinChecker.check(MultisetCorrect1.class); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /libtest/src/test/java/com/devexperts/dxlab/lincheck/tests/guava/SetCorrect1.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Lincheck - Linearizability checker 3 | * 4 | * Copyright (C) 2015-2022 Devexperts, LLC 5 | * Copyright (C) 2023 Devexperts Ireland Limited 6 | * 7 | * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. 8 | * If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | 11 | package com.devexperts.dxlab.lincheck.tests.guava; 12 | 13 | import com.devexperts.dxlab.lincheck.LinChecker; 14 | import com.devexperts.dxlab.lincheck.annotations.Operation; 15 | import com.devexperts.dxlab.lincheck.annotations.Param; 16 | import com.devexperts.dxlab.lincheck.paramgen.IntGen; 17 | import com.devexperts.dxlab.lincheck.strategy.stress.StressCTest; 18 | import org.junit.Test; 19 | 20 | import java.util.Collections; 21 | import java.util.Set; 22 | import java.util.concurrent.ConcurrentHashMap; 23 | 24 | @StressCTest 25 | @Param(name = "key", gen = IntGen.class) 26 | public class SetCorrect1 { 27 | private Set q = Collections.newSetFromMap(new ConcurrentHashMap());; 28 | 29 | @Operation(params = {"key"}) 30 | public boolean add(Integer params) { 31 | return q.add(params); 32 | } 33 | 34 | @Operation(params = {"key"}) 35 | public boolean remove(Integer params) { 36 | return q.remove(params); 37 | } 38 | 39 | @Test 40 | public void test() throws Exception { 41 | LinChecker.check(SetCorrect1.class); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /libtest/src/test/java/com/devexperts/dxlab/lincheck/tests/juc/blocking_queue/BlockingQueueTest1.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Lincheck - Linearizability checker 3 | * 4 | * Copyright (C) 2015-2022 Devexperts, LLC 5 | * Copyright (C) 2023 Devexperts Ireland Limited 6 | * 7 | * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. 8 | * If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | 11 | package com.devexperts.dxlab.lincheck.tests.juc.blocking_queue; 12 | 13 | import com.devexperts.dxlab.lincheck.LinChecker; 14 | import com.devexperts.dxlab.lincheck.annotations.Operation; 15 | import com.devexperts.dxlab.lincheck.annotations.Param; 16 | import com.devexperts.dxlab.lincheck.paramgen.IntGen; 17 | import com.devexperts.dxlab.lincheck.strategy.stress.StressCTest; 18 | import org.junit.Test; 19 | 20 | import java.util.NoSuchElementException; 21 | import java.util.concurrent.ArrayBlockingQueue; 22 | import java.util.concurrent.BlockingQueue; 23 | 24 | @StressCTest 25 | public class BlockingQueueTest1 { 26 | private BlockingQueue q = new ArrayBlockingQueue<>(10); 27 | 28 | @Operation 29 | public boolean add(@Param(gen = IntGen.class) Integer value) { 30 | return q.add(value); 31 | } 32 | 33 | @Operation(handleExceptionsAsResult = NoSuchElementException.class) 34 | public Integer element() { 35 | return q.element(); 36 | } 37 | 38 | @Operation(handleExceptionsAsResult = NoSuchElementException.class) 39 | public Integer remove() { 40 | return q.remove(); 41 | } 42 | 43 | @Operation(handleExceptionsAsResult = NoSuchElementException.class) 44 | public Integer poll() { 45 | return q.poll(); 46 | } 47 | 48 | @Test 49 | public void test() { 50 | LinChecker.check(BlockingQueueTest1.class); 51 | } 52 | } 53 | 54 | -------------------------------------------------------------------------------- /libtest/src/test/java/com/devexperts/dxlab/lincheck/tests/juc/hash_map/HashMapTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Lincheck - Linearizability checker 3 | * 4 | * Copyright (C) 2015-2022 Devexperts, LLC 5 | * Copyright (C) 2023 Devexperts Ireland Limited 6 | * 7 | * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. 8 | * If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | 11 | package com.devexperts.dxlab.lincheck.tests.juc.hash_map; 12 | 13 | import com.devexperts.dxlab.lincheck.LinChecker; 14 | import com.devexperts.dxlab.lincheck.annotations.Operation; 15 | import com.devexperts.dxlab.lincheck.annotations.Param; 16 | import com.devexperts.dxlab.lincheck.paramgen.IntGen; 17 | import com.devexperts.dxlab.lincheck.strategy.stress.StressCTest; 18 | import org.junit.Test; 19 | 20 | import java.util.HashMap; 21 | import java.util.Map; 22 | 23 | @StressCTest 24 | @Param(name = "key", gen = IntGen.class) 25 | @Param(name = "value", gen = IntGen.class) 26 | public class HashMapTest { 27 | private Map m = new HashMap<>(); 28 | 29 | @Operation(params = {"key", "value"}) 30 | public Integer put(Integer key, Integer value) { 31 | return m.put(key, value); 32 | } 33 | 34 | @Operation 35 | public Integer get(@Param(name = "key") Integer key) { 36 | return m.get(key); 37 | } 38 | 39 | @Test(expected = AssertionError.class) 40 | public void test() throws Exception { 41 | LinChecker.check(HashMapTest.class); 42 | } 43 | } 44 | 45 | -------------------------------------------------------------------------------- /libtest/src/test/java/com/devexperts/dxlab/lincheck/tests/lockfreequeue/QueueCorrect1.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Lincheck - Linearizability checker 3 | * 4 | * Copyright (C) 2015-2022 Devexperts, LLC 5 | * Copyright (C) 2023 Devexperts Ireland Limited 6 | * 7 | * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. 8 | * If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | 11 | package com.devexperts.dxlab.lincheck.tests.lockfreequeue; 12 | 13 | import com.devexperts.dxlab.lincheck.LinChecker; 14 | import com.devexperts.dxlab.lincheck.annotations.Operation; 15 | import com.devexperts.dxlab.lincheck.annotations.Param; 16 | import com.devexperts.dxlab.lincheck.paramgen.IntGen; 17 | import com.devexperts.dxlab.lincheck.strategy.stress.StressCTest; 18 | import com.github.lock.free.queue.LockFreeQueue; 19 | 20 | /** 21 | * https://github.com/yaitskov/lock-free-queue 22 | */ 23 | @StressCTest 24 | public class QueueCorrect1 { 25 | private LockFreeQueue q = new LockFreeQueue<>(); 26 | 27 | @Operation 28 | public void add(@Param(gen = IntGen.class) int value) { 29 | q.add(value); 30 | } 31 | 32 | @Operation 33 | public Object takeOrNull() { 34 | return q.takeOrNull(); 35 | } 36 | 37 | // @Test TODO is it really correct? 38 | public void test() { 39 | LinChecker.check(QueueCorrect1.class); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /libtest/src/test/java/com/devexperts/dxlab/lincheck/tests/romix/TrieCorrect1.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Lincheck - Linearizability checker 3 | * 4 | * Copyright (C) 2015-2022 Devexperts, LLC 5 | * Copyright (C) 2023 Devexperts Ireland Limited 6 | * 7 | * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. 8 | * If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | 11 | package com.devexperts.dxlab.lincheck.tests.romix; 12 | 13 | import com.devexperts.dxlab.lincheck.LinChecker; 14 | import com.devexperts.dxlab.lincheck.annotations.Operation; 15 | import com.devexperts.dxlab.lincheck.annotations.Param; 16 | import com.devexperts.dxlab.lincheck.paramgen.IntGen; 17 | import com.devexperts.dxlab.lincheck.strategy.stress.StressCTest; 18 | import org.junit.Test; 19 | import romix.scala.collection.concurrent.TrieMap; 20 | 21 | import java.util.Map; 22 | 23 | @StressCTest 24 | @Param(name = "key", gen = IntGen.class) 25 | @Param(name = "value", gen = IntGen.class) 26 | public class TrieCorrect1 { 27 | private Map m = new TrieMap<>(); 28 | 29 | @Operation(params = {"key", "value"}) 30 | public Integer put(Integer key, Integer value) { 31 | return m.put(key, value); 32 | } 33 | 34 | @Operation(params = {"key"}) 35 | public Integer get(Integer key) { 36 | return m.get(key); 37 | } 38 | 39 | @Test 40 | public void test() { 41 | LinChecker.check(TrieCorrect1.class); 42 | } 43 | } 44 | 45 | -------------------------------------------------------------------------------- /libtest/src/test/java/com/devexperts/dxlab/lincheck/tests/zchannel/QueueCorrect1.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Lincheck - Linearizability checker 3 | * 4 | * Copyright (C) 2015-2022 Devexperts, LLC 5 | * Copyright (C) 2023 Devexperts Ireland Limited 6 | * 7 | * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. 8 | * If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | 11 | package com.devexperts.dxlab.lincheck.tests.zchannel; 12 | 13 | import com.devexperts.dxlab.lincheck.LinChecker; 14 | import com.devexperts.dxlab.lincheck.annotations.Operation; 15 | import com.devexperts.dxlab.lincheck.annotations.Param; 16 | import com.devexperts.dxlab.lincheck.paramgen.IntGen; 17 | import com.devexperts.dxlab.lincheck.strategy.stress.StressCTest; 18 | import z.channel.GenericMPMCQueue; 19 | 20 | /** 21 | * http://landz.github.io/ 22 | */ 23 | @StressCTest 24 | public class QueueCorrect1 { 25 | private GenericMPMCQueue q = new GenericMPMCQueue<>(4); 26 | 27 | @Operation 28 | public boolean offer(@Param(gen = IntGen.class) int value) { 29 | return q.offer(value); 30 | } 31 | 32 | @Operation 33 | public Integer poll() { 34 | return q.poll(); 35 | } 36 | 37 | // @Test TODO is it really correct? 38 | public void test() throws Exception { 39 | LinChecker.check(QueueCorrect1.class); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /libtest/src/test/java/com/devexperts/dxlab/lincheck/tests/zchannel/QueueCorrect2.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Lincheck - Linearizability checker 3 | * 4 | * Copyright (C) 2015-2022 Devexperts, LLC 5 | * Copyright (C) 2023 Devexperts Ireland Limited 6 | * 7 | * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. 8 | * If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | 11 | package com.devexperts.dxlab.lincheck.tests.zchannel; 12 | 13 | import com.devexperts.dxlab.lincheck.LinChecker; 14 | import com.devexperts.dxlab.lincheck.annotations.Operation; 15 | import com.devexperts.dxlab.lincheck.annotations.Param; 16 | import com.devexperts.dxlab.lincheck.paramgen.IntGen; 17 | import com.devexperts.dxlab.lincheck.strategy.stress.StressCTest; 18 | import z.channel.GenericMPMCQueue; 19 | 20 | /** 21 | * http://landz.github.io/ 22 | */ 23 | @StressCTest 24 | public class QueueCorrect2 { 25 | private GenericMPMCQueue q = new GenericMPMCQueue<>(16); 26 | 27 | @Operation 28 | public boolean offer(@Param(gen = IntGen.class) int value) { 29 | return q.offer(value); 30 | } 31 | 32 | @Operation 33 | public Integer poll() { 34 | return q.poll(); 35 | } 36 | 37 | // @Test TODO is it really correct? 38 | public void test() throws Exception { 39 | LinChecker.check(QueueCorrect2.class); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /lincheck/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 13 | com.devexperts.lincheck 14 | lincheck-all 15 | 3.1-SNAPSHOT 16 | 17 | 4.0.0 18 | 19 | lincheck 20 | Lincheck 21 | 22 | 23 | 24 | org.ow2.asm 25 | asm-all 26 | 5.2 27 | 28 | 29 | com.devexperts.jagent 30 | jagent-impl 31 | 1.4 32 | 33 | 34 | 35 | org.jctools 36 | jctools-core 37 | 2.1.0 38 | test 39 | 40 | 41 | org.jetbrains.kotlinx 42 | atomicfu 43 | 0.9.1 44 | test 45 | 46 | 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /lincheck/src/main/java/com/devexperts/dxlab/lincheck/Actor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Lincheck - Linearizability checker 3 | * 4 | * Copyright (C) 2015-2022 Devexperts, LLC 5 | * Copyright (C) 2023 Devexperts Ireland Limited 6 | * 7 | * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. 8 | * If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | 11 | package com.devexperts.dxlab.lincheck; 12 | 13 | import com.devexperts.dxlab.lincheck.annotations.Operation; 14 | 15 | import java.lang.reflect.Method; 16 | import java.util.List; 17 | import java.util.stream.Collectors; 18 | import java.util.stream.Stream; 19 | 20 | /** 21 | * The actor entity describe the operation with its parameters 22 | * which is executed during the testing. 23 | * 24 | * @see Operation 25 | */ 26 | public class Actor { 27 | public final Method method; 28 | public final Object[] arguments; 29 | public final List> handledExceptions; 30 | 31 | public Actor(Method method, List arguments, List> handledExceptions) { 32 | this(method, arguments.toArray(), handledExceptions); 33 | } 34 | 35 | public Actor(Method method, Object[] arguments, List> handledExceptions) { 36 | this.method = method; 37 | this.arguments = arguments; 38 | this.handledExceptions = handledExceptions; 39 | } 40 | 41 | @Override 42 | public String toString() { 43 | return method.getName() + "(" + Stream.of(arguments).map(Object::toString).collect(Collectors.joining(", ")) + ")"; 44 | } 45 | 46 | public boolean handlesExceptions() { 47 | return !handledExceptions.isEmpty(); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /lincheck/src/main/java/com/devexperts/dxlab/lincheck/ExecutionClassLoader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Lincheck - Linearizability checker 3 | * 4 | * Copyright (C) 2015-2022 Devexperts, LLC 5 | * Copyright (C) 2023 Devexperts Ireland Limited 6 | * 7 | * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. 8 | * If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | 11 | package com.devexperts.dxlab.lincheck; 12 | 13 | import com.devexperts.dxlab.lincheck.runner.TestThreadExecution; 14 | 15 | /** 16 | * This classloader is mostly used by runner in order to separate parallel iterations, 17 | * and define generated {@link TestThreadExecution test executions}. 18 | */ 19 | public class ExecutionClassLoader extends ClassLoader { 20 | public Class defineClass(String className, byte[] bytecode) { 21 | return (Class) super.defineClass(className, bytecode, 0, bytecode.length); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /lincheck/src/main/java/com/devexperts/dxlab/lincheck/annotations/LogLevel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Lincheck - Linearizability checker 3 | * 4 | * Copyright (C) 2015-2022 Devexperts, LLC 5 | * Copyright (C) 2023 Devexperts Ireland Limited 6 | * 7 | * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. 8 | * If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | 11 | package com.devexperts.dxlab.lincheck.annotations; 12 | 13 | import com.devexperts.dxlab.lincheck.LoggingLevel; 14 | 15 | import java.lang.annotation.ElementType; 16 | import java.lang.annotation.Inherited; 17 | import java.lang.annotation.Retention; 18 | import java.lang.annotation.RetentionPolicy; 19 | import java.lang.annotation.Target; 20 | 21 | /** 22 | * This annotation should be added to a test class 23 | * to specify logging level. By default {@link LoggingLevel#ERROR} is used. 24 | */ 25 | @Retention(RetentionPolicy.RUNTIME) 26 | @Target(ElementType.TYPE) 27 | @Inherited 28 | public @interface LogLevel { 29 | LoggingLevel value(); 30 | } 31 | -------------------------------------------------------------------------------- /lincheck/src/main/java/com/devexperts/dxlab/lincheck/annotations/OpGroupConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Lincheck - Linearizability checker 3 | * 4 | * Copyright (C) 2015-2022 Devexperts, LLC 5 | * Copyright (C) 2023 Devexperts Ireland Limited 6 | * 7 | * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. 8 | * If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | 11 | package com.devexperts.dxlab.lincheck.annotations; 12 | 13 | import java.lang.annotation.ElementType; 14 | import java.lang.annotation.Inherited; 15 | import java.lang.annotation.Repeatable; 16 | import java.lang.annotation.Retention; 17 | import java.lang.annotation.RetentionPolicy; 18 | import java.lang.annotation.Target; 19 | 20 | /** 21 | * Set some restrictions to the group with the specified name, 22 | * used during the scenario generation phase. 23 | */ 24 | @Retention(RetentionPolicy.RUNTIME) 25 | @Target(ElementType.TYPE) 26 | @Repeatable(OpGroupConfig.OpGroupConfigs.class) 27 | @Inherited 28 | public @interface OpGroupConfig { 29 | /** 30 | * Name of this group used by {@link Operation#group()}. 31 | */ 32 | String name() default ""; 33 | 34 | /** 35 | * Set it to {@code true} for executing all actors in this group 36 | * from one thread. This restriction allows to test single-reader 37 | * and/or single-writer data structures and similar solutions. 38 | */ 39 | boolean nonParallel() default false; 40 | 41 | /** 42 | * Holder annotation for {@link OpGroupConfig}. 43 | * Not a public API. 44 | */ 45 | @Retention(RetentionPolicy.RUNTIME) 46 | @Target(ElementType.TYPE) 47 | @Inherited 48 | @interface OpGroupConfigs { 49 | OpGroupConfig[] value(); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /lincheck/src/main/java/com/devexperts/dxlab/lincheck/annotations/Operation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Lincheck - Linearizability checker 3 | * 4 | * Copyright (C) 2015-2022 Devexperts, LLC 5 | * Copyright (C) 2023 Devexperts Ireland Limited 6 | * 7 | * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. 8 | * If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | 11 | package com.devexperts.dxlab.lincheck.annotations; 12 | 13 | import java.lang.annotation.ElementType; 14 | import java.lang.annotation.Retention; 15 | import java.lang.annotation.RetentionPolicy; 16 | import java.lang.annotation.Target; 17 | 18 | /** 19 | * Mark your method with this annotation in order 20 | * to use it in concurrent testing as an operation. 21 | */ 22 | @Retention(RetentionPolicy.RUNTIME) 23 | @Target(ElementType.METHOD) 24 | public @interface Operation { 25 | /** 26 | * Binds the arguments of this operations with the specified {@link Param parameter configurations} 27 | * by theirs {@link Param#name()} names 28 | */ 29 | String[] params() default {}; 30 | 31 | /** 32 | * Set it to {@code true} if you this operation should be called 33 | * at most once during the test invocation; {@code false} by default. 34 | */ 35 | boolean runOnce() default false; 36 | 37 | /** 38 | * Specifies the operation group which can add some execution restriction. 39 | * @see OpGroupConfig#name() 40 | */ 41 | String group() default ""; 42 | 43 | /** 44 | * Handle the specified exceptions as a result of this operation invocation. 45 | */ 46 | Class[] handleExceptionsAsResult() default {}; 47 | } 48 | -------------------------------------------------------------------------------- /lincheck/src/main/java/com/devexperts/dxlab/lincheck/execution/ActorGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Lincheck - Linearizability checker 3 | * 4 | * Copyright (C) 2015-2022 Devexperts, LLC 5 | * Copyright (C) 2023 Devexperts Ireland Limited 6 | * 7 | * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. 8 | * If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | 11 | package com.devexperts.dxlab.lincheck.execution; 12 | 13 | import com.devexperts.dxlab.lincheck.Actor; 14 | import com.devexperts.dxlab.lincheck.paramgen.ParameterGenerator; 15 | 16 | import java.lang.reflect.Method; 17 | import java.util.List; 18 | import java.util.stream.Collectors; 19 | 20 | /** 21 | * Implementations of this class generate {@link Actor actors} 22 | * using {@link ParameterGenerator parameter generators}. 23 | */ 24 | public class ActorGenerator { 25 | private final Method method; 26 | private final List> parameterGenerators; 27 | private final List> handledExceptions; 28 | private final boolean useOnce; 29 | 30 | public ActorGenerator(Method method, List> parameterGenerators, 31 | List> handledExceptions, boolean useOnce) 32 | { 33 | this.method = method; 34 | this.parameterGenerators = parameterGenerators; 35 | this.handledExceptions = handledExceptions; 36 | this.useOnce = useOnce; 37 | } 38 | 39 | public Actor generate() { 40 | return new Actor(method, parameterGenerators.stream() 41 | .map(ParameterGenerator::generate).collect(Collectors.toList()), handledExceptions); 42 | } 43 | 44 | public boolean useOnce() { 45 | return useOnce; 46 | } 47 | 48 | @Override 49 | public String toString() { 50 | return method.toString(); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /lincheck/src/main/java/com/devexperts/dxlab/lincheck/execution/ExecutionGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Lincheck - Linearizability checker 3 | * 4 | * Copyright (C) 2015-2022 Devexperts, LLC 5 | * Copyright (C) 2023 Devexperts Ireland Limited 6 | * 7 | * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. 8 | * If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | 11 | package com.devexperts.dxlab.lincheck.execution; 12 | 13 | import com.devexperts.dxlab.lincheck.CTestConfiguration; 14 | import com.devexperts.dxlab.lincheck.CTestStructure; 15 | 16 | /** 17 | * Implementation of this interface generates execution scenarios. 18 | * By default, {@link RandomExecutionGenerator} is used. 19 | *

20 | * IMPORTANT! 21 | * All implementations should have the same constructor as {@link ExecutionGenerator} has. 22 | */ 23 | public abstract class ExecutionGenerator { 24 | protected final CTestConfiguration testConfiguration; 25 | protected final CTestStructure testStructure; 26 | 27 | protected ExecutionGenerator(CTestConfiguration testConfiguration, CTestStructure testStructure) { 28 | this.testConfiguration = testConfiguration; 29 | this.testStructure = testStructure; 30 | } 31 | 32 | public abstract ExecutionScenario nextExecution(); 33 | } 34 | -------------------------------------------------------------------------------- /lincheck/src/main/java/com/devexperts/dxlab/lincheck/execution/ExecutionScenario.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Lincheck - Linearizability checker 3 | * 4 | * Copyright (C) 2015-2022 Devexperts, LLC 5 | * Copyright (C) 2023 Devexperts Ireland Limited 6 | * 7 | * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. 8 | * If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | 11 | package com.devexperts.dxlab.lincheck.execution; 12 | 13 | import com.devexperts.dxlab.lincheck.Actor; 14 | import com.devexperts.dxlab.lincheck.strategy.Strategy; 15 | 16 | import java.util.List; 17 | 18 | /** 19 | * This class represents an execution scenario, which 20 | * is generated by an {@link ExecutionGenerator} and then \ 21 | * used by a {@link Strategy} which produces an {@link ExecutionResult}. 22 | */ 23 | public class ExecutionScenario { 24 | /** 25 | * The initial sequential part of the execution. 26 | * It helps to produce different initial states 27 | * before the parallel part. 28 | */ 29 | public final List initExecution; 30 | /** 31 | * The parallel part of the execution, which is used 32 | * to find an interleaving with incorrect behaviour. 33 | */ 34 | public final List> parallelExecution; 35 | /** 36 | * The last sequential part is used to test that 37 | * the data structure is in a correct state. 38 | */ 39 | public final List postExecution; 40 | 41 | public ExecutionScenario(List initExecution, List> parallelExecution, List postExecution) { 42 | this.initExecution = initExecution; 43 | this.parallelExecution = parallelExecution; 44 | this.postExecution = postExecution; 45 | } 46 | 47 | /** 48 | * Returns the number of threads used in 49 | * the parallel part of this execution. 50 | */ 51 | public int getThreads() { 52 | return parallelExecution.size(); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /lincheck/src/main/java/com/devexperts/dxlab/lincheck/paramgen/ByteGen.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Lincheck - Linearizability checker 3 | * 4 | * Copyright (C) 2015-2022 Devexperts, LLC 5 | * Copyright (C) 2023 Devexperts Ireland Limited 6 | * 7 | * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. 8 | * If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | 11 | package com.devexperts.dxlab.lincheck.paramgen; 12 | 13 | public class ByteGen implements ParameterGenerator { 14 | private final IntGen intGen; 15 | 16 | public ByteGen(String configuration) { 17 | intGen = new IntGen(configuration); 18 | intGen.checkRange(Byte.MIN_VALUE, Byte.MAX_VALUE, "byte"); 19 | } 20 | 21 | public Byte generate() { 22 | return (byte) (int) intGen.generate(); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /lincheck/src/main/java/com/devexperts/dxlab/lincheck/paramgen/FloatGen.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Lincheck - Linearizability checker 3 | * 4 | * Copyright (C) 2015-2022 Devexperts, LLC 5 | * Copyright (C) 2023 Devexperts Ireland Limited 6 | * 7 | * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. 8 | * If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | 11 | package com.devexperts.dxlab.lincheck.paramgen; 12 | 13 | public class FloatGen implements ParameterGenerator { 14 | private final DoubleGen doubleGen; 15 | 16 | public FloatGen(String configuration) { 17 | doubleGen = new DoubleGen(configuration); 18 | } 19 | 20 | public Float generate() { 21 | return (float) (double) doubleGen.generate(); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /lincheck/src/main/java/com/devexperts/dxlab/lincheck/paramgen/IntGen.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Lincheck - Linearizability checker 3 | * 4 | * Copyright (C) 2015-2022 Devexperts, LLC 5 | * Copyright (C) 2023 Devexperts Ireland Limited 6 | * 7 | * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. 8 | * If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | 11 | package com.devexperts.dxlab.lincheck.paramgen; 12 | 13 | import java.util.Random; 14 | 15 | public class IntGen implements ParameterGenerator { 16 | private static final int DEFAULT_BEGIN = -10; 17 | private static final int DEFAULT_END = 10; 18 | 19 | private final Random random = new Random(0); 20 | private final int begin; 21 | private final int end; 22 | 23 | public IntGen(String configuration) { 24 | if (configuration.isEmpty()) { // use default configuration 25 | begin = DEFAULT_BEGIN; 26 | end = DEFAULT_END; 27 | return; 28 | } 29 | String[] args = configuration.replaceAll("\\s", "").split(":"); 30 | switch (args.length) { 31 | case 2: // begin:end 32 | begin = Integer.parseInt(args[0]); 33 | end = Integer.parseInt(args[1]); 34 | break; 35 | default: 36 | throw new IllegalArgumentException("Configuration should have " + 37 | "two arguments (begin and end) separated by comma"); 38 | } 39 | } 40 | 41 | public Integer generate() { 42 | return begin + random.nextInt(end - begin + 1); 43 | } 44 | 45 | void checkRange(int min, int max, String type) { 46 | if (this.begin < min || this.end - 1 > max) { 47 | throw new IllegalArgumentException("Illegal range for " 48 | + type + " type: [" + begin + "; " + end + ")"); 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /lincheck/src/main/java/com/devexperts/dxlab/lincheck/paramgen/LongGen.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Lincheck - Linearizability checker 3 | * 4 | * Copyright (C) 2015-2022 Devexperts, LLC 5 | * Copyright (C) 2023 Devexperts Ireland Limited 6 | * 7 | * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. 8 | * If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | 11 | package com.devexperts.dxlab.lincheck.paramgen; 12 | 13 | public class LongGen implements ParameterGenerator { 14 | private final IntGen intGen; 15 | 16 | public LongGen(String configuration) { 17 | intGen = new IntGen(configuration); 18 | } 19 | 20 | public Long generate() { 21 | return (long) intGen.generate(); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /lincheck/src/main/java/com/devexperts/dxlab/lincheck/paramgen/ParameterGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Lincheck - Linearizability checker 3 | * 4 | * Copyright (C) 2015-2022 Devexperts, LLC 5 | * Copyright (C) 2023 Devexperts Ireland Limited 6 | * 7 | * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. 8 | * If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | 11 | package com.devexperts.dxlab.lincheck.paramgen; 12 | 13 | import com.devexperts.dxlab.lincheck.annotations.Operation; 14 | 15 | /** 16 | * The implementation of this interface is used to generate parameters 17 | * for {@link Operation operation}. 18 | */ 19 | public interface ParameterGenerator { 20 | T generate(); 21 | 22 | final class Dummy implements ParameterGenerator { 23 | @Override 24 | public Object generate() { 25 | throw new UnsupportedOperationException(); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /lincheck/src/main/java/com/devexperts/dxlab/lincheck/paramgen/ShortGen.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Lincheck - Linearizability checker 3 | * 4 | * Copyright (C) 2015-2022 Devexperts, LLC 5 | * Copyright (C) 2023 Devexperts Ireland Limited 6 | * 7 | * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. 8 | * If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | 11 | package com.devexperts.dxlab.lincheck.paramgen; 12 | 13 | public class ShortGen implements ParameterGenerator { 14 | private final IntGen intGen; 15 | 16 | public ShortGen(String configuration) { 17 | intGen = new IntGen(configuration); 18 | intGen.checkRange(Short.MIN_VALUE, Short.MAX_VALUE, "short"); 19 | } 20 | 21 | public Short generate() { 22 | return (short) (int) intGen.generate(); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /lincheck/src/main/java/com/devexperts/dxlab/lincheck/paramgen/StringGen.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Lincheck - Linearizability checker 3 | * 4 | * Copyright (C) 2015-2022 Devexperts, LLC 5 | * Copyright (C) 2023 Devexperts Ireland Limited 6 | * 7 | * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. 8 | * If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | 11 | package com.devexperts.dxlab.lincheck.paramgen; 12 | 13 | import java.util.Random; 14 | 15 | public class StringGen implements ParameterGenerator { 16 | private static final int DEFAULT_MAX_WORD_LENGTH = 15; 17 | private static final String DEFAULT_ALPHABET = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_ "; 18 | 19 | private final Random random = new Random(0); 20 | private final int maxWordLength; 21 | private final String alphabet; 22 | 23 | public StringGen(String configuration) { 24 | if (configuration.isEmpty()) { // use default configuration 25 | maxWordLength = DEFAULT_MAX_WORD_LENGTH; 26 | alphabet = DEFAULT_ALPHABET; 27 | return; 28 | } 29 | int firstCommaIndex = configuration.indexOf(':'); 30 | if (firstCommaIndex < 0) { // maxWordLength only 31 | maxWordLength = Integer.parseInt(configuration); 32 | alphabet = DEFAULT_ALPHABET; 33 | } else { // maxWordLength:alphabet 34 | maxWordLength = Integer.parseInt(configuration.substring(0, firstCommaIndex)); 35 | alphabet = configuration.substring(firstCommaIndex + 1); 36 | } 37 | } 38 | 39 | public String generate() { 40 | char[] cs = new char[random.nextInt(maxWordLength)]; 41 | for (int i = 0; i < cs.length; i++) 42 | cs[i] = alphabet.charAt(random.nextInt(alphabet.length())); 43 | return new String(cs); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /lincheck/src/main/java/com/devexperts/dxlab/lincheck/runner/TestThreadExecution.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Lincheck - Linearizability checker 3 | * 4 | * Copyright (C) 2015-2022 Devexperts, LLC 5 | * Copyright (C) 2023 Devexperts Ireland Limited 6 | * 7 | * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. 8 | * If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | 11 | package com.devexperts.dxlab.lincheck.runner; 12 | 13 | import com.devexperts.dxlab.lincheck.Result; 14 | 15 | import java.util.concurrent.Callable; 16 | 17 | /** 18 | * Instance of this class represents the test execution for ONE thread. Several instances should be ran in parallel. 19 | * All implementations of this class should be generated via {@link TestThreadExecutionGenerator}. 20 | * 21 | *

This class should be public for having access from generated classes. 22 | */ 23 | public abstract class TestThreadExecution implements Callable { 24 | // The following fields are assigned in TestThreadExecutionGenerator 25 | protected Runner runner; 26 | public Object testInstance; 27 | protected Object[] objArgs; 28 | public int[] waits; // for StressStrategy 29 | 30 | // It is better to return List, 31 | // but such implementation requires to have a synthetic 32 | // method to support generics and the byte-code generation 33 | // is more bug-prone. If you need to use 34 | // List, see Arrays.asList(..) method. 35 | public abstract Result[] call(); 36 | } 37 | -------------------------------------------------------------------------------- /lincheck/src/main/java/com/devexperts/dxlab/lincheck/strategy/ManagedStrategyHolder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Lincheck - Linearizability checker 3 | * 4 | * Copyright (C) 2015-2022 Devexperts, LLC 5 | * Copyright (C) 2023 Devexperts Ireland Limited 6 | * 7 | * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. 8 | * If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | 11 | package com.devexperts.dxlab.lincheck.strategy; 12 | 13 | /** 14 | * This utility class helps to hold the current strategy. In order to run several tests in parallel, 15 | * every iteration have to use its own class loader, thus this holder is not shared between them. 16 | */ 17 | public class ManagedStrategyHolder { 18 | public static ManagedStrategy strategy; 19 | 20 | /** 21 | * Sets the specified strategy in the specified class loader. 22 | */ 23 | public static void setStrategy(ClassLoader loader, ManagedStrategy strategy) { 24 | try { 25 | Class clazz = loader.loadClass(ManagedStrategyHolder.class.getCanonicalName()); 26 | clazz.getField("strategy").set(null, strategy); 27 | } catch (ClassNotFoundException | IllegalAccessException | NoSuchFieldException e) { 28 | throw new IllegalStateException("Cannot set strategy to ManagedStrategyHolder", e); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /lincheck/src/main/java/com/devexperts/dxlab/lincheck/strategy/randomswitch/RandomSwitchCTestConfiguration.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Lincheck - Linearizability checker 3 | * 4 | * Copyright (C) 2015-2022 Devexperts, LLC 5 | * Copyright (C) 2023 Devexperts Ireland Limited 6 | * 7 | * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. 8 | * If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | 11 | package com.devexperts.dxlab.lincheck.strategy.randomswitch; 12 | 13 | import com.devexperts.dxlab.lincheck.CTestConfiguration; 14 | import com.devexperts.dxlab.lincheck.execution.ExecutionGenerator; 15 | import com.devexperts.dxlab.lincheck.verifier.Verifier; 16 | 17 | /** 18 | * Configuration for {@link RandomSwitchStrategy random-switch} strategy. 19 | */ 20 | public class RandomSwitchCTestConfiguration extends CTestConfiguration { 21 | public static final int DEFAULT_INVOCATIONS = 1_000; 22 | 23 | public final int invocationsPerIteration; 24 | 25 | public RandomSwitchCTestConfiguration(int iterations, int threads, int actorsPerThread, int actorsBefore, 26 | int actorsAfter, Class generatorClass, Class verifierClass, 27 | int invocationsPerIteration) 28 | { 29 | super(iterations, threads, actorsPerThread, actorsBefore, actorsAfter, generatorClass, verifierClass); 30 | this.invocationsPerIteration = invocationsPerIteration; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /lincheck/src/main/java/com/devexperts/dxlab/lincheck/strategy/randomswitch/RandomSwitchOptions.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Lincheck - Linearizability checker 3 | * 4 | * Copyright (C) 2015-2022 Devexperts, LLC 5 | * Copyright (C) 2023 Devexperts Ireland Limited 6 | * 7 | * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. 8 | * If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | 11 | package com.devexperts.dxlab.lincheck.strategy.randomswitch; 12 | 13 | import com.devexperts.dxlab.lincheck.Options; 14 | 15 | /** 16 | * Options for {@link RandomSwitchStrategy random-switch} strategy. 17 | */ 18 | public class RandomSwitchOptions extends Options { 19 | protected int invocationsPerIteration = RandomSwitchCTestConfiguration.DEFAULT_INVOCATIONS; 20 | 21 | /** 22 | * Run each test scenario {@code invocations} times. 23 | */ 24 | public RandomSwitchOptions invocationsPerIteration(int invocations) { 25 | this.invocationsPerIteration = invocations; 26 | return this; 27 | } 28 | 29 | @Override 30 | public RandomSwitchCTestConfiguration createTestConfigurations() { 31 | return new RandomSwitchCTestConfiguration(iterations, threads, actorsPerThread, actorsBefore, actorsAfter, 32 | executionGenerator, verifier, invocationsPerIteration); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /lincheck/src/main/java/com/devexperts/dxlab/lincheck/strategy/stress/StressCTestConfiguration.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Lincheck - Linearizability checker 3 | * 4 | * Copyright (C) 2015-2022 Devexperts, LLC 5 | * Copyright (C) 2023 Devexperts Ireland Limited 6 | * 7 | * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. 8 | * If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | 11 | package com.devexperts.dxlab.lincheck.strategy.stress; 12 | 13 | import com.devexperts.dxlab.lincheck.CTestConfiguration; 14 | import com.devexperts.dxlab.lincheck.execution.ExecutionGenerator; 15 | import com.devexperts.dxlab.lincheck.verifier.Verifier; 16 | 17 | /** 18 | * Configuration for {@link StressStrategy stress} strategy. 19 | */ 20 | public class StressCTestConfiguration extends CTestConfiguration { 21 | public static final int DEFAULT_INVOCATIONS = 1_000; 22 | 23 | public final int invocationsPerIteration; 24 | public final boolean addWaits; 25 | 26 | public StressCTestConfiguration(int iterations, int threads, int actorsPerThread, int actorsBefore, int actorsAfter, 27 | Class generatorClass, Class verifierClass, 28 | int invocationsPerIteration, boolean addWaits) 29 | { 30 | super(iterations, threads, actorsPerThread, actorsBefore, actorsAfter, generatorClass, verifierClass); 31 | this.invocationsPerIteration = invocationsPerIteration; 32 | this.addWaits = addWaits; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /lincheck/src/main/java/com/devexperts/dxlab/lincheck/strategy/stress/StressOptions.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Lincheck - Linearizability checker 3 | * 4 | * Copyright (C) 2015-2022 Devexperts, LLC 5 | * Copyright (C) 2023 Devexperts Ireland Limited 6 | * 7 | * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. 8 | * If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | 11 | package com.devexperts.dxlab.lincheck.strategy.stress; 12 | 13 | import com.devexperts.dxlab.lincheck.Options; 14 | 15 | /** 16 | * Options for {@link StressStrategy stress} strategy. 17 | */ 18 | public class StressOptions extends Options { 19 | protected int invocationsPerIteration = StressCTestConfiguration.DEFAULT_INVOCATIONS; 20 | protected boolean addWaits = true; 21 | 22 | /** 23 | * Run each test scenario {@code invocations} times. 24 | */ 25 | public StressOptions invocationsPerIteration(int invocations) { 26 | this.invocationsPerIteration = invocations; 27 | return this; 28 | } 29 | 30 | /** 31 | * Set this to {@code false} to disable random waits between operations, enabled by default. 32 | */ 33 | public StressOptions addWaits(boolean value) { 34 | addWaits = value; 35 | return this; 36 | } 37 | 38 | @Override 39 | public StressCTestConfiguration createTestConfigurations() { 40 | return new StressCTestConfiguration(iterations, threads, actorsPerThread, actorsBefore, actorsAfter, 41 | executionGenerator, verifier, invocationsPerIteration, addWaits); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /lincheck/src/main/java/com/devexperts/dxlab/lincheck/verifier/CachedVerifier.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Lincheck - Linearizability checker 3 | * 4 | * Copyright (C) 2015-2022 Devexperts, LLC 5 | * Copyright (C) 2023 Devexperts Ireland Limited 6 | * 7 | * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. 8 | * If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | 11 | package com.devexperts.dxlab.lincheck.verifier; 12 | 13 | import com.devexperts.dxlab.lincheck.execution.ExecutionResult; 14 | 15 | import java.util.HashSet; 16 | import java.util.Set; 17 | 18 | /** 19 | * This verifier cached the already verified results in a hash table, 20 | * and look into this hash table at first. In case of many invocations 21 | * with the same scenario, this optimization improves the verification 22 | * phase significantly. 23 | */ 24 | public abstract class CachedVerifier implements Verifier { 25 | private final Set previousResults = new HashSet<>(); 26 | 27 | @Override 28 | public final boolean verifyResults(ExecutionResult results) { 29 | if (!previousResults.add(results)) 30 | return true; 31 | return verifyResultsImpl(results); 32 | } 33 | 34 | public abstract boolean verifyResultsImpl(ExecutionResult results); 35 | } 36 | -------------------------------------------------------------------------------- /lincheck/src/main/java/com/devexperts/dxlab/lincheck/verifier/EpsilonVerifier.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Lincheck - Linearizability checker 3 | * 4 | * Copyright (C) 2015-2022 Devexperts, LLC 5 | * Copyright (C) 2023 Devexperts Ireland Limited 6 | * 7 | * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. 8 | * If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | 11 | package com.devexperts.dxlab.lincheck.verifier; 12 | 13 | import com.devexperts.dxlab.lincheck.execution.ExecutionResult; 14 | import com.devexperts.dxlab.lincheck.execution.ExecutionScenario; 15 | 16 | /** 17 | * This verifier does nothing and could be used for performance benchmarking. 18 | */ 19 | public class EpsilonVerifier implements Verifier { 20 | 21 | public EpsilonVerifier(ExecutionScenario scenario, Class testClass) {} 22 | 23 | @Override 24 | public boolean verifyResults(ExecutionResult results) { 25 | return true; // Always correct results :) 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /lincheck/src/main/java/com/devexperts/dxlab/lincheck/verifier/Verifier.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Lincheck - Linearizability checker 3 | * 4 | * Copyright (C) 2015-2022 Devexperts, LLC 5 | * Copyright (C) 2023 Devexperts Ireland Limited 6 | * 7 | * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. 8 | * If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | 11 | package com.devexperts.dxlab.lincheck.verifier; 12 | 13 | import com.devexperts.dxlab.lincheck.execution.ExecutionResult; 14 | import com.devexperts.dxlab.lincheck.verifier.linearizability.LinearizabilityVerifier; 15 | 16 | /** 17 | * Implementation of this interface verifies that execution is correct with respect to the algorithm contract. 18 | * By default, {@link LinearizabilityVerifier} is used. 19 | *

20 | * IMPORTANT! 21 | * All implementations should have {@code (ExecutionScenario scenario, Class testClass)} constructor. 22 | */ 23 | public interface Verifier { 24 | /** 25 | * Verifies the specified results for correctness. 26 | * Returns {@code true} if results are possible, {@code false} otherwise. 27 | */ 28 | boolean verifyResults(ExecutionResult results); 29 | } 30 | -------------------------------------------------------------------------------- /lincheck/src/main/java/com/devexperts/dxlab/lincheck/verifier/quantitative/IterativePathCostFunctionCounter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Lincheck - Linearizability checker 3 | * 4 | * Copyright (C) 2015-2022 Devexperts, LLC 5 | * Copyright (C) 2023 Devexperts Ireland Limited 6 | * 7 | * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. 8 | * If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | 11 | package com.devexperts.dxlab.lincheck.verifier.quantitative; 12 | 13 | /** 14 | * Implementation of this interface counts path cost incrementally. 15 | */ 16 | interface IterativePathCostFunctionCounter { 17 | 18 | /** 19 | * Returns next path cost counter with the required information for incremental counting 20 | * if the transition is possible, {@code null} if the transition is not satisfied. 21 | * 22 | * @param costWithNextCostCounter describes the transition 23 | */ 24 | IterativePathCostFunctionCounter next(CostWithNextCostCounter costWithNextCostCounter); 25 | } 26 | -------------------------------------------------------------------------------- /lincheck/src/main/java/com/devexperts/dxlab/lincheck/verifier/quantitative/QuantitativeRelaxed.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Lincheck - Linearizability checker 3 | * 4 | * Copyright (C) 2015-2022 Devexperts, LLC 5 | * Copyright (C) 2023 Devexperts Ireland Limited 6 | * 7 | * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. 8 | * If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | 11 | package com.devexperts.dxlab.lincheck.verifier.quantitative; 12 | 13 | import java.lang.annotation.ElementType; 14 | import java.lang.annotation.Retention; 15 | import java.lang.annotation.RetentionPolicy; 16 | import java.lang.annotation.Target; 17 | 18 | /** 19 | * This annotation indicates that the method it is presented on is relaxed 20 | * in accordance with a contract for {@link QuantitativeRelaxationVerifier}. 21 | */ 22 | @Retention(RetentionPolicy.RUNTIME) 23 | @Target(ElementType.METHOD) 24 | public @interface QuantitativeRelaxed { 25 | // String group() default ""; todo: introduce relaxation groups in order to count path functions separately 26 | } 27 | -------------------------------------------------------------------------------- /lincheck/src/main/java/com/devexperts/dxlab/lincheck/verifier/quasi/QuasiLinearizabilityVerifierConf.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Lincheck - Linearizability checker 3 | * 4 | * Copyright (C) 2015-2022 Devexperts, LLC 5 | * Copyright (C) 2023 Devexperts Ireland Limited 6 | * 7 | * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. 8 | * If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | 11 | package com.devexperts.dxlab.lincheck.verifier.quasi; 12 | 13 | import java.lang.annotation.ElementType; 14 | import java.lang.annotation.Retention; 15 | import java.lang.annotation.RetentionPolicy; 16 | import java.lang.annotation.Target; 17 | 18 | /** 19 | * This annotation with quasi-linearizability verifier 20 | * parameters should be presented on a test class 21 | * if the {@link QuasiLinearizabilityVerifier} is used. 22 | */ 23 | @Retention(RetentionPolicy.RUNTIME) 24 | @Target(ElementType.TYPE) 25 | public @interface QuasiLinearizabilityVerifierConf { 26 | /** 27 | * Relaxation factor. 28 | */ 29 | int factor(); 30 | 31 | /** 32 | * The sequential implementation of the 33 | * testing data structure with the same 34 | * methods as operations in the test class 35 | * (same name, signature), but with a 36 | * correct sequential implementations. 37 | * It also should have an empty constructor 38 | * which creates the initial state 39 | * (similar to the test class). 40 | */ 41 | Class sequentialImplementation(); 42 | } 43 | -------------------------------------------------------------------------------- /lincheck/src/main/java/com/devexperts/dxlab/lincheck/verifier/quiescent/QuiescentConsistent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Lincheck - Linearizability checker 3 | * 4 | * Copyright (C) 2015-2022 Devexperts, LLC 5 | * Copyright (C) 2023 Devexperts Ireland Limited 6 | * 7 | * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. 8 | * If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | 11 | package com.devexperts.dxlab.lincheck.verifier.quiescent; 12 | 13 | import java.lang.annotation.ElementType; 14 | import java.lang.annotation.Retention; 15 | import java.lang.annotation.RetentionPolicy; 16 | import java.lang.annotation.Target; 17 | 18 | /** 19 | * This annotation indicates that the method it is presented on 20 | * is quiescent consistent. 21 | * 22 | * @see QuiescentConsistencyVerifier 23 | */ 24 | @Retention(RetentionPolicy.RUNTIME) 25 | @Target(ElementType.METHOD) 26 | public @interface QuiescentConsistent { 27 | } 28 | -------------------------------------------------------------------------------- /lincheck/src/test/java/com/devexperts/dxlab/lincheck/test/ExceptionAsResultTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Lincheck - Linearizability checker 3 | * 4 | * Copyright (C) 2015-2022 Devexperts, LLC 5 | * Copyright (C) 2023 Devexperts Ireland Limited 6 | * 7 | * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. 8 | * If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | 11 | package com.devexperts.dxlab.lincheck.test; 12 | 13 | import com.devexperts.dxlab.lincheck.LinChecker; 14 | import com.devexperts.dxlab.lincheck.annotations.Operation; 15 | import com.devexperts.dxlab.lincheck.strategy.stress.StressCTest; 16 | import org.junit.Test; 17 | 18 | import java.io.IOException; 19 | 20 | @StressCTest(iterations = 1) 21 | public class ExceptionAsResultTest { 22 | @Operation(handleExceptionsAsResult = NullPointerException.class) 23 | public void npeIsOk() { 24 | ((String) null).charAt(0); 25 | } 26 | 27 | @Operation(handleExceptionsAsResult = Exception.class) 28 | public void subclassExceptionIsOk() throws Exception { 29 | throw new IOException(); 30 | } 31 | 32 | @Test 33 | public void test() { 34 | LinChecker.check(ExceptionAsResultTest.class); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /lincheck/src/test/java/com/devexperts/dxlab/lincheck/test/NonParallelOpGroupTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Lincheck - Linearizability checker 3 | * 4 | * Copyright (C) 2015-2022 Devexperts, LLC 5 | * Copyright (C) 2023 Devexperts Ireland Limited 6 | * 7 | * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. 8 | * If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | 11 | package com.devexperts.dxlab.lincheck.test; 12 | 13 | import com.devexperts.dxlab.lincheck.LinChecker; 14 | import com.devexperts.dxlab.lincheck.LoggingLevel; 15 | import com.devexperts.dxlab.lincheck.annotations.LogLevel; 16 | import com.devexperts.dxlab.lincheck.annotations.OpGroupConfig; 17 | import com.devexperts.dxlab.lincheck.annotations.Operation; 18 | import com.devexperts.dxlab.lincheck.annotations.Param; 19 | import com.devexperts.dxlab.lincheck.paramgen.IntGen; 20 | import com.devexperts.dxlab.lincheck.strategy.stress.StressCTest; 21 | import org.jctools.queues.atomic.SpscLinkedAtomicQueue; 22 | import org.junit.Test; 23 | 24 | import java.util.concurrent.atomic.AtomicInteger; 25 | 26 | @OpGroupConfig(name = "producer", nonParallel = true) 27 | @OpGroupConfig(name = "consumer", nonParallel = true) 28 | @StressCTest 29 | @LogLevel(LoggingLevel.DEBUG) 30 | public class NonParallelOpGroupTest { 31 | private SpscLinkedAtomicQueue queue = new SpscLinkedAtomicQueue<>(); 32 | private AtomicInteger i = new AtomicInteger(); 33 | 34 | @Operation(group = "producer") 35 | public void offer(@Param(gen = IntGen.class) Integer x) { 36 | queue.offer(x); 37 | } 38 | 39 | @Operation(group = "consumer") 40 | public Integer poll() { 41 | return queue.poll(); 42 | } 43 | 44 | @Operation 45 | public int incAndGet() { 46 | return i.incrementAndGet(); 47 | } 48 | 49 | @Test 50 | public void test() { 51 | LinChecker.check(NonParallelOpGroupTest.class); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /lincheck/src/test/java/com/devexperts/dxlab/lincheck/test/RunOnceTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Lincheck - Linearizability checker 3 | * 4 | * Copyright (C) 2015-2022 Devexperts, LLC 5 | * Copyright (C) 2023 Devexperts Ireland Limited 6 | * 7 | * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. 8 | * If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | 11 | package com.devexperts.dxlab.lincheck.test; 12 | 13 | import com.devexperts.dxlab.lincheck.LinChecker; 14 | import com.devexperts.dxlab.lincheck.annotations.Operation; 15 | import com.devexperts.dxlab.lincheck.strategy.stress.StressCTest; 16 | import org.junit.Test; 17 | 18 | @StressCTest(threads = 3, iterations = 100, invocationsPerIteration = 10) 19 | public class RunOnceTest { 20 | private A a = new A();; 21 | 22 | @Operation(runOnce = true) 23 | public void a() { 24 | a.a(); 25 | } 26 | 27 | @Operation(runOnce = true) 28 | public void b() { 29 | a.b(); 30 | } 31 | 32 | @Test 33 | public void test() { 34 | LinChecker.check(RunOnceTest.class); 35 | } 36 | 37 | class A { 38 | private boolean a, b; 39 | synchronized void a() { 40 | if (a) 41 | throw new AssertionError(); 42 | a = true; 43 | } 44 | 45 | synchronized void b() { 46 | if (b) 47 | throw new AssertionError(); 48 | b = true; 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /lincheck/src/test/java/com/devexperts/dxlab/lincheck/test/strategy/randomswitch/RandomSwitchCTestAnnTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Lincheck - Linearizability checker 3 | * 4 | * Copyright (C) 2015-2022 Devexperts, LLC 5 | * Copyright (C) 2023 Devexperts Ireland Limited 6 | * 7 | * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. 8 | * If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | 11 | package com.devexperts.dxlab.lincheck.test.strategy.randomswitch; 12 | 13 | import com.devexperts.dxlab.lincheck.LinChecker; 14 | import com.devexperts.dxlab.lincheck.annotations.Operation; 15 | import com.devexperts.dxlab.lincheck.execution.RandomExecutionGenerator; 16 | import com.devexperts.dxlab.lincheck.strategy.randomswitch.RandomSwitchCTest; 17 | import com.devexperts.dxlab.lincheck.verifier.linearizability.LinearizabilityVerifier; 18 | import org.junit.Test; 19 | 20 | import java.util.concurrent.atomic.AtomicInteger; 21 | 22 | @RandomSwitchCTest(threads = 3, actorsPerThread = 3, iterations = 10, invocationsPerIteration = 5, 23 | generator = RandomExecutionGenerator.class, verifier = LinearizabilityVerifier.class) 24 | public class RandomSwitchCTestAnnTest { 25 | private AtomicInteger i = new AtomicInteger(); 26 | 27 | @Operation() 28 | public int incAndGet() { 29 | return i.incrementAndGet(); 30 | } 31 | 32 | @Test 33 | public void test() { 34 | LinChecker.check(RandomSwitchCTestAnnTest.class); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /lincheck/src/test/java/com/devexperts/dxlab/lincheck/test/strategy/randomswitch/RandomSwitchOptionsTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Lincheck - Linearizability checker 3 | * 4 | * Copyright (C) 2015-2022 Devexperts, LLC 5 | * Copyright (C) 2023 Devexperts Ireland Limited 6 | * 7 | * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. 8 | * If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | 11 | package com.devexperts.dxlab.lincheck.test.strategy.randomswitch; 12 | 13 | import com.devexperts.dxlab.lincheck.LinChecker; 14 | import com.devexperts.dxlab.lincheck.Options; 15 | import com.devexperts.dxlab.lincheck.annotations.Operation; 16 | import com.devexperts.dxlab.lincheck.execution.RandomExecutionGenerator; 17 | import com.devexperts.dxlab.lincheck.strategy.randomswitch.RandomSwitchOptions; 18 | import com.devexperts.dxlab.lincheck.verifier.linearizability.LinearizabilityVerifier; 19 | import org.junit.Test; 20 | 21 | import java.util.concurrent.atomic.AtomicInteger; 22 | 23 | public class RandomSwitchOptionsTest { 24 | private AtomicInteger i = new AtomicInteger(); 25 | 26 | @Operation() 27 | public int incAndGet() { 28 | return i.incrementAndGet(); 29 | } 30 | 31 | @Test 32 | public void test() { 33 | Options opts = new RandomSwitchOptions() 34 | .iterations(10) 35 | .invocationsPerIteration(200) 36 | .executionGenerator(RandomExecutionGenerator.class) 37 | .threads(2) 38 | .actorsPerThread(4) 39 | .verifier(LinearizabilityVerifier.class); 40 | LinChecker.check(RandomSwitchOptionsTest.class, opts); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /lincheck/src/test/java/com/devexperts/dxlab/lincheck/test/strategy/stress/StressCTestAnnTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Lincheck - Linearizability checker 3 | * 4 | * Copyright (C) 2015-2022 Devexperts, LLC 5 | * Copyright (C) 2023 Devexperts Ireland Limited 6 | * 7 | * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. 8 | * If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | 11 | package com.devexperts.dxlab.lincheck.test.strategy.stress; 12 | 13 | import com.devexperts.dxlab.lincheck.LinChecker; 14 | import com.devexperts.dxlab.lincheck.annotations.Operation; 15 | import com.devexperts.dxlab.lincheck.execution.RandomExecutionGenerator; 16 | import com.devexperts.dxlab.lincheck.strategy.stress.StressCTest; 17 | import com.devexperts.dxlab.lincheck.verifier.linearizability.LinearizabilityVerifier; 18 | import org.junit.Test; 19 | 20 | import java.util.concurrent.atomic.AtomicInteger; 21 | 22 | @StressCTest(threads = 3, actorsPerThread = 3, iterations = 10, invocationsPerIteration = 5, 23 | generator = RandomExecutionGenerator.class, verifier = LinearizabilityVerifier.class) 24 | public class StressCTestAnnTest { 25 | private AtomicInteger i = new AtomicInteger(); 26 | 27 | @Operation() 28 | public int incAndGet() { 29 | return i.incrementAndGet(); 30 | } 31 | 32 | @Test 33 | public void test() { 34 | LinChecker.check(StressCTestAnnTest.class); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /lincheck/src/test/java/com/devexperts/dxlab/lincheck/test/strategy/stress/StressOptionsTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Lincheck - Linearizability checker 3 | * 4 | * Copyright (C) 2015-2022 Devexperts, LLC 5 | * Copyright (C) 2023 Devexperts Ireland Limited 6 | * 7 | * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. 8 | * If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | 11 | package com.devexperts.dxlab.lincheck.test.strategy.stress; 12 | 13 | import com.devexperts.dxlab.lincheck.LinChecker; 14 | import com.devexperts.dxlab.lincheck.LoggingLevel; 15 | import com.devexperts.dxlab.lincheck.Options; 16 | import com.devexperts.dxlab.lincheck.annotations.Operation; 17 | import com.devexperts.dxlab.lincheck.execution.RandomExecutionGenerator; 18 | import com.devexperts.dxlab.lincheck.strategy.stress.StressOptions; 19 | import com.devexperts.dxlab.lincheck.verifier.linearizability.LinearizabilityVerifier; 20 | import org.junit.Test; 21 | 22 | import java.util.concurrent.atomic.AtomicInteger; 23 | 24 | public class StressOptionsTest { 25 | private AtomicInteger i = new AtomicInteger();; 26 | 27 | @Operation() 28 | public int incAndGet() { 29 | return i.incrementAndGet(); 30 | } 31 | 32 | @Test 33 | public void test() { 34 | Options opts = new StressOptions() 35 | .iterations(10) 36 | .invocationsPerIteration(200) 37 | .executionGenerator(RandomExecutionGenerator.class) 38 | .verifier(LinearizabilityVerifier.class) 39 | .threads(2) 40 | .actorsPerThread(3) 41 | .logLevel(LoggingLevel.INFO); 42 | LinChecker.check(StressOptionsTest.class, opts); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /lincheck/src/test/java/com/devexperts/dxlab/lincheck/test/verifier/EpsilonVerifierTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Lincheck - Linearizability checker 3 | * 4 | * Copyright (C) 2015-2022 Devexperts, LLC 5 | * Copyright (C) 2023 Devexperts Ireland Limited 6 | * 7 | * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. 8 | * If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | 11 | package com.devexperts.dxlab.lincheck.test.verifier 12 | 13 | import com.devexperts.dxlab.lincheck.LinChecker 14 | import com.devexperts.dxlab.lincheck.annotations.Operation 15 | import com.devexperts.dxlab.lincheck.strategy.stress.StressCTest 16 | import com.devexperts.dxlab.lincheck.verifier.EpsilonVerifier 17 | import org.junit.Test 18 | 19 | @StressCTest(verifier = EpsilonVerifier::class) 20 | class EpsilonVerifierTest { 21 | private var i = 0 22 | 23 | @Operation 24 | fun incAndGet() = i++ // non-atomic! 25 | 26 | @Test 27 | fun test() = LinChecker.check(EpsilonVerifierTest::class.java) 28 | } 29 | -------------------------------------------------------------------------------- /lincheck/src/test/java/com/devexperts/dxlab/lincheck/test/verifier/quantitative/KPriorityQueueSimulation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Lincheck - Linearizability checker 3 | * 4 | * Copyright (C) 2015-2022 Devexperts, LLC 5 | * Copyright (C) 2023 Devexperts Ireland Limited 6 | * 7 | * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. 8 | * If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | 11 | package com.devexperts.dxlab.lincheck.test.verifier.quantitative; 12 | 13 | import java.util.ArrayList; 14 | import java.util.Collections; 15 | import java.util.List; 16 | import java.util.Random; 17 | 18 | public class KPriorityQueueSimulation { 19 | private final Random r = new Random(0); 20 | private final int relaxationFactor; 21 | private final List values = new ArrayList<>(); 22 | 23 | private int countTopNotPopped; 24 | 25 | public KPriorityQueueSimulation(int relaxationFactor) { 26 | this.relaxationFactor = relaxationFactor; 27 | } 28 | 29 | synchronized void push(int value) { 30 | // Push is not relaxed 31 | values.add(value); 32 | Collections.sort(values); 33 | } 34 | 35 | synchronized Integer poll() { 36 | if (values.isEmpty()) { 37 | countTopNotPopped = 0; 38 | return null; 39 | } 40 | int index = r.nextInt(Math.min(relaxationFactor - countTopNotPopped, values.size())); 41 | if (index == 0) 42 | countTopNotPopped = 0; 43 | else 44 | countTopNotPopped++; 45 | return values.remove(index); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /lincheck/src/test/java/com/devexperts/dxlab/lincheck/test/verifier/quantitative/KStackSimulation.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Lincheck - Linearizability checker 3 | * 4 | * Copyright (C) 2015-2022 Devexperts, LLC 5 | * Copyright (C) 2023 Devexperts Ireland Limited 6 | * 7 | * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. 8 | * If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | package com.devexperts.dxlab.lincheck.test.verifier.quantitative 11 | 12 | import java.util.* 13 | import kotlin.collections.ArrayList 14 | 15 | class KStackSimulation(val k: Int) { 16 | private val list = ArrayList() 17 | 18 | private val random = Random(0) 19 | 20 | fun push(value: T) = synchronized(this) { 21 | list.add(0, value) 22 | } 23 | 24 | fun pushRelaxed(value: T) = synchronized(this) { 25 | val index = random.nextInt(k).coerceAtMost(list.size) 26 | list.add(index, value) 27 | } 28 | 29 | 30 | fun popOrNull(): T? = synchronized(this) { 31 | return if (list.isEmpty()) null else list.removeAt(0) 32 | } 33 | 34 | fun popOrNullRelaxed(): T? = synchronized(this) { 35 | if (list.isEmpty()) 36 | return null 37 | val index = random.nextInt(k).coerceAtMost(list.size - 1) 38 | return list.removeAt(index) 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /lincheck/src/test/java/com/devexperts/dxlab/lincheck/test/verifier/quantitative/StutteringCounterSimulation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Lincheck - Linearizability checker 3 | * 4 | * Copyright (C) 2015-2022 Devexperts, LLC 5 | * Copyright (C) 2023 Devexperts Ireland Limited 6 | * 7 | * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. 8 | * If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | 11 | package com.devexperts.dxlab.lincheck.test.verifier.quantitative; 12 | 13 | import java.util.Random; 14 | 15 | public class StutteringCounterSimulation { 16 | private final Random r = new Random(0); 17 | private final int relaxationFactor; 18 | private final float stutteringProbability; 19 | private int value; 20 | private int stutteringCount; 21 | 22 | public StutteringCounterSimulation(int relaxationFactor, float stutteringProbability) { 23 | this.relaxationFactor = relaxationFactor; 24 | this.stutteringProbability = stutteringProbability; 25 | } 26 | 27 | synchronized int incAndGet() { 28 | if (stutteringCount + 1 < relaxationFactor && r.nextFloat() < stutteringProbability) { 29 | stutteringCount++; 30 | return value; 31 | } else { 32 | stutteringCount = 0; 33 | return ++value; 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /lincheck/src/test/java/com/devexperts/dxlab/lincheck/test/verifier/quasi/KRelaxedPopStack.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Lincheck - Linearizability checker 3 | * 4 | * Copyright (C) 2015-2022 Devexperts, LLC 5 | * Copyright (C) 2023 Devexperts Ireland Limited 6 | * 7 | * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. 8 | * If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | 11 | package com.devexperts.dxlab.lincheck.test.verifier.quasi 12 | 13 | import java.util.* 14 | 15 | class KRelaxedPopStack(private val k: Int) { 16 | 17 | private val list = LinkedList() 18 | 19 | private val random = Random() 20 | 21 | @Synchronized 22 | fun push(value: T) { 23 | list.push(value) 24 | } 25 | 26 | @Synchronized 27 | fun push1(value: T) { 28 | list.push(value) 29 | } 30 | 31 | @Synchronized 32 | fun push2(value: T) { 33 | list.push(value) 34 | } 35 | 36 | @Synchronized 37 | fun pop(): T? { 38 | if (list.isEmpty()) { 39 | return null 40 | } 41 | val index = random.nextInt(k + 1).coerceAtMost(list.size - 1) 42 | return list.removeAt(index) 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /lincheck/src/test/java/com/devexperts/dxlab/lincheck/test/verifier/quasi/SegmentQueueTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Lincheck - Linearizability checker 3 | * 4 | * Copyright (C) 2015-2022 Devexperts, LLC 5 | * Copyright (C) 2023 Devexperts Ireland Limited 6 | * 7 | * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. 8 | * If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | 11 | package com.devexperts.dxlab.lincheck.test.verifier.quasi 12 | 13 | import com.devexperts.dxlab.lincheck.LinChecker 14 | import com.devexperts.dxlab.lincheck.annotations.Operation 15 | import com.devexperts.dxlab.lincheck.strategy.stress.StressCTest 16 | import com.devexperts.dxlab.lincheck.verifier.quasi.QuasiLinearizabilityVerifier 17 | import com.devexperts.dxlab.lincheck.verifier.quasi.QuasiLinearizabilityVerifierConf 18 | import org.junit.Ignore 19 | import org.junit.Test 20 | import java.util.* 21 | 22 | private const val K = 2 23 | 24 | @Ignore 25 | @StressCTest(verifier = QuasiLinearizabilityVerifier::class, iterations = 10, invocationsPerIteration = 10, actorsBefore = 5, actorsAfter = 5, actorsPerThread = 10, threads = 2) 26 | @QuasiLinearizabilityVerifierConf(factor = K, sequentialImplementation = SegmentQueueTest.SeqImpl::class) 27 | class SegmentQueueTest { 28 | private val q = SegmentQueue(2) 29 | 30 | @Operation 31 | fun enqueue(item: Int) = q.enqueue(item) 32 | 33 | @Operation 34 | fun dequeue(): Int? = q.dequeue() 35 | 36 | @Test 37 | fun test() = LinChecker.check(SegmentQueueTest::class.java) 38 | 39 | data class SeqImpl @JvmOverloads constructor(val q: Queue = ArrayDeque()) { 40 | fun enqueue(item: Int) = q.offer(item) 41 | fun dequeue(): Int? = q.poll() 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /lincheck/src/test/java/com/devexperts/dxlab/lincheck/test/verifier/quiescent/LockFreeMPSCQueueTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Lincheck - Linearizability checker 3 | * 4 | * Copyright (C) 2015-2022 Devexperts, LLC 5 | * Copyright (C) 2023 Devexperts Ireland Limited 6 | * 7 | * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. 8 | * If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | 11 | package com.devexperts.dxlab.lincheck.test.verifier.quiescent; 12 | 13 | import com.devexperts.dxlab.lincheck.LinChecker; 14 | import com.devexperts.dxlab.lincheck.annotations.OpGroupConfig; 15 | import com.devexperts.dxlab.lincheck.annotations.Operation; 16 | import com.devexperts.dxlab.lincheck.annotations.Param; 17 | import com.devexperts.dxlab.lincheck.paramgen.IntGen; 18 | import com.devexperts.dxlab.lincheck.strategy.stress.StressCTest; 19 | import com.devexperts.dxlab.lincheck.verifier.quiescent.QuiescentConsistencyVerifier; 20 | import com.devexperts.dxlab.lincheck.verifier.quiescent.QuiescentConsistent; 21 | import org.junit.Test; 22 | 23 | @StressCTest(verifier = QuiescentConsistencyVerifier.class) 24 | @OpGroupConfig(name = "consumer", nonParallel = true) 25 | public class LockFreeMPSCQueueTest { 26 | private LockFreeMPSCQueue q = new LockFreeMPSCQueue<>(); 27 | 28 | @Operation(group = "consumer") 29 | @QuiescentConsistent 30 | public Integer removeFirstOrNull() { 31 | return q.removeFirstOrNull(); 32 | } 33 | 34 | @Operation 35 | public boolean addLast(@Param(gen = IntGen.class) Integer val) { 36 | return q.addLast(val); 37 | } 38 | 39 | @Operation(runOnce = true) 40 | @QuiescentConsistent 41 | public void close() { 42 | q.close(); 43 | } 44 | 45 | @Test 46 | public void test() { 47 | LinChecker.check(LockFreeMPSCQueueTest.class); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /lincheck/src/test/java/com/devexperts/dxlab/lincheck/test/verifier/serializability/SerializableQueueSimulation.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Lincheck - Linearizability checker 3 | * 4 | * Copyright (C) 2015-2022 Devexperts, LLC 5 | * Copyright (C) 2023 Devexperts Ireland Limited 6 | * 7 | * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. 8 | * If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | package com.devexperts.dxlab.lincheck.test.verifier.serializability 11 | 12 | import java.util.Collections.shuffle 13 | 14 | data class SerializableQueueSimulation( 15 | private val queue: ArrayList = ArrayList(), 16 | private val pushQueue: ArrayList = ArrayList() 17 | ) { 18 | fun push(item: T) = synchronized(this) { 19 | pushQueue += item 20 | } 21 | 22 | fun pop(): T? = synchronized(this) { 23 | if (queue.isEmpty()) { 24 | shuffle(pushQueue) 25 | queue.addAll(pushQueue) 26 | pushQueue.clear() 27 | } 28 | return if (queue.isEmpty()) null else queue.removeAt(0) 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /lincheck/src/test/java/com/devexperts/dxlab/lincheck/test/verifier/serializability/SerializableQueueSimulationTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Lincheck - Linearizability checker 3 | * 4 | * Copyright (C) 2015-2022 Devexperts, LLC 5 | * Copyright (C) 2023 Devexperts Ireland Limited 6 | * 7 | * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. 8 | * If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | 11 | package com.devexperts.dxlab.lincheck.test.verifier.serializability 12 | 13 | import com.devexperts.dxlab.lincheck.LinChecker 14 | import com.devexperts.dxlab.lincheck.annotations.Operation 15 | import com.devexperts.dxlab.lincheck.annotations.Param 16 | import com.devexperts.dxlab.lincheck.paramgen.IntGen 17 | import com.devexperts.dxlab.lincheck.strategy.stress.StressCTest 18 | import com.devexperts.dxlab.lincheck.verifier.serializability.SerializabilityVerifier 19 | import org.junit.Test 20 | 21 | @StressCTest(actorsBefore = 2, 22 | threads = 2, actorsPerThread = 4, 23 | actorsAfter = 2, 24 | verifier = SerializabilityVerifier::class) 25 | class SerializableQueueSimulationTest { 26 | val q = SerializableQueueSimulation() 27 | 28 | @Operation 29 | fun push(@Param(gen = IntGen::class) item: Int) = q.push(item) 30 | 31 | @Operation 32 | fun pop(): Int? = q.pop() 33 | 34 | @Test 35 | fun test() = LinChecker.check(SerializableQueueSimulationTest::class.java) 36 | 37 | override fun equals(other: Any?): Boolean { 38 | if (this === other) return true 39 | if (javaClass != other?.javaClass) return false 40 | 41 | other as SerializableQueueSimulationTest 42 | 43 | if (q != other.q) return false 44 | 45 | return true 46 | } 47 | 48 | override fun hashCode(): Int { 49 | return q.hashCode() 50 | } 51 | 52 | 53 | } 54 | --------------------------------------------------------------------------------