Skip to content

Instantly share code, notes, and snippets.

View bandrzejczak's full-sized avatar

Bartek Andrzejczak bandrzejczak

View GitHub Profile
public long getPrice() {
return unsafe.getInt(objectOffset + priceOffset);
}
public void setPrice(final int price) {
unsafe.putInt(objectOffset + priceOffset, price);
}
address = unsafe.allocateMemory(TRADES_PER_DAY * UnsafeTrade.getObjectSize());
Constructor<Unsafe> constructor = Unsafe.class.getDeclaredConstructor();
constructor.setAccessible(true);
Unsafe unsafe = constructor.newInstance();
Field field = Unsafe.class.getDeclaredField("theUnsafe");
field.setAccessible(true);
Unsafe unsafe = (Unsafe) field.get(null);
@CallerSensitive
public static Unsafe getUnsafe() {
Class var0 = Reflection.getCallerClass();
if(!VM.isSystemDomainLoader(var0.getClassLoader())) {
throw new SecurityException("Unsafe");
} else {
return theUnsafe;
}
}
private static class UnsafeTrade {
private static long offset = 0;
private static final long ticketOffset = offset += 0;
private static final long amountOffset = offset += 4;
private static final long priceOffset = offset += 4;
private static final long buyOffset = offset += 4;
private static final long objectSize = offset += 1;
#
# A fatal error has been detected by the Java Runtime Environment:
#
# SIGSEGV (0xb) at pc=0xb71a0bde, pid=9350, tid=3066157936
#
# JRE version: Java(TM) SE Runtime Environment (8.0_25-b17) (build 1.8.0_25-b17)
# Java VM: Java HotSpot(TM) Client VM (25.25-b02 mixed mode linux-x86 )
# Problematic frame:
# V [libjvm.so+0x55dbde] Unsafe_SetNativeInt+0x4e
#
val test = if (1==1) "a" else "b"
String test = 1 == 1 ? "a" : "b";
String test;
if(1 == 1)
test = "a";
else
test = "b";