Add a module-info.java, use unfettered in MemoryUtilSun
This commit is contained in:
parent
0c1e38ab31
commit
fc8b1a9fbe
|
@ -252,6 +252,7 @@ compile_java = export(task("compile_java", function(env)
|
|||
local p = path.path.value
|
||||
return not p:startswith(ignore_a, ignore_b, ignore_c, ignore_d)
|
||||
end)
|
||||
table.insert(srcs, rootedpath(path("src/module"), path("src/module") .. "module-info.java"))
|
||||
push_all(srcs, generate().java)
|
||||
table.freeze(srcs)
|
||||
|
||||
|
@ -261,7 +262,10 @@ compile_java = export(task("compile_java", function(env)
|
|||
libs .. "unfettered.jar",
|
||||
libs .. "jinput.jar",
|
||||
libs .. "AppleJavaExtensions.jar",
|
||||
})
|
||||
}),
|
||||
extra_args = {
|
||||
"--add-reads", "lwjgl=ALL-UNNAMED",
|
||||
},
|
||||
})
|
||||
end))
|
||||
|
||||
|
|
|
@ -38,7 +38,7 @@ import java.lang.reflect.Method;
|
|||
import java.lang.reflect.Modifier;
|
||||
import java.nio.Buffer;
|
||||
|
||||
import sun.misc.Unsafe;
|
||||
import dev.pfaff.unfettered.UnsafeWrapper;
|
||||
|
||||
/**
|
||||
* MemoryUtil.Accessor implementations that depend on sun.misc.
|
||||
|
@ -55,53 +55,19 @@ final class MemoryUtilSun {
|
|||
/** Implementation using sun.misc.Unsafe. */
|
||||
private static class AccessorUnsafe implements MemoryUtil.Accessor {
|
||||
|
||||
private final Unsafe unsafe;
|
||||
private final long address;
|
||||
|
||||
AccessorUnsafe() {
|
||||
try {
|
||||
unsafe = getUnsafeInstance();
|
||||
address = unsafe.objectFieldOffset(MemoryUtil.getAddressField());
|
||||
address = UnsafeWrapper.objectFieldOffset(MemoryUtil.getAddressField());
|
||||
} catch (Exception e) {
|
||||
throw new UnsupportedOperationException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public long getAddress(final Buffer buffer) {
|
||||
return unsafe.getLong(buffer, address);
|
||||
return UnsafeWrapper.getLong(buffer, address);
|
||||
}
|
||||
|
||||
private static Unsafe getUnsafeInstance() {
|
||||
final Field[] fields = Unsafe.class.getDeclaredFields();
|
||||
|
||||
/*
|
||||
Different runtimes use different names for the Unsafe singleton,
|
||||
so we cannot use .getDeclaredField and we scan instead. For example:
|
||||
|
||||
Oracle: theUnsafe
|
||||
PERC : m_unsafe_instance
|
||||
Android: THE_ONE
|
||||
*/
|
||||
for ( Field field : fields ) {
|
||||
if ( !field.getType().equals(Unsafe.class) )
|
||||
continue;
|
||||
|
||||
final int modifiers = field.getModifiers();
|
||||
if ( !(Modifier.isStatic(modifiers) && Modifier.isFinal(modifiers)) )
|
||||
continue;
|
||||
|
||||
field.setAccessible(true);
|
||||
try {
|
||||
return (Unsafe)field.get(null);
|
||||
} catch (IllegalAccessException e) {
|
||||
// ignore
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/** Implementation using {@link java.lang.MethodHandle}s on ByteBuffer. Reflection is used to acquire the handle. */
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
module org.lwjgl {
|
||||
requires java.desktop;
|
||||
requires dev.pfaff.unfettered;
|
||||
requires static jinput;
|
||||
|
||||
exports org.lwjgl;
|
||||
exports org.lwjgl.examples;
|
||||
exports org.lwjgl.examples.spaceinvaders;
|
||||
exports org.lwjgl.input;
|
||||
exports org.lwjgl.openal;
|
||||
exports org.lwjgl.opencl;
|
||||
exports org.lwjgl.opencl.api;
|
||||
exports org.lwjgl.opengl;
|
||||
exports org.lwjgl.opengles;
|
||||
/*exports org.lwjgl.test;
|
||||
exports org.lwjgl.test.glu;
|
||||
exports org.lwjgl.test.glu.tessellation;
|
||||
exports org.lwjgl.test.input;
|
||||
exports org.lwjgl.test.mapped;
|
||||
exports org.lwjgl.test.openal;
|
||||
exports org.lwjgl.test.opencl;
|
||||
exports org.lwjgl.test.opencl.gl;
|
||||
exports org.lwjgl.test.opengl;
|
||||
exports org.lwjgl.test.opengl.multithread;
|
||||
exports org.lwjgl.test.opengl.pbuffers;
|
||||
exports org.lwjgl.test.opengl.shaders;
|
||||
exports org.lwjgl.test.opengl.sprites;
|
||||
exports org.lwjgl.test.opengles;
|
||||
exports org.lwjgl.test.opengles.util;*/
|
||||
exports org.lwjgl.util;
|
||||
/*exports org.lwjgl.util.generator;
|
||||
exports org.lwjgl.util.generator.openal;
|
||||
exports org.lwjgl.util.generator.opencl;
|
||||
exports org.lwjgl.util.generator.opengl;*/
|
||||
exports org.lwjgl.util.glu;
|
||||
exports org.lwjgl.util.glu.tessellation;
|
||||
exports org.lwjgl.util.input;
|
||||
exports org.lwjgl.util.jinput;
|
||||
//exports org.lwjgl.util.mapped;
|
||||
exports org.lwjgl.util.vector;
|
||||
}
|
Loading…
Reference in New Issue