When is ClassLoader checkPackageAccess method called

439 Views Asked by At

I would like to understand when the JVM calls the checkPackageAccess method of a ClassLoader. From the javadoc, I read that it is called by the JVM after loading class with the classloader. But I found out that sometimes it is called more than one time after a loadclass. On what basis does the JVM decide to call it. I would really appreciate it, if someone can clarify the method.

To make it easier to understand, here is what I did:

  1. I run the same program twice. Both times with -noverify
  2. In one run I remove the <clinit> from the classes, in the other run not.

The run with <clinit> looks like this: Run with clinit

The one without like this: Run without clinit

So as you can see the run without clinit leads to three calls to checkPackageAccess after java.sql.DriverPropertyInfo was loaded while the normal run (with clinit) only leads to one. Since in both runs the <clinit> (neither the original one, not the empty one in the second run) is not yet exeuted I wonder what leads the JVM to perform this checkPackageAccess call.

  • First checkPackageAccess is for java.sql.DriverPropertyInfo (in
    both runs)
  • Second one is for java.util.concurrent.ConcurrentHashMap
  • Third one is for java.lang.ref.ReferenceQueue

I use JVMTI methodEntry and methodExit events to generate a trace of everything that is happening. Nevertheless I can't explain what leads to those additional checkPackageAccess calls.

0

There are 0 best solutions below