Skip to content

Commit

Permalink
Provide a system property to opt-out of using sun.misc.Unsafe
Browse files Browse the repository at this point in the history
Property: joml.nounsafe

This also allows to use non-direct buffers, but is slower than using direct buffers with sun.misc.Unsafe.
This option is only provided for cases when JOML is used without an OpenGL binding library.
  • Loading branch information
httpdigest committed Jul 12, 2016
1 parent 23bbc19 commit 9be40bd
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/org/joml/MemUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,25 @@ of this software and associated documentation files (the "Software"), to deal
* @author Kai Burjack
*/
abstract class MemUtil {
private static final boolean nounsafe = hasOption("joml.nounsafe");
static final MemUtil INSTANCE = createInstance();

private static boolean hasOption(String option) {
String v = System.getProperty(option);
if (v == null)
return false;
if (v.trim().length() == 0)
return true;
return Boolean.valueOf(v).booleanValue();
}

private static final MemUtil createInstance() {
MemUtil accessor;
try {
accessor = new MemUtilUnsafe();
if (nounsafe)
accessor = new MemUtilNIO();
else
accessor = new MemUtilUnsafe();
} catch (Throwable e) {
accessor = new MemUtilNIO();
}
Expand Down

0 comments on commit 9be40bd

Please sign in to comment.