ciMethodBlocks.hpp revision 1472:c18cbe5936b8
1/*
2 * Copyright (c) 2006, 2008, 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
26class ciBlock;
27
28typedef short ciBlockIndex;
29
30class ciMethodBlocks : public ResourceObj {
31private:
32  ciMethod *_method;
33  Arena *_arena;
34  GrowableArray<ciBlock *>  *_blocks;
35  ciBlock  **_bci_to_block;
36  int _num_blocks;
37  int _code_size;
38
39  void do_analysis();
40public:
41  ciMethodBlocks(Arena *arena, ciMethod *meth);
42
43  ciBlock *block_containing(int bci);
44  ciBlock *block(int index)  { return _blocks->at(index); }
45  ciBlock *make_block_at(int bci);
46  ciBlock *split_block_at(int bci);
47  bool is_block_start(int bci);
48  int num_blocks()  { return _num_blocks;}
49  void clear_processed();
50
51  ciBlock *make_dummy_block(); // a block not associated with a bci
52
53#ifndef PRODUCT
54  void dump();
55#endif
56};
57
58class ciBlock : public ResourceObj {
59private:
60  int _idx;
61  int _start_bci;
62  int _limit_bci;
63  int _control_bci;
64  uint _flags;
65  int _ex_start_bci;
66  int _ex_limit_bci;
67#ifndef PRODUCT
68  ciMethod *_method;
69#endif
70  enum {
71    Processed   = (1 << 0),
72    Handler     = (1 << 1),
73    MayThrow    = (1 << 2),
74    DoesJsr     = (1 << 3),
75    DoesRet     = (1 << 4),
76    RetTarget   = (1 << 5),
77    HasHandler  = (1 << 6)
78  };
79
80
81public:
82  enum {
83    fall_through_bci = -1
84  };
85
86  ciBlock(ciMethod *method, int index, int start_bci);
87  int start_bci() const         { return _start_bci; }
88  int limit_bci() const         { return _limit_bci; }
89  int control_bci() const       { return _control_bci; }
90  int index() const             { return _idx; }
91  void set_start_bci(int bci)   { _start_bci = bci; }
92  void set_limit_bci(int bci)   { _limit_bci = bci; }
93  void set_control_bci(int bci) { _control_bci = bci;}
94  void set_exception_range(int start_bci, int limit_bci);
95  int ex_start_bci() const      { return _ex_start_bci; }
96  int ex_limit_bci() const      { return _ex_limit_bci; }
97  bool contains(int bci) const { return start_bci() <= bci && bci < limit_bci(); }
98
99  // flag handling
100  bool  processed() const           { return (_flags & Processed) != 0; }
101  bool  is_handler() const          { return (_flags & Handler) != 0; }
102  bool  may_throw() const           { return (_flags & MayThrow) != 0; }
103  bool  does_jsr() const            { return (_flags & DoesJsr) != 0; }
104  bool  does_ret() const            { return (_flags & DoesRet) != 0; }
105  bool  has_handler() const         { return (_flags & HasHandler) != 0; }
106  bool  is_ret_target() const       { return (_flags & RetTarget) != 0; }
107  void  set_processed()             { _flags |= Processed; }
108  void  clear_processed()           { _flags &= ~Processed; }
109  void  set_handler()               { _flags |= Handler; }
110  void  set_may_throw()             { _flags |= MayThrow; }
111  void  set_does_jsr()              { _flags |= DoesJsr; }
112  void  clear_does_jsr()            { _flags &= ~DoesJsr; }
113  void  set_does_ret()              { _flags |= DoesRet; }
114  void  clear_does_ret()            { _flags &= ~DoesRet; }
115  void  set_is_ret_target()         { _flags |= RetTarget; }
116  void  set_has_handler()           { _flags |= HasHandler; }
117  void  clear_exception_handler()   { _flags &= ~Handler; _ex_start_bci = -1; _ex_limit_bci = -1; }
118#ifndef PRODUCT
119  ciMethod *method() const          { return _method; }
120  void dump();
121  void print_on(outputStream* st) const  PRODUCT_RETURN;
122#endif
123};
124