The issue that turned up with JDK-8313798 (stack walking infinite loop) sem to be related to stack walking when LambdaForms are involved. I've noticed that when this JDK-8313798 timeout happenes, the debuggee always seems to have the following stack:
THREAD: main
Method java/lang/ClassLoader.defineClass0(Ljava/lang/ClassLoader;Ljava/lang/Class;Ljava/lang/String;[BIILjava/security/ProtectionDomain;ZILjava/lang/Object;)Ljava/lang/Class;@0x00000008004b4c00
Method java/lang/System$2.defineClass(Ljava/lang/ClassLoader;Ljava/lang/Class;Ljava/lang/String;[BLjava/security/ProtectionDomain;ZILjava/lang/Object;)Ljava/lang/Class;@0x000000080001c3c0
Method java/lang/invoke/MethodHandles$Lookup$ClassDefiner.defineClass(ZLjava/lang/Object;)Ljava/lang/Class;@0x0000000800220c48
Method java/lang/invoke/InnerClassLambdaMetafactory.generateInnerClass()Ljava/lang/Class;@0x000000080027c118
Method java/lang/invoke/InnerClassLambdaMetafactory.spinInnerClass()Ljava/lang/Class;@0x000000080027c0a8
Method java/lang/invoke/InnerClassLambdaMetafactory.buildCallSite()Ljava/lang/invoke/CallSite;@0x000000080027a938
Method java/lang/invoke/LambdaMetafactory.metafactory(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;@0x000000080044cdc8
Method java/lang/invoke/LambdaForm$DMH+0x00000008010a5000.invokeStatic(Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;@0x000000013360c340
Method java/lang/invoke/Invokers$Holder.invokeExact_MT(Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;@0x00000008000c3e80
Method java/lang/invoke/BootstrapMethodInvoker.invoke(Ljava/lang/Class;Ljava/lang/invoke/MethodHandle;Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Class;)Ljava/lang/Object;@0x0000000800187638
newSP(0x0000000122808220) is not above oldSP(0x000000016db520f0)
Error occurred during stack walking:
java.lang.RuntimeException: newSP(0x0000000122808220) is not above oldSP(0x000000016db520f0)
There are also other exceptions being thrown with similar stack traces (they didn't cause the JDK-8313798 timeout because an exception was thrown instead of getting in an infinite loop):
THREAD: main
Method java/lang/ClassLoader.defineClass0(Ljava/lang/ClassLoader;Ljava/lang/Class;Ljava/lang/String;[BIILjava/security/ProtectionDomain;ZILjava/lang/Object;)Ljava/lang/Class;@0x00000070004b4c00
Method java/lang/System$2.defineClass(Ljava/lang/ClassLoader;Ljava/lang/Class;Ljava/lang/String;[BLjava/security/ProtectionDomain;ZILjava/lang/Object;)Ljava/lang/Class;@0x000000700001c3c0
Method java/lang/invoke/MethodHandles$Lookup$ClassDefiner.defineClass(ZLjava/lang/Object;)Ljava/lang/Class;@0x0000007000220c48
Method java/lang/invoke/InnerClassLambdaMetafactory.generateInnerClass()Ljava/lang/Class;@0x000000700027c118
Method java/lang/invoke/InnerClassLambdaMetafactory.spinInnerClass()Ljava/lang/Class;@0x000000700027c0a8
Method java/lang/invoke/InnerClassLambdaMetafactory.buildCallSite()Ljava/lang/invoke/CallSite;@0x000000700027a938
Method java/lang/invoke/LambdaMetafactory.metafactory(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;@0x000000700044cdc8
Method java/lang/invoke/LambdaForm$DMH+0x00000070010a5000.invokeStatic(Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;@0x000000012760c340
Error occurred during stack walking:
java.lang.NullPointerException: Cannot invoke "sun.jvm.hotspot.debugger.Address.addOffsetTo(long)" because the return value of "sun.jvm.hotspot.runtime.Frame.getFP()" is null
THREAD: main
Method java/lang/ClassLoader.defineClass0(Ljava/lang/ClassLoader;Ljava/lang/Class;Ljava/lang/String;[BIILjava/security/ProtectionDomain;ZILjava/lang/Object;)Ljava/lang/Class;@0x00000004004b4c00
Method java/lang/System$2.defineClass(Ljava/lang/ClassLoader;Ljava/lang/Class;Ljava/lang/String;[BLjava/security/ProtectionDomain;ZILjava/lang/Object;)Ljava/lang/Class;@0x000000040001c3c0
Method java/lang/invoke/MethodHandles$Lookup$ClassDefiner.defineClass(ZLjava/lang/Object;)Ljava/lang/Class;@0x0000000400220c48
Method java/lang/invoke/InnerClassLambdaMetafactory.generateInnerClass()Ljava/lang/Class;@0x000000040027c118
Method java/lang/invoke/InnerClassLambdaMetafactory.spinInnerClass()Ljava/lang/Class;@0x000000040027c0a8
Method java/lang/invoke/InnerClassLambdaMetafactory.buildCallSite()Ljava/lang/invoke/CallSite;@0x000000040027a938
Method java/lang/invoke/LambdaMetafactory.metafactory(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;@0x000000040044cdc8
Method java/lang/invoke/LambdaForm$DMH+0x00000004010a1000.invokeStatic(Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;@0x000000012860c340
Method java/lang/invoke/Invokers$Holder.invokeExact_MT(Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;@0x00000004000c3e80
Error occurred during stack walking:
sun.jvm.hotspot.debugger.UnalignedAddressException: Trying to read at address: 0x00000068e109ce09 with alignment: 8
Note the test passes whenever an exception is thrown, because the test knows that SA can't handle generating a stack trace in certain situations (while in the middle of a frame push for example). However, the fact that these failures all seem to be happening while invoking LamdaForms is suspicious. This could be related to JDK-8276210 which noted issues when the debuggee stack looked like the following:
- jdk.internal.misc.Unsafe.allocateInstance(java.lang.Class) @bci=0 (Compiled frame; information may be imprecise)
- java.lang.invoke.DirectMethodHandle.allocateInstance(java.lang.Object) @bci=12, line=492 (Compiled frame)
- java.lang.invoke.DirectMethodHandle$Holder.newInvokeSpecial(java.lang.Object, java.lang.Object) @bci=1 (Compiled frame)
- java.lang.invoke.Invokers$Holder.linkToTargetMethod(java.lang.Object, java.lang.Object) @bci=5 (Compiled frame)
Note, usually stack walking issues with an active thread are with the topmost frame (the first frame that is visited), because it might be in an inconsistent state (not fully pushed or popped). If the state of the first frame is valid, then walking the rest of the stack should have no issues. But in all the above cases we eventually run into an issue with a frame higher up the stack, so this suggests that the stack walking code is broken in certain situations. Basically there is a frame somewhere in the middle of the stack that the stack walking code doesn't know how to get past. This seems to be unique to aarch64.