mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
revert: use optimized file managers in single-threaded environment only
This commit is contained in:
@@ -16,6 +16,7 @@ import java.util.*;
|
||||
*/
|
||||
public class JavacMain {
|
||||
private static final boolean IS_VM_6_VERSION = System.getProperty("java.version", "1.6").contains("1.6");
|
||||
private static final boolean ECLIPSE_COMPILER_SINGLE_THREADED_MODE = Boolean.parseBoolean(System.getProperty("jdt.compiler.useSingleThread", "false"));
|
||||
private static final Set<String> FILTERED_OPTIONS = new HashSet<String>(Arrays.<String>asList(
|
||||
"-d", "-classpath", "-cp", "-bootclasspath"
|
||||
));
|
||||
@@ -58,7 +59,8 @@ public class JavacMain {
|
||||
for (File outputDir : outputDirToRoots.keySet()) {
|
||||
outputDir.mkdirs();
|
||||
}
|
||||
final JavacFileManager fileManager = new JavacFileManager(new ContextImpl(compiler, outConsumer, outputSink, canceledStatus));
|
||||
final boolean canUseOptimizedmanager = nowUsingJavac || ECLIPSE_COMPILER_SINGLE_THREADED_MODE;
|
||||
final JavacFileManager fileManager = new JavacFileManager(new ContextImpl(compiler, outConsumer, outputSink, canceledStatus, canUseOptimizedmanager));
|
||||
|
||||
fileManager.handleOption("-bootclasspath", Collections.singleton("").iterator()); // this will clear cached stuff
|
||||
fileManager.handleOption("-extdirs", Collections.singleton("").iterator()); // this will clear cached stuff
|
||||
@@ -173,19 +175,21 @@ public class JavacMain {
|
||||
public ContextImpl(@NotNull JavaCompiler compiler,
|
||||
@NotNull DiagnosticOutputConsumer outConsumer,
|
||||
@NotNull OutputFileConsumer sink,
|
||||
CanceledStatus canceledStatus) {
|
||||
CanceledStatus canceledStatus, boolean canUseOptimizedmanager) {
|
||||
myOutConsumer = outConsumer;
|
||||
myOutputFileSink = sink;
|
||||
myCanceledStatus = canceledStatus;
|
||||
StandardJavaFileManager stdManager = null;
|
||||
final Class<StandardJavaFileManager> optimizedManagerClass = ClasspathBootstrap.getOptimizedFileManagerClass();
|
||||
if (optimizedManagerClass != null) {
|
||||
try {
|
||||
stdManager = optimizedManagerClass.newInstance();
|
||||
}
|
||||
catch (Throwable e) {
|
||||
if (SystemInfo.isWindows) {
|
||||
System.err.println("Failed to load JPS optimized file manager for javac: " + e.getMessage());
|
||||
if (canUseOptimizedmanager) {
|
||||
final Class<StandardJavaFileManager> optimizedManagerClass = ClasspathBootstrap.getOptimizedFileManagerClass();
|
||||
if (optimizedManagerClass != null) {
|
||||
try {
|
||||
stdManager = optimizedManagerClass.newInstance();
|
||||
}
|
||||
catch (Throwable e) {
|
||||
if (SystemInfo.isWindows) {
|
||||
System.err.println("Failed to load JPS optimized file manager for javac: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,8 +6,7 @@ import com.sun.tools.javac.util.*;
|
||||
import com.sun.tools.javac.util.List;
|
||||
|
||||
import javax.lang.model.SourceVersion;
|
||||
import javax.tools.FileObject;
|
||||
import javax.tools.JavaFileObject;
|
||||
import javax.tools.*;
|
||||
import java.io.*;
|
||||
import java.lang.ref.SoftReference;
|
||||
import java.lang.reflect.Field;
|
||||
@@ -17,7 +16,6 @@ import java.nio.ByteBuffer;
|
||||
import java.nio.CharBuffer;
|
||||
import java.nio.charset.*;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
/**
|
||||
@@ -29,9 +27,9 @@ import java.util.concurrent.atomic.AtomicReference;
|
||||
class OptimizedFileManager extends DefaultFileManager {
|
||||
private boolean myUseZipFileIndex;
|
||||
private final Map<File, Archive> myArchives;
|
||||
private final Map<File, Boolean> myIsFile = new ConcurrentHashMap<File, Boolean>();
|
||||
private final Map<InputFileObject, SoftReference<CharBuffer>> myContentCache = new ConcurrentHashMap<InputFileObject, SoftReference<CharBuffer>>();
|
||||
private final Map<File, File[]> myDirectoryCache = new ConcurrentHashMap<File, File[]>();
|
||||
private final Map<File, Boolean> myIsFile = new HashMap<File, Boolean>();
|
||||
private final Map<InputFileObject, SoftReference<CharBuffer>> myContentCache = new HashMap<InputFileObject, SoftReference<CharBuffer>>();
|
||||
private final Map<File, File[]> myDirectoryCache = new HashMap<File, File[]>();
|
||||
public static final File[] NULL_FILE_ARRAY = new File[0];
|
||||
|
||||
public OptimizedFileManager() throws Throwable {
|
||||
|
||||
@@ -8,7 +8,7 @@ import com.sun.tools.javac.util.List;
|
||||
import com.sun.tools.javac.util.ListBuffer;
|
||||
|
||||
import javax.lang.model.SourceVersion;
|
||||
import javax.tools.JavaFileObject;
|
||||
import javax.tools.*;
|
||||
import java.io.*;
|
||||
import java.lang.ref.Reference;
|
||||
import java.lang.ref.SoftReference;
|
||||
@@ -18,8 +18,6 @@ import java.nio.ByteBuffer;
|
||||
import java.nio.CharBuffer;
|
||||
import java.nio.charset.CharsetDecoder;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
/**
|
||||
* WARNING: Loaded via reflection, do not delete
|
||||
@@ -29,10 +27,9 @@ import java.util.concurrent.atomic.AtomicReference;
|
||||
class OptimizedFileManager17 extends com.sun.tools.javac.file.JavacFileManager {
|
||||
private boolean myUseZipFileIndex;
|
||||
private final Map<File, Archive> myArchives;
|
||||
private final Map<File, Boolean> myIsFile = new ConcurrentHashMap<File, Boolean>();
|
||||
private final Map<File, File[]> myDirectoryCache = new ConcurrentHashMap<File, File[]>();
|
||||
private final Map<File, Boolean> myIsFile = new HashMap<File, Boolean>();
|
||||
private final Map<File, File[]> myDirectoryCache = new HashMap<File, File[]>();
|
||||
public static final File[] NULL_FILE_ARRAY = new File[0];
|
||||
private final Map<JavaFileObject, SoftReference<CharBuffer>> myContentCache = new ConcurrentHashMap<JavaFileObject, SoftReference<CharBuffer>>();
|
||||
|
||||
public OptimizedFileManager17() throws Throwable {
|
||||
super(new Context(), true, null);
|
||||
@@ -199,66 +196,6 @@ class OptimizedFileManager17 extends com.sun.tools.javac.file.JavacFileManager {
|
||||
return fileKinds.contains(getKind(name));
|
||||
}
|
||||
|
||||
public CharBuffer getCachedContent(JavaFileObject file) {
|
||||
final SoftReference<CharBuffer> r = myContentCache.get(file);
|
||||
return r == null ? null : r.get();
|
||||
}
|
||||
|
||||
public void cache(JavaFileObject file, CharBuffer cb) {
|
||||
myContentCache.put(file, new SoftReference<CharBuffer>(cb));
|
||||
}
|
||||
|
||||
public void flush() {
|
||||
try {
|
||||
super.flush();
|
||||
}
|
||||
finally {
|
||||
myContentCache.clear();
|
||||
}
|
||||
}
|
||||
|
||||
public ByteBuffer makeByteBuffer(InputStream in) throws IOException {
|
||||
int limit = in.available();
|
||||
if (limit < 1024) {
|
||||
limit = 1024;
|
||||
}
|
||||
ByteBuffer result = myByteBufferCache.get(limit);
|
||||
int position = 0;
|
||||
while (in.available() != 0) {
|
||||
if (position >= limit) {
|
||||
// expand buffer
|
||||
result = ByteBuffer.allocate(limit <<= 1).put((ByteBuffer)result.flip());
|
||||
}
|
||||
final int count = in.read(result.array(), position, limit - position);
|
||||
if (count < 0) {
|
||||
break;
|
||||
}
|
||||
result.position(position += count);
|
||||
}
|
||||
return (ByteBuffer)result.flip();
|
||||
}
|
||||
|
||||
public void recycleByteBuffer(ByteBuffer bb) {
|
||||
myByteBufferCache.put(bb);
|
||||
}
|
||||
|
||||
private static class ByteBufferCache {
|
||||
private AtomicReference<ByteBuffer> myCached = new AtomicReference<ByteBuffer>(null);
|
||||
|
||||
ByteBuffer get(int capacity) {
|
||||
if (capacity < 20480) {
|
||||
capacity = 20480;
|
||||
}
|
||||
final ByteBuffer cached = myCached.getAndSet(null);
|
||||
return (cached != null && cached.capacity() >= capacity) ? (ByteBuffer)cached.clear() : ByteBuffer.allocate(capacity + capacity>>1);
|
||||
}
|
||||
|
||||
void put(ByteBuffer x) {
|
||||
myCached.set(x);
|
||||
}
|
||||
}
|
||||
private final ByteBufferCache myByteBufferCache = new ByteBufferCache();
|
||||
|
||||
private class InputFileObject extends BaseFileObject {
|
||||
private String name;
|
||||
final File file;
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user