Skip to content

Commit 4eda8ad

Browse files
committed
Java class literals: init using a library hook when possible
The Java library definition of java.lang.Class, when nondet initialized, can be quite time consuming due to the enumeration constant dictionary's internal array. Instead, let's give the library a chance to set Class constants (literals like MyClass.class) itself. While we're at it we might as well gain the ability to prove some properties of the literals. We currently supply those class attributes that are easy to come by in the parse tree; with a little more effort in the parser IsLocalClass and IsMemberClass could be determined.
1 parent 70f13f3 commit 4eda8ad

23 files changed

+288
-9
lines changed
Binary file not shown.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
public @interface ExampleAnnotation {
3+
4+
}
Binary file not shown.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
public enum ExampleEnum {
3+
4+
}
5+
Binary file not shown.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
interface ExampleInterface {
3+
4+
}
Binary file not shown.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
; Compile me with Jasmin 2.1+ (https://sourceforge.net/projects/jasmin/)
2+
3+
.class public synthetic ExampleSynthetic
4+
.super java/lang/Object
1.23 KB
Binary file not shown.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
2+
public class Test {
3+
4+
public static void main() {
5+
6+
assert ExampleAnnotation.class.isAnnotation();
7+
assert ExampleInterface.class.isInterface();
8+
assert ExampleEnum.class.isEnum();
9+
assert ExampleSynthetic.class.isSynthetic();
10+
11+
assert char[].class.isArray();
12+
assert short[].class.isArray();
13+
assert int[].class.isArray();
14+
assert long[].class.isArray();
15+
assert float[].class.isArray();
16+
assert double[].class.isArray();
17+
assert boolean[].class.isArray();
18+
assert Object[].class.isArray();
19+
assert Object[][].class.isArray();
20+
21+
// Note use of '==' not '.equals', as we expect the same exact literal,
22+
// which in jbmc always have the same address.
23+
// Note names of array classes are not tested yet, as arrays' types are
24+
// printed as their raw signature, to be addressed separately.
25+
// Note also primitive types (e.g. int.class) are not addresses here, as
26+
// they are created through box types' static initializers (e.g. Integer
27+
// has a static member TYPE that holds the Class for `int.class`)
28+
29+
assert ExampleAnnotation.class.getName() == "ExampleAnnotation";
30+
assert ExampleInterface.class.getName() == "ExampleInterface";
31+
assert ExampleEnum.class.getName() == "ExampleEnum";
32+
33+
}
34+
35+
}

0 commit comments

Comments
 (0)