Skip to content

Instantly share code, notes, and snippets.

@MinCha
Last active December 30, 2015 05:19
Show Gist options
  • Save MinCha/7781468 to your computer and use it in GitHub Desktop.
Save MinCha/7781468 to your computer and use it in GitHub Desktop.
Java Byte Code when getting from array
class HashBasedMutexProvider {
private static final int DEFAULT_DISPERSION = 1000;
private List<Object> mutexes = new ArrayList<Object>();
private int dispersion;
HashBasedMutexProvider() {
this(DEFAULT_DISPERSION);
}
HashBasedMutexProvider(int dispersion) {
this.dispersion = dispersion;
for (int i = 0; i < dispersion; i++) {
mutexes.add(new Object());
}
}
Object get(Object key) {
return mutexes.get(Math.abs(key.hashCode() % dispersion));
}
}
java.lang.Object get(java.lang.Object key);
0 aload_0 [this]
Stack [this] Array [this, key value]
1 getfield com.github.brighttp.HashBasedMutexProvider.mutexes : java.util.List [29]
Stack [mutexes ref] Array [this, key value]
4 aload_1 [key]
Stack [key value, mutexes ref] Array [this, key value]
5 invokevirtual java.lang.Object.hashCode() : int [42]
Stack [hashcode value, mutexes ref] Array [this, key value]
8 aload_0 [this]
Stack [this, hashcode value, mutexes ref] Array [this, key value]
9 getfield com.github.brighttp.HashBasedMutexProvider.dispersion : int [31]
Stack [dispersion value, hashcode value, mutexes] Array [this, key value]
12 irem
Stack ["dispersion % hashcode" value, mutexes] Array [this, key value]
13 invokestatic java.lang.Math.abs(int) : int [46]
Stack [abs(v) value, mutexes] Array [this, key value]
16 invokeinterface java.util.List.get(int) : java.lang.Object [52] [nargs: 2]
Stack [one item on list] Array [this, key value]
21 areturn
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment