Exemplo n.º 1
0
void BytecodeTranslatorVisitor::variableInScope(AstVar* x) {
    assert(x->info() == NULL);
    if (locals() == (uint16_t) -1)
        ERROR("Too many vars");
    x->setInfo(new VarDescriptor({functionId(), locals()++, false}));
    bytecodeFunction()->setLocalsNumber(std::max(locals(), (uint16_t) bytecodeFunction()->localsNumber()));
}
Exemplo n.º 2
0
void jvmtiDeferredLocalVariableSet::oops_do(OopClosure* f) {
  // The Method* is on the stack so a live activation keeps it alive
  // either by mirror in interpreter or code in compiled code.
  for ( int i = 0; i < locals()->length(); i++ ) {
    if ( locals()->at(i)->type() == T_OBJECT) {
      f->do_oop(locals()->at(i)->oop_addr());
    }
  }
}
Exemplo n.º 3
0
void jvmtiDeferredLocalVariableSet::oops_do(OopClosure* f) {

  f->do_oop((oop*) &_method);
  for ( int i = 0; i < locals()->length(); i++ ) {
    if ( locals()->at(i)->type() == T_OBJECT) {
      f->do_oop(locals()->at(i)->oop_addr());
    }
  }
}
Exemplo n.º 4
0
bool CodeGenContext::LookupBitVariable(BitVariable& outVar,const std::string& module, const std::string& name,const YYLTYPE &modLoc,const YYLTYPE &nameLoc)
{
	if ((currentBlock()!=nullptr) && (locals().find(name) != locals().end()))
	{
		outVar=locals()[name];
		outVar.refLoc = nameLoc;
	}
	else
	{
		if (globals().find(name) == globals().end())
		{
			if (m_includes.find(module)!=m_includes.end())
			{
				if (m_includes[module]->LookupBitVariable(outVar,"",name,modLoc,nameLoc))
				{
					if (outVar.pinType!=0)		// TODO: Globals Vars!
					{
						outVar.fromExternal=true;
						outVar.refLoc = CombineTokenLocations(nameLoc,modLoc);
						return true;
					}
					else
					{
						return gContext.ReportError(false, EC_InternalError, CombineTokenLocations(nameLoc, modLoc), "TODO: Globals");
					}
				}
				else
				{
					return gContext.ReportError(false, EC_ErrorAtLocation, CombineTokenLocations(nameLoc,modLoc), "undeclared variable %s%s", module.c_str(), name.c_str());
				}
			}
			else if (isRoot)
			{
				if (module == "")
				{
					return gContext.ReportError(false, EC_ErrorAtLocation, nameLoc, "undeclared variable %s", name.c_str());
				}
				else
				{
					return gContext.ReportError(false, EC_ErrorAtLocation, CombineTokenLocations(nameLoc,modLoc), "undeclared variable %s%s", module.c_str(), name.c_str());
				}
			}
			return false;
		}
		else
		{
			outVar=globals()[name];
			outVar.refLoc = nameLoc;
		}
	}

	outVar.fromExternal=false;
	return true;
}
Exemplo n.º 5
0
void jvmtiDeferredLocalVariableSet::set_local_at(int idx, BasicType type, jvalue val) {
  int i;
  for ( i = 0 ; i < locals()->length() ; i++ ) {
    if ( locals()->at(i)->index() == idx) {
      assert(locals()->at(i)->type() == type, "Wrong type");
      locals()->at(i)->set_value(val);
      return;
    }
  }
  locals()->push(new jvmtiDeferredLocalVariable(idx, type, val));
}
Exemplo n.º 6
0
 Object* Thread::locals_remove(STATE, Symbol* key) {
   if(state->vm() != vm()) {
     return locals()->remove(state, key);
   }
   Fiber* fib = state->vm()->current_fiber.get();
   if(fib->nil_p() || fib->root_p()) {
     return locals()->remove(state, key);
   }
   if(fib->locals()->nil_p()) {
     return cNil;
   }
   return fib->locals()->remove(state, key);
 }
Exemplo n.º 7
0
void javaVFrame::print() {
  ResourceMark rm;
  vframe::print();
  tty->print("\t");
  method()->print_value();
  tty->cr();
  tty->print_cr("\tbci:    %d", bci());

  print_stack_values("locals",      locals());
  print_stack_values("expressions", expressions());

  GrowableArray<MonitorInfo*>* list = monitors();
  if (list->is_empty()) return;
  tty->print_cr("\tmonitor list:");
  for (int index = (list->length()-1); index >= 0; index--) {
    MonitorInfo* monitor = list->at(index);
    tty->print("\t  obj\t");
    if (monitor->owner_is_scalar_replaced()) {
      Klass* k = java_lang_Class::as_Klass(monitor->owner_klass());
      tty->print("( is scalar replaced %s)", k->external_name());
    } else if (monitor->owner() == NULL) {
      tty->print("( null )");
    } else {
      monitor->owner()->print_value();
      tty->print("(" INTPTR_FORMAT ")", (address)monitor->owner());
    }
    if (monitor->eliminated() && is_compiled_frame())
      tty->print(" ( lock is eliminated )");
    tty->cr();
    tty->print("\t  ");
    monitor->lock()->print_on(tty);
    tty->cr();
  }
}
Exemplo n.º 8
0
bool javaVFrame::structural_compare(javaVFrame* other) {
  // Check static part
  if (method() != other->method()) return false;
  if (bci()    != other->bci())    return false;

  // Check locals
  StackValueCollection *locs = locals();
  StackValueCollection *other_locs = other->locals();
  assert(locs->size() == other_locs->size(), "sanity check");
  int i;
  for(i = 0; i < locs->size(); i++) {
    // it might happen the compiler reports a conflict and
    // the interpreter reports a bogus int.
    if (       is_compiled_frame() &&       locs->at(i)->type() == T_CONFLICT) continue;
    if (other->is_compiled_frame() && other_locs->at(i)->type() == T_CONFLICT) continue;

    if (!locs->at(i)->equal(other_locs->at(i)))
      return false;
  }

  // Check expressions
  StackValueCollection* exprs = expressions();
  StackValueCollection* other_exprs = other->expressions();
  assert(exprs->size() == other_exprs->size(), "sanity check");
  for(i = 0; i < exprs->size(); i++) {
    if (!exprs->at(i)->equal(other_exprs->at(i)))
      return false;
  }

  return true;
}
Exemplo n.º 9
0
void Parser::blockContents(MethodGenerationContext* mgenc, bool is_inlined) {
    if (accept(Or)) {
        locals(mgenc);
        expect(Or);
    }
    blockBody(mgenc, false, is_inlined);
}
Exemplo n.º 10
0
expr dsimplify_core_fn::visit_let(expr const & e) {
    if (m_cfg.m_zeta) {
        return visit(instantiate(let_body(e), let_value(e)));
    } else {
        type_context::tmp_locals locals(m_ctx);
        expr b = e;
        bool modified = false;
        while (is_let(b)) {
            expr t     = instantiate_rev(let_type(b), locals.size(), locals.data());
            expr v     = instantiate_rev(let_value(b), locals.size(), locals.data());
            expr new_t = visit(t);
            expr new_v = visit(v);
            if (!is_eqp(t, new_t) || !is_eqp(v, new_v)) modified = true;
            locals.push_let(let_name(b), new_t, new_v);
            b = let_body(b);
        }
        b = instantiate_rev(b, locals.size(), locals.data());
        expr new_b = visit(b);
        if (!is_eqp(b, new_b)) modified = true;
        if (modified)
            return locals.mk_lambda(new_b);
        else
            return e;
    }
}
Exemplo n.º 11
0
/* Store parameter info for fn in \c pinfos and return the dependencies of the resulting type
   (if compute_resulting_deps == true). */
static list<unsigned> get_core(type_context & ctx,
                               expr const & fn, buffer<param_info> & pinfos,
                               unsigned max_args, bool compute_resulting_deps) {
    expr type = ctx.relaxed_try_to_pi(ctx.infer(fn));
    type_context::tmp_locals locals(ctx);
    unsigned i = 0;
    while (is_pi(type)) {
        if (i == max_args)
            break;
        expr local      = locals.push_local_from_binding(type);
        expr local_type = ctx.infer(local);
        expr new_type   = ctx.relaxed_try_to_pi(instantiate(binding_body(type), local));
        bool is_prop    = ctx.is_prop(local_type);
        bool is_dep     = !closed(binding_body(type));
        pinfos.emplace_back(binding_info(type).is_implicit(),
                            binding_info(type).is_inst_implicit(),
                            is_prop, is_dep, collect_deps(local_type, locals.as_buffer()));
        type = new_type;
        i++;
    }
    if (compute_resulting_deps)
        return collect_deps(type, locals.as_buffer());
    else
        return list<unsigned>();
}
Exemplo n.º 12
0
 Object* Thread::locals_has_key(STATE, Symbol* key) {
   /*
    * If we're not trying to set values on the current thread,
    * we will set thread locals anyway and not use fiber locals.
    */
   if(state->vm() != vm()) {
     return locals()->has_key(state, key);
   }
   Fiber* fib = state->vm()->current_fiber.get();
   if(fib->nil_p() || fib->root_p()) {
     return locals()->has_key(state, key);
   }
   if(try_as<LookupTable>(fib->locals())) {
     return fib->locals()->has_key(state, key);
   }
   return cFalse;
 }
Exemplo n.º 13
0
 Object* Thread::locals_store(STATE, Symbol* key, Object* value) {
   /*
    * If we're not trying to set values on the current thread,
    * we will set thread locals anyway and not use fiber locals.
    */
   if(state->vm() != vm()) {
     return locals()->store(state, key, value);
   }
   Fiber* fib = state->vm()->current_fiber.get();
   if(fib->nil_p() || fib->root_p()) {
     return locals()->store(state, key, value);
   }
   if(fib->locals()->nil_p()) {
     fib->locals(state, LookupTable::create(state));
   }
   return fib->locals()->store(state, key, value);
 }
Exemplo n.º 14
0
bool vframeOopClass::equal(vframeOop v) {
  bool eq =
        method()     == v->method()
    &&  locals()     == v->locals()
    &&  descOffset() == v->descOffset();
  assert(!eq  ||  process() == v->process(), "should be the same");
  return eq;
}
Exemplo n.º 15
0
void FrameState::updateLocalRefValue(uint32_t id, unsigned inlineIdx,
                                     SSATmp* oldRef, SSATmp* newRef) {
  auto& local = locals(inlineIdx)[id];
  assert(local.value == oldRef);
  local.value = newRef;
  local.type  = newRef->type();
  local.typeSource = newRef;
}
Exemplo n.º 16
0
 Array* Thread::locals_keys(STATE) {
   /*
    * If we're not trying to set values on the current thread,
    * we will set thread locals anyway and not use fiber locals.
    */
   if(state->vm() != vm()) {
     return locals()->all_keys(state);
   }
   Fiber* fib = state->vm()->current_fiber.get();
   if(fib->nil_p() || fib->root_p()) {
     return locals()->all_keys(state);
   }
   if(try_as<LookupTable>(fib->locals())) {
     return fib->locals()->all_keys(state);
   }
   return Array::create(state, 0);
 }
Exemplo n.º 17
0
void BytecodeTranslatorVisitor::visitForNode(ForNode* node) {
    onVisitNode(node);

    const AstVar* i = node->var();
    if (i->type() != VT_INT)
        ERROR("Non-iterable type in for loop");

    const BinaryOpNode* expr = node->inExpr()->asBinaryOpNode();
    if (expr == NULL || expr->kind() != tRANGE)
        ERROR("Invalid range in for loop");

    CONTEXT(function(), locals(), node->body()->scope(), typeStack());

    beforeProcessBlock();

    bool needTempVar = !expr->right()->isIntLiteralNode();
    AstVar* temp = NULL;
    if (needTempVar) {
        if (!scope()->declareVariable("<tempForEnd>", VT_INT))
            ERROR("internal error: temp name is unavailable");
        temp = scope()->lookupVariable("<tempForEnd>", false);
    }

    Label L_Begin(bytecode());
    Label L_End(bytecode());

    VISIT(expr->left());
    EMIT_STORE(i);

    if (needTempVar) {
        VISIT(expr->right());
        EMIT_STORE(temp);
        popType(VT_INT);
    }

    popType(VT_INT);
    EMIT_BIND(L_Begin);
    if (needTempVar)
        EMIT_LOAD(temp);
    else
        VISIT(expr->right());
    EMIT_LOAD(i);
    EMIT_BRANCH(BC_IFICMPG, L_End);

    processBlockNode(node->body());
    afterProcessBlock();

    /* i += 1 */
    EMIT_LOAD(i);
    EMIT(BC_ILOAD1);
    EMIT(BC_IADD);
    EMIT_STORE(i);

    EMIT_BRANCH(BC_JA, L_Begin);
    EMIT_BIND(L_End);

    pushType(VT_VOID);
}
Exemplo n.º 18
0
void FrameState::refineLocalValue(uint32_t id, unsigned inlineIdx,
                                  SSATmp* oldVal, SSATmp* newVal) {
  auto& locs = locals(inlineIdx);
  always_assert(id < locs.size());
  auto& local = locs[id];
  local.value = newVal;
  local.type = newVal->type();
  local.typeSource = newVal;
}
Exemplo n.º 19
0
expr get_ind_result_type(type_context_old & tctx, expr const & ind) {
    expr ind_type = tctx.relaxed_whnf(tctx.infer(ind));
    type_context_old::tmp_locals locals(tctx);
    while (is_pi(ind_type)) {
        ind_type = instantiate(binding_body(ind_type), locals.push_local_from_binding(ind_type));
        ind_type = tctx.relaxed_whnf(ind_type);
    }
    lean_assert(is_sort(ind_type));
    return ind_type;
}
Exemplo n.º 20
0
    void program::print_assembler() const
    {
        auto pc = code.begin();

        std::vector<std::string> locals(variables.size());
        typedef std::pair<std::string, int> pair;
        for (pair const& p : variables)
        {
            locals[p.second] = p.first;
            std::cout << "local       "
                << p.first << ", @" << p.second << std::endl;
        }

        while (pc != code.end())
        {
            switch (*pc++)
            {
                case op_neg:
                    std::cout << "op_neg" << std::endl;
                    break;

                case op_add:
                    std::cout << "op_add" << std::endl;
                    break;

                case op_sub:
                    std::cout << "op_sub" << std::endl;
                    break;

                case op_mul:
                    std::cout << "op_mul" << std::endl;
                    break;

                case op_div:
                    std::cout << "op_div" << std::endl;
                    break;

                case op_load:
                    std::cout << "op_load     " << locals[*pc++] << std::endl;
                    break;

                case op_store:
                    std::cout << "op_store    " << locals[*pc++] << std::endl;
                    break;

                case op_int:
                    std::cout << "op_int      " << *pc++ << std::endl;
                    break;

                case op_stk_adj:
                    std::cout << "op_stk_adj  " << *pc++ << std::endl;
                    break;
            }
        }
    }
Exemplo n.º 21
0
void BytecodeTranslatorVisitor::visitBlockNode(BlockNode* node) {
    onVisitNode(node);

    CONTEXT(function(), locals(), node->scope(), typeStack());

    beforeProcessBlock();
    processBlockNode(node);
    afterProcessBlock();

    pushType(VT_VOID);
}
Exemplo n.º 22
0
    void function::print_assembler() const
    {
        std::vector<int>::const_iterator pc = code.begin() + address;

        std::vector<std::string> locals(variables.size());
        typedef std::pair<std::string, int> pair;
        BOOST_FOREACH(pair const& p, variables)
        {
            locals[p.second] = p.first;
            std::cout << "      local       "
                << p.first << ", @" << p.second << std::endl;
        }
Exemplo n.º 23
0
  void VariableScope::flush_to_heap_internal(STATE) {
    if(isolated()) return;

    Tuple* new_locals = Tuple::create(state, number_of_locals());

    for(int i = 0; i < number_of_locals(); i++) {
      new_locals->put(state, i, locals()[i]);
    }

    heap_locals(state, new_locals);
    isolated(1);
  }
Exemplo n.º 24
0
optional<name> defeq_canonizer::get_head_symbol(expr type) {
    type    = m_ctx.whnf(type);
    expr const & fn = get_app_fn(type);
    if (is_constant(fn)) {
        return optional<name>(const_name(fn));
    } else if (is_pi(type)) {
        type_context::tmp_locals locals(m_ctx);
        expr l = locals.push_local_from_binding(type);
        return get_head_symbol(instantiate(binding_body(type), l));
    } else {
        return optional<name>();
    }
}
Exemplo n.º 25
0
 /* Return new minor premise and a flag indicating whether the body is unreachable or not */
 pair<expr, bool> visit_minor_premise(expr e, buffer<bool> const & rel_fields) {
     type_context::tmp_locals locals(ctx());
     for (unsigned i = 0; i < rel_fields.size(); i++) {
         lean_assert(is_lambda(e));
         if (rel_fields[i]) {
             expr l = locals.push_local_from_binding(e);
             e = instantiate(binding_body(e), l);
         } else {
             e = instantiate(binding_body(e), mk_neutral_expr());
         }
     }
     e = visit(e);
     bool unreachable = is_unreachable_expr(e);
     return mk_pair(locals.mk_lambda(e), unreachable);
 }
Exemplo n.º 26
0
int vframeArrayElement::on_stack_size(int callee_parameters,
                                      int callee_locals,
                                      bool is_top_frame,
                                      int popframe_extra_stack_expression_els) const {
  assert(method()->max_locals() == locals()->size(), "just checking");
  int locks = monitors() == NULL ? 0 : monitors()->number_of_monitors();
  int temps = expressions()->size();
  return Interpreter::size_activation(method()->max_stack(),
                                      temps + callee_parameters,
                                      popframe_extra_stack_expression_els,
                                      locks,
                                      callee_parameters,
                                      callee_locals,
                                      is_top_frame);
}
Exemplo n.º 27
0
    void handleFrameExit() {
        if (hasExited())
            return;

        // Call the getters for their side-effects of caching the result:
        back(this, NULL);
        code(this, NULL);
        globals(this, NULL);
        assert(!_locals);
        _locals = incref(locals(this, NULL));
        ASSERT(frame_info->stmt->lineno > 0 && frame_info->stmt->lineno < 1000000, "%d", frame_info->stmt->lineno);
        _linenumber = frame_info->stmt->lineno;

        frame_info = NULL; // this means exited == true
        assert(hasExited());
    }
Exemplo n.º 28
0
void javaVFrame::print_lock_info(int frame_count) {        
  ResourceMark rm;

  // If this is the first frame, and java.lang.Object.wait(...) then print out the receiver.
  if (frame_count == 0 && method()->name() == vmSymbols::wait_name() && 
      instanceKlass::cast(method()->method_holder())->name() == vmSymbols::java_lang_Object()) {
    StackValueCollection* locs = locals();      
    if (!locs->is_empty()) {
      StackValue* sv = locs->at(0);
      if (sv->type() == T_OBJECT) {
        Handle o = locs->at(0)->get_obj();    
        if (o.not_null()) {
          instanceKlass* ik = instanceKlass::cast(o->klass());
          tty->print_cr("\t- waiting on <" INTPTR_FORMAT "> (a %s)", o(), ik->external_name());
        }
      }
    }        
  }    
  
  // Print out all monitors that we have locked or are trying to lock
  GrowableArray<MonitorInfo*>* mons = monitors();
  if (!mons->is_empty()) {
    bool found_first_monitor = false;
    for (int index = (mons->length()-1); index >= 0; index--) {
      MonitorInfo* monitor = mons->at(index);
      if (monitor->owner() != NULL) {
        //
        // First, assume we have the monitor locked. If we haven't found an
        // owned monitor before and this is the first frame, then we need to
        // see if the thread is blocked.
        //
        const char *lock_state = "locked"; // assume we have the monitor locked
        if (!found_first_monitor && frame_count == 0) {
          switch (thread()->thread_state()) {
          case _thread_blocked:
          case _thread_blocked_trans:
            lock_state = "waiting to lock";
            break;
          }
        }
        found_first_monitor = true;
        instanceKlass* ik = instanceKlass::cast(monitor->owner()->klass());
        tty->print_cr("\t- %s <" INTPTR_FORMAT "> (a %s)", lock_state, monitor->owner(), ik->external_name());
      }
    }  
  }
}
Exemplo n.º 29
0
void Gdb::parse(const QByteArray& inputs)
{
	foreach(const QByteArray& input, inputs.split('\n')) {
		qWarning() << "line" << input;
		if(input.startsWith("~")) { if(m_responder) { m_responder->writeDebugState(cString(input.data(), 1)); } }
		else if(input.startsWith("^error")) { if(m_responder) { m_responder->writeStderr(cString(input.data(), after(input.data(), "msg="))); } }
		else if(input.startsWith("^done,stack=")) stack(input.data());
		else if(input.startsWith("^done,stack-args=")) stackArgs(input.data());
		else if(input.startsWith("^done,locals=")) locals(input.data());
		else if(input.startsWith("^done,BreakpointTable=")) breakpointTable(input.data());
		else if(input.startsWith("^done,bkpt="));
		else if(input.startsWith("^done")) { if(m_responder) { m_responder->writeDebugState(cString(input.data(), after(input.data(), "reason="))); } }
		else if(input.startsWith("*stopped")) stopped(input.data());
		else if(input.startsWith("=shlibs-added")) m_libs += shlibsAdded(input.data());
	}
	if(m_responder) m_responder->update();
}
Exemplo n.º 30
0
    /* If type of d is a proposition or return a type, we don't need to compile it.
       We can just generate (fun args, neutral_expr)

       This procedure returns true if type of d is a proposition or return a type,
       and store the dummy code above in */
    bool compile_irrelevant(declaration const & d, buffer<procedure> & procs) {
        type_context ctx(m_env, transparency_mode::All);
        expr type = d.get_type();
        type_context::tmp_locals locals(ctx);
        while (true) {
            type = ctx.relaxed_whnf(type);
            if (!is_pi(type))
                break;
            expr local = locals.push_local_from_binding(type);
            type       = instantiate(binding_body(type), local);
        }
        if (ctx.is_prop(type) || is_sort(type)) {
            expr r = locals.mk_lambda(mk_neutral_expr());
            procs.emplace_back(d.get_name(), optional<pos_info>(), r);
            return true;
        } else {
            return false;
        }
    }