duke@435: /* duke@435: * Copyright 1997-2006 Sun Microsystems, Inc. All Rights Reserved. duke@435: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@435: * duke@435: * This code is free software; you can redistribute it and/or modify it duke@435: * under the terms of the GNU General Public License version 2 only, as duke@435: * published by the Free Software Foundation. duke@435: * duke@435: * This code is distributed in the hope that it will be useful, but WITHOUT duke@435: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@435: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@435: * version 2 for more details (a copy is included in the LICENSE file that duke@435: * accompanied this code). duke@435: * duke@435: * You should have received a copy of the GNU General Public License version duke@435: * 2 along with this work; if not, write to the Free Software Foundation, duke@435: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@435: * duke@435: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, duke@435: * CA 95054 USA or visit www.sun.com if you need additional information or duke@435: * have any questions. duke@435: * duke@435: */ duke@435: duke@435: # include "incls/_precompiled.incl" duke@435: # include "incls/_oopMapCache.cpp.incl" duke@435: duke@435: class OopMapCacheEntry: private InterpreterOopMap { duke@435: friend class InterpreterOopMap; duke@435: friend class OopMapForCacheEntry; duke@435: friend class OopMapCache; duke@435: friend class VerifyClosure; duke@435: duke@435: protected: duke@435: // Initialization duke@435: void fill(methodHandle method, int bci); duke@435: // fills the bit mask for native calls duke@435: void fill_for_native(methodHandle method); duke@435: void set_mask(CellTypeState* vars, CellTypeState* stack, int stack_top); duke@435: duke@435: // Deallocate bit masks and initialize fields duke@435: void flush(); duke@435: duke@435: private: duke@435: void allocate_bit_mask(); // allocates the bit mask on C heap f necessary duke@435: void deallocate_bit_mask(); // allocates the bit mask on C heap f necessary duke@435: bool verify_mask(CellTypeState *vars, CellTypeState *stack, int max_locals, int stack_top); duke@435: duke@435: public: duke@435: OopMapCacheEntry() : InterpreterOopMap() { duke@435: #ifdef ASSERT duke@435: _resource_allocate_bit_mask = false; duke@435: #endif duke@435: } duke@435: }; duke@435: duke@435: duke@435: // Implementation of OopMapForCacheEntry duke@435: // (subclass of GenerateOopMap, initializes an OopMapCacheEntry for a given method and bci) duke@435: duke@435: class OopMapForCacheEntry: public GenerateOopMap { duke@435: OopMapCacheEntry *_entry; duke@435: int _bci; duke@435: int _stack_top; duke@435: duke@435: virtual bool report_results() const { return false; } duke@435: virtual bool possible_gc_point (BytecodeStream *bcs); duke@435: virtual void fill_stackmap_prolog (int nof_gc_points); duke@435: virtual void fill_stackmap_epilog (); duke@435: virtual void fill_stackmap_for_opcodes (BytecodeStream *bcs, duke@435: CellTypeState* vars, duke@435: CellTypeState* stack, duke@435: int stack_top); duke@435: virtual void fill_init_vars (GrowableArray *init_vars); duke@435: duke@435: public: duke@435: OopMapForCacheEntry(methodHandle method, int bci, OopMapCacheEntry *entry); duke@435: duke@435: // Computes stack map for (method,bci) and initialize entry duke@435: void compute_map(TRAPS); duke@435: int size(); duke@435: }; duke@435: duke@435: duke@435: OopMapForCacheEntry::OopMapForCacheEntry(methodHandle method, int bci, OopMapCacheEntry* entry) : GenerateOopMap(method) { duke@435: _bci = bci; duke@435: _entry = entry; duke@435: _stack_top = -1; duke@435: } duke@435: duke@435: duke@435: void OopMapForCacheEntry::compute_map(TRAPS) { duke@435: assert(!method()->is_native(), "cannot compute oop map for native methods"); duke@435: // First check if it is a method where the stackmap is always empty duke@435: if (method()->code_size() == 0 || method()->max_locals() + method()->max_stack() == 0) { duke@435: _entry->set_mask_size(0); duke@435: } else { duke@435: ResourceMark rm; duke@435: GenerateOopMap::compute_map(CATCH); duke@435: result_for_basicblock(_bci); duke@435: } duke@435: } duke@435: duke@435: duke@435: bool OopMapForCacheEntry::possible_gc_point(BytecodeStream *bcs) { duke@435: return false; // We are not reporting any result. We call result_for_basicblock directly duke@435: } duke@435: duke@435: duke@435: void OopMapForCacheEntry::fill_stackmap_prolog(int nof_gc_points) { duke@435: // Do nothing duke@435: } duke@435: duke@435: duke@435: void OopMapForCacheEntry::fill_stackmap_epilog() { duke@435: // Do nothing duke@435: } duke@435: duke@435: duke@435: void OopMapForCacheEntry::fill_init_vars(GrowableArray *init_vars) { duke@435: // Do nothing duke@435: } duke@435: duke@435: duke@435: void OopMapForCacheEntry::fill_stackmap_for_opcodes(BytecodeStream *bcs, duke@435: CellTypeState* vars, duke@435: CellTypeState* stack, duke@435: int stack_top) { duke@435: // Only interested in one specific bci duke@435: if (bcs->bci() == _bci) { duke@435: _entry->set_mask(vars, stack, stack_top); duke@435: _stack_top = stack_top; duke@435: } duke@435: } duke@435: duke@435: duke@435: int OopMapForCacheEntry::size() { duke@435: assert(_stack_top != -1, "compute_map must be called first"); duke@435: return ((method()->is_static()) ? 0 : 1) + method()->max_locals() + _stack_top; duke@435: } duke@435: duke@435: duke@435: // Implementation of InterpreterOopMap and OopMapCacheEntry duke@435: duke@435: class VerifyClosure : public OffsetClosure { duke@435: private: duke@435: OopMapCacheEntry* _entry; duke@435: bool _failed; duke@435: duke@435: public: duke@435: VerifyClosure(OopMapCacheEntry* entry) { _entry = entry; _failed = false; } duke@435: void offset_do(int offset) { if (!_entry->is_oop(offset)) _failed = true; } duke@435: bool failed() const { return _failed; } duke@435: }; duke@435: duke@435: InterpreterOopMap::InterpreterOopMap() { duke@435: initialize(); duke@435: #ifdef ASSERT duke@435: _resource_allocate_bit_mask = true; duke@435: #endif duke@435: } duke@435: duke@435: InterpreterOopMap::~InterpreterOopMap() { duke@435: // The expection is that the bit mask was allocated duke@435: // last in this resource area. That would make the free of the duke@435: // bit_mask effective (see how FREE_RESOURCE_ARRAY does a free). duke@435: // If it was not allocated last, there is not a correctness problem duke@435: // but the space for the bit_mask is not freed. duke@435: assert(_resource_allocate_bit_mask, "Trying to free C heap space"); duke@435: if (mask_size() > small_mask_limit) { duke@435: FREE_RESOURCE_ARRAY(uintptr_t, _bit_mask[0], mask_word_size()); duke@435: } duke@435: } duke@435: duke@435: bool InterpreterOopMap::is_empty() { duke@435: bool result = _method == NULL; duke@435: assert(_method != NULL || (_bci == 0 && duke@435: (_mask_size == 0 || _mask_size == USHRT_MAX) && duke@435: _bit_mask[0] == 0), "Should be completely empty"); duke@435: return result; duke@435: } duke@435: duke@435: void InterpreterOopMap::initialize() { duke@435: _method = NULL; duke@435: _mask_size = USHRT_MAX; // This value should cause a failure quickly duke@435: _bci = 0; duke@435: _expression_stack_size = 0; duke@435: for (int i = 0; i < N; i++) _bit_mask[i] = 0; duke@435: } duke@435: duke@435: duke@435: void InterpreterOopMap::oop_iterate(OopClosure *blk) { duke@435: if (method() != NULL) { duke@435: blk->do_oop((oop*) &_method); duke@435: } duke@435: } duke@435: duke@435: void InterpreterOopMap::oop_iterate(OopClosure *blk, MemRegion mr) { duke@435: if (method() != NULL && mr.contains(&_method)) { duke@435: blk->do_oop((oop*) &_method); duke@435: } duke@435: } duke@435: duke@435: duke@435: duke@435: void InterpreterOopMap::iterate_oop(OffsetClosure* oop_closure) { duke@435: int n = number_of_entries(); duke@435: int word_index = 0; duke@435: uintptr_t value = 0; duke@435: uintptr_t mask = 0; duke@435: // iterate over entries duke@435: for (int i = 0; i < n; i++, mask <<= bits_per_entry) { duke@435: // get current word duke@435: if (mask == 0) { duke@435: value = bit_mask()[word_index++]; duke@435: mask = 1; duke@435: } duke@435: // test for oop duke@435: if ((value & (mask << oop_bit_number)) != 0) oop_closure->offset_do(i); duke@435: } duke@435: } duke@435: duke@435: void InterpreterOopMap::verify() { duke@435: // If we are doing mark sweep _method may not have a valid header duke@435: // $$$ This used to happen only for m/s collections; we might want to duke@435: // think of an appropriate generalization of this distinction. duke@435: guarantee(Universe::heap()->is_gc_active() || duke@435: _method->is_oop_or_null(), "invalid oop in oopMapCache") duke@435: } duke@435: duke@435: #ifdef ENABLE_ZAP_DEAD_LOCALS duke@435: duke@435: void InterpreterOopMap::iterate_all(OffsetClosure* oop_closure, OffsetClosure* value_closure, OffsetClosure* dead_closure) { duke@435: int n = number_of_entries(); duke@435: int word_index = 0; duke@435: uintptr_t value = 0; duke@435: uintptr_t mask = 0; duke@435: // iterate over entries duke@435: for (int i = 0; i < n; i++, mask <<= bits_per_entry) { duke@435: // get current word duke@435: if (mask == 0) { duke@435: value = bit_mask()[word_index++]; duke@435: mask = 1; duke@435: } duke@435: // test for dead values & oops, and for live values duke@435: if ((value & (mask << dead_bit_number)) != 0) dead_closure->offset_do(i); // call this for all dead values or oops duke@435: else if ((value & (mask << oop_bit_number)) != 0) oop_closure->offset_do(i); // call this for all live oops duke@435: else value_closure->offset_do(i); // call this for all live values duke@435: } duke@435: } duke@435: duke@435: #endif duke@435: duke@435: duke@435: void InterpreterOopMap::print() { duke@435: int n = number_of_entries(); duke@435: tty->print("oop map for "); duke@435: method()->print_value(); duke@435: tty->print(" @ %d = [%d] { ", bci(), n); duke@435: for (int i = 0; i < n; i++) { duke@435: #ifdef ENABLE_ZAP_DEAD_LOCALS duke@435: if (is_dead(i)) tty->print("%d+ ", i); duke@435: else duke@435: #endif duke@435: if (is_oop(i)) tty->print("%d ", i); duke@435: } duke@435: tty->print_cr("}"); duke@435: } duke@435: duke@435: class MaskFillerForNative: public NativeSignatureIterator { duke@435: private: duke@435: uintptr_t * _mask; // the bit mask to be filled duke@435: int _size; // the mask size in bits duke@435: duke@435: void set_one(int i) { duke@435: i *= InterpreterOopMap::bits_per_entry; duke@435: assert(0 <= i && i < _size, "offset out of bounds"); duke@435: _mask[i / BitsPerWord] |= (((uintptr_t) 1 << InterpreterOopMap::oop_bit_number) << (i % BitsPerWord)); duke@435: } duke@435: duke@435: public: duke@435: void pass_int() { /* ignore */ } duke@435: void pass_long() { /* ignore */ } duke@435: #ifdef _LP64 duke@435: void pass_float() { /* ignore */ } duke@435: #endif duke@435: void pass_double() { /* ignore */ } duke@435: void pass_object() { set_one(offset()); } duke@435: duke@435: MaskFillerForNative(methodHandle method, uintptr_t* mask, int size) : NativeSignatureIterator(method) { duke@435: _mask = mask; duke@435: _size = size; duke@435: // initialize with 0 duke@435: int i = (size + BitsPerWord - 1) / BitsPerWord; duke@435: while (i-- > 0) _mask[i] = 0; duke@435: } duke@435: duke@435: void generate() { duke@435: NativeSignatureIterator::iterate(); duke@435: } duke@435: }; duke@435: duke@435: bool OopMapCacheEntry::verify_mask(CellTypeState* vars, CellTypeState* stack, int max_locals, int stack_top) { duke@435: // Check mask includes map duke@435: VerifyClosure blk(this); duke@435: iterate_oop(&blk); duke@435: if (blk.failed()) return false; duke@435: duke@435: // Check if map is generated correctly duke@435: // (Use ?: operator to make sure all 'true' & 'false' are represented exactly the same so we can use == afterwards) duke@435: if (TraceOopMapGeneration && Verbose) tty->print("Locals (%d): ", max_locals); duke@435: duke@435: for(int i = 0; i < max_locals; i++) { duke@435: bool v1 = is_oop(i) ? true : false; duke@435: bool v2 = vars[i].is_reference() ? true : false; duke@435: assert(v1 == v2, "locals oop mask generation error"); duke@435: if (TraceOopMapGeneration && Verbose) tty->print("%d", v1 ? 1 : 0); duke@435: #ifdef ENABLE_ZAP_DEAD_LOCALS duke@435: bool v3 = is_dead(i) ? true : false; duke@435: bool v4 = !vars[i].is_live() ? true : false; duke@435: assert(v3 == v4, "locals live mask generation error"); duke@435: assert(!(v1 && v3), "dead value marked as oop"); duke@435: #endif duke@435: } duke@435: duke@435: if (TraceOopMapGeneration && Verbose) { tty->cr(); tty->print("Stack (%d): ", stack_top); } duke@435: for(int j = 0; j < stack_top; j++) { duke@435: bool v1 = is_oop(max_locals + j) ? true : false; duke@435: bool v2 = stack[j].is_reference() ? true : false; duke@435: assert(v1 == v2, "stack oop mask generation error"); duke@435: if (TraceOopMapGeneration && Verbose) tty->print("%d", v1 ? 1 : 0); duke@435: #ifdef ENABLE_ZAP_DEAD_LOCALS duke@435: bool v3 = is_dead(max_locals + j) ? true : false; duke@435: bool v4 = !stack[j].is_live() ? true : false; duke@435: assert(v3 == v4, "stack live mask generation error"); duke@435: assert(!(v1 && v3), "dead value marked as oop"); duke@435: #endif duke@435: } duke@435: if (TraceOopMapGeneration && Verbose) tty->cr(); duke@435: return true; duke@435: } duke@435: duke@435: void OopMapCacheEntry::allocate_bit_mask() { duke@435: if (mask_size() > small_mask_limit) { duke@435: assert(_bit_mask[0] == 0, "bit mask should be new or just flushed"); duke@435: _bit_mask[0] = (intptr_t) duke@435: NEW_C_HEAP_ARRAY(uintptr_t, mask_word_size()); duke@435: } duke@435: } duke@435: duke@435: void OopMapCacheEntry::deallocate_bit_mask() { duke@435: if (mask_size() > small_mask_limit && _bit_mask[0] != 0) { duke@435: assert(!Thread::current()->resource_area()->contains((void*)_bit_mask[0]), duke@435: "This bit mask should not be in the resource area"); duke@435: FREE_C_HEAP_ARRAY(uintptr_t, _bit_mask[0]); duke@435: debug_only(_bit_mask[0] = 0;) duke@435: } duke@435: } duke@435: duke@435: duke@435: void OopMapCacheEntry::fill_for_native(methodHandle mh) { duke@435: assert(mh->is_native(), "method must be native method"); duke@435: set_mask_size(mh->size_of_parameters() * bits_per_entry); duke@435: allocate_bit_mask(); duke@435: // fill mask for parameters duke@435: MaskFillerForNative mf(mh, bit_mask(), mask_size()); duke@435: mf.generate(); duke@435: } duke@435: duke@435: duke@435: void OopMapCacheEntry::fill(methodHandle method, int bci) { duke@435: HandleMark hm; duke@435: // Flush entry to deallocate an existing entry duke@435: flush(); duke@435: set_method(method()); duke@435: set_bci(bci); duke@435: if (method->is_native()) { duke@435: // Native method activations have oops only among the parameters and one duke@435: // extra oop following the parameters (the mirror for static native methods). duke@435: fill_for_native(method); duke@435: } else { duke@435: EXCEPTION_MARK; duke@435: OopMapForCacheEntry gen(method, bci, this); duke@435: gen.compute_map(CATCH); duke@435: } duke@435: #ifdef ASSERT duke@435: verify(); duke@435: #endif duke@435: } duke@435: duke@435: duke@435: void OopMapCacheEntry::set_mask(CellTypeState *vars, CellTypeState *stack, int stack_top) { duke@435: // compute bit mask size duke@435: int max_locals = method()->max_locals(); duke@435: int n_entries = max_locals + stack_top; duke@435: set_mask_size(n_entries * bits_per_entry); duke@435: allocate_bit_mask(); duke@435: set_expression_stack_size(stack_top); duke@435: duke@435: // compute bits duke@435: int word_index = 0; duke@435: uintptr_t value = 0; duke@435: uintptr_t mask = 1; duke@435: duke@435: CellTypeState* cell = vars; duke@435: for (int entry_index = 0; entry_index < n_entries; entry_index++, mask <<= bits_per_entry, cell++) { duke@435: // store last word duke@435: if (mask == 0) { duke@435: bit_mask()[word_index++] = value; duke@435: value = 0; duke@435: mask = 1; duke@435: } duke@435: duke@435: // switch to stack when done with locals duke@435: if (entry_index == max_locals) { duke@435: cell = stack; duke@435: } duke@435: duke@435: // set oop bit duke@435: if ( cell->is_reference()) { duke@435: value |= (mask << oop_bit_number ); duke@435: } duke@435: duke@435: #ifdef ENABLE_ZAP_DEAD_LOCALS duke@435: // set dead bit duke@435: if (!cell->is_live()) { duke@435: value |= (mask << dead_bit_number); duke@435: assert(!cell->is_reference(), "dead value marked as oop"); duke@435: } duke@435: #endif duke@435: } duke@435: duke@435: // make sure last word is stored duke@435: bit_mask()[word_index] = value; duke@435: duke@435: // verify bit mask duke@435: assert(verify_mask(vars, stack, max_locals, stack_top), "mask could not be verified"); duke@435: duke@435: duke@435: } duke@435: duke@435: void OopMapCacheEntry::flush() { duke@435: deallocate_bit_mask(); duke@435: initialize(); duke@435: } duke@435: duke@435: duke@435: // Implementation of OopMapCache duke@435: duke@435: #ifndef PRODUCT duke@435: duke@435: static long _total_memory_usage = 0; duke@435: duke@435: long OopMapCache::memory_usage() { duke@435: return _total_memory_usage; duke@435: } duke@435: duke@435: #endif duke@435: duke@435: void InterpreterOopMap::resource_copy(OopMapCacheEntry* from) { duke@435: assert(_resource_allocate_bit_mask, duke@435: "Should not resource allocate the _bit_mask"); duke@435: assert(from->method()->is_oop(), "MethodOop is bad"); duke@435: duke@435: set_method(from->method()); duke@435: set_bci(from->bci()); duke@435: set_mask_size(from->mask_size()); duke@435: set_expression_stack_size(from->expression_stack_size()); duke@435: duke@435: // Is the bit mask contained in the entry? duke@435: if (from->mask_size() <= small_mask_limit) { duke@435: memcpy((void *)_bit_mask, (void *)from->_bit_mask, duke@435: mask_word_size() * BytesPerWord); duke@435: } else { duke@435: // The expectation is that this InterpreterOopMap is a recently created duke@435: // and empty. It is used to get a copy of a cached entry. duke@435: // If the bit mask has a value, it should be in the duke@435: // resource area. duke@435: assert(_bit_mask[0] == 0 || duke@435: Thread::current()->resource_area()->contains((void*)_bit_mask[0]), duke@435: "The bit mask should have been allocated from a resource area"); duke@435: // Allocate the bit_mask from a Resource area for performance. Allocating duke@435: // from the C heap as is done for OopMapCache has a significant duke@435: // performance impact. duke@435: _bit_mask[0] = (uintptr_t) NEW_RESOURCE_ARRAY(uintptr_t, mask_word_size()); duke@435: assert(_bit_mask[0] != 0, "bit mask was not allocated"); duke@435: memcpy((void*) _bit_mask[0], (void*) from->_bit_mask[0], duke@435: mask_word_size() * BytesPerWord); duke@435: } duke@435: } duke@435: duke@435: inline unsigned int OopMapCache::hash_value_for(methodHandle method, int bci) { duke@435: // We use method->code_size() rather than method->identity_hash() below since duke@435: // the mark may not be present if a pointer to the method is already reversed. duke@435: return ((unsigned int) bci) duke@435: ^ ((unsigned int) method->max_locals() << 2) duke@435: ^ ((unsigned int) method->code_size() << 4) duke@435: ^ ((unsigned int) method->size_of_parameters() << 6); duke@435: } duke@435: duke@435: duke@435: OopMapCache::OopMapCache() : duke@435: _mut(Mutex::leaf, "An OopMapCache lock", true) duke@435: { duke@435: _array = NEW_C_HEAP_ARRAY(OopMapCacheEntry, _size); duke@435: // Cannot call flush for initialization, since flush duke@435: // will check if memory should be deallocated duke@435: for(int i = 0; i < _size; i++) _array[i].initialize(); duke@435: NOT_PRODUCT(_total_memory_usage += sizeof(OopMapCache) + (sizeof(OopMapCacheEntry) * _size);) duke@435: } duke@435: duke@435: duke@435: OopMapCache::~OopMapCache() { duke@435: assert(_array != NULL, "sanity check"); duke@435: // Deallocate oop maps that are allocated out-of-line duke@435: flush(); duke@435: // Deallocate array duke@435: NOT_PRODUCT(_total_memory_usage -= sizeof(OopMapCache) + (sizeof(OopMapCacheEntry) * _size);) duke@435: FREE_C_HEAP_ARRAY(OopMapCacheEntry, _array); duke@435: } duke@435: duke@435: OopMapCacheEntry* OopMapCache::entry_at(int i) const { duke@435: return &_array[i % _size]; duke@435: } duke@435: duke@435: void OopMapCache::flush() { duke@435: for (int i = 0; i < _size; i++) _array[i].flush(); duke@435: } duke@435: duke@435: void OopMapCache::flush_obsolete_entries() { duke@435: for (int i = 0; i < _size; i++) duke@435: if (!_array[i].is_empty() && _array[i].method()->is_old()) { duke@435: // Cache entry is occupied by an old redefined method and we don't want duke@435: // to pin it down so flush the entry. duke@435: _array[i].flush(); duke@435: } duke@435: } duke@435: duke@435: void OopMapCache::oop_iterate(OopClosure *blk) { duke@435: for (int i = 0; i < _size; i++) _array[i].oop_iterate(blk); duke@435: } duke@435: duke@435: void OopMapCache::oop_iterate(OopClosure *blk, MemRegion mr) { duke@435: for (int i = 0; i < _size; i++) _array[i].oop_iterate(blk, mr); duke@435: } duke@435: duke@435: void OopMapCache::verify() { duke@435: for (int i = 0; i < _size; i++) _array[i].verify(); duke@435: } duke@435: duke@435: void OopMapCache::lookup(methodHandle method, duke@435: int bci, duke@435: InterpreterOopMap* entry_for) { duke@435: MutexLocker x(&_mut); duke@435: duke@435: OopMapCacheEntry* entry = NULL; duke@435: int probe = hash_value_for(method, bci); duke@435: duke@435: // Search hashtable for match duke@435: int i; duke@435: for(i = 0; i < _probe_depth; i++) { duke@435: entry = entry_at(probe + i); duke@435: if (entry->match(method, bci)) { duke@435: entry_for->resource_copy(entry); duke@435: assert(!entry_for->is_empty(), "A non-empty oop map should be returned"); duke@435: return; duke@435: } duke@435: } duke@435: duke@435: if (TraceOopMapGeneration) { duke@435: static int count = 0; duke@435: ResourceMark rm; duke@435: tty->print("%d - Computing oopmap at bci %d for ", ++count, bci); duke@435: method->print_value(); tty->cr(); duke@435: } duke@435: duke@435: // Entry is not in hashtable. duke@435: // Compute entry and return it duke@435: duke@435: // First search for an empty slot duke@435: for(i = 0; i < _probe_depth; i++) { duke@435: entry = entry_at(probe + i); duke@435: if (entry->is_empty()) { duke@435: entry->fill(method, bci); duke@435: entry_for->resource_copy(entry); duke@435: assert(!entry_for->is_empty(), "A non-empty oop map should be returned"); duke@435: if (method->is_old()) { duke@435: // The caller of lookup() will receive a copy of the interesting duke@435: // info via entry_for, but we don't keep an old redefined method in duke@435: // the cache to avoid pinning down the method. duke@435: entry->flush(); duke@435: } duke@435: return; duke@435: } duke@435: } duke@435: duke@435: if (TraceOopMapGeneration) { duke@435: ResourceMark rm; duke@435: tty->print_cr("*** collision in oopmap cache - flushing item ***"); duke@435: } duke@435: duke@435: // No empty slot (uncommon case). Use (some approximation of a) LRU algorithm duke@435: //entry_at(probe + _probe_depth - 1)->flush(); duke@435: //for(i = _probe_depth - 1; i > 0; i--) { duke@435: // // Coping entry[i] = entry[i-1]; duke@435: // OopMapCacheEntry *to = entry_at(probe + i); duke@435: // OopMapCacheEntry *from = entry_at(probe + i - 1); duke@435: // to->copy(from); duke@435: // } duke@435: duke@435: assert(method->is_method(), "gaga"); duke@435: duke@435: entry = entry_at(probe + 0); duke@435: entry->fill(method, bci); duke@435: duke@435: // Copy the newly cached entry to input parameter duke@435: entry_for->resource_copy(entry); duke@435: duke@435: if (TraceOopMapGeneration) { duke@435: ResourceMark rm; duke@435: tty->print("Done with "); duke@435: method->print_value(); tty->cr(); duke@435: } duke@435: assert(!entry_for->is_empty(), "A non-empty oop map should be returned"); duke@435: duke@435: if (method->is_old()) { duke@435: // The caller of lookup() will receive a copy of the interesting duke@435: // info via entry_for, but we don't keep an old redefined method in duke@435: // the cache to avoid pinning down the method. duke@435: entry->flush(); duke@435: } duke@435: duke@435: return; duke@435: } duke@435: duke@435: void OopMapCache::compute_one_oop_map(methodHandle method, int bci, InterpreterOopMap* entry) { duke@435: // Due to the invariants above it's tricky to allocate a temporary OopMapCacheEntry on the stack duke@435: OopMapCacheEntry* tmp = NEW_C_HEAP_ARRAY(OopMapCacheEntry, 1); duke@435: tmp->initialize(); duke@435: tmp->fill(method, bci); duke@435: entry->resource_copy(tmp); duke@435: FREE_C_HEAP_ARRAY(OopMapCacheEntry, tmp); duke@435: }