You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: jbmc/src/java_bytecode/README.md
+89-1Lines changed: 89 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -37,7 +37,95 @@ To be documented.
37
37
38
38
\section java-bytecode-remove-java-new Remove java new
39
39
40
-
To be documented.
40
+
\ref remove_java_new.h is responsible for converting the `new`, `newarray` and `multianewarray` Java bytecode operation into codet. Specifically it converts the bytecode instruction into:
41
+
- An ALLOC with the size of the object being created
42
+
- An assignment to the value zeroing its contents
43
+
- If an array, initializing the size and data components
44
+
- If a multi-dimensional array, recursively calling `java_new` on each sub array
45
+
46
+
_Note: it does not call the constructor as this is done by a separate java bytecode operation._
47
+
48
+
\subsection java_objects Java Objects (`new`)
49
+
50
+
The basic `new` operation is represented in Java bytecode by the `new` op
51
+
52
+
These are converted by \ref remove_java_newt::lower_java_new
53
+
54
+
For example, the following Java code:
55
+
56
+
```java
57
+
TestClass f =newTestClass();
58
+
```
59
+
60
+
Which is represented as the following Java bytecode:
61
+
62
+
```
63
+
0: new #2 // class TestClass
64
+
3: dup
65
+
4: invokespecial #3 // Method "<init>":()V
66
+
```
67
+
68
+
The first instruction only is translated into the following `codet`s:
For more details about the zero expression see \ref expr_initializert
76
+
77
+
\subsection oned_arrays Single Dimensional Arrays (`newarray`)
78
+
79
+
The new Java array operation is represented in Java bytecode by the `newarray` operation.
80
+
81
+
These are converted by \ref remove_java_newt::lower_java_new_array
82
+
83
+
See TODO:details about java arrays for details on how arrays are represented in codet. It first allocates the array object as with a regular Java object. Then the size component is set to be the size of the array and the data component is also initialized.
84
+
85
+
For example the following Java:
86
+
87
+
```java
88
+
TestClass[] tArray = new TestClass[5];
89
+
```
90
+
91
+
Which is compiled into the following Java bytecode:
0 commit comments