forked from JeffersonLab/evio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
disruptorGitPatchJava
14881 lines (14867 loc) · 482 KB
/
disruptorGitPatchJava
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
diff --git a/src/main/java/com/lmax/disruptor/MultiProducerSequencer.java b/src/main/java/com/lmax/disruptor/MultiProducerSequencer.java
index a34cdd2..a5356bb 100644
--- a/src/main/java/com/lmax/disruptor/MultiProducerSequencer.java
+++ b/src/main/java/com/lmax/disruptor/MultiProducerSequencer.java
@@ -111,9 +111,9 @@ public final class MultiProducerSequencer extends AbstractSequencer
@Override
public long next(int n)
{
- if (n < 1)
+ if (n < 1 || n > bufferSize)
{
- throw new IllegalArgumentException("n must be > 0");
+ throw new IllegalArgumentException("n must be > 0 and < bufferSize");
}
long current;
@@ -149,6 +149,55 @@ public final class MultiProducerSequencer extends AbstractSequencer
return next;
}
+ /**
+ * @see Sequencer#nextIntr(int)
+ * @author Carl Timmer
+ */
+ @Override
+ public long nextIntr(int n) throws InterruptedException
+ {
+ if (n < 1 || n > bufferSize)
+ {
+ throw new IllegalArgumentException("n must be > 0 and < bufferSize");
+ }
+
+ long current;
+ long next;
+
+ do
+ {
+ current = cursor.get();
+ next = current + n;
+
+ long wrapPoint = next - bufferSize;
+ long cachedGatingSequence = gatingSequenceCache.get();
+
+ if (wrapPoint > cachedGatingSequence || cachedGatingSequence > current)
+ {
+ long gatingSequence = Util.getMinimumSequence(gatingSequences, current);
+
+ if (wrapPoint > gatingSequence)
+ {
+ if (Thread.currentThread().isInterrupted())
+ {
+ throw new InterruptedException();
+ }
+ LockSupport.parkNanos(1);
+ continue;
+ }
+
+ gatingSequenceCache.set(gatingSequence);
+ }
+ else if (cursor.compareAndSet(current, next))
+ {
+ break;
+ }
+ }
+ while (true);
+
+ return next;
+ }
+
/**
* @see Sequencer#tryNext()
*/
diff --git a/src/main/java/com/lmax/disruptor/RingBuffer.java b/src/main/java/com/lmax/disruptor/RingBuffer.java
index e9df321..6d4a2ff 100644
--- a/src/main/java/com/lmax/disruptor/RingBuffer.java
+++ b/src/main/java/com/lmax/disruptor/RingBuffer.java
@@ -50,7 +50,7 @@ abstract class RingBufferFields<E> extends RingBufferPad
}
BUFFER_PAD = 128 / scale;
// Including the buffer pad in the array base offset
- REF_ARRAY_BASE = UNSAFE.arrayBaseOffset(Object[].class) + (BUFFER_PAD << REF_ELEMENT_SHIFT);
+ REF_ARRAY_BASE = UNSAFE.arrayBaseOffset(Object[].class) + 128;
}
private final long indexMask;
@@ -137,7 +137,7 @@ public final class RingBuffer<E> extends RingBufferFields<E> implements Cursored
{
MultiProducerSequencer sequencer = new MultiProducerSequencer(bufferSize, waitStrategy);
- return new RingBuffer<E>(factory, sequencer);
+ return new RingBuffer<>(factory, sequencer);
}
/**
@@ -147,7 +147,7 @@ public final class RingBuffer<E> extends RingBufferFields<E> implements Cursored
* @param factory used to create the events within the ring buffer.
* @param bufferSize number of elements to create within the ring buffer.
* @return a constructed ring buffer.
- * @throws IllegalArgumentException if <tt>bufferSize</tt> is less than 1 or not a power of 2
+ * @throws IllegalArgumentException if <code>bufferSize</code> is less than 1 or not a power of 2
* @see MultiProducerSequencer
*/
public static <E> RingBuffer<E> createMultiProducer(EventFactory<E> factory, int bufferSize)
@@ -173,7 +173,7 @@ public final class RingBuffer<E> extends RingBufferFields<E> implements Cursored
{
SingleProducerSequencer sequencer = new SingleProducerSequencer(bufferSize, waitStrategy);
- return new RingBuffer<E>(factory, sequencer);
+ return new RingBuffer<>(factory, sequencer);
}
/**
@@ -183,7 +183,7 @@ public final class RingBuffer<E> extends RingBufferFields<E> implements Cursored
* @param factory used to create the events within the ring buffer.
* @param bufferSize number of elements to create within the ring buffer.
* @return a constructed ring buffer.
- * @throws IllegalArgumentException if <tt>bufferSize</tt> is less than 1 or not a power of 2
+ * @throws IllegalArgumentException if <code>bufferSize</code> is less than 1 or not a power of 2
* @see MultiProducerSequencer
*/
public static <E> RingBuffer<E> createSingleProducer(EventFactory<E> factory, int bufferSize)
@@ -277,6 +277,23 @@ public final class RingBuffer<E> extends RingBufferFields<E> implements Cursored
return sequencer.next(n);
}
+ /**
+ * The same functionality as {@link RingBuffer#next(int)}.
+ * This method throws an InterruptedException if the thread
+ * which calls it is interrupted.
+ *
+ * @author Carl Timmer
+ * @see Sequencer#next(int)
+ * @param n number of slots to claim
+ * @return sequence number of the highest slot claimed
+ * @throws InterruptedException if thread is interrupted
+ */
+ @Override
+ public long nextIntr(int n) throws InterruptedException
+ {
+ return sequencer.nextIntr(n);
+ }
+
/**
* <p>Increment and return the next sequence for the ring buffer. Calls of this
* method should ensure that they always publish the sequence afterward. E.g.</p>
@@ -388,7 +405,7 @@ public final class RingBuffer<E> extends RingBufferFields<E> implements Cursored
* Remove the specified sequence from this ringBuffer.
*
* @param sequence to be removed.
- * @return <tt>true</tt> if this sequence was found, <tt>false</tt> otherwise.
+ * @return <code>true</code> if this sequence was found, <code>false</code> otherwise.
*/
public boolean removeGatingSequence(Sequence sequence)
{
@@ -441,14 +458,14 @@ public final class RingBuffer<E> extends RingBufferFields<E> implements Cursored
}
/**
- * Given specified <tt>requiredCapacity</tt> determines if that amount of space
- * is available. Note, you can not assume that if this method returns <tt>true</tt>
+ * Given specified <code>requiredCapacity</code> determines if that amount of space
+ * is available. Note, you can not assume that if this method returns <code>true</code>
* that a call to {@link RingBuffer#next()} will not block. Especially true if this
* ring buffer is set up to handle multiple producers.
*
* @param requiredCapacity The capacity to check for.
- * @return <tt>true</tt> If the specified <tt>requiredCapacity</tt> is available
- * <tt>false</tt> if not.
+ * @return <code>true</code> If the specified <code>requiredCapacity</code> is available
+ * <code>false</code> if not.
*/
public boolean hasAvailableCapacity(int requiredCapacity)
{
diff --git a/src/main/java/com/lmax/disruptor/Sequenced.java b/src/main/java/com/lmax/disruptor/Sequenced.java
index 3c8ba69..89e4770 100644
--- a/src/main/java/com/lmax/disruptor/Sequenced.java
+++ b/src/main/java/com/lmax/disruptor/Sequenced.java
@@ -50,6 +50,18 @@ public interface Sequenced
*/
long next(int n);
+ /**
+ * Claim the next n events in sequence for publishing.
+ * This method is interruptible and will throw an
+ * InterruptedException if it is.
+ *
+ * @author Carl Timmer
+ * @param n the number of sequences to claim
+ * @return the highest claimed sequence value
+ * @throws InterruptedException if interrupted
+ */
+ long nextIntr(int n) throws InterruptedException;
+
/**
* Attempt to claim the next event in sequence for publishing. Will return the
* number of the slot if there is at least <code>requiredCapacity</code> slots
diff --git a/src/main/java/com/lmax/disruptor/SingleProducerSequencer.java b/src/main/java/com/lmax/disruptor/SingleProducerSequencer.java
index 32e1942..678388a 100644
--- a/src/main/java/com/lmax/disruptor/SingleProducerSequencer.java
+++ b/src/main/java/com/lmax/disruptor/SingleProducerSequencer.java
@@ -116,9 +116,9 @@ public final class SingleProducerSequencer extends SingleProducerSequencerFields
@Override
public long next(int n)
{
- if (n < 1)
+ if (n < 1 || n > bufferSize)
{
- throw new IllegalArgumentException("n must be > 0");
+ throw new IllegalArgumentException("n must be > 0 and < bufferSize");
}
long nextValue = this.nextValue;
@@ -145,6 +145,44 @@ public final class SingleProducerSequencer extends SingleProducerSequencerFields
return nextSequence;
}
+ /**
+ * @see Sequencer#nextIntr(int)
+ * @author Carl Timmer
+ */
+ @Override
+ public long nextIntr(int n) throws InterruptedException
+ {
+ if (n < 1 || n > bufferSize)
+ {
+ throw new IllegalArgumentException("n must be > 0 and < bufferSize");
+ }
+
+ long nextValue = this.nextValue;
+
+ long nextSequence = nextValue + n;
+ long wrapPoint = nextSequence - bufferSize;
+ long cachedGatingSequence = this.cachedValue;
+
+ if (wrapPoint > cachedGatingSequence || cachedGatingSequence > nextValue)
+ {
+ long minSequence;
+ while (wrapPoint > (minSequence = Util.getMinimumSequence(gatingSequences, nextValue)))
+ {
+ if (Thread.currentThread().isInterrupted())
+ {
+ throw new InterruptedException();
+ }
+ LockSupport.parkNanos(1L);
+ }
+
+ this.cachedValue = minSequence;
+ }
+
+ this.nextValue = nextSequence;
+
+ return nextSequence;
+ }
+
/**
* @see Sequencer#tryNext()
*/
diff --git a/src/main/java/com/lmax/disruptor/SpinCountBackoffWaitStrategy.java b/src/main/java/com/lmax/disruptor/SpinCountBackoffWaitStrategy.java
new file mode 100644
index 0000000..5d82f08
--- /dev/null
+++ b/src/main/java/com/lmax/disruptor/SpinCountBackoffWaitStrategy.java
@@ -0,0 +1,51 @@
+package com.lmax.disruptor;
+
+
+/**
+ * <p>Spin first wait strategy for waiting {@link EventProcessor}s on a barrier.</p>
+ *
+ * <p>This strategy can be used when throughput and low-latency are not as important as CPU resource.
+ * Spins for a given number of times then waits using the configured fallback WaitStrategy.</p>
+ * @author timmer
+ */
+public final class SpinCountBackoffWaitStrategy implements WaitStrategy
+{
+ private final int spin_tries;
+ private final WaitStrategy fallbackStrategy;
+
+ public SpinCountBackoffWaitStrategy(int spinTries,
+ WaitStrategy fallbackStrategy)
+ {
+ this.spin_tries = spinTries;
+ this.fallbackStrategy = fallbackStrategy;
+ }
+
+
+ @Override
+ public long waitFor(long sequence, Sequence cursor, Sequence dependentSequence, SequenceBarrier barrier)
+ throws AlertException, InterruptedException, TimeoutException
+ {
+ long availableSequence;
+ int counter = spin_tries;
+
+ do
+ {
+ if ((availableSequence = dependentSequence.get()) >= sequence)
+ {
+ return availableSequence;
+ }
+
+ if (0 == --counter)
+ {
+ return fallbackStrategy.waitFor(sequence, cursor, dependentSequence, barrier);
+ }
+
+ } while (true);
+ }
+
+ @Override
+ public void signalAllWhenBlocking()
+ {
+ fallbackStrategy.signalAllWhenBlocking();
+ }
+}
diff --git a/src/main/java/com/lmax/disruptor/YieldingWaitStrategy.java b/src/main/java/com/lmax/disruptor/YieldingWaitStrategy.java
index ba357ac..f8c4546 100644
--- a/src/main/java/com/lmax/disruptor/YieldingWaitStrategy.java
+++ b/src/main/java/com/lmax/disruptor/YieldingWaitStrategy.java
@@ -49,13 +49,18 @@ public final class YieldingWaitStrategy implements WaitStrategy
}
private int applyWaitMethod(final SequenceBarrier barrier, int counter)
- throws AlertException
+ throws AlertException, InterruptedException // InterruptedException added by Carl Timmer
{
barrier.checkAlert();
if (0 == counter)
{
Thread.yield();
+ // Next 3 lines added by Carl Timmer to make it interruptible
+ if (Thread.interrupted())
+ {
+ throw new InterruptedException();
+ }
}
else
{
diff --git a/src/perftest/java/com/lmax/disruptor/AbstractPerfTestDisruptor.java b/src/perftest/java/com/lmax/disruptor/AbstractPerfTestDisruptor.java
deleted file mode 100644
index 7b71ab6..0000000
--- a/src/perftest/java/com/lmax/disruptor/AbstractPerfTestDisruptor.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Copyright 2011 LMAX Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.lmax.disruptor;
-
-
-public abstract class AbstractPerfTestDisruptor
-{
- public static final int RUNS = 7;
-
- protected void testImplementations()
- throws Exception
- {
- final int availableProcessors = Runtime.getRuntime().availableProcessors();
- if (getRequiredProcessorCount() > availableProcessors)
- {
- System.out.print("*** Warning ***: your system has insufficient processors to execute the test efficiently. ");
- System.out.println("Processors required = " + getRequiredProcessorCount() + " available = " + availableProcessors);
- }
-
- long[] disruptorOps = new long[RUNS];
-
- System.out.println("Starting Disruptor tests");
- for (int i = 0; i < RUNS; i++)
- {
- System.gc();
- disruptorOps[i] = runDisruptorPass();
- System.out.format("Run %d, Disruptor=%,d ops/sec%n", i, Long.valueOf(disruptorOps[i]));
- }
- }
-
- public static void printResults(final String className, final long[] disruptorOps, final long[] queueOps)
- {
- for (int i = 0; i < RUNS; i++)
- {
- System.out.format("%s run %d: BlockingQueue=%,d Disruptor=%,d ops/sec\n",
- className, Integer.valueOf(i), Long.valueOf(queueOps[i]), Long.valueOf(disruptorOps[i]));
- }
- }
-
- protected abstract int getRequiredProcessorCount();
-
- protected abstract long runDisruptorPass() throws Exception;
-}
diff --git a/src/perftest/java/com/lmax/disruptor/AbstractPerfTestQueue.java b/src/perftest/java/com/lmax/disruptor/AbstractPerfTestQueue.java
deleted file mode 100644
index 1d16661..0000000
--- a/src/perftest/java/com/lmax/disruptor/AbstractPerfTestQueue.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * Copyright 2011 LMAX Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.lmax.disruptor;
-
-
-public abstract class AbstractPerfTestQueue
-{
- public static final int RUNS = 7;
-
- protected void testImplementations()
- throws Exception
- {
- final int availableProcessors = Runtime.getRuntime().availableProcessors();
- if (getRequiredProcessorCount() > availableProcessors)
- {
- System.out.print(
- "*** Warning ***: your system has insufficient processors to execute the test efficiently. ");
- System.out.println(
- "Processors required = " + getRequiredProcessorCount() + " available = " + availableProcessors);
- }
-
- long[] queueOps = new long[RUNS];
-
- System.out.println("Starting Queue tests");
- for (int i = 0; i < RUNS; i++)
- {
- System.gc();
- queueOps[i] = runQueuePass();
- System.out.format("Run %d, BlockingQueue=%,d ops/sec%n", i, Long.valueOf(queueOps[i]));
- }
- }
-
- public static void printResults(final String className, final long[] disruptorOps, final long[] queueOps)
- {
- for (int i = 0; i < RUNS; i++)
- {
- System.out.format(
- "%s run %d: BlockingQueue=%,d Disruptor=%,d ops/sec\n",
- className, Integer.valueOf(i), Long.valueOf(queueOps[i]), Long.valueOf(disruptorOps[i]));
- }
- }
-
- protected abstract int getRequiredProcessorCount();
-
- protected abstract long runQueuePass() throws Exception;
-}
diff --git a/src/perftest/java/com/lmax/disruptor/immutable/Constants.java b/src/perftest/java/com/lmax/disruptor/immutable/Constants.java
deleted file mode 100644
index 7c55258..0000000
--- a/src/perftest/java/com/lmax/disruptor/immutable/Constants.java
+++ /dev/null
@@ -1,7 +0,0 @@
-package com.lmax.disruptor.immutable;
-
-public class Constants
-{
- public static final long ITERATIONS = 1000 * 1000 * 100L;
- public static final int SIZE = 1 << 20;
-}
diff --git a/src/perftest/java/com/lmax/disruptor/immutable/CustomPerformanceTest.java b/src/perftest/java/com/lmax/disruptor/immutable/CustomPerformanceTest.java
deleted file mode 100644
index fc1a9b8..0000000
--- a/src/perftest/java/com/lmax/disruptor/immutable/CustomPerformanceTest.java
+++ /dev/null
@@ -1,59 +0,0 @@
-package com.lmax.disruptor.immutable;
-
-import java.util.concurrent.locks.LockSupport;
-
-import com.lmax.disruptor.BatchEventProcessor;
-import com.lmax.disruptor.SingleProducerSequencer;
-import com.lmax.disruptor.YieldingWaitStrategy;
-
-public class CustomPerformanceTest
-{
- private final CustomRingBuffer<SimpleEvent> ringBuffer;
-
- public CustomPerformanceTest()
- {
- ringBuffer =
- new CustomRingBuffer<SimpleEvent>(new SingleProducerSequencer(Constants.SIZE, new YieldingWaitStrategy()));
- }
-
- public void run()
- {
- try
- {
- doRun();
- }
- catch (InterruptedException e)
- {
- e.printStackTrace();
- }
- }
-
- private void doRun() throws InterruptedException
- {
- BatchEventProcessor<?> batchEventProcessor = ringBuffer.createHandler(new SimpleEventHandler());
-
- Thread t = new Thread(batchEventProcessor);
- t.start();
-
- long iterations = Constants.ITERATIONS;
- for (long l = 0; l < iterations; l++)
- {
- SimpleEvent e = new SimpleEvent(l, l, l, l);
- ringBuffer.put(e);
- }
-
- while (batchEventProcessor.getSequence().get() != iterations - 1)
- {
- LockSupport.parkNanos(1);
- }
-
- batchEventProcessor.halt();
- t.join();
- }
-
- public static void main(String[] args)
- {
- new CustomPerformanceTest().run();
- }
-
-}
diff --git a/src/perftest/java/com/lmax/disruptor/immutable/CustomRingBuffer.java b/src/perftest/java/com/lmax/disruptor/immutable/CustomRingBuffer.java
deleted file mode 100644
index c575f82..0000000
--- a/src/perftest/java/com/lmax/disruptor/immutable/CustomRingBuffer.java
+++ /dev/null
@@ -1,99 +0,0 @@
-package com.lmax.disruptor.immutable;
-
-import com.lmax.disruptor.BatchEventProcessor;
-import com.lmax.disruptor.DataProvider;
-import com.lmax.disruptor.EventHandler;
-import com.lmax.disruptor.LifecycleAware;
-import com.lmax.disruptor.Sequencer;
-
-public class CustomRingBuffer<T> implements DataProvider<EventAccessor<T>>, EventAccessor<T>
-{
- private static final class AccessorEventHandler<T> implements EventHandler<EventAccessor<T>>, LifecycleAware
- {
- private final EventHandler<T> handler;
- private final LifecycleAware lifecycle;
-
- private AccessorEventHandler(EventHandler<T> handler)
- {
- this.handler = handler;
- lifecycle = handler instanceof LifecycleAware ? (LifecycleAware) handler : null;
- }
-
- @Override
- public void onEvent(EventAccessor<T> accessor, long sequence, boolean endOfBatch) throws Exception
- {
- this.handler.onEvent(accessor.take(sequence), sequence, endOfBatch);
- }
-
- @Override
- public void onShutdown()
- {
- if (null != lifecycle)
- {
- lifecycle.onShutdown();
- }
- }
-
- @Override
- public void onStart()
- {
- if (null != lifecycle)
- {
- lifecycle.onStart();
- }
- }
- }
-
- private final Sequencer sequencer;
- private final Object[] buffer;
- private final int mask;
-
- public CustomRingBuffer(Sequencer sequencer)
- {
- this.sequencer = sequencer;
- buffer = new Object[sequencer.getBufferSize()];
- mask = sequencer.getBufferSize() - 1;
- }
-
- private int index(long sequence)
- {
- return (int) sequence & mask;
- }
-
- public void put(T e)
- {
- long next = sequencer.next();
- buffer[index(next)] = e;
- sequencer.publish(next);
- }
-
- @SuppressWarnings("unchecked")
- @Override
- public T take(long sequence)
- {
- int index = index(sequence);
-
- T t = (T) buffer[index];
- buffer[index] = null;
-
- return t;
- }
-
- @Override
- public EventAccessor<T> get(long sequence)
- {
- return this;
- }
-
- public BatchEventProcessor<EventAccessor<T>> createHandler(final EventHandler<T> handler)
- {
- BatchEventProcessor<EventAccessor<T>> processor =
- new BatchEventProcessor<EventAccessor<T>>(
- this,
- sequencer.newBarrier(),
- new AccessorEventHandler<T>(handler));
- sequencer.addGatingSequences(processor.getSequence());
-
- return processor;
- }
-}
diff --git a/src/perftest/java/com/lmax/disruptor/immutable/EventAccessor.java b/src/perftest/java/com/lmax/disruptor/immutable/EventAccessor.java
deleted file mode 100644
index 2f0fe86..0000000
--- a/src/perftest/java/com/lmax/disruptor/immutable/EventAccessor.java
+++ /dev/null
@@ -1,6 +0,0 @@
-package com.lmax.disruptor.immutable;
-
-public interface EventAccessor<T>
-{
- T take(long sequence);
-}
diff --git a/src/perftest/java/com/lmax/disruptor/immutable/EventHolder.java b/src/perftest/java/com/lmax/disruptor/immutable/EventHolder.java
deleted file mode 100644
index 515310b..0000000
--- a/src/perftest/java/com/lmax/disruptor/immutable/EventHolder.java
+++ /dev/null
@@ -1,18 +0,0 @@
-package com.lmax.disruptor.immutable;
-
-import com.lmax.disruptor.EventFactory;
-
-public class EventHolder
-{
-
- public static final EventFactory<EventHolder> FACTORY = new EventFactory<EventHolder>()
- {
- @Override
- public EventHolder newInstance()
- {
- return new EventHolder();
- }
- };
-
- public SimpleEvent event;
-}
diff --git a/src/perftest/java/com/lmax/disruptor/immutable/EventHolderHandler.java b/src/perftest/java/com/lmax/disruptor/immutable/EventHolderHandler.java
deleted file mode 100644
index f597187..0000000
--- a/src/perftest/java/com/lmax/disruptor/immutable/EventHolderHandler.java
+++ /dev/null
@@ -1,20 +0,0 @@
-package com.lmax.disruptor.immutable;
-
-import com.lmax.disruptor.EventHandler;
-
-public class EventHolderHandler implements EventHandler<EventHolder>
-{
- private final EventHandler<SimpleEvent> delegate;
-
- public EventHolderHandler(EventHandler<SimpleEvent> delegate)
- {
- this.delegate = delegate;
- }
-
- @Override
- public void onEvent(EventHolder holder, long sequence, boolean endOfBatch) throws Exception
- {
- delegate.onEvent(holder.event, sequence, endOfBatch);
- holder.event = null;
- }
-}
diff --git a/src/perftest/java/com/lmax/disruptor/immutable/SimpleEvent.java b/src/perftest/java/com/lmax/disruptor/immutable/SimpleEvent.java
deleted file mode 100644
index 2614c24..0000000
--- a/src/perftest/java/com/lmax/disruptor/immutable/SimpleEvent.java
+++ /dev/null
@@ -1,28 +0,0 @@
-package com.lmax.disruptor.immutable;
-
-public class SimpleEvent
-{
- private final long id;
- private final long v1;
- private final long v2;
- private final long v3;
-
- public SimpleEvent(long id, long v1, long v2, long v3)
- {
- this.id = id;
- this.v1 = v1;
- this.v2 = v2;
- this.v3 = v3;
- }
-
- public long getCounter()
- {
- return v1;
- }
-
- @Override
- public String toString()
- {
- return "SimpleEvent [id=" + id + ", v1=" + v1 + ", v2=" + v2 + ", v3=" + v3 + "]";
- }
-}
\ No newline at end of file
diff --git a/src/perftest/java/com/lmax/disruptor/immutable/SimpleEventHandler.java b/src/perftest/java/com/lmax/disruptor/immutable/SimpleEventHandler.java
deleted file mode 100644
index cc4560f..0000000
--- a/src/perftest/java/com/lmax/disruptor/immutable/SimpleEventHandler.java
+++ /dev/null
@@ -1,14 +0,0 @@
-package com.lmax.disruptor.immutable;
-
-import com.lmax.disruptor.EventHandler;
-
-public class SimpleEventHandler implements EventHandler<SimpleEvent>
-{
- public long counter;
-
- @Override
- public void onEvent(SimpleEvent arg0, long arg1, boolean arg2) throws Exception
- {
- counter += arg0.getCounter();
- }
-}
diff --git a/src/perftest/java/com/lmax/disruptor/immutable/SimplePerformanceTest.java b/src/perftest/java/com/lmax/disruptor/immutable/SimplePerformanceTest.java
deleted file mode 100644
index 074578a..0000000
--- a/src/perftest/java/com/lmax/disruptor/immutable/SimplePerformanceTest.java
+++ /dev/null
@@ -1,75 +0,0 @@
-package com.lmax.disruptor.immutable;
-
-import java.util.concurrent.locks.LockSupport;
-
-import com.lmax.disruptor.BatchEventProcessor;
-import com.lmax.disruptor.EventTranslatorOneArg;
-import com.lmax.disruptor.RingBuffer;
-import com.lmax.disruptor.YieldingWaitStrategy;
-
-public class SimplePerformanceTest
-{
- private final RingBuffer<EventHolder> ringBuffer;
- private final EventHolderHandler eventHolderHandler;
-
- public SimplePerformanceTest()
- {
- ringBuffer = RingBuffer.createSingleProducer(EventHolder.FACTORY, Constants.SIZE, new YieldingWaitStrategy());
- eventHolderHandler = new EventHolderHandler(new SimpleEventHandler());
- }
-
- public void run()
- {
- try
- {
- doRun();
- }
- catch (InterruptedException e)
- {
- e.printStackTrace();
- }
- }
-
- private void doRun() throws InterruptedException
- {
- BatchEventProcessor<EventHolder> batchEventProcessor =
- new BatchEventProcessor<EventHolder>(
- ringBuffer,
- ringBuffer.newBarrier(),
- eventHolderHandler);
- ringBuffer.addGatingSequences(batchEventProcessor.getSequence());
-
- Thread t = new Thread(batchEventProcessor);
- t.start();
-
- long iterations = Constants.ITERATIONS;
- for (long l = 0; l < iterations; l++)
- {
- SimpleEvent e = new SimpleEvent(l, l, l, l);
- ringBuffer.publishEvent(TRANSLATOR, e);
- }
-
- while (batchEventProcessor.getSequence().get() != iterations - 1)
- {
- LockSupport.parkNanos(1);
- }
-
- batchEventProcessor.halt();
- t.join();
- }
-
- private static final EventTranslatorOneArg<EventHolder, SimpleEvent> TRANSLATOR =
- new EventTranslatorOneArg<EventHolder, SimpleEvent>()
- {
- @Override
- public void translateTo(EventHolder holder, long arg1, SimpleEvent event)
- {
- holder.event = event;
- }
- };
-
- public static void main(String[] args)
- {
- new SimplePerformanceTest().run();
- }
-}
diff --git a/src/perftest/java/com/lmax/disruptor/offheap/OneToOneOffHeapThroughputTest.java b/src/perftest/java/com/lmax/disruptor/offheap/OneToOneOffHeapThroughputTest.java
deleted file mode 100644
index 0368eae..0000000
--- a/src/perftest/java/com/lmax/disruptor/offheap/OneToOneOffHeapThroughputTest.java
+++ /dev/null
@@ -1,183 +0,0 @@
-package com.lmax.disruptor.offheap;
-
-import com.lmax.disruptor.*;
-import com.lmax.disruptor.util.DaemonThreadFactory;
-
-import java.nio.ByteBuffer;
-import java.nio.ByteOrder;
-import java.util.Random;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.Executor;
-import java.util.concurrent.Executors;
-import java.util.concurrent.locks.LockSupport;
-
-public class OneToOneOffHeapThroughputTest extends AbstractPerfTestDisruptor
-{
- private static final int BLOCK_SIZE = 256;
- private static final int BUFFER_SIZE = 1024 * 1024;
- private static final long ITERATIONS = 1000 * 1000 * 10L;
-
- private final Executor executor = Executors.newFixedThreadPool(1, DaemonThreadFactory.INSTANCE);
- private final WaitStrategy waitStrategy = new YieldingWaitStrategy();
- private final OffHeapRingBuffer buffer =
- new OffHeapRingBuffer(new SingleProducerSequencer(BUFFER_SIZE, waitStrategy), BLOCK_SIZE);
- private final ByteBufferHandler handler = new ByteBufferHandler();
- private final BatchEventProcessor<ByteBuffer> processor =
- new BatchEventProcessor<ByteBuffer>(buffer, buffer.newBarrier(), handler);
-
- {
- buffer.addGatingSequences(processor.getSequence());
- }
-
- private final Random r = new Random(1);
- private final byte[] data = new byte[BLOCK_SIZE];
-
- public OneToOneOffHeapThroughputTest()
- {
- r.nextBytes(data);
- }
-
- @Override
- protected int getRequiredProcessorCount()
- {
- return 2;
- }
-
- @Override
- protected long runDisruptorPass() throws Exception
- {
- byte[] data = this.data;
-
- final CountDownLatch latch = new CountDownLatch(1);
- long expectedCount = processor.getSequence().get() + ITERATIONS;
- handler.reset(latch, ITERATIONS);
- executor.execute(processor);
- long start = System.currentTimeMillis();
-
- final OffHeapRingBuffer rb = buffer;
-
- for (long i = 0; i < ITERATIONS; i++)
- {
- rb.put(data);
- }
-
- latch.await();
- long opsPerSecond = (ITERATIONS * 1000L) / (System.currentTimeMillis() - start);
- waitForEventProcessorSequence(expectedCount);
- processor.halt();
-
- return opsPerSecond;
- }
-
- private void waitForEventProcessorSequence(long expectedCount)
- {
- while (processor.getSequence().get() < expectedCount)
- {
- LockSupport.parkNanos(1);
- }
- }
-
- public static void main(String[] args) throws Exception
- {
- new OneToOneOffHeapThroughputTest().testImplementations();
- }
-
- public static class ByteBufferHandler implements EventHandler<ByteBuffer>
- {
- private long total = 0;
- private long expectedCount;
- private CountDownLatch latch;
-
- @Override
- public void onEvent(ByteBuffer event, long sequence, boolean endOfBatch) throws Exception
- {
- final int start = event.position();
- for (int i = start, size = start + BLOCK_SIZE; i < size; i += 8)
- {
- total += event.getLong(i);
- }
-
- if (--expectedCount == 0)
- {
- latch.countDown();
- }
- }
-
- public long getTotal()
- {
- return total;
- }
-
- public void reset(CountDownLatch latch, long expectedCount)
- {
- this.latch = latch;
- this.expectedCount = expectedCount;
- }
- }
-
- public static class OffHeapRingBuffer implements DataProvider<ByteBuffer>
- {
- private final Sequencer sequencer;
- private final int entrySize;
- private final ByteBuffer buffer;
- private final int mask;
-
- private final ThreadLocal<ByteBuffer> perThreadBuffer = new ThreadLocal<ByteBuffer>()
- {
- @Override
- protected ByteBuffer initialValue()
- {
- return buffer.duplicate().order(ByteOrder.nativeOrder());
- }
- };
-
- public OffHeapRingBuffer(Sequencer sequencer, int entrySize)
- {
- this.sequencer = sequencer;
- this.entrySize = entrySize;
- this.mask = sequencer.getBufferSize() - 1;
- buffer = ByteBuffer.allocateDirect(sequencer.getBufferSize() * entrySize).order(ByteOrder.nativeOrder());
- }
-
- public void addGatingSequences(Sequence sequence)
- {
- sequencer.addGatingSequences(sequence);
- }
-
- public SequenceBarrier newBarrier()
- {