8141524: CompilerTest execution time dominated by Field.setAccessible
Reviewed-by: hannesw, mhaupt, sundar
--- 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;