Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/c1/c1_ValueStack.hpp
32285 views
/*1* Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#ifndef SHARE_VM_C1_C1_VALUESTACK_HPP25#define SHARE_VM_C1_C1_VALUESTACK_HPP2627#include "c1/c1_Instruction.hpp"2829class ValueStack: public CompilationResourceObj {30public:31enum Kind {32Parsing, // During abstract interpretation in GraphBuilder33CallerState, // Caller state when inlining34StateBefore, // Before before execution of instruction35StateAfter, // After execution of instruction36ExceptionState, // Exception handling of instruction37EmptyExceptionState, // Exception handling of instructions not covered by an xhandler38BlockBeginState // State of BlockBegin instruction with phi functions of this block39};4041private:42IRScope* _scope; // the enclosing scope43ValueStack* _caller_state;44int _bci;45Kind _kind;4647Values _locals; // the locals48Values _stack; // the expression stack49Values _locks; // the monitor stack (holding the locked values)5051Value check(ValueTag tag, Value t) {52assert(tag == t->type()->tag() || tag == objectTag && t->type()->tag() == addressTag, "types must correspond");53return t;54}5556Value check(ValueTag tag, Value t, Value h) {57assert(h == NULL, "hi-word of doubleword value must be NULL");58return check(tag, t);59}6061// helper routine62static void apply(Values list, ValueVisitor* f);6364// for simplified copying65ValueStack(ValueStack* copy_from, Kind kind, int bci);6667public:68// creation69ValueStack(IRScope* scope, ValueStack* caller_state);7071ValueStack* copy() { return new ValueStack(this, _kind, _bci); }72ValueStack* copy(Kind new_kind, int new_bci) { return new ValueStack(this, new_kind, new_bci); }73ValueStack* copy_for_parsing() { return new ValueStack(this, Parsing, -99); }7475void set_caller_state(ValueStack* s) {76assert(kind() == EmptyExceptionState ||77(Compilation::current()->env()->should_retain_local_variables() && kind() == ExceptionState),78"only EmptyExceptionStates can be modified");79_caller_state = s;80}8182bool is_same(ValueStack* s); // returns true if this & s's types match (w/o checking locals)8384// accessors85IRScope* scope() const { return _scope; }86ValueStack* caller_state() const { return _caller_state; }87int bci() const { return _bci; }88Kind kind() const { return _kind; }8990int locals_size() const { return _locals.length(); }91int stack_size() const { return _stack.length(); }92int locks_size() const { return _locks.length(); }93bool stack_is_empty() const { return _stack.is_empty(); }94bool no_active_locks() const { return _locks.is_empty(); }95int total_locks_size() const;9697// locals access98void clear_locals(); // sets all locals to NULL;99100void invalidate_local(int i) {101assert(_locals.at(i)->type()->is_single_word() ||102_locals.at(i + 1) == NULL, "hi-word of doubleword value must be NULL");103_locals.at_put(i, NULL);104}105106Value local_at(int i) const {107Value x = _locals.at(i);108assert(x == NULL || x->type()->is_single_word() ||109_locals.at(i + 1) == NULL, "hi-word of doubleword value must be NULL");110return x;111}112113void store_local(int i, Value x) {114// When overwriting local i, check if i - 1 was the start of a115// double word local and kill it.116if (i > 0) {117Value prev = _locals.at(i - 1);118if (prev != NULL && prev->type()->is_double_word()) {119_locals.at_put(i - 1, NULL);120}121}122123_locals.at_put(i, x);124if (x->type()->is_double_word()) {125// hi-word of doubleword value is always NULL126_locals.at_put(i + 1, NULL);127}128}129130// stack access131Value stack_at(int i) const {132Value x = _stack.at(i);133assert(x->type()->is_single_word() ||134_stack.at(i + 1) == NULL, "hi-word of doubleword value must be NULL");135return x;136}137138Value stack_at_inc(int& i) const {139Value x = stack_at(i);140i += x->type()->size();141return x;142}143144void stack_at_put(int i, Value x) {145_stack.at_put(i, x);146}147148// pinning support149void pin_stack_for_linear_scan();150151// iteration152void values_do(ValueVisitor* f);153154// untyped manipulation (for dup_x1, etc.)155void truncate_stack(int size) { _stack.trunc_to(size); }156void raw_push(Value t) { _stack.push(t); }157Value raw_pop() { return _stack.pop(); }158159// typed manipulation160void ipush(Value t) { _stack.push(check(intTag , t)); }161void fpush(Value t) { _stack.push(check(floatTag , t)); }162void apush(Value t) { _stack.push(check(objectTag , t)); }163void rpush(Value t) { _stack.push(check(addressTag, t)); }164void lpush(Value t) { _stack.push(check(longTag , t)); _stack.push(NULL); }165void dpush(Value t) { _stack.push(check(doubleTag , t)); _stack.push(NULL); }166167void push(ValueType* type, Value t) {168switch (type->tag()) {169case intTag : ipush(t); return;170case longTag : lpush(t); return;171case floatTag : fpush(t); return;172case doubleTag : dpush(t); return;173case objectTag : apush(t); return;174case addressTag: rpush(t); return;175}176ShouldNotReachHere();177}178179Value ipop() { return check(intTag , _stack.pop()); }180Value fpop() { return check(floatTag , _stack.pop()); }181Value apop() { return check(objectTag , _stack.pop()); }182Value rpop() { return check(addressTag, _stack.pop()); }183Value lpop() { Value h = _stack.pop(); return check(longTag , _stack.pop(), h); }184Value dpop() { Value h = _stack.pop(); return check(doubleTag, _stack.pop(), h); }185186Value pop(ValueType* type) {187switch (type->tag()) {188case intTag : return ipop();189case longTag : return lpop();190case floatTag : return fpop();191case doubleTag : return dpop();192case objectTag : return apop();193case addressTag: return rpop();194}195ShouldNotReachHere();196return NULL;197}198199Values* pop_arguments(int argument_size);200201// locks access202int lock (Value obj);203int unlock();204Value lock_at(int i) const { return _locks.at(i); }205206// SSA form IR support207void setup_phi_for_stack(BlockBegin* b, int index);208void setup_phi_for_local(BlockBegin* b, int index);209210// debugging211void print() PRODUCT_RETURN;212void verify() PRODUCT_RETURN;213};214215216217// Macro definitions for simple iteration of stack and local values of a ValueStack218// The macros can be used like a for-loop. All variables (state, index and value)219// must be defined before the loop.220// When states are nested because of inlining, the stack of the innermost state221// cumulates also the stack of the nested states. In contrast, the locals of all222// states must be iterated each.223// Use the following code pattern to iterate all stack values and all nested local values:224//225// ValueStack* state = ... // state that is iterated226// int index; // current loop index (overwritten in loop)227// Value value; // value at current loop index (overwritten in loop)228//229// for_each_stack_value(state, index, value {230// do something with value and index231// }232//233// for_each_state(state) {234// for_each_local_value(state, index, value) {235// do something with value and index236// }237// }238// as an invariant, state is NULL now239240241// construct a unique variable name with the line number where the macro is used242#define temp_var3(x) temp__ ## x243#define temp_var2(x) temp_var3(x)244#define temp_var temp_var2(__LINE__)245246#define for_each_state(state) \247for (; state != NULL; state = state->caller_state())248249#define for_each_local_value(state, index, value) \250int temp_var = state->locals_size(); \251for (index = 0; \252index < temp_var && (value = state->local_at(index), true); \253index += (value == NULL || value->type()->is_illegal() ? 1 : value->type()->size())) \254if (value != NULL)255256257#define for_each_stack_value(state, index, value) \258int temp_var = state->stack_size(); \259for (index = 0; \260index < temp_var && (value = state->stack_at(index), true); \261index += value->type()->size())262263264#define for_each_lock_value(state, index, value) \265int temp_var = state->locks_size(); \266for (index = 0; \267index < temp_var && (value = state->lock_at(index), true); \268index++) \269if (value != NULL)270271272// Macro definition for simple iteration of all state values of a ValueStack273// Because the code cannot be executed in a single loop, the code must be passed274// as a macro parameter.275// Use the following code pattern to iterate all stack values and all nested local values:276//277// ValueStack* state = ... // state that is iterated278// for_each_state_value(state, value,279// do something with value (note that this is a macro parameter)280// );281282#define for_each_state_value(v_state, v_value, v_code) \283{ \284int cur_index; \285ValueStack* cur_state = v_state; \286Value v_value; \287for_each_state(cur_state) { \288{ \289for_each_local_value(cur_state, cur_index, v_value) { \290v_code; \291} \292} \293{ \294for_each_stack_value(cur_state, cur_index, v_value) { \295v_code; \296} \297} \298} \299}300301302// Macro definition for simple iteration of all phif functions of a block, i.e all303// phi functions of the ValueStack where the block matches.304// Use the following code pattern to iterate all phi functions of a block:305//306// BlockBegin* block = ... // block that is iterated307// for_each_phi_function(block, phi,308// do something with the phi function phi (note that this is a macro parameter)309// );310311#define for_each_phi_fun(v_block, v_phi, v_code) \312{ \313int cur_index; \314ValueStack* cur_state = v_block->state(); \315Value value; \316{ \317for_each_stack_value(cur_state, cur_index, value) { \318Phi* v_phi = value->as_Phi(); \319if (v_phi != NULL && v_phi->block() == v_block) { \320v_code; \321} \322} \323} \324{ \325for_each_local_value(cur_state, cur_index, value) { \326Phi* v_phi = value->as_Phi(); \327if (v_phi != NULL && v_phi->block() == v_block) { \328v_code; \329} \330} \331} \332}333334#endif // SHARE_VM_C1_C1_VALUESTACK_HPP335336337