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-2008 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   ciBlock *make_dummy_block(); // a block not associated with a bci
  55 
  56 #ifndef PRODUCT
  57   void dump();
  58 #endif
  59 };
  60 
  61 class ciBlock : public ResourceObj {
  62 private:
  63   int _idx;
  64   int _start_bci;
  65   int _limit_bci;
  66   int _control_bci;
  67   uint _flags;
  68   int _ex_start_bci;
  69   int _ex_limit_bci;
  70 #ifndef PRODUCT
  71   ciMethod *_method;
  72 #endif
  73   enum {
  74     Processed   = (1 << 0),
  75     Handler     = (1 << 1),
  76     MayThrow    = (1 << 2),
  77     DoesJsr     = (1 << 3),
  78     DoesRet     = (1 << 4),
  79     RetTarget   = (1 << 5),
  80     HasHandler  = (1 << 6)
  81   };
  82 
  83 
  84 public:
  85   enum {
  86     fall_through_bci = -1
  87   };
  88 
  89   ciBlock(ciMethod *method, int index, int start_bci);
  90   int start_bci() const         { return _start_bci; }
  91   int limit_bci() const         { return _limit_bci; }
  92   int control_bci() const       { return _control_bci; }
  93   int index() const             { return _idx; }
  94   void set_start_bci(int bci)   { _start_bci = bci; }
  95   void set_limit_bci(int bci)   { _limit_bci = bci; }
  96   void set_control_bci(int bci) { _control_bci = bci;}
  97   void set_exception_range(int start_bci, int limit_bci);
  98   int ex_start_bci() const      { return _ex_start_bci; }
  99   int ex_limit_bci() const      { return _ex_limit_bci; }
 100   bool contains(int bci) const { return start_bci() <= bci && bci < limit_bci(); }
 101 
 102   // flag handling
 103   bool  processed() const           { return (_flags & Processed) != 0; }
 104   bool  is_handler() const          { return (_flags & Handler) != 0; }
 105   bool  may_throw() const           { return (_flags & MayThrow) != 0; }
 106   bool  does_jsr() const            { return (_flags & DoesJsr) != 0; }
 107   bool  does_ret() const            { return (_flags & DoesRet) != 0; }
 108   bool  has_handler() const         { return (_flags & HasHandler) != 0; }
 109   bool  is_ret_target() const       { return (_flags & RetTarget) != 0; }
 110   void  set_processed()             { _flags |= Processed; }
 111   void  clear_processed()           { _flags &= ~Processed; }
 112   void  set_handler()               { _flags |= Handler; }
 113   void  set_may_throw()             { _flags |= MayThrow; }
 114   void  set_does_jsr()              { _flags |= DoesJsr; }
 115   void  clear_does_jsr()            { _flags &= ~DoesJsr; }
 116   void  set_does_ret()              { _flags |= DoesRet; }
 117   void  clear_does_ret()            { _flags &= ~DoesRet; }
 118   void  set_is_ret_target()         { _flags |= RetTarget; }
 119   void  set_has_handler()           { _flags |= HasHandler; }
 120   void  clear_exception_handler()   { _flags &= ~Handler; _ex_start_bci = -1; _ex_limit_bci = -1; }
 121 #ifndef PRODUCT
 122   ciMethod *method() const          { return _method; }
 123   void dump();
 124   void print_on(outputStream* st) const  PRODUCT_RETURN;
 125 #endif
 126 };