src/share/vm/interpreter/oopMapCache.cpp

Tue, 03 Aug 2010 08:13:38 -0400

author
bobv
date
Tue, 03 Aug 2010 08:13:38 -0400
changeset 2036
126ea7725993
parent 1907
c18cbe5936b8
child 2314
f95d63e2154a
permissions
-rw-r--r--

6953477: Increase portability and flexibility of building Hotspot
Summary: A collection of portability improvements including shared code support for PPC, ARM platforms, software floating point, cross compilation support and improvements in error crash detail.
Reviewed-by: phh, never, coleenp, dholmes

duke@435 1 /*
trims@1907 2 * Copyright (c) 1997, 2008, Oracle and/or its affiliates. All rights reserved.
duke@435 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@435 4 *
duke@435 5 * This code is free software; you can redistribute it and/or modify it
duke@435 6 * under the terms of the GNU General Public License version 2 only, as
duke@435 7 * published by the Free Software Foundation.
duke@435 8 *
duke@435 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@435 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@435 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@435 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@435 13 * accompanied this code).
duke@435 14 *
duke@435 15 * You should have received a copy of the GNU General Public License version
duke@435 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@435 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@435 18 *
trims@1907 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1907 20 * or visit www.oracle.com if you need additional information or have any
trims@1907 21 * questions.
duke@435 22 *
duke@435 23 */
duke@435 24
duke@435 25 # include "incls/_precompiled.incl"
duke@435 26 # include "incls/_oopMapCache.cpp.incl"
duke@435 27
duke@435 28 class OopMapCacheEntry: private InterpreterOopMap {
duke@435 29 friend class InterpreterOopMap;
duke@435 30 friend class OopMapForCacheEntry;
duke@435 31 friend class OopMapCache;
duke@435 32 friend class VerifyClosure;
duke@435 33
duke@435 34 protected:
duke@435 35 // Initialization
duke@435 36 void fill(methodHandle method, int bci);
duke@435 37 // fills the bit mask for native calls
duke@435 38 void fill_for_native(methodHandle method);
duke@435 39 void set_mask(CellTypeState* vars, CellTypeState* stack, int stack_top);
duke@435 40
duke@435 41 // Deallocate bit masks and initialize fields
duke@435 42 void flush();
duke@435 43
duke@435 44 private:
duke@435 45 void allocate_bit_mask(); // allocates the bit mask on C heap f necessary
duke@435 46 void deallocate_bit_mask(); // allocates the bit mask on C heap f necessary
duke@435 47 bool verify_mask(CellTypeState *vars, CellTypeState *stack, int max_locals, int stack_top);
duke@435 48
duke@435 49 public:
duke@435 50 OopMapCacheEntry() : InterpreterOopMap() {
duke@435 51 #ifdef ASSERT
duke@435 52 _resource_allocate_bit_mask = false;
duke@435 53 #endif
duke@435 54 }
duke@435 55 };
duke@435 56
duke@435 57
duke@435 58 // Implementation of OopMapForCacheEntry
duke@435 59 // (subclass of GenerateOopMap, initializes an OopMapCacheEntry for a given method and bci)
duke@435 60
duke@435 61 class OopMapForCacheEntry: public GenerateOopMap {
duke@435 62 OopMapCacheEntry *_entry;
duke@435 63 int _bci;
duke@435 64 int _stack_top;
duke@435 65
duke@435 66 virtual bool report_results() const { return false; }
duke@435 67 virtual bool possible_gc_point (BytecodeStream *bcs);
duke@435 68 virtual void fill_stackmap_prolog (int nof_gc_points);
duke@435 69 virtual void fill_stackmap_epilog ();
duke@435 70 virtual void fill_stackmap_for_opcodes (BytecodeStream *bcs,
duke@435 71 CellTypeState* vars,
duke@435 72 CellTypeState* stack,
duke@435 73 int stack_top);
duke@435 74 virtual void fill_init_vars (GrowableArray<intptr_t> *init_vars);
duke@435 75
duke@435 76 public:
duke@435 77 OopMapForCacheEntry(methodHandle method, int bci, OopMapCacheEntry *entry);
duke@435 78
duke@435 79 // Computes stack map for (method,bci) and initialize entry
duke@435 80 void compute_map(TRAPS);
duke@435 81 int size();
duke@435 82 };
duke@435 83
duke@435 84
duke@435 85 OopMapForCacheEntry::OopMapForCacheEntry(methodHandle method, int bci, OopMapCacheEntry* entry) : GenerateOopMap(method) {
duke@435 86 _bci = bci;
duke@435 87 _entry = entry;
duke@435 88 _stack_top = -1;
duke@435 89 }
duke@435 90
duke@435 91
duke@435 92 void OopMapForCacheEntry::compute_map(TRAPS) {
duke@435 93 assert(!method()->is_native(), "cannot compute oop map for native methods");
duke@435 94 // First check if it is a method where the stackmap is always empty
duke@435 95 if (method()->code_size() == 0 || method()->max_locals() + method()->max_stack() == 0) {
duke@435 96 _entry->set_mask_size(0);
duke@435 97 } else {
duke@435 98 ResourceMark rm;
duke@435 99 GenerateOopMap::compute_map(CATCH);
duke@435 100 result_for_basicblock(_bci);
duke@435 101 }
duke@435 102 }
duke@435 103
duke@435 104
duke@435 105 bool OopMapForCacheEntry::possible_gc_point(BytecodeStream *bcs) {
duke@435 106 return false; // We are not reporting any result. We call result_for_basicblock directly
duke@435 107 }
duke@435 108
duke@435 109
duke@435 110 void OopMapForCacheEntry::fill_stackmap_prolog(int nof_gc_points) {
duke@435 111 // Do nothing
duke@435 112 }
duke@435 113
duke@435 114
duke@435 115 void OopMapForCacheEntry::fill_stackmap_epilog() {
duke@435 116 // Do nothing
duke@435 117 }
duke@435 118
duke@435 119
duke@435 120 void OopMapForCacheEntry::fill_init_vars(GrowableArray<intptr_t> *init_vars) {
duke@435 121 // Do nothing
duke@435 122 }
duke@435 123
duke@435 124
duke@435 125 void OopMapForCacheEntry::fill_stackmap_for_opcodes(BytecodeStream *bcs,
duke@435 126 CellTypeState* vars,
duke@435 127 CellTypeState* stack,
duke@435 128 int stack_top) {
duke@435 129 // Only interested in one specific bci
duke@435 130 if (bcs->bci() == _bci) {
duke@435 131 _entry->set_mask(vars, stack, stack_top);
duke@435 132 _stack_top = stack_top;
duke@435 133 }
duke@435 134 }
duke@435 135
duke@435 136
duke@435 137 int OopMapForCacheEntry::size() {
duke@435 138 assert(_stack_top != -1, "compute_map must be called first");
duke@435 139 return ((method()->is_static()) ? 0 : 1) + method()->max_locals() + _stack_top;
duke@435 140 }
duke@435 141
duke@435 142
duke@435 143 // Implementation of InterpreterOopMap and OopMapCacheEntry
duke@435 144
duke@435 145 class VerifyClosure : public OffsetClosure {
duke@435 146 private:
duke@435 147 OopMapCacheEntry* _entry;
duke@435 148 bool _failed;
duke@435 149
duke@435 150 public:
duke@435 151 VerifyClosure(OopMapCacheEntry* entry) { _entry = entry; _failed = false; }
duke@435 152 void offset_do(int offset) { if (!_entry->is_oop(offset)) _failed = true; }
duke@435 153 bool failed() const { return _failed; }
duke@435 154 };
duke@435 155
duke@435 156 InterpreterOopMap::InterpreterOopMap() {
duke@435 157 initialize();
duke@435 158 #ifdef ASSERT
duke@435 159 _resource_allocate_bit_mask = true;
duke@435 160 #endif
duke@435 161 }
duke@435 162
duke@435 163 InterpreterOopMap::~InterpreterOopMap() {
duke@435 164 // The expection is that the bit mask was allocated
duke@435 165 // last in this resource area. That would make the free of the
duke@435 166 // bit_mask effective (see how FREE_RESOURCE_ARRAY does a free).
duke@435 167 // If it was not allocated last, there is not a correctness problem
duke@435 168 // but the space for the bit_mask is not freed.
duke@435 169 assert(_resource_allocate_bit_mask, "Trying to free C heap space");
duke@435 170 if (mask_size() > small_mask_limit) {
duke@435 171 FREE_RESOURCE_ARRAY(uintptr_t, _bit_mask[0], mask_word_size());
duke@435 172 }
duke@435 173 }
duke@435 174
duke@435 175 bool InterpreterOopMap::is_empty() {
duke@435 176 bool result = _method == NULL;
duke@435 177 assert(_method != NULL || (_bci == 0 &&
duke@435 178 (_mask_size == 0 || _mask_size == USHRT_MAX) &&
duke@435 179 _bit_mask[0] == 0), "Should be completely empty");
duke@435 180 return result;
duke@435 181 }
duke@435 182
duke@435 183 void InterpreterOopMap::initialize() {
duke@435 184 _method = NULL;
duke@435 185 _mask_size = USHRT_MAX; // This value should cause a failure quickly
duke@435 186 _bci = 0;
duke@435 187 _expression_stack_size = 0;
duke@435 188 for (int i = 0; i < N; i++) _bit_mask[i] = 0;
duke@435 189 }
duke@435 190
duke@435 191
duke@435 192 void InterpreterOopMap::oop_iterate(OopClosure *blk) {
duke@435 193 if (method() != NULL) {
duke@435 194 blk->do_oop((oop*) &_method);
duke@435 195 }
duke@435 196 }
duke@435 197
duke@435 198 void InterpreterOopMap::oop_iterate(OopClosure *blk, MemRegion mr) {
duke@435 199 if (method() != NULL && mr.contains(&_method)) {
duke@435 200 blk->do_oop((oop*) &_method);
duke@435 201 }
duke@435 202 }
duke@435 203
duke@435 204
duke@435 205
duke@435 206 void InterpreterOopMap::iterate_oop(OffsetClosure* oop_closure) {
duke@435 207 int n = number_of_entries();
duke@435 208 int word_index = 0;
duke@435 209 uintptr_t value = 0;
duke@435 210 uintptr_t mask = 0;
duke@435 211 // iterate over entries
duke@435 212 for (int i = 0; i < n; i++, mask <<= bits_per_entry) {
duke@435 213 // get current word
duke@435 214 if (mask == 0) {
duke@435 215 value = bit_mask()[word_index++];
duke@435 216 mask = 1;
duke@435 217 }
duke@435 218 // test for oop
duke@435 219 if ((value & (mask << oop_bit_number)) != 0) oop_closure->offset_do(i);
duke@435 220 }
duke@435 221 }
duke@435 222
duke@435 223 void InterpreterOopMap::verify() {
duke@435 224 // If we are doing mark sweep _method may not have a valid header
duke@435 225 // $$$ This used to happen only for m/s collections; we might want to
duke@435 226 // think of an appropriate generalization of this distinction.
jcoomes@1844 227 guarantee(Universe::heap()->is_gc_active() || _method->is_oop_or_null(),
jcoomes@1844 228 "invalid oop in oopMapCache");
duke@435 229 }
duke@435 230
duke@435 231 #ifdef ENABLE_ZAP_DEAD_LOCALS
duke@435 232
duke@435 233 void InterpreterOopMap::iterate_all(OffsetClosure* oop_closure, OffsetClosure* value_closure, OffsetClosure* dead_closure) {
duke@435 234 int n = number_of_entries();
duke@435 235 int word_index = 0;
duke@435 236 uintptr_t value = 0;
duke@435 237 uintptr_t mask = 0;
duke@435 238 // iterate over entries
duke@435 239 for (int i = 0; i < n; i++, mask <<= bits_per_entry) {
duke@435 240 // get current word
duke@435 241 if (mask == 0) {
duke@435 242 value = bit_mask()[word_index++];
duke@435 243 mask = 1;
duke@435 244 }
duke@435 245 // test for dead values & oops, and for live values
duke@435 246 if ((value & (mask << dead_bit_number)) != 0) dead_closure->offset_do(i); // call this for all dead values or oops
duke@435 247 else if ((value & (mask << oop_bit_number)) != 0) oop_closure->offset_do(i); // call this for all live oops
duke@435 248 else value_closure->offset_do(i); // call this for all live values
duke@435 249 }
duke@435 250 }
duke@435 251
duke@435 252 #endif
duke@435 253
duke@435 254
duke@435 255 void InterpreterOopMap::print() {
duke@435 256 int n = number_of_entries();
duke@435 257 tty->print("oop map for ");
duke@435 258 method()->print_value();
duke@435 259 tty->print(" @ %d = [%d] { ", bci(), n);
duke@435 260 for (int i = 0; i < n; i++) {
duke@435 261 #ifdef ENABLE_ZAP_DEAD_LOCALS
duke@435 262 if (is_dead(i)) tty->print("%d+ ", i);
duke@435 263 else
duke@435 264 #endif
duke@435 265 if (is_oop(i)) tty->print("%d ", i);
duke@435 266 }
duke@435 267 tty->print_cr("}");
duke@435 268 }
duke@435 269
duke@435 270 class MaskFillerForNative: public NativeSignatureIterator {
duke@435 271 private:
duke@435 272 uintptr_t * _mask; // the bit mask to be filled
duke@435 273 int _size; // the mask size in bits
duke@435 274
duke@435 275 void set_one(int i) {
duke@435 276 i *= InterpreterOopMap::bits_per_entry;
duke@435 277 assert(0 <= i && i < _size, "offset out of bounds");
duke@435 278 _mask[i / BitsPerWord] |= (((uintptr_t) 1 << InterpreterOopMap::oop_bit_number) << (i % BitsPerWord));
duke@435 279 }
duke@435 280
duke@435 281 public:
duke@435 282 void pass_int() { /* ignore */ }
duke@435 283 void pass_long() { /* ignore */ }
duke@435 284 void pass_float() { /* ignore */ }
duke@435 285 void pass_double() { /* ignore */ }
duke@435 286 void pass_object() { set_one(offset()); }
duke@435 287
duke@435 288 MaskFillerForNative(methodHandle method, uintptr_t* mask, int size) : NativeSignatureIterator(method) {
duke@435 289 _mask = mask;
duke@435 290 _size = size;
duke@435 291 // initialize with 0
duke@435 292 int i = (size + BitsPerWord - 1) / BitsPerWord;
duke@435 293 while (i-- > 0) _mask[i] = 0;
duke@435 294 }
duke@435 295
duke@435 296 void generate() {
duke@435 297 NativeSignatureIterator::iterate();
duke@435 298 }
duke@435 299 };
duke@435 300
duke@435 301 bool OopMapCacheEntry::verify_mask(CellTypeState* vars, CellTypeState* stack, int max_locals, int stack_top) {
duke@435 302 // Check mask includes map
duke@435 303 VerifyClosure blk(this);
duke@435 304 iterate_oop(&blk);
duke@435 305 if (blk.failed()) return false;
duke@435 306
duke@435 307 // Check if map is generated correctly
duke@435 308 // (Use ?: operator to make sure all 'true' & 'false' are represented exactly the same so we can use == afterwards)
duke@435 309 if (TraceOopMapGeneration && Verbose) tty->print("Locals (%d): ", max_locals);
duke@435 310
duke@435 311 for(int i = 0; i < max_locals; i++) {
duke@435 312 bool v1 = is_oop(i) ? true : false;
duke@435 313 bool v2 = vars[i].is_reference() ? true : false;
duke@435 314 assert(v1 == v2, "locals oop mask generation error");
duke@435 315 if (TraceOopMapGeneration && Verbose) tty->print("%d", v1 ? 1 : 0);
duke@435 316 #ifdef ENABLE_ZAP_DEAD_LOCALS
duke@435 317 bool v3 = is_dead(i) ? true : false;
duke@435 318 bool v4 = !vars[i].is_live() ? true : false;
duke@435 319 assert(v3 == v4, "locals live mask generation error");
duke@435 320 assert(!(v1 && v3), "dead value marked as oop");
duke@435 321 #endif
duke@435 322 }
duke@435 323
duke@435 324 if (TraceOopMapGeneration && Verbose) { tty->cr(); tty->print("Stack (%d): ", stack_top); }
duke@435 325 for(int j = 0; j < stack_top; j++) {
duke@435 326 bool v1 = is_oop(max_locals + j) ? true : false;
duke@435 327 bool v2 = stack[j].is_reference() ? true : false;
duke@435 328 assert(v1 == v2, "stack oop mask generation error");
duke@435 329 if (TraceOopMapGeneration && Verbose) tty->print("%d", v1 ? 1 : 0);
duke@435 330 #ifdef ENABLE_ZAP_DEAD_LOCALS
duke@435 331 bool v3 = is_dead(max_locals + j) ? true : false;
duke@435 332 bool v4 = !stack[j].is_live() ? true : false;
duke@435 333 assert(v3 == v4, "stack live mask generation error");
duke@435 334 assert(!(v1 && v3), "dead value marked as oop");
duke@435 335 #endif
duke@435 336 }
duke@435 337 if (TraceOopMapGeneration && Verbose) tty->cr();
duke@435 338 return true;
duke@435 339 }
duke@435 340
duke@435 341 void OopMapCacheEntry::allocate_bit_mask() {
duke@435 342 if (mask_size() > small_mask_limit) {
duke@435 343 assert(_bit_mask[0] == 0, "bit mask should be new or just flushed");
duke@435 344 _bit_mask[0] = (intptr_t)
duke@435 345 NEW_C_HEAP_ARRAY(uintptr_t, mask_word_size());
duke@435 346 }
duke@435 347 }
duke@435 348
duke@435 349 void OopMapCacheEntry::deallocate_bit_mask() {
duke@435 350 if (mask_size() > small_mask_limit && _bit_mask[0] != 0) {
duke@435 351 assert(!Thread::current()->resource_area()->contains((void*)_bit_mask[0]),
duke@435 352 "This bit mask should not be in the resource area");
duke@435 353 FREE_C_HEAP_ARRAY(uintptr_t, _bit_mask[0]);
duke@435 354 debug_only(_bit_mask[0] = 0;)
duke@435 355 }
duke@435 356 }
duke@435 357
duke@435 358
duke@435 359 void OopMapCacheEntry::fill_for_native(methodHandle mh) {
duke@435 360 assert(mh->is_native(), "method must be native method");
duke@435 361 set_mask_size(mh->size_of_parameters() * bits_per_entry);
duke@435 362 allocate_bit_mask();
duke@435 363 // fill mask for parameters
duke@435 364 MaskFillerForNative mf(mh, bit_mask(), mask_size());
duke@435 365 mf.generate();
duke@435 366 }
duke@435 367
duke@435 368
duke@435 369 void OopMapCacheEntry::fill(methodHandle method, int bci) {
duke@435 370 HandleMark hm;
duke@435 371 // Flush entry to deallocate an existing entry
duke@435 372 flush();
duke@435 373 set_method(method());
duke@435 374 set_bci(bci);
duke@435 375 if (method->is_native()) {
duke@435 376 // Native method activations have oops only among the parameters and one
duke@435 377 // extra oop following the parameters (the mirror for static native methods).
duke@435 378 fill_for_native(method);
duke@435 379 } else {
duke@435 380 EXCEPTION_MARK;
duke@435 381 OopMapForCacheEntry gen(method, bci, this);
duke@435 382 gen.compute_map(CATCH);
duke@435 383 }
duke@435 384 #ifdef ASSERT
duke@435 385 verify();
duke@435 386 #endif
duke@435 387 }
duke@435 388
duke@435 389
duke@435 390 void OopMapCacheEntry::set_mask(CellTypeState *vars, CellTypeState *stack, int stack_top) {
duke@435 391 // compute bit mask size
duke@435 392 int max_locals = method()->max_locals();
duke@435 393 int n_entries = max_locals + stack_top;
duke@435 394 set_mask_size(n_entries * bits_per_entry);
duke@435 395 allocate_bit_mask();
duke@435 396 set_expression_stack_size(stack_top);
duke@435 397
duke@435 398 // compute bits
duke@435 399 int word_index = 0;
duke@435 400 uintptr_t value = 0;
duke@435 401 uintptr_t mask = 1;
duke@435 402
duke@435 403 CellTypeState* cell = vars;
duke@435 404 for (int entry_index = 0; entry_index < n_entries; entry_index++, mask <<= bits_per_entry, cell++) {
duke@435 405 // store last word
duke@435 406 if (mask == 0) {
duke@435 407 bit_mask()[word_index++] = value;
duke@435 408 value = 0;
duke@435 409 mask = 1;
duke@435 410 }
duke@435 411
duke@435 412 // switch to stack when done with locals
duke@435 413 if (entry_index == max_locals) {
duke@435 414 cell = stack;
duke@435 415 }
duke@435 416
duke@435 417 // set oop bit
duke@435 418 if ( cell->is_reference()) {
duke@435 419 value |= (mask << oop_bit_number );
duke@435 420 }
duke@435 421
duke@435 422 #ifdef ENABLE_ZAP_DEAD_LOCALS
duke@435 423 // set dead bit
duke@435 424 if (!cell->is_live()) {
duke@435 425 value |= (mask << dead_bit_number);
duke@435 426 assert(!cell->is_reference(), "dead value marked as oop");
duke@435 427 }
duke@435 428 #endif
duke@435 429 }
duke@435 430
duke@435 431 // make sure last word is stored
duke@435 432 bit_mask()[word_index] = value;
duke@435 433
duke@435 434 // verify bit mask
duke@435 435 assert(verify_mask(vars, stack, max_locals, stack_top), "mask could not be verified");
duke@435 436
duke@435 437
duke@435 438 }
duke@435 439
duke@435 440 void OopMapCacheEntry::flush() {
duke@435 441 deallocate_bit_mask();
duke@435 442 initialize();
duke@435 443 }
duke@435 444
duke@435 445
duke@435 446 // Implementation of OopMapCache
duke@435 447
duke@435 448 #ifndef PRODUCT
duke@435 449
duke@435 450 static long _total_memory_usage = 0;
duke@435 451
duke@435 452 long OopMapCache::memory_usage() {
duke@435 453 return _total_memory_usage;
duke@435 454 }
duke@435 455
duke@435 456 #endif
duke@435 457
duke@435 458 void InterpreterOopMap::resource_copy(OopMapCacheEntry* from) {
duke@435 459 assert(_resource_allocate_bit_mask,
duke@435 460 "Should not resource allocate the _bit_mask");
duke@435 461 assert(from->method()->is_oop(), "MethodOop is bad");
duke@435 462
duke@435 463 set_method(from->method());
duke@435 464 set_bci(from->bci());
duke@435 465 set_mask_size(from->mask_size());
duke@435 466 set_expression_stack_size(from->expression_stack_size());
duke@435 467
duke@435 468 // Is the bit mask contained in the entry?
duke@435 469 if (from->mask_size() <= small_mask_limit) {
duke@435 470 memcpy((void *)_bit_mask, (void *)from->_bit_mask,
duke@435 471 mask_word_size() * BytesPerWord);
duke@435 472 } else {
duke@435 473 // The expectation is that this InterpreterOopMap is a recently created
duke@435 474 // and empty. It is used to get a copy of a cached entry.
duke@435 475 // If the bit mask has a value, it should be in the
duke@435 476 // resource area.
duke@435 477 assert(_bit_mask[0] == 0 ||
duke@435 478 Thread::current()->resource_area()->contains((void*)_bit_mask[0]),
duke@435 479 "The bit mask should have been allocated from a resource area");
duke@435 480 // Allocate the bit_mask from a Resource area for performance. Allocating
duke@435 481 // from the C heap as is done for OopMapCache has a significant
duke@435 482 // performance impact.
duke@435 483 _bit_mask[0] = (uintptr_t) NEW_RESOURCE_ARRAY(uintptr_t, mask_word_size());
duke@435 484 assert(_bit_mask[0] != 0, "bit mask was not allocated");
duke@435 485 memcpy((void*) _bit_mask[0], (void*) from->_bit_mask[0],
duke@435 486 mask_word_size() * BytesPerWord);
duke@435 487 }
duke@435 488 }
duke@435 489
duke@435 490 inline unsigned int OopMapCache::hash_value_for(methodHandle method, int bci) {
duke@435 491 // We use method->code_size() rather than method->identity_hash() below since
duke@435 492 // the mark may not be present if a pointer to the method is already reversed.
duke@435 493 return ((unsigned int) bci)
duke@435 494 ^ ((unsigned int) method->max_locals() << 2)
duke@435 495 ^ ((unsigned int) method->code_size() << 4)
duke@435 496 ^ ((unsigned int) method->size_of_parameters() << 6);
duke@435 497 }
duke@435 498
duke@435 499
duke@435 500 OopMapCache::OopMapCache() :
duke@435 501 _mut(Mutex::leaf, "An OopMapCache lock", true)
duke@435 502 {
duke@435 503 _array = NEW_C_HEAP_ARRAY(OopMapCacheEntry, _size);
duke@435 504 // Cannot call flush for initialization, since flush
duke@435 505 // will check if memory should be deallocated
duke@435 506 for(int i = 0; i < _size; i++) _array[i].initialize();
duke@435 507 NOT_PRODUCT(_total_memory_usage += sizeof(OopMapCache) + (sizeof(OopMapCacheEntry) * _size);)
duke@435 508 }
duke@435 509
duke@435 510
duke@435 511 OopMapCache::~OopMapCache() {
duke@435 512 assert(_array != NULL, "sanity check");
duke@435 513 // Deallocate oop maps that are allocated out-of-line
duke@435 514 flush();
duke@435 515 // Deallocate array
duke@435 516 NOT_PRODUCT(_total_memory_usage -= sizeof(OopMapCache) + (sizeof(OopMapCacheEntry) * _size);)
duke@435 517 FREE_C_HEAP_ARRAY(OopMapCacheEntry, _array);
duke@435 518 }
duke@435 519
duke@435 520 OopMapCacheEntry* OopMapCache::entry_at(int i) const {
duke@435 521 return &_array[i % _size];
duke@435 522 }
duke@435 523
duke@435 524 void OopMapCache::flush() {
duke@435 525 for (int i = 0; i < _size; i++) _array[i].flush();
duke@435 526 }
duke@435 527
duke@435 528 void OopMapCache::flush_obsolete_entries() {
duke@435 529 for (int i = 0; i < _size; i++)
duke@435 530 if (!_array[i].is_empty() && _array[i].method()->is_old()) {
duke@435 531 // Cache entry is occupied by an old redefined method and we don't want
duke@435 532 // to pin it down so flush the entry.
dcubed@483 533 RC_TRACE(0x08000000, ("flush: %s(%s): cached entry @%d",
dcubed@483 534 _array[i].method()->name()->as_C_string(),
dcubed@483 535 _array[i].method()->signature()->as_C_string(), i));
dcubed@483 536
duke@435 537 _array[i].flush();
duke@435 538 }
duke@435 539 }
duke@435 540
duke@435 541 void OopMapCache::oop_iterate(OopClosure *blk) {
duke@435 542 for (int i = 0; i < _size; i++) _array[i].oop_iterate(blk);
duke@435 543 }
duke@435 544
duke@435 545 void OopMapCache::oop_iterate(OopClosure *blk, MemRegion mr) {
duke@435 546 for (int i = 0; i < _size; i++) _array[i].oop_iterate(blk, mr);
duke@435 547 }
duke@435 548
duke@435 549 void OopMapCache::verify() {
duke@435 550 for (int i = 0; i < _size; i++) _array[i].verify();
duke@435 551 }
duke@435 552
duke@435 553 void OopMapCache::lookup(methodHandle method,
duke@435 554 int bci,
duke@435 555 InterpreterOopMap* entry_for) {
duke@435 556 MutexLocker x(&_mut);
duke@435 557
duke@435 558 OopMapCacheEntry* entry = NULL;
duke@435 559 int probe = hash_value_for(method, bci);
duke@435 560
duke@435 561 // Search hashtable for match
duke@435 562 int i;
duke@435 563 for(i = 0; i < _probe_depth; i++) {
duke@435 564 entry = entry_at(probe + i);
duke@435 565 if (entry->match(method, bci)) {
duke@435 566 entry_for->resource_copy(entry);
duke@435 567 assert(!entry_for->is_empty(), "A non-empty oop map should be returned");
duke@435 568 return;
duke@435 569 }
duke@435 570 }
duke@435 571
duke@435 572 if (TraceOopMapGeneration) {
duke@435 573 static int count = 0;
duke@435 574 ResourceMark rm;
duke@435 575 tty->print("%d - Computing oopmap at bci %d for ", ++count, bci);
duke@435 576 method->print_value(); tty->cr();
duke@435 577 }
duke@435 578
duke@435 579 // Entry is not in hashtable.
duke@435 580 // Compute entry and return it
duke@435 581
dcubed@483 582 if (method->should_not_be_cached()) {
dcubed@483 583 // It is either not safe or not a good idea to cache this methodOop
dcubed@483 584 // at this time. We give the caller of lookup() a copy of the
dcubed@483 585 // interesting info via parameter entry_for, but we don't add it to
dcubed@483 586 // the cache. See the gory details in methodOop.cpp.
dcubed@483 587 compute_one_oop_map(method, bci, entry_for);
dcubed@483 588 return;
dcubed@483 589 }
dcubed@483 590
duke@435 591 // First search for an empty slot
duke@435 592 for(i = 0; i < _probe_depth; i++) {
duke@435 593 entry = entry_at(probe + i);
duke@435 594 if (entry->is_empty()) {
duke@435 595 entry->fill(method, bci);
duke@435 596 entry_for->resource_copy(entry);
duke@435 597 assert(!entry_for->is_empty(), "A non-empty oop map should be returned");
duke@435 598 return;
duke@435 599 }
duke@435 600 }
duke@435 601
duke@435 602 if (TraceOopMapGeneration) {
duke@435 603 ResourceMark rm;
duke@435 604 tty->print_cr("*** collision in oopmap cache - flushing item ***");
duke@435 605 }
duke@435 606
duke@435 607 // No empty slot (uncommon case). Use (some approximation of a) LRU algorithm
duke@435 608 //entry_at(probe + _probe_depth - 1)->flush();
duke@435 609 //for(i = _probe_depth - 1; i > 0; i--) {
duke@435 610 // // Coping entry[i] = entry[i-1];
duke@435 611 // OopMapCacheEntry *to = entry_at(probe + i);
duke@435 612 // OopMapCacheEntry *from = entry_at(probe + i - 1);
duke@435 613 // to->copy(from);
duke@435 614 // }
duke@435 615
duke@435 616 assert(method->is_method(), "gaga");
duke@435 617
duke@435 618 entry = entry_at(probe + 0);
duke@435 619 entry->fill(method, bci);
duke@435 620
duke@435 621 // Copy the newly cached entry to input parameter
duke@435 622 entry_for->resource_copy(entry);
duke@435 623
duke@435 624 if (TraceOopMapGeneration) {
duke@435 625 ResourceMark rm;
duke@435 626 tty->print("Done with ");
duke@435 627 method->print_value(); tty->cr();
duke@435 628 }
duke@435 629 assert(!entry_for->is_empty(), "A non-empty oop map should be returned");
duke@435 630
duke@435 631 return;
duke@435 632 }
duke@435 633
duke@435 634 void OopMapCache::compute_one_oop_map(methodHandle method, int bci, InterpreterOopMap* entry) {
duke@435 635 // Due to the invariants above it's tricky to allocate a temporary OopMapCacheEntry on the stack
duke@435 636 OopMapCacheEntry* tmp = NEW_C_HEAP_ARRAY(OopMapCacheEntry, 1);
duke@435 637 tmp->initialize();
duke@435 638 tmp->fill(method, bci);
duke@435 639 entry->resource_copy(tmp);
duke@435 640 FREE_C_HEAP_ARRAY(OopMapCacheEntry, tmp);
duke@435 641 }

mercurial