src/share/vm/interpreter/oopMapCache.cpp

Sat, 01 Dec 2007 00:00:00 +0000

author
duke
date
Sat, 01 Dec 2007 00:00:00 +0000
changeset 435
a61af66fc99e
child 483
d8b3ef7ee3e5
permissions
-rw-r--r--

Initial load

duke@435 1 /*
duke@435 2 * Copyright 1997-2006 Sun Microsystems, Inc. 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 *
duke@435 19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
duke@435 20 * CA 95054 USA or visit www.sun.com if you need additional information or
duke@435 21 * have any 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.
duke@435 227 guarantee(Universe::heap()->is_gc_active() ||
duke@435 228 _method->is_oop_or_null(), "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 #ifdef _LP64
duke@435 285 void pass_float() { /* ignore */ }
duke@435 286 #endif
duke@435 287 void pass_double() { /* ignore */ }
duke@435 288 void pass_object() { set_one(offset()); }
duke@435 289
duke@435 290 MaskFillerForNative(methodHandle method, uintptr_t* mask, int size) : NativeSignatureIterator(method) {
duke@435 291 _mask = mask;
duke@435 292 _size = size;
duke@435 293 // initialize with 0
duke@435 294 int i = (size + BitsPerWord - 1) / BitsPerWord;
duke@435 295 while (i-- > 0) _mask[i] = 0;
duke@435 296 }
duke@435 297
duke@435 298 void generate() {
duke@435 299 NativeSignatureIterator::iterate();
duke@435 300 }
duke@435 301 };
duke@435 302
duke@435 303 bool OopMapCacheEntry::verify_mask(CellTypeState* vars, CellTypeState* stack, int max_locals, int stack_top) {
duke@435 304 // Check mask includes map
duke@435 305 VerifyClosure blk(this);
duke@435 306 iterate_oop(&blk);
duke@435 307 if (blk.failed()) return false;
duke@435 308
duke@435 309 // Check if map is generated correctly
duke@435 310 // (Use ?: operator to make sure all 'true' & 'false' are represented exactly the same so we can use == afterwards)
duke@435 311 if (TraceOopMapGeneration && Verbose) tty->print("Locals (%d): ", max_locals);
duke@435 312
duke@435 313 for(int i = 0; i < max_locals; i++) {
duke@435 314 bool v1 = is_oop(i) ? true : false;
duke@435 315 bool v2 = vars[i].is_reference() ? true : false;
duke@435 316 assert(v1 == v2, "locals oop mask generation error");
duke@435 317 if (TraceOopMapGeneration && Verbose) tty->print("%d", v1 ? 1 : 0);
duke@435 318 #ifdef ENABLE_ZAP_DEAD_LOCALS
duke@435 319 bool v3 = is_dead(i) ? true : false;
duke@435 320 bool v4 = !vars[i].is_live() ? true : false;
duke@435 321 assert(v3 == v4, "locals live mask generation error");
duke@435 322 assert(!(v1 && v3), "dead value marked as oop");
duke@435 323 #endif
duke@435 324 }
duke@435 325
duke@435 326 if (TraceOopMapGeneration && Verbose) { tty->cr(); tty->print("Stack (%d): ", stack_top); }
duke@435 327 for(int j = 0; j < stack_top; j++) {
duke@435 328 bool v1 = is_oop(max_locals + j) ? true : false;
duke@435 329 bool v2 = stack[j].is_reference() ? true : false;
duke@435 330 assert(v1 == v2, "stack oop mask generation error");
duke@435 331 if (TraceOopMapGeneration && Verbose) tty->print("%d", v1 ? 1 : 0);
duke@435 332 #ifdef ENABLE_ZAP_DEAD_LOCALS
duke@435 333 bool v3 = is_dead(max_locals + j) ? true : false;
duke@435 334 bool v4 = !stack[j].is_live() ? true : false;
duke@435 335 assert(v3 == v4, "stack live mask generation error");
duke@435 336 assert(!(v1 && v3), "dead value marked as oop");
duke@435 337 #endif
duke@435 338 }
duke@435 339 if (TraceOopMapGeneration && Verbose) tty->cr();
duke@435 340 return true;
duke@435 341 }
duke@435 342
duke@435 343 void OopMapCacheEntry::allocate_bit_mask() {
duke@435 344 if (mask_size() > small_mask_limit) {
duke@435 345 assert(_bit_mask[0] == 0, "bit mask should be new or just flushed");
duke@435 346 _bit_mask[0] = (intptr_t)
duke@435 347 NEW_C_HEAP_ARRAY(uintptr_t, mask_word_size());
duke@435 348 }
duke@435 349 }
duke@435 350
duke@435 351 void OopMapCacheEntry::deallocate_bit_mask() {
duke@435 352 if (mask_size() > small_mask_limit && _bit_mask[0] != 0) {
duke@435 353 assert(!Thread::current()->resource_area()->contains((void*)_bit_mask[0]),
duke@435 354 "This bit mask should not be in the resource area");
duke@435 355 FREE_C_HEAP_ARRAY(uintptr_t, _bit_mask[0]);
duke@435 356 debug_only(_bit_mask[0] = 0;)
duke@435 357 }
duke@435 358 }
duke@435 359
duke@435 360
duke@435 361 void OopMapCacheEntry::fill_for_native(methodHandle mh) {
duke@435 362 assert(mh->is_native(), "method must be native method");
duke@435 363 set_mask_size(mh->size_of_parameters() * bits_per_entry);
duke@435 364 allocate_bit_mask();
duke@435 365 // fill mask for parameters
duke@435 366 MaskFillerForNative mf(mh, bit_mask(), mask_size());
duke@435 367 mf.generate();
duke@435 368 }
duke@435 369
duke@435 370
duke@435 371 void OopMapCacheEntry::fill(methodHandle method, int bci) {
duke@435 372 HandleMark hm;
duke@435 373 // Flush entry to deallocate an existing entry
duke@435 374 flush();
duke@435 375 set_method(method());
duke@435 376 set_bci(bci);
duke@435 377 if (method->is_native()) {
duke@435 378 // Native method activations have oops only among the parameters and one
duke@435 379 // extra oop following the parameters (the mirror for static native methods).
duke@435 380 fill_for_native(method);
duke@435 381 } else {
duke@435 382 EXCEPTION_MARK;
duke@435 383 OopMapForCacheEntry gen(method, bci, this);
duke@435 384 gen.compute_map(CATCH);
duke@435 385 }
duke@435 386 #ifdef ASSERT
duke@435 387 verify();
duke@435 388 #endif
duke@435 389 }
duke@435 390
duke@435 391
duke@435 392 void OopMapCacheEntry::set_mask(CellTypeState *vars, CellTypeState *stack, int stack_top) {
duke@435 393 // compute bit mask size
duke@435 394 int max_locals = method()->max_locals();
duke@435 395 int n_entries = max_locals + stack_top;
duke@435 396 set_mask_size(n_entries * bits_per_entry);
duke@435 397 allocate_bit_mask();
duke@435 398 set_expression_stack_size(stack_top);
duke@435 399
duke@435 400 // compute bits
duke@435 401 int word_index = 0;
duke@435 402 uintptr_t value = 0;
duke@435 403 uintptr_t mask = 1;
duke@435 404
duke@435 405 CellTypeState* cell = vars;
duke@435 406 for (int entry_index = 0; entry_index < n_entries; entry_index++, mask <<= bits_per_entry, cell++) {
duke@435 407 // store last word
duke@435 408 if (mask == 0) {
duke@435 409 bit_mask()[word_index++] = value;
duke@435 410 value = 0;
duke@435 411 mask = 1;
duke@435 412 }
duke@435 413
duke@435 414 // switch to stack when done with locals
duke@435 415 if (entry_index == max_locals) {
duke@435 416 cell = stack;
duke@435 417 }
duke@435 418
duke@435 419 // set oop bit
duke@435 420 if ( cell->is_reference()) {
duke@435 421 value |= (mask << oop_bit_number );
duke@435 422 }
duke@435 423
duke@435 424 #ifdef ENABLE_ZAP_DEAD_LOCALS
duke@435 425 // set dead bit
duke@435 426 if (!cell->is_live()) {
duke@435 427 value |= (mask << dead_bit_number);
duke@435 428 assert(!cell->is_reference(), "dead value marked as oop");
duke@435 429 }
duke@435 430 #endif
duke@435 431 }
duke@435 432
duke@435 433 // make sure last word is stored
duke@435 434 bit_mask()[word_index] = value;
duke@435 435
duke@435 436 // verify bit mask
duke@435 437 assert(verify_mask(vars, stack, max_locals, stack_top), "mask could not be verified");
duke@435 438
duke@435 439
duke@435 440 }
duke@435 441
duke@435 442 void OopMapCacheEntry::flush() {
duke@435 443 deallocate_bit_mask();
duke@435 444 initialize();
duke@435 445 }
duke@435 446
duke@435 447
duke@435 448 // Implementation of OopMapCache
duke@435 449
duke@435 450 #ifndef PRODUCT
duke@435 451
duke@435 452 static long _total_memory_usage = 0;
duke@435 453
duke@435 454 long OopMapCache::memory_usage() {
duke@435 455 return _total_memory_usage;
duke@435 456 }
duke@435 457
duke@435 458 #endif
duke@435 459
duke@435 460 void InterpreterOopMap::resource_copy(OopMapCacheEntry* from) {
duke@435 461 assert(_resource_allocate_bit_mask,
duke@435 462 "Should not resource allocate the _bit_mask");
duke@435 463 assert(from->method()->is_oop(), "MethodOop is bad");
duke@435 464
duke@435 465 set_method(from->method());
duke@435 466 set_bci(from->bci());
duke@435 467 set_mask_size(from->mask_size());
duke@435 468 set_expression_stack_size(from->expression_stack_size());
duke@435 469
duke@435 470 // Is the bit mask contained in the entry?
duke@435 471 if (from->mask_size() <= small_mask_limit) {
duke@435 472 memcpy((void *)_bit_mask, (void *)from->_bit_mask,
duke@435 473 mask_word_size() * BytesPerWord);
duke@435 474 } else {
duke@435 475 // The expectation is that this InterpreterOopMap is a recently created
duke@435 476 // and empty. It is used to get a copy of a cached entry.
duke@435 477 // If the bit mask has a value, it should be in the
duke@435 478 // resource area.
duke@435 479 assert(_bit_mask[0] == 0 ||
duke@435 480 Thread::current()->resource_area()->contains((void*)_bit_mask[0]),
duke@435 481 "The bit mask should have been allocated from a resource area");
duke@435 482 // Allocate the bit_mask from a Resource area for performance. Allocating
duke@435 483 // from the C heap as is done for OopMapCache has a significant
duke@435 484 // performance impact.
duke@435 485 _bit_mask[0] = (uintptr_t) NEW_RESOURCE_ARRAY(uintptr_t, mask_word_size());
duke@435 486 assert(_bit_mask[0] != 0, "bit mask was not allocated");
duke@435 487 memcpy((void*) _bit_mask[0], (void*) from->_bit_mask[0],
duke@435 488 mask_word_size() * BytesPerWord);
duke@435 489 }
duke@435 490 }
duke@435 491
duke@435 492 inline unsigned int OopMapCache::hash_value_for(methodHandle method, int bci) {
duke@435 493 // We use method->code_size() rather than method->identity_hash() below since
duke@435 494 // the mark may not be present if a pointer to the method is already reversed.
duke@435 495 return ((unsigned int) bci)
duke@435 496 ^ ((unsigned int) method->max_locals() << 2)
duke@435 497 ^ ((unsigned int) method->code_size() << 4)
duke@435 498 ^ ((unsigned int) method->size_of_parameters() << 6);
duke@435 499 }
duke@435 500
duke@435 501
duke@435 502 OopMapCache::OopMapCache() :
duke@435 503 _mut(Mutex::leaf, "An OopMapCache lock", true)
duke@435 504 {
duke@435 505 _array = NEW_C_HEAP_ARRAY(OopMapCacheEntry, _size);
duke@435 506 // Cannot call flush for initialization, since flush
duke@435 507 // will check if memory should be deallocated
duke@435 508 for(int i = 0; i < _size; i++) _array[i].initialize();
duke@435 509 NOT_PRODUCT(_total_memory_usage += sizeof(OopMapCache) + (sizeof(OopMapCacheEntry) * _size);)
duke@435 510 }
duke@435 511
duke@435 512
duke@435 513 OopMapCache::~OopMapCache() {
duke@435 514 assert(_array != NULL, "sanity check");
duke@435 515 // Deallocate oop maps that are allocated out-of-line
duke@435 516 flush();
duke@435 517 // Deallocate array
duke@435 518 NOT_PRODUCT(_total_memory_usage -= sizeof(OopMapCache) + (sizeof(OopMapCacheEntry) * _size);)
duke@435 519 FREE_C_HEAP_ARRAY(OopMapCacheEntry, _array);
duke@435 520 }
duke@435 521
duke@435 522 OopMapCacheEntry* OopMapCache::entry_at(int i) const {
duke@435 523 return &_array[i % _size];
duke@435 524 }
duke@435 525
duke@435 526 void OopMapCache::flush() {
duke@435 527 for (int i = 0; i < _size; i++) _array[i].flush();
duke@435 528 }
duke@435 529
duke@435 530 void OopMapCache::flush_obsolete_entries() {
duke@435 531 for (int i = 0; i < _size; i++)
duke@435 532 if (!_array[i].is_empty() && _array[i].method()->is_old()) {
duke@435 533 // Cache entry is occupied by an old redefined method and we don't want
duke@435 534 // to pin it down so flush the entry.
duke@435 535 _array[i].flush();
duke@435 536 }
duke@435 537 }
duke@435 538
duke@435 539 void OopMapCache::oop_iterate(OopClosure *blk) {
duke@435 540 for (int i = 0; i < _size; i++) _array[i].oop_iterate(blk);
duke@435 541 }
duke@435 542
duke@435 543 void OopMapCache::oop_iterate(OopClosure *blk, MemRegion mr) {
duke@435 544 for (int i = 0; i < _size; i++) _array[i].oop_iterate(blk, mr);
duke@435 545 }
duke@435 546
duke@435 547 void OopMapCache::verify() {
duke@435 548 for (int i = 0; i < _size; i++) _array[i].verify();
duke@435 549 }
duke@435 550
duke@435 551 void OopMapCache::lookup(methodHandle method,
duke@435 552 int bci,
duke@435 553 InterpreterOopMap* entry_for) {
duke@435 554 MutexLocker x(&_mut);
duke@435 555
duke@435 556 OopMapCacheEntry* entry = NULL;
duke@435 557 int probe = hash_value_for(method, bci);
duke@435 558
duke@435 559 // Search hashtable for match
duke@435 560 int i;
duke@435 561 for(i = 0; i < _probe_depth; i++) {
duke@435 562 entry = entry_at(probe + i);
duke@435 563 if (entry->match(method, bci)) {
duke@435 564 entry_for->resource_copy(entry);
duke@435 565 assert(!entry_for->is_empty(), "A non-empty oop map should be returned");
duke@435 566 return;
duke@435 567 }
duke@435 568 }
duke@435 569
duke@435 570 if (TraceOopMapGeneration) {
duke@435 571 static int count = 0;
duke@435 572 ResourceMark rm;
duke@435 573 tty->print("%d - Computing oopmap at bci %d for ", ++count, bci);
duke@435 574 method->print_value(); tty->cr();
duke@435 575 }
duke@435 576
duke@435 577 // Entry is not in hashtable.
duke@435 578 // Compute entry and return it
duke@435 579
duke@435 580 // First search for an empty slot
duke@435 581 for(i = 0; i < _probe_depth; i++) {
duke@435 582 entry = entry_at(probe + i);
duke@435 583 if (entry->is_empty()) {
duke@435 584 entry->fill(method, bci);
duke@435 585 entry_for->resource_copy(entry);
duke@435 586 assert(!entry_for->is_empty(), "A non-empty oop map should be returned");
duke@435 587 if (method->is_old()) {
duke@435 588 // The caller of lookup() will receive a copy of the interesting
duke@435 589 // info via entry_for, but we don't keep an old redefined method in
duke@435 590 // the cache to avoid pinning down the method.
duke@435 591 entry->flush();
duke@435 592 }
duke@435 593 return;
duke@435 594 }
duke@435 595 }
duke@435 596
duke@435 597 if (TraceOopMapGeneration) {
duke@435 598 ResourceMark rm;
duke@435 599 tty->print_cr("*** collision in oopmap cache - flushing item ***");
duke@435 600 }
duke@435 601
duke@435 602 // No empty slot (uncommon case). Use (some approximation of a) LRU algorithm
duke@435 603 //entry_at(probe + _probe_depth - 1)->flush();
duke@435 604 //for(i = _probe_depth - 1; i > 0; i--) {
duke@435 605 // // Coping entry[i] = entry[i-1];
duke@435 606 // OopMapCacheEntry *to = entry_at(probe + i);
duke@435 607 // OopMapCacheEntry *from = entry_at(probe + i - 1);
duke@435 608 // to->copy(from);
duke@435 609 // }
duke@435 610
duke@435 611 assert(method->is_method(), "gaga");
duke@435 612
duke@435 613 entry = entry_at(probe + 0);
duke@435 614 entry->fill(method, bci);
duke@435 615
duke@435 616 // Copy the newly cached entry to input parameter
duke@435 617 entry_for->resource_copy(entry);
duke@435 618
duke@435 619 if (TraceOopMapGeneration) {
duke@435 620 ResourceMark rm;
duke@435 621 tty->print("Done with ");
duke@435 622 method->print_value(); tty->cr();
duke@435 623 }
duke@435 624 assert(!entry_for->is_empty(), "A non-empty oop map should be returned");
duke@435 625
duke@435 626 if (method->is_old()) {
duke@435 627 // The caller of lookup() will receive a copy of the interesting
duke@435 628 // info via entry_for, but we don't keep an old redefined method in
duke@435 629 // the cache to avoid pinning down the method.
duke@435 630 entry->flush();
duke@435 631 }
duke@435 632
duke@435 633 return;
duke@435 634 }
duke@435 635
duke@435 636 void OopMapCache::compute_one_oop_map(methodHandle method, int bci, InterpreterOopMap* entry) {
duke@435 637 // Due to the invariants above it's tricky to allocate a temporary OopMapCacheEntry on the stack
duke@435 638 OopMapCacheEntry* tmp = NEW_C_HEAP_ARRAY(OopMapCacheEntry, 1);
duke@435 639 tmp->initialize();
duke@435 640 tmp->fill(method, bci);
duke@435 641 entry->resource_copy(tmp);
duke@435 642 FREE_C_HEAP_ARRAY(OopMapCacheEntry, tmp);
duke@435 643 }

mercurial