Better tools for adjusting to strong encapsulation
Alan Bateman
Alan.Bateman at oracle.com
Thu Mar 23 08:12:25 UTC 2017
On 22/03/2017 21:07, Jochen Theodorou wrote:
> the warnings you are seeing are from the groovy runtime trying to
> determine - in a pre JDK9 compatible way - if it is allowed to call
> the methods on Objecz. This happens in a first step by setAccessible
> on all methods using the array version, and if that fails by using the
> normal setAccessible on each method (which will contribute to much
> longer startup times). At no point our runtime or the program you
> wrote are trying to call finalize, clone or registerNatives.
This sounds like Object.class.getDeclaredMethods() and then invoking
setAccessible(true) on every method, is that right? If so then it will
trigger warnings for non-public methods. Is there any reason why this
code couldn't just look at the modifiers? Claes mentions the new
canAccess which might be useful going forward.
>
> The only one we are to be blamed for is
> MethodHandles$Lookup(java.lang.Class,int), for which I haven´t
> implemented the alternative yet
>
> If you did other programs... like for example running a gradle
> build... you would see many many more such lines
Lots of lines but not clear to me that it's Gradle that wants to hack
into every non-public member of java.util.ArrayList.
$ gradle
NOTE: Picked up the following options via JDK_JAVA_OPTIONS:
--permit-illegal-access
WARNING: --permit-illegal-access will be removed in the next major release
WARNING: Illegal access by org.gradle.internal.reflect.JavaMethod
(file:/gradle-3.4.1/lib/gradle-base-services-3.4.1.jar) to method
java.lang.ClassLoader.getPackages() (permitted by --permit-illegal-access)
Starting a Gradle Daemon, 1 stopped Daemon could not be reused, use
--status for details
WARNING: Illegal access by org.gradle.internal.reflect.JavaMethod
(file:/gradle-3.4.1/lib/gradle-base-services-3.4.1.jar) to method
java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int)
(permitted by --permit-illegal-access)
WARNING: Illegal access by
org.codehaus.groovy.reflection.CachedClass$3$1
(file:/gradle-3.4.1/lib/groovy-all-2.4.7.jar) to method
java.lang.Object.finalize() (permitted by --permit-illegal-access)
WARNING: Illegal access by
org.codehaus.groovy.reflection.CachedClass$3$1
(file:/gradle-3.4.1/lib/groovy-all-2.4.7.jar) to method
java.lang.Object.clone() (permitted by --permit-illegal-access)
WARNING: Illegal access by
org.codehaus.groovy.reflection.CachedClass$3$1
(file:/gradle-3.4.1/lib/groovy-all-2.4.7.jar) to method
java.lang.Object.registerNatives() (permitted by --permit-illegal-access)
WARNING: Illegal access by org.codehaus.groovy.vmplugin.v7.Java7$1
(file:/gradle-3.4.1/lib/groovy-all-2.4.7.jar) to constructor
java.lang.invoke.MethodHandles$Lookup(java.lang.Class,int) (permitted by
--permit-illegal-access)
WARNING: Illegal access by org.gradle.internal.reflect.JavaMethod
(file:/gradle-3.4.1/lib/gradle-base-services-3.4.1.jar) to method
java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int)
(permitted by --permit-illegal-access)
WARNING: Illegal access by
org.codehaus.groovy.reflection.CachedClass$3$1
(file:/gradle-3.4.1/lib/groovy-all-2.4.7.jar) to method
java.util.AbstractCollection.hugeCapacity(int) (permitted by
--permit-illegal-access)
WARNING: Illegal access by
org.codehaus.groovy.reflection.CachedClass$3$1
(file:/gradle-3.4.1/lib/groovy-all-2.4.7.jar) to method
java.util.AbstractCollection.finishToArray(java.lang.Object[],java.util.Iterator)
(permitted by --permit-illegal-access)
WARNING: Illegal access by
org.codehaus.groovy.reflection.CachedClass$3$1
(file:/gradle-3.4.1/lib/groovy-all-2.4.7.jar) to method
java.util.AbstractList.subListRangeCheck(int,int,int) (permitted by
--permit-illegal-access)
WARNING: Illegal access by
org.codehaus.groovy.reflection.CachedClass$3$1
(file:/gradle-3.4.1/lib/groovy-all-2.4.7.jar) to method
java.util.AbstractList.removeRange(int,int) (permitted by
--permit-illegal-access)
WARNING: Illegal access by
org.codehaus.groovy.reflection.CachedClass$3$1
(file:/gradle-3.4.1/lib/groovy-all-2.4.7.jar) to method
java.util.AbstractList.rangeCheckForAdd(int) (permitted by
--permit-illegal-access)
WARNING: Illegal access by
org.codehaus.groovy.reflection.CachedClass$3$1
(file:/gradle-3.4.1/lib/groovy-all-2.4.7.jar) to method
java.util.AbstractList.outOfBoundsMsg(int) (permitted by
--permit-illegal-access)
WARNING: Illegal access by
org.codehaus.groovy.reflection.CachedClass$3$1
(file:/gradle-3.4.1/lib/groovy-all-2.4.7.jar) to method
java.util.ArrayList.add(java.lang.Object,java.lang.Object[],int)
(permitted by --permit-illegal-access)
WARNING: Illegal access by
org.codehaus.groovy.reflection.CachedClass$3$1
(file:/gradle-3.4.1/lib/groovy-all-2.4.7.jar) to method
java.util.ArrayList.access$000(java.util.ArrayList) (permitted by
--permit-illegal-access)
WARNING: Illegal access by
org.codehaus.groovy.reflection.CachedClass$3$1
(file:/gradle-3.4.1/lib/groovy-all-2.4.7.jar) to method
java.util.ArrayList.elementAt(java.lang.Object[],int) (permitted by
--permit-illegal-access)
WARNING: Illegal access by
org.codehaus.groovy.reflection.CachedClass$3$1
(file:/gradle-3.4.1/lib/groovy-all-2.4.7.jar) to method
java.util.ArrayList.readObject(java.io.ObjectInputStream) (permitted by
--permit-illegal-access)
WARNING: Illegal access by
org.codehaus.groovy.reflection.CachedClass$3$1
(file:/gradle-3.4.1/lib/groovy-all-2.4.7.jar) to method
java.util.ArrayList.writeObject(java.io.ObjectOutputStream) (permitted
by --permit-illegal-access)
WARNING: Illegal access by
org.codehaus.groovy.reflection.CachedClass$3$1
(file:/gradle-3.4.1/lib/groovy-all-2.4.7.jar) to method
java.util.ArrayList.newCapacity(int) (permitted by --permit-illegal-access)
WARNING: Illegal access by
org.codehaus.groovy.reflection.CachedClass$3$1
(file:/gradle-3.4.1/lib/groovy-all-2.4.7.jar) to method
java.util.ArrayList.hugeCapacity(int) (permitted by --permit-illegal-access)
WARNING: Illegal access by
org.codehaus.groovy.reflection.CachedClass$3$1
(file:/gradle-3.4.1/lib/groovy-all-2.4.7.jar) to method
java.util.ArrayList.removeIf(java.util.function.Predicate,int,int)
(permitted by --permit-illegal-access)
WARNING: Illegal access by
org.codehaus.groovy.reflection.CachedClass$3$1
(file:/gradle-3.4.1/lib/groovy-all-2.4.7.jar) to method
java.util.ArrayList.removeRange(int,int) (permitted by
--permit-illegal-access)
WARNING: Illegal access by
org.codehaus.groovy.reflection.CachedClass$3$1
(file:/gradle-3.4.1/lib/groovy-all-2.4.7.jar) to method
java.util.ArrayList.rangeCheckForAdd(int) (permitted by
--permit-illegal-access)
WARNING: Illegal access by
org.codehaus.groovy.reflection.CachedClass$3$1
(file:/gradle-3.4.1/lib/groovy-all-2.4.7.jar) to method
java.util.ArrayList.outOfBoundsMsg(int,int) (permitted by
--permit-illegal-access)
WARNING: Illegal access by
org.codehaus.groovy.reflection.CachedClass$3$1
(file:/gradle-3.4.1/lib/groovy-all-2.4.7.jar) to method
java.util.ArrayList.outOfBoundsMsg(int) (permitted by
--permit-illegal-access)
WARNING: Illegal access by
org.codehaus.groovy.reflection.CachedClass$3$1
(file:/gradle-3.4.1/lib/groovy-all-2.4.7.jar) to method
java.util.ArrayList.elementData(int) (permitted by --permit-illegal-access)
WARNING: Illegal access by
org.codehaus.groovy.reflection.CachedClass$3$1
(file:/gradle-3.4.1/lib/groovy-all-2.4.7.jar) to method
java.util.ArrayList.grow() (permitted by --permit-illegal-access)
WARNING: Illegal access by
org.codehaus.groovy.reflection.CachedClass$3$1
(file:/gradle-3.4.1/lib/groovy-all-2.4.7.jar) to method
java.util.ArrayList.grow(int) (permitted by --permit-illegal-access)
WARNING: Illegal access by
org.codehaus.groovy.reflection.CachedClass$3$1
(file:/gradle-3.4.1/lib/groovy-all-2.4.7.jar) to method
java.util.ArrayList.nBits(int) (permitted by --permit-illegal-access)
WARNING: Illegal access by
org.codehaus.groovy.reflection.CachedClass$3$1
(file:/gradle-3.4.1/lib/groovy-all-2.4.7.jar) to method
java.util.ArrayList.setBit(long[],int) (permitted by
--permit-illegal-access)
WARNING: Illegal access by
org.codehaus.groovy.reflection.CachedClass$3$1
(file:/gradle-3.4.1/lib/groovy-all-2.4.7.jar) to method
java.util.ArrayList.isClear(long[],int) (permitted by
--permit-illegal-access)
WARNING: Illegal access by
org.codehaus.groovy.reflection.CachedClass$3$1
(file:/gradle-3.4.1/lib/groovy-all-2.4.7.jar) to method
java.util.ArrayList.shiftTailOverGap(java.lang.Object[],int,int)
(permitted by --permit-illegal-access)
WARNING: Illegal access by
org.codehaus.groovy.reflection.CachedClass$3$1
(file:/gradle-3.4.1/lib/groovy-all-2.4.7.jar) to method
java.util.ArrayList.checkInvariants() (permitted by --permit-illegal-access)
WARNING: Illegal access by
org.codehaus.groovy.reflection.CachedClass$3$1
(file:/gradle-3.4.1/lib/groovy-all-2.4.7.jar) to method
java.util.ArrayList.fastRemove(int) (permitted by --permit-illegal-access)
WARNING: Illegal access by
org.codehaus.groovy.reflection.CachedClass$3$1
(file:/gradle-3.4.1/lib/groovy-all-2.4.7.jar) to method
java.util.ArrayList.batchRemove(java.util.Collection,boolean,int,int)
(permitted by --permit-illegal-access)
WARNING: Illegal access by
org.codehaus.groovy.reflection.CachedClass$1$1
(file:/gradle-3.4.1/lib/groovy-all-2.4.7.jar) to field
java.util.AbstractCollection.MAX_ARRAY_SIZE (permitted by
--permit-illegal-access)
WARNING: Illegal access by
org.codehaus.groovy.reflection.CachedClass$1$1
(file:/gradle-3.4.1/lib/groovy-all-2.4.7.jar) to field
java.util.AbstractList.modCount (permitted by --permit-illegal-access)
WARNING: Illegal access by
org.codehaus.groovy.reflection.CachedClass$1$1
(file:/gradle-3.4.1/lib/groovy-all-2.4.7.jar) to field
java.util.ArrayList.serialVersionUID (permitted by --permit-illegal-access)
WARNING: Illegal access by
org.codehaus.groovy.reflection.CachedClass$1$1
(file:/gradle-3.4.1/lib/groovy-all-2.4.7.jar) to field
java.util.ArrayList.DEFAULT_CAPACITY (permitted by --permit-illegal-access)
WARNING: Illegal access by
org.codehaus.groovy.reflection.CachedClass$1$1
(file:/gradle-3.4.1/lib/groovy-all-2.4.7.jar) to field
java.util.ArrayList.EMPTY_ELEMENTDATA (permitted by --permit-illegal-access)
WARNING: Illegal access by
org.codehaus.groovy.reflection.CachedClass$1$1
(file:/gradle-3.4.1/lib/groovy-all-2.4.7.jar) to field
java.util.ArrayList.DEFAULTCAPACITY_EMPTY_ELEMENTDATA (permitted by
--permit-illegal-access)
WARNING: Illegal access by
org.codehaus.groovy.reflection.CachedClass$1$1
(file:/gradle-3.4.1/lib/groovy-all-2.4.7.jar) to field
java.util.ArrayList.elementData (permitted by --permit-illegal-access)
WARNING: Illegal access by
org.codehaus.groovy.reflection.CachedClass$1$1
(file:/gradle-3.4.1/lib/groovy-all-2.4.7.jar) to field
java.util.ArrayList.size (permitted by --permit-illegal-access)
WARNING: Illegal access by
org.codehaus.groovy.reflection.CachedClass$1$1
(file:/gradle-3.4.1/lib/groovy-all-2.4.7.jar) to field
java.util.ArrayList.MAX_ARRAY_SIZE (permitted by --permit-illegal-access)
:help
Welcome to Gradle 3.4.1.
To run a build, run gradle <task> ...
To see a list of available tasks, run gradle tasks
To see a list of command-line options, run gradle --help
To see more detail about a task, run gradle help --task <task>
BUILD SUCCESSFUL
Total time: 3.584 secs
>
> So it will not be on a invocation base with some kind of check if that
> has been locked already? Then I misunderstood
Once setAccessible succeeds then further use of that AccessiblecObject
does not do an access check so there won't be subsequent warnings.
> :
>
> So you tell me that if I add an add-opens to java.base for all unnamed
> modules, I will still pay a performance penalty here? on each method
> invocation or only once?
A discussion point is whether the precise options (--add-exports and
--add-opens) triggers warnings in JDK 9 or not. If they do not then
there will be no performance overhead.
-Alan
More information about the jigsaw-dev
mailing list