Created
October 11, 2024 11:51
-
-
Save kaspernielsen/30f25368afa6f65e1c49dacf2486af91 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class LookupUsage { | |
public static void main(String[] args) throws IOException { | |
record Entry(ClassModel cm, MethodModel mm) {} | |
Map<Integer, List<Entry>> hits = new HashMap<>(); | |
Path javaBasePath = FileSystems.getFileSystem(java.net.URI.create("jrt:/")).getPath("/modules/java.base/java/"); | |
Files.walk(javaBasePath).filter(path -> path.toString().endsWith(".class")).forEach(classFile -> { | |
try { | |
ClassModel cm = ClassFile.of().parse(classFile); | |
if (cm.flags().has(AccessFlag.PUBLIC)) { | |
for (MethodModel mm : cm.methods()) { | |
if (mm.flags().has(AccessFlag.PUBLIC)) { | |
for (int i = 0; i < mm.methodTypeSymbol().parameterCount(); i++) { | |
if (mm.methodTypeSymbol().parameterType(i).descriptorString().equals("Ljava/lang/invoke/MethodHandles$Lookup;")) { | |
hits.computeIfAbsent(i, k -> new ArrayList<>()).add(new Entry(cm, mm)); | |
} | |
} | |
} | |
} | |
} | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
}); | |
for (var e : hits.entrySet()) { | |
System.out.println("\n------" + e.getKey() + " parameter"); | |
e.getValue().forEach(v -> { | |
System.out.println(v.cm.thisClass().asInternalName() + "." + v.mm.methodName() | |
+ v.mm.methodTypeSymbol().parameterList().stream().map(f -> f.displayName()).collect(Collectors.joining(", ", "(", ")"))); | |
}); | |
} | |
} | |
} | |
------0 parameter | |
java/lang/Double.resolveConstantDesc(MethodHandles$Lookup) | |
java/lang/Double.resolveConstantDesc(MethodHandles$Lookup) | |
java/lang/Enum$EnumDesc.resolveConstantDesc(MethodHandles$Lookup) | |
java/lang/Enum$EnumDesc.resolveConstantDesc(MethodHandles$Lookup) | |
java/lang/Float.resolveConstantDesc(MethodHandles$Lookup) | |
java/lang/Float.resolveConstantDesc(MethodHandles$Lookup) | |
java/lang/Integer.resolveConstantDesc(MethodHandles$Lookup) | |
java/lang/Integer.resolveConstantDesc(MethodHandles$Lookup) | |
java/lang/Long.resolveConstantDesc(MethodHandles$Lookup) | |
java/lang/Long.resolveConstantDesc(MethodHandles$Lookup) | |
java/lang/String.resolveConstantDesc(MethodHandles$Lookup) | |
java/lang/String.resolveConstantDesc(MethodHandles$Lookup) | |
java/lang/classfile/ClassHierarchyResolver.ofClassLoading(MethodHandles$Lookup) | |
java/lang/constant/ClassDesc.resolveConstantDesc(MethodHandles$Lookup) | |
java/lang/constant/ClassDesc.resolveConstantDesc(MethodHandles$Lookup) | |
java/lang/constant/ConstantDesc.resolveConstantDesc(MethodHandles$Lookup) | |
java/lang/constant/DynamicCallSiteDesc.resolveCallSiteDesc(MethodHandles$Lookup) | |
java/lang/constant/DynamicConstantDesc.resolveConstantDesc(MethodHandles$Lookup) | |
java/lang/constant/MethodHandleDesc.resolveConstantDesc(MethodHandles$Lookup) | |
java/lang/constant/MethodHandleDesc.resolveConstantDesc(MethodHandles$Lookup) | |
java/lang/constant/MethodTypeDesc.resolveConstantDesc(MethodHandles$Lookup) | |
java/lang/constant/MethodTypeDesc.resolveConstantDesc(MethodHandles$Lookup) | |
java/lang/invoke/ConstantBootstraps.nullConstant(MethodHandles$Lookup, String, Class) | |
java/lang/invoke/ConstantBootstraps.primitiveClass(MethodHandles$Lookup, String, Class) | |
java/lang/invoke/ConstantBootstraps.enumConstant(MethodHandles$Lookup, String, Class) | |
java/lang/invoke/ConstantBootstraps.getStaticFinal(MethodHandles$Lookup, String, Class, Class) | |
java/lang/invoke/ConstantBootstraps.getStaticFinal(MethodHandles$Lookup, String, Class) | |
java/lang/invoke/ConstantBootstraps.invoke(MethodHandles$Lookup, String, Class, MethodHandle, Object[]) | |
java/lang/invoke/ConstantBootstraps.fieldVarHandle(MethodHandles$Lookup, String, Class, Class, Class) | |
java/lang/invoke/ConstantBootstraps.staticFieldVarHandle(MethodHandles$Lookup, String, Class, Class, Class) | |
java/lang/invoke/ConstantBootstraps.arrayVarHandle(MethodHandles$Lookup, String, Class, Class) | |
java/lang/invoke/ConstantBootstraps.explicitCast(MethodHandles$Lookup, String, Class, Object) | |
java/lang/invoke/LambdaMetafactory.metafactory(MethodHandles$Lookup, String, MethodType, MethodType, MethodHandle, MethodType) | |
java/lang/invoke/LambdaMetafactory.altMetafactory(MethodHandles$Lookup, String, MethodType, Object[]) | |
java/lang/invoke/MethodHandles.classData(MethodHandles$Lookup, String, Class) | |
java/lang/invoke/MethodHandles.classDataAt(MethodHandles$Lookup, String, Class, int) | |
java/lang/invoke/StringConcatFactory.makeConcat(MethodHandles$Lookup, String, MethodType) | |
java/lang/invoke/StringConcatFactory.makeConcatWithConstants(MethodHandles$Lookup, String, MethodType, String, Object[]) | |
java/lang/invoke/VarHandle$VarHandleDesc.resolveConstantDesc(MethodHandles$Lookup) | |
java/lang/invoke/VarHandle$VarHandleDesc.resolveConstantDesc(MethodHandles$Lookup) | |
java/lang/runtime/ObjectMethods.bootstrap(MethodHandles$Lookup, String, TypeDescriptor, Class, String, MethodHandle[]) | |
java/lang/runtime/SwitchBootstraps.typeSwitch(MethodHandles$Lookup, String, MethodType, Object[]) | |
java/lang/runtime/SwitchBootstraps.enumSwitch(MethodHandles$Lookup, String, MethodType, Object[]) | |
------1 parameter | |
java/lang/invoke/MethodHandleInfo.reflectAs(Class, MethodHandles$Lookup) | |
java/lang/invoke/MethodHandles.privateLookupIn(Class, MethodHandles$Lookup) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment