Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/tools/ProjectCreator/BuildConfig.java
32285 views
/*1* Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324import java.util.Enumeration;25import java.util.Hashtable;26import java.util.Vector;2728class BuildConfig {29@SuppressWarnings("rawtypes")30Hashtable vars;31Vector<String> basicNames, basicPaths;32String[] context;3334static CompilerInterface ci;35static CompilerInterface getCI() {36if (ci == null) {37String comp = (String)getField(null, "CompilerVersion");38try {39ci = (CompilerInterface)Class.forName("CompilerInterface" + comp).newInstance();40} catch (Exception cnfe) {41System.err.println("Cannot find support for compiler " + comp);42throw new RuntimeException(cnfe.toString());43}44}45return ci;46}4748@SuppressWarnings("rawtypes")49protected void initNames(String flavour, String build, String outDll) {50if (vars == null) vars = new Hashtable();5152String flavourBuild = flavour + "_" + build;53String platformName = getFieldString(null, "PlatformName");54System.out.println();55System.out.println(flavourBuild);5657put("Name", getCI().makeCfgName(flavourBuild, platformName));58put("Flavour", flavour);59put("Build", build);60put("PlatformName", platformName);6162// ones mentioned above were needed to expand format63String buildBase = expandFormat(getFieldString(null, "BuildBase"));64String sourceBase = getFieldString(null, "SourceBase");65String buildSpace = getFieldString(null, "BuildSpace");66String outDir = buildBase;67String jdkTargetRoot = getFieldString(null, "JdkTargetRoot");6869put("Id", flavourBuild);70put("OutputDir", outDir);71put("SourceBase", sourceBase);72put("BuildBase", buildBase);73put("BuildSpace", buildSpace);74put("OutputDll", outDir + Util.sep + outDll);75put("JdkTargetRoot", jdkTargetRoot);7677context = new String [] {flavourBuild, flavour, build, null};78}7980protected void init(Vector<String> includes, Vector<String> defines) {81initDefaultDefines(defines);82initDefaultCompilerFlags(includes);83initDefaultLinkerFlags();84//handleDB();85}868788protected void initDefaultCompilerFlags(Vector<String> includes) {89Vector compilerFlags = new Vector();9091compilerFlags.addAll(getCI().getBaseCompilerFlags(getV("Define"),92includes,93get("OutputDir")));9495put("CompilerFlags", compilerFlags);96}9798protected void initDefaultLinkerFlags() {99Vector linkerFlags = new Vector();100101linkerFlags.addAll(getCI().getBaseLinkerFlags( get("OutputDir"), get("OutputDll"), get("PlatformName")));102103put("LinkerFlags", linkerFlags);104}105106public boolean matchesIgnoredPath(String path) {107Vector<String> rv = new Vector<String>();108collectRelevantVectors(rv, "IgnorePath");109for (String pathPart : rv) {110if (path.contains(pathPart)) {111return true;112}113}114return false;115}116117public boolean matchesHidePath(String path) {118Vector<String> rv = new Vector<String>();119collectRelevantVectors(rv, "HidePath");120for (String pathPart : rv) {121if (path.contains(Util.normalize(pathPart))) {122return true;123}124}125return false;126}127128public Vector<String> matchesAdditionalGeneratedPath(String fullPath) {129Vector<String> rv = new Vector<String>();130Hashtable<String, String> v = (Hashtable<String, String>)BuildConfig.getField(this.toString(), "AdditionalGeneratedFile");131if (v != null) {132for (Enumeration<String> e=v.keys(); e.hasMoreElements(); ) {133String key = e.nextElement();134String val = v.get(key);135136if (fullPath.endsWith(expandFormat(key))) {137rv.add(expandFormat(val));138}139}140}141return rv;142}143144// Returns true if the specified path refers to a relative alternate145// source file. RelativeAltSrcInclude is usually "src\closed".146public static boolean matchesRelativeAltSrcInclude(String path) {147String relativeAltSrcInclude =148getFieldString(null, "RelativeAltSrcInclude");149Vector<String> v = getFieldVector(null, "AltRelativeInclude");150for (String pathPart : v) {151if (path.contains(relativeAltSrcInclude + Util.sep + pathPart)) {152return true;153}154}155return false;156}157158// Returns the relative alternate source file for the specified path.159// Null is returned if the specified path does not have a matching160// alternate source file.161public static String getMatchingRelativeAltSrcFile(String path) {162Vector<String> v = getFieldVector(null, "RelativeAltSrcFileList");163if (v == null) {164return null;165}166for (String pathPart : v) {167if (path.endsWith(pathPart)) {168String relativeAltSrcInclude =169getFieldString(null, "RelativeAltSrcInclude");170return relativeAltSrcInclude + Util.sep + pathPart;171}172}173return null;174}175176// Returns true if the specified path has a matching alternate177// source file.178public static boolean matchesRelativeAltSrcFile(String path) {179return getMatchingRelativeAltSrcFile(path) != null;180}181182// Track the specified alternate source file. The source file is183// tracked without the leading .*<sep><RelativeAltSrcFileList><sep>184// part to make matching regular source files easier.185public static void trackRelativeAltSrcFile(String path) {186String pattern = getFieldString(null, "RelativeAltSrcInclude") +187Util.sep;188int altSrcInd = path.indexOf(pattern);189if (altSrcInd == -1) {190// not an AltSrc path191return;192}193194altSrcInd += pattern.length();195if (altSrcInd >= path.length()) {196// not a valid AltSrc path197return;198}199200String altSrcFile = path.substring(altSrcInd);201Vector v = getFieldVector(null, "RelativeAltSrcFileList");202if (v == null || !v.contains(altSrcFile)) {203addFieldVector(null, "RelativeAltSrcFileList", altSrcFile);204}205}206207void addTo(Hashtable ht, String key, String value) {208ht.put(expandFormat(key), expandFormat(value));209}210211void initDefaultDefines(Vector defines) {212Vector sysDefines = new Vector();213sysDefines.add("WIN32");214sysDefines.add("_WINDOWS");215sysDefines.add("HOTSPOT_BUILD_USER=\\\""+System.getProperty("user.name")+"\\\"");216sysDefines.add("HOTSPOT_BUILD_TARGET=\\\""+get("Build")+"\\\"");217sysDefines.add("INCLUDE_TRACE=1");218sysDefines.add("_JNI_IMPLEMENTATION_");219if (vars.get("PlatformName").equals("Win32")) {220sysDefines.add("HOTSPOT_LIB_ARCH=\\\"i386\\\"");221} else {222sysDefines.add("HOTSPOT_LIB_ARCH=\\\"amd64\\\"");223}224225sysDefines.addAll(defines);226227put("Define", sysDefines);228}229230String get(String key) {231return (String)vars.get(key);232}233234Vector getV(String key) {235return (Vector)vars.get(key);236}237238Object getO(String key) {239return vars.get(key);240}241242Hashtable getH(String key) {243return (Hashtable)vars.get(key);244}245246Object getFieldInContext(String field) {247for (int i=0; i<context.length; i++) {248Object rv = getField(context[i], field);249if (rv != null) {250return rv;251}252}253return null;254}255256Object lookupHashFieldInContext(String field, String key) {257for (int i=0; i<context.length; i++) {258Hashtable ht = (Hashtable)getField(context[i], field);259if (ht != null) {260Object rv = ht.get(key);261if (rv != null) {262return rv;263}264}265}266return null;267}268269void put(String key, String value) {270vars.put(key, value);271}272273void put(String key, Vector vvalue) {274vars.put(key, vvalue);275}276277void add(String key, Vector vvalue) {278getV(key).addAll(vvalue);279}280281String flavour() {282return get("Flavour");283}284285String build() {286return get("Build");287}288289Object getSpecificField(String field) {290return getField(get("Id"), field);291}292293void putSpecificField(String field, Object value) {294putField(get("Id"), field, value);295}296297void collectRelevantVectors(Vector rv, String field) {298for (String ctx : context) {299Vector<String> v = getFieldVector(ctx, field);300if (v != null) {301for (String val : v) {302rv.add(expandFormat(val).replace('/', '\\'));303}304}305}306}307308void collectRelevantHashes(Hashtable rv, String field) {309for (String ctx : context) {310Hashtable v = (Hashtable)getField(ctx, field);311if (v != null) {312for (Enumeration e=v.keys(); e.hasMoreElements(); ) {313String key = (String)e.nextElement();314String val = (String)v.get(key);315addTo(rv, key, val);316}317}318}319}320321322Vector getDefines() {323Vector rv = new Vector();324collectRelevantVectors(rv, "Define");325return rv;326}327328Vector getIncludes() {329Vector rv = new Vector();330collectRelevantVectors(rv, "AbsoluteInclude");331rv.addAll(getSourceIncludes());332return rv;333}334335private Vector getSourceIncludes() {336Vector<String> rv = new Vector<String>();337String sourceBase = getFieldString(null, "SourceBase");338339// add relative alternate source include values:340String relativeAltSrcInclude =341getFieldString(null, "RelativeAltSrcInclude");342Vector<String> asri = new Vector<String>();343collectRelevantVectors(asri, "AltRelativeInclude");344for (String f : asri) {345rv.add(sourceBase + Util.sep + relativeAltSrcInclude +346Util.sep + f);347}348349Vector<String> ri = new Vector<String>();350collectRelevantVectors(ri, "RelativeInclude");351for (String f : ri) {352rv.add(sourceBase + Util.sep + f);353}354return rv;355}356357static Hashtable cfgData = new Hashtable();358static Hashtable globalData = new Hashtable();359360static boolean appliesToTieredBuild(String cfg) {361return (cfg != null &&362(cfg.startsWith("compiler1") ||363cfg.startsWith("compiler2")));364}365366// Filters out the IgnoreFile and IgnorePaths since they are367// handled specially for tiered builds.368static boolean appliesToTieredBuild(String cfg, String key) {369return (appliesToTieredBuild(cfg))&& (key != null && !key.startsWith("Ignore"));370}371372static String getTieredBuildCfg(String cfg) {373assert appliesToTieredBuild(cfg) : "illegal configuration " + cfg;374return "tiered" + cfg.substring(9);375}376377static Object getField(String cfg, String field) {378if (cfg == null) {379return globalData.get(field);380}381382Hashtable ht = (Hashtable)cfgData.get(cfg);383return ht == null ? null : ht.get(field);384}385386static String getFieldString(String cfg, String field) {387return (String)getField(cfg, field);388}389390static Vector getFieldVector(String cfg, String field) {391return (Vector)getField(cfg, field);392}393394static void putField(String cfg, String field, Object value) {395putFieldImpl(cfg, field, value);396if (appliesToTieredBuild(cfg, field)) {397putFieldImpl(getTieredBuildCfg(cfg), field, value);398}399}400401private static void putFieldImpl(String cfg, String field, Object value) {402if (cfg == null) {403globalData.put(field, value);404return;405}406407Hashtable ht = (Hashtable)cfgData.get(cfg);408if (ht == null) {409ht = new Hashtable();410cfgData.put(cfg, ht);411}412413ht.put(field, value);414}415416static Object getFieldHash(String cfg, String field, String name) {417Hashtable ht = (Hashtable)getField(cfg, field);418419return ht == null ? null : ht.get(name);420}421422static void putFieldHash(String cfg, String field, String name, Object val) {423putFieldHashImpl(cfg, field, name, val);424if (appliesToTieredBuild(cfg, field)) {425putFieldHashImpl(getTieredBuildCfg(cfg), field, name, val);426}427}428429private static void putFieldHashImpl(String cfg, String field, String name, Object val) {430Hashtable ht = (Hashtable)getField(cfg, field);431432if (ht == null) {433ht = new Hashtable();434putFieldImpl(cfg, field, ht);435}436437ht.put(name, val);438}439440static void addFieldVector(String cfg, String field, String element) {441addFieldVectorImpl(cfg, field, element);442if (appliesToTieredBuild(cfg, field)) {443addFieldVectorImpl(getTieredBuildCfg(cfg), field, element);444}445}446447private static void addFieldVectorImpl(String cfg, String field, String element) {448Vector v = (Vector)getField(cfg, field);449450if (v == null) {451v = new Vector();452putFieldImpl(cfg, field, v);453}454455v.add(element);456}457458String expandFormat(String format) {459if (format == null) {460return null;461}462463if (format.indexOf('%') == -1) {464return format;465}466467StringBuffer sb = new StringBuffer();468int len = format.length();469for (int i=0; i<len; i++) {470char ch = format.charAt(i);471if (ch == '%') {472char ch1 = format.charAt(i+1);473switch (ch1) {474case '%':475sb.append(ch1);476break;477case 'b':478sb.append(build());479break;480case 'f':481sb.append(flavour());482break;483default:484sb.append(ch);485sb.append(ch1);486}487i++;488} else {489sb.append(ch);490}491}492493return sb.toString();494}495}496497abstract class GenericDebugConfig extends BuildConfig {498abstract String getOptFlag();499500protected void init(Vector includes, Vector defines) {501defines.add("_DEBUG");502defines.add("ASSERT");503504super.init(includes, defines);505506getV("CompilerFlags").addAll(getCI().getDebugCompilerFlags(getOptFlag()));507getV("LinkerFlags").addAll(getCI().getDebugLinkerFlags());508}509}510511abstract class GenericDebugNonKernelConfig extends GenericDebugConfig {512protected void init(Vector includes, Vector defines) {513super.init(includes, defines);514getCI().getAdditionalNonKernelLinkerFlags(getV("LinkerFlags"));515}516}517518class C1DebugConfig extends GenericDebugNonKernelConfig {519String getOptFlag() {520return getCI().getNoOptFlag();521}522523C1DebugConfig() {524initNames("compiler1", "debug", "jvm.dll");525init(getIncludes(), getDefines());526}527}528529class C1FastDebugConfig extends GenericDebugNonKernelConfig {530String getOptFlag() {531return getCI().getOptFlag();532}533534C1FastDebugConfig() {535initNames("compiler1", "fastdebug", "jvm.dll");536init(getIncludes(), getDefines());537}538}539540class C2DebugConfig extends GenericDebugNonKernelConfig {541String getOptFlag() {542return getCI().getNoOptFlag();543}544545C2DebugConfig() {546initNames("compiler2", "debug", "jvm.dll");547init(getIncludes(), getDefines());548}549}550551class C2FastDebugConfig extends GenericDebugNonKernelConfig {552String getOptFlag() {553return getCI().getOptFlag();554}555556C2FastDebugConfig() {557initNames("compiler2", "fastdebug", "jvm.dll");558init(getIncludes(), getDefines());559}560}561562class TieredDebugConfig extends GenericDebugNonKernelConfig {563String getOptFlag() {564return getCI().getNoOptFlag();565}566567TieredDebugConfig() {568initNames("tiered", "debug", "jvm.dll");569init(getIncludes(), getDefines());570}571}572573class TieredFastDebugConfig extends GenericDebugNonKernelConfig {574String getOptFlag() {575return getCI().getOptFlag();576}577578TieredFastDebugConfig() {579initNames("tiered", "fastdebug", "jvm.dll");580init(getIncludes(), getDefines());581}582}583584abstract class ProductConfig extends BuildConfig {585protected void init(Vector includes, Vector defines) {586defines.add("NDEBUG");587defines.add("PRODUCT");588589super.init(includes, defines);590591getV("CompilerFlags").addAll(getCI().getProductCompilerFlags());592getV("LinkerFlags").addAll(getCI().getProductLinkerFlags());593}594}595596class C1ProductConfig extends ProductConfig {597C1ProductConfig() {598initNames("compiler1", "product", "jvm.dll");599init(getIncludes(), getDefines());600}601}602603class C2ProductConfig extends ProductConfig {604C2ProductConfig() {605initNames("compiler2", "product", "jvm.dll");606init(getIncludes(), getDefines());607}608}609610class TieredProductConfig extends ProductConfig {611TieredProductConfig() {612initNames("tiered", "product", "jvm.dll");613init(getIncludes(), getDefines());614}615}616617618abstract class CompilerInterface {619abstract Vector getBaseCompilerFlags(Vector defines, Vector includes, String outDir);620abstract Vector getBaseLinkerFlags(String outDir, String outDll, String platformName);621abstract Vector getDebugCompilerFlags(String opt);622abstract Vector getDebugLinkerFlags();623abstract void getAdditionalNonKernelLinkerFlags(Vector rv);624abstract Vector getProductCompilerFlags();625abstract Vector getProductLinkerFlags();626abstract String getOptFlag();627abstract String getNoOptFlag();628abstract String makeCfgName(String flavourBuild, String platformName);629630void addAttr(Vector receiver, String attr, String value) {631receiver.add(attr); receiver.add(value);632}633void extAttr(Vector receiver, String attr, String value) {634int attr_pos=receiver.indexOf(attr) ;635if ( attr_pos == -1) {636// If attr IS NOT present in the Vector - add it637receiver.add(attr); receiver.add(value);638} else {639// If attr IS present in the Vector - append value to it640receiver.set(attr_pos+1,receiver.get(attr_pos+1)+value);641}642}643}644645646