changeset 1495:a8b20725bcf2

8141524: CompilerTest execution time dominated by Field.setAccessible Reviewed-by: hannesw, mhaupt, sundar
author attila
date Thu, 05 Nov 2015 12:15:40 +0100
parents cc95f96b51d8
children 0c621f5166c5
files src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/ir/debug/ASTWriter.java
diffstat 1 files changed, 11 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/ir/debug/ASTWriter.java	Thu Nov 05 12:13:36 2015 +0100
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/ir/debug/ASTWriter.java	Thu Nov 05 12:15:40 2015 +0100
@@ -55,6 +55,16 @@
  * see the flags --print-ast and --print-ast-lower
  */
 public final class ASTWriter {
+    private static final ClassValue<Field[]> accessibleFields = new ClassValue<Field[]>() {
+        @Override
+        protected Field[] computeValue(final Class<?> type) {
+            final Field[] fields = type.getDeclaredFields();
+            for(final Field f: fields) {
+                f.setAccessible(true);
+            }
+            return fields;
+        }
+    };
     /** Root node from which to start the traversal */
     private final Node root;
 
@@ -258,9 +268,8 @@
 
         while (iter.hasNext()) {
             final Class<?> c = iter.next();
-            for (final Field f : c.getDeclaredFields()) {
+            for (final Field f : accessibleFields.get(c)) {
                 try {
-                    f.setAccessible(true);
                     final Object child = f.get(node);
                     if (child == null) {
                         continue;