12
12
#include "class-heap.h"
13
13
#include "classfile.h"
14
14
#include "constant-pool.h"
15
+ #include "list.h"
15
16
#include "object-heap.h"
16
17
#include "stack.h"
17
18
@@ -1114,7 +1115,11 @@ stack_entry_t *execute(method_t *method,
1114
1115
find_field_info_from_index (index , clazz , & field_name ,
1115
1116
& field_descriptor );
1116
1117
1117
- variable_t * addr = find_field_addr (obj , field_name );
1118
+ variable_t * addr = NULL ;
1119
+ while (!addr ) {
1120
+ addr = find_field_addr (obj , field_name );
1121
+ obj = obj -> parent ;
1122
+ }
1118
1123
1119
1124
switch (field_descriptor [0 ]) {
1120
1125
case 'I' :
@@ -1166,7 +1171,11 @@ stack_entry_t *execute(method_t *method,
1166
1171
find_field_info_from_index (index , clazz , & field_name ,
1167
1172
& field_descriptor );
1168
1173
1169
- variable_t * var = find_field_addr (obj , field_name );
1174
+ variable_t * var = NULL ;
1175
+ while (!var ) {
1176
+ var = find_field_addr (obj , field_name );
1177
+ obj = obj -> parent ;
1178
+ }
1170
1179
1171
1180
switch (field_descriptor [0 ]) {
1172
1181
case 'I' :
@@ -1197,22 +1206,20 @@ stack_entry_t *execute(method_t *method,
1197
1206
char * class_name = find_class_name_from_index (index , clazz );
1198
1207
class_file_t * target_class ;
1199
1208
1200
- /* FIXME: use linked list to prevent wasted space */
1201
- class_file_t * * stack = malloc ( sizeof ( class_file_t * ) * 100 );
1202
- size_t count = 0 ;
1203
- while (true ) {
1209
+ class_file_t * list = calloc ( 1 , sizeof ( class_file_t ));
1210
+ init_list ( list );
1211
+
1212
+ while (strcmp ( class_name , "java/lang/Object" ) ) {
1204
1213
find_or_add_class_to_heap (class_name , prefix , & target_class );
1205
1214
assert (target_class && "Failed to load class in i_new" );
1206
- stack [ count ++ ] = target_class ;
1215
+ list_add ( target_class , list ) ;
1207
1216
class_name = find_class_name_from_index (
1208
1217
target_class -> info -> super_class , target_class );
1209
- if (!strcmp (class_name , "java/lang/Object" ))
1210
- break ;
1211
1218
}
1212
1219
1213
- /* call static initialization */
1214
- while ( count ) {
1215
- target_class = stack [ -- count ];
1220
+ /* reversely call static initialization if class have not been
1221
+ * initialized */
1222
+ list_for_each ( target_class , list ) {
1216
1223
if (target_class -> initialized )
1217
1224
continue ;
1218
1225
target_class -> initialized = true;
@@ -1226,10 +1233,11 @@ stack_entry_t *execute(method_t *method,
1226
1233
free (exec_res );
1227
1234
}
1228
1235
}
1229
- free (stack );
1230
1236
1231
- object_t * object = create_object (target_class );
1237
+ object_t * object = create_object (list );
1232
1238
push_ref (op_stack , object );
1239
+ list_del (list );
1240
+ free (list );
1233
1241
1234
1242
pc += 3 ;
1235
1243
break ;
0 commit comments