This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static final Unsafe unsafe; | |
static | |
{ | |
try | |
{ | |
// This is a bit of voodoo to force the unsafe object into | |
// visibility and acquire it. | |
// This is not playing nice, but as an established back door it is | |
// not likely to be taken away. | |
Field field = Unsafe.class.getDeclaredField("theUnsafe"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static final long valueFieldOffset; | |
private static final long countFieldOffset; | |
private static final long offsetFieldOffset; | |
static | |
{ | |
try | |
{ | |
valueFieldOffset = UnsafeAccess.unsafe.objectFieldOffset(String.class.getDeclaredField("value")); | |
countFieldOffset = UnsafeAccess.unsafe.objectFieldOffset(String.class.getDeclaredField("count")); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public final static String buildUnsafe(char[] chars){ | |
String mutable = new String();// an empty string to hack | |
UnsafeAccess.unsafe.putObject(mutable,valueFieldOffset,chars); | |
UnsafeAccess.unsafe.putInt(mutable,countFieldOffset,chars.length); | |
return mutable; | |
} | |
public final static String buildUnsafe(char[] chars, int offset, int length){ | |
String mutable = new String();// an empty string to hack | |
UnsafeAccess.unsafe.putObject(mutable,valueFieldOffset,chars); | |
UnsafeAccess.unsafe.putInt(mutable,countFieldOffset,length); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
// On the ping thread | |
for (long l = 0; l < iterations; l++) { | |
pingValue.set(l); | |
while (pongValue.get() != l) | |
; | |
} | |
... | |
// On the pong thread |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private volatile long value; | |
private static final long valueOffset; | |
static { | |
try { | |
valueOffset = UnsafeAccess.unsafe.objectFieldOffset(VolatileLong.class.getDeclaredField("value")); | |
} catch (Exception e) { | |
throw new RuntimeException(e); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
final class Producer implements Runnable { | |
public void run() { | |
latch.countDown(); | |
for (long l = 0; l < ITERATIONS; l++) { | |
values[(int) l] = l; | |
producerIndex.set(l); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Server loop | |
... | |
accepted = serverSocket.accept(); | |
accepted.socket().setTcpNoDelay(true); | |
accepted.configureBlocking(false); | |
serverSocket.close(); | |
while (!Thread.interrupted()) { | |
buffy.clear(); | |
do { | |
if (accepted.read(buffy) == -1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static final long addressOffset; | |
static { | |
try { | |
addressOffset = UnsafeAccess.unsafe.objectFieldOffset(Buffer.class.getDeclaredField("address")); | |
} catch (Exception e) { | |
throw new RuntimeException(e); | |
} | |
} | |
public static long getAddress(ByteBuffer buffy) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package alignment; | |
import java.nio.ByteBuffer; | |
import util.UnsafeAccess; | |
import static util.UnsafeDirectByteBuffer.*; | |
import com.google.caliper.Param; | |
import com.google.caliper.SimpleBenchmark; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<project xmlns:ivy="antlib:org.apache.ivy.ant" name="TheBestestProjectEver" default="build"> | |
<property name="ivy.install.version" value="2.0.0-beta1" /> | |
<property name="ivy.jar.dir" value="${basedir}/ivy" /> | |
<property name="ivy.jar.file" value="${ivy.jar.dir}/ivy.jar" /> | |
<property name="allocation.jar.file" value="${basedir}/lib/allocation.jar" /> | |
<condition property="skip.download.ivy"> | |
<and> | |
<available file="${ivy.jar.file}"/> | |
</and> | |
</condition> |
OlderNewer