Skip to content

Instantly share code, notes, and snippets.

@alexkasko
alexkasko / sun.misc.Unsafe.diff
Created March 13, 2013 21:03
Patch to OpenJDK6 sun.misc.Unsafe class that restores additional copyMemory method
diff --git a/jdk/src/share/classes/sun/misc/Unsafe.java b/jdk/src/share/classes/sun/misc/Unsafe.java
index 345f654..5b6b54a 100644
--- a/jdk/src/share/classes/sun/misc/Unsafe.java
+++ b/jdk/src/share/classes/sun/misc/Unsafe.java
@@ -502,11 +502,41 @@ public final class Unsafe {
public native void setMemory(long address, long bytes, byte value);
/**
+ * alexkasko: reverting changes to match jdk7 signature
+ * http://hg.openjdk.java.net/jdk6/jdk6/jdk/diff/39e8fe7a0af1/src/share/classes/sun/misc/Unsafe.java
@alexkasko
alexkasko / LongPackUtils.java
Created February 16, 2013 18:58
Utility methods to pack long (limited by bits) and int into one long and read them from there
public class LongPackUtils {
public static long pack(long big, int little, int bits) {
assert bits > 32 && bits < 64;
assert big < (1L << bits);
assert little < (1 << (64 - bits));
int ls = bits % 8;
int bm = (1 << ls) - 1;
long res = (big & ~bm) << (64 - bits);
res |= (little & ((1L << (64 - bits)) - 1)) << ls;
res |= big & bm;
@Test
public void testTcp() throws InterruptedException {
new Thread(new Runnable() {
@Override
public void run() {
try {
ServerSocket ss = new ServerSocket();
ss.bind(new InetSocketAddress(2121));
Socket client = ss.accept();
byte[] data = new byte[200];
public class BeanPropertySqlParameterSourceNotThreadSafeTest {
@Test
public void test() throws InterruptedException {
BeanPropertySqlParameterSource sps = new BeanPropertySqlParameterSource(new ImmutableClass());
Thread[] threads = new Thread[1000];
CountDownLatch latch = new CountDownLatch(1000);
for (int i = 0; i < 1000; i++) {
Thread th = new TestThread(latch, sps);
threads[i] = th;
th.start();
@alexkasko
alexkasko / LimitedExecutorServiceWrapper.java
Created November 9, 2012 14:08
ExecutorService wrapper, limits max parallel threads
/**
* {@link ExecutorService} wrapper, limit max parallel threads to provided limit.
* May be useful for task with different parrallelism over the same executor.
*
* @author alexkasko
* Date: 7/6/12
*/
public class LimitedExecutorServiceWrapper implements ExecutorService {
private final ExecutorService target;
private final Semaphore semaphore;