Skip to content

Commit e89fd87

Browse files
authored
Merge pull request #18505 from theresa-m/valuetypetests_5
Add remaining ValueTypeTests for lw5
2 parents a2c9085 + ad40a92 commit e89fd87

File tree

7 files changed

+1855
-358
lines changed

7 files changed

+1855
-358
lines changed

test/functional/Valhalla/build.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
<!-- <src path="${src_lw5}"/> -->
6363
<src path="${transformerListener}" />
6464
<compilerarg line='--add-exports java.base/jdk.internal.misc=ALL-UNNAMED --add-exports java.base/jdk.internal.value=ALL-UNNAMED' />
65+
<compilerarg line='--enable-preview -source 22'/>
6566
<!-- Also remove this line when running lw5 -->
6667
<compilerarg line='-source 22 -XDenablePrimitiveClasses' />
6768
<classpath>

test/functional/Valhalla/playlist.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
<variation>-Xnocompressedrefs -Xgcpolicy:gencon</variation>
3737
</variations>
3838
<command>$(JAVA_COMMAND) $(JVM_OPTIONS) \
39-
-Xint \
39+
-Xint --enable-preview \
4040
--add-opens java.base/jdk.internal.misc=ALL-UNNAMED \
4141
--add-exports java.base/jdk.internal.value=ALL-UNNAMED \
4242
-cp $(Q)$(LIB_DIR)$(D)asm.jar$(P)$(RESOURCES_DIR)$(P)$(TESTNG)$(P)$(TEST_RESROOT)$(D)ValhallaTests.jar$(Q) \

test/functional/Valhalla/src/org/openj9/test/lworld/ValhallaAttributeGenerator.java

Lines changed: 20 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -30,61 +30,55 @@ public class ValhallaAttributeGenerator extends ClassLoader {
3030

3131
public static Class<?> generateClassWithTwoPreloadAttributes(String name, String[] classList1, String[] classList2) throws Throwable {
3232
byte[] bytes = generateClass(name, ValhallaUtils.ACC_IDENTITY, new Attribute[] {
33-
new PreloadAttribute(classList1),
34-
new PreloadAttribute(classList2)});
33+
new ValhallaUtils.PreloadAttribute(classList1),
34+
new ValhallaUtils.PreloadAttribute(classList2)});
3535
return generator.defineClass(name, bytes, 0, bytes.length);
3636
}
3737

3838
public static Class<?> generateClassWithPreloadAttribute(String name, String[] classList) throws Throwable {
39-
byte[] bytes = generateClass(name, ValhallaUtils.ACC_IDENTITY, new Attribute[] {new PreloadAttribute(classList)});
39+
byte[] bytes = generateClass(name, ValhallaUtils.ACC_IDENTITY, new Attribute[] {new ValhallaUtils.PreloadAttribute(classList)});
4040
return generator.defineClass(name, bytes, 0, bytes.length);
4141
}
4242

4343
public static Class<?> generateClassWithTwoImplicitCreationAttributes(String name) throws Throwable {
4444
byte[] bytes = generateClass(name, ACC_FINAL + ValhallaUtils.ACC_VALUE_TYPE,
45-
new Attribute[] {new ImplicitCreationAttribute(), new ImplicitCreationAttribute()});
45+
new Attribute[] {new ValhallaUtils.ImplicitCreationAttribute(), new ValhallaUtils.ImplicitCreationAttribute()});
4646
return generator.defineClass(name, bytes, 0, bytes.length);
4747
}
4848

4949
public static Class<?> generateNonValueTypeClassWithImplicitCreationAttribute(String name) throws Throwable {
50-
byte[] bytes = generateClass(name, ValhallaUtils.ACC_IDENTITY, new Attribute[] {new ImplicitCreationAttribute()});
51-
return generator.defineClass(name, bytes, 0, bytes.length);
52-
}
53-
54-
public static Class<?> generateValidClassWithImplicitCreationAttribute(String name) throws Throwable {
55-
byte[] bytes = generateClass(name, ACC_FINAL + ValhallaUtils.ACC_VALUE_TYPE,
56-
new Attribute[] {new ImplicitCreationAttribute()});
50+
byte[] bytes = generateClass(name, ValhallaUtils.ACC_IDENTITY, new Attribute[] {new ValhallaUtils.ImplicitCreationAttribute()});
5751
return generator.defineClass(name, bytes, 0, bytes.length);
5852
}
5953

6054
public static Class<?> generateFieldWithMultipleNullRestrictedAttributes(String className, String fieldClassName) throws Throwable {
6155
/* Generate field class - value class with ImplicitCreation attribute and ACC_DEFAULT flag set */
6256
byte[] fieldClassBytes = generateClass(fieldClassName, ACC_FINAL + ValhallaUtils.ACC_VALUE_TYPE,
63-
new Attribute[] {new ImplicitCreationAttribute()});
57+
new Attribute[] {new ValhallaUtils.ImplicitCreationAttribute()});
6458
Class<?> fieldClass = generator.defineClass(fieldClassName, fieldClassBytes, 0, fieldClassBytes.length);
6559

6660
/* Generate class with field and multiple NullRestricted attributes */
6761
byte[] classBytes = generateIdentityClassWithField(className, 0,
68-
"field", fieldClass.descriptorString(), new Attribute[]{new NullRestrictedAttribute(), new NullRestrictedAttribute()});
62+
"field", fieldClass.descriptorString(), new Attribute[]{new ValhallaUtils.NullRestrictedAttribute(), new ValhallaUtils.NullRestrictedAttribute()});
6963
return generator.defineClass(className, classBytes, 0, classBytes.length);
7064
}
7165

7266
public static Class<?> generateNullRestrictedAttributeInPrimitiveField(String className) throws Throwable {
7367
/* Generate class with primitive field and a NullRestricted attribute */
7468
byte[] classBytes = generateIdentityClassWithField(className, 0,
75-
"field", "I", new Attribute[]{new NullRestrictedAttribute()});
69+
"field", "I", new Attribute[]{new ValhallaUtils.NullRestrictedAttribute()});
7670
return generator.defineClass(className, classBytes, 0, classBytes.length);
7771
}
7872

7973
public static Class<?> generateNullRestrictedAttributeInArrayField(String className, String fieldClassName) throws Throwable {
8074
/* Generate field class - value class with ImplicitCreation attribute and ACC_DEFAULT flag set. */
8175
byte[] fieldClassBytes = generateClass(fieldClassName, ACC_FINAL + ValhallaUtils.ACC_VALUE_TYPE,
82-
new Attribute[] {new ImplicitCreationAttribute()});
76+
new Attribute[] {new ValhallaUtils.ImplicitCreationAttribute()});
8377
Class<?> fieldClass = generator.defineClass(fieldClassName, fieldClassBytes, 0, fieldClassBytes.length);
8478

8579
/* Generate class field field that is an array with a NullRestricted attribute */
8680
byte[] classBytes = generateIdentityClassWithField(className, 0,
87-
"field", "[" + fieldClass.descriptorString(), new Attribute[]{new NullRestrictedAttribute()});
81+
"field", "[" + fieldClass.descriptorString(), new Attribute[]{new ValhallaUtils.NullRestrictedAttribute()});
8882
return generator.defineClass(className, classBytes, 0, classBytes.length);
8983
}
9084

@@ -93,15 +87,15 @@ public static Class<?> generatePutStaticNullToNullRestrictedField(String classNa
9387

9488
/* Generate field class - value class with ImplicitCreation attribute and ACC_DEFAULT flag set. */
9589
byte[] fieldClassBytes = generateClass(fieldClassName, ACC_PUBLIC + ACC_FINAL + ValhallaUtils.ACC_VALUE_TYPE,
96-
new Attribute[] {new ImplicitCreationAttribute()});
90+
new Attribute[] {new ValhallaUtils.ImplicitCreationAttribute()});
9791
Class<?> fieldClass = generator.defineClass(fieldClassName, fieldClassBytes, 0, fieldClassBytes.length);
9892

9993
ClassWriter classWriter = new ClassWriter(0);
10094
classWriter.visit(ValhallaUtils.CLASS_FILE_MAJOR_VERSION, ACC_PUBLIC + ValhallaUtils.ACC_IDENTITY, className, null, "java/lang/Object", null);
10195

10296
/* static field of previously generated field class with NullRestrictd attribute */
10397
FieldVisitor fieldVisitor = classWriter.visitField(ACC_PUBLIC + ACC_STATIC, fieldName, fieldClass.descriptorString(), null, null);
104-
fieldVisitor.visitAttribute(new NullRestrictedAttribute());
98+
fieldVisitor.visitAttribute(new ValhallaUtils.NullRestrictedAttribute());
10599

106100
/* assign field to null in <clinit> */
107101
MethodVisitor mvClinit = classWriter.visitMethod(ACC_STATIC, "<clinit>", "()V", null, null);
@@ -131,15 +125,15 @@ public static Class<?> generatePutFieldNullToNullRestrictedField(String classNam
131125

132126
/* Generate field class - value class with ImplicitCreation attribute and ACC_DEFAULT flag set. */
133127
byte[] fieldClassBytes = generateClass(fieldClassName, ACC_PUBLIC + ACC_FINAL + ValhallaUtils.ACC_VALUE_TYPE,
134-
new Attribute[] {new ImplicitCreationAttribute()});
128+
new Attribute[] {new ValhallaUtils.ImplicitCreationAttribute()});
135129
Class<?> fieldClass = generator.defineClass(fieldClassName, fieldClassBytes, 0, fieldClassBytes.length);
136130

137131
ClassWriter classWriter = new ClassWriter(0);
138132
classWriter.visit(ValhallaUtils.CLASS_FILE_MAJOR_VERSION, ACC_PUBLIC + ValhallaUtils.ACC_IDENTITY, className, null, "java/lang/Object", null);
139133

140134
/* instance field of previously generated field class with NullRestrictd attribute */
141135
FieldVisitor fieldVisitor = classWriter.visitField(ACC_PUBLIC, fieldName, fieldClass.descriptorString(), null, null);
142-
fieldVisitor.visitAttribute(new NullRestrictedAttribute());
136+
fieldVisitor.visitAttribute(new ValhallaUtils.NullRestrictedAttribute());
143137

144138
/* assign field to null in <init> */
145139
MethodVisitor mvInit = classWriter.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
@@ -165,7 +159,7 @@ public static Class<?> generateNullRestrictedAttributeInIdentityClass(boolean is
165159

166160
/* Generate class with field that is an identity class with a NullRestricted attribute */
167161
byte[] classBytes = generateIdentityClassWithField(className, isStatic ? ACC_STATIC : 0,
168-
"field", fieldClass.descriptorString(), new Attribute[]{new NullRestrictedAttribute()});
162+
"field", fieldClass.descriptorString(), new Attribute[]{new ValhallaUtils.NullRestrictedAttribute()});
169163
return generator.defineClass(className, classBytes, 0, classBytes.length);
170164
}
171165

@@ -176,19 +170,19 @@ public static Class<?> generateNullRestrictedAttributeInValueClassWithoutIC(bool
176170

177171
/* Generate class with field that has a NullRestricted attribute */
178172
byte[] classBytes = generateIdentityClassWithField(className, isStatic ? ACC_STATIC : 0,
179-
"field", fieldClass.descriptorString(), new Attribute[]{new NullRestrictedAttribute()});
173+
"field", fieldClass.descriptorString(), new Attribute[]{new ValhallaUtils.NullRestrictedAttribute()});
180174
return generator.defineClass(className, classBytes, 0, classBytes.length);
181175
}
182176

183177
public static Class<?> generateNullRestrictedFieldWhereICHasNoDefaultFlag(boolean isStatic, String className, String fieldClassName) throws Throwable {
184178
/* Generate field class - value type with ImplicitCreation attribute, no flags */
185179
byte[] fieldClassBytes = generateClass(fieldClassName, ACC_FINAL + ValhallaUtils.ACC_VALUE_TYPE,
186-
new Attribute[] {new ImplicitCreationAttribute(0)});
180+
new Attribute[] {new ValhallaUtils.ImplicitCreationAttribute(0)});
187181
Class<?> fieldClass = generator.defineClass(fieldClassName, fieldClassBytes, 0, fieldClassBytes.length);
188182

189183
/* Generate class with field with NullRestricted attribute */
190184
byte[] classBytes = generateIdentityClassWithField(className, isStatic ? ACC_STATIC : 0,
191-
"field", fieldClass.descriptorString(), new Attribute[]{new NullRestrictedAttribute()});
185+
"field", fieldClass.descriptorString(), new Attribute[]{new ValhallaUtils.NullRestrictedAttribute()});
192186
return generator.defineClass(className, classBytes, 0, classBytes.length);
193187
}
194188

@@ -197,15 +191,15 @@ public static Class<?> generateWithFieldStoreNullToNullRestrictedField(String cl
197191

198192
/* Generate field class - value class with ImplicitCreation attribute and ACC_DEFAULT flag set. */
199193
byte[] fieldClassBytes = generateClass(fieldClassName, ACC_PUBLIC + ACC_FINAL + ValhallaUtils.ACC_VALUE_TYPE,
200-
new Attribute[] {new ImplicitCreationAttribute(ValhallaUtils.ACC_DEFAULT)});
194+
new Attribute[] {new ValhallaUtils.ImplicitCreationAttribute(ValhallaUtils.ACC_DEFAULT)});
201195
Class<?> fieldClass = generator.defineClass(fieldClassName, fieldClassBytes, 0, fieldClassBytes.length);
202196

203197
ClassWriter classWriter = new ClassWriter(0);
204198
classWriter.visit(ValhallaUtils.CLASS_FILE_MAJOR_VERSION, ACC_PUBLIC + ValhallaUtils.ACC_IDENTITY, className, null, "java/lang/Object", null);
205199

206200
/* instance field of previously generated field class with NullRestrictd attribute */
207201
FieldVisitor fieldVisitor = classWriter.visitField(ACC_PUBLIC, fieldName, fieldClass.descriptorString(), null, null);
208-
fieldVisitor.visitAttribute(new NullRestrictedAttribute());
202+
fieldVisitor.visitAttribute(new ValhallaUtils.NullRestrictedAttribute());
209203

210204
MethodVisitor mvInit = classWriter.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
211205
mvInit.visitCode();
@@ -269,93 +263,4 @@ public static byte[] generateIdentityClassWithField(String name, int fieldFlags,
269263
classWriter.visitEnd();
270264
return classWriter.toByteArray();
271265
}
272-
273-
final static class PreloadAttribute extends Attribute {
274-
private final String[] classes;
275-
276-
public PreloadAttribute(String[] classes) {
277-
super("Preload");
278-
this.classes = classes;
279-
}
280-
281-
public Label[] getLabels() {
282-
return null;
283-
}
284-
285-
public boolean isCodeAttribute() {
286-
return false;
287-
}
288-
289-
public boolean isUnknown() {
290-
return true;
291-
}
292-
293-
public ByteVector write(ClassWriter cw, byte[] code, int len, int maxStack, int maxLocals) {
294-
ByteVector b = new ByteVector();
295-
296-
b.putShort(classes.length);
297-
298-
int cpIndex;
299-
for (int i = 0; i < classes.length; i++) {
300-
cpIndex = cw.newClass(classes[i].replace('.', '/'));
301-
b.putShort(cpIndex);
302-
}
303-
return b;
304-
}
305-
}
306-
307-
final static class ImplicitCreationAttribute extends Attribute {
308-
private final int flags;
309-
310-
public ImplicitCreationAttribute() {
311-
super("ImplicitCreation");
312-
/* this is the default flag generated by the compiler for the implicit modifier. */
313-
this.flags = ValhallaUtils.ACC_DEFAULT;
314-
}
315-
316-
public ImplicitCreationAttribute(int flags) {
317-
super("ImplicitCreation");
318-
this.flags = flags;
319-
}
320-
321-
public Label[] getLabels() {
322-
return null;
323-
}
324-
325-
public boolean isCodeAttribute() {
326-
return false;
327-
}
328-
329-
public boolean isUnknown() {
330-
return true;
331-
}
332-
333-
public ByteVector write(ClassWriter cw, byte[] code, int len, int maxStack, int maxLocals) {
334-
ByteVector b = new ByteVector();
335-
b.putShort(flags);
336-
return b;
337-
}
338-
}
339-
340-
final static class NullRestrictedAttribute extends Attribute {
341-
public NullRestrictedAttribute() {
342-
super("NullRestricted");
343-
}
344-
345-
public Label[] getLabels() {
346-
return null;
347-
}
348-
349-
public boolean isCodeAttribute() {
350-
return false;
351-
}
352-
353-
public boolean isUnknown() {
354-
return true;
355-
}
356-
357-
public ByteVector write(ClassWriter cw, byte[] code, int len, int maxStack, int maxLocals) {
358-
return new ByteVector();
359-
}
360-
}
361266
}

test/functional/Valhalla/src/org/openj9/test/lworld/ValhallaAttributeTests.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,6 @@ static public void testNonValueTypeClassWithImplicitCreationAttribute() throws T
7777
ValhallaAttributeGenerator.generateNonValueTypeClassWithImplicitCreationAttribute("NonValueTypeImplicitCreationAttribute");
7878
}
7979

80-
/* ImplicitCreation smoke test. The attribute doesn't do anything in the vm right now, make sure
81-
* it passes class validation.
82-
*/
83-
@Test
84-
static public void testValueTypeClassWithImplicitCreationAttribute() throws Throwable {
85-
ValhallaAttributeGenerator.generateValidClassWithImplicitCreationAttribute("ValueTypeClassWithImplicitCreationAttribute");
86-
}
87-
8880
/* There must be no more than one NullRestricted attribute in the attributes table of a field_info structure */
8981
@Test(expectedExceptions = java.lang.ClassFormatError.class, expectedExceptionsMessageRegExp = ".*Multiple NullRestricted attributes present.*")
9082
static public void testMultipleNullRestrictedAttributes() throws Throwable {

test/functional/Valhalla/src/org/openj9/test/lworld/ValhallaUtils.java

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
*******************************************************************************/
2222
package org.openj9.test.lworld;
2323

24+
import org.objectweb.asm.*;
25+
2426
public class ValhallaUtils {
2527
/**
2628
* Currently value type is built on JDK22, so use java file major version 66 for now.
@@ -40,4 +42,92 @@ public class ValhallaUtils {
4042
static final int ACC_DEFAULT = 0x1;
4143
static final int ACC_NON_ATOMIC = 0x2;
4244

45+
final static class PreloadAttribute extends Attribute {
46+
private final String[] classes;
47+
48+
public PreloadAttribute(String[] classes) {
49+
super("Preload");
50+
this.classes = classes;
51+
}
52+
53+
public Label[] getLabels() {
54+
return null;
55+
}
56+
57+
public boolean isCodeAttribute() {
58+
return false;
59+
}
60+
61+
public boolean isUnknown() {
62+
return true;
63+
}
64+
65+
public ByteVector write(ClassWriter cw, byte[] code, int len, int maxStack, int maxLocals) {
66+
ByteVector b = new ByteVector();
67+
68+
b.putShort(classes.length);
69+
70+
int cpIndex;
71+
for (int i = 0; i < classes.length; i++) {
72+
cpIndex = cw.newClass(classes[i].replace('.', '/'));
73+
b.putShort(cpIndex);
74+
}
75+
return b;
76+
}
77+
}
78+
79+
final static class ImplicitCreationAttribute extends Attribute {
80+
private final int flags;
81+
82+
public ImplicitCreationAttribute() {
83+
super("ImplicitCreation");
84+
/* this is the default flag generated by the compiler for the implicit modifier. */
85+
this.flags = ValhallaUtils.ACC_DEFAULT;
86+
}
87+
88+
public ImplicitCreationAttribute(int flags) {
89+
super("ImplicitCreation");
90+
this.flags = flags;
91+
}
92+
93+
public Label[] getLabels() {
94+
return null;
95+
}
96+
97+
public boolean isCodeAttribute() {
98+
return false;
99+
}
100+
101+
public boolean isUnknown() {
102+
return true;
103+
}
104+
105+
public ByteVector write(ClassWriter cw, byte[] code, int len, int maxStack, int maxLocals) {
106+
ByteVector b = new ByteVector();
107+
b.putShort(flags);
108+
return b;
109+
}
110+
}
111+
112+
final static class NullRestrictedAttribute extends Attribute {
113+
public NullRestrictedAttribute() {
114+
super("NullRestricted");
115+
}
116+
117+
public Label[] getLabels() {
118+
return null;
119+
}
120+
121+
public boolean isCodeAttribute() {
122+
return false;
123+
}
124+
125+
public boolean isUnknown() {
126+
return true;
127+
}
128+
129+
public ByteVector write(ClassWriter cw, byte[] code, int len, int maxStack, int maxLocals) {
130+
return new ByteVector();
131+
}
132+
}
43133
}

0 commit comments

Comments
 (0)