1 /* |
1 /* |
2 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. |
7 * published by the Free Software Foundation. |
34 |
34 |
35 import static java.lang.StackWalker.Option.*; |
35 import static java.lang.StackWalker.Option.*; |
36 |
36 |
37 /** |
37 /** |
38 * @test |
38 * @test |
39 * @bug 8140450 |
39 * @bug 8140450 8197901 |
40 * @summary Verify stack trace information obtained with respect to StackWalker |
40 * @summary Verify stack trace information obtained with respect to StackWalker |
41 * options, when the stack contains lambdas, method handle invoke |
41 * options, when the stack contains lambdas, method handle invoke |
42 * virtual calls, and reflection. |
42 * virtual calls, and reflection. |
43 * @run main/othervm VerifyStackTrace |
43 * @run main/othervm VerifyStackTrace |
44 * @run main/othervm/java.security.policy=stackwalk.policy VerifyStackTrace |
44 * @run main/othervm/java.security.policy=stackwalk.policy VerifyStackTrace |
129 // is indeed correct (no frames are skipped that shouldn't) |
129 // is indeed correct (no frames are skipped that shouldn't) |
130 // then you can cut & paste the <-- actual --> stack printed in the |
130 // then you can cut & paste the <-- actual --> stack printed in the |
131 // test output in here (don't forget the final \n): |
131 // test output in here (don't forget the final \n): |
132 private final String expected = |
132 private final String expected = |
133 "1: VerifyStackTrace.lambda$test$1(VerifyStackTrace.java:213)\n" + |
133 "1: VerifyStackTrace.lambda$test$1(VerifyStackTrace.java:213)\n" + |
134 "2: VerifyStackTrace$$Lambda$1/662441761.run(Unknown Source)\n" + |
134 "2: VerifyStackTrace$$Lambda$1/0x00000007c0089430.run(Unknown Source)\n" + |
135 "3: VerifyStackTrace$Handle.execute(VerifyStackTrace.java:149)\n" + |
135 "3: VerifyStackTrace$Handle.execute(VerifyStackTrace.java:149)\n" + |
136 "4: java.base/java.lang.invoke.LambdaForm$DMH/2008017533.invokeVirtual_LL_V(LambdaForm$DMH)\n" + |
136 "4: java.base/java.lang.invoke.LambdaForm$DMH/0x00000007c008a830.invokeVirtual_LL_V(LambdaForm$DMH)\n" + |
137 "5: java.base/java.lang.invoke.LambdaForm$MH/1395089624.invoke_MT(LambdaForm$MH)\n" + |
137 "5: java.base/java.lang.invoke.LambdaForm$MH/0x00000007c008a830.invoke_MT(LambdaForm$MH)\n" + |
138 "6: VerifyStackTrace$Handle.run(VerifyStackTrace.java:162)\n" + |
138 "6: VerifyStackTrace$Handle.run(VerifyStackTrace.java:162)\n" + |
139 "7: VerifyStackTrace.invoke(VerifyStackTrace.java:192)\n" + |
139 "7: VerifyStackTrace.invoke(VerifyStackTrace.java:192)\n" + |
140 "8: java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)\n" + |
140 "8: java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)\n" + |
141 "9: java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)\n" + |
141 "9: java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)\n" + |
142 "10: java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)\n" + |
142 "10: java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)\n" + |
199 // Erase sensitive information before comparing: |
199 // Erase sensitive information before comparing: |
200 // comparing line numbers is too fragile, so we just erase them |
200 // comparing line numbers is too fragile, so we just erase them |
201 // out before comparing. We also erase the hash-like names of |
201 // out before comparing. We also erase the hash-like names of |
202 // synthetic frames introduced by lambdas & method handles |
202 // synthetic frames introduced by lambdas & method handles |
203 return produced.replaceAll(":[1-9][0-9]*\\)", ":00)") |
203 return produced.replaceAll(":[1-9][0-9]*\\)", ":00)") |
204 .replaceAll("/[0-9]+\\.run", "/xxxxxxxx.run") |
204 .replaceAll("/0x[0-9a-f]+\\.run", "/xxxxxxxx.run") |
205 .replaceAll("/[0-9]+\\.invoke", "/xxxxxxxx.invoke") |
205 .replaceAll("/0x[0-9a-f]+\\.invoke", "/xxxxxxxx.invoke") |
206 // LFs may or may not be pre-generated, making frames differ |
206 // LFs may or may not be pre-generated, making frames differ |
207 .replaceAll("DirectMethodHandle\\$Holder", "LambdaForm\\$DMH") |
207 .replaceAll("DirectMethodHandle\\$Holder", "LambdaForm\\$DMH") |
208 .replaceAll("Invokers\\$Holder", "LambdaForm\\$MH") |
208 .replaceAll("Invokers\\$Holder", "LambdaForm\\$MH") |
209 .replaceAll("MH\\.invoke", "MH/xxxxxxxx.invoke") |
209 .replaceAll("MH\\.invoke", "MH/xxxxxxxx.invoke") |
210 // invoke frames may or may not have basic method type |
210 // invoke frames may or may not have basic method type |