Dear all,
please review this change.
Bug: https://bugs.openjdk.java.net/browse/JDK-8131129
Webrev: http://cr.openjdk.java.net/~mhaupt/8131129/webrev.00/
Thanks to Peter Levart, who has contributed the actual code to fix the issue.
The background of this is as follows. Bug 8131129 is an intermittent failure in
a multi-threaded test for LambdaForm caching. The failure was not reproducible
but used to occur on various platforms every now and then. I was able to dig up
some stack traces that reveal the real cause in internal test logs. These
traces finally confirmed a suspicion that both Peter and I had had but could,
for lack of complete failure information, not pin down as the cause of the
issue. (Most traces from failures of the test were only partial, as the test
harness is selective about traces it logs.)
At the heart of the problem is an overflowing code cache for adapters in the
VM. The test, dynamically generating considerable amounts of LambdaForm and
BoundMethodHandle species classes, would eventually trigger this overflow. The
place at which the problem would surface is this, in
BoundMethodHandle.Factory.generateConcreteBMHClass():
Class<? extends BoundMethodHandle> bmhClass =
//UNSAFE.defineAnonymousClass(BoundMethodHandle.class, classFile,
null).asSubclass(BoundMethodHandle.class);
UNSAFE.defineClass(className, classFile, 0, classFile.length,
BoundMethodHandle.class.getClassLoader(), null)
.asSubclass(BoundMethodHandle.class);
UNSAFE.ensureClassInitialized(bmhClass);
The test would generate a BMH species with a given type signature via
defineClass and immediately thereafter force initialisation of that class, in
the course of which a SpeciesData instance is supposed to be created and
entered in the BMH species cache. In case the VM's adapter code cache
overflowed during this operation, the BMH species' class initialiser would not
finish its execution properly, leading to a stale placeholder entry left behind
in the cache. The presence of this very placeholder would trick the next
request for a BMH species with the same type signature into believing the class
needed to be defined, leading to the observed failure.
An exemplary stack trace is appended below.
Both Peter and I had come up with solutions, but I think Peter's is better as
it gets rid of the somewhat intricate and semi-hidden cache registration call
made from generated code. With Peter's fix, it's all visible in library code
now.
Thanks,
Michael
-----
java.lang.InternalError: java.lang.NoSuchMethodException: no such method:
java.lang.invoke.MethodHandle.linkToStatic(Object,Object,int,Object,Object,Object,Object,Object,Object,Object,MemberName)Object/invokeStatic
at
java.lang.invoke.MethodHandleStatics.newInternalError(MethodHandleStatics.java:120)
at
java.lang.invoke.DirectMethodHandle.makePreparedLambdaForm(DirectMethodHandle.java:214)
at
java.lang.invoke.DirectMethodHandle.preparedLambdaForm(DirectMethodHandle.java:188)
at
java.lang.invoke.DirectMethodHandle.preparedLambdaForm(DirectMethodHandle.java:177)
at java.lang.invoke.DirectMethodHandle.make(DirectMethodHandle.java:84)
at
java.lang.invoke.MethodHandles$Lookup.getDirectMethodCommon(MethodHandles.java:1655)
at
java.lang.invoke.MethodHandles$Lookup.getDirectMethod(MethodHandles.java:1600)
at
java.lang.invoke.MethodHandles$Lookup.findStatic(MethodHandles.java:777)
at
java.lang.invoke.BoundMethodHandle$Factory.makeCbmhCtor(BoundMethodHandle.java:817)
at
java.lang.invoke.BoundMethodHandle$Factory.makeCtors(BoundMethodHandle.java:772)
at
java.lang.invoke.BoundMethodHandle$SpeciesData.<init>(BoundMethodHandle.java:347)
at
java.lang.invoke.BoundMethodHandle$SpeciesData.getForClass(BoundMethodHandle.java:411)
at java.lang.invoke.BoundMethodHandle$Species_IL7.<clinit>(Species_IL7)
at sun.misc.Unsafe.ensureClassInitialized(Native Method)
at
java.lang.invoke.BoundMethodHandle$Factory.generateConcreteBMHClass(BoundMethodHandle.java:718)
at
java.lang.invoke.BoundMethodHandle$SpeciesData.get(BoundMethodHandle.java:401)
at
java.lang.invoke.BoundMethodHandle$SpeciesData.extendWith(BoundMethodHandle.java:388)
at
java.lang.invoke.LambdaFormEditor.newSpeciesData(LambdaFormEditor.java:363)
at
java.lang.invoke.LambdaFormEditor.makeArgumentCombinationForm(LambdaFormEditor.java:631)
at
java.lang.invoke.LambdaFormEditor.filterArgumentForm(LambdaFormEditor.java:612)
at
java.lang.invoke.MethodHandles.filterArgument(MethodHandles.java:2667)
at
java.lang.invoke.MethodHandles.filterArguments(MethodHandles.java:2654)
at TestMethods$4.getMH(TestMethods.java:180)
at TestMethods.getTestCaseMH(TestMethods.java:548)
at
LFMultiThreadCachingTest.lambda$doTest$0(LFMultiThreadCachingTest.java:80)
at LFMultiThreadCachingTest$$Lambda$5/21979926.run(Unknown Source)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.NoSuchMethodException: no such method:
java.lang.invoke.MethodHandle.linkToStatic(Object,Object,int,Object,Object,Object,Object,Object,Object,Object,MemberName)Object/invokeStatic
at java.lang.invoke.MemberName.makeAccessException(MemberName.java:873)
at
java.lang.invoke.MemberName$Factory.resolveOrFail(MemberName.java:990)
at
java.lang.invoke.DirectMethodHandle.makePreparedLambdaForm(DirectMethodHandle.java:212)
... 25 more
Caused by: java.lang.NoSuchMethodError:
java.lang.invoke.MethodHandle.linkToStatic(Ljava/lang/Object;Ljava/lang/Object;ILjava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/invoke/MemberName;)Ljava/lang/Object;
at java.lang.invoke.MethodHandleNatives.resolve(Native Method)
at java.lang.invoke.MemberName$Factory.resolve(MemberName.java:962)
at
java.lang.invoke.MemberName$Factory.resolveOrFail(MemberName.java:987)
... 26 more
Caused by: java.lang.VirtualMachineError: out of space in CodeCache for method
handle intrinsic
... 29 more
java.lang.LinkageError: loader (instance of <bootloader>): attempted duplicate class
definition for name: "java/lang/invoke/BoundMethodHandle$Species_IL7"
at sun.misc.Unsafe.defineClass(Native Method)
at
java.lang.invoke.BoundMethodHandle$Factory.generateConcreteBMHClass(BoundMethodHandle.java:715)
at
java.lang.invoke.BoundMethodHandle$SpeciesData.get(BoundMethodHandle.java:401)
at
java.lang.invoke.BoundMethodHandle$SpeciesData.extendWith(BoundMethodHandle.java:388)
at
java.lang.invoke.LambdaFormEditor.newSpeciesData(LambdaFormEditor.java:363)
at
java.lang.invoke.LambdaFormEditor.makeArgumentCombinationForm(LambdaFormEditor.java:631)
at
java.lang.invoke.LambdaFormEditor.filterArgumentForm(LambdaFormEditor.java:612)
at
java.lang.invoke.MethodHandles.filterArgument(MethodHandles.java:2667)
at
java.lang.invoke.MethodHandles.filterArguments(MethodHandles.java:2654)
at TestMethods$4.getMH(TestMethods.java:180)
at TestMethods.getTestCaseMH(TestMethods.java:548)
at
LFMultiThreadCachingTest.lambda$doTest$0(LFMultiThreadCachingTest.java:80)
at LFMultiThreadCachingTest$$Lambda$5/21979926.run(Unknown Source)
at java.lang.Thread.run(Thread.java:745)
java.lang.LinkageError: loader (instance of <bootloader>): attempted duplicate class
definition for name: "java/lang/invoke/BoundMethodHandle$Species_IL7"
at sun.misc.Unsafe.defineClass(Native Method)
at
java.lang.invoke.BoundMethodHandle$Factory.generateConcreteBMHClass(BoundMethodHandle.java:715)
at
java.lang.invoke.BoundMethodHandle$SpeciesData.get(BoundMethodHandle.java:401)
at
java.lang.invoke.BoundMethodHandle$SpeciesData.extendWith(BoundMethodHandle.java:388)
at
java.lang.invoke.LambdaFormEditor.newSpeciesData(LambdaFormEditor.java:363)
at
java.lang.invoke.LambdaFormEditor.makeArgumentCombinationForm(LambdaFormEditor.java:631)
at
java.lang.invoke.LambdaFormEditor.filterArgumentForm(LambdaFormEditor.java:612)
at
java.lang.invoke.MethodHandles.filterArgument(MethodHandles.java:2667)
at
java.lang.invoke.MethodHandles.filterArguments(MethodHandles.java:2654)
at TestMethods$4.getMH(TestMethods.java:180)
at TestMethods.getTestCaseMH(TestMethods.java:548)
at
LFMultiThreadCachingTest.lambda$doTest$0(LFMultiThreadCachingTest.java:80)
at LFMultiThreadCachingTest$$Lambda$5/21979926.run(Unknown Source)
at java.lang.Thread.run(Thread.java:745)
STATUS:Failed.STATUS:Failed.STATUS:Failed.`main' threw exception: java.lang.LinkageError:
loader (instance of <bootloader>): attempted duplicate class definition for name:
"java/lang/invoke/BoundMethodHandle$Species_IL7"
`main' threw exception: java.lang.LinkageError: loader (instance of <bootloader>):
attempted duplicate class definition for name:
"java/lang/invoke/BoundMethodHandle$Species_IL7"
`main' threw exception: java.lang.InternalError:
java.lang.NoSuchMethodException: no such method:
java.lang.invoke.MethodHandle.linkToStatic(Object,Object,int,Object,Object,Object,Object,Object,Object,Object,MemberName)Object/invokeStatic
java.lang.LinkageError: loader (instance of <bootloader>): attempted duplicate class
definition for name: "java/lang/invoke/BoundMethodHandle$Species_IL7"
at sun.misc.Unsafe.defineClass(Native Method)
at
java.lang.invoke.BoundMethodHandle$Factory.generateConcreteBMHClass(BoundMethodHandle.java:715)
at
java.lang.invoke.BoundMethodHandle$SpeciesData.get(BoundMethodHandle.java:401)
-----