Skip to content

Commit

Permalink
Upgrade to ASM master (including early support for Java 23 bytecode)
Browse files Browse the repository at this point in the history
Closes gh-31929
  • Loading branch information
jhoeller committed Dec 31, 2023
1 parent 243ec88 commit 174eae3
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ static AnnotationWriter create(
// Write type_index and reserve space for num_element_value_pairs.
annotation.putShort(symbolTable.addConstantUtf8(descriptor)).putShort(0);
return new AnnotationWriter(
symbolTable, /* useNamedValues = */ true, annotation, previousAnnotation);
symbolTable, /* useNamedValues= */ true, annotation, previousAnnotation);
}

/**
Expand Down Expand Up @@ -179,7 +179,7 @@ static AnnotationWriter create(
// Write type_index and reserve space for num_element_value_pairs.
typeAnnotation.putShort(symbolTable.addConstantUtf8(descriptor)).putShort(0);
return new AnnotationWriter(
symbolTable, /* useNamedValues = */ true, typeAnnotation, previousAnnotation);
symbolTable, /* useNamedValues= */ true, typeAnnotation, previousAnnotation);
}

// -----------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -284,7 +284,7 @@ public AnnotationVisitor visitAnnotation(final String name, final String descrip
}
// Write tag and type_index, and reserve 2 bytes for num_element_value_pairs.
annotation.put12('@', symbolTable.addConstantUtf8(descriptor)).putShort(0);
return new AnnotationWriter(symbolTable, /* useNamedValues = */ true, annotation, null);
return new AnnotationWriter(symbolTable, /* useNamedValues= */ true, annotation, null);
}

@Override
Expand All @@ -303,7 +303,7 @@ public AnnotationVisitor visitArray(final String name) {
// visit the array elements. Its num_element_value_pairs will correspond to the number of array
// elements and will be stored in what is in fact num_values.
annotation.put12('[', 0);
return new AnnotationWriter(symbolTable, /* useNamedValues = */ false, annotation, null);
return new AnnotationWriter(symbolTable, /* useNamedValues= */ false, annotation, null);
}

@Override
Expand Down
109 changes: 53 additions & 56 deletions spring-core/src/main/java/org/springframework/asm/ClassReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ public ClassReader(
final byte[] classFileBuffer,
final int classFileOffset,
final int classFileLength) { // NOPMD(UnusedFormalParameter) used for backward compatibility.
this(classFileBuffer, classFileOffset, /* checkClassVersion = */ true);
this(classFileBuffer, classFileOffset, /* checkClassVersion= */ true);
}

/**
Expand All @@ -194,7 +194,7 @@ public ClassReader(
this.b = classFileBuffer;
// Check the class' major_version. This field is after the magic and minor_version fields, which
// use 4 and 2 bytes respectively.
if (checkClassVersion && readShort(classFileOffset + 6) > Opcodes.V22) {
if (checkClassVersion && readShort(classFileOffset + 6) > Opcodes.V23) {
throw new IllegalArgumentException(
"Unsupported class file major version " + readShort(classFileOffset + 6));
}
Expand Down Expand Up @@ -608,9 +608,9 @@ public void accept(
// Parse num_element_value_pairs and element_value_pairs and visit these values.
currentAnnotationOffset =
readElementValues(
classVisitor.visitAnnotation(annotationDescriptor, /* visible = */ true),
classVisitor.visitAnnotation(annotationDescriptor, /* visible= */ true),
currentAnnotationOffset,
/* named = */ true,
/* named= */ true,
charBuffer);
}
}
Expand All @@ -626,9 +626,9 @@ public void accept(
// Parse num_element_value_pairs and element_value_pairs and visit these values.
currentAnnotationOffset =
readElementValues(
classVisitor.visitAnnotation(annotationDescriptor, /* visible = */ false),
classVisitor.visitAnnotation(annotationDescriptor, /* visible= */ false),
currentAnnotationOffset,
/* named = */ true,
/* named= */ true,
charBuffer);
}
}
Expand All @@ -650,9 +650,9 @@ public void accept(
context.currentTypeAnnotationTarget,
context.currentTypeAnnotationTargetPath,
annotationDescriptor,
/* visible = */ true),
/* visible= */ true),
currentAnnotationOffset,
/* named = */ true,
/* named= */ true,
charBuffer);
}
}
Expand All @@ -674,9 +674,9 @@ public void accept(
context.currentTypeAnnotationTarget,
context.currentTypeAnnotationTargetPath,
annotationDescriptor,
/* visible = */ false),
/* visible= */ false),
currentAnnotationOffset,
/* named = */ true,
/* named= */ true,
charBuffer);
}
}
Expand Down Expand Up @@ -968,9 +968,9 @@ private int readRecordComponent(
// Parse num_element_value_pairs and element_value_pairs and visit these values.
currentAnnotationOffset =
readElementValues(
recordComponentVisitor.visitAnnotation(annotationDescriptor, /* visible = */ true),
recordComponentVisitor.visitAnnotation(annotationDescriptor, /* visible= */ true),
currentAnnotationOffset,
/* named = */ true,
/* named= */ true,
charBuffer);
}
}
Expand All @@ -986,9 +986,9 @@ private int readRecordComponent(
// Parse num_element_value_pairs and element_value_pairs and visit these values.
currentAnnotationOffset =
readElementValues(
recordComponentVisitor.visitAnnotation(annotationDescriptor, /* visible = */ false),
recordComponentVisitor.visitAnnotation(annotationDescriptor, /* visible= */ false),
currentAnnotationOffset,
/* named = */ true,
/* named= */ true,
charBuffer);
}
}
Expand All @@ -1010,9 +1010,9 @@ private int readRecordComponent(
context.currentTypeAnnotationTarget,
context.currentTypeAnnotationTargetPath,
annotationDescriptor,
/* visible = */ true),
/* visible= */ true),
currentAnnotationOffset,
/* named = */ true,
/* named= */ true,
charBuffer);
}
}
Expand All @@ -1034,9 +1034,9 @@ private int readRecordComponent(
context.currentTypeAnnotationTarget,
context.currentTypeAnnotationTargetPath,
annotationDescriptor,
/* visible = */ false),
/* visible= */ false),
currentAnnotationOffset,
/* named = */ true,
/* named= */ true,
charBuffer);
}
}
Expand Down Expand Up @@ -1152,9 +1152,9 @@ private int readField(
// Parse num_element_value_pairs and element_value_pairs and visit these values.
currentAnnotationOffset =
readElementValues(
fieldVisitor.visitAnnotation(annotationDescriptor, /* visible = */ true),
fieldVisitor.visitAnnotation(annotationDescriptor, /* visible= */ true),
currentAnnotationOffset,
/* named = */ true,
/* named= */ true,
charBuffer);
}
}
Expand All @@ -1170,9 +1170,9 @@ private int readField(
// Parse num_element_value_pairs and element_value_pairs and visit these values.
currentAnnotationOffset =
readElementValues(
fieldVisitor.visitAnnotation(annotationDescriptor, /* visible = */ false),
fieldVisitor.visitAnnotation(annotationDescriptor, /* visible= */ false),
currentAnnotationOffset,
/* named = */ true,
/* named= */ true,
charBuffer);
}
}
Expand All @@ -1194,9 +1194,9 @@ private int readField(
context.currentTypeAnnotationTarget,
context.currentTypeAnnotationTargetPath,
annotationDescriptor,
/* visible = */ true),
/* visible= */ true),
currentAnnotationOffset,
/* named = */ true,
/* named= */ true,
charBuffer);
}
}
Expand All @@ -1218,9 +1218,9 @@ private int readField(
context.currentTypeAnnotationTarget,
context.currentTypeAnnotationTargetPath,
annotationDescriptor,
/* visible = */ false),
/* visible= */ false),
currentAnnotationOffset,
/* named = */ true,
/* named= */ true,
charBuffer);
}
}
Expand Down Expand Up @@ -1413,9 +1413,9 @@ private int readMethod(
// Parse num_element_value_pairs and element_value_pairs and visit these values.
currentAnnotationOffset =
readElementValues(
methodVisitor.visitAnnotation(annotationDescriptor, /* visible = */ true),
methodVisitor.visitAnnotation(annotationDescriptor, /* visible= */ true),
currentAnnotationOffset,
/* named = */ true,
/* named= */ true,
charBuffer);
}
}
Expand All @@ -1431,9 +1431,9 @@ private int readMethod(
// Parse num_element_value_pairs and element_value_pairs and visit these values.
currentAnnotationOffset =
readElementValues(
methodVisitor.visitAnnotation(annotationDescriptor, /* visible = */ false),
methodVisitor.visitAnnotation(annotationDescriptor, /* visible= */ false),
currentAnnotationOffset,
/* named = */ true,
/* named= */ true,
charBuffer);
}
}
Expand All @@ -1455,9 +1455,9 @@ private int readMethod(
context.currentTypeAnnotationTarget,
context.currentTypeAnnotationTargetPath,
annotationDescriptor,
/* visible = */ true),
/* visible= */ true),
currentAnnotationOffset,
/* named = */ true,
/* named= */ true,
charBuffer);
}
}
Expand All @@ -1479,26 +1479,23 @@ private int readMethod(
context.currentTypeAnnotationTarget,
context.currentTypeAnnotationTargetPath,
annotationDescriptor,
/* visible = */ false),
/* visible= */ false),
currentAnnotationOffset,
/* named = */ true,
/* named= */ true,
charBuffer);
}
}

// Visit the RuntimeVisibleParameterAnnotations attribute.
if (runtimeVisibleParameterAnnotationsOffset != 0) {
readParameterAnnotations(
methodVisitor, context, runtimeVisibleParameterAnnotationsOffset, /* visible = */ true);
methodVisitor, context, runtimeVisibleParameterAnnotationsOffset, /* visible= */ true);
}

// Visit the RuntimeInvisibleParameterAnnotations attribute.
if (runtimeInvisibleParameterAnnotationsOffset != 0) {
readParameterAnnotations(
methodVisitor,
context,
runtimeInvisibleParameterAnnotationsOffset,
/* visible = */ false);
methodVisitor, context, runtimeInvisibleParameterAnnotationsOffset, /* visible= */ false);
}

// Visit the non standard attributes.
Expand Down Expand Up @@ -1927,7 +1924,7 @@ private void readCode(
}
} else if (Constants.RUNTIME_VISIBLE_TYPE_ANNOTATIONS.equals(attributeName)) {
visibleTypeAnnotationOffsets =
readTypeAnnotations(methodVisitor, context, currentOffset, /* visible = */ true);
readTypeAnnotations(methodVisitor, context, currentOffset, /* visible= */ true);
// Here we do not extract the labels corresponding to the attribute content. This would
// require a full parsing of the attribute, which would need to be repeated when parsing
// the bytecode instructions (see below). Instead, the content of the attribute is read one
Expand All @@ -1936,7 +1933,7 @@ private void readCode(
// time. This assumes that type annotations are ordered by increasing bytecode offset.
} else if (Constants.RUNTIME_INVISIBLE_TYPE_ANNOTATIONS.equals(attributeName)) {
invisibleTypeAnnotationOffsets =
readTypeAnnotations(methodVisitor, context, currentOffset, /* visible = */ false);
readTypeAnnotations(methodVisitor, context, currentOffset, /* visible= */ false);
// Same comment as above for the RuntimeVisibleTypeAnnotations attribute.
} else if (Constants.STACK_MAP_TABLE.equals(attributeName)) {
if ((context.parsingOptions & SKIP_FRAMES) == 0) {
Expand Down Expand Up @@ -2518,9 +2515,9 @@ private void readCode(
context.currentTypeAnnotationTarget,
context.currentTypeAnnotationTargetPath,
annotationDescriptor,
/* visible = */ true),
/* visible= */ true),
currentAnnotationOffset,
/* named = */ true,
/* named= */ true,
charBuffer);
}
currentVisibleTypeAnnotationBytecodeOffset =
Expand All @@ -2546,9 +2543,9 @@ private void readCode(
context.currentTypeAnnotationTarget,
context.currentTypeAnnotationTargetPath,
annotationDescriptor,
/* visible = */ false),
/* visible= */ false),
currentAnnotationOffset,
/* named = */ true,
/* named= */ true,
charBuffer);
}
currentInvisibleTypeAnnotationBytecodeOffset =
Expand Down Expand Up @@ -2619,9 +2616,9 @@ private void readCode(
context.currentLocalVariableAnnotationRangeEnds,
context.currentLocalVariableAnnotationRangeIndices,
annotationDescriptor,
/* visible = */ true),
/* visible= */ true),
currentOffset,
/* named = */ true,
/* named= */ true,
charBuffer);
}
}
Expand All @@ -2647,9 +2644,9 @@ private void readCode(
context.currentLocalVariableAnnotationRangeEnds,
context.currentLocalVariableAnnotationRangeIndices,
annotationDescriptor,
/* visible = */ false),
/* visible= */ false),
currentOffset,
/* named = */ true,
/* named= */ true,
charBuffer);
}
}
Expand Down Expand Up @@ -2827,7 +2824,7 @@ private int[] readTypeAnnotations(
methodVisitor.visitTryCatchAnnotation(
targetType & 0xFFFFFF00, path, annotationDescriptor, visible),
currentOffset,
/* named = */ true,
/* named= */ true,
charBuffer);
} else {
// We don't want to visit the other target_type annotations, so we just skip them (which
Expand All @@ -2838,7 +2835,7 @@ private int[] readTypeAnnotations(
// with a null AnnotationVisitor).
currentOffset =
readElementValues(
/* annotationVisitor = */ null, currentOffset, /* named = */ true, charBuffer);
/* annotationVisitor= */ null, currentOffset, /* named= */ true, charBuffer);
}
}
return typeAnnotationsOffsets;
Expand Down Expand Up @@ -2978,7 +2975,7 @@ private void readParameterAnnotations(
readElementValues(
methodVisitor.visitParameterAnnotation(i, annotationDescriptor, visible),
currentOffset,
/* named = */ true,
/* named= */ true,
charBuffer);
}
}
Expand Down Expand Up @@ -3048,9 +3045,9 @@ private int readElementValue(
case 'e': // enum_const_value
return currentOffset + 5;
case '@': // annotation_value
return readElementValues(null, currentOffset + 3, /* named = */ true, charBuffer);
return readElementValues(null, currentOffset + 3, /* named= */ true, charBuffer);
case '[': // array_value
return readElementValues(null, currentOffset + 1, /* named = */ false, charBuffer);
return readElementValues(null, currentOffset + 1, /* named= */ false, charBuffer);
default:
return currentOffset + 3;
}
Expand Down Expand Up @@ -3118,7 +3115,7 @@ private int readElementValue(
return readElementValues(
annotationVisitor.visitArray(elementName),
currentOffset - 2,
/* named = */ false,
/* named= */ false,
charBuffer);
}
switch (classFileBuffer[currentOffset] & 0xFF) {
Expand Down Expand Up @@ -3195,7 +3192,7 @@ private int readElementValue(
readElementValues(
annotationVisitor.visitArray(elementName),
currentOffset - 2,
/* named = */ false,
/* named= */ false,
charBuffer);
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -774,7 +774,7 @@ private byte[] replaceAsmInstructions(final byte[] classFile, final boolean hasF
lastRecordComponent = null;
firstAttribute = null;
compute = hasFrames ? MethodWriter.COMPUTE_INSERTED_FRAMES : MethodWriter.COMPUTE_NOTHING;
new ClassReader(classFile, 0, /* checkClassVersion = */ false)
new ClassReader(classFile, 0, /* checkClassVersion= */ false)
.accept(
this,
attributes,
Expand Down
Loading

0 comments on commit 174eae3

Please sign in to comment.