Skip to content

Commit

Permalink
support graalvm native-image, for issue #2406
Browse files Browse the repository at this point in the history
  • Loading branch information
wenshao committed Apr 7, 2024
1 parent 0dbfd58 commit 1fa051e
Showing 1 changed file with 2 additions and 11 deletions.
13 changes: 2 additions & 11 deletions core/src/main/java/com/alibaba/fastjson2/util/JDKUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,22 +71,13 @@ public class JDKUtils {
Unsafe unsafe;
long offset, charOffset;
try {
Field theUnsafeField = null;
for (Field field : Unsafe.class.getDeclaredFields()) {
String fieldName = field.getName();
if (fieldName.equals("theUnsafe")
|| fieldName.equals("THE_ONE") // android
) {
theUnsafeField = field;
break;
}
}
Field theUnsafeField = Unsafe.class.getDeclaredField("theUnsafe");
theUnsafeField.setAccessible(true);
unsafe = (Unsafe) theUnsafeField.get(null);
offset = unsafe.arrayBaseOffset(byte[].class);
charOffset = unsafe.arrayBaseOffset(char[].class);
} catch (Throwable e) {
throw new JSONException("init unsafe error");
throw new JSONException("init unsafe error", e);
}

UNSAFE = unsafe;
Expand Down

0 comments on commit 1fa051e

Please sign in to comment.