1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/vm/shark/sharkState.hpp Wed Apr 27 01:25:04 2016 +0800 1.3 @@ -0,0 +1,200 @@ 1.4 +/* 1.5 + * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved. 1.6 + * Copyright 2008, 2009 Red Hat, Inc. 1.7 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.8 + * 1.9 + * This code is free software; you can redistribute it and/or modify it 1.10 + * under the terms of the GNU General Public License version 2 only, as 1.11 + * published by the Free Software Foundation. 1.12 + * 1.13 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.14 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.15 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.16 + * version 2 for more details (a copy is included in the LICENSE file that 1.17 + * accompanied this code). 1.18 + * 1.19 + * You should have received a copy of the GNU General Public License version 1.20 + * 2 along with this work; if not, write to the Free Software Foundation, 1.21 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.22 + * 1.23 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.24 + * or visit www.oracle.com if you need additional information or have any 1.25 + * questions. 1.26 + * 1.27 + */ 1.28 + 1.29 +#ifndef SHARE_VM_SHARK_SHARKSTATE_HPP 1.30 +#define SHARE_VM_SHARK_SHARKSTATE_HPP 1.31 + 1.32 +#include "ci/ciMethod.hpp" 1.33 +#include "memory/allocation.hpp" 1.34 +#include "shark/llvmHeaders.hpp" 1.35 +#include "shark/sharkBuilder.hpp" 1.36 +#include "shark/sharkInvariants.hpp" 1.37 +#include "shark/sharkValue.hpp" 1.38 + 1.39 +class SharkState : public SharkTargetInvariants { 1.40 + public: 1.41 + SharkState(const SharkTargetInvariants* parent) 1.42 + : SharkTargetInvariants(parent), 1.43 + _method(NULL), 1.44 + _oop_tmp(NULL), 1.45 + _has_safepointed(false) { initialize(NULL); } 1.46 + 1.47 + SharkState(const SharkState* state) 1.48 + : SharkTargetInvariants(state), 1.49 + _method(state->_method), 1.50 + _oop_tmp(state->_oop_tmp), 1.51 + _has_safepointed(state->_has_safepointed) { initialize(state); } 1.52 + 1.53 + private: 1.54 + void initialize(const SharkState* state); 1.55 + 1.56 + private: 1.57 + llvm::Value* _method; 1.58 + SharkValue** _locals; 1.59 + SharkValue** _stack; 1.60 + SharkValue** _sp; 1.61 + int _num_monitors; 1.62 + llvm::Value* _oop_tmp; 1.63 + bool _has_safepointed; 1.64 + 1.65 + // Method 1.66 + public: 1.67 + llvm::Value** method_addr() { 1.68 + return &_method; 1.69 + } 1.70 + llvm::Value* method() const { 1.71 + return _method; 1.72 + } 1.73 + protected: 1.74 + void set_method(llvm::Value* method) { 1.75 + _method = method; 1.76 + } 1.77 + 1.78 + // Local variables 1.79 + public: 1.80 + SharkValue** local_addr(int index) const { 1.81 + assert(index >= 0 && index < max_locals(), "bad local variable index"); 1.82 + return &_locals[index]; 1.83 + } 1.84 + SharkValue* local(int index) const { 1.85 + return *local_addr(index); 1.86 + } 1.87 + void set_local(int index, SharkValue* value) { 1.88 + *local_addr(index) = value; 1.89 + } 1.90 + 1.91 + // Expression stack 1.92 + public: 1.93 + SharkValue** stack_addr(int slot) const { 1.94 + assert(slot >= 0 && slot < stack_depth(), "bad stack slot"); 1.95 + return &_sp[-(slot + 1)]; 1.96 + } 1.97 + SharkValue* stack(int slot) const { 1.98 + return *stack_addr(slot); 1.99 + } 1.100 + protected: 1.101 + void set_stack(int slot, SharkValue* value) { 1.102 + *stack_addr(slot) = value; 1.103 + } 1.104 + public: 1.105 + int stack_depth() const { 1.106 + return _sp - _stack; 1.107 + } 1.108 + void push(SharkValue* value) { 1.109 + assert(stack_depth() < max_stack(), "stack overrun"); 1.110 + *(_sp++) = value; 1.111 + } 1.112 + SharkValue* pop() { 1.113 + assert(stack_depth() > 0, "stack underrun"); 1.114 + return *(--_sp); 1.115 + } 1.116 + 1.117 + // Monitors 1.118 + public: 1.119 + int num_monitors() const { 1.120 + return _num_monitors; 1.121 + } 1.122 + void set_num_monitors(int num_monitors) { 1.123 + _num_monitors = num_monitors; 1.124 + } 1.125 + 1.126 + // Temporary oop slot 1.127 + public: 1.128 + llvm::Value** oop_tmp_addr() { 1.129 + return &_oop_tmp; 1.130 + } 1.131 + llvm::Value* oop_tmp() const { 1.132 + return _oop_tmp; 1.133 + } 1.134 + void set_oop_tmp(llvm::Value* oop_tmp) { 1.135 + _oop_tmp = oop_tmp; 1.136 + } 1.137 + 1.138 + // Safepointed status 1.139 + public: 1.140 + bool has_safepointed() const { 1.141 + return _has_safepointed; 1.142 + } 1.143 + void set_has_safepointed(bool has_safepointed) { 1.144 + _has_safepointed = has_safepointed; 1.145 + } 1.146 + 1.147 + // Comparison 1.148 + public: 1.149 + bool equal_to(SharkState* other); 1.150 + 1.151 + // Copy and merge 1.152 + public: 1.153 + SharkState* copy() const { 1.154 + return new SharkState(this); 1.155 + } 1.156 + void merge(SharkState* other, 1.157 + llvm::BasicBlock* other_block, 1.158 + llvm::BasicBlock* this_block); 1.159 + 1.160 + // Value replacement 1.161 + public: 1.162 + void replace_all(SharkValue* old_value, SharkValue* new_value); 1.163 +}; 1.164 + 1.165 +class SharkTopLevelBlock; 1.166 + 1.167 +// SharkNormalEntryState objects are used to create the state 1.168 +// that the method will be entered with for a normal invocation. 1.169 +class SharkNormalEntryState : public SharkState { 1.170 + public: 1.171 + SharkNormalEntryState(SharkTopLevelBlock* block, 1.172 + llvm::Value* method); 1.173 +}; 1.174 + 1.175 +// SharkOSREntryState objects are used to create the state 1.176 +// that the method will be entered with for an OSR invocation. 1.177 +class SharkOSREntryState : public SharkState { 1.178 + public: 1.179 + SharkOSREntryState(SharkTopLevelBlock* block, 1.180 + llvm::Value* method, 1.181 + llvm::Value* osr_buf); 1.182 +}; 1.183 + 1.184 +// SharkPHIState objects are used to manage the entry state 1.185 +// for blocks with more than one entry path or for blocks 1.186 +// entered from blocks that will be compiled later. 1.187 +class SharkPHIState : public SharkState { 1.188 + public: 1.189 + SharkPHIState(SharkTopLevelBlock* block); 1.190 + 1.191 + private: 1.192 + SharkTopLevelBlock* _block; 1.193 + 1.194 + private: 1.195 + SharkTopLevelBlock* block() const { 1.196 + return _block; 1.197 + } 1.198 + 1.199 + public: 1.200 + void add_incoming(SharkState* incoming_state); 1.201 +}; 1.202 + 1.203 +#endif // SHARE_VM_SHARK_SHARKSTATE_HPP