Skip to content

Instantly share code, notes, and snippets.

View chrisvest's full-sized avatar
🍉

Chris Vest chrisvest

🍉
View GitHub Profile
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
import java.util.concurrent.ThreadLocalRandom;
import org.openjdk.jmh.annotations.Benchmark;
public class MethodHandleBenchmark
{
private static final MethodHandle workHandle = createWorkHandle();
package org.openjdk.jol.samples;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
import java.lang.reflect.Field;
import org.openjdk.jol.util.VMSupport;
import static java.lang.System.out;

This is a very simple approach to doing role-based access control with Neo4j. It is optimistic, in the sense that all items are assumed to be world-accessible unless they have specific constraints. Item visibility can be constrained to either individual users or all users who belong to a role. Roles are also hierarchical, so can inherit privileges from other roles.

First, lets create our basic example data:

<dependency>
<groupId>com.github.chrisvest</groupId>
<artifactId>stormpot</artifactId>
<version>2.3</version>
</dependency>
@chrisvest
chrisvest / Reachability.java
Last active August 29, 2015 14:10
Reachability fence benchmark
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.Fork;
import org.openjdk.jmh.annotations.Measurement;
import org.openjdk.jmh.annotations.OutputTimeUnit;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.Setup;
import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.annotations.Threads;
import org.openjdk.jmh.annotations.Warmup;
import sun.misc.Unsafe;
public class MemoryHolder {
private long pointer;
public MemoryHolder() {
pointer = unsafe.allocateMemory(MEMORY);
}
@Override
protected void finalize() {
unsafe.freeMemory(pointer);
public static void main(String[] args) {
MemoryHolder holder = new MemoryHolder();
long p = holder.pointer; // last use of 'holder'
int n = unsafe.getInt(null, p);
System.out.println("holder.getInt() = " + n);
}
public static void main(String[] args) {
MemoryHolder holder = new MemoryHolder();
System.out.println("holder.getInt() = " + holder.getInt());
reachabilityFence(holder);
}
@chrisvest
chrisvest / motd
Last active August 29, 2015 14:14
/etc/motd
 ▄▄▄▄▄▄▄▄▄ 
▄▄ ▄▄ ▄▄▄ 
 ▄▄▄▄▄▄ ▄▄    
▄▄ ▄ ▄▄▄ ▄▄ ▄ ▄▄▄▄▄ 
  ▄ ▄  ▄ ▄▄▄
nitsan:object-pool-benchmarks% java -jar target/benchmarks.jar 'Simulation.(newObject|claimReleaseWithout)' -bm sample -i 10 -wi 10 -tu ns -t 1 -f 1 -r 10 -jvmArgsPrepend '-XX:+UseConcMarkSweepGC'
# JMH 1.5.1 (released 10 days ago)
# VM invoker: /usr/lib/jvm/java-8-jdk/jre/bin/java
# VM options: -XX:+UseConcMarkSweepGC
# Warmup: 10 iterations, 1 s each
# Measurement: 10 iterations, 10 s each
# Timeout: 10 min per iteration
# Threads: 1 thread, will synchronize iterations
# Benchmark mode: Sampling time
# Benchmark: objectpoolbenchmark.specific.stormpot.Simulation.claimReleaseWithoutReturn