13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25 package java.lang;
26
27 import jdk.internal.reflect.MethodAccessor;
28 import java.lang.StackWalker.Option;
29 import java.lang.StackWalker.StackFrame;
30
31 import java.lang.annotation.Native;
32 import java.lang.reflect.Method;
33 import java.security.AccessController;
34 import java.security.PrivilegedAction;
35 import java.util.HashSet;
36 import java.util.NoSuchElementException;
37 import java.util.Objects;
38 import java.util.Set;
39 import java.util.Spliterator;
40 import java.util.function.Consumer;
41 import java.util.function.Function;
42 import java.util.stream.Stream;
43 import java.util.stream.StreamSupport;
44
45 import static java.lang.StackStreamFactory.WalkerState.*;
46
47 /**
48 * StackStreamFactory class provides static factory methods
49 * to get different kinds of stack walker/traverser.
50 *
51 * AbstractStackWalker provides the basic stack walking support
52 * fetching stack frames from VM in batches.
53 *
54 * AbstractStackWalker subclass is specialized for a specific kind of stack traversal
55 * to avoid overhead of Stream/Lambda
56 * 1. Support traversing Stream<StackFrame>
57 * 2. StackWalker::getCallerClass
58 * 3. AccessControlContext getting ProtectionDomain
59 */
60 final class StackStreamFactory {
61 private StackStreamFactory() {}
62
63 // Stack walk implementation classes to be excluded during stack walking
973 }
974
975 // MethodHandle frames are not hidden and CallerClassFinder has
976 // to filter them out
977 private static boolean isMethodHandleFrame(Class<?> c) {
978 return c.getName().startsWith("java.lang.invoke.");
979 }
980
981 private static boolean isReflectionFrame(Class<?> c) {
982 if (c.getName().startsWith("jdk.internal.reflect") &&
983 !MethodAccessor.class.isAssignableFrom(c)) {
984 throw new InternalError("Not jdk.internal.reflect.MethodAccessor: " + c.toString());
985 }
986 // ## should filter all @Hidden frames?
987 return c == Method.class ||
988 MethodAccessor.class.isAssignableFrom(c) ||
989 c.getName().startsWith("java.lang.invoke.LambdaForm");
990 }
991
992 private static boolean getProperty(String key, boolean value) {
993 String s = AccessController.doPrivileged(new PrivilegedAction<>() {
994 @Override
995 public String run() {
996 return System.getProperty(key);
997 }
998 });
999 if (s != null) {
1000 return Boolean.valueOf(s);
1001 }
1002 return value;
1003 }
1004 }
|
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25 package java.lang;
26
27 import jdk.internal.reflect.MethodAccessor;
28 import java.lang.StackWalker.Option;
29 import java.lang.StackWalker.StackFrame;
30
31 import java.lang.annotation.Native;
32 import java.lang.reflect.Method;
33 import java.util.HashSet;
34 import java.util.NoSuchElementException;
35 import java.util.Objects;
36 import java.util.Set;
37 import java.util.Spliterator;
38 import java.util.function.Consumer;
39 import java.util.function.Function;
40 import java.util.stream.Stream;
41 import java.util.stream.StreamSupport;
42 import sun.security.action.GetPropertyAction;
43
44 import static java.lang.StackStreamFactory.WalkerState.*;
45
46 /**
47 * StackStreamFactory class provides static factory methods
48 * to get different kinds of stack walker/traverser.
49 *
50 * AbstractStackWalker provides the basic stack walking support
51 * fetching stack frames from VM in batches.
52 *
53 * AbstractStackWalker subclass is specialized for a specific kind of stack traversal
54 * to avoid overhead of Stream/Lambda
55 * 1. Support traversing Stream<StackFrame>
56 * 2. StackWalker::getCallerClass
57 * 3. AccessControlContext getting ProtectionDomain
58 */
59 final class StackStreamFactory {
60 private StackStreamFactory() {}
61
62 // Stack walk implementation classes to be excluded during stack walking
972 }
973
974 // MethodHandle frames are not hidden and CallerClassFinder has
975 // to filter them out
976 private static boolean isMethodHandleFrame(Class<?> c) {
977 return c.getName().startsWith("java.lang.invoke.");
978 }
979
980 private static boolean isReflectionFrame(Class<?> c) {
981 if (c.getName().startsWith("jdk.internal.reflect") &&
982 !MethodAccessor.class.isAssignableFrom(c)) {
983 throw new InternalError("Not jdk.internal.reflect.MethodAccessor: " + c.toString());
984 }
985 // ## should filter all @Hidden frames?
986 return c == Method.class ||
987 MethodAccessor.class.isAssignableFrom(c) ||
988 c.getName().startsWith("java.lang.invoke.LambdaForm");
989 }
990
991 private static boolean getProperty(String key, boolean value) {
992 String s = GetPropertyAction.getProperty(key);
993 if (s != null) {
994 return Boolean.parseBoolean(s);
995 }
996 return value;
997 }
998 }
|