Path: blob/master/src/hotspot/share/gc/parallel/psParallelCompact.inline.hpp
41149 views
/*1* Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#ifndef SHARE_GC_PARALLEL_PSPARALLELCOMPACT_INLINE_HPP25#define SHARE_GC_PARALLEL_PSPARALLELCOMPACT_INLINE_HPP2627#include "gc/parallel/psParallelCompact.hpp"2829#include "gc/parallel/parallelScavengeHeap.hpp"30#include "gc/parallel/parMarkBitMap.inline.hpp"31#include "gc/shared/collectedHeap.hpp"32#include "oops/access.inline.hpp"33#include "oops/compressedOops.inline.hpp"34#include "oops/klass.hpp"35#include "oops/oop.inline.hpp"3637inline bool PSParallelCompact::is_marked(oop obj) {38return mark_bitmap()->is_marked(obj);39}4041inline double PSParallelCompact::normal_distribution(double density) {42assert(_dwl_initialized, "uninitialized");43const double squared_term = (density - _dwl_mean) / _dwl_std_dev;44return _dwl_first_term * exp(-0.5 * squared_term * squared_term);45}4647inline bool PSParallelCompact::dead_space_crosses_boundary(const RegionData* region,48idx_t bit) {49assert(bit > 0, "cannot call this for the first bit/region");50assert(_summary_data.region_to_addr(region) == _mark_bitmap.bit_to_addr(bit),51"sanity check");5253// Dead space crosses the boundary if (1) a partial object does not extend54// onto the region, (2) an object does not start at the beginning of the55// region, and (3) an object does not end at the end of the prior region.56return region->partial_obj_size() == 0 &&57!_mark_bitmap.is_obj_beg(bit) &&58!_mark_bitmap.is_obj_end(bit - 1);59}6061inline bool PSParallelCompact::is_in(HeapWord* p, HeapWord* beg_addr, HeapWord* end_addr) {62return p >= beg_addr && p < end_addr;63}6465inline bool PSParallelCompact::is_in(oop* p, HeapWord* beg_addr, HeapWord* end_addr) {66return is_in((HeapWord*)p, beg_addr, end_addr);67}6869inline MutableSpace* PSParallelCompact::space(SpaceId id) {70assert(id < last_space_id, "id out of range");71return _space_info[id].space();72}7374inline HeapWord* PSParallelCompact::new_top(SpaceId id) {75assert(id < last_space_id, "id out of range");76return _space_info[id].new_top();77}7879inline HeapWord* PSParallelCompact::dense_prefix(SpaceId id) {80assert(id < last_space_id, "id out of range");81return _space_info[id].dense_prefix();82}8384inline ObjectStartArray* PSParallelCompact::start_array(SpaceId id) {85assert(id < last_space_id, "id out of range");86return _space_info[id].start_array();87}8889#ifdef ASSERT90inline void PSParallelCompact::check_new_location(HeapWord* old_addr, HeapWord* new_addr) {91assert(old_addr >= new_addr || space_id(old_addr) != space_id(new_addr),92"must move left or to a different space");93assert(is_object_aligned(old_addr) && is_object_aligned(new_addr),94"checking alignment");95}96#endif // ASSERT9798inline bool PSParallelCompact::mark_obj(oop obj) {99const int obj_size = obj->size();100if (mark_bitmap()->mark_obj(obj, obj_size)) {101_summary_data.add_obj(obj, obj_size);102return true;103} else {104return false;105}106}107108template <class T>109inline void PSParallelCompact::adjust_pointer(T* p, ParCompactionManager* cm) {110T heap_oop = RawAccess<>::oop_load(p);111if (!CompressedOops::is_null(heap_oop)) {112oop obj = CompressedOops::decode_not_null(heap_oop);113assert(ParallelScavengeHeap::heap()->is_in(obj), "should be in heap");114115oop new_obj = cast_to_oop(summary_data().calc_new_pointer(obj, cm));116assert(new_obj != NULL, "non-null address for live objects");117// Is it actually relocated at all?118if (new_obj != obj) {119assert(ParallelScavengeHeap::heap()->is_in_reserved(new_obj),120"should be in object space");121RawAccess<IS_NOT_NULL>::oop_store(p, new_obj);122}123}124}125126class PCAdjustPointerClosure: public BasicOopIterateClosure {127public:128PCAdjustPointerClosure(ParCompactionManager* cm) {129verify_cm(cm);130_cm = cm;131}132template <typename T> void do_oop_nv(T* p) { PSParallelCompact::adjust_pointer(p, _cm); }133virtual void do_oop(oop* p) { do_oop_nv(p); }134virtual void do_oop(narrowOop* p) { do_oop_nv(p); }135136virtual ReferenceIterationMode reference_iteration_mode() { return DO_FIELDS; }137private:138ParCompactionManager* _cm;139140static void verify_cm(ParCompactionManager* cm) NOT_DEBUG_RETURN;141};142143#endif // SHARE_GC_PARALLEL_PSPARALLELCOMPACT_INLINE_HPP144145146