package com.intellij.compiler.impl.javaCompiler;

import com.intellij.openapi.compiler.CompileContext;
import com.intellij.openapi.diagnostic.Logger;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.NonNls;

import java.io.*;

public abstract class ExternalCompiler implements BackendCompiler {
  private static final Logger LOG = Logger.getInstance("com.intellij.compiler.impl.javaCompiler.ExternalCompiler");

  @NotNull
  public abstract String[] createStartupCommand(ModuleChunk chunk, CompileContext context, String outputPath)
    throws IOException, IllegalArgumentException;

  @NotNull
  public Process launchProcess(final ModuleChunk chunk, final String outputDir, final CompileContext compileContext) throws IOException {
    final String[] commands = createStartupCommand(chunk, compileContext, outputDir);

    @NonNls final StringBuffer buf = new StringBuffer(16 * commands.length);
    buf.append("Running compiler: ");
    for (final String command : commands) {
      buf.append(" ").append(command);
    }

    LOG.info(buf.toString());

    return Runtime.getRuntime().exec(commands);
  }
}

@@ -143,16 +143,69 @@
 Logger;%0A
+import com.intellij.util.StringBuilderSpinAllocator;%0A
 import o
@@ -231,21 +231,20 @@
 tions.No
-tNull
+nNls
 ;%0Aimport
@@ -272,20 +272,21 @@
 tions.No
-nNls
+tNull
 ;%0A%0Aimpor
@@ -295,17 +295,27 @@
 java.io.
-*
+IOException
 ;%0A%0Apubli
@@ -932,18 +932,19 @@
 ngBu
-ff
+ild
 er buf =
  new
@@ -943,12 +943,8 @@
 uf =
- new
  Str
@@ -952,36 +952,48 @@
 ngBu
-ffer(16 * commands.length);%0A
+ilderSpinAllocator.alloc();%0A    try %7B%0A  
     
@@ -1026,16 +1026,18 @@
 er: %22);%0A
+  
     for 
@@ -1070,32 +1070,34 @@
 mmands) %7B%0A      
+ 
+ 
 buf.append(%22 %22).
@@ -1121,15 +1121,19 @@
     
+  
 %7D%0A%0A    
+ 
+ 
 LOG.
@@ -1153,16 +1153,89 @@
 ring());
+%0A    %7D%0A    finally %7B%0A      StringBuilderSpinAllocator.dispose(buf);%0A    %7D
 %0A%0A    re

use StringBuilder from the pool, don't create it each time