You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Github jamm is a memory meter application which is used in the dacapo benchmarking suite. It does some rather insane stuff with Unsafe to directly access properties of a String.
Fieldfield = String.class.getDeclaredField("value");
Optional<MethodHandle> mayBeTrySetAccessible = MethodHandleUtils.mayBeMethodHandle(Field.class, "trySetAccessible"); // Added in Java 9if (mayBeTrySetAccessible.isPresent()) {
// Base on the JMH benchmarks, Unsafe is faster than using a MethodHandle so we try to use Unsafe first and default to reflection if it is unavailable. Unsafeunsafe = VM.getUnsafe();
if (unsafe == null) {
if ((boolean) mayBeTrySetAccessible.get().invoke(field)) {
returnnewPlainReflectionStringMeter(methodHandle(field));
}
thrownewCannotAccessFieldException("The value of the 'value' field from java.lang.String"
+ " cannot be retrieved as the field cannot be made accessible and Unsafe is unavailable");
}
longvalueFieldOffset = unsafe.objectFieldOffset(field);
returnnewUnsafeStringMeter(unsafe, valueFieldOffset);
}
As we exchange String with IASString here, the code tries to access a property of IASString (i.e., the value char array) that does not exist.
Fixing this is fairly involved, and probably needs a special case catching such attempts.
Github jamm is a memory meter application which is used in the dacapo benchmarking suite. It does some rather insane stuff with Unsafe to directly access properties of a String.
As we exchange String with IASString here, the code tries to access a property of IASString (i.e., the value char array) that does not exist.
Fixing this is fairly involved, and probably needs a special case catching such attempts.