1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/vm/shark/sharkBlock.hpp Wed Aug 11 05:51:21 2010 -0700 1.3 @@ -0,0 +1,281 @@ 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 +class SharkState; 1.30 + 1.31 +class SharkBlock : public SharkTargetInvariants { 1.32 + protected: 1.33 + SharkBlock(const SharkTargetInvariants* parent) 1.34 + : SharkTargetInvariants(parent), 1.35 + _iter(target()), 1.36 + _current_state(NULL) {} 1.37 + 1.38 + SharkBlock(const SharkCompileInvariants* parent, ciMethod* target) 1.39 + : SharkTargetInvariants(parent, target), 1.40 + _iter(target), 1.41 + _current_state(NULL) {} 1.42 + 1.43 + private: 1.44 + ciBytecodeStream _iter; 1.45 + SharkState* _current_state; 1.46 + 1.47 + public: 1.48 + ciBytecodeStream* iter() { 1.49 + return &_iter; 1.50 + } 1.51 + Bytecodes::Code bc() { 1.52 + return iter()->cur_bc(); 1.53 + } 1.54 + int bci() { 1.55 + return iter()->cur_bci(); 1.56 + } 1.57 + 1.58 + // Entry state 1.59 + protected: 1.60 + virtual SharkState* entry_state(); 1.61 + 1.62 + // Current state 1.63 + private: 1.64 + SharkState* initial_current_state(); 1.65 + 1.66 + public: 1.67 + SharkState* current_state() { 1.68 + if (_current_state == NULL) 1.69 + set_current_state(initial_current_state()); 1.70 + return _current_state; 1.71 + } 1.72 + 1.73 + protected: 1.74 + void set_current_state(SharkState* current_state) { 1.75 + _current_state = current_state; 1.76 + } 1.77 + 1.78 + // Local variables 1.79 + protected: 1.80 + SharkValue* local(int index) { 1.81 + SharkValue *value = current_state()->local(index); 1.82 + assert(value != NULL, "shouldn't be"); 1.83 + assert(value->is_one_word() || 1.84 + (index + 1 < max_locals() && 1.85 + current_state()->local(index + 1) == NULL), "should be"); 1.86 + return value; 1.87 + } 1.88 + void set_local(int index, SharkValue* value) { 1.89 + assert(value != NULL, "shouldn't be"); 1.90 + current_state()->set_local(index, value); 1.91 + if (value->is_two_word()) 1.92 + current_state()->set_local(index + 1, NULL); 1.93 + } 1.94 + 1.95 + // Expression stack (raw) 1.96 + protected: 1.97 + void xpush(SharkValue* value) { 1.98 + current_state()->push(value); 1.99 + } 1.100 + SharkValue* xpop() { 1.101 + return current_state()->pop(); 1.102 + } 1.103 + SharkValue* xstack(int slot) { 1.104 + SharkValue *value = current_state()->stack(slot); 1.105 + assert(value != NULL, "shouldn't be"); 1.106 + assert(value->is_one_word() || 1.107 + (slot > 0 && 1.108 + current_state()->stack(slot - 1) == NULL), "should be"); 1.109 + return value; 1.110 + } 1.111 + int xstack_depth() { 1.112 + return current_state()->stack_depth(); 1.113 + } 1.114 + 1.115 + // Expression stack (cooked) 1.116 + protected: 1.117 + void push(SharkValue* value) { 1.118 + assert(value != NULL, "shouldn't be"); 1.119 + xpush(value); 1.120 + if (value->is_two_word()) 1.121 + xpush(NULL); 1.122 + } 1.123 + SharkValue* pop() { 1.124 + int size = current_state()->stack(0) == NULL ? 2 : 1; 1.125 + if (size == 2) 1.126 + xpop(); 1.127 + SharkValue *value = xpop(); 1.128 + assert(value && value->size() == size, "should be"); 1.129 + return value; 1.130 + } 1.131 + SharkValue* pop_result(BasicType type) { 1.132 + SharkValue *result = pop(); 1.133 + 1.134 +#ifdef ASSERT 1.135 + switch (result->basic_type()) { 1.136 + case T_BOOLEAN: 1.137 + case T_BYTE: 1.138 + case T_CHAR: 1.139 + case T_SHORT: 1.140 + assert(type == T_INT, "type mismatch"); 1.141 + break; 1.142 + 1.143 + case T_ARRAY: 1.144 + assert(type == T_OBJECT, "type mismatch"); 1.145 + break; 1.146 + 1.147 + default: 1.148 + assert(result->basic_type() == type, "type mismatch"); 1.149 + } 1.150 +#endif // ASSERT 1.151 + 1.152 + return result; 1.153 + } 1.154 + 1.155 + // Code generation 1.156 + public: 1.157 + virtual void emit_IR(); 1.158 + 1.159 + protected: 1.160 + void parse_bytecode(int start, int limit); 1.161 + 1.162 + // Helpers 1.163 + protected: 1.164 + virtual void do_zero_check(SharkValue* value); 1.165 + 1.166 + // Zero checking 1.167 + protected: 1.168 + void check_null(SharkValue* object) { 1.169 + zero_check(object); 1.170 + } 1.171 + void check_divide_by_zero(SharkValue* value) { 1.172 + zero_check(value); 1.173 + } 1.174 + private: 1.175 + void zero_check(SharkValue* value) { 1.176 + if (!value->zero_checked()) 1.177 + do_zero_check(value); 1.178 + } 1.179 + 1.180 + // Safepoints 1.181 + protected: 1.182 + virtual void maybe_add_backedge_safepoint(); 1.183 + 1.184 + // Traps 1.185 + protected: 1.186 + virtual bool has_trap(); 1.187 + virtual int trap_request(); 1.188 + virtual int trap_bci(); 1.189 + virtual void do_trap(int trap_request); 1.190 + 1.191 + // arraylength 1.192 + protected: 1.193 + virtual void do_arraylength(); 1.194 + 1.195 + // *aload and *astore 1.196 + protected: 1.197 + virtual void do_aload(BasicType basic_type); 1.198 + virtual void do_astore(BasicType basic_type); 1.199 + 1.200 + // *div and *rem 1.201 + private: 1.202 + void do_idiv() { 1.203 + do_div_or_rem(false, false); 1.204 + } 1.205 + void do_irem() { 1.206 + do_div_or_rem(false, true); 1.207 + } 1.208 + void do_ldiv() { 1.209 + do_div_or_rem(true, false); 1.210 + } 1.211 + void do_lrem() { 1.212 + do_div_or_rem(true, true); 1.213 + } 1.214 + void do_div_or_rem(bool is_long, bool is_rem); 1.215 + 1.216 + // get* and put* 1.217 + private: 1.218 + void do_getstatic() { 1.219 + do_field_access(true, false); 1.220 + } 1.221 + void do_getfield() { 1.222 + do_field_access(true, true); 1.223 + } 1.224 + void do_putstatic() { 1.225 + do_field_access(false, false); 1.226 + } 1.227 + void do_putfield() { 1.228 + do_field_access(false, true); 1.229 + } 1.230 + void do_field_access(bool is_get, bool is_field); 1.231 + 1.232 + // lcmp and [fd]cmp[lg] 1.233 + private: 1.234 + void do_lcmp(); 1.235 + void do_fcmp(bool is_double, bool unordered_is_greater); 1.236 + 1.237 + // *return and athrow 1.238 + protected: 1.239 + virtual void do_return(BasicType type); 1.240 + virtual void do_athrow(); 1.241 + 1.242 + // goto* 1.243 + protected: 1.244 + virtual void do_goto(); 1.245 + 1.246 + // jsr* and ret 1.247 + protected: 1.248 + virtual void do_jsr(); 1.249 + virtual void do_ret(); 1.250 + 1.251 + // if* 1.252 + protected: 1.253 + virtual void do_if(llvm::ICmpInst::Predicate p, SharkValue* b, SharkValue* a); 1.254 + 1.255 + // *switch 1.256 + protected: 1.257 + int switch_default_dest(); 1.258 + int switch_table_length(); 1.259 + int switch_key(int i); 1.260 + int switch_dest(int i); 1.261 + 1.262 + virtual void do_switch(); 1.263 + 1.264 + // invoke* 1.265 + protected: 1.266 + virtual void do_call(); 1.267 + 1.268 + // checkcast and instanceof 1.269 + protected: 1.270 + virtual void do_instance_check(); 1.271 + virtual bool maybe_do_instanceof_if(); 1.272 + 1.273 + // new and *newarray 1.274 + protected: 1.275 + virtual void do_new(); 1.276 + virtual void do_newarray(); 1.277 + virtual void do_anewarray(); 1.278 + virtual void do_multianewarray(); 1.279 + 1.280 + // monitorenter and monitorexit 1.281 + protected: 1.282 + virtual void do_monitorenter(); 1.283 + virtual void do_monitorexit(); 1.284 +};