I was not sure so I also raised the same question here

https://github.com/google/guice/discussions/1902 


On Tuesday, May 27, 2025 at 2:29:57 PM UTC+10 Behrooz Nobakht wrote:

> When using Interception API with Guice, the enhanced classes by Guice 
> follow a specific pattern which is controlled/generated by Enhancer or 
> AbstractGlueGenerator. The naming pattern includes the hashCode(). The 
> design choice is understandable.
>
> However, there're use cases where the Class.getName() is distorted by the 
> naming pattern. For example, consider a continuous profiling that runs on 
> an application. In every instance of JVM, the class names are generated 
> with a different hashCode(). Maybe there's a way to always ensure a 
> consistent hashCode() but that also depends on the JVM.
>
> In this use case, since the name of the classes are different per JVM 
> instance, the collected profiling data appear as if they're collected from 
> *different 
> object types*; though the underlying object is all the same.
>
> For example, if MyService is intercepted, then it appears in the 
> profiling data as both MyService$$EnhancedByGuice$$111 and 
> MyService$$EnhancedByGuice$$222. They are both the same type but 
> intercepted in different JVM instances or the same JVM at different times.
>
> I am looking for a way to extend/configure/plug a way into how Guice 
> generates the proxyName -- link 
> <https://github.com/google/guice/blob/master/core/src/com/google/inject/internal/aop/AbstractGlueGenerator.java#L100>
>
> ===
> protected AbstractGlueGenerator(Class<?> hostClass, String marker) {
>     this.hostClass = hostClass;
>     this.hostName = Type.getInternalName(hostClass);
>     this.proxyName = proxyName(hostName, marker, hashCode());
>   }
>
>   /** Generates a unique name based on the original class name and marker. 
> */
>   private static String proxyName(String hostName, String marker, int 
> hash) {
>     long id = ((hash & 0x000FFFFF) | (COUNTER.getAndIncrement() << 20));
>     String proxyName = hostName + marker + Long.toHexString(id);
>     if (proxyName.startsWith("java/") && 
> !ClassDefining.hasPackageAccess()) {
>       proxyName = '$' + proxyName; // can't define java.* glue in same 
> package
>     }
>     return proxyName;
>   }
> ===
>
> Thanks,
> Behrooz
>

-- 
You received this message because you are subscribed to the Google Groups 
"google-guice" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion visit 
https://groups.google.com/d/msgid/google-guice/f4d84724-e4f3-43d3-9151-475978b4b040n%40googlegroups.com.

Reply via email to