Bytecode Instrumentation and Class Loading.

Michael Rasmussen Michael.Rasmussen at roguewave.com
Mon Sep 30 07:21:16 UTC 2019


There is a similar protected method on ClassLoader for that: ClassLoader.findBootstrapClassOrNull

/Michael
________________________________
From: Sam Thomas <sam.thomas at broadcom.com>
Sent: 25 September 2019 02:11
To: Michael Rasmussen <Michael.Rasmussen at roguewave.com>
Cc: serviceability-dev at openjdk.java.net <serviceability-dev at openjdk.java.net>; daniel.daugherty at oracle.com <daniel.daugherty at oracle.com>
Subject: Re: Bytecode Instrumentation and Class Loading.

Hi Michael,

Returning question: I understand that the method findLoadedClass is protected. But say it was public, how would you find out loaded classes on the bootstrap classloader? Since from instrumentation perspective when a loader is null its the bootstrap classloader.

Thanks
./Sam


On Fri, Sep 20, 2019 at 2:08 PM Sam Thomas <sam.thomas at broadcom.com<mailto:sam.thomas at broadcom.com>> wrote:
cool thanks

Thanks
./Sam


On Fri, Sep 20, 2019 at 5:05 AM Michael Rasmussen <Michael.Rasmussen at roguewave.com<mailto:Michael.Rasmussen at roguewave.com>> wrote:
On 9/18/19 2:47 PM, Sam Thomas wrote:
> Hi,
>
> I'm trying to understand if a class will load as soon as all the transformers return. The aim is to get a class reference of a class I have seen in my transformer.

Short answer: no.

Trying to define a class can cause other classes to try to be loaded before (for instance the super types), meaning when you're done transforming class A, the same thread might try to load multiple other classes before it finishes defining A.
And if any of these fail, A will also fail to be defined.

> Also if there is way to get the same without triggering class loading - if the class is not loaded return a null reference.

ClassLoader has a protected method findLoadedClass that checks if a class is loaded by that classloader and returns the Class instance if so, or null otherwise.
But as mentioned, the method is protected so normally not accessible outside the classloader itself.

/Michael
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.java.net/pipermail/serviceability-dev/attachments/20190930/4f8e91c2/attachment.html>


More information about the serviceability-dev mailing list