changeset 26248:9e9455565f77

8055954: Do not parallelize class installation Reviewed-by: jlaskey, sundar
author attila
date Tue, 26 Aug 2014 15:04:20 +0200
parents ec63f6d0eee4
children 5fbbd38ebc5b
files nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/Context.java
diffstat 1 files changed, 15 insertions(+), 28 deletions(-) [+]
line wrap: on
line diff
--- 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