-
CSR
-
Resolution: Unresolved
-
P4
-
None
-
behavioral
-
low
-
-
Java API
-
SE
Summary
Deliver CustomAttribute
and UnknownAttribute
in the streaming traversal of CodeModel
as a CompoundElement
, and adapt the labels in a StackMapTableAttribute
when an existing one is sent to another CodeBuilder
with incompatible labels.
Problem
UnknownAttribute
andCustomAttribute
are not delivered in the traversal of aCodeModel
, and can only be accessed via the functionalites ofAttributedElement
. They are, however, delivered in the traversal ofClassModel
,FieldModel
, orMethodModel
. Discussions revealed that this was probably an oversight in implementation instead of a deliberate design decison.StackMapTableAttribute
may become invalid if it is reused after a code transformation. It should be expanded to refer to correct updated code labels/offsets. Other code-bound attributes are modeled asPseudoInstruction
, andCodeBuilder
does not accept those code-bound attributes and we do not need to update them.
Solution
- Start delivering
CustomAttribute
andUnknownAttribute
in code model traversal, and remove the text about their non-delivery; makeUnknownAttribute
extendCodeElement
so it becomes eligible for delivery. - When the labels in a
CodeBuilder
is not compatible with the original labels from a parsedStackMapTableAttribute
, expand this attribute and rewrite its labels to restore its validity. (SeeAttributeMapper.AttributeStability.LABELS
for more details) Other attribute are already automatically rewritten as they are decomposed intoPseudoInstruction
and reconstructed unconditionally.
Specification
diff --git a/src/java.base/share/classes/java/lang/classfile/CodeElement.java b/src/java.base/share/classes/java/lang/classfile/CodeElement.java
index 9ca5138334403..3ad2ff16b355b 100644
--- a/src/java.base/share/classes/java/lang/classfile/CodeElement.java
+++ b/src/java.base/share/classes/java/lang/classfile/CodeElement.java
@@ -49,5 +50,5 @@
public sealed interface CodeElement extends ClassFileElement
permits Instruction, PseudoInstruction,
CustomAttribute, RuntimeVisibleTypeAnnotationsAttribute, RuntimeInvisibleTypeAnnotationsAttribute,
- StackMapTableAttribute {
+ StackMapTableAttribute, UnknownAttribute {
}
diff --git a/src/java.base/share/classes/java/lang/classfile/CustomAttribute.java b/src/java.base/share/classes/java/lang/classfile/CustomAttribute.java
index 9f924588770cd..c4d34d75dd5d6 100644
--- a/src/java.base/share/classes/java/lang/classfile/CustomAttribute.java
+++ b/src/java.base/share/classes/java/lang/classfile/CustomAttribute.java
@@ -36,9 +36,6 @@
* by {@link #attributeMapper}, and registered to the {@link
* ClassFile.AttributeMapperOption} so the user-defined attributes can be read.
* <p>
- * User-defined attributes are currently not delivered in the traversal of a
- * {@link CodeModel}.
- * <p>
* Accessor methods on user-defined attributes read from {@code class} files
* may throw {@link IllegalArgumentException} if the attribute model is lazily
* evaluated, and the evaluation encounters malformed {@code class} file format
diff --git a/src/java.base/share/classes/java/lang/classfile/attribute/UnknownAttribute.java b/src/java.base/share/classes/java/lang/classfile/attribute/UnknownAttribute.java
index c35942bc42c86..28a6e9e183a3e 100644
--- a/src/java.base/share/classes/java/lang/classfile/attribute/UnknownAttribute.java
+++ b/src/java.base/share/classes/java/lang/classfile/attribute/UnknownAttribute.java
@@ -35,8 +35,6 @@
* unknown if it is not recognized by one of the mappers in {@link Attributes}
* and is not recognized by the {@link ClassFile.AttributesProcessingOption}.
* <p>
- * This attribute is not delivered in the traversal of a {@link CodeModel}.
- * <p>
* An unknown attribute may appear anywhere where an attribute may appear, and
* has an {@linkplain AttributeStability#UNKNOWN unknown} data dependency.
*
@@ -45,7 +43,7 @@
*/
public sealed interface UnknownAttribute
extends Attribute<UnknownAttribute>,
- ClassElement, MethodElement, FieldElement
+ ClassElement, MethodElement, FieldElement, CodeElement
permits BoundAttribute.BoundUnknownAttribute {
/**
- csr of
-
JDK-8347472 Correct Attribute traversal and writing for Code attributes
-
- In Progress
-