/****************************************************************************** **函数名称: _avl_print **功 能: 打印平衡二叉树(内部接口) **输入参数: ** tree: 平衡二叉树 **输出参数: NONE **返 回: VOID **实现描述: ** 1. 结点入栈 ** 2. 打印该结点(头) ** 3. 打印该结点的右子树 ** 4. 打印该结点的左子树 ** 5. 打印该结点(尾) ** 6. 结点出栈 **注意事项: **作 者: # Qifeng.zou # 2013.12.17 # ******************************************************************************/ int _avl_print(avl_node_t *root, Stack_t *stack) { int depth; avl_node_t *node = root; /* 1. 将要处理的结点压栈 */ stack_push(stack, node); depth = stack_depth(stack); /* 2. 打印结点头 */ avl_print_head(node, depth); /* 3. 打印右子树 */ if (NULL != node->rchild) { _avl_print(node->rchild, stack); } /* 4. 打印左子树 */ if (NULL != node->lchild) { _avl_print(node->lchild, stack); } depth = stack_depth(stack); /* 5. 打印结点尾 */ avl_print_tail(node, depth); /* 6. 出栈 */ stack_pop(stack); return AVL_OK; }
void pdf_format::stack_event(stream_type& os, bool is_push) { const format_element_t& top(stack_top()); name_t self(top.tag()); name_t parent(stack_depth() >= 2 ? stack_n(1).tag() : name_t()); name_t grandparent(stack_depth() >= 3 ? stack_n(2).tag() : name_t()); if (self == atom_name_g) { handle_atom(os, is_push); } else if (is_push) { if (self == static_name_t("pdf")) { os << "% start pdf" << std::endl; } else if (self == bag_name_g) { os << "<<"; up(); } else if (self == seq_name_g && parent != bag_name_g) { os << "[ "; } } else { if (self == static_name_t("pdf")) { os << "\n% end pdf"; } else if (self == bag_name_g) { down(); if (top.num_out_m > 0) os << '\n' << indents(depth()); else os << ' '; os << ">>"; } else if (self == seq_name_g && parent != bag_name_g) { if (top.num_out_m > 0) os << ' '; os << ']'; } } }
// -----[ _radix_tree_enum_has_next ]-------------------------------- static int _radix_tree_enum_has_next(void * ctx) { _enum_ctx_t * ectx= (_enum_ctx_t *) ctx; // Depth first search while ((ectx->data == NULL) && (ectx->tree_item != NULL)) { if (ectx->tree_item->data != NULL) ectx->data= ectx->tree_item->data; // Move to next item if (ectx->tree_item->left != NULL) { if (ectx->tree_item->right != NULL) _stack_push(ectx->stack, ectx->tree_item->right, ectx->key_len+1, ectx->key+(1 << (ectx->tree->key_len-ectx->key_len-1))); ectx->tree_item= ectx->tree_item->left; ectx->key_len++; } else if (ectx->tree_item->right != NULL) { ectx->tree_item= ectx->tree_item->right; ectx->key= ectx->key+(1 << (ectx->tree->key_len-ectx->key_len-1)); ectx->key_len++; } else { if (stack_depth(ectx->stack) > 0) _stack_pop(ectx->stack, &ectx->tree_item, &ectx->key_len, &ectx->key); else ectx->tree_item= NULL; } } return (ectx->data != NULL); }
void asl_cel_format::stack_event(stream_type& os, bool is_push) { const format_element_t& top(stack_top()); name_t self(top.tag()); name_t parent(stack_depth() >= 2 ? stack_n(1).tag() : name_t()); if (self == atom_name_g) { handle_atom(os, is_push); } else if (is_push) { if (self == bag_name_g) { os << '{'; up(); } else if (self == seq_name_g && parent != bag_name_g) { os << "[ "; } } else { if (self == bag_name_g) { down(); if (top.num_out_m > 0) os << '\n' << indents(depth()); else os << ' '; os << '}'; } else if (self == seq_name_g && parent != bag_name_g) { if (top.num_out_m > 0) os << ' '; os << ']'; } } }
void stack_depth( symbol_tablet &symbol_table, goto_functionst &goto_functions, const int depth) { const symbol_exprt sym=add_stack_depth_symbol(symbol_table); const exprt depth_expr(from_integer(depth, sym.type())); Forall_goto_functions(f_it, goto_functions) if(f_it->second.body_available && f_it->first!=CPROVER_PREFIX "initialize" && f_it->first!=ID_main) stack_depth(f_it->second.body, sym, depth, depth_expr); // initialize depth to 0 goto_functionst::function_mapt::iterator i_it=goto_functions.function_map.find(CPROVER_PREFIX "initialize"); assert(i_it!=goto_functions.function_map.end()); goto_programt &init=i_it->second.body; goto_programt::targett first=init.instructions.begin(); goto_programt::targett it=init.insert_before(first); it->make_assignment(); it->code=code_assignt(sym, from_integer(0, sym.type())); it->location=first->location; it->function=first->function; // update counters etc. goto_functions.update(); }
//============================================================================= //------------------------------InlineTree------------------------------------- InlineTree::InlineTree(Compile* c, const InlineTree *caller_tree, ciMethod* callee, JVMState* caller_jvms, int caller_bci, float site_invoke_ratio, int max_inline_level) : C(c), _caller_jvms(caller_jvms), _caller_tree((InlineTree*) caller_tree), _method(callee), _site_invoke_ratio(site_invoke_ratio), _max_inline_level(max_inline_level), _count_inline_bcs(method()->code_size_for_inlining()), _subtrees(c->comp_arena(), 2, 0, NULL), _msg(NULL) { #ifndef PRODUCT _count_inlines = 0; _forced_inline = false; #endif if (_caller_jvms != NULL) { // Keep a private copy of the caller_jvms: _caller_jvms = new (C) JVMState(caller_jvms->method(), caller_tree->caller_jvms()); _caller_jvms->set_bci(caller_jvms->bci()); assert(!caller_jvms->should_reexecute(), "there should be no reexecute bytecode with inlining"); } assert(_caller_jvms->same_calls_as(caller_jvms), "consistent JVMS"); assert((caller_tree == NULL ? 0 : caller_tree->stack_depth() + 1) == stack_depth(), "correct (redundant) depth parameter"); assert(caller_bci == this->caller_bci(), "correct (redundant) bci parameter"); // Update hierarchical counts, count_inline_bcs() and count_inlines() InlineTree *caller = (InlineTree *)caller_tree; for( ; caller != NULL; caller = ((InlineTree *)(caller->caller_tree())) ) { caller->_count_inline_bcs += count_inline_bcs(); NOT_PRODUCT(caller->_count_inlines++;) } }
void test_stack_push_pop(void) { test_start(); struct stack *st = NULL; void *A = (void *) 0x4354523; void *B = (void *) 0x0918401; void *C = (void *) 0x0809481; void *D = (void *) 0x9084019; halt_on_true(stack_push(&st, A), "Failed to push A"); fail_on_true(stack_empty(&st), "Stack is empty, but A is there"); fail_on_false(stack_depth(&st) == 1, "Stack's depth is not 1"); fail_on_false(stack_top(&st) == A, "Top value is not A"); halt_on_true(stack_push(&st, B), "Failed to push B"); fail_on_true(stack_empty(&st), "Stack is empty, but A, B is there"); fail_on_false(stack_depth(&st) == 2, "Stack's depth is not 2"); fail_on_false(stack_top(&st) == B, "Top value is not B"); halt_on_false(stack_pop(&st) == B, "Popped value is not B"); fail_on_true(stack_empty(&st), "Stack is empty, but A is there"); fail_on_false(stack_depth(&st) == 1, "Stack's depth is not 1"); fail_on_false(stack_top(&st) == A, "Top value is not A"); halt_on_true(stack_push(&st, C), "Failed to push C"); fail_on_true(stack_empty(&st), "Stack is empty, but C, C is there"); fail_on_false(stack_depth(&st) == 2, "Stack's depth is not 2"); fail_on_false(stack_top(&st) == C, "Top value is not C"); halt_on_true(stack_push(&st, D), "Failed to push D"); fail_on_true(stack_empty(&st), "Stack is empty, but D, D is there"); fail_on_false(stack_depth(&st) == 3, "Stack's depth is not 3"); fail_on_false(stack_top(&st) == D, "Top value is not D"); fail_on_false(stack_pop(&st) == D, "Popped value is not D"); fail_on_true(stack_empty(&st), "Stack is empty, but A, C is there"); fail_on_false(stack_pop(&st) == C, "Popped value is not C"); fail_on_true(stack_empty(&st), "Stack is empty, but A is there"); fail_on_false(stack_pop(&st) == A, "Popped value is not A"); fail_on_false(stack_empty(&st), "Stack is not empty"); fail_on_false(stack_pop(&st) == NULL, "Popped value is not NULL"); test_end(); }
/****************************************************************************** **函数名称: _xml_node_len **功 能: 计算节点打印成XML格式字串时的长度(注: XML有层次结构) **输入参数: ** root: XML树根节点 ** stack: 栈 **输出参数: **返 回: 节点及其属性、孩子节点的总长度 **实现描述: **注意事项: **作 者: # Qifeng.zou # 2013.06.10 # ******************************************************************************/ int _xml_node_len(xml_tree_t *xml, xml_node_t *root, Stack_t *stack) { int depth, len; xml_node_t *node = root; depth = stack_depth(stack); if (0 != depth) { log_error(xml->log, "Stack depth must empty. depth:[%d]", depth); return XML_ERR_STACK; } len = 0; do { /* 1. 将要处理的节点压栈 */ node->temp = node->child; if (stack_push(stack, node)) { log_error(xml->log, "Stack push failed!"); return XML_ERR_STACK; } /* 2. 打印节点名 */ depth = stack_depth(stack); xml_node_name_len(node, depth, len); /* 3. 打印属性节点 */ if (xml_has_attr(node)) { xml_node_attr_len(node, len); } /* 4. 打印节点值 */ xml_node_value_len(node, len); /* 5. 选择下一个处理的节点: 从父亲节点、兄弟节点、孩子节点中 */ node = xml_node_next_len(xml, stack, node, &len); }while (NULL != node); if (!stack_empty(stack)) { return XML_ERR_STACK; } return len; }
void test_stack_move(void) { test_start(); struct stack *left = NULL; struct stack *right = NULL; void *A = (void *) 0x8970198; void *B = (void *) 0x1298730; void *C = (void *) 0x09812a0; fail_on_true(stack_push(&left, A), "Failed to push A to left"); fail_on_true(stack_push(&left, B), "Failed to push B to left"); fail_on_true(stack_push(&right, C), "Failed to push C to right"); fail_on_false(stack_depth(&left) == 2, "Depth of left is not 2"); fail_on_false(stack_depth(&right) == 1, "Depth of right is not 1"); fail_on_false(stack_move(&left, &right) == B, "Moving whatever but not B"); fail_on_false(stack_depth(&left) == 1, "Depth of left is not 1"); fail_on_false(stack_depth(&right) == 2, "Depth of right is not 2"); fail_on_false(stack_move(&left, &right) == A, "Moving whatever but not B"); fail_on_false(stack_depth(&left) == 0, "Depth of left is not 0"); fail_on_false(stack_depth(&right) == 3, "Depth of right is not 3"); fail_on_false(stack_pop(&right) == A, "Popping whatever but not A"); fail_on_false(stack_pop(&right) == B, "Popping whatever but not B"); fail_on_false(stack_pop(&right) == C, "Popping whatever but not C"); test_end(); }
/** * Remove the item at position 'key/Len' as well as all the empty * nodes that are on the way. * * Parameters: * - iSingle, if 1 remove a single key otherwise, remove the key and * all the keys under. */ int radix_tree_remove(gds_radix_tree_t * tree, uint32_t key, uint8_t key_len, int iSingle) { gds_stack_t * stack= stack_create(tree->key_len); uint8_t uLen= key_len; _radix_tree_item_t ** ptree_item= &tree->root; int iEmpty; while (uLen > 0) { if (*ptree_item == NULL) return -1; if (key & (1 << (tree->key_len-(key_len+1-uLen)))) { if ((*ptree_item)->right != NULL) { stack_push(stack, ptree_item); ptree_item= &(*ptree_item)->right; } else return -1; } else { if ((*ptree_item)->left != NULL) { stack_push(stack, ptree_item); ptree_item= &(*ptree_item)->left; } else return -1; } uLen--; } if ((*ptree_item == NULL) || ((*ptree_item)->data == NULL)) return -1; /* Keep information on the current key's emptiness. The key is considered empty if it has no child and has no item. */ iEmpty= (((*ptree_item)->left == NULL) && ((*ptree_item)->right == NULL)); radix_tree_item_destroy(ptree_item, tree->fDestroy, iSingle); /* If the current item is empty (no key below, go up towards the radix-tree's root and clear keys until a non-empty is found. */ while (iEmpty && (stack_depth(stack) > 0)) { ptree_item= (_radix_tree_item_t **) stack_pop(stack); /* If the key is empty (no child and no item), remove it. */ if (((*ptree_item)->left == NULL) && ((*ptree_item)->right == NULL) && ((*ptree_item)->data == NULL)) { radix_tree_item_destroy(ptree_item, tree->fDestroy, 1); } else break; } stack_destroy(&stack); return 0; }
/** * Call the 'fForEach' function for each non empty node. */ int radix_tree_for_each(gds_radix_tree_t * tree, FRadixTreeForEach fForEach, void * ctx) { gds_stack_t * stack= stack_create(tree->key_len); _radix_tree_item_t * tree_item; int result= 0; uint32_t key; uint8_t key_len; tree_item= tree->root; key= 0; key_len= 0; // Depth first search while (tree_item != NULL) { if (tree_item->data!= NULL) { result= fForEach(key, key_len, tree_item->data, ctx); if (result != 0) return result; } if (tree_item->left != NULL) { if (tree_item->right != NULL) _stack_push(stack, tree_item->right, key_len+1, key+(1 << (tree->key_len-key_len-1))); tree_item= tree_item->left; key_len++; } else if (tree_item->right != NULL) { tree_item= tree_item->right; key= key+(1 << (tree->key_len-key_len-1)); key_len++; } else { if (stack_depth(stack) > 0) _stack_pop(stack, &tree_item, &key_len, &key); else break; } } stack_destroy(&stack); return 0; }
/** * Remove an item. Remove also all its children if the parameter * 'iSingle' is 1. */ void radix_tree_item_destroy(_radix_tree_item_t ** ptree_item, FRadixTreeDestroy fDestroy, int iSingle) { gds_stack_t * stack= stack_create(32); _radix_tree_item_t * tree_item= *ptree_item; while (tree_item != NULL) { /* If all children are to be removed, push them onto stack. */ if (!iSingle) { if (tree_item->left != NULL) stack_push(stack, tree_item->left); if (tree_item->right != NULL) stack_push(stack, tree_item->right); } /* Destroy the item. */ if ((tree_item->data != NULL) && (fDestroy != NULL)) { fDestroy(&tree_item->data); tree_item->data= NULL; } /* If the current item is empty (no child) or if we delete all child, then free the item's memory. */ if (((tree_item->left == NULL) && (tree_item->right == NULL)) || !iSingle) { FREE(tree_item); *ptree_item= NULL; } /* Any other child to be removed ? */ if (stack_depth(stack) > 0) tree_item= (_radix_tree_item_t *) stack_pop(stack); else tree_item= NULL; } stack_destroy(&stack); }
int inline_level() const { return stack_depth(); }
/* Walk all references for an ObjectIndex and construct the hprof CLASS dump. */ static void dump_class_and_supers(JNIEnv *env, ObjectIndex object_index, RefIndex list) { SiteIndex site_index; SerialNumber trace_serial_num; RefIndex index; ClassIndex super_cnum; ObjectIndex super_index; LoaderIndex loader_index; ObjectIndex signers_index; ObjectIndex domain_index; FieldInfo *fields; jvalue *fvalues; jint n_fields; jlong size; ClassIndex cnum; char *sig; ObjectKind kind; TraceIndex trace_index; Stack *cpool_values; ConstantPoolValue *cpool; jint cpool_count; jboolean skip_fields; HPROF_ASSERT(object_index!=0); kind = object_get_kind(object_index); if ( kind != OBJECT_CLASS ) { return; } site_index = object_get_site(object_index); HPROF_ASSERT(site_index!=0); cnum = site_get_class_index(site_index); HPROF_ASSERT(cnum!=0); if ( class_get_status(cnum) & CLASS_DUMPED ) { return; } class_add_status(cnum, CLASS_DUMPED); size = (jlong)object_get_size(object_index); super_index = 0; super_cnum = class_get_super(cnum); if ( super_cnum != 0 ) { super_index = class_get_object_index(super_cnum); if ( super_index != 0 ) { dump_class_and_supers(env, super_index, object_get_references(super_index)); } } trace_index = site_get_trace_index(site_index); HPROF_ASSERT(trace_index!=0); trace_serial_num = trace_get_serial_number(trace_index); sig = string_get(class_get_signature(cnum)); n_fields = 0; fields = NULL; fvalues = NULL; skip_fields = JNI_TRUE; if ( class_get_all_fields(env, cnum, &n_fields, &fields) == 0 ) { if ( n_fields > 0 ) { skip_fields = JNI_FALSE; fvalues = (jvalue*)HPROF_MALLOC(n_fields*(int)sizeof(jvalue)); (void)memset(fvalues, 0, n_fields*(int)sizeof(jvalue)); } } /* We use a Stack just because it will automatically expand as needed */ cpool_values = stack_init(16, 16, sizeof(ConstantPoolValue)); cpool = NULL; cpool_count = 0; loader_index = class_get_loader(cnum); signers_index = 0; domain_index = 0; index = list; while ( index != 0 ) { RefInfo *info; info = get_info(index); /* Process reference objects, many not used right now. */ switch ( info->kind ) { case JVMTI_REFERENCE_STATIC_FIELD: /* If the class_tag is 0, it is possible for * info->element_index to be >= n_fields * and when this happens we just skip this field ref * for now. We probably have a java.lang.Object class * with n_fields==0, which is probably the wrong class. */ if (info->class_tag == (jlong)0 || skip_fields == JNI_TRUE ) { break; } HPROF_ASSERT(info->element_index < n_fields); if (info->element_index < n_fields) { ObjectIndex field_object_index; /* Field index is referrer_index from referrer_tag */ field_object_index = tag_to_object_index(info->object_tag); fvalues[info->element_index].i = field_object_index; } break; case JVMTI_REFERENCE_CONSTANT_POOL: { ConstantPoolValue cpv; ObjectIndex cp_object_index; SiteIndex cp_site_index; ClassIndex cp_cnum; cp_object_index = tag_to_object_index(info->object_tag); HPROF_ASSERT(cp_object_index!=0); cp_site_index = object_get_site(cp_object_index); HPROF_ASSERT(cp_site_index!=0); cp_cnum = site_get_class_index(cp_site_index); cpv.constant_pool_index = info->element_index; cpv.sig_index = class_get_signature(cp_cnum); cpv.value.i = cp_object_index; stack_push(cpool_values, (void*)&cpv); cpool_count++; break; } default: break; } index = info->next; } /* FIXUP: Fill rest of static primitive fields? If requested? */ /* Use: value = getStaticFieldValue(env, klass, field, field_sig); ? */ HPROF_ASSERT(cpool_count==stack_depth(cpool_values)); if ( cpool_count > 0 ) { cpool = (ConstantPoolValue*)stack_element(cpool_values, 0); } io_heap_class_dump(cnum, sig, object_index, trace_serial_num, super_index, loader_index, signers_index, domain_index, (jint)size, cpool_count, cpool, n_fields, fields, fvalues); stack_term(cpool_values); if ( fvalues != NULL ) { HPROF_FREE(fvalues); } }
/****************************************************************************** **函数名称: xml_node_next_len **功 能: 获取下一个要处理的节点,并计算当前结束节点的长度(注: XML有层次结构) **输入参数: ** root: XML树根节点 ** stack: 栈 **输出参数: **返 回: 0:成功 !0:失败 **实现描述: **注意事项: **作 者: # Qifeng.zou # 2013.06.10 # ******************************************************************************/ static xml_node_t *xml_node_next_len( xml_tree_t *xml, Stack_t *stack, xml_node_t *node, int *len) { xml_node_t *top, *child; int depth, level, len2; /* 首先: 处理孩子节点: 选出下一个孩子节点 */ if (NULL != node->temp) { child = node->temp; node->temp = child->next; node = child; return node; } /* 再次: 处理其兄弟节点: 选出下一个兄弟节点 */ len2 = 0; /* 1. 弹出已经处理完成的节点 */ top = stack_gettop(stack); if (xml_has_child(top)) { depth = stack_depth(stack); level = depth - 1; while (level > 1) { /* fprintf(fp, "\t"); */ len2++; level--; } /* fprintf(fp, "</%s>\n", top->name); */ len2 += (top->name.len + 4); } if (NULL == stack_pop(stack)) { *len += len2; log_error(xml->log, "Stack pop failed!"); return NULL; } if (stack_empty(stack)) { *len += len2; log_error(xml->log, "Compelte fprint!"); return NULL; } /* 2. 处理其下一个兄弟节点 */ node = top->next; while (NULL == node) /* 所有兄弟节点已经处理完成,说明父亲节点也处理完成 */ { /* 3. 父亲节点出栈 */ top = stack_pop(stack); if (NULL == top) { *len += len2; log_error(xml->log, "Stack pop failed!"); return NULL; } /* 4. 打印父亲节点结束标志 */ if (xml_has_child(top)) { depth = stack_depth(stack); level = depth + 1; while (level > 1) { /* fprintf(fp, "\t"); */ len2++; level--; } /* fprintf(fp, "</%s>\n", top->name); */ len2 += (top->name.len + 4); } if (stack_empty(stack)) { *len += len2; return NULL; /* 处理完成 */ } /* 5. 选择父亲的兄弟节点 */ node = top->next; } *len += len2; return node; }
/****************************************************************************** **函数名称: rbt_print **功 能: 打印红黑树(外部接口) **输入参数: ** tree: 红黑树 **输出参数: NONE **返 回: VOID **实现描述: **注意事项: **作 者: # Qifeng.zou # 2013.12.17 # ******************************************************************************/ int rbt_print(rbt_tree_t *tree) { int depth = 0; Stack_t _stack, *stack = &_stack; rbt_node_t *node = tree->root, *parent = NULL; if (tree->sentinel == node) return 0; stack_init(stack, RBT_MAX_DEPTH); while (tree->sentinel != node) { /* 压左孩子入栈 */ while (tree->sentinel != node->lchild) { rbt_assert(tree, node); depth = stack_depth(stack); stack_push(stack, node); rbt_print_head(tree, node, depth); /* 打印头:入栈时打印头 出栈时打印尾 */ node = node->lchild; } /* 打印最左端的子孙结点 */ depth = stack_depth(stack); rbt_print_head(tree, node, depth); /* 最左端的孩子有右孩子 */ if (tree->sentinel != node->rchild) { stack_push(stack, node); node = node->rchild; continue; } /* 最左端的孩子无右孩子 */ rbt_print_tail(tree, node, depth); parent = stack_gettop(stack); if (NULL == parent) { return stack_destroy(stack); } /* 判断最左结点的父结点未处理完成 */ if (parent->lchild == node) { if (tree->sentinel != parent->rchild) { node = parent->rchild; continue; } } /* 判断最左结点的父结点已处理完成 */ while ((node == parent->rchild) || (tree->sentinel == parent->rchild)) { stack_pop(stack); depth = stack_depth(stack); rbt_print_tail(tree, parent, depth); /* 打印尾:出栈时打印尾 入栈时已打印头 */ node = parent; parent = stack_gettop(stack); if (NULL == parent) { return stack_destroy(stack); } } node = parent->rchild; } return stack_destroy(stack); }
int inline_depth() const { return stack_depth() + _site_depth_adjust; }
void asl_cel_format::handle_atom(stream_type& os, bool is_push) { const format_element_t& top(stack_top()); name_t parent(stack_depth() >= 2 ? stack_n(1).tag() : name_t()); name_t grandparent(stack_depth() >= 3 ? stack_n(2).tag() : name_t()); const any_regular_t& value(top.value()); bool outputting_bag(parent == seq_name_g && grandparent == bag_name_g); std::size_t& num_out(outputting_bag ? stack_n(2).num_out_m : stack_n(1).num_out_m); bool named_argument(outputting_bag && (num_out & 0x1) == 0); if (is_push) { // if this is not the first item in the element, add a comma and set up a newline if (num_out > 0) { if (!outputting_bag) { os << ", "; } else if (named_argument) { os << ",\n" << indents(depth()); } } else if (outputting_bag) { os << '\n' << indents(depth()); } if (value.type_info() == typeid(string)) { bool escape(needs_entity_escape(value.cast<string>())); if (escape_m && escape) os << "xml_unescape("; os << '\"' << (escape_m && escape ? entity_escape(value.cast<string>()) : value.cast<string>()) << '\"'; if (escape_m && escape) os << ")"; } else if (value.type_info() == typeid(name_t)) { if (!named_argument) os << '@'; os << value.cast<name_t>(); if (outputting_bag && named_argument) os << ": "; } else if (value.type_info() == typeid(bool)) { os << (value.cast<bool>() ? "true" : "false"); } else if (value.type_info() == typeid(double)) { double dbl_val(value.cast<double>()); boost::int64_t int_val(static_cast<boost::int64_t>(dbl_val)); if (dbl_val == int_val) { os << int_val; } else { // For asl_cel, we want to output floating-point values in decimal-based // fixed-point notation (asl_cel doesn't support any other format) with // a very high precision for accceptable roundtrip values. os.setf(std::ios_base::dec, std::ios_base::basefield); os.setf(std::ios_base::fixed, std::ios_base::floatfield); os.precision(16); os << dbl_val; } } else if (value.type_info() == typeid(empty_t)) { os << value.cast<empty_t>(); } else if (value.type_info() == typeid(dictionary_t)) { os << value.cast<dictionary_t>(); } else if (value.type_info() == typeid(array_t)) { os << value.cast<array_t>(); } else { os << "'" << value.type_info().name() << "'"; } } else { // up the number of outputted items for the parent to this atom ++num_out; } }
void push(SharkValue* value) { assert(stack_depth() < max_stack(), "stack overrun"); *(_sp++) = value; }
SharkValue* pop() { assert(stack_depth() > 0, "stack underrun"); return *(--_sp); }
/* Walk all references for an ObjectIndex and construct the hprof CLASS dump. */ static void dump_class_and_supers(JNIEnv *env, ObjectIndex object_index, RefIndex list) { SiteIndex site_index; SerialNumber trace_serial_num; RefIndex index; ClassIndex super_cnum; ObjectIndex super_index; LoaderIndex loader_index; ObjectIndex signers_index; ObjectIndex domain_index; FieldInfo *fields; jvalue *fvalues; jint n_fields; jboolean skip_fields; jint n_fields_set; jlong size; ClassIndex cnum; char *sig; ObjectKind kind; TraceIndex trace_index; Stack *cpool_values; ConstantPoolValue *cpool; jint cpool_count; HPROF_ASSERT(object_index!=0); kind = object_get_kind(object_index); if ( kind != OBJECT_CLASS ) { return; } site_index = object_get_site(object_index); HPROF_ASSERT(site_index!=0); cnum = site_get_class_index(site_index); HPROF_ASSERT(cnum!=0); if ( class_get_status(cnum) & CLASS_DUMPED ) { return; } class_add_status(cnum, CLASS_DUMPED); size = (jlong)object_get_size(object_index); super_index = 0; super_cnum = class_get_super(cnum); if ( super_cnum != 0 ) { super_index = class_get_object_index(super_cnum); if ( super_index != 0 ) { dump_class_and_supers(env, super_index, object_get_references(super_index)); } } trace_index = site_get_trace_index(site_index); HPROF_ASSERT(trace_index!=0); trace_serial_num = trace_get_serial_number(trace_index); sig = string_get(class_get_signature(cnum)); loader_index = class_get_loader(cnum); signers_index = 0; domain_index = 0; /* Get field information */ n_fields = 0; skip_fields = JNI_FALSE; n_fields_set = 0; fields = NULL; fvalues = NULL; if ( class_get_all_fields(env, cnum, &n_fields, &fields) == 1 ) { /* Problems getting all the fields, can't trust field index values */ skip_fields = JNI_TRUE; /* Class with no references at all? (ok to be unprepared if list==0?) */ if ( list != 0 ) { /* It is assumed that the reason why we didn't get the fields * was because the class is not prepared. */ if ( gdata->debugflags & DEBUGFLAG_UNPREPARED_CLASSES ) { dump_ref_list(list); debug_message("Unprepared class with references: %s\n", sig); } HPROF_ERROR(JNI_FALSE, "Trouble with unprepared classes"); } /* Why would an unprepared class contain references? */ } if ( n_fields > 0 ) { fvalues = (jvalue*)HPROF_MALLOC(n_fields*(int)sizeof(jvalue)); (void)memset(fvalues, 0, n_fields*(int)sizeof(jvalue)); } /* We use a Stack just because it will automatically expand as needed */ cpool_values = stack_init(16, 16, sizeof(ConstantPoolValue)); cpool = NULL; cpool_count = 0; index = list; while ( index != 0 ) { RefInfo *info; jvalue ovalue; static jvalue empty_value; info = get_info(index); switch ( info->flavor ) { case INFO_OBJECT_REF_DATA: switch ( info->refKind ) { case JVMTI_HEAP_REFERENCE_FIELD: case JVMTI_HEAP_REFERENCE_ARRAY_ELEMENT: /* Should never be seen on a class dump */ HPROF_ASSERT(0); break; case JVMTI_HEAP_REFERENCE_STATIC_FIELD: if ( skip_fields == JNI_TRUE ) { break; } ovalue = empty_value; ovalue.i = info->object_index; fill_in_field_value(list, fields, fvalues, n_fields, info->index, ovalue, 0); n_fields_set++; HPROF_ASSERT(n_fields_set <= n_fields); break; case JVMTI_HEAP_REFERENCE_CONSTANT_POOL: { ConstantPoolValue cpv; ObjectIndex cp_object_index; SiteIndex cp_site_index; ClassIndex cp_cnum; cp_object_index = info->object_index; HPROF_ASSERT(cp_object_index!=0); cp_site_index = object_get_site(cp_object_index); HPROF_ASSERT(cp_site_index!=0); cp_cnum = site_get_class_index(cp_site_index); cpv.constant_pool_index = info->index; cpv.sig_index = class_get_signature(cp_cnum); cpv.value.i = cp_object_index; stack_push(cpool_values, (void*)&cpv); cpool_count++; break; } case JVMTI_HEAP_REFERENCE_SIGNERS: signers_index = info->object_index; break; case JVMTI_HEAP_REFERENCE_PROTECTION_DOMAIN: domain_index = info->object_index; break; case JVMTI_HEAP_REFERENCE_CLASS_LOADER: case JVMTI_HEAP_REFERENCE_INTERFACE: default: /* Ignore, not needed */ break; } break; case INFO_PRIM_FIELD_DATA: if ( skip_fields == JNI_TRUE ) { break; } HPROF_ASSERT(info->primType!=0); HPROF_ASSERT(info->length==-1); HPROF_ASSERT(info->refKind==JVMTI_HEAP_REFERENCE_STATIC_FIELD); ovalue = get_key_value(index); fill_in_field_value(list, fields, fvalues, n_fields, info->index, ovalue, info->primType); n_fields_set++; HPROF_ASSERT(n_fields_set <= n_fields); break; case INFO_PRIM_ARRAY_DATA: default: /* Should never see these */ HPROF_ASSERT(0); break; } index = info->next; } /* Get constant pool data if we have any */ HPROF_ASSERT(cpool_count==stack_depth(cpool_values)); if ( cpool_count > 0 ) { cpool = (ConstantPoolValue*)stack_element(cpool_values, 0); } io_heap_class_dump(cnum, sig, object_index, trace_serial_num, super_index, loader_object_index(env, loader_index), signers_index, domain_index, (jint)size, cpool_count, cpool, n_fields, fields, fvalues); stack_term(cpool_values); if ( fvalues != NULL ) { HPROF_FREE(fvalues); } }
void pdf_format::handle_atom(stream_type& os, bool is_push) { const format_element_t& top(stack_top()); name_t self(top.tag()); name_t parent(stack_depth() >= 2 ? stack_n(1).tag() : name_t()); name_t grandparent(stack_depth() >= 3 ? stack_n(2).tag() : name_t()); const any_regular_t& value(top.value()); bool outputting_bag(parent == seq_name_g && grandparent == bag_name_g); std::size_t& num_out(outputting_bag ? stack_n(2).num_out_m : stack_n(1).num_out_m); bool named_argument(outputting_bag && num_out % 2 == 0); if (is_push) { // if this is not the first item in the element, add a comma and set up a newline if (num_out > 0) { if (!outputting_bag) { os << ' '; } else if (named_argument) { os << '\n' << indents(depth()); } } else if (outputting_bag) { os << '\n' << indents(depth()); } if (value.type_info() == adobe::type_info<string_t>()) { os << '(' << value.cast<string_t>() << ')'; } else if (value.type_info() == adobe::type_info<name_t>()) { os << '/' << value.cast<name_t>(); if (outputting_bag && named_argument) os << " "; } else if (value.type_info() == adobe::type_info<bool>()) { os << (value.cast<bool>() ? "true" : "false"); } else if (value.type_info() == adobe::type_info<double>()) { double dbl_val(value.cast<double>()); boost::int64_t int_val(static_cast<boost::int64_t>(dbl_val)); if (dbl_val == int_val) { os << int_val; } else { // For pdf, we want to output floating-point values in decimal-based // fixed-point notation (asl_cel doesn't support any other format) with // a very high precision for accceptable roundtrip values. os.setf(std::ios_base::dec, std::ios_base::basefield); os.setf(std::ios_base::fixed, std::ios_base::floatfield); os.precision(16); os << dbl_val; } } else if (value.type_info() == adobe::type_info<empty_t>()) { os << "null"; } else if (value.type_info() == adobe::type_info<dictionary_t>()) { os << value.cast<dictionary_t>(); } else if (value.type_info() == adobe::type_info<array_t>()) { os << value.cast<array_t>(); } else { os << "(pdf_unknown: " << value.type_info().name() << ")"; } } else { // up the number of outputted items for the parent to this atom ++num_out; } }