< prev index next >
src/jdk.compiler/share/classes/com/sun/tools/javac/api/JavacTaskPool.java
Print this page
rev 50902 : imported patch 8206122-Use-Queue-in-place-of-ArrayList-when-need-to-remove-first-element
*** 1,7 ****
/*
! * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
--- 1,7 ----
/*
! * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
*** 25,37 ****
package com.sun.tools.javac.api;
import java.io.PrintStream;
import java.io.Writer;
import java.util.ArrayList;
import java.util.Collection;
! import java.util.Collections;
import java.util.HashMap;
import com.sun.source.tree.ClassTree;
import com.sun.source.tree.CompilationUnitTree;
import com.sun.source.util.JavacTask;
--- 25,38 ----
package com.sun.tools.javac.api;
import java.io.PrintStream;
import java.io.Writer;
+ import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Collection;
! import java.util.Deque;
import java.util.HashMap;
import com.sun.source.tree.ClassTree;
import com.sun.source.tree.CompilationUnitTree;
import com.sun.source.util.JavacTask;
*** 99,111 ****
* deletion without notice.</b>
*/
public class JavacTaskPool {
private static final JavacTool systemProvider = JavacTool.create();
private final int maxPoolSize;
! private final Map<List<String>, List<ReusableContext>> options2Contexts = new HashMap<>();
private int id;
private int statReused = 0;
private int statNew = 0;
private int statPolluted = 0;
--- 100,113 ----
* deletion without notice.</b>
*/
public class JavacTaskPool {
private static final JavacTool systemProvider = JavacTool.create();
+ private static final Deque<ReusableContext> EMPTY_DEQUE = new ArrayDeque<>(0);
private final int maxPoolSize;
! private final Map<List<String>, Deque<ReusableContext>> options2Contexts = new HashMap<>();
private int id;
private int statReused = 0;
private int statNew = 0;
private int statPolluted = 0;
*** 157,174 ****
.collect(Collectors.toCollection(ArrayList::new));
ReusableContext ctx;
synchronized (this) {
! List<ReusableContext> cached =
! options2Contexts.getOrDefault(opts, Collections.emptyList());
if (cached.isEmpty()) {
ctx = new ReusableContext(opts);
statNew++;
} else {
! ctx = cached.remove(0);
statReused++;
}
}
ctx.useCount++;
--- 159,176 ----
.collect(Collectors.toCollection(ArrayList::new));
ReusableContext ctx;
synchronized (this) {
! Deque<ReusableContext> cached =
! options2Contexts.getOrDefault(opts, EMPTY_DEQUE);
if (cached.isEmpty()) {
ctx = new ReusableContext(opts);
statNew++;
} else {
! ctx = cached.remove();
statReused++;
}
}
ctx.useCount++;
*** 198,208 ****
.findFirst()
.get();
options2Contexts.get(toRemove.arguments).remove(toRemove);
statRemoved++;
}
! options2Contexts.computeIfAbsent(ctx.arguments, x -> new ArrayList<>()).add(ctx);
ctx.timeStamp = id++;
}
}
return result;
--- 200,210 ----
.findFirst()
.get();
options2Contexts.get(toRemove.arguments).remove(toRemove);
statRemoved++;
}
! options2Contexts.computeIfAbsent(ctx.arguments, x -> new ArrayDeque<>()).add(ctx);
ctx.timeStamp = id++;
}
}
return result;
< prev index next >