1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/vm/shark/sharkCacheDecache.hpp Wed Aug 11 05:51:21 2010 -0700 1.3 @@ -0,0 +1,417 @@ 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 hierarchy: 1.30 +// - SharkStateScanner 1.31 +// - SharkCacherDecacher 1.32 +// - SharkDecacher 1.33 +// - SharkJavaCallDecacher 1.34 +// - SharkVMCallDecacher 1.35 +// - SharkTrapDecacher 1.36 +// - SharkCacher 1.37 +// - SharkJavaCallCacher 1.38 +// - SharkVMCallCacher 1.39 +// - SharkFunctionEntryCacher 1.40 +// - SharkNormalEntryCacher 1.41 +// - SharkOSREntryCacher 1.42 + 1.43 +class SharkCacherDecacher : public SharkStateScanner { 1.44 + protected: 1.45 + SharkCacherDecacher(SharkFunction* function) 1.46 + : SharkStateScanner(function) {} 1.47 + 1.48 + // Helper 1.49 + protected: 1.50 + static int adjusted_offset(SharkValue* value, int offset) { 1.51 + if (value->is_two_word()) 1.52 + offset--; 1.53 + return offset; 1.54 + } 1.55 +}; 1.56 + 1.57 +class SharkDecacher : public SharkCacherDecacher { 1.58 + protected: 1.59 + SharkDecacher(SharkFunction* function, int bci) 1.60 + : SharkCacherDecacher(function), _bci(bci) {} 1.61 + 1.62 + private: 1.63 + int _bci; 1.64 + 1.65 + protected: 1.66 + int bci() const { 1.67 + return _bci; 1.68 + } 1.69 + 1.70 + private: 1.71 + int _pc_offset; 1.72 + OopMap* _oopmap; 1.73 + GrowableArray<ScopeValue*>* _exparray; 1.74 + GrowableArray<MonitorValue*>* _monarray; 1.75 + GrowableArray<ScopeValue*>* _locarray; 1.76 + 1.77 + private: 1.78 + int pc_offset() const { 1.79 + return _pc_offset; 1.80 + } 1.81 + OopMap* oopmap() const { 1.82 + return _oopmap; 1.83 + } 1.84 + GrowableArray<ScopeValue*>* exparray() const { 1.85 + return _exparray; 1.86 + } 1.87 + GrowableArray<MonitorValue*>* monarray() const { 1.88 + return _monarray; 1.89 + } 1.90 + GrowableArray<ScopeValue*>* locarray() const { 1.91 + return _locarray; 1.92 + } 1.93 + 1.94 + // Callbacks 1.95 + protected: 1.96 + void start_frame(); 1.97 + 1.98 + void start_stack(int stack_depth); 1.99 + void process_stack_slot(int index, SharkValue** value, int offset); 1.100 + 1.101 + void start_monitors(int num_monitors); 1.102 + void process_monitor(int index, int box_offset, int obj_offset); 1.103 + 1.104 + void process_oop_tmp_slot(llvm::Value** value, int offset); 1.105 + void process_method_slot(llvm::Value** value, int offset); 1.106 + void process_pc_slot(int offset); 1.107 + 1.108 + void start_locals(); 1.109 + void process_local_slot(int index, SharkValue** value, int offset); 1.110 + 1.111 + void end_frame(); 1.112 + 1.113 + // oopmap and debuginfo helpers 1.114 + private: 1.115 + static int oopmap_slot_munge(int offset) { 1.116 + return SharkStack::oopmap_slot_munge(offset); 1.117 + } 1.118 + static VMReg slot2reg(int offset) { 1.119 + return SharkStack::slot2reg(offset); 1.120 + } 1.121 + static Location slot2loc(int offset, Location::Type type) { 1.122 + return Location::new_stk_loc(type, offset * wordSize); 1.123 + } 1.124 + static LocationValue* slot2lv(int offset, Location::Type type) { 1.125 + return new LocationValue(slot2loc(offset, type)); 1.126 + } 1.127 + static Location::Type location_type(SharkValue** addr, bool maybe_two_word) { 1.128 + // low addresses this end 1.129 + // Type 32-bit 64-bit 1.130 + // ---------------------------------------------------- 1.131 + // stack[0] local[3] jobject oop oop 1.132 + // stack[1] local[2] NULL normal lng 1.133 + // stack[2] local[1] jlong normal invalid 1.134 + // stack[3] local[0] jint normal normal 1.135 + // 1.136 + // high addresses this end 1.137 + 1.138 + SharkValue *value = *addr; 1.139 + if (value) { 1.140 + if (value->is_jobject()) 1.141 + return Location::oop; 1.142 +#ifdef _LP64 1.143 + if (value->is_two_word()) 1.144 + return Location::invalid; 1.145 +#endif // _LP64 1.146 + return Location::normal; 1.147 + } 1.148 + else { 1.149 + if (maybe_two_word) { 1.150 + value = *(addr - 1); 1.151 + if (value && value->is_two_word()) { 1.152 +#ifdef _LP64 1.153 + if (value->is_jlong()) 1.154 + return Location::lng; 1.155 + if (value->is_jdouble()) 1.156 + return Location::dbl; 1.157 + ShouldNotReachHere(); 1.158 +#else 1.159 + return Location::normal; 1.160 +#endif // _LP64 1.161 + } 1.162 + } 1.163 + return Location::invalid; 1.164 + } 1.165 + } 1.166 + 1.167 + // Stack slot helpers 1.168 + protected: 1.169 + virtual bool stack_slot_needs_write(int index, SharkValue* value) = 0; 1.170 + virtual bool stack_slot_needs_oopmap(int index, SharkValue* value) = 0; 1.171 + virtual bool stack_slot_needs_debuginfo(int index, SharkValue* value) = 0; 1.172 + 1.173 + static Location::Type stack_location_type(int index, SharkValue** addr) { 1.174 + return location_type(addr, *addr == NULL); 1.175 + } 1.176 + 1.177 + // Local slot helpers 1.178 + protected: 1.179 + virtual bool local_slot_needs_write(int index, SharkValue* value) = 0; 1.180 + virtual bool local_slot_needs_oopmap(int index, SharkValue* value) = 0; 1.181 + virtual bool local_slot_needs_debuginfo(int index, SharkValue* value) = 0; 1.182 + 1.183 + static Location::Type local_location_type(int index, SharkValue** addr) { 1.184 + return location_type(addr, index > 0); 1.185 + } 1.186 + 1.187 + // Writer helper 1.188 + protected: 1.189 + void write_value_to_frame(const llvm::Type* type, 1.190 + llvm::Value* value, 1.191 + int offset); 1.192 +}; 1.193 + 1.194 +class SharkJavaCallDecacher : public SharkDecacher { 1.195 + public: 1.196 + SharkJavaCallDecacher(SharkFunction* function, int bci, ciMethod* callee) 1.197 + : SharkDecacher(function, bci), _callee(callee) {} 1.198 + 1.199 + private: 1.200 + ciMethod* _callee; 1.201 + 1.202 + protected: 1.203 + ciMethod* callee() const { 1.204 + return _callee; 1.205 + } 1.206 + 1.207 + // Stack slot helpers 1.208 + protected: 1.209 + bool stack_slot_needs_write(int index, SharkValue* value) { 1.210 + return value && (index < callee()->arg_size() || value->is_jobject()); 1.211 + } 1.212 + bool stack_slot_needs_oopmap(int index, SharkValue* value) { 1.213 + return value && value->is_jobject() && index >= callee()->arg_size(); 1.214 + } 1.215 + bool stack_slot_needs_debuginfo(int index, SharkValue* value) { 1.216 + return index >= callee()->arg_size(); 1.217 + } 1.218 + 1.219 + // Local slot helpers 1.220 + protected: 1.221 + bool local_slot_needs_write(int index, SharkValue* value) { 1.222 + return value && value->is_jobject(); 1.223 + } 1.224 + bool local_slot_needs_oopmap(int index, SharkValue* value) { 1.225 + return value && value->is_jobject(); 1.226 + } 1.227 + bool local_slot_needs_debuginfo(int index, SharkValue* value) { 1.228 + return true; 1.229 + } 1.230 +}; 1.231 + 1.232 +class SharkVMCallDecacher : public SharkDecacher { 1.233 + public: 1.234 + SharkVMCallDecacher(SharkFunction* function, int bci) 1.235 + : SharkDecacher(function, bci) {} 1.236 + 1.237 + // Stack slot helpers 1.238 + protected: 1.239 + bool stack_slot_needs_write(int index, SharkValue* value) { 1.240 + return value && value->is_jobject(); 1.241 + } 1.242 + bool stack_slot_needs_oopmap(int index, SharkValue* value) { 1.243 + return value && value->is_jobject(); 1.244 + } 1.245 + bool stack_slot_needs_debuginfo(int index, SharkValue* value) { 1.246 + return true; 1.247 + } 1.248 + 1.249 + // Local slot helpers 1.250 + protected: 1.251 + bool local_slot_needs_write(int index, SharkValue* value) { 1.252 + return value && value->is_jobject(); 1.253 + } 1.254 + bool local_slot_needs_oopmap(int index, SharkValue* value) { 1.255 + return value && value->is_jobject(); 1.256 + } 1.257 + bool local_slot_needs_debuginfo(int index, SharkValue* value) { 1.258 + return true; 1.259 + } 1.260 +}; 1.261 + 1.262 +class SharkTrapDecacher : public SharkDecacher { 1.263 + public: 1.264 + SharkTrapDecacher(SharkFunction* function, int bci) 1.265 + : SharkDecacher(function, bci) {} 1.266 + 1.267 + // Stack slot helpers 1.268 + protected: 1.269 + bool stack_slot_needs_write(int index, SharkValue* value) { 1.270 + return value != NULL; 1.271 + } 1.272 + bool stack_slot_needs_oopmap(int index, SharkValue* value) { 1.273 + return value && value->is_jobject(); 1.274 + } 1.275 + bool stack_slot_needs_debuginfo(int index, SharkValue* value) { 1.276 + return true; 1.277 + } 1.278 + 1.279 + // Local slot helpers 1.280 + protected: 1.281 + bool local_slot_needs_write(int index, SharkValue* value) { 1.282 + return value != NULL; 1.283 + } 1.284 + bool local_slot_needs_oopmap(int index, SharkValue* value) { 1.285 + return value && value->is_jobject(); 1.286 + } 1.287 + bool local_slot_needs_debuginfo(int index, SharkValue* value) { 1.288 + return true; 1.289 + } 1.290 +}; 1.291 + 1.292 +class SharkCacher : public SharkCacherDecacher { 1.293 + protected: 1.294 + SharkCacher(SharkFunction* function) 1.295 + : SharkCacherDecacher(function) {} 1.296 + 1.297 + // Callbacks 1.298 + protected: 1.299 + void process_stack_slot(int index, SharkValue** value, int offset); 1.300 + 1.301 + void process_oop_tmp_slot(llvm::Value** value, int offset); 1.302 + virtual void process_method_slot(llvm::Value** value, int offset); 1.303 + 1.304 + virtual void process_local_slot(int index, SharkValue** value, int offset); 1.305 + 1.306 + // Stack slot helper 1.307 + protected: 1.308 + virtual bool stack_slot_needs_read(int index, SharkValue* value) = 0; 1.309 + 1.310 + // Local slot helper 1.311 + protected: 1.312 + virtual bool local_slot_needs_read(int index, SharkValue* value) { 1.313 + return value && value->is_jobject(); 1.314 + } 1.315 + 1.316 + // Writer helper 1.317 + protected: 1.318 + llvm::Value* read_value_from_frame(const llvm::Type* type, int offset); 1.319 +}; 1.320 + 1.321 +class SharkJavaCallCacher : public SharkCacher { 1.322 + public: 1.323 + SharkJavaCallCacher(SharkFunction* function, ciMethod* callee) 1.324 + : SharkCacher(function), _callee(callee) {} 1.325 + 1.326 + private: 1.327 + ciMethod* _callee; 1.328 + 1.329 + protected: 1.330 + ciMethod* callee() const { 1.331 + return _callee; 1.332 + } 1.333 + 1.334 + // Stack slot helper 1.335 + protected: 1.336 + bool stack_slot_needs_read(int index, SharkValue* value) { 1.337 + return value && (index < callee()->return_type()->size() || 1.338 + value->is_jobject()); 1.339 + } 1.340 +}; 1.341 + 1.342 +class SharkVMCallCacher : public SharkCacher { 1.343 + public: 1.344 + SharkVMCallCacher(SharkFunction* function) 1.345 + : SharkCacher(function) {} 1.346 + 1.347 + // Stack slot helper 1.348 + protected: 1.349 + bool stack_slot_needs_read(int index, SharkValue* value) { 1.350 + return value && value->is_jobject(); 1.351 + } 1.352 +}; 1.353 + 1.354 +class SharkFunctionEntryCacher : public SharkCacher { 1.355 + public: 1.356 + SharkFunctionEntryCacher(SharkFunction* function, llvm::Value* method) 1.357 + : SharkCacher(function), _method(method) {} 1.358 + 1.359 + private: 1.360 + llvm::Value* _method; 1.361 + 1.362 + private: 1.363 + llvm::Value* method() const { 1.364 + return _method; 1.365 + } 1.366 + 1.367 + // Method slot callback 1.368 + protected: 1.369 + void process_method_slot(llvm::Value** value, int offset); 1.370 + 1.371 + // Stack slot helper 1.372 + protected: 1.373 + bool stack_slot_needs_read(int index, SharkValue* value) { 1.374 + ShouldNotReachHere(); // entry block shouldn't have stack 1.375 + } 1.376 + 1.377 + // Local slot helper 1.378 + protected: 1.379 + bool local_slot_needs_read(int index, SharkValue* value) { 1.380 + return value != NULL; 1.381 + } 1.382 +}; 1.383 + 1.384 +class SharkNormalEntryCacher : public SharkFunctionEntryCacher { 1.385 + public: 1.386 + SharkNormalEntryCacher(SharkFunction* function, llvm::Value* method) 1.387 + : SharkFunctionEntryCacher(function, method) {} 1.388 +}; 1.389 + 1.390 +class SharkOSREntryCacher : public SharkFunctionEntryCacher { 1.391 + public: 1.392 + SharkOSREntryCacher(SharkFunction* function, 1.393 + llvm::Value* method, 1.394 + llvm::Value* osr_buf) 1.395 + : SharkFunctionEntryCacher(function, method), 1.396 + _osr_buf( 1.397 + builder()->CreateBitCast( 1.398 + osr_buf, 1.399 + llvm::PointerType::getUnqual( 1.400 + llvm::ArrayType::get( 1.401 + SharkType::intptr_type(), 1.402 + max_locals() + max_monitors() * 2)))) {} 1.403 + 1.404 + private: 1.405 + llvm::Value* _osr_buf; 1.406 + 1.407 + private: 1.408 + llvm::Value* osr_buf() const { 1.409 + return _osr_buf; 1.410 + } 1.411 + 1.412 + // Callbacks 1.413 + protected: 1.414 + void process_monitor(int index, int box_offset, int obj_offset); 1.415 + void process_local_slot(int index, SharkValue** value, int offset); 1.416 + 1.417 + // Helper 1.418 + private: 1.419 + llvm::Value* CreateAddressOfOSRBufEntry(int offset, const llvm::Type* type); 1.420 +};