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