1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/vm/shark/sharkInvariants.hpp Wed Apr 27 01:25:04 2016 +0800 1.3 @@ -0,0 +1,184 @@ 1.4 +/* 1.5 + * Copyright (c) 1999, 2013, 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_SHARKINVARIANTS_HPP 1.30 +#define SHARE_VM_SHARK_SHARKINVARIANTS_HPP 1.31 + 1.32 +#include "ci/ciEnv.hpp" 1.33 +#include "ci/ciInstanceKlass.hpp" 1.34 +#include "ci/ciMethod.hpp" 1.35 +#include "ci/ciTypeFlow.hpp" 1.36 +#include "code/debugInfoRec.hpp" 1.37 +#include "code/dependencies.hpp" 1.38 +#include "memory/allocation.hpp" 1.39 +#include "shark/llvmHeaders.hpp" 1.40 +#include "shark/sharkBuilder.hpp" 1.41 + 1.42 +// Base classes used to track various values through the compilation. 1.43 +// SharkCompileInvariants is used to track values which remain the 1.44 +// same for the top-level method and any inlined methods it may have 1.45 +// (ie for the whole compilation). SharkTargetInvariants is used to 1.46 +// track values which differ between methods. 1.47 + 1.48 +class SharkCompileInvariants : public ResourceObj { 1.49 + protected: 1.50 + SharkCompileInvariants(ciEnv* env, SharkBuilder* builder) 1.51 + : _env(env), 1.52 + _builder(builder), 1.53 + _thread(NULL) {} 1.54 + 1.55 + SharkCompileInvariants(const SharkCompileInvariants* parent) 1.56 + : _env(parent->_env), 1.57 + _builder(parent->_builder), 1.58 + _thread(parent->_thread) {} 1.59 + 1.60 + private: 1.61 + ciEnv* _env; 1.62 + SharkBuilder* _builder; 1.63 + llvm::Value* _thread; 1.64 + 1.65 + // Top-level broker for HotSpot's Compiler Interface. 1.66 + // 1.67 + // Its main purpose is to allow the various CI classes to access 1.68 + // oops in the VM without having to worry about safepointing. In 1.69 + // addition to this it acts as a holder for various recorders and 1.70 + // memory allocators. 1.71 + // 1.72 + // Accessing this directly is kind of ugly, so it's private. Add 1.73 + // new accessors below if you need something from it. 1.74 + protected: 1.75 + ciEnv* env() const { 1.76 + assert(_env != NULL, "env not available"); 1.77 + return _env; 1.78 + } 1.79 + 1.80 + // The SharkBuilder that is used to build LLVM IR. 1.81 + protected: 1.82 + SharkBuilder* builder() const { 1.83 + return _builder; 1.84 + } 1.85 + 1.86 + // Pointer to this thread's JavaThread object. This is not 1.87 + // available until a short way into SharkFunction creation 1.88 + // so a setter is required. Assertions are used to enforce 1.89 + // invariance. 1.90 + protected: 1.91 + llvm::Value* thread() const { 1.92 + assert(_thread != NULL, "thread not available"); 1.93 + return _thread; 1.94 + } 1.95 + void set_thread(llvm::Value* thread) { 1.96 + assert(_thread == NULL, "thread already set"); 1.97 + _thread = thread; 1.98 + } 1.99 + 1.100 + // Objects that handle various aspects of the compilation. 1.101 + protected: 1.102 + DebugInformationRecorder* debug_info() const { 1.103 + return env()->debug_info(); 1.104 + } 1.105 + SharkCodeBuffer* code_buffer() const { 1.106 + return builder()->code_buffer(); 1.107 + } 1.108 + 1.109 + public: 1.110 + Dependencies* dependencies() const { 1.111 + return env()->dependencies(); 1.112 + } 1.113 + 1.114 + // Commonly used classes 1.115 + protected: 1.116 + ciInstanceKlass* java_lang_Object_klass() const { 1.117 + return env()->Object_klass(); 1.118 + } 1.119 + ciInstanceKlass* java_lang_Throwable_klass() const { 1.120 + return env()->Throwable_klass(); 1.121 + } 1.122 +}; 1.123 + 1.124 +class SharkTargetInvariants : public SharkCompileInvariants { 1.125 + protected: 1.126 + SharkTargetInvariants(ciEnv* env, SharkBuilder* builder, ciTypeFlow* flow) 1.127 + : SharkCompileInvariants(env, builder), 1.128 + _target(flow->method()), 1.129 + _flow(flow), 1.130 + _max_monitors(count_monitors()) {} 1.131 + 1.132 + SharkTargetInvariants(const SharkCompileInvariants* parent, ciMethod* target) 1.133 + : SharkCompileInvariants(parent), 1.134 + _target(target), 1.135 + _flow(NULL), 1.136 + _max_monitors(count_monitors()) {} 1.137 + 1.138 + SharkTargetInvariants(const SharkTargetInvariants* parent) 1.139 + : SharkCompileInvariants(parent), 1.140 + _target(parent->_target), 1.141 + _flow(parent->_flow), 1.142 + _max_monitors(parent->_max_monitors) {} 1.143 + 1.144 + private: 1.145 + int count_monitors(); 1.146 + 1.147 + private: 1.148 + ciMethod* _target; 1.149 + ciTypeFlow* _flow; 1.150 + int _max_monitors; 1.151 + 1.152 + // The method being compiled. 1.153 + protected: 1.154 + ciMethod* target() const { 1.155 + return _target; 1.156 + } 1.157 + 1.158 + // Typeflow analysis of the method being compiled. 1.159 + protected: 1.160 + ciTypeFlow* flow() const { 1.161 + assert(_flow != NULL, "typeflow not available"); 1.162 + return _flow; 1.163 + } 1.164 + 1.165 + // Properties of the method. 1.166 + protected: 1.167 + int max_locals() const { 1.168 + return target()->max_locals(); 1.169 + } 1.170 + int max_stack() const { 1.171 + return target()->max_stack(); 1.172 + } 1.173 + int max_monitors() const { 1.174 + return _max_monitors; 1.175 + } 1.176 + int arg_size() const { 1.177 + return target()->arg_size(); 1.178 + } 1.179 + bool is_static() const { 1.180 + return target()->is_static(); 1.181 + } 1.182 + bool is_synchronized() const { 1.183 + return target()->is_synchronized(); 1.184 + } 1.185 +}; 1.186 + 1.187 +#endif // SHARE_VM_SHARK_SHARKINVARIANTS_HPP