8335905: CompoundElement API cleanup
Reviewed-by: asotona
This commit is contained in:
parent
6f325db493
commit
a9f5e76a65
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2022, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -89,7 +89,7 @@ public sealed interface ClassFileBuilder<E extends ClassFileElement, B extends C
|
|||||||
B builder = (B) this;
|
B builder = (B) this;
|
||||||
var resolved = transform.resolve(builder);
|
var resolved = transform.resolve(builder);
|
||||||
resolved.startHandler().run();
|
resolved.startHandler().run();
|
||||||
model.forEachElement(resolved.consumer());
|
model.forEach(resolved.consumer());
|
||||||
resolved.endHandler().run();
|
resolved.endHandler().run();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2022, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -37,7 +37,7 @@ import jdk.internal.javac.PreviewFeature;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Models a classfile. The contents of the classfile can be traversed via
|
* Models a classfile. The contents of the classfile can be traversed via
|
||||||
* a streaming view (e.g., {@link #elements()}), or via random access (e.g.,
|
* a streaming view, or via random access (e.g.,
|
||||||
* {@link #flags()}), or by freely mixing the two.
|
* {@link #flags()}), or by freely mixing the two.
|
||||||
*
|
*
|
||||||
* @since 22
|
* @since 22
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2022, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -36,8 +36,7 @@ import jdk.internal.javac.PreviewFeature;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Models the body of a method (the {@code Code} attribute). The instructions
|
* Models the body of a method (the {@code Code} attribute). The instructions
|
||||||
* of the method body are accessed via a streaming view (e.g., {@link
|
* of the method body are accessed via a streaming view.
|
||||||
* #elements()}).
|
|
||||||
*
|
*
|
||||||
* @since 22
|
* @since 22
|
||||||
*/
|
*/
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2022, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -40,7 +40,7 @@ import jdk.internal.javac.PreviewFeature;
|
|||||||
* class. When encountering a {@linkplain CompoundElement}, clients have the
|
* class. When encountering a {@linkplain CompoundElement}, clients have the
|
||||||
* option to treat the element as a single entity (e.g., an entire method)
|
* option to treat the element as a single entity (e.g., an entire method)
|
||||||
* or to traverse the contents of that element with the methods in this class
|
* or to traverse the contents of that element with the methods in this class
|
||||||
* (e.g., {@link #elements()}, {@link #forEachElement(Consumer)}, etc.)
|
* (e.g., {@link #forEach(Consumer)}, etc.)
|
||||||
* @param <E> the element type
|
* @param <E> the element type
|
||||||
*
|
*
|
||||||
* @sealedGraph
|
* @sealedGraph
|
||||||
@ -55,15 +55,8 @@ public sealed interface CompoundElement<E extends ClassFileElement>
|
|||||||
* compound element
|
* compound element
|
||||||
* @param consumer the handler
|
* @param consumer the handler
|
||||||
*/
|
*/
|
||||||
void forEachElement(Consumer<E> consumer);
|
@Override
|
||||||
|
void forEach(Consumer<? super E> consumer);
|
||||||
/**
|
|
||||||
* {@return an {@link Iterable} describing all the elements contained in this
|
|
||||||
* compound element}
|
|
||||||
*/
|
|
||||||
default Iterable<E> elements() {
|
|
||||||
return elementList();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@return an {@link Iterator} describing all the elements contained in this
|
* {@return an {@link Iterator} describing all the elements contained in this
|
||||||
@ -71,7 +64,7 @@ public sealed interface CompoundElement<E extends ClassFileElement>
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
default Iterator<E> iterator() {
|
default Iterator<E> iterator() {
|
||||||
return elements().iterator();
|
return elementList().iterator();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -91,7 +84,7 @@ public sealed interface CompoundElement<E extends ClassFileElement>
|
|||||||
*/
|
*/
|
||||||
default List<E> elementList() {
|
default List<E> elementList() {
|
||||||
List<E> list = new ArrayList<>();
|
List<E> list = new ArrayList<>();
|
||||||
forEachElement(new Consumer<>() {
|
forEach(new Consumer<>() {
|
||||||
@Override
|
@Override
|
||||||
public void accept(E e) {
|
public void accept(E e) {
|
||||||
list.add(e);
|
list.add(e);
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2022, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -35,7 +35,7 @@ import jdk.internal.javac.PreviewFeature;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Models a field. The contents of the field can be traversed via
|
* Models a field. The contents of the field can be traversed via
|
||||||
* a streaming view (e.g., {@link #elements()}), or via random access (e.g.,
|
* a streaming view, or via random access (e.g.,
|
||||||
* {@link #flags()}), or by freely mixing the two.
|
* {@link #flags()}), or by freely mixing the two.
|
||||||
*
|
*
|
||||||
* @since 22
|
* @since 22
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2022, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -35,7 +35,7 @@ import jdk.internal.javac.PreviewFeature;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Models a method. The contents of the method can be traversed via
|
* Models a method. The contents of the method can be traversed via
|
||||||
* a streaming view (e.g., {@link #elements()}), or via random access (e.g.,
|
* a streaming view, or via random access (e.g.,
|
||||||
* {@link #flags()}), or by freely mixing the two.
|
* {@link #flags()}), or by freely mixing the two.
|
||||||
*
|
*
|
||||||
* @since 22
|
* @since 22
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2022, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -45,7 +45,7 @@ public abstract sealed class AbstractUnboundModel<E extends ClassFileElement>
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void forEachElement(Consumer<E> consumer) {
|
public void forEach(Consumer<? super E> consumer) {
|
||||||
elements.forEach(consumer);
|
elements.forEach(consumer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -201,7 +201,7 @@ public final class BufferedCodeBuilder
|
|||||||
builder.withCode(new Consumer<>() {
|
builder.withCode(new Consumer<>() {
|
||||||
@Override
|
@Override
|
||||||
public void accept(CodeBuilder cb) {
|
public void accept(CodeBuilder cb) {
|
||||||
forEachElement(cb);
|
forEach(cb);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2022, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -200,7 +200,7 @@ public final class BufferedMethodBuilder
|
|||||||
builder.withMethod(methodName(), methodType(), methodFlags(), new Consumer<>() {
|
builder.withMethod(methodName(), methodType(), methodFlags(), new Consumer<>() {
|
||||||
@Override
|
@Override
|
||||||
public void accept(MethodBuilder mb) {
|
public void accept(MethodBuilder mb) {
|
||||||
forEachElement(mb);
|
forEach(mb);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -156,7 +156,7 @@ public final class ClassImpl
|
|||||||
// ClassModel
|
// ClassModel
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void forEachElement(Consumer<ClassElement> consumer) {
|
public void forEach(Consumer<? super ClassElement> consumer) {
|
||||||
consumer.accept(flags());
|
consumer.accept(flags());
|
||||||
consumer.accept(ClassFileVersion.of(majorVersion(), minorVersion()));
|
consumer.accept(ClassFileVersion.of(majorVersion(), minorVersion()));
|
||||||
superclass().ifPresent(new Consumer<ClassEntry>() {
|
superclass().ifPresent(new Consumer<ClassEntry>() {
|
||||||
|
@ -97,12 +97,10 @@ public record ClassRemapperImpl(Function<ClassDesc, ClassDesc> mapFunction) impl
|
|||||||
switch (cle) {
|
switch (cle) {
|
||||||
case FieldModel fm ->
|
case FieldModel fm ->
|
||||||
clb.withField(fm.fieldName().stringValue(), map(
|
clb.withField(fm.fieldName().stringValue(), map(
|
||||||
fm.fieldTypeSymbol()), fb ->
|
fm.fieldTypeSymbol()), fb -> fb.transform(fm, asFieldTransform()));
|
||||||
fm.forEachElement(asFieldTransform().resolve(fb).consumer()));
|
|
||||||
case MethodModel mm ->
|
case MethodModel mm ->
|
||||||
clb.withMethod(mm.methodName().stringValue(), mapMethodDesc(
|
clb.withMethod(mm.methodName().stringValue(), mapMethodDesc(
|
||||||
mm.methodTypeSymbol()), mm.flags().flagsMask(), mb ->
|
mm.methodTypeSymbol()), mm.flags().flagsMask(), mb -> mb.transform(mm, asMethodTransform()));
|
||||||
mm.forEachElement(asMethodTransform().resolve(mb).consumer()));
|
|
||||||
case Superclass sc ->
|
case Superclass sc ->
|
||||||
clb.withSuperclass(map(sc.superclassEntry().asSymbol()));
|
clb.withSuperclass(map(sc.superclassEntry().asSymbol()));
|
||||||
case Interfaces ins ->
|
case Interfaces ins ->
|
||||||
|
@ -27,6 +27,7 @@ package jdk.internal.classfile.impl;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
@ -149,7 +150,7 @@ public final class CodeImpl
|
|||||||
new Consumer<CodeBuilder>() {
|
new Consumer<CodeBuilder>() {
|
||||||
@Override
|
@Override
|
||||||
public void accept(CodeBuilder cb) {
|
public void accept(CodeBuilder cb) {
|
||||||
forEachElement(cb);
|
forEach(cb);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
(SplitConstantPool)buf.constantPool(),
|
(SplitConstantPool)buf.constantPool(),
|
||||||
@ -166,7 +167,8 @@ public final class CodeImpl
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void forEachElement(Consumer<CodeElement> consumer) {
|
public void forEach(Consumer<? super CodeElement> consumer) {
|
||||||
|
Objects.requireNonNull(consumer);
|
||||||
inflateMetadata();
|
inflateMetadata();
|
||||||
boolean doLineNumbers = (lineNumbers != null);
|
boolean doLineNumbers = (lineNumbers != null);
|
||||||
generateCatchTargets(consumer);
|
generateCatchTargets(consumer);
|
||||||
@ -329,7 +331,7 @@ public final class CodeImpl
|
|||||||
findAttribute(Attributes.runtimeInvisibleTypeAnnotations()).ifPresent(RuntimeInvisibleTypeAnnotationsAttribute::annotations);
|
findAttribute(Attributes.runtimeInvisibleTypeAnnotations()).ifPresent(RuntimeInvisibleTypeAnnotationsAttribute::annotations);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void generateCatchTargets(Consumer<CodeElement> consumer) {
|
private void generateCatchTargets(Consumer<? super CodeElement> consumer) {
|
||||||
// We attach all catch targets to bci zero, because trying to attach them
|
// We attach all catch targets to bci zero, because trying to attach them
|
||||||
// to their range could subtly affect the order of exception processing
|
// to their range could subtly affect the order of exception processing
|
||||||
iterateExceptionHandlers(new ExceptionHandlerAction() {
|
iterateExceptionHandlers(new ExceptionHandlerAction() {
|
||||||
@ -343,7 +345,7 @@ public final class CodeImpl
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void generateDebugElements(Consumer<CodeElement> consumer) {
|
private void generateDebugElements(Consumer<? super CodeElement> consumer) {
|
||||||
for (Attribute<?> a : attributes()) {
|
for (Attribute<?> a : attributes()) {
|
||||||
if (a.attributeMapper() == Attributes.characterRangeTable()) {
|
if (a.attributeMapper() == Attributes.characterRangeTable()) {
|
||||||
var attr = (BoundCharacterRangeTableAttribute) a;
|
var attr = (BoundCharacterRangeTableAttribute) a;
|
||||||
|
@ -101,14 +101,14 @@ public final class FieldImpl
|
|||||||
builder.withField(fieldName(), fieldType(), new Consumer<>() {
|
builder.withField(fieldName(), fieldType(), new Consumer<>() {
|
||||||
@Override
|
@Override
|
||||||
public void accept(FieldBuilder fb) {
|
public void accept(FieldBuilder fb) {
|
||||||
FieldImpl.this.forEachElement(fb);
|
FieldImpl.this.forEach(fb);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void forEachElement(Consumer<FieldElement> consumer) {
|
public void forEach(Consumer<? super FieldElement> consumer) {
|
||||||
consumer.accept(flags());
|
consumer.accept(flags());
|
||||||
for (Attribute<?> attr : attributes()) {
|
for (Attribute<?> attr : attributes()) {
|
||||||
if (attr instanceof FieldElement e)
|
if (attr instanceof FieldElement e)
|
||||||
|
@ -122,7 +122,7 @@ public final class MethodImpl
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void forEachElement(Consumer<MethodElement> consumer) {
|
public void forEach(Consumer<? super MethodElement> consumer) {
|
||||||
consumer.accept(flags());
|
consumer.accept(flags());
|
||||||
for (Attribute<?> attr : attributes()) {
|
for (Attribute<?> attr : attributes()) {
|
||||||
if (attr instanceof MethodElement e)
|
if (attr instanceof MethodElement e)
|
||||||
@ -140,7 +140,7 @@ public final class MethodImpl
|
|||||||
new Consumer<>() {
|
new Consumer<>() {
|
||||||
@Override
|
@Override
|
||||||
public void accept(MethodBuilder mb) {
|
public void accept(MethodBuilder mb) {
|
||||||
MethodImpl.this.forEachElement(mb);
|
MethodImpl.this.forEach(mb);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2016, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -172,7 +172,7 @@ final class FingerPrint {
|
|||||||
cm.thisClass().asInternalName(),
|
cm.thisClass().asInternalName(),
|
||||||
cm.superclass().map(ClassEntry::asInternalName).orElse(null),
|
cm.superclass().map(ClassEntry::asInternalName).orElse(null),
|
||||||
cm.majorVersion());
|
cm.majorVersion());
|
||||||
cm.forEachElement(attrs);
|
cm.forEach(attrs);
|
||||||
return attrs;
|
return attrs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -222,7 +222,7 @@ final class EventInstrumentation {
|
|||||||
// Only supports String, String[] and Boolean values
|
// Only supports String, String[] and Boolean values
|
||||||
private static <T> T annotationValue(ClassModel classModel, ClassDesc classDesc, Class<T> type) {
|
private static <T> T annotationValue(ClassModel classModel, ClassDesc classDesc, Class<T> type) {
|
||||||
String typeDescriptor = classDesc.descriptorString();
|
String typeDescriptor = classDesc.descriptorString();
|
||||||
for (ClassElement ce : classModel.elements()) {
|
for (ClassElement ce : classModel) {
|
||||||
if (ce instanceof RuntimeVisibleAnnotationsAttribute rvaa) {
|
if (ce instanceof RuntimeVisibleAnnotationsAttribute rvaa) {
|
||||||
for (Annotation a : rvaa.annotations()) {
|
for (Annotation a : rvaa.annotations()) {
|
||||||
if (a.className().equalsString(typeDescriptor)) {
|
if (a.className().equalsString(typeDescriptor)) {
|
||||||
@ -260,7 +260,7 @@ final class EventInstrumentation {
|
|||||||
Set<String> methodSet = new HashSet<>();
|
Set<String> methodSet = new HashSet<>();
|
||||||
List<SettingDesc> settingDescs = new ArrayList<>();
|
List<SettingDesc> settingDescs = new ArrayList<>();
|
||||||
for (MethodModel m : classModel.methods()) {
|
for (MethodModel m : classModel.methods()) {
|
||||||
for (var me : m.elements()) {
|
for (var me : m) {
|
||||||
if (me instanceof RuntimeVisibleAnnotationsAttribute rvaa) {
|
if (me instanceof RuntimeVisibleAnnotationsAttribute rvaa) {
|
||||||
for (Annotation a : rvaa.annotations()) {
|
for (Annotation a : rvaa.annotations()) {
|
||||||
// We can't really validate the method at this
|
// We can't really validate the method at this
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2014, 2023, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2014, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -39,7 +39,6 @@ import java.util.MissingResourceException;
|
|||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
import java.lang.classfile.ClassModel;
|
|
||||||
import java.lang.classfile.ClassFile;
|
import java.lang.classfile.ClassFile;
|
||||||
import java.lang.classfile.CodeModel;
|
import java.lang.classfile.CodeModel;
|
||||||
import java.lang.classfile.MethodModel;
|
import java.lang.classfile.MethodModel;
|
||||||
@ -368,9 +367,9 @@ class JImageTask {
|
|||||||
if (name.endsWith(".class") && !name.endsWith("module-info.class")) {
|
if (name.endsWith(".class") && !name.endsWith("module-info.class")) {
|
||||||
try {
|
try {
|
||||||
byte[] bytes = reader.getResource(location);
|
byte[] bytes = reader.getResource(location);
|
||||||
ClassFile.of().parse(bytes).forEachElement(cle -> {
|
ClassFile.of().parse(bytes).forEach(cle -> {
|
||||||
if (cle instanceof MethodModel mm) mm.forEachElement(me -> {
|
if (cle instanceof MethodModel mm) mm.forEach(me -> {
|
||||||
if (me instanceof CodeModel com) com.forEachElement(coe -> {
|
if (me instanceof CodeModel com) com.forEach(coe -> {
|
||||||
//do nothing here, just visit each model element
|
//do nothing here, just visit each model element
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -133,7 +133,7 @@ public class Instrumentor {
|
|||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
builder.withMethod(newName, mt, mm.flags().flagsMask(), mm::forEachElement);
|
builder.withMethod(newName, mt, mm.flags().flagsMask(), mm::forEach);
|
||||||
} else {
|
} else {
|
||||||
builder.accept(element);
|
builder.accept(element);
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2013, 2023, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2013, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -63,7 +63,7 @@ public class MHIllegalAccess {
|
|||||||
*/
|
*/
|
||||||
ClassTransform changeName = (cb, ce) -> {
|
ClassTransform changeName = (cb, ce) -> {
|
||||||
if (ce instanceof MethodModel mm && mm.methodName().equalsString("m")) {
|
if (ce instanceof MethodModel mm && mm.methodName().equalsString("m")) {
|
||||||
cb.withMethod("nemo", mm.methodTypeSymbol(), mm.flags().flagsMask(), mm::forEachElement);
|
cb.withMethod("nemo", mm.methodTypeSymbol(), mm.flags().flagsMask(), mm::forEach);
|
||||||
} else {
|
} else {
|
||||||
cb.accept(ce);
|
cb.accept(ce);
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2013, 2023, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2013, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -100,7 +100,7 @@ public class LambdaAsm {
|
|||||||
|
|
||||||
static void checkMethod(String cname, String mname, ConstantPool cp,
|
static void checkMethod(String cname, String mname, ConstantPool cp,
|
||||||
CodeAttribute code) throws IllegalArgumentException {
|
CodeAttribute code) throws IllegalArgumentException {
|
||||||
for (var inst : code.elements()) {
|
for (var inst : code) {
|
||||||
if (inst instanceof InvokeInstruction inv && (inv.opcode() == Opcode.INVOKESPECIAL
|
if (inst instanceof InvokeInstruction inv && (inv.opcode() == Opcode.INVOKESPECIAL
|
||||||
|| inv.opcode() == Opcode.INVOKEINTERFACE)) {
|
|| inv.opcode() == Opcode.INVOKEINTERFACE)) {
|
||||||
var ref = inv.method();
|
var ref = inv.method();
|
||||||
|
@ -114,7 +114,7 @@ class AdaptCodeTest {
|
|||||||
void testCopy() throws Exception {
|
void testCopy() throws Exception {
|
||||||
var cc = ClassFile.of();
|
var cc = ClassFile.of();
|
||||||
ClassModel cm = cc.parse(testClassPath);
|
ClassModel cm = cc.parse(testClassPath);
|
||||||
byte[] newBytes = cc.build(cm.thisClass().asSymbol(), cb -> cm.forEachElement(cb));
|
byte[] newBytes = cc.build(cm.thisClass().asSymbol(), cm::forEach);
|
||||||
// TestUtil.writeClass(newBytes, "TestClass.class");
|
// TestUtil.writeClass(newBytes, "TestClass.class");
|
||||||
String result = (String)
|
String result = (String)
|
||||||
new ByteArrayClassLoader(AdaptCodeTest.class.getClassLoader(), testClassName, newBytes)
|
new ByteArrayClassLoader(AdaptCodeTest.class.getClassLoader(), testClassName, newBytes)
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2022, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -57,7 +57,7 @@ class BasicBlockTest {
|
|||||||
try (InputStream in = BasicBlockTest.class.getResourceAsStream("BasicBlockTest.class")) {
|
try (InputStream in = BasicBlockTest.class.getResourceAsStream("BasicBlockTest.class")) {
|
||||||
var cc = ClassFile.of();
|
var cc = ClassFile.of();
|
||||||
var classModel = cc.parse(in.readAllBytes());
|
var classModel = cc.parse(in.readAllBytes());
|
||||||
cc.build(classModel.thisClass().asSymbol(), cb -> classModel.forEachElement(cb));
|
cc.build(classModel.thisClass().asSymbol(), classModel::forEach);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -127,7 +127,7 @@ class ClassHierarchyInfoTest {
|
|||||||
if (cle instanceof MethodModel mm) {
|
if (cle instanceof MethodModel mm) {
|
||||||
clb.transformMethod(mm, (mb, me) -> {
|
clb.transformMethod(mm, (mb, me) -> {
|
||||||
if (me instanceof CodeModel cm) {
|
if (me instanceof CodeModel cm) {
|
||||||
mb.withCode(cob -> cm.forEachElement(cob));
|
mb.withCode(cm::forEach);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
mb.with(me);
|
mb.with(me);
|
||||||
|
@ -200,7 +200,7 @@ class CorpusTest {
|
|||||||
|
|
||||||
byte[] newBytes = cc.build(
|
byte[] newBytes = cc.build(
|
||||||
classModel.thisClass().asSymbol(),
|
classModel.thisClass().asSymbol(),
|
||||||
classModel::forEachElement);
|
classModel::forEach);
|
||||||
var newModel = cc.parse(newBytes);
|
var newModel = cc.parse(newBytes);
|
||||||
assertEqualsDeep(ClassRecord.ofClassModel(newModel, CompatibilityFilter.By_ClassBuilder),
|
assertEqualsDeep(ClassRecord.ofClassModel(newModel, CompatibilityFilter.By_ClassBuilder),
|
||||||
ClassRecord.ofClassModel(classModel, CompatibilityFilter.By_ClassBuilder),
|
ClassRecord.ofClassModel(classModel, CompatibilityFilter.By_ClassBuilder),
|
||||||
|
@ -88,7 +88,7 @@ class LvtTest {
|
|||||||
.orElseThrow();
|
.orElseThrow();
|
||||||
|
|
||||||
List<LocalVariable> lvs = new ArrayList<>();
|
List<LocalVariable> lvs = new ArrayList<>();
|
||||||
co.forEachElement(e -> {
|
co.forEach(e -> {
|
||||||
if (e instanceof LocalVariable l) lvs.add(l);
|
if (e instanceof LocalVariable l) lvs.add(l);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -198,7 +198,7 @@ class LvtTest {
|
|||||||
.orElseThrow();
|
.orElseThrow();
|
||||||
|
|
||||||
List<LocalVariableType> lvts = new ArrayList<>();
|
List<LocalVariableType> lvts = new ArrayList<>();
|
||||||
co.forEachElement(e -> {
|
co.forEach(e -> {
|
||||||
if (e instanceof LocalVariableType l) lvts.add(l);
|
if (e instanceof LocalVariableType l) lvts.add(l);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -304,11 +304,11 @@ class LvtTest {
|
|||||||
void skipDebugSkipsLVT() {
|
void skipDebugSkipsLVT() {
|
||||||
ClassModel c = ClassFile.of(ClassFile.DebugElementsOption.DROP_DEBUG).parse(fileBytes);
|
ClassModel c = ClassFile.of(ClassFile.DebugElementsOption.DROP_DEBUG).parse(fileBytes);
|
||||||
|
|
||||||
c.forEachElement(e -> {
|
c.forEach(e -> {
|
||||||
if (e instanceof MethodModel m) {
|
if (e instanceof MethodModel m) {
|
||||||
m.forEachElement(el -> {
|
m.forEach(el -> {
|
||||||
if (el instanceof CodeModel cm) {
|
if (el instanceof CodeModel cm) {
|
||||||
cm.forEachElement(elem -> {
|
cm.forEach(elem -> {
|
||||||
assertFalse(elem instanceof LocalVariable);
|
assertFalse(elem instanceof LocalVariable);
|
||||||
assertFalse(elem instanceof LocalVariableType);
|
assertFalse(elem instanceof LocalVariableType);
|
||||||
});
|
});
|
||||||
|
@ -117,6 +117,6 @@ class OptionsTest {
|
|||||||
if (e instanceof AttributedElement ae) ae.attributes().forEach(a ->
|
if (e instanceof AttributedElement ae) ae.attributes().forEach(a ->
|
||||||
assertTrue(AttributeMapper.AttributeStability.UNSTABLE.ordinal() >= a.attributeMapper().stability().ordinal(),
|
assertTrue(AttributeMapper.AttributeStability.UNSTABLE.ordinal() >= a.attributeMapper().stability().ordinal(),
|
||||||
() -> "class " + path + " contains unexpected " + a));
|
() -> "class " + path + " contains unexpected " + a));
|
||||||
if (e instanceof CompoundElement ce) ce.forEachElement(ee -> testNoUnstable(path, (ClassFileElement)ee));
|
if (e instanceof CompoundElement ce) ce.forEach(ee -> testNoUnstable(path, (ClassFileElement)ee));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -270,7 +270,7 @@ class StackMapsTest {
|
|||||||
// classModel.superclass().ifPresent(cb::withSuperclass);
|
// classModel.superclass().ifPresent(cb::withSuperclass);
|
||||||
// cb.withInterfaces(classModel.interfaces());
|
// cb.withInterfaces(classModel.interfaces());
|
||||||
// cb.withVersion(classModel.majorVersion(), classModel.minorVersion());
|
// cb.withVersion(classModel.majorVersion(), classModel.minorVersion());
|
||||||
classModel.forEachElement(cb);
|
classModel.forEach(cb);
|
||||||
});
|
});
|
||||||
|
|
||||||
//then verify transformed bytecode
|
//then verify transformed bytecode
|
||||||
|
@ -105,7 +105,7 @@ class TestRecordComponent {
|
|||||||
void testOptions() throws Exception {
|
void testOptions() throws Exception {
|
||||||
AtomicInteger count = new AtomicInteger(0);
|
AtomicInteger count = new AtomicInteger(0);
|
||||||
ClassModel cm = ClassFile.of().parse(Files.readAllBytes(testClassPath));
|
ClassModel cm = ClassFile.of().parse(Files.readAllBytes(testClassPath));
|
||||||
cm.forEachElement((ce) -> {
|
cm.forEach((ce) -> {
|
||||||
if (ce instanceof RecordAttribute rm) {
|
if (ce instanceof RecordAttribute rm) {
|
||||||
count.addAndGet(rm.components().size());
|
count.addAndGet(rm.components().size());
|
||||||
}});
|
}});
|
||||||
|
@ -79,7 +79,7 @@ class VerifierSelfTest {
|
|||||||
if (cle instanceof MethodModel mm) {
|
if (cle instanceof MethodModel mm) {
|
||||||
clb.transformMethod(mm, (mb, me) -> {
|
clb.transformMethod(mm, (mb, me) -> {
|
||||||
if (me instanceof CodeModel cm) {
|
if (me instanceof CodeModel cm) {
|
||||||
mb.withCode(cob -> cm.forEachElement(cob));
|
mb.withCode(cob -> cm.forEach(cob));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
mb.with(me);
|
mb.with(me);
|
||||||
|
@ -75,7 +75,7 @@ class RebuildingTransformation {
|
|||||||
cob2.transforming(new CodeRebuildingTransform(), cob3 ->
|
cob2.transforming(new CodeRebuildingTransform(), cob3 ->
|
||||||
// first pass transforms bound to unbound instructions
|
// first pass transforms bound to unbound instructions
|
||||||
cob3.transforming(new CodeRebuildingTransform(), cob4 -> {
|
cob3.transforming(new CodeRebuildingTransform(), cob4 -> {
|
||||||
com.forEachElement(cob4::with);
|
com.forEach(cob4::with);
|
||||||
com.findAttribute(Attributes.stackMapTable()).ifPresent(cob4::with);
|
com.findAttribute(Attributes.stackMapTable()).ifPresent(cob4::with);
|
||||||
}))));
|
}))));
|
||||||
case AnnotationDefaultAttribute a -> mb.with(AnnotationDefaultAttribute.of(transformAnnotationValue(a.defaultValue())));
|
case AnnotationDefaultAttribute a -> mb.with(AnnotationDefaultAttribute.of(transformAnnotationValue(a.defaultValue())));
|
||||||
|
@ -218,7 +218,7 @@ public class Transforms {
|
|||||||
if (me instanceof CodeModel xm) {
|
if (me instanceof CodeModel xm) {
|
||||||
mb.withCode(xb -> {
|
mb.withCode(xb -> {
|
||||||
xb.nop();
|
xb.nop();
|
||||||
xm.forEachElement(new Consumer<>() {
|
xm.forEach(new Consumer<>() {
|
||||||
@Override
|
@Override
|
||||||
public void accept(CodeElement e) {
|
public void accept(CodeElement e) {
|
||||||
xb.with(e);
|
xb.with(e);
|
||||||
@ -270,7 +270,7 @@ public class Transforms {
|
|||||||
ClassModel cm = cc.parse(bytes);
|
ClassModel cm = cc.parse(bytes);
|
||||||
return cc.build(cm.thisClass().asSymbol(),
|
return cc.build(cm.thisClass().asSymbol(),
|
||||||
cb -> {
|
cb -> {
|
||||||
cm.forEachElement(cb);
|
cm.forEach(cb);
|
||||||
cb.withField("argleBargleWoogaWooga", ConstantDescs.CD_int, b -> { });
|
cb.withField("argleBargleWoogaWooga", ConstantDescs.CD_int, b -> { });
|
||||||
});
|
});
|
||||||
}),
|
}),
|
||||||
@ -301,7 +301,7 @@ public class Transforms {
|
|||||||
ClassModel cm = cc.parse(bytes);
|
ClassModel cm = cc.parse(bytes);
|
||||||
return cc.build(cm.thisClass().asSymbol(),
|
return cc.build(cm.thisClass().asSymbol(),
|
||||||
cb -> {
|
cb -> {
|
||||||
cm.forEachElement(element -> {
|
cm.forEach(element -> {
|
||||||
if (element instanceof MethodModel mm
|
if (element instanceof MethodModel mm
|
||||||
&& mm.methodName().stringValue().equals("hashCode")
|
&& mm.methodName().stringValue().equals("hashCode")
|
||||||
&& mm.methodType().stringValue().equals("()Z")) {
|
&& mm.methodType().stringValue().equals("()Z")) {
|
||||||
|
@ -390,7 +390,7 @@ class InlineCalls {
|
|||||||
mm.methodTypeSymbol()
|
mm.methodTypeSymbol()
|
||||||
);
|
);
|
||||||
int offset = 0;
|
int offset = 0;
|
||||||
for (var ce : com.elements()) {
|
for (var ce : com) {
|
||||||
if (ce instanceof Instruction ins) {
|
if (ce instanceof Instruction ins) {
|
||||||
if (ins instanceof InvokeInstruction inv) {
|
if (ins instanceof InvokeInstruction inv) {
|
||||||
calls.add(new Call(caller, new MethodDesc(
|
calls.add(new Call(caller, new MethodDesc(
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2022, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -101,11 +101,11 @@ public class ReadDeep extends AbstractCorpusBenchmark {
|
|||||||
for (byte[] bytes : classes) {
|
for (byte[] bytes : classes) {
|
||||||
int[] count = new int[1];
|
int[] count = new int[1];
|
||||||
ClassModel cm = cc.parse(bytes);
|
ClassModel cm = cc.parse(bytes);
|
||||||
cm.forEachElement(ce -> {
|
cm.forEach(ce -> {
|
||||||
if (ce instanceof MethodModel mm) {
|
if (ce instanceof MethodModel mm) {
|
||||||
mm.forEachElement(me -> {
|
mm.forEach(me -> {
|
||||||
if (me instanceof CodeModel xm) {
|
if (me instanceof CodeModel xm) {
|
||||||
xm.forEachElement(xe -> {
|
xm.forEach(xe -> {
|
||||||
if (xe instanceof LoadInstruction) {
|
if (xe instanceof LoadInstruction) {
|
||||||
++count[0];
|
++count[0];
|
||||||
}
|
}
|
||||||
|
@ -204,7 +204,7 @@ public class Transforms {
|
|||||||
if (me instanceof CodeModel xm) {
|
if (me instanceof CodeModel xm) {
|
||||||
mb.withCode(xb -> {
|
mb.withCode(xb -> {
|
||||||
xb.nop();
|
xb.nop();
|
||||||
xm.forEachElement(new Consumer<>() {
|
xm.forEach(new Consumer<>() {
|
||||||
@Override
|
@Override
|
||||||
public void accept(CodeElement e) {
|
public void accept(CodeElement e) {
|
||||||
xb.with(e);
|
xb.with(e);
|
||||||
@ -256,7 +256,7 @@ public class Transforms {
|
|||||||
ClassModel cm = cc.parse(bytes);
|
ClassModel cm = cc.parse(bytes);
|
||||||
return cc.build(cm.thisClass().asSymbol(),
|
return cc.build(cm.thisClass().asSymbol(),
|
||||||
cb -> {
|
cb -> {
|
||||||
cm.forEachElement(cb);
|
cm.forEach(cb);
|
||||||
cb.withField("argleBargleWoogaWooga", ConstantDescs.CD_int, b -> { });
|
cb.withField("argleBargleWoogaWooga", ConstantDescs.CD_int, b -> { });
|
||||||
});
|
});
|
||||||
}),
|
}),
|
||||||
@ -287,7 +287,7 @@ public class Transforms {
|
|||||||
ClassModel cm = cc.parse(bytes);
|
ClassModel cm = cc.parse(bytes);
|
||||||
return cc.build(cm.thisClass().asSymbol(),
|
return cc.build(cm.thisClass().asSymbol(),
|
||||||
cb -> {
|
cb -> {
|
||||||
cm.forEachElement(element -> {
|
cm.forEach(element -> {
|
||||||
if (element instanceof MethodModel mm
|
if (element instanceof MethodModel mm
|
||||||
&& mm.methodName().stringValue().equals("hashCode")
|
&& mm.methodName().stringValue().equals("hashCode")
|
||||||
&& mm.methodType().stringValue().equals("()Z")) {
|
&& mm.methodType().stringValue().equals("()Z")) {
|
||||||
|
Loading…
Reference in New Issue
Block a user