Skip to content

Commit 4ffa7e9

Browse files
authored
Record Feature Progress (#499)
* add Tests to test record feature of jpf * modify the setBootstrapMethod(...) to check the type of bootstrap method more precisely to handle each type with the correct scheme
1 parent 50557c9 commit 4ffa7e9

File tree

2 files changed

+71
-43
lines changed

2 files changed

+71
-43
lines changed

src/main/gov/nasa/jpf/jvm/JVMClassInfo.java

Lines changed: 18 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -18,43 +18,16 @@
1818

1919
package gov.nasa.jpf.jvm;
2020

21+
import gov.nasa.jpf.Config;
22+
import gov.nasa.jpf.util.Misc;
23+
import gov.nasa.jpf.util.StringSetMatcher;
24+
import gov.nasa.jpf.vm.*;
25+
2126
import java.lang.reflect.Modifier;
2227
import java.util.HashMap;
2328
import java.util.LinkedHashMap;
2429
import java.util.LinkedList;
2530

26-
import gov.nasa.jpf.Config;
27-
import gov.nasa.jpf.util.Misc;
28-
import gov.nasa.jpf.util.StringSetMatcher;
29-
import gov.nasa.jpf.vm.AbstractTypeAnnotationInfo;
30-
import gov.nasa.jpf.vm.AnnotationInfo;
31-
import gov.nasa.jpf.vm.BootstrapMethodInfo;
32-
import gov.nasa.jpf.vm.BytecodeAnnotationInfo;
33-
import gov.nasa.jpf.vm.BytecodeTypeParameterAnnotationInfo;
34-
import gov.nasa.jpf.vm.ClassInfo;
35-
import gov.nasa.jpf.vm.ClassInfoException;
36-
import gov.nasa.jpf.vm.ClassLoaderInfo;
37-
import gov.nasa.jpf.vm.ClassParseException;
38-
import gov.nasa.jpf.vm.DirectCallStackFrame;
39-
import gov.nasa.jpf.vm.ExceptionHandler;
40-
import gov.nasa.jpf.vm.ExceptionParameterAnnotationInfo;
41-
import gov.nasa.jpf.vm.FieldInfo;
42-
import gov.nasa.jpf.vm.FormalParameterAnnotationInfo;
43-
import gov.nasa.jpf.vm.GenericSignatureHolder;
44-
import gov.nasa.jpf.vm.InfoObject;
45-
import gov.nasa.jpf.vm.LocalVarInfo;
46-
import gov.nasa.jpf.vm.MethodInfo;
47-
import gov.nasa.jpf.vm.NativeMethodInfo;
48-
import gov.nasa.jpf.vm.StackFrame;
49-
import gov.nasa.jpf.vm.SuperTypeAnnotationInfo;
50-
import gov.nasa.jpf.vm.ThreadInfo;
51-
import gov.nasa.jpf.vm.ThrowsAnnotationInfo;
52-
import gov.nasa.jpf.vm.TypeAnnotationInfo;
53-
import gov.nasa.jpf.vm.TypeParameterAnnotationInfo;
54-
import gov.nasa.jpf.vm.TypeParameterBoundAnnotationInfo;
55-
import gov.nasa.jpf.vm.Types;
56-
import gov.nasa.jpf.vm.VariableAnnotationInfo;
57-
5831
/**
5932
* a ClassInfo that was created from a Java classfile
6033
*/
@@ -118,14 +91,15 @@ public void setClassAttribute (ClassFile cf, int attrIndex, String name, int att
11891
public void setBootstrapMethodCount (ClassFile cf, Object tag, int count) {
11992
bootstrapMethods = new BootstrapMethodInfo[count];
12093
}
121-
94+
12295
@Override
12396
public void setBootstrapMethod (ClassFile cf, Object tag, int idx, int refKind, String cls, String mth,
12497
String parameters, String descriptor, int[] cpArgs) {
12598
String clsName = null;
12699
ClassInfo enclosingLambdaCls;
127-
128-
if (cpArgs.length > 1) {
100+
101+
if (cls.equals("java/lang/invoke/LambdaMetafactory") && (mth.equals("metafactory") || mth.equals("altMetafactory"))) {
102+
assert(cpArgs.length>1);
129103
// For Lambdas
130104
int mrefIdx = cf.mhMethodRefIndexAt(cpArgs[1]);
131105
clsName = cf.methodClassNameAt(mrefIdx).replace('/', '.');
@@ -164,16 +138,17 @@ public void setBootstrapMethod (ClassFile cf, Object tag, int idx, int refKind,
164138
int lambdaRefKind = cf.mhRefTypeAt(cpArgs[1]);
165139
String mthName = cf.methodNameAt(mrefIdx);
166140
String signature = cf.methodDescriptorAt(mrefIdx);
167-
String samDescriptor = cf.methodTypeDescriptorAt(cpArgs[2]);
168-
141+
String samDescriptor = cf.methodTypeDescriptorAt(cpArgs[2]);
142+
169143
setBootstrapMethodInfo(enclosingLambdaCls, mthName, signature, idx, lambdaRefKind, samDescriptor, null,
170-
isSerializable ? BootstrapMethodInfo.BMType.SERIALIZABLE_LAMBDA_EXPRESSION
171-
: BootstrapMethodInfo.BMType.LAMBDA_EXPRESSION);
172-
}
173-
else {
144+
isSerializable ? BootstrapMethodInfo.BMType.SERIALIZABLE_LAMBDA_EXPRESSION
145+
: BootstrapMethodInfo.BMType.LAMBDA_EXPRESSION);
146+
} else if (cls.equals("java/lang/runtime/ObjectMethods") && mth.equals("bootstrap")) {
147+
// -----
148+
} else {
174149
// For String Concatenation
175-
clsName = cls;
176-
150+
clsName = cls;
151+
assert(mth.startsWith("makeConcat"));
177152
if(!clsName.equals(JVMClassInfo.this.getName())) {
178153
enclosingLambdaCls = ClassLoaderInfo.getCurrentResolvedClassInfo(clsName);
179154
} else {
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package java17;
2+
3+
import gov.nasa.jpf.util.test.TestJPF;
4+
import org.junit.Test;
5+
6+
public class RecordFeatureTest extends TestJPF {
7+
record Point(int x, int y){}
8+
// Official documents suggest that fields of "record" are "private" and "final".
9+
// So we are testing by direct access. It should fail here at compile time, but do not know why it works.
10+
@Test
11+
public void testRecordFieldsDirectly(){
12+
if (verifyNoPropertyViolation()){
13+
Point point = new Point(4, 5);
14+
assertEquals("",4,point.x);
15+
assertEquals("",5,point.y);
16+
}
17+
}
18+
@Test
19+
public void testRecordFields(){
20+
if (verifyNoPropertyViolation()){
21+
Point point = new Point(4, 5);
22+
assertEquals("",4,point.x());
23+
assertEquals("",5,point.y());
24+
}
25+
}
26+
@Test
27+
public void testRecordEquality(){
28+
if (verifyNoPropertyViolation()){
29+
Point point1 = new Point(4,5);
30+
Point point2 = new Point(4,5);
31+
Point point3 = new Point(3,5);
32+
assertEquals("",point1, point2);
33+
assertNotEquals("",point1, point3);
34+
}
35+
}
36+
@Test
37+
public void testRecordHashCode() {
38+
if (verifyNoPropertyViolation()){
39+
Point point1 = new Point(4, 5);
40+
Point point2 = new Point(4, 5);
41+
Point point3 = new Point(3,5);
42+
assertEquals("", point1.hashCode(), point2.hashCode());
43+
assertNotEquals("",point1.hashCode(),point3.hashCode());
44+
}
45+
}
46+
@Test
47+
public void testRecordToString() {
48+
if (verifyNoPropertyViolation()){
49+
Point point = new Point(4, 5);
50+
assertEquals("Point[x=4, y=5]", point.toString());
51+
}
52+
}
53+
}

0 commit comments

Comments
 (0)