Skip to content

Commit

Permalink
[Truffle] If parallel core load is off, don't load builtins in parall…
Browse files Browse the repository at this point in the history
…el either.
  • Loading branch information
chrisseaton committed Nov 27, 2016
1 parent 82d58e7 commit c78aa1e
Showing 1 changed file with 29 additions and 23 deletions.
52 changes: 29 additions & 23 deletions truffle/src/main/java/org/jruby/truffle/core/CoreLibrary.java
Expand Up @@ -783,30 +783,36 @@ public void addCoreMethods(PrimitiveManager primitiveManager) {
WeakRefPrimitiveNodesFactory.getFactories()
);

int nFactories = factories.size();
int threads = 8;
int chunk = nFactories / threads;

List<Callable<Void>> tasks = new ArrayList<>(threads);
for (int t = 0; t < threads; t++) {
final int nb = t;
tasks.add(() -> {
int start = nb * chunk;
int end = nb == threads - 1 ? nFactories : (nb + 1) * chunk;
for (int i = start; i < end; i++) {
coreMethodNodeManager.addCoreMethodNodes(factories.get(i));
}
return null;
});
}
if (context.getOptions().CORE_PARALLEL_LOAD) {
int nFactories = factories.size();
int threads = 8;
int chunk = nFactories / threads;

List<Callable<Void>> tasks = new ArrayList<>(threads);
for (int t = 0; t < threads; t++) {
final int nb = t;
tasks.add(() -> {
int start = nb * chunk;
int end = nb == threads - 1 ? nFactories : (nb + 1) * chunk;
for (int i = start; i < end; i++) {
coreMethodNodeManager.addCoreMethodNodes(factories.get(i));
}
return null;
});
}

for (Future<Void> future : ForkJoinPool.commonPool().invokeAll(tasks)) {
try {
future.get();
} catch (InterruptedException e) {
throw new JavaException(e);
} catch (ExecutionException e) {
throw new JavaException(e.getCause());
for (Future<Void> future : ForkJoinPool.commonPool().invokeAll(tasks)) {
try {
future.get();
} catch (InterruptedException e) {
throw new JavaException(e);
} catch (ExecutionException e) {
throw new JavaException(e.getCause());
}
}
} else {
for (List<? extends NodeFactory<? extends RubyNode>> factory : factories) {
coreMethodNodeManager.addCoreMethodNodes(factory);
}
}

Expand Down

0 comments on commit c78aa1e

Please sign in to comment.