37 // Exception states for an instruction.
38 // Dead stack items or locals may be invalidated or cleared/removed.
39 // Locals are retained if needed for JVMTI.
40 // "empty" exception states are used when there is no handler,
41 // and invalidate the locals.
42 // "leaf" exception states clear the stack.
43 // "caller" exception states are used for the parent/caller,
44 // and invalidate the stack.
45 ExceptionState, // Exception state for leaf with handler, stack cleared
46 EmptyExceptionState, // Exception state for leaf w/o handler, stack cleared, locals invalidated
47 CallerExceptionState, // Exception state for parent with handler, stack invalidated
48 CallerEmptyExceptionState, // Exception state for parent w/o handler, stack+locals invalidated
49 BlockBeginState // State of BlockBegin instruction with phi functions of this block
50 };
51
52 private:
53 IRScope* _scope; // the enclosing scope
54 ValueStack* _caller_state;
55 int _bci;
56 Kind _kind;
57
58 Values _locals; // the locals
59 Values _stack; // the expression stack
60 Values* _locks; // the monitor stack (holding the locked values)
61
62 Value check(ValueTag tag, Value t) {
63 assert(tag == t->type()->tag() || (tag == objectTag && t->type()->tag() == addressTag), "types must correspond");
64 return t;
65 }
66
67 Value check(ValueTag tag, Value t, Value h) {
68 assert(h == nullptr, "hi-word of doubleword value must be null");
69 return check(tag, t);
70 }
71
72 // helper routine
73 static void apply(const Values& list, ValueVisitor* f);
74
75 // for simplified copying
76 ValueStack(ValueStack* copy_from, Kind kind, int bci);
77
78 int locals_size_for_copy(Kind kind) const;
79 int stack_size_for_copy(Kind kind) const;
80 public:
81 // creation
82 ValueStack(IRScope* scope, ValueStack* caller_state);
83
84 ValueStack* copy() { return new ValueStack(this, _kind, _bci); }
85 ValueStack* copy(Kind new_kind, int new_bci) { return new ValueStack(this, new_kind, new_bci); }
86 ValueStack* copy_for_parsing() { return new ValueStack(this, Parsing, -99); }
87
88 // Used when no exception handler is found
89 static Kind empty_exception_kind(bool caller = false) {
90 return Compilation::current()->env()->should_retain_local_variables() ?
91 (caller ? CallerExceptionState : ExceptionState) : // retain locals
92 (caller ? CallerEmptyExceptionState : EmptyExceptionState); // clear locals
93 }
94
95 void set_caller_state(ValueStack* s) {
96 assert(kind() == empty_exception_kind(false) || kind() == empty_exception_kind(true),
97 "only empty exception states can be modified");
98 _caller_state = s;
99 }
100
101 bool is_same(ValueStack* s); // returns true if this & s's types match (w/o checking locals)
102
103 // accessors
104 IRScope* scope() const { return _scope; }
105 ValueStack* caller_state() const { return _caller_state; }
106 int bci() const { return _bci; }
107 Kind kind() const { return _kind; }
108
109 int locals_size() const { return _locals.length(); }
110 int stack_size() const { return _stack.length(); }
111 int locks_size() const { return _locks == nullptr ? 0 : _locks->length(); }
112 bool stack_is_empty() const { return _stack.is_empty(); }
113 bool no_active_locks() const { return _locks == nullptr || _locks->is_empty(); }
114 int total_locks_size() const;
115
116 // locals access
117 void clear_locals(); // sets all locals to null;
118
119 void invalidate_local(int i) {
120 assert(!_locals.at(i)->type()->is_double_word() ||
121 _locals.at(i + 1) == nullptr, "hi-word of doubleword value must be null");
122 _locals.at_put(i, nullptr);
123 }
124
125 Value local_at(int i) const {
126 Value x = _locals.at(i);
127 assert(x == nullptr || !x->type()->is_double_word() ||
|
37 // Exception states for an instruction.
38 // Dead stack items or locals may be invalidated or cleared/removed.
39 // Locals are retained if needed for JVMTI.
40 // "empty" exception states are used when there is no handler,
41 // and invalidate the locals.
42 // "leaf" exception states clear the stack.
43 // "caller" exception states are used for the parent/caller,
44 // and invalidate the stack.
45 ExceptionState, // Exception state for leaf with handler, stack cleared
46 EmptyExceptionState, // Exception state for leaf w/o handler, stack cleared, locals invalidated
47 CallerExceptionState, // Exception state for parent with handler, stack invalidated
48 CallerEmptyExceptionState, // Exception state for parent w/o handler, stack+locals invalidated
49 BlockBeginState // State of BlockBegin instruction with phi functions of this block
50 };
51
52 private:
53 IRScope* _scope; // the enclosing scope
54 ValueStack* _caller_state;
55 int _bci;
56 Kind _kind;
57 bool _should_reexecute;
58
59 Values _locals; // the locals
60 Values _stack; // the expression stack
61 Values* _locks; // the monitor stack (holding the locked values)
62
63 Value check(ValueTag tag, Value t) {
64 assert(tag == t->type()->tag() || (tag == objectTag && t->type()->tag() == addressTag), "types must correspond");
65 return t;
66 }
67
68 Value check(ValueTag tag, Value t, Value h) {
69 assert(h == nullptr, "hi-word of doubleword value must be null");
70 return check(tag, t);
71 }
72
73 // helper routine
74 static void apply(const Values& list, ValueVisitor* f);
75
76 // for simplified copying
77 ValueStack(ValueStack* copy_from, Kind kind, int bci, bool reexecute);
78
79 int locals_size_for_copy(Kind kind) const;
80 int stack_size_for_copy(Kind kind) const;
81 public:
82 // creation
83 ValueStack(IRScope* scope, ValueStack* caller_state);
84
85 ValueStack* copy() { return new ValueStack(this, _kind, _bci, _should_reexecute); }
86 ValueStack* copy(Kind new_kind, int new_bci) { return new ValueStack(this, new_kind, new_bci, _should_reexecute); }
87 ValueStack* copy_for_parsing() { return new ValueStack(this, Parsing, -99, false); }
88
89 // Used when no exception handler is found
90 static Kind empty_exception_kind(bool caller = false) {
91 return Compilation::current()->env()->should_retain_local_variables() ?
92 (caller ? CallerExceptionState : ExceptionState) : // retain locals
93 (caller ? CallerEmptyExceptionState : EmptyExceptionState); // clear locals
94 }
95
96 void set_caller_state(ValueStack* s) {
97 assert(kind() == empty_exception_kind(false) || kind() == empty_exception_kind(true),
98 "only empty exception states can be modified");
99 _caller_state = s;
100 }
101
102 bool is_same(ValueStack* s); // returns true if this & s's types match (w/o checking locals)
103
104 // accessors
105 IRScope* scope() const { return _scope; }
106 ValueStack* caller_state() const { return _caller_state; }
107 int bci() const { return _bci; }
108 Kind kind() const { return _kind; }
109 bool should_reexecute() const { return _should_reexecute; }
110 void set_should_reexecute(bool reexec) { _should_reexecute = reexec; }
111
112 int locals_size() const { return _locals.length(); }
113 int stack_size() const { return _stack.length(); }
114 int locks_size() const { return _locks == nullptr ? 0 : _locks->length(); }
115 bool stack_is_empty() const { return _stack.is_empty(); }
116 bool no_active_locks() const { return _locks == nullptr || _locks->is_empty(); }
117 int total_locks_size() const;
118
119 // locals access
120 void clear_locals(); // sets all locals to null;
121
122 void invalidate_local(int i) {
123 assert(!_locals.at(i)->type()->is_double_word() ||
124 _locals.at(i + 1) == nullptr, "hi-word of doubleword value must be null");
125 _locals.at_put(i, nullptr);
126 }
127
128 Value local_at(int i) const {
129 Value x = _locals.at(i);
130 assert(x == nullptr || !x->type()->is_double_word() ||
|