Esempio n. 1
0
MethodLivenessResult MethodLiveness::BasicBlock::get_liveness_at(ciMethod* method, int bci) {
  MethodLivenessResult answer(NEW_RESOURCE_ARRAY(uintptr_t, _analyzer->bit_map_size_words()),
                _analyzer->bit_map_size_bits());
  answer.set_is_valid();

#ifndef ASSERT
  if (bci == start_bci()) {
    answer.set_from(_entry);
    return answer;
  }
#endif

#ifdef ASSERT
  ResourceMark rm;
  BitMap g(_gen.size()); g.set_from(_gen);
  BitMap k(_kill.size()); k.set_from(_kill);
#endif
  if (_last_bci != bci || trueInDebug) {
    ciBytecodeStream bytes(method);
    bytes.reset_to_bci(bci);
    bytes.set_max_bci(limit_bci());
    compute_gen_kill_range(&bytes);
    assert(_last_bci != bci ||
           (g.is_same(_gen) && k.is_same(_kill)), "cached computation is incorrect");
    _last_bci = bci;
  }

  answer.clear();
  answer.set_union(_normal_exit);
  answer.set_difference(_kill);
  answer.set_union(_gen);
  answer.set_union(_exception_exit);

#ifdef ASSERT
  if (bci == start_bci()) {
    assert(answer.is_same(_entry), "optimized answer must be accurate");
  }
#endif

  return answer;
}
Esempio n. 2
0
OopMap::OopMap(OopMap::DeepCopyToken, OopMap* source) {
  // This constructor does a deep copy
  // of the source OopMap.
  set_write_stream(new CompressedWriteStream(source->omv_count() * 2));
  set_omv_data(NULL);
  set_omv_count(0);
  set_offset(source->offset());

#ifdef ASSERT
  _locs_length = source->_locs_length;
  _locs_used = NEW_RESOURCE_ARRAY(OopMapValue::oop_types, _locs_length);
  for(int i = 0; i < _locs_length; i++) _locs_used[i] = OopMapValue::unused_value;
#endif

  // We need to copy the entries too.
  for (OopMapStream oms(source); !oms.is_done(); oms.next()) {
    OopMapValue omv = oms.current();
    omv.write_on(write_stream());
    increment_count();
  }
}
void CodeSection::expand_locs(int new_capacity) {
  if (_locs_start == NULL) {
    initialize_locs(new_capacity);
    return;
  } else {
    int old_count    = locs_count();
    int old_capacity = locs_capacity();
    if (new_capacity < old_capacity * 2)
      new_capacity = old_capacity * 2;
    relocInfo* locs_start;
    if (_locs_own) {
      locs_start = REALLOC_RESOURCE_ARRAY(relocInfo, _locs_start, old_capacity, new_capacity);
    } else {
      locs_start = NEW_RESOURCE_ARRAY(relocInfo, new_capacity);
      Copy::conjoint_jbytes(_locs_start, locs_start, old_capacity * sizeof(relocInfo));
      _locs_own = true;
    }
    _locs_start    = locs_start;
    _locs_end      = locs_start + old_count;
    _locs_limit    = locs_start + new_capacity;
  }
}
Esempio n. 4
0
void OopNCode::gc_mark_contents() {
  ResourceMark m;
  addrDesc* p = locs(), *end = locsEnd();
  LocChange* changes = NEW_RESOURCE_ARRAY( LocChange, end - p);
  int32 locLen = 0;
  for (; p < end; p++) {
    if (!p->isOop()) {
      // no oops here
    } else {
      oop oldOop = (oop)p->referent(this);
      oop newOop = oldOop;
      MARK_TEMPLATE(&newOop);
      if (newOop != oldOop) {
        changes[locLen].p = p;
        changes[locLen].newOop = newOop;
        locLen++;
      }
    }
  }
  for (LocChange* l = &changes[0]; locLen > 0; locLen--, l++) {
    l->p->set_referent(this, (char*)l->newOop);
  }
}
void BytecodePrinter::print_attributes(int bci, outputStream* st) {
  // Show attributes of pre-rewritten codes
  Bytecodes::Code code = Bytecodes::java_code(raw_code());
  // If the code doesn't have any fields there's nothing to print.
  // note this is ==1 because the tableswitch and lookupswitch are
  // zero size (for some reason) and we want to print stuff out for them.
  if (Bytecodes::length_for(code) == 1) {
    st->cr();
    return;
  }

  switch(code) {
    // Java specific bytecodes only matter.
    case Bytecodes::_bipush:
      st->print_cr(" " INT32_FORMAT, get_byte());
      break;
    case Bytecodes::_sipush:
      st->print_cr(" " INT32_FORMAT, get_short());
      break;
    case Bytecodes::_ldc:
      if (Bytecodes::uses_cp_cache(raw_code())) {
        print_constant(get_index_u1_cpcache(), st);
      } else {
        print_constant(get_index_u1(), st);
      }
      break;

    case Bytecodes::_ldc_w:
    case Bytecodes::_ldc2_w:
      if (Bytecodes::uses_cp_cache(raw_code())) {
        print_constant(get_index_u2_cpcache(), st);
      } else {
        print_constant(get_index_u2(), st);
      }
      break;

    case Bytecodes::_iload:
    case Bytecodes::_lload:
    case Bytecodes::_fload:
    case Bytecodes::_dload:
    case Bytecodes::_aload:
    case Bytecodes::_istore:
    case Bytecodes::_lstore:
    case Bytecodes::_fstore:
    case Bytecodes::_dstore:
    case Bytecodes::_astore:
      st->print_cr(" #%d", get_index_special());
      break;

    case Bytecodes::_iinc:
      { int index = get_index_special();
        jint offset = is_wide() ? get_short(): get_byte();
        st->print_cr(" #%d " INT32_FORMAT, index, offset);
      }
      break;

    case Bytecodes::_newarray: {
        BasicType atype = (BasicType)get_index_u1();
        const char* str = type2name(atype);
        if (str == NULL || atype == T_OBJECT || atype == T_ARRAY) {
          assert(false, "Unidentified basic type");
        }
        st->print_cr(" %s", str);
      }
      break;
    case Bytecodes::_anewarray: {
        int klass_index = get_index_u2();
        ConstantPool* constants = method()->constants();
        Symbol* name = constants->klass_name_at(klass_index);
        st->print_cr(" %s ", name->as_C_string());
      }
      break;
    case Bytecodes::_multianewarray: {
        int klass_index = get_index_u2();
        int nof_dims = get_index_u1();
        ConstantPool* constants = method()->constants();
        Symbol* name = constants->klass_name_at(klass_index);
        st->print_cr(" %s %d", name->as_C_string(), nof_dims);
      }
      break;

    case Bytecodes::_ifeq:
    case Bytecodes::_ifnull:
    case Bytecodes::_iflt:
    case Bytecodes::_ifle:
    case Bytecodes::_ifne:
    case Bytecodes::_ifnonnull:
    case Bytecodes::_ifgt:
    case Bytecodes::_ifge:
    case Bytecodes::_if_icmpeq:
    case Bytecodes::_if_icmpne:
    case Bytecodes::_if_icmplt:
    case Bytecodes::_if_icmpgt:
    case Bytecodes::_if_icmple:
    case Bytecodes::_if_icmpge:
    case Bytecodes::_if_acmpeq:
    case Bytecodes::_if_acmpne:
    case Bytecodes::_goto:
    case Bytecodes::_jsr:
      st->print_cr(" %d", bci + get_short());
      break;

    case Bytecodes::_goto_w:
    case Bytecodes::_jsr_w:
      st->print_cr(" %d", bci + get_int());
      break;

    case Bytecodes::_ret: st->print_cr(" %d", get_index_special()); break;

    case Bytecodes::_tableswitch:
      { align();
        int  default_dest = bci + get_int();
        int  lo           = get_int();
        int  hi           = get_int();
        int  len          = hi - lo + 1;
        jint* dest        = NEW_RESOURCE_ARRAY(jint, len);
        for (int i = 0; i < len; i++) {
          dest[i] = bci + get_int();
        }
        st->print(" %d " INT32_FORMAT " " INT32_FORMAT " ",
                      default_dest, lo, hi);
        int first = true;
        for (int ll = lo; ll <= hi; ll++, first = false)  {
          int idx = ll - lo;
          const char *format = first ? " %d:" INT32_FORMAT " (delta: %d)" :
                                       ", %d:" INT32_FORMAT " (delta: %d)";
          st->print(format, ll, dest[idx], dest[idx]-bci);
        }
        st->cr();
      }
      break;
    case Bytecodes::_lookupswitch:
      { align();
        int  default_dest = bci + get_int();
        int  len          = get_int();
        jint* key         = NEW_RESOURCE_ARRAY(jint, len);
        jint* dest        = NEW_RESOURCE_ARRAY(jint, len);
        for (int i = 0; i < len; i++) {
          key [i] = get_int();
          dest[i] = bci + get_int();
        };
        st->print(" %d %d ", default_dest, len);
        bool first = true;
        for (int ll = 0; ll < len; ll++, first = false)  {
          const char *format = first ? " " INT32_FORMAT ":" INT32_FORMAT :
                                       ", " INT32_FORMAT ":" INT32_FORMAT ;
          st->print(format, key[ll], dest[ll]);
        }
        st->cr();
      }
      break;

    case Bytecodes::_putstatic:
    case Bytecodes::_getstatic:
    case Bytecodes::_putfield:
    case Bytecodes::_getfield:
      print_field_or_method(get_index_u2_cpcache(), st);
      break;

    case Bytecodes::_invokevirtual:
    case Bytecodes::_invokespecial:
    case Bytecodes::_invokestatic:
      print_field_or_method(get_index_u2_cpcache(), st);
      break;

    case Bytecodes::_invokeinterface:
      { int i = get_index_u2_cpcache();
        int n = get_index_u1();
        get_byte();            // ignore zero byte
        print_field_or_method(i, st);
      }
      break;

    case Bytecodes::_invokedynamic:
      print_field_or_method(get_index_u4(), st);
      break;

    case Bytecodes::_new:
    case Bytecodes::_checkcast:
    case Bytecodes::_instanceof:
      { int i = get_index_u2();
        ConstantPool* constants = method()->constants();
        Symbol* name = constants->klass_name_at(i);
        st->print_cr(" %d <%s>", i, name->as_C_string());
      }
      break;

    case Bytecodes::_wide:
      // length is zero not one, but printed with no more info.
      break;

    default:
      ShouldNotReachHere();
      break;
  }
}
Esempio n. 6
0
//------------------------------Dominator--------------------------------------
// Compute the dominator tree of the CFG.  The CFG must already have been 
// constructed.  This is the Lengauer & Tarjan O(E-alpha(E,V)) algorithm.
void PhaseCFG::Dominators( ) {
  // Pre-grow the blocks array, prior to the ResourceMark kicking in
  _blocks.map(_num_blocks,0);

  ResourceMark rm;
  // Setup mappings from my Graph to Tarjan's stuff and back 
  // Note: Tarjan uses 1-based arrays
  Tarjan *tarjan = NEW_RESOURCE_ARRAY(Tarjan,_num_blocks+1);

  // Tarjan's algorithm, almost verbatim: 
  // Step 1: 
  _rpo_ctr = _num_blocks;
  uint dfsnum = DFS( tarjan );
  if( dfsnum-1 != _num_blocks ) {// Check for unreachable loops!
    // If the returned dfsnum does not match the number of blocks, then we
    // must have some unreachable loops.  These can be made at any time by
    // IterGVN.  They are cleaned up by CCP or the loop opts, but the last
    // IterGVN can always make more that are not cleaned up.  Highly unlikely
    // except in ZKM.jar, where endless irreducible loops cause the loop opts
    // to not get run.
    //
    // Having found unreachable loops, we have made a bad RPO _block layout.
    // We can re-run the above DFS pass with the correct number of blocks,
    // and hack the Tarjan algorithm below to be robust in the presence of
    // such dead loops (as was done for the NTarjan code farther below).
    // Since this situation is so unlikely, instead I've decided to bail out.
    // CNC 7/24/2001
    C->record_method_not_compilable("unreachable loop");
    return;
  }
  _blocks._cnt = _num_blocks;

  // Tarjan is using 1-based arrays, so these are some initialize flags
  tarjan[0]._size = tarjan[0]._semi = 0;
  tarjan[0]._label = &tarjan[0];
  
  uint i;
  for( i=_num_blocks; i>=2; i-- ) { // For all vertices in DFS order 
    Tarjan *w = &tarjan[i];     // Get vertex from DFS 

    // Step 2: 
    Node *whead = w->_block->head();
    for( uint j=1; j < whead->req(); j++ ) {
      Block *b = _bbs[whead->in(j)->_idx];
      Tarjan *vx = &tarjan[b->_pre_order];
      Tarjan *u = vx->EVAL();
      if( u->_semi < w->_semi )
        w->_semi = u->_semi;
    } 

    // w is added to a bucket here, and only here.
    // Thus w is in at most one bucket and the sum of all bucket sizes is O(n).
    // Thus bucket can be a linked list.
    // Thus we do not need a small integer name for each Block.
    w->_bucket = tarjan[w->_semi]._bucket;
    tarjan[w->_semi]._bucket = w;

    w->_parent->LINK( w, &tarjan[0] );

    // Step 3: 
    for( Tarjan *vx = w->_parent->_bucket; vx; vx = vx->_bucket ) {
      Tarjan *u = vx->EVAL();
      vx->_dom = (u->_semi < vx->_semi) ? u : w->_parent;
    }
  }

  // Step 4: 
  for( i=2; i <= _num_blocks; i++ ) {
    Tarjan *w = &tarjan[i];
    if( w->_dom != &tarjan[w->_semi] )
      w->_dom = w->_dom->_dom;
    w->_dom_next = w->_dom_child = NULL;  // Initialize for building tree later
  }
  // No immediate dominator for the root
  Tarjan *w = &tarjan[_broot->_pre_order];
  w->_dom = NULL;       
  w->_dom_next = w->_dom_child = NULL;  // Initialize for building tree later

  // Convert the dominator tree array into my kind of graph 
  for( i=1; i<=_num_blocks;i++){// For all Tarjan vertices
    Tarjan *t = &tarjan[i];     // Handy access
    Tarjan *tdom = t->_dom;     // Handy access to immediate dominator 
    if( tdom )  {               // Root has no immediate dominator
      t->_block->_idom = tdom->_block; // Set immediate dominator
      t->_dom_next = tdom->_dom_child; // Make me a sibling of parent's child
      tdom->_dom_child = t;     // Make me a child of my parent
    } else
      t->_block->_idom = NULL;  // Root
  }
  w->setdepth( _num_blocks+1 ); // Set depth in dominator tree

}
Esempio n. 7
0
 Block_Stack(Tarjan *tarjan, int size) : _tarjan(tarjan) {
   _stack = NEW_RESOURCE_ARRAY(Block_Descr, size);
   _stack_max = _stack + size;
   _stack_top = _stack - 1; // stack is empty
 }
// --- oops_arguments_do_impl ------------------------------------------------
void CodeBlob::oops_arguments_do_impl(frame fr, OopClosure* f) const {
  ResourceMark rm;
  // We are in some trampoline (resolve_and_patch_call) doing a GC.  The
  // pending call has arguments that need GC'ing, but we do not yet know the
  // target method and cannot resolve the target method yet.
  frame cc = fr.sender();       // Compiled caller expected
symbolOop meth_sig;
  bool is_static;
  if( cc.is_entry_frame() ) {
    // There's a rare race condition where the caller is an entry frame, but
    // the target got patched not-entrant before the call could be made.
    methodOop moop = cc.entry_frame_call_wrapper()->callee_method();
    meth_sig = moop->signature();
    is_static = moop->is_static();

  } else {
Bytecode_invoke*call;
if(cc.is_interpreted_frame()){
      // There's a rare race condition where we might need to GC in
      // resolve_and_patch_call but the caller is an interpreted frame.
      call = Bytecode_invoke_at(cc.interpreter_frame_method(),
                                cc.interpreter_frame_bci());
    } else {
      // Normal case: find caller's callsite
CodeBlob*cb=CodeCache::find_blob(cc.pc());
      const DebugScope *ds = cb->debuginfo(cc.pc());
      call = Bytecode_invoke_at(ds->method(), ds->bci());
    }
    meth_sig = call->signature();
    is_static = (call->adjusted_invoke_code() == Bytecodes::_invokestatic);
  }

  int argcnt = 0;               // Size of signature
  if( !is_static ) argcnt++;    // Add receiver
for(SignatureStream ss(meth_sig);!ss.at_return_type();ss.next()){
    argcnt++;
    if (ss.type() == T_LONG || ss.type() == T_DOUBLE) argcnt++;
  }

  BasicType * sig_bt = NEW_RESOURCE_ARRAY(BasicType  ,argcnt);
  VReg::VR * regs = NEW_RESOURCE_ARRAY(VReg::VR,argcnt);
  int i=0;
  if( !is_static ) sig_bt[i++] = T_OBJECT;
for(SignatureStream ss(meth_sig);!ss.at_return_type();ss.next()){
    sig_bt[i++] = ss.type();	// Collect remaining bits of signature
    if (ss.type() == T_LONG || ss.type() == T_DOUBLE)
      sig_bt[i++] = T_VOID;	// Longs & doubles take 2 Java slots
  }
  assert0(i==argcnt);

  // Now get the re-packed compiled-Java layout.  Registers are numbered from
  // the callee's point of view.
  SharedRuntime::java_calling_convention(sig_bt,regs,argcnt,true);

  // Find the oop locations and do the GC thing
for(int i=0;i<argcnt;i++){
    if ((sig_bt[i] == T_OBJECT) || (sig_bt[i] == T_ARRAY)) {
      objectRef *loc = cc.reg_to_addr_oop(VReg::as_VOopReg(regs[i]));
f->do_oop(loc);
    }
  }
}
Esempio n. 9
0
void PhaseLive::compute(uint maxlrg) {
  _maxlrg   = maxlrg;
  _worklist = new (_arena) Block_List();

  // Init the sparse live arrays.  This data is live on exit from here!
  // The _live info is the live-out info.
  _live = (IndexSet*)_arena->Amalloc(sizeof(IndexSet)*_cfg._num_blocks);
  uint i;
  for( i=0; i<_cfg._num_blocks; i++ ) {
    _live[i].initialize(_maxlrg);
  }

  // Init the sparse arrays for delta-sets.  
  ResourceMark rm;              // Nuke temp storage on exit

  // Does the memory used by _defs and _deltas get reclaimed?  Does it matter?  TT

  // Array of values defined locally in blocks
  _defs = NEW_RESOURCE_ARRAY(IndexSet,_cfg._num_blocks);
  for( i=0; i<_cfg._num_blocks; i++ ) {
    _defs[i].initialize(_maxlrg);
  }

  // Array of delta-set pointers, indexed by block pre_order-1.
  _deltas = NEW_RESOURCE_ARRAY(IndexSet*,_cfg._num_blocks);
  memset( _deltas, 0, sizeof(IndexSet*)* _cfg._num_blocks);

  _free_IndexSet = NULL;

  // Blocks having done pass-1
  VectorSet first_pass(Thread::current()->resource_area());

  // Outer loop: must compute local live-in sets and push into predecessors.
  uint iters = _cfg._num_blocks;        // stat counters
  for( uint j=_cfg._num_blocks; j>0; j-- ) {
    Block *b = _cfg._blocks[j-1];

    // Compute the local live-in set.  Start with any new live-out bits.
    IndexSet *use = getset( b );
    IndexSet *def = &_defs[b->_pre_order-1];
    uint i;
    for( i=b->_nodes.size(); i>1; i-- ) {
      Node *n = b->_nodes[i-1];
      if( n->is_Phi() ) break;
      // BoxNodes keep their input alive as long as their uses.  If we
      // see a BoxNode then make its input live to the Root block.
      // Because we are solving LIVEness, the input now becomes live
      // over the whole procedure, interferencing with everything else
      // and getting a private unshared stack slot.  YeeeHaw!
      MachNode *mach = n->is_Mach();
      if( mach && mach->ideal_Opcode() == Op_Box ) 
        getset(_cfg._broot)->insert( _names[n->in(1)->_idx] );

      uint r = _names[n->_idx];
      def->insert( r );
      use->remove( r );
      uint cnt = n->req();
      for( uint k=1; k<cnt; k++ ) {
        Node *nk = n->in(k);
        uint nkidx = nk->_idx;
        if( _cfg._bbs[nkidx] != b )
          use->insert( _names[nkidx] );
      }
    }
    // Remove anything defined by Phis and the block start instruction
    for( uint k=i; k>0; k-- ) {
      uint r = _names[b->_nodes[k-1]->_idx];
      def->insert( r );
      use->remove( r );
    }

    // Push these live-in things to predecessors
    for( uint l=1; l<b->num_preds(); l++ ) {
      Block *p = _cfg._bbs[b->pred(l)->_idx];
      add_liveout( p, use, first_pass );

      // PhiNode uses go in the live-out set of prior blocks.
      for( uint k=i; k>0; k-- ) 
        add_liveout( p, _names[b->_nodes[k-1]->in(l)->_idx], first_pass );
    }
    freeset( b );
    first_pass.set(b->_pre_order);
    
    // Inner loop: blocks that picked up new live-out values to be propagated
    while( _worklist->size() ) {
        // !!!!!
// #ifdef ASSERT
      iters++;
// #endif
      Block *b = _worklist->pop();
      IndexSet *delta = getset(b);
      assert( delta->count(), "missing delta set" );

      // Add new-live-in to predecessors live-out sets
      for( uint l=1; l<b->num_preds(); l++ ) 
        add_liveout( _cfg._bbs[b->pred(l)->_idx], delta, first_pass );

      freeset(b);
    } // End of while-worklist-not-empty

  } // End of for-all-blocks-outer-loop

  // We explicitly clear all of the IndexSets which we are about to release.
  // This allows us to recycle their internal memory into IndexSet's free list.

  for( i=0; i<_cfg._num_blocks; i++ ) {
    _defs[i].clear();
    if (_deltas[i]) {
      // Is this always true?
      _deltas[i]->clear();
    }
  }
  IndexSet *free = _free_IndexSet;
  while (free != NULL) {
    IndexSet *temp = free;
    free = free->next();
    temp->clear();
  }

}
Esempio n. 10
0
ExceptionHandlerTable::ExceptionHandlerTable(int initial_size) {
  guarantee(initial_size > 0, "initial size must be > 0");
  _table  = NEW_RESOURCE_ARRAY(HandlerTableEntry, initial_size);
  _length = 0;
  _size   = initial_size;
}
Esempio n. 11
0
// ----------------------------------------------------------------------------
// Implicit null exception tables.  Maps an exception PC offset to a
// continuation PC offset.  During construction it's a variable sized
// array with a max size and current length.  When stored inside an
// nmethod a zero length table takes no space.  This is detected by
// nul_chk_table_size() == 0.  Otherwise the table has a length word
// followed by pairs of <excp-offset, const-offset>.
void ImplicitExceptionTable::set_size( uint size ) {
  _size = size;
  _data = NEW_RESOURCE_ARRAY(implicit_null_entry, (size*2));
  _len = 0;
}
Esempio n. 12
0
void PhaseLive::compute(uint maxlrg) {
  _maxlrg   = maxlrg;
  _worklist = new (_arena) Block_List();

  // Init the sparse live arrays.  This data is live on exit from here!
  // The _live info is the live-out info.
  _live = (IndexSet*)_arena->Amalloc(sizeof(IndexSet) * _cfg.number_of_blocks());
  uint i;
  for (i = 0; i < _cfg.number_of_blocks(); i++) {
    _live[i].initialize(_maxlrg);
  }

  if (_keep_deltas) {
    _livein = (IndexSet*)_arena->Amalloc(sizeof(IndexSet) * _cfg.number_of_blocks());
    for (i = 0; i < _cfg.number_of_blocks(); i++) {
      _livein[i].initialize(_maxlrg);
    }
  }

  // Init the sparse arrays for delta-sets.
  ResourceMark rm;              // Nuke temp storage on exit

  // Does the memory used by _defs and _deltas get reclaimed?  Does it matter?  TT

  // Array of values defined locally in blocks
  _defs = NEW_RESOURCE_ARRAY(IndexSet,_cfg.number_of_blocks());
  for (i = 0; i < _cfg.number_of_blocks(); i++) {
    _defs[i].initialize(_maxlrg);
  }

  // Array of delta-set pointers, indexed by block pre_order-1.
  _deltas = NEW_RESOURCE_ARRAY(IndexSet*,_cfg.number_of_blocks());
  memset( _deltas, 0, sizeof(IndexSet*)* _cfg.number_of_blocks());

  _free_IndexSet = NULL;

  // Blocks having done pass-1
  VectorSet first_pass(Thread::current()->resource_area());

  // Outer loop: must compute local live-in sets and push into predecessors.
  for (uint j = _cfg.number_of_blocks(); j > 0; j--) {
    Block* block = _cfg.get_block(j - 1);

    // Compute the local live-in set.  Start with any new live-out bits.
    IndexSet* use = getset(block);
    IndexSet* def = &_defs[block->_pre_order-1];
    DEBUG_ONLY(IndexSet *def_outside = getfreeset();)
    uint i;
    for (i = block->number_of_nodes(); i > 1; i--) {
      Node* n = block->get_node(i-1);
      if (n->is_Phi()) {
        break;
      }

      uint r = _names.at(n->_idx);
      assert(!def_outside->member(r), "Use of external LRG overlaps the same LRG defined in this block");
      def->insert( r );
      use->remove( r );
      uint cnt = n->req();
      for (uint k = 1; k < cnt; k++) {
        Node *nk = n->in(k);
        uint nkidx = nk->_idx;
        if (_cfg.get_block_for_node(nk) != block) {
          uint u = _names.at(nkidx);
          use->insert(u);
          DEBUG_ONLY(def_outside->insert(u);)
        }
      }
    }
Esempio n. 13
0
//------------------------------set_oop----------------------------------------
void PhaseRegAlloc::set_oop( const Node *n, bool is_an_oop ) {
  if( is_an_oop ) {
    _node_oops.set(n->_idx);
  }
}

//------------------------------is_oop-----------------------------------------
bool PhaseRegAlloc::is_oop( const Node *n ) const {
  return _node_oops.test(n->_idx) != 0;
}

// Allocate _node_regs table with at least "size" elements
void PhaseRegAlloc::alloc_node_regs(int size) {
  _node_regs_max_index = size + (size >> 1) + NodeRegsOverflowSize;
  _node_regs = NEW_RESOURCE_ARRAY( OptoRegPair, _node_regs_max_index );
  // We assume our caller will fill in all elements up to size-1, so
  // only the extra space we allocate is initialized here.
  for( uint i = size; i < _node_regs_max_index; ++i )
    _node_regs[i].set_bad();
}

#ifndef PRODUCT
void
PhaseRegAlloc::print_statistics() {
  tty->print_cr("Total frameslots = %d, Max frameslots = %d", _total_framesize, _max_framesize);
  int i;

  for (i=0; i < _num_allocators; i++) {
    _alloc_statistics[i]();
  }
Esempio n. 14
0
int DTraceJSDT::pd_activate(
    void* moduleBaseAddress, jstring module,
    jint providers_count, JVM_DTraceProvider* providers) {

  // We need sections:
  //  (1) STRTAB
  //  (
  //    (2) PROVIDER
  //    (3) PROBES
  //    (4) PROBOFFS
  //    (5) PROBARGS
  //  ) * Number of Providers

  // Type of sections we create
  enum {
    STRTAB = 0,
    PROVIDERS = 1,
    PROBES = 2,
    PROBE_OFFSETS = 3,
    ARG_OFFSETS = 4,
    NUM_SECTIONS = 5
  };

  static int alignment_for[NUM_SECTIONS] = { 1, 4, 8, 4, 1 };

  ResourceMark rm;

  uint32_t num_sections = 1 + 4 * providers_count;
  uint32_t offset = sizeof(dof_hdr_t) + (num_sections * sizeof(dof_sec_t));
  uint32_t* secoffs = NEW_RESOURCE_ARRAY(uint32_t, num_sections);
  uint32_t* secsize = NEW_RESOURCE_ARRAY(uint32_t, num_sections);

  // Store offsets of all strings here in such order:
  //  zero-string (always 0)
  //  provider1-name
  //    probe1-function
  //    probe1-name
  //    arg-1
  //    arg-2
  //    ...
  //    probe2-function
  //    probe2-name
  //    arg-1
  //    arg-2
  //  provider2-name
  //    ...

  uint32_t strcount  = 0;
  // Count the number of strings we'll need
  for(int prvc = 0; prvc < providers_count; ++prvc) {
    JVM_DTraceProvider* provider = &providers[prvc];
    // Provider name
    ++strcount;
    for(int prbc = 0; prbc < provider->probe_count; ++prbc) {
      JVM_DTraceProbe* p = &(provider->probes[prbc]);
      symbolOop sig = JNIHandles::resolve_jmethod_id(p->method)->signature();
      // function + name + one per argument
      strcount += 2 + ArgumentCount(sig).size();
    }
  }

  // Create place for string offsets
  uint32_t* stroffs = NEW_RESOURCE_ARRAY(uint32_t, strcount + 1);
  uint32_t string_index = 0;
  uint32_t curstr = 0;

  // First we need an empty string: ""
  stroffs[curstr++] = string_index;
  string_index += strlen("") + 1;

  for(int prvc = 0; prvc < providers_count; ++prvc) {
    JVM_DTraceProvider* provider = &providers[prvc];
    char* provider_name = java_lang_String::as_utf8_string(
        JNIHandles::resolve_non_null(provider->name));
    stroffs[curstr++] = string_index;
    string_index += strlen(provider_name) + 1;

    // All probes
    for(int prbc = 0; prbc < provider->probe_count; ++prbc) {
      JVM_DTraceProbe* p = &(provider->probes[prbc]);

      char* function = java_lang_String::as_utf8_string(
          JNIHandles::resolve_non_null(p->function));
      stroffs[curstr++] = string_index;
      string_index += strlen(function) + 1;

      char* name = java_lang_String::as_utf8_string(
          JNIHandles::resolve_non_null(p->name));
      stroffs[curstr++] = string_index;
      string_index += strlen(name) + 1;

      symbolOop sig = JNIHandles::resolve_jmethod_id(p->method)->signature();
      SignatureStream ss(sig);
      for ( ; !ss.at_return_type(); ss.next()) {
        BasicType bt = ss.type();
        const char* t = NULL;
        if (bt == T_OBJECT &&
            ss.as_symbol_or_null() == vmSymbols::java_lang_String()) {
          t = string_sig;
        } else if (bt == T_LONG) {
          t = long_sig;
        } else {
          t = int_sig;
        }
        stroffs[curstr++] = string_index;
        string_index += strlen(t) + 1;
      }
    }
  }
  secoffs[STRTAB] = offset;
  secsize[STRTAB] = string_index;
  offset += string_index;

  // Calculate the size of the rest
  for(int prvc = 0; prvc < providers_count; ++prvc) {
    JVM_DTraceProvider* provider = &providers[prvc];
    size_t provider_sec  = PROVIDERS     + prvc * 4;
    size_t probe_sec     = PROBES        + prvc * 4;
    size_t probeoffs_sec = PROBE_OFFSETS + prvc * 4;
    size_t argoffs_sec   = ARG_OFFSETS   + prvc * 4;

    // Allocate space for the provider data struction
    secoffs[provider_sec] = align_size_up(offset, alignment_for[PROVIDERS]);
    secsize[provider_sec] = sizeof(dof_provider_t);
    offset = secoffs[provider_sec] + secsize[provider_sec];

    // Allocate space for all the probes
    secoffs[probe_sec] = align_size_up(offset, alignment_for[PROBES]);
    secsize[probe_sec] = sizeof(dof_probe_t) * provider->probe_count;
    offset = secoffs[probe_sec] + secsize[probe_sec];

    // Allocate space for the probe offsets
    secoffs[probeoffs_sec] = align_size_up(offset, alignment_for[PROBE_OFFSETS]);
    secsize[probeoffs_sec] = sizeof(uint32_t) * provider->probe_count;
    offset = secoffs[probeoffs_sec] + secsize[probeoffs_sec];

    // We need number of arguments argoffs
    uint32_t argscount = 0;
    for(int prbc = 0; prbc < provider->probe_count; ++prbc) {
       JVM_DTraceProbe* p = &(provider->probes[prbc]);
       symbolOop sig = JNIHandles::resolve_jmethod_id(p->method)->signature();
       argscount += ArgumentCount(sig).size();
    }
    secoffs[argoffs_sec] = align_size_up(offset, alignment_for[ARG_OFFSETS]);
    secsize[argoffs_sec] = sizeof(uint8_t) * argscount;
    offset = secoffs[argoffs_sec] + secsize[argoffs_sec];
  }

  uint32_t size = offset;

  uint8_t* dof = NEW_RESOURCE_ARRAY(uint8_t, size);
  if (!dof) {
    return -1;
  }
  memset((void*)dof, 0, size);

  // Fill memory with proper values
  dof_hdr_t* hdr = (dof_hdr_t*)dof;
  hdr->dofh_ident[DOF_ID_MAG0]     = DOF_MAG_MAG0;
  hdr->dofh_ident[DOF_ID_MAG1]     = DOF_MAG_MAG1;
  hdr->dofh_ident[DOF_ID_MAG2]     = DOF_MAG_MAG2;
  hdr->dofh_ident[DOF_ID_MAG3]     = DOF_MAG_MAG3;
  hdr->dofh_ident[DOF_ID_MODEL]    = DOF_MODEL_NATIVE;  // No variants
  hdr->dofh_ident[DOF_ID_ENCODING] = DOF_ENCODE_NATIVE; // No variants
  hdr->dofh_ident[DOF_ID_VERSION]  = DOF_VERSION_1;     // No variants
  hdr->dofh_ident[DOF_ID_DIFVERS]  = DIF_VERSION_2;     // No variants
  // all other fields of ident to zero

  hdr->dofh_flags   = 0;
  hdr->dofh_hdrsize = sizeof(dof_hdr_t);
  hdr->dofh_secsize = sizeof(dof_sec_t);
  hdr->dofh_secnum  = num_sections;
  hdr->dofh_secoff  = sizeof(dof_hdr_t);
  hdr->dofh_loadsz  = size;
  hdr->dofh_filesz  = size;

  // First section: STRTAB
  dof_sec_t* sec = (dof_sec_t*)(dof + sizeof(dof_hdr_t));
  sec->dofs_type    = DOF_SECT_STRTAB;
  sec->dofs_align   = alignment_for[STRTAB];
  sec->dofs_flags   = DOF_SECF_LOAD;
  sec->dofs_entsize = 0;
  sec->dofs_offset  = secoffs[STRTAB];
  sec->dofs_size    = secsize[STRTAB];
  // Make data for this section
  char* str = (char*)(dof + sec->dofs_offset);

  *str = 0; str += 1; // ""

  // Run through all strings again
  for(int prvc = 0; prvc < providers_count; ++prvc) {
    JVM_DTraceProvider* provider = &providers[prvc];
    char* provider_name = java_lang_String::as_utf8_string(
        JNIHandles::resolve_non_null(provider->name));
    strcpy(str, provider_name);
    str += strlen(provider_name) + 1;

    // All probes
    for(int prbc = 0; prbc < provider->probe_count; ++prbc) {
      JVM_DTraceProbe* p = &(provider->probes[prbc]);

      char* function = java_lang_String::as_utf8_string(
          JNIHandles::resolve_non_null(p->function));
      strcpy(str, function);
      str += strlen(str) + 1;

      char* name = java_lang_String::as_utf8_string(
          JNIHandles::resolve_non_null(p->name));
      strcpy(str, name);
      str += strlen(name) + 1;

      symbolOop sig = JNIHandles::resolve_jmethod_id(p->method)->signature();
      SignatureStream ss(sig);
      for ( ; !ss.at_return_type(); ss.next()) {
        BasicType bt = ss.type();
        const char* t;
        if (bt == T_OBJECT &&
            ss.as_symbol_or_null() == vmSymbols::java_lang_String()) {
          t = string_sig;
        } else if (bt == T_LONG) {
          t = long_sig;
        } else {
          t = int_sig;
        }
        strcpy(str, t);
        str += strlen(t) + 1;
      }
    }
  }

  curstr = 1;
  for(int prvc = 0; prvc < providers_count; ++prvc) {
    JVM_DTraceProvider* provider = &providers[prvc];
    size_t provider_sec  = PROVIDERS     + prvc * 4;
    size_t probe_sec     = PROBES        + prvc * 4;
    size_t probeoffs_sec = PROBE_OFFSETS + prvc * 4;
    size_t argoffs_sec   = ARG_OFFSETS   + prvc * 4;

    // PROVIDER ///////////////////////////////////////////////////////////////
    // Section header
    sec = (dof_sec_t*)
        (dof + sizeof(dof_hdr_t) + sizeof(dof_sec_t) * provider_sec);
    sec->dofs_type    = DOF_SECT_PROVIDER;
    sec->dofs_align   = alignment_for[PROVIDERS];
    sec->dofs_flags   = DOF_SECF_LOAD;
    sec->dofs_entsize = 0;
    sec->dofs_offset  = secoffs[provider_sec];
    sec->dofs_size    = secsize[provider_sec];
    // Make provider decriiption
    dof_provider_t* prv = (dof_provider_t*)(dof + sec->dofs_offset);
    prv->dofpv_strtab   = STRTAB;
    prv->dofpv_probes   = probe_sec;
    prv->dofpv_prargs   = argoffs_sec;
    prv->dofpv_proffs   = probeoffs_sec;
    prv->dofpv_name     = stroffs[curstr++]; // Index in string table
    prv->dofpv_provattr = DOF_ATTR(
        provider->providerAttributes.nameStability,
        provider->providerAttributes.dataStability,
        provider->providerAttributes.dependencyClass);
    prv->dofpv_modattr = DOF_ATTR(
        provider->moduleAttributes.nameStability,
        provider->moduleAttributes.dataStability,
        provider->moduleAttributes.dependencyClass);
    prv->dofpv_funcattr = DOF_ATTR(
        provider->functionAttributes.nameStability,
        provider->functionAttributes.dataStability,
        provider->functionAttributes.dependencyClass);
    prv->dofpv_nameattr = DOF_ATTR(
        provider->nameAttributes.nameStability,
        provider->nameAttributes.dataStability,
        provider->nameAttributes.dependencyClass);
    prv->dofpv_argsattr = DOF_ATTR(
        provider->argsAttributes.nameStability,
        provider->argsAttributes.dataStability,
        provider->argsAttributes.dependencyClass);

    // PROBES /////////////////////////////////////////////////////////////////
    // Section header
    sec = (dof_sec_t*)
        (dof + sizeof(dof_hdr_t) + sizeof(dof_sec_t) * probe_sec);
    sec->dofs_type    = DOF_SECT_PROBES;
    sec->dofs_align   = alignment_for[PROBES];
    sec->dofs_flags   = DOF_SECF_LOAD;
    sec->dofs_entsize = sizeof(dof_probe_t);
    sec->dofs_offset  = secoffs[probe_sec];
    sec->dofs_size    = secsize[probe_sec];
    // Make probes descriptions
    uint32_t argsoffs = 0;
    for(int prbc = 0; prbc < provider->probe_count; ++prbc) {
      JVM_DTraceProbe* probe = &(provider->probes[prbc]);
      methodOop m = JNIHandles::resolve_jmethod_id(probe->method);
      int arg_count = ArgumentCount(m->signature()).size();
      assert(m->code() != NULL, "must have an nmethod");

      dof_probe_t* prb =
         (dof_probe_t*)(dof + sec->dofs_offset + prbc * sizeof(dof_probe_t));

      prb->dofpr_addr   = (uint64_t)m->code()->entry_point();
      prb->dofpr_func   = stroffs[curstr++]; // Index in string table
      prb->dofpr_name   = stroffs[curstr++]; // Index in string table
      prb->dofpr_nargv  = stroffs[curstr  ]; // Index in string table
      // We spent siglen strings here
      curstr += arg_count;
      prb->dofpr_xargv  = prb->dofpr_nargv;  // Same bunch of strings
      prb->dofpr_argidx = argsoffs;
      prb->dofpr_offidx = prbc;
      prb->dofpr_nargc  = arg_count;
      prb->dofpr_xargc  = arg_count;
      prb->dofpr_noffs  = 1; // Number of offsets
      // Next bunch of offsets
      argsoffs += arg_count;
    }

    // PROFFS /////////////////////////////////////////////////////////////////
    // Section header
    sec = (dof_sec_t*)
        (dof + sizeof(dof_hdr_t) + sizeof(dof_sec_t) * probeoffs_sec);
    sec->dofs_type    = DOF_SECT_PROFFS;
    sec->dofs_align   = alignment_for[PROBE_OFFSETS];
    sec->dofs_flags   = DOF_SECF_LOAD;
    sec->dofs_entsize = sizeof(uint32_t);
    sec->dofs_offset  = secoffs[probeoffs_sec];
    sec->dofs_size    = secsize[probeoffs_sec];
    // Make offsets
    for (int prbc = 0; prbc < provider->probe_count; ++prbc) {
      uint32_t* pof =
          (uint32_t*)(dof + sec->dofs_offset + sizeof(uint32_t) * prbc);
      JVM_DTraceProbe* probe = &(provider->probes[prbc]);
      methodOop m = JNIHandles::resolve_jmethod_id(probe->method);
      *pof = m->code()->trap_offset();
    }

    // PRARGS /////////////////////////////////////////////////////////////////
    // Section header
    sec = (dof_sec_t*)
        (dof + sizeof(dof_hdr_t) + sizeof(dof_sec_t) * argoffs_sec);
    sec->dofs_type    = DOF_SECT_PRARGS;
    sec->dofs_align   = alignment_for[ARG_OFFSETS];
    sec->dofs_flags   = DOF_SECF_LOAD;
    sec->dofs_entsize = sizeof(uint8_t);
    sec->dofs_offset  = secoffs[argoffs_sec];
    sec->dofs_size    = secsize[argoffs_sec];
    // Make arguments
    uint8_t* par = (uint8_t*)(dof + sec->dofs_offset);
    for (int prbc = 0; prbc < provider->probe_count; ++prbc) {
      JVM_DTraceProbe* p = &(provider->probes[prbc]);
      symbolOop sig = JNIHandles::resolve_jmethod_id(p->method)->signature();
      uint8_t count = (uint8_t)ArgumentCount(sig).size();
      for (uint8_t i = 0; i < count; ++i) {
        *par++ = i;
      }
    }
  }

  // Register module
  return dof_register(module, dof, moduleBaseAddress);
}
//=============================================================================
//------------------------------UnionFind--------------------------------------
UnionFind::UnionFind( uint max ) : _cnt(max), _max(max), _indices(NEW_RESOURCE_ARRAY(uint,max)) {
  Copy::zero_to_bytes( _indices, sizeof(uint)*max );
}