OpenJDK / jdk / jdk12
changeset 30848:c275389a3680
Merge
author | lana |
---|---|
date | Thu, 28 May 2015 16:54:56 -0700 |
parents | b02fa8bb730c 9385b9c8506b |
children | fcfa8eb95c23 |
files | langtools/make/gensrc/Gensrc-jdk.dev.gmk langtools/src/jdk.compiler/share/classes/com/sun/tools/classfile/AccessFlags.java langtools/src/jdk.compiler/share/classes/com/sun/tools/classfile/Annotation.java langtools/src/jdk.compiler/share/classes/com/sun/tools/classfile/AnnotationDefault_attribute.java langtools/src/jdk.compiler/share/classes/com/sun/tools/classfile/Attribute.java langtools/src/jdk.compiler/share/classes/com/sun/tools/classfile/AttributeException.java langtools/src/jdk.compiler/share/classes/com/sun/tools/classfile/Attributes.java langtools/src/jdk.compiler/share/classes/com/sun/tools/classfile/BootstrapMethods_attribute.java langtools/src/jdk.compiler/share/classes/com/sun/tools/classfile/CharacterRangeTable_attribute.java langtools/src/jdk.compiler/share/classes/com/sun/tools/classfile/ClassFile.java langtools/src/jdk.compiler/share/classes/com/sun/tools/classfile/ClassReader.java langtools/src/jdk.compiler/share/classes/com/sun/tools/classfile/ClassTranslator.java langtools/src/jdk.compiler/share/classes/com/sun/tools/classfile/ClassWriter.java langtools/src/jdk.compiler/share/classes/com/sun/tools/classfile/Code_attribute.java langtools/src/jdk.compiler/share/classes/com/sun/tools/classfile/CompilationID_attribute.java langtools/src/jdk.compiler/share/classes/com/sun/tools/classfile/ConstantPool.java langtools/src/jdk.compiler/share/classes/com/sun/tools/classfile/ConstantPoolException.java langtools/src/jdk.compiler/share/classes/com/sun/tools/classfile/ConstantValue_attribute.java langtools/src/jdk.compiler/share/classes/com/sun/tools/classfile/DefaultAttribute.java langtools/src/jdk.compiler/share/classes/com/sun/tools/classfile/Dependencies.java langtools/src/jdk.compiler/share/classes/com/sun/tools/classfile/Dependency.java langtools/src/jdk.compiler/share/classes/com/sun/tools/classfile/Deprecated_attribute.java langtools/src/jdk.compiler/share/classes/com/sun/tools/classfile/Descriptor.java langtools/src/jdk.compiler/share/classes/com/sun/tools/classfile/DescriptorException.java langtools/src/jdk.compiler/share/classes/com/sun/tools/classfile/EnclosingMethod_attribute.java langtools/src/jdk.compiler/share/classes/com/sun/tools/classfile/Exceptions_attribute.java langtools/src/jdk.compiler/share/classes/com/sun/tools/classfile/Field.java langtools/src/jdk.compiler/share/classes/com/sun/tools/classfile/InnerClasses_attribute.java langtools/src/jdk.compiler/share/classes/com/sun/tools/classfile/Instruction.java langtools/src/jdk.compiler/share/classes/com/sun/tools/classfile/LineNumberTable_attribute.java langtools/src/jdk.compiler/share/classes/com/sun/tools/classfile/LocalVariableTable_attribute.java langtools/src/jdk.compiler/share/classes/com/sun/tools/classfile/LocalVariableTypeTable_attribute.java langtools/src/jdk.compiler/share/classes/com/sun/tools/classfile/Method.java langtools/src/jdk.compiler/share/classes/com/sun/tools/classfile/MethodParameters_attribute.java langtools/src/jdk.compiler/share/classes/com/sun/tools/classfile/Opcode.java langtools/src/jdk.compiler/share/classes/com/sun/tools/classfile/ReferenceFinder.java langtools/src/jdk.compiler/share/classes/com/sun/tools/classfile/RuntimeAnnotations_attribute.java langtools/src/jdk.compiler/share/classes/com/sun/tools/classfile/RuntimeInvisibleAnnotations_attribute.java langtools/src/jdk.compiler/share/classes/com/sun/tools/classfile/RuntimeInvisibleParameterAnnotations_attribute.java langtools/src/jdk.compiler/share/classes/com/sun/tools/classfile/RuntimeInvisibleTypeAnnotations_attribute.java langtools/src/jdk.compiler/share/classes/com/sun/tools/classfile/RuntimeParameterAnnotations_attribute.java langtools/src/jdk.compiler/share/classes/com/sun/tools/classfile/RuntimeTypeAnnotations_attribute.java langtools/src/jdk.compiler/share/classes/com/sun/tools/classfile/RuntimeVisibleAnnotations_attribute.java langtools/src/jdk.compiler/share/classes/com/sun/tools/classfile/RuntimeVisibleParameterAnnotations_attribute.java langtools/src/jdk.compiler/share/classes/com/sun/tools/classfile/RuntimeVisibleTypeAnnotations_attribute.java langtools/src/jdk.compiler/share/classes/com/sun/tools/classfile/Signature.java langtools/src/jdk.compiler/share/classes/com/sun/tools/classfile/Signature_attribute.java langtools/src/jdk.compiler/share/classes/com/sun/tools/classfile/SourceDebugExtension_attribute.java langtools/src/jdk.compiler/share/classes/com/sun/tools/classfile/SourceFile_attribute.java langtools/src/jdk.compiler/share/classes/com/sun/tools/classfile/SourceID_attribute.java langtools/src/jdk.compiler/share/classes/com/sun/tools/classfile/StackMapTable_attribute.java langtools/src/jdk.compiler/share/classes/com/sun/tools/classfile/StackMap_attribute.java langtools/src/jdk.compiler/share/classes/com/sun/tools/classfile/Synthetic_attribute.java langtools/src/jdk.compiler/share/classes/com/sun/tools/classfile/Type.java langtools/src/jdk.compiler/share/classes/com/sun/tools/classfile/TypeAnnotation.java langtools/src/jdk.compiler/share/classes/com/sun/tools/classfile/package-info.java langtools/src/jdk.compiler/share/classes/com/sun/tools/javap/AnnotationWriter.java langtools/src/jdk.compiler/share/classes/com/sun/tools/javap/AttributeWriter.java langtools/src/jdk.compiler/share/classes/com/sun/tools/javap/BasicWriter.java langtools/src/jdk.compiler/share/classes/com/sun/tools/javap/ClassWriter.java langtools/src/jdk.compiler/share/classes/com/sun/tools/javap/CodeWriter.java langtools/src/jdk.compiler/share/classes/com/sun/tools/javap/ConstantWriter.java langtools/src/jdk.compiler/share/classes/com/sun/tools/javap/Context.java langtools/src/jdk.compiler/share/classes/com/sun/tools/javap/DisassemblerTool.java langtools/src/jdk.compiler/share/classes/com/sun/tools/javap/InstructionDetailWriter.java langtools/src/jdk.compiler/share/classes/com/sun/tools/javap/InternalError.java langtools/src/jdk.compiler/share/classes/com/sun/tools/javap/JavapFileManager.java langtools/src/jdk.compiler/share/classes/com/sun/tools/javap/JavapTask.java langtools/src/jdk.compiler/share/classes/com/sun/tools/javap/LocalVariableTableWriter.java langtools/src/jdk.compiler/share/classes/com/sun/tools/javap/LocalVariableTypeTableWriter.java langtools/src/jdk.compiler/share/classes/com/sun/tools/javap/Main.java langtools/src/jdk.compiler/share/classes/com/sun/tools/javap/Messages.java langtools/src/jdk.compiler/share/classes/com/sun/tools/javap/Options.java langtools/src/jdk.compiler/share/classes/com/sun/tools/javap/SourceWriter.java langtools/src/jdk.compiler/share/classes/com/sun/tools/javap/StackMapWriter.java langtools/src/jdk.compiler/share/classes/com/sun/tools/javap/TryBlockWriter.java langtools/src/jdk.compiler/share/classes/com/sun/tools/javap/TypeAnnotationWriter.java langtools/src/jdk.compiler/share/classes/com/sun/tools/javap/overview.html langtools/src/jdk.compiler/share/classes/com/sun/tools/javap/package-info.java langtools/src/jdk.compiler/share/classes/com/sun/tools/javap/resources/javap.properties langtools/src/jdk.compiler/share/classes/com/sun/tools/javap/resources/javap_ja.properties langtools/src/jdk.compiler/share/classes/com/sun/tools/javap/resources/javap_zh_CN.properties langtools/src/jdk.compiler/share/classes/com/sun/tools/javap/resources/version.properties-template langtools/src/jdk.dev/share/classes/com/sun/tools/jdeps/Analyzer.java langtools/src/jdk.dev/share/classes/com/sun/tools/jdeps/Archive.java langtools/src/jdk.dev/share/classes/com/sun/tools/jdeps/ClassFileReader.java langtools/src/jdk.dev/share/classes/com/sun/tools/jdeps/JdepsTask.java langtools/src/jdk.dev/share/classes/com/sun/tools/jdeps/Main.java langtools/src/jdk.dev/share/classes/com/sun/tools/jdeps/Module.java langtools/src/jdk.dev/share/classes/com/sun/tools/jdeps/ModulesXmlReader.java langtools/src/jdk.dev/share/classes/com/sun/tools/jdeps/PlatformClassPath.java langtools/src/jdk.dev/share/classes/com/sun/tools/jdeps/Profile.java langtools/src/jdk.dev/share/classes/com/sun/tools/jdeps/resources/jdeps.properties langtools/src/jdk.dev/share/classes/com/sun/tools/jdeps/resources/jdeps_ja.properties langtools/src/jdk.dev/share/classes/com/sun/tools/jdeps/resources/jdeps_zh_CN.properties langtools/src/jdk.dev/share/classes/com/sun/tools/jdeps/resources/jdkinternals.properties langtools/src/jdk.dev/share/classes/com/sun/tools/jdeps/resources/version.properties-template |
diffstat | 421 files changed, 19502 insertions(+), 18546 deletions(-) [+] |
line wrap: on
line diff
--- a/langtools/make/CompileInterim.gmk Thu May 28 16:13:55 2015 -0700 +++ b/langtools/make/CompileInterim.gmk Thu May 28 16:54:56 2015 -0700 @@ -41,11 +41,11 @@ DISABLE_SJAVAC := true, \ SRC := $(LANGTOOLS_TOPDIR)/src/java.compiler/share/classes \ $(LANGTOOLS_TOPDIR)/src/jdk.compiler/share/classes \ - $(LANGTOOLS_TOPDIR)/src/jdk.dev/share/classes \ $(LANGTOOLS_TOPDIR)/src/jdk.javadoc/share/classes \ + $(LANGTOOLS_TOPDIR)/src/jdk.jdeps/share/classes \ $(SUPPORT_OUTPUTDIR)/gensrc/jdk.compiler \ - $(SUPPORT_OUTPUTDIR)/gensrc/jdk.dev \ - $(SUPPORT_OUTPUTDIR)/gensrc/jdk.javadoc, \ + $(SUPPORT_OUTPUTDIR)/gensrc/jdk.javadoc \ + $(SUPPORT_OUTPUTDIR)/gensrc/jdk.jdeps, \ EXCLUDES := sun jdk, \ COPY := .gif .xml .css .js javax.tools.JavaCompilerTool, \ BIN := $(BUILDTOOLS_OUTPUTDIR)/langtools_interim_classes, \
--- a/langtools/make/build.properties Thu May 28 16:13:55 2015 -0700 +++ b/langtools/make/build.properties Thu May 28 16:54:56 2015 -0700 @@ -47,11 +47,11 @@ boot.javac.target = 8 #configuration of submodules (share by both the bootstrap and normal compilation): -langtools.modules=java.compiler:jdk.compiler:jdk.dev:jdk.javadoc +langtools.modules=java.compiler:jdk.compiler:jdk.jdeps:jdk.javadoc java.compiler.dependencies= jdk.compiler.dependencies=java.compiler jdk.javadoc.dependencies=java.compiler:jdk.compiler -jdk.dev.dependencies=java.compiler:jdk.compiler +jdk.jdeps.dependencies=java.compiler:jdk.compiler javac.resource.includes = \ com/sun/tools/javac/resources/compiler.properties
--- a/langtools/make/build.xml Thu May 28 16:13:55 2015 -0700 +++ b/langtools/make/build.xml Thu May 28 16:54:56 2015 -0700 @@ -257,7 +257,7 @@ <class location="${build.dir}/java.compiler/classes"/> <class location="${build.dir}/jdk.compiler/classes"/> <class location="${build.dir}/jdk.javadoc/classes"/> - <class location="${build.dir}/jdk.dev/classes"/> + <class location="${build.dir}/jdk.jdeps/classes"/> <sourcePath> <pathelement path="${langtools.sources}"/> </sourcePath> @@ -463,7 +463,7 @@ <build-module-jar module.name="java.compiler" compilation.kind="@{compilation.kind}" /> <build-module-jar module.name="jdk.compiler" compilation.kind="@{compilation.kind}" /> <build-module-jar module.name="jdk.javadoc" compilation.kind="@{compilation.kind}" /> - <build-module-jar module.name="jdk.dev" compilation.kind="@{compilation.kind}" /> + <build-module-jar module.name="jdk.jdeps" compilation.kind="@{compilation.kind}" /> </sequential> </macrodef> </target> @@ -527,7 +527,7 @@ resource.includes="${javac.resource.includes}" /> <build-module-classes module.name="jdk.javadoc" compilation.kind="@{compilation.kind}" /> - <build-module-classes module.name="jdk.dev" + <build-module-classes module.name="jdk.jdeps" compilation.kind="@{compilation.kind}" /> </sequential> </macrodef>
--- a/langtools/make/gensrc/Gensrc-jdk.compiler.gmk Thu May 28 16:13:55 2015 -0700 +++ b/langtools/make/gensrc/Gensrc-jdk.compiler.gmk Thu May 28 16:54:56 2015 -0700 @@ -31,11 +31,8 @@ $(eval $(call SetupVersionProperties,JAVAH_VERSION, \ com/sun/tools/javah/resources/version.properties)) -$(eval $(call SetupVersionProperties,JAVAP_VERSION, \ - com/sun/tools/javap/resources/version.properties)) - $(eval $(call SetupCompileProperties,COMPILE_PROPERTIES, \ - $(JAVAC_VERSION) $(JAVAH_VERSION) $(JAVAP_VERSION))) + $(JAVAC_VERSION) $(JAVAH_VERSION))) $(eval $(call SetupParseProperties,PARSE_PROPERTIES, \ com/sun/tools/javac/resources/compiler.properties))
--- a/langtools/make/gensrc/Gensrc-jdk.dev.gmk Thu May 28 16:13:55 2015 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,33 +0,0 @@ -# -# Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. -# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. -# -# This code is free software; you can redistribute it and/or modify it -# under the terms of the GNU General Public License version 2 only, as -# published by the Free Software Foundation. Oracle designates this -# particular file as subject to the "Classpath" exception as provided -# by Oracle in the LICENSE file that accompanied this code. -# -# This code is distributed in the hope that it will be useful, but WITHOUT -# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -# version 2 for more details (a copy is included in the LICENSE file that -# accompanied this code). -# -# You should have received a copy of the GNU General Public License version -# 2 along with this work; if not, write to the Free Software Foundation, -# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. -# -# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA -# or visit www.oracle.com if you need additional information or have any -# questions. -# - -include GensrcCommon.gmk - -$(eval $(call SetupVersionProperties,JDEPS_VERSION,\ - com/sun/tools/jdeps/resources/version.properties)) - -$(eval $(call SetupCompileProperties,COMPILE_PROPERTIES, $(JDEPS_VERSION))) - -all: $(COMPILE_PROPERTIES)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/make/gensrc/Gensrc-jdk.jdeps.gmk Thu May 28 16:54:56 2015 -0700 @@ -0,0 +1,37 @@ +# +# Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# This code is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License version 2 only, as +# published by the Free Software Foundation. Oracle designates this +# particular file as subject to the "Classpath" exception as provided +# by Oracle in the LICENSE file that accompanied this code. +# +# This code is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +# version 2 for more details (a copy is included in the LICENSE file that +# accompanied this code). +# +# You should have received a copy of the GNU General Public License version +# 2 along with this work; if not, write to the Free Software Foundation, +# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. +# +# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA +# or visit www.oracle.com if you need additional information or have any +# questions. +# + +include GensrcCommon.gmk + +$(eval $(call SetupVersionProperties,JAVAP_VERSION, \ + com/sun/tools/javap/resources/version.properties)) + +$(eval $(call SetupVersionProperties,JDEPS_VERSION,\ + com/sun/tools/jdeps/resources/version.properties)) + +$(eval $(call SetupCompileProperties,COMPILE_PROPERTIES,\ + $(JDEPS_VERSION) $(JAVAP_VERSION))) + +all: $(COMPILE_PROPERTIES)
--- a/langtools/make/intellij/langtools.iml Thu May 28 16:13:55 2015 -0700 +++ b/langtools/make/intellij/langtools.iml Thu May 28 16:54:56 2015 -0700 @@ -6,13 +6,13 @@ <content url="file://$MODULE_DIR$"> <sourceFolder url="file://$MODULE_DIR$/src/java.compiler/share/classes" isTestSource="false" /> <sourceFolder url="file://$MODULE_DIR$/src/jdk.compiler/share/classes" isTestSource="false" /> - <sourceFolder url="file://$MODULE_DIR$/src/jdk.dev/share/classes" isTestSource="false" /> <sourceFolder url="file://$MODULE_DIR$/src/jdk.javadoc/share/classes" isTestSource="false" /> + <sourceFolder url="file://$MODULE_DIR$/src/jdk.jdeps/share/classes" isTestSource="false" /> <sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" /> <sourceFolder url="file://$MODULE_DIR$/build/bootstrap/java.compiler/gensrc" isTestSource="false" /> <sourceFolder url="file://$MODULE_DIR$/build/bootstrap/jdk.compiler/gensrc" isTestSource="false" /> - <sourceFolder url="file://$MODULE_DIR$/build/bootstrap/jdk.dev/gensrc" isTestSource="false" /> <sourceFolder url="file://$MODULE_DIR$/build/bootstrap/jdk.javadoc/gensrc" isTestSource="false" /> + <sourceFolder url="file://$MODULE_DIR$/build/bootstrap/jdk.jdeps/gensrc" isTestSource="false" /> </content> <orderEntry type="sourceFolder" forTests="false" /> <orderEntry type="inheritedJdk" />
--- a/langtools/make/intellij/workspace.xml Thu May 28 16:13:55 2015 -0700 +++ b/langtools/make/intellij/workspace.xml Thu May 28 16:54:56 2015 -0700 @@ -10,7 +10,7 @@ <!-- standard tools --> <configuration default="false" name="javac" type="Application" factoryName="Application"> <option name="MAIN_CLASS_NAME" value="com.sun.tools.javac.Main" /> - <option name="VM_PARAMETERS" value="-Xbootclasspath/p:build@FILE_SEP@java.compiler@FILE_SEP@classes@PATH_SEP@build@FILE_SEP@jdk.compiler@FILE_SEP@classes@PATH_SEP@build@FILE_SEP@jdk.javadoc@FILE_SEP@classes@PATH_SEP@build@FILE_SEP@jdk.dev@FILE_SEP@classes" /> + <option name="VM_PARAMETERS" value="-Xbootclasspath/p:build@FILE_SEP@java.compiler@FILE_SEP@classes@PATH_SEP@build@FILE_SEP@jdk.compiler@FILE_SEP@classes@PATH_SEP@build@FILE_SEP@jdk.javadoc@FILE_SEP@classes@PATH_SEP@build@FILE_SEP@jdk.jdeps@FILE_SEP@classes" /> <option name="PROGRAM_PARAMETERS" value="" /> <option name="WORKING_DIRECTORY" value="file://$PROJECT_DIR$" /> <option name="ALTERNATIVE_JRE_PATH_ENABLED" value="false" /> @@ -29,7 +29,7 @@ </configuration> <configuration default="false" name="javadoc" type="Application" factoryName="Application"> <option name="MAIN_CLASS_NAME" value="com.sun.tools.javadoc.Main" /> - <option name="VM_PARAMETERS" value="-Xbootclasspath/p:build@FILE_SEP@java.compiler@FILE_SEP@classes@PATH_SEP@build@FILE_SEP@jdk.compiler@FILE_SEP@classes@PATH_SEP@build@FILE_SEP@jdk.javadoc@FILE_SEP@classes@PATH_SEP@build@FILE_SEP@jdk.dev@FILE_SEP@classes" /> + <option name="VM_PARAMETERS" value="-Xbootclasspath/p:build@FILE_SEP@java.compiler@FILE_SEP@classes@PATH_SEP@build@FILE_SEP@jdk.compiler@FILE_SEP@classes@PATH_SEP@build@FILE_SEP@jdk.javadoc@FILE_SEP@classes@PATH_SEP@build@FILE_SEP@jdk.jdeps@FILE_SEP@classes" /> <option name="PROGRAM_PARAMETERS" value="" /> <option name="WORKING_DIRECTORY" value="file://$PROJECT_DIR$" /> <option name="ALTERNATIVE_JRE_PATH_ENABLED" value="false" /> @@ -48,7 +48,7 @@ </configuration> <configuration default="false" name="javap" type="Application" factoryName="Application"> <option name="MAIN_CLASS_NAME" value="com.sun.tools.javap.Main" /> - <option name="VM_PARAMETERS" value="-Xbootclasspath/p:build@FILE_SEP@java.compiler@FILE_SEP@classes@PATH_SEP@build@FILE_SEP@jdk.compiler@FILE_SEP@classes@PATH_SEP@build@FILE_SEP@jdk.javadoc@FILE_SEP@classes@PATH_SEP@build@FILE_SEP@jdk.dev@FILE_SEP@classes" /> + <option name="VM_PARAMETERS" value="-Xbootclasspath/p:build@FILE_SEP@java.compiler@FILE_SEP@classes@PATH_SEP@build@FILE_SEP@jdk.compiler@FILE_SEP@classes@PATH_SEP@build@FILE_SEP@jdk.javadoc@FILE_SEP@classes@PATH_SEP@build@FILE_SEP@jdk.jdeps@FILE_SEP@classes" /> <option name="PROGRAM_PARAMETERS" value="" /> <option name="WORKING_DIRECTORY" value="file://$PROJECT_DIR$" /> <option name="ALTERNATIVE_JRE_PATH_ENABLED" value="false" /> @@ -67,7 +67,7 @@ </configuration> <configuration default="false" name="javah" type="Application" factoryName="Application"> <option name="MAIN_CLASS_NAME" value="com.sun.tools.javah.Main" /> - <option name="VM_PARAMETERS" value="-Xbootclasspath/p:build@FILE_SEP@java.compiler@FILE_SEP@classes@PATH_SEP@build@FILE_SEP@jdk.compiler@FILE_SEP@classes@PATH_SEP@build@FILE_SEP@jdk.javadoc@FILE_SEP@classes@PATH_SEP@build@FILE_SEP@jdk.dev@FILE_SEP@classes" /> + <option name="VM_PARAMETERS" value="-Xbootclasspath/p:build@FILE_SEP@java.compiler@FILE_SEP@classes@PATH_SEP@build@FILE_SEP@jdk.compiler@FILE_SEP@classes@PATH_SEP@build@FILE_SEP@jdk.javadoc@FILE_SEP@classes@PATH_SEP@build@FILE_SEP@jdk.jdeps@FILE_SEP@classes" /> <option name="PROGRAM_PARAMETERS" value="" /> <option name="WORKING_DIRECTORY" value="file://$PROJECT_DIR$" /> <option name="ALTERNATIVE_JRE_PATH_ENABLED" value="false" /> @@ -86,7 +86,7 @@ </configuration> <configuration default="false" name="sjavac" type="Application" factoryName="Application"> <option name="MAIN_CLASS_NAME" value="com.sun.tools.sjavac.Main" /> - <option name="VM_PARAMETERS" value="-Xbootclasspath/p:build@FILE_SEP@java.compiler@FILE_SEP@classes@PATH_SEP@build@FILE_SEP@jdk.compiler@FILE_SEP@classes@PATH_SEP@build@FILE_SEP@jdk.javadoc@FILE_SEP@classes@PATH_SEP@build@FILE_SEP@jdk.dev@FILE_SEP@classes" /> + <option name="VM_PARAMETERS" value="-Xbootclasspath/p:build@FILE_SEP@java.compiler@FILE_SEP@classes@PATH_SEP@build@FILE_SEP@jdk.compiler@FILE_SEP@classes@PATH_SEP@build@FILE_SEP@jdk.javadoc@FILE_SEP@classes@PATH_SEP@build@FILE_SEP@jdk.jdeps@FILE_SEP@classes" /> <option name="PROGRAM_PARAMETERS" value="" /> <option name="WORKING_DIRECTORY" value="file://$PROJECT_DIR$" /> <option name="ALTERNATIVE_JRE_PATH_ENABLED" value="false" /> @@ -106,7 +106,7 @@ <!-- bootstrap javac --> <configuration default="false" name="javac (bootstrap)" type="Application" factoryName="Application"> <option name="MAIN_CLASS_NAME" value="com.sun.tools.javac.Main" /> - <option name="VM_PARAMETERS" value="-Xbootclasspath/p:build@FILE_SEP@bootstrap@FILE_SEP@java.compiler@FILE_SEP@classes@PATH_SEP@build@FILE_SEP@bootstrap@FILE_SEP@jdk.compiler@FILE_SEP@classes@PATH_SEP@build@FILE_SEP@bootstrap@FILE_SEP@jdk.javadoc@FILE_SEP@classes@PATH_SEP@build@FILE_SEP@bootstrap@FILE_SEP@jdk.dev@FILE_SEP@classes" /> + <option name="VM_PARAMETERS" value="-Xbootclasspath/p:build@FILE_SEP@bootstrap@FILE_SEP@java.compiler@FILE_SEP@classes@PATH_SEP@build@FILE_SEP@bootstrap@FILE_SEP@jdk.compiler@FILE_SEP@classes@PATH_SEP@build@FILE_SEP@bootstrap@FILE_SEP@jdk.javadoc@FILE_SEP@classes@PATH_SEP@build@FILE_SEP@bootstrap@FILE_SEP@jdk.jdeps@FILE_SEP@classes" /> <option name="PROGRAM_PARAMETERS" value="" /> <option name="WORKING_DIRECTORY" value="file://$PROJECT_DIR$" /> <option name="ALTERNATIVE_JRE_PATH_ENABLED" value="false" />
--- a/langtools/make/netbeans/langtools/nbproject/project.xml Thu May 28 16:13:55 2015 -0700 +++ b/langtools/make/netbeans/langtools/nbproject/project.xml Thu May 28 16:54:56 2015 -0700 @@ -67,9 +67,9 @@ <location>${root}/src/jdk.compiler/share/classes</location> </source-folder> <source-folder> - <label>Source files - jdk.dev</label> + <label>Source files - jdk.jdeps</label> <type>java</type> - <location>${root}/src/jdk.dev/share/classes</location> + <location>${root}/src/jdk.jdeps/share/classes</location> </source-folder> <source-folder> <label>Source files - jdk.javadoc</label> @@ -128,10 +128,10 @@ </action> <action name="compile.single"> <target>compile-single</target> - <property name="module.name">jdk.dev</property> + <property name="module.name">jdk.jdeps</property> <context> <property>includes</property> - <folder>${root}/src/jdk.dev/share/classes</folder> + <folder>${root}/src/jdk.jdeps/share/classes</folder> <pattern>\.java$</pattern> <format>relative-path</format> <arity> @@ -195,7 +195,7 @@ <target>run-single</target> <context> <property>run.classname</property> - <folder>${root}/src/jdk.dev/share/classes</folder> + <folder>${root}/src/jdk.jdeps/share/classes</folder> <pattern>\.java$</pattern> <format>java-name</format> <arity> @@ -265,7 +265,7 @@ <target>debug-single</target> <context> <property>debug.classname</property> - <folder>${root}/src/jdk.dev/share/classes</folder> + <folder>${root}/src/jdk.jdeps/share/classes</folder> <pattern>\.java$</pattern> <format>java-name</format> <arity> @@ -329,10 +329,10 @@ </action> <action name="debug.fix"> <target>debug-fix</target> - <property name="module.name">jdk.dev</property> + <property name="module.name">jdk.jdeps</property> <context> <property>class</property> - <folder>${root}/src/jdk.dev/share/classes</folder> + <folder>${root}/src/jdk.jdeps/share/classes</folder> <pattern>\.java$</pattern> <format>relative-path-noext</format> <arity> @@ -382,8 +382,8 @@ <location>${root}/src/jdk.compiler/share/classes</location> </source-folder> <source-folder style="tree"> - <label>Source files - jdk.dev</label> - <location>${root}/src/jdk.dev/share/classes</location> + <label>Source files - jdk.jdeps</label> + <location>${root}/src/jdk.jdeps/share/classes</location> </source-folder> <source-folder style="tree"> <label>Source files - jdk.javadoc</label> @@ -443,10 +443,10 @@ <source-level>1.8</source-level> </compilation-unit> <compilation-unit> - <package-root>${root}/src/jdk.dev/share/classes</package-root> - <package-root>${root}/build/bootstrap/jdk.dev/gensrc</package-root> + <package-root>${root}/src/jdk.jdeps/share/classes</package-root> + <package-root>${root}/build/bootstrap/jdk.jdeps/gensrc</package-root> <classpath mode="compile">${root}/build/java.compiler/classes:${root}/build/jdk.compiler/classes</classpath> - <built-to>${root}/build/jdk.dev/classes</built-to> + <built-to>${root}/build/jdk.jdeps/classes</built-to> <source-level>1.8</source-level> </compilation-unit> <compilation-unit>
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/classfile/AccessFlags.java Thu May 28 16:13:55 2015 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,258 +0,0 @@ -/* - * Copyright (c) 2007, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package com.sun.tools.classfile; - -import java.io.IOException; -import java.util.LinkedHashSet; -import java.util.Set; - -/** - * See JVMS, sections 4.2, 4.6, 4.7. - * - * <p><b>This is NOT part of any supported API. - * If you write code that depends on this, you do so at your own risk. - * This code and its internal interfaces are subject to change or - * deletion without notice.</b> - */ -public class AccessFlags { - public static final int ACC_PUBLIC = 0x0001; // class, inner, field, method - public static final int ACC_PRIVATE = 0x0002; // inner, field, method - public static final int ACC_PROTECTED = 0x0004; // inner, field, method - public static final int ACC_STATIC = 0x0008; // inner, field, method - public static final int ACC_FINAL = 0x0010; // class, inner, field, method - public static final int ACC_SUPER = 0x0020; // class - public static final int ACC_SYNCHRONIZED = 0x0020; // method - public static final int ACC_VOLATILE = 0x0040; // field - public static final int ACC_BRIDGE = 0x0040; // method - public static final int ACC_TRANSIENT = 0x0080; // field - public static final int ACC_VARARGS = 0x0080; // method - public static final int ACC_NATIVE = 0x0100; // method - public static final int ACC_INTERFACE = 0x0200; // class, inner - public static final int ACC_ABSTRACT = 0x0400; // class, inner, method - public static final int ACC_STRICT = 0x0800; // method - public static final int ACC_SYNTHETIC = 0x1000; // class, inner, field, method - public static final int ACC_ANNOTATION = 0x2000; // class, inner - public static final int ACC_ENUM = 0x4000; // class, inner, field - public static final int ACC_MANDATED = 0x8000; // class, inner, field, method - - public static enum Kind { Class, InnerClass, Field, Method} - - AccessFlags(ClassReader cr) throws IOException { - this(cr.readUnsignedShort()); - } - - public AccessFlags(int flags) { - this.flags = flags; - } - - public AccessFlags ignore(int mask) { - return new AccessFlags(flags & ~mask); - } - - public boolean is(int mask) { - return (flags & mask) != 0; - } - - public int byteLength() { - return 2; - } - - private static final int[] classModifiers = { - ACC_PUBLIC, ACC_FINAL, ACC_ABSTRACT - }; - - private static final int[] classFlags = { - ACC_PUBLIC, ACC_FINAL, ACC_SUPER, ACC_INTERFACE, ACC_ABSTRACT, - ACC_SYNTHETIC, ACC_ANNOTATION, ACC_ENUM - }; - - public Set<String> getClassModifiers() { - int f = ((flags & ACC_INTERFACE) != 0 ? flags & ~ACC_ABSTRACT : flags); - return getModifiers(f, classModifiers, Kind.Class); - } - - public Set<String> getClassFlags() { - return getFlags(classFlags, Kind.Class); - } - - private static final int[] innerClassModifiers = { - ACC_PUBLIC, ACC_PRIVATE, ACC_PROTECTED, ACC_STATIC, ACC_FINAL, - ACC_ABSTRACT - }; - - private static final int[] innerClassFlags = { - ACC_PUBLIC, ACC_PRIVATE, ACC_PROTECTED, ACC_STATIC, ACC_FINAL, ACC_SUPER, - ACC_INTERFACE, ACC_ABSTRACT, ACC_SYNTHETIC, ACC_ANNOTATION, ACC_ENUM - }; - - public Set<String> getInnerClassModifiers() { - int f = ((flags & ACC_INTERFACE) != 0 ? flags & ~ACC_ABSTRACT : flags); - return getModifiers(f, innerClassModifiers, Kind.InnerClass); - } - - public Set<String> getInnerClassFlags() { - return getFlags(innerClassFlags, Kind.InnerClass); - } - - private static final int[] fieldModifiers = { - ACC_PUBLIC, ACC_PRIVATE, ACC_PROTECTED, ACC_STATIC, ACC_FINAL, - ACC_VOLATILE, ACC_TRANSIENT - }; - - private static final int[] fieldFlags = { - ACC_PUBLIC, ACC_PRIVATE, ACC_PROTECTED, ACC_STATIC, ACC_FINAL, - ACC_VOLATILE, ACC_TRANSIENT, ACC_SYNTHETIC, ACC_ENUM - }; - - public Set<String> getFieldModifiers() { - return getModifiers(fieldModifiers, Kind.Field); - } - - public Set<String> getFieldFlags() { - return getFlags(fieldFlags, Kind.Field); - } - - private static final int[] methodModifiers = { - ACC_PUBLIC, ACC_PRIVATE, ACC_PROTECTED, ACC_STATIC, ACC_FINAL, - ACC_SYNCHRONIZED, ACC_NATIVE, ACC_ABSTRACT, ACC_STRICT - }; - - private static final int[] methodFlags = { - ACC_PUBLIC, ACC_PRIVATE, ACC_PROTECTED, ACC_STATIC, ACC_FINAL, - ACC_SYNCHRONIZED, ACC_BRIDGE, ACC_VARARGS, ACC_NATIVE, ACC_ABSTRACT, - ACC_STRICT, ACC_SYNTHETIC - }; - - public Set<String> getMethodModifiers() { - return getModifiers(methodModifiers, Kind.Method); - } - - public Set<String> getMethodFlags() { - return getFlags(methodFlags, Kind.Method); - } - - private Set<String> getModifiers(int[] modifierFlags, Kind t) { - return getModifiers(flags, modifierFlags, t); - } - - private static Set<String> getModifiers(int flags, int[] modifierFlags, Kind t) { - Set<String> s = new LinkedHashSet<>(); - for (int m: modifierFlags) { - if ((flags & m) != 0) - s.add(flagToModifier(m, t)); - } - return s; - } - - private Set<String> getFlags(int[] expectedFlags, Kind t) { - Set<String> s = new LinkedHashSet<>(); - int f = flags; - for (int e: expectedFlags) { - if ((f & e) != 0) { - s.add(flagToName(e, t)); - f = f & ~e; - } - } - while (f != 0) { - int bit = Integer.highestOneBit(f); - s.add("0x" + Integer.toHexString(bit)); - f = f & ~bit; - } - return s; - } - - private static String flagToModifier(int flag, Kind t) { - switch (flag) { - case ACC_PUBLIC: - return "public"; - case ACC_PRIVATE: - return "private"; - case ACC_PROTECTED: - return "protected"; - case ACC_STATIC: - return "static"; - case ACC_FINAL: - return "final"; - case ACC_SYNCHRONIZED: - return "synchronized"; - case 0x80: - return (t == Kind.Field ? "transient" : null); - case ACC_VOLATILE: - return "volatile"; - case ACC_NATIVE: - return "native"; - case ACC_ABSTRACT: - return "abstract"; - case ACC_STRICT: - return "strictfp"; - case ACC_MANDATED: - return "mandated"; - default: - return null; - } - } - - private static String flagToName(int flag, Kind t) { - switch (flag) { - case ACC_PUBLIC: - return "ACC_PUBLIC"; - case ACC_PRIVATE: - return "ACC_PRIVATE"; - case ACC_PROTECTED: - return "ACC_PROTECTED"; - case ACC_STATIC: - return "ACC_STATIC"; - case ACC_FINAL: - return "ACC_FINAL"; - case 0x20: - return (t == Kind.Class ? "ACC_SUPER" : "ACC_SYNCHRONIZED"); - case 0x40: - return (t == Kind.Field ? "ACC_VOLATILE" : "ACC_BRIDGE"); - case 0x80: - return (t == Kind.Field ? "ACC_TRANSIENT" : "ACC_VARARGS"); - case ACC_NATIVE: - return "ACC_NATIVE"; - case ACC_INTERFACE: - return "ACC_INTERFACE"; - case ACC_ABSTRACT: - return "ACC_ABSTRACT"; - case ACC_STRICT: - return "ACC_STRICT"; - case ACC_SYNTHETIC: - return "ACC_SYNTHETIC"; - case ACC_ANNOTATION: - return "ACC_ANNOTATION"; - case ACC_ENUM: - return "ACC_ENUM"; - case ACC_MANDATED: - return "ACC_MANDATED"; - default: - return null; - } - } - - public final int flags; -}
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/classfile/Annotation.java Thu May 28 16:13:55 2015 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,244 +0,0 @@ -/* - * Copyright (c) 2007, 2009, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package com.sun.tools.classfile; - -import java.io.IOException; - -/** - * See JVMS, section 4.8.16. - * - * <p><b>This is NOT part of any supported API. - * If you write code that depends on this, you do so at your own risk. - * This code and its internal interfaces are subject to change or - * deletion without notice.</b> - */ -public class Annotation { - static class InvalidAnnotation extends AttributeException { - private static final long serialVersionUID = -4620480740735772708L; - InvalidAnnotation(String msg) { - super(msg); - } - } - - Annotation(ClassReader cr) throws IOException, InvalidAnnotation { - type_index = cr.readUnsignedShort(); - num_element_value_pairs = cr.readUnsignedShort(); - element_value_pairs = new element_value_pair[num_element_value_pairs]; - for (int i = 0; i < element_value_pairs.length; i++) - element_value_pairs[i] = new element_value_pair(cr); - } - - public Annotation(ConstantPool constant_pool, - int type_index, - element_value_pair[] element_value_pairs) { - this.type_index = type_index; - num_element_value_pairs = element_value_pairs.length; - this.element_value_pairs = element_value_pairs; - } - - public int length() { - int n = 2 /*type_index*/ + 2 /*num_element_value_pairs*/; - for (element_value_pair pair: element_value_pairs) - n += pair.length(); - return n; - } - - public final int type_index; - public final int num_element_value_pairs; - public final element_value_pair element_value_pairs[]; - - /** - * See JVMS, section 4.8.16.1. - */ - public static abstract class element_value { - public static element_value read(ClassReader cr) - throws IOException, InvalidAnnotation { - int tag = cr.readUnsignedByte(); - switch (tag) { - case 'B': - case 'C': - case 'D': - case 'F': - case 'I': - case 'J': - case 'S': - case 'Z': - case 's': - return new Primitive_element_value(cr, tag); - - case 'e': - return new Enum_element_value(cr, tag); - - case 'c': - return new Class_element_value(cr, tag); - - case '@': - return new Annotation_element_value(cr, tag); - - case '[': - return new Array_element_value(cr, tag); - - default: - throw new InvalidAnnotation("unrecognized tag: " + tag); - } - } - - protected element_value(int tag) { - this.tag = tag; - } - - public abstract int length(); - - public abstract <R,P> R accept(Visitor<R,P> visitor, P p); - - public interface Visitor<R,P> { - R visitPrimitive(Primitive_element_value ev, P p); - R visitEnum(Enum_element_value ev, P p); - R visitClass(Class_element_value ev, P p); - R visitAnnotation(Annotation_element_value ev, P p); - R visitArray(Array_element_value ev, P p); - } - - public final int tag; - } - - public static class Primitive_element_value extends element_value { - Primitive_element_value(ClassReader cr, int tag) throws IOException { - super(tag); - const_value_index = cr.readUnsignedShort(); - } - - @Override - public int length() { - return 2; - } - - public <R,P> R accept(Visitor<R,P> visitor, P p) { - return visitor.visitPrimitive(this, p); - } - - public final int const_value_index; - - } - - public static class Enum_element_value extends element_value { - Enum_element_value(ClassReader cr, int tag) throws IOException { - super(tag); - type_name_index = cr.readUnsignedShort(); - const_name_index = cr.readUnsignedShort(); - } - - @Override - public int length() { - return 4; - } - - public <R,P> R accept(Visitor<R,P> visitor, P p) { - return visitor.visitEnum(this, p); - } - - public final int type_name_index; - public final int const_name_index; - } - - public static class Class_element_value extends element_value { - Class_element_value(ClassReader cr, int tag) throws IOException { - super(tag); - class_info_index = cr.readUnsignedShort(); - } - - @Override - public int length() { - return 2; - } - - public <R,P> R accept(Visitor<R,P> visitor, P p) { - return visitor.visitClass(this, p); - } - - public final int class_info_index; - } - - public static class Annotation_element_value extends element_value { - Annotation_element_value(ClassReader cr, int tag) - throws IOException, InvalidAnnotation { - super(tag); - annotation_value = new Annotation(cr); - } - - @Override - public int length() { - return annotation_value.length(); - } - - public <R,P> R accept(Visitor<R,P> visitor, P p) { - return visitor.visitAnnotation(this, p); - } - - public final Annotation annotation_value; - } - - public static class Array_element_value extends element_value { - Array_element_value(ClassReader cr, int tag) - throws IOException, InvalidAnnotation { - super(tag); - num_values = cr.readUnsignedShort(); - values = new element_value[num_values]; - for (int i = 0; i < values.length; i++) - values[i] = element_value.read(cr); - } - - @Override - public int length() { - int n = 2; - for (int i = 0; i < values.length; i++) - n += values[i].length(); - return n; - } - - public <R,P> R accept(Visitor<R,P> visitor, P p) { - return visitor.visitArray(this, p); - } - - public final int num_values; - public final element_value[] values; - } - - public static class element_value_pair { - element_value_pair(ClassReader cr) - throws IOException, InvalidAnnotation { - element_name_index = cr.readUnsignedShort(); - value = element_value.read(cr); - } - - public int length() { - return 2 + value.length(); - } - - public final int element_name_index; - public final element_value value; - } -}
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/classfile/AnnotationDefault_attribute.java Thu May 28 16:13:55 2015 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,61 +0,0 @@ -/* - * Copyright (c) 2007, 2008, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package com.sun.tools.classfile; - -import java.io.IOException; - -/** - * See JVMS, section 4.8.15. - * - * <p><b>This is NOT part of any supported API. - * If you write code that depends on this, you do so at your own risk. - * This code and its internal interfaces are subject to change or - * deletion without notice.</b> - */ -public class AnnotationDefault_attribute extends Attribute { - AnnotationDefault_attribute(ClassReader cr, int name_index, int length) - throws IOException, Annotation.InvalidAnnotation { - super(name_index, length); - default_value = Annotation.element_value.read(cr); - } - - public AnnotationDefault_attribute(ConstantPool constant_pool, Annotation.element_value default_value) - throws ConstantPoolException { - this(constant_pool.getUTF8Index(Attribute.AnnotationDefault), default_value); - } - - public AnnotationDefault_attribute(int name_index, Annotation.element_value default_value) { - super(name_index, default_value.length()); - this.default_value = default_value; - } - - public <R, D> R accept(Visitor<R, D> visitor, D data) { - return visitor.visitAnnotationDefault(this, data); - } - - public final Annotation.element_value default_value; -} -
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/classfile/Attribute.java Thu May 28 16:13:55 2015 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,192 +0,0 @@ -/* - * Copyright (c) 2007, 2014, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package com.sun.tools.classfile; - -import java.io.IOException; -import java.lang.reflect.Constructor; -import java.util.HashMap; -import java.util.Map; - -/** - * <p><b>This is NOT part of any supported API. - * If you write code that depends on this, you do so at your own risk. - * This code and its internal interfaces are subject to change or - * deletion without notice.</b> - */ - -public abstract class Attribute { - public static final String AnnotationDefault = "AnnotationDefault"; - public static final String BootstrapMethods = "BootstrapMethods"; - public static final String CharacterRangeTable = "CharacterRangeTable"; - public static final String Code = "Code"; - public static final String ConstantValue = "ConstantValue"; - public static final String CompilationID = "CompilationID"; - public static final String Deprecated = "Deprecated"; - public static final String EnclosingMethod = "EnclosingMethod"; - public static final String Exceptions = "Exceptions"; - public static final String InnerClasses = "InnerClasses"; - public static final String LineNumberTable = "LineNumberTable"; - public static final String LocalVariableTable = "LocalVariableTable"; - public static final String LocalVariableTypeTable = "LocalVariableTypeTable"; - public static final String MethodParameters = "MethodParameters"; - public static final String RuntimeVisibleAnnotations = "RuntimeVisibleAnnotations"; - public static final String RuntimeInvisibleAnnotations = "RuntimeInvisibleAnnotations"; - public static final String RuntimeVisibleParameterAnnotations = "RuntimeVisibleParameterAnnotations"; - public static final String RuntimeInvisibleParameterAnnotations = "RuntimeInvisibleParameterAnnotations"; - public static final String RuntimeVisibleTypeAnnotations = "RuntimeVisibleTypeAnnotations"; - public static final String RuntimeInvisibleTypeAnnotations = "RuntimeInvisibleTypeAnnotations"; - public static final String Signature = "Signature"; - public static final String SourceDebugExtension = "SourceDebugExtension"; - public static final String SourceFile = "SourceFile"; - public static final String SourceID = "SourceID"; - public static final String StackMap = "StackMap"; - public static final String StackMapTable = "StackMapTable"; - public static final String Synthetic = "Synthetic"; - - public static class Factory { - public Factory() { - // defer init of standardAttributeClasses until after options set up - } - - public Attribute createAttribute(ClassReader cr, int name_index, byte[] data) - throws IOException { - if (standardAttributes == null) { - init(); - } - - ConstantPool cp = cr.getConstantPool(); - String reasonForDefaultAttr; - try { - String name = cp.getUTF8Value(name_index); - Class<? extends Attribute> attrClass = standardAttributes.get(name); - if (attrClass != null) { - try { - Class<?>[] constrArgTypes = {ClassReader.class, int.class, int.class}; - Constructor<? extends Attribute> constr = attrClass.getDeclaredConstructor(constrArgTypes); - return constr.newInstance(cr, name_index, data.length); - } catch (Throwable t) { - reasonForDefaultAttr = t.toString(); - // fall through and use DefaultAttribute - // t.printStackTrace(); - } - } else { - reasonForDefaultAttr = "unknown attribute"; - } - } catch (ConstantPoolException e) { - reasonForDefaultAttr = e.toString(); - // fall through and use DefaultAttribute - } - return new DefaultAttribute(cr, name_index, data, reasonForDefaultAttr); - } - - protected void init() { - standardAttributes = new HashMap<>(); - standardAttributes.put(AnnotationDefault, AnnotationDefault_attribute.class); - standardAttributes.put(BootstrapMethods, BootstrapMethods_attribute.class); - standardAttributes.put(CharacterRangeTable, CharacterRangeTable_attribute.class); - standardAttributes.put(Code, Code_attribute.class); - standardAttributes.put(CompilationID, CompilationID_attribute.class); - standardAttributes.put(ConstantValue, ConstantValue_attribute.class); - standardAttributes.put(Deprecated, Deprecated_attribute.class); - standardAttributes.put(EnclosingMethod, EnclosingMethod_attribute.class); - standardAttributes.put(Exceptions, Exceptions_attribute.class); - standardAttributes.put(InnerClasses, InnerClasses_attribute.class); - standardAttributes.put(LineNumberTable, LineNumberTable_attribute.class); - standardAttributes.put(LocalVariableTable, LocalVariableTable_attribute.class); - standardAttributes.put(LocalVariableTypeTable, LocalVariableTypeTable_attribute.class); - standardAttributes.put(MethodParameters, MethodParameters_attribute.class); - standardAttributes.put(RuntimeInvisibleAnnotations, RuntimeInvisibleAnnotations_attribute.class); - standardAttributes.put(RuntimeInvisibleParameterAnnotations, RuntimeInvisibleParameterAnnotations_attribute.class); - standardAttributes.put(RuntimeVisibleAnnotations, RuntimeVisibleAnnotations_attribute.class); - standardAttributes.put(RuntimeVisibleParameterAnnotations, RuntimeVisibleParameterAnnotations_attribute.class); - standardAttributes.put(RuntimeVisibleTypeAnnotations, RuntimeVisibleTypeAnnotations_attribute.class); - standardAttributes.put(RuntimeInvisibleTypeAnnotations, RuntimeInvisibleTypeAnnotations_attribute.class); - standardAttributes.put(Signature, Signature_attribute.class); - standardAttributes.put(SourceDebugExtension, SourceDebugExtension_attribute.class); - standardAttributes.put(SourceFile, SourceFile_attribute.class); - standardAttributes.put(SourceID, SourceID_attribute.class); - standardAttributes.put(StackMap, StackMap_attribute.class); - standardAttributes.put(StackMapTable, StackMapTable_attribute.class); - standardAttributes.put(Synthetic, Synthetic_attribute.class); - } - - private Map<String,Class<? extends Attribute>> standardAttributes; - } - - public static Attribute read(ClassReader cr) throws IOException { - return cr.readAttribute(); - } - - protected Attribute(int name_index, int length) { - attribute_name_index = name_index; - attribute_length = length; - } - - public String getName(ConstantPool constant_pool) throws ConstantPoolException { - return constant_pool.getUTF8Value(attribute_name_index); - } - - public abstract <R,D> R accept(Attribute.Visitor<R,D> visitor, D data); - - public int byteLength() { - return 6 + attribute_length; - } - - public final int attribute_name_index; - public final int attribute_length; - - - public interface Visitor<R,P> { - R visitBootstrapMethods(BootstrapMethods_attribute attr, P p); - R visitDefault(DefaultAttribute attr, P p); - R visitAnnotationDefault(AnnotationDefault_attribute attr, P p); - R visitCharacterRangeTable(CharacterRangeTable_attribute attr, P p); - R visitCode(Code_attribute attr, P p); - R visitCompilationID(CompilationID_attribute attr, P p); - R visitConstantValue(ConstantValue_attribute attr, P p); - R visitDeprecated(Deprecated_attribute attr, P p); - R visitEnclosingMethod(EnclosingMethod_attribute attr, P p); - R visitExceptions(Exceptions_attribute attr, P p); - R visitInnerClasses(InnerClasses_attribute attr, P p); - R visitLineNumberTable(LineNumberTable_attribute attr, P p); - R visitLocalVariableTable(LocalVariableTable_attribute attr, P p); - R visitLocalVariableTypeTable(LocalVariableTypeTable_attribute attr, P p); - R visitMethodParameters(MethodParameters_attribute attr, P p); - R visitRuntimeVisibleAnnotations(RuntimeVisibleAnnotations_attribute attr, P p); - R visitRuntimeInvisibleAnnotations(RuntimeInvisibleAnnotations_attribute attr, P p); - R visitRuntimeVisibleParameterAnnotations(RuntimeVisibleParameterAnnotations_attribute attr, P p); - R visitRuntimeInvisibleParameterAnnotations(RuntimeInvisibleParameterAnnotations_attribute attr, P p); - R visitRuntimeVisibleTypeAnnotations(RuntimeVisibleTypeAnnotations_attribute attr, P p); - R visitRuntimeInvisibleTypeAnnotations(RuntimeInvisibleTypeAnnotations_attribute attr, P p); - R visitSignature(Signature_attribute attr, P p); - R visitSourceDebugExtension(SourceDebugExtension_attribute attr, P p); - R visitSourceFile(SourceFile_attribute attr, P p); - R visitSourceID(SourceID_attribute attr, P p); - R visitStackMap(StackMap_attribute attr, P p); - R visitStackMapTable(StackMapTable_attribute attr, P p); - R visitSynthetic(Synthetic_attribute attr, P p); - } -}
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/classfile/AttributeException.java Thu May 28 16:13:55 2015 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,41 +0,0 @@ -/* - * Copyright (c) 2008, 2009, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package com.sun.tools.classfile; - -/* - * <p><b>This is NOT part of any supported API. - * If you write code that depends on this, you do so at your own risk. - * This code and its internal interfaces are subject to change or - * deletion without notice.</b> - */ -public class AttributeException extends Exception { - private static final long serialVersionUID = -4231486387714867770L; - AttributeException() { } - - AttributeException(String msg) { - super(msg); - } -}
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/classfile/Attributes.java Thu May 28 16:13:55 2015 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,107 +0,0 @@ -/* - * Copyright (c) 2007, 2008, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package com.sun.tools.classfile; - -import java.io.IOException; -import java.util.Arrays; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; - -/* - * <p><b>This is NOT part of any supported API. - * If you write code that depends on this, you do so at your own risk. - * This code and its internal interfaces are subject to change or - * deletion without notice.</b> - */ -public class Attributes implements Iterable<Attribute> { - - public final Attribute[] attrs; - public final Map<String, Attribute> map; - - Attributes(ClassReader cr) throws IOException { - map = new HashMap<>(); - int attrs_count = cr.readUnsignedShort(); - attrs = new Attribute[attrs_count]; - for (int i = 0; i < attrs_count; i++) { - Attribute attr = Attribute.read(cr); - attrs[i] = attr; - try { - map.put(attr.getName(cr.getConstantPool()), attr); - } catch (ConstantPoolException e) { - // don't enter invalid names in map - } - } - } - - public Attributes(ConstantPool constant_pool, Attribute[] attrs) { - this.attrs = attrs; - map = new HashMap<>(); - for (Attribute attr : attrs) { - try { - map.put(attr.getName(constant_pool), attr); - } catch (ConstantPoolException e) { - // don't enter invalid names in map - } - } - } - - public Iterator<Attribute> iterator() { - return Arrays.asList(attrs).iterator(); - } - - public Attribute get(int index) { - return attrs[index]; - } - - public Attribute get(String name) { - return map.get(name); - } - - public int getIndex(ConstantPool constant_pool, String name) { - for (int i = 0; i < attrs.length; i++) { - Attribute attr = attrs[i]; - try { - if (attr != null && attr.getName(constant_pool).equals(name)) - return i; - } catch (ConstantPoolException e) { - // ignore invalid entries - } - } - return -1; - } - - public int size() { - return attrs.length; - } - - public int byteLength() { - int length = 2; - for (Attribute a: attrs) - length += a.byteLength(); - return length; - } -}
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/classfile/BootstrapMethods_attribute.java Thu May 28 16:13:55 2015 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,90 +0,0 @@ -/* - * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package com.sun.tools.classfile; - -import java.io.IOException; - -/** - * See JVMS 4.7.21 - * http://docs.oracle.com/javase/specs/jvms/se7/html/jvms-4.html#jvms-4.7.21 - * - * <p><b>This is NOT part of any supported API. - * If you write code that depends on this, you do so at your own risk. - * This code and its internal interfaces are subject to change or - * deletion without notice.</b> - */ -public class BootstrapMethods_attribute extends Attribute { - public final BootstrapMethodSpecifier[] bootstrap_method_specifiers; - - BootstrapMethods_attribute(ClassReader cr, int name_index, int length) - throws IOException, AttributeException { - super(name_index, length); - int bootstrap_method_count = cr.readUnsignedShort(); - bootstrap_method_specifiers = new BootstrapMethodSpecifier[bootstrap_method_count]; - for (int i = 0; i < bootstrap_method_specifiers.length; i++) - bootstrap_method_specifiers[i] = new BootstrapMethodSpecifier(cr); - } - - public BootstrapMethods_attribute(int name_index, BootstrapMethodSpecifier[] bootstrap_method_specifiers) { - super(name_index, length(bootstrap_method_specifiers)); - this.bootstrap_method_specifiers = bootstrap_method_specifiers; - } - - public static int length(BootstrapMethodSpecifier[] bootstrap_method_specifiers) { - int n = 2; - for (BootstrapMethodSpecifier b : bootstrap_method_specifiers) - n += b.length(); - return n; - } - - @Override - public <R, P> R accept(Visitor<R, P> visitor, P p) { - return visitor.visitBootstrapMethods(this, p); - } - - public static class BootstrapMethodSpecifier { - public int bootstrap_method_ref; - public int[] bootstrap_arguments; - - public BootstrapMethodSpecifier(int bootstrap_method_ref, int[] bootstrap_arguments) { - this.bootstrap_method_ref = bootstrap_method_ref; - this.bootstrap_arguments = bootstrap_arguments; - } - BootstrapMethodSpecifier(ClassReader cr) throws IOException { - bootstrap_method_ref = cr.readUnsignedShort(); - int method_count = cr.readUnsignedShort(); - bootstrap_arguments = new int[method_count]; - for (int i = 0; i < bootstrap_arguments.length; i++) { - bootstrap_arguments[i] = cr.readUnsignedShort(); - } - } - - int length() { - // u2 (method_ref) + u2 (argc) + u2 * argc - return 2 + 2 + (bootstrap_arguments.length * 2); - } - } -}
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/classfile/CharacterRangeTable_attribute.java Thu May 28 16:13:55 2015 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,90 +0,0 @@ -/* - * Copyright (c) 2007, 2008, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package com.sun.tools.classfile; - -import java.io.IOException; - -/** - * <p><b>This is NOT part of any supported API. - * If you write code that depends on this, you do so at your own risk. - * This code and its internal interfaces are subject to change or - * deletion without notice.</b> - */ -public class CharacterRangeTable_attribute extends Attribute { - public static final int CRT_STATEMENT = 0x0001; - public static final int CRT_BLOCK = 0x0002; - public static final int CRT_ASSIGNMENT = 0x0004; - public static final int CRT_FLOW_CONTROLLER = 0x0008; - public static final int CRT_FLOW_TARGET = 0x0010; - public static final int CRT_INVOKE = 0x0020; - public static final int CRT_CREATE = 0x0040; - public static final int CRT_BRANCH_TRUE = 0x0080; - public static final int CRT_BRANCH_FALSE = 0x0100; - - CharacterRangeTable_attribute(ClassReader cr, int name_index, int length) throws IOException { - super(name_index, length); - int character_range_table_length = cr.readUnsignedShort(); - character_range_table = new Entry[character_range_table_length]; - for (int i = 0; i < character_range_table_length; i++) - character_range_table[i] = new Entry(cr); - } - - public CharacterRangeTable_attribute(ConstantPool constant_pool, Entry[] character_range_table) - throws ConstantPoolException { - this(constant_pool.getUTF8Index(Attribute.CharacterRangeTable), character_range_table); - } - - public CharacterRangeTable_attribute(int name_index, Entry[] character_range_table) { - super(name_index, 2 + character_range_table.length * Entry.length()); - this.character_range_table = character_range_table; - } - - public <R, D> R accept(Visitor<R, D> visitor, D data) { - return visitor.visitCharacterRangeTable(this, data); - } - - public final Entry[] character_range_table; - - public static class Entry { - Entry(ClassReader cr) throws IOException { - start_pc = cr.readUnsignedShort(); - end_pc = cr.readUnsignedShort(); - character_range_start = cr.readInt(); - character_range_end = cr.readInt(); - flags = cr.readUnsignedShort(); - } - - public static int length() { - return 14; - } - - public final int start_pc; - public final int end_pc; - public final int character_range_start; - public final int character_range_end; - public final int flags; - } -}
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/classfile/ClassFile.java Thu May 28 16:13:55 2015 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,189 +0,0 @@ -/* - * Copyright (c) 2007, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package com.sun.tools.classfile; - -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.nio.file.Files; -import java.nio.file.Path; - -import static com.sun.tools.classfile.AccessFlags.*; - -/** - * See JVMS, section 4.2. - * - * <p><b>This is NOT part of any supported API. - * If you write code that depends on this, you do so at your own risk. - * This code and its internal interfaces are subject to change or - * deletion without notice.</b> - */ -public class ClassFile { - public static ClassFile read(File file) - throws IOException, ConstantPoolException { - return read(file.toPath(), new Attribute.Factory()); - } - - public static ClassFile read(Path input) - throws IOException, ConstantPoolException { - return read(input, new Attribute.Factory()); - } - - public static ClassFile read(Path input, Attribute.Factory attributeFactory) - throws IOException, ConstantPoolException { - try (InputStream in = Files.newInputStream(input)) { - return new ClassFile(in, attributeFactory); - } - } - - public static ClassFile read(File file, Attribute.Factory attributeFactory) - throws IOException, ConstantPoolException { - return read(file.toPath(), attributeFactory); - } - - public static ClassFile read(InputStream in) - throws IOException, ConstantPoolException { - return new ClassFile(in, new Attribute.Factory()); - } - - public static ClassFile read(InputStream in, Attribute.Factory attributeFactory) - throws IOException, ConstantPoolException { - return new ClassFile(in, attributeFactory); - } - - ClassFile(InputStream in, Attribute.Factory attributeFactory) throws IOException, ConstantPoolException { - ClassReader cr = new ClassReader(this, in, attributeFactory); - magic = cr.readInt(); - minor_version = cr.readUnsignedShort(); - major_version = cr.readUnsignedShort(); - constant_pool = new ConstantPool(cr); - access_flags = new AccessFlags(cr); - this_class = cr.readUnsignedShort(); - super_class = cr.readUnsignedShort(); - - int interfaces_count = cr.readUnsignedShort(); - interfaces = new int[interfaces_count]; - for (int i = 0; i < interfaces_count; i++) - interfaces[i] = cr.readUnsignedShort(); - - int fields_count = cr.readUnsignedShort(); - fields = new Field[fields_count]; - for (int i = 0; i < fields_count; i++) - fields[i] = new Field(cr); - - int methods_count = cr.readUnsignedShort(); - methods = new Method[methods_count]; - for (int i = 0; i < methods_count; i++) - methods[i] = new Method(cr); - - attributes = new Attributes(cr); - } - - public ClassFile(int magic, int minor_version, int major_version, - ConstantPool constant_pool, AccessFlags access_flags, - int this_class, int super_class, int[] interfaces, - Field[] fields, Method[] methods, Attributes attributes) { - this.magic = magic; - this.minor_version = minor_version; - this.major_version = major_version; - this.constant_pool = constant_pool; - this.access_flags = access_flags; - this.this_class = this_class; - this.super_class = super_class; - this.interfaces = interfaces; - this.fields = fields; - this.methods = methods; - this.attributes = attributes; - } - - public String getName() throws ConstantPoolException { - return constant_pool.getClassInfo(this_class).getName(); - } - - public String getSuperclassName() throws ConstantPoolException { - return constant_pool.getClassInfo(super_class).getName(); - } - - public String getInterfaceName(int i) throws ConstantPoolException { - return constant_pool.getClassInfo(interfaces[i]).getName(); - } - - public Attribute getAttribute(String name) { - return attributes.get(name); - } - - public boolean isClass() { - return !isInterface(); - } - - public boolean isInterface() { - return access_flags.is(ACC_INTERFACE); - } - - public int byteLength() { - return 4 + // magic - 2 + // minor - 2 + // major - constant_pool.byteLength() + - 2 + // access flags - 2 + // this_class - 2 + // super_class - byteLength(interfaces) + - byteLength(fields) + - byteLength(methods) + - attributes.byteLength(); - } - - private int byteLength(int[] indices) { - return 2 + 2 * indices.length; - } - - private int byteLength(Field[] fields) { - int length = 2; - for (Field f: fields) - length += f.byteLength(); - return length; - } - - private int byteLength(Method[] methods) { - int length = 2; - for (Method m: methods) - length += m.byteLength(); - return length; - } - - public final int magic; - public final int minor_version; - public final int major_version; - public final ConstantPool constant_pool; - public final AccessFlags access_flags; - public final int this_class; - public final int super_class; - public final int[] interfaces; - public final Field[] fields; - public final Method[] methods; - public final Attributes attributes; -}
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/classfile/ClassReader.java Thu May 28 16:13:55 2015 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,106 +0,0 @@ -/* - * Copyright (c) 2007, 2008, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package com.sun.tools.classfile; - -import java.io.BufferedInputStream; -import java.io.ByteArrayInputStream; -import java.io.DataInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.util.Objects; - -/** - * <p><b>This is NOT part of any supported API. - * If you write code that depends on this, you do so at your own risk. - * This code and its internal interfaces are subject to change or - * deletion without notice.</b> - */ -public class ClassReader { - ClassReader(ClassFile classFile, InputStream in, Attribute.Factory attributeFactory) throws IOException { - this.classFile = Objects.requireNonNull(classFile); - this.attributeFactory = Objects.requireNonNull(attributeFactory); - this.in = new DataInputStream(new BufferedInputStream(in)); - } - - ClassFile getClassFile() { - return classFile; - } - - ConstantPool getConstantPool() { - return classFile.constant_pool; - } - - public Attribute readAttribute() throws IOException { - int name_index = readUnsignedShort(); - int length = readInt(); - byte[] data = new byte[length]; - readFully(data); - - DataInputStream prev = in; - in = new DataInputStream(new ByteArrayInputStream(data)); - try { - return attributeFactory.createAttribute(this, name_index, data); - } finally { - in = prev; - } - } - - public void readFully(byte[] b) throws IOException { - in.readFully(b); - } - - public int readUnsignedByte() throws IOException { - return in.readUnsignedByte(); - } - - public int readUnsignedShort() throws IOException { - return in.readUnsignedShort(); - } - - public int readInt() throws IOException { - return in.readInt(); - } - - public long readLong() throws IOException { - return in.readLong(); - } - - public float readFloat() throws IOException { - return in.readFloat(); - } - - public double readDouble() throws IOException { - return in.readDouble(); - } - - public String readUTF() throws IOException { - return in.readUTF(); - } - - private DataInputStream in; - private ClassFile classFile; - private Attribute.Factory attributeFactory; -}
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/classfile/ClassTranslator.java Thu May 28 16:13:55 2015 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,410 +0,0 @@ -/* - * Copyright (c) 2008, 2012, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package com.sun.tools.classfile; - -import java.util.Map; - -import com.sun.tools.classfile.ConstantPool.CONSTANT_Class_info; -import com.sun.tools.classfile.ConstantPool.CONSTANT_Double_info; -import com.sun.tools.classfile.ConstantPool.CONSTANT_Fieldref_info; -import com.sun.tools.classfile.ConstantPool.CONSTANT_Float_info; -import com.sun.tools.classfile.ConstantPool.CONSTANT_Integer_info; -import com.sun.tools.classfile.ConstantPool.CONSTANT_InterfaceMethodref_info; -import com.sun.tools.classfile.ConstantPool.CONSTANT_InvokeDynamic_info; -import com.sun.tools.classfile.ConstantPool.CONSTANT_Long_info; -import com.sun.tools.classfile.ConstantPool.CONSTANT_MethodHandle_info; -import com.sun.tools.classfile.ConstantPool.CONSTANT_MethodType_info; -import com.sun.tools.classfile.ConstantPool.CONSTANT_Methodref_info; -import com.sun.tools.classfile.ConstantPool.CONSTANT_NameAndType_info; -import com.sun.tools.classfile.ConstantPool.CONSTANT_String_info; -import com.sun.tools.classfile.ConstantPool.CONSTANT_Utf8_info; -import com.sun.tools.classfile.ConstantPool.CPInfo; - -/** - * Rewrites a class file using a map of translations. - * - * <p><b>This is NOT part of any supported API. - * If you write code that depends on this, you do so at your own risk. - * This code and its internal interfaces are subject to change or - * deletion without notice.</b> - */ -public class ClassTranslator - implements ConstantPool.Visitor<ConstantPool.CPInfo,Map<Object,Object>> { - /** - * Create a new ClassFile from {@code cf}, such that for all entries - * {@code k -\> v} in {@code translations}, - * each occurrence of {@code k} in {@code cf} will be replaced by {@code v}. - * in - * @param cf the class file to be processed - * @param translations the set of translations to be applied - * @return a copy of {@code} with the values in {@code translations} substituted - */ - public ClassFile translate(ClassFile cf, Map<Object,Object> translations) { - ClassFile cf2 = (ClassFile) translations.get(cf); - if (cf2 == null) { - ConstantPool constant_pool2 = translate(cf.constant_pool, translations); - Field[] fields2 = translate(cf.fields, cf.constant_pool, translations); - Method[] methods2 = translateMethods(cf.methods, cf.constant_pool, translations); - Attributes attributes2 = translateAttributes(cf.attributes, cf.constant_pool, - translations); - - if (constant_pool2 == cf.constant_pool && - fields2 == cf.fields && - methods2 == cf.methods && - attributes2 == cf.attributes) - cf2 = cf; - else - cf2 = new ClassFile( - cf.magic, - cf.minor_version, - cf.major_version, - constant_pool2, - cf.access_flags, - cf.this_class, - cf.super_class, - cf.interfaces, - fields2, - methods2, - attributes2); - translations.put(cf, cf2); - } - return cf2; - } - - ConstantPool translate(ConstantPool cp, Map<Object,Object> translations) { - ConstantPool cp2 = (ConstantPool) translations.get(cp); - if (cp2 == null) { - ConstantPool.CPInfo[] pool2 = new ConstantPool.CPInfo[cp.size()]; - boolean eq = true; - for (int i = 0; i < cp.size(); ) { - ConstantPool.CPInfo cpInfo; - try { - cpInfo = cp.get(i); - } catch (ConstantPool.InvalidIndex e) { - throw new IllegalStateException(e); - } - ConstantPool.CPInfo cpInfo2 = translate(cpInfo, translations); - eq &= (cpInfo == cpInfo2); - pool2[i] = cpInfo2; - if (cpInfo.getTag() != cpInfo2.getTag()) - throw new IllegalStateException(); - i += cpInfo.size(); - } - - if (eq) - cp2 = cp; - else - cp2 = new ConstantPool(pool2); - - translations.put(cp, cp2); - } - return cp2; - } - - ConstantPool.CPInfo translate(ConstantPool.CPInfo cpInfo, Map<Object,Object> translations) { - ConstantPool.CPInfo cpInfo2 = (ConstantPool.CPInfo) translations.get(cpInfo); - if (cpInfo2 == null) { - cpInfo2 = cpInfo.accept(this, translations); - translations.put(cpInfo, cpInfo2); - } - return cpInfo2; - } - - Field[] translate(Field[] fields, ConstantPool constant_pool, Map<Object,Object> translations) { - Field[] fields2 = (Field[]) translations.get(fields); - if (fields2 == null) { - fields2 = new Field[fields.length]; - for (int i = 0; i < fields.length; i++) - fields2[i] = translate(fields[i], constant_pool, translations); - if (equal(fields, fields2)) - fields2 = fields; - translations.put(fields, fields2); - } - return fields2; - } - - Field translate(Field field, ConstantPool constant_pool, Map<Object,Object> translations) { - Field field2 = (Field) translations.get(field); - if (field2 == null) { - Attributes attributes2 = translateAttributes(field.attributes, constant_pool, - translations); - - if (attributes2 == field.attributes) - field2 = field; - else - field2 = new Field( - field.access_flags, - field.name_index, - field.descriptor, - attributes2); - translations.put(field, field2); - } - return field2; - } - - Method[] translateMethods(Method[] methods, ConstantPool constant_pool, Map<Object,Object> translations) { - Method[] methods2 = (Method[]) translations.get(methods); - if (methods2 == null) { - methods2 = new Method[methods.length]; - for (int i = 0; i < methods.length; i++) - methods2[i] = translate(methods[i], constant_pool, translations); - if (equal(methods, methods2)) - methods2 = methods; - translations.put(methods, methods2); - } - return methods2; - } - - Method translate(Method method, ConstantPool constant_pool, Map<Object,Object> translations) { - Method method2 = (Method) translations.get(method); - if (method2 == null) { - Attributes attributes2 = translateAttributes(method.attributes, constant_pool, - translations); - - if (attributes2 == method.attributes) - method2 = method; - else - method2 = new Method( - method.access_flags, - method.name_index, - method.descriptor, - attributes2); - translations.put(method, method2); - } - return method2; - } - - Attributes translateAttributes(Attributes attributes, - ConstantPool constant_pool, Map<Object,Object> translations) { - Attributes attributes2 = (Attributes) translations.get(attributes); - if (attributes2 == null) { - Attribute[] attrArray2 = new Attribute[attributes.size()]; - ConstantPool constant_pool2 = translate(constant_pool, translations); - boolean attrsEqual = true; - for (int i = 0; i < attributes.size(); i++) { - Attribute attr = attributes.get(i); - Attribute attr2 = translate(attr, translations); - if (attr2 != attr) - attrsEqual = false; - attrArray2[i] = attr2; - } - if ((constant_pool2 == constant_pool) && attrsEqual) - attributes2 = attributes; - else - attributes2 = new Attributes(constant_pool2, attrArray2); - translations.put(attributes, attributes2); - } - return attributes2; - } - - Attribute translate(Attribute attribute, Map<Object,Object> translations) { - Attribute attribute2 = (Attribute) translations.get(attribute); - if (attribute2 == null) { - attribute2 = attribute; // don't support translation within attributes yet - // (what about Code attribute) - translations.put(attribute, attribute2); - } - return attribute2; - } - - private static <T> boolean equal(T[] a1, T[] a2) { - if (a1 == null || a2 == null) - return (a1 == a2); - if (a1.length != a2.length) - return false; - for (int i = 0; i < a1.length; i++) { - if (a1[i] != a2[i]) - return false; - } - return true; - } - - public CPInfo visitClass(CONSTANT_Class_info info, Map<Object, Object> translations) { - CONSTANT_Class_info info2 = (CONSTANT_Class_info) translations.get(info); - if (info2 == null) { - ConstantPool cp2 = translate(info.cp, translations); - if (cp2 == info.cp) - info2 = info; - else - info2 = new CONSTANT_Class_info(cp2, info.name_index); - translations.put(info, info2); - } - return info; - } - - public CPInfo visitDouble(CONSTANT_Double_info info, Map<Object, Object> translations) { - CONSTANT_Double_info info2 = (CONSTANT_Double_info) translations.get(info); - if (info2 == null) { - info2 = info; - translations.put(info, info2); - } - return info; - } - - public CPInfo visitFieldref(CONSTANT_Fieldref_info info, Map<Object, Object> translations) { - CONSTANT_Fieldref_info info2 = (CONSTANT_Fieldref_info) translations.get(info); - if (info2 == null) { - ConstantPool cp2 = translate(info.cp, translations); - if (cp2 == info.cp) - info2 = info; - else - info2 = new CONSTANT_Fieldref_info(cp2, info.class_index, info.name_and_type_index); - translations.put(info, info2); - } - return info; - } - - public CPInfo visitFloat(CONSTANT_Float_info info, Map<Object, Object> translations) { - CONSTANT_Float_info info2 = (CONSTANT_Float_info) translations.get(info); - if (info2 == null) { - info2 = info; - translations.put(info, info2); - } - return info; - } - - public CPInfo visitInteger(CONSTANT_Integer_info info, Map<Object, Object> translations) { - CONSTANT_Integer_info info2 = (CONSTANT_Integer_info) translations.get(info); - if (info2 == null) { - info2 = info; - translations.put(info, info2); - } - return info; - } - - public CPInfo visitInterfaceMethodref(CONSTANT_InterfaceMethodref_info info, Map<Object, Object> translations) { - CONSTANT_InterfaceMethodref_info info2 = (CONSTANT_InterfaceMethodref_info) translations.get(info); - if (info2 == null) { - ConstantPool cp2 = translate(info.cp, translations); - if (cp2 == info.cp) - info2 = info; - else - info2 = new CONSTANT_InterfaceMethodref_info(cp2, info.class_index, info.name_and_type_index); - translations.put(info, info2); - } - return info; - } - - public CPInfo visitInvokeDynamic(CONSTANT_InvokeDynamic_info info, Map<Object, Object> translations) { - CONSTANT_InvokeDynamic_info info2 = (CONSTANT_InvokeDynamic_info) translations.get(info); - if (info2 == null) { - ConstantPool cp2 = translate(info.cp, translations); - if (cp2 == info.cp) { - info2 = info; - } else { - info2 = new CONSTANT_InvokeDynamic_info(cp2, info.bootstrap_method_attr_index, info.name_and_type_index); - } - translations.put(info, info2); - } - return info; - } - - public CPInfo visitLong(CONSTANT_Long_info info, Map<Object, Object> translations) { - CONSTANT_Long_info info2 = (CONSTANT_Long_info) translations.get(info); - if (info2 == null) { - info2 = info; - translations.put(info, info2); - } - return info; - } - - public CPInfo visitNameAndType(CONSTANT_NameAndType_info info, Map<Object, Object> translations) { - CONSTANT_NameAndType_info info2 = (CONSTANT_NameAndType_info) translations.get(info); - if (info2 == null) { - ConstantPool cp2 = translate(info.cp, translations); - if (cp2 == info.cp) - info2 = info; - else - info2 = new CONSTANT_NameAndType_info(cp2, info.name_index, info.type_index); - translations.put(info, info2); - } - return info; - } - - public CPInfo visitMethodref(CONSTANT_Methodref_info info, Map<Object, Object> translations) { - CONSTANT_Methodref_info info2 = (CONSTANT_Methodref_info) translations.get(info); - if (info2 == null) { - ConstantPool cp2 = translate(info.cp, translations); - if (cp2 == info.cp) - info2 = info; - else - info2 = new CONSTANT_Methodref_info(cp2, info.class_index, info.name_and_type_index); - translations.put(info, info2); - } - return info; - } - - public CPInfo visitMethodHandle(CONSTANT_MethodHandle_info info, Map<Object, Object> translations) { - CONSTANT_MethodHandle_info info2 = (CONSTANT_MethodHandle_info) translations.get(info); - if (info2 == null) { - ConstantPool cp2 = translate(info.cp, translations); - if (cp2 == info.cp) { - info2 = info; - } else { - info2 = new CONSTANT_MethodHandle_info(cp2, info.reference_kind, info.reference_index); - } - translations.put(info, info2); - } - return info; - } - - public CPInfo visitMethodType(CONSTANT_MethodType_info info, Map<Object, Object> translations) { - CONSTANT_MethodType_info info2 = (CONSTANT_MethodType_info) translations.get(info); - if (info2 == null) { - ConstantPool cp2 = translate(info.cp, translations); - if (cp2 == info.cp) { - info2 = info; - } else { - info2 = new CONSTANT_MethodType_info(cp2, info.descriptor_index); - } - translations.put(info, info2); - } - return info; - } - - public CPInfo visitString(CONSTANT_String_info info, Map<Object, Object> translations) { - CONSTANT_String_info info2 = (CONSTANT_String_info) translations.get(info); - if (info2 == null) { - ConstantPool cp2 = translate(info.cp, translations); - if (cp2 == info.cp) - info2 = info; - else - info2 = new CONSTANT_String_info(cp2, info.string_index); - translations.put(info, info2); - } - return info; - } - - public CPInfo visitUtf8(CONSTANT_Utf8_info info, Map<Object, Object> translations) { - CONSTANT_Utf8_info info2 = (CONSTANT_Utf8_info) translations.get(info); - if (info2 == null) { - info2 = info; - translations.put(info, info2); - } - return info; - } - -}
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/classfile/ClassWriter.java Thu May 28 16:13:55 2015 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,808 +0,0 @@ - -/* - * Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package com.sun.tools.classfile; - -import java.io.ByteArrayOutputStream; -import java.io.DataOutputStream; -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.OutputStream; - -import static com.sun.tools.classfile.Annotation.*; -import static com.sun.tools.classfile.ConstantPool.*; -import static com.sun.tools.classfile.StackMapTable_attribute.*; -import static com.sun.tools.classfile.StackMapTable_attribute.verification_type_info.*; - -/** - * Write a ClassFile data structure to a file or stream. - * - * <p><b>This is NOT part of any supported API. - * If you write code that depends on this, you do so at your own risk. - * This code and its internal interfaces are subject to change or - * deletion without notice.</b> - */ -public class ClassWriter { - public ClassWriter() { - attributeWriter = new AttributeWriter(); - constantPoolWriter = new ConstantPoolWriter(); - out = new ClassOutputStream(); - } - - /** - * Write a ClassFile data structure to a file. - */ - public void write(ClassFile classFile, File f) throws IOException { - try (FileOutputStream f_out = new FileOutputStream(f)) { - write(classFile, f_out); - } - } - - /** - * Write a ClassFile data structure to a stream. - */ - public void write(ClassFile classFile, OutputStream s) throws IOException { - this.classFile = classFile; - out.reset(); - write(); - out.writeTo(s); - } - - protected void write() throws IOException { - writeHeader(); - writeConstantPool(); - writeAccessFlags(classFile.access_flags); - writeClassInfo(); - writeFields(); - writeMethods(); - writeAttributes(classFile.attributes); - } - - protected void writeHeader() { - out.writeInt(classFile.magic); - out.writeShort(classFile.minor_version); - out.writeShort(classFile.major_version); - } - - protected void writeAccessFlags(AccessFlags flags) { - out.writeShort(flags.flags); - } - - protected void writeAttributes(Attributes attributes) { - int size = attributes.size(); - out.writeShort(size); - for (Attribute attr: attributes) - attributeWriter.write(attr, out); - } - - protected void writeClassInfo() { - out.writeShort(classFile.this_class); - out.writeShort(classFile.super_class); - int[] interfaces = classFile.interfaces; - out.writeShort(interfaces.length); - for (int i: interfaces) - out.writeShort(i); - } - - protected void writeDescriptor(Descriptor d) { - out.writeShort(d.index); - } - - protected void writeConstantPool() { - ConstantPool pool = classFile.constant_pool; - int size = pool.size(); - out.writeShort(size); - for (CPInfo cpInfo: pool.entries()) - constantPoolWriter.write(cpInfo, out); - } - - protected void writeFields() throws IOException { - Field[] fields = classFile.fields; - out.writeShort(fields.length); - for (Field f: fields) - writeField(f); - } - - protected void writeField(Field f) throws IOException { - writeAccessFlags(f.access_flags); - out.writeShort(f.name_index); - writeDescriptor(f.descriptor); - writeAttributes(f.attributes); - } - - protected void writeMethods() throws IOException { - Method[] methods = classFile.methods; - out.writeShort(methods.length); - for (Method m: methods) { - writeMethod(m); - } - } - - protected void writeMethod(Method m) throws IOException { - writeAccessFlags(m.access_flags); - out.writeShort(m.name_index); - writeDescriptor(m.descriptor); - writeAttributes(m.attributes); - } - - protected ClassFile classFile; - protected ClassOutputStream out; - protected AttributeWriter attributeWriter; - protected ConstantPoolWriter constantPoolWriter; - - /** - * Subtype of ByteArrayOutputStream with the convenience methods of - * a DataOutputStream. Since ByteArrayOutputStream does not throw - * IOException, there are no exceptions from the additional - * convenience methods either, - */ - protected static class ClassOutputStream extends ByteArrayOutputStream { - public ClassOutputStream() { - d = new DataOutputStream(this); - } - - public void writeByte(int value) { - try { - d.writeByte(value); - } catch (IOException ignore) { - } - } - - public void writeShort(int value) { - try { - d.writeShort(value); - } catch (IOException ignore) { - } - } - - public void writeInt(int value) { - try { - d.writeInt(value); - } catch (IOException ignore) { - } - } - - public void writeLong(long value) { - try { - d.writeLong(value); - } catch (IOException ignore) { - } - } - - public void writeFloat(float value) { - try { - d.writeFloat(value); - } catch (IOException ignore) { - } - } - - public void writeDouble(double value) { - try { - d.writeDouble(value); - } catch (IOException ignore) { - } - } - - public void writeUTF(String value) { - try { - d.writeUTF(value); - } catch (IOException ignore) { - } - } - - public void writeTo(ClassOutputStream s) { - try { - super.writeTo(s); - } catch (IOException ignore) { - } - } - - private DataOutputStream d; - } - - /** - * Writer for the entries in the constant pool. - */ - protected static class ConstantPoolWriter - implements ConstantPool.Visitor<Integer,ClassOutputStream> { - protected int write(CPInfo info, ClassOutputStream out) { - out.writeByte(info.getTag()); - return info.accept(this, out); - } - - public Integer visitClass(CONSTANT_Class_info info, ClassOutputStream out) { - out.writeShort(info.name_index); - return 1; - } - - public Integer visitDouble(CONSTANT_Double_info info, ClassOutputStream out) { - out.writeDouble(info.value); - return 2; - } - - public Integer visitFieldref(CONSTANT_Fieldref_info info, ClassOutputStream out) { - writeRef(info, out); - return 1; - } - - public Integer visitFloat(CONSTANT_Float_info info, ClassOutputStream out) { - out.writeFloat(info.value); - return 1; - } - - public Integer visitInteger(CONSTANT_Integer_info info, ClassOutputStream out) { - out.writeInt(info.value); - return 1; - } - - public Integer visitInterfaceMethodref(CONSTANT_InterfaceMethodref_info info, ClassOutputStream out) { - writeRef(info, out); - return 1; - } - - public Integer visitInvokeDynamic(CONSTANT_InvokeDynamic_info info, ClassOutputStream out) { - out.writeShort(info.bootstrap_method_attr_index); - out.writeShort(info.name_and_type_index); - return 1; - } - - public Integer visitLong(CONSTANT_Long_info info, ClassOutputStream out) { - out.writeLong(info.value); - return 2; - } - - public Integer visitNameAndType(CONSTANT_NameAndType_info info, ClassOutputStream out) { - out.writeShort(info.name_index); - out.writeShort(info.type_index); - return 1; - } - - public Integer visitMethodHandle(CONSTANT_MethodHandle_info info, ClassOutputStream out) { - out.writeByte(info.reference_kind.tag); - out.writeShort(info.reference_index); - return 1; - } - - public Integer visitMethodType(CONSTANT_MethodType_info info, ClassOutputStream out) { - out.writeShort(info.descriptor_index); - return 1; - } - - public Integer visitMethodref(CONSTANT_Methodref_info info, ClassOutputStream out) { - return writeRef(info, out); - } - - public Integer visitString(CONSTANT_String_info info, ClassOutputStream out) { - out.writeShort(info.string_index); - return 1; - } - - public Integer visitUtf8(CONSTANT_Utf8_info info, ClassOutputStream out) { - out.writeUTF(info.value); - return 1; - } - - protected Integer writeRef(CPRefInfo info, ClassOutputStream out) { - out.writeShort(info.class_index); - out.writeShort(info.name_and_type_index); - return 1; - } - } - - /** - * Writer for the different types of attribute. - */ - protected static class AttributeWriter implements Attribute.Visitor<Void,ClassOutputStream> { - public void write(Attributes attributes, ClassOutputStream out) { - int size = attributes.size(); - out.writeShort(size); - for (Attribute a: attributes) - write(a, out); - } - - // Note: due to the use of shared resources, this method is not reentrant. - public void write(Attribute attr, ClassOutputStream out) { - out.writeShort(attr.attribute_name_index); - sharedOut.reset(); - attr.accept(this, sharedOut); - out.writeInt(sharedOut.size()); - sharedOut.writeTo(out); - } - - protected ClassOutputStream sharedOut = new ClassOutputStream(); - protected AnnotationWriter annotationWriter = new AnnotationWriter(); - - public Void visitDefault(DefaultAttribute attr, ClassOutputStream out) { - out.write(attr.info, 0, attr.info.length); - return null; - } - - public Void visitAnnotationDefault(AnnotationDefault_attribute attr, ClassOutputStream out) { - annotationWriter.write(attr.default_value, out); - return null; - } - - public Void visitBootstrapMethods(BootstrapMethods_attribute attr, ClassOutputStream out) { - out.writeShort(attr.bootstrap_method_specifiers.length); - for (BootstrapMethods_attribute.BootstrapMethodSpecifier bsm : attr.bootstrap_method_specifiers) { - out.writeShort(bsm.bootstrap_method_ref); - int bsm_args_count = bsm.bootstrap_arguments.length; - out.writeShort(bsm_args_count); - for (int i : bsm.bootstrap_arguments) { - out.writeShort(i); - } - } - return null; - } - - public Void visitCharacterRangeTable(CharacterRangeTable_attribute attr, ClassOutputStream out) { - out.writeShort(attr.character_range_table.length); - for (CharacterRangeTable_attribute.Entry e: attr.character_range_table) - writeCharacterRangeTableEntry(e, out); - return null; - } - - protected void writeCharacterRangeTableEntry(CharacterRangeTable_attribute.Entry entry, ClassOutputStream out) { - out.writeShort(entry.start_pc); - out.writeShort(entry.end_pc); - out.writeInt(entry.character_range_start); - out.writeInt(entry.character_range_end); - out.writeShort(entry.flags); - } - - public Void visitCode(Code_attribute attr, ClassOutputStream out) { - out.writeShort(attr.max_stack); - out.writeShort(attr.max_locals); - out.writeInt(attr.code.length); - out.write(attr.code, 0, attr.code.length); - out.writeShort(attr.exception_table.length); - for (Code_attribute.Exception_data e: attr.exception_table) - writeExceptionTableEntry(e, out); - new AttributeWriter().write(attr.attributes, out); - return null; - } - - protected void writeExceptionTableEntry(Code_attribute.Exception_data exception_data, ClassOutputStream out) { - out.writeShort(exception_data.start_pc); - out.writeShort(exception_data.end_pc); - out.writeShort(exception_data.handler_pc); - out.writeShort(exception_data.catch_type); - } - - public Void visitCompilationID(CompilationID_attribute attr, ClassOutputStream out) { - out.writeShort(attr.compilationID_index); - return null; - } - - public Void visitConstantValue(ConstantValue_attribute attr, ClassOutputStream out) { - out.writeShort(attr.constantvalue_index); - return null; - } - - public Void visitDeprecated(Deprecated_attribute attr, ClassOutputStream out) { - return null; - } - - public Void visitEnclosingMethod(EnclosingMethod_attribute attr, ClassOutputStream out) { - out.writeShort(attr.class_index); - out.writeShort(attr.method_index); - return null; - } - - public Void visitExceptions(Exceptions_attribute attr, ClassOutputStream out) { - out.writeShort(attr.exception_index_table.length); - for (int i: attr.exception_index_table) - out.writeShort(i); - return null; - } - - public Void visitInnerClasses(InnerClasses_attribute attr, ClassOutputStream out) { - out.writeShort(attr.classes.length); - for (InnerClasses_attribute.Info info: attr.classes) - writeInnerClassesInfo(info, out); - return null; - } - - protected void writeInnerClassesInfo(InnerClasses_attribute.Info info, ClassOutputStream out) { - out.writeShort(info.inner_class_info_index); - out.writeShort(info.outer_class_info_index); - out.writeShort(info.inner_name_index); - writeAccessFlags(info.inner_class_access_flags, out); - } - - public Void visitLineNumberTable(LineNumberTable_attribute attr, ClassOutputStream out) { - out.writeShort(attr.line_number_table.length); - for (LineNumberTable_attribute.Entry e: attr.line_number_table) - writeLineNumberTableEntry(e, out); - return null; - } - - protected void writeLineNumberTableEntry(LineNumberTable_attribute.Entry entry, ClassOutputStream out) { - out.writeShort(entry.start_pc); - out.writeShort(entry.line_number); - } - - public Void visitLocalVariableTable(LocalVariableTable_attribute attr, ClassOutputStream out) { - out.writeShort(attr.local_variable_table.length); - for (LocalVariableTable_attribute.Entry e: attr.local_variable_table) - writeLocalVariableTableEntry(e, out); - return null; - } - - protected void writeLocalVariableTableEntry(LocalVariableTable_attribute.Entry entry, ClassOutputStream out) { - out.writeShort(entry.start_pc); - out.writeShort(entry.length); - out.writeShort(entry.name_index); - out.writeShort(entry.descriptor_index); - out.writeShort(entry.index); - } - - public Void visitLocalVariableTypeTable(LocalVariableTypeTable_attribute attr, ClassOutputStream out) { - out.writeShort(attr.local_variable_table.length); - for (LocalVariableTypeTable_attribute.Entry e: attr.local_variable_table) - writeLocalVariableTypeTableEntry(e, out); - return null; - } - - protected void writeLocalVariableTypeTableEntry(LocalVariableTypeTable_attribute.Entry entry, ClassOutputStream out) { - out.writeShort(entry.start_pc); - out.writeShort(entry.length); - out.writeShort(entry.name_index); - out.writeShort(entry.signature_index); - out.writeShort(entry.index); - } - - public Void visitMethodParameters(MethodParameters_attribute attr, ClassOutputStream out) { - out.writeByte(attr.method_parameter_table.length); - for (MethodParameters_attribute.Entry e : attr.method_parameter_table) { - out.writeShort(e.name_index); - out.writeShort(e.flags); - } - return null; - } - - public Void visitRuntimeVisibleAnnotations(RuntimeVisibleAnnotations_attribute attr, ClassOutputStream out) { - annotationWriter.write(attr.annotations, out); - return null; - } - - public Void visitRuntimeInvisibleAnnotations(RuntimeInvisibleAnnotations_attribute attr, ClassOutputStream out) { - annotationWriter.write(attr.annotations, out); - return null; - } - - public Void visitRuntimeVisibleTypeAnnotations(RuntimeVisibleTypeAnnotations_attribute attr, ClassOutputStream out) { - annotationWriter.write(attr.annotations, out); - return null; - } - - public Void visitRuntimeInvisibleTypeAnnotations(RuntimeInvisibleTypeAnnotations_attribute attr, ClassOutputStream out) { - annotationWriter.write(attr.annotations, out); - return null; - } - - public Void visitRuntimeVisibleParameterAnnotations(RuntimeVisibleParameterAnnotations_attribute attr, ClassOutputStream out) { - out.writeByte(attr.parameter_annotations.length); - for (Annotation[] annos: attr.parameter_annotations) - annotationWriter.write(annos, out); - return null; - } - - public Void visitRuntimeInvisibleParameterAnnotations(RuntimeInvisibleParameterAnnotations_attribute attr, ClassOutputStream out) { - out.writeByte(attr.parameter_annotations.length); - for (Annotation[] annos: attr.parameter_annotations) - annotationWriter.write(annos, out); - return null; - } - - public Void visitSignature(Signature_attribute attr, ClassOutputStream out) { - out.writeShort(attr.signature_index); - return null; - } - - public Void visitSourceDebugExtension(SourceDebugExtension_attribute attr, ClassOutputStream out) { - out.write(attr.debug_extension, 0, attr.debug_extension.length); - return null; - } - - public Void visitSourceFile(SourceFile_attribute attr, ClassOutputStream out) { - out.writeShort(attr.sourcefile_index); - return null; - } - - public Void visitSourceID(SourceID_attribute attr, ClassOutputStream out) { - out.writeShort(attr.sourceID_index); - return null; - } - - public Void visitStackMap(StackMap_attribute attr, ClassOutputStream out) { - if (stackMapWriter == null) - stackMapWriter = new StackMapTableWriter(); - - out.writeShort(attr.entries.length); - for (stack_map_frame f: attr.entries) - stackMapWriter.write(f, out); - return null; - } - - public Void visitStackMapTable(StackMapTable_attribute attr, ClassOutputStream out) { - if (stackMapWriter == null) - stackMapWriter = new StackMapTableWriter(); - - out.writeShort(attr.entries.length); - for (stack_map_frame f: attr.entries) - stackMapWriter.write(f, out); - return null; - } - - public Void visitSynthetic(Synthetic_attribute attr, ClassOutputStream out) { - return null; - } - - protected void writeAccessFlags(AccessFlags flags, ClassOutputStream p) { - sharedOut.writeShort(flags.flags); - } - - protected StackMapTableWriter stackMapWriter; - } - - /** - * Writer for the frames of StackMap and StackMapTable attributes. - */ - protected static class StackMapTableWriter - implements stack_map_frame.Visitor<Void,ClassOutputStream> { - - public void write(stack_map_frame frame, ClassOutputStream out) { - out.write(frame.frame_type); - frame.accept(this, out); - } - - public Void visit_same_frame(same_frame frame, ClassOutputStream p) { - return null; - } - - public Void visit_same_locals_1_stack_item_frame(same_locals_1_stack_item_frame frame, ClassOutputStream out) { - writeVerificationTypeInfo(frame.stack[0], out); - return null; - } - - public Void visit_same_locals_1_stack_item_frame_extended(same_locals_1_stack_item_frame_extended frame, ClassOutputStream out) { - out.writeShort(frame.offset_delta); - writeVerificationTypeInfo(frame.stack[0], out); - return null; - } - - public Void visit_chop_frame(chop_frame frame, ClassOutputStream out) { - out.writeShort(frame.offset_delta); - return null; - } - - public Void visit_same_frame_extended(same_frame_extended frame, ClassOutputStream out) { - out.writeShort(frame.offset_delta); - return null; - } - - public Void visit_append_frame(append_frame frame, ClassOutputStream out) { - out.writeShort(frame.offset_delta); - for (verification_type_info l: frame.locals) - writeVerificationTypeInfo(l, out); - return null; - } - - public Void visit_full_frame(full_frame frame, ClassOutputStream out) { - out.writeShort(frame.offset_delta); - out.writeShort(frame.locals.length); - for (verification_type_info l: frame.locals) - writeVerificationTypeInfo(l, out); - out.writeShort(frame.stack.length); - for (verification_type_info s: frame.stack) - writeVerificationTypeInfo(s, out); - return null; - } - - protected void writeVerificationTypeInfo(verification_type_info info, - ClassOutputStream out) { - out.write(info.tag); - switch (info.tag) { - case ITEM_Top: - case ITEM_Integer: - case ITEM_Float: - case ITEM_Long: - case ITEM_Double: - case ITEM_Null: - case ITEM_UninitializedThis: - break; - - case ITEM_Object: - Object_variable_info o = (Object_variable_info) info; - out.writeShort(o.cpool_index); - break; - - case ITEM_Uninitialized: - Uninitialized_variable_info u = (Uninitialized_variable_info) info; - out.writeShort(u.offset); - break; - - default: - throw new Error(); - } - } - } - - /** - * Writer for annotations and the values they contain. - */ - protected static class AnnotationWriter - implements Annotation.element_value.Visitor<Void,ClassOutputStream> { - public void write(Annotation[] annos, ClassOutputStream out) { - out.writeShort(annos.length); - for (Annotation anno: annos) - write(anno, out); - } - - public void write(TypeAnnotation[] annos, ClassOutputStream out) { - out.writeShort(annos.length); - for (TypeAnnotation anno: annos) - write(anno, out); - } - - public void write(Annotation anno, ClassOutputStream out) { - out.writeShort(anno.type_index); - out.writeShort(anno.element_value_pairs.length); - for (element_value_pair p: anno.element_value_pairs) - write(p, out); - } - - public void write(TypeAnnotation anno, ClassOutputStream out) { - write(anno.position, out); - write(anno.annotation, out); - } - - public void write(element_value_pair pair, ClassOutputStream out) { - out.writeShort(pair.element_name_index); - write(pair.value, out); - } - - public void write(element_value ev, ClassOutputStream out) { - out.writeByte(ev.tag); - ev.accept(this, out); - } - - public Void visitPrimitive(Primitive_element_value ev, ClassOutputStream out) { - out.writeShort(ev.const_value_index); - return null; - } - - public Void visitEnum(Enum_element_value ev, ClassOutputStream out) { - out.writeShort(ev.type_name_index); - out.writeShort(ev.const_name_index); - return null; - } - - public Void visitClass(Class_element_value ev, ClassOutputStream out) { - out.writeShort(ev.class_info_index); - return null; - } - - public Void visitAnnotation(Annotation_element_value ev, ClassOutputStream out) { - write(ev.annotation_value, out); - return null; - } - - public Void visitArray(Array_element_value ev, ClassOutputStream out) { - out.writeShort(ev.num_values); - for (element_value v: ev.values) - write(v, out); - return null; - } - - // TODO: Move this to TypeAnnotation to be closer with similar logic? - private void write(TypeAnnotation.Position p, ClassOutputStream out) { - out.writeByte(p.type.targetTypeValue()); - switch (p.type) { - // instanceof - case INSTANCEOF: - // new expression - case NEW: - // constructor/method reference receiver - case CONSTRUCTOR_REFERENCE: - case METHOD_REFERENCE: - out.writeShort(p.offset); - break; - // local variable - case LOCAL_VARIABLE: - // resource variable - case RESOURCE_VARIABLE: - int table_length = p.lvarOffset.length; - out.writeShort(table_length); - for (int i = 0; i < table_length; ++i) { - out.writeShort(1); // for table length - out.writeShort(p.lvarOffset[i]); - out.writeShort(p.lvarLength[i]); - out.writeShort(p.lvarIndex[i]); - } - break; - // exception parameter - case EXCEPTION_PARAMETER: - out.writeShort(p.exception_index); - break; - // method receiver - case METHOD_RECEIVER: - // Do nothing - break; - // type parameters - case CLASS_TYPE_PARAMETER: - case METHOD_TYPE_PARAMETER: - out.writeByte(p.parameter_index); - break; - // type parameters bounds - case CLASS_TYPE_PARAMETER_BOUND: - case METHOD_TYPE_PARAMETER_BOUND: - out.writeByte(p.parameter_index); - out.writeByte(p.bound_index); - break; - // class extends or implements clause - case CLASS_EXTENDS: - out.writeShort(p.type_index); - break; - // throws - case THROWS: - out.writeShort(p.type_index); - break; - // method parameter - case METHOD_FORMAL_PARAMETER: - out.writeByte(p.parameter_index); - break; - // type cast - case CAST: - // method/constructor/reference type argument - case CONSTRUCTOR_INVOCATION_TYPE_ARGUMENT: - case METHOD_INVOCATION_TYPE_ARGUMENT: - case CONSTRUCTOR_REFERENCE_TYPE_ARGUMENT: - case METHOD_REFERENCE_TYPE_ARGUMENT: - out.writeShort(p.offset); - out.writeByte(p.type_index); - break; - // We don't need to worry about these - case METHOD_RETURN: - case FIELD: - break; - case UNKNOWN: - throw new AssertionError("ClassWriter: UNKNOWN target type should never occur!"); - default: - throw new AssertionError("ClassWriter: Unknown target type for position: " + p); - } - - { // Append location data for generics/arrays. - // TODO: check for overrun? - out.writeByte((byte)p.location.size()); - for (int i : TypeAnnotation.Position.getBinaryFromTypePath(p.location)) - out.writeByte((byte)i); - } - } - } -}
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/classfile/Code_attribute.java Thu May 28 16:13:55 2015 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,159 +0,0 @@ -/* - * Copyright (c) 2007, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package com.sun.tools.classfile; - -import java.io.IOException; -import java.util.Iterator; -import java.util.NoSuchElementException; - -/** - * See JVMS, section 4.8.3. - * - * <p><b>This is NOT part of any supported API. - * If you write code that depends on this, you do so at your own risk. - * This code and its internal interfaces are subject to change or - * deletion without notice.</b> - */ -public class Code_attribute extends Attribute { - public static class InvalidIndex extends AttributeException { - private static final long serialVersionUID = -8904527774589382802L; - InvalidIndex(int index) { - this.index = index; - } - - @Override - public String getMessage() { - // i18n - return "invalid index " + index + " in Code attribute"; - } - - public final int index; - } - - Code_attribute(ClassReader cr, int name_index, int length) - throws IOException, ConstantPoolException { - super(name_index, length); - max_stack = cr.readUnsignedShort(); - max_locals = cr.readUnsignedShort(); - code_length = cr.readInt(); - code = new byte[code_length]; - cr.readFully(code); - exception_table_length = cr.readUnsignedShort(); - exception_table = new Exception_data[exception_table_length]; - for (int i = 0; i < exception_table_length; i++) - exception_table[i] = new Exception_data(cr); - attributes = new Attributes(cr); - } - - public int getByte(int offset) throws InvalidIndex { - if (offset < 0 || offset >= code.length) - throw new InvalidIndex(offset); - return code[offset]; - } - - public int getUnsignedByte(int offset) throws InvalidIndex { - if (offset < 0 || offset >= code.length) - throw new InvalidIndex(offset); - return code[offset] & 0xff; - } - - public int getShort(int offset) throws InvalidIndex { - if (offset < 0 || offset + 1 >= code.length) - throw new InvalidIndex(offset); - return (code[offset] << 8) | (code[offset + 1] & 0xFF); - } - - public int getUnsignedShort(int offset) throws InvalidIndex { - if (offset < 0 || offset + 1 >= code.length) - throw new InvalidIndex(offset); - return ((code[offset] << 8) | (code[offset + 1] & 0xFF)) & 0xFFFF; - } - - public int getInt(int offset) throws InvalidIndex { - if (offset < 0 || offset + 3 >= code.length) - throw new InvalidIndex(offset); - return (getShort(offset) << 16) | (getShort(offset + 2) & 0xFFFF); - } - - public <R, D> R accept(Visitor<R, D> visitor, D data) { - return visitor.visitCode(this, data); - } - - public Iterable<Instruction> getInstructions() { - return new Iterable<Instruction>() { - public Iterator<Instruction> iterator() { - return new Iterator<Instruction>() { - - public boolean hasNext() { - return (next != null); - } - - public Instruction next() { - if (next == null) - throw new NoSuchElementException(); - - current = next; - pc += current.length(); - next = (pc < code.length ? new Instruction(code, pc) : null); - return current; - } - - public void remove() { - throw new UnsupportedOperationException("Not supported."); - } - - Instruction current = null; - int pc = 0; - Instruction next = new Instruction(code, pc); - - }; - } - - }; - } - - public final int max_stack; - public final int max_locals; - public final int code_length; - public final byte[] code; - public final int exception_table_length; - public final Exception_data[] exception_table; - public final Attributes attributes; - - public static class Exception_data { - Exception_data(ClassReader cr) throws IOException { - start_pc = cr.readUnsignedShort(); - end_pc = cr.readUnsignedShort(); - handler_pc = cr.readUnsignedShort(); - catch_type = cr.readUnsignedShort(); - } - - public final int start_pc; - public final int end_pc; - public final int handler_pc; - public final int catch_type; - } -}
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/classfile/CompilationID_attribute.java Thu May 28 16:13:55 2015 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,62 +0,0 @@ -/* - * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.sun.tools.classfile; - -import java.io.IOException; - -/** - * <p><b>This is NOT part of any supported API. - * If you write code that depends on this, you do so at your own risk. - * This code and its internal interfaces are subject to change or - * deletion without notice.</b> - */ -public class CompilationID_attribute extends Attribute { - - CompilationID_attribute(ClassReader cr, int name_index, int length) throws IOException { - super(name_index, length); - compilationID_index = cr.readUnsignedShort(); - } - - public CompilationID_attribute(ConstantPool constant_pool, int compilationID_index) - throws ConstantPoolException { - this(constant_pool.getUTF8Index(Attribute.CompilationID), compilationID_index); - } - - public CompilationID_attribute(int name_index, int compilationID_index) { - super(name_index, 2); - this.compilationID_index = compilationID_index; - } - - String getCompilationID(ConstantPool constant_pool) - throws ConstantPoolException { - return constant_pool.getUTF8Value(compilationID_index); - } - - public <R, D> R accept(Visitor<R, D> visitor, D data) { - return visitor.visitCompilationID(this, data); - } - - public final int compilationID_index; -}
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/classfile/ConstantPool.java Thu May 28 16:13:55 2015 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,914 +0,0 @@ -/* - * Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package com.sun.tools.classfile; - -import java.io.DataOutputStream; -import java.io.IOException; -import java.io.OutputStream; -import java.util.Iterator; - -/** - * See JVMS, section 4.5. - * - * <p><b>This is NOT part of any supported API. - * If you write code that depends on this, you do so at your own risk. - * This code and its internal interfaces are subject to change or - * deletion without notice.</b> - */ -public class ConstantPool { - - public static class InvalidIndex extends ConstantPoolException { - private static final long serialVersionUID = -4350294289300939730L; - InvalidIndex(int index) { - super(index); - } - - @Override - public String getMessage() { - // i18n - return "invalid index #" + index; - } - } - - public static class UnexpectedEntry extends ConstantPoolException { - private static final long serialVersionUID = 6986335935377933211L; - UnexpectedEntry(int index, int expected_tag, int found_tag) { - super(index); - this.expected_tag = expected_tag; - this.found_tag = found_tag; - } - - @Override - public String getMessage() { - // i18n? - return "unexpected entry at #" + index + " -- expected tag " + expected_tag + ", found " + found_tag; - } - - public final int expected_tag; - public final int found_tag; - } - - public static class InvalidEntry extends ConstantPoolException { - private static final long serialVersionUID = 1000087545585204447L; - InvalidEntry(int index, int tag) { - super(index); - this.tag = tag; - } - - @Override - public String getMessage() { - // i18n? - return "unexpected tag at #" + index + ": " + tag; - } - - public final int tag; - } - - public static class EntryNotFound extends ConstantPoolException { - private static final long serialVersionUID = 2885537606468581850L; - EntryNotFound(Object value) { - super(-1); - this.value = value; - } - - @Override - public String getMessage() { - // i18n? - return "value not found: " + value; - } - - public final Object value; - } - - public static final int CONSTANT_Utf8 = 1; - public static final int CONSTANT_Integer = 3; - public static final int CONSTANT_Float = 4; - public static final int CONSTANT_Long = 5; - public static final int CONSTANT_Double = 6; - public static final int CONSTANT_Class = 7; - public static final int CONSTANT_String = 8; - public static final int CONSTANT_Fieldref = 9; - public static final int CONSTANT_Methodref = 10; - public static final int CONSTANT_InterfaceMethodref = 11; - public static final int CONSTANT_NameAndType = 12; - public static final int CONSTANT_MethodHandle = 15; - public static final int CONSTANT_MethodType = 16; - public static final int CONSTANT_InvokeDynamic = 18; - - public static enum RefKind { - REF_getField(1, "getfield"), - REF_getStatic(2, "getstatic"), - REF_putField(3, "putfield"), - REF_putStatic(4, "putstatic"), - REF_invokeVirtual(5, "invokevirtual"), - REF_invokeStatic(6, "invokestatic"), - REF_invokeSpecial(7, "invokespecial"), - REF_newInvokeSpecial(8, "newinvokespecial"), - REF_invokeInterface(9, "invokeinterface"); - - public final int tag; - public final String name; - - RefKind(int tag, String name) { - this.tag = tag; - this.name = name; - } - - static RefKind getRefkind(int tag) { - switch(tag) { - case 1: - return REF_getField; - case 2: - return REF_getStatic; - case 3: - return REF_putField; - case 4: - return REF_putStatic; - case 5: - return REF_invokeVirtual; - case 6: - return REF_invokeStatic; - case 7: - return REF_invokeSpecial; - case 8: - return REF_newInvokeSpecial; - case 9: - return REF_invokeInterface; - default: - return null; - } - } - } - - ConstantPool(ClassReader cr) throws IOException, InvalidEntry { - int count = cr.readUnsignedShort(); - pool = new CPInfo[count]; - for (int i = 1; i < count; i++) { - int tag = cr.readUnsignedByte(); - switch (tag) { - case CONSTANT_Class: - pool[i] = new CONSTANT_Class_info(this, cr); - break; - - case CONSTANT_Double: - pool[i] = new CONSTANT_Double_info(cr); - i++; - break; - - case CONSTANT_Fieldref: - pool[i] = new CONSTANT_Fieldref_info(this, cr); - break; - - case CONSTANT_Float: - pool[i] = new CONSTANT_Float_info(cr); - break; - - case CONSTANT_Integer: - pool[i] = new CONSTANT_Integer_info(cr); - break; - - case CONSTANT_InterfaceMethodref: - pool[i] = new CONSTANT_InterfaceMethodref_info(this, cr); - break; - - case CONSTANT_InvokeDynamic: - pool[i] = new CONSTANT_InvokeDynamic_info(this, cr); - break; - - case CONSTANT_Long: - pool[i] = new CONSTANT_Long_info(cr); - i++; - break; - - case CONSTANT_MethodHandle: - pool[i] = new CONSTANT_MethodHandle_info(this, cr); - break; - - case CONSTANT_MethodType: - pool[i] = new CONSTANT_MethodType_info(this, cr); - break; - - case CONSTANT_Methodref: - pool[i] = new CONSTANT_Methodref_info(this, cr); - break; - - case CONSTANT_NameAndType: - pool[i] = new CONSTANT_NameAndType_info(this, cr); - break; - - case CONSTANT_String: - pool[i] = new CONSTANT_String_info(this, cr); - break; - - case CONSTANT_Utf8: - pool[i] = new CONSTANT_Utf8_info(cr); - break; - - default: - throw new InvalidEntry(i, tag); - } - } - } - - public ConstantPool(CPInfo[] pool) { - this.pool = pool; - } - - public int size() { - return pool.length; - } - - public int byteLength() { - int length = 2; - for (int i = 1; i < size(); ) { - CPInfo cpInfo = pool[i]; - length += cpInfo.byteLength(); - i += cpInfo.size(); - } - return length; - } - - public CPInfo get(int index) throws InvalidIndex { - if (index <= 0 || index >= pool.length) - throw new InvalidIndex(index); - CPInfo info = pool[index]; - if (info == null) { - // this occurs for indices referencing the "second half" of an - // 8 byte constant, such as CONSTANT_Double or CONSTANT_Long - throw new InvalidIndex(index); - } - return pool[index]; - } - - private CPInfo get(int index, int expected_type) throws InvalidIndex, UnexpectedEntry { - CPInfo info = get(index); - if (info.getTag() != expected_type) - throw new UnexpectedEntry(index, expected_type, info.getTag()); - return info; - } - - public CONSTANT_Utf8_info getUTF8Info(int index) throws InvalidIndex, UnexpectedEntry { - return ((CONSTANT_Utf8_info) get(index, CONSTANT_Utf8)); - } - - public CONSTANT_Class_info getClassInfo(int index) throws InvalidIndex, UnexpectedEntry { - return ((CONSTANT_Class_info) get(index, CONSTANT_Class)); - } - - public CONSTANT_NameAndType_info getNameAndTypeInfo(int index) throws InvalidIndex, UnexpectedEntry { - return ((CONSTANT_NameAndType_info) get(index, CONSTANT_NameAndType)); - } - - public String getUTF8Value(int index) throws InvalidIndex, UnexpectedEntry { - return getUTF8Info(index).value; - } - - public int getUTF8Index(String value) throws EntryNotFound { - for (int i = 1; i < pool.length; i++) { - CPInfo info = pool[i]; - if (info instanceof CONSTANT_Utf8_info && - ((CONSTANT_Utf8_info) info).value.equals(value)) - return i; - } - throw new EntryNotFound(value); - } - - public Iterable<CPInfo> entries() { - return new Iterable<CPInfo>() { - public Iterator<CPInfo> iterator() { - return new Iterator<CPInfo>() { - - public boolean hasNext() { - return next < pool.length; - } - - public CPInfo next() { - current = pool[next]; - switch (current.getTag()) { - case CONSTANT_Double: - case CONSTANT_Long: - next += 2; - break; - default: - next += 1; - } - return current; - } - - public void remove() { - throw new UnsupportedOperationException(); - } - - private CPInfo current; - private int next = 1; - - }; - } - }; - } - - private CPInfo[] pool; - - public interface Visitor<R,P> { - R visitClass(CONSTANT_Class_info info, P p); - R visitDouble(CONSTANT_Double_info info, P p); - R visitFieldref(CONSTANT_Fieldref_info info, P p); - R visitFloat(CONSTANT_Float_info info, P p); - R visitInteger(CONSTANT_Integer_info info, P p); - R visitInterfaceMethodref(CONSTANT_InterfaceMethodref_info info, P p); - R visitInvokeDynamic(CONSTANT_InvokeDynamic_info info, P p); - R visitLong(CONSTANT_Long_info info, P p); - R visitNameAndType(CONSTANT_NameAndType_info info, P p); - R visitMethodref(CONSTANT_Methodref_info info, P p); - R visitMethodHandle(CONSTANT_MethodHandle_info info, P p); - R visitMethodType(CONSTANT_MethodType_info info, P p); - R visitString(CONSTANT_String_info info, P p); - R visitUtf8(CONSTANT_Utf8_info info, P p); - } - - public static abstract class CPInfo { - CPInfo() { - this.cp = null; - } - - CPInfo(ConstantPool cp) { - this.cp = cp; - } - - public abstract int getTag(); - - /** The number of slots in the constant pool used by this entry. - * 2 for CONSTANT_Double and CONSTANT_Long; 1 for everything else. */ - public int size() { - return 1; - } - - public abstract int byteLength(); - - public abstract <R,D> R accept(Visitor<R,D> visitor, D data); - - protected final ConstantPool cp; - } - - public static abstract class CPRefInfo extends CPInfo { - protected CPRefInfo(ConstantPool cp, ClassReader cr, int tag) throws IOException { - super(cp); - this.tag = tag; - class_index = cr.readUnsignedShort(); - name_and_type_index = cr.readUnsignedShort(); - } - - protected CPRefInfo(ConstantPool cp, int tag, int class_index, int name_and_type_index) { - super(cp); - this.tag = tag; - this.class_index = class_index; - this.name_and_type_index = name_and_type_index; - } - - public int getTag() { - return tag; - } - - public int byteLength() { - return 5; - } - - public CONSTANT_Class_info getClassInfo() throws ConstantPoolException { - return cp.getClassInfo(class_index); - } - - public String getClassName() throws ConstantPoolException { - return cp.getClassInfo(class_index).getName(); - } - - public CONSTANT_NameAndType_info getNameAndTypeInfo() throws ConstantPoolException { - return cp.getNameAndTypeInfo(name_and_type_index); - } - - public final int tag; - public final int class_index; - public final int name_and_type_index; - } - - public static class CONSTANT_Class_info extends CPInfo { - CONSTANT_Class_info(ConstantPool cp, ClassReader cr) throws IOException { - super(cp); - name_index = cr.readUnsignedShort(); - } - - public CONSTANT_Class_info(ConstantPool cp, int name_index) { - super(cp); - this.name_index = name_index; - } - - public int getTag() { - return CONSTANT_Class; - } - - public int byteLength() { - return 3; - } - - /** - * Get the raw value of the class referenced by this constant pool entry. - * This will either be the name of the class, in internal form, or a - * descriptor for an array class. - * @return the raw value of the class - */ - public String getName() throws ConstantPoolException { - return cp.getUTF8Value(name_index); - } - - /** - * If this constant pool entry identifies either a class or interface type, - * or a possibly multi-dimensional array of a class of interface type, - * return the name of the class or interface in internal form. Otherwise, - * (i.e. if this is a possibly multi-dimensional array of a primitive type), - * return null. - * @return the base class or interface name - */ - public String getBaseName() throws ConstantPoolException { - String name = getName(); - if (name.startsWith("[")) { - int index = name.indexOf("[L"); - if (index == -1) - return null; - return name.substring(index + 2, name.length() - 1); - } else - return name; - } - - public int getDimensionCount() throws ConstantPoolException { - String name = getName(); - int count = 0; - while (name.charAt(count) == '[') - count++; - return count; - } - - @Override - public String toString() { - return "CONSTANT_Class_info[name_index: " + name_index + "]"; - } - - public <R, D> R accept(Visitor<R, D> visitor, D data) { - return visitor.visitClass(this, data); - } - - public final int name_index; - } - - public static class CONSTANT_Double_info extends CPInfo { - CONSTANT_Double_info(ClassReader cr) throws IOException { - value = cr.readDouble(); - } - - public CONSTANT_Double_info(double value) { - this.value = value; - } - - public int getTag() { - return CONSTANT_Double; - } - - public int byteLength() { - return 9; - } - - @Override - public int size() { - return 2; - } - - @Override - public String toString() { - return "CONSTANT_Double_info[value: " + value + "]"; - } - - public <R, D> R accept(Visitor<R, D> visitor, D data) { - return visitor.visitDouble(this, data); - } - - public final double value; - } - - public static class CONSTANT_Fieldref_info extends CPRefInfo { - CONSTANT_Fieldref_info(ConstantPool cp, ClassReader cr) throws IOException { - super(cp, cr, CONSTANT_Fieldref); - } - - public CONSTANT_Fieldref_info(ConstantPool cp, int class_index, int name_and_type_index) { - super(cp, CONSTANT_Fieldref, class_index, name_and_type_index); - } - - @Override - public String toString() { - return "CONSTANT_Fieldref_info[class_index: " + class_index + ", name_and_type_index: " + name_and_type_index + "]"; - } - - public <R, D> R accept(Visitor<R, D> visitor, D data) { - return visitor.visitFieldref(this, data); - } - } - - public static class CONSTANT_Float_info extends CPInfo { - CONSTANT_Float_info(ClassReader cr) throws IOException { - value = cr.readFloat(); - } - - public CONSTANT_Float_info(float value) { - this.value = value; - } - - public int getTag() { - return CONSTANT_Float; - } - - public int byteLength() { - return 5; - } - - @Override - public String toString() { - return "CONSTANT_Float_info[value: " + value + "]"; - } - - public <R, D> R accept(Visitor<R, D> visitor, D data) { - return visitor.visitFloat(this, data); - } - - public final float value; - } - - public static class CONSTANT_Integer_info extends CPInfo { - CONSTANT_Integer_info(ClassReader cr) throws IOException { - value = cr.readInt(); - } - - public CONSTANT_Integer_info(int value) { - this.value = value; - } - - public int getTag() { - return CONSTANT_Integer; - } - - public int byteLength() { - return 5; - } - - @Override - public String toString() { - return "CONSTANT_Integer_info[value: " + value + "]"; - } - - public <R, D> R accept(Visitor<R, D> visitor, D data) { - return visitor.visitInteger(this, data); - } - - public final int value; - } - - public static class CONSTANT_InterfaceMethodref_info extends CPRefInfo { - CONSTANT_InterfaceMethodref_info(ConstantPool cp, ClassReader cr) throws IOException { - super(cp, cr, CONSTANT_InterfaceMethodref); - } - - public CONSTANT_InterfaceMethodref_info(ConstantPool cp, int class_index, int name_and_type_index) { - super(cp, CONSTANT_InterfaceMethodref, class_index, name_and_type_index); - } - - @Override - public String toString() { - return "CONSTANT_InterfaceMethodref_info[class_index: " + class_index + ", name_and_type_index: " + name_and_type_index + "]"; - } - - public <R, D> R accept(Visitor<R, D> visitor, D data) { - return visitor.visitInterfaceMethodref(this, data); - } - } - - public static class CONSTANT_InvokeDynamic_info extends CPInfo { - CONSTANT_InvokeDynamic_info(ConstantPool cp, ClassReader cr) throws IOException { - super(cp); - bootstrap_method_attr_index = cr.readUnsignedShort(); - name_and_type_index = cr.readUnsignedShort(); - } - - public CONSTANT_InvokeDynamic_info(ConstantPool cp, int bootstrap_method_index, int name_and_type_index) { - super(cp); - this.bootstrap_method_attr_index = bootstrap_method_index; - this.name_and_type_index = name_and_type_index; - } - - public int getTag() { - return CONSTANT_InvokeDynamic; - } - - public int byteLength() { - return 5; - } - - @Override - public String toString() { - return "CONSTANT_InvokeDynamic_info[bootstrap_method_index: " + bootstrap_method_attr_index + ", name_and_type_index: " + name_and_type_index + "]"; - } - - public <R, D> R accept(Visitor<R, D> visitor, D data) { - return visitor.visitInvokeDynamic(this, data); - } - - public CONSTANT_NameAndType_info getNameAndTypeInfo() throws ConstantPoolException { - return cp.getNameAndTypeInfo(name_and_type_index); - } - - public final int bootstrap_method_attr_index; - public final int name_and_type_index; - } - - public static class CONSTANT_Long_info extends CPInfo { - CONSTANT_Long_info(ClassReader cr) throws IOException { - value = cr.readLong(); - } - - public CONSTANT_Long_info(long value) { - this.value = value; - } - - public int getTag() { - return CONSTANT_Long; - } - - @Override - public int size() { - return 2; - } - - public int byteLength() { - return 9; - } - - @Override - public String toString() { - return "CONSTANT_Long_info[value: " + value + "]"; - } - - public <R, D> R accept(Visitor<R, D> visitor, D data) { - return visitor.visitLong(this, data); - } - - public final long value; - } - - public static class CONSTANT_MethodHandle_info extends CPInfo { - CONSTANT_MethodHandle_info(ConstantPool cp, ClassReader cr) throws IOException { - super(cp); - reference_kind = RefKind.getRefkind(cr.readUnsignedByte()); - reference_index = cr.readUnsignedShort(); - } - - public CONSTANT_MethodHandle_info(ConstantPool cp, RefKind ref_kind, int member_index) { - super(cp); - this.reference_kind = ref_kind; - this.reference_index = member_index; - } - - public int getTag() { - return CONSTANT_MethodHandle; - } - - public int byteLength() { - return 4; - } - - @Override - public String toString() { - return "CONSTANT_MethodHandle_info[ref_kind: " + reference_kind + ", member_index: " + reference_index + "]"; - } - - public <R, D> R accept(Visitor<R, D> visitor, D data) { - return visitor.visitMethodHandle(this, data); - } - - public CPRefInfo getCPRefInfo() throws ConstantPoolException { - int expected = CONSTANT_Methodref; - int actual = cp.get(reference_index).getTag(); - // allow these tag types also: - switch (actual) { - case CONSTANT_Fieldref: - case CONSTANT_InterfaceMethodref: - expected = actual; - } - return (CPRefInfo) cp.get(reference_index, expected); - } - - public final RefKind reference_kind; - public final int reference_index; - } - - public static class CONSTANT_MethodType_info extends CPInfo { - CONSTANT_MethodType_info(ConstantPool cp, ClassReader cr) throws IOException { - super(cp); - descriptor_index = cr.readUnsignedShort(); - } - - public CONSTANT_MethodType_info(ConstantPool cp, int signature_index) { - super(cp); - this.descriptor_index = signature_index; - } - - public int getTag() { - return CONSTANT_MethodType; - } - - public int byteLength() { - return 3; - } - - @Override - public String toString() { - return "CONSTANT_MethodType_info[signature_index: " + descriptor_index + "]"; - } - - public <R, D> R accept(Visitor<R, D> visitor, D data) { - return visitor.visitMethodType(this, data); - } - - public String getType() throws ConstantPoolException { - return cp.getUTF8Value(descriptor_index); - } - - public final int descriptor_index; - } - - public static class CONSTANT_Methodref_info extends CPRefInfo { - CONSTANT_Methodref_info(ConstantPool cp, ClassReader cr) throws IOException { - super(cp, cr, CONSTANT_Methodref); - } - - public CONSTANT_Methodref_info(ConstantPool cp, int class_index, int name_and_type_index) { - super(cp, CONSTANT_Methodref, class_index, name_and_type_index); - } - - @Override - public String toString() { - return "CONSTANT_Methodref_info[class_index: " + class_index + ", name_and_type_index: " + name_and_type_index + "]"; - } - - public <R, D> R accept(Visitor<R, D> visitor, D data) { - return visitor.visitMethodref(this, data); - } - } - - public static class CONSTANT_NameAndType_info extends CPInfo { - CONSTANT_NameAndType_info(ConstantPool cp, ClassReader cr) throws IOException { - super(cp); - name_index = cr.readUnsignedShort(); - type_index = cr.readUnsignedShort(); - } - - public CONSTANT_NameAndType_info(ConstantPool cp, int name_index, int type_index) { - super(cp); - this.name_index = name_index; - this.type_index = type_index; - } - - public int getTag() { - return CONSTANT_NameAndType; - } - - public int byteLength() { - return 5; - } - - public String getName() throws ConstantPoolException { - return cp.getUTF8Value(name_index); - } - - public String getType() throws ConstantPoolException { - return cp.getUTF8Value(type_index); - } - - public <R, D> R accept(Visitor<R, D> visitor, D data) { - return visitor.visitNameAndType(this, data); - } - - @Override - public String toString() { - return "CONSTANT_NameAndType_info[name_index: " + name_index + ", type_index: " + type_index + "]"; - } - - public final int name_index; - public final int type_index; - } - - public static class CONSTANT_String_info extends CPInfo { - CONSTANT_String_info(ConstantPool cp, ClassReader cr) throws IOException { - super(cp); - string_index = cr.readUnsignedShort(); - } - - public CONSTANT_String_info(ConstantPool cp, int string_index) { - super(cp); - this.string_index = string_index; - } - - public int getTag() { - return CONSTANT_String; - } - - public int byteLength() { - return 3; - } - - public String getString() throws ConstantPoolException { - return cp.getUTF8Value(string_index); - } - - public <R, D> R accept(Visitor<R, D> visitor, D data) { - return visitor.visitString(this, data); - } - - @Override - public String toString() { - return "CONSTANT_String_info[class_index: " + string_index + "]"; - } - - public final int string_index; - } - - public static class CONSTANT_Utf8_info extends CPInfo { - CONSTANT_Utf8_info(ClassReader cr) throws IOException { - value = cr.readUTF(); - } - - public CONSTANT_Utf8_info(String value) { - this.value = value; - } - - public int getTag() { - return CONSTANT_Utf8; - } - - public int byteLength() { - class SizeOutputStream extends OutputStream { - @Override - public void write(int b) { - size++; - } - int size; - } - SizeOutputStream sizeOut = new SizeOutputStream(); - DataOutputStream out = new DataOutputStream(sizeOut); - try { out.writeUTF(value); } catch (IOException ignore) { } - return 1 + sizeOut.size; - } - - @Override - public String toString() { - if (value.length() < 32 && isPrintableAscii(value)) - return "CONSTANT_Utf8_info[value: \"" + value + "\"]"; - else - return "CONSTANT_Utf8_info[value: (" + value.length() + " chars)]"; - } - - static boolean isPrintableAscii(String s) { - for (int i = 0; i < s.length(); i++) { - char c = s.charAt(i); - if (c < 32 || c >= 127) - return false; - } - return true; - } - - public <R, D> R accept(Visitor<R, D> visitor, D data) { - return visitor.visitUtf8(this, data); - } - - public final String value; - } - -}
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/classfile/ConstantPoolException.java Thu May 28 16:13:55 2015 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,42 +0,0 @@ -/* - * Copyright (c) 2008, 2009, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - - -package com.sun.tools.classfile; - -/* - * <p><b>This is NOT part of any supported API. - * If you write code that depends on this, you do so at your own risk. - * This code and its internal interfaces are subject to change or - * deletion without notice.</b> - */ -public class ConstantPoolException extends Exception { - private static final long serialVersionUID = -2324397349644754565L; - ConstantPoolException(int index) { - this.index = index; - } - - public final int index; -}
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/classfile/ConstantValue_attribute.java Thu May 28 16:13:55 2015 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,59 +0,0 @@ -/* - * Copyright (c) 2007, 2008, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package com.sun.tools.classfile; - -import java.io.IOException; - -/** - * See JVMS, section 4.8.2. - * - * <p><b>This is NOT part of any supported API. - * If you write code that depends on this, you do so at your own risk. - * This code and its internal interfaces are subject to change or - * deletion without notice.</b> - */ -public class ConstantValue_attribute extends Attribute { - ConstantValue_attribute(ClassReader cr, int name_index, int length) throws IOException { - super(name_index, length); - constantvalue_index = cr.readUnsignedShort(); - } - - public ConstantValue_attribute(ConstantPool constant_pool, int constantvalue_index) - throws ConstantPoolException { - this(constant_pool.getUTF8Index(Attribute.ConstantValue), constantvalue_index); - } - - public ConstantValue_attribute(int name_index, int constantvalue_index) { - super(name_index, 2); - this.constantvalue_index = constantvalue_index; - } - - public <R, D> R accept(Visitor<R, D> visitor, D data) { - return visitor.visitConstantValue(this, data); - } - - public final int constantvalue_index; -}
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/classfile/DefaultAttribute.java Thu May 28 16:13:55 2015 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,64 +0,0 @@ -/* - * Copyright (c) 2007, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package com.sun.tools.classfile; - -/* - * <p><b>This is NOT part of any supported API. - * If you write code that depends on this, you do so at your own risk. - * This code and its internal interfaces are subject to change or - * deletion without notice.</b> - */ -public class DefaultAttribute extends Attribute { - DefaultAttribute(ClassReader cr, int name_index, byte[] data) { - this(cr, name_index, data, null); - } - - DefaultAttribute(ClassReader cr, int name_index, byte[] data, String reason) { - super(name_index, data.length); - info = data; - this.reason = reason; - } - - public DefaultAttribute(ConstantPool constant_pool, int name_index, byte[] info) { - this(constant_pool, name_index, info, null); - } - - public DefaultAttribute(ConstantPool constant_pool, int name_index, - byte[] info, String reason) { - super(name_index, info.length); - this.info = info; - this.reason = reason; - } - - public <R, P> R accept(Visitor<R, P> visitor, P p) { - return visitor.visitDefault(this, p); - } - - public final byte[] info; - /** Why did we need to generate a DefaultAttribute - */ - public final String reason; -}
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/classfile/Dependencies.java Thu May 28 16:13:55 2015 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,794 +0,0 @@ -/* - * Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.sun.tools.classfile; - -import java.util.Deque; -import java.util.HashMap; -import java.util.HashSet; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.Set; -import java.util.regex.Pattern; - -import com.sun.tools.classfile.Dependency.Filter; -import com.sun.tools.classfile.Dependency.Finder; -import com.sun.tools.classfile.Dependency.Location; -import com.sun.tools.classfile.Type.ArrayType; -import com.sun.tools.classfile.Type.ClassSigType; -import com.sun.tools.classfile.Type.ClassType; -import com.sun.tools.classfile.Type.MethodType; -import com.sun.tools.classfile.Type.SimpleType; -import com.sun.tools.classfile.Type.TypeParamType; -import com.sun.tools.classfile.Type.WildcardType; - -import static com.sun.tools.classfile.ConstantPool.*; - -/** - * A framework for determining {@link Dependency dependencies} between class files. - * - * A {@link Dependency.Finder finder} is used to identify the dependencies of - * individual classes. Some finders may return subtypes of {@code Dependency} to - * further characterize the type of dependency, such as a dependency on a - * method within a class. - * - * A {@link Dependency.Filter filter} may be used to restrict the set of - * dependencies found by a finder. - * - * Dependencies that are found may be passed to a {@link Dependencies.Recorder - * recorder} so that the dependencies can be stored in a custom data structure. - */ -public class Dependencies { - /** - * Thrown when a class file cannot be found. - */ - public static class ClassFileNotFoundException extends Exception { - private static final long serialVersionUID = 3632265927794475048L; - - public ClassFileNotFoundException(String className) { - super(className); - this.className = className; - } - - public ClassFileNotFoundException(String className, Throwable cause) { - this(className); - initCause(cause); - } - - public final String className; - } - - /** - * Thrown when an exception is found processing a class file. - */ - public static class ClassFileError extends Error { - private static final long serialVersionUID = 4111110813961313203L; - - public ClassFileError(Throwable cause) { - initCause(cause); - } - } - - /** - * Service provider interface to locate and read class files. - */ - public interface ClassFileReader { - /** - * Get the ClassFile object for a specified class. - * @param className the name of the class to be returned. - * @return the ClassFile for the given class - * @throws Dependencies.ClassFileNotFoundException if the classfile cannot be - * found - */ - public ClassFile getClassFile(String className) - throws ClassFileNotFoundException; - } - - /** - * Service provide interface to handle results. - */ - public interface Recorder { - /** - * Record a dependency that has been found. - * @param d - */ - public void addDependency(Dependency d); - } - - /** - * Get the default finder used to locate the dependencies for a class. - * @return the default finder - */ - public static Finder getDefaultFinder() { - return new APIDependencyFinder(AccessFlags.ACC_PRIVATE); - } - - /** - * Get a finder used to locate the API dependencies for a class. - * These include the superclass, superinterfaces, and classes referenced in - * the declarations of fields and methods. The fields and methods that - * are checked can be limited according to a specified access. - * The access parameter must be one of {@link AccessFlags#ACC_PUBLIC ACC_PUBLIC}, - * {@link AccessFlags#ACC_PRIVATE ACC_PRIVATE}, - * {@link AccessFlags#ACC_PROTECTED ACC_PROTECTED}, or 0 for - * package private access. Members with greater than or equal accessibility - * to that specified will be searched for dependencies. - * @param access the access of members to be checked - * @return an API finder - */ - public static Finder getAPIFinder(int access) { - return new APIDependencyFinder(access); - } - - /** - * Get a finder to do class dependency analysis. - * - * @return a Class dependency finder - */ - public static Finder getClassDependencyFinder() { - return new ClassDependencyFinder(); - } - - /** - * Get the finder used to locate the dependencies for a class. - * @return the finder - */ - public Finder getFinder() { - if (finder == null) - finder = getDefaultFinder(); - return finder; - } - - /** - * Set the finder used to locate the dependencies for a class. - * @param f the finder - */ - public void setFinder(Finder f) { - finder = Objects.requireNonNull(f); - } - - /** - * Get the default filter used to determine included when searching - * the transitive closure of all the dependencies. - * Unless overridden, the default filter accepts all dependencies. - * @return the default filter. - */ - public static Filter getDefaultFilter() { - return DefaultFilter.instance(); - } - - /** - * Get a filter which uses a regular expression on the target's class name - * to determine if a dependency is of interest. - * @param pattern the pattern used to match the target's class name - * @return a filter for matching the target class name with a regular expression - */ - public static Filter getRegexFilter(Pattern pattern) { - return new TargetRegexFilter(pattern); - } - - /** - * Get a filter which checks the package of a target's class name - * to determine if a dependency is of interest. The filter checks if the - * package of the target's class matches any of a set of given package - * names. The match may optionally match subpackages of the given names as well. - * @param packageNames the package names used to match the target's class name - * @param matchSubpackages whether or not to match subpackages as well - * @return a filter for checking the target package name against a list of package names - */ - public static Filter getPackageFilter(Set<String> packageNames, boolean matchSubpackages) { - return new TargetPackageFilter(packageNames, matchSubpackages); - } - - /** - * Get the filter used to determine the dependencies included when searching - * the transitive closure of all the dependencies. - * Unless overridden, the default filter accepts all dependencies. - * @return the filter - */ - public Filter getFilter() { - if (filter == null) - filter = getDefaultFilter(); - return filter; - } - - /** - * Set the filter used to determine the dependencies included when searching - * the transitive closure of all the dependencies. - * @param f the filter - */ - public void setFilter(Filter f) { - filter = Objects.requireNonNull(f); - } - - /** - * Find the dependencies of a class, using the current - * {@link Dependencies#getFinder finder} and - * {@link Dependencies#getFilter filter}. - * The search may optionally include the transitive closure of all the - * filtered dependencies, by also searching in the classes named in those - * dependencies. - * @param classFinder a finder to locate class files - * @param rootClassNames the names of the root classes from which to begin - * searching - * @param transitiveClosure whether or not to also search those classes - * named in any filtered dependencies that are found. - * @return the set of dependencies that were found - * @throws ClassFileNotFoundException if a required class file cannot be found - * @throws ClassFileError if an error occurs while processing a class file, - * such as an error in the internal class file structure. - */ - public Set<Dependency> findAllDependencies( - ClassFileReader classFinder, Set<String> rootClassNames, - boolean transitiveClosure) - throws ClassFileNotFoundException { - final Set<Dependency> results = new HashSet<>(); - Recorder r = new Recorder() { - public void addDependency(Dependency d) { - results.add(d); - } - }; - findAllDependencies(classFinder, rootClassNames, transitiveClosure, r); - return results; - } - - /** - * Find the dependencies of a class, using the current - * {@link Dependencies#getFinder finder} and - * {@link Dependencies#getFilter filter}. - * The search may optionally include the transitive closure of all the - * filtered dependencies, by also searching in the classes named in those - * dependencies. - * @param classFinder a finder to locate class files - * @param rootClassNames the names of the root classes from which to begin - * searching - * @param transitiveClosure whether or not to also search those classes - * named in any filtered dependencies that are found. - * @param recorder a recorder for handling the results - * @throws ClassFileNotFoundException if a required class file cannot be found - * @throws ClassFileError if an error occurs while processing a class file, - * such as an error in the internal class file structure. - */ - public void findAllDependencies( - ClassFileReader classFinder, Set<String> rootClassNames, - boolean transitiveClosure, Recorder recorder) - throws ClassFileNotFoundException { - Set<String> doneClasses = new HashSet<>(); - - getFinder(); // ensure initialized - getFilter(); // ensure initialized - - // Work queue of names of classfiles to be searched. - // Entries will be unique, and for classes that do not yet have - // dependencies in the results map. - Deque<String> deque = new LinkedList<>(rootClassNames); - - String className; - while ((className = deque.poll()) != null) { - assert (!doneClasses.contains(className)); - doneClasses.add(className); - - ClassFile cf = classFinder.getClassFile(className); - - // The following code just applies the filter to the dependencies - // followed for the transitive closure. - for (Dependency d: finder.findDependencies(cf)) { - recorder.addDependency(d); - if (transitiveClosure && filter.accepts(d)) { - String cn = d.getTarget().getClassName(); - if (!doneClasses.contains(cn)) - deque.add(cn); - } - } - } - } - - private Filter filter; - private Finder finder; - - /** - * A location identifying a class. - */ - static class SimpleLocation implements Location { - public SimpleLocation(String name) { - this.name = name; - this.className = name.replace('/', '.'); - } - - public String getName() { - return name; - } - - public String getClassName() { - return className; - } - - public String getPackageName() { - int i = name.lastIndexOf('/'); - return (i > 0) ? name.substring(0, i).replace('/', '.') : ""; - } - - @Override - public boolean equals(Object other) { - if (this == other) - return true; - if (!(other instanceof SimpleLocation)) - return false; - return (name.equals(((SimpleLocation) other).name)); - } - - @Override - public int hashCode() { - return name.hashCode(); - } - - @Override - public String toString() { - return name; - } - - private String name; - private String className; - } - - /** - * A dependency of one class on another. - */ - static class SimpleDependency implements Dependency { - public SimpleDependency(Location origin, Location target) { - this.origin = origin; - this.target = target; - } - - public Location getOrigin() { - return origin; - } - - public Location getTarget() { - return target; - } - - @Override - public boolean equals(Object other) { - if (this == other) - return true; - if (!(other instanceof SimpleDependency)) - return false; - SimpleDependency o = (SimpleDependency) other; - return (origin.equals(o.origin) && target.equals(o.target)); - } - - @Override - public int hashCode() { - return origin.hashCode() * 31 + target.hashCode(); - } - - @Override - public String toString() { - return origin + ":" + target; - } - - private Location origin; - private Location target; - } - - - /** - * This class accepts all dependencies. - */ - static class DefaultFilter implements Filter { - private static DefaultFilter instance; - - static DefaultFilter instance() { - if (instance == null) - instance = new DefaultFilter(); - return instance; - } - - public boolean accepts(Dependency dependency) { - return true; - } - } - - /** - * This class accepts those dependencies whose target's class name matches a - * regular expression. - */ - static class TargetRegexFilter implements Filter { - TargetRegexFilter(Pattern pattern) { - this.pattern = pattern; - } - - public boolean accepts(Dependency dependency) { - return pattern.matcher(dependency.getTarget().getClassName()).matches(); - } - - private final Pattern pattern; - } - - /** - * This class accepts those dependencies whose class name is in a given - * package. - */ - static class TargetPackageFilter implements Filter { - TargetPackageFilter(Set<String> packageNames, boolean matchSubpackages) { - for (String pn: packageNames) { - if (pn.length() == 0) // implies null check as well - throw new IllegalArgumentException(); - } - this.packageNames = packageNames; - this.matchSubpackages = matchSubpackages; - } - - public boolean accepts(Dependency dependency) { - String pn = dependency.getTarget().getPackageName(); - if (packageNames.contains(pn)) - return true; - - if (matchSubpackages) { - for (String n: packageNames) { - if (pn.startsWith(n + ".")) - return true; - } - } - - return false; - } - - private final Set<String> packageNames; - private final boolean matchSubpackages; - } - - /** - * This class identifies class names directly or indirectly in the constant pool. - */ - static class ClassDependencyFinder extends BasicDependencyFinder { - public Iterable<? extends Dependency> findDependencies(ClassFile classfile) { - Visitor v = new Visitor(classfile); - for (CPInfo cpInfo: classfile.constant_pool.entries()) { - v.scan(cpInfo); - } - try { - v.addClass(classfile.super_class); - v.addClasses(classfile.interfaces); - v.scan(classfile.attributes); - - for (Field f : classfile.fields) { - v.scan(f.descriptor, f.attributes); - } - for (Method m : classfile.methods) { - v.scan(m.descriptor, m.attributes); - Exceptions_attribute e = - (Exceptions_attribute)m.attributes.get(Attribute.Exceptions); - if (e != null) { - v.addClasses(e.exception_index_table); - } - } - } catch (ConstantPoolException e) { - throw new ClassFileError(e); - } - - return v.deps; - } - } - - /** - * This class identifies class names in the signatures of classes, fields, - * and methods in a class. - */ - static class APIDependencyFinder extends BasicDependencyFinder { - APIDependencyFinder(int access) { - switch (access) { - case AccessFlags.ACC_PUBLIC: - case AccessFlags.ACC_PROTECTED: - case AccessFlags.ACC_PRIVATE: - case 0: - showAccess = access; - break; - default: - throw new IllegalArgumentException("invalid access 0x" - + Integer.toHexString(access)); - } - } - - public Iterable<? extends Dependency> findDependencies(ClassFile classfile) { - try { - Visitor v = new Visitor(classfile); - v.addClass(classfile.super_class); - v.addClasses(classfile.interfaces); - // inner classes? - for (Field f : classfile.fields) { - if (checkAccess(f.access_flags)) - v.scan(f.descriptor, f.attributes); - } - for (Method m : classfile.methods) { - if (checkAccess(m.access_flags)) { - v.scan(m.descriptor, m.attributes); - Exceptions_attribute e = - (Exceptions_attribute) m.attributes.get(Attribute.Exceptions); - if (e != null) - v.addClasses(e.exception_index_table); - } - } - return v.deps; - } catch (ConstantPoolException e) { - throw new ClassFileError(e); - } - } - - boolean checkAccess(AccessFlags flags) { - // code copied from javap.Options.checkAccess - boolean isPublic = flags.is(AccessFlags.ACC_PUBLIC); - boolean isProtected = flags.is(AccessFlags.ACC_PROTECTED); - boolean isPrivate = flags.is(AccessFlags.ACC_PRIVATE); - boolean isPackage = !(isPublic || isProtected || isPrivate); - - if ((showAccess == AccessFlags.ACC_PUBLIC) && (isProtected || isPrivate || isPackage)) - return false; - else if ((showAccess == AccessFlags.ACC_PROTECTED) && (isPrivate || isPackage)) - return false; - else if ((showAccess == 0) && (isPrivate)) - return false; - else - return true; - } - - private int showAccess; - } - - static abstract class BasicDependencyFinder implements Finder { - private Map<String,Location> locations = new HashMap<>(); - - Location getLocation(String className) { - Location l = locations.get(className); - if (l == null) - locations.put(className, l = new SimpleLocation(className)); - return l; - } - - class Visitor implements ConstantPool.Visitor<Void,Void>, Type.Visitor<Void, Void> { - private ConstantPool constant_pool; - private Location origin; - Set<Dependency> deps; - - Visitor(ClassFile classFile) { - try { - constant_pool = classFile.constant_pool; - origin = getLocation(classFile.getName()); - deps = new HashSet<>(); - } catch (ConstantPoolException e) { - throw new ClassFileError(e); - } - } - - void scan(Descriptor d, Attributes attrs) { - try { - scan(new Signature(d.index).getType(constant_pool)); - scan(attrs); - } catch (ConstantPoolException e) { - throw new ClassFileError(e); - } - } - - void scan(CPInfo cpInfo) { - cpInfo.accept(this, null); - } - - void scan(Type t) { - t.accept(this, null); - } - - void scan(Attributes attrs) { - try { - Signature_attribute sa = (Signature_attribute)attrs.get(Attribute.Signature); - if (sa != null) - scan(sa.getParsedSignature().getType(constant_pool)); - - scan((RuntimeVisibleAnnotations_attribute) - attrs.get(Attribute.RuntimeVisibleAnnotations)); - scan((RuntimeVisibleParameterAnnotations_attribute) - attrs.get(Attribute.RuntimeVisibleParameterAnnotations)); - } catch (ConstantPoolException e) { - throw new ClassFileError(e); - } - } - - private void scan(RuntimeAnnotations_attribute attr) throws ConstantPoolException { - if (attr == null) { - return; - } - for (int i = 0; i < attr.annotations.length; i++) { - int index = attr.annotations[i].type_index; - scan(new Signature(index).getType(constant_pool)); - } - } - - private void scan(RuntimeParameterAnnotations_attribute attr) throws ConstantPoolException { - if (attr == null) { - return; - } - for (int param = 0; param < attr.parameter_annotations.length; param++) { - for (int i = 0; i < attr.parameter_annotations[param].length; i++) { - int index = attr.parameter_annotations[param][i].type_index; - scan(new Signature(index).getType(constant_pool)); - } - } - } - - void addClass(int index) throws ConstantPoolException { - if (index != 0) { - String name = constant_pool.getClassInfo(index).getBaseName(); - if (name != null) - addDependency(name); - } - } - - void addClasses(int[] indices) throws ConstantPoolException { - for (int i: indices) - addClass(i); - } - - private void addDependency(String name) { - deps.add(new SimpleDependency(origin, getLocation(name))); - } - - // ConstantPool.Visitor methods - - public Void visitClass(CONSTANT_Class_info info, Void p) { - try { - if (info.getName().startsWith("[")) - new Signature(info.name_index).getType(constant_pool).accept(this, null); - else - addDependency(info.getBaseName()); - return null; - } catch (ConstantPoolException e) { - throw new ClassFileError(e); - } - } - - public Void visitDouble(CONSTANT_Double_info info, Void p) { - return null; - } - - public Void visitFieldref(CONSTANT_Fieldref_info info, Void p) { - return visitRef(info, p); - } - - public Void visitFloat(CONSTANT_Float_info info, Void p) { - return null; - } - - public Void visitInteger(CONSTANT_Integer_info info, Void p) { - return null; - } - - public Void visitInterfaceMethodref(CONSTANT_InterfaceMethodref_info info, Void p) { - return visitRef(info, p); - } - - public Void visitInvokeDynamic(CONSTANT_InvokeDynamic_info info, Void p) { - return null; - } - - public Void visitLong(CONSTANT_Long_info info, Void p) { - return null; - } - - public Void visitMethodHandle(CONSTANT_MethodHandle_info info, Void p) { - return null; - } - - public Void visitMethodType(CONSTANT_MethodType_info info, Void p) { - return null; - } - - public Void visitMethodref(CONSTANT_Methodref_info info, Void p) { - return visitRef(info, p); - } - - public Void visitNameAndType(CONSTANT_NameAndType_info info, Void p) { - try { - new Signature(info.type_index).getType(constant_pool).accept(this, null); - return null; - } catch (ConstantPoolException e) { - throw new ClassFileError(e); - } - } - - public Void visitString(CONSTANT_String_info info, Void p) { - return null; - } - - public Void visitUtf8(CONSTANT_Utf8_info info, Void p) { - return null; - } - - private Void visitRef(CPRefInfo info, Void p) { - try { - visitClass(info.getClassInfo(), p); - return null; - } catch (ConstantPoolException e) { - throw new ClassFileError(e); - } - } - - // Type.Visitor methods - - private void findDependencies(Type t) { - if (t != null) - t.accept(this, null); - } - - private void findDependencies(List<? extends Type> ts) { - if (ts != null) { - for (Type t: ts) - t.accept(this, null); - } - } - - public Void visitSimpleType(SimpleType type, Void p) { - return null; - } - - public Void visitArrayType(ArrayType type, Void p) { - findDependencies(type.elemType); - return null; - } - - public Void visitMethodType(MethodType type, Void p) { - findDependencies(type.paramTypes); - findDependencies(type.returnType); - findDependencies(type.throwsTypes); - findDependencies(type.typeParamTypes); - return null; - } - - public Void visitClassSigType(ClassSigType type, Void p) { - findDependencies(type.superclassType); - findDependencies(type.superinterfaceTypes); - return null; - } - - public Void visitClassType(ClassType type, Void p) { - findDependencies(type.outerType); - addDependency(type.getBinaryName()); - findDependencies(type.typeArgs); - return null; - } - - public Void visitTypeParamType(TypeParamType type, Void p) { - findDependencies(type.classBound); - findDependencies(type.interfaceBounds); - return null; - } - - public Void visitWildcardType(WildcardType type, Void p) { - findDependencies(type.boundType); - return null; - } - } - } -}
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/classfile/Dependency.java Thu May 28 16:13:55 2015 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,102 +0,0 @@ -/* - * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package com.sun.tools.classfile; - - -/** - * A directed relationship between two {@link Dependency.Location Location}s. - * Subtypes of {@code Dependency} may provide additional detail about the dependency. - * - * @see Dependency.Finder - * @see Dependency.Filter - * @see Dependencies - */ -public interface Dependency { - /** - * A filter used to select dependencies of interest, and to discard others. - */ - public interface Filter { - /** - * Return true if the dependency is of interest. - * @param dependency the dependency to be considered - * @return true if and only if the dependency is of interest. - */ - boolean accepts(Dependency dependency); - } - - /** - * An interface for finding the immediate dependencies of a given class file. - */ - public interface Finder { - /** - * Find the immediate dependencies of a given class file. - * @param classfile the class file to be examined - * @return the dependencies located in the given class file. - */ - public Iterable<? extends Dependency> findDependencies(ClassFile classfile); - } - - - /** - * A location somewhere within a class. Subtypes of {@code Location} - * may be used to provide additional detail about the location. - */ - public interface Location { - /** - * Get the name of the class containing the location. - * This name will be used to locate the class file for transitive - * dependency analysis. - * @return the name of the class containing the location. - */ - String getName(); - - /** - * Get the fully-qualified name of the class containing the location. - * @return the fully-qualified name of the class containing the location. - */ - String getClassName(); - - /** - * Get the package name of the class containing the location. - * @return the package name of the class containing the location. - */ - String getPackageName(); - } - - - /** - * Get the location that has the dependency. - * @return the location that has the dependency. - */ - Location getOrigin(); - - /** - * Get the location that is being depended upon. - * @return the location that is being depended upon. - */ - Location getTarget(); -} -
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/classfile/Deprecated_attribute.java Thu May 28 16:13:55 2015 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,55 +0,0 @@ -/* - * Copyright (c) 2007, 2008, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package com.sun.tools.classfile; - -import java.io.IOException; - -/** - * See JVMS, section 4.8.15. - * - * <p><b>This is NOT part of any supported API. - * If you write code that depends on this, you do so at your own risk. - * This code and its internal interfaces are subject to change or - * deletion without notice.</b> - */ -public class Deprecated_attribute extends Attribute { - Deprecated_attribute(ClassReader cr, int name_index, int length) throws IOException { - super(name_index, length); - } - - public Deprecated_attribute(ConstantPool constant_pool) - throws ConstantPoolException { - this(constant_pool.getUTF8Index(Attribute.Deprecated)); - } - - public Deprecated_attribute(int name_index) { - super(name_index, 0); - } - - public <R, D> R accept(Visitor<R, D> visitor, D data) { - return visitor.visitDeprecated(this, data); - } -}
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/classfile/Descriptor.java Thu May 28 16:13:55 2015 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,199 +0,0 @@ -/* - * Copyright (c) 2007, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - - -package com.sun.tools.classfile; - -import java.io.IOException; - -/** - * See JVMS, section 4.4. - * - * <p><b>This is NOT part of any supported API. - * If you write code that depends on this, you do so at your own risk. - * This code and its internal interfaces are subject to change or - * deletion without notice.</b> - */ -public class Descriptor { - public static class InvalidDescriptor extends DescriptorException { - private static final long serialVersionUID = 1L; - InvalidDescriptor(String desc) { - this.desc = desc; - this.index = -1; - } - - InvalidDescriptor(String desc, int index) { - this.desc = desc; - this.index = index; - } - - @Override - public String getMessage() { - // i18n - if (index == -1) - return "invalid descriptor \"" + desc + "\""; - else - return "descriptor is invalid at offset " + index + " in \"" + desc + "\""; - } - - public final String desc; - public final int index; - - } - - public Descriptor(ClassReader cr) throws IOException { - this(cr.readUnsignedShort()); - } - - public Descriptor(int index) { - this.index = index; - - } - - public String getValue(ConstantPool constant_pool) throws ConstantPoolException { - return constant_pool.getUTF8Value(index); - } - - public int getParameterCount(ConstantPool constant_pool) - throws ConstantPoolException, InvalidDescriptor { - String desc = getValue(constant_pool); - int end = desc.indexOf(")"); - if (end == -1) - throw new InvalidDescriptor(desc); - parse(desc, 0, end + 1); - return count; - - } - - public String getParameterTypes(ConstantPool constant_pool) - throws ConstantPoolException, InvalidDescriptor { - String desc = getValue(constant_pool); - int end = desc.indexOf(")"); - if (end == -1) - throw new InvalidDescriptor(desc); - return parse(desc, 0, end + 1); - } - - public String getReturnType(ConstantPool constant_pool) - throws ConstantPoolException, InvalidDescriptor { - String desc = getValue(constant_pool); - int end = desc.indexOf(")"); - if (end == -1) - throw new InvalidDescriptor(desc); - return parse(desc, end + 1, desc.length()); - } - - public String getFieldType(ConstantPool constant_pool) - throws ConstantPoolException, InvalidDescriptor { - String desc = getValue(constant_pool); - return parse(desc, 0, desc.length()); - } - - private String parse(String desc, int start, int end) - throws InvalidDescriptor { - int p = start; - StringBuilder sb = new StringBuilder(); - int dims = 0; - count = 0; - - while (p < end) { - String type; - char ch; - switch (ch = desc.charAt(p++)) { - case '(': - sb.append('('); - continue; - - case ')': - sb.append(')'); - continue; - - case '[': - dims++; - continue; - - case 'B': - type = "byte"; - break; - - case 'C': - type = "char"; - break; - - case 'D': - type = "double"; - break; - - case 'F': - type = "float"; - break; - - case 'I': - type = "int"; - break; - - case 'J': - type = "long"; - break; - - case 'L': - int sep = desc.indexOf(';', p); - if (sep == -1) - throw new InvalidDescriptor(desc, p - 1); - type = desc.substring(p, sep).replace('/', '.'); - p = sep + 1; - break; - - case 'S': - type = "short"; - break; - - case 'Z': - type = "boolean"; - break; - - case 'V': - type = "void"; - break; - - default: - throw new InvalidDescriptor(desc, p - 1); - } - - if (sb.length() > 1 && sb.charAt(0) == '(') - sb.append(", "); - sb.append(type); - for ( ; dims > 0; dims-- ) - sb.append("[]"); - - count++; - } - - return sb.toString(); - } - - public final int index; - private int count; -}
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/classfile/DescriptorException.java Thu May 28 16:13:55 2015 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,37 +0,0 @@ -/* - * Copyright (c) 2008, 2009, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - - -package com.sun.tools.classfile; - -/* - * <p><b>This is NOT part of any supported API. - * If you write code that depends on this, you do so at your own risk. - * This code and its internal interfaces are subject to change or - * deletion without notice.</b> - */ -public class DescriptorException extends Exception { - private static final long serialVersionUID = 2411890273788901032L; -}
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/classfile/EnclosingMethod_attribute.java Thu May 28 16:13:55 2015 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,73 +0,0 @@ - -/* - * Copyright (c) 2007, 2008, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package com.sun.tools.classfile; - -import java.io.IOException; - -/** - * See JVMS, section 4.8.7. - * - * <p><b>This is NOT part of any supported API. - * If you write code that depends on this, you do so at your own risk. - * This code and its internal interfaces are subject to change or - * deletion without notice.</b> - */ -public class EnclosingMethod_attribute extends Attribute { - EnclosingMethod_attribute(ClassReader cr, int name_index, int length) throws IOException { - super(name_index, length); - class_index = cr.readUnsignedShort(); - method_index = cr.readUnsignedShort(); - } - - public EnclosingMethod_attribute(ConstantPool constant_pool, int class_index, int method_index) - throws ConstantPoolException { - this(constant_pool.getUTF8Index(Attribute.EnclosingMethod), class_index, method_index); - } - - public EnclosingMethod_attribute(int name_index, int class_index, int method_index) { - super(name_index, 4); - this.class_index = class_index; - this.method_index = method_index; - } - - public String getClassName(ConstantPool constant_pool) throws ConstantPoolException { - return constant_pool.getClassInfo(class_index).getName(); - } - - public String getMethodName(ConstantPool constant_pool) throws ConstantPoolException { - if (method_index == 0) - return ""; - return constant_pool.getNameAndTypeInfo(method_index).getName(); - } - - public <R, D> R accept(Visitor<R, D> visitor, D data) { - return visitor.visitEnclosingMethod(this, data); - } - - public final int class_index; - public final int method_index; -}
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/classfile/Exceptions_attribute.java Thu May 28 16:13:55 2015 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,69 +0,0 @@ -/* - * Copyright (c) 2007, 2008, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package com.sun.tools.classfile; - -import java.io.IOException; - -/** - * See JVMS, section 4.8.5. - * - * <p><b>This is NOT part of any supported API. - * If you write code that depends on this, you do so at your own risk. - * This code and its internal interfaces are subject to change or - * deletion without notice.</b> - */ -public class Exceptions_attribute extends Attribute { - Exceptions_attribute(ClassReader cr, int name_index, int length) throws IOException { - super(name_index, length); - number_of_exceptions = cr.readUnsignedShort(); - exception_index_table = new int[number_of_exceptions]; - for (int i = 0; i < number_of_exceptions; i++) - exception_index_table[i] = cr.readUnsignedShort(); - } - - public Exceptions_attribute(ConstantPool constant_pool, int[] exception_index_table) - throws ConstantPoolException { - this(constant_pool.getUTF8Index(Attribute.Exceptions), exception_index_table); - } - - public Exceptions_attribute(int name_index, int[] exception_index_table) { - super(name_index, 2 + 2 * exception_index_table.length); - this.number_of_exceptions = exception_index_table.length; - this.exception_index_table = exception_index_table; - } - - public String getException(int index, ConstantPool constant_pool) throws ConstantPoolException { - int exception_index = exception_index_table[index]; - return constant_pool.getClassInfo(exception_index).getName(); - } - - public <R, D> R accept(Visitor<R, D> visitor, D data) { - return visitor.visitExceptions(this, data); - } - - public final int number_of_exceptions; - public final int[] exception_index_table; -}
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/classfile/Field.java Thu May 28 16:13:55 2015 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,65 +0,0 @@ -/* - * Copyright (c) 2007, 2008, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package com.sun.tools.classfile; - -import java.io.IOException; - -/* - * <p><b>This is NOT part of any supported API. - * If you write code that depends on this, you do so at your own risk. - * This code and its internal interfaces are subject to change or - * deletion without notice.</b> - */ -public class Field { - Field(ClassReader cr) throws IOException { - access_flags = new AccessFlags(cr); - name_index = cr.readUnsignedShort(); - descriptor = new Descriptor(cr); - attributes = new Attributes(cr); - } - - public Field(AccessFlags access_flags, - int name_index, Descriptor descriptor, - Attributes attributes) { - this.access_flags = access_flags; - this.name_index = name_index; - this.descriptor = descriptor; - this.attributes = attributes; - } - - public int byteLength() { - return 6 + attributes.byteLength(); - } - - public String getName(ConstantPool constant_pool) throws ConstantPoolException { - return constant_pool.getUTF8Value(name_index); - } - - public final AccessFlags access_flags; - public final int name_index; - public final Descriptor descriptor; - public final Attributes attributes; -}
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/classfile/InnerClasses_attribute.java Thu May 28 16:13:55 2015 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,102 +0,0 @@ -/* - * Copyright (c) 2007, 2008, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package com.sun.tools.classfile; - -import java.io.IOException; - -import com.sun.tools.classfile.ConstantPool.*; - -/** - * See JVMS, section 4.8.6. - * - * <p><b>This is NOT part of any supported API. - * If you write code that depends on this, you do so at your own risk. - * This code and its internal interfaces are subject to change or - * deletion without notice.</b> - */ -public class InnerClasses_attribute extends Attribute { - InnerClasses_attribute(ClassReader cr, int name_index, int length) throws IOException { - super(name_index, length); - number_of_classes = cr.readUnsignedShort(); - classes = new Info[number_of_classes]; - for (int i = 0; i < number_of_classes; i++) - classes[i] = new Info(cr); - } - - public InnerClasses_attribute(ConstantPool constant_pool, Info[] classes) - throws ConstantPoolException { - this(constant_pool.getUTF8Index(Attribute.InnerClasses), classes); - } - - public InnerClasses_attribute(int name_index, Info[] classes) { - super(name_index, 2 + Info.length() * classes.length); - this.number_of_classes = classes.length; - this.classes = classes; - } - - public <R, D> R accept(Visitor<R, D> visitor, D data) { - return visitor.visitInnerClasses(this, data); - } - - public final int number_of_classes; - public final Info[] classes; - - public static class Info { - Info(ClassReader cr) throws IOException { - inner_class_info_index = cr.readUnsignedShort(); - outer_class_info_index = cr.readUnsignedShort(); - inner_name_index = cr.readUnsignedShort(); - inner_class_access_flags = new AccessFlags(cr.readUnsignedShort()); - } - - public CONSTANT_Class_info getInnerClassInfo(ConstantPool constant_pool) throws ConstantPoolException { - if (inner_class_info_index == 0) - return null; - return constant_pool.getClassInfo(inner_class_info_index); - } - - public CONSTANT_Class_info getOuterClassInfo(ConstantPool constant_pool) throws ConstantPoolException { - if (outer_class_info_index == 0) - return null; - return constant_pool.getClassInfo(outer_class_info_index); - } - - public String getInnerName(ConstantPool constant_pool) throws ConstantPoolException { - if (inner_name_index == 0) - return null; - return constant_pool.getUTF8Value(inner_name_index); - } - - public static int length() { - return 8; - } - - public final int inner_class_info_index; - public final int outer_class_info_index; - public final int inner_name_index; - public final AccessFlags inner_class_access_flags; - } -}
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/classfile/Instruction.java Thu May 28 16:13:55 2015 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,353 +0,0 @@ -/* - * Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package com.sun.tools.classfile; - -import java.util.Locale; - -/** - * See JVMS, chapter 6. - * - * <p><b>This is NOT part of any supported API. - * If you write code that depends on this, you do so at your own risk. - * This code and its internal interfaces are subject to change or - * deletion without notice.</b> - * - * @see Code_attribute#getInstructions - */ -public class Instruction { - /** The kind of an instruction, as determined by the position, size and - * types of its operands. */ - public static enum Kind { - /** Opcode is not followed by any operands. */ - NO_OPERANDS(1), - /** Opcode is followed by a byte indicating a type. */ - ATYPE(2), - /** Opcode is followed by a 2-byte branch offset. */ - BRANCH(3), - /** Opcode is followed by a 4-byte branch offset. */ - BRANCH_W(5), - /** Opcode is followed by a signed byte value. */ - BYTE(2), - /** Opcode is followed by a 1-byte index into the constant pool. */ - CPREF(2), - /** Opcode is followed by a 2-byte index into the constant pool. */ - CPREF_W(3), - /** Opcode is followed by a 2-byte index into the constant pool, - * an unsigned byte value. */ - CPREF_W_UBYTE(4), - /** Opcode is followed by a 2-byte index into the constant pool., - * an unsigned byte value, and a zero byte. */ - CPREF_W_UBYTE_ZERO(5), - /** Opcode is followed by variable number of operands, depending - * on the instruction.*/ - DYNAMIC(-1), - /** Opcode is followed by a 1-byte reference to a local variable. */ - LOCAL(2), - /** Opcode is followed by a 1-byte reference to a local variable, - * and a signed byte value. */ - LOCAL_BYTE(3), - /** Opcode is followed by a signed short value. */ - SHORT(3), - /** Wide opcode is not followed by any operands. */ - WIDE_NO_OPERANDS(2), - /** Wide opcode is followed by a 2-byte index into the local variables array. */ - WIDE_LOCAL(4), - /** Wide opcode is followed by a 2-byte index into the constant pool. */ - WIDE_CPREF_W(4), - /** Wide opcode is followed by a 2-byte index into the constant pool, - * and a signed short value. */ - WIDE_CPREF_W_SHORT(6), - /** Wide opcode is followed by a 2-byte reference to a local variable, - * and a signed short value. */ - WIDE_LOCAL_SHORT(6), - /** Opcode was not recognized. */ - UNKNOWN(1); - - Kind(int length) { - this.length = length; - } - - /** The length, in bytes, of this kind of instruction, or -1 is the - * length depends on the specific instruction. */ - public final int length; - } - - /** A utility visitor to help decode the operands of an instruction. - * @see Instruction#accept */ - public interface KindVisitor<R,P> { - /** See {@link Kind#NO_OPERANDS}, {@link Kind#WIDE_NO_OPERANDS}. */ - R visitNoOperands(Instruction instr, P p); - /** See {@link Kind#ATYPE}. */ - R visitArrayType(Instruction instr, TypeKind kind, P p); - /** See {@link Kind#BRANCH}, {@link Kind#BRANCH_W}. */ - R visitBranch(Instruction instr, int offset, P p); - /** See {@link Kind#CPREF}, {@link Kind#CPREF_W}, {@link Kind#WIDE_CPREF_W}. */ - R visitConstantPoolRef(Instruction instr, int index, P p); - /** See {@link Kind#CPREF_W_UBYTE}, {@link Kind#CPREF_W_UBYTE_ZERO}, {@link Kind#WIDE_CPREF_W_SHORT}. */ - R visitConstantPoolRefAndValue(Instruction instr, int index, int value, P p); - /** See {@link Kind#LOCAL}, {@link Kind#WIDE_LOCAL}. */ - R visitLocal(Instruction instr, int index, P p); - /** See {@link Kind#LOCAL_BYTE}. */ - R visitLocalAndValue(Instruction instr, int index, int value, P p); - /** See {@link Kind#DYNAMIC}. */ - R visitLookupSwitch(Instruction instr, int default_, int npairs, int[] matches, int[] offsets, P p); - /** See {@link Kind#DYNAMIC}. */ - R visitTableSwitch(Instruction instr, int default_, int low, int high, int[] offsets, P p); - /** See {@link Kind#BYTE}, {@link Kind#SHORT}. */ - R visitValue(Instruction instr, int value, P p); - /** Instruction is unrecognized. */ - R visitUnknown(Instruction instr, P p); - - } - - /** The kind of primitive array type to create. - * See JVMS chapter 6, newarray. */ - public static enum TypeKind { - T_BOOLEAN(4, "boolean"), - T_CHAR(5, "char"), - T_FLOAT(6, "float"), - T_DOUBLE(7, "double"), - T_BYTE(8, "byte"), - T_SHORT(9, "short"), - T_INT (10, "int"), - T_LONG (11, "long"); - TypeKind(int value, String name) { - this.value = value; - this.name = name; - } - - public static TypeKind get(int value) { - switch (value) { - case 4: return T_BOOLEAN; - case 5: return T_CHAR; - case 6: return T_FLOAT; - case 7: return T_DOUBLE; - case 8: return T_BYTE; - case 9: return T_SHORT; - case 10: return T_INT; - case 11: return T_LONG; - default: return null; - } - } - - public final int value; - public final String name; - } - - /** An instruction is defined by its position in a bytecode array. */ - public Instruction(byte[] bytes, int pc) { - this.bytes = bytes; - this.pc = pc; - } - - /** Get the position of the instruction within the bytecode array. */ - public int getPC() { - return pc; - } - - /** Get a byte value, relative to the start of this instruction. */ - public int getByte(int offset) { - return bytes[pc + offset]; - } - - /** Get an unsigned byte value, relative to the start of this instruction. */ - public int getUnsignedByte(int offset) { - return getByte(offset) & 0xff; - } - - /** Get a 2-byte value, relative to the start of this instruction. */ - public int getShort(int offset) { - return (getByte(offset) << 8) | getUnsignedByte(offset + 1); - } - - /** Get a unsigned 2-byte value, relative to the start of this instruction. */ - public int getUnsignedShort(int offset) { - return getShort(offset) & 0xFFFF; - } - - /** Get a 4-byte value, relative to the start of this instruction. */ - public int getInt(int offset) { - return (getShort(offset) << 16) | (getUnsignedShort(offset + 2)); - } - - /** Get the Opcode for this instruction, or null if the instruction is - * unrecognized. */ - public Opcode getOpcode() { - int b = getUnsignedByte(0); - switch (b) { - case Opcode.NONPRIV: - case Opcode.PRIV: - case Opcode.WIDE: - return Opcode.get(b, getUnsignedByte(1)); - } - return Opcode.get(b); - } - - /** Get the mnemonic for this instruction, or a default string if the - * instruction is unrecognized. */ - public String getMnemonic() { - Opcode opcode = getOpcode(); - if (opcode == null) - return "bytecode " + getUnsignedByte(0); - else - return opcode.toString().toLowerCase(Locale.US); - } - - /** Get the length, in bytes, of this instruction, including the opcode - * and all its operands. */ - public int length() { - Opcode opcode = getOpcode(); - if (opcode == null) - return 1; - - switch (opcode) { - case TABLESWITCH: { - int pad = align(pc + 1) - pc; - int low = getInt(pad + 4); - int high = getInt(pad + 8); - return pad + 12 + 4 * (high - low + 1); - } - case LOOKUPSWITCH: { - int pad = align(pc + 1) - pc; - int npairs = getInt(pad + 4); - return pad + 8 + 8 * npairs; - - } - default: - return opcode.kind.length; - } - } - - /** Get the {@link Kind} of this instruction. */ - public Kind getKind() { - Opcode opcode = getOpcode(); - return (opcode != null ? opcode.kind : Kind.UNKNOWN); - } - - /** Invoke a method on the visitor according to the kind of this - * instruction, passing in the decoded operands for the instruction. */ - public <R,P> R accept(KindVisitor<R,P> visitor, P p) { - switch (getKind()) { - case NO_OPERANDS: - return visitor.visitNoOperands(this, p); - - case ATYPE: - return visitor.visitArrayType( - this, TypeKind.get(getUnsignedByte(1)), p); - - case BRANCH: - return visitor.visitBranch(this, getShort(1), p); - - case BRANCH_W: - return visitor.visitBranch(this, getInt(1), p); - - case BYTE: - return visitor.visitValue(this, getByte(1), p); - - case CPREF: - return visitor.visitConstantPoolRef(this, getUnsignedByte(1), p); - - case CPREF_W: - return visitor.visitConstantPoolRef(this, getUnsignedShort(1), p); - - case CPREF_W_UBYTE: - case CPREF_W_UBYTE_ZERO: - return visitor.visitConstantPoolRefAndValue( - this, getUnsignedShort(1), getUnsignedByte(3), p); - - case DYNAMIC: { - switch (getOpcode()) { - case TABLESWITCH: { - int pad = align(pc + 1) - pc; - int default_ = getInt(pad); - int low = getInt(pad + 4); - int high = getInt(pad + 8); - int[] values = new int[high - low + 1]; - for (int i = 0; i < values.length; i++) - values[i] = getInt(pad + 12 + 4 * i); - return visitor.visitTableSwitch( - this, default_, low, high, values, p); - } - case LOOKUPSWITCH: { - int pad = align(pc + 1) - pc; - int default_ = getInt(pad); - int npairs = getInt(pad + 4); - int[] matches = new int[npairs]; - int[] offsets = new int[npairs]; - for (int i = 0; i < npairs; i++) { - matches[i] = getInt(pad + 8 + i * 8); - offsets[i] = getInt(pad + 12 + i * 8); - } - return visitor.visitLookupSwitch( - this, default_, npairs, matches, offsets, p); - } - default: - throw new IllegalStateException(); - } - } - - case LOCAL: - return visitor.visitLocal(this, getUnsignedByte(1), p); - - case LOCAL_BYTE: - return visitor.visitLocalAndValue( - this, getUnsignedByte(1), getByte(2), p); - - case SHORT: - return visitor.visitValue(this, getShort(1), p); - - case WIDE_NO_OPERANDS: - return visitor.visitNoOperands(this, p); - - case WIDE_LOCAL: - return visitor.visitLocal(this, getUnsignedShort(2), p); - - case WIDE_CPREF_W: - return visitor.visitConstantPoolRef(this, getUnsignedShort(2), p); - - case WIDE_CPREF_W_SHORT: - return visitor.visitConstantPoolRefAndValue( - this, getUnsignedShort(2), getUnsignedByte(4), p); - - case WIDE_LOCAL_SHORT: - return visitor.visitLocalAndValue( - this, getUnsignedShort(2), getShort(4), p); - - case UNKNOWN: - return visitor.visitUnknown(this, p); - - default: - throw new IllegalStateException(); - } - } - - private static int align(int n) { - return (n + 3) & ~3; - } - - private byte[] bytes; - private int pc; -}
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/classfile/LineNumberTable_attribute.java Thu May 28 16:13:55 2015 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,78 +0,0 @@ -/* - * Copyright (c) 2007, 2008, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package com.sun.tools.classfile; - -import java.io.IOException; - -/** - * See JVMS, section 4.8.12. - * - * <p><b>This is NOT part of any supported API. - * If you write code that depends on this, you do so at your own risk. - * This code and its internal interfaces are subject to change or - * deletion without notice.</b> - */ -public class LineNumberTable_attribute extends Attribute { - LineNumberTable_attribute(ClassReader cr, int name_index, int length) throws IOException { - super(name_index, length); - line_number_table_length = cr.readUnsignedShort(); - line_number_table = new Entry[line_number_table_length]; - for (int i = 0; i < line_number_table_length; i++) - line_number_table[i] = new Entry(cr); - } - - public LineNumberTable_attribute(ConstantPool constant_pool, Entry[] line_number_table) - throws ConstantPoolException { - this(constant_pool.getUTF8Index(Attribute.LineNumberTable), line_number_table); - } - - public LineNumberTable_attribute(int name_index, Entry[] line_number_table) { - super(name_index, 2 + line_number_table.length * Entry.length()); - this.line_number_table_length = line_number_table.length; - this.line_number_table = line_number_table; - } - - public <R, D> R accept(Visitor<R, D> visitor, D data) { - return visitor.visitLineNumberTable(this, data); - } - - public final int line_number_table_length; - public final Entry[] line_number_table; - - public static class Entry { - Entry(ClassReader cr) throws IOException { - start_pc = cr.readUnsignedShort(); - line_number = cr.readUnsignedShort(); - } - - public static int length() { - return 4; - } - - public final int start_pc; - public final int line_number; - } -}
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/classfile/LocalVariableTable_attribute.java Thu May 28 16:13:55 2015 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,84 +0,0 @@ -/* - * Copyright (c) 2007, 2008, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package com.sun.tools.classfile; - -import java.io.IOException; - -/** - * See JVMS, section 4.8.13. - * - * <p><b>This is NOT part of any supported API. - * If you write code that depends on this, you do so at your own risk. - * This code and its internal interfaces are subject to change or - * deletion without notice.</b> - */ -public class LocalVariableTable_attribute extends Attribute { - LocalVariableTable_attribute(ClassReader cr, int name_index, int length) throws IOException { - super(name_index, length); - local_variable_table_length = cr.readUnsignedShort(); - local_variable_table = new Entry[local_variable_table_length]; - for (int i = 0; i < local_variable_table_length; i++) - local_variable_table[i] = new Entry(cr); - } - - public LocalVariableTable_attribute(ConstantPool constant_pool, Entry[] local_variable_table) - throws ConstantPoolException { - this(constant_pool.getUTF8Index(Attribute.LocalVariableTable), local_variable_table); - } - - public LocalVariableTable_attribute(int name_index, Entry[] local_variable_table) { - super(name_index, 2 + local_variable_table.length * Entry.length()); - this.local_variable_table_length = local_variable_table.length; - this.local_variable_table = local_variable_table; - } - - public <R, D> R accept(Visitor<R, D> visitor, D data) { - return visitor.visitLocalVariableTable(this, data); - } - - public final int local_variable_table_length; - public final Entry[] local_variable_table; - - public static class Entry { - Entry(ClassReader cr) throws IOException { - start_pc = cr.readUnsignedShort(); - length = cr.readUnsignedShort(); - name_index = cr.readUnsignedShort(); - descriptor_index = cr.readUnsignedShort(); - index = cr.readUnsignedShort(); - } - - public static int length() { - return 10; - } - - public final int start_pc; - public final int length; - public final int name_index; - public final int descriptor_index; - public final int index; - } -}
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/classfile/LocalVariableTypeTable_attribute.java Thu May 28 16:13:55 2015 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,84 +0,0 @@ -/* - * Copyright (c) 2007, 2008, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package com.sun.tools.classfile; - -import java.io.IOException; - -/** - * See JVMS, section 4.8.14. - * - * <p><b>This is NOT part of any supported API. - * If you write code that depends on this, you do so at your own risk. - * This code and its internal interfaces are subject to change or - * deletion without notice.</b> - */ -public class LocalVariableTypeTable_attribute extends Attribute { - LocalVariableTypeTable_attribute(ClassReader cr, int name_index, int length) throws IOException { - super(name_index, length); - local_variable_table_length = cr.readUnsignedShort(); - local_variable_table = new Entry[local_variable_table_length]; - for (int i = 0; i < local_variable_table_length; i++) - local_variable_table[i] = new Entry(cr); - } - - public LocalVariableTypeTable_attribute(ConstantPool constant_pool, Entry[] local_variable_table) - throws ConstantPoolException { - this(constant_pool.getUTF8Index(Attribute.LocalVariableTypeTable), local_variable_table); - } - - public LocalVariableTypeTable_attribute(int name_index, Entry[] local_variable_table) { - super(name_index, 2 + local_variable_table.length * Entry.length()); - this.local_variable_table_length = local_variable_table.length; - this.local_variable_table = local_variable_table; - } - - public <R, D> R accept(Visitor<R, D> visitor, D data) { - return visitor.visitLocalVariableTypeTable(this, data); - } - - public final int local_variable_table_length; - public final Entry[] local_variable_table; - - public static class Entry { - Entry(ClassReader cr) throws IOException { - start_pc = cr.readUnsignedShort(); - length = cr.readUnsignedShort(); - name_index = cr.readUnsignedShort(); - signature_index = cr.readUnsignedShort(); - index = cr.readUnsignedShort(); - } - - public static int length() { - return 10; - } - - public final int start_pc; - public final int length; - public final int name_index; - public final int signature_index; - public final int index; - } -}
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/classfile/Method.java Thu May 28 16:13:55 2015 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,65 +0,0 @@ -/* - * Copyright (c) 2007, 2008, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package com.sun.tools.classfile; - -import java.io.IOException; - -/* - * <p><b>This is NOT part of any supported API. - * If you write code that depends on this, you do so at your own risk. - * This code and its internal interfaces are subject to change or - * deletion without notice.</b> - */ -public class Method { - Method(ClassReader cr) throws IOException { - access_flags = new AccessFlags(cr); - name_index = cr.readUnsignedShort(); - descriptor = new Descriptor(cr); - attributes = new Attributes(cr); - } - - public Method(AccessFlags access_flags, - int name_index, Descriptor descriptor, - Attributes attributes) { - this.access_flags = access_flags; - this.name_index = name_index; - this.descriptor = descriptor; - this.attributes = attributes; - } - - public int byteLength() { - return 6 + attributes.byteLength(); - } - - public String getName(ConstantPool constant_pool) throws ConstantPoolException { - return constant_pool.getUTF8Value(name_index); - } - - public final AccessFlags access_flags; - public final int name_index; - public final Descriptor descriptor; - public final Attributes attributes; -}
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/classfile/MethodParameters_attribute.java Thu May 28 16:13:55 2015 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,87 +0,0 @@ -/* - * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package com.sun.tools.classfile; - -import java.io.IOException; - -/** - * See JVMS, section 4.8.13. - * - * <p><b>This is NOT part of any supported API. - * If you write code that depends on this, you do so at your own risk. - * This code and its internal interfaces are subject to change or - * deletion without notice.</b> - */ -public class MethodParameters_attribute extends Attribute { - - public final int method_parameter_table_length; - public final Entry[] method_parameter_table; - - MethodParameters_attribute(ClassReader cr, - int name_index, - int length) - throws IOException { - super(name_index, length); - - method_parameter_table_length = cr.readUnsignedByte(); - method_parameter_table = new Entry[method_parameter_table_length]; - for (int i = 0; i < method_parameter_table_length; i++) - method_parameter_table[i] = new Entry(cr); - } - - public MethodParameters_attribute(ConstantPool constant_pool, - Entry[] method_parameter_table) - throws ConstantPoolException { - this(constant_pool.getUTF8Index(Attribute.MethodParameters), - method_parameter_table); - } - - public MethodParameters_attribute(int name_index, - Entry[] method_parameter_table) { - super(name_index, 1 + method_parameter_table.length * Entry.length()); - this.method_parameter_table_length = method_parameter_table.length; - this.method_parameter_table = method_parameter_table; - } - - public <R, D> R accept(Visitor<R, D> visitor, D data) { - return visitor.visitMethodParameters(this, data); - } - - public static class Entry { - Entry(ClassReader cr) throws IOException { - name_index = cr.readUnsignedShort(); - flags = cr.readUnsignedShort(); - } - - public static int length() { - return 6; - } - - public final int name_index; - public final int flags; - } - -}
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/classfile/Opcode.java Thu May 28 16:13:55 2015 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,472 +0,0 @@ -/* - * Copyright (c) 2009, 2012, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package com.sun.tools.classfile; - -import static com.sun.tools.classfile.Instruction.Kind.*; -import static com.sun.tools.classfile.Opcode.Set.*; - -/** - * See JVMS, chapter 6. - * - * <p>In addition to providing all the standard opcodes defined in JVMS, - * this class also provides legacy support for the PicoJava extensions. - * - * <p><b>This is NOT part of any supported API. - * If you write code that depends on this, you do so at your own risk. - * This code and its internal interfaces are subject to change or - * deletion without notice.</b> - */ -public enum Opcode { - NOP(0x0), - ACONST_NULL(0x1), - ICONST_M1(0x2), - ICONST_0(0x3), - ICONST_1(0x4), - ICONST_2(0x5), - ICONST_3(0x6), - ICONST_4(0x7), - ICONST_5(0x8), - LCONST_0(0x9), - LCONST_1(0xa), - FCONST_0(0xb), - FCONST_1(0xc), - FCONST_2(0xd), - DCONST_0(0xe), - DCONST_1(0xf), - BIPUSH(0x10, BYTE), - SIPUSH(0x11, SHORT), - LDC(0x12, CPREF), - LDC_W(0x13, CPREF_W), - LDC2_W(0x14, CPREF_W), - ILOAD(0x15, LOCAL), - LLOAD(0x16, LOCAL), - FLOAD(0x17, LOCAL), - DLOAD(0x18, LOCAL), - ALOAD(0x19, LOCAL), - ILOAD_0(0x1a), - ILOAD_1(0x1b), - ILOAD_2(0x1c), - ILOAD_3(0x1d), - LLOAD_0(0x1e), - LLOAD_1(0x1f), - LLOAD_2(0x20), - LLOAD_3(0x21), - FLOAD_0(0x22), - FLOAD_1(0x23), - FLOAD_2(0x24), - FLOAD_3(0x25), - DLOAD_0(0x26), - DLOAD_1(0x27), - DLOAD_2(0x28), - DLOAD_3(0x29), - ALOAD_0(0x2a), - ALOAD_1(0x2b), - ALOAD_2(0x2c), - ALOAD_3(0x2d), - IALOAD(0x2e), - LALOAD(0x2f), - FALOAD(0x30), - DALOAD(0x31), - AALOAD(0x32), - BALOAD(0x33), - CALOAD(0x34), - SALOAD(0x35), - ISTORE(0x36, LOCAL), - LSTORE(0x37, LOCAL), - FSTORE(0x38, LOCAL), - DSTORE(0x39, LOCAL), - ASTORE(0x3a, LOCAL), - ISTORE_0(0x3b), - ISTORE_1(0x3c), - ISTORE_2(0x3d), - ISTORE_3(0x3e), - LSTORE_0(0x3f), - LSTORE_1(0x40), - LSTORE_2(0x41), - LSTORE_3(0x42), - FSTORE_0(0x43), - FSTORE_1(0x44), - FSTORE_2(0x45), - FSTORE_3(0x46), - DSTORE_0(0x47), - DSTORE_1(0x48), - DSTORE_2(0x49), - DSTORE_3(0x4a), - ASTORE_0(0x4b), - ASTORE_1(0x4c), - ASTORE_2(0x4d), - ASTORE_3(0x4e), - IASTORE(0x4f), - LASTORE(0x50), - FASTORE(0x51), - DASTORE(0x52), - AASTORE(0x53), - BASTORE(0x54), - CASTORE(0x55), - SASTORE(0x56), - POP(0x57), - POP2(0x58), - DUP(0x59), - DUP_X1(0x5a), - DUP_X2(0x5b), - DUP2(0x5c), - DUP2_X1(0x5d), - DUP2_X2(0x5e), - SWAP(0x5f), - IADD(0x60), - LADD(0x61), - FADD(0x62), - DADD(0x63), - ISUB(0x64), - LSUB(0x65), - FSUB(0x66), - DSUB(0x67), - IMUL(0x68), - LMUL(0x69), - FMUL(0x6a), - DMUL(0x6b), - IDIV(0x6c), - LDIV(0x6d), - FDIV(0x6e), - DDIV(0x6f), - IREM(0x70), - LREM(0x71), - FREM(0x72), - DREM(0x73), - INEG(0x74), - LNEG(0x75), - FNEG(0x76), - DNEG(0x77), - ISHL(0x78), - LSHL(0x79), - ISHR(0x7a), - LSHR(0x7b), - IUSHR(0x7c), - LUSHR(0x7d), - IAND(0x7e), - LAND(0x7f), - IOR(0x80), - LOR(0x81), - IXOR(0x82), - LXOR(0x83), - IINC(0x84, LOCAL_BYTE), - I2L(0x85), - I2F(0x86), - I2D(0x87), - L2I(0x88), - L2F(0x89), - L2D(0x8a), - F2I(0x8b), - F2L(0x8c), - F2D(0x8d), - D2I(0x8e), - D2L(0x8f), - D2F(0x90), - I2B(0x91), - I2C(0x92), - I2S(0x93), - LCMP(0x94), - FCMPL(0x95), - FCMPG(0x96), - DCMPL(0x97), - DCMPG(0x98), - IFEQ(0x99, BRANCH), - IFNE(0x9a, BRANCH), - IFLT(0x9b, BRANCH), - IFGE(0x9c, BRANCH), - IFGT(0x9d, BRANCH), - IFLE(0x9e, BRANCH), - IF_ICMPEQ(0x9f, BRANCH), - IF_ICMPNE(0xa0, BRANCH), - IF_ICMPLT(0xa1, BRANCH), - IF_ICMPGE(0xa2, BRANCH), - IF_ICMPGT(0xa3, BRANCH), - IF_ICMPLE(0xa4, BRANCH), - IF_ACMPEQ(0xa5, BRANCH), - IF_ACMPNE(0xa6, BRANCH), - GOTO(0xa7, BRANCH), - JSR(0xa8, BRANCH), - RET(0xa9, LOCAL), - TABLESWITCH(0xaa, DYNAMIC), - LOOKUPSWITCH(0xab, DYNAMIC), - IRETURN(0xac), - LRETURN(0xad), - FRETURN(0xae), - DRETURN(0xaf), - ARETURN(0xb0), - RETURN(0xb1), - GETSTATIC(0xb2, CPREF_W), - PUTSTATIC(0xb3, CPREF_W), - GETFIELD(0xb4, CPREF_W), - PUTFIELD(0xb5, CPREF_W), - INVOKEVIRTUAL(0xb6, CPREF_W), - INVOKESPECIAL(0xb7, CPREF_W), - INVOKESTATIC(0xb8, CPREF_W), - INVOKEINTERFACE(0xb9, CPREF_W_UBYTE_ZERO), - INVOKEDYNAMIC(0xba, CPREF_W_UBYTE_ZERO), - NEW(0xbb, CPREF_W), - NEWARRAY(0xbc, ATYPE), - ANEWARRAY(0xbd, CPREF_W), - ARRAYLENGTH(0xbe), - ATHROW(0xbf), - CHECKCAST(0xc0, CPREF_W), - INSTANCEOF(0xc1, CPREF_W), - MONITORENTER(0xc2), - MONITOREXIT(0xc3), - // wide 0xc4 - MULTIANEWARRAY(0xc5, CPREF_W_UBYTE), - IFNULL(0xc6, BRANCH), - IFNONNULL(0xc7, BRANCH), - GOTO_W(0xc8, BRANCH_W), - JSR_W(0xc9, BRANCH_W), - // impdep 0xfe: PicoJava nonpriv - // impdep 0xff: Picojava priv - - // wide opcodes - ILOAD_W(0xc415, WIDE_LOCAL), - LLOAD_W(0xc416, WIDE_LOCAL), - FLOAD_W(0xc417, WIDE_LOCAL), - DLOAD_W(0xc418, WIDE_LOCAL), - ALOAD_W(0xc419, WIDE_LOCAL), - ISTORE_W(0xc436, WIDE_LOCAL), - LSTORE_W(0xc437, WIDE_LOCAL), - FSTORE_W(0xc438, WIDE_LOCAL), - DSTORE_W(0xc439, WIDE_LOCAL), - ASTORE_W(0xc43a, WIDE_LOCAL), - IINC_W(0xc484, WIDE_LOCAL_SHORT), - RET_W(0xc4a9, WIDE_LOCAL), - - // PicoJava nonpriv instructions - LOAD_UBYTE(PICOJAVA, 0xfe00), - LOAD_BYTE(PICOJAVA, 0xfe01), - LOAD_CHAR(PICOJAVA, 0xfe02), - LOAD_SHORT(PICOJAVA, 0xfe03), - LOAD_WORD(PICOJAVA, 0xfe04), - RET_FROM_SUB(PICOJAVA, 0xfe05), - LOAD_CHAR_OE(PICOJAVA, 0xfe0a), - LOAD_SHORT_OE(PICOJAVA, 0xfe0b), - LOAD_WORD_OE(PICOJAVA, 0xfe0c), - NCLOAD_UBYTE(PICOJAVA, 0xfe10), - NCLOAD_BYTE(PICOJAVA, 0xfe11), - NCLOAD_CHAR(PICOJAVA, 0xfe12), - NCLOAD_SHORT(PICOJAVA, 0xfe13), - NCLOAD_WORD(PICOJAVA, 0xfe14), - NCLOAD_CHAR_OE(PICOJAVA, 0xfe1a), - NCLOAD_SHORT_OE(PICOJAVA, 0xfe1b), - NCLOAD_WORD_OE(PICOJAVA, 0xfe1c), - CACHE_FLUSH(PICOJAVA, 0xfe1e), - STORE_BYTE(PICOJAVA, 0xfe20), - STORE_SHORT(PICOJAVA, 0xfe22), - STORE_WORD(PICOJAVA, 0xfe24), - STORE_SHORT_OE(PICOJAVA, 0xfe2a), - STORE_WORD_OE(PICOJAVA, 0xfe2c), - NCSTORE_BYTE(PICOJAVA, 0xfe30), - NCSTORE_SHORT(PICOJAVA, 0xfe32), - NCSTORE_WORD(PICOJAVA, 0xfe34), - NCSTORE_SHORT_OE(PICOJAVA, 0xfe3a), - NCSTORE_WORD_OE(PICOJAVA, 0xfe3c), - ZERO_LINE(PICOJAVA, 0xfe3e), - ENTER_SYNC_METHOD(PICOJAVA, 0xfe3f), - - // PicoJava priv instructions - PRIV_LOAD_UBYTE(PICOJAVA, 0xff00), - PRIV_LOAD_BYTE(PICOJAVA, 0xff01), - PRIV_LOAD_CHAR(PICOJAVA, 0xff02), - PRIV_LOAD_SHORT(PICOJAVA, 0xff03), - PRIV_LOAD_WORD(PICOJAVA, 0xff04), - PRIV_RET_FROM_TRAP(PICOJAVA, 0xff05), - PRIV_READ_DCACHE_TAG(PICOJAVA, 0xff06), - PRIV_READ_DCACHE_DATA(PICOJAVA, 0xff07), - PRIV_LOAD_CHAR_OE(PICOJAVA, 0xff0a), - PRIV_LOAD_SHORT_OE(PICOJAVA, 0xff0b), - PRIV_LOAD_WORD_OE(PICOJAVA, 0xff0c), - PRIV_READ_ICACHE_TAG(PICOJAVA, 0xff0e), - PRIV_READ_ICACHE_DATA(PICOJAVA, 0xff0f), - PRIV_NCLOAD_UBYTE(PICOJAVA, 0xff10), - PRIV_NCLOAD_BYTE(PICOJAVA, 0xff11), - PRIV_NCLOAD_CHAR(PICOJAVA, 0xff12), - PRIV_NCLOAD_SHORT(PICOJAVA, 0xff13), - PRIV_NCLOAD_WORD(PICOJAVA, 0xff14), - PRIV_POWERDOWN(PICOJAVA, 0xff16), - PRIV_READ_SCACHE_DATA(PICOJAVA, 0xff17), - PRIV_NCLOAD_CHAR_OE(PICOJAVA, 0xff1a), - PRIV_NCLOAD_SHORT_OE(PICOJAVA, 0xff1b), - PRIV_NCLOAD_WORD_OE(PICOJAVA, 0xff1c), - PRIV_CACHE_FLUSH(PICOJAVA, 0xff1e), - PRIV_CACHE_INDEX_FLUSH(PICOJAVA, 0xff1f), - PRIV_STORE_BYTE(PICOJAVA, 0xff20), - PRIV_STORE_SHORT(PICOJAVA, 0xff22), - PRIV_STORE_WORD(PICOJAVA, 0xff24), - PRIV_WRITE_DCACHE_TAG(PICOJAVA, 0xff26), - PRIV_WRITE_DCACHE_DATA(PICOJAVA, 0xff27), - PRIV_STORE_SHORT_OE(PICOJAVA, 0xff2a), - PRIV_STORE_WORD_OE(PICOJAVA, 0xff2c), - PRIV_WRITE_ICACHE_TAG(PICOJAVA, 0xff2e), - PRIV_WRITE_ICACHE_DATA(PICOJAVA, 0xff2f), - PRIV_NCSTORE_BYTE(PICOJAVA, 0xff30), - PRIV_NCSTORE_SHORT(PICOJAVA, 0xff32), - PRIV_NCSTORE_WORD(PICOJAVA, 0xff34), - PRIV_RESET(PICOJAVA, 0xff36), - PRIV_WRITE_SCACHE_DATA(PICOJAVA, 0xff37), - PRIV_NCSTORE_SHORT_OE(PICOJAVA, 0xff3a), - PRIV_NCSTORE_WORD_OE(PICOJAVA, 0xff3c), - PRIV_ZERO_LINE(PICOJAVA, 0xff3e), - PRIV_READ_REG_0(PICOJAVA, 0xff40), - PRIV_READ_REG_1(PICOJAVA, 0xff41), - PRIV_READ_REG_2(PICOJAVA, 0xff42), - PRIV_READ_REG_3(PICOJAVA, 0xff43), - PRIV_READ_REG_4(PICOJAVA, 0xff44), - PRIV_READ_REG_5(PICOJAVA, 0xff45), - PRIV_READ_REG_6(PICOJAVA, 0xff46), - PRIV_READ_REG_7(PICOJAVA, 0xff47), - PRIV_READ_REG_8(PICOJAVA, 0xff48), - PRIV_READ_REG_9(PICOJAVA, 0xff49), - PRIV_READ_REG_10(PICOJAVA, 0xff4a), - PRIV_READ_REG_11(PICOJAVA, 0xff4b), - PRIV_READ_REG_12(PICOJAVA, 0xff4c), - PRIV_READ_REG_13(PICOJAVA, 0xff4d), - PRIV_READ_REG_14(PICOJAVA, 0xff4e), - PRIV_READ_REG_15(PICOJAVA, 0xff4f), - PRIV_READ_REG_16(PICOJAVA, 0xff50), - PRIV_READ_REG_17(PICOJAVA, 0xff51), - PRIV_READ_REG_18(PICOJAVA, 0xff52), - PRIV_READ_REG_19(PICOJAVA, 0xff53), - PRIV_READ_REG_20(PICOJAVA, 0xff54), - PRIV_READ_REG_21(PICOJAVA, 0xff55), - PRIV_READ_REG_22(PICOJAVA, 0xff56), - PRIV_READ_REG_23(PICOJAVA, 0xff57), - PRIV_READ_REG_24(PICOJAVA, 0xff58), - PRIV_READ_REG_25(PICOJAVA, 0xff59), - PRIV_READ_REG_26(PICOJAVA, 0xff5a), - PRIV_READ_REG_27(PICOJAVA, 0xff5b), - PRIV_READ_REG_28(PICOJAVA, 0xff5c), - PRIV_READ_REG_29(PICOJAVA, 0xff5d), - PRIV_READ_REG_30(PICOJAVA, 0xff5e), - PRIV_READ_REG_31(PICOJAVA, 0xff5f), - PRIV_WRITE_REG_0(PICOJAVA, 0xff60), - PRIV_WRITE_REG_1(PICOJAVA, 0xff61), - PRIV_WRITE_REG_2(PICOJAVA, 0xff62), - PRIV_WRITE_REG_3(PICOJAVA, 0xff63), - PRIV_WRITE_REG_4(PICOJAVA, 0xff64), - PRIV_WRITE_REG_5(PICOJAVA, 0xff65), - PRIV_WRITE_REG_6(PICOJAVA, 0xff66), - PRIV_WRITE_REG_7(PICOJAVA, 0xff67), - PRIV_WRITE_REG_8(PICOJAVA, 0xff68), - PRIV_WRITE_REG_9(PICOJAVA, 0xff69), - PRIV_WRITE_REG_10(PICOJAVA, 0xff6a), - PRIV_WRITE_REG_11(PICOJAVA, 0xff6b), - PRIV_WRITE_REG_12(PICOJAVA, 0xff6c), - PRIV_WRITE_REG_13(PICOJAVA, 0xff6d), - PRIV_WRITE_REG_14(PICOJAVA, 0xff6e), - PRIV_WRITE_REG_15(PICOJAVA, 0xff6f), - PRIV_WRITE_REG_16(PICOJAVA, 0xff70), - PRIV_WRITE_REG_17(PICOJAVA, 0xff71), - PRIV_WRITE_REG_18(PICOJAVA, 0xff72), - PRIV_WRITE_REG_19(PICOJAVA, 0xff73), - PRIV_WRITE_REG_20(PICOJAVA, 0xff74), - PRIV_WRITE_REG_21(PICOJAVA, 0xff75), - PRIV_WRITE_REG_22(PICOJAVA, 0xff76), - PRIV_WRITE_REG_23(PICOJAVA, 0xff77), - PRIV_WRITE_REG_24(PICOJAVA, 0xff78), - PRIV_WRITE_REG_25(PICOJAVA, 0xff79), - PRIV_WRITE_REG_26(PICOJAVA, 0xff7a), - PRIV_WRITE_REG_27(PICOJAVA, 0xff7b), - PRIV_WRITE_REG_28(PICOJAVA, 0xff7c), - PRIV_WRITE_REG_29(PICOJAVA, 0xff7d), - PRIV_WRITE_REG_30(PICOJAVA, 0xff7e), - PRIV_WRITE_REG_31(PICOJAVA, 0xff7f); - - Opcode(int opcode) { - this(STANDARD, opcode, NO_OPERANDS); - } - - Opcode(int opcode, Instruction.Kind kind) { - this(STANDARD, opcode, kind); - } - - Opcode(Set set, int opcode) { - this(set, opcode, (set == STANDARD ? NO_OPERANDS : WIDE_NO_OPERANDS)); - } - - Opcode(Set set, int opcode, Instruction.Kind kind) { - this.set = set; - this.opcode = opcode; - this.kind = kind; - } - - public final Set set; - public final int opcode; - public final Instruction.Kind kind; - - /** Get the Opcode for a simple standard 1-byte opcode. */ - public static Opcode get(int opcode) { - return stdOpcodes[opcode]; - } - - /** Get the Opcode for 1- or 2-byte opcode. */ - public static Opcode get(int opcodePrefix, int opcode) { - Opcode[] block = getOpcodeBlock(opcodePrefix); - return (block == null ? null : block[opcode]); - } - - private static Opcode[] getOpcodeBlock(int opcodePrefix) { - switch (opcodePrefix) { - case 0: - return stdOpcodes; - case WIDE: - return wideOpcodes; - case NONPRIV: - return nonPrivOpcodes; - case PRIV: - return privOpcodes; - default: - return null; - } - - } - - private static final Opcode[] stdOpcodes = new Opcode[256]; - private static final Opcode[] wideOpcodes = new Opcode[256]; - private static final Opcode[] nonPrivOpcodes = new Opcode[256]; - private static final Opcode[] privOpcodes = new Opcode[256]; - static { - for (Opcode o: values()) - getOpcodeBlock(o.opcode >> 8)[o.opcode & 0xff] = o; - } - - /** The byte prefix for the wide instructions. */ - public static final int WIDE = 0xc4; - /** The byte prefix for the PicoJava nonpriv instructions. */ - public static final int NONPRIV = 0xfe; - /** The byte prefix for the PicoJava priv instructions. */ - public static final int PRIV = 0xff; - - public enum Set { - /** Standard opcodes. */ - STANDARD, - /** Legacy support for PicoJava opcodes. */ - PICOJAVA } -}
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/classfile/ReferenceFinder.java Thu May 28 16:13:55 2015 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,240 +0,0 @@ -/* - * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package com.sun.tools.classfile; - -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Objects; -import java.util.Set; -import com.sun.tools.classfile.Instruction.TypeKind; -import static com.sun.tools.classfile.ConstantPool.*; - -/** - * A utility class to find where in a ClassFile references - * a {@link CONSTANT_Methodref_info method}, - * a {@link CONSTANT_InterfaceMethodref_info interface method, - * or a {@link CONSTANT_Fieldref_info field}. - */ -public final class ReferenceFinder { - /** - * Filter for ReferenceFinder of what constant pool entries for reference lookup. - */ - public interface Filter { - /** - * Decides if the given CPRefInfo entry should be accepted or filtered. - * - * @param cpool ConstantPool of the ClassFile being parsed - * @param cpref constant pool entry representing a reference to - * a fields method, and interface method. - * @return {@code true} if accepted; otherwise {@code false} - */ - boolean accept(ConstantPool cpool, CPRefInfo cpref); - } - - /** - * Visitor of individual method of a ClassFile that references the - * accepted field, method, or interface method references. - */ - public interface Visitor { - /** - * Invoked for a method containing one or more accepted CPRefInfo entries - * - * @param cf ClassFile - * @param method Method that does the references the accepted references - * @param refs Accepted constant pool method/field reference - */ - void visit(ClassFile cf, Method method, List<CPRefInfo> refConstantPool); - } - - private final Filter filter; - private final Visitor visitor; - - /** - * Constructor. - */ - public ReferenceFinder(Filter filter, Visitor visitor) { - this.filter = Objects.requireNonNull(filter); - this.visitor = Objects.requireNonNull(visitor); - } - - /** - * Parses a given ClassFile and invoke the visitor if there is any reference - * to the constant pool entries referencing field, method, or - * interface method that are accepted. This method will return - * {@code true} if there is one or more accepted constant pool entries - * to lookup; otherwise, it will return {@code false}. - * - * @param cf ClassFile - * @return {@code true} if the given class file is processed to lookup - * references - * @throws ConstantPoolException if an error of the constant pool - */ - public boolean parse(ClassFile cf) throws ConstantPoolException { - List<Integer> cprefs = new ArrayList<>(); - int index = 1; - for (ConstantPool.CPInfo cpInfo : cf.constant_pool.entries()) { - if (cpInfo.accept(cpVisitor, cf.constant_pool)) { - cprefs.add(index); - } - index += cpInfo.size(); - } - - if (cprefs.isEmpty()) { - return false; - } - - for (Method m : cf.methods) { - Set<Integer> ids = new HashSet<>(); - Code_attribute c_attr = (Code_attribute) m.attributes.get(Attribute.Code); - if (c_attr != null) { - for (Instruction instr : c_attr.getInstructions()) { - int idx = instr.accept(codeVisitor, cprefs); - if (idx > 0) { - ids.add(idx); - } - } - } - if (ids.size() > 0) { - List<CPRefInfo> refInfos = new ArrayList<>(ids.size()); - for (int id : ids) { - refInfos.add(CPRefInfo.class.cast(cf.constant_pool.get(id))); - } - visitor.visit(cf, m, refInfos); - } - } - return true; - } - - private ConstantPool.Visitor<Boolean,ConstantPool> cpVisitor = - new ConstantPool.Visitor<Boolean,ConstantPool>() - { - public Boolean visitClass(CONSTANT_Class_info info, ConstantPool cpool) { - return false; - } - - public Boolean visitInterfaceMethodref(CONSTANT_InterfaceMethodref_info info, ConstantPool cpool) { - return filter.accept(cpool, info); - } - - public Boolean visitMethodref(CONSTANT_Methodref_info info, ConstantPool cpool) { - return filter.accept(cpool, info); - } - - public Boolean visitFieldref(CONSTANT_Fieldref_info info, ConstantPool cpool) { - return filter.accept(cpool, info); - } - - public Boolean visitDouble(CONSTANT_Double_info info, ConstantPool cpool) { - return false; - } - - public Boolean visitFloat(CONSTANT_Float_info info, ConstantPool cpool) { - return false; - } - - public Boolean visitInteger(CONSTANT_Integer_info info, ConstantPool cpool) { - return false; - } - - public Boolean visitInvokeDynamic(CONSTANT_InvokeDynamic_info info, ConstantPool cpool) { - return false; - } - - public Boolean visitLong(CONSTANT_Long_info info, ConstantPool cpool) { - return false; - } - - public Boolean visitNameAndType(CONSTANT_NameAndType_info info, ConstantPool cpool) { - return false; - } - - public Boolean visitMethodHandle(CONSTANT_MethodHandle_info info, ConstantPool cpool) { - return false; - } - - public Boolean visitMethodType(CONSTANT_MethodType_info info, ConstantPool cpool) { - return false; - } - - public Boolean visitString(CONSTANT_String_info info, ConstantPool cpool) { - return false; - } - - public Boolean visitUtf8(CONSTANT_Utf8_info info, ConstantPool cpool) { - return false; - } - }; - - private Instruction.KindVisitor<Integer, List<Integer>> codeVisitor = - new Instruction.KindVisitor<Integer, List<Integer>>() - { - public Integer visitNoOperands(Instruction instr, List<Integer> p) { - return 0; - } - - public Integer visitArrayType(Instruction instr, TypeKind kind, List<Integer> p) { - return 0; - } - - public Integer visitBranch(Instruction instr, int offset, List<Integer> p) { - return 0; - } - - public Integer visitConstantPoolRef(Instruction instr, int index, List<Integer> p) { - return p.contains(index) ? index : 0; - } - - public Integer visitConstantPoolRefAndValue(Instruction instr, int index, int value, List<Integer> p) { - return p.contains(index) ? index : 0; - } - - public Integer visitLocal(Instruction instr, int index, List<Integer> p) { - return 0; - } - - public Integer visitLocalAndValue(Instruction instr, int index, int value, List<Integer> p) { - return 0; - } - - public Integer visitLookupSwitch(Instruction instr, int default_, int npairs, int[] matches, int[] offsets, List<Integer> p) { - return 0; - } - - public Integer visitTableSwitch(Instruction instr, int default_, int low, int high, int[] offsets, List<Integer> p) { - return 0; - } - - public Integer visitValue(Instruction instr, int value, List<Integer> p) { - return 0; - } - - public Integer visitUnknown(Instruction instr, List<Integer> p) { - return 0; - } - }; -} -
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/classfile/RuntimeAnnotations_attribute.java Thu May 28 16:13:55 2015 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,61 +0,0 @@ -/* - * Copyright (c) 2007, 2008, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package com.sun.tools.classfile; - -import java.io.IOException; - -/** - * See JVMS, section 4.8.16 and 4.8.17. - * - * <p><b>This is NOT part of any supported API. - * If you write code that depends on this, you do so at your own risk. - * This code and its internal interfaces are subject to change or - * deletion without notice.</b> - */ -public abstract class RuntimeAnnotations_attribute extends Attribute { - protected RuntimeAnnotations_attribute(ClassReader cr, int name_index, int length) - throws IOException, Annotation.InvalidAnnotation { - super(name_index, length); - int num_annotations = cr.readUnsignedShort(); - annotations = new Annotation[num_annotations]; - for (int i = 0; i < annotations.length; i++) - annotations[i] = new Annotation(cr); - } - - protected RuntimeAnnotations_attribute(int name_index, Annotation[] annotations) { - super(name_index, length(annotations)); - this.annotations = annotations; - } - - private static int length(Annotation[] annos) { - int n = 2; - for (Annotation anno: annos) - n += anno.length(); - return n; - } - - public final Annotation[] annotations; -}
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/classfile/RuntimeInvisibleAnnotations_attribute.java Thu May 28 16:13:55 2015 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,56 +0,0 @@ -/* - * Copyright (c) 2007, 2008, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package com.sun.tools.classfile; - -import java.io.IOException; - -/** - * See JVMS, section 4.8.17. - * - * <p><b>This is NOT part of any supported API. - * If you write code that depends on this, you do so at your own risk. - * This code and its internal interfaces are subject to change or - * deletion without notice.</b> - */ -public class RuntimeInvisibleAnnotations_attribute extends RuntimeAnnotations_attribute { - RuntimeInvisibleAnnotations_attribute(ClassReader cr, int name_index, int length) - throws IOException, AttributeException { - super(cr, name_index, length); - } - - public RuntimeInvisibleAnnotations_attribute(ConstantPool cp, Annotation[] annotations) - throws ConstantPoolException { - this(cp.getUTF8Index(Attribute.RuntimeInvisibleAnnotations), annotations); - } - - public RuntimeInvisibleAnnotations_attribute(int name_index, Annotation[] annotations) { - super(name_index, annotations); - } - - public <R, P> R accept(Visitor<R, P> visitor, P p) { - return visitor.visitRuntimeInvisibleAnnotations(this, p); - } -}
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/classfile/RuntimeInvisibleParameterAnnotations_attribute.java Thu May 28 16:13:55 2015 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,56 +0,0 @@ -/* - * Copyright (c) 2007, 2008, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package com.sun.tools.classfile; - -import java.io.IOException; - -/** - * See JVMS, section 4.8.18. - * - * <p><b>This is NOT part of any supported API. - * If you write code that depends on this, you do so at your own risk. - * This code and its internal interfaces are subject to change or - * deletion without notice.</b> - */ -public class RuntimeInvisibleParameterAnnotations_attribute extends RuntimeParameterAnnotations_attribute { - RuntimeInvisibleParameterAnnotations_attribute(ClassReader cr, int name_index, int length) - throws IOException, Annotation.InvalidAnnotation { - super(cr, name_index, length); - } - - public RuntimeInvisibleParameterAnnotations_attribute(ConstantPool cp, Annotation[][] parameter_annotations) - throws ConstantPoolException { - this(cp.getUTF8Index(Attribute.RuntimeInvisibleParameterAnnotations), parameter_annotations); - } - - public RuntimeInvisibleParameterAnnotations_attribute(int name_index, Annotation[][] parameter_annotations) { - super(name_index, parameter_annotations); - } - - public <R, P> R accept(Visitor<R, P> visitor, P p) { - return visitor.visitRuntimeInvisibleParameterAnnotations(this, p); - } -}
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/classfile/RuntimeInvisibleTypeAnnotations_attribute.java Thu May 28 16:13:55 2015 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,56 +0,0 @@ -/* - * Copyright (c) 2007, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package com.sun.tools.classfile; - -import java.io.IOException; - -/** - * See JSR 308 specification, Section 3. - * - * <p><b>This is NOT part of any supported API. - * If you write code that depends on this, you do so at your own risk. - * This code and its internal interfaces are subject to change or - * deletion without notice.</b> - */ -public class RuntimeInvisibleTypeAnnotations_attribute extends RuntimeTypeAnnotations_attribute { - RuntimeInvisibleTypeAnnotations_attribute(ClassReader cr, int name_index, int length) - throws IOException, Annotation.InvalidAnnotation { - super(cr, name_index, length); - } - - public RuntimeInvisibleTypeAnnotations_attribute(ConstantPool cp, TypeAnnotation[] annotations) - throws ConstantPoolException { - this(cp.getUTF8Index(Attribute.RuntimeInvisibleTypeAnnotations), annotations); - } - - public RuntimeInvisibleTypeAnnotations_attribute(int name_index, TypeAnnotation[] annotations) { - super(name_index, annotations); - } - - public <R, P> R accept(Visitor<R, P> visitor, P p) { - return visitor.visitRuntimeInvisibleTypeAnnotations(this, p); - } -}
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/classfile/RuntimeParameterAnnotations_attribute.java Thu May 28 16:13:55 2015 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,70 +0,0 @@ -/* - * Copyright (c) 2007, 2008, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package com.sun.tools.classfile; - -import java.io.IOException; - -/** - * See JVMS, section 4.8.18 and 4.8.19. - * - * <p><b>This is NOT part of any supported API. - * If you write code that depends on this, you do so at your own risk. - * This code and its internal interfaces are subject to change or - * deletion without notice.</b> - */ -public abstract class RuntimeParameterAnnotations_attribute extends Attribute { - RuntimeParameterAnnotations_attribute(ClassReader cr, int name_index, int length) - throws IOException, Annotation.InvalidAnnotation { - super(name_index, length); - int num_parameters = cr.readUnsignedByte(); - parameter_annotations = new Annotation[num_parameters][]; - for (int p = 0; p < parameter_annotations.length; p++) { - int num_annotations = cr.readUnsignedShort(); - Annotation[] annotations = new Annotation[num_annotations]; - for (int i = 0; i < num_annotations; i++) - annotations[i] = new Annotation(cr); - parameter_annotations[p] = annotations; - } - } - - protected RuntimeParameterAnnotations_attribute(int name_index, Annotation[][] parameter_annotations) { - super(name_index, length(parameter_annotations)); - this.parameter_annotations = parameter_annotations; - } - - private static int length(Annotation[][] anno_arrays) { - int n = 1; - for (Annotation[] anno_array: anno_arrays) { - n += 2; - for (Annotation anno: anno_array) - n += anno.length(); - } - return n; - } - - public final Annotation[][] parameter_annotations; -} -
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/classfile/RuntimeTypeAnnotations_attribute.java Thu May 28 16:13:55 2015 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,61 +0,0 @@ -/* - * Copyright (c) 2007, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package com.sun.tools.classfile; - -import java.io.IOException; - -/** - * See JSR 308 specification, Section 3. - * - * <p><b>This is NOT part of any supported API. - * If you write code that depends on this, you do so at your own risk. - * This code and its internal interfaces are subject to change or - * deletion without notice.</b> - */ -public abstract class RuntimeTypeAnnotations_attribute extends Attribute { - protected RuntimeTypeAnnotations_attribute(ClassReader cr, int name_index, int length) - throws IOException, Annotation.InvalidAnnotation { - super(name_index, length); - int num_annotations = cr.readUnsignedShort(); - annotations = new TypeAnnotation[num_annotations]; - for (int i = 0; i < annotations.length; i++) - annotations[i] = new TypeAnnotation(cr); - } - - protected RuntimeTypeAnnotations_attribute(int name_index, TypeAnnotation[] annotations) { - super(name_index, length(annotations)); - this.annotations = annotations; - } - - private static int length(TypeAnnotation[] annos) { - int n = 2; - for (TypeAnnotation anno: annos) - n += anno.length(); - return n; - } - - public final TypeAnnotation[] annotations; -}
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/classfile/RuntimeVisibleAnnotations_attribute.java Thu May 28 16:13:55 2015 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,56 +0,0 @@ -/* - * Copyright (c) 2007, 2008, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package com.sun.tools.classfile; - -import java.io.IOException; - -/** - * See JVMS, section 4.8.16. - * - * <p><b>This is NOT part of any supported API. - * If you write code that depends on this, you do so at your own risk. - * This code and its internal interfaces are subject to change or - * deletion without notice.</b> - */ -public class RuntimeVisibleAnnotations_attribute extends RuntimeAnnotations_attribute { - RuntimeVisibleAnnotations_attribute(ClassReader cr, int name_index, int length) - throws IOException, Annotation.InvalidAnnotation { - super(cr, name_index, length); - } - - public RuntimeVisibleAnnotations_attribute(ConstantPool cp, Annotation[] annotations) - throws ConstantPoolException { - this(cp.getUTF8Index(Attribute.RuntimeVisibleAnnotations), annotations); - } - - public RuntimeVisibleAnnotations_attribute(int name_index, Annotation[] annotations) { - super(name_index, annotations); - } - - public <R, P> R accept(Visitor<R, P> visitor, P p) { - return visitor.visitRuntimeVisibleAnnotations(this, p); - } -}
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/classfile/RuntimeVisibleParameterAnnotations_attribute.java Thu May 28 16:13:55 2015 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,56 +0,0 @@ -/* - * Copyright (c) 2007, 2008, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package com.sun.tools.classfile; - -import java.io.IOException; - -/** - * See JVMS, section 4.8.18. - * - * <p><b>This is NOT part of any supported API. - * If you write code that depends on this, you do so at your own risk. - * This code and its internal interfaces are subject to change or - * deletion without notice.</b> - */ -public class RuntimeVisibleParameterAnnotations_attribute extends RuntimeParameterAnnotations_attribute { - RuntimeVisibleParameterAnnotations_attribute(ClassReader cr, int name_index, int length) - throws IOException, Annotation.InvalidAnnotation { - super(cr, name_index, length); - } - - public RuntimeVisibleParameterAnnotations_attribute(ConstantPool cp, Annotation[][] parameter_annotations) - throws ConstantPoolException { - this(cp.getUTF8Index(Attribute.RuntimeVisibleParameterAnnotations), parameter_annotations); - } - - public RuntimeVisibleParameterAnnotations_attribute(int name_index, Annotation[][] parameter_annotations) { - super(name_index, parameter_annotations); - } - - public <R, P> R accept(Visitor<R, P> visitor, P p) { - return visitor.visitRuntimeVisibleParameterAnnotations(this, p); - } -}
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/classfile/RuntimeVisibleTypeAnnotations_attribute.java Thu May 28 16:13:55 2015 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,56 +0,0 @@ -/* - * Copyright (c) 2007, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package com.sun.tools.classfile; - -import java.io.IOException; - -/** - * See JSR 308 specification, Section 3. - * - * <p><b>This is NOT part of any supported API. - * If you write code that depends on this, you do so at your own risk. - * This code and its internal interfaces are subject to change or - * deletion without notice.</b> - */ -public class RuntimeVisibleTypeAnnotations_attribute extends RuntimeTypeAnnotations_attribute { - RuntimeVisibleTypeAnnotations_attribute(ClassReader cr, int name_index, int length) - throws IOException, Annotation.InvalidAnnotation { - super(cr, name_index, length); - } - - public RuntimeVisibleTypeAnnotations_attribute(ConstantPool cp, TypeAnnotation[] annotations) - throws ConstantPoolException { - this(cp.getUTF8Index(Attribute.RuntimeVisibleTypeAnnotations), annotations); - } - - public RuntimeVisibleTypeAnnotations_attribute(int name_index, TypeAnnotation[] annotations) { - super(name_index, annotations); - } - - public <R, P> R accept(Visitor<R, P> visitor, P p) { - return visitor.visitRuntimeVisibleTypeAnnotations(this, p); - } -}
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/classfile/Signature.java Thu May 28 16:13:55 2015 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,272 +0,0 @@ -/* - * Copyright (c) 2007, 2008, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package com.sun.tools.classfile; - -import java.util.ArrayList; -import java.util.List; -import com.sun.tools.classfile.Type.*; - -/** - * See JVMS 4.4.4. - * - * <p><b>This is NOT part of any supported API. - * If you write code that depends on this, you do so at your own risk. - * This code and its internal interfaces are subject to change or - * deletion without notice.</b> - */ -public class Signature extends Descriptor { - - public Signature(int index) { - super(index); - } - - public Type getType(ConstantPool constant_pool) throws ConstantPoolException { - if (type == null) - type = parse(getValue(constant_pool)); - return type; - } - - @Override - public int getParameterCount(ConstantPool constant_pool) throws ConstantPoolException { - MethodType m = (MethodType) getType(constant_pool); - return m.paramTypes.size(); - } - - @Override - public String getParameterTypes(ConstantPool constant_pool) throws ConstantPoolException { - MethodType m = (MethodType) getType(constant_pool); - StringBuilder sb = new StringBuilder(); - sb.append("("); - String sep = ""; - for (Type paramType: m.paramTypes) { - sb.append(sep); - sb.append(paramType); - sep = ", "; - } - sb.append(")"); - return sb.toString(); - } - - @Override - public String getReturnType(ConstantPool constant_pool) throws ConstantPoolException { - MethodType m = (MethodType) getType(constant_pool); - return m.returnType.toString(); - } - - @Override - public String getFieldType(ConstantPool constant_pool) throws ConstantPoolException { - return getType(constant_pool).toString(); - } - - private Type parse(String sig) { - this.sig = sig; - sigp = 0; - - List<TypeParamType> typeParamTypes = null; - if (sig.charAt(sigp) == '<') - typeParamTypes = parseTypeParamTypes(); - - if (sig.charAt(sigp) == '(') { - List<Type> paramTypes = parseTypeSignatures(')'); - Type returnType = parseTypeSignature(); - List<Type> throwsTypes = null; - while (sigp < sig.length() && sig.charAt(sigp) == '^') { - sigp++; - if (throwsTypes == null) - throwsTypes = new ArrayList<>(); - throwsTypes.add(parseTypeSignature()); - } - return new MethodType(typeParamTypes, paramTypes, returnType, throwsTypes); - } else { - Type t = parseTypeSignature(); - if (typeParamTypes == null && sigp == sig.length()) - return t; - Type superclass = t; - List<Type> superinterfaces = null; - while (sigp < sig.length()) { - if (superinterfaces == null) - superinterfaces = new ArrayList<>(); - superinterfaces.add(parseTypeSignature()); - } - return new ClassSigType(typeParamTypes, superclass, superinterfaces); - - } - } - - private Type parseTypeSignature() { - switch (sig.charAt(sigp)) { - case 'B': - sigp++; - return new SimpleType("byte"); - - case 'C': - sigp++; - return new SimpleType("char"); - - case 'D': - sigp++; - return new SimpleType("double"); - - case 'F': - sigp++; - return new SimpleType("float"); - - case 'I': - sigp++; - return new SimpleType("int"); - - case 'J': - sigp++; - return new SimpleType("long"); - - case 'L': - return parseClassTypeSignature(); - - case 'S': - sigp++; - return new SimpleType("short"); - - case 'T': - return parseTypeVariableSignature(); - - case 'V': - sigp++; - return new SimpleType("void"); - - case 'Z': - sigp++; - return new SimpleType("boolean"); - - case '[': - sigp++; - return new ArrayType(parseTypeSignature()); - - case '*': - sigp++; - return new WildcardType(); - - case '+': - sigp++; - return new WildcardType(WildcardType.Kind.EXTENDS, parseTypeSignature()); - - case '-': - sigp++; - return new WildcardType(WildcardType.Kind.SUPER, parseTypeSignature()); - - default: - throw new IllegalStateException(debugInfo()); - } - } - - private List<Type> parseTypeSignatures(char term) { - sigp++; - List<Type> types = new ArrayList<>(); - while (sig.charAt(sigp) != term) - types.add(parseTypeSignature()); - sigp++; - return types; - } - - private Type parseClassTypeSignature() { - assert sig.charAt(sigp) == 'L'; - sigp++; - return parseClassTypeSignatureRest(); - } - - private Type parseClassTypeSignatureRest() { - StringBuilder sb = new StringBuilder(); - List<Type> argTypes = null; - ClassType t = null; - char sigch ; - - do { - switch (sigch = sig.charAt(sigp)) { - case '<': - argTypes = parseTypeSignatures('>'); - break; - - case '.': - case ';': - sigp++; - t = new ClassType(t, sb.toString(), argTypes); - sb.setLength(0); - argTypes = null; - break; - - default: - sigp++; - sb.append(sigch); - break; - } - } while (sigch != ';'); - - return t; - } - - private List<TypeParamType> parseTypeParamTypes() { - assert sig.charAt(sigp) == '<'; - sigp++; - List<TypeParamType> types = new ArrayList<>(); - while (sig.charAt(sigp) != '>') - types.add(parseTypeParamType()); - sigp++; - return types; - } - - private TypeParamType parseTypeParamType() { - int sep = sig.indexOf(":", sigp); - String name = sig.substring(sigp, sep); - Type classBound = null; - List<Type> interfaceBounds = null; - sigp = sep + 1; - if (sig.charAt(sigp) != ':') - classBound = parseTypeSignature(); - while (sig.charAt(sigp) == ':') { - sigp++; - if (interfaceBounds == null) - interfaceBounds = new ArrayList<>(); - interfaceBounds.add(parseTypeSignature()); - } - return new TypeParamType(name, classBound, interfaceBounds); - } - - private Type parseTypeVariableSignature() { - sigp++; - int sep = sig.indexOf(';', sigp); - Type t = new SimpleType(sig.substring(sigp, sep)); - sigp = sep + 1; - return t; - } - - private String debugInfo() { - return sig.substring(0, sigp) + "!" + sig.charAt(sigp) + "!" + sig.substring(sigp+1); - } - - private String sig; - private int sigp; - - private Type type; -}
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/classfile/Signature_attribute.java Thu May 28 16:13:55 2015 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,67 +0,0 @@ -/* - * Copyright (c) 2007, 2008, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package com.sun.tools.classfile; - -import java.io.IOException; - -/** - * See JVMS, section 4.8.9. - * - * <p><b>This is NOT part of any supported API. - * If you write code that depends on this, you do so at your own risk. - * This code and its internal interfaces are subject to change or - * deletion without notice.</b> - */ -public class Signature_attribute extends Attribute { - Signature_attribute(ClassReader cr, int name_index, int length) throws IOException { - super(name_index, length); - signature_index = cr.readUnsignedShort(); - } - - public Signature_attribute(ConstantPool constant_pool, int signature_index) - throws ConstantPoolException { - this(constant_pool.getUTF8Index(Attribute.Signature), signature_index); - } - - public Signature_attribute(int name_index, int signature_index) { - super(name_index, 2); - this.signature_index = signature_index; - } - - public String getSignature(ConstantPool constant_pool) throws ConstantPoolException { - return constant_pool.getUTF8Value(signature_index); - } - - public Signature getParsedSignature() { - return new Signature(signature_index); - } - - public <R, D> R accept(Visitor<R, D> visitor, D data) { - return visitor.visitSignature(this, data); - } - - public final int signature_index; -}
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/classfile/SourceDebugExtension_attribute.java Thu May 28 16:13:55 2015 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,69 +0,0 @@ -/* - * Copyright (c) 2007, 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package com.sun.tools.classfile; - -import java.io.ByteArrayInputStream; -import java.io.DataInputStream; -import java.io.IOException; -import java.nio.charset.Charset; - -/** - * See JVMS, section 4.8.15. - * - * <p><b>This is NOT part of any supported API. - * If you write code that depends on this, you do so at your own risk. - * This code and its internal interfaces are subject to change or - * deletion without notice.</b> - */ -public class SourceDebugExtension_attribute extends Attribute { - private static final Charset UTF8 = Charset.forName("UTF-8"); - - SourceDebugExtension_attribute(ClassReader cr, int name_index, int length) throws IOException { - super(name_index, length); - debug_extension = new byte[attribute_length]; - cr.readFully(debug_extension); - } - - public SourceDebugExtension_attribute(ConstantPool constant_pool, byte[] debug_extension) - throws ConstantPoolException { - this(constant_pool.getUTF8Index(Attribute.SourceDebugExtension), debug_extension); - } - - public SourceDebugExtension_attribute(int name_index, byte[] debug_extension) { - super(name_index, debug_extension.length); - this.debug_extension = debug_extension; - } - - public String getValue() { - return new String(debug_extension, UTF8); - } - - public <R, D> R accept(Visitor<R, D> visitor, D data