15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package com.sun.tools.sjavac;
27
28 import java.io.File;
29 import java.io.PrintStream;
30 import java.net.URI;
31 import java.util.Arrays;
32 import java.util.Collections;
33 import java.util.Random;
34 import java.util.Set;
35 import java.util.Map;
36
37 import com.sun.tools.sjavac.options.Options;
38 import com.sun.tools.sjavac.server.CompilationResult;
39 import com.sun.tools.sjavac.server.JavacService;
40 import com.sun.tools.sjavac.server.SysInfo;
41
42 /**
43 * This transform compiles a set of packages containing Java sources.
44 * The compile request is divided into separate sets of source files.
45 * For each set a separate request thread is dispatched to a javac server
46 * and the meta data is accumulated. The number of sets correspond more or
47 * less to the number of cores. Less so now, than it will in the future.
48 *
49 * <p><b>This is NOT part of any supported API.
50 * If you write code that depends on this, you do so at your own
51 * risk. This code and its internal interfaces are subject to change
52 * or deletion without notice.</b></p>
53 */
54 public class CompileJavaPackages implements Transformer {
58 // We hope to improve this in the future.
59 final static int limitOnConcurrency = 3;
60
61 Options args;
62
63 public void setExtra(String e) {
64 }
65
66 public void setExtra(Options a) {
67 args = a;
68 }
69
70 public boolean transform(final JavacService javacService,
71 Map<String,Set<URI>> pkgSrcs,
72 final Set<URI> visibleSources,
73 final Map<URI,Set<String>> visibleClasses,
74 Map<String,Set<String>> oldPackageDependents,
75 URI destRoot,
76 final Map<String,Set<URI>> packageArtifacts,
77 final Map<String,Set<String>> packageDependencies,
78 final Map<String,String> packagePubapis,
79 int debugLevel,
80 boolean incremental,
81 int numCores,
82 final PrintStream out,
83 final PrintStream err)
84 {
85 boolean rc = true;
86 boolean concurrentCompiles = true;
87
88 // Fetch the id.
89 final String id = Util.extractStringOption("id", javacService.serverSettings());
90 // Only keep portfile and sjavac settings..
91 String psServerSettings = Util.cleanSubOptions(Util.set("portfile","sjavac","background","keepalive"), javacService.serverSettings());
92
93 // Get maximum heap size from the server!
94 SysInfo sysinfo = javacService.getSysInfo();
95 if (sysinfo.numCores == -1) {
96 Log.error("Could not query server for sysinfo!");
97 return false;
98 }
99 int numMBytes = (int)(sysinfo.maxMemory / ((long)(1024*1024)));
100 Log.debug("Server reports "+numMBytes+"MiB of memory and "+sysinfo.numCores+" cores");
101
102 if (numCores <= 0) {
103 // Set the requested number of cores to the number of cores on the server.
104 numCores = sysinfo.numCores;
105 Log.debug("Number of jobs not explicitly set, defaulting to "+sysinfo.numCores);
106 } else if (sysinfo.numCores < numCores) {
107 // Set the requested number of cores to the number of cores on the server.
108 Log.debug("Limiting jobs from explicitly set "+numCores+" to cores available on server: "+sysinfo.numCores);
109 numCores = sysinfo.numCores;
110 } else {
111 Log.debug("Number of jobs explicitly set to "+numCores);
112 }
113 // More than three concurrent cores does not currently give a speedup, at least for compiling the jdk
114 // in the OpenJDK. This will change in the future.
115 int numCompiles = numCores;
116 if (numCores > limitOnConcurrency) numCompiles = limitOnConcurrency;
207 long start = System.currentTimeMillis();
208
209 for (int i=0; i<numCompiles; ++i) {
210 final int ii = i;
211 final CompileChunk cc = compileChunks[i];
212
213 // Pass the num_cores and the id (appended with the chunk number) to the server.
214 final String cleanedServerSettings = psServerSettings+",poolsize="+numCores+",id="+id+"-"+i;
215
216 requests[i] = new Thread() {
217 @Override
218 public void run() {
219 rn[ii] = javacService.compile("n/a",
220 id + "-" + ii,
221 args.prepJavacArgs(),
222 Collections.<File>emptyList(),
223 cc.srcs,
224 visibleSources);
225 packageArtifacts.putAll(rn[ii].packageArtifacts);
226 packageDependencies.putAll(rn[ii].packageDependencies);
227 packagePubapis.putAll(rn[ii].packagePubapis);
228 }
229 };
230
231 if (cc.srcs.size() > 0) {
232 String numdeps = "";
233 if (cc.numDependents > 0) numdeps = "(with "+cc.numDependents+" dependents) ";
234 if (!incremental || cc.numPackages > 16) {
235 String info = "("+cc.pkgFromTos+")";
236 if (info.equals("( to )")) {
237 info = "";
238 }
239 Log.info("Compiling "+cc.srcs.size()+" files "+numdeps+"in "+cc.numPackages+" packages "+info);
240 } else {
241 Log.info("Compiling "+cc.pkgNames+numdeps);
242 }
243 if (concurrentCompiles) {
244 requests[ii].start();
245 }
246 else {
247 requests[ii].run();
|
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package com.sun.tools.sjavac;
27
28 import java.io.File;
29 import java.io.PrintStream;
30 import java.net.URI;
31 import java.util.Arrays;
32 import java.util.Collections;
33 import java.util.Random;
34 import java.util.Set;
35 import java.util.List;
36 import java.util.Map;
37
38 import com.sun.tools.sjavac.options.Options;
39 import com.sun.tools.sjavac.server.CompilationResult;
40 import com.sun.tools.sjavac.server.JavacService;
41 import com.sun.tools.sjavac.server.SysInfo;
42
43 /**
44 * This transform compiles a set of packages containing Java sources.
45 * The compile request is divided into separate sets of source files.
46 * For each set a separate request thread is dispatched to a javac server
47 * and the meta data is accumulated. The number of sets correspond more or
48 * less to the number of cores. Less so now, than it will in the future.
49 *
50 * <p><b>This is NOT part of any supported API.
51 * If you write code that depends on this, you do so at your own
52 * risk. This code and its internal interfaces are subject to change
53 * or deletion without notice.</b></p>
54 */
55 public class CompileJavaPackages implements Transformer {
59 // We hope to improve this in the future.
60 final static int limitOnConcurrency = 3;
61
62 Options args;
63
64 public void setExtra(String e) {
65 }
66
67 public void setExtra(Options a) {
68 args = a;
69 }
70
71 public boolean transform(final JavacService javacService,
72 Map<String,Set<URI>> pkgSrcs,
73 final Set<URI> visibleSources,
74 final Map<URI,Set<String>> visibleClasses,
75 Map<String,Set<String>> oldPackageDependents,
76 URI destRoot,
77 final Map<String,Set<URI>> packageArtifacts,
78 final Map<String,Set<String>> packageDependencies,
79 final Map<String,List<String>> packagePublicApis,
80 final Map<String,Set<String>> classpathPackageDependencies,
81 int debugLevel,
82 boolean incremental,
83 int numCores,
84 final PrintStream out,
85 final PrintStream err)
86 {
87 boolean rc = true;
88 boolean concurrentCompiles = true;
89
90 // Fetch the id.
91 final String id = Util.extractStringOption("id", javacService.serverSettings());
92 // Only keep portfile and sjavac settings..
93 String psServerSettings = Util.cleanSubOptions(Util.set("portfile","sjavac","background","keepalive"), javacService.serverSettings());
94
95 // Get maximum heap size from the server!
96 SysInfo sysinfo = javacService.getSysInfo();
97 if (sysinfo.numCores == -1) {
98 Log.error("Could not query server for sysinfo! Check javac_server.stdouterr for exceptions");
99 return false;
100 }
101 int numMBytes = (int)(sysinfo.maxMemory / ((long)(1024*1024)));
102 Log.debug("Server reports "+numMBytes+"MiB of memory and "+sysinfo.numCores+" cores");
103
104 if (numCores <= 0) {
105 // Set the requested number of cores to the number of cores on the server.
106 numCores = sysinfo.numCores;
107 Log.debug("Number of jobs not explicitly set, defaulting to "+sysinfo.numCores);
108 } else if (sysinfo.numCores < numCores) {
109 // Set the requested number of cores to the number of cores on the server.
110 Log.debug("Limiting jobs from explicitly set "+numCores+" to cores available on server: "+sysinfo.numCores);
111 numCores = sysinfo.numCores;
112 } else {
113 Log.debug("Number of jobs explicitly set to "+numCores);
114 }
115 // More than three concurrent cores does not currently give a speedup, at least for compiling the jdk
116 // in the OpenJDK. This will change in the future.
117 int numCompiles = numCores;
118 if (numCores > limitOnConcurrency) numCompiles = limitOnConcurrency;
209 long start = System.currentTimeMillis();
210
211 for (int i=0; i<numCompiles; ++i) {
212 final int ii = i;
213 final CompileChunk cc = compileChunks[i];
214
215 // Pass the num_cores and the id (appended with the chunk number) to the server.
216 final String cleanedServerSettings = psServerSettings+",poolsize="+numCores+",id="+id+"-"+i;
217
218 requests[i] = new Thread() {
219 @Override
220 public void run() {
221 rn[ii] = javacService.compile("n/a",
222 id + "-" + ii,
223 args.prepJavacArgs(),
224 Collections.<File>emptyList(),
225 cc.srcs,
226 visibleSources);
227 packageArtifacts.putAll(rn[ii].packageArtifacts);
228 packageDependencies.putAll(rn[ii].packageDependencies);
229 packagePublicApis.putAll(rn[ii].packagePublicApis);
230 classpathPackageDependencies.putAll(rn[ii].classpathPackageDependencies);
231 }
232 };
233
234 if (cc.srcs.size() > 0) {
235 String numdeps = "";
236 if (cc.numDependents > 0) numdeps = "(with "+cc.numDependents+" dependents) ";
237 if (!incremental || cc.numPackages > 16) {
238 String info = "("+cc.pkgFromTos+")";
239 if (info.equals("( to )")) {
240 info = "";
241 }
242 Log.info("Compiling "+cc.srcs.size()+" files "+numdeps+"in "+cc.numPackages+" packages "+info);
243 } else {
244 Log.info("Compiling "+cc.pkgNames+numdeps);
245 }
246 if (concurrentCompiles) {
247 requests[ii].start();
248 }
249 else {
250 requests[ii].run();
|