Search in sources :

Example 16 with TIntObjectHashMap

use of gnu.trove.TIntObjectHashMap in project intellij-community by JetBrains.

the class IncArtifactBuilder method build.

@Override
public void build(@NotNull ArtifactBuildTarget target, @NotNull DirtyFilesHolder<ArtifactRootDescriptor, ArtifactBuildTarget> holder, @NotNull BuildOutputConsumer outputConsumer, @NotNull final CompileContext context) throws ProjectBuildException {
    JpsArtifact artifact = target.getArtifact();
    String outputFilePath = artifact.getOutputFilePath();
    if (StringUtil.isEmpty(outputFilePath)) {
        context.processMessage(new CompilerMessage(BUILDER_NAME, BuildMessage.Kind.ERROR, "Cannot build '" + artifact.getName() + "' artifact: output path is not specified"));
        return;
    }
    final ProjectDescriptor pd = context.getProjectDescriptor();
    final ArtifactSorter sorter = new ArtifactSorter(pd.getModel());
    final Map<JpsArtifact, JpsArtifact> selfIncludingNameMap = sorter.getArtifactToSelfIncludingNameMap();
    final JpsArtifact selfIncluding = selfIncludingNameMap.get(artifact);
    if (selfIncluding != null) {
        String name = selfIncluding.equals(artifact) ? "it" : "'" + selfIncluding.getName() + "' artifact";
        context.processMessage(new CompilerMessage(BUILDER_NAME, BuildMessage.Kind.ERROR, "Cannot build '" + artifact.getName() + "' artifact: " + name + " includes itself in the output layout"));
        return;
    }
    try {
        final Collection<String> deletedFiles = holder.getRemovedFiles(target);
        String messageText = "Building artifact '" + artifact.getName() + "'...";
        context.processMessage(new ProgressMessage(messageText));
        LOG.debug(messageText);
        runArtifactTasks(context, target.getArtifact(), ArtifactBuildTaskProvider.ArtifactBuildPhase.PRE_PROCESSING);
        final SourceToOutputMapping srcOutMapping = pd.dataManager.getSourceToOutputMap(target);
        final ArtifactOutputToSourceMapping outSrcMapping = pd.dataManager.getStorage(target, ArtifactOutToSourceStorageProvider.INSTANCE);
        final TIntObjectHashMap<Set<String>> filesToProcess = new TIntObjectHashMap<>();
        final MultiMap<String, String> filesToDelete = new MultiMap<>();
        final Set<String> deletedOutputPaths = new THashSet<>(FileUtil.PATH_HASHING_STRATEGY);
        for (String sourcePath : deletedFiles) {
            final Collection<String> outputPaths = srcOutMapping.getOutputs(sourcePath);
            if (outputPaths != null) {
                for (String outputPath : outputPaths) {
                    if (deletedOutputPaths.add(outputPath)) {
                        collectSourcesCorrespondingToOutput(outputPath, sourcePath, deletedFiles, outSrcMapping, filesToProcess, filesToDelete);
                    }
                }
            }
        }
        final Set<String> changedOutputPaths = new THashSet<>(FileUtil.PATH_HASHING_STRATEGY);
        holder.processDirtyFiles(new FileProcessor<ArtifactRootDescriptor, ArtifactBuildTarget>() {

            @Override
            public boolean apply(ArtifactBuildTarget target, File file, ArtifactRootDescriptor root) throws IOException {
                int rootIndex = root.getRootIndex();
                String sourcePath = FileUtil.toSystemIndependentName(file.getPath());
                addFileToProcess(filesToProcess, rootIndex, sourcePath, deletedFiles);
                final Collection<String> outputPaths = srcOutMapping.getOutputs(sourcePath);
                if (outputPaths != null) {
                    for (String outputPath : outputPaths) {
                        if (changedOutputPaths.add(outputPath)) {
                            collectSourcesCorrespondingToOutput(outputPath, sourcePath, deletedFiles, outSrcMapping, filesToProcess, filesToDelete);
                        }
                    }
                }
                return true;
            }
        });
        BuildOperations.cleanOutputsCorrespondingToChangedFiles(context, holder);
        for (String outputPath : changedOutputPaths) {
            outSrcMapping.remove(outputPath);
        }
        if (filesToDelete.isEmpty() && filesToProcess.isEmpty()) {
            return;
        }
        deleteOutdatedFiles(filesToDelete, context, srcOutMapping, outSrcMapping);
        context.checkCanceled();
        context.processMessage(new ProgressMessage("Building artifact '" + artifact.getName() + "': copying files..."));
        final Set<JarInfo> changedJars = new THashSet<>();
        for (ArtifactRootDescriptor descriptor : pd.getBuildRootIndex().getTargetRoots(target, context)) {
            context.checkCanceled();
            final Set<String> sourcePaths = filesToProcess.get(descriptor.getRootIndex());
            if (sourcePaths == null)
                continue;
            for (String sourcePath : sourcePaths) {
                if (!descriptor.getFilter().shouldBeCopied(sourcePath, pd)) {
                    if (LOG.isDebugEnabled()) {
                        LOG.debug("File " + sourcePath + " will be skipped because it isn't accepted by filter");
                    }
                    continue;
                }
                DestinationInfo destination = descriptor.getDestinationInfo();
                if (destination instanceof ExplodedDestinationInfo) {
                    descriptor.copyFromRoot(sourcePath, descriptor.getRootIndex(), destination.getOutputPath(), context, outputConsumer, outSrcMapping);
                } else {
                    List<ArtifactOutputToSourceMapping.SourcePathAndRootIndex> sources = outSrcMapping.getState(destination.getOutputFilePath());
                    if (sources == null || sources.size() > 0 && sources.get(0).getRootIndex() == descriptor.getRootIndex()) {
                        outSrcMapping.update(destination.getOutputFilePath(), Collections.<ArtifactOutputToSourceMapping.SourcePathAndRootIndex>emptyList());
                        changedJars.add(((JarDestinationInfo) destination).getJarInfo());
                    }
                }
            }
        }
        context.checkCanceled();
        JarsBuilder builder = new JarsBuilder(changedJars, context, outputConsumer, outSrcMapping);
        builder.buildJars();
        runArtifactTasks(context, artifact, ArtifactBuildTaskProvider.ArtifactBuildPhase.FINISHING_BUILD);
        runArtifactTasks(context, artifact, ArtifactBuildTaskProvider.ArtifactBuildPhase.POST_PROCESSING);
    } catch (IOException e) {
        throw new ProjectBuildException(e);
    }
}
Also used : ProgressMessage(org.jetbrains.jps.incremental.messages.ProgressMessage) SourceToOutputMapping(org.jetbrains.jps.builders.storage.SourceToOutputMapping) CompilerMessage(org.jetbrains.jps.incremental.messages.CompilerMessage) THashSet(gnu.trove.THashSet) MultiMap(com.intellij.util.containers.MultiMap) ArtifactSorter(org.jetbrains.jps.incremental.artifacts.impl.ArtifactSorter) JpsArtifact(org.jetbrains.jps.model.artifact.JpsArtifact) IOException(java.io.IOException) THashSet(gnu.trove.THashSet) JarsBuilder(org.jetbrains.jps.incremental.artifacts.impl.JarsBuilder) ProjectDescriptor(org.jetbrains.jps.cmdline.ProjectDescriptor) TIntObjectHashMap(gnu.trove.TIntObjectHashMap) File(java.io.File)

Example 17 with TIntObjectHashMap

use of gnu.trove.TIntObjectHashMap in project intellij-community by JetBrains.

the class ThreadDumpAction method buildThreadStates.

static List<ThreadState> buildThreadStates(VirtualMachineProxyImpl vmProxy) {
    final List<ThreadReference> threads = vmProxy.getVirtualMachine().allThreads();
    final List<ThreadState> result = new ArrayList<>();
    final Map<String, ThreadState> nameToThreadMap = new HashMap<>();
    // key 'waits_for' value
    final Map<String, String> waitingMap = new HashMap<>();
    for (ThreadReference threadReference : threads) {
        final StringBuilder buffer = new StringBuilder();
        boolean hasEmptyStack = true;
        final int threadStatus = threadReference.status();
        if (threadStatus == ThreadReference.THREAD_STATUS_ZOMBIE) {
            continue;
        }
        final String threadName = threadName(threadReference);
        final ThreadState threadState = new ThreadState(threadName, threadStatusToState(threadStatus));
        nameToThreadMap.put(threadName, threadState);
        result.add(threadState);
        threadState.setJavaThreadState(threadStatusToJavaThreadState(threadStatus));
        buffer.append("\"").append(threadName).append("\"");
        ReferenceType referenceType = threadReference.referenceType();
        if (referenceType != null) {
            //noinspection HardCodedStringLiteral
            Field daemon = referenceType.fieldByName("daemon");
            if (daemon != null) {
                Value value = threadReference.getValue(daemon);
                if (value instanceof BooleanValue && ((BooleanValue) value).booleanValue()) {
                    buffer.append(" ").append(DebuggerBundle.message("threads.export.attribute.label.daemon"));
                    threadState.setDaemon(true);
                }
            }
            //noinspection HardCodedStringLiteral
            Field priority = referenceType.fieldByName("priority");
            if (priority != null) {
                Value value = threadReference.getValue(priority);
                if (value instanceof IntegerValue) {
                    buffer.append(" ").append(DebuggerBundle.message("threads.export.attribute.label.priority", ((IntegerValue) value).intValue()));
                }
            }
            Field tid = referenceType.fieldByName("tid");
            if (tid != null) {
                Value value = threadReference.getValue(tid);
                if (value instanceof LongValue) {
                    buffer.append(" ").append(DebuggerBundle.message("threads.export.attribute.label.tid", Long.toHexString(((LongValue) value).longValue())));
                    buffer.append(" nid=NA");
                }
            }
        }
        //ThreadGroupReference groupReference = threadReference.threadGroup();
        //if (groupReference != null) {
        //  buffer.append(", ").append(DebuggerBundle.message("threads.export.attribute.label.group", groupReference.name()));
        //}
        final String state = threadState.getState();
        if (state != null) {
            buffer.append(" ").append(state);
        }
        buffer.append("\n  java.lang.Thread.State: ").append(threadState.getJavaThreadState());
        try {
            if (vmProxy.canGetOwnedMonitorInfo() && vmProxy.canGetMonitorInfo()) {
                List<ObjectReference> list = threadReference.ownedMonitors();
                for (ObjectReference reference : list) {
                    if (!vmProxy.canGetMonitorFrameInfo()) {
                        // java 5 and earlier
                        buffer.append("\n\t ").append(renderLockedObject(reference));
                    }
                    final List<ThreadReference> waiting = reference.waitingThreads();
                    for (ThreadReference thread : waiting) {
                        final String waitingThreadName = threadName(thread);
                        waitingMap.put(waitingThreadName, threadName);
                        buffer.append("\n\t ").append(DebuggerBundle.message("threads.export.attribute.label.blocks.thread", waitingThreadName));
                    }
                }
            }
            ObjectReference waitedMonitor = vmProxy.canGetCurrentContendedMonitor() ? threadReference.currentContendedMonitor() : null;
            if (waitedMonitor != null) {
                if (vmProxy.canGetMonitorInfo()) {
                    ThreadReference waitedMonitorOwner = waitedMonitor.owningThread();
                    if (waitedMonitorOwner != null) {
                        final String monitorOwningThreadName = threadName(waitedMonitorOwner);
                        waitingMap.put(threadName, monitorOwningThreadName);
                        buffer.append("\n\t ").append(DebuggerBundle.message("threads.export.attribute.label.waiting.for.thread", monitorOwningThreadName, renderObject(waitedMonitor)));
                    }
                }
            }
            final List<StackFrame> frames = threadReference.frames();
            hasEmptyStack = frames.size() == 0;
            final TIntObjectHashMap<List<ObjectReference>> lockedAt = new TIntObjectHashMap<>();
            if (vmProxy.canGetMonitorFrameInfo()) {
                for (MonitorInfo info : threadReference.ownedMonitorsAndFrames()) {
                    final int stackDepth = info.stackDepth();
                    List<ObjectReference> monitors;
                    if ((monitors = lockedAt.get(stackDepth)) == null) {
                        lockedAt.put(stackDepth, monitors = new SmartList<>());
                    }
                    monitors.add(info.monitor());
                }
            }
            for (int i = 0, framesSize = frames.size(); i < framesSize; i++) {
                final StackFrame stackFrame = frames.get(i);
                try {
                    final Location location = stackFrame.location();
                    buffer.append("\n\t  ").append(renderLocation(location));
                    final List<ObjectReference> monitors = lockedAt.get(i);
                    if (monitors != null) {
                        for (ObjectReference monitor : monitors) {
                            buffer.append("\n\t  - ").append(renderLockedObject(monitor));
                        }
                    }
                } catch (InvalidStackFrameException e) {
                    buffer.append("\n\t  Invalid stack frame: ").append(e.getMessage());
                }
            }
        } catch (IncompatibleThreadStateException e) {
            buffer.append("\n\t ").append(DebuggerBundle.message("threads.export.attribute.error.incompatible.state"));
        }
        threadState.setStackTrace(buffer.toString(), hasEmptyStack);
        ThreadDumpParser.inferThreadStateDetail(threadState);
    }
    for (String waiting : waitingMap.keySet()) {
        final ThreadState waitingThread = nameToThreadMap.get(waiting);
        final ThreadState awaitedThread = nameToThreadMap.get(waitingMap.get(waiting));
        if (waitingThread != null && awaitedThread != null) {
            //zombie
            awaitedThread.addWaitingThread(waitingThread);
        }
    }
    // detect simple deadlocks
    for (ThreadState thread : result) {
        for (ThreadState awaitingThread : thread.getAwaitingThreads()) {
            if (awaitingThread.isAwaitedBy(thread)) {
                thread.addDeadlockedThread(awaitingThread);
                awaitingThread.addDeadlockedThread(thread);
            }
        }
    }
    ThreadDumpParser.sortThreads(result);
    return result;
}
Also used : HashMap(java.util.HashMap) TIntObjectHashMap(gnu.trove.TIntObjectHashMap) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) SmartList(com.intellij.util.SmartList) ThreadState(com.intellij.unscramble.ThreadState) TIntObjectHashMap(gnu.trove.TIntObjectHashMap) SmartList(com.intellij.util.SmartList)

Example 18 with TIntObjectHashMap

use of gnu.trove.TIntObjectHashMap in project intellij-community by JetBrains.

the class SourceLineCounterUtil method collectSrcLinesForUntouchedFiles.

public static void collectSrcLinesForUntouchedFiles(final List<Integer> uncoveredLines, byte[] content, final boolean excludeLines) {
    final ClassReader reader = new ClassReader(content);
    final SourceLineCounter collector = new SourceLineCounter(null, excludeLines, null);
    reader.accept(collector, 0);
    final TIntObjectHashMap lines = collector.getSourceLines();
    lines.forEachKey(new TIntProcedure() {

        public boolean execute(int line) {
            line--;
            uncoveredLines.add(line);
            return true;
        }
    });
}
Also used : TIntProcedure(gnu.trove.TIntProcedure) TIntObjectHashMap(gnu.trove.TIntObjectHashMap) ClassReader(org.jetbrains.org.objectweb.asm.ClassReader) SourceLineCounter(com.intellij.rt.coverage.instrumentation.SourceLineCounter)

Example 19 with TIntObjectHashMap

use of gnu.trove.TIntObjectHashMap in project intellij-community by JetBrains.

the class FileNameCacheMicroBenchmark method generateNames.

@NotNull
private static TIntObjectHashMap<CharSequence> generateNames(int nameCount) {
    Random random = new Random();
    TIntObjectHashMap<CharSequence> map = new TIntObjectHashMap<>();
    for (int i = 0; i < nameCount; i++) {
        String name = "some_name_" + random.nextInt() + StringUtil.repeat("a", random.nextInt(10));
        int id = FileNameCache.storeName(name);
        map.put(id, name);
    }
    return map;
}
Also used : Random(java.util.Random) TIntObjectHashMap(gnu.trove.TIntObjectHashMap) NotNull(org.jetbrains.annotations.NotNull)

Example 20 with TIntObjectHashMap

use of gnu.trove.TIntObjectHashMap in project intellij-community by JetBrains.

the class TestDiscoveryIndex method loadClassAndMethodsMap.

@NotNull
private static TIntObjectHashMap<TIntArrayList> loadClassAndMethodsMap(File file, TestInfoHolder holder) throws IOException {
    DataInputStream inputStream = new DataInputStream(new BufferedInputStream(new FileInputStream(file), 64 * 1024));
    byte[] buffer = IOUtil.allocReadWriteUTFBuffer();
    try {
        int numberOfClasses = DataInputOutputUtil.readINT(inputStream);
        TIntObjectHashMap<TIntArrayList> classData = new TIntObjectHashMap<>(numberOfClasses);
        while (numberOfClasses-- > 0) {
            String classQName = IOUtil.readUTFFast(buffer, inputStream);
            int classId = holder.myClassEnumeratorCache.enumerate(classQName);
            int numberOfMethods = DataInputOutputUtil.readINT(inputStream);
            TIntArrayList methodsList = new TIntArrayList(numberOfMethods);
            while (numberOfMethods-- > 0) {
                String methodName = IOUtil.readUTFFast(buffer, inputStream);
                methodsList.add(holder.myMethodEnumeratorCache.enumerate(methodName));
            }
            classData.put(classId, methodsList);
        }
        return classData;
    } finally {
        inputStream.close();
    }
}
Also used : TIntObjectHashMap(gnu.trove.TIntObjectHashMap) TIntArrayList(gnu.trove.TIntArrayList) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

TIntObjectHashMap (gnu.trove.TIntObjectHashMap)22 ArrayList (java.util.ArrayList)4 TObjectIntHashMap (gnu.trove.TObjectIntHashMap)3 HashMap (java.util.HashMap)3 Nullable (org.jetbrains.annotations.Nullable)3 FileTemplate (com.intellij.ide.fileTemplates.FileTemplate)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 MultiMap (com.intellij.util.containers.MultiMap)2 TIntArrayList (gnu.trove.TIntArrayList)2 Collection (java.util.Collection)2 List (java.util.List)2 Map (java.util.Map)2 Random (java.util.Random)2 NotNull (org.jetbrains.annotations.NotNull)2 VisibleForTesting (com.android.annotations.VisibleForTesting)1 IntArrayWrapper (com.android.ide.common.resources.IntArrayWrapper)1 ResourceType (com.android.resources.ResourceType)1 AppResourceRepository (com.android.tools.idea.res.AppResourceRepository)1 Pair (com.android.util.Pair)1 JavaChainLookupElement (com.intellij.codeInsight.completion.JavaChainLookupElement)1