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

/Michael
________________________________
From: Sam Thomas <sam.tho...@broadcom.com>
Sent: 25 September 2019 02:11
To: Michael Rasmussen <michael.rasmus...@roguewave.com>
Cc: serviceability-dev@openjdk.java.net <serviceability-dev@openjdk.java.net>; 
daniel.daughe...@oracle.com <daniel.daughe...@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.tho...@broadcom.com<mailto:sam.tho...@broadcom.com>> wrote:
cool thanks

Thanks
./Sam


On Fri, Sep 20, 2019 at 5:05 AM Michael Rasmussen 
<michael.rasmus...@roguewave.com<mailto:michael.rasmus...@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

Reply via email to