void ik_delete_pcb(ikpcb* pcb){ ikpage* p = pcb->cached_pages; pcb->cached_pages = 0; pcb->uncached_pages = 0; while(p){ ik_munmap(p->base, pagesize); p = p->next; } ik_munmap(pcb->cached_pages_base, pcb->cached_pages_size); { int i; for(i=0; i<generation_count; i++){ ik_ptr_page* p = pcb->protected_list[i]; while(p){ ik_ptr_page* next = p->next; ik_munmap((ikptr)(long)p, pagesize); p = next; } } } ikptr base = pcb->memory_base; ikptr end = pcb->memory_end; unsigned int* segment_vec = pcb->segment_vector; long int i = page_index(base); long int j = page_index(end); while(i < j){ unsigned int t = segment_vec[i]; if(t != hole_mt){ ik_munmap((ikptr)(i<<pageshift), pagesize); } i++; } long int vecsize = (segment_index(end) - segment_index(base)) * pagesize; ik_munmap((ikptr)(long)pcb->dirty_vector_base, vecsize); ik_munmap((ikptr)(long)pcb->segment_vector_base, vecsize); ik_free(pcb, sizeof(ikpcb)); }
static void extend_table_maybe(ikptr p, unsigned long int size, ikpcb* pcb){ assert(size == align_to_next_page(size)); ikptr q = p + size; if(p < pcb->memory_base){ unsigned long int new_lo = segment_index(p); unsigned long int old_lo = segment_index(pcb->memory_base); unsigned long int hi = segment_index(pcb->memory_end); unsigned long int new_vec_size = (hi - new_lo) * pagesize; unsigned long int old_vec_size = (hi - old_lo) * pagesize; ikptr v = ik_mmap(new_vec_size); bzero((char*)(long)v, new_vec_size - old_vec_size); memcpy((char*)(long)(v+new_vec_size-old_vec_size), (char*)(long)pcb->dirty_vector_base, old_vec_size); ik_munmap((ikptr)(long)pcb->dirty_vector_base, old_vec_size); pcb->dirty_vector_base = (unsigned int*)(long)v; pcb->dirty_vector = (v - new_lo * pagesize); ikptr s = ik_mmap(new_vec_size); bzero((char*)(long)s, new_vec_size - old_vec_size); memcpy((char*)(long)(s+new_vec_size-old_vec_size), (char*)(long)(pcb->segment_vector_base), old_vec_size); ik_munmap((ikptr)(long)pcb->segment_vector_base, old_vec_size); pcb->segment_vector_base = (unsigned int*)(long)s; pcb->segment_vector = (unsigned int*)(long)(s - new_lo * pagesize); pcb->memory_base = (new_lo * segment_size); } else if (q >= pcb->memory_end){ unsigned long int lo = segment_index(pcb->memory_base); unsigned long int old_hi = segment_index(pcb->memory_end); unsigned long int new_hi = segment_index(q+segment_size-1); unsigned long int new_vec_size = (new_hi - lo) * pagesize; unsigned long int old_vec_size = (old_hi - lo) * pagesize; ikptr v = ik_mmap(new_vec_size); memcpy((char*)(long)v, (char*)(long)pcb->dirty_vector_base, old_vec_size); bzero((char*)(long)(v+old_vec_size), new_vec_size - old_vec_size); ik_munmap((ikptr)(long)pcb->dirty_vector_base, old_vec_size); pcb->dirty_vector_base = (unsigned int*)(long)v; pcb->dirty_vector = (v - lo * pagesize); ikptr s = ik_mmap(new_vec_size); memcpy((char*)(long)s, pcb->segment_vector_base, old_vec_size); bzero((char*)(long)(s+old_vec_size), new_vec_size - old_vec_size); ik_munmap((ikptr)(long)pcb->segment_vector_base, old_vec_size); pcb->segment_vector_base = (unsigned int*)(long) s; pcb->segment_vector = (unsigned int*)(s - lo * pagesize); pcb->memory_end = (new_hi * segment_size); } }
void merge_path_operation::merge_inside (svg_path *path, svg_path_geom_iterator dest, svg_path_geom_iterator src) { /// if it is the same subpath, just close it if (&dest.subpath () == &src.subpath ()) { auto &elements = dest.subpath ().elements (); auto &front_elem = elements.front (); auto &back_elem = elements.back (); if (elements.size () > 1 && front_elem.point == back_elem.point) { front_elem.c1 = back_elem.c1; svg_path_geom_iterator last_segment_point (*path->get_geom (), dest.get_subpath_index (), dest.subpath ().last_point ()); size_t point_index = last_segment_point.point_index (); path->get_node_type ()->erase (path->get_node_type ()->begin () + point_index); elements.pop_back (); } dest.subpath ().set_closed (true); return; } /// else merge two subpaths // if dest is subpath begin, prepend src vector<single_path_point> &dest_subpath = dest.subpath ().elements (), &src_subpath = src.subpath ().elements (); if (src_subpath.size () > 0) { svg_path_geom *geom = path->get_geom (); auto line_segment = path->get_is_line_segment (); auto node_types = path->get_node_type (); auto line_begin = line_segment->begin (); auto node_type_begin = node_types->begin (); int dest_subpath_index = (int)dest.get_subpath_index (); int src_subpath_index = (int)src.get_subpath_index (); auto src_begin_it = geom->subpath_begin (src_subpath_index); auto dst_begin_it = geom->subpath_begin (dest_subpath_index); if (dest.get_subpath_point () == 0) { if (src.get_subpath_point () == 0) path->reverse_subpath ((int)src.get_subpath_index ()); slide (line_begin + src_begin_it.segment_index (cp_type::RIGHT), line_begin + src_begin_it.segment_index (cp_type::RIGHT) + src.subpath ().total_segments (), line_begin + dst_begin_it.segment_index (cp_type::RIGHT)); slide (node_type_begin + src_begin_it.point_index (), node_type_begin + src_begin_it.point_index () + src.subpath ().total_points (), node_type_begin + dst_begin_it.point_index ()); node_types->erase (node_type_begin + src_begin_it.point_index () + src.subpath ().total_points () - 1); dest_subpath.insert (dest_subpath.begin (), src_subpath.begin (), src_subpath.end () - 1); } else { /// reverse src if necessary if (src.get_subpath_point () != 0) path->reverse_subpath ((int)src.get_subpath_index ()); slide (line_begin + src_begin_it.segment_index (cp_type::RIGHT), line_begin + src_begin_it.segment_index (cp_type::RIGHT) + src.subpath ().total_segments (), line_begin + dst_begin_it.segment_index (cp_type::RIGHT) + dest.subpath ().total_segments ()); slide (node_type_begin + src_begin_it.point_index (), node_type_begin + src_begin_it.point_index () + src.subpath ().total_points (), node_type_begin + dst_begin_it.point_index () + dest.subpath ().total_points ()); node_types->erase (node_type_begin + src_begin_it.point_index ()); dest_subpath.insert (dest_subpath.end (), src_subpath.begin () + 1, src_subpath.end ()); } } auto & subpath = path->get_geom ()->subpath (); subpath.erase (subpath.begin () + src.get_subpath_index ()); }
ikpcb* ik_make_pcb(){ ikpcb* pcb = ik_malloc(sizeof(ikpcb)); bzero(pcb, sizeof(ikpcb)); pcb->collect_key = false_object; #define STAKSIZE (1024 * 4096) //#define STAKSIZE (256 * 4096) pcb->heap_base = ik_mmap(IK_HEAPSIZE); pcb->heap_size = IK_HEAPSIZE; pcb->allocation_pointer = pcb->heap_base; pcb->allocation_redline = pcb->heap_base + IK_HEAPSIZE - 2 * 4096; pcb->stack_base = ik_mmap(STAKSIZE); pcb->stack_size = STAKSIZE; pcb->frame_pointer = pcb->stack_base + pcb->stack_size; pcb->frame_base = pcb->frame_pointer; pcb->frame_redline = pcb->stack_base + 2 * 4096; { /* make cache ikpage */ ikpage* p = (ikpage*)(long)ik_mmap(CACHE_SIZE * sizeof(ikpage)); pcb->cached_pages_base = (ikptr)(long)p; pcb->cached_pages_size = CACHE_SIZE * sizeof(ikpage); ikpage* q = 0; ikpage* e = p + CACHE_SIZE; while(p < e){ p->next = q; q = p; p++; } pcb->uncached_pages = q; } { /* compute extent of heap and stack */ ikptr lo_mem; ikptr hi_mem; if(pcb->heap_base < pcb->stack_base){ lo_mem = pcb->heap_base - pagesize; hi_mem = pcb->stack_base + pcb->stack_size + pagesize; } else { lo_mem = pcb->stack_base - pagesize; hi_mem = pcb->heap_base + pcb->heap_size + pagesize; } unsigned long int lo_seg = segment_index(lo_mem); unsigned long int hi_seg = segment_index(hi_mem+segment_size-1); unsigned long int vec_size = (hi_seg - lo_seg) * pagesize; ikptr dvec = ik_mmap(vec_size); bzero((char*)(long)dvec, vec_size); pcb->dirty_vector_base = (unsigned int*)(long) dvec; pcb->dirty_vector = (dvec - lo_seg * pagesize); ikptr svec = ik_mmap(vec_size); bzero((char*)(long)svec, vec_size); pcb->segment_vector_base = (unsigned int*)(long)svec; pcb->segment_vector = (unsigned int*)(long)(svec - lo_seg * pagesize); pcb->memory_base = (ikptr)(lo_seg * segment_size); pcb->memory_end = (ikptr)(hi_seg * segment_size); set_segment_type(pcb->heap_base, pcb->heap_size, mainheap_mt, pcb); set_segment_type(pcb->stack_base, pcb->stack_size, mainstack_mt, pcb); } /* initialize base rtd */ { ikptr r = ik_unsafe_alloc(pcb, align(rtd_size)) + rtd_tag; ref(r, off_rtd_rtd) = r; ref(r, off_rtd_length) = (ikptr) (rtd_size-wordsize); ref(r, off_rtd_name) = 0; ref(r, off_rtd_fields) = 0; ref(r, off_rtd_printer) = 0; ref(r, off_rtd_symbol) = 0; pcb->base_rtd = r; } return pcb; }