From cc147bce6458afa2bbd71f586f82ed1605bbe4db Mon Sep 17 00:00:00 2001 From: liach Date: Mon, 24 Mar 2025 19:35:41 -0500 Subject: [PATCH 1/4] 8310310: Migrate CreateSymbols tool in make/langtools to Classfile API --- .../tools/symbolgenerator/CreateSymbols.java | 1348 +++++------------ .../platform/CanHandleClassFilesTest.java | 9 +- .../createsymbols/CreateSymbolsTest.java | 6 +- 3 files changed, 358 insertions(+), 1005 deletions(-) diff --git a/make/langtools/src/classes/build/tools/symbolgenerator/CreateSymbols.java b/make/langtools/src/classes/build/tools/symbolgenerator/CreateSymbols.java index 6faefecd4247a..03553c24034bb 100644 --- a/make/langtools/src/classes/build/tools/symbolgenerator/CreateSymbols.java +++ b/make/langtools/src/classes/build/tools/symbolgenerator/CreateSymbols.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2006, 2025, 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 @@ -45,6 +45,18 @@ import java.io.OutputStream; import java.io.StringWriter; import java.io.Writer; +import java.lang.classfile.*; +import java.lang.classfile.attribute.*; +import java.lang.classfile.constantpool.ClassEntry; +import java.lang.classfile.constantpool.ConstantPoolBuilder; +import java.lang.classfile.constantpool.ConstantValueEntry; +import java.lang.classfile.constantpool.IntegerEntry; +import java.lang.classfile.constantpool.Utf8Entry; +import java.lang.constant.ClassDesc; +import java.lang.constant.MethodTypeDesc; +import java.lang.constant.ModuleDesc; +import java.lang.constant.PackageDesc; +import java.lang.reflect.AccessFlag; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.FileVisitResult; @@ -88,63 +100,6 @@ import javax.tools.StandardLocation; import com.sun.source.util.JavacTask; -import com.sun.tools.classfile.AccessFlags; -import com.sun.tools.classfile.Annotation; -import com.sun.tools.classfile.Annotation.Annotation_element_value; -import com.sun.tools.classfile.Annotation.Array_element_value; -import com.sun.tools.classfile.Annotation.Class_element_value; -import com.sun.tools.classfile.Annotation.Enum_element_value; -import com.sun.tools.classfile.Annotation.Primitive_element_value; -import com.sun.tools.classfile.Annotation.element_value; -import com.sun.tools.classfile.Annotation.element_value_pair; -import com.sun.tools.classfile.AnnotationDefault_attribute; -import com.sun.tools.classfile.Attribute; -import com.sun.tools.classfile.Attributes; -import com.sun.tools.classfile.ClassFile; -import com.sun.tools.classfile.ClassWriter; -import com.sun.tools.classfile.ConstantPool; -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_Float_info; -import com.sun.tools.classfile.ConstantPool.CONSTANT_Integer_info; -import com.sun.tools.classfile.ConstantPool.CONSTANT_Long_info; -import com.sun.tools.classfile.ConstantPool.CONSTANT_Module_info; -import com.sun.tools.classfile.ConstantPool.CONSTANT_Package_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; -import com.sun.tools.classfile.ConstantPool.InvalidIndex; -import com.sun.tools.classfile.ConstantPoolException; -import com.sun.tools.classfile.ConstantValue_attribute; -import com.sun.tools.classfile.Deprecated_attribute; -import com.sun.tools.classfile.Descriptor; -import com.sun.tools.classfile.Exceptions_attribute; -import com.sun.tools.classfile.Field; -import com.sun.tools.classfile.InnerClasses_attribute; -import com.sun.tools.classfile.InnerClasses_attribute.Info; -import com.sun.tools.classfile.Method; -import com.sun.tools.classfile.ModulePackages_attribute; -import com.sun.tools.classfile.MethodParameters_attribute; -import com.sun.tools.classfile.ModuleMainClass_attribute; -import com.sun.tools.classfile.ModuleResolution_attribute; -import com.sun.tools.classfile.ModuleTarget_attribute; -import com.sun.tools.classfile.Module_attribute; -import com.sun.tools.classfile.Module_attribute.ExportsEntry; -import com.sun.tools.classfile.Module_attribute.OpensEntry; -import com.sun.tools.classfile.Module_attribute.ProvidesEntry; -import com.sun.tools.classfile.Module_attribute.RequiresEntry; -import com.sun.tools.classfile.NestHost_attribute; -import com.sun.tools.classfile.NestMembers_attribute; -import com.sun.tools.classfile.PermittedSubclasses_attribute; -import com.sun.tools.classfile.Record_attribute; -import com.sun.tools.classfile.Record_attribute.ComponentInfo; -import com.sun.tools.classfile.RuntimeAnnotations_attribute; -import com.sun.tools.classfile.RuntimeInvisibleAnnotations_attribute; -import com.sun.tools.classfile.RuntimeInvisibleParameterAnnotations_attribute; -import com.sun.tools.classfile.RuntimeParameterAnnotations_attribute; -import com.sun.tools.classfile.RuntimeVisibleAnnotations_attribute; -import com.sun.tools.classfile.RuntimeVisibleParameterAnnotations_attribute; -import com.sun.tools.classfile.Signature_attribute; import com.sun.tools.javac.api.JavacTool; import com.sun.tools.javac.jvm.Target; import com.sun.tools.javac.util.Assert; @@ -154,6 +109,9 @@ import java.util.Optional; import java.util.function.Consumer; +import static java.lang.classfile.ClassFile.ACC_PROTECTED; +import static java.lang.classfile.ClassFile.ACC_PUBLIC; + /** * A tool for processing the .sym.txt files. * @@ -409,7 +367,7 @@ LoadDescriptions load(Path ctDescriptionWithExtraContent, Path ctDescriptionOpen reader.moveNext(); break; default: - throw new IllegalStateException("Unknown key: " + reader.lineKey); + throw new IllegalArgumentException("Unknown key: " + reader.lineKey); } } } @@ -432,7 +390,7 @@ LoadDescriptions load(Path ctDescriptionWithExtraContent, Path ctDescriptionOpen reader.moveNext(); break; default: - throw new IllegalStateException("Unknown key: " + reader.lineKey); + throw new IllegalArgumentException("Unknown key: " + reader.lineKey); } } } @@ -830,31 +788,12 @@ void writeModule(Map> directory2FileData, ModuleHeaderDescription header, char version, Function version2ModuleVersion) throws IOException { - List constantPool = new ArrayList<>(); - constantPool.add(null); - int currentClass = addClass(constantPool, "module-info"); - int superclass = 0; - int[] interfaces = new int[0]; - AccessFlags flags = new AccessFlags(header.flags); - Map attributesMap = new HashMap<>(); - String versionString = Character.toString(version); - addAttributes(moduleDescription, header, constantPool, attributesMap, - version2ModuleVersion.apply(version)); - Attributes attributes = new Attributes(attributesMap); - CPInfo[] cpData = constantPool.toArray(new CPInfo[constantPool.size()]); - ConstantPool cp = new ConstantPool(cpData); - ClassFile classFile = new ClassFile(0xCAFEBABE, - Target.DEFAULT.minorVersion, - Target.DEFAULT.majorVersion, - cp, - flags, - currentClass, - superclass, - interfaces, - new Field[0], - new Method[0], - attributes); + var classFile = ClassFile.of().build(ClassDesc.of("module-info"), clb -> { + clb.withFlags(header.flags); + addAttributes(moduleDescription, header, clb, version2ModuleVersion.apply(version)); + }); + String versionString = Character.toString(version); doWrite(directory2FileData, versionString, moduleDescription.name, "module-info" + EXTENSION, classFile); } @@ -863,57 +802,26 @@ void writeClass(Map> directory2FileData, ClassHeaderDescription header, String module, String version) throws IOException { - List constantPool = new ArrayList<>(); - constantPool.add(null); - List methods = new ArrayList<>(); - for (MethodDescription methDesc : classDescription.methods) { - if (disjoint(methDesc.versions, version)) - continue; - Descriptor descriptor = new Descriptor(addString(constantPool, methDesc.descriptor)); - //TODO: LinkedHashMap to avoid param annotations vs. Signature problem in javac's ClassReader: - Map attributesMap = new LinkedHashMap<>(); - addAttributes(methDesc, constantPool, attributesMap); - Attributes attributes = new Attributes(attributesMap); - AccessFlags flags = new AccessFlags(methDesc.flags); - int nameString = addString(constantPool, methDesc.name); - methods.add(new Method(flags, nameString, descriptor, attributes)); - } - List fields = new ArrayList<>(); - for (FieldDescription fieldDesc : classDescription.fields) { - if (disjoint(fieldDesc.versions, version)) - continue; - Descriptor descriptor = new Descriptor(addString(constantPool, fieldDesc.descriptor)); - Map attributesMap = new HashMap<>(); - addAttributes(fieldDesc, constantPool, attributesMap); - Attributes attributes = new Attributes(attributesMap); - AccessFlags flags = new AccessFlags(fieldDesc.flags); - int nameString = addString(constantPool, fieldDesc.name); - fields.add(new Field(flags, nameString, descriptor, attributes)); - } - int currentClass = addClass(constantPool, classDescription.name); - int superclass = header.extendsAttr != null ? addClass(constantPool, header.extendsAttr) : 0; - int[] interfaces = new int[header.implementsAttr.size()]; - int i = 0; - for (String intf : header.implementsAttr) { - interfaces[i++] = addClass(constantPool, intf); - } - AccessFlags flags = new AccessFlags(header.flags); - Map attributesMap = new HashMap<>(); - addAttributes(header, constantPool, attributesMap); - Attributes attributes = new Attributes(attributesMap); - ConstantPool cp = new ConstantPool(constantPool.toArray(new CPInfo[constantPool.size()])); - ClassFile classFile = new ClassFile(0xCAFEBABE, - Target.DEFAULT.minorVersion, - Target.DEFAULT.majorVersion, - cp, - flags, - currentClass, - superclass, - interfaces, - fields.toArray(new Field[0]), - methods.toArray(new Method[0]), - attributes); - + var classFile = ClassFile.of().build(ClassDesc.ofInternalName(classDescription.name), clb -> { + if (header.extendsAttr != null) + clb.withSuperclass(ClassDesc.ofInternalName(header.extendsAttr)); + clb.withInterfaceSymbols(header.implementsAttr.stream().map(ClassDesc::ofInternalName).collect(Collectors.toList())) + .withFlags(header.flags); + for (FieldDescription fieldDesc : classDescription.fields) { + if (disjoint(fieldDesc.versions, version)) + continue; + clb.withField(fieldDesc.name, ClassDesc.ofDescriptor(fieldDesc.descriptor), fb -> { + addAttributes(fieldDesc, fb); + fb.withFlags(fieldDesc.flags); + }); + } + for (MethodDescription methDesc : classDescription.methods) { + if (disjoint(methDesc.versions, version)) + continue; + clb.withMethod(methDesc.name, MethodTypeDesc.ofDescriptor(methDesc.descriptor), methDesc.flags, mb -> addAttributes(methDesc, mb)); + } + addAttributes(header, clb); + }); doWrite(directory2FileData, version, module, classDescription.name + EXTENSION, classFile); } @@ -921,19 +829,13 @@ private void doWrite(Map> directory2FileData, String version, String moduleName, String fileName, - ClassFile classFile) throws IOException { + byte[] classFile) throws IOException { int lastSlash = fileName.lastIndexOf('/'); String pack = lastSlash != (-1) ? fileName.substring(0, lastSlash + 1) : "/"; String directory = version + "/" + moduleName + "/" + pack; String fullFileName = version + "/" + moduleName + "/" + fileName; - try (ByteArrayOutputStream out = new ByteArrayOutputStream()) { - ClassWriter w = new ClassWriter(); - - w.write(classFile, out); - - openDirectory(directory2FileData, directory) - .add(new FileData(fullFileName, out.toByteArray())); - } + openDirectory(directory2FileData, directory) + .add(new FileData(fullFileName, classFile)); } private Set openDirectory(Map> directory2FileData, @@ -955,278 +857,149 @@ public FileData(String fileName, byte[] fileData) { private void addAttributes(ModuleDescription md, ModuleHeaderDescription header, - List cp, - Map attributes, + ClassBuilder builder, String moduleVersion) { - addGenericAttributes(header, cp, attributes); + addGenericAttributes(header, builder); if (header.moduleResolution != null) { - int attrIdx = addString(cp, Attribute.ModuleResolution); - final ModuleResolution_attribute resIdx = - new ModuleResolution_attribute(attrIdx, - header.moduleResolution); - attributes.put(Attribute.ModuleResolution, resIdx); + builder.with(ModuleResolutionAttribute.of(header.moduleResolution)); } if (header.moduleTarget != null) { - int attrIdx = addString(cp, Attribute.ModuleTarget); - int targetIdx = addString(cp, header.moduleTarget); - attributes.put(Attribute.ModuleTarget, - new ModuleTarget_attribute(attrIdx, targetIdx)); + builder.with(ModuleTargetAttribute.of(header.moduleTarget)); } if (header.moduleMainClass != null) { - int attrIdx = addString(cp, Attribute.ModuleMainClass); - int targetIdx = addClassName(cp, header.moduleMainClass); - attributes.put(Attribute.ModuleMainClass, - new ModuleMainClass_attribute(attrIdx, targetIdx)); - } - int versionIdx = addString(cp, moduleVersion); - int attrIdx = addString(cp, Attribute.Module); - attributes.put(Attribute.Module, - new Module_attribute(attrIdx, - addModuleName(cp, md.name), - 0, - versionIdx, - header.requires - .stream() - .map(r -> createRequiresEntry(cp, r)) - .collect(Collectors.toList()) - .toArray(new RequiresEntry[0]), - header.exports - .stream() - .map(e -> createExportsEntry(cp, e)) - .collect(Collectors.toList()) - .toArray(new ExportsEntry[0]), - header.opens - .stream() - .map(e -> createOpensEntry(cp, e)) - .collect(Collectors.toList()) - .toArray(new OpensEntry[0]), - header.uses - .stream() - .mapToInt(u -> addClassName(cp, u)) - .toArray(), - header.provides - .stream() - .map(p -> createProvidesEntry(cp, p)) - .collect(Collectors.toList()) - .toArray(new ProvidesEntry[0]))); - addInnerClassesAttribute(header, cp, attributes); - } - - private static RequiresEntry createRequiresEntry(List cp, - RequiresDescription r) { - final int idx = addModuleName(cp, r.moduleName); - return new RequiresEntry(idx, - r.flags, - r.version != null - ? addString(cp, r.version) - : 0); - } - - private static ExportsEntry createExportsEntry(List cp, - ExportsDescription export) { - int[] to; - if (export.isQualified()) { - to = export.to.stream() - .mapToInt(module -> addModuleName(cp, module)) - .toArray(); - } else { - to = new int[0]; + builder.with(ModuleMainClassAttribute.of(ClassDesc.ofInternalName(header.moduleMainClass))); } - return new ExportsEntry(addPackageName(cp, export.packageName()), 0, to); - } - - private static OpensEntry createOpensEntry(List cp, String e) { - return new OpensEntry(addPackageName(cp, e), 0, new int[0]); - } - - private static ProvidesEntry createProvidesEntry(List cp, - ModuleHeaderDescription.ProvidesDescription p) { - final int idx = addClassName(cp, p.interfaceName); - return new ProvidesEntry(idx, p.implNames - .stream() - .mapToInt(i -> addClassName(cp, i)) - .toArray()); + builder.with(ModuleAttribute.of(ModuleDesc.of(md.name), mb -> { + mb.moduleVersion(moduleVersion); + for (var req : header.requires) { + mb.requires(ModuleDesc.of(req.moduleName), req.flags, req.version); // nullable version + } + for (var exp : header.exports) { + if (exp.isQualified()) { + mb.exports(PackageDesc.ofInternalName(exp.packageName()), 0, exp.to.stream().map(ModuleDesc::of).toArray(ModuleDesc[]::new)); + } else { + mb.exports(PackageDesc.ofInternalName(exp.packageName()), 0); + } + } + for (var open : header.opens) { + mb.opens(PackageDesc.ofInternalName(open), 0); + } + for (var use : header.uses) { + mb.uses(ClassDesc.ofInternalName(use)); + } + for (var provide : header.provides) { + mb.provides(ClassDesc.ofInternalName(provide.interfaceName), + provide.implNames.stream().map(ClassDesc::ofInternalName).toArray(ClassDesc[]::new)); + } + })); + addInnerClassesAttribute(header, builder); } - private void addAttributes(ClassHeaderDescription header, - List constantPool, Map attributes) { - addGenericAttributes(header, constantPool, attributes); + private void addAttributes(ClassHeaderDescription header, ClassBuilder builder) { + addGenericAttributes(header, builder); if (header.nestHost != null) { - int attributeString = addString(constantPool, Attribute.NestHost); - int nestHost = addClass(constantPool, header.nestHost); - attributes.put(Attribute.NestHost, - new NestHost_attribute(attributeString, nestHost)); + builder.with(NestHostAttribute.of(ClassDesc.ofInternalName(header.nestHost))); } if (header.nestMembers != null && !header.nestMembers.isEmpty()) { - int attributeString = addString(constantPool, Attribute.NestMembers); - int[] nestMembers = new int[header.nestMembers.size()]; - int i = 0; - for (String intf : header.nestMembers) { - nestMembers[i++] = addClass(constantPool, intf); - } - attributes.put(Attribute.NestMembers, - new NestMembers_attribute(attributeString, nestMembers)); + builder.with(NestMembersAttribute.ofSymbols(header.nestMembers.stream().map(ClassDesc::ofInternalName).collect(Collectors.toList()))); } if (header.isRecord) { - assert header.recordComponents != null; - int attributeString = addString(constantPool, Attribute.Record); - ComponentInfo[] recordComponents = new ComponentInfo[header.recordComponents.size()]; - int i = 0; - for (RecordComponentDescription rcd : header.recordComponents) { - int name = addString(constantPool, rcd.name); - Descriptor desc = new Descriptor(addString(constantPool, rcd.descriptor)); - Map nestedAttrs = new HashMap<>(); - addGenericAttributes(rcd, constantPool, nestedAttrs); - Attributes attrs = new Attributes(nestedAttrs); - recordComponents[i++] = new ComponentInfo(name, desc, attrs); - } - attributes.put(Attribute.Record, - new Record_attribute(attributeString, recordComponents)); + builder.with(RecordAttribute.of(header.recordComponents.stream().map(desc -> { + List> attributes = new ArrayList<>(); + addGenericAttributes(desc, attributes::add, builder.constantPool()); + return RecordComponentInfo.of(desc.name, ClassDesc.ofDescriptor(desc.descriptor), attributes); + }).collect(Collectors.toList()))); } if (header.isSealed) { - int attributeString = addString(constantPool, Attribute.PermittedSubclasses); - int[] subclasses = new int[header.permittedSubclasses.size()]; - int i = 0; - for (String intf : header.permittedSubclasses) { - subclasses[i++] = addClass(constantPool, intf); - } - attributes.put(Attribute.PermittedSubclasses, - new PermittedSubclasses_attribute(attributeString, subclasses)); + builder.with(PermittedSubclassesAttribute.ofSymbols(header.permittedSubclasses.stream().map(ClassDesc::ofInternalName).collect(Collectors.toList()))); } - addInnerClassesAttribute(header, constantPool, attributes); + addInnerClassesAttribute(header, builder); } - private void addInnerClassesAttribute(HeaderDescription header, - List constantPool, Map attributes) { + private void addInnerClassesAttribute(HeaderDescription header, ClassBuilder builder) { if (header.innerClasses != null && !header.innerClasses.isEmpty()) { - Info[] innerClasses = new Info[header.innerClasses.size()]; - int i = 0; - for (InnerClassInfo info : header.innerClasses) { - innerClasses[i++] = - new Info(info.innerClass == null ? 0 : addClass(constantPool, info.innerClass), - info.outerClass == null ? 0 : addClass(constantPool, info.outerClass), - info.innerClassName == null ? 0 : addString(constantPool, info.innerClassName), - new AccessFlags(info.innerClassFlags)); - } - int attributeString = addString(constantPool, Attribute.InnerClasses); - attributes.put(Attribute.InnerClasses, - new InnerClasses_attribute(attributeString, innerClasses)); + builder.with(InnerClassesAttribute.of(header.innerClasses.stream() + .map(info -> java.lang.classfile.attribute.InnerClassInfo.of( + ClassDesc.ofInternalName(info.innerClass), + Optional.ofNullable(info.outerClass).map(ClassDesc::ofInternalName), + Optional.ofNullable(info.innerClassName), + info.innerClassFlags + )).collect(Collectors.toList()))); } } - private void addAttributes(MethodDescription desc, List constantPool, Map attributes) { - addGenericAttributes(desc, constantPool, attributes); + private void addAttributes(MethodDescription desc, MethodBuilder builder) { + addGenericAttributes(desc, builder); if (desc.thrownTypes != null) { - int[] exceptions = new int[desc.thrownTypes.size()]; - int i = 0; - for (String exc : desc.thrownTypes) { - exceptions[i++] = addClass(constantPool, exc); - } - int attributeString = addString(constantPool, Attribute.Exceptions); - attributes.put(Attribute.Exceptions, - new Exceptions_attribute(attributeString, exceptions)); + builder.with(ExceptionsAttribute.ofSymbols(desc.thrownTypes.stream() + .map(ClassDesc::ofInternalName).collect(Collectors.toList()))); } if (desc.annotationDefaultValue != null) { - int attributeString = addString(constantPool, Attribute.AnnotationDefault); - element_value attributeValue = createAttributeValue(constantPool, - desc.annotationDefaultValue); - attributes.put(Attribute.AnnotationDefault, - new AnnotationDefault_attribute(attributeString, attributeValue)); + builder.with(AnnotationDefaultAttribute.of(createAttributeValue(desc.annotationDefaultValue))); } if (desc.classParameterAnnotations != null && !desc.classParameterAnnotations.isEmpty()) { - int attributeString = - addString(constantPool, Attribute.RuntimeInvisibleParameterAnnotations); - Annotation[][] annotations = - createParameterAnnotations(constantPool, desc.classParameterAnnotations); - attributes.put(Attribute.RuntimeInvisibleParameterAnnotations, - new RuntimeInvisibleParameterAnnotations_attribute(attributeString, - annotations)); + builder.with(RuntimeInvisibleParameterAnnotationsAttribute.of(createParameterAnnotations(desc.classParameterAnnotations))); } if (desc.runtimeParameterAnnotations != null && !desc.runtimeParameterAnnotations.isEmpty()) { - int attributeString = - addString(constantPool, Attribute.RuntimeVisibleParameterAnnotations); - Annotation[][] annotations = - createParameterAnnotations(constantPool, desc.runtimeParameterAnnotations); - attributes.put(Attribute.RuntimeVisibleParameterAnnotations, - new RuntimeVisibleParameterAnnotations_attribute(attributeString, - annotations)); + builder.with(RuntimeVisibleParameterAnnotationsAttribute.of(createParameterAnnotations(desc.runtimeParameterAnnotations))); } if (desc.methodParameters != null && !desc.methodParameters.isEmpty()) { - int attributeString = - addString(constantPool, Attribute.MethodParameters); - MethodParameters_attribute.Entry[] entries = - desc.methodParameters - .stream() - .map(p -> new MethodParameters_attribute.Entry(p.name == null || p.name.isEmpty() ? 0 - : addString(constantPool, p.name), - p.flags)) - .toArray(s -> new MethodParameters_attribute.Entry[s]); - attributes.put(Attribute.MethodParameters, - new MethodParameters_attribute(attributeString, entries)); + builder.with(MethodParametersAttribute.of(desc.methodParameters.stream() + .map(mp -> MethodParameterInfo.ofParameter(Optional.ofNullable(mp.name), mp.flags)).collect(Collectors.toList()))); } } - private void addAttributes(FieldDescription desc, List constantPool, Map attributes) { - addGenericAttributes(desc, constantPool, attributes); + private void addAttributes(FieldDescription desc, FieldBuilder builder) { + addGenericAttributes(desc, builder); if (desc.constantValue != null) { - Pair constantPoolEntry = - addConstant(constantPool, desc.constantValue, false); - Assert.checkNonNull(constantPoolEntry); - int constantValueString = addString(constantPool, Attribute.ConstantValue); - attributes.put(Attribute.ConstantValue, - new ConstantValue_attribute(constantValueString, constantPoolEntry.fst)); + var cp = builder.constantPool(); + ConstantValueEntry entry = switch (desc.constantValue) { + case Boolean v -> cp.intEntry(v ? 1 : 0); + case Byte v -> cp.intEntry(v); + case Character v -> cp.intEntry(v); + case Short v -> cp.intEntry(v); + case Integer v -> cp.intEntry(v); + case Long v -> cp.longEntry(v); + case Float v -> cp.floatEntry(v); + case Double v -> cp.doubleEntry(v); + case String v -> cp.stringEntry(v); + default -> throw new IllegalArgumentException(desc.constantValue.getClass().toString()); + }; + builder.with(ConstantValueAttribute.of(entry)); } } - private void addGenericAttributes(FeatureDescription desc, List constantPool, Map attributes) { + @SuppressWarnings("unchecked") + private void addGenericAttributes(FeatureDescription desc, ClassFileBuilder builder) { + addGenericAttributes(desc, (Consumer>) builder, builder.constantPool()); + } + + private void addGenericAttributes(FeatureDescription desc, Consumer> sink, ConstantPoolBuilder cpb) { + @SuppressWarnings("unchecked") + var builder = (Consumer>) sink; if (desc.deprecated) { - int attributeString = addString(constantPool, Attribute.Deprecated); - attributes.put(Attribute.Deprecated, - new Deprecated_attribute(attributeString)); + builder.accept(DeprecatedAttribute.of()); } if (desc.signature != null) { - int attributeString = addString(constantPool, Attribute.Signature); - int signatureString = addString(constantPool, desc.signature); - attributes.put(Attribute.Signature, - new Signature_attribute(attributeString, signatureString)); + builder.accept(SignatureAttribute.of(cpb.utf8Entry(desc.signature))); } if (desc.classAnnotations != null && !desc.classAnnotations.isEmpty()) { - int attributeString = addString(constantPool, Attribute.RuntimeInvisibleAnnotations); - Annotation[] annotations = createAnnotations(constantPool, desc.classAnnotations); - attributes.put(Attribute.RuntimeInvisibleAnnotations, - new RuntimeInvisibleAnnotations_attribute(attributeString, annotations)); + builder.accept(RuntimeInvisibleAnnotationsAttribute.of(createAnnotations(desc.classAnnotations))); } if (desc.runtimeAnnotations != null && !desc.runtimeAnnotations.isEmpty()) { - int attributeString = addString(constantPool, Attribute.RuntimeVisibleAnnotations); - Annotation[] annotations = createAnnotations(constantPool, desc.runtimeAnnotations); - attributes.put(Attribute.RuntimeVisibleAnnotations, - new RuntimeVisibleAnnotations_attribute(attributeString, annotations)); + builder.accept(RuntimeVisibleAnnotationsAttribute.of(createAnnotations(desc.runtimeAnnotations))); } } - private Annotation[] createAnnotations(List constantPool, List desc) { - Annotation[] result = new Annotation[desc.size()]; - int i = 0; - - for (AnnotationDescription ad : desc) { - result[i++] = createAnnotation(constantPool, ad); - } - - return result; + private List createAnnotations(List desc) { + return desc.stream().map(this::createAnnotation).collect(Collectors.toList()); } - private Annotation[][] createParameterAnnotations(List constantPool, List> desc) { - Annotation[][] result = new Annotation[desc.size()][]; - int i = 0; - - for (List paramAnnos : desc) { - result[i++] = createAnnotations(constantPool, paramAnnos); - } - - return result; + private List> createParameterAnnotations(List> desc) { + return desc.stream().map(this::createAnnotations).collect(Collectors.toList()); } - private Annotation createAnnotation(List constantPool, AnnotationDescription desc) { + private Annotation createAnnotation(AnnotationDescription desc) { String annotationType = desc.annotationType; Map values = desc.values; @@ -1257,184 +1030,33 @@ private Annotation createAnnotation(List constantPool, AnnotationDescrip annotationType = RESTRICTED_ANNOTATION_INTERNAL; } - return new Annotation(null, - addString(constantPool, annotationType), - createElementPairs(constantPool, values)); - } - - private element_value_pair[] createElementPairs(List constantPool, Map annotationAttributes) { - element_value_pair[] pairs = new element_value_pair[annotationAttributes.size()]; - int i = 0; - - for (Entry e : annotationAttributes.entrySet()) { - int elementNameString = addString(constantPool, e.getKey()); - element_value value = createAttributeValue(constantPool, e.getValue()); - pairs[i++] = new element_value_pair(elementNameString, value); - } - - return pairs; + return Annotation.of(ClassDesc.ofDescriptor(annotationType), + createElementPairs(values)); } - private element_value createAttributeValue(List constantPool, Object value) { - Pair constantPoolEntry = addConstant(constantPool, value, true); - if (constantPoolEntry != null) { - return new Primitive_element_value(constantPoolEntry.fst, constantPoolEntry.snd); - } else if (value instanceof EnumConstant) { - EnumConstant ec = (EnumConstant) value; - return new Enum_element_value(addString(constantPool, ec.type), - addString(constantPool, ec.constant), - 'e'); - } else if (value instanceof ClassConstant) { - ClassConstant cc = (ClassConstant) value; - return new Class_element_value(addString(constantPool, cc.type), 'c'); - } else if (value instanceof AnnotationDescription) { - Annotation annotation = createAnnotation(constantPool, ((AnnotationDescription) value)); - return new Annotation_element_value(annotation, '@'); - } else if (value instanceof Collection) { - @SuppressWarnings("unchecked") - Collection array = (Collection) value; - element_value[] values = new element_value[array.size()]; - int i = 0; - - for (Object elem : array) { - values[i++] = createAttributeValue(constantPool, elem); - } - - return new Array_element_value(values, '['); - } - throw new IllegalStateException(value.getClass().getName()); + private List createElementPairs(Map annotationAttributes) { + return annotationAttributes.entrySet().stream() + .map(e -> AnnotationElement.of(e.getKey(), createAttributeValue(e.getValue()))) + .collect(Collectors.toList()); } - private static Pair addConstant(List constantPool, Object value, boolean annotation) { - if (value instanceof Boolean) { - return Pair.of(addToCP(constantPool, new CONSTANT_Integer_info(((Boolean) value) ? 1 : 0)), 'Z'); - } else if (value instanceof Byte) { - return Pair.of(addToCP(constantPool, new CONSTANT_Integer_info((byte) value)), 'B'); - } else if (value instanceof Character) { - return Pair.of(addToCP(constantPool, new CONSTANT_Integer_info((char) value)), 'C'); - } else if (value instanceof Short) { - return Pair.of(addToCP(constantPool, new CONSTANT_Integer_info((short) value)), 'S'); - } else if (value instanceof Integer) { - return Pair.of(addToCP(constantPool, new CONSTANT_Integer_info((int) value)), 'I'); - } else if (value instanceof Long) { - return Pair.of(addToCP(constantPool, new CONSTANT_Long_info((long) value)), 'J'); - } else if (value instanceof Float) { - return Pair.of(addToCP(constantPool, new CONSTANT_Float_info((float) value)), 'F'); - } else if (value instanceof Double) { - return Pair.of(addToCP(constantPool, new CONSTANT_Double_info((double) value)), 'D'); - } else if (value instanceof String) { - int stringIndex = addString(constantPool, (String) value); - if (annotation) { - return Pair.of(stringIndex, 's'); - } else { - return Pair.of(addToCP(constantPool, new CONSTANT_String_info(null, stringIndex)), 's'); - } - } - - return null; - } - - private static int addString(List constantPool, String string) { - Assert.checkNonNull(string); - - int i = 0; - for (CPInfo info : constantPool) { - if (info instanceof CONSTANT_Utf8_info) { - if (((CONSTANT_Utf8_info) info).value.equals(string)) { - return i; - } - } - i++; - } - - return addToCP(constantPool, new CONSTANT_Utf8_info(string)); - } - - private static int addInt(List constantPool, int value) { - int i = 0; - for (CPInfo info : constantPool) { - if (info instanceof CONSTANT_Integer_info) { - if (((CONSTANT_Integer_info) info).value == value) { - return i; - } - } - i++; - } - - return addToCP(constantPool, new CONSTANT_Integer_info(value)); - } - - private static int addModuleName(List constantPool, String moduleName) { - int nameIdx = addString(constantPool, moduleName); - int i = 0; - for (CPInfo info : constantPool) { - if (info instanceof CONSTANT_Module_info) { - if (((CONSTANT_Module_info) info).name_index == nameIdx) { - return i; - } - } - i++; - } - - return addToCP(constantPool, new CONSTANT_Module_info(null, nameIdx)); - } - - private static int addPackageName(List constantPool, String packageName) { - int nameIdx = addString(constantPool, packageName); - int i = 0; - for (CPInfo info : constantPool) { - if (info instanceof CONSTANT_Package_info) { - if (((CONSTANT_Package_info) info).name_index == nameIdx) { - return i; - } - } - i++; - } - - return addToCP(constantPool, new CONSTANT_Package_info(null, nameIdx)); - } - - private static int addClassName(List constantPool, String className) { - int nameIdx = addString(constantPool, className); - int i = 0; - for (CPInfo info : constantPool) { - if (info instanceof CONSTANT_Class_info) { - if (((CONSTANT_Class_info) info).name_index == nameIdx) { - return i; - } - } - i++; - } - - return addToCP(constantPool, new CONSTANT_Class_info(null, nameIdx)); - } - - private static int addToCP(List constantPool, CPInfo entry) { - int result = constantPool.size(); - - constantPool.add(entry); - - if (entry.size() > 1) { - constantPool.add(null); - } - - return result; - } - - private static int addClass(List constantPool, String className) { - int classNameIndex = addString(constantPool, className); - - int i = 0; - for (CPInfo info : constantPool) { - if (info instanceof CONSTANT_Class_info) { - if (((CONSTANT_Class_info) info).name_index == classNameIndex) { - return i; - } - } - i++; - } - - return addToCP(constantPool, new CONSTANT_Class_info(null, classNameIndex)); + private AnnotationValue createAttributeValue(Object value) { + return switch (value) { + case Boolean v -> AnnotationValue.ofBoolean(v); + case Byte v -> AnnotationValue.ofByte(v); + case Character v -> AnnotationValue.ofChar(v); + case Short v -> AnnotationValue.ofShort(v); + case Integer v -> AnnotationValue.ofInt(v); + case Long v -> AnnotationValue.ofLong(v); + case Float v -> AnnotationValue.ofFloat(v); + case Double v -> AnnotationValue.ofDouble(v); + case String v -> AnnotationValue.ofString(v); + case EnumConstant v -> AnnotationValue.ofEnum(ClassDesc.ofDescriptor(v.type), v.constant); + case ClassConstant v -> AnnotationValue.ofClass(ClassDesc.ofDescriptor(v.type)); + case AnnotationDescription v -> AnnotationValue.ofAnnotation(createAnnotation(v)); + case Collection v -> AnnotationValue.ofArray(v.stream().map(this::createAttributeValue).collect(Collectors.toList())); + default -> throw new IllegalArgumentException(value.getClass().getName()); + }; } // // @@ -1509,7 +1131,7 @@ private Iterable loadClassData(String path) { classFileData.add(data.toByteArray()); } } catch (IOException ex) { - throw new IllegalStateException(ex); + throw new IllegalArgumentException(ex); } return classFileData; @@ -1525,12 +1147,8 @@ private void loadVersionClasses(ClassList classes, new HashMap<>(); for (byte[] classFileData : classData) { - try (InputStream in = new ByteArrayInputStream(classFileData)) { - inspectModuleInfoClassFile(in, - currentVersionModules, version); - } catch (IOException | ConstantPoolException ex) { - throw new IllegalStateException(ex); - } + inspectModuleInfoClassFile(classFileData, + currentVersionModules, version); } ExcludeIncludeList currentEIList; @@ -1561,28 +1179,25 @@ private void loadVersionClasses(ClassList classes, try (InputStream in = new ByteArrayInputStream(classFileData)) { inspectClassFile(in, currentVersionClasses, currentEIList, version, - cf -> { - PermittedSubclasses_attribute permitted = (PermittedSubclasses_attribute) cf.getAttribute(Attribute.PermittedSubclasses); + cm -> { + var permitted = cm.findAttribute(Attributes.permittedSubclasses()).orElse(null); if (permitted != null) { - try { - String currentPack = cf.getName().substring(0, cf.getName().lastIndexOf('/')); + var name = cm.thisClass().asInternalName(); + String currentPack = name.substring(0, name.lastIndexOf('/')); - for (int i = 0; i < permitted.subtypes.length; i++) { - String permittedClassName = cf.constant_pool.getClassInfo(permitted.subtypes[i]).getName(); - if (!currentEIList.accepts(permittedClassName, false)) { - String permittedPack = permittedClassName.substring(0, permittedClassName.lastIndexOf('/')); + for (var sub : permitted.permittedSubclasses()) { + String permittedClassName = sub.asInternalName(); + if (!currentEIList.accepts(permittedClassName, false)) { + String permittedPack = permittedClassName.substring(0, permittedClassName.lastIndexOf('/')); - extraModulesPackagesToDerive.computeIfAbsent(permittedPack, x -> new HashSet<>()) - .add(currentPack); - } + extraModulesPackagesToDerive.computeIfAbsent(permittedPack, x -> new HashSet<>()) + .add(currentPack); } - } catch (ConstantPoolException ex) { - throw new IllegalStateException(ex); } } }); - } catch (IOException | ConstantPoolException ex) { - throw new IllegalStateException(ex); + } catch (IOException ex) { + throw new IllegalArgumentException(ex); } } @@ -1648,12 +1263,8 @@ private void loadVersionClassesFromDirectory(ClassList classes, Path moduleInfo = p.resolve("module-info.class"); if (Files.isReadable(moduleInfo)) { - ModuleDescription md; - - try (InputStream in = Files.newInputStream(moduleInfo)) { - md = inspectModuleInfoClassFile(in, + ModuleDescription md = inspectModuleInfoClassFile(Files.readAllBytes(moduleInfo), currentVersionModules, version); - } if (md == null) { continue; } @@ -1715,8 +1326,8 @@ private void loadVersionClassesFromDirectory(ClassList classes, } } } - } catch (IOException | ConstantPoolException ex) { - throw new IllegalStateException(ex); + } catch (IOException ex) { + throw new IllegalArgumentException(ex); } finishClassLoading(classes, modules, currentVersionModules, currentVersionClasses, currentEIList, version, baseline); @@ -1724,7 +1335,7 @@ private void loadVersionClassesFromDirectory(ClassList classes, private void loadFromDirectoryHandleClassFile(Path path, ClassList currentVersionClasses, ExcludeIncludeList currentEIList, String version, - List todo) throws IOException, ConstantPoolException { + List todo) throws IOException { try (InputStream in = Files.newInputStream(path)) { inspectClassFile(in, currentVersionClasses, currentEIList, version, @@ -2244,45 +1855,41 @@ private JavaFileManager setupJavac(String... options) { public static String PROFILE_ANNOTATION = "Ljdk/Profile+Annotation;"; public static boolean ALLOW_NON_EXISTING_CLASSES = false; - private void inspectClassFile(InputStream in, ClassList classes, ExcludeIncludeList excludesIncludes, String version) throws IOException, ConstantPoolException { + private void inspectClassFile(InputStream in, ClassList classes, ExcludeIncludeList excludesIncludes, String version) throws IOException { inspectClassFile(in, classes, excludesIncludes, version, cf -> {}); } private void inspectClassFile(InputStream in, ClassList classes, ExcludeIncludeList excludesIncludes, String version, - Consumer extraTask) throws IOException, ConstantPoolException { - ClassFile cf = ClassFile.read(in); + Consumer extraTask) throws IOException { + ClassModel cm = ClassFile.of().parse(in.readAllBytes()); - if (cf.access_flags.is(AccessFlags.ACC_MODULE)) { + if (cm.isModuleInfo()) { return ; } - if (!excludesIncludes.accepts(cf.getName(), true)) { + if (!excludesIncludes.accepts(cm.thisClass().asInternalName(), true)) { return ; } - extraTask.accept(cf); + extraTask.accept(cm); ClassHeaderDescription headerDesc = new ClassHeaderDescription(); - headerDesc.flags = cf.access_flags.flags; + headerDesc.flags = cm.flags().flagsMask(); - if (cf.super_class != 0) { - headerDesc.extendsAttr = cf.getSuperclassName(); - } - List interfaces = new ArrayList<>(); - for (int i = 0; i < cf.interfaces.length; i++) { - interfaces.add(cf.getInterfaceName(i)); + if (cm.superclass().isPresent()) { + headerDesc.extendsAttr = cm.superclass().get().asInternalName(); } - headerDesc.implementsAttr = interfaces; - for (Attribute attr : cf.attributes) { - if (!readAttribute(cf, headerDesc, attr)) + headerDesc.implementsAttr = cm.interfaces().stream().map(ClassEntry::asInternalName).collect(Collectors.toList()); + for (var attr : cm.attributes()) { + if (!readAttribute(headerDesc, attr)) return ; } ClassDescription clazzDesc = null; for (ClassDescription cd : classes) { - if (cd.name.equals(cf.getName())) { + if (cd.name.equals(cm.thisClass().asInternalName())) { clazzDesc = cd; break; } @@ -2290,54 +1897,54 @@ private void inspectClassFile(InputStream in, ClassList classes, ExcludeIncludeL if (clazzDesc == null) { clazzDesc = new ClassDescription(); - clazzDesc.name = cf.getName(); + clazzDesc.name = cm.thisClass().asInternalName(); classes.add(clazzDesc); } addClassHeader(clazzDesc, headerDesc, version, null); - for (Method m : cf.methods) { - if (!include(m.access_flags.flags)) + for (var m : cm.methods()) { + if (!include(m.flags().flagsMask())) continue; MethodDescription methDesc = new MethodDescription(); - methDesc.flags = m.access_flags.flags; - methDesc.name = m.getName(cf.constant_pool); - methDesc.descriptor = m.descriptor.getValue(cf.constant_pool); - for (Attribute attr : m.attributes) { - readAttribute(cf, methDesc, attr); + methDesc.flags = m.flags().flagsMask(); + methDesc.name = m.methodName().stringValue(); + methDesc.descriptor = m.methodType().stringValue(); + for (var attr : m.attributes()) { + readAttribute(methDesc, attr); } addMethod(clazzDesc, methDesc, version, null); } - for (Field f : cf.fields) { - if (!include(f.access_flags.flags)) + for (var f : cm.fields()) { + if (!include(f.flags().flagsMask())) continue; FieldDescription fieldDesc = new FieldDescription(); - fieldDesc.flags = f.access_flags.flags; - fieldDesc.name = f.getName(cf.constant_pool); - fieldDesc.descriptor = f.descriptor.getValue(cf.constant_pool); - for (Attribute attr : f.attributes) { - readAttribute(cf, fieldDesc, attr); + fieldDesc.flags = f.flags().flagsMask(); + fieldDesc.name = f.fieldName().stringValue(); + fieldDesc.descriptor = f.fieldType().stringValue(); + for (var attr : f.attributes()) { + readAttribute(fieldDesc, attr); } addField(clazzDesc, fieldDesc, version, null); } } - private ModuleDescription inspectModuleInfoClassFile(InputStream in, + private ModuleDescription inspectModuleInfoClassFile(byte[] data, Map modules, - String version) throws IOException, ConstantPoolException { - ClassFile cf = ClassFile.read(in); + String version) { + ClassModel cm = ClassFile.of().parse(data); - if (!cf.access_flags.is(AccessFlags.ACC_MODULE)) { + if (!cm.flags().has(AccessFlag.MODULE)) { return null; } ModuleHeaderDescription headerDesc = new ModuleHeaderDescription(); headerDesc.versions = version; - headerDesc.flags = cf.access_flags.flags; + headerDesc.flags = cm.flags().flagsMask(); - for (Attribute attr : cf.attributes) { - if (!readAttribute(cf, headerDesc, attr)) + for (var attr : cm.attributes()) { + if (!readAttribute(headerDesc, attr)) return null; } @@ -2361,56 +1968,46 @@ private Set enhancedIncludesListBasedOnClassHeaders(ClassList classes, Set additionalIncludes = new HashSet<>(); for (byte[] classFileData : classData) { - try (InputStream in = new ByteArrayInputStream(classFileData)) { - ClassFile cf = ClassFile.read(in); - - additionalIncludes.addAll(otherRelevantTypesWithOwners(cf)); - } catch (IOException | ConstantPoolException ex) { - throw new IllegalStateException(ex); - } + additionalIncludes.addAll(otherRelevantTypesWithOwners(ClassFile.of().parse(classFileData))); } return additionalIncludes; } - private Set otherRelevantTypesWithOwners(ClassFile cf) { + private Set otherRelevantTypesWithOwners(ClassModel cm) { Set supertypes = new HashSet<>(); - try { - if (cf.access_flags.is(AccessFlags.ACC_MODULE)) { - return supertypes; - } + if (cm.flags().has(AccessFlag.MODULE)) { + return supertypes; + } - Set additionalClasses = new HashSet<>(); + Set additionalClasses = new HashSet<>(); - if (cf.super_class != 0) { - additionalClasses.add(cf.getSuperclassName()); - } - for (int i = 0; i < cf.interfaces.length; i++) { - additionalClasses.add(cf.getInterfaceName(i)); - } - PermittedSubclasses_attribute permitted = (PermittedSubclasses_attribute) cf.getAttribute(Attribute.PermittedSubclasses); - if (permitted != null) { - for (int i = 0; i < permitted.subtypes.length; i++) { - additionalClasses.add(cf.constant_pool.getClassInfo(permitted.subtypes[i]).getName()); - } + if (cm.superclass().isPresent()) { + additionalClasses.add(cm.superclass().get().asInternalName()); + } + for (var iface : cm.interfaces()) { + additionalClasses.add(iface.asInternalName()); + } + var permitted = cm.findAttribute(Attributes.permittedSubclasses()).orElse(null); + if (permitted != null) { + for (var sub : permitted.permittedSubclasses()) { + additionalClasses.add(sub.asInternalName()); } + } - for (String additional : additionalClasses) { - int dollar; + for (String additional : additionalClasses) { + int dollar; - supertypes.add(additional); + supertypes.add(additional); - while ((dollar = additional.lastIndexOf('$')) != (-1)) { - additional = additional.substring(0, dollar); - supertypes.add(additional); - } + while ((dollar = additional.lastIndexOf('$')) != (-1)) { + additional = additional.substring(0, dollar); + supertypes.add(additional); } - - return supertypes; - } catch (ConstantPoolException ex) { - throw new IllegalStateException(ex); } + + return supertypes; } private void addModuleHeader(ModuleDescription moduleDesc, @@ -2435,7 +2032,7 @@ private void addModuleHeader(ModuleDescription moduleDesc, } private boolean include(int accessFlags) { - return (accessFlags & (AccessFlags.ACC_PUBLIC | AccessFlags.ACC_PROTECTED)) != 0; + return (accessFlags & (ACC_PUBLIC | ACC_PROTECTED)) != 0; } private void addClassHeader(ClassDescription clazzDesc, ClassHeaderDescription headerDesc, String version, String baseline) { @@ -2531,367 +2128,137 @@ private void addField(ClassDescription clazzDesc, FieldDescription fieldDesc, St } } - private boolean readAttribute(ClassFile cf, FeatureDescription feature, Attribute attr) throws ConstantPoolException { - String attrName = attr.getName(cf.constant_pool); - switch (attrName) { - case Attribute.AnnotationDefault: - assert feature instanceof MethodDescription; - element_value defaultValue = ((AnnotationDefault_attribute) attr).default_value; - ((MethodDescription) feature).annotationDefaultValue = - convertElementValue(cf.constant_pool, defaultValue); - break; - case "Deprecated": - feature.deprecated = true; - break; - case "Exceptions": - assert feature instanceof MethodDescription; - List thrownTypes = new ArrayList<>(); - Exceptions_attribute exceptionAttr = (Exceptions_attribute) attr; - for (int i = 0; i < exceptionAttr.exception_index_table.length; i++) { - thrownTypes.add(exceptionAttr.getException(i, cf.constant_pool)); - } - ((MethodDescription) feature).thrownTypes = thrownTypes; - break; - case Attribute.InnerClasses: + private boolean readAttribute(FeatureDescription feature, Attribute attr) { + switch (attr) { + case AnnotationDefaultAttribute a -> + ((MethodDescription) feature).annotationDefaultValue = convertElementValue(a.defaultValue()); + case DeprecatedAttribute _ -> feature.deprecated = true; + case ExceptionsAttribute a -> ((MethodDescription) feature).thrownTypes = a.exceptions().stream().map(ClassEntry::asInternalName).collect(Collectors.toList()); + case InnerClassesAttribute a -> { if (feature instanceof ModuleHeaderDescription) break; //XXX - assert feature instanceof ClassHeaderDescription; - List innerClasses = new ArrayList<>(); - InnerClasses_attribute innerClassesAttr = (InnerClasses_attribute) attr; - for (int i = 0; i < innerClassesAttr.number_of_classes; i++) { - CONSTANT_Class_info outerClassInfo = - innerClassesAttr.classes[i].getOuterClassInfo(cf.constant_pool); - InnerClassInfo info = new InnerClassInfo(); - CONSTANT_Class_info innerClassInfo = - innerClassesAttr.classes[i].getInnerClassInfo(cf.constant_pool); - info.innerClass = innerClassInfo != null ? innerClassInfo.getName() : null; - info.outerClass = outerClassInfo != null ? outerClassInfo.getName() : null; - info.innerClassName = innerClassesAttr.classes[i].getInnerName(cf.constant_pool); - info.innerClassFlags = innerClassesAttr.classes[i].inner_class_access_flags.flags; - innerClasses.add(info); - } - ((ClassHeaderDescription) feature).innerClasses = innerClasses; - break; - case "RuntimeInvisibleAnnotations": - feature.classAnnotations = annotations2Description(cf.constant_pool, attr); - break; - case "RuntimeVisibleAnnotations": - feature.runtimeAnnotations = annotations2Description(cf.constant_pool, attr); - break; - case "Signature": - feature.signature = ((Signature_attribute) attr).getSignature(cf.constant_pool); - break; - case "ConstantValue": - assert feature instanceof FieldDescription; - Object value = convertConstantValue(cf.constant_pool.get(((ConstantValue_attribute) attr).constantvalue_index), ((FieldDescription) feature).descriptor); - if (((FieldDescription) feature).descriptor.equals("C")) { - value = (char) (int) value; - } - ((FieldDescription) feature).constantValue = value; - break; - case "SourceFile": - //ignore, not needed - break; - case "BootstrapMethods": - //ignore, not needed - break; - case "Code": - //ignore, not needed - break; - case "EnclosingMethod": + ((ClassHeaderDescription) feature).innerClasses = a.classes().stream().map(cfi -> { + var info = new InnerClassInfo(); + info.innerClass = cfi.innerClass().asInternalName(); + info.outerClass = cfi.outerClass().map(ClassEntry::asInternalName).orElse(null); + info.innerClassName = cfi.innerName().map(Utf8Entry::stringValue).orElse(null); + info.innerClassFlags = cfi.flagsMask(); + return info; + }).collect(Collectors.toList()); + } + case RuntimeInvisibleAnnotationsAttribute a -> feature.classAnnotations = annotations2Description(a.annotations()); + case RuntimeVisibleAnnotationsAttribute a -> feature.runtimeAnnotations = annotations2Description(a.annotations()); + case SignatureAttribute a -> feature.signature = a.signature().stringValue(); + case ConstantValueAttribute a -> { + var f = (FieldDescription) feature; + f.constantValue = convertConstantValue(a.constant(), f.descriptor); + } + case SourceFileAttribute _, BootstrapMethodsAttribute _, CodeAttribute _, SyntheticAttribute _ -> {} + case EnclosingMethodAttribute _ -> { return false; - case "Synthetic": - break; - case "RuntimeVisibleParameterAnnotations": - assert feature instanceof MethodDescription; - ((MethodDescription) feature).runtimeParameterAnnotations = - parameterAnnotations2Description(cf.constant_pool, attr); - break; - case "RuntimeInvisibleParameterAnnotations": - assert feature instanceof MethodDescription; - ((MethodDescription) feature).classParameterAnnotations = - parameterAnnotations2Description(cf.constant_pool, attr); - break; - case Attribute.Module: { - assert feature instanceof ModuleHeaderDescription; - ModuleHeaderDescription header = - (ModuleHeaderDescription) feature; - Module_attribute mod = (Module_attribute) attr; - - header.name = cf.constant_pool - .getModuleInfo(mod.module_name) - .getName(); - - header.exports = - Arrays.stream(mod.exports) - .map(ee -> ExportsDescription.create(cf, ee)) - .collect(Collectors.toList()); + } + case RuntimeVisibleParameterAnnotationsAttribute a -> ((MethodDescription) feature).runtimeParameterAnnotations = parameterAnnotations2Description(a.parameterAnnotations()); + case RuntimeInvisibleParameterAnnotationsAttribute a -> ((MethodDescription) feature).classParameterAnnotations = parameterAnnotations2Description(a.parameterAnnotations()); + case ModuleAttribute a -> { + ModuleHeaderDescription header = (ModuleHeaderDescription) feature; + header.name = a.moduleName().name().stringValue(); + header.exports = a.exports().stream().map(ExportsDescription::create).collect(Collectors.toList()); if (header.extraModulePackages != null) { header.exports.forEach(ed -> header.extraModulePackages.remove(ed.packageName())); } - header.requires = - Arrays.stream(mod.requires) - .map(r -> RequiresDescription.create(cf, r)) - .collect(Collectors.toList()); - header.uses = Arrays.stream(mod.uses_index) - .mapToObj(use -> getClassName(cf, use)) - .collect(Collectors.toList()); - header.provides = - Arrays.stream(mod.provides) - .map(p -> ProvidesDescription.create(cf, p)) - .collect(Collectors.toList()); - break; - } - case Attribute.ModuleTarget: { - assert feature instanceof ModuleHeaderDescription; - ModuleHeaderDescription header = - (ModuleHeaderDescription) feature; - ModuleTarget_attribute mod = (ModuleTarget_attribute) attr; - if (mod.target_platform_index != 0) { - header.moduleTarget = - cf.constant_pool - .getUTF8Value(mod.target_platform_index); - } - break; - } - case Attribute.ModuleResolution: { - assert feature instanceof ModuleHeaderDescription; - ModuleHeaderDescription header = - (ModuleHeaderDescription) feature; - ModuleResolution_attribute mod = - (ModuleResolution_attribute) attr; - header.moduleResolution = mod.resolution_flags; - break; - } - case Attribute.ModulePackages: - assert feature instanceof ModuleHeaderDescription; - ModuleHeaderDescription header = - (ModuleHeaderDescription) feature; - ModulePackages_attribute mod = - (ModulePackages_attribute) attr; - header.extraModulePackages = new ArrayList<>(); - for (int i = 0; i < mod.packages_count; i++) { - String packageName = getPackageName(cf, mod.packages_index[i]); + header.requires = a.requires().stream().map(RequiresDescription::create).collect(Collectors.toList()); + header.uses = a.uses().stream().map(ClassEntry::asInternalName).collect(Collectors.toList()); + header.provides = a.provides().stream().map(ProvidesDescription::create).collect(Collectors.toList()); + } + case ModuleTargetAttribute a -> ((ModuleHeaderDescription) feature).moduleTarget = a.targetPlatform().stringValue(); + case ModuleResolutionAttribute a -> ((ModuleHeaderDescription) feature).moduleResolution = a.resolutionFlags(); + case ModulePackagesAttribute a -> { + var header = (ModuleHeaderDescription) feature; + header.extraModulePackages = a.packages().stream().mapMulti((packageItem, sink) -> { + var packageName = packageItem.name().stringValue(); if (header.exports == null || - header.exports.stream().noneMatch(ed -> ed.packageName().equals(packageName))) { - header.extraModulePackages.add(packageName); + header.exports.stream().noneMatch(ed -> ed.packageName().equals(packageName))) { + sink.accept(packageName); } - } - break; - case Attribute.ModuleHashes: - break; - case Attribute.NestHost: { - assert feature instanceof ClassHeaderDescription; - NestHost_attribute nestHost = (NestHost_attribute) attr; - ClassHeaderDescription chd = (ClassHeaderDescription) feature; - chd.nestHost = nestHost.getNestTop(cf.constant_pool).getName(); - break; - } - case Attribute.NestMembers: { - assert feature instanceof ClassHeaderDescription; - NestMembers_attribute nestMembers = (NestMembers_attribute) attr; - ClassHeaderDescription chd = (ClassHeaderDescription) feature; - chd.nestMembers = Arrays.stream(nestMembers.members_indexes) - .mapToObj(i -> getClassName(cf, i)) - .collect(Collectors.toList()); - break; + }).collect(Collectors.toList()); } - case Attribute.Record: { - assert feature instanceof ClassHeaderDescription; - Record_attribute record = (Record_attribute) attr; - List components = new ArrayList<>(); - for (ComponentInfo info : record.component_info_arr) { - RecordComponentDescription rcd = new RecordComponentDescription(); - rcd.name = info.getName(cf.constant_pool); - rcd.descriptor = info.descriptor.getValue(cf.constant_pool); - for (Attribute nestedAttr : info.attributes) { - readAttribute(cf, rcd, nestedAttr); - } - components.add(rcd); - } - ClassHeaderDescription chd = (ClassHeaderDescription) feature; + case ModuleHashesAttribute _ -> {} + case NestHostAttribute a -> ((ClassHeaderDescription) feature).nestHost = a.nestHost().asInternalName(); + case NestMembersAttribute a -> ((ClassHeaderDescription) feature).nestMembers = a.nestMembers().stream().map(ClassEntry::asInternalName).collect(Collectors.toList()); + case RecordAttribute a -> { + var chd = (ClassHeaderDescription) feature; chd.isRecord = true; - chd.recordComponents = components; - break; - } - case Attribute.MethodParameters: { - assert feature instanceof MethodDescription; - MethodParameters_attribute params = (MethodParameters_attribute) attr; - MethodDescription method = (MethodDescription) feature; - method.methodParameters = new ArrayList<>(); - for (MethodParameters_attribute.Entry e : params.method_parameter_table) { - String name = e.name_index == 0 ? null - : cf.constant_pool.getUTF8Value(e.name_index); - MethodDescription.MethodParam param = - new MethodDescription.MethodParam(e.flags, name); - method.methodParameters.add(param); - } - break; - } - case Attribute.PermittedSubclasses: { - assert feature instanceof ClassHeaderDescription; - PermittedSubclasses_attribute permittedSubclasses = (PermittedSubclasses_attribute) attr; - ClassHeaderDescription chd = (ClassHeaderDescription) feature; - chd.permittedSubclasses = Arrays.stream(permittedSubclasses.subtypes) - .mapToObj(i -> getClassName(cf, i)) - .collect(Collectors.toList()); + chd.recordComponents = a.components().stream().map(rci -> { + var rcd = new RecordComponentDescription(); + rcd.name = rci.name().stringValue(); + rcd.descriptor = rci.descriptor().stringValue(); + rci.attributes().forEach(child -> readAttribute(rcd, child)); + return rcd; + }).collect(Collectors.toList()); + } + case MethodParametersAttribute a -> ((MethodDescription) feature).methodParameters = a.parameters().stream() + .map(mpi -> new MethodDescription.MethodParam(mpi.flagsMask(), mpi.name().map(Utf8Entry::stringValue).orElse(null))) + .collect(Collectors.toList()); + case PermittedSubclassesAttribute a -> { + var chd = (ClassHeaderDescription) feature; chd.isSealed = true; - break; + chd.permittedSubclasses = a.permittedSubclasses().stream().map(ClassEntry::asInternalName).collect(Collectors.toList()); } - case Attribute.ModuleMainClass: { - ModuleMainClass_attribute moduleMainClass = (ModuleMainClass_attribute) attr; - assert feature instanceof ModuleHeaderDescription; - ModuleHeaderDescription mhd = (ModuleHeaderDescription) feature; - mhd.moduleMainClass = moduleMainClass.getMainClassName(cf.constant_pool); - break; - } - default: - throw new IllegalStateException("Unhandled attribute: " + - attrName); + case ModuleMainClassAttribute a -> ((ModuleHeaderDescription) feature).moduleMainClass = a.mainClass().asInternalName(); + default -> throw new IllegalArgumentException("Unhandled attribute: " + attr.attributeName()); // Do nothing } return true; } - private static String getClassName(ClassFile cf, int idx) { - try { - return cf.constant_pool.getClassInfo(idx).getName(); - } catch (InvalidIndex ex) { - throw new IllegalStateException(ex); - } catch (ConstantPool.UnexpectedEntry ex) { - throw new IllegalStateException(ex); - } catch (ConstantPoolException ex) { - throw new IllegalStateException(ex); - } - } - - private static String getPackageName(ClassFile cf, int idx) { - try { - return cf.constant_pool.getPackageInfo(idx).getName(); - } catch (InvalidIndex ex) { - throw new IllegalStateException(ex); - } catch (ConstantPool.UnexpectedEntry ex) { - throw new IllegalStateException(ex); - } catch (ConstantPoolException ex) { - throw new IllegalStateException(ex); - } - } - - private static String getModuleName(ClassFile cf, int idx) { - try { - return cf.constant_pool.getModuleInfo(idx).getName(); - } catch (InvalidIndex ex) { - throw new IllegalStateException(ex); - } catch (ConstantPool.UnexpectedEntry ex) { - throw new IllegalStateException(ex); - } catch (ConstantPoolException ex) { - throw new IllegalStateException(ex); - } - } - public static String INJECTED_VERSION = null; - private static String getVersion(ClassFile cf, int idx) { + private static String getVersion(Optional version) { if (INJECTED_VERSION != null) { return INJECTED_VERSION; } - if (idx == 0) - return null; - try { - return ((CONSTANT_Utf8_info) cf.constant_pool.get(idx)).value; - } catch (InvalidIndex ex) { - throw new IllegalStateException(ex); - } + return version.map(Utf8Entry::stringValue).orElse(null); } - Object convertConstantValue(CPInfo info, String descriptor) throws ConstantPoolException { - if (info instanceof CONSTANT_Integer_info) { - if ("Z".equals(descriptor)) - return ((CONSTANT_Integer_info) info).value == 1; - else - return ((CONSTANT_Integer_info) info).value; - } else if (info instanceof CONSTANT_Long_info) { - return ((CONSTANT_Long_info) info).value; - } else if (info instanceof CONSTANT_Float_info) { - return ((CONSTANT_Float_info) info).value; - } else if (info instanceof CONSTANT_Double_info) { - return ((CONSTANT_Double_info) info).value; - } else if (info instanceof CONSTANT_String_info) { - return ((CONSTANT_String_info) info).getString(); - } - throw new IllegalStateException(info.getClass().getName()); + Object convertConstantValue(ConstantValueEntry info, String descriptor) { + if (descriptor.length() == 1 && info instanceof IntegerEntry ie) { + var i = ie.intValue(); + return switch (descriptor.charAt(0)) { + case 'I' -> i; + case 'B' -> (byte) i; + case 'C' -> (char) i; + case 'S' -> (short) i; + case 'Z' -> i == 1; + default -> throw new IllegalArgumentException(descriptor); + }; + } + return info.constantValue(); } - Object convertElementValue(ConstantPool cp, element_value val) throws InvalidIndex, ConstantPoolException { - switch (val.tag) { - case 'Z': - return ((CONSTANT_Integer_info) cp.get(((Primitive_element_value) val).const_value_index)).value != 0; - case 'B': - return (byte) ((CONSTANT_Integer_info) cp.get(((Primitive_element_value) val).const_value_index)).value; - case 'C': - return (char) ((CONSTANT_Integer_info) cp.get(((Primitive_element_value) val).const_value_index)).value; - case 'S': - return (short) ((CONSTANT_Integer_info) cp.get(((Primitive_element_value) val).const_value_index)).value; - case 'I': - return ((CONSTANT_Integer_info) cp.get(((Primitive_element_value) val).const_value_index)).value; - case 'J': - return ((CONSTANT_Long_info) cp.get(((Primitive_element_value) val).const_value_index)).value; - case 'F': - return ((CONSTANT_Float_info) cp.get(((Primitive_element_value) val).const_value_index)).value; - case 'D': - return ((CONSTANT_Double_info) cp.get(((Primitive_element_value) val).const_value_index)).value; - case 's': - return ((CONSTANT_Utf8_info) cp.get(((Primitive_element_value) val).const_value_index)).value; - - case 'e': - return new EnumConstant(cp.getUTF8Value(((Enum_element_value) val).type_name_index), - cp.getUTF8Value(((Enum_element_value) val).const_name_index)); - case 'c': - return new ClassConstant(cp.getUTF8Value(((Class_element_value) val).class_info_index)); - - case '@': - return annotation2Description(cp, ((Annotation_element_value) val).annotation_value); - - case '[': - List values = new ArrayList<>(); - for (element_value elem : ((Array_element_value) val).values) { - values.add(convertElementValue(cp, elem)); - } - return values; - default: - throw new IllegalStateException("Currently unhandled tag: " + val.tag); - } + Object convertElementValue(AnnotationValue val) { + return switch (val) { + case AnnotationValue.OfConstant oc -> oc.resolvedValue(); + case AnnotationValue.OfEnum oe -> new EnumConstant(oe.className().stringValue(), oe.constantName().stringValue()); + case AnnotationValue.OfClass oc -> new ClassConstant(oc.className().stringValue()); + case AnnotationValue.OfArray oa -> oa.values().stream().map(this::convertElementValue).collect(Collectors.toList()); + case AnnotationValue.OfAnnotation oa -> annotation2Description(oa.annotation()); + }; } - private List annotations2Description(ConstantPool cp, Attribute attr) throws ConstantPoolException { - RuntimeAnnotations_attribute annotationsAttr = (RuntimeAnnotations_attribute) attr; - List descs = new ArrayList<>(); - for (Annotation a : annotationsAttr.annotations) { - descs.add(annotation2Description(cp, a)); - } - return descs; + private List annotations2Description(List annos) { + return annos.stream().map(this::annotation2Description).collect(Collectors.toList()); } - private List> parameterAnnotations2Description(ConstantPool cp, Attribute attr) throws ConstantPoolException { - RuntimeParameterAnnotations_attribute annotationsAttr = - (RuntimeParameterAnnotations_attribute) attr; - List> descs = new ArrayList<>(); - for (Annotation[] attrAnnos : annotationsAttr.parameter_annotations) { - List paramDescs = new ArrayList<>(); - for (Annotation ann : attrAnnos) { - paramDescs.add(annotation2Description(cp, ann)); - } - descs.add(paramDescs); - } - return descs; + private List> parameterAnnotations2Description(List> annos) { + return annos.stream().map(this::annotations2Description).collect(Collectors.toList()); } - private AnnotationDescription annotation2Description(ConstantPool cp, Annotation a) throws ConstantPoolException { - String annotationType = cp.getUTF8Value(a.type_index); + private AnnotationDescription annotation2Description(java.lang.classfile.Annotation a) { + String annotationType = a.className().stringValue(); Map values = new HashMap<>(); - for (element_value_pair e : a.element_value_pairs) { - values.put(cp.getUTF8Value(e.element_name_index), convertElementValue(cp, e.value)); + for (var e : a.elements()) { + values.put(e.name().stringValue(), convertElementValue(e.value())); } return new AnnotationDescription(annotationType, values); @@ -3181,7 +2548,7 @@ public void read(LineBasedReader reader, String baselineVersion, case "-module": break OUTER; default: - throw new IllegalStateException(reader.lineKey); + throw new IllegalArgumentException(reader.lineKey); } } } @@ -3396,15 +2763,11 @@ public static ExportsDescription deserialize(String data) { return new ExportsDescription(packageName, to); } - public static ExportsDescription create(ClassFile cf, - ExportsEntry ee) { - String packageName = getPackageName(cf, ee.exports_index); + public static ExportsDescription create(ModuleExportInfo ee) { + String packageName = ee.exportedPackage().name().stringValue(); List to = null; - if (ee.exports_to_count > 0) { - to = new ArrayList<>(); - for (int moduleIndex : ee.exports_to_index) { - to.add(getModuleName(cf, moduleIndex)); - } + if (!ee.exportsTo().isEmpty()) { + to = ee.exportsTo().stream().map(m -> m.name().stringValue()).collect(Collectors.toList()); } return new ExportsDescription(packageName, to); } @@ -3447,12 +2810,11 @@ public static RequiresDescription deserialize(String data) { ver); } - public static RequiresDescription create(ClassFile cf, - RequiresEntry req) { - String mod = getModuleName(cf, req.requires_index); - String ver = getVersion(cf, req.requires_version_index); + public static RequiresDescription create(ModuleRequireInfo req) { + String mod = req.requires().name().stringValue(); + String ver = getVersion(req.requiresVersion()); return new RequiresDescription(mod, - req.requires_flags, + req.requiresFlagsMask(), ver); } @@ -3515,13 +2877,9 @@ public static ProvidesDescription deserialize(String data) { implsList); } - public static ProvidesDescription create(ClassFile cf, - ProvidesEntry prov) { - String api = getClassName(cf, prov.provides_index); - List impls = - Arrays.stream(prov.with_index) - .mapToObj(wi -> getClassName(cf, wi)) - .collect(Collectors.toList()); + public static ProvidesDescription create(ModuleProvideInfo prov) { + String api = prov.provides().asInternalName(); + List impls = prov.providesWith().stream().map(ClassEntry::asInternalName).collect(Collectors.toList()); return new ProvidesDescription(api, impls); } @@ -3676,7 +3034,7 @@ public void read(LineBasedReader reader, String baselineVersion, case "-module": break OUTER; default: - throw new IllegalStateException(reader.lineKey); + throw new IllegalArgumentException(reader.lineKey); } } } @@ -4149,7 +3507,7 @@ public boolean read(LineBasedReader reader) throws IOException { case "D": constantValue = Double.parseDouble(inConstantValue); break; case "Ljava/lang/String;": constantValue = inConstantValue; break; default: - throw new IllegalStateException("Unrecognized field type: " + descriptor); + throw new IllegalArgumentException("Unrecognized field type: " + descriptor); } } @@ -4416,7 +3774,7 @@ public ClassDescription find(String name, boolean allowNull) { if (desc != null || allowNull) return desc; - throw new IllegalStateException("Cannot find: " + name); + throw new IllegalArgumentException("Cannot find: " + name); } private static final ClassDescription NONE = new ClassDescription(); @@ -4565,7 +3923,7 @@ private static Object parseAnnotationValue(String value, int[] valuePointer) { valuePointer[0] += 5; return false; } else { - throw new IllegalStateException("Unrecognized boolean structure: " + value); + throw new IllegalArgumentException("Unrecognized boolean structure: " + value); } case 'B': return Byte.parseByte(readDigits(value, valuePointer)); case 'C': return value.charAt(valuePointer[0]++); @@ -4593,7 +3951,7 @@ private static Object parseAnnotationValue(String value, int[] valuePointer) { case '@': return parseAnnotation(value, valuePointer); default: - throw new IllegalStateException("Unrecognized signature type: " + value.charAt(valuePointer[0] - 1) + "; value=" + value); + throw new IllegalArgumentException("Unrecognized signature type: " + value.charAt(valuePointer[0] - 1) + "; value=" + value); } } diff --git a/test/langtools/tools/javac/platform/CanHandleClassFilesTest.java b/test/langtools/tools/javac/platform/CanHandleClassFilesTest.java index a8d4747babb2d..f91d9ea02b186 100644 --- a/test/langtools/tools/javac/platform/CanHandleClassFilesTest.java +++ b/test/langtools/tools/javac/platform/CanHandleClassFilesTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2025, 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 @@ -30,7 +30,6 @@ * jdk.compiler/com.sun.tools.javac.main * jdk.compiler/com.sun.tools.javac.jvm:+open * jdk.compiler/com.sun.tools.javac.util:+open - * jdk.jdeps/com.sun.tools.classfile:+open * @build toolbox.ToolBox toolbox.JavacTask toolbox.Task * @run main CanHandleClassFilesTest */ @@ -76,8 +75,7 @@ void run() throws Exception { try (ToolBox.MemoryFileManager mfm = new ToolBox.MemoryFileManager()) { ToolBox tb = new ToolBox(); new JavacTask(tb) - .options("--add-exports", "jdk.jdeps/com.sun.tools.classfile=ALL-UNNAMED", - "--add-exports", "jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED", + .options("--add-exports", "jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED", "--add-exports", "jdk.compiler/com.sun.tools.javac.jvm=ALL-UNNAMED", "--add-exports", "jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED", "--add-modules", "jdk.jdeps") @@ -102,8 +100,7 @@ protected Class findClass(String name) throws ClassNotFoundException { Module targetModule = cl.getUnnamedModule(); Stream.of("jdk.compiler/com.sun.tools.javac.api", "jdk.compiler/com.sun.tools.javac.jvm", - "jdk.compiler/com.sun.tools.javac.util", - "jdk.jdeps/com.sun.tools.classfile") + "jdk.compiler/com.sun.tools.javac.util") .forEach(p -> open(p, targetModule)); var createSymbolsClass = Class.forName("build.tools.symbolgenerator.CreateSymbols", false, cl); diff --git a/test/langtools/tools/javac/platform/createsymbols/CreateSymbolsTest.java b/test/langtools/tools/javac/platform/createsymbols/CreateSymbolsTest.java index 97def1b148003..76c13582b73cd 100644 --- a/test/langtools/tools/javac/platform/createsymbols/CreateSymbolsTest.java +++ b/test/langtools/tools/javac/platform/createsymbols/CreateSymbolsTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2025, 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 @@ -30,7 +30,6 @@ * jdk.compiler/com.sun.tools.javac.jvm * jdk.compiler/com.sun.tools.javac.main * jdk.compiler/com.sun.tools.javac.util - * jdk.jdeps/com.sun.tools.classfile * @clean * * @run main/othervm CreateSymbolsTest */ @@ -107,8 +106,7 @@ void doRun() throws Exception { "--add-exports", "jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED", "--add-exports", "jdk.compiler/com.sun.tools.javac.jvm=ALL-UNNAMED", "--add-exports", "jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED", - "--add-exports", "jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED", - "--add-exports", "jdk.jdeps/com.sun.tools.classfile=ALL-UNNAMED"), + "--add-exports", "jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED"), null, fm.getJavaFileObjectsFromPaths(files) ).call(); From 3c6d3a69849716e7a6ef6057ea56d57f321d3aae Mon Sep 17 00:00:00 2001 From: liach Date: Tue, 25 Mar 2025 15:06:06 -0500 Subject: [PATCH 2/4] FieldDescription.constantValue uses Integer for byte and short --- .../build/tools/symbolgenerator/CreateSymbols.java | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/make/langtools/src/classes/build/tools/symbolgenerator/CreateSymbols.java b/make/langtools/src/classes/build/tools/symbolgenerator/CreateSymbols.java index 03553c24034bb..46d43857e37ff 100644 --- a/make/langtools/src/classes/build/tools/symbolgenerator/CreateSymbols.java +++ b/make/langtools/src/classes/build/tools/symbolgenerator/CreateSymbols.java @@ -955,9 +955,7 @@ private void addAttributes(FieldDescription desc, FieldBuilder builder) { var cp = builder.constantPool(); ConstantValueEntry entry = switch (desc.constantValue) { case Boolean v -> cp.intEntry(v ? 1 : 0); - case Byte v -> cp.intEntry(v); case Character v -> cp.intEntry(v); - case Short v -> cp.intEntry(v); case Integer v -> cp.intEntry(v); case Long v -> cp.longEntry(v); case Float v -> cp.floatEntry(v); @@ -2224,10 +2222,8 @@ Object convertConstantValue(ConstantValueEntry info, String descriptor) { if (descriptor.length() == 1 && info instanceof IntegerEntry ie) { var i = ie.intValue(); return switch (descriptor.charAt(0)) { - case 'I' -> i; - case 'B' -> (byte) i; + case 'I', 'B', 'S' -> i; case 'C' -> (char) i; - case 'S' -> (short) i; case 'Z' -> i == 1; default -> throw new IllegalArgumentException(descriptor); }; @@ -3431,7 +3427,7 @@ public MethodParam(int flags, String name) { static class FieldDescription extends FeatureDescription { String name; String descriptor; - Object constantValue; + Object constantValue; // Uses (unsigned) Integer for byte/short String keyName = "field"; @Override From b9b4509e0b7393a898ea3517bb7d1c5e1d353467 Mon Sep 17 00:00:00 2001 From: liach Date: Tue, 25 Mar 2025 15:27:00 -0500 Subject: [PATCH 3/4] Other references to remove --- .../src/classes/build/tools/symbolgenerator/CreateSymbols.java | 3 +-- make/modules/jdk.compiler/Gendata.gmk | 1 - make/scripts/generate-symbol-data.sh | 3 +-- 3 files changed, 2 insertions(+), 5 deletions(-) diff --git a/make/langtools/src/classes/build/tools/symbolgenerator/CreateSymbols.java b/make/langtools/src/classes/build/tools/symbolgenerator/CreateSymbols.java index 46d43857e37ff..db8924c79fbf4 100644 --- a/make/langtools/src/classes/build/tools/symbolgenerator/CreateSymbols.java +++ b/make/langtools/src/classes/build/tools/symbolgenerator/CreateSymbols.java @@ -117,8 +117,7 @@ * * To add historical data for JDK N, N >= 11, do the following: * * cd /src/jdk.compiler/share/data/symbols - * * /bin/java --add-exports jdk.jdeps/com.sun.tools.classfile=ALL-UNNAMED \ - * --add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED \ + * * /bin/java --add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED \ * --add-exports jdk.compiler/com.sun.tools.javac.jvm=ALL-UNNAMED \ * --add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED \ * --add-modules jdk.jdeps \ diff --git a/make/modules/jdk.compiler/Gendata.gmk b/make/modules/jdk.compiler/Gendata.gmk index 739625a5732a1..5bbd28b803794 100644 --- a/make/modules/jdk.compiler/Gendata.gmk +++ b/make/modules/jdk.compiler/Gendata.gmk @@ -53,7 +53,6 @@ COMPILECREATESYMBOLS_ADD_EXPORTS := \ --add-exports jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED \ --add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED \ --add-exports jdk.compiler/com.sun.tools.javac.jvm=ALL-UNNAMED \ - --add-exports jdk.jdeps/com.sun.tools.classfile=ALL-UNNAMED \ # # TODO: Unify with jdk.javadoc-gendata. Should only compile this once and share. diff --git a/make/scripts/generate-symbol-data.sh b/make/scripts/generate-symbol-data.sh index 015beb582fdaf..6f38d8730093c 100644 --- a/make/scripts/generate-symbol-data.sh +++ b/make/scripts/generate-symbol-data.sh @@ -68,8 +68,7 @@ if [ "`git status --porcelain=v1 .`x" != "x" ] ; then exit 1 fi; -$1/bin/java --add-exports jdk.jdeps/com.sun.tools.classfile=ALL-UNNAMED \ - --add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED \ +$1/bin/java --add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED \ --add-exports jdk.compiler/com.sun.tools.javac.jvm=ALL-UNNAMED \ --add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED \ --add-modules jdk.jdeps \ From ba2ce182abf7d76ed313f0c94530d952e3f0121d Mon Sep 17 00:00:00 2001 From: liach Date: Tue, 8 Apr 2025 15:07:46 -0500 Subject: [PATCH 4/4] 8352748: Remove com.sun.tools.classfile from the JDK --- make/modules/jdk.compiler/Gendata.gmk | 2 +- make/modules/jdk.javadoc/Gendata.gmk | 2 +- .../com/sun/tools/javac/code/TargetType.java | 3 +- .../javac/code/TypeAnnotationPosition.java | 3 +- .../com/sun/tools/classfile/AccessFlags.java | 259 ---- .../com/sun/tools/classfile/Annotation.java | 276 ----- .../AnnotationDefault_attribute.java | 61 - .../com/sun/tools/classfile/Attribute.java | 222 ---- .../tools/classfile/AttributeException.java | 41 - .../com/sun/tools/classfile/Attributes.java | 112 -- .../classfile/BootstrapMethods_attribute.java | 90 -- .../CharacterRangeTable_attribute.java | 90 -- .../com/sun/tools/classfile/ClassFile.java | 189 --- .../com/sun/tools/classfile/ClassReader.java | 115 -- .../sun/tools/classfile/ClassTranslator.java | 469 -------- .../com/sun/tools/classfile/ClassWriter.java | 1011 ---------------- .../sun/tools/classfile/Code_attribute.java | 154 --- .../classfile/CompilationID_attribute.java | 63 - .../com/sun/tools/classfile/ConstantPool.java | 1053 ----------------- .../classfile/ConstantPoolException.java | 41 - .../classfile/ConstantValue_attribute.java | 59 - .../sun/tools/classfile/DefaultAttribute.java | 64 - .../tools/classfile/Deprecated_attribute.java | 55 - .../com/sun/tools/classfile/Descriptor.java | 198 ---- .../tools/classfile/DescriptorException.java | 36 - .../classfile/EnclosingMethod_attribute.java | 73 -- .../tools/classfile/Exceptions_attribute.java | 69 -- .../com/sun/tools/classfile/FatalError.java | 40 - .../com/sun/tools/classfile/Field.java | 65 - .../classfile/InnerClasses_attribute.java | 109 -- .../com/sun/tools/classfile/Instruction.java | 357 ------ .../classfile/LineNumberTable_attribute.java | 78 -- .../LocalVariableTable_attribute.java | 84 -- .../LocalVariableTypeTable_attribute.java | 84 -- .../com/sun/tools/classfile/Method.java | 65 - .../classfile/MethodParameters_attribute.java | 92 -- .../classfile/ModuleHashes_attribute.java | 95 -- .../classfile/ModuleMainClass_attribute.java | 64 - .../classfile/ModulePackages_attribute.java | 77 -- .../classfile/ModuleResolution_attribute.java | 69 -- .../classfile/ModuleTarget_attribute.java | 55 - .../sun/tools/classfile/Module_attribute.java | 230 ---- .../tools/classfile/NestHost_attribute.java | 63 - .../classfile/NestMembers_attribute.java | 70 -- .../com/sun/tools/classfile/Opcode.java | 472 -------- .../PermittedSubclasses_attribute.java | 65 - .../sun/tools/classfile/Record_attribute.java | 82 -- .../sun/tools/classfile/ReferenceFinder.java | 253 ---- .../RuntimeAnnotations_attribute.java | 61 - ...RuntimeInvisibleAnnotations_attribute.java | 56 - ...visibleParameterAnnotations_attribute.java | 56 - ...imeInvisibleTypeAnnotations_attribute.java | 56 - ...RuntimeParameterAnnotations_attribute.java | 70 -- .../RuntimeTypeAnnotations_attribute.java | 61 - .../RuntimeVisibleAnnotations_attribute.java | 56 - ...VisibleParameterAnnotations_attribute.java | 56 - ...ntimeVisibleTypeAnnotations_attribute.java | 56 - .../com/sun/tools/classfile/Signature.java | 272 ----- .../tools/classfile/Signature_attribute.java | 67 -- .../SourceDebugExtension_attribute.java | 69 -- .../tools/classfile/SourceFile_attribute.java | 63 - .../tools/classfile/SourceID_attribute.java | 62 - .../classfile/StackMapTable_attribute.java | 380 ------ .../tools/classfile/StackMap_attribute.java | 70 -- .../tools/classfile/Synthetic_attribute.java | 55 - .../classes/com/sun/tools/classfile/Type.java | 378 ------ .../sun/tools/classfile/TypeAnnotation.java | 654 ---------- .../com/sun/tools/classfile/package-info.java | 36 - src/jdk.jdeps/share/classes/module-info.java | 4 +- ...ildcardBoundsNotReadFromClassFileTest.java | 4 +- 70 files changed, 6 insertions(+), 10015 deletions(-) delete mode 100644 src/jdk.jdeps/share/classes/com/sun/tools/classfile/AccessFlags.java delete mode 100644 src/jdk.jdeps/share/classes/com/sun/tools/classfile/Annotation.java delete mode 100644 src/jdk.jdeps/share/classes/com/sun/tools/classfile/AnnotationDefault_attribute.java delete mode 100644 src/jdk.jdeps/share/classes/com/sun/tools/classfile/Attribute.java delete mode 100644 src/jdk.jdeps/share/classes/com/sun/tools/classfile/AttributeException.java delete mode 100644 src/jdk.jdeps/share/classes/com/sun/tools/classfile/Attributes.java delete mode 100644 src/jdk.jdeps/share/classes/com/sun/tools/classfile/BootstrapMethods_attribute.java delete mode 100644 src/jdk.jdeps/share/classes/com/sun/tools/classfile/CharacterRangeTable_attribute.java delete mode 100644 src/jdk.jdeps/share/classes/com/sun/tools/classfile/ClassFile.java delete mode 100644 src/jdk.jdeps/share/classes/com/sun/tools/classfile/ClassReader.java delete mode 100644 src/jdk.jdeps/share/classes/com/sun/tools/classfile/ClassTranslator.java delete mode 100644 src/jdk.jdeps/share/classes/com/sun/tools/classfile/ClassWriter.java delete mode 100644 src/jdk.jdeps/share/classes/com/sun/tools/classfile/Code_attribute.java delete mode 100644 src/jdk.jdeps/share/classes/com/sun/tools/classfile/CompilationID_attribute.java delete mode 100644 src/jdk.jdeps/share/classes/com/sun/tools/classfile/ConstantPool.java delete mode 100644 src/jdk.jdeps/share/classes/com/sun/tools/classfile/ConstantPoolException.java delete mode 100644 src/jdk.jdeps/share/classes/com/sun/tools/classfile/ConstantValue_attribute.java delete mode 100644 src/jdk.jdeps/share/classes/com/sun/tools/classfile/DefaultAttribute.java delete mode 100644 src/jdk.jdeps/share/classes/com/sun/tools/classfile/Deprecated_attribute.java delete mode 100644 src/jdk.jdeps/share/classes/com/sun/tools/classfile/Descriptor.java delete mode 100644 src/jdk.jdeps/share/classes/com/sun/tools/classfile/DescriptorException.java delete mode 100644 src/jdk.jdeps/share/classes/com/sun/tools/classfile/EnclosingMethod_attribute.java delete mode 100644 src/jdk.jdeps/share/classes/com/sun/tools/classfile/Exceptions_attribute.java delete mode 100644 src/jdk.jdeps/share/classes/com/sun/tools/classfile/FatalError.java delete mode 100644 src/jdk.jdeps/share/classes/com/sun/tools/classfile/Field.java delete mode 100644 src/jdk.jdeps/share/classes/com/sun/tools/classfile/InnerClasses_attribute.java delete mode 100644 src/jdk.jdeps/share/classes/com/sun/tools/classfile/Instruction.java delete mode 100644 src/jdk.jdeps/share/classes/com/sun/tools/classfile/LineNumberTable_attribute.java delete mode 100644 src/jdk.jdeps/share/classes/com/sun/tools/classfile/LocalVariableTable_attribute.java delete mode 100644 src/jdk.jdeps/share/classes/com/sun/tools/classfile/LocalVariableTypeTable_attribute.java delete mode 100644 src/jdk.jdeps/share/classes/com/sun/tools/classfile/Method.java delete mode 100644 src/jdk.jdeps/share/classes/com/sun/tools/classfile/MethodParameters_attribute.java delete mode 100644 src/jdk.jdeps/share/classes/com/sun/tools/classfile/ModuleHashes_attribute.java delete mode 100644 src/jdk.jdeps/share/classes/com/sun/tools/classfile/ModuleMainClass_attribute.java delete mode 100644 src/jdk.jdeps/share/classes/com/sun/tools/classfile/ModulePackages_attribute.java delete mode 100644 src/jdk.jdeps/share/classes/com/sun/tools/classfile/ModuleResolution_attribute.java delete mode 100644 src/jdk.jdeps/share/classes/com/sun/tools/classfile/ModuleTarget_attribute.java delete mode 100644 src/jdk.jdeps/share/classes/com/sun/tools/classfile/Module_attribute.java delete mode 100644 src/jdk.jdeps/share/classes/com/sun/tools/classfile/NestHost_attribute.java delete mode 100644 src/jdk.jdeps/share/classes/com/sun/tools/classfile/NestMembers_attribute.java delete mode 100644 src/jdk.jdeps/share/classes/com/sun/tools/classfile/Opcode.java delete mode 100644 src/jdk.jdeps/share/classes/com/sun/tools/classfile/PermittedSubclasses_attribute.java delete mode 100644 src/jdk.jdeps/share/classes/com/sun/tools/classfile/Record_attribute.java delete mode 100644 src/jdk.jdeps/share/classes/com/sun/tools/classfile/ReferenceFinder.java delete mode 100644 src/jdk.jdeps/share/classes/com/sun/tools/classfile/RuntimeAnnotations_attribute.java delete mode 100644 src/jdk.jdeps/share/classes/com/sun/tools/classfile/RuntimeInvisibleAnnotations_attribute.java delete mode 100644 src/jdk.jdeps/share/classes/com/sun/tools/classfile/RuntimeInvisibleParameterAnnotations_attribute.java delete mode 100644 src/jdk.jdeps/share/classes/com/sun/tools/classfile/RuntimeInvisibleTypeAnnotations_attribute.java delete mode 100644 src/jdk.jdeps/share/classes/com/sun/tools/classfile/RuntimeParameterAnnotations_attribute.java delete mode 100644 src/jdk.jdeps/share/classes/com/sun/tools/classfile/RuntimeTypeAnnotations_attribute.java delete mode 100644 src/jdk.jdeps/share/classes/com/sun/tools/classfile/RuntimeVisibleAnnotations_attribute.java delete mode 100644 src/jdk.jdeps/share/classes/com/sun/tools/classfile/RuntimeVisibleParameterAnnotations_attribute.java delete mode 100644 src/jdk.jdeps/share/classes/com/sun/tools/classfile/RuntimeVisibleTypeAnnotations_attribute.java delete mode 100644 src/jdk.jdeps/share/classes/com/sun/tools/classfile/Signature.java delete mode 100644 src/jdk.jdeps/share/classes/com/sun/tools/classfile/Signature_attribute.java delete mode 100644 src/jdk.jdeps/share/classes/com/sun/tools/classfile/SourceDebugExtension_attribute.java delete mode 100644 src/jdk.jdeps/share/classes/com/sun/tools/classfile/SourceFile_attribute.java delete mode 100644 src/jdk.jdeps/share/classes/com/sun/tools/classfile/SourceID_attribute.java delete mode 100644 src/jdk.jdeps/share/classes/com/sun/tools/classfile/StackMapTable_attribute.java delete mode 100644 src/jdk.jdeps/share/classes/com/sun/tools/classfile/StackMap_attribute.java delete mode 100644 src/jdk.jdeps/share/classes/com/sun/tools/classfile/Synthetic_attribute.java delete mode 100644 src/jdk.jdeps/share/classes/com/sun/tools/classfile/Type.java delete mode 100644 src/jdk.jdeps/share/classes/com/sun/tools/classfile/TypeAnnotation.java delete mode 100644 src/jdk.jdeps/share/classes/com/sun/tools/classfile/package-info.java diff --git a/make/modules/jdk.compiler/Gendata.gmk b/make/modules/jdk.compiler/Gendata.gmk index 5bbd28b803794..2afc6e98e3791 100644 --- a/make/modules/jdk.compiler/Gendata.gmk +++ b/make/modules/jdk.compiler/Gendata.gmk @@ -60,7 +60,7 @@ $(eval $(call SetupJavaCompilation, COMPILE_CREATE_SYMBOLS, \ TARGET_RELEASE := $(TARGET_RELEASE_NEWJDK), \ COMPILER := buildjdk, \ SRC := $(TOPDIR)/make/langtools/src/classes, \ - INCLUDES := build/tools/symbolgenerator com/sun/tools/classfile, \ + INCLUDES := build/tools/symbolgenerator, \ BIN := $(BUILDTOOLS_OUTPUTDIR)/create_symbols_javac, \ DISABLED_WARNINGS := options, \ JAVAC_FLAGS := \ diff --git a/make/modules/jdk.javadoc/Gendata.gmk b/make/modules/jdk.javadoc/Gendata.gmk index 2cd812de779ef..a97342ffd049e 100644 --- a/make/modules/jdk.javadoc/Gendata.gmk +++ b/make/modules/jdk.javadoc/Gendata.gmk @@ -51,7 +51,7 @@ $(eval $(call SetupJavaCompilation, COMPILE_CREATE_SYMBOLS, \ TARGET_RELEASE := $(TARGET_RELEASE_BOOTJDK), \ SRC := $(TOPDIR)/make/langtools/src/classes \ $(TOPDIR)/src/jdk.jdeps/share/classes, \ - INCLUDES := build/tools/symbolgenerator com/sun/tools/classfile, \ + INCLUDES := build/tools/symbolgenerator, \ BIN := $(BUILDTOOLS_OUTPUTDIR)/create_symbols_javadoc, \ DISABLED_WARNINGS := options, \ JAVAC_FLAGS := \ diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/code/TargetType.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/code/TargetType.java index 0876749335472..bdb08091aa5ab 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/code/TargetType.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/code/TargetType.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2008, 2025, 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 @@ -41,7 +41,6 @@ * This code and its internal interfaces are subject to change or * deletion without notice. */ -// Code duplicated in com.sun.tools.classfile.TypeAnnotation.TargetType public enum TargetType { /** For annotations on a class type parameter declaration. */ CLASS_TYPE_PARAMETER(0x00), diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/code/TypeAnnotationPosition.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/code/TypeAnnotationPosition.java index 92fe41adb5b0e..8c88dec51063f 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/code/TypeAnnotationPosition.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/code/TypeAnnotationPosition.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2025, 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 @@ -37,7 +37,6 @@ * This code and its internal interfaces are subject to change or * deletion without notice. */ -// Code duplicated in com.sun.tools.classfile.TypeAnnotation.Position public class TypeAnnotationPosition { public enum TypePathEntryKind { diff --git a/src/jdk.jdeps/share/classes/com/sun/tools/classfile/AccessFlags.java b/src/jdk.jdeps/share/classes/com/sun/tools/classfile/AccessFlags.java deleted file mode 100644 index 5e9b6853a4d72..0000000000000 --- a/src/jdk.jdeps/share/classes/com/sun/tools/classfile/AccessFlags.java +++ /dev/null @@ -1,259 +0,0 @@ -/* - * Copyright (c) 2007, 2015, 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. - * - *

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. - */ -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; // method parameter - public static final int ACC_MODULE = 0x8000; // class - - 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, ACC_MODULE - }; - - public Set getClassModifiers() { - int f = ((flags & ACC_INTERFACE) != 0 ? flags & ~ACC_ABSTRACT : flags); - return getModifiers(f, classModifiers, Kind.Class); - } - - public Set 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 getInnerClassModifiers() { - int f = ((flags & ACC_INTERFACE) != 0 ? flags & ~ACC_ABSTRACT : flags); - return getModifiers(f, innerClassModifiers, Kind.InnerClass); - } - - public Set 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 getFieldModifiers() { - return getModifiers(fieldModifiers, Kind.Field); - } - - public Set 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 getMethodModifiers() { - return getModifiers(methodModifiers, Kind.Method); - } - - public Set getMethodFlags() { - return getFlags(methodFlags, Kind.Method); - } - - private Set getModifiers(int[] modifierFlags, Kind t) { - return getModifiers(flags, modifierFlags, t); - } - - private static Set getModifiers(int flags, int[] modifierFlags, Kind t) { - Set s = new LinkedHashSet<>(); - for (int m: modifierFlags) { - if ((flags & m) != 0) - s.add(flagToModifier(m, t)); - } - return s; - } - - private Set getFlags(int[] expectedFlags, Kind t) { - Set 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 0x8000: - return (t == Kind.Class ? "ACC_MODULE" : "ACC_MANDATED"); - default: - return null; - } - } - - public final int flags; -} diff --git a/src/jdk.jdeps/share/classes/com/sun/tools/classfile/Annotation.java b/src/jdk.jdeps/share/classes/com/sun/tools/classfile/Annotation.java deleted file mode 100644 index caf148944ab87..0000000000000 --- a/src/jdk.jdeps/share/classes/com/sun/tools/classfile/Annotation.java +++ /dev/null @@ -1,276 +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. - * - *

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. - */ -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 abstract static 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 accept(Visitor visitor, P p); - - public interface Visitor { - 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(); - } - - public Primitive_element_value(int const_value_index, int tag) { - super(tag); - this.const_value_index = const_value_index; - } - - @Override - public int length() { - return 2; - } - - public R accept(Visitor 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(); - } - - public Enum_element_value(int type_name_index, int const_name_index, int tag) { - super(tag); - this.type_name_index = type_name_index; - this.const_name_index = const_name_index; - } - - @Override - public int length() { - return 4; - } - - public R accept(Visitor 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(); - } - - public Class_element_value(int class_info_index, int tag) { - super(tag); - this.class_info_index = class_info_index; - } - - @Override - public int length() { - return 2; - } - - public R accept(Visitor 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); - } - - public Annotation_element_value(Annotation annotation_value, int tag) { - super(tag); - this.annotation_value = annotation_value; - } - - @Override - public int length() { - return annotation_value.length(); - } - - public R accept(Visitor 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); - } - - public Array_element_value(element_value[] values, int tag) { - super(tag); - this.num_values = values.length; - this.values = values; - } - - @Override - public int length() { - int n = 2; - for (int i = 0; i < values.length; i++) - n += values[i].length(); - return n; - } - - public R accept(Visitor 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 element_value_pair(int element_name_index, element_value value) { - this.element_name_index = element_name_index; - this.value = value; - } - - public int length() { - return 2 + value.length(); - } - - public final int element_name_index; - public final element_value value; - } -} diff --git a/src/jdk.jdeps/share/classes/com/sun/tools/classfile/AnnotationDefault_attribute.java b/src/jdk.jdeps/share/classes/com/sun/tools/classfile/AnnotationDefault_attribute.java deleted file mode 100644 index 1ca7fc4565c2d..0000000000000 --- a/src/jdk.jdeps/share/classes/com/sun/tools/classfile/AnnotationDefault_attribute.java +++ /dev/null @@ -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. - * - *

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. - */ -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 accept(Visitor visitor, D data) { - return visitor.visitAnnotationDefault(this, data); - } - - public final Annotation.element_value default_value; -} - diff --git a/src/jdk.jdeps/share/classes/com/sun/tools/classfile/Attribute.java b/src/jdk.jdeps/share/classes/com/sun/tools/classfile/Attribute.java deleted file mode 100644 index 3ab3fce1863b8..0000000000000 --- a/src/jdk.jdeps/share/classes/com/sun/tools/classfile/Attribute.java +++ /dev/null @@ -1,222 +0,0 @@ -/* - * Copyright (c) 2007, 2020, 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; - -/** - *

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. - */ - -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 Module = "Module"; - public static final String ModuleHashes = "ModuleHashes"; - public static final String ModuleMainClass = "ModuleMainClass"; - public static final String ModulePackages = "ModulePackages"; - public static final String ModuleResolution = "ModuleResolution"; - public static final String ModuleTarget = "ModuleTarget"; - public static final String NestHost = "NestHost"; - public static final String NestMembers = "NestMembers"; - public static final String Record = "Record"; - 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 PermittedSubclasses = "PermittedSubclasses"; - 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 attrClass = standardAttributes.get(name); - if (attrClass != null) { - try { - Class[] constrArgTypes = {ClassReader.class, int.class, int.class}; - Constructor 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(Module, Module_attribute.class); - standardAttributes.put(ModuleHashes, ModuleHashes_attribute.class); - standardAttributes.put(ModuleMainClass, ModuleMainClass_attribute.class); - standardAttributes.put(ModulePackages, ModulePackages_attribute.class); - standardAttributes.put(ModuleResolution, ModuleResolution_attribute.class); - standardAttributes.put(ModuleTarget, ModuleTarget_attribute.class); - standardAttributes.put(NestHost, NestHost_attribute.class); - standardAttributes.put(NestMembers, NestMembers_attribute.class); - standardAttributes.put(Record, Record_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(PermittedSubclasses, PermittedSubclasses_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> 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 accept(Attribute.Visitor 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 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 visitModule(Module_attribute attr, P p); - R visitModuleHashes(ModuleHashes_attribute attr, P p); - R visitModuleMainClass(ModuleMainClass_attribute attr, P p); - R visitModulePackages(ModulePackages_attribute attr, P p); - R visitModuleResolution(ModuleResolution_attribute attr, P p); - R visitModuleTarget(ModuleTarget_attribute attr, P p); - R visitNestHost(NestHost_attribute attr, P p); - R visitNestMembers(NestMembers_attribute attr, P p); - R visitRecord(Record_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 visitPermittedSubclasses(PermittedSubclasses_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); - } -} diff --git a/src/jdk.jdeps/share/classes/com/sun/tools/classfile/AttributeException.java b/src/jdk.jdeps/share/classes/com/sun/tools/classfile/AttributeException.java deleted file mode 100644 index a4682c02515ef..0000000000000 --- a/src/jdk.jdeps/share/classes/com/sun/tools/classfile/AttributeException.java +++ /dev/null @@ -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; - -/* - *

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. - */ -public class AttributeException extends Exception { - private static final long serialVersionUID = -4231486387714867770L; - AttributeException() { } - - AttributeException(String msg) { - super(msg); - } -} diff --git a/src/jdk.jdeps/share/classes/com/sun/tools/classfile/Attributes.java b/src/jdk.jdeps/share/classes/com/sun/tools/classfile/Attributes.java deleted file mode 100644 index 0bc75ac1a248a..0000000000000 --- a/src/jdk.jdeps/share/classes/com/sun/tools/classfile/Attributes.java +++ /dev/null @@ -1,112 +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; - -/* - *

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. - */ -public class Attributes implements Iterable { - - public final Attribute[] attrs; - public final Map 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 Attributes(Map attributes) { - this.attrs = attributes.values().toArray(new Attribute[attributes.size()]); - map = attributes; - } - - public Iterator 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; - } -} diff --git a/src/jdk.jdeps/share/classes/com/sun/tools/classfile/BootstrapMethods_attribute.java b/src/jdk.jdeps/share/classes/com/sun/tools/classfile/BootstrapMethods_attribute.java deleted file mode 100644 index 69d034788cc0b..0000000000000 --- a/src/jdk.jdeps/share/classes/com/sun/tools/classfile/BootstrapMethods_attribute.java +++ /dev/null @@ -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 - * - *

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. - */ -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 accept(Visitor 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); - } - } -} diff --git a/src/jdk.jdeps/share/classes/com/sun/tools/classfile/CharacterRangeTable_attribute.java b/src/jdk.jdeps/share/classes/com/sun/tools/classfile/CharacterRangeTable_attribute.java deleted file mode 100644 index 2b1425789f40a..0000000000000 --- a/src/jdk.jdeps/share/classes/com/sun/tools/classfile/CharacterRangeTable_attribute.java +++ /dev/null @@ -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; - -/** - *

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. - */ -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 accept(Visitor 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; - } -} diff --git a/src/jdk.jdeps/share/classes/com/sun/tools/classfile/ClassFile.java b/src/jdk.jdeps/share/classes/com/sun/tools/classfile/ClassFile.java deleted file mode 100644 index 52aefca546971..0000000000000 --- a/src/jdk.jdeps/share/classes/com/sun/tools/classfile/ClassFile.java +++ /dev/null @@ -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. - * - *

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. - */ -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; -} diff --git a/src/jdk.jdeps/share/classes/com/sun/tools/classfile/ClassReader.java b/src/jdk.jdeps/share/classes/com/sun/tools/classfile/ClassReader.java deleted file mode 100644 index 6511d0f905c09..0000000000000 --- a/src/jdk.jdeps/share/classes/com/sun/tools/classfile/ClassReader.java +++ /dev/null @@ -1,115 +0,0 @@ -/* - * Copyright (c) 2007, 2020, 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; - -/** - *

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. - */ -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(); - if (length < 0) { // we have an overflow as max_value(u4) > max_value(int) - String attrName; - try { - attrName = getConstantPool().getUTF8Value(name_index); - } catch (ConstantPool.InvalidIndex | ConstantPool.UnexpectedEntry e) { - attrName = ""; - } - throw new FatalError(String.format("attribute %s too big to handle", attrName)); - } - 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; -} diff --git a/src/jdk.jdeps/share/classes/com/sun/tools/classfile/ClassTranslator.java b/src/jdk.jdeps/share/classes/com/sun/tools/classfile/ClassTranslator.java deleted file mode 100644 index 2725fc3d41861..0000000000000 --- a/src/jdk.jdeps/share/classes/com/sun/tools/classfile/ClassTranslator.java +++ /dev/null @@ -1,469 +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_Dynamic_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_Module_info; -import com.sun.tools.classfile.ConstantPool.CONSTANT_NameAndType_info; -import com.sun.tools.classfile.ConstantPool.CONSTANT_Package_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. - * - *

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. - */ -public class ClassTranslator - implements ConstantPool.Visitor> { - /** - * 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 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 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 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 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 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 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 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 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 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 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; - } - - @Override - public CPInfo visitClass(CONSTANT_Class_info info, Map 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; - } - - @Override - public CPInfo visitDouble(CONSTANT_Double_info info, Map translations) { - CONSTANT_Double_info info2 = (CONSTANT_Double_info) translations.get(info); - if (info2 == null) { - info2 = info; - translations.put(info, info2); - } - return info; - } - - @Override - public CPInfo visitFieldref(CONSTANT_Fieldref_info info, Map 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; - } - - @Override - public CPInfo visitFloat(CONSTANT_Float_info info, Map translations) { - CONSTANT_Float_info info2 = (CONSTANT_Float_info) translations.get(info); - if (info2 == null) { - info2 = info; - translations.put(info, info2); - } - return info; - } - - @Override - public CPInfo visitInteger(CONSTANT_Integer_info info, Map translations) { - CONSTANT_Integer_info info2 = (CONSTANT_Integer_info) translations.get(info); - if (info2 == null) { - info2 = info; - translations.put(info, info2); - } - return info; - } - - @Override - public CPInfo visitInterfaceMethodref(CONSTANT_InterfaceMethodref_info info, Map 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; - } - - @Override - public CPInfo visitInvokeDynamic(CONSTANT_InvokeDynamic_info info, Map 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 visitDynamicConstant(CONSTANT_Dynamic_info info, Map translations) { - CONSTANT_Dynamic_info info2 = (CONSTANT_Dynamic_info) translations.get(info); - if (info2 == null) { - ConstantPool cp2 = translate(info.cp, translations); - if (cp2 == info.cp) { - info2 = info; - } else { - info2 = new CONSTANT_Dynamic_info(cp2, info.bootstrap_method_attr_index, info.name_and_type_index); - } - translations.put(info, info2); - } - return info; - } - - @Override - public CPInfo visitLong(CONSTANT_Long_info info, Map translations) { - CONSTANT_Long_info info2 = (CONSTANT_Long_info) translations.get(info); - if (info2 == null) { - info2 = info; - translations.put(info, info2); - } - return info; - } - - @Override - public CPInfo visitMethodref(CONSTANT_Methodref_info info, Map 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; - } - - @Override - public CPInfo visitMethodHandle(CONSTANT_MethodHandle_info info, Map 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; - } - - @Override - public CPInfo visitMethodType(CONSTANT_MethodType_info info, Map 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; - } - - @Override - public CPInfo visitModule(CONSTANT_Module_info info, Map translations) { - CONSTANT_Module_info info2 = (CONSTANT_Module_info) translations.get(info); - if (info2 == null) { - ConstantPool cp2 = translate(info.cp, translations); - if (cp2 == info.cp) - info2 = info; - else - info2 = new CONSTANT_Module_info(cp2, info.name_index); - translations.put(info, info2); - } - return info; - } - - @Override - public CPInfo visitNameAndType(CONSTANT_NameAndType_info info, Map 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; - } - - @Override - public CPInfo visitPackage(CONSTANT_Package_info info, Map translations) { - CONSTANT_Package_info info2 = (CONSTANT_Package_info) translations.get(info); - if (info2 == null) { - ConstantPool cp2 = translate(info.cp, translations); - if (cp2 == info.cp) - info2 = info; - else - info2 = new CONSTANT_Package_info(cp2, info.name_index); - translations.put(info, info2); - } - return info; - } - - @Override - public CPInfo visitString(CONSTANT_String_info info, Map 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; - } - - @Override - public CPInfo visitUtf8(CONSTANT_Utf8_info info, Map translations) { - CONSTANT_Utf8_info info2 = (CONSTANT_Utf8_info) translations.get(info); - if (info2 == null) { - info2 = info; - translations.put(info, info2); - } - return info; - } - -} diff --git a/src/jdk.jdeps/share/classes/com/sun/tools/classfile/ClassWriter.java b/src/jdk.jdeps/share/classes/com/sun/tools/classfile/ClassWriter.java deleted file mode 100644 index a24fb837f4309..0000000000000 --- a/src/jdk.jdeps/share/classes/com/sun/tools/classfile/ClassWriter.java +++ /dev/null @@ -1,1011 +0,0 @@ -/* - * Copyright (c) 2008, 2020, 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. - * - *

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. - */ -public class ClassWriter { - public ClassWriter() { - attributeWriter = new AttributeWriter(); - constantPoolWriter = new ConstantPoolWriter(); - out = new ClassOutputStream(); - } - - /** - * Write a ClassFile data structure to a file. - * @param classFile the classfile object to be written - * @param f the file - * @throws IOException if an error occurs while writing the 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. - * @param classFile the classfile object to be written - * @param s the stream - * @throws IOException if an error occurs while writing the file - */ - 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 final DataOutputStream d; - } - - /** - * Writer for the entries in the constant pool. - */ - protected static class ConstantPoolWriter - implements ConstantPool.Visitor { - protected int write(CPInfo info, ClassOutputStream out) { - out.writeByte(info.getTag()); - return info.accept(this, out); - } - - @Override - public Integer visitClass(CONSTANT_Class_info info, ClassOutputStream out) { - out.writeShort(info.name_index); - return 1; - } - - @Override - public Integer visitDouble(CONSTANT_Double_info info, ClassOutputStream out) { - out.writeDouble(info.value); - return 2; - } - - @Override - public Integer visitFieldref(CONSTANT_Fieldref_info info, ClassOutputStream out) { - writeRef(info, out); - return 1; - } - - @Override - public Integer visitFloat(CONSTANT_Float_info info, ClassOutputStream out) { - out.writeFloat(info.value); - return 1; - } - - @Override - public Integer visitInteger(CONSTANT_Integer_info info, ClassOutputStream out) { - out.writeInt(info.value); - return 1; - } - - @Override - public Integer visitInterfaceMethodref(CONSTANT_InterfaceMethodref_info info, ClassOutputStream out) { - writeRef(info, out); - return 1; - } - - @Override - 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 visitDynamicConstant(CONSTANT_Dynamic_info info, ClassOutputStream out) { - out.writeShort(info.bootstrap_method_attr_index); - out.writeShort(info.name_and_type_index); - return 1; - } - - @Override - public Integer visitLong(CONSTANT_Long_info info, ClassOutputStream out) { - out.writeLong(info.value); - return 2; - } - - @Override - public Integer visitMethodHandle(CONSTANT_MethodHandle_info info, ClassOutputStream out) { - out.writeByte(info.reference_kind.tag); - out.writeShort(info.reference_index); - return 1; - } - - @Override - public Integer visitMethodType(CONSTANT_MethodType_info info, ClassOutputStream out) { - out.writeShort(info.descriptor_index); - return 1; - } - - @Override - public Integer visitMethodref(CONSTANT_Methodref_info info, ClassOutputStream out) { - return writeRef(info, out); - } - - @Override - public Integer visitModule(CONSTANT_Module_info info, ClassOutputStream out) { - out.writeShort(info.name_index); - return 1; - } - - @Override - public Integer visitNameAndType(CONSTANT_NameAndType_info info, ClassOutputStream out) { - out.writeShort(info.name_index); - out.writeShort(info.type_index); - return 1; - } - - @Override - public Integer visitPackage(CONSTANT_Package_info info, ClassOutputStream out) { - out.writeShort(info.name_index); - return 1; - } - - @Override - public Integer visitString(CONSTANT_String_info info, ClassOutputStream out) { - out.writeShort(info.string_index); - return 1; - } - - @Override - 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 { - public void write(Attributes attributes, ClassOutputStream out) { - int size = attributes.size(); - out.writeShort(size); - for (Attribute a: attributes) - write(a, out); - } - - public void write(Attribute attr, ClassOutputStream out) { - out.writeShort(attr.attribute_name_index); - ClassOutputStream nestedOut = new ClassOutputStream(); - attr.accept(this, nestedOut); - out.writeInt(nestedOut.size()); - nestedOut.writeTo(out); - } - - protected AnnotationWriter annotationWriter = new AnnotationWriter(); - - @Override - public Void visitDefault(DefaultAttribute attr, ClassOutputStream out) { - out.write(attr.info, 0, attr.info.length); - return null; - } - - @Override - public Void visitAnnotationDefault(AnnotationDefault_attribute attr, ClassOutputStream out) { - annotationWriter.write(attr.default_value, out); - return null; - } - - @Override - 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; - } - - @Override - 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); - } - - @Override - 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); - } - - @Override - public Void visitCompilationID(CompilationID_attribute attr, ClassOutputStream out) { - out.writeShort(attr.compilationID_index); - return null; - } - - @Override - public Void visitConstantValue(ConstantValue_attribute attr, ClassOutputStream out) { - out.writeShort(attr.constantvalue_index); - return null; - } - - @Override - public Void visitDeprecated(Deprecated_attribute attr, ClassOutputStream out) { - return null; - } - - @Override - public Void visitEnclosingMethod(EnclosingMethod_attribute attr, ClassOutputStream out) { - out.writeShort(attr.class_index); - out.writeShort(attr.method_index); - return null; - } - - @Override - 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; - } - - @Override - 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); - } - - @Override - 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); - } - - @Override - 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); - } - - @Override - 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); - } - - @Override - public Void visitNestHost(NestHost_attribute attr, ClassOutputStream out) { - out.writeShort(attr.top_index); - return null; - } - - @Override - 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; - } - - @Override - public Void visitModule(Module_attribute attr, ClassOutputStream out) { - out.writeShort(attr.module_name); - out.writeShort(attr.module_flags); - out.writeShort(attr.module_version_index); - - out.writeShort(attr.requires.length); - for (Module_attribute.RequiresEntry e: attr.requires) { - out.writeShort(e.requires_index); - out.writeShort(e.requires_flags); - out.writeShort(e.requires_version_index); - } - - out.writeShort(attr.exports.length); - for (Module_attribute.ExportsEntry e: attr.exports) { - out.writeShort(e.exports_index); - out.writeShort(e.exports_flags); - out.writeShort(e.exports_to_index.length); - for (int index: e.exports_to_index) - out.writeShort(index); - } - - out.writeShort(attr.opens.length); - for (Module_attribute.OpensEntry e: attr.opens) { - out.writeShort(e.opens_index); - out.writeShort(e.opens_flags); - out.writeShort(e.opens_to_index.length); - for (int index: e.opens_to_index) - out.writeShort(index); - } - - out.writeShort(attr.uses_index.length); - for (int index: attr.uses_index) { - out.writeShort(index); - } - - out.writeShort(attr.provides.length); - for (Module_attribute.ProvidesEntry e: attr.provides) { - out.writeShort(e.provides_index); - out.writeShort(e.with_count); - for (int with : e.with_index) { - out.writeShort(with); - } - } - - return null; - } - - @Override - public Void visitModuleHashes(ModuleHashes_attribute attr, ClassOutputStream out) { - out.writeShort(attr.algorithm_index); - out.writeShort(attr.hashes_table.length); - for (ModuleHashes_attribute.Entry e: attr.hashes_table) { - out.writeShort(e.module_name_index); - out.writeShort(e.hash.length); - for (byte b: e.hash) { - out.writeByte(b); - } - } - return null; - } - - @Override - public Void visitModuleMainClass(ModuleMainClass_attribute attr, ClassOutputStream out) { - out.writeShort(attr.main_class_index); - return null; - } - - @Override - public Void visitModulePackages(ModulePackages_attribute attr, ClassOutputStream out) { - out.writeShort(attr.packages_count); - for (int i: attr.packages_index) - out.writeShort(i); - return null; - } - - @Override - public Void visitModuleResolution(ModuleResolution_attribute attr, ClassOutputStream out) { - out.writeShort(attr.resolution_flags); - return null; - } - - @Override - public Void visitModuleTarget(ModuleTarget_attribute attr, ClassOutputStream out) { - out.writeShort(attr.target_platform_index); - return null; - } - - @Override - public Void visitNestMembers(NestMembers_attribute attr, ClassOutputStream out) { - out.writeShort(attr.members_indexes.length); - for (int i : attr.members_indexes) { - out.writeShort(i); - } - return null; - } - - @Override - public Void visitRecord(Record_attribute attr, ClassOutputStream out) { - out.writeShort(attr.component_count); - for (Record_attribute.ComponentInfo info: attr.component_info_arr) { - out.writeShort(info.name_index); - out.writeShort(info.descriptor.index); - int size = info.attributes.size(); - out.writeShort(size); - for (Attribute componentAttr: info.attributes) - write(componentAttr, out); - } - return null; - } - - @Override - public Void visitRuntimeInvisibleAnnotations(RuntimeInvisibleAnnotations_attribute attr, ClassOutputStream out) { - annotationWriter.write(attr.annotations, out); - return null; - } - - @Override - 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; - } - - @Override - public Void visitRuntimeInvisibleTypeAnnotations(RuntimeInvisibleTypeAnnotations_attribute attr, ClassOutputStream out) { - annotationWriter.write(attr.annotations, out); - return null; - } - - @Override - public Void visitRuntimeVisibleAnnotations(RuntimeVisibleAnnotations_attribute attr, ClassOutputStream out) { - annotationWriter.write(attr.annotations, out); - return null; - } - - @Override - 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; - } - - @Override - public Void visitRuntimeVisibleTypeAnnotations(RuntimeVisibleTypeAnnotations_attribute attr, ClassOutputStream out) { - annotationWriter.write(attr.annotations, out); - return null; - } - - @Override - public Void visitPermittedSubclasses(PermittedSubclasses_attribute attr, ClassOutputStream out) { - int n = attr.subtypes.length; - out.writeShort(n); - for (int i = 0 ; i < n ; i++) { - out.writeShort(attr.subtypes[i]); - } - return null; - } - - @Override - public Void visitSignature(Signature_attribute attr, ClassOutputStream out) { - out.writeShort(attr.signature_index); - return null; - } - - @Override - public Void visitSourceDebugExtension(SourceDebugExtension_attribute attr, ClassOutputStream out) { - out.write(attr.debug_extension, 0, attr.debug_extension.length); - return null; - } - - @Override - public Void visitSourceFile(SourceFile_attribute attr, ClassOutputStream out) { - out.writeShort(attr.sourcefile_index); - return null; - } - - @Override - public Void visitSourceID(SourceID_attribute attr, ClassOutputStream out) { - out.writeShort(attr.sourceID_index); - return null; - } - - @Override - 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; - } - - @Override - 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; - } - - @Override - public Void visitSynthetic(Synthetic_attribute attr, ClassOutputStream out) { - return null; - } - - protected void writeAccessFlags(AccessFlags flags, ClassOutputStream out) { - out.writeShort(flags.flags); - } - - protected StackMapTableWriter stackMapWriter; - } - - /** - * Writer for the frames of StackMap and StackMapTable attributes. - */ - protected static class StackMapTableWriter - implements stack_map_frame.Visitor { - - public void write(stack_map_frame frame, ClassOutputStream out) { - out.write(frame.frame_type); - frame.accept(this, out); - } - - @Override - public Void visit_same_frame(same_frame frame, ClassOutputStream p) { - return null; - } - - @Override - 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; - } - - @Override - 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; - } - - @Override - public Void visit_chop_frame(chop_frame frame, ClassOutputStream out) { - out.writeShort(frame.offset_delta); - return null; - } - - @Override - public Void visit_same_frame_extended(same_frame_extended frame, ClassOutputStream out) { - out.writeShort(frame.offset_delta); - return null; - } - - @Override - 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; - } - - @Override - 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 { - 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); - } - - @Override - public Void visitPrimitive(Primitive_element_value ev, ClassOutputStream out) { - out.writeShort(ev.const_value_index); - return null; - } - - @Override - public Void visitEnum(Enum_element_value ev, ClassOutputStream out) { - out.writeShort(ev.type_name_index); - out.writeShort(ev.const_name_index); - return null; - } - - @Override - public Void visitClass(Class_element_value ev, ClassOutputStream out) { - out.writeShort(ev.class_info_index); - return null; - } - - @Override - public Void visitAnnotation(Annotation_element_value ev, ClassOutputStream out) { - write(ev.annotation_value, out); - return null; - } - - @Override - 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); - } - } - } -} diff --git a/src/jdk.jdeps/share/classes/com/sun/tools/classfile/Code_attribute.java b/src/jdk.jdeps/share/classes/com/sun/tools/classfile/Code_attribute.java deleted file mode 100644 index dc19fc564aaa7..0000000000000 --- a/src/jdk.jdeps/share/classes/com/sun/tools/classfile/Code_attribute.java +++ /dev/null @@ -1,154 +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. - * - *

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. - */ -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 accept(Visitor visitor, D data) { - return visitor.visitCode(this, data); - } - - public Iterable getInstructions() { - return () -> new Iterator() { - - 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 = (pc < code.length ? new Instruction(code, pc) : null); - - }; - } - - 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; - } -} diff --git a/src/jdk.jdeps/share/classes/com/sun/tools/classfile/CompilationID_attribute.java b/src/jdk.jdeps/share/classes/com/sun/tools/classfile/CompilationID_attribute.java deleted file mode 100644 index 6f2d70508b384..0000000000000 --- a/src/jdk.jdeps/share/classes/com/sun/tools/classfile/CompilationID_attribute.java +++ /dev/null @@ -1,63 +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; - -/** - *

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. - */ -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 accept(Visitor visitor, D data) { - return visitor.visitCompilationID(this, data); - } - - public final int compilationID_index; -} diff --git a/src/jdk.jdeps/share/classes/com/sun/tools/classfile/ConstantPool.java b/src/jdk.jdeps/share/classes/com/sun/tools/classfile/ConstantPool.java deleted file mode 100644 index 801220a026c5f..0000000000000 --- a/src/jdk.jdeps/share/classes/com/sun/tools/classfile/ConstantPool.java +++ /dev/null @@ -1,1053 +0,0 @@ -/* - * Copyright (c) 2007, 2021, 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. - * - *

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. - */ -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; - } - - @SuppressWarnings("serial") // Type of field is not Serializable - 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_Dynamic = 17; - public static final int CONSTANT_InvokeDynamic = 18; - public static final int CONSTANT_Module = 19; - public static final int CONSTANT_Package = 20; - - public static enum RefKind { - REF_getField(1), - REF_getStatic(2), - REF_putField(3), - REF_putStatic(4), - REF_invokeVirtual(5), - REF_invokeStatic(6), - REF_invokeSpecial(7), - REF_newInvokeSpecial(8), - REF_invokeInterface(9); - - public final int tag; - - RefKind(int tag) { - this.tag = tag; - } - - 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_Dynamic: - pool[i] = new CONSTANT_Dynamic_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_Module: - pool[i] = new CONSTANT_Module_info(this, cr); - break; - - case CONSTANT_NameAndType: - pool[i] = new CONSTANT_NameAndType_info(this, cr); - break; - - case CONSTANT_Package: - pool[i] = new CONSTANT_Package_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_Module_info getModuleInfo(int index) throws InvalidIndex, UnexpectedEntry { - return ((CONSTANT_Module_info) get(index, CONSTANT_Module)); - } - - public CONSTANT_NameAndType_info getNameAndTypeInfo(int index) throws InvalidIndex, UnexpectedEntry { - return ((CONSTANT_NameAndType_info) get(index, CONSTANT_NameAndType)); - } - - public CONSTANT_Package_info getPackageInfo(int index) throws InvalidIndex, UnexpectedEntry { - return ((CONSTANT_Package_info) get(index, CONSTANT_Package)); - } - - 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 entries() { - return () -> new Iterator() { - - 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 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 visitDynamicConstant(CONSTANT_Dynamic_info info, P p); - R visitLong(CONSTANT_Long_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 visitModule(CONSTANT_Module_info info, P p); - R visitNameAndType(CONSTANT_NameAndType_info info, P p); - R visitPackage(CONSTANT_Package_info info, P p); - R visitString(CONSTANT_String_info info, P p); - R visitUtf8(CONSTANT_Utf8_info info, P p); - } - - public abstract static 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 accept(Visitor visitor, D data); - - protected final ConstantPool cp; - } - - public abstract static 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 accept(Visitor 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 accept(Visitor 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 accept(Visitor 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 accept(Visitor 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 accept(Visitor 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 accept(Visitor 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 accept(Visitor 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 accept(Visitor 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 accept(Visitor 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 accept(Visitor 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 accept(Visitor visitor, D data) { - return visitor.visitMethodref(this, data); - } - } - - public static class CONSTANT_Module_info extends CPInfo { - CONSTANT_Module_info(ConstantPool cp, ClassReader cr) throws IOException { - super(cp); - name_index = cr.readUnsignedShort(); - } - - public CONSTANT_Module_info(ConstantPool cp, int name_index) { - super(cp); - this.name_index = name_index; - } - - public int getTag() { - return CONSTANT_Module; - } - - public int byteLength() { - return 3; - } - - /** - * Get the raw value of the module name referenced by this constant pool entry. - * This will be the name of the module. - * @return the raw value of the module name - */ - public String getName() throws ConstantPoolException { - return cp.getUTF8Value(name_index); - } - - @Override - public String toString() { - return "CONSTANT_Module_info[name_index: " + name_index + "]"; - } - - public R accept(Visitor visitor, D data) { - return visitor.visitModule(this, data); - } - - public final int name_index; - } - - 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 accept(Visitor 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_Dynamic_info extends CPInfo { - CONSTANT_Dynamic_info(ConstantPool cp, ClassReader cr) throws IOException { - super(cp); - bootstrap_method_attr_index = cr.readUnsignedShort(); - name_and_type_index = cr.readUnsignedShort(); - } - - public CONSTANT_Dynamic_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_Dynamic; - } - - public int byteLength() { - return 5; - } - - @Override - public String toString() { - return "CONSTANT_Dynamic_info[bootstrap_method_index: " + bootstrap_method_attr_index + ", name_and_type_index: " + name_and_type_index + "]"; - } - - public R accept(Visitor visitor, D data) { - return visitor.visitDynamicConstant(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_Package_info extends CPInfo { - CONSTANT_Package_info(ConstantPool cp, ClassReader cr) throws IOException { - super(cp); - name_index = cr.readUnsignedShort(); - } - - public CONSTANT_Package_info(ConstantPool cp, int name_index) { - super(cp); - this.name_index = name_index; - } - - public int getTag() { - return CONSTANT_Package; - } - - public int byteLength() { - return 3; - } - - /** - * Get the raw value of the package name referenced by this constant pool entry. - * This will be the name of the package, in internal form. - * @return the raw value of the module name - */ - public String getName() throws ConstantPoolException { - return cp.getUTF8Value(name_index); - } - - @Override - public String toString() { - return "CONSTANT_Package_info[name_index: " + name_index + "]"; - } - - public R accept(Visitor visitor, D data) { - return visitor.visitPackage(this, data); - } - - public final int name_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 accept(Visitor 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 accept(Visitor visitor, D data) { - return visitor.visitUtf8(this, data); - } - - public final String value; - } - -} diff --git a/src/jdk.jdeps/share/classes/com/sun/tools/classfile/ConstantPoolException.java b/src/jdk.jdeps/share/classes/com/sun/tools/classfile/ConstantPoolException.java deleted file mode 100644 index 50a9e9b8d88a9..0000000000000 --- a/src/jdk.jdeps/share/classes/com/sun/tools/classfile/ConstantPoolException.java +++ /dev/null @@ -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; - -/* - *

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. - */ -public class ConstantPoolException extends Exception { - private static final long serialVersionUID = -2324397349644754565L; - ConstantPoolException(int index) { - this.index = index; - } - - public final int index; -} diff --git a/src/jdk.jdeps/share/classes/com/sun/tools/classfile/ConstantValue_attribute.java b/src/jdk.jdeps/share/classes/com/sun/tools/classfile/ConstantValue_attribute.java deleted file mode 100644 index df40defa4f734..0000000000000 --- a/src/jdk.jdeps/share/classes/com/sun/tools/classfile/ConstantValue_attribute.java +++ /dev/null @@ -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. - * - *

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. - */ -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 accept(Visitor visitor, D data) { - return visitor.visitConstantValue(this, data); - } - - public final int constantvalue_index; -} diff --git a/src/jdk.jdeps/share/classes/com/sun/tools/classfile/DefaultAttribute.java b/src/jdk.jdeps/share/classes/com/sun/tools/classfile/DefaultAttribute.java deleted file mode 100644 index 16fdeb9824d9a..0000000000000 --- a/src/jdk.jdeps/share/classes/com/sun/tools/classfile/DefaultAttribute.java +++ /dev/null @@ -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; - -/* - *

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. - */ -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 accept(Visitor visitor, P p) { - return visitor.visitDefault(this, p); - } - - public final byte[] info; - /** Why did we need to generate a DefaultAttribute - */ - public final String reason; -} diff --git a/src/jdk.jdeps/share/classes/com/sun/tools/classfile/Deprecated_attribute.java b/src/jdk.jdeps/share/classes/com/sun/tools/classfile/Deprecated_attribute.java deleted file mode 100644 index dbf6442f2023f..0000000000000 --- a/src/jdk.jdeps/share/classes/com/sun/tools/classfile/Deprecated_attribute.java +++ /dev/null @@ -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. - * - *

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. - */ -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 accept(Visitor visitor, D data) { - return visitor.visitDeprecated(this, data); - } -} diff --git a/src/jdk.jdeps/share/classes/com/sun/tools/classfile/Descriptor.java b/src/jdk.jdeps/share/classes/com/sun/tools/classfile/Descriptor.java deleted file mode 100644 index fed0f3010a98d..0000000000000 --- a/src/jdk.jdeps/share/classes/com/sun/tools/classfile/Descriptor.java +++ /dev/null @@ -1,198 +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. - * - *

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. - */ -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; -} diff --git a/src/jdk.jdeps/share/classes/com/sun/tools/classfile/DescriptorException.java b/src/jdk.jdeps/share/classes/com/sun/tools/classfile/DescriptorException.java deleted file mode 100644 index 0a91e36a9143d..0000000000000 --- a/src/jdk.jdeps/share/classes/com/sun/tools/classfile/DescriptorException.java +++ /dev/null @@ -1,36 +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; - -/* - *

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. - */ -public class DescriptorException extends Exception { - private static final long serialVersionUID = 2411890273788901032L; -} diff --git a/src/jdk.jdeps/share/classes/com/sun/tools/classfile/EnclosingMethod_attribute.java b/src/jdk.jdeps/share/classes/com/sun/tools/classfile/EnclosingMethod_attribute.java deleted file mode 100644 index 4cbf1eba9120f..0000000000000 --- a/src/jdk.jdeps/share/classes/com/sun/tools/classfile/EnclosingMethod_attribute.java +++ /dev/null @@ -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. - * - *

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. - */ -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 accept(Visitor visitor, D data) { - return visitor.visitEnclosingMethod(this, data); - } - - public final int class_index; - public final int method_index; -} diff --git a/src/jdk.jdeps/share/classes/com/sun/tools/classfile/Exceptions_attribute.java b/src/jdk.jdeps/share/classes/com/sun/tools/classfile/Exceptions_attribute.java deleted file mode 100644 index a56db00b371dd..0000000000000 --- a/src/jdk.jdeps/share/classes/com/sun/tools/classfile/Exceptions_attribute.java +++ /dev/null @@ -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. - * - *

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. - */ -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 accept(Visitor visitor, D data) { - return visitor.visitExceptions(this, data); - } - - public final int number_of_exceptions; - public final int[] exception_index_table; -} diff --git a/src/jdk.jdeps/share/classes/com/sun/tools/classfile/FatalError.java b/src/jdk.jdeps/share/classes/com/sun/tools/classfile/FatalError.java deleted file mode 100644 index 1f7ad56ef9d6c..0000000000000 --- a/src/jdk.jdeps/share/classes/com/sun/tools/classfile/FatalError.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (c) 2020, 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; - -/** - *

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. - */ -public class FatalError extends Error { - private static final long serialVersionUID = 8114054446416187030L; - - FatalError(String message) { - super(message); - } -} diff --git a/src/jdk.jdeps/share/classes/com/sun/tools/classfile/Field.java b/src/jdk.jdeps/share/classes/com/sun/tools/classfile/Field.java deleted file mode 100644 index 89e313f6fc890..0000000000000 --- a/src/jdk.jdeps/share/classes/com/sun/tools/classfile/Field.java +++ /dev/null @@ -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; - -/* - *

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. - */ -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; -} diff --git a/src/jdk.jdeps/share/classes/com/sun/tools/classfile/InnerClasses_attribute.java b/src/jdk.jdeps/share/classes/com/sun/tools/classfile/InnerClasses_attribute.java deleted file mode 100644 index b7ae9ab5d5154..0000000000000 --- a/src/jdk.jdeps/share/classes/com/sun/tools/classfile/InnerClasses_attribute.java +++ /dev/null @@ -1,109 +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. - * - *

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. - */ -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 accept(Visitor 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 Info(int inner_class_info_index, int outer_class_info_index, int inner_name_index, AccessFlags inner_class_access_flags) { - this.inner_class_info_index = inner_class_info_index; - this.outer_class_info_index = outer_class_info_index; - this.inner_name_index = inner_name_index; - this.inner_class_access_flags = inner_class_access_flags; - } - - 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; - } -} diff --git a/src/jdk.jdeps/share/classes/com/sun/tools/classfile/Instruction.java b/src/jdk.jdeps/share/classes/com/sun/tools/classfile/Instruction.java deleted file mode 100644 index 0f5f15eed399b..0000000000000 --- a/src/jdk.jdeps/share/classes/com/sun/tools/classfile/Instruction.java +++ /dev/null @@ -1,357 +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. - * - *

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. - * - * @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 { - /** 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 accept(KindVisitor 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); - if (low > high) - throw new IllegalStateException(); - 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); - if (npairs < 0) - throw new IllegalStateException(); - 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; -} diff --git a/src/jdk.jdeps/share/classes/com/sun/tools/classfile/LineNumberTable_attribute.java b/src/jdk.jdeps/share/classes/com/sun/tools/classfile/LineNumberTable_attribute.java deleted file mode 100644 index 58595b7d0583e..0000000000000 --- a/src/jdk.jdeps/share/classes/com/sun/tools/classfile/LineNumberTable_attribute.java +++ /dev/null @@ -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. - * - *

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. - */ -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 accept(Visitor 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; - } -} diff --git a/src/jdk.jdeps/share/classes/com/sun/tools/classfile/LocalVariableTable_attribute.java b/src/jdk.jdeps/share/classes/com/sun/tools/classfile/LocalVariableTable_attribute.java deleted file mode 100644 index 1e4465f2f7ce2..0000000000000 --- a/src/jdk.jdeps/share/classes/com/sun/tools/classfile/LocalVariableTable_attribute.java +++ /dev/null @@ -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. - * - *

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. - */ -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 accept(Visitor 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; - } -} diff --git a/src/jdk.jdeps/share/classes/com/sun/tools/classfile/LocalVariableTypeTable_attribute.java b/src/jdk.jdeps/share/classes/com/sun/tools/classfile/LocalVariableTypeTable_attribute.java deleted file mode 100644 index 8332cbec577da..0000000000000 --- a/src/jdk.jdeps/share/classes/com/sun/tools/classfile/LocalVariableTypeTable_attribute.java +++ /dev/null @@ -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. - * - *

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. - */ -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 accept(Visitor 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; - } -} diff --git a/src/jdk.jdeps/share/classes/com/sun/tools/classfile/Method.java b/src/jdk.jdeps/share/classes/com/sun/tools/classfile/Method.java deleted file mode 100644 index 5345d54ccdfe1..0000000000000 --- a/src/jdk.jdeps/share/classes/com/sun/tools/classfile/Method.java +++ /dev/null @@ -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; - -/* - *

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. - */ -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; -} diff --git a/src/jdk.jdeps/share/classes/com/sun/tools/classfile/MethodParameters_attribute.java b/src/jdk.jdeps/share/classes/com/sun/tools/classfile/MethodParameters_attribute.java deleted file mode 100644 index 942f8f00c049b..0000000000000 --- a/src/jdk.jdeps/share/classes/com/sun/tools/classfile/MethodParameters_attribute.java +++ /dev/null @@ -1,92 +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. - * - *

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. - */ -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 accept(Visitor 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 Entry(int name_index, int flags) { - this.name_index = name_index; - this.flags = flags; - } - - public static int length() { - return 6; - } - - public final int name_index; - public final int flags; - } - -} diff --git a/src/jdk.jdeps/share/classes/com/sun/tools/classfile/ModuleHashes_attribute.java b/src/jdk.jdeps/share/classes/com/sun/tools/classfile/ModuleHashes_attribute.java deleted file mode 100644 index c227f3df8b726..0000000000000 --- a/src/jdk.jdeps/share/classes/com/sun/tools/classfile/ModuleHashes_attribute.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Copyright (c) 2015, 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. - * - *

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. - */ -public class ModuleHashes_attribute extends Attribute { - ModuleHashes_attribute(ClassReader cr, int name_index, int length) throws IOException { - super(name_index, length); - algorithm_index = cr.readUnsignedShort(); - hashes_table_length = cr.readUnsignedShort(); - hashes_table = new Entry[hashes_table_length]; - for (int i = 0; i < hashes_table_length; i++) - hashes_table[i] = new Entry(cr); - } - - public ModuleHashes_attribute(ConstantPool constant_pool, int algorithm_index, Entry[] hashes_table) - throws ConstantPoolException { - this(constant_pool.getUTF8Index(Attribute.ModuleHashes), algorithm_index, hashes_table); - } - - public ModuleHashes_attribute(int name_index, int algorithm_index, Entry[] hashes_table) { - super(name_index, 2 + 2 + length(hashes_table)); - this.algorithm_index = algorithm_index; - this.hashes_table_length = hashes_table.length; - this.hashes_table = hashes_table; - } - - @Override - public R accept(Visitor visitor, D data) { - return visitor.visitModuleHashes(this, data); - } - - private static int length(Entry[] hashes_table) { - int len = 0; - for (Entry e: hashes_table) { - len += e.length(); - } - return len; - } - - public final int algorithm_index; - public final int hashes_table_length; - public final Entry[] hashes_table; - - public static class Entry { - Entry(ClassReader cr) throws IOException { - module_name_index = cr.readUnsignedShort(); - int hash_length = cr.readUnsignedShort(); - hash = new byte[hash_length]; - for (int i=0; iThis 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. - */ -public class ModuleMainClass_attribute extends Attribute { - ModuleMainClass_attribute(ClassReader cr, int name_index, int length) throws IOException { - super(name_index, length); - main_class_index = cr.readUnsignedShort(); - } - - public ModuleMainClass_attribute(ConstantPool constant_pool, int mainClass_index) - throws ConstantPoolException { - this(constant_pool.getUTF8Index(Attribute.ModuleMainClass), mainClass_index); - } - - public ModuleMainClass_attribute(int name_index, int mainClass_index) { - super(name_index, 2); - this.main_class_index = mainClass_index; - } - - public String getMainClassName(ConstantPool constant_pool) throws ConstantPoolException { - return constant_pool.getClassInfo(main_class_index).getName(); - } - - @Override - public R accept(Visitor visitor, D data) { - return visitor.visitModuleMainClass(this, data); - } - - public final int main_class_index; -} diff --git a/src/jdk.jdeps/share/classes/com/sun/tools/classfile/ModulePackages_attribute.java b/src/jdk.jdeps/share/classes/com/sun/tools/classfile/ModulePackages_attribute.java deleted file mode 100644 index 9b3cd433bd8bb..0000000000000 --- a/src/jdk.jdeps/share/classes/com/sun/tools/classfile/ModulePackages_attribute.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright (c) 2015, 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.CONSTANT_Package_info; - -/** - * See JVMS, section 4.8.15. - * - *

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. - */ -public class ModulePackages_attribute extends Attribute { - ModulePackages_attribute(ClassReader cr, int name_index, int length) - throws IOException { - super(name_index, length); - packages_count = cr.readUnsignedShort(); - packages_index = new int[packages_count]; - for (int i = 0; i < packages_count; i++) - packages_index[i] = cr.readUnsignedShort(); - } - - public ModulePackages_attribute(ConstantPool constant_pool, - int[] packages_index) - throws ConstantPoolException { - this(constant_pool.getUTF8Index(Attribute.ModulePackages), - packages_index); - } - - public ModulePackages_attribute(int name_index, - int[] packages_index) { - super(name_index, 2 + packages_index.length * 2); - this.packages_count = packages_index.length; - this.packages_index = packages_index; - } - - public String getPackage(int index, ConstantPool constant_pool) throws ConstantPoolException { - int package_index = packages_index[index]; - CONSTANT_Package_info info = constant_pool.getPackageInfo(package_index); - return info.getName(); - } - - @Override - public R accept(Visitor visitor, D data) { - return visitor.visitModulePackages(this, data); - } - - public final int packages_count; - public final int[] packages_index; -} diff --git a/src/jdk.jdeps/share/classes/com/sun/tools/classfile/ModuleResolution_attribute.java b/src/jdk.jdeps/share/classes/com/sun/tools/classfile/ModuleResolution_attribute.java deleted file mode 100644 index e1ba78a337629..0000000000000 --- a/src/jdk.jdeps/share/classes/com/sun/tools/classfile/ModuleResolution_attribute.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright (c) 2016, 2017, 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. - * - *

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. - */ -public class ModuleResolution_attribute extends Attribute { - public static final int DO_NOT_RESOLVE_BY_DEFAULT = 0x0001; - public static final int WARN_DEPRECATED = 0x0002; - public static final int WARN_DEPRECATED_FOR_REMOVAL = 0x0004; - public static final int WARN_INCUBATING = 0x0008; - - ModuleResolution_attribute(ClassReader cr, int name_index, int length) - throws IOException { - super(name_index, length); - resolution_flags = cr.readUnsignedShort(); - } - - public ModuleResolution_attribute(ConstantPool constant_pool, - int resolution_flags) - throws ConstantPoolException { - this(constant_pool.getUTF8Index(Attribute.ModuleResolution), - resolution_flags); - } - - public ModuleResolution_attribute(int name_index, - int resolution_flags) { - super(name_index, 2); - this.resolution_flags = resolution_flags; - } - - @Override - public R accept(Visitor visitor, D data) { - return visitor.visitModuleResolution(this, data); - } - - public final int resolution_flags; -} diff --git a/src/jdk.jdeps/share/classes/com/sun/tools/classfile/ModuleTarget_attribute.java b/src/jdk.jdeps/share/classes/com/sun/tools/classfile/ModuleTarget_attribute.java deleted file mode 100644 index b7d7ecc77e396..0000000000000 --- a/src/jdk.jdeps/share/classes/com/sun/tools/classfile/ModuleTarget_attribute.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c) 2016, 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. - * - *

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. - */ -public class ModuleTarget_attribute extends Attribute { - ModuleTarget_attribute(ClassReader cr, int name_index, int length) throws IOException { - super(name_index, length); - target_platform_index = cr.readUnsignedShort(); - } - - public ModuleTarget_attribute(int name_index, int target_platform_index) { - super(name_index, 2); - this.target_platform_index = target_platform_index; - } - - @Override - public R accept(Visitor visitor, D data) { - return visitor.visitModuleTarget(this, data); - } - - public final int target_platform_index; -} diff --git a/src/jdk.jdeps/share/classes/com/sun/tools/classfile/Module_attribute.java b/src/jdk.jdeps/share/classes/com/sun/tools/classfile/Module_attribute.java deleted file mode 100644 index 6b0b525b50c10..0000000000000 --- a/src/jdk.jdeps/share/classes/com/sun/tools/classfile/Module_attribute.java +++ /dev/null @@ -1,230 +0,0 @@ -/* - * Copyright (c) 2015, 2016, 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.CONSTANT_Module_info; - -/** - * See Jigsaw. - * - *

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. - */ -public class Module_attribute extends Attribute { - public static final int ACC_TRANSITIVE = 0x20; - public static final int ACC_STATIC_PHASE = 0x40; - public static final int ACC_OPEN = 0x20; - public static final int ACC_SYNTHETIC = 0x1000; - public static final int ACC_MANDATED = 0x8000; - - Module_attribute(ClassReader cr, int name_index, int length) throws IOException { - super(name_index, length); - - module_name = cr.readUnsignedShort(); - module_flags = cr.readUnsignedShort(); - - module_version_index = cr.readUnsignedShort(); - - requires_count = cr.readUnsignedShort(); - requires = new RequiresEntry[requires_count]; - for (int i = 0; i < requires_count; i++) - requires[i] = new RequiresEntry(cr); - - exports_count = cr.readUnsignedShort(); - exports = new ExportsEntry[exports_count]; - for (int i = 0; i < exports_count; i++) - exports[i] = new ExportsEntry(cr); - - opens_count = cr.readUnsignedShort(); - opens = new OpensEntry[opens_count]; - for (int i = 0; i < opens_count; i++) - opens[i] = new OpensEntry(cr); - - uses_count = cr.readUnsignedShort(); - uses_index = new int[uses_count]; - for (int i = 0; i < uses_count; i++) - uses_index[i] = cr.readUnsignedShort(); - - provides_count = cr.readUnsignedShort(); - provides = new ProvidesEntry[provides_count]; - for (int i = 0; i < provides_count; i++) - provides[i] = new ProvidesEntry(cr); - } - - public Module_attribute(int name_index, - int module_name, - int module_flags, - int module_version_index, - RequiresEntry[] requires, - ExportsEntry[] exports, - OpensEntry[] opens, - int[] uses, - ProvidesEntry[] provides) { - super(name_index, 2); - this.module_name = module_name; - this.module_flags = module_flags; - this.module_version_index = module_version_index; - requires_count = requires.length; - this.requires = requires; - exports_count = exports.length; - this.exports = exports; - opens_count = opens.length; - this.opens = opens; - uses_count = uses.length; - this.uses_index = uses; - provides_count = provides.length; - this.provides = provides; - } - - public String getUses(int index, ConstantPool constant_pool) throws ConstantPoolException { - int i = uses_index[index]; - return constant_pool.getClassInfo(i).getName(); - } - - @Override - public R accept(Visitor visitor, D data) { - return visitor.visitModule(this, data); - } - - public final int module_name; - public final int module_flags; - public final int module_version_index; - public final int requires_count; - public final RequiresEntry[] requires; - public final int exports_count; - public final ExportsEntry[] exports; - public final int opens_count; - public final OpensEntry[] opens; - public final int uses_count; - public final int[] uses_index; - public final int provides_count; - public final ProvidesEntry[] provides; - - public static class RequiresEntry { - RequiresEntry(ClassReader cr) throws IOException { - requires_index = cr.readUnsignedShort(); - requires_flags = cr.readUnsignedShort(); - requires_version_index = cr.readUnsignedShort(); - } - - public RequiresEntry(int index, int flags, int version_index) { - this.requires_index = index; - this.requires_flags = flags; - this.requires_version_index = version_index; - } - - public String getRequires(ConstantPool constant_pool) throws ConstantPoolException { - CONSTANT_Module_info info = constant_pool.getModuleInfo(requires_index); - return info.getName(); - } - - public static final int length = 4; - - public final int requires_index; - public final int requires_flags; - public final int requires_version_index; - } - - public static class ExportsEntry { - ExportsEntry(ClassReader cr) throws IOException { - exports_index = cr.readUnsignedShort(); - exports_flags = cr.readUnsignedShort(); - exports_to_count = cr.readUnsignedShort(); - exports_to_index = new int[exports_to_count]; - for (int i = 0; i < exports_to_count; i++) - exports_to_index[i] = cr.readUnsignedShort(); - } - - public ExportsEntry(int index, int flags, int[] to) { - this.exports_index = index; - this.exports_flags = flags; - this.exports_to_count = to.length; - this.exports_to_index = to; - } - - public int length() { - return 4 + 2 * exports_to_index.length; - } - - public final int exports_index; - public final int exports_flags; - public final int exports_to_count; - public final int[] exports_to_index; - } - - public static class OpensEntry { - OpensEntry(ClassReader cr) throws IOException { - opens_index = cr.readUnsignedShort(); - opens_flags = cr.readUnsignedShort(); - opens_to_count = cr.readUnsignedShort(); - opens_to_index = new int[opens_to_count]; - for (int i = 0; i < opens_to_count; i++) - opens_to_index[i] = cr.readUnsignedShort(); - } - - public OpensEntry(int index, int flags, int[] to) { - this.opens_index = index; - this.opens_flags = flags; - this.opens_to_count = to.length; - this.opens_to_index = to; - } - - public int length() { - return 4 + 2 * opens_to_index.length; - } - - public final int opens_index; - public final int opens_flags; - public final int opens_to_count; - public final int[] opens_to_index; - } - - public static class ProvidesEntry { - ProvidesEntry(ClassReader cr) throws IOException { - provides_index = cr.readUnsignedShort(); - with_count = cr.readUnsignedShort(); - with_index = new int[with_count]; - for (int i = 0; i < with_count; i++) - with_index[i] = cr.readUnsignedShort(); - } - - public ProvidesEntry(int provides, int[] with) { - this.provides_index = provides; - this.with_count = with.length; - this.with_index = with; - } - - public static final int length = 4; - - public final int provides_index; - public final int with_count; - public final int[] with_index; - } -} diff --git a/src/jdk.jdeps/share/classes/com/sun/tools/classfile/NestHost_attribute.java b/src/jdk.jdeps/share/classes/com/sun/tools/classfile/NestHost_attribute.java deleted file mode 100644 index 0473fbf56feb5..0000000000000 --- a/src/jdk.jdeps/share/classes/com/sun/tools/classfile/NestHost_attribute.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright (c) 2018, 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 com.sun.tools.classfile.ConstantPool.CONSTANT_Class_info; - -import java.io.IOException; - -/** - *

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. - */ -public class NestHost_attribute extends Attribute { - NestHost_attribute(ClassReader cr, int name_index, int length) throws IOException { - super(name_index, length); - top_index = cr.readUnsignedShort(); - } - - public NestHost_attribute(ConstantPool constant_pool, int signature_index) - throws ConstantPoolException { - this(constant_pool.getUTF8Index(Attribute.Signature), signature_index); - } - - public NestHost_attribute(int name_index, int top_index) { - super(name_index, 2); - this.top_index = top_index; - } - - public CONSTANT_Class_info getNestTop(ConstantPool constant_pool) throws ConstantPoolException { - return constant_pool.getClassInfo(top_index); - } - - public R accept(Visitor visitor, D data) { - return visitor.visitNestHost(this, data); - } - - public final int top_index; -} diff --git a/src/jdk.jdeps/share/classes/com/sun/tools/classfile/NestMembers_attribute.java b/src/jdk.jdeps/share/classes/com/sun/tools/classfile/NestMembers_attribute.java deleted file mode 100644 index bf57a12a1a625..0000000000000 --- a/src/jdk.jdeps/share/classes/com/sun/tools/classfile/NestMembers_attribute.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright (c) 2018, 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 com.sun.tools.classfile.ConstantPool.CONSTANT_Class_info; - -import java.io.IOException; -import java.util.stream.IntStream; - -/** - *

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. - */ -public class NestMembers_attribute extends Attribute { - NestMembers_attribute(ClassReader cr, int name_index, int length) throws IOException { - super(name_index, length); - int len = cr.readUnsignedShort(); - members_indexes = new int[len]; - for (int i = 0 ; i < len ; i++) { - members_indexes[i] = cr.readUnsignedShort(); - } - } - - public NestMembers_attribute(int name_index, int[] members_indexes) { - super(name_index, 2); - this.members_indexes = members_indexes; - } - - public CONSTANT_Class_info[] getChildren(ConstantPool constant_pool) throws ConstantPoolException { - return IntStream.of(members_indexes) - .mapToObj(i -> { - try { - return constant_pool.getClassInfo(i); - } catch (ConstantPoolException ex) { - throw new AssertionError(ex); - } - }).toArray(CONSTANT_Class_info[]::new); - } - - public R accept(Visitor visitor, D data) { - return visitor.visitNestMembers(this, data); - } - - public final int[] members_indexes; -} diff --git a/src/jdk.jdeps/share/classes/com/sun/tools/classfile/Opcode.java b/src/jdk.jdeps/share/classes/com/sun/tools/classfile/Opcode.java deleted file mode 100644 index 0f3ff0434165b..0000000000000 --- a/src/jdk.jdeps/share/classes/com/sun/tools/classfile/Opcode.java +++ /dev/null @@ -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. - * - *

In addition to providing all the standard opcodes defined in JVMS, - * this class also provides legacy support for the PicoJava extensions. - * - *

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. - */ -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 } -} diff --git a/src/jdk.jdeps/share/classes/com/sun/tools/classfile/PermittedSubclasses_attribute.java b/src/jdk.jdeps/share/classes/com/sun/tools/classfile/PermittedSubclasses_attribute.java deleted file mode 100644 index fcd680fdda4aa..0000000000000 --- a/src/jdk.jdeps/share/classes/com/sun/tools/classfile/PermittedSubclasses_attribute.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright (c) 2019, 2020, 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.stream.IntStream; - -import com.sun.tools.classfile.ConstantPool.CONSTANT_Class_info; - -public class PermittedSubclasses_attribute extends Attribute { - - public int[] subtypes; - - PermittedSubclasses_attribute(ClassReader cr, int name_index, int length) throws IOException { - super(name_index, length); - int number_of_classes = cr.readUnsignedShort(); - subtypes = new int[number_of_classes]; - for (int i = 0; i < number_of_classes; i++) - subtypes[i] = cr.readUnsignedShort(); - } - - public PermittedSubclasses_attribute(int name_index, int[] subtypes) { - super(name_index, 2); - this.subtypes = subtypes; - } - - public CONSTANT_Class_info[] getSubtypes(ConstantPool constant_pool) throws ConstantPoolException { - return IntStream.of(subtypes) - .mapToObj(i -> { - try { - return constant_pool.getClassInfo(i); - } catch (ConstantPoolException ex) { - throw new AssertionError(ex); - } - }).toArray(CONSTANT_Class_info[]::new); - } - - @Override - public R accept(Visitor visitor, D data) { - return visitor.visitPermittedSubclasses(this, data); - } -} diff --git a/src/jdk.jdeps/share/classes/com/sun/tools/classfile/Record_attribute.java b/src/jdk.jdeps/share/classes/com/sun/tools/classfile/Record_attribute.java deleted file mode 100644 index 8d67e6c3016f9..0000000000000 --- a/src/jdk.jdeps/share/classes/com/sun/tools/classfile/Record_attribute.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright (c) 2018, 2019, 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.Attribute.Visitor; - -/** - *

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. - */ -public class Record_attribute extends Attribute { - Record_attribute(ClassReader cr, int name_index, int length) throws IOException { - super(name_index, length); - component_count = cr.readUnsignedShort(); - component_info_arr = new ComponentInfo[component_count]; - for (int i = 0; i < component_count; i++) { - component_info_arr[i] = new ComponentInfo(cr); - } - } - - public Record_attribute(int name_index, ComponentInfo[] component_info_arr) { - super(name_index, 2); - this.component_count = component_info_arr.length; - this.component_info_arr = component_info_arr; - } - - @Override - public R accept(Visitor visitor, D data) { - return visitor.visitRecord(this, data); - } - - public final int component_count; - public final ComponentInfo[] component_info_arr; - - public static class ComponentInfo { - ComponentInfo(ClassReader cr) throws IOException { - name_index = cr.readUnsignedShort(); - descriptor = new Descriptor(cr); - attributes = new Attributes(cr); - } - - public ComponentInfo(int name_index, Descriptor descriptor, Attributes attributes) { - this.name_index = name_index; - this.descriptor = descriptor; - this.attributes = attributes; - } - - public String getName(ConstantPool constant_pool) throws ConstantPoolException { - return constant_pool.getUTF8Value(name_index); - } - - public final int name_index; - public final Descriptor descriptor; - public final Attributes attributes; - } -} diff --git a/src/jdk.jdeps/share/classes/com/sun/tools/classfile/ReferenceFinder.java b/src/jdk.jdeps/share/classes/com/sun/tools/classfile/ReferenceFinder.java deleted file mode 100644 index a15cb40a71833..0000000000000 --- a/src/jdk.jdeps/share/classes/com/sun/tools/classfile/ReferenceFinder.java +++ /dev/null @@ -1,253 +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 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 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 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 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 cpVisitor = - new ConstantPool.Visitor() - { - public Boolean visitClass(CONSTANT_Class_info info, ConstantPool cpool) { - return false; - } - - 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 visitInterfaceMethodref(CONSTANT_InterfaceMethodref_info info, ConstantPool cpool) { - return filter.accept(cpool, info); - } - - public Boolean visitInvokeDynamic(CONSTANT_InvokeDynamic_info info, ConstantPool cpool) { - return false; - } - - @Override - public Boolean visitDynamicConstant(CONSTANT_Dynamic_info info, ConstantPool constantPool) { - return false; - } - - public Boolean visitLong(CONSTANT_Long_info info, ConstantPool cpool) { - return false; - } - - public Boolean visitMethodHandle(CONSTANT_MethodHandle_info info, ConstantPool cpool) { - return false; - } - - public Boolean visitMethodref(CONSTANT_Methodref_info info, ConstantPool cpool) { - return filter.accept(cpool, info); - } - - public Boolean visitMethodType(CONSTANT_MethodType_info info, ConstantPool cpool) { - return false; - } - - public Boolean visitModule(CONSTANT_Module_info info, ConstantPool cpool) { - return false; - } - - public Boolean visitNameAndType(CONSTANT_NameAndType_info info, ConstantPool cpool) { - return false; - } - - public Boolean visitPackage(CONSTANT_Package_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> codeVisitor = - new Instruction.KindVisitor>() - { - public Integer visitNoOperands(Instruction instr, List p) { - return 0; - } - - public Integer visitArrayType(Instruction instr, TypeKind kind, List p) { - return 0; - } - - public Integer visitBranch(Instruction instr, int offset, List p) { - return 0; - } - - public Integer visitConstantPoolRef(Instruction instr, int index, List p) { - return p.contains(index) ? index : 0; - } - - public Integer visitConstantPoolRefAndValue(Instruction instr, int index, int value, List p) { - return p.contains(index) ? index : 0; - } - - public Integer visitLocal(Instruction instr, int index, List p) { - return 0; - } - - public Integer visitLocalAndValue(Instruction instr, int index, int value, List p) { - return 0; - } - - public Integer visitLookupSwitch(Instruction instr, int default_, int npairs, int[] matches, int[] offsets, List p) { - return 0; - } - - public Integer visitTableSwitch(Instruction instr, int default_, int low, int high, int[] offsets, List p) { - return 0; - } - - public Integer visitValue(Instruction instr, int value, List p) { - return 0; - } - - public Integer visitUnknown(Instruction instr, List p) { - return 0; - } - }; -} - diff --git a/src/jdk.jdeps/share/classes/com/sun/tools/classfile/RuntimeAnnotations_attribute.java b/src/jdk.jdeps/share/classes/com/sun/tools/classfile/RuntimeAnnotations_attribute.java deleted file mode 100644 index 859cec405da03..0000000000000 --- a/src/jdk.jdeps/share/classes/com/sun/tools/classfile/RuntimeAnnotations_attribute.java +++ /dev/null @@ -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. - * - *

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. - */ -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; -} diff --git a/src/jdk.jdeps/share/classes/com/sun/tools/classfile/RuntimeInvisibleAnnotations_attribute.java b/src/jdk.jdeps/share/classes/com/sun/tools/classfile/RuntimeInvisibleAnnotations_attribute.java deleted file mode 100644 index ed700823cd54e..0000000000000 --- a/src/jdk.jdeps/share/classes/com/sun/tools/classfile/RuntimeInvisibleAnnotations_attribute.java +++ /dev/null @@ -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. - * - *

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. - */ -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 accept(Visitor visitor, P p) { - return visitor.visitRuntimeInvisibleAnnotations(this, p); - } -} diff --git a/src/jdk.jdeps/share/classes/com/sun/tools/classfile/RuntimeInvisibleParameterAnnotations_attribute.java b/src/jdk.jdeps/share/classes/com/sun/tools/classfile/RuntimeInvisibleParameterAnnotations_attribute.java deleted file mode 100644 index 57de543a90321..0000000000000 --- a/src/jdk.jdeps/share/classes/com/sun/tools/classfile/RuntimeInvisibleParameterAnnotations_attribute.java +++ /dev/null @@ -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. - * - *

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. - */ -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 accept(Visitor visitor, P p) { - return visitor.visitRuntimeInvisibleParameterAnnotations(this, p); - } -} diff --git a/src/jdk.jdeps/share/classes/com/sun/tools/classfile/RuntimeInvisibleTypeAnnotations_attribute.java b/src/jdk.jdeps/share/classes/com/sun/tools/classfile/RuntimeInvisibleTypeAnnotations_attribute.java deleted file mode 100644 index 672bb55420f90..0000000000000 --- a/src/jdk.jdeps/share/classes/com/sun/tools/classfile/RuntimeInvisibleTypeAnnotations_attribute.java +++ /dev/null @@ -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. - * - *

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. - */ -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 accept(Visitor visitor, P p) { - return visitor.visitRuntimeInvisibleTypeAnnotations(this, p); - } -} diff --git a/src/jdk.jdeps/share/classes/com/sun/tools/classfile/RuntimeParameterAnnotations_attribute.java b/src/jdk.jdeps/share/classes/com/sun/tools/classfile/RuntimeParameterAnnotations_attribute.java deleted file mode 100644 index 904010f649f43..0000000000000 --- a/src/jdk.jdeps/share/classes/com/sun/tools/classfile/RuntimeParameterAnnotations_attribute.java +++ /dev/null @@ -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. - * - *

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. - */ -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; -} - diff --git a/src/jdk.jdeps/share/classes/com/sun/tools/classfile/RuntimeTypeAnnotations_attribute.java b/src/jdk.jdeps/share/classes/com/sun/tools/classfile/RuntimeTypeAnnotations_attribute.java deleted file mode 100644 index 162e0765c7e93..0000000000000 --- a/src/jdk.jdeps/share/classes/com/sun/tools/classfile/RuntimeTypeAnnotations_attribute.java +++ /dev/null @@ -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. - * - *

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. - */ -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; -} diff --git a/src/jdk.jdeps/share/classes/com/sun/tools/classfile/RuntimeVisibleAnnotations_attribute.java b/src/jdk.jdeps/share/classes/com/sun/tools/classfile/RuntimeVisibleAnnotations_attribute.java deleted file mode 100644 index c7a443905c6b1..0000000000000 --- a/src/jdk.jdeps/share/classes/com/sun/tools/classfile/RuntimeVisibleAnnotations_attribute.java +++ /dev/null @@ -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. - * - *

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. - */ -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 accept(Visitor visitor, P p) { - return visitor.visitRuntimeVisibleAnnotations(this, p); - } -} diff --git a/src/jdk.jdeps/share/classes/com/sun/tools/classfile/RuntimeVisibleParameterAnnotations_attribute.java b/src/jdk.jdeps/share/classes/com/sun/tools/classfile/RuntimeVisibleParameterAnnotations_attribute.java deleted file mode 100644 index 24214e7e2a255..0000000000000 --- a/src/jdk.jdeps/share/classes/com/sun/tools/classfile/RuntimeVisibleParameterAnnotations_attribute.java +++ /dev/null @@ -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. - * - *

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. - */ -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 accept(Visitor visitor, P p) { - return visitor.visitRuntimeVisibleParameterAnnotations(this, p); - } -} diff --git a/src/jdk.jdeps/share/classes/com/sun/tools/classfile/RuntimeVisibleTypeAnnotations_attribute.java b/src/jdk.jdeps/share/classes/com/sun/tools/classfile/RuntimeVisibleTypeAnnotations_attribute.java deleted file mode 100644 index 851c1f7d90723..0000000000000 --- a/src/jdk.jdeps/share/classes/com/sun/tools/classfile/RuntimeVisibleTypeAnnotations_attribute.java +++ /dev/null @@ -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. - * - *

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. - */ -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 accept(Visitor visitor, P p) { - return visitor.visitRuntimeVisibleTypeAnnotations(this, p); - } -} diff --git a/src/jdk.jdeps/share/classes/com/sun/tools/classfile/Signature.java b/src/jdk.jdeps/share/classes/com/sun/tools/classfile/Signature.java deleted file mode 100644 index 384c7080d7107..0000000000000 --- a/src/jdk.jdeps/share/classes/com/sun/tools/classfile/Signature.java +++ /dev/null @@ -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. - * - *

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. - */ -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 typeParamTypes = null; - if (sig.charAt(sigp) == '<') - typeParamTypes = parseTypeParamTypes(); - - if (sig.charAt(sigp) == '(') { - List paramTypes = parseTypeSignatures(')'); - Type returnType = parseTypeSignature(); - List 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 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 parseTypeSignatures(char term) { - sigp++; - List 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 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 parseTypeParamTypes() { - assert sig.charAt(sigp) == '<'; - sigp++; - List 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 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; -} diff --git a/src/jdk.jdeps/share/classes/com/sun/tools/classfile/Signature_attribute.java b/src/jdk.jdeps/share/classes/com/sun/tools/classfile/Signature_attribute.java deleted file mode 100644 index acb9475c7981e..0000000000000 --- a/src/jdk.jdeps/share/classes/com/sun/tools/classfile/Signature_attribute.java +++ /dev/null @@ -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. - * - *

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. - */ -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 accept(Visitor visitor, D data) { - return visitor.visitSignature(this, data); - } - - public final int signature_index; -} diff --git a/src/jdk.jdeps/share/classes/com/sun/tools/classfile/SourceDebugExtension_attribute.java b/src/jdk.jdeps/share/classes/com/sun/tools/classfile/SourceDebugExtension_attribute.java deleted file mode 100644 index 22e87723d2ff6..0000000000000 --- a/src/jdk.jdeps/share/classes/com/sun/tools/classfile/SourceDebugExtension_attribute.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright (c) 2007, 2021, 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 static java.nio.charset.StandardCharsets.UTF_8; - -/** - * See JVMS, section 4.8.15. - * - *

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. - */ -public class SourceDebugExtension_attribute extends Attribute { - - 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, UTF_8); - } - - public R accept(Visitor visitor, D data) { - return visitor.visitSourceDebugExtension(this, data); - } - - public final byte[] debug_extension; -} diff --git a/src/jdk.jdeps/share/classes/com/sun/tools/classfile/SourceFile_attribute.java b/src/jdk.jdeps/share/classes/com/sun/tools/classfile/SourceFile_attribute.java deleted file mode 100644 index c3b7509d165dd..0000000000000 --- a/src/jdk.jdeps/share/classes/com/sun/tools/classfile/SourceFile_attribute.java +++ /dev/null @@ -1,63 +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.10. - * - *

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. - */ -public class SourceFile_attribute extends Attribute { - SourceFile_attribute(ClassReader cr, int name_index, int length) throws IOException { - super(name_index, length); - sourcefile_index = cr.readUnsignedShort(); - } - - public SourceFile_attribute(ConstantPool constant_pool, int sourcefile_index) - throws ConstantPoolException { - this(constant_pool.getUTF8Index(Attribute.SourceFile), sourcefile_index); - } - - public SourceFile_attribute(int name_index, int sourcefile_index) { - super(name_index, 2); - this.sourcefile_index = sourcefile_index; - } - - public String getSourceFile(ConstantPool constant_pool) throws ConstantPoolException { - return constant_pool.getUTF8Value(sourcefile_index); - } - - public R accept(Visitor visitor, P p) { - return visitor.visitSourceFile(this, p); - } - - public final int sourcefile_index; -} diff --git a/src/jdk.jdeps/share/classes/com/sun/tools/classfile/SourceID_attribute.java b/src/jdk.jdeps/share/classes/com/sun/tools/classfile/SourceID_attribute.java deleted file mode 100644 index d8c1e523c9d5e..0000000000000 --- a/src/jdk.jdeps/share/classes/com/sun/tools/classfile/SourceID_attribute.java +++ /dev/null @@ -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; - -/** - *

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. - */ -public class SourceID_attribute extends Attribute { - - SourceID_attribute(ClassReader cr, int name_index, int length) throws IOException { - super(name_index, length); - sourceID_index = cr.readUnsignedShort(); - } - - public SourceID_attribute(ConstantPool constant_pool, int sourceID_index) - throws ConstantPoolException { - this(constant_pool.getUTF8Index(Attribute.SourceID), sourceID_index); - } - - public SourceID_attribute(int name_index, int sourceID_index) { - super(name_index, 2); - this.sourceID_index = sourceID_index; - } - - String getSourceID(ConstantPool constant_pool) throws ConstantPoolException { - return constant_pool.getUTF8Value(sourceID_index); - } - - public R accept(Visitor visitor, D data) { - return visitor.visitSourceID(this, data); - } - - public final int sourceID_index; -} diff --git a/src/jdk.jdeps/share/classes/com/sun/tools/classfile/StackMapTable_attribute.java b/src/jdk.jdeps/share/classes/com/sun/tools/classfile/StackMapTable_attribute.java deleted file mode 100644 index a0f94f1bbd5f0..0000000000000 --- a/src/jdk.jdeps/share/classes/com/sun/tools/classfile/StackMapTable_attribute.java +++ /dev/null @@ -1,380 +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.4. - * - *

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. - */ -public class StackMapTable_attribute extends Attribute { - static class InvalidStackMap extends AttributeException { - private static final long serialVersionUID = -5659038410855089780L; - InvalidStackMap(String msg) { - super(msg); - } - } - - StackMapTable_attribute(ClassReader cr, int name_index, int length) - throws IOException, InvalidStackMap { - super(name_index, length); - number_of_entries = cr.readUnsignedShort(); - entries = new stack_map_frame[number_of_entries]; - for (int i = 0; i < number_of_entries; i++) - entries[i] = stack_map_frame.read(cr); - } - - public StackMapTable_attribute(ConstantPool constant_pool, stack_map_frame[] entries) - throws ConstantPoolException { - this(constant_pool.getUTF8Index(Attribute.StackMapTable), entries); - } - - public StackMapTable_attribute(int name_index, stack_map_frame[] entries) { - super(name_index, length(entries)); - this.number_of_entries = entries.length; - this.entries = entries; - } - - public R accept(Visitor visitor, D data) { - return visitor.visitStackMapTable(this, data); - } - - static int length(stack_map_frame[] entries) { - int n = 2; - for (stack_map_frame entry: entries) - n += entry.length(); - return n; - } - - public final int number_of_entries; - public final stack_map_frame entries[]; - - public abstract static class stack_map_frame { - static stack_map_frame read(ClassReader cr) - throws IOException, InvalidStackMap { - int frame_type = cr.readUnsignedByte(); - if (frame_type <= 63) - return new same_frame(frame_type); - else if (frame_type <= 127) - return new same_locals_1_stack_item_frame(frame_type, cr); - else if (frame_type <= 246) - throw new Error("unknown frame_type " + frame_type); - else if (frame_type == 247) - return new same_locals_1_stack_item_frame_extended(frame_type, cr); - else if (frame_type <= 250) - return new chop_frame(frame_type, cr); - else if (frame_type == 251) - return new same_frame_extended(frame_type, cr); - else if (frame_type <= 254) - return new append_frame(frame_type, cr); - else - return new full_frame(frame_type, cr); - } - - protected stack_map_frame(int frame_type) { - this.frame_type = frame_type; - } - - public int length() { - return 1; - } - - public abstract int getOffsetDelta(); - - public abstract R accept(Visitor visitor, D data); - - public final int frame_type; - - public static interface Visitor { - R visit_same_frame(same_frame frame, P p); - R visit_same_locals_1_stack_item_frame(same_locals_1_stack_item_frame frame, P p); - R visit_same_locals_1_stack_item_frame_extended(same_locals_1_stack_item_frame_extended frame, P p); - R visit_chop_frame(chop_frame frame, P p); - R visit_same_frame_extended(same_frame_extended frame, P p); - R visit_append_frame(append_frame frame, P p); - R visit_full_frame(full_frame frame, P p); - } - } - - public static class same_frame extends stack_map_frame { - same_frame(int frame_type) { - super(frame_type); - } - - public R accept(Visitor visitor, D data) { - return visitor.visit_same_frame(this, data); - } - - public int getOffsetDelta() { - return frame_type; - } - } - - public static class same_locals_1_stack_item_frame extends stack_map_frame { - same_locals_1_stack_item_frame(int frame_type, ClassReader cr) - throws IOException, InvalidStackMap { - super(frame_type); - stack = new verification_type_info[1]; - stack[0] = verification_type_info.read(cr); - } - - @Override - public int length() { - return super.length() + stack[0].length(); - } - - public R accept(Visitor visitor, D data) { - return visitor.visit_same_locals_1_stack_item_frame(this, data); - } - - public int getOffsetDelta() { - return frame_type - 64; - } - - public final verification_type_info[] stack; - } - - public static class same_locals_1_stack_item_frame_extended extends stack_map_frame { - same_locals_1_stack_item_frame_extended(int frame_type, ClassReader cr) - throws IOException, InvalidStackMap { - super(frame_type); - offset_delta = cr.readUnsignedShort(); - stack = new verification_type_info[1]; - stack[0] = verification_type_info.read(cr); - } - - @Override - public int length() { - return super.length() + 2 + stack[0].length(); - } - - public R accept(Visitor visitor, D data) { - return visitor.visit_same_locals_1_stack_item_frame_extended(this, data); - } - - public int getOffsetDelta() { - return offset_delta; - } - - public final int offset_delta; - public final verification_type_info[] stack; - } - - public static class chop_frame extends stack_map_frame { - chop_frame(int frame_type, ClassReader cr) throws IOException { - super(frame_type); - offset_delta = cr.readUnsignedShort(); - } - - @Override - public int length() { - return super.length() + 2; - } - - public R accept(Visitor visitor, D data) { - return visitor.visit_chop_frame(this, data); - } - - public int getOffsetDelta() { - return offset_delta; - } - - public final int offset_delta; - } - - public static class same_frame_extended extends stack_map_frame { - same_frame_extended(int frame_type, ClassReader cr) throws IOException { - super(frame_type); - offset_delta = cr.readUnsignedShort(); - } - - @Override - public int length() { - return super.length() + 2; - } - - public R accept(Visitor visitor, D data) { - return visitor.visit_same_frame_extended(this, data); - } - - public int getOffsetDelta() { - return offset_delta; - } - - public final int offset_delta; - } - - public static class append_frame extends stack_map_frame { - append_frame(int frame_type, ClassReader cr) - throws IOException, InvalidStackMap { - super(frame_type); - offset_delta = cr.readUnsignedShort(); - locals = new verification_type_info[frame_type - 251]; - for (int i = 0; i < locals.length; i++) - locals[i] = verification_type_info.read(cr); - } - - @Override - public int length() { - int n = super.length() + 2; - for (verification_type_info local: locals) - n += local.length(); - return n; - } - - public R accept(Visitor visitor, D data) { - return visitor.visit_append_frame(this, data); - } - - public int getOffsetDelta() { - return offset_delta; - } - - public final int offset_delta; - public final verification_type_info[] locals; - } - - public static class full_frame extends stack_map_frame { - full_frame(int frame_type, ClassReader cr) - throws IOException, InvalidStackMap { - super(frame_type); - offset_delta = cr.readUnsignedShort(); - number_of_locals = cr.readUnsignedShort(); - locals = new verification_type_info[number_of_locals]; - for (int i = 0; i < locals.length; i++) - locals[i] = verification_type_info.read(cr); - number_of_stack_items = cr.readUnsignedShort(); - stack = new verification_type_info[number_of_stack_items]; - for (int i = 0; i < stack.length; i++) - stack[i] = verification_type_info.read(cr); - } - - @Override - public int length() { - int n = super.length() + 2; - for (verification_type_info local: locals) - n += local.length(); - n += 2; - for (verification_type_info item: stack) - n += item.length(); - return n; - } - - public R accept(Visitor visitor, D data) { - return visitor.visit_full_frame(this, data); - } - - public int getOffsetDelta() { - return offset_delta; - } - - public final int offset_delta; - public final int number_of_locals; - public final verification_type_info[] locals; - public final int number_of_stack_items; - public final verification_type_info[] stack; - } - - public static class verification_type_info { - public static final int ITEM_Top = 0; - public static final int ITEM_Integer = 1; - public static final int ITEM_Float = 2; - public static final int ITEM_Long = 4; - public static final int ITEM_Double = 3; - public static final int ITEM_Null = 5; - public static final int ITEM_UninitializedThis = 6; - public static final int ITEM_Object = 7; - public static final int ITEM_Uninitialized = 8; - - static verification_type_info read(ClassReader cr) - throws IOException, InvalidStackMap { - int tag = cr.readUnsignedByte(); - switch (tag) { - case ITEM_Top: - case ITEM_Integer: - case ITEM_Float: - case ITEM_Long: - case ITEM_Double: - case ITEM_Null: - case ITEM_UninitializedThis: - return new verification_type_info(tag); - - case ITEM_Object: - return new Object_variable_info(cr); - - case ITEM_Uninitialized: - return new Uninitialized_variable_info(cr); - - default: - throw new InvalidStackMap("unrecognized verification_type_info tag"); - } - } - - protected verification_type_info(int tag) { - this.tag = tag; - } - - public int length() { - return 1; - } - - public final int tag; - } - - public static class Object_variable_info extends verification_type_info { - Object_variable_info(ClassReader cr) throws IOException { - super(ITEM_Object); - cpool_index = cr.readUnsignedShort(); - } - - @Override - public int length() { - return super.length() + 2; - } - - public final int cpool_index; - } - - public static class Uninitialized_variable_info extends verification_type_info { - Uninitialized_variable_info(ClassReader cr) throws IOException { - super(ITEM_Uninitialized); - offset = cr.readUnsignedShort(); - } - - @Override - public int length() { - return super.length() + 2; - } - - public final int offset; - - } -} diff --git a/src/jdk.jdeps/share/classes/com/sun/tools/classfile/StackMap_attribute.java b/src/jdk.jdeps/share/classes/com/sun/tools/classfile/StackMap_attribute.java deleted file mode 100644 index e57a24bfa981e..0000000000000 --- a/src/jdk.jdeps/share/classes/com/sun/tools/classfile/StackMap_attribute.java +++ /dev/null @@ -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; - -/** - *

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. - */ -public class StackMap_attribute extends Attribute { - StackMap_attribute(ClassReader cr, int name_index, int length) - throws IOException, StackMapTable_attribute.InvalidStackMap { - super(name_index, length); - number_of_entries = cr.readUnsignedShort(); - entries = new stack_map_frame[number_of_entries]; - for (int i = 0; i < number_of_entries; i++) - entries[i] = new stack_map_frame(cr); - } - - public StackMap_attribute(ConstantPool constant_pool, stack_map_frame[] entries) - throws ConstantPoolException { - this(constant_pool.getUTF8Index(Attribute.StackMap), entries); - } - - public StackMap_attribute(int name_index, stack_map_frame[] entries) { - super(name_index, StackMapTable_attribute.length(entries)); - this.number_of_entries = entries.length; - this.entries = entries; - } - - public R accept(Visitor visitor, D data) { - return visitor.visitStackMap(this, data); - } - - public final int number_of_entries; - public final stack_map_frame entries[]; - - public static class stack_map_frame extends StackMapTable_attribute.full_frame { - stack_map_frame(ClassReader cr) - throws IOException, StackMapTable_attribute.InvalidStackMap { - super(255, cr); - } - } -} diff --git a/src/jdk.jdeps/share/classes/com/sun/tools/classfile/Synthetic_attribute.java b/src/jdk.jdeps/share/classes/com/sun/tools/classfile/Synthetic_attribute.java deleted file mode 100644 index 0b7f933d78765..0000000000000 --- a/src/jdk.jdeps/share/classes/com/sun/tools/classfile/Synthetic_attribute.java +++ /dev/null @@ -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.8. - * - *

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. - */ -public class Synthetic_attribute extends Attribute { - Synthetic_attribute(ClassReader cr, int name_index, int length) throws IOException { - super(name_index, length); - } - - public Synthetic_attribute(ConstantPool constant_pool) - throws ConstantPoolException { - this(constant_pool.getUTF8Index(Attribute.Synthetic)); - } - - public Synthetic_attribute(int name_index) { - super(name_index, 0); - } - - public R accept(Visitor visitor, D data) { - return visitor.visitSynthetic(this, data); - } -} diff --git a/src/jdk.jdeps/share/classes/com/sun/tools/classfile/Type.java b/src/jdk.jdeps/share/classes/com/sun/tools/classfile/Type.java deleted file mode 100644 index 478d1607324a0..0000000000000 --- a/src/jdk.jdeps/share/classes/com/sun/tools/classfile/Type.java +++ /dev/null @@ -1,378 +0,0 @@ -/* - * Copyright (c) 2008, 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.util.Arrays; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -/* - * Family of classes used to represent the parsed form of a {@link Descriptor} - * or {@link Signature}. - * - *

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. - */ -public abstract class Type { - protected Type() { } - - public boolean isObject() { - return false; - } - - public abstract R accept(Visitor visitor, D data); - - protected static void append(StringBuilder sb, String prefix, List types, String suffix) { - sb.append(prefix); - String sep = ""; - for (Type t: types) { - sb.append(sep); - sb.append(t); - sep = ", "; - } - sb.append(suffix); - } - - protected static void appendIfNotEmpty(StringBuilder sb, String prefix, List types, String suffix) { - if (types != null && types.size() > 0) - append(sb, prefix, types, suffix); - } - - public interface Visitor { - R visitSimpleType(SimpleType type, P p); - R visitArrayType(ArrayType type, P p); - R visitMethodType(MethodType type, P p); - R visitClassSigType(ClassSigType type, P p); - R visitClassType(ClassType type, P p); - R visitTypeParamType(TypeParamType type, P p); - R visitWildcardType(WildcardType type, P p); - } - - /** - * Represents a type signature with a simple name. The name may be that of a - * primitive type, such "{@code int}, {@code float}, etc - * or that of a type argument, such as {@code T}, {@code K}, {@code V}, etc. - * - * See: - * JVMS 4.3.2 - * BaseType: - * {@code B}, {@code C}, {@code D}, {@code F}, {@code I}, - * {@code J}, {@code S}, {@code Z}; - * VoidDescriptor: - * {@code V}; - * JVMS 4.3.4 - * TypeVariableSignature: - * {@code T} Identifier {@code ;} - */ - public static class SimpleType extends Type { - public SimpleType(String name) { - this.name = name; - } - - public R accept(Visitor visitor, D data) { - return visitor.visitSimpleType(this, data); - } - - public boolean isPrimitiveType() { - return primitiveTypes.contains(name); - } - // where - private static final Set primitiveTypes = new HashSet<>(Arrays.asList( - "boolean", "byte", "char", "double", "float", "int", "long", "short", "void")); - - @Override - public String toString() { - return name; - } - - public final String name; - } - - /** - * Represents an array type signature. - * - * See: - * JVMS 4.3.4 - * ArrayTypeSignature: - * {@code [} TypeSignature {@code ]} - */ - public static class ArrayType extends Type { - public ArrayType(Type elemType) { - this.elemType = elemType; - } - - public R accept(Visitor visitor, D data) { - return visitor.visitArrayType(this, data); - } - - @Override - public String toString() { - return elemType + "[]"; - } - - public final Type elemType; - } - - /** - * Represents a method type signature. - * - * See; - * JVMS 4.3.4 - * MethodTypeSignature: - * FormalTypeParameters_opt {@code (} TypeSignature* {@code)} ReturnType - * ThrowsSignature* - */ - public static class MethodType extends Type { - public MethodType(List paramTypes, Type resultType) { - this(null, paramTypes, resultType, null); - } - - public MethodType(List typeParamTypes, - List paramTypes, - Type returnType, - List throwsTypes) { - this.typeParamTypes = typeParamTypes; - this.paramTypes = paramTypes; - this.returnType = returnType; - this.throwsTypes = throwsTypes; - } - - public R accept(Visitor visitor, D data) { - return visitor.visitMethodType(this, data); - } - - @Override - public String toString() { - StringBuilder sb = new StringBuilder(); - appendIfNotEmpty(sb, "<", typeParamTypes, "> "); - sb.append(returnType); - append(sb, " (", paramTypes, ")"); - appendIfNotEmpty(sb, " throws ", throwsTypes, ""); - return sb.toString(); - } - - public final List typeParamTypes; - public final List paramTypes; - public final Type returnType; - public final List throwsTypes; - } - - /** - * Represents a class signature. These describe the signature of - * a class that has type arguments. - * - * See: - * JVMS 4.3.4 - * ClassSignature: - * FormalTypeParameters_opt SuperclassSignature SuperinterfaceSignature* - */ - public static class ClassSigType extends Type { - public ClassSigType(List typeParamTypes, Type superclassType, - List superinterfaceTypes) { - this.typeParamTypes = typeParamTypes; - this.superclassType = superclassType; - this.superinterfaceTypes = superinterfaceTypes; - } - - public R accept(Visitor visitor, D data) { - return visitor.visitClassSigType(this, data); - } - - @Override - public String toString() { - StringBuilder sb = new StringBuilder(); - appendIfNotEmpty(sb, "<", typeParamTypes, ">"); - if (superclassType != null) { - sb.append(" extends "); - sb.append(superclassType); - } - appendIfNotEmpty(sb, " implements ", superinterfaceTypes, ""); - return sb.toString(); - } - - public final List typeParamTypes; - public final Type superclassType; - public final List superinterfaceTypes; - } - - /** - * Represents a class type signature. This is used to represent a - * reference to a class, such as in a field, parameter, return type, etc. - * - * See: - * JVMS 4.3.4 - * ClassTypeSignature: - * {@code L} PackageSpecifier_opt SimpleClassTypeSignature - * ClassTypeSignatureSuffix* {@code ;} - * PackageSpecifier: - * Identifier {@code /} PackageSpecifier* - * SimpleClassTypeSignature: - * Identifier TypeArguments_opt } - * ClassTypeSignatureSuffix: - * {@code .} SimpleClassTypeSignature - */ - public static class ClassType extends Type { - public ClassType(ClassType outerType, String name, List typeArgs) { - this.outerType = outerType; - this.name = name; - this.typeArgs = typeArgs; - } - - public R accept(Visitor visitor, D data) { - return visitor.visitClassType(this, data); - } - - public String getBinaryName() { - if (outerType == null) - return name; - else - return (outerType.getBinaryName() + "$" + name); - } - - @Override - public String toString() { - StringBuilder sb = new StringBuilder(); - if (outerType != null) { - sb.append(outerType); - sb.append("."); - } - sb.append(name); - appendIfNotEmpty(sb, "<", typeArgs, ">"); - return sb.toString(); - } - - @Override - public boolean isObject() { - return (outerType == null) - && name.equals("java/lang/Object") - && (typeArgs == null || typeArgs.isEmpty()); - } - - public final ClassType outerType; - public final String name; - public final List typeArgs; - } - - /** - * Represents a FormalTypeParameter. These are used to declare the type - * parameters for generic classes and methods. - * - * See: - * JVMS 4.3.4 - * FormalTypeParameters: - * {@code <} FormalTypeParameter+ {@code >} - * FormalTypeParameter: - * Identifier ClassBound InterfaceBound* - * ClassBound: - * {@code :} FieldTypeSignature_opt - * InterfaceBound: - * {@code :} FieldTypeSignature - */ - public static class TypeParamType extends Type { - public TypeParamType(String name, Type classBound, List interfaceBounds) { - this.name = name; - this.classBound = classBound; - this.interfaceBounds = interfaceBounds; - } - - public R accept(Visitor visitor, D data) { - return visitor.visitTypeParamType(this, data); - } - - @Override - public String toString() { - StringBuilder sb = new StringBuilder(); - sb.append(name); - String sep = " extends "; - if (classBound != null) { - sb.append(sep); - sb.append(classBound); - sep = " & "; - } - if (interfaceBounds != null) { - for (Type bound: interfaceBounds) { - sb.append(sep); - sb.append(bound); - sep = " & "; - } - } - return sb.toString(); - } - - public final String name; - public final Type classBound; - public final List interfaceBounds; - } - - /** - * Represents a wildcard type argument. A type argument that is not a - * wildcard type argument will be represented by a ClassType, ArrayType, etc. - * - * See: - * JVMS 4.3.4 - * TypeArgument: - * WildcardIndicator_opt FieldTypeSignature - * {@code *} - * WildcardIndicator: - * {@code +} - * {@code -} - */ - public static class WildcardType extends Type { - public enum Kind { UNBOUNDED, EXTENDS, SUPER } - - public WildcardType() { - this(Kind.UNBOUNDED, null); - } - public WildcardType(Kind kind, Type boundType) { - this.kind = kind; - this.boundType = boundType; - } - - public R accept(Visitor visitor, D data) { - return visitor.visitWildcardType(this, data); - } - - @Override - public String toString() { - switch (kind) { - case UNBOUNDED: - return "?"; - case EXTENDS: - return "? extends " + boundType; - case SUPER: - return "? super " + boundType; - default: - throw new AssertionError(); - } - } - - public final Kind kind; - public final Type boundType; - } -} diff --git a/src/jdk.jdeps/share/classes/com/sun/tools/classfile/TypeAnnotation.java b/src/jdk.jdeps/share/classes/com/sun/tools/classfile/TypeAnnotation.java deleted file mode 100644 index 65876d02b8d3d..0000000000000 --- a/src/jdk.jdeps/share/classes/com/sun/tools/classfile/TypeAnnotation.java +++ /dev/null @@ -1,654 +0,0 @@ -/* - * Copyright (c) 2009, 2022, 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.ArrayList; -import java.util.List; - -import com.sun.tools.classfile.TypeAnnotation.Position.TypePathEntry; - -/** - * See JSR 308 specification, Section 3. - * - *

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. - */ -public class TypeAnnotation { - TypeAnnotation(ClassReader cr) throws IOException, Annotation.InvalidAnnotation { - constant_pool = cr.getConstantPool(); - position = read_position(cr); - annotation = new Annotation(cr); - } - - public TypeAnnotation(ConstantPool constant_pool, - Annotation annotation, Position position) { - this.constant_pool = constant_pool; - this.position = position; - this.annotation = annotation; - } - - public int length() { - int n = annotation.length(); - n += position_length(position); - return n; - } - - @Override - public String toString() { - try { - return "@" + constant_pool.getUTF8Value(annotation.type_index).substring(1) + - " pos: " + position.toString(); - } catch (Exception e) { - e.printStackTrace(); - return e.toString(); - } - } - - public final ConstantPool constant_pool; - public final Position position; - public final Annotation annotation; - - private static Position read_position(ClassReader cr) throws IOException, Annotation.InvalidAnnotation { - // Copied from ClassReader - int tag = cr.readUnsignedByte(); // TargetType tag is a byte - if (!TargetType.isValidTargetTypeValue(tag)) - throw new Annotation.InvalidAnnotation("TypeAnnotation: Invalid type annotation target type value: " + String.format("0x%02X", tag)); - - TargetType type = TargetType.fromTargetTypeValue(tag); - - Position position = new Position(); - position.type = type; - - switch (type) { - // instanceof - case INSTANCEOF: - // new expression - case NEW: - // constructor/method reference receiver - case CONSTRUCTOR_REFERENCE: - case METHOD_REFERENCE: - position.offset = cr.readUnsignedShort(); - break; - // local variable - case LOCAL_VARIABLE: - // resource variable - case RESOURCE_VARIABLE: - int table_length = cr.readUnsignedShort(); - position.lvarOffset = new int[table_length]; - position.lvarLength = new int[table_length]; - position.lvarIndex = new int[table_length]; - for (int i = 0; i < table_length; ++i) { - position.lvarOffset[i] = cr.readUnsignedShort(); - position.lvarLength[i] = cr.readUnsignedShort(); - position.lvarIndex[i] = cr.readUnsignedShort(); - } - break; - // exception parameter - case EXCEPTION_PARAMETER: - position.exception_index = cr.readUnsignedShort(); - break; - // method receiver - case METHOD_RECEIVER: - // Do nothing - break; - // type parameter - case CLASS_TYPE_PARAMETER: - case METHOD_TYPE_PARAMETER: - position.parameter_index = cr.readUnsignedByte(); - break; - // type parameter bound - case CLASS_TYPE_PARAMETER_BOUND: - case METHOD_TYPE_PARAMETER_BOUND: - position.parameter_index = cr.readUnsignedByte(); - position.bound_index = cr.readUnsignedByte(); - break; - // class extends or implements clause - case CLASS_EXTENDS: - position.type_index = cr.readUnsignedShort(); - break; - // throws - case THROWS: - position.type_index = cr.readUnsignedShort(); - break; - // method parameter - case METHOD_FORMAL_PARAMETER: - position.parameter_index = cr.readUnsignedByte(); - 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: - position.offset = cr.readUnsignedShort(); - position.type_index = cr.readUnsignedByte(); - break; - // We don't need to worry about these - case METHOD_RETURN: - case FIELD: - break; - case UNKNOWN: - throw new AssertionError("TypeAnnotation: UNKNOWN target type should never occur!"); - default: - throw new AssertionError("TypeAnnotation: Unknown target type: " + type); - } - - { // Write type path - int len = cr.readUnsignedByte(); - List loc = new ArrayList<>(len); - for (int i = 0; i < len * TypePathEntry.bytesPerEntry; ++i) - loc.add(cr.readUnsignedByte()); - position.location = Position.getTypePathFromBinary(loc); - } - return position; - } - - private static int position_length(Position pos) { - int n = 0; - n += 1; // TargetType tag is a byte - switch (pos.type) { - // instanceof - case INSTANCEOF: - // new expression - case NEW: - // constructor/method reference receiver - case CONSTRUCTOR_REFERENCE: - case METHOD_REFERENCE: - n += 2; // offset - break; - // local variable - case LOCAL_VARIABLE: - // resource variable - case RESOURCE_VARIABLE: - n += 2; // table_length; - int table_length = pos.lvarOffset.length; - n += 2 * table_length; // offset - n += 2 * table_length; // length - n += 2 * table_length; // index - break; - // exception parameter - case EXCEPTION_PARAMETER: - n += 2; // exception_index - break; - // method receiver - case METHOD_RECEIVER: - // Do nothing - break; - // type parameter - case CLASS_TYPE_PARAMETER: - case METHOD_TYPE_PARAMETER: - n += 1; // parameter_index - break; - // type parameter bound - case CLASS_TYPE_PARAMETER_BOUND: - case METHOD_TYPE_PARAMETER_BOUND: - n += 1; // parameter_index - n += 1; // bound_index - break; - // class extends or implements clause - case CLASS_EXTENDS: - n += 2; // type_index - break; - // throws - case THROWS: - n += 2; // type_index - break; - // method parameter - case METHOD_FORMAL_PARAMETER: - n += 1; // 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: - n += 2; // offset - n += 1; // type index - break; - // We don't need to worry about these - case METHOD_RETURN: - case FIELD: - break; - case UNKNOWN: - throw new AssertionError("TypeAnnotation: UNKNOWN target type should never occur!"); - default: - throw new AssertionError("TypeAnnotation: Unknown target type: " + pos.type); - } - - { - n += 1; // length - n += TypePathEntry.bytesPerEntry * pos.location.size(); // bytes for actual array - } - - return n; - } - - // Code duplicated from com.sun.tools.javac.code.TypeAnnotationPosition - public static class Position { - public enum TypePathEntryKind { - ARRAY(0), - INNER_TYPE(1), - WILDCARD(2), - TYPE_ARGUMENT(3); - - public final int tag; - - private TypePathEntryKind(int tag) { - this.tag = tag; - } - } - - public static class TypePathEntry { - /** The fixed number of bytes per TypePathEntry. */ - public static final int bytesPerEntry = 2; - - public final TypePathEntryKind tag; - public final int arg; - - public static final TypePathEntry ARRAY = new TypePathEntry(TypePathEntryKind.ARRAY); - public static final TypePathEntry INNER_TYPE = new TypePathEntry(TypePathEntryKind.INNER_TYPE); - public static final TypePathEntry WILDCARD = new TypePathEntry(TypePathEntryKind.WILDCARD); - - private TypePathEntry(TypePathEntryKind tag) { - if (!(tag == TypePathEntryKind.ARRAY || - tag == TypePathEntryKind.INNER_TYPE || - tag == TypePathEntryKind.WILDCARD)) { - throw new AssertionError("Invalid TypePathEntryKind: " + tag); - } - this.tag = tag; - this.arg = 0; - } - - public TypePathEntry(TypePathEntryKind tag, int arg) { - if (tag != TypePathEntryKind.TYPE_ARGUMENT) { - throw new AssertionError("Invalid TypePathEntryKind: " + tag); - } - this.tag = tag; - this.arg = arg; - } - - public static TypePathEntry fromBinary(int tag, int arg) { - if (arg != 0 && tag != TypePathEntryKind.TYPE_ARGUMENT.tag) { - throw new AssertionError("Invalid TypePathEntry tag/arg: " + tag + "/" + arg); - } - switch (tag) { - case 0: - return ARRAY; - case 1: - return INNER_TYPE; - case 2: - return WILDCARD; - case 3: - return new TypePathEntry(TypePathEntryKind.TYPE_ARGUMENT, arg); - default: - throw new AssertionError("Invalid TypePathEntryKind tag: " + tag); - } - } - - @Override - public String toString() { - return tag.toString() + - (tag == TypePathEntryKind.TYPE_ARGUMENT ? ("(" + arg + ")") : ""); - } - - @Override - public boolean equals(Object other) { - if (! (other instanceof TypePathEntry)) { - return false; - } - TypePathEntry tpe = (TypePathEntry) other; - return this.tag == tpe.tag && this.arg == tpe.arg; - } - - @Override - public int hashCode() { - return this.tag.hashCode() * 17 + this.arg; - } - } - - public TargetType type = TargetType.UNKNOWN; - - // For generic/array types. - // TODO: or should we use null? No one will use this object. - public List location = new ArrayList<>(0); - - // Tree position. - public int pos = -1; - - // For typecasts, type tests, new (and locals, as start_pc). - public boolean isValidOffset = false; - public int offset = -1; - - // For locals. arrays same length - public int[] lvarOffset = null; - public int[] lvarLength = null; - public int[] lvarIndex = null; - - // For type parameter bound - public int bound_index = Integer.MIN_VALUE; - - // For type parameter and method parameter - public int parameter_index = Integer.MIN_VALUE; - - // For class extends, implements, and throws clauses - public int type_index = Integer.MIN_VALUE; - - // For exception parameters, index into exception table - public int exception_index = Integer.MIN_VALUE; - - public Position() {} - - @Override - public String toString() { - StringBuilder sb = new StringBuilder(); - sb.append('['); - sb.append(type); - - switch (type) { - // instanceof - case INSTANCEOF: - // new expression - case NEW: - // constructor/method reference receiver - case CONSTRUCTOR_REFERENCE: - case METHOD_REFERENCE: - sb.append(", offset = "); - sb.append(offset); - break; - // local variable - case LOCAL_VARIABLE: - // resource variable - case RESOURCE_VARIABLE: - if (lvarOffset == null) { - sb.append(", lvarOffset is null!"); - break; - } - sb.append(", {"); - for (int i = 0; i < lvarOffset.length; ++i) { - if (i != 0) sb.append("; "); - sb.append("start_pc = "); - sb.append(lvarOffset[i]); - sb.append(", length = "); - sb.append(lvarLength[i]); - sb.append(", index = "); - sb.append(lvarIndex[i]); - } - sb.append("}"); - break; - // method receiver - case METHOD_RECEIVER: - // Do nothing - break; - // type parameter - case CLASS_TYPE_PARAMETER: - case METHOD_TYPE_PARAMETER: - sb.append(", param_index = "); - sb.append(parameter_index); - break; - // type parameter bound - case CLASS_TYPE_PARAMETER_BOUND: - case METHOD_TYPE_PARAMETER_BOUND: - sb.append(", param_index = "); - sb.append(parameter_index); - sb.append(", bound_index = "); - sb.append(bound_index); - break; - // class extends or implements clause - case CLASS_EXTENDS: - sb.append(", type_index = "); - sb.append(type_index); - break; - // throws - case THROWS: - sb.append(", type_index = "); - sb.append(type_index); - break; - // exception parameter - case EXCEPTION_PARAMETER: - sb.append(", exception_index = "); - sb.append(exception_index); - break; - // method parameter - case METHOD_FORMAL_PARAMETER: - sb.append(", param_index = "); - sb.append(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: - sb.append(", offset = "); - sb.append(offset); - sb.append(", type_index = "); - sb.append(type_index); - break; - // We don't need to worry about these - case METHOD_RETURN: - case FIELD: - break; - case UNKNOWN: - sb.append(", position UNKNOWN!"); - break; - default: - throw new AssertionError("Unknown target type: " + type); - } - - // Append location data for generics/arrays. - if (!location.isEmpty()) { - sb.append(", location = ("); - sb.append(location); - sb.append(")"); - } - - sb.append(", pos = "); - sb.append(pos); - - sb.append(']'); - return sb.toString(); - } - - /** - * Indicates whether the target tree of the annotation has been optimized - * away from classfile or not. - * @return true if the target has not been optimized away - */ - public boolean emitToClassfile() { - return !type.isLocal() || isValidOffset; - } - - /** - * Decode the binary representation for a type path and set - * the {@code location} field. - * - * @param list The bytecode representation of the type path. - */ - public static List getTypePathFromBinary(List list) { - List loc = new ArrayList<>(list.size() / TypePathEntry.bytesPerEntry); - int idx = 0; - while (idx < list.size()) { - if (idx + 1 == list.size()) { - throw new AssertionError("Could not decode type path: " + list); - } - loc.add(TypePathEntry.fromBinary(list.get(idx), list.get(idx + 1))); - idx += 2; - } - return loc; - } - - public static List getBinaryFromTypePath(List locs) { - List loc = new ArrayList<>(locs.size() * TypePathEntry.bytesPerEntry); - for (TypePathEntry tpe : locs) { - loc.add(tpe.tag.tag); - loc.add(tpe.arg); - } - return loc; - } - } - - // Code duplicated from com.sun.tools.javac.code.TargetType - // The IsLocal flag could be removed here. - public enum TargetType { - /** For annotations on a class type parameter declaration. */ - CLASS_TYPE_PARAMETER(0x00), - - /** For annotations on a method type parameter declaration. */ - METHOD_TYPE_PARAMETER(0x01), - - /** For annotations on the type of an "extends" or "implements" clause. */ - CLASS_EXTENDS(0x10), - - /** For annotations on a bound of a type parameter of a class. */ - CLASS_TYPE_PARAMETER_BOUND(0x11), - - /** For annotations on a bound of a type parameter of a method. */ - METHOD_TYPE_PARAMETER_BOUND(0x12), - - /** For annotations on a field. */ - FIELD(0x13), - - /** For annotations on a method return type. */ - METHOD_RETURN(0x14), - - /** For annotations on the method receiver. */ - METHOD_RECEIVER(0x15), - - /** For annotations on a method parameter. */ - METHOD_FORMAL_PARAMETER(0x16), - - /** For annotations on a throws clause in a method declaration. */ - THROWS(0x17), - - /** For annotations on a local variable. */ - LOCAL_VARIABLE(0x40, true), - - /** For annotations on a resource variable. */ - RESOURCE_VARIABLE(0x41, true), - - /** For annotations on an exception parameter. */ - EXCEPTION_PARAMETER(0x42, true), - - /** For annotations on a type test. */ - INSTANCEOF(0x43, true), - - /** For annotations on an object creation expression. */ - NEW(0x44, true), - - /** For annotations on a constructor reference receiver. */ - CONSTRUCTOR_REFERENCE(0x45, true), - - /** For annotations on a method reference receiver. */ - METHOD_REFERENCE(0x46, true), - - /** For annotations on a typecast. */ - CAST(0x47, true), - - /** For annotations on a type argument of an object creation expression. */ - CONSTRUCTOR_INVOCATION_TYPE_ARGUMENT(0x48, true), - - /** For annotations on a type argument of a method call. */ - METHOD_INVOCATION_TYPE_ARGUMENT(0x49, true), - - /** For annotations on a type argument of a constructor reference. */ - CONSTRUCTOR_REFERENCE_TYPE_ARGUMENT(0x4A, true), - - /** For annotations on a type argument of a method reference. */ - METHOD_REFERENCE_TYPE_ARGUMENT(0x4B, true), - - /** For annotations with an unknown target. */ - UNKNOWN(0xFF); - - private static final int MAXIMUM_TARGET_TYPE_VALUE = 0x4B; - - private final int targetTypeValue; - private final boolean isLocal; - - private TargetType(int targetTypeValue) { - this(targetTypeValue, false); - } - - private TargetType(int targetTypeValue, boolean isLocal) { - if (targetTypeValue < 0 - || targetTypeValue > 255) - throw new AssertionError("Attribute type value needs to be an unsigned byte: " + String.format("0x%02X", targetTypeValue)); - this.targetTypeValue = targetTypeValue; - this.isLocal = isLocal; - } - - /** - * Returns whether or not this TargetType represents an annotation whose - * target is exclusively a tree in a method body - * - * Note: wildcard bound targets could target a local tree and a class - * member declaration signature tree - */ - public boolean isLocal() { - return isLocal; - } - - public int targetTypeValue() { - return this.targetTypeValue; - } - - private static final TargetType[] targets; - - static { - targets = new TargetType[MAXIMUM_TARGET_TYPE_VALUE + 1]; - TargetType[] alltargets = values(); - for (TargetType target : alltargets) { - if (target.targetTypeValue != UNKNOWN.targetTypeValue) - targets[target.targetTypeValue] = target; - } - for (int i = 0; i <= MAXIMUM_TARGET_TYPE_VALUE; ++i) { - if (targets[i] == null) - targets[i] = UNKNOWN; - } - } - - public static boolean isValidTargetTypeValue(int tag) { - if (tag == UNKNOWN.targetTypeValue) - return true; - return (tag >= 0 && tag < targets.length); - } - - public static TargetType fromTargetTypeValue(int tag) { - if (tag == UNKNOWN.targetTypeValue) - return UNKNOWN; - - if (tag < 0 || tag >= targets.length) - throw new AssertionError("Unknown TargetType: " + tag); - return targets[tag]; - } - } -} diff --git a/src/jdk.jdeps/share/classes/com/sun/tools/classfile/package-info.java b/src/jdk.jdeps/share/classes/com/sun/tools/classfile/package-info.java deleted file mode 100644 index 505c1a7e03d93..0000000000000 --- a/src/jdk.jdeps/share/classes/com/sun/tools/classfile/package-info.java +++ /dev/null @@ -1,36 +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. - */ - -/** - A minimalist library to read and write class files into objects closely - based on the corresponding definitions in - The Java Virtual Machine Specification (JVMS). - -

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. -*/ -package com.sun.tools.classfile; diff --git a/src/jdk.jdeps/share/classes/module-info.java b/src/jdk.jdeps/share/classes/module-info.java index 3fdd3ca32d270..3c15c3330c7ac 100644 --- a/src/jdk.jdeps/share/classes/module-info.java +++ b/src/jdk.jdeps/share/classes/module-info.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2025, 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 @@ -70,8 +70,6 @@ uses com.sun.tools.javac.platform.PlatformProvider; - exports com.sun.tools.classfile to jdk.jlink; - provides java.util.spi.ToolProvider with com.sun.tools.javap.Main.JavapToolProvider, com.sun.tools.jdeps.Main.JDepsToolProvider, diff --git a/test/langtools/tools/javac/generics/wildcards/separate_compilation/WildcardBoundsNotReadFromClassFileTest.java b/test/langtools/tools/javac/generics/wildcards/separate_compilation/WildcardBoundsNotReadFromClassFileTest.java index 6d44f7ccf1e4e..ec28c274e7dbb 100644 --- a/test/langtools/tools/javac/generics/wildcards/separate_compilation/WildcardBoundsNotReadFromClassFileTest.java +++ b/test/langtools/tools/javac/generics/wildcards/separate_compilation/WildcardBoundsNotReadFromClassFileTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2024, 2025, 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 @@ -32,7 +32,6 @@ * jdk.compiler/com.sun.tools.javac.api * jdk.compiler/com.sun.tools.javac.file * jdk.compiler/com.sun.tools.javac.main - * jdk.jdeps/com.sun.tools.classfile * @build toolbox.ToolBox toolbox.JavacTask * @run main WildcardBoundsNotReadFromClassFileTest */ @@ -42,7 +41,6 @@ import com.sun.tools.javac.code.Flags; import com.sun.tools.javac.util.Assert; -import com.sun.tools.classfile.ClassFile; import toolbox.TestRunner; import toolbox.ToolBox;