aoqi@0: /* aoqi@0: * Copyright (c) 1998, 2014, Oracle and/or its affiliates. All rights reserved. aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. aoqi@0: * aoqi@0: * This code is free software; you can redistribute it and/or modify it aoqi@0: * under the terms of the GNU General Public License version 2 only, as aoqi@0: * published by the Free Software Foundation. aoqi@0: * aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that aoqi@0: * accompanied this code). aoqi@0: * aoqi@0: * You should have received a copy of the GNU General Public License version aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation, aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. aoqi@0: * aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@0: * or visit www.oracle.com if you need additional information or have any aoqi@0: * questions. aoqi@0: * aoqi@0: */ aoqi@0: aoqi@0: #include "precompiled.hpp" aoqi@0: #include "code/codeBlob.hpp" aoqi@0: #include "code/codeCache.hpp" aoqi@0: #include "code/nmethod.hpp" aoqi@0: #include "code/scopeDesc.hpp" aoqi@0: #include "compiler/oopMap.hpp" aoqi@0: #include "gc_interface/collectedHeap.hpp" aoqi@0: #include "memory/allocation.inline.hpp" aoqi@0: #include "memory/resourceArea.hpp" aoqi@0: #include "runtime/frame.inline.hpp" aoqi@0: #include "runtime/signature.hpp" aoqi@0: #ifdef COMPILER1 aoqi@0: #include "c1/c1_Defs.hpp" aoqi@0: #endif aoqi@0: aoqi@0: // OopMapStream aoqi@0: aoqi@0: OopMapStream::OopMapStream(OopMap* oop_map) { aoqi@0: if(oop_map->omv_data() == NULL) { aoqi@0: _stream = new CompressedReadStream(oop_map->write_stream()->buffer()); aoqi@0: } else { aoqi@0: _stream = new CompressedReadStream(oop_map->omv_data()); aoqi@0: } aoqi@0: _mask = OopMapValue::type_mask_in_place; aoqi@0: _size = oop_map->omv_count(); aoqi@0: _position = 0; aoqi@0: _valid_omv = false; aoqi@0: } aoqi@0: aoqi@0: aoqi@0: OopMapStream::OopMapStream(OopMap* oop_map, int oop_types_mask) { aoqi@0: if(oop_map->omv_data() == NULL) { aoqi@0: _stream = new CompressedReadStream(oop_map->write_stream()->buffer()); aoqi@0: } else { aoqi@0: _stream = new CompressedReadStream(oop_map->omv_data()); aoqi@0: } aoqi@0: _mask = oop_types_mask; aoqi@0: _size = oop_map->omv_count(); aoqi@0: _position = 0; aoqi@0: _valid_omv = false; aoqi@0: } aoqi@0: aoqi@0: aoqi@0: void OopMapStream::find_next() { aoqi@0: while(_position++ < _size) { aoqi@0: _omv.read_from(_stream); aoqi@0: if(((int)_omv.type() & _mask) > 0) { aoqi@0: _valid_omv = true; aoqi@0: return; aoqi@0: } aoqi@0: } aoqi@0: _valid_omv = false; aoqi@0: } aoqi@0: aoqi@0: aoqi@0: // OopMap aoqi@0: aoqi@0: // frame_size units are stack-slots (4 bytes) NOT intptr_t; we can name odd aoqi@0: // slots to hold 4-byte values like ints and floats in the LP64 build. aoqi@0: OopMap::OopMap(int frame_size, int arg_count) { aoqi@0: // OopMaps are usually quite so small, so pick a small initial size aoqi@0: set_write_stream(new CompressedWriteStream(32)); aoqi@0: set_omv_data(NULL); aoqi@0: set_omv_count(0); aoqi@0: aoqi@0: #ifdef ASSERT aoqi@0: _locs_length = VMRegImpl::stack2reg(0)->value() + frame_size + arg_count; aoqi@0: _locs_used = NEW_RESOURCE_ARRAY(OopMapValue::oop_types, _locs_length); aoqi@0: for(int i = 0; i < _locs_length; i++) _locs_used[i] = OopMapValue::unused_value; aoqi@0: #endif aoqi@0: } aoqi@0: aoqi@0: aoqi@0: OopMap::OopMap(OopMap::DeepCopyToken, OopMap* source) { aoqi@0: // This constructor does a deep copy aoqi@0: // of the source OopMap. aoqi@0: set_write_stream(new CompressedWriteStream(source->omv_count() * 2)); aoqi@0: set_omv_data(NULL); aoqi@0: set_omv_count(0); aoqi@0: set_offset(source->offset()); aoqi@0: aoqi@0: #ifdef ASSERT aoqi@0: _locs_length = source->_locs_length; aoqi@0: _locs_used = NEW_RESOURCE_ARRAY(OopMapValue::oop_types, _locs_length); aoqi@0: for(int i = 0; i < _locs_length; i++) _locs_used[i] = OopMapValue::unused_value; aoqi@0: #endif aoqi@0: aoqi@0: // We need to copy the entries too. aoqi@0: for (OopMapStream oms(source); !oms.is_done(); oms.next()) { aoqi@0: OopMapValue omv = oms.current(); aoqi@0: omv.write_on(write_stream()); aoqi@0: increment_count(); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: aoqi@0: OopMap* OopMap::deep_copy() { aoqi@0: return new OopMap(_deep_copy_token, this); aoqi@0: } aoqi@0: aoqi@0: aoqi@0: void OopMap::copy_to(address addr) { aoqi@0: memcpy(addr,this,sizeof(OopMap)); aoqi@0: memcpy(addr + sizeof(OopMap),write_stream()->buffer(),write_stream()->position()); aoqi@0: OopMap* new_oop = (OopMap*)addr; aoqi@0: new_oop->set_omv_data_size(write_stream()->position()); aoqi@0: new_oop->set_omv_data((unsigned char *)(addr + sizeof(OopMap))); aoqi@0: new_oop->set_write_stream(NULL); aoqi@0: } aoqi@0: aoqi@0: aoqi@0: int OopMap::heap_size() const { aoqi@0: int size = sizeof(OopMap); aoqi@0: int align = sizeof(void *) - 1; aoqi@0: if(write_stream() != NULL) { aoqi@0: size += write_stream()->position(); aoqi@0: } else { aoqi@0: size += omv_data_size(); aoqi@0: } aoqi@0: // Align to a reasonable ending point aoqi@0: size = ((size+align) & ~align); aoqi@0: return size; aoqi@0: } aoqi@0: aoqi@0: // frame_size units are stack-slots (4 bytes) NOT intptr_t; we can name odd aoqi@0: // slots to hold 4-byte values like ints and floats in the LP64 build. aoqi@0: void OopMap::set_xxx(VMReg reg, OopMapValue::oop_types x, VMReg optional) { aoqi@0: aoqi@0: assert(reg->value() < _locs_length, "too big reg value for stack size"); aoqi@0: assert( _locs_used[reg->value()] == OopMapValue::unused_value, "cannot insert twice" ); aoqi@0: debug_only( _locs_used[reg->value()] = x; ) aoqi@0: aoqi@0: OopMapValue o(reg, x); aoqi@0: aoqi@0: if(x == OopMapValue::callee_saved_value) { aoqi@0: // This can never be a stack location, so we don't need to transform it. aoqi@0: assert(optional->is_reg(), "Trying to callee save a stack location"); aoqi@0: o.set_content_reg(optional); aoqi@0: } else if(x == OopMapValue::derived_oop_value) { aoqi@0: o.set_content_reg(optional); aoqi@0: } aoqi@0: aoqi@0: o.write_on(write_stream()); aoqi@0: increment_count(); aoqi@0: } aoqi@0: aoqi@0: aoqi@0: void OopMap::set_oop(VMReg reg) { aoqi@0: set_xxx(reg, OopMapValue::oop_value, VMRegImpl::Bad()); aoqi@0: } aoqi@0: aoqi@0: aoqi@0: void OopMap::set_value(VMReg reg) { aoqi@0: // At this time, we only need value entries in our OopMap when ZapDeadCompiledLocals is active. aoqi@0: if (ZapDeadCompiledLocals) aoqi@0: set_xxx(reg, OopMapValue::value_value, VMRegImpl::Bad()); aoqi@0: } aoqi@0: aoqi@0: aoqi@0: void OopMap::set_narrowoop(VMReg reg) { aoqi@0: set_xxx(reg, OopMapValue::narrowoop_value, VMRegImpl::Bad()); aoqi@0: } aoqi@0: aoqi@0: aoqi@0: void OopMap::set_callee_saved(VMReg reg, VMReg caller_machine_register ) { aoqi@0: set_xxx(reg, OopMapValue::callee_saved_value, caller_machine_register); aoqi@0: } aoqi@0: aoqi@0: aoqi@0: void OopMap::set_derived_oop(VMReg reg, VMReg derived_from_local_register ) { aoqi@0: if( reg == derived_from_local_register ) { aoqi@0: // Actually an oop, derived shares storage with base, aoqi@0: set_oop(reg); aoqi@0: } else { aoqi@0: set_xxx(reg, OopMapValue::derived_oop_value, derived_from_local_register); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: // OopMapSet aoqi@0: aoqi@0: OopMapSet::OopMapSet() { aoqi@0: set_om_size(MinOopMapAllocation); aoqi@0: set_om_count(0); aoqi@0: OopMap** temp = NEW_RESOURCE_ARRAY(OopMap*, om_size()); aoqi@0: set_om_data(temp); aoqi@0: } aoqi@0: aoqi@0: aoqi@0: void OopMapSet::grow_om_data() { aoqi@0: int new_size = om_size() * 2; aoqi@0: OopMap** new_data = NEW_RESOURCE_ARRAY(OopMap*, new_size); aoqi@0: memcpy(new_data,om_data(),om_size() * sizeof(OopMap*)); aoqi@0: set_om_size(new_size); aoqi@0: set_om_data(new_data); aoqi@0: } aoqi@0: aoqi@0: aoqi@0: void OopMapSet::copy_to(address addr) { aoqi@0: address temp = addr; aoqi@0: int align = sizeof(void *) - 1; aoqi@0: // Copy this aoqi@0: memcpy(addr,this,sizeof(OopMapSet)); aoqi@0: temp += sizeof(OopMapSet); aoqi@0: temp = (address)((intptr_t)(temp + align) & ~align); aoqi@0: // Do the needed fixups to the new OopMapSet aoqi@0: OopMapSet* new_set = (OopMapSet*)addr; aoqi@0: new_set->set_om_data((OopMap**)temp); aoqi@0: // Allow enough space for the OopMap pointers aoqi@0: temp += (om_count() * sizeof(OopMap*)); aoqi@0: aoqi@0: for(int i=0; i < om_count(); i++) { aoqi@0: OopMap* map = at(i); aoqi@0: map->copy_to((address)temp); aoqi@0: new_set->set(i,(OopMap*)temp); aoqi@0: temp += map->heap_size(); aoqi@0: } aoqi@0: // This "locks" the OopMapSet aoqi@0: new_set->set_om_size(-1); aoqi@0: } aoqi@0: aoqi@0: aoqi@0: void OopMapSet::add_gc_map(int pc_offset, OopMap *map ) { aoqi@0: assert(om_size() != -1,"Cannot grow a fixed OopMapSet"); aoqi@0: aoqi@0: if(om_count() >= om_size()) { aoqi@0: grow_om_data(); aoqi@0: } aoqi@0: map->set_offset(pc_offset); aoqi@0: aoqi@0: #ifdef ASSERT aoqi@0: if(om_count() > 0) { aoqi@0: OopMap* last = at(om_count()-1); aoqi@0: if (last->offset() == map->offset() ) { aoqi@0: fatal("OopMap inserted twice"); aoqi@0: } aoqi@0: if(last->offset() > map->offset()) { aoqi@0: tty->print_cr( "WARNING, maps not sorted: pc[%d]=%d, pc[%d]=%d", aoqi@0: om_count(),last->offset(),om_count()+1,map->offset()); aoqi@0: } aoqi@0: } aoqi@0: #endif // ASSERT aoqi@0: aoqi@0: set(om_count(),map); aoqi@0: increment_count(); aoqi@0: } aoqi@0: aoqi@0: aoqi@0: int OopMapSet::heap_size() const { aoqi@0: // The space we use aoqi@0: int size = sizeof(OopMap); aoqi@0: int align = sizeof(void *) - 1; aoqi@0: size = ((size+align) & ~align); aoqi@0: size += om_count() * sizeof(OopMap*); aoqi@0: aoqi@0: // Now add in the space needed for the indivdiual OopMaps aoqi@0: for(int i=0; i < om_count(); i++) { aoqi@0: size += at(i)->heap_size(); aoqi@0: } aoqi@0: // We don't need to align this, it will be naturally pointer aligned aoqi@0: return size; aoqi@0: } aoqi@0: aoqi@0: aoqi@0: OopMap* OopMapSet::singular_oop_map() { aoqi@0: guarantee(om_count() == 1, "Make sure we only have a single gc point"); aoqi@0: return at(0); aoqi@0: } aoqi@0: aoqi@0: aoqi@0: OopMap* OopMapSet::find_map_at_offset(int pc_offset) const { aoqi@0: int i, len = om_count(); aoqi@0: assert( len > 0, "must have pointer maps" ); aoqi@0: aoqi@0: // Scan through oopmaps. Stop when current offset is either equal or greater aoqi@0: // than the one we are looking for. aoqi@0: for( i = 0; i < len; i++) { aoqi@0: if( at(i)->offset() >= pc_offset ) aoqi@0: break; aoqi@0: } aoqi@0: aoqi@0: assert( i < len, "oopmap not found" ); aoqi@0: aoqi@0: OopMap* m = at(i); aoqi@0: assert( m->offset() == pc_offset, "oopmap not found" ); aoqi@0: return m; aoqi@0: } aoqi@0: aoqi@0: class DoNothingClosure: public OopClosure { aoqi@0: public: aoqi@0: void do_oop(oop* p) {} aoqi@0: void do_oop(narrowOop* p) {} aoqi@0: }; aoqi@0: static DoNothingClosure do_nothing; aoqi@0: aoqi@0: static void add_derived_oop(oop* base, oop* derived) { aoqi@0: #ifndef TIERED aoqi@0: COMPILER1_PRESENT(ShouldNotReachHere();) aoqi@0: #endif // TIERED aoqi@0: #ifdef COMPILER2 aoqi@0: DerivedPointerTable::add(derived, base); aoqi@0: #endif // COMPILER2 aoqi@0: } aoqi@0: aoqi@0: aoqi@0: #ifndef PRODUCT aoqi@0: static void trace_codeblob_maps(const frame *fr, const RegisterMap *reg_map) { aoqi@0: // Print oopmap and regmap aoqi@0: tty->print_cr("------ "); aoqi@0: CodeBlob* cb = fr->cb(); aoqi@0: OopMapSet* maps = cb->oop_maps(); aoqi@0: OopMap* map = cb->oop_map_for_return_address(fr->pc()); aoqi@0: map->print(); aoqi@0: if( cb->is_nmethod() ) { aoqi@0: nmethod* nm = (nmethod*)cb; aoqi@0: // native wrappers have no scope data, it is implied aoqi@0: if (nm->is_native_method()) { aoqi@0: tty->print("bci: 0 (native)"); aoqi@0: } else { aoqi@0: ScopeDesc* scope = nm->scope_desc_at(fr->pc()); aoqi@0: tty->print("bci: %d ",scope->bci()); aoqi@0: } aoqi@0: } aoqi@0: tty->cr(); aoqi@0: fr->print_on(tty); aoqi@0: tty->print(" "); aoqi@0: cb->print_value_on(tty); tty->cr(); aoqi@0: reg_map->print(); aoqi@0: tty->print_cr("------ "); aoqi@0: aoqi@0: } aoqi@0: #endif // PRODUCT aoqi@0: aoqi@0: void OopMapSet::oops_do(const frame *fr, const RegisterMap* reg_map, OopClosure* f) { aoqi@0: // add derived oops to a table aoqi@0: all_do(fr, reg_map, f, add_derived_oop, &do_nothing); aoqi@0: } aoqi@0: aoqi@0: aoqi@0: void OopMapSet::all_do(const frame *fr, const RegisterMap *reg_map, aoqi@0: OopClosure* oop_fn, void derived_oop_fn(oop*, oop*), aoqi@0: OopClosure* value_fn) { aoqi@0: CodeBlob* cb = fr->cb(); aoqi@0: assert(cb != NULL, "no codeblob"); aoqi@0: aoqi@0: NOT_PRODUCT(if (TraceCodeBlobStacks) trace_codeblob_maps(fr, reg_map);) aoqi@0: aoqi@0: OopMapSet* maps = cb->oop_maps(); aoqi@0: OopMap* map = cb->oop_map_for_return_address(fr->pc()); aoqi@0: assert(map != NULL, "no ptr map found"); aoqi@0: aoqi@0: // handle derived pointers first (otherwise base pointer may be aoqi@0: // changed before derived pointer offset has been collected) aoqi@0: OopMapValue omv; aoqi@0: { aoqi@0: OopMapStream oms(map,OopMapValue::derived_oop_value); aoqi@0: if (!oms.is_done()) { aoqi@0: #ifndef TIERED aoqi@0: COMPILER1_PRESENT(ShouldNotReachHere();) aoqi@0: #endif // !TIERED aoqi@0: // Protect the operation on the derived pointers. This aoqi@0: // protects the addition of derived pointers to the shared aoqi@0: // derived pointer table in DerivedPointerTable::add(). aoqi@0: MutexLockerEx x(DerivedPointerTableGC_lock, Mutex::_no_safepoint_check_flag); aoqi@0: do { aoqi@0: omv = oms.current(); aoqi@0: oop* loc = fr->oopmapreg_to_location(omv.reg(),reg_map); aoqi@0: if ( loc != NULL ) { aoqi@0: oop *base_loc = fr->oopmapreg_to_location(omv.content_reg(), reg_map); aoqi@0: oop *derived_loc = loc; aoqi@0: oop val = *base_loc; aoqi@0: if (val == (oop)NULL || Universe::is_narrow_oop_base(val)) { aoqi@0: // Ignore NULL oops and decoded NULL narrow oops which aoqi@0: // equal to Universe::narrow_oop_base when a narrow oop aoqi@0: // implicit null check is used in compiled code. aoqi@0: // The narrow_oop_base could be NULL or be the address aoqi@0: // of the page below heap depending on compressed oops mode. aoqi@0: } else aoqi@0: derived_oop_fn(base_loc, derived_loc); aoqi@0: } aoqi@0: oms.next(); aoqi@0: } while (!oms.is_done()); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: // We want coop, value and oop oop_types aoqi@0: int mask = OopMapValue::oop_value | OopMapValue::value_value | OopMapValue::narrowoop_value; aoqi@0: { aoqi@0: for (OopMapStream oms(map,mask); !oms.is_done(); oms.next()) { aoqi@0: omv = oms.current(); aoqi@0: oop* loc = fr->oopmapreg_to_location(omv.reg(),reg_map); aoqi@0: if ( loc != NULL ) { aoqi@0: if ( omv.type() == OopMapValue::oop_value ) { aoqi@0: oop val = *loc; aoqi@0: if (val == (oop)NULL || Universe::is_narrow_oop_base(val)) { aoqi@0: // Ignore NULL oops and decoded NULL narrow oops which aoqi@0: // equal to Universe::narrow_oop_base when a narrow oop aoqi@0: // implicit null check is used in compiled code. aoqi@0: // The narrow_oop_base could be NULL or be the address aoqi@0: // of the page below heap depending on compressed oops mode. aoqi@0: continue; aoqi@0: } aoqi@0: #ifdef ASSERT aoqi@0: if ((((uintptr_t)loc & (sizeof(*loc)-1)) != 0) || aoqi@0: !Universe::heap()->is_in_or_null(*loc)) { aoqi@0: tty->print_cr("# Found non oop pointer. Dumping state at failure"); aoqi@0: // try to dump out some helpful debugging information aoqi@0: trace_codeblob_maps(fr, reg_map); aoqi@0: omv.print(); aoqi@0: tty->print_cr("register r"); aoqi@0: omv.reg()->print(); aoqi@0: tty->print_cr("loc = %p *loc = %p\n", loc, (address)*loc); aoqi@0: // do the real assert. aoqi@0: assert(Universe::heap()->is_in_or_null(*loc), "found non oop pointer"); aoqi@0: } aoqi@0: #endif // ASSERT aoqi@0: oop_fn->do_oop(loc); aoqi@0: } else if ( omv.type() == OopMapValue::value_value ) { aoqi@0: assert((*loc) == (oop)NULL || !Universe::is_narrow_oop_base(*loc), aoqi@0: "found invalid value pointer"); aoqi@0: value_fn->do_oop(loc); aoqi@0: } else if ( omv.type() == OopMapValue::narrowoop_value ) { aoqi@0: narrowOop *nl = (narrowOop*)loc; aoqi@0: #ifndef VM_LITTLE_ENDIAN aoqi@0: if (!omv.reg()->is_stack()) { aoqi@0: // compressed oops in registers only take up 4 bytes of an aoqi@0: // 8 byte register but they are in the wrong part of the aoqi@0: // word so adjust loc to point at the right place. aoqi@0: nl = (narrowOop*)((address)nl + 4); aoqi@0: } aoqi@0: #endif aoqi@0: oop_fn->do_oop(nl); aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: aoqi@0: // Update callee-saved register info for the following frame aoqi@0: void OopMapSet::update_register_map(const frame *fr, RegisterMap *reg_map) { aoqi@0: ResourceMark rm; aoqi@0: CodeBlob* cb = fr->cb(); aoqi@0: assert(cb != NULL, "no codeblob"); aoqi@0: aoqi@0: // Any reg might be saved by a safepoint handler (see generate_handler_blob). aoqi@0: const int max_saved_on_entry_reg_count = ConcreteRegisterImpl::number_of_registers; aoqi@0: assert( reg_map->_update_for_id == NULL || fr->is_older(reg_map->_update_for_id), aoqi@0: "already updated this map; do not 'update' it twice!" ); aoqi@0: debug_only(reg_map->_update_for_id = fr->id()); aoqi@0: aoqi@0: // Check if caller must update oop argument aoqi@0: assert((reg_map->include_argument_oops() || aoqi@0: !cb->caller_must_gc_arguments(reg_map->thread())), aoqi@0: "include_argument_oops should already be set"); aoqi@0: aoqi@0: int nof_callee = 0; aoqi@0: oop* locs[2*max_saved_on_entry_reg_count+1]; aoqi@0: VMReg regs[2*max_saved_on_entry_reg_count+1]; aoqi@0: // ("+1" because max_saved_on_entry_reg_count might be zero) aoqi@0: aoqi@0: // Scan through oopmap and find location of all callee-saved registers aoqi@0: // (we do not do update in place, since info could be overwritten) aoqi@0: aoqi@0: address pc = fr->pc(); aoqi@0: aoqi@0: OopMap* map = cb->oop_map_for_return_address(pc); aoqi@0: aoqi@0: assert(map != NULL, " no ptr map found"); aoqi@0: aoqi@0: OopMapValue omv; aoqi@0: for(OopMapStream oms(map,OopMapValue::callee_saved_value); !oms.is_done(); oms.next()) { aoqi@0: omv = oms.current(); aoqi@0: assert(nof_callee < 2*max_saved_on_entry_reg_count, "overflow"); aoqi@0: regs[nof_callee] = omv.content_reg(); aoqi@0: locs[nof_callee] = fr->oopmapreg_to_location(omv.reg(),reg_map); aoqi@0: nof_callee++; aoqi@0: } aoqi@0: aoqi@0: // Check that runtime stubs save all callee-saved registers aoqi@0: #ifdef COMPILER2 aoqi@0: assert(cb->is_compiled_by_c1() || !cb->is_runtime_stub() || aoqi@0: (nof_callee >= SAVED_ON_ENTRY_REG_COUNT || nof_callee >= C_SAVED_ON_ENTRY_REG_COUNT), aoqi@0: "must save all"); aoqi@0: #endif // COMPILER2 aoqi@0: aoqi@0: // Copy found callee-saved register to reg_map aoqi@0: for(int i = 0; i < nof_callee; i++) { aoqi@0: reg_map->set_location(regs[i], (address)locs[i]); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: //============================================================================= aoqi@0: // Non-Product code aoqi@0: aoqi@0: #ifndef PRODUCT aoqi@0: aoqi@0: bool OopMap::has_derived_pointer() const { aoqi@0: #ifndef TIERED aoqi@0: COMPILER1_PRESENT(return false); aoqi@0: #endif // !TIERED aoqi@0: #ifdef COMPILER2 aoqi@0: OopMapStream oms((OopMap*)this,OopMapValue::derived_oop_value); aoqi@0: return oms.is_done(); aoqi@0: #else aoqi@0: return false; aoqi@0: #endif // COMPILER2 aoqi@0: } aoqi@0: aoqi@0: #endif //PRODUCT aoqi@0: aoqi@0: // Printing code is present in product build for -XX:+PrintAssembly. aoqi@0: aoqi@0: static aoqi@0: void print_register_type(OopMapValue::oop_types x, VMReg optional, aoqi@0: outputStream* st) { aoqi@0: switch( x ) { aoqi@0: case OopMapValue::oop_value: aoqi@0: st->print("Oop"); aoqi@0: break; aoqi@0: case OopMapValue::value_value: aoqi@0: st->print("Value"); aoqi@0: break; aoqi@0: case OopMapValue::narrowoop_value: aoqi@0: st->print("NarrowOop"); aoqi@0: break; aoqi@0: case OopMapValue::callee_saved_value: aoqi@0: st->print("Callers_"); aoqi@0: optional->print_on(st); aoqi@0: break; aoqi@0: case OopMapValue::derived_oop_value: aoqi@0: st->print("Derived_oop_"); aoqi@0: optional->print_on(st); aoqi@0: break; aoqi@0: default: aoqi@0: ShouldNotReachHere(); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: aoqi@0: void OopMapValue::print_on(outputStream* st) const { aoqi@0: reg()->print_on(st); aoqi@0: st->print("="); aoqi@0: print_register_type(type(),content_reg(),st); aoqi@0: st->print(" "); aoqi@0: } aoqi@0: aoqi@0: aoqi@0: void OopMap::print_on(outputStream* st) const { aoqi@0: OopMapValue omv; aoqi@0: st->print("OopMap{"); aoqi@0: for(OopMapStream oms((OopMap*)this); !oms.is_done(); oms.next()) { aoqi@0: omv = oms.current(); aoqi@0: omv.print_on(st); aoqi@0: } aoqi@0: st->print("off=%d}", (int) offset()); aoqi@0: } aoqi@0: aoqi@0: aoqi@0: void OopMapSet::print_on(outputStream* st) const { aoqi@0: int i, len = om_count(); aoqi@0: aoqi@0: st->print_cr("OopMapSet contains %d OopMaps\n",len); aoqi@0: aoqi@0: for( i = 0; i < len; i++) { aoqi@0: OopMap* m = at(i); aoqi@0: st->print_cr("#%d ",i); aoqi@0: m->print_on(st); aoqi@0: st->cr(); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: aoqi@0: aoqi@0: //------------------------------DerivedPointerTable--------------------------- aoqi@0: aoqi@0: #ifdef COMPILER2 aoqi@0: aoqi@0: class DerivedPointerEntry : public CHeapObj { aoqi@0: private: aoqi@0: oop* _location; // Location of derived pointer (also pointing to the base) aoqi@0: intptr_t _offset; // Offset from base pointer aoqi@0: public: aoqi@0: DerivedPointerEntry(oop* location, intptr_t offset) { _location = location; _offset = offset; } aoqi@0: oop* location() { return _location; } aoqi@0: intptr_t offset() { return _offset; } aoqi@0: }; aoqi@0: aoqi@0: aoqi@0: GrowableArray* DerivedPointerTable::_list = NULL; aoqi@0: bool DerivedPointerTable::_active = false; aoqi@0: aoqi@0: aoqi@0: void DerivedPointerTable::clear() { aoqi@0: // The first time, we create the list. Otherwise it should be aoqi@0: // empty. If not, then we have probably forgotton to call aoqi@0: // update_pointers after last GC/Scavenge. aoqi@0: assert (!_active, "should not be active"); aoqi@0: assert(_list == NULL || _list->length() == 0, "table not empty"); aoqi@0: if (_list == NULL) { aoqi@0: _list = new (ResourceObj::C_HEAP, mtCompiler) GrowableArray(10, true); // Allocated on C heap aoqi@0: } aoqi@0: _active = true; aoqi@0: } aoqi@0: aoqi@0: aoqi@0: // Returns value of location as an int aoqi@0: intptr_t value_of_loc(oop *pointer) { return cast_from_oop((*pointer)); } aoqi@0: aoqi@0: aoqi@0: void DerivedPointerTable::add(oop *derived_loc, oop *base_loc) { aoqi@0: assert(Universe::heap()->is_in_or_null(*base_loc), "not an oop"); aoqi@0: assert(derived_loc != base_loc, "Base and derived in same location"); aoqi@0: if (_active) { aoqi@0: assert(*derived_loc != (oop)base_loc, "location already added"); aoqi@0: assert(_list != NULL, "list must exist"); aoqi@0: intptr_t offset = value_of_loc(derived_loc) - value_of_loc(base_loc); aoqi@0: // This assert is invalid because derived pointers can be aoqi@0: // arbitrarily far away from their base. aoqi@0: // assert(offset >= -1000000, "wrong derived pointer info"); aoqi@0: aoqi@0: if (TraceDerivedPointers) { aoqi@0: tty->print_cr( aoqi@0: "Add derived pointer@" INTPTR_FORMAT aoqi@0: " - Derived: " INTPTR_FORMAT aoqi@0: " Base: " INTPTR_FORMAT " (@" INTPTR_FORMAT ") (Offset: " INTX_FORMAT ")", aoqi@0: p2i(derived_loc), p2i((address)*derived_loc), p2i((address)*base_loc), p2i(base_loc), offset aoqi@0: ); aoqi@0: } aoqi@0: // Set derived oop location to point to base. aoqi@0: *derived_loc = (oop)base_loc; aoqi@0: assert_lock_strong(DerivedPointerTableGC_lock); aoqi@0: DerivedPointerEntry *entry = new DerivedPointerEntry(derived_loc, offset); aoqi@0: _list->append(entry); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: aoqi@0: void DerivedPointerTable::update_pointers() { aoqi@0: assert(_list != NULL, "list must exist"); aoqi@0: for(int i = 0; i < _list->length(); i++) { aoqi@0: DerivedPointerEntry* entry = _list->at(i); aoqi@0: oop* derived_loc = entry->location(); aoqi@0: intptr_t offset = entry->offset(); aoqi@0: // The derived oop was setup to point to location of base aoqi@0: oop base = **(oop**)derived_loc; aoqi@0: assert(Universe::heap()->is_in_or_null(base), "must be an oop"); aoqi@0: aoqi@0: *derived_loc = (oop)(((address)base) + offset); aoqi@0: assert(value_of_loc(derived_loc) - value_of_loc(&base) == offset, "sanity check"); aoqi@0: aoqi@0: if (TraceDerivedPointers) { aoqi@0: tty->print_cr("Updating derived pointer@" INTPTR_FORMAT aoqi@0: " - Derived: " INTPTR_FORMAT " Base: " INTPTR_FORMAT " (Offset: " INTX_FORMAT ")", aoqi@0: p2i(derived_loc), p2i((address)*derived_loc), p2i((address)base), offset); aoqi@0: } aoqi@0: aoqi@0: // Delete entry aoqi@0: delete entry; aoqi@0: _list->at_put(i, NULL); aoqi@0: } aoqi@0: // Clear list, so it is ready for next traversal (this is an invariant) aoqi@0: if (TraceDerivedPointers && !_list->is_empty()) { aoqi@0: tty->print_cr("--------------------------"); aoqi@0: } aoqi@0: _list->clear(); aoqi@0: _active = false; aoqi@0: } aoqi@0: aoqi@0: #endif // COMPILER2