Skip to content

Commit

Permalink
Revert invalid commits from JDK9 branch
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeb01 committed Feb 13, 2020
1 parent c61cda1 commit c5ffca3
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 674 deletions.
47 changes: 11 additions & 36 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ apply plugin: 'idea'
defaultTasks 'build'

group = 'com.lmax'
version = new Version(major: 3, minor: 5, revision: 0)
version = new Version(major: 3, minor: 4, revision: 3)

ext {
fullName = 'Disruptor Framework'
Expand All @@ -41,10 +41,8 @@ ext {
if (!project.hasProperty('sonatypePassword')) sonatypePassword = ''
}


sourceSets {
perf.java.srcDir file('src/perftest/java')
java9.java.srcDir file('src/main/java9')
}

eclipse.classpath.plusConfigurations += [ sourceSets.perf.compileClasspath ]
Expand All @@ -57,40 +55,24 @@ dependencies {
// checkstyle 'com.puppycrawl.tools:checkstyle:8.12'
testCompile 'junit:junit:4.12'
perfCompile 'org.hdrhistogram:HdrHistogram:2.1.10'
java9Compile sourceSets.main.output
}

idea.module {
testSourceDirs += sourceSets.perf.allSource.srcDirs
scopes.TEST.plus += [ configurations.perfCompile ]
}

sourceCompatibility = 1.7
targetCompatibility = 1.7


compileJava {
// Suppress warnings about using Unsafe and sun.misc
options.compilerArgs << '-XDignore.symbol.file'
options.fork = true
options.debug = true
options.forkOptions.executable = javaCompilerExecutable
options.warnings = false
sourceCompatibility = 1.7
targetCompatibility = 1.7
}

compileJava9Java {
sourceCompatibility = 1.9
targetCompatibility = 1.9
// options.compilerArgs.addAll(['--release', '9'])
}

task testJava9(type: Test) {
dependsOn jar
def jdkHome = System.getenv("JAVA_9")
classpath = files(jar.archivePath, classpath) - sourceSets.main.output
executable = file("$jdkHome/bin/java")
doFirst {
println classpath.asPath
println "$name runs test using JDK 9"
}
}

tasks.withType(Test) {
Expand All @@ -114,19 +96,12 @@ javadoc {
}

jar {
manifest.attributes(
'Built-By': System.properties['user.name'],
'Bundle-Name': fullName,
'Bundle-Vendor': teamName,
'Bundle-Description': fullDescription,
'Bundle-DocURL': siteUrl,
'Multi-Release': true,
'Automatic-Module-Name': moduleName
)

into('META-INF/versions/9') {
from sourceSets.java9.output
}
manifest.attributes('Built-By': System.properties['user.name'],
'Bundle-Name': fullName,
'Bundle-Vendor': teamName,
'Bundle-Description': fullDescription,
'Bundle-DocURL': siteUrl,
'Automatic-Module-Name': moduleName)
}

task sourcesJar(type: Jar) {
Expand Down
37 changes: 0 additions & 37 deletions src/main/java/com/lmax/disruptor/Main.java

This file was deleted.

53 changes: 43 additions & 10 deletions src/main/java/com/lmax/disruptor/RingBuffer.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@
package com.lmax.disruptor;


import sun.misc.Unsafe;

import com.lmax.disruptor.dsl.ProducerType;
import com.lmax.disruptor.util.Util;

abstract class RingBufferPad
{
Expand All @@ -25,40 +28,69 @@ abstract class RingBufferPad

abstract class RingBufferFields<E> extends RingBufferPad
{
private static final int BUFFER_PAD;
private static final long REF_ARRAY_BASE;
private static final int REF_ELEMENT_SHIFT;
private static final Unsafe UNSAFE = Util.getUnsafe();

static
{
final int scale = UNSAFE.arrayIndexScale(Object[].class);
if (4 == scale)
{
REF_ELEMENT_SHIFT = 2;
}
else if (8 == scale)
{
REF_ELEMENT_SHIFT = 3;
}
else
{
throw new IllegalStateException("Unknown pointer size");
}
BUFFER_PAD = 128 / scale;
// Including the buffer pad in the array base offset
REF_ARRAY_BASE = UNSAFE.arrayBaseOffset(Object[].class) + 128;
}

private final long indexMask;
private final Object[] entries;
protected final int bufferSize;
protected final Sequencer sequencer;

RingBufferFields(
EventFactory<E> eventFactory,
Sequencer sequencer)
{
this.sequencer = sequencer;
this.bufferSize = sequencer.getBufferSize();

if (sequencer.getBufferSize() < 1)
if (bufferSize < 1)
{
throw new IllegalArgumentException("bufferSize must not be less than 1");
}
if (Integer.bitCount(sequencer.getBufferSize()) != 1)
if (Integer.bitCount(bufferSize) != 1)
{
throw new IllegalArgumentException("bufferSize must be a power of 2");
}

this.entries = new Object[sequencer.getBufferSize()];
this.indexMask = bufferSize - 1;
this.entries = new Object[sequencer.getBufferSize() + 2 * BUFFER_PAD];
fill(eventFactory);
}

private void fill(EventFactory<E> eventFactory)
{
for (int i = 0; i < entries.length; i++)
for (int i = 0; i < bufferSize; i++)
{
entries[i] = eventFactory.newInstance();
entries[BUFFER_PAD + i] = eventFactory.newInstance();
}
}

@SuppressWarnings("unchecked")
protected final E elementAt(long sequence)
{
return (E) entries[(int) (sequence & (entries.length - 1))];
return (E) UNSAFE.getObject(entries, REF_ARRAY_BASE + ((sequence & indexMask) << REF_ELEMENT_SHIFT));
}
}

Expand Down Expand Up @@ -405,7 +437,7 @@ public long getCursor()
*/
public int getBufferSize()
{
return sequencer.getBufferSize();
return bufferSize;
}

/**
Expand Down Expand Up @@ -878,9 +910,9 @@ private void checkBatchSizing(int batchStartsAt, int batchSize)
{
throw new IllegalArgumentException("Both batchStartsAt and batchSize must be positive but got: batchStartsAt " + batchStartsAt + " and batchSize " + batchSize);
}
else if (batchSize > sequencer.getBufferSize())
else if (batchSize > bufferSize)
{
throw new IllegalArgumentException("The ring buffer cannot accommodate " + batchSize + " it only has space for " + sequencer.getBufferSize() + " entities.");
throw new IllegalArgumentException("The ring buffer cannot accommodate " + batchSize + " it only has space for " + bufferSize + " entities.");
}
}

Expand Down Expand Up @@ -1092,7 +1124,8 @@ private void translateAndPublishBatch(
public String toString()
{
return "RingBuffer{" +
"sequencer=" + sequencer +
"bufferSize=" + bufferSize +
", sequencer=" + sequencer +
"}";
}
}
Loading

0 comments on commit c5ffca3

Please sign in to comment.