Thu, 27 May 2010 19:08:38 -0700
6941466: Oracle rebranding changes for Hotspot repositories
Summary: Change all the Sun copyrights to Oracle copyright
Reviewed-by: ohair
1 /*
2 * Copyright (c) 2005, 2009, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
25 import java.util.*;
26 import java.io.File;
28 class BuildConfig {
29 Hashtable vars;
30 Vector basicNames, basicPaths;
31 String[] context;
33 static CompilerInterface ci;
34 static CompilerInterface getCI() {
35 if (ci == null) {
36 String comp = (String)getField(null, "CompilerVersion");
37 try {
38 ci = (CompilerInterface)Class.forName("CompilerInterface" + comp).newInstance();
39 } catch (Exception cnfe) {
40 System.err.println("Cannot find support for compiler " + comp);
41 throw new RuntimeException(cnfe.toString());
42 }
43 }
44 return ci;
45 }
47 protected void initNames(String flavour, String build, String outDll) {
48 if (vars == null) vars = new Hashtable();
50 String flavourBuild = flavour + "_" + build;
51 put("Name", getCI().makeCfgName(flavourBuild));
52 put("Flavour", flavour);
53 put("Build", build);
55 // ones mentioned above were needed to expand format
56 String buildBase = expandFormat(getFieldString(null, "BuildBase"));
57 String jdkDir = getFieldString(null, "JdkTargetRoot");
58 String sourceBase = getFieldString(null, "SourceBase");
59 String outDir = buildBase;
61 put("Id", flavourBuild);
62 put("OutputDir", outDir);
63 put("SourceBase", sourceBase);
64 put("BuildBase", buildBase);
65 put("OutputDll", jdkDir + Util.sep + outDll);
67 context = new String [] {flavourBuild, flavour, build, null};
68 }
70 protected void init(Vector includes, Vector defines) {
71 initDefaultDefines(defines);
72 initDefaultCompilerFlags(includes);
73 initDefaultLinkerFlags();
74 handleDB((String)getFieldInContext("IncludeDB"));
75 }
78 protected void initDefaultCompilerFlags(Vector includes) {
79 Vector compilerFlags = new Vector();
81 compilerFlags.addAll(getCI().getBaseCompilerFlags(getV("Define"),
82 includes,
83 get("OutputDir")));
85 put("CompilerFlags", compilerFlags);
86 }
88 protected void initDefaultLinkerFlags() {
89 Vector linkerFlags = new Vector();
91 linkerFlags.addAll(getCI().getBaseLinkerFlags( get("OutputDir"), get("OutputDll")));
93 put("LinkerFlags", linkerFlags);
94 }
96 DirectoryTree getSourceTree(String sourceBase, String startAt) {
97 DirectoryTree tree = new DirectoryTree();
99 tree.addSubdirToIgnore("Codemgr_wsdata");
100 tree.addSubdirToIgnore("deleted_files");
101 tree.addSubdirToIgnore("SCCS");
102 tree.setVerbose(true);
103 if (startAt != null) {
104 tree.readDirectory(sourceBase + File.separator + startAt);
105 } else {
106 tree.readDirectory(sourceBase);
107 }
109 return tree;
110 }
113 Vector getPreferredPaths(Database currentDB) {
114 Vector preferredPaths = new Vector();
115 // In the case of multiple files with the same name in
116 // different subdirectories, prefer the versions specified in
117 // the platform file as the "os_family" and "arch" macros.
118 for (Iterator iter = currentDB.getMacros(); iter.hasNext(); ) {
119 Macro macro = (Macro) iter.next();
120 if (macro.name.equals("os_family") ||
121 macro.name.equals("arch")) {
122 preferredPaths.add(macro.contents);
123 }
124 }
125 // Also prefer "opto" over "adlc" for adlcVMDeps.hpp
126 preferredPaths.add("opto");
128 return preferredPaths;
129 }
132 void handleDB(String dbFile) {
133 WinGammaPlatform platform = (WinGammaPlatform)getField(null, "PlatformObject");
134 Database db = new Database(platform, platform.defaultGrandIncludeThreshold());
136 try {
137 File incls = new File(get("OutputDir")+Util.sep+"incls");
138 FileName oldInclTempl = platform.getInclFileTemplate();
139 FileName oldGITempl = platform.getGIFileTemplate();
140 FileName oldGDTempl = platform.getGDFileTemplate();
142 platform.setInclFileTemplate(new FileName(platform, incls.getPath()+Util.sep,
143 "_", "", ".incl", "", ""));
144 platform.setGIFileTemplate(new FileName(platform, incls.getPath()+Util.sep,
145 "", "_precompiled", ".incl", "", ""));
147 incls.mkdirs();
149 db.get(getFieldString(null, "Platform"), dbFile);
150 db.compute();
152 db.put();
154 //platform.setInclFileTemplate(oldInclTempl);
155 //platform.setGIFileTemplate(oldInclTempl);
156 } catch (Exception e) {
157 e.printStackTrace();
158 throw new RuntimeException("cannot do db: "+e);
159 }
161 putSpecificField("AllFilesHash", computeAllFiles(platform, db));
162 }
165 void addAll(Iterator i, Hashtable hash,
166 WinGammaPlatform platform, DirectoryTree tree,
167 Vector preferredPaths, Vector filesNotFound, Vector filesDuplicate) {
168 for (; i.hasNext(); ) {
169 String fileName = (String) i.next();
170 if (lookupHashFieldInContext("IgnoreFile", fileName) == null) {
171 String prefixedName = platform.envVarPrefixedFileName(fileName,
172 0, /* ignored */
173 tree,
174 preferredPaths,
175 filesNotFound,
176 filesDuplicate);
177 if (prefixedName != null) {
178 addTo(hash, Util.normalize(prefixedName), fileName);
179 }
180 }
181 }
182 }
184 void addTo(Hashtable ht, String key, String value) {
185 ht.put(expandFormat(key), expandFormat(value));
186 }
188 Hashtable computeAllFiles(WinGammaPlatform platform, Database db) {
189 Hashtable rv = new Hashtable();
190 DirectoryTree tree = getSourceTree(get("SourceBase"), getFieldString(null, "StartAt"));
191 Vector preferredPaths = getPreferredPaths(db);
193 // Hold errors until end
194 Vector filesNotFound = new Vector();
195 Vector filesDuplicate = new Vector();
198 // find all files
199 Vector dbFiles = new Vector();
200 for (Iterator i=db.getAllFiles().iterator(); i.hasNext(); ) {
201 FileList fl = (FileList) i.next();
202 dbFiles.add(fl.getName());
203 }
204 addAll(dbFiles.iterator(), rv,
205 platform, tree,
206 preferredPaths, filesNotFound, filesDuplicate);
208 Vector addFiles = new Vector();
209 collectRelevantVectors(addFiles, "AdditionalFile");
210 addAll(addFiles.iterator(), rv,
211 platform, tree,
212 preferredPaths, filesNotFound, filesDuplicate);
214 collectRelevantHashes(rv, "AdditionalGeneratedFile");
216 if ((filesNotFound.size() != 0) ||
217 (filesDuplicate.size() != 0)) {
218 System.err.println("Error: some files were not found or " +
219 "appeared in multiple subdirectories of " +
220 "directory " + get("SourceBase") + " and could not " +
221 "be resolved with the os_family and arch " +
222 "macros in the platform file.");
223 if (filesNotFound.size() != 0) {
224 System.err.println("Files not found:");
225 for (Iterator iter = filesNotFound.iterator();
226 iter.hasNext(); ) {
227 System.err.println(" " + (String) iter.next());
228 }
229 }
230 if (filesDuplicate.size() != 0) {
231 System.err.println("Duplicate files:");
232 for (Iterator iter = filesDuplicate.iterator();
233 iter.hasNext(); ) {
234 System.err.println(" " + (String) iter.next());
235 }
236 }
237 throw new RuntimeException();
238 }
240 return rv;
241 }
243 void initDefaultDefines(Vector defines) {
244 Vector sysDefines = new Vector();
245 sysDefines.add("WIN32");
246 sysDefines.add("_WINDOWS");
247 sysDefines.add("HOTSPOT_BUILD_USER="+System.getProperty("user.name"));
248 sysDefines.add("HOTSPOT_BUILD_TARGET=\\\""+get("Build")+"\\\"");
249 sysDefines.add("_JNI_IMPLEMENTATION_");
250 sysDefines.add("HOTSPOT_LIB_ARCH=\\\"i386\\\"");
252 sysDefines.addAll(defines);
254 put("Define", sysDefines);
255 }
257 String get(String key) {
258 return (String)vars.get(key);
259 }
261 Vector getV(String key) {
262 return (Vector)vars.get(key);
263 }
265 Object getO(String key) {
266 return vars.get(key);
267 }
269 Hashtable getH(String key) {
270 return (Hashtable)vars.get(key);
271 }
273 Object getFieldInContext(String field) {
274 for (int i=0; i<context.length; i++) {
275 Object rv = getField(context[i], field);
276 if (rv != null) {
277 return rv;
278 }
279 }
280 return null;
281 }
283 Object lookupHashFieldInContext(String field, String key) {
284 for (int i=0; i<context.length; i++) {
285 Hashtable ht = (Hashtable)getField(context[i], field);
286 if (ht != null) {
287 Object rv = ht.get(key);
288 if (rv != null) {
289 return rv;
290 }
291 }
292 }
293 return null;
294 }
296 void put(String key, String value) {
297 vars.put(key, value);
298 }
300 void put(String key, Vector vvalue) {
301 vars.put(key, vvalue);
302 }
304 void add(String key, Vector vvalue) {
305 getV(key).addAll(vvalue);
306 }
308 String flavour() {
309 return get("Flavour");
310 }
312 String build() {
313 return get("Build");
314 }
316 Object getSpecificField(String field) {
317 return getField(get("Id"), field);
318 }
320 void putSpecificField(String field, Object value) {
321 putField(get("Id"), field, value);
322 }
324 void collectRelevantVectors(Vector rv, String field) {
325 for (int i = 0; i < context.length; i++) {
326 Vector v = getFieldVector(context[i], field);
327 if (v != null) {
328 for (Iterator j=v.iterator(); j.hasNext(); ) {
329 String val = (String)j.next();
330 rv.add(expandFormat(val));
331 }
332 }
333 }
334 }
336 void collectRelevantHashes(Hashtable rv, String field) {
337 for (int i = 0; i < context.length; i++) {
338 Hashtable v = (Hashtable)getField(context[i], field);
339 if (v != null) {
340 for (Enumeration e=v.keys(); e.hasMoreElements(); ) {
341 String key = (String)e.nextElement();
342 String val = (String)v.get(key);
343 addTo(rv, key, val);
344 }
345 }
346 }
347 }
350 Vector getDefines() {
351 Vector rv = new Vector();
352 collectRelevantVectors(rv, "Define");
353 return rv;
354 }
356 Vector getIncludes() {
357 Vector rv = new Vector();
359 // for generated includes
360 rv.add(get("OutputDir"));
362 collectRelevantVectors(rv, "AbsoluteInclude");
364 Vector ri = new Vector();
365 String sourceBase = getFieldString(null, "SourceBase");
366 collectRelevantVectors(ri, "RelativeInclude");
367 for (Iterator i = ri.iterator(); i.hasNext(); ) {
368 String f = (String)i.next();
369 rv.add(sourceBase + Util.sep + f);
370 }
372 return rv;
373 }
375 static Hashtable cfgData = new Hashtable();
376 static Hashtable globalData = new Hashtable();
378 static boolean appliesToTieredBuild(String cfg) {
379 return (cfg != null &&
380 (cfg.startsWith("compiler1") ||
381 cfg.startsWith("compiler2")));
382 }
384 // Filters out the IncludeDB statement, which is the only command-
385 // line argument we explicitly specialize for the tiered build
386 static boolean appliesToTieredBuild(String cfg, String key) {
387 return (appliesToTieredBuild(cfg) &&
388 (key != null &&
389 !key.equals("IncludeDB")));
390 }
392 static String getTieredBuildCfg(String cfg) {
393 assert appliesToTieredBuild(cfg) : "illegal configuration " + cfg;
394 return "tiered" + cfg.substring(9);
395 }
397 static Object getField(String cfg, String field) {
398 if (cfg == null) {
399 return globalData.get(field);
400 }
402 Hashtable ht = (Hashtable)cfgData.get(cfg);
403 return ht == null ? null : ht.get(field);
404 }
406 static String getFieldString(String cfg, String field) {
407 return (String)getField(cfg, field);
408 }
410 static Vector getFieldVector(String cfg, String field) {
411 return (Vector)getField(cfg, field);
412 }
414 static void putField(String cfg, String field, Object value) {
415 putFieldImpl(cfg, field, value);
416 if (appliesToTieredBuild(cfg, field)) {
417 putFieldImpl(getTieredBuildCfg(cfg), field, value);
418 }
419 }
421 private static void putFieldImpl(String cfg, String field, Object value) {
422 if (cfg == null) {
423 globalData.put(field, value);
424 return;
425 }
427 Hashtable ht = (Hashtable)cfgData.get(cfg);
428 if (ht == null) {
429 ht = new Hashtable();
430 cfgData.put(cfg, ht);
431 }
433 ht.put(field, value);
434 }
436 static Object getFieldHash(String cfg, String field, String name) {
437 Hashtable ht = (Hashtable)getField(cfg, field);
439 return ht == null ? null : ht.get(name);
440 }
442 static void putFieldHash(String cfg, String field, String name, Object val) {
443 putFieldHashImpl(cfg, field, name, val);
444 if (appliesToTieredBuild(cfg)) {
445 putFieldHashImpl(getTieredBuildCfg(cfg), field, name, val);
446 }
447 }
449 private static void putFieldHashImpl(String cfg, String field, String name, Object val) {
450 Hashtable ht = (Hashtable)getField(cfg, field);
452 if (ht == null) {
453 ht = new Hashtable();
454 putFieldImpl(cfg, field, ht);
455 }
457 ht.put(name, val);
458 }
460 static void addFieldVector(String cfg, String field, String element) {
461 addFieldVectorImpl(cfg, field, element);
462 if (appliesToTieredBuild(cfg)) {
463 addFieldVectorImpl(getTieredBuildCfg(cfg), field, element);
464 }
465 }
467 private static void addFieldVectorImpl(String cfg, String field, String element) {
468 Vector v = (Vector)getField(cfg, field);
470 if (v == null) {
471 v = new Vector();
472 putFieldImpl(cfg, field, v);
473 }
475 v.add(element);
476 }
478 String expandFormat(String format) {
479 if (format == null) {
480 return null;
481 }
483 if (format.indexOf('%') == -1) {
484 return format;
485 }
487 StringBuffer sb = new StringBuffer();
488 int len = format.length();
489 for (int i=0; i<len; i++) {
490 char ch = format.charAt(i);
491 if (ch == '%') {
492 char ch1 = format.charAt(i+1);
493 switch (ch1) {
494 case '%':
495 sb.append(ch1);
496 break;
497 case 'b':
498 sb.append(build());
499 break;
500 case 'f':
501 sb.append(flavour());
502 break;
503 default:
504 sb.append(ch);
505 sb.append(ch1);
506 }
507 i++;
508 } else {
509 sb.append(ch);
510 }
511 }
513 return sb.toString();
514 }
515 }
517 abstract class GenericDebugConfig extends BuildConfig {
518 abstract String getOptFlag();
520 protected void init(Vector includes, Vector defines) {
521 defines.add("_DEBUG");
522 defines.add("ASSERT");
524 super.init(includes, defines);
526 getV("CompilerFlags").addAll(getCI().getDebugCompilerFlags(getOptFlag()));
527 getV("LinkerFlags").addAll(getCI().getDebugLinkerFlags());
528 }
529 }
531 class C1DebugConfig extends GenericDebugConfig {
532 String getOptFlag() {
533 return getCI().getNoOptFlag();
534 }
536 C1DebugConfig() {
537 initNames("compiler1", "debug", "fastdebug\\jre\\bin\\client\\jvm.dll");
538 init(getIncludes(), getDefines());
539 }
540 }
542 class C1FastDebugConfig extends GenericDebugConfig {
543 String getOptFlag() {
544 return getCI().getOptFlag();
545 }
547 C1FastDebugConfig() {
548 initNames("compiler1", "fastdebug", "fastdebug\\jre\\bin\\client\\jvm.dll");
549 init(getIncludes(), getDefines());
550 }
551 }
553 class C2DebugConfig extends GenericDebugConfig {
554 String getOptFlag() {
555 return getCI().getNoOptFlag();
556 }
558 C2DebugConfig() {
559 initNames("compiler2", "debug", "fastdebug\\jre\\bin\\server\\jvm.dll");
560 init(getIncludes(), getDefines());
561 }
562 }
564 class C2FastDebugConfig extends GenericDebugConfig {
565 String getOptFlag() {
566 return getCI().getOptFlag();
567 }
569 C2FastDebugConfig() {
570 initNames("compiler2", "fastdebug", "fastdebug\\jre\\bin\\server\\jvm.dll");
571 init(getIncludes(), getDefines());
572 }
573 }
575 class TieredDebugConfig extends GenericDebugConfig {
576 String getOptFlag() {
577 return getCI().getNoOptFlag();
578 }
580 TieredDebugConfig() {
581 initNames("tiered", "debug", "fastdebug\\jre\\bin\\server\\jvm.dll");
582 init(getIncludes(), getDefines());
583 }
584 }
586 class TieredFastDebugConfig extends GenericDebugConfig {
587 String getOptFlag() {
588 return getCI().getOptFlag();
589 }
591 TieredFastDebugConfig() {
592 initNames("tiered", "fastdebug", "fastdebug\\jre\\bin\\server\\jvm.dll");
593 init(getIncludes(), getDefines());
594 }
595 }
598 abstract class ProductConfig extends BuildConfig {
599 protected void init(Vector includes, Vector defines) {
600 defines.add("NDEBUG");
601 defines.add("PRODUCT");
603 super.init(includes, defines);
605 getV("CompilerFlags").addAll(getCI().getProductCompilerFlags());
606 getV("LinkerFlags").addAll(getCI().getProductLinkerFlags());
607 }
608 }
610 class C1ProductConfig extends ProductConfig {
611 C1ProductConfig() {
612 initNames("compiler1", "product", "jre\\bin\\client\\jvm.dll");
613 init(getIncludes(), getDefines());
614 }
615 }
617 class C2ProductConfig extends ProductConfig {
618 C2ProductConfig() {
619 initNames("compiler2", "product", "jre\\bin\\server\\jvm.dll");
620 init(getIncludes(), getDefines());
621 }
622 }
624 class TieredProductConfig extends ProductConfig {
625 TieredProductConfig() {
626 initNames("tiered", "product", "jre\\bin\\server\\jvm.dll");
627 init(getIncludes(), getDefines());
628 }
629 }
632 class CoreDebugConfig extends GenericDebugConfig {
633 String getOptFlag() {
634 return getCI().getNoOptFlag();
635 }
637 CoreDebugConfig() {
638 initNames("core", "debug", "fastdebug\\jre\\bin\\core\\jvm.dll");
639 init(getIncludes(), getDefines());
640 }
641 }
644 class CoreFastDebugConfig extends GenericDebugConfig {
645 String getOptFlag() {
646 return getCI().getOptFlag();
647 }
649 CoreFastDebugConfig() {
650 initNames("core", "fastdebug", "fastdebug\\jre\\bin\\core\\jvm.dll");
651 init(getIncludes(), getDefines());
652 }
653 }
656 class CoreProductConfig extends ProductConfig {
657 CoreProductConfig() {
658 initNames("core", "product", "jre\\bin\\core\\jvm.dll");
659 init(getIncludes(), getDefines());
660 }
661 }
663 class KernelDebugConfig extends GenericDebugConfig {
664 String getOptFlag() {
665 return getCI().getNoOptFlag();
666 }
668 KernelDebugConfig() {
669 initNames("kernel", "debug", "fastdebug\\jre\\bin\\kernel\\jvm.dll");
670 init(getIncludes(), getDefines());
671 }
672 }
675 class KernelFastDebugConfig extends GenericDebugConfig {
676 String getOptFlag() {
677 return getCI().getOptFlag();
678 }
680 KernelFastDebugConfig() {
681 initNames("kernel", "fastdebug", "fastdebug\\jre\\bin\\kernel\\jvm.dll");
682 init(getIncludes(), getDefines());
683 }
684 }
687 class KernelProductConfig extends ProductConfig {
688 KernelProductConfig() {
689 initNames("kernel", "product", "jre\\bin\\kernel\\jvm.dll");
690 init(getIncludes(), getDefines());
691 }
692 }
693 abstract class CompilerInterface {
694 abstract Vector getBaseCompilerFlags(Vector defines, Vector includes, String outDir);
695 abstract Vector getBaseLinkerFlags(String outDir, String outDll);
696 abstract Vector getDebugCompilerFlags(String opt);
697 abstract Vector getDebugLinkerFlags();
698 abstract Vector getProductCompilerFlags();
699 abstract Vector getProductLinkerFlags();
700 abstract String getOptFlag();
701 abstract String getNoOptFlag();
702 abstract String makeCfgName(String flavourBuild);
704 void addAttr(Vector receiver, String attr, String value) {
705 receiver.add(attr); receiver.add(value);
706 }
707 }