@@ -116,9 +116,108 @@ To be documented.
116
116
117
117
To be documented.
118
118
119
- \section java-bytecode-remove-java-new Remove java new
119
+ \section java-bytecode-remove-java-new Remove ` new ` , ` newarray ` and ` multianewarray ` bytecode operators
120
120
121
- To be documented.
121
+ \ref remove_java_new.h is responsible for converting the ` new ` , ` newarray ` and
122
+ ` multianewarray ` Java bytecode operation into \ref codet. Specifically it
123
+ converts the bytecode instruction into: - An ALLOCATE with the size of the
124
+ object being created - An assignment to the value zeroing its contents - If an
125
+ array, initializing the size and data components - If a multi-dimensional
126
+ array, recursively calling ` java_new ` on each sub array
127
+
128
+ An ALLOCATE is a \ref side_effect_exprt that is interpreted by \ref
129
+ goto_symext::symex_allocate
130
+
131
+ _ Note: it does not call the constructor as this is done by a separate
132
+ java_bytecode operation._
133
+
134
+ \subsection java_objects Java Objects (` new ` )
135
+
136
+ The basic ` new ` operation is represented in Java bytecode by the ` new ` op
137
+
138
+ These are converted by \ref remove_java_newt::lower_java_new
139
+
140
+ For example, the following Java code:
141
+
142
+ ``` java
143
+ TestClass f = new TestClass ();
144
+ ```
145
+
146
+ Which is represented as the following Java bytecode:
147
+
148
+ ```
149
+ 0: new #2 // class TestClass
150
+ 3: dup
151
+ 4: invokespecial #3 // Method "<init>":()V
152
+ ```
153
+
154
+ The first instruction only is translated into the following ` codet ` s:
155
+
156
+ ``` cpp
157
+ tmp_object1 = side_effect_exprt(ALLOCATE, sizeof (TestClass))
158
+ *tmp_object1 = struct_exprt{.component = 0, ... }
159
+ ```
160
+
161
+ For more details about the zero expression see \ref expr_initializert
162
+
163
+ \subsection oned_arrays Single Dimensional Arrays (`newarray`)
164
+
165
+ The new Java array operation is represented in Java bytecode by the `newarray`
166
+ operation.
167
+
168
+ These are converted by \ref remove_java_newt::lower_java_new_array
169
+
170
+ See TODO: DOC-20: for details on how arrays are represented in codet. It first
171
+ allocates the array object as with a regular Java object. Then the size
172
+ component is set to be the size of the array and the data component is also
173
+ initialized.
174
+
175
+ For example the following Java:
176
+
177
+ ```java
178
+ TestClass[] tArray = new TestClass[5];
179
+ ```
180
+
181
+ Which is compiled into the following Java bytecode:
182
+
183
+ ```
184
+ 8: iconst_5
185
+ 9: anewarray #2 // class TestClass
186
+ ```
187
+
188
+ Is translated into the following ` codet ` s:
189
+
190
+ ``` cpp
191
+ tmp_object1 = side_effect_exprt(ALLOCATE, sizeof (java::array[referenence]))
192
+ *tmp_object1 = struct_exprt{.size = 0, .data = null}
193
+ tmp_object1->length = length
194
+ tmp_new_data_array1 = side_effect_exprt(java_new_array_data, TestClass)
195
+ tmp_object1->data = tmp_new_data_array1
196
+ ARRAY_SET (tmp_new_data_array1, NULL)
197
+ ```
198
+
199
+ The `ARRAY_SET` `codet` sets all the values to null.
200
+
201
+ \subsection multidarrays Multi Dimensional Arrays (`newmultiarray`)
202
+
203
+ The new Java multi dimensional array operation is represented in bytecode by
204
+ `multianewarray`
205
+
206
+ These are also by \ref remove_java_newt::lower_java_new_array
207
+
208
+ They work the same as single dimensional arrays but create a for loop for each
209
+ element in the array since these start initialized.
210
+
211
+ ```cpp
212
+ for(tmp_index = 0; tmp_index < dim_size; ++tmp_index)
213
+ {
214
+ struct java::array[reference] *subarray_init;
215
+ subarray_init = java_new_array
216
+ newarray_tmp1->data[tmp_index] = (void *)subarray_init;
217
+ }
218
+ ```
219
+
220
+ ` remove_java_new ` is then recursively applied to the new ` subarray ` .
122
221
123
222
\section java-bytecode-remove-exceptions remove_exceptions
124
223
0 commit comments