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