1 #ifdef USE_PRAGMA_IDENT_HDR
   2 #pragma ident "@(#)ciMethodBlocks.hpp   1.5 07/05/05 17:05:14 JVM"
   3 #endif
   4 /*
   5  * Copyright 2006 Sun Microsystems, Inc.  All Rights Reserved.
   6  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   7  *
   8  * This code is free software; you can redistribute it and/or modify it
   9  * under the terms of the GNU General Public License version 2 only, as
  10  * published by the Free Software Foundation.
  11  *
  12  * This code is distributed in the hope that it will be useful, but WITHOUT
  13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  15  * version 2 for more details (a copy is included in the LICENSE file that
  16  * accompanied this code).
  17  *
  18  * You should have received a copy of the GNU General Public License version
  19  * 2 along with this work; if not, write to the Free Software Foundation,
  20  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  21  *
  22  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  23  * CA 95054 USA or visit www.sun.com if you need additional information or
  24  * have any questions.
  25  *  
  26  */
  27 
  28 
  29 class ciBlock;
  30 
  31 typedef short ciBlockIndex;
  32 
  33 class ciMethodBlocks : public ResourceObj {
  34 private:
  35   ciMethod *_method;
  36   Arena *_arena;
  37   GrowableArray<ciBlock *>  *_blocks;
  38   ciBlock  **_bci_to_block;
  39   int _num_blocks;
  40   int _code_size;
  41 
  42   void do_analysis();
  43 public:
  44   ciMethodBlocks(Arena *arena, ciMethod *meth);
  45 
  46   ciBlock *block_containing(int bci);
  47   ciBlock *block(int index)  { return _blocks->at(index); }
  48   ciBlock *make_block_at(int bci);
  49   ciBlock *split_block_at(int bci);
  50   bool is_block_start(int bci);
  51   int num_blocks()  { return _num_blocks;}
  52   void clear_processed();
  53 
  54 #ifndef PRODUCT
  55   void dump();
  56 #endif
  57 };
  58 
  59 class ciBlock : public ResourceObj {
  60 private:
  61   int _idx;
  62   int _start_bci;
  63   int _limit_bci;
  64   int _control_bci;
  65   uint _flags;
  66   int _ex_start_bci;
  67   int _ex_limit_bci;
  68 #ifndef PRODUCT
  69   ciMethod *_method;
  70 #endif
  71   enum {
  72     Processed   = (1 << 0),
  73     Handler     = (1 << 1),
  74     MayThrow    = (1 << 2),
  75     DoesJsr     = (1 << 3),
  76     DoesRet     = (1 << 4),
  77     RetTarget   = (1 << 5),
  78     HasHandler  = (1 << 6)
  79   };
  80 
  81 
  82 public:
  83   enum {
  84     fall_through_bci = -1
  85   };
  86 
  87   ciBlock(ciMethod *method, int index, ciMethodBlocks *mb, int start_bci);
  88   int start_bci() const         { return _start_bci; }
  89   int limit_bci() const         { return _limit_bci; }
  90   int control_bci() const       { return _control_bci; }
  91   int index() const             { return _idx; }
  92   void set_start_bci(int bci)   { _start_bci = bci; }
  93   void set_limit_bci(int bci)   { _limit_bci = bci; }
  94   void set_control_bci(int bci) { _control_bci = bci;}
  95   void set_exception_range(int start_bci, int limit_bci);
  96   int ex_start_bci() const      { return _ex_start_bci; }
  97   int ex_limit_bci() const      { return _ex_limit_bci; }
  98   bool contains(int bci) const { return start_bci() <= bci && bci < limit_bci(); }
  99 
 100 
 101   // flag handling
 102   bool  processed() const           { return (_flags & Processed) != 0; }
 103   bool  is_handler() const          { return (_flags & Handler) != 0; }
 104   bool  may_throw() const           { return (_flags & MayThrow) != 0; }
 105   bool  does_jsr() const            { return (_flags & DoesJsr) != 0; }
 106   bool  does_ret() const            { return (_flags & DoesRet) != 0; }
 107   bool  has_handler() const         { return (_flags & HasHandler) != 0; }
 108   bool  is_ret_target() const       { return (_flags & RetTarget) != 0; }
 109   void  set_processed()             { _flags |= Processed; }
 110   void  clear_processed()           { _flags &= ~Processed; }
 111   void  set_handler()               { _flags |= Handler; }
 112   void  set_may_throw()             { _flags |= MayThrow; }
 113   void  set_does_jsr()              { _flags |= DoesJsr; }
 114   void  clear_does_jsr()            { _flags &= ~DoesJsr; }
 115   void  set_does_ret()              { _flags |= DoesRet; }
 116   void  clear_does_ret()            { _flags |= DoesRet; }
 117   void  set_is_ret_target()         { _flags |= RetTarget; }
 118   void  set_has_handler()           { _flags |= HasHandler; }
 119 #ifndef PRODUCT
 120   ciMethod *method() const          { return _method; }
 121   void dump();
 122   void print_on(outputStream* st) const  PRODUCT_RETURN;
 123 #endif
 124 };