Wed, 11 Aug 2010 05:51:21 -0700
6976186: integrate Shark HotSpot changes
Summary: Shark is a JIT compiler for Zero that uses the LLVM compiler infrastructure.
Reviewed-by: kvn, twisti
Contributed-by: Gary Benson <gbenson@redhat.com>
twisti@2047 | 1 | /* |
twisti@2047 | 2 | * Copyright (c) 1999, 2007, Oracle and/or its affiliates. All rights reserved. |
twisti@2047 | 3 | * Copyright 2008, 2009 Red Hat, Inc. |
twisti@2047 | 4 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
twisti@2047 | 5 | * |
twisti@2047 | 6 | * This code is free software; you can redistribute it and/or modify it |
twisti@2047 | 7 | * under the terms of the GNU General Public License version 2 only, as |
twisti@2047 | 8 | * published by the Free Software Foundation. |
twisti@2047 | 9 | * |
twisti@2047 | 10 | * This code is distributed in the hope that it will be useful, but WITHOUT |
twisti@2047 | 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
twisti@2047 | 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
twisti@2047 | 13 | * version 2 for more details (a copy is included in the LICENSE file that |
twisti@2047 | 14 | * accompanied this code). |
twisti@2047 | 15 | * |
twisti@2047 | 16 | * You should have received a copy of the GNU General Public License version |
twisti@2047 | 17 | * 2 along with this work; if not, write to the Free Software Foundation, |
twisti@2047 | 18 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
twisti@2047 | 19 | * |
twisti@2047 | 20 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
twisti@2047 | 21 | * or visit www.oracle.com if you need additional information or have any |
twisti@2047 | 22 | * questions. |
twisti@2047 | 23 | * |
twisti@2047 | 24 | */ |
twisti@2047 | 25 | |
twisti@2047 | 26 | // Class hierarchy: |
twisti@2047 | 27 | // - SharkStateScanner |
twisti@2047 | 28 | // - SharkCacherDecacher |
twisti@2047 | 29 | // - SharkDecacher |
twisti@2047 | 30 | // - SharkJavaCallDecacher |
twisti@2047 | 31 | // - SharkVMCallDecacher |
twisti@2047 | 32 | // - SharkTrapDecacher |
twisti@2047 | 33 | // - SharkCacher |
twisti@2047 | 34 | // - SharkJavaCallCacher |
twisti@2047 | 35 | // - SharkVMCallCacher |
twisti@2047 | 36 | // - SharkFunctionEntryCacher |
twisti@2047 | 37 | // - SharkNormalEntryCacher |
twisti@2047 | 38 | // - SharkOSREntryCacher |
twisti@2047 | 39 | |
twisti@2047 | 40 | class SharkCacherDecacher : public SharkStateScanner { |
twisti@2047 | 41 | protected: |
twisti@2047 | 42 | SharkCacherDecacher(SharkFunction* function) |
twisti@2047 | 43 | : SharkStateScanner(function) {} |
twisti@2047 | 44 | |
twisti@2047 | 45 | // Helper |
twisti@2047 | 46 | protected: |
twisti@2047 | 47 | static int adjusted_offset(SharkValue* value, int offset) { |
twisti@2047 | 48 | if (value->is_two_word()) |
twisti@2047 | 49 | offset--; |
twisti@2047 | 50 | return offset; |
twisti@2047 | 51 | } |
twisti@2047 | 52 | }; |
twisti@2047 | 53 | |
twisti@2047 | 54 | class SharkDecacher : public SharkCacherDecacher { |
twisti@2047 | 55 | protected: |
twisti@2047 | 56 | SharkDecacher(SharkFunction* function, int bci) |
twisti@2047 | 57 | : SharkCacherDecacher(function), _bci(bci) {} |
twisti@2047 | 58 | |
twisti@2047 | 59 | private: |
twisti@2047 | 60 | int _bci; |
twisti@2047 | 61 | |
twisti@2047 | 62 | protected: |
twisti@2047 | 63 | int bci() const { |
twisti@2047 | 64 | return _bci; |
twisti@2047 | 65 | } |
twisti@2047 | 66 | |
twisti@2047 | 67 | private: |
twisti@2047 | 68 | int _pc_offset; |
twisti@2047 | 69 | OopMap* _oopmap; |
twisti@2047 | 70 | GrowableArray<ScopeValue*>* _exparray; |
twisti@2047 | 71 | GrowableArray<MonitorValue*>* _monarray; |
twisti@2047 | 72 | GrowableArray<ScopeValue*>* _locarray; |
twisti@2047 | 73 | |
twisti@2047 | 74 | private: |
twisti@2047 | 75 | int pc_offset() const { |
twisti@2047 | 76 | return _pc_offset; |
twisti@2047 | 77 | } |
twisti@2047 | 78 | OopMap* oopmap() const { |
twisti@2047 | 79 | return _oopmap; |
twisti@2047 | 80 | } |
twisti@2047 | 81 | GrowableArray<ScopeValue*>* exparray() const { |
twisti@2047 | 82 | return _exparray; |
twisti@2047 | 83 | } |
twisti@2047 | 84 | GrowableArray<MonitorValue*>* monarray() const { |
twisti@2047 | 85 | return _monarray; |
twisti@2047 | 86 | } |
twisti@2047 | 87 | GrowableArray<ScopeValue*>* locarray() const { |
twisti@2047 | 88 | return _locarray; |
twisti@2047 | 89 | } |
twisti@2047 | 90 | |
twisti@2047 | 91 | // Callbacks |
twisti@2047 | 92 | protected: |
twisti@2047 | 93 | void start_frame(); |
twisti@2047 | 94 | |
twisti@2047 | 95 | void start_stack(int stack_depth); |
twisti@2047 | 96 | void process_stack_slot(int index, SharkValue** value, int offset); |
twisti@2047 | 97 | |
twisti@2047 | 98 | void start_monitors(int num_monitors); |
twisti@2047 | 99 | void process_monitor(int index, int box_offset, int obj_offset); |
twisti@2047 | 100 | |
twisti@2047 | 101 | void process_oop_tmp_slot(llvm::Value** value, int offset); |
twisti@2047 | 102 | void process_method_slot(llvm::Value** value, int offset); |
twisti@2047 | 103 | void process_pc_slot(int offset); |
twisti@2047 | 104 | |
twisti@2047 | 105 | void start_locals(); |
twisti@2047 | 106 | void process_local_slot(int index, SharkValue** value, int offset); |
twisti@2047 | 107 | |
twisti@2047 | 108 | void end_frame(); |
twisti@2047 | 109 | |
twisti@2047 | 110 | // oopmap and debuginfo helpers |
twisti@2047 | 111 | private: |
twisti@2047 | 112 | static int oopmap_slot_munge(int offset) { |
twisti@2047 | 113 | return SharkStack::oopmap_slot_munge(offset); |
twisti@2047 | 114 | } |
twisti@2047 | 115 | static VMReg slot2reg(int offset) { |
twisti@2047 | 116 | return SharkStack::slot2reg(offset); |
twisti@2047 | 117 | } |
twisti@2047 | 118 | static Location slot2loc(int offset, Location::Type type) { |
twisti@2047 | 119 | return Location::new_stk_loc(type, offset * wordSize); |
twisti@2047 | 120 | } |
twisti@2047 | 121 | static LocationValue* slot2lv(int offset, Location::Type type) { |
twisti@2047 | 122 | return new LocationValue(slot2loc(offset, type)); |
twisti@2047 | 123 | } |
twisti@2047 | 124 | static Location::Type location_type(SharkValue** addr, bool maybe_two_word) { |
twisti@2047 | 125 | // low addresses this end |
twisti@2047 | 126 | // Type 32-bit 64-bit |
twisti@2047 | 127 | // ---------------------------------------------------- |
twisti@2047 | 128 | // stack[0] local[3] jobject oop oop |
twisti@2047 | 129 | // stack[1] local[2] NULL normal lng |
twisti@2047 | 130 | // stack[2] local[1] jlong normal invalid |
twisti@2047 | 131 | // stack[3] local[0] jint normal normal |
twisti@2047 | 132 | // |
twisti@2047 | 133 | // high addresses this end |
twisti@2047 | 134 | |
twisti@2047 | 135 | SharkValue *value = *addr; |
twisti@2047 | 136 | if (value) { |
twisti@2047 | 137 | if (value->is_jobject()) |
twisti@2047 | 138 | return Location::oop; |
twisti@2047 | 139 | #ifdef _LP64 |
twisti@2047 | 140 | if (value->is_two_word()) |
twisti@2047 | 141 | return Location::invalid; |
twisti@2047 | 142 | #endif // _LP64 |
twisti@2047 | 143 | return Location::normal; |
twisti@2047 | 144 | } |
twisti@2047 | 145 | else { |
twisti@2047 | 146 | if (maybe_two_word) { |
twisti@2047 | 147 | value = *(addr - 1); |
twisti@2047 | 148 | if (value && value->is_two_word()) { |
twisti@2047 | 149 | #ifdef _LP64 |
twisti@2047 | 150 | if (value->is_jlong()) |
twisti@2047 | 151 | return Location::lng; |
twisti@2047 | 152 | if (value->is_jdouble()) |
twisti@2047 | 153 | return Location::dbl; |
twisti@2047 | 154 | ShouldNotReachHere(); |
twisti@2047 | 155 | #else |
twisti@2047 | 156 | return Location::normal; |
twisti@2047 | 157 | #endif // _LP64 |
twisti@2047 | 158 | } |
twisti@2047 | 159 | } |
twisti@2047 | 160 | return Location::invalid; |
twisti@2047 | 161 | } |
twisti@2047 | 162 | } |
twisti@2047 | 163 | |
twisti@2047 | 164 | // Stack slot helpers |
twisti@2047 | 165 | protected: |
twisti@2047 | 166 | virtual bool stack_slot_needs_write(int index, SharkValue* value) = 0; |
twisti@2047 | 167 | virtual bool stack_slot_needs_oopmap(int index, SharkValue* value) = 0; |
twisti@2047 | 168 | virtual bool stack_slot_needs_debuginfo(int index, SharkValue* value) = 0; |
twisti@2047 | 169 | |
twisti@2047 | 170 | static Location::Type stack_location_type(int index, SharkValue** addr) { |
twisti@2047 | 171 | return location_type(addr, *addr == NULL); |
twisti@2047 | 172 | } |
twisti@2047 | 173 | |
twisti@2047 | 174 | // Local slot helpers |
twisti@2047 | 175 | protected: |
twisti@2047 | 176 | virtual bool local_slot_needs_write(int index, SharkValue* value) = 0; |
twisti@2047 | 177 | virtual bool local_slot_needs_oopmap(int index, SharkValue* value) = 0; |
twisti@2047 | 178 | virtual bool local_slot_needs_debuginfo(int index, SharkValue* value) = 0; |
twisti@2047 | 179 | |
twisti@2047 | 180 | static Location::Type local_location_type(int index, SharkValue** addr) { |
twisti@2047 | 181 | return location_type(addr, index > 0); |
twisti@2047 | 182 | } |
twisti@2047 | 183 | |
twisti@2047 | 184 | // Writer helper |
twisti@2047 | 185 | protected: |
twisti@2047 | 186 | void write_value_to_frame(const llvm::Type* type, |
twisti@2047 | 187 | llvm::Value* value, |
twisti@2047 | 188 | int offset); |
twisti@2047 | 189 | }; |
twisti@2047 | 190 | |
twisti@2047 | 191 | class SharkJavaCallDecacher : public SharkDecacher { |
twisti@2047 | 192 | public: |
twisti@2047 | 193 | SharkJavaCallDecacher(SharkFunction* function, int bci, ciMethod* callee) |
twisti@2047 | 194 | : SharkDecacher(function, bci), _callee(callee) {} |
twisti@2047 | 195 | |
twisti@2047 | 196 | private: |
twisti@2047 | 197 | ciMethod* _callee; |
twisti@2047 | 198 | |
twisti@2047 | 199 | protected: |
twisti@2047 | 200 | ciMethod* callee() const { |
twisti@2047 | 201 | return _callee; |
twisti@2047 | 202 | } |
twisti@2047 | 203 | |
twisti@2047 | 204 | // Stack slot helpers |
twisti@2047 | 205 | protected: |
twisti@2047 | 206 | bool stack_slot_needs_write(int index, SharkValue* value) { |
twisti@2047 | 207 | return value && (index < callee()->arg_size() || value->is_jobject()); |
twisti@2047 | 208 | } |
twisti@2047 | 209 | bool stack_slot_needs_oopmap(int index, SharkValue* value) { |
twisti@2047 | 210 | return value && value->is_jobject() && index >= callee()->arg_size(); |
twisti@2047 | 211 | } |
twisti@2047 | 212 | bool stack_slot_needs_debuginfo(int index, SharkValue* value) { |
twisti@2047 | 213 | return index >= callee()->arg_size(); |
twisti@2047 | 214 | } |
twisti@2047 | 215 | |
twisti@2047 | 216 | // Local slot helpers |
twisti@2047 | 217 | protected: |
twisti@2047 | 218 | bool local_slot_needs_write(int index, SharkValue* value) { |
twisti@2047 | 219 | return value && value->is_jobject(); |
twisti@2047 | 220 | } |
twisti@2047 | 221 | bool local_slot_needs_oopmap(int index, SharkValue* value) { |
twisti@2047 | 222 | return value && value->is_jobject(); |
twisti@2047 | 223 | } |
twisti@2047 | 224 | bool local_slot_needs_debuginfo(int index, SharkValue* value) { |
twisti@2047 | 225 | return true; |
twisti@2047 | 226 | } |
twisti@2047 | 227 | }; |
twisti@2047 | 228 | |
twisti@2047 | 229 | class SharkVMCallDecacher : public SharkDecacher { |
twisti@2047 | 230 | public: |
twisti@2047 | 231 | SharkVMCallDecacher(SharkFunction* function, int bci) |
twisti@2047 | 232 | : SharkDecacher(function, bci) {} |
twisti@2047 | 233 | |
twisti@2047 | 234 | // Stack slot helpers |
twisti@2047 | 235 | protected: |
twisti@2047 | 236 | bool stack_slot_needs_write(int index, SharkValue* value) { |
twisti@2047 | 237 | return value && value->is_jobject(); |
twisti@2047 | 238 | } |
twisti@2047 | 239 | bool stack_slot_needs_oopmap(int index, SharkValue* value) { |
twisti@2047 | 240 | return value && value->is_jobject(); |
twisti@2047 | 241 | } |
twisti@2047 | 242 | bool stack_slot_needs_debuginfo(int index, SharkValue* value) { |
twisti@2047 | 243 | return true; |
twisti@2047 | 244 | } |
twisti@2047 | 245 | |
twisti@2047 | 246 | // Local slot helpers |
twisti@2047 | 247 | protected: |
twisti@2047 | 248 | bool local_slot_needs_write(int index, SharkValue* value) { |
twisti@2047 | 249 | return value && value->is_jobject(); |
twisti@2047 | 250 | } |
twisti@2047 | 251 | bool local_slot_needs_oopmap(int index, SharkValue* value) { |
twisti@2047 | 252 | return value && value->is_jobject(); |
twisti@2047 | 253 | } |
twisti@2047 | 254 | bool local_slot_needs_debuginfo(int index, SharkValue* value) { |
twisti@2047 | 255 | return true; |
twisti@2047 | 256 | } |
twisti@2047 | 257 | }; |
twisti@2047 | 258 | |
twisti@2047 | 259 | class SharkTrapDecacher : public SharkDecacher { |
twisti@2047 | 260 | public: |
twisti@2047 | 261 | SharkTrapDecacher(SharkFunction* function, int bci) |
twisti@2047 | 262 | : SharkDecacher(function, bci) {} |
twisti@2047 | 263 | |
twisti@2047 | 264 | // Stack slot helpers |
twisti@2047 | 265 | protected: |
twisti@2047 | 266 | bool stack_slot_needs_write(int index, SharkValue* value) { |
twisti@2047 | 267 | return value != NULL; |
twisti@2047 | 268 | } |
twisti@2047 | 269 | bool stack_slot_needs_oopmap(int index, SharkValue* value) { |
twisti@2047 | 270 | return value && value->is_jobject(); |
twisti@2047 | 271 | } |
twisti@2047 | 272 | bool stack_slot_needs_debuginfo(int index, SharkValue* value) { |
twisti@2047 | 273 | return true; |
twisti@2047 | 274 | } |
twisti@2047 | 275 | |
twisti@2047 | 276 | // Local slot helpers |
twisti@2047 | 277 | protected: |
twisti@2047 | 278 | bool local_slot_needs_write(int index, SharkValue* value) { |
twisti@2047 | 279 | return value != NULL; |
twisti@2047 | 280 | } |
twisti@2047 | 281 | bool local_slot_needs_oopmap(int index, SharkValue* value) { |
twisti@2047 | 282 | return value && value->is_jobject(); |
twisti@2047 | 283 | } |
twisti@2047 | 284 | bool local_slot_needs_debuginfo(int index, SharkValue* value) { |
twisti@2047 | 285 | return true; |
twisti@2047 | 286 | } |
twisti@2047 | 287 | }; |
twisti@2047 | 288 | |
twisti@2047 | 289 | class SharkCacher : public SharkCacherDecacher { |
twisti@2047 | 290 | protected: |
twisti@2047 | 291 | SharkCacher(SharkFunction* function) |
twisti@2047 | 292 | : SharkCacherDecacher(function) {} |
twisti@2047 | 293 | |
twisti@2047 | 294 | // Callbacks |
twisti@2047 | 295 | protected: |
twisti@2047 | 296 | void process_stack_slot(int index, SharkValue** value, int offset); |
twisti@2047 | 297 | |
twisti@2047 | 298 | void process_oop_tmp_slot(llvm::Value** value, int offset); |
twisti@2047 | 299 | virtual void process_method_slot(llvm::Value** value, int offset); |
twisti@2047 | 300 | |
twisti@2047 | 301 | virtual void process_local_slot(int index, SharkValue** value, int offset); |
twisti@2047 | 302 | |
twisti@2047 | 303 | // Stack slot helper |
twisti@2047 | 304 | protected: |
twisti@2047 | 305 | virtual bool stack_slot_needs_read(int index, SharkValue* value) = 0; |
twisti@2047 | 306 | |
twisti@2047 | 307 | // Local slot helper |
twisti@2047 | 308 | protected: |
twisti@2047 | 309 | virtual bool local_slot_needs_read(int index, SharkValue* value) { |
twisti@2047 | 310 | return value && value->is_jobject(); |
twisti@2047 | 311 | } |
twisti@2047 | 312 | |
twisti@2047 | 313 | // Writer helper |
twisti@2047 | 314 | protected: |
twisti@2047 | 315 | llvm::Value* read_value_from_frame(const llvm::Type* type, int offset); |
twisti@2047 | 316 | }; |
twisti@2047 | 317 | |
twisti@2047 | 318 | class SharkJavaCallCacher : public SharkCacher { |
twisti@2047 | 319 | public: |
twisti@2047 | 320 | SharkJavaCallCacher(SharkFunction* function, ciMethod* callee) |
twisti@2047 | 321 | : SharkCacher(function), _callee(callee) {} |
twisti@2047 | 322 | |
twisti@2047 | 323 | private: |
twisti@2047 | 324 | ciMethod* _callee; |
twisti@2047 | 325 | |
twisti@2047 | 326 | protected: |
twisti@2047 | 327 | ciMethod* callee() const { |
twisti@2047 | 328 | return _callee; |
twisti@2047 | 329 | } |
twisti@2047 | 330 | |
twisti@2047 | 331 | // Stack slot helper |
twisti@2047 | 332 | protected: |
twisti@2047 | 333 | bool stack_slot_needs_read(int index, SharkValue* value) { |
twisti@2047 | 334 | return value && (index < callee()->return_type()->size() || |
twisti@2047 | 335 | value->is_jobject()); |
twisti@2047 | 336 | } |
twisti@2047 | 337 | }; |
twisti@2047 | 338 | |
twisti@2047 | 339 | class SharkVMCallCacher : public SharkCacher { |
twisti@2047 | 340 | public: |
twisti@2047 | 341 | SharkVMCallCacher(SharkFunction* function) |
twisti@2047 | 342 | : SharkCacher(function) {} |
twisti@2047 | 343 | |
twisti@2047 | 344 | // Stack slot helper |
twisti@2047 | 345 | protected: |
twisti@2047 | 346 | bool stack_slot_needs_read(int index, SharkValue* value) { |
twisti@2047 | 347 | return value && value->is_jobject(); |
twisti@2047 | 348 | } |
twisti@2047 | 349 | }; |
twisti@2047 | 350 | |
twisti@2047 | 351 | class SharkFunctionEntryCacher : public SharkCacher { |
twisti@2047 | 352 | public: |
twisti@2047 | 353 | SharkFunctionEntryCacher(SharkFunction* function, llvm::Value* method) |
twisti@2047 | 354 | : SharkCacher(function), _method(method) {} |
twisti@2047 | 355 | |
twisti@2047 | 356 | private: |
twisti@2047 | 357 | llvm::Value* _method; |
twisti@2047 | 358 | |
twisti@2047 | 359 | private: |
twisti@2047 | 360 | llvm::Value* method() const { |
twisti@2047 | 361 | return _method; |
twisti@2047 | 362 | } |
twisti@2047 | 363 | |
twisti@2047 | 364 | // Method slot callback |
twisti@2047 | 365 | protected: |
twisti@2047 | 366 | void process_method_slot(llvm::Value** value, int offset); |
twisti@2047 | 367 | |
twisti@2047 | 368 | // Stack slot helper |
twisti@2047 | 369 | protected: |
twisti@2047 | 370 | bool stack_slot_needs_read(int index, SharkValue* value) { |
twisti@2047 | 371 | ShouldNotReachHere(); // entry block shouldn't have stack |
twisti@2047 | 372 | } |
twisti@2047 | 373 | |
twisti@2047 | 374 | // Local slot helper |
twisti@2047 | 375 | protected: |
twisti@2047 | 376 | bool local_slot_needs_read(int index, SharkValue* value) { |
twisti@2047 | 377 | return value != NULL; |
twisti@2047 | 378 | } |
twisti@2047 | 379 | }; |
twisti@2047 | 380 | |
twisti@2047 | 381 | class SharkNormalEntryCacher : public SharkFunctionEntryCacher { |
twisti@2047 | 382 | public: |
twisti@2047 | 383 | SharkNormalEntryCacher(SharkFunction* function, llvm::Value* method) |
twisti@2047 | 384 | : SharkFunctionEntryCacher(function, method) {} |
twisti@2047 | 385 | }; |
twisti@2047 | 386 | |
twisti@2047 | 387 | class SharkOSREntryCacher : public SharkFunctionEntryCacher { |
twisti@2047 | 388 | public: |
twisti@2047 | 389 | SharkOSREntryCacher(SharkFunction* function, |
twisti@2047 | 390 | llvm::Value* method, |
twisti@2047 | 391 | llvm::Value* osr_buf) |
twisti@2047 | 392 | : SharkFunctionEntryCacher(function, method), |
twisti@2047 | 393 | _osr_buf( |
twisti@2047 | 394 | builder()->CreateBitCast( |
twisti@2047 | 395 | osr_buf, |
twisti@2047 | 396 | llvm::PointerType::getUnqual( |
twisti@2047 | 397 | llvm::ArrayType::get( |
twisti@2047 | 398 | SharkType::intptr_type(), |
twisti@2047 | 399 | max_locals() + max_monitors() * 2)))) {} |
twisti@2047 | 400 | |
twisti@2047 | 401 | private: |
twisti@2047 | 402 | llvm::Value* _osr_buf; |
twisti@2047 | 403 | |
twisti@2047 | 404 | private: |
twisti@2047 | 405 | llvm::Value* osr_buf() const { |
twisti@2047 | 406 | return _osr_buf; |
twisti@2047 | 407 | } |
twisti@2047 | 408 | |
twisti@2047 | 409 | // Callbacks |
twisti@2047 | 410 | protected: |
twisti@2047 | 411 | void process_monitor(int index, int box_offset, int obj_offset); |
twisti@2047 | 412 | void process_local_slot(int index, SharkValue** value, int offset); |
twisti@2047 | 413 | |
twisti@2047 | 414 | // Helper |
twisti@2047 | 415 | private: |
twisti@2047 | 416 | llvm::Value* CreateAddressOfOSRBufEntry(int offset, const llvm::Type* type); |
twisti@2047 | 417 | }; |