8141524: CompilerTest execution time dominated by Field.setAccessible
authorattila
Thu, 05 Nov 2015 12:15:40 +0100
changeset 33537 2d7055bf79a8
parent 33536 3168b2a1640e
child 33538 82c57d427fa1
8141524: CompilerTest execution time dominated by Field.setAccessible Reviewed-by: hannesw, mhaupt, sundar
nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/ir/debug/ASTWriter.java
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/ir/debug/ASTWriter.java	Thu Nov 05 12:13:36 2015 +0100
+++ b/nashorn/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;