1212#include "class-heap.h"
1313#include "classfile.h"
1414#include "constant-pool.h"
15+ #include "list.h"
1516#include "object-heap.h"
1617#include "stack.h"
1718
@@ -1114,7 +1115,11 @@ stack_entry_t *execute(method_t *method,
11141115 find_field_info_from_index (index , clazz , & field_name ,
11151116 & field_descriptor );
11161117
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+ }
11181123
11191124 switch (field_descriptor [0 ]) {
11201125 case 'I' :
@@ -1166,7 +1171,11 @@ stack_entry_t *execute(method_t *method,
11661171 find_field_info_from_index (index , clazz , & field_name ,
11671172 & field_descriptor );
11681173
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+ }
11701179
11711180 switch (field_descriptor [0 ]) {
11721181 case 'I' :
@@ -1197,22 +1206,20 @@ stack_entry_t *execute(method_t *method,
11971206 char * class_name = find_class_name_from_index (index , clazz );
11981207 class_file_t * target_class ;
11991208
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" ) ) {
12041213 find_or_add_class_to_heap (class_name , prefix , & target_class );
12051214 assert (target_class && "Failed to load class in i_new" );
1206- stack [ count ++ ] = target_class ;
1215+ list_add ( target_class , list ) ;
12071216 class_name = find_class_name_from_index (
12081217 target_class -> info -> super_class , target_class );
1209- if (!strcmp (class_name , "java/lang/Object" ))
1210- break ;
12111218 }
12121219
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 ) {
12161223 if (target_class -> initialized )
12171224 continue ;
12181225 target_class -> initialized = true;
@@ -1226,10 +1233,11 @@ stack_entry_t *execute(method_t *method,
12261233 free (exec_res );
12271234 }
12281235 }
1229- free (stack );
12301236
1231- object_t * object = create_object (target_class );
1237+ object_t * object = create_object (list );
12321238 push_ref (op_stack , object );
1239+ list_del (list );
1240+ free (list );
12331241
12341242 pc += 3 ;
12351243 break ;
0 commit comments