From 2428fe3035f6c60484172c060ab749948d3e7250 Mon Sep 17 00:00:00 2001 From: TudbuT Date: Sat, 30 Apr 2022 09:45:34 +0200 Subject: [PATCH] !WIP! java 16/17 support --- bootstrap/ISBPL.java | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/bootstrap/ISBPL.java b/bootstrap/ISBPL.java index b20a37c..b66895b 100644 --- a/bootstrap/ISBPL.java +++ b/bootstrap/ISBPL.java @@ -7,6 +7,7 @@ import java.nio.file.Files; import java.util.*; import java.util.concurrent.atomic.AtomicInteger; import java.util.function.Supplier; +import sun.misc.Unsafe; // the Safe /** * @author TudbuT @@ -17,6 +18,16 @@ public class ISBPL { // TODO: fully implement JIO // public static final boolean ENABLE_JINTEROP = true; + static Unsafe theSafe; + static { + try { + Field f = Unsafe.class.getDeclaredField("theUnsafe"); + f.setAccessible(true); + theSafe = (Unsafe) f.get(null); + } catch (Throwable e) { + throw new Error(e); + } + } static boolean debug = false, printCalls = false; public ISBPLDebugger.IPC debuggerIPC = new ISBPLDebugger.IPC(); @@ -983,7 +994,7 @@ public class ISBPL { } for (Field field : clazz.getDeclaredFields()) { addFunction(type, field.getName(), stack -> { - field.setAccessible(true); + forceAccessible(field); if(debug) System.err.println("Java Get: " + field); try { @@ -993,7 +1004,7 @@ public class ISBPL { } }); addFunction(type, "=" + field.getName(), stack -> { - field.setAccessible(true); + forceAccessible(field); if(debug) System.err.println("Java Set: " + field); try { @@ -1024,7 +1035,7 @@ public class ISBPL { Object[] params = resolve(mid, stack, entry.getValue().get(0).getParameterCount(), paramTypes); Method method = ms.get(mid.get()); - method.setAccessible(true); + forceAccessible(method); if(debug) System.err.println("Java Call: " + method + " - " + Arrays.toString(params)); try { @@ -1060,7 +1071,7 @@ public class ISBPL { Object[] params = resolve(mid, stack, entry.getValue().get(0).getParameterCount(), paramTypes); Constructor constructor = ms.get(mid.get()); - constructor.setAccessible(true); + forceAccessible(constructor); if(debug) System.err.println("Java Call: new - " + Arrays.toString(params)); try { @@ -1545,6 +1556,15 @@ public class ISBPL { return bytes.toString(); } + private static void forceAccessible(AccessibleObject thing) { + try { + theSafe.putBoolean(thing, theSafe.objectFieldOffset(AccessibleObject.class.getDeclaredField("override")), true); + } catch(Exception e) { //we are doomed + e.printStackTrace(); + System.err.println("Failed to set accessible property. We are doomed."); + System.exit(1); + } + } } interface ISBPLKeyword {