Skip to content

Commit 14b1f28

Browse files
committed
Fixes #34 with some unsafe magic
1 parent a1c2847 commit 14b1f28

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

compiler/src/main/java/net/openhft/compiler/CompilerUtils.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,15 @@
2222
import org.jetbrains.annotations.Nullable;
2323
import org.slf4j.Logger;
2424
import org.slf4j.LoggerFactory;
25+
import sun.misc.Unsafe;
2526

2627
import javax.tools.JavaCompiler;
2728
import javax.tools.StandardJavaFileManager;
2829
import javax.tools.ToolProvider;
2930
import java.io.*;
3031
import java.lang.management.ManagementFactory;
32+
import java.lang.reflect.AccessibleObject;
33+
import java.lang.reflect.Field;
3134
import java.lang.reflect.InvocationTargetException;
3235
import java.lang.reflect.Method;
3336
import java.nio.charset.Charset;
@@ -50,9 +53,14 @@ public enum CompilerUtils {
5053

5154
static {
5255
try {
56+
Field theUnsafe = Unsafe.class.getDeclaredField("theUnsafe");
57+
theUnsafe.setAccessible(true);
58+
Unsafe u = (Unsafe) theUnsafe.get(null);
5359
DEFINE_CLASS_METHOD = ClassLoader.class.getDeclaredMethod("defineClass", String.class, byte[].class, int.class, int.class);
54-
DEFINE_CLASS_METHOD.setAccessible(true);
55-
} catch (NoSuchMethodException e) {
60+
Field f = AccessibleObject.class.getDeclaredField("override");
61+
long offset = u.objectFieldOffset(f);
62+
u.putBoolean(DEFINE_CLASS_METHOD, offset, true);
63+
} catch (NoSuchMethodException | IllegalAccessException | NoSuchFieldException e) {
5664
throw new AssertionError(e);
5765
}
5866
}

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919

2020
<parent>
2121
<groupId>net.openhft</groupId>
22-
<artifactId>root-parent-pom</artifactId>
23-
<version>1.1.12</version>
22+
<artifactId>java-parent-pom</artifactId>
23+
<version>1.1.16</version>
2424
<relativePath />
2525
</parent>
2626

0 commit comments

Comments
 (0)