Path: blob/master/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/utilities/MarkBits.java
41161 views
/*1* Copyright (c) 2001, 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*/2324package sun.jvm.hotspot.utilities;2526import sun.jvm.hotspot.debugger.*;27import sun.jvm.hotspot.gc.shared.*;28import sun.jvm.hotspot.memory.*;29import sun.jvm.hotspot.oops.*;30import sun.jvm.hotspot.runtime.*;3132/** Helper class which covers the reserved area of the heap with an33(object-external) set of mark bits, used for GC-like scans through34the heap like liveness analysis. */3536public class MarkBits {37public MarkBits(CollectedHeap heap) {38MemRegion reserved = heap.reservedRegion();39// Must cover "reserved" with one bit for each OopHandle40start = reserved.start();41end = reserved.end();42long numOopHandles = end.minus(start) / VM.getVM().getOopSize();43bits = heap.createBitMap(numOopHandles);44}4546public void clear() {47bits.clear();48}4950/** Returns true if a mark was newly placed for the given Oop, or51false if the Oop was already marked. If the Oop happens to lie52outside the heap (should not happen), prints a warning and53returns false. */54public boolean mark(Oop obj) {55if (obj == null) {56System.err.println("MarkBits: WARNING: null object, ignoring");57return false;58}5960OopHandle handle = obj.getHandle();61long idx = handle.minus(start) / VM.getVM().getOopSize();62if (bits.at(idx)) {63return false; // already marked64}65bits.atPut(idx, true);66return true;67}6869/** Forces clearing of a given mark bit. */70public void clear(Oop obj) {71OopHandle handle = obj.getHandle();72long idx = handle.minus(start) / VM.getVM().getOopSize();73bits.atPut(idx, false);74}7576private BitMapInterface bits;77private Address start;78private Address end;79}808182