1 /*
2 * Copyright (c) 1999, 2016, 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 #include "precompiled.hpp"
26 #include "c1/c1_IR.hpp"
27 #include "c1/c1_InstructionPrinter.hpp"
28 #include "c1/c1_ValueStack.hpp"
29
30
31 // Implementation of ValueStack
32
33 ValueStack::ValueStack(IRScope* scope, ValueStack* caller_state)
34 : _scope(scope)
35 , _caller_state(caller_state)
36 , _bci(-99)
37 , _kind(Parsing)
38 , _locals(scope->method()->max_locals(), scope->method()->max_locals(), NULL)
39 , _stack(scope->method()->max_stack())
40 , _locks(NULL)
41 {
42 verify();
43 }
44
45 ValueStack::ValueStack(ValueStack* copy_from, Kind kind, int bci)
46 : _scope(copy_from->scope())
47 , _caller_state(copy_from->caller_state())
48 , _bci(bci)
49 , _kind(kind)
50 , _locals(copy_from->locals_size_for_copy(kind))
51 , _stack(copy_from->stack_size_for_copy(kind))
52 , _locks(copy_from->locks_size() == 0 ? NULL : new Values(copy_from->locks_size()))
53 {
54 assert(kind != EmptyExceptionState || !Compilation::current()->env()->should_retain_local_variables(), "need locals");
55 if (kind != EmptyExceptionState) {
56 _locals.appendAll(©_from->_locals);
57 }
58
59 if (kind != ExceptionState && kind != EmptyExceptionState) {
60 _stack.appendAll(©_from->_stack);
61 }
62
63 if (copy_from->locks_size() > 0) {
64 _locks->appendAll(copy_from->_locks);
65 }
66
67 verify();
68 }
69
175 return num_locks;
176 }
177
178 int ValueStack::lock(Value obj) {
179 if (_locks == NULL) {
180 _locks = new Values();
181 }
182 _locks->push(obj);
183 int num_locks = total_locks_size();
184 scope()->set_min_number_of_locks(num_locks);
185 return num_locks - 1;
186 }
187
188
189 int ValueStack::unlock() {
190 assert(locks_size() > 0, "sanity");
191 _locks->pop();
192 return total_locks_size();
193 }
194
195
196 void ValueStack::setup_phi_for_stack(BlockBegin* b, int index) {
197 assert(stack_at(index)->as_Phi() == NULL || stack_at(index)->as_Phi()->block() != b, "phi function already created");
198
199 ValueType* t = stack_at(index)->type();
200 Value phi = new Phi(t, b, -index - 1);
201 _stack.at_put(index, phi);
202
203 assert(!t->is_double_word() || _stack.at(index + 1) == NULL, "hi-word of doubleword value must be NULL");
204 }
205
206 void ValueStack::setup_phi_for_local(BlockBegin* b, int index) {
207 assert(local_at(index)->as_Phi() == NULL || local_at(index)->as_Phi()->block() != b, "phi function already created");
208
209 ValueType* t = local_at(index)->type();
210 Value phi = new Phi(t, b, index);
211 store_local(index, phi);
212 }
213
214 #ifndef PRODUCT
215
|
1 /*
2 * Copyright (c) 1999, 2019, 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 #include "precompiled.hpp"
26 #include "c1/c1_IR.hpp"
27 #include "c1/c1_InstructionPrinter.hpp"
28 #include "c1/c1_ValueStack.hpp"
29
30
31 // Implementation of ValueStack
32
33 ValueStack::ValueStack(IRScope* scope, ValueStack* caller_state)
34 : _scope(scope)
35 , _caller_state(caller_state)
36 , _bci(-99)
37 , _kind(Parsing)
38 , _should_reexecute(false)
39 , _locals(scope->method()->max_locals(), scope->method()->max_locals(), NULL)
40 , _stack(scope->method()->max_stack())
41 , _locks(NULL)
42 {
43 verify();
44 }
45
46 ValueStack::ValueStack(ValueStack* copy_from, Kind kind, int bci, bool reexecute)
47 : _scope(copy_from->scope())
48 , _caller_state(copy_from->caller_state())
49 , _bci(bci)
50 , _kind(kind)
51 , _should_reexecute(reexecute)
52 , _locals(copy_from->locals_size_for_copy(kind))
53 , _stack(copy_from->stack_size_for_copy(kind))
54 , _locks(copy_from->locks_size() == 0 ? NULL : new Values(copy_from->locks_size()))
55 {
56 assert(kind != EmptyExceptionState || !Compilation::current()->env()->should_retain_local_variables(), "need locals");
57 if (kind != EmptyExceptionState) {
58 _locals.appendAll(©_from->_locals);
59 }
60
61 if (kind != ExceptionState && kind != EmptyExceptionState) {
62 _stack.appendAll(©_from->_stack);
63 }
64
65 if (copy_from->locks_size() > 0) {
66 _locks->appendAll(copy_from->_locks);
67 }
68
69 verify();
70 }
71
177 return num_locks;
178 }
179
180 int ValueStack::lock(Value obj) {
181 if (_locks == NULL) {
182 _locks = new Values();
183 }
184 _locks->push(obj);
185 int num_locks = total_locks_size();
186 scope()->set_min_number_of_locks(num_locks);
187 return num_locks - 1;
188 }
189
190
191 int ValueStack::unlock() {
192 assert(locks_size() > 0, "sanity");
193 _locks->pop();
194 return total_locks_size();
195 }
196
197 void ValueStack::setup_phi_for_stack(BlockBegin* b, int index) {
198 assert(stack_at(index)->as_Phi() == NULL || stack_at(index)->as_Phi()->block() != b, "phi function already created");
199
200 ValueType* t = stack_at(index)->type();
201 Value phi = new Phi(t, b, -index - 1);
202 _stack.at_put(index, phi);
203
204 assert(!t->is_double_word() || _stack.at(index + 1) == NULL, "hi-word of doubleword value must be NULL");
205 }
206
207 void ValueStack::setup_phi_for_local(BlockBegin* b, int index) {
208 assert(local_at(index)->as_Phi() == NULL || local_at(index)->as_Phi()->block() != b, "phi function already created");
209
210 ValueType* t = local_at(index)->type();
211 Value phi = new Phi(t, b, index);
212 store_local(index, phi);
213 }
214
215 #ifndef PRODUCT
216
|