8337219: AccessFlags factories do not require necessary arguments
Reviewed-by: asotona
This commit is contained in:
parent
6154a2129b
commit
93c19ac73c
@ -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.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -64,52 +64,4 @@ public sealed interface AccessFlags
|
||||
* method, or field}
|
||||
*/
|
||||
AccessFlag.Location location();
|
||||
|
||||
/**
|
||||
* {@return an {@linkplain AccessFlags} for a class}
|
||||
* @param mask the flags to be set, as a bit mask
|
||||
*/
|
||||
static AccessFlags ofClass(int mask) {
|
||||
return new AccessFlagsImpl(AccessFlag.Location.CLASS, mask);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return an {@linkplain AccessFlags} for a class}
|
||||
* @param flags the flags to be set
|
||||
*/
|
||||
static AccessFlags ofClass(AccessFlag... flags) {
|
||||
return new AccessFlagsImpl(AccessFlag.Location.CLASS, flags);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return an {@linkplain AccessFlags} for a field}
|
||||
* @param mask the flags to be set, as a bit mask
|
||||
*/
|
||||
static AccessFlags ofField(int mask) {
|
||||
return new AccessFlagsImpl(AccessFlag.Location.FIELD, mask);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return an {@linkplain AccessFlags} for a field}
|
||||
* @param flags the flags to be set
|
||||
*/
|
||||
static AccessFlags ofField(AccessFlag... flags) {
|
||||
return new AccessFlagsImpl(AccessFlag.Location.FIELD, flags);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return an {@linkplain AccessFlags} for a method}
|
||||
* @param mask the flags to be set, as a bit mask
|
||||
*/
|
||||
static AccessFlags ofMethod(int mask) {
|
||||
return new AccessFlagsImpl(AccessFlag.Location.METHOD, mask);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return an {@linkplain AccessFlags} for a method}
|
||||
* @param flags the flags to be set
|
||||
*/
|
||||
static AccessFlags ofMethod(AccessFlag... flags) {
|
||||
return new AccessFlagsImpl(AccessFlag.Location.METHOD, flags);
|
||||
}
|
||||
}
|
||||
|
@ -34,6 +34,8 @@ import java.util.function.Consumer;
|
||||
|
||||
import java.lang.classfile.constantpool.ClassEntry;
|
||||
import java.lang.classfile.constantpool.Utf8Entry;
|
||||
|
||||
import jdk.internal.classfile.impl.AccessFlagsImpl;
|
||||
import jdk.internal.classfile.impl.ChainedClassBuilder;
|
||||
import jdk.internal.classfile.impl.DirectClassBuilder;
|
||||
import jdk.internal.classfile.impl.Util;
|
||||
@ -73,7 +75,7 @@ public sealed interface ClassBuilder
|
||||
* @return this builder
|
||||
*/
|
||||
default ClassBuilder withFlags(int flags) {
|
||||
return with(AccessFlags.ofClass(flags));
|
||||
return with(new AccessFlagsImpl(AccessFlag.Location.CLASS, flags));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -82,7 +84,7 @@ public sealed interface ClassBuilder
|
||||
* @return this builder
|
||||
*/
|
||||
default ClassBuilder withFlags(AccessFlag... flags) {
|
||||
return with(AccessFlags.ofClass(flags));
|
||||
return with(new AccessFlagsImpl(AccessFlag.Location.CLASS, flags));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -26,6 +26,8 @@
|
||||
package java.lang.classfile;
|
||||
|
||||
import java.lang.classfile.constantpool.Utf8Entry;
|
||||
|
||||
import jdk.internal.classfile.impl.AccessFlagsImpl;
|
||||
import jdk.internal.classfile.impl.ChainedFieldBuilder;
|
||||
import jdk.internal.classfile.impl.TerminalFieldBuilder;
|
||||
import java.lang.reflect.AccessFlag;
|
||||
@ -55,7 +57,7 @@ public sealed interface FieldBuilder
|
||||
* @return this builder
|
||||
*/
|
||||
default FieldBuilder withFlags(int flags) {
|
||||
return with(AccessFlags.ofField(flags));
|
||||
return with(new AccessFlagsImpl(AccessFlag.Location.FIELD, flags));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -64,7 +66,7 @@ public sealed interface FieldBuilder
|
||||
* @return this builder
|
||||
*/
|
||||
default FieldBuilder withFlags(AccessFlag... flags) {
|
||||
return with(AccessFlags.ofField(flags));
|
||||
return with(new AccessFlagsImpl(AccessFlag.Location.FIELD, flags));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -28,6 +28,8 @@ package java.lang.classfile;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import java.lang.classfile.constantpool.Utf8Entry;
|
||||
|
||||
import jdk.internal.classfile.impl.AccessFlagsImpl;
|
||||
import jdk.internal.classfile.impl.ChainedMethodBuilder;
|
||||
import jdk.internal.classfile.impl.TerminalMethodBuilder;
|
||||
import java.lang.reflect.AccessFlag;
|
||||
@ -55,7 +57,7 @@ public sealed interface MethodBuilder
|
||||
* @return this builder
|
||||
*/
|
||||
default MethodBuilder withFlags(int flags) {
|
||||
return with(AccessFlags.ofMethod(flags));
|
||||
return with(new AccessFlagsImpl(AccessFlag.Location.METHOD, flags));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -64,7 +66,7 @@ public sealed interface MethodBuilder
|
||||
* @return this builder
|
||||
*/
|
||||
default MethodBuilder withFlags(AccessFlag... flags) {
|
||||
return with(AccessFlags.ofMethod(flags));
|
||||
return with(new AccessFlagsImpl(AccessFlag.Location.METHOD, flags));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -24,6 +24,7 @@
|
||||
*/
|
||||
package jdk.internal.classfile.impl;
|
||||
|
||||
import java.lang.reflect.AccessFlag;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
@ -50,7 +51,7 @@ public final class BufferedFieldBuilder
|
||||
this.context = context;
|
||||
this.name = name;
|
||||
this.desc = type;
|
||||
this.flags = AccessFlags.ofField();
|
||||
this.flags = new AccessFlagsImpl(AccessFlag.Location.FIELD);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -66,7 +66,7 @@ public final class BufferedMethodBuilder
|
||||
this.context = context;
|
||||
this.name = nameInfo;
|
||||
this.desc = typeInfo;
|
||||
this.flags = AccessFlags.ofMethod(flags);
|
||||
this.flags = new AccessFlagsImpl(AccessFlag.Location.METHOD, flags);
|
||||
this.original = original;
|
||||
}
|
||||
|
||||
|
@ -101,7 +101,7 @@ public final class ClassImpl
|
||||
|
||||
@Override
|
||||
public AccessFlags flags() {
|
||||
return AccessFlags.ofClass(reader.flags());
|
||||
return new AccessFlagsImpl(AccessFlag.Location.CLASS, reader.flags());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -24,6 +24,7 @@
|
||||
*/
|
||||
package jdk.internal.classfile.impl;
|
||||
|
||||
import java.lang.reflect.AccessFlag;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Consumer;
|
||||
@ -48,7 +49,7 @@ public final class FieldImpl
|
||||
|
||||
@Override
|
||||
public AccessFlags flags() {
|
||||
return AccessFlags.ofField(reader.readU2(startPos));
|
||||
return new AccessFlagsImpl(AccessFlag.Location.FIELD, reader.readU2(startPos));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -28,6 +28,7 @@ import java.lang.constant.MethodTypeDesc;
|
||||
import java.lang.classfile.*;
|
||||
import java.lang.classfile.constantpool.Utf8Entry;
|
||||
|
||||
import java.lang.reflect.AccessFlag;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Consumer;
|
||||
@ -51,7 +52,7 @@ public final class MethodImpl
|
||||
|
||||
@Override
|
||||
public AccessFlags flags() {
|
||||
return AccessFlags.ofMethod(reader.readU2(startPos));
|
||||
return new AccessFlagsImpl(AccessFlag.Location.METHOD, reader.readU2(startPos));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2007, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2007, 2024, 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
|
||||
@ -25,10 +25,12 @@
|
||||
|
||||
package com.sun.tools.javap;
|
||||
|
||||
import java.lang.reflect.AccessFlag;
|
||||
import java.net.URI;
|
||||
import java.text.DateFormat;
|
||||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
@ -149,7 +151,7 @@ public class ClassWriter extends BasicWriter {
|
||||
indent(-1);
|
||||
}
|
||||
|
||||
writeModifiers(getClassModifiers(cm.flags().flagsMask()));
|
||||
writeModifiers(getClassModifiers(cm.flags()));
|
||||
|
||||
if ((classModel.flags().flagsMask() & ACC_MODULE) != 0) {
|
||||
var attr = classModel.findAttribute(Attributes.module());
|
||||
@ -210,7 +212,7 @@ public class ClassWriter extends BasicWriter {
|
||||
println("minor version: " + classModel.minorVersion());
|
||||
println("major version: " + classModel.majorVersion());
|
||||
writeList(String.format("flags: (0x%04x) ", cm.flags().flagsMask()),
|
||||
getClassFlags(cm.flags().flagsMask()), "\n");
|
||||
getClassFlags(cm.flags()), "\n");
|
||||
print("this_class: #");print(() -> classModel.thisClass().index());
|
||||
tab();
|
||||
print(() -> "// " + classModel.thisClass().asInternalName());
|
||||
@ -416,7 +418,7 @@ public class ClassWriter extends BasicWriter {
|
||||
if (!options.checkAccess(f.flags().flagsMask()))
|
||||
return;
|
||||
|
||||
var flags = AccessFlags.ofField(f.flags().flagsMask());
|
||||
var flags = f.flags();
|
||||
writeModifiers(flagsReportUnknown(flags).stream().filter(fl -> fl.sourceModifier())
|
||||
.map(fl -> Modifier.toString(fl.mask())).toList());
|
||||
print(() -> sigPrinter.print(
|
||||
@ -794,9 +796,16 @@ public class ClassWriter extends BasicWriter {
|
||||
}
|
||||
}
|
||||
|
||||
private Set<String> getClassModifiers(int mask) {
|
||||
return getModifiers(flagsReportUnknown(AccessFlags.ofClass((mask & ACC_INTERFACE) != 0
|
||||
? mask & ~ACC_ABSTRACT : mask)));
|
||||
private Set<String> getClassModifiers(AccessFlags flags) {
|
||||
var flagSet = flagsReportUnknown(flags);
|
||||
Set<AccessFlag> set;
|
||||
if (flagSet.contains(AccessFlag.INTERFACE)) {
|
||||
set = EnumSet.copyOf(flagSet);
|
||||
set.remove(AccessFlag.ABSTRACT);
|
||||
} else {
|
||||
set = flagSet;
|
||||
}
|
||||
return getModifiers(set);
|
||||
}
|
||||
|
||||
private static Set<String> getModifiers(Set<java.lang.reflect.AccessFlag> flags) {
|
||||
@ -806,16 +815,8 @@ public class ClassWriter extends BasicWriter {
|
||||
return s;
|
||||
}
|
||||
|
||||
private Set<String> getClassFlags(int mask) {
|
||||
return getFlags(mask, flagsReportUnknown(AccessFlags.ofClass(mask)));
|
||||
}
|
||||
|
||||
private Set<String> getMethodFlags(int mask) {
|
||||
return getFlags(mask, flagsReportUnknown(AccessFlags.ofMethod(mask)));
|
||||
}
|
||||
|
||||
private Set<String> getFieldFlags(int mask) {
|
||||
return getFlags(mask, flagsReportUnknown(AccessFlags.ofField(mask)));
|
||||
private Set<String> getClassFlags(AccessFlags flags) {
|
||||
return getFlags(flags.flagsMask(), flagsReportUnknown(flags));
|
||||
}
|
||||
|
||||
private static Set<String> getFlags(int mask, Set<java.lang.reflect.AccessFlag> flags) {
|
||||
|
@ -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.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -26,6 +26,9 @@
|
||||
* @summary Testing ClassFile AccessFlags.
|
||||
* @run junit AccessFlagsTest
|
||||
*/
|
||||
import java.lang.classfile.ClassFile;
|
||||
import java.lang.constant.ClassDesc;
|
||||
import java.util.Arrays;
|
||||
import java.util.EnumSet;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
@ -34,6 +37,10 @@ import java.util.function.Function;
|
||||
import java.util.function.IntFunction;
|
||||
import java.lang.reflect.AccessFlag;
|
||||
import java.lang.classfile.AccessFlags;
|
||||
|
||||
import static java.lang.classfile.ClassFile.ACC_STATIC;
|
||||
import static java.lang.constant.ConstantDescs.CD_int;
|
||||
import static java.lang.constant.ConstantDescs.MTD_void;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.provider.EnumSource;
|
||||
@ -45,15 +52,38 @@ class AccessFlagsTest {
|
||||
@EnumSource(names = { "CLASS", "METHOD", "FIELD" })
|
||||
void testRandomAccessFlagsConverions(AccessFlag.Location ctx) {
|
||||
IntFunction<AccessFlags> intFactory = switch (ctx) {
|
||||
case CLASS -> AccessFlags::ofClass;
|
||||
case METHOD -> AccessFlags::ofMethod;
|
||||
case FIELD -> AccessFlags::ofField;
|
||||
case CLASS -> v -> {
|
||||
var bytes = ClassFile.of().build(ClassDesc.of("Test"), clb -> clb.withFlags(v));
|
||||
return ClassFile.of().parse(bytes).flags();
|
||||
};
|
||||
case METHOD -> v -> {
|
||||
var bytes = ClassFile.of().build(ClassDesc.of("Test"), clb ->
|
||||
clb.withMethod("test", MTD_void, v & ACC_STATIC, mb -> mb.withFlags(v)));
|
||||
return ClassFile.of().parse(bytes).methods().getFirst().flags();
|
||||
};
|
||||
case FIELD -> v -> {
|
||||
var bytes = ClassFile.of().build(ClassDesc.of("Test"), clb ->
|
||||
clb.withField("test", CD_int, fb -> fb.withFlags(v)));
|
||||
return ClassFile.of().parse(bytes).fields().getFirst().flags();
|
||||
};
|
||||
default -> null;
|
||||
};
|
||||
Function<AccessFlag[], AccessFlags> flagsFactory = switch (ctx) {
|
||||
case CLASS -> AccessFlags::ofClass;
|
||||
case METHOD -> AccessFlags::ofMethod;
|
||||
case FIELD -> AccessFlags::ofField;
|
||||
case CLASS -> v -> {
|
||||
var bytes = ClassFile.of().build(ClassDesc.of("Test"), clb -> clb.withFlags(v));
|
||||
return ClassFile.of().parse(bytes).flags();
|
||||
};
|
||||
case METHOD -> v -> {
|
||||
boolean hasStatic = Arrays.stream(v).anyMatch(f -> f == AccessFlag.STATIC);
|
||||
var bytes = ClassFile.of().build(ClassDesc.of("Test"), clb ->
|
||||
clb.withMethod("test", MTD_void, hasStatic ? ACC_STATIC : 0, mb -> mb.withFlags(v)));
|
||||
return ClassFile.of().parse(bytes).methods().getFirst().flags();
|
||||
};
|
||||
case FIELD -> v -> {
|
||||
var bytes = ClassFile.of().build(ClassDesc.of("Test"), clb ->
|
||||
clb.withField("test", CD_int, fb -> fb.withFlags(v)));
|
||||
return ClassFile.of().parse(bytes).fields().getFirst().flags();
|
||||
};
|
||||
default -> null;
|
||||
};
|
||||
|
||||
@ -72,11 +102,11 @@ class AccessFlagsTest {
|
||||
|
||||
@Test
|
||||
void testInvalidFlagsUse() {
|
||||
assertAll(
|
||||
() -> assertThrowsForInvalidFlagsUse(AccessFlags::ofClass),
|
||||
() -> assertThrowsForInvalidFlagsUse(AccessFlags::ofField),
|
||||
() -> assertThrowsForInvalidFlagsUse(AccessFlags::ofMethod)
|
||||
);
|
||||
ClassFile.of().build(ClassDesc.of("Test"), clb -> {
|
||||
assertThrowsForInvalidFlagsUse(clb::withFlags);
|
||||
clb.withMethod("test", MTD_void, ACC_STATIC, mb -> assertThrowsForInvalidFlagsUse(mb::withFlags));
|
||||
clb.withField("test", CD_int, fb -> assertThrowsForInvalidFlagsUse(fb::withFlags));
|
||||
});
|
||||
}
|
||||
|
||||
void assertThrowsForInvalidFlagsUse(Consumer<AccessFlag[]> factory) {
|
||||
|
@ -28,7 +28,6 @@
|
||||
* @run junit BuilderBlockTest
|
||||
*/
|
||||
import java.io.IOException;
|
||||
import java.lang.classfile.AccessFlags;
|
||||
import java.lang.classfile.Attributes;
|
||||
import java.lang.classfile.ClassFile;
|
||||
import java.lang.classfile.ClassTransform;
|
||||
@ -53,6 +52,8 @@ import helpers.ByteArrayClassLoader;
|
||||
import jdk.internal.classfile.impl.LabelImpl;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static java.lang.classfile.ClassFile.ACC_PUBLIC;
|
||||
import static java.lang.classfile.ClassFile.ACC_STATIC;
|
||||
import static java.lang.constant.ConstantDescs.CD_int;
|
||||
import static java.lang.constant.ConstantDescs.CD_void;
|
||||
|
||||
@ -116,7 +117,7 @@ class BuilderBlockTest {
|
||||
byte[] bytes = ClassFile.of().build(ClassDesc.of("Foo"), cb -> {
|
||||
cb.withFlags(AccessFlag.PUBLIC);
|
||||
cb.withMethod("foo", MethodTypeDesc.of(CD_int, CD_int),
|
||||
AccessFlags.ofMethod(AccessFlag.PUBLIC, AccessFlag.STATIC).flagsMask(),
|
||||
ACC_PUBLIC | ACC_STATIC,
|
||||
mb -> mb.withCode(xb -> xb.iload(0)
|
||||
.ifThen(xxb -> xxb.iconst_1().ireturn())
|
||||
.iconst_2()
|
||||
@ -135,7 +136,7 @@ class BuilderBlockTest {
|
||||
byte[] bytes = ClassFile.of().build(ClassDesc.of("Foo"), cb -> {
|
||||
cb.withFlags(AccessFlag.PUBLIC);
|
||||
cb.withMethod("foo", MethodTypeDesc.of(CD_int, CD_int),
|
||||
AccessFlags.ofMethod(AccessFlag.PUBLIC, AccessFlag.STATIC).flagsMask(),
|
||||
ACC_PUBLIC | ACC_STATIC,
|
||||
mb -> mb.withCode(xb -> xb.iload(0)
|
||||
.ifThenElse(xxb -> xxb.iconst_1().ireturn(),
|
||||
xxb -> xxb.iconst_2().ireturn())));
|
||||
@ -153,7 +154,7 @@ class BuilderBlockTest {
|
||||
ClassFile.of().build(ClassDesc.of("Foo"), cb -> {
|
||||
cb.withFlags(AccessFlag.PUBLIC);
|
||||
cb.withMethod("foo", MethodTypeDesc.of(CD_int, CD_int, CD_int),
|
||||
AccessFlags.ofMethod(AccessFlag.PUBLIC, AccessFlag.STATIC).flagsMask(),
|
||||
ACC_PUBLIC | ACC_STATIC,
|
||||
mb -> mb.withCode(xb -> {
|
||||
xb.iload(0);
|
||||
xb.iload(1);
|
||||
@ -173,7 +174,7 @@ class BuilderBlockTest {
|
||||
byte[] bytes = ClassFile.of().build(ClassDesc.of("Foo"), cb -> {
|
||||
cb.withFlags(AccessFlag.PUBLIC);
|
||||
cb.withMethod("foo", MethodTypeDesc.of(CD_int, CD_int),
|
||||
AccessFlags.ofMethod(AccessFlag.PUBLIC, AccessFlag.STATIC).flagsMask(),
|
||||
ACC_PUBLIC | ACC_STATIC,
|
||||
mb -> mb.withCode(xb -> xb.iload(0)
|
||||
.ifThenElse(xxb -> xxb.iconst_1().istore(2),
|
||||
xxb -> xxb.iconst_2().istore(2))
|
||||
@ -193,7 +194,7 @@ class BuilderBlockTest {
|
||||
byte[] bytes = ClassFile.of().build(ClassDesc.of("Foo"), cb -> {
|
||||
cb.withFlags(AccessFlag.PUBLIC);
|
||||
cb.withMethod("foo", MethodTypeDesc.of(CD_int, CD_int),
|
||||
AccessFlags.ofMethod(AccessFlag.PUBLIC, AccessFlag.STATIC).flagsMask(),
|
||||
ACC_PUBLIC | ACC_STATIC,
|
||||
mb -> mb.withCode(xb -> xb.iload(0)
|
||||
.ifThenElse(xxb -> xxb.iconst_1().istore(2).goto_(xxb.breakLabel()),
|
||||
xxb -> xxb.iconst_2().istore(2).goto_(xxb.breakLabel()))
|
||||
@ -212,7 +213,7 @@ class BuilderBlockTest {
|
||||
byte[] bytes = ClassFile.of().build(ClassDesc.of("Foo"), cb -> {
|
||||
cb.withFlags(AccessFlag.PUBLIC);
|
||||
cb.withMethod("foo", MethodTypeDesc.of(CD_int, CD_int, CD_int),
|
||||
AccessFlags.ofMethod(AccessFlag.PUBLIC, AccessFlag.STATIC).flagsMask(),
|
||||
ACC_PUBLIC | ACC_STATIC,
|
||||
mb -> mb.withCode(xb ->
|
||||
xb.iload(0)
|
||||
.iload(1)
|
||||
@ -237,7 +238,7 @@ class BuilderBlockTest {
|
||||
ClassFile.of().build(ClassDesc.of("Foo"), cb -> {
|
||||
cb.withFlags(AccessFlag.PUBLIC);
|
||||
cb.withMethod("foo", MethodTypeDesc.of(CD_int, CD_int, CD_int),
|
||||
AccessFlags.ofMethod(AccessFlag.PUBLIC, AccessFlag.STATIC).flagsMask(),
|
||||
ACC_PUBLIC | ACC_STATIC,
|
||||
mb -> mb.withCode(xb -> {
|
||||
xb.iload(0);
|
||||
xb.iload(1);
|
||||
|
@ -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.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -27,7 +27,6 @@
|
||||
* @run junit BuilderTryCatchTest
|
||||
*/
|
||||
|
||||
import java.lang.classfile.AccessFlags;
|
||||
import java.lang.classfile.ClassFile;
|
||||
import java.lang.classfile.CodeBuilder;
|
||||
import java.lang.classfile.CompoundElement;
|
||||
@ -35,6 +34,9 @@ import java.lang.classfile.Opcode;
|
||||
import java.lang.classfile.TypeKind;
|
||||
import java.lang.classfile.instruction.BranchInstruction;
|
||||
import java.lang.classfile.instruction.ExceptionCatch;
|
||||
|
||||
import static java.lang.classfile.ClassFile.ACC_PUBLIC;
|
||||
import static java.lang.classfile.ClassFile.ACC_STATIC;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@ -43,7 +45,6 @@ import java.lang.constant.MethodTypeDesc;
|
||||
import java.lang.invoke.MethodHandle;
|
||||
import java.lang.invoke.MethodHandles;
|
||||
import java.lang.invoke.MethodType;
|
||||
import java.lang.reflect.AccessFlag;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
@ -184,7 +185,7 @@ class BuilderTryCatchTest {
|
||||
void testEmptyTry() {
|
||||
byte[] bytes = ClassFile.of().build(ClassDesc.of("C"), cb -> {
|
||||
cb.withMethod("main", MethodTypeDesc.of(CD_String, CD_String.arrayType()),
|
||||
AccessFlags.ofMethod(AccessFlag.PUBLIC, AccessFlag.STATIC).flagsMask(), mb -> {
|
||||
ACC_PUBLIC | ACC_STATIC, mb -> {
|
||||
mb.withCode(xb -> {
|
||||
int stringSlot = xb.allocateLocal(TypeKind.ReferenceType);
|
||||
xb.loadConstant("S");
|
||||
@ -215,7 +216,7 @@ class BuilderTryCatchTest {
|
||||
void testLocalAllocation() throws Throwable {
|
||||
byte[] bytes = ClassFile.of().build(ClassDesc.of("C"), cb -> {
|
||||
cb.withMethod("main", MethodTypeDesc.of(CD_String, CD_String.arrayType()),
|
||||
AccessFlags.ofMethod(AccessFlag.PUBLIC, AccessFlag.STATIC).flagsMask(), mb -> {
|
||||
ACC_PUBLIC | ACC_STATIC, mb -> {
|
||||
mb.withCode(xb -> {
|
||||
int stringSlot = xb.allocateLocal(TypeKind.ReferenceType);
|
||||
xb.loadConstant("S");
|
||||
@ -278,7 +279,7 @@ class BuilderTryCatchTest {
|
||||
static byte[] generateTryCatchMethod(Consumer<CodeBuilder.CatchBuilder> c) {
|
||||
byte[] bytes = ClassFile.of().build(ClassDesc.of("C"), cb -> {
|
||||
cb.withMethod("main", MethodTypeDesc.of(CD_String, CD_String.arrayType()),
|
||||
AccessFlags.ofMethod(AccessFlag.PUBLIC, AccessFlag.STATIC).flagsMask(), mb -> {
|
||||
ACC_PUBLIC | ACC_STATIC, mb -> {
|
||||
mb.withCode(xb -> {
|
||||
int stringSlot = xb.allocateLocal(TypeKind.ReferenceType);
|
||||
xb.loadConstant("S");
|
||||
|
@ -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.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -27,6 +27,9 @@
|
||||
* @run junit LDCTest
|
||||
*/
|
||||
import java.lang.constant.ClassDesc;
|
||||
|
||||
import static java.lang.classfile.ClassFile.ACC_PUBLIC;
|
||||
import static java.lang.classfile.ClassFile.ACC_STATIC;
|
||||
import static java.lang.constant.ConstantDescs.*;
|
||||
import java.lang.constant.MethodTypeDesc;
|
||||
|
||||
@ -38,7 +41,6 @@ import static org.junit.jupiter.api.Assertions.*;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static helpers.TestConstants.MTD_VOID;
|
||||
import static java.lang.classfile.Opcode.*;
|
||||
import static java.lang.classfile.TypeKind.VoidType;
|
||||
import java.lang.classfile.instruction.ConstantInstruction;
|
||||
|
||||
class LDCTest {
|
||||
@ -56,7 +58,7 @@ class LDCTest {
|
||||
)
|
||||
|
||||
.withMethod("main", MethodTypeDesc.of(CD_void, CD_String.arrayType()),
|
||||
AccessFlags.ofMethod(AccessFlag.PUBLIC, AccessFlag.STATIC).flagsMask(),
|
||||
ACC_PUBLIC | ACC_STATIC,
|
||||
mb -> mb.withCode(c0 -> {
|
||||
ConstantPoolBuilder cpb = cb.constantPool();
|
||||
for (int i = 0; i <= 256/2 + 2; i++) { // two entries per String
|
||||
|
@ -27,6 +27,9 @@
|
||||
* @run junit LowAdaptTest
|
||||
*/
|
||||
import java.lang.constant.ClassDesc;
|
||||
|
||||
import static java.lang.classfile.ClassFile.ACC_PUBLIC;
|
||||
import static java.lang.classfile.ClassFile.ACC_STATIC;
|
||||
import static java.lang.constant.ConstantDescs.*;
|
||||
import java.lang.constant.DirectMethodHandleDesc;
|
||||
import java.lang.constant.DynamicCallSiteDesc;
|
||||
@ -35,7 +38,6 @@ import java.lang.constant.MethodTypeDesc;
|
||||
import java.net.URI;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
import java.lang.classfile.AccessFlags;
|
||||
import java.lang.reflect.AccessFlag;
|
||||
import java.lang.classfile.ClassModel;
|
||||
import java.lang.classfile.ClassFile;
|
||||
@ -75,7 +77,7 @@ class LowAdaptTest {
|
||||
cl.methods().forEach(cb::with);
|
||||
|
||||
cb.withMethod("doit", MethodTypeDesc.of(CD_int, CD_int),
|
||||
AccessFlags.ofMethod(AccessFlag.PUBLIC, AccessFlag.STATIC).flagsMask(),
|
||||
ACC_PUBLIC | ACC_STATIC,
|
||||
mb -> mb.withCode(xb -> {
|
||||
xb.invokedynamic(indy);
|
||||
xb.astore(1);
|
||||
|
@ -35,13 +35,10 @@ import java.io.*;
|
||||
import java.lang.constant.ClassDesc;
|
||||
import java.net.URI;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import java.lang.classfile.AccessFlags;
|
||||
import java.lang.classfile.Attributes;
|
||||
import java.lang.classfile.attribute.SourceFileAttribute;
|
||||
import java.lang.classfile.constantpool.ConstantPoolBuilder;
|
||||
@ -58,11 +55,10 @@ import static helpers.TestConstants.MTD_INT_VOID;
|
||||
import static helpers.TestConstants.MTD_VOID;
|
||||
import static helpers.TestUtil.ExpectedLvRecord;
|
||||
import static helpers.TestUtil.ExpectedLvtRecord;
|
||||
import static java.lang.classfile.ClassFile.ACC_PUBLIC;
|
||||
import static java.lang.classfile.ClassFile.ACC_STATIC;
|
||||
import static java.lang.constant.ConstantDescs.*;
|
||||
import java.lang.constant.MethodTypeDesc;
|
||||
import static java.lang.classfile.Opcode.*;
|
||||
import static java.lang.classfile.Opcode.INVOKEVIRTUAL;
|
||||
import static java.lang.classfile.TypeKind.VoidType;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class LvtTest {
|
||||
@ -128,7 +124,7 @@ class LvtTest {
|
||||
)
|
||||
)
|
||||
.withMethod("main", MethodTypeDesc.of(CD_void, CD_String.arrayType()),
|
||||
AccessFlags.ofMethod(AccessFlag.PUBLIC, AccessFlag.STATIC).flagsMask(),
|
||||
ACC_PUBLIC | ACC_STATIC,
|
||||
mb -> mb
|
||||
.withCode(c0 -> {
|
||||
ConstantPoolBuilder cpb = cb.constantPool();
|
||||
@ -243,7 +239,7 @@ class LvtTest {
|
||||
)
|
||||
|
||||
.withMethod("m", MethodTypeDesc.of(CD_Object, CD_Object.arrayType()),
|
||||
ClassFile.ACC_PUBLIC,
|
||||
ACC_PUBLIC,
|
||||
mb -> mb.withFlags(AccessFlag.PUBLIC)
|
||||
.withCode(c0 -> {
|
||||
ConstantPoolBuilder cpb = cb.constantPool();
|
||||
|
@ -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.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -27,18 +27,19 @@
|
||||
* @run junit OneToOneTest
|
||||
*/
|
||||
import java.lang.constant.ClassDesc;
|
||||
|
||||
import static java.lang.classfile.ClassFile.ACC_PUBLIC;
|
||||
import static java.lang.classfile.ClassFile.ACC_STATIC;
|
||||
import static java.lang.constant.ConstantDescs.*;
|
||||
import java.lang.constant.MethodTypeDesc;
|
||||
import java.util.List;
|
||||
|
||||
import java.lang.classfile.AccessFlags;
|
||||
import java.lang.reflect.AccessFlag;
|
||||
import java.lang.classfile.ClassModel;
|
||||
import java.lang.classfile.ClassFile;
|
||||
import java.lang.classfile.Instruction;
|
||||
import java.lang.classfile.Label;
|
||||
import java.lang.classfile.MethodModel;
|
||||
import java.lang.classfile.TypeKind;
|
||||
import java.lang.classfile.attribute.SourceFileAttribute;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@ -74,7 +75,7 @@ class OneToOneTest {
|
||||
)
|
||||
)
|
||||
.withMethod("main", MethodTypeDesc.of(CD_void, CD_String.arrayType()),
|
||||
AccessFlags.ofMethod(AccessFlag.STATIC, AccessFlag.PUBLIC).flagsMask(),
|
||||
ACC_PUBLIC | ACC_STATIC,
|
||||
mb -> mb.withCode(c0 -> {
|
||||
Label loopTop = c0.newLabel();
|
||||
Label loopEnd = c0.newLabel();
|
||||
|
@ -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.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -27,8 +27,10 @@
|
||||
* @run junit SwapTest
|
||||
*/
|
||||
|
||||
import java.lang.classfile.AccessFlags;
|
||||
import java.lang.classfile.ClassFile;
|
||||
|
||||
import static java.lang.classfile.ClassFile.ACC_PUBLIC;
|
||||
import static java.lang.classfile.ClassFile.ACC_STATIC;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@ -38,9 +40,6 @@ import java.lang.invoke.MethodHandle;
|
||||
import java.lang.invoke.MethodHandles;
|
||||
import java.lang.invoke.MethodType;
|
||||
|
||||
import static java.lang.reflect.AccessFlag.PUBLIC;
|
||||
import static java.lang.reflect.AccessFlag.STATIC;
|
||||
|
||||
class SwapTest {
|
||||
@Test
|
||||
void testTryCatchCatchAll() throws Throwable {
|
||||
@ -48,7 +47,7 @@ class SwapTest {
|
||||
MethodTypeDesc mtd = mt.describeConstable().get();
|
||||
|
||||
byte[] bytes = ClassFile.of().build(ClassDesc.of("C"), cb -> {
|
||||
cb.withMethodBody("m", mtd, AccessFlags.ofMethod(PUBLIC, STATIC).flagsMask(), xb -> {
|
||||
cb.withMethodBody("m", mtd, ACC_PUBLIC | ACC_STATIC, xb -> {
|
||||
xb.aload(0); // 0
|
||||
xb.aload(1); // 1, 0
|
||||
xb.swap(); // 0, 1
|
||||
|
@ -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.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -30,20 +30,16 @@ import java.lang.constant.ClassDesc;
|
||||
import java.lang.constant.MethodTypeDesc;
|
||||
|
||||
import helpers.TestConstants;
|
||||
import java.lang.classfile.AccessFlags;
|
||||
import java.lang.reflect.AccessFlag;
|
||||
import java.lang.classfile.ClassFile;
|
||||
import java.lang.classfile.TypeKind;
|
||||
import java.lang.classfile.Label;
|
||||
import java.lang.classfile.attribute.SourceFileAttribute;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static helpers.TestConstants.MTD_VOID;
|
||||
import static java.lang.classfile.ClassFile.ACC_PUBLIC;
|
||||
import static java.lang.classfile.ClassFile.ACC_STATIC;
|
||||
import static java.lang.constant.ConstantDescs.*;
|
||||
import static java.lang.classfile.Opcode.*;
|
||||
import static java.lang.classfile.TypeKind.IntType;
|
||||
import static java.lang.classfile.TypeKind.ReferenceType;
|
||||
import static java.lang.classfile.TypeKind.VoidType;
|
||||
|
||||
class WriteTest {
|
||||
|
||||
@ -61,7 +57,7 @@ class WriteTest {
|
||||
)
|
||||
)
|
||||
.withMethod("main", MethodTypeDesc.of(CD_void, CD_String.arrayType()),
|
||||
AccessFlags.ofMethod(AccessFlag.PUBLIC, AccessFlag.STATIC).flagsMask(),
|
||||
ACC_PUBLIC | ACC_STATIC,
|
||||
mb -> mb.withCode(c0 -> {
|
||||
Label loopTop = c0.newLabel();
|
||||
Label loopEnd = c0.newLabel();
|
||||
@ -102,7 +98,7 @@ class WriteTest {
|
||||
)
|
||||
)
|
||||
.withMethod("main", MethodTypeDesc.of(CD_void, CD_String.arrayType()),
|
||||
AccessFlags.ofMethod(AccessFlag.PUBLIC, AccessFlag.STATIC).flagsMask(),
|
||||
ACC_PUBLIC | ACC_STATIC,
|
||||
mb -> mb.withCode(c0 -> {
|
||||
Label loopTop = c0.newLabel();
|
||||
Label loopEnd = c0.newLabel();
|
||||
|
@ -207,7 +207,7 @@ public class ExampleGallery {
|
||||
public byte[] changeFieldFlags(ClassModel cm) {
|
||||
return ClassFile.of().transformClass(cm, ClassTransform.transformingFields((fb, fe) -> {
|
||||
switch (fe) {
|
||||
case AccessFlags a -> fb.with(AccessFlags.ofField(a.flagsMask() & ~ClassFile.ACC_PUBLIC & ~ClassFile.ACC_PROTECTED));
|
||||
case AccessFlags a -> fb.withFlags(a.flagsMask() & ~ClassFile.ACC_PUBLIC & ~ClassFile.ACC_PROTECTED);
|
||||
default -> fb.with(fe);
|
||||
}
|
||||
}));
|
||||
|
@ -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.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -22,7 +22,6 @@
|
||||
*/
|
||||
package org.openjdk.bench.jdk.classfile;
|
||||
|
||||
import java.lang.classfile.AccessFlags;
|
||||
import java.lang.reflect.AccessFlag;
|
||||
import java.lang.classfile.ClassFile;
|
||||
import java.lang.classfile.TypeKind;
|
||||
@ -30,6 +29,8 @@ import java.lang.classfile.attribute.SourceFileAttribute;
|
||||
import jdk.internal.org.objectweb.asm.*;
|
||||
import org.openjdk.jmh.annotations.*;
|
||||
import java.io.FileOutputStream;
|
||||
import static java.lang.classfile.ClassFile.ACC_PUBLIC;
|
||||
import static java.lang.classfile.ClassFile.ACC_STATIC;
|
||||
import static java.lang.constant.ConstantDescs.*;
|
||||
|
||||
import java.nio.file.Files;
|
||||
@ -148,7 +149,7 @@ public class Write {
|
||||
);
|
||||
for (int xi = 0; xi < 40; ++xi) {
|
||||
cb.withMethod("main" + ((xi == 0) ? "" : "" + xi), MTD_void_StringArray,
|
||||
AccessFlags.ofMethod(AccessFlag.STATIC, AccessFlag.PUBLIC).flagsMask(),
|
||||
ACC_PUBLIC | ACC_STATIC,
|
||||
mb -> mb.withCode(c0 -> {
|
||||
java.lang.classfile.Label loopTop = c0.newLabel();
|
||||
java.lang.classfile.Label loopEnd = c0.newLabel();
|
||||
@ -196,7 +197,7 @@ public class Write {
|
||||
);
|
||||
for (int xi = 0; xi < 40; ++xi) {
|
||||
cb.withMethod("main" + ((xi == 0) ? "" : "" + xi), MTD_void_StringArray,
|
||||
AccessFlags.ofMethod(AccessFlag.STATIC, AccessFlag.PUBLIC).flagsMask(),
|
||||
ACC_PUBLIC | ACC_STATIC,
|
||||
mb -> mb.withCode(c0 -> {
|
||||
java.lang.classfile.Label loopTop = c0.newLabel();
|
||||
java.lang.classfile.Label loopEnd = c0.newLabel();
|
||||
|
Loading…
Reference in New Issue
Block a user