8055954: Do not parallelize class installation
authorattila
Tue, 26 Aug 2014 15:04:20 +0200
changeset 26248 9e9455565f77
parent 26247 ec63f6d0eee4
child 26249 5fbbd38ebc5b
8055954: Do not parallelize class installation Reviewed-by: jlaskey, sundar
nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/Context.java
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/Context.java	Tue Aug 26 17:21:17 2014 +0530
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/Context.java	Tue Aug 26 15:04:20 2014 +0200
@@ -163,39 +163,26 @@
 
         @Override
         public void initialize(final Collection<Class<?>> classes, final Source source, final Object[] constants) {
-            // do these in parallel, this significantly reduces class installation overhead
-            // however - it still means that every thread needs a separate doPrivileged
-            final Global global = currentGlobal.get();
-            classes.parallelStream().forEach(
-                new Consumer<Class<?>>() {
+            try {
+                AccessController.doPrivileged(new PrivilegedExceptionAction<Void>() {
                     @Override
-                    public void accept(final Class<?> clazz) {
-                        // Global threadlocal may be needed by StructureLoader during in field lookup.
-                        currentGlobal.set(global);
-                        try {
-                            AccessController.doPrivileged(new PrivilegedExceptionAction<Void>() {
-                                @Override
-                                public Void run() {
-                                    try {
-                                        //use reflection to write source and constants table to installed classes
-                                        final Field sourceField = clazz.getDeclaredField(SOURCE.symbolName());
-                                        sourceField.setAccessible(true);
-                                        sourceField.set(null, source);
+                    public Void run() throws Exception {
+                        for (final Class<?> clazz : classes) {
+                            //use reflection to write source and constants table to installed classes
+                            final Field sourceField = clazz.getDeclaredField(SOURCE.symbolName());
+                            sourceField.setAccessible(true);
+                            sourceField.set(null, source);
 
-                                        final Field constantsField = clazz.getDeclaredField(CONSTANTS.symbolName());
-                                        constantsField.setAccessible(true);
-                                        constantsField.set(null, constants);
-                                    } catch (final IllegalAccessException | NoSuchFieldException e) {
-                                        throw new RuntimeException(e);
-                                    }
-                                    return null;
-                                }
-                            });
-                        } catch (final PrivilegedActionException e) {
-                            throw new RuntimeException(e);
+                            final Field constantsField = clazz.getDeclaredField(CONSTANTS.symbolName());
+                            constantsField.setAccessible(true);
+                            constantsField.set(null, constants);
                         }
+                        return null;
                     }
                 });
+            } catch (final PrivilegedActionException e) {
+                throw new RuntimeException(e);
+            }
         }
 
         @Override