1 /*
2  * Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * This code is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License version 2 only, as
7  * published by the Free Software Foundation.
8  *
9  * This code is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12  * version 2 for more details (a copy is included in the LICENSE file that
13  * accompanied this code).
14  *
15  * You should have received a copy of the GNU General Public License version
16  * 2 along with this work; if not, write to the Free Software Foundation,
17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18  *
19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20  * or visit www.oracle.com if you need additional information or have any
21  * questions.
22  *
23  */
24 
25 #ifndef SHARE_VM_CI_CIMETHODBLOCKS_HPP
26 #define SHARE_VM_CI_CIMETHODBLOCKS_HPP
27 
28 #include "ci/ciMethod.hpp"
29 #include "memory/resourceArea.hpp"
30 #include "utilities/growableArray.hpp"
31 
32 
33 class ciBlock;
34 
35 typedef short ciBlockIndex;
36 
37 class ciMethodBlocks : public ResourceObj {
38 private:
39   ciMethod *_method;
40   Arena *_arena;
41   GrowableArray<ciBlock *>  *_blocks;
42   ciBlock  **_bci_to_block;
43   int _num_blocks;
44   int _code_size;
45 
46   void do_analysis();
47 public:
48   ciMethodBlocks(Arena *arena, ciMethod *meth);
49 
50   ciBlock *block_containing(int bci);
block(int index)51   ciBlock *block(int index)  { return _blocks->at(index); }
52   ciBlock *make_block_at(int bci);
53   ciBlock *split_block_at(int bci);
54   bool is_block_start(int bci);
num_blocks()55   int num_blocks()  { return _num_blocks;}
56   void clear_processed();
57 
58   ciBlock *make_dummy_block(); // a block not associated with a bci
59 
60 #ifndef PRODUCT
61   void dump();
62 #endif
63 };
64 
65 class ciBlock : public ResourceObj {
66 private:
67   int _idx;
68   int _start_bci;
69   int _limit_bci;
70   int _control_bci;
71   uint _flags;
72   int _ex_start_bci;
73   int _ex_limit_bci;
74 #ifndef PRODUCT
75   ciMethod *_method;
76 #endif
77   enum {
78     Processed   = (1 << 0),
79     Handler     = (1 << 1),
80     MayThrow    = (1 << 2),
81     DoesJsr     = (1 << 3),
82     DoesRet     = (1 << 4),
83     RetTarget   = (1 << 5),
84     HasHandler  = (1 << 6)
85   };
86 
87 
88 public:
89   enum {
90     fall_through_bci = -1
91   };
92 
93   ciBlock(ciMethod *method, int index, int start_bci);
start_bci() const94   int start_bci() const         { return _start_bci; }
limit_bci() const95   int limit_bci() const         { return _limit_bci; }
control_bci() const96   int control_bci() const       { return _control_bci; }
index() const97   int index() const             { return _idx; }
set_start_bci(int bci)98   void set_start_bci(int bci)   { _start_bci = bci; }
set_limit_bci(int bci)99   void set_limit_bci(int bci)   { _limit_bci = bci; }
set_control_bci(int bci)100   void set_control_bci(int bci) { _control_bci = bci;}
101   void set_exception_range(int start_bci, int limit_bci);
ex_start_bci() const102   int ex_start_bci() const      { return _ex_start_bci; }
ex_limit_bci() const103   int ex_limit_bci() const      { return _ex_limit_bci; }
contains(int bci) const104   bool contains(int bci) const { return start_bci() <= bci && bci < limit_bci(); }
105 
106   // flag handling
processed() const107   bool  processed() const           { return (_flags & Processed) != 0; }
is_handler() const108   bool  is_handler() const          { return (_flags & Handler) != 0; }
may_throw() const109   bool  may_throw() const           { return (_flags & MayThrow) != 0; }
does_jsr() const110   bool  does_jsr() const            { return (_flags & DoesJsr) != 0; }
does_ret() const111   bool  does_ret() const            { return (_flags & DoesRet) != 0; }
has_handler() const112   bool  has_handler() const         { return (_flags & HasHandler) != 0; }
is_ret_target() const113   bool  is_ret_target() const       { return (_flags & RetTarget) != 0; }
set_processed()114   void  set_processed()             { _flags |= Processed; }
clear_processed()115   void  clear_processed()           { _flags &= ~Processed; }
set_handler()116   void  set_handler()               { _flags |= Handler; }
set_may_throw()117   void  set_may_throw()             { _flags |= MayThrow; }
set_does_jsr()118   void  set_does_jsr()              { _flags |= DoesJsr; }
clear_does_jsr()119   void  clear_does_jsr()            { _flags &= ~DoesJsr; }
set_does_ret()120   void  set_does_ret()              { _flags |= DoesRet; }
clear_does_ret()121   void  clear_does_ret()            { _flags &= ~DoesRet; }
set_is_ret_target()122   void  set_is_ret_target()         { _flags |= RetTarget; }
set_has_handler()123   void  set_has_handler()           { _flags |= HasHandler; }
clear_exception_handler()124   void  clear_exception_handler()   { _flags &= ~Handler; _ex_start_bci = -1; _ex_limit_bci = -1; }
125 #ifndef PRODUCT
method() const126   ciMethod *method() const          { return _method; }
127   void dump();
128   void print_on(outputStream* st) const  PRODUCT_RETURN;
129 #endif
130 };
131 
132 #endif // SHARE_VM_CI_CIMETHODBLOCKS_HPP
133