Skip to content

Commit

Permalink
Use Lookup.class as the base when retrieving trusted lookup because w…
Browse files Browse the repository at this point in the history
…e know that's where the field is declared.

Fixes #1673
Fixes #1672

PiperOrigin-RevId: 524835342
  • Loading branch information
mcculls authored and Guice Team committed Apr 17, 2023
1 parent 5c37cd9 commit 3399615
Showing 1 changed file with 1 addition and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
final class HiddenClassDefiner implements ClassDefiner {

private static final Object THE_UNSAFE;
private static final Object TRUSTED_LOOKUP_BASE;
private static final Object TRUSTED_LOOKUP_OFFSET;
private static final Method GET_OBJECT_METHOD;
private static final Object HIDDEN_CLASS_OPTIONS;
Expand All @@ -42,8 +41,6 @@ final class HiddenClassDefiner implements ClassDefiner {
theUnsafeField.setAccessible(true);
THE_UNSAFE = theUnsafeField.get(null);
Field trustedLookupField = Lookup.class.getDeclaredField("IMPL_LOOKUP");
Method baseMethod = unsafeType.getMethod("staticFieldBase", Field.class);
TRUSTED_LOOKUP_BASE = baseMethod.invoke(THE_UNSAFE, trustedLookupField);
Method offsetMethod = unsafeType.getMethod("staticFieldOffset", Field.class);
TRUSTED_LOOKUP_OFFSET = offsetMethod.invoke(THE_UNSAFE, trustedLookupField);
GET_OBJECT_METHOD = unsafeType.getMethod("getObject", Object.class, long.class);
Expand All @@ -59,7 +56,7 @@ final class HiddenClassDefiner implements ClassDefiner {
@Override
public Class<?> define(Class<?> hostClass, byte[] bytecode) throws Exception {
Lookup trustedLookup =
(Lookup) GET_OBJECT_METHOD.invoke(THE_UNSAFE, TRUSTED_LOOKUP_BASE, TRUSTED_LOOKUP_OFFSET);
(Lookup) GET_OBJECT_METHOD.invoke(THE_UNSAFE, Lookup.class, TRUSTED_LOOKUP_OFFSET);
Lookup definedLookup =
(Lookup)
HIDDEN_DEFINE_METHOD.invoke(
Expand Down

0 comments on commit 3399615

Please sign in to comment.