/** * Get this binding of current execution context * * @return ecma-value */ ecma_value_t vm_get_this_binding (void) { JERRY_ASSERT (vm_top_context_p != NULL); return ecma_copy_value (vm_stack_frame_get_reg_value (&vm_top_context_p->stack_frame, VM_REG_SPECIAL_THIS_BINDING), true); } /* vm_get_this_binding */
/** * Run garbage collecting */ void ecma_gc_run (void) { ecma_gc_new_objects_since_last_gc = 0; JERRY_ASSERT (ecma_gc_objects_lists[ECMA_GC_COLOR_BLACK] == NULL); /* if some object is referenced from stack or globals (i.e. it is root), mark it */ for (ecma_object_t *obj_iter_p = ecma_gc_objects_lists[ECMA_GC_COLOR_WHITE_GRAY]; obj_iter_p != NULL; obj_iter_p = ecma_gc_get_object_next (obj_iter_p)) { JERRY_ASSERT (!ecma_gc_is_object_visited (obj_iter_p)); if (ecma_gc_get_object_refs (obj_iter_p) > 0) { ecma_gc_set_object_visited (obj_iter_p, true); } } /* if some object is referenced from a register variable (i.e. it is root), * start recursive marking traverse from the object */ for (vm_stack_frame_t *frame_iter_p = vm_stack_get_top_frame (); frame_iter_p != NULL; frame_iter_p = frame_iter_p->prev_frame_p) { for (int32_t reg_index = 0; reg_index < frame_iter_p->regs_number; reg_index++) { ecma_value_t reg_value = vm_stack_frame_get_reg_value (frame_iter_p, reg_index); if (ecma_is_value_object (reg_value)) { ecma_object_t *obj_p = ecma_get_object_from_value (reg_value); ecma_gc_set_object_visited (obj_p, true); } } } bool marked_anything_during_current_iteration = false; do { marked_anything_during_current_iteration = false; for (ecma_object_t *obj_iter_p = ecma_gc_objects_lists[ECMA_GC_COLOR_WHITE_GRAY], *obj_prev_p = NULL, *obj_next_p; obj_iter_p != NULL; obj_iter_p = obj_next_p) { obj_next_p = ecma_gc_get_object_next (obj_iter_p); if (ecma_gc_is_object_visited (obj_iter_p)) { /* Moving the object to list of marked objects */ ecma_gc_set_object_next (obj_iter_p, ecma_gc_objects_lists[ECMA_GC_COLOR_BLACK]); ecma_gc_objects_lists[ECMA_GC_COLOR_BLACK] = obj_iter_p; if (likely (obj_prev_p != NULL)) { JERRY_ASSERT (ecma_gc_get_object_next (obj_prev_p) == obj_iter_p); ecma_gc_set_object_next (obj_prev_p, obj_next_p); } else { ecma_gc_objects_lists[ECMA_GC_COLOR_WHITE_GRAY] = obj_next_p; } ecma_gc_mark (obj_iter_p); marked_anything_during_current_iteration = true; } else { obj_prev_p = obj_iter_p; } } } while (marked_anything_during_current_iteration); /* Sweeping objects that are currently unmarked */ for (ecma_object_t *obj_iter_p = ecma_gc_objects_lists[ECMA_GC_COLOR_WHITE_GRAY], *obj_next_p; obj_iter_p != NULL; obj_iter_p = obj_next_p) { obj_next_p = ecma_gc_get_object_next (obj_iter_p); JERRY_ASSERT (!ecma_gc_is_object_visited (obj_iter_p)); ecma_gc_sweep (obj_iter_p); } /* Unmarking all objects */ ecma_gc_objects_lists[ECMA_GC_COLOR_WHITE_GRAY] = ecma_gc_objects_lists[ECMA_GC_COLOR_BLACK]; ecma_gc_objects_lists[ECMA_GC_COLOR_BLACK] = NULL; ecma_gc_visited_flip_flag = !ecma_gc_visited_flip_flag; } /* ecma_gc_run */