Tue, 08 Dec 2009 09:16:34 -0800
Merge
1.1 --- a/make/Makefile Thu Dec 03 12:53:12 2009 -0800 1.2 +++ b/make/Makefile Tue Dec 08 09:16:34 2009 -0800 1.3 @@ -133,6 +133,23 @@ 1.4 ANT_JAVA_HOME = JAVA_HOME=$(ALT_BOOTDIR) 1.5 endif 1.6 1.7 +# To facilitate bootstrapping, much of langtools can be compiled with (just) 1.8 +# a boot JDK. However, some source files need to be compiled against 1.9 +# new JDK API. In a bootstrap build, an import JDK may not be available, 1.10 +# so build.xml can also build against the source files in a jdk repo, 1.11 +# in which case it will automatically generate stub files for the new JDK API. 1.12 +ifdef JDK_TOPDIR 1.13 + ANT_OPTIONS += -Dimport.jdk=$(JDK_TOPDIR) 1.14 +else 1.15 + ifdef ALT_JDK_TOPDIR 1.16 + ANT_OPTIONS += -Dimport.jdk=$(ALT_JDK_TOPDIR) 1.17 + else 1.18 + ifdef ALT_JDK_IMPORT_DIR 1.19 + ANT_OPTIONS += -Dimport.jdk=$(ALT_JDK_IMPORT_DIR) 1.20 + endif 1.21 + endif 1.22 +endif 1.23 + 1.24 ifdef ALT_OUTPUTDIR 1.25 OUTPUTDIR = $(ALT_OUTPUTDIR) 1.26 ANT_OPTIONS += -Dbuild.dir=$(ALT_OUTPUTDIR)/build
2.1 --- a/make/build.properties Thu Dec 03 12:53:12 2009 -0800 2.2 +++ b/make/build.properties Tue Dec 08 09:16:34 2009 -0800 2.3 @@ -148,6 +148,13 @@ 2.4 2.5 # 2.6 2.7 +# The following files require the import JDK to be available 2.8 +require.import.jdk.files = 2.9 + 2.10 +# The following files in the import jdk source directory are required 2.11 +# in order to compile the files defined in ${require.import.jdk.files} 2.12 +import.jdk.stub.files = 2.13 + 2.14 # The following value is used by the main jtreg target. 2.15 # An empty value means all tests 2.16 # Override as desired to run a specific set of tests
3.1 --- a/make/build.xml Thu Dec 03 12:53:12 2009 -0800 3.2 +++ b/make/build.xml Tue Dec 08 09:16:34 2009 -0800 3.3 @@ -56,6 +56,7 @@ 3.4 <property name="build.coverage.dir" location="${build.dir}/coverage"/> 3.5 <property name="build.classes.dir" location="${build.dir}/classes"/> 3.6 <property name="build.gensrc.dir" location="${build.dir}/gensrc"/> 3.7 + <property name="build.genstubs.dir" location="${build.dir}/genstubs"/> 3.8 <property name="build.javadoc.dir" location="${build.dir}/javadoc"/> 3.9 <property name="build.jtreg.dir" location="${build.dir}/jtreg"/> 3.10 <property name="build.toolclasses.dir" location="${build.dir}/toolclasses"/> 3.11 @@ -93,6 +94,41 @@ 3.12 <isset property="target.java.home"/> 3.13 </condition> 3.14 3.15 + <!-- Logic for handling access import jdk classes, if available. 3.16 + import.jdk should be unset, or set to jdk home (to use rt.jar) 3.17 + or to jdk repo (to use src/share/classes). 3.18 + Based on the value, if any, set up default values for javac's sourcepath, 3.19 + classpath and bootclasspath. Note: the default values are overridden 3.20 + in the build-bootstrap-classes macro. --> 3.21 + 3.22 + <available property="import.jdk.src.dir" value="${import.jdk}/src/share/classes" 3.23 + filepath="${import.jdk}/src/share/classes" file="java/nio/file/Path.java"/> 3.24 + <available property="import.jdk.jar" value="${import.jdk}/jre/lib/rt.jar" 3.25 + ignoresystemclasses="true" 3.26 + classpath="${import.jdk}/jre/lib/rt.jar" classname="java.nio.file.Path"/> 3.27 + 3.28 + <condition property="javac.sourcepath" value="${build.genstubs.dir}" else=""> 3.29 + <isset property="import.jdk.src.dir"/> 3.30 + </condition> 3.31 + 3.32 + <property name="javac.classpath" value=""/> 3.33 + 3.34 + <condition property="javac.bootclasspath.opt" 3.35 + value="-Xbootclasspath:${build.classes.dir}:${import.jdk.jar}" 3.36 + else="-Xbootclasspath/p:${build.classes.dir}"> 3.37 + <isset property="import.jdk.jar"/> 3.38 + </condition> 3.39 + 3.40 + <condition property="exclude.files" value="" else="${require.import.jdk.files}"> 3.41 + <isset property="import.jdk"/> 3.42 + </condition> 3.43 + 3.44 + <!-- for debugging --> 3.45 + <target name="check-import.jdk"> 3.46 + <echo message="import.jdk: ${import.jdk}"/> 3.47 + <echo message="import.jdk.jar: ${import.jdk.jar}"/> 3.48 + <echo message="import.jdk.src.dir: ${import.jdk.src.dir}"/> 3.49 + </target> 3.50 3.51 <!-- Standard target to build deliverables for JDK build. --> 3.52 3.53 @@ -108,11 +144,17 @@ 3.54 <zip file="${dist.lib.dir}/src.zip" basedir="${src.classes.dir}"/> 3.55 </target> 3.56 3.57 - <target name="build-bootstrap-tools" depends="build-bootstrap-javac,build-bootstrap-javadoc,build-bootstrap-doclets,build-bootstrap-javah"/> 3.58 + <target name="build-bootstrap-tools" 3.59 + depends="build-bootstrap-javac,build-bootstrap-javadoc,build-bootstrap-doclets,build-bootstrap-javah" 3.60 + /> 3.61 3.62 - <target name="build-all-tools" depends="build-javac,build-javadoc,build-doclets,build-javah,build-javap,build-apt"/> 3.63 + <target name="build-all-tools" 3.64 + depends="build-javac,build-javadoc,build-doclets,build-javah,build-javap,build-apt" 3.65 + /> 3.66 3.67 - <target name="build-all-classes" depends="build-classes-javac,build-classes-javadoc,build-classes-doclets,build-classes-javah,build-classes-javap,build-classes-apt"/> 3.68 + <target name="build-all-classes" depends="build-bootstrap-javac,-create-import-jdk-stubs"> 3.69 + <build-classes includes="${javac.includes} ${javadoc.includes} ${doclets.includes} ${javah.includes} ${javap.includes} ${apt.includes}"/> 3.70 + </target> 3.71 3.72 <!-- clean --> 3.73 3.74 @@ -188,23 +230,27 @@ 3.75 3.76 <!-- javac targets --> 3.77 3.78 - <target name="build-bootstrap-javac" depends="-def-build-bootstrap-tool"> 3.79 - <build-bootstrap-tool name="javac" includes="${javac.includes}"/> 3.80 + <target name="build-bootstrap-javac" 3.81 + depends="-def-build-bootstrap-classes,-def-build-bootstrap-jar,-def-build-bootstrap-tool"> 3.82 + <build-bootstrap-classes includes="${javac.includes}"/> 3.83 + <build-bootstrap-jar name="javac" includes="${javac.includes}"/> 3.84 + <build-bootstrap-tool name="javac"/> 3.85 </target> 3.86 3.87 - <target name="build-classes-javac" depends="build-bootstrap-javac"> 3.88 - <build-classes name="javac" includes="${javac.includes}"/> 3.89 + <target name="build-classes-javac" depends="build-bootstrap-javac,-create-import-jdk-stubs"> 3.90 + <build-classes includes="${javac.includes}"/> 3.91 </target> 3.92 3.93 - <target name="build-javac" depends="build-bootstrap-javac"> 3.94 - <build-tool name="javac" includes="${javac.includes}"/> 3.95 + <target name="build-javac" depends="build-classes-javac"> 3.96 + <build-jar name="javac" includes="${javac.includes}"/> 3.97 + <build-tool name="javac"/> 3.98 </target> 3.99 3.100 <target name="javadoc-javac" depends="build-javac,-def-javadoc-tool"> 3.101 <javadoc-tool name="javac" includes="${javac.includes}" options="${javadoc.jls3.option}"/> 3.102 </target> 3.103 3.104 - <target name="jtreg-javac" depends="build-javac,-def-jtreg"> 3.105 + <target name="jtreg-javac" depends="build-javac,build-javap,-def-jtreg"> 3.106 <jtreg-tool name="javac" tests="${javac.tests}"/> 3.107 </target> 3.108 3.109 @@ -217,19 +263,20 @@ 3.110 <!-- javadoc targets --> 3.111 3.112 <target name="build-bootstrap-javadoc" depends="build-bootstrap-javac"> 3.113 - <build-bootstrap-tool name="javadoc" 3.114 - includes="${javadoc.includes}" 3.115 - jarclasspath="javac.jar doclets.jar"/> 3.116 + <build-bootstrap-classes includes="${javadoc.includes}"/> 3.117 + <build-bootstrap-jar name="javadoc" includes="${javadoc.includes}" 3.118 + jarclasspath="javac.jar doclets.jar"/> 3.119 + <build-bootstrap-tool name="javadoc"/> 3.120 </target> 3.121 3.122 <target name="build-classes-javadoc" depends="build-classes-javac"> 3.123 - <build-classes name="javadoc" includes="${javadoc.includes}"/> 3.124 + <build-classes includes="${javadoc.includes}"/> 3.125 </target> 3.126 3.127 - <target name="build-javadoc" depends="build-javac"> 3.128 - <build-tool name="javadoc" 3.129 - includes="${javadoc.includes}" 3.130 + <target name="build-javadoc" depends="build-javac,build-classes-javadoc"> 3.131 + <build-jar name="javadoc" includes="${javadoc.includes}" 3.132 jarclasspath="javac.jar doclets.jar"/> 3.133 + <build-tool name="javadoc"/> 3.134 </target> 3.135 3.136 <target name="javadoc-javadoc" depends="build-javadoc,-def-javadoc-tool"> 3.137 @@ -249,21 +296,19 @@ 3.138 <!-- doclets targets --> 3.139 3.140 <target name="build-bootstrap-doclets" depends="build-bootstrap-javadoc,-def-build-bootstrap-jar"> 3.141 - <build-bootstrap-jar name="doclets" 3.142 - includes="${doclets.includes}" 3.143 - jarmainclass="com.sun.tools.javadoc.Main" 3.144 - jarclasspath="javadoc.jar"/> 3.145 + <build-bootstrap-classes includes="${doclets.includes}"/> 3.146 + <build-bootstrap-jar name="doclets" includes="${doclets.includes}" 3.147 + jarmainclass="com.sun.tools.javadoc.Main" 3.148 + jarclasspath="javadoc.jar"/> 3.149 </target> 3.150 3.151 <target name="build-classes-doclets" depends="build-classes-javadoc"> 3.152 - <build-classes name="doclets" includes="${doclets.includes}"/> 3.153 + <build-classes includes="${doclets.includes}"/> 3.154 </target> 3.155 3.156 - <target name="build-doclets" depends="build-javadoc"> 3.157 + <target name="build-doclets" depends="build-javadoc,build-classes-doclets"> 3.158 <!-- just jar, no bin for doclets --> 3.159 - <build-jar name="doclets" 3.160 - includes="${doclets.includes}" 3.161 - jarclasspath="javadoc.jar"/> 3.162 + <build-jar name="doclets" includes="${doclets.includes}" jarclasspath="javadoc.jar"/> 3.163 </target> 3.164 3.165 <!-- (no javadoc for doclets) --> 3.166 @@ -281,19 +326,19 @@ 3.167 <!-- javah targets --> 3.168 3.169 <target name="build-bootstrap-javah" depends="build-bootstrap-javadoc"> 3.170 - <build-bootstrap-tool name="javah" 3.171 - includes="${javah.includes}" 3.172 - jarclasspath="javadoc.jar doclets.jar javac.jar"/> 3.173 + <build-bootstrap-classes includes="${javah.includes}"/> 3.174 + <build-bootstrap-jar name="javah" includes="${javah.includes}" 3.175 + jarclasspath="javadoc.jar doclets.jar javac.jar"/> 3.176 + <build-bootstrap-tool name="javah"/> 3.177 </target> 3.178 3.179 - <target name="build-javah" depends="build-javac"> 3.180 - <build-tool name="javah" 3.181 - includes="${javah.includes}" 3.182 - jarclasspath="javac.jar"/> 3.183 + <target name="build-javah" depends="build-javac,build-classes-javah"> 3.184 + <build-jar name="javah" includes="${javah.includes}" jarclasspath="javac.jar"/> 3.185 + <build-tool name="javah"/> 3.186 </target> 3.187 3.188 <target name="build-classes-javah" depends="build-classes-javadoc"> 3.189 - <build-classes name="javah" includes="${javah.includes}"/> 3.190 + <build-classes includes="${javah.includes}"/> 3.191 </target> 3.192 3.193 <!-- (no javadoc for javah) --> 3.194 @@ -310,21 +355,23 @@ 3.195 3.196 <!-- javap targets --> 3.197 3.198 - <target name="build-bootstrap-javap" depends="-def-build-bootstrap-tool"> 3.199 - <build-bootstrap-tool name="javap" 3.200 - includes="${javap.includes}" 3.201 - jarmainclass="sun.tools.javap.Main"/> 3.202 + <target name="build-bootstrap-javap" 3.203 + depends="-def-build-bootstrap-classes,-def-build-bootstrap-jar,-def-build-bootstrap-tool"> 3.204 + <build-bootstrap-classes includes="${javap.includes}"/> 3.205 + <build-bootstrap-jar name="javap" includes="${javap.includes}" 3.206 + jarmainclass="sun.tools.javap.Main"/> 3.207 + <build-bootstrap-tool name="javap"/> 3.208 </target> 3.209 3.210 <target name="build-classes-javap" depends="build-classes-javac"> 3.211 - <build-classes name="javap" includes="${javap.includes}"/> 3.212 + <build-classes includes="${javap.includes}"/> 3.213 </target> 3.214 3.215 - <target name="build-javap" depends="build-javac"> 3.216 - <build-tool name="javap" 3.217 - includes="${javap.includes}" 3.218 + <target name="build-javap" depends="build-javac,build-classes-javap"> 3.219 + <build-jar name="javap" includes="${javap.includes}" 3.220 jarmainclass="com.sun.tools.javap.Main" 3.221 jarclasspath="javac.jar"/> 3.222 + <build-tool name="javap"/> 3.223 </target> 3.224 3.225 <!-- (no javadoc for javap) --> 3.226 @@ -342,19 +389,19 @@ 3.227 <!-- apt targets --> 3.228 3.229 <target name="build-bootstrap-apt" depends="build-bootstrap-javac"> 3.230 - <build-bootstrap-tool name="apt" 3.231 - includes="${apt.includes}" 3.232 - jarclasspath="javac.jar"/> 3.233 + <build-bootstrap-classes includes="${apt.includes}"/> 3.234 + <build-bootstrap-jar name="apt" includes="${apt.includes}" 3.235 + jarclasspath="javac.jar"/> 3.236 + <build-bootstrap-tool name="apt"/> 3.237 </target> 3.238 3.239 - <target name="build-apt" depends="build-javac"> 3.240 - <build-tool name="apt" 3.241 - includes="${apt.includes}" 3.242 - jarclasspath="javac.jar"/> 3.243 + <target name="build-apt" depends="build-javac,build-classes-apt"> 3.244 + <build-jar name="apt" includes="${apt.includes}" jarclasspath="javac.jar"/> 3.245 + <build-tool name="apt"/> 3.246 </target> 3.247 3.248 <target name="build-classes-apt" depends="build-classes-javac"> 3.249 - <build-classes name="apt" includes="${apt.includes}"/> 3.250 + <build-classes includes="${apt.includes}"/> 3.251 </target> 3.252 3.253 <target name="javadoc-apt" depends="build-apt,-def-javadoc-tool"> 3.254 @@ -372,6 +419,17 @@ 3.255 3.256 <target name="apt" depends="build-apt,jtreg-apt,findbugs-apt"/> 3.257 3.258 + <!-- Create import JDK stubs --> 3.259 + 3.260 + <target name="-create-import-jdk-stubs" depends="-def-genstubs" if="import.jdk.src.dir"> 3.261 + <mkdir dir="${build.genstubs.dir}"/> 3.262 + <genstubs 3.263 + srcdir="${import.jdk.src.dir}" destdir="${build.genstubs.dir}" 3.264 + includes="${import.jdk.stub.files}" 3.265 + fork="true" classpath="${build.toolclasses.dir}:${build.bootstrap.dir}/classes:${ant.home}/lib/ant.jar" 3.266 + /> 3.267 + </target> 3.268 + 3.269 <!-- Check targets --> 3.270 3.271 <target name="-check-boot.java.home" depends="-def-check"> 3.272 @@ -396,40 +454,12 @@ 3.273 3.274 <!-- Ant macro and preset defs --> 3.275 3.276 - <target name="-def-build-tool" depends="-def-build-jar"> 3.277 + <target name="-def-build-tool"> 3.278 <macrodef name="build-tool"> 3.279 <attribute name="name"/> 3.280 - <attribute name="includes"/> 3.281 - <attribute name="excludes" default="**/package-info.java"/> 3.282 <attribute name="bin.dir" default="${dist.bin.dir}"/> 3.283 - <attribute name="classes.dir" default="${build.classes.dir}"/> 3.284 - <attribute name="gensrc.dir" default="${build.gensrc.dir}"/> 3.285 - <attribute name="lib.dir" default="${dist.lib.dir}"/> 3.286 <attribute name="java" default="${launcher.java}"/> 3.287 - <attribute name="javac.bootclasspath" default="${build.bootstrap.dir}/classes"/> 3.288 - <attribute name="javac.java.home" default="${boot.java.home}"/> 3.289 - <attribute name="javac.source" default="${javac.source}"/> 3.290 - <attribute name="javac.target" default="${javac.target}"/> 3.291 - <attribute name="jarmainclass" default="com.sun.tools.@{name}.Main"/> 3.292 - <attribute name="jarclasspath" default=""/> 3.293 - <attribute name="release" default="${release}"/> 3.294 - <attribute name="full.version" default="${full.version}"/> 3.295 <sequential> 3.296 - <build-jar 3.297 - name="@{name}" 3.298 - gensrc.dir="@{gensrc.dir}" 3.299 - classes.dir="@{classes.dir}" 3.300 - lib.dir="@{lib.dir}" 3.301 - includes="@{includes}" 3.302 - excludes="@{excludes}" 3.303 - jarmainclass="@{jarmainclass}" 3.304 - jarclasspath="@{jarclasspath}" 3.305 - release="@{release}" 3.306 - full.version="@{full.version}" 3.307 - javac.bootclasspath="@{javac.bootclasspath}" 3.308 - javac.source="@{javac.source}" 3.309 - javac.target="@{javac.target}" 3.310 - /> 3.311 <mkdir dir="@{bin.dir}"/> 3.312 <copy file="${src.bin.dir}/launcher.sh-template" tofile="@{bin.dir}/@{name}"> 3.313 <filterset begintoken="#" endtoken="#"> 3.314 @@ -442,35 +472,15 @@ 3.315 </macrodef> 3.316 </target> 3.317 3.318 - <target name="-def-build-jar" depends="-def-build-classes"> 3.319 + <target name="-def-build-jar"> 3.320 <macrodef name="build-jar"> 3.321 <attribute name="name"/> 3.322 <attribute name="includes"/> 3.323 - <attribute name="excludes" default="**/package-info.java"/> 3.324 <attribute name="classes.dir" default="${build.classes.dir}"/> 3.325 - <attribute name="gensrc.dir" default="${build.gensrc.dir}"/> 3.326 <attribute name="lib.dir" default="${dist.lib.dir}"/> 3.327 - <attribute name="javac.bootclasspath" default="${build.bootstrap.dir}/classes"/> 3.328 - <attribute name="javac.java.home" default="${boot.java.home}"/> 3.329 - <attribute name="javac.source" default="${javac.source}"/> 3.330 - <attribute name="javac.target" default="${javac.target}"/> 3.331 <attribute name="jarmainclass" default="com.sun.tools.@{name}.Main"/> 3.332 <attribute name="jarclasspath" default=""/> 3.333 - <attribute name="release" default="${release}"/> 3.334 - <attribute name="full.version" default="${full.version}"/> 3.335 <sequential> 3.336 - <build-classes 3.337 - name="@{name}" 3.338 - gensrc.dir="@{gensrc.dir}" 3.339 - classes.dir="@{classes.dir}" 3.340 - includes="@{includes}" 3.341 - excludes="@{excludes}" 3.342 - release="@{release}" 3.343 - full.version="@{full.version}" 3.344 - javac.bootclasspath="@{javac.bootclasspath}" 3.345 - javac.source="@{javac.source}" 3.346 - javac.target="@{javac.target}" 3.347 - /> 3.348 <mkdir dir="@{lib.dir}"/> 3.349 <jar destfile="@{lib.dir}/@{name}.jar" 3.350 basedir="@{classes.dir}" 3.351 @@ -486,18 +496,24 @@ 3.352 3.353 <target name="-def-build-classes" depends="-def-pcompile"> 3.354 <macrodef name="build-classes"> 3.355 - <attribute name="name"/> 3.356 <attribute name="includes"/> 3.357 - <attribute name="excludes" default="**/package-info.java"/> 3.358 + <attribute name="excludes" default="${exclude.files} **/package-info.java"/> 3.359 <attribute name="classes.dir" default="${build.classes.dir}"/> 3.360 <attribute name="gensrc.dir" default="${build.gensrc.dir}"/> 3.361 <attribute name="javac.bootclasspath" default="${build.bootstrap.dir}/classes"/> 3.362 - <attribute name="javac.java.home" default="${boot.java.home}"/> 3.363 - <attribute name="javac.source" default="${javac.source}"/> 3.364 - <attribute name="javac.target" default="${javac.target}"/> 3.365 + <attribute name="bootclasspath.opt" default="${javac.bootclasspath.opt}"/> 3.366 + <attribute name="classpath" default="${javac.classpath}"/> 3.367 + <attribute name="sourcepath" default="${javac.sourcepath}"/> 3.368 + <attribute name="java.home" default="${boot.java.home}"/> 3.369 + <attribute name="source" default="${javac.source}"/> 3.370 + <attribute name="target" default="${javac.target}"/> 3.371 <attribute name="release" default="${release}"/> 3.372 <attribute name="full.version" default="${full.version}"/> 3.373 <sequential> 3.374 + <echo level="verbose" message="build-classes: excludes=@{excludes}"/> 3.375 + <echo level="verbose" message="build-classes: bootclasspath.opt=@{bootclasspath.opt}"/> 3.376 + <echo level="verbose" message="build-classes: classpath=@{classpath}"/> 3.377 + <echo level="verbose" message="build-classes: sourcepath=@{sourcepath}"/> 3.378 <mkdir dir="@{gensrc.dir}"/> 3.379 <mkdir dir="@{classes.dir}"/> 3.380 <pcompile srcdir="${src.classes.dir}" 3.381 @@ -516,39 +532,28 @@ 3.382 destdir="@{gensrc.dir}" 3.383 includes="**/*.properties"/> 3.384 <javac fork="true" 3.385 - executable="@{javac.java.home}/bin/javac" 3.386 - srcdir="@{gensrc.dir}" 3.387 - destdir="@{classes.dir}" 3.388 - includes="@{includes}" 3.389 - sourcepath="" 3.390 - includeAntRuntime="no" 3.391 - source="@{javac.source}" 3.392 - target="@{javac.target}"> 3.393 - <compilerarg value="-J-Xbootclasspath/p:@{javac.bootclasspath}"/> 3.394 - <compilerarg line="${javac.version.opt}"/> 3.395 - <compilerarg line="-Xlint"/> 3.396 - </javac> 3.397 - <javac fork="true" 3.398 - executable="@{javac.java.home}/bin/javac" 3.399 - srcdir="${src.classes.dir}" 3.400 + executable="@{java.home}/bin/javac" 3.401 + srcdir="${src.classes.dir}:@{gensrc.dir}" 3.402 destdir="@{classes.dir}" 3.403 includes="@{includes}" 3.404 excludes="@{excludes}" 3.405 - sourcepath="" 3.406 + sourcepath="@{sourcepath}" 3.407 + classpath="@{classpath}" 3.408 includeAntRuntime="no" 3.409 - source="@{javac.source}" 3.410 - target="@{javac.target}" 3.411 + source="@{source}" 3.412 + target="@{target}" 3.413 debug="${javac.debug}" 3.414 debuglevel="${javac.debuglevel}"> 3.415 + <compilerarg value="-implicit:none"/> 3.416 + <compilerarg value="-Xprefer:source"/> 3.417 <compilerarg value="-J-Xbootclasspath/p:@{javac.bootclasspath}"/> 3.418 - <compilerarg value="-Xbootclasspath/p:@{classes.dir}"/> 3.419 + <compilerarg line="@{bootclasspath.opt}"/> 3.420 <compilerarg line="${javac.no.jdk.warnings}"/> 3.421 <compilerarg line="${javac.version.opt}"/> 3.422 <compilerarg line="${javac.lint.opts}"/> 3.423 </javac> 3.424 <copy todir="@{classes.dir}"> 3.425 - <fileset dir="${src.classes.dir}"> 3.426 - <include name="@{includes}"/> 3.427 + <fileset dir="${src.classes.dir}" includes="@{includes}"> 3.428 <exclude name="**/*.java"/> 3.429 <exclude name="**/*.properties"/> 3.430 <exclude name="**/*-template"/> 3.431 @@ -562,30 +567,32 @@ 3.432 <target name="-def-build-bootstrap-tool" depends="-check-boot.java.home,-def-build-tool"> 3.433 <presetdef name="build-bootstrap-tool"> 3.434 <build-tool 3.435 - javac.source="${boot.javac.source}" 3.436 - javac.target="${boot.javac.target}" 3.437 - gensrc.dir="${build.bootstrap.dir}/gensrc" 3.438 - classes.dir="${build.bootstrap.dir}/classes" 3.439 bin.dir="${build.bootstrap.dir}/bin" 3.440 - lib.dir="${build.bootstrap.dir}/lib" 3.441 - java="${boot.java}" 3.442 - javac.bootclasspath="" 3.443 - release="${bootstrap.release}" 3.444 - full.version="${bootstrap.full.version}"/> 3.445 + java="${boot.java}"/> 3.446 </presetdef> 3.447 </target> 3.448 3.449 <target name="-def-build-bootstrap-jar" depends="-def-build-jar"> 3.450 <presetdef name="build-bootstrap-jar"> 3.451 <build-jar 3.452 - javac.source="${boot.javac.source}" 3.453 - javac.target="${boot.javac.target}" 3.454 + classes.dir="${build.bootstrap.dir}/classes" 3.455 + lib.dir="${build.bootstrap.dir}/lib"/> 3.456 + </presetdef> 3.457 + </target> 3.458 + 3.459 + <target name="-def-build-bootstrap-classes" depends="-def-build-classes"> 3.460 + <presetdef name="build-bootstrap-classes"> 3.461 + <build-classes 3.462 + source="${boot.javac.source}" 3.463 + target="${boot.javac.target}" 3.464 gensrc.dir="${build.bootstrap.dir}/gensrc" 3.465 classes.dir="${build.bootstrap.dir}/classes" 3.466 - lib.dir="${build.bootstrap.dir}/lib" 3.467 javac.bootclasspath="" 3.468 + bootclasspath.opt="-Xbootclasspath/p:${build.bootstrap.dir}/classes" 3.469 + sourcepath="" 3.470 release="${bootstrap.release}" 3.471 - full.version="${bootstrap.full.version}"/> 3.472 + full.version="${bootstrap.full.version}" 3.473 + excludes="${require.import.jdk.files} **/package-info.java"/> 3.474 </presetdef> 3.475 </target> 3.476 3.477 @@ -603,6 +610,20 @@ 3.478 classpath="${build.toolclasses.dir}/"/> 3.479 </target> 3.480 3.481 + <target name="-def-genstubs" depends="build-bootstrap-javac"> 3.482 + <mkdir dir="${build.toolclasses.dir}"/> 3.483 + <javac fork="true" 3.484 + source="${boot.javac.source}" 3.485 + target="${boot.javac.target}" 3.486 + executable="${boot.java.home}/bin/javac" 3.487 + srcdir="${make.tools.dir}/GenStubs" 3.488 + destdir="${build.toolclasses.dir}/" 3.489 + classpath="${build.bootstrap.dir}/classes:${ant.home}/lib/ant.jar"/> 3.490 + <taskdef name="genstubs" 3.491 + classname="GenStubs$$Ant" 3.492 + classpath="${build.toolclasses.dir}/"/> 3.493 + </target> 3.494 + 3.495 <target name="-def-javadoc-tool" depends="-check-target.java.home"> 3.496 <macrodef name="javadoc-tool"> 3.497 <attribute name="name"/> 3.498 @@ -764,7 +785,7 @@ 3.499 3.500 <!-- standard JDK target --> 3.501 <target name="sanity" 3.502 - description="display settings of congiguration values"> 3.503 + description="display settings of configuration values"> 3.504 <echo level="info">ant.home = ${ant.home}</echo> 3.505 <echo level="info">boot.java.home = ${boot.java.home}</echo> 3.506 <echo level="info">target.java.home = ${target.java.home}</echo>
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 4.2 +++ b/make/tools/GenStubs/GenStubs.java Tue Dec 08 09:16:34 2009 -0800 4.3 @@ -0,0 +1,392 @@ 4.4 +/* 4.5 + * Copyright 2009 Sun Microsystems, Inc. All Rights Reserved. 4.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4.7 + * 4.8 + * This code is free software; you can redistribute it and/or modify it 4.9 + * under the terms of the GNU General Public License version 2 only, as 4.10 + * published by the Free Software Foundation. Sun designates this 4.11 + * particular file as subject to the "Classpath" exception as provided 4.12 + * by Sun in the LICENSE file that accompanied this code. 4.13 + * 4.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 4.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 4.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 4.17 + * version 2 for more details (a copy is included in the LICENSE file that 4.18 + * accompanied this code). 4.19 + * 4.20 + * You should have received a copy of the GNU General Public License version 4.21 + * 2 along with this work; if not, write to the Free Software Foundation, 4.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 4.23 + * 4.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 4.25 + * CA 95054 USA or visit www.sun.com if you need additional information or 4.26 + * have any questions. 4.27 + */ 4.28 +import java.io.*; 4.29 +import java.util.*; 4.30 +import javax.tools.JavaFileObject; 4.31 +import javax.tools.StandardJavaFileManager; 4.32 +import javax.tools.StandardLocation; 4.33 + 4.34 +import org.apache.tools.ant.BuildException; 4.35 +import org.apache.tools.ant.DirectoryScanner; 4.36 +import org.apache.tools.ant.taskdefs.MatchingTask; 4.37 +import org.apache.tools.ant.types.Path; 4.38 +import org.apache.tools.ant.types.Reference; 4.39 + 4.40 + 4.41 +import com.sun.source.tree.CompilationUnitTree; 4.42 +import com.sun.source.util.JavacTask; 4.43 +import com.sun.tools.javac.api.JavacTool; 4.44 +import com.sun.tools.javac.code.Flags; 4.45 +import com.sun.tools.javac.code.TypeTags; 4.46 +import com.sun.tools.javac.tree.JCTree; 4.47 +import com.sun.tools.javac.tree.JCTree.JCBlock; 4.48 +import com.sun.tools.javac.tree.JCTree.JCCompilationUnit; 4.49 +import com.sun.tools.javac.tree.JCTree.JCLiteral; 4.50 +import com.sun.tools.javac.tree.JCTree.JCMethodDecl; 4.51 +import com.sun.tools.javac.tree.JCTree.JCModifiers; 4.52 +import com.sun.tools.javac.tree.JCTree.JCStatement; 4.53 +import com.sun.tools.javac.tree.JCTree.JCVariableDecl; 4.54 +import com.sun.tools.javac.tree.Pretty; 4.55 +import com.sun.tools.javac.tree.TreeTranslator; 4.56 + 4.57 +/** 4.58 + * Generate stub source files by removing implementation details from input files. 4.59 + * 4.60 + * This is a special purpose stub generator, specific to the needs of generating 4.61 + * stub files for JDK 7 API that are needed to compile langtools files that depend 4.62 + * on that API. The stub generator works by removing as much of the API source code 4.63 + * as possible without affecting the public signature, in order to reduce the 4.64 + * transitive closure of the API being referenced. The resulting stubs can be 4.65 + * put on the langtools sourcepath with -implicit:none to compile the langtools 4.66 + * files that depend on the JDK 7 API. 4.67 + * 4.68 + * Usage: 4.69 + * genstubs -s <outdir> -sourcepath <path> <classnames> 4.70 + * 4.71 + * The specified class names are looked up on the sourcepath, and corresponding 4.72 + * stubs are written to the source output directory. 4.73 + * 4.74 + * Classes are parsed into javac ASTs, then processed with a javac TreeTranslator 4.75 + * to remove implementation details, and written out in the source output directory. 4.76 + * Documentation comments and annotations are removed. Method bodies are removed 4.77 + * and methods are marked native. Private and package-private field definitions 4.78 + * have their initializers replace with 0, 0.0, false, null as appropriate. 4.79 + * 4.80 + * An Ant task, Main$Ant is also provided. Files are specified with an implicit 4.81 + * fileset, using srcdir as a base directory. The set of files to be included 4.82 + * is specified with an includes attribute or nested <includes> set. However, 4.83 + * unlike a normal fileset, an empty includes attribute means "no files" instead 4.84 + * of "all files". The Ant task also accepts "fork=true" and classpath attribute 4.85 + * or nested <classpath> element to run GenStubs in a separate VM with the specified 4.86 + * path. This is likely necessary if a JDK 7 parser is required to read the 4.87 + * JDK 7 input files. 4.88 + */ 4.89 + 4.90 +public class GenStubs { 4.91 + static class Fault extends Exception { 4.92 + private static final long serialVersionUID = 0; 4.93 + Fault(String message) { 4.94 + super(message); 4.95 + } 4.96 + Fault(String message, Throwable cause) { 4.97 + super(message); 4.98 + initCause(cause); 4.99 + } 4.100 + } 4.101 + 4.102 + public static void main(String[] args) { 4.103 + boolean ok = new GenStubs().run(args); 4.104 + if (!ok) 4.105 + System.exit(1); 4.106 + } 4.107 + 4.108 + boolean run(String... args) { 4.109 + File outdir = null; 4.110 + String sourcepath = null; 4.111 + List<String> classes = new ArrayList<String>(); 4.112 + for (ListIterator<String> iter = Arrays.asList(args).listIterator(); iter.hasNext(); ) { 4.113 + String arg = iter.next(); 4.114 + if (arg.equals("-s") && iter.hasNext()) 4.115 + outdir = new File(iter.next()); 4.116 + else if (arg.equals("-sourcepath") && iter.hasNext()) 4.117 + sourcepath = iter.next(); 4.118 + else if (arg.startsWith("-")) 4.119 + throw new IllegalArgumentException(arg); 4.120 + else { 4.121 + classes.add(arg); 4.122 + while (iter.hasNext()) 4.123 + classes.add(iter.next()); 4.124 + } 4.125 + } 4.126 + 4.127 + return run(sourcepath, outdir, classes); 4.128 + } 4.129 + 4.130 + boolean run(String sourcepath, File outdir, List<String> classes) { 4.131 + //System.err.println("run: sourcepath:" + sourcepath + " outdir:" + outdir + " classes:" + classes); 4.132 + if (sourcepath == null) 4.133 + throw new IllegalArgumentException("sourcepath not set"); 4.134 + if (outdir == null) 4.135 + throw new IllegalArgumentException("source output dir not set"); 4.136 + 4.137 + JavacTool tool = JavacTool.create(); 4.138 + StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null); 4.139 + 4.140 + try { 4.141 + fm.setLocation(StandardLocation.SOURCE_OUTPUT, Collections.singleton(outdir)); 4.142 + fm.setLocation(StandardLocation.SOURCE_PATH, splitPath(sourcepath)); 4.143 + List<JavaFileObject> files = new ArrayList<JavaFileObject>(); 4.144 + for (String c: classes) { 4.145 + JavaFileObject fo = fm.getJavaFileForInput( 4.146 + StandardLocation.SOURCE_PATH, c, JavaFileObject.Kind.SOURCE); 4.147 + if (fo == null) 4.148 + error("class not found: " + c); 4.149 + else 4.150 + files.add(fo); 4.151 + } 4.152 + 4.153 + JavacTask t = tool.getTask(null, fm, null, null, null, files); 4.154 + Iterable<? extends CompilationUnitTree> trees = t.parse(); 4.155 + for (CompilationUnitTree tree: trees) { 4.156 + makeStub(fm, tree); 4.157 + } 4.158 + } catch (IOException e) { 4.159 + error("IO error " + e, e); 4.160 + } 4.161 + 4.162 + return (errors == 0); 4.163 + } 4.164 + 4.165 + void makeStub(StandardJavaFileManager fm, CompilationUnitTree tree) throws IOException { 4.166 + CompilationUnitTree tree2 = new StubMaker().translate(tree); 4.167 + 4.168 + String className = fm.inferBinaryName(StandardLocation.SOURCE_PATH, tree.getSourceFile()); 4.169 + JavaFileObject fo = fm.getJavaFileForOutput(StandardLocation.SOURCE_OUTPUT, 4.170 + className, JavaFileObject.Kind.SOURCE, null); 4.171 + // System.err.println("Writing " + className + " to " + fo.getName()); 4.172 + Writer out = fo.openWriter(); 4.173 + try { 4.174 + new Pretty(out, true).printExpr((JCTree) tree2); 4.175 + } finally { 4.176 + out.close(); 4.177 + } 4.178 + } 4.179 + 4.180 + List<File> splitPath(String path) { 4.181 + List<File> list = new ArrayList<File>(); 4.182 + for (String p: path.split(File.pathSeparator)) { 4.183 + if (p.length() > 0) 4.184 + list.add(new File(p)); 4.185 + } 4.186 + return list; 4.187 + } 4.188 + 4.189 + void error(String message) { 4.190 + System.err.println(message); 4.191 + errors++; 4.192 + } 4.193 + 4.194 + void error(String message, Throwable cause) { 4.195 + error(message); 4.196 + } 4.197 + 4.198 + int errors; 4.199 + 4.200 + class StubMaker extends TreeTranslator { 4.201 + CompilationUnitTree translate(CompilationUnitTree tree) { 4.202 + return super.translate((JCCompilationUnit) tree); 4.203 + } 4.204 + 4.205 + /** 4.206 + * compilation units: remove javadoc comments 4.207 + * -- required, in order to remove @deprecated tags, since we 4.208 + * (separately) remove all annotations, including @Deprecated 4.209 + */ 4.210 + public void visitTopLevel(JCCompilationUnit tree) { 4.211 + super.visitTopLevel(tree); 4.212 + tree.docComments = Collections.emptyMap(); 4.213 + } 4.214 + 4.215 + /** 4.216 + * methods: remove method bodies, make methods native 4.217 + */ 4.218 + @Override 4.219 + public void visitMethodDef(JCMethodDecl tree) { 4.220 + tree.mods = translate(tree.mods); 4.221 + tree.restype = translate(tree.restype); 4.222 + tree.typarams = translateTypeParams(tree.typarams); 4.223 + tree.params = translateVarDefs(tree.params); 4.224 + tree.thrown = translate(tree.thrown); 4.225 + if (tree.restype != null && tree.body != null) { 4.226 + tree.mods.flags |= Flags.NATIVE; 4.227 + tree.body = null; 4.228 + } 4.229 + result = tree; 4.230 + } 4.231 + 4.232 + /** 4.233 + * modifiers: remove annotations 4.234 + */ 4.235 + @Override 4.236 + public void visitModifiers(JCModifiers tree) { 4.237 + tree.annotations = com.sun.tools.javac.util.List.nil(); 4.238 + result = tree; 4.239 + } 4.240 + 4.241 + /** 4.242 + * field definitions: replace initializers with 0, 0.0, false etc 4.243 + * when possible -- i.e. leave public, protected initializers alone 4.244 + */ 4.245 + @Override 4.246 + public void visitVarDef(JCVariableDecl tree) { 4.247 + tree.mods = translate(tree.mods); 4.248 + tree.vartype = translate(tree.vartype); 4.249 + if (tree.init != null) { 4.250 + if ((tree.mods.flags & (Flags.PUBLIC | Flags.PROTECTED)) != 0) 4.251 + tree.init = translate(tree.init); 4.252 + else { 4.253 + String t = tree.vartype.toString(); 4.254 + if (t.equals("boolean")) 4.255 + tree.init = new JCLiteral(TypeTags.BOOLEAN, 0) { }; 4.256 + else if (t.equals("byte")) 4.257 + tree.init = new JCLiteral(TypeTags.BYTE, 0) { }; 4.258 + else if (t.equals("char")) 4.259 + tree.init = new JCLiteral(TypeTags.CHAR, 0) { }; 4.260 + else if (t.equals("double")) 4.261 + tree.init = new JCLiteral(TypeTags.DOUBLE, 0.d) { }; 4.262 + else if (t.equals("float")) 4.263 + tree.init = new JCLiteral(TypeTags.FLOAT, 0.f) { }; 4.264 + else if (t.equals("int")) 4.265 + tree.init = new JCLiteral(TypeTags.INT, 0) { }; 4.266 + else if (t.equals("long")) 4.267 + tree.init = new JCLiteral(TypeTags.LONG, 0) { }; 4.268 + else if (t.equals("short")) 4.269 + tree.init = new JCLiteral(TypeTags.SHORT, 0) { }; 4.270 + else 4.271 + tree.init = new JCLiteral(TypeTags.BOT, null) { }; 4.272 + } 4.273 + } 4.274 + result = tree; 4.275 + } 4.276 + } 4.277 + 4.278 + //---------- Ant Invocation ------------------------------------------------ 4.279 + 4.280 + public static class Ant extends MatchingTask { 4.281 + private File srcDir; 4.282 + private File destDir; 4.283 + private boolean fork; 4.284 + private Path classpath; 4.285 + private String includes; 4.286 + 4.287 + public void setSrcDir(File dir) { 4.288 + this.srcDir = dir; 4.289 + } 4.290 + 4.291 + public void setDestDir(File dir) { 4.292 + this.destDir = dir; 4.293 + } 4.294 + 4.295 + public void setFork(boolean v) { 4.296 + this.fork = v; 4.297 + } 4.298 + 4.299 + public void setClasspath(Path cp) { 4.300 + if (classpath == null) 4.301 + classpath = cp; 4.302 + else 4.303 + classpath.append(cp); 4.304 + } 4.305 + 4.306 + public Path createClasspath() { 4.307 + if (classpath == null) { 4.308 + classpath = new Path(getProject()); 4.309 + } 4.310 + return classpath.createPath(); 4.311 + } 4.312 + 4.313 + public void setClasspathRef(Reference r) { 4.314 + createClasspath().setRefid(r); 4.315 + } 4.316 + 4.317 + public void setIncludes(String includes) { 4.318 + super.setIncludes(includes); 4.319 + this.includes = includes; 4.320 + } 4.321 + 4.322 + @Override 4.323 + public void execute() { 4.324 + if (includes != null && includes.trim().isEmpty()) 4.325 + return; 4.326 + 4.327 + DirectoryScanner s = getDirectoryScanner(srcDir); 4.328 + String[] files = s.getIncludedFiles(); 4.329 +// System.err.println("Ant.execute: srcDir " + srcDir); 4.330 +// System.err.println("Ant.execute: destDir " + destDir); 4.331 +// System.err.println("Ant.execute: files " + Arrays.asList(files)); 4.332 + 4.333 + files = filter(srcDir, destDir, files); 4.334 + if (files.length == 0) 4.335 + return; 4.336 + System.out.println("Generating " + files.length + " stub files to " + destDir); 4.337 + 4.338 + List<String> classNames = new ArrayList<String>(); 4.339 + for (String file: files) { 4.340 + classNames.add(file.replaceAll(".java$", "").replace('/', '.')); 4.341 + } 4.342 + 4.343 + if (!fork) { 4.344 + GenStubs m = new GenStubs(); 4.345 + boolean ok = m.run(srcDir.getPath(), destDir, classNames); 4.346 + if (!ok) 4.347 + throw new BuildException("genstubs failed"); 4.348 + } else { 4.349 + List<String> cmd = new ArrayList<String>(); 4.350 + String java_home = System.getProperty("java.home"); 4.351 + cmd.add(new File(new File(java_home, "bin"), "java").getPath()); 4.352 + if (classpath != null) 4.353 + cmd.add("-Xbootclasspath/p:" + classpath); 4.354 + cmd.add(GenStubs.class.getName()); 4.355 + cmd.add("-sourcepath"); 4.356 + cmd.add(srcDir.getPath()); 4.357 + cmd.add("-s"); 4.358 + cmd.add(destDir.getPath()); 4.359 + cmd.addAll(classNames); 4.360 + //System.err.println("GenStubs exec " + cmd); 4.361 + ProcessBuilder pb = new ProcessBuilder(cmd); 4.362 + pb.redirectErrorStream(true); 4.363 + try { 4.364 + Process p = pb.start(); 4.365 + BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream())); 4.366 + try { 4.367 + String line; 4.368 + while ((line = in.readLine()) != null) 4.369 + System.out.println(line); 4.370 + } finally { 4.371 + in.close(); 4.372 + } 4.373 + int rc = p.waitFor(); 4.374 + if (rc != 0) 4.375 + throw new BuildException("genstubs failed"); 4.376 + } catch (IOException e) { 4.377 + throw new BuildException("genstubs failed", e); 4.378 + } catch (InterruptedException e) { 4.379 + throw new BuildException("genstubs failed", e); 4.380 + } 4.381 + } 4.382 + } 4.383 + 4.384 + String[] filter(File srcDir, File destDir, String[] files) { 4.385 + List<String> results = new ArrayList<String>(); 4.386 + for (String f: files) { 4.387 + long srcTime = new File(srcDir, f).lastModified(); 4.388 + long destTime = new File(destDir, f).lastModified(); 4.389 + if (srcTime > destTime) 4.390 + results.add(f); 4.391 + } 4.392 + return results.toArray(new String[results.size()]); 4.393 + } 4.394 + } 4.395 +}
5.1 --- a/src/share/classes/com/sun/tools/classfile/Instruction.java Thu Dec 03 12:53:12 2009 -0800 5.2 +++ b/src/share/classes/com/sun/tools/classfile/Instruction.java Tue Dec 08 09:16:34 2009 -0800 5.3 @@ -106,9 +106,9 @@ 5.4 /** See {@link Kind#LOCAL_UBYTE}. */ 5.5 R visitLocalAndValue(Instruction instr, int index, int value, P p); 5.6 /** See {@link Kind#DYNAMIC}. */ 5.7 - R visitLookupSwitch(Instruction instr, int default_, int npairs, int[] matches, int[] offsets); 5.8 + R visitLookupSwitch(Instruction instr, int default_, int npairs, int[] matches, int[] offsets, P p); 5.9 /** See {@link Kind#DYNAMIC}. */ 5.10 - R visitTableSwitch(Instruction instr, int default_, int low, int high, int[] offsets); 5.11 + R visitTableSwitch(Instruction instr, int default_, int low, int high, int[] offsets, P p); 5.12 /** See {@link Kind#BYTE}, {@link Kind#SHORT}. */ 5.13 R visitValue(Instruction instr, int value, P p); 5.14 /** Instruction is unrecognized. */ 5.15 @@ -282,7 +282,7 @@ 5.16 for (int i = 0; i < values.length; i++) 5.17 values[i] = getInt(pad + 12 + 4 * i); 5.18 return visitor.visitTableSwitch( 5.19 - this, default_, low, high, values); 5.20 + this, default_, low, high, values, p); 5.21 } 5.22 case LOOKUPSWITCH: { 5.23 int pad = align(pc + 1) - pc; 5.24 @@ -295,7 +295,7 @@ 5.25 offsets[i] = getInt(pad + 12 + i * 8); 5.26 } 5.27 return visitor.visitLookupSwitch( 5.28 - this, default_, npairs, matches, offsets); 5.29 + this, default_, npairs, matches, offsets, p); 5.30 } 5.31 default: 5.32 throw new IllegalStateException();
6.1 --- a/src/share/classes/com/sun/tools/javac/code/Source.java Thu Dec 03 12:53:12 2009 -0800 6.2 +++ b/src/share/classes/com/sun/tools/javac/code/Source.java Tue Dec 08 09:16:34 2009 -0800 6.3 @@ -110,9 +110,6 @@ 6.4 } 6.5 6.6 /** Allow encoding errors, giving only warnings. */ 6.7 - public boolean allowStringsInSwitch() { 6.8 - return compareTo(JDK1_7) >= 0; 6.9 - } 6.10 public boolean allowEncodingErrors() { 6.11 return compareTo(JDK1_6) < 0; 6.12 } 6.13 @@ -168,6 +165,9 @@ 6.14 public boolean allowUnderscoresInLiterals() { 6.15 return compareTo(JDK1_7) >= 0; 6.16 } 6.17 + public boolean allowStringsInSwitch() { 6.18 + return compareTo(JDK1_7) >= 0; 6.19 + } 6.20 public static SourceVersion toSourceVersion(Source source) { 6.21 switch(source) { 6.22 case JDK1_2:
7.1 --- a/src/share/classes/com/sun/tools/javac/comp/Lower.java Thu Dec 03 12:53:12 2009 -0800 7.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Lower.java Tue Dec 08 09:16:34 2009 -0800 7.3 @@ -3117,7 +3117,6 @@ 7.4 tree.cases = translateCases(tree.cases); 7.5 if (enumSwitch) { 7.6 result = visitEnumSwitch(tree); 7.7 - patchTargets(result, tree, result); 7.8 } else if (stringSwitch) { 7.9 result = visitStringSwitch(tree); 7.10 } else { 7.11 @@ -3146,7 +3145,9 @@ 7.12 cases.append(c); 7.13 } 7.14 } 7.15 - return make.Switch(selector, cases.toList()); 7.16 + JCSwitch enumSwitch = make.Switch(selector, cases.toList()); 7.17 + patchTargets(enumSwitch, tree, enumSwitch); 7.18 + return enumSwitch; 7.19 } 7.20 7.21 public JCTree visitStringSwitch(JCSwitch tree) { 7.22 @@ -3187,7 +3188,14 @@ 7.23 * of String is the same in the compilation environment as 7.24 * in the environment the code will run in. The string 7.25 * hashing algorithm in the SE JDK has been unchanged 7.26 - * since at least JDK 1.2. 7.27 + * since at least JDK 1.2. Since the algorithm has been 7.28 + * specified since that release as well, it is very 7.29 + * unlikely to be changed in the future. 7.30 + * 7.31 + * Different hashing algorithms, such as the length of the 7.32 + * strings or a perfect hashing algorithm over the 7.33 + * particular set of case labels, could potentially be 7.34 + * used instead of String.hashCode. 7.35 */ 7.36 7.37 ListBuffer<JCStatement> stmtList = new ListBuffer<JCStatement>();
8.1 --- a/src/share/classes/com/sun/tools/javac/file/ZipFileIndex.java Thu Dec 03 12:53:12 2009 -0800 8.2 +++ b/src/share/classes/com/sun/tools/javac/file/ZipFileIndex.java Tue Dec 08 09:16:34 2009 -0800 8.3 @@ -1002,7 +1002,7 @@ 8.4 // Do nothing 8.5 } finally { 8.6 try { 8.7 - if (raf == null) { 8.8 + if (raf != null) { 8.9 raf.close(); 8.10 } 8.11 } catch (Throwable t) {
9.1 --- a/src/share/classes/com/sun/tools/javac/main/JavacOption.java Thu Dec 03 12:53:12 2009 -0800 9.2 +++ b/src/share/classes/com/sun/tools/javac/main/JavacOption.java Tue Dec 08 09:16:34 2009 -0800 9.3 @@ -130,7 +130,7 @@ 9.4 private static Map<String,Boolean> createChoices(String... choices) { 9.5 Map<String,Boolean> map = new LinkedHashMap<String,Boolean>(); 9.6 for (String c: choices) 9.7 - map.put(c, true); 9.8 + map.put(c, false); 9.9 return map; 9.10 } 9.11
10.1 --- a/src/share/classes/com/sun/tools/javac/tree/Pretty.java Thu Dec 03 12:53:12 2009 -0800 10.2 +++ b/src/share/classes/com/sun/tools/javac/tree/Pretty.java Tue Dec 08 09:16:34 2009 -0800 10.3 @@ -54,7 +54,7 @@ 10.4 /** Set when we are producing source output. If we're not 10.5 * producing source output, we can sometimes give more detail in 10.6 * the output even though that detail would not be valid java 10.7 - * soruce. 10.8 + * source. 10.9 */ 10.10 private final boolean sourceOutput; 10.11 10.12 @@ -489,6 +489,20 @@ 10.13 print("/*public static final*/ "); 10.14 print(tree.name); 10.15 if (tree.init != null) { 10.16 + if (sourceOutput && tree.init.getTag() == JCTree.NEWCLASS) { 10.17 + print(" /*enum*/ "); 10.18 + JCNewClass init = (JCNewClass) tree.init; 10.19 + if (init.args != null && init.args.nonEmpty()) { 10.20 + print("("); 10.21 + print(init.args); 10.22 + print(")"); 10.23 + } 10.24 + if (init.def != null && init.def.defs != null) { 10.25 + print(" "); 10.26 + printBlock(init.def.defs); 10.27 + } 10.28 + return; 10.29 + } 10.30 print(" /* = "); 10.31 printExpr(tree.init); 10.32 print(" */");
11.1 --- a/src/share/classes/com/sun/tools/javap/CodeWriter.java Thu Dec 03 12:53:12 2009 -0800 11.2 +++ b/src/share/classes/com/sun/tools/javap/CodeWriter.java Tue Dec 08 09:16:34 2009 -0800 11.3 @@ -118,28 +118,33 @@ 11.4 11.5 public void writeInstr(Instruction instr) { 11.6 print(String.format("%4d: %-13s ", instr.getPC(), instr.getMnemonic())); 11.7 - instr.accept(instructionPrinter, null); 11.8 + // compute the number of indentations for the body of multi-line instructions 11.9 + // This is 6 (the width of "%4d: "), divided by the width of each indentation level, 11.10 + // and rounded up to the next integer. 11.11 + int indentWidth = options.indentWidth; 11.12 + int indent = (6 + indentWidth - 1) / indentWidth; 11.13 + instr.accept(instructionPrinter, indent); 11.14 println(); 11.15 } 11.16 // where 11.17 - Instruction.KindVisitor<Void,Void> instructionPrinter = 11.18 - new Instruction.KindVisitor<Void,Void>() { 11.19 + Instruction.KindVisitor<Void,Integer> instructionPrinter = 11.20 + new Instruction.KindVisitor<Void,Integer>() { 11.21 11.22 - public Void visitNoOperands(Instruction instr, Void p) { 11.23 + public Void visitNoOperands(Instruction instr, Integer indent) { 11.24 return null; 11.25 } 11.26 11.27 - public Void visitArrayType(Instruction instr, TypeKind kind, Void p) { 11.28 + public Void visitArrayType(Instruction instr, TypeKind kind, Integer indent) { 11.29 print(" " + kind.name); 11.30 return null; 11.31 } 11.32 11.33 - public Void visitBranch(Instruction instr, int offset, Void p) { 11.34 + public Void visitBranch(Instruction instr, int offset, Integer indent) { 11.35 print((instr.getPC() + offset)); 11.36 return null; 11.37 } 11.38 11.39 - public Void visitConstantPoolRef(Instruction instr, int index, Void p) { 11.40 + public Void visitConstantPoolRef(Instruction instr, int index, Integer indent) { 11.41 print("#" + index); 11.42 tab(); 11.43 print("// "); 11.44 @@ -147,7 +152,7 @@ 11.45 return null; 11.46 } 11.47 11.48 - public Void visitConstantPoolRefAndValue(Instruction instr, int index, int value, Void p) { 11.49 + public Void visitConstantPoolRefAndValue(Instruction instr, int index, int value, Integer indent) { 11.50 print("#" + index + ", " + value); 11.51 tab(); 11.52 print("// "); 11.53 @@ -155,46 +160,48 @@ 11.54 return null; 11.55 } 11.56 11.57 - public Void visitLocal(Instruction instr, int index, Void p) { 11.58 + public Void visitLocal(Instruction instr, int index, Integer indent) { 11.59 print(index); 11.60 return null; 11.61 } 11.62 11.63 - public Void visitLocalAndValue(Instruction instr, int index, int value, Void p) { 11.64 + public Void visitLocalAndValue(Instruction instr, int index, int value, Integer indent) { 11.65 print(index + ", " + value); 11.66 return null; 11.67 } 11.68 11.69 - public Void visitLookupSwitch(Instruction instr, int default_, int npairs, int[] matches, int[] offsets) { 11.70 + public Void visitLookupSwitch(Instruction instr, 11.71 + int default_, int npairs, int[] matches, int[] offsets, Integer indent) { 11.72 int pc = instr.getPC(); 11.73 print("{ // " + npairs); 11.74 - indent(+1); 11.75 + indent(indent); 11.76 for (int i = 0; i < npairs; i++) { 11.77 - print("\n" + matches[i] + ": " + (pc + offsets[i])); 11.78 + print(String.format("%n%12d: %d", matches[i], (pc + offsets[i]))); 11.79 } 11.80 - print("\ndefault: " + (pc + default_) + " }"); 11.81 - indent(-1); 11.82 + print("\n default: " + (pc + default_) + "\n}"); 11.83 + indent(-indent); 11.84 return null; 11.85 } 11.86 11.87 - public Void visitTableSwitch(Instruction instr, int default_, int low, int high, int[] offsets) { 11.88 + public Void visitTableSwitch(Instruction instr, 11.89 + int default_, int low, int high, int[] offsets, Integer indent) { 11.90 int pc = instr.getPC(); 11.91 - print("{ //" + low + " to " + high); 11.92 - indent(+1); 11.93 + print("{ // " + low + " to " + high); 11.94 + indent(indent); 11.95 for (int i = 0; i < offsets.length; i++) { 11.96 - print("\n" + (low + i) + ": " + (pc + offsets[i])); 11.97 + print(String.format("%n%12d: %d", (low + i), (pc + offsets[i]))); 11.98 } 11.99 - print("\ndefault: " + (pc + default_) + " }"); 11.100 - indent(-1); 11.101 + print("\n default: " + (pc + default_) + "\n}"); 11.102 + indent(-indent); 11.103 return null; 11.104 } 11.105 11.106 - public Void visitValue(Instruction instr, int value, Void p) { 11.107 + public Void visitValue(Instruction instr, int value, Integer indent) { 11.108 print(value); 11.109 return null; 11.110 } 11.111 11.112 - public Void visitUnknown(Instruction instr, Void p) { 11.113 + public Void visitUnknown(Instruction instr, Integer indent) { 11.114 return null; 11.115 } 11.116 };
12.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 12.2 +++ b/test/tools/javac/6902720/E1.java Tue Dec 08 09:16:34 2009 -0800 12.3 @@ -0,0 +1,28 @@ 12.4 +/* 12.5 + * Copyright 2009 Sun Microsystems, Inc. All Rights Reserved. 12.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 12.7 + * 12.8 + * This code is free software; you can redistribute it and/or modify it 12.9 + * under the terms of the GNU General Public License version 2 only, as 12.10 + * published by the Free Software Foundation. 12.11 + * 12.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 12.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12.15 + * version 2 for more details (a copy is included in the LICENSE file that 12.16 + * accompanied this code). 12.17 + * 12.18 + * You should have received a copy of the GNU General Public License version 12.19 + * 2 along with this work; if not, write to the Free Software Foundation, 12.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 12.21 + * 12.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 12.23 + * CA 95054 USA or visit www.sun.com if you need additional information or 12.24 + * have any questions. 12.25 + */ 12.26 + 12.27 +enum E1 { 12.28 + A, 12.29 + B { }, 12.30 + C { void m() { } }; 12.31 +}
13.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 13.2 +++ b/test/tools/javac/6902720/E2.java Tue Dec 08 09:16:34 2009 -0800 13.3 @@ -0,0 +1,29 @@ 13.4 +/* 13.5 + * Copyright 2009 Sun Microsystems, Inc. All Rights Reserved. 13.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 13.7 + * 13.8 + * This code is free software; you can redistribute it and/or modify it 13.9 + * under the terms of the GNU General Public License version 2 only, as 13.10 + * published by the Free Software Foundation. 13.11 + * 13.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 13.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13.15 + * version 2 for more details (a copy is included in the LICENSE file that 13.16 + * accompanied this code). 13.17 + * 13.18 + * You should have received a copy of the GNU General Public License version 13.19 + * 2 along with this work; if not, write to the Free Software Foundation, 13.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 13.21 + * 13.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 13.23 + * CA 95054 USA or visit www.sun.com if you need additional information or 13.24 + * have any questions. 13.25 + */ 13.26 + 13.27 +enum E2 { 13.28 + A(1), 13.29 + B(2) { }, 13.30 + C(3) { void m() { } }; 13.31 + E2(int i) { } 13.32 +}
14.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 14.2 +++ b/test/tools/javac/6902720/Test.java Tue Dec 08 09:16:34 2009 -0800 14.3 @@ -0,0 +1,91 @@ 14.4 +/* 14.5 + * Copyright 2009 Sun Microsystems, Inc. All Rights Reserved. 14.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 14.7 + * 14.8 + * This code is free software; you can redistribute it and/or modify it 14.9 + * under the terms of the GNU General Public License version 2 only, as 14.10 + * published by the Free Software Foundation. 14.11 + * 14.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 14.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 14.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14.15 + * version 2 for more details (a copy is included in the LICENSE file that 14.16 + * accompanied this code). 14.17 + * 14.18 + * You should have received a copy of the GNU General Public License version 14.19 + * 2 along with this work; if not, write to the Free Software Foundation, 14.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 14.21 + * 14.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 14.23 + * CA 95054 USA or visit www.sun.com if you need additional information or 14.24 + * have any questions. 14.25 + */ 14.26 + 14.27 +import java.io.*; 14.28 +import java.net.*; 14.29 +import javax.tools.*; 14.30 +import java.util.*; 14.31 + 14.32 +import com.sun.source.tree.CompilationUnitTree; 14.33 +import com.sun.source.util.JavacTask; 14.34 +import com.sun.tools.javac.api.JavacTool; 14.35 +import com.sun.tools.javac.tree.JCTree; 14.36 +import com.sun.tools.javac.tree.Pretty; 14.37 + 14.38 +/** 14.39 + * @test 14.40 + * @bug 6902720 14.41 + * @summary javac pretty printer does not handle enums correctly 14.42 + */ 14.43 + 14.44 +public class Test { 14.45 + 14.46 + public static void main(String[] args) throws Exception { 14.47 + Test t = new Test(); 14.48 + t.run("E1.java", "E2.java"); 14.49 + } 14.50 + 14.51 + void run(String... args) throws Exception { 14.52 + File testSrcDir = new File(System.getProperty("test.src")); 14.53 + for (String arg: args) { 14.54 + test(new File(testSrcDir, arg)); 14.55 + } 14.56 + } 14.57 + 14.58 + void test(File test) throws Exception { 14.59 + JavacTool tool1 = JavacTool.create(); 14.60 + StandardJavaFileManager fm = tool1.getStandardFileManager(null, null, null); 14.61 + Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(test); 14.62 + 14.63 + // parse test file into a tree, and write it out to a stringbuffer using Pretty 14.64 + JavacTask t1 = tool1.getTask(null, fm, null, null, null, files); 14.65 + StringWriter sw = new StringWriter(); 14.66 + PrintWriter pw = new PrintWriter(sw); 14.67 + Iterable<? extends CompilationUnitTree> trees = t1.parse(); 14.68 + for (CompilationUnitTree tree: trees) { 14.69 + new Pretty(pw, true).printExpr((JCTree) tree); 14.70 + } 14.71 + pw.close(); 14.72 + 14.73 + final String out = sw.toString(); 14.74 + System.err.println("generated code:\n" + out + "\n"); 14.75 + 14.76 + // verify the generated code is valid Java by compiling it 14.77 + JavacTool tool2 = JavacTool.create(); 14.78 + JavaFileObject fo = new SimpleJavaFileObject(URI.create("output"), JavaFileObject.Kind.SOURCE) { 14.79 + @Override 14.80 + public CharSequence getCharContent(boolean ignoreEncodingErrors) { 14.81 + return out; 14.82 + } 14.83 + }; 14.84 + JavacTask t2 = tool2.getTask(null, fm, null, null, null, Collections.singleton(fo)); 14.85 + boolean ok = t2.call(); 14.86 + if (!ok) 14.87 + throw new Exception("compilation of generated code failed"); 14.88 + 14.89 + File expectedClass = new File(test.getName().replace(".java", ".class")); 14.90 + if (!expectedClass.exists()) 14.91 + throw new Exception(expectedClass + " not found"); 14.92 + } 14.93 +} 14.94 +