mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 06:05:01 +07:00
switching to java.util.ConcurrentHashMap in jps code; eliminate unneeded map queries
This commit is contained in:
@@ -19,7 +19,6 @@ import com.intellij.openapi.util.Key;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.util.io.FileUtilRt;
|
||||
import com.intellij.util.SmartList;
|
||||
import com.intellij.util.containers.ConcurrentHashMap;
|
||||
import gnu.trove.THashMap;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -37,6 +36,7 @@ import org.jetbrains.jps.service.JpsServiceManager;
|
||||
import java.io.File;
|
||||
import java.io.FileFilter;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
|
||||
/**
|
||||
@@ -55,7 +55,7 @@ public class BuildRootIndexImpl implements BuildRootIndex {
|
||||
myIgnoredFileIndex = ignoredFileIndex;
|
||||
myRootsByTarget = new HashMap<BuildTarget<?>, List<? extends BuildRootDescriptor>>();
|
||||
myRootToDescriptors = new THashMap<File, List<BuildRootDescriptor>>(FileUtil.FILE_HASHING_STRATEGY);
|
||||
myFileFilters = new ConcurrentHashMap<BuildRootDescriptor, FileFilter>();
|
||||
myFileFilters = new ConcurrentHashMap<BuildRootDescriptor, FileFilter>(16, 0.75f, 1);
|
||||
final Iterable<AdditionalRootsProviderService> rootsProviders = JpsServiceManager.getInstance().getExtensions(AdditionalRootsProviderService.class);
|
||||
for (BuildTargetType<?> targetType : TargetTypeRegistry.getInstance().getTargetTypes()) {
|
||||
for (BuildTarget<?> target : targetIndex.getAllTargets(targetType)) {
|
||||
|
||||
@@ -88,6 +88,7 @@ public class IncProjectBuilder {
|
||||
maxThreads = Math.max(2, Integer.parseInt(System.getProperty(GlobalOptions.COMPILE_PARALLEL_MAX_THREADS_OPTION, Integer.toString(maxThreads))));
|
||||
}
|
||||
catch (NumberFormatException ignored) {
|
||||
maxThreads = Math.max(2, maxThreads);
|
||||
}
|
||||
MAX_BUILDER_THREADS = maxThreads;
|
||||
}
|
||||
@@ -632,9 +633,7 @@ public class IncProjectBuilder {
|
||||
}
|
||||
|
||||
private class BuildParallelizer {
|
||||
private final BoundedTaskExecutor myParallelBuildExecutor =
|
||||
new BoundedTaskExecutor(SharedThreadPool.getInstance(),
|
||||
Math.min(MAX_BUILDER_THREADS, Math.max(2, Runtime.getRuntime().availableProcessors())));
|
||||
private final BoundedTaskExecutor myParallelBuildExecutor = new BoundedTaskExecutor(SharedThreadPool.getInstance(), MAX_BUILDER_THREADS);
|
||||
private final CompileContext myContext;
|
||||
private final AtomicReference<Throwable> myException = new AtomicReference<Throwable>();
|
||||
private final Object myQueueLock = new Object();
|
||||
|
||||
+2
-2
@@ -17,7 +17,6 @@ package org.jetbrains.jps.incremental.storage;
|
||||
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.util.containers.ConcurrentHashMap;
|
||||
import com.intellij.util.io.IOUtil;
|
||||
import org.jetbrains.jps.builders.BuildTarget;
|
||||
import org.jetbrains.jps.builders.BuildTargetLoader;
|
||||
@@ -26,6 +25,7 @@ import org.jetbrains.jps.builders.BuildTargetType;
|
||||
import java.io.*;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
|
||||
/**
|
||||
@@ -43,7 +43,7 @@ public class BuildTargetTypeState {
|
||||
myTargetType = targetType;
|
||||
myTargetsState = state;
|
||||
myTargetsFile = new File(state.getDataPaths().getTargetTypeDataRoot(targetType), "targets.dat");
|
||||
myConfigurations = new ConcurrentHashMap<BuildTarget<?>, BuildTargetConfiguration>();
|
||||
myConfigurations = new ConcurrentHashMap<BuildTarget<?>, BuildTargetConfiguration>(16, 0.75f, 1);
|
||||
myTargetIds = new HashMap<BuildTarget<?>, Integer>();
|
||||
load();
|
||||
}
|
||||
|
||||
@@ -17,7 +17,6 @@ package org.jetbrains.jps.incremental.storage;
|
||||
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.util.containers.ConcurrentHashMap;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jps.builders.BuildTarget;
|
||||
import org.jetbrains.jps.builders.BuildTargetType;
|
||||
@@ -27,6 +26,7 @@ import org.jetbrains.jps.incremental.TargetTypeRegistry;
|
||||
import org.jetbrains.jps.model.JpsModel;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
@@ -37,7 +37,7 @@ public class BuildTargetsState {
|
||||
private static final Logger LOG = Logger.getInstance("#org.jetbrains.jps.incremental.storage.BuildTargetsState");
|
||||
private final BuildDataPaths myDataPaths;
|
||||
private AtomicInteger myMaxTargetId = new AtomicInteger(0);
|
||||
private ConcurrentMap<BuildTargetType<?>, BuildTargetTypeState> myTypeStates = new ConcurrentHashMap<BuildTargetType<?>, BuildTargetTypeState>();
|
||||
private ConcurrentMap<BuildTargetType<?>, BuildTargetTypeState> myTypeStates = new ConcurrentHashMap<BuildTargetType<?>, BuildTargetTypeState>(16, 0.75f, 1);
|
||||
private JpsModel myModel;
|
||||
private final BuildRootIndexImpl myBuildRootIndex;
|
||||
|
||||
@@ -99,9 +99,11 @@ public class BuildTargetsState {
|
||||
private BuildTargetTypeState getTypeState(BuildTargetType<?> type) {
|
||||
BuildTargetTypeState state = myTypeStates.get(type);
|
||||
if (state == null) {
|
||||
state = new BuildTargetTypeState(type, this);
|
||||
myTypeStates.putIfAbsent(type, state);
|
||||
state = myTypeStates.get(type);
|
||||
final BuildTargetTypeState newState = new BuildTargetTypeState(type, this);
|
||||
state = myTypeStates.putIfAbsent(type, newState);
|
||||
if (state == null) {
|
||||
state = newState;
|
||||
}
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
@@ -15,17 +15,17 @@
|
||||
*/
|
||||
package org.jetbrains.jps.service.impl;
|
||||
|
||||
import com.intellij.util.containers.ConcurrentHashMap;
|
||||
import org.jetbrains.jps.service.JpsServiceManager;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
public class JpsServiceManagerImpl extends JpsServiceManager {
|
||||
private final ConcurrentHashMap<Class, Object> myServices = new ConcurrentHashMap<Class, Object>();
|
||||
private final ConcurrentHashMap<Class, List<?>> myExtensions = new ConcurrentHashMap<Class, List<?>>();
|
||||
private final ConcurrentHashMap<Class, Object> myServices = new ConcurrentHashMap<Class, Object>(16, 0.75f, 1);
|
||||
private final ConcurrentHashMap<Class, List<?>> myExtensions = new ConcurrentHashMap<Class, List<?>>(16, 0.75f, 1);
|
||||
|
||||
@Override
|
||||
public <T> T getService(Class<T> serviceClass) {
|
||||
@@ -36,14 +36,16 @@ public class JpsServiceManagerImpl extends JpsServiceManager {
|
||||
if (!iterator.hasNext()) {
|
||||
throw new ServiceConfigurationError("Implementation for " + serviceClass + " not found");
|
||||
}
|
||||
service = iterator.next();
|
||||
final T loadedService = iterator.next();
|
||||
if (iterator.hasNext()) {
|
||||
throw new ServiceConfigurationError(
|
||||
"More than one implementation for " + serviceClass + " found: " + service.getClass() + " and " + iterator.next().getClass());
|
||||
"More than one implementation for " + serviceClass + " found: " + loadedService.getClass() + " and " + iterator.next().getClass());
|
||||
}
|
||||
myServices.putIfAbsent(serviceClass, service);
|
||||
//noinspection unchecked
|
||||
service = (T)myServices.get(serviceClass);
|
||||
service = (T)myServices.putIfAbsent(serviceClass, loadedService);
|
||||
if (service == null) {
|
||||
service = loadedService;
|
||||
}
|
||||
}
|
||||
return service;
|
||||
}
|
||||
@@ -53,12 +55,14 @@ public class JpsServiceManagerImpl extends JpsServiceManager {
|
||||
List<?> cached = myExtensions.get(extensionClass);
|
||||
if (cached == null) {
|
||||
final ServiceLoader<T> loader = ServiceLoader.load(extensionClass, extensionClass.getClassLoader());
|
||||
List<T> extensions = new ArrayList<T>();
|
||||
final List<T> extensions = new ArrayList<T>();
|
||||
for (T t : loader) {
|
||||
extensions.add(t);
|
||||
}
|
||||
myExtensions.putIfAbsent(extensionClass, extensions);
|
||||
cached = myExtensions.get(extensionClass);
|
||||
cached = myExtensions.putIfAbsent(extensionClass, extensions);
|
||||
if (cached == null) {
|
||||
cached = extensions;
|
||||
}
|
||||
}
|
||||
//noinspection unchecked
|
||||
return (List<T>)cached;
|
||||
|
||||
Reference in New Issue
Block a user