1612N/A/*
1879N/A * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
1612N/A * Copyright 2008, 2009 Red Hat, Inc.
1612N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
1612N/A *
1612N/A * This code is free software; you can redistribute it and/or modify it
1612N/A * under the terms of the GNU General Public License version 2 only, as
1612N/A * published by the Free Software Foundation.
1612N/A *
1612N/A * This code is distributed in the hope that it will be useful, but WITHOUT
1612N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1612N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
1612N/A * version 2 for more details (a copy is included in the LICENSE file that
1612N/A * accompanied this code).
1612N/A *
1612N/A * You should have received a copy of the GNU General Public License version
1612N/A * 2 along with this work; if not, write to the Free Software Foundation,
1612N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1612N/A *
1612N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1612N/A * or visit www.oracle.com if you need additional information or have any
1612N/A * questions.
1612N/A *
1612N/A */
1612N/A
1879N/A#ifndef SHARE_VM_SHARK_SHARKSTATE_HPP
1879N/A#define SHARE_VM_SHARK_SHARKSTATE_HPP
1879N/A
1879N/A#include "ci/ciMethod.hpp"
1879N/A#include "memory/allocation.hpp"
1879N/A#include "shark/llvmHeaders.hpp"
1879N/A#include "shark/sharkBuilder.hpp"
1879N/A#include "shark/sharkInvariants.hpp"
1879N/A#include "shark/sharkValue.hpp"
1879N/A
1612N/Aclass SharkState : public SharkTargetInvariants {
1612N/A public:
1612N/A SharkState(const SharkTargetInvariants* parent)
1612N/A : SharkTargetInvariants(parent),
1612N/A _method(NULL),
1612N/A _oop_tmp(NULL),
1612N/A _has_safepointed(false) { initialize(NULL); }
1612N/A
1612N/A SharkState(const SharkState* state)
1612N/A : SharkTargetInvariants(state),
1612N/A _method(state->_method),
1612N/A _oop_tmp(state->_oop_tmp),
1612N/A _has_safepointed(state->_has_safepointed) { initialize(state); }
1612N/A
1612N/A private:
1612N/A void initialize(const SharkState* state);
1612N/A
1612N/A private:
1612N/A llvm::Value* _method;
1612N/A SharkValue** _locals;
1612N/A SharkValue** _stack;
1612N/A SharkValue** _sp;
1612N/A int _num_monitors;
1612N/A llvm::Value* _oop_tmp;
1612N/A bool _has_safepointed;
1612N/A
1612N/A // Method
1612N/A public:
1612N/A llvm::Value** method_addr() {
1612N/A return &_method;
1612N/A }
1612N/A llvm::Value* method() const {
1612N/A return _method;
1612N/A }
1612N/A protected:
1612N/A void set_method(llvm::Value* method) {
1612N/A _method = method;
1612N/A }
1612N/A
1612N/A // Local variables
1612N/A public:
1612N/A SharkValue** local_addr(int index) const {
1612N/A assert(index >= 0 && index < max_locals(), "bad local variable index");
1612N/A return &_locals[index];
1612N/A }
1612N/A SharkValue* local(int index) const {
1612N/A return *local_addr(index);
1612N/A }
1612N/A void set_local(int index, SharkValue* value) {
1612N/A *local_addr(index) = value;
1612N/A }
1612N/A
1612N/A // Expression stack
1612N/A public:
1612N/A SharkValue** stack_addr(int slot) const {
1612N/A assert(slot >= 0 && slot < stack_depth(), "bad stack slot");
1612N/A return &_sp[-(slot + 1)];
1612N/A }
1612N/A SharkValue* stack(int slot) const {
1612N/A return *stack_addr(slot);
1612N/A }
1612N/A protected:
1612N/A void set_stack(int slot, SharkValue* value) {
1612N/A *stack_addr(slot) = value;
1612N/A }
1612N/A public:
1612N/A int stack_depth() const {
1612N/A return _sp - _stack;
1612N/A }
1612N/A void push(SharkValue* value) {
1612N/A assert(stack_depth() < max_stack(), "stack overrun");
1612N/A *(_sp++) = value;
1612N/A }
1612N/A SharkValue* pop() {
1612N/A assert(stack_depth() > 0, "stack underrun");
1612N/A return *(--_sp);
1612N/A }
1612N/A
1612N/A // Monitors
1612N/A public:
1612N/A int num_monitors() const {
1612N/A return _num_monitors;
1612N/A }
1612N/A void set_num_monitors(int num_monitors) {
1612N/A _num_monitors = num_monitors;
1612N/A }
1612N/A
1612N/A // Temporary oop slot
1612N/A public:
1612N/A llvm::Value** oop_tmp_addr() {
1612N/A return &_oop_tmp;
1612N/A }
1612N/A llvm::Value* oop_tmp() const {
1612N/A return _oop_tmp;
1612N/A }
1612N/A void set_oop_tmp(llvm::Value* oop_tmp) {
1612N/A _oop_tmp = oop_tmp;
1612N/A }
1612N/A
1612N/A // Safepointed status
1612N/A public:
1612N/A bool has_safepointed() const {
1612N/A return _has_safepointed;
1612N/A }
1612N/A void set_has_safepointed(bool has_safepointed) {
1612N/A _has_safepointed = has_safepointed;
1612N/A }
1612N/A
1612N/A // Comparison
1612N/A public:
1612N/A bool equal_to(SharkState* other);
1612N/A
1612N/A // Copy and merge
1612N/A public:
1612N/A SharkState* copy() const {
1612N/A return new SharkState(this);
1612N/A }
1612N/A void merge(SharkState* other,
1612N/A llvm::BasicBlock* other_block,
1612N/A llvm::BasicBlock* this_block);
1612N/A
1612N/A // Value replacement
1612N/A public:
1612N/A void replace_all(SharkValue* old_value, SharkValue* new_value);
1612N/A};
1612N/A
1612N/Aclass SharkTopLevelBlock;
1612N/A
1612N/A// SharkNormalEntryState objects are used to create the state
1612N/A// that the method will be entered with for a normal invocation.
1612N/Aclass SharkNormalEntryState : public SharkState {
1612N/A public:
1612N/A SharkNormalEntryState(SharkTopLevelBlock* block,
1612N/A llvm::Value* method);
1612N/A};
1612N/A
1612N/A// SharkOSREntryState objects are used to create the state
1612N/A// that the method will be entered with for an OSR invocation.
1612N/Aclass SharkOSREntryState : public SharkState {
1612N/A public:
1612N/A SharkOSREntryState(SharkTopLevelBlock* block,
1612N/A llvm::Value* method,
1612N/A llvm::Value* osr_buf);
1612N/A};
1612N/A
1612N/A// SharkPHIState objects are used to manage the entry state
1612N/A// for blocks with more than one entry path or for blocks
1612N/A// entered from blocks that will be compiled later.
1612N/Aclass SharkPHIState : public SharkState {
1612N/A public:
1612N/A SharkPHIState(SharkTopLevelBlock* block);
1612N/A
1612N/A private:
1612N/A SharkTopLevelBlock* _block;
1612N/A
1612N/A private:
1612N/A SharkTopLevelBlock* block() const {
1612N/A return _block;
1612N/A }
1612N/A
1612N/A public:
1612N/A void add_incoming(SharkState* incoming_state);
1612N/A};
1879N/A
1879N/A#endif // SHARE_VM_SHARK_SHARKSTATE_HPP